opencode-orchestrator 0.5.12 → 0.5.17
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/LICENSE +21 -21
- package/README.md +437 -92
- package/dist/agents/subagents/librarian.d.ts +10 -0
- package/dist/agents/subagents/researcher.d.ts +11 -0
- package/dist/core/agents/concurrency.d.ts +2 -6
- package/dist/core/agents/config.d.ts +1 -1
- package/dist/core/agents/consts/index.d.ts +4 -0
- package/dist/core/agents/consts/task-status.const.d.ts +12 -0
- package/dist/core/agents/interfaces/concurrency-config.interface.d.ts +9 -0
- package/dist/core/agents/interfaces/index.d.ts +6 -3
- package/dist/core/agents/interfaces/{parallel-task.d.ts → parallel-task.interface.d.ts} +4 -8
- package/dist/core/agents/interfaces/resume-input.interface.d.ts +17 -0
- package/dist/core/agents/interfaces/task-progress.interface.d.ts +9 -0
- package/dist/core/agents/manager/event-handler.d.ts +34 -0
- package/dist/core/agents/manager/index.d.ts +10 -0
- package/dist/core/agents/manager/task-cleaner.d.ts +17 -0
- package/dist/core/agents/manager/task-launcher.d.ts +20 -0
- package/dist/core/agents/manager/task-poller.d.ts +26 -0
- package/dist/core/agents/manager/task-resumer.d.ts +18 -0
- package/dist/core/agents/manager.d.ts +11 -29
- package/dist/core/agents/task-store.d.ts +29 -3
- package/dist/core/agents/types/index.d.ts +1 -1
- package/dist/core/agents/types/parallel-task-status.type.d.ts +4 -0
- package/dist/core/bus/event-bus.d.ts +53 -0
- package/dist/core/bus/index.d.ts +19 -0
- package/dist/core/bus/interfaces.d.ts +34 -0
- package/dist/core/bus/types.d.ts +12 -0
- package/dist/core/cache/constants.d.ts +6 -0
- package/dist/core/cache/document-cache.d.ts +6 -0
- package/dist/core/cache/index.d.ts +4 -0
- package/dist/core/cache/interfaces.d.ts +53 -0
- package/dist/core/cache/operations.d.ts +36 -0
- package/dist/core/cache/utils.d.ts +20 -0
- package/dist/core/loop/formatters.d.ts +16 -0
- package/dist/core/loop/interfaces.d.ts +34 -0
- package/dist/core/loop/parser.d.ts +8 -0
- package/dist/core/loop/stats.d.ts +24 -0
- package/dist/core/loop/todo-enforcer.d.ts +9 -0
- package/dist/core/notification/event-integration.d.ts +7 -0
- package/dist/core/notification/presets.d.ts +14 -0
- package/dist/core/notification/toast-core.d.ts +28 -0
- package/dist/core/notification/toast.d.ts +9 -0
- package/dist/core/notification/types.d.ts +19 -0
- package/dist/core/orchestrator/types/task-status.d.ts +2 -2
- package/dist/core/progress/calculator.d.ts +11 -0
- package/dist/core/progress/formatters.d.ts +20 -0
- package/dist/core/progress/interfaces.d.ts +54 -0
- package/dist/core/progress/store.d.ts +28 -0
- package/dist/core/progress/tracker.d.ts +11 -0
- package/dist/core/queue/async-queue.d.ts +46 -0
- package/dist/core/queue/async-utils.d.ts +20 -0
- package/dist/core/queue/index.d.ts +8 -0
- package/dist/core/queue/work-pool.d.ts +19 -0
- package/dist/core/recovery/auto-recovery.d.ts +9 -0
- package/dist/core/recovery/constants.d.ts +6 -0
- package/dist/core/recovery/handler.d.ts +27 -0
- package/dist/core/recovery/interfaces.d.ts +63 -0
- package/dist/core/recovery/patterns.d.ts +8 -0
- package/dist/core/session/interfaces.d.ts +53 -0
- package/dist/core/session/shared-context.d.ts +8 -0
- package/dist/core/session/store.d.ts +44 -0
- package/dist/core/session/summary.d.ts +7 -0
- package/dist/core/task/interfaces.d.ts +54 -0
- package/dist/core/task/parser.d.ts +8 -0
- package/dist/core/task/scheduler.d.ts +12 -0
- package/dist/core/task/store.d.ts +32 -0
- package/dist/core/task/summary.d.ts +7 -0
- package/dist/core/task/task-decomposer.d.ts +10 -0
- package/dist/index.d.ts +56 -2
- package/dist/index.js +2605 -690
- package/dist/scripts/postinstall.js +0 -0
- package/dist/scripts/preuninstall.js +0 -0
- package/dist/shared/agent.d.ts +2 -0
- package/dist/shared/constants.d.ts +56 -3
- package/dist/shared/event-types.d.ts +77 -0
- package/dist/tools/background-cmd/list.d.ts +2 -2
- package/dist/tools/parallel/delegate-task.d.ts +3 -0
- package/dist/tools/web/cache-docs.d.ts +21 -0
- package/dist/tools/web/codesearch.d.ts +19 -0
- package/dist/tools/web/index.d.ts +9 -0
- package/dist/tools/web/webfetch.d.ts +19 -0
- package/dist/tools/web/websearch.d.ts +17 -0
- package/package.json +74 -73
- package/dist/core/agents/types/parallel-task-status.d.ts +0 -4
- /package/dist/core/agents/interfaces/{launch-input.d.ts → launch-input.interface.d.ts} +0 -0
|
@@ -6,12 +6,8 @@
|
|
|
6
6
|
* - Provider-specific limits (e.g., anthropic/*, openai/*)
|
|
7
7
|
* - Model-specific limits (e.g., anthropic/claude-3-5-sonnet)
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
agentConcurrency?: Record<string, number>;
|
|
12
|
-
providerConcurrency?: Record<string, number>;
|
|
13
|
-
modelConcurrency?: Record<string, number>;
|
|
14
|
-
}
|
|
9
|
+
import type { ConcurrencyConfig } from "./interfaces/concurrency-config.interface.js";
|
|
10
|
+
export type { ConcurrencyConfig } from "./interfaces/concurrency-config.interface.js";
|
|
15
11
|
export declare class ConcurrencyController {
|
|
16
12
|
private counts;
|
|
17
13
|
private queues;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TASK_STATUS - Task status constants
|
|
3
|
+
*/
|
|
4
|
+
export declare const TASK_STATUS: {
|
|
5
|
+
readonly PENDING: "pending";
|
|
6
|
+
readonly RUNNING: "running";
|
|
7
|
+
readonly COMPLETED: "completed";
|
|
8
|
+
readonly FAILED: "failed";
|
|
9
|
+
readonly ERROR: "error";
|
|
10
|
+
readonly TIMEOUT: "timeout";
|
|
11
|
+
readonly CANCELLED: "cancelled";
|
|
12
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Agents Interfaces Index
|
|
3
3
|
*/
|
|
4
|
-
export { ParallelTask } from "./parallel-task.js";
|
|
5
|
-
export {
|
|
4
|
+
export type { ParallelTask } from "./parallel-task.interface.js";
|
|
5
|
+
export type { TaskProgress } from "./task-progress.interface.js";
|
|
6
|
+
export type { LaunchInput } from "./launch-input.interface.js";
|
|
7
|
+
export type { ResumeInput } from "./resume-input.interface.js";
|
|
8
|
+
export type { ConcurrencyConfig } from "./concurrency-config.interface.js";
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ParallelTask - Represents a task running in a parallel session
|
|
2
|
+
* ParallelTask Interface - Represents a task running in a parallel session
|
|
3
3
|
*/
|
|
4
|
-
import { ParallelTaskStatus } from "../types/parallel-task-status.js";
|
|
5
|
-
|
|
6
|
-
toolCalls: number;
|
|
7
|
-
lastTool?: string;
|
|
8
|
-
lastMessage?: string;
|
|
9
|
-
lastUpdate: Date;
|
|
10
|
-
}
|
|
4
|
+
import type { ParallelTaskStatus } from "../types/parallel-task-status.type.js";
|
|
5
|
+
import type { TaskProgress } from "./task-progress.interface.js";
|
|
11
6
|
export interface ParallelTask {
|
|
12
7
|
id: string;
|
|
13
8
|
sessionID: string;
|
|
14
9
|
parentSessionID: string;
|
|
15
10
|
description: string;
|
|
11
|
+
prompt: string;
|
|
16
12
|
agent: string;
|
|
17
13
|
status: ParallelTaskStatus;
|
|
18
14
|
startedAt: Date;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ResumeInput - Input for resuming an existing parallel task session
|
|
3
|
+
*
|
|
4
|
+
* This allows continuing work in an existing session, preserving all context.
|
|
5
|
+
* Useful for:
|
|
6
|
+
* - Retry after failure (don't start from scratch)
|
|
7
|
+
* - Follow-up questions to previous work
|
|
8
|
+
* - Token efficiency (reuse context)
|
|
9
|
+
*/
|
|
10
|
+
export interface ResumeInput {
|
|
11
|
+
/** Session ID to resume (from previous task.sessionID) */
|
|
12
|
+
sessionId: string;
|
|
13
|
+
/** New prompt to send to the resumed session */
|
|
14
|
+
prompt: string;
|
|
15
|
+
/** New parent session ID for notifications */
|
|
16
|
+
parentSessionID: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Handler - Handles OpenCode session events
|
|
3
|
+
*/
|
|
4
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
|
+
import { TaskStore } from "../task-store.js";
|
|
6
|
+
import { ConcurrencyController } from "../concurrency.js";
|
|
7
|
+
import type { ParallelTask } from "../interfaces/parallel-task.interface.js";
|
|
8
|
+
type OpencodeClient = PluginInput["client"];
|
|
9
|
+
export declare class EventHandler {
|
|
10
|
+
private client;
|
|
11
|
+
private store;
|
|
12
|
+
private concurrency;
|
|
13
|
+
private findBySession;
|
|
14
|
+
private notifyParentIfAllComplete;
|
|
15
|
+
private scheduleCleanup;
|
|
16
|
+
private validateSessionHasOutput;
|
|
17
|
+
constructor(client: OpencodeClient, store: TaskStore, concurrency: ConcurrencyController, findBySession: (sessionID: string) => ParallelTask | undefined, notifyParentIfAllComplete: (parentSessionID: string) => Promise<void>, scheduleCleanup: (taskId: string) => void, validateSessionHasOutput: (sessionID: string) => Promise<boolean>);
|
|
18
|
+
/**
|
|
19
|
+
* Handle OpenCode session events for proper resource cleanup.
|
|
20
|
+
* Call this from your plugin's event hook.
|
|
21
|
+
*/
|
|
22
|
+
handle(event: {
|
|
23
|
+
type: string;
|
|
24
|
+
properties?: {
|
|
25
|
+
sessionID?: string;
|
|
26
|
+
info?: {
|
|
27
|
+
id?: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}): void;
|
|
31
|
+
private handleSessionIdle;
|
|
32
|
+
private handleSessionDeleted;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manager Module Index
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all manager components
|
|
5
|
+
*/
|
|
6
|
+
export { TaskLauncher } from "./task-launcher.js";
|
|
7
|
+
export { TaskResumer } from "./task-resumer.js";
|
|
8
|
+
export { TaskPoller } from "./task-poller.js";
|
|
9
|
+
export { TaskCleaner } from "./task-cleaner.js";
|
|
10
|
+
export { EventHandler } from "./event-handler.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Cleaner - Handles cleanup and expiration of tasks
|
|
3
|
+
*/
|
|
4
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
|
+
import { TaskStore } from "../task-store.js";
|
|
6
|
+
import { ConcurrencyController } from "../concurrency.js";
|
|
7
|
+
type OpencodeClient = PluginInput["client"];
|
|
8
|
+
export declare class TaskCleaner {
|
|
9
|
+
private client;
|
|
10
|
+
private store;
|
|
11
|
+
private concurrency;
|
|
12
|
+
constructor(client: OpencodeClient, store: TaskStore, concurrency: ConcurrencyController);
|
|
13
|
+
pruneExpiredTasks(): void;
|
|
14
|
+
scheduleCleanup(taskId: string): void;
|
|
15
|
+
notifyParentIfAllComplete(parentSessionID: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Launcher - Handles launching new parallel tasks
|
|
3
|
+
*/
|
|
4
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
|
+
import { ConcurrencyController } from "../concurrency.js";
|
|
6
|
+
import { TaskStore } from "../task-store.js";
|
|
7
|
+
import type { ParallelTask } from "../interfaces/parallel-task.interface.js";
|
|
8
|
+
import type { LaunchInput } from "../interfaces/launch-input.interface.js";
|
|
9
|
+
type OpencodeClient = PluginInput["client"];
|
|
10
|
+
export declare class TaskLauncher {
|
|
11
|
+
private client;
|
|
12
|
+
private directory;
|
|
13
|
+
private store;
|
|
14
|
+
private concurrency;
|
|
15
|
+
private onTaskError;
|
|
16
|
+
private startPolling;
|
|
17
|
+
constructor(client: OpencodeClient, directory: string, store: TaskStore, concurrency: ConcurrencyController, onTaskError: (taskId: string, error: unknown) => void, startPolling: () => void);
|
|
18
|
+
launch(input: LaunchInput): Promise<ParallelTask>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Poller - Handles polling and completion detection for running tasks
|
|
3
|
+
*/
|
|
4
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
|
+
import { TaskStore } from "../task-store.js";
|
|
6
|
+
import { ConcurrencyController } from "../concurrency.js";
|
|
7
|
+
import type { ParallelTask } from "../interfaces/parallel-task.interface.js";
|
|
8
|
+
type OpencodeClient = PluginInput["client"];
|
|
9
|
+
export declare class TaskPoller {
|
|
10
|
+
private client;
|
|
11
|
+
private store;
|
|
12
|
+
private concurrency;
|
|
13
|
+
private notifyParentIfAllComplete;
|
|
14
|
+
private scheduleCleanup;
|
|
15
|
+
private pruneExpiredTasks;
|
|
16
|
+
private pollingInterval?;
|
|
17
|
+
constructor(client: OpencodeClient, store: TaskStore, concurrency: ConcurrencyController, notifyParentIfAllComplete: (parentSessionID: string) => Promise<void>, scheduleCleanup: (taskId: string) => void, pruneExpiredTasks: () => void);
|
|
18
|
+
start(): void;
|
|
19
|
+
stop(): void;
|
|
20
|
+
isRunning(): boolean;
|
|
21
|
+
poll(): Promise<void>;
|
|
22
|
+
validateSessionHasOutput(sessionID: string): Promise<boolean>;
|
|
23
|
+
completeTask(task: ParallelTask): Promise<void>;
|
|
24
|
+
private updateTaskProgress;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Resumer - Handles resuming existing parallel task sessions
|
|
3
|
+
*/
|
|
4
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
|
+
import { TaskStore } from "../task-store.js";
|
|
6
|
+
import type { ParallelTask } from "../interfaces/parallel-task.interface.js";
|
|
7
|
+
import type { ResumeInput } from "../interfaces/resume-input.interface.js";
|
|
8
|
+
type OpencodeClient = PluginInput["client"];
|
|
9
|
+
export declare class TaskResumer {
|
|
10
|
+
private client;
|
|
11
|
+
private store;
|
|
12
|
+
private findBySession;
|
|
13
|
+
private startPolling;
|
|
14
|
+
private notifyParentIfAllComplete;
|
|
15
|
+
constructor(client: OpencodeClient, store: TaskStore, findBySession: (sessionID: string) => ParallelTask | undefined, startPolling: () => void, notifyParentIfAllComplete: (parentSessionID: string) => Promise<void>);
|
|
16
|
+
resume(input: ResumeInput): Promise<ParallelTask>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
* - Concurrency control per agent type
|
|
6
6
|
* - Batched notifications
|
|
7
7
|
* - Automatic cleanup
|
|
8
|
+
*
|
|
9
|
+
* This is the main facade that composes the specialized components.
|
|
8
10
|
*/
|
|
9
11
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
10
12
|
import { formatDuration } from "./format.js";
|
|
11
|
-
import type { ParallelTask } from "./interfaces/parallel-task.js";
|
|
12
|
-
import type { LaunchInput } from "./interfaces/launch-input.js";
|
|
13
|
+
import type { ParallelTask } from "./interfaces/parallel-task.interface.js";
|
|
14
|
+
import type { LaunchInput } from "./interfaces/launch-input.interface.js";
|
|
15
|
+
import type { ResumeInput } from "./interfaces/resume-input.interface.js";
|
|
13
16
|
export type { ParallelTask };
|
|
14
17
|
export { formatDuration };
|
|
15
18
|
type OpencodeClient = PluginInput["client"];
|
|
@@ -19,10 +22,15 @@ export declare class ParallelAgentManager {
|
|
|
19
22
|
private client;
|
|
20
23
|
private directory;
|
|
21
24
|
private concurrency;
|
|
22
|
-
private
|
|
25
|
+
private launcher;
|
|
26
|
+
private resumer;
|
|
27
|
+
private poller;
|
|
28
|
+
private cleaner;
|
|
29
|
+
private eventHandler;
|
|
23
30
|
private constructor();
|
|
24
31
|
static getInstance(client?: OpencodeClient, directory?: string): ParallelAgentManager;
|
|
25
32
|
launch(input: LaunchInput): Promise<ParallelTask>;
|
|
33
|
+
resume(input: ResumeInput): Promise<ParallelTask>;
|
|
26
34
|
getTask(id: string): ParallelTask | undefined;
|
|
27
35
|
getRunningTasks(): ParallelTask[];
|
|
28
36
|
getAllTasks(): ParallelTask[];
|
|
@@ -33,10 +41,6 @@ export declare class ParallelAgentManager {
|
|
|
33
41
|
getPendingCount(parentSessionID: string): number;
|
|
34
42
|
cleanup(): void;
|
|
35
43
|
formatDuration: typeof formatDuration;
|
|
36
|
-
/**
|
|
37
|
-
* Handle OpenCode session events for proper resource cleanup.
|
|
38
|
-
* Call this from your plugin's event hook.
|
|
39
|
-
*/
|
|
40
44
|
handleEvent(event: {
|
|
41
45
|
type: string;
|
|
42
46
|
properties?: {
|
|
@@ -46,30 +50,8 @@ export declare class ParallelAgentManager {
|
|
|
46
50
|
};
|
|
47
51
|
};
|
|
48
52
|
}): void;
|
|
49
|
-
/**
|
|
50
|
-
* Find task by session ID
|
|
51
|
-
*/
|
|
52
53
|
private findBySession;
|
|
53
|
-
/**
|
|
54
|
-
* Handle session.idle event - validate and complete task
|
|
55
|
-
*/
|
|
56
|
-
private handleSessionIdle;
|
|
57
54
|
private handleTaskError;
|
|
58
|
-
private startPolling;
|
|
59
|
-
private stopPolling;
|
|
60
|
-
private pollRunningTasks;
|
|
61
|
-
/**
|
|
62
|
-
* Update task progress and stability tracking
|
|
63
|
-
*/
|
|
64
|
-
private updateTaskProgress;
|
|
65
|
-
/**
|
|
66
|
-
* Complete a task and cleanup
|
|
67
|
-
*/
|
|
68
|
-
private completeTask;
|
|
69
|
-
private validateSessionHasOutput;
|
|
70
|
-
private pruneExpiredTasks;
|
|
71
|
-
private scheduleCleanup;
|
|
72
|
-
private notifyParentIfAllComplete;
|
|
73
55
|
}
|
|
74
56
|
export declare const parallelAgentManager: {
|
|
75
57
|
getInstance: typeof ParallelAgentManager.getInstance;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Task Store - Stores and manages parallel tasks
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Automatic garbage collection
|
|
6
|
+
* - Memory-safe storage with limits
|
|
7
|
+
* - Completed task archiving
|
|
3
8
|
*/
|
|
4
|
-
import type { ParallelTask } from "./interfaces/parallel-task.js";
|
|
9
|
+
import type { ParallelTask } from "./interfaces/parallel-task.interface.js";
|
|
5
10
|
export declare class TaskStore {
|
|
6
11
|
private tasks;
|
|
7
12
|
private pendingByParent;
|
|
8
13
|
private notifications;
|
|
14
|
+
private archivedCount;
|
|
9
15
|
set(id: string, task: ParallelTask): void;
|
|
10
16
|
get(id: string): ParallelTask | undefined;
|
|
11
17
|
getAll(): ParallelTask[];
|
|
@@ -21,8 +27,28 @@ export declare class TaskStore {
|
|
|
21
27
|
getNotifications(parentSessionID: string): ParallelTask[];
|
|
22
28
|
clearNotifications(parentSessionID: string): void;
|
|
23
29
|
cleanEmptyNotifications(): void;
|
|
30
|
+
clearNotificationsForTask(taskId: string): void;
|
|
24
31
|
/**
|
|
25
|
-
*
|
|
32
|
+
* Get memory statistics
|
|
26
33
|
*/
|
|
27
|
-
|
|
34
|
+
getStats(): {
|
|
35
|
+
tasksInMemory: number;
|
|
36
|
+
runningTasks: number;
|
|
37
|
+
archivedTasks: number;
|
|
38
|
+
notificationQueues: number;
|
|
39
|
+
pendingParents: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Garbage collect completed tasks
|
|
43
|
+
* Archives old completed tasks to disk
|
|
44
|
+
*/
|
|
45
|
+
gc(): Promise<number>;
|
|
46
|
+
/**
|
|
47
|
+
* Archive tasks to disk for later analysis
|
|
48
|
+
*/
|
|
49
|
+
private archiveTasks;
|
|
50
|
+
/**
|
|
51
|
+
* Force cleanup of all completed tasks
|
|
52
|
+
*/
|
|
53
|
+
forceCleanup(): number;
|
|
28
54
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document Cache Module
|
|
3
|
+
*/
|
|
4
|
+
export type { CachedDocument, CacheMetadata, CacheDocumentEntry, CacheListEntry, CacheStats, } from "./interfaces.js";
|
|
5
|
+
export { CACHE_DIR, METADATA_FILE, DEFAULT_TTL_MS } from "./constants.js";
|
|
6
|
+
export { get, getByFilename, set, remove, list, clear, cleanExpired, stats, } from "./operations.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document Cache Interfaces
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Cached document structure
|
|
6
|
+
*/
|
|
7
|
+
export interface CachedDocument {
|
|
8
|
+
url: string;
|
|
9
|
+
title: string;
|
|
10
|
+
content: string;
|
|
11
|
+
fetchedAt: string;
|
|
12
|
+
expiresAt: string;
|
|
13
|
+
size: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cache metadata structure
|
|
17
|
+
*/
|
|
18
|
+
export interface CacheMetadata {
|
|
19
|
+
documents: Record<string, CacheDocumentEntry>;
|
|
20
|
+
lastUpdated: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Individual document entry in metadata
|
|
24
|
+
*/
|
|
25
|
+
export interface CacheDocumentEntry {
|
|
26
|
+
url: string;
|
|
27
|
+
title: string;
|
|
28
|
+
fetchedAt: string;
|
|
29
|
+
expiresAt: string;
|
|
30
|
+
size: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Document listing entry
|
|
34
|
+
*/
|
|
35
|
+
export interface CacheListEntry {
|
|
36
|
+
filename: string;
|
|
37
|
+
url: string;
|
|
38
|
+
title: string;
|
|
39
|
+
fetchedAt: string;
|
|
40
|
+
expiresAt: string;
|
|
41
|
+
size: number;
|
|
42
|
+
expired: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Cache statistics
|
|
46
|
+
*/
|
|
47
|
+
export interface CacheStats {
|
|
48
|
+
totalDocuments: number;
|
|
49
|
+
totalSize: number;
|
|
50
|
+
expiredCount: number;
|
|
51
|
+
oldestDocument: string | null;
|
|
52
|
+
newestDocument: string | null;
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document Cache Operations
|
|
3
|
+
*/
|
|
4
|
+
import type { CachedDocument, CacheListEntry, CacheStats } from "./interfaces.js";
|
|
5
|
+
/**
|
|
6
|
+
* Get cached document by URL
|
|
7
|
+
*/
|
|
8
|
+
export declare function get(url: string): Promise<CachedDocument | null>;
|
|
9
|
+
/**
|
|
10
|
+
* Get cached document by filename
|
|
11
|
+
*/
|
|
12
|
+
export declare function getByFilename(filename: string): Promise<CachedDocument | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Cache a document
|
|
15
|
+
*/
|
|
16
|
+
export declare function set(url: string, content: string, title: string, ttlMs?: number): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Remove cached document
|
|
19
|
+
*/
|
|
20
|
+
export declare function remove(url: string): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* List all cached documents
|
|
23
|
+
*/
|
|
24
|
+
export declare function list(): Promise<CacheListEntry[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Clear all cached documents
|
|
27
|
+
*/
|
|
28
|
+
export declare function clear(): Promise<number>;
|
|
29
|
+
/**
|
|
30
|
+
* Clean expired documents
|
|
31
|
+
*/
|
|
32
|
+
export declare function cleanExpired(): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Get cache statistics
|
|
35
|
+
*/
|
|
36
|
+
export declare function stats(): Promise<CacheStats>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document Cache Utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { CacheMetadata } from "./interfaces.js";
|
|
5
|
+
/**
|
|
6
|
+
* Ensure cache directory exists
|
|
7
|
+
*/
|
|
8
|
+
export declare function ensureCacheDir(): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Generate safe filename from URL
|
|
11
|
+
*/
|
|
12
|
+
export declare function urlToFilename(url: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Read cache metadata
|
|
15
|
+
*/
|
|
16
|
+
export declare function readMetadata(): Promise<CacheMetadata>;
|
|
17
|
+
/**
|
|
18
|
+
* Write cache metadata
|
|
19
|
+
*/
|
|
20
|
+
export declare function writeMetadata(metadata: CacheMetadata): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Todo Formatters - Format output strings
|
|
3
|
+
*/
|
|
4
|
+
import type { Todo } from "./interfaces.js";
|
|
5
|
+
/**
|
|
6
|
+
* Format progress string
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatProgress(todos: Todo[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Generate continuation prompt when todos remain
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateContinuationPrompt(todos: Todo[]): string;
|
|
13
|
+
/**
|
|
14
|
+
* Generate completion message
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateCompletionMessage(todos: Todo[]): string;
|