Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): 提问卡片「自行键入」的答案原样回给 Pi,不再当作取消 (#4275)

FicoWanga8286bda4a8f
diff --git a/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts b/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts
index 1dbcabd969..8d1937327c 100644
--- a/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts
@@ -420,6 +420,19 @@ describe('cindy-bridge extension source', () => {
expect((await run).details).toEqual({ answers: { 'Continue?': 'No' }, cancelled: false });
});
+ it('returns a typed answer outside the options as a real answer, not a cancel (#4273)', async () => {
+ const tool = loadQuestionTool();
+ const result = await tool.execute('q', {
+ questions: [
+ { question: 'Continue?', options: ['Yes', 'No'] },
+ { question: 'Which color?', options: ['Red', 'Blue'] },
+ ],
+ }, undefined, undefined, {
+ ui: { select: async (_title: string, options: string[]) => (options.includes('Yes') ? 'No' : 'teal') },
+ });
+ expect(result.details).toEqual({ answers: { 'Continue?': 'No', 'Which color?': 'teal' }, cancelled: false });
+ });
+
it('reports cancellation without fabricating a choice and validates all questions before showing UI', async () => {
const tool = loadQuestionTool();
const ctx = { ui: { input: async () => undefined } };
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
index b10b2ac9a0..387fdf5c30 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
@@ -1311,6 +1311,51 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
}
});
+ it('passes a typed custom answer for a select dialog through and keeps an empty answer as cancel (#4273)', async () => {
+ const handle = await start();
+ const answers: Record<string, string> = {
+ 'Pick a color': 'teal',
+ 'Pick a size': '',
+ };
+ handle.setInteractionResolver(async (request) => {
+ if (request.kind !== 'ask_user_question') throw new Error(`unexpected interaction ${request.kind}`);
+ const question = request.questions[0]?.question ?? '';
+ expect(request.questions[0]?.options).toEqual([{ label: 'Red' }, { label: 'Blue' }]);
+ return { kind: 'ask_user_question', answers: { [question]: answers[question] ?? '' } };
+ });
+ try {
+ // The card's "type your own" entry yields an answer that is not one of `options`.
+ captured.onEvent!({
+ type: 'extension_ui_request',
+ id: 'select-custom',
+ method: 'select',
+ title: 'Pick a color',
+ options: ['Red', 'Blue'],
+ });
+ expect(await waitForResponse('select-custom')).toEqual({
+ type: 'extension_ui_response',
+ id: 'select-custom',
+ value: 'teal',
+ });
+
+ // An empty answer is still a skip/cancel, not a value.
+ captured.onEvent!({
+ type: 'extension_ui_request',
+ id: 'select-empty',
+ method: 'select',
+ title: 'Pick a size',
+ options: ['Red', 'Blue'],
+ });
+ expect(await waitForResponse('select-empty')).toEqual({
+ type: 'extension_ui_response',
+ id: 'select-empty',
+ cancelled: true,
+ });
+ } finally {
+ await handle.close();
+ }
+ });
+
it('surfaces Pi UI requests that Cindy cannot safely adapt at runtime', async () => {
const handle = await start();
const events: Array<Record<string, unknown>> = [];
diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.ts
index aa02a02b37..ff43fd0bbc 100644
--- a/packages/maker-core/src/agents/pi/index.ts
+++ b/packages/maker-core/src/agents/pi/index.ts
@@ -8456,10 +8456,10 @@ export class PiAgent extends BaseAgent {
proc.send({ type: 'extension_ui_response', id, cancelled: true });
return;
}
- if (method === 'select' && !options.includes(answer)) {
- proc.send({ type: 'extension_ui_response', id, cancelled: true });
- return;
- }
+ // Pi's RPC select contract only distinguishes cancelled from value and hands
+ // `value` back to the caller verbatim; Cindy's question card always offers a
+ // "type your own" entry, so a non-empty answer outside `options` is a real
+ // answer, not a cancel (#4273).
context.recordUserClarification(question, answer);
proc.send({ type: 'extension_ui_response', id, value: answer });
})