@thincoder/core 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +10 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +54 -9
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
package/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 字符截断加 `…`
|
|
@@ -136,7 +183,7 @@ const FULL_ACTIONS = ["add", "update", "close", "query", "count"]
|
|
|
136
183
|
const READ_ACTIONS = ["query", "count"]
|
|
137
184
|
|
|
138
185
|
/** cwd 参数描述(五前身声明同文——文本单点)。 */
|
|
139
|
-
const CWD_DESC = "
|
|
186
|
+
const CWD_DESC = "The action's target path. The project root is the nearest ancestor directory holding a `PROJECT-MANIFEST.json`. A ledger file on disk does not make a project. A workspace with several roots and no project directory is reported with the candidates. The search never descends into a sub-project. The ledger is stored per project root in the user data directory, outside the work tree. A relative path resolves against the session anchor; no project is attached outside that boundary. Default: the session anchor"
|
|
140
187
|
|
|
141
188
|
/** 各 action 声明条目(= 前身旧工具 `parameters` 逐字;伪工具对象守卫 + 弃用壳共用单源)。
|
|
142
189
|
* `parameters` 内的键 = 交模型 / provider 的那一份声明;**组判据两键(`oneOfRequired` / `whenPresent`)
|
|
@@ -148,14 +195,14 @@ const ACTION_SPECS = {
|
|
|
148
195
|
required: ["kind", "title"],
|
|
149
196
|
properties: {
|
|
150
197
|
cwd: { type: "string", description: CWD_DESC },
|
|
151
|
-
kind: { type: "string", enum: ["requirement", "tech_todo"], description: "
|
|
152
|
-
title: { type: "string", description: "
|
|
153
|
-
board: { type: "string", description: "
|
|
154
|
-
req_doc: { type: "string", description: "
|
|
155
|
-
task_book: { type: "string", description: "
|
|
156
|
-
evidence: { type: "string", description: "
|
|
157
|
-
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "
|
|
158
|
-
resume_when: { type: "string", description: "
|
|
198
|
+
kind: { type: "string", enum: ["requirement", "tech_todo"], description: "What kind of row to open — required on add." },
|
|
199
|
+
title: { type: "string", description: "The row's title — required on add." },
|
|
200
|
+
board: { type: "string", description: "The owning board — a requirements document name (optional)." },
|
|
201
|
+
req_doc: { type: "string", description: "Requirements-document pointer (optional)." },
|
|
202
|
+
task_book: { type: "string", description: "Task-book pointer (optional). Required while the row is 在途 or 待核销 — the ledger CHECK enforces it." },
|
|
203
|
+
evidence: { type: "string", description: "Minimal evidence line (optional)." },
|
|
204
|
+
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "Tech-todo trigger — one of the `enum` values (optional)." },
|
|
205
|
+
resume_when: { type: "string", description: "Resume condition sentence (optional): one sentence for rows whose trigger is the conditional-resume kind, plus an optional anchor `@YYYY-MM-DD` or `@<event name>`. A blank or whitespace-only value is refused." },
|
|
159
206
|
},
|
|
160
207
|
additionalProperties: false,
|
|
161
208
|
},
|
|
@@ -165,18 +212,18 @@ const ACTION_SPECS = {
|
|
|
165
212
|
type: "object",
|
|
166
213
|
properties: {
|
|
167
214
|
cwd: { type: "string", description: CWD_DESC },
|
|
168
|
-
id: { type: "number", description: "
|
|
169
|
-
batch: { type: "string", description: "
|
|
170
|
-
status: { type: "string", enum: ["待讨论", "待设计", "在途", "待核销", "已核销", "已废弃"], description: "
|
|
171
|
-
title: { type: "string", description: "
|
|
172
|
-
board: { type: "string", description: "
|
|
173
|
-
req_doc: { type: "string", description: "
|
|
174
|
-
task_book: { type: "string", description: "
|
|
175
|
-
evidence: { type: "string", description: "
|
|
176
|
-
evidenceReplace: { type: "boolean", description: "
|
|
177
|
-
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "
|
|
178
|
-
resume_when: { type: "string", description: "
|
|
179
|
-
executor: { type: "string", description: "
|
|
215
|
+
id: { type: "number", description: "Row id — pass exactly one of id and batch." },
|
|
216
|
+
batch: { type: "string", description: "Batch-record pointer — pass exactly one of id and batch. Batch-level bulk: settles that batch's rows in one call. With `status`, every row is re-judged against the migration table; without it this is a plain field patch (status is not written)." },
|
|
217
|
+
status: { type: "string", enum: ["待讨论", "待设计", "在途", "待核销", "已核销", "已废弃"], description: "Target state — one of the six; omitted ⇒ unchanged." },
|
|
218
|
+
title: { type: "string", description: "Title; omitted ⇒ unchanged." },
|
|
219
|
+
board: { type: "string", description: "Owning board; omitted ⇒ unchanged." },
|
|
220
|
+
req_doc: { type: "string", description: "Requirements-document pointer; omitted ⇒ unchanged." },
|
|
221
|
+
task_book: { type: "string", description: "Task-book pointer; omitted ⇒ unchanged." },
|
|
222
|
+
evidence: { type: "string", description: "Evidence line; omitted ⇒ unchanged, given ⇒ appended: a non-empty old value is joined as `旧|新` (no spaces around the bar), an empty one is replaced outright. A whitespace-only value is refused. Pass `evidenceReplace: true` to replace the whole range. Required when moving 在途 or 待核销 back to 待讨论 — it is the return reason. The receipt returns it as `reason`." },
|
|
223
|
+
evidenceReplace: { type: "boolean", description: "Replace flag: pass it with `evidence` to replace the whole range (no part of the old text survives). Omitted or false ⇒ append. Passed alone, with no new text ⇒ refused." },
|
|
224
|
+
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "Tech-todo trigger; omitted ⇒ unchanged." },
|
|
225
|
+
resume_when: { type: "string", description: "Resume condition sentence; omitted ⇒ unchanged. A blank or whitespace-only value is refused." },
|
|
226
|
+
executor: { type: "string", description: "Executor session id (optional — override the owner when taking a row over). The default follows the state transition: entering 待设计 or 在途 writes this session automatically. Leaving 在途, withdrawing or returning to 待讨论 clears it. 待核销 → 在途 always writes this session, and an explicit value does not override it." },
|
|
180
227
|
},
|
|
181
228
|
additionalProperties: false,
|
|
182
229
|
},
|
|
@@ -188,11 +235,11 @@ const ACTION_SPECS = {
|
|
|
188
235
|
required: ["status"],
|
|
189
236
|
properties: {
|
|
190
237
|
cwd: { type: "string", description: CWD_DESC },
|
|
191
|
-
id: { type: "number", description: "
|
|
192
|
-
batch: { type: "string", description: "
|
|
193
|
-
status: { type: "string", enum: ["已核销", "已废弃"], description: "
|
|
194
|
-
evidence: { type: "string", description: "
|
|
195
|
-
evidenceReplace: { type: "boolean", description: "
|
|
238
|
+
id: { type: "number", description: "Row id — pass exactly one of id and batch." },
|
|
239
|
+
batch: { type: "string", description: "Batch-record pointer — pass exactly one of id and batch. Batch-level settlement: only rows already 待核销 are settled. Rows in 待讨论 or 待设计 are skipped and named (claim them first with update, which moves them to 在途). A 在途 row named here is skipped as well — the transition cannot jump over 待核销." },
|
|
240
|
+
status: { type: "string", enum: ["已核销", "已废弃"], description: "Target state: settle or withdraw. With `batch` it may be omitted (the settle value); given, it must be 已核销." },
|
|
241
|
+
evidence: { type: "string", description: "Minimal work-evidence line (optional); given ⇒ appended: a non-empty old value is joined as `旧|新` (no spaces around the bar), an empty one is replaced outright. A whitespace-only value is refused. Pass `evidenceReplace: true` to replace the whole range. The settle gate only asks whether the evidence is non-blank after this write — it never reads the anchoring batch's closeout or review state." },
|
|
242
|
+
evidenceReplace: { type: "boolean", description: "Replace flag: pass it with `evidence` to replace the whole range (no part of the old text survives). Omitted or false ⇒ append. Passed alone, with no new text ⇒ refused." },
|
|
196
243
|
},
|
|
197
244
|
additionalProperties: false,
|
|
198
245
|
},
|
|
@@ -204,11 +251,12 @@ const ACTION_SPECS = {
|
|
|
204
251
|
type: "object",
|
|
205
252
|
properties: {
|
|
206
253
|
cwd: { type: "string", description: CWD_DESC },
|
|
207
|
-
status: { type: "string", enum: ["待讨论", "待设计", "在途", "待核销", "已核销", "已废弃"], description: "
|
|
208
|
-
kind: { type: "string", enum: ["requirement", "tech_todo"], description: "
|
|
209
|
-
board: { type: "string", description: "
|
|
210
|
-
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "
|
|
211
|
-
task_book: { type: "string", description: "
|
|
254
|
+
status: { type: "string", enum: ["待讨论", "待设计", "在途", "待核销", "已核销", "已废弃"], description: "Filter by state — one of the six; omitted ⇒ no filter." },
|
|
255
|
+
kind: { type: "string", enum: ["requirement", "tech_todo"], description: "Filter by kind." },
|
|
256
|
+
board: { type: "string", description: "Filter by owning board (a requirements document name)." },
|
|
257
|
+
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "Filter by tech-todo trigger — one of the three `enum` values. Omitted ⇒ no filter, and rows carrying no trigger (NULL) are left in." },
|
|
258
|
+
task_book: { type: "string", description: "Filter by task-book pointer (exact value — the batch→row lookup). Omitted ⇒ no filter." },
|
|
259
|
+
cursor: { type: "string", description: "Page cursor (optional): copy the previous page's tail line verbatim (form `<updated_at>|<id>`). Omitted ⇒ the first page, newest row first. A malformed cursor is refused — never silently treated as page one." },
|
|
212
260
|
},
|
|
213
261
|
additionalProperties: false,
|
|
214
262
|
},
|
|
@@ -218,7 +266,7 @@ const ACTION_SPECS = {
|
|
|
218
266
|
type: "object",
|
|
219
267
|
properties: {
|
|
220
268
|
cwd: { type: "string", description: CWD_DESC },
|
|
221
|
-
task_book: { type: "string", description: "
|
|
269
|
+
task_book: { type: "string", description: "Filter by task-book pointer (exact value)." },
|
|
222
270
|
},
|
|
223
271
|
additionalProperties: false,
|
|
224
272
|
},
|
|
@@ -232,19 +280,20 @@ const UNION_PARAMETERS = {
|
|
|
232
280
|
properties: {
|
|
233
281
|
action: { type: "string", enum: FULL_ACTIONS, description: "" }, // 变体构造时填描述
|
|
234
282
|
cwd: { type: "string", description: CWD_DESC },
|
|
235
|
-
kind: { type: "string", enum: ["requirement", "tech_todo"], description: "
|
|
236
|
-
title: { type: "string", description: "
|
|
237
|
-
board: { type: "string", description: "
|
|
238
|
-
req_doc: { type: "string", description: "
|
|
239
|
-
task_book: { type: "string", description: "
|
|
240
|
-
evidence: { type: "string", description: "
|
|
241
|
-
evidenceReplace: { type: "boolean", description: "
|
|
242
|
-
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "
|
|
243
|
-
resume_when: { type: "string", description: "
|
|
244
|
-
id: { type: "number", description: "
|
|
245
|
-
batch: { type: "string", description: "
|
|
246
|
-
status: { type: "string", enum: ["待讨论", "待设计", "在途", "待核销", "已核销", "已废弃"], description: "
|
|
247
|
-
executor: { type: "string", description: "
|
|
283
|
+
kind: { type: "string", enum: ["requirement", "tech_todo"], description: "Kind — required on add, a filter on query; omitted ⇒ no filter." },
|
|
284
|
+
title: { type: "string", description: "Row title — required on add, changeable on update. Empty or whitespace-only is refused." },
|
|
285
|
+
board: { type: "string", description: "Owning board — a requirements document name: optional on add, unchanged when omitted on update, a filter on query." },
|
|
286
|
+
req_doc: { type: "string", description: "Requirements-document pointer: optional on add, unchanged when omitted on update." },
|
|
287
|
+
task_book: { type: "string", description: "Task-book pointer: optional on add, unchanged when omitted on update. Required while the row is 在途 or 待核销 — the ledger CHECK enforces it." },
|
|
288
|
+
evidence: { type: "string", description: "Evidence line: optional on add. On update and close, given ⇒ appended: an empty old value is replaced outright, a non-empty one is joined as `旧|新` (no spaces around the bar). A whitespace-only value is refused. Pass `evidenceReplace: true` to replace the whole range. Omitted on update ⇒ unchanged; omitted on close ⇒ the row's own value is judged." },
|
|
289
|
+
evidenceReplace: { type: "boolean", description: "Replace flag: pass it with `evidence` to replace the whole range. Omitted or false ⇒ append. Passed alone, with no new text ⇒ refused (update / close)." },
|
|
290
|
+
trigger: { type: "string", enum: ["归批", "条件", "认账不排期"], description: "Tech-todo trigger — one of the `enum` values: optional on add and update, a filter on query." },
|
|
291
|
+
resume_when: { type: "string", description: "Resume condition sentence: optional on add and update, for rows whose trigger is the conditional-resume kind. One sentence plus an optional anchor `@YYYY-MM-DD` or `@<event name>`. A blank or whitespace-only value is refused." },
|
|
292
|
+
id: { type: "number", description: "Row id — on update and close, pass exactly one of id and batch." },
|
|
293
|
+
batch: { type: "string", description: "Batch-record pointer — on update and close, pass exactly one of id and batch. Batch-level bulk: settles that batch's rows in one call. On update, with `status` every row is re-judged against the migration table; without it this is a plain field patch. On close only 待核销 rows are settled, and `status` may be omitted." },
|
|
294
|
+
status: { type: "string", enum: ["待讨论", "待设计", "在途", "待核销", "已核销", "已废弃"], description: "Status — one of the six. Single-row close requires it and accepts `已核销` or `已废弃`. With `batch`, close may omit it; given, it must be `已核销`. update migrates the row; query filters by it." },
|
|
295
|
+
executor: { type: "string", description: "Executor session id (update, optional — override the owner when taking a row over). The default follows the state transition: entering 待设计 or 在途 writes this session automatically. Leaving 在途, withdrawing or returning to 待讨论 clears it. 待核销 → 在途 always writes this session, and an explicit value does not override it." },
|
|
296
|
+
cursor: { type: "string", description: "Page cursor (query, optional): copy the previous page's tail line verbatim (form `<updated_at>|<id>`). A malformed cursor is refused — never silently treated as page one." },
|
|
248
297
|
},
|
|
249
298
|
additionalProperties: false,
|
|
250
299
|
}
|
|
@@ -252,26 +301,32 @@ 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: "Which operation to run — read-only: `query` or `count`." }, ...readProps }
|
|
316
|
+
: {
|
|
265
317
|
...UNION_PARAMETERS.properties,
|
|
266
318
|
action: {
|
|
267
319
|
...UNION_PARAMETERS.properties.action,
|
|
268
320
|
enum: actions,
|
|
269
321
|
description: writeFace
|
|
270
|
-
? "
|
|
271
|
-
: "
|
|
322
|
+
? "Which operation to run. The three write actions are assembled for the main agent only."
|
|
323
|
+
: "Which operation to run — read-only: `query` or `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)
|