@thincoder/core 0.11.5 → 0.12.1
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 +27 -0
- package/abort-provenance.mjs +23 -0
- package/advisor/citations.mjs +5 -1
- package/advisor/compaction.mjs +13 -10
- package/advisor/history.mjs +6 -1
- package/advisor/loop.mjs +35 -10
- package/advisor/messages.mjs +31 -43
- package/advisor/project-context.mjs +49 -45
- package/advisor/run.mjs +82 -26
- package/advisor.mjs +40 -11
- package/agent/assemble.mjs +5 -5
- package/agent/chat-call.mjs +21 -1
- package/agent/completion.mjs +1 -20
- package/agent/dispatch-gates.mjs +8 -3
- package/agent/dispatch-run.mjs +131 -20
- package/agent/dispatch.mjs +23 -22
- package/agent/family-tools.mjs +4 -7
- package/agent/goal-judge.mjs +99 -0
- package/agent/goal-state.mjs +96 -0
- package/agent/helpers.mjs +13 -4
- package/agent/offload.mjs +1 -1
- package/agent/planning-graph-guardrail.mjs +224 -0
- package/agent/planning-prompt.mjs +179 -0
- package/agent/planning-step.mjs +460 -173
- package/agent/post-turn.mjs +23 -33
- package/agent/record-results.mjs +8 -5
- package/agent/run-stages.mjs +18 -38
- package/agent/run-start.mjs +26 -19
- package/agent/setup-reminders.mjs +16 -14
- package/agent/setup.mjs +3 -2
- package/agent/spawn-child.mjs +17 -4
- package/agent/suspension.mjs +42 -21
- package/agent/task-lifecycle.mjs +165 -52
- package/agent/timers.mjs +9 -1
- package/agent/turn-loop.mjs +160 -69
- package/agent/turn-projection.mjs +26 -15
- package/agent/turn-task-state.mjs +4 -4
- package/agent/write-gate-ledger.mjs +1 -1
- package/agent/write-gate.mjs +14 -11
- package/agent-tools/advisor-async.mjs +2 -0
- package/agent-tools/advisor-launch.mjs +27 -13
- package/agent-tools/advisor-settle.mjs +19 -18
- package/agent-tools/advisor.mjs +90 -13
- package/agent-tools/bash-async.mjs +3 -3
- package/agent-tools/batch-ledger-bind.mjs +8 -5
- package/agent-tools/batch-read.mjs +42 -0
- package/agent-tools/batch-record-write.mjs +20 -12
- package/agent-tools/batch-segment-vocab.mjs +6 -4
- package/agent-tools/batch-skeleton.mjs +43 -12
- package/agent-tools/consult.mjs +5 -1
- package/agent-tools/context.mjs +5 -4
- package/agent-tools/design-slots.mjs +7 -4
- package/agent-tools/design-token.mjs +3 -2
- package/agent-tools/doc-graph.mjs +257 -95
- package/agent-tools/escalate-async.mjs +4 -1
- package/agent-tools/goal.mjs +28 -95
- package/agent-tools/plan.mjs +1 -1
- package/agent-tools/review-facts.mjs +56 -7
- package/agent-tools/settings.mjs +35 -1
- package/agent-tools/ssh-transport.mjs +23 -22
- package/agent-tools/step.mjs +24 -4
- package/agent-tools/subagent-actions.mjs +6 -2
- package/agent-tools/subagent-async.mjs +4 -2
- package/agent-tools/subagent.mjs +1 -1
- package/agent-tools/task.mjs +73 -65
- package/agent-tools.mjs +3 -3
- package/agent.mjs +12 -3
- package/auto-think.mjs +16 -3
- package/browser/actions.mjs +5 -1
- package/browser/cdp.mjs +1 -1
- package/browser/pool.mjs +110 -17
- package/compaction-work-state.mjs +103 -13
- package/compress-form.mjs +29 -3
- package/config-defaults.mjs +27 -3
- package/config-io.mjs +3 -14
- package/config-normalize.mjs +24 -4
- package/config-presets.mjs +40 -26
- package/config-warn.mjs +30 -0
- package/config.mjs +139 -63
- package/context-degrade.mjs +4 -4
- package/context-push.mjs +20 -9
- package/context.mjs +65 -20
- package/doc-graph/anchors.mjs +39 -40
- package/doc-graph/clusters.mjs +49 -0
- package/doc-graph/code-parsers.mjs +494 -0
- package/doc-graph/context-pack.mjs +392 -0
- package/doc-graph/dir-signals.mjs +228 -0
- package/doc-graph/edges.mjs +231 -0
- package/doc-graph/format.mjs +70 -0
- package/doc-graph/gc-cmd.mjs +104 -0
- package/doc-graph/gc.mjs +112 -0
- package/doc-graph/glob-work-graph.mjs +307 -0
- package/doc-graph/golden-set.mjs +131 -0
- package/doc-graph/ls-work-graph.mjs +534 -0
- package/doc-graph/outline.mjs +377 -0
- package/doc-graph/output-annotations.mjs +85 -0
- package/doc-graph/process-docs.mjs +68 -0
- package/doc-graph/read-work-graph.mjs +91 -0
- package/doc-graph/rebuild-cmd.mjs +75 -0
- package/doc-graph/resolvers.mjs +322 -0
- package/doc-graph/roots.mjs +86 -0
- package/doc-graph/schema.mjs +110 -0
- package/doc-graph/search-augment.mjs +418 -0
- package/doc-graph/store.mjs +231 -0
- package/doc-graph/target-resolve.mjs +352 -0
- package/doc-graph/walk.mjs +87 -0
- package/doc-graph.mjs +583 -707
- package/explore-distill.mjs +52 -17
- package/generate-title.mjs +7 -4
- package/ledger-close.mjs +6 -6
- package/ledger-cmd.mjs +3 -3
- package/ledger-consistency.mjs +8 -6
- package/ledger-db.mjs +45 -10
- package/ledger-migrate.mjs +25 -10
- package/ledger-read.mjs +1 -1
- package/ledger-write-ops.mjs +6 -6
- package/ledger.mjs +2 -2
- package/model-context.mjs +54 -18
- package/model-specs.mjs +86 -67
- package/package.json +1 -1
- package/prompt-overlays.mjs +3 -3
- package/prompts/advisor-round1.md +6 -5
- package/prompts/common.md +16 -6
- package/prompts/consult-base.md +2 -1
- package/prompts/discipline-engineering.md +1 -1
- package/prompts/discipline-normal.md +12 -8
- package/prompts/knowledge/doc-lookup.md +2 -2
- package/prompts/knowledge/normal-batch-discipline.md +2 -2
- package/prompts/knowledge/normal-delivery-collaboration.md +3 -3
- package/prompts/knowledge/tool-advisor.md +2 -2
- package/prompts/knowledge/tool-apply-patch.md +1 -1
- package/prompts/knowledge/tool-bash.md +2 -2
- package/prompts/knowledge/tool-batch.md +4 -4
- package/prompts/knowledge/tool-glob.md +9 -2
- package/prompts/knowledge/tool-goal.md +9 -6
- package/prompts/knowledge/tool-grep.md +7 -2
- package/prompts/knowledge/tool-ls.md +11 -5
- package/prompts/knowledge/tool-lsp.md +1 -1
- package/prompts/knowledge/tool-operations.md +3 -2
- package/prompts/knowledge/tool-plan.md +1 -1
- package/prompts/knowledge/tool-read.md +7 -6
- package/prompts/knowledge/tool-repo-graph-read.md +12 -0
- package/prompts/knowledge/tool-repo-graph.md +12 -0
- package/prompts/knowledge/tool-step.md +1 -1
- package/prompts/knowledge/tool-subagent.md +2 -2
- package/prompts/knowledge/tool-task.md +10 -9
- package/prompts/knowledge/tool-tree.md +7 -1
- package/prompts/persona-eng-coder.md +1 -1
- package/prompts/persona-eng-designer.md +1 -1
- package/prompts/persona-engineering.md +2 -1
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-normal.md +7 -6
- package/prompts/persona-plan.md +2 -2
- package/prompts/planning-next-moves.md +7 -8
- package/provider/anthropic.mjs +53 -51
- package/provider/core.mjs +85 -34
- package/provider/errors.mjs +33 -10
- package/provider/google.mjs +244 -37
- package/provider/list-models.mjs +28 -14
- package/provider/responses-request.mjs +15 -9
- package/provider/responses.mjs +10 -8
- package/provider/sse.mjs +3 -6
- package/proxy-transport.mjs +228 -119
- package/rules-file.mjs +79 -0
- package/rules.mjs +13 -51
- package/session-lifecycle.mjs +32 -20
- package/team-ledger.mjs +7 -7
- package/think-off.mjs +37 -18
- package/token-window.mjs +48 -31
- package/tool-args.mjs +8 -8
- package/tool-docs/bash.md +1 -1
- package/tool-docs/glob.md +3 -1
- package/tool-docs/goal.md +2 -2
- package/tool-docs/grep.md +3 -1
- package/tool-docs/ls.md +7 -1
- package/tool-docs/read.md +1 -1
- package/tool-docs/repo_graph-read.md +3 -0
- package/tool-docs/repo_graph.md +3 -0
- package/tool-docs/tree.md +1 -1
- package/tools/bash.mjs +53 -8
- package/tools/browser.mjs +4 -4
- package/tools/file.mjs +34 -7
- package/tools/glob-dialect.mjs +57 -7
- package/tools/index.mjs +3 -7
- package/tools/patch.mjs +8 -7
- package/tools/process-doc-mark.mjs +13 -0
- package/tools/search.mjs +152 -37
- package/tools/shared.mjs +6 -0
- package/tools/tree.mjs +211 -8
- package/window-policy.mjs +205 -126
- package/prompts/knowledge/tool-doc-graph-read.md +0 -20
- package/prompts/knowledge/tool-doc-graph.md +0 -49
- package/prompts/knowledge/tool-peek.md +0 -10
- package/prompts/knowledge/tool-repo-outline.md +0 -4
- package/tool-docs/doc_graph-read.md +0 -3
- package/tool-docs/doc_graph.md +0 -3
- package/tool-docs/peek.md +0 -3
- package/tool-docs/repo_outline.md +0 -3
- package/tools/peek.mjs +0 -447
package/tools/bash.mjs
CHANGED
|
@@ -44,6 +44,36 @@ function posixSyntaxHint(command, shellName) {
|
|
|
44
44
|
return "[hint: POSIX-only construct(s) detected — " + hits.join(", ") + ". Current shell is " + shellName + "; these will NOT work. Use && / NUL / %VAR%, or use the execute tool (node) for complex logic]"
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
const CODE_FILE_EXT_RE = /\.(?:mjs|cjs|js|jsx|ts|tsx|py|rs|go|java|kt|cs|c|h|cc|cpp|hpp|md|json|ya?ml|toml|css|scss|html|vue|svelte|sh|ps1)(?:['"\s:;),]|$)/i
|
|
48
|
+
const SHELL_FILE_SLICE_RE = /(?:^|[;&|\n(]\s*)(?:cat|head|tail|sed\s+-n|nl|type|Get-Content|gc|Select-String|sls)\b/i
|
|
49
|
+
const SHELL_FILE_FIND_RE = /(?:^|[;&|\n(]\s*)(?:Get-ChildItem|gci|ls|dir)\b/i
|
|
50
|
+
const REPO_DIR_OR_FILTER_RE = /(?:-Filter\b|-Include\b|\b(?:src|docs|packages|lib|test|locales|renderer|webview|thincoder-[a-z]+)\b|\*\.[a-z0-9]+)/i
|
|
51
|
+
const FIND_EXCLUDED_TARGET_RE = /\b(?:node_modules|\.thincoder|\.git|traces|logs|tmp|temp)\b/i
|
|
52
|
+
const NODE_READ_CODE_RE = /\bnode\b[^;\n]*(?:-e|--eval)\b[\s\S]*?\b(?:readFileSync|readFile|readdirSync)\b/
|
|
53
|
+
const PY_READ_CODE_RE = /\bpython3?\b[^;\n]*-c\b[\s\S]*?\bopen\s*\([\s\S]*?\.read/i
|
|
54
|
+
const WRITE_GUARD_RE = /\b(?:writeFileSync|writeFile|appendFileSync|rmSync|unlinkSync)\b/
|
|
55
|
+
|
|
56
|
+
/** 判定 bash 命令是否在用 shell / node 读取、搜索或枚举仓内源码与文档(替代 `read`/`grep`/`glob`/`repo_graph`)。 */
|
|
57
|
+
export function isBashCodeFragmentCommand(command) {
|
|
58
|
+
if (typeof command !== "string" || !command.trim()) return false
|
|
59
|
+
if (WRITE_GUARD_RE.test(command)) return false
|
|
60
|
+
if (NODE_READ_CODE_RE.test(command)) return true
|
|
61
|
+
if (PY_READ_CODE_RE.test(command) && !/['"][wa]\+?['"]/.test(command)) return true
|
|
62
|
+
const isBuildOrTest = /\b(?:git|npm|pnpm|node\s+--test)\b/i.test(command)
|
|
63
|
+
if (!isBuildOrTest && SHELL_FILE_SLICE_RE.test(command) && CODE_FILE_EXT_RE.test(command)) {
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
if (!isBuildOrTest && SHELL_FILE_FIND_RE.test(command) && REPO_DIR_OR_FILTER_RE.test(command) && !FIND_EXCLUDED_TARGET_RE.test(command)) {
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function codeReadViaBashHint(command) {
|
|
73
|
+
if (!isBashCodeFragmentCommand(command)) return ""
|
|
74
|
+
return "[hint: avoid reading/slicing source code fragments via bash (or searching/listing repo files with shell/PowerShell) — use `read` (full file), `grep` (supports `paths` array & `limit`), `glob`/`ls`, or `repo_graph(action=\"context\"|\"overview\")` instead.]"
|
|
75
|
+
}
|
|
76
|
+
|
|
47
77
|
|
|
48
78
|
// ====================================================================
|
|
49
79
|
// bash — command execution with safety gates
|
|
@@ -114,15 +144,26 @@ async function gitGuardSnapshot(command, cwd) {
|
|
|
114
144
|
*
|
|
115
145
|
* Returns a promise that resolves to the formatted output string (stdout + stderr + status + truncation note).
|
|
116
146
|
*/
|
|
147
|
+
/**
|
|
148
|
+
* Windows UTF-8 命令行包装单源(同步 `bash.mjs` 与后台 `bash-async.mjs` 共用):
|
|
149
|
+
* - `cmd` 族:前缀 `chcp 65001 >nul &&` 切 UTF-8 代码页;
|
|
150
|
+
* - `powershell` 族(Windows PowerShell 5.1 / pwsh):前缀设置无 BOM UTF-8 控制台与管道编码,
|
|
151
|
+
* 防止原生命令输出经 PowerShell 管道(如 `2>&1 | Select-Object`)时被 OEM 代码页(GBK/936)二次转码为乱码;
|
|
152
|
+
* - POSIX / 非 win32 / 未知执行器:原样返回。
|
|
153
|
+
*/
|
|
154
|
+
export function wrapShellCommandForUtf8(command, shell = null, platform = process.platform) {
|
|
155
|
+
if (platform !== "win32") return command
|
|
156
|
+
const { kind } = resolveShellIdentity(shell)
|
|
157
|
+
if (kind === "cmd") return `chcp 65001 >nul && ${command}`
|
|
158
|
+
if (kind === "powershell") {
|
|
159
|
+
return `[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.UTF8Encoding]::new($false); ${command}`
|
|
160
|
+
}
|
|
161
|
+
return command
|
|
162
|
+
}
|
|
163
|
+
|
|
117
164
|
function runBash(command, cwd, { timeout, signal, onOutput, shell }) {
|
|
118
165
|
return new Promise((resolve) => {
|
|
119
|
-
|
|
120
|
-
// is an independent cmd, so chcp has no side effects on other shells) — otherwise
|
|
121
|
-
// cmd emits GBK bytes that the UTF-8 decoder turns into mojibake, and the model
|
|
122
|
-
// fights encoding errors instead of the actual command (reported UX on win11).
|
|
123
|
-
const effectiveCommand = process.platform === "win32" && !shell
|
|
124
|
-
? `chcp 65001 >nul && ${command}`
|
|
125
|
-
: command
|
|
166
|
+
const effectiveCommand = wrapShellCommandForUtf8(command, shell)
|
|
126
167
|
// args MUST be an explicit [] — the two-arg spawn(cmd, options) form is
|
|
127
168
|
// DEP0190-deprecated (Node 24): the options object would be misread as args.
|
|
128
169
|
const child = spawn(effectiveCommand, [], {
|
|
@@ -268,7 +309,11 @@ export const bashTool = {
|
|
|
268
309
|
const guard = await gitGuardSnapshot(args.command, ctx.cwd)
|
|
269
310
|
// hint 身份门:只有 cmd 执行器产出 POSIX-only 提示(PS/POSIX 下该提示误导——态 4)。
|
|
270
311
|
const identity = resolveShellIdentity(ctx.agent?.config?.shell ?? null)
|
|
271
|
-
const
|
|
312
|
+
const hints = [
|
|
313
|
+
identity.kind === "cmd" ? posixSyntaxHint(args.command, identity.name) : "",
|
|
314
|
+
args.async === true ? "" : codeReadViaBashHint(args.command),
|
|
315
|
+
].filter(Boolean)
|
|
316
|
+
const hint = hints.join("\n")
|
|
272
317
|
if (args.async === true) {
|
|
273
318
|
// depth 第二道(schema 主门 = agent/helpers.mjs excludeSubagentTools 删参——异步面只到
|
|
274
319
|
// 子代理实装亦拒:留一条显式文案,不静默转同步)。
|
package/tools/browser.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* tools/browser.mjs — 浏览器工具面:schema ∥ 参数校验 ∥ `isReadonlyAction` ∥ 回执/错误形(§2.1/§2.2/§3.1)。
|
|
3
3
|
*
|
|
4
|
-
* 设计权威 = `docs/core/design/BROWSER-TOOL.md
|
|
4
|
+
* 设计权威 = `docs/core/design/BROWSER-TOOL.md`(工具级 `description` 母版由 `thincoder-core/tool-docs/browser.md` 提供)。
|
|
5
5
|
* 分类钩子(KD-2 ∥ KD-11 ∥ N-BT7):过门 = `click` ∥ `evaluate` + `press` ∥ `mouse` ∥ `drag` ∥ `touch` 点按 ∥
|
|
6
6
|
* `clipboard` 全量;免审 = `navigate` ∥ `type` ∥ `snapshot` ∥ `screenshot` ∥ `wait` ∥ `close` +
|
|
7
7
|
* `hover` ∥ `wheel` ∥ `insert` ∥ `touch` 手势(swipe / pinch)+ `cookies` ∥ `storage` 六形
|
|
@@ -30,15 +30,15 @@ const GATED_ACTIONS = new Set(["click", "evaluate", "press", "mouse", "drag", "c
|
|
|
30
30
|
const nonEmpty = (v) => typeof v === "string" && v !== ""
|
|
31
31
|
const coord = (v) => v !== undefined && v !== null && String(v) !== "" && Number.isFinite(Number(v))
|
|
32
32
|
const hasTarget = (args) => nonEmpty(args.ref) || (coord(args.x) && coord(args.y))
|
|
33
|
-
/** 互斥面(§2.2
|
|
33
|
+
/** 互斥面(§2.2「参数校验」· 互斥项冲突 ⇒ `Error`):落点 ref 与 x,y 同时给 —— 不静默取一。 */
|
|
34
34
|
const targetConflict = (args) => nonEmpty(args.ref) && coord(args.x) && coord(args.y)
|
|
35
35
|
|
|
36
|
-
/** 目标形检(`from` / `to`——§2.2
|
|
36
|
+
/** 目标形检(`from` / `to`——§2.2 的 from/to 形句)。 */
|
|
37
37
|
function specError(action, param, value) {
|
|
38
38
|
return parseTargetSpec(value) ? null : `Error: ${action} ${param} must be an element ref (e<N>) or "x,y"`
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/** 参数校验(缺必填 / 互斥项冲突 ⇒ `Error: …`——不执行,§2.2
|
|
41
|
+
/** 参数校验(缺必填 / 互斥项冲突 ⇒ `Error: …`——不执行,§2.2;扩展动作校验句逐字同 §2.2)。 */
|
|
42
42
|
export function validateArgs(args) {
|
|
43
43
|
const action = args?.action
|
|
44
44
|
if (!BROWSER_ACTIONS.includes(action)) {
|
package/tools/file.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import { writeThroughPath, clearDirty, clearLastWrite, lineAnchorVerdict, lineAn
|
|
|
22
22
|
import { specForModel } from "../config.mjs";
|
|
23
23
|
// 层标识(机制 = `docs/core/design/DOC-SYSTEM.md` §3.1「层标识」):`read` 的输出就是一份档,
|
|
24
24
|
// 所以它带层标识;它**不**参与默认排除(点名读是显式请求——`docs/core/design/TOOLS.md` §7.1)。
|
|
25
|
-
import { docLayerName } from "./process-doc-mark.mjs";
|
|
25
|
+
import { docLayerName, layerLabel } from "./process-doc-mark.mjs";
|
|
26
26
|
import { createHash } from "node:crypto";
|
|
27
27
|
import { mkdir, readFile, stat } from "node:fs/promises";
|
|
28
28
|
import { join, relative, dirname } from "node:path";
|
|
@@ -66,6 +66,24 @@ export async function appendWriteContext(abs, writeLine, baseResult) {
|
|
|
66
66
|
return `${baseResult}\ncontext (L${start}-L${end}):\n${ctxLines.join("\n")}`
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* `read` 的图谱头取数(需求 F8 / 验收 11,设计 §4.1「read 的图谱头」)。
|
|
71
|
+
*
|
|
72
|
+
* 动态 `import`:`doc-graph/read-work-graph.mjs` 会拉进图谱面(含它自己的 `node:sqlite` 取数链),静态引它
|
|
73
|
+
* 等于把库面拖进端壳静态闭包 —— 与 `tools/search.mjs` 对 `search-augment.mjs` / `glob-work-graph.mjs` /
|
|
74
|
+
* `ls-work-graph.mjs` 同一条纪律。「没有头」的各种情形与各自的处置**只在 `doc-graph/read-work-graph.mjs`
|
|
75
|
+
* 的档头**枚举一次(含「增强模块取不到」那一支),这里不重复、也不报计数(重复必漂,本批已漂过一次)。
|
|
76
|
+
*/
|
|
77
|
+
async function readGraphHead(abs, ctx, selfFullRead) {
|
|
78
|
+
try {
|
|
79
|
+
const { buildReadGraphHead } = await import("../doc-graph/read-work-graph.mjs")
|
|
80
|
+
return await buildReadGraphHead({ abs, ctx, selfFullRead })
|
|
81
|
+
} catch {
|
|
82
|
+
// 连增强模块都取不到 —— 也是「图谱没用成」的一种,给一行可见降级,不静默(需求 F8)。
|
|
83
|
+
return "[graph] repo_graph 增强模块未加载;read 正文不受影响。\n"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
69
87
|
export const readTool = {
|
|
70
88
|
name: "read",
|
|
71
89
|
description: DESC("read"),
|
|
@@ -83,7 +101,10 @@ export const readTool = {
|
|
|
83
101
|
},
|
|
84
102
|
readonly: true,
|
|
85
103
|
async execute(args, ctx) {
|
|
86
|
-
const p = args
|
|
104
|
+
const p = args?.path ?? args?.filePath
|
|
105
|
+
if (typeof p !== "string" || !p.trim()) {
|
|
106
|
+
throw new Error("read: path is required (pass a non-empty file path string via `path`)")
|
|
107
|
+
}
|
|
87
108
|
const abs = args.allowExternal ? resolveExternal(ctx, p) : resolveInCwd(ctx, p)
|
|
88
109
|
// Large file guard: check size first, reject reading entire file if >10MB (offset/limit only affect the returned slice, not buffering)
|
|
89
110
|
const st = await stat(abs).catch(() => null)
|
|
@@ -94,8 +115,14 @@ export const readTool = {
|
|
|
94
115
|
clearLastWrite(abs) // 2026-08-31:read 同时清写入快照(新视图以 read 为准)
|
|
95
116
|
const lines = content.split("\n")
|
|
96
117
|
// 层标识单起一行:掺进正文行会破坏 `L<n>\t<正文>` 这个逐字格式。图片走 `read_image`(另一条出口),
|
|
97
|
-
// 失败走 throw
|
|
98
|
-
|
|
118
|
+
// 失败走 throw——两者都没有这一行,因为那里没有编号正文。代码档没有层可标(`layerLabel` 只认文档档),
|
|
119
|
+
// 那时整行不出,不刷一个 `[unlayered]` 充数。
|
|
120
|
+
const lab = layerLabel(abs)
|
|
121
|
+
const layerHead = lab ? `${lab}\n` : ""
|
|
122
|
+
// 图谱头(需求 F8 / 验收 11):层标识之后、正文之前的一段独立元信息,与层标识同一条规矩
|
|
123
|
+
// (元信息单起一行、绝不掺进正文行)。「没有头」的各种情形与处置见 `doc-graph/read-work-graph.mjs`
|
|
124
|
+
// 档头 —— 只在那一处枚举,这里不重复、不报计数;读档本身一律不因图谱受阻。
|
|
125
|
+
const metaHead = layerHead + (await readGraphHead(abs, ctx, args.offset === undefined && args.limit === undefined))
|
|
99
126
|
const offset = Math.max(1, args.offset ?? 1)
|
|
100
127
|
const limit = Math.min(args.limit ?? MAX_READ_LINES, MAX_READ_LINES)
|
|
101
128
|
const windowEnd = offset - 1 + limit // index just past the requested window
|
|
@@ -111,7 +138,7 @@ export const readTool = {
|
|
|
111
138
|
// 也走旧路径。与 hashes 模式照常交互(头尾行 hash 照算)。
|
|
112
139
|
if (windowEnd >= lines.length || lines.length <= MAX_READ_LINES) {
|
|
113
140
|
const suffix = windowEnd < lines.length ? `\n... (${lines.length} lines total, use offset to continue)` : ""
|
|
114
|
-
return `${
|
|
141
|
+
return `${metaHead}${truncate(render(lines.slice(offset - 1, windowEnd), offset) + suffix)}`
|
|
115
142
|
}
|
|
116
143
|
const head = render(lines.slice(offset - 1, windowEnd), offset)
|
|
117
144
|
// 尾区 = 文件末 READ_TAIL_LINES 行;尾区起点落在窗口内(重叠)→ 尾区从窗口后开始
|
|
@@ -120,8 +147,8 @@ export const readTool = {
|
|
|
120
147
|
const middle = tailStart - windowEnd
|
|
121
148
|
const tail = render(lines.slice(tailStart), tailStart + 1)
|
|
122
149
|
return middle > 0
|
|
123
|
-
? `${
|
|
124
|
-
: `${
|
|
150
|
+
? `${metaHead}${head}\n…(truncated: ${middle} lines in middle, use offset to continue)\n${tail}`
|
|
151
|
+
: `${metaHead}${head}\n${tail}`
|
|
125
152
|
},
|
|
126
153
|
}
|
|
127
154
|
|
package/tools/glob-dialect.mjs
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* importers (system.mjs / ls filter / tests) keep their import paths.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import { isAbsolute } from "node:path"
|
|
20
|
+
|
|
19
21
|
const BRACE_OPEN = "\u0003", BRACE_SEP = "\u0004", BRACE_CLOSE = "\u0005"
|
|
20
22
|
const EXT_GLOB_RE = /[@?+*!]\(/
|
|
21
23
|
|
|
@@ -54,8 +56,9 @@ function expandBraces(pattern) {
|
|
|
54
56
|
/** Convert a single glob pattern to a RegExp (anchored full match). Supports the
|
|
55
57
|
* recursive "star-star" forms, single-star, "?", "[..]" character classes and
|
|
56
58
|
* {a,b} brace expansion. Malformed braces and unsupported extglob syntax throw
|
|
57
|
-
* explicit errors (no silent mismatch).
|
|
58
|
-
|
|
59
|
+
* explicit errors (no silent mismatch). `flags` is forwarded to the RegExp
|
|
60
|
+
* ("i" = case-insensitive; default = case-sensitive). */
|
|
61
|
+
export function globToRegex(pattern, flags = "") {
|
|
59
62
|
pattern = String(pattern)
|
|
60
63
|
assertNoExtglob(pattern)
|
|
61
64
|
pattern = expandBraces(pattern)
|
|
@@ -71,7 +74,7 @@ export function globToRegex(pattern) {
|
|
|
71
74
|
.replace(new RegExp(BRACE_OPEN, "g"), "(?:")
|
|
72
75
|
.replace(new RegExp(BRACE_SEP, "g"), "|")
|
|
73
76
|
.replace(new RegExp(BRACE_CLOSE, "g"), ")")
|
|
74
|
-
return new RegExp(`^${escaped}
|
|
77
|
+
return new RegExp(`^${escaped}$`, flags)
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/** Whitespace-split a glob expression into parts WITHOUT splitting inside {a,b}
|
|
@@ -109,11 +112,53 @@ export function splitGlobPatterns(expr) {
|
|
|
109
112
|
return parts
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
/** A "bare word" is a pattern that names no glob metacharacter at all (`*`, `?`, `[`, `{`),
|
|
116
|
+
* carries no path separator and does not start with `.` (so `.gitignore` stays an exact
|
|
117
|
+
* name). Callers that opt in (`opts.bareWord`) treat it as "any path whose name
|
|
118
|
+
* contains this word" — equivalent to the recursive star form with the word between
|
|
119
|
+
* two single-stars — so `case_field_acl` finds `v2_cfg_case_field_acl_delete.sql`
|
|
120
|
+
* without the caller having to spell the wildcards. */
|
|
121
|
+
export function isBareWordPattern(part) {
|
|
122
|
+
const s = String(part)
|
|
123
|
+
if (s === "" || s.startsWith(".") || s.startsWith("!") || s.includes("/")) return false
|
|
124
|
+
return !/[*?\[{]/.test(s)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** First ABSOLUTE pattern among the whitespace-split parts (leading "!" stripped), or `null`.
|
|
128
|
+
* Glob matching runs against root-relative paths, so an absolute pattern can never match
|
|
129
|
+
* anything — every caller that scans a root must REJECT it instead of reporting a silent
|
|
130
|
+
* zero-match. Two callers share this one predicate (the `repo_graph` tool face and
|
|
131
|
+
* `doc-graph/outline.mjs`); writing it once here keeps the judgement from drifting into two
|
|
132
|
+
* copies with the same error sentence. */
|
|
133
|
+
export function firstAbsoluteGlobPattern(expr) {
|
|
134
|
+
return splitGlobPatterns(expr).map((p) => p.replace(/^!/, "")).find((p) => isAbsolute(p)) || null
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Canonical rejection for an absolute glob pattern handed to a root-scanning caller.
|
|
138
|
+
* `outline` rejects it in two places — the tool-face pre-check (so a workspace fanout
|
|
139
|
+
* reports once instead of N times) and `doc-graph/outline.mjs` (the single-repo path) —
|
|
140
|
+
* and both must say the same thing. Returns the Error rather than throwing so each caller
|
|
141
|
+
* picks its own site. */
|
|
142
|
+
export function absoluteGlobRejection(expr) {
|
|
143
|
+
return new Error(`repo_graph(outline):glob 必须是根相对模式,收到绝对模式 "${expr}";绝对定位请改用 paths`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Does this string carry glob metacharacters — i.e. is it a PATTERN rather than a literal path?
|
|
147
|
+
* `outline`'s convenience route turns a glob-shaped `query` into `effectiveGlob`, and the
|
|
148
|
+
* workspace fanout's pre-check has to ask that same question — one predicate, one home. */
|
|
149
|
+
export function looksLikeGlob(s) {
|
|
150
|
+
return /[*?{\[]/.test(String(s ?? ""))
|
|
151
|
+
}
|
|
152
|
+
|
|
112
153
|
/** Compile whitespace-split pattern parts (see splitGlobPatterns) into a matcher:
|
|
113
154
|
* non-"!" parts are includes, leading-"!" parts are excludes — a rel path matches
|
|
114
155
|
* when it matches ≥1 include (or there are no includes) and no exclude. Every
|
|
115
|
-
* part runs the full brace/error dialect through globToRegex (excludes too).
|
|
116
|
-
|
|
156
|
+
* part runs the full brace/error dialect through globToRegex (excludes too).
|
|
157
|
+
* `opts` — `{ ignoreCase }` compiles every part with the `i` flag; `{ bareWord }`
|
|
158
|
+
* rewrites metacharacter-free includes and excludes into the recursive contains-word
|
|
159
|
+
* form. Both default off, so every existing caller keeps its behavior. */
|
|
160
|
+
export function compileGlobMatchers(parts, opts = {}) {
|
|
161
|
+
const flags = opts.ignoreCase === true ? "i" : ""
|
|
117
162
|
const includes = []
|
|
118
163
|
const excludes = []
|
|
119
164
|
for (const p of parts) {
|
|
@@ -121,8 +166,13 @@ export function compileGlobMatchers(parts) {
|
|
|
121
166
|
if (part.startsWith("!")) excludes.push(part.slice(1))
|
|
122
167
|
else if (part !== "") includes.push(part)
|
|
123
168
|
}
|
|
124
|
-
const
|
|
125
|
-
const
|
|
169
|
+
const compile = (p) => globToRegex(p, flags)
|
|
170
|
+
const include = includes.map((p) =>
|
|
171
|
+
opts.bareWord === true && isBareWordPattern(p) ? compile(`**/*${p}*`) : compile(p))
|
|
172
|
+
// Excludes speak the same dialect: a bare-word exclude that stayed an exact name would never exclude
|
|
173
|
+
// anything once the include side became a substring match (`*.sql !delete` must drop `x_delete.sql`).
|
|
174
|
+
const exclude = excludes.map((p) =>
|
|
175
|
+
opts.bareWord === true && isBareWordPattern(p) ? compile(`**/*${p}*`) : compile(p))
|
|
126
176
|
const test = (relPath) =>
|
|
127
177
|
(include.length === 0 || include.some((re) => re.test(relPath))) &&
|
|
128
178
|
!exclude.some((re) => re.test(relPath))
|
package/tools/index.mjs
CHANGED
|
@@ -13,7 +13,6 @@ import { lspTool } from "./lsp.mjs";
|
|
|
13
13
|
import { executeTool } from "./execute.mjs";
|
|
14
14
|
import { fileOpsTool, processTool, getCurrentTimeTool, waitForTool } from "./ops.mjs";
|
|
15
15
|
import { treeTool } from "./tree.mjs";
|
|
16
|
-
import { peekTool } from "./peek.mjs";
|
|
17
16
|
import { browserTool } from "./browser.mjs";
|
|
18
17
|
import { sshTool } from "./ssh.mjs";
|
|
19
18
|
|
|
@@ -26,7 +25,7 @@ export const builtinTools = [
|
|
|
26
25
|
gitTool, questionTool,
|
|
27
26
|
lintTool, lspTool, executeTool,
|
|
28
27
|
fileOpsTool, processTool, getCurrentTimeTool, waitForTool,
|
|
29
|
-
treeTool,
|
|
28
|
+
treeTool,
|
|
30
29
|
browserTool,
|
|
31
30
|
sshTool,
|
|
32
31
|
];
|
|
@@ -38,7 +37,7 @@ export {
|
|
|
38
37
|
gitTool, questionTool,
|
|
39
38
|
lintTool, lspTool, executeTool,
|
|
40
39
|
fileOpsTool, processTool, getCurrentTimeTool, waitForTool,
|
|
41
|
-
treeTool,
|
|
40
|
+
treeTool,
|
|
42
41
|
browserTool,
|
|
43
42
|
sshTool,
|
|
44
43
|
};
|
|
@@ -64,7 +63,6 @@ export {
|
|
|
64
63
|
export async function assembleBuiltinTools({ memory, cwd, projectDir = null, author = "unknown", team = null, model = null } = {}) {
|
|
65
64
|
const { specForModel } = await import("../model-specs.mjs");
|
|
66
65
|
const { memoryTools, codeSearchTool, docSearchTool } = await import("../memory.mjs");
|
|
67
|
-
const { repoOutlineTool } = await import("./repomap.mjs");
|
|
68
66
|
const { settingsTool } = await import("../agent-tools/settings.mjs");
|
|
69
67
|
const { peerInstancesTool } = await import("../peer-instances.mjs");
|
|
70
68
|
// 投递面工具两件(MULTI-INSTANCE-COLLAB §5.2 / §5.8):装配点 = `peer_instances` 同点——核基集一处,
|
|
@@ -78,12 +76,10 @@ export async function assembleBuiltinTools({ memory, cwd, projectDir = null, aut
|
|
|
78
76
|
...memoryTools(memory, { cwd, projectDir, author, team }),
|
|
79
77
|
codeSearchTool(memory),
|
|
80
78
|
docSearchTool(memory),
|
|
81
|
-
// memory 缺位容错:组装期零解引用(memory?.db);缺位不抛(懒失败留执行期——与 memory ∕ code_search ∕ doc_search 同族,dispatch 收成 Error 回模型);有 memory 逐字零变
|
|
82
|
-
repoOutlineTool(memory?.db, cwd),
|
|
83
79
|
settingsTool(),
|
|
84
80
|
peerInstancesTool,
|
|
85
81
|
instanceListTool,
|
|
86
82
|
instanceSendTool,
|
|
87
|
-
//
|
|
83
|
+
// 台账与项目知识图谱工具面(`ledger` / `repo_graph`)随家族段 `agent/family-tools.mjs` 统一装配
|
|
88
84
|
];
|
|
89
85
|
}
|
package/tools/patch.mjs
CHANGED
|
@@ -98,13 +98,14 @@ function parsePatch(patch) {
|
|
|
98
98
|
i++
|
|
99
99
|
}
|
|
100
100
|
if (hunk.ops.length === 0) throw new Error(`Malformed patch: empty coordinate-less hunk "${line.trim()}"`)
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
//
|
|
105
|
-
//
|
|
101
|
+
const ctxLines = hunk.ops.filter((o) => o.type === " ")
|
|
102
|
+
const ctxCount = ctxLines.length
|
|
103
|
+
const hasNonBlankCtx = ctxLines.some((o) => o.text.trim().length > 0)
|
|
104
|
+
// §3 (APPLY-PATCH.md):无坐标 hunk 定位锚 = 空格上下文行 + - 行(连续唯一匹配才应用;applyHunks 负责唯一性校验)。
|
|
105
|
+
// 含 ≥1 个 - 行时允许 0/1 行上下文;纯 +(无 - 锚)若零上下文或仅 1 行空行则无可靠锚,解析期直接拒绝;
|
|
106
|
+
// 含 ≥1 行非空上下文行则放行至 applyHunks,仅全文件恰匹配 1 处才生效(多匹配仍明确拒绝并提示加行)。
|
|
106
107
|
const removedCount = hunk.ops.filter((o) => o.type === "-").length
|
|
107
|
-
if (
|
|
108
|
+
if (removedCount === 0 && (ctxCount === 0 || (ctxCount === 1 && !hasNonBlankCtx))) {
|
|
108
109
|
throw new Error(
|
|
109
110
|
`Coordinate-less hunk ${cur.hunks.length + 1} in ${cur.path} has ${ctxCount} context line(s) — add more context lines`,
|
|
110
111
|
)
|
|
@@ -239,7 +240,7 @@ export const applyPatchTool = {
|
|
|
239
240
|
parameters: {
|
|
240
241
|
type: "object",
|
|
241
242
|
properties: {
|
|
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
|
|
243
|
+
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 one non-blank context line (or >=2 context lines). Anchor-free pure-+ hunks with zero or single blank context are refused. 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
244
|
ledger: { type: "string", description: LEDGER_PARAM_DESC },
|
|
244
245
|
// 工作区根窄口(设计档 §2.3.1):目标取不到项目根时才被读;目标有根时以路径为准(定位参数优先)。
|
|
245
246
|
project: { type: "string", description: PROJECT_PARAM_DESC },
|
|
@@ -62,6 +62,19 @@ export function docLayerName(absFile, cache) {
|
|
|
62
62
|
return layer
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/** 层标签只给**文档档**:`docRoot` 声明的层是文档层的划分,代码档(`.mjs`/`.sql`/…)永远落不到任何声明根,
|
|
66
|
+
* 给它们标 `[unlayered]` 只是把「正常」写成「未归层」——十三字宽零信息,还会被读成「这个档有问题」。
|
|
67
|
+
* 判据只看扩展名:只有 `.md` 系才可能有层;其余一律不出标签(空串 = 这一行不加标签)。
|
|
68
|
+
* 层判定本身仍走 `docLayerName` 单源,本函数只决定「要不要标」。 */
|
|
69
|
+
const LAYERED_EXT = /\.(md|mdx|markdown)$/i
|
|
70
|
+
|
|
71
|
+
/** 档行上的层标签(含方括号);不是文档档 ⇒ `""`。调用面:`grep`/`glob`/`ls`/`tree`/`read`。 */
|
|
72
|
+
export function layerLabel(absFile, cache) {
|
|
73
|
+
const key = String(absFile ?? "")
|
|
74
|
+
if (!LAYERED_EXT.test(key)) return ""
|
|
75
|
+
return `[${docLayerName(key, cache)}]`
|
|
76
|
+
}
|
|
77
|
+
|
|
65
78
|
/** 行首 token 的字符帽(步骤 ①):超过即成不了路径,该行跳过不解析。 */
|
|
66
79
|
const MAX_TOKEN_CHARS = 260
|
|
67
80
|
|