nanocode-cli 0.5.4__tar.gz → 0.5.9__tar.gz

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.
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ include README.zh-CN.md
3
+ prune demo*
4
+ prune tests
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nanocode-cli
3
- Version: 0.5.4
3
+ Version: 0.5.9
4
4
  Summary: A small terminal coding agent written in Python
5
5
  Author-email: hit9 <hit9@icloud.com>
6
6
  License-Expression: BSD-3-Clause
@@ -23,6 +23,7 @@ Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: anthropic>=0.64.0
25
25
  Requires-Dist: code-symbol-index>=0.1.13
26
+ Requires-Dist: json-repair
26
27
  Requires-Dist: openai>=2.37.0
27
28
  Requires-Dist: prompt-toolkit>=3.0
28
29
  Requires-Dist: rich>=13.0
@@ -36,18 +37,22 @@ Dynamic: license-file
36
37
 
37
38
  A small terminal coding agent written in Python.
38
39
 
40
+ [简体中文](README.zh-CN.md)
41
+
39
42
  nanocode is pre-1.0 software. Commands, configuration, and tool behavior may change before a stable release.
40
43
 
41
44
  ![nanocode screenshot](snapshots/nanocode-snapshot.png)
42
45
 
43
46
  ## Features
44
47
 
45
- - **Snapshot context**: Every turn starts from a clean workspace snapshot instead of a bloated chat replay.
46
- - **File memory**: Recent reads and edits stay available as focused, line-numbered file ranges.
47
- - **Anchored edits**: `line:hash` anchors catch stale edits before they touch the wrong code.
48
- - **Symbol index**: Jump from names to outlines, references, and changed files without searching blindly.
49
- - **Tool recall**: Big outputs are bounded in the prompt but still recallable later by `tr.N`.
50
- - **Terminal-native UI**: Model picking, history search, confirmations, live command output, and status all stay in the terminal.
48
+ - **Live turn control**: Add follow-up input while the agent is still working, without losing the current tool flow.
49
+ - **File-state brain**: Reads and edits build a current, line-numbered view of the files that matter now.
50
+ - **Stale-edit protection**: `line:hash` anchors reject edits when the target code has drifted.
51
+ - **Project-aware navigation**: Use the symbol index to jump through outlines, references, and changed files quickly.
52
+ - **Recoverable context**: Tool output stays bounded in the prompt, while raw `tr.N` results remain recallable.
53
+ - **Cache-aware context**: Stable sections stay early and noisy working state stays late to improve prompt-cache reuse.
54
+ - **Focused working memory**: `Note` separates goal, plan, and known facts from noisy execution logs.
55
+ - **Terminal-first workflow**: Model selection, history search, confirmations, live command output, appended input, and status all stay in one CLI.
51
56
 
52
57
  ## Install
53
58
 
@@ -55,6 +60,12 @@ nanocode is pre-1.0 software. Commands, configuration, and tool behavior may cha
55
60
  uv tool install nanocode-cli
56
61
  ```
57
62
 
63
+ Upgrade:
64
+
65
+ ```sh
66
+ uv tool upgrade nanocode-cli
67
+ ```
68
+
58
69
  For local development:
59
70
 
60
71
  ```sh
@@ -77,6 +88,8 @@ Useful arguments:
77
88
  - `--yolo`: skip confirmations for mutating tools.
78
89
  - `-v`, `--version`: show the version.
79
90
 
91
+ During a running turn, the `+>` prompt accepts follow-up input for the next model request.
92
+
80
93
  ## Commands
81
94
 
82
95
  - `/help`: show commands and tools.
@@ -99,9 +112,10 @@ Interactive selectors support `j`/`k`, arrows, `/` search, Enter, and Esc. Input
99
112
 
100
113
  - File: `Read`, `LineCount`, `List`, `Find`, `Search`.
101
114
  - Code index: `InspectCode`.
