@thincoder/core 0.10.13 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -1
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +46 -27
- package/advisor/notice.mjs +1 -1
- package/advisor/project-context.mjs +253 -14
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +57 -4
- package/agent/digest-account.mjs +73 -46
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +35 -22
- package/agent/family-tools.mjs +36 -17
- package/agent/helpers.mjs +123 -95
- package/agent/offload.mjs +84 -0
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +19 -7
- package/agent/run-stages.mjs +127 -61
- package/agent/run-start.mjs +45 -8
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +27 -22
- package/agent/spawn-child.mjs +38 -1
- package/agent/suspension.mjs +1 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +60 -6
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-face.mjs +99 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +39 -13
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +136 -31
- package/agent-tools/async-settle.mjs +2 -2
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +8 -2
- package/agent-tools/batch-closeout.mjs +444 -0
- package/agent-tools/batch-gate.mjs +152 -138
- package/agent-tools/batch-ledger-bind.mjs +392 -0
- package/agent-tools/batch-ledger-link.mjs +73 -0
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +245 -376
- package/agent-tools/batch-paths.mjs +73 -47
- package/agent-tools/batch-read.mjs +1 -1
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +154 -0
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +344 -196
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +189 -253
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +47 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +24 -24
- package/agent-tools/design-token.mjs +318 -39
- package/agent-tools/doc-check.mjs +55 -29
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +10 -9
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/manifest.mjs +34 -15
- package/agent-tools/read-history.mjs +115 -14
- package/agent-tools/review-facts.mjs +40 -15
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +19 -22
- package/agent-tools/ssh-session.mjs +120 -111
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +210 -0
- package/agent-tools/ssh-transport.mjs +183 -81
- package/agent-tools/subagent-actions-query.mjs +11 -7
- package/agent-tools/subagent-actions.mjs +1 -1
- package/agent-tools/subagent-async.mjs +11 -11
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +45 -11
- package/agent-tools/subagent-spawn.mjs +143 -104
- package/agent-tools/subagent.mjs +26 -23
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +22 -6
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-presets.mjs +5 -3
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +165 -68
- package/conventions.mjs +11 -9
- package/declaration.mjs +33 -7
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +312 -163
- package/doc-check/line-refs.mjs +38 -0
- package/doc-check/paragraph.mjs +220 -91
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +12 -6
- package/i18n.mjs +2 -2
- package/index-discover.mjs +4 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +95 -62
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +76 -244
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +70 -37
- package/ledger-executors.mjs +1 -1
- package/ledger-migrate.mjs +4 -4
- package/ledger-read.mjs +10 -8
- package/ledger-surface.mjs +1 -1
- package/ledger-tools.mjs +83 -24
- package/ledger-variant-notice.mjs +1 -1
- package/ledger-write-ops.mjs +462 -0
- package/ledger.mjs +2 -2
- package/manifest-discovery.mjs +5 -3
- package/manifest-schema.mjs +28 -2
- package/memory/memory-tool.mjs +5 -2
- package/memory/schema.mjs +6 -27
- package/package.json +3 -1
- package/path-resolve.mjs +498 -0
- package/permission.mjs +4 -0
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +14 -6
- package/prompts/advisor-design.md +66 -22
- package/prompts/advisor-round1.md +37 -3
- package/prompts/advisor-round2.md +44 -10
- package/prompts/advisor-round3.md +43 -9
- package/prompts/common.md +15 -375
- package/prompts/consult-base.md +6 -1
- package/prompts/discipline-engineering.md +251 -95
- package/prompts/discipline-normal.md +4 -250
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +29 -3
- package/prompts/persona-eng-designer.md +131 -159
- package/prompts/persona-engineering.md +202 -131
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +6 -1
- package/prompts/persona-tester.md +55 -0
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +5 -4
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +39 -12
- package/provider/rate.mjs +11 -3
- package/provider/responses.mjs +3 -1
- package/provider/sse.mjs +15 -4
- package/provider-flows.mjs +2 -2
- package/session-identity.mjs +21 -0
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +79 -19
- package/session-slot-write.mjs +37 -5
- package/session-slots.mjs +9 -14
- package/session.mjs +29 -8
- package/skip-dirs.mjs +48 -0
- package/team-ledger.mjs +17 -13
- package/text-budget.mjs +4 -0
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +244 -34
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -13
- package/tool-docs/bash.md +2 -37
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +3 -1
- package/tool-docs/browser.md +2 -47
- package/tool-docs/code_search.md +3 -1
- package/tool-docs/consult_start.md +2 -4
- package/tool-docs/consult_stop.md +2 -2
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -14
- package/tool-docs/doc_check.md +2 -72
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +3 -1
- package/tool-docs/edit.md +2 -18
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -12
- package/tool-docs/fetch.md +2 -12
- package/tool-docs/file_ops.md +2 -16
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -27
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +2 -5
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -13
- package/tool-docs/insert_after.md +2 -14
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -9
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -7
- package/tool-docs/manifest.md +2 -28
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +3 -11
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +2 -4
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -6
- package/tool-docs/read_image.md +2 -7
- package/tool-docs/recent_changes.md +3 -1
- package/tool-docs/repo_outline.md +3 -1
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +2 -5
- package/tool-docs/skill.md +3 -5
- package/tool-docs/ssh.md +2 -50
- package/tool-docs/subagent.md +2 -63
- package/tool-docs/task.md +2 -6
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +3 -13
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +3 -1
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -17
- package/tool-docs/write.md +2 -10
- package/tools/bash.mjs +12 -2
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +176 -91
- package/tools/edit-diff.mjs +129 -45
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +11 -5
- package/tools/file.mjs +32 -34
- package/tools/git.mjs +43 -2
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +4 -1
- package/tools/patch.mjs +127 -38
- package/tools/process-doc-mark.mjs +139 -0
- package/tools/search.mjs +15 -6
- package/tools/shared.mjs +31 -7
- package/tools/ssh.mjs +48 -7
- package/tools/tree.mjs +4 -1
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +79 -6
- package/traces/trace-store.mjs +4 -3
- package/window-policy.mjs +203 -0
- package/agent/light-round.mjs +0 -63
- package/agent/unbooked-pen.mjs +0 -62
- package/doc-check/anchors.mjs +0 -135
package/tools/shared.mjs
CHANGED
|
@@ -7,7 +7,8 @@ import { execFile } from "node:child_process"
|
|
|
7
7
|
import { readFileSync, existsSync, realpathSync, readdirSync, statSync, openSync, readSync, closeSync } from "node:fs"
|
|
8
8
|
import { dirname, join, resolve } from "node:path"
|
|
9
9
|
import { fileURLToPath } from "node:url"
|
|
10
|
-
import { loadToolDoc, applyPromptInjections } from "../prompt-files.mjs"
|
|
10
|
+
import { loadToolDoc, applyPromptInjections, expandKnowledgeTopics } from "../prompt-files.mjs"
|
|
11
|
+
import { WORK_MODES } from "../config-migrate.mjs"
|
|
11
12
|
import { spawnGit, gitTimeoutNote, GIT_TIMEOUT_MS } from "./git-run.mjs"
|
|
12
13
|
|
|
13
14
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
@@ -21,10 +22,15 @@ export const DESC = (name) => loadToolDoc(name)
|
|
|
21
22
|
export const MAX_READ_LINES = 2000
|
|
22
23
|
export const MAX_OUTPUT_CHARS = 200_000
|
|
23
24
|
|
|
25
|
+
// 写门两参的说明文本已搬出本档(设计 TOOLS §1.2):文本单点 = `./write-gate-params.mjs`,这里只转出同一常量,
|
|
26
|
+
// 八处导入档的导入面(`from "./shared.mjs"`)一个字不改。
|
|
27
|
+
export { LEDGER_PARAM_DESC, LEDGER_PARAM_DESC_MEMORY, PROJECT_PARAM_DESC } from "./write-gate-params.mjs"
|
|
28
|
+
|
|
24
29
|
const ENCODING_DETECT_MAX_TRIM = 3
|
|
25
30
|
const SYNTAX_CHECK_TIMEOUT = 10000
|
|
26
31
|
export const BASH_TIMEOUT_MS = 120_000
|
|
27
|
-
|
|
32
|
+
// `IGNORED_DIRS` 退场(2026-10-27 四份名单合一):单源 = `../skip-dirs.mjs` 的 `SKIP_DIRS`,
|
|
33
|
+
// 消费面 `search.mjs` 直接引它(一词一物——同一集合不再两个名字)。
|
|
28
34
|
|
|
29
35
|
/** SSRF guard: check if a hostname is private/internal. Shared by web.mjs and codemode.mjs.
|
|
30
36
|
* Returns TRUE for private hosts — callers block them. */
|
|
@@ -162,16 +168,34 @@ export function findCandidates(lines, oldString, topN = 3, threshold = 0.5) {
|
|
|
162
168
|
/** Appended to hashline_edit results when the file contains U+FFFD (encoding-corruption probe). */
|
|
163
169
|
export const FFFD_WARNING = "⚠ file contains U+FFFD (replacement char) — encoding may be corrupted; hash-based addressing may be unreliable. Consider fixing the file encoding first."
|
|
164
170
|
|
|
171
|
+
/**
|
|
172
|
+
* 工具描述分档展开薄壳(设计 TOOLS §1 ∥ PROMPT-SYSTEM 设计档 §2 §7):母版描述里的
|
|
173
|
+
* `{{knowledge:<id>}}` 锚在这里按档展开,展开体一律交 `prompt-files.mjs` 的 `expandKnowledgeTopics`
|
|
174
|
+
* ——壳只校验 mode 并选极简支,不复刻锚文法(另起一套展开器 = 逐字一致那条规则写在两处,漂一处查不出)。
|
|
175
|
+
* mode **必填、不给缺省**:缺省会让一次运行悄悄用上另一档的文本,而错处要到模型按错文本行事时才显形。
|
|
176
|
+
* 非字符串描述恒等过(无锚可展开——与下方 `applyPromptInjections` 同一判据)。
|
|
177
|
+
*/
|
|
178
|
+
export function expandToolDescription(text, mode) {
|
|
179
|
+
if (mode === undefined) throw new Error(`tool description: mode is required — pass one of ${WORK_MODES.join(" / ")}; no default is applied (a missing mode silently renders another tier's text)`)
|
|
180
|
+
if (!WORK_MODES.includes(mode)) throw new Error(`tool description: mode must be one of ${WORK_MODES.join(" / ")} — got ${JSON.stringify(mode)}`)
|
|
181
|
+
if (typeof text !== "string") return text
|
|
182
|
+
return expandKnowledgeTopics(text, { tiny: mode === "tiny" })
|
|
183
|
+
}
|
|
184
|
+
|
|
165
185
|
/** Convert to OpenAI tools parameter format.
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
|
|
186
|
+
* 分档缝 + 锚替换缝:`description` 先按 mode 展开知识锚(`expandToolDescription`)、再跑
|
|
187
|
+
* `applyPromptInjections`。顺序不可倒——注入值由端侧提供,倒过来会把注入值当主题锚再展开一次。
|
|
188
|
+
* 调用点与各自传的档见设计 TOOLS §1 的表:主链按会话现读的 mode,其余五面取完整档 `"normal"`。
|
|
189
|
+
* 非字符串 description 恒等过(无锚可替换)。
|
|
190
|
+
* `descriptionPostProcess`(可选钩子)跑在两者之后:宿主端对某端不存在的动作做行级剔除,剔的必须是
|
|
191
|
+
* **装配完的那份描述**(设计 TOOLS §1.1)——锚展开在装配期,剔除点放在展开之前就看不到展开面的内容。*/
|
|
192
|
+
export function toOpenAISchema(tool, mode) {
|
|
193
|
+
const assembled = applyPromptInjections(expandToolDescription(tool.description, mode))
|
|
170
194
|
return {
|
|
171
195
|
type: "function",
|
|
172
196
|
function: {
|
|
173
197
|
name: tool.name,
|
|
174
|
-
description:
|
|
198
|
+
description: typeof tool.descriptionPostProcess === "function" ? tool.descriptionPostProcess(assembled) : assembled,
|
|
175
199
|
parameters: tool.parameters,
|
|
176
200
|
},
|
|
177
201
|
}
|
package/tools/ssh.mjs
CHANGED
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
* 会话跨调用存活于池(非本档持有);depth>0 排除(`agent/helpers.mjs` `SUBAGENT_TOOL_EXCLUSIONS`)。
|
|
13
13
|
* 动态 import(W8 契约②:agent-tools 静态链达 node:sqlite——端壳静态闭包须保持零命中)。
|
|
14
14
|
*/
|
|
15
|
-
import { DESC } from "./shared.mjs"
|
|
15
|
+
import { DESC, LEDGER_PARAM_DESC } from "./shared.mjs"
|
|
16
|
+
// `~` 展开单源(`touchedPaths` 钩子与传输件同一件叶子——`config.mjs` 已 import 同一处)。
|
|
17
|
+
import { expandHome } from "../expand-home.mjs"
|
|
16
18
|
|
|
17
|
-
export const SSH_ACTIONS = ["connect", "send", "read", "secret_input", "close", "list", "credentials", "forget"]
|
|
19
|
+
export const SSH_ACTIONS = ["connect", "send", "read", "secret_input", "close", "list", "credentials", "forget", "put", "get"]
|
|
18
20
|
|
|
19
21
|
/** 参数校验(缺必填 / 形错 ⇒ `Error: …`——不执行;§6.22 动作表逐动作必填面)。 */
|
|
20
22
|
export function validateArgs(args) {
|
|
@@ -30,6 +32,19 @@ export function validateArgs(args) {
|
|
|
30
32
|
return null
|
|
31
33
|
}
|
|
32
34
|
if (action === "list" || action === "credentials") return null
|
|
35
|
+
if (action === "put" || action === "get") {
|
|
36
|
+
// 两个传输动作 = 单文件(目录参数不收——递归归边界句);主机 / 凭据全取会话记录值(S10)。
|
|
37
|
+
if (typeof args.localPath !== "string" || args.localPath.trim() === "") return `Error: ${action} requires localPath`
|
|
38
|
+
if (typeof args.remotePath !== "string" || args.remotePath.trim() === "") return `Error: ${action} requires remotePath`
|
|
39
|
+
if (args.protocol !== undefined && args.protocol !== null && args.protocol !== "" && args.protocol !== "scp" && args.protocol !== "sftp") {
|
|
40
|
+
return `Error: ${action} protocol must be "scp" (classic, the default) or "sftp"`
|
|
41
|
+
}
|
|
42
|
+
// S10「`put` 参数面没有 `host` / `user` / `port`」:传了就拒——静默忽略会让模型以为换了目标主机。
|
|
43
|
+
const stray = ["host", "user", "port"].filter((k) => args[k] !== undefined && args[k] !== null && args[k] !== "")
|
|
44
|
+
if (stray.length) {
|
|
45
|
+
return `Error: ${action} takes the host / user / port from the session — remove ${stray.join(" / ")} (the session already names the target host)`
|
|
46
|
+
}
|
|
47
|
+
}
|
|
33
48
|
if (action === "forget") {
|
|
34
49
|
if (typeof args.host !== "string" || args.host.trim() === "") return "Error: forget requires host"
|
|
35
50
|
if (args.port !== undefined && args.port !== null && args.port !== "" && !Number.isFinite(Number(args.port))) {
|
|
@@ -50,18 +65,24 @@ export const sshTool = {
|
|
|
50
65
|
parameters: {
|
|
51
66
|
type: "object",
|
|
52
67
|
properties: {
|
|
53
|
-
action: { type: "string", enum: SSH_ACTIONS, description: "Action to run (one per call): connect | send | read | secret_input | close | list | credentials | forget." },
|
|
68
|
+
action: { type: "string", enum: SSH_ACTIONS, description: "Action to run (one per call): connect | send | read | secret_input | close | list | credentials | forget | put | get." },
|
|
54
69
|
host: { type: "string", description: "connect / forget: target host (IP or name)." },
|
|
55
70
|
user: { type: "string", description: "connect: login user (optional: your local ssh config decides, else the user recorded for this host locally)." },
|
|
56
71
|
port: { type: "number", description: "connect / forget: TCP port (optional, default 22)." },
|
|
57
72
|
label: { type: "string", description: "connect: short human label for this session (optional); secret_input: label for the value being sent." },
|
|
58
|
-
promptPattern: { type: "string", description: "connect: regex that marks the shell prompt as ready (optional): send/read
|
|
59
|
-
id: { type: "string", description: "send / read / secret_input / close: session id from connect (`ssh#N`)." },
|
|
73
|
+
promptPattern: { type: "string", description: "connect: regex that marks the shell prompt as ready (optional; the default recognises lines ending in # > $ %): without a hit, send/read on a slow device wait out the full timeout instead of returning early." },
|
|
74
|
+
id: { type: "string", description: "send / read / secret_input / close / put / get: session id from connect (`ssh#N`)." },
|
|
60
75
|
data: { type: "string", description: "send: text to type into the session (a trailing newline is passed as-is; otherwise Enter is sent as `\\r`)." },
|
|
61
76
|
settle: { type: "boolean", description: "send: wait for the ready verdict before returning (default true); false returns right after the bytes are written." },
|
|
62
|
-
timeoutMs: { type: "number", description: "send / read: wait budget override (default
|
|
63
|
-
maxChars: { type: "number", description: "read: return
|
|
77
|
+
timeoutMs: { type: "number", description: "send / read: wait budget override (default 60000) — a return happens the moment the device is waiting for input (prompt, `--More--`, a y/n or password prompt); on expiry the call returns partial output plus a line naming what was not seen. put / get: transfer budget override (default 600000) — on expiry the process tree is killed." },
|
|
78
|
+
maxChars: { type: "number", description: "read: return-window override (default 8000) — head 60% + a note + tail 40%; the omitted middle is kept in the session, so the next read collects it." },
|
|
64
79
|
identityFile: { type: "string", description: "connect: private-key path to offer (`-i`, `~` expands); remembered for this host and reused when omitted (optional)." },
|
|
80
|
+
localPath: { type: "string", description: "put / get: local file path (`~` expands; a file, never a directory)." },
|
|
81
|
+
remotePath: { type: "string", description: "put / get: path of the file on the session host (`/flash/img.bin`)." },
|
|
82
|
+
overwrite: { type: "boolean", description: "get only: replace an existing local file (default false — an existing target is refused, never overwritten silently). put follows scp's own semantics: a same-named remote file is replaced." },
|
|
83
|
+
protocol: { type: "string", enum: ["scp", "sftp"], description: "put / get: `scp` = classic SCP protocol, the default and what network devices speak; `sftp` = the SFTP subsystem, for hosts that only offer that. No automatic fallback between them." },
|
|
84
|
+
// 写门接面(⑬ ④):`get` 往项目内落盘 ⇒ 与 `write` 同一道门——那一道门读的就是本参数。
|
|
85
|
+
ledger: { type: "string", description: LEDGER_PARAM_DESC + ";仅 `get` 要号,`put` 写的是远端主机,不要" },
|
|
65
86
|
},
|
|
66
87
|
required: ["action"],
|
|
67
88
|
},
|
|
@@ -70,6 +91,19 @@ export const sshTool = {
|
|
|
70
91
|
isReadonlyAction(args) {
|
|
71
92
|
return args?.action === "list" || args?.action === "read" || args?.action === "credentials"
|
|
72
93
|
},
|
|
94
|
+
// 写门接面(§6.22 ⑬ ④ · D-TO26):只有 `get` 往本地落盘;其余动作不写项目内档。
|
|
95
|
+
// 钩子契约 = `agent/helpers.mjs` 的 `toolTouchPaths`(`const hook = tool?.touchedPaths`)——
|
|
96
|
+
// 光有这个钩子不够:门还要把 `ssh` 收进入口集并按 action 判要号,三处缺一不可。
|
|
97
|
+
// `~` 在这里就展开成绝对形:钩子拿不到 `ctx`(契约形 = `touchedPaths(args)`,`toolTouchPaths` 以 `hook(a)` 调用),
|
|
98
|
+
// 而各消费面都在其后按会话 cwd 归一(`resolve(agent.cwd, p)`;`agent.cwd` 即工具 ctx 的 `cwd`,见
|
|
99
|
+
// `agent/dispatch-run.mjs` 的 `toolCtx`)⇒ 原样回 `~/x` 会被拼成 `<项目>/~/x` 这个虚构路径,工程模式下
|
|
100
|
+
// `get` 到 `~`(本工具最常见的备份落点)因此被无故要号、判据点也不是真实落点。回 `expandHome` 的绝对形后,
|
|
101
|
+
// 消费面的 `resolve(agent.cwd, …)` 对它恒等 ⇒ 判据点 = 真实落点,与传输件起跑点同一件叶子(D2)。
|
|
102
|
+
// 空 ∥ 非字符串 ⇒ `[]`(不虚报——缺参由 execute 的 `validateArgs` 出可读句)。
|
|
103
|
+
touchedPaths(args) {
|
|
104
|
+
const localPath = String(args?.action ?? "") === "get" ? args?.localPath : null
|
|
105
|
+
return typeof localPath === "string" && localPath.trim() !== "" ? [expandHome(localPath)] : []
|
|
106
|
+
},
|
|
73
107
|
async execute(args, ctx) {
|
|
74
108
|
const invalid = validateArgs(args)
|
|
75
109
|
if (invalid) return invalid
|
|
@@ -96,6 +130,13 @@ export const sshTool = {
|
|
|
96
130
|
res = mod.credentialsSsh()
|
|
97
131
|
} else if (action === "forget") {
|
|
98
132
|
res = mod.forgetSsh({ host: args.host, port: args.port ?? null })
|
|
133
|
+
} else if (action === "put" || action === "get") {
|
|
134
|
+
// 传输面自成一件(非交互原语:无剥离 / 无就绪判据 / 无遮蔽——塞进会话件会把两套语义混在一档)。
|
|
135
|
+
const xfer = await import("../agent-tools/ssh-transfer.mjs")
|
|
136
|
+
res = await xfer.transferSsh(parent, ctx, {
|
|
137
|
+
action, id: args.id, localPath: args.localPath, remotePath: args.remotePath,
|
|
138
|
+
overwrite: args.overwrite === true, protocol: args.protocol ?? null, timeoutMs: args.timeoutMs,
|
|
139
|
+
})
|
|
99
140
|
} else {
|
|
100
141
|
res = mod.listSsh(parent)
|
|
101
142
|
}
|
package/tools/tree.mjs
CHANGED
|
@@ -7,10 +7,13 @@
|
|
|
7
7
|
import { DESC, truncate, resolveInCwd } from "./shared.mjs"
|
|
8
8
|
import { readdir, stat } from "node:fs/promises"
|
|
9
9
|
import { join, basename, extname } from "node:path"
|
|
10
|
+
// 排除名单单源(零依赖叶档 `skip-dirs.mjs`——2026-10-27 四份名单合一):本档不再持本地副本。
|
|
11
|
+
// 两项旧值随之退场:`turbo`(无点,笔误——另三份都是 `.turbo`)、`bin`(`thincoder-cli/bin/**`
|
|
12
|
+
// 是 CLI 入口、产品代码,不该从任何面上被剪掉)。
|
|
13
|
+
import { SKIP_DIRS } from "../skip-dirs.mjs"
|
|
10
14
|
|
|
11
15
|
const MAX_ENTRIES = 200
|
|
12
16
|
const DEFAULT_DEPTH = 3
|
|
13
|
-
const SKIP_DIRS = new Set(["node_modules", "bin", "obj", "dist", "build", "coverage", "turbo", ".git", ".thincoder", ".vs", ".venv", "__pycache__", ".idea"])
|
|
14
17
|
const BINARY_EXTS = new Set([".exe", ".dll", ".png", ".jpg", ".jpeg", ".gif", ".pdf", ".docx", ".xlsx", ".pptx", ".zip", ".7z", ".mp3", ".mp4", ".woff", ".woff2", ".ico"])
|
|
15
18
|
|
|
16
19
|
// ─── cwd 归一注入缝(#56——「cwd 归一开关按端注入」,形态参 §2.13.5 注入缝)─────────
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* write-gate-params.mjs — 写门两参的说明文本单点(设计 TOOLS §1.2)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一档:`tools/shared.mjs` 越过了 500 行设计时线(`docs/core/standards/CODE-TIER.md` §7 的量法),
|
|
5
|
+
* 而这三条常量是它里面唯一能整块搬走、且搬走不动任何调用语义的部分。`tools/shared.mjs` 仍转出同一常量,
|
|
6
|
+
* 八处导入档的导入面一个字不改——文本单点与导入面分开,改口径只改一处,消费面不跟着改名。
|
|
7
|
+
*
|
|
8
|
+
* 两条身份句只答「这一笔该传什么」;完整口径(哪一档生效 ∥ 哪些工具必带 ∥ 缺什么怎么被拒)只讲一次,
|
|
9
|
+
* 在 `prompts/discipline-engineering.md` 的写门参数一节。参数行不重述它:每个入口工具各带一份近乎逐字的
|
|
10
|
+
* 副本,改一处口径要改每一处,漏一处就是两套规则在跑。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ─── 写门 `ledger` 参数(2026-11-03 笔-账绑定批 · 设计档 §2.3「工具 schema 面」)───────────────
|
|
14
|
+
// 描述单源:入口集十一把工具的 `parameters.properties.ledger` 共用下面这一条。
|
|
15
|
+
// 为什么放一处:同一个参数在十一处各写一遍 = 同一机制十一份描述,措辞一旦漂移,模型读到的规则就有十一版;
|
|
16
|
+
// 而 `memory` 的差异只是各接一句「本工具的哪一径要号」——差异走后缀,不复制全文。
|
|
17
|
+
// 为什么不进 `required`(决策 35):`required` 是静态字面,而这十一把工具在两模式、子代理、出辖目标下共用;
|
|
18
|
+
// 静态必填会让普通模式读到一条不成立的强制(写锁仅工程模式),也让子代理读到一条没人核的要求。
|
|
19
|
+
// 机械强制在门(缺号即拒),schema 只负责让模型知道有这个参数;拒文因此是唯一教学面(决策 38)。
|
|
20
|
+
export const LEDGER_PARAM_DESC = '本笔调用服务的在途台账号,`"#N"` 或 `"N"`'
|
|
21
|
+
/** `memory`:只有 `layer:"project"` 写项目内 `.thincoder/memory/**`(决策 39;`put` 缺省 `personal`)。 */
|
|
22
|
+
export const LEDGER_PARAM_DESC_MEMORY = LEDGER_PARAM_DESC
|
|
23
|
+
+ ';仅落 project 层的写型 action 要号:`layer:"project"`,或省略 `layer`、单条删除且 id 以 `project:` 开头(此时层由前缀定;`personal` ∥ `team` 落用户数据目录,不要号)'
|
|
24
|
+
/** 写门 `project` 参数(2026-11-03 项目声明面批 · 设计档 §2.3「工具 schema 面」/ 决策 40):项目根路径(带
|
|
25
|
+
* `PROJECT-MANIFEST.json` 的那个目录)—— 台账按项目根算键,所以「传项目」就是把这个根传进来,零映射表。
|
|
26
|
+
* 定位参数在场时以它为准,`project` 只补位;纯声明,不改执行目录(第二句因此是语义,不是「何时必带」)。
|
|
27
|
+
* 为什么写盘七件也各带一格(2026-11-08 工作区根窄口批 · 设计档 §2.3.1):它们的定位参数是一支支目标路径,
|
|
28
|
+
* 而「目标取不到项目根」真会发生(工作区根的文件)——那时 `project` 是唯一可用的判据点,schema 不给
|
|
29
|
+
* 这一格,门里的口子就永远触发不了(模型不知道有这个参数,第一次撞的还是拒文)。何时必带那条口径
|
|
30
|
+
* 在工程纪律段的写门参数一节,参数行只留身份。 */
|
|
31
|
+
export const PROJECT_PARAM_DESC = '本笔调用服务的项目根——带 `PROJECT-MANIFEST.json` 的那个目录(绝对路径,或相对会话 cwd)。纯声明:不改执行目录(`bash` 仍在会话 cwd 执行,`workdir` 才是改执行目录的那个)。'
|
package/tools/write-path.mjs
CHANGED
|
@@ -16,11 +16,17 @@
|
|
|
16
16
|
* 记账面(dirty-file tracking)**同源住本档**:核内写盘只此一处 ⇒ 记账面只此一处(Map/Set +
|
|
17
17
|
* 函数)。默认径的记账由本档代落——`meta.record` ⇒ `recordWrite`、`op="delete"` ⇒ `markDirty`;
|
|
18
18
|
* 调用方不再自行 `recordWrite` / `markDirty`(**不重复记账**)。**唯一例外 = apply_patch 的批级
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* 记账**——判据(谁在哪一层写记账表):写点内由写点自己记、调用方只交记录的值,只有「调用方
|
|
20
|
+
* 自持」才不经写点;`edit` 批面把合并快照当 `record` 交给本档 ⇒ 仍属写点内,不是例外。
|
|
21
|
+
* 量法(结论可复跑):仓根 `grep -rn "markDirty(\|clearLastWrite(\|recordWrite(" thincoder-core/tools`
|
|
22
|
+
* ⇒ 只有 `write-path.mjs`(定义 ∥ 写点内自用)· `patch.mjs`(批级循环,对已落盘档跑,成功 ∥ 失败
|
|
23
|
+
* 两路同、含注入径已提交那批)· `file.mjs`(`read` 清快照)三档命中;出现第四档就是又一个调用方
|
|
24
|
+
* 自持的记账面,这一句要重判。`file.mjs` 只做再导出,保既有 import 面稳定(模块拆分写优先纪律)。
|
|
21
25
|
*/
|
|
22
26
|
import { writeFile, unlink, rename, cp, rm, rmdir } from "node:fs/promises"
|
|
23
27
|
|
|
28
|
+
import { runDocWriteGate } from "./doc-write-gate.mjs"
|
|
29
|
+
|
|
24
30
|
/** apply_patch 两段式的暂存后缀(单点定义——阶段一落暂存档、阶段二提交、失败清理均用它)。 */
|
|
25
31
|
export const TMP_SUFFIX = ".thincoder-tmp"
|
|
26
32
|
|
|
@@ -34,9 +40,9 @@ export function markDirty(abs) { dirtyPaths.add(abs) }
|
|
|
34
40
|
export function clearDirty(abs) { dirtyPaths.delete(abs) }
|
|
35
41
|
export function isDirty(abs) { return dirtyPaths.has(abs) }
|
|
36
42
|
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
// write 全文重写 →
|
|
43
|
+
// 写入工具记录受影响行范围(受影响区 = 从 startLine 起、净漂移 shift 行)——行号锚护栏
|
|
44
|
+
// 的数据源:目标区整体在受影响区之前 → 行号未漂移 → 允许;区内或其下 → 拒;
|
|
45
|
+
// write 全文重写 → 全文件受影响,任何行号都拒。判据本体 = 下方 `lineAnchorVerdict`。
|
|
40
46
|
const lastWrites = new Map() // abs → { type: 'write'|'edit'|'insert', startLine, shift }
|
|
41
47
|
export function recordWrite(abs, write) {
|
|
42
48
|
lastWrites.set(abs, write)
|
|
@@ -74,6 +80,67 @@ export function resetWritePath() { injected = null }
|
|
|
74
80
|
export const dirtyRefusalMessage = (abs) =>
|
|
75
81
|
`File has unsaved changes in the editor: ${abs}. Save or discard before allowing automated edits.`
|
|
76
82
|
|
|
83
|
+
// ────────────────────────────────────────
|
|
84
|
+
// 行号锚护栏(edit 行号形 ∥ insert_after 共用的唯一判据)
|
|
85
|
+
// ────────────────────────────────────────
|
|
86
|
+
/**
|
|
87
|
+
* 判据(六行按序判):放行 ⇒ `null`;拒绝 ⇒ 命中行的实况
|
|
88
|
+
* `{ row, type?, startLine?, shift? }`(row = §3 的行号 1–6)。
|
|
89
|
+
*
|
|
90
|
+
* @param {string} abs 目标绝对路径(记账键)
|
|
91
|
+
* @param {number|null} startLine 目标区首行;`null` = 调用方没有行号目标(正则定位形)
|
|
92
|
+
* @param {number|null} endLine 目标区末行(单行形与 startLine 同值)
|
|
93
|
+
*/
|
|
94
|
+
export function lineAnchorVerdict(abs, startLine, endLine) {
|
|
95
|
+
const lw = lastWrites.get(abs)
|
|
96
|
+
const dirty = dirtyPaths.has(abs)
|
|
97
|
+
if (!lw) return dirty ? { row: 6 } : null // 行 1 放行 / 行 6 拒
|
|
98
|
+
if (dirty) return { row: 2, type: lw.type, startLine: lw.startLine, shift: lw.shift }
|
|
99
|
+
// 行 3–5 判的是「模型给的行号」,没有行号目标就无从判——只判到记账态这一层
|
|
100
|
+
if (startLine == null) return null
|
|
101
|
+
if (lw.type === "write") return { row: 3, type: "write" }
|
|
102
|
+
// 「整体在之前」的边界按记账类型分:替换要读也写目标行(`<`),插入只落在两行之间(`<=`)
|
|
103
|
+
const last = endLine ?? startLine
|
|
104
|
+
const untouched = lw.type === "insert" ? last <= lw.startLine : last < lw.startLine
|
|
105
|
+
if (untouched) return null // 行 4 放行
|
|
106
|
+
return { row: 5, type: lw.type, startLine: lw.startLine, shift: lw.shift }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 第 1 / 3 / 5 行的首句之后共用的三要素(两条下一步 + 第二条路的成立条件)。 */
|
|
110
|
+
const LINE_ANCHOR_NEXT_STEPS =
|
|
111
|
+
`Editing by the old numbers would land on the wrong lines and still report success.\n` +
|
|
112
|
+
`Two ways on:\n` +
|
|
113
|
+
` 1. read this file again and retry with the new line numbers;\n` +
|
|
114
|
+
` 2. address the region without line numbers — pass its current content as old_string, or use hashline_edit,\n` +
|
|
115
|
+
` which needs old_hashes from a read with hashes=true and is only valid while that block's content is unchanged.`
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 拒文(单点构造——edit 行号形与 insert_after 同句;四要素固定:路径与漂移事实 / 重 read /
|
|
119
|
+
* 改走位置无关寻址 / 那条路的成立条件)。事实取自 `lineAnchorVerdict`,不另算一份。
|
|
120
|
+
*
|
|
121
|
+
* 第 2 行(脏 ∧ 陈旧快照)与第 6 行(无快照但脏)报不出「上次写入点 + 漂移量」——首句改成
|
|
122
|
+
* 说清这两个数不可得,其余三要素不变(照填一个不可信的数字等于把它重新递给模型)。
|
|
123
|
+
*/
|
|
124
|
+
export function lineAnchorRefusal(abs, startLine, endLine) {
|
|
125
|
+
const hit = lineAnchorVerdict(abs, startLine, endLine)
|
|
126
|
+
if (!hit) {
|
|
127
|
+
throw new Error("lineAnchorRefusal: the call passes the line-anchor criterion — no refusal to build")
|
|
128
|
+
}
|
|
129
|
+
const range = startLine == null ? null : endLine == null || startLine === endLine ? `L${startLine}` : `L${startLine}-L${endLine}`
|
|
130
|
+
const head = hit.row === 2
|
|
131
|
+
? `${abs} — these line numbers are stale, and the drift cannot be measured: a write in this session changed\n` +
|
|
132
|
+
`this file after the recorded write point, so neither that line nor an offset from it can be trusted.`
|
|
133
|
+
: hit.row === 6
|
|
134
|
+
? `${abs} — this file was modified since your last read; line numbers may be stale, and there is no recorded\n` +
|
|
135
|
+
`write point to check them against.`
|
|
136
|
+
: hit.row === 3
|
|
137
|
+
? `${abs} — these line numbers are stale: this file was rewritten in full by a write since your last read,\n` +
|
|
138
|
+
`so no line number from that read can still be trusted.`
|
|
139
|
+
: `${abs} — these line numbers are stale: the last write to this file was at L${hit.startLine}\n` +
|
|
140
|
+
`(line numbers are now offset by ${hit.shift >= 0 ? "+" : ""}${hit.shift}), and the target range ${range} falls inside or below it.`
|
|
141
|
+
return `${head}\n${LINE_ANCHOR_NEXT_STEPS}`
|
|
142
|
+
}
|
|
143
|
+
|
|
77
144
|
/**
|
|
78
145
|
* 门禁单点(src 面与 dest 面共用——每面各问一次 `openDoc`):
|
|
79
146
|
* fail-closed(给了 `applyEdit` 却没给 `isDirty` ⇒ 脏态不可知 ⇒ 抛配置错,不静默退化为
|
|
@@ -183,9 +250,15 @@ async function defaultPath(abs, content, meta) {
|
|
|
183
250
|
* `via:"editor"` 与 `meta.stage` 组合 = 编辑器径已直接提交目标档(无暂存档)
|
|
184
251
|
*/
|
|
185
252
|
export async function writeThroughPath(abs, content, meta = {}) {
|
|
253
|
+
const op = meta.op ?? "write"
|
|
254
|
+
// **写前文档机检门**(`docs/core/design/DOC-DISCIPLINE.md` §3.26 条目 Z):只挂内容写点,且写在两条落盘径
|
|
255
|
+
// 之前——命中即 throw,于是目标档与暂存档都还是零字节。其余 op(commit ∥ delete ∥ rmdir ∥ copy ∥ move ∥
|
|
256
|
+
// rename)不写文档内容 ⇒ 零门调用。`apply_patch` 两段式的第一段(`op:"write"` + `stage`)判,提交段不判。
|
|
257
|
+
// 普通模式(meta.agent.config.agent.engineering === false)不运行内容写门;无 agent 的低层调用保持原行为。
|
|
258
|
+
if (op === "write" && meta.agent?.config?.agent?.engineering !== false) await runDocWriteGate({ abs, content })
|
|
186
259
|
// `op="commit"` = 默认径两段式的收尾(暂存档 → 目标)——编辑器径是即时提交、不产生暂存
|
|
187
260
|
// 档 ⇒ 无端侧载体,不再问注入面(避免无意义的门禁调用;目标档的门禁已在 staging 问过)。
|
|
188
|
-
if (
|
|
261
|
+
if (op !== "commit") {
|
|
189
262
|
const handled = await tryInjectedPath(abs, content, meta)
|
|
190
263
|
if (handled) return handled
|
|
191
264
|
}
|
package/traces/trace-store.mjs
CHANGED
|
@@ -222,11 +222,12 @@ export function recordChatTrace(provider, opts = {}, result = null, error = null
|
|
|
222
222
|
const logCtx = opts.logCtx ?? {}
|
|
223
223
|
if (!tracesEnabled(logCtx)) return
|
|
224
224
|
// cwd/session 经 logCtx 增补(调用点传 agent.cwd / agent._sessionStart——
|
|
225
|
-
// D-TR3 的 cwdHash/命名与 D-TR1 的 session
|
|
226
|
-
//
|
|
225
|
+
// D-TR3 的 cwdHash/命名与 D-TR1 的 session 字段所需);logCtx 未携 cwd(无 agent 作用域
|
|
226
|
+
// 的调用点)⇒ 该值缺失即失败,不回落进程 cwd(换界会静默写错会话目录)。
|
|
227
|
+
// 该类点开关状态:distill 已含
|
|
227
228
|
// traces 开关(D-TR6 fix round1);auto-think 已闭环(D-TS12——chat 调用点
|
|
228
229
|
// logCtx 全字段补传:traces/session/cwd/role/depth/kind——无残留点)。
|
|
229
|
-
const cwd = logCtx.cwd
|
|
230
|
+
const cwd = logCtx.cwd
|
|
230
231
|
// D-TR3(fix round1):分日按本地时区(_traceHooks.now——T-TR12 注入点);
|
|
231
232
|
// ts 与 dateStr 同源(同一时刻)——记录时间戳与目录日不撕裂。
|
|
232
233
|
const now = _traceHooks.now()
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* window-policy.mjs — 窗口策略面(有效窗口 ∥ 两个预算出口 ∥ 压缩线派生)。
|
|
3
|
+
*
|
|
4
|
+
* 迁出:`config.mjs` 的预算族(`outputReserve` ∥ `usableWindow` ∥ `requestBudget` ∥
|
|
5
|
+
* `resolveCompactThreshold`)整族迁入本档;`config.mjs` 经 `export … from` 转口保既有导入面(先例 =
|
|
6
|
+
* `model-specs.mjs` 自 `config.mjs` 抽出的同形)。
|
|
7
|
+
* 新增:`TINY_WINDOW_CAP` ∥ `effectiveWindow` ∥ `policyBudget`——窗口只有一个事实来源(`providerSpec`
|
|
8
|
+
* 的五级链,`PROVIDER.md` §6.15),策略出口只有 `effectiveWindow` 一个(`CONTEXT-COMPACTION.md` §2.1 / §2.2)。
|
|
9
|
+
*
|
|
10
|
+
* 为什么要单出一层:策略值只从 `workMode` 现算,**不落在 provider ∥ config 对象上**——派生字段会被落盘 ∥
|
|
11
|
+
* 跨会话带走,「切出 tiny 即解除」就只能靠下一次装配才成立,而它必须在下一处读数上就生效。
|
|
12
|
+
* 缺参即拒(§2.3):`workMode` 无默认值,值不在 `WORK_MODES` 里就在函数入口拒绝并点名参数——默认值会把
|
|
13
|
+
* 「忘传」静默成一条不下上限的窗口,压缩线随之上移,人要等到账单才发现。
|
|
14
|
+
*
|
|
15
|
+
* 派生链(§2.2):`window` 是唯一输入。`reserve` 与窗口无关;`limit = window − reserve`;`threshold =
|
|
16
|
+
* min(limit − INJECT_HEADROOM_TOKENS, RETAIN_CAP_TOKENS)`。三个量对窗口的斜率分别是 0 ∥ 1 ∥ 1,封顶段上
|
|
17
|
+
* `threshold` 的斜率转 0 ⇒ 窗口增大时两线都不减小(恒定不算减小)。
|
|
18
|
+
* 算式里没有比例项,也没有静默兜底:派生不成立就在装载期抛(§2.4)。
|
|
19
|
+
*
|
|
20
|
+
* 依赖面 = `model-specs.mjs`(`providerSpec` ∥ `providerSpecResolution`)+ `config-migrate.mjs`
|
|
21
|
+
* (`WORK_MODES`)——**零 import 环**(本档不 import `config.mjs`,只被它转口)。
|
|
22
|
+
*/
|
|
23
|
+
import { providerSpec, providerSpecResolution } from "./model-specs.mjs"
|
|
24
|
+
import { WORK_MODES } from "./config-migrate.mjs"
|
|
25
|
+
|
|
26
|
+
/** tiny 档的有效窗口上限(token):`CONTEXT-COMPACTION.md` §2.1 的策略值。数值在本档只出现这一处。 */
|
|
27
|
+
export const TINY_WINDOW_CAP = 262144
|
|
28
|
+
|
|
29
|
+
/** 压缩线上方留给注入上下文的余量(`CONTEXT-COMPACTION.md` §2.2)。
|
|
30
|
+
* Headroom above the line absorbs injected context (directory tree, git context, outline, project instructions,
|
|
31
|
+
* memory/doc search — 30–50K). 这些量按会话注入、**不随窗口缩放**:1M 窗口上与 320K 窗口上它们占同样多的条目,
|
|
32
|
+
* 所以正确的刻度是绝对量,不是窗口比例。
|
|
33
|
+
* 取上界 50000 的理由不对称:估小一档的后果是注入把 prompt 顶过硬上限而压缩线帮不上(守卫报 `context_overflow`),
|
|
34
|
+
* 估大一档只多付一次早压。 */
|
|
35
|
+
export const INJECT_HEADROOM_TOKENS = 50000
|
|
36
|
+
|
|
37
|
+
/** 压缩线的绝对上限(`CONTEXT-COMPACTION.md` §2.2):`threshold` 不越过这个数,窗口再大也一样。
|
|
38
|
+
* 理由是用户的现场观测:上下文越长部分模型的注意力越衰减,1M 窗口的模型也只要求用到 256K。这是观测事实,
|
|
39
|
+
* 不是估算,也不是可以按模型重推的推断,所以它是一个显式常量而不是派生值。
|
|
40
|
+
* 它封的是**压缩线**:`TINY_WINDOW_CAP`(同值 262144)封的是**窗口**——同值不同物,改一个不动另一个。
|
|
41
|
+
* 只夹 `threshold`,不夹 `limit`:`limit` 是物理线(窗口减预留),把它压到之下会在真实越窗之前就报错。 */
|
|
42
|
+
export const RETAIN_CAP_TOKENS = 262144
|
|
43
|
+
|
|
44
|
+
/** 模式入参的准入判据(§2.3 缺参即拒):无默认值。合法值域单源 = `WORK_MODES`(不在此重列字面)。 */
|
|
45
|
+
function assertWorkMode(workMode, fnName) {
|
|
46
|
+
if (!WORK_MODES.includes(workMode)) {
|
|
47
|
+
throw new Error(`${fnName}: workMode is required and must be one of ${WORK_MODES.join(" / ")} — got ${JSON.stringify(workMode)}`)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 策略收敛的唯一算式(§2.1):tiny 取 min(模型窗口, TINY_WINDOW_CAP);其余档逐位返回模型窗口。
|
|
52
|
+
* `effectiveWindow` 与 `policyBudget` 同调本函数——两处各写一遍就是一个政策两个实现。 */
|
|
53
|
+
function capWindow(modelWindow, workMode) {
|
|
54
|
+
return workMode === "tiny" ? Math.min(modelWindow, TINY_WINDOW_CAP) : modelWindow
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 有效窗口(§2.1):本 run 参与预算算式和一切上下文百分比分母的输入窗口。它由模型的真实窗口经工作模式
|
|
59
|
+
* 策略收敛得到,是**策略值**,不是模型事实——模型事实仍只由 `providerSpec` 回答,本档不改它。
|
|
60
|
+
* 窗口派生的一切读数(threshold ∥ limit ∥ 尾部两式 ∥ 百分比分母)全从本函数取,端侧不另立算式。
|
|
61
|
+
* @param {object} provider 在用渠道条目(含 model)
|
|
62
|
+
* @param {"tiny"|"normal"|"engineering"} workMode 必填,无缺省
|
|
63
|
+
*/
|
|
64
|
+
export function effectiveWindow(provider, workMode) {
|
|
65
|
+
assertWorkMode(workMode, "effectiveWindow")
|
|
66
|
+
return capWindow(providerSpec(provider).context, workMode)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ─── 预算族(自 `config.mjs` 迁出;算式 = §2.2 的四行)────────────────────────
|
|
70
|
+
|
|
71
|
+
// absent 档的服务端默认输出(`CONTEXT-COMPACTION.md` §2.2.1)。三个数的唯一出处 =
|
|
72
|
+
// https://api-docs.deepseek.com/zh-cn/api/create-chat-completion 的 `max_tokens` 段:
|
|
73
|
+
// 「限制一次请求中模型生成 completion 的最大 token 数。取值范围为 1 到 384K(393216)。未设置时,非思考模式
|
|
74
|
+
// 默认 8K,思考模式默认 64K(`reasoning_effort` 为 `max` 时为 128K)。」
|
|
75
|
+
// 要改这三个数,先改那条文档事实——它们不是我们的旋钮,是服务端收到请求后自己会生成多少。
|
|
76
|
+
const DEFAULT_OUTPUT_PLAIN = 8_192
|
|
77
|
+
const DEFAULT_OUTPUT_THINKING = 65_536
|
|
78
|
+
const DEFAULT_OUTPUT_MAX_EFFORT = 131_072
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Output reservation counted against the window (`CONTEXT-COMPACTION.md` §2.2.1): what THIS request
|
|
82
|
+
* actually takes out of the window for output.
|
|
83
|
+
* - explicit `provider.maxTokens` ⇒ that value verbatim (the transport sends it as max_tokens).
|
|
84
|
+
* - `format === "anthropic"` ⇒ `spec.maxOutput` (that face always sends max_tokens ⇒ spec 档).
|
|
85
|
+
* - absent 档(transport sends no max_tokens)⇒ `min(spec.maxOutput, 服务端默认输出)`: the server reserves
|
|
86
|
+
* its own default, not the model's capability ceiling.
|
|
87
|
+
* explicit 档与 spec 档**不封顶**:那两档的 reserve 就是实发输出预算,封顶等于把真实输出挤进输入里
|
|
88
|
+
* (教训见 2026-10-18 overflow 400:`budget counted 250_000, 393_216 actually sent`)。
|
|
89
|
+
* 分支只有这一处:`budgetOf` 照本函数的返回值取数,不另判一次档。
|
|
90
|
+
*/
|
|
91
|
+
export function outputReserve(provider, spec) {
|
|
92
|
+
// 与 `budgetOf` 同一归一(`Number(...)` + 有限正数判):两处各写一种取值判,explicit 档的 reserve
|
|
93
|
+
// 就会与实际发出的 maxTokens 分成两个数。
|
|
94
|
+
const rawExplicit = Number(provider?.maxTokens)
|
|
95
|
+
const explicit = Number.isFinite(rawExplicit) && rawExplicit > 0 ? rawExplicit : undefined
|
|
96
|
+
if (explicit !== undefined) return explicit
|
|
97
|
+
const maxOutput = spec?.maxOutput ?? 0
|
|
98
|
+
if (provider?.format === "anthropic") return maxOutput
|
|
99
|
+
const defaultOutput = provider?.reasoningEffort === "max"
|
|
100
|
+
? DEFAULT_OUTPUT_MAX_EFFORT
|
|
101
|
+
: (spec?.thinking ? DEFAULT_OUTPUT_THINKING : DEFAULT_OUTPUT_PLAIN)
|
|
102
|
+
return Math.min(maxOutput, defaultOutput)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Usable input window = window − output reservation (§2.2 的 `limit`)。判据单点(§2.4):
|
|
107
|
+
* `reserve ≥ window` 时派生链没有解——没有任何输入装得下,`limit ≤ 0`、`threshold < 0`。
|
|
108
|
+
* 这一格不静默兜底:配置不成立就在装载期抛,报文点三个数(window ∥ reserve ∥ 差值)与三条出路。
|
|
109
|
+
* 留到发送期才报的后果是报文说 `context_overflow`、指向会话内容,而真实原因是配置矛盾。
|
|
110
|
+
*/
|
|
111
|
+
export function usableWindow(context, reserve) {
|
|
112
|
+
const ctx = context ?? 0
|
|
113
|
+
const usable = ctx - reserve
|
|
114
|
+
if (usable <= 0) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`usableWindow: the output reservation ${reserve} leaves no input window — window ${ctx} − reserve ${reserve} = ${usable}. ` +
|
|
117
|
+
`No prompt can fit this configuration: raise the window (providers[].modelContext / a larger-context model), ` +
|
|
118
|
+
`lower provider.maxTokens, or use a model whose maxOutput is smaller than its window.`,
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
return usable
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The one budget formula (§2.2) — window is the ONLY input that differs between the two exits.
|
|
126
|
+
* Fields:
|
|
127
|
+
* - window / windowSource: the input window this budget was computed on, plus its source name
|
|
128
|
+
* (closed set { modelContext | provider-override | list | spec | default }, passed through
|
|
129
|
+
* verbatim — no class merging).
|
|
130
|
+
* - maxTokens / maxTokensSource: the value THIS transport writes into the request body —
|
|
131
|
+
* anthropic always sends it (explicit ?? spec.maxOutput); the other three faces send only an
|
|
132
|
+
* explicit provider.maxTokens, absent ⇒ undefined / "absent". Never a guard criterion
|
|
133
|
+
* (undefined ⇒ NaN — §6.17 guard); the guard reads limit instead.
|
|
134
|
+
* - reserve: what the request actually takes out of the window for output (see `outputReserve`).
|
|
135
|
+
* - limit: window − reserve — the input ceiling the server accepts (prompt + reserved output ≤ window).
|
|
136
|
+
* - threshold: min(limit − INJECT_HEADROOM_TOKENS, RETAIN_CAP_TOKENS) — the compaction trigger line.
|
|
137
|
+
* The cap clamps the LINE only, never `limit`: the guard line must stay below the physical one, or a
|
|
138
|
+
* request that fits would be refused before it ever overflows.
|
|
139
|
+
* 派生不成立(reserve ≥ window、threshold ≤ 0)都在这里抛(§2.4):守卫面因此永远拿到一个正数 `limit`。
|
|
140
|
+
*/
|
|
141
|
+
function budgetOf(provider, spec, window, windowSource) {
|
|
142
|
+
const explicitRaw = Number(provider?.maxTokens)
|
|
143
|
+
const explicit = Number.isFinite(explicitRaw) && explicitRaw > 0 ? explicitRaw : undefined
|
|
144
|
+
const anthropicAlwaysSends = provider?.format === "anthropic"
|
|
145
|
+
const maxTokens = explicit ?? (anthropicAlwaysSends ? spec?.maxOutput ?? 0 : undefined)
|
|
146
|
+
const maxTokensSource = explicit != null ? "explicit" : anthropicAlwaysSends ? "spec" : "absent"
|
|
147
|
+
const reserve = outputReserve(provider, spec)
|
|
148
|
+
const limit = usableWindow(window, reserve)
|
|
149
|
+
// 封顶只夹压缩线(§2.2):RETAIN_CAP_TOKENS 是正数 ⇒ 下面的非正判据只可能出自第一个臂。
|
|
150
|
+
const threshold = Math.min(limit - INJECT_HEADROOM_TOKENS, RETAIN_CAP_TOKENS)
|
|
151
|
+
if (threshold <= 0) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`budgetOf: the compaction line does not exist — window ${window} − reserve ${reserve} = ${limit} input tokens, ` +
|
|
154
|
+
`but the injected context needs ${INJECT_HEADROOM_TOKENS} of headroom above the line. ` +
|
|
155
|
+
`The window fits the output reservation and not the injection: raise the window or lower provider.maxTokens.`,
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
return { window, windowSource, maxTokens, maxTokensSource, reserve, limit, threshold }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Request budget — the MODEL-window exit (§2.2). Single source for the actually-sent max_tokens
|
|
162
|
+
* (CONTEXT-COMPACTION.md §6.17 / D-CC32). Four consumer faces read it here for that one purpose:
|
|
163
|
+
* the four transport faces (`provider/core.mjs` OpenAI-compatible ∥ `provider/anthropic.mjs`
|
|
164
|
+
* Messages ∥ `provider/google.mjs` generateContent ∥ `provider/responses-request.mjs` Responses)
|
|
165
|
+
* read ONLY maxTokens — max_tokens is the output contract, untouched by any input-window policy.
|
|
166
|
+
* Everything that measures the INPUT window reads `policyBudget` instead (§2.2).
|
|
167
|
+
* 窗口来源 = 五级链的同一次遍历出口(§6.15)——L1 / L3 命中也会如实报来源,不再二值猜。
|
|
168
|
+
* 调用方传 spec(core.mjs 已算过 providerSpec)时窗口值用它,来源仍读 resolution(恒等映射,不并类)。 */
|
|
169
|
+
export function requestBudget(provider, spec) {
|
|
170
|
+
const resolution = providerSpecResolution(provider)
|
|
171
|
+
const resolved = spec ?? resolution.spec
|
|
172
|
+
return budgetOf(provider, resolved, resolved?.context ?? 0, resolution.source)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Policy budget — the EFFECTIVE-window exit (§2.2): what the compaction threshold, the stats face
|
|
176
|
+
* and the pre-send guard read (window ∥ limit ∥ threshold).
|
|
177
|
+
* `maxTokens ∥ maxTokensSource ∥ reserve ∥ windowSource` 逐位转交 `requestBudget`(同一算式、同一次五级链
|
|
178
|
+
* 遍历),不另算;与它不同的只有窗口那一边 = `effectiveWindow`。`windowSource` 说的是**模型窗口**的来源名,
|
|
179
|
+
* 在 tiny 档下窗口已被策略收敛到 `TINY_WINDOW_CAP`——照抄而不另起一个来源名,是 §2.2 的裁定。
|
|
180
|
+
* @param {object} provider 在用渠道条目
|
|
181
|
+
* @param {object} [spec] 调用方已算过的 providerSpec(省一次查表;来源仍读五级链)
|
|
182
|
+
* @param {"tiny"|"normal"|"engineering"} workMode 必填,无缺省
|
|
183
|
+
*/
|
|
184
|
+
export function policyBudget(provider, spec, workMode) {
|
|
185
|
+
assertWorkMode(workMode, "policyBudget")
|
|
186
|
+
const resolution = providerSpecResolution(provider)
|
|
187
|
+
const resolved = spec ?? resolution.spec
|
|
188
|
+
return budgetOf(provider, resolved, capWindow(resolved?.context ?? 0, workMode), resolution.source)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Derive compaction threshold; explicit is the value explicitly set in config file (takes priority),
|
|
192
|
+
* otherwise auto = policyBudget().threshold (§6.17 single source — min(limit − INJECT_HEADROOM_TOKENS,
|
|
193
|
+
* RETAIN_CAP_TOKENS), over the EFFECTIVE window, §2.1). Second param accepts EITHER a model name string (pure spec lookup —
|
|
194
|
+
* compat shape, no caller passes a string today) OR a provider object (providerSpec — the
|
|
195
|
+
* providers[].context override in K units is honored, PROVIDER.md §15 T-C2).
|
|
196
|
+
* `workMode` is checked at the entrance even when `explicit` is present: the value domain has one
|
|
197
|
+
* gate, and a caller that forgot the mode is wrong whichever branch it lands on. */
|
|
198
|
+
export function resolveCompactThreshold(explicit, modelOrProvider, workMode) {
|
|
199
|
+
assertWorkMode(workMode, "resolveCompactThreshold")
|
|
200
|
+
if (explicit != null) return { value: explicit, auto: false }
|
|
201
|
+
const provider = typeof modelOrProvider === "string" ? { model: modelOrProvider } : (modelOrProvider ?? {})
|
|
202
|
+
return { value: policyBudget(provider, undefined, workMode).threshold, auto: true }
|
|
203
|
+
}
|
package/agent/light-round.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* agent/light-round.mjs — 轻通道代码笔通路谓词(F-LC5 · 设计 = `docs/core/design/LIGHT-CHANNEL.md` §2.8)。
|
|
3
|
-
*
|
|
4
|
-
* `lightRoundOpen(agent)`:闸读判据——**两件双在盘**才算轻通道轮在盘:
|
|
5
|
-
* ① 轮次台账行:`status = 在途` ∧ `title` 携「收尾链待跑」(轮型标记 = 闸凭据)∧ `task_book` 非空;
|
|
6
|
-
* ② 该指针指向的轮次批档:`§1` 状态行 = 「进行中」(判定器单源 = `readBatchStatusLine`)。
|
|
7
|
-
* 查找面(纯向下)= 会话锚 + 其直接子目录一层(候选枚举单源 = `ledgerChildren`——与族发现同级判据
|
|
8
|
-
* 同源;不递归 ∥ 不取同胞):逐候选查行 ∥ 以各候选为基解析指针(台账写门同式)。歧义候选
|
|
9
|
-
* (`projectRootView` 判 `workspace`——如工作区锚自身)⇒ 跳过该候选、照查其余(既定观察态,非读错);
|
|
10
|
-
* 候选读错 ∥ 不可判 ⇒ 停本候选(总判不因他候选读错而失——开路凭据仍是「两件校验全过」)。
|
|
11
|
-
* 语义:开门动作 ≡ 开轮两件落盘(「启动即挂账」本体——无独立于账的开门面);单件不放行
|
|
12
|
-
* (轮档独在 ∥ 行独在 ∥ 无标记 ∥ 行非在途 ∥ 指针失据 ∥ 档已收口 ⇒ 皆 false);收口即自闭
|
|
13
|
-
* (信号生命周期 = 账生命周期——零撤销动作 ∥ 零跨轮残留)。
|
|
14
|
-
* 读错 ∥ 不可判 ⇒ `false`(fail-closed——照拦;被拦时文案不因读错而变)。
|
|
15
|
-
* 只读:台账 = `ledgerQuery` **动态 import**(`ledger-db.mjs` 静态 import node:sqlite ⇒
|
|
16
|
-
* 消费侧静态 import 破 W8 契约②);批档 = 一次 `readFileSync`。
|
|
17
|
-
*/
|
|
18
|
-
import { readFileSync } from "node:fs"
|
|
19
|
-
import { resolve } from "node:path"
|
|
20
|
-
import { projectRootView, resolveProjectRoot } from "../manifest.mjs"
|
|
21
|
-
import { resolveDeclaredRef } from "../declaration.mjs"
|
|
22
|
-
import { readBatchStatusLine } from "../agent-tools/batch-skeleton.mjs"
|
|
23
|
-
|
|
24
|
-
/** 轻通道轮在盘谓词(异步 · 只读 · fail-closed)。契约见头注。
|
|
25
|
-
* @param {object} agent — 会话 agent(读 `cwd`)
|
|
26
|
-
* @returns {Promise<boolean>} true = 放行(在盘轮次);读错 ∥ 不可判 ⇒ false(照拦)
|
|
27
|
-
*/
|
|
28
|
-
export async function lightRoundOpen(agent) {
|
|
29
|
-
try {
|
|
30
|
-
const cwd = agent?.cwd
|
|
31
|
-
if (typeof cwd !== "string" || cwd.trim() === "") return false
|
|
32
|
-
// W8 契约②:node:sqlite 链只经动态 import 进入(勿升静态)——候选枚举与逐候选查行同取本档公共面。
|
|
33
|
-
const { ledgerChildren, ledgerQuery, ROUND_MARKER } = await import("../ledger.mjs")
|
|
34
|
-
const anchor = resolve(cwd)
|
|
35
|
-
// 候选面 = 锚自身 + 直接子目录一层(纯向下;子项枚举单源 = `ledgerChildren`)。
|
|
36
|
-
const candidates = [anchor, ...ledgerChildren(anchor).map((p) => p.root)]
|
|
37
|
-
for (const cand of candidates) {
|
|
38
|
-
// 工作区候选(下辖 ≥2 项目——`projectRootView`)⇒ 跳过、照查其余(工作区锚不充当项目 = AC-M2-19 同判;
|
|
39
|
-
// 该态判据 = 根推导单源「已注册」的库臂排除(键控库在盘 ≠ 可作项目)——既定观察态,非读错)。
|
|
40
|
-
if (projectRootView(cand).state === "workspace") continue
|
|
41
|
-
let rows
|
|
42
|
-
try { rows = ledgerQuery({ cwd: cand, status: "在途" }) } catch { continue } // 候选读错 ⇒ 停本候选
|
|
43
|
-
if (!Array.isArray(rows) || rows.length === 0) continue
|
|
44
|
-
// 指针基准 = 台账写门同式(`ledger-cmd.mjs` assertTaskBookGate 同一子表达式)——以各候选为基。
|
|
45
|
-
const base = resolveProjectRoot(cand) ?? resolve(cand ?? ".")
|
|
46
|
-
for (const row of rows) {
|
|
47
|
-
if (!String(row?.title ?? "").includes(ROUND_MARKER)) continue // 无标记 ⇒ 非轻通道轮(全链批行)
|
|
48
|
-
const taskBook = row?.task_book
|
|
49
|
-
if (typeof taskBook !== "string" || taskBook.trim() === "") continue // 缺指针 ⇒ 单件不放行
|
|
50
|
-
const part = taskBook.split("§")[0].trim() // 台账写门同式:首个 § 前子串
|
|
51
|
-
if (part === "") continue
|
|
52
|
-
const hit = resolveDeclaredRef(base, part)
|
|
53
|
-
if (!hit.ok) continue // 指针失据 ⇒ 不放行
|
|
54
|
-
let src
|
|
55
|
-
try { src = readFileSync(hit.abs, "utf8") } catch { continue } // 档读不到 ⇒ 不放行
|
|
56
|
-
if (readBatchStatusLine(src) === "open") return true // 两件双在盘 ⇒ 放行
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return false
|
|
60
|
-
} catch {
|
|
61
|
-
return false // 读错 ∥ 不可判 ⇒ fail-closed(照拦)
|
|
62
|
-
}
|
|
63
|
-
}
|