@kalenkevich/agent_007 0.0.1
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/agent/agent.d.ts +17 -0
- package/dist/agent/agent.js +6 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/agent_event.d.ts +108 -0
- package/dist/agent/agent_event.js +56 -0
- package/dist/agent/agent_event.js.map +1 -0
- package/dist/agent/agent_event_utils.d.ts +5 -0
- package/dist/agent/agent_event_utils.js +66 -0
- package/dist/agent/agent_event_utils.js.map +1 -0
- package/dist/agent/cli_agent/cli_agent.d.ts +41 -0
- package/dist/agent/cli_agent/cli_agent.js +324 -0
- package/dist/agent/cli_agent/cli_agent.js.map +1 -0
- package/dist/agent/cli_agent/system_prompt.d.ts +1 -0
- package/dist/agent/cli_agent/system_prompt.js +58 -0
- package/dist/agent/cli_agent/system_prompt.js.map +1 -0
- package/dist/agent/cli_agent.d.ts +34 -0
- package/dist/agent/cli_agent.js +91 -0
- package/dist/agent/cli_agent.js.map +1 -0
- package/dist/agent/planner_agent/planner_agent.d.ts +28 -0
- package/dist/agent/planner_agent/planner_agent.js +102 -0
- package/dist/agent/planner_agent/planner_agent.js.map +1 -0
- package/dist/agent/request_processor/basic_request_processor.d.ts +17 -0
- package/dist/agent/request_processor/basic_request_processor.js +28 -0
- package/dist/agent/request_processor/basic_request_processor.js.map +1 -0
- package/dist/agent/request_processor/compaction_processor.d.ts +17 -0
- package/dist/agent/request_processor/compaction_processor.js +118 -0
- package/dist/agent/request_processor/compaction_processor.js.map +1 -0
- package/dist/agent/request_processor/request_processor.d.ts +11 -0
- package/dist/agent/request_processor/request_processor.js +2 -0
- package/dist/agent/request_processor/request_processor.js.map +1 -0
- package/dist/cli/init_project_command_handler.d.ts +3 -0
- package/dist/cli/init_project_command_handler.js +58 -0
- package/dist/cli/init_project_command_handler.js.map +1 -0
- package/dist/cli/loader.d.ts +6 -0
- package/dist/cli/loader.js +27 -0
- package/dist/cli/loader.js.map +1 -0
- package/dist/cli/prompt_utils.d.ts +11 -0
- package/dist/cli/prompt_utils.js +18 -0
- package/dist/cli/prompt_utils.js.map +1 -0
- package/dist/cli/run_command.d.ts +6 -0
- package/dist/cli/run_command.js +72 -0
- package/dist/cli/run_command.js.map +1 -0
- package/dist/cli/run_interactive_command.d.ts +6 -0
- package/dist/cli/run_interactive_command.js +282 -0
- package/dist/cli/run_interactive_command.js.map +1 -0
- package/dist/cli/run_noninteractive_command.d.ts +6 -0
- package/dist/cli/run_noninteractive_command.js +60 -0
- package/dist/cli/run_noninteractive_command.js.map +1 -0
- package/dist/cli_entrypoint.d.ts +2 -0
- package/dist/cli_entrypoint.js +110 -0
- package/dist/cli_entrypoint.js.map +1 -0
- package/dist/command/commnad_handler.d.ts +3 -0
- package/dist/command/commnad_handler.js +2 -0
- package/dist/command/commnad_handler.js.map +1 -0
- package/dist/command/init_project_command_handler.d.ts +4 -0
- package/dist/command/init_project_command_handler.js +58 -0
- package/dist/command/init_project_command_handler.js.map +1 -0
- package/dist/config/app_dir.d.ts +1 -0
- package/dist/config/app_dir.js +4 -0
- package/dist/config/app_dir.js.map +1 -0
- package/dist/config/config.d.ts +21 -0
- package/dist/config/config.js +2 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/config_loader.d.ts +2 -0
- package/dist/config/config_loader.js +47 -0
- package/dist/config/config_loader.js.map +1 -0
- package/dist/config/config_store.d.ts +10 -0
- package/dist/config/config_store.js +44 -0
- package/dist/config/config_store.js.map +1 -0
- package/dist/content.d.ts +51 -0
- package/dist/content.js +16 -0
- package/dist/content.js.map +1 -0
- package/dist/core/functions.d.ts +1 -0
- package/dist/core/functions.js +6 -0
- package/dist/core/functions.js.map +1 -0
- package/dist/core/loop.d.ts +20 -0
- package/dist/core/loop.js +121 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/core/project_service.d.ts +11 -0
- package/dist/core/project_service.js +26 -0
- package/dist/core/project_service.js.map +1 -0
- package/dist/core/run.d.ts +6 -0
- package/dist/core/run.js +25 -0
- package/dist/core/run.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +27 -0
- package/dist/logger.js +98 -0
- package/dist/logger.js.map +1 -0
- package/dist/model/adaptive_model.d.ts +16 -0
- package/dist/model/adaptive_model.js +57 -0
- package/dist/model/adaptive_model.js.map +1 -0
- package/dist/model/google/gemini_model.d.ts +15 -0
- package/dist/model/google/gemini_model.js +131 -0
- package/dist/model/google/gemini_model.js.map +1 -0
- package/dist/model/google/gemini_response_utils.d.ts +3 -0
- package/dist/model/google/gemini_response_utils.js +36 -0
- package/dist/model/google/gemini_response_utils.js.map +1 -0
- package/dist/model/google/gemini_streaming_utils.d.ts +28 -0
- package/dist/model/google/gemini_streaming_utils.js +235 -0
- package/dist/model/google/gemini_streaming_utils.js.map +1 -0
- package/dist/model/google/gen_ai_convert_utils.d.ts +6 -0
- package/dist/model/google/gen_ai_convert_utils.js +117 -0
- package/dist/model/google/gen_ai_convert_utils.js.map +1 -0
- package/dist/model/model.d.ts +11 -0
- package/dist/model/model.js +2 -0
- package/dist/model/model.js.map +1 -0
- package/dist/model/registry.d.ts +19 -0
- package/dist/model/registry.js +47 -0
- package/dist/model/registry.js.map +1 -0
- package/dist/model/request.d.ts +13 -0
- package/dist/model/request.js +2 -0
- package/dist/model/request.js.map +1 -0
- package/dist/model/request_builder_utils.d.ts +19 -0
- package/dist/model/request_builder_utils.js +43 -0
- package/dist/model/request_builder_utils.js.map +1 -0
- package/dist/model/response.d.ts +60 -0
- package/dist/model/response.js +2 -0
- package/dist/model/response.js.map +1 -0
- package/dist/model/util_llm.d.ts +10 -0
- package/dist/model/util_llm.js +149 -0
- package/dist/model/util_llm.js.map +1 -0
- package/dist/session/session.d.ts +14 -0
- package/dist/session/session.js +2 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/session_file_service.d.ts +23 -0
- package/dist/session/session_file_service.js +147 -0
- package/dist/session/session_file_service.js.map +1 -0
- package/dist/skills/skill.d.ts +23 -0
- package/dist/skills/skill.js +12 -0
- package/dist/skills/skill.js.map +1 -0
- package/dist/tools/build_in/find.d.ts +3 -0
- package/dist/tools/build_in/find.js +71 -0
- package/dist/tools/build_in/find.js.map +1 -0
- package/dist/tools/build_in/grep.d.ts +3 -0
- package/dist/tools/build_in/grep.js +97 -0
- package/dist/tools/build_in/grep.js.map +1 -0
- package/dist/tools/build_in/index.d.ts +1 -0
- package/dist/tools/build_in/index.js +13 -0
- package/dist/tools/build_in/index.js.map +1 -0
- package/dist/tools/build_in/list_dir.d.ts +3 -0
- package/dist/tools/build_in/list_dir.js +46 -0
- package/dist/tools/build_in/list_dir.js.map +1 -0
- package/dist/tools/build_in/view_file.d.ts +3 -0
- package/dist/tools/build_in/view_file.js +44 -0
- package/dist/tools/build_in/view_file.js.map +1 -0
- package/dist/tools/build_in/write_file.d.ts +3 -0
- package/dist/tools/build_in/write_file.js +50 -0
- package/dist/tools/build_in/write_file.js.map +1 -0
- package/dist/tools/functional_tool.d.ts +18 -0
- package/dist/tools/functional_tool.js +20 -0
- package/dist/tools/functional_tool.js.map +1 -0
- package/dist/tools/schema.d.ts +86 -0
- package/dist/tools/schema.js +37 -0
- package/dist/tools/schema.js.map +1 -0
- package/dist/tools/tool.d.ts +30 -0
- package/dist/tools/tool.js +9 -0
- package/dist/tools/tool.js.map +1 -0
- package/dist/tools/tool_call_policy.d.ts +4 -0
- package/dist/tools/tool_call_policy.js +4 -0
- package/dist/tools/tool_call_policy.js.map +1 -0
- package/dist/tools/tool_policy.d.ts +4 -0
- package/dist/tools/tool_policy.js +4 -0
- package/dist/tools/tool_policy.js.map +1 -0
- package/dist/ui/ui.d.ts +1 -0
- package/dist/ui/ui.js +2 -0
- package/dist/ui/ui.js.map +1 -0
- package/dist/user_input.d.ts +20 -0
- package/dist/user_input.js +21 -0
- package/dist/user_input.js.map +1 -0
- package/package.json +44 -0
- package/src/agent/agent.ts +18 -0
- package/src/agent/agent_event.ts +171 -0
- package/src/agent/agent_event_utils.ts +87 -0
- package/src/agent/cli_agent/cli_agent.ts +418 -0
- package/src/agent/cli_agent/system_prompt.ts +57 -0
- package/src/agent/planner_agent/planner_agent.ts +136 -0
- package/src/agent/request_processor/basic_request_processor.ts +46 -0
- package/src/agent/request_processor/compaction_processor.ts +164 -0
- package/src/agent/request_processor/request_processor.ts +13 -0
- package/src/cli/loader.ts +27 -0
- package/src/cli/prompt_utils.ts +19 -0
- package/src/cli/run_interactive_command.ts +337 -0
- package/src/cli/run_noninteractive_command.ts +74 -0
- package/src/cli_entrypoint.ts +128 -0
- package/src/command/commnad_handler.ts +3 -0
- package/src/command/init_project_command_handler.ts +66 -0
- package/src/config/app_dir.ts +4 -0
- package/src/config/config.ts +24 -0
- package/src/config/config_loader.ts +57 -0
- package/src/config/config_store.ts +50 -0
- package/src/content.ts +87 -0
- package/src/core/functions.ts +7 -0
- package/src/core/loop.ts +165 -0
- package/src/core/project_service.ts +38 -0
- package/src/core/run.ts +36 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +128 -0
- package/src/model/adaptive_model.ts +77 -0
- package/src/model/google/gemini_model.ts +194 -0
- package/src/model/google/gemini_response_utils.ts +46 -0
- package/src/model/google/gemini_streaming_utils.ts +294 -0
- package/src/model/google/gen_ai_convert_utils.ts +149 -0
- package/src/model/model.ts +18 -0
- package/src/model/registry.ts +61 -0
- package/src/model/request.ts +15 -0
- package/src/model/request_builder_utils.ts +79 -0
- package/src/model/response.ts +66 -0
- package/src/model/util_llm.ts +167 -0
- package/src/session/session.ts +16 -0
- package/src/session/session_file_service.ts +207 -0
- package/src/skills/skill.ts +38 -0
- package/src/tools/build_in/find.ts +80 -0
- package/src/tools/build_in/grep.ts +101 -0
- package/src/tools/build_in/index.ts +13 -0
- package/src/tools/build_in/list_dir.ts +50 -0
- package/src/tools/build_in/view_file.ts +47 -0
- package/src/tools/build_in/write_file.ts +53 -0
- package/src/tools/functional_tool.ts +59 -0
- package/src/tools/schema.ts +87 -0
- package/src/tools/tool.ts +68 -0
- package/src/tools/tool_call_policy.ts +7 -0
- package/src/ui/ui.ts +0 -0
- package/src/user_input.ts +51 -0
- package/tests/integration/util_llm_test.ts +42 -0
- package/tests/unit/adaptive_model_test.ts +122 -0
- package/tests/unit/agent/request_processor/compaction_processor_test.ts +121 -0
- package/tests/unit/cli/prompt_utils_test.ts +47 -0
- package/tests/unit/cli_agent_test.ts +476 -0
- package/tests/unit/content_test.ts +56 -0
- package/tests/unit/logger_test.ts +109 -0
- package/tests/unit/loop_test.ts +141 -0
- package/tests/unit/model/gemini_model_test.ts +111 -0
- package/tests/unit/planner_agent_test.ts +52 -0
- package/tests/unit/project_service_test.ts +102 -0
- package/tests/unit/session_file_service_test.ts +160 -0
- package/tests/unit/tools/find_test.ts +40 -0
- package/tests/unit/tools/grep_test.ts +43 -0
- package/tests/unit/tools/list_dir_test.ts +32 -0
- package/tests/unit/tools/view_file_test.ts +32 -0
- package/tests/unit/tools/write_file_test.ts +44 -0
- package/tests/unit/user_input_test.ts +55 -0
- package/tests/unit/util_llm_test.ts +61 -0
- package/todo.md +29 -0
- package/tsconfig.json +33 -0
- package/vitest.config.ts +33 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CLI_AGENT_SYSTEM_PROMPT = "\nYou are Agent 007, an advanced AI coding assistant specializing in software engineering tasks. Your primary goal is to help users safely and effectively develop, debug, and maintain codebases.\n\n## Core Mandates\n\n### Security & System Integrity\n- **Credential Protection:** Never log, print, or commit secrets, API keys, or sensitive credentials. Rigorously protect `.env` files, `.git`, and system configuration folders.\n- **Source Control:** Do not stage or commit changes unless specifically requested by the user.\n\n### Context Efficiency\nBe strategic in your use of the available tools to minimize unnecessary context usage while still providing the best answer that you can.\n- **Minimize Turns:** Combine turns whenever possible by utilizing parallel searching and reading.\n- **Search First:** Prefer using search tools (e.g., grep, glob) to identify points of interest instead of reading lots of files individually.\n- **Conservative Limits:** Provide conservative limits and scopes to tools to reduce the impact on context, as long as it doesn't result in extra turns to recover missing data.\n\n### Conventions & Style\n- **Workspace Precedence:** Rigorously adhere to existing workspace conventions, architectural patterns, and style (naming, formatting, typing, commenting).\n- **Surgical Updates:** Analyze surrounding files, tests, and configuration to ensure your changes are seamless, idiomatic, and consistent with the local context.\n\n### Technical Integrity & Quality\n- **No Hacks:** NEVER use hacks like disabling or suppressing warnings, bypassing the type system, or employing \"hidden\" logic unless explicitly instructed. Use explicit and idiomatic language features.\n- **Library Verification:** NEVER assume a library/framework is available. Verify its established usage within the project (e.g., check `package.json`, `Cargo.toml`) before employing it.\n- **Lifecycle Responsibility:** You are responsible for the entire lifecycle: implementation, testing, and validation.\n- **Testing Mandate:** ALWAYS search for and update related tests after making a code change. You must add a new test case to the existing test file or create a new one to verify your changes.\n- **Bug Reproduction:** For bug fixes, you must empirically reproduce the failure with a new test case or reproduction script before applying the fix.\n\n### Expertise & Intent Alignment\n- **Directives vs Inquiries:** Distinguish between **Directives** (unambiguous requests for action) and **Inquiries** (requests for analysis, advice, or observations).\n- **Default to Inquiry:** Assume all requests are Inquiries unless they contain an explicit instruction to perform a task.\n- **Scope Limitation:** For Inquiries, your scope is strictly limited to research and analysis. Propose solutions but DO NOT modify files until a corresponding Directive is issued.\n- **Autonomy:** For Directives, work autonomously. Only seek user intervention if you have exhausted all possible routes or if a proposed solution diverges significantly from the established architecture.\n\n## Development Lifecycle\n\nOperate using a **Research -> Strategy -> Execution** lifecycle. For the Execution phase, resolve each sub-task through an iterative **Plan -> Act -> Validate** cycle.\n\n1. **Research:** Systematically map the codebase and validate assumptions. Use search tools extensively to understand file structures and conventions. Prioritize empirical reproduction of reported issues.\n2. **Strategy:** Formulate a grounded plan based on your research. Share a concise summary of your strategy with the user before proceeding to execution.\n3. **Execution:** For each sub-task:\n - **Plan:** Define the specific implementation approach and the testing strategy to verify the change.\n - **Act:** Apply targeted, surgical changes. Ensure changes are idiomatically complete and follow all workspace standards.\n - **Validate:** Run tests and workspace standards to confirm the success of the specific change and ensure no regressions were introduced. Validation is the only path to finality.\n\n## Operational Guidelines\n\n### Tone and Style\n- **Role:** A senior software engineer and collaborative peer programmer.\n- **High-Signal Output:** Focus exclusively on **intent** and **technical rationale**. Avoid conversational filler, apologies, and mechanical tool-use narration.\n- **Concise & Direct:** Adopt a professional, direct, and concise tone suitable for a CLI environment. Aim for minimal text output per response whenever practical.\n- **Formatting:** Use GitHub-flavored Markdown.\n\n### Tool Usage\n- **Parallelism:** Tools execute in parallel by default. Execute multiple independent tool calls in parallel when feasible (e.g., searching or reading different files).\n- **Sequencing:** If a tool depends on the output of a previous tool in the same turn, you MUST ensure sequential execution (e.g., setting specific flags if the system supports it).\n- **File Collisions:** Do NOT make multiple calls to edit tools for the SAME file in a single turn to prevent race conditions.\n- **Explain Critical Commands:** Before executing commands that modify the file system or system state, provide a brief explanation of the command's purpose and potential impact.\n";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const CLI_AGENT_SYSTEM_PROMPT = `
|
|
2
|
+
You are Agent 007, an advanced AI coding assistant specializing in software engineering tasks. Your primary goal is to help users safely and effectively develop, debug, and maintain codebases.
|
|
3
|
+
|
|
4
|
+
## Core Mandates
|
|
5
|
+
|
|
6
|
+
### Security & System Integrity
|
|
7
|
+
- **Credential Protection:** Never log, print, or commit secrets, API keys, or sensitive credentials. Rigorously protect \`.env\` files, \`.git\`, and system configuration folders.
|
|
8
|
+
- **Source Control:** Do not stage or commit changes unless specifically requested by the user.
|
|
9
|
+
|
|
10
|
+
### Context Efficiency
|
|
11
|
+
Be strategic in your use of the available tools to minimize unnecessary context usage while still providing the best answer that you can.
|
|
12
|
+
- **Minimize Turns:** Combine turns whenever possible by utilizing parallel searching and reading.
|
|
13
|
+
- **Search First:** Prefer using search tools (e.g., grep, glob) to identify points of interest instead of reading lots of files individually.
|
|
14
|
+
- **Conservative Limits:** Provide conservative limits and scopes to tools to reduce the impact on context, as long as it doesn't result in extra turns to recover missing data.
|
|
15
|
+
|
|
16
|
+
### Conventions & Style
|
|
17
|
+
- **Workspace Precedence:** Rigorously adhere to existing workspace conventions, architectural patterns, and style (naming, formatting, typing, commenting).
|
|
18
|
+
- **Surgical Updates:** Analyze surrounding files, tests, and configuration to ensure your changes are seamless, idiomatic, and consistent with the local context.
|
|
19
|
+
|
|
20
|
+
### Technical Integrity & Quality
|
|
21
|
+
- **No Hacks:** NEVER use hacks like disabling or suppressing warnings, bypassing the type system, or employing "hidden" logic unless explicitly instructed. Use explicit and idiomatic language features.
|
|
22
|
+
- **Library Verification:** NEVER assume a library/framework is available. Verify its established usage within the project (e.g., check \`package.json\`, \`Cargo.toml\`) before employing it.
|
|
23
|
+
- **Lifecycle Responsibility:** You are responsible for the entire lifecycle: implementation, testing, and validation.
|
|
24
|
+
- **Testing Mandate:** ALWAYS search for and update related tests after making a code change. You must add a new test case to the existing test file or create a new one to verify your changes.
|
|
25
|
+
- **Bug Reproduction:** For bug fixes, you must empirically reproduce the failure with a new test case or reproduction script before applying the fix.
|
|
26
|
+
|
|
27
|
+
### Expertise & Intent Alignment
|
|
28
|
+
- **Directives vs Inquiries:** Distinguish between **Directives** (unambiguous requests for action) and **Inquiries** (requests for analysis, advice, or observations).
|
|
29
|
+
- **Default to Inquiry:** Assume all requests are Inquiries unless they contain an explicit instruction to perform a task.
|
|
30
|
+
- **Scope Limitation:** For Inquiries, your scope is strictly limited to research and analysis. Propose solutions but DO NOT modify files until a corresponding Directive is issued.
|
|
31
|
+
- **Autonomy:** For Directives, work autonomously. Only seek user intervention if you have exhausted all possible routes or if a proposed solution diverges significantly from the established architecture.
|
|
32
|
+
|
|
33
|
+
## Development Lifecycle
|
|
34
|
+
|
|
35
|
+
Operate using a **Research -> Strategy -> Execution** lifecycle. For the Execution phase, resolve each sub-task through an iterative **Plan -> Act -> Validate** cycle.
|
|
36
|
+
|
|
37
|
+
1. **Research:** Systematically map the codebase and validate assumptions. Use search tools extensively to understand file structures and conventions. Prioritize empirical reproduction of reported issues.
|
|
38
|
+
2. **Strategy:** Formulate a grounded plan based on your research. Share a concise summary of your strategy with the user before proceeding to execution.
|
|
39
|
+
3. **Execution:** For each sub-task:
|
|
40
|
+
- **Plan:** Define the specific implementation approach and the testing strategy to verify the change.
|
|
41
|
+
- **Act:** Apply targeted, surgical changes. Ensure changes are idiomatically complete and follow all workspace standards.
|
|
42
|
+
- **Validate:** Run tests and workspace standards to confirm the success of the specific change and ensure no regressions were introduced. Validation is the only path to finality.
|
|
43
|
+
|
|
44
|
+
## Operational Guidelines
|
|
45
|
+
|
|
46
|
+
### Tone and Style
|
|
47
|
+
- **Role:** A senior software engineer and collaborative peer programmer.
|
|
48
|
+
- **High-Signal Output:** Focus exclusively on **intent** and **technical rationale**. Avoid conversational filler, apologies, and mechanical tool-use narration.
|
|
49
|
+
- **Concise & Direct:** Adopt a professional, direct, and concise tone suitable for a CLI environment. Aim for minimal text output per response whenever practical.
|
|
50
|
+
- **Formatting:** Use GitHub-flavored Markdown.
|
|
51
|
+
|
|
52
|
+
### Tool Usage
|
|
53
|
+
- **Parallelism:** Tools execute in parallel by default. Execute multiple independent tool calls in parallel when feasible (e.g., searching or reading different files).
|
|
54
|
+
- **Sequencing:** If a tool depends on the output of a previous tool in the same turn, you MUST ensure sequential execution (e.g., setting specific flags if the system supports it).
|
|
55
|
+
- **File Collisions:** Do NOT make multiple calls to edit tools for the SAME file in a single turn to prevent race conditions.
|
|
56
|
+
- **Explain Critical Commands:** Before executing commands that modify the file system or system state, provide a brief explanation of the command's purpose and potential impact.
|
|
57
|
+
`;
|
|
58
|
+
//# sourceMappingURL=system_prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system_prompt.js","sourceRoot":"","sources":["../../../src/agent/cli_agent/system_prompt.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDtC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Agent } from "./agent.js";
|
|
2
|
+
import type { LlmModel } from "../model/model.js";
|
|
3
|
+
import type { Tool } from "../tools/tool.js";
|
|
4
|
+
import type { Skill } from "../skills/skill.js";
|
|
5
|
+
import { type AgentEvent } from "./agent_event.js";
|
|
6
|
+
import { type UserInput } from "../user_input.js";
|
|
7
|
+
export interface CliAgentOptions {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
instructions: string;
|
|
11
|
+
model: LlmModel;
|
|
12
|
+
tools?: Tool[];
|
|
13
|
+
skills?: Skill[];
|
|
14
|
+
history?: AgentEvent[];
|
|
15
|
+
}
|
|
16
|
+
export declare class CliAgent implements Agent {
|
|
17
|
+
readonly id = "cli_agent";
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly description: string;
|
|
20
|
+
readonly instructions: string;
|
|
21
|
+
readonly model: LlmModel;
|
|
22
|
+
readonly tools?: Tool[];
|
|
23
|
+
readonly skills?: Skill[];
|
|
24
|
+
private streamId?;
|
|
25
|
+
private history;
|
|
26
|
+
private historyContent;
|
|
27
|
+
private abortController?;
|
|
28
|
+
constructor(options: CliAgentOptions);
|
|
29
|
+
run(userInput: UserInput): AsyncGenerator<AgentEvent, void, unknown>;
|
|
30
|
+
private runInternal;
|
|
31
|
+
private createEvent;
|
|
32
|
+
getHistory(): AgentEvent[];
|
|
33
|
+
abort(): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { AgentEventType, AgentEndReason, } from "./agent_event.js";
|
|
3
|
+
import { isUserCommand, toContentParts, } from "../user_input.js";
|
|
4
|
+
import { buildLlmRequest } from "../model/request_builder_utils.js";
|
|
5
|
+
import { getContentFromAgentEvent, llmResponseToAgentEvents, } from "./agent_event_utils.js";
|
|
6
|
+
import { logger } from "../logger.js";
|
|
7
|
+
export class CliAgent {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.id = "cli_agent";
|
|
10
|
+
this.history = [];
|
|
11
|
+
this.historyContent = [];
|
|
12
|
+
this.name = options.name;
|
|
13
|
+
this.description = options.description;
|
|
14
|
+
this.instructions = options.instructions;
|
|
15
|
+
this.model = options.model;
|
|
16
|
+
this.tools = options.tools;
|
|
17
|
+
this.skills = options.skills;
|
|
18
|
+
this.history = options.history || [];
|
|
19
|
+
this.historyContent = this.history
|
|
20
|
+
.map((c) => getContentFromAgentEvent(c))
|
|
21
|
+
.filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
async *run(userInput) {
|
|
24
|
+
for await (const agentEvent of this.runInternal(userInput)) {
|
|
25
|
+
this.history.push(agentEvent);
|
|
26
|
+
const content = getContentFromAgentEvent(agentEvent);
|
|
27
|
+
if (content) {
|
|
28
|
+
this.historyContent.push(content);
|
|
29
|
+
}
|
|
30
|
+
yield agentEvent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async *runInternal(userInput) {
|
|
34
|
+
if (isUserCommand(userInput)) {
|
|
35
|
+
// process command
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const userContent = toContentParts(userInput);
|
|
39
|
+
logger.debug("[CliAgent] runInternal started");
|
|
40
|
+
this.abortController = new AbortController();
|
|
41
|
+
this.streamId = randomUUID();
|
|
42
|
+
yield this.createEvent(AgentEventType.START);
|
|
43
|
+
yield this.createEvent(AgentEventType.MESSAGE, {
|
|
44
|
+
role: "user",
|
|
45
|
+
parts: userContent,
|
|
46
|
+
});
|
|
47
|
+
const llmRequest = buildLlmRequest({
|
|
48
|
+
agentName: this.name,
|
|
49
|
+
content: {
|
|
50
|
+
parts: userContent,
|
|
51
|
+
role: "user",
|
|
52
|
+
},
|
|
53
|
+
historyContent: this.historyContent.slice(0, -1),
|
|
54
|
+
tools: this.tools,
|
|
55
|
+
skills: this.skills,
|
|
56
|
+
description: this.description,
|
|
57
|
+
instructions: this.instructions,
|
|
58
|
+
});
|
|
59
|
+
logger.debug("[CliAgent] calling model.run");
|
|
60
|
+
for await (const modelResponse of this.model.run(llmRequest, {
|
|
61
|
+
stream: true,
|
|
62
|
+
abortSignal: this.abortController?.signal,
|
|
63
|
+
})) {
|
|
64
|
+
for (const agentEvent of llmResponseToAgentEvents(modelResponse)) {
|
|
65
|
+
logger.debug("[CliAgent] yielding event:", agentEvent.type);
|
|
66
|
+
yield this.createEvent(agentEvent.type, agentEvent);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
yield this.createEvent(AgentEventType.END, {
|
|
70
|
+
role: "agent",
|
|
71
|
+
type: AgentEventType.END,
|
|
72
|
+
reason: AgentEndReason.COMPLETED,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
createEvent(type, data = {}) {
|
|
76
|
+
return {
|
|
77
|
+
type,
|
|
78
|
+
id: randomUUID(),
|
|
79
|
+
streamId: this.streamId,
|
|
80
|
+
timestamp: new Date().toISOString(),
|
|
81
|
+
...data,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
getHistory() {
|
|
85
|
+
return [...this.history];
|
|
86
|
+
}
|
|
87
|
+
async abort() {
|
|
88
|
+
this.abortController?.abort();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=cli_agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli_agent.js","sourceRoot":"","sources":["../../src/agent/cli_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,EAEL,cAAc,EACd,cAAc,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEL,aAAa,EACb,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,c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AAC,WAAW,CAAC,UAAU,CAAC,IAAK,EAAE,UAAU,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAED,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,EAAE;YACzC,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,cAAc,CAAC,GAAG;YACxB,MAAM,EAAE,cAAc,CAAC,SAAS;SACjC,CAAC,CAAC;IACL,CAAC;IAEO,WAAW,CACjB,IAAoB,EACpB,OAA4B,EAAE;QAE9B,OAAO;YACL,IAAI;YACJ,EAAE,EAAE,UAAU,EAAE;YAChB,QAAQ,EAAE,IAAI,CAAC,QAAS;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,GAAG,IAAI;SACM,CAAC;IAClB,CAAC;IAED,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Agent } from "../agent.js";
|
|
2
|
+
import type { LlmModel } from "../../model/model.js";
|
|
3
|
+
import type { Tool } from "../../tools/tool.js";
|
|
4
|
+
import type { Skill } from "../../skills/skill.js";
|
|
5
|
+
import { type AgentEvent } from "../agent_event.js";
|
|
6
|
+
import { type UserInput } from "../../user_input.js";
|
|
7
|
+
export interface PlannerAgentOptions {
|
|
8
|
+
model: LlmModel;
|
|
9
|
+
tools?: Tool[];
|
|
10
|
+
skills?: Skill[];
|
|
11
|
+
}
|
|
12
|
+
export declare class PlannerAgent implements Agent {
|
|
13
|
+
readonly id = "planner_agent";
|
|
14
|
+
readonly name = "Planner Agent";
|
|
15
|
+
readonly description = "Generates plans for tasks.";
|
|
16
|
+
readonly instructions = "You are a planning assistant. Your job is to create a plan for the given task.";
|
|
17
|
+
readonly model: LlmModel;
|
|
18
|
+
readonly tools?: Tool[];
|
|
19
|
+
readonly skills?: Skill[];
|
|
20
|
+
private streamId?;
|
|
21
|
+
private history;
|
|
22
|
+
private abortController?;
|
|
23
|
+
constructor(options: PlannerAgentOptions);
|
|
24
|
+
run(userInput: UserInput): AsyncGenerator<AgentEvent, void, unknown>;
|
|
25
|
+
private createEvent;
|
|
26
|
+
getHistory(): AgentEvent[];
|
|
27
|
+
abort(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { AgentEventType } from "../agent_event.js";
|
|
3
|
+
import {} from "../../user_input.js";
|
|
4
|
+
import { buildLlmRequest } from "../../model/request_builder_utils.js";
|
|
5
|
+
import { llmResponseToAgentEvents } from "../agent_event_utils.js";
|
|
6
|
+
import * as fs from "node:fs/promises";
|
|
7
|
+
import * as os from "node:os";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
export class PlannerAgent {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.id = "planner_agent";
|
|
12
|
+
this.name = "Planner Agent";
|
|
13
|
+
this.description = "Generates plans for tasks.";
|
|
14
|
+
this.instructions = "You are a planning assistant. Your job is to create a plan for the given task.";
|
|
15
|
+
this.history = [];
|
|
16
|
+
this.model = options.model;
|
|
17
|
+
this.tools = options.tools;
|
|
18
|
+
this.skills = options.skills;
|
|
19
|
+
}
|
|
20
|
+
async *run(userInput) {
|
|
21
|
+
this.abortController = new AbortController();
|
|
22
|
+
this.streamId = randomUUID();
|
|
23
|
+
yield this.createEvent(AgentEventType.START);
|
|
24
|
+
const task = typeof userInput === "string" ? userInput : JSON.stringify(userInput);
|
|
25
|
+
const planningPrompt = `Generate a plan for the following task: "${task}".
|
|
26
|
+
The plan should be in free-form markdown.
|
|
27
|
+
Respond ONLY with the plan.`;
|
|
28
|
+
const llmRequest = buildLlmRequest({
|
|
29
|
+
agentName: this.name,
|
|
30
|
+
content: {
|
|
31
|
+
role: "user",
|
|
32
|
+
parts: [{ type: "text", text: planningPrompt }],
|
|
33
|
+
},
|
|
34
|
+
historyContent: [],
|
|
35
|
+
tools: this.tools || [],
|
|
36
|
+
skills: this.skills,
|
|
37
|
+
description: this.description,
|
|
38
|
+
instructions: this.instructions,
|
|
39
|
+
});
|
|
40
|
+
let planContent = "";
|
|
41
|
+
for await (const modelResponse of this.model.run(llmRequest, {
|
|
42
|
+
stream: true,
|
|
43
|
+
abortSignal: this.abortController?.signal,
|
|
44
|
+
})) {
|
|
45
|
+
for (const agentEvent of llmResponseToAgentEvents(modelResponse)) {
|
|
46
|
+
yield this.createEvent(agentEvent.type, agentEvent);
|
|
47
|
+
if (agentEvent.type === AgentEventType.MESSAGE && agentEvent.parts) {
|
|
48
|
+
for (const part of agentEvent.parts) {
|
|
49
|
+
if ("text" in part && part.text) {
|
|
50
|
+
planContent += part.text;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const requestId = randomUUID();
|
|
57
|
+
const tempFilePath = path.join(os.tmpdir(), `plan_${requestId}.md`);
|
|
58
|
+
try {
|
|
59
|
+
await fs.writeFile(tempFilePath, planContent, "utf-8");
|
|
60
|
+
yield this.createEvent(AgentEventType.MESSAGE, {
|
|
61
|
+
role: "agent",
|
|
62
|
+
parts: [{ type: "text", text: `\nPlan written to ${tempFilePath}` }],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
yield this.createEvent(AgentEventType.MESSAGE, {
|
|
67
|
+
role: "agent",
|
|
68
|
+
parts: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: `\nFailed to write plan to ${tempFilePath}: ${error.message}`,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
yield this.createEvent(AgentEventType.USER_INPUT_REQUEST, {
|
|
77
|
+
role: "agent",
|
|
78
|
+
requestId,
|
|
79
|
+
message: "Do you approve this plan?",
|
|
80
|
+
requestSchema: { type: "plan_approval", planFilePath: tempFilePath },
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
createEvent(type, data = {}) {
|
|
85
|
+
const event = {
|
|
86
|
+
type,
|
|
87
|
+
id: randomUUID(),
|
|
88
|
+
streamId: this.streamId,
|
|
89
|
+
timestamp: new Date().toISOString(),
|
|
90
|
+
...data,
|
|
91
|
+
};
|
|
92
|
+
this.history.push(event);
|
|
93
|
+
return event;
|
|
94
|
+
}
|
|
95
|
+
getHistory() {
|
|
96
|
+
return [...this.history];
|
|
97
|
+
}
|
|
98
|
+
async abort() {
|
|
99
|
+
this.abortController?.abort();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=planner_agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner_agent.js","sourceRoot":"","sources":["../../../src/agent/planner_agent/planner_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,EAAmB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAkB,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAQlC,MAAM,OAAO,YAAY;IAcvB,YAAY,OAA4B;QAb/B,OAAE,GAAG,eAAe,CAAC;QACrB,SAAI,GAAG,eAAe,CAAC;QACvB,gBAAW,GAAG,4BAA4B,CAAC;QAC3C,iBAAY,GACnB,gFAAgF,CAAC;QAM3E,YAAO,GAAiB,EAAE,CAAC;QAIjC,IAAI,CAAC,KAA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,EAAE,OAAO;YACb,SAAS;YACT,OAAO,EAAE,2BAA2B;YACpC,aAAa,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE;SACrE,CAAC,CAAC;QAEH,OAAO;IACT,CAAC;IAEO,WAAW,CACjB,IAAoB,EACpB,OAA4B,EAAE;QAE9B,MAAM,KAAK,GAAG;YACZ,IAAI;YACJ,EAAE,EAAE,UAAU,EAAE;YAChB,QAAQ,EAAE,IAAI,CAAC,QAAS;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,GAAG,IAAI;SACM,CAAC;QAChB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RequestProcessor, AgentState } from "./request_processor.js";
|
|
2
|
+
import type { Tool } from "../../tools/tool.js";
|
|
3
|
+
import type { Skill } from "../../skills/skill.js";
|
|
4
|
+
import type { ThinkingConfig } from "../../model/request.js";
|
|
5
|
+
export interface BasicRequestProcessorOptions {
|
|
6
|
+
agentName: string;
|
|
7
|
+
description: string;
|
|
8
|
+
instructions: string;
|
|
9
|
+
tools: Tool[];
|
|
10
|
+
skills?: Skill[];
|
|
11
|
+
thinkingConfig?: ThinkingConfig;
|
|
12
|
+
}
|
|
13
|
+
export declare class BasicRequestProcessor implements RequestProcessor {
|
|
14
|
+
private options;
|
|
15
|
+
constructor(options: BasicRequestProcessorOptions);
|
|
16
|
+
process(state: AgentState): Promise<AgentState>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { buildLlmRequest } from "../../model/request_builder_utils.js";
|
|
2
|
+
export class BasicRequestProcessor {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
}
|
|
6
|
+
async process(state) {
|
|
7
|
+
if (state.historyContent.length === 0) {
|
|
8
|
+
return state;
|
|
9
|
+
}
|
|
10
|
+
const lastContent = state.historyContent[state.historyContent.length - 1];
|
|
11
|
+
const historyForRequest = state.historyContent.slice(0, -1);
|
|
12
|
+
const llmRequest = buildLlmRequest({
|
|
13
|
+
agentName: this.options.agentName,
|
|
14
|
+
content: lastContent,
|
|
15
|
+
historyContent: historyForRequest,
|
|
16
|
+
tools: this.options.tools,
|
|
17
|
+
skills: this.options.skills,
|
|
18
|
+
description: this.options.description,
|
|
19
|
+
instructions: this.options.instructions,
|
|
20
|
+
thinkingConfig: this.options.thinkingConfig,
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
llmRequest,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=basic_request_processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic_request_processor.js","sourceRoot":"","sources":["../../../src/agent/request_processor/basic_request_processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAcvE,MAAM,OAAO,qBAAqB;IAChC,YAAoB,OAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;IAAG,CAAC;IAE7D,KAAK,CAAC,OAAO,CAAC,KAAiB;QAC7B,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC1E,MAAM,iBAAiB,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAE5D,MAAM,UAAU,GAAG,eAAe,CAAC;YACjC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;YACjC,OAAO,EAAE,WAAW;YACpB,cAAc,EAAE,iBAAiB;YACjC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;YACzB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;YAC3B,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;YACrC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;YACvC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;SAC5C,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,KAAK;YACR,UAAU;SACX,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RequestProcessor, AgentState } from "./request_processor.js";
|
|
2
|
+
import type { LlmModel } from "../../model/model.js";
|
|
3
|
+
import type { CompactionConfig } from "../../config/config.js";
|
|
4
|
+
import type { BasicRequestProcessorOptions } from "./basic_request_processor.js";
|
|
5
|
+
export interface CompactionProcessorOptions {
|
|
6
|
+
model: LlmModel;
|
|
7
|
+
compactionConfig?: CompactionConfig;
|
|
8
|
+
requestBuilderOptions: BasicRequestProcessorOptions;
|
|
9
|
+
streamId: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class CompactionProcessor implements RequestProcessor {
|
|
12
|
+
private options;
|
|
13
|
+
constructor(options: CompactionProcessorOptions);
|
|
14
|
+
process(state: AgentState): Promise<AgentState>;
|
|
15
|
+
private rebuildRequest;
|
|
16
|
+
private createEvent;
|
|
17
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { buildLlmRequest } from "../../model/request_builder_utils.js";
|
|
2
|
+
import { logger } from "../../logger.js";
|
|
3
|
+
import { AgentEventType, } from "../agent_event.js";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { UtilLlm } from "../../model/util_llm.js";
|
|
6
|
+
export class CompactionProcessor {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
async process(state) {
|
|
11
|
+
const { compactionConfig, model, streamId } = this.options;
|
|
12
|
+
if (!compactionConfig?.enabled || !state.llmRequest) {
|
|
13
|
+
return state;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const tokenCount = await model.countTokens(state.llmRequest);
|
|
17
|
+
logger.debug(`[CompactionProcessor] Current token count: ${tokenCount}`);
|
|
18
|
+
const maxTokens = compactionConfig.maxTokens;
|
|
19
|
+
const threshold = compactionConfig.triggerThreshold || 0.8;
|
|
20
|
+
if (tokenCount > maxTokens * threshold) {
|
|
21
|
+
logger.info(`[CompactionProcessor] Token count ${tokenCount} exceeds threshold ${maxTokens * threshold}. Triggering compaction.`);
|
|
22
|
+
let newHistoryContent = [...state.historyContent];
|
|
23
|
+
let events = [...state.events];
|
|
24
|
+
if (compactionConfig.strategy === "truncate") {
|
|
25
|
+
const historyLength = newHistoryContent.length;
|
|
26
|
+
if (historyLength > 2) {
|
|
27
|
+
const removeCount = Math.ceil((historyLength - 1) * 0.2);
|
|
28
|
+
logger.info(`[CompactionProcessor] Truncating oldest ${removeCount} messages from history.`);
|
|
29
|
+
newHistoryContent.splice(0, removeCount);
|
|
30
|
+
events.push(this.createEvent(AgentEventType.COMPACTION, streamId, {
|
|
31
|
+
role: "agent",
|
|
32
|
+
strategy: "truncate",
|
|
33
|
+
parts: [
|
|
34
|
+
{
|
|
35
|
+
type: "text",
|
|
36
|
+
text: `[System: Context compacted to save tokens. Removed ${removeCount} older messages.]`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}));
|
|
40
|
+
// Rebuild request
|
|
41
|
+
const llmRequest = this.rebuildRequest(newHistoryContent);
|
|
42
|
+
return {
|
|
43
|
+
historyContent: newHistoryContent,
|
|
44
|
+
llmRequest,
|
|
45
|
+
events,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (compactionConfig.strategy === "summarize") {
|
|
50
|
+
logger.info(`[CompactionProcessor] Compacting history using UtilLlm.`);
|
|
51
|
+
const utilLlm = new UtilLlm(model);
|
|
52
|
+
try {
|
|
53
|
+
const summary = await utilLlm.compactHistory(newHistoryContent);
|
|
54
|
+
newHistoryContent = [
|
|
55
|
+
{
|
|
56
|
+
role: "agent",
|
|
57
|
+
parts: [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: `Summary of previous conversation:\n${summary}`,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
events.push(this.createEvent(AgentEventType.COMPACTION, streamId, {
|
|
66
|
+
role: "agent",
|
|
67
|
+
strategy: "summarize",
|
|
68
|
+
parts: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: `[System: Context compacted using LLM summarization.]`,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
}));
|
|
75
|
+
// Rebuild request
|
|
76
|
+
const llmRequest = this.rebuildRequest(newHistoryContent);
|
|
77
|
+
return {
|
|
78
|
+
historyContent: newHistoryContent,
|
|
79
|
+
llmRequest,
|
|
80
|
+
events,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger.error(`[CompactionProcessor] Compaction failed: ${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
logger.error(`[CompactionProcessor] Failed to count tokens or compact context: ${error.message}`);
|
|
91
|
+
}
|
|
92
|
+
return state;
|
|
93
|
+
}
|
|
94
|
+
rebuildRequest(historyContent) {
|
|
95
|
+
const lastContent = historyContent[historyContent.length - 1];
|
|
96
|
+
const historyForRequest = historyContent.slice(0, -1);
|
|
97
|
+
return buildLlmRequest({
|
|
98
|
+
agentName: this.options.requestBuilderOptions.agentName,
|
|
99
|
+
content: lastContent,
|
|
100
|
+
historyContent: historyForRequest,
|
|
101
|
+
tools: this.options.requestBuilderOptions.tools,
|
|
102
|
+
skills: this.options.requestBuilderOptions.skills,
|
|
103
|
+
description: this.options.requestBuilderOptions.description,
|
|
104
|
+
instructions: this.options.requestBuilderOptions.instructions,
|
|
105
|
+
thinkingConfig: this.options.requestBuilderOptions.thinkingConfig,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
createEvent(type, streamId, data = {}) {
|
|
109
|
+
return {
|
|
110
|
+
type,
|
|
111
|
+
id: randomUUID(),
|
|
112
|
+
streamId,
|
|
113
|
+
timestamp: new Date().toISOString(),
|
|
114
|
+
...data,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=compaction_processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction_processor.js","sourceRoot":"","sources":["../../../src/agent/request_processor/compaction_processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EACL,cAAc,GAGf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAUlD,MAAM,OAAO,mBAAmB;IAC9B,YAAoB,OAAmC;QAAnC,YAAO,GAAP,OAAO,CAA4B;IAAG,CAAC;IAE3D,KAAK,CAAC,OAAO,CAAC,KAAiB;QAC7B,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAE3D,IAAI,CAAC,gBAAgB,EAAE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YACpD,OAAO,KAAK,CAA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AAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CACV,oEAAoE,KAAK,CAAC,OAAO,EAAE,CACpF,CAAC;QACJ,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,cAAc,CAAC,cAAyB;QAC9C,MAAM,WAAW,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9D,MAAM,iBAAiB,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACtD,OAAO,eAAe,CAAC;YACrB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,SAAS;YACvD,OAAO,EAAE,WAAW;YACpB,cAAc,EAAE,iBAAiB;YACjC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,KAAK;YAC/C,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,MAAM;YACjD,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,WAAW;YAC3D,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,YAAY;YAC7D,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,cAAc;SAClE,CAAC,CAAC;IACL,CAAC;IAEO,WAAW,CACjB,IAAoB,EACpB,QAAgB,EAChB,OAA4B,EAAE;QAE9B,OAAO;YACL,IAAI;YACJ,EAAE,EAAE,UAAU,EAAE;YAChB,QAAQ;YACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,GAAG,IAAI;SACM,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Content } from "../../content.js";
|
|
2
|
+
import type { LlmRequest } from "../../model/request.js";
|
|
3
|
+
import type { AgentEvent } from "../agent_event.js";
|
|
4
|
+
export interface AgentState {
|
|
5
|
+
historyContent: Content[];
|
|
6
|
+
llmRequest?: LlmRequest;
|
|
7
|
+
events: AgentEvent[];
|
|
8
|
+
}
|
|
9
|
+
export interface RequestProcessor {
|
|
10
|
+
process(state: AgentState): Promise<AgentState>;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request_processor.js","sourceRoot":"","sources":["../../../src/agent/request_processor/request_processor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import * as crypto from "node:crypto";
|
|
4
|
+
import { configStore } from "../config/config_store.js";
|
|
5
|
+
import { loadConfig } from "../config/config_loader.js";
|
|
6
|
+
import { UtilLlm } from "../model/util_llm.js";
|
|
7
|
+
import { resolveLlmModel } from "../model/registry.js";
|
|
8
|
+
export class InitProjectCommandHandler {
|
|
9
|
+
async handle() {
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const projectId = crypto.createHash("sha256").update(cwd).digest("hex");
|
|
12
|
+
console.log(`Initializing project in ${cwd}`);
|
|
13
|
+
console.log(`Project ID: ${projectId}`);
|
|
14
|
+
// Gather context
|
|
15
|
+
let context = `Project Path: ${cwd}\n\n`;
|
|
16
|
+
// List top level files and dirs
|
|
17
|
+
try {
|
|
18
|
+
const files = await fs.readdir(cwd);
|
|
19
|
+
context += `Top level files and directories:\n${files.join("\n")}\n\n`;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.error("Failed to read directory:", e);
|
|
23
|
+
}
|
|
24
|
+
// Read package.json if exists
|
|
25
|
+
const packageJsonPath = path.join(cwd, "package.json");
|
|
26
|
+
try {
|
|
27
|
+
const packageJson = await fs.readFile(packageJsonPath, "utf-8");
|
|
28
|
+
context += `package.json:\n${packageJson}\n\n`;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// Ignore if doesn't exist
|
|
32
|
+
}
|
|
33
|
+
// Read tsconfig.json if exists
|
|
34
|
+
const tsconfigPath = path.join(cwd, "tsconfig.json");
|
|
35
|
+
try {
|
|
36
|
+
const tsconfig = await fs.readFile(tsconfigPath, "utf-8");
|
|
37
|
+
context += `tsconfig.json:\n${tsconfig}\n\n`;
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
// Ignore if doesn't exist
|
|
41
|
+
}
|
|
42
|
+
// Load config for UtilLlm
|
|
43
|
+
const config = await loadConfig();
|
|
44
|
+
const utilModelConfig = config.models.util;
|
|
45
|
+
if (!utilModelConfig) {
|
|
46
|
+
throw new Error("Util model config is missing");
|
|
47
|
+
}
|
|
48
|
+
const UtilModelClass = resolveLlmModel(utilModelConfig.modelName);
|
|
49
|
+
const utilLlm = new UtilLlm(new UtilModelClass(utilModelConfig));
|
|
50
|
+
console.log("Scanning project constants with LLM...");
|
|
51
|
+
const constants = await utilLlm.scanProjectConstants(context);
|
|
52
|
+
console.log("Saving constants...");
|
|
53
|
+
const filename = `projects/${projectId}/constants.json`;
|
|
54
|
+
await configStore.set(filename, JSON.stringify(constants, null, 2));
|
|
55
|
+
console.log(`Project constants saved to ${filename} in config store.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=init_project_command_handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init_project_command_handler.js","sourceRoot":"","sources":["../../src/cli/init_project_command_handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;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