@demirarch/recode 0.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/COMMERCIAL.md ADDED
@@ -0,0 +1,53 @@
1
+ # Commercial License — Recode
2
+
3
+ Copyright 2026 DemirArch. All rights reserved.
4
+
5
+ ---
6
+
7
+ ## Who needs a commercial license?
8
+
9
+ You need a commercial license if you:
10
+
11
+ - Use Recode in a **for-profit company** or organization
12
+ - Embed Recode (or derivative works) in a **paid product or service**
13
+ - Offer Recode as a **SaaS or hosted service** to third parties
14
+ - Redistribute Recode as part of a **commercial software package**
15
+ - Use Recode internally at a company with more than **5 employees**
16
+
17
+ ## Who does NOT need a commercial license?
18
+
19
+ The Apache 2.0 license (see `LICENSE`) covers:
20
+
21
+ - Personal use and hobby projects
22
+ - Open-source projects (source must remain open)
23
+ - Students and educational use
24
+ - Non-profit organizations
25
+ - Evaluation and testing (up to 30 days)
26
+
27
+ ## Commercial License Terms
28
+
29
+ A commercial license grants you:
30
+
31
+ 1. The right to use Recode in closed-source commercial products
32
+ 2. The right to offer Recode as part of a SaaS or hosted service
33
+ 3. The right to redistribute Recode within a commercial package
34
+ 4. Priority support from DemirArch
35
+
36
+ **Restrictions:**
37
+ - You may NOT sublicense this commercial license to third parties
38
+ - You may NOT resell or white-label Recode without a separate agreement
39
+ - Attribution to DemirArch must remain in any "About" screen or documentation
40
+
41
+ ## How to obtain a commercial license
42
+
43
+ Contact DemirArch to discuss pricing and terms:
44
+
45
+ - GitHub: https://github.com/demirgitbuh
46
+ - Repository: https://github.com/demirgitbuh/recode
47
+
48
+ Pricing is based on team size and use case. We will respond within 48 hours.
49
+
50
+ ---
51
+
52
+ This document does not constitute a legal contract. A commercial license
53
+ becomes valid only upon written agreement between DemirArch and the licensee.
package/LICENSE ADDED
@@ -0,0 +1,184 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as
57
+ "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a
80
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
81
+ or a Contribution incorporated within the Work constitutes direct
82
+ or contributory patent infringement, then any patent licenses
83
+ granted to You under this License for that Work shall terminate
84
+ as of the date such litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or
92
+ Derivative Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file, you must include a
104
+ readable copy of the attribution notices contained within such
105
+ NOTICE file, in at least one of the following places: within a
106
+ NOTICE text provided with the distribution; within the Source
107
+ form or documentation, if provided along with the Derivative
108
+ Works; or, within a display generated by the Derivative Works,
109
+ if and wherever such third-party notices normally appear. The
110
+ contents of the NOTICE file are for informational purposes only
111
+ and do not modify the License. You may add Your own attribution
112
+ notices within Derivative Works that You distribute, alongside
113
+ or as an addendum to the NOTICE text from the Work, provided
114
+ that such additional attribution notices cannot be construed
115
+ as modifying the License.
116
+
117
+ You may add Your own license statement for Your modifications and
118
+ may provide additional grant of rights to use, reproduce, modify,
119
+ prepare Derivative Works of, convert to, or distribute, Your
120
+ modifications, or for such Combined Works as a whole, under Your
121
+ chosen terms, if Your chosen terms satisfy the conditions stated
122
+ in this License.
123
+
124
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
125
+ any Contribution intentionally submitted for inclusion in the Work
126
+ by You to the Licensor shall be under the terms and conditions of
127
+ this License, without any additional terms or conditions.
128
+ Notwithstanding the above, nothing herein shall supersede or modify
129
+ the terms of any separate license agreement you may have executed
130
+ with Licensor regarding such Contributions.
131
+
132
+ 6. Trademarks. This License does not grant permission to use the trade
133
+ names, trademarks, service marks, or product names of the Licensor,
134
+ except as required for reasonable and customary use in describing the
135
+ origin of the Work and reproducing the content of the NOTICE file.
136
+
137
+ 7. Disclaimer of Warranty. Unless required by applicable law or
138
+ agreed to in writing, Licensor provides the Work (and each
139
+ Contributor provides its Contributions) on an "AS IS" BASIS,
140
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
141
+ implied, including, without limitation, any conditions of TITLE,
142
+ NONINFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
143
+ PURPOSE. You are solely responsible for determining the
144
+ appropriateness of using or reproducing the Work and assume any
145
+ risks associated with Your exercise of permissions under this License.
146
+
147
+ 8. Limitation of Liability. In no event and under no legal theory,
148
+ whether in tort (including negligence), contract, or otherwise,
149
+ unless required by applicable law (such as deliberate and grossly
150
+ negligent acts) or agreed to in writing, shall any Contributor be
151
+ liable to You for damages, including any direct, indirect, special,
152
+ incidental, or exemplary damages of any character arising as a
153
+ result of this License or out of the use or inability to use the
154
+ Work (including but not limited to damages for loss of goodwill,
155
+ work stoppage, computer failure or malfunction, or all other
156
+ commercial damages or losses), even if such Contributor has been
157
+ advised of the possibility of such damages.
158
+
159
+ 9. Accepting Warranty or Liability. While redistributing the Work or
160
+ Derivative Works thereof, You may choose to offer, and charge a fee
161
+ for, acceptance of support, warranty, indemnity, or other liability
162
+ obligations and/or rights consistent with this License. However, in
163
+ accepting such obligations, You may act only on Your own behalf and
164
+ on Your sole responsibility, not on behalf of any other Contributor,
165
+ and only if You agree to indemnify, defend, and hold each Contributor
166
+ harmless for any liability incurred by, or claims asserted against,
167
+ such Contributor by reason of your accepting any warranty or
168
+ additional liability.
169
+
170
+ END OF TERMS AND CONDITIONS
171
+
172
+ Copyright 2026 DemirArch
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ http://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software
181
+ distributed under the License is distributed on an "AS IS" BASIS,
182
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183
+ See the License for the specific language governing permissions and
184
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Recode
2
+
3
+ A minimal terminal code editor with an embedded AI assistant powered by [OpenRouter](https://openrouter.ai).
4
+
5
+ Built with TypeScript + [Ink](https://github.com/vadimdemedes/ink).
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - Split-pane TUI: code editor (left) + AI chat (right)
12
+ - Syntax highlighting via `cli-highlight`
13
+ - Line numbers + cursor display
14
+ - OpenRouter AI integration (bring your own key)
15
+ - Model switching at runtime (`Ctrl+M`)
16
+ - Config persisted to `~/recode-data/config.json`
17
+ - First-launch setup wizard
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install -g recode
23
+ ```
24
+
25
+ Or run from source:
26
+
27
+ ```bash
28
+ git clone https://github.com/demirgitbuh/recode
29
+ cd recode
30
+ npm install
31
+ npm run dev [file]
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```bash
37
+ recode [file] # open a file
38
+ recode # start with empty buffer
39
+ ```
40
+
41
+ ## Keybindings
42
+
43
+ | Key | Action |
44
+ |-----|--------|
45
+ | `Ctrl+Q` | Quit |
46
+ | `Ctrl+S` | Save file |
47
+ | `Ctrl+A` | Focus AI panel |
48
+ | `Ctrl+E` | Focus editor |
49
+ | `Enter` | Send AI message |
50
+ | `Ctrl+Enter` | Send message + current file content to AI |
51
+ | `Ctrl+M` | Open model selector |
52
+ | `Esc` | Cancel / close overlay |
53
+
54
+ ## License
55
+
56
+ This project is dual-licensed:
57
+
58
+ - **Open source** (personal & non-commercial use): [Apache License 2.0](LICENSE)
59
+ - **Commercial use** (companies, SaaS, paid products): see [COMMERCIAL.md](COMMERCIAL.md)
60
+
61
+ ---
62
+
63
+ Made by [DemirArch](https://github.com/demirgitbuh)
package/dist/App.js ADDED
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState, useEffect } from 'react';
3
+ import { Text } from 'ink';
4
+ import { loadConfig } from './lib/config.js';
5
+ import { SetupScreen } from './components/SetupScreen.js';
6
+ import { ChatScreen } from './components/ChatScreen.js';
7
+ export function App({ initialCwd }) {
8
+ const [state, setState] = useState({ screen: 'loading' });
9
+ const [model, setModel] = useState('');
10
+ useEffect(() => {
11
+ loadConfig().then((cfg) => {
12
+ if (cfg) {
13
+ setModel(cfg.model);
14
+ setState({ screen: 'chat', config: cfg });
15
+ }
16
+ else {
17
+ setState({ screen: 'setup' });
18
+ }
19
+ });
20
+ }, []);
21
+ if (state.screen === 'loading') {
22
+ return _jsx(Text, { color: "#F26207", children: "Loading..." });
23
+ }
24
+ if (state.screen === 'setup') {
25
+ return (_jsx(SetupScreen, { onComplete: (cfg) => {
26
+ setModel(cfg.model);
27
+ setState({ screen: 'chat', config: cfg });
28
+ } }));
29
+ }
30
+ return (_jsx(ChatScreen, { model: model || state.config.model, apiKey: state.config.apiKey, initialCwd: initialCwd, onModelChange: setModel }));
31
+ }
@@ -0,0 +1,130 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Box, Text, useInput, useApp } from 'ink';
4
+ import TextInput from 'ink-text-input';
5
+ import Spinner from 'ink-spinner';
6
+ import { useAgent } from '../hooks/useAgent.js';
7
+ import { TopBar } from './TopBar.js';
8
+ import { StatusBar } from './StatusBar.js';
9
+ import { parseCommand } from '../lib/commands.js';
10
+ import { saveConfig } from '../lib/config.js';
11
+ import path from 'path';
12
+ const MODEL_EXAMPLES = [
13
+ 'anthropic/claude-sonnet-4-5',
14
+ 'openai/gpt-4o',
15
+ 'google/gemini-2.5-pro',
16
+ 'deepseek/deepseek-r1',
17
+ 'meta-llama/llama-4-maverick',
18
+ 'mistralai/codestral-latest',
19
+ 'qwen/qwen3-235b-a22b',
20
+ 'x-ai/grok-3',
21
+ ];
22
+ // ── Message Renderer ─────────────────────────────────────────
23
+ function RenderMessage({ msg }) {
24
+ switch (msg.type) {
25
+ case 'user':
26
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: "#F26207", children: "You" }), _jsx(Text, { children: msg.content })] }));
27
+ case 'assistant':
28
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "Recode" }), _jsx(Text, { wrap: "wrap", children: msg.content })] }));
29
+ case 'tool_call': {
30
+ let preview = '';
31
+ try {
32
+ const args = JSON.parse(msg.args);
33
+ const firstVal = Object.values(args)[0];
34
+ preview = typeof firstVal === 'string' ? firstVal.slice(0, 50) : '';
35
+ }
36
+ catch {
37
+ preview = '';
38
+ }
39
+ const icon = msg.status === 'running' ? '⟳' : msg.status === 'done' ? '✓' : '✗';
40
+ const color = msg.status === 'running' ? 'yellow' : msg.status === 'done' ? 'green' : 'red';
41
+ return (_jsxs(Box, { marginBottom: 0, children: [_jsxs(Text, { color: color, children: [icon, " "] }), _jsx(Text, { color: "gray", children: msg.name }), preview ? _jsxs(Text, { color: "gray", children: [" ", preview] }) : null] }));
42
+ }
43
+ case 'system':
44
+ return (_jsx(Box, { flexDirection: "column", marginBottom: 1, borderStyle: "single", borderColor: "gray", paddingX: 1, children: _jsx(Text, { color: "gray", children: msg.content }) }));
45
+ case 'error':
46
+ return (_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { color: "red", children: ["Error: ", msg.content] }) }));
47
+ default:
48
+ return null;
49
+ }
50
+ }
51
+ // ── Model Input Overlay ───────────────────────────────────────
52
+ function ModelOverlay({ currentModel, onConfirm, onCancel, }) {
53
+ const [value, setValue] = useState(currentModel);
54
+ const [error, setError] = useState(null);
55
+ useInput((_, key) => {
56
+ if (key.escape) {
57
+ onCancel();
58
+ return;
59
+ }
60
+ if (key.return) {
61
+ const m = value.trim();
62
+ if (!m.includes('/')) {
63
+ setError('Must include provider, e.g. anthropic/claude-sonnet-4-5');
64
+ return;
65
+ }
66
+ onConfirm(m);
67
+ }
68
+ });
69
+ return (_jsxs(Box, { flexDirection: "column", borderStyle: "double", borderColor: "#F26207", padding: 1, marginX: 2, children: [_jsxs(Text, { bold: true, color: "#F26207", children: ["Change Model ", _jsx(Text, { color: "gray", children: "(Esc to cancel)" })] }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: "#F26207", children: '> ' }), _jsx(TextInput, { value: value, onChange: setValue, placeholder: "provider/model-name" })] }), _jsx(Text, { color: "gray", dimColor: true, children: "Press Enter to confirm" }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: "gray", dimColor: true, children: "Examples:" }), MODEL_EXAMPLES.map((e) => (_jsxs(Text, { color: "gray", dimColor: true, children: [" ", e] }, e)))] }), error && _jsx(Text, { color: "red", children: error })] }));
70
+ }
71
+ // ── Main Chat Screen ─────────────────────────────────────────
72
+ export function ChatScreen({ model, apiKey, initialCwd, onModelChange }) {
73
+ const { exit } = useApp();
74
+ const [cwd, setCwd] = useState(initialCwd);
75
+ const [input, setInput] = useState('');
76
+ const [showModelInput, setShowModelInput] = useState(false);
77
+ const { display, thinking, sendMessage, clearHistory, addSystemMessage } = useAgent(model, apiKey, cwd);
78
+ const handleSubmit = async (value) => {
79
+ const trimmed = value.trim();
80
+ if (!trimmed || thinking)
81
+ return;
82
+ setInput('');
83
+ const result = parseCommand(trimmed, cwd);
84
+ switch (result.type) {
85
+ case 'system':
86
+ addSystemMessage(result.content);
87
+ return;
88
+ case 'open_model_select':
89
+ setShowModelInput(true);
90
+ return;
91
+ case 'clear':
92
+ clearHistory();
93
+ return;
94
+ case 'exit':
95
+ exit();
96
+ return;
97
+ case 'cd': {
98
+ const newCwd = path.isAbsolute(result.path)
99
+ ? result.path
100
+ : path.resolve(cwd, result.path);
101
+ setCwd(newCwd);
102
+ addSystemMessage(`cwd: ${newCwd}`);
103
+ return;
104
+ }
105
+ case 'send_to_ai':
106
+ await sendMessage(result.content);
107
+ return;
108
+ case 'none':
109
+ await sendMessage(trimmed);
110
+ return;
111
+ }
112
+ };
113
+ const handleModelConfirm = async (newModel) => {
114
+ setShowModelInput(false);
115
+ onModelChange(newModel);
116
+ try {
117
+ await saveConfig({ apiKey, model: newModel });
118
+ }
119
+ catch { /* ignore */ }
120
+ addSystemMessage(`Model: ${newModel}`);
121
+ };
122
+ useInput((inp, key) => {
123
+ if (key.ctrl && inp === 'l')
124
+ clearHistory();
125
+ if (key.ctrl && inp === 'c')
126
+ exit();
127
+ });
128
+ const visibleMessages = display.slice(-40);
129
+ return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsx(TopBar, { model: model, cwd: cwd }), showModelInput ? (_jsx(ModelOverlay, { currentModel: model, onConfirm: (m) => { void handleModelConfirm(m); }, onCancel: () => setShowModelInput(false) })) : (_jsxs(Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, overflow: "hidden", children: [visibleMessages.length === 0 && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: "gray", children: ["Type a message or ", _jsx(Text, { color: "#F26207", children: "/help" }), " for commands."] }) })), visibleMessages.map((msg, i) => (_jsx(RenderMessage, { msg: msg }, i))), thinking && (_jsxs(Box, { children: [_jsx(Spinner, { type: "dots" }), _jsx(Text, { color: "#F26207", children: " Thinking..." })] }))] })), _jsxs(Box, { borderStyle: "single", borderColor: "#F26207", paddingX: 1, children: [_jsx(Text, { bold: true, color: "#F26207", children: '> ' }), _jsx(TextInput, { value: input, onChange: setInput, onSubmit: (v) => { void handleSubmit(v); }, placeholder: thinking ? 'Waiting...' : 'Message Recode...', focus: !showModelInput })] }), _jsx(StatusBar, {})] }));
130
+ }
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Box, Text, useInput } from 'ink';
4
+ import TextInput from 'ink-text-input';
5
+ import { saveConfig } from '../lib/config.js';
6
+ const EXAMPLES = [
7
+ 'anthropic/claude-sonnet-4-5',
8
+ 'openai/gpt-4o',
9
+ 'google/gemini-2.5-pro',
10
+ 'deepseek/deepseek-r1',
11
+ 'meta-llama/llama-4-maverick',
12
+ 'mistralai/codestral-latest',
13
+ 'qwen/qwen3-235b-a22b',
14
+ 'x-ai/grok-3',
15
+ ];
16
+ export function SetupScreen({ onComplete }) {
17
+ const [step, setStep] = useState('apiKey');
18
+ const [apiKey, setApiKey] = useState('');
19
+ const [model, setModel] = useState('');
20
+ const [error, setError] = useState(null);
21
+ useInput((_, key) => {
22
+ if (!key.return)
23
+ return;
24
+ if (step === 'apiKey') {
25
+ if (apiKey.trim().length < 10) {
26
+ setError('API key too short — paste your OpenRouter key');
27
+ return;
28
+ }
29
+ setError(null);
30
+ setStep('model');
31
+ return;
32
+ }
33
+ if (step === 'model') {
34
+ const m = model.trim();
35
+ if (!m.includes('/')) {
36
+ setError('Model must include provider, e.g. anthropic/claude-sonnet-4-5');
37
+ return;
38
+ }
39
+ setError(null);
40
+ void save(m);
41
+ }
42
+ });
43
+ const save = async (m) => {
44
+ setStep('saving');
45
+ const config = { apiKey: apiKey.trim(), model: m };
46
+ try {
47
+ await saveConfig(config);
48
+ onComplete(config);
49
+ }
50
+ catch (err) {
51
+ setError(err instanceof Error ? err.message : String(err));
52
+ setStep('model');
53
+ }
54
+ };
55
+ return (_jsxs(Box, { flexDirection: "column", padding: 2, gap: 1, children: [_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, color: "#F26207", children: "Recode \u2014 First Launch Setup" }), _jsx(Text, { color: "gray", children: "Autonomous AI coding agent by DemirArch" }), _jsx(Text, { color: "gray", children: "Config: ~/recode-data/config.json" })] }), step === 'apiKey' && (_jsxs(Box, { flexDirection: "column", gap: 1, marginTop: 1, children: [_jsx(Text, { children: "OpenRouter API key:" }), _jsx(Text, { color: "gray", dimColor: true, children: "Get one at openrouter.ai/keys" }), _jsxs(Box, { children: [_jsx(Text, { color: "#F26207", children: '> ' }), _jsx(TextInput, { value: apiKey, onChange: setApiKey, mask: "*", placeholder: "sk-or-..." })] }), _jsx(Text, { color: "gray", dimColor: true, children: "Press Enter to continue" }), error && _jsx(Text, { color: "red", children: error })] })), step === 'model' && (_jsxs(Box, { flexDirection: "column", gap: 1, marginTop: 1, children: [_jsxs(Text, { children: ["Model ID ", _jsx(Text, { color: "gray", children: "(provider/model-name)" })] }), _jsxs(Box, { children: [_jsx(Text, { color: "#F26207", children: '> ' }), _jsx(TextInput, { value: model, onChange: setModel, placeholder: "anthropic/claude-sonnet-4-5" })] }), _jsx(Text, { color: "gray", dimColor: true, children: "Press Enter to confirm \u2022 /model to change later" }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: "gray", dimColor: true, children: "Examples:" }), EXAMPLES.map((e) => (_jsxs(Text, { color: "gray", dimColor: true, children: [" ", e] }, e)))] }), error && _jsx(Text, { color: "red", children: error })] })), step === 'saving' && _jsx(Text, { color: "#F26207", children: "Saving config..." })] }));
56
+ }
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ const CMD = ({ c, label }) => (_jsxs(Box, { gap: 0, marginRight: 2, children: [_jsx(Text, { bold: true, color: "#F26207", children: c }), _jsxs(Text, { color: "gray", children: [" ", label] })] }));
4
+ export function StatusBar() {
5
+ return (_jsxs(Box, { borderStyle: "single", borderColor: "gray", paddingX: 1, children: [_jsx(CMD, { c: "/help", label: "help" }), _jsx(CMD, { c: "/model", label: "model" }), _jsx(CMD, { c: "/clear", label: "clear" }), _jsx(CMD, { c: "/cd", label: "cd" }), _jsx(CMD, { c: "/ls", label: "ls" }), _jsx(CMD, { c: "/read", label: "read" }), _jsx(CMD, { c: "/exit", label: "exit" })] }));
6
+ }
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ import { getModelLabel } from '../lib/models.js';
4
+ import os from 'os';
5
+ function shortenPath(p) {
6
+ const home = os.homedir();
7
+ if (p.startsWith(home))
8
+ return '~' + p.slice(home.length);
9
+ return p;
10
+ }
11
+ export function TopBar({ model, cwd }) {
12
+ const shortModel = getModelLabel(model);
13
+ const shortCwd = shortenPath(cwd);
14
+ return (_jsxs(Box, { borderStyle: "single", borderColor: "#F26207", paddingX: 1, justifyContent: "space-between", children: [_jsxs(Box, { gap: 2, children: [_jsx(Text, { bold: true, color: "#F26207", children: "Recode" }), _jsx(Text, { color: "gray", children: shortCwd })] }), _jsxs(Text, { color: "gray", children: ['model: ', _jsx(Text, { color: "#F26207", children: shortModel })] })] }));
15
+ }
@@ -0,0 +1,106 @@
1
+ import { useState, useRef, useCallback } from 'react';
2
+ import { callOpenRouter } from '../lib/openrouter.js';
3
+ import { executeTool } from '../lib/tools.js';
4
+ export function useAgent(model, apiKey, cwd) {
5
+ const displayRef = useRef([]);
6
+ const [display, setDisplay] = useState([]);
7
+ const [apiMessages, setApiMessages] = useState([]);
8
+ const [thinking, setThinking] = useState(false);
9
+ // Sync ref → state
10
+ const flush = () => setDisplay([...displayRef.current]);
11
+ const addDisplay = (msg) => {
12
+ const idx = displayRef.current.length;
13
+ displayRef.current = [...displayRef.current, msg];
14
+ flush();
15
+ return idx;
16
+ };
17
+ const updateDisplay = (idx, updates) => {
18
+ displayRef.current = displayRef.current.map((m, i) => i === idx ? { ...m, ...updates } : m);
19
+ flush();
20
+ };
21
+ const addSystemMessage = useCallback((content) => {
22
+ addDisplay({ type: 'system', content });
23
+ }, []);
24
+ const clearHistory = useCallback(() => {
25
+ displayRef.current = [];
26
+ setDisplay([]);
27
+ setApiMessages([]);
28
+ }, []);
29
+ const sendMessage = useCallback(async (userInput) => {
30
+ if (thinking)
31
+ return;
32
+ // Add user message to display
33
+ addDisplay({ type: 'user', content: userInput });
34
+ setThinking(true);
35
+ // Build current API messages
36
+ const newUserMsg = { role: 'user', content: userInput };
37
+ let currentMessages = [...apiMessages, newUserMsg];
38
+ setApiMessages(currentMessages);
39
+ try {
40
+ // Agentic loop — run until no more tool calls
41
+ while (true) {
42
+ const response = await callOpenRouter(currentMessages, model, apiKey);
43
+ if (response.tool_calls && response.tool_calls.length > 0) {
44
+ // Record assistant message with tool calls
45
+ currentMessages = [
46
+ ...currentMessages,
47
+ {
48
+ role: 'assistant',
49
+ content: response.content,
50
+ tool_calls: response.tool_calls,
51
+ },
52
+ ];
53
+ // Execute each tool
54
+ const toolResultMessages = [];
55
+ for (const tc of response.tool_calls) {
56
+ const displayIdx = addDisplay({
57
+ type: 'tool_call',
58
+ name: tc.function.name,
59
+ args: tc.function.arguments,
60
+ status: 'running',
61
+ });
62
+ let result;
63
+ let status = 'done';
64
+ try {
65
+ const parsedArgs = JSON.parse(tc.function.arguments);
66
+ result = await executeTool(tc.function.name, parsedArgs, cwd);
67
+ }
68
+ catch (err) {
69
+ result = `Error: ${err instanceof Error ? err.message : String(err)}`;
70
+ status = 'error';
71
+ }
72
+ updateDisplay(displayIdx, { status, result });
73
+ toolResultMessages.push({
74
+ role: 'tool',
75
+ content: result,
76
+ tool_call_id: tc.id,
77
+ });
78
+ }
79
+ currentMessages = [...currentMessages, ...toolResultMessages];
80
+ }
81
+ else {
82
+ // Final text response
83
+ const content = response.content ?? '(no response)';
84
+ addDisplay({ type: 'assistant', content });
85
+ setApiMessages(currentMessages);
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ catch (err) {
91
+ const msg = err instanceof Error ? err.message : String(err);
92
+ addDisplay({ type: 'error', content: msg });
93
+ }
94
+ finally {
95
+ setThinking(false);
96
+ }
97
+ }, [apiMessages, model, apiKey, cwd, thinking]);
98
+ return {
99
+ display,
100
+ thinking,
101
+ sendMessage,
102
+ clearHistory,
103
+ addSystemMessage,
104
+ apiMessages,
105
+ };
106
+ }