src / continuation.ts
src / continuation.ts
/**
* The note the model sees when a reply resumes after a pass cap or a compaction.
*
* A bare "continue the task" lets the model decide what "the task" is. Models with a
* plan or checklist in view read it as permission to work through all of it, and an
* invitation to "summarize the final result" makes them wrap up early. Quoting the
* user's last request ties the reply back to what was actually asked.
*/
import { ownWords } from "./naming";
import type { CanonMessage } from "./view";
export const CONTINUATION_PREFIX = "(Automatic note from context management, not a new request:";
const MAX_QUOTE = 400;
/** The user's most recent request in their own words, without text other plugins added. */
export function lastUserRequest(msgs: readonly CanonMessage[]): string {
for (let i = msgs.length - 1; i >= 0; i--) {
const m = msgs[i];
if (m.role !== "user" || m.text.startsWith(CONTINUATION_PREFIX)) continue;
const words = ownWords(m.text).replace(/\s+/g, " ").trim();
if (!words) continue;
return words.length > MAX_QUOTE ? words.slice(0, MAX_QUOTE - 1).replace(/\s+\S*$/, "") + "…" : words;
}
return "";
}
/** Sent after a pass of tool rounds ends mid-reply. */
export function continuationNote(request: string): string {
return request
? `${CONTINUATION_PREFIX} your reply was paused after several tool calls. Continue answering the user's last message, which was: "${request}" When that is answered, give the answer and stop.)`
: `${CONTINUATION_PREFIX} your reply was paused after several tool calls. Continue answering the user's last message. When that is answered, give the answer and stop.)`;
}
/** Stands in for the user turn when compaction left none in the recent part of the chat. */
export function resumedRequestNote(request: string): string {
return request
? `${CONTINUATION_PREFIX} the earlier conversation is summarized above. The request being answered is the user's last message, which was: "${request}")`
: `${CONTINUATION_PREFIX} the earlier conversation is summarized above. Continue answering the user's last message.)`;
}
/**
* The note the model sees when a reply resumes after a pass cap or a compaction.
*
* A bare "continue the task" lets the model decide what "the task" is. Models with a
* plan or checklist in view read it as permission to work through all of it, and an
* invitation to "summarize the final result" makes them wrap up early. Quoting the
* user's last request ties the reply back to what was actually asked.
*/
import { ownWords } from "./naming";
import type { CanonMessage } from "./view";
export const CONTINUATION_PREFIX = "(Automatic note from context management, not a new request:";
const MAX_QUOTE = 400;
/** The user's most recent request in their own words, without text other plugins added. */
export function lastUserRequest(msgs: readonly CanonMessage[]): string {
for (let i = msgs.length - 1; i >= 0; i--) {
const m = msgs[i];
if (m.role !== "user" || m.text.startsWith(CONTINUATION_PREFIX)) continue;
const words = ownWords(m.text).replace(/\s+/g, " ").trim();
if (!words) continue;
return words.length > MAX_QUOTE ? words.slice(0, MAX_QUOTE - 1).replace(/\s+\S*$/, "") + "…" : words;
}
return "";
}
/** Sent after a pass of tool rounds ends mid-reply. */
export function continuationNote(request: string): string {
return request
? `${CONTINUATION_PREFIX} your reply was paused after several tool calls. Continue answering the user's last message, which was: "${request}" When that is answered, give the answer and stop.)`
: `${CONTINUATION_PREFIX} your reply was paused after several tool calls. Continue answering the user's last message. When that is answered, give the answer and stop.)`;
}
/** Stands in for the user turn when compaction left none in the recent part of the chat. */
export function resumedRequestNote(request: string): string {
return request
? `${CONTINUATION_PREFIX} the earlier conversation is summarized above. The request being answered is the user's last message, which was: "${request}")`
: `${CONTINUATION_PREFIX} the earlier conversation is summarized above. Continue answering the user's last message.)`;
}