@polka-codes/cli 0.10.23 → 0.10.25
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/bin.cjs +143854 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9201 -9195
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/package.json +6 -7
- package/cli.mjs +0 -2
- package/dist/ApiProviderConfig.js +0 -57
- package/dist/ApiProviderConfig.js.map +0 -1
- package/dist/ApiProviderConfig.test.js +0 -278
- package/dist/ApiProviderConfig.test.js.map +0 -1
- package/dist/agent/advanced-discovery.js +0 -604
- package/dist/agent/advanced-discovery.js.map +0 -1
- package/dist/agent/config.js +0 -139
- package/dist/agent/config.js.map +0 -1
- package/dist/agent/config.test.js +0 -140
- package/dist/agent/config.test.js.map +0 -1
- package/dist/agent/constants.js +0 -172
- package/dist/agent/constants.js.map +0 -1
- package/dist/agent/constants.test.js +0 -132
- package/dist/agent/constants.test.js.map +0 -1
- package/dist/agent/debug-logger.js +0 -281
- package/dist/agent/debug-logger.js.map +0 -1
- package/dist/agent/debug-logger.test.js +0 -294
- package/dist/agent/debug-logger.test.js.map +0 -1
- package/dist/agent/error-handling.js +0 -114
- package/dist/agent/error-handling.js.map +0 -1
- package/dist/agent/error-handling.test.js +0 -191
- package/dist/agent/error-handling.test.js.map +0 -1
- package/dist/agent/errors.js +0 -301
- package/dist/agent/errors.js.map +0 -1
- package/dist/agent/executor.js +0 -206
- package/dist/agent/executor.js.map +0 -1
- package/dist/agent/executor.test.js +0 -228
- package/dist/agent/executor.test.js.map +0 -1
- package/dist/agent/goal-decomposer.js +0 -281
- package/dist/agent/goal-decomposer.js.map +0 -1
- package/dist/agent/goal-decomposer.test.js +0 -225
- package/dist/agent/goal-decomposer.test.js.map +0 -1
- package/dist/agent/health-monitor.js +0 -89
- package/dist/agent/health-monitor.js.map +0 -1
- package/dist/agent/improvement-loop.js +0 -177
- package/dist/agent/improvement-loop.js.map +0 -1
- package/dist/agent/index.js +0 -38
- package/dist/agent/index.js.map +0 -1
- package/dist/agent/metrics.js +0 -158
- package/dist/agent/metrics.js.map +0 -1
- package/dist/agent/metrics.test.js +0 -311
- package/dist/agent/metrics.test.js.map +0 -1
- package/dist/agent/orchestrator.js +0 -438
- package/dist/agent/orchestrator.js.map +0 -1
- package/dist/agent/planner.js +0 -199
- package/dist/agent/planner.js.map +0 -1
- package/dist/agent/planner.test.js +0 -135
- package/dist/agent/planner.test.js.map +0 -1
- package/dist/agent/progress.js +0 -298
- package/dist/agent/progress.js.map +0 -1
- package/dist/agent/progress.test.js +0 -255
- package/dist/agent/progress.test.js.map +0 -1
- package/dist/agent/resource-monitor.js +0 -114
- package/dist/agent/resource-monitor.js.map +0 -1
- package/dist/agent/safety/approval.js +0 -178
- package/dist/agent/safety/approval.js.map +0 -1
- package/dist/agent/safety/approval.test.js +0 -142
- package/dist/agent/safety/approval.test.js.map +0 -1
- package/dist/agent/safety/checks.js +0 -152
- package/dist/agent/safety/checks.js.map +0 -1
- package/dist/agent/safety/checks.test.js +0 -89
- package/dist/agent/safety/checks.test.js.map +0 -1
- package/dist/agent/safety/interrupt.js +0 -92
- package/dist/agent/safety/interrupt.js.map +0 -1
- package/dist/agent/safety/interrupt.test.js +0 -53
- package/dist/agent/safety/interrupt.test.js.map +0 -1
- package/dist/agent/session.js +0 -117
- package/dist/agent/session.js.map +0 -1
- package/dist/agent/session.test.js +0 -213
- package/dist/agent/session.test.js.map +0 -1
- package/dist/agent/state-manager.js +0 -287
- package/dist/agent/state-manager.js.map +0 -1
- package/dist/agent/task-discovery.js +0 -433
- package/dist/agent/task-discovery.js.map +0 -1
- package/dist/agent/task-discovery.test.js +0 -40
- package/dist/agent/task-discovery.test.js.map +0 -1
- package/dist/agent/task-history.js +0 -128
- package/dist/agent/task-history.js.map +0 -1
- package/dist/agent/task-prioritizer.js +0 -286
- package/dist/agent/task-prioritizer.js.map +0 -1
- package/dist/agent/test-fixtures.js +0 -112
- package/dist/agent/test-fixtures.js.map +0 -1
- package/dist/agent/types.js +0 -15
- package/dist/agent/types.js.map +0 -1
- package/dist/agent/workflow-adapter.js +0 -219
- package/dist/agent/workflow-adapter.js.map +0 -1
- package/dist/agent/workflow-adapter.test.js +0 -11
- package/dist/agent/workflow-adapter.test.js.map +0 -1
- package/dist/agent/working-dir-discovery.js +0 -54
- package/dist/agent/working-dir-discovery.js.map +0 -1
- package/dist/agent/working-space.js +0 -484
- package/dist/agent/working-space.js.map +0 -1
- package/dist/agent/working-space.test.js +0 -436
- package/dist/agent/working-space.test.js.map +0 -1
- package/dist/api.js +0 -279
- package/dist/api.js.map +0 -1
- package/dist/builtin-commands.js +0 -20
- package/dist/builtin-commands.js.map +0 -1
- package/dist/commandSummarizer.js +0 -96
- package/dist/commandSummarizer.js.map +0 -1
- package/dist/commands/__tests__/command-detection.integration.test.js +0 -238
- package/dist/commands/__tests__/command-detection.integration.test.js.map +0 -1
- package/dist/commands/__tests__/script-generator.integration.test.js +0 -271
- package/dist/commands/__tests__/script-generator.integration.test.js.map +0 -1
- package/dist/commands/agent.js +0 -218
- package/dist/commands/agent.js.map +0 -1
- package/dist/commands/code.js +0 -102
- package/dist/commands/code.js.map +0 -1
- package/dist/commands/command.constants.js +0 -13
- package/dist/commands/command.constants.js.map +0 -1
- package/dist/commands/commit.js +0 -17
- package/dist/commands/commit.js.map +0 -1
- package/dist/commands/fix.js +0 -17
- package/dist/commands/fix.js.map +0 -1
- package/dist/commands/init.js +0 -501
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/mcp-server.js +0 -122
- package/dist/commands/mcp-server.js.map +0 -1
- package/dist/commands/memory.js +0 -410
- package/dist/commands/memory.js.map +0 -1
- package/dist/commands/memory.test.js +0 -453
- package/dist/commands/memory.test.js.map +0 -1
- package/dist/commands/meta.js +0 -142
- package/dist/commands/meta.js.map +0 -1
- package/dist/commands/plan.js +0 -39
- package/dist/commands/plan.js.map +0 -1
- package/dist/commands/pr.js +0 -14
- package/dist/commands/pr.js.map +0 -1
- package/dist/commands/review-json.test.js +0 -33
- package/dist/commands/review-json.test.js.map +0 -1
- package/dist/commands/review.js +0 -137
- package/dist/commands/review.js.map +0 -1
- package/dist/commands/review.usage.test.js +0 -41
- package/dist/commands/review.usage.test.js.map +0 -1
- package/dist/commands/run.js +0 -107
- package/dist/commands/run.js.map +0 -1
- package/dist/commands/skills.js +0 -175
- package/dist/commands/skills.js.map +0 -1
- package/dist/commands/task.js +0 -34
- package/dist/commands/task.js.map +0 -1
- package/dist/commands/workflow.js +0 -117
- package/dist/commands/workflow.js.map +0 -1
- package/dist/configPrompt.js +0 -39
- package/dist/configPrompt.js.map +0 -1
- package/dist/env.js +0 -22
- package/dist/env.js.map +0 -1
- package/dist/errors.js +0 -132
- package/dist/errors.js.map +0 -1
- package/dist/errors.test.js +0 -21
- package/dist/errors.test.js.map +0 -1
- package/dist/file-attachments.js +0 -77
- package/dist/file-attachments.js.map +0 -1
- package/dist/file-attachments.test.js +0 -214
- package/dist/file-attachments.test.js.map +0 -1
- package/dist/getModel.js +0 -229
- package/dist/getModel.js.map +0 -1
- package/dist/getModel.test.js +0 -67
- package/dist/getModel.test.js.map +0 -1
- package/dist/getProviderOptions.js +0 -58
- package/dist/getProviderOptions.js.map +0 -1
- package/dist/git-operations.js +0 -363
- package/dist/git-operations.js.map +0 -1
- package/dist/git-operations.test.js +0 -81
- package/dist/git-operations.test.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -41
- package/dist/logger.js.map +0 -1
- package/dist/mcp/client.js +0 -11
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/error-scenarios.test.js +0 -206
- package/dist/mcp/error-scenarios.test.js.map +0 -1
- package/dist/mcp/errors.js +0 -63
- package/dist/mcp/errors.js.map +0 -1
- package/dist/mcp/index.js +0 -9
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/manager.js +0 -231
- package/dist/mcp/manager.js.map +0 -1
- package/dist/mcp/manager.test.js +0 -40
- package/dist/mcp/manager.test.js.map +0 -1
- package/dist/mcp/sdk-client.js +0 -166
- package/dist/mcp/sdk-client.js.map +0 -1
- package/dist/mcp/shared-types.js +0 -3
- package/dist/mcp/shared-types.js.map +0 -1
- package/dist/mcp/tools-integration.test.js +0 -198
- package/dist/mcp/tools-integration.test.js.map +0 -1
- package/dist/mcp/tools.js +0 -60
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/transport.js +0 -257
- package/dist/mcp/transport.js.map +0 -1
- package/dist/mcp/types.js +0 -3
- package/dist/mcp/types.js.map +0 -1
- package/dist/mcp-server/index.js +0 -5
- package/dist/mcp-server/index.js.map +0 -1
- package/dist/mcp-server/plan-formatting.test.js +0 -74
- package/dist/mcp-server/plan-formatting.test.js.map +0 -1
- package/dist/mcp-server/sdk-server.js +0 -102
- package/dist/mcp-server/sdk-server.js.map +0 -1
- package/dist/mcp-server/sdk-server.test.js +0 -363
- package/dist/mcp-server/sdk-server.test.js.map +0 -1
- package/dist/mcp-server/tools.js +0 -785
- package/dist/mcp-server/tools.js.map +0 -1
- package/dist/mcp-server/types.js +0 -3
- package/dist/mcp-server/types.js.map +0 -1
- package/dist/options.js +0 -85
- package/dist/options.js.map +0 -1
- package/dist/options.test.js +0 -177
- package/dist/options.test.js.map +0 -1
- package/dist/prices.js +0 -61
- package/dist/prices.js.map +0 -1
- package/dist/prices.test.js +0 -148
- package/dist/prices.test.js.map +0 -1
- package/dist/runWorkflow.js +0 -313
- package/dist/runWorkflow.js.map +0 -1
- package/dist/script/__tests__/execution.integration.test.js +0 -274
- package/dist/script/__tests__/execution.integration.test.js.map +0 -1
- package/dist/script/__tests__/runner.test.js +0 -176
- package/dist/script/__tests__/runner.test.js.map +0 -1
- package/dist/script/__tests__/validator.test.js +0 -180
- package/dist/script/__tests__/validator.test.js.map +0 -1
- package/dist/script/executor.js +0 -127
- package/dist/script/executor.js.map +0 -1
- package/dist/script/index.js +0 -4
- package/dist/script/index.js.map +0 -1
- package/dist/script/runner.js +0 -258
- package/dist/script/runner.js.map +0 -1
- package/dist/skillIntegration.js +0 -46
- package/dist/skillIntegration.js.map +0 -1
- package/dist/skillIntegration.test.js +0 -128
- package/dist/skillIntegration.test.js.map +0 -1
- package/dist/test/utils.js +0 -200
- package/dist/test/utils.js.map +0 -1
- package/dist/test/workflow-fixtures.js +0 -120
- package/dist/test/workflow-fixtures.js.map +0 -1
- package/dist/tool-implementations.js +0 -521
- package/dist/tool-implementations.js.map +0 -1
- package/dist/tool-implementations.skill-tools.test.js +0 -106
- package/dist/tool-implementations.skill-tools.test.js.map +0 -1
- package/dist/tools/getTodoItem.js +0 -33
- package/dist/tools/getTodoItem.js.map +0 -1
- package/dist/tools/gitDiff.js +0 -108
- package/dist/tools/gitDiff.js.map +0 -1
- package/dist/tools/index.js +0 -8
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/listMemoryTopics.js +0 -24
- package/dist/tools/listMemoryTopics.js.map +0 -1
- package/dist/tools/listTodoItems.js +0 -35
- package/dist/tools/listTodoItems.js.map +0 -1
- package/dist/tools/listTodoItems.test.js +0 -89
- package/dist/tools/listTodoItems.test.js.map +0 -1
- package/dist/tools/readMemory.js +0 -33
- package/dist/tools/readMemory.js.map +0 -1
- package/dist/tools/updateMemory.js +0 -62
- package/dist/tools/updateMemory.js.map +0 -1
- package/dist/tools/updateMemory.test.js +0 -109
- package/dist/tools/updateMemory.test.js.map +0 -1
- package/dist/tools/updateTodoItem.js +0 -31
- package/dist/tools/updateTodoItem.js.map +0 -1
- package/dist/tools/utils/diffLineNumbers.js +0 -178
- package/dist/tools/utils/diffLineNumbers.js.map +0 -1
- package/dist/utils/cacheControl.js +0 -59
- package/dist/utils/cacheControl.js.map +0 -1
- package/dist/utils/cacheControl.test.js +0 -128
- package/dist/utils/cacheControl.test.js.map +0 -1
- package/dist/utils/command.js +0 -50
- package/dist/utils/command.js.map +0 -1
- package/dist/utils/shell.js +0 -56
- package/dist/utils/shell.js.map +0 -1
- package/dist/utils/userInput.js +0 -47
- package/dist/utils/userInput.js.map +0 -1
- package/dist/workflow-tools.js +0 -21
- package/dist/workflow-tools.js.map +0 -1
- package/dist/workflows/agent-builder.js +0 -90
- package/dist/workflows/agent-builder.js.map +0 -1
- package/dist/workflows/agent-builder.test.js +0 -115
- package/dist/workflows/agent-builder.test.js.map +0 -1
- package/dist/workflows/code.workflow.js +0 -145
- package/dist/workflows/code.workflow.js.map +0 -1
- package/dist/workflows/commit.workflow.js +0 -111
- package/dist/workflows/commit.workflow.js.map +0 -1
- package/dist/workflows/commit.workflow.test.js +0 -141
- package/dist/workflows/commit.workflow.test.js.map +0 -1
- package/dist/workflows/fix.workflow.js +0 -172
- package/dist/workflows/fix.workflow.js.map +0 -1
- package/dist/workflows/fix.workflow.test.js +0 -137
- package/dist/workflows/fix.workflow.test.js.map +0 -1
- package/dist/workflows/git-file-tools.js +0 -408
- package/dist/workflows/git-file-tools.js.map +0 -1
- package/dist/workflows/index.js +0 -12
- package/dist/workflows/index.js.map +0 -1
- package/dist/workflows/init-interactive.workflow.js +0 -198
- package/dist/workflows/init-interactive.workflow.js.map +0 -1
- package/dist/workflows/init.workflow.js +0 -41
- package/dist/workflows/init.workflow.js.map +0 -1
- package/dist/workflows/meta.workflow.js +0 -107
- package/dist/workflows/meta.workflow.js.map +0 -1
- package/dist/workflows/plan.workflow.js +0 -275
- package/dist/workflows/plan.workflow.js.map +0 -1
- package/dist/workflows/plan.workflow.test.js +0 -419
- package/dist/workflows/plan.workflow.test.js.map +0 -1
- package/dist/workflows/pr.workflow.js +0 -54
- package/dist/workflows/pr.workflow.js.map +0 -1
- package/dist/workflows/pr.workflow.test.js +0 -98
- package/dist/workflows/pr.workflow.test.js.map +0 -1
- package/dist/workflows/prompts/coder.js +0 -85
- package/dist/workflows/prompts/coder.js.map +0 -1
- package/dist/workflows/prompts/commit.js +0 -16
- package/dist/workflows/prompts/commit.js.map +0 -1
- package/dist/workflows/prompts/fix.js +0 -44
- package/dist/workflows/prompts/fix.js.map +0 -1
- package/dist/workflows/prompts/index.js +0 -10
- package/dist/workflows/prompts/index.js.map +0 -1
- package/dist/workflows/prompts/init.js +0 -48
- package/dist/workflows/prompts/init.js.map +0 -1
- package/dist/workflows/prompts/meta.js +0 -17
- package/dist/workflows/prompts/meta.js.map +0 -1
- package/dist/workflows/prompts/plan.js +0 -212
- package/dist/workflows/prompts/plan.js.map +0 -1
- package/dist/workflows/prompts/pr.js +0 -15
- package/dist/workflows/prompts/pr.js.map +0 -1
- package/dist/workflows/prompts/review.js +0 -145
- package/dist/workflows/prompts/review.js.map +0 -1
- package/dist/workflows/prompts/shared.js +0 -93
- package/dist/workflows/prompts/shared.js.map +0 -1
- package/dist/workflows/review.workflow.js +0 -357
- package/dist/workflows/review.workflow.js.map +0 -1
- package/dist/workflows/task.workflow.js +0 -47
- package/dist/workflows/task.workflow.js.map +0 -1
- package/dist/workflows/testing/helper.js +0 -41
- package/dist/workflows/testing/helper.js.map +0 -1
- package/dist/workflows/workflow.utils.js +0 -351
- package/dist/workflows/workflow.utils.js.map +0 -1
- package/dist/workflows/workflow.utils.test.js +0 -45
- package/dist/workflows/workflow.utils.test.js.map +0 -1
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
import { ulid } from 'ulid';
|
|
3
|
-
import { AgentStatusError, SafetyViolationError } from './errors';
|
|
4
|
-
import { TaskExecutor } from './executor';
|
|
5
|
-
import { GoalDecomposer } from './goal-decomposer';
|
|
6
|
-
import { createContinuousImprovementLoop } from './improvement-loop';
|
|
7
|
-
import { MetricsCollector } from './metrics';
|
|
8
|
-
import { createTaskPlanner } from './planner';
|
|
9
|
-
import { ApprovalManager } from './safety/approval';
|
|
10
|
-
import { SafetyChecker } from './safety/checks';
|
|
11
|
-
import { InterruptHandler } from './safety/interrupt';
|
|
12
|
-
import { acquire, release } from './session';
|
|
13
|
-
import { AgentStateManager } from './state-manager';
|
|
14
|
-
import { TaskHistory } from './task-history';
|
|
15
|
-
import { WorkingSpace } from './working-space';
|
|
16
|
-
/**
|
|
17
|
-
* Main autonomous agent orchestrator
|
|
18
|
-
*
|
|
19
|
-
* Coordinates all agent components to:
|
|
20
|
-
* - Accept high-level goals
|
|
21
|
-
* - Decompose into executable tasks
|
|
22
|
-
* - Execute tasks safely with approvals
|
|
23
|
-
* - Manage state
|
|
24
|
-
* - Handle continuous improvement mode
|
|
25
|
-
* - Manage working directory for plans and tasks
|
|
26
|
-
*
|
|
27
|
-
* Two modes:
|
|
28
|
-
* - Goal-directed: User provides a goal to achieve
|
|
29
|
-
* - Continuous: Auto-discovers and fixes issues
|
|
30
|
-
*
|
|
31
|
-
* Optional working directory mode:
|
|
32
|
-
* - Uses a user-specified directory for plans and task documentation
|
|
33
|
-
* - Discovers tasks from working directory
|
|
34
|
-
* - Documents completed tasks in working directory
|
|
35
|
-
*/
|
|
36
|
-
export class AutonomousAgent {
|
|
37
|
-
#stateManager;
|
|
38
|
-
#taskHistory;
|
|
39
|
-
#logger;
|
|
40
|
-
#metrics;
|
|
41
|
-
#approvalManager;
|
|
42
|
-
#safetyChecker;
|
|
43
|
-
#interruptHandler;
|
|
44
|
-
#goalDecomposer;
|
|
45
|
-
#taskPlanner;
|
|
46
|
-
#taskExecutor;
|
|
47
|
-
#improvementLoop;
|
|
48
|
-
#workingSpace;
|
|
49
|
-
#initialized = false;
|
|
50
|
-
#sessionId;
|
|
51
|
-
#config;
|
|
52
|
-
#context;
|
|
53
|
-
constructor(config, context) {
|
|
54
|
-
this.#config = config;
|
|
55
|
-
this.#context = context;
|
|
56
|
-
this.#sessionId = this.generateSessionId();
|
|
57
|
-
// Determine state directory
|
|
58
|
-
const stateDir = config.stateDir || path.join(process.cwd(), '.polka', 'agent-state');
|
|
59
|
-
// Initialize all components with correct constructor arguments
|
|
60
|
-
this.#stateManager = new AgentStateManager(stateDir, this.#sessionId);
|
|
61
|
-
this.#taskHistory = new TaskHistory(stateDir);
|
|
62
|
-
this.#logger = context.logger;
|
|
63
|
-
this.#metrics = new MetricsCollector();
|
|
64
|
-
this.#approvalManager = new ApprovalManager(this.#logger, config.approval.level, config.approval.autoApproveSafeTasks, config.approval.maxAutoApprovalCost, config.destructiveOperations);
|
|
65
|
-
this.#safetyChecker = new SafetyChecker(this.#logger, context.tools);
|
|
66
|
-
this.#interruptHandler = new InterruptHandler(this.#logger, this);
|
|
67
|
-
this.#goalDecomposer = new GoalDecomposer(context);
|
|
68
|
-
this.#taskPlanner = createTaskPlanner(context);
|
|
69
|
-
this.#taskExecutor = new TaskExecutor(context, context.logger);
|
|
70
|
-
// Initialize working space if configured
|
|
71
|
-
if (config.workingDir) {
|
|
72
|
-
this.#workingSpace = new WorkingSpace(config.workingDir, context.logger);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Initialize agent (acquire session, start monitors)
|
|
77
|
-
*/
|
|
78
|
-
async initialize() {
|
|
79
|
-
if (this.#initialized) {
|
|
80
|
-
throw new AgentStatusError('Agent already initialized');
|
|
81
|
-
}
|
|
82
|
-
this.#logger.info('='.repeat(60));
|
|
83
|
-
this.#logger.info('🤖 Polka Codes Autonomous Agent');
|
|
84
|
-
this.#logger.info('='.repeat(60));
|
|
85
|
-
this.#logger.info('');
|
|
86
|
-
try {
|
|
87
|
-
// 1. Acquire session
|
|
88
|
-
this.#logger.info(`[Init] Acquiring session: ${this.#sessionId}`);
|
|
89
|
-
const acquireResult = await acquire(this.#sessionId);
|
|
90
|
-
if (!acquireResult.acquired) {
|
|
91
|
-
throw new AgentStatusError(`Session conflict: ${this.#sessionId} - ${acquireResult.reason}`);
|
|
92
|
-
}
|
|
93
|
-
this.#logger.info('[Init] ✅ Session acquired');
|
|
94
|
-
// 2. Initialize state
|
|
95
|
-
this.#logger.info('[Init] Initializing state...');
|
|
96
|
-
const initialState = await this.#stateManager.initialize(this.#config);
|
|
97
|
-
this.#logger.info(`[Init] ✅ State initialized: ${initialState.currentMode}`);
|
|
98
|
-
// 3. Initialize working space if configured
|
|
99
|
-
if (this.#workingSpace) {
|
|
100
|
-
this.#logger.info('[Init] Initializing working space...');
|
|
101
|
-
await this.#workingSpace.initialize();
|
|
102
|
-
this.#logger.info(`[Init] ✅ Working space ready: ${this.#config.workingDir}`);
|
|
103
|
-
const stats = await this.#workingSpace.getStats();
|
|
104
|
-
this.#logger.info(`[Init] Working space stats: ${stats.planCount} plans, ${stats.pendingTaskCount} pending tasks, ${stats.completedTaskCount} completed tasks`);
|
|
105
|
-
}
|
|
106
|
-
// 4. Log configuration
|
|
107
|
-
this.#logger.info('[Init] Configuration:');
|
|
108
|
-
this.#logger.info(` - Strategy: ${this.#config.strategy}`);
|
|
109
|
-
this.#logger.info(` - Approval level: ${this.#config.approval.level}`);
|
|
110
|
-
if (this.#config.workingDir) {
|
|
111
|
-
this.#logger.info(` - Working directory: ${this.#config.workingDir}`);
|
|
112
|
-
}
|
|
113
|
-
this.#logger.info('');
|
|
114
|
-
this.#initialized = true;
|
|
115
|
-
this.#logger.info('✅ Agent initialized successfully');
|
|
116
|
-
this.#logger.info('');
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
this.#logger.error('[Init] Initialization failed', error);
|
|
120
|
-
// Cleanup on failure
|
|
121
|
-
await this.cleanup();
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Set goal for goal-directed mode
|
|
127
|
-
*/
|
|
128
|
-
async setGoal(goal) {
|
|
129
|
-
if (!this.#initialized) {
|
|
130
|
-
throw new AgentStatusError('Agent not initialized');
|
|
131
|
-
}
|
|
132
|
-
const state = await this.#stateManager.getState();
|
|
133
|
-
if (!state) {
|
|
134
|
-
throw new AgentStatusError('State is null');
|
|
135
|
-
}
|
|
136
|
-
if (state.currentMode !== 'idle') {
|
|
137
|
-
throw new AgentStatusError(`Cannot set goal while agent is ${state.currentMode}`);
|
|
138
|
-
}
|
|
139
|
-
this.#logger.info(`[Goal] Setting goal: ${goal}`);
|
|
140
|
-
await this.#stateManager.updateState({
|
|
141
|
-
currentGoal: goal,
|
|
142
|
-
currentMode: 'planning',
|
|
143
|
-
});
|
|
144
|
-
this.#logger.info('[Goal] ✅ Goal set');
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Run agent (goal-directed mode)
|
|
148
|
-
*/
|
|
149
|
-
async run() {
|
|
150
|
-
if (!this.#initialized) {
|
|
151
|
-
throw new AgentStatusError('Agent not initialized');
|
|
152
|
-
}
|
|
153
|
-
const state = await this.#stateManager.getState();
|
|
154
|
-
if (!state) {
|
|
155
|
-
throw new AgentStatusError('State is null');
|
|
156
|
-
}
|
|
157
|
-
if (!state.currentGoal) {
|
|
158
|
-
throw new AgentStatusError('No goal set');
|
|
159
|
-
}
|
|
160
|
-
this.#logger.info('');
|
|
161
|
-
this.#logger.info('🚀 Starting execution...');
|
|
162
|
-
this.#logger.info('');
|
|
163
|
-
try {
|
|
164
|
-
// 1. Goal decomposition
|
|
165
|
-
this.#logger.info('[Run] Phase 1: Decomposing goal...');
|
|
166
|
-
const decomposition = await this.#goalDecomposer.decompose(state.currentGoal);
|
|
167
|
-
this.#logger.info(`[Run] ✅ Generated ${decomposition.tasks.length} task(s)`);
|
|
168
|
-
// Log the high-level plan
|
|
169
|
-
if (decomposition.highLevelPlan) {
|
|
170
|
-
this.#logger.info('[Run] High-level plan:');
|
|
171
|
-
this.#logger.info(decomposition.highLevelPlan);
|
|
172
|
-
}
|
|
173
|
-
// 2. Safety check
|
|
174
|
-
this.#logger.info('[Run] Phase 2: Checking safety...');
|
|
175
|
-
const safetyResult = await this.#safetyChecker.checkTasks(decomposition.tasks);
|
|
176
|
-
if (!safetyResult.safe) {
|
|
177
|
-
const violations = safetyResult.failed.map((f) => f.message).join(', ');
|
|
178
|
-
throw new SafetyViolationError(`Safety check failed: ${violations}`);
|
|
179
|
-
}
|
|
180
|
-
this.#logger.info('[Run] ✅ Safety checks passed');
|
|
181
|
-
// 3. Create plan
|
|
182
|
-
this.#logger.info('[Run] Phase 3: Creating execution plan...');
|
|
183
|
-
const plan = this.#taskPlanner.createPlan(state.currentGoal, decomposition.tasks);
|
|
184
|
-
this.#logger.info(`[Run] ✅ Plan created: ${plan.executionOrder.length} phase(s)`);
|
|
185
|
-
this.#logger.info(`[Run] Estimated time: ${plan.estimatedTime}min`);
|
|
186
|
-
if (plan.risks.length > 0) {
|
|
187
|
-
this.#logger.warn(`[Run] ⚠️ Risks identified:`);
|
|
188
|
-
for (const risk of plan.risks) {
|
|
189
|
-
this.#logger.warn(` - ${risk}`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// 4. Request approval
|
|
193
|
-
this.#logger.info('[Run] Phase 4: Requesting approval...');
|
|
194
|
-
// Generate a unique plan ID using ULID
|
|
195
|
-
const planId = `plan-${ulid()}`;
|
|
196
|
-
// Create plan approval request
|
|
197
|
-
const approvalRequest = {
|
|
198
|
-
planId,
|
|
199
|
-
goal: state.currentGoal,
|
|
200
|
-
tasks: plan.tasks,
|
|
201
|
-
estimatedTime: plan.estimatedTime,
|
|
202
|
-
risks: plan.risks,
|
|
203
|
-
executionOrder: plan.executionOrder,
|
|
204
|
-
};
|
|
205
|
-
// Request approval from user
|
|
206
|
-
const decision = await this.#approvalManager.requestPlanApproval(approvalRequest);
|
|
207
|
-
if (!decision.approved) {
|
|
208
|
-
this.#logger.info(`[Run] ❌ Plan not approved: ${decision.reason || 'No reason provided'}`);
|
|
209
|
-
await this.#stateManager.updateState({ currentMode: 'idle' });
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
this.#logger.info('[Run] ✅ Plan approved');
|
|
213
|
-
// 5. Save plan to working space if configured
|
|
214
|
-
if (this.#workingSpace) {
|
|
215
|
-
this.#logger.info('[Run] Saving plan to working space...');
|
|
216
|
-
await this.#workingSpace.savePlan(plan);
|
|
217
|
-
}
|
|
218
|
-
// 6. Execute plan
|
|
219
|
-
this.#logger.info('[Run] Phase 6: Executing plan...');
|
|
220
|
-
this.#logger.info('');
|
|
221
|
-
await this.executePlan(plan);
|
|
222
|
-
// 6. Complete
|
|
223
|
-
this.#logger.info('');
|
|
224
|
-
this.#logger.info('✅ Execution complete');
|
|
225
|
-
this.#logger.info('');
|
|
226
|
-
await this.#stateManager.updateState({ currentMode: 'idle' });
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
this.#logger.error('[Run] Execution failed', error);
|
|
230
|
-
await this.#stateManager.updateState({ currentMode: 'error-recovery' });
|
|
231
|
-
throw error;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Run in continuous improvement mode
|
|
236
|
-
*/
|
|
237
|
-
async runContinuous() {
|
|
238
|
-
if (!this.#initialized) {
|
|
239
|
-
throw new AgentStatusError('Agent not initialized');
|
|
240
|
-
}
|
|
241
|
-
const state = await this.#stateManager.getState();
|
|
242
|
-
if (!state) {
|
|
243
|
-
throw new AgentStatusError('State is null');
|
|
244
|
-
}
|
|
245
|
-
if (state.currentMode !== 'idle') {
|
|
246
|
-
throw new AgentStatusError(`Cannot start continuous mode while agent is ${state.currentMode}`);
|
|
247
|
-
}
|
|
248
|
-
this.#logger.info('');
|
|
249
|
-
this.#logger.info('🔄 Starting continuous improvement mode...');
|
|
250
|
-
this.#logger.info('');
|
|
251
|
-
await this.#stateManager.updateState({
|
|
252
|
-
currentMode: 'executing',
|
|
253
|
-
});
|
|
254
|
-
// Create and start continuous loop
|
|
255
|
-
this.#improvementLoop = createContinuousImprovementLoop(this.#context, this.#stateManager, this.#sessionId);
|
|
256
|
-
try {
|
|
257
|
-
await this.#improvementLoop.start();
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
this.#logger.error('[Continuous] Loop failed', error);
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
finally {
|
|
264
|
-
await this.#stateManager.updateState({ currentMode: 'idle' });
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Stop agent
|
|
269
|
-
*/
|
|
270
|
-
async stop() {
|
|
271
|
-
this.#logger.info('[Stop] Stopping agent...');
|
|
272
|
-
// Stop continuous loop if running
|
|
273
|
-
if (this.#improvementLoop?.isRunning()) {
|
|
274
|
-
await this.#improvementLoop.stop();
|
|
275
|
-
}
|
|
276
|
-
// Cancel executing tasks
|
|
277
|
-
this.#taskExecutor.cancelAll();
|
|
278
|
-
await this.#stateManager.updateState({ currentMode: 'idle' });
|
|
279
|
-
this.#logger.info('[Stop] ✅ Agent stopped');
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Cleanup and release resources
|
|
283
|
-
*/
|
|
284
|
-
async cleanup() {
|
|
285
|
-
this.#logger.info('[Cleanup] Cleaning up...');
|
|
286
|
-
try {
|
|
287
|
-
// Release session
|
|
288
|
-
await release(this.#sessionId);
|
|
289
|
-
// Log metrics
|
|
290
|
-
const metrics = this.#metrics.getMetrics();
|
|
291
|
-
this.#logger.info('[Cleanup] Metrics:', JSON.stringify(metrics, null, 2));
|
|
292
|
-
this.#initialized = false;
|
|
293
|
-
this.#logger.info('[Cleanup] ✅ Cleanup complete');
|
|
294
|
-
}
|
|
295
|
-
catch (error) {
|
|
296
|
-
this.#logger.error('[Cleanup] Cleanup failed', error);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Execute a plan phase by phase
|
|
301
|
-
*/
|
|
302
|
-
async executePlan(plan) {
|
|
303
|
-
let completedTasks = 0;
|
|
304
|
-
let failedTasks = 0;
|
|
305
|
-
// Add all tasks to the queue first
|
|
306
|
-
await this.#stateManager.updateState({
|
|
307
|
-
taskQueue: plan.tasks,
|
|
308
|
-
});
|
|
309
|
-
// Execute each phase
|
|
310
|
-
for (let i = 0; i < plan.executionOrder.length; i++) {
|
|
311
|
-
const phase = plan.executionOrder[i];
|
|
312
|
-
this.#logger.info(`[Run] Phase ${i + 1}/${plan.executionOrder.length} (${phase.length} task(s))`);
|
|
313
|
-
// Execute tasks in phase (could be parallel in future)
|
|
314
|
-
for (const taskId of phase) {
|
|
315
|
-
const task = plan.tasks.find((t) => t.id === taskId);
|
|
316
|
-
if (!task) {
|
|
317
|
-
this.#logger.warn(`[Run] Task not found: ${taskId}`);
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
// Check for interrupts
|
|
321
|
-
if (this.#interruptHandler.shouldStop()) {
|
|
322
|
-
this.#logger.info(`[Run] ⚠️ Interrupted: ${this.#interruptHandler.getReason()}`);
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
// Execute task
|
|
326
|
-
const success = await this.executeTask(task);
|
|
327
|
-
if (success) {
|
|
328
|
-
completedTasks++;
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
failedTasks++;
|
|
332
|
-
// Stop execution on task failure to prevent cascading errors
|
|
333
|
-
const error = new Error(`Task "${task.title}" failed, stopping execution to prevent cascading errors`);
|
|
334
|
-
this.#logger.error('[Run]', error);
|
|
335
|
-
throw error;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
this.#logger.info(`[Run] Execution summary: ${completedTasks} succeeded, ${failedTasks} failed`);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Execute a single task
|
|
343
|
-
*/
|
|
344
|
-
async executeTask(task) {
|
|
345
|
-
this.#logger.info(`[Run] → ${task.title}`);
|
|
346
|
-
try {
|
|
347
|
-
// Get current state
|
|
348
|
-
const state = await this.#stateManager.getState();
|
|
349
|
-
if (!state) {
|
|
350
|
-
this.#logger.error('[Run]', new Error('State is null'));
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
// Request approval if needed
|
|
354
|
-
const needsApproval = this.#approvalManager.requiresApproval(task);
|
|
355
|
-
if (needsApproval) {
|
|
356
|
-
const decision = await this.#approvalManager.requestApproval(task);
|
|
357
|
-
if (!decision.approved) {
|
|
358
|
-
this.#logger.info(`[Run] ⏭️ Task skipped (not approved): ${decision.reason || 'No reason provided'}`);
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
// Execute task
|
|
363
|
-
const taskStartTime = Date.now();
|
|
364
|
-
const result = await this.#taskExecutor.execute(task, state);
|
|
365
|
-
const actualTime = (Date.now() - taskStartTime) / 60000; // Convert to minutes
|
|
366
|
-
if (result.success) {
|
|
367
|
-
this.#logger.info(`[Run] ✅ Task completed`);
|
|
368
|
-
// Document completed task in working space if configured
|
|
369
|
-
if (this.#workingSpace) {
|
|
370
|
-
// Convert result data to readable string (handle objects, strings, primitives)
|
|
371
|
-
let resultText = result.output;
|
|
372
|
-
if (!resultText) {
|
|
373
|
-
if (result.data !== null && result.data !== undefined) {
|
|
374
|
-
if (typeof result.data === 'string') {
|
|
375
|
-
resultText = result.data;
|
|
376
|
-
}
|
|
377
|
-
else if (typeof result.data === 'object') {
|
|
378
|
-
resultText = JSON.stringify(result.data, null, 2);
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
resultText = String(result.data);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
resultText = 'Task completed successfully';
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
await this.#workingSpace.documentCompletedTask(task, resultText);
|
|
389
|
-
}
|
|
390
|
-
// Move task from queue to completed
|
|
391
|
-
await this.#stateManager.moveTask(task.id, 'queue', 'completed');
|
|
392
|
-
// Add to history
|
|
393
|
-
await this.#taskHistory.add({
|
|
394
|
-
taskId: task.id,
|
|
395
|
-
taskType: task.type,
|
|
396
|
-
success: true,
|
|
397
|
-
duration: Date.now() - taskStartTime,
|
|
398
|
-
estimatedTime: task.estimatedTime,
|
|
399
|
-
actualTime,
|
|
400
|
-
timestamp: Date.now(),
|
|
401
|
-
});
|
|
402
|
-
return true;
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
const errorMsg = result.error || 'Unknown error';
|
|
406
|
-
this.#logger.error('[Run]', new Error(`Task failed: ${errorMsg}`));
|
|
407
|
-
// Move task from queue to failed
|
|
408
|
-
await this.#stateManager.moveTask(task.id, 'queue', 'failed');
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
this.#logger.error('[Run]', error);
|
|
414
|
-
// Move task from queue to failed
|
|
415
|
-
await this.#stateManager.moveTask(task.id, 'queue', 'failed');
|
|
416
|
-
return false;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Generate unique session ID
|
|
421
|
-
*/
|
|
422
|
-
generateSessionId() {
|
|
423
|
-
return `agent-${ulid()}`;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Get current state
|
|
427
|
-
*/
|
|
428
|
-
async getState() {
|
|
429
|
-
return await this.#stateManager.getState();
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Get metrics
|
|
433
|
-
*/
|
|
434
|
-
getMetrics() {
|
|
435
|
-
return this.#metrics.getMetrics();
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/agent/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,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ACjC,UAAU;oBACV,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;iBACtB,CAAC,CAAA;gBAEF,OAAO,IAAI,CAAA;YACb,CAAC;iBAAM,CAAC;gBACN,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,IAAI,eAAe,CAAA;gBAChD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,gBAAgB,QAAQ,EAAE,CAAC,CAAC,CAAA;gBAElE,iCAAiC;gBACjC,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;gBAE7D,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAc,CAAC,CAAA;YAE3C,iCAAiC;YACjC,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;YAE7D,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACK,iBAAiB;QACvB,OAAO,SAAS,IAAI,EAAE,EAAE,CAAA;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAA;IAC5C,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACnC,CAAC;CACF"}
|
package/dist/agent/planner.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants for agent planner
|
|
3
|
-
*/
|
|
4
|
-
const PLANNER_CONSTANTS = {
|
|
5
|
-
/** Maximum number of dependencies before a task is flagged as risky */
|
|
6
|
-
MAX_DEPENDENCIES: 5,
|
|
7
|
-
/** Time threshold (in minutes) for classifying a task as "long-running" */
|
|
8
|
-
LONG_TASK_MINUTES: 120,
|
|
9
|
-
/** File count threshold for classifying a task as "file-heavy" */
|
|
10
|
-
FILE_HEAVY_THRESHOLD: 10,
|
|
11
|
-
/** Priority value that indicates a high-priority task */
|
|
12
|
-
HIGH_PRIORITY: 800,
|
|
13
|
-
/** Priority value that indicates a critical task */
|
|
14
|
-
CRITICAL_PRIORITY: 1000,
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Resolve task dependencies
|
|
18
|
-
*/
|
|
19
|
-
function resolveDependencies(tasks, context) {
|
|
20
|
-
const taskMap = new Map(tasks.map((t) => [t.id, t]));
|
|
21
|
-
const resolved = tasks.map((task) => {
|
|
22
|
-
// Dependencies can be either IDs or titles
|
|
23
|
-
// If all dependencies are valid task IDs, use them as-is
|
|
24
|
-
// Otherwise, convert titles to IDs
|
|
25
|
-
const depIds = [];
|
|
26
|
-
for (const dep of task.dependencies) {
|
|
27
|
-
// Check if this is already a task ID (O(1) lookup)
|
|
28
|
-
const isTaskId = taskMap.has(dep);
|
|
29
|
-
if (isTaskId) {
|
|
30
|
-
// It's already an ID, use it directly
|
|
31
|
-
depIds.push(dep);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// It's a title, find the corresponding task ID
|
|
35
|
-
const depTask = tasks.find((t) => t.title === dep);
|
|
36
|
-
if (depTask) {
|
|
37
|
-
depIds.push(depTask.id);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
context.logger.warn(`[Planner] Dependency not found: ${dep}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
...task,
|
|
46
|
-
dependencies: depIds,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
return resolved;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Create execution phases using topological sort
|
|
53
|
-
* Tasks in each phase can be executed in parallel
|
|
54
|
-
*/
|
|
55
|
-
function createExecutionPhases(tasks, _context) {
|
|
56
|
-
const phases = [];
|
|
57
|
-
const completed = new Set();
|
|
58
|
-
const _taskMap = new Map(tasks.map((t) => [t.id, t]));
|
|
59
|
-
// Keep processing until all tasks are assigned
|
|
60
|
-
while (completed.size < tasks.length) {
|
|
61
|
-
const readyTasks = [];
|
|
62
|
-
// Find all tasks whose dependencies are met
|
|
63
|
-
for (const task of tasks) {
|
|
64
|
-
if (completed.has(task.id))
|
|
65
|
-
continue;
|
|
66
|
-
// Check if all dependencies are met
|
|
67
|
-
// Note: task.dependencies should be task IDs at this point
|
|
68
|
-
const depsMet = task.dependencies.every((depId) => completed.has(depId));
|
|
69
|
-
if (depsMet) {
|
|
70
|
-
readyTasks.push(task.id);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (readyTasks.length === 0) {
|
|
74
|
-
// Circular dependency or missing dependency - throw error instead of returning partial plan
|
|
75
|
-
const remainingTasks = tasks.filter((t) => !completed.has(t.id)).map((t) => `${t.title} (deps: ${t.dependencies.join(', ')})`);
|
|
76
|
-
throw new Error(`Circular dependency detected or missing dependencies. Remaining tasks: ${remainingTasks.join(', ')}`);
|
|
77
|
-
}
|
|
78
|
-
// Add to phases and mark as completed
|
|
79
|
-
phases.push(readyTasks);
|
|
80
|
-
for (const id of readyTasks) {
|
|
81
|
-
completed.add(id);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return phases;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Identify potential risks in the plan
|
|
88
|
-
*/
|
|
89
|
-
function identifyRisks(tasks) {
|
|
90
|
-
const risks = [];
|
|
91
|
-
// Check for tasks with many dependencies
|
|
92
|
-
for (const task of tasks) {
|
|
93
|
-
if (task.dependencies.length > PLANNER_CONSTANTS.MAX_DEPENDENCIES) {
|
|
94
|
-
risks.push(`Task "${task.title}" has ${task.dependencies.length} dependencies - could become blocked`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// Check for long-running tasks
|
|
98
|
-
const longTasks = tasks.filter((t) => t.estimatedTime > PLANNER_CONSTANTS.LONG_TASK_MINUTES);
|
|
99
|
-
if (longTasks.length > 0) {
|
|
100
|
-
risks.push(`${longTasks.length} tasks have long estimated time (>2 hours)`);
|
|
101
|
-
}
|
|
102
|
-
// Check for high-priority tasks with high complexity
|
|
103
|
-
const riskyTasks = tasks.filter((t) => t.priority >= PLANNER_CONSTANTS.HIGH_PRIORITY && t.complexity === 'high');
|
|
104
|
-
if (riskyTasks.length > 0) {
|
|
105
|
-
risks.push(`${riskyTasks.length} high-priority, high-complexity tasks`);
|
|
106
|
-
}
|
|
107
|
-
// Check for tasks affecting many files
|
|
108
|
-
const fileHeavyTasks = tasks.filter((t) => t.files.length > PLANNER_CONSTANTS.FILE_HEAVY_THRESHOLD);
|
|
109
|
-
if (fileHeavyTasks.length > 0) {
|
|
110
|
-
risks.push(`${fileHeavyTasks.length} tasks affect >10 files - potential for merge conflicts`);
|
|
111
|
-
}
|
|
112
|
-
// Check for many critical tasks
|
|
113
|
-
const criticalTasks = tasks.filter((t) => t.priority === PLANNER_CONSTANTS.CRITICAL_PRIORITY);
|
|
114
|
-
if (criticalTasks.length > 3) {
|
|
115
|
-
risks.push(`${criticalTasks.length} critical-priority tasks - consider prioritizing`);
|
|
116
|
-
}
|
|
117
|
-
return risks;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Generate high-level plan description
|
|
121
|
-
*/
|
|
122
|
-
function generateHighLevelPlan(goal, tasks, context) {
|
|
123
|
-
const lines = [];
|
|
124
|
-
lines.push(`**Goal:** ${goal}`);
|
|
125
|
-
lines.push('');
|
|
126
|
-
lines.push(`**Overview:** This goal will be achieved through ${tasks.length} tasks organized into logical phases.`);
|
|
127
|
-
lines.push('');
|
|
128
|
-
// Group by type
|
|
129
|
-
const byType = new Map();
|
|
130
|
-
for (const task of tasks) {
|
|
131
|
-
if (!byType.has(task.type)) {
|
|
132
|
-
byType.set(task.type, []);
|
|
133
|
-
}
|
|
134
|
-
byType.get(task.type)?.push(task);
|
|
135
|
-
}
|
|
136
|
-
// Show task breakdown
|
|
137
|
-
lines.push(`**Task Breakdown:**`);
|
|
138
|
-
for (const [type, typeTasks] of byType) {
|
|
139
|
-
lines.push(`- ${typeTasks.length} ${type} task(s)`);
|
|
140
|
-
}
|
|
141
|
-
lines.push('');
|
|
142
|
-
// Show phases (simplified)
|
|
143
|
-
const phases = createExecutionPhases(tasks, context);
|
|
144
|
-
lines.push(`**Execution:** ${phases.length} phases`);
|
|
145
|
-
for (let i = 0; i < phases.length; i++) {
|
|
146
|
-
const phaseTasks = phases[i].map((id) => tasks.find((t) => t.id === id)?.title);
|
|
147
|
-
lines.push(`- Phase ${i + 1}: ${phaseTasks.join(', ')}`);
|
|
148
|
-
}
|
|
149
|
-
return lines.join('\n');
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Extract dependency graph as list of edges
|
|
153
|
-
*/
|
|
154
|
-
function extractDependencyGraph(tasks) {
|
|
155
|
-
const dependencies = [];
|
|
156
|
-
for (const task of tasks) {
|
|
157
|
-
if (task.dependencies.length > 0) {
|
|
158
|
-
dependencies.push({
|
|
159
|
-
taskId: task.id,
|
|
160
|
-
dependsOn: task.dependencies,
|
|
161
|
-
type: 'hard',
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return dependencies;
|
|
166
|
-
}
|
|
167
|
-
export function createTaskPlanner(context) {
|
|
168
|
-
return {
|
|
169
|
-
createPlan(goal, tasks) {
|
|
170
|
-
context.logger.info(`[Planner] Creating plan with ${tasks.length} tasks`);
|
|
171
|
-
// Resolve dependencies
|
|
172
|
-
const withDependencies = resolveDependencies(tasks, context);
|
|
173
|
-
// Create execution phases (topological sort)
|
|
174
|
-
const executionOrder = createExecutionPhases(withDependencies, context);
|
|
175
|
-
// Estimate total time
|
|
176
|
-
const estimatedTime = withDependencies.reduce((sum, task) => sum + task.estimatedTime, 0);
|
|
177
|
-
// Identify risks
|
|
178
|
-
const risks = identifyRisks(withDependencies);
|
|
179
|
-
// Generate high-level plan text
|
|
180
|
-
const highLevelPlan = generateHighLevelPlan(goal, withDependencies, context);
|
|
181
|
-
// Convert dependency array to Record format
|
|
182
|
-
const dependencyGraph = {};
|
|
183
|
-
const depArray = extractDependencyGraph(withDependencies);
|
|
184
|
-
for (const dep of depArray) {
|
|
185
|
-
dependencyGraph[dep.taskId] = dep.dependsOn;
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
goal,
|
|
189
|
-
highLevelPlan,
|
|
190
|
-
tasks: withDependencies,
|
|
191
|
-
executionOrder,
|
|
192
|
-
estimatedTime,
|
|
193
|
-
risks,
|
|
194
|
-
dependencies: dependencyGraph,
|
|
195
|
-
};
|
|
196
|
-
},
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
//# sourceMappingURL=planner.js.map
|