@noobdemon/noob-cli 1.13.1 → 1.13.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  Tất cả thay đổi đáng kể của `@noobdemon/noob-cli` được ghi vào file này.
4
4
 
5
+ ## [1.13.3] - 2026-06-29
6
+
7
+ ### Fixed
8
+ - **Message nhắc việc nội bộ không còn gây nhiễu mô hình** (`src/agent.js`): các message nhắc tiếp tục công việc (nhắc todo còn dở, hướng dẫn khi tool lỗi, cảnh báo gọi trùng tool) trước đây được chèn vào hội thoại như thể là tin nhắn người dùng và mở đầu bằng nhãn `[SYSTEM]`. Mô hình ở lượt sau đọc lại tưởng có người chèn lệnh giả dạng hệ thống vào cuộc trò chuyện nên sinh nghi ngờ, đi sửa lung tung. Giờ các message này đi đúng kênh kết quả tool và đổi nhãn thành `[TODO]`/`[TOOL GUIDANCE]`.
9
+
10
+ ### Verified
11
+ - `npm test` 109/109 pass.
12
+
13
+ ## [1.13.2] - 2026-06-28
14
+
15
+ ### Added
16
+ - **Hỗ trợ nhiều ảnh trong một tin nhắn**: paste hoặc nhắc nhiều ảnh `@file` trong cùng một lượt — tất cả được đính kèm cho mô hình vision, mỗi ảnh là một phần riêng. Trước đây chỉ ảnh đầu tiên được gửi đi.
17
+ - **Smoke test chống README drift** (`scripts/smoke-readme-drift.mjs`): đối chiếu README với danh mục mô hình + tool thật — fail nếu README quảng cáo số mô hình lớn hơn thực tế hoặc thiếu tool. 20/20 pass.
18
+ - **Gợi ý trang động cho `web_fetch`** (`src/tools.js`): khi tải một trang nhiều HTML nhưng bóc ra rất ít chữ (thường là trang render bằng JS), trả thêm gợi ý thử chế độ `raw` thay vì để mô hình tưởng trang trống. 16/16 pass.
19
+
20
+ ### Changed
21
+ - **README viết lại khớp thực tế**: số lượng mô hình, danh sách tool và lệnh trong phiên, cấu trúc thư mục `src/` đều cập nhật cho đúng với mã hiện tại.
22
+
23
+ ### Internal
24
+ - **Tách bớt `src/repl.js`** (`src/repl/commands/kg.js` + `src/repl/commands/goal.js`): khối `/kg` và `/goal` chuyển thành hàm riêng nhận dependency injected, không truy cập closure `startRepl`. Verify: import sạch, `smoke-kg` 45/45, `npm test` 109/109.
25
+ - **Luồng ảnh dạng mảng** (`src/api.js` + `src/agent.js` + `src/repl.js`): tham số `images` (mảng) luồng xuyên `runAgent → streamWithRetry → stream → streamOnce`, giữ `image` đơn làm alias tương thích ngược.
26
+
5
27
  ## [1.13.1] - 2026-06-28
6
28
 
7
29
  ### Fixed
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # noob — agentic coding CLI
2
2
 
3
- A Claude-Code-style coding agent that lives in your terminal, powered by
4
- **Noob Demon** (34 models across 8 providers GPT, Claude, Gemini, DeepSeek,
5
- Grok, Qwen, Kimi, Llama).
3
+ Một coding agent kiểu Claude Code sống trong terminal, giao tiếp **tiếng Việt**,
4
+ chạy qua gateway **Noob Demon** với 3 hình flagship (Claude Opus 4.8, GPT-5.5,
5
+ DeepSeek V4 Pro).
6
6
 
7
- It reads and edits files, runs shell commands, and iterates on a taskasking
8
- permission before anything destructiveall inside a polished terminal UI.
7
+ đọc & sửa file, chạy lệnh shell, tự lặp để hoàn thành tác vụ xin phép trước
8
+ mọi thao tác rủi ro tất cả trong một giao diện terminal gọn gàng.
9
9
 
10
10
  ```
11
11
  ███╗ ██╗ ██████╗ ██████╗ ██████╗
@@ -21,15 +21,15 @@ permission before anything destructive — all inside a polished terminal UI.
21
21
  ```bash
22
22
  cd "noob cli"
23
23
  npm install
24
- npm link # optional: makes `noob` available globally
24
+ npm link # tùy chọn: cho phép gõ `noob` toàn cục
25
25
  ```
26
26
 
27
- Requires Node.js ≥ 18 (tested on 22).
27
+ Yêu cầu Node.js ≥ 18 (test trên 22).
28
28
 
29
- ## Xác thực & gói cước (Authentication)
29
+ ## Xác thực & gói cước
30
30
 
31
- noob đi qua một **gateway** (Cloudflare Worker `claude-code-proxy`) để ẩn backend
32
- thật và quản lý API key qua Supabase. Bạn cần một API key để dùng:
31
+ noob đi qua một **gateway** (Cloudflare Worker) để ẩn backend thật và quản lý API
32
+ key. Bạn cần một API key để dùng:
33
33
 
34
34
  ```bash
