@alexnetrebskii/hive-agent 0.28.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +9 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +163 -24
- package/dist/agent.js.map +1 -1
- package/dist/built-in-agents/explore.d.ts +9 -0
- package/dist/built-in-agents/explore.d.ts.map +1 -0
- package/dist/built-in-agents/explore.js +57 -0
- package/dist/built-in-agents/explore.js.map +1 -0
- package/dist/built-in-agents/index.d.ts +14 -0
- package/dist/built-in-agents/index.d.ts.map +1 -0
- package/dist/built-in-agents/index.js +17 -0
- package/dist/built-in-agents/index.js.map +1 -0
- package/dist/built-in-agents/plan.d.ts +10 -0
- package/dist/built-in-agents/plan.d.ts.map +1 -0
- package/dist/built-in-agents/plan.js +76 -0
- package/dist/built-in-agents/plan.js.map +1 -0
- package/dist/executor.d.ts +2 -2
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +103 -32
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/prompt/index.d.ts +2 -2
- package/dist/prompt/index.d.ts.map +1 -1
- package/dist/prompt/index.js +1 -1
- package/dist/prompt/index.js.map +1 -1
- package/dist/prompt/main-agent-builder.d.ts +5 -5
- package/dist/prompt/main-agent-builder.d.ts.map +1 -1
- package/dist/prompt/main-agent-builder.js +61 -26
- package/dist/prompt/main-agent-builder.js.map +1 -1
- package/dist/prompt/sub-agent-builder.d.ts +7 -7
- package/dist/prompt/sub-agent-builder.d.ts.map +1 -1
- package/dist/prompt/sub-agent-builder.js +35 -30
- package/dist/prompt/sub-agent-builder.js.map +1 -1
- package/dist/prompt/templates.d.ts +3 -3
- package/dist/prompt/templates.d.ts.map +1 -1
- package/dist/prompt/templates.js +13 -8
- package/dist/prompt/templates.js.map +1 -1
- package/dist/prompt/types.d.ts +5 -5
- package/dist/prompt/types.d.ts.map +1 -1
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -1
- package/dist/providers/workspace/file.d.ts +20 -0
- package/dist/providers/workspace/file.d.ts.map +1 -0
- package/dist/providers/workspace/file.js +72 -0
- package/dist/providers/workspace/file.js.map +1 -0
- package/dist/providers/workspace/index.d.ts +7 -0
- package/dist/providers/workspace/index.d.ts.map +1 -0
- package/dist/providers/workspace/index.js +6 -0
- package/dist/providers/workspace/index.js.map +1 -0
- package/dist/providers/workspace/memory.d.ts +13 -0
- package/dist/providers/workspace/memory.d.ts.map +1 -0
- package/dist/providers/workspace/memory.js +18 -0
- package/dist/providers/workspace/memory.js.map +1 -0
- package/dist/providers/workspace/types.d.ts +27 -0
- package/dist/providers/workspace/types.d.ts.map +1 -0
- package/dist/providers/workspace/types.js +8 -0
- package/dist/providers/workspace/types.js.map +1 -0
- package/dist/providers/workspace/workspace-provider.test.d.ts +2 -0
- package/dist/providers/workspace/workspace-provider.test.d.ts.map +1 -0
- package/dist/providers/workspace/workspace-provider.test.js +268 -0
- package/dist/providers/workspace/workspace-provider.test.js.map +1 -0
- package/dist/shell/commands/browse.d.ts +6 -0
- package/dist/shell/commands/browse.d.ts.map +1 -0
- package/dist/shell/commands/browse.js +163 -0
- package/dist/shell/commands/browse.js.map +1 -0
- package/dist/shell/commands/cat.d.ts +6 -0
- package/dist/shell/commands/cat.d.ts.map +1 -0
- package/dist/shell/commands/cat.js +42 -0
- package/dist/shell/commands/cat.js.map +1 -0
- package/dist/shell/commands/curl.d.ts +6 -0
- package/dist/shell/commands/curl.d.ts.map +1 -0
- package/dist/shell/commands/curl.js +113 -0
- package/dist/shell/commands/curl.js.map +1 -0
- package/dist/shell/commands/echo.d.ts +6 -0
- package/dist/shell/commands/echo.d.ts.map +1 -0
- package/dist/shell/commands/echo.js +48 -0
- package/dist/shell/commands/echo.js.map +1 -0
- package/dist/shell/commands/find.d.ts +6 -0
- package/dist/shell/commands/find.d.ts.map +1 -0
- package/dist/shell/commands/find.js +82 -0
- package/dist/shell/commands/find.js.map +1 -0
- package/dist/shell/commands/grep.d.ts +6 -0
- package/dist/shell/commands/grep.d.ts.map +1 -0
- package/dist/shell/commands/grep.js +145 -0
- package/dist/shell/commands/grep.js.map +1 -0
- package/dist/shell/commands/head.d.ts +6 -0
- package/dist/shell/commands/head.d.ts.map +1 -0
- package/dist/shell/commands/head.js +62 -0
- package/dist/shell/commands/head.js.map +1 -0
- package/dist/shell/commands/index.d.ts +19 -0
- package/dist/shell/commands/index.d.ts.map +1 -0
- package/dist/shell/commands/index.js +31 -0
- package/dist/shell/commands/index.js.map +1 -0
- package/dist/shell/commands/jq.d.ts +8 -0
- package/dist/shell/commands/jq.d.ts.map +1 -0
- package/dist/shell/commands/jq.js +233 -0
- package/dist/shell/commands/jq.js.map +1 -0
- package/dist/shell/commands/ls.d.ts +6 -0
- package/dist/shell/commands/ls.d.ts.map +1 -0
- package/dist/shell/commands/ls.js +87 -0
- package/dist/shell/commands/ls.js.map +1 -0
- package/dist/shell/commands/mkdir.d.ts +6 -0
- package/dist/shell/commands/mkdir.d.ts.map +1 -0
- package/dist/shell/commands/mkdir.js +43 -0
- package/dist/shell/commands/mkdir.js.map +1 -0
- package/dist/shell/commands/rm.d.ts +6 -0
- package/dist/shell/commands/rm.d.ts.map +1 -0
- package/dist/shell/commands/rm.js +64 -0
- package/dist/shell/commands/rm.js.map +1 -0
- package/dist/shell/commands/tail.d.ts +6 -0
- package/dist/shell/commands/tail.d.ts.map +1 -0
- package/dist/shell/commands/tail.js +62 -0
- package/dist/shell/commands/tail.js.map +1 -0
- package/dist/shell/fs.d.ts +31 -0
- package/dist/shell/fs.d.ts.map +1 -0
- package/dist/shell/fs.js +161 -0
- package/dist/shell/fs.js.map +1 -0
- package/dist/shell/index.d.ts +11 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +11 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/shell/parser.d.ts +8 -0
- package/dist/shell/parser.d.ts.map +1 -0
- package/dist/shell/parser.js +205 -0
- package/dist/shell/parser.js.map +1 -0
- package/dist/shell/shell.d.ts +57 -0
- package/dist/shell/shell.d.ts.map +1 -0
- package/dist/shell/shell.js +265 -0
- package/dist/shell/shell.js.map +1 -0
- package/dist/shell/shell.test.d.ts +2 -0
- package/dist/shell/shell.test.d.ts.map +1 -0
- package/dist/shell/shell.test.js +554 -0
- package/dist/shell/shell.test.js.map +1 -0
- package/dist/shell/types.d.ts +90 -0
- package/dist/shell/types.d.ts.map +1 -0
- package/dist/shell/types.js +5 -0
- package/dist/shell/types.js.map +1 -0
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +8 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/shell.d.ts +13 -0
- package/dist/tools/shell.d.ts.map +1 -0
- package/dist/tools/shell.js +126 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/tools/{task.d.ts → sub-agent.d.ts} +2 -2
- package/dist/tools/sub-agent.d.ts.map +1 -0
- package/dist/tools/{task.js → sub-agent.js} +22 -11
- package/dist/tools/sub-agent.js.map +1 -0
- package/dist/tools/tasks.d.ts +170 -0
- package/dist/tools/tasks.d.ts.map +1 -0
- package/dist/tools/tasks.js +1085 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/trace/builder.d.ts.map +1 -1
- package/dist/trace/builder.js +12 -0
- package/dist/trace/builder.js.map +1 -1
- package/dist/types.d.ts +83 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/{context.d.ts → workspace.d.ts} +69 -51
- package/dist/workspace.d.ts.map +1 -0
- package/dist/{context.js → workspace.js} +163 -249
- package/dist/workspace.js.map +1 -0
- package/package.json +5 -2
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/tools/task.d.ts.map +0 -1
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -73
- package/dist/tools/todo.d.ts.map +0 -1
- package/dist/tools/todo.js +0 -476
- package/dist/tools/todo.js.map +0 -1
package/dist/agent.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hive Agent
|
|
3
3
|
*
|
|
4
|
-
* Main agent class that orchestrates tool execution, sub-agents, and
|
|
4
|
+
* Main agent class that orchestrates tool execution, sub-agents, and workspace management.
|
|
5
5
|
*/
|
|
6
6
|
import type { HiveConfig, RunOptions, AgentResult } from "./types.js";
|
|
7
7
|
import { TraceBuilder } from "./trace.js";
|
|
8
|
+
/** Path where the plan is stored in workspace */
|
|
9
|
+
export declare const PLAN_PATH = ".hive/plan.md";
|
|
10
|
+
/** Full filesystem path for the plan in VirtualFS */
|
|
11
|
+
export declare const PLAN_FS_PATH = "/.hive/plan.md";
|
|
8
12
|
/**
|
|
9
13
|
* Hive Agent Class
|
|
10
14
|
*/
|
|
@@ -12,11 +16,11 @@ export declare class Hive {
|
|
|
12
16
|
readonly config: HiveConfig;
|
|
13
17
|
private contextManager;
|
|
14
18
|
private tools;
|
|
15
|
-
/** Current trace builder (set during run, used by
|
|
19
|
+
/** Current trace builder (set during run, used by __sub_agent__ tool) */
|
|
16
20
|
private currentTraceBuilder?;
|
|
17
21
|
constructor(config: HiveConfig);
|
|
18
22
|
/**
|
|
19
|
-
* Get the current trace builder (used by
|
|
23
|
+
* Get the current trace builder (used by __sub_agent__ tool for sub-agent tracing)
|
|
20
24
|
*/
|
|
21
25
|
getCurrentTraceBuilder(): TraceBuilder | undefined;
|
|
22
26
|
/**
|
|
@@ -24,7 +28,8 @@ export declare class Hive {
|
|
|
24
28
|
*/
|
|
25
29
|
setCurrentTraceBuilder(builder: TraceBuilder | undefined): void;
|
|
26
30
|
/**
|
|
27
|
-
* Get tools including internal tools for a specific run
|
|
31
|
+
* Get tools including internal tools for a specific run.
|
|
32
|
+
* In plan mode, only a restricted set of tools is returned.
|
|
28
33
|
*/
|
|
29
34
|
private getRunTools;
|
|
30
35
|
/**
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,UAAU,EAGV,UAAU,EACV,WAAW,EAEZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,UAAU,EAGV,UAAU,EACV,WAAW,EAEZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAa1C,iDAAiD;AACjD,eAAO,MAAM,SAAS,kBAAkB,CAAC;AAEzC,qDAAqD;AACrD,eAAO,MAAM,YAAY,mBAAkB,CAAC;AA4C5C;;GAEG;AACH,qBAAa,IAAI;IACf,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,KAAK,CAAS;IACtB,yEAAyE;IACzE,OAAO,CAAC,mBAAmB,CAAC,CAAe;gBAE/B,MAAM,EAAE,UAAU;IA0C9B;;OAEG;IACH,sBAAsB,IAAI,YAAY,GAAG,SAAS;IAIlD;;OAEG;IACH,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI;IAI/D;;;OAGG;IACH,OAAO,CAAC,WAAW;IA6DnB;;OAEG;IACG,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAiO3E"}
|
package/dist/agent.js
CHANGED
|
@@ -1,13 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hive Agent
|
|
3
3
|
*
|
|
4
|
-
* Main agent class that orchestrates tool execution, sub-agents, and
|
|
4
|
+
* Main agent class that orchestrates tool execution, sub-agents, and workspace management.
|
|
5
5
|
*/
|
|
6
6
|
import { ContextManager } from "./context-manager.js";
|
|
7
7
|
import { executeLoop } from "./executor.js";
|
|
8
8
|
import { TraceBuilder } from "./trace.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { Workspace } from "./workspace.js";
|
|
10
|
+
import { createShellTool } from "./tools/shell.js";
|
|
11
|
+
import { createAskUserTool, createTaskTool as createSubAgentTool, TaskManager, createTaskTools, createTaskGetTool, createTaskListTool, } from "./tools/index.js";
|
|
12
|
+
import { getBuiltInAgents } from "./built-in-agents/index.js";
|
|
13
|
+
/** Path where the plan is stored in workspace */
|
|
14
|
+
export const PLAN_PATH = ".hive/plan.md";
|
|
15
|
+
/** Full filesystem path for the plan in VirtualFS */
|
|
16
|
+
export const PLAN_FS_PATH = `/${PLAN_PATH}`;
|
|
17
|
+
/** System prompt prepended in plan mode */
|
|
18
|
+
const PLAN_MODE_INSTRUCTIONS = `# Plan Mode
|
|
19
|
+
|
|
20
|
+
You are in **plan mode**. Your job is to understand the current state, then write a plan.
|
|
21
|
+
|
|
22
|
+
## Workflow
|
|
23
|
+
|
|
24
|
+
1. **Explore first** — Use the \`explore\` sub-agent to discover what data and state currently exists. This is mandatory before writing a plan.
|
|
25
|
+
2. **Analyze** — Based on the exploration results and the user's request, determine what needs to happen.
|
|
26
|
+
3. **Write the plan** — Save your plan to \`${PLAN_FS_PATH}\` using the shell.
|
|
27
|
+
|
|
28
|
+
## Rules
|
|
29
|
+
|
|
30
|
+
- **Read-only**: The shell is in read-only mode. You cannot create, modify, or delete files except the plan file.
|
|
31
|
+
- **Explore before planning**: Always launch the \`explore\` agent first to understand what exists. Do not skip this step.
|
|
32
|
+
- **Allowed tools**: shell (read-only), \`explore\` and \`plan\` sub-agents, TaskList, TaskGet, __ask_user__.
|
|
33
|
+
- **Write your plan**:
|
|
34
|
+
\`\`\`
|
|
35
|
+
cat << 'EOF' > ${PLAN_FS_PATH}
|
|
36
|
+
# Plan
|
|
37
|
+
...your plan here...
|
|
38
|
+
EOF
|
|
39
|
+
\`\`\`
|
|
40
|
+
- When your plan is complete, tell the user and summarize it.
|
|
41
|
+
|
|
42
|
+
`;
|
|
43
|
+
/** System prompt section appended in execute mode when a plan exists */
|
|
44
|
+
function executeModeSection(planContent) {
|
|
45
|
+
return `\n\n# Plan Context
|
|
46
|
+
|
|
47
|
+
The following plan was created during the planning phase. Use it as guidance for your implementation:
|
|
48
|
+
|
|
49
|
+
<plan>
|
|
50
|
+
${planContent}
|
|
51
|
+
</plan>
|
|
52
|
+
|
|
53
|
+
Follow the plan steps. Mark tasks as completed as you finish them.
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
11
56
|
/**
|
|
12
57
|
* Hive Agent Class
|
|
13
58
|
*/
|
|
@@ -15,7 +60,7 @@ export class Hive {
|
|
|
15
60
|
config;
|
|
16
61
|
contextManager;
|
|
17
62
|
tools;
|
|
18
|
-
/** Current trace builder (set during run, used by
|
|
63
|
+
/** Current trace builder (set during run, used by __sub_agent__ tool) */
|
|
19
64
|
currentTraceBuilder;
|
|
20
65
|
constructor(config) {
|
|
21
66
|
this.config = {
|
|
@@ -31,16 +76,21 @@ export class Hive {
|
|
|
31
76
|
if (!config.disableAskUser) {
|
|
32
77
|
this.tools.push(createAskUserTool());
|
|
33
78
|
}
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
79
|
+
// Auto-merge built-in agents (user-defined agents with same name take priority)
|
|
80
|
+
const builtIn = getBuiltInAgents();
|
|
81
|
+
const userAgentNames = new Set((this.config.agents || []).map((a) => a.name));
|
|
82
|
+
const newAgents = builtIn.filter((a) => !userAgentNames.has(a.name));
|
|
83
|
+
this.config.agents = [...(this.config.agents || []), ...newAgents];
|
|
84
|
+
// Add __sub_agent__ tool if sub-agents are defined
|
|
85
|
+
if (this.config.agents && this.config.agents.length > 0) {
|
|
86
|
+
this.tools.push(createSubAgentTool({
|
|
37
87
|
config: this.config,
|
|
38
88
|
getCurrentTraceBuilder: () => this.getCurrentTraceBuilder(),
|
|
39
|
-
}, config.agents, (subConfig) => new Hive(subConfig)));
|
|
89
|
+
}, this.config.agents, (subConfig) => new Hive(subConfig)));
|
|
40
90
|
}
|
|
41
91
|
}
|
|
42
92
|
/**
|
|
43
|
-
* Get the current trace builder (used by
|
|
93
|
+
* Get the current trace builder (used by __sub_agent__ tool for sub-agent tracing)
|
|
44
94
|
*/
|
|
45
95
|
getCurrentTraceBuilder() {
|
|
46
96
|
return this.currentTraceBuilder;
|
|
@@ -52,21 +102,60 @@ export class Hive {
|
|
|
52
102
|
this.currentTraceBuilder = builder;
|
|
53
103
|
}
|
|
54
104
|
/**
|
|
55
|
-
* Get tools including internal tools for a specific run
|
|
105
|
+
* Get tools including internal tools for a specific run.
|
|
106
|
+
* In plan mode, only a restricted set of tools is returned.
|
|
56
107
|
*/
|
|
57
|
-
getRunTools(
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
108
|
+
getRunTools(taskManager, workspace, agentName, mode) {
|
|
109
|
+
const taskToolOptions = {
|
|
110
|
+
logger: this.config.logger,
|
|
111
|
+
agentName,
|
|
112
|
+
workspace,
|
|
113
|
+
};
|
|
114
|
+
if (mode === "plan") {
|
|
115
|
+
// Plan mode: restricted tool set
|
|
116
|
+
const planTools = [];
|
|
117
|
+
// __ask_user__ (if not disabled)
|
|
118
|
+
const askUser = this.tools.find((t) => t.name === "__ask_user__");
|
|
119
|
+
if (askUser) {
|
|
120
|
+
planTools.push(askUser);
|
|
121
|
+
}
|
|
122
|
+
// __sub_agent__ restricted to explore + plan agents only
|
|
123
|
+
const subAgentTool = this.tools.find((t) => t.name === "__sub_agent__");
|
|
124
|
+
if (subAgentTool) {
|
|
125
|
+
// Create a wrapper that only allows explore and plan agents
|
|
126
|
+
planTools.push({
|
|
127
|
+
...subAgentTool,
|
|
128
|
+
execute: async (params, context) => {
|
|
129
|
+
const agentParam = params.agent;
|
|
130
|
+
if (agentParam !== "explore" && agentParam !== "plan") {
|
|
131
|
+
return {
|
|
132
|
+
success: false,
|
|
133
|
+
error: `Plan mode: only 'explore' and 'plan' sub-agents are allowed. Got: '${agentParam}'`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return subAgentTool.execute(params, context);
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// TaskList and TaskGet only (no TaskCreate, TaskUpdate)
|
|
141
|
+
planTools.push(createTaskListTool(taskManager, taskToolOptions));
|
|
142
|
+
planTools.push(createTaskGetTool(taskManager, taskToolOptions));
|
|
143
|
+
// Shell (already in read-only mode via setReadOnly)
|
|
144
|
+
planTools.push(createShellTool(workspace.getShell()));
|
|
145
|
+
return planTools;
|
|
62
146
|
}
|
|
63
|
-
|
|
147
|
+
// Default / execute mode: all tools
|
|
148
|
+
return [
|
|
149
|
+
...this.tools,
|
|
150
|
+
...createTaskTools(taskManager, taskToolOptions),
|
|
151
|
+
createShellTool(workspace.getShell()),
|
|
152
|
+
];
|
|
64
153
|
}
|
|
65
154
|
/**
|
|
66
155
|
* Run the agent with a user message
|
|
67
156
|
*/
|
|
68
157
|
async run(message, options = {}) {
|
|
69
|
-
const { conversationId, userId, history: providedHistory, signal, shouldContinue,
|
|
158
|
+
const { conversationId, userId, history: providedHistory, signal, shouldContinue, workspace, mode, } = options;
|
|
70
159
|
// Load history from repository or use provided
|
|
71
160
|
let history = [];
|
|
72
161
|
if (providedHistory) {
|
|
@@ -78,11 +167,15 @@ export class Hive {
|
|
|
78
167
|
// Handle history with pending tool_use blocks (from interrupted executions)
|
|
79
168
|
const messages = [...history];
|
|
80
169
|
const lastMessage = messages[messages.length - 1];
|
|
170
|
+
// Detect if we're resuming from an interrupted execution (__ask_user__ pause etc.)
|
|
171
|
+
// This is true when the last message is assistant with pending tool_use blocks.
|
|
172
|
+
let isResuming = false;
|
|
81
173
|
// Check if last message is assistant with tool_use blocks that need results
|
|
82
174
|
if (lastMessage?.role === "assistant" &&
|
|
83
175
|
Array.isArray(lastMessage.content)) {
|
|
84
176
|
const toolUseBlocks = lastMessage.content.filter((block) => block.type === "tool_use");
|
|
85
177
|
if (toolUseBlocks.length > 0) {
|
|
178
|
+
isResuming = true;
|
|
86
179
|
// Find __ask_user__ tool if present
|
|
87
180
|
const askUserToolUse = toolUseBlocks.find((block) => block.name === "__ask_user__");
|
|
88
181
|
// Build tool_results for all tool_use blocks
|
|
@@ -134,14 +227,43 @@ export class Hive {
|
|
|
134
227
|
// Normal user message
|
|
135
228
|
messages.push({ role: "user", content: message });
|
|
136
229
|
}
|
|
137
|
-
//
|
|
138
|
-
const
|
|
230
|
+
// Ensure workspace always exists (create default if not provided)
|
|
231
|
+
const ws = workspace ?? new Workspace();
|
|
232
|
+
await ws.init();
|
|
233
|
+
// Capture existing plan content before cleanup (for prompt injection)
|
|
234
|
+
const existingPlan = ws.read(PLAN_PATH);
|
|
235
|
+
const hasExistingPlan = !!existingPlan && typeof existingPlan === "string";
|
|
236
|
+
// Always delete old plan file — each run starts clean.
|
|
237
|
+
// The content is already captured above for prompt injection.
|
|
238
|
+
if (hasExistingPlan) {
|
|
239
|
+
ws.delete(PLAN_PATH);
|
|
240
|
+
}
|
|
241
|
+
// Configure shell read-only mode based on mode option
|
|
242
|
+
const shell = ws.getShell();
|
|
243
|
+
if (mode === "plan") {
|
|
244
|
+
// Plan mode: read-only shell, only allow writing to the plan file
|
|
245
|
+
shell.setReadOnly(true, [PLAN_FS_PATH]);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
shell.setReadOnly(false);
|
|
249
|
+
}
|
|
250
|
+
// Create task manager for this run.
|
|
251
|
+
// Only restore from workspace when resuming from a pause (e.g., __ask_user__) —
|
|
252
|
+
// detected by pending tool_use blocks in the last history message.
|
|
253
|
+
// On a normal run (even with conversation history), start with a clean task list.
|
|
254
|
+
const taskManager = new TaskManager();
|
|
255
|
+
if (isResuming) {
|
|
256
|
+
taskManager.restoreFromWorkspace(ws);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
ws.delete(".hive/tasks.json");
|
|
260
|
+
}
|
|
139
261
|
// Create tool context
|
|
140
262
|
const toolContext = {
|
|
141
263
|
remainingTokens: this.contextManager.getRemainingTokens(),
|
|
142
264
|
conversationId,
|
|
143
265
|
userId,
|
|
144
|
-
|
|
266
|
+
workspace: ws,
|
|
145
267
|
};
|
|
146
268
|
// Create or use existing trace builder
|
|
147
269
|
// If _traceBuilder is passed (from parent agent), use it
|
|
@@ -151,17 +273,34 @@ export class Hive {
|
|
|
151
273
|
? new TraceBuilder(this.config.agentName || "agent", this.config.trace, message // Pass input message to trace
|
|
152
274
|
)
|
|
153
275
|
: undefined);
|
|
154
|
-
// Store trace builder for
|
|
276
|
+
// Store trace builder for __sub_agent__ tool to access
|
|
155
277
|
this.setCurrentTraceBuilder(traceBuilder);
|
|
278
|
+
// Build system prompt based on mode
|
|
279
|
+
let systemPrompt = this.config.systemPrompt;
|
|
280
|
+
if (mode === "plan") {
|
|
281
|
+
systemPrompt = PLAN_MODE_INSTRUCTIONS + systemPrompt;
|
|
282
|
+
}
|
|
283
|
+
else if (mode === "execute") {
|
|
284
|
+
if (hasExistingPlan) {
|
|
285
|
+
systemPrompt = systemPrompt + executeModeSection(existingPlan);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Inject workspace state snapshot so the AI knows what data exists
|
|
289
|
+
// without needing to call explore first
|
|
290
|
+
const workspaceItems = ws.list().filter((item) => !item.path.startsWith("/.hive/"));
|
|
291
|
+
if (workspaceItems.length > 0) {
|
|
292
|
+
const stateLines = workspaceItems.map((item) => `- ${item.path}: ${item.preview}`);
|
|
293
|
+
systemPrompt += `\n\n## Current Workspace State\n\nThe following data currently exists in workspace:\n\n${stateLines.join("\n")}\n\nUse the shell to read full contents (e.g. \`cat ${workspaceItems[0].path}\`). Do NOT recreate data that already exists — read and present it instead.`;
|
|
294
|
+
}
|
|
156
295
|
// Execute the agent loop
|
|
157
296
|
const result = await executeLoop({
|
|
158
|
-
systemPrompt
|
|
159
|
-
tools: this.getRunTools(
|
|
297
|
+
systemPrompt,
|
|
298
|
+
tools: this.getRunTools(taskManager, ws, this.config.agentName, mode),
|
|
160
299
|
llm: this.config.llm,
|
|
161
300
|
logger: this.config.logger,
|
|
162
301
|
maxIterations: this.config.maxIterations,
|
|
163
302
|
contextManager: this.contextManager,
|
|
164
|
-
|
|
303
|
+
taskManager,
|
|
165
304
|
llmOptions: {},
|
|
166
305
|
signal,
|
|
167
306
|
shouldContinue,
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,cAAc,IAAI,kBAAkB,EACpC,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,iDAAiD;AACjD,MAAM,CAAC,MAAM,SA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,CAC/B,OAAO,EACP,OAAO,EACP,IAAI,CAAC,MAAM,EACX,MAAM,CACP,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explore Agent
|
|
3
|
+
*
|
|
4
|
+
* Fast, read-only agent for investigating workspace data.
|
|
5
|
+
* Uses shell commands to explore the workspace virtual filesystem.
|
|
6
|
+
*/
|
|
7
|
+
import type { SubAgentConfig } from '../types.js';
|
|
8
|
+
export declare const exploreAgent: SubAgentConfig;
|
|
9
|
+
//# sourceMappingURL=explore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explore.d.ts","sourceRoot":"","sources":["../../src/built-in-agents/explore.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,YAAY,EAAE,cAiD1B,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explore Agent
|
|
3
|
+
*
|
|
4
|
+
* Fast, read-only agent for investigating workspace data.
|
|
5
|
+
* Uses shell commands to explore the workspace virtual filesystem.
|
|
6
|
+
*/
|
|
7
|
+
export const exploreAgent = {
|
|
8
|
+
name: 'explore',
|
|
9
|
+
description: 'Fast, read-only agent for exploring workspace data. Use when you need to search, list, or read workspace entries before taking action.',
|
|
10
|
+
systemPrompt: `You are a workspace exploration specialist. You excel at thoroughly navigating and searching workspace data to find relevant information quickly.
|
|
11
|
+
|
|
12
|
+
=== CRITICAL: READ-ONLY MODE - NO MODIFICATIONS ===
|
|
13
|
+
This is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from:
|
|
14
|
+
- Writing or modifying workspace entries
|
|
15
|
+
- Creating new files or entries
|
|
16
|
+
- Using redirect operators (>, >>) to write data
|
|
17
|
+
- Running ANY commands that change workspace state
|
|
18
|
+
|
|
19
|
+
Your role is EXCLUSIVELY to search and analyze existing workspace data.
|
|
20
|
+
|
|
21
|
+
## Tools
|
|
22
|
+
|
|
23
|
+
Use shell commands to explore the / virtual filesystem:
|
|
24
|
+
- \`ls /\` - list top-level workspace paths
|
|
25
|
+
- \`ls /path/\` - list entries under a path
|
|
26
|
+
- \`cat /path/file.json\` - read a workspace entry
|
|
27
|
+
- \`grep "keyword" /**/*.json\` - search across workspace entries
|
|
28
|
+
- \`find / -name "*.json"\` - find entries by pattern
|
|
29
|
+
|
|
30
|
+
## Your Strengths
|
|
31
|
+
|
|
32
|
+
- Rapidly listing and navigating workspace paths
|
|
33
|
+
- Searching workspace content with grep patterns
|
|
34
|
+
- Reading and analyzing entry contents
|
|
35
|
+
- Synthesizing findings from multiple sources
|
|
36
|
+
|
|
37
|
+
## Guidelines
|
|
38
|
+
|
|
39
|
+
- Use \`ls\` for broad discovery, \`grep\` for targeted content search, \`cat\` for reading specific entries
|
|
40
|
+
- Adapt your search approach based on the thoroughness level specified by the caller
|
|
41
|
+
- Be thorough but fast - explore systematically
|
|
42
|
+
- Report what you find clearly and concisely
|
|
43
|
+
- If you find nothing relevant, say so explicitly
|
|
44
|
+
- Communicate your final report directly as a regular message
|
|
45
|
+
- Avoid using emojis
|
|
46
|
+
|
|
47
|
+
NOTE: You are meant to be a fast agent that returns output as quickly as possible. To achieve this:
|
|
48
|
+
- Make efficient use of the tools at your disposal: be smart about how you search
|
|
49
|
+
- Wherever possible, spawn multiple parallel shell calls for searching and reading
|
|
50
|
+
|
|
51
|
+
Complete the search request efficiently and report your findings clearly.`,
|
|
52
|
+
tools: [],
|
|
53
|
+
disableAskUser: true,
|
|
54
|
+
builtInToolNames: ['shell (read-only workspace access)'],
|
|
55
|
+
maxIterations: 15,
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=explore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explore.js","sourceRoot":"","sources":["../../src/built-in-agents/explore.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,CAAC,MAAM,YAAY,GAAmB;IAC1C,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,wIAAwI;IACrJ,YAAY,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EAyC0D;IACxE,KAAK,EAAE,EAAE;IACT,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,CAAC,oCAAoC,CAAC;IACxD,aAAa,EAAE,EAAE;CAClB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Agents
|
|
3
|
+
*
|
|
4
|
+
* Agents that are always available. Cannot be disabled.
|
|
5
|
+
*/
|
|
6
|
+
import type { SubAgentConfig } from '../types.js';
|
|
7
|
+
export { exploreAgent } from './explore.js';
|
|
8
|
+
export { planAgent } from './plan.js';
|
|
9
|
+
/**
|
|
10
|
+
* Get all built-in agents.
|
|
11
|
+
* Returns agents that are always auto-injected into every Hive.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getBuiltInAgents(): SubAgentConfig[];
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/built-in-agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,cAAc,EAAE,CAEnD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Agents
|
|
3
|
+
*
|
|
4
|
+
* Agents that are always available. Cannot be disabled.
|
|
5
|
+
*/
|
|
6
|
+
import { exploreAgent } from './explore.js';
|
|
7
|
+
import { planAgent } from './plan.js';
|
|
8
|
+
export { exploreAgent } from './explore.js';
|
|
9
|
+
export { planAgent } from './plan.js';
|
|
10
|
+
/**
|
|
11
|
+
* Get all built-in agents.
|
|
12
|
+
* Returns agents that are always auto-injected into every Hive.
|
|
13
|
+
*/
|
|
14
|
+
export function getBuiltInAgents() {
|
|
15
|
+
return [exploreAgent, planAgent];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/built-in-agents/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Agent
|
|
3
|
+
*
|
|
4
|
+
* Read-only planning agent for designing task approaches.
|
|
5
|
+
* Reads workspace data to understand current state, then suggests
|
|
6
|
+
* a step-by-step strategy for the main agent to follow.
|
|
7
|
+
*/
|
|
8
|
+
import type { SubAgentConfig } from '../types.js';
|
|
9
|
+
export declare const planAgent: SubAgentConfig;
|
|
10
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../src/built-in-agents/plan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,SAAS,EAAE,cAmEvB,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Agent
|
|
3
|
+
*
|
|
4
|
+
* Read-only planning agent for designing task approaches.
|
|
5
|
+
* Reads workspace data to understand current state, then suggests
|
|
6
|
+
* a step-by-step strategy for the main agent to follow.
|
|
7
|
+
*/
|
|
8
|
+
export const planAgent = {
|
|
9
|
+
name: 'plan',
|
|
10
|
+
description: 'Read-only planning agent for designing task approaches. Use when facing complex or multi-step tasks that benefit from a strategy before execution.',
|
|
11
|
+
systemPrompt: `You are a planning specialist. Your role is to explore workspace data and design implementation plans for the main agent to follow.
|
|
12
|
+
|
|
13
|
+
=== CRITICAL: READ-ONLY MODE - NO MODIFICATIONS ===
|
|
14
|
+
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
15
|
+
- Writing or modifying workspace entries
|
|
16
|
+
- Creating new files or entries
|
|
17
|
+
- Using redirect operators (>, >>) to write data
|
|
18
|
+
- Running ANY commands that change workspace state
|
|
19
|
+
|
|
20
|
+
Your role is EXCLUSIVELY to explore workspace data and design plans.
|
|
21
|
+
|
|
22
|
+
## Tools
|
|
23
|
+
|
|
24
|
+
Use shell commands to read workspace (read-only):
|
|
25
|
+
- \`ls /\` - list available workspace paths
|
|
26
|
+
- \`ls /path/\` - list entries under a path
|
|
27
|
+
- \`cat /path/file.json\` - read workspace entries
|
|
28
|
+
- \`grep "keyword" /**/*.json\` - search workspace
|
|
29
|
+
- \`find / -name "*.json"\` - find entries by pattern
|
|
30
|
+
|
|
31
|
+
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
|
|
32
|
+
|
|
33
|
+
## Your Process
|
|
34
|
+
|
|
35
|
+
1. **Understand requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
|
|
36
|
+
|
|
37
|
+
2. **Explore thoroughly**:
|
|
38
|
+
- Read any workspace paths referenced in the initial prompt
|
|
39
|
+
- Find existing data and state using ls, grep, and cat
|
|
40
|
+
- Understand the current context
|
|
41
|
+
- Identify what information is available vs. what is missing
|
|
42
|
+
|
|
43
|
+
3. **Design solution**:
|
|
44
|
+
- Create an implementation approach based on your findings
|
|
45
|
+
- Consider trade-offs and alternatives
|
|
46
|
+
- Follow existing patterns where appropriate
|
|
47
|
+
|
|
48
|
+
4. **Detail the plan**:
|
|
49
|
+
- Provide step-by-step strategy
|
|
50
|
+
- Identify dependencies and sequencing
|
|
51
|
+
- Anticipate potential challenges
|
|
52
|
+
|
|
53
|
+
## Required Output
|
|
54
|
+
|
|
55
|
+
End your response with:
|
|
56
|
+
|
|
57
|
+
### Key Data for Implementation
|
|
58
|
+
List the most important workspace paths and data points for executing this plan:
|
|
59
|
+
- path/to/entry - [Brief reason: e.g., "Contains user preferences needed for step 1"]
|
|
60
|
+
- path/to/other - [Brief reason: e.g., "Current state to check before proceeding"]
|
|
61
|
+
|
|
62
|
+
## Guidelines
|
|
63
|
+
|
|
64
|
+
- Be specific and actionable - avoid vague steps
|
|
65
|
+
- Reference actual workspace paths and data you found
|
|
66
|
+
- Keep plans concise - focus on what matters
|
|
67
|
+
- If the task is simple enough to not need a plan, say so
|
|
68
|
+
- Avoid using emojis
|
|
69
|
+
|
|
70
|
+
REMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write or modify any workspace data.`,
|
|
71
|
+
tools: [],
|
|
72
|
+
disableAskUser: true,
|
|
73
|
+
builtInToolNames: ['shell (read-only workspace access)'],
|
|
74
|
+
maxIterations: 10,
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/built-in-agents/plan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,CAAC,MAAM,SAAS,GAAmB;IACvC,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,oJAAoJ;IACjK,YAAY,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qGA2DqF;IACnG,KAAK,EAAE,EAAE;IACT,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,CAAC,oCAAoC,CAAC;IACxD,aAAa,EAAE,EAAE;CAClB,CAAA"}
|
package/dist/executor.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { Message, Tool, ToolContext, LLMProvider, LLMOptions, LogProvider, AgentResult } from './types.js';
|
|
7
7
|
import { ContextManager } from './context-manager.js';
|
|
8
|
-
import {
|
|
8
|
+
import { TaskManager } from './tools/tasks.js';
|
|
9
9
|
export interface ExecutorConfig {
|
|
10
10
|
systemPrompt: string;
|
|
11
11
|
tools: Tool[];
|
|
@@ -13,7 +13,7 @@ export interface ExecutorConfig {
|
|
|
13
13
|
logger?: LogProvider;
|
|
14
14
|
maxIterations: number;
|
|
15
15
|
contextManager: ContextManager;
|
|
16
|
-
|
|
16
|
+
taskManager: TaskManager;
|
|
17
17
|
llmOptions?: LLMOptions;
|
|
18
18
|
/** AbortSignal for cancellation */
|
|
19
19
|
signal?: AbortSignal;
|
package/dist/executor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EAIJ,WAAW,EAIX,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EAEZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EAIJ,WAAW,EAIX,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EAEZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAI9C,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,GAAG,EAAE,WAAW,CAAA;IAChB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,EAAE,WAAW,CAAA;IACxB,UAAU,CAAC,EAAE,UAAU,CAAA;IAEvB,mCAAmC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAA;IAEpB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAEvC,0CAA0C;IAC1C,YAAY,CAAC,EAAE,OAAO,YAAY,EAAE,YAAY,CAAA;CACjD;AAyND;;GAEG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,cAAc,EACtB,eAAe,EAAE,OAAO,EAAE,EAC1B,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,WAAW,CAAC,CA6QtB"}
|