dsh-workplan 2.1.3 → 2.2.6

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 (38) hide show
  1. package/CHANGELOG.md +380 -1
  2. package/README.en.md +5 -2
  3. package/README.md +5 -2
  4. package/README.zh.md +5 -2
  5. package/client.js +143 -3
  6. package/docs/dsh-workplan_T4_runtime.patch +508 -0
  7. package/docs/release-records/_release_notes_2.1.2_20261106.md +44 -0
  8. package/docs/release-records/_t2_version_determination_20261106.md +39 -0
  9. package/docs/release-records/_t5_external_reverify_20261106.md +18 -0
  10. package/docs/release-records/release-dryrun-report-20261106.md +74 -0
  11. package/docs/release-records/release-notes-2.2.6-T3.md +128 -0
  12. package/docs/release-records/release-record-2.1.3-20261106.md +82 -0
  13. package/docs/release-records/release-steps-20261106.md +129 -0
  14. package/docs/release-records/version-freeze-20261109-T2.md +37 -0
  15. package/lib/client.js +143 -3
  16. package/lib/comm-format.js +17 -0
  17. package/lib/departments.js +19 -0
  18. package/lib/host.js +95 -17
  19. package/lib/notice-channel.js +290 -0
  20. package/lib/plan.js +541 -32
  21. package/lib/replan.js +4 -0
  22. package/lib/runtime.js +1481 -85
  23. package/lib/supersede.js +2 -2
  24. package/lib/understanding.js +8 -2
  25. package/lib/watchdog.js +52 -1
  26. package/package.json +3 -2
  27. package/scripts/repair-malformed-user-messages.mjs +312 -0
  28. package/src/client.ts +150 -2
  29. package/src/comm-format.ts +17 -0
  30. package/src/departments.ts +22 -0
  31. package/src/host.ts +90 -12
  32. package/src/notice-channel.ts +328 -0
  33. package/src/plan.ts +575 -24
  34. package/src/replan.ts +4 -0
  35. package/src/runtime.ts +1500 -86
  36. package/src/supersede.ts +2 -1
  37. package/src/understanding.ts +10 -2
  38. package/src/watchdog.ts +80 -1
package/src/supersede.ts CHANGED
@@ -27,6 +27,7 @@
27
27
  * 防线。
28
28
  */