35
35
  noob login nk_xxx_xxxxxxxx # đăng nhập, key lưu ở ~/.noob/config.json
@@ -50,51 +50,71 @@ Trong phiên: `/login <key>`, `/usage`, `/logout`.
50
50
 
51
51
  > Mỗi lệnh gọi mô hình (kể cả từng bước tool trong một tác vụ) tính là 1 request.
52
52
 
53
- Cấp/huỷ key (admin) — trong repo gateway `worker/`:
54
-
55
- ```bash
56
- node scripts/admin.mjs create pro "khách A"
57
- node scripts/admin.mjs list
58
- node scripts/admin.mjs revoke nk_pro_xxx
59
- ```
60
-
61
53
  ## Use
62
54
 
63
55
  ```bash
64
- noob # interactive session
65
- noob "add input validation to api.js" # start with a request
66
- noob -m gateway-claude-opus-4-8 # pick a model
67
- noob --yolo # auto-approve edits & commands
56
+ noob # phiên tương tác
57
+ noob "add input validation to api.js" # bắt đầu kèm yêu cầu
58
+ noob -m gateway-claude-opus-4-8 # chọn hình
59
+ noob --yolo # tự duyệt edit & lệnh
68
60
  ```
69
61
 
70
- Without `npm link`, run `node bin/noob.js …`.
71
-
72
- ### In-session commands
73
-
74
- | Command | What it does |
75
- | --------------- | ------------------------------------------------------------------ |
76
- | `/model [name]` | switch model (fuzzy match), or list all |
77
- | `/models` | list every model grouped by provider |
78
- | `/merge` | toggle **Merge AI** — synthesizes GPT-5.5 + Claude + Gemini via o3 |
79
- | `/search` | toggle **web search** mode |
80
- | `/chat` | back to normal chat mode |
81
- | `/yolo` | toggle auto-approve for file/command tools (or **Shift+Tab**) |
82
- | `/clear` `/new` | wipe conversation context |
83
- | `/status` | show current model + working directory |
84
- | `/exit` | quit (Ctrl+C once = stop turn, twice = quit) |
62
+ Không `npm link` thì chạy `node bin/noob.js …`.
63
+
64
+ Cờ dòng lệnh: `--yolo`, `--ultra`, `--model <name>`, `--continue`, `--resume`,
65
+ `--insecure-tls`.
66
+
67
+ ### Lệnh trong phiên
68
+
69
+ | Lệnh | Tác dụng |
70
+ | ----------------- | ------------------------------------------------------------- |
71
+ | `/help` | danh sách lệnh |
72
+ | `/model [name]` | đổi hình (fuzzy match), hoặc liệt kê tất cả |
73
+ | `/models` | liệt mọi hình theo provider |
74
+ | `/merge` | bật/tắt **Merge AI** (tổng hợp đa mô hình) |
75
+ | `/search` | bật/tắt chế độ tìm web |
76
+ | `/chat` | quay lại chế độ chat thường |
77
+ | `/agent on\|off` | bật/tắt agent mode (đẻ sub-agent song song/tuần tự/phân cấp) |
78
+ | `/mode` | build\|plan\|compose — đổi chế độ agent (Ctrl+T cycle) |
79
+ | `/goal [text]` | đặt HARD GOAL cho phiên · `/goal clear` để xoá |
80
+ | `/loop <iv> <task>` | chạy task định kỳ · `/loop stop` để dừng |
81
+ | `/ultra` | chế độ tự hành: model tự nghĩ & làm tới khi xong |
82
+ | `/workflow` | orchestrate workflow đa-agent (xem `/workflow help`) |
83
+ | `/kg` | knowledge graph của project (xem `/kg help`) |
84
+ | `/compact` | tóm tắt phiên ngay để gọn ngữ cảnh |
85
+ | `/tokens` | xem token đã dùng trong phiên |
86
+ | `/memory` | xem bộ nhớ `noob.md` · `/memory stats` xem kích thước |
87
+ | `/learn` | chưng cất bài học vào `noob.md` |
88
+ | `/init` | quét dự án & tạo `noob.md` |
89
+ | `/karpathy` | rà soát code theo nguyên tắc Karpathy |
90
+ | `/frontend-design`| skill thiết kế UI frontend chất lượng cao |
91
+ | `/improve` | phân tích workspace & gợi ý tính năng cải thiện |
92
+ | `/add-dir <path>` | thêm thư mục ngoài cwd vào phạm vi · `remove` để gỡ |
93
+ | `/cwd` | thư mục làm việc hiện tại |
94
+ | `/yolo` | bật/tắt tự duyệt file/lệnh (hoặc **Shift+Tab**) |
95
+ | `/auto-yolo` | lưu yolo làm mặc định mỗi lần chạy |
96
+ | `/clear` `/new` | xoá ngữ cảnh / phiên mới |
97
+ | `/continue` | tiếp tục phiên gần nhất |
98
+ | `/resume` | chọn & tiếp tục một phiên cũ |
99
+ | `/sessions` | liệt kê phiên đã lưu |
100
+ | `/status` | mô hình hiện tại + thư mục làm việc |
101
+ | `/version` | phiên bản |
102
+ | `/login` `/logout` `/usage` | xác thực & hạn mức |
103
+ | `/update` | tự cập nhật noob |
104
+ | `/exit` | thoát (Ctrl+C một lần = dừng turn, hai lần = thoát) |
85
105
 
