cmdr-agent 1.0.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.
- package/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/bin/cmdr.d.ts +9 -0
- package/dist/bin/cmdr.d.ts.map +1 -0
- package/dist/bin/cmdr.js +49 -0
- package/dist/bin/cmdr.js.map +1 -0
- package/dist/src/cli/args.d.ts +19 -0
- package/dist/src/cli/args.d.ts.map +1 -0
- package/dist/src/cli/args.js +89 -0
- package/dist/src/cli/args.js.map +1 -0
- package/dist/src/cli/commands.d.ts +12 -0
- package/dist/src/cli/commands.d.ts.map +1 -0
- package/dist/src/cli/commands.js +400 -0
- package/dist/src/cli/commands.js.map +1 -0
- package/dist/src/cli/renderer.d.ts +8 -0
- package/dist/src/cli/renderer.d.ts.map +1 -0
- package/dist/src/cli/renderer.js +47 -0
- package/dist/src/cli/renderer.js.map +1 -0
- package/dist/src/cli/repl.d.ts +18 -0
- package/dist/src/cli/repl.d.ts.map +1 -0
- package/dist/src/cli/repl.js +751 -0
- package/dist/src/cli/repl.js.map +1 -0
- package/dist/src/cli/spinner.d.ts +16 -0
- package/dist/src/cli/spinner.d.ts.map +1 -0
- package/dist/src/cli/spinner.js +233 -0
- package/dist/src/cli/spinner.js.map +1 -0
- package/dist/src/cli/theme.d.ts +95 -0
- package/dist/src/cli/theme.d.ts.map +1 -0
- package/dist/src/cli/theme.js +178 -0
- package/dist/src/cli/theme.js.map +1 -0
- package/dist/src/communication/message-bus.d.ts +35 -0
- package/dist/src/communication/message-bus.d.ts.map +1 -0
- package/dist/src/communication/message-bus.js +60 -0
- package/dist/src/communication/message-bus.js.map +1 -0
- package/dist/src/communication/shared-memory.d.ts +19 -0
- package/dist/src/communication/shared-memory.d.ts.map +1 -0
- package/dist/src/communication/shared-memory.js +37 -0
- package/dist/src/communication/shared-memory.js.map +1 -0
- package/dist/src/communication/task-queue.d.ts +50 -0
- package/dist/src/communication/task-queue.d.ts.map +1 -0
- package/dist/src/communication/task-queue.js +158 -0
- package/dist/src/communication/task-queue.js.map +1 -0
- package/dist/src/config/config-loader.d.ts +23 -0
- package/dist/src/config/config-loader.d.ts.map +1 -0
- package/dist/src/config/config-loader.js +91 -0
- package/dist/src/config/config-loader.js.map +1 -0
- package/dist/src/config/defaults.d.ts +6 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +21 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/schema.d.ts +135 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +35 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/config/telemetry.d.ts +41 -0
- package/dist/src/config/telemetry.d.ts.map +1 -0
- package/dist/src/config/telemetry.js +57 -0
- package/dist/src/config/telemetry.js.map +1 -0
- package/dist/src/core/agent-pool.d.ts +40 -0
- package/dist/src/core/agent-pool.d.ts.map +1 -0
- package/dist/src/core/agent-pool.js +66 -0
- package/dist/src/core/agent-pool.js.map +1 -0
- package/dist/src/core/agent-runner.d.ts +51 -0
- package/dist/src/core/agent-runner.d.ts.map +1 -0
- package/dist/src/core/agent-runner.js +251 -0
- package/dist/src/core/agent-runner.js.map +1 -0
- package/dist/src/core/agent.d.ts +34 -0
- package/dist/src/core/agent.d.ts.map +1 -0
- package/dist/src/core/agent.js +143 -0
- package/dist/src/core/agent.js.map +1 -0
- package/dist/src/core/intent.d.ts +33 -0
- package/dist/src/core/intent.d.ts.map +1 -0
- package/dist/src/core/intent.js +91 -0
- package/dist/src/core/intent.js.map +1 -0
- package/dist/src/core/orchestrator.d.ts +43 -0
- package/dist/src/core/orchestrator.d.ts.map +1 -0
- package/dist/src/core/orchestrator.js +115 -0
- package/dist/src/core/orchestrator.js.map +1 -0
- package/dist/src/core/permissions.d.ts +36 -0
- package/dist/src/core/permissions.d.ts.map +1 -0
- package/dist/src/core/permissions.js +129 -0
- package/dist/src/core/permissions.js.map +1 -0
- package/dist/src/core/presets.d.ts +12 -0
- package/dist/src/core/presets.d.ts.map +1 -0
- package/dist/src/core/presets.js +148 -0
- package/dist/src/core/presets.js.map +1 -0
- package/dist/src/core/team.d.ts +44 -0
- package/dist/src/core/team.d.ts.map +1 -0
- package/dist/src/core/team.js +156 -0
- package/dist/src/core/team.js.map +1 -0
- package/dist/src/core/types.d.ts +257 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +7 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/index.d.ts +44 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/llm/adapter.d.ts +5 -0
- package/dist/src/llm/adapter.d.ts.map +1 -0
- package/dist/src/llm/adapter.js +5 -0
- package/dist/src/llm/adapter.js.map +1 -0
- package/dist/src/llm/model-registry.d.ts +14 -0
- package/dist/src/llm/model-registry.d.ts.map +1 -0
- package/dist/src/llm/model-registry.js +30 -0
- package/dist/src/llm/model-registry.js.map +1 -0
- package/dist/src/llm/ollama.d.ts +26 -0
- package/dist/src/llm/ollama.d.ts.map +1 -0
- package/dist/src/llm/ollama.js +375 -0
- package/dist/src/llm/ollama.js.map +1 -0
- package/dist/src/llm/token-counter.d.ts +11 -0
- package/dist/src/llm/token-counter.d.ts.map +1 -0
- package/dist/src/llm/token-counter.js +35 -0
- package/dist/src/llm/token-counter.js.map +1 -0
- package/dist/src/plugins/mcp-client.d.ts +38 -0
- package/dist/src/plugins/mcp-client.d.ts.map +1 -0
- package/dist/src/plugins/mcp-client.js +113 -0
- package/dist/src/plugins/mcp-client.js.map +1 -0
- package/dist/src/plugins/plugin-manager.d.ts +37 -0
- package/dist/src/plugins/plugin-manager.d.ts.map +1 -0
- package/dist/src/plugins/plugin-manager.js +146 -0
- package/dist/src/plugins/plugin-manager.js.map +1 -0
- package/dist/src/scheduling/semaphore.d.ts +20 -0
- package/dist/src/scheduling/semaphore.d.ts.map +1 -0
- package/dist/src/scheduling/semaphore.js +52 -0
- package/dist/src/scheduling/semaphore.js.map +1 -0
- package/dist/src/scheduling/strategies.d.ts +39 -0
- package/dist/src/scheduling/strategies.d.ts.map +1 -0
- package/dist/src/scheduling/strategies.js +88 -0
- package/dist/src/scheduling/strategies.js.map +1 -0
- package/dist/src/session/compaction.d.ts +32 -0
- package/dist/src/session/compaction.d.ts.map +1 -0
- package/dist/src/session/compaction.js +172 -0
- package/dist/src/session/compaction.js.map +1 -0
- package/dist/src/session/cost-tracker.d.ts +41 -0
- package/dist/src/session/cost-tracker.d.ts.map +1 -0
- package/dist/src/session/cost-tracker.js +76 -0
- package/dist/src/session/cost-tracker.js.map +1 -0
- package/dist/src/session/project-context.d.ts +6 -0
- package/dist/src/session/project-context.d.ts.map +1 -0
- package/dist/src/session/project-context.js +147 -0
- package/dist/src/session/project-context.js.map +1 -0
- package/dist/src/session/prompt-builder.d.ts +11 -0
- package/dist/src/session/prompt-builder.d.ts.map +1 -0
- package/dist/src/session/prompt-builder.js +30 -0
- package/dist/src/session/prompt-builder.js.map +1 -0
- package/dist/src/session/session-manager.d.ts +32 -0
- package/dist/src/session/session-manager.d.ts.map +1 -0
- package/dist/src/session/session-manager.js +84 -0
- package/dist/src/session/session-manager.js.map +1 -0
- package/dist/src/session/session-persistence.d.ts +44 -0
- package/dist/src/session/session-persistence.d.ts.map +1 -0
- package/dist/src/session/session-persistence.js +150 -0
- package/dist/src/session/session-persistence.js.map +1 -0
- package/dist/src/session/undo-manager.d.ts +35 -0
- package/dist/src/session/undo-manager.d.ts.map +1 -0
- package/dist/src/session/undo-manager.js +79 -0
- package/dist/src/session/undo-manager.js.map +1 -0
- package/dist/src/tools/built-in/ask-user.d.ts +7 -0
- package/dist/src/tools/built-in/ask-user.d.ts.map +1 -0
- package/dist/src/tools/built-in/ask-user.js +28 -0
- package/dist/src/tools/built-in/ask-user.js.map +1 -0
- package/dist/src/tools/built-in/bash.d.ts +9 -0
- package/dist/src/tools/built-in/bash.d.ts.map +1 -0
- package/dist/src/tools/built-in/bash.js +67 -0
- package/dist/src/tools/built-in/bash.js.map +1 -0
- package/dist/src/tools/built-in/file-edit.d.ts +9 -0
- package/dist/src/tools/built-in/file-edit.d.ts.map +1 -0
- package/dist/src/tools/built-in/file-edit.js +39 -0
- package/dist/src/tools/built-in/file-edit.js.map +1 -0
- package/dist/src/tools/built-in/file-read.d.ts +9 -0
- package/dist/src/tools/built-in/file-read.d.ts.map +1 -0
- package/dist/src/tools/built-in/file-read.js +41 -0
- package/dist/src/tools/built-in/file-read.js.map +1 -0
- package/dist/src/tools/built-in/file-write.d.ts +8 -0
- package/dist/src/tools/built-in/file-write.d.ts.map +1 -0
- package/dist/src/tools/built-in/file-write.js +29 -0
- package/dist/src/tools/built-in/file-write.js.map +1 -0
- package/dist/src/tools/built-in/git-commit.d.ts +12 -0
- package/dist/src/tools/built-in/git-commit.d.ts.map +1 -0
- package/dist/src/tools/built-in/git-commit.js +96 -0
- package/dist/src/tools/built-in/git-commit.js.map +1 -0
- package/dist/src/tools/built-in/git-diff.d.ts +8 -0
- package/dist/src/tools/built-in/git-diff.d.ts.map +1 -0
- package/dist/src/tools/built-in/git-diff.js +43 -0
- package/dist/src/tools/built-in/git-diff.js.map +1 -0
- package/dist/src/tools/built-in/git-log.d.ts +8 -0
- package/dist/src/tools/built-in/git-log.d.ts.map +1 -0
- package/dist/src/tools/built-in/git-log.js +39 -0
- package/dist/src/tools/built-in/git-log.js.map +1 -0
- package/dist/src/tools/built-in/glob.d.ts +8 -0
- package/dist/src/tools/built-in/glob.d.ts.map +1 -0
- package/dist/src/tools/built-in/glob.js +60 -0
- package/dist/src/tools/built-in/glob.js.map +1 -0
- package/dist/src/tools/built-in/grep.d.ts +9 -0
- package/dist/src/tools/built-in/grep.d.ts.map +1 -0
- package/dist/src/tools/built-in/grep.js +115 -0
- package/dist/src/tools/built-in/grep.js.map +1 -0
- package/dist/src/tools/built-in/index.d.ts +21 -0
- package/dist/src/tools/built-in/index.d.ts.map +1 -0
- package/dist/src/tools/built-in/index.js +30 -0
- package/dist/src/tools/built-in/index.js.map +1 -0
- package/dist/src/tools/built-in/think.d.ts +7 -0
- package/dist/src/tools/built-in/think.d.ts.map +1 -0
- package/dist/src/tools/built-in/think.js +18 -0
- package/dist/src/tools/built-in/think.js.map +1 -0
- package/dist/src/tools/built-in/web-fetch.d.ts +11 -0
- package/dist/src/tools/built-in/web-fetch.d.ts.map +1 -0
- package/dist/src/tools/built-in/web-fetch.js +70 -0
- package/dist/src/tools/built-in/web-fetch.js.map +1 -0
- package/dist/src/tools/executor.d.ts +25 -0
- package/dist/src/tools/executor.d.ts.map +1 -0
- package/dist/src/tools/executor.js +61 -0
- package/dist/src/tools/executor.js.map +1 -0
- package/dist/src/tools/registry.d.ts +25 -0
- package/dist/src/tools/registry.d.ts.map +1 -0
- package/dist/src/tools/registry.js +135 -0
- package/dist/src/tools/registry.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orchestrator — top-level coordinator for multi-agent workflows.
|
|
3
|
+
*
|
|
4
|
+
* Provides runAgent(), runTeam(), and runTasks() entry points.
|
|
5
|
+
*/
|
|
6
|
+
import { Agent } from './agent.js';
|
|
7
|
+
import { Team } from './team.js';
|
|
8
|
+
import { TaskQueue } from '../communication/task-queue.js';
|
|
9
|
+
import { Semaphore } from '../scheduling/semaphore.js';
|
|
10
|
+
const ZERO_USAGE = { input_tokens: 0, output_tokens: 0 };
|
|
11
|
+
export class Orchestrator {
|
|
12
|
+
adapter;
|
|
13
|
+
toolRegistry;
|
|
14
|
+
config;
|
|
15
|
+
permissionManager;
|
|
16
|
+
cwd;
|
|
17
|
+
activeTeam;
|
|
18
|
+
constructor(adapter, toolRegistry, config = {}, cwd, permissionManager) {
|
|
19
|
+
this.adapter = adapter;
|
|
20
|
+
this.toolRegistry = toolRegistry;
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.cwd = cwd ?? process.cwd();
|
|
23
|
+
this.permissionManager = permissionManager;
|
|
24
|
+
}
|
|
25
|
+
/** Run a single agent on a task. */
|
|
26
|
+
async runAgent(agentConfig, task) {
|
|
27
|
+
const agent = new Agent(agentConfig, this.adapter, this.toolRegistry, this.cwd, this.permissionManager);
|
|
28
|
+
this.emit({ type: 'agent_start', agent: agentConfig.name });
|
|
29
|
+
const result = await agent.run(task);
|
|
30
|
+
this.emit({ type: 'agent_complete', agent: agentConfig.name, data: result });
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/** Run a team on a goal. Returns aggregated results from all agents. */
|
|
34
|
+
async runTeam(teamConfig, goal) {
|
|
35
|
+
const team = new Team(teamConfig, this.adapter, this.toolRegistry, this.cwd, this.permissionManager);
|
|
36
|
+
this.activeTeam = team;
|
|
37
|
+
team.setProgressHandler(event => this.emit(event));
|
|
38
|
+
const result = await team.run(goal);
|
|
39
|
+
this.activeTeam = undefined;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Run a set of tasks with dependency resolution and agent assignment.
|
|
44
|
+
* Uses topological ordering and semaphore-controlled parallelism.
|
|
45
|
+
*/
|
|
46
|
+
async runTasks(tasks, agentConfigs) {
|
|
47
|
+
const queue = new TaskQueue();
|
|
48
|
+
queue.addAll(tasks);
|
|
49
|
+
const semaphore = new Semaphore(this.config.maxConcurrency ?? 2);
|
|
50
|
+
const results = new Map();
|
|
51
|
+
let totalUsage = ZERO_USAGE;
|
|
52
|
+
// Create agents
|
|
53
|
+
const agents = new Map();
|
|
54
|
+
for (const config of agentConfigs) {
|
|
55
|
+
agents.set(config.name, new Agent(config, this.adapter, this.toolRegistry, this.cwd, this.permissionManager));
|
|
56
|
+
}
|
|
57
|
+
// Process tasks in topological order, running independent tasks in parallel
|
|
58
|
+
while (!queue.isFinished()) {
|
|
59
|
+
const ready = queue.getReady();
|
|
60
|
+
if (ready.length === 0) {
|
|
61
|
+
// Check for deadlock
|
|
62
|
+
const summary = queue.summary();
|
|
63
|
+
if (summary.in_progress === 0)
|
|
64
|
+
break; // true deadlock or all done
|
|
65
|
+
// Wait for in-progress tasks
|
|
66
|
+
await new Promise(r => setTimeout(r, 100));
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const batch = ready.map(task => {
|
|
70
|
+
const agentName = task.assignee ?? agentConfigs[0].name;
|
|
71
|
+
const agent = agents.get(agentName) ?? agents.values().next().value;
|
|
72
|
+
queue.start(task.id);
|
|
73
|
+
this.emit({ type: 'task_start', task: task.id, agent: agentName });
|
|
74
|
+
return semaphore.run(async () => {
|
|
75
|
+
try {
|
|
76
|
+
this.emit({ type: 'agent_start', agent: agentName });
|
|
77
|
+
const result = await agent.run(task.description);
|
|
78
|
+
results.set(task.id, result);
|
|
79
|
+
totalUsage = addUsage(totalUsage, result.tokenUsage);
|
|
80
|
+
queue.complete(task.id, result.output.slice(0, 500));
|
|
81
|
+
this.emit({ type: 'task_complete', task: task.id, agent: agentName });
|
|
82
|
+
this.emit({ type: 'agent_complete', agent: agentName });
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
86
|
+
queue.fail(task.id, error);
|
|
87
|
+
this.emit({ type: 'error', task: task.id, agent: agentName, data: error.message });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
await Promise.all(batch);
|
|
92
|
+
}
|
|
93
|
+
return { results, totalUsage };
|
|
94
|
+
}
|
|
95
|
+
/** Get the active team (if any). */
|
|
96
|
+
getActiveTeam() {
|
|
97
|
+
return this.activeTeam;
|
|
98
|
+
}
|
|
99
|
+
/** Get status of the active team. */
|
|
100
|
+
getStatus() {
|
|
101
|
+
if (!this.activeTeam)
|
|
102
|
+
return null;
|
|
103
|
+
return this.activeTeam.getStatus();
|
|
104
|
+
}
|
|
105
|
+
emit(event) {
|
|
106
|
+
this.config.onProgress?.(event);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function addUsage(a, b) {
|
|
110
|
+
return {
|
|
111
|
+
input_tokens: a.input_tokens + b.input_tokens,
|
|
112
|
+
output_tokens: a.output_tokens + b.output_tokens,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../../src/core/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAEtD,MAAM,UAAU,GAAe,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAA;AAEpE,MAAM,OAAO,YAAY;IACN,OAAO,CAAY;IACnB,YAAY,CAAc;IAC1B,MAAM,CAAoB;IAC1B,iBAAiB,CAAoB;IACrC,GAAG,CAAQ;IACpB,UAAU,CAAO;IAEzB,YACE,OAAmB,EACnB,YAA0B,EAC1B,SAA6B,EAAE,EAC/B,GAAY,EACZ,iBAAqC;QAErC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;QAC/B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED,oCAAoC;IACpC,KAAK,CAAC,QAAQ,CAAC,WAAwB,EAAE,IAAY;QACnD,MAAM,KAAK,GAAG,IAAI,KAAK,CACrB,WAAW,EACX,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,YAAY,EACjB,IAA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AK,CAAC,OAAO,EAAE,CAAC,CAAA;oBACpF,CAAC;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YAEF,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA;IAChC,CAAC;IAED,oCAAoC;IACpC,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED,qCAAqC;IACrC,SAAS;QACP,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAA;QACjC,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAA;IACpC,CAAC;IAEO,IAAI,CAAC,KAAwB;QACnC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,CAAa,EAAE,CAAa;IAC5C,OAAO;QACL,YAAY,EAAE,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY;QAC7C,aAAa,EAAE,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa;KACjD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission management — HITL (Human-in-the-Loop) tool approval.
|
|
3
|
+
*
|
|
4
|
+
* Classifies tools by risk level and gates execution on user approval
|
|
5
|
+
* depending on the current permission mode.
|
|
6
|
+
*/
|
|
7
|
+
import type { PermissionMode, ToolRiskLevel, ApprovalCallback } from './types.js';
|
|
8
|
+
export declare function classifyTool(toolName: string): ToolRiskLevel;
|
|
9
|
+
export declare class PermissionManager {
|
|
10
|
+
private mode;
|
|
11
|
+
/** Tools the user has permanently allowed for this session. */
|
|
12
|
+
private sessionAllowed;
|
|
13
|
+
/** Tools persisted in ~/.cmdr/settings.json. */
|
|
14
|
+
private persistedAllowed;
|
|
15
|
+
constructor(mode?: PermissionMode);
|
|
16
|
+
/** Load persisted settings from ~/.cmdr/settings.json. */
|
|
17
|
+
loadSettings(): Promise<void>;
|
|
18
|
+
/** Save current persisted allow-list to disk. */
|
|
19
|
+
private saveSettings;
|
|
20
|
+
getMode(): PermissionMode;
|
|
21
|
+
setMode(mode: PermissionMode): void;
|
|
22
|
+
/**
|
|
23
|
+
* Decide whether a tool call should proceed.
|
|
24
|
+
*
|
|
25
|
+
* Returns true if auto-approved, false if the user must be prompted.
|
|
26
|
+
*/
|
|
27
|
+
needsApproval(toolName: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Gate a tool call. If approval is needed, calls the approvalCallback.
|
|
30
|
+
* Returns the decision (allow/deny). Handles 'allow-always' by recording it.
|
|
31
|
+
*/
|
|
32
|
+
gate(toolName: string, input: Record<string, unknown>, approvalCallback: ApprovalCallback): Promise<'allow' | 'deny'>;
|
|
33
|
+
/** Reset session-allowed set (e.g. on /clear). */
|
|
34
|
+
resetSession(): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../../src/core/permissions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAoB,gBAAgB,EAAE,MAAM,YAAY,CAAA;AA6BnG,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAI5D;AAMD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,IAAI,CAAgB;IAC5B,+DAA+D;IAC/D,OAAO,CAAC,cAAc,CAAoB;IAC1C,gDAAgD;IAChD,OAAO,CAAC,gBAAgB,CAAoB;gBAEhC,IAAI,GAAE,cAAyB;IAI3C,0DAA0D;IACpD,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBnC,iDAAiD;YACnC,YAAY;IAa1B,OAAO,IAAI,cAAc;IAIzB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAMnC;;;;OAIG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAmBxC;;;OAGG;IACG,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;IAkB5B,kDAAkD;IAClD,YAAY,IAAI,IAAI;CAGrB"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission management — HITL (Human-in-the-Loop) tool approval.
|
|
3
|
+
*
|
|
4
|
+
* Classifies tools by risk level and gates execution on user approval
|
|
5
|
+
* depending on the current permission mode.
|
|
6
|
+
*/
|
|
7
|
+
import { readFile, writeFile, mkdir } from 'fs/promises';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { homedir } from 'os';
|
|
10
|
+
const SETTINGS_PATH = join(homedir(), '.cmdr', 'settings.json');
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Tool classification
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
const READ_ONLY_TOOLS = new Set([
|
|
15
|
+
'file_read',
|
|
16
|
+
'glob',
|
|
17
|
+
'grep',
|
|
18
|
+
'git_diff',
|
|
19
|
+
'git_log',
|
|
20
|
+
'think',
|
|
21
|
+
]);
|
|
22
|
+
const DANGEROUS_TOOLS = new Set([
|
|
23
|
+
'bash',
|
|
24
|
+
]);
|
|
25
|
+
export function classifyTool(toolName) {
|
|
26
|
+
if (READ_ONLY_TOOLS.has(toolName))
|
|
27
|
+
return 'read-only';
|
|
28
|
+
if (DANGEROUS_TOOLS.has(toolName))
|
|
29
|
+
return 'dangerous';
|
|
30
|
+
return 'write';
|
|
31
|
+
}
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Permission manager
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
export class PermissionManager {
|
|
36
|
+
mode;
|
|
37
|
+
/** Tools the user has permanently allowed for this session. */
|
|
38
|
+
sessionAllowed = new Set();
|
|
39
|
+
/** Tools persisted in ~/.cmdr/settings.json. */
|
|
40
|
+
persistedAllowed = new Set();
|
|
41
|
+
constructor(mode = 'normal') {
|
|
42
|
+
this.mode = mode;
|
|
43
|
+
}
|
|
44
|
+
/** Load persisted settings from ~/.cmdr/settings.json. */
|
|
45
|
+
async loadSettings() {
|
|
46
|
+
try {
|
|
47
|
+
const data = await readFile(SETTINGS_PATH, 'utf-8');
|
|
48
|
+
const settings = JSON.parse(data);
|
|
49
|
+
if (settings.allowedTools) {
|
|
50
|
+
for (const tool of settings.allowedTools) {
|
|
51
|
+
this.persistedAllowed.add(tool);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (settings.permissionMode) {
|
|
55
|
+
this.mode = settings.permissionMode;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// no settings file yet — that's fine
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Save current persisted allow-list to disk. */
|
|
63
|
+
async saveSettings() {
|
|
64
|
+
try {
|
|
65
|
+
await mkdir(join(homedir(), '.cmdr'), { recursive: true });
|
|
66
|
+
const settings = {
|
|
67
|
+
allowedTools: [...this.persistedAllowed],
|
|
68
|
+
permissionMode: this.mode,
|
|
69
|
+
};
|
|
70
|
+
await writeFile(SETTINGS_PATH, JSON.stringify(settings, null, 2), 'utf-8');
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// best effort
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
getMode() {
|
|
77
|
+
return this.mode;
|
|
78
|
+
}
|
|
79
|
+
setMode(mode) {
|
|
80
|
+
this.mode = mode;
|
|
81
|
+
// Reset session-allowed when mode changes
|
|
82
|
+
this.sessionAllowed.clear();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Decide whether a tool call should proceed.
|
|
86
|
+
*
|
|
87
|
+
* Returns true if auto-approved, false if the user must be prompted.
|
|
88
|
+
*/
|
|
89
|
+
needsApproval(toolName) {
|
|
90
|
+
// Yolo mode — everything auto-approved
|
|
91
|
+
if (this.mode === 'yolo')
|
|
92
|
+
return false;
|
|
93
|
+
// Session-allowed or persisted-allowed tools skip the prompt
|
|
94
|
+
if (this.sessionAllowed.has(toolName))
|
|
95
|
+
return false;
|
|
96
|
+
if (this.persistedAllowed.has(toolName))
|
|
97
|
+
return false;
|
|
98
|
+
const risk = classifyTool(toolName);
|
|
99
|
+
if (this.mode === 'strict') {
|
|
100
|
+
// Strict mode — everything needs approval
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
// Normal mode — only write/dangerous need approval
|
|
104
|
+
return risk !== 'read-only';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Gate a tool call. If approval is needed, calls the approvalCallback.
|
|
108
|
+
* Returns the decision (allow/deny). Handles 'allow-always' by recording it.
|
|
109
|
+
*/
|
|
110
|
+
async gate(toolName, input, approvalCallback) {
|
|
111
|
+
if (!this.needsApproval(toolName)) {
|
|
112
|
+
return 'allow';
|
|
113
|
+
}
|
|
114
|
+
const risk = classifyTool(toolName);
|
|
115
|
+
const decision = await approvalCallback(toolName, input, risk);
|
|
116
|
+
if (decision === 'allow-always') {
|
|
117
|
+
this.sessionAllowed.add(toolName);
|
|
118
|
+
this.persistedAllowed.add(toolName);
|
|
119
|
+
await this.saveSettings();
|
|
120
|
+
return 'allow';
|
|
121
|
+
}
|
|
122
|
+
return decision;
|
|
123
|
+
}
|
|
124
|
+
/** Reset session-allowed set (e.g. on /clear). */
|
|
125
|
+
resetSession() {
|
|
126
|
+
this.sessionAllowed.clear();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","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amConfig } from './types.js';
|
|
5
|
+
export declare const SOLO_CODER: AgentConfig;
|
|
6
|
+
export declare const CODE_REVIEW_TEAM: TeamConfig;
|
|
7
|
+
export declare const FULL_STACK_TEAM: TeamConfig;
|
|
8
|
+
export declare const SECURITY_AUDIT_TEAM: TeamConfig;
|
|
9
|
+
export declare function getPreset(name: string): AgentConfig | undefined;
|
|
10
|
+
export declare function getTeamPreset(name: string): TeamConfig | undefined;
|
|
11
|
+
export declare function listTeamPresets(): string[];
|
|
12
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../../src/core/presets.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAMzD,eAAO,MAAM,UAAU,EAAE,WAuBxB,CAAA;AA8ED,eAAO,MAAM,gBAAgB,EAAE,UAM9B,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,UAM7B,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,UAMjC,CAAA;AAeD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAS/D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAElE;AAED,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAE1C"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-built agent and team presets for common coding tasks.
|
|
3
|
+
*/
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Solo agent presets
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
export const SOLO_CODER = {
|
|
8
|
+
name: 'cmdr',
|
|
9
|
+
systemPrompt: `You are cmdr, an expert coding assistant running in the user's terminal.
|
|
10
|
+
You have direct access to their filesystem and can run shell commands.
|
|
11
|
+
|
|
12
|
+
RULES:
|
|
13
|
+
- For greetings and casual conversation, respond conversationally. Do NOT use any tools.
|
|
14
|
+
- Only use tools when the user asks you to perform a concrete task or explore the codebase.
|
|
15
|
+
- Read files before editing them. Never guess at file contents.
|
|
16
|
+
- Use file_edit for surgical changes, file_write only for new files or full rewrites.
|
|
17
|
+
- Run the code after writing it to verify it works.
|
|
18
|
+
- If a command fails, analyze the error and fix it. Do not give up.
|
|
19
|
+
- Explain what you are doing briefly, then act. Bias toward action over explanation.
|
|
20
|
+
- When asked to implement something, write real, production-quality code.
|
|
21
|
+
- Use grep/glob to explore unfamiliar codebases before making changes.
|
|
22
|
+
- Respect the project's existing patterns, style, and conventions.
|
|
23
|
+
- When showing file changes, be specific about what you changed and why.
|
|
24
|
+
- Keep responses concise. Do not list your capabilities unless the user asks.`,
|
|
25
|
+
tools: [
|
|
26
|
+
'bash', 'file_read', 'file_write', 'file_edit',
|
|
27
|
+
'grep', 'glob', 'git_diff', 'git_log', 'think',
|
|
28
|
+
],
|
|
29
|
+
maxTurns: 30,
|
|
30
|
+
};
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Team presets
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
const CODER_AGENT = {
|
|
35
|
+
name: 'coder',
|
|
36
|
+
systemPrompt: `You are the coder agent in a multi-agent team. Your job is to write and modify code.
|
|
37
|
+
Read files before editing. Use file_edit for surgical changes. Run code after writing it.
|
|
38
|
+
Bias toward action. Write production-quality code. Respect existing patterns.`,
|
|
39
|
+
tools: ['bash', 'file_read', 'file_write', 'file_edit', 'grep', 'glob', 'git_diff', 'think'],
|
|
40
|
+
maxTurns: 20,
|
|
41
|
+
};
|
|
42
|
+
const REVIEWER_AGENT = {
|
|
43
|
+
name: 'reviewer',
|
|
44
|
+
systemPrompt: `You are the reviewer agent. Analyze code changes for:
|
|
45
|
+
- Logic errors and edge cases
|
|
46
|
+
- Security vulnerabilities (injection, auth, data exposure)
|
|
47
|
+
- Performance issues (N+1 queries, unnecessary allocations)
|
|
48
|
+
- Missing error handling
|
|
49
|
+
- Test coverage gaps
|
|
50
|
+
Be specific: cite line numbers, suggest concrete fixes. Read all changed files before reviewing.`,
|
|
51
|
+
tools: ['file_read', 'grep', 'glob', 'git_diff', 'think'],
|
|
52
|
+
maxTurns: 10,
|
|
53
|
+
};
|
|
54
|
+
const PLANNER_AGENT = {
|
|
55
|
+
name: 'planner',
|
|
56
|
+
systemPrompt: `You are the planner agent. Given a high-level goal:
|
|
57
|
+
1. Analyze the codebase structure
|
|
58
|
+
2. Break the goal into specific, ordered subtasks
|
|
59
|
+
3. Identify dependencies between subtasks
|
|
60
|
+
4. Assign each subtask to frontend, backend, or reviewer
|
|
61
|
+
Output a structured task list. Think about: API contracts, data models, component structure, error handling.`,
|
|
62
|
+
tools: ['file_read', 'grep', 'glob', 'think'],
|
|
63
|
+
maxTurns: 5,
|
|
64
|
+
};
|
|
65
|
+
const FRONTEND_AGENT = {
|
|
66
|
+
name: 'frontend',
|
|
67
|
+
systemPrompt: `You are the frontend agent. You specialize in UI/UX code:
|
|
68
|
+
- React, Vue, Angular, Svelte components
|
|
69
|
+
- CSS/Tailwind styling
|
|
70
|
+
- Client-side state management
|
|
71
|
+
- Accessibility and responsive design
|
|
72
|
+
Write clean, component-based code. Follow existing patterns.`,
|
|
73
|
+
tools: ['bash', 'file_read', 'file_write', 'file_edit', 'grep', 'glob', 'think'],
|
|
74
|
+
maxTurns: 20,
|
|
75
|
+
};
|
|
76
|
+
const BACKEND_AGENT = {
|
|
77
|
+
name: 'backend',
|
|
78
|
+
systemPrompt: `You are the backend agent. You specialize in server-side code:
|
|
79
|
+
- API endpoints and routes
|
|
80
|
+
- Database queries and migrations
|
|
81
|
+
- Authentication and authorization
|
|
82
|
+
- Business logic and data validation
|
|
83
|
+
Write robust, well-tested code. Handle errors properly.`,
|
|
84
|
+
tools: ['bash', 'file_read', 'file_write', 'file_edit', 'grep', 'glob', 'think'],
|
|
85
|
+
maxTurns: 20,
|
|
86
|
+
};
|
|
87
|
+
const SECURITY_SCANNER = {
|
|
88
|
+
name: 'scanner',
|
|
89
|
+
systemPrompt: `You are the security scanner. Analyze the codebase for vulnerabilities:
|
|
90
|
+
- OWASP Top 10 issues
|
|
91
|
+
- Hardcoded secrets or credentials
|
|
92
|
+
- Insecure dependencies
|
|
93
|
+
- SQL injection, XSS, CSRF
|
|
94
|
+
- Improper input validation
|
|
95
|
+
- Insecure cryptographic usage
|
|
96
|
+
List findings with severity, location, and remediation steps.`,
|
|
97
|
+
tools: ['file_read', 'grep', 'glob', 'bash', 'think'],
|
|
98
|
+
maxTurns: 15,
|
|
99
|
+
};
|
|
100
|
+
export const CODE_REVIEW_TEAM = {
|
|
101
|
+
name: 'review',
|
|
102
|
+
agents: [CODER_AGENT, REVIEWER_AGENT],
|
|
103
|
+
sharedMemory: true,
|
|
104
|
+
maxConcurrency: 1,
|
|
105
|
+
schedulingStrategy: 'dependency-first',
|
|
106
|
+
};
|
|
107
|
+
export const FULL_STACK_TEAM = {
|
|
108
|
+
name: 'fullstack',
|
|
109
|
+
agents: [PLANNER_AGENT, FRONTEND_AGENT, BACKEND_AGENT, REVIEWER_AGENT],
|
|
110
|
+
sharedMemory: true,
|
|
111
|
+
maxConcurrency: 2,
|
|
112
|
+
schedulingStrategy: 'dependency-first',
|
|
113
|
+
};
|
|
114
|
+
export const SECURITY_AUDIT_TEAM = {
|
|
115
|
+
name: 'security',
|
|
116
|
+
agents: [SECURITY_SCANNER, REVIEWER_AGENT],
|
|
117
|
+
sharedMemory: true,
|
|
118
|
+
maxConcurrency: 1,
|
|
119
|
+
schedulingStrategy: 'dependency-first',
|
|
120
|
+
};
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// Lookup
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
const TEAM_PRESETS = new Map([
|
|
125
|
+
['review', CODE_REVIEW_TEAM],
|
|
126
|
+
['code-review', CODE_REVIEW_TEAM],
|
|
127
|
+
['fullstack', FULL_STACK_TEAM],
|
|
128
|
+
['full-stack', FULL_STACK_TEAM],
|
|
129
|
+
['security', SECURITY_AUDIT_TEAM],
|
|
130
|
+
['security-audit', SECURITY_AUDIT_TEAM],
|
|
131
|
+
]);
|
|
132
|
+
export function getPreset(name) {
|
|
133
|
+
switch (name) {
|
|
134
|
+
case 'solo':
|
|
135
|
+
case 'coder':
|
|
136
|
+
case 'default':
|
|
137
|
+
return SOLO_CODER;
|
|
138
|
+
default:
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function getTeamPreset(name) {
|
|
143
|
+
return TEAM_PRESETS.get(name);
|
|
144
|
+
}
|
|
145
|
+
export function listTeamPresets() {
|
|
146
|
+
return ['review', 'fullstack', 'security'];
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../../../src/core/presets.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAM,CAAC,MAAM,UAAU,GAAgB;IACrC,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE;;;;;;;;;;;;;;;8EAe8D;IAC5E,KAAK,EAAE;QACL,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW;QAC9C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO;KAC/C;IACD,QAAQ,EAAE,EAAE;CACb,CAAA;AAED,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,MAAM,WAAW,GAAgB;IAC/B,IAAI,EAAE,OAAO;IACb,YAAY,EAAE;;8EAE8D;IAC5E,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC;IAC5F,QAAQ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
|
|
1
|
+
/**
|
|
2
|
+
* Team — multi-agent collaboration unit.
|
|
3
|
+
*
|
|
4
|
+
* A team owns agents, a shared memory, a message bus, and a task queue.
|
|
5
|
+
* The Orchestrator uses teams to decompose and execute complex goals.
|
|
6
|
+
*/
|
|
7
|
+
import type { TeamConfig, TeamRunResult, LLMAdapter, OrchestratorEvent } from './types.js';
|
|
8
|
+
import type { ToolRegistry } from '../tools/registry.js';
|
|
9
|
+
import type { PermissionManager } from './permissions.js';
|
|
10
|
+
import { AgentPool } from './agent-pool.js';
|
|
11
|
+
import { MessageBus } from '../communication/message-bus.js';
|
|
12
|
+
import { SharedMemory } from '../communication/shared-memory.js';
|
|
13
|
+
import { TaskQueue } from '../communication/task-queue.js';
|
|
14
|
+
export declare class Team {
|
|
15
|
+
readonly config: TeamConfig;
|
|
16
|
+
readonly messageBus: MessageBus;
|
|
17
|
+
readonly sharedMemory: SharedMemory;
|
|
18
|
+
readonly taskQueue: TaskQueue;
|
|
19
|
+
private readonly pool;
|
|
20
|
+
private taskCounter;
|
|
21
|
+
private onProgress?;
|
|
22
|
+
constructor(config: TeamConfig, adapter: LLMAdapter, toolRegistry: ToolRegistry, cwd?: string, permissionManager?: PermissionManager);
|
|
23
|
+
/** Set a progress callback for orchestration events. */
|
|
24
|
+
setProgressHandler(handler: (event: OrchestratorEvent) => void): void;
|
|
25
|
+
/**
|
|
26
|
+
* Run a goal by decomposing it into tasks and assigning to agents.
|
|
27
|
+
* The first agent in the config is the "planner" that decomposes the goal.
|
|
28
|
+
*/
|
|
29
|
+
run(goal: string): Promise<TeamRunResult>;
|
|
30
|
+
/** Select the best agent for a task using the configured strategy. */
|
|
31
|
+
private selectAgent;
|
|
32
|
+
private emit;
|
|
33
|
+
/** Get the agent pool for direct access. */
|
|
34
|
+
getPool(): AgentPool;
|
|
35
|
+
/** Get status of all agents and tasks. */
|
|
36
|
+
getStatus(): {
|
|
37
|
+
agents: Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
status: string;
|
|
40
|
+
}>;
|
|
41
|
+
tasks: ReturnType<TaskQueue['summary']>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=team.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"team.d.ts","sourceRoot":"","sources":["../../../src/core/team.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EAAE,aAAa,EACzB,UAAU,EAAoB,iBAAiB,EAChD,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAK1D,qBAAa,IAAI;IACf,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;IAC/B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAW;IAChC,OAAO,CAAC,WAAW,CAAI;IACvB,OAAO,CAAC,UAAU,CAAC,CAAoC;gBAGrD,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,EACnB,YAAY,EAAE,YAAY,EAC1B,GAAG,CAAC,EAAE,MAAM,EACZ,iBAAiB,CAAC,EAAE,iBAAiB;IAiBvC,wDAAwD;IACxD,kBAAkB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAAG,IAAI;IAIrE;;;OAGG;IACG,GAAG,CAAC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