@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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent/batch-changed-surface.mjs — 收口档位臂取材面的判据一族(从 `agent-tools/batch-closeout.mjs` 拆出):
|
|
3
|
+
* 比较键 `surfaceKey` ∥ 显示式 `displayRelOf` ∥ 三处判据 `selfAttributedOf` / `sessionClaimsOf` / `neighborListClaims`。
|
|
4
|
+
*
|
|
5
|
+
* 语义单源 = `docs/core/design/BATCH-RECORD.md` §4.18.1(本批改动面的取材:写时归属作判据一 ∥ 提交 diff 按认领收窄);
|
|
6
|
+
* 本档只实现它,不重述口径。
|
|
7
|
+
*
|
|
8
|
+
* 依赖单向:`agent-tools/batch-closeout.mjs` → 本档——入口 `changedSurface` 与回执段 `changedSurfaceReceiptLine`
|
|
9
|
+
* 留在那里;本档不 import 它,两档不成环。比较键随判据一族住在这里:三处判据都用它,留在入口侧就要反向 import。
|
|
10
|
+
*
|
|
11
|
+
* 本档不是无依赖那一形(同族的 `batch-attribution.mjs` 才是「零 fs、零 import」):认领的计划源本来就要读盘、
|
|
12
|
+
* 要问 git——`batchDirs` ∥ `machineListRowsOf` ∥ `baseShaOf` ∥ `committedDocs` 都在它的取材路径上。
|
|
13
|
+
*/
|
|
14
|
+
import { readdirSync, readFileSync } from "node:fs"
|
|
15
|
+
import { isAbsolute, relative, resolve } from "node:path"
|
|
16
|
+
|
|
17
|
+
import { owningProject } from "../manifest.mjs"
|
|
18
|
+
import { batchDirs } from "../doc-check/existence.mjs"
|
|
19
|
+
import { baseShaOf } from "../agent-tools/batch-gate.mjs"
|
|
20
|
+
import { committedDocs, committedDocsUpto, lastCommitOf } from "../agent-tools/batch-regions.mjs"
|
|
21
|
+
import { isBatchRecord, machineListRowsOf, readBatchStatusLine } from "../agent-tools/batch-segment-vocab.mjs"
|
|
22
|
+
import { attributedTo } from "./batch-attribution.mjs"
|
|
23
|
+
|
|
24
|
+
/** 比较键(绝对路径归一:`/` 分隔符 + win32 折小写)——归属表、认领表与改动面条目三处共用一把尺。 */
|
|
25
|
+
export function surfaceKey(p) {
|
|
26
|
+
const s = resolve(String(p ?? "")).replace(/\\/g, "/")
|
|
27
|
+
return process.platform === "win32" ? s.toLowerCase() : s
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 显示用的仓根相对路径(**不折大小写**:折小写是比较键的事,回执上印真名;仓外 ⇒ 照原值)。 */
|
|
31
|
+
export function displayRelOf(root, p) {
|
|
32
|
+
const raw = String(p ?? "").replace(/\\/g, "/")
|
|
33
|
+
if (typeof root !== "string" || root === "") return raw
|
|
34
|
+
const rel = relative(resolve(root), resolve(p)).replace(/\\/g, "/")
|
|
35
|
+
return rel === "" || rel.startsWith("../") || isAbsolute(rel) ? raw : rel
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 归属表里归属**含本档**的路径集(比较键)。精确取件走叶档的 `attributedTo`,再按归一键补一遍:
|
|
39
|
+
* 表键与批档串在分隔符 ∥ 大小写上可能不同形,而判据一必须比认领更硬——少判的那一侧只许来自认领。 */
|
|
40
|
+
export function selfAttributedOf(agent, selfAbs) {
|
|
41
|
+
const mine = new Set(attributedTo(agent, selfAbs).map(surfaceKey))
|
|
42
|
+
const table = agent?._batchAttribution
|
|
43
|
+
if (!(table instanceof Map)) return mine
|
|
44
|
+
const self = surfaceKey(selfAbs)
|
|
45
|
+
for (const [batch, paths] of table) {
|
|
46
|
+
if (surfaceKey(batch) !== self) continue
|
|
47
|
+
for (const p of paths) mine.add(surfaceKey(p))
|
|
48
|
+
}
|
|
49
|
+
return mine
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 本会话归属表里**别的批**的路径集(认领的观测源)。
|
|
53
|
+
* 不按批档状态筛:归属记的是「哪一批写了这一档」这件已发生的事,那一批收口之后这个事实不变——
|
|
54
|
+
* 同会话并行的两批,后收口的一方靠这一源减掉先收口那一方的档(正是「各自收口不为对方档要行」的实现面)。 */
|
|
55
|
+
export function sessionClaimsOf(agent, selfAbs) {
|
|
56
|
+
const table = agent?._batchAttribution
|
|
57
|
+
const claims = new Set()
|
|
58
|
+
if (!(table instanceof Map)) return claims
|
|
59
|
+
const self = surfaceKey(selfAbs)
|
|
60
|
+
for (const [batch, paths] of table) {
|
|
61
|
+
if (surfaceKey(batch) === self) continue
|
|
62
|
+
for (const p of paths) claims.add(surfaceKey(p))
|
|
63
|
+
}
|
|
64
|
+
return claims
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 盘上**别的批档**已认领的路径集(认领的计划源),`Map<比较键, 批档绝对路径>`。
|
|
68
|
+
*
|
|
69
|
+
* 清单只是**计划面**——它声明打算改哪些档,不证明真改了;单凭计划认领,一条永不兑现的计划就能把一档从
|
|
70
|
+
* 每一批的判据里摘出去。故本源另加三条(缺一不认领):
|
|
71
|
+
* ① 该档确在**那份批档自己的**区间之内(`baseShaOf` 取那份批档的 sha,`committedDocs` ∥ `committedDocsUpto` 给档清单);
|
|
72
|
+
* ② 那份批档与本次收口**同项目根**——跨项目同名的相对路径不认领;
|
|
73
|
+
* ③ 那份批档**状态可读**(`readBatchStatusLine` 三值):收口不改变归属事实,所以已收口的批同样靠本源认领,
|
|
74
|
+
* 缺的只是上界——上界随状态定:`open` ⇒ `HEAD`(`committedDocs`,答「目前改到哪」),`closed` ⇒ 那份批档
|
|
75
|
+
* 自己的最后一次改动提交(`lastCommitOf` + `committedDocsUpto`),取不到上界就不认领。`unknown`(无状态行 ∥
|
|
76
|
+
* 两条以上 ∥ 两词皆不命中)与写锁同口按冻结处置:状态不明的一方不给认领权(不明不等于未收口)。
|
|
77
|
+
* 为什么 `closed` 不能也取 HEAD:收口批的区间会一直往后长,「该档在它的区间之内」对它几乎恒真 ⇒ 计划面变回
|
|
78
|
+
* 所有权,正是①要防的静默放过;钉死上界之后,认领面退回「那一批确实改过的档」。
|
|
79
|
+
* **失败面**:本函数逐条链批各算一次,那几笔读不出——`baseShaOf` 回 `null`、两函数回 `ok: false`、
|
|
80
|
+
* `lastCommitOf` 回 `null`——一律 `continue` 按「认领不成立」处置:那一档照本批判,本批收口照跑。
|
|
81
|
+
* 拒收口那一条只属 `changedSurface` 自己那一笔 diff(邻批的缺陷不得拦本批的收口)。
|
|
82
|
+
* 抽取面 = `machineListRowsOf`(机读清单读取)+ `batchDirs`(批档目录):按「哪一份批档列了哪一档」取,
|
|
83
|
+
* 不取跨批合并后的路径集(并集给不出①要的那份批档自己的批起 sha)。 */
|
|
84
|
+
export function neighborListClaims(root, selfAbs) {
|
|
85
|
+
const claims = new Map()
|
|
86
|
+
const self = surfaceKey(selfAbs)
|
|
87
|
+
const base = resolve(root)
|
|
88
|
+
for (const dir of batchDirs(base)) {
|
|
89
|
+
let names
|
|
90
|
+
try { names = readdirSync(dir) } catch { continue }
|
|
91
|
+
for (const name of names) {
|
|
92
|
+
if (!name.toLowerCase().endsWith(".md")) continue
|
|
93
|
+
const abs = resolve(dir, name)
|
|
94
|
+
if (surfaceKey(abs) === self) continue
|
|
95
|
+
let src
|
|
96
|
+
try { src = readFileSync(abs, "utf8") } catch { continue }
|
|
97
|
+
// 认领面只收**可读状态**的批档:收口批靠它自己的区间上界认领,`unknown`(无状态行 ∥ 两条以上 ∥ 两词皆不命中)
|
|
98
|
+
// 与写锁同口按冻结处置——状态不明的一方不给认领权(不明不等于未收口,认领是往「少判」方向倒的那一条)。
|
|
99
|
+
if (!isBatchRecord(src)) continue
|
|
100
|
+
const status = readBatchStatusLine(src)
|
|
101
|
+
if (status === "unknown") continue
|
|
102
|
+
const rows = machineListRowsOf(src)
|
|
103
|
+
if (rows.length === 0) continue
|
|
104
|
+
const owned = owningProject(abs, base)
|
|
105
|
+
if (!owned || surfaceKey(owned) !== surfaceKey(base)) continue // ②(取不到根 ⇒ 不认领)
|
|
106
|
+
const sha = baseShaOf(abs)
|
|
107
|
+
if (sha === null) continue // 没有它自己的批起 sha ⇒ 观测不成立
|
|
108
|
+
// 区间上界随状态定:未收口 ⇒ HEAD(右端继续往后长是对的,那一批还在写);
|
|
109
|
+
// 已收口 ⇒ 它自己的最后一次提交(钉死上界,否则「该档在它区间内」对它几乎恒真 ⇒ 计划面变所有权)。
|
|
110
|
+
let committed
|
|
111
|
+
if (status === "closed") {
|
|
112
|
+
const upper = lastCommitOf(base, abs)
|
|
113
|
+
if (upper === null) continue // 上界取不到 ⇒ 不认领(fail-closed:那一档照本批判)
|
|
114
|
+
committed = committedDocsUpto(base, sha, upper)
|
|
115
|
+
} else {
|
|
116
|
+
committed = committedDocs(base, sha)
|
|
117
|
+
}
|
|
118
|
+
if (!committed.ok) continue // 这一链读不出 ⇒ 不认领、本批照跑(拒收口只属本批自己的 diff 腿)
|
|
119
|
+
// 认领键与改动面条目同一坐标系(绝对路径归一)——两侧共用 `surfaceKey` 一把尺。
|
|
120
|
+
const changed = new Set()
|
|
121
|
+
for (const f of committed.files ?? []) changed.add(surfaceKey(resolve(committed.base, f)))
|
|
122
|
+
for (const row of rows) {
|
|
123
|
+
const key = surfaceKey(resolve(base, row.path))
|
|
124
|
+
if (changed.has(key)) claims.set(key, abs) // ①
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return claims
|
|
129
|
+
}
|
package/agent/completion.mjs
CHANGED
|
@@ -13,8 +13,23 @@ import { poolLive } from "./suspension.mjs"
|
|
|
13
13
|
const MAX_VERIFY_PUSHBACKS = 2
|
|
14
14
|
const MAX_VERIFY_RETRIES = 3
|
|
15
15
|
const MAX_ADVISOR_PUSHBACKS = 3
|
|
16
|
+
// 层 2(ADVISOR-CONVERGENCE.md §6.4 B):同一未评审周期的提醒硬上限——续跑与段重启都不回满。
|
|
17
|
+
// 取 5 而非 3:进展窗口预算保持原值 3,周期上限再给一次「真改了代码还是漏评审」的宽限。
|
|
18
|
+
const MAX_ADVISOR_REMINDERS = 5
|
|
16
19
|
const MAX_EMPTY_RETRIES = 2
|
|
17
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 响应「有实质」判据(单源——判空面与清零面读同一份;AGENT-LOOP.md §6.5① · D-AL28):有非空正文
|
|
23
|
+
* **或** 有工具调用 ⇒ 实质,两种形都证明「刚才那次空是瞬时的」。此处也是唯一判空式,不另写
|
|
24
|
+
* `.trim() === ""`——两份一漂,判空与清零就不再是同一件事(判空加宽、清零面漏跟)。
|
|
25
|
+
* 「或」不是「且」:带工具调用但正文为空(提供端常见形态)必须判为实质——写成「且」,工具轮就不清零,
|
|
26
|
+
* 空计数跨轮累计,「中间成功过却照样抛」原样留存。
|
|
27
|
+
* @param {object} response - chat response with .content, .toolCalls(同下方 handleCompletion 的既有契约)
|
|
28
|
+
*/
|
|
29
|
+
export function isSubstantiveResponse(response) {
|
|
30
|
+
return String(response.content ?? "").trim() !== "" || response.toolCalls.length > 0
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
/**
|
|
19
34
|
* Handle a model turn with zero tool calls. May push back (verify/advisor/pending tasks)
|
|
20
35
|
* or accept the completion.
|
|
@@ -29,7 +44,7 @@ const MAX_EMPTY_RETRIES = 2
|
|
|
29
44
|
* @param {object} callbacks - { onTurnEnd, onSubTurnBreak }
|
|
30
45
|
*/
|
|
31
46
|
export function handleCompletion(agent, response, depth, turn, guardPushbacks, honestReminderInjected, advisorPushbacks, callbacks) {
|
|
32
|
-
if (
|
|
47
|
+
if (!isSubstantiveResponse(response)) {
|
|
33
48
|
// Transient empty response (reasoning exhausted / output truncated): instead of
|
|
34
49
|
// aborting the whole turn, inject a reminder and let the model respond again.
|
|
35
50
|
// Bounded — after MAX_EMPTY_RETRIES consecutive empties, surface the original error.
|
|
@@ -140,13 +155,51 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
140
155
|
const pending = advisorReviewPending(agent)
|
|
141
156
|
// rounds 仅作提醒文案显示(撤 cap——轮次不是终止判据;ADVISOR-CONVERGENCE.md §3.1)。
|
|
142
157
|
const rounds = effectiveAdvisorRound(agent)
|
|
143
|
-
|
|
144
|
-
|
|
158
|
+
// 「未评审即收尾」的四项合取(既有判据逐字零改)+ 两支出口(推回一条 ∥ 任一层停推后的到顶诚实提醒,§6.4 A/B)。
|
|
159
|
+
// `!pending` 同属两支的一部分:异步评审在飞 = 未决,不是未评审——此时推「未经评审」的诚实声明
|
|
160
|
+
// 会与正在跑的评审自相矛盾。
|
|
161
|
+
const unreviewed = !pending && agent._mutatedThisRun && !agent._calledAdvisorThisRun && hasCodeMutations(agent)
|
|
162
|
+
// 层 1(进展窗口,§6.4 A)+ 层 2(未评审周期,§6.4 B)都还有余量 ⇒ 推一条。
|
|
163
|
+
// 计数落 agent:回合环那个 `advisorPushbacks` 是 `runAgent` 局部量,续跑重进即归零(上限形同没设)。
|
|
164
|
+
if (unreviewed && (agent._advisorReminders ?? 0) < MAX_ADVISOR_REMINDERS && advisorPushbacks < MAX_ADVISOR_PUSHBACKS) {
|
|
165
|
+
agent._advisorReminders = (agent._advisorReminders ?? 0) + 1
|
|
145
166
|
advisorPushbacks++
|
|
146
167
|
pushReal(agent, { role: "assistant", content: response.content })
|
|
147
168
|
agent.history.push({
|
|
148
169
|
role: "user",
|
|
149
|
-
content: `[System reminder: you changed code in this run and MUST get an advisor review before finishing (round ${rounds + 1}). Call the \`advisor\` tool now. This is required, not optional — do not skip it even if you believe the changes are trivial — the review will be quick either way. After the review, produce a response table for every issue found (see discipline rules for format)
|
|
170
|
+
content: `[System reminder: you changed code in this run and MUST get an advisor review before finishing (round ${rounds + 1}). Call the \`advisor\` tool now. This is required, not optional — do not skip it even if you believe the changes are trivial — the review will be quick either way. After the review, produce a response table for every issue found (see discipline rules for format).${
|
|
171
|
+
agent._advisorReminders >= MAX_ADVISOR_REMINDERS
|
|
172
|
+
? ` This is reminder ${MAX_ADVISOR_REMINDERS} of ${MAX_ADVISOR_REMINDERS} — the last one. If you deliver without an advisor review, state explicitly in your reply to the user that this code has not been reviewed.`
|
|
173
|
+
: ""
|
|
174
|
+
}]`,
|
|
175
|
+
})
|
|
176
|
+
callbacks.onSubTurnBreak?.()
|
|
177
|
+
callbacks.onTurnEnd?.(agent, turn)
|
|
178
|
+
return { action: "continue", guardPushbacks, honestReminderInjected, advisorPushbacks }
|
|
179
|
+
}
|
|
180
|
+
// **任一层停推**(层 1 或层 2 耗尽 ⇒ 本轮推不成)⇒ 推**一条**诚实提醒,其后本轮放行收尾。
|
|
181
|
+
// 判据不写成「推满 5 条」:层 1 的预算只在真写了文件时回满(§6.4 A),所以「改过一次代码后只读不写」
|
|
182
|
+
// 是最常见形态——层 1 停在 3 条时只认 5 条的到顶条件永不成真,两支都不进 ⇒ 直接 `done`、零诚实提醒,
|
|
183
|
+
// 正是本机制要挡的「未评审即交付且静默」。
|
|
184
|
+
// 到顶静默放行 = 把「未评审即交付」这条业务失败做成静默成功,而这道 guard 存在的目的就是挡它:
|
|
185
|
+
// 形态照 verify 面到顶(本档上方 `// Exhausted retries — inject honesty reminder once`)——同形、
|
|
186
|
+
// 只换主语,不新增用户可见标记 / 字段 / 配置键。
|
|
187
|
+
// 一次性位的复位口径(§1 20:39 裁定):位**随新进展复位**——与推回预算同一处(`turn-loop.mjs` 的写序推进
|
|
188
|
+
// 点,两行手拉手),另在本周期两处复位点(新用户回合起点 ∥ 评审覆盖成立处)一并归假。故口径是
|
|
189
|
+
// 「每次停推且仍未评审的收尾恰得一条诚实提醒」——不存在「发过一条之后本周期彻底静默」的第二条静默途径,
|
|
190
|
+
// 而「本轮发过就再也不发」会让「诚实提醒 → 又改代码 → 再收尾」整段不吭声(正是本批要堵的形状)。
|
|
191
|
+
// 文案只陈述事实(几条已发 ∥ 代码未评审 ∥ 二选一),**不**许诺「不再推」——层 1 先耗尽的形态下,
|
|
192
|
+
// 后续有新进展仍会再推提醒(§1 20:39 裁定第二条)。条数取 `?? 0`:复位点 2 清零后层 1 耗尽可达,别读出 undefined。
|
|
193
|
+
if (
|
|
194
|
+
unreviewed
|
|
195
|
+
&& ((agent._advisorReminders ?? 0) >= MAX_ADVISOR_REMINDERS || advisorPushbacks >= MAX_ADVISOR_PUSHBACKS)
|
|
196
|
+
&& !agent._advisorHonestySent
|
|
197
|
+
) {
|
|
198
|
+
agent._advisorHonestySent = true
|
|
199
|
+
pushReal(agent, { role: "assistant", content: response.content })
|
|
200
|
+
agent.history.push({
|
|
201
|
+
role: "user",
|
|
202
|
+
content: `[System reminder: ${agent._advisorReminders ?? 0} advisor reminders sent. You have not had this code reviewed. Either call the \`advisor\` tool now, or state explicitly in your reply that this code has not been reviewed — do not present the work as reviewed. The user needs to know it is unreviewed.]`,
|
|
150
203
|
})
|
|
151
204
|
callbacks.onSubTurnBreak?.()
|
|
152
205
|
callbacks.onTurnEnd?.(agent, turn)
|
package/agent/digest-account.mjs
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* agent/digest-account.mjs — 消化账务单件(AGENT-LOOP-ASYNC-POOL.md §6.31 · 批 digest-accounting ·
|
|
3
|
-
* 台账 #930
|
|
3
|
+
* 台账 #930;批 digest-retry-amplify · 台账 #1850:投递恒一次):投递 ≠ 销账——报告不许无声消失。
|
|
4
4
|
*
|
|
5
|
-
* 三角色(§6.31.2
|
|
6
|
-
* **销账**(覆盖才离容器 + 释放 report
|
|
7
|
-
*
|
|
8
|
-
* `digestAccountRequirement` 要求行)/ 见账 pass(`accountDigestRound
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* 三角色(§6.31.2):**投递**(注入但留容器——每条恒一次)/ **见账**(消化轮收尾逐条机检账目覆盖)/
|
|
6
|
+
* **销账**(覆盖才离容器 + 释放 report;未覆盖计一个未签收轮,达 `DA_MISS_LIMIT` ⇒ 升级)。本档承载:
|
|
7
|
+
* 常量(`DA_MISS_LIMIT`)/ 回合分类(`isDigestRound`)/ 投递门控(`shouldDeliverEntry`)/ 账目合同
|
|
8
|
+
* (`coversDigestId` 解析 ∥ `digestAccountRequirement` 要求行)/ 见账 pass(`accountDigestRound`——
|
|
9
|
+
* 销账 ∥ 未签收轮 ∥ 升级四步含终局披露)/ 读面(`unsettledRows` · `unsettledRow` · `unsettledCount`)/
|
|
10
|
+
* 落痕清位 ∕ 取件助手(`armAccountRound` · `harvestAccountOutput`)。
|
|
11
11
|
*
|
|
12
12
|
* 载体(§6.31.2):`_daSession`(会话标记——挂起会话置 / 复位,`agent/suspension.mjs`)与
|
|
13
13
|
* `_unsettledDigests`(升级账本——经 `async-settle.mjs` 写助手);账目态挂条目字段
|
|
14
|
-
* (`_daDelivered` / `
|
|
15
|
-
* 直连 `runAgent`)零账目动作(不销账 /
|
|
14
|
+
* (`_daDelivered` / `_daMissRounds`)。**fallback 面**(无 `_daSession`——headless /
|
|
15
|
+
* 直连 `runAgent`)零账目动作(不销账 / 不计未签收轮 / 不升级):缺省条逐字沿用取尽语义(先离容后注入);
|
|
16
16
|
* 已投递未销账条同判据跳过且留容器(§6.31 出口缝② · 父侧裁定 2026-10-05)。
|
|
17
17
|
*
|
|
18
18
|
* 边界(§6.31.12):不做处理质量机检(只保「不许无声」);升级账本无 TTL(会话期面——
|
|
19
19
|
* 中止清、idle 存续)。
|
|
20
20
|
*/
|
|
21
|
-
import { logEvent } from "../log.mjs"
|
|
21
|
+
import { logEvent, errText } from "../log.mjs"
|
|
22
22
|
import { pushReal } from "../context.mjs"
|
|
23
23
|
import { carrierField, releaseSettledEntry, appendUnsettledDigest } from "../agent-tools/async-settle.mjs"
|
|
24
24
|
import { DIGEST_ACCOUNT_DOMAIN } from "./helpers.mjs"
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/** 同条未签收上限(§6.31.5 KD-DA11):积满 DA_MISS_LIMIT 个未签收消化轮 ⇒ 升级(离容器 + 账本 + 提醒 + 终局披露一次)。
|
|
27
|
+
* 依据 = 「连空 3 轮仍须在容器、第 4 轮补签仍能销账」的**下界**(N = 4——无额外余量;可复算;不取观测值——
|
|
28
|
+
* 修前观测受「总投递 ≤3」删失)。 */
|
|
29
|
+
export const DA_MISS_LIMIT = 4
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* 回合分类单点(§6.31.2):账目只属**消化轮**(autoTurn ∧ 非上行唤醒轮 ∧ 非 timer 轮)——
|
|
31
|
-
* timer /
|
|
33
|
+
* timer / 上行轮投递不销账(其账目在后续消化轮)。
|
|
32
34
|
*/
|
|
33
35
|
export function isDigestRound(opts) {
|
|
34
36
|
return opts?.autoTurn === true && opts?.upstreamTurn !== true && opts?.timerTurn !== true
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
|
-
* 投递门控(§6.31.4
|
|
39
|
-
*
|
|
40
|
-
* - `
|
|
41
|
-
*
|
|
40
|
+
* 投递门控(§6.31.4 单点谓词 · 批 digest-retry-amplify 收为单门):`!_daDelivered` ∧ 本回合 = 系统轮
|
|
41
|
+
* (`autoTurn`)⇒ 投(首次投递——**用户回合零投递**);`_daDelivered` 已置 ⇒ 恒跳过(**每条只投一次**——
|
|
42
|
+
* 重投回路退场,§6.31.5 KD-DA4)。注入抛错 ⇒ `_daDelivered` 未置 ⇒ 下一系统轮重试注入
|
|
43
|
+
* (注入失败的再试,不属投递回路)。
|
|
42
44
|
* 注:`autoTurn` 判据由调用方(`run-start.mjs` 会话态支)传入;回退面(非会话态支)不经本谓词。
|
|
43
45
|
*/
|
|
44
|
-
export function shouldDeliverEntry(entry,
|
|
45
|
-
if (entry?._daDelivered
|
|
46
|
-
return
|
|
46
|
+
export function shouldDeliverEntry(entry, autoTurn) {
|
|
47
|
+
if (entry?._daDelivered === true) return false
|
|
48
|
+
return autoTurn === true
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/** 账目要求行(§6.31.3):核常量(helpers.mjs)+ 未销账 id 清单动态拼(`<ids>` 占位替换)。 */
|
|
@@ -77,70 +79,94 @@ export function coversDigestId(output, id) {
|
|
|
77
79
|
* 见账 pass(§6.31.5——消化轮收尾 `finalizeAgentTurn` 单点调用;调用方已判 `isDigestRound ∧
|
|
78
80
|
* `_daSession` ∧ 非会话停止径):
|
|
79
81
|
* - 投递账 = pending ∩ `_daDelivered`;覆盖 ⇒ 离容器(splice)+ `releaseSettledEntry`(含 report 释放);
|
|
80
|
-
* -
|
|
81
|
-
*
|
|
82
|
-
* 缺痕(output == null——抛错 / 撞帽 /
|
|
82
|
+
* - 未覆盖(空回合 ∥ 有输出未签收——同判同计)⇒ `_daMissRounds += 1`;< `DA_MISS_LIMIT` ⇒ 条留容器、
|
|
83
|
+
* **零投递动作**;达上限 ⇒ **升级**(四步固定先后:账本 → 提醒 → 离容器 → 终局披露)。
|
|
84
|
+
* 缺痕(output == null——抛错 / 撞帽 / 未收口 / 整 run 零非空正文)⇒ 按未签收判(与「有输出未签收」同出口)。
|
|
85
|
+
*
|
|
86
|
+
* async(§6.31.5 升级支 ④):披露复用首投注入器 ⇒ pass 变 async——唯一调用点 = `run-stages.mjs` 的
|
|
87
|
+
* finalize 单点(已 await)。披露逐条 try/catch:判据 = **披露失败不得使报告离开可见面**
|
|
88
|
+
* (账本 + 提醒 + status 面 `preview` 已在披露之前落定,失败降级可见性、留痕不静默)。
|
|
83
89
|
*/
|
|
84
|
-
export function accountDigestRound(carrier) {
|
|
90
|
+
export async function accountDigestRound(carrier) {
|
|
85
91
|
const pending = carrierField(carrier, "_pendingAsyncResults")
|
|
86
|
-
if (!Array.isArray(pending)) return { covered: 0,
|
|
92
|
+
if (!Array.isArray(pending)) return { covered: 0, unsettled: 0 }
|
|
87
93
|
const output = harvestAccountOutput(carrier)
|
|
88
94
|
const covered = []
|
|
89
|
-
const retried = []
|
|
90
95
|
const upgraded = []
|
|
91
96
|
for (const entry of [...pending]) {
|
|
92
97
|
if (entry?._daDelivered !== true) continue
|
|
93
98
|
if (output != null && coversDigestId(output, entry.id)) { covered.push(entry); continue }
|
|
94
|
-
entry.
|
|
95
|
-
if (entry.
|
|
96
|
-
else upgraded.push(entry)
|
|
99
|
+
entry._daMissRounds = (entry._daMissRounds ?? 0) + 1
|
|
100
|
+
if (entry._daMissRounds >= DA_MISS_LIMIT) upgraded.push(entry)
|
|
97
101
|
}
|
|
98
102
|
for (const entry of covered) {
|
|
99
103
|
const i = pending.indexOf(entry)
|
|
100
104
|
if (i >= 0) pending.splice(i, 1)
|
|
101
105
|
releaseSettledEntry(entry)
|
|
102
106
|
}
|
|
107
|
+
if (upgraded.length === 0) return { covered: covered.length, unsettled: 0 }
|
|
108
|
+
// 升级四步固定先后(§6.31.5——纯内存的两面先落、披露最后:披露是本 pass 唯一的 I/O,
|
|
109
|
+
// 抛错会中断余下条目判定并越过 `run-stages.mjs` 的 `_inAutoTurn = false` 与 guard 快照)。
|
|
110
|
+
// ① 入账本(纯内存):账本记录 = **快照**,只喂 status 面与 `preview`——被注入的对象是原条目(见 ④)。
|
|
103
111
|
for (const entry of upgraded) {
|
|
104
|
-
const i = pending.indexOf(entry)
|
|
105
|
-
if (i >= 0) pending.splice(i, 1)
|
|
106
112
|
appendUnsettledDigest(carrier, {
|
|
107
113
|
id: String(entry.id),
|
|
108
114
|
role: entry.role ?? "subagent",
|
|
109
|
-
|
|
115
|
+
missRounds: entry._daMissRounds,
|
|
110
116
|
report: entry.report ?? null,
|
|
111
117
|
at: Date.now(),
|
|
112
118
|
})
|
|
113
119
|
}
|
|
114
|
-
//
|
|
120
|
+
// ② 提醒:恰一条(机器线 + 人读线——`pushReal`)+ 恰一条留痕(字段单源 = LOGGING.md §6.2)。
|
|
115
121
|
// 注:`ids` 以 join 串落盘——`logEvent` 只收标量(数组字段会被静默丢弃——先例 `ev:discarded`)。
|
|
116
|
-
|
|
122
|
+
{
|
|
117
123
|
const ids = upgraded.map((entry) => String(entry.id))
|
|
118
124
|
pushReal(carrier, { role: "user", content: unsettledReminder(upgraded.length, ids) })
|
|
119
125
|
logEvent("ev:unsettled", { n: upgraded.length, ids: ids.join(", ") })
|
|
120
126
|
}
|
|
121
|
-
|
|
127
|
+
// ③ 离容器(纯结构):至此条目定态「已升级」,不再参与判定 ⇒ 披露结构上至多一次。
|
|
128
|
+
for (const entry of upgraded) {
|
|
129
|
+
const i = pending.indexOf(entry)
|
|
130
|
+
if (i >= 0) pending.splice(i, 1)
|
|
131
|
+
}
|
|
132
|
+
// ④ 终局披露:**按 role 与首投同分流**(consult → `injectConsultResult`;其余 → `injectAsyncResult`——
|
|
133
|
+
// 内部已分派 bg / browser);不新造第二投递形。注入的对象 = **原条目**(墓碑值
|
|
134
|
+
// `error != null ? "failed" : "consumed"` 与评审族投递水印 `entry.run` 都按原条目字段才成立)。
|
|
135
|
+
const { injectAsyncResult } = await import("../agent-tools/subagent.mjs")
|
|
136
|
+
const { injectConsultResult } = await import("../agent-tools/consult.mjs")
|
|
137
|
+
for (const entry of upgraded) {
|
|
138
|
+
try {
|
|
139
|
+
if (entry.role === "consult") await injectConsultResult(carrier, entry)
|
|
140
|
+
else await injectAsyncResult(carrier, entry)
|
|
141
|
+
} catch (e) {
|
|
142
|
+
// 逐条 continue(形同 `suspension.mjs` 注入循环收口;差异 = 该处首错即 return)——
|
|
143
|
+
// 账本 + 提醒已在 ① ② 落地,单条披露失败不得拦住余下条目,也不得拦住 finalize 的收尾两步。
|
|
144
|
+
logEvent("ev:unsettled-disclose-failed", { id: String(entry.id), err: errText(e, 200) })
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return { covered: covered.length, unsettled: upgraded.length }
|
|
122
148
|
}
|
|
123
149
|
|
|
124
|
-
/** 升级提醒行(§6.31.5
|
|
150
|
+
/** 升级提醒行(§6.31.5——含 n / 轮数(恒 = `DA_MISS_LIMIT`,升级只在第 N 个未签收轮发生)/ id 清单与接手指引)。 */
|
|
125
151
|
export function unsettledReminder(n, ids) {
|
|
126
|
-
return `[System reminder: ${n} background report(s) were delivered but never accounted after ${
|
|
152
|
+
return `[System reminder: ${n} background report(s) were delivered but never accounted after ${DA_MISS_LIMIT} digest rounds — they are marked UNSETTLED: ${ids.map((id) => `#${id}`).join(", ")}. Their content was delivered once in this conversation and is re-delivered once right below as the final delivery — if that copy is missing, the delivery failed and the full text stays readable via subagent action:'status'. Process it there or re-spawn the work.]`
|
|
127
153
|
}
|
|
128
154
|
|
|
129
155
|
/**
|
|
130
156
|
* 读面(§6.31.6——status 段 ∥ 端面残余行共用单点):行 = `{ id, role, state, attempts }`;
|
|
131
|
-
* state ∈ `awaiting-digest`(在途未投递 ∥
|
|
132
|
-
* `unsettled`(已升级——随携 `preview` ≤400
|
|
157
|
+
* state ∈ `awaiting-digest`(在途未投递 ∥ 已投递未判 = `attempts == 0`)/ `unaccounted`(判过未签收 =
|
|
158
|
+
* `attempts > 0`)/ `unsettled`(已升级——随携 `preview` ≤400 字符);`attempts` = 未签收轮数 `_daMissRounds`。
|
|
133
159
|
*/
|
|
134
160
|
export function unsettledRows(carrier) {
|
|
135
161
|
const rows = []
|
|
136
162
|
const pending = carrierField(carrier, "_pendingAsyncResults")
|
|
137
163
|
for (const entry of Array.isArray(pending) ? pending : []) {
|
|
138
|
-
const
|
|
164
|
+
const missRounds = entry?._daMissRounds ?? 0
|
|
139
165
|
rows.push({
|
|
140
166
|
id: String(entry.id),
|
|
141
167
|
role: entry.role ?? "subagent",
|
|
142
|
-
state:
|
|
143
|
-
attempts:
|
|
168
|
+
state: missRounds > 0 ? "unaccounted" : "awaiting-digest",
|
|
169
|
+
attempts: missRounds,
|
|
144
170
|
})
|
|
145
171
|
}
|
|
146
172
|
const ledger = carrierField(carrier, "_unsettledDigests")
|
|
@@ -149,7 +175,7 @@ export function unsettledRows(carrier) {
|
|
|
149
175
|
id: String(u.id),
|
|
150
176
|
role: u.role ?? "subagent",
|
|
151
177
|
state: "unsettled",
|
|
152
|
-
attempts: u.
|
|
178
|
+
attempts: u.missRounds ?? 0,
|
|
153
179
|
preview: String(u.report ?? "").slice(0, 400),
|
|
154
180
|
})
|
|
155
181
|
}
|
|
@@ -162,11 +188,12 @@ export function unsettledRow(carrier, id) {
|
|
|
162
188
|
return unsettledRows(carrier).find((row) => row.id === key) ?? null
|
|
163
189
|
}
|
|
164
190
|
|
|
165
|
-
/** 端面残余行判据(§6.31.6):pending 中 `
|
|
191
|
+
/** 端面残余行判据(§6.31.6):pending 中 `_daMissRounds > 0` 条数(与状态面 `unaccounted` 同判据;
|
|
192
|
+
* 升级条已离容器——由升级提醒承载)。 */
|
|
166
193
|
export function unsettledCount(carrier) {
|
|
167
194
|
const pending = carrierField(carrier, "_pendingAsyncResults")
|
|
168
195
|
let n = 0
|
|
169
|
-
for (const entry of Array.isArray(pending) ? pending : []) if ((entry?.
|
|
196
|
+
for (const entry of Array.isArray(pending) ? pending : []) if ((entry?._daMissRounds ?? 0) > 0) n += 1
|
|
170
197
|
return n
|
|
171
198
|
}
|
|
172
199
|
|
|
@@ -181,7 +208,7 @@ export function armAccountRound(carrier) {
|
|
|
181
208
|
}
|
|
182
209
|
|
|
183
210
|
/** 落痕取件(§6.31.5——载体吸收读:父字段优先 / 回退 `history`);读值 = 本 run 多轮累积文本(#939);
|
|
184
|
-
* 缺痕(本 run 零输出落痕——零模型轮 /
|
|
211
|
+
* 缺痕(本 run 零输出落痕——零模型轮 / 起跑即断 / 每轮正文皆空)⇒ null。 */
|
|
185
212
|
export function harvestAccountOutput(carrier) {
|
|
186
213
|
const own = carrier?._lastRunOutput
|
|
187
214
|
if (own !== undefined && own !== null) return own
|
package/agent/dispatch-gates.mjs
CHANGED
|
@@ -132,6 +132,12 @@ export function isSubagentEscalateAction(toolName, args) {
|
|
|
132
132
|
export function readonlyActionOf(tool, toolName, args) {
|
|
133
133
|
return tool?.isReadonlyAction?.(args) ?? isReadonlyAction(toolName, args)
|
|
134
134
|
}
|
|
135
|
+
/** 只读变体派生面的谓词形(`(tool, args)`——`readonlyActionOf` 的单参适配,单源只此一处)。
|
|
136
|
+
* 消费点 = `agent/helpers.mjs` 的 `makeReadonlyToolVariant` / `deriveReadonlyTools` 注入面:
|
|
137
|
+
* 构造器不 import 本档(本档 import 它——成环),故由调用方把这枚函数传进去(TOOLS.md §6.29 ①)。 */
|
|
138
|
+
export function readonlyActionTest(tool, args) {
|
|
139
|
+
return readonlyActionOf(tool, tool?.name, args)
|
|
140
|
+
}
|
|
135
141
|
export function controlActionOf(tool, toolName, args) {
|
|
136
142
|
return tool?.isControlAction?.(args) ?? isSubagentControlAction(toolName, args)
|
|
137
143
|
}
|
package/agent/dispatch-run.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export async function runPreparedItem(item, agent, depth, signal, callbacks) {
|
|
|
28
28
|
? "Error: plan mode is active — only read-only tools are allowed. Exit plan mode first."
|
|
29
29
|
: item.reason === "engineering design gate"
|
|
30
30
|
? `Error: design review required before any file modification. ${item.hint}`
|
|
31
|
-
: item.reason === "d5 freeze window" || item.reason === "cross-batch record write"
|
|
31
|
+
: item.reason === "d5 freeze window" || item.reason === "cross-batch record write" || item.reason === "ledger binding"
|
|
32
32
|
? `Error: ${item.hint}`
|
|
33
33
|
: item.reason === "denied by user"
|
|
34
34
|
? "Error: permission denied by user"
|
package/agent/dispatch.mjs
CHANGED
|
@@ -7,15 +7,17 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { FILE_MUTATORS, toolTouchPaths } from "./helpers.mjs"
|
|
9
9
|
import { runHooks } from "../hooks.mjs"
|
|
10
|
-
|
|
10
|
+
// 面判定单源(2026-10-27 三链统一批 · 设计档 §2.1):设计门的面判据由 `isCodePath` 换成 `faceOf`——
|
|
11
|
+
// 与写锁共用同一份判据(两道门各用一套必然漂移:设计门放的、写锁拦的各说各话)。`isCodePath` / `classifyPath`
|
|
12
|
+
// 本体零改(其余六个消费面语义不变);`declarationForTarget` 仍用来取出辖判定与提示指针。
|
|
13
|
+
import { declarationForTarget } from "../conventions.mjs"
|
|
11
14
|
import { manifestFilePath } from "../manifest.mjs"
|
|
15
|
+
import { faceOf } from "./write-face.mjs"
|
|
12
16
|
import { resolve, relative } from "node:path"
|
|
13
17
|
import { anyLiveDesignSlot } from "../token-ttl.mjs"
|
|
14
|
-
// F-LC5(LIGHT-CHANNEL §2.8 · 2026-10-09):轻通道轮在盘谓词(代码笔通路——两件双在盘 ⇒ 父侧代码笔放行)。
|
|
15
|
-
import { lightRoundOpen } from "./light-round.mjs"
|
|
16
18
|
// M4 写权门禁(模块设计 §2.1#2):冻结窗口判据组装(被审文件集 = 声明文档集 + 批次档
|
|
17
19
|
// 的合流点)落 write-gate.mjs 单一权威源——本档只 import 消费(KD-M4-4 拆分点)。
|
|
18
|
-
import { freezeWindowConflict, batchRecordWriteConflict } from "./write-gate.mjs"
|
|
20
|
+
import { freezeWindowConflict, batchRecordWriteConflict, ledgerBindWriteConflict } from "./write-gate.mjs"
|
|
19
21
|
// 门面谓词 ∕ 记账(2026-09-28 拆分外提——见头注):动作级四谓词 + logToolError 住 ./dispatch-gates.mjs。
|
|
20
22
|
import {
|
|
21
23
|
logToolError, isSubagentConsumeDesignAction, isSubagentEscalateAction,
|
|
@@ -76,30 +78,23 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
|
|
|
76
78
|
continue
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
// Engineering mode PARENT gate: the parent agent must not touch
|
|
81
|
+
// Engineering mode PARENT gate: the parent agent must not touch the product face
|
|
80
82
|
// before the design review passed. Signaled by a live design slot (design-review
|
|
81
83
|
// approval — persists in the session slot, survives across turns; _engDesignReviewed
|
|
82
|
-
// is eng-coder-only and reset per run).
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
// design token. The project can declare its own code paths (the manifest's
|
|
87
|
-
// `codePaths`) so a non-src layout is not silently exempted. Mechanically
|
|
88
|
-
// blocks "talk then code".
|
|
89
|
-
// F-LC5(LIGHT-CHANNEL §2.8 · 2026-10-09):轻通道轮在盘 = 机械开路——轮次台账行(在途 · title 携「收尾链
|
|
90
|
-
// 待跑」· 携指针)与所指轮档(§1 状态行「进行中」)双在盘期间父侧代码笔放行(谓词 fail-closed)。
|
|
91
|
-
// 查找面 = 会话锚 + 其直接子目录一层(纯向下——工作区锚会话同判)。
|
|
84
|
+
// is eng-coder-only and reset per run). Exemption = the doc face only (manifest
|
|
85
|
+
// `docRoot` paths + the project manifest itself); every other path is the product
|
|
86
|
+
// face and needs a design token — writing a design document IS the design step.
|
|
87
|
+
// Mechanically blocks "talk then code".
|
|
92
88
|
// F11(#1104 · PORTABILITY §3.9 / D20):辖域 = 目标所属项目——逐目标沿祖先链取最近带档
|
|
93
89
|
// 目录(`declarationForTarget`——nearest wins ∥ 纯向上 ∥ 发现梯不参与);出辖(祖先链无档)
|
|
94
90
|
// ⇒ 放行(门只管 manifest 树以内的内容)。相对形先按会话 cwd 解析(cwd 只是相对基,非声明源);
|
|
95
|
-
//
|
|
91
|
+
// 在辖目标按两值面判(`write-face.mjs`)——文档面放行 ∥ 其余一切产品面(fail-closed)。
|
|
96
92
|
// DESIGN-TOKEN-SETTLEMENT D3(2026-09-08):资格判据 = 权威槽"任一活槽存在"
|
|
97
93
|
// (anyLiveDesignSlot——查内存 Map,miss 回读槽文件——单值镜像 `_engDesignToken`
|
|
98
94
|
// 已退役,门禁不再读镜像——AC4)。
|
|
99
95
|
if (agent.config?.agent?.engineering && depth === 0
|
|
100
96
|
&& !anyLiveDesignSlot(agent)
|
|
101
|
-
&& FILE_MUTATORS.has(toolCall.name)
|
|
102
|
-
&& !(await lightRoundOpen(agent))) {
|
|
97
|
+
&& FILE_MUTATORS.has(toolCall.name)) {
|
|
103
98
|
const paths = toolTouchPaths(tool, args)
|
|
104
99
|
// Unknown/missing paths (non-string / empty — nothing to judge) block conservatively.
|
|
105
100
|
// Known paths are judged per target: resolve against the session cwd first, then
|
|
@@ -112,20 +107,23 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
|
|
|
112
107
|
if (typeof p !== "string" || p.trim() === "") { blocked = true; continue }
|
|
113
108
|
const abs = resolve(agent.cwd, p)
|
|
114
109
|
const conv = declarationForTarget(abs)
|
|
115
|
-
if (!conv
|
|
110
|
+
if (!conv) continue // 出辖(祖先链无档)⇒ 放行(零改)
|
|
111
|
+
if (faceOf(abs) !== "product") continue // 面判单源(`write-face.mjs`)——文档面 / 出辖放行
|
|
116
112
|
blocked = true
|
|
117
113
|
if (!noteConv && !conv.declared) noteConv = conv
|
|
118
114
|
}
|
|
119
115
|
if (blocked) {
|
|
120
116
|
// Undeclared project → point at ITS declaration file (§4.3 降级可见契约; #1102).
|
|
117
|
+
// 文案不列段名:本支只在 `!conv.declared` 时发,而 `declared` 是值比较(`buildDeclaration`)
|
|
118
|
+
// ⇒ 未声明 ⇒ `codePaths` 与缺省逐项相等 = 空。默认段自 2026-11-10 起清空(KD-M1-31),
|
|
119
|
+
// 原先 `code paths: ${…join}` 的空集渲染会印出一句残句,故改述判据来源(兜底分类)。
|
|
121
120
|
const convNote = noteConv
|
|
122
|
-
? ` — this path
|
|
121
|
+
? ` — this path fell through to product code (no code segment is declared: code paths are empty); declare project conventions in ${manifestFilePath(noteConv.root)} to adjust.`
|
|
123
122
|
: ""
|
|
124
123
|
prepared.push({
|
|
125
124
|
toolCall, tool, denied: true,
|
|
126
125
|
reason: "engineering design gate",
|
|
127
|
-
hint: `Engineering mode: write the design document first(location per your project's document conventions), then call advisor with type='design' to review it, and wait for user approval. Implementation is done by eng-coder subagents.${convNote}
|
|
128
|
-
`If this is a light-channel code pen: the gate looks for the round from the session anchor and its direct subdirectories — book the round first (an in-flight batch record plus a 在途 ledger row carrying 「收尾链待跑」 pointing at the record); code pens pass once that is on disk.`,
|
|
126
|
+
hint: `Engineering mode: write the design document first(location per your project's document conventions), then call advisor with type='design' to review it, and wait for user approval. Implementation is done by eng-coder subagents.${convNote}`,
|
|
129
127
|
})
|
|
130
128
|
continue
|
|
131
129
|
}
|
|
@@ -164,6 +162,21 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
|
|
|
164
162
|
}
|
|
165
163
|
}
|
|
166
164
|
|
|
165
|
+
// 写锁(第三道 · 2026-11-03 笔-账绑定批 · 设计档 §2.3):本笔报的 `ledger:"#N"` 必须是**目标所属项目**
|
|
166
|
+
// 台账里一条 `status = 在途` 的行。位次 = 既有两道之后(既有拒因先报);判序 = 先判目标所属项目
|
|
167
|
+
// (出辖 ⇒ 门不管),再按号查该根台账;台账读不到 ⇒ 拒(业务门)。
|
|
168
|
+
// 入口集 = 十一把(写盘七件 + `bash` ∥ `execute` + `memory` + `ssh`)——`bash` ∥ `execute`
|
|
169
|
+
// 与写盘工具同一判据、不按命令内容分类(决策 36);`ssh` 只对 `get` 要号。`git` **不在集内**(决策 37 改判):
|
|
170
|
+
// 它不落新字节,写型与只读同为不要号 ⇒ 本门不问它的 action;`manifest` **不在集内**(决策 44):本门自己要
|
|
171
|
+
// 读它写的那份档(取根 ∥ 写权表),把它也放在门后即构成环 ⇒ 三动作一概不要号。
|
|
172
|
+
// 只在工程模式生效(`agent.config.agent.engineering`)∥ 只在 depth 0(子代理走既有 token 门)。
|
|
173
|
+
// 路径集与 `args.ledger` 由判据函数自己取(调形只传 tool + toolName + args)。
|
|
174
|
+
const ledgerConflict = await ledgerBindWriteConflict(agent, depth, tool, toolCall.name, args)
|
|
175
|
+
if (ledgerConflict) {
|
|
176
|
+
prepared.push({ toolCall, tool, denied: true, reason: "ledger binding", hint: ledgerConflict.message })
|
|
177
|
+
continue
|
|
178
|
+
}
|
|
179
|
+
|
|
167
180
|
// Readonly tools (and autoApprove — the short-circuit, unchanged for the
|
|
168
181
|
// whole batch too) skip the permission stage entirely.
|
|
169
182
|
// AGENT-LOOP-SUBAGENT.md §6.7.6 D-E3 task-domain authorization (spawn-time): an eng-coder child's
|