@hncode/hncode 0.8.5 → 1.0.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 +30 -0
- package/README_CN.md +27 -0
- package/package.json +1 -1
- package/src/agent.js +172 -43
- package/src/bootstrap.js +63 -56
- package/src/ci.js +247 -247
- package/src/colors.js +5 -1
- package/src/commands.js +121 -0
- package/src/composer.js +31 -1
- package/src/config.js +177 -45
- package/src/context.js +29 -0
- package/src/files.js +32 -0
- package/src/fx.js +19 -2
- package/src/i18n.js +180 -131
- package/src/index.js +558 -77
- package/src/permission-gate.js +103 -0
- package/src/plugin.js +221 -2
- package/src/prompt-presets.js +36 -0
- package/src/protocol.js +184 -0
- package/src/registry-browser.js +14 -3
- package/src/remote.js +117 -5
- package/src/schedule.js +148 -11
- package/src/serve.js +613 -0
- package/src/session-client.js +148 -0
- package/src/session-host.js +52 -0
- package/src/session.js +26 -3
- package/src/settings-schema.js +2 -2
- package/src/status-line.js +48 -0
- package/src/term.js +20 -1
- package/src/toml.js +18 -4
- package/src/tool-line.js +13 -6
- package/src/tool-status.js +45 -0
- package/src/tools/bash.js +43 -24
- package/src/tools/edit.js +10 -5
- package/src/tools/web-search.js +8 -5
- package/src/tools/write.js +28 -3
- package/src/tui.js +498 -1397
- package/src/ws.js +248 -0
- package/src/session-hub.js +0 -445
- package/src/web-auth.js +0 -98
- package/src/web-daemon-cli.js +0 -63
- package/src/web-daemon-client.js +0 -203
- package/src/web-daemon.js +0 -894
- package/src/web-live.js +0 -250
- package/src/web-public/app.css +0 -1524
- package/src/web-public/app.js +0 -2969
- package/src/web-public/complete.js +0 -154
- package/src/web-public/fonts/JetBrainsMono-Bold.woff2 +0 -0
- package/src/web-public/fonts/JetBrainsMono-Regular.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-100-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-101-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-102-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-103-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-104-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-105-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-106-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-107-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-108-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-109-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-110-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-111-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-112-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-113-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-114-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-115-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-116-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-117-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-118-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-119-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-21-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-22-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-23-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-24-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-25-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-26-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-27-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-28-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-29-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-30-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-31-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-32-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-33-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-34-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-35-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-36-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-37-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-38-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-39-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-4-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-40-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-41-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-42-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-43-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-44-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-45-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-46-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-47-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-48-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-49-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-5-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-50-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-51-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-52-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-53-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-54-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-55-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-56-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-57-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-58-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-59-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-6-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-60-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-61-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-62-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-63-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-64-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-65-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-66-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-67-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-68-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-69-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-70-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-71-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-72-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-73-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-74-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-75-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-76-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-77-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-78-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-79-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-80-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-81-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-82-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-83-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-84-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-85-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-86-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-87-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-88-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-89-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-90-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-91-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-97-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-98-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-99-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc.css +0 -775
- package/src/web-public/fonts.css +0 -31
- package/src/web-public/home.css +0 -222
- package/src/web-public/home.html +0 -33
- package/src/web-public/home.js +0 -160
- package/src/web-public/i18n.js +0 -983
- package/src/web-public/index.html +0 -196
- package/src/web-public/login.css +0 -123
- package/src/web-public/login.html +0 -25
- package/src/web-public/login.js +0 -46
- package/src/web-public/settings.js +0 -290
- package/src/web-ws.js +0 -226
- package/src/web.js +0 -430
package/src/tools/edit.js
CHANGED
|
@@ -28,7 +28,8 @@ import { hashRegion as hashLines } from './read.js';
|
|
|
28
28
|
|
|
29
29
|
export const spec = {
|
|
30
30
|
name: 'Edit',
|
|
31
|
-
description: `
|
|
31
|
+
description: `READ THE FILE FIRST. Never edit what you have not read this turn — the contents move, and an edit against a remembered version fails or lands in the wrong place. Read a file again after anything else has changed it.
|
|
32
|
+
Edit a file. Three shapes: LINE-RANGE (path + start_line + end_line + new_string),
|
|
32
33
|
SUBSTRING (path + old_string + new_string, unique unless replace_all), RANGED SUBSTRING (the same plus
|
|
33
34
|
start_line + end_line, which narrows where old_string is searched).
|
|
34
35
|
|
|
@@ -173,8 +174,10 @@ duplicate, the fix is to remove the duplicated line — never to restate another
|
|
|
173
174
|
let rangeHandled = hasSubKeys;
|
|
174
175
|
if (hasRangeKeys && hasSubKeys && hasNewString) {
|
|
175
176
|
if ((start_line != null) !== (end_line != null)) {
|
|
176
|
-
// Ignore the unpaired bound
|
|
177
|
-
//
|
|
177
|
+
// Ignore the unpaired bound: `searchFrom`/`searchTo` stay at the whole file, so the
|
|
178
|
+
// snippet is searched everywhere. `rangeHandled` is already true from `hasSubKeys`, which
|
|
179
|
+
// is what keeps the line-range guard below from seeing the same half-given bound and
|
|
180
|
+
// rejecting a call that was already complete.
|
|
178
181
|
searchFrom = 0;
|
|
179
182
|
searchTo = 0;
|
|
180
183
|
} else {
|
|
@@ -258,7 +261,8 @@ duplicate, the fix is to remove the duplicated line — never to restate another
|
|
|
258
261
|
if (ctx) ctx.lastEditDiff = buildEditDiff({ fileLines: lines, oldText: replacedText, newText: inserted.join('\n'), startLine: start, filePath: p });
|
|
259
262
|
const written = Math.max(1, inserted.length);
|
|
260
263
|
const excerpt = readAfterEdit(p, start, written, ctx);
|
|
261
|
-
|
|
264
|
+
// THE CHANGED REGION IS THE ANSWER. See the note in write.js.
|
|
265
|
+
return excerpt.trimEnd();
|
|
262
266
|
}
|
|
263
267
|
|
|
264
268
|
// ---- SUBSTRING mode (old_string -> new_string) --------------------------
|
|
@@ -415,7 +419,8 @@ duplicate, the fix is to remove the duplicated line — never to restate another
|
|
|
415
419
|
const writtenLines = normalizeText(new_string).split('\n').length;
|
|
416
420
|
const excerpt = readAfterEdit(p, editedAt, writtenLines, replace_all ? null : ctx);
|
|
417
421
|
if (replace_all && ctx && ctx.readPool) ctx.readPool.delete(p);
|
|
418
|
-
|
|
422
|
+
// THE CHANGED REGION IS THE ANSWER. See the note in write.js.
|
|
423
|
+
return excerpt.trimEnd();
|
|
419
424
|
},
|
|
420
425
|
};
|
|
421
426
|
|
package/src/tools/web-search.js
CHANGED
|
@@ -76,12 +76,15 @@ export function parseSearchResults(json, limit = 8) {
|
|
|
76
76
|
export const spec = {
|
|
77
77
|
name: 'WebSearch',
|
|
78
78
|
description: [
|
|
79
|
-
'Search the web.
|
|
80
|
-
'
|
|
79
|
+
'Search the web. Use it whenever you do not know something and the answer is not in the repository:',
|
|
80
|
+
'a library version, an API you have not seen, an error you cannot place, anything after your training',
|
|
81
|
+
'cutoff. A guess presented as fact is worse than a search.',
|
|
81
82
|
'',
|
|
82
|
-
'
|
|
83
|
-
'
|
|
84
|
-
'
|
|
83
|
+
'Results are title/URL/snippet; snippets are summaries, so fetch a promising URL with FetchURL.',
|
|
84
|
+
'Cite the sources you use.',
|
|
85
|
+
'',
|
|
86
|
+
'Use FEW words: two or three that name the thing. Generic terms ("下载", "热门", "官网", "tutorial")',
|
|
87
|
+
'match more junk, not more relevant pages.',
|
|
85
88
|
].join('\n'),
|
|
86
89
|
parameters: {
|
|
87
90
|
type: 'object',
|
package/src/tools/write.js
CHANGED
|
@@ -2,10 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import { resolvePath, ensureDir, truncateBuf, checkpointBeforeWrite } from './utils.js';
|
|
5
|
+
import { uiText } from '../i18n.js';
|
|
5
6
|
|
|
6
7
|
export const spec = {
|
|
7
8
|
name: 'Write',
|
|
8
|
-
|
|
9
|
+
// THE DESCRIPTION IS WHERE THIS TOOL STATES ITS OWN DANGER: it is the text the model reads
|
|
10
|
+
// when deciding whether to call it. A warning kept only in the system prompt is read once at
|
|
11
|
+
// the start of a long turn and is easy to drift from by the end of it.
|
|
12
|
+
//
|
|
13
|
+
// Written through `uiText` so a reader whose interface is Chinese gets the same rules in
|
|
14
|
+
// Chinese: the tool's own contract is not a place to leave someone guessing.
|
|
15
|
+
description: uiText([
|
|
16
|
+
'Create a file, or REPLACE a whole one.',
|
|
17
|
+
'',
|
|
18
|
+
'OVERWRITE IS DESTRUCTIVE: every byte in the target is replaced by `content`. Before calling',
|
|
19
|
+
'this with the default mode on a file that already exists:',
|
|
20
|
+
' 1. Read it first. Never write over a file you have not read this turn.',
|
|
21
|
+
' 2. Prefer Edit for changing part of a file. Edit leaves the rest alone and its diff is',
|
|
22
|
+
' reviewable; Write replaces the whole thing, which is how a file loses the parts nobody',
|
|
23
|
+
' asked about.',
|
|
24
|
+
' 3. Stay inside the workspace. Do not write to config, credential, lock or history files',
|
|
25
|
+
' unless the user asked for exactly that file.',
|
|
26
|
+
'',
|
|
27
|
+
'Writing over an existing file from memory is the usual way this tool destroys work: the',
|
|
28
|
+
'model is sure of the contents from earlier in the turn, the file has moved on, and the',
|
|
29
|
+
'write says nothing about it.',
|
|
30
|
+
'',
|
|
31
|
+
'mode: overwrite (default) | append.',
|
|
32
|
+
].join('\n')),
|
|
9
33
|
parameters: {
|
|
10
34
|
type: 'object',
|
|
11
35
|
properties: {
|
|
@@ -53,7 +77,8 @@ export const spec = {
|
|
|
53
77
|
fs.writeFileSync(p, args.content, { flag });
|
|
54
78
|
} catch (e) { return `Error writing ${path_}: ${e.message}`; }
|
|
55
79
|
const size = fs.statSync(p).size;
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
// THE ONE FACT THE CALLER CANNOT SEE: the file's size after the write. The path and the
|
|
81
|
+
// verb are theirs already, and a sentence around it is a line of transcript for nothing.
|
|
82
|
+
return `${size} bytes`;
|
|
58
83
|
},
|
|
59
84
|
};
|