@alpacachen/dsh-kanban 1.11.2 → 1.12.0

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/package.json CHANGED
@@ -1,18 +1,29 @@
1
1
  {
2
2
  "name": "@alpacachen/dsh-kanban",
3
- "version": "1.11.2",
4
- "description": "A collaborative kanban board for DeepSeek Harness with text search, native image attachments, due dates, comments and 19 agent tools.",
3
+ "version": "1.12.0",
4
+ "description": "Human-led Kanban and AI-run workflows for DeepSeek Harness, with native execution, human review and task artifacts.",
5
5
  "type": "module",
6
+ "engines": {
7
+ "dsh": "0.2.2-rc.3"
8
+ },
6
9
  "main": "index.js",
7
10
  "exports": {
8
11
  ".": "./index.js",
9
12
  "./client": "./lib/client.js",
13
+ "./workflow": "./workflow/index.js",
14
+ "./workflow/locale/*.json": "./workflow/locale/*.json",
15
+ "./workflow/icon": "./image.png",
10
16
  "./cordis.patch.yml": "./cordis.patch.yml",
11
17
  "./package.json": "./package.json"
12
18
  },
13
19
  "files": [
14
20
  "index.js",
15
21
  "search.js",
22
+ "workflow",
23
+ "docs/workflow-model.schema.sql",
24
+ "docs/workflow-validation.md",
25
+ "docs/workflow-guide.md",
26
+ "docs/workflow-guide.en.md",
16
27
  "lib/client.js",
17
28
  "cordis.patch.yml",
18
29
  "README.md",
@@ -22,7 +33,8 @@
22
33
  "docs/testing-images.md",
23
34
  "docs/guide.md",
24
35
  "docs/guide.zh.md",
25
- "docs/readme/*.png",
36
+ "docs/readme/board-*.png",
37
+ "docs/readme/*.svg",
26
38
  "LICENSE"
27
39
  ],
28
40
  "scripts": {
@@ -46,6 +58,7 @@
46
58
  "@radix-ui/react-separator": "^1.1.2",
47
59
  "@radix-ui/react-slot": "^1.1.2",
48
60
  "@radix-ui/react-tooltip": "^1.1.8",
61
+ "@xyflow/react": "^12.12.1",
49
62
  "clsx": "^2.1.1",
50
63
  "lucide-react": "^1.34.0"
51
64
  },
@@ -55,19 +68,21 @@
55
68
  },
56
69
  "devDependencies": {
57
70
  "@deepseek-ai/cordis": "~4.1.0",
58
- "@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.1",
59
- "@deepseek-ai/dsh-api-workspace-controller": "0.2.2-rc.1",
60
- "@deepseek-ai/dsh-client-locale": "0.2.2-rc.1",
61
- "@deepseek-ai/dsh-client-store": "0.2.2-rc.1",
62
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.1",
63
- "@deepseek-ai/dsh-client-ui-layout": "0.2.2-rc.1",
64
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.1",
65
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.1",
66
- "@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.1",
67
- "@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.1",
68
- "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.1",
69
- "@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.1",
70
- "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
71
+ "@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.3",
72
+ "@deepseek-ai/dsh-api-workspace-controller": "0.2.2-rc.3",
73
+ "@deepseek-ai/dsh-client-locale": "0.2.2-rc.3",
74
+ "@deepseek-ai/dsh-client-store": "0.2.2-rc.3",
75
+ "@deepseek-ai/dsh-client-ui-chat": "0.2.2-rc.3",
76
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.3",
77
+ "@deepseek-ai/dsh-client-ui-layout": "0.2.2-rc.3",
78
+ "@deepseek-ai/dsh-client-ui-model-selection": "0.2.2-rc.3",
79
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.3",
80
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.3",
81
+ "@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.3",
82
+ "@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.3",
83
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.3",
84
+ "@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.3",
85
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.3",
71
86
  "@testing-library/react": "^16.3.2",
72
87
  "@testing-library/user-event": "^14.6.5",
73
88
  "@types/node": "^26.6.5",
@@ -97,7 +112,10 @@
97
112
  "dsh",
98
113
  "dsh-plugin",
99
114
  "kanban",
100
- "plugin"
115
+ "plugin",
116
+ "workflow",
117
+ "ai-agent",
118
+ "human-in-the-loop"
101
119
  ],
