dsh-plan-steps 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +10 -5
- package/index.js +25 -13
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -280,6 +280,13 @@ window.__ModuleLoader__.load({
|
|
|
280
280
|
const next = /the next step is (\d+) "([^"]*)"/.exec(text)
|
|
281
281
|
if (next === null) return null
|
|
282
282
|
const index = Number(next[1])
|
|
283
|
+
// Prefer the stated total: in a two-level list the current phase can sit
|
|
284
|
+
// before its own completed sub-steps, so "index - 1 + open" undercounts.
|
|
285
|
+
const stated = /\((\d+) open of (\d+)\)/.exec(text)
|
|
286
|
+
if (stated !== null) {
|
|
287
|
+
const openCount = Number(stated[1])
|
|
288
|
+
return { index, current: next[2], open: openCount, total: Number(stated[2]), done: false }
|
|
289
|
+
}
|
|
283
290
|
const open = /\((\d+) open\)/.exec(text)
|
|
284
291
|
const openCount = open === null ? 0 : Number(open[1])
|
|
285
292
|
return { index, current: next[2], open: openCount, total: index - 1 + openCount, done: false }
|
|
@@ -294,10 +301,9 @@ window.__ModuleLoader__.load({
|
|
|
294
301
|
if (position.done === true) {
|
|
295
302
|
return h('div', { style: { padding: '6px 2px', fontSize: '13px', fontWeight: 600 } }, '计划 · 全部完成')
|
|
296
303
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}))
|
|
304
|
+
// No bar here: one linear bar cannot show a two-level list truthfully — a
|
|
305
|
+
// phase can be current while completed sub-steps sit after it — so the row
|
|
306
|
+
// states the position and the panel, which knows every status, draws it.
|
|
301
307
|
return h(
|
|
302
308
|
'div',
|
|
303
309
|
{ style: { padding: '6px 2px', fontSize: '13px', display: 'flex', alignItems: 'center', gap: '10px' } },
|
|
@@ -307,7 +313,6 @@ window.__ModuleLoader__.load({
|
|
|
307
313
|
{ style: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
308
314
|
position.current,
|
|
309
315
|
),
|
|
310
|
-
h(Bar, { items, index: done + 1 }),
|
|
311
316
|
)
|
|
312
317
|
} catch (error) {
|
|
313
318
|
return h('div', { style: { padding: '6px 2px', fontSize: '12px', opacity: 0.7 } }, '完成一步')
|
package/index.js
CHANGED
|
@@ -30,6 +30,22 @@ export const inject = ['tools']
|
|
|
30
30
|
/** Marks a level-1 sub-step inside content, which every projection keeps. */
|
|
31
31
|
const SUB_STEP_MARK = ''
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Turn parsed items back into the snapshot payload, restoring the sub-step
|
|
35
|
+
* marker that `toItem` strips: every reader of the event, the panel included,
|
|
36
|
+
* only sees what the payload carries.
|
|
37
|
+
* @param items - the parsed list.
|
|
38
|
+
* @returns the payload for a `todo/write` append.
|
|
39
|
+
*/
|
|
40
|
+
function snapshotOf(items) {
|
|
41
|
+
return items.map((item) => ({
|
|
42
|
+
content: item.level === 1 ? SUB_STEP_MARK + item.content : item.content,
|
|
43
|
+
status: item.status,
|
|
44
|
+
...(item.level === 1 ? { level: 1 } : {}),
|
|
45
|
+
...(item.stepId === undefined ? {} : { step_id: item.stepId }),
|
|
46
|
+
}))
|
|
47
|
+
}
|
|
48
|
+
|
|
33
49
|
/** The shipped task list's snapshot event: one whole-list write per update. */
|
|
34
50
|
const TODO_WRITE = 'todo/write'
|
|
35
51
|
|
|
@@ -606,14 +622,7 @@ export function apply(ctx, config = {}) {
|
|
|
606
622
|
if (problem !== null) throw new Error(problem)
|
|
607
623
|
const continuity = continuityProblem(listOf(agent.session), items)
|
|
608
624
|
if (continuity !== null) throw new Error(continuity)
|
|
609
|
-
agent.session.append(TODO_WRITE, {
|
|
610
|
-
todos: items.map((item) => ({
|
|
611
|
-
content: item.level === 1 ? SUB_STEP_MARK + item.content : item.content,
|
|
612
|
-
status: item.status,
|
|
613
|
-
...(item.level === 1 ? { level: 1 } : {}),
|
|
614
|
-
...(item.stepId === undefined ? {} : { step_id: item.stepId }),
|
|
615
|
-
})),
|
|
616
|
-
})
|
|
625
|
+
agent.session.append(TODO_WRITE, { todos: snapshotOf(items) })
|
|
617
626
|
const done = items.filter((item) => item.status === 'completed').length
|
|
618
627
|
const active = items.filter((item) => item.status === 'in_progress').length
|
|
619
628
|
const pending = items.length - done - active
|
|
@@ -723,7 +732,7 @@ export function apply(ctx, config = {}) {
|
|
|
723
732
|
const advanced = advance(items, at)
|
|
724
733
|
// Persist the advance as the same snapshot the shipped tool writes, so
|
|
725
734
|
// the task panel and every log reader see the step close here and now.
|
|
726
|
-
agent.session.append(TODO_WRITE, { todos: advanced })
|
|
735
|
+
agent.session.append(TODO_WRITE, { todos: snapshotOf(advanced) })
|
|
727
736
|
const next = currentItem(advanced)
|
|
728
737
|
const remaining = advanced.filter((item) => item.status !== 'completed').length
|
|
729
738
|
const tail =
|
|
@@ -731,7 +740,10 @@ export function apply(ctx, config = {}) {
|
|
|
731
740
|
? 'Every step in the task list is now complete. Do not open new work under this plan.'
|
|
732
741
|
: `The host advanced the list; the next step is ${advanced.indexOf(next) + 1} ${JSON.stringify(next.content)}.`
|
|
733
742
|
return {
|
|
734
|
-
|
|
743
|
+
// The total is stated, not inferred: a two-level list can have a phase
|
|
744
|
+
// current *before* its completed sub-steps, so "index - 1 + open" is not
|
|
745
|
+
// the list length and a reader must not compute it.
|
|
746
|
+
message: `Step ${JSON.stringify(target.content)} done: ${said} ${tail} (${remaining} open of ${advanced.length})`,
|
|
735
747
|
}
|
|
736
748
|
},
|
|
737
749
|
presentCall: (args) => ({
|
|
@@ -907,7 +919,7 @@ export function apply(ctx, config = {}) {
|
|
|
907
919
|
if (restoreEnabled && restored !== payload.turn) {
|
|
908
920
|
restoredTurns.set(session, payload.turn)
|
|
909
921
|
try {
|
|
910
|
-
session.append(TODO_WRITE, { todos: items })
|
|
922
|
+
session.append(TODO_WRITE, { todos: snapshotOf(items) })
|
|
911
923
|
} catch {
|
|
912
924
|
// A read-only or closing session keeps its own behaviour.
|
|
913
925
|
}
|
|
@@ -939,7 +951,7 @@ export function apply(ctx, config = {}) {
|
|
|
939
951
|
if (items === null || items.length === 0) return
|
|
940
952
|
if (!items.some((item) => item.status !== 'completed')) return
|
|
941
953
|
try {
|
|
942
|
-
session.append(TODO_WRITE, { todos: items })
|
|
954
|
+
session.append(TODO_WRITE, { todos: snapshotOf(items) })
|
|
943
955
|
restoredTurns.set(session, turn)
|
|
944
956
|
} catch (error) {
|
|
945
957
|
// The pre-step restore still runs for this turn, so the panel is not
|
|
@@ -955,4 +967,4 @@ export function apply(ctx, config = {}) {
|
|
|
955
967
|
}
|
|
956
968
|
|
|
957
969
|
/** Pure helpers, exposed for the regression tests in test/. */
|
|
958
|
-
export const __testing = { normalize, locate, advance, replayCalls, renderTaskState, stepSeqOf, parseTodos, validateSerial, segmentsOf, firstUnfinishedSubStep, continuityProblem }
|
|
970
|
+
export const __testing = { normalize, locate, advance, replayCalls, renderTaskState, stepSeqOf, parseTodos, validateSerial, segmentsOf, firstUnfinishedSubStep, continuityProblem, snapshotOf, toItem }
|