gencode-ai 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +86 -0
- package/README.md +14 -17
- package/dist/agent/agent.d.ts +8 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +14 -1
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/types.d.ts +14 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/cli/components/App.d.ts.map +1 -1
- package/dist/cli/components/App.js +38 -3
- package/dist/cli/components/App.js.map +1 -1
- package/dist/cli/components/Messages.d.ts.map +1 -1
- package/dist/cli/components/Messages.js +17 -0
- package/dist/cli/components/Messages.js.map +1 -1
- package/dist/cli/components/QuestionPrompt.d.ts +23 -0
- package/dist/cli/components/QuestionPrompt.d.ts.map +1 -0
- package/dist/cli/components/QuestionPrompt.js +231 -0
- package/dist/cli/components/QuestionPrompt.js.map +1 -0
- package/dist/cli/components/index.d.ts +1 -0
- package/dist/cli/components/index.d.ts.map +1 -1
- package/dist/cli/components/index.js +1 -0
- package/dist/cli/components/index.js.map +1 -1
- package/dist/cli/components/theme.d.ts +7 -0
- package/dist/cli/components/theme.d.ts.map +1 -1
- package/dist/cli/components/theme.js +11 -1
- package/dist/cli/components/theme.js.map +1 -1
- package/dist/permissions/types.d.ts.map +1 -1
- package/dist/permissions/types.js +2 -0
- package/dist/permissions/types.js.map +1 -1
- package/dist/tools/builtin/ask-user.d.ts +64 -0
- package/dist/tools/builtin/ask-user.d.ts.map +1 -0
- package/dist/tools/builtin/ask-user.js +148 -0
- package/dist/tools/builtin/ask-user.js.map +1 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.ts +17 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/docs/proposals/0012-ask-user-question.md +66 -1
- package/docs/proposals/README.md +1 -1
- package/examples/test-ask-user.ts +167 -0
- package/package.json +1 -1
- package/src/agent/agent.ts +20 -1
- package/src/agent/index.ts +1 -0
- package/src/agent/types.ts +13 -1
- package/src/cli/components/App.tsx +55 -3
- package/src/cli/components/Messages.tsx +43 -0
- package/src/cli/components/QuestionPrompt.tsx +462 -0
- package/src/cli/components/index.ts +1 -0
- package/src/cli/components/theme.ts +11 -1
- package/src/permissions/types.ts +2 -0
- package/src/prompts/system/base.txt +42 -0
- package/src/prompts/tools/ask-user.txt +110 -0
- package/src/tools/builtin/ask-user.ts +185 -0
- package/src/tools/index.ts +15 -0
- package/src/tools/types.ts +18 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AskUserQuestion Tool - Structured user questioning
|
|
3
|
+
*
|
|
4
|
+
* Allows the agent to pause execution and present structured questions
|
|
5
|
+
* to the user with predefined options. Supports single-select, multi-select,
|
|
6
|
+
* and custom "Other" input.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { loadToolDescription } from '../../prompts/index.js';
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Zod Schemas
|
|
12
|
+
// ============================================================================
|
|
13
|
+
export const QuestionOptionSchema = z.object({
|
|
14
|
+
label: z
|
|
15
|
+
.string()
|
|
16
|
+
.min(1)
|
|
17
|
+
.max(50)
|
|
18
|
+
.describe('Display text for this option (1-5 words, concise)'),
|
|
19
|
+
description: z
|
|
20
|
+
.string()
|
|
21
|
+
.min(1)
|
|
22
|
+
.max(200)
|
|
23
|
+
.describe('Explanation of what this option means or implications'),
|
|
24
|
+
});
|
|
25
|
+
export const QuestionSchema = z.object({
|
|
26
|
+
question: z
|
|
27
|
+
.string()
|
|
28
|
+
.min(1)
|
|
29
|
+
.describe('The complete question to ask the user, ending with a question mark'),
|
|
30
|
+
header: z
|
|
31
|
+
.string()
|
|
32
|
+
.min(1)
|
|
33
|
+
.max(12)
|
|
34
|
+
.describe('Very short label displayed as a chip/tag (max 12 chars)'),
|
|
35
|
+
options: z
|
|
36
|
+
.array(QuestionOptionSchema)
|
|
37
|
+
.min(2)
|
|
38
|
+
.max(4)
|
|
39
|
+
.describe('2-4 options for the user to choose from'),
|
|
40
|
+
multiSelect: z
|
|
41
|
+
.boolean()
|
|
42
|
+
.describe('Set to true to allow multiple selections, false for single choice'),
|
|
43
|
+
});
|
|
44
|
+
export const AskUserQuestionInputSchema = z.object({
|
|
45
|
+
questions: z
|
|
46
|
+
.array(QuestionSchema)
|
|
47
|
+
.min(1)
|
|
48
|
+
.max(4)
|
|
49
|
+
.describe('1-4 questions to ask the user'),
|
|
50
|
+
});
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// Answer Formatting
|
|
53
|
+
// ============================================================================
|
|
54
|
+
/**
|
|
55
|
+
* Format answers for display to the agent
|
|
56
|
+
*/
|
|
57
|
+
export function formatAnswersForAgent(answers) {
|
|
58
|
+
const lines = ['User answered the following questions:', ''];
|
|
59
|
+
answers.forEach((answer, index) => {
|
|
60
|
+
lines.push(`${index + 1}. ${answer.header} (${answer.question})`);
|
|
61
|
+
if (answer.selectedOptions.length > 0) {
|
|
62
|
+
lines.push(` Selected: ${answer.selectedOptions.join(', ')}`);
|
|
63
|
+
}
|
|
64
|
+
if (answer.customInput) {
|
|
65
|
+
lines.push(` Custom input: ${answer.customInput}`);
|
|
66
|
+
}
|
|
67
|
+
lines.push('');
|
|
68
|
+
});
|
|
69
|
+
lines.push('Proceeding with user selections.');
|
|
70
|
+
return lines.join('\n');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Format answers for CLI confirmation display
|
|
74
|
+
*/
|
|
75
|
+
export function formatAnswersForDisplay(answers) {
|
|
76
|
+
return answers
|
|
77
|
+
.map((answer) => {
|
|
78
|
+
const selections = answer.customInput
|
|
79
|
+
? [...answer.selectedOptions, answer.customInput].join(', ')
|
|
80
|
+
: answer.selectedOptions.join(', ');
|
|
81
|
+
return `✔ ${answer.header}: ${selections}`;
|
|
82
|
+
})
|
|
83
|
+
.join('\n');
|
|
84
|
+
}
|
|
85
|
+
// ============================================================================
|
|
86
|
+
// Tool Implementation
|
|
87
|
+
// ============================================================================
|
|
88
|
+
/**
|
|
89
|
+
* AskUserQuestion tool
|
|
90
|
+
*
|
|
91
|
+
* This tool is special - it doesn't execute immediately but signals
|
|
92
|
+
* the agent loop to pause and wait for user input via the CLI.
|
|
93
|
+
*
|
|
94
|
+
* The actual questioning is handled by the CLI layer (QuestionPrompt component).
|
|
95
|
+
* This tool just validates the input and returns a marker for the agent loop.
|
|
96
|
+
*/
|
|
97
|
+
export const askUserQuestionTool = {
|
|
98
|
+
name: 'AskUserQuestion',
|
|
99
|
+
description: loadToolDescription('ask-user'),
|
|
100
|
+
parameters: AskUserQuestionInputSchema,
|
|
101
|
+
async execute(input, context) {
|
|
102
|
+
// Validation is handled by Zod schema
|
|
103
|
+
// Additional validation for recommended options format
|
|
104
|
+
for (const question of input.questions) {
|
|
105
|
+
// Check if first option has (Recommended) - this is just a hint, not enforced
|
|
106
|
+
const firstOption = question.options[0];
|
|
107
|
+
if (firstOption && !firstOption.label.includes('(Recommended)')) {
|
|
108
|
+
// This is fine - recommended suffix is optional
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Check if context has askUser callback
|
|
112
|
+
if (context.askUser) {
|
|
113
|
+
try {
|
|
114
|
+
const answers = await context.askUser(input.questions);
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
output: formatAnswersForAgent(answers),
|
|
118
|
+
metadata: {
|
|
119
|
+
title: 'AskUserQuestion',
|
|
120
|
+
subtitle: `${answers.length} answer(s) received`,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return {
|
|
126
|
+
success: false,
|
|
127
|
+
output: '',
|
|
128
|
+
error: `Failed to get user response: ${error instanceof Error ? error.message : String(error)}`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// If no askUser callback, return a special marker
|
|
133
|
+
// The agent loop should detect this and handle it specially
|
|
134
|
+
return {
|
|
135
|
+
success: true,
|
|
136
|
+
output: JSON.stringify({
|
|
137
|
+
type: 'ask_user_question',
|
|
138
|
+
questions: input.questions,
|
|
139
|
+
requiresUserInput: true,
|
|
140
|
+
}),
|
|
141
|
+
metadata: {
|
|
142
|
+
title: 'AskUserQuestion',
|
|
143
|
+
subtitle: `${input.questions.length} question(s) pending`,
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=ask-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-user.js","sourceRoot":"","sources":["../../../src/tools/builtin/ask-user.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,EAAE,CAAC;SACP,QAAQ,CAAC,mDAAmD,CAAC;IAChE,WAAW,EAAE,CAAC;SACX,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,GAAG,CAAC;SACR,QAAQ,CAAC,uDAAuD,CAAC;CACrE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;S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ChE,gDAAgD;YAClD,CAAC;QACH,CAAC;QAED,wCAAwC;QACxC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBACvD,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,qBAAqB,CAAC,OAAO,CAAC;oBACtC,QAAQ,EAAE;wBACR,KAAK,EAAE,iBAAiB;wBACxB,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,qBAAqB;qBACjD;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,EAAE;oBACV,KAAK,EAAE,gCAAgC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBAChG,CAAC;YACJ,CAAC;QACH,CAAC;QAED,kDAAkD;QAClD,4DAA4D;QAC5D,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC;gBACrB,IAAI,EAAE,mBAAmB;gBACzB,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,iBAAiB,EAAE,IAAI;aACxB,CAAC;YACF,QAAQ,EAAE;gBACR,KAAK,EAAE,iBAAiB;gBACxB,QAAQ,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,sBAAsB;aAC1D;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export { grepTool } from './builtin/grep.js';
|
|
|
12
12
|
export { webfetchTool } from './builtin/webfetch.js';
|
|
13
13
|
export { websearchTool } from './builtin/websearch.js';
|
|
14
14
|
export { todowriteTool, getTodos, clearTodos } from './builtin/todowrite.js';
|
|
15
|
+
export { askUserQuestionTool, formatAnswersForAgent, formatAnswersForDisplay, } from './builtin/ask-user.js';
|
|
16
|
+
export type { Question as AskUserQuestion, QuestionOption as AskUserQuestionOption, QuestionAnswer as AskUserQuestionAnswer, AskUserQuestionInput, AskUserQuestionResult, } from './builtin/ask-user.js';
|
|
15
17
|
import { ToolRegistry } from './registry.js';
|
|
16
18
|
/**
|
|
17
19
|
* Create a registry with all built-in tools
|
|
@@ -52,5 +54,15 @@ export declare const builtinTools: (import("./types.js").Tool<{
|
|
|
52
54
|
status: "pending" | "in_progress" | "completed";
|
|
53
55
|
id?: string | undefined;
|
|
54
56
|
}[];
|
|
57
|
+
}> | import("./types.js").Tool<{
|
|
58
|
+
questions: {
|
|
59
|
+
question: string;
|
|
60
|
+
header: string;
|
|
61
|
+
options: {
|
|
62
|
+
label: string;
|
|
63
|
+
description: string;
|
|
64
|
+
}[];
|
|
65
|
+
multiSelect: boolean;
|
|
66
|
+
}[];
|
|
55
67
|
}>)[];
|
|
56
68
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,E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7 @@ export { grepTool } from './builtin/grep.js';
|
|
|
13
13
|
export { webfetchTool } from './builtin/webfetch.js';
|
|
14
14
|
export { websearchTool } from './builtin/websearch.js';
|
|
15
15
|
export { todowriteTool, getTodos, clearTodos } from './builtin/todowrite.js';
|
|
16
|
+
export { askUserQuestionTool, formatAnswersForAgent, formatAnswersForDisplay, } from './builtin/ask-user.js';
|
|
16
17
|
import { ToolRegistry } from './registry.js';
|
|
17
18
|
import { readTool } from './builtin/read.js';
|
|
18
19
|
import { writeTool } from './builtin/write.js';
|
|
@@ -23,6 +24,7 @@ import { grepTool } from './builtin/grep.js';
|
|
|
23
24
|
import { webfetchTool } from './builtin/webfetch.js';
|
|
24
25
|
import { websearchTool } from './builtin/websearch.js';
|
|
25
26
|
import { todowriteTool } from './builtin/todowrite.js';
|
|
27
|
+
import { askUserQuestionTool } from './builtin/ask-user.js';
|
|
26
28
|
/**
|
|
27
29
|
* Create a registry with all built-in tools
|
|
28
30
|
*/
|
|
@@ -38,6 +40,7 @@ export function createDefaultRegistry() {
|
|
|
38
40
|
webfetchTool,
|
|
39
41
|
websearchTool,
|
|
40
42
|
todowriteTool,
|
|
43
|
+
askUserQuestionTool,
|
|
41
44
|
]);
|
|
42
45
|
return registry;
|
|
43
46
|
}
|
|
@@ -54,5 +57,6 @@ export const builtinTools = [
|
|
|
54
57
|
webfetchTool,
|
|
55
58
|
websearchTool,
|
|
56
59
|
todowriteTool,
|
|
60
|
+
askUserQuestionTool,
|
|
57
61
|
];
|
|
58
62
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;A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Ae,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IACpC,QAAQ,CAAC,WAAW,CAAC;QACnB,QAAQ;QACR,SAAS;QACT,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,YAAY;QACZ,aAAa;QACb,aAAa;QACb,mBAAmB;KACpB,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,aAAa;IACb,mBAAmB;CACpB,CAAC"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -2,9 +2,26 @@
|
|
|
2
2
|
* Tool System Type Definitions
|
|
3
3
|
*/
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
+
export interface Question {
|
|
6
|
+
question: string;
|
|
7
|
+
header: string;
|
|
8
|
+
options: Array<{
|
|
9
|
+
label: string;
|
|
10
|
+
description: string;
|
|
11
|
+
}>;
|
|
12
|
+
multiSelect: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface QuestionAnswer {
|
|
15
|
+
question: string;
|
|
16
|
+
header: string;
|
|
17
|
+
selectedOptions: string[];
|
|
18
|
+
customInput?: string;
|
|
19
|
+
}
|
|
5
20
|
export interface ToolContext {
|
|
6
21
|
cwd: string;
|
|
7
22
|
abortSignal?: AbortSignal;
|
|
23
|
+
/** Callback for AskUserQuestion tool to interact with user */
|
|
24
|
+
askUser?: (questions: Question[]) => Promise<QuestionAnswer[]>;
|
|
8
25
|
}
|
|
9
26
|
export interface ToolResultMetadata {
|
|
10
27
|
title?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvD,WAAW,EAAE,OAAO,CAAC;CACtB;AAGD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,8DAA8D;IAC9D,OAAO,C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ACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,eAAe;;;iBAG1B,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,eAAe;;;iBAG1B,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,eAAe;;;;iBAI1B,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,mBAAmB;;;;;;;;iBAO9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,cAAc;;;;;;;;iBAIzB,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD,eAAO,MAAM,oBAAoB;;;;;;;;;;iBAE/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAOlE,wBAAgB,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwCjF"}
|
package/dist/tools/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],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D,WAAW;SACZ,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
- **Proposal ID**: 0012
|
|
4
4
|
- **Author**: gencode team
|
|
5
|
-
- **Status**:
|
|
5
|
+
- **Status**: Implemented
|
|
6
6
|
- **Created**: 2025-01-15
|
|
7
7
|
- **Updated**: 2025-01-16
|
|
8
|
+
- **Implemented**: 2025-01-16
|
|
8
9
|
|
|
9
10
|
## Summary
|
|
10
11
|
|
|
@@ -1014,6 +1015,70 @@ describe('AskUserQuestion Integration', () => {
|
|
|
1014
1015
|
|
|
1015
1016
|
No breaking changes to existing functionality.
|
|
1016
1017
|
|
|
1018
|
+
## Implementation Notes
|
|
1019
|
+
|
|
1020
|
+
### Files Created/Modified
|
|
1021
|
+
|
|
1022
|
+
| File | Action | Description |
|
|
1023
|
+
|------|--------|-------------|
|
|
1024
|
+
| `src/tools/builtin/ask-user.ts` | Created | Tool implementation with Zod schemas |
|
|
1025
|
+
| `src/tools/types.ts` | Modified | Added Question/QuestionAnswer interfaces to ToolContext |
|
|
1026
|
+
| `src/tools/index.ts` | Modified | Registered and exported askUserQuestionTool |
|
|
1027
|
+
| `src/agent/types.ts` | Modified | Added AgentEventAskUser type |
|
|
1028
|
+
| `src/agent/agent.ts` | Modified | Added askUserCallback and toolContext integration |
|
|
1029
|
+
| `src/agent/index.ts` | Modified | Exported AskUserCallback type |
|
|
1030
|
+
| `src/cli/components/QuestionPrompt.tsx` | Created | Question UI component with Claude Code style |
|
|
1031
|
+
| `src/cli/components/App.tsx` | Modified | Integrated QuestionPrompt and state management |
|
|
1032
|
+
| `src/cli/components/theme.ts` | Modified | Added new icons for checkboxes and chips |
|
|
1033
|
+
| `src/cli/components/index.ts` | Modified | Exported QuestionPrompt and AnswerDisplay |
|
|
1034
|
+
| `src/prompts/tools/ask-user.txt` | Created | Tool description for LLM |
|
|
1035
|
+
|
|
1036
|
+
### Key Implementation Details
|
|
1037
|
+
|
|
1038
|
+
1. **Callback-based architecture**: The tool uses a callback (`askUser`) injected via `ToolContext` to communicate with the CLI layer
|
|
1039
|
+
2. **Promise-based async flow**: Questions block agent execution until user responds
|
|
1040
|
+
3. **Claude Code UI alignment**: Uses radio buttons (○/●), checkboxes (☐/☑), chip headers, and matching color scheme
|
|
1041
|
+
4. **Auto-added "Other" option**: Every question automatically includes an "Other" option for custom input
|
|
1042
|
+
5. **Multi-select support**: Full support for both single-select and multi-select modes
|
|
1043
|
+
|
|
1044
|
+
### Prompt Guidance (Critical for LLM Tool Usage)
|
|
1045
|
+
|
|
1046
|
+
The system prompt in `src/prompts/system/base.txt` includes explicit guidance with bad examples to ensure the LLM uses the tool instead of plain text:
|
|
1047
|
+
|
|
1048
|
+
```
|
|
1049
|
+
CRITICAL: You MUST use the AskUserQuestion tool for ALL questions with choices.
|
|
1050
|
+
NEVER write numbered lists, bullet points, or "which do you prefer" questions as plain text.
|
|
1051
|
+
|
|
1052
|
+
## Wrong - Plain Text Questions (DO NOT DO THIS)
|
|
1053
|
+
|
|
1054
|
+
<bad-example>
|
|
1055
|
+
user: Set up a new database
|
|
1056
|
+
assistant: I can set up a database for you. Which one would you prefer?
|
|
1057
|
+
1. PostgreSQL - relational database
|
|
1058
|
+
2. MongoDB - document database
|
|
1059
|
+
3. SQLite - embedded database
|
|
1060
|
+
</bad-example>
|
|
1061
|
+
|
|
1062
|
+
## Correct - Use AskUserQuestion Tool
|
|
1063
|
+
|
|
1064
|
+
<example>
|
|
1065
|
+
user: Set up a new database
|
|
1066
|
+
assistant: [uses AskUserQuestion tool with structured options]
|
|
1067
|
+
</example>
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
The tool description in `src/prompts/tools/ask-user.txt` reinforces this with explicit "WRONG" examples:
|
|
1071
|
+
|
|
1072
|
+
```
|
|
1073
|
+
CRITICAL: You MUST use this tool for ANY question with 2+ choices.
|
|
1074
|
+
NEVER present options as plain text, numbered lists, or bullet points.
|
|
1075
|
+
|
|
1076
|
+
WRONG (never do this):
|
|
1077
|
+
- "Which do you prefer? 1. Option A 2. Option B"
|
|
1078
|
+
- "What type? - Web - CLI - API"
|
|
1079
|
+
- Writing any numbered or bulleted choices in your response
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1017
1082
|
## Theme Extensions
|
|
1018
1083
|
|
|
1019
1084
|
Add the following icons to `src/cli/components/theme.ts`:
|
package/docs/proposals/README.md
CHANGED
|
@@ -27,7 +27,7 @@ This directory contains enhancement proposals for the gencode project. Each prop
|
|
|
27
27
|
| [0009](./0009-hooks-system.md) | Hooks System | Draft |
|
|
28
28
|
| [0010](./0010-mcp-integration.md) | MCP Integration | Draft |
|
|
29
29
|
| [0011](./0011-custom-commands.md) | Custom Commands | Draft |
|
|
30
|
-
| [0012](./0012-ask-user-question.md) | AskUserQuestion Tool |
|
|
30
|
+
| [0012](./0012-ask-user-question.md) | AskUserQuestion Tool | Implemented |
|
|
31
31
|
| [0041](./0041-configuration-system.md) | Configuration System | Implemented |
|
|
32
32
|
| [0042](./0042-prompt-optimization.md) | Prompt System Optimization | Implemented |
|
|
33
33
|
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test script for AskUserQuestion tool
|
|
3
|
+
*
|
|
4
|
+
* Run with: npx tsx examples/test-ask-user.ts [mode]
|
|
5
|
+
*
|
|
6
|
+
* Modes:
|
|
7
|
+
* single - Single question, single select (default)
|
|
8
|
+
* multi - Single question, multi-select
|
|
9
|
+
* multiple - Multiple questions with review screen
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { render } from 'ink';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { QuestionPrompt } from '../src/cli/components/QuestionPrompt.js';
|
|
15
|
+
import type { Question, QuestionAnswer } from '../src/tools/types.js';
|
|
16
|
+
|
|
17
|
+
// Test questions - matching Claude Code style
|
|
18
|
+
const testQuestions: Question[] = [
|
|
19
|
+
{
|
|
20
|
+
question: 'What type of database would you like to create?',
|
|
21
|
+
header: 'DB Type',
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
label: 'PostgreSQL',
|
|
25
|
+
description: 'Powerful open-source relational database with advanced features like JSON support and full-text search',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'MySQL',
|
|
29
|
+
description: 'Popular relational database, great for web applications and general-purpose use',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: 'SQLite',
|
|
33
|
+
description: 'Lightweight file-based database, perfect for local development or embedded applications',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: 'MongoDB',
|
|
37
|
+
description: 'NoSQL document database for flexible schema and JSON-like documents',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
multiSelect: false,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const testMultiSelectQuestions: Question[] = [
|
|
45
|
+
{
|
|
46
|
+
question: 'Which features should we enable for your project?',
|
|
47
|
+
header: 'Features',
|
|
48
|
+
options: [
|
|
49
|
+
{
|
|
50
|
+
label: 'TypeScript',
|
|
51
|
+
description: 'Type safety and better IDE support with static type checking',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
label: 'ESLint + Prettier',
|
|
55
|
+
description: 'Code linting and automatic formatting for consistent code style',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
label: 'Testing (Vitest)',
|
|
59
|
+
description: 'Fast unit testing framework with native ESM support',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: 'Tailwind CSS',
|
|
63
|
+
description: 'Utility-first CSS framework for rapid UI development',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
multiSelect: true,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const testMultipleQuestions: Question[] = [
|
|
71
|
+
{
|
|
72
|
+
question: 'What type of database would you like to create?',
|
|
73
|
+
header: 'DB Type',
|
|
74
|
+
options: [
|
|
75
|
+
{
|
|
76
|
+
label: 'PostgreSQL',
|
|
77
|
+
description: 'Powerful open-source relational database with advanced features like JSON support and full-text search',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
label: 'MySQL',
|
|
81
|
+
description: 'Popular relational database, great for web applications and general-purpose use',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
label: 'SQLite',
|
|
85
|
+
description: 'Lightweight file-based database, perfect for local development or embedded applications',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
label: 'MongoDB',
|
|
89
|
+
description: 'NoSQL document database for flexible schema and JSON-like documents',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
multiSelect: false,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
question: 'What is the primary purpose of this database?',
|
|
96
|
+
header: 'Purpose',
|
|
97
|
+
options: [
|
|
98
|
+
{
|
|
99
|
+
label: 'GenCode project',
|
|
100
|
+
description: 'Add database functionality to the GenCode AI assistant project',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
label: 'New project',
|
|
104
|
+
description: 'Create a database for a separate new project',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: 'Learning/Testing',
|
|
108
|
+
description: 'Set up a database for experimentation and learning',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
multiSelect: false,
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
// Choose which test to run
|
|
116
|
+
const testMode = process.argv[2] || 'single';
|
|
117
|
+
|
|
118
|
+
let questions: Question[];
|
|
119
|
+
switch (testMode) {
|
|
120
|
+
case 'multi':
|
|
121
|
+
questions = testMultiSelectQuestions;
|
|
122
|
+
console.log('\n=== Testing Multi-Select Mode ===\n');
|
|
123
|
+
break;
|
|
124
|
+
case 'multiple':
|
|
125
|
+
questions = testMultipleQuestions;
|
|
126
|
+
console.log('\n=== Testing Multiple Questions with Review ===\n');
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
questions = testQuestions;
|
|
130
|
+
console.log('\n=== Testing Single-Select Mode ===\n');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function TestApp() {
|
|
134
|
+
const handleComplete = (answers: QuestionAnswer[]) => {
|
|
135
|
+
console.log('\n\n=== Answers Received ===');
|
|
136
|
+
answers.forEach((answer, i) => {
|
|
137
|
+
console.log(`\n${i + 1}. ${answer.header}`);
|
|
138
|
+
console.log(` Question: ${answer.question}`);
|
|
139
|
+
console.log(` Selected: ${answer.selectedOptions.join(', ') || '(none)'}`);
|
|
140
|
+
if (answer.customInput) {
|
|
141
|
+
console.log(` Custom: ${answer.customInput}`);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
console.log('\n');
|
|
145
|
+
process.exit(0);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const handleCancel = () => {
|
|
149
|
+
console.log('\n\nCancelled by user\n');
|
|
150
|
+
process.exit(0);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return React.createElement(QuestionPrompt, {
|
|
154
|
+
questions,
|
|
155
|
+
onComplete: handleComplete,
|
|
156
|
+
onCancel: handleCancel,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Render the test app
|
|
161
|
+
const { unmount } = render(React.createElement(TestApp));
|
|
162
|
+
|
|
163
|
+
// Handle Ctrl+C
|
|
164
|
+
process.on('SIGINT', () => {
|
|
165
|
+
unmount();
|
|
166
|
+
process.exit(0);
|
|
167
|
+
});
|
package/package.json
CHANGED
package/src/agent/agent.ts
CHANGED
|
@@ -16,6 +16,10 @@ import { SessionManager } from '../session/index.js';
|
|
|
16
16
|
import { MemoryManager, type LoadedMemory } from '../memory/index.js';
|
|
17
17
|
import type { AgentConfig, AgentEvent } from './types.js';
|
|
18
18
|
import { buildSystemPromptForModel, debugPromptLoading } from '../prompts/index.js';
|
|
19
|
+
import type { Question, QuestionAnswer } from '../tools/types.js';
|
|
20
|
+
|
|
21
|
+
// Type for askUser callback
|
|
22
|
+
export type AskUserCallback = (questions: Question[]) => Promise<QuestionAnswer[]>;
|
|
19
23
|
|
|
20
24
|
export class Agent {
|
|
21
25
|
private provider: LLMProvider;
|
|
@@ -27,6 +31,7 @@ export class Agent {
|
|
|
27
31
|
private messages: Message[] = [];
|
|
28
32
|
private sessionId: string | null = null;
|
|
29
33
|
private loadedMemory: LoadedMemory | null = null;
|
|
34
|
+
private askUserCallback: AskUserCallback | null = null;
|
|
30
35
|
|
|
31
36
|
constructor(config: AgentConfig) {
|
|
32
37
|
this.config = {
|
|
@@ -101,6 +106,14 @@ export class Agent {
|
|
|
101
106
|
return this.permissions;
|
|
102
107
|
}
|
|
103
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Set callback for AskUserQuestion tool
|
|
111
|
+
* This allows the CLI to handle user questioning
|
|
112
|
+
*/
|
|
113
|
+
setAskUserCallback(callback: AskUserCallback): void {
|
|
114
|
+
this.askUserCallback = callback;
|
|
115
|
+
}
|
|
116
|
+
|
|
104
117
|
/**
|
|
105
118
|
* Get memory manager for direct access
|
|
106
119
|
*/
|
|
@@ -336,12 +349,18 @@ export class Agent {
|
|
|
336
349
|
const toolResults: ToolResultContent[] = [];
|
|
337
350
|
const cwd = this.config.cwd ?? process.cwd();
|
|
338
351
|
|
|
352
|
+
// Build tool context with askUser callback
|
|
353
|
+
const toolContext = {
|
|
354
|
+
cwd,
|
|
355
|
+
askUser: this.askUserCallback ?? undefined,
|
|
356
|
+
};
|
|
357
|
+
|
|
339
358
|
for (const call of toolCalls) {
|
|
340
359
|
yield { type: 'tool_start', id: call.id, name: call.name, input: call.input };
|
|
341
360
|
|
|
342
361
|
const allowed = await this.permissions.requestPermission(call.name, call.input);
|
|
343
362
|
const result = allowed
|
|
344
|
-
? await this.registry.execute(call.name, call.input,
|
|
363
|
+
? await this.registry.execute(call.name, call.input, toolContext)
|
|
345
364
|
: { success: false, output: '', error: 'Permission denied by user' };
|
|
346
365
|
|
|
347
366
|
yield { type: 'tool_result', id: call.id, name: call.name, result };
|
package/src/agent/index.ts
CHANGED
package/src/agent/types.ts
CHANGED
|
@@ -61,10 +61,22 @@ export interface AgentEventDone {
|
|
|
61
61
|
text: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
export interface AgentEventAskUser {
|
|
65
|
+
type: 'ask_user';
|
|
66
|
+
id: string;
|
|
67
|
+
questions: Array<{
|
|
68
|
+
question: string;
|
|
69
|
+
header: string;
|
|
70
|
+
options: Array<{ label: string; description: string }>;
|
|
71
|
+
multiSelect: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
export type AgentEvent =
|
|
65
76
|
| AgentEventText
|
|
66
77
|
| AgentEventToolStart
|
|
67
78
|
| AgentEventToolResult
|
|
68
79
|
| AgentEventThinking
|
|
69
80
|
| AgentEventError
|
|
70
|
-
| AgentEventDone
|
|
81
|
+
| AgentEventDone
|
|
82
|
+
| AgentEventAskUser;
|