102
120
  "dsh": {
103
121
  "bundle": {
@@ -115,15 +133,14 @@
115
133
  "@deepseek-ai/dsh-client-ui-primitives",
116
134
  "@deepseek-ai/dsh-client-ui-renderer",
117
135
  "@deepseek-ai/dsh-client-ui-session",
118
- "@deepseek-ai/dsh-client-ui-workspace"
136
+ "@deepseek-ai/dsh-client-ui-workspace",
137
+ "@deepseek-ai/dsh-client-store"
119
138
  ]
120
139
  },
121
140
  "compatibility": {
122
- "dsh": "0.2.0-rc.2 || 0.2.1-rc.3 || 0.2.2-rc.1",
141
+ "dsh": "0.2.2-rc.3",
123
142
  "dshReleases": {
124
- "0.2.0-rc.2": "compatible",
125
- "0.2.1-rc.3": "compatible",
126
- "0.2.2-rc.1": "compatible"
143
+ "0.2.2-rc.3": "compatible"
127
144
  },
128
145
  "profiles": [
129
146
  "web",
@@ -0,0 +1,206 @@
1
+ import { createHash, randomUUID } from 'node:crypto'
2
+
3
+ export const NATIVE_POLICY = 'dsh-native/v1'
4
+ const failure = (code, message) => Object.assign(new Error(message), { code })
5
+ const textInput = value => typeof value === 'string' && value.trim().length > 0
6
+
7
+ export class DshExecutionError extends Error {
8
+ constructor(code, message, evidence, cause) {
9
+ super(message, { cause })
10
+ this.name = 'DshExecutionError'
11
+ this.code = code
12
+ this.evidence = { ...evidence, completed: false }
13
+ }
14
+ }
15
+
16
+ // DSH owns tools, retries, compaction and authorization. Verify the stage receipt
17
+ // and terminal report without imposing a second tool-dispatch policy.
18
+ function resultFromLog(header, events, request) {
19
+ const refuse = () => { throw failure('WORKFLOW_LOG_UNKNOWN', 'The stage has no verified completed result.') }
20
+ if (header.id !== request.sessionId || (request.cwd && header.cwd !== request.cwd)
21
+ || !Array.isArray(events) || events.some((event, i) => event.seq !== i)) refuse()
22
+ const inputs = events.filter(event => event.type === 'user/message' && event.data.source?.rpcId === request.requestId)
23
+ if (inputs.length !== 1) refuse()
24
+ const input = inputs[0]
25
+ if ((request.messageId && input.data.id !== request.messageId)
26
+ || input.data.content?.length !== 1 || input.data.content[0].type !== 'text'
27
+ || (request.prompt !== undefined && input.data.content[0].text !== request.prompt)) refuse()
28
+ const start = events.findLast(event => event.type === 'turn/start' && event.seq < input.seq)
29
+ const end = events.find(event => event.type === 'turn/end' && event.data.turn === start?.data.turn && event.seq > input.seq)
30
+ if (!start || !end) refuse()
31
+ const reason = end.data.reason
32
+ if (reason?.kind === 'error') throw failure(reason.error?.code === 'TRANSPORT' ? 'WORKFLOW_NETWORK_FAILED' : 'WORKFLOW_MODEL_FAILED', 'Native model execution failed.')
33
+ if (reason?.kind === 'interrupted') throw failure('WORKFLOW_MODEL_INTERRUPTED', 'Native model execution was interrupted.')
34
+ if (reason?.kind === 'max-tokens') throw failure('WORKFLOW_MODEL_INCOMPLETE', 'Native model output is incomplete.')
35
+ if (reason?.kind !== 'completed') refuse()
36
+ const reply = events.findLast(event => event.type === 'assistant/message' && event.data.turn === start.data.turn
37
+ && event.seq > input.seq && event.seq < end.seq)
38
+ if (!reply || reply.data.interrupted || reply.data.message?.content?.some(block => block.type === 'tool-call')) refuse()
39
+ const text = reply.data.message.content.filter(block => block.type === 'text').map(block => block.text).join('\n')
40
+ if (!textInput(text)) refuse()
41
+ return { text, sessionId: header.id, messageId: input.data.id, turnNumber: start.data.turn,
42
+ evidence: { policy: NATIVE_POLICY, userSeq: input.seq, assistantSeq: reply.seq, endSeq: end.seq,
43
+ endReason: 'completed', toolInvocationCount: events.filter(event => event.type === 'tool/call' && event.seq > input.seq && event.seq < end.seq).length,
44
+ outputSha256: createHash('sha256').update(text).digest('hex') } }
45
+ }
46
+
47
+ export async function readPersistedSession(persistence, sessionId, signal) {
48
+ const handle = await persistence.open(sessionId, 'read', { signal })
49
+ try { return { header: handle.header, events: (await handle.read(0, undefined, { signal })).events } }
50
+ finally { await handle.close() }
51
+ }
52
+
53
+ /** Reconcile under native Session ownership, without dispatching or cancelling later chat turns. */
54
+ export async function withStoppedNativeExecution(ctx, attempt, commit, { confirmedStopped = false } = {}) {
55
+ const agents = ctx.get('agents'), sessions = ctx.get('sessions'), persistence = ctx.get('sessionPersistence'), jobs = ctx.get('jobs')
56
+ const busy = () => { throw failure('WF_RECOVERY_RUNNING', '执行会话或关联作业仍在工作,请先停止该会话,再重新核对任务。') }
57
+ const assertNoJobs = () => {
58
+ if (jobs.list(attempt.sessionId).some(job => job.owner === attempt.sessionId && ['running', 'stopping'].includes(job.status))) busy()
59
+ }
60
+ const settle = async (handle, ownership, signal) => {
61
+ signal?.throwIfAborted(); assertNoJobs()
62
+ const { events } = await handle.read(0, undefined, { signal })
63
+ if (handle.header.id !== attempt.sessionId || attempt.executorSnapshot.cwd && handle.header.cwd !== attempt.executorSnapshot.cwd
64
+ || !Array.isArray(events) || events.some((event, index) => event.seq !== index)) throw failure('WF_RECOVERY_UNCONFIRMED', '执行会话记录不完整或与任务不匹配,未释放执行位置。')
65
+ const inputs = events.filter(event => event.type === 'user/message' && event.data.source?.rpcId === attempt.requestId)
66
+ const input = inputs[0]
67
+ const start = input && events.findLast(event => event.type === 'turn/start' && event.seq < input.seq)
68
+ if (inputs.length > 1 || input && (!start || attempt.messageId && input.data.id !== attempt.messageId
69
+ || attempt.turnNumber != null && start.data.turn !== attempt.turnNumber
70
+ || input.data.content?.length !== 1 || input.data.content[0].type !== 'text' || input.data.content[0].text !== attempt.prompt)
71
+ || !input && events.some(event => event.type === 'user/message')) throw failure('WF_RECOVERY_UNCONFIRMED', '无法关联这次阶段的原始输入,未释放执行位置。')
72
+ const end = start && events.find(event => event.type === 'turn/end' && event.seq > input.seq && event.data.turn === start.data.turn)
73
+ // A cold Session lock cannot prove that commands survived neither SIGKILL nor a crash.
74
+ if (ownership === 'exclusive-session' && (attempt.state === 'unknown' || input && !end) && !confirmedStopped) {
75
+ throw failure('WF_RECOVERY_CONFIRM_REQUIRED', '原 DSH 已退出,但旧命令可能仍在运行。请先核对并确认旧操作已停止,再恢复或结束任务。')
76
+ }
77
+ signal?.throwIfAborted(); assertNoJobs()
78
+ return commit({ kind: 'dsh-native-stop', attemptId: attempt.id, sessionId: attempt.sessionId, requestId: attempt.requestId,
79
+ messageId: input?.data.id ?? attempt.messageId ?? null, turnNumber: start?.data.turn ?? attempt.turnNumber ?? null, userSeq: input?.seq ?? null, endSeq: end?.seq ?? null,
80
+ endReason: end?.data.reason?.kind ?? 'owner_released', ownership, operatorConfirmedStopped: confirmedStopped, logLastSeq: events.at(-1)?.seq ?? -1, quiescent: true, ownedJobCount: 0 })
81
+ }
82
+ const agent = agents.get(attempt.sessionId)
83
+ if (agent) {
84
+ if (agent.phase.kind !== 'idle') busy()
85
+ return agent.runMaintenance(async signal => {
86
+ assertNoJobs()
87
+ if (!await sessions.flush(agent.session)) throw failure('WF_RECOVERY_UNCONFIRMED', '执行会话暂时无法保存,请稍后重新核对。')
88
+ const handle = await persistence.open(attempt.sessionId, 'read', { signal })
89
+ try { return await settle(handle, 'live-idle', signal) } finally { await handle.close() }
90
+ })
91
+ }
92
+ let handle
93
+ if (!await persistence.stat(attempt.sessionId) && attempt.messageId == null && attempt.turnNumber == null) {
94
+ if (agents.get(attempt.sessionId)) busy()
95
+ assertNoJobs()
96
+ return commit({ kind: 'dsh-native-stop', attemptId: attempt.id, sessionId: attempt.sessionId, requestId: attempt.requestId,
97
+ messageId: null, turnNumber: null, userSeq: null, endSeq: null, endReason: 'not_dispatched', ownership: 'session-absent',
98
+ logLastSeq: -1, quiescent: true, ownedJobCount: 0 })
99
+ }
100
+ try { handle = await persistence.open(attempt.sessionId, 'write') }
101
+ catch { throw failure('WF_RECOVERY_UNCONFIRMED', '暂时无法取得原执行会话的独占所有权,请稍后重新核对。') }
102
+ try {
103
+ if (agents.get(attempt.sessionId)) busy()
104
+ return await settle(handle, 'exclusive-session')
105
+ } finally { await handle.close() }
106
+ }
107
+
108
+ export function createDshExecutor(ownerCtx, { modelSelection, installModelSelection } = {}) {
109
+ const required = (name, methods) => {
110
+ const service = ownerCtx.get(name)
111
+ if (!service || methods.some(method => typeof service[method] !== 'function')) {
112
+ throw failure('WORKFLOW_CONTRACT_UNAVAILABLE', `Required DSH capability is unavailable: ${name}`)
113
+ }
114
+ return service
115
+ }
116
+ const agents = required('agents', ['create', 'get', 'withoutInitiator'])
117
+ const sessions = required('sessions', ['get', 'flush'])
118
+ const persistence = required('sessionPersistence', ['stat', 'open'])
119
+ const presets = required('agentPresets', ['resolve', 'mount'])
120
+ const jobs = required('jobs', ['list'])
121
+ const active = new Map(), submitted = new Set()
122
+ let closed = false
123
+ const runningJobs = sessionId => jobs.list(sessionId).filter(job => job.owner === sessionId && ['running', 'stopping'].includes(job.status))
124
+ const readRaw = (sessionId, signal) => readPersistedSession(persistence, sessionId, signal)
125
+ const cancel = attemptId => {
126
+ const record = active.get(attemptId)
127
+ if (!record) return { requested: false }
128
+ record.cancelled = true
129
+ record.abort.abort()
130
+ record.handle?.agent.cancel({ kind: 'user' }, { keepInbox: false })
131
+ return { requested: true }
132
+ }
133
+ async function run({ attemptId, sessionId, requestId, prompt, cwd, modelSelection: taskModelSelection, onBound, onObserved, signal }) {
134
+ if (![attemptId, sessionId, requestId, prompt, cwd].every(textInput)) throw new TypeError('Stage identities, prompt and working directory are required')
135
+ const evidence = { kind: 'dsh-session-log', policy: NATIVE_POLICY, attemptId, sessionId, requestId,
136
+ messageId: null, turnNumber: null, completed: false, flushConfirmed: false, quiescent: false, ownedJobCount: 0, toolInvocationCount: 0 }
137
+ if (closed || submitted.has(attemptId) || submitted.has(sessionId)) throw new DshExecutionError('WORKFLOW_REUSE_FORBIDDEN', 'Stage execution already submitted or executor closed', evidence)
138
+ submitted.add(attemptId); submitted.add(sessionId)
139
+ const record = { abort: new AbortController(), cancelled: false, handle: null }
140
+ record.done = new Promise(resolve => { record.finish = resolve })
141
+ active.set(attemptId, record)
142
+ const abort = () => cancel(attemptId)
143
+ signal?.addEventListener('abort', abort, { once: true })
144
+ if (signal?.aborted) abort()
145
+ let issue, result, created = false
146
+ const message = { id: randomUUID(), role: 'user', content: [{ type: 'text', text: prompt }], source: { kind: 'user', rpcId: requestId } }
147
+ evidence.messageId = message.id
148
+ try {
149
+ record.abort.signal.throwIfAborted()
150
+ if (agents.get(sessionId) || sessions.get(sessionId) || await persistence.stat(sessionId)) throw failure('WORKFLOW_REUSE_FORBIDDEN', 'Existing session cannot be dispatched again')
151
+ const preset = await presets.resolve()
152
+ const selection = structuredClone(taskModelSelection ?? modelSelection ?? required('agentDefaultModel', ['currentSelection']).currentSelection())
153
+ record.handle = await agents.withoutInitiator(() => agents.create({ sessionId, meta: { cwd, agentPreset: preset.id },
154
+ agentOptions: selection, signal: record.abort.signal,
155
+ setup: async agentCtx => {
156
+ installModelSelection?.(agentCtx)
157
+ await presets.mount(agentCtx, preset.id)
158
+ } }))
159
+ created = true
160
+ const agent = record.handle.agent
161
+ if (!await sessions.flush(agent.session)) throw failure('WORKFLOW_FLUSH_UNAVAILABLE', 'Session persistence is unavailable')
162
+ await onBound?.({ attemptId, sessionId, requestId, messageId: message.id })
163
+ const remove = agent.ctx.on('session/event', (session, event) => {
164
+ if (session !== agent.session || event.type !== 'turn/start') return
165
+ evidence.turnNumber = event.data.turn
166
+ })
167
+ try {
168
+ record.abort.signal.throwIfAborted()
169
+ agent.followup(message)
170
+ await agent.whenIdle()
171
+ } finally { remove?.() }
172
+ if (record.cancelled) throw failure('WORKFLOW_CANCELLED', 'Stage cancelled')
173
+ await onObserved?.({ attemptId, sessionId, requestId, messageId: message.id, turnNumber: evidence.turnNumber })
174
+ evidence.flushConfirmed = await sessions.flush(agent.session)
175
+ if (!evidence.flushConfirmed) throw failure('WORKFLOW_FLUSH_UNAVAILABLE', 'Session persistence is unavailable')
176
+ const raw = await readRaw(sessionId)
177
+ result = resultFromLog(raw.header, raw.events, { sessionId, requestId, messageId: message.id, prompt, cwd })
178
+ Object.assign(evidence, result.evidence)
179
+ } catch (error) { issue = error }
180
+ finally {
181
+ try {
182
+ if (record.handle) await record.handle.dispose()
183
+ evidence.ownedJobCount = runningJobs(sessionId).length
184
+ evidence.quiescent = !agents.get(sessionId) && evidence.ownedJobCount === 0
185
+ if (!created && issue?.code === 'WORKFLOW_REUSE_FORBIDDEN') evidence.quiescent = false
186
+ } catch (error) { issue ??= error; evidence.quiescent = false }
187
+ signal?.removeEventListener('abort', abort)
188
+ active.delete(attemptId)
189
+ record.finish()
190
+ }
191
+ if (record.cancelled) issue = failure('WORKFLOW_CANCELLED', 'Stage cancelled')
192
+ if (issue || !result || !evidence.quiescent) throw new DshExecutionError(issue?.code ?? 'WORKFLOW_EXECUTION_UNKNOWN', issue?.message ?? 'Stage execution is not complete', evidence, issue)
193
+ evidence.completed = true
194
+ return { ...result, evidence }
195
+ }
196
+ return { run, cancel,
197
+ async inspectReadonly(request) {
198
+ const evidence = { kind: 'dsh-session-log', ...request, completed: false, quiescent: false, flushConfirmed: false }
199
+ if (!await persistence.stat(request.sessionId, { signal: request.signal })) return { status: 'missing', evidence }
200
+ const raw = await readRaw(request.sessionId, request.signal)
201
+ try { return { status: 'completed-evidence', ...resultFromLog(raw.header, raw.events, request) } }
202
+ catch (error) { return { status: 'unknown', code: error.code, evidence } }
203
+ },
204
+ async dispose() { closed = true; const records = [...active.entries()]; for (const [id] of records) cancel(id); await Promise.all(records.map(([, record]) => record.done)) },
205
+ }
206
+ }