86
106
  ## How it works
87
107
 
88
- The Noob Demon gateway is a **stateless single-message** endpoint with no native
89
- function-calling. noob layers an agent on top:
108
+ Gateway Noob Demon một endpoint **stateless single-message** không
109
+ function-calling gốc. noob phủ một lớp agent lên trên:
90
110
 
91
- 1. The full transcript (system prompt + history + tool results) is serialized into
92
- one `message` and streamed to the gateway's `/api/chat`.
93
- 2. The model replies with either a final answer or a single \`\`\`tool JSON block.
94
- 3. noob parses the tool call, asks permission if it's destructive, executes it, and
95
- feeds the result back looping until the model answers without a tool block.
111
+ 1. Toàn bộ transcript (system prompt + history + kết quả tool) được serialize
112
+ thành một `message` rồi stream tới `/api/chat`.
113
+ 2. Model trả về hoặc câu trả lời cuối, hoặc một khối ```tool JSON duy nhất.
114
+ 3. noob parse tool call, xin phép nếu có rủi ro, thực thi, rồi feed kết quả
115
+ lạilặp tới khi model trả lời không kèm tool block.
96
116
 
97
- ### Architecture (high-level)
117
+ ### Kiến trúc (tổng quan)
98
118
 
99
119
  ```mermaid
100
120
  flowchart LR
@@ -104,8 +124,8 @@ flowchart LR
104
124
  API -->|HTTPS stream| GW[(Noob Demon<br/>Gateway)]
105
125
  GW -->|delta tokens| API
106
126
  API -->|onDelta callbacks| Agent
107
- Agent -->|parse tool block| Tools[tools.js<br/>read/write/edit/run]
108
- Tools -->|fs / spawn| FS[(workspace)]
127
+ Agent -->|parse tool block| Tools[tools.js<br/>read/write/edit/run/fetch]
128
+ Tools -->|fs / spawn / http| FS[(workspace)]
109
129
  Tools -->|result text| Agent
110
130
  Agent -->|final answer| REPL
111
131
  REPL -->|persist| Sessions[(~/.noob/sessions/)]
@@ -114,109 +134,122 @@ flowchart LR
114
134
  Subagent -->|isolated context| API
115
135
  ```
116
136
 
117
- ### Tools the agent can call
137
+ ### Tool agent gọi được
118
138
 
119
- `read_file` · `write_file` · `edit_file` · `list_dir` · `glob` · `grep` · `run_command`
139
+ Đọc/khám phá (chạy tự do, không xin phép):
140
+ `read_file` · `list_dir` · `glob` · `grep` · `web_fetch`
120
141
 
121
- Destructive tools (`write_file`, `edit_file`, `run_command`) prompt for approval
122
- (`y` / `n` / `a`lways) unless `/yolo` is on.
142
+ Thao tác có rủi ro (xin phép `y`/`n`/`a`, thêm `t`=hết turn, `f`=file này khi
143
+ bật rich TTY):
144
+ `write_file` · `edit_file` · `run_command`
145
+
146
+ Quản lý tiến trình nền & điều phối:
147
+ `bg_output` · `kill_bg` · `write_todos` · `spawn_agent` / `spawn_agents` (khi
148
+ `/agent` bật) · `kg_search` / `kg_add` / `kg_link` / `kg_obs` (knowledge graph)
149
+
150
+ > `web_fetch` truy cập mạng (http/https) nhưng read-only nên không xin phép.
151
+ > Nó strip HTML bằng regex; với trang render bằng JS (SPA) sẽ trả về gần rỗng
152
+ > kèm gợi ý thử `raw:true`.
123
153
 
124
154
  ## Configuration
125
155
 
126
- | Env var | Effect |
127
- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
128
- | `NOOB_API_BASE` | override the gateway URL |
129
- | `NOOB_API_KEY` | API key (overrides `~/.noob/config.json`) |
130
- | `NOOB_INSECURE_TLS=1` | disable TLS verification — **last resort** for machines behind a TLS-intercepting proxy. Prefer adding your proxy CA to the trust store. |
156
+ | Env var | Tác dụng |
157
+ | --------------------- | ------------------------------------------------------------------ |
158
+ | `NOOB_API_BASE` | ghi đè URL gateway |
159
+ | `NOOB_API_KEY` | API key (ghi đè `~/.noob/config.json`) |
160
+ | `NOOB_INSECURE_TLS=1` | tắt verify TLS — **giải pháp cuối** cho máy sau proxy chặn TLS. |
131
161
 
132
162
  ## Model compatibility
133
163
 
134
- The agent drives tools through a text protocol (the proxy has no native
135
- function-calling). Models differ in how willingly they follow it:
164
+ Agent điều khiển tool qua một text protocol (gateway không function-calling
165
+ gốc). Các model khác nhau về mức độ sẵn lòng tuân theo:
136
166
 
