opencode-orchestrator 0.6.19 → 0.6.21

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.
@@ -6,4 +6,3 @@
6
6
  export type { ToastVariant, ToastMessage, ToastOptions } from "./types.js";
7
7
  export { show, dismiss, getActive, getHistory, clear, onToast, initToastClient } from "./toast-core.js";
8
8
  export { presets } from "./presets.js";
9
- export { enableAutoToasts } from "./event-integration.js";
package/dist/index.js CHANGED
@@ -545,11 +545,22 @@ Blocked: [if any]
545
545
  </context_format>
546
546
 
547
547
  <summarization>
548
- When context gets long:
549
- 1. Create .opencode/summary.md
550
- 2. Keep key decisions, file changes
551
- 3. Remove verbose details
552
- 4. Team references summary instead
548
+ CRITICAL: Prevent .opencode/ from growing too large!
549
+
550
+ AFTER EVERY MAJOR UPDATE:
551
+ 1. Check file sizes in .opencode/
552
+ 2. If context.md > 200 lines \u2192 SUMMARIZE NOW
553
+
554
+ SUMMARIZE:
555
+ - Create/update .opencode/summary.md
556
+ - Keep: key decisions, file changes, blockers
557
+ - Remove: verbose logs, old iterations
558
+ - Team reads summary, not full history
559
+
560
+ CLEANUP OLD:
561
+ - Archive old context to .opencode/archive/
562
+ - Delete temporary notes
563
+ - Keep only current state
553
564
  </summarization>
554
565
 
555
566
  <output>
@@ -14160,36 +14171,6 @@ var presets = {
14160
14171
  })
14161
14172
  };
14162
14173
 
14163
- // src/core/session/store.ts
14164
- var contexts = /* @__PURE__ */ new Map();
14165
- var parentChildMap = /* @__PURE__ */ new Map();
14166
- function create(sessionId, parentId) {
14167
- const context = {
14168
- sessionId,
14169
- parentId,
14170
- documents: /* @__PURE__ */ new Map(),
14171
- findings: [],
14172
- decisions: /* @__PURE__ */ new Map(),
14173
- createdAt: /* @__PURE__ */ new Date(),
14174
- updatedAt: /* @__PURE__ */ new Date()
14175
- };
14176
- contexts.set(sessionId, context);
14177
- if (parentId) {
14178
- if (!parentChildMap.has(parentId)) {
14179
- parentChildMap.set(parentId, /* @__PURE__ */ new Set());
14180
- }
14181
- parentChildMap.get(parentId).add(sessionId);
14182
- }
14183
- return context;
14184
- }
14185
- function clear(sessionId) {
14186
- const context = contexts.get(sessionId);
14187
- if (context?.parentId) {
14188
- parentChildMap.get(context.parentId)?.delete(sessionId);
14189
- }
14190
- contexts.delete(sessionId);
14191
- }
14192
-
14193
14174
  // src/core/agents/manager/task-launcher.ts
14194
14175
  var TaskLauncher = class {
14195
14176
  constructor(client, directory, store, concurrency, onTaskError, startPolling) {
@@ -14232,8 +14213,6 @@ var TaskLauncher = class {
14232
14213
  };
14233
14214
  this.store.set(taskId, task);
14234
14215
  this.store.trackPending(input.parentSessionID, taskId);
14235
- create(sessionID, input.parentSessionID);
14236
- log2(`[task-launcher.ts] Created shared context for session ${sessionID}`);
14237
14216
  this.startPolling();
14238
14217
  this.client.session.prompt({
14239
14218
  path: { id: sessionID },
@@ -14462,7 +14441,6 @@ var TaskCleaner = class {
14462
14441
  }
14463
14442
  this.client.session.delete({ path: { id: task.sessionID } }).catch(() => {
14464
14443
  });
14465
- clear(task.sessionID);
14466
14444
  this.store.delete(taskId);
14467
14445
  }
14468
14446
  this.store.cleanEmptyNotifications();
@@ -14476,7 +14454,6 @@ var TaskCleaner = class {
14476
14454
  await this.client.session.delete({ path: { id: sessionID } });
14477
14455
  } catch {
14478
14456
  }
14479
- clear(sessionID);
14480
14457
  }
14481
14458
  this.store.delete(taskId);
14482
14459
  log2(`Cleaned up ${taskId}`);
@@ -14500,180 +14477,11 @@ var TaskCleaner = class {
14500
14477
  }
14501
14478
  };
14502
14479
 
14503
- // src/shared/event-types.ts
14504
- var TASK_EVENTS = {
14505
- STARTED: "task.started",
14506
- COMPLETED: "task.completed",
14507
- FAILED: "task.failed",
14508
- CANCELLED: "task.cancelled"
14509
- };
14510
- var TODO_EVENTS = {
14511
- CREATED: "todo.created",
14512
- UPDATED: "todo.updated",
14513
- COMPLETED: "todo.completed"
14514
- };
14480
+ // src/core/agents/manager/event-handler.ts
14515
14481
  var SESSION_EVENTS = {
14516
14482
  IDLE: "session.idle",
14517
- BUSY: "session.busy",
14518
- ERROR: "session.error",
14519
14483
  DELETED: "session.deleted"
14520
14484
  };
14521
- var DOCUMENT_EVENTS = {
14522
- CACHED: "document.cached",
14523
- EXPIRED: "document.expired"
14524
- };
14525
- var MISSION_EVENTS = {
14526
- COMPLETE: "mission.complete",
14527
- FAILED: "mission.failed",
14528
- ALL_TASKS_COMPLETE: "all_tasks.complete"
14529
- };
14530
- var SPECIAL_EVENTS = {
14531
- WILDCARD: "*"
14532
- };
14533
- var EVENT_TYPES = {
14534
- ...TASK_EVENTS,
14535
- ...TODO_EVENTS,
14536
- ...SESSION_EVENTS,
14537
- ...DOCUMENT_EVENTS,
14538
- ...MISSION_EVENTS,
14539
- ...SPECIAL_EVENTS
14540
- };
14541
-
14542
- // src/core/bus/event-bus.ts
14543
- var EventBusImpl = class {
14544
- subscriptions = /* @__PURE__ */ new Map();
14545
- eventHistory = [];
14546
- maxHistorySize = 100;
14547
- subscriptionCounter = 0;
14548
- /**
14549
- * Subscribe to an event type
14550
- * Returns unsubscribe function
14551
- */
14552
- subscribe(type, handler) {
14553
- const id = `sub_${++this.subscriptionCounter}`;
14554
- const subscription = { id, type, handler, once: false };
14555
- const existing = this.subscriptions.get(type) || [];
14556
- existing.push(subscription);
14557
- this.subscriptions.set(type, existing);
14558
- return () => this.unsubscribe(id, type);
14559
- }
14560
- /**
14561
- * Subscribe to an event type, auto-unsubscribe after first event
14562
- */
14563
- once(type, handler) {
14564
- const id = `sub_${++this.subscriptionCounter}`;
14565
- const subscription = { id, type, handler, once: true };
14566
- const existing = this.subscriptions.get(type) || [];
14567
- existing.push(subscription);
14568
- this.subscriptions.set(type, existing);
14569
- return () => this.unsubscribe(id, type);
14570
- }
14571
- /**
14572
- * Unsubscribe from an event
14573
- */
14574
- unsubscribe(id, type) {
14575
- const subs = this.subscriptions.get(type);
14576
- if (subs) {
14577
- const filtered = subs.filter((s) => s.id !== id);
14578
- if (filtered.length > 0) {
14579
- this.subscriptions.set(type, filtered);
14580
- } else {
14581
- this.subscriptions.delete(type);
14582
- }
14583
- }
14584
- }
14585
- /**
14586
- * Publish an event
14587
- */
14588
- async publish(type, properties = {}, options = {}) {
14589
- const event = {
14590
- type,
14591
- timestamp: /* @__PURE__ */ new Date(),
14592
- source: options.source || "unknown",
14593
- sessionId: options.sessionId,
14594
- properties
14595
- };
14596
- this.eventHistory.push(event);
14597
- if (this.eventHistory.length > this.maxHistorySize) {
14598
- this.eventHistory.shift();
14599
- }
14600
- const toNotify = [];
14601
- const typeSubs = this.subscriptions.get(type) || [];
14602
- toNotify.push(...typeSubs);
14603
- const wildcardSubs = this.subscriptions.get(SPECIAL_EVENTS.WILDCARD) || [];
14604
- toNotify.push(...wildcardSubs);
14605
- const toRemove = [];
14606
- for (const sub of toNotify) {
14607
- try {
14608
- await sub.handler(event);
14609
- } catch (error45) {
14610
- console.error(`[EventBus] Handler error for ${type}:`, error45);
14611
- }
14612
- if (sub.once) {
14613
- toRemove.push({ id: sub.id, type: sub.type });
14614
- }
14615
- }
14616
- for (const { id, type: t } of toRemove) {
14617
- this.unsubscribe(id, t);
14618
- }
14619
- }
14620
- /**
14621
- * Emit (alias for publish, sync-looking API)
14622
- */
14623
- emit(type, properties = {}) {
14624
- this.publish(type, properties).catch(console.error);
14625
- }
14626
- /**
14627
- * Get recent event history
14628
- */
14629
- getHistory(type, limit = 20) {
14630
- let events = this.eventHistory;
14631
- if (type && type !== SPECIAL_EVENTS.WILDCARD) {
14632
- events = events.filter((e) => e.type === type);
14633
- }
14634
- return events.slice(-limit);
14635
- }
14636
- /**
14637
- * Clear all subscriptions
14638
- */
14639
- clear() {
14640
- this.subscriptions.clear();
14641
- this.eventHistory = [];
14642
- }
14643
- /**
14644
- * Get subscription count
14645
- */
14646
- getSubscriptionCount() {
14647
- let count = 0;
14648
- for (const subs of this.subscriptions.values()) {
14649
- count += subs.length;
14650
- }
14651
- return count;
14652
- }
14653
- /**
14654
- * Wait for a specific event (Promise-based)
14655
- */
14656
- waitFor(type, timeout = 3e4) {
14657
- return new Promise((resolve, reject) => {
14658
- const timer = setTimeout(() => {
14659
- unsubscribe();
14660
- reject(new Error(`Timeout waiting for event: ${type}`));
14661
- }, timeout);
14662
- const unsubscribe = this.once(type, (event) => {
14663
- clearTimeout(timer);
14664
- resolve(event);
14665
- });
14666
- });
14667
- }
14668
- };
14669
-
14670
- // src/core/bus/index.ts
14671
- var EventBus = new EventBusImpl();
14672
- function emit(type, properties) {
14673
- EventBus.emit(type, properties);
14674
- }
14675
-
14676
- // src/core/agents/manager/event-handler.ts
14677
14485
  var EventHandler = class {
14678
14486
  constructor(client, store, concurrency, findBySession, notifyParentIfAllComplete, scheduleCleanup, validateSessionHasOutput) {
14679
14487
  this.client = client;
@@ -15388,7 +15196,7 @@ async function list() {
15388
15196
  expired: new Date(entry.expiresAt) < now
15389
15197
  }));
15390
15198
  }
