@thincoder/core 0.11.1 → 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 +46 -2
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +42 -25
- package/advisor/project-context.mjs +171 -42
- 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 +44 -3
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch.mjs +8 -3
- package/agent/family-tools.mjs +27 -12
- package/agent/helpers.mjs +122 -1
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +18 -1
- package/agent/run-stages.mjs +77 -32
- package/agent/run-start.mjs +37 -0
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +24 -11
- package/agent/spawn-child.mjs +38 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +30 -5
- 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-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- 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 +36 -47
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/batch-closeout.mjs +273 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +226 -17
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +169 -46
- package/agent-tools/batch-paths.mjs +29 -8
- 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 +379 -0
- package/agent-tools/batch-skeleton.mjs +192 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +182 -439
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +44 -17
- 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/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +9 -8
- package/agent-tools/escalate-async.mjs +2 -2
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +10 -3
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +9 -8
- package/agent-tools/ssh-session.mjs +2 -2
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-async.mjs +8 -9
- 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 +4 -4
- package/agent-tools/subagent-spawn.mjs +90 -110
- package/agent-tools/subagent.mjs +11 -10
- 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 +1 -1
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- 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 +149 -83
- package/conventions.mjs +11 -9
- package/declaration.mjs +31 -5
- 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/explore-distill.mjs +11 -5
- 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 +6 -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 +78 -19
- package/ledger-write-ops.mjs +130 -41
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/schema.mjs +2 -2
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +9 -6
- package/prompts/advisor-design.md +62 -21
- package/prompts/advisor-round1.md +34 -1
- package/prompts/advisor-round2.md +40 -7
- package/prompts/advisor-round3.md +39 -6
- package/prompts/common.md +14 -387
- package/prompts/consult-base.md +5 -1
- package/prompts/discipline-engineering.md +226 -51
- package/prompts/discipline-normal.md +4 -255
- 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 +21 -3
- package/prompts/persona-eng-designer.md +131 -169
- package/prompts/persona-engineering.md +142 -84
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +5 -1
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +3 -2
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +24 -7
- package/provider/responses.mjs +3 -1
- package/provider-flows.mjs +2 -2
- 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 +72 -17
- package/session-slot-write.mjs +37 -5
- package/session.mjs +24 -8
- package/skip-dirs.mjs +2 -2
- package/team-ledger.mjs +13 -9
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +167 -33
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -41
- 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 +52 -7
- 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 +1 -1
- package/tools/file.mjs +16 -8
- package/tools/git.mjs +24 -9
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +3 -1
- package/tools/patch.mjs +123 -43
- package/tools/shared.mjs +28 -27
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +203 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -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 = []
|
|
@@ -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
|
* 条存活会话;超限**显式拒**(零静默关旧)。
|
|
@@ -425,7 +425,7 @@ export { SSH_SETTLE_MS, SSH_TIMEOUT_MS, SSH_RETURN_CAP }
|
|
|
425
425
|
export { _setSshBinaryForTest, _setSshConfigDirForTest } from "./ssh-transport.mjs"
|
|
426
426
|
|
|
427
427
|
// 保存凭据管理面(§6.22 ⑫):`credentials` / `forget` 实体 = `ssh-vault.mjs`(核单点——本档只转口;
|
|
428
|
-
// 拆档由 =
|
|
428
|
+
// 拆档由 = 当年机制档已过 500 行,§6.22 落点表候选拆分)。
|
|
429
429
|
export { credentialsSsh, forgetSsh } from "./ssh-vault.mjs"
|
|
430
430
|
// ─── 凭据判定单源(D-TO25:`connect` ∥ 传输面两处共用)─────────────────────────
|
|
431
431
|
|
|
@@ -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
|
+
}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ssh-transport.mjs — SSH 传输面单点(askpass 链 ∥ 子进程 ∥ 沉降 ∥
|
|
2
|
+
* ssh-transport.mjs — SSH 传输面单点(askpass 链 ∥ 子进程 ∥ 沉降 ∥ 输出帽)。
|
|
3
3
|
* 设计 = `docs/core/design/TOOLS.md` §6.22(D-TO17/D-TO18 · 台账 #1436)。
|
|
4
4
|
*
|
|
5
|
-
* 拆档由 =
|
|
5
|
+
* 拆档由 = 设计轮判定机制档改前读数过 500(`docs/core/design/DOC-GRAPH.md` §3「行数档位口径」)——本档收**运行面**
|
|
6
6
|
* (与会话语义无关的传输原语),`ssh-session.mjs` 收**会话面**(池 / 生命周期 / 动作)。条目形
|
|
7
7
|
* (entry)由 `ssh-session.mjs` 定义并持有;本档只经其字段工作(`buf` / `mask` / `_waiters` /
|
|
8
8
|
* `promptRe` / `state` / `child` / `logStream` / `_notify` / `lastDataAt` / `bytes`)。
|
|
9
9
|
*
|
|
10
|
+
* 2026-11-05 拆档族再切一刀:**可见文本面**(剥离 ∥ 归一 ∥ 遮蔽 ∥ 收场注记)搬进同目录叶档
|
|
11
|
+
* `ssh-text.mjs`——本档只留进程、计时、四门与输出面。
|
|
12
|
+
*
|
|
10
13
|
* - askpass 链:包装档(Win `.cmd` ∥ POSIX `.sh` 0700)→ `tools/ssh-askpass.mjs` → stdout;秘密只经
|
|
11
14
|
* ssh 子进程环境 `TC_SSH_SECRET`(零入参 / 零落盘 / 零回显;环境经 `nodeChildEnv` 单点补 Electron 旗标)。
|
|
12
15
|
* - 终端噪声:有状态剥离(CSI ∥ OSC ∥ 单字符控制三类 + CRLF 归一;状态跨 chunk 携带)——落点 = 传输入口,
|
|
13
|
-
* **先剥离后遮蔽**;日志面 = 模型面同源(D-TO23
|
|
16
|
+
* **先剥离后遮蔽**;日志面 = 模型面同源(D-TO23)。剥离器与遮蔽器本体住 `ssh-text.mjs`,本档 import 消费。
|
|
14
17
|
* - 就绪判据:四门(待答标记 ∥ 提示符 ∥ 仍在吐 ∥ 硬超时 60 s);静默窗只作去抖(D-TO21)。
|
|
15
|
-
* - 遮蔽:写入的秘密对**捕获面与日志面**做字面移除(比较面 = 同一归一 + 按不可见处切段 ≥ 4
|
|
18
|
+
* - 遮蔽:写入的秘密对**捕获面与日志面**做字面移除(比较面 = 同一归一 + 按不可见处切段 ≥ 4)——
|
|
19
|
+
* 实现住 `ssh-text.mjs` 的 `createMask`。
|
|
16
20
|
* - 失败分类族(auth ∥ unreachable ∥ hostkey)照服务端 `src/sandbox/ssh.mjs` 同源判据。
|
|
17
21
|
* 模块图:→ config.mjs(configDir 缺省)· tools/shared.mjs(解码)· text-budget.mjs(截断本体)·
|
|
18
|
-
* tools/node-child.mjs(nodeChildEnv)· expand-home.mjs(`~` 展开单源——`identityFile`
|
|
19
|
-
*
|
|
22
|
+
* tools/node-child.mjs(nodeChildEnv)· expand-home.mjs(`~` 展开单源——`identityFile` 用)·
|
|
23
|
+
* ssh-text.mjs(可见文本面)——叶子向、无环(本档不 import `ssh-session.mjs`)。
|
|
20
24
|
*/
|
|
21
25
|
import { chmodSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs"
|
|
22
26
|
import { spawn } from "node:child_process"
|
|
@@ -26,6 +30,10 @@ import { expandHome } from "../expand-home.mjs"
|
|
|
26
30
|
import { makeDecoder } from "../tools/shared.mjs"
|
|
27
31
|
import { nodeChildEnv } from "../tools/node-child.mjs"
|
|
28
32
|
import { capText as capBudgetText, fillMarker } from "../text-budget.mjs"
|
|
33
|
+
// 可见文本面(剥离 ∥ 归一 ∥ 遮蔽 ∥ 收场注记)2026-11-05 外移同目录叶档 `ssh-text.mjs`:体逐字搬家、
|
|
34
|
+
// 导出名零改——`ssh-session.mjs` / `ssh-transfer.mjs` / `ssh-vault.mjs` 的 import 行零改。
|
|
35
|
+
import { createStripper, createMask, escapeNote, normalizeText } from "./ssh-text.mjs"
|
|
36
|
+
export { createStripper, createMask, escapeNote, normalizeText }
|
|
29
37
|
|
|
30
38
|
/** 静默窗(§6.22 ③):**只作去抖**——判尾部这半条标记到没到齐;不再单独构成「已就绪」。 */
|
|
31
39
|
export const SSH_SETTLE_MS = 800
|
|
@@ -37,8 +45,6 @@ export const SSH_CONNECT_SETTLE_MS = 10_000
|
|
|
37
45
|
export const SSH_RETURN_CAP = 8000
|
|
38
46
|
/** 帽窗头尾比例(§6.22 ⑥:头 60% ∥ 尾 40%——头段装接口 / ACL,尾段装结束证据)。 */
|
|
39
47
|
const CAP_HEAD_RATIO = 0.6
|
|
40
|
-
/** 遮蔽分段下限(§6.22 ③「`≥ 4` 为选定策略值」:3 字符以下与正常输出撞面过高)。 */
|
|
41
|
-
const MASK_SEG_MIN = 4
|
|
42
48
|
/** 保活缺省(§6.22 ④:`ServerAliveInterval=30`;测试态时间缝按 ms 传入后换算)。 */
|
|
43
49
|
export const SSH_KEEPALIVE_MS = 30_000
|
|
44
50
|
/** 秘密环境变量名(§6.22 ②「秘密传递」行)。 */
|
|
@@ -113,138 +119,11 @@ export function buildSshArgs({ host, user, port, probe, identityFile = null, kee
|
|
|
113
119
|
]
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
// ───
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
/** 有状态剥离器(§6.22 ③):三类序列 CSI ∥ OSC ∥ 单字符控制 + `\r\n`∥裸 `\r` 归 `\n`。
|
|
122
|
-
* 状态跨 chunk 携带(序列被 chunk 边界切开不残留成字面);三类之外的序列(DCS / APC 等)按
|
|
123
|
-
* 单字符控制处理——头字节剥掉,体内字节当可见文本如实交出(设计「表外序列的出口」)。
|
|
124
|
-
* `push` = 返回边界(状态保留);`end` = 收场(硬超时 ∥ close ∥ 会话终结:尾部半条序列丢弃并计一次)。 */
|
|
125
|
-
export function createStripper() {
|
|
126
|
-
let state = "ground" // ground ∥ esc ∥ csi ∥ osc ∥ oscEsc ∥ charset
|
|
127
|
-
let pendingCr = false // chunk 尾的 `\r`(下一片首字为 `\n` ⇒ 仍归一条——跨 chunk 的 CRLF)
|
|
128
|
-
const scan = (text) => {
|
|
129
|
-
const s = String(text ?? "")
|
|
130
|
-
let out = ""
|
|
131
|
-
let i = 0
|
|
132
|
-
while (i < s.length) {
|
|
133
|
-
const ch = s[i]
|
|
134
|
-
if (pendingCr) {
|
|
135
|
-
pendingCr = false
|
|
136
|
-
out += "\n"
|
|
137
|
-
if (ch === "\n") { i += 1; continue }
|
|
138
|
-
}
|
|
139
|
-
if (state === "esc") {
|
|
140
|
-
state = "ground"
|
|
141
|
-
if (ch === "[") state = "csi"
|
|
142
|
-
else if (ch === "]") state = "osc"
|
|
143
|
-
else if (ch === "(" || ch === ")" || ch === "*" || ch === "+") state = "charset"
|
|
144
|
-
else if (ch === "\x1b") state = "esc"
|
|
145
|
-
i += 1
|
|
146
|
-
continue
|
|
147
|
-
}
|
|
148
|
-
if (state === "charset") { state = "ground"; i += 1; continue } // `ESC ( 0` 字符集指定(既有覆盖不回归)
|
|
149
|
-
if (state === "csi") {
|
|
150
|
-
const c = ch.charCodeAt(0)
|
|
151
|
-
if (c >= 0x20 && c <= 0x3f) { i += 1; continue } // 参数 ∥ 中间字节
|
|
152
|
-
if (c >= 0x40 && c <= 0x7e) { state = "ground"; i += 1; continue } // 终字节
|
|
153
|
-
state = "ground" // 类外字 ⇒ 序列作废,本字按常规面重判(不吞可见字节)
|
|
154
|
-
continue
|
|
155
|
-
}
|
|
156
|
-
if (state === "osc") {
|
|
157
|
-
if (ch === "\x07") { state = "ground"; i += 1; continue }
|
|
158
|
-
if (ch === "\x1b") { state = "oscEsc"; i += 1; continue }
|
|
159
|
-
i += 1
|
|
160
|
-
continue
|
|
161
|
-
}
|
|
162
|
-
if (state === "oscEsc") {
|
|
163
|
-
state = "ground"
|
|
164
|
-
if (ch === "\\") { i += 1; continue } // `ESC \` = ST
|
|
165
|
-
state = "osc" // 非 ST ⇒ 本字仍在 OSC 体内(ESC 已丢弃,体内字节本就要丢)
|
|
166
|
-
continue
|
|
167
|
-
}
|
|
168
|
-
if (ch === "\x1b") { state = "esc"; i += 1; continue }
|
|
169
|
-
if (ch === "\r") {
|
|
170
|
-
if (i + 1 >= s.length) { pendingCr = true; i += 1; continue }
|
|
171
|
-
out += "\n"
|
|
172
|
-
i += s[i + 1] === "\n" ? 2 : 1
|
|
173
|
-
continue
|
|
174
|
-
}
|
|
175
|
-
if (ch === "\n" || ch === "\t") { out += ch; i += 1; continue }
|
|
176
|
-
const code = ch.charCodeAt(0)
|
|
177
|
-
if (code < 0x20 || code === 0x7f) { i += 1; continue } // BEL ∥ 退格 ∥ 其余 C0(保留 `\n` / `\t`)
|
|
178
|
-
out += ch
|
|
179
|
-
i += 1
|
|
180
|
-
}
|
|
181
|
-
return out
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
/** 喂一片(返回可交出文本;半条序列留给下一片)。 */
|
|
185
|
-
feed(text) { return scan(text) },
|
|
186
|
-
/** 收场:尾部半条序列丢弃并计一次;其前后的可见字节照常交出。 */
|
|
187
|
-
end(text = "") {
|
|
188
|
-
let out = scan(text)
|
|
189
|
-
if (pendingCr) { out += "\n"; pendingCr = false }
|
|
190
|
-
const dropped = state === "ground" ? 0 : 1
|
|
191
|
-
state = "ground"
|
|
192
|
-
return { text: out, dropped }
|
|
193
|
-
},
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** 同一归一(无状态旁路——遮蔽比较面用:秘密值先过控制字节剥离 + CRLF 归一)。 */
|
|
198
|
-
export function normalizeText(text) {
|
|
199
|
-
return createStripper().end(String(text ?? "")).text
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ─── 遮蔽(§6.22 ⑦)────────────────────────────────────────────────────────
|
|
203
|
-
|
|
204
|
-
/** 秘密遮蔽过滤器:字面移除 + `len-1` 尾缓冲(跨 chunk 切分不泄;尾至沉降冲涮)。
|
|
205
|
-
* 比较面 = 与剥离同一归一(§6.22 ③):秘密值先归一、再按不可见处切段(段长 ≥ 4)——
|
|
206
|
-
* 裸字面匹配会漏掉夹控制字节 ∥ 被 chunk 切开的回显。 */
|
|
207
|
-
export function createMask() {
|
|
208
|
-
const secrets = []
|
|
209
|
-
let tail = ""
|
|
210
|
-
let keep = 0
|
|
211
|
-
return {
|
|
212
|
-
add(secret) {
|
|
213
|
-
const raw = String(secret ?? "")
|
|
214
|
-
if (!raw) return
|
|
215
|
-
const table = [normalizeText(raw), ...raw.split(INVISIBLE_SPLIT).filter((seg) => seg.length >= MASK_SEG_MIN)]
|
|
216
|
-
for (const s of table) {
|
|
217
|
-
if (!s || secrets.includes(s)) continue
|
|
218
|
-
secrets.push(s)
|
|
219
|
-
keep = Math.max(keep, s.length - 1)
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
push(text) {
|
|
223
|
-
let out = tail + String(text ?? "")
|
|
224
|
-
for (const s of secrets) out = out.split(s).join("")
|
|
225
|
-
if (out.length <= keep) { tail = out; return "" }
|
|
226
|
-
const emit = out.slice(0, out.length - keep)
|
|
227
|
-
tail = out.slice(out.length - keep)
|
|
228
|
-
return emit
|
|
229
|
-
},
|
|
230
|
-
/** 尾缓冲现行内容(**判据面用**:门①② 要看到已达字节——尾在 drain 时释放,判据不得被它推迟)。 */
|
|
231
|
-
peek() { return tail },
|
|
232
|
-
/** 沉降时冲涮尾缓冲:**只放行非秘密前缀段**(尾内最长可疑后缀一律扣下——整尾 ∥ 移位前缀
|
|
233
|
-
* 都不出返回面;扣下的至多 `秘密长-1` 字符,代价 < 前缀外泄)。 */
|
|
234
|
-
flush() {
|
|
235
|
-
const t = tail
|
|
236
|
-
tail = ""
|
|
237
|
-
if (!t) return ""
|
|
238
|
-
let cut = 0
|
|
239
|
-
for (const s of secrets) {
|
|
240
|
-
const max = Math.min(t.length, s.length - 1)
|
|
241
|
-
for (let L = 1; L <= max; L++) if (t.endsWith(s.slice(0, L))) cut = Math.max(cut, L)
|
|
242
|
-
}
|
|
243
|
-
return cut ? t.slice(0, t.length - cut) : t
|
|
244
|
-
},
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
122
|
+
// ─── 终端噪声 / 遮蔽(2026-11-05 拆档族已外移 `ssh-text.mjs`)──────────────────
|
|
123
|
+
// 剥离器(`createStripper`)、同一归一(`normalizeText`)与遮蔽过滤器(`createMask`)的体全住兄弟档
|
|
124
|
+
// `ssh-text.mjs`(纯「字节 → 可见文本」链,零子进程 / 零计时);本档 import 回来原样再出口。
|
|
125
|
+
// 收场面作两半:**半条序列的冲涮**(`flushEscapes`)留本档——它把交出的字节经 `handleChunk` 汇入
|
|
126
|
+
// log / 缓冲 / 等待者(运行时汇聚点住这里,搬过去就得反向 import);**注记**(`escapeNote`)随文本面走。
|
|
248
127
|
// ─── 子进程(起跑 ∥ 双流汇入 ∥ 退出)────────────────────────────────────────
|
|
249
128
|
|
|
250
129
|
/** 悬挂 chunk 双流汇入(已剥离已遮蔽 → log ∥ 缓冲 ∥ 面板 → 唤醒沉降等待者)。 */
|
|
@@ -506,14 +385,6 @@ export function flushEscapes(entry) {
|
|
|
506
385
|
return dropped
|
|
507
386
|
}
|
|
508
387
|
|
|
509
|
-
/** 半条序列收场注记(§6.22 ③ flush②)——报告一次即清零。 */
|
|
510
|
-
export function escapeNote(entry) {
|
|
511
|
-
const n = entry.escDropped ?? 0
|
|
512
|
-
if (!n) return ""
|
|
513
|
-
entry.escDropped = 0
|
|
514
|
-
return `\n— ${n} incomplete escape sequence dropped`
|
|
515
|
-
}
|
|
516
|
-
|
|
517
388
|
/** 状态行冠形(§6.22 动作表末行):每返回首行。 */
|
|
518
389
|
export function statusLine(entry) {
|
|
519
390
|
const idle = Math.max(0, Math.round((Date.now() - entry.lastActivityAt) / 1000))
|
|
@@ -217,11 +217,10 @@ function queuedPositionOf(agent, key) {
|
|
|
217
217
|
return i >= 0 ? i + 1 : undefined
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
/** recent
|
|
220
|
+
/** recent 参数钳制(必填,1..20;不再造默认值)。值已在 `executeObserveAction` 入口判过缺 ∥ 非法,
|
|
221
|
+
* 本函数只钳区间;钳制到 1..20 防超长 N2 失控。 */
|
|
221
222
|
function clampRecent(n) {
|
|
222
|
-
|
|
223
|
-
if (!Number.isFinite(v)) return 5
|
|
224
|
-
return Math.max(1, Math.min(20, v))
|
|
223
|
+
return Math.max(1, Math.min(20, n))
|
|
225
224
|
}
|
|
226
225
|
|
|
227
226
|
/**
|
|
@@ -242,6 +241,11 @@ export function executeObserveAction(args, ctx) {
|
|
|
242
241
|
return JSON.stringify({ status: "error", error: "observe requires the id of the async subagent to inspect (from the async spawn return) — pass the id; omitting it observes nothing" })
|
|
243
242
|
}
|
|
244
243
|
const key = String(id)
|
|
244
|
+
// `recent` 必填(KD-4):钳制函数里的 `return 5` 是代码造的值——缺了就拒,不替调用方选条数。
|
|
245
|
+
const recentNum = Number.parseInt(args?.recent, 10)
|
|
246
|
+
if (!Number.isFinite(recentNum)) {
|
|
247
|
+
return JSON.stringify({ status: "error", error: `observe: recent is required — pass how many recent-turn summaries to return (1..20); got ${JSON.stringify(args?.recent ?? null)}` })
|
|
248
|
+
}
|
|
245
249
|
const entry = getAsyncPool(agent, "subagent")?.get(key)
|
|
246
250
|
if (!entry) {
|
|
247
251
|
if (getAsyncPool(agent, "advisor")?.has(key)) {
|
|
@@ -259,7 +263,7 @@ export function executeObserveAction(args, ctx) {
|
|
|
259
263
|
// 执行前后维护——LLM 生成/工具间空隙为空;子代理 await 长工具调用时父回合可见它。
|
|
260
264
|
const inflight = child?._inflightTools
|
|
261
265
|
if (inflight instanceof Set && inflight.size > 0) out.currentTool = [...inflight]
|
|
262
|
-
const n = clampRecent(
|
|
266
|
+
const n = clampRecent(recentNum)
|
|
263
267
|
out.recentTurns = recentTurnLines(child, n)
|
|
264
268
|
out.note = `observing running ${entry.role}#${key} — recentTurns newest-first (cap ${n}); currentTool shown only while a tool is executing (stuck detection); sent directions consume at the next turn boundary`
|
|
265
269
|
} else if (entry.status === "queued") {
|
|
@@ -270,7 +274,7 @@ export function executeObserveAction(args, ctx) {
|
|
|
270
274
|
out.done = true
|
|
271
275
|
out.turn = entry.turn ?? 0
|
|
272
276
|
out.maxTurns = entry.maxTurns ?? 0
|
|
273
|
-
out.recentTurns = child ? recentTurnLines(child, clampRecent(
|
|
277
|
+
out.recentTurns = child ? recentTurnLines(child, clampRecent(recentNum)) : []
|
|
274
278
|
out.note = "settled — the final report is delivered by the auto channel (turn-end collection or the suspension digest); observe returns the activity summary, not the full report (N2)"
|
|
275
279
|
}
|
|
276
280
|
return JSON.stringify(out)
|
|
@@ -40,6 +40,7 @@ import { noteReviewDelivered } from "./review-facts.mjs"
|
|
|
40
40
|
import { injectBgResult } from "./bash-async.mjs"
|
|
41
41
|
// 批 browser-async-fix:后台浏览器动作注入器(同族——role="browser" 分发到 browser-async.mjs)。
|
|
42
42
|
import { injectBrowserResult } from "./browser-async.mjs"
|
|
43
|
+
import { mergeAttribution } from "../agent/batch-attribution.mjs" // 归属表合入(收口取材的判据一;子代理记在自己的 agent 上,并回父侧)
|
|
43
44
|
|
|
44
45
|
// agent-tools 共享:并行子代理的审批/继续弹窗经 owner 上命名 promise 链串行——
|
|
45
46
|
// 永不叠弹窗(返回链供调用方 .then 续接)。
|
|
@@ -50,7 +51,7 @@ export function enqueueAsk(owner, key, ask) {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
// Async pool limits per role domain (AGENT-LOOP-ASYNC-POOL.md §6.10 — R14, 2026-09-06):
|
|
53
|
-
// the old single cap (ASYNC_SUBAGENT_LIMIT = 4, AGENT-LOOP-SUBAGENT.md §6.7.3
|
|
54
|
+
// the old single cap (ASYNC_SUBAGENT_LIMIT = 4, AGENT-LOOP-SUBAGENT.md §6.7.3) evolved into two
|
|
54
55
|
// independent pools — eng-coder 4 / other roles 4 (user ruling "eng-coder 四路,
|
|
55
56
|
// 其他 4 路") — a full engCoder pool never blocks an explore spawn and vice versa
|
|
56
57
|
// (same-domain cap still 4, cross-domain total up to 8). The per-turn check
|
|
@@ -123,7 +124,7 @@ function warnPoolFallback(what, sig) {
|
|
|
123
124
|
console.warn(`[config] agent.poolLimits: ${what} — must be a positive integer ≥1 — falling back to default ${JSON.stringify(ASYNC_POOL_LIMITS)}`)
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
/** Running count within ONE pool domain (口径同 AGENT-LOOP-SUBAGENT.md §6.7.3
|
|
127
|
+
/** Running count within ONE pool domain (口径同 AGENT-LOOP-SUBAGENT.md §6.7.3 T6: queued 与已完成不计入;
|
|
127
128
|
* 条目带 _pool 域字段——spawn 时 poolDomainOf(role) 落位;缺字段(手工/旧条目)按
|
|
128
129
|
* other——既有 coder 域测试语义不变)。 */
|
|
129
130
|
export function runningPoolCount(parent, pool) {
|
|
@@ -314,10 +315,10 @@ export function executeCancelAction(args, ctx) {
|
|
|
314
315
|
}
|
|
315
316
|
|
|
316
317
|
/**
|
|
317
|
-
* 共享 post-spawn 管线(阻塞与 async 同一条——AGENT-LOOP-SUBAGENT.md §6.7.3
|
|
318
|
+
* 共享 post-spawn 管线(阻塞与 async 同一条——AGENT-LOOP-SUBAGENT.md §6.7.3 "全不变"):turn-cap continue
|
|
318
319
|
* 循环 → 拒绝降级 partial 返回 → MIN_REPORT_CHARS 扩写 → eng-coder mutation merge →
|
|
319
320
|
* designId 后缀。onDeclined 在此(两路同一形态)——只有 askContinue 不同:阻塞经权限
|
|
320
|
-
* 面板询问;async
|
|
321
|
+
* 面板询问;async 永不弹面板(自动拒绝;撞帽即注册父侧检查点、挂起等父 `send` / `cancel`,AUTO 档亦不自动续跑——§6.7.3)。
|
|
321
322
|
*/
|
|
322
323
|
export async function runChildPipeline(child, input, childOpts, childRunOpts, { parent, role, args, askContinue }) {
|
|
323
324
|
const declined = { partial: null }
|
|
@@ -463,11 +464,9 @@ export function mergeChildMutations(parent, child) {
|
|
|
463
464
|
// to the parent's guard state.
|
|
464
465
|
if (!child._mutatedThisRun || !(child._touchedFiles?.length)) return false
|
|
465
466
|
parent._mutatedThisRun = true
|
|
466
|
-
const merged = []
|
|
467
|
-
for (const abs of
|
|
468
|
-
|
|
469
|
-
merged.push(abs)
|
|
470
|
-
}
|
|
467
|
+
const merged = [...(child._touchedFiles ?? [])]
|
|
468
|
+
for (const abs of merged) if (!parent._touchedFiles.includes(abs)) parent._touchedFiles.push(abs)
|
|
469
|
+
mergeAttribution(parent, child) // 归属表并集(判据一的取材面随 `_touchedFiles` 同笔并回)
|
|
471
470
|
// §6.10: merged code mutates the parent's state — log it for the stale
|
|
472
471
|
// scan of in-flight reviews (a review whose code changed under it is stale).
|
|
473
472
|
noteMutations(parent, merged)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* subagent-brief.mjs — **任务书与 system 固块拼装**族:任务书播报文本、写域行(S4)、文档坐标行(S5)。
|
|
3
|
+
*
|
|
4
|
+
* 机制单源 = `docs/core/design/AGENT-LOOP-SUBAGENT.md` §6.22(任务书)∥ §6.26(写域行 S4)∥ §6.61(文档坐标行 S5);
|
|
5
|
+
* 本档只拼文本,不判准入——三条门的判据住 `./spawn-gates.mjs` 与 `./subagent-spawn.mjs`。
|
|
6
|
+
* **为什么单独立档**:这三个函数是纯拼装(入参 → 一段文本),消费者只有 `subagent-spawn.mjs` 的 child 装配点;
|
|
7
|
+
* 把它整族搬走是分拆落点(`docs/core/design/PATH-RESOLUTION.md` §3 末条),装配面一句调用都没动。
|
|
8
|
+
*/
|
|
9
|
+
import { relative } from "node:path"
|
|
10
|
+
|
|
11
|
+
import { docRootBase, docRootPaths, readManifest } from "../manifest.mjs"
|
|
12
|
+
import { composeTaskBookBrief } from "./spawn-gates.mjs"
|
|
13
|
+
|
|
14
|
+
/** 任务书播报文本:该角色名集拼装 + 可选 task 自由文本(拼装空 ⇒ 原 task 逐字——旧形零变)。 */
|
|
15
|
+
export function taskBriefOf(args, role) {
|
|
16
|
+
const composed = composeTaskBookBrief(args, role)
|
|
17
|
+
if (!composed) return args.task
|
|
18
|
+
const extra = typeof args.task === "string" ? args.task.trim() : ""
|
|
19
|
+
return extra ? `${composed}\n\n${extra}` : composed
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** S4 写域行(AGENT-LOOP-SUBAGENT.md §6.26「写域行(S4)」):表头 + 逐条绝对路径 + 两句语义——
|
|
23
|
+
* 本档局部纯函数(D23-9:不外提模块)。两句不可省:缺① 子代理读成「我只能写这些」⇒ 该写的漏掉;
|
|
24
|
+
* 缺② 仍把任务书 §2 全文当成自己的改动面(本块的病因)。清单不截断——截断正是本块要消除的
|
|
25
|
+
* 「看不见」。返回块文本(块间分隔由装配侧 `join("\n\n")` 施加)。 */
|
|
26
|
+
export function filesBlockOf(files) {
|
|
27
|
+
return `Files declared for this spawn (the write domain this task declares, for scheduling):\n` +
|
|
28
|
+
files.map((f) => `- ${f}`).join("\n") +
|
|
29
|
+
`\n\nThis list is not an authorization boundary: touching a file outside it is allowed — report every out-of-list file you changed, with its reason. It is also not the whole change surface: other spawns on this task declare their own files, and what is listed here is your share only.`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** §6.61 契约 ② 的两件常量:层键固定 = 这三层(`specs` ∥ `modules` ∥ `standards` 不读——多的层每发再付
|
|
33
|
+
* 一次 token,KD-DC3);前缀逐字(英文——与兄弟块同语体),层串接在其后。 */
|
|
34
|
+
const DOCS_COORDINATE_KEYS = ["requirements", "design", "batches"]
|
|
35
|
+
const DOCS_COORDINATE_PREFIX = "Docs (project-root relative, declared by this project's PROJECT-MANIFEST.json docRoot):"
|
|
36
|
+
|
|
37
|
+
/** S5 文档坐标行(AGENT-LOOP-SUBAGENT.md §6.61「子代理文档坐标行」):本项目 manifest 声明的三层
|
|
38
|
+
* 文档坐标(`requirements` ∥ `design` ∥ `batches`),项目根相对形,一行随 system 固块下发;
|
|
39
|
+
* 未声明的层呈现 `(undeclared)`。
|
|
40
|
+
*
|
|
41
|
+
* **「未声明」的判别单源 = `readManifest` 同次返回的 `missingKeys`**——它在**原始档**上算得,与补默认
|
|
42
|
+
* 后的值分属两个事实。不能看返回的 `manifest.docRoot[键]` 判:`readManifest` 的返回值已 `fillDefaults`,
|
|
43
|
+
* `docs/design` 这类默认路径与一条真声明同形,打出去就是把项目从未声明的坐标当声明发给子代理
|
|
44
|
+
* (KD-DC2——比不发更坏,它看起来像声明)。
|
|
45
|
+
*
|
|
46
|
+
* **读不出(缺档 ∥ 坏档 ∥ 校验不过 ∥ 读抛 ∥ 项目根解析链 I/O 异常)⇒ 返回 null,调用点不推块**:不加本行
|
|
47
|
+
* 的结果 = 本批之前的行为,业务结果零变(KD-DC4;这不是兜底式静默——坐标取不到不该赔掉一次 spawn)。
|
|
48
|
+
*
|
|
49
|
+
* **护栏宽度 = 整段坐标计算**(读档 + 基数解析 + 路径映射 + 串拼装),不是只包读档那一句(§6.61.2 ④ ·
|
|
50
|
+
* AC-DC-8):基数取法 `docRootBase(cwd)` 走项目发现链,而树根那一环 `owningProject` 的 `statSync` 无护栏
|
|
51
|
+
* ⇒ 该链的 I/O 异常照原样上抛;只包读档那一句,「读不出不赔掉一次 spawn」就只兑现一半。
|
|
52
|
+
*
|
|
53
|
+
* 返回块文本 ∥ null。 */
|
|
54
|
+
export function docsCoordinatesBlockOf(cwd) {
|
|
55
|
+
try {
|
|
56
|
+
const read = readManifest(cwd)
|
|
57
|
+
if (!read.ok || !read.manifest) return null // 缺档 ∥ 坏 JSON ∥ 校验不过(契约 ③ 读档格)
|
|
58
|
+
const missing = new Set(read.missingKeys ?? [])
|
|
59
|
+
// 整键缺 ∥ 非对象 ⇒ 三层皆按未声明。**不另设「三层全未声明」分支**:它就是下面这条逐层判据连用三次。
|
|
60
|
+
const wholeUndeclared = missing.has("docRoot")
|
|
61
|
+
const base = docRootBase(cwd)
|
|
62
|
+
const layers = DOCS_COORDINATE_KEYS.map((key) => {
|
|
63
|
+
if (wholeUndeclared || missing.has(`docRoot.${key}`)) return `${key} = (undeclared)`
|
|
64
|
+
const value = read.manifest.docRoot?.[key]
|
|
65
|
+
// 显式「本面无」(`null`)与缺键同呈现:`docRootPaths(null) = []` 已定那一读(MANIFEST.md §2.7)。
|
|
66
|
+
if (value === null || value === undefined) return `${key} = (undeclared)`
|
|
67
|
+
// 路径一律项目根相对、`/` 分隔;解析为空(声明 = 项目根自身)呈现为 `.`。
|
|
68
|
+
const roots = docRootPaths(value, cwd).map((abs) => relative(base, abs).replaceAll("\\", "/") || ".")
|
|
69
|
+
return `${key} = ${roots.join(", ")}`
|
|
70
|
+
})
|
|
71
|
+
return `${DOCS_COORDINATE_PREFIX} ${layers.join(" · ")}`
|
|
72
|
+
} catch {
|
|
73
|
+
// 读档非 ENOENT 读错(权限 ∥ 目录等)· 项目根解析链的 I/O 异常:一律收成「读不出」(契约 ④)
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
}
|