102
- - Edit: `CreateFile`, `Edit`.
115
+ - Edit: `Edit` creates or patches file content.
103
116
  - Shell: `Bash`, `Git`.
104
- - Tool results: `Recall`, `Forget`.
117
+ - Tool results: `Recall`.
118
+ - Working notes: `Note`.
105
119
 
106
120
  `Read`, `Search`, and `InspectCode` return line anchors where useful. `Edit` uses current `line:hash` anchors to reject stale edits.
107
121
 
@@ -126,7 +140,7 @@ Main fields:
126
140
 
127
141
  ## Context Design
128
142
 
129
- Each model request is built manually as one system message and one user message. The user message is a structured context snapshot, ordered from stable sections to volatile sections so provider prompt caching can reuse the prefix.
143
+ Each model request is built manually from explicit messages. Stable context comes first, conversation stays as messages, working memory follows, and the latest file state is appended at the end.
130
144
 
131
145
  ```text
132
146
  model request
@@ -136,27 +150,27 @@ model request
136
150
  +--------------------------------------------------+
137
151
  | user |
138
152
  | Environment |
139
- | State |
140
- | Summary |
141
- | Recent Conversation |
142
- | Tool Result Index |
143
- | File Context |
144
- | Discovery Context |
145
- | Error Feedback |
146
- | Latest Tool Results |
147
- | Current Turn Conversation |
153
+ +--------------------------------------------------+
154
+ | user/assistant |
155
+ | conversation, compacted summaries, tools |
156
+ +--------------------------------------------------+
157
+ | user |
158
+ | Memory: goal, plan, known, date |
159
+ +--------------------------------------------------+
160
+ | user |
161
+ | FILE STATE: latest Read/Edit file view |
148
162
  +--------------------------------------------------+
149
163
  ```
150
164
 
151
165
  Core rules:
152
166
 
153
- - File Context is rebuilt dynamically from active `Read` and `Edit` results.
167
+ - Mid-turn assistant text and appended user input are kept as conversation.
168
+ - Earlier conversation is compacted into an explicit summary when the context grows too large.
169
+ - FILE STATE is updated by successful `Read` and `Edit` tools and shows current listed file ranges, with recent files first.
154
170
  - Newer file lines overwrite older lines; edit invalidations clear stale ranges.
155
171
  - File lines are checked against current file stat or line hash before being shown.
156
- - Discovery Context contains `Find`, `Search`, and `InspectCode` leads, not source truth.
157
- - Large tool outputs are bounded in context and can be recalled by `tr.N`.
158
- - Error Feedback keeps only recent failed tool calls.
159
- - `Forget` removes stale result keys from the active tool result store.
172
+ - Successful `Read` and `Edit` tool messages point to FILE STATE instead of repeating file bodies.
173
+ - Other tool outputs are bounded in conversation messages and can be recalled by `tr.N`.
160
174
 
161
175
  ## Safety
162
176
 
@@ -2,18 +2,22 @@
2
2
 
3
3
  A small terminal coding agent written in Python.
4
4
 
5
+ [简体中文](README.zh-CN.md)
6
+
5
7
  nanocode is pre-1.0 software. Commands, configuration, and tool behavior may change before a stable release.
6
8
 
7
9
  ![nanocode screenshot](snapshots/nanocode-snapshot.png)
8
10
 
9
11
  ## Features
10
12
 
