ineedcodes 0.1.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/LICENSE +21 -0
- package/README.md +161 -0
- package/docs/assets/ineed-logo.svg +161 -0
- package/docs/configuration.md +71 -0
- package/docs/skills.md +58 -0
- package/package.json +41 -0
- package/packages/agent/dist/boost.d.ts +34 -0
- package/packages/agent/dist/boost.js +138 -0
- package/packages/agent/dist/boost.js.map +1 -0
- package/packages/agent/dist/events.d.ts +67 -0
- package/packages/agent/dist/events.js +16 -0
- package/packages/agent/dist/events.js.map +1 -0
- package/packages/agent/dist/index.d.ts +6 -0
- package/packages/agent/dist/index.js +7 -0
- package/packages/agent/dist/index.js.map +1 -0
- package/packages/agent/dist/lead-agent.d.ts +85 -0
- package/packages/agent/dist/lead-agent.js +235 -0
- package/packages/agent/dist/lead-agent.js.map +1 -0
- package/packages/agent/dist/orchestrator.d.ts +43 -0
- package/packages/agent/dist/orchestrator.js +135 -0
- package/packages/agent/dist/orchestrator.js.map +1 -0
- package/packages/agent/dist/runtime.d.ts +44 -0
- package/packages/agent/dist/runtime.js +265 -0
- package/packages/agent/dist/runtime.js.map +1 -0
- package/packages/agent/dist/system-prompts.d.ts +24 -0
- package/packages/agent/dist/system-prompts.js +91 -0
- package/packages/agent/dist/system-prompts.js.map +1 -0
- package/packages/agent/package.json +21 -0
- package/packages/cli/dist/index.d.ts +3 -0
- package/packages/cli/dist/index.js +567 -0
- package/packages/cli/dist/index.js.map +1 -0
- package/packages/cli/dist/setup.d.ts +37 -0
- package/packages/cli/dist/setup.js +240 -0
- package/packages/cli/dist/setup.js.map +1 -0
- package/packages/cli/dist/tools-setup.d.ts +12 -0
- package/packages/cli/dist/tools-setup.js +28 -0
- package/packages/cli/dist/tools-setup.js.map +1 -0
- package/packages/cli/dist/ui/approval.d.ts +12 -0
- package/packages/cli/dist/ui/approval.js +52 -0
- package/packages/cli/dist/ui/approval.js.map +1 -0
- package/packages/cli/dist/ui/colors.d.ts +14 -0
- package/packages/cli/dist/ui/colors.js +21 -0
- package/packages/cli/dist/ui/colors.js.map +1 -0
- package/packages/cli/dist/ui/prompts.d.ts +46 -0
- package/packages/cli/dist/ui/prompts.js +135 -0
- package/packages/cli/dist/ui/prompts.js.map +1 -0
- package/packages/cli/dist/ui/renderer.d.ts +13 -0
- package/packages/cli/dist/ui/renderer.js +95 -0
- package/packages/cli/dist/ui/renderer.js.map +1 -0
- package/packages/cli/package.json +23 -0
- package/packages/core/dist/config/config.d.ts +32 -0
- package/packages/core/dist/config/config.js +43 -0
- package/packages/core/dist/config/config.js.map +1 -0
- package/packages/core/dist/context/engine.d.ts +25 -0
- package/packages/core/dist/context/engine.js +98 -0
- package/packages/core/dist/context/engine.js.map +1 -0
- package/packages/core/dist/index.d.ts +20 -0
- package/packages/core/dist/index.js +21 -0
- package/packages/core/dist/index.js.map +1 -0
- package/packages/core/dist/llm/openai-compatible.d.ts +23 -0
- package/packages/core/dist/llm/openai-compatible.js +177 -0
- package/packages/core/dist/llm/openai-compatible.js.map +1 -0
- package/packages/core/dist/memory/icm-adapter.d.ts +31 -0
- package/packages/core/dist/memory/icm-adapter.js +98 -0
- package/packages/core/dist/memory/icm-adapter.js.map +1 -0
- package/packages/core/dist/permissions/permissions.d.ts +28 -0
- package/packages/core/dist/permissions/permissions.js +89 -0
- package/packages/core/dist/permissions/permissions.js.map +1 -0
- package/packages/core/dist/security/secrets.d.ts +4 -0
- package/packages/core/dist/security/secrets.js +43 -0
- package/packages/core/dist/security/secrets.js.map +1 -0
- package/packages/core/dist/session/store.d.ts +16 -0
- package/packages/core/dist/session/store.js +54 -0
- package/packages/core/dist/session/store.js.map +1 -0
- package/packages/core/dist/shell/process.d.ts +26 -0
- package/packages/core/dist/shell/process.js +128 -0
- package/packages/core/dist/shell/process.js.map +1 -0
- package/packages/core/dist/skills/loader.d.ts +9 -0
- package/packages/core/dist/skills/loader.js +163 -0
- package/packages/core/dist/skills/loader.js.map +1 -0
- package/packages/core/dist/tools/fs.d.ts +10 -0
- package/packages/core/dist/tools/fs.js +409 -0
- package/packages/core/dist/tools/fs.js.map +1 -0
- package/packages/core/dist/tools/git.d.ts +7 -0
- package/packages/core/dist/tools/git.js +251 -0
- package/packages/core/dist/tools/git.js.map +1 -0
- package/packages/core/dist/tools/mcp.d.ts +42 -0
- package/packages/core/dist/tools/mcp.js +158 -0
- package/packages/core/dist/tools/mcp.js.map +1 -0
- package/packages/core/dist/tools/registry.d.ts +21 -0
- package/packages/core/dist/tools/registry.js +50 -0
- package/packages/core/dist/tools/registry.js.map +1 -0
- package/packages/core/dist/tools/search.d.ts +2 -0
- package/packages/core/dist/tools/search.js +243 -0
- package/packages/core/dist/tools/search.js.map +1 -0
- package/packages/core/dist/tools/shell.d.ts +8 -0
- package/packages/core/dist/tools/shell.js +164 -0
- package/packages/core/dist/tools/shell.js.map +1 -0
- package/packages/core/dist/tools/web.d.ts +14 -0
- package/packages/core/dist/tools/web.js +125 -0
- package/packages/core/dist/tools/web.js.map +1 -0
- package/packages/core/dist/types.d.ts +202 -0
- package/packages/core/dist/types.js +7 -0
- package/packages/core/dist/types.js.map +1 -0
- package/packages/core/dist/util/fs.d.ts +5 -0
- package/packages/core/dist/util/fs.js +33 -0
- package/packages/core/dist/util/fs.js.map +1 -0
- package/packages/core/dist/util/shell-quote.d.ts +7 -0
- package/packages/core/dist/util/shell-quote.js +20 -0
- package/packages/core/dist/util/shell-quote.js.map +1 -0
- package/packages/core/dist/workspace/workspace.d.ts +15 -0
- package/packages/core/dist/workspace/workspace.js +84 -0
- package/packages/core/dist/workspace/workspace.js.map +1 -0
- package/packages/core/package.json +21 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Native multi-agent orchestrator (plan §9–11).
|
|
5
|
+
* Sub-agents are real isolated contexts, not simulated personas in one prompt.
|
|
6
|
+
* The Lead Agent remains the authoritative coordinator.
|
|
7
|
+
*/
|
|
8
|
+
export class Orchestrator {
|
|
9
|
+
maxParallel;
|
|
10
|
+
agents = new Map();
|
|
11
|
+
constructor(maxParallel = 4) {
|
|
12
|
+
this.maxParallel = maxParallel;
|
|
13
|
+
}
|
|
14
|
+
setMaxParallel(n) {
|
|
15
|
+
this.maxParallel = Math.max(1, n);
|
|
16
|
+
}
|
|
17
|
+
get runningCount() {
|
|
18
|
+
return [...this.agents.values()].filter((a) => a.status === 'running').length;
|
|
19
|
+
}
|
|
20
|
+
createTask(opts) {
|
|
21
|
+
const taskId = randomUUID();
|
|
22
|
+
const agentId = `agent-${taskId.slice(0, 8)}`;
|
|
23
|
+
const packet = {
|
|
24
|
+
taskId,
|
|
25
|
+
agentId,
|
|
26
|
+
parentAgentId: opts.parentAgentId,
|
|
27
|
+
objective: opts.objective,
|
|
28
|
+
context: opts.context ?? '',
|
|
29
|
+
constraints: opts.constraints ?? [
|
|
30
|
+
'Stay strictly within your task scope.',
|
|
31
|
+
'Do not commit or push.',
|
|
32
|
+
'Report evidence for every claim.'
|
|
33
|
+
],
|
|
34
|
+
availableTools: opts.availableTools ?? ['*'],
|
|
35
|
+
workspace: opts.workspace ?? '.',
|
|
36
|
+
expectedResult: opts.expectedResult ?? 'A clear summary with evidence.'
|
|
37
|
+
};
|
|
38
|
+
this.agents.set(taskId, {
|
|
39
|
+
agentId,
|
|
40
|
+
parentAgentId: opts.parentAgentId,
|
|
41
|
+
capability: opts.capability,
|
|
42
|
+
status: 'pending',
|
|
43
|
+
task: packet
|
|
44
|
+
});
|
|
45
|
+
return packet;
|
|
46
|
+
}
|
|
47
|
+
canStartMore() {
|
|
48
|
+
return this.runningCount < this.maxParallel;
|
|
49
|
+
}
|
|
50
|
+
setStatus(taskId, status) {
|
|
51
|
+
const record = this.agents.get(taskId);
|
|
52
|
+
if (record)
|
|
53
|
+
record.status = status;
|
|
54
|
+
}
|
|
55
|
+
finish(taskId, result) {
|
|
56
|
+
const record = this.agents.get(taskId);
|
|
57
|
+
if (record) {
|
|
58
|
+
record.status = result.status === 'completed' ? 'completed' : 'failed';
|
|
59
|
+
record.result = result;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
get(taskId) {
|
|
63
|
+
return this.agents.get(taskId);
|
|
64
|
+
}
|
|
65
|
+
list() {
|
|
66
|
+
return [...this.agents.values()];
|
|
67
|
+
}
|
|
68
|
+
/** Forget all agents (used by /clear). */
|
|
69
|
+
clear() {
|
|
70
|
+
this.agents.clear();
|
|
71
|
+
}
|
|
72
|
+
pendingTasks() {
|
|
73
|
+
return this.list().filter((a) => a.status === 'pending');
|
|
74
|
+
}
|
|
75
|
+
restore(record) {
|
|
76
|
+
this.agents.set(record.task.taskId, record);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Run a set of task packets in parallel (bounded by maxParallel).
|
|
80
|
+
* Each worker gets its own AgentRuntime instance via the factory.
|
|
81
|
+
*/
|
|
82
|
+
async runParallel(packets, worker, hooks) {
|
|
83
|
+
const results = new Map();
|
|
84
|
+
const queue = [...packets];
|
|
85
|
+
const launchNext = async () => {
|
|
86
|
+
const packet = queue.shift();
|
|
87
|
+
if (!packet)
|
|
88
|
+
return;
|
|
89
|
+
this.setStatus(packet.taskId, 'running');
|
|
90
|
+
await hooks?.onStatus?.(packet.taskId, 'running');
|
|
91
|
+
let result;
|
|
92
|
+
try {
|
|
93
|
+
result = await worker(packet);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
result = {
|
|
97
|
+
status: 'failed',
|
|
98
|
+
summary: err instanceof Error ? err.message : String(err),
|
|
99
|
+
evidence: [],
|
|
100
|
+
filesChanged: [],
|
|
101
|
+
commandsExecuted: [],
|
|
102
|
+
unresolvedIssues: ['Worker crashed before returning a result.']
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
this.finish(packet.taskId, result);
|
|
106
|
+
results.set(packet.taskId, result);
|
|
107
|
+
await hooks?.onResult?.(packet.taskId, result);
|
|
108
|
+
if (queue.length > 0)
|
|
109
|
+
await launchNext();
|
|
110
|
+
};
|
|
111
|
+
const lanes = Math.min(this.maxParallel, Math.max(1, packets.length));
|
|
112
|
+
await Promise.all(Array.from({ length: lanes }, () => launchNext()));
|
|
113
|
+
return results;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Serialize a task result into compact text for the Lead Agent context. */
|
|
117
|
+
export function summarizeTaskResults(results) {
|
|
118
|
+
const lines = [];
|
|
119
|
+
for (const [taskId, result] of results) {
|
|
120
|
+
lines.push(`Task ${taskId.slice(0, 8)} [${result.status}]: ${result.summary}`);
|
|
121
|
+
for (const ev of result.evidence.slice(0, 5))
|
|
122
|
+
lines.push(` evidence: ${ev}`);
|
|
123
|
+
if (result.filesChanged.length)
|
|
124
|
+
lines.push(` files: ${result.filesChanged.join(', ')}`);
|
|
125
|
+
if (result.tests)
|
|
126
|
+
lines.push(` tests: ${result.tests}`);
|
|
127
|
+
for (const issue of result.unresolvedIssues)
|
|
128
|
+
lines.push(` unresolved: ${issue}`);
|
|
129
|
+
}
|
|
130
|
+
return lines.join('\n');
|
|
131
|
+
}
|
|
132
|
+
export function worktreePathFor(projectRoot, label) {
|
|
133
|
+
return path.join(projectRoot, '.ineedcodes', label);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAGH;IAFZ,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEhD,YAAoB,cAAsB,CAAC;QAAvB,gBAAW,GAAX,WAAW,CAAY;IAAG,CAAC;IAE/C,cAAc,CAAC,CAAS;Q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+
import type { ChatMessage, LLMProvider, MemoryProvider, ToolContext, ToolRegistry } from '@ineedcodes/core';
|
|
2
|
+
export interface RuntimeServices {
|
|
3
|
+
provider: LLMProvider;
|
|
4
|
+
registry: ToolRegistry;
|
|
5
|
+
memory: MemoryProvider;
|
|
6
|
+
toolContext: ToolContext;
|
|
7
|
+
systemPrompt: string;
|
|
8
|
+
maxTurns: number;
|
|
9
|
+
/** plan = read-only exploration; build = full tool access. */
|
|
10
|
+
mode?: 'plan' | 'build';
|
|
11
|
+
reasoningEffort?: 'low' | 'medium' | 'high';
|
|
12
|
+
}
|
|
13
|
+
export type StopReason = 'complete' | 'needs_approval' | 'needs_information' | 'max_turns' | 'aborted' | 'error';
|
|
14
|
+
export interface RuntimeOutcome {
|
|
15
|
+
stopReason: StopReason;
|
|
16
|
+
finalMessage: string;
|
|
17
|
+
turns: number;
|
|
18
|
+
toolCalls: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ApprovalRequest {
|
|
21
|
+
tool: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The real iterative agent loop (plan §7):
|
|
26
|
+
* reason → tool call → observe actual result → update state → repeat → verify.
|
|
27
|
+
*/
|
|
28
|
+
export declare class AgentRuntime {
|
|
29
|
+
private readonly services;
|
|
30
|
+
private readonly emit;
|
|
31
|
+
private readonly requestApproval?;
|
|
32
|
+
private signal?;
|
|
33
|
+
private engine;
|
|
34
|
+
constructor(services: RuntimeServices, emit: (event: import('./events.js').RuntimeEvent) => Promise<void>, requestApproval?: ((req: ApprovalRequest) => Promise<boolean>) | undefined, initialMessages?: ChatMessage[], signal?: AbortSignal | undefined);
|
|
35
|
+
get messages(): readonly ChatMessage[];
|
|
36
|
+
run(objective: string): Promise<RuntimeOutcome>;
|
|
37
|
+
/**
|
|
38
|
+
* Second-chance verification: when the model stops calling tools, require it
|
|
39
|
+
* to either present evidence of completion or state what is missing.
|
|
40
|
+
* Returns the single final answer (never duplicated to the UI).
|
|
41
|
+
*/
|
|
42
|
+
private verifyCompletion;
|
|
43
|
+
private summarize;
|
|
44
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { ContextEngine, heuristicCheckpoint } from '@ineedcodes/core';
|
|
2
|
+
/**
|
|
3
|
+
* The real iterative agent loop (plan §7):
|
|
4
|
+
* reason → tool call → observe actual result → update state → repeat → verify.
|
|
5
|
+
*/
|
|
6
|
+
export class AgentRuntime {
|
|
7
|
+
services;
|
|
8
|
+
emit;
|
|
9
|
+
requestApproval;
|
|
10
|
+
signal;
|
|
11
|
+
engine;
|
|
12
|
+
constructor(services, emit, requestApproval, initialMessages = [], signal) {
|
|
13
|
+
this.services = services;
|
|
14
|
+
this.emit = emit;
|
|
15
|
+
this.requestApproval = requestApproval;
|
|
16
|
+
this.signal = signal;
|
|
17
|
+
this.engine = new ContextEngine(services.provider.contextLimit);
|
|
18
|
+
this.engine.setMessages(initialMessages);
|
|
19
|
+
if (this.engine.messages.length === 0 || this.engine.messages[0]?.role !== 'system') {
|
|
20
|
+
this.engine.append({ role: 'system', content: services.systemPrompt });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get messages() {
|
|
24
|
+
return this.engine.messages;
|
|
25
|
+
}
|
|
26
|
+
async run(objective) {
|
|
27
|
+
const { provider, registry, toolContext } = this.services;
|
|
28
|
+
this.engine.append({ role: 'user', content: objective });
|
|
29
|
+
let turns = 0;
|
|
30
|
+
let toolCalls = 0;
|
|
31
|
+
while (turns < this.services.maxTurns) {
|
|
32
|
+
if (this.signal?.aborted) {
|
|
33
|
+
return { stopReason: 'aborted', finalMessage: 'Run was cancelled.', turns, toolCalls };
|
|
34
|
+
}
|
|
35
|
+
turns += 1;
|
|
36
|
+
await this.emit({ type: 'turn-start', turn: turns });
|
|
37
|
+
if (this.engine.needsCompaction()) {
|
|
38
|
+
const checkpoint = await this.engine.compact(async (msgs) => await this.summarize(msgs));
|
|
39
|
+
await this.emit({ type: 'compaction', checkpoint });
|
|
40
|
+
}
|
|
41
|
+
let response;
|
|
42
|
+
try {
|
|
43
|
+
response = await provider.complete({
|
|
44
|
+
messages: [...this.engine.messages],
|
|
45
|
+
tools: registry.schemas(),
|
|
46
|
+
signal: this.signal,
|
|
47
|
+
reasoningEffort: this.services.reasoningEffort
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
52
|
+
await this.emit({ type: 'assistant-message', text: `I hit a provider error: ${message}` });
|
|
53
|
+
return { stopReason: 'error', finalMessage: message, turns, toolCalls };
|
|
54
|
+
}
|
|
55
|
+
if (response.toolCalls.length === 0) {
|
|
56
|
+
// No tool calls: the model believes it is done. Do NOT display this yet :
|
|
57
|
+
// ask it once to either present evidence (final answer) or keep working,
|
|
58
|
+
// so the user sees exactly one final answer, never a duplicate.
|
|
59
|
+
this.engine.append({ role: 'assistant', content: response.content ?? '' });
|
|
60
|
+
const verdict = await this.verifyCompletion(response.content ?? '');
|
|
61
|
+
return {
|
|
62
|
+
stopReason: verdict.stopReason,
|
|
63
|
+
finalMessage: verdict.message || (response.content ?? ''),
|
|
64
|
+
turns,
|
|
65
|
+
toolCalls
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (response.content) {
|
|
69
|
+
await this.emit({ type: 'assistant-message', text: response.content });
|
|
70
|
+
}
|
|
71
|
+
this.engine.append({
|
|
72
|
+
role: 'assistant',
|
|
73
|
+
content: response.content ?? null,
|
|
74
|
+
toolCalls: response.toolCalls
|
|
75
|
+
});
|
|
76
|
+
let deniedAny = false;
|
|
77
|
+
for (const call of response.toolCalls) {
|
|
78
|
+
if (this.signal?.aborted)
|
|
79
|
+
break;
|
|
80
|
+
toolCalls += 1;
|
|
81
|
+
let input;
|
|
82
|
+
try {
|
|
83
|
+
input = JSON.parse(call.arguments || '{}');
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
input = {};
|
|
87
|
+
}
|
|
88
|
+
if (call.name === 'get_skill') {
|
|
89
|
+
await this.emit({ type: 'skill-invoked', name: String(input?.['name'] ?? '?') });
|
|
90
|
+
}
|
|
91
|
+
await this.emit({ type: 'tool-start', tool: call.name, input });
|
|
92
|
+
// Plan mode: only read-only tools may run; anything else is refused.
|
|
93
|
+
const tool = registry.get(call.name);
|
|
94
|
+
if (this.services.mode === 'plan' && tool && !tool.readonly) {
|
|
95
|
+
deniedAny = true;
|
|
96
|
+
const reason = 'Plan mode is ON: I can only look, not change anything. Switch to build mode (/mode build or Shift+Tab) to apply changes.';
|
|
97
|
+
await this.emit({ type: 'permission-denied', tool: call.name, reason });
|
|
98
|
+
this.engine.append({
|
|
99
|
+
role: 'tool',
|
|
100
|
+
content: JSON.stringify({ ok: false, summary: reason, error: 'plan_mode_blocked' }),
|
|
101
|
+
toolCallId: call.id,
|
|
102
|
+
name: call.name
|
|
103
|
+
});
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const permissions = toolContext.permissions;
|
|
107
|
+
let result;
|
|
108
|
+
if (!tool) {
|
|
109
|
+
result = { ok: false, summary: `Unknown tool: ${call.name}`, error: 'unknown_tool' };
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const decision = await permissions.check(tool.permissions, `tool ${call.name}`);
|
|
113
|
+
if (!decision.allowed) {
|
|
114
|
+
deniedAny = true;
|
|
115
|
+
await this.emit({ type: 'permission-denied', tool: call.name, reason: decision.reason });
|
|
116
|
+
result = { ok: false, summary: decision.reason, error: 'permission_denied' };
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
result = await registry.execute(call.name, input, toolContext);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
await this.emit({ type: 'tool-result', tool: call.name, result });
|
|
123
|
+
this.engine.append({
|
|
124
|
+
role: 'tool',
|
|
125
|
+
content: JSON.stringify({ ok: result.ok, summary: result.summary, data: result.data, error: result.error }),
|
|
126
|
+
toolCallId: call.id,
|
|
127
|
+
name: call.name
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (deniedAny && this.requestApproval) {
|
|
131
|
+
const approved = await this.requestApproval({
|
|
132
|
+
tool: 'session-permissions',
|
|
133
|
+
reason: 'One or more actions were blocked by permissions. Approve them to continue?'
|
|
134
|
+
});
|
|
135
|
+
if (!approved) {
|
|
136
|
+
await this.emit({ type: 'turn-end', turn: turns, stopReason: 'needs_approval' });
|
|
137
|
+
return { stopReason: 'needs_approval', finalMessage: 'Waiting for your approval. Re-run or use /permissions to adjust.', turns, toolCalls };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
await this.emit({ type: 'turn-end', turn: turns, stopReason: 'continue' });
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
stopReason: 'max_turns',
|
|
144
|
+
finalMessage: 'I reached the execution limit for this run. The work is partially done: ask me to continue.',
|
|
145
|
+
turns,
|
|
146
|
+
toolCalls
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Second-chance verification: when the model stops calling tools, require it
|
|
151
|
+
* to either present evidence of completion or state what is missing.
|
|
152
|
+
* Returns the single final answer (never duplicated to the UI).
|
|
153
|
+
*/
|
|
154
|
+
async verifyCompletion(draftAnswer) {
|
|
155
|
+
const effort = this.services.reasoningEffort ?? 'medium';
|
|
156
|
+
const mode = this.services.mode;
|
|
157
|
+
// Plan mode: the answer is an analysis, not an implementation claim: accept it as-is.
|
|
158
|
+
if (mode === 'plan') {
|
|
159
|
+
return { stopReason: 'complete', message: draftAnswer };
|
|
160
|
+
}
|
|
161
|
+
// LOW effort: speed first: accept the draft, skip the verification round trip.
|
|
162
|
+
if (effort === 'low') {
|
|
163
|
+
return { stopReason: 'complete', message: draftAnswer };
|
|
164
|
+
}
|
|
165
|
+
// MEDIUM effort: accept the draft when it already presents evidence.
|
|
166
|
+
// HIGH effort: never trusts the draft: always runs the evidence check below.
|
|
167
|
+
const looksVerified = /(^|\n)\s*(DONE:|verified|exit code|passed|✓)/i.test(draftAnswer) && draftAnswer.length > 40;
|
|
168
|
+
if (effort !== 'high' && looksVerified) {
|
|
169
|
+
return { stopReason: 'complete', message: draftAnswer };
|
|
170
|
+
}
|
|
171
|
+
const { provider, registry } = this.services;
|
|
172
|
+
let response;
|
|
173
|
+
try {
|
|
174
|
+
response = await provider.complete({
|
|
175
|
+
messages: [
|
|
176
|
+
...this.engine.messages,
|
|
177
|
+
{
|
|
178
|
+
role: 'user',
|
|
179
|
+
content: 'Before finishing: state your final answer. If the objective is complete, list the evidence ' +
|
|
180
|
+
'(commands run, exit codes, test results). If it is not complete, continue working with tools instead. ' +
|
|
181
|
+
'Reply with exactly one line starting with "DONE:" if verified complete, or "BLOCKED:" plus the reason if you cannot continue, or keep using tools.'
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
tools: registry.schemas(),
|
|
185
|
+
signal: this.signal,
|
|
186
|
+
reasoningEffort: this.services.reasoningEffort
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return { stopReason: 'complete', message: draftAnswer };
|
|
191
|
+
}
|
|
192
|
+
if (response.toolCalls.length > 0) {
|
|
193
|
+
// Model wants to keep working; show the draft as narration, run the tools,
|
|
194
|
+
// and continue the loop. Only one final answer will be displayed at the end.
|
|
195
|
+
if (response.content) {
|
|
196
|
+
await this.emit({ type: 'assistant-message', text: response.content });
|
|
197
|
+
}
|
|
198
|
+
else if (draftAnswer) {
|
|
199
|
+
await this.emit({ type: 'thinking', text: draftAnswer });
|
|
200
|
+
}
|
|
201
|
+
this.engine.append({ role: 'assistant', content: response.content ?? null, toolCalls: response.toolCalls });
|
|
202
|
+
for (const call of response.toolCalls) {
|
|
203
|
+
let input = {};
|
|
204
|
+
try {
|
|
205
|
+
input = JSON.parse(call.arguments || '{}');
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// leave empty
|
|
209
|
+
}
|
|
210
|
+
const tool = this.services.registry.get(call.name);
|
|
211
|
+
let result;
|
|
212
|
+
if (!tool) {
|
|
213
|
+
result = { ok: false, summary: `Unknown tool: ${call.name}`, error: 'unknown_tool' };
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const decision = await this.services.toolContext.permissions.check(tool.permissions, `tool ${call.name}`);
|
|
217
|
+
result = decision.allowed
|
|
218
|
+
? await this.services.registry.execute(call.name, input, this.services.toolContext)
|
|
219
|
+
: { ok: false, summary: decision.reason, error: 'permission_denied' };
|
|
220
|
+
}
|
|
221
|
+
await this.emit({ type: 'tool-result', tool: call.name, result });
|
|
222
|
+
this.engine.append({
|
|
223
|
+
role: 'tool',
|
|
224
|
+
content: JSON.stringify(result),
|
|
225
|
+
toolCallId: call.id,
|
|
226
|
+
name: call.name
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const continuation = await this.run('Continue from the tool results above and finish the objective.');
|
|
230
|
+
return { stopReason: continuation.stopReason, message: continuation.finalMessage };
|
|
231
|
+
}
|
|
232
|
+
const text = response.content ?? '';
|
|
233
|
+
if (text.startsWith('BLOCKED:')) {
|
|
234
|
+
return { stopReason: 'needs_information', message: text.replace(/^BLOCKED:\s*/, '') };
|
|
235
|
+
}
|
|
236
|
+
return { stopReason: 'complete', message: (text || draftAnswer).replace(/^DONE:\s*/, '') };
|
|
237
|
+
}
|
|
238
|
+
async summarize(messages) {
|
|
239
|
+
try {
|
|
240
|
+
const response = await this.services.provider.complete({
|
|
241
|
+
reasoningEffort: this.services.reasoningEffort,
|
|
242
|
+
messages: [
|
|
243
|
+
{
|
|
244
|
+
role: 'system',
|
|
245
|
+
content: 'Summarize this agent session segment into a factual checkpoint. Output strict JSON: ' +
|
|
246
|
+
'{"objective": string, "decisions": string[], "unresolved": string[], "recentSummary": string}. ' +
|
|
247
|
+
'Facts only, no speculation.'
|
|
248
|
+
},
|
|
249
|
+
{ role: 'user', content: messages.map((m) => `${m.role}: ${(m.content ?? '').slice(0, 500)}`).join('\n').slice(0, 60_000) }
|
|
250
|
+
],
|
|
251
|
+
temperature: 0
|
|
252
|
+
});
|
|
253
|
+
if (response.content) {
|
|
254
|
+
const parsed = JSON.parse(response.content);
|
|
255
|
+
if (typeof parsed.objective === 'string')
|
|
256
|
+
return parsed;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
// fall through to heuristic
|
|
261
|
+
}
|
|
262
|
+
return heuristicCheckpoint(messages);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAkCtE;;;GAGG;AACH,MAAM,OAAO,YAAY;IAIJ;IACA;IACA;IAET;IAPF,MAAM,CAAgB;IAE9B,YACmB,QAAyB,EACzB,IAAkE,EAClE,eAA4D,EAC7E,kBAAiC,EAAE,EAC3B,MAAoB;QAJX,aAAQ,GAAR,QAAQ,CAAiB;QACzB,SAAI,GAAJ,IAAI,CAA8D;QAClE,oBAAe,GAAf,eAAe,CAA6C;QAErE,WAAM,GAAN,MAAM,CAAc;QAE5B,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpF,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,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,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,4BAA4B;QAC9B,CAAC;QACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Skill, WorkspaceInfo } from '@ineedcodes/core';
|
|
2
|
+
export type ExplanationDepth = 'beginner' | 'balanced' | 'terse';
|
|
3
|
+
export interface SystemPromptOptions {
|
|
4
|
+
objective: string;
|
|
5
|
+
workspace: WorkspaceInfo;
|
|
6
|
+
skills: Skill[];
|
|
7
|
+
memories: string[];
|
|
8
|
+
depth: ExplanationDepth;
|
|
9
|
+
permissionMode: string;
|
|
10
|
+
/** plan = read-only analysis; build = full autonomy. */
|
|
11
|
+
mode?: 'plan' | 'build';
|
|
12
|
+
reasoningEffort?: 'low' | 'medium' | 'high';
|
|
13
|
+
isSubAgent?: boolean;
|
|
14
|
+
capability?: string;
|
|
15
|
+
parentObjective?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildSystemPrompt(opts: SystemPromptOptions): string;
|
|
18
|
+
export declare function buildTaskPacketPrompt(packet: {
|
|
19
|
+
objective: string;
|
|
20
|
+
context: string;
|
|
21
|
+
constraints: string[];
|
|
22
|
+
expectedResult: string;
|
|
23
|
+
workspace: string;
|
|
24
|
+
}): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const IDENTITY = `You are iNeedCodes, an autonomous terminal agent.
|
|
2
|
+
The user describes outcomes; you decide how to achieve them. You are not a chatbot that
|
|
3
|
+
generates code: you take real actions: inspect files, search code, run commands, edit
|
|
4
|
+
files, run Git, run tests, use the web, and verify results.
|
|
5
|
+
|
|
6
|
+
Core rules:
|
|
7
|
+
- NEVER fabricate tool output. Success claims require real evidence (exit codes, test output, build output).
|
|
8
|
+
- Never report success just because generated code looks correct. Run the verification.
|
|
9
|
+
- Prefer targeted patches over full-file rewrites for existing source files.
|
|
10
|
+
- Work inside the current project. Touch files outside it only when the user asked for it.
|
|
11
|
+
- Do not push to remotes, force-push, reset --hard, or delete data without explicit approval.
|
|
12
|
+
- Do not invent configuration, endpoints, or APIs. If something is unavailable, say so plainly.`;
|
|
13
|
+
const BEGINNER_STYLE = `Communication style: the user may be a beginner.
|
|
14
|
+
- Before important actions, say in one short sentence what you are doing and why.
|
|
15
|
+
- When something fails, explain in simple words what went wrong before fixing it.
|
|
16
|
+
- Avoid unexplained jargon. If you must use a technical term, briefly define it.
|
|
17
|
+
- At the end, give a short summary: what changed, what you verified, and one thing the user learned.`;
|
|
18
|
+
const BALANCED_STYLE = `Communication style: concise and informative. Briefly note important actions, report evidence for results.`;
|
|
19
|
+
const TERSE_STYLE = `Communication style: terse. Minimal narration, dense results, no fluff.`;
|
|
20
|
+
const LEAD_DUTIES = `As the Lead Agent you are the authoritative coordinator:
|
|
21
|
+
- Understand the user's real objective before acting.
|
|
22
|
+
- Do simple work directly. Do not spawn sub-agents for small tasks.
|
|
23
|
+
- Spawn sub-agents when parallel research, implementation, testing, or review genuinely helps.
|
|
24
|
+
- Reconcile sub-agent results yourself; they never control the session.
|
|
25
|
+
- Keep going until the objective is verified complete, you need approval, or you truly need information from the user.`;
|
|
26
|
+
const SUB_AGENT_DUTIES = (capability, parentObjective) => `You are a sub-agent (${capability}) created by the Lead Agent.
|
|
27
|
+
The Lead Agent's overall objective: ${parentObjective}
|
|
28
|
+
Your job is ONLY your own task packet. Do not expand scope. Do not commit or push.
|
|
29
|
+
When done, produce a result summary with evidence: what you did, what you verified (commands + exit codes), files changed, and any unresolved issues.`;
|
|
30
|
+
export function buildSystemPrompt(opts) {
|
|
31
|
+
const ws = opts.workspace;
|
|
32
|
+
const parts = [IDENTITY];
|
|
33
|
+
if (opts.isSubAgent) {
|
|
34
|
+
parts.push(SUB_AGENT_DUTIES(opts.capability ?? 'general', opts.parentObjective ?? opts.objective));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
parts.push(LEAD_DUTIES);
|
|
38
|
+
}
|
|
39
|
+
// Reasoning effort changes HOW the agent thinks, not just a flag:
|
|
40
|
+
// high = deliberate multi-step reasoning; low = act immediately.
|
|
41
|
+
if (opts.reasoningEffort === 'high') {
|
|
42
|
+
parts.push('Thinking depth: HIGH. Before acting: consider root causes, edge cases, and second-order effects. ' +
|
|
43
|
+
'For multi-step work, plan the steps first, then execute. Before claiming success, actively look for ways ' +
|
|
44
|
+
'your conclusion could be wrong and check them. Do not skip verification.');
|
|
45
|
+
}
|
|
46
|
+
else if (opts.reasoningEffort === 'low') {
|
|
47
|
+
parts.push('Thinking depth: LOW. Be fast and direct: minimal deliberation, act on the obvious path, keep answers short. ' +
|
|
48
|
+
'Skip ceremony; if a task turns out to be bigger than it looks, say so and ask.');
|
|
49
|
+
}
|
|
50
|
+
if (opts.mode === 'plan') {
|
|
51
|
+
parts.push('MODE: PLAN (read-only). Analyze, explore, and propose: do NOT modify files, run state-changing commands, ' +
|
|
52
|
+
'or commit. Produce a concrete, step-by-step plan the user can approve before any change is made.');
|
|
53
|
+
}
|
|
54
|
+
parts.push(opts.depth === 'beginner' ? BEGINNER_STYLE
|
|
55
|
+
: opts.depth === 'terse' ? TERSE_STYLE
|
|
56
|
+
: BALANCED_STYLE);
|
|
57
|
+
const env = [
|
|
58
|
+
`Working directory: ${ws.root}`,
|
|
59
|
+
`Project root: ${ws.projectRoot}`,
|
|
60
|
+
ws.isGitRepo ? `Git repository: yes (branch ${ws.gitBranch ?? 'unknown'})` : 'Git repository: no',
|
|
61
|
+
`Permission mode: ${opts.permissionMode}`
|
|
62
|
+
];
|
|
63
|
+
parts.push(`## Environment\n${env.join('\n')}`);
|
|
64
|
+
if (ws.projectInstructions) {
|
|
65
|
+
parts.push(`## Project instructions (apply automatically)\n${ws.projectInstructions}`);
|
|
66
|
+
}
|
|
67
|
+
if (opts.memories.length) {
|
|
68
|
+
parts.push(`## Relevant memory from previous sessions\n${opts.memories.map((m) => `- ${m}`).join('\n')}`);
|
|
69
|
+
}
|
|
70
|
+
if (opts.skills.length) {
|
|
71
|
+
const list = opts.skills
|
|
72
|
+
.map((s) => `- ${s.name}${s.scope !== 'builtin' ? ` (${s.scope})` : ''}: ${s.description}`)
|
|
73
|
+
.join('\n');
|
|
74
|
+
parts.push(`## Available skills\n${list}\n\n` +
|
|
75
|
+
`Use a skill when the user names it, or when the description clearly matches the task. ` +
|
|
76
|
+
`To follow a skill, apply its instructions to your next actions (skill text is provided by the get_skill tool).`);
|
|
77
|
+
}
|
|
78
|
+
parts.push(`## Current objective\n${opts.objective}`);
|
|
79
|
+
return parts.join('\n\n');
|
|
80
|
+
}
|
|
81
|
+
export function buildTaskPacketPrompt(packet) {
|
|
82
|
+
return [
|
|
83
|
+
`## Task packet`,
|
|
84
|
+
`Objective: ${packet.objective}`,
|
|
85
|
+
packet.context ? `Context:\n${packet.context}` : '',
|
|
86
|
+
packet.constraints.length ? `Constraints:\n- ${packet.constraints.join('\n- ')}` : '',
|
|
87
|
+
`Expected result: ${packet.expectedResult}`,
|
|
88
|
+
`Workspace: ${packet.workspace}`
|
|
89
|
+
].filter(Boolean).join('\n\n');
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=system-prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-prompts.js","sourceRoot":"","sources":["../src/system-prompts.ts"],"names":[],"mappings":"AAmBA,MAAM,QAAQ,GAAG;;;;;;;;;;;gGAW+E,CAAC;AAEjG,MAAM,cAAc,GAAG;;;;qGAI8E,CAAC;AAEtG,MAAM,cAAc,GAAG,4GAA4G,CAAC;AAEpI,MAAM,WAAW,GAAG,yEAAyE,CAAC;AAE9F,MAAM,WAAW,GAAG;;;;;uHAKmG,CAAC;AAExH,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAE,eAAuB,EAAE,EAAE,CAAC,wBAAwB,UAAU;sCACtE,eAAe;;sJAEiG,CAAC;AAEvJ,MAAM,UAAU,iBAAiB,CAAC,IAAyB;IACzD,MAAM,EAAE,GAAG,I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EAAE,CAAC,CAAC,CAAC,EAAE;QACnD,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,mBAAmB,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QACrF,oBAAoB,MAAM,CAAC,cAAc,EAAE;QAC3C,cAAc,MAAM,CAAC,SAAS,EAAE;KACjC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ineedcodes/agent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "iNeedCodes agent runtime: lead agent, orchestrator, sub-agents, boost",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -b"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@ineedcodes/core": "0.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^22.0.0"
|
|
20
|
+
}
|
|
21
|
+
}
|