Repository navigation
fix(web): complete goal subcommands in the composer #26025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2cdb688
1e0fb21
d926ea0
8875528
d4cb411
89142a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
| import { ProviderDriverKind } from "@t3tools/contracts"; | ||
| import type { ComposerCommandItem } from "./ComposerCommandMenu"; | ||
| import { expandGoalSubcommands, searchSlashCommandItems } from "./composerSlashCommandSearch"; | ||
|
|
||
| const goal: Extract<ComposerCommandItem, { type: "provider-slash-command" }> = { | ||
| id: "provider-slash-command:codex:goal", | ||
| type: "provider-slash-command", | ||
| provider: ProviderDriverKind.make("codex"), | ||
| command: { name: "goal" }, | ||
| label: "/goal", | ||
| description: "Set a goal", | ||
| }; | ||
|
|
||
| describe("goal subcommand completion", () => { | ||
| it("only offers native Claude goal commands", () => { | ||
| const items = expandGoalSubcommands( | ||
| [{ ...goal, provider: ProviderDriverKind.make("claudeAgent") }], | ||
| "goal", | ||
| "Fix it", | ||
| ); | ||
| expect(items.map((item) => item.label)).toEqual(["/goal", "/goal edit", "/goal clear"]); | ||
| }); | ||
|
|
||
| it("does not assume another provider implements Codex goal commands", () => { | ||
| const other = { ...goal, provider: ProviderDriverKind.make("opencode") }; | ||
| expect(expandGoalSubcommands([other], "goal", "Fix it")).toEqual([other]); | ||
| }); | ||
|
|
||
| it("waits for the full goal command and omits edit when no goal is set", () => { | ||
| expect(expandGoalSubcommands([goal], "go", "Fix it")).toEqual([goal]); | ||
| expect(expandGoalSubcommands([goal], "goal", null).map((item) => item.label)).not.toContain( | ||
| "/goal edit", | ||
| ); | ||
| }); | ||
|
|
||
| it.each(["goal r", "goal r", "goal\tr", "GOAL R"])("completes %j", (query) => { | ||
| const items = expandGoalSubcommands([goal], query, "Fix the tests"); | ||
| expect(searchSlashCommandItems(items, query).map((item) => item.label)).toEqual([ | ||
| "/goal resume", | ||
| ]); | ||
| }); | ||
|
|
||
| it("fills the current objective when editing", () => { | ||
| const items = expandGoalSubcommands([goal], "goal", "Fix the tests"); | ||
| expect(items.find((item) => item.label === "/goal edit")).toMatchObject({ | ||
| replacementText: "/goal Fix the tests", | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,46 @@ type SlashSearchItem = Extract< | |
| { type: "slash-command" | "provider-slash-command" | "skill" } | ||
| >; | ||
|
|
||
| export function expandGoalSubcommands( | ||
| items: ReadonlyArray<SlashSearchItem>, | ||
| query: string, | ||
| objective: string | null, | ||
| ): SlashSearchItem[] { | ||
| if (!/^goal(?:\s|$)/i.test(query)) return [...items]; | ||
| return items.flatMap((item): SlashSearchItem[] => { | ||
| if ( | ||
| item.type !== "provider-slash-command" || | ||
| item.command.name !== "goal" || | ||
| (item.provider !== "codex" && item.provider !== "claudeAgent") | ||
| ) | ||
| return [item]; | ||
| const commands = [ | ||
| ...(objective === null ? [] : [{ name: "edit", description: "Edit the current goal" }]), | ||
| ...(item.provider === "codex" | ||
| ? [ | ||
| { name: "pause", description: "Pause the current goal" }, | ||
| { name: "resume", description: "Resume the current goal" }, | ||
| ] | ||
| : []), | ||
| { name: "clear", description: "Remove the current goal" }, | ||
| ]; | ||
| const prefix = query.slice("goal".length).trim().toLowerCase(); | ||
| return [ | ||
| item, | ||
| ...commands | ||
| .filter(({ name }) => name.startsWith(prefix)) | ||
| .map(({ name, description }) => ({ | ||
| ...item, | ||
| id: `${item.id}:${name}`, | ||
| command: { name: `goal ${name}`, description }, | ||
| label: `/goal ${name}`, | ||
| description, | ||
| ...(name === "edit" ? { replacementText: `/goal ${objective}` } : {}), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not prefill a goal control command as the objective. If the stored objective is
|
||
| })), | ||
| ]; | ||
| }); | ||
| } | ||
|
|
||
| /** Provider commands, `/side`, `/btw` and `/clear` work only at the message start. */ | ||
| export function slashCommandItemsForPromptPosition( | ||
| items: ReadonlyArray<SlashSearchItem>, | ||
|
|
@@ -79,7 +119,10 @@ export function searchSlashCommandItems( | |
| items: ReadonlyArray<SlashSearchItem>, | ||
| query: string, | ||
| ): SlashSearchItem[] { | ||
| const normalizedQuery = normalizeSearchQuery(query, { trimLeadingPattern: /^\/+/ }); | ||
| const normalizedQuery = normalizeSearchQuery(query, { trimLeadingPattern: /^\/+/ }).replace( | ||
| /^goal[\t ]+/, | ||
| "goal ", | ||
| ); | ||
| if (!normalizedQuery) { | ||
| return [...items]; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
rg -n 'parseGoalCommand|case "set"|goal\.objective|objective:' apps/server/src/orchestration-v2 packages/contracts/src/orchestrationV2.tsRepository: pingdotgg/t3code
Length of output: 4383
Script executed:
Repository: pingdotgg/t3code
Length of output: 8161
Script executed:
Repository: pingdotgg/t3code
Length of output: 6002
Clear the rest of the command token when completing a goal subcommand.
With the cursor inside
/goal resume, the goal trigger range ends at the cursor. Selecting the completion leaves the rest of the word in the prompt. Submitting/goal resume esumeruns as asetwith objectiveresume esume. For Codex, this clears the existing goal and starts work on the new objective.Extend the goal trigger range across the remaining letters of the command word.
Suggested fix
const prefix = text.slice(0, cursor); if (goalSubcommands && /^\/goal[\t ]+[a-z]*$/i.test(prefix)) { + const suffix = /^[a-z]*/i.exec(text.slice(cursor))?.[0] ?? ""; return { kind: "slash-command", query: prefix.slice(1), rangeStart: 0, - rangeEnd: cursor, + rangeEnd: cursor + suffix.length, }; }