dsh-sansheng-liubu/sansheng/index.js

42 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { DsBotState } from './src/dsbot-state.js'
import { installGates } from './src/gates.js'
import { installObserver } from './src/observe.js'
import { dsbotStatePath, sanshengStatePath } from './src/paths.js'
import { newBootId } from './src/records.js'
import { installRoute } from './src/route.js'
import { SanshengStore } from './src/store.js'
import { installTools } from './src/tools.js'
export const name = 'sansheng'
export const inject = ['tools']
/**
* 三省六部伴侣插件。原生 group_goal 是阶段进度唯一权威;
* 这里只补 DS Bot 没有的东西:项目三角色绑定、审查记录、目标门禁、
* 派发回执与返工预算。
*/
export async function apply(ctx, config = {}) {
const home = typeof config.home === 'string' && config.home.trim() !== '' ? config.home : undefined
const store = new SanshengStore(
typeof config.statePath === 'string' && config.statePath !== '' ? config.statePath : sanshengStatePath(home),
)
const dsbot = new DsBotState(
typeof config.dsbotStatePath === 'string' && config.dsbotStatePath !== '' ? config.dsbotStatePath : dsbotStatePath(home),
)
const bootId = newBootId()
try {
await store.load()
// 重启对账:上次启动里停在 intent 的派发,结果未知,标记待核实。
const pending = await store.reconcileDispatches(bootId)
if (pending > 0) {
console.warn(`sansheng: ${pending} 条派发在上次退出时未拿到回执,已标记待核实(用 sansheng_reconcile 核对)。`)
}
} catch (error) {
console.warn(`sansheng: 无法读取 ${store.file}:${error?.message ?? error}`)
}
installGates({ ctx, store, dsbot })
installObserver({ ctx, store, dsbot, bootId })
installTools({ ctx, store, dsbot, bootId })
installRoute({ ctx, store, dsbot })
}