137
- | Provider | Agentic tools | Notes |
167
+ | Provider | Agentic tools | Ghi chú |
138
168
  | ---------------------- | ---------------- | ---------------------------------------- |
139
- | **Anthropic** (Claude) | ✅ best | default — `gateway-claude-opus-4-8` |
140
- | **DeepSeek** | ✅ works | good free alternative |
141
- | OpenAI (GPT/o-series) | ⚠️ often refuses | replies "I can't access your filesystem" |
142
- | Google (Gemini) | ⚠️ often refuses | same |
169
+ | **Anthropic** (Claude) | ✅ tốt nhất | mặc định — `gateway-claude-opus-4-8` |
170
+ | **DeepSeek** | ✅ chạy tốt | lựa chọn thay thế tốt |
171
+ | OpenAI (GPT) | ⚠️ hay từ chối | trả "I can't access your filesystem" |
143
172
 
144
- Stick with Claude or DeepSeek for file edits & commands. Any model is fine for
145
- plain chat, `/merge`, and `/search`.
173
+ Dùng Claude hoặc DeepSeek cho edit file & chạy lệnh. Mọi model đều ổn cho chat
174
+ thường, `/merge`, `/search`.
146
175
 
147
176
  ## Project structure
148
177
 
149
178
  ```
150
179
  src/
151
- ├── api.js # gateway client + stream parser + memory token
152
- ├── agent.js # tool-loop driver, summarization, prompt assembly
153
- ├── tools.js # read/write/edit/list_dir/glob/grep/run_command + bg
154
- ├── repl.js # input loop, slash commands, session state (88 KB)
180
+ ├── api.js # gateway client + stream parser + quota warning
181
+ ├── agent.js # tool-loop driver, SYSTEM prompt, summarization
182
+ ├── tools.js # read/write/edit/list_dir/glob/grep/run_command/web_fetch/bg/kg
183
+ ├── repl.js # input loop, slash commands, session state
155
184
  ├── repl/
156
- │ ├── complete.js # SLASH catalog + autocomplete
157
- │ ├── todos.js # parseTodosFromHistory (pure)
158
- │ ├── ultra.js # ULTRA mode constants + prompt templates
159
- └── workflow-commands.js # /workflow help/list/load/delete (pure)
185
+ │ ├── agent-dispatch.js # spawn_agent + write_todos dispatcher
186
+ │ ├── complete.js # SLASH catalog + autocomplete
187
+ │ ├── permission.js # askPermission (y/n/a/t/f scopes)
188
+ ├── state.js # createState session state shape
189
+ │ ├── stream-printer.js # render stream theo dòng (heading/table/code)
190
+ │ ├── todos.js # parseTodosFromHistory (pure)
191
+ │ ├── ultra.js # ULTRA mode prompt templates
192
+ │ ├── workflow-commands.js # /workflow help/list/load/delete (pure)
193
+ │ └── commands/ # nhóm slash command tách rời
160
194
  ├── subagent.js # spawn_agent / spawn_agents — sub-agent isolation
161
- ├── tui.js # terminal UI (input, status bar, prompt rendering)
162
- ├── ui.js # color helpers, markdown renderer, banner
195
+ ├── workflow-bg.js # workflow chạy nền
196
+ ├── workflow-runs.js # lưu/khôi phục lần chạy workflow
197
+ ├── workflows.js # ~/.noob/workflows/ — workflow user lưu
198
+ ├── workflows-builtin.js # workflow ship-sẵn (deep-research, verify-claims, triage)
199
+ ├── kg.js # knowledge graph (.noob/kg.jsonl per project)
200
+ ├── tui.js # terminal UI (input, status bar, todo progress)
201
+ ├── ui.js # color, markdown renderer, banner
202
+ ├── diff.js # render diff khi edit_file
163
203
  ├── config.js # ~/.noob/config.json (api key, gateway, model)
164
204
  ├── sessions.js # ~/.noob/sessions/ — save/list/resume
165
- ├── skills.js # ~/.noob/skills/ user-defined skill loader
166
- ├── workflows.js # ~/.noob/workflows/ — user-saved workflows
167
- ├── workflows-builtin.js # ship-with-binary workflows (deep-research, etc)
205
+ ├── skills.js # skill loader (cwd package)
168
206
  ├── memory.js # noob.md per-project agent memory
169
- ├── tokens.js # local token counter (o200k_base / cl100k_base)
170
- ├── models.js # 34-model catalog + fuzzy resolver
171
- ├── i18n.js # Vietnamese string table
172
- ├── update.js # `noob update` self-updater
173
- └── prompts/
174
- └── system.md # base system prompt template
175
-
176
- tests/ # vitest unit tests (96 tests)
177
- scripts/ # check-imports, notify-discord, release.ps1
207
+ ├── tokens.js # local token counter (gpt-tokenizer)
208
+ ├── models.js # 3-model flagship catalog + fuzzy resolver
209
+ ├── i18n.js # bảng chuỗi tiếng Việt
210
+ └── update.js # `noob update` self-updater
211
+
212
+ tests/ # vitest unit tests
213
+ scripts/ # smoke tests + notify-discord
178
214
  ```
