sync
This commit is contained in:
parent
8ca4343053
commit
aeca8051d5
4 changed files with 51 additions and 37 deletions
|
|
@ -42,20 +42,19 @@ export namespace Agent {
|
||||||
|
|
||||||
const state = Instance.state(async () => {
|
const state = Instance.state(async () => {
|
||||||
const cfg = await Config.get()
|
const cfg = await Config.get()
|
||||||
const permission: PermissionNext.Ruleset = PermissionNext.merge(
|
|
||||||
PermissionNext.fromConfig({
|
const defaults = PermissionNext.fromConfig({
|
||||||
"*": "allow",
|
"*": "allow",
|
||||||
doom_loop: "ask",
|
doom_loop: "ask",
|
||||||
external_directory: "ask",
|
external_directory: "ask",
|
||||||
}),
|
})
|
||||||
PermissionNext.fromConfig(cfg.permission ?? {}),
|
const user = PermissionNext.fromConfig(cfg.permission ?? {})
|
||||||
)
|
|
||||||
|
|
||||||
const result: Record<string, Info> = {
|
const result: Record<string, Info> = {
|
||||||
build: {
|
build: {
|
||||||
name: "build",
|
name: "build",
|
||||||
options: {},
|
options: {},
|
||||||
permission,
|
permission: PermissionNext.merge(defaults, user),
|
||||||
mode: "primary",
|
mode: "primary",
|
||||||
native: true,
|
native: true,
|
||||||
},
|
},
|
||||||
|
|
@ -63,13 +62,14 @@ export namespace Agent {
|
||||||
name: "plan",
|
name: "plan",
|
||||||
options: {},
|
options: {},
|
||||||
permission: PermissionNext.merge(
|
permission: PermissionNext.merge(
|
||||||
permission,
|
defaults,
|
||||||
PermissionNext.fromConfig({
|
PermissionNext.fromConfig({
|
||||||
edit: {
|
edit: {
|
||||||
"*": "deny",
|
"*": "deny",
|
||||||
".opencode/plan/*.md": "allow",
|
".opencode/plan/*.md": "allow",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
user,
|
||||||
),
|
),
|
||||||
mode: "primary",
|
mode: "primary",
|
||||||
native: true,
|
native: true,
|
||||||
|
|
@ -78,11 +78,12 @@ export namespace Agent {
|
||||||
name: "general",
|
name: "general",
|
||||||
description: `General-purpose agent for researching complex questions and executing multi-step tasks. Use this agent to execute multiple units of work in parallel.`,
|
description: `General-purpose agent for researching complex questions and executing multi-step tasks. Use this agent to execute multiple units of work in parallel.`,
|
||||||
permission: PermissionNext.merge(
|
permission: PermissionNext.merge(
|
||||||
permission,
|
defaults,
|
||||||
PermissionNext.fromConfig({
|
PermissionNext.fromConfig({
|
||||||
todoread: "deny",
|
todoread: "deny",
|
||||||
todowrite: "deny",
|
todowrite: "deny",
|
||||||
}),
|
}),
|
||||||
|
user,
|
||||||
),
|
),
|
||||||
options: {},
|
options: {},
|
||||||
mode: "subagent",
|
mode: "subagent",
|
||||||
|
|
@ -92,7 +93,7 @@ export namespace Agent {
|
||||||
explore: {
|
explore: {
|
||||||
name: "explore",
|
name: "explore",
|
||||||
permission: PermissionNext.merge(
|
permission: PermissionNext.merge(
|
||||||
permission,
|
defaults,
|
||||||
PermissionNext.fromConfig({
|
PermissionNext.fromConfig({
|
||||||
"*": "deny",
|
"*": "deny",
|
||||||
grep: "allow",
|
grep: "allow",
|
||||||
|
|
@ -104,6 +105,7 @@ export namespace Agent {
|
||||||
codesearch: "allow",
|
codesearch: "allow",
|
||||||
read: "allow",
|
read: "allow",
|
||||||
}),
|
}),
|
||||||
|
user,
|
||||||
),
|
),
|
||||||
description: `Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.`,
|
description: `Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.`,
|
||||||
prompt: PROMPT_EXPLORE,
|
prompt: PROMPT_EXPLORE,
|
||||||
|
|
@ -117,9 +119,13 @@ export namespace Agent {
|
||||||
native: true,
|
native: true,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
prompt: PROMPT_COMPACTION,
|
prompt: PROMPT_COMPACTION,
|
||||||
permission: PermissionNext.fromConfig({
|
permission: PermissionNext.merge(
|
||||||
"*": "deny",
|
defaults,
|
||||||
}),
|
PermissionNext.fromConfig({
|
||||||
|
"*": "deny",
|
||||||
|
}),
|
||||||
|
user,
|
||||||
|
),
|
||||||
options: {},
|
options: {},
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
|
|
@ -128,9 +134,13 @@ export namespace Agent {
|
||||||
options: {},
|
options: {},
|
||||||
native: true,
|
native: true,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
permission: PermissionNext.fromConfig({
|
permission: PermissionNext.merge(
|
||||||
"*": "deny",
|
defaults,
|
||||||
}),
|
PermissionNext.fromConfig({
|
||||||
|
"*": "deny",
|
||||||
|
}),
|
||||||
|
user,
|
||||||
|
),
|
||||||
prompt: PROMPT_TITLE,
|
prompt: PROMPT_TITLE,
|
||||||
},
|
},
|
||||||
summary: {
|
summary: {
|
||||||
|
|
@ -139,9 +149,13 @@ export namespace Agent {
|
||||||
options: {},
|
options: {},
|
||||||
native: true,
|
native: true,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
permission: PermissionNext.fromConfig({
|
permission: PermissionNext.merge(
|
||||||
"*": "deny",
|
defaults,
|
||||||
}),
|
PermissionNext.fromConfig({
|
||||||
|
"*": "deny",
|
||||||
|
}),
|
||||||
|
user,
|
||||||
|
),
|
||||||
prompt: PROMPT_SUMMARY,
|
prompt: PROMPT_SUMMARY,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +170,7 @@ export namespace Agent {
|
||||||
item = result[key] = {
|
item = result[key] = {
|
||||||
name: key,
|
name: key,
|
||||||
mode: "all",
|
mode: "all",
|
||||||
permission,
|
permission: PermissionNext.merge(defaults, user),
|
||||||
options: {},
|
options: {},
|
||||||
native: false,
|
native: false,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,10 +161,9 @@ export function PermissionPrompt(props: { request: PermissionRequest }) {
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={props.request.permission === "task"}>
|
<Match when={props.request.permission === "task"}>
|
||||||
<TextBody
|
<TextBody
|
||||||
icon="◉"
|
icon="#"
|
||||||
title={
|
title={`${Locale.titlecase((input().subagent_type as string) ?? "Unknown")} Task`}
|
||||||
`${Locale.titlecase(input().subagent_type as string)} Task "` + (input().description ?? "") + `"`
|
description={"◉ " + input().description}
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={props.request.permission === "webfetch"}>
|
<Match when={props.request.permission === "webfetch"}>
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ export namespace SessionProcessor {
|
||||||
JSON.stringify(p.state.input) === JSON.stringify(value.input),
|
JSON.stringify(p.state.input) === JSON.stringify(value.input),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
const agent = await Agent.get(input.assistantMessage.mode)
|
const agent = await Agent.get(input.assistantMessage.agent)
|
||||||
await PermissionNext.ask({
|
await PermissionNext.ask({
|
||||||
permission: "doom_loop",
|
permission: "doom_loop",
|
||||||
patterns: [value.toolName],
|
patterns: [value.toolName],
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,7 @@ export namespace SessionPrompt {
|
||||||
using _ = defer(() => cancel(sessionID))
|
using _ = defer(() => cancel(sessionID))
|
||||||
|
|
||||||
let step = 0
|
let step = 0
|
||||||
|
const session = await Session.get(sessionID)
|
||||||
while (true) {
|
while (true) {
|
||||||
SessionStatus.set(sessionID, { type: "busy" })
|
SessionStatus.set(sessionID, { type: "busy" })
|
||||||
log.info("loop", { step, sessionID })
|
log.info("loop", { step, sessionID })
|
||||||
|
|
@ -277,7 +278,7 @@ export namespace SessionPrompt {
|
||||||
step++
|
step++
|
||||||
if (step === 1)
|
if (step === 1)
|
||||||
ensureTitle({
|
ensureTitle({
|
||||||
session: await Session.get(sessionID),
|
session,
|
||||||
modelID: lastUser.model.modelID,
|
modelID: lastUser.model.modelID,
|
||||||
providerID: lastUser.model.providerID,
|
providerID: lastUser.model.providerID,
|
||||||
message: msgs.find((m) => m.info.role === "user")!,
|
message: msgs.find((m) => m.info.role === "user")!,
|
||||||
|
|
@ -519,7 +520,7 @@ export namespace SessionPrompt {
|
||||||
})
|
})
|
||||||
const tools = await resolveTools({
|
const tools = await resolveTools({
|
||||||
agent,
|
agent,
|
||||||
sessionID,
|
session,
|
||||||
model,
|
model,
|
||||||
tools: lastUser.tools,
|
tools: lastUser.tools,
|
||||||
processor,
|
processor,
|
||||||
|
|
@ -589,7 +590,7 @@ export namespace SessionPrompt {
|
||||||
async function resolveTools(input: {
|
async function resolveTools(input: {
|
||||||
agent: Agent.Info
|
agent: Agent.Info
|
||||||
model: Provider.Model
|
model: Provider.Model
|
||||||
sessionID: string
|
session: Session.Info
|
||||||
tools?: Record<string, boolean>
|
tools?: Record<string, boolean>
|
||||||
processor: SessionProcessor.Info
|
processor: SessionProcessor.Info
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -606,7 +607,7 @@ export namespace SessionPrompt {
|
||||||
"tool.execute.before",
|
"tool.execute.before",
|
||||||
{
|
{
|
||||||
tool: item.id,
|
tool: item.id,
|
||||||
sessionID: input.sessionID,
|
sessionID: input.session.id,
|
||||||
callID: options.toolCallId,
|
callID: options.toolCallId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -614,7 +615,7 @@ export namespace SessionPrompt {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
const ctx: Tool.Context = {
|
const ctx: Tool.Context = {
|
||||||
sessionID: input.sessionID,
|
sessionID: input.session.id,
|
||||||
abort: options.abortSignal!,
|
abort: options.abortSignal!,
|
||||||
messageID: input.processor.message.id,
|
messageID: input.processor.message.id,
|
||||||
callID: options.toolCallId,
|
callID: options.toolCallId,
|
||||||
|
|
@ -640,7 +641,7 @@ export namespace SessionPrompt {
|
||||||
async ask(req) {
|
async ask(req) {
|
||||||
await PermissionNext.ask({
|
await PermissionNext.ask({
|
||||||
...req,
|
...req,
|
||||||
sessionID: input.sessionID,
|
sessionID: input.session.parentID ?? input.session.id,
|
||||||
tool: { messageID: input.processor.message.id, callID: options.toolCallId },
|
tool: { messageID: input.processor.message.id, callID: options.toolCallId },
|
||||||
ruleset: input.agent.permission,
|
ruleset: input.agent.permission,
|
||||||
})
|
})
|
||||||
|
|
@ -651,7 +652,7 @@ export namespace SessionPrompt {
|
||||||
"tool.execute.after",
|
"tool.execute.after",
|
||||||
{
|
{
|
||||||
tool: item.id,
|
tool: item.id,
|
||||||
sessionID: input.sessionID,
|
sessionID: input.session.id,
|
||||||
callID: options.toolCallId,
|
callID: options.toolCallId,
|
||||||
},
|
},
|
||||||
result,
|
result,
|
||||||
|
|
@ -676,7 +677,7 @@ export namespace SessionPrompt {
|
||||||
"tool.execute.before",
|
"tool.execute.before",
|
||||||
{
|
{
|
||||||
tool: key,
|
tool: key,
|
||||||
sessionID: input.sessionID,
|
sessionID: input.session.id,
|
||||||
callID: opts.toolCallId,
|
callID: opts.toolCallId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -689,7 +690,7 @@ export namespace SessionPrompt {
|
||||||
"tool.execute.after",
|
"tool.execute.after",
|
||||||
{
|
{
|
||||||
tool: key,
|
tool: key,
|
||||||
sessionID: input.sessionID,
|
sessionID: input.session.id,
|
||||||
callID: opts.toolCallId,
|
callID: opts.toolCallId,
|
||||||
},
|
},
|
||||||
result,
|
result,
|
||||||
|
|
@ -704,7 +705,7 @@ export namespace SessionPrompt {
|
||||||
} else if (contentItem.type === "image") {
|
} else if (contentItem.type === "image") {
|
||||||
attachments.push({
|
attachments.push({
|
||||||
id: Identifier.ascending("part"),
|
id: Identifier.ascending("part"),
|
||||||
sessionID: input.sessionID,
|
sessionID: input.session.id,
|
||||||
messageID: input.processor.message.id,
|
messageID: input.processor.message.id,
|
||||||
type: "file",
|
type: "file",
|
||||||
mime: contentItem.mimeType,
|
mime: contentItem.mimeType,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue