Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/tools/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,15 @@ export function registerWriteTool<Schema extends z.ZodObject>(
confirm_error: check.remedy,
confirm_token: fresh
}),
`Not applied — the confirmation token was rejected (${check.failure}). ${check.remedy} ` +
`A fresh token for this exact operation: \`${fresh}\`.`
// `check.remedy` says to call again *without* `confirm`, which is
// right when no token comes back and wrong here, because one does.
// It stays in `confirm_error` as the diagnosis; the text gives the
// single next action, worded as the plain preview words it. The
// token goes last in both: a reader clipping the trailing word or
// the final backticked span gets it, and prose after it would not.
`Not applied — the confirmation token was rejected (${check.failure}). ` +
`Do not resend the rejected one. To apply this, call ${spec.name} again with ` +
`the same arguments plus \`confirm\` set to \`${fresh}\`.`
);
}
} else {
Expand Down
26 changes: 26 additions & 0 deletions test/writeTool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ describe('write tool harness — preview and confirm', () => {
expect(content[0]?.text).toContain(structuredContent.confirm_token);
});

// Every failure that reissues carries a remedy telling the caller to call
// again *without* `confirm`, which contradicts the usable token in the very
// next sentence. A model that follows the remedy throws away a good token
// and spends another preview. The diagnosis stays in `confirm_error`.
it('gives one next action on a rejection, not two', async () => {
const { content, structuredContent } = await harness.call('delete_media', { id: '5', confirm: 'nonsense' });
const text = content[0]?.text ?? '';

expect(text).toContain(structuredContent.confirm_token);
expect(text).not.toContain('without `confirm`');
expect(structuredContent.confirm_error).toContain('without `confirm`');
});

// The token is the last thing in both texts on purpose. A reader clipping
// it out takes the trailing word or the final backticked span, and prose
// after the token defeats both — `unwrap` strips punctuation, not a clause.
it('ends both the preview and the rejection with the token itself', async () => {
const ending = /`v1\.[\w.-]+`\.?$/u;

const preview = await harness.call('delete_media', { id: '5' });
expect(preview.content[0]?.text.trimEnd()).toMatch(ending);

const rejected = await harness.call('delete_media', { id: '5', confirm: 'nonsense' });
expect(rejected.content[0]?.text.trimEnd()).toMatch(ending);
});

it('lets the fresh token from a rejection be used', async () => {
const rejected = await harness.call('delete_media', { id: '5', confirm: 'nonsense' });
const applied = await harness.call('delete_media', {
Expand Down
Loading