6b66f69433
- Add buildContextualContinuationPrompt to include assistant message context
- Move extractPermissionPhrase to detector module for better separation
- Block continuation injection in subagent sessions
- Update handler to use contextual prompts with last response context
- Add tests for subagent session blocking and contextual prompts
- Update todo coordination test to verify new prompt format
🤖 Generated with assistance of OhMyOpenCode
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { DEFAULT_STALL_PATTERNS } from "./constants"
|
|
|
|
function getTrailingSegment(text: string): string {
|
|
const normalized = text.trim().replace(/\s+/g, " ")
|
|
if (!normalized) return ""
|
|
|
|
const sentenceParts = normalized.split(/(?<=[.!?])\s+/)
|
|
return sentenceParts[sentenceParts.length - 1]?.trim().toLowerCase() ?? ""
|
|
}
|
|
|
|
export function detectStallPattern(
|
|
text: string,
|
|
patterns: readonly string[] = DEFAULT_STALL_PATTERNS,
|
|
): boolean {
|
|
if (!text.trim()) return false
|
|
|
|
const tail = text.slice(-800)
|
|
const lines = tail.split("\n").map((line) => line.trim()).filter(Boolean)
|
|
const hotZone = lines.slice(-3).join(" ")
|
|
const trailingSegment = getTrailingSegment(hotZone)
|
|
|
|
return patterns.some((pattern) => trailingSegment.startsWith(pattern.toLowerCase()))
|
|
}
|
|
|
|
export function extractPermissionPhrase(text: string): string | null {
|
|
const tail = text.slice(-800)
|
|
const lines = tail.split("\n").map((line) => line.trim()).filter(Boolean)
|
|
const hotZone = lines.slice(-3).join(" ")
|
|
const sentenceParts = hotZone.trim().replace(/\s+/g, " ").split(/(?<=[.!?])\s+/)
|
|
const trailingSegment = sentenceParts[sentenceParts.length - 1]?.trim().toLowerCase() ?? ""
|
|
return trailingSegment || null
|
|
}
|