@jackchen_me/open-multi-agent 0.1.0

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.
Files changed (133) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +280 -0
  3. package/dist/agent/agent.d.ts +121 -0
  4. package/dist/agent/agent.d.ts.map +1 -0
  5. package/dist/agent/agent.js +294 -0
  6. package/dist/agent/agent.js.map +1 -0
  7. package/dist/agent/pool.d.ts +128 -0
  8. package/dist/agent/pool.d.ts.map +1 -0
  9. package/dist/agent/pool.js +236 -0
  10. package/dist/agent/pool.js.map +1 -0
  11. package/dist/agent/runner.d.ts +120 -0
  12. package/dist/agent/runner.d.ts.map +1 -0
  13. package/dist/agent/runner.js +274 -0
  14. package/dist/agent/runner.js.map +1 -0
  15. package/dist/index.d.ts +73 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +87 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/llm/adapter.d.ts +38 -0
  20. package/dist/llm/adapter.d.ts.map +1 -0
  21. package/dist/llm/adapter.js +46 -0
  22. package/dist/llm/adapter.js.map +1 -0
  23. package/dist/llm/anthropic.d.ts +56 -0
  24. package/dist/llm/anthropic.d.ts.map +1 -0
  25. package/dist/llm/anthropic.js +307 -0
  26. package/dist/llm/anthropic.js.map +1 -0
  27. package/dist/llm/openai.d.ts +62 -0
  28. package/dist/llm/openai.d.ts.map +1 -0
  29. package/dist/llm/openai.js +424 -0
  30. package/dist/llm/openai.js.map +1 -0
  31. package/dist/memory/shared.d.ts +86 -0
  32. package/dist/memory/shared.d.ts.map +1 -0
  33. package/dist/memory/shared.js +155 -0
  34. package/dist/memory/shared.js.map +1 -0
  35. package/dist/memory/store.d.ts +64 -0
  36. package/dist/memory/store.d.ts.map +1 -0
  37. package/dist/memory/store.js +103 -0
  38. package/dist/memory/store.js.map +1 -0
  39. package/dist/orchestrator/orchestrator.d.ts +173 -0
  40. package/dist/orchestrator/orchestrator.d.ts.map +1 -0
  41. package/dist/orchestrator/orchestrator.js +698 -0
  42. package/dist/orchestrator/orchestrator.js.map +1 -0
  43. package/dist/orchestrator/scheduler.d.ts +112 -0
  44. package/dist/orchestrator/scheduler.d.ts.map +1 -0
  45. package/dist/orchestrator/scheduler.js +282 -0
  46. package/dist/orchestrator/scheduler.js.map +1 -0
  47. package/dist/task/queue.d.ts +160 -0
  48. package/dist/task/queue.d.ts.map +1 -0
  49. package/dist/task/queue.js +337 -0
  50. package/dist/task/queue.js.map +1 -0
  51. package/dist/task/task.d.ts +86 -0
  52. package/dist/task/task.d.ts.map +1 -0
  53. package/dist/task/task.js +201 -0
  54. package/dist/task/task.js.map +1 -0
  55. package/dist/team/messaging.d.ts +106 -0
  56. package/dist/team/messaging.d.ts.map +1 -0
  57. package/dist/team/messaging.js +182 -0
  58. package/dist/team/messaging.js.map +1 -0
  59. package/dist/team/team.d.ts +141 -0
  60. package/dist/team/team.d.ts.map +1 -0
  61. package/dist/team/team.js +282 -0
  62. package/dist/team/team.js.map +1 -0
  63. package/dist/tool/built-in/bash.d.ts +12 -0
  64. package/dist/tool/built-in/bash.d.ts.map +1 -0
  65. package/dist/tool/built-in/bash.js +133 -0
  66. package/dist/tool/built-in/bash.js.map +1 -0
  67. package/dist/tool/built-in/file-edit.d.ts +14 -0
  68. package/dist/tool/built-in/file-edit.d.ts.map +1 -0
  69. package/dist/tool/built-in/file-edit.js +130 -0
  70. package/dist/tool/built-in/file-edit.js.map +1 -0
  71. package/dist/tool/built-in/file-read.d.ts +12 -0
  72. package/dist/tool/built-in/file-read.d.ts.map +1 -0
  73. package/dist/tool/built-in/file-read.js +82 -0
  74. package/dist/tool/built-in/file-read.js.map +1 -0
  75. package/dist/tool/built-in/file-write.d.ts +11 -0
  76. package/dist/tool/built-in/file-write.d.ts.map +1 -0
  77. package/dist/tool/built-in/file-write.js +70 -0
  78. package/dist/tool/built-in/file-write.js.map +1 -0
  79. package/dist/tool/built-in/grep.d.ts +15 -0
  80. package/dist/tool/built-in/grep.d.ts.map +1 -0
  81. package/dist/tool/built-in/grep.js +287 -0
  82. package/dist/tool/built-in/grep.js.map +1 -0
  83. package/dist/tool/built-in/index.d.ts +36 -0
  84. package/dist/tool/built-in/index.d.ts.map +1 -0
  85. package/dist/tool/built-in/index.js +45 -0
  86. package/dist/tool/built-in/index.js.map +1 -0
  87. package/dist/tool/executor.d.ts +71 -0
  88. package/dist/tool/executor.d.ts.map +1 -0
  89. package/dist/tool/executor.js +116 -0
  90. package/dist/tool/executor.js.map +1 -0
  91. package/dist/tool/framework.d.ts +143 -0
  92. package/dist/tool/framework.d.ts.map +1 -0
  93. package/dist/tool/framework.js +371 -0
  94. package/dist/tool/framework.js.map +1 -0
  95. package/dist/types.d.ts +285 -0
  96. package/dist/types.d.ts.map +1 -0
  97. package/dist/types.js +8 -0
  98. package/dist/types.js.map +1 -0
  99. package/dist/utils/semaphore.d.ts +47 -0
  100. package/dist/utils/semaphore.d.ts.map +1 -0
  101. package/dist/utils/semaphore.js +85 -0
  102. package/dist/utils/semaphore.js.map +1 -0
  103. package/examples/01-single-agent.ts +131 -0
  104. package/examples/02-team-collaboration.ts +167 -0
  105. package/examples/03-task-pipeline.ts +201 -0
  106. package/examples/04-multi-model-team.ts +261 -0
  107. package/package.json +49 -0
  108. package/src/agent/agent.ts +364 -0
  109. package/src/agent/pool.ts +278 -0
  110. package/src/agent/runner.ts +413 -0
  111. package/src/index.ts +166 -0
  112. package/src/llm/adapter.ts +74 -0
  113. package/src/llm/anthropic.ts +388 -0
  114. package/src/llm/openai.ts +522 -0
  115. package/src/memory/shared.ts +181 -0
  116. package/src/memory/store.ts +124 -0
  117. package/src/orchestrator/orchestrator.ts +851 -0
  118. package/src/orchestrator/scheduler.ts +352 -0
  119. package/src/task/queue.ts +394 -0
  120. package/src/task/task.ts +232 -0
  121. package/src/team/messaging.ts +230 -0
  122. package/src/team/team.ts +334 -0
  123. package/src/tool/built-in/bash.ts +187 -0
  124. package/src/tool/built-in/file-edit.ts +154 -0
  125. package/src/tool/built-in/file-read.ts +105 -0
  126. package/src/tool/built-in/file-write.ts +81 -0
  127. package/src/tool/built-in/grep.ts +362 -0
  128. package/src/tool/built-in/index.ts +50 -0
  129. package/src/tool/executor.ts +178 -0
  130. package/src/tool/framework.ts +557 -0
  131. package/src/types.ts +362 -0
  132. package/src/utils/semaphore.ts +89 -0
  133. package/tsconfig.json +25 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAaH,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAM,UAAU,GAAe,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAA;AACpE,MAAM,uBAAuB,GAAG,CAAC,CAAA;AACjC,MAAM,aAAa,GAAG,iBAAiB,CAAA;AAEvC,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,CAAa,EAAE,CAAa;IAC5C,OAAO;QACL,YAAY,EAAE,CAAC,CAAC,YAAY,GAAG,CAAC,CA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AAC,UAAU,CAAC;oBAC5D,SAAS,EAAE,CAAC,GAAG,QAAQ,CAAC,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;iBACxD,CAAC,CAAA;YACJ,CAAC;YAED,+DAA+D;YAC/D,iEAAiE;YACjE,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;gBACrD,IAAI,CAAC,kBAAkB,EAAE,CAAA;YAC3B,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO,EAAE,cAAc;YACvB,YAAY,EAAE,SAAS;YACvB,eAAe,EAAE,UAAU;SAC5B,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @fileoverview Task scheduling strategies for the open-multi-agent orchestrator.
