@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/ledger-db.mjs
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* ledger-db.mjs — 台账 SQLite 连接 / DDL / 枚举常量(M2 模块拆分件——设计档
|
|
3
3
|
* docs/core/design/modules/ENGINEERING-MODE-V2-MODULE-LEDGER.md §2.3 拆分计划)。
|
|
4
4
|
*
|
|
5
|
-
* items
|
|
5
|
+
* items 表 + 三 CHECK 枚举(kind / status / trigger)+ task_book 咬合 CHECK——枚举机械锁死
|
|
6
6
|
* 靠 DDL(AC-M2-2),不靠应用层 if。归档 = 软删除(状态值,无物理 DELETE——KD-M2-4)。
|
|
7
|
+
* 同库第二张表 `doc_edges`(文档锚点图的边)—— 同一 `db.exec`、同一文件,不新建第二个库。
|
|
7
8
|
* 本档静态 import node:sqlite ⇒ 消费侧一律动态 import 本模块链(W8 契约②——KD-M2-3)。
|
|
8
9
|
*
|
|
9
10
|
* 项目根推导单源(`resolveLedgerRoot` = 判据本体 `owningProject` 的 `basis` 形状包装)+ 同级枚举
|
|
@@ -22,7 +23,9 @@ import { join, resolve } from "node:path"
|
|
|
22
23
|
import { DatabaseSync } from "node:sqlite"
|
|
23
24
|
|
|
24
25
|
import { configDir } from "./config-io.mjs"
|
|
25
|
-
import { MANIFEST_REL, owningProject
|
|
26
|
+
import { MANIFEST_REL, owningProject } from "./manifest.mjs"
|
|
27
|
+
// 无根报明面的候选来源 = 统一解析层(`docs/core/design/PATH-RESOLUTION.md` §2.3——本档不自持候选枚举)。
|
|
28
|
+
import { resolvePathTarget } from "./path-resolve.mjs"
|
|
26
29
|
// 归一步单源(KD-LN1——直引,不抽新 util:先例 = peer-domains.mjs / traces/trace-store.mjs)。
|
|
27
30
|
import { normalizeCwd } from "./session-slots.mjs"
|
|
28
31
|
|
|
@@ -38,7 +41,7 @@ export function _resetLedgerDirForTest() { ledgerDir = join(configDir, "ledger")
|
|
|
38
41
|
export function ledgerDirPath() { return ledgerDir }
|
|
39
42
|
|
|
40
43
|
/** 项目根 → 库键(**键式单源**——设计档 `LEDGER.md` §2.1:键只在**本函数**一处生成):
|
|
41
|
-
* `sha1(normalizeCwd(root))
|
|
44
|
+
* `sha1(normalizeCwd(root))` 取前 16 位——`normalizeCwd`(盘符统一大写)是唯一补丁面:`resolve()`
|
|
42
45
|
* 已覆盖分隔符 / 点段 / 尾斜杠;非盘符段大小写**不折叠**(§2.1 不做段)。
|
|
43
46
|
* @param {string} root 项目根绝对路径
|
|
44
47
|
* @returns {string} 16 位十六进制键 */
|
|
@@ -51,18 +54,18 @@ export function ledgerKey(root) {
|
|
|
51
54
|
const keyedDbFile = (root) => join(ledgerDir, `${ledgerKey(root)}.db`)
|
|
52
55
|
|
|
53
56
|
/** 「已注册」判据(**唯一**事实):该目录带项目声明档 `PROJECT-MANIFEST.json`。
|
|
54
|
-
* 项目 = 带 manifest 的目录(`docs/core/requirements/ENGINEERING-MODE-V2-SPEC-MANIFEST.md
|
|
57
|
+
* 项目 = 带 manifest 的目录(`docs/core/requirements/ENGINEERING-MODE-V2-SPEC-MANIFEST.md` 的「解析模型与作用定位」节)——
|
|
55
58
|
* 台账没有自己的「项目」定义:台账根 = 项目根,一个判据。 */
|
|
56
59
|
function isRegistered(dir) {
|
|
57
60
|
return existsSync(join(dir, MANIFEST_REL))
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
/** 同级枚举上限(成本有界:父目录超此规模 = 缓存 / 临时等非仓族形态 → 退化空集)。
|
|
61
|
-
* 2026-10-16 批 ledger-root-derivation 自 `ledger.mjs`
|
|
64
|
+
* 2026-10-16 批 ledger-root-derivation 自 `ledger.mjs` 随迁(同级枚举:族发现单一消费面)。 */
|
|
62
65
|
export const MAX_SIBLING_SCAN = 100
|
|
63
66
|
|
|
64
67
|
/** 目录下**已注册**(档在盘——§2.1 单谓词)的直接子目录(目录名升序;不可读 ∥ 超限 ⇒ 空集;
|
|
65
|
-
* **惰性枚举 + 上限**——大目录零全量扫描)。消费面 =
|
|
68
|
+
* **惰性枚举 + 上限**——大目录零全量扫描)。消费面 = 族发现(`thincoder-core/ledger.mjs`)。
|
|
66
69
|
* `ledger` = 该子目录根的键控库路径(推算值 ⇒ 可能尚未在盘)。2026-10-16 批自 `ledger.mjs` 随迁。 */
|
|
67
70
|
export function ledgerChildren(dir) {
|
|
68
71
|
const out = []
|
|
@@ -91,11 +94,11 @@ export function ledgerChildren(dir) {
|
|
|
91
94
|
* `ancestor`(最近带档祖先)。「项目根报明 / 建档」由用点决定。
|
|
92
95
|
* **无自指**:本档不判库在盘(台账无第二定义——库在盘不算项目)。
|
|
93
96
|
* @param {string} [target] 动作目标路径(目录 | 文件则取其所在目录)
|
|
94
|
-
* @param {string}
|
|
97
|
+
* @param {string} boundary 上溯上界(会话锚——**必传**;缺则该值缺失即失败,不落 `process.cwd()`)
|
|
95
98
|
* @returns {{root: string, basis: 'self'|'ancestor'}|null} 项目根 + 判据来源 / 无根(`null`) */
|
|
96
99
|
export function resolveLedgerRoot(target, boundary) {
|
|
97
100
|
const start = resolve(target ?? ".")
|
|
98
|
-
const edge = resolve(boundary
|
|
101
|
+
const edge = resolve(boundary)
|
|
99
102
|
const root = owningProject(start, edge)
|
|
100
103
|
return root ? { root, basis: root === start ? "self" : "ancestor" } : null
|
|
101
104
|
}
|
|
@@ -103,26 +106,26 @@ export function resolveLedgerRoot(target, boundary) {
|
|
|
103
106
|
/** 无根文案(单源——`openLedger` 写面 ∥ `ledgerDbPath` ∥ 工具面读面(`ledger-tools.mjs`)共用同一句):
|
|
104
107
|
* **只陈述事实**——起点 + 上溯上界(界内无项目根),不写「祖先链无已注册项目」这类越界断言:
|
|
105
108
|
* 归属根可能就在界**之上**(界外)——那一格该句为假,读它会教人误判层级。
|
|
106
|
-
* 锚态 = 工作区时追报下辖候选(报明面读数 =
|
|
107
|
-
*
|
|
109
|
+
* 锚态 = 工作区时追报下辖候选(报明面读数 = 统一解析层的 `ambiguous.candidates`——
|
|
110
|
+
* **只供报明,不参与取根**:取根仍以会话锚为界,`resolveLedgerRoot` 零改)。
|
|
108
111
|
* @param {string} start 起点(动作目标路径)
|
|
109
|
-
* @param {string}
|
|
112
|
+
* @param {string} boundary 上溯上界(会话锚——**必传**)——与 `resolveLedgerRoot` 同一口径 */
|
|
110
113
|
export const noRootMessage = (start, boundary) => {
|
|
111
|
-
const
|
|
112
|
-
const edge = resolve(boundary
|
|
113
|
-
const tail =
|
|
114
|
+
const picked = resolvePathTarget(start, undefined, { kind: "dir", order: "root-first" })
|
|
115
|
+
const edge = resolve(boundary)
|
|
116
|
+
const tail = picked.state === "ambiguous" ? `;下辖候选项目:${picked.candidates.join(" ∥ ")}` : ""
|
|
114
117
|
return `台账:自 ${start} 未找到项目根(向上找到 ${edge} 为止)${tail}`
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
/** 项目根 → 库路径(稳定键 = `ledgerKey` 前 16 位——路径唯一标识,不含分隔符)。
|
|
118
121
|
* **归单源**(2026-10-16 批 ledger-root-derivation):根 = `resolveLedgerRoot(cwd, boundary)`——与读面 / 写面
|
|
119
122
|
* 同一推导;无根 ⇒ 抛**同一**无根文案(键需根,不产第二答案)。
|
|
120
|
-
* `boundary` = 上溯上界(**会话锚**——设计档 §3.8
|
|
121
|
-
*
|
|
123
|
+
* `boundary` = 上溯上界(**会话锚**——设计档 §3.8「界(单源)」):由调用方指名(**必传**);
|
|
124
|
+
* 进程工作目录不是界(CLI 的锚只是端 adapter 在装配期写入 `agent.cwd` 的取值)。
|
|
122
125
|
* v2 键归一(2026-09-25 批):盘符本大写(CLI)⇒ 键恒等零变;小写盘符(VSC `uri.fsPath`)
|
|
123
126
|
* 并入同键 ⇒ 同项目两端同库(收正前 = 同项目两键两库)。
|
|
124
127
|
* @param {string} [cwd] 动作目标路径
|
|
125
|
-
* @param {string}
|
|
128
|
+
* @param {string} boundary 上溯上界(会话锚——**必传**) */
|
|
126
129
|
export function ledgerDbPath(cwd, boundary) {
|
|
127
130
|
const start = resolve(cwd ?? ".")
|
|
128
131
|
const derived = resolveLedgerRoot(start, boundary)
|
|
@@ -133,38 +136,52 @@ export function ledgerDbPath(cwd, boundary) {
|
|
|
133
136
|
/** 未决四态(「活条目」口径 = 计数单源 WHERE 集;已核销 / 已废弃 = 归档态)。 */
|
|
134
137
|
export const PENDING_STATUSES = ["待讨论", "待设计", "在途", "待核销"]
|
|
135
138
|
|
|
136
|
-
/** 轻通道轮次行标记(单源——LIGHT-CHANNEL.md §2.3 开轮挂账 ∥ §2.8 闸凭据 ∥ §2.5 核销标记门
|
|
137
|
-
* 判据三面同一字面;消费面 = `agent/light-round.mjs`(经 `ledger.mjs` re-export 动态解构——
|
|
138
|
-
* W8 契约②零新静态边)∥ `ledger-cmd.mjs` 核销标记门)。 */
|
|
139
|
-
export const ROUND_MARKER = "收尾链待跑"
|
|
140
|
-
|
|
141
139
|
/** 老化阈值(天——口径 = 需求档;消费面 = `buildScan`(展示,`days` 可覆盖)+ `ledgerQuery` 逐行
|
|
142
140
|
* `aged`(查询面,`now` 可注入))。2026-10-07 批 ledger-tool:自 `ledger.mjs` 迁入(枚举常量档单源
|
|
143
141
|
* ——`ledgerQuery` 计算面直引本档,消 `ledger-cmd ↔ ledger.mjs` 新环;`ledger.mjs` 同名 re-export
|
|
144
142
|
* 保公共面零变——LEDGER.md §13.4)。 */
|
|
145
143
|
export const AGING_DAYS = 30
|
|
146
144
|
|
|
147
|
-
/** `evidence`
|
|
148
|
-
*
|
|
149
|
-
* `count` 回报)。 */
|
|
150
|
-
export const
|
|
145
|
+
/** `evidence` 判为太长的上限(字——设计档 `LEDGER.md` §5 P4 读数面单源):过了这条线即判为太长,
|
|
146
|
+
* 但**只出读数,不拒写**(读数非闸门——用户裁定「无限机检反感」;读数面 = `query` 逐行
|
|
147
|
+
* `evidenceTooLong` ∥ `count` 回报)。 */
|
|
148
|
+
export const EVIDENCE_TOO_LONG_MAX = 300
|
|
149
|
+
|
|
150
|
+
/** `query` 工具面每页行数(设计档 `LEDGER.md` §7.2「常量单源」):分页在工具面做(核仍全量),
|
|
151
|
+
* 带不带过滤条件都是这个数。**本档 = 唯一字面**——工具面取本常量;描述面两档(`tool-docs/ledger.md`
|
|
152
|
+
* ∥ `ledger-read.md`)写死该数字(模型读不到常量),同步判据 = 文案数字恒等 `String(QUERY_PAGE_SIZE)`。 */
|
|
153
|
+
export const QUERY_PAGE_SIZE = 10
|
|
154
|
+
|
|
151
155
|
|
|
152
156
|
/** 台账库结构版本(N2 标记**单源**——`PRAGMA user_version` 落标:写面开库 `v < 本值 ⇒ 置`;
|
|
153
157
|
* 读面如实回读(旧库未标 = 0);结构变更(新列 / 新表)同步升号——2026-10-03 read-data-interface 批。
|
|
154
|
-
* 2 = `resume_when` 可空列(设计档 §3.4 P5)。
|
|
155
|
-
|
|
158
|
+
* 2 = `resume_when` 可空列(设计档 §3.4 P5)。
|
|
159
|
+
* 3 = 同库第二张表 `doc_edges` 与两条索引(文档锚点图 · 机制单源 = `docs/core/design/DOC-GRAPH.md` §2.3
|
|
160
|
+
* ——边表与台账行住同一个 SQLite 文件,不新建第二个库)。 */
|
|
161
|
+
export const LEDGER_SCHEMA_VERSION = 3
|
|
156
162
|
|
|
157
|
-
/** 六态允许迁移表(ledgerUpdate 迁移前判,不在表内 →
|
|
163
|
+
/** 六态允许迁移表(ledgerUpdate 迁移前判,不在表内 → 拒)。
|
|
164
|
+
* `待讨论 → 在途` 是建档点火边;`在途 / 待核销 → 待讨论` 是未完成行的退回边;
|
|
165
|
+
* `待核销 → 在途` 是重开或手工回退边。`已核销 / 已废弃` 都是终态,没有出边。 */
|
|
158
166
|
export const ALLOWED_MIGRATIONS = {
|
|
159
|
-
"待讨论": ["待设计", "已废弃"],
|
|
167
|
+
"待讨论": ["待设计", "在途", "已废弃"],
|
|
160
168
|
"待设计": ["在途", "已废弃"],
|
|
161
|
-
"在途": ["待核销", "已废弃"],
|
|
162
|
-
"待核销": ["已核销", "已废弃"],
|
|
163
|
-
"已核销": [
|
|
169
|
+
"在途": ["待核销", "待讨论", "已废弃"],
|
|
170
|
+
"待核销": ["已核销", "在途", "待讨论", "已废弃"],
|
|
171
|
+
"已核销": [],
|
|
164
172
|
"已废弃": [],
|
|
165
173
|
}
|
|
166
174
|
|
|
167
|
-
/**
|
|
175
|
+
/** `doc_edges.kind` 的闭集(设计档 `docs/core/design/DOC-GRAPH.md` §2.2 的六类)。
|
|
176
|
+
* **一份闭集、两个消费面**:本档 DDL 的 CHECK 由它生成;查询面的 `kind` 收窄入参也按它校验
|
|
177
|
+
* (`doc-graph.mjs` 动态 import 本常量)——两边不各持一份字面,两份一漂就是「能存不能查」。 */
|
|
178
|
+
export const DOC_EDGE_KINDS = ["cites", "cites-req", "mentions-case", "case-file", "cites-symbol", "imports"]
|
|
179
|
+
|
|
180
|
+
/** 建表 DDL(幂等——设计档 §2.2 逐字;CHECK 字符串用单引号——KD7 实核)。
|
|
181
|
+
* 两张表同一个 `db.exec`、同一个文件:`items`(台账行)∥ `doc_edges`(文档锚点图的边——机制单源 =
|
|
182
|
+
* `docs/core/design/DOC-GRAPH.md` §2.3,需求 F1「边表与台账同库」)。边表的三值 `state` 与本档台账的
|
|
183
|
+
* 六态无关:它是「目标在不在盘」的三态(`ok` ∥ `目标不在盘` ∥ `判不了存在性`),与 `doc_check` 的
|
|
184
|
+
* `档缺` / `unverified` 同义不同词。 */
|
|
168
185
|
const DDL = `
|
|
169
186
|
CREATE TABLE IF NOT EXISTS items (
|
|
170
187
|
id INTEGER PRIMARY KEY,
|
|
@@ -182,7 +199,23 @@ CREATE TABLE IF NOT EXISTS items (
|
|
|
182
199
|
closed_at TEXT,
|
|
183
200
|
resume_when TEXT,
|
|
184
201
|
CHECK (status NOT IN ('在途','待核销') OR (task_book IS NOT NULL AND task_book <> ''))
|
|
185
|
-
)
|
|
202
|
+
);
|
|
203
|
+
CREATE TABLE IF NOT EXISTS doc_edges (
|
|
204
|
+
id INTEGER PRIMARY KEY,
|
|
205
|
+
src TEXT NOT NULL,
|
|
206
|
+
src_label TEXT,
|
|
207
|
+
kind TEXT NOT NULL CHECK(kind IN (${DOC_EDGE_KINDS.map((k) => `'${k}'`).join(",")})),
|
|
208
|
+
dst TEXT NOT NULL,
|
|
209
|
+
dst_label TEXT,
|
|
210
|
+
evidence TEXT NOT NULL,
|
|
211
|
+
state TEXT NOT NULL CHECK(state IN ('ok','目标不在盘','判不了存在性')),
|
|
212
|
+
scope TEXT NOT NULL,
|
|
213
|
+
scanned_at TEXT NOT NULL,
|
|
214
|
+
UNIQUE(src, kind, dst, evidence)
|
|
215
|
+
);
|
|
216
|
+
CREATE INDEX IF NOT EXISTS doc_edges_dst ON doc_edges(dst);
|
|
217
|
+
CREATE INDEX IF NOT EXISTS doc_edges_scope ON doc_edges(scope);
|
|
218
|
+
`
|
|
186
219
|
|
|
187
220
|
/** 老库幂等迁移共件:items 表缺该可空列 ⇒ ALTER 补列(`executor` ∥ `resume_when` 两列共用一份
|
|
188
221
|
* 「复判列在否」逻辑——设计档 §3.4)。判据 = PRAGMA table_info 实查(不猜版本号);ALTER
|
|
@@ -238,8 +271,8 @@ function markSchemaVersion(db) {
|
|
|
238
271
|
* **只读态**(readOnly=true——读面专用):只读句柄 + 零 DDL / ALTER + items 探针(见 openReadOnly);
|
|
239
272
|
* 如实副作用:旧库(缺 executor 列)**读**不再自动补列——补列归写面开库;读出行缺列按 null 归一。
|
|
240
273
|
* 「目录不存在」的真错照抛(fail-loud——先于推导,文案逐字零改)。
|
|
241
|
-
* `boundary` = 上溯上界(**会话锚**——设计档 §3.8「界(单源)」):工具面传 `ctx.agent.cwd
|
|
242
|
-
*
|
|
274
|
+
* `boundary` = 上溯上界(**会话锚**——设计档 §3.8「界(单源)」):工具面传 `ctx.agent.cwd`(**必传**;
|
|
275
|
+
* 缺则该值缺失即失败,不落 `process.cwd()`——进程工作目录不是界)。 */
|
|
243
276
|
export function openLedger(cwd, { create = false, readOnly = false, boundary } = {}) {
|
|
244
277
|
const start = resolve(cwd ?? ".")
|
|
245
278
|
if (!existsSync(start)) {
|
package/ledger-executors.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ledger-executors.mjs — 在途 executor 判活展示(F-LX1 · 设计档 LEDGER.md §7.3.1)。
|
|
3
3
|
*
|
|
4
4
|
* 红线:写径零探测——判活只落显示面。本档从 ledger.mjs 拆出(2026-09-21 executor 判活批,
|
|
5
|
-
* ledger.mjs 307 → ≤300
|
|
5
|
+
* ledger.mjs 307 → ≤300 行线回落),语义零变:`resolveExecutorStates` async 单源 + `executorTail`
|
|
6
6
|
* 三态文案(双端同文——CLI L2 与 VSC tooltip 共此函数)+ TTL 缓存(与 peer-instances 同源口径)。
|
|
7
7
|
*/
|
|
8
8
|
import { classifyEnd, ownerState, probeOwnersAsync } from "./process-probe.mjs"
|
package/ledger-migrate.mjs
CHANGED
|
@@ -98,9 +98,9 @@ function fromKeyRefusal(fromKeys, dir) {
|
|
|
98
98
|
return null
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
/** 迁移计划(dry-run / confirm 共用)。cwd 口径 = 写门口径 2 同一子表达式(根推导单源 `resolveLedgerRoot(cwd)?.root` ∨ 兜底)——与实开库(`openLedger
|
|
101
|
+
/** 迁移计划(dry-run / confirm 共用)。cwd 口径 = 写门口径 2 同一子表达式(根推导单源 `resolveLedgerRoot(cwd, cwd)?.root` ∨ 兜底)——与实开库(`openLedger`)同源。界 = 目标自身(不再向上找——同 `findProject` 形)。 */
|
|
102
102
|
export function planLedgerMigration(cwd, { fromKeys = [] } = {}) {
|
|
103
|
-
const projectRoot = resolveLedgerRoot(cwd)?.root ?? resolve(cwd ?? ".")
|
|
103
|
+
const projectRoot = resolveLedgerRoot(cwd, cwd)?.root ?? resolve(cwd ?? ".")
|
|
104
104
|
const dir = ledgerDirPath()
|
|
105
105
|
const targetKey = ledgerKey(projectRoot)
|
|
106
106
|
const targetPath = join(dir, `${targetKey}.db`)
|
|
@@ -194,7 +194,7 @@ export function runLedgerMigrate(args, { cwd = process.cwd(), out = console.log,
|
|
|
194
194
|
// 步 3 单事务迁入:BEGIN → 逐行 INSERT(重发新 id)→ 事务内读回核验 → COMMIT;失败 ⇒ ROLLBACK。
|
|
195
195
|
const report = { version: 1, batch, at: now.toISOString(), projectRoot: plan.projectRoot, targetKey: plan.targetKey, targetPath: plan.targetPath, targetCreated: !targetExists, sources: [], skippedRows: [], flags: plan.flags, recycled: [], kept: [] }
|
|
196
196
|
let db
|
|
197
|
-
try { db = openLedger(plan.projectRoot, { create: true }) } catch (e) { err(`Refused: 目标库不可开(${e.message})。`); return 1 }
|
|
197
|
+
try { db = openLedger(plan.projectRoot, { create: true, boundary: plan.projectRoot }) } catch (e) { err(`Refused: 目标库不可开(${e.message})。`); return 1 }
|
|
198
198
|
try {
|
|
199
199
|
db.exec(`PRAGMA busy_timeout = ${Math.max(0, Math.floor(busyMs))}`)
|
|
200
200
|
const existing = readRows(db)
|
|
@@ -255,7 +255,7 @@ export function runLedgerMigrate(args, { cwd = process.cwd(), out = console.log,
|
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
/** ③ 审计(只读——零删改):逐 `*.db` 出 `{键, 文件, 大小, mtime, 行数, 状态分布, 定性}`;归因 = **候选根集合**(锚项目 + `--root`)的变体键匹配(sha1 不可逆——只做候选生成)。 */
|
|
258
|
-
export function auditLedgerDir({ cwd
|
|
258
|
+
export function auditLedgerDir({ cwd, roots = [], dir = ledgerDirPath() } = {}) {
|
|
259
259
|
let names = []
|
|
260
260
|
try { names = readdirSync(dir).filter((n) => n.endsWith(".db")).sort() } catch { /* 不可读 ⇒ 空报告 */ }
|
|
261
261
|
const anchorKeys = new Set()
|
package/ledger-read.mjs
CHANGED
|
@@ -34,28 +34,30 @@ function exportRow(r, full) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** 单项目读(**两开均只读态**——版本探针开 + 行集开,§2.3):库不在 / 非台账库 ⇒ null(项目不出项)。
|
|
37
|
-
* 不可读(坏档)⇒ 抛(单范围 = 读错转 exit 1;族范围 = 调用侧捕获跳过)。
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
* 不可读(坏档)⇒ 抛(单范围 = 读错转 exit 1;族范围 = 调用侧捕获跳过)。
|
|
38
|
+
* `boundary` = 上溯上界(会话锚)——**必传**:缺值即当场失败(不再落 `process.cwd()`——那正是台账 #1834
|
|
39
|
+
* 的静默空账:进程 cwd 与目标项目不同时 `openLedger` 判越界 ⇒ 返回 null「该项目没有台账」,与真无库不可区分)。 */
|
|
40
|
+
function readProject(root, full, boundary) {
|
|
41
|
+
const probe = openLedger(root, { readOnly: true, boundary })
|
|
40
42
|
if (!probe) return null
|
|
41
43
|
let schemaVersion
|
|
42
44
|
try { schemaVersion = Number(probe.prepare("PRAGMA user_version").get().user_version ?? 0) } finally { probe.close() }
|
|
43
|
-
const rows = ledgerQuery({ cwd: root })
|
|
45
|
+
const rows = ledgerQuery({ cwd: root, boundary })
|
|
44
46
|
return { root, name: basename(root), schemaVersion, rows: rows.map((r) => exportRow(r, full)) }
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/** 统一序列化单源(N1——两出口共用;载荷 = §3.2 冻结形)。
|
|
48
50
|
* 单范围 = 当前项目一项;`family=true` = 族内发现序逐项(不可读跳过——余者照常)。 */
|
|
49
51
|
export function ledgerExport({ cwd, family = false, full = false } = {}) {
|
|
50
|
-
const anchor = cwd
|
|
52
|
+
const anchor = cwd
|
|
51
53
|
if (!family) {
|
|
52
|
-
const derived = resolveLedgerRoot(anchor)
|
|
53
|
-
const item = derived ? readProject(derived.root, full) : null
|
|
54
|
+
const derived = resolveLedgerRoot(anchor, anchor)
|
|
55
|
+
const item = derived ? readProject(derived.root, full, anchor) : null
|
|
54
56
|
return { projects: item ? [item] : [] }
|
|
55
57
|
}
|
|
56
58
|
const projects = []
|
|
57
59
|
for (const p of discoverFamily(anchor).projects) {
|
|
58
|
-
try { const item = readProject(p.root, full); if (item) projects.push(item) } catch { /* 不可读跳过 */ }
|
|
60
|
+
try { const item = readProject(p.root, full, anchor); if (item) projects.push(item) } catch { /* 不可读跳过 */ }
|
|
59
61
|
}
|
|
60
62
|
return { projects }
|
|
61
63
|
}
|
package/ledger-surface.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { ledgerDirPath } from "./ledger-db.mjs"
|
|
|
14
14
|
/** 单次扫描(直驱面——timer 包装见 `startLedgerSurface`)。**async**(F-LX1:await 判活解析——
|
|
15
15
|
* LEDGER.md §7.3.1 ④ 读面不阻塞事件循环)。 */
|
|
16
16
|
export async function runLedgerScan({ state, agent = null, anchor = null, render = () => {} } = {}) {
|
|
17
|
-
const base = anchor ?? agent?.cwd
|
|
17
|
+
const base = anchor ?? agent?.cwd
|
|
18
18
|
const family = discoverFamily(base)
|
|
19
19
|
const scans = []
|
|
20
20
|
for (const p of family.projects) {
|
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` 段号;空值跳过)。 */
|
|
@@ -24,12 +24,12 @@ const ptrPath = (v) => {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/** 会话锚供值面(**单源**——`cwdOf` 的缺省起点与上溯上界(`boundary`)同一表达式):
|
|
27
|
-
* `ctx.agent.cwd` > `ctx.cwd
|
|
27
|
+
* `ctx.agent.cwd` > `ctx.cwd`(零进程缺省:工具面拿不到给值时当场失败,不换界)。界 = 会话锚(设计档 §3.8「界(单源)· 两面两界」)——
|
|
28
28
|
* 工具面传给 `resolveLedgerRoot` / `openLedger` 的上界恒取本值,不取 `process.cwd()`(desktop / VSC
|
|
29
29
|
* 宿主下两者不同:会话锚才是「不能跑到工作目录以外去」的那道界)。 */
|
|
30
|
-
const anchorOf = (ctx) => ctx?.agent?.cwd ?? ctx?.cwd
|
|
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
|
},
|
|
@@ -189,9 +236,9 @@ const ACTION_SPECS = {
|
|
|
189
236
|
properties: {
|
|
190
237
|
cwd: { type: "string", description: CWD_DESC },
|
|
191
238
|
id: { type: "number", description: "条目 id(与 batch 恰携其一)" },
|
|
192
|
-
batch: { type: "string", description: "批档指针(与 id 恰携其一)——批级批量结算:只销已到 待核销 的行;待讨论 / 待设计
|
|
193
|
-
status: { type: "string", enum: ["已核销", "已废弃"], description: "目标态(勾销 /
|
|
194
|
-
evidence: { type: "string", description: "
|
|
239
|
+
batch: { type: "string", description: "批档指针(与 id 恰携其一)——批级批量结算:只销已到 待核销 的行;待讨论 / 待设计 点名跳过(须先 update 到 在途 认领);在途 点名跳过(不可跳)" },
|
|
240
|
+
status: { type: "string", enum: ["已核销", "已废弃"], description: "目标态(勾销 / 撤回)——携 batch 时可不给(缺省 = 勾销单值),给了只能是 已核销" },
|
|
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
|
},
|
|
@@ -237,14 +285,15 @@ const UNION_PARAMETERS = {
|
|
|
237
285
|
board: { type: "string", description: "归属板块(需求档文档名;add 可空 / update 缺省 = 不变 / query 过滤)" },
|
|
238
286
|
req_doc: { type: "string", description: "需求档指针(add 可空 / update 缺省 = 不变)" },
|
|
239
287
|
task_book: { type: "string", description: "任务书指针(add 可空 / update 缺省 = 不变;在途 / 待核销必填——咬合 CHECK)" },
|
|
240
|
-
evidence: { type: "string", description: "最小证据行(add 可空;update / close 传入 = 追加缺省——旧空直写、旧非空拼 `旧|新`(「|」零空格)、新值全空白 ⇒ 拒;覆盖 = 与 `evidenceReplace: true` 同传;update 缺省 = 不变 / close 缺省 =
|
|
288
|
+
evidence: { type: "string", description: "最小证据行(add 可空;update / close 传入 = 追加缺省——旧空直写、旧非空拼 `旧|新`(「|」零空格)、新值全空白 ⇒ 拒;覆盖 = 与 `evidenceReplace: true` 同传;update 缺省 = 不变 / close 缺省 = 判行值)" },
|
|
241
289
|
evidenceReplace: { type: "boolean", description: "覆盖旗(布尔):与 evidence 同传 = 整段替换;缺省 / false = 追加;旗独传(无新文)⇒ 拒(update / close)" },
|
|
242
290
|
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "技术待办触发(add / update 可空 / query 过滤)" },
|
|
243
291
|
resume_when: { type: "string", description: "复启条件句(add / update 可空;值非空——空串 / 全空白 ⇒ 拒;`trigger=条件` 行的一句话条件 + 可选锚 `@YYYY-MM-DD` ∥ `@事件件名`)" },
|
|
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)
|
|
@@ -35,7 +35,7 @@ export function _resetLedgerVariantNoticeForTest() { noticeChecked = false }
|
|
|
35
35
|
* @param {{cwd?: string, dir?: string, locale?: string, exists?: (p: string) => boolean}} [opts]
|
|
36
36
|
* @returns {string|null} 单行文案 / null
|
|
37
37
|
*/
|
|
38
|
-
export function ledgerVariantNotice({ cwd
|
|
38
|
+
export function ledgerVariantNotice({ cwd, dir = ledgerDirPath(), locale = "en", exists = defaultExists } = {}) {
|
|
39
39
|
if (noticeChecked) return null
|
|
40
40
|
noticeChecked = true
|
|
41
41
|
try {
|