11
- - **Snapshot context**: Every turn starts from a clean workspace snapshot instead of a bloated chat replay.
12
- - **File memory**: Recent reads and edits stay available as focused, line-numbered file ranges.
13
- - **Anchored edits**: `line:hash` anchors catch stale edits before they touch the wrong code.
14
- - **Symbol index**: Jump from names to outlines, references, and changed files without searching blindly.
15
- - **Tool recall**: Big outputs are bounded in the prompt but still recallable later by `tr.N`.
16
- - **Terminal-native UI**: Model picking, history search, confirmations, live command output, and status all stay in the terminal.
13
+ - **Live turn control**: Add follow-up input while the agent is still working, without losing the current tool flow.
14
+ - **File-state brain**: Reads and edits build a current, line-numbered view of the files that matter now.
15
+ - **Stale-edit protection**: `line:hash` anchors reject edits when the target code has drifted.
16
+ - **Project-aware navigation**: Use the symbol index to jump through outlines, references, and changed files quickly.
17
+ - **Recoverable context**: Tool output stays bounded in the prompt, while raw `tr.N` results remain recallable.
18
+ - **Cache-aware context**: Stable sections stay early and noisy working state stays late to improve prompt-cache reuse.
19
+ - **Focused working memory**: `Note` separates goal, plan, and known facts from noisy execution logs.
20
+ - **Terminal-first workflow**: Model selection, history search, confirmations, live command output, appended input, and status all stay in one CLI.
17
21
 
18
22
  ## Install
19
23
 
@@ -21,6 +25,12 @@ nanocode is pre-1.0 software. Commands, configuration, and tool behavior may cha
21
25
  uv tool install nanocode-cli
22
26
  ```
23
27
 
28
+ Upgrade:
29
+
30
+ ```sh
31
+ uv tool upgrade nanocode-cli
32
+ ```
33
+
24
34
  For local development:
25
35
 
26
36
  ```sh
@@ -43,6 +53,8 @@ Useful arguments:
43
53
  - `--yolo`: skip confirmations for mutating tools.
44
54
  - `-v`, `--version`: show the version.
45
55
 
56
+ During a running turn, the `+>` prompt accepts follow-up input for the next model request.
57
+
46
58
  ## Commands
47
59
 
48
60
  - `/help`: show commands and tools.
@@ -65,9 +77,10 @@ Interactive selectors support `j`/`k`, arrows, `/` search, Enter, and Esc. Input
65
77
 
66
78
  - File: `Read`, `LineCount`, `List`, `Find`, `Search`.
67
79
  - Code index: `InspectCode`.
68
- - Edit: `CreateFile`, `Edit`.
80
+ - Edit: `Edit` creates or patches file content.
69
81
  - Shell: `Bash`, `Git`.
70
- - Tool results: `Recall`, `Forget`.
82
+ - Tool results: `Recall`.
83
+ - Working notes: `Note`.
71
84
 
72
85
  `Read`, `Search`, and `InspectCode` return line anchors where useful. `Edit` uses current `line:hash` anchors to reject stale edits.
73
86
 
@@ -92,7 +105,7 @@ Main fields:
92
105
 
93
106
  ## Context Design
94
107
 
95
- Each model request is built manually as one system message and one user message. The user message is a structured context snapshot, ordered from stable sections to volatile sections so provider prompt caching can reuse the prefix.
108
+ Each model request is built manually from explicit messages. Stable context comes first, conversation stays as messages, working memory follows, and the latest file state is appended at the end.
96
109
 
97
110
  ```text
98
111
  model request
@@ -102,27 +115,27 @@ model request
102
115
  +--------------------------------------------------+
103
116
  | user |
104
117
  | Environment |
105
- | State |
106
- | Summary |
107
- | Recent Conversation |
108
- | Tool Result Index |
109
- | File Context |
110
- | Discovery Context |
111
- | Error Feedback |
112
- | Latest Tool Results |
113
- | Current Turn Conversation |
118
+ +--------------------------------------------------+
119
+ | user/assistant |
120
+ | conversation, compacted summaries, tools |
121
+ +--------------------------------------------------+
122
+ | user |
123
+ | Memory: goal, plan, known, date |
124
+ +--------------------------------------------------+
125
+ | user |
126
+ | FILE STATE: latest Read/Edit file view |
114
127
  +--------------------------------------------------+
115
128
  ```
116
129
 
117
130
  Core rules:
118
131
 
