Skip to content

Commit 371b3e6

Browse files
committed
refactor: simplify new-task prompt generation
- Replace complex template literals with two complete prompt constants - Remove nested ternary operators for better readability - Hide todos parameter completely when disabled (not shown as optional) - Update tests to reflect new behavior - Reduce code from 105 to 66 lines for better maintainability
1 parent c9da981 commit 371b3e6

File tree

2 files changed

+68
-55
lines changed

2 files changed

+68
-55
lines changed

src/core/prompts/tools/__tests__/new-task.spec.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getNewTaskDescription } from "../new-task"
33
import { ToolArgs } from "../types"
44

55
describe("getNewTaskDescription", () => {
6-
it("should show todos parameter as optional when setting is disabled", () => {
6+
it("should NOT show todos parameter at all when setting is disabled", () => {
77
const args: ToolArgs = {
88
cwd: "/test",
99
supportsComputerUse: false,
@@ -14,15 +14,17 @@ describe("getNewTaskDescription", () => {
1414

1515
const description = getNewTaskDescription(args)
1616

17-
// Check that todos parameter is shown as optional
18-
expect(description).toContain("todos: (optional)")
19-
expect(description).toContain("The initial todo list in markdown checklist format")
17+
// Check that todos parameter is NOT shown at all
18+
expect(description).not.toContain("todos:")
19+
expect(description).not.toContain("todos parameter")
20+
expect(description).not.toContain("The initial todo list in markdown checklist format")
2021

21-
// Should have a simple example without todos in the main example
22+
// Should have a simple example without todos
2223
expect(description).toContain("Implement a new feature for the application")
2324

24-
// Should also have an example with optional todos
25-
expect(description).toContain("Example with optional todos:")
25+
// Should NOT have any todos tags in examples
26+
expect(description).not.toContain("<todos>")
27+
expect(description).not.toContain("</todos>")
2628

2729
// Should still have mode and message as required
2830
expect(description).toContain("mode: (required)")
@@ -43,6 +45,7 @@ describe("getNewTaskDescription", () => {
4345
// Check that todos is marked as required
4446
expect(description).toContain("todos: (required)")
4547
expect(description).toContain("and initial todo list")
48+
expect(description).toContain("The initial todo list in markdown checklist format")
4649

4750
// Should not contain any mention of optional for todos
4851
expect(description).not.toContain("todos: (optional)")
@@ -54,7 +57,7 @@ describe("getNewTaskDescription", () => {
5457
expect(description).toContain("Set up auth middleware")
5558
})
5659

57-
it("should show todos parameter as optional when settings is undefined", () => {
60+
it("should NOT show todos parameter when settings is undefined", () => {
5861
const args: ToolArgs = {
5962
cwd: "/test",
6063
supportsComputerUse: false,
@@ -63,12 +66,14 @@ describe("getNewTaskDescription", () => {
6366

6467
const description = getNewTaskDescription(args)
6568

66-
// Check that todos parameter is shown as optional by default
67-
expect(description).toContain("todos: (optional)")
68-
expect(description).toContain("The initial todo list in markdown checklist format")
69+
// Check that todos parameter is NOT shown by default
70+
expect(description).not.toContain("todos:")
71+
expect(description).not.toContain("The initial todo list in markdown checklist format")
72+
expect(description).not.toContain("<todos>")
73+
expect(description).not.toContain("</todos>")
6974
})
7075

71-
it("should show todos parameter as optional when newTaskRequireTodos is undefined", () => {
76+
it("should NOT show todos parameter when newTaskRequireTodos is undefined", () => {
7277
const args: ToolArgs = {
7378
cwd: "/test",
7479
supportsComputerUse: false,
@@ -77,12 +82,14 @@ describe("getNewTaskDescription", () => {
7782

7883
const description = getNewTaskDescription(args)
7984

80-
// Check that todos parameter is shown as optional by default
81-
expect(description).toContain("todos: (optional)")
82-
expect(description).toContain("The initial todo list in markdown checklist format")
85+
// Check that todos parameter is NOT shown by default
86+
expect(description).not.toContain("todos:")
87+
expect(description).not.toContain("The initial todo list in markdown checklist format")
88+
expect(description).not.toContain("<todos>")
89+
expect(description).not.toContain("</todos>")
8390
})
8491

85-
it("should include todos in main example only when setting is enabled", () => {
92+
it("should include todos in examples only when setting is enabled", () => {
8693
const argsWithSettingOff: ToolArgs = {
8794
cwd: "/test",
8895
supportsComputerUse: false,
@@ -105,16 +112,17 @@ describe("getNewTaskDescription", () => {
105112
// When setting is on, should include todos in main example
106113
expect(descriptionOn).toContain("Implement user authentication")
107114
expect(descriptionOn).toContain("[ ] Set up auth middleware")
115+
expect(descriptionOn).toContain("<todos>")
116+
expect(descriptionOn).toContain("</todos>")
108117

109-
// When setting is on, should NOT have "Example with optional todos" section
110-
expect(descriptionOn).not.toContain("Example with optional todos:")
118+
// When setting is off, should NOT include any todos references
119+
expect(descriptionOff).not.toContain("<todos>")
120+
expect(descriptionOff).not.toContain("</todos>")
121+
expect(descriptionOff).not.toContain("[ ] Set up auth middleware")
122+
expect(descriptionOff).not.toContain("[ ] First task to complete")
111123

112-
// When setting is off, main example should NOT include todos in Usage section
124+
// When setting is off, main example should be simple
113125
const usagePattern = /<new_task>\s*<mode>.*<\/mode>\s*<message>.*<\/message>\s*<\/new_task>/s
114126
expect(descriptionOff).toMatch(usagePattern)
115-
116-
// When setting is off, should have separate "Example with optional todos" section
117-
expect(descriptionOff).toContain("Example with optional todos:")
118-
expect(descriptionOff).toContain("[ ] Set up auth middleware")
119127
})
120128
})

src/core/prompts/tools/new-task.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
import { ToolArgs } from "./types"
22

3-
export function getNewTaskDescription(args: ToolArgs): string {
4-
const todosRequired = args.settings?.newTaskRequireTodos === true
5-
6-
// Always show the todos parameter, but mark it as optional or required based on setting
7-
return `## new_task
8-
Description: This will let you create a new task instance in the chosen mode using your provided message${todosRequired ? " and initial todo list" : ""}.
3+
/**
4+
* Prompt when todos are NOT required (default)
5+
*/
6+
const PROMPT_WITHOUT_TODOS = `## new_task
7+
Description: This will let you create a new task instance in the chosen mode using your provided message.
98
109
Parameters:
1110
- mode: (required) The slug of the mode to start the new task in (e.g., "code", "debug", "architect").
1211
- message: (required) The initial user message or instructions for this new task.
13-
- todos: (${todosRequired ? "required" : "optional"}) The initial todo list in markdown checklist format for the new task.
1412
1513
Usage:
1614
<new_task>
1715
<mode>your-mode-slug-here</mode>
18-
<message>Your initial instructions here</message>${
19-
todosRequired
20-
? `
21-
<todos>
22-
[ ] First task to complete
23-
[ ] Second task to complete
24-
[ ] Third task to complete
25-
</todos>`
26-
: ""
27-
}
16+
<message>Your initial instructions here</message>
2817
</new_task>
2918
3019
Example:
3120
<new_task>
3221
<mode>code</mode>
33-
<message>${todosRequired ? "Implement user authentication" : "Implement a new feature for the application"}</message>${
34-
todosRequired
35-
? `
22+
<message>Implement a new feature for the application</message>
23+
</new_task>
24+
`
25+
26+
/**
27+
* Prompt when todos ARE required
28+
*/
29+
const PROMPT_WITH_TODOS = `## new_task
30+
Description: This will let you create a new task instance in the chosen mode using your provided message and initial todo list.
31+
32+
Parameters:
33+
- mode: (required) The slug of the mode to start the new task in (e.g., "code", "debug", "architect").
34+
- message: (required) The initial user message or instructions for this new task.
35+
- todos: (required) The initial todo list in markdown checklist format for the new task.
36+
37+
Usage:
38+
<new_task>
39+
<mode>your-mode-slug-here</mode>
40+
<message>Your initial instructions here</message>
3641
<todos>
37-
[ ] Set up auth middleware
38-
[ ] Create login endpoint
39-
[ ] Add session management
40-
[ ] Write tests
41-
</todos>`
42-
: ""
43-
}
42+
[ ] First task to complete
43+
[ ] Second task to complete
44+
[ ] Third task to complete
45+
</todos>
4446
</new_task>
4547
46-
${
47-
!todosRequired
48-
? `Example with optional todos:
48+
Example:
4949
<new_task>
5050
<mode>code</mode>
5151
<message>Implement user authentication</message>
@@ -56,7 +56,12 @@ ${
5656
[ ] Write tests
5757
</todos>
5858
</new_task>
59+
5960
`
60-
: ""
61-
}`
61+
62+
export function getNewTaskDescription(args: ToolArgs): string {
63+
const todosRequired = args.settings?.newTaskRequireTodos === true
64+
65+
// Simply return the appropriate prompt based on the setting
66+
return todosRequired ? PROMPT_WITH_TODOS : PROMPT_WITHOUT_TODOS
6267
}

0 commit comments

Comments
 (0)