@vibe-forge/mcp 0.10.1 → 0.11.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/__tests__/sync.spec.ts +23 -0
- package/__tests__/task-manager.spec.ts +319 -1
- package/__tests__/task-tool.spec.ts +142 -9
- package/package.json +8 -8
- package/src/sync.ts +7 -1
- package/src/tools/task/index.ts +27 -79
- package/src/tools/task/manager.ts +493 -69
- package/src/tools/task/permission-recovery.ts +172 -0
- package/src/tools/task/permission-state.ts +200 -0
- package/src/tools/task/presentation.ts +95 -0
- package/src/tools/task/register-task-runtime-tools.ts +145 -0
package/src/tools/task/index.ts
CHANGED
|
@@ -8,6 +8,15 @@ import { createChildSession, getParentSessionId } from '#~/sync.js'
|
|
|
8
8
|
import type { McpManagedTaskInput } from '../../types'
|
|
9
9
|
import { defineRegister } from '../types'
|
|
10
10
|
import { TaskManager } from './manager'
|
|
11
|
+
import {
|
|
12
|
+
SESSION_PERMISSION_MODES,
|
|
13
|
+
START_TASKS_DESCRIPTION,
|
|
14
|
+
TASK_BACKGROUND_DESCRIPTION,
|
|
15
|
+
TASK_PERMISSION_MODE_DESCRIPTION,
|
|
16
|
+
resolveInheritedPermissionMode,
|
|
17
|
+
serializeTaskInfo
|
|
18
|
+
} from './presentation'
|
|
19
|
+
import { registerTaskRuntimeTools } from './register-task-runtime-tools'
|
|
11
20
|
|
|
12
21
|
export const createTaskRegister = () => {
|
|
13
22
|
const taskManager = new TaskManager()
|
|
@@ -17,7 +26,7 @@ export const createTaskRegister = () => {
|
|
|
17
26
|
'StartTasks',
|
|
18
27
|
{
|
|
19
28
|
title: 'Start Tasks',
|
|
20
|
-
description:
|
|
29
|
+
description: START_TASKS_DESCRIPTION,
|
|
21
30
|
inputSchema: z.object({
|
|
22
31
|
tasks: z
|
|
23
32
|
.array(
|
|
@@ -41,14 +50,12 @@ export const createTaskRegister = () => {
|
|
|
41
50
|
.describe('The adapter to use for the task (e.g. claude-code)')
|
|
42
51
|
.optional(),
|
|
43
52
|
permissionMode: z
|
|
44
|
-
.enum(
|
|
45
|
-
.describe(
|
|
53
|
+
.enum(SESSION_PERMISSION_MODES)
|
|
54
|
+
.describe(TASK_PERMISSION_MODE_DESCRIPTION)
|
|
46
55
|
.optional(),
|
|
47
56
|
background: z
|
|
48
57
|
.boolean()
|
|
49
|
-
.describe(
|
|
50
|
-
'Whether to run in background (default: true). If false, waits for completion and returns logs.'
|
|
51
|
-
)
|
|
58
|
+
.describe(TASK_BACKGROUND_DESCRIPTION)
|
|
52
59
|
.optional()
|
|
53
60
|
})
|
|
54
61
|
)
|
|
@@ -56,8 +63,14 @@ export const createTaskRegister = () => {
|
|
|
56
63
|
})
|
|
57
64
|
},
|
|
58
65
|
async ({ tasks }) => {
|
|
59
|
-
const
|
|
66
|
+
const inheritedPermissionMode = resolveInheritedPermissionMode()
|
|
67
|
+
const resolvedTasks = tasks.map((task): McpManagedTaskInput & {
|
|
68
|
+
taskId: string
|
|
69
|
+
type: NonNullable<McpManagedTaskInput['type']>
|
|
70
|
+
} => ({
|
|
60
71
|
...task,
|
|
72
|
+
permissionMode: task.permissionMode ?? inheritedPermissionMode,
|
|
73
|
+
type: task.type ?? 'default',
|
|
61
74
|
taskId: uuid()
|
|
62
75
|
}))
|
|
63
76
|
const parentSessionId = getParentSessionId()
|
|
@@ -72,7 +85,8 @@ export const createTaskRegister = () => {
|
|
|
72
85
|
createChildSession({
|
|
73
86
|
id: task.taskId,
|
|
74
87
|
title: task.name ?? task.description,
|
|
75
|
-
parentSessionId
|
|
88
|
+
parentSessionId,
|
|
89
|
+
permissionMode: task.permissionMode
|
|
76
90
|
})
|
|
77
91
|
))
|
|
78
92
|
: []
|
|
@@ -89,84 +103,18 @@ export const createTaskRegister = () => {
|
|
|
89
103
|
type: 'text',
|
|
90
104
|
text: JSON.stringify(results.map((r, idx) => {
|
|
91
105
|
const { taskId, description } = resolvedTasks[idx]
|
|
92
|
-
|
|
93
|
-
const { session, onStop, serverSync, createdAt, ...safeInfo } = info ?? {}
|
|
94
|
-
return {
|
|
106
|
+
return serializeTaskInfo({
|
|
95
107
|
taskId,
|
|
96
108
|
description,
|
|
97
|
-
status:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
109
|
+
status: r.status === 'rejected' ? 'failed' : 'running',
|
|
110
|
+
info: taskManager.getTask(taskId)
|
|
111
|
+
})
|
|
101
112
|
}))
|
|
102
113
|
}]
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
)
|
|
106
117
|
|
|
107
|
-
server
|
|
108
|
-
'GetTaskInfo',
|
|
109
|
-
{
|
|
110
|
-
title: 'Get Task Info',
|
|
111
|
-
description: 'Get the status and logs of a specific task',
|
|
112
|
-
inputSchema: z.object({
|
|
113
|
-
taskId: z.string().describe('The ID of the task to check')
|
|
114
|
-
})
|
|
115
|
-
},
|
|
116
|
-
async ({ taskId }) => {
|
|
117
|
-
const task = taskManager.getTask(taskId)
|
|
118
|
-
if (!task) {
|
|
119
|
-
return {
|
|
120
|
-
content: [{ type: 'text', text: `Task ${taskId} not found.` }],
|
|
121
|
-
isError: true
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const { session, onStop, serverSync, createdAt, ...safeTask } = task
|
|
125
|
-
return {
|
|
126
|
-
content: [{
|
|
127
|
-
type: 'text',
|
|
128
|
-
text: JSON.stringify([safeTask])
|
|
129
|
-
}]
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
server.registerTool(
|
|
135
|
-
'StopTask',
|
|
136
|
-
{
|
|
137
|
-
title: 'Stop Task',
|
|
138
|
-
description: 'Stop a running task',
|
|
139
|
-
inputSchema: z.object({
|
|
140
|
-
taskId: z.string().describe('The ID of the task to stop')
|
|
141
|
-
})
|
|
142
|
-
},
|
|
143
|
-
async ({ taskId }) => {
|
|
144
|
-
const success = taskManager.stopTask(taskId)
|
|
145
|
-
return {
|
|
146
|
-
content: [{
|
|
147
|
-
type: 'text',
|
|
148
|
-
text: success ? `Task ${taskId} stopped.` : `Failed to stop task ${taskId} (not found or already stopped).`
|
|
149
|
-
}]
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
server.registerTool(
|
|
155
|
-
'ListTasks',
|
|
156
|
-
{
|
|
157
|
-
title: 'List Tasks',
|
|
158
|
-
description: 'List all managed tasks',
|
|
159
|
-
inputSchema: z.object({})
|
|
160
|
-
},
|
|
161
|
-
async () => {
|
|
162
|
-
const tasks = taskManager.getAllTasks()
|
|
163
|
-
return {
|
|
164
|
-
content: [{
|
|
165
|
-
type: 'text',
|
|
166
|
-
text: JSON.stringify(tasks.map(({ session, onStop, serverSync, createdAt, ...task }) => task))
|
|
167
|
-
}]
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
)
|
|
118
|
+
registerTaskRuntimeTools(server, taskManager)
|
|
171
119
|
})
|
|
172
120
|
}
|