@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.
Files changed (159) hide show
  1. package/README.md +30 -0
  2. package/README_CN.md +27 -0
  3. package/package.json +1 -1
  4. package/src/agent.js +172 -43
  5. package/src/bootstrap.js +63 -56
  6. package/src/ci.js +247 -247
  7. package/src/colors.js +5 -1
  8. package/src/commands.js +121 -0
  9. package/src/composer.js +31 -1
  10. package/src/config.js +177 -45
  11. package/src/context.js +29 -0
  12. package/src/files.js +32 -0
  13. package/src/fx.js +19 -2
  14. package/src/i18n.js +180 -131
  15. package/src/index.js +558 -77
  16. package/src/permission-gate.js +103 -0
  17. package/src/plugin.js +221 -2
  18. package/src/prompt-presets.js +36 -0
  19. package/src/protocol.js +184 -0
  20. package/src/registry-browser.js +14 -3
  21. package/src/remote.js +117 -5
  22. package/src/schedule.js +148 -11
  23. package/src/serve.js +613 -0
  24. package/src/session-client.js +148 -0
  25. package/src/session-host.js +52 -0
  26. package/src/session.js +26 -3
  27. package/src/settings-schema.js +2 -2
  28. package/src/status-line.js +48 -0
  29. package/src/term.js +20 -1
  30. package/src/toml.js +18 -4
  31. package/src/tool-line.js +13 -6
  32. package/src/tool-status.js +45 -0
  33. package/src/tools/bash.js +43 -24
  34. package/src/tools/edit.js +10 -5
  35. package/src/tools/web-search.js +8 -5
  36. package/src/tools/write.js +28 -3
  37. package/src/tui.js +498 -1397
  38. package/src/ws.js +248 -0
  39. package/src/session-hub.js +0 -445
  40. package/src/web-auth.js +0 -98
  41. package/src/web-daemon-cli.js +0 -63
  42. package/src/web-daemon-client.js +0 -203
  43. package/src/web-daemon.js +0 -894
  44. package/src/web-live.js +0 -250
  45. package/src/web-public/app.css +0 -1524
  46. package/src/web-public/app.js +0 -2969
  47. package/src/web-public/complete.js +0 -154
  48. package/src/web-public/fonts/JetBrainsMono-Bold.woff2 +0 -0
  49. package/src/web-public/fonts/JetBrainsMono-Regular.woff2 +0 -0
  50. package/src/web-public/fonts/noto-sans-sc-100-400-normal.woff2 +0 -0
  51. package/src/web-public/fonts/noto-sans-sc-101-400-normal.woff2 +0 -0
  52. package/src/web-public/fonts/noto-sans-sc-102-400-normal.woff2 +0 -0
  53. package/src/web-public/fonts/noto-sans-sc-103-400-normal.woff2 +0 -0
  54. package/src/web-public/fonts/noto-sans-sc-104-400-normal.woff2 +0 -0
  55. package/src/web-public/fonts/noto-sans-sc-105-400-normal.woff2 +0 -0
  56. package/src/web-public/fonts/noto-sans-sc-106-400-normal.woff2 +0 -0
  57. package/src/web-public/fonts/noto-sans-sc-107-400-normal.woff2 +0 -0
  58. package/src/web-public/fonts/noto-sans-sc-108-400-normal.woff2 +0 -0
  59. package/src/web-public/fonts/noto-sans-sc-109-400-normal.woff2 +0 -0
  60. package/src/web-public/fonts/noto-sans-sc-110-400-normal.woff2 +0 -0
  61. package/src/web-public/fonts/noto-sans-sc-111-400-normal.woff2 +0 -0
  62. package/src/web-public/fonts/noto-sans-sc-112-400-normal.woff2 +0 -0
  63. package/src/web-public/fonts/noto-sans-sc-113-400-normal.woff2 +0 -0
  64. package/src/web-public/fonts/noto-sans-sc-114-400-normal.woff2 +0 -0
  65. package/src/web-public/fonts/noto-sans-sc-115-400-normal.woff2 +0 -0
  66. package/src/web-public/fonts/noto-sans-sc-116-400-normal.woff2 +0 -0
  67. package/src/web-public/fonts/noto-sans-sc-117-400-normal.woff2 +0 -0
  68. package/src/web-public/fonts/noto-sans-sc-118-400-normal.woff2 +0 -0
  69. package/src/web-public/fonts/noto-sans-sc-119-400-normal.woff2 +0 -0
  70. package/src/web-public/fonts/noto-sans-sc-21-400-normal.woff2 +0 -0
  71. package/src/web-public/fonts/noto-sans-sc-22-400-normal.woff2 +0 -0
  72. package/src/web-public/fonts/noto-sans-sc-23-400-normal.woff2 +0 -0
  73. package/src/web-public/fonts/noto-sans-sc-24-400-normal.woff2 +0 -0
  74. package/src/web-public/fonts/noto-sans-sc-25-400-normal.woff2 +0 -0
  75. package/src/web-public/fonts/noto-sans-sc-26-400-normal.woff2 +0 -0
  76. package/src/web-public/fonts/noto-sans-sc-27-400-normal.woff2 +0 -0
  77. package/src/web-public/fonts/noto-sans-sc-28-400-normal.woff2 +0 -0
  78. package/src/web-public/fonts/noto-sans-sc-29-400-normal.woff2 +0 -0
  79. package/src/web-public/fonts/noto-sans-sc-30-400-normal.woff2 +0 -0
  80. package/src/web-public/fonts/noto-sans-sc-31-400-normal.woff2 +0 -0
  81. package/src/web-public/fonts/noto-sans-sc-32-400-normal.woff2 +0 -0
  82. package/src/web-public/fonts/noto-sans-sc-33-400-normal.woff2 +0 -0
  83. package/src/web-public/fonts/noto-sans-sc-34-400-normal.woff2 +0 -0
  84. package/src/web-public/fonts/noto-sans-sc-35-400-normal.woff2 +0 -0
  85. package/src/web-public/fonts/noto-sans-sc-36-400-normal.woff2 +0 -0
  86. package/src/web-public/fonts/noto-sans-sc-37-400-normal.woff2 +0 -0
  87. package/src/web-public/fonts/noto-sans-sc-38-400-normal.woff2 +0 -0
  88. package/src/web-public/fonts/noto-sans-sc-39-400-normal.woff2 +0 -0
  89. package/src/web-public/fonts/noto-sans-sc-4-400-normal.woff2 +0 -0
  90. package/src/web-public/fonts/noto-sans-sc-40-400-normal.woff2 +0 -0
  91. package/src/web-public/fonts/noto-sans-sc-41-400-normal.woff2 +0 -0
  92. package/src/web-public/fonts/noto-sans-sc-42-400-normal.woff2 +0 -0
  93. package/src/web-public/fonts/noto-sans-sc-43-400-normal.woff2 +0 -0
  94. package/src/web-public/fonts/noto-sans-sc-44-400-normal.woff2 +0 -0
  95. package/src/web-public/fonts/noto-sans-sc-45-400-normal.woff2 +0 -0
  96. package/src/web-public/fonts/noto-sans-sc-46-400-normal.woff2 +0 -0
  97. package/src/web-public/fonts/noto-sans-sc-47-400-normal.woff2 +0 -0
  98. package/src/web-public/fonts/noto-sans-sc-48-400-normal.woff2 +0 -0
  99. package/src/web-public/fonts/noto-sans-sc-49-400-normal.woff2 +0 -0
  100. package/src/web-public/fonts/noto-sans-sc-5-400-normal.woff2 +0 -0
  101. package/src/web-public/fonts/noto-sans-sc-50-400-normal.woff2 +0 -0
  102. package/src/web-public/fonts/noto-sans-sc-51-400-normal.woff2 +0 -0
  103. package/src/web-public/fonts/noto-sans-sc-52-400-normal.woff2 +0 -0
  104. package/src/web-public/fonts/noto-sans-sc-53-400-normal.woff2 +0 -0
  105. package/src/web-public/fonts/noto-sans-sc-54-400-normal.woff2 +0 -0
  106. package/src/web-public/fonts/noto-sans-sc-55-400-normal.woff2 +0 -0
  107. package/src/web-public/fonts/noto-sans-sc-56-400-normal.woff2 +0 -0
  108. package/src/web-public/fonts/noto-sans-sc-57-400-normal.woff2 +0 -0
  109. package/src/web-public/fonts/noto-sans-sc-58-400-normal.woff2 +0 -0
  110. package/src/web-public/fonts/noto-sans-sc-59-400-normal.woff2 +0 -0
  111. package/src/web-public/fonts/noto-sans-sc-6-400-normal.woff2 +0 -0
  112. package/src/web-public/fonts/noto-sans-sc-60-400-normal.woff2 +0 -0
  113. package/src/web-public/fonts/noto-sans-sc-61-400-normal.woff2 +0 -0
  114. package/src/web-public/fonts/noto-sans-sc-62-400-normal.woff2 +0 -0
  115. package/src/web-public/fonts/noto-sans-sc-63-400-normal.woff2 +0 -0
  116. package/src/web-public/fonts/noto-sans-sc-64-400-normal.woff2 +0 -0
  117. package/src/web-public/fonts/noto-sans-sc-65-400-normal.woff2 +0 -0
  118. package/src/web-public/fonts/noto-sans-sc-66-400-normal.woff2 +0 -0
  119. package/src/web-public/fonts/noto-sans-sc-67-400-normal.woff2 +0 -0
  120. package/src/web-public/fonts/noto-sans-sc-68-400-normal.woff2 +0 -0
  121. package/src/web-public/fonts/noto-sans-sc-69-400-normal.woff2 +0 -0
  122. package/src/web-public/fonts/noto-sans-sc-70-400-normal.woff2 +0 -0
  123. package/src/web-public/fonts/noto-sans-sc-71-400-normal.woff2 +0 -0
  124. package/src/web-public/fonts/noto-sans-sc-72-400-normal.woff2 +0 -0
  125. package/src/web-public/fonts/noto-sans-sc-73-400-normal.woff2 +0 -0
  126. package/src/web-public/fonts/noto-sans-sc-74-400-normal.woff2 +0 -0
  127. package/src/web-public/fonts/noto-sans-sc-75-400-normal.woff2 +0 -0
  128. package/src/web-public/fonts/noto-sans-sc-76-400-normal.woff2 +0 -0
  129. package/src/web-public/fonts/noto-sans-sc-77-400-normal.woff2 +0 -0
  130. package/src/web-public/fonts/noto-sans-sc-78-400-normal.woff2 +0 -0
  131. package/src/web-public/fonts/noto-sans-sc-79-400-normal.woff2 +0 -0
  132. package/src/web-public/fonts/noto-sans-sc-80-400-normal.woff2 +0 -0
  133. package/src/web-public/fonts/noto-sans-sc-81-400-normal.woff2 +0 -0
  134. package/src/web-public/fonts/noto-sans-sc-82-400-normal.woff2 +0 -0
  135. package/src/web-public/fonts/noto-sans-sc-83-400-normal.woff2 +0 -0
  136. package/src/web-public/fonts/noto-sans-sc-84-400-normal.woff2 +0 -0
  137. package/src/web-public/fonts/noto-sans-sc-85-400-normal.woff2 +0 -0
  138. package/src/web-public/fonts/noto-sans-sc-86-400-normal.woff2 +0 -0
  139. package/src/web-public/fonts/noto-sans-sc-87-400-normal.woff2 +0 -0
  140. package/src/web-public/fonts/noto-sans-sc-88-400-normal.woff2 +0 -0
  141. package/src/web-public/fonts/noto-sans-sc-89-400-normal.woff2 +0 -0
  142. package/src/web-public/fonts/noto-sans-sc-90-400-normal.woff2 +0 -0
  143. package/src/web-public/fonts/noto-sans-sc-91-400-normal.woff2 +0 -0
  144. package/src/web-public/fonts/noto-sans-sc-97-400-normal.woff2 +0 -0
  145. package/src/web-public/fonts/noto-sans-sc-98-400-normal.woff2 +0 -0
  146. package/src/web-public/fonts/noto-sans-sc-99-400-normal.woff2 +0 -0
  147. package/src/web-public/fonts/noto-sans-sc.css +0 -775
  148. package/src/web-public/fonts.css +0 -31
  149. package/src/web-public/home.css +0 -222
  150. package/src/web-public/home.html +0 -33
  151. package/src/web-public/home.js +0 -160
  152. package/src/web-public/i18n.js +0 -983
  153. package/src/web-public/index.html +0 -196
  154. package/src/web-public/login.css +0 -123
  155. package/src/web-public/login.html +0 -25
  156. package/src/web-public/login.js +0 -46
  157. package/src/web-public/settings.js +0 -290
  158. package/src/web-ws.js +0 -226
  159. 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: `Edit a file. Three shapes: LINE-RANGE (path + start_line + end_line + new_string),
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; `searchFrom`/`searchTo` stay at the whole file and `rangedToWindow`
177
- // was already set above.
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
- return `Edited ${args.path}: replaced lines ${start}-${end} (${removed} line${removed === 1 ? '' : 's'}) with ${inserted.length} line${inserted.length === 1 ? '' : 's'}.\n\n${excerpt}`.trimEnd();
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
- return `Edited ${args.path}: replaced ${occurrences} occurrence(s).\n\n${excerpt}`.trimEnd();
422
+ // THE CHANGED REGION IS THE ANSWER. See the note in write.js.
423
+ return excerpt.trimEnd();
419
424
  },
420
425
  };
421
426
 
@@ -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. Results are title/URL/snippet; snippets are summaries, so fetch a promising URL with',
80
- 'FetchURL. Cite sources.',
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
- 'Use FEW words: two or three that name the thing. Adding generic terms ("下载", "热门", "官网",',
83
- '"tutorial") does not narrow the search — it matches more unrelated pages, because those are the words',
84
- 'junk pages stuff into their titles.',
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',
@@ -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
- description: 'Create or overwrite a file (prefer Edit for existing files). mode: overwrite (default) | append.',
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
- const verb = mode === 'append' ? 'appended to' : 'written';
57
- return `File ${verb}: ${path_} (${size} bytes)`;
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
  };