179
215
 
180
216
  ## Development
181
217
 
182
218
  ```bash
183
- npm test # run vitest unit tests (96 tests across 7 files)
184
- npm run lint # eslint --check
219
+ npm test # chạy vitest unit tests
220
+ npm run lint # eslint
185
221
  npm run lint:fix # eslint --fix
186
222
  npm run format # prettier --write
187
223
  npm run format:check # prettier --check
188
- npm run check # lint + format:check + test (pre-commit gate)
224
+ npm run check # lint + format:check + test (cổng pre-commit)
189
225
  ```
190
226
 
191
227
  Husky chạy `lint-staged` + `npm test` trước mỗi commit. Bỏ qua bằng
192
228
  `git commit --no-verify` nếu thực sự cần (vd commit WIP).
193
229
 
230
+ Ngoài unit test, `scripts/` chứa nhiều smoke test chạy bằng
231
+ `node scripts/smoke-<name>.mjs` (offline, không cần gateway).
232
+
194
233
  ## Troubleshooting
195
234
 
196
235
  **"CLI tự thoát sau khi hỏi quyền"** — thường là readline trên Windows phát sự
197
- kiện `close` từ tiến trình con chạm vào console. Đã có workaround trong
198
- `repl.js` (input layer tự re-arm). Nếu còn xảy ra, mở issue kèm OS + Node version.
236
+ kiện `close` từ tiến trình con. Đã có workaround trong `repl.js`. Nếu còn xảy ra,
237
+ mở issue kèm OS + Node version.
199
238
 
200
- **"TLS error / certificate"** — máy bạn sau proxy chặn TLS (Zscaler, Cisco
239
+ **"TLS error / certificate"** — máy sau proxy chặn TLS (Zscaler, Cisco
201
240
  Umbrella…). Ưu tiên add CA của proxy vào trust store. Cuối cùng mới dùng
202
241
  `NOOB_INSECURE_TLS=1` (tắt verify TLS toàn process, MITM-vulnerable).
203
242
 
204
- **"Model OpenAI/Gemini từ chối tool"** — bình thường. GPT-o-series Gemini
205
- thường refuse access filesystem qua text protocol. Dùng `/model claude-opus` hoặc
206
- `/model deepseek-v3` cho tasks cần tool.
207
-
208
- **"Token count có vẻ sai"** — `tokens.js` chọn encoder theo model id
209
- (`o200k_base` cho GPT-4o/5/o-series, `cl100k_base` cho phần còn lại). Đếm chính
210
- xác cho OpenAI, xấp xỉ ±5-15% cho Claude/Gemini/khác (các provider này không
211
- publish tokenizer public).
243
+ **"Model OpenAI từ chối tool"** — GPT thường refuse access filesystem qua text
244
+ protocol. Dùng `/model claude` hoặc `/model deepseek` cho task cần tool.
212
245
 
213
246
  ## Notes & limits
214
247
 
215
- - Free shared proxy: rate limits and occasional hiccups are expected.
216
- - Context is sent in full each turn, so very long sessions cost more tokensuse
217
- `/clear` to reset.
218
- - This is an unofficial tool built against a public community endpoint; it is not
219
- affiliated with Anthropic or the model providers.
248
+ - Proxy chia sẻ miễn phí: rate limit đôi lúc trục trặc là bình thường.
249
+ - Context gửi đầy đủ mỗi lượt, nên phiên rất dài tốn nhiều tokendùng `/compact`
250
+ hoặc `/clear` để gọn lại.
251
+ - Đây công cụ không chính thức, không liên kết với Anthropic hay các nhà cung
252
+ cấp model.
220
253
 
221
254
  ## License
222
255
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noobdemon/noob-cli",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -25,7 +25,8 @@
25
25
  "format:check": "prettier --check .",
26
26
  "test": "vitest run",
27
27
  "test:watch": "vitest",
28
- "check": "npm run lint && npm run format:check && npm run test",
28
+ "i18n:check": "node scripts/check-i18n-orphans.mjs",
29
+ "check": "npm run lint && npm run format:check && npm run i18n:check && npm run test",
29
30
  "postpublish": "node scripts/notify-discord.js",
30
31
  "prepare": "husky"
31
32
  },
package/src/agent.js CHANGED
@@ -479,18 +479,18 @@ export function todoContinuationMessage(toolName, ok, tasks) {
479
479
  if (!tasks?.length) return null;
480
480
  const next = tasks[0];
481
481
  const status = ok ? `đã hoàn thành` : `vừa LỖI`;
482
- return `[SYSTEM] Việc "${toolName}" ${status}. Còn ${tasks.length} việc: ${tasks.map((t) => `"${t}"`).join(', ')}. Việc tiếp theo BẮT BUỘC phải làm ngay: "${next}". Gọi tool (write_file/edit_file/run_command) để làm việc này. KHÔNG dừng, KHÔNG tóm tắt.`;
482
+ return `[TODO] Việc "${toolName}" ${status}. Còn ${tasks.length} việc: ${tasks.map((t) => `"${t}"`).join(', ')}. Việc tiếp theo BẮT BUỘC phải làm ngay: "${next}". Gọi tool (write_file/edit_file/run_command) để làm việc này. KHÔNG dừng, KHÔNG tóm tắt.`;
483
483
  }
