nou-cli 0.1.0 → 0.2.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/README.md +140 -31
- package/dist/grammars/tree-sitter-bash.wasm +0 -0
- package/dist/grammars/tree-sitter-c.wasm +0 -0
- package/dist/grammars/tree-sitter-css.wasm +0 -0
- package/dist/grammars/tree-sitter-go.wasm +0 -0
- package/dist/grammars/tree-sitter-html.wasm +0 -0
- package/dist/grammars/tree-sitter-java.wasm +0 -0
- package/dist/grammars/tree-sitter-javascript.wasm +0 -0
- package/dist/grammars/tree-sitter-json.wasm +0 -0
- package/dist/grammars/tree-sitter-python.wasm +0 -0
- package/dist/grammars/tree-sitter-rust.wasm +0 -0
- package/dist/grammars/tree-sitter-toml.wasm +0 -0
- package/dist/grammars/tree-sitter-tsx.wasm +0 -0
- package/dist/grammars/tree-sitter-typescript.wasm +0 -0
- package/dist/grammars/tree-sitter-yaml.wasm +0 -0
- package/dist/index.js +55 -6
- package/dist/src/agent/index.js +37 -5
- package/dist/src/commands/index.js +16 -6
- package/dist/src/config/index.js +5 -2
- package/dist/src/diagnostics/index.js +235 -0
- package/dist/src/diagnostics/process.js +64 -0
- package/dist/src/diagnostics/providers.js +103 -0
- package/dist/src/diagnostics/types.js +1 -0
- package/dist/src/env.js +12 -0
- package/dist/src/history/index.js +113 -0
- package/dist/src/lsp/client.js +169 -0
- package/dist/src/lsp/index.js +169 -0
- package/dist/src/plugins/index.js +94 -3
- package/dist/src/providers/ids.js +3 -0
- package/dist/src/providers/ollama.js +2 -1
- package/dist/src/providers/openai.js +3 -2
- package/dist/src/syntax/index.js +240 -0
- package/dist/src/ui/App.js +268 -29
- package/dist/src/ui/Chat.js +11 -4
- package/dist/src/ui/ChatInput.js +128 -0
- package/dist/src/ui/CodeView.js +21 -5
- package/dist/src/ui/Editor.js +90 -21
- package/dist/src/ui/FileTree.js +6 -4
- package/dist/src/ui/Header.js +2 -2
- package/dist/src/ui/ProblemsView.js +71 -0
- package/dist/src/ui/Settings.js +30 -15
- package/dist/src/ui/text.js +6 -1
- package/dist/src/update/index.js +102 -0
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,55 +1,164 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/JorgeOchoaReyes/nou/HEAD/docs/banner.svg" alt="Nou: your AI coding companion, right in the terminal" width="100%">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/nou-cli"><img src="https://img.shields.io/npm/v/nou-cli?style=for-the-badge&color=bb9af7&labelColor=1a1b26&logo=npm&logoColor=white" alt="npm version"></a>
|
|
7
|
+
<a href="https://github.com/JorgeOchoaReyes/nou/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/JorgeOchoaReyes/nou/ci.yml?branch=master&style=for-the-badge&label=CI&labelColor=1a1b26&color=9ece6a&logo=githubactions&logoColor=white" alt="CI"></a>
|
|
8
|
+
<img src="https://img.shields.io/node/v/nou-cli?style=for-the-badge&color=7dcfff&labelColor=1a1b26&logo=nodedotjs&logoColor=white" alt="node version">
|
|
9
|
+
<img src="https://img.shields.io/npm/l/nou-cli?style=for-the-badge&color=e0af68&labelColor=1a1b26" alt="license">
|
|
10
|
+
</p>
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
<p align="center">
|
|
13
|
+
<img src="https://img.shields.io/badge/Ollama-local-9ece6a?style=flat-square&logo=ollama&logoColor=white&labelColor=1a1b26" alt="Ollama">
|
|
14
|
+
<img src="https://img.shields.io/badge/LM%20Studio-local-9ece6a?style=flat-square&labelColor=1a1b26" alt="LM Studio">
|
|
15
|
+
<img src="https://img.shields.io/badge/Claude-cloud-bb9af7?style=flat-square&logo=anthropic&logoColor=white&labelColor=1a1b26" alt="Claude">
|
|
16
|
+
<img src="https://img.shields.io/badge/OpenAI-cloud-bb9af7?style=flat-square&labelColor=1a1b26" alt="OpenAI">
|
|
17
|
+
<img src="https://img.shields.io/badge/Gemini-cloud-bb9af7?style=flat-square&logo=googlegemini&logoColor=white&labelColor=1a1b26" alt="Gemini">
|
|
18
|
+
<img src="https://img.shields.io/badge/OpenRouter%20·%20Groq%20·%20DeepSeek-cloud-bb9af7?style=flat-square&labelColor=1a1b26" alt="More providers">
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<b>An IDE that lives in your terminal.</b> Browse your code, watch the AI's edits as live side-by-side diffs,<br>
|
|
23
|
+
approve them with a keypress, edit files yourself, and switch between local and cloud models on the fly.
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<p align="center">
|
|
27
|
+
<img src="https://raw.githubusercontent.com/JorgeOchoaReyes/nou/HEAD/docs/screenshot.svg" alt="Nou proposing an edit as a side-by-side diff, with the file tree and chat" width="100%">
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## ⚡ Quick start
|
|
33
|
+
|
|
34
|
+
```bash
|
|
6
35
|
npm install -g nou-cli
|
|
7
36
|
cd your-project
|
|
8
37
|
nou
|
|
9
38
|
```
|
|
10
39
|
|
|
11
|
-
|
|
40
|
+
> [!TIP]
|
|
41
|
+
> Want it fully local and free? Install [Ollama](https://ollama.com), run `ollama pull qwen3:8b`, and you're set. That's the default model.
|
|
42
|
+
|
|
43
|
+
Needs **Node 22.12+** and an interactive terminal (Windows Terminal, PowerShell, macOS/Linux terminals).
|
|
44
|
+
|
|
45
|
+
## ✨ What it does
|
|
46
|
+
|
|
47
|
+
| | |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| 🗂️ **File explorer** | Browse your project with file icons and git status (`M` modified, `?` new). Press <kbd>c</kbd> to see only changed files. |
|
|
50
|
+
| 🔀 **Live diffs** | Every edit Nou proposes shows up side by side. <kbd>y</kbd> accepts, <kbd>n</kbd> rejects. Nothing touches disk without you. |
|
|
51
|
+
| ✍️ **Built-in editor** | Press <kbd>e</kbd> to edit the open file yourself, with undo/redo and **auto-save**. |
|
|
52
|
+
| ↶ **Undo anything** | Every change, Nou's or yours, is recorded. <kbd>u</kbd> undoes Nou's last edit, `/rewind` undoes its whole last turn, and your own later edits are kept. |
|
|
53
|
+
| 🩺 **Problems, live** | Syntax errors instantly, plus ESLint, TypeScript, Ruff and language servers when your project has them. Shown in the gutter, inline, and in a <kbd>p</kbd> Problems panel. |
|
|
54
|
+
| 🤖 **Self-correcting** | Nou checks its own edits: you see "⚠ +1 problem" *before* approving, and any problems it introduced are fed back so it fixes them. |
|
|
55
|
+
| 🎨 **Real syntax highlighting** | tree-sitter parsing for 14 languages (TS, JS, Python, Go, Rust, Java, C, JSON, YAML…). |
|
|
56
|
+
| 🧭 **Code intelligence** | <kbd>Ctrl</kbd>+<kbd>K</kbd> hover info and <kbd>Ctrl</kbd>+<kbd>G</kbd> go-to-definition via language servers (typescript-language-server, pyright, rust-analyzer, gopls, clangd). |
|
|
57
|
+
| 👀 **Knows what you're looking at** | The open file, visible lines, your cursor and unsaved edits ride along with each message. "Fix this function" just works. |
|
|
58
|
+
| 🌿 **Git aware** | Sees your branch, uncommitted changes and recent commits, and can diff on its own. Press <kbd>v</kbd> to diff any file against `HEAD`. |
|
|
59
|
+
| 🔌 **Any model** | Local (Ollama, LM Studio, llama.cpp) or cloud (Claude, OpenAI, Gemini, OpenRouter, Groq, DeepSeek). Switch mid-conversation. |
|
|
60
|
+
| 🧩 **Plugins** | Add your own tools and slash commands with a single file. |
|
|
61
|
+
| 🔎 **Quick open** | <kbd>Ctrl</kbd>+<kbd>P</kbd> fuzzy-finds any file. |
|
|
62
|
+
|
|
63
|
+
Every change is reviewed like a code review:
|
|
64
|
+
|
|
65
|
+
```diff
|
|
66
|
+
function resolveInProject(filePath: string): string {
|
|
67
|
+
- const fullPath = path.resolve(process.cwd(), filePath);
|
|
68
|
+
+ const root = realpathSync(process.cwd());
|
|
69
|
+
+ const fullPath = path.resolve(root, filePath);
|
|
70
|
+
```
|
|
12
71
|
|
|
13
|
-
##
|
|
72
|
+
## ⌨️ Keys
|
|
14
73
|
|
|
15
74
|
| Key | Does |
|
|
16
75
|
| --- | --- |
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
76
|
+
| <kbd>Tab</kbd> | switch between files, code and chat |
|
|
77
|
+
| <kbd>Ctrl</kbd>+<kbd>P</kbd> | fuzzy-find a file |
|
|
78
|
+
| <kbd>e</kbd> | edit the open file (<kbd>Ctrl</kbd>+<kbd>S</kbd> save · <kbd>Ctrl</kbd>+<kbd>Z</kbd>/<kbd>Y</kbd> undo/redo · <kbd>Ctrl</kbd>+<kbd>K</kbd> info · <kbd>Ctrl</kbd>+<kbd>G</kbd> definition · <kbd>Esc</kbd> close) |
|
|
79
|
+
| <kbd>p</kbd> | Problems panel: every error and warning, <kbd>Enter</kbd> jumps to it |
|
|
80
|
+
| <kbd>u</kbd> | undo Nou's last edit |
|
|
81
|
+
| <kbd>v</kbd> | diff the open file vs git `HEAD` (or Nou's last edit) · <kbd>n</kbd>/<kbd>N</kbd> jump between changes |
|
|
82
|
+
| <kbd>c</kbd> | in the file tree: show only changed files |
|
|
83
|
+
| <kbd>f</kbd> | follow mode: jump to files as Nou reads and edits them |
|
|
84
|
+
| <kbd>s</kbd> | settings: model, preferences, plugins |
|
|
85
|
+
| <kbd>y</kbd> / <kbd>n</kbd> | accept / reject a proposed edit or command |
|
|
86
|
+
| <kbd>Esc</kbd> | stop Nou · close a diff · back to chat |
|
|
87
|
+
| <kbd>Ctrl</kbd>+<kbd>C</kbd> | stop Nou while it works · press twice to quit |
|
|
26
88
|
|
|
27
|
-
|
|
89
|
+
Chat commands: `/settings` · `/model [provider:model]` · `/models [provider]` · `/undo` · `/rewind` · `/history` · `/problems` · `/clear` · `/help`
|
|
28
90
|
|
|
29
|
-
|
|
91
|
+
## 🧠 Models
|
|
30
92
|
|
|
31
|
-
|
|
93
|
+
Pick one in <kbd>s</kbd> settings, with `/model anthropic` or `/model ollama:qwen3:8b`, or set `NOU_MODEL=provider:model`. API keys come from your environment or a `.env` file in your project; see [.env.example](.env.example).
|
|
32
94
|
|
|
33
|
-
|
|
95
|
+
<details>
|
|
96
|
+
<summary><b>All providers and how to set them up</b></summary>
|
|
34
97
|
|
|
35
|
-
| Provider | Setup |
|
|
36
|
-
| --- | --- |
|
|
37
|
-
| Ollama (default) | runs locally
|
|
38
|
-
| LM Studio
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
98
|
+
| Provider | Type | Setup |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| 🦙 Ollama *(default)* | 🟢 local | runs locally · `OLLAMA_HOST` to change |
|
|
101
|
+
| 🖥️ LM Studio | 🟢 local | start its local server |
|
|
102
|
+
| ⚙️ llama.cpp server | 🟢 local | start `llama-server` |
|
|
103
|
+
| 🔧 Any OpenAI-compatible server | 🟢 local | `NOU_BASE_URL`, optional `NOU_API_KEY` |
|
|
104
|
+
| 🟣 Anthropic (Claude) | ☁️ cloud | `ANTHROPIC_API_KEY` |
|
|
105
|
+
| ⚪ OpenAI | ☁️ cloud | `OPENAI_API_KEY` |
|
|
106
|
+
| 🔷 Google Gemini | ☁️ cloud | `GEMINI_API_KEY` |
|
|
107
|
+
| 🔀 OpenRouter | ☁️ cloud | `OPENROUTER_API_KEY` |
|
|
108
|
+
| ⚡ Groq | ☁️ cloud | `GROQ_API_KEY` |
|
|
109
|
+
| 🐋 DeepSeek | ☁️ cloud | `DEEPSEEK_API_KEY` |
|
|
110
|
+
|
|
111
|
+
</details>
|
|
112
|
+
|
|
113
|
+
## 🔄 Updating
|
|
114
|
+
|
|
115
|
+
Nou checks npm once a day and offers to update when a new version is out (one keypress, then it restarts itself). Or run it yourself:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
nou update # or: npm install -g nou-cli@latest
|
|
119
|
+
nou --version
|
|
120
|
+
```
|
|
42
121
|
|
|
43
|
-
|
|
122
|
+
Set `NOU_NO_UPDATE_CHECK=1` to turn the check off.
|
|
44
123
|
|
|
45
|
-
|
|
124
|
+
## 🧩 Plugins *(early)*
|
|
46
125
|
|
|
47
|
-
|
|
126
|
+
Drop a `.js` / `.mjs` file into `.nou/plugins/` (this project) or `~/.nou/plugins/` (everywhere), then switch it on in <kbd>s</kbd> settings → **Plugins**. A plugin can give the model new tools, add slash commands, add to the system prompt, and add **checkers** (linters) whose problems show in the editor. The built-in ESLint, TypeScript, Ruff, syntax and language-server checkers are plugins too, so you can switch any of them off.
|
|
48
127
|
|
|
128
|
+
```js
|
|
129
|
+
export default {
|
|
130
|
+
name: "word-count",
|
|
131
|
+
tools: [{ readOnly: true, definition: { name: "word_count", /* ... */ }, run: (args) => "42 words" }],
|
|
132
|
+
commands: [{ name: "wc", description: "Count words", run: (args) => "42 words" }],
|
|
133
|
+
diagnostics: [{
|
|
134
|
+
id: "todo", name: "TODOs", checksText: true, matches: (f) => f.endsWith(".ts"), available: () => true,
|
|
135
|
+
check: async (file, text) => text.split("\n").flatMap((l, i) => l.includes("TODO")
|
|
136
|
+
? [{ file, line: i + 1, col: 1, severity: "info", message: "TODO left here", source: "todo" }] : []),
|
|
137
|
+
}],
|
|
138
|
+
};
|
|
49
139
|
```
|
|
140
|
+
|
|
141
|
+
Full example: [examples/plugins/word-count.mjs](examples/plugins/word-count.mjs).
|
|
142
|
+
|
|
143
|
+
> [!WARNING]
|
|
144
|
+
> Plugins run code on your machine, so they stay **off** until you enable them.
|
|
145
|
+
|
|
146
|
+
## 🛠️ Development
|
|
147
|
+
|
|
148
|
+
```bash
|
|
50
149
|
npm install
|
|
51
|
-
npm run dev
|
|
52
|
-
npm run build
|
|
150
|
+
npm run dev # run from source
|
|
151
|
+
npm run build # compile to dist/ (and copy the syntax grammars)
|
|
152
|
+
npm test # end-to-end tests: drives the real UI with simulated keys
|
|
153
|
+
npm run screenshot # regenerate docs/screenshot.svg
|
|
53
154
|
```
|
|
54
155
|
|
|
55
|
-
|
|
156
|
+
Releasing: bump `version` in `package.json`, merge to `master`, then run **Actions → Publish to npm**. It tests, publishes with provenance, and creates the git tag and GitHub Release. (Or publish a GitHub release tagged `vX.Y.Z`.) The token lives in the `production` environment as `NPM_TOKEN`.
|
|
157
|
+
|
|
158
|
+
Upkeep runs on its own:
|
|
159
|
+
- **CI** on every PR: type-check, lint, build, unit and end-to-end tests on Linux, macOS and Windows (Node 22.12 and 24 too), plus installing the packed tarball to check the package works.
|
|
160
|
+
- **Dependabot** opens weekly PRs for dependency and GitHub Actions updates.
|
|
161
|
+
- **CodeQL** scans for security issues on every PR and weekly.
|
|
162
|
+
- **npm audit** fails CI if a dependency users install has a high-severity vulnerability.
|
|
163
|
+
|
|
164
|
+
<p align="center"><sub>Made with 🌞 by <a href="https://github.com/JorgeOchoaReyes">Jorge Ochoa-Reyes</a></sub></p>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
// Must stay the first import: loads .env before any provider reads its keys and URLs.
|
|
3
|
+
import "./src/env.js";
|
|
3
4
|
import { createElement } from "react";
|
|
4
5
|
import { render } from "ink";
|
|
5
6
|
import * as p from "@clack/prompts";
|
|
@@ -7,16 +8,61 @@ import chalk from "chalk";
|
|
|
7
8
|
import { artWork } from "./src/util/index.js";
|
|
8
9
|
import { ensureProjectContext, loadPermanentContext } from "./src/context/index.js";
|
|
9
10
|
import { describe, initialModel, resolveModel } from "./src/providers/index.js";
|
|
11
|
+
import { checkForUpdate, currentVersion, installUpdate, relaunch } from "./src/update/index.js";
|
|
12
|
+
import { lsp } from "./src/lsp/index.js";
|
|
10
13
|
import { App } from "./src/ui/App.js";
|
|
14
|
+
const HELP = `nou ${currentVersion()}: an AI coding assistant for your terminal
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
nou open Nou in the current folder
|
|
18
|
+
nou update update to the latest version
|
|
19
|
+
nou --version print the version
|
|
20
|
+
nou --help show this help
|
|
21
|
+
|
|
22
|
+
Settings live in ~/.nou/config.json (or press s inside Nou). Set NOU_NO_UPDATE_CHECK=1 to skip update checks.`;
|
|
11
23
|
async function main() {
|
|
24
|
+
const args = process.argv.slice(2);
|
|
25
|
+
if (args.includes("--version") || args.includes("-v")) {
|
|
26
|
+
console.log(currentVersion());
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
30
|
+
console.log(HELP);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (args[0] === "update") {
|
|
34
|
+
const latest = await checkForUpdate({ force: true, timeout: 10_000 });
|
|
35
|
+
if (!latest) {
|
|
36
|
+
console.log(`nou ${currentVersion()} is up to date.`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
console.log(`Updating nou ${currentVersion()} → ${latest}...`);
|
|
40
|
+
if (await installUpdate(latest))
|
|
41
|
+
process.exit(0);
|
|
42
|
+
if (process.platform !== "win32")
|
|
43
|
+
console.log("If that was a permissions error, run: sudo npm install -g nou-cli@latest");
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
12
46
|
if (!process.stdin.isTTY) {
|
|
13
|
-
console.error("Nou needs an interactive terminal (try Windows Terminal /
|
|
47
|
+
console.error("Nou needs an interactive terminal (try Windows Terminal, PowerShell, or Terminal/iTerm on macOS).");
|
|
14
48
|
process.exit(1);
|
|
15
49
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
50
|
+
p.intro(chalk.cyan(`${artWork} \n Hello I am Nou! 🌞 ${chalk.dim(`v${currentVersion()}`)}`));
|
|
51
|
+
const latest = await checkForUpdate();
|
|
52
|
+
if (latest) {
|
|
53
|
+
const update = await p.confirm({ message: `Nou ${chalk.green(latest)} is available (you have ${currentVersion()}). Update now?` });
|
|
54
|
+
if (update === true) {
|
|
55
|
+
const ok = await installUpdate(latest);
|
|
56
|
+
if (ok) {
|
|
57
|
+
p.log.success(`Updated to ${latest}. Restarting...`);
|
|
58
|
+
relaunch();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
p.log.warn(process.platform === "win32"
|
|
62
|
+
? "The update failed. You can retry later with: npm install -g nou-cli@latest"
|
|
63
|
+
: "The update failed. If it was a permissions error, run: sudo npm install -g nou-cli@latest");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
20
66
|
let choice = initialModel();
|
|
21
67
|
const problem = choice.provider.unavailable();
|
|
22
68
|
if (problem) {
|
|
@@ -26,10 +72,13 @@ async function main() {
|
|
|
26
72
|
p.log.info(`Model: ${chalk.yellow(describe(choice))} (change it any time with /model)`);
|
|
27
73
|
await ensureProjectContext(choice);
|
|
28
74
|
const permContext = await loadPermanentContext();
|
|
75
|
+
// Ctrl+C is handled inside the app: press it twice to quit, so a stray press doesn't lose work.
|
|
29
76
|
const app = render(createElement(App, { initialModel: choice, permContext }), {
|
|
30
77
|
alternateScreen: true,
|
|
78
|
+
exitOnCtrlC: false,
|
|
31
79
|
});
|
|
32
80
|
await app.waitUntilExit();
|
|
81
|
+
lsp.stopAll();
|
|
33
82
|
p.outro(chalk.cyan("Bye bye!"));
|
|
34
83
|
}
|
|
35
84
|
main().catch(console.error);
|
package/dist/src/agent/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { toolDefs } from "../tools/index.js";
|
|
2
2
|
import { applyChange, fileTree, proposeEdit, proposeWrite, readFile, runCommand, toRelative, } from "../commands/index.js";
|
|
3
3
|
import { describe } from "../providers/index.js";
|
|
4
|
+
import { newCallId } from "../providers/ids.js";
|
|
4
5
|
const MAX_STEPS = 25;
|
|
5
6
|
export function buildSystemPrompt(permContext, extras = []) {
|
|
6
7
|
return `You are Nou, a coding assistant running in the user's terminal, working in ${process.cwd()}.
|
|
@@ -32,6 +33,14 @@ export class Agent {
|
|
|
32
33
|
controller = null;
|
|
33
34
|
extraTools = [];
|
|
34
35
|
effort;
|
|
36
|
+
notes = [];
|
|
37
|
+
/** Increments per user message; tags changes so a whole turn can be rewound. */
|
|
38
|
+
turn = 0;
|
|
39
|
+
/** Distinguishes this run from earlier ones, since turn numbers restart at 1 every session. */
|
|
40
|
+
session = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
41
|
+
get turnId() {
|
|
42
|
+
return `${this.session}:${this.turn}`;
|
|
43
|
+
}
|
|
35
44
|
constructor(choice, system, hooks) {
|
|
36
45
|
this.choice = choice;
|
|
37
46
|
this.system = system;
|
|
@@ -54,13 +63,21 @@ export class Agent {
|
|
|
54
63
|
}
|
|
55
64
|
clear() {
|
|
56
65
|
this.messages = [];
|
|
66
|
+
this.notes = [];
|
|
67
|
+
}
|
|
68
|
+
/** Something the model should know before the next message (e.g. the user undid its edit). */
|
|
69
|
+
note(text) {
|
|
70
|
+
this.notes.push(text);
|
|
57
71
|
}
|
|
58
72
|
cancel() {
|
|
59
73
|
this.controller?.abort();
|
|
60
74
|
}
|
|
61
75
|
/** `context` (what the user is looking at) is sent to the model but not shown in the chat. */
|
|
62
76
|
async send(text, context) {
|
|
63
|
-
this.
|
|
77
|
+
this.turn++;
|
|
78
|
+
const notes = this.notes.length ? `${this.notes.map((n) => `[Note: ${n}]`).join("\n")}\n\n` : "";
|
|
79
|
+
this.notes = [];
|
|
80
|
+
this.messages.push({ role: "user", content: `${notes}${text}${context ? `\n\n${context}` : ""}` });
|
|
64
81
|
this.controller = new AbortController();
|
|
65
82
|
const { signal } = this.controller;
|
|
66
83
|
try {
|
|
@@ -80,6 +97,15 @@ export class Agent {
|
|
|
80
97
|
},
|
|
81
98
|
});
|
|
82
99
|
this.hooks.onStream("");
|
|
100
|
+
// Tool-call ids must be unique across the conversation (results are matched by id, and some APIs
|
|
101
|
+
// reject duplicates). Some providers reuse ids, so rename any repeat. Claude's own copy of the turn
|
|
102
|
+
// (raw) keeps its ids, which the API guarantees are unique.
|
|
103
|
+
const used = new Set(this.messages.flatMap((m) => (m.role === "assistant" ? m.toolCalls.map((c) => c.id) : [])));
|
|
104
|
+
for (const call of result.toolCalls) {
|
|
105
|
+
if (used.has(call.id) && !result.raw)
|
|
106
|
+
call.id = newCallId();
|
|
107
|
+
used.add(call.id);
|
|
108
|
+
}
|
|
83
109
|
this.messages.push({
|
|
84
110
|
role: "assistant",
|
|
85
111
|
content: result.text,
|
|
@@ -199,16 +225,22 @@ export class Agent {
|
|
|
199
225
|
}
|
|
200
226
|
}
|
|
201
227
|
async reviewChange(change) {
|
|
202
|
-
this.hooks.onChange(change, "pending");
|
|
228
|
+
this.hooks.onChange(change, "pending", this.turnId);
|
|
203
229
|
const ok = await this.hooks.approve({ kind: "change", change });
|
|
204
230
|
if (!ok) {
|
|
205
|
-
this.hooks.onChange(change, "rejected");
|
|
231
|
+
this.hooks.onChange(change, "rejected", this.turnId);
|
|
206
232
|
this.hooks.onEntry({ kind: "tool", text: `Rejected edit to ${change.path}` });
|
|
207
233
|
return "User rejected this change. Ask them what they would like instead.";
|
|
208
234
|
}
|
|
209
235
|
const result = await applyChange(change);
|
|
210
|
-
this.hooks.onChange(change, "applied");
|
|
236
|
+
this.hooks.onChange(change, "applied", this.turnId);
|
|
211
237
|
this.hooks.onEntry({ kind: "tool", text: result });
|
|
212
|
-
|
|
238
|
+
if (result.startsWith("Failed"))
|
|
239
|
+
return result;
|
|
240
|
+
this.hooks.onBusy(`Checking ${change.path} for problems...`);
|
|
241
|
+
const problems = await this.hooks.checkChange?.(change).catch(() => null);
|
|
242
|
+
if (problems)
|
|
243
|
+
this.hooks.onEntry({ kind: "error", text: `New problems in ${change.path}:\n${problems}` });
|
|
244
|
+
return problems ? `${result}\n\nThis edit introduced problems; fix them:\n${problems}` : result;
|
|
213
245
|
}
|
|
214
246
|
}
|
|
@@ -63,12 +63,22 @@ export function fileTree(dir = ".", maxDepth = 3) {
|
|
|
63
63
|
walk(path.resolve(process.cwd(), dir), 1, "");
|
|
64
64
|
return lines.join("\n") || "(empty)";
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Undoes common model mistakes in write_file content without touching real code:
|
|
68
|
+
* - a whole file sent as one line with literal "\n" escapes (no real newlines at all) is unescaped;
|
|
69
|
+
* files that already have real newlines are left alone, so "\n" inside strings and regexes survives
|
|
70
|
+
* - a whole file wrapped in a markdown code fence is unwrapped
|
|
71
|
+
* Indentation and blank lines are kept; a final newline is added if missing.
|
|
72
|
+
*/
|
|
73
|
+
export function cleanContent(content) {
|
|
74
|
+
let text = content;
|
|
75
|
+
if (!text.includes("\n") && text.includes("\\n")) {
|
|
76
|
+
text = text.replace(/\\r\\n|\\n/g, "\n").replace(/\\t/g, "\t");
|
|
77
|
+
}
|
|
78
|
+
const fenced = text.match(/^\s*```[\w+-]*\r?\n([\s\S]*?)\r?\n```\s*$/);
|
|
79
|
+
if (fenced)
|
|
80
|
+
text = fenced[1];
|
|
81
|
+
return text.endsWith("\n") || text === "" ? text : `${text}\n`;
|
|
72
82
|
}
|
|
73
83
|
async function readOrEmpty(fullPath) {
|
|
74
84
|
try {
|
package/dist/src/config/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from "path";
|
|
|
4
4
|
export const NOU_HOME = path.join(os.homedir(), ".nou");
|
|
5
5
|
const CONFIG_PATH = path.join(NOU_HOME, "config.json");
|
|
6
6
|
export const EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
7
|
+
export const AUTO_SAVE = ["delay", "focus", "off"];
|
|
7
8
|
export const DEFAULT_SETTINGS = {
|
|
8
9
|
model: "",
|
|
9
10
|
effort: "high",
|
|
@@ -11,15 +12,17 @@ export const DEFAULT_SETTINGS = {
|
|
|
11
12
|
autoApproveEdits: false,
|
|
12
13
|
autoApproveCommands: false,
|
|
13
14
|
gitContext: true,
|
|
15
|
+
autoSave: "delay",
|
|
14
16
|
plugins: {},
|
|
17
|
+
trustedPlugins: {},
|
|
15
18
|
};
|
|
16
19
|
export function loadSettings() {
|
|
17
20
|
try {
|
|
18
21
|
const saved = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
19
|
-
return { ...DEFAULT_SETTINGS, ...saved, plugins: { ...saved.plugins } };
|
|
22
|
+
return { ...DEFAULT_SETTINGS, ...saved, plugins: { ...saved.plugins }, trustedPlugins: { ...saved.trustedPlugins } };
|
|
20
23
|
}
|
|
21
24
|
catch {
|
|
22
|
-
return { ...DEFAULT_SETTINGS, plugins: {} };
|
|
25
|
+
return { ...DEFAULT_SETTINGS, plugins: {}, trustedPlugins: {} };
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
export function saveSettings(patch) {
|