Skip to content

Commit ee42eb3

Browse files
authored
fix(core): render built-in command arguments (anomalyco#45697)
1 parent 80323a4 commit ee42eb3

2 files changed

Lines changed: 51 additions & 4 deletions

File tree

‎packages/core/src/plugin/command.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export const Plugin = define({
8484
})
8585

8686
function append(template: string, input: string) {
87-
return [template, input.trim()].filter(Boolean).join("\n\n")
87+
const value = input.trim()
88+
if (template.includes("$ARGUMENTS")) return template.replaceAll("$ARGUMENTS", () => value)
89+
return [template, value].filter(Boolean).join("\n\n")
8890
}
8991

9092
function parseArguments(input: string) {

‎packages/core/test/plugin/command.test.ts‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { emptyMcpLayer } from "../fixture/mcp"
1616
import { location } from "../fixture/location"
1717
import { testEffect } from "../lib/effect"
1818
import { host } from "./host"
19+
import PROMPT_INITIALIZE from "../../src/plugin/command/initialize.txt"
1920
import PROMPT_REVIEW from "../../src/plugin/command/review.txt"
2021

2122
const directory = AbsolutePath.make("/repo/packages/app")
@@ -40,7 +41,11 @@ describe("CommandPlugin.Plugin", () => {
4041
it.effect("registers built-in init and review commands", () =>
4142
Effect.gen(function* () {
4243
const command = yield* Command.Service
43-
const prompts: { text: string; files?: readonly { readonly uri: string }[] }[] = []
44+
const prompts: {
45+
text: string
46+
files?: readonly { readonly uri: string }[]
47+
delivery?: "steer" | "queue"
48+
}[] = []
4449
yield* CommandPlugin.Plugin.effect(
4550
host({
4651
command: {
@@ -51,7 +56,7 @@ describe("CommandPlugin.Plugin", () => {
5156
session: {
5257
prompt: (input) =>
5358
Effect.sync(() => {
54-
prompts.push({ text: input.text, files: input.files })
59+
prompts.push({ text: input.text, files: input.files, delivery: input.delivery })
5560
return SessionInbox.User.make({
5661
id: SessionMessage.ID.make("msg_test"),
5762
sessionID: input.sessionID,
@@ -86,10 +91,50 @@ describe("CommandPlugin.Plugin", () => {
8691
delivery: "queue",
8792
},
8893
})
94+
yield* command.execute({
95+
name: "review",
96+
invocation: {
97+
sessionID: Session.ID.make("ses_test"),
98+
prompt: { text: " branch $& $$ $` $' " },
99+
delivery: "steer",
100+
},
101+
})
102+
yield* command.execute({
103+
name: "init",
104+
invocation: {
105+
sessionID: Session.ID.make("ses_test"),
106+
prompt: { text: "" },
107+
delivery: "steer",
108+
},
109+
})
110+
yield* command.execute({
111+
name: "review",
112+
invocation: {
113+
sessionID: Session.ID.make("ses_test"),
114+
prompt: { text: " " },
115+
delivery: "steer",
116+
},
117+
})
89118
expect(prompts).toEqual([
90119
{
91-
text: expect.stringContaining("extra context"),
120+
text: PROMPT_INITIALIZE.replace("${path}", project).replaceAll("$ARGUMENTS", "extra context"),
92121
files: [{ uri: "file:///tmp/context.md" }],
122+
delivery: "queue",
123+
},
124+
{
125+
text: PROMPT_REVIEW.replace("${path}", project).replaceAll("$ARGUMENTS", () => "branch $& $$ $` $'"),
126+
files: undefined,
127+
delivery: "steer",
128+
},
129+
{
130+
text: PROMPT_INITIALIZE.replace("${path}", project).replaceAll("$ARGUMENTS", ""),
131+
files: undefined,
132+
delivery: "steer",
133+
},
134+
{
135+
text: PROMPT_REVIEW.replace("${path}", project).replaceAll("$ARGUMENTS", ""),
136+
files: undefined,
137+
delivery: "steer",
93138
},
94139
])
95140
}),

0 commit comments

Comments
 (0)