@thincoder/core 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +10 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +54 -9
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -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
|
|
@@ -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"),
|
|
@@ -35,8 +35,12 @@ export function docSetKey(documents, cwd) {
|
|
|
35
35
|
|
|
36
36
|
/** **写门面**评审根的 docRoot 键集(`agent/write-gate.mjs` 的 `resolveReviewTargetPaths` 消费)——
|
|
37
37
|
* 设计评审**受理面不再消费**本键集(受理 = 项目内现存 `.md`,判据单源 = `ADVISOR-GUARDS.md` §12)。
|
|
38
|
-
* 2026-10-04 自 `agent/write-gate.mjs` 迁入(键集本体零变;write-gate 同名再出口)。
|
|
39
|
-
|
|
38
|
+
* 2026-10-04 自 `agent/write-gate.mjs` 迁入(键集本体零变;write-gate 同名再出口)。
|
|
39
|
+
*
|
|
40
|
+
* **六层**(`docs/core/design/MANIFEST.md` §2.5「键集」条):末位 `standards` = 标准层(目录语义,
|
|
41
|
+
* 见同档 §2.12)。键集只在本处改——写面 `agent/write-face.mjs`、评审候选扫描、文档锚点图
|
|
42
|
+
* `doc-graph.mjs` 三处共用这一份,不各持字面(KD-M1-64)。 */
|
|
43
|
+
export const REVIEW_ROOT_KEYS = ["requirements", "specs", "design", "modules", "batches", "standards"]
|
|
40
44
|
|
|
41
45
|
/**
|
|
42
46
|
* 写门评审根解析单点(按用点形——2026-09-21 收口 · 台账 #828;2026-10-04 自 `agent/write-gate.mjs`
|
|
@@ -93,7 +97,7 @@ export function resolveReviewDocPaths(documents, cwd) {
|
|
|
93
97
|
for (const doc of (documents ?? [])) {
|
|
94
98
|
if (typeof doc !== "string" || !doc.trim()) continue
|
|
95
99
|
const abs = /^[a-zA-Z]:[\\/]/.test(doc) || doc.startsWith("/") || doc.startsWith("\\\\")
|
|
96
|
-
const r = resolvePathTarget(cwd, doc, { kind: "file", order: "root-first",
|
|
100
|
+
const r = resolvePathTarget(cwd, doc, { kind: "file", order: "root-first", scanBases })
|
|
97
101
|
if (r.state === "ambiguous") { invalid.push({ doc, resolved: null, reason: "ambiguous-path", candidates: r.candidates }); continue }
|
|
98
102
|
// 相对形 ∧ 锚无项目根 ⇒ 无基可挂(受理判据「必须在项目内」)——**与盘上有没有那档无关**:
|
|
99
103
|
// 同一锚态同一个词(KD-8),否则拒因词成了磁盘状态的函数。
|
|
@@ -103,6 +107,9 @@ export function resolveReviewDocPaths(documents, cwd) {
|
|
|
103
107
|
invalid.push({ doc, resolved: r.tried?.[0] ?? null, reason: "not-doc-file", sameName: r.sameName })
|
|
104
108
|
continue
|
|
105
109
|
}
|
|
110
|
+
// 其余非 `resolved` 态(`unverified` ∥ `outOfDomain`):本面不传 `declaredRepos` / `domainRoots`,两者今天都不会出现,
|
|
111
|
+
// 但消费面必须**总覆盖**——拿不到 `abs` 的态一律按「解析无果」拒(fail-closed),不让 undefined 流进 `isInside`。
|
|
112
|
+
if (r.state !== "resolved") { invalid.push({ doc, resolved: null, reason: "dangling-path" }); continue }
|
|
106
113
|
const p = r.abs
|
|
107
114
|
if (!abs && !isInside(p, view.root)) { invalid.push({ doc, resolved: p, reason: "outside-project" }); continue }
|
|
108
115
|
if (abs && !owningProject(p, cwd)) { invalid.push({ doc, resolved: p, reason: "outside-project" }); continue }
|
|
@@ -121,10 +128,16 @@ export function scopeAdvisorMirror(agent, run) {
|
|
|
121
128
|
agent._advisorResponseAnchor = run.historyAnchorIdx ?? null
|
|
122
129
|
}
|
|
123
130
|
|
|
124
|
-
/** #949(② 投递水印):响应表取件下界 =
|
|
125
|
-
*
|
|
131
|
+
/** #949(② 投递水印):响应表取件下界 = 投递刻的线尾位置 `{ turn, msg }`(外层最后一个轮元素 + 它内层的长度;
|
|
132
|
+
* 消费面前向取首表)。位置形不存拍平下标——拍平下标在每次结构编辑后全部漂。
|
|
133
|
+
* 调用点:async `injectAsyncResult`(pushInject 后)∥ sync record-results 记账块;
|
|
126
134
|
* run 缺省 / 非对象(legacy 直调)⇒ 零写(回落全文倒扫)。 */
|
|
127
135
|
export function noteReviewDelivered(agent, run) {
|
|
128
136
|
if (!run || typeof run !== "object") return
|
|
129
|
-
|
|
137
|
+
const h = Array.isArray(agent?.history) ? agent.history : []
|
|
138
|
+
const last = h.at(-1)
|
|
139
|
+
run.historyAnchorIdx = {
|
|
140
|
+
turn: h.length - 1,
|
|
141
|
+
msg: Array.isArray(last?.messages) ? last.messages.length : 0,
|
|
142
|
+
}
|
|
130
143
|
}
|
package/agent-tools/settings.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 走显式形状表(_NULL_LEAF_SHAPES 相等面 / _SIBLING_SHAPES 存在性面——按各自真实消费形态
|
|
13
13
|
* 校验,完备性机械锁 + 一次性警告;SETTINGS-TOOL.md §8);set 侧效走审批门(dispatch 动作级分类)。
|
|
14
14
|
*/
|
|
15
|
-
import { DEFAULTS, configPath, promoteAgentViews, writeConfigAtomic } from "../config.mjs"
|
|
15
|
+
import { DEFAULTS, WORK_MODES, configPath, promoteAgentViews, resolveWorkMode, setConfigWorkMode, writeConfigAtomic } from "../config.mjs"
|
|
16
16
|
import { DESC } from "../tools/shared.mjs" // #15 描述外置:文本单点 = tool-docs/settings.md
|
|
17
17
|
|
|
18
18
|
/** 敏感键段判定(完整点分路径的段级匹配——两句取或:词表段 ∨ 开口键族段;SETTINGS-TOOL.md §2.4)。
|
|
@@ -164,6 +164,20 @@ function _checkAdvisorTimeout(value) {
|
|
|
164
164
|
* ③ 未知键 → 原样通过(全量域)。
|
|
165
165
|
*/
|
|
166
166
|
function _checkKnownKeyValue(path, value) {
|
|
167
|
+
if (path === "agent.engineering") {
|
|
168
|
+
throw new Error("settings set: agent.engineering is derived from agent.mode and cannot be written directly")
|
|
169
|
+
}
|
|
170
|
+
if (path === "agent.mode" && !WORK_MODES.includes(value)) {
|
|
171
|
+
throw new Error(`settings set: agent.mode expects one of ${WORK_MODES.join(", ")} — got ${_shownValue(path, value)}`)
|
|
172
|
+
}
|
|
173
|
+
if (path === "agent" && value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
174
|
+
if (Object.hasOwn(value, "engineering")) {
|
|
175
|
+
throw new Error("settings set: agent.engineering is derived from agent.mode and cannot be written through an agent object")
|
|
176
|
+
}
|
|
177
|
+
if (Object.hasOwn(value, "mode") && !WORK_MODES.includes(value.mode)) {
|
|
178
|
+
throw new Error(`settings set: agent.mode expects one of ${WORK_MODES.join(", ")} — got ${_shownValue("agent.mode", value.mode)}`)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
167
181
|
if (path === "agent.advisor.timeoutMs" || path === "advisor.timeoutMs") return _checkAdvisorTimeout(value)
|
|
168
182
|
if ((path === "agent.advisor" || path === "advisor") && value !== null && typeof value === "object" && !Array.isArray(value) && "timeoutMs" in value) {
|
|
169
183
|
_checkAdvisorTimeout(value.timeoutMs) // 整段赋值腿(两个段名):对象内该键同规则校验(§2.6)
|
|
@@ -307,6 +321,7 @@ export function settingsTool(opts = {}) {
|
|
|
307
321
|
// set
|
|
308
322
|
if (!args.key || args.value === undefined) throw new Error("settings set: key and value are required")
|
|
309
323
|
const value = parseValue(args.value)
|
|
324
|
+
const sessionMode = resolveWorkMode(config.agent)
|
|
310
325
|
// 已知键校验(形状表两表都查 + 派生类型表——SETTINGS-TOOL.md §8.3;未知键 JSON 原样)
|
|
311
326
|
_checkKnownKeyValue(String(args.key), value)
|
|
312
327
|
// 写盘(D-F5b:磁盘真相最小化——默认不固化;冲突/畸形抛错,内存不热应用(零虚假成功))+
|
|
@@ -340,11 +355,17 @@ export function settingsTool(opts = {}) {
|
|
|
340
355
|
setKeyPath(config, promotedPath, value) // 子键 set:键级同步(与 null 腿同一种「同一子键」口径)
|
|
341
356
|
}
|
|
342
357
|
}
|
|
358
|
+
// agent.mode persisted here is the new-session default. Keep the existing session's sole
|
|
359
|
+
// mode and its derived boolean unchanged; session commands and host controls switch slots.
|
|
360
|
+
const modeDefaultWrite = args.key === "agent.mode" || args.key === "agent"
|
|
361
|
+
if (modeDefaultWrite) setConfigWorkMode(config, sessionMode)
|
|
343
362
|
const sensitive = isSensitiveKey(String(args.key))
|
|
344
363
|
const shown = sensitive ? MASKED : value
|
|
345
364
|
const suffix = value === null
|
|
346
365
|
? " — key removed(键已删除——回退默认)"
|
|
347
|
-
: sensitive ? " — stored(值不回显)"
|
|
366
|
+
: sensitive ? " — stored(值不回显)"
|
|
367
|
+
: modeDefaultWrite ? " — persisted as the new-session default(当前会话不变)"
|
|
368
|
+
: " — persisted + hot-applied(运行中已生效)"
|
|
348
369
|
return `settings set: ${args.key} = ${shown} (${_kindOf(value)})${suffix}`
|
|
349
370
|
},
|
|
350
371
|
}
|
package/agent-tools/skill.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { loadSkills, readSkill } from "../skills.mjs"
|
|
2
2
|
import { escapeXml } from "../agent.mjs"
|
|
3
3
|
import { DESC } from "../tools/shared.mjs"
|
|
4
|
+
// C 段(累积内容)载体:按名字追加、同名替换——技能块每请求都在(`CONTEXT-COMPACTION.md` §1.1 注入三段)。
|
|
5
|
+
import { retain } from "../context.mjs"
|
|
4
6
|
|
|
5
7
|
// ─── skill loader 注入缝(#88——「同步 loader 面按核内结构归一」的端侧覆盖范围)──────────
|
|
6
8
|
/**
|
|
@@ -41,9 +43,9 @@ export const skillTool = {
|
|
|
41
43
|
return skills.map((s) => `- ${s.name}: ${s.description}`).join("\n")
|
|
42
44
|
}
|
|
43
45
|
if (!args.name) return "Error: skill name required for 'load' action."
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
if (ctx.agent.
|
|
46
|
+
// 已加载判据按名字读 C 段(不扫机读线——注入不在线上);压缩后找不到是原语义(块随累积段一直在,
|
|
47
|
+
// 本就与机读线无关)。
|
|
48
|
+
if (ctx.agent._retained?.some?.((e) => e?.name === args.name)) {
|
|
47
49
|
return `Skill "${args.name}" is already loaded in this conversation — follow the instructions in the existing <skill-loaded> block above. Do not reload it.`
|
|
48
50
|
}
|
|
49
51
|
const content = await readSkillFn(ctx.agent.cwd, args.name)
|
|
@@ -51,11 +53,8 @@ export const skillTool = {
|
|
|
51
53
|
const available = skills.map((s) => s.name).join(", ")
|
|
52
54
|
return `Error: skill "${args.name}" not found. Available: ${available || "(none)"}`
|
|
53
55
|
}
|
|
54
|
-
//
|
|
55
|
-
ctx.agent.
|
|
56
|
-
ctx.agent._pendingReminders.push(
|
|
57
|
-
`<skill-loaded name="${args.name}" source=".thincoder/skills/${args.name}.md">\n${escapeXml(content)}\n</skill-loaded>\n\nFollow the skill's instructions above for the current task.`
|
|
58
|
-
)
|
|
56
|
+
// 技能内容进 C 段累积载体(按名字追加、同名替换——装配时每请求都在)
|
|
57
|
+
retain(ctx.agent, args.name, `<skill-loaded name="${args.name}" source=".thincoder/skills/${args.name}.md">\n${escapeXml(content)}\n</skill-loaded>\n\nFollow the skill's instructions above for the current task.`)
|
|
59
58
|
return `Skill "${args.name}" loaded. Instructions will appear in the next message.`
|
|
60
59
|
},
|
|
61
60
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* spawn-gates.mjs — M5 委派与 spawn 门新门禁统一落点(ENGINEERING-MODE-V2-MODULE-DELEGATION §2.3):
|
|
3
3
|
* 全部新增门禁逻辑集中于此——装配点(buildSpawnChild / normalizeFileList)只加 import 调用。
|
|
4
4
|
* 已实现:F2(round 枚举 + 任务书参数门/拼装)· F6(files 声明面拦截谓词)。
|
|
5
|
-
* 2026-10-24(AGENT-LOOP-SUBAGENT.md §6.22
|
|
6
|
-
*
|
|
5
|
+
* 2026-10-24(AGENT-LOOP-SUBAGENT.md §6.22):工程角色零任务书文本参数——八个自由文本键
|
|
6
|
+
* (键在场即拒)命中即点名拒收;任务书 = 绑定批档、按角色切片(2026-11-15 §8.1:eng-coder 取 §2,
|
|
7
|
+
* eng-designer 取 §1 + §2);
|
|
7
8
|
* 非工程角色(explore / plan / coder / tester)保持四项核心 + `scope`。
|
|
8
9
|
* 裁撤(2026-09-17 主 agent 裁定——不落代码):
|
|
9
10
|
* - F4 修复轮窄带:全量勘察散文 marker 不可机判(误拒风险不可接受)→ 由 F2 的 round 参数承载轮次语义;
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
export const ROUND_VALUES = ["initial", "fix"]
|
|
19
20
|
|
|
20
21
|
/** 任务书样例内容(供人照抄;不是门的判据——门只判存在 / 类型 / 非空):非工程角色
|
|
21
|
-
* = 四项核心 + `scope`(工程角色无任务书文本参数——任务书 =
|
|
22
|
+
* = 四项核心 + `scope`(工程角色无任务书文本参数——任务书 = 绑定批档,按角色切片(§8.1))。 */
|
|
22
23
|
const TASK_BOOK_CORE_MIN = {
|
|
23
24
|
goal: "实现批准设计(样例任务书——四项核心 + `scope` 齐备)。",
|
|
24
25
|
knownFacts: "设计已评审通过、token 已签发、批次档在册。",
|
|
@@ -53,7 +54,7 @@ export function validateRoundParam(args) {
|
|
|
53
54
|
/** 工程角色名集(单一判据 = 是否有写权 ⇒ 只应有唯一任务来源——AGENT-LOOP-SUBAGENT.md §6.22)。 */
|
|
54
55
|
const ENGINEERING_ROLES = new Set(["eng-coder", "eng-designer"])
|
|
55
56
|
|
|
56
|
-
/** 角色 ∈ 工程角色(任务书 =
|
|
57
|
+
/** 角色 ∈ 工程角色(任务书 = 绑定批档,按角色切片(§8.1);零任务书文本参数)。 */
|
|
57
58
|
export function isEngineeringRole(role) {
|
|
58
59
|
return ENGINEERING_ROLES.has(role)
|
|
59
60
|
}
|
|
@@ -86,8 +87,8 @@ export function rejectEngFreeTextParams(args, role) {
|
|
|
86
87
|
const required = ENG_REQUIRED_NAMES[role] ?? "role · batchDoc (readable) · round"
|
|
87
88
|
throw new Error(
|
|
88
89
|
`Spawn task-channel gate (role='${role}'): ${names}. ` +
|
|
89
|
-
`An engineering spawn carries NO task-book text parameters — the task book is batch record
|
|
90
|
-
`Put everything the child needs into §2 before spawning; a thin
|
|
90
|
+
`An engineering spawn carries NO task-book text parameters — the task book is the bound batch record (batchDoc), sliced per role into the spawn system block (eng-coder: §2; eng-designer: §1 + §2). ` +
|
|
91
|
+
`Put everything the child needs into ${role === "eng-designer" ? "the record (§1 rulings bind; §2 is your pen)" : "§2"} before spawning; a thin section earns a bounce, not a supplement. ` +
|
|
91
92
|
`Required for role='${role}': ${required}.`)
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -103,7 +104,7 @@ export const TASK_BOOK_PARAMS = {
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
/** 角色 → 该角色的任务书名集(四项核心 + `scope`;序 = 拼装序:第五项插在 `knownFacts` 之后)。
|
|
106
|
-
* 工程角色返回空集——它们没有任务书文本参数(任务书 =
|
|
107
|
+
* 工程角色返回空集——它们没有任务书文本参数(任务书 = 绑定批档,按角色切片(§8.1))。 */
|
|
107
108
|
export function taskBookParamsFor(role) {
|
|
108
109
|
if (isEngineeringRole(role)) return []
|
|
109
110
|
const core = TASK_BOOK_PARAMS.core
|
|
@@ -152,7 +153,7 @@ export function validateTaskBookParams(args, role) {
|
|
|
152
153
|
|
|
153
154
|
/** 非工程角色任务书 → 子代理任务书文本(**非门禁**,纯拼装):按 `taskBookParamsFor(role)` 固定序
|
|
154
155
|
* + 标签,空值跳过,`\n\n` 分隔。拼装单源 = 本函数——子代理 input、权限预览与探针判官同源。
|
|
155
|
-
* 工程角色名集为空 ⇒ 返回空串(任务书 =
|
|
156
|
+
* 工程角色名集为空 ⇒ 返回空串(任务书 = 绑定批档,按角色切片(§8.1),运行时不拼装——KD-SC5)。 */
|
|
156
157
|
export function composeTaskBookBrief(args, role) {
|
|
157
158
|
const a = args ?? {}
|
|
158
159
|
const parts = []
|
|
@@ -163,39 +164,28 @@ export function composeTaskBookBrief(args, role) {
|
|
|
163
164
|
return parts.join("\n\n")
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
/**
|
|
167
|
-
* F6 过程档 basename 族(父侧维护文件——AGENT-LOOP-SUBAGENT.md §6.9 R26 同族扩展):
|
|
168
|
-
* CHANGELOG.md。(台账 = 用户数据目录键控库——项目内无文件,不再入族;老台账族 todo.md /
|
|
169
|
-
* todo-archive.md / checklist 族随 M2 SQLite 化 + M7 checklist 废除退役。)
|
|
170
|
-
* 大小写不敏感全名匹配(路径任意层——归一化在调用点 normalizeFileList 已做)。
|
|
171
|
-
*/
|
|
172
|
-
const PROCESS_BASENAMES = new Set(["changelog.md"])
|
|
173
|
-
|
|
174
167
|
/**
|
|
175
168
|
* 写域 basename(**模式无关**——#33 二道防线;`PROJECT-MANIFEST.json` 是项目级状态档,其写门对任何会话生效;设计 docs/core/design/MANIFEST.md §2.5 / KD-M1-14):
|
|
176
169
|
* PROJECT-MANIFEST.json = M1 项目状态档——写门唯主 agent(`manifest.mjs` `writeManifest` 的
|
|
177
170
|
* `writer` 闸,fail-closed);本常量 = `files` 声明面**第二道防线**(子代理无法把该路径声明为
|
|
178
171
|
* 写域)。字面量(匹配前已大小写归一;**不** import `MANIFEST_REL`——保本模块「叶子·零 import」
|
|
179
|
-
* 性质;单源指针 = `thincoder-core/manifest.mjs
|
|
180
|
-
* ——过程档 = 父侧对账职责;本档 = 写门唯主 agent。
|
|
172
|
+
* 性质;单源指针 = `thincoder-core/manifest.mjs`)。本谓词唯一的一支。
|
|
181
173
|
*/
|
|
182
174
|
const MANIFEST_BASENAME = "project-manifest.json"
|
|
183
175
|
|
|
184
176
|
/**
|
|
185
|
-
* F6 files 声明面拦截谓词(ENGINEERING-MODE-V2-MODULE-DELEGATION §2.2
|
|
177
|
+
* F6 files 声明面拦截谓词(ENGINEERING-MODE-V2-MODULE-DELEGATION §2.2):项目状态档
|
|
186
178
|
* → 收集全部违规后抛合并错误(fail-closed——错误即工具结果 JSON——无排队残留)。目录声明不在本谓词
|
|
187
179
|
* (normalizeFileList 循环内先行拒——错误序不变)。调用点 = normalizeFileList(subagent-scheduler.mjs——
|
|
188
|
-
*
|
|
180
|
+
* 本谓词在循环后跑——目录错误先于本谓词错误)。
|
|
189
181
|
* 产品面路径(含仓根 `scripts/**` · `test/**`)本就该进 `files` 声明面——工程工具面退役后不再有这一臂。
|
|
190
182
|
*/
|
|
191
|
-
export function
|
|
183
|
+
export function rejectParentOwnedPaths(files) {
|
|
192
184
|
const violations = []
|
|
193
185
|
for (const f of Array.isArray(files) ? files : []) {
|
|
194
186
|
const segs = String(f).replace(/\\/g, "/").split("/").filter((s) => s)
|
|
195
187
|
const base = (segs[segs.length - 1] ?? "").toLowerCase()
|
|
196
|
-
if (
|
|
197
|
-
violations.push(`Parent-side maintained file ${f} must not be listed in files — reconciliation is the parent's duty; use the design-doc path if you need to edit a design doc`)
|
|
198
|
-
} else if (base === MANIFEST_BASENAME) {
|
|
188
|
+
if (base === MANIFEST_BASENAME) {
|
|
199
189
|
violations.push(`Manifest file ${f} must not be listed in files — PROJECT-MANIFEST.json is the project state manifest and the main agent is its only writer (M1 write gate); this files-domain check is the second line of defense`)
|
|
200
190
|
}
|
|
201
191
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ssh-session.mjs — SSH 会话面单点(池 ∥ 生命周期 ∥ 动作 ∥ 凭据窗 ∥ 非密预填)。
|
|
3
3
|
* 设计 = `docs/core/design/TOOLS.md` §6.22(D-TO17/D-TO18 · 台账 #1436);需求 = `docs/core/requirements/TOOLS.md` §4.8。
|
|
4
4
|
* 工具面 = `tools/ssh.mjs`(薄接线);传输面 = `agent-tools/ssh-transport.mjs`(askpass 链 / 沉降 / 遮蔽 / 帽
|
|
5
|
-
* ——拆档由 =
|
|
5
|
+
* ——拆档由 = 当年机制档已过 500 行,§6.22 落点表候选拆分)。
|
|
6
6
|
*
|
|
7
7
|
* - 池:`_sshSessions`(照 `bash-async.mjs` 池先例——载体经 `carrierField` 吸收);帽 `SSH_SESSION_MAX = 4`
|
|
8
8
|
* 条存活会话;超限**显式拒**(零静默关旧)。
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
import { createWriteStream, mkdirSync, readFileSync, writeFileSync } from "node:fs"
|
|
23
23
|
import { join } from "node:path"
|
|
24
24
|
import { cleanupOldToolResults } from "../agent/helpers.mjs"
|
|
25
|
-
import {
|
|
25
|
+
import { pushInject, pushRecord } from "../context.mjs"
|
|
26
26
|
import { t } from "../i18n.mjs"
|
|
27
27
|
import { killProcessTree } from "../tools/process-tree.mjs"
|
|
28
28
|
import {
|
|
@@ -123,10 +123,13 @@ function armIdle(entry) {
|
|
|
123
123
|
const parent = entry.parent
|
|
124
124
|
hardClose(entry, "closed", "consumed")
|
|
125
125
|
if (parent?.history) {
|
|
126
|
-
|
|
126
|
+
const msg = {
|
|
127
127
|
role: "user",
|
|
128
128
|
content: `[System reminder: ssh session ${idLabel(entry)} (${escapeLite(entry.host)}) was closed after ${idleS}s idle (no send/read). Open a new session if you still need it.]`,
|
|
129
|
-
}
|
|
129
|
+
}
|
|
130
|
+
// B 段:一次性投递走待发队,持久写入只落人读线(机读线零触)。
|
|
131
|
+
pushInject(parent, msg)
|
|
132
|
+
pushRecord(parent, msg)
|
|
130
133
|
}
|
|
131
134
|
}, idleMs())
|
|
132
135
|
entry.idleTimer.unref?.()
|
|
@@ -425,7 +428,7 @@ export { SSH_SETTLE_MS, SSH_TIMEOUT_MS, SSH_RETURN_CAP }
|
|
|
425
428
|
export { _setSshBinaryForTest, _setSshConfigDirForTest } from "./ssh-transport.mjs"
|
|
426
429
|
|
|
427
430
|
// 保存凭据管理面(§6.22 ⑫):`credentials` / `forget` 实体 = `ssh-vault.mjs`(核单点——本档只转口;
|
|
428
|
-
// 拆档由 =
|
|
431
|
+
// 拆档由 = 当年机制档已过 500 行,§6.22 落点表候选拆分)。
|
|
429
432
|
export { credentialsSsh, forgetSsh } from "./ssh-vault.mjs"
|
|
430
433
|
// ─── 凭据判定单源(D-TO25:`connect` ∥ 传输面两处共用)─────────────────────────
|
|
431
434
|
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ssh-text.mjs — SSH **可见文本面**单点(剥离 ∥ 归一 ∥ 遮蔽)。
|
|
3
|
+
*
|
|
4
|
+
* 2026-11-05 拆档族从 `ssh-transport.mjs` 外移:这三件是「字节 → 可见文本」的纯函数链,不含子进程、
|
|
5
|
+
* 计时与就绪判定——传输面其余部分全是进程与等待。设计 = `docs/core/design/TOOLS.md` §6.22(D-TO23)。
|
|
6
|
+
*
|
|
7
|
+
* 搬家形 = 具名符号整块外移、体逐字、字段名零改:`createStripper` ∥ `normalizeText` ∥ `createMask` ∥
|
|
8
|
+
* `escapeNote` 与两件私有常量(`INVISIBLE_SPLIT` ∥ `MASK_SEG_MIN`)。原档 import 回来并原样再导出
|
|
9
|
+
* ⇒ `ssh-session.mjs` / `ssh-transfer.mjs` / `ssh-vault.mjs` 的 import 行零改。
|
|
10
|
+
*
|
|
11
|
+
* **`flushEscapes` 没跟出来**:它的体除了读 `strippers` 的收场形态,还把交出的字节经 `handleChunk`
|
|
12
|
+
* 汇入 `logStream` / `buf` / 等待者(传输面的运行时汇聚点,仍住原档)——搬过来就得反向 import 原档,
|
|
13
|
+
* 而两档互 import 在 ESM 下会成环。它的读者面全在原档内部(无档外消费者),落点不改导出面。
|
|
14
|
+
*
|
|
15
|
+
* 依赖单向:`本档 ← ssh-transport.mjs`(本档零 import、零 fs、零状态)。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** 不可见处(遮蔽比较面的切段器——与剥离同一类目:CSI ∥ ESC+1 ∥ 任一控制字符)。 */
|
|
19
|
+
const INVISIBLE_SPLIT = /\x1b\[[\x20-\x3f]*[\x40-\x7e]|\x1b[^\x1b]?|[\x00-\x1f\x7f]/
|
|
20
|
+
|
|
21
|
+
/** 遮蔽分段下限(§6.22 ③「`≥ 4` 为选定策略值」:3 字符以下与正常输出撞面过高)。 */
|
|
22
|
+
const MASK_SEG_MIN = 4
|
|
23
|
+
|
|
24
|
+
/** 有状态剥离器(§6.22 ③):三类序列 CSI ∥ OSC ∥ 单字符控制 + `\r\n`∥裸 `\r` 归 `\n`。
|
|
25
|
+
* 状态跨 chunk 携带(序列被 chunk 边界切开不残留成字面);三类之外的序列(DCS / APC 等)按
|
|
26
|
+
* 单字符控制处理——头字节剥掉,体内字节当可见文本如实交出(设计「表外序列的出口」)。
|
|
27
|
+
* `push` = 返回边界(状态保留);`end` = 收场(硬超时 ∥ close ∥ 会话终结:尾部半条序列丢弃并计一次)。 */
|
|
28
|
+
export function createStripper() {
|
|
29
|
+
let state = "ground" // ground ∥ esc ∥ csi ∥ osc ∥ oscEsc ∥ charset
|
|
30
|
+
let pendingCr = false // chunk 尾的 `\r`(下一片首字为 `\n` ⇒ 仍归一条——跨 chunk 的 CRLF)
|
|
31
|
+
const scan = (text) => {
|
|
32
|
+
const s = String(text ?? "")
|
|
33
|
+
let out = ""
|
|
34
|
+
let i = 0
|
|
35
|
+
while (i < s.length) {
|
|
36
|
+
const ch = s[i]
|
|
37
|
+
if (pendingCr) {
|
|
38
|
+
pendingCr = false
|
|
39
|
+
out += "\n"
|
|
40
|
+
if (ch === "\n") { i += 1; continue }
|
|
41
|
+
}
|
|
42
|
+
if (state === "esc") {
|
|
43
|
+
state = "ground"
|
|
44
|
+
if (ch === "[") state = "csi"
|
|
45
|
+
else if (ch === "]") state = "osc"
|
|
46
|
+
else if (ch === "(" || ch === ")" || ch === "*" || ch === "+") state = "charset"
|
|
47
|
+
else if (ch === "\x1b") state = "esc"
|
|
48
|
+
i += 1
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
if (state === "charset") { state = "ground"; i += 1; continue } // `ESC ( 0` 字符集指定(既有覆盖不回归)
|
|
52
|
+
if (state === "csi") {
|
|
53
|
+
const c = ch.charCodeAt(0)
|
|
54
|
+
if (c >= 0x20 && c <= 0x3f) { i += 1; continue } // 参数 ∥ 中间字节
|
|
55
|
+
if (c >= 0x40 && c <= 0x7e) { state = "ground"; i += 1; continue } // 终字节
|
|
56
|
+
state = "ground" // 类外字 ⇒ 序列作废,本字按常规面重判(不吞可见字节)
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
if (state === "osc") {
|
|
60
|
+
if (ch === "\x07") { state = "ground"; i += 1; continue }
|
|
61
|
+
if (ch === "\x1b") { state = "oscEsc"; i += 1; continue }
|
|
62
|
+
i += 1
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
if (state === "oscEsc") {
|
|
66
|
+
state = "ground"
|
|
67
|
+
if (ch === "\\") { i += 1; continue } // `ESC \` = ST
|
|
68
|
+
state = "osc" // 非 ST ⇒ 本字仍在 OSC 体内(ESC 已丢弃,体内字节本就要丢)
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
if (ch === "\x1b") { state = "esc"; i += 1; continue }
|
|
72
|
+
if (ch === "\r") {
|
|
73
|
+
if (i + 1 >= s.length) { pendingCr = true; i += 1; continue }
|
|
74
|
+
out += "\n"
|
|
75
|
+
i += s[i + 1] === "\n" ? 2 : 1
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
if (ch === "\n" || ch === "\t") { out += ch; i += 1; continue }
|
|
79
|
+
const code = ch.charCodeAt(0)
|
|
80
|
+
if (code < 0x20 || code === 0x7f) { i += 1; continue } // BEL ∥ 退格 ∥ 其余 C0(保留 `\n` / `\t`)
|
|
81
|
+
out += ch
|
|
82
|
+
i += 1
|
|
83
|
+
}
|
|
84
|
+
return out
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
/** 喂一片(返回可交出文本;半条序列留给下一片)。 */
|
|
88
|
+
feed(text) { return scan(text) },
|
|
89
|
+
/** 收场:尾部半条序列丢弃并计一次;其前后的可见字节照常交出。 */
|
|
90
|
+
end(text = "") {
|
|
91
|
+
let out = scan(text)
|
|
92
|
+
if (pendingCr) { out += "\n"; pendingCr = false }
|
|
93
|
+
const dropped = state === "ground" ? 0 : 1
|
|
94
|
+
state = "ground"
|
|
95
|
+
return { text: out, dropped }
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 同一归一(无状态旁路——遮蔽比较面用:秘密值先过控制字节剥离 + CRLF 归一)。 */
|
|
101
|
+
export function normalizeText(text) {
|
|
102
|
+
return createStripper().end(String(text ?? "")).text
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 秘密遮蔽过滤器:字面移除 + `len-1` 尾缓冲(跨 chunk 切分不泄;尾至沉降冲涮)。
|
|
106
|
+
* 比较面 = 与剥离同一归一(§6.22 ③):秘密值先归一、再按不可见处切段(段长 ≥ 4)——
|
|
107
|
+
* 裸字面匹配会漏掉夹控制字节 ∥ 被 chunk 切开的回显。 */
|
|
108
|
+
export function createMask() {
|
|
109
|
+
const secrets = []
|
|
110
|
+
let tail = ""
|
|
111
|
+
let keep = 0
|
|
112
|
+
return {
|
|
113
|
+
add(secret) {
|
|
114
|
+
const raw = String(secret ?? "")
|
|
115
|
+
if (!raw) return
|
|
116
|
+
const table = [normalizeText(raw), ...raw.split(INVISIBLE_SPLIT).filter((seg) => seg.length >= MASK_SEG_MIN)]
|
|
117
|
+
for (const s of table) {
|
|
118
|
+
if (!s || secrets.includes(s)) continue
|
|
119
|
+
secrets.push(s)
|
|
120
|
+
keep = Math.max(keep, s.length - 1)
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
push(text) {
|
|
124
|
+
let out = tail + String(text ?? "")
|
|
125
|
+
for (const s of secrets) out = out.split(s).join("")
|
|
126
|
+
if (out.length <= keep) { tail = out; return "" }
|
|
127
|
+
const emit = out.slice(0, out.length - keep)
|
|
128
|
+
tail = out.slice(out.length - keep)
|
|
129
|
+
return emit
|
|
130
|
+
},
|
|
131
|
+
/** 尾缓冲现行内容(**判据面用**:门①② 要看到已达字节——尾在 drain 时释放,判据不得被它推迟)。 */
|
|
132
|
+
peek() { return tail },
|
|
133
|
+
/** 沉降时冲涮尾缓冲:**只放行非秘密前缀段**(尾内最长可疑后缀一律扣下——整尾 ∥ 移位前缀
|
|
134
|
+
* 都不出返回面;扣下的至多 `秘密长-1` 字符,代价 < 前缀外泄)。 */
|
|
135
|
+
flush() {
|
|
136
|
+
const t = tail
|
|
137
|
+
tail = ""
|
|
138
|
+
if (!t) return ""
|
|
139
|
+
let cut = 0
|
|
140
|
+
for (const s of secrets) {
|
|
141
|
+
const max = Math.min(t.length, s.length - 1)
|
|
142
|
+
for (let L = 1; L <= max; L++) if (t.endsWith(s.slice(0, L))) cut = Math.max(cut, L)
|
|
143
|
+
}
|
|
144
|
+
return cut ? t.slice(0, t.length - cut) : t
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** 半条序列收场注记(§6.22 ③ flush②)——报告一次即清零。 */
|
|
150
|
+
export function escapeNote(entry) {
|
|
151
|
+
const n = entry.escDropped ?? 0
|
|
152
|
+
if (!n) return ""
|
|
153
|
+
entry.escDropped = 0
|
|
154
|
+
return `\n— ${n} incomplete escape sequence dropped`
|
|
155
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* `-O`;不自动换协议重试(D-TO27:同笔重试把「协议不对」这个可诊断事实埋在两次尝试之后)。
|
|
7
7
|
* - 凭据 = 与会话面**同一段判定**(`ssh-session.mjs` 的 `resolveSessionSecret`:探连 → 密文库 → 凭据窗),
|
|
8
8
|
* 零新凭据通道(D-TO25);askpass 包装档 / 环境 / 失败分类族全取 `ssh-transport.mjs` 既有导出。
|
|
9
|
-
* - 内容零入上下文(NS8):文件字节只经磁盘;回执 = 会话冠行 + 一行状态句,失败时附 stderr
|
|
9
|
+
* - 内容零入上下文(NS8):文件字节只经磁盘;回执 = 会话冠行 + 一行状态句,失败时附 stderr 尾段(600 characters = UTF-16 code units;截断在转义之前,读到的可能更长)。
|
|
10
10
|
* - 本地面(⑬ ②):本地路径展开 `~`(单源 `expand-home.mjs`)后解析成绝对路径 ⇒ `spawn` 的 `cwd` = 该档
|
|
11
11
|
* 所在目录、命令行只传**档名**——Windows 盘符的 `:` 与反斜杠都不进 scp 的参数位(scp 以首个 `:`
|
|
12
12
|
* 切分本地 / 远端);`get` 的父目录必须已在盘(**零建目录**:建目录即项目内一笔写,绕写门;落点也要
|