484
484
 
485
485
  export function toolErrorGuidance(name, { result } = {}) {
486
486
  if (name !== 'edit_file' || !String(result || '').includes('old_string not found')) return null;
487
487
  const m = String(result).match(/NEXT REQUIRED TOOL:\s*(read_file \{[^\n]+\})/);
488
488
  if (!m) return null;
489
- return `[SYSTEM] edit_file thất bại vì old_string sai. Bạn PHẢI gọi đúng tool này ngay: ${m[1]}. KHÔNG gọi edit_file lại trước khi đọc file. Sau đó copy đúng text từ read_file mới để retry.`;
489
+ return `[TOOL GUIDANCE] edit_file thất bại vì old_string sai. Bạn PHẢI gọi đúng tool này ngay: ${m[1]}. KHÔNG gọi edit_file lại trước khi đọc file. Sau đó copy đúng text từ read_file mới để retry.`;
490
490
  }
491
491
 
492
492
  export function duplicateToolGuidance(name, input) {
493
- return `[SYSTEM] Tool call vừa rồi TRÙNG HỆT lần trước: ${name} ${JSON.stringify(input || {})}. KHÔNG chạy tool này lại. Dùng kết quả đã có trong history; nếu cần tiến thêm thì gọi tool khác (grep/read_file/edit_file/run_command) hoặc trả lời Markdown nếu xong.`;
493
+ return `[TOOL GUIDANCE] Tool call vừa rồi TRÙNG HỆT lần trước: ${name} ${JSON.stringify(input || {})}. KHÔNG chạy tool này lại. Dùng kết quả đã có trong history; nếu cần tiến thêm thì gọi tool khác (grep/read_file/edit_file/run_command) hoặc trả lời Markdown nếu xong.`;
494
494
  }
495
495
 
496
496
  // Detect câu trả lời bị cắt giữa chừng — KHÔNG phải câu hoàn chỉnh.
