index.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import type { Plugin } from "@opencode-ai/plugin";
  2. /**
  3. * CoderAgent Assistant Plugin - Simplified Version
  4. *
  5. * Actively helps CoderAgent by showing reminders and toasts
  6. */
  7. export const CoderAgentAssistantPlugin: Plugin = async (ctx) => {
  8. const { client, toast } = ctx as any;
  9. await client.app.log({
  10. service: "coder-agent-assistant",
  11. level: "info",
  12. message: "CoderAgent Assistant Plugin initialized"
  13. });
  14. return {
  15. // Hook 1: Before CoderAgent starts
  16. "tool.execute.before": async (input: any, output: any) => {
  17. if (input.tool === "task" && input.args?.subagent_type === "CoderAgent") {
  18. console.log("\n🤖 CoderAgent Assistant: Monitoring started");
  19. // Show toast
  20. if (toast) {
  21. await toast.show({
  22. title: "🤖 CoderAgent Assistant",
  23. message: "Monitoring CoderAgent work - checks will be validated",
  24. type: "info",
  25. duration: 4000
  26. });
  27. }
  28. }
  29. },
  30. // Hook 2: After CoderAgent completes
  31. "tool.execute.after": async (input: any, output: any) => {
  32. if (input.tool === "task" && input.args?.subagent_type === "CoderAgent") {
  33. const result = output.result || "";
  34. // Check for self-review
  35. const hasSelfReview =
  36. result.includes("Self-Review") ||
  37. result.includes("✅ Types clean");
  38. // Check for deliverables
  39. const hasDeliverables =
  40. result.includes("Deliverables:") ||
  41. result.includes("created");
  42. console.log("\n🤖 CoderAgent Assistant: Validation");
  43. console.log(` Self-Review: ${hasSelfReview ? '✅' : '⚠️'}`);
  44. console.log(` Deliverables: ${hasDeliverables ? '✅' : '⚠️'}`);
  45. // Show toast
  46. if (toast) {
  47. if (hasSelfReview && hasDeliverables) {
  48. await toast.show({
  49. title: "✅ CoderAgent Checks Passed",
  50. message: "All validation checks completed successfully",
  51. type: "success",
  52. duration: 5000
  53. });
  54. } else {
  55. await toast.show({
  56. title: "⚠️ CoderAgent Validation",
  57. message: "Some checks need attention - see console",
  58. type: "warning",
  59. duration: 6000
  60. });
  61. }
  62. }
  63. }
  64. },
  65. // Hook 3: Session idle
  66. "session.idle": async () => {
  67. console.log("\n🤖 CoderAgent Assistant: Session complete");
  68. if (toast) {
  69. await toast.show({
  70. title: "🤖 Session Summary",
  71. message: "CoderAgent Assistant monitoring complete",
  72. type: "info",
  73. duration: 4000
  74. });
  75. }
  76. }
  77. };
  78. };
  79. export default CoderAgentAssistantPlugin;