@thincoder/core 0.11.1 → 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 +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- 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 +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- 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 +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- 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 +1 -1
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- 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 +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- 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/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- package/i18n.mjs +1 -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 +10 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -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 +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -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 +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -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 +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -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 +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -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 +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -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 +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -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 +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- 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 +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- 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 +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- 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 -10
- 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 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- 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 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +54 -9
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- 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 +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
package/doc-check/line-refs.mjs
CHANGED
|
@@ -1,112 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* doc-check/line-refs.mjs —
|
|
2
|
+
* doc-check/line-refs.mjs — 判据 ②「拿行号做锚」。
|
|
3
3
|
*
|
|
4
|
-
* 判据句单源 = `docs/core/design/DOC-
|
|
5
|
-
*
|
|
6
|
-
* (三形是**读数分类**,不是判据分级——同一命中按处计,不按形加权);
|
|
7
|
-
* · 它是**清点,不是判据**:不产 verdict、不计入 `hits`、不阻断任何写入。
|
|
8
|
-
* 调用点只在 `./index.mjs` 的 `if (gate) { return … }` 早返回之后的报面构造段——`gate` 分支够不着本档,
|
|
9
|
-
* 所以「闸看不见清单」是构造上的事实,不是「算出来但声明不参与」。
|
|
10
|
-
* · 档名豁免 = 与锚判同一谓词 `docNameExemption`(单源 = `./anchors.mjs` ∥ §3.24 条目 X)——
|
|
11
|
-
* 本档零自建名集:占位形(`x.md`)∥ 类名(`todo.md`)不算档名,也就不构成任何归属窗。
|
|
4
|
+
* 判据句单源 = `docs/core/design/DOC-CHECK.md` §1 ②:正文里出现「档名 + 冒号 + 数字」的定位写法 ⇒ 报。
|
|
5
|
+
* 为什么报:上面插一行,它以下所有引用一起漂;照它去翻,翻到的是别人的东西。
|
|
12
6
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* 两个面并列:**正文面** = 围栏块整块跳过 ∧ 可执行行跳过;**围栏内** = 不跳围栏时独有的处;**合计** = 两数之和。
|
|
16
|
-
* 为什么围栏面要留:围栏块里躺着成片的存量坐标(改前 / 改后对照块的左半),清账要看见的正是它们;
|
|
17
|
-
* 反方向也要防——围栏同时是举例的家,只报全文面会把举例混进读数,读数就没法跟下一份比。
|
|
7
|
+
* 扫描面 = 围栏块之外的行(`bodyLines`);档名形与豁免谓词取 `./doc-tokens.mjs` ∥ `./doc-names.mjs`
|
|
8
|
+
* (与判据 ③ 同一组,本档不持第二份字面)。时刻(`12:30`)不会被认成坐标——本判据要求档名紧贴在冒号前。
|
|
18
9
|
*/
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { fenceMark, isFenceClose, isExecutableLine } from "./paragraph.mjs"
|
|
10
|
+
import { EXT_PART, NAME_CH, TOKEN_LEFT_GUARD, TOKEN_RIGHT_GUARD, isDocToken } from "./doc-tokens.mjs"
|
|
11
|
+
import { docNameExemption } from "./doc-names.mjs"
|
|
12
|
+
import { bodyLines } from "./paragraph.mjs"
|
|
23
13
|
|
|
24
|
-
/** 档名
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/** 相对路径显示形(正斜杠——跨平台同形)。 */
|
|
31
|
-
const rel = (base, p) => relative(base, p).replace(/\\/g, "/")
|
|
32
|
-
|
|
33
|
-
/** 原文片段 ≤ 40 字(CJK 按字计——`[...]` 逐码点切,不按 UTF-16 单元)。 */
|
|
34
|
-
const snippet = (line) => [...line.trim()].slice(0, 40).join("")
|
|
35
|
-
|
|
36
|
-
/** 一行内的档名位置(已过豁免谓词——豁免名不算档名,也就不构成任何归属窗)。 */
|
|
37
|
-
function nameSpans(line) {
|
|
38
|
-
const out = []
|
|
39
|
-
const re = new RegExp(NAME_RE.source, "g")
|
|
40
|
-
let m
|
|
41
|
-
while ((m = re.exec(line)) !== null) {
|
|
42
|
-
if (docNameExemption(basename(m[1])) !== null) continue
|
|
43
|
-
out.push({ start: m.index, end: m.index + m[0].length })
|
|
44
|
-
}
|
|
45
|
-
return out
|
|
46
|
-
}
|
|
14
|
+
/** 档名 + `:` + 数字(`name:12` ∥ `name:12-15`):行号锚的抽取式,全仓一处。
|
|
15
|
+
* 右界同档名一族(数字之后不再接名字字符);左界同档名一族(不接名字字符 ∥ 路径分隔符)。 */
|
|
16
|
+
export const LINE_ANCHOR_RE = new RegExp(
|
|
17
|
+
`${TOKEN_LEFT_GUARD}((?:${NAME_CH}+/)*${NAME_CH}+${EXT_PART}):(\\d+)(?:-\\d+)?${TOKEN_RIGHT_GUARD}`,
|
|
18
|
+
"gu",
|
|
19
|
+
)
|
|
47
20
|
|
|
48
21
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param {
|
|
51
|
-
* @returns {{
|
|
52
|
-
* `body` = 正文面的处(围栏块外 ∧ 非可执行行);`fenced` = 围栏内独有的处;每处 = `{file, line, form, fenced, snippet}`
|
|
22
|
+
* 判据 ②:逐行找「档名 + 冒号 + 数字」。
|
|
23
|
+
* @param {string} text 档全文(调用方读好的,本档不读盘)
|
|
24
|
+
* @returns {{line:number, token:string}[]} `line` = 1-based 行号,`token` = 命中的那一处写法(`a.md:12`)
|
|
53
25
|
*/
|
|
54
|
-
export function
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const inFence = fence !== null
|
|
65
|
-
if (mark !== null) {
|
|
66
|
-
if (fence === null) fence = mark
|
|
67
|
-
else if (isFenceClose(mark, fence)) fence = null
|
|
68
|
-
prevNames = [] // 围栏标记行不承载档名(③ 因此不跨过围栏边界)
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
if (isExecutableLine(l)) { prevNames = []; return } // 可执行行整行不判(命令保字面——两面同跳)
|
|
72
|
-
const names = nameSpans(l)
|
|
73
|
-
const re = new RegExp(COORD_RE.source, "g")
|
|
74
|
-
let m
|
|
75
|
-
while ((m = re.exec(l)) !== null) {
|
|
76
|
-
const at = m.index
|
|
77
|
-
const before = names.filter((n) => n.end <= at)
|
|
78
|
-
let form
|
|
79
|
-
if (before.length && before[before.length - 1].end === at) form = "①" // 紧贴:档名与 `:` 之间零字符
|
|
80
|
-
else if (before.length) form = "②" // 承名:本行前文有档名(反引号收尾的坐标归此形)
|
|
81
|
-
else if (prevNames.length) form = "③" // 段落承名:本行无前文档名,取上一行最后一个档名
|
|
82
|
-
else continue // 无主——判据句自然排除,不列例外表
|
|
83
|
-
const hit = { file: f, line: i + 1, form, fenced: inFence, snippet: snippet(l) }
|
|
84
|
-
;(inFence ? fenced : body).push(hit)
|
|
85
|
-
}
|
|
86
|
-
prevNames = names
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
return { body, fenced, total: body.length + fenced.length }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 清单块(四件 · 定名 = §3.23「清单块的形态与位置」):**量法行**(首行:抽取式 + 扫描域)·
|
|
94
|
-
* **合计行** · **逐处行**(`源档:行` + 原文片段 ≤ 40 字,围栏内那处带 `围栏内` 标)· **空态行**(无命中时:`行号坐标 0 处`)。
|
|
95
|
-
* 块内不留空行——空行读起来像「没跑」。
|
|
96
|
-
* @param {{base:string, files?:string[], refs?:{body:Array, fenced:Array, total:number}}} o
|
|
97
|
-
* `refs` 缺省 ⇒ 本函数现采一次;调用方要给返回值时传进来,别采两遍
|
|
98
|
-
* @returns {string[]} 块内各行(按序)
|
|
99
|
-
*/
|
|
100
|
-
export function lineRefsBlock({ base, files = [], refs = collectLineRefs({ files }) }) {
|
|
101
|
-
const out = [
|
|
102
|
-
`量法(行号坐标清单):档名 = ${NAME_RE} · 坐标 = ${COORD_RE} · 扫描域 = 传入清单 ${files.length} 档(${base})`,
|
|
103
|
-
]
|
|
104
|
-
if (refs.total === 0) {
|
|
105
|
-
out.push("行号坐标 0 处")
|
|
106
|
-
return out
|
|
26
|
+
export function lineRefHits(text) {
|
|
27
|
+
const out = []
|
|
28
|
+
for (const { no, text: l } of bodyLines(text)) {
|
|
29
|
+
const re = new RegExp(LINE_ANCHOR_RE.source, "gu")
|
|
30
|
+
let m
|
|
31
|
+
while ((m = re.exec(l)) !== null) {
|
|
32
|
+
if (!isDocToken(m[1])) continue // 后缀不在档名清单内 ⇒ 不是档名(`1.5:3` 这类)
|
|
33
|
+
if (docNameExemption(m[1]) !== null) continue // 示例名 ∥ 类名不是档名,也就不构成锚
|
|
34
|
+
out.push({ line: no, token: m[0] })
|
|
35
|
+
}
|
|
107
36
|
}
|
|
108
|
-
out.push(`正文面 ${refs.body.length} 处 · 围栏内 ${refs.fenced.length} 处 · 合计 ${refs.total} 处`)
|
|
109
|
-
for (const h of refs.body) out.push(` · ${h.form} ${rel(base, h.file)}:${h.line} ${h.snippet}`)
|
|
110
|
-
for (const h of refs.fenced) out.push(` · ${h.form} ${rel(base, h.file)}:${h.line} 围栏内 ${h.snippet}`)
|
|
111
37
|
return out
|
|
112
38
|
}
|
package/doc-check/paragraph.mjs
CHANGED
|
@@ -1,135 +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
|
-
/** 围栏标记(行首可选空白 + 三反引号 ∥ 三波浪号 ⇒ `{ ch, len }`;非围栏行 ⇒ null
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* **长度带出**:闭合 = 同字符 ∧ 长度 ≥ 开启长度(CommonMark 围栏语义)——只比字符会让
|
|
28
|
-
* `` ```` `` 包 `` ``` `` 的嵌套围栏在外层开启行处提前闭合,内层代码行落入正文并被并成段。 */
|
|
23
|
+
/** 围栏标记(行首可选空白 + 三反引号 ∥ 三波浪号 ⇒ `{ ch, len }`;非围栏行 ⇒ null)。
|
|
24
|
+
* 闭合语义带长度:同字符 ∧ 长度 ≥ 开启长度(CommonMark)——只比字符会让四反引号围栏包住的三反引号块提前闭合,
|
|
25
|
+
* 块内代码行落进正文并被并成段。 */
|
|
29
26
|
export function fenceMark(l) {
|
|
30
27
|
const m = /^\s*(`{3,}|~{3,})/.exec(String(l))
|
|
31
28
|
return m ? { ch: m[1][0], len: m[1].length } : null
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
/** 围栏闭合谓词(单源 =
|
|
31
|
+
/** 围栏闭合谓词(单源 = 上面的长度语义)。 */
|
|
35
32
|
export const isFenceClose = (mark, fence) => mark.ch === fence.ch && mark.len >= fence.len
|
|
36
33
|
|
|
37
|
-
/**
|
|
38
|
-
export const isFenceLine = (l) => fenceMark(l) !== null
|
|
39
|
-
|
|
40
|
-
/** 引文块行谓词(行首可选空白 + `>`)——连续 `>` 行整块不计入段(引证须逐字连续、不可折,同表行理据)。 */
|
|
34
|
+
/** 引文块行谓词(行首可选空白 + `>`)——引文整块不计入段(逐字连续、不可折)。 */
|
|
41
35
|
export const isQuoteLine = (l) => /^\s*>/.test(String(l))
|
|
42
36
|
|
|
43
|
-
/** 列表项谓词(无序 `-` ∥ `*` ∥ `+` · 有序 `数字 + . ∥ ) ∥ 、`
|
|
44
|
-
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
|
+
}
|
|
45
142
|
|
|
46
|
-
/** 提示词面谓词(`thincoder-core/prompts
|
|
47
|
-
* 模型读原始文本,一行就是一个块(FR46 同源理由)⇒ 该面逐行裸判,无结构豁免。 */
|
|
143
|
+
/** 提示词面谓词(`thincoder-core/prompts/**`):模型读原始文本,一行就是一个块 ⇒ 该面逐行判。 */
|
|
48
144
|
export const isPromptFace = (abs) => /(?:^|\/)thincoder-core\/prompts\//i.test(String(abs).replace(/\\/g, "/"))
|
|
49
145
|
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
export function
|
|
53
|
-
const
|
|
54
|
-
|
|
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)
|
|
55
165
|
}
|
|
56
166
|
|
|
57
|
-
/**
|
|
167
|
+
/** 行内可执行坐标(任一码段满足 `isExecutableSpan`)。 */
|
|
58
168
|
export function isExecutableLine(line) {
|
|
59
|
-
|
|
60
|
-
if (/`[^`\n]*&&[^`\n]*`/.test(l)) return true // 命令链(cd … && …)
|
|
61
|
-
if (/`[^`\n]*\b(?:cd|node|npm|npx|grep|rg|git)\s[^`\n]*`/.test(l)) return true // 码段内命令词
|
|
62
|
-
if (/`[^`\n]*(?:\[\^|\\\.|\(\?<|\(\?:|\{\d)/.test(l)) return true // 码段内搜索模式串片段
|
|
63
|
-
return false
|
|
169
|
+
return codeSpans(line).some(isExecutableSpan)
|
|
64
170
|
}
|
|
65
171
|
|
|
66
|
-
/**
|
|
172
|
+
/** 行内位置是否在反引号码段内(与 `isExecutableLine` 同取一份配对规则)。 */
|
|
67
173
|
export function inCodeSpan(line, idx) {
|
|
68
|
-
return (
|
|
174
|
+
return codeSpans(line).some((s) => idx >= s.start && idx <= s.end)
|
|
69
175
|
}
|
|
70
176
|
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*
|
|
81
|
-
export function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const zones = (Array.isArray(exemptZones) ? exemptZones : []).filter((z) => typeof z === "string" && z !== "")
|
|
91
|
-
const hits = []
|
|
92
|
-
for (const f of files) {
|
|
93
|
-
let text = ""
|
|
94
|
-
try { text = readFileSync(f, "utf8") } catch { continue }
|
|
95
|
-
if (isPromptFace(f)) {
|
|
96
|
-
text.split("\n").forEach((l, i) => {
|
|
97
|
-
const len = [...l].length
|
|
98
|
-
if (len > lineMax) hits.push({ file: f, line: i + 1, len, clazz: DOC_CLASS.line })
|
|
99
|
-
})
|
|
100
|
-
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
|
|
101
196
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
109
226
|
}
|
|
227
|
+
return false
|
|
228
|
+
}
|
|
229
|
+
if (promptFace) {
|
|
230
|
+
const spans = []
|
|
110
231
|
lines.forEach((l, i) => {
|
|
111
|
-
|
|
112
|
-
if (mark !== null) {
|
|
113
|
-
if (fence === null) fence = mark
|
|
114
|
-
else if (isFenceClose(mark, fence)) fence = null
|
|
115
|
-
flush()
|
|
116
|
-
return // 围栏标记行自身断段
|
|
117
|
-
}
|
|
118
|
-
if (fence !== null) { flush(); return } // 块内整行断段(未闭合 ⇒ 至档尾免)
|
|
119
|
-
const hm = /^(#{1,6})\s+(.*)$/.exec(l)
|
|
120
|
-
if (hm) {
|
|
121
|
-
while (stack.length && stack[stack.length - 1].level >= hm[1].length) stack.pop()
|
|
122
|
-
const self = isZoneHead(hm[2].trim(), zones)
|
|
123
|
-
stack.push({ level: hm[1].length, exempt: self || (stack[stack.length - 1]?.exempt ?? false) })
|
|
124
|
-
flush()
|
|
125
|
-
return // 标题断段
|
|
126
|
-
}
|
|
127
|
-
const inZone = stack[stack.length - 1]?.exempt === true
|
|
128
|
-
if (inZone || l.trim() === "" || isTableRow(l) || isListItem(l) || isQuoteLine(l)) { flush(); return }
|
|
129
|
-
if (para === null) para = { start: i + 1, len: 0 }
|
|
130
|
-
para.len += [...l].length
|
|
232
|
+
if (!excluded[i]) spans.push({ line: i + 1, end: i + 1, len: [...l].length })
|
|
131
233
|
})
|
|
132
|
-
|
|
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
|
|
133
241
|
}
|
|
134
|
-
|
|
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 }))
|
|
135
251
|
}
|