Ver código fonte

refactor(pipeline): align hook activity thresholds

Ma 7 meses atrás
pai
commit
82c28425a3

+ 11 - 0
packages/core/src/__tests__/hook-policy.test.ts

@@ -1,5 +1,6 @@
 import { describe, expect, it } from "vitest";
 import {
+  HOOK_ACTIVITY_THRESHOLDS,
   HOOK_AGENDA_LIMITS,
   HOOK_HEALTH_DEFAULTS,
   HOOK_PHASE_THRESHOLDS,
@@ -30,4 +31,14 @@ describe("hook-policy", () => {
     expect(HOOK_PHASE_THRESHOLDS.lateProgress).toBeGreaterThan(HOOK_PHASE_THRESHOLDS.middleProgress);
     expect(HOOK_PRESSURE_WEIGHTS.resolveBiasMultiplier).toBe(10);
   });
+
+  it("keeps lifecycle activity and refresh thresholds on the same policy surface", () => {
+    expect(HOOK_ACTIVITY_THRESHOLDS.recentlyTouchedDormancy).toBe(1);
+    expect(HOOK_ACTIVITY_THRESHOLDS.longArcQuietHoldMaxAge).toBeGreaterThan(
+      HOOK_ACTIVITY_THRESHOLDS.freshPromiseAge,
+    );
+    expect(HOOK_ACTIVITY_THRESHOLDS.refreshDormancy).toBeGreaterThan(
+      HOOK_ACTIVITY_THRESHOLDS.longArcQuietHoldMaxDormancy,
+    );
+  });
 });

+ 2 - 1
packages/core/src/utils/hook-lifecycle.ts

@@ -1,5 +1,6 @@
 import type { HookPayoffTiming } from "../models/runtime-state.js";
 import {
+  HOOK_ACTIVITY_THRESHOLDS,
   HOOK_PHASE_THRESHOLDS,
   HOOK_PHASE_WEIGHT,
   HOOK_PRESSURE_WEIGHTS,
@@ -119,7 +120,7 @@ export function describeHookLifecycle(params: {
   const dormancy = Math.max(0, params.chapterNumber - Math.max(1, lastTouchChapter));
   const explicitProgressing = /^(progressing|advanced|重大推进|持续推进)$/i.test(params.status.trim());
   const phaseReady = HOOK_PHASE_WEIGHT[phase] >= HOOK_PHASE_WEIGHT[profile.minimumPhase];
-  const recentlyTouched = dormancy <= 1;
+  const recentlyTouched = dormancy <= HOOK_ACTIVITY_THRESHOLDS.recentlyTouchedDormancy;
   const overdue = phaseReady && age >= profile.overdueAge;
   const cadenceReady = timing === "slow-burn"
     ? phase === "late" || overdue

+ 8 - 0
packages/core/src/utils/hook-policy.ts

@@ -74,6 +74,14 @@ export const HOOK_PRESSURE_WEIGHTS = {
   criticalResolvePressure: 40,
 } as const;
 
+export const HOOK_ACTIVITY_THRESHOLDS = {
+  recentlyTouchedDormancy: 1,
+  longArcQuietHoldMaxAge: 2,
+  longArcQuietHoldMaxDormancy: 1,
+  refreshDormancy: 2,
+  freshPromiseAge: 1,
+} as const;
+
 export const HOOK_AGENDA_LIMITS: Record<HookAgendaLoad, {
   readonly staleDebt: number;
   readonly mustAdvance: number;

+ 8 - 3
packages/core/src/utils/memory-retrieval.ts

@@ -17,6 +17,7 @@ import {
   normalizeHookPayoffTiming,
 } from "./hook-lifecycle.js";
 import {
+  HOOK_ACTIVITY_THRESHOLDS,
   HOOK_AGENDA_LIMITS,
   HOOK_AGENDA_LOAD_THRESHOLDS,
   HOOK_PRESSURE_WEIGHTS,
@@ -592,11 +593,15 @@ function resolveHookMovement(params: {
     return "advance";
   }
 
-  if (longArc && params.lifecycle.age <= 2 && params.lifecycle.dormancy <= 1) {
+  if (
+    longArc
+    && params.lifecycle.age <= HOOK_ACTIVITY_THRESHOLDS.longArcQuietHoldMaxAge
+    && params.lifecycle.dormancy <= HOOK_ACTIVITY_THRESHOLDS.longArcQuietHoldMaxDormancy
+  ) {
     return "quiet-hold";
   }
 
-  if (params.lifecycle.dormancy >= 2) {
+  if (params.lifecycle.dormancy >= HOOK_ACTIVITY_THRESHOLDS.refreshDormancy) {
     return "refresh";
   }
 
@@ -637,7 +642,7 @@ function resolveHookPressureReason(params: {
       ? "long-arc-hold"
       : "fresh-promise";
   }
-  if (params.lifecycle.age <= 1) {
+  if (params.lifecycle.age <= HOOK_ACTIVITY_THRESHOLDS.freshPromiseAge) {
     return "fresh-promise";
   }
   return "building-debt";