@vibe-forge/core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/adapter/type.ts +1 -0
- package/src/channel.ts +24 -1
- package/src/controllers/task/run.ts +11 -0
- package/src/types.ts +5 -0
- package/src/utils/cache.ts +8 -1
- package/src/utils/definition-loader.ts +88 -40
package/package.json
CHANGED
package/src/adapter/type.ts
CHANGED
package/src/channel.ts
CHANGED
|
@@ -40,6 +40,13 @@ export const channelBaseSchema = z.object({
|
|
|
40
40
|
systemPrompt: z
|
|
41
41
|
.string().optional()
|
|
42
42
|
.describe('在此频道启动会话时注入的系统提示词'),
|
|
43
|
+
// 指令
|
|
44
|
+
commandPrefix: z
|
|
45
|
+
.string().optional()
|
|
46
|
+
.describe('频道指令前缀,默认 /'),
|
|
47
|
+
language: z
|
|
48
|
+
.enum(['zh', 'en']).optional()
|
|
49
|
+
.describe('频道提示语言,默认 zh'),
|
|
43
50
|
// 访问权限控制
|
|
44
51
|
access: channelAccessSchema
|
|
45
52
|
.optional()
|
|
@@ -54,8 +61,24 @@ export type ChannelConfig = {
|
|
|
54
61
|
[K in ChannelType]: ChannelConfigByType<K>
|
|
55
62
|
}[ChannelType]
|
|
56
63
|
|
|
64
|
+
export interface ChannelSendResult {
|
|
65
|
+
messageId?: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ChannelFollowUp {
|
|
69
|
+
content: string
|
|
70
|
+
i18nContents?: Array<{
|
|
71
|
+
content: string
|
|
72
|
+
language: string
|
|
73
|
+
}>
|
|
74
|
+
}
|
|
75
|
+
|
|
57
76
|
export interface ChannelConnection<TMessage> {
|
|
58
|
-
sendMessage: (message: TMessage) => Promise<
|
|
77
|
+
sendMessage: (message: TMessage) => Promise<ChannelSendResult | undefined>
|
|
78
|
+
pushFollowUps?: (input: {
|
|
79
|
+
messageId: string
|
|
80
|
+
followUps: readonly ChannelFollowUp[]
|
|
81
|
+
}) => Promise<void>
|
|
59
82
|
startReceiving?: (options: {
|
|
60
83
|
handlers: ChannelEventHandlers
|
|
61
84
|
}) => Promise<void>
|
|
@@ -129,6 +129,17 @@ export const run = async (
|
|
|
129
129
|
|
|
130
130
|
const originalOnEvent = adapterOptions.onEvent
|
|
131
131
|
const wrappedOnEvent = (event: AdapterOutputEvent) => {
|
|
132
|
+
if (event.type === 'init') {
|
|
133
|
+
originalOnEvent({
|
|
134
|
+
...event,
|
|
135
|
+
data: {
|
|
136
|
+
...event.data,
|
|
137
|
+
adapter: adapterType
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
|
|
132
143
|
if (event.type === 'exit') {
|
|
133
144
|
const { data } = event
|
|
134
145
|
|
package/src/types.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface Project {
|
|
|
9
9
|
|
|
10
10
|
export type SessionStatus = 'running' | 'completed' | 'failed' | 'terminated' | 'waiting_input'
|
|
11
11
|
|
|
12
|
+
export type SessionPermissionMode = 'default' | 'acceptEdits' | 'plan' | 'dontAsk' | 'bypassPermissions'
|
|
13
|
+
|
|
12
14
|
export interface Session {
|
|
13
15
|
id: string
|
|
14
16
|
parentSessionId?: string
|
|
@@ -21,6 +23,9 @@ export interface Session {
|
|
|
21
23
|
isArchived?: boolean
|
|
22
24
|
tags?: string[]
|
|
23
25
|
status?: SessionStatus
|
|
26
|
+
model?: string
|
|
27
|
+
adapter?: string
|
|
28
|
+
permissionMode?: SessionPermissionMode
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
export type ChatMessageContent =
|
package/src/utils/cache.ts
CHANGED
|
@@ -46,6 +46,13 @@ export const getCache = async <K extends keyof Cache>(
|
|
|
46
46
|
key: K
|
|
47
47
|
): Promise<Cache[K] | undefined> => {
|
|
48
48
|
const cachePath = getCachePath(cwd, taskId, sessionId, key)
|
|
49
|
-
|
|
49
|
+
try {
|
|
50
|
+
await fs.access(cachePath)
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
throw error
|
|
56
|
+
}
|
|
50
57
|
return JSON.parse(await fs.readFile(cachePath, 'utf-8'))
|
|
51
58
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { readFile } from 'node:fs/promises'
|
|
3
|
-
import { basename, dirname,
|
|
3
|
+
import { basename, dirname, relative, resolve } from 'node:path'
|
|
4
4
|
import process from 'node:process'
|
|
5
5
|
|
|
6
6
|
import { glob } from 'fast-glob'
|
|
@@ -79,6 +79,50 @@ export const loadLocalDocuments = async <Attrs extends object>(
|
|
|
79
79
|
return Promise.all(promises)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
const normalizePath = (path: string) => path.split('\\').join('/')
|
|
83
|
+
|
|
84
|
+
const stripExtension = (fileName: string) => fileName.replace(/\.[^/.]+$/, '')
|
|
85
|
+
|
|
86
|
+
const getFirstNonEmptyLine = (text: string) =>
|
|
87
|
+
text
|
|
88
|
+
.split('\n')
|
|
89
|
+
.map(line => line.trim())
|
|
90
|
+
.find(Boolean)
|
|
91
|
+
|
|
92
|
+
const toPromptPath = (cwd: string, path: string) => {
|
|
93
|
+
const relPath = normalizePath(relative(cwd, path))
|
|
94
|
+
return relPath.startsWith('..') ? normalizePath(path) : relPath
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const resolveDocumentName = (
|
|
98
|
+
path: string,
|
|
99
|
+
explicitName?: string,
|
|
100
|
+
indexFileNames: string[] = []
|
|
101
|
+
) => {
|
|
102
|
+
const trimmedName = explicitName?.trim()
|
|
103
|
+
if (trimmedName) return trimmedName
|
|
104
|
+
|
|
105
|
+
const fileName = basename(path).toLowerCase()
|
|
106
|
+
if (indexFileNames.includes(fileName)) {
|
|
107
|
+
return basename(dirname(path))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return stripExtension(basename(path))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const resolveDocumentDescription = (
|
|
114
|
+
body: string,
|
|
115
|
+
explicitDescription?: string,
|
|
116
|
+
fallbackName?: string
|
|
117
|
+
) => {
|
|
118
|
+
const trimmedDescription = explicitDescription?.trim()
|
|
119
|
+
return trimmedDescription || getFirstNonEmptyLine(body) || fallbackName || ''
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const resolveSpecIdentifier = (path: string, explicitName?: string) => {
|
|
123
|
+
return resolveDocumentName(path, explicitName, ['index.md'])
|
|
124
|
+
}
|
|
125
|
+
|
|
82
126
|
export class DefinitionLoader {
|
|
83
127
|
private readonly cwd: string
|
|
84
128
|
|
|
@@ -113,13 +157,12 @@ export class DefinitionLoader {
|
|
|
113
157
|
const rulesPrompt = rules
|
|
114
158
|
.map((rule) => {
|
|
115
159
|
const { path, body, attributes } = rule
|
|
116
|
-
const name = attributes.name
|
|
117
|
-
const desc = attributes.description
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
)
|
|
160
|
+
const name = resolveDocumentName(path, attributes.name)
|
|
161
|
+
const desc = resolveDocumentDescription(body, attributes.description, name)
|
|
162
|
+
const content = attributes.always && body.trim()
|
|
163
|
+
? `<rule-content>\n${body.trim()}\n</rule-content>\n`
|
|
164
|
+
: ''
|
|
165
|
+
return ` - ${name}:${desc}\n${content}--------------------\n`
|
|
123
166
|
})
|
|
124
167
|
.filter(Boolean)
|
|
125
168
|
.join('\n')
|
|
@@ -150,9 +193,7 @@ export class DefinitionLoader {
|
|
|
150
193
|
// Filter by directory name (skill name)
|
|
151
194
|
if (skills) {
|
|
152
195
|
paths = paths.filter(path => {
|
|
153
|
-
|
|
154
|
-
// .../skills/{name}/SKILL.md
|
|
155
|
-
return skills.includes(parts[parts.length - 2])
|
|
196
|
+
return skills.includes(basename(dirname(path)))
|
|
156
197
|
})
|
|
157
198
|
}
|
|
158
199
|
|
|
@@ -164,13 +205,17 @@ export class DefinitionLoader {
|
|
|
164
205
|
generateSkillsPrompt(skills: Definition<Skill>[]): string {
|
|
165
206
|
return skills
|
|
166
207
|
.map((skill) => {
|
|
167
|
-
const { path, body } = skill
|
|
208
|
+
const { path, body, attributes } = skill
|
|
209
|
+
const name = resolveDocumentName(path, attributes.name, ['skill.md'])
|
|
210
|
+
const desc = resolveDocumentDescription(body, attributes.description, name)
|
|
168
211
|
return (
|
|
169
212
|
'技能相关信息如下,通过阅读以下内容了解技能的详细信息:\n' +
|
|
170
|
-
`-
|
|
213
|
+
`- 技能名称:${name}\n` +
|
|
214
|
+
`- 技能介绍:${desc}\n` +
|
|
215
|
+
`- 技能文件资源路径:${toPromptPath(this.cwd, dirname(path))}\n` +
|
|
171
216
|
'- 资源内容:\n' +
|
|
172
217
|
'<skill-content>\n' +
|
|
173
|
-
`${body}\n` +
|
|
218
|
+
`${body.trim()}\n` +
|
|
174
219
|
'</skill-content>\n' +
|
|
175
220
|
'资源内容中的文件路径相对「技能文件资源路径」路径,通过读取相关工具按照实际需要进行阅读。\n'
|
|
176
221
|
)
|
|
@@ -185,7 +230,11 @@ export class DefinitionLoader {
|
|
|
185
230
|
skills
|
|
186
231
|
.filter(({ attributes: { always } }) => always !== false)
|
|
187
232
|
.map(
|
|
188
|
-
({
|
|
233
|
+
({ path, body, attributes }) => {
|
|
234
|
+
const name = resolveDocumentName(path, attributes.name, ['skill.md'])
|
|
235
|
+
const desc = resolveDocumentDescription(body, attributes.description, name)
|
|
236
|
+
return ` - ${name}:${desc}\n`
|
|
237
|
+
}
|
|
189
238
|
)
|
|
190
239
|
.join('')
|
|
191
240
|
}\n` +
|
|
@@ -197,7 +246,8 @@ export class DefinitionLoader {
|
|
|
197
246
|
const patterns = [
|
|
198
247
|
`.ai/specs/${name}.md`,
|
|
199
248
|
`.ai/specs/${name}/index.md`,
|
|
200
|
-
`.ai/plugins/*/specs/${name}.md
|
|
249
|
+
`.ai/plugins/*/specs/${name}.md`,
|
|
250
|
+
`.ai/plugins/*/specs/${name}/index.md`
|
|
201
251
|
]
|
|
202
252
|
const paths = await this.scan(patterns)
|
|
203
253
|
if (paths.length === 0) return undefined
|
|
@@ -221,34 +271,23 @@ export class DefinitionLoader {
|
|
|
221
271
|
generateSpecRoutePrompt(specsDocuments: Definition<Spec>[]): string {
|
|
222
272
|
const specsRouteStr = specsDocuments
|
|
223
273
|
.filter(({ attributes }) => attributes.always !== false)
|
|
224
|
-
.map(({ path, attributes }) => {
|
|
225
|
-
const name = attributes.name
|
|
226
|
-
const desc = attributes.description
|
|
274
|
+
.map(({ path, body, attributes }) => {
|
|
275
|
+
const name = resolveDocumentName(path, attributes.name, ['index.md'])
|
|
276
|
+
const desc = resolveDocumentDescription(body, attributes.description, name)
|
|
277
|
+
const identifier = resolveSpecIdentifier(path, attributes.name)
|
|
227
278
|
const params = attributes.params ?? []
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
// Actually, just providing a relative path from project root is probably fine or the name.
|
|
234
|
-
// User code: relative('.ai/specs', path)
|
|
235
|
-
|
|
236
|
-
let relPath = relative(join(this.cwd, '.ai/specs'), path)
|
|
237
|
-
if (relPath.startsWith('..')) {
|
|
238
|
-
// Maybe in a plugin?
|
|
239
|
-
relPath = relative(this.cwd, path)
|
|
240
|
-
}
|
|
279
|
+
const paramsPrompt = params.length > 0
|
|
280
|
+
? params
|
|
281
|
+
.map(({ name, description }) => ` - ${name}:${description ?? '无'}\n`)
|
|
282
|
+
.join('')
|
|
283
|
+
: ' - 无\n'
|
|
241
284
|
|
|
242
285
|
return (
|
|
243
286
|
`- 流程名称:${name}\n` +
|
|
244
287
|
` - 介绍:${desc}\n` +
|
|
245
|
-
` - 标识:${
|
|
288
|
+
` - 标识:${identifier}\n` +
|
|
246
289
|
' - 参数:\n' +
|
|
247
|
-
`${
|
|
248
|
-
params
|
|
249
|
-
.map(({ name, description }) => ` - ${name}:${description}\n`)
|
|
250
|
-
.join('')
|
|
251
|
-
}\n`
|
|
290
|
+
`${paramsPrompt}`
|
|
252
291
|
)
|
|
253
292
|
})
|
|
254
293
|
.join('\n')
|
|
@@ -285,7 +324,9 @@ export class DefinitionLoader {
|
|
|
285
324
|
|
|
286
325
|
// 2. Fallback to Markdown file
|
|
287
326
|
const patterns = [
|
|
327
|
+
`.ai/entities/${name}.md`,
|
|
288
328
|
`.ai/entities/${name}/README.md`,
|
|
329
|
+
`.ai/plugins/*/entities/${name}.md`,
|
|
289
330
|
`.ai/plugins/*/entities/${name}/README.md`
|
|
290
331
|
]
|
|
291
332
|
const paths = await this.scan(patterns)
|
|
@@ -327,7 +368,9 @@ export class DefinitionLoader {
|
|
|
327
368
|
// List both .md and index.json entities
|
|
328
369
|
const mdPatterns = [
|
|
329
370
|
'.ai/entities/*.md',
|
|
330
|
-
'.ai/
|
|
371
|
+
'.ai/entities/*/README.md',
|
|
372
|
+
'.ai/plugins/*/entities/*.md',
|
|
373
|
+
'.ai/plugins/*/entities/*/README.md'
|
|
331
374
|
]
|
|
332
375
|
const jsonPatterns = [
|
|
333
376
|
'.ai/entities/*/index.json',
|
|
@@ -350,7 +393,12 @@ export class DefinitionLoader {
|
|
|
350
393
|
'项目存在如下实体:\n' +
|
|
351
394
|
`${
|
|
352
395
|
entities
|
|
353
|
-
.
|
|
396
|
+
.filter(({ attributes }) => attributes.always !== false)
|
|
397
|
+
.map(({ path, attributes, body }) => {
|
|
398
|
+
const name = resolveDocumentName(path, attributes.name, ['readme.md', 'index.json'])
|
|
399
|
+
const desc = resolveDocumentDescription(body, attributes.description, name)
|
|
400
|
+
return ` - ${name}:${desc}\n`
|
|
401
|
+
})
|
|
354
402
|
.join('')
|
|
355
403
|
}\n` +
|
|
356
404
|
'解决用户问题时,需根据用户需求可以通过 run-tasks 工具指定为实体后,自行调度多个不同类型的实体来完成工作。\n' +
|