@thincoder/core 0.10.13 → 0.11.2
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 +74 -1
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +46 -27
- package/advisor/notice.mjs +1 -1
- package/advisor/project-context.mjs +253 -14
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +57 -4
- package/agent/digest-account.mjs +73 -46
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +35 -22
- package/agent/family-tools.mjs +36 -17
- package/agent/helpers.mjs +123 -95
- package/agent/offload.mjs +84 -0
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +19 -7
- package/agent/run-stages.mjs +127 -61
- package/agent/run-start.mjs +45 -8
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +27 -22
- package/agent/spawn-child.mjs +38 -1
- package/agent/suspension.mjs +1 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +60 -6
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-face.mjs +99 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +39 -13
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +136 -31
- package/agent-tools/async-settle.mjs +2 -2
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +8 -2
- package/agent-tools/batch-closeout.mjs +444 -0
- package/agent-tools/batch-gate.mjs +152 -138
- package/agent-tools/batch-ledger-bind.mjs +392 -0
- package/agent-tools/batch-ledger-link.mjs +73 -0
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +245 -376
- package/agent-tools/batch-paths.mjs +73 -47
- package/agent-tools/batch-read.mjs +1 -1
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +154 -0
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +344 -196
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +189 -253
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +47 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +24 -24
- package/agent-tools/design-token.mjs +318 -39
- package/agent-tools/doc-check.mjs +55 -29
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +10 -9
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/manifest.mjs +34 -15
- package/agent-tools/read-history.mjs +115 -14
- package/agent-tools/review-facts.mjs +40 -15
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +19 -22
- package/agent-tools/ssh-session.mjs +120 -111
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +210 -0
- package/agent-tools/ssh-transport.mjs +183 -81
- package/agent-tools/subagent-actions-query.mjs +11 -7
- package/agent-tools/subagent-actions.mjs +1 -1
- package/agent-tools/subagent-async.mjs +11 -11
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +45 -11
- package/agent-tools/subagent-spawn.mjs +143 -104
- package/agent-tools/subagent.mjs +26 -23
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +22 -6
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-presets.mjs +5 -3
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +165 -68
- package/conventions.mjs +11 -9
- package/declaration.mjs +33 -7
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +312 -163
- package/doc-check/line-refs.mjs +38 -0
- package/doc-check/paragraph.mjs +220 -91
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +12 -6
- package/i18n.mjs +2 -2
- package/index-discover.mjs +4 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +95 -62
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +76 -244
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +70 -37
- package/ledger-executors.mjs +1 -1
- package/ledger-migrate.mjs +4 -4
- package/ledger-read.mjs +10 -8
- package/ledger-surface.mjs +1 -1
- package/ledger-tools.mjs +83 -24
- package/ledger-variant-notice.mjs +1 -1
- package/ledger-write-ops.mjs +462 -0
- package/ledger.mjs +2 -2
- package/manifest-discovery.mjs +5 -3
- package/manifest-schema.mjs +28 -2
- package/memory/memory-tool.mjs +5 -2
- package/memory/schema.mjs +6 -27
- package/package.json +3 -1
- package/path-resolve.mjs +498 -0
- package/permission.mjs +4 -0
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +14 -6
- package/prompts/advisor-design.md +66 -22
- package/prompts/advisor-round1.md +37 -3
- package/prompts/advisor-round2.md +44 -10
- package/prompts/advisor-round3.md +43 -9
- package/prompts/common.md +15 -375
- package/prompts/consult-base.md +6 -1
- package/prompts/discipline-engineering.md +251 -95
- package/prompts/discipline-normal.md +4 -250
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +29 -3
- package/prompts/persona-eng-designer.md +131 -159
- package/prompts/persona-engineering.md +202 -131
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +6 -1
- package/prompts/persona-tester.md +55 -0
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +5 -4
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +39 -12
- package/provider/rate.mjs +11 -3
- package/provider/responses.mjs +3 -1
- package/provider/sse.mjs +15 -4
- package/provider-flows.mjs +2 -2
- package/session-identity.mjs +21 -0
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +79 -19
- package/session-slot-write.mjs +37 -5
- package/session-slots.mjs +9 -14
- package/session.mjs +29 -8
- package/skip-dirs.mjs +48 -0
- package/team-ledger.mjs +17 -13
- package/text-budget.mjs +4 -0
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +244 -34
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -13
- package/tool-docs/bash.md +2 -37
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +3 -1
- package/tool-docs/browser.md +2 -47
- package/tool-docs/code_search.md +3 -1
- package/tool-docs/consult_start.md +2 -4
- package/tool-docs/consult_stop.md +2 -2
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -14
- package/tool-docs/doc_check.md +2 -72
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +3 -1
- package/tool-docs/edit.md +2 -18
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -12
- package/tool-docs/fetch.md +2 -12
- package/tool-docs/file_ops.md +2 -16
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -27
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +2 -5
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -13
- package/tool-docs/insert_after.md +2 -14
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -9
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -7
- package/tool-docs/manifest.md +2 -28
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +3 -11
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +2 -4
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -6
- package/tool-docs/read_image.md +2 -7
- package/tool-docs/recent_changes.md +3 -1
- package/tool-docs/repo_outline.md +3 -1
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +2 -5
- package/tool-docs/skill.md +3 -5
- package/tool-docs/ssh.md +2 -50
- package/tool-docs/subagent.md +2 -63
- package/tool-docs/task.md +2 -6
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +3 -13
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +3 -1
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -17
- package/tool-docs/write.md +2 -10
- package/tools/bash.mjs +12 -2
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +176 -91
- package/tools/edit-diff.mjs +129 -45
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +11 -5
- package/tools/file.mjs +32 -34
- package/tools/git.mjs +43 -2
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +4 -1
- package/tools/patch.mjs +127 -38
- package/tools/process-doc-mark.mjs +139 -0
- package/tools/search.mjs +15 -6
- package/tools/shared.mjs +31 -7
- package/tools/ssh.mjs +48 -7
- package/tools/tree.mjs +4 -1
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +79 -6
- package/traces/trace-store.mjs +4 -3
- package/window-policy.mjs +203 -0
- package/agent/light-round.mjs +0 -63
- package/agent/unbooked-pen.mjs +0 -62
- package/doc-check/anchors.mjs +0 -135
package/doc-check/paragraph.mjs
CHANGED
|
@@ -1,122 +1,251 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* doc-check/paragraph.mjs —
|
|
2
|
+
* doc-check/paragraph.mjs — 判据 ①「一段太长」+ 全仓共用的结构谓词族。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* ∥
|
|
13
|
-
*
|
|
14
|
-
*
|
|
4
|
+
* 判据句单源 = `docs/core/design/DOC-CHECK.md` §2:一段 = 相邻的非空正文行合起来的那一片文字;
|
|
5
|
+
* 标题 ∥ 表格 ∥ 列表 ∥ 引用 ∥ 围栏块 ∥ 缩进代码块各自成界(它们断开段,自己也不算进段);超过 300 字 ⇒ 报。
|
|
6
|
+
* 提示词面(`thincoder-core/prompts/`)每行自成一界——那里的换行排的是版式,不是分段。
|
|
7
|
+
* 阈值 300 是常量:判据不读项目配置,要改就改代码、走评审(§2 末行)。
|
|
8
|
+
*
|
|
9
|
+
* 结构谓词族(围栏 ∥ 标题 ∥ 列表 ∥ 引用 ∥ 表格 ∥ 码段)住本档**一处**,消费面只有两个:
|
|
10
|
+
* 本档的段判据,与 `thincoder-core/doc-graph/anchors.mjs` 的指针扫描。各写一份必然漂。
|
|
11
|
+
*
|
|
12
|
+
* **整行排除表 `structuralExclusionLines` 由两面共用**(六族:标题行 ∥ 表格块 ∥ 列表块 ∥ 引用块 ∥
|
|
13
|
+
* 围栏代码块 ∥ 缩进代码块):文档面的并段判与提示词面的逐行判读的是同一张表,
|
|
14
|
+
* 两面差别只在「谁和谁并成一段」,不在「哪些行不算正文段落」。
|
|
15
15
|
*/
|
|
16
|
-
import { readFileSync } from "node:fs"
|
|
17
16
|
|
|
18
|
-
/**
|
|
19
|
-
export const
|
|
17
|
+
/** 一段的字数上限(判据参数 · 常量):超过即命中。 */
|
|
18
|
+
export const PARAGRAPH_MAX = 300
|
|
20
19
|
|
|
21
|
-
/** 表格行谓词(markdown
|
|
20
|
+
/** 表格行谓词(markdown 表格行结构性不可折行——不计入段,且断段)。 */
|
|
22
21
|
export const isTableRow = (l) => /^\s*\|.*\|\s*$/.test(String(l))
|
|
23
22
|
|
|
24
|
-
/** 围栏标记(行首可选空白 + 三反引号 ∥ 三波浪号 ⇒
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
/** 围栏标记(行首可选空白 + 三反引号 ∥ 三波浪号 ⇒ `{ ch, len }`;非围栏行 ⇒ null)。
|
|
24
|
+
* 闭合语义带长度:同字符 ∧ 长度 ≥ 开启长度(CommonMark)——只比字符会让四反引号围栏包住的三反引号块提前闭合,
|
|
25
|
+
* 块内代码行落进正文并被并成段。 */
|
|
27
26
|
export function fenceMark(l) {
|
|
28
27
|
const m = /^\s*(`{3,}|~{3,})/.exec(String(l))
|
|
29
|
-
return m ? m[1][0] : null
|
|
28
|
+
return m ? { ch: m[1][0], len: m[1].length } : null
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
/**
|
|
33
|
-
export const
|
|
31
|
+
/** 围栏闭合谓词(单源 = 上面的长度语义)。 */
|
|
32
|
+
export const isFenceClose = (mark, fence) => mark.ch === fence.ch && mark.len >= fence.len
|
|
34
33
|
|
|
35
|
-
/** 引文块行谓词(行首可选空白 +
|
|
34
|
+
/** 引文块行谓词(行首可选空白 + `>`)——引文整块不计入段(逐字连续、不可折)。 */
|
|
36
35
|
export const isQuoteLine = (l) => /^\s*>/.test(String(l))
|
|
37
36
|
|
|
38
|
-
/** 列表项谓词(无序 `-` ∥ `*` ∥ `+` · 有序 `数字 + . ∥ ) ∥ 、`
|
|
39
|
-
export const isListItem = (l) => /^\s*(?:[-*+]|\d+[.)、])\s/.test(String(l))
|
|
37
|
+
/** 列表项谓词(无序 `-` ∥ `*` ∥ `+` · 有序 `数字 + . ∥ ) ∥ 、` · 中文标记 `·` ∥ `•`;圈号 `①`–`⑳` 另起一式)。 */
|
|
38
|
+
export const isListItem = (l) => /^\s*(?:[-*+]|\d+[.)、]|[·•])\s/.test(String(l)) || /^\s*[①-⑳]/.test(String(l))
|
|
39
|
+
|
|
40
|
+
/** 缩进代码行:四格空格或 Tab 起头;是否成块还要看前一行是否为空或也是代码。 */
|
|
41
|
+
const isIndentedCodeLine = (l) => /^(?: {4}|\t)/.test(String(l))
|
|
42
|
+
|
|
43
|
+
/** 表格单元:只把未转义且在码段外的竖线当分隔符;外侧竖线形成的空单元再剥掉。 */
|
|
44
|
+
function tableCells(l) {
|
|
45
|
+
const s = String(l).trim()
|
|
46
|
+
if (!s.includes("|")) return null
|
|
47
|
+
const cells = []
|
|
48
|
+
let start = 0
|
|
49
|
+
let codeTicks = 0
|
|
50
|
+
let i = 0
|
|
51
|
+
while (i < s.length) {
|
|
52
|
+
if (s[i] === "\\" && s[i + 1] === "|" && codeTicks === 0) { i += 2; continue }
|
|
53
|
+
if (s[i] === "`") {
|
|
54
|
+
let end = i + 1
|
|
55
|
+
while (s[end] === "`") end += 1
|
|
56
|
+
const ticks = end - i
|
|
57
|
+
if (codeTicks === 0) codeTicks = ticks
|
|
58
|
+
else if (codeTicks === ticks) codeTicks = 0
|
|
59
|
+
i = end
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
if (s[i] === "|" && codeTicks === 0) {
|
|
63
|
+
cells.push(s.slice(start, i))
|
|
64
|
+
start = i + 1
|
|
65
|
+
}
|
|
66
|
+
i += 1
|
|
67
|
+
}
|
|
68
|
+
cells.push(s.slice(start))
|
|
69
|
+
if (s.startsWith("|") && cells[0].trim() === "") cells.shift()
|
|
70
|
+
if (s.endsWith("|") && cells.at(-1).trim() === "") cells.pop()
|
|
71
|
+
return cells.map((cell) => cell.trim())
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 无首尾竖线的表头只能由下一行的分隔行确认;列数必须一致,避免把普通竖线文本误判成表。 */
|
|
75
|
+
function startsTable(lines, i) {
|
|
76
|
+
const header = tableCells(lines[i])
|
|
77
|
+
const delimiter = i + 1 < lines.length ? tableCells(lines[i + 1]) : null
|
|
78
|
+
return header !== null && delimiter !== null && header.length === delimiter.length && delimiter.every((cell) => /^:?-{3,}:?$/.test(cell))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 空行之后仍是缩进内容或下一列表项 ⇒ 这是疏松列表的内部空行,不是列表结束。 */
|
|
82
|
+
function listContinuesAfterBlank(lines, i) {
|
|
83
|
+
for (let j = i + 1; j < lines.length; j += 1) {
|
|
84
|
+
if (lines[j].trim() === "") continue
|
|
85
|
+
return isListItem(lines[j]) || /^\s{2,}\S/.test(lines[j])
|
|
86
|
+
}
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 两面共用的整行排除表(六族):标题行 ∥ 表格块 ∥ 列表块 ∥ 引用块 ∥ 围栏代码块 ∥ 缩进代码块。
|
|
91
|
+
* 文档面的并段判与提示词面的逐行判都只问它「哪些行不算正文段落」。
|
|
92
|
+
* 围栏截断表格,但缩进围栏不截断它所属的列表;列表项之后的普通行是 Markdown 的懒惰续行,
|
|
93
|
+
* 同样属于列表;表格体延续到第一个无竖线的非空行。 */
|
|
94
|
+
function structuralExclusionLines(lines) {
|
|
95
|
+
const excluded = new Array(lines.length).fill(false)
|
|
96
|
+
let fence = null
|
|
97
|
+
let inList = false
|
|
98
|
+
let inTable = false
|
|
99
|
+
let inIndentedCode = false
|
|
100
|
+
lines.forEach((l, i) => {
|
|
101
|
+
const mark = fenceMark(l)
|
|
102
|
+
if (mark !== null) {
|
|
103
|
+
const nestedInList = inList && /^\s{2,}\S/.test(l)
|
|
104
|
+
if (fence === null) fence = mark
|
|
105
|
+
else if (isFenceClose(mark, fence)) fence = null
|
|
106
|
+
if (!nestedInList) inList = false
|
|
107
|
+
inTable = false
|
|
108
|
+
inIndentedCode = false
|
|
109
|
+
excluded[i] = true
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
if (fence !== null) {
|
|
113
|
+
excluded[i] = true
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
const previous = i === 0 ? "" : lines[i - 1]
|
|
117
|
+
const codeBoundary = i === 0 || previous.trim() === "" || inIndentedCode
|
|
118
|
+
inIndentedCode = isIndentedCodeLine(l) && codeBoundary
|
|
119
|
+
if (inIndentedCode) {
|
|
120
|
+
excluded[i] = true
|
|
121
|
+
inTable = false
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
if (startsTable(lines, i)) {
|
|
125
|
+
inTable = true
|
|
126
|
+
inList = false
|
|
127
|
+
}
|
|
128
|
+
if (isTableRow(l) || (inTable && tableCells(l) !== null)) {
|
|
129
|
+
excluded[i] = true
|
|
130
|
+
inList = false
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
inTable = false
|
|
134
|
+
const heading = headingMark(l)
|
|
135
|
+
if (heading !== null) inList = false
|
|
136
|
+
else if (isListItem(l)) inList = true
|
|
137
|
+
else if (inList && l.trim() === "") inList = listContinuesAfterBlank(lines, i)
|
|
138
|
+
if (inList || heading !== null || isQuoteLine(l)) excluded[i] = true
|
|
139
|
+
})
|
|
140
|
+
return excluded
|
|
141
|
+
}
|
|
40
142
|
|
|
41
|
-
/** 提示词面谓词(`thincoder-core/prompts
|
|
42
|
-
* 模型读原始文本,一行就是一个块(FR46 同源理由)⇒ 该面逐行裸判,无结构豁免。 */
|
|
143
|
+
/** 提示词面谓词(`thincoder-core/prompts/**`):模型读原始文本,一行就是一个块 ⇒ 该面逐行判。 */
|
|
43
144
|
export const isPromptFace = (abs) => /(?:^|\/)thincoder-core\/prompts\//i.test(String(abs).replace(/\\/g, "/"))
|
|
44
145
|
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
export function
|
|
48
|
-
const
|
|
49
|
-
|
|
146
|
+
/** 码段切分(行内反引号按出现序配对):`{ start, end, text }[]`——开启反引号之后一位到闭合反引号所在位。
|
|
147
|
+
* 消费面是图侧指针扫描(它跳过命令形码段);段判据不吃它(段 = 读者所见,码段渲染后仍在段内)。 */
|
|
148
|
+
export function codeSpans(line) {
|
|
149
|
+
const l = String(line)
|
|
150
|
+
const ticks = []
|
|
151
|
+
for (let i = 0; i < l.length; i++) if (l[i] === "`") ticks.push(i)
|
|
152
|
+
const spans = []
|
|
153
|
+
for (let k = 0; k + 1 < ticks.length; k += 2) {
|
|
154
|
+
spans.push({ start: ticks[k] + 1, end: ticks[k + 1], text: l.slice(ticks[k] + 1, ticks[k + 1]) })
|
|
155
|
+
}
|
|
156
|
+
return spans
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 单个码段的可执行谓词(命令 / 搜索模式串):判域只是这一段的文本,不连同同一行的其他码段。 */
|
|
160
|
+
export function isExecutableSpan(span) {
|
|
161
|
+
const t = typeof span === "string" ? span : String(span?.text ?? "")
|
|
162
|
+
return t.includes("&&") ||
|
|
163
|
+
/\b(?:cd|node|npm|npx|grep|rg|git)\s/.test(t) ||
|
|
164
|
+
/(?:\[\^|\\\.|\(\?<|\(\?:|\{\d)/.test(t)
|
|
50
165
|
}
|
|
51
166
|
|
|
52
|
-
/**
|
|
167
|
+
/** 行内可执行坐标(任一码段满足 `isExecutableSpan`)。 */
|
|
53
168
|
export function isExecutableLine(line) {
|
|
54
|
-
|
|
55
|
-
if (/`[^`\n]*&&[^`\n]*`/.test(l)) return true // 命令链(cd … && …)
|
|
56
|
-
if (/`[^`\n]*\b(?:cd|node|npm|npx|grep|rg|git)\s[^`\n]*`/.test(l)) return true // 码段内命令词
|
|
57
|
-
if (/`[^`\n]*(?:\[\^|\\\.|\(\?<|\(\?:|\{\d)/.test(l)) return true // 码段内搜索模式串片段
|
|
58
|
-
return false
|
|
169
|
+
return codeSpans(line).some(isExecutableSpan)
|
|
59
170
|
}
|
|
60
171
|
|
|
61
|
-
/**
|
|
172
|
+
/** 行内位置是否在反引号码段内(与 `isExecutableLine` 同取一份配对规则)。 */
|
|
62
173
|
export function inCodeSpan(line, idx) {
|
|
63
|
-
return (
|
|
174
|
+
return codeSpans(line).some((s) => idx >= s.start && idx <= s.end)
|
|
64
175
|
}
|
|
65
176
|
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
export function
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (len > lineMax) hits.push({ file: f, line: i + 1, len, clazz: DOC_CLASS.line })
|
|
86
|
-
})
|
|
87
|
-
continue
|
|
177
|
+
/** 标题谓词:行首 1–6 个 `#` 后接空白 ⇒ `{ level, text }`;非标题行 ⇒ null。
|
|
178
|
+
* 不锚行尾(`$` 会让 CRLF 的标题行漏认),也不要求标题后还有正文。 */
|
|
179
|
+
export function headingMark(l) {
|
|
180
|
+
const s = String(l)
|
|
181
|
+
const m = /^(#{1,6})\s+/.exec(s)
|
|
182
|
+
return m ? { level: m[1].length, text: s.slice(m[0].length) } : null
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 围栏块**之外**的行(`{ no, text }`,`no` = 1-based 行号):判据 ② ∥ ③ 的扫描面。
|
|
186
|
+
* 围栏里是逐字证据与举例,不是指路——判它只会让每一份「改前 / 改后」对照块都来一条假命中。 */
|
|
187
|
+
export function bodyLines(text) {
|
|
188
|
+
const out = []
|
|
189
|
+
let fence = null
|
|
190
|
+
String(text ?? "").split("\n").forEach((l, i) => {
|
|
191
|
+
const mark = fenceMark(l)
|
|
192
|
+
if (mark !== null) {
|
|
193
|
+
if (fence === null) fence = mark
|
|
194
|
+
else if (isFenceClose(mark, fence)) fence = null
|
|
195
|
+
return
|
|
88
196
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
197
|
+
if (fence === null) out.push({ no: i + 1, text: l })
|
|
198
|
+
})
|
|
199
|
+
return out
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 判据 ①:一段超过 `PARAGRAPH_MAX` 字 ⇒ 一条命中 `{ line, len }`(`line` = 段首行,1-based)。
|
|
204
|
+
*
|
|
205
|
+
* **区间归属就落在这里,因为「一段跨哪几行」只有本函数知道**:命中只带段首行与字数,跨行从命中里读不出来
|
|
206
|
+
* (判据句单源 = `docs/core/design/DOC-CHECK.md` §6「区间只在段这一级扩」)。
|
|
207
|
+
* @param {string} text 档全文(调用方读好的,本档不读盘)
|
|
208
|
+
* @param {{promptFace?:boolean, region?:{rows:number[],gaps:number[]}|null}} o
|
|
209
|
+
* `promptFace` = 该档在提示词面 ⇒ 逐行判(每行自成一段);
|
|
210
|
+
* `region` = 本批变更区(`null` = 判整份):段内含变更行 ⇒ 整段量;整段无变更行 ⇒ 不判。
|
|
211
|
+
* 纯删的零宽区间(`gaps`)落在缝上 ⇒ 取**缝上现占位的那一段**——缝前那一行属于它,或缝后那一行是它的首行。
|
|
212
|
+
* @returns {{line:number, len:number}[]}
|
|
213
|
+
*/
|
|
214
|
+
export function paragraphHits(text, { promptFace = false, region = null } = {}) {
|
|
215
|
+
const src = String(text ?? "")
|
|
216
|
+
const lines = src.split("\n")
|
|
217
|
+
const excluded = structuralExclusionLines(lines)
|
|
218
|
+
// 段的归属:变更行在段内,或纯删的缝贴在段首之前 ∥ 落在段内;**缝落在档头(`g = 0`)则取第一段**。
|
|
219
|
+
// 第一段只有把段收齐之后才指得出来,所以本函数先收段、再按 `i` 判第一段。
|
|
220
|
+
const owned = (s, e, i) => {
|
|
221
|
+
if (region === null || region === undefined) return true
|
|
222
|
+
for (const r of region.rows ?? []) if (r >= s && r <= e) return true
|
|
223
|
+
for (const g of region.gaps ?? []) {
|
|
224
|
+
if (g === 0) return i === 0
|
|
225
|
+
if (g >= s - 1 && g <= e) return true
|
|
96
226
|
}
|
|
227
|
+
return false
|
|
228
|
+
}
|
|
229
|
+
if (promptFace) {
|
|
230
|
+
const spans = []
|
|
97
231
|
lines.forEach((l, i) => {
|
|
98
|
-
|
|
99
|
-
if (mark !== null) {
|
|
100
|
-
if (fence === null) fence = mark
|
|
101
|
-
else if (mark === fence) fence = null
|
|
102
|
-
flush()
|
|
103
|
-
return // 围栏标记行自身断段
|
|
104
|
-
}
|
|
105
|
-
if (fence !== null) { flush(); return } // 块内整行断段(未闭合 ⇒ 至档尾免)
|
|
106
|
-
const hm = /^(#{1,6})\s+(.*)$/.exec(l)
|
|
107
|
-
if (hm) {
|
|
108
|
-
while (stack.length && stack[stack.length - 1].level >= hm[1].length) stack.pop()
|
|
109
|
-
const self = isZoneHead(hm[2].trim(), zones)
|
|
110
|
-
stack.push({ level: hm[1].length, exempt: self || (stack[stack.length - 1]?.exempt ?? false) })
|
|
111
|
-
flush()
|
|
112
|
-
return // 标题断段
|
|
113
|
-
}
|
|
114
|
-
const inZone = stack[stack.length - 1]?.exempt === true
|
|
115
|
-
if (inZone || l.trim() === "" || isTableRow(l) || isListItem(l) || isQuoteLine(l)) { flush(); return }
|
|
116
|
-
if (para === null) para = { start: i + 1, len: 0 }
|
|
117
|
-
para.len += [...l].length
|
|
232
|
+
if (!excluded[i]) spans.push({ line: i + 1, end: i + 1, len: [...l].length })
|
|
118
233
|
})
|
|
119
|
-
|
|
234
|
+
return spans.filter((s, i) => s.len > PARAGRAPH_MAX && owned(s.line, s.end, i)).map(({ line, len }) => ({ line, len }))
|
|
235
|
+
}
|
|
236
|
+
const spans = []
|
|
237
|
+
let cur = null
|
|
238
|
+
const flush = () => {
|
|
239
|
+
if (cur !== null) spans.push(cur)
|
|
240
|
+
cur = null
|
|
120
241
|
}
|
|
121
|
-
|
|
242
|
+
lines.forEach((l, i) => {
|
|
243
|
+
// 排除行与空行都断段:围栏 ∥ 标题 ∥ 引用 ∥ 表格 ∥ 列表 ∥ 缩进代码六族的判据全在排除表里,这里不再自持一套。
|
|
244
|
+
if (excluded[i] || l.trim() === "") { flush(); return }
|
|
245
|
+
if (cur === null) cur = { line: i + 1, end: i + 1, len: 0 }
|
|
246
|
+
cur.end = i + 1
|
|
247
|
+
cur.len += [...l].length
|
|
248
|
+
})
|
|
249
|
+
flush()
|
|
250
|
+
return spans.filter((s, i) => s.len > PARAGRAPH_MAX && owned(s.line, s.end, i)).map(({ line, len }) => ({ line, len }))
|
|
122
251
|
}
|