mirror of
https://github.com/theniceboy/.config.git
synced 2026-04-16 00:45:56 +08:00
agent tracker update
This commit is contained in:
parent
5064629d61
commit
0bfcb8d7c3
31 changed files with 1741 additions and 3320 deletions
93
opencode/plugins/require_work_summary.ts
Normal file
93
opencode/plugins/require_work_summary.ts
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import type { Plugin } from "@opencode-ai/plugin"
|
||||
|
||||
type TurnState = {
|
||||
summaryCalled: boolean
|
||||
}
|
||||
|
||||
const states = new Map<string, TurnState>()
|
||||
|
||||
function sessionState(sessionID: string) {
|
||||
let state = states.get(sessionID)
|
||||
if (!state) {
|
||||
state = { summaryCalled: false }
|
||||
states.set(sessionID, state)
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
function eventSessionID(event: any) {
|
||||
return String(
|
||||
event?.properties?.sessionID ||
|
||||
event?.properties?.session?.id ||
|
||||
event?.properties?.info?.sessionID ||
|
||||
"",
|
||||
).trim()
|
||||
}
|
||||
|
||||
export const RequireWorkSummaryPlugin: Plugin = async () => {
|
||||
return {
|
||||
"chat.message": async (input: any) => {
|
||||
const sessionID = String(input?.sessionID || "").trim()
|
||||
if (!sessionID) {
|
||||
return
|
||||
}
|
||||
sessionState(sessionID).summaryCalled = false
|
||||
},
|
||||
|
||||
"command.execute.before": async (input: any) => {
|
||||
const sessionID = String(input?.sessionID || "").trim()
|
||||
if (!sessionID) {
|
||||
return
|
||||
}
|
||||
sessionState(sessionID).summaryCalled = false
|
||||
},
|
||||
|
||||
"tool.execute.before": async (input: any) => {
|
||||
const sessionID = String(input?.sessionID || "").trim()
|
||||
if (!sessionID) {
|
||||
return
|
||||
}
|
||||
|
||||
const tool = String(input?.tool || "").trim()
|
||||
if (!tool) {
|
||||
return
|
||||
}
|
||||
|
||||
const state = sessionState(sessionID)
|
||||
if (tool === "set_work_summary") {
|
||||
return
|
||||
}
|
||||
|
||||
if (!state.summaryCalled) {
|
||||
throw new Error(
|
||||
"Call set_work_summary first with a specific theme and next-step now label before using other tools.",
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
"tool.execute.after": async (input: any) => {
|
||||
const sessionID = String(input?.sessionID || "").trim()
|
||||
if (!sessionID) {
|
||||
return
|
||||
}
|
||||
|
||||
const tool = String(input?.tool || "").trim()
|
||||
if (tool === "set_work_summary") {
|
||||
sessionState(sessionID).summaryCalled = true
|
||||
}
|
||||
},
|
||||
|
||||
event: async ({ event }) => {
|
||||
if (event?.type === "session.deleted") {
|
||||
const sessionID = eventSessionID(event)
|
||||
if (sessionID) {
|
||||
states.delete(sessionID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default RequireWorkSummaryPlugin
|
||||
Loading…
Add table
Add a link
Reference in a new issue