15391
- async function clear2() {
15199
+ async function clear() {
15392
15200
  const metadata = await readMetadata();
15393
15201
  const count = Object.keys(metadata.documents).length;
15394
15202
  for (const filename of Object.keys(metadata.documents)) {
@@ -15865,7 +15673,7 @@ Cached: ${doc.fetchedAt}
15865
15673
  ${doc.content}`;
15866
15674
  }
15867
15675
  case "clear": {
15868
- const count = await clear2();
15676
+ const count = await clear();
15869
15677
  return `\u{1F5D1}\uFE0F Cleared ${count} cached documents`;
15870
15678
  }
15871
15679
  case "stats": {
@@ -16043,40 +15851,6 @@ ${r.content}
16043
15851
  }
16044
15852
  });
16045
15853
 
16046
- // src/core/notification/event-integration.ts
16047
- function enableAutoToasts() {
16048
- const unsubscribers = [];
16049
- unsubscribers.push(EventBus.subscribe(TASK_EVENTS.STARTED, (event) => {
16050
- const { taskId, agent } = event.properties;
16051
- presets.taskStarted(taskId, agent);
16052
- }));
16053
- unsubscribers.push(EventBus.subscribe(TASK_EVENTS.COMPLETED, (event) => {
16054
- const { taskId, agent } = event.properties;
16055
- presets.taskCompleted(taskId, agent);
16056
- }));
16057
- unsubscribers.push(EventBus.subscribe(TASK_EVENTS.FAILED, (event) => {
16058
- const { taskId, error: error45 } = event.properties;
16059
- presets.taskFailed(taskId, error45);
16060
- }));
16061
- unsubscribers.push(EventBus.subscribe(MISSION_EVENTS.ALL_TASKS_COMPLETE, (event) => {
16062
- const { count } = event.properties;
16063
- presets.allTasksComplete(count);
16064
- }));
16065
- unsubscribers.push(EventBus.subscribe(MISSION_EVENTS.COMPLETE, (event) => {
16066
- const { summary } = event.properties;
16067
- presets.missionComplete(summary);
16068
- }));
16069
- unsubscribers.push(EventBus.subscribe(DOCUMENT_EVENTS.CACHED, (event) => {
16070
- const { filename } = event.properties;
16071
- presets.documentCached(filename);
16072
- }));
16073
- return () => {
16074
- for (const unsub of unsubscribers) {
16075
- unsub();
16076
- }
16077
- };
16078
- }
16079
-
16080
15854
  // src/core/progress/store.ts
16081
15855
  var progressHistory = /* @__PURE__ */ new Map();
16082
15856
  var sessionStartTimes = /* @__PURE__ */ new Map();
@@ -16198,7 +15972,6 @@ var OrchestratorPlugin = async (input) => {
16198
15972
  console.log(`[orchestrator] Log file: ${getLogPath()}`);
16199
15973
  log2("[index.ts] Plugin initialized", { version: PLUGIN_VERSION, directory });
16200
15974
  initToastClient(client);
16201
- const disableAutoToasts = enableAutoToasts();
16202
15975
  log2("[index.ts] Toast notifications enabled with TUI");
16203
15976
  const sessions = /* @__PURE__ */ new Map();
16204
15977
  const parallelAgentManager2 = ParallelAgentManager.getInstance(client, directory);
@@ -16341,7 +16114,7 @@ var OrchestratorPlugin = async (input) => {
16341
16114
  log2("[index.ts] event: session.created", { sessionID });
16342
16115
  presets.missionStarted(`Session ${sessionID.slice(0, 12)}...`);
16343
16116
  }
16344
- if (event.type === "session.deleted" || event.type === SESSION_EVENTS.DELETED) {
16117
+ if (event.type === "session.deleted") {
16345
16118
  const sessionID = event.properties?.id || event.properties?.info?.id || "";
16346
16119
  const session = sessions.get(sessionID);
16347
16120
  if (session) {
@@ -16398,11 +16171,7 @@ var OrchestratorPlugin = async (input) => {
16398
16171
  anomalyCount: 0
16399
16172
  });
16400
16173
  startSession(sessionID);
16401
- emit(TASK_EVENTS.STARTED, {
16402
- taskId: sessionID,
16403
- agent: AGENT_NAMES.COMMANDER,
16404
- description: "Mission started"
16405
- });
16174
+ presets.taskStarted(sessionID, AGENT_NAMES.COMMANDER);
16406
16175
  }
16407
16176
  if (!parsed || parsed.command !== "task") {
16408
16177
  const taskTemplate = COMMANDS["task"].template;
@@ -16561,10 +16330,7 @@ Anomaly count: ${stateSession.anomalyCount}
16561
16330
  if (textContent.includes(MISSION.COMPLETE) || textContent.includes(MISSION.COMPLETE_TEXT)) {
16562
16331
  session.active = false;
16563
16332
  state.missionActive = false;
16564
- emit(MISSION_EVENTS.COMPLETE, {
16565
- sessionId: sessionID,
16566
- summary: "Mission completed successfully"
16567
- });
16333
+ presets.missionComplete("Mission completed successfully");
16568
16334
  clearSession(sessionID);
16569
16335
  sessions.delete(sessionID);
16570
16336
  state.sessions.delete(sessionID);
@@ -16573,10 +16339,7 @@ Anomaly count: ${stateSession.anomalyCount}
16573
16339
  if (textContent.includes(MISSION.STOP_COMMAND) || textContent.includes(MISSION.CANCEL_COMMAND)) {
16574
16340
  session.active = false;
16575
16341
  state.missionActive = false;
16576
- emit(TASK_EVENTS.FAILED, {
16577
- taskId: sessionID,
16578
- error: "Cancelled by user"
16579
- });
16342
+ presets.taskFailed(sessionID, "Cancelled by user");
16580
16343
  clearSession(sessionID);
16581
16344
  sessions.delete(sessionID);
16582
16345
  state.sessions.delete(sessionID);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "opencode-orchestrator",
3
3
  "displayName": "OpenCode Orchestrator",
4
4
  "description": "Distributed Cognitive Architecture for OpenCode. Turns simple prompts into specialized multi-agent workflows (Planner, Coder, Reviewer).",
5
- "version": "0.6.19",
5
+ "version": "0.6.21",
6
6
  "author": "agnusdei1207",
7
7
  "license": "MIT",
8
8
  "repository": {
@@ -1,53 +0,0 @@
1
- /**
2
- * Event Bus Implementation
3
- *
4
- * Core pub/sub system for communication between sessions and agents
5
- */
6
- import type { EventType } from "./types.js";
7
- import type { BusEvent, EventHandler } from "./interfaces.js";
8
- export declare class EventBusImpl {
9
- private subscriptions;
10
- private eventHistory;
11
- private maxHistorySize;
12
- private subscriptionCounter;
13
- /**
14
- * Subscribe to an event type
15
- * Returns unsubscribe function
16
- */
17
- subscribe(type: EventType, handler: EventHandler): () => void;
18
- /**
19
- * Subscribe to an event type, auto-unsubscribe after first event
20
- */
21
- once(type: EventType, handler: EventHandler): () => void;
22
- /**
23
- * Unsubscribe from an event
24
- */
25
- private unsubscribe;
26
- /**
27
- * Publish an event
28
- */
29
- publish(type: EventType, properties?: Record<string, unknown>, options?: {
30
- source?: string;
31
- sessionId?: string;
32
- }): Promise<void>;
33
- /**
34
- * Emit (alias for publish, sync-looking API)
35
- */
36
- emit(type: EventType, properties?: Record<string, unknown>): void;
37
- /**
38
- * Get recent event history
39
- */
40
- getHistory(type?: EventType, limit?: number): BusEvent[];
41
- /**
42
- * Clear all subscriptions
43
- */
44
- clear(): void;
45
- /**
46
- * Get subscription count
47
- */
48
- getSubscriptionCount(): number;
49
- /**
50
- * Wait for a specific event (Promise-based)
51
- */
52
- waitFor(type: EventType, timeout?: number): Promise<BusEvent>;
53
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Event Bus System
3
- *
4
- * Pub/Sub system for communication between sessions and agents
5
- * Enables loose coupling and async event handling
6
- */
7
- export type { EventType, EventProperties } from "./types.js";
8
- export type { BusEvent, EventHandler, Subscription, PublishOptions } from "./interfaces.js";
9
- export { EVENT_TYPES, TASK_EVENTS, TODO_EVENTS, SESSION_EVENTS, DOCUMENT_EVENTS, MISSION_EVENTS, SPECIAL_EVENTS, } from "../../shared/event-types.js";
10
- import { EventBusImpl } from "./event-bus.js";
11
- import type { EventType, EventProperties } from "./types.js";
12
- import type { EventHandler } from "./interfaces.js";
13
- export declare const EventBus: EventBusImpl;
14
- export declare function subscribe(type: EventType, handler: EventHandler): () => void;
15
- export declare function publish(type: EventType, properties?: EventProperties, options?: {
16
- source?: string;
17
- sessionId?: string;
18
- }): Promise<void>;
19
- export declare function emit(type: EventType, properties?: EventProperties): void;
@@ -1,34 +0,0 @@
1
- /**
2
- * Event Bus Interfaces
3
- */
4
- import type { EventType, EventProperties } from "./types.js";
5
- /**
6
- * Event payload structure
7
- */
8
- export interface BusEvent {
9
- type: EventType;
10
- timestamp: Date;
11
- source: string;
12
- sessionId?: string;
13
- properties: EventProperties;
14
- }
15
- /**
16
- * Event handler function signature
17
- */
18
- export type EventHandler = (event: BusEvent) => void | Promise<void>;
19
- /**
20
- * Internal subscription record
21
- */
22
- export interface Subscription {
23
- id: string;
24
- type: EventType;
25
- handler: EventHandler;
26
- once: boolean;
27
- }
28
- /**
29
- * Publish options
30
- */
31
- export interface PublishOptions {
32
- source?: string;
33
- sessionId?: string;
34
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Event Bus Types (Type Aliases Only)
3
- */
4
- import type { EventTypeValue } from "../../shared/event-types.js";
5
- /**
6
- * Event type - allows constants or custom strings
7
- */
8
- export type EventType = EventTypeValue | (string & {});
9
- /**
10
- * Properties payload for events
11
- */
12
- export type EventProperties = Record<string, unknown>;
@@ -1,7 +0,0 @@
1
- /**
2
- * Event Bus Integration - Auto-subscribe to events
3
- */
4
- /**
5
- * Auto-subscribe to events and show toasts
6
- */
7
- export declare function enableAutoToasts(): () => void;