@thincoder/core 0.11.2 → 0.11.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 +18 -0
- package/advisor/compaction.mjs +7 -5
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +13 -8
- package/advisor/messages.mjs +72 -8
- package/advisor/run.mjs +24 -13
- package/advisor.mjs +7 -3
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +28 -40
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +2 -1
- package/agent/family-tools.mjs +12 -13
- package/agent/helpers.mjs +17 -72
- package/agent/image-heal.mjs +18 -4
- package/agent/post-turn.mjs +13 -26
- package/agent/record-results.mjs +21 -6
- package/agent/run-stages.mjs +72 -37
- package/agent/run-start.mjs +148 -113
- package/agent/setup-reminders.mjs +187 -91
- package/agent/setup.mjs +204 -138
- package/agent/spawn-child.mjs +2 -2
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +4 -1
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +54 -22
- package/agent/turn-projection.mjs +127 -227
- package/agent/turn-tool-process.mjs +32 -37
- package/agent-tools/advisor-async.mjs +6 -3
- package/agent-tools/advisor-launch.mjs +5 -5
- package/agent-tools/advisor.mjs +1 -1
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +12 -62
- package/agent-tools/batch-ledger-bind.mjs +19 -8
- package/agent-tools/batch-lifecycle.mjs +37 -11
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +5 -5
- package/agent-tools/batch-segment-vocab.mjs +84 -4
- package/agent-tools/batch-skeleton.mjs +18 -14
- package/agent-tools/batch-supersede.mjs +1 -1
- package/agent-tools/batch-tier-gate.mjs +36 -119
- package/agent-tools/batch.mjs +30 -20
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +10 -7
- package/agent-tools/context.mjs +47 -31
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/eng.mjs +3 -4
- package/agent-tools/escalate-async.mjs +3 -3
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +2 -2
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/review-facts.mjs +9 -3
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +5 -16
- package/agent-tools/ssh-session.mjs +6 -3
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +11 -8
- package/agent-tools/subagent-scheduler.mjs +9 -9
- package/agent-tools/subagent-spawn.mjs +2 -2
- package/agent-tools/subagent.mjs +5 -18
- package/agent-tools/task.mjs +0 -8
- package/agent.mjs +15 -15
- package/auto-think.mjs +5 -2
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +5 -2
- package/config.mjs +53 -17
- package/context-degrade.mjs +79 -48
- package/context-echo.mjs +6 -26
- package/context-push.mjs +328 -31
- package/context.mjs +203 -141
- package/conventions.mjs +1 -1
- package/declaration.mjs +95 -17
- package/escape.mjs +6 -5
- package/explore-distill.mjs +35 -8
- package/generate-title.mjs +10 -1
- package/knowledge/prompt-resources.md +5 -1
- package/ledger-tools.mjs +50 -50
- package/ledger-write-ops.mjs +43 -16
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +1 -1
- package/prompt-files.mjs +33 -11
- package/prompt-overlays.mjs +12 -5
- package/prompts/advisor-design.md +55 -36
- package/prompts/advisor-round1.md +18 -7
- package/prompts/advisor-round2.md +18 -7
- package/prompts/advisor-round3.md +18 -7
- package/prompts/common.md +89 -51
- package/prompts/consult-base.md +2 -3
- package/prompts/discipline-engineering.md +474 -440
- package/prompts/discipline-normal.md +107 -31
- package/prompts/knowledge/business-gates.md +23 -15
- package/prompts/knowledge/decision-quality.md +16 -18
- package/prompts/knowledge/doc-lookup.md +22 -27
- package/prompts/knowledge/document-writing.md +31 -49
- package/prompts/knowledge/documentation-evaluation.md +37 -45
- package/prompts/knowledge/evidence-discipline.md +36 -55
- package/prompts/knowledge/normal-coding-workflow.md +27 -21
- package/prompts/knowledge/normal-delivery-collaboration.md +33 -17
- package/prompts/knowledge/normal-work-management.md +10 -7
- package/prompts/knowledge/product-security.md +22 -17
- package/prompts/knowledge/project-records.md +63 -52
- package/prompts/knowledge/tool-apply-patch.md +12 -13
- package/prompts/knowledge/tool-bash.md +13 -4
- package/prompts/knowledge/tool-batch-eng-coder.md +13 -6
- package/prompts/knowledge/tool-batch-eng-designer.md +14 -6
- package/prompts/knowledge/tool-batch-review.md +12 -6
- package/prompts/knowledge/tool-batch.md +76 -62
- package/prompts/knowledge/tool-browser.md +45 -34
- package/prompts/knowledge/tool-context.md +2 -2
- package/prompts/knowledge/tool-delete.md +5 -1
- package/prompts/knowledge/tool-doc-check.md +25 -24
- package/prompts/knowledge/tool-doc-graph-read.md +3 -3
- package/prompts/knowledge/tool-doc-graph.md +15 -15
- package/prompts/knowledge/tool-edit.md +26 -23
- package/prompts/knowledge/tool-execute.md +9 -4
- package/prompts/knowledge/tool-fetch.md +7 -1
- package/prompts/knowledge/tool-file-ops.md +6 -1
- package/prompts/knowledge/tool-git-read.md +3 -1
- package/prompts/knowledge/tool-git.md +1 -1
- package/prompts/knowledge/tool-glob.md +3 -1
- package/prompts/knowledge/tool-grep.md +5 -2
- package/prompts/knowledge/tool-hashline-edit.md +4 -2
- package/prompts/knowledge/tool-insert-after.md +3 -1
- package/prompts/knowledge/tool-ledger-read.md +6 -13
- package/prompts/knowledge/tool-ledger.md +14 -10
- package/prompts/knowledge/tool-ls.md +2 -0
- package/prompts/knowledge/tool-manifest.md +10 -7
- package/prompts/knowledge/tool-memory.md +15 -11
- package/prompts/knowledge/tool-operations.md +59 -71
- package/prompts/knowledge/tool-plan.md +1 -2
- package/prompts/knowledge/tool-process.md +1 -1
- package/prompts/knowledge/tool-read-history.md +6 -7
- package/prompts/knowledge/tool-read.md +1 -0
- package/prompts/knowledge/tool-settings.md +6 -7
- package/prompts/knowledge/tool-ssh.md +37 -15
- package/prompts/knowledge/tool-subagent.md +37 -39
- package/prompts/knowledge/tool-task.md +3 -1
- package/prompts/knowledge/tool-team-ledger.md +5 -1
- package/prompts/knowledge/tool-tree.md +2 -0
- package/prompts/knowledge/tool-wait-for.md +16 -16
- package/prompts/knowledge/tool-write.md +4 -1
- package/prompts/knowledge/upstream-protocol.md +39 -37
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +5 -5
- package/prompts/persona-eng-designer.md +34 -17
- package/prompts/persona-engineering.md +532 -501
- package/prompts/persona-explore.md +0 -2
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +0 -2
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +0 -2
- package/provider/anthropic.mjs +4 -2
- package/provider/core.mjs +5 -3
- package/provider/errors.mjs +41 -7
- package/provider/google.mjs +5 -3
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +4 -2
- package/provider/sse.mjs +11 -6
- package/rules.mjs +11 -10
- package/session-lifecycle.mjs +115 -81
- package/session-slot-write.mjs +1 -1
- package/session.mjs +23 -20
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +24 -0
- package/team-ledger.mjs +22 -22
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +1 -1
- package/token-window.mjs +278 -88
- package/tool-docs/bash.md +0 -2
- package/tool-docs/consult_start.md +2 -2
- package/tool-docs/consult_stop.md +2 -2
- package/tools/browser.mjs +8 -8
- package/tools/execute.mjs +2 -2
- package/tools/file.mjs +17 -11
- package/tools/git.mjs +12 -12
- package/tools/ops.mjs +2 -2
- package/tools/patch.mjs +1 -1
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +4 -3
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +3 -3
- package/window-policy.mjs +118 -78
package/tools/file.mjs
CHANGED
|
@@ -20,6 +20,9 @@ import { runSingleEdit } from "./edit-diff.mjs";
|
|
|
20
20
|
// 记账面同源住该档(下面只做再导出——保既有 import 面稳定)。
|
|
21
21
|
import { writeThroughPath, clearDirty, clearLastWrite, lineAnchorVerdict, lineAnchorRefusal } from "./write-path.mjs";
|
|
22
22
|
import { specForModel } from "../config.mjs";
|
|
23
|
+
// 层标识(机制 = `docs/core/design/DOC-SYSTEM.md` §3.1「层标识」):`read` 的输出就是一份档,
|
|
24
|
+
// 所以它带层标识;它**不**参与默认排除(点名读是显式请求——`docs/core/design/TOOLS.md` §7.1)。
|
|
25
|
+
import { docLayerName } from "./process-doc-mark.mjs";
|
|
23
26
|
import { createHash } from "node:crypto";
|
|
24
27
|
import { mkdir, readFile, stat } from "node:fs/promises";
|
|
25
28
|
import { join, relative, dirname } from "node:path";
|
|
@@ -90,6 +93,9 @@ export const readTool = {
|
|
|
90
93
|
clearDirty(abs)
|
|
91
94
|
clearLastWrite(abs) // 2026-08-31:read 同时清写入快照(新视图以 read 为准)
|
|
92
95
|
const lines = content.split("\n")
|
|
96
|
+
// 层标识单起一行:掺进正文行会破坏 `L<n>\t<正文>` 这个逐字格式。图片走 `read_image`(另一条出口),
|
|
97
|
+
// 失败走 throw——两者都没有这一行,因为那里没有编号正文。
|
|
98
|
+
const layerLine = `[${docLayerName(abs)}]`
|
|
93
99
|
const offset = Math.max(1, args.offset ?? 1)
|
|
94
100
|
const limit = Math.min(args.limit ?? MAX_READ_LINES, MAX_READ_LINES)
|
|
95
101
|
const windowEnd = offset - 1 + limit // index just past the requested window
|
|
@@ -105,7 +111,7 @@ export const readTool = {
|
|
|
105
111
|
// 也走旧路径。与 hashes 模式照常交互(头尾行 hash 照算)。
|
|
106
112
|
if (windowEnd >= lines.length || lines.length <= MAX_READ_LINES) {
|
|
107
113
|
const suffix = windowEnd < lines.length ? `\n... (${lines.length} lines total, use offset to continue)` : ""
|
|
108
|
-
return truncate(render(lines.slice(offset - 1, windowEnd), offset) + suffix)
|
|
114
|
+
return `${layerLine}\n${truncate(render(lines.slice(offset - 1, windowEnd), offset) + suffix)}`
|
|
109
115
|
}
|
|
110
116
|
const head = render(lines.slice(offset - 1, windowEnd), offset)
|
|
111
117
|
// 尾区 = 文件末 READ_TAIL_LINES 行;尾区起点落在窗口内(重叠)→ 尾区从窗口后开始
|
|
@@ -114,8 +120,8 @@ export const readTool = {
|
|
|
114
120
|
const middle = tailStart - windowEnd
|
|
115
121
|
const tail = render(lines.slice(tailStart), tailStart + 1)
|
|
116
122
|
return middle > 0
|
|
117
|
-
? `${head}\n…(truncated: ${middle} lines in middle, use offset to continue)\n${tail}`
|
|
118
|
-
: `${head}\n${tail}`
|
|
123
|
+
? `${layerLine}\n${head}\n…(truncated: ${middle} lines in middle, use offset to continue)\n${tail}`
|
|
124
|
+
: `${layerLine}\n${head}\n${tail}`
|
|
119
125
|
},
|
|
120
126
|
}
|
|
121
127
|
|
|
@@ -227,16 +233,16 @@ export const editTool = {
|
|
|
227
233
|
parameters: {
|
|
228
234
|
type: "object",
|
|
229
235
|
properties: {
|
|
230
|
-
path: { type: "string", description: "
|
|
231
|
-
old_string: { type: "string", description: "
|
|
232
|
-
new_string: { type: "string", description: "Replacement text
|
|
233
|
-
line: { type: "integer", description: "1-based line
|
|
234
|
-
startLine: { type: "integer", description: "1-based first line of the range
|
|
235
|
-
endLine: { type: "integer", description: "1-based last line of the range
|
|
236
|
-
replace_all: { type: "boolean", description: "Replace
|
|
236
|
+
path: { type: "string", description: "Path. Required in single form; with `edits`, a default for entries lacking their own." },
|
|
237
|
+
old_string: { type: "string", description: "Text to replace. Match order: exact, then whitespace-only variant, then fuzzy at ≥90% line equality (whitespace, indent and quotes normalized). Mutually exclusive with line/startLine/endLine." },
|
|
238
|
+
new_string: { type: "string", description: "Replacement text. Content targeting requires it, and an empty string is an error there (with replace_all it would delete every match). Line targeting may omit it or pass \"\" — both delete the range." },
|
|
239
|
+
line: { type: "integer", description: "1-based line to replace. Omit new_string to delete it. Mutually exclusive with old_string, startLine and endLine." },
|
|
240
|
+
startLine: { type: "integer", description: "1-based first line of the range. Requires endLine. Omit new_string to delete the range." },
|
|
241
|
+
endLine: { type: "integer", description: "1-based last line of the range. Requires startLine. Omit new_string to delete the range." },
|
|
242
|
+
replace_all: { type: "boolean", description: "Replace every occurrence (default false)." },
|
|
237
243
|
edits: {
|
|
238
244
|
type: "array",
|
|
239
|
-
description: "Batch form
|
|
245
|
+
description: "Batch form: several edits in one call, each reported separately. A failing entry does not stop the rest; but if the file's final content is rejected, that file writes nothing. Files already written are never rolled back. Line entries apply first, descending by startLine, ranges non-overlapping; content entries then in array order. Top-level path defaults entries without one (an entry's own path wins). No top-level targeting params here — put them inside each entry.",
|
|
240
246
|
items: {
|
|
241
247
|
type: "object",
|
|
242
248
|
properties: {
|
package/tools/git.mjs
CHANGED
|
@@ -56,10 +56,10 @@ export const gitTool = {
|
|
|
56
56
|
parameters: {
|
|
57
57
|
type: "object",
|
|
58
58
|
properties: {
|
|
59
|
-
action: { type: "string", enum: ["diff", "status", "log", "show", "checkpoint", "add", "rm", "commit", "push", "tag", "branch", "checkout", "restore", "stash", "fetch", "pull", "reset", "revert", "merge", "cherry-pick", "ls-remote", "clone", "init", "rebase", "remote", "clean", "switch", "apply", "worktree", "archive", "blame", "mv"], description: "
|
|
59
|
+
action: { type: "string", enum: ["diff", "status", "log", "show", "checkpoint", "add", "rm", "commit", "push", "tag", "branch", "checkout", "restore", "stash", "fetch", "pull", "reset", "revert", "merge", "cherry-pick", "ls-remote", "clone", "init", "rebase", "remote", "clean", "switch", "apply", "worktree", "archive", "blame", "mv"], description: "Subcommand to run. `clean` and `rebase` snapshot the tree first; recover with `checkpointAction: \"rewind\"`." },
|
|
60
60
|
// diff/log params
|
|
61
61
|
staged: { type: "boolean", description: "(diff) Show staged changes instead of working tree" },
|
|
62
|
-
path: { type: "string", description: "
|
|
62
|
+
path: { type: "string", description: "File or directory this subcommand acts on. `checkout -- <path>` and `restore` snapshot the tree first; recover with `checkpointAction: \"rewind\"`. `add`, `rm` and `commit` take several paths, space-separated — a name containing spaces is split as several paths." },
|
|
63
63
|
ref: { type: "string", description: "(diff/show/checkout/reset/revert/merge/cherry-pick/tag:create/branch:create/rebase/worktree:add/archive) Commit/branch/ref; (push/pull/fetch) the branch or tag (space-separated for multiple)" },
|
|
64
64
|
count: { type: "number", description: "(log) Number of commits (default 10)" },
|
|
65
65
|
oneline: { type: "boolean", description: "(log) One-line-per-commit format" },
|
|
@@ -68,24 +68,24 @@ export const gitTool = {
|
|
|
68
68
|
// write-op params
|
|
69
69
|
name: { type: "string", description: "(branch/tag) The branch or tag name (create/delete/switch)" },
|
|
70
70
|
remote: { type: "string", description: "(push/fetch/pull) Remote name (e.g. origin). Default: current upstream" },
|
|
71
|
-
workdir: { type: "string", description: "Run git in this subdirectory (monorepo / multi-repo). Path relative to cwd — no directory restriction. Default: the discovered project repo root
|
|
71
|
+
workdir: { type: "string", description: "Run git in this subdirectory (monorepo / multi-repo). Path relative to cwd — no directory restriction. Default: the discovered project repo root; an explicit workdir wins." },
|
|
72
72
|
config: { type: "array", items: { type: "string" }, description: "(network actions: push/fetch/pull/ls-remote) git -c overrides, e.g. [\"http.proxy=http://10.2.2.112:3128\"] for blocked remotes" },
|
|
73
73
|
tags: { type: "boolean", description: "(push) Also push all tags (--tags)" },
|
|
74
|
-
mode: { type: "string", enum: ["soft", "mixed", "hard"], description: "(reset)
|
|
75
|
-
tagAction: { type: "string", enum: ["list", "create", "delete"], description: "(tag)
|
|
76
|
-
branchAction: { type: "string", enum: ["list", "create", "delete", "switch"], description: "(branch)
|
|
77
|
-
stashAction: { type: "string", enum: ["push", "pop", "list"], description: "(stash)
|
|
74
|
+
mode: { type: "string", enum: ["soft", "mixed", "hard"], description: "(reset) Reset mode. `hard` snapshots the tree first and needs confirmation; recover with `checkpointAction: \"rewind\"`." },
|
|
75
|
+
tagAction: { type: "string", enum: ["list", "create", "delete"], description: "(tag) Which tag action to run. `delete` snapshots first; recover with `checkpointAction: \"rewind\"`." },
|
|
76
|
+
branchAction: { type: "string", enum: ["list", "create", "delete", "switch"], description: "(branch) Which branch action to run. `delete` snapshots first; recover with `checkpointAction: \"rewind\"`." },
|
|
77
|
+
stashAction: { type: "string", enum: ["push", "pop", "list"], description: "(stash) Which stash action to run. `pop` applies then drops the entry, and snapshots first; recover with `checkpointAction: \"rewind\"`." },
|
|
78
78
|
// checkpoint params
|
|
79
|
-
checkpointAction: { type: "string", enum: ["list", "create", "rewind", "cat", "versions"], description: "(checkpoint)
|
|
79
|
+
checkpointAction: { type: "string", enum: ["list", "create", "rewind", "cat", "versions"], description: "(checkpoint) Which snapshot action to run. `rewind` restores a pre-operation state (it snapshots first, so it is reversible); `cat` needs `checkpointId`." },
|
|
80
80
|
checkpointId: { type: "string", description: "(checkpoint) Snapshot id — required for rewind and cat; optional for list (shows file tree)" },
|
|
81
81
|
// F7 new-action params
|
|
82
|
-
remoteAction: { type: "string", enum: ["list", "add", "remove", "set-url"], description: "(remote)
|
|
82
|
+
remoteAction: { type: "string", enum: ["list", "add", "remove", "set-url"], description: "(remote) Which remote action to run; `add` and `set-url` need `remoteUrl`." },
|
|
83
83
|
remoteUrl: { type: "string", description: "(remote add/set-url) Remote URL (https/git/ssh or local path)" },
|
|
84
|
-
rebaseAction: { type: "string", enum: ["start", "abort", "continue"], description: "(rebase) start
|
|
85
|
-
dryRun: { type: "boolean", description: "(clean)
|
|
84
|
+
rebaseAction: { type: "string", enum: ["start", "abort", "continue"], description: "(rebase) Which rebase step to run. `start` needs `ref`; the tree is snapshotted first — recover with `checkpointAction: \"rewind\"`." },
|
|
85
|
+
dryRun: { type: "boolean", description: "(clean) Preview only (-n) — no deletion, no snapshot. A real `clean` snapshots first; recover with `checkpointAction: \"rewind\"`." },
|
|
86
86
|
create: { type: "boolean", description: "(switch) create the branch then switch (-c)" },
|
|
87
87
|
dest: { type: "string", description: "(mv) destination path (file or directory)" },
|
|
88
|
-
worktreeAction: { type: "string", enum: ["list", "add", "remove"], description: "(worktree)
|
|
88
|
+
worktreeAction: { type: "string", enum: ["list", "add", "remove"], description: "(worktree) Which worktree action to run; `add` takes `path` and `ref`, `remove` takes `path`." },
|
|
89
89
|
},
|
|
90
90
|
required: ["action"],
|
|
91
91
|
},
|
package/tools/ops.mjs
CHANGED
|
@@ -23,7 +23,7 @@ export const fileOpsTool = {
|
|
|
23
23
|
parameters: {
|
|
24
24
|
type: "object",
|
|
25
25
|
properties: {
|
|
26
|
-
action: { type: "string", enum: ["move", "copy", "rename"], description: "
|
|
26
|
+
action: { type: "string", enum: ["move", "copy", "rename"], description: "The action to run." },
|
|
27
27
|
source: { type: "string", description: "Source path, relative to cwd or absolute" },
|
|
28
28
|
dest: { type: "string", description: "Destination path" },
|
|
29
29
|
ledger: { type: "string", description: LEDGER_PARAM_DESC },
|
|
@@ -60,7 +60,7 @@ export const processTool = {
|
|
|
60
60
|
action: { type: "string", enum: ["list", "kill"], description: "list (default) — show running processes; kill — terminate a process tree (target: pid) or a background task (target: id)" },
|
|
61
61
|
name: { type: "string", description: "Optional name substring filter for list (case-insensitive)" },
|
|
62
62
|
pid: { type: "number", description: "kill target: process id — the whole tree is terminated (taskkill /T /F on win32; POSIX group kill)" },
|
|
63
|
-
id: { type: "number", description: "kill target: background task id — a bash#N
|
|
63
|
+
id: { type: "number", description: "kill target: background task id — the N from a `bash#N` or `browser#N` ack, as a number. bash ⇒ its process tree is terminated. browser ⇒ a queued task is dropped, a running one aborted (the browser itself is not killed). Either way the entry leaves the pool and no digest arrives." },
|
|
64
64
|
},
|
|
65
65
|
},
|
|
66
66
|
// #9:动作分级——list 保持只读分类(dispatch-gates `isReadonlyAction`:planMode 放行/
|
package/tools/patch.mjs
CHANGED
|
@@ -239,7 +239,7 @@ export const applyPatchTool = {
|
|
|
239
239
|
parameters: {
|
|
240
240
|
type: "object",
|
|
241
241
|
properties: {
|
|
242
|
-
patch: { type: "string", description: "Unified diff.
|
|
242
|
+
patch: { type: "string", description: "Unified diff. One `--- a/<path>` / `+++ b/<path>` pair per file, then @@ hunks. Creating files: `--- /dev/null` plus the path header. A bare `@@` hunk is located by its anchor lines — the context lines plus the removed (-) lines, matched as one contiguous unique sequence; it applies only when that sequence is unique and it either removes at least one line or carries at least 2 context lines. Anchor-free pure-+ hunks need at least 2 context lines. For an existing file the `+++ b/<path>` pair may be omitted: a lone `--- a/<path>` (or `--- b/<path>`) header followed directly by hunks applies to that path." },
|
|
243
243
|
ledger: { type: "string", description: LEDGER_PARAM_DESC },
|
|
244
244
|
// 工作区根窄口(设计档 §2.3.1):目标取不到项目根时才被读;目标有根时以路径为准(定位参数优先)。
|
|
245
245
|
project: { type: "string", description: PROJECT_PARAM_DESC },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* process-doc-mark.mjs —
|
|
2
|
+
* process-doc-mark.mjs — 工具输出里的过程档标记与文档层标识(单源小档;过程层排除的机制 = `docs/core/design/TOOLS.md` §7.1
|
|
3
|
+
* 「检索与浏览类工具的过程层默认排除」,层标识的机制 = `docs/core/design/DOC-SYSTEM.md` §3.1「层标识」)。
|
|
3
4
|
*
|
|
4
5
|
* 依赖面说清楚:本档**不**是零依赖叶档——谓词都来自判据单源 `../declaration.mjs`,而它的静态闭包
|
|
5
6
|
* 经 `memory/file-walk.mjs` 达 `memory/schema.mjs`(`node:sqlite`)。因此端壳里静态引本档 = 把那条链拉进静态闭包;
|
|
@@ -8,7 +9,8 @@
|
|
|
8
9
|
*
|
|
9
10
|
* 一句话:输出里**判定得出**来源档落在索引排除集(batches 段 ∥ `_archive` 前缀)的行,
|
|
10
11
|
* 行首加 `[process doc: not a design basis]`(原行整体后随);其余行一个字节不动。**不是门**——
|
|
11
|
-
*
|
|
12
|
+
* 不拦、不筛、不改命中集,只加可读信息。文档层标识(`[<层键>]`)也住这一档:两者都是“这一行来自哪份档”的
|
|
13
|
+
* 可读信息,共用同一次属辖声明查找。
|
|
12
14
|
*
|
|
13
15
|
* 两套判据、一份文案、一个谓词、一个 helper:
|
|
14
16
|
* - `grep` 面按命中行的**档**判(消费面直调 `isProcessDocPath`——grep 自己已有 `h.file`,本档不参与拼装);
|
|
@@ -18,13 +20,14 @@
|
|
|
18
20
|
* 判据单源 = `../declaration.mjs` 的 `isExcludedRelPath`(面① 前缀 ∪ 面⑥ 段序列):本档零新排除名单、
|
|
19
21
|
* 零新谓词。第三参必须传 `decl.root`——`isExcludedRelPath` 内 `resolve(base, s)` 对绝对参恒等,
|
|
20
22
|
* 再由 `relative(root, …)` 换成根相对面,面① 前缀才判得住(只被面① 命中的 `_archive` 靠这一点)。
|
|
23
|
+
* 层标识的判据单源 = `docLayerOf`(同一个属辖声明、同一次按档记忆)。
|
|
21
24
|
*
|
|
22
25
|
* 零 console 噪声:本档不调用 `console`。判据只走 `declarationForTarget` → `loadProjectDeclaration`,
|
|
23
26
|
* 后者按档缓存,只在声明档不可用 / 读不出时 warn(既有降级面,非本档新增)。
|
|
24
27
|
*/
|
|
25
28
|
import { existsSync } from "node:fs"
|
|
26
29
|
import { isAbsolute, resolve } from "node:path"
|
|
27
|
-
import { declarationForTarget, isExcludedRelPath } from "../declaration.mjs"
|
|
30
|
+
import { declarationForTarget, docLayerOf, isExcludedRelPath } from "../declaration.mjs"
|
|
28
31
|
|
|
29
32
|
/** 逐字文案(33 字符 · 全 ASCII · 方括号闭合):工具输出面全英文,同一行混中英破坏「一词一物」。 */
|
|
30
33
|
export const PROCESS_DOC_MARK = "[process doc: not a design basis]"
|
|
@@ -33,6 +36,32 @@ export const PROCESS_DOC_MARK = "[process doc: not a design basis]"
|
|
|
33
36
|
export const processDocSummary = (n) =>
|
|
34
37
|
`[process doc: ${n} of this output's lines come from process docs — not a design basis]`
|
|
35
38
|
|
|
39
|
+
/** 检索与浏览类工具的报数行(逐字文案 · 全 ASCII):`n` = 本次输出里被判为过程档的条目 / 行数。
|
|
40
|
+
* 两式共用一条规则——`included` 说清这一批是被排除还是按请求取回;`n = 0` 时调用面不加行。 */
|
|
41
|
+
export const processDocsReport = (n, included) =>
|
|
42
|
+
included
|
|
43
|
+
? `[process docs: ${n} of this output's rows come from process docs — included by request]`
|
|
44
|
+
: `[process docs: ${n} of this output's rows come from process docs — excluded by default; pass includeProcessDocs=true to include them]`
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 文档层标识(一次调用内按档记忆:`Map<absoluteFile, string>`)——工具输出面的唯一算点。
|
|
48
|
+
* 层判定单源 = `../declaration.mjs` 的 `docLayerOf`,属辖声明由 `declarationForTarget` 取(与
|
|
49
|
+
* `isProcessDocPath` 同一形,不新建机制):声明公共源里的档因此按那个仓自己的 `docRoot` 判层。
|
|
50
|
+
* @param {string} absFile 档的绝对路径
|
|
51
|
+
* @param {Map<string, string>} [cache] 记忆表(缺省自建——不传就没有跳调用的记忆)
|
|
52
|
+
* @returns {string} 层名(`docRoot` 键名逐字);出辖 ∥ 未落入声明根 ⇒ `"unlayered"`
|
|
53
|
+
*/
|
|
54
|
+
export function docLayerName(absFile, cache) {
|
|
55
|
+
const key = String(absFile ?? "")
|
|
56
|
+
if (!key) return "unlayered"
|
|
57
|
+
const memo = cache instanceof Map ? cache : new Map()
|
|
58
|
+
if (memo.has(key)) return memo.get(key)
|
|
59
|
+
const decl = declarationForTarget(key) // null = 出辖(祖先链无 manifest)
|
|
60
|
+
const layer = decl ? docLayerOf(key, decl).layer : "unlayered"
|
|
61
|
+
memo.set(key, layer)
|
|
62
|
+
return layer
|
|
63
|
+
}
|
|
64
|
+
|
|
36
65
|
/** 行首 token 的字符帽(步骤 ①):超过即成不了路径,该行跳过不解析。 */
|
|
37
66
|
const MAX_TOKEN_CHARS = 260
|
|
38
67
|
|
|
@@ -104,7 +133,7 @@ function resolveOnDisk(token, base) {
|
|
|
104
133
|
}
|
|
105
134
|
|
|
106
135
|
/**
|
|
107
|
-
*
|
|
136
|
+
* 命令面打标(`TOOLS.md` §7.1「命令输出面」六步,`bash` ∥ `execute` ∥ VSC 端 `bash` 共用):
|
|
108
137
|
* 逐行取行首 token → 真解析到盘上 → 判归属 → 命中者行首加前缀(行其余部分原样)。
|
|
109
138
|
* N > 0 ⇒ 正文之后追加一行汇总;N = 0 ⇒ **原样返回入参**(一个字节不动,无空汇总行)。
|
|
110
139
|
*
|
package/tools/repomap.mjs
CHANGED
|
@@ -8,6 +8,23 @@ import { readFile, stat } from "node:fs/promises"
|
|
|
8
8
|
import { join } from "node:path"
|
|
9
9
|
import { DESC, normalizeEOL } from "./shared.mjs" // #15 描述外置:文本单点 = tool-docs/repo_outline.md(DESC 单解析面)
|
|
10
10
|
import { INDEX_ORIGIN_ROW_WARN } from "../memory/schema.mjs" // §6.14 B4 文件数上界(WARN 值复用)
|
|
11
|
+
import { BUILD_ARTIFACT_DIRS, BUILD_ARTIFACT_DIR_PAIRS, BUILD_ARTIFACT_DIR_PREFIXES } from "../skip-dirs.mjs" // 大纲去噪族(单源 = 名单旁;机制 = `docs/core/design/MEMORY.md` §4)
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 大纲编撰面的去噪判据:行 `path`(相对 origin 根,`/` 分隔)是否命中构建产物族。
|
|
15
|
+
* 只跳过大纲的建图行——索引准入与库里那些行一处不改(删除走维护面,`ENOENT` 判死)。
|
|
16
|
+
* **前缀族只判目录段**:末段是文件名,`dist-resource-face.mjs` 一类产品代码照进大纲。
|
|
17
|
+
*/
|
|
18
|
+
function isBuildArtifactPath(rel) {
|
|
19
|
+
const segs = String(rel ?? "").split("/").filter(Boolean)
|
|
20
|
+
for (let i = 0; i < segs.length; i++) {
|
|
21
|
+
const isDirSegment = i < segs.length - 1
|
|
22
|
+
if (BUILD_ARTIFACT_DIRS.has(segs[i])) return true
|
|
23
|
+
if (isDirSegment && BUILD_ARTIFACT_DIR_PREFIXES.some((p) => segs[i].startsWith(p))) return true
|
|
24
|
+
if (i + 1 < segs.length && BUILD_ARTIFACT_DIR_PAIRS.some(([a, b]) => segs[i] === a && segs[i + 1] === b)) return true
|
|
25
|
+
}
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
/** Extract JS/TS file import paths (normalize by stripping .ts/.js/.mjs suffixes) */
|
|
13
30
|
function parseImports(lines, ext) {
|
|
@@ -129,11 +146,16 @@ async function _buildDepGraph(db, cwd, { origin = null } = {}) {
|
|
|
129
146
|
if (allFiles.length === 0) return null
|
|
130
147
|
if (allFiles.length >= limit) return { overLimit: true, fileCount: allFiles.length }
|
|
131
148
|
|
|
149
|
+
// 读取面去噪(`docs/core/design/MEMORY.md` §4「文件发现与范围」):构建产物族的行不进大纲——
|
|
150
|
+
// 目录依赖 ∥ Hub files ∥ Entry points 三段同一次干净(不含构建产物与缓存)。
|
|
151
|
+
const files = allFiles.filter((rel) => !isBuildArtifactPath(rel))
|
|
152
|
+
if (files.length === 0) return null
|
|
153
|
+
|
|
132
154
|
const deps = new Map() // path → { imports: Set, exports: Set, size: number, dir: string }
|
|
133
155
|
const importers = new Map() // importee → Set<importer>
|
|
134
156
|
|
|
135
|
-
for (let i = 0; i <
|
|
136
|
-
const rel =
|
|
157
|
+
for (let i = 0; i < files.length; i++) {
|
|
158
|
+
const rel = files[i]
|
|
137
159
|
const abs = join(cwd, ...rel.split("/"))
|
|
138
160
|
if (!existsSync(abs)) continue
|
|
139
161
|
// Large file guard: skip files over 10MB to prevent OOM
|
|
@@ -181,7 +203,7 @@ async function _buildDepGraph(db, cwd, { origin = null } = {}) {
|
|
|
181
203
|
if (i % 20 === 19) await new Promise(r => setImmediate(r))
|
|
182
204
|
}
|
|
183
205
|
|
|
184
|
-
return { deps, importers, fileCount:
|
|
206
|
+
return { deps, importers, fileCount: files.length }
|
|
185
207
|
}
|
|
186
208
|
|
|
187
209
|
/**
|
package/tools/search.mjs
CHANGED
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
// 排除名单单源(零依赖叶档 `../skip-dirs.mjs`——2026-10-27 四份名单合一):旧名 `IGNORED_DIRS`
|
|
11
11
|
// 退场,本档三处直接引 `SKIP_DIRS`(一词一物)。
|
|
12
12
|
import { SKIP_DIRS } from "../skip-dirs.mjs";
|
|
13
|
-
//
|
|
14
|
-
|
|
13
|
+
// 过程档标记 + 文档层标识(机制 = `docs/core/design/TOOLS.md` §7.1):命中行的**档**在索引排除集内 ⇒ 行首逐字前缀;
|
|
14
|
+
// 每行再带它自己的层标识。只加可读信息,不改命中集。
|
|
15
|
+
import { PROCESS_DOC_MARK, isProcessDocPath, docLayerName, processDocsReport } from "./process-doc-mark.mjs";
|
|
15
16
|
import { readFile, readdir, stat, lstat } from "node:fs/promises";
|
|
16
17
|
import { join } from "node:path";
|
|
17
18
|
|
|
@@ -20,6 +21,11 @@ function escapeRegExp(s) {
|
|
|
20
21
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
/** 四个检索与浏览工具的同一个参数:省略即排除、`true` 取回。schema 上**不写 `default` 键**——
|
|
25
|
+
* 省略即排除是规则的语义,不是代码替调用方选值(`docs/core/design/TOOL-PARAM-ZERO-DEFAULTS.md` §1)。
|
|
26
|
+
* `description` 的最短语义是 tiny 档唯一的参数面(那里看不见知识主题)。 */
|
|
27
|
+
const INCLUDE_PROCESS_DOCS_DESC = "Include process-layer docs (batch records, archived material) — omitted = excluded by default; true = include them"
|
|
28
|
+
|
|
23
29
|
// ---------------------------------------------------------------- glob
|
|
24
30
|
|
|
25
31
|
export const globTool = {
|
|
@@ -30,12 +36,14 @@ export const globTool = {
|
|
|
30
36
|
properties: {
|
|
31
37
|
pattern: { type: "string", description: "Glob pattern — supports **, *, ?, [..], {a,b} braces, and space-separated exclusion (\"**/*.js !test/**\")" },
|
|
32
38
|
path: { type: "string", description: "Directory to search in (default cwd)" },
|
|
39
|
+
includeProcessDocs: { type: "boolean", description: INCLUDE_PROCESS_DOCS_DESC },
|
|
33
40
|
},
|
|
34
41
|
required: ["pattern"],
|
|
35
42
|
},
|
|
36
43
|
readonly: true,
|
|
37
44
|
async execute(args, ctx) {
|
|
38
45
|
const base = resolveInCwd(ctx, args.path ?? ".")
|
|
46
|
+
const includeProcessDocs = args.includeProcessDocs === true
|
|
39
47
|
// TOOLS.md §6.7 调用侧拆分(评审 #5 职责分层):空格分隔 include !exclude 多模式在这里拆;
|
|
40
48
|
// globToRegex 只收单个模式(数组由 compileGlobMatchers 收)。
|
|
41
49
|
let match
|
|
@@ -47,6 +55,9 @@ export const globTool = {
|
|
|
47
55
|
return `glob error: invalid pattern "${args.pattern}": ${e.message}`
|
|
48
56
|
}
|
|
49
57
|
const results = []
|
|
58
|
+
const procCache = new Map()
|
|
59
|
+
const layerCache = new Map()
|
|
60
|
+
let excluded = 0
|
|
50
61
|
// §2.5 #65 并入(VSC「路径不存在明确报错」):目标路径缺失不再静默空清单。
|
|
51
62
|
try {
|
|
52
63
|
await stat(base)
|
|
@@ -54,13 +65,17 @@ export const globTool = {
|
|
|
54
65
|
return `glob error: path not found: ${base}`
|
|
55
66
|
}
|
|
56
67
|
for await (const relPath of walkFiles(base)) {
|
|
57
|
-
if (match(relPath))
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
if (!match(relPath)) continue
|
|
69
|
+
// 默认排除在截断之前生效:被排除的档不占 1000 条配额(否则只堆过程档的目录会把输出挤成空)。
|
|
70
|
+
if (!includeProcessDocs && isProcessDocPath(join(base, relPath), procCache)) { excluded += 1; continue }
|
|
71
|
+
results.push(relPath)
|
|
72
|
+
if (results.length >= 1000) break
|
|
61
73
|
}
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
const n = includeProcessDocs ? results.filter((p) => isProcessDocPath(join(base, p), procCache)).length : excluded
|
|
75
|
+
const body = results.length === 0
|
|
76
|
+
? "(no matches)"
|
|
77
|
+
: truncate(results.sort().map((p) => `[${docLayerName(join(base, p), layerCache)}] ${p}`).join("\n"))
|
|
78
|
+
return n > 0 ? `${body}\n${processDocsReport(n, includeProcessDocs)}` : body
|
|
64
79
|
},
|
|
65
80
|
}
|
|
66
81
|
|
|
@@ -100,6 +115,7 @@ export const grepTool = {
|
|
|
100
115
|
literal: { type: "boolean", description: "Literal string match — no regex interpretation (default false)" },
|
|
101
116
|
before: { type: "integer", description: "Lines of context to show before each match (grep -B). Default 0" },
|
|
102
117
|
after: { type: "integer", description: "Lines of context to show after each match (grep -A). Default 0" },
|
|
118
|
+
includeProcessDocs: { type: "boolean", description: INCLUDE_PROCESS_DOCS_DESC },
|
|
103
119
|
},
|
|
104
120
|
required: ["pattern"],
|
|
105
121
|
},
|
|
@@ -132,8 +148,11 @@ export const grepTool = {
|
|
|
132
148
|
const before = Math.max(0, Math.floor(args.before ?? 0))
|
|
133
149
|
const after = Math.max(0, Math.floor(args.after ?? 0))
|
|
134
150
|
const wantCtx = before > 0 || after > 0
|
|
151
|
+
const includeProcessDocs = args.includeProcessDocs === true
|
|
135
152
|
const hits = [] // { file, line(1-based), text }
|
|
136
153
|
const fileLines = new Map() // file -> string[] (cached only when context lines requested)
|
|
154
|
+
const procCache = new Map() // 档 → 是否过程档(一次调用一个记忆表)
|
|
155
|
+
let excludedRows = 0 // 被默认排除的命中行数(报数用;N = 0 不加行)
|
|
137
156
|
|
|
138
157
|
async function search(file) {
|
|
139
158
|
let content
|
|
@@ -145,13 +164,17 @@ export const grepTool = {
|
|
|
145
164
|
} catch {
|
|
146
165
|
return // Skip unreadable files; binary files will be read as UTF-8 and searched (may produce garbled matches)
|
|
147
166
|
}
|
|
167
|
+
// 默认排除在**命中处**生效:被排除的档不占 200 条配额,也不进上下文区。
|
|
168
|
+
// 首次命中时才判定(整仓 grep 不必为每个扫到的档付一次属辖声明探测)。
|
|
169
|
+
let skipProcess = null
|
|
148
170
|
const lines = content.split("\n")
|
|
149
171
|
if (wantCtx) fileLines.set(file, lines)
|
|
150
172
|
for (let i = 0; i < lines.length; i++) {
|
|
151
|
-
if (regex.test(lines[i]))
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
173
|
+
if (!regex.test(lines[i])) continue
|
|
174
|
+
if (skipProcess === null) skipProcess = !includeProcessDocs && isProcessDocPath(file, procCache)
|
|
175
|
+
if (skipProcess) { excludedRows += 1; continue }
|
|
176
|
+
hits.push({ file, line: i + 1, text: lines[i] })
|
|
177
|
+
if (hits.length >= 200) break
|
|
155
178
|
}
|
|
156
179
|
}
|
|
157
180
|
|
|
@@ -179,16 +202,22 @@ export const grepTool = {
|
|
|
179
202
|
}
|
|
180
203
|
|
|
181
204
|
await walk(base, "")
|
|
182
|
-
if (hits.length === 0) return "(no matches)"
|
|
183
205
|
|
|
184
|
-
// §
|
|
185
|
-
//
|
|
206
|
+
// §7.1:一次调用一个档记忆表;命中行与上下文行都在原有文案前镀前缀(判据是**档**不是行——
|
|
207
|
+
// 不标则同一档的上下文行读起来像普通档的内容)。层标识紧随既有过程档前缀之后:
|
|
208
|
+
// `[process doc: not a design basis] [design] path:line: text`。打标在 `truncate` 之前,不新增截断点。
|
|
186
209
|
const markCache = new Map()
|
|
210
|
+
const layerCache = new Map()
|
|
187
211
|
const mark = (f) => (isProcessDocPath(f, markCache) ? `${PROCESS_DOC_MARK} ` : "")
|
|
212
|
+
const lead = (f) => `${mark(f)}[${docLayerName(f, layerCache)}] `
|
|
213
|
+
// 报数 N = 本次输出里被判为过程档的行(排除模式 = 被排掉的行;取回模式 = 进来的行)。
|
|
214
|
+
const reported = includeProcessDocs ? hits.filter((h) => isProcessDocPath(h.file, markCache)).length : excludedRows
|
|
215
|
+
const withReport = (body) => (reported > 0 ? `${body}\n${processDocsReport(reported, includeProcessDocs)}` : body)
|
|
216
|
+
if (hits.length === 0) return withReport("(no matches)")
|
|
188
217
|
|
|
189
|
-
// No context:
|
|
218
|
+
// No context: one line per hit — layer label first, then the original path:line: content shape.
|
|
190
219
|
if (!wantCtx) {
|
|
191
|
-
return truncate(hits.map((h) => `${
|
|
220
|
+
return withReport(truncate(hits.map((h) => `${lead(h.file)}${h.file}:${h.line}: ${h.text}`).join("\n")))
|
|
192
221
|
}
|
|
193
222
|
|
|
194
223
|
// With context: matching lines use ':', context lines use '-' (like ripgrep); overlapping ranges in same file are merged and de-duplicated
|
|
@@ -206,10 +235,10 @@ export const grepTool = {
|
|
|
206
235
|
}
|
|
207
236
|
for (const l of [...lineSet].sort((a, b) => a - b)) {
|
|
208
237
|
const sep = matchedLines.has(l) ? ":" : "-"
|
|
209
|
-
out.push(`${
|
|
238
|
+
out.push(`${lead(file)}${file}${sep}${l}${sep} ${lines[l - 1]}`)
|
|
210
239
|
}
|
|
211
240
|
}
|
|
212
|
-
return truncate(out.join("\n"))
|
|
241
|
+
return withReport(truncate(out.join("\n")))
|
|
213
242
|
},
|
|
214
243
|
}
|
|
215
244
|
|
|
@@ -221,6 +250,7 @@ export const lsTool = {
|
|
|
221
250
|
properties: {
|
|
222
251
|
path: { type: "string", description: "Directory path (default cwd)" },
|
|
223
252
|
filter: { type: "string", description: "Only list entries matching this glob (e.g. '*.mjs', '*test*')" },
|
|
253
|
+
includeProcessDocs: { type: "boolean", description: INCLUDE_PROCESS_DOCS_DESC },
|
|
224
254
|
},
|
|
225
255
|
},
|
|
226
256
|
readonly: true,
|
|
@@ -234,24 +264,42 @@ export const lsTool = {
|
|
|
234
264
|
if (e.code === "ENOENT" || e.code === "ENOTDIR") throw new Error(`ls: ${args.path ?? "."} — ${e.code === "ENOTDIR" ? "not a directory" : "not found"}`, { cause: e })
|
|
235
265
|
throw e
|
|
236
266
|
}
|
|
267
|
+
// 默认排除只判**档结果**、不判目录节点(目录不是档;否则过程层目录自身从上一级列表消失)。
|
|
268
|
+
// 名额窗口 = 能渲染到的那 500 条:扫到第 500 条就停,两种模式因此在**同一批条目**上计数——
|
|
269
|
+
// 否则排除式数全目录、取回式只数前 500,报数字描述的就不是同一批条目。
|
|
270
|
+
const includeProcessDocs = args.includeProcessDocs === true
|
|
271
|
+
const procCache = new Map()
|
|
272
|
+
const layerCache = new Map()
|
|
273
|
+
let excluded = 0
|
|
274
|
+
const kept = []
|
|
275
|
+
for (const e of entries) {
|
|
276
|
+
if (filterRe && !filterRe.test(e.name)) continue
|
|
277
|
+
if (kept.length >= 500) break
|
|
278
|
+
if (!includeProcessDocs && !e.isDirectory() && isProcessDocPath(join(abs, e.name), procCache)) { excluded += 1; continue }
|
|
279
|
+
kept.push(e)
|
|
280
|
+
}
|
|
237
281
|
const rows = await Promise.all(
|
|
238
|
-
|
|
239
|
-
.filter((e) => !filterRe || filterRe.test(e.name))
|
|
240
|
-
.slice(0, 500)
|
|
241
|
-
.map(async (e) => {
|
|
282
|
+
kept.map(async (e) => {
|
|
242
283
|
const s = await stat(join(abs, e.name)).catch(() => null)
|
|
243
284
|
const isDir = e.isDirectory()
|
|
285
|
+
const proc = isDir ? false : isProcessDocPath(join(abs, e.name), procCache)
|
|
286
|
+
// 层标识跟在条目名之后——本行的字形与列宽本身是结构,行首留给 `d`/`-` 与尺寸列。
|
|
287
|
+
const label = isDir ? "" : ` [${docLayerName(join(abs, e.name), layerCache)}]`
|
|
244
288
|
return {
|
|
245
289
|
dir: isDir,
|
|
246
|
-
|
|
290
|
+
proc,
|
|
291
|
+
name: e.name + (isDir ? "/" : "") + label,
|
|
247
292
|
size: s?.size ?? 0,
|
|
248
293
|
mtime: s ? s.mtime.toISOString().slice(0, 16).replace("T", " ") : "?",
|
|
249
294
|
}
|
|
250
295
|
}),
|
|
251
296
|
)
|
|
252
297
|
rows.sort((a, b) => (a.dir === b.dir ? a.name.localeCompare(b.name) : a.dir ? -1 : 1))
|
|
253
|
-
|
|
298
|
+
// 报数 N = 本次输出里被判为过程档的条目(排除模式 = 被排掉的条目;取回模式 = 进来的条目)。
|
|
299
|
+
const reported = includeProcessDocs ? rows.filter((r) => r.proc).length : excluded
|
|
300
|
+
if (rows.length === 0) return reported > 0 ? `(no entries)\n${processDocsReport(reported, includeProcessDocs)}` : "(no entries)"
|
|
254
301
|
const out = rows.map((r) => `${r.dir ? "d" : "-"} ${r.name.padEnd(40)} ${String(r.size).padStart(10)} ${r.mtime}`)
|
|
255
|
-
|
|
302
|
+
const body = truncate(out.join("\n"))
|
|
303
|
+
return reported > 0 ? `${body}\n${processDocsReport(reported, includeProcessDocs)}` : body
|
|
256
304
|
},
|
|
257
305
|
}
|
package/tools/shared.mjs
CHANGED
|
@@ -169,9 +169,10 @@ export function findCandidates(lines, oldString, topN = 3, threshold = 0.5) {
|
|
|
169
169
|
export const FFFD_WARNING = "⚠ file contains U+FFFD (replacement char) — encoding may be corrupted; hash-based addressing may be unreliable. Consider fixing the file encoding first."
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
|
-
* 工具描述分档展开薄壳(设计 TOOLS §1 ∥ PROMPT-SYSTEM 设计档 §2 §7
|
|
173
|
-
*
|
|
174
|
-
*
|
|
172
|
+
* 工具描述分档展开薄壳(设计 TOOLS §1 ∥ PROMPT-SYSTEM 设计档 §2 §7):锚**独占一行**才算锚——完整档把那一行
|
|
173
|
+
* 换成主题正文,极简档把那一行原样留下;句子里夹着的同形文字两档都按正文原样进模型可见文本,既不展开也不删。
|
|
174
|
+
* 展开体一律交 `prompt-files.mjs` 的 `expandKnowledgeTopics`——壳只校验 mode 并选极简支,不复刻锚文法
|
|
175
|
+
* (另起一套展开器 = 整行锚定那条规则写在两处,漂一处查不出)。
|
|
175
176
|
* mode **必填、不给缺省**:缺省会让一次运行悄悄用上另一档的文本,而错处要到模型按错文本行事时才显形。
|
|
176
177
|
* 非字符串描述恒等过(无锚可展开——与下方 `applyPromptInjections` 同一判据)。
|
|
177
178
|
*/
|
package/tools/ssh.mjs
CHANGED
|
@@ -65,24 +65,24 @@ export const sshTool = {
|
|
|
65
65
|
parameters: {
|
|
66
66
|
type: "object",
|
|
67
67
|
properties: {
|
|
68
|
-
action: { type: "string", enum: SSH_ACTIONS, description: "
|
|
68
|
+
action: { type: "string", enum: SSH_ACTIONS, description: "The action to run (one per call)." },
|
|
69
69
|
host: { type: "string", description: "connect / forget: target host (IP or name)." },
|
|
70
70
|
user: { type: "string", description: "connect: login user (optional: your local ssh config decides, else the user recorded for this host locally)." },
|
|
71
71
|
port: { type: "number", description: "connect / forget: TCP port (optional, default 22)." },
|
|
72
72
|
label: { type: "string", description: "connect: short human label for this session (optional); secret_input: label for the value being sent." },
|
|
73
|
-
promptPattern: { type: "string", description: "connect: regex
|
|
73
|
+
promptPattern: { type: "string", description: "connect: regex marking the shell prompt as ready (optional; the default matches lines ending in # > $ %). Without a hit, send/read on a slow device waits out the full timeout instead of returning early." },
|
|
74
74
|
id: { type: "string", description: "send / read / secret_input / close / put / get: session id from connect (`ssh#N`)." },
|
|
75
75
|
data: { type: "string", description: "send: text to type into the session (a trailing newline is passed as-is; otherwise Enter is sent as `\\r`)." },
|
|
76
76
|
settle: { type: "boolean", description: "send: wait for the ready verdict before returning (default true); false returns right after the bytes are written." },
|
|
77
|
-
timeoutMs: { type: "number", description: "send / read: wait budget override (default 60000)
|
|
77
|
+
timeoutMs: { type: "number", description: "send / read: wait budget override (default 60000). The call returns as soon as the device waits for input (prompt, `--More--`, a y/n or password prompt); on expiry you get partial output plus a line naming what was not seen. put / get: transfer budget override (default 600000); on expiry the process tree is killed." },
|
|
78
78
|
maxChars: { type: "number", description: "read: return-window override (default 8000) — head 60% + a note + tail 40%; the omitted middle is kept in the session, so the next read collects it." },
|
|
79
79
|
identityFile: { type: "string", description: "connect: private-key path to offer (`-i`, `~` expands); remembered for this host and reused when omitted (optional)." },
|
|
80
80
|
localPath: { type: "string", description: "put / get: local file path (`~` expands; a file, never a directory)." },
|
|
81
81
|
remotePath: { type: "string", description: "put / get: path of the file on the session host (`/flash/img.bin`)." },
|
|
82
|
-
overwrite: { type: "boolean", description: "get only: replace an existing local file (default false — an existing target is refused, never overwritten silently). put follows scp's own semantics: a same-named remote file is replaced." },
|
|
82
|
+
overwrite: { type: "boolean", description: "get only: replace an existing local file (default false — an existing target is refused, never overwritten silently). `put` follows scp's own semantics: a same-named remote file is replaced." },
|
|
83
83
|
protocol: { type: "string", enum: ["scp", "sftp"], description: "put / get: `scp` = classic SCP protocol, the default and what network devices speak; `sftp` = the SFTP subsystem, for hosts that only offer that. No automatic fallback between them." },
|
|
84
84
|
// 写门接面(⑬ ④):`get` 往项目内落盘 ⇒ 与 `write` 同一道门——那一道门读的就是本参数。
|
|
85
|
-
ledger: { type: "string", description: LEDGER_PARAM_DESC + "
|
|
85
|
+
ledger: { type: "string", description: LEDGER_PARAM_DESC + "; only `get` needs one — `put` writes the remote host." },
|
|
86
86
|
},
|
|
87
87
|
required: ["action"],
|
|
88
88
|
},
|