dsh-work-fish 0.0.0-stage → 0.1.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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -2
  3. package/THIRD-PARTY-NOTICES.md +61 -0
  4. package/board/client.js +1048 -0
  5. package/cordis.patch.yml +173 -0
  6. package/core/approve-paths.mjs +387 -0
  7. package/core/approve-paths.test.mjs +241 -0
  8. package/core/approve.mjs +182 -0
  9. package/core/bootstrap.mjs +186 -0
  10. package/core/events.mjs +80 -0
  11. package/core/guard.mjs +155 -0
  12. package/core/index.mjs +630 -0
  13. package/core/parse.mjs +310 -0
  14. package/core/persona.mjs +98 -0
  15. package/core/pet-bridge.mjs +439 -0
  16. package/core/report.mjs +370 -0
  17. package/core/skills.mjs +111 -0
  18. package/docs/DETAIL.md +1 -0
  19. package/docs/DETAIL.zh.md +1 -0
  20. package/docs/preview.webp +0 -0
  21. package/icon.png +0 -0
  22. package/locale/en.json +7 -0
  23. package/locale/zh.json +7 -0
  24. package/package.json +69 -4
  25. package/rules/code-rules.md +92 -0
  26. package/rules/experience-pool.md +59 -0
  27. package/rules/file-rules.md +134 -0
  28. package/rules/memory-rules.md +91 -0
  29. package/rules/task-rules.md +71 -0
  30. package/skills/code-review/LICENSE +202 -0
  31. package/skills/code-review/NOTICE.md +75 -0
  32. package/skills/code-review/SKILL.md +155 -0
  33. package/skills/code-review/upstream/README.md +258 -0
  34. package/skills/code-review/upstream/code-review.command.md +110 -0
  35. package/skills/code-review/upstream/plugin.json +10 -0
  36. package/skills/code-simplifier/LICENSE +202 -0
  37. package/skills/code-simplifier/NOTICE.md +72 -0
  38. package/skills/code-simplifier/SKILL.md +126 -0
  39. package/skills/code-simplifier/agents/code-simplifier.md +52 -0
  40. package/skills/code-simplifier/upstream/plugin.json +9 -0
  41. package/skills/comfyui-h3/SKILL.md +455 -0
  42. package/skills/comfyui-h3/reference/failures.md +84 -0
  43. package/skills/comfyui-h3/reference/serial-production.md +173 -0
  44. package/skills/delete-gate/SKILL.md +48 -0
  45. package/skills/doc-writing/SKILL.md +152 -0
  46. package/skills/doc-writing/reference/skeletons.md +81 -0
  47. package/skills/feature-dev/LICENSE +202 -0
  48. package/skills/feature-dev/NOTICE.md +67 -0
  49. package/skills/feature-dev/SKILL.md +181 -0
  50. package/skills/feature-dev/agents/code-architect.md +34 -0
  51. package/skills/feature-dev/agents/code-explorer.md +51 -0
  52. package/skills/feature-dev/agents/code-reviewer.md +46 -0
  53. package/skills/feature-dev/upstream/README.md +412 -0
  54. package/skills/feature-dev/upstream/feature-dev.command.md +125 -0
  55. package/skills/feature-dev/upstream/plugin.json +9 -0
  56. package/skills/frontend-design/LICENSE.txt +177 -0
  57. package/skills/frontend-design/SKILL.md +71 -0
  58. package/skills/git-flow/SKILL.md +80 -0
  59. package/skills/plan-revision/SKILL.md +54 -0
  60. package/skills/task-setup/SKILL.md +124 -0
  61. package/template/AGENTS.template.md +28 -0
  62. package/template/memory/pool/experience.md +9 -0
  63. package/template/memory/preferences.md +17 -0
  64. package/template/memory/projects/README.md +6 -0
  65. package/template/memory/user-profile.md +33 -0
  66. package/template/persona-core.md +32 -0
  67. package/template/persona-user.md +0 -0
  68. package/template/rules/user-rules.md +20 -0
  69. package/template/rules-index.md +50 -0
  70. package/template/tasks/index.md +34 -0
  71. package/tools/lib/paths.mjs +31 -0
  72. package/tools/lib/persona.mjs +454 -0
  73. package/tools/lib/taskboard.mjs +713 -0
  74. package/tools/wf-audit.cmd +3 -0
  75. package/tools/wf-audit.ps1 +242 -0
  76. package/tools/wf-mem.mjs +336 -0
  77. package/tools/wf-metrics.mjs +601 -0
  78. package/tools/wf-persona.mjs +337 -0
  79. package/tools/wf-pool.mjs +250 -0
  80. package/tools/wf-preview.mjs +242 -0
  81. package/tools/wf-recent.mjs +168 -0
  82. package/tools/wf-review.mjs +650 -0
  83. package/tools/wf-rule.mjs +407 -0
  84. package/tools/wf-snapshot.mjs +100 -0
  85. package/tools/wf-spec.mjs +882 -0
  86. package/tools/wf-task.mjs +303 -0
