opencode-orchestrator 1.2.38 → 1.2.46
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/dist/core/agents/concurrency-token.d.ts +23 -0
- package/dist/core/agents/concurrency.d.ts +72 -15
- package/dist/core/agents/index.d.ts +0 -1
- package/dist/core/agents/interfaces/index.d.ts +4 -3
- package/dist/core/agents/logger.d.ts +4 -3
- package/dist/core/agents/manager/event-handler.d.ts +1 -1
- package/dist/core/agents/manager/task-launcher.d.ts +1 -1
- package/dist/core/agents/manager/task-poller.d.ts +15 -1
- package/dist/core/agents/manager/task-resumer.d.ts +1 -1
- package/dist/core/agents/manager.d.ts +5 -1
- package/dist/core/agents/persistence/task-wal.d.ts +11 -13
- package/dist/core/agents/session-pool.d.ts +9 -1
- package/dist/core/agents/task-store.d.ts +25 -1
- package/dist/core/cleanup/cleanup-scheduler.d.ts +16 -0
- package/dist/core/commands/interfaces/background-task.d.ts +1 -0
- package/dist/core/commands/manager.d.ts +4 -0
- package/dist/core/lifecycle/shutdown-manager.d.ts +29 -0
- package/dist/core/plugins/interfaces.d.ts +4 -0
- package/dist/core/plugins/plugin-manager.d.ts +4 -0
- package/dist/core/pool/buffer-pool.d.ts +48 -0
- package/dist/core/pool/object-pool.d.ts +59 -0
- package/dist/core/pool/string-pool.d.ts +40 -0
- package/dist/core/pool/task-pool.d.ts +13 -0
- package/dist/core/queue/work-stealing-deque.d.ts +47 -0
- package/dist/core/queue/worker-pool.d.ts +78 -0
- package/dist/core/sync/todo-sync-service.d.ts +5 -0
- package/dist/index.js +17903 -16834
- package/dist/scripts/postinstall.js +156 -25
- package/dist/scripts/preuninstall.js +159 -17
- package/dist/shared/task/interfaces/parallel-task.d.ts +6 -4
- package/dist/tools/registry.d.ts +14 -0
- package/dist/tools/rust-pool.d.ts +63 -0
- package/dist/tools/rust.d.ts +4 -0
- package/package.json +1 -1
- package/dist/core/agents/interfaces/concurrency-config.interface.d.ts +0 -9
- package/dist/core/agents/interfaces/parallel-task.interface.d.ts +0 -26
- package/dist/core/agents/interfaces/task-progress.interface.d.ts +0 -9
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConcurrencyToken
|
|
3
|
+
*
|
|
4
|
+
* RAII-style token for concurrency slot management.
|
|
5
|
+
* Automatically releases slot if not manually released within timeout.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConcurrencyController } from "./concurrency.js";
|
|
8
|
+
export declare class ConcurrencyToken {
|
|
9
|
+
private controller;
|
|
10
|
+
private key;
|
|
11
|
+
private autoReleaseMs;
|
|
12
|
+
private released;
|
|
13
|
+
private autoReleaseTimer;
|
|
14
|
+
constructor(controller: ConcurrencyController, key: string, autoReleaseMs?: number);
|
|
15
|
+
/**
|
|
16
|
+
* Manually release the concurrency slot
|
|
17
|
+
*/
|
|
18
|
+
release(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Check if token has been released
|
|
21
|
+
*/
|
|
22
|
+
isReleased(): boolean;
|
|
23
|
+
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Concurrency Controller
|
|
2
|
+
* Enhanced Concurrency Controller
|
|
3
3
|
*
|
|
4
|
-
* Queue-based rate limiting with
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
4
|
+
* Queue-based rate limiting with:
|
|
5
|
+
* - Priority queue (HIGH/NORMAL/LOW)
|
|
6
|
+
* - Circuit breaker pattern
|
|
7
|
+
* - Resource-aware scheduling
|
|
8
|
+
* - Adaptive auto-scaling
|
|
8
9
|
*/
|
|
9
|
-
import type { ConcurrencyConfig } from "
|
|
10
|
-
|
|
10
|
+
import type { ConcurrencyConfig } from "../../shared/agent/interfaces/concurrency-config.js";
|
|
11
|
+
import { ConcurrencyToken } from "./concurrency-token.js";
|
|
12
|
+
export type { ConcurrencyConfig } from "../../shared/agent/interfaces/concurrency-config.js";
|
|
13
|
+
export declare enum TaskPriority {
|
|
14
|
+
HIGH = 0,
|
|
15
|
+
NORMAL = 1,
|
|
16
|
+
LOW = 2
|
|
17
|
+
}
|
|
18
|
+
export declare enum CircuitState {
|
|
19
|
+
CLOSED = "CLOSED",// Normal operation
|
|
20
|
+
OPEN = "OPEN",// Blocking requests
|
|
21
|
+
HALF_OPEN = "HALF_OPEN"
|
|
22
|
+
}
|
|
11
23
|
export declare class ConcurrencyController {
|
|
12
24
|
private counts;
|
|
13
25
|
private queues;
|
|
@@ -15,24 +27,69 @@ export declare class ConcurrencyController {
|
|
|
15
27
|
private config;
|
|
16
28
|
private successStreak;
|
|
17
29
|
private failureCount;
|
|
30
|
+
private circuits;
|
|
31
|
+
private readonly CIRCUIT_THRESHOLD;
|
|
32
|
+
private readonly CIRCUIT_TIMEOUT;
|
|
33
|
+
private readonly HALF_OPEN_SUCCESS;
|
|
34
|
+
private readonly MAX_MEMORY_PERCENT;
|
|
35
|
+
private workerPools;
|
|
18
36
|
constructor(config?: ConcurrencyConfig);
|
|
19
37
|
setLimit(key: string, limit: number): void;
|
|
20
|
-
/**
|
|
21
|
-
* Get concurrency limit for a key.
|
|
22
|
-
* Priority: explicit limit > model > provider > agent > default
|
|
23
|
-
*/
|
|
24
38
|
getConcurrencyLimit(key: string): number;
|
|
25
39
|
getLimit(key: string): number;
|
|
26
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Acquire slot with priority support
|
|
42
|
+
*/
|
|
43
|
+
acquire(key: string, priority?: TaskPriority): Promise<void>;
|
|
27
44
|
release(key: string): void;
|
|
28
45
|
/**
|
|
29
|
-
* Report
|
|
46
|
+
* Report result with circuit breaker integration
|
|
30
47
|
*/
|
|
31
48
|
reportResult(key: string, success: boolean): void;
|
|
49
|
+
private handleSuccess;
|
|
50
|
+
private handleFailure;
|
|
51
|
+
private isCircuitOpen;
|
|
52
|
+
private getCircuit;
|
|
53
|
+
private isUnderResourcePressure;
|
|
54
|
+
private removeFromQueue;
|
|
32
55
|
getQueueLength(key: string): number;
|
|
33
56
|
getActiveCount(key: string): number;
|
|
57
|
+
getConcurrencyInfo(key: string): string;
|
|
34
58
|
/**
|
|
35
|
-
* Get
|
|
59
|
+
* Get circuit breaker state for monitoring
|
|
36
60
|
*/
|
|
37
|
-
|
|
61
|
+
getCircuitState(key: string): CircuitState;
|
|
62
|
+
/**
|
|
63
|
+
* Manually reset circuit breaker
|
|
64
|
+
*/
|
|
65
|
+
resetCircuit(key: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Acquire slot and return RAII token for automatic cleanup
|
|
68
|
+
* @param key - Concurrency key
|
|
69
|
+
* @param priority - Task priority
|
|
70
|
+
* @param autoReleaseMs - Auto-release timeout (default: 10 minutes)
|
|
71
|
+
* @returns ConcurrencyToken - Call .release() when done
|
|
72
|
+
*/
|
|
73
|
+
acquireToken(key: string, priority?: TaskPriority, autoReleaseMs?: number): Promise<ConcurrencyToken>;
|
|
74
|
+
/**
|
|
75
|
+
* Enable work-stealing for a concurrency key
|
|
76
|
+
* @param key - Concurrency key
|
|
77
|
+
* @param workerCount - Number of workers (default: 4)
|
|
78
|
+
*/
|
|
79
|
+
enableWorkStealing(key: string, workerCount?: number): void;
|
|
80
|
+
/**
|
|
81
|
+
* Get work-stealing pool statistics
|
|
82
|
+
*/
|
|
83
|
+
getWorkStealingStats(key: string): {
|
|
84
|
+
workers: number;
|
|
85
|
+
totalExecuted: number;
|
|
86
|
+
totalStolen: number;
|
|
87
|
+
stealRate: number;
|
|
88
|
+
utilizationPercent: number;
|
|
89
|
+
queuedTasks: number;
|
|
90
|
+
} | null;
|
|
91
|
+
/**
|
|
92
|
+
* Shutdown - stops all worker pools
|
|
93
|
+
*/
|
|
94
|
+
shutdown(): Promise<void>;
|
|
38
95
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agents Interfaces Index
|
|
3
|
+
* Re-exports from shared to maintain compatibility
|
|
3
4
|
*/
|
|
4
|
-
export type { ParallelTask } from "
|
|
5
|
-
export type { TaskProgress } from "
|
|
5
|
+
export type { ParallelTask } from "../../../shared/task/interfaces/parallel-task.js";
|
|
6
|
+
export type { TaskProgress } from "../../../shared/task/interfaces/task-progress.js";
|
|
7
|
+
export type { ConcurrencyConfig } from "../../../shared/agent/interfaces/concurrency-config.js";
|
|
6
8
|
export type { LaunchInput } from "./launch-input.interface.js";
|
|
7
9
|
export type { ResumeInput } from "./resume-input.interface.js";
|
|
8
|
-
export type { ConcurrencyConfig } from "./concurrency-config.interface.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Debug logger for parallel agent
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* DISABLED: File logging removed to eliminate I/O overhead.
|
|
5
|
+
* All log calls are now no-ops for maximum performance.
|
|
5
6
|
*/
|
|
6
|
-
export declare function log(...
|
|
7
|
+
export declare function log(..._args: unknown[]): void;
|
|
7
8
|
export declare function getLogPath(): string;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
5
|
import { TaskStore } from "../task-store.js";
|
|
6
6
|
import { ConcurrencyController } from "../concurrency.js";
|
|
7
|
-
import type { ParallelTask } from "../interfaces/
|
|
7
|
+
import type { ParallelTask } from "../interfaces/index.js";
|
|
8
8
|
type OpencodeClient = PluginInput["client"];
|
|
9
9
|
export declare class EventHandler {
|
|
10
10
|
private client;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
5
|
import { ConcurrencyController } from "../concurrency.js";
|
|
6
6
|
import { TaskStore } from "../task-store.js";
|
|
7
|
-
import type { ParallelTask } from "../interfaces/
|
|
7
|
+
import type { ParallelTask } from "../interfaces/index.js";
|
|
8
8
|
import type { LaunchInput } from "../interfaces/launch-input.interface.js";
|
|
9
9
|
import { SessionPool } from "../session-pool.js";
|
|
10
10
|
type OpencodeClient = PluginInput["client"];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
5
|
import { TaskStore } from "../task-store.js";
|
|
6
6
|
import { ConcurrencyController } from "../concurrency.js";
|
|
7
|
-
import type { ParallelTask } from "../interfaces/
|
|
7
|
+
import type { ParallelTask } from "../interfaces/index.js";
|
|
8
8
|
type OpencodeClient = PluginInput["client"];
|
|
9
9
|
export declare class TaskPoller {
|
|
10
10
|
private client;
|
|
@@ -16,13 +16,27 @@ export declare class TaskPoller {
|
|
|
16
16
|
private onTaskComplete?;
|
|
17
17
|
private pollingInterval?;
|
|
18
18
|
private messageCache;
|
|
19
|
+
private currentPollInterval;
|
|
20
|
+
private readonly MIN_POLL_INTERVAL;
|
|
21
|
+
private readonly MAX_POLL_INTERVAL;
|
|
19
22
|
constructor(client: OpencodeClient, store: TaskStore, concurrency: ConcurrencyController, notifyParentIfAllComplete: (parentSessionID: string) => Promise<void>, scheduleCleanup: (taskId: string) => void, pruneExpiredTasks: () => void, onTaskComplete?: ((task: ParallelTask) => void | Promise<void>) | undefined);
|
|
20
23
|
start(): void;
|
|
21
24
|
stop(): void;
|
|
22
25
|
isRunning(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Schedule next poll with adaptive interval
|
|
28
|
+
*/
|
|
29
|
+
private scheduleNextPoll;
|
|
23
30
|
poll(): Promise<void>;
|
|
24
31
|
validateSessionHasOutput(sessionID: string, task?: ParallelTask): Promise<boolean>;
|
|
25
32
|
completeTask(task: ParallelTask): Promise<void>;
|
|
26
33
|
private updateTaskProgress;
|
|
34
|
+
/**
|
|
35
|
+
* Adjust poll interval based on current load
|
|
36
|
+
* - No tasks: Exponential backoff to MAX_POLL_INTERVAL
|
|
37
|
+
* - High utilization (>80%): Speed up to MIN_POLL_INTERVAL
|
|
38
|
+
* - Medium utilization: Proportional adjustment
|
|
39
|
+
*/
|
|
40
|
+
private adjustPollInterval;
|
|
27
41
|
}
|
|
28
42
|
export {};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
5
|
import { TaskStore } from "../task-store.js";
|
|
6
|
-
import type { ParallelTask } from "../interfaces/
|
|
6
|
+
import type { ParallelTask } from "../interfaces/index.js";
|
|
7
7
|
import type { ResumeInput } from "../interfaces/resume-input.interface.js";
|
|
8
8
|
type OpencodeClient = PluginInput["client"];
|
|
9
9
|
export declare class TaskResumer {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
12
12
|
import { ConcurrencyController } from "./concurrency.js";
|
|
13
13
|
import { formatDuration } from "./format.js";
|
|
14
|
-
import type { ParallelTask } from "./interfaces/
|
|
14
|
+
import type { ParallelTask } from "./interfaces/index.js";
|
|
15
15
|
import type { LaunchInput } from "./interfaces/launch-input.interface.js";
|
|
16
16
|
import type { ResumeInput } from "./interfaces/resume-input.interface.js";
|
|
17
17
|
export type { ParallelTask };
|
|
@@ -43,6 +43,10 @@ export declare class ParallelAgentManager {
|
|
|
43
43
|
getPendingCount(parentSessionID: string): number;
|
|
44
44
|
getConcurrency(): ConcurrencyController;
|
|
45
45
|
cleanup(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Shutdown - alias for cleanup, releases all resources
|
|
48
|
+
*/
|
|
49
|
+
shutdown(): Promise<void>;
|
|
46
50
|
formatDuration: typeof formatDuration;
|
|
47
51
|
handleEvent(event: {
|
|
48
52
|
type: string;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Task WAL (Write-Ahead Log)
|
|
2
|
+
* Task WAL (Write-Ahead Log) - REMOVED
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* This module is deprecated and provides no-op stubs for backward compatibility.
|
|
5
|
+
* WAL was removed to reduce I/O overhead and simplify architecture.
|
|
5
6
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import type { ParallelTask } from "../interfaces/parallel-task.interface.js";
|
|
7
|
+
import type { ParallelTask } from "../interfaces/index.js";
|
|
8
8
|
export interface WALEntry {
|
|
9
9
|
timestamp: string;
|
|
10
|
-
action:
|
|
10
|
+
action: string;
|
|
11
11
|
taskId: string;
|
|
12
12
|
data: Partial<ParallelTask>;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* No-op WAL - all methods are stubs
|
|
16
|
+
*/
|
|
14
17
|
export declare class TaskWAL {
|
|
15
|
-
private walPath;
|
|
16
|
-
private initialized;
|
|
17
|
-
constructor(customPath?: string);
|
|
18
18
|
init(): Promise<void>;
|
|
19
|
-
log(
|
|
19
|
+
log(): Promise<void>;
|
|
20
|
+
flush(): Promise<void>;
|
|
20
21
|
readAll(): Promise<Map<string, ParallelTask>>;
|
|
21
|
-
|
|
22
|
-
* Compact the WAL by writing only the current active tasks
|
|
23
|
-
*/
|
|
24
|
-
compact(activeTasks: ParallelTask[]): Promise<void>;
|
|
22
|
+
compact(): Promise<void>;
|
|
25
23
|
}
|
|
26
24
|
export declare const taskWAL: TaskWAL;
|
|
@@ -9,7 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
11
11
|
import type { PooledSession, SessionPoolConfig, SessionPoolStats, ISessionPool } from "./interfaces/session-pool.interface.js";
|
|
12
|
-
type OpencodeClient = PluginInput["client"]
|
|
12
|
+
type OpencodeClient = PluginInput["client"] & {
|
|
13
|
+
session: {
|
|
14
|
+
compact?: (opts: {
|
|
15
|
+
path: {
|
|
16
|
+
id: string;
|
|
17
|
+
};
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
13
21
|
export declare class SessionPool implements ISessionPool {
|
|
14
22
|
private static _instance;
|
|
15
23
|
private pool;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - Memory-safe storage with limits
|
|
7
7
|
* - Completed task archiving
|
|
8
8
|
*/
|
|
9
|
-
import type { ParallelTask } from "./interfaces/
|
|
9
|
+
import type { ParallelTask } from "./interfaces/index.js";
|
|
10
10
|
export declare class TaskStore {
|
|
11
11
|
private tasks;
|
|
12
12
|
private pendingByParent;
|
|
@@ -51,4 +51,28 @@ export declare class TaskStore {
|
|
|
51
51
|
* Force cleanup of all completed tasks
|
|
52
52
|
*/
|
|
53
53
|
forceCleanup(): number;
|
|
54
|
+
/**
|
|
55
|
+
* Get pooling statistics
|
|
56
|
+
*/
|
|
57
|
+
getPoolStats(): {
|
|
58
|
+
taskPool: {
|
|
59
|
+
created: number;
|
|
60
|
+
available: number;
|
|
61
|
+
inUse: number;
|
|
62
|
+
acquires: number;
|
|
63
|
+
releases: number;
|
|
64
|
+
hits: number;
|
|
65
|
+
misses: number;
|
|
66
|
+
disposed: number;
|
|
67
|
+
hitRate: number;
|
|
68
|
+
};
|
|
69
|
+
stringPool: {
|
|
70
|
+
interns: number;
|
|
71
|
+
hits: number;
|
|
72
|
+
misses: number;
|
|
73
|
+
skipped: number;
|
|
74
|
+
hitRate: number;
|
|
75
|
+
poolSize: number;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
54
78
|
}
|
|
@@ -8,4 +8,20 @@ export declare class CleanupScheduler {
|
|
|
8
8
|
compactWAL(): Promise<void>;
|
|
9
9
|
cleanDocs(): Promise<void>;
|
|
10
10
|
rotateHistory(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Clean old session files (>7 days)
|
|
13
|
+
*/
|
|
14
|
+
cleanOldSessions(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Remove node_modules from .opencode directory
|
|
17
|
+
*/
|
|
18
|
+
cleanNodeModules(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Enforce file count limit (500 files max)
|
|
21
|
+
*/
|
|
22
|
+
enforceFileLimit(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Recursively list all files in a directory
|
|
25
|
+
*/
|
|
26
|
+
private listAllFiles;
|
|
11
27
|
}
|
|
@@ -22,6 +22,10 @@ declare class BackgroundTaskManager {
|
|
|
22
22
|
kill(taskId: string): boolean;
|
|
23
23
|
formatDuration(task: BackgroundTask): string;
|
|
24
24
|
getStatusEmoji(status: BackgroundTaskStatus): string;
|
|
25
|
+
/**
|
|
26
|
+
* Shutdown - kills all running processes and clears tasks
|
|
27
|
+
*/
|
|
28
|
+
shutdown(): Promise<void>;
|
|
25
29
|
}
|
|
26
30
|
export declare const backgroundTaskManager: BackgroundTaskManager;
|
|
27
31
|
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShutdownManager
|
|
3
|
+
*
|
|
4
|
+
* Coordinates graceful shutdown of all subsystems.
|
|
5
|
+
* Ensures resources are properly cleaned up when the plugin is unloaded.
|
|
6
|
+
*/
|
|
7
|
+
export type CleanupFunction = () => void | Promise<void>;
|
|
8
|
+
export declare class ShutdownManager {
|
|
9
|
+
private cleanupHandlers;
|
|
10
|
+
private isShuttingDown;
|
|
11
|
+
private shutdownPromise;
|
|
12
|
+
/**
|
|
13
|
+
* Register a cleanup handler
|
|
14
|
+
* @param name - Identifier for logging
|
|
15
|
+
* @param fn - Cleanup function to execute
|
|
16
|
+
* @param priority - Lower numbers run first (0-100). Default: 100
|
|
17
|
+
*/
|
|
18
|
+
register(name: string, fn: CleanupFunction, priority?: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Execute all cleanup handlers in priority order
|
|
21
|
+
* Each handler gets 5 seconds max
|
|
22
|
+
*/
|
|
23
|
+
shutdown(): Promise<void>;
|
|
24
|
+
private _executeShutdown;
|
|
25
|
+
/**
|
|
26
|
+
* Check if shutdown is in progress
|
|
27
|
+
*/
|
|
28
|
+
isShutdown(): boolean;
|
|
29
|
+
}
|
|
@@ -24,6 +24,10 @@ export interface CustomPlugin {
|
|
|
24
24
|
* Initialization logic
|
|
25
25
|
*/
|
|
26
26
|
init?: (context: PluginContext) => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Cleanup logic (called on shutdown)
|
|
29
|
+
*/
|
|
30
|
+
cleanup?: () => Promise<void>;
|
|
27
31
|
}
|
|
28
32
|
export interface PluginContext {
|
|
29
33
|
directory: string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Buffer Pool
|
|
3
|
+
*
|
|
4
|
+
* Pools ArrayBuffers for efficient memory reuse.
|
|
5
|
+
* Sizes: 1KB, 4KB, 16KB, 64KB
|
|
6
|
+
*/
|
|
7
|
+
export declare class BufferPool {
|
|
8
|
+
private pools;
|
|
9
|
+
private readonly sizes;
|
|
10
|
+
private readonly maxPerSize;
|
|
11
|
+
private stats;
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Acquire a buffer of at least minSize
|
|
15
|
+
* Returns the buffer and its actual size
|
|
16
|
+
*/
|
|
17
|
+
acquire(minSize: number): {
|
|
18
|
+
buffer: ArrayBuffer;
|
|
19
|
+
poolSize: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Release a buffer back to the pool
|
|
23
|
+
*/
|
|
24
|
+
release(buffer: ArrayBuffer): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get pool statistics
|
|
27
|
+
*/
|
|
28
|
+
getStats(): {
|
|
29
|
+
acquires: number;
|
|
30
|
+
releases: number;
|
|
31
|
+
hits: number;
|
|
32
|
+
misses: number;
|
|
33
|
+
hitRate: number;
|
|
34
|
+
poolSizes: Record<number, number>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Clear all pools
|
|
38
|
+
*/
|
|
39
|
+
clear(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Prewarm pools with buffers
|
|
42
|
+
*/
|
|
43
|
+
prewarm(countPerSize?: number): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Global buffer pool
|
|
47
|
+
*/
|
|
48
|
+
export declare const bufferPool: BufferPool;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Object Pool
|
|
3
|
+
*
|
|
4
|
+
* Reduces GC pressure by reusing objects instead of allocating new ones.
|
|
5
|
+
* Target: 80% GC reduction, 60% memory usage reduction
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Poolable interface - objects that can be pooled must implement this
|
|
9
|
+
*/
|
|
10
|
+
export interface Poolable {
|
|
11
|
+
/**
|
|
12
|
+
* Reset the object to initial state for reuse
|
|
13
|
+
*/
|
|
14
|
+
reset(): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generic Object Pool
|
|
18
|
+
*/
|
|
19
|
+
export declare class ObjectPool<T extends Poolable> {
|
|
20
|
+
private available;
|
|
21
|
+
private inUse;
|
|
22
|
+
private factory;
|
|
23
|
+
private maxSize;
|
|
24
|
+
private created;
|
|
25
|
+
private stats;
|
|
26
|
+
constructor(factory: () => T, maxSize?: number);
|
|
27
|
+
/**
|
|
28
|
+
* Acquire an object from the pool
|
|
29
|
+
* Reuses existing or creates new if needed
|
|
30
|
+
*/
|
|
31
|
+
acquire(): T;
|
|
32
|
+
/**
|
|
33
|
+
* Release an object back to the pool
|
|
34
|
+
* Object is reset and made available for reuse
|
|
35
|
+
*/
|
|
36
|
+
release(obj: T): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get pool statistics
|
|
39
|
+
*/
|
|
40
|
+
getStats(): {
|
|
41
|
+
created: number;
|
|
42
|
+
available: number;
|
|
43
|
+
inUse: number;
|
|
44
|
+
acquires: number;
|
|
45
|
+
releases: number;
|
|
46
|
+
hits: number;
|
|
47
|
+
misses: number;
|
|
48
|
+
disposed: number;
|
|
49
|
+
hitRate: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Clear the pool
|
|
53
|
+
*/
|
|
54
|
+
clear(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Prewarm the pool with N objects
|
|
57
|
+
*/
|
|
58
|
+
prewarm(count: number): void;
|
|
59
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String Interning Pool
|
|
3
|
+
*
|
|
4
|
+
* Reduces memory by deduplicating identical strings.
|
|
5
|
+
* Especially useful for repeated agent names, status values, etc.
|
|
6
|
+
*/
|
|
7
|
+
export declare class StringPool {
|
|
8
|
+
private pool;
|
|
9
|
+
private maxLength;
|
|
10
|
+
private maxSize;
|
|
11
|
+
private stats;
|
|
12
|
+
/**
|
|
13
|
+
* Intern a string - returns the canonical instance
|
|
14
|
+
* Type-safe version that preserves the input type
|
|
15
|
+
*/
|
|
16
|
+
intern<T extends string>(str: T): T;
|
|
17
|
+
/**
|
|
18
|
+
* Get pool statistics
|
|
19
|
+
*/
|
|
20
|
+
getStats(): {
|
|
21
|
+
interns: number;
|
|
22
|
+
hits: number;
|
|
23
|
+
misses: number;
|
|
24
|
+
skipped: number;
|
|
25
|
+
hitRate: number;
|
|
26
|
+
poolSize: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Clear the pool
|
|
30
|
+
*/
|
|
31
|
+
clear(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Prewarm with common strings
|
|
34
|
+
*/
|
|
35
|
+
prewarm(strings: string[]): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Global string pool
|
|
39
|
+
*/
|
|
40
|
+
export declare const stringPool: StringPool;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ParallelTask Object Pool
|
|
3
|
+
*
|
|
4
|
+
* Reduces GC pressure by reusing ParallelTask objects.
|
|
5
|
+
* Pool size: 200 instances (typical max concurrent tasks)
|
|
6
|
+
*/
|
|
7
|
+
import { ObjectPool } from "./object-pool.js";
|
|
8
|
+
import type { ParallelTask } from "../../shared/task/interfaces/parallel-task.js";
|
|
9
|
+
/**
|
|
10
|
+
* Global ParallelTask pool
|
|
11
|
+
* Pool size: 200 (typical max concurrent tasks)
|
|
12
|
+
*/
|
|
13
|
+
export declare const taskPool: ObjectPool<ParallelTask>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chase-Lev Work-Stealing Deque
|
|
3
|
+
*
|
|
4
|
+
* Lock-free deque for efficient work-stealing scheduling.
|
|
5
|
+
* - Owner pushes/pops from bottom (LIFO for cache locality)
|
|
6
|
+
* - Thieves steal from top (FIFO for fairness)
|
|
7
|
+
*
|
|
8
|
+
* Based on: "Dynamic Circular Work-Stealing Deque" (Chase & Lev, 2005)
|
|
9
|
+
*/
|
|
10
|
+
import { TaskPriority } from "../agents/concurrency.js";
|
|
11
|
+
export interface WorkItem<T> {
|
|
12
|
+
task: T;
|
|
13
|
+
priority: TaskPriority;
|
|
14
|
+
enqueuedAt: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Work-Stealing Deque (Chase-Lev)
|
|
18
|
+
*/
|
|
19
|
+
export declare class WorkStealingDeque<T> {
|
|
20
|
+
private top;
|
|
21
|
+
private bottom;
|
|
22
|
+
private array;
|
|
23
|
+
constructor(initialCapacity?: number);
|
|
24
|
+
/**
|
|
25
|
+
* Push item to bottom (owner only)
|
|
26
|
+
* LIFO for owner = better cache locality
|
|
27
|
+
*/
|
|
28
|
+
push(item: WorkItem<T>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Pop item from bottom (owner only)
|
|
31
|
+
* LIFO for owner = better cache locality
|
|
32
|
+
*/
|
|
33
|
+
pop(): WorkItem<T> | null;
|
|
34
|
+
/**
|
|
35
|
+
* Steal item from top (thieves)
|
|
36
|
+
* FIFO for thieves = better fairness
|
|
37
|
+
*/
|
|
38
|
+
steal(): WorkItem<T> | null;
|
|
39
|
+
/**
|
|
40
|
+
* Get current size (approximate, not thread-safe)
|
|
41
|
+
*/
|
|
42
|
+
size(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Check if empty
|
|
45
|
+
*/
|
|
46
|
+
isEmpty(): boolean;
|
|
47
|
+
}
|