opencode-orchestrator 1.0.36 → 1.0.38

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/README.md CHANGED
@@ -67,6 +67,61 @@ OpenCode Orchestrator manages complex software tasks through **parallel multi-ag
67
67
  [MISSION SEALED]
68
68
  ```
69
69
 
70
+
71
+ ```mermaid
72
+ graph TD
73
+ %% Nodes
74
+ User(("User 👤"))
75
+ LLM(("Brain (LLM) 🧠"))
76
+ Tool(("Tool 🛠️"))
77
+
78
+ %% 1. Chat Processing
79
+ subgraph Chat_Processing [Chat Processing]
80
+ UserAct[UserActivity Hook]
81
+ MissionChat[MissionControl Hook - Start]
82
+ end
83
+
84
+ %% 2. Pre-Execution
85
+ subgraph Pre_Execution [Pre-Execution Guard]
86
+ RoleGuard[StrictRoleGuard]
87
+ end
88
+
89
+ %% 3. Post-Execution
90
+ subgraph Post_Execution [Post-Execution Processing]
91
+ Scanner[SecretScanner]
92
+ UI[AgentUI Hook]
93
+ Resource[ResourceControl - Track]
94
+ end
95
+
96
+ %% 4. Completion
97
+ subgraph Completion [Completion & Loop Control]
98
+ Sanity[SanityCheck]
99
+ MissionDone[MissionControl Hook - Loop]
100
+ ResourceComp[ResourceControl - Compact]
101
+ end
102
+
103
+ %% Flow Connections
104
+ User -->|1. Message| UserAct
105
+ UserAct --> MissionChat
106
+ MissionChat -->|2. Modified Prompt| LLM
107
+
108
+ LLM -->|3. Tool Call| RoleGuard
109
+ RoleGuard -->|4. Safe?| Tool
110
+ RoleGuard -.->|Blocked| LLM
111
+
112
+ Tool -->|5. Output| Scanner
113
+ Scanner --> UI
114
+ UI --> Resource
115
+ Resource -->|6. Result| LLM
116
+
117
+ LLM -->|7. Turn Done| Sanity
118
+ Sanity --> MissionDone
119
+
120
+ MissionDone -.->|No Seal: Auto-Continue| LLM
121
+ MissionDone -->|Yes Seal: Complete| ResourceComp
122
+ ResourceComp -->|9. Final Response| User
123
+ ```
124
+
70
125
  ---
71
126
 
72
127
  ## 🚀 Agents
@@ -94,6 +149,7 @@ OpenCode Orchestrator manages complex software tasks through **parallel multi-ag
94
149
  OpenCode Orchestrator was developed to solve the "sequential bottleneck" in AI-assisted coding. By treating agents as distributed processing units rather than just chat interfaces, we aim to provide a more reliable and scalable autonomous engineering experience.
95
150
 
96
151
  [Full Developer's Note →](docs/DEVELOPERS_NOTE.md)
152
+
97
153
  [System Architecture →](docs/SYSTEM_ARCHITECTURE.md)
98
154
 
99
155
  ---
@@ -24,6 +24,13 @@ export declare const CONTEXT_MONITOR_CONFIG: {
24
24
  /** Minimum time between alerts (ms) */
25
25
  readonly ALERT_COOLDOWN_MS: 60000;
26
26
  };
27
+ export interface MonitorState {
28
+ lastAlertTime: number;
29
+ lastAlertLevel: "info" | "warning" | "critical" | null;
30
+ isMonitoring: boolean;
31
+ intervalId?: ReturnType<typeof setInterval>;
32
+ }
33
+ export declare function getMonitorState(sessionID: string): MonitorState;
27
34
  /**
28
35
  * Calculate context usage percentage
29
36
  */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * External Plugin Compatibility Hook
3
+ *
4
+ * Detects if other major plugins are present and ensures orchestrator plays nicely.
5
+ */
6
+ import type { ChatMessageHook, AssistantDoneHook, HookContext } from "../types.js";
7
+ export declare class ExternalPluginCompatHook implements ChatMessageHook, AssistantDoneHook {
8
+ name: string;
9
+ execute(ctx: HookContext, input: any): Promise<any>;
10
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Hook Constants
3
+ * Defines strict constant values for hook actions and statuses.
4
+ */
5
+ export declare const HOOK_ACTIONS: {
6
+ readonly CONTINUE: "continue";
7
+ readonly STOP: "stop";
8
+ readonly ALLOW: "allow";
9
+ readonly BLOCK: "block";
10
+ readonly MODIFY: "modify";
11
+ readonly INJECT: "inject";
12
+ readonly PROCESS: "process";
13
+ readonly INTERCEPT: "intercept";
14
+ };
15
+ export declare const HOOK_NAMES: {
16
+ readonly SANITY_CHECK: "SanityCheck";
17
+ readonly MISSION_LOOP: "MissionLoop";
18
+ readonly STRICT_ROLE_GUARD: "StrictRoleGuard";
19
+ readonly SECRET_SCANNER: "SecretScanner";
20
+ readonly AGENT_UI: "AgentUI";
21
+ readonly RESOURCE_CONTROL: "ResourceControl";
22
+ readonly SLASH_COMMAND: "SlashCommandDispatcher";
23
+ readonly USER_ACTIVITY: "UserActivity";
24
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Agent UI Hook
3
+ *
4
+ * Decorates tool outputs with UI elements:
5
+ * - Agent headers (e.g. [P] PLANNER Working...)
6
+ * - Task ID tracking
7
+ */
8
+ import type { PostToolUseHook, HookContext } from "../types.js";
9
+ export declare class AgentUIHook implements PostToolUseHook {
10
+ name: "AgentUI";
11
+ execute(ctx: HookContext, tool: string, input: any, output: {
12
+ title: string;
13
+ output: string;
14
+ metadata: any;
15
+ }): Promise<{
16
+ output?: undefined;
17
+ } | {
18
+ output: string;
19
+ }>;
20
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Resource Control Hook
3
+ *
4
+ * Unifies resource tracking, monitoring, and active memory compaction.
5
+ * Replaces separate ResourceUsageHook and MemoryCompactionHook.
6
+ */
7
+ import type { PostToolUseHook, AssistantDoneHook, HookContext } from "../types.js";
8
+ export declare class ResourceControlHook implements PostToolUseHook, AssistantDoneHook {
9
+ name: "ResourceControl";
10
+ private lastCompactionTime;
11
+ execute(ctx: HookContext, toolOrText: string, input?: any, output?: any): Promise<any>;
12
+ private checkMemoryHealth;
13
+ private generateCompactionPrompt;
14
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Secret Scanner Hook
3
+ *
4
+ * Scans tool outputs for potential secrets (API Keys, etc) and masks them.
5
+ * This prevents leaking secrets into the context window or logs.
6
+ */
7
+ import type { PostToolUseHook, HookContext } from "../types.js";
8
+ export declare class SecretScannerHook implements PostToolUseHook {
9
+ name: "SecretScanner";
10
+ execute(ctx: HookContext, tool: string, input: any, output: {
11
+ title: string;
12
+ output: string;
13
+ metadata: any;
14
+ }): Promise<{
15
+ output: string;
16
+ } | {
17
+ output?: undefined;
18
+ }>;
19
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Strict Role Guard Hook
3
+ *
4
+ * Enforces role-based access control (RBAC) for agents.
5
+ * - Planner: Cannot write code or run commands.
6
+ * - Reviewer: Cannot write code (only review).
7
+ */
8
+ import type { PreToolUseHook, HookContext } from "../types.js";
9
+ export declare class StrictRoleGuardHook implements PreToolUseHook {
10
+ name: "StrictRoleGuard";
11
+ execute(ctx: HookContext, tool: string, args: any): Promise<{
12
+ action: "block";
13
+ reason: string;
14
+ } | {
15
+ action: "allow";
16
+ reason?: undefined;
17
+ }>;
18
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * User Activity Hook
3
+ *
4
+ * Tracks user interaction (chat messages) to pause auto-continuation/loops
5
+ * and update activity timestamps.
6
+ */
7
+ import type { ChatMessageHook, HookContext } from "../types.js";
8
+ export declare class UserActivityHook implements ChatMessageHook {
9
+ name: "UserActivity";
10
+ execute(ctx: HookContext, message: string): Promise<any>;
11
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Mission Loop Hook
3
+ *
4
+ * Handles:
5
+ * - Mission seal detection (Stop)
6
+ * - Auto-continuation injection (Loop)
7
+ * - User cancellation detection
8
+ */
9
+ import type { AssistantDoneHook, ChatMessageHook, HookContext } from "../types.js";
10
+ export declare class MissionControlHook implements AssistantDoneHook, ChatMessageHook {
11
+ name: "MissionLoop";
12
+ execute(ctx: HookContext, text: string): Promise<any>;
13
+ private handleChatCommand;
14
+ private handleMissionSeal;
15
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Sanity Check Hook
3
+ * Implements output anomaly detection.
4
+ */
5
+ import type { PostToolUseHook, AssistantDoneHook, HookContext } from "../types.js";
6
+ export declare class SanityCheckHook implements PostToolUseHook, AssistantDoneHook {
7
+ name: "SanityCheck";
8
+ execute(ctx: HookContext, toolOrText: string, input?: any, output?: {
9
+ title: string;
10
+ output: string;
11
+ metadata: any;
12
+ }): Promise<any>;
13
+ private checkToolOutput;
14
+ private checkFinalText;
15
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Initialize Hooks
3
+ * Registers all default hooks.
4
+ */
5
+ export declare function initializeHooks(): void;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Hook Registry
3
+ * Manages registration and execution of hooks.
4
+ */
5
+ import type { PreToolUseHook, PostToolUseHook, ChatMessageHook, AssistantDoneHook, HookContext, HookResult } from "./types.js";
6
+ import { HOOK_ACTIONS } from "./constants.js";
7
+ export declare class HookRegistry {
8
+ private static instance;
9
+ private preToolHooks;
10
+ private postToolHooks;
11
+ private chatHooks;
12
+ private doneHooks;
13
+ private constructor();
14
+ static getInstance(): HookRegistry;
15
+ registerPreTool(hook: PreToolUseHook): void;
16
+ registerPostTool(hook: PostToolUseHook): void;
17
+ registerChat(hook: ChatMessageHook): void;
18
+ registerDone(hook: AssistantDoneHook): void;
19
+ executePreTool(ctx: HookContext, tool: string, args: any): Promise<{
20
+ action: typeof HOOK_ACTIONS.ALLOW | typeof HOOK_ACTIONS.BLOCK | typeof HOOK_ACTIONS.MODIFY;
21
+ modifiedArgs?: any;
22
+ reason?: string;
23
+ }>;
24
+ executePostTool(ctx: HookContext, tool: string, input: any, output: {
25
+ title: string;
26
+ output: string;
27
+ metadata: any;
28
+ }): Promise<void>;
29
+ executeChat(ctx: HookContext, message: string): Promise<{
30
+ action: typeof HOOK_ACTIONS.PROCESS | typeof HOOK_ACTIONS.INTERCEPT;
31
+ modifiedMessage?: string;
32
+ }>;
33
+ executeDone(ctx: HookContext, finalText: string): Promise<HookResult>;
34
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Hook System Types
3
+ * Defines the contract for all hooks in the system.
4
+ */
5
+ import { HOOK_ACTIONS } from "./constants.js";
6
+ export interface HookContext {
7
+ sessionID: string;
8
+ agent?: string;
9
+ directory: string;
10
+ sessions: Map<string, any>;
11
+ }
12
+ export type HookResult = {
13
+ action: typeof HOOK_ACTIONS.CONTINUE;
14
+ } | {
15
+ action: typeof HOOK_ACTIONS.STOP;
16
+ reason?: string;
17
+ } | {
18
+ action: typeof HOOK_ACTIONS.INJECT;
19
+ prompts: string[];
20
+ };
21
+ /**
22
+ * Pre-Tool Execution Hook
23
+ * Runs before a tool is executed. Can block execution or modify arguments.
24
+ */
25
+ export interface PreToolUseHook {
26
+ name: string;
27
+ execute(context: HookContext, tool: string, args: any): Promise<{
28
+ action: typeof HOOK_ACTIONS.ALLOW | typeof HOOK_ACTIONS.BLOCK | typeof HOOK_ACTIONS.MODIFY;
29
+ modifiedArgs?: any;
30
+ reason?: string;
31
+ }>;
32
+ }
33
+ /**
34
+ * Post-Tool Execution Hook
35
+ * Runs after a tool is executed. Can analyze output or trigger side effects.
36
+ */
37
+ export interface PostToolUseHook {
38
+ name: string;
39
+ execute(context: HookContext, tool: string, input: any, output: {
40
+ title: string;
41
+ output: string;
42
+ metadata: any;
43
+ }): Promise<{
44
+ output?: string;
45
+ }>;
46
+ }
47
+ /**
48
+ * Chat Message Hook
49
+ * Runs when a user sends a message. Can intercept commands.
50
+ */
51
+ export interface ChatMessageHook {
52
+ name: string;
53
+ execute(context: HookContext, message: string): Promise<{
54
+ action: typeof HOOK_ACTIONS.PROCESS | typeof HOOK_ACTIONS.INTERCEPT;
55
+ modifiedMessage?: string;
56
+ }>;
57
+ }
58
+ /**
59
+ * Assistant Done Hook
60
+ * Runs when the assistant finishes a turn. Can inject continuation prompts.
61
+ */
62
+ export interface AssistantDoneHook {
63
+ name: string;
64
+ execute(context: HookContext, finalText: string): Promise<HookResult>;
65
+ }