@thincoder/core 0.11.3 → 0.11.5

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.
Files changed (183) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/advisor/compaction.mjs +40 -17
  3. package/advisor/loop.mjs +14 -6
  4. package/advisor/notice.mjs +1 -1
  5. package/advisor/timeline.mjs +4 -4
  6. package/agent/completion.mjs +19 -0
  7. package/agent/dispatch-gates.mjs +2 -0
  8. package/agent/dispatch.mjs +2 -2
  9. package/agent/family-tools.mjs +13 -9
  10. package/agent/helpers.mjs +10 -6
  11. package/agent/planning-step.mjs +453 -0
  12. package/agent/post-turn.mjs +70 -2
  13. package/agent/run-stages.mjs +22 -50
  14. package/agent/run-start.mjs +17 -0
  15. package/agent/setup-reminders.mjs +71 -8
  16. package/agent/setup.mjs +8 -39
  17. package/agent/spawn-child.mjs +6 -2
  18. package/agent/task-lifecycle.mjs +146 -0
  19. package/agent/turn-loop.mjs +73 -11
  20. package/agent-tools/batch-closeout.mjs +21 -34
  21. package/agent-tools/batch-gate.mjs +7 -5
  22. package/agent-tools/batch-ledger-bind.mjs +21 -1
  23. package/agent-tools/batch-lifecycle.mjs +7 -7
  24. package/agent-tools/batch-record-write.mjs +237 -280
  25. package/agent-tools/batch-supersede.mjs +3 -3
  26. package/agent-tools/batch.mjs +42 -9
  27. package/agent-tools/context.mjs +0 -13
  28. package/agent-tools/escalate-async.mjs +7 -1
  29. package/agent-tools/parent-channel.mjs +7 -6
  30. package/agent-tools/plan.mjs +103 -67
  31. package/agent-tools/review-facts.mjs +3 -3
  32. package/agent-tools/settings.mjs +2 -0
  33. package/agent-tools/spawn-gates.mjs +37 -11
  34. package/agent-tools/ssh-session.mjs +68 -25
  35. package/agent-tools/ssh-transfer.mjs +7 -2
  36. package/agent-tools/ssh-transport.mjs +2 -2
  37. package/agent-tools/ssh-vault.mjs +2 -2
  38. package/agent-tools/step.mjs +462 -0
  39. package/agent-tools/subagent-actions.mjs +6 -1
  40. package/agent-tools/subagent-run.mjs +7 -0
  41. package/agent-tools/subagent-spawn.mjs +1 -1
  42. package/agent-tools/subagent.mjs +17 -11
  43. package/agent-tools/task.mjs +178 -26
  44. package/agent-tools.mjs +1 -0
  45. package/agent.mjs +2 -0
  46. package/config-defaults.mjs +17 -1
  47. package/config-migrate.mjs +8 -5
  48. package/config.mjs +7 -0
  49. package/context.mjs +5 -4
  50. package/declaration.mjs +4 -4
  51. package/generate-title.mjs +0 -6
  52. package/i18n.mjs +4 -0
  53. package/ledger-cmd.mjs +11 -1
  54. package/ledger-tools.mjs +15 -4
  55. package/manifest-schema.mjs +1 -0
  56. package/model-context.mjs +34 -11
  57. package/model-specs.mjs +5 -2
  58. package/package.json +1 -1
  59. package/prompt-files.mjs +48 -11
  60. package/prompt-overlays.mjs +79 -8
  61. package/prompts/advisor-design.md +253 -206
  62. package/prompts/advisor-round1.md +151 -145
  63. package/prompts/advisor-round2.md +136 -130
  64. package/prompts/advisor-round3.md +140 -134
  65. package/prompts/common.md +244 -96
  66. package/prompts/consult-base.md +29 -30
  67. package/prompts/discipline-engineering.md +73 -519
  68. package/prompts/discipline-normal.md +28 -136
  69. package/prompts/knowledge/batch-before-write.md +8 -0
  70. package/prompts/knowledge/batch-cycle-register.md +15 -0
  71. package/prompts/knowledge/batch-progress-ledger.md +29 -0
  72. package/prompts/knowledge/business-gates.md +24 -24
  73. package/prompts/knowledge/decision-quality.md +8 -19
  74. package/prompts/knowledge/doc-discipline-d-rules.md +63 -0
  75. package/prompts/knowledge/doc-lookup.md +25 -24
  76. package/prompts/knowledge/document-writing.md +11 -32
  77. package/prompts/knowledge/documentation-evaluation.md +42 -42
  78. package/prompts/knowledge/eng-dispatch-ops.md +34 -0
  79. package/prompts/knowledge/eng-ledger-ops.md +26 -0
  80. package/prompts/knowledge/evidence-discipline.md +10 -32
  81. package/prompts/knowledge/normal-batch-discipline.md +13 -0
  82. package/prompts/knowledge/normal-coding-workflow.md +97 -99
  83. package/prompts/knowledge/normal-delivery-collaboration.md +107 -112
  84. package/prompts/knowledge/normal-work-management.md +44 -44
  85. package/prompts/knowledge/product-security.md +7 -26
  86. package/prompts/knowledge/project-records.md +69 -64
  87. package/prompts/knowledge/tool-advisor.md +17 -17
  88. package/prompts/knowledge/tool-apply-patch.md +14 -14
  89. package/prompts/knowledge/tool-bash.md +32 -31
  90. package/prompts/knowledge/tool-batch-eng-coder.md +19 -13
  91. package/prompts/knowledge/tool-batch-eng-designer.md +21 -14
  92. package/prompts/knowledge/tool-batch-review.md +18 -12
  93. package/prompts/knowledge/tool-batch.md +93 -85
  94. package/prompts/knowledge/tool-browser.md +59 -59
  95. package/prompts/knowledge/tool-code-search.md +2 -2
  96. package/prompts/knowledge/tool-consult-start.md +6 -6
  97. package/prompts/knowledge/tool-consult-stop.md +3 -3
  98. package/prompts/knowledge/tool-context.md +4 -4
  99. package/prompts/knowledge/tool-delete.md +16 -16
  100. package/prompts/knowledge/tool-doc-check.md +39 -39
  101. package/prompts/knowledge/tool-doc-graph-read.md +11 -11
  102. package/prompts/knowledge/tool-doc-graph.md +48 -48
  103. package/prompts/knowledge/tool-doc-search.md +3 -3
  104. package/prompts/knowledge/tool-edit.md +30 -30
  105. package/prompts/knowledge/tool-eng.md +1 -1
  106. package/prompts/knowledge/tool-execute.md +16 -16
  107. package/prompts/knowledge/tool-fetch.md +15 -15
  108. package/prompts/knowledge/tool-file-ops.md +15 -15
  109. package/prompts/knowledge/tool-get-current-time.md +3 -3
  110. package/prompts/knowledge/tool-git-read.md +15 -15
  111. package/prompts/knowledge/tool-git.md +26 -26
  112. package/prompts/knowledge/tool-glob.md +14 -14
  113. package/prompts/knowledge/tool-goal.md +5 -5
  114. package/prompts/knowledge/tool-grep.md +19 -18
  115. package/prompts/knowledge/tool-hashline-edit.md +13 -13
  116. package/prompts/knowledge/tool-insert-after.md +14 -14
  117. package/prompts/knowledge/tool-instance-list.md +3 -3
  118. package/prompts/knowledge/tool-instance-send.md +5 -5
  119. package/prompts/knowledge/tool-knowledge.md +12 -12
  120. package/prompts/knowledge/tool-ledger-read.md +20 -20
  121. package/prompts/knowledge/tool-ledger.md +44 -44
  122. package/prompts/knowledge/tool-lint.md +10 -10
  123. package/prompts/knowledge/tool-ls.md +11 -11
  124. package/prompts/knowledge/tool-lsp.md +8 -8
  125. package/prompts/knowledge/tool-main-history.md +1 -1
  126. package/prompts/knowledge/tool-manifest-read.md +7 -7
  127. package/prompts/knowledge/tool-manifest.md +43 -32
  128. package/prompts/knowledge/tool-memory-read.md +12 -12
  129. package/prompts/knowledge/tool-memory.md +14 -14
  130. package/prompts/knowledge/tool-notify-parent.md +10 -10
  131. package/prompts/knowledge/tool-operations.md +88 -88
  132. package/prompts/knowledge/tool-peek.md +10 -0
  133. package/prompts/knowledge/tool-peer-instances.md +1 -1
  134. package/prompts/knowledge/tool-plan.md +6 -3
  135. package/prompts/knowledge/tool-process-read.md +8 -8
  136. package/prompts/knowledge/tool-process.md +11 -11
  137. package/prompts/knowledge/tool-question.md +11 -13
  138. package/prompts/knowledge/tool-read-history-batch.md +13 -13
  139. package/prompts/knowledge/tool-read-history.md +19 -19
  140. package/prompts/knowledge/tool-read-image.md +8 -8
  141. package/prompts/knowledge/tool-read.md +17 -17
  142. package/prompts/knowledge/tool-recent-changes.md +4 -4
  143. package/prompts/knowledge/tool-repo-outline.md +2 -2
  144. package/prompts/knowledge/tool-settings-read.md +5 -7
  145. package/prompts/knowledge/tool-settings.md +10 -10
  146. package/prompts/knowledge/tool-skill.md +4 -4
  147. package/prompts/knowledge/tool-ssh.md +66 -66
  148. package/prompts/knowledge/tool-step.md +26 -0
  149. package/prompts/knowledge/tool-subagent.md +52 -50
  150. package/prompts/knowledge/tool-task.md +14 -11
  151. package/prompts/knowledge/tool-team-ledger-read.md +7 -7
  152. package/prompts/knowledge/tool-team-ledger.md +13 -13
  153. package/prompts/knowledge/tool-timer.md +14 -14
  154. package/prompts/knowledge/tool-tree.md +11 -11
  155. package/prompts/knowledge/tool-verify.md +11 -11
  156. package/prompts/knowledge/tool-wait-for.md +20 -20
  157. package/prompts/knowledge/tool-websearch.md +16 -14
  158. package/prompts/knowledge/tool-write.md +10 -10
  159. package/prompts/knowledge/upstream-protocol.md +37 -38
  160. package/prompts/persona-coder.md +22 -22
  161. package/prompts/persona-eng-coder.md +87 -81
  162. package/prompts/persona-eng-designer.md +173 -153
  163. package/prompts/persona-engineering.md +53 -554
  164. package/prompts/persona-explore.md +18 -15
  165. package/prompts/persona-normal.md +62 -63
  166. package/prompts/persona-plan.md +36 -32
  167. package/prompts/persona-tester.md +39 -39
  168. package/prompts/planning-next-moves.md +9 -0
  169. package/prompts/subagent-base.md +4 -16
  170. package/provider/errors.mjs +0 -24
  171. package/provider/list-models.mjs +20 -2
  172. package/session-lifecycle.mjs +4 -3
  173. package/tool-args.mjs +25 -0
  174. package/tool-docs/peek.md +3 -0
  175. package/tool-docs/plan.md +1 -1
  176. package/tool-docs/question.md +1 -1
  177. package/tool-docs/step.md +3 -0
  178. package/tools/edit-diff.mjs +4 -4
  179. package/tools/index.mjs +3 -2
  180. package/tools/peek.mjs +447 -0
  181. package/tools/question.mjs +87 -9
  182. package/tools/ssh.mjs +1 -1
  183. package/window-policy.mjs +107 -80
