42 lines
1.8 KiB
JavaScript
42 lines
1.8 KiB
JavaScript
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 })
|
||
}
|