@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-forge/core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "imports": {
5
5
  "#~/*.js": {
6
6
  "__vibe-forge__": {
@@ -20,6 +20,7 @@ export type SessionInfo =
20
20
  export interface SessionInitInfo {
21
21
  uuid: string
22
22
  model: string
23
+ adapter?: string
23
24
  version: string
24
25
  tools: string[]
25
26
  slashCommands: string[]
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<void>
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 =
@@ -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
- await fs.access(cachePath)
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, join, relative, resolve } from 'node:path'
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 ?? basename(path)
117
- const desc = attributes.description ?? name
118
- return (
119
- ` - ${name}:${desc}\n` +
120
- `${attributes.always ? body : ''}\n` +
121
- '--------------------\n'
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
- const parts = path.split('/')
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
- `- 技能文件资源路径:${dirname(path)}\n` +
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
- ({ attributes: { name, description } }) => ` - ${name}:${description}\n`
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 ?? basename(dirname(path))
226
- const desc = attributes.description ?? name
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
- // Calculate relative path for display/ID
229
- // User code used relative('.ai/specs', path), but here path is absolute.
230
- // We can try to make it relative to cwd/.ai/specs if possible, or just relative to cwd.
231
- // The user code seems to assume specs are in .ai/specs.
232
- // Let's use relative(join(this.cwd, '.ai/specs'), path) if it's in there, otherwise...
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
- ` - 标识:${relPath}\n` +
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/plugins/*/entities/*.md'
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
- .map(({ attributes: { name, prompt: _p }, body }) => ` - ${name}:${body}\n`)
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' +