|
1 | | -import { Ripgrep } from "../file/ripgrep" |
| 1 | +import { Context, Effect, Layer } from "effect" |
2 | 2 |
|
3 | 3 | import { Instance } from "../project/instance" |
4 | 4 |
|
@@ -33,44 +33,52 @@ export namespace SystemPrompt { |
33 | 33 | return [PROMPT_DEFAULT] |
34 | 34 | } |
35 | 35 |
|
36 | | - export async function environment(model: Provider.Model) { |
37 | | - const project = Instance.project |
38 | | - return [ |
39 | | - [ |
40 | | - `You are powered by the model named ${model.api.id}. The exact model ID is ${model.providerID}/${model.api.id}`, |
41 | | - `Here is some useful information about the environment you are running in:`, |
42 | | - `<env>`, |
43 | | - ` Working directory: ${Instance.directory}`, |
44 | | - ` Workspace root folder: ${Instance.worktree}`, |
45 | | - ` Is directory a git repo: ${project.vcs === "git" ? "yes" : "no"}`, |
46 | | - ` Platform: ${process.platform}`, |
47 | | - ` Today's date: ${new Date().toDateString()}`, |
48 | | - `</env>`, |
49 | | - `<directories>`, |
50 | | - ` ${ |
51 | | - project.vcs === "git" && false |
52 | | - ? await Ripgrep.tree({ |
53 | | - cwd: Instance.directory, |
54 | | - limit: 50, |
55 | | - }) |
56 | | - : "" |
57 | | - }`, |
58 | | - `</directories>`, |
59 | | - ].join("\n"), |
60 | | - ] |
| 36 | + export interface Interface { |
| 37 | + readonly environment: (model: Provider.Model) => string[] |
| 38 | + readonly skills: (agent: Agent.Info) => Effect.Effect<string | undefined> |
61 | 39 | } |
62 | 40 |
|
63 | | - export async function skills(agent: Agent.Info) { |
64 | | - if (Permission.disabled(["skill"], agent.permission).has("skill")) return |
| 41 | + export class Service extends Context.Service<Service, Interface>()("@opencode/SystemPrompt") {} |
65 | 42 |
|
66 | | - const list = await Skill.available(agent) |
| 43 | + export const layer = Layer.effect( |
| 44 | + Service, |
| 45 | + Effect.gen(function* () { |
| 46 | + const skill = yield* Skill.Service |
67 | 47 |
|
68 | | - return [ |
69 | | - "Skills provide specialized instructions and workflows for specific tasks.", |
70 | | - "Use the skill tool to load a skill when a task matches its description.", |
71 | | - // the agents seem to ingest the information about skills a bit better if we present a more verbose |
72 | | - // version of them here and a less verbose version in tool description, rather than vice versa. |
73 | | - Skill.fmt(list, { verbose: true }), |
74 | | - ].join("\n") |
75 | | - } |
| 48 | + return Service.of({ |
| 49 | + environment(model) { |
| 50 | + const project = Instance.project |
| 51 | + return [ |
| 52 | + [ |
| 53 | + `You are powered by the model named ${model.api.id}. The exact model ID is ${model.providerID}/${model.api.id}`, |
| 54 | + `Here is some useful information about the environment you are running in:`, |
| 55 | + `<env>`, |
| 56 | + ` Working directory: ${Instance.directory}`, |
| 57 | + ` Workspace root folder: ${Instance.worktree}`, |
| 58 | + ` Is directory a git repo: ${project.vcs === "git" ? "yes" : "no"}`, |
| 59 | + ` Platform: ${process.platform}`, |
| 60 | + ` Today's date: ${new Date().toDateString()}`, |
| 61 | + `</env>`, |
| 62 | + ].join("\n"), |
| 63 | + ] |
| 64 | + }, |
| 65 | + |
| 66 | + skills: Effect.fn("SystemPrompt.skills")(function* (agent: Agent.Info) { |
| 67 | + if (Permission.disabled(["skill"], agent.permission).has("skill")) return |
| 68 | + |
| 69 | + const list = yield* skill.available(agent) |
| 70 | + |
| 71 | + return [ |
| 72 | + "Skills provide specialized instructions and workflows for specific tasks.", |
| 73 | + "Use the skill tool to load a skill when a task matches its description.", |
| 74 | + // the agents seem to ingest the information about skills a bit better if we present a more verbose |
| 75 | + // version of them here and a less verbose version in tool description, rather than vice versa. |
| 76 | + Skill.fmt(list, { verbose: true }), |
| 77 | + ].join("\n") |
| 78 | + }), |
| 79 | + }) |
| 80 | + }), |
| 81 | + ) |
| 82 | + |
| 83 | + export const defaultLayer = layer.pipe(Layer.provide(Skill.defaultLayer)) |
76 | 84 | } |
0 commit comments