nou-cli 0.1.0 → 0.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.
Files changed (45) hide show
  1. package/README.md +142 -31
  2. package/dist/grammars/tree-sitter-bash.wasm +0 -0
  3. package/dist/grammars/tree-sitter-c.wasm +0 -0
  4. package/dist/grammars/tree-sitter-css.wasm +0 -0
  5. package/dist/grammars/tree-sitter-go.wasm +0 -0
  6. package/dist/grammars/tree-sitter-html.wasm +0 -0
  7. package/dist/grammars/tree-sitter-java.wasm +0 -0
  8. package/dist/grammars/tree-sitter-javascript.wasm +0 -0
  9. package/dist/grammars/tree-sitter-json.wasm +0 -0
  10. package/dist/grammars/tree-sitter-python.wasm +0 -0
  11. package/dist/grammars/tree-sitter-rust.wasm +0 -0
  12. package/dist/grammars/tree-sitter-toml.wasm +0 -0
  13. package/dist/grammars/tree-sitter-tsx.wasm +0 -0
  14. package/dist/grammars/tree-sitter-typescript.wasm +0 -0
  15. package/dist/grammars/tree-sitter-yaml.wasm +0 -0
  16. package/dist/index.js +55 -6
  17. package/dist/src/agent/index.js +37 -5
  18. package/dist/src/commands/index.js +16 -6
  19. package/dist/src/config/index.js +6 -2
  20. package/dist/src/diagnostics/index.js +235 -0
  21. package/dist/src/diagnostics/process.js +64 -0
  22. package/dist/src/diagnostics/providers.js +103 -0
  23. package/dist/src/diagnostics/types.js +1 -0
  24. package/dist/src/env.js +12 -0
  25. package/dist/src/history/index.js +113 -0
  26. package/dist/src/lsp/client.js +169 -0
  27. package/dist/src/lsp/index.js +169 -0
  28. package/dist/src/plugins/index.js +94 -3
  29. package/dist/src/providers/ids.js +3 -0
  30. package/dist/src/providers/ollama.js +2 -1
  31. package/dist/src/providers/openai.js +3 -2
  32. package/dist/src/syntax/index.js +240 -0
  33. package/dist/src/ui/App.js +299 -30
  34. package/dist/src/ui/Chat.js +19 -6
  35. package/dist/src/ui/ChatInput.js +128 -0
  36. package/dist/src/ui/CodeView.js +25 -5
  37. package/dist/src/ui/Editor.js +94 -21
  38. package/dist/src/ui/FileTree.js +23 -4
  39. package/dist/src/ui/Header.js +4 -2
  40. package/dist/src/ui/ProblemsView.js +75 -0
  41. package/dist/src/ui/Settings.js +31 -15
  42. package/dist/src/ui/mouse.js +52 -0
  43. package/dist/src/ui/text.js +6 -1
  44. package/dist/src/update/index.js +102 -0
  45. package/package.json +10 -5
