@xmodelin/dsh-collab-sessions 0.0.0-stage → 0.0.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/README.md +685 -2
- package/client.js +2172 -0
- package/cordis.patch.yml +195 -0
- package/icon.svg +7 -0
- package/index.js +2583 -0
- package/lib/auth.js +187 -0
- package/lib/layout.js +821 -0
- package/lib/notices.js +135 -0
- package/lib/relationships.js +157 -0
- package/lib/requests.js +315 -0
- package/lib/tasks.js +375 -0
- package/lib/write-scope.js +96 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +61 -4
package/lib/tasks.js
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supervisor task registry. A task is the unit created for one accepted
|
|
3
|
+
* request; subtasks are the units assigned to functional workers. The store is
|
|
4
|
+
* the source of truth for assignment, completion, results, and task lifecycle;
|
|
5
|
+
* collaboration messages are only wake-up notifications.
|
|
6
|
+
*/
|
|
7
|
+
import crypto from 'node:crypto'
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
|
|
10
|
+
import { fileStamp, isSessionId, readStateJson, withFileLock, writeJson } from './layout.js'
|
|
11
|
+
|
|
12
|
+
const ACTIVE_STATUSES = new Set(['created', 'assigned', 'accepted', 'running'])
|
|
13
|
+
|
|
14
|
+
function nowIso(now) {
|
|
15
|
+
return new Date(now).toISOString()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function subtaskSummary(subtask) {
|
|
19
|
+
return {
|
|
20
|
+
id: subtask.id,
|
|
21
|
+
subtaskId: subtask.id,
|
|
22
|
+
taskId: subtask.taskId,
|
|
23
|
+
supervisor: subtask.supervisor,
|
|
24
|
+
worker: subtask.worker,
|
|
25
|
+
title: subtask.title,
|
|
26
|
+
status: subtask.status,
|
|
27
|
+
attempts: subtask.attempts,
|
|
28
|
+
createdAt: subtask.createdAt,
|
|
29
|
+
updatedAt: subtask.updatedAt,
|
|
30
|
+
...(Number.isInteger(subtask.createdTurn) ? { createdTurn: subtask.createdTurn } : {}),
|
|
31
|
+
...(Number.isInteger(subtask.assignedTurn) ? { assignedTurn: subtask.assignedTurn } : {}),
|
|
32
|
+
...(typeof subtask.capabilityVersion === 'string' ? { capabilityVersion: subtask.capabilityVersion } : {}),
|
|
33
|
+
...(subtask.result === null ? {} : { result: subtask.result }),
|
|
34
|
+
...(subtask.failure === null ? {} : { failure: subtask.failure }),
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function taskSummary(task) {
|
|
39
|
+
return {
|
|
40
|
+
id: task.id,
|
|
41
|
+
taskId: task.id,
|
|
42
|
+
supervisor: task.supervisor,
|
|
43
|
+
title: task.title,
|
|
44
|
+
status: task.status,
|
|
45
|
+
requestId: task.requestId ?? null,
|
|
46
|
+
createdAt: task.createdAt,
|
|
47
|
+
closedAt: task.closedAt ?? null,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Convert the old project/task document into tasks/subtasks. */
|
|
52
|
+
function migrateLegacy(raw) {
|
|
53
|
+
if (raw === null || typeof raw !== 'object') return { version: 2, tasks: {}, subtasks: {} }
|
|
54
|
+
if (raw.version === 2 && raw.subtasks !== null && typeof raw.subtasks === 'object') {
|
|
55
|
+
return {
|
|
56
|
+
version: 2,
|
|
57
|
+
tasks: raw.tasks !== null && typeof raw.tasks === 'object' ? raw.tasks : {},
|
|
58
|
+
subtasks: raw.subtasks,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const tasks = {}
|
|
62
|
+
for (const [id, project] of Object.entries(raw.projects ?? {})) {
|
|
63
|
+
if (project === null || typeof project !== 'object') continue
|
|
64
|
+
tasks[id] = {
|
|
65
|
+
id,
|
|
66
|
+
supervisor: project.supervisor,
|
|
67
|
+
title: project.title,
|
|
68
|
+
status: project.status === 'closed' ? 'closed' : 'open',
|
|
69
|
+
requestId: project.requestId ?? null,
|
|
70
|
+
createdAt: project.createdAt ?? Date.now(),
|
|
71
|
+
closedAt: project.closedAt ?? null,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const subtasks = {}
|
|
75
|
+
for (const [id, task] of Object.entries(raw.tasks ?? {})) {
|
|
76
|
+
if (task === null || typeof task !== 'object') continue
|
|
77
|
+
const taskId = task.projectId ?? task.taskId
|
|
78
|
+
if (typeof taskId !== 'string') continue
|
|
79
|
+
subtasks[id] = {
|
|
80
|
+
...task,
|
|
81
|
+
id,
|
|
82
|
+
taskId,
|
|
83
|
+
subtaskId: id,
|
|
84
|
+
}
|
|
85
|
+
delete subtasks[id].projectId
|
|
86
|
+
}
|
|
87
|
+
return { version: 2, tasks, subtasks }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Durable tasks and their subtasks. */
|
|
91
|
+
export class TaskStore {
|
|
92
|
+
constructor(file) {
|
|
93
|
+
this.file = file
|
|
94
|
+
this.state = undefined
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
read() {
|
|
98
|
+
const stamp = fileStamp(this.file)
|
|
99
|
+
if (this.state !== undefined && this.stamp === stamp) return this.state
|
|
100
|
+
const raw = readStateJson(this.file)
|
|
101
|
+
this.state = migrateLegacy(raw)
|
|
102
|
+
this.stamp = stamp
|
|
103
|
+
return this.state
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
write(state) {
|
|
107
|
+
this.state = { version: 2, tasks: state.tasks, subtasks: state.subtasks }
|
|
108
|
+
writeJson(this.file, this.state)
|
|
109
|
+
this.stamp = fileStamp(this.file)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Persist a legacy document as the current schema once. */
|
|
113
|
+
migrate() {
|
|
114
|
+
if (fs.existsSync(this.file) && readStateJson(this.file)?.version === 2) return false
|
|
115
|
+
return withFileLock(this.file, () => {
|
|
116
|
+
this.state = undefined
|
|
117
|
+
const state = this.read()
|
|
118
|
+
if (fs.existsSync(this.file)) fs.copyFileSync(this.file, `${this.file}.v1.bak`)
|
|
119
|
+
this.write(state)
|
|
120
|
+
return true
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Parent task API.
|
|
125
|
+
task(taskId) {
|
|
126
|
+
return this.read().tasks[taskId]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getTask(taskId) {
|
|
130
|
+
return this.task(taskId)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
listTasks(supervisor) {
|
|
134
|
+
return Object.values(this.read().tasks)
|
|
135
|
+
.filter(task => task.supervisor === supervisor)
|
|
136
|
+
.sort((left, right) => left.createdAt - right.createdAt)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
createTask({ supervisor, title, requestId = null }, now = Date.now()) {
|
|
140
|
+
if (!isSessionId(supervisor)) throw new Error('task requires a supervisor session')
|
|
141
|
+
return withFileLock(this.file, () => {
|
|
142
|
+
const id = `task-${crypto.randomUUID()}`
|
|
143
|
+
const task = {
|
|
144
|
+
id,
|
|
145
|
+
taskId: id,
|
|
146
|
+
supervisor,
|
|
147
|
+
title: String(title ?? 'Untitled task'),
|
|
148
|
+
status: 'open',
|
|
149
|
+
requestId: requestId ?? null,
|
|
150
|
+
createdAt: now,
|
|
151
|
+
closedAt: null,
|
|
152
|
+
}
|
|
153
|
+
this.state = undefined
|
|
154
|
+
const state = this.read()
|
|
155
|
+
state.tasks[id] = task
|
|
156
|
+
this.write(state)
|
|
157
|
+
return task
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
bindTask(taskId, requestId) {
|
|
162
|
+
return this.updateTask(taskId, (task) => {
|
|
163
|
+
if (task.requestId !== null && task.requestId !== requestId) {
|
|
164
|
+
throw new Error(`task is already bound to another request: ${String(task.requestId)}`)
|
|
165
|
+
}
|
|
166
|
+
task.requestId = requestId
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
updateTask(taskId, mutate, now = Date.now()) {
|
|
171
|
+
return withFileLock(this.file, () => {
|
|
172
|
+
this.state = undefined
|
|
173
|
+
const state = this.read()
|
|
174
|
+
const task = state.tasks[taskId]
|
|
175
|
+
if (task === undefined) throw new Error(`unknown task: ${String(taskId)}`)
|
|
176
|
+
mutate(task, now)
|
|
177
|
+
task.updatedAt = now
|
|
178
|
+
this.write(state)
|
|
179
|
+
return task
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
closeTask(taskId, now = Date.now()) {
|
|
184
|
+
return this.updateTask(taskId, (task) => {
|
|
185
|
+
if (task.status === 'closed') return
|
|
186
|
+
task.status = 'closed'
|
|
187
|
+
task.closedAt = now
|
|
188
|
+
}, now)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Subtask API. The old method names remain aliases for the Host tools.
|
|
192
|
+
get(subtaskId) {
|
|
193
|
+
return this.read().subtasks[subtaskId]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
getSubtask(subtaskId) {
|
|
197
|
+
return this.get(subtaskId)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
listForSupervisor(supervisor, status) {
|
|
201
|
+
return Object.values(this.read().subtasks)
|
|
202
|
+
.filter(task => task.supervisor === supervisor && (status === undefined || task.status === status))
|
|
203
|
+
.sort((left, right) => left.createdAt - right.createdAt)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
listSubtasksForTask(taskId, status) {
|
|
207
|
+
return Object.values(this.read().subtasks)
|
|
208
|
+
.filter(task => task.taskId === taskId && (status === undefined || task.status === status))
|
|
209
|
+
.sort((left, right) => left.createdAt - right.createdAt)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
listForWorker(worker, status) {
|
|
213
|
+
return Object.values(this.read().subtasks)
|
|
214
|
+
.filter(task => task.worker === worker && (status === undefined || task.status === status))
|
|
215
|
+
.sort((left, right) => left.createdAt - right.createdAt)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
activeCount(worker) {
|
|
219
|
+
return Object.values(this.read().subtasks)
|
|
220
|
+
.filter(task => task.worker === worker && ACTIVE_STATUSES.has(task.status)).length
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
activeTaskCount(taskId) {
|
|
224
|
+
return Object.values(this.read().subtasks)
|
|
225
|
+
.filter(task => task.taskId === taskId && ACTIVE_STATUSES.has(task.status)).length
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
createSubtask({
|
|
229
|
+
supervisor, worker, taskId, title, instruction, inputs = {}, acceptance = '', createdTurn = null,
|
|
230
|
+
}, now = Date.now()) {
|
|
231
|
+
if (!isSessionId(supervisor)) throw new Error('subtask requires a supervisor session')
|
|
232
|
+
if (worker !== null && worker !== undefined && !isSessionId(worker)) throw new Error('subtask requires a valid worker session')
|
|
233
|
+
if (typeof taskId !== 'string' || taskId.length === 0) throw new Error('subtask requires a task')
|
|
234
|
+
const id = `subtask-${crypto.randomUUID()}`
|
|
235
|
+
const subtask = {
|
|
236
|
+
id,
|
|
237
|
+
subtaskId: id,
|
|
238
|
+
taskId,
|
|
239
|
+
supervisor,
|
|
240
|
+
worker: worker ?? null,
|
|
241
|
+
title: String(title ?? '').trim() || 'Untitled subtask',
|
|
242
|
+
instruction: String(instruction ?? ''),
|
|
243
|
+
inputs: inputs !== null && typeof inputs === 'object' ? inputs : {},
|
|
244
|
+
acceptance: String(acceptance ?? ''),
|
|
245
|
+
status: 'created',
|
|
246
|
+
attempts: 0,
|
|
247
|
+
createdAt: now,
|
|
248
|
+
updatedAt: now,
|
|
249
|
+
createdTurn: Number.isInteger(createdTurn) ? createdTurn : null,
|
|
250
|
+
assignedTurn: null,
|
|
251
|
+
capabilityVersion: null,
|
|
252
|
+
result: null,
|
|
253
|
+
failure: null,
|
|
254
|
+
history: [],
|
|
255
|
+
}
|
|
256
|
+
return withFileLock(this.file, () => {
|
|
257
|
+
this.state = undefined
|
|
258
|
+
const state = this.read()
|
|
259
|
+
if (state.tasks[taskId] === undefined) throw new Error(`unknown task: ${taskId}`)
|
|
260
|
+
state.subtasks[id] = subtask
|
|
261
|
+
this.write(state)
|
|
262
|
+
return subtask
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
update(subtaskId, mutate, now = Date.now()) {
|
|
267
|
+
return withFileLock(this.file, () => {
|
|
268
|
+
this.state = undefined
|
|
269
|
+
const state = this.read()
|
|
270
|
+
const subtask = state.subtasks[subtaskId]
|
|
271
|
+
if (subtask === undefined) throw new Error(`unknown subtask: ${String(subtaskId)}`)
|
|
272
|
+
mutate(subtask, now)
|
|
273
|
+
subtask.updatedAt = now
|
|
274
|
+
this.write(state)
|
|
275
|
+
return subtask
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
assign(subtaskId, worker, assignedTurn, capabilityVersion, now = Date.now()) {
|
|
280
|
+
return this.update(subtaskId, (subtask) => {
|
|
281
|
+
if (subtask.worker !== null && subtask.worker !== worker) throw new Error('subtask is assigned to a different worker')
|
|
282
|
+
if (!['created', 'assigned', 'failed'].includes(subtask.status)) throw new Error(`subtask cannot be assigned from ${subtask.status}`)
|
|
283
|
+
subtask.worker = worker
|
|
284
|
+
subtask.status = 'assigned'
|
|
285
|
+
subtask.attempts += 1
|
|
286
|
+
subtask.failure = null
|
|
287
|
+
if (Number.isInteger(assignedTurn)) subtask.assignedTurn = assignedTurn
|
|
288
|
+
subtask.capabilityVersion = typeof capabilityVersion === 'string' ? capabilityVersion : subtask.capabilityVersion
|
|
289
|
+
subtask.history.push({ at: nowIso(now), status: 'assigned', note: `attempt ${String(subtask.attempts)}` })
|
|
290
|
+
}, now)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
accept(subtaskId, worker, now = Date.now()) {
|
|
294
|
+
return this.update(subtaskId, (subtask) => {
|
|
295
|
+
if (subtask.worker !== worker) throw new Error('subtask is assigned to a different worker')
|
|
296
|
+
if (!['assigned', 'accepted', 'running'].includes(subtask.status)) throw new Error(`subtask cannot be accepted from ${subtask.status}`)
|
|
297
|
+
if (subtask.status === 'assigned') subtask.status = 'accepted'
|
|
298
|
+
subtask.history.push({ at: nowIso(now), status: subtask.status, note: 'accepted' })
|
|
299
|
+
}, now)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
progress(subtaskId, worker, note, now = Date.now()) {
|
|
303
|
+
return this.update(subtaskId, (subtask) => {
|
|
304
|
+
if (subtask.worker !== worker) throw new Error('subtask is assigned to a different worker')
|
|
305
|
+
if (!ACTIVE_STATUSES.has(subtask.status)) throw new Error(`subtask is not active: ${subtask.status}`)
|
|
306
|
+
subtask.status = subtask.status === 'assigned' || subtask.status === 'accepted' ? 'running' : subtask.status
|
|
307
|
+
subtask.history.push({ at: nowIso(now), status: subtask.status, note: String(note ?? '') })
|
|
308
|
+
}, now)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
complete(subtaskId, worker, result, now = Date.now()) {
|
|
312
|
+
return this.update(subtaskId, (subtask) => {
|
|
313
|
+
if (subtask.worker !== worker) throw new Error('subtask is assigned to a different worker')
|
|
314
|
+
if (!ACTIVE_STATUSES.has(subtask.status)) throw new Error(`subtask cannot be completed from ${subtask.status}`)
|
|
315
|
+
subtask.status = 'done'
|
|
316
|
+
subtask.result = {
|
|
317
|
+
summary: String(result?.summary ?? ''),
|
|
318
|
+
details: String(result?.details ?? ''),
|
|
319
|
+
artifacts: Array.isArray(result?.artifacts)
|
|
320
|
+
? result.artifacts.filter(value => typeof value === 'string')
|
|
321
|
+
: [],
|
|
322
|
+
completedAt: nowIso(now),
|
|
323
|
+
}
|
|
324
|
+
subtask.history.push({ at: nowIso(now), status: 'done', note: 'completed by worker' })
|
|
325
|
+
}, now)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
fail(subtaskId, worker, reason, now = Date.now()) {
|
|
329
|
+
return this.update(subtaskId, (subtask) => {
|
|
330
|
+
if (subtask.worker !== worker) throw new Error('subtask is assigned to a different worker')
|
|
331
|
+
if (!ACTIVE_STATUSES.has(subtask.status)) throw new Error(`subtask cannot fail from ${subtask.status}`)
|
|
332
|
+
subtask.status = 'failed'
|
|
333
|
+
subtask.failure = String(reason ?? '')
|
|
334
|
+
subtask.history.push({ at: nowIso(now), status: 'failed', note: subtask.failure })
|
|
335
|
+
}, now)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
retry(subtaskId, now = Date.now()) {
|
|
339
|
+
return this.update(subtaskId, (subtask) => {
|
|
340
|
+
if (!['failed', 'cancelled', 'done'].includes(subtask.status)) throw new Error(`subtask cannot be retried from ${subtask.status}`)
|
|
341
|
+
subtask.status = 'created'
|
|
342
|
+
subtask.result = null
|
|
343
|
+
subtask.failure = null
|
|
344
|
+
subtask.history.push({ at: nowIso(now), status: 'created', note: 'retry requested by supervisor' })
|
|
345
|
+
}, now)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
reject(subtaskId, reason, now = Date.now()) {
|
|
349
|
+
return this.update(subtaskId, (subtask) => {
|
|
350
|
+
if (subtask.status !== 'done') throw new Error('only a completed subtask can be rejected')
|
|
351
|
+
subtask.status = 'assigned'
|
|
352
|
+
subtask.failure = String(reason ?? '')
|
|
353
|
+
subtask.result = null
|
|
354
|
+
subtask.history.push({ at: nowIso(now), status: 'assigned', note: `rejected: ${subtask.failure}` })
|
|
355
|
+
}, now)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
cancel(subtaskId, now = Date.now()) {
|
|
359
|
+
return this.update(subtaskId, (subtask) => {
|
|
360
|
+
if (!['created', 'assigned', 'accepted', 'running', 'failed'].includes(subtask.status)) throw new Error(`subtask cannot be cancelled from ${subtask.status}`)
|
|
361
|
+
subtask.status = 'cancelled'
|
|
362
|
+
subtask.history.push({ at: nowIso(now), status: 'cancelled', note: 'cancelled by supervisor' })
|
|
363
|
+
}, now)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Compatibility aliases used by the existing Host composition.
|
|
367
|
+
project(taskId) { return this.task(taskId) }
|
|
368
|
+
listProjects(supervisor) { return this.listTasks(supervisor) }
|
|
369
|
+
createProject({ supervisor, title }) { return this.createTask({ supervisor, title }) }
|
|
370
|
+
bindProject(taskId, requestId) { return this.bindTask(taskId, requestId) }
|
|
371
|
+
closeProject(taskId) { return this.closeTask(taskId) }
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
TaskStore.summary = subtaskSummary
|
|
375
|
+
TaskStore.taskSummary = taskSummary
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conservative write-target extraction for managed workers. This is a policy
|
|
3
|
+
* helper, not an OS sandbox; callers must still treat shell execution as a
|
|
4
|
+
* best-effort boundary.
|
|
5
|
+
*/
|
|
6
|
+
import path from 'node:path'
|
|
7
|
+
|
|
8
|
+
const shellWords = (value) => (String(value).match(/"[^"]*"|'[^']*'|[^\s;&|]+/gu) ?? [])
|
|
9
|
+
.map(word => word.replace(/^["']|["']$/gu, ''))
|
|
10
|
+
.filter(word => word.length > 0)
|
|
11
|
+
|
|
12
|
+
/** Conservative write-target extraction for managed workers. */
|
|
13
|
+
const shellWriteTargets = (command, cwd) => {
|
|
14
|
+
const targets = []
|
|
15
|
+
const add = (value) => {
|
|
16
|
+
if (typeof value !== 'string' || value.length === 0 || value.startsWith('-')) return
|
|
17
|
+
targets.push(path.resolve(cwd, value))
|
|
18
|
+
}
|
|
19
|
+
const text = String(command)
|
|
20
|
+
for (const match of text.matchAll(/\b(?:cd|pushd)\s+("[^"]+"|'[^']+'|[^\s;&|]+)/gu)) {
|
|
21
|
+
const target = match[1].replace(/^["']|["']$/gu, '')
|
|
22
|
+
if (target === '-' || target.startsWith('-')) continue
|
|
23
|
+
if (path.resolve(cwd, target) === path.resolve(cwd)) continue
|
|
24
|
+
add(target)
|
|
25
|
+
}
|
|
26
|
+
for (const match of text.matchAll(/(?:^|[^>&])>{1,2}\s*("[^"]+"|'[^']+'|[^\s;&|]+)/gu)) {
|
|
27
|
+
const target = match[1].replace(/^["']|["']$/gu, '')
|
|
28
|
+
if (!target.startsWith('&')) add(target)
|
|
29
|
+
}
|
|
30
|
+
for (const match of text.matchAll(/\b(cp|mv|install|rsync|ln|tee|touch|mkdir|rm|rmdir|truncate|dd|chmod|chown)\b([^;&|]*)/giu)) {
|
|
31
|
+
const verb = match[1].toLowerCase()
|
|
32
|
+
const words = shellWords(match[2]).filter(word => !word.startsWith('-'))
|
|
33
|
+
if (verb === 'dd') {
|
|
34
|
+
const of = words.find(word => word.startsWith('of='))
|
|
35
|
+
if (of !== undefined) add(of.slice(3))
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
if (verb === 'tee' || verb === 'touch' || verb === 'mkdir' || verb === 'rm' || verb === 'rmdir' || verb === 'truncate' || verb === 'chmod' || verb === 'chown') {
|
|
39
|
+
for (const word of words) {
|
|
40
|
+
if (verb === 'chmod' && /^[0-7]{3,4}$/u.test(word)) continue
|
|
41
|
+
add(word)
|
|
42
|
+
}
|
|
43
|
+
continue
|
|
44
|
+
}
|
|
45
|
+
if (words.length > 0) add(words[words.length - 1])
|
|
46
|
+
}
|
|
47
|
+
for (const match of text.matchAll(/\bsed\b([^;&|]*)/giu)) {
|
|
48
|
+
if (!/(?:^|\s)-i(?:\s|$)/u.test(match[1])) continue
|
|
49
|
+
const words = shellWords(match[1]).filter(word => !word.startsWith('-') && !word.startsWith('s/') && !word.startsWith('s#'))
|
|
50
|
+
for (const word of words) add(word)
|
|
51
|
+
}
|
|
52
|
+
// PowerShell write cmdlets. DSH uses pwsh instead of bash on Windows; the
|
|
53
|
+
// parser is deliberately conservative and only claims destinations.
|
|
54
|
+
const psWrites = /\b(Set-Content|Add-Content|Out-File|New-Item|Copy-Item|Move-Item|Rename-Item|Remove-Item|Clear-Content|Set-Item|New-ItemProperty|Tee-Object|Export-Csv|Start-Transcript|Invoke-WebRequest|Invoke-RestMethod)\b([^;&|]*)/giu
|
|
55
|
+
for (const match of text.matchAll(psWrites)) {
|
|
56
|
+
const verb = match[1].toLowerCase()
|
|
57
|
+
const words = shellWords(match[2])
|
|
58
|
+
const isCopyLike = verb === 'copy-item' || verb === 'move-item' || verb === 'rename-item'
|
|
59
|
+
const namedFlags = isCopyLike
|
|
60
|
+
? new Set(['-destination', '-newpath', '-newname'])
|
|
61
|
+
: new Set(['-path', '-filepath', '-literalpath', '-destination', '-outfile'])
|
|
62
|
+
let named = false
|
|
63
|
+
for (let index = 0; index < words.length; index += 1) {
|
|
64
|
+
if (!namedFlags.has(words[index].toLowerCase())) continue
|
|
65
|
+
const value = words[index + 1]
|
|
66
|
+
if (value !== undefined) { add(value); named = true }
|
|
67
|
+
}
|
|
68
|
+
if (named) continue
|
|
69
|
+
const positional = words.filter(word => !word.startsWith('-'))
|
|
70
|
+
if (positional.length === 0) continue
|
|
71
|
+
if (verb === 'copy-item' || verb === 'move-item' || verb === 'rename-item') {
|
|
72
|
+
add(positional[positional.length - 1])
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
for (const word of positional) {
|
|
76
|
+
if (verb === 'remove-item' || verb === 'clear-content') add(word)
|
|
77
|
+
else { add(word); break }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const match of text.matchAll(/\[(?:System\.)?IO\.File\]::(?:WriteAllText|WriteAllBytes|WriteAllLines|AppendAllText|AppendAllLines)\s*\(\s*["']([^"']+)["']/giu)) {
|
|
81
|
+
add(match[1])
|
|
82
|
+
}
|
|
83
|
+
return targets
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const applyPatchTargets = (patch, cwd) => {
|
|
87
|
+
const targets = []
|
|
88
|
+
for (const match of String(patch).matchAll(/^\*\*\* (?:Add File|Update File|Delete File|Move to): (.+)$/gmu)) {
|
|
89
|
+
const value = match[1].trim()
|
|
90
|
+
if (value.length > 0) targets.push(path.resolve(cwd, value))
|
|
91
|
+
}
|
|
92
|
+
return targets
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export { shellWords, shellWriteTargets, applyPatchTargets }
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Collab sessions",
|
|
4
|
+
"description": "Adds a Collab control to the left sidebar's New-session row, a Collab access panel with bilateral session-pair authorization, and a per-session base prompt editor. The base prompt is injected at the top of the collaboration prompt on every turn for role/constraint instructions; configure it from the new-session 设置提示词 button, the session right-click menu, or the session header's More menu. Only collab sessions can message each other, and authorization requires both sides. Messages are HMAC-authenticated; a cold target is resumed, a live target is woken, and the browser activates the target's page when it starts running. Another session's whole work directory is denied by a DSH tool guard. This is a session-level guard, not an OS sandbox. Disabling the bundle removes the control, panel, preset, tools, guard, and prompt sections; session data, authorization, and base prompts stay on disk."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "协同会话",
|
|
4
|
+
"description": "在左侧栏“新建会话”行新增“协同”入口,新增带双向会话对授权的“协同授权”面板,以及每个协同会话独立的会话提示词编辑器。会话提示词会在每一轮注入协同提示词顶部,可用于角色和约束;可从左侧工作区会话行的“更多”菜单配置。只有协同会话支持相互通信,且必须双方授权。消息带 HMAC 凭证;目标离线时自动恢复,在线时被唤起,目标开始运行时浏览器自动切到它的页面。其他会话访问本会话的整个工作目录会被 DSH 工具守卫拒绝。这是会话级守卫,不是操作系统沙箱。禁用该插件会移除入口、面板、预设、工具、守卫与提示词段落;会话数据、授权与会话提示词仍保留在磁盘。"
|
|
5
|
+
}
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmodelin/dsh-collab-sessions",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Left-sidebar entry that creates collaboration sessions with a private/communication workspace layout and session-to-session messaging.",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./index.js",
|
|
8
|
+
"./client": "./client.js",
|
|
9
|
+
"./locale/*.json": "./locale/*.json",
|
|
10
|
+
"./icon": "./icon.svg"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.js",
|
|
14
|
+
"client.js",
|
|
15
|
+
"lib",
|
|
16
|
+
"cordis.patch.yml",
|
|
17
|
+
"locale/*.json",
|
|
18
|
+
"icon.svg",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"dsh": {
|
|
22
|
+
"bundle": {
|
|
23
|
+
"patch": "./cordis.patch.yml"
|
|
24
|
+
},
|
|
25
|
+
"client": {
|
|
26
|
+
"platform": "web",
|
|
27
|
+
"immediately": true,
|
|
28
|
+
"inject": [
|
|
29
|
+
"@deepseek-ai/dsh-api-remotes",
|
|
30
|
+
"@deepseek-ai/dsh-api-session-controller",
|
|
31
|
+
"@deepseek-ai/dsh-client-ui-commands",
|
|
32
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
33
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
34
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
35
|
+
"@deepseek-ai/dsh-client-ui-workspace",
|
|
36
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
37
|
+
"@xmodelin/dsh-collab-auth-api"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "node --test test/*.test.mjs",
|
|
43
|
+
"test:browser": "node --test test/browser.smoke.mjs"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/colinchan666/dsh-plugins-collab-agent.git",
|
|
51
|
+
"directory": "dsh-collab"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/colinchan666/dsh-plugins-collab-agent#readme",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/colinchan666/dsh-plugins-collab-agent/issues"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"dsh": "^0.2.2-rc.5"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@xmodelin/dsh-collab-auth-api": "0.0.1"
|
|
62
|
+
}
|
|
63
|
+
}
|