fix: resolve publish blockers for v3.7.4→v3.8.0 release
- Fix #1991 crash: optional chaining for task-history sessionID access - Fix #1992 think-mode: add antigravity entries to HIGH_VARIANT_MAP - Fix #1949 Copilot premium misattribution: use createInternalAgentTextPart - Fix #1982 load_skills: pass directory to discoverSkills for project-level skills - Fix command priority: sort scopePriority before .find(), project-first return - Fix Google provider transform: apply in userFallbackModels path - Fix ralph-loop TUI: optional chaining for event handler - Fix runtime-fallback: unify dual fallback engines, remove HTTP 400 from retry, fix pendingFallbackModel stuck state, add priority gate to skip model-fallback when runtime-fallback is active - Fix Prometheus task system: exempt from todowrite/todoread deny - Fix background_output: default full_session to true - Remove orphan hooks: hashline-edit-diff-enhancer (redundant with hashline_edit built-in diff), task-reminder (dead code) - Remove orphan config entries: 3 stale hook names from Zod schema - Fix disabled_hooks schema: accept arbitrary strings for forward compatibility - Register json-error-recovery hook in tool-guard pipeline - Add disabled_hooks gating for question-label-truncator, task-resume-info, claude-code-hooks - Update test expectations to match new behavior
This commit is contained in:
@@ -45,6 +45,24 @@ export function createChatMessageHandler(args: {
|
||||
output: ChatMessageHandlerOutput
|
||||
) => Promise<void> {
|
||||
const { ctx, pluginConfig, firstMessageVariantGate, hooks } = args
|
||||
const pluginContext = ctx as {
|
||||
client: {
|
||||
tui: {
|
||||
showToast: (input: {
|
||||
body: {
|
||||
title: string
|
||||
message: string
|
||||
variant: "warning"
|
||||
duration: number
|
||||
}
|
||||
}) => Promise<unknown>
|
||||
}
|
||||
}
|
||||
}
|
||||
const isRuntimeFallbackEnabled =
|
||||
hooks.runtimeFallback !== null &&
|
||||
hooks.runtimeFallback !== undefined &&
|
||||
(pluginConfig.runtime_fallback?.enabled ?? true)
|
||||
|
||||
return async (
|
||||
input: ChatMessageInput,
|
||||
@@ -58,7 +76,9 @@ export function createChatMessageHandler(args: {
|
||||
firstMessageVariantGate.markApplied(input.sessionID)
|
||||
}
|
||||
|
||||
await hooks.modelFallback?.["chat.message"]?.(input, output)
|
||||
if (!isRuntimeFallbackEnabled) {
|
||||
await hooks.modelFallback?.["chat.message"]?.(input, output)
|
||||
}
|
||||
const modelOverride = output.message["model"]
|
||||
if (
|
||||
modelOverride &&
|
||||
@@ -86,7 +106,7 @@ export function createChatMessageHandler(args: {
|
||||
}
|
||||
|
||||
if (!hasConnectedProvidersCache()) {
|
||||
ctx.client.tui
|
||||
pluginContext.client.tui
|
||||
.showToast({
|
||||
body: {
|
||||
title: "⚠️ Provider Cache Missing",
|
||||
@@ -130,6 +150,6 @@ export function createChatMessageHandler(args: {
|
||||
}
|
||||
}
|
||||
|
||||
applyUltraworkModelOverrideOnMessage(pluginConfig, input.agent, output, ctx.client.tui, input.sessionID)
|
||||
applyUltraworkModelOverrideOnMessage(pluginConfig, input.agent, output, pluginContext.client.tui, input.sessionID)
|
||||
}
|
||||
}
|
||||
|
||||
+37
-20
@@ -105,6 +105,23 @@ export function createEventHandler(args: {
|
||||
hooks: CreatedHooks
|
||||
}): (input: EventInput) => Promise<void> {
|
||||
const { ctx, firstMessageVariantGate, managers, hooks } = args
|
||||
const pluginContext = ctx as {
|
||||
directory: string
|
||||
client: {
|
||||
session: {
|
||||
abort: (input: { path: { id: string } }) => Promise<unknown>
|
||||
prompt: (input: {
|
||||
path: { id: string }
|
||||
body: { parts: Array<{ type: "text"; text: string }> }
|
||||
query: { directory: string }
|
||||
}) => Promise<unknown>
|
||||
}
|
||||
}
|
||||
}
|
||||
const isRuntimeFallbackEnabled =
|
||||
hooks.runtimeFallback !== null &&
|
||||
hooks.runtimeFallback !== undefined &&
|
||||
(args.pluginConfig.runtime_fallback?.enabled ?? true)
|
||||
|
||||
// Avoid triggering multiple abort+continue cycles for the same failing assistant message.
|
||||
const lastHandledModelErrorMessageID = new Map<string, string>()
|
||||
@@ -250,7 +267,7 @@ export function createEventHandler(args: {
|
||||
|
||||
// Model fallback: in practice, API/model failures often surface as assistant message errors.
|
||||
// session.error events are not guaranteed for all providers, so we also observe message.updated.
|
||||
if (sessionID && role === "assistant") {
|
||||
if (sessionID && role === "assistant" && !isRuntimeFallbackEnabled) {
|
||||
try {
|
||||
const assistantMessageID = info?.id as string | undefined
|
||||
const assistantError = info?.error
|
||||
@@ -292,12 +309,12 @@ export function createEventHandler(args: {
|
||||
if (setFallback && shouldAutoRetrySession(sessionID) && !hooks.stopContinuationGuard?.isStopped(sessionID)) {
|
||||
lastHandledModelErrorMessageID.set(sessionID, assistantMessageID)
|
||||
|
||||
await ctx.client.session.abort({ path: { id: sessionID } }).catch(() => {})
|
||||
await ctx.client.session
|
||||
await pluginContext.client.session.abort({ path: { id: sessionID } }).catch(() => {})
|
||||
await pluginContext.client.session
|
||||
.prompt({
|
||||
path: { id: sessionID },
|
||||
body: { parts: [{ type: "text", text: "continue" }] },
|
||||
query: { directory: ctx.directory },
|
||||
query: { directory: pluginContext.directory },
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
@@ -316,7 +333,7 @@ export function createEventHandler(args: {
|
||||
| { type?: string; attempt?: number; message?: string; next?: number }
|
||||
| undefined
|
||||
|
||||
if (sessionID && status?.type === "retry") {
|
||||
if (sessionID && status?.type === "retry" && !isRuntimeFallbackEnabled) {
|
||||
try {
|
||||
const retryMessage = typeof status.message === "string" ? status.message : ""
|
||||
const retryKey = `${status.attempt ?? "?"}:${status.next ?? "?"}:${retryMessage}`
|
||||
@@ -353,12 +370,12 @@ export function createEventHandler(args: {
|
||||
)
|
||||
|
||||
if (setFallback && shouldAutoRetrySession(sessionID) && !hooks.stopContinuationGuard?.isStopped(sessionID)) {
|
||||
await ctx.client.session.abort({ path: { id: sessionID } }).catch(() => {})
|
||||
await ctx.client.session
|
||||
await pluginContext.client.session.abort({ path: { id: sessionID } }).catch(() => {})
|
||||
await pluginContext.client.session
|
||||
.prompt({
|
||||
path: { id: sessionID },
|
||||
body: { parts: [{ type: "text", text: "continue" }] },
|
||||
query: { directory: ctx.directory },
|
||||
query: { directory: pluginContext.directory },
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
@@ -395,17 +412,17 @@ export function createEventHandler(args: {
|
||||
sessionID === getMainSessionID() &&
|
||||
!hooks.stopContinuationGuard?.isStopped(sessionID)
|
||||
) {
|
||||
await ctx.client.session
|
||||
await pluginContext.client.session
|
||||
.prompt({
|
||||
path: { id: sessionID },
|
||||
body: { parts: [{ type: "text", text: "continue" }] },
|
||||
query: { directory: ctx.directory },
|
||||
query: { directory: pluginContext.directory },
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
}
|
||||
// Second, try model fallback for model errors (rate limit, quota, provider issues, etc.)
|
||||
else if (sessionID && shouldRetryError(errorInfo)) {
|
||||
else if (sessionID && shouldRetryError(errorInfo) && !isRuntimeFallbackEnabled) {
|
||||
let agentName = getSessionAgent(sessionID)
|
||||
|
||||
if (!agentName && sessionID === getMainSessionID()) {
|
||||
@@ -432,15 +449,15 @@ export function createEventHandler(args: {
|
||||
)
|
||||
|
||||
if (setFallback && shouldAutoRetrySession(sessionID) && !hooks.stopContinuationGuard?.isStopped(sessionID)) {
|
||||
await ctx.client.session.abort({ path: { id: sessionID } }).catch(() => {})
|
||||
|
||||
await ctx.client.session
|
||||
.prompt({
|
||||
path: { id: sessionID },
|
||||
body: { parts: [{ type: "text", text: "continue" }] },
|
||||
query: { directory: ctx.directory },
|
||||
})
|
||||
.catch(() => {})
|
||||
await pluginContext.client.session.abort({ path: { id: sessionID } }).catch(() => {})
|
||||
|
||||
await pluginContext.client.session
|
||||
.prompt({
|
||||
path: { id: sessionID },
|
||||
body: { parts: [{ type: "text", text: "continue" }] },
|
||||
query: { directory: pluginContext.directory },
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ export type SessionHooks = {
|
||||
sisyphusJuniorNotepad: ReturnType<typeof createSisyphusJuniorNotepadHook> | null
|
||||
noSisyphusGpt: ReturnType<typeof createNoSisyphusGptHook> | null
|
||||
noHephaestusNonGpt: ReturnType<typeof createNoHephaestusNonGptHook> | null
|
||||
questionLabelTruncator: ReturnType<typeof createQuestionLabelTruncatorHook>
|
||||
taskResumeInfo: ReturnType<typeof createTaskResumeInfoHook>
|
||||
questionLabelTruncator: ReturnType<typeof createQuestionLabelTruncatorHook> | null
|
||||
taskResumeInfo: ReturnType<typeof createTaskResumeInfoHook> | null
|
||||
anthropicEffort: ReturnType<typeof createAnthropicEffortHook> | null
|
||||
runtimeFallback: ReturnType<typeof createRuntimeFallbackHook> | null
|
||||
}
|
||||
@@ -234,8 +234,12 @@ export function createSessionHooks(args: {
|
||||
? safeHook("no-hephaestus-non-gpt", () => createNoHephaestusNonGptHook(ctx))
|
||||
: null
|
||||
|
||||
const questionLabelTruncator = createQuestionLabelTruncatorHook()
|
||||
const taskResumeInfo = createTaskResumeInfoHook()
|
||||
const questionLabelTruncator = isHookEnabled("question-label-truncator")
|
||||
? safeHook("question-label-truncator", () => createQuestionLabelTruncatorHook())
|
||||
: null
|
||||
const taskResumeInfo = isHookEnabled("task-resume-info")
|
||||
? safeHook("task-resume-info", () => createTaskResumeInfoHook())
|
||||
: null
|
||||
|
||||
const anthropicEffort = isHookEnabled("anthropic-effort")
|
||||
? safeHook("anthropic-effort", () => createAnthropicEffortHook())
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
createTasksTodowriteDisablerHook,
|
||||
createWriteExistingFileGuardHook,
|
||||
createHashlineReadEnhancerHook,
|
||||
createJsonErrorRecoveryHook,
|
||||
} from "../../hooks"
|
||||
import {
|
||||
getOpenCodeVersion,
|
||||
@@ -31,6 +32,7 @@ export type ToolGuardHooks = {
|
||||
tasksTodowriteDisabler: ReturnType<typeof createTasksTodowriteDisablerHook> | null
|
||||
writeExistingFileGuard: ReturnType<typeof createWriteExistingFileGuardHook> | null
|
||||
hashlineReadEnhancer: ReturnType<typeof createHashlineReadEnhancerHook> | null
|
||||
jsonErrorRecovery: ReturnType<typeof createJsonErrorRecoveryHook> | null
|
||||
}
|
||||
|
||||
export function createToolGuardHooks(args: {
|
||||
@@ -99,6 +101,10 @@ export function createToolGuardHooks(args: {
|
||||
? safeHook("hashline-read-enhancer", () => createHashlineReadEnhancerHook(ctx, { hashline_edit: { enabled: pluginConfig.hashline_edit ?? true } }))
|
||||
: null
|
||||
|
||||
const jsonErrorRecovery = isHookEnabled("json-error-recovery")
|
||||
? safeHook("json-error-recovery", () => createJsonErrorRecoveryHook(ctx))
|
||||
: null
|
||||
|
||||
return {
|
||||
commentChecker,
|
||||
toolOutputTruncator,
|
||||
@@ -109,5 +115,6 @@ export function createToolGuardHooks(args: {
|
||||
tasksTodowriteDisabler,
|
||||
writeExistingFileGuard,
|
||||
hashlineReadEnhancer,
|
||||
jsonErrorRecovery,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
import { safeCreateHook } from "../../shared/safe-create-hook"
|
||||
|
||||
export type TransformHooks = {
|
||||
claudeCodeHooks: ReturnType<typeof createClaudeCodeHooksHook>
|
||||
claudeCodeHooks: ReturnType<typeof createClaudeCodeHooksHook> | null
|
||||
keywordDetector: ReturnType<typeof createKeywordDetectorHook> | null
|
||||
contextInjectorMessagesTransform: ReturnType<typeof createContextInjectorMessagesTransformHook>
|
||||
thinkingBlockValidator: ReturnType<typeof createThinkingBlockValidatorHook> | null
|
||||
@@ -30,14 +30,21 @@ export function createTransformHooks(args: {
|
||||
const { ctx, pluginConfig, isHookEnabled } = args
|
||||
const safeHookEnabled = args.safeHookEnabled ?? true
|
||||
|
||||
const claudeCodeHooks = createClaudeCodeHooksHook(
|
||||
ctx,
|
||||
{
|
||||
disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true,
|
||||
keywordDetectorDisabled: !isHookEnabled("keyword-detector"),
|
||||
},
|
||||
contextCollector,
|
||||
)
|
||||
const claudeCodeHooks = isHookEnabled("claude-code-hooks")
|
||||
? safeCreateHook(
|
||||
"claude-code-hooks",
|
||||
() =>
|
||||
createClaudeCodeHooksHook(
|
||||
ctx,
|
||||
{
|
||||
disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true,
|
||||
keywordDetectorDisabled: !isHookEnabled("keyword-detector"),
|
||||
},
|
||||
contextCollector,
|
||||
),
|
||||
{ enabled: safeHookEnabled },
|
||||
)
|
||||
: null
|
||||
|
||||
const keywordDetector = isHookEnabled("keyword-detector")
|
||||
? safeCreateHook(
|
||||
|
||||
@@ -44,5 +44,6 @@ export function createToolExecuteAfterHandler(args: {
|
||||
await hooks.atlasHook?.["tool.execute.after"]?.(input, output)
|
||||
await hooks.taskResumeInfo?.["tool.execute.after"]?.(input, output)
|
||||
await hooks.hashlineReadEnhancer?.["tool.execute.after"]?.(input, output)
|
||||
await hooks.jsonErrorRecovery?.["tool.execute.after"]?.(input, output)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user