mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 23:24:00 +03:00
fix(core): send only changed entries in instruction updates (#57626)
This commit is contained in:
committed by
GitHub
Unverified
parent
17ebb66d25
commit
15adc3d91e
@@ -35,8 +35,8 @@ const update = (previous: ReadonlyArray<Summary>, current: ReadonlyArray<Summary
|
||||
(server) => server.server,
|
||||
(before, after) => before.instructions !== after.instructions || before.codemode !== after.codemode,
|
||||
)
|
||||
// Additions and removals render as small deltas; anything else restates the full list.
|
||||
if (diff.changed.length > 0 || (diff.added.length === 0 && diff.removed.length === 0))
|
||||
// Added, changed, and removed servers render as deltas; the full list is restated only when no entry differs.
|
||||
if (diff.added.length === 0 && diff.changed.length === 0 && diff.removed.length === 0)
|
||||
return [
|
||||
"The available MCP server instructions have changed. This list supersedes the previous one.",
|
||||
render(current),
|
||||
@@ -45,6 +45,12 @@ const update = (previous: ReadonlyArray<Summary>, current: ReadonlyArray<Summary
|
||||
...(diff.added.length === 0
|
||||
? []
|
||||
: ["New MCP server instructions are available in addition to those previously listed:", ...entries(diff.added)]),
|
||||
...(diff.changed.length === 0
|
||||
? []
|
||||
: [
|
||||
"The following MCP server instructions have changed. Each entry replaces the previously listed server with the same name:",
|
||||
...entries(diff.changed.map((change) => change.current)),
|
||||
]),
|
||||
...(diff.removed.length === 0
|
||||
? []
|
||||
: [
|
||||
|
||||
@@ -35,8 +35,8 @@ const update = (previous: ReadonlyArray<typeof Summary.Type>, current: ReadonlyA
|
||||
(reference) => reference.name,
|
||||
(before, after) => before.path !== after.path || before.description !== after.description,
|
||||
)
|
||||
// Additions and removals render as small deltas; anything else restates the full list.
|
||||
if (diff.changed.length > 0 || (diff.added.length === 0 && diff.removed.length === 0))
|
||||
// Added, changed, and removed references render as deltas; the full list is restated only when no entry differs.
|
||||
if (diff.added.length === 0 && diff.changed.length === 0 && diff.removed.length === 0)
|
||||
return [
|
||||
"The available project references have changed. This list supersedes the previous reference list.",
|
||||
render(current),
|
||||
@@ -45,6 +45,12 @@ const update = (previous: ReadonlyArray<typeof Summary.Type>, current: ReadonlyA
|
||||
...(diff.added.length === 0
|
||||
? []
|
||||
: ["New project references are available in addition to those previously listed:", ...entries(diff.added)]),
|
||||
...(diff.changed.length === 0
|
||||
? []
|
||||
: [
|
||||
"The following project references have changed. Each entry replaces the previously listed reference with the same name:",
|
||||
...entries(diff.changed.map((change) => change.current)),
|
||||
]),
|
||||
...(diff.removed.length === 0
|
||||
? []
|
||||
: [
|
||||
|
||||
@@ -39,8 +39,8 @@ const update = (previous: ReadonlyArray<Summary>, current: ReadonlyArray<Summary
|
||||
(skill) => skill.id,
|
||||
(before, after) => before.name !== after.name || before.description !== after.description,
|
||||
)
|
||||
// Additions and removals render as small deltas; anything else restates the full list.
|
||||
if (diff.changed.length > 0 || (diff.added.length === 0 && diff.removed.length === 0))
|
||||
// Added, changed, and removed skills render as deltas; the full list is restated only when no entry differs.
|
||||
if (diff.added.length === 0 && diff.changed.length === 0 && diff.removed.length === 0)
|
||||
return [
|
||||
"The available skills have changed. This list supersedes the previous available skills list.",
|
||||
render(current),
|
||||
@@ -49,6 +49,12 @@ const update = (previous: ReadonlyArray<Summary>, current: ReadonlyArray<Summary
|
||||
...(diff.added.length === 0
|
||||
? []
|
||||
: ["New skills are available in addition to those previously listed:", ...entries(diff.added)]),
|
||||
...(diff.changed.length === 0
|
||||
? []
|
||||
: [
|
||||
"The following skills have changed. Each entry replaces the previously listed skill with the same ID:",
|
||||
...entries(diff.changed.map((change) => change.current)),
|
||||
]),
|
||||
...(diff.removed.length === 0
|
||||
? []
|
||||
: [
|
||||
|
||||
@@ -116,7 +116,7 @@ describe("McpInstructions", () => {
|
||||
),
|
||||
)
|
||||
|
||||
it.effect("restates guidance when Code Mode is disabled for a server", () => {
|
||||
it.effect("replaces a server entry when Code Mode is disabled for it", () => {
|
||||
let tools: Mcp.Tool[] = [tool("alpha")]
|
||||
return Effect.gen(function* () {
|
||||
const service = yield* McpInstructions.Service
|
||||
@@ -126,12 +126,10 @@ describe("McpInstructions", () => {
|
||||
const changed = yield* readUpdate(yield* service.load([]), initialized)
|
||||
expect(changed.text).toBe(
|
||||
[
|
||||
"The available MCP server instructions have changed. This list supersedes the previous one.",
|
||||
"<mcp_instructions>",
|
||||
"The following MCP server instructions have changed. Each entry replaces the previously listed server with the same name:",
|
||||
' <server name="alpha">',
|
||||
" Alpha instructions",
|
||||
" </server>",
|
||||
"</mcp_instructions>",
|
||||
].join("\n"),
|
||||
)
|
||||
}).pipe(
|
||||
@@ -167,17 +165,11 @@ describe("McpInstructions", () => {
|
||||
const changed = yield* readUpdate(yield* service.load([]), added)
|
||||
expect(changed.text).toBe(
|
||||
[
|
||||
"The available MCP server instructions have changed. This list supersedes the previous one.",
|
||||
"<mcp_instructions>",
|
||||
"The following MCP server instructions have changed. Each entry replaces the previously listed server with the same name:",
|
||||
' <server name="alpha">',
|
||||
' Use tools from this server through `execute` under `tools["alpha"]`.',
|
||||
" Updated alpha",
|
||||
" </server>",
|
||||
' <server name="beta">',
|
||||
' Use tools from this server through `execute` under `tools["beta"]`.',
|
||||
" Beta instructions",
|
||||
" </server>",
|
||||
"</mcp_instructions>",
|
||||
].join("\n"),
|
||||
)
|
||||
|
||||
|
||||
@@ -108,4 +108,40 @@ describe("ReferenceInstructions", () => {
|
||||
Effect.provide(instructionsLayer(Layer.mock(Reference.Service, { list: () => Effect.succeed(references) }))),
|
||||
)
|
||||
})
|
||||
|
||||
it.effect("announces added, changed, and removed references in one delta", () => {
|
||||
const reference = (name: string, description: string) =>
|
||||
Reference.Info.make({
|
||||
name,
|
||||
path: AbsolutePath.make(`/${name}`),
|
||||
description,
|
||||
source: Reference.LocalSource.make({ type: "local", path: AbsolutePath.make(`/${name}`), description }),
|
||||
})
|
||||
let references = [reference("docs", "Use for product documentation"), reference("legacy", "Use for old code")]
|
||||
return Effect.gen(function* () {
|
||||
const instructions = yield* ReferenceInstructions.Service
|
||||
const initialized = yield* readInitial(yield* instructions.load())
|
||||
|
||||
references = [reference("docs", "Use for API documentation"), reference("examples", "Use for examples")]
|
||||
expect((yield* readUpdate(yield* instructions.load(), initialized)).text).toBe(
|
||||
[
|
||||
"New project references are available in addition to those previously listed:",
|
||||
" <reference>",
|
||||
" <name>examples</name>",
|
||||
" <path>/examples</path>",
|
||||
" <description>Use for examples</description>",
|
||||
" </reference>",
|
||||
"The following project references have changed. Each entry replaces the previously listed reference with the same name:",
|
||||
" <reference>",
|
||||
" <name>docs</name>",
|
||||
" <path>/docs</path>",
|
||||
" <description>Use for API documentation</description>",
|
||||
" </reference>",
|
||||
"The following project references are no longer available and must not be used: legacy.",
|
||||
].join("\n"),
|
||||
)
|
||||
}).pipe(
|
||||
Effect.provide(instructionsLayer(Layer.mock(Reference.Service, { list: () => Effect.succeed(references) }))),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -117,7 +117,7 @@ describe("SkillInstructions", () => {
|
||||
}).pipe(Effect.provide(layer(() => skills)))
|
||||
})
|
||||
|
||||
it.effect("restates the full skill list when a description changes", () => {
|
||||
it.effect("renders only the changed skill when a description changes", () => {
|
||||
const agent = Agent.Info.make(Agent.Info.default(build))
|
||||
let skills = [effect]
|
||||
return Effect.gen(function* () {
|
||||
@@ -125,15 +125,19 @@ describe("SkillInstructions", () => {
|
||||
const initialized = yield* instructions.load(agent.permissions).pipe(Effect.flatMap(readInitial))
|
||||
|
||||
skills = [Skill.Info.make({ ...effect, description: "Build applications with Effect v4" })]
|
||||
expect(
|
||||
yield* instructions
|
||||
.load(agent.permissions)
|
||||
.pipe(Effect.flatMap((context) => readUpdate(context, initialized))),
|
||||
).toMatchObject({
|
||||
text: expect.stringContaining(
|
||||
"The available skills have changed. This list supersedes the previous available skills list.",
|
||||
),
|
||||
})
|
||||
const changed = yield* instructions
|
||||
.load(agent.permissions)
|
||||
.pipe(Effect.flatMap((context) => readUpdate(context, initialized)))
|
||||
expect(changed.text).toBe(
|
||||
[
|
||||
"The following skills have changed. Each entry replaces the previously listed skill with the same ID:",
|
||||
" <skill>",
|
||||
" <id>effect</id>",
|
||||
" <name>Effect</name>",
|
||||
" <description>Build applications with Effect v4</description>",
|
||||
" </skill>",
|
||||
].join("\n"),
|
||||
)
|
||||
}).pipe(Effect.provide(layer(() => skills)))
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user