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.
- package/LICENSE +21 -0
- package/README.md +82 -2
- package/THIRD-PARTY-NOTICES.md +61 -0
- package/board/client.js +1048 -0
- package/cordis.patch.yml +173 -0
- package/core/approve-paths.mjs +387 -0
- package/core/approve-paths.test.mjs +241 -0
- package/core/approve.mjs +182 -0
- package/core/bootstrap.mjs +186 -0
- package/core/events.mjs +80 -0
- package/core/guard.mjs +155 -0
- package/core/index.mjs +630 -0
- package/core/parse.mjs +310 -0
- package/core/persona.mjs +98 -0
- package/core/pet-bridge.mjs +439 -0
- package/core/report.mjs +370 -0
- package/core/skills.mjs +111 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.webp +0 -0
- package/icon.png +0 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +69 -4
- package/rules/code-rules.md +92 -0
- package/rules/experience-pool.md +59 -0
- package/rules/file-rules.md +134 -0
- package/rules/memory-rules.md +91 -0
- package/rules/task-rules.md +71 -0
- package/skills/code-review/LICENSE +202 -0
- package/skills/code-review/NOTICE.md +75 -0
- package/skills/code-review/SKILL.md +155 -0
- package/skills/code-review/upstream/README.md +258 -0
- package/skills/code-review/upstream/code-review.command.md +110 -0
- package/skills/code-review/upstream/plugin.json +10 -0
- package/skills/code-simplifier/LICENSE +202 -0
- package/skills/code-simplifier/NOTICE.md +72 -0
- package/skills/code-simplifier/SKILL.md +126 -0
- package/skills/code-simplifier/agents/code-simplifier.md +52 -0
- package/skills/code-simplifier/upstream/plugin.json +9 -0
- package/skills/comfyui-h3/SKILL.md +455 -0
- package/skills/comfyui-h3/reference/failures.md +84 -0
- package/skills/comfyui-h3/reference/serial-production.md +173 -0
- package/skills/delete-gate/SKILL.md +48 -0
- package/skills/doc-writing/SKILL.md +152 -0
- package/skills/doc-writing/reference/skeletons.md +81 -0
- package/skills/feature-dev/LICENSE +202 -0
- package/skills/feature-dev/NOTICE.md +67 -0
- package/skills/feature-dev/SKILL.md +181 -0
- package/skills/feature-dev/agents/code-architect.md +34 -0
- package/skills/feature-dev/agents/code-explorer.md +51 -0
- package/skills/feature-dev/agents/code-reviewer.md +46 -0
- package/skills/feature-dev/upstream/README.md +412 -0
- package/skills/feature-dev/upstream/feature-dev.command.md +125 -0
- package/skills/feature-dev/upstream/plugin.json +9 -0
- package/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/frontend-design/SKILL.md +71 -0
- package/skills/git-flow/SKILL.md +80 -0
- package/skills/plan-revision/SKILL.md +54 -0
- package/skills/task-setup/SKILL.md +124 -0
- package/template/AGENTS.template.md +28 -0
- package/template/memory/pool/experience.md +9 -0
- package/template/memory/preferences.md +17 -0
- package/template/memory/projects/README.md +6 -0
- package/template/memory/user-profile.md +33 -0
- package/template/persona-core.md +32 -0
- package/template/persona-user.md +0 -0
- package/template/rules/user-rules.md +20 -0
- package/template/rules-index.md +50 -0
- package/template/tasks/index.md +34 -0
- package/tools/lib/paths.mjs +31 -0
- package/tools/lib/persona.mjs +454 -0
- package/tools/lib/taskboard.mjs +713 -0
- package/tools/wf-audit.cmd +3 -0
- package/tools/wf-audit.ps1 +242 -0
- package/tools/wf-mem.mjs +336 -0
- package/tools/wf-metrics.mjs +601 -0
- package/tools/wf-persona.mjs +337 -0
- package/tools/wf-pool.mjs +250 -0
- package/tools/wf-preview.mjs +242 -0
- package/tools/wf-recent.mjs +168 -0
- package/tools/wf-review.mjs +650 -0
- package/tools/wf-rule.mjs +407 -0
- package/tools/wf-snapshot.mjs +100 -0
- package/tools/wf-spec.mjs +882 -0
- package/tools/wf-task.mjs +303 -0
package/core/events.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Panel event bus: the bridge pushes, `GET /wf/events` drains.
|
|
3
|
+
*
|
|
4
|
+
* The task panel lives in the browser while the events that should move it are
|
|
5
|
+
* detected by the host (a right-click menu item on the `dsh-pet` character, or
|
|
6
|
+
* a ledger write performed on its behalf). Polling `/wf/tasks` every second
|
|
7
|
+
* would answer "did anything change" by re-reading the ledger each time, so the
|
|
8
|
+
* host keeps a tiny in-memory sequence instead and the client long-polls it.
|
|
9
|
+
*
|
|
10
|
+
* Delivery is by cursor, not by queue: a client that was away just sees a
|
|
11
|
+
* larger `since` and a shorter list, which is exactly what it needs — the panel
|
|
12
|
+
* refreshes from `/wf/tasks` on any event anyway.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-work-fish/core/events
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Oldest events are dropped past this many; a long-gone client is told to refetch. */
|
|
18
|
+
const MAX_KEPT = 50
|
|
19
|
+
|
|
20
|
+
/** Monotonic sequence; never reused, survives nothing (in-memory only). */
|
|
21
|
+
let seq = 0
|
|
22
|
+
|
|
23
|
+
/** @type {{seq: number, type: string}[]} kept events, oldest first. */
|
|
24
|
+
const items = []
|
|
25
|
+
|
|
26
|
+
/** @type {Set<() => void>} pending polls waiting for the next event. */
|
|
27
|
+
const waiters = new Set()
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Record one event and wake every pending poll.
|
|
31
|
+
* @param {'open' | 'changed'} type what the panel should do.
|
|
32
|
+
* @returns {number} the sequence number assigned.
|
|
33
|
+
*/
|
|
34
|
+
export function pushEvent(type) {
|
|
35
|
+
seq += 1
|
|
36
|
+
items.push({ seq, type })
|
|
37
|
+
while (items.length > MAX_KEPT) items.shift()
|
|
38
|
+
for (const wake of [...waiters]) wake()
|
|
39
|
+
return seq
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Read every event newer than a cursor, optionally waiting for one.
|
|
44
|
+
*
|
|
45
|
+
* `since === null` means "subscribe from now": a freshly mounted panel must not
|
|
46
|
+
* see the `open` of a click that happened before it existed. A cursor from a
|
|
47
|
+
* previous process (larger than the current sequence) is reported as `reset`
|
|
48
|
+
* and also starts from now, so a restarted host cannot silently swallow the
|
|
49
|
+
* next real event.
|
|
50
|
+
*
|
|
51
|
+
* @param {number | null} since cursor the client already has, or null to subscribe.
|
|
52
|
+
* @param {number} waitMs how long to hang when nothing is newer; `0` returns at once.
|
|
53
|
+
* @returns {Promise<{since: number, events: {seq: number, type: string}[], reset: boolean}>} the batch.
|
|
54
|
+
*/
|
|
55
|
+
export async function waitEvents(since, waitMs) {
|
|
56
|
+
const cursor = Number.isFinite(since) && since >= 0 ? Math.floor(since) : null
|
|
57
|
+
const reset = cursor !== null && cursor > seq
|
|
58
|
+
const from = cursor === null || reset ? seq : Math.max(cursor, seq - MAX_KEPT)
|
|
59
|
+
const pending = () => items.filter((event) => event.seq > from)
|
|
60
|
+
const wait = Math.min(10_000, Math.max(0, Math.floor(Number(waitMs) || 0)))
|
|
61
|
+
|
|
62
|
+
if (pending().length === 0 && wait > 0) {
|
|
63
|
+
await new Promise((resolve) => {
|
|
64
|
+
/** @type {{timer?: ReturnType<typeof setTimeout>}} */
|
|
65
|
+
const hold = {}
|
|
66
|
+
let settled = false
|
|
67
|
+
const finish = () => {
|
|
68
|
+
if (settled) return
|
|
69
|
+
settled = true
|
|
70
|
+
if (hold.timer !== undefined) clearTimeout(hold.timer)
|
|
71
|
+
waiters.delete(finish)
|
|
72
|
+
resolve(undefined)
|
|
73
|
+
}
|
|
74
|
+
hold.timer = setTimeout(finish, wait)
|
|
75
|
+
waiters.add(finish)
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { since: seq, events: pending(), reset }
|
|
80
|
+
}
|
package/core/guard.mjs
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work Fish write guard.
|
|
3
|
+
*
|
|
4
|
+
* Refuses direct `write` / `edit` / `apply_patch` calls into the protected
|
|
5
|
+
* directories and points at the tool that owns each of them:
|
|
6
|
+
*
|
|
7
|
+
* persona.md / persona.full.md -> wf-persona
|
|
8
|
+
* tasks/, board/ -> wf-task
|
|
9
|
+
* memory/pool/experience.md -> wf-pool
|
|
10
|
+
* memory/ -> wf-mem
|
|
11
|
+
* rules/INDEX.md -> generated at startup, never written
|
|
12
|
+
* rules/ (workbench) -> wf-rule
|
|
13
|
+
* rules/ (package) -> wf-rule with @plugin/rules/...
|
|
14
|
+
*
|
|
15
|
+
* Scope: it sees tool calls only. A shell command or an external editor is out
|
|
16
|
+
* of reach — this raises the cost of the shortcut, it does not seal the file.
|
|
17
|
+
*
|
|
18
|
+
* @module dsh-work-fish/core/guard
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { resolve, dirname } from 'node:path'
|
|
22
|
+
import { homedir } from 'node:os'
|
|
23
|
+
import { fileURLToPath } from 'node:url'
|
|
24
|
+
|
|
25
|
+
/** The tool service must exist before this plugin activates. */
|
|
26
|
+
export const inject = ['tools']
|
|
27
|
+
|
|
28
|
+
/** Tools that write files directly. */
|
|
29
|
+
const GUARDED = new Set(['write', 'edit', 'apply_patch'])
|
|
30
|
+
|
|
31
|
+
/** Where the rule-write tool lives, for the refusal text. */
|
|
32
|
+
const WF_RULE = 'node app/tools/wf-rule.mjs'
|
|
33
|
+
|
|
34
|
+
/** First match wins: which tool owns a protected path. */
|
|
35
|
+
const OWNERS = [
|
|
36
|
+
{
|
|
37
|
+
test: (p) => p === 'persona.md' || p === 'persona.full.md',
|
|
38
|
+
tool: 'wf-persona',
|
|
39
|
+
how: 'node app/tools/wf-persona.mjs',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
test: (p) => p.startsWith('tasks/') || p.startsWith('board/'),
|
|
43
|
+
tool: 'wf-task',
|
|
44
|
+
how: 'node app/tools/wf-task.mjs',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
test: (p) => p === 'memory/pool/experience.md',
|
|
48
|
+
tool: 'wf-pool',
|
|
49
|
+
how: 'node app/tools/wf-pool.mjs',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
test: (p) => p.startsWith('memory/'),
|
|
53
|
+
tool: 'wf-mem',
|
|
54
|
+
how: 'node app/tools/wf-mem.mjs',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
test: (p) => p === 'rules/INDEX.md',
|
|
58
|
+
tool: null,
|
|
59
|
+
how: '这份入口由插件启动时生成,手改会被覆盖;改文案改插件 template/rules-index.md',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
test: (p) => p.startsWith('rules/'),
|
|
63
|
+
tool: 'wf-rule',
|
|
64
|
+
how: WF_RULE,
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
/** The package root: app/core → package root. Rules there ship with the plugin. */
|
|
69
|
+
function pluginRoot() {
|
|
70
|
+
const override = process.env.WF_PLUGIN_ROOT
|
|
71
|
+
if (override && override.trim()) return resolve(override)
|
|
72
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A package rule file, named the way wf-rule takes it (`@plugin/rules/x.md`).
|
|
77
|
+
*
|
|
78
|
+
* @param {string} path the path a tool call would touch.
|
|
79
|
+
* @param {string} root the package root.
|
|
80
|
+
* @returns {string|null} the wf-rule spec, or null when it is not a package rule.
|
|
81
|
+
*/
|
|
82
|
+
export function pluginRuleSpec(path, root) {
|
|
83
|
+
const raw = String(path).replace(/\\/g, '/')
|
|
84
|
+
const base = root.replace(/\\/g, '/')
|
|
85
|
+
if (!raw.startsWith(`${base}/rules/`)) return null
|
|
86
|
+
const rel = raw.slice(base.length + 1)
|
|
87
|
+
return rel.endsWith('.md') ? `@plugin/${rel}` : null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The workbench root, resolved the same way the tools resolve it. */
|
|
91
|
+
function workHome() {
|
|
92
|
+
const fromEnv = process.env.WF_HOME
|
|
93
|
+
if (fromEnv && fromEnv.trim()) return resolve(fromEnv)
|
|
94
|
+
const dshHome = process.env.DSH_HOME && process.env.DSH_HOME.trim() ? resolve(process.env.DSH_HOME) : resolve(homedir(), '.dsh')
|
|
95
|
+
return resolve(dshHome, 'work-fish')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Normalize a model-supplied path to a workbench-relative posix path.
|
|
100
|
+
* Returns null when the path is neither relative to the workbench nor absolute.
|
|
101
|
+
*/
|
|
102
|
+
export function relative(path, home) {
|
|
103
|
+
const raw = String(path).replace(/\\/g, '/').replace(/^\.\//, '')
|
|
104
|
+
if (/^(tasks|board|memory|rules)\//.test(raw)) return raw
|
|
105
|
+
// The two persona files sit at the workbench root, not under a protected directory.
|
|
106
|
+
if (/^persona(?:\.full)?\.md$/.test(raw)) return raw
|
|
107
|
+
if (!/^[a-zA-Z]:\//.test(raw) && !raw.startsWith('/')) return null
|
|
108
|
+
const prefix = `${home.replace(/\\/g, '/')}/`
|
|
109
|
+
return raw.startsWith(prefix) ? raw.slice(prefix.length) : null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Every path a single tool call would touch. */
|
|
113
|
+
export function pathsOf(exec) {
|
|
114
|
+
const args = exec.arguments ?? {}
|
|
115
|
+
if (exec.name === 'apply_patch') {
|
|
116
|
+
const text = String(args.input ?? args.patch ?? '')
|
|
117
|
+
const found = []
|
|
118
|
+
// Section headers of a patch: `file x`, `new x`, `move a -> b`, `remove x`.
|
|
119
|
+
for (const match of text.matchAll(/^(?:file|new|remove) (.+?)\s*$|^move (.+?) -> (.+?)\s*$/gm)) {
|
|
120
|
+
if (match[1] !== undefined) found.push(match[1])
|
|
121
|
+
else found.push(match[2], match[3])
|
|
122
|
+
}
|
|
123
|
+
// The `*** Add File:` / `*** Update File:` dialect some clients send.
|
|
124
|
+
for (const match of text.matchAll(/^\*\*\* (?:Add File|Update File|Delete File|Move to):\s*(.+?)\s*$/gm)) {
|
|
125
|
+
found.push(match[1])
|
|
126
|
+
}
|
|
127
|
+
return found
|
|
128
|
+
}
|
|
129
|
+
return [args.file_path ?? args.path ?? args.filePath].filter((value) => typeof value === 'string')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Which tool owns this path, if any. */
|
|
133
|
+
function ownerOf(candidate, home, plugin) {
|
|
134
|
+
const rel = relative(candidate, home)
|
|
135
|
+
if (rel !== null) return OWNERS.find((rule) => rule.test(rel))
|
|
136
|
+
const spec = pluginRuleSpec(candidate, plugin)
|
|
137
|
+
if (spec !== null) return { tool: 'wf-rule', how: `${WF_RULE}(--file ${spec})` }
|
|
138
|
+
return undefined
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function apply(ctx) {
|
|
142
|
+
const home = workHome()
|
|
143
|
+
const plugin = pluginRoot()
|
|
144
|
+
ctx.on('tools/pre-execute', async (exec, next) => {
|
|
145
|
+
if (!GUARDED.has(exec.name)) return next()
|
|
146
|
+
for (const candidate of pathsOf(exec)) {
|
|
147
|
+
const owner = ownerOf(candidate, home, plugin)
|
|
148
|
+
if (owner === undefined) continue
|
|
149
|
+
const reason =
|
|
150
|
+
owner.tool === null ? `${candidate} 不能直接写:${owner.how}` : `${candidate} 只能经 ${owner.tool} 写入:${owner.how}`
|
|
151
|
+
return { kind: 'deny', reason }
|
|
152
|
+
}
|
|
153
|
+
return next()
|
|
154
|
+
})
|
|
155
|
+
}
|