mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
resolve merge conflicts
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { afterEach, test, expect } from "bun:test"
|
||||
import { Effect } from "effect"
|
||||
import path from "path"
|
||||
import { tmpdir } from "../fixture/fixture"
|
||||
import { provideInstance, tmpdir } from "../fixture/fixture"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { Agent } from "../../src/agent/agent"
|
||||
import { Permission } from "../../src/permission"
|
||||
@@ -11,6 +12,10 @@ function evalPerm(agent: Agent.Info | undefined, permission: string): Permission
|
||||
return Permission.evaluate(permission, "*", agent.permission).action
|
||||
}
|
||||
|
||||
function load<A>(dir: string, fn: (svc: Agent.Interface) => Effect.Effect<A>) {
|
||||
return Effect.runPromise(provideInstance(dir)(Agent.Service.use(fn)).pipe(Effect.provide(Agent.defaultLayer)))
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Instance.disposeAll()
|
||||
})
|
||||
@@ -20,7 +25,7 @@ test("returns default native agents when no config", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const agents = await Agent.list()
|
||||
const agents = await load(tmp.path, (svc) => svc.list())
|
||||
const names = agents.map((a) => a.name)
|
||||
expect(names).toContain("code") // kilocode_change
|
||||
expect(names).toContain("plan")
|
||||
@@ -42,12 +47,12 @@ test("code agent has correct default properties", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const code = await Agent.get("code")
|
||||
expect(code).toBeDefined()
|
||||
expect(code?.mode).toBe("primary")
|
||||
expect(code?.native).toBe(true)
|
||||
expect(evalPerm(code, "edit")).toBe("allow")
|
||||
expect(evalPerm(code, "bash")).toBe("ask")
|
||||
const build = await load(tmp.path, (svc) => svc.get("build"))
|
||||
expect(build).toBeDefined()
|
||||
expect(build?.mode).toBe("primary")
|
||||
expect(build?.native).toBe(true)
|
||||
expect(evalPerm(build, "edit")).toBe("allow")
|
||||
expect(evalPerm(build, "bash")).toBe("allow")
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -119,7 +124,7 @@ test("plan agent asks before edits except .kilo/plans/* and .opencode/plans/*",
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const plan = await Agent.get("plan")
|
||||
const plan = await load(tmp.path, (svc) => svc.get("plan"))
|
||||
expect(plan).toBeDefined()
|
||||
// Wildcard requires permission
|
||||
expect(evalPerm(plan, "edit")).toBe("ask")
|
||||
@@ -139,7 +144,7 @@ test("explore agent denies edit and write", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const explore = await Agent.get("explore")
|
||||
const explore = await load(tmp.path, (svc) => svc.get("explore"))
|
||||
expect(explore).toBeDefined()
|
||||
expect(explore?.mode).toBe("subagent")
|
||||
expect(evalPerm(explore, "edit")).toBe("deny")
|
||||
@@ -155,7 +160,7 @@ test("explore agent asks for external directories and allows Truncate.GLOB", asy
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const explore = await Agent.get("explore")
|
||||
const explore = await load(tmp.path, (svc) => svc.get("explore"))
|
||||
expect(explore).toBeDefined()
|
||||
expect(Permission.evaluate("external_directory", "/some/other/path", explore!.permission).action).toBe("ask")
|
||||
expect(Permission.evaluate("external_directory", Truncate.GLOB, explore!.permission).action).toBe("allow")
|
||||
@@ -168,7 +173,7 @@ test("general agent denies todo tools", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const general = await Agent.get("general")
|
||||
const general = await load(tmp.path, (svc) => svc.get("general"))
|
||||
expect(general).toBeDefined()
|
||||
expect(general?.mode).toBe("subagent")
|
||||
expect(general?.hidden).toBeUndefined()
|
||||
@@ -182,7 +187,7 @@ test("compaction agent denies all permissions", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const compaction = await Agent.get("compaction")
|
||||
const compaction = await load(tmp.path, (svc) => svc.get("compaction"))
|
||||
expect(compaction).toBeDefined()
|
||||
expect(compaction?.hidden).toBe(true)
|
||||
expect(evalPerm(compaction, "bash")).toBe("deny")
|
||||
@@ -208,7 +213,7 @@ test("custom agent from config creates new agent", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const custom = await Agent.get("my_custom_agent")
|
||||
const custom = await load(tmp.path, (svc) => svc.get("my_custom_agent"))
|
||||
expect(custom).toBeDefined()
|
||||
expect(String(custom?.model?.providerID)).toBe("openai")
|
||||
expect(String(custom?.model?.modelID)).toBe("gpt-4")
|
||||
@@ -240,11 +245,11 @@ test("custom agent config overrides native agent properties", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(code).toBeDefined()
|
||||
expect(String(code?.model?.providerID)).toBe("anthropic")
|
||||
expect(String(code?.model?.modelID)).toBe("claude-3")
|
||||
expect(code?.description).toBe("Custom code agent")
|
||||
expect(code?.description).toBe("Custom build agent")
|
||||
expect(code?.temperature).toBe(0.7)
|
||||
expect(code?.color).toBe("#FF0000")
|
||||
expect(code?.native).toBe(true)
|
||||
@@ -264,9 +269,9 @@ test("agent disable removes agent from list", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const explore = await Agent.get("explore")
|
||||
const explore = await load(tmp.path, (svc) => svc.get("explore"))
|
||||
expect(explore).toBeUndefined()
|
||||
const agents = await Agent.list()
|
||||
const agents = await load(tmp.path, (svc) => svc.list())
|
||||
const names = agents.map((a) => a.name)
|
||||
expect(names).not.toContain("explore")
|
||||
},
|
||||
@@ -293,7 +298,7 @@ test("agent permission config merges with defaults", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(code).toBeDefined()
|
||||
// Specific pattern is denied
|
||||
expect(Permission.evaluate("bash", "rm -rf *", code!.permission).action).toBe("deny")
|
||||
@@ -316,7 +321,7 @@ test("global permission config applies to all agents", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(code).toBeDefined()
|
||||
expect(evalPerm(code, "bash")).toBe("deny")
|
||||
// kilocode_change end
|
||||
@@ -338,8 +343,8 @@ test("agent steps/maxSteps config sets steps property", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const code = await Agent.get("code") // kilocode_change
|
||||
const plan = await Agent.get("plan")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code")) // kilocode_change
|
||||
const plan = await load(tmp.path, (svc) => svc.get("plan"))
|
||||
expect(code?.steps).toBe(50) // kilocode_change
|
||||
expect(plan?.steps).toBe(100)
|
||||
},
|
||||
@@ -357,7 +362,7 @@ test("agent mode can be overridden", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const explore = await Agent.get("explore")
|
||||
const explore = await load(tmp.path, (svc) => svc.get("explore"))
|
||||
expect(explore?.mode).toBe("primary")
|
||||
},
|
||||
})
|
||||
@@ -375,8 +380,8 @@ test("agent name can be overridden", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
expect(code?.name).toBe("Coder")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(code?.name).toBe("Builder")
|
||||
// kilocode_change end
|
||||
},
|
||||
})
|
||||
@@ -394,7 +399,7 @@ test("agent prompt can be set from config", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(code?.prompt).toBe("Custom system prompt")
|
||||
// kilocode_change end
|
||||
},
|
||||
@@ -416,7 +421,7 @@ test("unknown agent properties are placed into options", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(code?.options.random_property).toBe("hello")
|
||||
expect(code?.options.another_random).toBe(123)
|
||||
// kilocode_change end
|
||||
@@ -443,7 +448,7 @@ test("agent options merge correctly", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(code?.options.custom_option).toBe(true)
|
||||
expect(code?.options.another_option).toBe("value")
|
||||
// kilocode_change end
|
||||
@@ -469,8 +474,8 @@ test("multiple custom agents can be defined", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const agentA = await Agent.get("agent_a")
|
||||
const agentB = await Agent.get("agent_b")
|
||||
const agentA = await load(tmp.path, (svc) => svc.get("agent_a"))
|
||||
const agentB = await load(tmp.path, (svc) => svc.get("agent_b"))
|
||||
expect(agentA?.description).toBe("Agent A")
|
||||
expect(agentA?.mode).toBe("subagent")
|
||||
expect(agentB?.description).toBe("Agent B")
|
||||
@@ -498,7 +503,7 @@ test("Agent.list keeps the default agent first and sorts the rest by name", asyn
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const names = (await Agent.list()).map((a) => a.name)
|
||||
const names = (await load(tmp.path, (svc) => svc.list())).map((a) => a.name)
|
||||
expect(names[0]).toBe("plan")
|
||||
expect(names.slice(1)).toEqual(names.slice(1).toSorted((a, b) => a.localeCompare(b)))
|
||||
},
|
||||
@@ -510,7 +515,7 @@ test("Agent.get returns undefined for non-existent agent", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const nonExistent = await Agent.get("does_not_exist")
|
||||
const nonExistent = await load(tmp.path, (svc) => svc.get("does_not_exist"))
|
||||
expect(nonExistent).toBeUndefined()
|
||||
},
|
||||
})
|
||||
@@ -522,7 +527,7 @@ test("default permission includes doom_loop and external_directory as ask", asyn
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(evalPerm(code, "doom_loop")).toBe("ask")
|
||||
expect(evalPerm(code, "external_directory")).toBe("ask")
|
||||
// kilocode_change end
|
||||
@@ -536,7 +541,7 @@ test("webfetch is allowed by default", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(evalPerm(code, "webfetch")).toBe("allow")
|
||||
// kilocode_change end
|
||||
},
|
||||
@@ -562,7 +567,7 @@ test("legacy tools config converts to permissions", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(evalPerm(code, "bash")).toBe("deny")
|
||||
expect(evalPerm(code, "read")).toBe("deny")
|
||||
// kilocode_change end
|
||||
@@ -588,7 +593,7 @@ test("legacy tools config maps write/edit/patch/multiedit to edit permission", a
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const code = await Agent.get("code")
|
||||
const code = await load(tmp.path, (svc) => svc.get("code"))
|
||||
expect(evalPerm(code, "edit")).toBe("deny")
|
||||
// kilocode_change end
|
||||
},
|
||||
@@ -608,7 +613,7 @@ test("Truncate.GLOB is allowed even when user denies external_directory globally
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const build = await Agent.get("code")
|
||||
const build = await load(tmp.path, (svc) => svc.get("code"))
|
||||
// kilocode_change end
|
||||
expect(Permission.evaluate("external_directory", Truncate.GLOB, build!.permission).action).toBe("allow")
|
||||
expect(Permission.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("deny")
|
||||
@@ -636,7 +641,7 @@ test("Truncate.GLOB is allowed even when user denies external_directory per-agen
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const build = await Agent.get("code")
|
||||
const build = await load(tmp.path, (svc) => svc.get("code"))
|
||||
// kilocode_change end
|
||||
expect(Permission.evaluate("external_directory", Truncate.GLOB, build!.permission).action).toBe("allow")
|
||||
expect(Permission.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("deny")
|
||||
@@ -661,7 +666,7 @@ test("explicit Truncate.GLOB deny is respected", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change start - renamed from "build" to "code"
|
||||
const build = await Agent.get("code")
|
||||
const build = await load(tmp.path, (svc) => svc.get("code"))
|
||||
// kilocode_change end
|
||||
expect(Permission.evaluate("external_directory", Truncate.GLOB, build!.permission).action).toBe("deny")
|
||||
expect(Permission.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("deny")
|
||||
@@ -694,7 +699,7 @@ description: Permission skill.
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const build = await Agent.get("build")
|
||||
const build = await load(tmp.path, (svc) => svc.get("build"))
|
||||
const skillDir = path.join(tmp.path, ".kilo", "skill", "perm-skill") // kilocode_change: .kilo is primary
|
||||
const target = path.join(skillDir, "reference", "notes.md")
|
||||
expect(Permission.evaluate("external_directory", target, build!.permission).action).toBe("allow")
|
||||
@@ -710,7 +715,7 @@ test("defaultAgent returns build when no default_agent config", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const agent = await Agent.defaultAgent()
|
||||
const agent = await load(tmp.path, (svc) => svc.defaultAgent())
|
||||
expect(agent).toBe("code") // kilocode_change
|
||||
},
|
||||
})
|
||||
@@ -725,7 +730,7 @@ test("defaultAgent respects default_agent config set to plan", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const agent = await Agent.defaultAgent()
|
||||
const agent = await load(tmp.path, (svc) => svc.defaultAgent())
|
||||
expect(agent).toBe("plan")
|
||||
},
|
||||
})
|
||||
@@ -745,7 +750,7 @@ test("defaultAgent respects default_agent config set to custom agent with mode a
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const agent = await Agent.defaultAgent()
|
||||
const agent = await load(tmp.path, (svc) => svc.defaultAgent())
|
||||
expect(agent).toBe("my_custom")
|
||||
},
|
||||
})
|
||||
@@ -760,7 +765,7 @@ test("defaultAgent throws when default_agent points to subagent", async () => {
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
await expect(Agent.defaultAgent()).rejects.toThrow('default agent "explore" is a subagent')
|
||||
await expect(load(tmp.path, (svc) => svc.defaultAgent())).rejects.toThrow('default agent "explore" is a subagent')
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -774,7 +779,7 @@ test("defaultAgent throws when default_agent points to hidden agent", async () =
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
await expect(Agent.defaultAgent()).rejects.toThrow('default agent "compaction" is hidden')
|
||||
await expect(load(tmp.path, (svc) => svc.defaultAgent())).rejects.toThrow('default agent "compaction" is hidden')
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -788,7 +793,9 @@ test("defaultAgent throws when default_agent points to non-existent agent", asyn
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
await expect(Agent.defaultAgent()).rejects.toThrow('default agent "does_not_exist" not found')
|
||||
await expect(load(tmp.path, (svc) => svc.defaultAgent())).rejects.toThrow(
|
||||
'default agent "does_not_exist" not found',
|
||||
)
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -808,7 +815,7 @@ test("defaultAgent returns plan when code is disabled and default_agent not set"
|
||||
await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
const agent = await Agent.defaultAgent()
|
||||
const agent = await load(tmp.path, (svc) => svc.defaultAgent())
|
||||
// kilocode_change - code is disabled, so it should return plan (next primary agent)
|
||||
expect(agent).toBe("plan")
|
||||
},
|
||||
@@ -833,7 +840,7 @@ test("defaultAgent throws when all primary agents are disabled", async () => {
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
// kilocode_change - all primary agents are disabled
|
||||
await expect(Agent.defaultAgent()).rejects.toThrow("no primary visible agent found")
|
||||
await expect(load(tmp.path, (svc) => svc.defaultAgent())).rejects.toThrow("no primary visible agent found")
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user