@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
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-tools/doc-graph.mjs — `doc_graph` 工具面:入参校验 ∥ 动作分派 ∥ 文本回执。
|
|
3
|
+
*
|
|
4
|
+
* 设计单源 = `docs/core/design/DOC-GRAPH.md` §2.5(工具面)∥ §2.5.5(两变体契约)∥ §3(登记面);机制单源 =
|
|
5
|
+
* `../doc-graph.mjs`。工具形与同族(`ledger` ∥ `team_ledger` ∥ `doc_check`)同构:**一个工具 + `action` 枚举**
|
|
6
|
+
* 四种问法(`scan` 扫 ∥ `forward` 正向 ∥ `reverse` 反向 ∥ `chain` 链路)——`doc_check` 那边是「判决」的两种问法,
|
|
7
|
+
* 两者判的东西不同,故不并成一个工具(KD-2)。
|
|
8
|
+
*
|
|
9
|
+
* **两变体同体、动作集一处字面**(构造单源 = `docs/core/design/AGENT-LOOP-SUBAGENT.md` §6.60.2 ②):参数化工厂
|
|
10
|
+
* `makeDocGraphTool(actions, { readonly, docName, unscanned })` 产出两形——全量 `docGraphTool`(四动作,depth-0 主 agent 段)
|
|
11
|
+
* ∥ 只读 `docGraphReadTool`(三动作、无 `scan`,全部 depth>0 角色段与 advisor 面)。动作集一处字面 `ALL_ACTIONS`、
|
|
12
|
+
* 只读集由它派生 ⇒ schema 的 `enum` ∥ execute 的护栏 ∥ 拒文里的取值集三处取同一个 `actions` 参数,变体不写第二份
|
|
13
|
+
* 字面对象(先例 = `../ledger-tools.mjs` 的 `makeLedgerTool`)。描述从同一 `actions` 生成(`ACTION_CLAUSES`)、
|
|
14
|
+
* 各自一份描述档;未建图策略(`unscanned`)由只读变体传 `readonly-empty`(TOOLS.md §6.29 ③)。
|
|
15
|
+
*
|
|
16
|
+
* **子代理段为什么不给 `scan`**:`scan` 把边落进台账库(`doc_edges` 表)——一次显式动作,没有常驻进程、没有 watch
|
|
17
|
+
* (需求 §3);而 depth>0 段拿到的台账是**只读**变体 ⇒ 同一段里没有可依的写面,多个子代理并发扫还会重写同一张共享
|
|
18
|
+
* 边表(D-DT1)。父侧扫一次、子代理查同一份库。只读性按 action 判(`isReadonlyAction`,与 `ledger` 同形):三个
|
|
19
|
+
* 查询走只读句柄、免审批;`scan` 走写面。
|
|
20
|
+
*
|
|
21
|
+
* **参数零默认**(设计 §2.5):`target` 恒必填;`forward` ∥ `reverse` ∥ `chain` 的 `node`、`chain` 的 `depth` 缺一即拒
|
|
22
|
+
* 并**点名**那一个——给默认值就是替调用方做决定。两个可选参数(`scan` 的 `scope` ∥ 三个读动作的 `kind`)缺席的含义
|
|
23
|
+
* 都由回执首行印出来(`全仓` / `范围 K 档` ∥ 本次生效的 kind 集合),不靠调用方记。
|
|
24
|
+
* `kind` 的**闭集校验住在核里**(`doc-graph.mjs` 的 `kindFilterOf`,闭集单源 = `ledger-db.mjs` 的 `DOC_EDGE_KINDS`):
|
|
25
|
+
* 本档只判形(必为字符串),闭集外拒并点名那个值由核做——一处校验,两个入口(工具 ∥ 直调核)。
|
|
26
|
+
*
|
|
27
|
+
* W8 契约②:本档只**动态** import `../doc-graph.mjs`(它自己再动态 import 台账库)——端壳静态闭包零 `node:sqlite`。
|
|
28
|
+
* 描述外置:模型可见文本单点 = `tool-docs/{doc_graph,doc_graph-read}.md`(`DESC` 单一解析面)——
|
|
29
|
+
* 两变体各一份描述档(TOOLS.md §6.29「描述面也分两份」:只读变体的字面里没有它执行不到的 `scan` 段)。
|
|
30
|
+
*/
|
|
31
|
+
import { isAbsolute, resolve } from "node:path"
|
|
32
|
+
import { DESC } from "../tools/shared.mjs"
|
|
33
|
+
|
|
34
|
+
/** `target` 归一:相对路径按会话锚解析(锚缺位 + 相对形 ⇒ 拒、点名锚——不落 `process.cwd()`)。 */
|
|
35
|
+
function targetOf(args, ctx) {
|
|
36
|
+
const anchor = ctx?.agent?.cwd ?? ctx?.cwd
|
|
37
|
+
const given = args?.target
|
|
38
|
+
if (typeof given !== "string" || given.trim() === "") {
|
|
39
|
+
throw new Error("doc_graph:target 缺失(必填)——请给项目根(带 PROJECT-MANIFEST.json 的那个目录)")
|
|
40
|
+
}
|
|
41
|
+
if (!isAbsolute(given) && !anchor) {
|
|
42
|
+
throw new Error("doc_graph:会话锚不可用(`ctx.agent.cwd` / `ctx.cwd` 都空)——请把 target 写成绝对路径;相对 target 没有基根,本工具不落 `process.cwd()`")
|
|
43
|
+
}
|
|
44
|
+
return resolve(anchor ?? ".", given)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 全量动作集——本档唯一字面。 */
|
|
48
|
+
const ALL_ACTIONS = ["scan", "forward", "reverse", "chain"]
|
|
49
|
+
/** 只读动作集——由上一行派生,不写第二份字面(`scan` 归主 agent,见文件头)。 */
|
|
50
|
+
const READ_ACTIONS = ALL_ACTIONS.filter((a) => a !== "scan")
|
|
51
|
+
|
|
52
|
+
/** 逐动作的一句话(`action` 参数描述的唯一措辞来源:描述从**本变体的动作集**生成——只读变体的字面
|
|
53
|
+
* 因此不含 `scan`,而两变体的措辞只有这一份,漂移由「同一张表同时派生动作与描述」挡住)。 */
|
|
54
|
+
const ACTION_CLAUSES = {
|
|
55
|
+
scan: "collects the edges into the ledger database (one explicit pass, no background index)",
|
|
56
|
+
forward: "lists the edges leaving a node",
|
|
57
|
+
reverse: "lists the edges pointing at a node",
|
|
58
|
+
chain: "walks outward from a node layer by layer, one layer per edge count",
|
|
59
|
+
}
|
|
60
|
+
/** `action` 参数描述(按本变体动作集生成;全量四个动作时与旧字面逐字相同)。 */
|
|
61
|
+
const actionDescOf = (actions) => `The question to ask: ${actions.map((a) => `\`${a}\` ${ACTION_CLAUSES[a]}`).join(" · ")}.`
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 工具工厂:两个装配面同体,只有 `actions` ∥ `readonly` ∥ `docName` ∥ `unscanned` 四个参数不同。
|
|
65
|
+
* @param {string[]} actions — 本变体的 action 闭集(schema `enum` ∥ execute 护栏 ∥ 拒文取值集三处同取本参数)。
|
|
66
|
+
* @param {{readonly?: boolean, docName?: string, unscanned?: 'throw'|'readonly-empty'}} [opts] — `readonly` 缺省 false
|
|
67
|
+
* (全量);`docName` = 该变体的描述档名(`tool-docs/<docName>.md`);`unscanned` = 未建图策略(B5:
|
|
68
|
+
* 只读变体传 `readonly-empty`,全量保持抛既有指引)。
|
|
69
|
+
*/
|
|
70
|
+
function makeDocGraphTool(actions, { readonly = false, docName = "doc_graph", unscanned = "throw" } = {}) {
|
|
71
|
+
const readOnlyVariant = readonly
|
|
72
|
+
return {
|
|
73
|
+
name: "doc_graph",
|
|
74
|
+
description: DESC(docName),
|
|
75
|
+
parameters: {
|
|
76
|
+
type: "object",
|
|
77
|
+
required: ["action"],
|
|
78
|
+
properties: {
|
|
79
|
+
action: { type: "string", enum: actions, description: actionDescOf(actions) },
|
|
80
|
+
target: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "The project root this call is about (the directory carrying PROJECT-MANIFEST.json; a relative path resolves against the session anchor). Required for every action — there is no default: the session anchor is the base for a relative path, never a substitute for `target`.",
|
|
83
|
+
},
|
|
84
|
+
node: {
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "The node to start from, written in the identity form: `req:F16` · `doc:<path>` · `doc:<path>#<section>` · `case:CLI 41-1` · `symbol:editTool` · `ledger:#2236`. Required for forward / reverse / chain — a missing node is refused by name, never answered with an empty result.",
|
|
87
|
+
},
|
|
88
|
+
depth: {
|
|
89
|
+
type: "number",
|
|
90
|
+
description: "How many edge steps to walk (`chain` only, required there): depth 1 = the immediate neighbours, depth 2 = their neighbours, and so on. Hops are counted in edges, not nodes. There is no default — a missing depth is refused by name.",
|
|
91
|
+
},
|
|
92
|
+
// `scope` 只服务 `scan` ⇒ 只存在全量 schema(B6:只读角色面不出现它执行不了的参数)
|
|
93
|
+
...(readOnlyVariant ? {} : {
|
|
94
|
+
scope: {
|
|
95
|
+
type: "array",
|
|
96
|
+
items: { type: "string" },
|
|
97
|
+
description: "`scan` only, optional: re-scan just these documents (project-root-relative or absolute). Their edges are deleted and rebuilt; every other document's edges stay untouched. Omit it to scan the whole repository — the receipt's first field always says which of the two it did (`全仓` / `范围 K 档`).",
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
kind: {
|
|
101
|
+
type: "string",
|
|
102
|
+
description: "`forward` / `reverse` / `chain` only, optional: a comma-separated subset of edge kinds to read — `cites`, `cites-req`, `mentions-case`, `case-file`, `cites-symbol`, `imports`. The edges are filtered before sorting and layering, so a narrowed run is a complete run, not a few lines pulled out of a big receipt. Omit it to read every kind (ledger projections included); the receipt's first line always prints the set in force. A value outside that closed set is refused by name — it is never treated as an empty set.",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
additionalProperties: false,
|
|
106
|
+
},
|
|
107
|
+
readonly,
|
|
108
|
+
/** 只读性按 action(先例 = `ledger` 的 `isReadonlyAction`):三查询免审批,`scan` 走侧效门。
|
|
109
|
+
* 只读变体的动作集不含 `scan` ⇒ 它恒为真,与 `readonly: true` 同向,不需要第二份实现。 */
|
|
110
|
+
isReadonlyAction(args) { return args?.action !== "scan" },
|
|
111
|
+
async execute(args, ctx) {
|
|
112
|
+
const action = args?.action
|
|
113
|
+
// schema 的 enum 是建议性的(provider 不强制)——枚举外的值必须由入口拒,且只印本变体的取值集。
|
|
114
|
+
if (!actions.includes(action)) {
|
|
115
|
+
throw new Error(`doc_graph:action 非法(${JSON.stringify(action ?? null)})——取值 ∈ {${actions.join(", ")}}`)
|
|
116
|
+
}
|
|
117
|
+
const target = targetOf(args, ctx)
|
|
118
|
+
const boundary = ctx?.agent?.cwd ?? ctx?.cwd
|
|
119
|
+
const kindArg = args?.kind
|
|
120
|
+
if (kindArg !== undefined && typeof kindArg !== "string") {
|
|
121
|
+
throw new Error(`doc_graph:kind 须为逗号分隔的字符串(收到 ${typeof kindArg})——如 "cites,imports";闭集外拒并点名那一个值(由核校验)`)
|
|
122
|
+
}
|
|
123
|
+
const mod = await import("../doc-graph.mjs")
|
|
124
|
+
if (action === "scan") {
|
|
125
|
+
const scope = args?.scope
|
|
126
|
+
if (scope !== undefined && !Array.isArray(scope)) {
|
|
127
|
+
throw new Error(`doc_graph:scope 须为路径数组(收到 ${typeof scope})——只重扫几档就给 ["<path>"];给空数组等号于全仓`)
|
|
128
|
+
}
|
|
129
|
+
return mod.scanDocGraph({ target, scope, boundary })
|
|
130
|
+
}
|
|
131
|
+
return mod.queryDocGraph({ action, target, node: args?.node, depth: args?.depth, kind: kindArg, boundary, unscanned })
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 全量变体(depth-0 主 agent 段):四动作,含 `scan`;未建图仍抛既有指引(逐字不变)。 */
|
|
137
|
+
export const docGraphTool = makeDocGraphTool(ALL_ACTIONS, { readonly: false })
|
|
138
|
+
/** 只读变体(全部 depth>0 角色段与 advisor 面):三动作、无 `scan`;同名不塌缩——两变体互斥装配。
|
|
139
|
+
* 未建图返可读空态(不要求父代跑 scan、不隐式写共享边表)。 */
|
|
140
|
+
export const docGraphReadTool = makeDocGraphTool(READ_ACTIONS, { readonly: true, docName: "doc_graph-read", unscanned: "readonly-empty" })
|
package/agent-tools/eng.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import { ENG_ON_REMINDER, ENG_OFF_REMINDER } from "../agent.mjs"
|
|
|
19
19
|
import { clearPlanMode } from "./plan.mjs"
|
|
20
20
|
import { purgeExpiredDesignTokens } from "../token-ttl.mjs"
|
|
21
21
|
import { resolveEngineeringManifest } from "../manifest.mjs"
|
|
22
|
+
import { resolveWorkMode, setConfigWorkMode } from "../config.mjs"
|
|
22
23
|
// 描述面 = `tool-docs/eng.md`(#15 描述外置统一——DESC 单一解析面,与内置工具族同径)
|
|
23
24
|
import { DESC } from "../tools/shared.mjs"
|
|
24
25
|
|
|
@@ -26,7 +27,7 @@ import { DESC } from "../tools/shared.mjs"
|
|
|
26
27
|
/**
|
|
27
28
|
* 工程模式切换通知注入位(**缺省不覆盖** = no-op——CLI 语义(只进会话),零行为变;端装配层
|
|
28
29
|
* 可覆盖为本端镜像写盘 / 面板提示)。核内零端名分支(契约 5——本档只认 `onToggle` 函数名)。
|
|
29
|
-
* 契约:`onToggle(
|
|
30
|
+
* 契约:`onToggle(mode, ctx) → string | null | undefined | Promise<同>`——非空字符串 =
|
|
30
31
|
* 追加到结果文案尾(如镜像写入碰撞提示);其余值 = 无提示。调用时机 = 状态翻转后(观察新态)。
|
|
31
32
|
*/
|
|
32
33
|
let injectedMirror = null
|
|
@@ -37,8 +38,8 @@ export function configureEngMirror(impl) {
|
|
|
37
38
|
export function resetEngMirror() { injectedMirror = null }
|
|
38
39
|
|
|
39
40
|
/** 镜像通知串(缺省空串;仅非空字符串追加)。 */
|
|
40
|
-
async function mirrorNotice(
|
|
41
|
-
const out = await injectedMirror?.onToggle(
|
|
41
|
+
async function mirrorNotice(mode, ctx) {
|
|
42
|
+
const out = await injectedMirror?.onToggle(mode, ctx)
|
|
42
43
|
return typeof out === "string" && out.length > 0 ? ` ${out}` : ""
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -56,7 +57,7 @@ export const engTool = {
|
|
|
56
57
|
async execute(args, ctx) {
|
|
57
58
|
ctx.agent.config.agent ??= {}
|
|
58
59
|
if (args.action === "exit") {
|
|
59
|
-
ctx.agent.config
|
|
60
|
+
setConfigWorkMode(ctx.agent.config, "normal")
|
|
60
61
|
// R16 (F-R16a): OFF 不清 token——有效 token 跨模式存活(设计评审过的产物不因
|
|
61
62
|
// 开关重复烧)。过期清理跑在另外三处(恢复过滤 / 开模式 / spawn 门禁拒)。
|
|
62
63
|
ctx.agent._advisorRound = 0 // reset convergence budget
|
|
@@ -65,13 +66,13 @@ export const engTool = {
|
|
|
65
66
|
ctx.agent._lastEngState = false
|
|
66
67
|
ctx.agent._pendingReminders = ctx.agent._pendingReminders ?? []
|
|
67
68
|
ctx.agent._pendingReminders.push(ENG_OFF_REMINDER)
|
|
68
|
-
return "Engineering mode exited. Standard discipline now applies. You may edit files directly." + await mirrorNotice(
|
|
69
|
+
return "Engineering mode exited. Standard discipline now applies. You may edit files directly." + await mirrorNotice(ctx.agent.config.agent.mode, ctx)
|
|
69
70
|
}
|
|
70
71
|
if (args.action === "enter") {
|
|
71
72
|
// Idempotent enter (v2 2026-08-25): already in engineering mode → pure no-op
|
|
72
73
|
// (cleanup only runs on a real off→on transition — T-R16c precondition: first
|
|
73
74
|
// exit/OFF, then enter; an already-on enter must not touch tokens at all).
|
|
74
|
-
if (ctx.agent.config.agent
|
|
75
|
+
if (resolveWorkMode(ctx.agent.config.agent) === "engineering") {
|
|
75
76
|
return "Engineering mode already active. Existing design tokens stay valid."
|
|
76
77
|
}
|
|
77
78
|
// #41 先判后翻(MANIFEST.md §2.8 F2 / KD-M1-21):判据 = 入口决策树**单源**
|
|
@@ -80,12 +81,12 @@ export const engTool = {
|
|
|
80
81
|
// **零副作用**(不清 token / 不重置 _advisorRuns / 不入列 ENG_ON_REMINDER /
|
|
81
82
|
// 不动 _lastEngState / 不触镜像缝);准 ⇒ 缺档格就地建档(writer:'main')+
|
|
82
83
|
// agent.manifest ← 结果(翻转面唯一赋值点——相位行当回合起活,§2.8 F2 放行行)。
|
|
83
|
-
const r = resolveEngineeringManifest(ctx.agent.cwd ?? ctx.cwd
|
|
84
|
+
const r = resolveEngineeringManifest(ctx.agent.cwd ?? ctx.cwd, { writer: "main" })
|
|
84
85
|
if (!r.ok && r.code !== "workspace") {
|
|
85
86
|
return `Error: cannot enter engineering mode — ${r.message} (mode unchanged)`
|
|
86
87
|
}
|
|
87
88
|
ctx.agent.manifest = r.ok ? r.manifest : null // 工作区放行 ⇒ 零附着(显式置 null——§2.8 F2 放行行)
|
|
88
|
-
ctx.agent.config
|
|
89
|
+
setConfigWorkMode(ctx.agent.config, "engineering")
|
|
89
90
|
// FR31 ③ / KD10(翻转点①):工程模式 ⇒ planMode 恒 false——中途开模式时清残留
|
|
90
91
|
//(planMode 位 + reminder 计数 + 未注入的 plan 提示语),半状态(工程纪律 × plan 只读)不产生。
|
|
91
92
|
clearPlanMode(ctx.agent)
|
|
@@ -100,7 +101,7 @@ export const engTool = {
|
|
|
100
101
|
if (cleared > 0) {
|
|
101
102
|
msg += ` Cleared ${cleared} expired design token${cleared === 1 ? "" : "s"} — 清 ${cleared} 个过期 token,有效 token 保留(TTL 内不重评)。`
|
|
102
103
|
}
|
|
103
|
-
msg += await mirrorNotice(
|
|
104
|
+
msg += await mirrorNotice(ctx.agent.config.agent.mode, ctx)
|
|
104
105
|
return msg
|
|
105
106
|
}
|
|
106
107
|
return "Invalid action: expected 'enter' or 'exit'"
|
|
@@ -62,7 +62,7 @@ function overlapPaths(parent, launchSeq, childTouched) {
|
|
|
62
62
|
const sinceKeys = new Set(since.map(key))
|
|
63
63
|
const hits = childTouched.filter((p) => sinceKeys.has(key(p)))
|
|
64
64
|
// relative display form (touchedFilesNote precedent)
|
|
65
|
-
const cwd = parent?.cwd
|
|
65
|
+
const cwd = parent?.cwd
|
|
66
66
|
return hits.map((p) => {
|
|
67
67
|
const r = relative(cwd, p)
|
|
68
68
|
return r && !r.startsWith("..") && !isAbsolute(r) ? r : p
|
|
@@ -74,7 +74,7 @@ function childTouchedDisplay(child, cwd) {
|
|
|
74
74
|
const touched = child?._touchedFiles ?? []
|
|
75
75
|
if (touched.length === 0) return "(none recorded)"
|
|
76
76
|
const shown = touched.map((f) => {
|
|
77
|
-
const r = relative(cwd
|
|
77
|
+
const r = relative(cwd, f)
|
|
78
78
|
return r && !r.startsWith("..") && !isAbsolute(r) ? r : f
|
|
79
79
|
})
|
|
80
80
|
return shown.join(", ")
|
|
@@ -85,7 +85,7 @@ function touchedFilesNote(child, cwd) {
|
|
|
85
85
|
const touched = child?._touchedFiles ?? []
|
|
86
86
|
if (touched.length === 0) return ""
|
|
87
87
|
const shown = touched.map((f) => {
|
|
88
|
-
const r = relative(cwd
|
|
88
|
+
const r = relative(cwd, f)
|
|
89
89
|
return r && !r.startsWith("..") && !isAbsolute(r) ? r : f
|
|
90
90
|
})
|
|
91
91
|
return `\nTouched files: ${shown.join(", ")}`
|
|
@@ -152,7 +152,7 @@ export function launchEscalateAsync(parent, ctx, launch) {
|
|
|
152
152
|
const { task, provider, tag, effortNote } = launch
|
|
153
153
|
parent._asyncSubagents ??= new Map()
|
|
154
154
|
parent._asyncQueue ??= []
|
|
155
|
-
// Async id allocation (AGENT-LOOP-SUBAGENT.md §6.7.3
|
|
155
|
+
// Async id allocation (AGENT-LOOP-SUBAGENT.md §6.7.3 precedent): reserve the relay
|
|
156
156
|
// counter at launch — the returned id stays stable while the entry sits queued.
|
|
157
157
|
// The [model] token (TUI block creation) is DEFERRED to actual start so queued
|
|
158
158
|
// flights don't paint an empty panel block (subagent-parity).
|
|
@@ -228,7 +228,7 @@ export function launchEscalateAsync(parent, ctx, launch) {
|
|
|
228
228
|
signal: entry.controller.signal,
|
|
229
229
|
// §2.5 #78 并入:escalate 子代理输出流式(VSC subagent-escalate-async 同款豁免)。
|
|
230
230
|
streamOutput: true,
|
|
231
|
-
// SUBAGENT-OBSERVE-SEND
|
|
231
|
+
// SUBAGENT-OBSERVE-SEND 缺口补配(`docs/core/design/TURN-CAP-CONTINUE.md` §3.1「兑现后的消费路径」):send 注入队列
|
|
232
232
|
// 回合边界消费(否则续段文本静默丢弃)。空队列 no-op。
|
|
233
233
|
consumeInjected: (ag) => { drainInjectedQueue(entry, ag ?? child) },
|
|
234
234
|
}
|
package/agent-tools/manifest.mjs
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* - `write` ⇒ **点改**:读现档 → 设节点 → 落盘(`writeManifest` 内先 `validateManifest`——
|
|
12
12
|
* 编辑结果非法 ⇒ 拒 + 盘零变);**缺档 ⇒ 拒** + 引导 `init`(写不建档)。
|
|
13
13
|
*
|
|
14
|
-
* 写面白名单(判据单源 = `MANIFEST_SCHEMA`——钉死谓词):**
|
|
15
|
-
* 父键者(`version` / `phase` / `codePaths` 整键)+ `nestedKeys` 子键(`docRoot.*`
|
|
14
|
+
* 写面白名单(判据单源 = `MANIFEST_SCHEMA`——钉死谓词):**16 个可写节点** = `keys` 中**非** `nestedKeys`
|
|
15
|
+
* 父键者(`version` / `phase` / `codePaths` 整键)+ `nestedKeys` 子键(`docRoot.*` 六子键 / `index.*` 七子键);
|
|
16
16
|
* **两族整键写(传整个对象)⇒ 拒**;白名单外 ⇒ 拒(拼写保护——未知键写盘 = 静默死键,KD-M1-36 问题本体)。
|
|
17
17
|
* `value` 解析 = 同款口径 `settings.mjs` 的 `parseValue`(先 `JSON.parse`,失败取字面串;`"null"` ⇒ `null`
|
|
18
18
|
* ——`docRoot.*` 的「本面无」,KD-M1-37)。
|
|
@@ -22,7 +22,14 @@
|
|
|
22
22
|
* 工作区塌缩 `null`(**回落发生在调用方 `writeRoot`,非本函数**)⇒ 写 / 建两动作**不得**直用。
|
|
23
23
|
*
|
|
24
24
|
* 写路径复用(零新写路径):落盘恒经 `writeManifest` / `initManifest`——`writer` 恒显式 `'main'`
|
|
25
|
-
* (缺省 `'subagent'` = 写门 fail-closed 缺省,KD-M1-3 / AC-M1-5
|
|
25
|
+
* (缺省 `'subagent'` = 写门 fail-closed 缺省,KD-M1-3 / AC-M1-5 零改)。**这里的「写门」= `writer` 身份闸**,
|
|
26
|
+
* 与下面那道不是同一道。
|
|
27
|
+
*
|
|
28
|
+
* **不在笔-账绑定写锁的入口集**(2026-11-10 整把出集批 · 决策 44):`read` ∥ `init` ∥ `write` 三动作一律不要
|
|
29
|
+
* 台账号、不要项目声明——本工具写的这份档正是写锁的输入(取根 ∥ 读 `index.writableRepos` 判跨仓),把写它
|
|
30
|
+
* 也放在门后就成环(档缺失建不出项目、档坏修不回来)。机制与理由单源 = `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md`
|
|
31
|
+
* §2.3「`manifest` 不进写门」;该出口因此不在 `thincoder-core/agent/write-gate-ledger.mjs` 的入口集里,
|
|
32
|
+
* `ledger` ∥ `project` 两格也不在本工具的 `parameters.properties`(名字只为被读的地方存在)。
|
|
26
33
|
*
|
|
27
34
|
* 报告面随动(KD-M1-40):本工具**不写** `agent.manifest`(第二值源否——工具目标可为非锚项目)——
|
|
28
35
|
* 写盘 = 盘面变化,情境行经既有 ③b mtime 门控于下回合采纳(`agent/setup-reminders.mjs`)。
|
|
@@ -37,7 +44,7 @@
|
|
|
37
44
|
* (`readonly: false` = 动作级分类面,只读性归 `dispatch-gates` 的 `read` 判定)。
|
|
38
45
|
*/
|
|
39
46
|
import { existsSync } from "node:fs"
|
|
40
|
-
import { join, resolve } from "node:path"
|
|
47
|
+
import { isAbsolute, join, resolve } from "node:path"
|
|
41
48
|
import { MANIFEST_REL, MANIFEST_SCHEMA, initManifest, projectRootView, projectView, readManifest, writeManifest } from "../manifest.mjs"
|
|
42
49
|
import { DESC } from "../tools/shared.mjs"
|
|
43
50
|
import { clearDeclarationCache } from "../conventions.mjs" // #1367 面⑦:写档成功 ⇒ 缓存失效(fix 轮接线)
|
|
@@ -47,11 +54,23 @@ function refuse(action, reason) {
|
|
|
47
54
|
return new Error(`manifest ${action}: refused — ${reason}`)
|
|
48
55
|
}
|
|
49
56
|
|
|
50
|
-
/** `target`
|
|
51
|
-
*
|
|
52
|
-
function resolveTarget(args, ctx) {
|
|
53
|
-
const base = ctx?.agent?.cwd ?? ctx?.cwd
|
|
54
|
-
|
|
57
|
+
/** `target` 解析:`target` 必填;`base` 只作相对形基根。缺 ∥ 空串 ∥ `null` ⇒ 抛、报文点名 `target`,零判定
|
|
58
|
+
* (不拿锚替调用方选根)。`base` = `ctx.agent.cwd ?? ctx.cwd`(KD-9);绝对形原样。 */
|
|
59
|
+
function resolveTarget(action, args, ctx) {
|
|
60
|
+
const base = ctx?.agent?.cwd ?? ctx?.cwd
|
|
61
|
+
const given = args?.target
|
|
62
|
+
if (typeof given !== "string" || given.trim() === "") {
|
|
63
|
+
throw new Error(`manifest ${action}: target is required — pass the project root or directory you mean (an absolute path, or a path relative to the session anchor); there is no default.`)
|
|
64
|
+
}
|
|
65
|
+
// 锚只作**相对形**的基根(KD-9):锚缺位 + 相对形 ⇒ 拒、点名锚——不许落 `process.cwd()`
|
|
66
|
+
// (同 `thincoder-core/agent-tools/doc-check.mjs` 的同支,全批共用契约)。
|
|
67
|
+
if (!base) {
|
|
68
|
+
if (!isAbsolute(given)) {
|
|
69
|
+
throw new Error(`manifest ${action}: target is required as an absolute path — no session anchor is available (\`ctx.agent.cwd\` / \`ctx.cwd\` both empty), so a relative \`target\` has no base to resolve against.`)
|
|
70
|
+
}
|
|
71
|
+
return resolve(given)
|
|
72
|
+
}
|
|
73
|
+
return resolve(base, given)
|
|
55
74
|
}
|
|
56
75
|
|
|
57
76
|
/** 写面白名单谓词(**钉死**——设计 §2.10):点分路径恰两形——
|
|
@@ -131,11 +150,11 @@ export const manifestTool = {
|
|
|
131
150
|
type: "object",
|
|
132
151
|
properties: {
|
|
133
152
|
action: { type: "string", enum: ["read", "init", "write"], description: "read — current manifest + validation state (five-state anchor, never throws); init — create the default manifest when missing (refused when one already exists); write — point-edit one node (key + value) of an existing manifest" },
|
|
134
|
-
target: { type: "string", description: "
|
|
153
|
+
target: { type: "string", description: "Required — pass the project root or directory you mean (relative paths resolve against the session anchor; a workspace target is reported with its project list)" },
|
|
135
154
|
key: { type: "string", description: "(write) Dot path of the node to set — version / phase / codePaths, or a sub-key of docRoot / index (e.g. docRoot.design / index.publicRepos); whole-object writes of those two families are refused", },
|
|
136
155
|
value: { type: "string", description: "(write) New value — parsed as JSON first (null / true / 5 / [\"a\"]), otherwise kept as a literal string; \"null\" is the explicit no-such-face for docRoot.<key>" },
|
|
137
156
|
},
|
|
138
|
-
required: ["action"],
|
|
157
|
+
required: ["action", "target"],
|
|
139
158
|
},
|
|
140
159
|
readonly: false, // 动作级分类(dispatch-gates `isReadonlyAction`):read = 只读类;init / write 保持侧效门
|
|
141
160
|
async execute(args, ctx) {
|
|
@@ -143,7 +162,7 @@ export const manifestTool = {
|
|
|
143
162
|
if (!["read", "init", "write"].includes(action)) {
|
|
144
163
|
throw new Error(`manifest: action must be one of read/init/write — got ${JSON.stringify(action)}`)
|
|
145
164
|
}
|
|
146
|
-
const target = resolveTarget(args, ctx)
|
|
165
|
+
const target = resolveTarget(action, args, ctx)
|
|
147
166
|
|
|
148
167
|
if (action === "read") return readAction(target)
|
|
149
168
|
|
|
@@ -217,15 +236,15 @@ export const manifestReadTool = {
|
|
|
217
236
|
type: "object",
|
|
218
237
|
properties: {
|
|
219
238
|
action: { type: "string", enum: ["read"], description: "read — current manifest + validation state (five-state anchor, never throws)" },
|
|
220
|
-
target: { type: "string", description: "
|
|
239
|
+
target: { type: "string", description: "Required — pass the project root or directory you mean (relative paths resolve against the session anchor; a workspace target is reported with its project list)" },
|
|
221
240
|
},
|
|
222
|
-
required: ["action"],
|
|
241
|
+
required: ["action", "target"],
|
|
223
242
|
},
|
|
224
243
|
readonly: true,
|
|
225
244
|
async execute(args, ctx) {
|
|
226
245
|
if (args?.action !== "read") {
|
|
227
246
|
throw new Error(`manifest read: refused — this read-only variant exposes only action=read (got ${JSON.stringify(args?.action)})`)
|
|
228
247
|
}
|
|
229
|
-
return readAction(resolveTarget(args, ctx), { canInit: false })
|
|
248
|
+
return readAction(resolveTarget("read", args, ctx), { canInit: false })
|
|
230
249
|
},
|
|
231
250
|
}
|
|
@@ -19,9 +19,11 @@
|
|
|
19
19
|
*
|
|
20
20
|
* Returns a JSON array in chronological order. Every message without ts comes
|
|
21
21
|
* back as ts:null and can never match a time window (legacy sessions). Content
|
|
22
|
-
* is truncated to ~500 chars with an explicit marker
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* is truncated to ~500 chars with an explicit marker that states what is actually
|
|
23
|
+
* retrievable: for `tool` results the session file stores only those first 500
|
|
24
|
+
* chars (re-run the tool for more), for `user` / `assistant` text the full text
|
|
25
|
+
* is in the session file. assistant tool_calls come back as [{name, arguments}]
|
|
26
|
+
* with the stored argument string capped at 300 chars (matches the stored precision).
|
|
25
27
|
*
|
|
26
28
|
* Cross-session (SESSION.md §6.13 D-R19a + §6.19 D-SE47 — 索引优先 + 主存回落):
|
|
27
29
|
* path = a session file path (absolute, or relative to the project cwd) → when the derived
|
|
@@ -78,16 +80,21 @@ function messageText(m) {
|
|
|
78
80
|
return ""
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
/** Truncate long content (~500 chars) with an explicit marker
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
|
|
83
|
+
/** Truncate long content (~500 chars) with an explicit marker whose wording is **true for the role**
|
|
84
|
+
* (`SESSION.md` §5 取回面标记条): on the human line a `tool` result is stored as the first 500 chars
|
|
85
|
+
* (`slimForDisplay`), so the session file holds no more than what already came back — “full text is in
|
|
86
|
+
* the session file” would be a promise nobody can keep, and a model that believes it stops re-running
|
|
87
|
+
* the tool. `user` / `assistant` bodies are never slimmed, so that promise still holds there.
|
|
88
|
+
* The cut never splits a UTF-16 surrogate pair (emoji etc.) — `text-budget.mjs` `safeSliceUTF16` same rule. */
|
|
89
|
+
function truncateContent(text, role) {
|
|
86
90
|
const t = String(text ?? "")
|
|
87
91
|
if (t.length <= CONTENT_CAP) return t
|
|
88
92
|
let end = CONTENT_CAP
|
|
89
93
|
if (t.charCodeAt(end - 1) >= 0xd800 && t.charCodeAt(end - 1) <= 0xdbff) end-- // high surrogate at the cut → step back
|
|
90
|
-
|
|
94
|
+
const where = role === "tool"
|
|
95
|
+
? "the session file keeps only the first 500 chars of a tool result — re-run the tool if you need it"
|
|
96
|
+
: "full text is in the session file"
|
|
97
|
+
return t.slice(0, end) + `\n… (truncated: ${t.length - end} chars — ${where})`
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
/** Tool name across both stored shapes ({function:{name}} and flat {name}). */
|
|
@@ -124,7 +131,7 @@ function toEntry(m) {
|
|
|
124
131
|
}
|
|
125
132
|
if (m.name !== undefined) entry.name = m.name
|
|
126
133
|
if (m.tool_call_id !== undefined) entry.tool_call_id = m.tool_call_id
|
|
127
|
-
entry.content = truncateContent(messageText(m))
|
|
134
|
+
entry.content = truncateContent(messageText(m), m.role)
|
|
128
135
|
if (Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
|
|
129
136
|
const calls = toolCallEntries(m.tool_calls)
|
|
130
137
|
if (calls.length > 0) entry.tool_calls = calls
|
|
@@ -190,7 +197,7 @@ function exceedsScanMax(file) {
|
|
|
190
197
|
|
|
191
198
|
/** 跨会话深查(回落面):单个槽文件,同 filter 面(§6.13 D-R19a——两道护栏逐字保留)。 */
|
|
192
199
|
function querySessionFile(pathArg, { role, kwRe, tool, since, until, direction, limit }, baseCwd) {
|
|
193
|
-
const file = isAbsolute(pathArg) ? pathArg : resolve(baseCwd
|
|
200
|
+
const file = isAbsolute(pathArg) ? pathArg : resolve(baseCwd, pathArg)
|
|
194
201
|
if (!existsSync(file)) return `Error: session file not found: ${file}`
|
|
195
202
|
if (exceedsScanMax(file)) return TOO_LARGE_ERROR
|
|
196
203
|
let text
|
|
@@ -221,7 +228,7 @@ function querySessionFile(pathArg, { role, kwRe, tool, since, until, direction,
|
|
|
221
228
|
* ——评审 #2:摘要必须含寻址字段——模型第二步深查 = 复制行内文件路径重调 path=)。
|
|
222
229
|
* 计数不可得 = `null` ⇒ `messages: —`(§6.25 判据句 4——禁显示数值 0:真 0 与未知可分)。 */
|
|
223
230
|
function discoverCwd(raw, baseCwd) {
|
|
224
|
-
const dir = resolve(baseCwd
|
|
231
|
+
const dir = resolve(baseCwd, raw)
|
|
225
232
|
let st = null
|
|
226
233
|
try {
|
|
227
234
|
st = statSync(dir)
|
|
@@ -259,7 +266,7 @@ function indexEntry(r) {
|
|
|
259
266
|
const entry = { ts: typeof r.ts === "number" ? r.ts : null, role: r.role ?? null }
|
|
260
267
|
if (r.name !== undefined && r.name !== null) entry.name = r.name
|
|
261
268
|
if (r.tool_call_id !== undefined && r.tool_call_id !== null) entry.tool_call_id = r.tool_call_id
|
|
262
|
-
entry.content = truncateContent(r.content ?? "")
|
|
269
|
+
entry.content = truncateContent(r.content ?? "", r.role)
|
|
263
270
|
if (Array.isArray(r.tool_calls) && r.tool_calls.length > 0) entry.tool_calls = r.tool_calls
|
|
264
271
|
return entry
|
|
265
272
|
}
|
|
@@ -308,6 +315,100 @@ async function queryAllSessions(filters, current = null) {
|
|
|
308
315
|
} finally { if (db) db.close() }
|
|
309
316
|
}
|
|
310
317
|
|
|
318
|
+
// ─── 受限父历史(TOOLS.md §6.29 ④ · B8)─────────────────────────────────────────
|
|
319
|
+
/** 变体 `limit` 上限(设计档:必传且上限 50——读的是父会话的一个批窗口,不是整本历史)。 */
|
|
320
|
+
export const BATCH_HISTORY_LIMIT_MAX = 50
|
|
321
|
+
|
|
322
|
+
/** 批档比较键(win32 大小写不敏感——与 `agent-tools/subagent-scheduler.mjs` 的 fileKey 同律)。 */
|
|
323
|
+
const batchKeyOf = (p) => (process.platform === "win32" ? String(p).toLowerCase() : String(p))
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 记录一批的父会话起点(`depth-0 根 agent` 上按规范化 batchDoc 存):批创建成功时记一次;
|
|
327
|
+
* 旧批没有起点时由首次绑定 spawn 记一次(`subagent-spawn.mjs` 的 `buildSpawnChild`)——
|
|
328
|
+
* **已记过的不动**(不回填一个虚构的历史范围)。
|
|
329
|
+
* @param {object} rootAgent — depth-0 根 agent(历史与窗口都属于它那一本账)
|
|
330
|
+
* @param {string} batchDoc — 批次档绝对路径
|
|
331
|
+
* @param {number} [ts] — 起点时刻(epoch ms;缺省 = 现在)
|
|
332
|
+
*/
|
|
333
|
+
export function recordBatchHistoryStart(rootAgent, batchDoc, ts = Date.now()) {
|
|
334
|
+
if (!rootAgent || !batchDoc) return
|
|
335
|
+
const map = (rootAgent._batchHistoryStart ??= new Map())
|
|
336
|
+
const key = batchKeyOf(batchDoc)
|
|
337
|
+
if (!map.has(key)) map.set(key, ts)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** 本批的父会话窗口:`[起点, 下一批起点)`;没有下一批 ⇒ 终点开放到查询时刻。
|
|
341
|
+
* 起点不在账上 ⇒ null(fail-closed:不拿一个猜出来的下界去读)。 */
|
|
342
|
+
function historyWindowOf(rootAgent, batchDoc) {
|
|
343
|
+
const map = rootAgent?._batchHistoryStart
|
|
344
|
+
const key = batchKeyOf(batchDoc)
|
|
345
|
+
const start = map instanceof Map ? map.get(key) : undefined
|
|
346
|
+
if (typeof start !== "number") return null
|
|
347
|
+
let end = null
|
|
348
|
+
for (const [k, v] of map) {
|
|
349
|
+
if (k === key || typeof v !== "number" || v <= start) continue
|
|
350
|
+
if (end === null || v < end) end = v
|
|
351
|
+
}
|
|
352
|
+
return { start, end }
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 绑定父 agent 的受限 `read_history`(同名工具,只在 eng 子代理的 `childRunOpts.extraTools` 注入):
|
|
357
|
+
* 读的是**父会话**里本批起点之后、下一批起点之前的消息,限量 50,禁止 `path` / 跨会话
|
|
358
|
+
* (`ctx.agent` 固定为闭包里的父 agent ⇒ 读不到 child 自己,也不能反向写父状态)。
|
|
359
|
+
* 无时间戳消息按原工具规则不进入时间窗——所需无日期事实由任务书 `knownFacts` 携带(K6)。
|
|
360
|
+
* @param {object} parentAgent — depth-0 根 agent(父会话 + 窗口账本)
|
|
361
|
+
* @param {string} batchDoc — 本批批次档绝对路径(窗口键)
|
|
362
|
+
*/
|
|
363
|
+
export function makeBatchHistoryTool(parentAgent, batchDoc) {
|
|
364
|
+
return {
|
|
365
|
+
name: "read_history",
|
|
366
|
+
description: DESC("read_history-batch"),
|
|
367
|
+
parameters: {
|
|
368
|
+
type: "object",
|
|
369
|
+
required: ["limit"],
|
|
370
|
+
properties: {
|
|
371
|
+
role: { type: "string", enum: ["user", "assistant", "tool"], description: "Only messages with this role." },
|
|
372
|
+
keyword: { type: "string", description: "Case-insensitive substring of the message text (multimodal matches on text parts)." },
|
|
373
|
+
tool: { type: "string", description: "Only messages for this tool: role=tool messages with name=tool, plus assistant messages that declared a call to it." },
|
|
374
|
+
since: { type: "integer", description: "Earliest ts to match, epoch ms, INCLUSIVE — this batch window's start applies too (the later of the two wins); messages without ts never match." },
|
|
375
|
+
until: { type: "integer", description: "Latest ts to match, epoch ms, INCLUSIVE — the next batch's start (or now) applies too (the earlier of the two wins)." },
|
|
376
|
+
limit: { type: "integer", description: "REQUIRED — how many messages to return (1–50). No default: the window is decided by the caller, never supplied for it." },
|
|
377
|
+
direction: { type: "string", enum: ["oldest", "newest"], description: "Take the limit window from the oldest or newest end of the matched set (default newest)." },
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
readonly: true,
|
|
381
|
+
execute(args, ctx) {
|
|
382
|
+
const a = args ?? {}
|
|
383
|
+
// `path` 不在本变体 schema 里;直接调进来的一笔同样拒(schema 是提示,不是门)
|
|
384
|
+
if (Object.hasOwn(a, "path")) {
|
|
385
|
+
throw new Error("read_history: `path` is not available here — this bounded face reads the parent session's window for THIS batch only (no other session, no other batch). Drop `path`. Nothing was read.")
|
|
386
|
+
}
|
|
387
|
+
if (a.limit === undefined || a.limit === null) {
|
|
388
|
+
throw new Error(`read_history: limit is required and has no default — pass how many messages you need (1–${BATCH_HISTORY_LIMIT_MAX}). Nothing was read.`)
|
|
389
|
+
}
|
|
390
|
+
const limit = Math.floor(Number(a.limit))
|
|
391
|
+
if (!Number.isFinite(limit) || limit < 1) {
|
|
392
|
+
throw new Error(`read_history: limit ${JSON.stringify(a.limit)} is not a positive integer — pass 1–${BATCH_HISTORY_LIMIT_MAX}. Nothing was read.`)
|
|
393
|
+
}
|
|
394
|
+
if (limit > BATCH_HISTORY_LIMIT_MAX) {
|
|
395
|
+
throw new Error(`read_history: limit ${limit} exceeds the cap of ${BATCH_HISTORY_LIMIT_MAX} for this bounded face — narrow it by keyword / since / until and ask again. Nothing was read.`)
|
|
396
|
+
}
|
|
397
|
+
const window = historyWindowOf(parentAgent, batchDoc)
|
|
398
|
+
if (window === null) {
|
|
399
|
+
throw new Error(`read_history: no history window is recorded for this batch record (${batchDoc}) — the window is recorded when the batch is created or when its first spawn binds it. Nothing was read; carry the fact you need in the task book instead.`)
|
|
400
|
+
}
|
|
401
|
+
const asNumber = (v) => (v === undefined || v === null ? null : Number(v))
|
|
402
|
+
const sinceGiven = asNumber(a.since)
|
|
403
|
+
const untilGiven = asNumber(a.until)
|
|
404
|
+
const since = sinceGiven === null || !Number.isFinite(sinceGiven) ? window.start : Math.max(sinceGiven, window.start)
|
|
405
|
+
const end = window.end ?? Date.now()
|
|
406
|
+
const until = untilGiven === null || !Number.isFinite(untilGiven) ? end : Math.min(untilGiven, end)
|
|
407
|
+
// ctx.agent 固定为父 agent:读到的是父会话,读不到 child 自己,也写不回父状态
|
|
408
|
+
return readHistoryTool.execute({ ...a, limit, since, until }, { ...ctx, agent: parentAgent })
|
|
409
|
+
},
|
|
410
|
+
}
|
|
411
|
+
}
|
|
311
412
|
export const readHistoryTool = {
|
|
312
413
|
name: "read_history",
|
|
313
414
|
description: DESC("read_history"),
|
|
@@ -358,7 +459,7 @@ export const readHistoryTool = {
|
|
|
358
459
|
// keyword stays a literal substring).
|
|
359
460
|
const kwRe = keyword ? new RegExp(keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i") : null
|
|
360
461
|
const tool = typeof a.tool === "string" && a.tool.length > 0 ? a.tool : null
|
|
361
|
-
const baseCwd = ctx.agent?.cwd
|
|
462
|
+
const baseCwd = ctx.agent?.cwd
|
|
362
463
|
|
|
363
464
|
const pathArg = typeof a.path === "string" && a.path.trim().length > 0 ? a.path.trim() : null
|
|
364
465
|
if (pathArg !== null) {
|