@kkeve/suite 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.
Files changed (63) hide show
  1. package/dist/agent/factory.d.ts +25 -0
  2. package/dist/agent/factory.js +99 -0
  3. package/dist/agent/index.d.ts +3 -0
  4. package/dist/agent/index.js +7 -0
  5. package/dist/agent/loader.d.ts +22 -0
  6. package/dist/agent/loader.js +117 -0
  7. package/dist/agent/types.d.ts +9 -0
  8. package/dist/agent/types.js +2 -0
  9. package/dist/agent-loop/complete-task.d.ts +28 -0
  10. package/dist/agent-loop/complete-task.js +70 -0
  11. package/dist/agent-loop/index.d.ts +16 -0
  12. package/dist/agent-loop/index.js +26 -0
  13. package/dist/agent-loop/loop.d.ts +42 -0
  14. package/dist/agent-loop/loop.js +282 -0
  15. package/dist/agent-loop/runtime.d.ts +40 -0
  16. package/dist/agent-loop/runtime.js +163 -0
  17. package/dist/agent-loop/types.d.ts +161 -0
  18. package/dist/agent-loop/types.js +105 -0
  19. package/dist/context/index.d.ts +8 -0
  20. package/dist/context/index.js +29 -0
  21. package/dist/context/tokenCalculation.d.ts +55 -0
  22. package/dist/context/tokenCalculation.js +95 -0
  23. package/dist/context/truncation.d.ts +67 -0
  24. package/dist/context/truncation.js +142 -0
  25. package/dist/context/types.d.ts +7 -0
  26. package/dist/context/types.js +27 -0
  27. package/dist/index.d.ts +23 -0
  28. package/dist/index.js +45 -0
  29. package/dist/llm/OpenAIClient.d.ts +31 -0
  30. package/dist/llm/OpenAIClient.js +455 -0
  31. package/dist/llm/constants.d.ts +2 -0
  32. package/dist/llm/constants.js +6 -0
  33. package/dist/llm/errors.d.ts +25 -0
  34. package/dist/llm/errors.js +51 -0
  35. package/dist/llm/index.d.ts +49 -0
  36. package/dist/llm/index.js +158 -0
  37. package/dist/llm/types.d.ts +124 -0
  38. package/dist/llm/types.js +2 -0
  39. package/dist/llm/utils.d.ts +29 -0
  40. package/dist/llm/utils.js +284 -0
  41. package/dist/skill/frontmatter-parser.d.ts +50 -0
  42. package/dist/skill/frontmatter-parser.js +152 -0
  43. package/dist/skill/index.d.ts +12 -0
  44. package/dist/skill/index.js +17 -0
  45. package/dist/skill/loader.d.ts +96 -0
  46. package/dist/skill/loader.js +256 -0
  47. package/dist/tools/ask-user.d.ts +8 -0
  48. package/dist/tools/ask-user.js +47 -0
  49. package/dist/tools/bash.d.ts +47 -0
  50. package/dist/tools/bash.js +213 -0
  51. package/dist/tools/edit-file.d.ts +9 -0
  52. package/dist/tools/edit-file.js +76 -0
  53. package/dist/tools/glob.d.ts +8 -0
  54. package/dist/tools/glob.js +101 -0
  55. package/dist/tools/grep.d.ts +10 -0
  56. package/dist/tools/grep.js +76 -0
  57. package/dist/tools/index.d.ts +24 -0
  58. package/dist/tools/index.js +47 -0
  59. package/dist/tools/read-files.d.ts +8 -0
  60. package/dist/tools/read-files.js +81 -0
  61. package/dist/tools/write-file.d.ts +8 -0
  62. package/dist/tools/write-file.js +63 -0
  63. package/package.json +59 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * AgentFactory — creates execution resources for AgentLoop
