dsh-work-fish 0.0.0-stage → 0.1.1
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 +76 -2
- package/THIRD-PARTY-NOTICES.md +59 -0
- package/board/client.js +1041 -0
- package/cordis.patch.yml +172 -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 +185 -0
- package/core/events.mjs +80 -0
- package/core/guard.mjs +155 -0
- package/core/index.mjs +637 -0
- package/core/parse.mjs +310 -0
- package/core/persona.mjs +98 -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 +708 -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 +240 -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 +298 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import test from 'node:test'
|
|
3
|
+
|
|
4
|
+
import { bundleRoots, climbsOut, commandPaths, inspect, isInside, trustedRoots } from './approve-paths.mjs'
|
|
5
|
+
|
|
6
|
+
const ROOTS = ['E:\\C1', 'E:\\C34'].map((value) => value.toLowerCase())
|
|
7
|
+
|
|
8
|
+
test('a write inside a project is approved', () => {
|
|
9
|
+
const verdict = inspect({ name: 'write', args: { file_path: 'E:\\C34\\ts\\game\\module\\a.ts' } }, { roots: ROOTS, allowCommands: true })
|
|
10
|
+
assert.equal(verdict.allow, true)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('a write outside every project is passed to the prompt', () => {
|
|
14
|
+
const verdict = inspect({ name: 'edit', args: { file_path: 'C:\\Windows\\x.ini' } }, { roots: ROOTS, allowCommands: true })
|
|
15
|
+
assert.equal(verdict.allow, false)
|
|
16
|
+
assert.match(verdict.reason, /outside every project/)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('a sibling directory with a shared prefix is not inside the project', () => {
|
|
20
|
+
assert.equal(isInside('E:\\C341\\a.ts', ROOTS), false)
|
|
21
|
+
assert.equal(isInside('E:\\c34\\a.ts', ROOTS), true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('a relative path resolves against the call working directory', () => {
|
|
25
|
+
const inside = inspect({ name: 'write', args: { file_path: 'a.ts' }, cwd: 'E:\\C34\\ts' }, { roots: ROOTS, allowCommands: true })
|
|
26
|
+
assert.equal(inside.allow, true)
|
|
27
|
+
const outside = inspect({ name: 'write', args: { file_path: '..\\..\\x.ts' }, cwd: 'E:\\C34\\ts' }, { roots: ROOTS, allowCommands: true })
|
|
28
|
+
assert.equal(outside.allow, false)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('a patch is approved only when every declared file is inside', () => {
|
|
32
|
+
const clean = '*** Update File: E:\\C1\\client\\a.ts\n*** Add File: E:\\C1\\client\\b.ts'
|
|
33
|
+
assert.equal(inspect({ name: 'apply_patch', args: { patch: clean } }, { roots: ROOTS, allowCommands: true }).allow, true)
|
|
34
|
+
const mixed = '*** Update File: E:\\C1\\client\\a.ts\n*** Update File: C:\\Windows\\x.ini'
|
|
35
|
+
assert.equal(inspect({ name: 'apply_patch', args: { patch: mixed } }, { roots: ROOTS, allowCommands: true }).allow, false)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('the harness spellings of a patch are read too', () => {
|
|
39
|
+
const body = ['file E:\\C1\\client\\a.ts', 'replace 3a', '+x', 'new E:\\C1\\client\\b.ts', '+y', 'remove E:\\C1\\client\\c.ts', 'move E:\\C1\\client\\d.ts -> E:\\C1\\client\\e.ts'].join('\n')
|
|
40
|
+
assert.equal(inspect({ name: 'apply_patch', args: { patch: body } }, { roots: ROOTS, allowCommands: true }).allow, true)
|
|
41
|
+
const mixed = 'file E:\\C1\\client\\a.ts\nnew C:\\Windows\\x.ini'
|
|
42
|
+
assert.equal(inspect({ name: 'apply_patch', args: { patch: mixed } }, { roots: ROOTS, allowCommands: true }).allow, false)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('edit is approved when it names its target as path', () => {
|
|
46
|
+
const verdict = inspect(
|
|
47
|
+
{ name: 'edit', args: { path: 'E:\\C34\\client\\Scripts\\a.ts', edits: [{ op: 'replace', anchor_start: 'ab', lines: ['+x'] }] }, cwd: 'E:\\C34\\client' },
|
|
48
|
+
{ roots: ROOTS, allowCommands: true },
|
|
49
|
+
)
|
|
50
|
+
assert.equal(verdict.allow, true)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('one edit item pointing outside refuses the whole call', () => {
|
|
54
|
+
const verdict = inspect(
|
|
55
|
+
{ name: 'edit', args: { path: 'E:\\C34\\client\\Scripts\\a.ts', edits: [{ path: 'C:\\Windows\\x.ini', lines: [''] }] } },
|
|
56
|
+
{ roots: ROOTS, allowCommands: true },
|
|
57
|
+
)
|
|
58
|
+
assert.equal(verdict.allow, false)
|
|
59
|
+
assert.match(verdict.reason, /outside every project/)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('delete and rename are judged by every path they move', () => {
|
|
63
|
+
assert.equal(inspect({ name: 'delete', args: { paths: ['E:\\C34\\a.ts'] } }, { roots: ROOTS, allowCommands: true }).allow, true)
|
|
64
|
+
assert.equal(inspect({ name: 'delete', args: { paths: ['E:\\C34\\a.ts', 'C:\\x\\b.ts'] } }, { roots: ROOTS, allowCommands: true }).allow, false)
|
|
65
|
+
assert.equal(
|
|
66
|
+
inspect({ name: 'rename', args: { renames: [{ from: 'E:\\C34\\a.ts', to: 'E:\\C34\\b.ts' }] } }, { roots: ROOTS, allowCommands: true }).allow,
|
|
67
|
+
true,
|
|
68
|
+
)
|
|
69
|
+
assert.equal(
|
|
70
|
+
inspect({ name: 'rename', args: { renames: [{ from: 'E:\\C34\\a.ts', to: 'C:\\x\\b.ts' }] } }, { roots: ROOTS, allowCommands: true }).allow,
|
|
71
|
+
false,
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('a command whose every path is inside is approved', () => {
|
|
76
|
+
const verdict = inspect(
|
|
77
|
+
{ name: 'pwsh', args: { command: 'Get-ChildItem E:\\C34\\ts | Out-File E:\\C34\\ts\\list.txt' } },
|
|
78
|
+
{ roots: ROOTS, allowCommands: true },
|
|
79
|
+
)
|
|
80
|
+
assert.equal(verdict.allow, true)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('a command naming one outside path is passed to the prompt', () => {
|
|
84
|
+
const verdict = inspect(
|
|
85
|
+
{ name: 'pwsh', args: { command: 'Copy-Item E:\\C34\\a.ts C:\\Users\\x\\a.ts' } },
|
|
86
|
+
{ roots: ROOTS, allowCommands: true },
|
|
87
|
+
)
|
|
88
|
+
assert.equal(verdict.allow, false)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('a command with no absolute path is never approved', () => {
|
|
92
|
+
const verdict = inspect({ name: 'pwsh', args: { command: 'npm run build' } }, { roots: ROOTS, allowCommands: true })
|
|
93
|
+
assert.equal(verdict.allow, false)
|
|
94
|
+
assert.match(verdict.reason, /names no absolute path/)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('parent traversal is refused even without an absolute path', () => {
|
|
98
|
+
assert.equal(climbsOut('cd ..; Remove-Item -Recurse x'), true)
|
|
99
|
+
const verdict = inspect({ name: 'pwsh', args: { command: 'cd .. ; Set-Content x.txt hi' } }, { roots: ROOTS, allowCommands: true })
|
|
100
|
+
assert.equal(verdict.allow, false)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('commands are passed through when the switch is off', () => {
|
|
104
|
+
const verdict = inspect({ name: 'pwsh', args: { command: 'Get-ChildItem E:\\C34' } }, { roots: ROOTS, allowCommands: false })
|
|
105
|
+
assert.equal(verdict.allow, false)
|
|
106
|
+
assert.match(verdict.reason, /switched off/)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('an empty project list approves nothing', () => {
|
|
110
|
+
const verdict = inspect({ name: 'write', args: { file_path: 'E:\\C34\\a.ts' } }, { roots: [], allowCommands: true })
|
|
111
|
+
assert.equal(verdict.allow, false)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('paths are read out of a command and de-duplicated', () => {
|
|
115
|
+
assert.deepEqual(commandPaths('Copy-Item E:\\C34\\a.ts E:\\C34\\b.ts'), ['E:\\C34\\a.ts', 'E:\\C34\\b.ts'])
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('a dev checkout trusts the package and its parent', () => {
|
|
119
|
+
assert.deepEqual(bundleRoots('E:\\my-dsh\\dsh-work-fish\\app'), ['e:\\my-dsh\\dsh-work-fish\\app', 'e:\\my-dsh\\dsh-work-fish'])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('an installed package trusts only its own directory', () => {
|
|
123
|
+
assert.deepEqual(
|
|
124
|
+
bundleRoots('C:\\Users\\x\\.dsh\\profiles\\desktop\\node_modules\\dsh-work-fish\\app'),
|
|
125
|
+
['c:\\users\\x\\.dsh\\profiles\\desktop\\node_modules\\dsh-work-fish\\app'],
|
|
126
|
+
)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('preview output beside the package is approved under the bundle roots', () => {
|
|
130
|
+
const roots = bundleRoots('E:\\my-dsh\\dsh-work-fish\\app')
|
|
131
|
+
const command = 'Get-Item E:\\my-dsh\\dsh-work-fish\\out\\preview\\a.png'
|
|
132
|
+
assert.equal(inspect({ name: 'pwsh', args: { command } }, { roots, allowCommands: true }).allow, true)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('a sibling checkout stays out of scope', () => {
|
|
136
|
+
const roots = bundleRoots('E:\\my-dsh\\dsh-work-fish\\app')
|
|
137
|
+
const verdict = inspect({ name: 'write', args: { file_path: 'E:\\my-dsh\\dsh-editor-pro\\lib\\client.js' } }, { roots, allowCommands: true })
|
|
138
|
+
assert.equal(verdict.allow, false)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('the workbench directory is trusted alongside the bundle roots', () => {
|
|
142
|
+
const roots = trustedRoots({
|
|
143
|
+
roots: bundleRoots('E:\\my-dsh\\dsh-work-fish\\app'),
|
|
144
|
+
workbench: 'C:\\Users\\x\\.dsh\\work-fish',
|
|
145
|
+
projects: ['E:\\C1'],
|
|
146
|
+
extra: ['E:\\C34'],
|
|
147
|
+
})
|
|
148
|
+
assert.deepEqual(roots, [
|
|
149
|
+
'e:\\my-dsh\\dsh-work-fish\\app',
|
|
150
|
+
'e:\\my-dsh\\dsh-work-fish',
|
|
151
|
+
'c:\\users\\x\\.dsh\\work-fish',
|
|
152
|
+
'e:\\c1',
|
|
153
|
+
'e:\\c34',
|
|
154
|
+
])
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('a workbench write is approved once the workbench is a root', () => {
|
|
158
|
+
const roots = trustedRoots({ workbench: 'C:\\Users\\x\\.dsh\\work-fish', projects: ['E:\\C1'] })
|
|
159
|
+
const inside = inspect({ name: 'write', args: { file_path: 'C:\\Users\\x\\.dsh\\work-fish\\rules\\user-rules.md' } }, { roots, allowCommands: true })
|
|
160
|
+
assert.equal(inside.allow, true)
|
|
161
|
+
const sibling = inspect({ name: 'write', args: { file_path: 'C:\\Users\\x\\.dsh\\sessions\\demo\\log.jsonl' } }, { roots, allowCommands: true })
|
|
162
|
+
assert.equal(sibling.allow, false)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('the same root listed twice collapses, and empty entries are skipped', () => {
|
|
166
|
+
const roots = trustedRoots({
|
|
167
|
+
roots: ['E:\\my-dsh\\dsh-work-fish'],
|
|
168
|
+
workbench: '',
|
|
169
|
+
projects: ['e:\\MY-DSH\\dsh-work-fish', 'E:\\C1'],
|
|
170
|
+
extra: ['E:\\C1', ''],
|
|
171
|
+
})
|
|
172
|
+
assert.deepEqual(roots, ['e:\\my-dsh\\dsh-work-fish', 'e:\\c1'])
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('a path quoted inside a commit message is not a target', () => {
|
|
176
|
+
const verdict = inspect(
|
|
177
|
+
{ name: 'pwsh', args: { command: 'git -C E:\\C34 commit -m "回滚 C:\\Windows\\old.ini 的逻辑"' }, cwd: 'E:\\C34' },
|
|
178
|
+
{ roots: ROOTS, allowCommands: true },
|
|
179
|
+
)
|
|
180
|
+
assert.equal(verdict.allow, true)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('a path quoted inside a search pattern is not a target', () => {
|
|
184
|
+
const verdict = inspect(
|
|
185
|
+
{ name: 'pwsh', args: { command: "Select-String -Path E:\\C34\\a.log -Pattern 'C:\\Windows\\x'" }, cwd: 'E:\\C34' },
|
|
186
|
+
{ roots: ROOTS, allowCommands: true },
|
|
187
|
+
)
|
|
188
|
+
assert.equal(verdict.allow, true)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('a here-string body is data, not a command', () => {
|
|
192
|
+
const command = ["@'", 'print("C:\\Windows\\x")', "'@ | Set-Content E:\\C34\\a.py"].join('\n')
|
|
193
|
+
const verdict = inspect({ name: 'pwsh', args: { command }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
194
|
+
assert.equal(verdict.allow, true)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('a relative path after cd resolves against the new directory', () => {
|
|
198
|
+
const command = 'cd E:\\C34\\client\\Scripts; ..\\node_modules\\.bin\\tsc.cmd --noEmit'
|
|
199
|
+
const verdict = inspect({ name: 'pwsh', args: { command }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
200
|
+
assert.equal(verdict.allow, true)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('a path assembled at run time is never approved', () => {
|
|
204
|
+
const command = 'Copy-Item E:\\C34\\a.ts $dest'
|
|
205
|
+
const verdict = inspect({ name: 'pwsh', args: { command }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
206
|
+
assert.equal(verdict.allow, false)
|
|
207
|
+
assert.match(verdict.reason, /assembled at run time/)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('an outside interpreter still refuses the whole call', () => {
|
|
211
|
+
const command = 'C:\\Users\\x\\runtime\\python.exe E:\\C34\\a.py'
|
|
212
|
+
const verdict = inspect({ name: 'pwsh', args: { command }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
213
|
+
assert.equal(verdict.allow, false)
|
|
214
|
+
assert.match(verdict.reason, /outside every project/)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
test('a directory change into an unresolved variable is refused', () => {
|
|
218
|
+
const verdict = inspect({ name: 'pwsh', args: { command: 'cd $env:TEMP; Set-Content E:\\C34\\a.txt hi' }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
219
|
+
assert.equal(verdict.allow, false)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
test('the parser reports every path of a command and skips bare words', () => {
|
|
223
|
+
assert.deepEqual(commandPaths('node E:\\C34\\a.mjs --note ok', 'E:\\C34'), ['E:\\C34\\a.mjs'])
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
test('a path assigned to a variable in the same command is judged by its value', () => {
|
|
227
|
+
const outside = '$py="C:\\Users\\x\\runtime\\python.exe"; & $py E:\\C34\\a.py'
|
|
228
|
+
const refused = inspect({ name: 'pwsh', args: { command: outside }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
229
|
+
assert.equal(refused.allow, false)
|
|
230
|
+
assert.match(refused.reason, /outside every project/)
|
|
231
|
+
|
|
232
|
+
const inside = '$tmp="E:\\C34\\.tmp"; Set-Content -Path E:\\C34\\a.txt hi'
|
|
233
|
+
const approved = inspect({ name: 'pwsh', args: { command: inside }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
234
|
+
assert.equal(approved.allow, true)
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
test('a variable whose value is not a literal in this command is refused for a write', () => {
|
|
238
|
+
const verdict = inspect({ name: 'pwsh', args: { command: 'Set-Content -Path $target hi' }, cwd: 'E:\\C34' }, { roots: ROOTS, allowCommands: true })
|
|
239
|
+
assert.equal(verdict.allow, false)
|
|
240
|
+
assert.match(verdict.reason, /assembled at run time/)
|
|
241
|
+
})
|
package/core/approve.mjs
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work Fish auto-approval.
|
|
3
|
+
*
|
|
4
|
+
* Sandbox escalation asks the user every time a call reaches outside the session
|
|
5
|
+
* workspace, so working on a project directory (C1, C34, …) means answering a
|
|
6
|
+
* prompt for every write. This row answers those requests on the user's behalf —
|
|
7
|
+
* but only when **every** target of the call lies inside a trusted root (see
|
|
8
|
+
* below).
|
|
9
|
+
*
|
|
10
|
+
* Two listeners joined by `callId`, because neither alone has what is needed:
|
|
11
|
+
* the approval request carries `callId` and no arguments, and the pre-execute
|
|
12
|
+
* hook sees the arguments but may not rewrite them.
|
|
13
|
+
*
|
|
14
|
+
* 1. `tools/pre-execute` records what the pending call declares.
|
|
15
|
+
* 2. `approval/request` looks that record up; a call whose targets are all
|
|
16
|
+
* inside a trusted root is answered `allowed-once`, everything else
|
|
17
|
+
* delegates to `next()` and the ordinary prompt happens.
|
|
18
|
+
*
|
|
19
|
+
* Three kinds of root are in scope. The bundle's own package directory — plus,
|
|
20
|
+
* in a dev checkout, the checkout that holds `out/` — is always trusted
|
|
21
|
+
* (`selfTrusted`), because maintaining the plugin is not the project work this
|
|
22
|
+
* guard exists for. The workbench directory is trusted too: the board, the
|
|
23
|
+
* rules, the memory and this log all live there, and it is not a registered
|
|
24
|
+
* project, so nothing else would ever cover it. Everything else comes from
|
|
25
|
+
* `<WF_HOME>/projects.json`: adding a project to the workbench is what puts it
|
|
26
|
+
* in scope, with no profile edit and no restart. The inspection itself lives in
|
|
27
|
+
* `./approve-paths.mjs`.
|
|
28
|
+
*
|
|
29
|
+
* Sessions whose approval policy is `never` are left alone — that policy must
|
|
30
|
+
* keep rejecting.
|
|
31
|
+
*
|
|
32
|
+
* @module dsh-work-fish/core/approve
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { appendFileSync, mkdirSync, readFileSync } from 'node:fs'
|
|
36
|
+
import { dirname, join } from 'node:path'
|
|
37
|
+
import { fileURLToPath } from 'node:url'
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
import { bundleRoots, inspect, trustedRoots } from './approve-paths.mjs'
|
|
41
|
+
import { resolveWorkHome } from '../tools/lib/paths.mjs'
|
|
42
|
+
|
|
43
|
+
/** Absolute path of this package's directory (`app/`), the bundle's own root. */
|
|
44
|
+
const PACKAGE_DIR = dirname(dirname(fileURLToPath(import.meta.url)))
|
|
45
|
+
|
|
46
|
+
/** Plugin name used by the loader / Cordis row. */
|
|
47
|
+
export const name = 'wf-approve'
|
|
48
|
+
|
|
49
|
+
/** How many pending calls are remembered before the oldest is dropped. */
|
|
50
|
+
const MAX_RECORDS = 512
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Accepted row config keys, applied as plain defaults:
|
|
54
|
+
* enabled (true) · allowCommands (true) · projects ([]) · home ('') · selfTrusted (true)
|
|
55
|
+
*
|
|
56
|
+
* Deliberately no schemastery schema: this file is also consumed straight from a
|
|
57
|
+
* link or a checkout (a dev profile points `dsh-work-fish` at the working tree),
|
|
58
|
+
* where `@deepseek-ai/schemastery` may not resolve. A schema import that throws
|
|
59
|
+
* takes the whole row down with it, and every escalation then falls back to the
|
|
60
|
+
* prompt with no log line to show why.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Read the projects registered in the workbench.
|
|
65
|
+
*
|
|
66
|
+
* `projects.json` is the registry: `{"projects":[{"code":"c34","path":"E:\\C34"}]}`.
|
|
67
|
+
* Entries without a usable path are skipped; a missing or broken file yields an
|
|
68
|
+
* empty list, which approves nothing.
|
|
69
|
+
* @param {string} home - the workbench directory.
|
|
70
|
+
* @returns {string[]} registered project directories.
|
|
71
|
+
*/
|
|
72
|
+
export function readProjects(home) {
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(readFileSync(join(home, 'projects.json'), 'utf8'))
|
|
75
|
+
if (!Array.isArray(parsed?.projects)) return []
|
|
76
|
+
return parsed.projects
|
|
77
|
+
.map((entry) => (typeof entry === 'string' ? entry : entry?.path))
|
|
78
|
+
.filter((value) => typeof value === 'string' && value.trim().length > 0)
|
|
79
|
+
} catch {
|
|
80
|
+
return []
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Append one verdict to the workbench log. Logging never fails a call.
|
|
86
|
+
* @param {string} home - the workbench directory.
|
|
87
|
+
* @param {Record<string, unknown>} record - the verdict.
|
|
88
|
+
* @returns {void}
|
|
89
|
+
*/
|
|
90
|
+
function log(home, record) {
|
|
91
|
+
try {
|
|
92
|
+
const file = join(home, 'auto-approve.log')
|
|
93
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
94
|
+
appendFileSync(file, JSON.stringify({ at: new Date().toISOString(), ...record }) + '\n', 'utf8')
|
|
95
|
+
} catch {
|
|
96
|
+
// A read-only workbench must not turn into a denied tool call.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Record what one pending call declares, keyed by its call id.
|
|
102
|
+
* @param {Map<string, {name: string, args: Record<string, unknown>, cwd?: string}>} records - the bounded store.
|
|
103
|
+
* @param {{callId?: string, name: string, arguments?: Record<string, unknown>, agent?: unknown}} exec - the pre-execute view.
|
|
104
|
+
* @returns {void}
|
|
105
|
+
*/
|
|
106
|
+
function remember(records, exec) {
|
|
107
|
+
if (exec.callId === undefined) return
|
|
108
|
+
const cwd = exec.agent?.session?.header?.cwd
|
|
109
|
+
records.set(exec.callId, {
|
|
110
|
+
name: exec.name,
|
|
111
|
+
args: exec.arguments ?? {},
|
|
112
|
+
...(typeof cwd === 'string' ? { cwd } : {}),
|
|
113
|
+
})
|
|
114
|
+
if (records.size > MAX_RECORDS) {
|
|
115
|
+
const oldest = records.keys().next()
|
|
116
|
+
if (oldest.done !== true) records.delete(oldest.value)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Install both listeners.
|
|
122
|
+
* @param {import('@deepseek-ai/cordis').Context} ctx - the plugin context.
|
|
123
|
+
* @param {z.infer<typeof Config>} config - the row config.
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
126
|
+
export function apply(ctx, config) {
|
|
127
|
+
if (config?.enabled === false) return
|
|
128
|
+
const home = config?.home?.trim() ? config.home.trim() : resolveWorkHome(process.env)
|
|
129
|
+
const extra = (config?.projects ?? []).filter((value) => typeof value === 'string' && value.length > 0)
|
|
130
|
+
const allowCommands = config?.allowCommands !== false
|
|
131
|
+
const records = new Map()
|
|
132
|
+
|
|
133
|
+
ctx.on(
|
|
134
|
+
'tools/pre-execute',
|
|
135
|
+
(exec, next) => {
|
|
136
|
+
remember(records, exec)
|
|
137
|
+
return next()
|
|
138
|
+
},
|
|
139
|
+
{ prepend: true },
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
ctx.on(
|
|
143
|
+
'approval/request',
|
|
144
|
+
(request, next) => {
|
|
145
|
+
const record = request.callId === undefined ? undefined : records.get(request.callId)
|
|
146
|
+
if (record === undefined) {
|
|
147
|
+
// 没有记录有两种可能:pre-execute 没跑(插件没加载 / 事件名不对),或这次请求的 callId 与记录对不上。
|
|
148
|
+
// 写一条留痕,否则只能从「怎么没批准」反推。
|
|
149
|
+
log(home, {
|
|
150
|
+
session: request.agent?.session?.id,
|
|
151
|
+
callId: request.callId,
|
|
152
|
+
tool: undefined,
|
|
153
|
+
allow: false,
|
|
154
|
+
reason: 'no pre-execute record for this call',
|
|
155
|
+
targets: [],
|
|
156
|
+
})
|
|
157
|
+
return next()
|
|
158
|
+
}
|
|
159
|
+
const session = request.agent?.session
|
|
160
|
+
if (ctx.get('approval')?.overrideOf?.(session) === 'never') return next()
|
|
161
|
+
const selfRoots = config?.selfTrusted === false ? [] : bundleRoots(PACKAGE_DIR)
|
|
162
|
+
const roots = trustedRoots({
|
|
163
|
+
roots: selfRoots,
|
|
164
|
+
workbench: home,
|
|
165
|
+
projects: readProjects(home),
|
|
166
|
+
extra,
|
|
167
|
+
})
|
|
168
|
+
const verdict = inspect(record, { roots, allowCommands })
|
|
169
|
+
log(home, {
|
|
170
|
+
session: session?.id,
|
|
171
|
+
callId: request.callId,
|
|
172
|
+
tool: record.name,
|
|
173
|
+
allow: verdict.allow,
|
|
174
|
+
reason: verdict.reason,
|
|
175
|
+
targets: verdict.targets,
|
|
176
|
+
})
|
|
177
|
+
if (!verdict.allow) return next()
|
|
178
|
+
return Promise.resolve('allowed-once')
|
|
179
|
+
},
|
|
180
|
+
{ prepend: true },
|
|
181
|
+
)
|
|
182
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-run bootstrap: lay down the workbench skeleton.
|
|
3
|
+
*
|
|
4
|
+
* Idempotent by design — missing files are created, existing files are never
|
|
5
|
+
* overwritten, so a user's edits survive plugin upgrades. The skeleton comes
|
|
6
|
+
* from the package's `template/` directory; the destination is the workbench
|
|
7
|
+
* home (`WF_HOME`, `$DSH_HOME/work-fish` by default).
|
|
8
|
+
*
|
|
9
|
+
* Rules are **not** copied: they stay read-only inside this package and the
|
|
10
|
+
* workbench only carries `rules/INDEX.md`, a generated pointer to them.
|
|
11
|
+
* Skills are not copied either — `core/skills.mjs` registers them from the
|
|
12
|
+
* package at activation.
|
|
13
|
+
*
|
|
14
|
+
* The host entry (`core/index.mjs`) calls this once per start, so a fresh install
|
|
15
|
+
* gets a workbench with no extra step.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-work-fish/core/bootstrap
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import fs from 'node:fs'
|
|
21
|
+
import path from 'node:path'
|
|
22
|
+
import { fileURLToPath } from 'node:url'
|
|
23
|
+
import { parseSkillFile } from './skills.mjs'
|
|
24
|
+
|
|
25
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url)) // <pkg>/core
|
|
26
|
+
/** `<pkg>`. The skeletons live beside the code, so a packed tarball carries them. */
|
|
27
|
+
const PKG_ROOT = path.resolve(HERE, '..')
|
|
28
|
+
const SKILLS_DIR = path.join(PKG_ROOT, 'skills')
|
|
29
|
+
|
|
30
|
+
/** Skeleton revision; bump when a new release adds required files. */
|
|
31
|
+
export const SEED_VERSION = 3
|
|
32
|
+
|
|
33
|
+
const DIRECTORIES = ['tasks', 'memory', 'memory/projects', 'memory/pool', 'out', 'archive', 'rules', 'rules/projects', '.tmp']
|
|
34
|
+
|
|
35
|
+
/** `[source relative to the package dir, destination relative to home]`. */
|
|
36
|
+
const FILES = [
|
|
37
|
+
['template/AGENTS.template.md', 'AGENTS.md'],
|
|
38
|
+
['template/tasks/index.md', 'tasks/index.md'],
|
|
39
|
+
['template/persona-user.md', 'persona.md'],
|
|
40
|
+
['template/memory/user-profile.md', 'memory/user-profile.md'],
|
|
41
|
+
['template/memory/preferences.md', 'memory/preferences.md'],
|
|
42
|
+
['template/rules/user-rules.md', 'rules/user-rules.md'],
|
|
43
|
+
['template/memory/projects/README.md', 'memory/projects/README.md'],
|
|
44
|
+
['template/memory/pool/experience.md', 'memory/pool/experience.md'],
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* One-line summary of a skill, derived from its frontmatter `description`.
|
|
49
|
+
*
|
|
50
|
+
* The index is read at start-up, so a row is capped: first sentence when it
|
|
51
|
+
* fits, otherwise a hard cut. The full text stays in the `SKILL.md`, which is
|
|
52
|
+
* the only source — this file is generated and never hand-edited.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} text frontmatter description.
|
|
55
|
+
* @param {number} max maximum characters kept.
|
|
56
|
+
* @returns {string} shortened single-line text.
|
|
57
|
+
*/
|
|
58
|
+
function oneLine(text, max = 110) {
|
|
59
|
+
const flat = text.replace(/\s+/g, ' ').trim()
|
|
60
|
+
const firstSentence = flat.split(/(?<=\.)\s/)[0]
|
|
61
|
+
const picked = firstSentence.length > 0 && firstSentence.length <= max ? firstSentence : flat
|
|
62
|
+
// Count code points, not UTF-16 units: slicing an emoji in half writes U+FFFD.
|
|
63
|
+
const points = [...picked]
|
|
64
|
+
return points.length <= max ? picked : `${points.slice(0, max - 1).join('').trimEnd()}…`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build the bundled-skill bullet list for `rules/INDEX.md`.
|
|
69
|
+
*
|
|
70
|
+
* One bullet per `skills/<name>/SKILL.md`, sorted by skill name. A directory
|
|
71
|
+
* without a usable `name` / `description` is skipped, exactly as `core/skills`
|
|
72
|
+
* skips it at registration, so the index can never advertise a skill the
|
|
73
|
+
* session does not have.
|
|
74
|
+
*
|
|
75
|
+
* @returns {string} markdown bullets, or an empty string when nothing loads.
|
|
76
|
+
*/
|
|
77
|
+
function skillsTable() {
|
|
78
|
+
if (!fs.existsSync(SKILLS_DIR)) return ''
|
|
79
|
+
|
|
80
|
+
/** @type {{name: string, description: string}[]} */
|
|
81
|
+
const rows = []
|
|
82
|
+
for (const entry of fs.readdirSync(SKILLS_DIR, { withFileTypes: true })) {
|
|
83
|
+
if (!entry.isDirectory()) continue
|
|
84
|
+
const file = path.join(SKILLS_DIR, entry.name, 'SKILL.md')
|
|
85
|
+
if (!fs.existsSync(file)) continue
|
|
86
|
+
|
|
87
|
+
/** @type {string} */
|
|
88
|
+
let text = ''
|
|
89
|
+
try {
|
|
90
|
+
text = fs.readFileSync(file, 'utf8')
|
|
91
|
+
} catch {
|
|
92
|
+
// Unreadable (a directory named SKILL.md, EACCES): skip the entry rather
|
|
93
|
+
// than lose the whole index, which is rewritten on every start-up.
|
|
94
|
+
continue
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const parsed = parseSkillFile(text)
|
|
98
|
+
const name = parsed?.meta.name
|
|
99
|
+
const description = parsed?.meta.description
|
|
100
|
+
if (name === undefined || description === undefined || description.length === 0) continue
|
|
101
|
+
rows.push({ name, description })
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return rows
|
|
105
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
106
|
+
// Backticks are dropped from the summary so an unbalanced one cannot open a
|
|
107
|
+
// code span that swallows the rest of the section; the name keeps its span.
|
|
108
|
+
.map((row) => `- \`${row.name.replace(/`/g, "'")}\` — ${oneLine(row.description).replace(/`/g, '')}`)
|
|
109
|
+
.join('\n')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Create the workbench skeleton under `homeDir`.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} homeDir absolute workbench path.
|
|
116
|
+
* @param {NodeJS.ProcessEnv} [env] reserved; kept for call-site compatibility.
|
|
117
|
+
* @returns {{home: string, created: number, files: string[]}} what was created.
|
|
118
|
+
*/
|
|
119
|
+
export function bootstrap(homeDir, env = process.env) {
|
|
120
|
+
if (typeof homeDir !== 'string' || homeDir.trim().length === 0) {
|
|
121
|
+
throw new Error('bootstrap needs an absolute home directory')
|
|
122
|
+
}
|
|
123
|
+
const created = []
|
|
124
|
+
|
|
125
|
+
for (const relative of DIRECTORIES) {
|
|
126
|
+
const dir = path.join(homeDir, relative)
|
|
127
|
+
if (fs.existsSync(dir)) continue
|
|
128
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
129
|
+
created.push(`${relative}/`)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for (const [from, to] of FILES) {
|
|
133
|
+
const source = path.join(PKG_ROOT, from)
|
|
134
|
+
if (!fs.existsSync(source)) continue
|
|
135
|
+
const target = path.join(homeDir, to)
|
|
136
|
+
if (fs.existsSync(target)) continue
|
|
137
|
+
|
|
138
|
+
if (fs.statSync(source).isDirectory()) {
|
|
139
|
+
fs.mkdirSync(target, { recursive: true })
|
|
140
|
+
for (const name of fs.readdirSync(source)) {
|
|
141
|
+
if (!name.endsWith('.md')) continue
|
|
142
|
+
const fileTarget = path.join(target, name)
|
|
143
|
+
if (fs.existsSync(fileTarget)) continue
|
|
144
|
+
fs.copyFileSync(path.join(source, name), fileTarget)
|
|
145
|
+
created.push(path.posix.join(to, name))
|
|
146
|
+
}
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
151
|
+
fs.copyFileSync(source, target)
|
|
152
|
+
created.push(to)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const marker = path.join(homeDir, '.work-fish.json')
|
|
156
|
+
if (!fs.existsSync(marker)) {
|
|
157
|
+
const payload = { seed: SEED_VERSION, createdAt: new Date().toISOString() }
|
|
158
|
+
fs.writeFileSync(marker, `${JSON.stringify(payload, null, 2)}\n`)
|
|
159
|
+
created.push('.work-fish.json')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// The rules pointer is generated, not seeded: rewrite it every start so a
|
|
163
|
+
// moved or upgraded plugin always leaves a correct absolute path behind.
|
|
164
|
+
const indexTemplate = path.join(PKG_ROOT, 'template', 'rules-index.md')
|
|
165
|
+
if (fs.existsSync(indexTemplate)) {
|
|
166
|
+
const rulesDir = path.join(PKG_ROOT, 'rules').split(path.sep).join('/')
|
|
167
|
+
const toolsDir = path.join(PKG_ROOT, 'tools').split(path.sep).join('/')
|
|
168
|
+
const index = fs.readFileSync(indexTemplate, 'utf8').replace(/\{\{(\w+)\}\}/g, (placeholder, name) => {
|
|
169
|
+
// One pass, so text inserted for one placeholder is never re-scanned and
|
|
170
|
+
// a skill description that mentions {{TOOLS_DIR}} stays literal.
|
|
171
|
+
if (name === 'RULES_DIR') return rulesDir
|
|
172
|
+
if (name === 'TOOLS_DIR') return toolsDir
|
|
173
|
+
if (name === 'SKILLS_TABLE') return skillsTable()
|
|
174
|
+
return placeholder
|
|
175
|
+
})
|
|
176
|
+
const indexTarget = path.join(homeDir, 'rules', 'INDEX.md')
|
|
177
|
+
// Write beside the target and rename: an interrupted start-up must not leave
|
|
178
|
+
// a half-written INDEX.md where a complete one used to be.
|
|
179
|
+
const staging = `${indexTarget}.${process.pid}.tmp`
|
|
180
|
+
fs.writeFileSync(staging, index, 'utf8')
|
|
181
|
+
fs.renameSync(staging, indexTarget)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return { home: homeDir, created: created.length, files: created }
|
|
185
|
+
}
|