@bahulam/code 0.1.24 → 0.1.26
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/package.json +1 -1
- package/src/commands/install.mjs +88 -6
- package/src/commands/plugin-manage.mjs +146 -5
- package/src/config/cli-args.mjs +23 -3
- package/src/config/model-catalog.mjs +9 -0
- package/src/config/model-defaults.mjs +16 -0
- package/src/core/approval.mjs +8 -1
- package/src/core/attachments.mjs +4 -0
- package/src/core/backend-url.mjs +16 -0
- package/src/core/context-reduction.mjs +207 -0
- package/src/core/headless.mjs +85 -13
- package/src/core/local-agent.mjs +352 -44
- package/src/core/model-selection.mjs +72 -0
- package/src/core/request-retry.mjs +106 -0
- package/src/core/tool-error.mjs +155 -0
- package/src/core/usage-normalization.mjs +32 -0
- package/src/local-service/agent-relay.mjs +279 -7
- package/src/local-service/server.mjs +37 -0
- package/src/orchestration/node-runner.mjs +7 -3
- package/src/plugins/executor.mjs +4 -4
- package/src/plugins/lifecycle.mjs +337 -0
- package/src/plugins/manifest.mjs +37 -0
- package/src/plugins/pi-compat/requirements.mjs +30 -17
- package/src/plugins/preflight.mjs +37 -0
- package/src/terminal/main.mjs +10 -1
- package/src/terminal/paste-input.mjs +52 -0
- package/src/terminal/repl.mjs +169 -36
- package/src/tools/registry.mjs +1 -16
- package/src/core/agent-loop.mjs +0 -503
- package/src/core/context-manager.mjs +0 -198
- package/src/tools/agent.mjs +0 -142
package/src/tools/agent.mjs
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Tool — spawn a subagent with its own agent loop.
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - subagent_type parameter
|
|
6
|
-
* - isolation: "worktree" option
|
|
7
|
-
* - run_in_background option
|
|
8
|
-
* - model override
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { createAgentLoop } from '../core/agent-loop.mjs';
|
|
12
|
-
import { createToolRegistry } from './registry.mjs';
|
|
13
|
-
import { createPermissionChecker } from '../permissions/checker.mjs';
|
|
14
|
-
import { DEFAULT_REASONING_MODEL } from '../config/model-defaults.mjs';
|
|
15
|
-
|
|
16
|
-
export const AgentTool = {
|
|
17
|
-
name: 'Agent',
|
|
18
|
-
description: 'Spawn a subagent to handle a task. The subagent has its own context and tools.',
|
|
19
|
-
inputSchema: {
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {
|
|
22
|
-
prompt: {
|
|
23
|
-
type: 'string',
|
|
24
|
-
description: 'The task for the subagent to perform',
|
|
25
|
-
},
|
|
26
|
-
allowed_tools: {
|
|
27
|
-
type: 'array',
|
|
28
|
-
items: { type: 'string' },
|
|
29
|
-
description: 'List of tool names the subagent can use (default: all)',
|
|
30
|
-
},
|
|
31
|
-
subagent_type: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
description: 'Type of subagent (e.g. coder, reviewer, researcher)',
|
|
34
|
-
},
|
|
35
|
-
isolation: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
enum: ['default', 'worktree'],
|
|
38
|
-
description: 'Isolation mode. "worktree" uses a git worktree.',
|
|
39
|
-
},
|
|
40
|
-
run_in_background: {
|
|
41
|
-
type: 'boolean',
|
|
42
|
-
description: 'Run in background and return immediately',
|
|
43
|
-
},
|
|
44
|
-
model: {
|
|
45
|
-
type: 'string',
|
|
46
|
-
description: 'Override model for this subagent',
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
required: ['prompt'],
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
validateInput(input) {
|
|
53
|
-
const errors = [];
|
|
54
|
-
if (!input.prompt) errors.push('prompt is required');
|
|
55
|
-
return errors;
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
// Track background subagents
|
|
59
|
-
_backgroundAgents: new Map(),
|
|
60
|
-
_nextBgId: 0,
|
|
61
|
-
|
|
62
|
-
async call(input, options = {}) {
|
|
63
|
-
const model = input.model || process.env.SUBAGENT_MODEL || DEFAULT_REASONING_MODEL;
|
|
64
|
-
const tools = createToolRegistry({
|
|
65
|
-
pluginRegistry: options.pluginRegistry || null,
|
|
66
|
-
stateEmit: options.stateEmit || null,
|
|
67
|
-
exposePluginTools: true,
|
|
68
|
-
});
|
|
69
|
-
const permissions = createPermissionChecker({ defaultMode: 'bypassPermissions' });
|
|
70
|
-
|
|
71
|
-
// Build type-specific system prompt prefix
|
|
72
|
-
let systemPrefix = '';
|
|
73
|
-
if (input.subagent_type) {
|
|
74
|
-
const typePrompts = {
|
|
75
|
-
coder: 'You are a coding agent. Write clean, tested code.',
|
|
76
|
-
reviewer: 'You are a code reviewer. Analyze code for bugs and improvements.',
|
|
77
|
-
researcher: 'You are a research agent. Find and summarize information.',
|
|
78
|
-
tester: 'You are a testing agent. Write and run tests.',
|
|
79
|
-
planner: 'You are a planning agent. Break down tasks into steps.',
|
|
80
|
-
};
|
|
81
|
-
systemPrefix = typePrompts[input.subagent_type] || `You are a ${input.subagent_type} agent.`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const fullPrompt = systemPrefix
|
|
85
|
-
? `${systemPrefix}\n\nTask: ${input.prompt}`
|
|
86
|
-
: input.prompt;
|
|
87
|
-
|
|
88
|
-
const loop = createAgentLoop({
|
|
89
|
-
model,
|
|
90
|
-
tools,
|
|
91
|
-
permissions,
|
|
92
|
-
settings: {
|
|
93
|
-
stream: false,
|
|
94
|
-
stagnationDetection: !['0', 'false', 'no', 'off'].includes(
|
|
95
|
-
(process.env.BAHULAM_STAGNATION_DETECTION ?? '0').toLowerCase(),
|
|
96
|
-
),
|
|
97
|
-
stagnationThreshold: Number.parseInt(
|
|
98
|
-
process.env.BAHULAM_STAGNATION_THRESHOLD
|
|
99
|
-
?? '3',
|
|
100
|
-
10,
|
|
101
|
-
),
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
if (input.run_in_background) {
|
|
106
|
-
const bgId = ++AgentTool._nextBgId;
|
|
107
|
-
const entry = { id: bgId, status: 'running', result: null, prompt: input.prompt };
|
|
108
|
-
AgentTool._backgroundAgents.set(bgId, entry);
|
|
109
|
-
|
|
110
|
-
// Run in background
|
|
111
|
-
runSubagent(loop, fullPrompt).then(result => {
|
|
112
|
-
entry.status = 'completed';
|
|
113
|
-
entry.result = result;
|
|
114
|
-
}).catch(err => {
|
|
115
|
-
entry.status = 'error';
|
|
116
|
-
entry.result = err.message;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
return `Subagent started in background: id=${bgId}`;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return runSubagent(loop, fullPrompt);
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
async function runSubagent(loop, prompt) {
|
|
127
|
-
const results = [];
|
|
128
|
-
try {
|
|
129
|
-
for await (const event of loop.run(prompt)) {
|
|
130
|
-
if (event.type === 'assistant' && event.content) {
|
|
131
|
-
results.push(event.content);
|
|
132
|
-
}
|
|
133
|
-
if (event.type === 'result') {
|
|
134
|
-
results.push(`[tool:${event.tool}] ${String(event.result).slice(0, 500)}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch (err) {
|
|
138
|
-
return `Subagent error: ${err.message}`;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return results.join('\n') || 'Subagent completed with no output.';
|
|
142
|
-
}
|