3
+ *
4
+ * - Creates LLM, ToolRegistry, RuntimeEnvironment
5
+ * - Provides AgentLoader for agent discovery
6
+ * - Creates sub-agent ToolRegistry with configurable allowed/blocked tools
7
+ */
8
+ import type { LLMConfig } from '../llm/types';
9
+ import type { RuntimeEnvironment } from '../agent-loop/runtime';
10
+ import { ToolRegistry } from '../agent-loop/types';
11
+ import { LLM } from '../llm/index';
12
+ import { AgentLoader } from './loader';
13
+ export declare class AgentFactory {
14
+ private llm;
15
+ private runtime;
16
+ private toolRegistry;
17
+ private agentLoader;
18
+ constructor(llmConfig: LLMConfig, workspaceDir?: string);
19
+ init(agentsDir: string): Promise<void>;
20
+ getLLM(): LLM;
21
+ getToolRegistry(): ToolRegistry;
22
+ getRuntime(): RuntimeEnvironment;
23
+ getAgentLoader(): AgentLoader;
24
+ createSubAgentToolRegistry(allowedTools?: string[], blockedTools?: string[]): ToolRegistry;
25
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * AgentFactory — creates execution resources for AgentLoop
4
+ *
5
+ * - Creates LLM, ToolRegistry, RuntimeEnvironment
6
+ * - Provides AgentLoader for agent discovery
7
+ * - Creates sub-agent ToolRegistry with configurable allowed/blocked tools
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.AgentFactory = void 0;
44
+ const path = __importStar(require("node:path"));
45
+ const types_1 = require("../agent-loop/types");
46
+ const index_1 = require("../llm/index");
47
+ const runtime_1 = require("../agent-loop/runtime");
48
+ const index_2 = require("../tools/index");
49
+ const loader_1 = require("./loader");
50
+ class AgentFactory {
51
+ llm;
52
+ runtime;
53
+ toolRegistry;
54
+ agentLoader;
55
+ constructor(llmConfig, workspaceDir) {
56
+ this.llm = new index_1.LLM({
57
+ ...llmConfig,
58
+ baseURL: llmConfig.baseURL || process.env.LLM_BASE_URL || '',
59
+ model: llmConfig.model || process.env.LLM_MODEL_NAME || process.env.LLM_MODEL || '',
60
+ apiKey: llmConfig.apiKey || process.env.LLM_API_KEY || '',
61
+ });
62
+ this.runtime = (0, runtime_1.detectRuntimeEnvironment)(process.cwd(), workspaceDir || path.join(process.cwd(), 'workspace'));
63
+ this.toolRegistry = (0, index_2.createDefaultToolRegistry)(this.runtime);
64
+ }
65
+ async init(agentsDir) {
66
+ this.agentLoader = new loader_1.AgentLoader(agentsDir);
67
+ await this.agentLoader.discover();
68
+ }
69
+ getLLM() {
70
+ return this.llm;
71
+ }
72
+ getToolRegistry() {
73
+ return this.toolRegistry;
74
+ }
75
+ getRuntime() {
76
+ return this.runtime;
77
+ }
78
+ getAgentLoader() {
79
+ return this.agentLoader;
80
+ }
81
+ createSubAgentToolRegistry(allowedTools, blockedTools) {
82
+ const subRegistry = new types_1.ToolRegistry();
83
+ const toolFilter = (allowedTools && allowedTools.length > 0)
84
+ ? new Set(allowedTools)
85
+ : null;
86
+ const blocked = new Set(blockedTools ?? []);
87
+ for (const name of this.toolRegistry.getAllToolNames()) {
88
+ if (blocked.has(name))
89
+ continue;
90
+ if (toolFilter && !toolFilter.has(name))
91
+ continue;
92
+ const tool = this.toolRegistry.get(name);
93
+ if (tool)
94
+ subRegistry.register(tool);
95
+ }
96
+ return subRegistry;
97
+ }
98
+ }
99
+ exports.AgentFactory = AgentFactory;
@@ -0,0 +1,3 @@
1
+ export { AgentLoader } from './loader';
2
+ export { AgentFactory } from './factory';
3
+ export type { AgentRegistryDefinition } from './types';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentFactory = exports.AgentLoader = void 0;
4
+ var loader_1 = require("./loader");
5
+ Object.defineProperty(exports, "AgentLoader", { enumerable: true, get: function () { return loader_1.AgentLoader; } });
6
+ var factory_1 = require("./factory");
7
+ Object.defineProperty(exports, "AgentFactory", { enumerable: true, get: function () { return factory_1.AgentFactory; } });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * AgentLoader — discovers and loads .md agent definitions from a directory
3
+ *
4
+ * Mirrors SkillLoader pattern (instance-based, no singleton).
5
+ * Each .md file uses YAML frontmatter (same as SKILL.md) to define agent metadata.
6
+ */
7
+ import type { AgentRegistryDefinition } from './types';
8
+ export declare class AgentLoader {
9
+ private agentsDir;
10
+ private agents;
11
+ constructor(agentsDir: string);
12
+ discover(): Promise<void>;
13
+ get(name: string): AgentRegistryDefinition | undefined;
14
+ has(name: string): boolean;
15
+ getAll(): Map<string, AgentRegistryDefinition>;
16
+ listAvailable(): Array<{
17
+ name: string;
18
+ description: string;
19
+ outputType?: string;
20
+ }>;
21
+ reset(): void;
22
+ }
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ /**
3
+ * AgentLoader — discovers and loads .md agent definitions from a directory
4
+ *
5
+ * Mirrors SkillLoader pattern (instance-based, no singleton).
6
+ * Each .md file uses YAML frontmatter (same as SKILL.md) to define agent metadata.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.AgentLoader = void 0;
43
+ const fs = __importStar(require("node:fs/promises"));
44
+ const path = __importStar(require("node:path"));
45
+ const glob_1 = require("glob");
46
+ const frontmatter_parser_1 = require("../skill/frontmatter-parser");
47
+ class AgentLoader {
48
+ agentsDir;
49
+ agents = new Map();
50
+ constructor(agentsDir) {
51
+ this.agentsDir = agentsDir;
52
+ }
53
+ async discover() {
54
+ const absoluteDir = path.resolve(this.agentsDir);
55
+ try {
56
+ const stats = await fs.stat(absoluteDir).catch(() => null);
57
+ if (!stats || !stats.isDirectory()) {
58
+ console.warn(`[AgentLoader] Agents directory not found: ${absoluteDir}`);
59
+ return;
60
+ }
61
+ const agentFiles = await (0, glob_1.glob)('*.md', {
62
+ cwd: absoluteDir,
63
+ absolute: true,
64
+ nodir: true,
65
+ });
66
+ for (const agentFile of agentFiles) {
67
+ try {
68
+ const content = await fs.readFile(agentFile, 'utf-8');
69
+ const parsed = (0, frontmatter_parser_1.parseSkillFrontmatter)(content);
70
+ if (!parsed || !parsed.name) {
71
+ console.warn(`[AgentLoader] Invalid agent file: ${agentFile}`);
72
+ continue;
73
+ }
74
+ const tools = parsed.allowedTools ?? [];
75
+ const agent = {
76
+ name: parsed.name,
77
+ description: parsed.description,
78
+ tools,
79
+ outputType: parsed.outputType,
80
+ model: undefined,
81
+ prompt: parsed.body,
82
+ location: agentFile,
83
+ };
84
+ this.agents.set(parsed.name, agent);
85
+ console.log(`[AgentLoader] Loaded agent: "${parsed.name}" (tools: ${tools.join(', ')}, outputType: ${parsed.outputType ?? 'N/A'})`);
86
+ }
87
+ catch (err) {
88
+ console.warn(`[AgentLoader] Failed to load ${agentFile}: ${err.message}`);
89
+ }
90
+ }
91
+ console.log(`[AgentLoader] Total agents: ${this.agents.size}`);
92
+ }
93
+ catch (err) {
94
+ console.warn(`[AgentLoader] Error discovering agents: ${err.message}`);
95
+ }
96
+ }
97
+ get(name) {
98
+ return this.agents.get(name);
99
+ }
100
+ has(name) {
101
+ return this.agents.has(name);
102
+ }
103
+ getAll() {
104
+ return this.agents;
105
+ }
106
+ listAvailable() {
107
+ return Array.from(this.agents.values()).map(a => ({
108
+ name: a.name,
109
+ description: a.description,
110
+ outputType: a.outputType,
111
+ }));
112
+ }
113
+ reset() {
114
+ this.agents.clear();
115
+ }
116
+ }
117
+ exports.AgentLoader = AgentLoader;
@@ -0,0 +1,9 @@
1
+ export interface AgentRegistryDefinition {
2
+ name: string;
3
+ description: string;
4
+ tools: string[];
5
+ outputType?: string;
6
+ model?: string;
7
+ prompt: string;
8
+ location: string;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Complete Task Tool — signals that the agent has finished its task.
3
+ *
4
+ * Reference: gemini-cli CompleteTaskTool (tools/complete-task.ts)
5
+ *
6
+ * This tool is automatically registered in every agent loop execution.
7
+ * When the LLM calls this tool, the agent loop terminates with GOAL mode.
8
+ *
9
+ * The `result` parameter can be either:
10
+ * - A structured JSON object (when the agent has a defined output schema)
11
+ * - A plain string summary (for conversational tasks)
12
+ */
13
+ import { z } from 'zod/v4';
14
+ import type { ToolDefinition } from './types';
15
+ export interface CompleteTaskToolOptions {
16
+ outputHint?: string;
17
+ }
18
+ export declare const CompleteTaskSchema: z.ZodObject<{
19
+ result: z.ZodAny;
20
+ _result: z.ZodOptional<z.ZodEnum<{
21
+ PASSED: "PASSED";
22
+ FAILED: "FAILED";
23
+ BLOCKED: "BLOCKED";
24
+ }>>;
25
+ _summary: z.ZodOptional<z.ZodString>;
26
+ _blockedReason: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strip>;
28
+ export declare function createCompleteTaskTool(options?: CompleteTaskToolOptions): ToolDefinition;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Complete Task Tool — signals that the agent has finished its task.
4
+ *
5
+ * Reference: gemini-cli CompleteTaskTool (tools/complete-task.ts)
6
+ *
7
+ * This tool is automatically registered in every agent loop execution.
8
+ * When the LLM calls this tool, the agent loop terminates with GOAL mode.
9
+ *
10
+ * The `result` parameter can be either:
11
+ * - A structured JSON object (when the agent has a defined output schema)
12
+ * - A plain string summary (for conversational tasks)
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CompleteTaskSchema = void 0;
16
+ exports.createCompleteTaskTool = createCompleteTaskTool;
17
+ const v4_1 = require("zod/v4");
18
+ const types_1 = require("./types");
19
+ exports.CompleteTaskSchema = v4_1.z.object({
20
+ result: v4_1.z.any().describe('Your final result. You can provide either a structured JSON object or a text summary. ' +
21
+ 'This is the ONLY way to finish the task — call this tool when you are done.'),
22
+ _result: v4_1.z.enum(['PASSED', 'FAILED', 'BLOCKED']).optional().describe('Execution result. "PASSED" = task completed successfully. ' +
23
+ '"FAILED" = task failed (e.g. tests did not pass). ' +
24
+ '"BLOCKED" = unresolved items prevent downstream steps from proceeding safely. ' +
25
+ 'Use "BLOCKED" when critical information is missing and proceeding would produce unreliable results.'),
26
+ _summary: v4_1.z.string().optional().describe('Brief human-readable summary of the result (1-2 sentences). Used by the orchestrator to display progress. ' +
27
+ 'If omitted, the orchestrator will derive a summary from the result object.'),
28
+ _blockedReason: v4_1.z.string().optional().describe('Reason for blocking. Required when _result is "BLOCKED". ' +
29
+ 'Describe what information is missing and what needs to be confirmed before proceeding.'),
30
+ });
31
+ function createCompleteTaskTool(options) {
32
+ const hint = options?.outputHint;
33
+ const baseDescription = 'Call this tool to submit your final result and complete the task. ' +
34
+ 'This is the ONLY way to finish. You MUST call this tool when you ' +
35
+ 'have completed your work.';
36
+ const description = hint
37
+ ? baseDescription + '\n\n' + hint
38
+ : baseDescription;
39
+ const structuredDesc = hint
40
+ ? 'Structured JSON result. ' + hint
41
+ : 'Structured JSON result with key fields matching the expected output schema.';
42
+ return {
43
+ name: types_1.COMPLETE_TASK_TOOL_NAME,
44
+ description,
45
+ inputSchema: exports.CompleteTaskSchema,
46
+ execute: async (args) => {
47
+ const result = typeof args.result === 'string' ? args.result : args.result;
48
+ return { result, taskCompleted: true };
49
+ },
50
+ customJsonSchema: {
51
+ type: 'object',
52
+ properties: {
53
+ result: {
54
+ oneOf: [
55
+ {
56
+ type: 'object',
57
+ description: structuredDesc,
58
+ },
59
+ {
60
+ type: 'string',
61
+ description: 'Plain text summary of what you accomplished.',
62
+ },
63
+ ],
64
+ description: 'Your final result. Provide structured JSON when a schema is defined, or a text summary otherwise.',
65
+ },
66
+ },
67
+ required: ['result'],
68
+ },
69
+ };
70
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Agent Loop module — universal agent execution engine
3
+ *
4
+ * Provides the core agent loop runtime that executes an AgentDefinition
5
+ * by calling the LLM in a while loop, processing tool_calls, and
6
+ * terminating when complete_task is called or limits are reached.
7
+ *
8
+ * Reference: gemini-cli LocalAgentExecutor (agents/local-executor.ts)
9
+ */
10
+ export { AgentLoop } from './loop';
11
+ export { createCompleteTaskTool, CompleteTaskSchema } from './complete-task';
12
+ export type { CompleteTaskToolOptions } from './complete-task';
13
+ export type { AgentDefinition, AgentEvent, AgentEventCallback, AgentLoopContext, AgentResult, AgentTerminateMode, ToolDefinition, ToolExecutionContext, } from './types';
14
+ export { ToolRegistry, COMPLETE_TASK_TOOL_NAME, DEFAULT_MAX_TURNS, DEFAULT_MAX_TIME_MINUTES, } from './types';
15
+ export { detectRuntimeEnvironment } from './runtime';
16
+ export type { RuntimeEnvironment } from './runtime';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * Agent Loop module — universal agent execution engine
4
+ *
5
+ * Provides the core agent loop runtime that executes an AgentDefinition
6
+ * by calling the LLM in a while loop, processing tool_calls, and
7
+ * terminating when complete_task is called or limits are reached.
8
+ *
9
+ * Reference: gemini-cli LocalAgentExecutor (agents/local-executor.ts)
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.detectRuntimeEnvironment = exports.DEFAULT_MAX_TIME_MINUTES = exports.DEFAULT_MAX_TURNS = exports.COMPLETE_TASK_TOOL_NAME = exports.ToolRegistry = exports.CompleteTaskSchema = exports.createCompleteTaskTool = exports.AgentLoop = void 0;
13
+ var loop_1 = require("./loop");
14
+ Object.defineProperty(exports, "AgentLoop", { enumerable: true, get: function () { return loop_1.AgentLoop; } });
15
+ var complete_task_1 = require("./complete-task");
16
+ Object.defineProperty(exports, "createCompleteTaskTool", { enumerable: true, get: function () { return complete_task_1.createCompleteTaskTool; } });
17
+ Object.defineProperty(exports, "CompleteTaskSchema", { enumerable: true, get: function () { return complete_task_1.CompleteTaskSchema; } });
18
+ var types_1 = require("./types");
19
+ Object.defineProperty(exports, "ToolRegistry", { enumerable: true, get: function () { return types_1.ToolRegistry; } });
20
+ // Constants
21
+ Object.defineProperty(exports, "COMPLETE_TASK_TOOL_NAME", { enumerable: true, get: function () { return types_1.COMPLETE_TASK_TOOL_NAME; } });
22
+ Object.defineProperty(exports, "DEFAULT_MAX_TURNS", { enumerable: true, get: function () { return types_1.DEFAULT_MAX_TURNS; } });
23
+ Object.defineProperty(exports, "DEFAULT_MAX_TIME_MINUTES", { enumerable: true, get: function () { return types_1.DEFAULT_MAX_TIME_MINUTES; } });
24
+ // Runtime Environment
25
+ var runtime_1 = require("./runtime");
26
+ Object.defineProperty(exports, "detectRuntimeEnvironment", { enumerable: true, get: function () { return runtime_1.detectRuntimeEnvironment; } });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Agent Loop — universal agent execution engine
3
+ *
4
+ * Reference: gemini-cli LocalAgentExecutor (agents/local-executor.ts L120-1518)
5
+ * Key adaptation: uses OpenAIClient.chat() instead of GeminiChat,
6
+ * decoupled tool execution via ToolRegistry, simplified timeout.
7
+ *
8
+ * Core loop:
9
+ * 1. Build messages (system prompt + user query)
10
+ * 2. While (!done):
11
+ * a. Check termination (max turns, timeout, abort)
12
+ * b. Call LLM via chatWithTools → get assistant message
13
+ * c. If no tool_calls → ERROR_NO_COMPLETE_TASK (or handle text-only response)
14
+ * d. For each tool_call:
15
+ * - If complete_task → done, extract result
16
+ * - Otherwise → execute via ToolRegistry → append tool response
17
+ * e. Emit events (thought_chunk, tool_call_start/end)
18
+ * 3. Return AgentResult with termination mode and output
19
+ */
20
+ import type { AgentDefinition, AgentEventCallback, AgentResult } from './types';
21
+ import { ToolRegistry } from './types';
22
+ import type { LLM } from '../llm/index';
23
+ export declare class AgentLoop {
24
+ private llm;
25
+ private toolRegistry;
26
+ constructor(llm: LLM, toolRegistry: ToolRegistry);
27
+ /**
28
+ * Execute an agent definition with the given event callback and optional abort signal.
29
+ *
30
+ * Reference: gemini-cli LocalAgentExecutor.run() (L537-566) and runInternal() (L568-730)
31
+ */
32
+ execute(definition: AgentDefinition, onEvent?: AgentEventCallback, signal?: AbortSignal): Promise<AgentResult>;
33
+ /**
34
+ * Check if the agent should terminate.
35
+ * Returns a terminate reason if termination is needed, null otherwise.
36
+ */
37
+ private checkTermination;
38
+ /**
39
+ * Emit an event to the callback, if provided.
40
+ */
41
+ private emitEvent;
42
+ }