mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
fix(core): ignore pure instruction reorders mid-session (#60918)
This commit is contained in:
committed by
GitHub
Unverified
parent
bf544cd419
commit
3960ebb5b9
@@ -131,7 +131,7 @@ function renderUpdate(previous: ReadonlyArray<File>, current: ReadonlyArray<File
|
||||
(file) => file.path,
|
||||
(before, after) => before.content !== after.content,
|
||||
)
|
||||
return [
|
||||
const parts = [
|
||||
...changes.removed.map((file) => `The instructions from ${file.path} no longer apply.`),
|
||||
...changes.added.map((file) => `New instructions apply from:\n${render([file])}`),
|
||||
...changes.changed.map(({ previous: before, current: after }) => {
|
||||
@@ -145,5 +145,6 @@ function renderUpdate(previous: ReadonlyArray<File>, current: ReadonlyArray<File
|
||||
const replacement = `The instructions changed:\n${render([after])}`
|
||||
return diff.length < replacement.length ? diff : replacement
|
||||
}),
|
||||
].join("\n\n")
|
||||
]
|
||||
return parts.length === 0 ? undefined : parts.join("\n\n")
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export declare namespace Source {
|
||||
readonly read: Effect.Effect<A | Unavailable | Removed>
|
||||
readonly render: {
|
||||
readonly initial: (current: A) => string
|
||||
readonly changed: (previous: A, current: A) => string
|
||||
readonly changed: (previous: A, current: A) => string | undefined
|
||||
readonly removed?: (previous: A) => string
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,8 @@ export function make<A>(source: Source.Definition<A>): List {
|
||||
const after = decodeValue(current)
|
||||
if (after === undefined) return undefined
|
||||
if (before === undefined) return initial(after)
|
||||
return requireText(source.key, "changed", source.render.changed(before, after))
|
||||
const text = source.render.changed(before, after)
|
||||
return text === undefined ? undefined : requireText(source.key, "changed", text)
|
||||
},
|
||||
removed: (previous) => {
|
||||
const decoded = decodeValue(previous)
|
||||
|
||||
@@ -7,6 +7,7 @@ import { LayerNode } from "@opencode/util/effect/layer-node"
|
||||
import { Bus } from "@opencode/core/bus"
|
||||
import { Event } from "@opencode/schema/event"
|
||||
import { EventTable } from "@opencode/core/event/sql"
|
||||
import { InstructionDiscovery } from "@opencode/core/instruction-discovery"
|
||||
import { Instructions } from "@opencode/core/instructions/index"
|
||||
import { Project } from "@opencode/core/project"
|
||||
import { ProjectTable } from "@opencode/core/project/sql"
|
||||
@@ -23,7 +24,7 @@ import {
|
||||
import { testEffect } from "./lib/effect"
|
||||
|
||||
const it = testEffect(
|
||||
AppNodeBuilder.build(LayerNode.group([Database.node, Bus.node, SessionProjector.node]), [
|
||||
AppNodeBuilder.build(LayerNode.group([Database.node, Bus.node, SessionProjector.node, InstructionDiscovery.node]), [
|
||||
Bus.node.replace(Bus.configured({ persist: true })),
|
||||
]),
|
||||
)
|
||||
@@ -228,6 +229,29 @@ describe("InstructionState", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("records reordered instructions without emitting update text", () =>
|
||||
Effect.gen(function* () {
|
||||
const sessionID = SessionSchema.ID.make("ses_instruction_reorder")
|
||||
const { db, events } = yield* setup(sessionID)
|
||||
const discovery = yield* InstructionDiscovery.Service
|
||||
const first = new InstructionDiscovery.File({ path: "/instructions/first.md", content: "one" })
|
||||
const second = new InstructionDiscovery.File({ path: "/instructions/second.md", content: "two" })
|
||||
const arrange = (files: InstructionDiscovery.File[]) =>
|
||||
discovery.transform((editor) => {
|
||||
for (const file of files) editor.add(file)
|
||||
})
|
||||
|
||||
const initial = yield* arrange([first, second])
|
||||
yield* InstructionState.prepare(db, events, yield* discovery.load(), sessionID)
|
||||
yield* initial.dispose
|
||||
yield* arrange([second, first])
|
||||
yield* InstructionState.prepare(db, events, yield* discovery.load(), sessionID)
|
||||
|
||||
expect((yield* instructionEvents(db, sessionID)).map((event) => event.data.text)).toEqual([undefined, undefined])
|
||||
expect(yield* db.select().from(SessionMessageTable).all().pipe(Effect.orDie)).toEqual([])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("keeps no-op observations free of events and blobs", () =>
|
||||
Effect.gen(function* () {
|
||||
const sessionID = SessionSchema.ID.make("ses_instruction_noop")
|
||||
|
||||
@@ -8,7 +8,7 @@ const source = (input: {
|
||||
key: string
|
||||
value: string | Instructions.Unavailable | Instructions.Removed
|
||||
initial?: (value: string) => string
|
||||
changed?: (previous: string, current: string) => string
|
||||
changed?: (previous: string, current: string) => string | undefined
|
||||
removed?: (value: string) => string
|
||||
}) =>
|
||||
Instructions.make({
|
||||
@@ -202,12 +202,19 @@ describe("Instructions", () => {
|
||||
).toThrow(new Instructions.DuplicateKeyError({ key: key("core/date") }))
|
||||
})
|
||||
|
||||
test("rejects empty model-visible renderings", () => {
|
||||
const instructions = source({ key: "core/empty", value: "value", initial: () => "" })
|
||||
test("rejects empty model-visible renderings while allowing silent updates", () => {
|
||||
const empty = source({ key: "core/empty", value: "value", initial: () => "", changed: () => "" })
|
||||
const silent = source({ key: "core/silent", value: "value", changed: () => undefined })
|
||||
|
||||
expect(() => Instructions.renderInitial(instructions, { "core/empty": "value" })).toThrow(
|
||||
expect(() => Instructions.renderInitial(empty, { "core/empty": "value" })).toThrow(
|
||||
"Instruction source core/empty rendered an empty initial",
|
||||
)
|
||||
expect(() =>
|
||||
Instructions.renderUpdate(empty, { "core/empty": "before" }, { "core/empty": Option.some("after") }),
|
||||
).toThrow("Instruction source core/empty rendered an empty changed")
|
||||
expect(
|
||||
Instructions.renderUpdate(silent, { "core/silent": "before" }, { "core/silent": Option.some("after") }),
|
||||
).toBe("")
|
||||
})
|
||||
|
||||
test("diffs list values by key", () => {
|
||||
|
||||
Reference in New Issue
Block a user