@thincoder/core 0.11.1 → 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 +46 -2
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +42 -25
- package/advisor/project-context.mjs +171 -42
- 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 +44 -3
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch.mjs +8 -3
- package/agent/family-tools.mjs +27 -12
- package/agent/helpers.mjs +122 -1
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +18 -1
- package/agent/run-stages.mjs +77 -32
- package/agent/run-start.mjs +37 -0
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +24 -11
- package/agent/spawn-child.mjs +38 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +30 -5
- 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-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- 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 +36 -47
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/batch-closeout.mjs +273 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +226 -17
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +169 -46
- package/agent-tools/batch-paths.mjs +29 -8
- 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 +379 -0
- package/agent-tools/batch-skeleton.mjs +192 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +182 -439
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +44 -17
- 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/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +9 -8
- package/agent-tools/escalate-async.mjs +2 -2
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +10 -3
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +9 -8
- package/agent-tools/ssh-session.mjs +2 -2
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-async.mjs +8 -9
- 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 +4 -4
- package/agent-tools/subagent-spawn.mjs +90 -110
- package/agent-tools/subagent.mjs +11 -10
- 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 +1 -1
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- 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 +149 -83
- package/conventions.mjs +11 -9
- package/declaration.mjs +31 -5
- 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/explore-distill.mjs +11 -5
- 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 +6 -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 +78 -19
- package/ledger-write-ops.mjs +130 -41
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/schema.mjs +2 -2
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +9 -6
- package/prompts/advisor-design.md +62 -21
- package/prompts/advisor-round1.md +34 -1
- package/prompts/advisor-round2.md +40 -7
- package/prompts/advisor-round3.md +39 -6
- package/prompts/common.md +14 -387
- package/prompts/consult-base.md +5 -1
- package/prompts/discipline-engineering.md +226 -51
- package/prompts/discipline-normal.md +4 -255
- 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 +21 -3
- package/prompts/persona-eng-designer.md +131 -169
- package/prompts/persona-engineering.md +142 -84
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +5 -1
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +3 -2
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +24 -7
- package/provider/responses.mjs +3 -1
- package/provider-flows.mjs +2 -2
- 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 +72 -17
- package/session-slot-write.mjs +37 -5
- package/session.mjs +24 -8
- package/skip-dirs.mjs +2 -2
- package/team-ledger.mjs +13 -9
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +167 -33
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -41
- 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 +52 -7
- 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 +1 -1
- package/tools/file.mjs +16 -8
- package/tools/git.mjs +24 -9
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +3 -1
- package/tools/patch.mjs +123 -43
- package/tools/shared.mjs +28 -27
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +203 -0
- package/doc-check/anchors.mjs +0 -235
package/ledger-tools.mjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { existsSync } from "node:fs"
|
|
14
14
|
import { isAbsolute, dirname, join, resolve } from "node:path"
|
|
15
15
|
import { ledgerAdd, ledgerClose, ledgerCloseBatch, ledgerCount, ledgerQuery, ledgerUpdate, ledgerUpdateBatch } from "./ledger-cmd.mjs"
|
|
16
|
-
import { noRootMessage, resolveLedgerRoot } from "./ledger-db.mjs"
|
|
16
|
+
import { QUERY_PAGE_SIZE, noRootMessage, resolveLedgerRoot } from "./ledger-db.mjs"
|
|
17
17
|
import { DESC } from "./tools/shared.mjs" // #15 描述外置:文本单点 = tool-docs/ledger.md(DESC 单解析面)
|
|
18
18
|
|
|
19
19
|
/** 指针值 → 文件路径(剥 `§N` 段号;空值跳过)。 */
|
|
@@ -29,7 +29,7 @@ const ptrPath = (v) => {
|
|
|
29
29
|
* 宿主下两者不同:会话锚才是「不能跑到工作目录以外去」的那道界)。 */
|
|
30
30
|
const anchorOf = (ctx) => ctx?.agent?.cwd ?? ctx?.cwd
|
|
31
31
|
|
|
32
|
-
/** 工具 cwd 供值面:**起点 = 动作目标路径**(`docs/core/requirements/ENGINEERING-MODE-V2-SPEC-MANIFEST.md
|
|
32
|
+
/** 工具 cwd 供值面:**起点 = 动作目标路径**(`docs/core/requirements/ENGINEERING-MODE-V2-SPEC-MANIFEST.md` 的「解析模型与作用定位」节
|
|
33
33
|
* 「参数按用点解析——动作作用于哪个项目的路径,就取那个项目的档」)。
|
|
34
34
|
* 指针(`task_book` ∥ `req_doc` ∥ `batch`)在场 ⇒ 取该文件所在目录为起点(文件 = 其所在目录);
|
|
35
35
|
* 无指针的动作(`query` ∥ `count` ∥ 首次建行)才回退会话锚。项目根由核 `resolveLedgerRoot` 推导。 */
|
|
@@ -56,6 +56,53 @@ function assertLedgerStart(start, boundary) {
|
|
|
56
56
|
if (!resolveLedgerRoot(start, boundary)) throw new Error(noRootMessage(start, boundary))
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// ── 分页(设计档 `LEDGER.md` §7.2「分页」条——`query` 工具面;核仍全量) ───────────────
|
|
60
|
+
|
|
61
|
+
/** 排序键(§7.2「无时间戳行的位置」):`updated_at ?? created_at ?? ""`(两列皆空的存量行键 = 空串)。
|
|
62
|
+
* 写入侧 `ledgerAdd` 恒置两列 ⇒ 空串形只来自迁移进来的存量行。定宽 UTC ISO 串(`nowIso`)⇒ 字典序 =
|
|
63
|
+
* 时序,游标按串比较即成立;空串字典序最小 ⇒ 倒序里恒居末位(当最旧处理)。 */
|
|
64
|
+
const pageSortKeyOf = (r) => r.updated_at ?? r.created_at ?? ""
|
|
65
|
+
|
|
66
|
+
/** 倒序比较:排序键倒序,同键按 `id` 倒序(兜底键——同刻多行才有确定次序)。 */
|
|
67
|
+
const pageSortDesc = (a, b) => {
|
|
68
|
+
const ka = pageSortKeyOf(a), kb = pageSortKeyOf(b)
|
|
69
|
+
return ka === kb ? b.id - a.id : ka < kb ? 1 : -1
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 游标形判(§7.2「游标形」):`"<排序键>|<id>"`——首个 `|` 之前是排序键(任意串、可为空),之后是十进制
|
|
73
|
+
* 正整数;不合 ⇒ 拒,**不静默回首页**(静默回退把「游标打错」伪装成「已翻到头」,读的人不会再核第二遍)。
|
|
74
|
+
* 判于 `ledgerQuery` 之前 ⇒ 非法游标零库动作。 */
|
|
75
|
+
function parseQueryCursor(raw) {
|
|
76
|
+
const bad = () => new Error(`ledger(query):cursor 非法:${argPreview(raw)}(应为「<updated_at>|<id>」,照上一页尾行原样传入)`)
|
|
77
|
+
if (typeof raw !== "string") throw bad()
|
|
78
|
+
const sep = raw.indexOf("|")
|
|
79
|
+
const idText = sep < 0 ? "" : raw.slice(sep + 1)
|
|
80
|
+
if (!/^[0-9]+$/.test(idText) || Number.parseInt(idText, 10) <= 0) throw bad()
|
|
81
|
+
return { key: raw.slice(0, sep), id: Number.parseInt(idText, 10) }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 回显段(§7.2「回显段」):本页生效的过滤原样带上,形如 `, status:"在途"`;一枚没给 ⇒ 空串(`cursor`
|
|
85
|
+
* 前不留逗号)。**回显是「照抄尾行就翻同一本账」的前提**——不回显则第二页按未过滤全集取行、`<N>` 从过滤集
|
|
86
|
+
* 换成全库,且零报错。`cwd` 同一道理:换锚就换了库。 */
|
|
87
|
+
const QUERY_ECHO_KEYS = ["status", "kind", "board", "trigger", "task_book", "cwd"]
|
|
88
|
+
const queryEchoOf = (args) => QUERY_ECHO_KEYS.filter((k) => args[k] != null).map((k) => `, ${k}:${JSON.stringify(args[k])}`).join("")
|
|
89
|
+
|
|
90
|
+
/** 分页切片 + 尾行(§7.2「回执逐字」四态)。`rows` = 核返回的**全量**行集(本函数不读库;排序在副本上
|
|
91
|
+
* 就地做,核的 `ORDER BY id` 零改):`<N>` = 同一行集的长度(不另跑 `count`——两数出自同一次读,不会互相
|
|
92
|
+
* 打架);`<P>` / `<A>–<B>` = 同一行集的序号;`cursor` 越过末行 ⇒ 本页空(与「候选集空」同一行)。 */
|
|
93
|
+
function queryPageOf(rows, cursor, echo) {
|
|
94
|
+
const ordered = [...rows].sort(pageSortDesc)
|
|
95
|
+
const total = ordered.length
|
|
96
|
+
const hit = cursor ? ordered.findIndex((r) => { const k = pageSortKeyOf(r); return k < cursor.key || (k === cursor.key && r.id < cursor.id) }) : 0
|
|
97
|
+
const from = hit < 0 ? total : hit
|
|
98
|
+
const page = ordered.slice(from, from + QUERY_PAGE_SIZE)
|
|
99
|
+
if (page.length === 0) return { page, tail: `共 ${total} 行 · 本页无行` }
|
|
100
|
+
const span = `第 ${Math.floor(from / QUERY_PAGE_SIZE) + 1} 页(第 ${from + 1}–${from + page.length} 行,按 updated_at 倒序)`
|
|
101
|
+
if (from + page.length >= total) return { page, tail: `共 ${total} 行 · ${span}· 已到末页` }
|
|
102
|
+
const last = page[page.length - 1]
|
|
103
|
+
return { page, tail: `共 ${total} 行 · ${span}· 下一页:ledger({action:"query"${echo}, cursor:"${pageSortKeyOf(last)}|${last.id}"})` }
|
|
104
|
+
}
|
|
105
|
+
|
|
59
106
|
// ── 工具层参数守卫(设计档 §3.2 · 2026-09-27 快车道修复 · Gitee #IKIQGK / 台账 #472) ──
|
|
60
107
|
|
|
61
108
|
/** 值预览(P1–P5 文案的 `<预览>`——设计档 §3.2):`JSON.stringify`,超 80 字符截断加 `…`
|
|
@@ -172,11 +219,11 @@ const ACTION_SPECS = {
|
|
|
172
219
|
board: { type: "string", description: "归属板块(缺省 = 不变)" },
|
|
173
220
|
req_doc: { type: "string", description: "需求档指针(缺省 = 不变)" },
|
|
174
221
|
task_book: { type: "string", description: "任务书指针(缺省 = 不变)" },
|
|
175
|
-
evidence: { type: "string", description: "证据(缺省 = 不变;传入 = 追加——旧值非空 ⇒ 拼 `旧|新`(「|」零空格)、旧空直写;新值全空白 ⇒ 拒;覆盖 = 与 `evidenceReplace: true`
|
|
222
|
+
evidence: { type: "string", description: "证据(缺省 = 不变;传入 = 追加——旧值非空 ⇒ 拼 `旧|新`(「|」零空格)、旧空直写;新值全空白 ⇒ 拒;覆盖 = 与 `evidenceReplace: true` 同传)。在途 / 待核销 → 待讨论 时本笔必填,作为退回理由并随回执返回 reason" },
|
|
176
223
|
evidenceReplace: { type: "boolean", description: "覆盖旗(布尔):与 evidence 同传 = 整段替换(旧文零保留);缺省 / false = 追加;旗独传(无新文)⇒ 拒" },
|
|
177
224
|
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "触发(缺省 = 不变)" },
|
|
178
225
|
resume_when: { type: "string", description: "复启条件句(缺省 = 不变;值非空——空串 / 全空白 ⇒ 拒)" },
|
|
179
|
-
executor: { type: "string", description: "执行者 sessionId
|
|
226
|
+
executor: { type: "string", description: "执行者 sessionId(可选——普通接手改写归属用;缺省 = 按状态迁移语义:进入待设计 / 在途自动写本会话;出在途 / 撤回 / 退回待讨论清空;待核销 → 在途恒写本会话,显式值不覆盖)" },
|
|
180
227
|
},
|
|
181
228
|
additionalProperties: false,
|
|
182
229
|
},
|
|
@@ -191,7 +238,7 @@ const ACTION_SPECS = {
|
|
|
191
238
|
id: { type: "number", description: "条目 id(与 batch 恰携其一)" },
|
|
192
239
|
batch: { type: "string", description: "批档指针(与 id 恰携其一)——批级批量结算:只销已到 待核销 的行;待讨论 / 待设计 点名跳过(须先 update 到 在途 认领);在途 点名跳过(不可跳)" },
|
|
193
240
|
status: { type: "string", enum: ["已核销", "已废弃"], description: "目标态(勾销 / 撤回)——携 batch 时可不给(缺省 = 勾销单值),给了只能是 已核销" },
|
|
194
|
-
evidence: { type: "string", description: "
|
|
241
|
+
evidence: { type: "string", description: "最小工作证据行(可选;传入 = 追加缺省——旧值非空 ⇒ 拼 `旧|新`(「|」零空格)、旧空直写;新值全空白 ⇒ 拒;覆盖 = 与 `evidenceReplace: true` 同传)。核销只判应用本笔后的 evidence 非空白,不读锚批收口或评审状态" },
|
|
195
242
|
evidenceReplace: { type: "boolean", description: "覆盖旗(布尔):与 evidence 同传 = 整段替换(旧文零保留);缺省 / false = 追加;旗独传(无新文)⇒ 拒" },
|
|
196
243
|
},
|
|
197
244
|
additionalProperties: false,
|
|
@@ -209,6 +256,7 @@ const ACTION_SPECS = {
|
|
|
209
256
|
board: { type: "string", description: "按归属板块过滤(需求档文档名)" },
|
|
210
257
|
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "按技术待办触发过滤(三枚举,缺省 = 不过滤——无触发(NULL)不过滤)" },
|
|
211
258
|
task_book: { type: "string", description: "按任务书指针过滤(原值等值——批→行反查;缺省 = 不过滤)" },
|
|
259
|
+
cursor: { type: "string", description: "分页游标(可空):照上一页尾行原样传入(形 `<updated_at>|<id>`)。缺省 = 首页(自最新一行起);形不合 ⇒ 拒,不静默回首页" },
|
|
212
260
|
},
|
|
213
261
|
additionalProperties: false,
|
|
214
262
|
},
|
|
@@ -244,7 +292,8 @@ const UNION_PARAMETERS = {
|
|
|
244
292
|
id: { type: "number", description: "条目 id(update / close:与 batch 恰携其一)" },
|
|
245
293
|
batch: { type: "string", description: "批档指针(update / close:与 id 恰携其一)——批级批量:一次结算该批的行(update 携 status ⇒ 逐行迁移表重判;不携 status ⇒ 纯字段补丁;close 只销 待核销 行、status 可空)" },
|
|
246
294
|
status: { type: "string", enum: ["待讨论", "待设计", "在途", "待核销", "已核销", "已废弃"], description: "状态(单行 close 必填 ∈ {已核销, 已废弃};close 携 batch 时可空、给了只能是 已核销;update 迁移 / query 过滤——六态之一)" },
|
|
247
|
-
executor: { type: "string", description: "执行者 sessionId(update
|
|
295
|
+
executor: { type: "string", description: "执行者 sessionId(update 可选——普通接手改写归属;缺省 = 按状态迁移语义:进入待设计 / 在途自动写本会话;出在途 / 撤回 / 退回待讨论清空;待核销 → 在途恒写本会话,显式值不覆盖)" },
|
|
296
|
+
cursor: { type: "string", description: "分页游标(query,可空):照上一页尾行原样传入(形 `<updated_at>|<id>`);形不合 ⇒ 拒,不静默回首页" },
|
|
248
297
|
},
|
|
249
298
|
additionalProperties: false,
|
|
250
299
|
}
|
|
@@ -252,16 +301,19 @@ const UNION_PARAMETERS = {
|
|
|
252
301
|
/** 变体构造(同名单对象、schema 窄化、两形永不同装配——先例 = `subagent` 工具 depth 面变体):
|
|
253
302
|
* 全量(depth-0 五 action;`writeFace:true` —— `readonly:false` + 动作级分类钩子,写面保持侧效门,
|
|
254
303
|
* query / count 归只读类 = 旧读二 `readonly:true` 同行为:planMode 放行 / 免审批)∥ 只读(depth>0
|
|
255
|
-
* 二 action;`readonly:true`,写三 schema
|
|
256
|
-
*
|
|
304
|
+
* 二 action;`readonly:true`,写三 schema 级不可达、写专用参数与写说明同样不出现)。
|
|
305
|
+
* 形态显式声明(不按 actions 长度推导——增量变体不改错标文案)。
|
|
306
|
+
*
|
|
307
|
+
* **只读变体的参数面 = 本变体各 action 的 `ACTION_SPECS` 并集**(TOOLS.md §6.29 B6:按角色生成 schema):
|
|
308
|
+
* 它拿不到 `title` / `evidence` / `id` 这类只有写动作消费的参数,也拿不到它们的说明;描述取自己的档
|
|
309
|
+
* (`ledger-read.md`)——全量档 `ledger.md` 通篇讲五动作,只读角色读到它就是读到做不到的事。 */
|
|
257
310
|
function makeLedgerTool(actions, { readonly = false, writeFace = false } = {}) {
|
|
258
311
|
const entryTool = { name: "ledger", parameters: { type: "object", required: ["action"], properties: { action: { type: "string", enum: actions } } } }
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
properties: {
|
|
312
|
+
const readProps = {}
|
|
313
|
+
if (readonly) for (const a of actions) Object.assign(readProps, ACTION_SPECS[a].parameters.properties)
|
|
314
|
+
const properties = readonly
|
|
315
|
+
? { action: { type: "string", enum: actions, description: "操作(只读二值):query 查询 / count 计数" }, ...readProps }
|
|
316
|
+
: {
|
|
265
317
|
...UNION_PARAMETERS.properties,
|
|
266
318
|
action: {
|
|
267
319
|
...UNION_PARAMETERS.properties.action,
|
|
@@ -270,8 +322,11 @@ function makeLedgerTool(actions, { readonly = false, writeFace = false } = {}) {
|
|
|
270
322
|
? "操作(五值):add 新增 / update 更新 / close 收口 / query 查询 / count 计数——写三仅主 agent 装配面"
|
|
271
323
|
: "操作(只读二值):query 查询 / count 计数",
|
|
272
324
|
},
|
|
273
|
-
}
|
|
274
|
-
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
name: "ledger",
|
|
328
|
+
description: readonly ? DESC("ledger-read") : DESC("ledger"), // 文本单点 = tool-docs/{ledger,ledger-read}.md
|
|
329
|
+
parameters: { type: "object", required: ["action"], properties, additionalProperties: false },
|
|
275
330
|
readonly,
|
|
276
331
|
isReadonlyAction(args) { return READ_ACTIONS.includes(args?.action) },
|
|
277
332
|
async execute(args, ctx) {
|
|
@@ -299,8 +354,8 @@ function makeLedgerTool(actions, { readonly = false, writeFace = false } = {}) {
|
|
|
299
354
|
const { cwd, id, batch, ...patch } = rest
|
|
300
355
|
const target = startOf(ctx, anchor, cwd, batch, patch.task_book, patch.req_doc)
|
|
301
356
|
let executorSessionId
|
|
302
|
-
if (patch.executor == null) {
|
|
303
|
-
//
|
|
357
|
+
if (patch.executor == null || patch.status === "在途") {
|
|
358
|
+
// 回退到在途也必须供当前会话:显式旧 executor 不得覆盖机器语义。
|
|
304
359
|
const { getSessionId } = await import("./session-slots.mjs")
|
|
305
360
|
executorSessionId = getSessionId()
|
|
306
361
|
}
|
|
@@ -315,9 +370,13 @@ function makeLedgerTool(actions, { readonly = false, writeFace = false } = {}) {
|
|
|
315
370
|
return JSON.stringify({ ...ledgerClose({ cwd: target, id: rest.id, status: rest.status, evidence: rest.evidence, evidenceReplace: rest.evidenceReplace, boundary: anchor, agent: ctx?.agent }) })
|
|
316
371
|
}
|
|
317
372
|
case "query": {
|
|
373
|
+
// 分页(§7.2):游标形判先落(非法游标零库动作)→ 核取全量行 → 工具面排序切片 + 尾行。
|
|
318
374
|
const target = startOf(ctx, anchor, rest.cwd, rest.task_book)
|
|
375
|
+
const cursor = rest.cursor == null ? null : parseQueryCursor(rest.cursor)
|
|
319
376
|
assertLedgerStart(target, anchor)
|
|
320
|
-
|
|
377
|
+
const rows = ledgerQuery({ cwd: target, boundary: anchor, status: rest.status, kind: rest.kind, board: rest.board, trigger: rest.trigger, task_book: rest.task_book })
|
|
378
|
+
const { page, tail } = queryPageOf(rows, cursor, queryEchoOf(rest))
|
|
379
|
+
return `${JSON.stringify(page, null, 2)}\n\n${tail}`
|
|
321
380
|
}
|
|
322
381
|
case "count": {
|
|
323
382
|
const target = startOf(ctx, anchor, rest.cwd, rest.task_book)
|
package/ledger-write-ops.mjs
CHANGED
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
* 「解析出的档在盘」,先写指针后落档必被自己的门当场拒。
|
|
18
18
|
* ③ **回收只回 `待核销`**(§2.13):`已核销` 是终态,重开不回收、回执点名;其余状态一律不动。
|
|
19
19
|
*/
|
|
20
|
-
import { resolve } from "node:path"
|
|
20
|
+
import { basename, isAbsolute, resolve } from "node:path"
|
|
21
21
|
|
|
22
22
|
import { ALLOWED_MIGRATIONS, nowIso, openLedger, PENDING_STATUSES, resolveLedgerRoot } from "./ledger-db.mjs"
|
|
23
|
-
import { resolveDeclaredRef } from "./declaration.mjs"
|
|
24
|
-
import { assertCloseOutProof, filePartOf, namesPointer } from "./ledger-close-proof.mjs"
|
|
23
|
+
import { declaredPublicRoots, resolveDeclaredRef } from "./declaration.mjs"
|
|
24
|
+
import { assertAnchorBatchSettleable, assertCloseOutProof, filePartOf, isReservedPointer, namesPointer } from "./ledger-close-proof.mjs"
|
|
25
25
|
|
|
26
26
|
/** 解析基准(设计档 §6.1 口径 2 同一子表达式——与台账库键同源):`resolveLedgerRoot(cwd, boundary)?.root
|
|
27
27
|
* ?? resolve(cwd ?? ".")`。`boundary` = 会话锚(与 `openLedger` 同一枚上界——同一笔动作的判据不能两界)。 */
|
|
@@ -37,12 +37,12 @@ const pathKey = (p) => {
|
|
|
37
37
|
|
|
38
38
|
// ─── 逐行写核(update / close / bind 共用;判序 = 设计档 §13.9 逐字未变)───────────────────────
|
|
39
39
|
|
|
40
|
-
/** executor
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* 建档边——「需求已确认、当场开工」同样是一次进边,AC-M2-7「进入在途的迁移带 executor」在机器径上
|
|
44
|
-
* 也得成立)。 */
|
|
40
|
+
/** executor 目标值计算。
|
|
41
|
+
* 普通进边 = patch 显式 > 当前会话 > 行现值 > NULL;离开在途与退回待讨论恒为 NULL。
|
|
42
|
+
* `待核销 → 在途` 恒写当前会话,显式 patch 不覆盖这条机器语义。 */
|
|
45
43
|
export function resolveExecutorTarget(row, to, patch, executorSessionId) {
|
|
44
|
+
if (row.status === "待核销" && to === "在途") return executorSessionId ?? null
|
|
45
|
+
if (to === "待讨论") return null
|
|
46
46
|
if ((row.status === "待讨论" && to === "待设计") || (row.status === "待设计" && to === "在途") || (row.status === "待讨论" && to === "在途")) {
|
|
47
47
|
return patch.executor ?? executorSessionId ?? row.executor ?? null
|
|
48
48
|
}
|
|
@@ -70,11 +70,32 @@ export function assertEvidenceValue(fnName, evidence) {
|
|
|
70
70
|
if (evidence != null && String(evidence).trim() === "") throw new Error(`${fnName}:evidence 为空(非空字符串)`)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/** 预定指针拒文(逐字 = `docs/core/design/LEDGER.md` §6.4 拒文表两分支)。 */
|
|
74
|
+
const reservedNotRelativeError = (value) => `task_book:预定指针须写项目相对路径(不带声明源前缀 / 绝对路径):${value}`
|
|
75
|
+
const reservedOnDiskError = (value) => `task_book:预定指针所指的档已在盘(去掉「(预定)」标记即可):${value}`
|
|
76
|
+
|
|
77
|
+
/** 预定指针(§6.4 写门臂② 两支):两条件全成立才放过——① **项目相对**(不带声明源前缀、不是绝对路径、
|
|
78
|
+
* 不带盘符):认领以 `batch create` 的目标路径 P 为键(P 恒项目相对),值带声明源前缀 ∥ 绝对路径时认领按 P
|
|
79
|
+
* 解析、走另一个基准 ⇒ 同一行在认领里永远认不到;② **不在盘**(已在盘 ⇒ 标记多余,读数面会撒谎:
|
|
80
|
+
* `taskBookOnDisk` 报 `false` 而档在盘)。在盘判据与普通指针同一函数(`resolveDeclaredRef`),零二写。 */
|
|
81
|
+
function assertReservedPointer(cwd, value, boundary) {
|
|
82
|
+
const base = baseOf(cwd, boundary)
|
|
83
|
+
const part = filePartOf(value)
|
|
84
|
+
if (!part) throw new Error(reservedNotRelativeError(value))
|
|
85
|
+
const segs = part.replace(/\\/g, "/").split("/").filter(Boolean)
|
|
86
|
+
const declared = declaredPublicRoots(base)
|
|
87
|
+
const withPrefix = declared.some((root) => segs[0] === basename(root))
|
|
88
|
+
if (isAbsolute(part) || /^[a-zA-Z]:/.test(part) || withPrefix) throw new Error(reservedNotRelativeError(value))
|
|
89
|
+
if (resolveDeclaredRef(base, part).ok) throw new Error(reservedOnDiskError(value))
|
|
90
|
+
}
|
|
91
|
+
|
|
73
92
|
/** 写门·指针点名(设计档 §6.1 两臂 · AC-M2-10 ∥ AC-M2-29):判**本笔写入面**——两臂之外零判。
|
|
74
93
|
* 臂①(点名非空):结果行 `status ∈ {在途, 待核销}` ∨ 结果行 `trigger = 归批` ⇒ `task_book` 非空
|
|
75
94
|
* (缺 / 空串 / 全空白 ⇒ 拒「必填」);**不判在盘**(列值事实,不随盘面翻转——DDL 咬合 CHECK 为该半幅防线)。
|
|
76
95
|
* 臂②(本笔新指名):本笔新写 `task_book`(非空值)∥ 本笔新写 `trigger = 归批` ⇒ 绑定指针非空 ∧ 文件部分
|
|
77
96
|
* 可解析 ∧ 解析出的档**在盘**(判定单源 = `resolveDeclaredRef`,零二写)。
|
|
97
|
+
* **预定指针一支例外**(§6.4):值尾带 `(预定)` 标记 ⇒ 臂② 改判两支(项目相对 ∥ 不在盘),
|
|
98
|
+
* 不判在盘——未建档是它的合法态。
|
|
78
99
|
* **「档此刻在不在盘」不入臂①**:批档可随时整体清理 ⇒ 当结果行判据则合法账务被拒、而出路正是被拒字段
|
|
79
100
|
* (死锁);存量指针失效只体现为读数 `taskBookOnDisk = false`(§7.1)。 */
|
|
80
101
|
export function assertTaskBookGate(cwd, fnName, face, boundary) {
|
|
@@ -83,6 +104,7 @@ export function assertTaskBookGate(cwd, fnName, face, boundary) {
|
|
|
83
104
|
throw new Error(`${fnName}:task_book 必填(在途 / 待核销 / 归批 须携任务书指针)`)
|
|
84
105
|
}
|
|
85
106
|
if (!wroteTaskBook && !wroteBatchTrigger) return // 臂② 之外零判:旧指针所指档已清不阻任何此类写入
|
|
107
|
+
if (isReservedPointer(taskBook)) return assertReservedPointer(cwd, taskBook, boundary)
|
|
86
108
|
const part = filePartOf(taskBook)
|
|
87
109
|
if (!part) throw new Error(`${fnName}:task_book 不可解析(缺文件部分):${taskBook}`)
|
|
88
110
|
const base = baseOf(cwd, boundary) // §6.1 口径 2 同一子表达式(单源 = 本档 `baseOf`)
|
|
@@ -91,36 +113,47 @@ export function assertTaskBookGate(cwd, fnName, face, boundary) {
|
|
|
91
113
|
}
|
|
92
114
|
|
|
93
115
|
/**
|
|
94
|
-
* 单行落笔·update
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* 补丁(不携 `status`)时 `to === row.status` ⇒ 迁移表不判、`status` 零写(§3.3)。
|
|
116
|
+
* 单行落笔·update(单行形 ∥ 批量形 ∥ 建档形共函数):迁移表判 → 本笔退回理由与 evidence 值计算 →
|
|
117
|
+
* 工作证据门 → **锚批结算门**(归档目标态,`docs/core/design/LEDGER.md` §11.2)→ executor / 指针写门 → UPDATE。`to` = `patch.status ?? 行现态`——批量形纯字段
|
|
118
|
+
* 补丁(不携 `status`)时 `to === row.status` ⇒ 迁移表不判、`status` 零写(§3.3);归档态显式同态重写仍拒。
|
|
98
119
|
* `resume_when` = 普通可空字段补丁(`patch.resume_when ?? 行值`——§3.4)。
|
|
99
120
|
* **事务归属**:`tx = true` ⇒ 调用方已开事务(本函数不 BEGIN——嵌套 BEGIN 会当场抛);缺省 ⇒ 自开
|
|
100
121
|
* `BEGIN IMMEDIATE` 包一条 UPDATE(半途抛 ⇒ 行零改)。
|
|
122
|
+
* @param {object} [proof] — `{ base }`:锚批结算门的指针解析基准(必传——归档目标态那一笔要读锚批 §1)
|
|
101
123
|
*/
|
|
102
124
|
export function applyRowUpdateTx(db, cwd, row, patch, executorSessionId, boundary, proof = {}) {
|
|
103
125
|
const to = patch.status ?? row.status
|
|
126
|
+
const archivedRewrite = patch.status != null && to === row.status && (row.status === "已核销" || row.status === "已废弃")
|
|
127
|
+
if (archivedRewrite) throw new Error(`ledgerUpdate:归档态 ${row.status} 为终态,拒绝再次写入该状态`)
|
|
104
128
|
if (to !== row.status && !(ALLOWED_MIGRATIONS[row.status] ?? []).includes(to)) {
|
|
105
129
|
throw new Error(`ledgerUpdate:迁移 ${row.status} → ${to} 不在允许迁移表`)
|
|
106
130
|
}
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
131
|
+
const returning = to === "待讨论" && (row.status === "在途" || row.status === "待核销")
|
|
132
|
+
if (returning && (patch.evidence == null || String(patch.evidence).trim() === "")) {
|
|
133
|
+
throw new Error("ledgerUpdate:退回 待讨论 须携本笔 evidence 理由(非空字符串)")
|
|
134
|
+
}
|
|
110
135
|
const nextEvidence = evidenceValue("ledgerUpdate", row.evidence, patch.evidence, patch.evidenceReplace)
|
|
111
136
|
assertEvidenceValue("ledgerUpdate", patch.evidence)
|
|
112
|
-
|
|
137
|
+
if (to === "已核销") assertCloseOutProof("ledgerUpdate", nextEvidence)
|
|
138
|
+
// 锚批结算门(`docs/core/design/LEDGER.md` §11.2):**两个归档目标态同过一门**——只挂 `已核销` 会留下
|
|
139
|
+
// `待核销 → 已废弃` 这条同等通路,绕过「挂未收口档的行不得单独归档」。豁免 notice 随返回形回传调用面。
|
|
140
|
+
const anchor = to === "已核销" || to === "已废弃"
|
|
141
|
+
? assertAnchorBatchSettleable("ledgerUpdate", { taskBook: row.task_book, base: proof.base, to, from: row.status })
|
|
142
|
+
: null
|
|
143
|
+
const nextExecutor = resolveExecutorTarget(row, to, patch, executorSessionId)
|
|
144
|
+
const nextTaskBook = returning ? null : patch.task_book ?? row.task_book
|
|
145
|
+
const nextTrigger = returning ? null : patch.trigger ?? row.trigger
|
|
113
146
|
assertTaskBookGate(cwd, "ledgerUpdate", {
|
|
114
147
|
status: to,
|
|
115
|
-
trigger:
|
|
148
|
+
trigger: nextTrigger,
|
|
116
149
|
taskBook: nextTaskBook,
|
|
117
|
-
wroteTaskBook: namesPointer(patch.task_book),
|
|
118
|
-
wroteBatchTrigger: patch.trigger === "归批",
|
|
150
|
+
wroteTaskBook: !returning && namesPointer(patch.task_book),
|
|
151
|
+
wroteBatchTrigger: !returning && patch.trigger === "归批",
|
|
119
152
|
}, boundary) // → 写门 → UPDATE
|
|
120
153
|
const now = nowIso()
|
|
121
154
|
db.prepare(`UPDATE items SET status = ?, title = ?, board = ?, req_doc = ?, task_book = ?, evidence = ?, trigger = ?, resume_when = ?, executor = ?, updated_at = ? WHERE id = ?`)
|
|
122
|
-
.run(to, patch.title ?? row.title, patch.board ?? row.board, patch.req_doc ?? row.req_doc, nextTaskBook, nextEvidence,
|
|
123
|
-
return { id: Number(row.id), status: to }
|
|
155
|
+
.run(to, patch.title ?? row.title, patch.board ?? row.board, patch.req_doc ?? row.req_doc, nextTaskBook, nextEvidence, nextTrigger, patch.resume_when ?? row.resume_when, nextExecutor, now, row.id)
|
|
156
|
+
return { id: Number(row.id), status: to, ...(returning ? { reason: patch.evidence } : {}), ...(anchor ? { notices: [{ id: Number(row.id), ...anchor }] } : {}) }
|
|
124
157
|
}
|
|
125
158
|
|
|
126
159
|
/**
|
|
@@ -149,21 +182,25 @@ function closeExitSentence(status) {
|
|
|
149
182
|
return "先 update 到 在途 认领,再 update 到 待核销,最后 close 勾销"
|
|
150
183
|
}
|
|
151
184
|
|
|
152
|
-
/** 单行落笔·close
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* `executor` 零触碰(非在途出边)。调用方恒已开事务(`ledgerClose` / `ledgerCloseBatch`)。 */
|
|
185
|
+
/** 单行落笔·close(单行形 ∥ 批量形共函数):核销只有 `待核销 → 已核销` 一条边。
|
|
186
|
+
* 核销门读取应用本笔后的工作证据;撤回只允许未归档态,并清空 executor。
|
|
187
|
+
* `已核销 / 已废弃` 都是终态,重复撤回与归档态改写均拒绝。调用方恒已开事务。
|
|
188
|
+
* **两个归档目标态同过锚批结算门**(`docs/core/design/LEDGER.md` §11.2,解析基准 = `proof.base`):
|
|
189
|
+
* 单行 / batch / 收口重锚三条入口无一绕过;豁免 notice 随返回形回传调用面。 */
|
|
158
190
|
export function applyRowClose(db, row, status, evidence, evidenceReplace, proof = {}) {
|
|
159
191
|
if (status === "已核销" && row.status !== "待核销") throw new Error(`ledgerClose:核销仅限 待核销(现态 ${row.status}):${closeExitSentence(row.status)}`)
|
|
160
|
-
|
|
161
|
-
|
|
192
|
+
if (status === "已废弃" && (row.status === "已核销" || row.status === "已废弃")) {
|
|
193
|
+
throw new Error(`ledgerClose:撤回仅限未归档态(现态 ${row.status}):该行已归档,不可重复撤回或改写归档态`)
|
|
194
|
+
}
|
|
162
195
|
const nextEvidence = evidenceValue("ledgerClose", row.evidence, evidence, evidenceReplace)
|
|
163
|
-
assertEvidenceValue("ledgerClose", evidence)
|
|
196
|
+
assertEvidenceValue("ledgerClose", evidence)
|
|
197
|
+
if (status === "已核销") assertCloseOutProof("ledgerClose", nextEvidence)
|
|
198
|
+
const anchor = status === "已核销" || status === "已废弃"
|
|
199
|
+
? assertAnchorBatchSettleable("ledgerClose", { taskBook: row.task_book, base: proof.base, to: status, from: row.status })
|
|
200
|
+
: null
|
|
164
201
|
const now = nowIso()
|
|
165
202
|
db.prepare("UPDATE items SET status = ?, closed_at = ?, updated_at = ?, executor = ?, evidence = ? WHERE id = ?").run(status, now, now, status === "已废弃" ? null : row.executor, nextEvidence, row.id)
|
|
166
|
-
return { id: Number(row.id), status }
|
|
203
|
+
return { id: Number(row.id), status, ...(anchor ? { notices: [{ id: Number(row.id), ...anchor }] } : {}) }
|
|
167
204
|
}
|
|
168
205
|
|
|
169
206
|
// ─── 批级写点(建档绑定 · 重开回收;与收口重锚同形对称)────────────────────────────────
|
|
@@ -267,31 +304,54 @@ async function sameFaceScan({ cwd, boundary, face }) {
|
|
|
267
304
|
* 存在未决四态行 ⇒ 必须显式声明 `newDebt:"<一句理由>"`,否则**在写形开户之前**拒(逐行列候选)。
|
|
268
305
|
* 因此「零写 = 二件」(无行写入 ∥ 无批档写入)是结构挣来的,不靠判后回滚;判前取集走读形开户,不建库档。
|
|
269
306
|
* 理由落本笔新开行的 `evidence`(前缀 `新事理由:`);`ledger:"#N"` 在场 ⇒ 本节零判(接手路径零回归)。
|
|
307
|
+
* **认领支**(设计档 `docs/core/design/LEDGER.md` §6.4):`ledger` 与 `newDebt` 都不给时先探「目标路径 P 上
|
|
308
|
+
* 有没有带 `(预定)` 标记的行」——命中 ⇒ 认领**同一行**(不 INSERT;落笔 = 事务内那笔 `UPDATE`),§6.3 同面判
|
|
309
|
+
* 零判;`≥2` 条 ⇒ 拒并逐行点名。探针 = 纯读(读形开户之前),与同面判同一判点。
|
|
270
310
|
* @param {{cwd:string, ledgerNo:number|null, newDebt:string|null, targetAbs:string, taskBook:string, title:string,
|
|
271
311
|
* kind:string, board:string|null, boundary?:string, executorSessionId?:string|null, agent?:object}} o
|
|
272
312
|
* `newDebt` = 非空字符串(为什么这不是候选里那几条);空串 ∥ 全空白 ⇒ 按未给判;与 `ledger` 同携 ⇒ 拒。
|
|
273
313
|
* @param {(id:number)=>void} writeRecord — 写批档(`wx` 独占创建;真实行号已可得)
|
|
274
|
-
* @returns {Promise<{id:number, created:boolean, tookOver:"new"|"discussed"|"designed"|"live",
|
|
275
|
-
* sameFace:{face:string|null, n:number, m:number, declared:string|null}|null}>} `
|
|
276
|
-
*
|
|
314
|
+
* @returns {Promise<{id:number, created:boolean, claimed?:boolean, tookOver:"new"|"discussed"|"designed"|"live",
|
|
315
|
+
* sameFace:{face:string|null, n:number, m:number, declared:string|null}|null}>} `claimed` = 本笔认领了预定行
|
|
316
|
+
* (不开新行);`sameFace` = 同面判读数(`null` = 接手 ∥ 认领路径——两支都不判同面);
|
|
317
|
+
* `n` = 本面未决数 · `m` = 他面未决数(读数,不拦)· `declared` = 声明的新事理由
|
|
277
318
|
*/
|
|
278
319
|
export async function ledgerBindBatch({ cwd, ledgerNo = null, newDebt = null, targetAbs, taskBook, title, kind = "tech_todo", board = null, boundary, executorSessionId = null, agent = {} }, writeRecord) {
|
|
279
320
|
const face = faceOf(board)
|
|
280
321
|
const newDebtReason = typeof newDebt === "string" && newDebt.trim() !== "" ? newDebt.trim() : null // 空串 ∥ 全空白 ⇒ 按未给判
|
|
281
322
|
if (ledgerNo != null && newDebtReason) throw new Error(newDebtAndLedgerError()) // 语义互斥:`ledger` 在场即接手,不是新事
|
|
282
|
-
|
|
283
|
-
|
|
323
|
+
const base = baseOf(cwd, boundary)
|
|
324
|
+
// 认领支先判(§6.4「判序」):`ledger` 未给 ∧ `newDebt` 未给 ⇒ 先问「目标路径 P 上有没有预定行」。
|
|
325
|
+
// 预定行本身就在未决面(`待讨论` / `待设计`),同面判若先判,认领这一笔必被拒 ⇒ 认领永不发生。
|
|
326
|
+
// 命中 ⇒ 走认领、§6.3 同面判零判;未命中 ⇒ 才判同面。三支互斥:`ledger` ⇒ 接手径(两支零判);
|
|
327
|
+
// `newDebt` ⇒ 声明新事(不认领)。
|
|
328
|
+
const claimRows = ledgerNo == null && !newDebtReason ? reservedClaimProbe({ cwd, base, targetAbs, boundary }) : []
|
|
329
|
+
if (claimRows.length > 1) throw new Error(reservedAmbiguousError(taskBook, claimRows)) // `≥2` 条 ⇒ 拒并逐行点名
|
|
330
|
+
const claim = claimRows[0] ?? null
|
|
331
|
+
// 开批同面判(§6.3):判点 = 写形开户之前;`ledger` 在场 ∥ 认领命中 ⇒ 本节零判
|
|
332
|
+
const scan = ledgerNo == null && !claim ? await sameFaceScan({ cwd, boundary, face }) : null
|
|
284
333
|
if (scan && scan.n > 0 && !newDebtReason) throw new Error(sameFaceRefusal(face, scan.candidates))
|
|
285
334
|
const sameFace = scan ? { face, n: scan.n, m: scan.m, declared: newDebtReason } : null
|
|
286
335
|
const db = openLedger(cwd, { create: true, boundary })
|
|
287
336
|
try {
|
|
288
|
-
const base = baseOf(cwd, boundary)
|
|
289
337
|
db.exec("BEGIN IMMEDIATE")
|
|
290
338
|
try {
|
|
291
339
|
let row = null
|
|
292
340
|
let id = null
|
|
293
341
|
let created = false
|
|
294
|
-
if (
|
|
342
|
+
if (claim) {
|
|
343
|
+
// 认领(§6.4「落笔位次」):不 INSERT——本笔 UPDATE 就是它替代的那一步(与 INSERT 同位,事务内)。
|
|
344
|
+
// 崩在中间 ⇒ 事务回滚、零残留(本批正是消半状态的批,不能自己造一个)。
|
|
345
|
+
// 事务内复核与探针**同一判据**(标记 ∧ 现态 ∧ 仍解析到 P):探针到事务之间被改指的行不得认领,
|
|
346
|
+
// 否则落笔会把另一条归批意图静默改写成规范形。
|
|
347
|
+
id = Number(claim.id)
|
|
348
|
+
row = db.prepare("SELECT * FROM items WHERE id = ?").get(id)
|
|
349
|
+
const stillMine = row ? filePartOf(row.task_book) : ""
|
|
350
|
+
if (!row || !isReservedPointer(row.task_book) || (row.status !== "待讨论" && row.status !== "待设计")
|
|
351
|
+
|| stillMine === "" || pathKey(resolveDeclaredRef(base, stillMine).abs) !== pathKey(targetAbs)) {
|
|
352
|
+
throw new Error(`batch: the reserved ledger row #${id} changed under this call (probe vs transaction) — retry create; nothing was claimed. Nothing was written.`)
|
|
353
|
+
}
|
|
354
|
+
} else if (ledgerNo == null) {
|
|
295
355
|
// 步 2:先落一行不带指针的 `待讨论`(`在途` 被 DDL 咬合 CHECK 强制非空指针)+ `trigger` 不填;
|
|
296
356
|
// 声明新事者同拍带理由入 `evidence`(步 4 的值计算在 `patch.evidence` 缺省时保留行现值)
|
|
297
357
|
const now = nowIso()
|
|
@@ -318,10 +378,12 @@ export async function ledgerBindBatch({ cwd, ledgerNo = null, newDebt = null, ta
|
|
|
318
378
|
}
|
|
319
379
|
// 步 3:落档——必须先于步 4(写门两形都判「解析出的档在盘」)
|
|
320
380
|
writeRecord(id)
|
|
321
|
-
// 步 4:行写入走同一函数体(迁移表 → 机检 → executor → 写门 → UPDATE),不直写 SQL
|
|
381
|
+
// 步 4:行写入走同一函数体(迁移表 → 机检 → executor → 写门 → UPDATE),不直写 SQL。
|
|
382
|
+
// 认领径的 `task_book` 写规范形(`taskBook` 由调用方按 `relative(root, abs)` 给)⇒ 标记剥掉,
|
|
383
|
+
// 该行此后是普通行集成员(`filePartOf` 同址,选行判据零改)。
|
|
322
384
|
applyRowUpdateTx(db, cwd, row, { status: "在途", task_book: taskBook, trigger: "归批" }, executorSessionId, boundary, { base, agent })
|
|
323
385
|
db.exec("COMMIT")
|
|
324
|
-
return { id, created, tookOver: created ? "new" : row.status === "待设计" ? "designed" : "discussed", sameFace }
|
|
386
|
+
return { id, created, claimed: !!claim, tookOver: created ? "new" : row.status === "待设计" ? "designed" : "discussed", sameFace }
|
|
325
387
|
} catch (e) {
|
|
326
388
|
try { db.exec("ROLLBACK") } catch { /* 事务未开 / 已结 */ }
|
|
327
389
|
throw e
|
|
@@ -329,6 +391,32 @@ export async function ledgerBindBatch({ cwd, ledgerNo = null, newDebt = null, ta
|
|
|
329
391
|
} finally { db.close() }
|
|
330
392
|
}
|
|
331
393
|
|
|
394
|
+
/**
|
|
395
|
+
* 预定行认领探针(设计档 §6.4「建档认领」——**位次 = 读形开户之前**,与 §6.3 同面判同一判点):
|
|
396
|
+
* 只读地问「目标路径 P 上有没有带标记且解析到 P 的行」——纯读、零写、不建库档。
|
|
397
|
+
* 取集口径 = 预定行 ∧ 现态 `待讨论` / `待设计`(预定行本身就在未决面;已离开未决面的行不是可认领对象)。
|
|
398
|
+
* @returns {object[]} 命中行(`id` 升序)
|
|
399
|
+
*/
|
|
400
|
+
function reservedClaimProbe({ cwd, base, targetAbs, boundary }) {
|
|
401
|
+
const db = openLedger(cwd, { readOnly: true, boundary }) // 读形:库档不在 ⇒ null(零行可认领)
|
|
402
|
+
if (!db) return []
|
|
403
|
+
try {
|
|
404
|
+
return db.prepare("SELECT * FROM items ORDER BY id").all()
|
|
405
|
+
.filter((r) => isReservedPointer(r.task_book) && (r.status === "待讨论" || r.status === "待设计"))
|
|
406
|
+
.filter((r) => {
|
|
407
|
+
const part = filePartOf(r.task_book)
|
|
408
|
+
return part !== "" && pathKey(resolveDeclaredRef(base, part).abs) === pathKey(targetAbs)
|
|
409
|
+
})
|
|
410
|
+
} finally { db.close() }
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** `≥2` 条预定行指同一档的拒文(出处 = `docs/core/design/LEDGER.md` §6.4:认领此刻无可择一的判据——
|
|
414
|
+
* 无优先级、无时间戳序,任选一条 = 静默丢掉另一条的归批意图)。设计未给逐字串,本实现按 `batch` 族
|
|
415
|
+
* 拒文语域自拟(英文 + 逐行点名 + `Nothing was written.`)。 */
|
|
416
|
+
function reservedAmbiguousError(taskBook, rows) {
|
|
417
|
+
return `batch: ${rows.length} reserved ledger rows point at ${taskBook} — create cannot claim one of them: a reserved pointer carries no priority and no timestamp order, so picking one would silently drop another row's 归批 intent. Clear one first (ledger update — drop the 「(预定)」 marker or point it at another record). Candidates:\n` +
|
|
418
|
+
rows.map((r) => ` #${r.id} ${r.status} ${r.title}`).join("\n") + "\nNothing was written."
|
|
419
|
+
}
|
|
332
420
|
/** 重开回收回执的三种行(设计档 §2.13)。 */
|
|
333
421
|
const reclaimResult = (batch, { reclaimed = [], unreclaimable = [], failed = null } = {}) => ({ batch, reclaimed, unreclaimable, failed })
|
|
334
422
|
|
|
@@ -338,7 +426,8 @@ const reclaimResult = (batch, { reclaimed = [], unreclaimable = [], failed = nul
|
|
|
338
426
|
* 结账证据),入 `unreclaimable` 由回执点名;其余状态一律不动、不点名。
|
|
339
427
|
*
|
|
340
428
|
* 与 `ledgerReanchorBatch` 同形对称:同一行集 `resolveBatchRows`(行集判据单源)、`BEGIN IMMEDIATE`
|
|
341
|
-
* 单事务、失败 `ROLLBACK` 零行改、**不抛**(返回形 `failed
|
|
429
|
+
* 单事务、失败 `ROLLBACK` 零行改、**不抛**(返回形 `failed`——由调用方 `ledgerAfterRecordWrite` 转成
|
|
430
|
+
* 「回滚档 + 抛拒」:重开与回收要么一起成、要么一个都不成)。
|
|
342
431
|
* `trigger` / `resume_when` / `evidence` / `updated_at` **零触**(机器回收不是人工推进,行龄读数照旧);
|
|
343
432
|
* `executor` = 本会话 `sessionId`(行回工作位、干活的就是重开会话——AC-M2-7 在机器径上也成立)。
|
|
344
433
|
* @returns {{batch:string, reclaimed:{id:number,status:string,title:string}[], unreclaimable:{id:number,status:string,title:string}[], failed:string|null}}
|
package/ledger.mjs
CHANGED
|
@@ -154,7 +154,7 @@ export function detailScans(scans, current) {
|
|
|
154
154
|
// ——2026-10-07 批 ledger-tool 自本档迁入,公共面零变;`ledgerChildren` / `MAX_SIBLING_SCAN` / `resolveLedgerRoot`
|
|
155
155
|
// ——2026-10-16 批 ledger-root-derivation 随迁 / 新增,公共面形零改) ──
|
|
156
156
|
export { AGING_DAYS, ALLOWED_MIGRATIONS, EVIDENCE_TOO_LONG_MAX, MAX_SIBLING_SCAN, ledgerChildren, ledgerDbPath, ledgerKey, ledgerDirPath, openLedger, PENDING_STATUSES, resolveLedgerRoot, _setLedgerDirForTest, _resetLedgerDirForTest, ensureColumn, ensureExecutorColumn } from "./ledger-db.mjs"
|
|
157
|
-
export { ledgerAdd, ledgerBatchRows, ledgerBindBatch, ledgerClose, ledgerCloseBatch, ledgerCount, ledgerEvidenceTooLong, ledgerQuery, ledgerReanchorBatch, ledgerReclaimBatch, ledgerUpdate, ledgerUpdateBatch, overdueOf } from "./ledger-cmd.mjs"
|
|
157
|
+
export { assertLedgerCloseDisposition, batchLedgerConsistency, ledgerAdd, ledgerBatchRows, ledgerBindBatch, ledgerClose, ledgerCloseBatch, ledgerCount, ledgerEvidenceTooLong, ledgerQuery, ledgerReanchorBatch, ledgerReclaimBatch, ledgerUpdate, ledgerUpdateBatch, overdueOf } from "./ledger-cmd.mjs"
|
|
158
158
|
export { ledgerTool, ledgerReadTool, ledgerAddTool, ledgerCloseTool, ledgerCountTool, ledgerQueryTool, ledgerUpdateTool } from "./ledger-tools.mjs"
|
|
159
159
|
export { runLedgerAudit, runLedgerMigrate } from "./ledger-migrate.mjs"
|
|
160
160
|
export { resolveExecutorStates, executorTail, _setExecutorProbeTtlForTest } from "./ledger-executors.mjs"
|
package/manifest-discovery.mjs
CHANGED
|
@@ -136,7 +136,9 @@ function isInsideOrEqual(dir, bound) {
|
|
|
136
136
|
* **按名排序**——多根工作区常态,非错误态;1 ∥ ≥2 同判)/ `none`(其余,含裸仓锚——
|
|
137
137
|
* **不向下取根** ⇒ 双空);覆盖位在场 ⇒ 头部短路(`ok` + 覆盖值)。
|
|
138
138
|
* **发现读数只供 `workspace` 报明**:`discoverProjects` 的 `self` **不进 `root`**
|
|
139
|
-
* (判据单源 = `owningProject
|
|
139
|
+
* (判据单源 = `owningProject`)。**零写 · 状态面不抛**(`state` 三值恒有答案);**I/O 异常照原样上抛**——
|
|
140
|
+
* `owningProject` 取根那一环无护栏(`statSync(..., { throwIfNoEntry: false })` 只把「不存在」变成 `undefined`,
|
|
141
|
+
* 权限 ∥ 链接环等照抛),故调用点要自己包护栏;`resolveProjectRoot` 薄委托本函数。
|
|
140
142
|
* @returns {{state:'ok'|'workspace'|'none', root:string|null, candidates:string[]}} */
|
|
141
143
|
export function projectRootView(cwd) {
|
|
142
144
|
const target = resolve(cwd ?? ".")
|
package/manifest-schema.mjs
CHANGED
|
@@ -36,14 +36,25 @@ export const DEFAULT_MANIFEST = Object.freeze({
|
|
|
36
36
|
design: "docs/design",
|
|
37
37
|
modules: "docs/design/modules",
|
|
38
38
|
batches: "docs/batches",
|
|
39
|
-
// 第六子键(MANIFEST.md §2.12 · KD-M1-
|
|
40
|
-
//
|
|
41
|
-
//
|
|
39
|
+
// 第六子键(MANIFEST.md §2.12 · KD-M1-62/63/66):**一个文档层**——项目根相对的**目录**
|
|
40
|
+
// (单目录 ∥ 多目录数组),层内成员 = 目录及其全部子目录下的 `.md`,按层根相对路径码点序(KD-M1-63)。
|
|
41
|
+
// 文件值不受理(一个键一个语义——KD-M1-62);旧文件值得到一句可读原因,不自动改档(KD-M1-66)。
|
|
42
|
+
// 默认 `null`(未声明)是三态的地基:给一条默认目录,「未声明」与「声明了但层里没档」会读出
|
|
43
|
+
// 同一路径、塌成一态。
|
|
42
44
|
standards: null,
|
|
43
45
|
}),
|
|
44
46
|
// 项目声明三族(2026-09-27 声明载体唯一化批并入——键名 / 形态逐字承前;来源档已退役)。
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
// 无默认段(KD-M1-31 · 逐面对照 = `docs/core/design/MANIFEST.md` §2.4.1):默认段不是便利缺省,
|
|
48
|
+
// 是产品替项目下的一条判据——段名任意深度匹配,默认 `["src"]` 会让每个未声明代码面的项目静默按
|
|
49
|
+
// `src` 分类(用户 2026-11-10「不要带这个默认值」)。空数组是合法声明 =「无段名代码面」(兜底分类
|
|
50
|
+
// 仍在);收回路径 = 在项目档里显式写 `"codePaths": ["src"]`。
|
|
51
|
+
codePaths: Object.freeze([]),
|
|
52
|
+
// `docCheckExcludePaths` = 文档机检的**排除面**(消费方 = `thincoder-core/doc-check/index.mjs` 的 `judgedDomainDocs`;
|
|
53
|
+
// 机制 = `docs/core/design/DOC-CHECK.md` §10):落在声明前缀下的档不进判域——判据仍是三件,一件不加。
|
|
54
|
+
// 数组层 fail-closed 照旧(非数组 ⇒ 拒);归一 = `thincoder-core/declaration.mjs` 的 `normalizePathList`(与 `index.excludePaths` 同一把尺)。
|
|
55
|
+
// `writableRepos` = 可写外部**目录**表(写权声明,单向;机制 = `docs/core/design/CROSS-REPO-WRITE.md` §2.1):
|
|
56
|
+
// 与 `publicRepos` 成对但**不互派**——一个读名单、一个写名单,一个键的变化不顺带改另一个的授权面。
|
|
57
|
+
index: Object.freeze({ codeExtensions: Object.freeze([]), docExtensions: Object.freeze([]), excludePaths: Object.freeze([]), docCheckExcludePaths: Object.freeze([]), publicRepos: Object.freeze([]), writableRepos: Object.freeze([]) }),
|
|
47
58
|
})
|
|
48
59
|
|
|
49
60
|
/** 校验判据(模块设计 §2.2)——枚举 / 键存在(fallback 用);判据单源(KD-M1-4)。 */
|
|
@@ -119,9 +130,20 @@ export function validateManifest(obj) {
|
|
|
119
130
|
if (obj.index.excludePaths !== undefined && !Array.isArray(obj.index.excludePaths)) {
|
|
120
131
|
errors.push(`index.excludePaths 值形态非法:${JSON.stringify(obj.index.excludePaths)}(须为数组——非数组 fail-closed;空 ∕ 非串元素由归一剔除)`)
|
|
121
132
|
}
|
|
133
|
+
// `index.docCheckExcludePaths`(排除面 · 机制 = `docs/core/design/DOC-CHECK.md` §10):只是**数组层** fail-closed
|
|
134
|
+
// ——非数组 ⇒ 拒(元素层宽容,由归一剔除)。读侧:消费方读不到可用声明 ⇒ 排除面为空、档照判。
|
|
135
|
+
if (obj.index.docCheckExcludePaths !== undefined && !Array.isArray(obj.index.docCheckExcludePaths)) {
|
|
136
|
+
errors.push(`index.docCheckExcludePaths 值形态非法:${JSON.stringify(obj.index.docCheckExcludePaths)}(须为数组——非数组 fail-closed;空 ∕ 非串元素由归一剔除)`)
|
|
137
|
+
}
|
|
122
138
|
if (obj.index.publicRepos !== undefined && !Array.isArray(obj.index.publicRepos)) {
|
|
123
139
|
errors.push(`index.publicRepos 值形态非法:${JSON.stringify(obj.index.publicRepos)}(须为数组——非数组 fail-closed;空 ∕ 非串元素由归一剔除)`)
|
|
124
140
|
}
|
|
141
|
+
// `index.writableRepos`(跨仓写权声明 · 机制 = `docs/core/design/CROSS-REPO-WRITE.md` §2.1):与上一行同款
|
|
142
|
+
// **数组层** fail-closed——非数组 ⇒ 拒(元素层宽容,由归一剔除)。键写坏不该让整份 manifest 不可用;
|
|
143
|
+
// 而把非数组当「一项」读则是静默放行,故数组层照拒。
|
|
144
|
+
if (obj.index.writableRepos !== undefined && !Array.isArray(obj.index.writableRepos)) {
|
|
145
|
+
errors.push(`index.writableRepos 值形态非法:${JSON.stringify(obj.index.writableRepos)}(须为数组——非数组 fail-closed;空 ∕ 非串元素由归一剔除)`)
|
|
146
|
+
}
|
|
125
147
|
}
|
|
126
148
|
if (obj.phase !== undefined && !MANIFEST_SCHEMA.enum.phase.includes(obj.phase)) {
|
|
127
149
|
errors.push(`phase 取值非法:"${obj.phase}"(允许:${MANIFEST_SCHEMA.enum.phase.join(" | ")})`)
|
package/memory/schema.mjs
CHANGED
|
@@ -42,7 +42,7 @@ export const CODE_EXTS = new Set([
|
|
|
42
42
|
// Same declaration rule as CODE_EXTS (index.docExtensions).
|
|
43
43
|
export const DOC_EXTS = new Set([".md", ".mdc", ".mdx", ".txt", ".rst", ".adoc", ".org", ".wiki", ".tex"])
|
|
44
44
|
// 目录剪枝名单**单源外提**(2026-10-27 四份名单合一 · 零依赖叶档 `../skip-dirs.mjs`):本档不再持
|
|
45
|
-
// 副本,同名 re-export 保 `memory.mjs
|
|
45
|
+
// 副本,同名 re-export 保 `memory.mjs` 的导出面逐字零变。名单 = 42 项精确集 + win32 折叠族(18)
|
|
46
46
|
// + 前缀族(`bazel-`);判定形状(折叠 / 前缀 / 点段)仍在本包 `file-walk.mjs`(只合名单,不合判定)。
|
|
47
47
|
import { SKIP_DIRS, SKIP_DIRS_FOLD, SKIP_DIR_PREFIXES } from "../skip-dirs.mjs"
|
|
48
48
|
export { SKIP_DIRS, SKIP_DIRS_FOLD, SKIP_DIR_PREFIXES } from "../skip-dirs.mjs"
|
|
@@ -65,7 +65,7 @@ export function createMemory({ dbPath }) {
|
|
|
65
65
|
// §6.12 WAL 卫生(TUI 假死批):① `journal_size_limit` = 回收后 WAL 文件截断上界(防复胀);
|
|
66
66
|
// ② 开库**一次性** `wal_checkpoint(TRUNCATE)`——失败容忍(另一实例持读事务 ⇒ busy:静默跳过,
|
|
67
67
|
// 不重试不报错)。边界写实:最坏等待上界 = 连接上的 `busy_timeout`(**不是**「不阻塞」;
|
|
68
|
-
// `wal_checkpoint` 是否走 busy handler = unverified
|
|
68
|
+
// `wal_checkpoint` 是否走 busy handler = unverified)。
|
|
69
69
|
db.exec(`PRAGMA journal_size_limit = ${WAL_SIZE_LIMIT_BYTES}`)
|
|
70
70
|
try { db.exec(`PRAGMA wal_checkpoint(TRUNCATE)`) } catch { /* busy / 非 WAL(内存库)⇒ 保持现状 */ }
|
|
71
71
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thincoder/core",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "ThinCoder shared core — shared mechanism modules + shared prompt content (CLI ↔ VS Code extension).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"agent-tools/",
|
|
43
43
|
"browser/",
|
|
44
44
|
"doc-check/",
|
|
45
|
+
"doc-graph/",
|
|
45
46
|
"git/",
|
|
46
47
|
"mcp/",
|
|
47
48
|
"memory/",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"tools/",
|
|
51
52
|
"traces/",
|
|
52
53
|
"prompts/",
|
|
54
|
+
"knowledge/",
|
|
53
55
|
"tool-docs/"
|
|
54
56
|
]
|
|
55
57
|
}
|