3
+ *
4
+ * The {@link Scheduler} class encapsulates four distinct strategies for
5
+ * mapping a set of pending {@link Task}s onto a pool of available agents:
6
+ *
7
+ * - `round-robin` — Distribute tasks evenly across agents by index.
8
+ * - `least-busy` — Assign to whichever agent has the fewest active tasks.
9
+ * - `capability-match` — Score agents by keyword overlap with the task description.
10
+ * - `dependency-first` — Prioritise tasks on the critical path (most blocked dependents).
11
+ *
12
+ * The scheduler is stateless between calls. All mutable task state lives in the
13
+ * {@link TaskQueue} that is passed to {@link Scheduler.autoAssign}.
14
+ */
15
+ import type { AgentConfig, Task } from '../types.js';
16
+ import type { TaskQueue } from '../task/queue.js';
17
+ /**
18
+ * The four scheduling strategies available to the {@link Scheduler}.
19
+ *
20
+ * - `round-robin` — Equal distribution by agent index.
21
+ * - `least-busy` — Prefers the agent with the fewest `in_progress` tasks.
22
+ * - `capability-match` — Keyword-based affinity between task text and agent role.
23
+ * - `dependency-first` — Prioritise tasks that unblock the most other tasks.
24
+ */
25
+ export type SchedulingStrategy = 'round-robin' | 'least-busy' | 'capability-match' | 'dependency-first';
26
+ /**
27
+ * Maps pending tasks to available agents using one of four configurable strategies.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const scheduler = new Scheduler('capability-match')
32
+ *
33
+ * // Get a full assignment map from tasks to agent names
34
+ * const assignments = scheduler.schedule(pendingTasks, teamAgents)
35
+ *
36
+ * // Or let the scheduler directly update a TaskQueue
37
+ * scheduler.autoAssign(queue, teamAgents)
38
+ * ```
39
+ */
40
+ export declare class Scheduler {
41
+ private readonly strategy;
42
+ /** Rolling cursor used by `round-robin` to distribute tasks sequentially. */
43
+ private roundRobinCursor;
44
+ /**
45
+ * @param strategy - The scheduling algorithm to apply. Defaults to
46
+ * `'dependency-first'` which is the safest default for
47
+ * complex multi-step pipelines.
48
+ */
49
+ constructor(strategy?: SchedulingStrategy);
50
+ /**
51
+ * Given a list of pending `tasks` and `agents`, return a mapping from
52
+ * `taskId` to `agentName` representing the recommended assignment.
53
+ *
54
+ * Only tasks without an existing `assignee` are considered. Tasks that are
55
+ * already assigned are preserved unchanged.
56
+ *
57
+ * The method is deterministic for all strategies except `round-robin`, which
58
+ * advances an internal cursor and therefore produces different results across
59
+ * successive calls with the same inputs.
60
+ *
61
+ * @param tasks - Snapshot of all tasks in the current run (any status).
62
+ * @param agents - Available agent configurations.
63
+ * @returns A `Map<taskId, agentName>` for every unassigned pending task.
64
+ */
65
+ schedule(tasks: Task[], agents: AgentConfig[]): Map<string, string>;
66
+ /**
67
+ * Convenience method that applies assignments returned by {@link schedule}
68
+ * directly to a live `TaskQueue`.
69
+ *
70
+ * Iterates all pending, unassigned tasks in the queue and sets `assignee` for
71
+ * each according to the current strategy. Skips tasks that are already
72
+ * assigned, non-pending, or whose IDs are not found in the queue snapshot.
73
+ *
74
+ * @param queue - The live task queue to mutate.
75
+ * @param agents - Available agent configurations.
76
+ */
77
+ autoAssign(queue: TaskQueue, agents: AgentConfig[]): void;
78
+ /**
79
+ * Round-robin: assign tasks to agents in order, cycling back to the start.
80
+ *
81
+ * The cursor advances with every call so that repeated calls with the same
82
+ * task set continue distributing work — rather than always starting from
83
+ * agent[0].
84
+ */
85
+ private scheduleRoundRobin;
86
+ /**
87
+ * Least-busy: assign each task to the agent with the fewest `in_progress`
88
+ * tasks at the time the schedule is computed.
89
+ *
90
+ * Agent load is derived from the `in_progress` count in `allTasks`. Ties are
91
+ * broken by the agent's position in the `agents` array (earlier = preferred).
92
+ */
93
+ private scheduleLeastBusy;
94
+ /**
95
+ * Capability-match: score each agent against each task by keyword overlap
96
+ * between the task's title/description and the agent's `systemPrompt` and
97
+ * `name`. The highest-scoring agent wins.
98
+ *
99
+ * Falls back to round-robin when no agent has any positive score.
100
+ */
101
+ private scheduleCapabilityMatch;
102
+ /**
103
+ * Dependency-first: prioritise tasks by how many other tasks are blocked
104
+ * waiting for them (the "critical path" heuristic).
105
+ *
106
+ * Tasks with more downstream dependents are assigned to agents first. Within
107
+ * the same criticality tier the agents are selected round-robin so no single
108
+ * agent is overloaded.
109
+ */
110
+ private scheduleDependencyFirst;
111
+ }
112
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/orchestrator/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAMjD;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,YAAY,GACZ,kBAAkB,GAClB,kBAAkB,CAAA;AA8EtB;;;;;;;;;;;;;GAaG;AACH,qBAAa,SAAS;IASR,OAAO,CAAC,QAAQ,CAAC,QAAQ;IARrC,6EAA6E;IAC7E,OAAO,CAAC,gBAAgB,CAAI;IAE5B;;;;OAIG;gBAC0B,QAAQ,GAAE,kBAAuC;IAM9E;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAmBnE;;;;;;;;;;OAUG;IACH,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI;IAiBzD;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAsCzB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAyC/B;;;;;;;OAOG;IACH,OAAO,CAAC,uBAAuB;CA2BhC"}
@@ -0,0 +1,282 @@
1
+ /**
2
+ * @fileoverview Task scheduling strategies for the open-multi-agent orchestrator.
3
+ *
4
+ * The {@link Scheduler} class encapsulates four distinct strategies for
5
+ * mapping a set of pending {@link Task}s onto a pool of available agents:
6
+ *
7
+ * - `round-robin` — Distribute tasks evenly across agents by index.
8
+ * - `least-busy` — Assign to whichever agent has the fewest active tasks.
9
+ * - `capability-match` — Score agents by keyword overlap with the task description.
10
+ * - `dependency-first` — Prioritise tasks on the critical path (most blocked dependents).
11
+ *
12
+ * The scheduler is stateless between calls. All mutable task state lives in the
13
+ * {@link TaskQueue} that is passed to {@link Scheduler.autoAssign}.
14
+ */
15
+ // ---------------------------------------------------------------------------
16
+ // Internal helpers
17
+ // ---------------------------------------------------------------------------
18
+ /**
19
+ * Count how many tasks in `allTasks` are (transitively) blocked waiting for
20
+ * `taskId` to complete. Used by the `dependency-first` strategy to compute
21
+ * the "criticality" of each pending task.
22
+ *
23
+ * The algorithm is a forward BFS over the dependency graph: for each task
24
+ * whose `dependsOn` includes `taskId`, we add it to the result set and
25
+ * recurse — without revisiting nodes.
26
+ */
27
+ function countBlockedDependents(taskId, allTasks) {
28
+ const idToTask = new Map(allTasks.map((t) => [t.id, t]));
29
+ // Build reverse adjacency: dependencyId -> tasks that depend on it
30
+ const dependents = new Map();
31
+ for (const t of allTasks) {
32
+ for (const depId of t.dependsOn ?? []) {
33
+ const list = dependents.get(depId) ?? [];
34
+ list.push(t.id);
35
+ dependents.set(depId, list);
36
+ }
37
+ }
38
+ const visited = new Set();
39
+ const queue = [taskId];
40
+ while (queue.length > 0) {
41
+ const current = queue.shift();
42
+ for (const depId of dependents.get(current) ?? []) {
43
+ if (!visited.has(depId) && idToTask.has(depId)) {
44
+ visited.add(depId);
45
+ queue.push(depId);
46
+ }
47
+ }
48
+ }
49
+ // Exclude the seed task itself from the count
50
+ return visited.size;
51
+ }
52
+ /**
53
+ * Compute a simple keyword-overlap score between `text` and `keywords`.
54
+ *
55
+ * Both the text and keywords are normalised to lower-case before comparison.
56
+ * Each keyword that appears in the text contributes +1 to the score.
57
+ */
58
+ function keywordScore(text, keywords) {
59
+ const lower = text.toLowerCase();
60
+ return keywords.reduce((acc, kw) => acc + (lower.includes(kw.toLowerCase()) ? 1 : 0), 0);
61
+ }
62
+ /**
63
+ * Extract a list of meaningful keywords from a string for capability matching.
64
+ *
65
+ * Strips common stop-words so that incidental matches (e.g. "the", "and") do
66
+ * not inflate scores. Returns unique words longer than three characters.
67
+ */
68
+ function extractKeywords(text) {
69
+ const STOP_WORDS = new Set([
70
+ 'the', 'and', 'for', 'that', 'this', 'with', 'are', 'from', 'have',
71
+ 'will', 'your', 'you', 'can', 'all', 'each', 'when', 'then', 'they',
72
+ 'them', 'their', 'about', 'into', 'more', 'also', 'should', 'must',
73
+ ]);
74
+ return [...new Set(text
75
+ .toLowerCase()
76
+ .split(/\W+/)
77
+ .filter((w) => w.length > 3 && !STOP_WORDS.has(w)))];
78
+ }
79
+ // ---------------------------------------------------------------------------
80
+ // Scheduler
81
+ // ---------------------------------------------------------------------------
82
+ /**
83
+ * Maps pending tasks to available agents using one of four configurable strategies.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const scheduler = new Scheduler('capability-match')
88
+ *
89
+ * // Get a full assignment map from tasks to agent names
90
+ * const assignments = scheduler.schedule(pendingTasks, teamAgents)
91
+ *
92
+ * // Or let the scheduler directly update a TaskQueue
93
+ * scheduler.autoAssign(queue, teamAgents)
94
+ * ```
95
+ */
96
+ export class Scheduler {
97
+ strategy;
98
+ /** Rolling cursor used by `round-robin` to distribute tasks sequentially. */
99
+ roundRobinCursor = 0;
100
+ /**
101
+ * @param strategy - The scheduling algorithm to apply. Defaults to
102
+ * `'dependency-first'` which is the safest default for
103
+ * complex multi-step pipelines.
104
+ */
105
+ constructor(strategy = 'dependency-first') {
106
+ this.strategy = strategy;
107
+ }
108
+ // -------------------------------------------------------------------------
109
+ // Primary API
110
+ // -------------------------------------------------------------------------
111
+ /**
112
+ * Given a list of pending `tasks` and `agents`, return a mapping from
113
+ * `taskId` to `agentName` representing the recommended assignment.
114
+ *
115
+ * Only tasks without an existing `assignee` are considered. Tasks that are
116
+ * already assigned are preserved unchanged.
117
+ *
118
+ * The method is deterministic for all strategies except `round-robin`, which
119
+ * advances an internal cursor and therefore produces different results across
120
+ * successive calls with the same inputs.
121
+ *
122
+ * @param tasks - Snapshot of all tasks in the current run (any status).
123
+ * @param agents - Available agent configurations.
124
+ * @returns A `Map<taskId, agentName>` for every unassigned pending task.
125
+ */
126
+ schedule(tasks, agents) {
127
+ if (agents.length === 0)
128
+ return new Map();
129
+ const unassigned = tasks.filter((t) => t.status === 'pending' && !t.assignee);
130
+ switch (this.strategy) {
131
+ case 'round-robin':
132
+ return this.scheduleRoundRobin(unassigned, agents);
133
+ case 'least-busy':
134
+ return this.scheduleLeastBusy(unassigned, agents, tasks);
135
+ case 'capability-match':
136
+ return this.scheduleCapabilityMatch(unassigned, agents);
137
+ case 'dependency-first':
138
+ return this.scheduleDependencyFirst(unassigned, agents, tasks);
139
+ }
140
+ }
141
+ /**
142
+ * Convenience method that applies assignments returned by {@link schedule}
143
+ * directly to a live `TaskQueue`.
144
+ *
145
+ * Iterates all pending, unassigned tasks in the queue and sets `assignee` for
146
+ * each according to the current strategy. Skips tasks that are already
147
+ * assigned, non-pending, or whose IDs are not found in the queue snapshot.
148
+ *
149
+ * @param queue - The live task queue to mutate.
150
+ * @param agents - Available agent configurations.
151
+ */
152
+ autoAssign(queue, agents) {
153
+ const allTasks = queue.list();
154
+ const assignments = this.schedule(allTasks, agents);
155
+ for (const [taskId, agentName] of assignments) {
156
+ try {
157
+ queue.update(taskId, { assignee: agentName });
158
+ }
159
+ catch {
160
+ // Task may have been completed/failed between snapshot and now — skip.
161
+ }
162
+ }
163
+ }
164
+ // -------------------------------------------------------------------------
165
+ // Strategy implementations
166
+ // -------------------------------------------------------------------------
167
+ /**
168
+ * Round-robin: assign tasks to agents in order, cycling back to the start.
169
+ *
170
+ * The cursor advances with every call so that repeated calls with the same
171
+ * task set continue distributing work — rather than always starting from
172
+ * agent[0].
173
+ */
174
+ scheduleRoundRobin(unassigned, agents) {
175
+ const result = new Map();
176
+ for (const task of unassigned) {
177
+ const agent = agents[this.roundRobinCursor % agents.length];
178
+ result.set(task.id, agent.name);
179
+ this.roundRobinCursor = (this.roundRobinCursor + 1) % agents.length;
180
+ }
181
+ return result;
182
+ }
183
+ /**
184
+ * Least-busy: assign each task to the agent with the fewest `in_progress`
185
+ * tasks at the time the schedule is computed.
186
+ *
187
+ * Agent load is derived from the `in_progress` count in `allTasks`. Ties are
188
+ * broken by the agent's position in the `agents` array (earlier = preferred).
189
+ */
190
+ scheduleLeastBusy(unassigned, agents, allTasks) {
191
+ // Build initial in-progress count per agent.
192
+ const load = new Map(agents.map((a) => [a.name, 0]));
193
+ for (const task of allTasks) {
194
+ if (task.status === 'in_progress' && task.assignee) {
195
+ const current = load.get(task.assignee) ?? 0;
196
+ load.set(task.assignee, current + 1);
197
+ }
198
+ }
199
+ const result = new Map();
200
+ for (const task of unassigned) {
201
+ // Pick the agent with the lowest current load.
202
+ let bestAgent = agents[0];
203
+ let bestLoad = load.get(bestAgent.name) ?? 0;
204
+ for (let i = 1; i < agents.length; i++) {
205
+ const agent = agents[i];
206
+ const agentLoad = load.get(agent.name) ?? 0;
207
+ if (agentLoad < bestLoad) {
208
+ bestLoad = agentLoad;
209
+ bestAgent = agent;
210
+ }
211
+ }
212
+ result.set(task.id, bestAgent.name);
213
+ // Increment the simulated load so subsequent tasks in this batch avoid
214
+ // piling onto the same agent.
215
+ load.set(bestAgent.name, (load.get(bestAgent.name) ?? 0) + 1);
216
+ }
217
+ return result;
218
+ }
219
+ /**
220
+ * Capability-match: score each agent against each task by keyword overlap
221
+ * between the task's title/description and the agent's `systemPrompt` and
222
+ * `name`. The highest-scoring agent wins.
223
+ *
224
+ * Falls back to round-robin when no agent has any positive score.
225
+ */
226
+ scheduleCapabilityMatch(unassigned, agents) {
227
+ const result = new Map();
228
+ // Pre-compute keyword lists for each agent to avoid re-extracting per task.
229
+ const agentKeywords = new Map(agents.map((a) => [
230
+ a.name,
231
+ extractKeywords(`${a.name} ${a.systemPrompt ?? ''} ${a.model}`),
232
+ ]));
233
+ for (const task of unassigned) {
234
+ const taskText = `${task.title} ${task.description}`;
235
+ const taskKeywords = extractKeywords(taskText);
236
+ let bestAgent = agents[0];
237
+ let bestScore = -1;
238
+ for (const agent of agents) {
239
+ // Score in both directions: task keywords vs agent text, and agent
240
+ // keywords vs task text, then take the max.
241
+ const agentText = `${agent.name} ${agent.systemPrompt ?? ''}`;
242
+ const scoreA = keywordScore(agentText, taskKeywords);
243
+ const scoreB = keywordScore(taskText, agentKeywords.get(agent.name) ?? []);
244
+ const score = scoreA + scoreB;
245
+ if (score > bestScore) {
246
+ bestScore = score;
247
+ bestAgent = agent;
248
+ }
249
+ }
250
+ result.set(task.id, bestAgent.name);
251
+ }
252
+ return result;
253
+ }
254
+ /**
255
+ * Dependency-first: prioritise tasks by how many other tasks are blocked
256
+ * waiting for them (the "critical path" heuristic).
257
+ *
258
+ * Tasks with more downstream dependents are assigned to agents first. Within
259
+ * the same criticality tier the agents are selected round-robin so no single
260
+ * agent is overloaded.
261
+ */
262
+ scheduleDependencyFirst(unassigned, agents, allTasks) {
263
+ // Sort by descending blocked-dependent count so high-criticality tasks
264
+ // get first choice of agents.
265
+ const ranked = [...unassigned].sort((a, b) => {
266
+ const critA = countBlockedDependents(a.id, allTasks);
267
+ const critB = countBlockedDependents(b.id, allTasks);
268
+ return critB - critA;
269
+ });
270
+ const result = new Map();
271
+ let cursor = this.roundRobinCursor;
272
+ for (const task of ranked) {
273
+ const agent = agents[cursor % agents.length];
274
+ result.set(task.id, agent.name);
275
+ cursor = (cursor + 1) % agents.length;
276
+ }
277
+ // Advance the shared cursor for consistency with round-robin.
278
+ this.roundRobinCursor = cursor;
279
+ return result;
280
+ }
281
+ }
282
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/orchestrator/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAuBH,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,SAAS,sBAAsB,CAAC,MAAc,EAAE,QAAgB;IAC9D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAe,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACtE,mEAAmE;IACnE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAoB,CAAA;IAC9C,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;YACxC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;YACf,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,MAAM,KAAK,GAAa,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,KA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Dependency-aware task queue.
3
+ *
4
+ * {@link TaskQueue} owns the mutable lifecycle of every task it holds.
5
+ * Completing a task automatically unblocks dependents and fires events so
6
+ * orchestrators can react without polling.
7
+ */
8
+ import type { Task, TaskStatus } from '../types.js';
9
+ /** Named event types emitted by {@link TaskQueue}. */
10
+ export type TaskQueueEvent = 'task:ready' | 'task:complete' | 'task:failed' | 'all:complete';
11
+ /** Handler for `'task:ready' | 'task:complete' | 'task:failed'` events. */
12
+ type TaskHandler = (task: Task) => void;
13
+ /** Handler for `'all:complete'` (no task argument). */
14
+ type AllCompleteHandler = () => void;
15
+ type HandlerFor<E extends TaskQueueEvent> = E extends 'all:complete' ? AllCompleteHandler : TaskHandler;
16
+ /**
17
+ * Mutable, event-driven queue with topological dependency resolution.
18
+ *
19
+ * Tasks enter in `'pending'` state. The queue promotes them to `'blocked'`
20
+ * when unresolved dependencies exist, and back to `'pending'` (firing
21
+ * `'task:ready'`) when those dependencies complete. Callers drive execution by
22
+ * calling {@link next} / {@link nextAvailable} and updating task state via
23
+ * {@link complete} or {@link fail}.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const queue = new TaskQueue()
28
+ * queue.on('task:ready', (task) => scheduleExecution(task))
29
+ * queue.on('all:complete', () => shutdown())
30
+ *
31
+ * queue.addBatch(tasks)
32
+ * ```
33
+ */
34
+ export declare class TaskQueue {
35
+ private readonly tasks;
36
+ /** Listeners keyed by event type, stored as symbol → handler pairs. */
37
+ private readonly listeners;
38
+ /**
39
+ * Adds a single task.
40
+ *
41
+ * If the task has unresolved dependencies it is immediately promoted to
42
+ * `'blocked'`; otherwise it stays `'pending'` and `'task:ready'` fires.
43
+ */
44
+ add(task: Task): void;
45
+ /**
46
+ * Adds multiple tasks at once.
47
+ *
48
+ * Processing each task re-evaluates the current map state, so inserting a
49
+ * batch where some tasks satisfy others' dependencies produces correct initial
50
+ * statuses when the dependencies appear first in the array. Use
51
+ * {@link getTaskDependencyOrder} from `task.ts` to pre-sort if needed.
52
+ */
53
+ addBatch(tasks: Task[]): void;
54
+ /**
55
+ * Applies a partial update to an existing task.
56
+ *
57
+ * Only `status`, `result`, and `assignee` are accepted to keep the update
58
+ * surface narrow. Use {@link complete} and {@link fail} for terminal states.
59
+ *
60
+ * @throws {Error} when `taskId` is not found.
61
+ */
62
+ update(taskId: string, update: Partial<Pick<Task, 'status' | 'result' | 'assignee'>>): Task;
63
+ /**
64
+ * Marks `taskId` as `'completed'`, records an optional `result` string, and
65
+ * unblocks any dependents that are now ready to run.
66
+ *
67
+ * Fires `'task:complete'`, then `'task:ready'` for each newly-unblocked task,
68
+ * then `'all:complete'` when the queue is fully resolved.
69
+ *
70
+ * @throws {Error} when `taskId` is not found.
71
+ */
72
+ complete(taskId: string, result?: string): Task;
73
+ /**
74
+ * Marks `taskId` as `'failed'` and records `error` in the `result` field.
75
+ *
76
+ * Fires `'task:failed'` for the failed task and for every downstream task
77
+ * that transitively depended on it (cascade failure). This prevents blocked
78
+ * tasks from remaining stuck indefinitely when an upstream dependency fails.
79
+ *
80
+ * @throws {Error} when `taskId` is not found.
81
+ */
82
+ fail(taskId: string, error: string): Task;
83
+ /**
84
+ * Recursively marks all tasks that (transitively) depend on `failedTaskId`
85
+ * as `'failed'` with an informative message, firing `'task:failed'` for each.
86
+ *
87
+ * Only tasks in `'blocked'` or `'pending'` state are affected; tasks already
88
+ * in a terminal state are left untouched.
89
+ */
90
+ private cascadeFailure;
91
+ /**
92
+ * Returns the next `'pending'` task for `assignee` (matched against
93
+ * `task.assignee`), or `undefined` if none exists.
94
+ *
95
+ * If `assignee` is omitted, behaves like {@link nextAvailable}.
96
+ */
97
+ next(assignee?: string): Task | undefined;
98
+ /**
99
+ * Returns the next `'pending'` task that has no `assignee` restriction, or
100
+ * the first `'pending'` task overall when all pending tasks have an assignee.
101
+ */
102
+ nextAvailable(): Task | undefined;
103
+ /** Returns a snapshot array of all tasks (any status). */
104
+ list(): Task[];
105
+ /** Returns all tasks whose `status` matches `status`. */
106
+ getByStatus(status: TaskStatus): Task[];
107
+ /**
108
+ * Returns `true` when every task in the queue has reached a terminal state
109
+ * (`'completed'` or `'failed'`), **or** the queue is empty.
110
+ */
111
+ isComplete(): boolean;
112
+ /**
113
+ * Returns a progress snapshot.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const { completed, total } = queue.getProgress()
118
+ * console.log(`${completed}/${total} tasks done`)
119
+ * ```
120
+ */
121
+ getProgress(): {
122
+ total: number;
123
+ completed: number;
124
+ failed: number;
125
+ inProgress: number;
126
+ pending: number;
127
+ blocked: number;
128
+ };
129
+ /**
130
+ * Subscribes to a queue event.
131
+ *
132
+ * @returns An unsubscribe function. Calling it is idempotent.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const off = queue.on('task:ready', (task) => execute(task))
137
+ * // later…
138
+ * off()
139
+ * ```
140
+ */
141
+ on<E extends TaskQueueEvent>(event: E, handler: HandlerFor<E>): () => void;
142
+ /**
143
+ * Evaluates whether `task` should start as `'blocked'` based on the tasks
144
+ * already registered in the queue.
145
+ */
146
+ private resolveInitialStatus;
147
+ /**
148
+ * After a task completes, scan all `'blocked'` tasks and promote any that are
149
+ * now fully satisfied to `'pending'`, firing `'task:ready'` for each.
150
+ *
151
+ * The task array and lookup map are built once for the entire scan to keep
152
+ * the operation O(n) rather than O(n²).
153
+ */
154
+ private unblockDependents;
155
+ private emit;
156
+ private emitAllComplete;
157
+ private requireTask;
158
+ }
159
+ export {};
160
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/task/queue.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOnD,sDAAsD;AACtD,MAAM,MAAM,cAAc,GACtB,YAAY,GACZ,eAAe,GACf,aAAa,GACb,cAAc,CAAA;AAElB,2EAA2E;AAC3E,KAAK,WAAW,GAAG,CAAC,IAA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