package/core/parse.mjs ADDED
@@ -0,0 +1,310 @@
1
+ /**
2
+ * Pure parsing of the workbench's markdown task board, for the task panel.
3
+ *
4
+ * Nothing here touches the filesystem: the caller reads text and this module
5
+ * turns it into the rows the card renders. Keeping it pure is what makes the
6
+ * card's numbers testable, which matters because the ledger is the single source
7
+ * of truth and a silently mis-parsed row would be worse than no card at all.
8
+ *
9
+ * The parser reads by **header name**, not by column position, so adding a column
10
+ * to the markdown does not shift every field one place to the right.
11
+ *
12
+ * @module dsh-work-fish/core/parse
13
+ */
14
+
15
+ /** Section headings the card understands, keyed by the prefix they start with. */
16
+ export const SECTIONS = /** @type {const} */ ({
17
+ inProgress: '进行中',
18
+ todo: '待办',
19
+ waiting: '等待他人',
20
+ done: '已完成',
21
+ })
22
+
23
+ /**
24
+ * Strip markdown decoration from one table cell.
25
+ *
26
+ * A link keeps its text (the URL is not useful in a 320px card), and an escaped
27
+ * pipe is unescaped so a cell may contain one.
28
+ *
29
+ * @param {string} value raw cell text.
30
+ * @returns {string} plain text.
31
+ */
32
+ export function cleanCell(value) {
33
+ if (typeof value !== 'string') return ''
34
+ let text = value.trim()
35
+ // [label](target) → label, including a bare autolink.
36
+ text = text.replace(/\[([^\]]*)\]\([^)]*\)/gu, '$1')
37
+ text = text.replace(/\\\|/gu, '|')
38
+ text = text.replace(/\*\*([^*]+)\*\*/gu, '$1')
39
+ text = text.replace(/`([^`]*)`/gu, '$1')
40
+ return text.trim()
41
+ }
42
+
43
+ /**
44
+ * Split one markdown table row into cells.
45
+ *
46
+ * Pipes escaped as `\|` stay inside their cell.
47
+ *
48
+ * @param {string} line a line that starts with `|`.
49
+ * @returns {string[]} cell texts without the outer pipes.
50
+ */
51
+ export function splitRow(line) {
52
+ const body = line.trim().replace(/^\|/u, '').replace(/\|$/u, '')
53
+ const cells = []
54
+ let current = ''
55
+ for (let index = 0; index < body.length; index++) {
56
+ const char = body[index]
57
+ if (char === '\\' && body[index + 1] === '|') {
58
+ current += '\\|'
59
+ index++
60
+ continue
61
+ }
62
+ if (char === '|') {
63
+ cells.push(current)
64
+ current = ''
65
+ continue
66
+ }
67
+ current += char
68
+ }
69
+ cells.push(current)
70
+ return cells.map((cell) => cell.trim())
71
+ }
72
+
73
+ /**
74
+ * Whether a row is the `|---|:--:|` separator that follows a header.
75
+ *
76
+ * @param {string[]} cells cells of the row.
77
+ * @returns {boolean} true for a separator row.
78
+ */
79
+ export function isSeparatorRow(cells) {
80
+ if (cells.length === 0) return false
81
+ return cells.every((cell) => /^:?-{1,}:?$/u.test(cell.trim()))
82
+ }
83
+
84
+ /**
85
+ * Read one ISO-ish date out of a ledger cell.
86
+ *
87
+ * Accepted: `2026-11-06`, `2026/11/06`, `11-06` (current year), each optionally
88
+ * followed by a time. Anything else — `未定`, empty, prose — is `null`, because a
89
+ * guessed date would show a false deadline.
90
+ *
91
+ * @param {string} value cell text.
92
+ * @param {number} defaultYear year used for a month-day value.
93
+ * @returns {{year: number, month: number, day: number} | null} the date, or null.
94
+ */
95
+ export function parseDateCell(value, defaultYear) {
96
+ if (typeof value !== 'string') return null
97
+ const text = value.trim()
98
+ const full = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})/u.exec(text)
99
+ if (full !== null) {
100
+ return { year: Number(full[1]), month: Number(full[2]), day: Number(full[3]) }
101
+ }
102
+ const short = /^(\d{1,2})[-/](\d{1,2})(?!\d)/u.exec(text)
103
+ if (short !== null) {
104
+ return { year: defaultYear, month: Number(short[1]), day: Number(short[2]) }
105
+ }
106
+ return null
107
+ }
108
+
109
+ /**
110
+ * Format a date as `YYYY-MM-DD`.
111
+ *
112
+ * @param {{year: number, month: number, day: number}} date the date.
113
+ * @returns {string} ISO date.
114
+ */
115
+ export function formatDate(date) {
116
+ return `${String(date.year).padStart(4, '0')}-${String(date.month).padStart(2, '0')}-${String(date.day).padStart(2, '0')}`
117
+ }
118
+
119
+ /**
120
+ * Whole days from `from` to `to` (positive when `to` is later).
121
+ *
122
+ * Both dates are read as UTC midnights so daylight saving never shifts the count.
123
+ *
124
+ * @param {{year: number, month: number, day: number}} from earlier date.
125
+ * @param {{year: number, month: number, day: number}} to later date.
126
+ * @returns {number} day difference.
127
+ */
128
+ export function dayDifference(from, to) {
129
+ const a = Date.UTC(from.year, from.month - 1, from.day)
130
+ const b = Date.UTC(to.year, to.month - 1, to.day)
131
+ return Math.round((b - a) / 86400000)
132
+ }
133
+
134
+ /**
135
+ * Today's calendar date in one time zone.
136
+ *
137
+ * @param {string} timeZone IANA zone name or offset label.
138
+ * @param {Date} [now] the instant to read.
139
+ * @returns {{year: number, month: number, day: number, weekday: string, label: string}} the date.
140
+ */
141
+ export function todayInZone(timeZone, now = new Date()) {
142
+ let parts
143
+ try {
144
+ parts = new Intl.DateTimeFormat('en-CA', {
145
+ timeZone,
146
+ year: 'numeric',
147
+ month: '2-digit',
148
+ day: '2-digit',
149
+ weekday: 'short',
150
+ }).formatToParts(now)
151
+ } catch {
152
+ // An unusable zone must not blank the card: fall back to the host's own zone.
153
+ parts = new Intl.DateTimeFormat('en-CA', {
154
+ year: 'numeric',
155
+ month: '2-digit',
156
+ day: '2-digit',
157
+ weekday: 'short',
158
+ }).formatToParts(now)
159
+ }
160
+ const pick = (type) => parts.find((part) => part.type === type)?.value ?? ''
161
+ const year = Number(pick('year'))
162
+ const month = Number(pick('month'))
163
+ const day = Number(pick('day'))
164
+ return { year, month, day, weekday: pick('weekday'), label: formatDate({ year, month, day }) }
165
+ }
166
+
167
+ /**
168
+ * Parse the task ledger markdown.
169
+ *
170
+ * @param {string} markdown full text of `tasks/index.md`.
171
+ * @param {number} defaultYear year assumed for a month-day deadline.
172
+ * @returns {{inProgress: object[], todo: object[], waiting: object[], done: object[], warnings: string[]}} parsed sections.
173
+ */
174
+ export function parseLedger(markdown, defaultYear) {
175
+ const result = { inProgress: [], todo: [], waiting: [], done: [], warnings: [] }
176
+ if (typeof markdown !== 'string' || markdown.length === 0) {
177
+ result.warnings.push('台账为空或不可读')
178
+ return result
179
+ }
180
+ const lines = markdown.split(/\r?\n/u)
181
+ /** @type {'inProgress'|'todo'|'waiting'|'done'|null} */
182
+ let section = null
183
+ let header = null
184
+
185
+ for (let index = 0; index < lines.length; index++) {
186
+ const line = lines[index]
187
+ const heading = /^#{2,3}\s+(.*)$/u.exec(line)
188
+ if (heading !== null) {
189
+ const title = cleanCell(heading[1])
190
+ section = sectionOf(title)
191
+ header = null
192
+ if (section === null && header === null) {
193
+ // A heading the card does not know: keep scanning, never guess a section.
194
+ }
195
+ continue
196
+ }
197
+ if (section === null) continue
198
+ const trimmed = line.trim()
199
+ if (!trimmed.startsWith('|')) {
200
+ header = null
201
+ continue
202
+ }
203
+ const cells = splitRow(trimmed)
204
+
205
+ if (header === null) {
206
+ if (isSeparatorRow(cells)) continue
207
+ header = cells.map((cell) => cleanCell(cell))
208
+ continue
209
+ }
210
+ if (isSeparatorRow(cells)) continue
211
+ const row = rowFromCells(header, cells, section, defaultYear, index + 1, result.warnings)
212
+ if (row !== null) result[section].push(row)
213
+ }
214
+
215
+ if (result.inProgress.length + result.todo.length + result.waiting.length + result.done.length === 0) {
216
+ result.warnings.push('未解析出任何任务行,检查表头是否仍为「编号 / 任务 / …」')
217
+ }
218
+ return result
219
+ }
220
+
221
+ /**
222
+ * Map a heading title onto one of the four known sections.
223
+ *
224
+ * @param {string} title cleaned heading text.
225
+ * @returns {'inProgress'|'todo'|'waiting'|'done'|null} the section key.
226
+ */
227
+ function sectionOf(title) {
228
+ for (const [key, prefix] of Object.entries(SECTIONS)) {
229
+ if (title.startsWith(prefix)) return /** @type {any} */ (key)
230
+ }
231
+ return null
232
+ }
233
+
234
+ /**
235
+ * Build one normalized row, reading fields by header name.
236
+ *
237
+ * @param {string[]} header cleaned header cells.
238
+ * @param {string[]} cells cleaned row cells.
239
+ * @param {string} section the owning section key.
240
+ * @param {number} defaultYear year assumed for a month-day deadline.
241
+ * @param {number} lineNumber 1-based line, for warnings.
242
+ * @param {string[]} warnings collected warnings.
243
+ * @returns {object | null} the row, or null when the row carries no id and no title.
244
+ */
245
+ function rowFromCells(header, cells, section, defaultYear, lineNumber, warnings) {
246
+ /** @type {Record<string, string>} */
247
+ const fields = {}
248
+ for (let index = 0; index < header.length; index++) {
249
+ fields[header[index]] = cleanCell(cells[index] ?? '')
250
+ }
251
+ const id = fields['编号'] ?? ''
252
+ const title = fields['任务'] ?? ''
253
+ if (id.length === 0 && title.length === 0) return null
254
+ if (id.length === 0) {
255
+ warnings.push(`第 ${lineNumber} 行有任务名但没有编号`)
256
+ }
257
+ const dueRaw = fields['截止'] ?? ''
258
+ const due = parseDateCell(dueRaw, defaultYear)
259
+ const completedRaw = fields['完成日期'] ?? ''
260
+ const completed = parseDateCell(completedRaw, defaultYear)
261
+ const base = {
262
+ id,
263
+ title,
264
+ status: fields['状态'] ?? '',
265
+ dueRaw,
266
+ due,
267
+ next: fields['下一步'] ?? '',
268
+ note: fields['备注'] ?? '',
269
+ accept: fields['产出物 / 验收'] ?? '',
270
+ priority: fields['优先级'] ?? '',
271
+ }
272
+ if (section === 'waiting') {
273
+ return { ...base, who: fields['等谁'] ?? '', what: fields['等什么'] ?? '', nudge: fields['该催的时间'] ?? '' }
274
+ }
275
+ if (section === 'done') {
276
+ return {
277
+ ...base,
278
+ result: fields['结果'] ?? '',
279
+ completedRaw,
280
+ completed,
281
+ deliverable: fields['交付物'] ?? '',
282
+ }
283
+ }
284
+ return base
285
+ }
286
+
287
+ /**
288
+ * Whether a parsed row is due today.
289
+ *
290
+ * @param {object} row parsed row.
291
+ * @param {{year: number, month: number, day: number}} today today's date.
292
+ * @returns {boolean} true when the deadline is today.
293
+ */
294
+ export function dueToday(row, today) {
295
+ if (row?.due == null) return false
296
+ return dayDifference(today, row.due) === 0
297
+ }
298
+
299
+ /**
300
+ * Days a row is overdue, or 0 when it is not.
301
+ *
302
+ * @param {object} row parsed row.
303
+ * @param {{year: number, month: number, day: number}} today today's date.
304
+ * @returns {number} overdue days.
305
+ */
306
+ export function overdueDays(row, today) {
307
+ if (row?.due == null) return 0
308
+ const days = dayDifference(row.due, today)
309
+ return days > 0 ? days : 0
310
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Work Fish persona section.
3
+ *
4
+ * Replaces the static `@deepseek-ai/dsh-persona` row: same prompt section name,
5
+ * same placement, same `complete` policy — but the text is a function, so it is
6
+ * re-read on every model step. That is what makes "edit in the settings page →
7
+ * effective on the next step" work without restarting the harness.
8
+ *
9
+ * The section name must stay `deployment:persona-prefix`: registering another
10
+ * section with the same name in the same scope throws ("already registered in
11
+ * this scope"), which is why the preset must not mount the stock persona row as
12
+ * well.
13
+ *
14
+ * `complete` stays on purpose. With it off, the assembled prompt starts with the
15
+ * harness identity line, and dsh-llm-workbuddy's `systemPromptPersona: replace`
16
+ * mode treats that as "no deployment persona" and drops the text entirely.
17
+ *
18
+ * The section also carries `<WF_HOME>/AGENTS.md`, the workbench manual (start-up,
19
+ * board, close-out). With `complete` on, this section becomes the whole system
20
+ * prompt and every other section is dropped at assembly, so a second prompt
21
+ * section could not deliver it: the manual has to travel with the persona.
22
+ * Fail-open: a missing or unreadable file yields whatever is left (at worst the
23
+ * shipped skeleton), never an exception in prompt assembly.
24
+ *
25
+ * @module dsh-work-fish/core/persona
26
+ */
27
+
28
+ import { personaSectionText, readPersonaState } from '../tools/lib/persona.mjs'
29
+ import { resolveWorkHome } from '../tools/lib/paths.mjs'
30
+
31
+ /** Plugin name used by the loader / Cordis row. */
32
+ export const name = 'wf-persona'
33
+
34
+ /** The prompt registry must exist before this plugin activates. */
35
+ export const inject = ['systemPrompt']
36
+
37
+ /** Section name owned by `@deepseek-ai/dsh-persona`; we take over its slot. */
38
+ const PERSONA_PREFIX_SECTION = 'deployment:persona-prefix'
39
+
40
+ /**
41
+ * Last composed text, keyed by revision. The store re-reads its files on every
42
+ * call; this only keeps the composed string from being rebuilt when nothing
43
+ * actually changed.
44
+ */
45
+ let cache = { revision: '', text: '' }
46
+
47
+
48
+ /**
49
+ * Read the effective section text, reusing the last one when nothing changed.
50
+ * @param {NodeJS.ProcessEnv} env environment used to resolve the workbench.
51
+ * @returns {string} prompt text, possibly empty when every input is missing.
52
+ */
53
+ function currentText(env) {
54
+ try {
55
+ const next = personaSectionText(env)
56
+ if (next.revision !== cache.revision) cache = { revision: next.revision, text: next.text }
57
+ return cache.text
58
+ } catch {
59
+ // Any surprise here must not break prompt assembly.
60
+ return cache.text
61
+ }
62
+ }
63
+ /**
64
+ * Register the persona section for the mounting (preset) scope.
65
+ * @param {any} ctx Cordis context carrying the `systemPrompt` service.
66
+ * @param {{complete?: boolean, home?: string}} [config] row config.
67
+ */
68
+ export function apply(ctx, config = {}) {
69
+ const env = typeof config.home === 'string' && config.home.trim().length > 0
70
+ ? { ...process.env, WF_HOME: config.home.trim() }
71
+ : process.env
72
+ const home = resolveWorkHome(env)
73
+ const first = readPersonaState(env)
74
+
75
+ if (first.core.trim().length === 0) {
76
+ ctx.logger?.warn?.(`wf: persona skeleton missing (${first.paths.core}); only the user section will be sent`)
77
+ }
78
+ if (first.mode === 'full') {
79
+ ctx.logger?.info?.('wf: persona is in advanced mode (persona.full.md takes over)')
80
+ }
81
+
82
+ ctx.effect(
83
+ () =>
84
+ ctx.systemPrompt.section({
85
+ name: PERSONA_PREFIX_SECTION,
86
+ order: ctx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX'),
87
+ text: () => currentText(env),
88
+ ...(config.complete === false ? {} : { complete: true }),
89
+ // User text may contain `{{...}}`; interpolation would throw on unknown names.
90
+ interpolate: false,
91
+ }),
92
+ 'wf.persona.section()',
93
+ )
94
+
95
+ ctx.logger?.info?.(
96
+ `wf: persona section registered (mode=${first.mode}, ${first.bytes} bytes, home=${home}, revision=${first.revision})`,
97
+ )
98
+ }