@oh-my-pi/pi-coding-agent 15.5.11 → 15.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/types/cli-commands.d.ts +19 -0
- package/dist/types/commands/install.d.ts +51 -0
- package/dist/types/discovery/index.d.ts +1 -0
- package/dist/types/discovery/omp-extension-roots.d.ts +43 -0
- package/dist/types/discovery/omp-plugins.d.ts +1 -0
- package/dist/types/extensibility/plugins/loader.d.ts +12 -2
- package/dist/types/tools/todo-write.d.ts +30 -0
- package/package.json +8 -8
- package/src/cli-commands.ts +44 -0
- package/src/cli.ts +2 -32
- package/src/commands/install.ts +107 -0
- package/src/discovery/index.ts +1 -0
- package/src/discovery/omp-extension-roots.ts +190 -0
- package/src/discovery/omp-plugins.ts +383 -0
- package/src/extensibility/plugins/loader.ts +43 -18
- package/src/main.ts +12 -0
- package/src/modes/interactive-mode.ts +243 -12
- package/src/tools/todo-write.ts +64 -0
|
@@ -67,7 +67,7 @@ import type { LspStartupServerInfo } from "../tools";
|
|
|
67
67
|
import { normalizeLocalScheme } from "../tools/path-utils";
|
|
68
68
|
import { setAutoQaConsentHandler } from "../tools/report-tool-issue";
|
|
69
69
|
import { type ResolveToolDetails, runResolveInvocation } from "../tools/resolve";
|
|
70
|
-
import { formatPhaseDisplayName } from "../tools/todo-write";
|
|
70
|
+
import { formatPhaseDisplayName, selectStickyTodoWindow, todoMatchesAnyDescription } from "../tools/todo-write";
|
|
71
71
|
import { ToolError } from "../tools/tool-errors";
|
|
72
72
|
import type { EventBus } from "../utils/event-bus";
|
|
73
73
|
import { getEditorCommand, openInEditor } from "../utils/external-editor";
|
|
@@ -324,6 +324,10 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
324
324
|
#eventBus?: EventBus;
|
|
325
325
|
#eventBusUnsubscribers: Array<() => void> = [];
|
|
326
326
|
#welcomeComponent?: WelcomeComponent;
|
|
327
|
+
#todoSpinnerInterval?: NodeJS.Timeout;
|
|
328
|
+
#todoSpinnerFrame = 0;
|
|
329
|
+
#todoClosingTimeout?: NodeJS.Timeout;
|
|
330
|
+
#todoClosingState: "idle" | "playing" | "done" = "idle";
|
|
327
331
|
|
|
328
332
|
constructor(
|
|
329
333
|
session: AgentSession,
|
|
@@ -529,6 +533,12 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
529
533
|
this.#observerRegistry.setMainSession(this.sessionManager.getSessionFile() ?? undefined);
|
|
530
534
|
this.#observerRegistry.onChange(() => {
|
|
531
535
|
this.statusLine.setSubagentCount(this.#observerRegistry.getActiveSubagentCount());
|
|
536
|
+
// Auto-checkmark todos whose matching subagent just succeeded, then
|
|
537
|
+
// re-render so the running override (animated row when a subagent
|
|
538
|
+
// is doing the work for a still-pending todo) updates as subagents
|
|
539
|
+
// start, finish, or fail. Also handles spinner start/stop.
|
|
540
|
+
this.#reconcileTodosWithSubagents();
|
|
541
|
+
this.#renderTodoList();
|
|
532
542
|
this.ui.requestRender();
|
|
533
543
|
});
|
|
534
544
|
|
|
@@ -839,6 +849,7 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
839
849
|
this.#pendingSubmissionDispose = undefined;
|
|
840
850
|
}
|
|
841
851
|
this.editor.setText("");
|
|
852
|
+
this.ui.refreshNativeScrollbackIfDirty();
|
|
842
853
|
this.ensureLoadingAnimation();
|
|
843
854
|
this.ui.requestRender();
|
|
844
855
|
return submission;
|
|
@@ -949,21 +960,101 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
949
960
|
this.renderSessionContext(context);
|
|
950
961
|
}
|
|
951
962
|
|
|
952
|
-
#formatTodoLine(todo: TodoItem, prefix: string): string {
|
|
963
|
+
#formatTodoLine(todo: TodoItem, prefix: string, matched: boolean, spinnerOn: boolean): string {
|
|
953
964
|
const checkbox = theme.checkbox;
|
|
954
965
|
const marker = formatHudNoteMarker(todo.notes?.length ?? 0);
|
|
966
|
+
const frames = theme.spinnerFrames;
|
|
967
|
+
// When the spinner is ticking, use the current animated frame; otherwise
|
|
968
|
+
// fall back to the static "running" glyph so in_progress rows still look
|
|
969
|
+
// distinct from pending rows.
|
|
970
|
+
const runningGlyph =
|
|
971
|
+
spinnerOn && frames.length > 0
|
|
972
|
+
? (frames[this.#todoSpinnerFrame % frames.length] ?? theme.status.running)
|
|
973
|
+
: theme.status.running;
|
|
955
974
|
switch (todo.status) {
|
|
956
975
|
case "completed":
|
|
957
|
-
return
|
|
976
|
+
return (
|
|
977
|
+
theme.fg("success", `${prefix}${theme.status.success} ${chalk.strikethrough(todo.content)}`) + marker
|
|
978
|
+
);
|
|
958
979
|
case "in_progress":
|
|
959
|
-
return theme.fg("accent", `${prefix}${
|
|
980
|
+
return theme.fg("accent", `${prefix}${runningGlyph} ${todo.content}`) + marker;
|
|
960
981
|
case "abandoned":
|
|
961
982
|
return theme.fg("error", `${prefix}${checkbox.unchecked} ${chalk.strikethrough(todo.content)}`) + marker;
|
|
962
983
|
default:
|
|
984
|
+
if (matched) {
|
|
985
|
+
return theme.fg("accent", `${prefix}${runningGlyph} ${todo.content}`) + marker;
|
|
986
|
+
}
|
|
963
987
|
return theme.fg("dim", `${prefix}${checkbox.unchecked} ${todo.content}`) + marker;
|
|
964
988
|
}
|
|
965
989
|
}
|
|
966
990
|
|
|
991
|
+
#getActiveSubagentDescriptions(): string[] {
|
|
992
|
+
const out: string[] = [];
|
|
993
|
+
for (const session of this.#observerRegistry.getSessions()) {
|
|
994
|
+
if (session.kind !== "subagent") continue;
|
|
995
|
+
if (session.status !== "active") continue;
|
|
996
|
+
const candidate =
|
|
997
|
+
session.description?.trim() || session.progress?.description?.trim() || session.label?.trim();
|
|
998
|
+
if (candidate) out.push(candidate);
|
|
999
|
+
}
|
|
1000
|
+
return out;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Auto-complete any pending/in_progress todo whose content matches a
|
|
1005
|
+
* subagent that has finished successfully. Fires on every observer
|
|
1006
|
+
* `onChange` so the visual state stays in sync with subagent lifecycle
|
|
1007
|
+
* without requiring the agent to issue a follow-up `todo_write`. Failed
|
|
1008
|
+
* and aborted subagents are intentionally NOT auto-completed — those
|
|
1009
|
+
* stay open so the user (or the next agent turn) can decide what to do.
|
|
1010
|
+
*
|
|
1011
|
+
* Idempotent: only flips open tasks, never re-touches completed ones.
|
|
1012
|
+
*/
|
|
1013
|
+
#reconcileTodosWithSubagents(): void {
|
|
1014
|
+
const completedDescs: string[] = [];
|
|
1015
|
+
for (const session of this.#observerRegistry.getSessions()) {
|
|
1016
|
+
if (session.kind !== "subagent") continue;
|
|
1017
|
+
if (session.status !== "completed") continue;
|
|
1018
|
+
const candidate =
|
|
1019
|
+
session.description?.trim() || session.progress?.description?.trim() || session.label?.trim();
|
|
1020
|
+
if (candidate) completedDescs.push(candidate);
|
|
1021
|
+
}
|
|
1022
|
+
if (completedDescs.length === 0) return;
|
|
1023
|
+
|
|
1024
|
+
let mutated = false;
|
|
1025
|
+
const next: TodoPhase[] = this.todoPhases.map(phase => ({
|
|
1026
|
+
name: phase.name,
|
|
1027
|
+
tasks: phase.tasks.map(task => {
|
|
1028
|
+
if (task.status !== "pending" && task.status !== "in_progress") return task;
|
|
1029
|
+
if (!todoMatchesAnyDescription(task.content, completedDescs)) return task;
|
|
1030
|
+
mutated = true;
|
|
1031
|
+
return { ...task, status: "completed" as const };
|
|
1032
|
+
}),
|
|
1033
|
+
}));
|
|
1034
|
+
if (!mutated) return;
|
|
1035
|
+
this.todoPhases = next;
|
|
1036
|
+
this.session.setTodoPhases(next);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
#updateTodoSpinnerAnimation(needSpinner: boolean): void {
|
|
1040
|
+
if (needSpinner) {
|
|
1041
|
+
if (this.#todoSpinnerInterval) return;
|
|
1042
|
+
this.#todoSpinnerInterval = setInterval(() => {
|
|
1043
|
+
const frames = theme.spinnerFrames;
|
|
1044
|
+
if (frames.length === 0) return;
|
|
1045
|
+
this.#todoSpinnerFrame = (this.#todoSpinnerFrame + 1) % frames.length;
|
|
1046
|
+
// Rebuild the todo container so the new frame appears, then schedule
|
|
1047
|
+
// a paint. The renderer self-stops the interval once no row needs it.
|
|
1048
|
+
this.#renderTodoList();
|
|
1049
|
+
this.ui.requestRender();
|
|
1050
|
+
}, 80);
|
|
1051
|
+
} else if (this.#todoSpinnerInterval) {
|
|
1052
|
+
clearInterval(this.#todoSpinnerInterval);
|
|
1053
|
+
this.#todoSpinnerInterval = undefined;
|
|
1054
|
+
this.#todoSpinnerFrame = 0;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
967
1058
|
#getActivePhase(phases: TodoPhase[]): TodoPhase | undefined {
|
|
968
1059
|
const nonEmpty = phases.filter(phase => phase.tasks.length > 0);
|
|
969
1060
|
const active = nonEmpty.find(phase =>
|
|
@@ -976,44 +1067,183 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
976
1067
|
this.todoContainer.clear();
|
|
977
1068
|
const phases = this.todoPhases.filter(phase => phase.tasks.length > 0);
|
|
978
1069
|
if (phases.length === 0) {
|
|
1070
|
+
this.#updateTodoSpinnerAnimation(false);
|
|
1071
|
+
this.#stopTodoClosingAnimation();
|
|
1072
|
+
this.#todoClosingState = "idle";
|
|
979
1073
|
return;
|
|
980
1074
|
}
|
|
981
1075
|
|
|
1076
|
+
// When every visible task is completed or abandoned, fold the panel
|
|
1077
|
+
// away with a brief celebratory animation (see
|
|
1078
|
+
// #startTodoClosingAnimation). State machine guards against replaying
|
|
1079
|
+
// on every re-render once the animation has finished.
|
|
1080
|
+
const allClosed = phases.every(phase =>
|
|
1081
|
+
phase.tasks.every(t => t.status === "completed" || t.status === "abandoned"),
|
|
1082
|
+
);
|
|
1083
|
+
if (allClosed) {
|
|
1084
|
+
this.#updateTodoSpinnerAnimation(false);
|
|
1085
|
+
if (this.#todoClosingState === "done") return;
|
|
1086
|
+
if (this.#todoClosingState === "idle") this.#startTodoClosingAnimation(phases);
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
// Any open task here means the close animation is no longer applicable.
|
|
1090
|
+
this.#stopTodoClosingAnimation();
|
|
1091
|
+
this.#todoClosingState = "idle";
|
|
1092
|
+
|
|
982
1093
|
const indent = " ";
|
|
983
1094
|
const hook = theme.tree.hook;
|
|
984
1095
|
const lines = ["", indent + theme.bold(theme.fg("accent", "Todos"))];
|
|
985
1096
|
|
|
1097
|
+
const activeDescs = this.#getActiveSubagentDescriptions();
|
|
1098
|
+
// Cache matcher results so we don't re-scan the description list per row
|
|
1099
|
+
// twice (once for the spinner decision, once for the render).
|
|
1100
|
+
const matchedSet = new Set<TodoItem>();
|
|
1101
|
+
const isMatched = (todo: TodoItem): boolean => {
|
|
1102
|
+
if (activeDescs.length === 0) return false;
|
|
1103
|
+
if (matchedSet.has(todo)) return true;
|
|
1104
|
+
if (todoMatchesAnyDescription(todo.content, activeDescs)) {
|
|
1105
|
+
matchedSet.add(todo);
|
|
1106
|
+
return true;
|
|
1107
|
+
}
|
|
1108
|
+
return false;
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
// The cube animates whenever any visible open todo is "live":
|
|
1112
|
+
// (a) status is in_progress (the agent itself is working it), or
|
|
1113
|
+
// (b) a still-pending todo has a matching in-flight subagent doing
|
|
1114
|
+
// the work for it. The renderer self-stops the interval once no row
|
|
1115
|
+
// qualifies, so an orphan in_progress row at end-of-session keeps
|
|
1116
|
+
// ticking — that's the intentional "this todo is still open" signal.
|
|
1117
|
+
let needsSpinner = false;
|
|
1118
|
+
const considerForSpinner = (todo: TodoItem): void => {
|
|
1119
|
+
if (todo.status === "in_progress") {
|
|
1120
|
+
needsSpinner = true;
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
if (todo.status !== "pending") return;
|
|
1124
|
+
if (isMatched(todo)) needsSpinner = true;
|
|
1125
|
+
};
|
|
1126
|
+
|
|
986
1127
|
if (!this.todoExpanded) {
|
|
987
1128
|
const activeIdx = phases.indexOf(this.#getActivePhase(phases) ?? phases[0]);
|
|
988
1129
|
const activePhase = phases[activeIdx];
|
|
989
|
-
if (!activePhase)
|
|
1130
|
+
if (!activePhase) {
|
|
1131
|
+
this.#updateTodoSpinnerAnimation(false);
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
const { visible, hiddenOpenCount } = selectStickyTodoWindow(activePhase.tasks, 5);
|
|
1135
|
+
for (const todo of visible) considerForSpinner(todo);
|
|
1136
|
+
this.#updateTodoSpinnerAnimation(needsSpinner);
|
|
1137
|
+
|
|
990
1138
|
lines.push(
|
|
991
1139
|
`${indent}${theme.fg("accent", `${hook} ${formatPhaseDisplayName(activePhase.name, activeIdx + 1)}`)}`,
|
|
992
1140
|
);
|
|
993
|
-
|
|
994
|
-
visibleTasks.forEach((todo, index) => {
|
|
1141
|
+
visible.forEach((todo, index) => {
|
|
995
1142
|
const prefix = `${indent}${index === 0 ? hook : " "} `;
|
|
996
|
-
lines.push(this.#formatTodoLine(todo, prefix));
|
|
1143
|
+
lines.push(this.#formatTodoLine(todo, prefix, matchedSet.has(todo), needsSpinner));
|
|
997
1144
|
});
|
|
998
|
-
if (
|
|
999
|
-
|
|
1000
|
-
lines.push(theme.fg("muted", `${indent} ${hook} +${remaining} more`));
|
|
1145
|
+
if (hiddenOpenCount > 0) {
|
|
1146
|
+
lines.push(theme.fg("muted", `${indent} ${hook} +${hiddenOpenCount} more`));
|
|
1001
1147
|
}
|
|
1002
1148
|
this.todoContainer.addChild(new Text(lines.join("\n"), 1, 0));
|
|
1003
1149
|
return;
|
|
1004
1150
|
}
|
|
1005
1151
|
|
|
1152
|
+
for (const phase of phases) for (const todo of phase.tasks) considerForSpinner(todo);
|
|
1153
|
+
this.#updateTodoSpinnerAnimation(needsSpinner);
|
|
1154
|
+
|
|
1006
1155
|
phases.forEach((phase, phaseIndex) => {
|
|
1007
1156
|
lines.push(`${indent}${theme.fg("accent", `${hook} ${formatPhaseDisplayName(phase.name, phaseIndex + 1)}`)}`);
|
|
1008
1157
|
phase.tasks.forEach((todo, index) => {
|
|
1009
1158
|
const prefix = `${indent}${index === 0 ? hook : " "} `;
|
|
1010
|
-
lines.push(this.#formatTodoLine(todo, prefix));
|
|
1159
|
+
lines.push(this.#formatTodoLine(todo, prefix, matchedSet.has(todo), needsSpinner));
|
|
1011
1160
|
});
|
|
1012
1161
|
});
|
|
1013
1162
|
|
|
1014
1163
|
this.todoContainer.addChild(new Text(lines.join("\n"), 1, 0));
|
|
1015
1164
|
}
|
|
1016
1165
|
|
|
1166
|
+
/**
|
|
1167
|
+
* Play a short "all done" close animation: a celebratory bright frame,
|
|
1168
|
+
* a brief dim transition, then a row-by-row vertical collapse until the
|
|
1169
|
+
* panel is empty. Triggered from #renderTodoList exactly once per
|
|
1170
|
+
* open-to-all-closed transition; #todoClosingState gates re-entry.
|
|
1171
|
+
*
|
|
1172
|
+
* While playing, the animator owns the panel container; #renderTodoList
|
|
1173
|
+
* returns early. Subsequent renders with state === "done" keep the
|
|
1174
|
+
* panel hidden until a fresh open task flips state back to "idle".
|
|
1175
|
+
*/
|
|
1176
|
+
#startTodoClosingAnimation(phases: TodoPhase[]): void {
|
|
1177
|
+
this.#stopTodoClosingAnimation();
|
|
1178
|
+
this.#todoClosingState = "playing";
|
|
1179
|
+
|
|
1180
|
+
const indent = " ";
|
|
1181
|
+
const hook = theme.tree.hook;
|
|
1182
|
+
const snapshot: string[] = ["", `${indent}Todos ${theme.status.success}`];
|
|
1183
|
+
for (let i = 0; i < phases.length; i++) {
|
|
1184
|
+
const phase = phases[i];
|
|
1185
|
+
snapshot.push(`${indent}${hook} ${formatPhaseDisplayName(phase.name, i + 1)}`);
|
|
1186
|
+
for (let j = 0; j < phase.tasks.length; j++) {
|
|
1187
|
+
const task = phase.tasks[j];
|
|
1188
|
+
const mark = task.status === "abandoned" ? theme.status.aborted : theme.status.success;
|
|
1189
|
+
const prefix = `${indent}${j === 0 ? hook : " "} `;
|
|
1190
|
+
snapshot.push(`${prefix}${mark} ${task.content}`);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// Frame schedule (tint, drop-from-bottom, hold-ms). Frame 0 holds long
|
|
1195
|
+
// enough for the user to actually read the final checkmarks before the
|
|
1196
|
+
// fade starts; later frames fade and progressively drop rows from the
|
|
1197
|
+
// bottom for the collapse effect. Total runtime ≈ 1.4s.
|
|
1198
|
+
const frames = [
|
|
1199
|
+
{ tint: "success" as const, drop: 0, holdMs: 900 },
|
|
1200
|
+
{ tint: "success" as const, drop: 0, holdMs: 150 },
|
|
1201
|
+
{ tint: "muted" as const, drop: 1, holdMs: 90 },
|
|
1202
|
+
{ tint: "muted" as const, drop: 2, holdMs: 90 },
|
|
1203
|
+
{ tint: "dim" as const, drop: 3, holdMs: 80 },
|
|
1204
|
+
{ tint: "dim" as const, drop: 4, holdMs: 80 },
|
|
1205
|
+
];
|
|
1206
|
+
|
|
1207
|
+
let frameIdx = 0;
|
|
1208
|
+
const tick = (): void => {
|
|
1209
|
+
if (this.#todoClosingState !== "playing") return;
|
|
1210
|
+
if (frameIdx >= frames.length) {
|
|
1211
|
+
this.todoContainer.clear();
|
|
1212
|
+
this.#stopTodoClosingAnimation();
|
|
1213
|
+
this.#todoClosingState = "done";
|
|
1214
|
+
this.ui.requestRender();
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const { tint, drop, holdMs } = frames[frameIdx];
|
|
1218
|
+
const visibleCount = Math.max(0, snapshot.length - drop);
|
|
1219
|
+
this.todoContainer.clear();
|
|
1220
|
+
if (visibleCount > 0) {
|
|
1221
|
+
const visible = snapshot.slice(0, visibleCount);
|
|
1222
|
+
const painted = visible.map((line, idx) => {
|
|
1223
|
+
if (idx === 1) {
|
|
1224
|
+
// Header row gets a bold flourish on the opening tick.
|
|
1225
|
+
const colored = theme.fg(tint, line);
|
|
1226
|
+
return frameIdx === 0 ? theme.bold(colored) : colored;
|
|
1227
|
+
}
|
|
1228
|
+
return theme.fg(tint, line);
|
|
1229
|
+
});
|
|
1230
|
+
this.todoContainer.addChild(new Text(painted.join("\n"), 1, 0));
|
|
1231
|
+
}
|
|
1232
|
+
this.ui.requestRender();
|
|
1233
|
+
frameIdx++;
|
|
1234
|
+
this.#todoClosingTimeout = setTimeout(tick, holdMs);
|
|
1235
|
+
};
|
|
1236
|
+
|
|
1237
|
+
tick();
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
#stopTodoClosingAnimation(): void {
|
|
1241
|
+
if (this.#todoClosingTimeout) {
|
|
1242
|
+
clearTimeout(this.#todoClosingTimeout);
|
|
1243
|
+
this.#todoClosingTimeout = undefined;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1017
1247
|
async #loadTodoList(): Promise<void> {
|
|
1018
1248
|
this.todoPhases = this.session.getTodoPhases();
|
|
1019
1249
|
this.#renderTodoList();
|
|
@@ -2035,6 +2265,7 @@ export class InteractiveMode implements InteractiveModeContext {
|
|
|
2035
2265
|
this.loadingAnimation = undefined;
|
|
2036
2266
|
}
|
|
2037
2267
|
this.#cleanupMicAnimation();
|
|
2268
|
+
this.#updateTodoSpinnerAnimation(false);
|
|
2038
2269
|
this.#cancelGoalContinuation();
|
|
2039
2270
|
if (this.#sttController) {
|
|
2040
2271
|
this.#sttController.dispose();
|
package/src/tools/todo-write.ts
CHANGED
|
@@ -139,6 +139,70 @@ export function getLatestTodoPhasesFromEntries(entries: SessionEntry[]): TodoPha
|
|
|
139
139
|
return [];
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Pick the actionable window of tasks to display in the sticky todo panel.
|
|
144
|
+
*
|
|
145
|
+
* Returns up to `maxVisible` open (pending / in_progress) tasks in their
|
|
146
|
+
* original phase order, plus the count of remaining open tasks not shown so
|
|
147
|
+
* the caller can render a `+N more` hint. When every task in `tasks` is
|
|
148
|
+
* closed (completed or abandoned), returns the trailing `maxVisible` tasks
|
|
149
|
+
* with `hiddenOpenCount = 0`, so the panel keeps useful context until the
|
|
150
|
+
* active-phase pointer advances on the next `todo_write`.
|
|
151
|
+
*
|
|
152
|
+
* Task identity and order are preserved — this is a slice, never a sort.
|
|
153
|
+
*/
|
|
154
|
+
export function selectStickyTodoWindow(
|
|
155
|
+
tasks: TodoItem[],
|
|
156
|
+
maxVisible = 5,
|
|
157
|
+
): { visible: TodoItem[]; hiddenOpenCount: number } {
|
|
158
|
+
const openTasks = tasks.filter(t => t.status === "pending" || t.status === "in_progress");
|
|
159
|
+
if (openTasks.length > 0) {
|
|
160
|
+
const visible = openTasks.slice(0, maxVisible);
|
|
161
|
+
return { visible, hiddenOpenCount: openTasks.length - visible.length };
|
|
162
|
+
}
|
|
163
|
+
const start = Math.max(0, tasks.length - maxVisible);
|
|
164
|
+
return { visible: tasks.slice(start), hiddenOpenCount: 0 };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Minimum overlap (after normalization) required for a substring match.
|
|
168
|
+
* Picked at six chars to admit single-word identifiers like "review" /
|
|
169
|
+
* "Sonnet" without admitting tiny common substrings like "test" / "fix"
|
|
170
|
+
* that would collide across unrelated todos. */
|
|
171
|
+
const TODO_DESCRIPTION_MIN_OVERLAP = 6;
|
|
172
|
+
|
|
173
|
+
function normalizeForTodoMatch(value: string): string {
|
|
174
|
+
return value
|
|
175
|
+
.toLowerCase()
|
|
176
|
+
.replace(/[^\p{L}\p{N}]+/gu, " ")
|
|
177
|
+
.trim();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Report whether `content` likely names the same work as any entry in
|
|
182
|
+
* `descriptions`. Used by the sticky todo panel to light up a pending todo
|
|
183
|
+
* when an in-flight subagent is doing the work for it, without requiring
|
|
184
|
+
* the caller to flip the todo's status.
|
|
185
|
+
*
|
|
186
|
+
* Matching is normalize-then-equal first (lowercased; punctuation and
|
|
187
|
+
* whitespace runs both collapsed to a single space; trimmed), with a
|
|
188
|
+
* substring fallback in either direction so minor wording drift
|
|
189
|
+
* ("Sonnet #2: bug scan" vs "Sonnet #2") still links up. The substring
|
|
190
|
+
* fallback requires at least {@link TODO_DESCRIPTION_MIN_OVERLAP} chars on
|
|
191
|
+
* the contained side.
|
|
192
|
+
*/
|
|
193
|
+
export function todoMatchesAnyDescription(content: string, descriptions: readonly string[]): boolean {
|
|
194
|
+
const target = normalizeForTodoMatch(content);
|
|
195
|
+
if (!target) return false;
|
|
196
|
+
for (const desc of descriptions) {
|
|
197
|
+
const candidate = normalizeForTodoMatch(desc);
|
|
198
|
+
if (!candidate) continue;
|
|
199
|
+
if (target === candidate) return true;
|
|
200
|
+
if (target.length >= TODO_DESCRIPTION_MIN_OVERLAP && candidate.includes(target)) return true;
|
|
201
|
+
if (candidate.length >= TODO_DESCRIPTION_MIN_OVERLAP && target.includes(candidate)) return true;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
|
|
142
206
|
function resolveTaskOrError(
|
|
143
207
|
phases: TodoPhase[],
|
|
144
208
|
content: string | undefined,
|