@@ -13,8 +13,9 @@
13
13
  * - 保存面(用户裁定 A+B · 台账 #1602):⑩ 身份面(`identityFile` / `auth` 随 ⑨ 记录)∥ ⑪ 保存件读写 /
14
14
  * 解密 / `lastUsedAt` / fail-soft / 窗内勾选 ⇒ 单点 `agent-tools/ssh-vault.mjs`;⑫ `credentials` / `forget`。
15
15
  * - 生命周期:闲置 600 s 自动关(digest 注记)· `close` = stdin 结束 → 1.5 s 宽限 → 杀树 · 回合中断存活
16
- * (F2 豁免)· 会话中止逐条杀 + 清池(`agent-tools/async-discard.mjs` `SSH_SPEC`)· depth>0 排除
17
- * (`agent/helpers.mjs` `SUBAGENT_TOOL_EXCLUSIONS`)。
16
+ * (F2 豁免)· 会话中止逐条杀 + 清池(`agent-tools/async-discard.mjs` `SSH_SPEC`)· depth>0 **提供**
17
+ * (排除面只剩 `question`,`agent/helpers.mjs` `SUBAGENT_TOOL_EXCLUSIONS`):子代理自建池、结清时由
18
+ * `discardSshSessions` 排空——调用面四条路径五个点,见该导出。
18
19
  * 模块图:→ ssh-transport.mjs(运行面)· ssh-vault.mjs(保存件单点)· agent/helpers.mjs(轮转清理)·
19
20
  * tools/process-tree.mjs(树杀)· context.mjs(pushReal)· async-settle.mjs(池 ∥ 载体 ∥ 墓碑 ∥ 控制器链)·
20
21
  * subagent-scheduler.mjs(取号 ∥ 令牌 ∥ 入池守卫)——叶子向、无环。
@@ -115,6 +116,28 @@ function hardClose(entry, state, status) {
115
116
  finalize(entry, { state, status })
116
117
  }
117
118
 
119
+ /** 子代理结清:把该 agent **自己**的 ssh 池逐条硬关并清空。
120
+ * 子代理的池是懒建的、挂在自己身上(`sshPool`),父池不受影响;idle 600 s 只是保底,
121
+ * 退出即清才是真语义——不留一条父会话不知道、却还活着的远程连接。
122
+ * 取值走 `getAsyncPool(agent, "ssh")`(同档 `findEntry` / `listSsh` / `finalize` 三处同源),
123
+ * 不直读 `_sshSessions`:换一个只挂 `history` 的载体形态时,直读会静默返回 0 而会话照旧活着。
124
+ * 调用面 = 四条路径、五个点,成功与失败都清:
125
+ * ① `subagent-run.mjs` async spawn 的 `finally`(撞帽挂起除外)
126
+ * ② `subagent.mjs` 阻塞路 `finally`(sync 族无撞帽挂起)
127
+ * ③ `subagent-actions.mjs` 同步飞刀的收尾
128
+ * ④ `subagent-actions.mjs` 同步飞刀的 `catch`
129
+ * ⑤ `escalate-async.mjs` 异步飞刀 `flight().finally`(撞帽挂起除外) */
130
+ export function discardSshSessions(agent) {
131
+ const pool = getAsyncPool(agent, "ssh")
132
+ if (!(pool instanceof Map) || pool.size === 0) return 0
133
+ let closed = 0
134
+ for (const entry of [...pool.values()]) {
135
+ try { hardClose(entry, "closed", "discarded"); closed++ } catch { /* 尽力面 */ }
136
+ }
137
+ pool.clear()
138
+ return closed
139
+ }
140
+
118
141
  /** 闲置自动关闭(§6.22 ④):关闭 + 注记(注入面照异步结算先例)。 */
119
142
  function armIdle(entry) {
120
143
  clearIdle(entry)
@@ -204,7 +227,7 @@ function saveHostRecord(host, port, user, { identity = null, auth = null } = {})
204
227
  * @returns {{ text?: string, error?: string }}
205
228
  */
206
229
  export async function connectSsh(parent, ctx, { host, user, port, label, promptPattern, identityFile } = {}) {
207
- if (!parent) return { error: "no agent context — ssh sessions need a session-level pool (depth-0 only)" }
230
+ if (!parent) return { error: "no agent context — ssh sessions need a session-level pool" }
208
231
  if (typeof host !== "string" || !host.trim()) return { error: "connect requires host" }
209
232
  const pool = sshPool(parent)
210
233
  const live = [...pool.values()].filter((e) => e.state === "connecting" || e.state === "ready")
@@ -243,8 +266,9 @@ export async function connectSsh(parent, ctx, { host, user, port, label, promptP
243
266
  return { reason, waitedMs: Date.now() - t0 }
244
267
  }
245
268
  /** 起跑(探连 ∥ 带密会话同径;`-i` 两径同带——追加候选身份,不夺既有尝试序列)。
246
- * 每次起跑前清该轮缓冲:分类 / 沉降只看**本次连接**的输出(探连错误的残渣不得误判下一次尝试)。 */
269
+ * 每次起跑前先冲涮遮蔽尾缓冲再清该轮缓冲:分类 / 沉降只看**本次连接**的输出(探连或前次错误凭据的残渣不得误判下一次尝试)。 */
247
270
  const spawn = (sessionUser, secret) => {
271
+ entry.mask.flush()
248
272
  entry.buf = ""
249
273
  entry.bufDropped = false
250
274
  return spawnSession(entry, { user: sessionUser, port, secret, identityFile: identity, keepAliveMs: keepAliveMs() })
@@ -296,6 +320,9 @@ export async function connectSsh(parent, ctx, { host, user, port, label, promptP
296
320
  const stopped = out.state === "cancel" || out.state === "empty" || (out.phase === "probe" && (r.reason === "aborted" || r.reason === "timeout"))
297
321
  hardClose(entry, "closed", stopped ? "consumed" : "connect-failed")
298
322
  if (out.state === "cancel") {
323
+ if (out.attempts > 0) {
324
+ return { error: `ssh connect to ${entry.host} cancelled after ${out.attempts} rejected credential attempt(s)` }
325
+ }
299
326
  return { error: `ssh connect to ${entry.host} cancelled — no credential was provided (no connection was attempted with one)${out.failNote ? ` (${out.failNote}; the credential window was shown)` : ""}` }
300
327
  }
301
328
  if (out.state === "empty") return { error: "ssh connect cancelled — an empty password is never submitted (submit a password or cancel the window)" }
@@ -432,15 +459,19 @@ export { _setSshBinaryForTest, _setSshConfigDirForTest } from "./ssh-transport.m
432
459
  export { credentialsSsh, forgetSsh } from "./ssh-vault.mjs"
433
460
  // ─── 凭据判定单源(D-TO25:`connect` ∥ 传输面两处共用)─────────────────────────
434
461
 
462
+ /** 凭据窗认证失败时的最大尝试次数(含首次,对齐 OpenSSH 默认 3 次交互重试上限;用户随时可取消)。 */
463
+ export const SSH_CREDENTIAL_MAX_ATTEMPTS = 3
464
+
435
465
  /**
436
466
  * 凭据判定(§6.22 ⑩ / ⑪ + 裁定 A 预探路)——`connect` 与 `put` / `get` 两处共用的**顺序**:
437
- * 探连(密钥 ∥ agent)→ 密文库 → 凭据窗。保存件**恒不先于探连**(S6 / N6 / B7——密钥可用则零读取)。
467
+ * 探连(密钥 ∥ agent)→ 密文库 → 凭据窗(认证被拒时带失败提示与上次用户名预填重试,至多 `maxAttempts` 次)。
468
+ * 保存件**恒不先于探连**(S6 / N6 / B7——密钥可用则零读取)。
438
469
  * `attempt(secret, user)` = 调方的起跑 + 沉降 + 分类,回 `{ ok:true, … }` 或 `{ ok:false, auth, failure }`
439
- * (`auth` = 服务端拒绝认证 ⇒ 才继续往下一条来源;`failure` = 该来源失败的可读句)。
470
+ * (`auth` = 服务端拒绝认证 ⇒ 才继续往下一条来源或在凭据窗重试;`failure` = 该来源失败的可读句)。
440
471
  * @returns {Promise<{state:"ok", secret:string|null, user:string|null, source:"key"|"vault"|"window", r:Object, notes:string[]}
441
- * | {state:"fail", phase:"probe"|"vault"|"window", r:Object} | {state:"cancel"|"empty", failNote?:string}>}
472
+ * | {state:"fail", phase:"probe"|"vault"|"window", r:Object} | {state:"cancel"|"empty", failNote?:string, attempts?:number}>}
442
473
  */
443
- export async function resolveSessionSecret({ ctx, host, port, user, sessionId, offerSave = false, attempt }) {
474
+ export async function resolveSessionSecret({ ctx, host, port, user, sessionId, offerSave = false, maxAttempts = SSH_CREDENTIAL_MAX_ATTEMPTS, attempt }) {
444
475
  const notes = []
445
476
  let r = await attempt(null)
446
477
  if (r.ok) return { state: "ok", secret: null, user: user ?? null, source: "key", r, notes }
@@ -466,24 +497,36 @@ export async function resolveSessionSecret({ ctx, host, port, user, sessionId, o
466
497
  else if (got.state === "unavailable") failNote = "saved credentials are not available on this platform"
467
498
  // missing ⇒ 静默(正常首连态)
468
499
  }
469
- // 凭据窗(值只走回调返回路 + 子进程环境——NS4:零入参 ∥ 零入结果 ∥ 零落盘)。
470
- const input = await askCredential(ctx, { host, user, port, sessionId, offerSave })
471
- if (!input) return { state: "cancel", failNote }
472
- if (!String(input.password ?? "").length) return { state: "empty" }
473
- const asUser = input.user || user || null
474
- r = await attempt(input.password, asUser)
475
- if (!r.ok) return { state: "fail", phase: "window", r }
476
- // 认证成功后才写(opt-in——严格布尔;写失败不影响连接:增益面语义)
477
- if (input.save === true && asUser) {
478
- const saved = await saveEntry(host, port, { user: asUser, value: input.password })
479
- notes.push(saved.ok
480
- ? "the credential was saved for this host (encrypted with this Windows user account)"
481
- : "the credential could not be saved (the connection is unaffected)")
482
- } else if (input.save === true) {
483
- notes.push("the credential was not saved (no login user was given for this host)")
500
+ // 凭据窗(值只走回调返回路 + 子进程环境——NS4:零入参 ∥ 零入结果 ∥ 零落盘):
501
+ // 仅在服务端明确拒绝认证(`r.auth === true`)且未中止时重开凭据窗,保留用户上次填入的 `user` 预填并切重试提示词。
502
+ const limit = Math.max(1, Math.floor(Number(maxAttempts) || SSH_CREDENTIAL_MAX_ATTEMPTS))
503
+ let currentUser = user ?? null
504
+ for (let tries = 1; tries <= limit; tries++) {
505
+ const promptKey = tries === 1 ? "ssh.credentialPrompt" : "ssh.credentialRetryPrompt"
506
+ const input = await askCredential(ctx, { host, user: currentUser, port, sessionId, offerSave, promptKey })
507
+ if (!input) return { state: "cancel", failNote, attempts: tries - 1 }
508
+ if (!String(input.password ?? "").length) return { state: "empty" }
509
+ const asUser = input.user || currentUser || null
510
+ currentUser = asUser
511
+ r = await attempt(input.password, asUser)
512
+ if (r.ok) {
513
+ // 认证成功后才写(opt-in——严格布尔;写失败不影响连接:增益面语义)
514
+ if (input.save === true && asUser) {
515
+ const saved = await saveEntry(host, port, { user: asUser, value: input.password })
516
+ notes.push(saved.ok
517
+ ? "the credential was saved for this host (encrypted with this Windows user account)"
518
+ : "the credential could not be saved (the connection is unaffected)")
519
+ } else if (input.save === true) {
520
+ notes.push("the credential was not saved (no login user was given for this host)")
521
+ }
522
+ if (failNote) notes.unshift(`${failNote}; the credential window was shown`)
523
+ return { state: "ok", secret: input.password, user: asUser, source: "window", r, notes }
524
+ }
525
+ if (!r.auth || tries >= limit || ctx?.signal?.aborted) {
526
+ return { state: "fail", phase: "window", r }
527
+ }
484
528
  }
485
- if (failNote) notes.unshift(`${failNote}; the credential window was shown`)
486
- return { state: "ok", secret: input.password, user: asUser, source: "window", r, notes }
529
+ return { state: "fail", phase: "window", r }
487
530
  }
488
531
 
489
532
  /** 传输面取会话记录(§6.22 ⑬ ②:主机 / 用户 / 端口 / 身份面全取会话记录值——S10「不另填主机 / 凭据」)。
@@ -98,7 +98,7 @@ function runScp({ args, cwd, wrapper, secret, timeoutMs }) {
98
98
  child.stdout.on("data", (d) => { out += d })
99
99
  child.stderr.on("data", (d) => { err += d })
100
100
  child.on("error", (e) => finish({ spawnError: e?.message ?? String(e) }))
101
- child.on("exit", (code, signal) => finish({ code, signal }))
101
+ child.on("close", (code, signal) => finish({ code, signal }))
102
102
  })
103
103
  }
104
104
 
@@ -179,7 +179,12 @@ export async function transferSsh(parent, ctx, { action, id, localPath, remotePa
179
179
  ctx, host: session.host, port: session.port, user: session.user, sessionId: sid, offerSave: false, attempt,
180
180
  })
181
181
  if (out.state !== "ok") {
182
- if (out.state === "cancel") return { error: `Error: ssh transfer cancelled — no credential was provided (${label} @ ${session.host})` }
182
+ if (out.state === "cancel") {
183
+ if (out.attempts > 0) {
184
+ return { error: `Error: ssh transfer cancelled after ${out.attempts} rejected credential attempt(s) (${label} @ ${session.host})` }
185
+ }
186
+ return { error: `Error: ssh transfer cancelled — no credential was provided (${label} @ ${session.host})` }
187
+ }
183
188
  if (out.state === "empty") return { error: `Error: ssh transfer cancelled — an empty password is never submitted (${label} @ ${session.host})` }
184
189
  const r = out.r ?? {}
185
190
  if (r.reason === "timeout") {
@@ -175,7 +175,7 @@ export function attachChild(entry, child) {
175
175
  entry.spawnError = error?.message ?? String(error)
176
176
  for (const w of [...entry._waiters]) w("exit")
177
177
  })
178
- child.on("exit", (code, exitSignal) => {
178
+ child.on("close", (code, exitSignal) => {
179
179
  if (entry.child !== child) return // 旧进程(探连 → 带密会话的重起面)——事件不污染新连接判定
180
180
  entry.exitInfo = { code, signal: exitSignal }
181
181
  flush()
@@ -409,7 +409,7 @@ export function classifyFailure(stderr) {
409
409
  if (/REMOTE HOST IDENTIFICATION HAS CHANGED|Host key verification failed|host key .* revoked|requested strict checking/i.test(text)) {
410
410
  return { kind: "hostkey", message: "host key verification failed — the key changed or your local ssh config requires strict checking; known_hosts is never rewritten by this tool" }
411
411
  }
412
- if (/Permission denied|Too many authentication failures|Authentication failed/i.test(text)) {
412
+ if (/Permission denied|Too many authentication failures|Authentication failed|Access denied|Invalid password|Login incorrect/i.test(text)) {
413
413
  return { kind: "auth", message: "authentication rejected" }
414
414
  }
415
415
  if (/Connection timed out|Connection refused|No route to host|Could not resolve hostname|Connection closed by|Network is unreachable|connect to host .* failure/i.test(text)) {
@@ -228,7 +228,7 @@ export function touchEntry(host, port) {
228
228
  * 端侧回调自身拒绝(CLI `refuseSecretInput()` 形:抛可读句)⇒ 同族直出(`noUi` 标记 = 失败句不另加前缀)。
229
229
  * `offerSave` ⇒ `fields` += `save`(`checkbox: true`——缺省不勾(opt-in);提交值 = 布尔;核侧严格判 `=== true`)。
230
230
  * 拆档由 = 会话面超 500 顾问线(拆前 ≈513 行;设计 490 再拆线 ⇒ 按落点表候选拆分「凭据获取链迁入 `ssh-vault.mjs`」)。 */
231
- export async function askCredential(ctx, { host, user, port, sessionId, offerSave = false }) {
231
+ export async function askCredential(ctx, { host, user, port, sessionId, offerSave = false, promptKey = "ssh.credentialPrompt" }) {
232
232
  if (typeof ctx?.onSecretInput !== "function") {
233
233
  const err = new Error(t("ssh.no_ui"))
234
234
  err.noUi = true // 可读句直出(catch 面不另加前缀——失败句单源 = 核字典)
@@ -246,7 +246,7 @@ export async function askCredential(ctx, { host, user, port, sessionId, offerSav
246
246
  sessionId: sessionId != null ? `ssh#${sessionId}` : null,
247
247
  host, user: user ?? null, port: port ?? null,
248
248
  fields,
249
- keys: { title: "ssh.credentialTitle", prompt: "ssh.credentialPrompt" },
249
+ keys: { title: "ssh.credentialTitle", prompt: promptKey },
250
250
  })
251
251
  } catch (e) {
252
252
  // 端侧拒绝(无交互面 / 载荷成形外)⇒ 同族可读句直出(不裹「connect failed」前缀)。