joonecli 0.1.1 → 0.2.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/cli/index.js +4 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/builtinCommands.js +6 -6
- package/dist/commands/builtinCommands.js.map +1 -1
- package/dist/commands/commandRegistry.d.ts +3 -1
- package/dist/commands/commandRegistry.js.map +1 -1
- package/dist/core/agentLoop.d.ts +3 -1
- package/dist/core/agentLoop.js +17 -7
- package/dist/core/agentLoop.js.map +1 -1
- package/dist/core/compactor.js +2 -2
- package/dist/core/compactor.js.map +1 -1
- package/dist/core/contextGuard.d.ts +5 -0
- package/dist/core/contextGuard.js +30 -3
- package/dist/core/contextGuard.js.map +1 -1
- package/dist/core/events.d.ts +45 -0
- package/dist/core/events.js +8 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/sessionStore.js +3 -2
- package/dist/core/sessionStore.js.map +1 -1
- package/dist/core/subAgent.js +2 -2
- package/dist/core/subAgent.js.map +1 -1
- package/dist/core/tokenCounter.d.ts +8 -1
- package/dist/core/tokenCounter.js +28 -0
- package/dist/core/tokenCounter.js.map +1 -1
- package/dist/middleware/permission.js +1 -0
- package/dist/middleware/permission.js.map +1 -1
- package/dist/tools/browser.js +4 -1
- package/dist/tools/browser.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +11 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/installHostDeps.d.ts +2 -0
- package/dist/tools/installHostDeps.js +37 -0
- package/dist/tools/installHostDeps.js.map +1 -0
- package/dist/tools/router.js +1 -0
- package/dist/tools/router.js.map +1 -1
- package/dist/tools/spawnAgent.js +3 -1
- package/dist/tools/spawnAgent.js.map +1 -1
- package/dist/tracing/sessionTracer.d.ts +1 -0
- package/dist/tracing/sessionTracer.js +4 -1
- package/dist/tracing/sessionTracer.js.map +1 -1
- package/dist/ui/App.js +6 -1
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/components/ActionLog.d.ts +7 -0
- package/dist/ui/components/ActionLog.js +63 -0
- package/dist/ui/components/ActionLog.js.map +1 -0
- package/dist/ui/components/FileBrowser.d.ts +2 -0
- package/dist/ui/components/FileBrowser.js +41 -0
- package/dist/ui/components/FileBrowser.js.map +1 -0
- package/package.json +3 -5
- package/AGENTS.md +0 -56
- package/Handover.md +0 -115
- package/PROGRESS.md +0 -160
- package/docs/01_insights_and_patterns.md +0 -27
- package/docs/02_edge_cases_and_mitigations.md +0 -143
- package/docs/03_initial_implementation_plan.md +0 -66
- package/docs/04_tech_stack_proposal.md +0 -20
- package/docs/05_prd.md +0 -87
- package/docs/06_user_stories.md +0 -72
- package/docs/07_system_architecture.md +0 -138
- package/docs/08_roadmap.md +0 -200
- package/e2b/Dockerfile +0 -26
- package/src/__tests__/bootstrap.test.ts +0 -111
- package/src/__tests__/config.test.ts +0 -97
- package/src/__tests__/m55.test.ts +0 -238
- package/src/__tests__/middleware.test.ts +0 -219
- package/src/__tests__/modelFactory.test.ts +0 -63
- package/src/__tests__/optimizations.test.ts +0 -201
- package/src/__tests__/promptBuilder.test.ts +0 -141
- package/src/__tests__/sandbox.test.ts +0 -102
- package/src/__tests__/security.test.ts +0 -122
- package/src/__tests__/streaming.test.ts +0 -82
- package/src/__tests__/toolRouter.test.ts +0 -52
- package/src/__tests__/tools.test.ts +0 -146
- package/src/__tests__/tracing.test.ts +0 -196
- package/src/agents/agentRegistry.ts +0 -69
- package/src/agents/agentSpec.ts +0 -67
- package/src/agents/builtinAgents.ts +0 -142
- package/src/cli/config.ts +0 -124
- package/src/cli/index.ts +0 -742
- package/src/cli/modelFactory.ts +0 -174
- package/src/cli/postinstall.ts +0 -28
- package/src/cli/providers.ts +0 -107
- package/src/commands/builtinCommands.ts +0 -293
- package/src/commands/commandRegistry.ts +0 -194
- package/src/core/agentLoop.d.ts.map +0 -1
- package/src/core/agentLoop.ts +0 -312
- package/src/core/autoSave.ts +0 -95
- package/src/core/compactor.ts +0 -252
- package/src/core/contextGuard.ts +0 -129
- package/src/core/errors.ts +0 -202
- package/src/core/promptBuilder.d.ts.map +0 -1
- package/src/core/promptBuilder.ts +0 -139
- package/src/core/reasoningRouter.ts +0 -121
- package/src/core/retry.ts +0 -75
- package/src/core/sessionResumer.ts +0 -90
- package/src/core/sessionStore.ts +0 -216
- package/src/core/subAgent.ts +0 -339
- package/src/core/tokenCounter.ts +0 -64
- package/src/evals/dataset.ts +0 -67
- package/src/evals/evaluator.ts +0 -81
- package/src/hitl/bridge.ts +0 -160
- package/src/middleware/commandSanitizer.ts +0 -60
- package/src/middleware/loopDetection.ts +0 -63
- package/src/middleware/permission.ts +0 -72
- package/src/middleware/pipeline.ts +0 -75
- package/src/middleware/preCompletion.ts +0 -94
- package/src/middleware/types.ts +0 -45
- package/src/sandbox/bootstrap.ts +0 -121
- package/src/sandbox/manager.ts +0 -239
- package/src/sandbox/sync.ts +0 -157
- package/src/skills/loader.ts +0 -143
- package/src/skills/tools.ts +0 -99
- package/src/skills/types.ts +0 -13
- package/src/test_cache.ts +0 -72
- package/src/tools/askUser.ts +0 -47
- package/src/tools/browser.ts +0 -137
- package/src/tools/index.d.ts.map +0 -1
- package/src/tools/index.ts +0 -237
- package/src/tools/registry.ts +0 -198
- package/src/tools/router.ts +0 -78
- package/src/tools/security.ts +0 -220
- package/src/tools/spawnAgent.ts +0 -158
- package/src/tools/webSearch.ts +0 -142
- package/src/tracing/analyzer.ts +0 -265
- package/src/tracing/langsmith.ts +0 -63
- package/src/tracing/sessionTracer.ts +0 -202
- package/src/tracing/types.ts +0 -49
- package/src/types/valyu.d.ts +0 -37
- package/src/ui/App.tsx +0 -404
- package/src/ui/components/HITLPrompt.tsx +0 -119
- package/src/ui/components/Header.tsx +0 -51
- package/src/ui/components/MessageBubble.tsx +0 -46
- package/src/ui/components/StatusBar.tsx +0 -138
- package/src/ui/components/StreamingText.tsx +0 -48
- package/src/ui/components/ToolCallPanel.tsx +0 -80
- package/tests/commands/commands.test.ts +0 -356
- package/tests/core/compactor.test.ts +0 -217
- package/tests/core/retryAndErrors.test.ts +0 -164
- package/tests/core/sessionResumer.test.ts +0 -95
- package/tests/core/sessionStore.test.ts +0 -84
- package/tests/core/stability.test.ts +0 -165
- package/tests/core/subAgent.test.ts +0 -238
- package/tests/hitl/hitlBridge.test.ts +0 -115
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -10
- package/vitest.out +0 -48
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import * as os from "node:os";
|
|
5
|
-
import { SessionTracer } from "../tracing/sessionTracer.js";
|
|
6
|
-
import {
|
|
7
|
-
enableLangSmith,
|
|
8
|
-
disableLangSmith,
|
|
9
|
-
isLangSmithEnabled,
|
|
10
|
-
} from "../tracing/langsmith.js";
|
|
11
|
-
import { TraceAnalyzer } from "../tracing/analyzer.js";
|
|
12
|
-
import type { SessionTrace } from "../tracing/types.js";
|
|
13
|
-
|
|
14
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
15
|
-
// 6a: SessionTracer
|
|
16
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
17
|
-
|
|
18
|
-
describe("SessionTracer", () => {
|
|
19
|
-
// ─── Test #83: Records LLM calls and computes totals ───
|
|
20
|
-
|
|
21
|
-
it("records LLM calls and computes token totals", () => {
|
|
22
|
-
const tracer = new SessionTracer("test-session-1");
|
|
23
|
-
|
|
24
|
-
tracer.recordLLMCall({ promptTokens: 500, completionTokens: 100, cached: false, duration: 800 });
|
|
25
|
-
tracer.recordLLMCall({ promptTokens: 400, completionTokens: 150, cached: true, duration: 600 });
|
|
26
|
-
|
|
27
|
-
const summary = tracer.getSummary();
|
|
28
|
-
|
|
29
|
-
expect(summary.promptTokens).toBe(900);
|
|
30
|
-
expect(summary.completionTokens).toBe(250);
|
|
31
|
-
expect(summary.totalTokens).toBe(1150);
|
|
32
|
-
expect(summary.turnCount).toBe(2);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// ─── Test #84: Records tool calls and counts them ───
|
|
36
|
-
|
|
37
|
-
it("records tool calls and counts them", () => {
|
|
38
|
-
const tracer = new SessionTracer("test-session-2");
|
|
39
|
-
|
|
40
|
-
tracer.recordToolCall({ name: "bash", args: { command: "ls" }, duration: 50, success: true });
|
|
41
|
-
tracer.recordToolCall({ name: "write_file", args: { path: "a.ts" }, duration: 30, success: true });
|
|
42
|
-
tracer.recordToolCall({ name: "bash", args: { command: "npm test" }, duration: 200, success: false });
|
|
43
|
-
|
|
44
|
-
const summary = tracer.getSummary();
|
|
45
|
-
|
|
46
|
-
expect(summary.toolCallCount).toBe(3);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// ─── Test #85: Computes cache hit rate correctly ───
|
|
50
|
-
|
|
51
|
-
it("computes cache hit rate correctly", () => {
|
|
52
|
-
const tracer = new SessionTracer("test-session-3");
|
|
53
|
-
|
|
54
|
-
// 3 calls: 2 cached, 1 not
|
|
55
|
-
tracer.recordLLMCall({ promptTokens: 100, completionTokens: 50, cached: true, duration: 100 });
|
|
56
|
-
tracer.recordLLMCall({ promptTokens: 100, completionTokens: 50, cached: true, duration: 100 });
|
|
57
|
-
tracer.recordLLMCall({ promptTokens: 100, completionTokens: 50, cached: false, duration: 100 });
|
|
58
|
-
|
|
59
|
-
const summary = tracer.getSummary();
|
|
60
|
-
|
|
61
|
-
// 200 cached out of 300 total prompt tokens = 66.7%
|
|
62
|
-
expect(summary.cacheHitRate).toBeCloseTo(0.667, 2);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// ─── Test #86: export() returns valid SessionTrace ───
|
|
66
|
-
|
|
67
|
-
it("export() returns a valid SessionTrace", () => {
|
|
68
|
-
const tracer = new SessionTracer("export-test");
|
|
69
|
-
|
|
70
|
-
tracer.recordLLMCall({ promptTokens: 100, completionTokens: 50, cached: true, duration: 200 });
|
|
71
|
-
tracer.recordError({ message: "Timeout", tool: "bash" });
|
|
72
|
-
|
|
73
|
-
const trace = tracer.export();
|
|
74
|
-
|
|
75
|
-
expect(trace.sessionId).toBe("export-test");
|
|
76
|
-
expect(trace.startedAt).toBeGreaterThan(0);
|
|
77
|
-
expect(trace.endedAt).toBeGreaterThanOrEqual(trace.startedAt);
|
|
78
|
-
expect(trace.events).toHaveLength(2);
|
|
79
|
-
expect(trace.summary.turnCount).toBe(1);
|
|
80
|
-
expect(trace.summary.errorCount).toBe(1);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
85
|
-
// 6b: LangSmith Integration
|
|
86
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
87
|
-
|
|
88
|
-
describe("LangSmith Integration", () => {
|
|
89
|
-
afterEach(() => {
|
|
90
|
-
disableLangSmith();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// ─── Test #87: enableLangSmith sets correct env vars ───
|
|
94
|
-
|
|
95
|
-
it("sets the correct environment variables", () => {
|
|
96
|
-
enableLangSmith({ apiKey: "test-key-123", project: "my-project" });
|
|
97
|
-
|
|
98
|
-
expect(process.env.LANGCHAIN_TRACING_V2).toBe("true");
|
|
99
|
-
expect(process.env.LANGCHAIN_API_KEY).toBe("test-key-123");
|
|
100
|
-
expect(process.env.LANGCHAIN_PROJECT).toBe("my-project");
|
|
101
|
-
expect(isLangSmithEnabled()).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// ─── Test #88: disableLangSmith clears env vars ───
|
|
105
|
-
|
|
106
|
-
it("disableLangSmith clears the environment variables", () => {
|
|
107
|
-
enableLangSmith({ apiKey: "test-key" });
|
|
108
|
-
disableLangSmith();
|
|
109
|
-
|
|
110
|
-
expect(process.env.LANGCHAIN_TRACING_V2).toBeUndefined();
|
|
111
|
-
expect(isLangSmithEnabled()).toBe(false);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
116
|
-
// 6c: TraceAnalyzer
|
|
117
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
118
|
-
|
|
119
|
-
describe("TraceAnalyzer", () => {
|
|
120
|
-
const createTrace = (overrides?: Partial<SessionTrace>): SessionTrace => ({
|
|
121
|
-
sessionId: "test",
|
|
122
|
-
startedAt: Date.now() - 10000,
|
|
123
|
-
endedAt: Date.now(),
|
|
124
|
-
events: [],
|
|
125
|
-
summary: {
|
|
126
|
-
totalTokens: 1000,
|
|
127
|
-
promptTokens: 700,
|
|
128
|
-
completionTokens: 300,
|
|
129
|
-
totalCost: 0.006,
|
|
130
|
-
cacheHitRate: 0.8,
|
|
131
|
-
toolCallCount: 5,
|
|
132
|
-
errorCount: 0,
|
|
133
|
-
totalDuration: 10000,
|
|
134
|
-
turnCount: 5,
|
|
135
|
-
},
|
|
136
|
-
...overrides,
|
|
137
|
-
});
|
|
138
|
-
// ─── Test #89: Detects loop patterns ───
|
|
139
|
-
|
|
140
|
-
it("detects doom-loop patterns in tool calls", () => {
|
|
141
|
-
const trace = createTrace({
|
|
142
|
-
events: [
|
|
143
|
-
{ type: "tool_call", timestamp: 1, data: { name: "bash", args: { command: "ls" } } },
|
|
144
|
-
{ type: "tool_call", timestamp: 2, data: { name: "bash", args: { command: "ls" } } },
|
|
145
|
-
{ type: "tool_call", timestamp: 3, data: { name: "bash", args: { command: "ls" } } },
|
|
146
|
-
],
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const analyzer = new TraceAnalyzer(trace);
|
|
150
|
-
const report = analyzer.analyze();
|
|
151
|
-
|
|
152
|
-
const loopIssues = report.issues.filter((i) => i.category === "loop");
|
|
153
|
-
expect(loopIssues.length).toBeGreaterThan(0);
|
|
154
|
-
expect(loopIssues[0].severity).toBe("critical");
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// ─── Test #90: Detects cost hotspots ───
|
|
158
|
-
|
|
159
|
-
it("flags turns consuming >20% of total tokens", () => {
|
|
160
|
-
const trace = createTrace({
|
|
161
|
-
summary: {
|
|
162
|
-
...createTrace().summary,
|
|
163
|
-
totalTokens: 1000,
|
|
164
|
-
},
|
|
165
|
-
events: [
|
|
166
|
-
{ type: "llm_call", timestamp: 1, data: { promptTokens: 300, completionTokens: 100, cached: false } },
|
|
167
|
-
{ type: "llm_call", timestamp: 2, data: { promptTokens: 100, completionTokens: 50, cached: true } },
|
|
168
|
-
],
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const analyzer = new TraceAnalyzer(trace);
|
|
172
|
-
const report = analyzer.analyze();
|
|
173
|
-
|
|
174
|
-
const costIssues = report.issues.filter((i) => i.category === "cost");
|
|
175
|
-
expect(costIssues.length).toBeGreaterThan(0);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// ─── Test #91: Warns on low cache hit rate ───
|
|
179
|
-
|
|
180
|
-
it("warns when cache hit rate is below 70%", () => {
|
|
181
|
-
const trace = createTrace({
|
|
182
|
-
summary: {
|
|
183
|
-
...createTrace().summary,
|
|
184
|
-
cacheHitRate: 0.5,
|
|
185
|
-
turnCount: 5,
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
const analyzer = new TraceAnalyzer(trace);
|
|
190
|
-
const report = analyzer.analyze();
|
|
191
|
-
|
|
192
|
-
const cacheIssues = report.issues.filter((i) => i.category === "cache");
|
|
193
|
-
expect(cacheIssues.length).toBe(1);
|
|
194
|
-
expect(cacheIssues[0].message).toContain("50.0%");
|
|
195
|
-
});
|
|
196
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Registry
|
|
3
|
-
*
|
|
4
|
-
* Central registry for named sub-agents. The registry enables:
|
|
5
|
-
* - Decoupled agent development (add agents without touching the main loop)
|
|
6
|
-
* - Prompt injection (registry summary included in the main agent's system prompt)
|
|
7
|
-
* - Lookup by name for the spawn_agent tool
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { AgentSpec } from "./agentSpec.js";
|
|
11
|
-
|
|
12
|
-
export class AgentRegistry {
|
|
13
|
-
private agents: Map<string, AgentSpec> = new Map();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Register a new agent spec. Overwrites if name already exists.
|
|
17
|
-
*/
|
|
18
|
-
register(spec: AgentSpec): void {
|
|
19
|
-
this.agents.set(spec.name, spec);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Look up an agent by name.
|
|
24
|
-
*/
|
|
25
|
-
get(name: string): AgentSpec | undefined {
|
|
26
|
-
return this.agents.get(name);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Returns all registered agent specs.
|
|
31
|
-
*/
|
|
32
|
-
getAll(): AgentSpec[] {
|
|
33
|
-
return Array.from(this.agents.values());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Returns all registered agent names.
|
|
38
|
-
*/
|
|
39
|
-
getNames(): string[] {
|
|
40
|
-
return Array.from(this.agents.keys());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Returns true if an agent with the given name exists.
|
|
45
|
-
*/
|
|
46
|
-
has(name: string): boolean {
|
|
47
|
-
return this.agents.has(name);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Generates a summary of all available agents, formatted for injection
|
|
52
|
-
* into the main agent's system prompt.
|
|
53
|
-
*/
|
|
54
|
-
getSummary(): string {
|
|
55
|
-
if (this.agents.size === 0) {
|
|
56
|
-
return "No sub-agents are currently registered.";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const lines = ["Available sub-agents (use spawn_agent tool to invoke):\n"];
|
|
60
|
-
|
|
61
|
-
for (const spec of this.agents.values()) {
|
|
62
|
-
const tools = spec.tools ? ` [tools: ${spec.tools.join(", ")}]` : " [all tools]";
|
|
63
|
-
const turns = spec.maxTurns ?? 10;
|
|
64
|
-
lines.push(` • ${spec.name}: ${spec.description}${tools} (max ${turns} turns)`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return lines.join("\n");
|
|
68
|
-
}
|
|
69
|
-
}
|
package/src/agents/agentSpec.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Specification
|
|
3
|
-
*
|
|
4
|
-
* Defines the shape of a sub-agent: its identity, capabilities, constraints,
|
|
5
|
-
* and tools. This enables decoupled agent development — new agents can be
|
|
6
|
-
* added to the registry without modifying the main agent or harness.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Describes a named sub-agent with a purpose-tuned configuration.
|
|
11
|
-
*/
|
|
12
|
-
export interface AgentSpec {
|
|
13
|
-
/** Unique name (e.g., "script_runner", "code_reviewer"). */
|
|
14
|
-
name: string;
|
|
15
|
-
|
|
16
|
-
/** Human-readable description included in the main agent's prompt. */
|
|
17
|
-
description: string;
|
|
18
|
-
|
|
19
|
-
/** Dedicated system prompt for this sub-agent. */
|
|
20
|
-
systemPrompt: string;
|
|
21
|
-
|
|
22
|
-
/** Restrict to specific tool names. If omitted, all main-agent tools are available. */
|
|
23
|
-
tools?: string[];
|
|
24
|
-
|
|
25
|
-
/** Maximum turns before the sub-agent is forcibly stopped (doom-loop protection). Default: 10. */
|
|
26
|
-
maxTurns?: number;
|
|
27
|
-
|
|
28
|
-
/** Override model for this agent (default: FAST_MODEL_DEFAULTS from same provider). */
|
|
29
|
-
model?: string;
|
|
30
|
-
|
|
31
|
-
/** Permission behavior for this agent. */
|
|
32
|
-
permissionMode?: "auto" | "ask_all";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Structured result returned by a sub-agent after completing (or failing) a task.
|
|
37
|
-
* Only this result is injected into the main agent's history — the sub-agent's
|
|
38
|
-
* full conversation is discarded to save context.
|
|
39
|
-
*/
|
|
40
|
-
export interface SubAgentResult {
|
|
41
|
-
/** The agent name from AgentSpec. */
|
|
42
|
-
agentName: string;
|
|
43
|
-
|
|
44
|
-
/** The original task description. */
|
|
45
|
-
taskDescription: string;
|
|
46
|
-
|
|
47
|
-
/** Outcome status. */
|
|
48
|
-
outcome: "success" | "failure" | "partial";
|
|
49
|
-
|
|
50
|
-
/** The final text output from the sub-agent. */
|
|
51
|
-
result: string;
|
|
52
|
-
|
|
53
|
-
/** Files created, modified, or deleted during the sub-task. */
|
|
54
|
-
filesModified: string[];
|
|
55
|
-
|
|
56
|
-
/** Total tool calls executed. */
|
|
57
|
-
toolCallCount: number;
|
|
58
|
-
|
|
59
|
-
/** Approximate token usage. */
|
|
60
|
-
tokenUsage: { prompt: number; completion: number };
|
|
61
|
-
|
|
62
|
-
/** Wall-clock duration in milliseconds. */
|
|
63
|
-
duration: number;
|
|
64
|
-
|
|
65
|
-
/** Number of turns the sub-agent ran. */
|
|
66
|
-
turnsUsed: number;
|
|
67
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Built-in Agent Specs
|
|
3
|
-
*
|
|
4
|
-
* Pre-configured sub-agents for common coding tasks. Each agent has a
|
|
5
|
-
* purpose-tuned system prompt and restricted tool access. This enables
|
|
6
|
-
* decoupled agent development — new agents are added here without
|
|
7
|
-
* touching the main agent or harness.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { AgentSpec } from "./agentSpec.js";
|
|
11
|
-
import { AgentRegistry } from "./agentRegistry.js";
|
|
12
|
-
|
|
13
|
-
// ─── Script Runner ──────────────────────────────────────────────────────────────
|
|
14
|
-
|
|
15
|
-
export const ScriptRunnerAgent: AgentSpec = {
|
|
16
|
-
name: "script_runner",
|
|
17
|
-
description: "Execute and test scripts, return stdout/stderr and exit codes",
|
|
18
|
-
systemPrompt: `You are a script execution agent. Your task is to run scripts and commands, capturing their output.
|
|
19
|
-
|
|
20
|
-
Rules:
|
|
21
|
-
- Run the commands/scripts as specified in the task
|
|
22
|
-
- Capture ALL stdout and stderr output
|
|
23
|
-
- Report the exit code
|
|
24
|
-
- If the script fails, analyze the error and report the likely cause
|
|
25
|
-
- Do NOT modify any files unless explicitly asked
|
|
26
|
-
- Summarize the results clearly at the end`,
|
|
27
|
-
tools: ["bash", "read_file"],
|
|
28
|
-
maxTurns: 8,
|
|
29
|
-
permissionMode: "auto",
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// ─── Code Reviewer ──────────────────────────────────────────────────────────────
|
|
33
|
-
|
|
34
|
-
export const CodeReviewerAgent: AgentSpec = {
|
|
35
|
-
name: "code_reviewer",
|
|
36
|
-
description: "Review code changes and suggest improvements",
|
|
37
|
-
systemPrompt: `You are a code review agent. Your task is to analyze code files and provide quality feedback.
|
|
38
|
-
|
|
39
|
-
Rules:
|
|
40
|
-
- Read the specified files and analyze them
|
|
41
|
-
- Look for: bugs, security issues, code smells, missing error handling, performance issues
|
|
42
|
-
- Check style consistency and naming conventions
|
|
43
|
-
- Provide specific, actionable suggestions with line numbers
|
|
44
|
-
- Rate overall quality: 1-5 stars
|
|
45
|
-
- Be constructive and specific — avoid vague feedback`,
|
|
46
|
-
tools: ["read_file", "bash"],
|
|
47
|
-
maxTurns: 6,
|
|
48
|
-
permissionMode: "auto",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// ─── Test Runner ────────────────────────────────────────────────────────────────
|
|
52
|
-
|
|
53
|
-
export const TestRunnerAgent: AgentSpec = {
|
|
54
|
-
name: "test_runner",
|
|
55
|
-
description: "Run test suites, diagnose failures, and suggest fixes",
|
|
56
|
-
systemPrompt: `You are a test execution agent. Your task is to run tests and analyze the results.
|
|
57
|
-
|
|
58
|
-
Rules:
|
|
59
|
-
- Execute the specified test command(s)
|
|
60
|
-
- Parse test output to identify passing, failing, and skipped tests
|
|
61
|
-
- For failures: read the relevant source files to diagnose the cause
|
|
62
|
-
- Suggest specific fixes for failing tests
|
|
63
|
-
- Report: total passes, failures, skips, and coverage if available
|
|
64
|
-
- If asked to fix tests, you may write corrected test files`,
|
|
65
|
-
tools: ["bash", "read_file", "write_file"],
|
|
66
|
-
maxTurns: 10,
|
|
67
|
-
permissionMode: "auto",
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// ─── File Analyst ───────────────────────────────────────────────────────────────
|
|
71
|
-
|
|
72
|
-
export const FileAnalystAgent: AgentSpec = {
|
|
73
|
-
name: "file_analyst",
|
|
74
|
-
description: "Analyze project structure, find patterns, count metrics",
|
|
75
|
-
systemPrompt: `You are a file analysis agent. Your task is to analyze the project structure and report findings.
|
|
76
|
-
|
|
77
|
-
Rules:
|
|
78
|
-
- Use bash commands (find, grep, wc, etc.) to analyze the project
|
|
79
|
-
- Report: file counts by type, line counts, directory structure
|
|
80
|
-
- Identify patterns: naming conventions, common imports, dependency usage
|
|
81
|
-
- Highlight anything unusual or noteworthy
|
|
82
|
-
- Present results in a clear, structured format`,
|
|
83
|
-
tools: ["bash", "read_file"],
|
|
84
|
-
maxTurns: 6,
|
|
85
|
-
permissionMode: "auto",
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// ─── Security Auditor ───────────────────────────────────────────────────────────
|
|
89
|
-
|
|
90
|
-
export const SecurityAuditorAgent: AgentSpec = {
|
|
91
|
-
name: "security_auditor",
|
|
92
|
-
description: "Run security scans and report vulnerabilities",
|
|
93
|
-
systemPrompt: `You are a security audit agent. Your task is to check for security issues in the codebase.
|
|
94
|
-
|
|
95
|
-
Rules:
|
|
96
|
-
- Check for: hardcoded secrets, SQL injection, XSS, insecure dependencies
|
|
97
|
-
- Run available security scanning tools
|
|
98
|
-
- Read configuration files for security misconfigurations
|
|
99
|
-
- Rate severity: Critical, High, Medium, Low, Info
|
|
100
|
-
- Provide remediation steps for each finding
|
|
101
|
-
- Do NOT expose actual secret values in your report`,
|
|
102
|
-
tools: ["bash", "read_file"],
|
|
103
|
-
maxTurns: 8,
|
|
104
|
-
permissionMode: "auto",
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// ─── Browser Agent ──────────────────────────────────────────────────────────────
|
|
108
|
-
|
|
109
|
-
export const BrowserAgent: AgentSpec = {
|
|
110
|
-
name: "browser_agent",
|
|
111
|
-
description: "Browse URLs, extract content, analyze web pages",
|
|
112
|
-
systemPrompt: `You are a web browsing agent. Your task is to access URLs and extract information.
|
|
113
|
-
|
|
114
|
-
Rules:
|
|
115
|
-
- Navigate to the specified URL(s)
|
|
116
|
-
- Extract text content, titles, metadata as requested
|
|
117
|
-
- Summarize the page content clearly
|
|
118
|
-
- Report any errors (404, timeouts, etc.)
|
|
119
|
-
- Do NOT submit forms or make purchases unless explicitly instructed
|
|
120
|
-
- If the page requires authentication, report that you cannot access it`,
|
|
121
|
-
tools: ["bash"],
|
|
122
|
-
maxTurns: 6,
|
|
123
|
-
permissionMode: "auto",
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// ─── Registry Factory ───────────────────────────────────────────────────────────
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Creates an AgentRegistry pre-loaded with all built-in agents.
|
|
130
|
-
*/
|
|
131
|
-
export function createDefaultAgentRegistry(): AgentRegistry {
|
|
132
|
-
const registry = new AgentRegistry();
|
|
133
|
-
|
|
134
|
-
registry.register(ScriptRunnerAgent);
|
|
135
|
-
registry.register(CodeReviewerAgent);
|
|
136
|
-
registry.register(TestRunnerAgent);
|
|
137
|
-
registry.register(FileAnalystAgent);
|
|
138
|
-
registry.register(SecurityAuditorAgent);
|
|
139
|
-
registry.register(BrowserAgent);
|
|
140
|
-
|
|
141
|
-
return registry;
|
|
142
|
-
}
|
package/src/cli/config.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The shape of the Joone configuration file (~/.joone/config.json).
|
|
6
|
-
*/
|
|
7
|
-
export interface JooneConfig {
|
|
8
|
-
provider: string;
|
|
9
|
-
model: string;
|
|
10
|
-
apiKey?: string;
|
|
11
|
-
maxTokens: number;
|
|
12
|
-
temperature: number;
|
|
13
|
-
streaming: boolean;
|
|
14
|
-
/** E2B sandbox template. If set, uses a pre-baked template (prod). If unset, uses default + lazy install (dev). */
|
|
15
|
-
sandboxTemplate?: string;
|
|
16
|
-
/** E2B API key for sandbox provisioning. */
|
|
17
|
-
e2bApiKey?: string;
|
|
18
|
-
/** OpenSandbox API key for sandbox fallback provisioning. */
|
|
19
|
-
openSandboxApiKey?: string;
|
|
20
|
-
/** OpenSandbox API Domain for fallback. */
|
|
21
|
-
openSandboxDomain?: string;
|
|
22
|
-
/** Gemini API key for SecurityScanTool (Gemini CLI inside sandbox). */
|
|
23
|
-
geminiApiKey?: string;
|
|
24
|
-
/** Valyu API key for web search. */
|
|
25
|
-
valyuApiKey?: string;
|
|
26
|
-
/** LangSmith API key for tracing (optional). */
|
|
27
|
-
langsmithApiKey?: string;
|
|
28
|
-
/** LangSmith project name (optional, default: "joone"). */
|
|
29
|
-
langsmithProject?: string;
|
|
30
|
-
/** Tool permission mode: 'auto' (no prompts), 'ask_dangerous' (prompt for destructive tools), 'ask_all' (prompt for everything). */
|
|
31
|
-
permissionMode?: "auto" | "ask_dangerous" | "ask_all";
|
|
32
|
-
/** Override model for context compaction (default: auto-selected fast model from same provider). */
|
|
33
|
-
compactModel?: string;
|
|
34
|
-
/** Override model for sub-agents (default: auto-selected fast model from same provider). */
|
|
35
|
-
subAgentModel?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Sensible defaults — Anthropic Claude as the default provider.
|
|
40
|
-
*/
|
|
41
|
-
export const DEFAULT_CONFIG: JooneConfig = {
|
|
42
|
-
provider: "anthropic",
|
|
43
|
-
model: "claude-sonnet-4-20250514",
|
|
44
|
-
maxTokens: 4096,
|
|
45
|
-
temperature: 0,
|
|
46
|
-
streaming: true,
|
|
47
|
-
permissionMode: "auto",
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Maps provider names to their expected environment variable for the API key.
|
|
52
|
-
*/
|
|
53
|
-
const PROVIDER_ENV_VARS: Record<string, string> = {
|
|
54
|
-
anthropic: "ANTHROPIC_API_KEY",
|
|
55
|
-
openai: "OPENAI_API_KEY",
|
|
56
|
-
google: "GOOGLE_API_KEY",
|
|
57
|
-
mistral: "MISTRAL_API_KEY",
|
|
58
|
-
groq: "GROQ_API_KEY",
|
|
59
|
-
deepseek: "DEEPSEEK_API_KEY",
|
|
60
|
-
fireworks: "FIREWORKS_API_KEY",
|
|
61
|
-
together: "TOGETHER_API_KEY",
|
|
62
|
-
// Ollama (local) doesn't need an API key
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Loads the Joone config from the specified path.
|
|
67
|
-
* Returns DEFAULT_CONFIG if the file does not exist.
|
|
68
|
-
* Falls back to environment variables for API key if not set in config.
|
|
69
|
-
*/
|
|
70
|
-
export function loadConfig(configPath: string): JooneConfig {
|
|
71
|
-
let config: JooneConfig;
|
|
72
|
-
|
|
73
|
-
if (!fs.existsSync(configPath)) {
|
|
74
|
-
config = { ...DEFAULT_CONFIG };
|
|
75
|
-
} else {
|
|
76
|
-
try {
|
|
77
|
-
const raw = fs.readFileSync(configPath, "utf-8");
|
|
78
|
-
const parsed = JSON.parse(raw) as Partial<JooneConfig>;
|
|
79
|
-
config = { ...DEFAULT_CONFIG, ...parsed };
|
|
80
|
-
} catch (err) {
|
|
81
|
-
console.warn(`Warning: Failed to parse config at ${configPath}. Using defaults.`);
|
|
82
|
-
config = { ...DEFAULT_CONFIG };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Env var fallback: if apiKey is missing, check the provider's env var
|
|
86
|
-
if (!config.apiKey) {
|
|
87
|
-
const envVar = PROVIDER_ENV_VARS[config.provider];
|
|
88
|
-
if (envVar && process.env[envVar]) {
|
|
89
|
-
config.apiKey = process.env[envVar];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return config;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Saves the Joone config to the specified path.
|
|
98
|
-
* Creates the parent directory if it doesn't exist.
|
|
99
|
-
* Sets restrictive file permissions (owner-only read/write) for security.
|
|
100
|
-
*/
|
|
101
|
-
export function saveConfig(configPath: string, config: JooneConfig): void {
|
|
102
|
-
const dir = path.dirname(configPath);
|
|
103
|
-
if (!fs.existsSync(dir)) {
|
|
104
|
-
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
105
|
-
}
|
|
106
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), {
|
|
107
|
-
encoding: "utf-8",
|
|
108
|
-
mode: 0o600, // Owner read/write only (Linux/macOS)
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// On Unix systems, enforce permissions even if file already existed
|
|
112
|
-
try {
|
|
113
|
-
fs.chmodSync(configPath, 0o600);
|
|
114
|
-
} catch {
|
|
115
|
-
// chmod may fail on Windows — ignore silently
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Returns the expected environment variable name for a provider's API key.
|
|
121
|
-
*/
|
|
122
|
-
export function getProviderEnvVar(provider: string): string | undefined {
|
|
123
|
-
return PROVIDER_ENV_VARS[provider];
|
|
124
|
-
}
|