@@ -581,6 +581,7 @@ export async function runAgent({
581
581
  history,
582
582
  model,
583
583
  image,
584
+ images,
584
585
  signal,
585
586
  onTool,
586
587
  onStatus,
@@ -638,6 +639,7 @@ export async function runAgent({
638
639
  model,
639
640
  message,
640
641
  image,
642
+ images,
641
643
  system,
642
644
  signal,
643
645
  tokenMeter,
@@ -720,7 +722,7 @@ export async function runAgent({
720
722
  });
721
723
  const toolOk = allow && !String(result || '').startsWith('ERROR:');
722
724
  const errorNudge = allow ? toolErrorGuidance(call.name, { result }) : null;
723
- if (errorNudge) history.push({ role: 'user', content: errorNudge });
725
+ if (errorNudge) history.push({ role: 'tool', name: 'tool_guidance', content: errorNudge });
724
726
 
725
727
  // ── Todo continuation nudge ──────────────────────────────────────────
726
728
  // Sau mỗi tool result, inject nudge nếu còn task chưa xong.
@@ -728,7 +730,7 @@ export async function runAgent({
728
730
  {
729
731
  const tasks = pendingTasks || [];
730
732
  const msg = todoContinuationMessage(call.name, toolOk, tasks);
731
- if (msg) history.push({ role: 'user', content: msg });
733
+ if (msg) history.push({ role: 'tool', name: 'todo_continuation', content: msg });
732
734
  }
733
735
 
734
736
  // ── Loop detection ──────────────────────────────────────────────────
@@ -818,6 +820,7 @@ async function streamWithRetry({
818
820
  model,
819
821
  message,
820
822
  image,
823
+ images,
821
824
  system,
822
825
  signal,
823
826
  tokenMeter,
@@ -834,6 +837,7 @@ async function streamWithRetry({
834
837
  model,
835
838
  message,
836
839
  image,
840
+ images,
837
841
  system,
838
842
  signal,
839
843
  effort,
package/src/api.js CHANGED
@@ -158,6 +158,7 @@ export async function stream({
158
158
  mode = 'chat',
159
159
  message,
160
160
  image,
161
+ images,
161
162
  model,
162
163
  system,
163
164
  conversation,
@@ -188,6 +189,7 @@ export async function stream({
188
189
  mode,
189
190
  message: prompt,
190
191
  image,
192
+ images,
191
193
  model,
192
194
  system,
193
195
  conversation,
@@ -265,6 +267,7 @@ async function streamOnce({
265
267
  mode,
266
268
  message,
267
269
  image,
270
+ images,
268
271
  model,
269
272
  system,
270
273
  conversation,
@@ -281,7 +284,14 @@ async function streamOnce({
281
284
  else if (mode === 'merge') body = { message };
282
285
  else {
283
286
  body = { message, model, remember: true, memoryToken: getMemoryToken() };
284
- if (image) body.image = image;
287
+ // Ảnh: chấp nhận cả `images` (mảng, multi-image) lẫn `image` (1 ảnh, cũ).
288
+ // Gửi `images` (mảng data URL) cho worker; giữ `image` = ảnh đầu cho
289
+ // tương thích ngược với worker/upstream cũ.
290
+ const imgList = Array.isArray(images) ? images.filter(Boolean) : image ? [image] : [];
291
+ if (imgList.length) {
292
+ body.images = imgList;
293
+ body.image = imgList[0];
294
+ }
285
295
  if (system) body.customInstructions = system;
286
296
  if (Array.isArray(conversation) && conversation.length) body.conversation = conversation;
287
297
  if (effort) body.effort = effort;
package/src/diff.js CHANGED
@@ -8,6 +8,42 @@
8
8
  // File lớn hơn (write_file overwrite 1k+ dòng) → caller truncate trước khi gọi.
9
9
  import chalk from 'chalk';
10
10
 
11
+ // Bề rộng khả dụng cho NỘI DUNG diff (trừ tiền tố ' │ ' = 4 cột + '+ '/'- ' = 2).
12
+ // Cap tối thiểu 20 để không wrap loạn ở terminal hẹp; mặc định 80 khi không phải TTY.
13
+ function contentWidth() {
14
+ const cols = process.stdout.columns || 80;
15
+ return Math.max(20, cols - 6);
16
+ }
17
+
18
+ // Soft-wrap 1 đoạn text THUẦN (không màu) thành mảng dòng có vis-width ≤ width.
19
+ // Ưu tiên word boundary; không có space hợp lý → hard-slice. Diff text đã bị
20
+ // slice(0,200) ở caller nên không cần ANSI-aware ở đây.
21
+ function wrapPlain(text, width) {
22
+ if (text.length <= width) return [text];
23
+ const lines = [];
24
+ let remaining = text;
25
+ while (remaining.length > width) {
26
+ let cut = width;
27
+ const lastSpace = remaining.slice(0, width).lastIndexOf(' ');
28
+ if (lastSpace > width * 0.3) cut = lastSpace;
29
+ lines.push(remaining.slice(0, cut).trimEnd());
30
+ remaining = remaining.slice(cut).trimStart();
31
+ }
32
+ if (remaining) lines.push(remaining);
33
+ return lines.length ? lines : [''];
34
+ }
35
+
36
+ // Emit 1 dòng diff đã wrap: dòng đầu có dấu (+/-/space), dòng wrap kế thụt 2 cột
37
+ // cho thẳng cột nội dung. Mỗi dòng con tự bọc tiền tố '│' + tô màu riêng (chalk
38
+ // reset cuối từng đoạn) → wrap KHÔNG mất màu / mất khung.
39
+ function emitDiffLine(out, text, color, sign) {
40
+ const segs = wrapPlain(text, contentWidth());
41
+ for (let i = 0; i < segs.length; i++) {
42
+ const prefix = i === 0 ? sign : ' ';
43
+ out.push(chalk.dim(' │ ') + color(prefix + segs[i]));
44
+ }
45
+ }
46
+
11
47
  // LCS table giữa 2 mảng lines. Trả về matrix (M+1) x (N+1).
12
48
  function lcsTable(a, b) {
13
49
  const m = a.length;
@@ -129,11 +165,9 @@ export function renderUnifiedDiff(
129
165
  continue;
130
166
  }
131
167
  const text = String(op.text).slice(0, 200);
132
- let line;
133
- if (op.type === 'add') line = chalk.green('+ ') + chalk.green(text);
134
- else if (op.type === 'del') line = chalk.red('- ') + chalk.red(text);
135
- else line = chalk.dim(' ') + chalk.dim(text);
136
- out.push(chalk.dim(' │ ') + line);
168
+ if (op.type === 'add') emitDiffLine(out, text, chalk.green, '+ ');
169
+ else if (op.type === 'del') emitDiffLine(out, text, chalk.red, '- ');
170
+ else emitDiffLine(out, text, chalk.dim, ' ');
137
171
  printed++;
138
172
  }
139
173
  }
@@ -153,7 +187,7 @@ export function renderNewFilePreview(content, { label = '', maxLines = 20 } = {}
153
187
  const out = [];
154
188
  out.push(chalk.dim(' ┌─ ' + label + ' ') + chalk.green(`(file MỚI · ${lines.length} dòng)`));
155
189
  for (const l of head) {
156
- out.push(chalk.dim(' │ ') + chalk.green('+ ') + chalk.green(l.slice(0, 200)));
190
+ emitDiffLine(out, l.slice(0, 200), chalk.green, '+ ');
157
191
  }
158
192
  if (more > 0) out.push(chalk.dim(' │ ') + chalk.dim(`… +${more} dòng nữa`));
159
193
  out.push(chalk.dim(' └─'));
package/src/i18n.js CHANGED
@@ -26,7 +26,6 @@ export const t = {
26
26
  // auth
27
27
  notLoggedIn:
28
28
  'Bạn chưa đăng nhập. Chạy: noob login <api-key>\nChưa có key? Liên hệ admin để lấy key (Pro / Pro+ / Trial).',
29
- loginOk: (plan) => `Đăng nhập thành công. Gói: ${plan}.`,
30
29
  loginSaved: (p) => `Đã lưu API key vào ${p}`,
31
30
  loggedOut: 'Đã đăng xuất, xoá API key khỏi máy.',
32
31
  needKeyArg: 'Thiếu key. Dùng: noob login <api-key>',
@@ -173,11 +172,6 @@ export const t = {
173
172
  loopAutoStop: (n) => `Loop tự dừng sau tick #${n} — model phát <<LOOP_DONE>> (task hoàn tất).`,
174
173
  loopAlreadyRunning: 'Đã có loop đang chạy. /loop stop trước khi đặt loop mới.',
175
174
  learning: 'đang chưng cất bài học vào noob.md…',
176
- learnSuggest: (n) =>
177
- `💡 Phiên này có ${n} lượt. Gõ /learn trước để chưng cất bài học vào noob.md (sau khi /new thì history sẽ mất).`,
178
- memoryStatus: (lines, rules, notes, ago) =>
179
- `📝 noob.md: ${lines} dòng (${rules} rules, ${notes} notes) · cập nhật ${ago}`,
180
- memoryMissing: '📝 noob.md: chưa có — gõ /init để tạo từ dự án.',
181
175
  compactRunning: 'đang tóm tắt phiên để gọn ngữ cảnh…',
182
176
  compactEmpty: 'Phiên còn trống — không có gì để tóm tắt.',
183
177
  compactSkipped: 'Phiên còn ngắn hoặc tóm tắt thất bại — bỏ qua.',
@@ -199,12 +193,8 @@ export const t = {
199
193
  'cần mô tả yêu cầu. Ví dụ: /frontend-design landing page cho app nghe nhạc lo-fi',
200
194
  workflowRunning: 'đang chạy dynamic workflow đa sub-agent…',
201
195
  workflowNoSkill: 'không tìm thấy skills/dynamic-workflows/SKILL.md — skill chưa được cài.',
202
- workflowNeedArg: 'cần mô tả task. Ví dụ: /workflow audit toàn bộ src/ tìm lỗ hổng SQL injection',
203
- workflowAgentAutoOn: 'agent mode tự bật cho /workflow (cần spawn_agent)',
204
196
  workflowAgentAskHint:
205
197
  '🎼 /workflow cần spawn sub-agent (spawn_agent) — agent mode hiện đang TẮT.',
206
- workflowAgentAskPrompt:
207
- ' bật agent mode và chạy workflow? [y] có, bật & chạy / [n] huỷ (gõ /agent rồi chạy lại nếu muốn) › ',
208
198
  workflowAgentEnabled: 'đã bật agent mode cho workflow này.',
209
199
  bgWorkflowDone: (label) => `workflow nền ${label} đã xong`,
210
200
  bgWorkflowFailed: (label, err) => `workflow nền ${label} lỗi: ${err}`,
@@ -212,8 +202,6 @@ export const t = {
212
202
  workflowAgentDenied:
213
203
  'đã huỷ /workflow — agent mode vẫn TẮT. Gõ /agent rồi chạy lại lệnh nếu muốn.',
214
204
  // saved workflows (CRUD)
215
- workflowListEmpty: (dir) =>
216
- `Chưa có workflow đã lưu. Tạo bằng /workflow save <name> <yêu cầu>. Thư mục: ${dir}`,
217
205
  workflowListHeader: (dir) => `Workflow đã lưu (${dir}):`,
218
206
  workflowSaveNeedArgs: 'Cách dùng: /workflow save <name> <yêu cầu workflow>',
219
207
  workflowSaveEmptyPrompt:
@@ -228,7 +216,6 @@ export const t = {
228
216
  workflowSaveDescOk: (n, d) => `Đã thêm mô tả cho '${n}': ${d}`,
229
217
  workflowRunNeedName: 'Cách dùng: /workflow run <name> [thêm ngữ cảnh]',
230
218
  workflowRunError: (n, e) => `Không nạp được workflow '${n}': ${e}`,
231
- workflowRunOk: (n) => `Chạy workflow đã lưu '${n}'…`,
232
219
  workflowRunPreviewBuiltin: (n, title) => `Built-in workflow '${n}' (${title})`,
233
220
  workflowRunPreviewSaved: (n) => `Workflow đã lưu '${n}'`,
234
221
  workflowLoadNeedName: 'Cách dùng: /workflow load <name>',
@@ -267,7 +254,6 @@ export const t = {
267
254
  updateBgDone: 'Đang cập nhật nền. Mở lại noob để dùng bản mới.',
268
255
  updateChecking: 'Đang kiểm tra cập nhật…',
269
256
  updateLatest: (cur) => `Đã ở bản mới nhất (${cur}).`,
270
- updating: 'Đang cập nhật…',
271
257
  updateOk: '✓ Cập nhật xong. Mở lại noob để dùng bản mới.',
272
258
  updateFail: '✗ Cập nhật thất bại. Thử thủ công: npm i -g @noobdemon/noob-cli@latest',
273
259
  };