29
29
  import {
30
+ appendUserMessage,
30
31
  buildCancelMessage,
31
32
  derivePlanSnapshot,
32
33
  flattenSubtasks,
@@ -383,7 +384,7 @@ export function supersedePlanRecord(session: any, record: any, args: any, deps:
383
384
  return deny(SUPERSEDE_CODES.WRITE_FAILED, `构造取代记录失败:${error?.message ?? String(error)}`)
384
385
  }
385
386
  try {
386
- session.append('user/message', message, { surfaceOp: 'append' })
387
+ appendUserMessage(session, message)
387
388
  } catch (error: any) {
388
389
  record.errors = [...(Array.isArray(record?.errors) ? record.errors : []),
389
390
  `写入取代记录失败:${error instanceof Error ? error.message : String(error)}`].slice(-20)
@@ -1247,10 +1247,18 @@ export function auditTaskUnderstanding(plan: any, context: PlanAuditContext = {}
1247
1247
  const found = fromConversation ?? resolvePronounAntecedentInline(reference.token, taskText)
1248
1248
  if (!found) return reference
1249
1249
  // Option letters are resolved only when the conversation lists that option
1250
- // as a listed choice ("A 方案" / "B 选项"), not a bare letter in a word.
1250
+ // as a listed choice, not a bare letter in a word. Listed-choice markers:
1251
+ // "C 方案" / "C 选项" and the enumeration forms "C=…" / "C=…" / "C:…" /
1252
+ // "C、…" / "C)…" / "C)…" / "C.…" / "C.…" (marker must be followed by
1253
+ // content). Q10-style reports enumerate options as "A=… / B=… / C=…";
1254
+ // [2.2.6] the old regex only accepted 方案/选项, so a plain "选C" was
1255
+ // falsely judged unresolvable, burned two full planner attempts (~12 min
1256
+ // of silent planning in session-a404d49d) and degraded a legitimate task.
1251
1257
  // Task-text entities never satisfy this rule on their own: the option must
1252
1258
  // be defined where the user chose it, i.e. in the conversation.
1253
- const listedOption = new RegExp('(?:^|[^A-Za-z])' + reference.token + '\\s*(?:方案|选项)')
1259
+ const listedOption = new RegExp(
1260
+ '(?:^|[^A-Za-z])' + reference.token + '\\s*(?:方案|选项|=|=|:|:|、|\\)|)|\\.|.)\\s*\\S',
1261
+ )
1254
1262
  if (/^[A-D]$/.test(reference.token) && !listedOption.test(conversation)) return reference
1255
1263
  /*
1256
1264
  * [T3] Record where the referent came from. Reusing 'context' for an
package/src/watchdog.ts CHANGED
@@ -94,6 +94,28 @@ export function describeError(value: unknown): string {
94
94
  return String(value)
95
95
  }
96
96
 
97
+ /**
98
+ * Warning window floor: two minutes. The approaching-deadline window is
99
+ * `max(timeoutMs × 0.2, WARN_FLOOR_MS)` (O-4b, design doc §2.3/§2.6 #9).
100
+ */
101
+ const WARN_FLOOR_MS = 120_000
102
+
103
+ /**
104
+ * What `onApproachingDeadline` reports once per armed warning cycle (O-4b).
105
+ *
106
+ * The warning is a signal, never a gate (design doc §5.3「预警是提示,不是拦截」):
107
+ * this module cannot extend anything on its own, and the payload only reports
108
+ * facts so the caller can decide whether to grant `extendMs`.
109
+ */
110
+ export interface ApproachingDeadlineInfo {
111
+ /** Which subtask is nearing its ceiling (optional `subtaskId` input; '' when absent). */
112
+ subtaskId: string
113
+ /** Milliseconds left before the current ceiling fires. */
114
+ remainingMs: number
115
+ /** The ceiling currently in force, ms measured from the attempt start. */
116
+ timeoutMs: number
117
+ }
118
+
97
119
  /** One live progress watchdog around a single child execution. */
98
120
  export interface ProgressWatchdog {
99
121
  /** Rejects once with the PlanError built by `makeError`; never resolves. */
@@ -104,6 +126,17 @@ export interface ProgressWatchdog {
104
126
  lastProgressAt(): number
105
127
  /** How many times the observed session log grew. */
106
128
  progressEvents(): number
129
+ /**
130
+ * Push the absolute ceiling (ms from the attempt start) to `newHardMs` and
131
+ * re-arm the one-shot approaching-deadline warning (O-4d). The watchdog never
132
+ * moves the ceiling by itself — only an explicit call here does.
133
+ */
134
+ extend(newHardMs: number): void
135
+ /**
136
+ * Alias of `extend` under the T4/T5 parallel-construction contract name:
137
+ * identical semantics and implementation — new ceiling plus warning re-arm.
138
+ */
139
+ rearmApproachingDeadline(newTimeoutMs: number): void
107
140
  }
108
141
 
109
142
  /**
@@ -115,6 +148,9 @@ export interface ProgressWatchdog {
115
148
  * @param input.pollMs - observation period.
116
149
  * @param input.makeError - builds the rejection for the decided reason.
117
150
  * @param input.onProgress - called after each observed log growth.
151
+ * @param input.onApproachingDeadline - called once per armed cycle when the
152
+ * remaining time enters `max(timeoutMs × 0.2, WARN_FLOOR_MS)` before the ceiling (O-4b).
153
+ * @param input.subtaskId - reported back inside `onApproachingDeadline` info (optional).
118
154
  * @param input.now - clock, injectable for tests.
119
155
  * @returns a watchdog handle.
120
156
  */
@@ -125,6 +161,8 @@ export function createProgressWatchdog(input: {
125
161
  makeError: (reason: Exclude<TimeoutReason, null>) => Error
126
162
  pollMs?: number
127
163
  onProgress?: (info: { now: number; seq: number; elapsedMs: number }) => void
164
+ onApproachingDeadline?: (info: ApproachingDeadlineInfo) => void
165
+ subtaskId?: string
128
166
  now?: () => number
129
167
  }): ProgressWatchdog {
130
168
  const clock = input.now ?? (() => Date.now())
@@ -134,6 +172,12 @@ export function createProgressWatchdog(input: {
134
172
  let lastSeq: number | null = null
135
173
  let growth = 0
136
174
  let settled = false
175
+ // [2.2.0][O-4b/O-4d] Absolute ceiling (ms from `startedAt`) currently in
176
+ // force. Only `rearm` below moves it — the warning itself never extends
177
+ // anything, so an un-extended ceiling still settles as `exhausted`.
178
+ let hardMs = Math.max(1, Math.floor(input.hardMs))
179
+ // [2.2.0][O-4b] One-shot warning latch per armed cycle; cleared by `rearm`.
180
+ let warned = false
137
181
  let timer: ReturnType<typeof setInterval> | null = null
138
182
  let rejectOnce: (error: Error) => void = () => {}
139
183
 
@@ -154,6 +198,34 @@ export function createProgressWatchdog(input: {
154
198
  rejectOnce(input.makeError(reason))
155
199
  }
156
200
 
201
+ // [2.2.0][O-4d] 推移绝对上限(自尝试起点计)并重新武装一次性预警。
202
+ // 看门狗自身没有延期能力:只有调用方显式调用才会动上限
203
+ // (design doc §5.3「预警是提示,不是拦截」)。
204
+ const rearm = (newTimeoutMs: number) => {
205
+ if (settled || !Number.isFinite(newTimeoutMs)) return
206
+ hardMs = Math.max(1, Math.floor(newTimeoutMs))
207
+ warned = false
208
+ }
209
+
210
+ // [2.2.0][O-4b] 即将超时预警:剩余 ≤ max(timeoutMs × 0.2, WARN_FLOOR_MS)
211
+ // (取大者)且到点之前(remainingMs > 0,D1「到点之前到达」)时触发一次;
212
+ // 同一武装周期内幂等(warned 闩锁),rearm 后按新时限重新武装。
213
+ const warnApproachingDeadline = (now: number) => {
214
+ if (warned || !input.onApproachingDeadline) return
215
+ const remainingMs = hardMs - (now - startedAt)
216
+ if (remainingMs <= 0 || remainingMs > Math.max(hardMs * 0.2, WARN_FLOOR_MS)) return
217
+ warned = true
218
+ try {
219
+ input.onApproachingDeadline({
220
+ subtaskId: input.subtaskId ?? '',
221
+ remainingMs,
222
+ timeoutMs: hardMs,
223
+ })
224
+ } catch {
225
+ // An observer must never break the watchdog.
226
+ }
227
+ }
228
+
157
229
  const poll = () => {
158
230
  if (settled) return
159
231
  const now = clock()
@@ -177,12 +249,13 @@ export function createProgressWatchdog(input: {
177
249
  }
178
250
  }
179
251
  }
252
+ warnApproachingDeadline(now)
180
253
  const reason = pickTimeoutReason({
181
254
  now,
182
255
  startedAt,
183
256
  lastProgressAt: lastProgress,
184
257
  idleMs: Math.max(1, Math.floor(input.idleMs)),
185
- hardMs: Math.max(1, Math.floor(input.hardMs)),
258
+ hardMs,
186
259
  progressObservable: lastSeq !== null,
187
260
  })
188
261
  if (reason) finish(reason)
@@ -203,5 +276,11 @@ export function createProgressWatchdog(input: {
203
276
  },
204
277
  lastProgressAt: () => lastProgress,
205
278
  progressEvents: () => growth,
279
+ extend: (newHardMs: number) => {
280
+ rearm(newHardMs)
281
+ },
282
+ rearmApproachingDeadline: (newTimeoutMs: number) => {
283
+ rearm(newTimeoutMs)
284
+ },
206
285
  }
207
286
  }