119
- - File Context is rebuilt dynamically from active `Read` and `Edit` results.
132
+ - Mid-turn assistant text and appended user input are kept as conversation.
133
+ - Earlier conversation is compacted into an explicit summary when the context grows too large.
134
+ - FILE STATE is updated by successful `Read` and `Edit` tools and shows current listed file ranges, with recent files first.
120
135
  - Newer file lines overwrite older lines; edit invalidations clear stale ranges.
121
136
  - File lines are checked against current file stat or line hash before being shown.
122
- - Discovery Context contains `Find`, `Search`, and `InspectCode` leads, not source truth.
123
- - Large tool outputs are bounded in context and can be recalled by `tr.N`.
124
- - Error Feedback keeps only recent failed tool calls.
125
- - `Forget` removes stale result keys from the active tool result store.
137
+ - Successful `Read` and `Edit` tool messages point to FILE STATE instead of repeating file bodies.
138
+ - Other tool outputs are bounded in conversation messages and can be recalled by `tr.N`.
126
139
 
127
140
  ## Safety
128
141
 
@@ -0,0 +1,142 @@
1
+ # nanocode
2
+
3
+ 一个用 Python 写的小型终端编程代理。
4
+
5
+ [English](README.md)
6
+
7
+ nanocode 仍是 1.0 前的软件。稳定版发布前,命令、配置和工具行为都可能变化。
8
+
9
+ ![nanocode screenshot](snapshots/nanocode-snapshot.png)
10
+
11
+ ## 特性
12
+
13
+ - **实时回合控制**:代理还在工作时,也可以追加输入,不打断当前工具流程。
14
+ - **文件状态大脑**:`Read` 和 `Edit` 会构建当前重要文件的带行号视图。
15
+ - **过期编辑保护**:`line:hash` 锚点会在目标代码漂移后拒绝错误编辑。
16
+ - **项目级导航**:通过符号索引快速查看 outline、references 和变更文件。
17
+ - **可恢复上下文**:prompt 中的工具输出保持有界,原始 `tr.N` 结果仍可按需召回。
18
+ - **缓存友好上下文**:稳定内容靠前,嘈杂的工作状态靠后,提高 prompt cache 复用率。
19
+ - **聚焦工作记忆**:`Note` 把 goal、plan、known facts 从嘈杂执行日志中拆出来。
20
+ - **终端优先工作流**:模型选择、历史搜索、确认、实时命令输出、追加输入和状态展示都在一个 CLI 内完成。
21
+
22
+ ## 安装
23
+
24
+ ```sh
25
+ uv tool install nanocode-cli
26
+ ```
27
+
28
+ 升级:
29
+
30
+ ```sh
31
+ uv tool upgrade nanocode-cli
32
+ ```
33
+
34
+ 本地开发:
35
+
36
+ ```sh
37
+ uv sync --extra dev
38
+ uv run nanocode
39
+ ```
40
+
41
+ ## 使用
42
+
43
+ 启动 CLI:
44
+
45
+ ```sh
46
+ nanocode
47
+ ```
48
+
49
+ 常用参数:
50
+
51
+ - `--config <path>`:使用指定 TOML 配置文件。
52
+ - `--init-config`:创建默认配置文件。
53
+ - `--yolo`:跳过会修改环境的工具确认。
54
+ - `-v`, `--version`:显示版本。
55
+
56
+ 代理运行中,`+>` 提示符可以接收追加输入,并在下一次模型请求中发送。
57
+
58
+ ## 命令
59
+
60
+ - `/help`:显示命令和工具。
61
+ - `/status`:显示运行状态。
62
+ - `/config`:显示当前配置。
63
+ - `/api [auto|chat|anthropic]`:显示或设置 provider API 格式。
64
+ - `/debug [on|off]`:切换模型 I/O debug trace。
65
+ - `/compact`:立即压缩上下文。
66
+ - `/index [force]`:同步或重建代码符号索引。
67
+ - `/provider [NAME]`:显示或设置 provider。
68
+ - `/model [MODEL]`:显示或设置模型。
69
+ - `/reason`:选择 reasoning effort。
70
+ - `/set KEY VALUE`:设置 provider/runtime 值。
71
+ - `/yolo`:切换工具确认。
72
+ - `/exit`, `/quit`:退出。
73
+
74
+ 交互选择器支持 `j`/`k`、方向键、`/` 搜索、Enter 和 Esc。输入框支持历史、补全和 `Ctrl-R` 历史搜索。
75
+
76
+ ## 工具
77
+
78
+ - 文件:`Read`, `LineCount`, `List`, `Find`, `Search`。
79
+ - 代码索引:`InspectCode`。
80
+ - 编辑:`Edit` 创建或修改文件内容。
81
+ - Shell:`Bash`, `Git`。
82
+ - 工具结果:`Recall`。
83
+ - 工作笔记:`Note`。
84
+
85
+ `Read`、`Search` 和 `InspectCode` 会在合适时返回行锚点。`Edit` 使用当前 `line:hash` 锚点拒绝过期编辑。
86
+
87
+ ## 配置
88
+
89
+ 运行:
90
+
91
+ ```sh
92
+ nanocode --init-config
93
+ ```
94
+
95
+ 默认配置位置是 `~/.nanocode/config.toml`。
96
+
97
+ 主要字段:
98
+
99
+ - `[provider] active = "name"`
100
+ - `[provider.<name>]`:`url`, `key`, `model`, `api`, `prompt_cache_key`, `available_models`, `reasoning`, `chat_reasoning`, `temperature`, `timeout`
101
+ - `[paths] data_dir`
102
+ - `[runtime] shell_timeout`, `max_agent_steps`, `max_context_tokens`, `yolo`
103
+
104
+ `api = "auto"` 会根据 provider/model profile 在 Chat Completions 和 Anthropic Messages 之间选择。`prompt_cache_key = "auto"` 会根据 provider、model、workspace 和工具 schema 名称生成稳定 key。
105
+
106
+ ## 上下文设计
107
+
108
+ 每次模型请求都由 nanocode 手动构建成明确的 messages。稳定上下文在前,会话作为 messages 保留,工作记忆随后,最新文件状态放在末尾。
109
+
110
+ ```text
111
+ model request
112
+ +--------------------------------------------------+
113
+ | system |
114
+ | concise agent contract and tool rules |
115
+ +--------------------------------------------------+
116
+ | user |
117
+ | Environment |
118
+ +--------------------------------------------------+
119
+ | user/assistant |
120
+ | conversation, compacted summaries, tools |
121
+ +--------------------------------------------------+
122
+ | user |
123
+ | Memory: goal, plan, known, date |
124
+ +--------------------------------------------------+
125
+ | user |
126
+ | FILE STATE: latest Read/Edit file view |
127
+ +--------------------------------------------------+
128
+ ```
129
+
130
+ 核心规则:
131
+
132
+ - 回合中的 assistant 文本和用户追加输入都会作为 conversation 保留。
133
+ - 上下文过大时,较早 conversation 会压缩成明确的 summary。
134
+ - FILE STATE 由成功的 `Read` 和 `Edit` 更新,展示当前文件范围,最近文件优先。
135
+ - 更新的文件行会覆盖旧行;edit invalidation 会清理过期范围。
136
+ - 文件行展示前会通过当前文件 stat 或行 hash 校验。
137
+ - 成功的 `Read` 和 `Edit` 工具消息只指向 FILE STATE,不重复塞入文件正文。
138
+ - 其他工具输出在 conversation messages 中保持有界,并可通过 `tr.N` 召回。
139
+
140
+ ## 安全
141
+
142
+ nanocode 会在启动它的环境中编辑文件和执行 shell 命令。它不提供 sandbox 保护。需要隔离时,请在你自己的 sandbox、容器、虚拟机或其他隔离环境中运行。