feat(core): include session ID in instructions

This commit is contained in:
Dax Raad 2026-07-15 00:47:10 -04:00
commit ce636daf04
3 changed files with 49 additions and 38 deletions

View file

@ -3,10 +3,11 @@ export * as InstructionBuiltIns from "./builtins"
import { makeLocationNode } from "../effect/app-node"
import { Context, DateTime, Effect, Layer, Schema } from "effect"
import { Location } from "../location"
import { SessionSchema } from "../session/schema"
import { Instructions } from "./index"
export interface Interface {
readonly load: () => Effect.Effect<Instructions.Instructions>
readonly load: (sessionID: SessionSchema.ID) => Effect.Effect<Instructions.Instructions>
}
export class Service extends Context.Service<Service, Interface>()("@opencode/v2/InstructionBuiltIns") {}
@ -15,38 +16,45 @@ const layer = Layer.effect(
Service,
Effect.gen(function* () {
const location = yield* Location.Service
const instructions = Instructions.combine([
Instructions.make({
key: Instructions.Key.make("core/environment"),
codec: Schema.toCodecJson(Schema.String),
read: Effect.sync(() =>
[
"<env>",
` Working directory: ${location.directory}`,
` Workspace root folder: ${location.project.directory}`,
` Is directory a git repo: ${location.vcs?.type === "git" ? "yes" : "no"}`,
` Platform: ${process.platform}`,
"</env>",
].join("\n"),
return Service.of({
load: (sessionID) =>
Effect.succeed(
Instructions.combine([
Instructions.make({
key: Instructions.Key.make("core/environment"),
codec: Schema.toCodecJson(Schema.String),
read: Effect.sync(() =>
[
"<env>",
` Session ID: ${sessionID}`,
` Working directory: ${location.directory}`,
` Workspace root folder: ${location.project.directory}`,
` Is directory a git repo: ${location.vcs?.type === "git" ? "yes" : "no"}`,
` Platform: ${process.platform}`,
"</env>",
].join("\n"),
),
render: {
initial: (environment) =>
["Here is some useful information about the environment you are running in:", environment].join(
"\n",
),
changed: (_previous, environment) =>
["The environment you are running in is now:", environment].join("\n"),
},
}),
Instructions.make({
key: Instructions.Key.make("core/date"),
codec: Schema.toCodecJson(Schema.String),
read: DateTime.nowAsDate.pipe(Effect.map((date) => date.toDateString())),
render: {
initial: (date) => `Today's date: ${date}`,
changed: (_previous, date) => `Today's date is now: ${date}`,
},
}),
]),
),
render: {
initial: (environment) =>
["Here is some useful information about the environment you are running in:", environment].join("\n"),
changed: (_previous, environment) => ["The environment you are running in is now:", environment].join("\n"),
},
}),
Instructions.make({
key: Instructions.Key.make("core/date"),
codec: Schema.toCodecJson(Schema.String),
read: DateTime.nowAsDate.pipe(Effect.map((date) => date.toDateString())),
render: {
initial: (date) => `Today's date: ${date}`,
changed: (_previous, date) => `Today's date is now: ${date}`,
},
}),
])
return Service.of({ load: () => Effect.succeed(instructions) })
})
}),
)

View file

@ -145,7 +145,7 @@ const layer = Layer.effect(
const loadInstructions = (agent: AgentV2.Selection, sessionID: SessionSchema.ID) =>
Effect.all(
[
builtins.load(),
builtins.load(sessionID),
discovery.load(),
skillGuidance.load(agent),
referenceGuidance.load(),