@xmodelin/dsh-collab-sessions 0.0.2 → 0.0.4
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 +23 -0
- package/client.js +80 -57
- package/index.js +172 -511
- package/lib/access-policy.js +71 -0
- package/lib/audit.js +34 -0
- package/lib/cancel-request.js +11 -0
- package/lib/delivery-manifest.js +63 -0
- package/lib/health.js +29 -0
- package/lib/panel-api.js +12 -0
- package/lib/presets.js +4 -0
- package/lib/prompt.js +107 -0
- package/lib/task-aliases.js +61 -0
- package/lib/task-views.js +26 -0
- package/lib/tasks.js +0 -5
- package/lib/tool-schemas.js +220 -0
- package/package.json +2 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** Delivery and shared-root access policy for the collaboration guard. */
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { canonicalPath } from './layout.js'
|
|
5
|
+
|
|
6
|
+
export function createAccessPolicy({
|
|
7
|
+
sharedRoot, sessionId, selfWorkdir, layoutWorkdir, tasks, requests, isSupervisorSession, isManagedWorker,
|
|
8
|
+
}) {
|
|
9
|
+
const comparablePath = value => {
|
|
10
|
+
const resolved = path.resolve(value)
|
|
11
|
+
return process.platform === 'win32' ? resolved.toLowerCase() : resolved
|
|
12
|
+
}
|
|
13
|
+
const pathInside = (candidate, root) => {
|
|
14
|
+
const resolvedCandidate = comparablePath(candidate)
|
|
15
|
+
const resolvedRoot = comparablePath(root)
|
|
16
|
+
return resolvedCandidate === resolvedRoot || resolvedCandidate.startsWith(`${resolvedRoot}${path.sep}`)
|
|
17
|
+
}
|
|
18
|
+
const canonicalSharedRoot = canonicalPath(sharedRoot)
|
|
19
|
+
const taskIdFromShared = (resolved) => {
|
|
20
|
+
if (!pathInside(resolved, canonicalSharedRoot)) return undefined
|
|
21
|
+
const relative = path.relative(canonicalSharedRoot, resolved).split(path.sep).filter(Boolean)
|
|
22
|
+
if (relative.length < 2 || relative[1] !== 'artifacts') return undefined
|
|
23
|
+
return relative[0]
|
|
24
|
+
}
|
|
25
|
+
const deliveryAccessFor = (candidate, write) => {
|
|
26
|
+
if (typeof candidate !== 'string' || candidate.length === 0) return false
|
|
27
|
+
const resolved = canonicalPath(path.resolve(selfWorkdir, candidate))
|
|
28
|
+
const taskId = taskIdFromShared(resolved)
|
|
29
|
+
if (taskId === undefined) return false
|
|
30
|
+
const task = tasks.task(taskId)
|
|
31
|
+
if (task === undefined) return false
|
|
32
|
+
if (isSupervisorSession(sessionId)) return task.supervisor === sessionId && write !== true
|
|
33
|
+
if (isManagedWorker(sessionId)) {
|
|
34
|
+
if (write && task.status !== 'open') return false
|
|
35
|
+
return tasks.listForWorker(sessionId).some(subtask => (
|
|
36
|
+
subtask.taskId === taskId && subtask.supervisor === task.supervisor
|
|
37
|
+
))
|
|
38
|
+
}
|
|
39
|
+
if (write) return false
|
|
40
|
+
return requests.listForRequester(sessionId).some(request => (
|
|
41
|
+
request.taskId === taskId
|
|
42
|
+
&& (request.status === 'delivered' || (request.status === 'accepted' && request.delivery !== null))
|
|
43
|
+
&& task.requestId === request.id
|
|
44
|
+
&& request.delivery !== null
|
|
45
|
+
))
|
|
46
|
+
}
|
|
47
|
+
const sharedAccessDenied = (candidates, write) => {
|
|
48
|
+
for (const candidate of candidates) {
|
|
49
|
+
if (typeof candidate !== 'string' || candidate.length === 0) continue
|
|
50
|
+
const lexical = path.resolve(selfWorkdir, candidate)
|
|
51
|
+
const resolved = canonicalPath(lexical)
|
|
52
|
+
if (!pathInside(lexical, sharedRoot) && !pathInside(resolved, canonicalSharedRoot)) continue
|
|
53
|
+
if (pathInside(lexical, sharedRoot) && !pathInside(resolved, canonicalSharedRoot)) return { path: lexical }
|
|
54
|
+
if (deliveryAccessFor(candidate, write)) continue
|
|
55
|
+
return { path: lexical }
|
|
56
|
+
}
|
|
57
|
+
return undefined
|
|
58
|
+
}
|
|
59
|
+
const managedWriteAllowed = (candidate) => {
|
|
60
|
+
if (!isManagedWorker(sessionId)) return true
|
|
61
|
+
if (typeof candidate !== 'string' || candidate.length === 0) return false
|
|
62
|
+
const resolved = canonicalPath(path.resolve(selfWorkdir, candidate))
|
|
63
|
+
if (deliveryAccessFor(candidate, true)) return true
|
|
64
|
+
for (const own of [path.join(layoutWorkdir ?? selfWorkdir, 'private'), path.join(layoutWorkdir ?? selfWorkdir, 'comm')]) {
|
|
65
|
+
if (pathInside(resolved, canonicalPath(own))) return true
|
|
66
|
+
}
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
const allowedDeliveryPaths = (candidates, write) => candidates.filter(candidate => !deliveryAccessFor(candidate, write))
|
|
70
|
+
return { deliveryAccessFor, sharedAccessDenied, managedWriteAllowed, allowedDeliveryPaths }
|
|
71
|
+
}
|
package/lib/audit.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Append-only collaboration audit log for human and supervisor actions. */
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { mkdirp, withFileLock } from './layout.js'
|
|
6
|
+
|
|
7
|
+
export class AuditLog {
|
|
8
|
+
constructor(file) {
|
|
9
|
+
this.file = file
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
append(event, fields = {}) {
|
|
13
|
+
try {
|
|
14
|
+
mkdirp(path.dirname(this.file), 0o700)
|
|
15
|
+
withFileLock(this.file, () => {
|
|
16
|
+
fs.appendFileSync(this.file, `${JSON.stringify({ at: Date.now(), event, ...fields })}\n`, { mode: 0o600 })
|
|
17
|
+
})
|
|
18
|
+
} catch {
|
|
19
|
+
// Audit is advisory; a full read-only disk must not break collaboration.
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
tail(limit = 100) {
|
|
24
|
+
try {
|
|
25
|
+
const lines = fs.readFileSync(this.file, 'utf8').trim().split('\n').filter(Boolean)
|
|
26
|
+
return lines.slice(Math.max(0, lines.length - Math.max(1, Math.min(limit, 500))))
|
|
27
|
+
.map(line => {
|
|
28
|
+
try { return JSON.parse(line) } catch { return { event: 'audit.invalid', raw: line } }
|
|
29
|
+
})
|
|
30
|
+
} catch {
|
|
31
|
+
return []
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Cancel every remaining subtask of a task and close it. */
|
|
2
|
+
export function cancelBoundTask(tasks, taskId, releaseWorker = () => {}) {
|
|
3
|
+
const subtasks = tasks.listSubtasksForTask(taskId)
|
|
4
|
+
for (const subtask of subtasks) {
|
|
5
|
+
if (!['done', 'cancelled'].includes(subtask.status)) {
|
|
6
|
+
try { tasks.cancel(subtask.id) } catch { /* best effort after request cancellation */ }
|
|
7
|
+
}
|
|
8
|
+
if (subtask.worker !== null) releaseWorker(subtask.worker)
|
|
9
|
+
}
|
|
10
|
+
try { return tasks.closeTask(taskId) } catch { return undefined }
|
|
11
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Canonical delivery manifest and opaque alias publication. */
|
|
2
|
+
export function createDeliveryManifestService({
|
|
3
|
+
sharedRoot, tasks, fs, path, crypto, mkdirp, writeJson, listDeliveryFiles, warn, maxFiles = 2000,
|
|
4
|
+
}) {
|
|
5
|
+
const rootFor = taskId => path.join(sharedRoot, taskId ?? 'default', 'artifacts')
|
|
6
|
+
|
|
7
|
+
const buildDeliveryManifest = (taskId) => {
|
|
8
|
+
const task = tasks.task(taskId)
|
|
9
|
+
if (task === undefined) throw new Error('unknown task')
|
|
10
|
+
const root = rootFor(taskId)
|
|
11
|
+
const listed = listDeliveryFiles(root)
|
|
12
|
+
if (listed.truncated === true) throw new Error(`delivery has more than ${maxFiles} files; split the task`)
|
|
13
|
+
const files = listed.sort((left, right) => left.path.localeCompare(right.path)).map(file => {
|
|
14
|
+
const full = path.join(root, file.path)
|
|
15
|
+
const before = fs.statSync(full)
|
|
16
|
+
const content = fs.readFileSync(full)
|
|
17
|
+
const after = fs.statSync(full)
|
|
18
|
+
if (before.size !== after.size || before.mtimeMs !== after.mtimeMs) {
|
|
19
|
+
throw new Error(`delivery file changed while hashing: ${file.path}`)
|
|
20
|
+
}
|
|
21
|
+
const hash = crypto.createHash('sha256').update(content).digest('hex')
|
|
22
|
+
return {
|
|
23
|
+
path: file.path.split(path.sep).join('/'),
|
|
24
|
+
bytes: after.size,
|
|
25
|
+
sha256: hash,
|
|
26
|
+
mode: `0${(after.mode & 0o777).toString(8)}`,
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
const manifest = {
|
|
30
|
+
generatedAt: new Date().toISOString(),
|
|
31
|
+
root,
|
|
32
|
+
files,
|
|
33
|
+
}
|
|
34
|
+
const taskDir = path.join(sharedRoot, taskId)
|
|
35
|
+
mkdirp(taskDir, 0o755)
|
|
36
|
+
const manifestPath = path.join(taskDir, 'manifest.json')
|
|
37
|
+
const temporary = `${manifestPath}.${crypto.randomBytes(4).toString('hex')}.tmp`
|
|
38
|
+
writeJson(temporary, manifest, 0o644)
|
|
39
|
+
fs.renameSync(temporary, manifestPath)
|
|
40
|
+
return manifest
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const publishDeliveryAlias = (taskId, deliveryId) => {
|
|
44
|
+
const target = rootFor(taskId)
|
|
45
|
+
const aliasRoot = path.join(sharedRoot, '.deliveries', deliveryId)
|
|
46
|
+
const alias = path.join(aliasRoot, 'artifacts')
|
|
47
|
+
mkdirp(aliasRoot, 0o755)
|
|
48
|
+
try {
|
|
49
|
+
const existing = fs.lstatSync(alias)
|
|
50
|
+
if (existing.isSymbolicLink() && fs.realpathSync(alias) === fs.realpathSync(target)) return alias
|
|
51
|
+
fs.rmSync(alias, { recursive: true, force: true })
|
|
52
|
+
} catch { /* alias does not exist yet */ }
|
|
53
|
+
try {
|
|
54
|
+
fs.symlinkSync(target, alias, 'dir')
|
|
55
|
+
return alias
|
|
56
|
+
} catch (error) {
|
|
57
|
+
warn(`delivery alias could not be published: ${String(error)}`)
|
|
58
|
+
return target
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { buildDeliveryManifest, publishDeliveryAlias }
|
|
63
|
+
}
|
package/lib/health.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Pure read-only collaboration health projection used by collab_doctor. */
|
|
2
|
+
export function collectHealth({
|
|
3
|
+
sessionId, registryEntries, relationships, grants, tasks, requests, auditEntries, isSupervisor,
|
|
4
|
+
}) {
|
|
5
|
+
const presetOf = id => registryEntries.find(entry => entry.sessionId === id)?.preset
|
|
6
|
+
const invalidRelationships = relationships.filter(relationship => (
|
|
7
|
+
presetOf(relationship.worker) !== 'collab'
|
|
8
|
+
|| presetOf(relationship.supervisor) !== 'supervisor'
|
|
9
|
+
))
|
|
10
|
+
const invalidGrants = grants.filter(grant => (
|
|
11
|
+
(presetOf(grant.from) !== undefined && presetOf(grant.from) !== 'collab' && presetOf(grant.from) !== 'supervisor')
|
|
12
|
+
|| (presetOf(grant.to) !== undefined && presetOf(grant.to) !== 'collab' && presetOf(grant.to) !== 'supervisor')
|
|
13
|
+
))
|
|
14
|
+
const tasksForSelf = isSupervisor ? tasks : []
|
|
15
|
+
const requestsForSelf = requests.filter(request => request.supervisor === sessionId || request.requester === sessionId)
|
|
16
|
+
return {
|
|
17
|
+
sessionId,
|
|
18
|
+
registry: registryEntries.length,
|
|
19
|
+
relationships: relationships.length,
|
|
20
|
+
invalidRelationships: invalidRelationships.length,
|
|
21
|
+
grants: grants.length,
|
|
22
|
+
invalidGrants: invalidGrants.length,
|
|
23
|
+
tasks: tasksForSelf.length,
|
|
24
|
+
activeTasks: tasksForSelf.filter(task => task.status === 'open').length,
|
|
25
|
+
requests: requestsForSelf.length,
|
|
26
|
+
activeRequests: requestsForSelf.filter(request => request.status === 'accepted').length,
|
|
27
|
+
auditEntries,
|
|
28
|
+
}
|
|
29
|
+
}
|
package/lib/panel-api.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Typed facade over the JSON panel transport used by the Host Remote. */
|
|
2
|
+
export function createPanelApi(panel) {
|
|
3
|
+
return {
|
|
4
|
+
board: sessionId => panel(sessionId, 'board', {}),
|
|
5
|
+
link: (sessionId, worker, payload) => panel(sessionId, 'link', { worker, payload }),
|
|
6
|
+
unlink: (sessionId, worker) => panel(sessionId, 'unlink', { worker }),
|
|
7
|
+
pin: (sessionId, worker) => panel(sessionId, 'pin', { worker }),
|
|
8
|
+
live: (sessionId, worker) => panel(sessionId, 'live', { worker }),
|
|
9
|
+
baseGet: sessionId => panel(sessionId, 'baseGet', {}),
|
|
10
|
+
baseSet: (sessionId, value) => panel(sessionId, 'baseSet', { value }),
|
|
11
|
+
}
|
|
12
|
+
}
|
package/lib/presets.js
ADDED
package/lib/prompt.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** Prompt section for collaboration and supervisor sessions. */
|
|
2
|
+
export function promptText(sessionId, layout, role, relationships, capabilityLines = []) {
|
|
3
|
+
const basePrompt = typeof layout.meta.basePrompt === 'string' ? layout.meta.basePrompt.trim() : ''
|
|
4
|
+
const baseSection = basePrompt.length === 0
|
|
5
|
+
? []
|
|
6
|
+
: ['Session base prompt (role and constraints for this session; apply it to every turn):', basePrompt, '']
|
|
7
|
+
const header = [
|
|
8
|
+
...baseSection,
|
|
9
|
+
`This is ${role === 'supervisor' ? 'supervisor' : 'collaboration'} session ${sessionId}.`,
|
|
10
|
+
`Its working directory is ${layout.workdir}; it contains exactly two collaboration directories:`,
|
|
11
|
+
`- comm/<peerSessionId>/ holds credential.json plus inbox/ (unread inbound), outbox/ (sent), archive/inbox/ (read inbound), and archive/outbox/ (explicitly archived sent).`,
|
|
12
|
+
`- private/ belongs only to this session; it is mode 0700.`,
|
|
13
|
+
`Never read, write, search, or infer another session's working directory (comm or private): the tool guard denies it.`,
|
|
14
|
+
`Recursive searches and shells rooted above another session's working directory are also refused; use the task tools instead.`,
|
|
15
|
+
`Workspace: ${layout.meta.originalCwd}.`,
|
|
16
|
+
'',
|
|
17
|
+
]
|
|
18
|
+
if (role === 'supervisor') {
|
|
19
|
+
return [
|
|
20
|
+
...header,
|
|
21
|
+
...(capabilityLines.length === 0 ? [] : [
|
|
22
|
+
'Current registered capabilities (live; re-check before decomposition):',
|
|
23
|
+
...capabilityLines,
|
|
24
|
+
'',
|
|
25
|
+
]),
|
|
26
|
+
'You are the SUPERVISOR. You do not implement anything yourself.',
|
|
27
|
+
'You only decompose requirements, assign tasks to registered functional sessions, verify results, retry/reject, and deliver.',
|
|
28
|
+
'You have no shell, file, office, web, or edit tools. Never try to perform a task yourself.',
|
|
29
|
+
'',
|
|
30
|
+
'Coordination tools:',
|
|
31
|
+
'- collab_inbox reads messages from any authorized peer, including task/request notifications. Call it at the start of every turn.',
|
|
32
|
+
'- collab_peers / collab_send are ordinary communication tools for authorized peers. Chat does not create or change tasks.',
|
|
33
|
+
'- collab_requests lists work requests. For each pending request, evaluate registered capabilities before accepting or rejecting.',
|
|
34
|
+
'- collab_capabilities lists the functional sessions registered to you, their capabilities, online/authorization state, and workload.',
|
|
35
|
+
'- collab_task_open creates the parent task for one requirement.',
|
|
36
|
+
'- collab_task_list lists parent tasks.',
|
|
37
|
+
'- collab_subtask_create creates a subtask under that parent task.',
|
|
38
|
+
'- collab_subtask_assign assigns a subtask to an offered worker.',
|
|
39
|
+
'- collab_subtasks lists subtasks for the supervisor or worker.',
|
|
40
|
+
'- collab_task_create creates a subtask under that task.',
|
|
41
|
+
'- collab_task_assign assigns a task to a worker with an offer relationship and wakes it.',
|
|
42
|
+
'- collab_tasks / collab_task_result inspect progress and results.',
|
|
43
|
+
'- collab_task_retry / collab_task_reject / collab_task_cancel manage failures and revisions.',
|
|
44
|
+
'- collab_task_close closes a task after all its subtasks finish.',
|
|
45
|
+
'- collab_delivery_list lists the canonical shared delivery files (names/sizes/times).',
|
|
46
|
+
'- collab_delivery_manifest writes a task manifest with path, bytes, sha256, and mode.',
|
|
47
|
+
'- collab_request_deliver sends the sanitized manifest to an accepted requester.',
|
|
48
|
+
'',
|
|
49
|
+
'How to work:',
|
|
50
|
+
'0. At the start of every turn, read collab_requests. For each pending request, evaluate the registered capabilities. If the request is feasible, create a task and subtasks, assign at least one subtask to an offered worker, then call collab_request_accept with the taskId. If it is not feasible, call collab_request_reject and name the missing capability. Never implement the request yourself.',
|
|
51
|
+
'Never send task IDs, subtask IDs, worker IDs, task decomposition, or internal scheduling to the requester. The requester receives only acceptance/rejection status and the sanitized delivery manifest.',
|
|
52
|
+
'1. Read the requirement, list capabilities, and plan subtasks with explicit acceptance criteria. Call collab_task_open once per requirement, then pass its taskId to every collab_subtask_create call.',
|
|
53
|
+
'Capabilities are live and versioned. Call collab_capabilities immediately before decomposing tasks; never rely on capability text remembered from an earlier turn. If a capability version changed, re-evaluate the decomposition.',
|
|
54
|
+
'2. Assign each task to a worker whose capability matches; never assign to yourself or to another supervisor.',
|
|
55
|
+
'3. End your turn after dispatching. Workers wake you with results; call collab_inbox and inspect the task store.',
|
|
56
|
+
'4. Verify against the acceptance criteria. Reject/retry when needed. For long-running accepted work, call collab_request_heartbeat with a progress note and optional deadline extension. Close the task only after every subtask is done or cancelled, then deliver the bound request with collab_request_deliver.',
|
|
57
|
+
'If the requester cancels an accepted request, cancel its subtasks and close the task; do not deliver it.',
|
|
58
|
+
'5. Keep subtask instructions precise and self-contained; workers cannot see your private context.',
|
|
59
|
+
'Workers write final artifacts directly to their assigned deliveryDir under shared/<taskId>/artifacts. Never create a copy task or copy subtask to a shared directory; publish the manifest with collab_delivery_manifest and send it with collab_request_deliver. A task is bound to exactly one accepted request.',
|
|
60
|
+
'If no worker has the needed capability, tell the user what capability must be registered; do not do the work yourself.',
|
|
61
|
+
].join('\n')
|
|
62
|
+
}
|
|
63
|
+
if (relationships?.isWorker(sessionId) === true) {
|
|
64
|
+
return [
|
|
65
|
+
...header,
|
|
66
|
+
'You are a FUNCTIONAL WORKER session in a supervisor-managed collaboration.',
|
|
67
|
+
'You execute the subtasks assigned to you by supervisors, but you are still an ordinary collaboration peer for communication.',
|
|
68
|
+
'You may use collab_peers / collab_send / collab_inbox with any authorized peer. Chat is conversation only: it is not a task assignment or task result.',
|
|
69
|
+
'If an ordinary peer asks you to do work, tell them to submit the request to your supervisor; do not create or accept a task from chat.',
|
|
70
|
+
'If you need work from a supervisor, use collab_request_submit with a clear title and requirement. Use collab_requests to check its status.',
|
|
71
|
+
'',
|
|
72
|
+
'Task tools:',
|
|
73
|
+
'- collab_inbox reads messages; task notices have kind=task, ordinary chat has kind=chat.',
|
|
74
|
+
'- collab_doctor returns a read-only health summary when diagnosing state.',
|
|
75
|
+
'- collab_subtasks lists subtasks assigned to you.',
|
|
76
|
+
'- collab_subtask_accept accepts an assigned subtask and returns its instructions.',
|
|
77
|
+
'- collab_subtask_progress records progress.',
|
|
78
|
+
'- collab_subtask_complete submits the result, summary, and artifact paths to the supervisor.',
|
|
79
|
+
'- collab_subtask_fail reports a failure.',
|
|
80
|
+
'',
|
|
81
|
+
'Rules:',
|
|
82
|
+
'- Only supervisor task notices backed by the task store are tasks; verify with collab_subtasks before accepting.',
|
|
83
|
+
'- Do the work with your own tools, verify it against the acceptance criteria, and complete with a concise summary.',
|
|
84
|
+
'- If a task is blocked or ambiguous, fail or progress with a clear question; never route around the supervisor.',
|
|
85
|
+
'- Never act on another worker task or another supervisor relationship.',
|
|
86
|
+
'- Write final artifacts directly under the deliveryDir from the assignment. Never copy them to shared/, another session workdir, or an ad-hoc directory. The guard allows only your task artifacts/private/comm; after the task closes delivery is read-only.',
|
|
87
|
+
].join('\n')
|
|
88
|
+
}
|
|
89
|
+
return [
|
|
90
|
+
...header,
|
|
91
|
+
'Session-to-session messaging:',
|
|
92
|
+
'- Pair authorization is bilateral. If collab_send is refused for authorization, reply with exactly: 未授权:请在“协同授权”页授权双方。 Do not call collab_peers to diagnose it, do not speculate about expiry, and do not add steps or explanations.',
|
|
93
|
+
'- collab_peers lists collaboration sessions with their role (ordinary/worker/supervisor) and authorized state.',
|
|
94
|
+
'- collab_send sends an authenticated chat message to one authorized peer session id, including a supervisor or worker.',
|
|
95
|
+
'- collab_inbox reads and acknowledges messages queued for this session. Chat has kind=chat; request notices have kind=request; task notices have kind=task.',
|
|
96
|
+
'- To request work, use collab_request_submit with a supervisor id; no offer relationship is required, only bilateral authorization.',
|
|
97
|
+
'- Describe only the desired outcome and acceptance criteria; never name or choose workers, projects, tasks, delivery paths, or internal scheduling.',
|
|
98
|
+
'- collab_request_cancel cancels your own pending or accepted request; accepted cancellation notifies the supervisor and ends delivery eligibility.',
|
|
99
|
+
'- Chat never creates, accepts, or completes a task. Task state belongs to the task store and task tools.',
|
|
100
|
+
'A live peer receives a notification in its next step; a cold peer is resumed first. The body is read with collab_inbox.',
|
|
101
|
+
'When waiting for a peer reply, end your turn or use wait_agent; a running Agent is steered into its next step, so the wait returns promptly.',
|
|
102
|
+
'Reply with collab_send to the sender session id.',
|
|
103
|
+
'Keep credentials in comm/<peer>/credential.json and never paste a token into a message or a private file.',
|
|
104
|
+
].join('\n')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The original project directory is the immutable header cwd. */
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Build the public subtask aliases from the legacy task tool definitions. */
|
|
2
|
+
export function subtaskAliases(taskTools) {
|
|
3
|
+
const taskTool = name => taskTools.find(tool => tool.name === name)
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
...taskTool('collab_task_create'),
|
|
7
|
+
name: 'collab_subtask_create',
|
|
8
|
+
description: 'Create a subtask under an existing parent task.',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
...taskTool('collab_task_assign'),
|
|
12
|
+
name: 'collab_subtask_assign',
|
|
13
|
+
description: 'Assign a subtask to a worker with an offer relationship and wake it.',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
...taskTool('collab_tasks'),
|
|
17
|
+
name: 'collab_subtasks',
|
|
18
|
+
description: 'List subtasks for this supervisor or the subtasks assigned to the calling worker.',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
...taskTool('collab_task_result'),
|
|
22
|
+
name: 'collab_subtask_result',
|
|
23
|
+
description: 'Read one subtask detail and result.',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
...taskTool('collab_task_retry'),
|
|
27
|
+
name: 'collab_subtask_retry',
|
|
28
|
+
description: 'Retry a failed, cancelled, or completed subtask.',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
...taskTool('collab_task_reject'),
|
|
32
|
+
name: 'collab_subtask_reject',
|
|
33
|
+
description: 'Reject a completed subtask and send it back to its worker.',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
...taskTool('collab_task_cancel'),
|
|
37
|
+
name: 'collab_subtask_cancel',
|
|
38
|
+
description: 'Cancel a subtask.',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
...taskTool('collab_task_accept'),
|
|
42
|
+
name: 'collab_subtask_accept',
|
|
43
|
+
description: 'Accept an assigned subtask and return its instructions.',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
...taskTool('collab_task_progress'),
|
|
47
|
+
name: 'collab_subtask_progress',
|
|
48
|
+
description: 'Record progress on an accepted subtask.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
...taskTool('collab_task_complete'),
|
|
52
|
+
name: 'collab_subtask_complete',
|
|
53
|
+
description: 'Complete a subtask and notify its supervisor with the result.',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
...taskTool('collab_task_fail'),
|
|
57
|
+
name: 'collab_subtask_fail',
|
|
58
|
+
description: 'Report a subtask failure to its supervisor.',
|
|
59
|
+
},
|
|
60
|
+
]
|
|
61
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Compact and detailed task views shared by the Host tools. */
|
|
2
|
+
export function taskLine(task) {
|
|
3
|
+
return `- ${task.id} [${task.status}] worker=${task.worker ?? 'unassigned'} task=${task.taskId ?? '-'} title=${JSON.stringify(task.title)}`
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function taskDetail(task) {
|
|
7
|
+
return {
|
|
8
|
+
id: task.id,
|
|
9
|
+
subtaskId: task.id,
|
|
10
|
+
taskId: task.taskId,
|
|
11
|
+
supervisor: task.supervisor,
|
|
12
|
+
worker: task.worker,
|
|
13
|
+
title: task.title,
|
|
14
|
+
instruction: task.instruction,
|
|
15
|
+
inputs: task.inputs,
|
|
16
|
+
acceptance: task.acceptance,
|
|
17
|
+
status: task.status,
|
|
18
|
+
attempts: task.attempts,
|
|
19
|
+
createdTurn: task.createdTurn,
|
|
20
|
+
assignedTurn: task.assignedTurn,
|
|
21
|
+
capabilityVersion: task.capabilityVersion,
|
|
22
|
+
result: task.result,
|
|
23
|
+
failure: task.failure,
|
|
24
|
+
history: task.history,
|
|
25
|
+
}
|
|
26
|
+
}
|
package/lib/tasks.js
CHANGED
|
@@ -364,11 +364,6 @@ export class TaskStore {
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
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
367
|
}
|
|
373
368
|
|
|
374
369
|
TaskStore.summary = subtaskSummary
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/** Model-facing tool parameter schemas. */
|
|
2
|
+
export const TEXT_OUTPUT = {
|
|
3
|
+
schema: { type: 'string' },
|
|
4
|
+
render(_args, value) {
|
|
5
|
+
return [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value) }]
|
|
6
|
+
},
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const NO_PARAMETERS = { type: 'object', properties: {}, additionalProperties: false }
|
|
10
|
+
|
|
11
|
+
export const SEND_PARAMETERS = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
target: { type: 'string', description: 'Exact target session id (session-...). Use collab_peers to find it.' },
|
|
15
|
+
message: { type: 'string', description: 'Message text for the target session.' },
|
|
16
|
+
},
|
|
17
|
+
required: ['target', 'message'],
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const INBOX_PARAMETERS = {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
peer: { type: 'string', description: 'Optional peer session id to read only that pair.' },
|
|
25
|
+
mark_read: { type: 'boolean', description: 'Whether to move read messages into the pair read directory. Defaults to true.' },
|
|
26
|
+
},
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const TASK_OPEN_PARAMETERS = {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
title: { type: 'string', description: 'Short parent-task title.' },
|
|
34
|
+
},
|
|
35
|
+
required: ['title'],
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const TASK_CREATE_PARAMETERS = {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
title: { type: 'string', description: 'Short task title.' },
|
|
43
|
+
instruction: { type: 'string', description: 'Self-contained instructions for the worker.' },
|
|
44
|
+
acceptance: { type: 'string', description: 'Acceptance criteria the supervisor will verify.' },
|
|
45
|
+
inputs: { type: 'object', description: 'Optional structured inputs for the worker.' },
|
|
46
|
+
taskId: { type: 'string', description: 'Parent task id returned by collab_task_open.' },
|
|
47
|
+
},
|
|
48
|
+
required: ['taskId', 'title', 'instruction'],
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const TASK_ASSIGN_PARAMETERS = {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
subtaskId: { type: 'string', description: 'Subtask id (subtask-...); taskId is accepted for legacy callers.' },
|
|
56
|
+
taskId: { type: 'string', description: 'Legacy subtask id alias.' },
|
|
57
|
+
worker: { type: 'string', description: 'Worker session id with an offer relationship.' },
|
|
58
|
+
},
|
|
59
|
+
required: ['worker'],
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const TASK_ID_PARAMETERS = {
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
taskId: { type: 'string', description: 'Task id (task-...).' },
|
|
67
|
+
},
|
|
68
|
+
required: ['taskId'],
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const TASK_LIST_PARAMETERS = {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
status: { type: 'string', description: 'Optional status filter.' },
|
|
76
|
+
},
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const TASK_REJECT_PARAMETERS = {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
taskId: { type: 'string' },
|
|
84
|
+
reason: { type: 'string', description: 'Why the delivered result is rejected.' },
|
|
85
|
+
},
|
|
86
|
+
required: ['taskId', 'reason'],
|
|
87
|
+
additionalProperties: false,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const TASK_PROGRESS_PARAMETERS = {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties: {
|
|
93
|
+
taskId: { type: 'string' },
|
|
94
|
+
note: { type: 'string' },
|
|
95
|
+
},
|
|
96
|
+
required: ['taskId', 'note'],
|
|
97
|
+
additionalProperties: false,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const TASK_COMPLETE_PARAMETERS = {
|
|
101
|
+
type: 'object',
|
|
102
|
+
properties: {
|
|
103
|
+
taskId: { type: 'string' },
|
|
104
|
+
summary: { type: 'string', description: 'Concise result summary.' },
|
|
105
|
+
details: { type: 'string', description: 'Optional longer result details.' },
|
|
106
|
+
artifacts: {
|
|
107
|
+
type: 'array',
|
|
108
|
+
items: { type: 'string' },
|
|
109
|
+
description: 'Optional paths under the delivery subdirectory.',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ['taskId', 'summary'],
|
|
113
|
+
additionalProperties: false,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const TASK_FAIL_PARAMETERS = {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
taskId: { type: 'string' },
|
|
120
|
+
reason: { type: 'string' },
|
|
121
|
+
},
|
|
122
|
+
required: ['taskId', 'reason'],
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const TASK_CLOSE_PARAMETERS = {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
taskId: { type: 'string' },
|
|
130
|
+
},
|
|
131
|
+
required: ['taskId'],
|
|
132
|
+
additionalProperties: false,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const DELIVERY_LIST_PARAMETERS = {
|
|
136
|
+
type: 'object',
|
|
137
|
+
properties: {
|
|
138
|
+
taskId: { type: 'string', description: 'Optional task id; omitted lists only this supervisor\'s tasks.' },
|
|
139
|
+
},
|
|
140
|
+
additionalProperties: false,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const DELIVERY_MANIFEST_PARAMETERS = {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
taskId: { type: 'string' },
|
|
147
|
+
},
|
|
148
|
+
required: ['taskId'],
|
|
149
|
+
additionalProperties: false,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const REQUEST_DELIVER_PARAMETERS = {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
requestId: { type: 'string' },
|
|
156
|
+
},
|
|
157
|
+
required: ['requestId'],
|
|
158
|
+
additionalProperties: false,
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
export const REQUEST_SUBMIT_PARAMETERS = {
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
supervisor: { type: 'string', description: 'Target supervisor id. Required when more than one authorized supervisor is available.' },
|
|
166
|
+
title: { type: 'string', description: 'Short request title.' },
|
|
167
|
+
requirement: { type: 'string', description: 'Outcome-focused requirement and acceptance criteria. Do not name workers, projects, tasks, delivery paths, or internal scheduling.' },
|
|
168
|
+
},
|
|
169
|
+
required: ['title', 'requirement'],
|
|
170
|
+
additionalProperties: false,
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export const REQUEST_LIST_PARAMETERS = {
|
|
174
|
+
type: 'object',
|
|
175
|
+
properties: {
|
|
176
|
+
status: { type: 'string', description: 'Optional status filter.' },
|
|
177
|
+
},
|
|
178
|
+
additionalProperties: false,
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export const REQUEST_ACCEPT_PARAMETERS = {
|
|
182
|
+
type: 'object',
|
|
183
|
+
properties: {
|
|
184
|
+
requestId: { type: 'string' },
|
|
185
|
+
taskId: { type: 'string', description: 'Task containing the subtasks created for this request.' },
|
|
186
|
+
response: { type: 'string', description: 'Optional message for the requester.' },
|
|
187
|
+
},
|
|
188
|
+
required: ['requestId', 'taskId'],
|
|
189
|
+
additionalProperties: false,
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const REQUEST_REJECT_PARAMETERS = {
|
|
193
|
+
type: 'object',
|
|
194
|
+
properties: {
|
|
195
|
+
requestId: { type: 'string' },
|
|
196
|
+
reason: { type: 'string', description: 'Why the registered capabilities cannot satisfy this request; name the missing capability.' },
|
|
197
|
+
},
|
|
198
|
+
required: ['requestId', 'reason'],
|
|
199
|
+
additionalProperties: false,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export const REQUEST_CANCEL_PARAMETERS = {
|
|
203
|
+
type: 'object',
|
|
204
|
+
properties: {
|
|
205
|
+
requestId: { type: 'string' },
|
|
206
|
+
},
|
|
207
|
+
required: ['requestId'],
|
|
208
|
+
additionalProperties: false,
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export const REQUEST_HEARTBEAT_PARAMETERS = {
|
|
212
|
+
type: 'object',
|
|
213
|
+
properties: {
|
|
214
|
+
requestId: { type: 'string' },
|
|
215
|
+
note: { type: 'string', description: 'Optional progress note for the requester.' },
|
|
216
|
+
extendByMs: { type: 'number', description: 'Optional execution deadline extension in milliseconds, capped at seven days.' },
|
|
217
|
+
},
|
|
218
|
+
required: ['requestId'],
|
|
219
|
+
additionalProperties: false,
|
|
220
|
+
}
|