package/README.md CHANGED
@@ -1,55 +1,166 @@
1
- # Nou
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
- An IDE-style AI coding assistant that lives in your terminal: file explorer, code view with live side-by-side diffs, a built-in editor, and a chat with an agent that reads, edits and runs things in your project. Works with local models (Ollama, LM Studio, llama.cpp) and cloud ones (Claude, OpenAI, Gemini, OpenRouter, Groq, DeepSeek).
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
- Needs Node 20.12+ and an interactive terminal (Windows Terminal, PowerShell, macOS/Linux terminals). For local models, install [Ollama](https://ollama.com) and pull a model, e.g. `ollama pull qwen3:8b` (the default).
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
- ## Using it
72
+ ## ⌨️ Keys
14
73
 
15
74
  | Key | Does |
16
75
  | --- | --- |
17
- | `Tab` | switch between files, code and chat |
18
- | `Ctrl+P` | fuzzy-find a file |
19
- | `e` | edit the open file (`Ctrl+S` save, `Ctrl+Z` undo, `Esc` close) |
20
- | `v` | diff the open file against git `HEAD` (or Nou's last edit) |
21
- | `c` | in the file tree, show only changed files |
22
- | `f` | follow mode: jump to files Nou is reading/editing |
23
- | `s` or `/settings` | settings: model, preferences, plugins |
24
- | `y` / `n` | accept / reject a proposed edit or command |
25
- | `Esc` | stop Nou, close a diff, back to chat |
76
+ | 🖱️ Mouse | wheel scrolls the pane under the pointer · click a pane to focus it · click a file to open it (hold <kbd>Shift</kbd> to select text; turn off in settings) |
77
+ | <kbd>Shift</kbd>+<kbd>↑</kbd>/<kbd>↓</kbd>, <kbd>PgUp</kbd>/<kbd>PgDn</kbd> | scroll the chat history |
78
+ | <kbd>Tab</kbd> | switch between files, code and chat |
79
+ | <kbd>Ctrl</kbd>+<kbd>P</kbd> | fuzzy-find a file |
80
+ | <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) |
81
+ | <kbd>p</kbd> | Problems panel: every error and warning, <kbd>Enter</kbd> jumps to it |
82
+ | <kbd>u</kbd> | undo Nou's last edit |
83
+ | <kbd>v</kbd> | diff the open file vs git `HEAD` (or Nou's last edit) · <kbd>n</kbd>/<kbd>N</kbd> jump between changes |
84
+ | <kbd>c</kbd> | in the file tree: show only changed files |
85
+ | <kbd>f</kbd> | follow mode: jump to files as Nou reads and edits them |
86
+ | <kbd>s</kbd> | settings: model, preferences, plugins |
87
+ | <kbd>y</kbd> / <kbd>n</kbd> | accept / reject a proposed edit or command |
88
+ | <kbd>Esc</kbd> | stop Nou · close a diff · back to chat |
89
+ | <kbd>Ctrl</kbd>+<kbd>C</kbd> | stop Nou while it works · press twice to quit |
26
90
 
27
- Nou sees what you're looking at: the open file and visible lines (or your cursor line and unsaved edits while editing) are attached to each message, so "explain this function" just works. In a git repo it also gets your branch, uncommitted changes and recent commits, plus `git_status` / `git_diff` / `git_log` tools.
91
+ Chat commands: `/settings` · `/model [provider:model]` · `/models [provider]` · `/undo` · `/rewind` · `/history` · `/problems` · `/clear` · `/help`
28
92
 
29
- Chat commands: `/settings`, `/model [provider:model]`, `/models [provider]`, `/clear`, `/help`.
93
+ ## 🧠 Models
30
94
 
31
- ## Models
95
+ 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
96
 
33
- Pick one in `/settings`, with `/model anthropic`, `/model ollama:qwen3:8b`, or `NOU_MODEL=provider:model`. API keys come from your environment or a `.env` file in the project; see [.env.example](.env.example).
97
+ <details>
98
+ <summary><b>All providers and how to set them up</b></summary>
34
99
 
35
- | Provider | Setup |
36
- | --- | --- |
37
- | Ollama (default) | runs locally, `OLLAMA_HOST` to change |
38
- | LM Studio, llama.cpp | start their local server |
39
- | Any OpenAI-compatible server | `NOU_BASE_URL`, optional `NOU_API_KEY` |
40
- | Anthropic | `ANTHROPIC_API_KEY` |
41
- | OpenAI / Gemini / OpenRouter / Groq / DeepSeek | `OPENAI_API_KEY` / `GEMINI_API_KEY` / `OPENROUTER_API_KEY` / `GROQ_API_KEY` / `DEEPSEEK_API_KEY` |
100
+ | Provider | Type | Setup |
101
+ | --- | --- | --- |
102
+ | 🦙 Ollama *(default)* | 🟢 local | runs locally · `OLLAMA_HOST` to change |
103
+ | 🖥️ LM Studio | 🟢 local | start its local server |
104
+ | ⚙️ llama.cpp server | 🟢 local | start `llama-server` |
105
+ | 🔧 Any OpenAI-compatible server | 🟢 local | `NOU_BASE_URL`, optional `NOU_API_KEY` |
106
+ | 🟣 Anthropic (Claude) | ☁️ cloud | `ANTHROPIC_API_KEY` |
107
+ | ⚪ OpenAI | ☁️ cloud | `OPENAI_API_KEY` |
108
+ | 🔷 Google Gemini | ☁️ cloud | `GEMINI_API_KEY` |
109
+ | 🔀 OpenRouter | ☁️ cloud | `OPENROUTER_API_KEY` |
110
+ | ⚡ Groq | ☁️ cloud | `GROQ_API_KEY` |
111
+ | 🐋 DeepSeek | ☁️ cloud | `DEEPSEEK_API_KEY` |
112
+
113
+ </details>
114
+
115
+ ## 🔄 Updating
116
+
117
+ 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:
118
+
119
+ ```bash
120
+ nou update # or: npm install -g nou-cli@latest
121
+ nou --version
122
+ ```
42
123
 
43
- ## Plugins (early)
124
+ Set `NOU_NO_UPDATE_CHECK=1` to turn the check off.
44
125
 
45
- Drop a `.js`/`.mjs` file into `.nou/plugins/` (project) or `~/.nou/plugins/` (everywhere), then enable it in `/settings → Plugins`. A plugin can add tools for the model, slash commands, and system prompt text. See [examples/plugins/word-count.mjs](examples/plugins/word-count.mjs). Plugins run code on your machine, so they stay off until you enable them.
126
+ ## 🧩 Plugins *(early)*
46
127
 
47
- ## Development
128
+ 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
129
 
130
+ ```js
131
+ export default {
132
+ name: "word-count",
133
+ tools: [{ readOnly: true, definition: { name: "word_count", /* ... */ }, run: (args) => "42 words" }],
134
+ commands: [{ name: "wc", description: "Count words", run: (args) => "42 words" }],
135
+ diagnostics: [{
136
+ id: "todo", name: "TODOs", checksText: true, matches: (f) => f.endsWith(".ts"), available: () => true,
137
+ check: async (file, text) => text.split("\n").flatMap((l, i) => l.includes("TODO")
138
+ ? [{ file, line: i + 1, col: 1, severity: "info", message: "TODO left here", source: "todo" }] : []),
139
+ }],
140
+ };
49
141
  ```
142
+
143
+ Full example: [examples/plugins/word-count.mjs](examples/plugins/word-count.mjs).
144
+
145
+ > [!WARNING]
146
+ > Plugins run code on your machine, so they stay **off** until you enable them.
147
+
148
+ ## 🛠️ Development
149
+
150
+ ```bash
50
151
  npm install
51
- npm run dev # run from source
52
- npm run build # compile to dist/
152
+ npm run dev # run from source
153
+ npm run build # compile to dist/ (and copy the syntax grammars)
154
+ npm test # end-to-end tests: drives the real UI with simulated keys
155
+ npm run screenshot # regenerate docs/screenshot.svg
53
156
  ```
54
157
 
55
- Releases: create a GitHub release tagged `vX.Y.Z` and the Publish workflow builds and publishes that version to npm (needs an `NPM_TOKEN` secret in the `production` environment).
158
+ 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`.
159
+
160
+ Upkeep runs on its own:
161
+ - **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.
162
+ - **Dependabot** opens weekly PRs for dependency and GitHub Actions updates.
163
+ - **CodeQL** scans for security issues on every PR and weekly.
164
+ - **npm audit** fails CI if a dependency users install has a high-severity vulnerability.
165
+
166
+ <p align="center"><sub>Made with 🌞 by <a href="https://github.com/JorgeOchoaReyes">Jorge Ochoa-Reyes</a></sub></p>
Binary file
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { existsSync } from "fs";
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 / PowerShell).");
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
- // API keys can live in a .env next to the project (it's gitignored).
17
- if (existsSync(".env"))
18
- process.loadEnvFile(".env");
19
- p.intro(chalk.cyan(`${artWork} \n Hello I am Nou! 🌞`));
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);
@@ -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.messages.push({ role: "user", content: context ? `${text}\n\n${context}` : text });
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
- return result;
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
- function cleanContent(content) {
67
- return content
68
- .replace(/\\n/g, "\n")
69
- .replace(/^```[a-z]*\n/i, "")
70
- .replace(/\n```$/g, "")
71
- .trim() + "\n";
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 {
@@ -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,18 @@ export const DEFAULT_SETTINGS = {
11
12
  autoApproveEdits: false,
12
13
  autoApproveCommands: false,
13
14
  gitContext: true,
15
+ autoSave: "delay",
16
+ mouse: true,
14
17
  plugins: {},
18
+ trustedPlugins: {},
15
19
  };
16
20
  export function loadSettings() {
17
21
  try {
18
22
  const saved = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
19
- return { ...DEFAULT_SETTINGS, ...saved, plugins: { ...saved.plugins } };
23
+ return { ...DEFAULT_SETTINGS, ...saved, plugins: { ...saved.plugins }, trustedPlugins: { ...saved.trustedPlugins } };
20
24
  }
21
25
  catch {
22
- return { ...DEFAULT_SETTINGS, plugins: {} };
26
+ return { ...DEFAULT_SETTINGS, plugins: {}, trustedPlugins: {} };
23
27
  }
24
28
  }
25
29
  export function saveSettings(patch) {