pi-ext
bugabingas pi extensions
owned by bugabinga
fix(goal): defer visible messages until idle
2fd15d344b5dc9057c0520e063ba5740453c3a4a
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (2)
extensions/goal/__tests__/unit.test.ts
Modified 91 91 options
?: Record
<string, unknown
>,
93 93 sent.
push({ message, options });
94 + entries.
push({ type:
"custom_message",
...message });
95 96 sendUserMessage: (content
: string)
=> {
96 97 sent.
push({ message: { content }, options: { triggerTurn:
true } });
187 188 it(
"records user steering as one criterion event, not a judge verdict",
async ()
=> {
188 - const harness
= createCompactionHarness({ idle:
false });
189 - await emitHarness(harness,
"before_agent_start", {
191 - "Start working toward this standing goal.\n\n<objective>ship it</objective>",
192 - systemPrompt:
"base",
189 + vi.
useFakeTimers();
191 + const harness
= createCompactionHarness({ idle:
false });
192 + await emitHarness(harness,
"before_agent_start", {
194 + "Start working toward this standing goal.\n\n<objective>ship it</objective>",
195 + systemPrompt:
"base",
195 - await emitHarness(harness,
"input", {
196 - text:
"use simpler code",
198 + await emitHarness(harness,
"input", {
199 + text:
"use simpler code",
202 + await vi.
runAllTimersAsync();
200 - const latest
= __goalTest.
latestGoalState({
201 - sessionManager: harness.ctx.sessionManager,
203 - const visibleCriterionEvents
= [
204 - ...harness.entries.
filter(
204 + const latest
= __goalTest.
latestGoalState({
205 + sessionManager: harness.ctx.sessionManager,
207 + const visibleCriterionEvents
= harness.entries.
filter(
206 209 entry.
type === "custom_message" && 207 210 entry.customType
=== "goal-event" && 208 211 entry.
display === true,
210 - ...harness.sent.
filter(
212 - (entry.message
as Record<
string,
unknown>).customType
=== 214 - (entry.message
as Record<
string,
unknown>).
display === true,
218 - expect(latest?.criteria).
toContain(
"use simpler code");
219 - expect(latest?.lastVerdict).
toBeUndefined();
220 - expect(latest?.lastReason).
toBeUndefined();
221 - expect(visibleCriterionEvents).
toHaveLength(
1);
214 + expect(latest?.criteria).
toContain(
"use simpler code");
215 + expect(latest?.lastVerdict).
toBeUndefined();
216 + expect(latest?.lastReason).
toBeUndefined();
217 + expect(visibleCriterionEvents).
toHaveLength(
1);
219 + vi.
useRealTimers();
224 223 it(
"applies a happy judge as one atomic completion transition",
async ()
=> {
extensions/goal/index.ts
Modified1038 1038 function appendVisibleCustomMessage(
1039 1039 pi
: ExtensionAPI,
1040 + ctx
: ExtensionContext,
1040 1041 customType
: string,
1041 1042 content
: string,
1042 1043 details
: Record<
string,
unknown>,
1044 - pi.
sendMessage({ customType, content, display:
true, details });
1045 + const send = ()
=> 1047 + { customType, content, display:
true, details },
1048 + { triggerTurn:
false },
1050 + if (ctx.
isIdle()) {
1054 + setTimeout(()
=> {
1058 + if (
!isStaleContextError(error))
throw error;
1047 1063 function appendGoalEvent(
1048 1064 pi
: ExtensionAPI,
1049 - _ctx
: ExtensionContext,
1065 + ctx
: ExtensionContext,
1051 1067 state
: GoalState | undefined,
1052 1068 data
: Record<
string,
unknown>
= {},
1064 1080 const suffix
= reason
?? text;
1065 1081 appendVisibleCustomMessage(
1067 1084 GOAL_EVENT_ENTRY,
1068 1085 `goal ${event}${suffix ? ` · ${cleanGoalText(suffix)}` : ""}`,
2094 2111 function appendJudge(
2095 2112 pi
: ExtensionAPI,
2096 - _ctx
: ExtensionContext,
2113 + ctx
: ExtensionContext,
2097 2114 event
: "start" | "verdict",
2098 2115 state
: GoalState,
2099 2116 verdict
?: JudgeVerdict,
2110 2127 if (
event !== "start")
return;
2111 2128 appendVisibleCustomMessage(
2113 2131 GOAL_JUDGE_ENTRY,
2114 2132 `goal judge running · turn ${data.turn}`,
3040 3058 pi.
appendEntry(GOAL_EVENT_ENTRY, payload);
3041 3059 appendVisibleCustomMessage(
3043 3062 GOAL_JUDGE_ENTRY,
3044 3063 `goal judge passed → goal complete · turn ${turnsUsed} · ${judgeDisplayReason(verdict.reason)}`,
3045 3064 {
...payload, verdict },
3065 3084 appendVisibleCustomMessage(
3067 3087 GOAL_JUDGE_ENTRY,
3068 3088 `goal judge sees blocker · turn ${turnsUsed} · ${judgeDisplayReason(verdict.reason)}`,
3069 3089 { goalId: state.
id, turn: turnsUsed, verdict },
3116 3136 appendVisibleCustomMessage(
3118 3139 GOAL_JUDGE_ENTRY,
3119 3140 `goal judge rejected completion · turn ${turnsUsed} · ${judgeDisplayReason(verdict.reason)}`,
3120 3141 { goalId: state.
id, turn: turnsUsed, verdict },