pi-ui-extend 0.1.34 → 0.1.35
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/README.md +20 -0
- package/dist/app/app.js +4 -2
- package/dist/app/constants.d.ts +2 -1
- package/dist/app/constants.js +6 -1
- package/dist/app/input/input-controller.d.ts +4 -1
- package/dist/app/input/input-controller.js +95 -16
- package/dist/app/input/input-paste-handler.js +3 -1
- package/dist/app/input/terminal-edit-shortcuts.d.ts +20 -0
- package/dist/app/input/terminal-edit-shortcuts.js +50 -16
- package/dist/app/rendering/conversation-entry-renderer.d.ts +1 -0
- package/dist/app/rendering/conversation-entry-renderer.js +1 -1
- package/dist/app/rendering/conversation-tool-renderer.d.ts +1 -0
- package/dist/app/rendering/conversation-tool-renderer.js +21 -0
- package/dist/app/rendering/conversation-viewport.d.ts +3 -0
- package/dist/app/rendering/conversation-viewport.js +41 -5
- package/dist/app/rendering/editor-layout-renderer.js +3 -2
- package/dist/app/rendering/editor-panels.js +27 -10
- package/dist/app/runtime.d.ts +1 -0
- package/dist/app/runtime.js +33 -14
- package/dist/app/session/session-event-controller.d.ts +7 -0
- package/dist/app/session/session-event-controller.js +78 -0
- package/dist/app/session/tabs-controller.js +3 -1
- package/dist/app/subagents/subagents-widget-controller.d.ts +10 -2
- package/dist/app/subagents/subagents-widget-controller.js +141 -70
- package/dist/app/terminal/terminal-controller.d.ts +10 -0
- package/dist/app/terminal/terminal-controller.js +91 -2
- package/dist/app/todo/todo-model.js +2 -0
- package/dist/app/todo/todo-widget-controller.d.ts +2 -0
- package/dist/app/todo/todo-widget-controller.js +17 -7
- package/dist/app/types.d.ts +4 -0
- package/dist/bundled-extensions/question/tui.js +8 -1
- package/dist/bundled-extensions/session-title/index.js +65 -14
- package/dist/input-editor-files.js +23 -4
- package/dist/markdown-format.d.ts +4 -1
- package/dist/markdown-format.js +76 -9
- package/external/pi-tools-suite/README.md +71 -1
- package/external/pi-tools-suite/package.json +3 -3
- package/external/pi-tools-suite/src/async-subagents/commands.ts +12 -6
- package/external/pi-tools-suite/src/async-subagents/index.ts +133 -37
- package/external/pi-tools-suite/src/context-usage.ts +6 -1
- package/external/pi-tools-suite/src/dcp/commands.ts +3 -2
- package/external/pi-tools-suite/src/dcp/compress-tool.ts +9 -4
- package/external/pi-tools-suite/src/dcp/config.ts +142 -6
- package/external/pi-tools-suite/src/dcp/index.ts +20 -8
- package/external/pi-tools-suite/src/dcp/prompts.ts +17 -9
- package/external/pi-tools-suite/src/dcp/pruner-candidates.ts +59 -15
- package/external/pi-tools-suite/src/dcp/pruner-metadata.ts +6 -8
- package/external/pi-tools-suite/src/dcp/pruner-nudge.ts +3 -3
- package/external/pi-tools-suite/src/default-pi-tools-suite-config.ts +51 -1
- package/external/pi-tools-suite/src/glm-coding-discipline/index.ts +16 -11
- package/external/pi-tools-suite/src/model-tools/index.ts +24 -12
- package/external/pi-tools-suite/src/prompt-commands/index.ts +11 -2
- package/external/pi-tools-suite/src/telegram-mirror/index.ts +66 -27
- package/external/pi-tools-suite/src/todo/index.ts +87 -16
- package/external/pi-tools-suite/src/todo/state/store.ts +41 -10
- package/external/pi-tools-suite/src/todo/todo.ts +49 -6
- package/external/pi-tools-suite/src/tool-descriptions.ts +4 -4
- package/package.json +7 -5
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { loadPiToolsSuiteConfig } from "../config.js";
|
|
3
|
+
import { isAgentBusyRaceError } from "../context-usage.js";
|
|
3
4
|
import { autoClearCompletedTodos } from "./state/auto-clear.js";
|
|
4
5
|
import { loadPersistedPlan, syncPersistedPlan } from "./state/persistence.js";
|
|
5
6
|
import { replayFromBranch } from "./state/replay.js";
|
|
6
7
|
import { ACTIVE_STATUSES, isTaskBlocked, selectVisibleTasks } from "./state/selectors.js";
|
|
7
8
|
import { applyTaskMutation } from "./state/state-reducer.js";
|
|
8
9
|
import { getState, replaceState } from "./state/store.js";
|
|
9
|
-
import { DEFAULT_PROMPT_GUIDELINES, DEFAULT_PROMPT_SNIPPET, publishTodoState, registerTodosCommand, registerTodoTool } from "./todo.js";
|
|
10
|
+
import { activateTodoStateScope, DEFAULT_PROMPT_GUIDELINES, DEFAULT_PROMPT_SNIPPET, publishTodoState, registerTodosCommand, registerTodoTool } from "./todo.js";
|
|
10
11
|
import type { Task, TaskMutationParams } from "./tool/types.js";
|
|
11
12
|
|
|
12
13
|
type AgentMessageLike = { role?: unknown; stopReason?: unknown; content?: unknown };
|
|
@@ -17,6 +18,11 @@ const TODO_NUDGE_IDLE_RETRY_DELAY_MS = 100;
|
|
|
17
18
|
const TODO_NUDGE_MAX_IDLE_ATTEMPTS = 40;
|
|
18
19
|
const ASK_USER_TOOL_NAMES = new Set(["ask_user", "ask_user_question", "question"]);
|
|
19
20
|
const TODO_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"] as const;
|
|
21
|
+
const TODO_THINKING_RESTORE_METADATA_KEY = "__piTodoRestoreThinking";
|
|
22
|
+
|
|
23
|
+
function isStaleExtensionContextError(error: unknown): boolean {
|
|
24
|
+
return error instanceof Error && /ctx is stale|stale ctx|stale after session replacement|stale after.*reload/i.test(error.message);
|
|
25
|
+
}
|
|
20
26
|
|
|
21
27
|
type TodoThinkingLevel = (typeof TODO_THINKING_LEVELS)[number];
|
|
22
28
|
type ModelLike = { reasoning?: boolean; thinkingLevelMap?: Partial<Record<TodoThinkingLevel, unknown | null>> };
|
|
@@ -108,7 +114,12 @@ function getPersistedPlanPrompt(path: string): string | undefined {
|
|
|
108
114
|
|
|
109
115
|
function emitPersistedPlanPrompt(pi: ExtensionAPI, ctx: ExtensionContext, prompt: string): void {
|
|
110
116
|
if (ctx.hasUI) {
|
|
111
|
-
|
|
117
|
+
try {
|
|
118
|
+
pi.sendUserMessage(prompt);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (isStaleExtensionContextError(error)) return;
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
112
123
|
return;
|
|
113
124
|
}
|
|
114
125
|
console.log(prompt);
|
|
@@ -128,10 +139,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
128
139
|
const thinkingPrompt = todoThinkingEnabled ? buildThinkingPromptParts(currentModel) : {};
|
|
129
140
|
registerTodoTool(pi, {
|
|
130
141
|
...thinkingPrompt,
|
|
142
|
+
prepareMutation: (state, _ctx, info) => {
|
|
143
|
+
if (!todoThinkingEnabled) return info.params;
|
|
144
|
+
if (info.action === "update") return prepareTodoThinkingMutation(state, info.params);
|
|
145
|
+
if (info.action === "batch_update") {
|
|
146
|
+
return {
|
|
147
|
+
...info.params,
|
|
148
|
+
items: (info.params.items ?? []).map((item) => prepareTodoThinkingMutation(state, item)),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return info.params;
|
|
152
|
+
},
|
|
131
153
|
afterCommit: async (state, ctx, info) => {
|
|
132
154
|
if (todoThinkingEnabled) applyTodoThinkingAfterCommit(state, info);
|
|
133
155
|
try {
|
|
134
|
-
const sync = syncPersistedPlan(ctx.cwd,
|
|
156
|
+
const sync = syncPersistedPlan(ctx.cwd, info.committedState);
|
|
135
157
|
if (sync?.completed) console.log(`rpiv-todo: completed persisted plan and removed ${sync.path}`);
|
|
136
158
|
} catch (err) {
|
|
137
159
|
console.warn(`rpiv-todo: failed to sync persisted plan — ${(err as Error).message}`);
|
|
@@ -144,7 +166,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
144
166
|
const mutations = getTodoThinkingMutations(info.action, info.params);
|
|
145
167
|
for (const mutation of mutations) {
|
|
146
168
|
if (mutation.id === undefined || mutation.status === "in_progress") continue;
|
|
147
|
-
restoreTaskThinking(mutation.id);
|
|
169
|
+
restoreTaskThinking(mutation.id, state);
|
|
148
170
|
}
|
|
149
171
|
restoreInactiveTodoThinking(state);
|
|
150
172
|
for (const mutation of mutations) {
|
|
@@ -167,6 +189,34 @@ export default function (pi: ExtensionAPI) {
|
|
|
167
189
|
return isTodoThinkingLevel(level) ? level : undefined;
|
|
168
190
|
}
|
|
169
191
|
|
|
192
|
+
function prepareTodoThinkingMutation(state: ReturnType<typeof getState>, params: TaskMutationParams): TaskMutationParams {
|
|
193
|
+
if (params.id === undefined) return params;
|
|
194
|
+
const current = state.tasks.find((task) => task.id === params.id);
|
|
195
|
+
if (!current) return params;
|
|
196
|
+
const nextStatus = params.status ?? current.status;
|
|
197
|
+
const nextThinking = params.thinking ?? current.thinking;
|
|
198
|
+
const shouldCapturePreviousThinking =
|
|
199
|
+
nextStatus === "in_progress" && nextThinking !== undefined && (current.status !== "in_progress" || params.thinking !== undefined);
|
|
200
|
+
if (!shouldCapturePreviousThinking) return params;
|
|
201
|
+
const currentThinking = getCurrentThinkingLevel();
|
|
202
|
+
if (!currentThinking) return params;
|
|
203
|
+
return {
|
|
204
|
+
...params,
|
|
205
|
+
metadata: {
|
|
206
|
+
...(params.metadata ?? {}),
|
|
207
|
+
[TODO_THINKING_RESTORE_METADATA_KEY]: currentThinking,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function getRememberedThinking(taskId: number, state: ReturnType<typeof getState>): TodoThinkingLevel | undefined {
|
|
213
|
+
const remembered = rememberedThinkingByTaskId.get(taskId);
|
|
214
|
+
if (remembered) return remembered;
|
|
215
|
+
const task = state.tasks.find((item) => item.id === taskId);
|
|
216
|
+
const stored = task?.metadata?.[TODO_THINKING_RESTORE_METADATA_KEY];
|
|
217
|
+
return isTodoThinkingLevel(stored) ? stored : undefined;
|
|
218
|
+
}
|
|
219
|
+
|
|
170
220
|
function switchToTaskThinking(taskId: number, level: TodoThinkingLevel): void {
|
|
171
221
|
if (!getAvailableTodoThinkingLevels(currentModel).includes(level)) return;
|
|
172
222
|
const current = getCurrentThinkingLevel();
|
|
@@ -175,8 +225,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
175
225
|
if (current !== level) setTodoThinkingLevel(level);
|
|
176
226
|
}
|
|
177
227
|
|
|
178
|
-
function restoreTaskThinking(taskId: number): void {
|
|
179
|
-
const previous =
|
|
228
|
+
function restoreTaskThinking(taskId: number, state: ReturnType<typeof getState>): void {
|
|
229
|
+
const previous = getRememberedThinking(taskId, state);
|
|
180
230
|
if (!previous) return;
|
|
181
231
|
rememberedThinkingByTaskId.delete(taskId);
|
|
182
232
|
if (getCurrentThinkingLevel() !== previous) setTodoThinkingLevel(previous);
|
|
@@ -186,7 +236,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
186
236
|
for (const taskId of [...rememberedThinkingByTaskId.keys()]) {
|
|
187
237
|
const task = state.tasks.find((item) => item.id === taskId);
|
|
188
238
|
if (task?.status === "in_progress") continue;
|
|
189
|
-
restoreTaskThinking(taskId);
|
|
239
|
+
restoreTaskThinking(taskId, state);
|
|
190
240
|
}
|
|
191
241
|
}
|
|
192
242
|
|
|
@@ -197,13 +247,20 @@ export default function (pi: ExtensionAPI) {
|
|
|
197
247
|
setter.call(pi, level);
|
|
198
248
|
}
|
|
199
249
|
|
|
200
|
-
function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
250
|
+
function hasVisibleAssistantContent(content: unknown): boolean {
|
|
251
|
+
if (typeof content === "string") return content.trim().length > 0;
|
|
252
|
+
if (!Array.isArray(content)) return false;
|
|
253
|
+
return content.some((block) => {
|
|
254
|
+
const candidate = block as { type?: unknown; text?: unknown };
|
|
255
|
+
return candidate.type === "text" && typeof candidate.text === "string" && candidate.text.trim().length > 0;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function isCompletedAssistantReply(message: AgentMessageLike | undefined): boolean {
|
|
260
|
+
if (message?.role !== "assistant") return false;
|
|
261
|
+
if (message.stopReason === "aborted" || message.stopReason === "error" || message.stopReason === "length" || message.stopReason === "toolUse") return false;
|
|
262
|
+
return hasVisibleAssistantContent(message.content);
|
|
263
|
+
}
|
|
207
264
|
|
|
208
265
|
function hasCompletedAssistantReply(messages: readonly unknown[] | undefined): boolean {
|
|
209
266
|
if (!Array.isArray(messages)) return false;
|
|
@@ -227,6 +284,7 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
227
284
|
}
|
|
228
285
|
|
|
229
286
|
function applyInternalTodoMutation(action: "update", params: TaskMutationParams, ctx: ExtensionContext): boolean {
|
|
287
|
+
activateTodoStateScope(ctx);
|
|
230
288
|
const result = applyTaskMutation(getState(), action, params);
|
|
231
289
|
if (result.op.kind === "error") {
|
|
232
290
|
console.warn(`rpiv-todo: failed internal ${action} mutation — ${result.op.message}`);
|
|
@@ -235,7 +293,7 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
235
293
|
const autoClear = autoClearCompletedTodos(result.state);
|
|
236
294
|
replaceState(autoClear.state);
|
|
237
295
|
publishTodoState(pi as any, ctx, action, params as Record<string, unknown>);
|
|
238
|
-
if (todoThinkingEnabled) applyTodoThinkingAfterCommit(
|
|
296
|
+
if (todoThinkingEnabled) applyTodoThinkingAfterCommit(result.state, { action, params });
|
|
239
297
|
try {
|
|
240
298
|
const sync = syncPersistedPlan(ctx.cwd, autoClear.state);
|
|
241
299
|
if (sync?.completed) console.log(`rpiv-todo: completed persisted plan and removed ${sync.path}`);
|
|
@@ -246,6 +304,7 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
246
304
|
}
|
|
247
305
|
|
|
248
306
|
function maybeRecoverCompletedCurrentTask(messages: readonly unknown[] | undefined, ctx: ExtensionContext): boolean {
|
|
307
|
+
activateTodoStateScope(ctx);
|
|
249
308
|
if (!hasCompletedAssistantReply(messages)) return false;
|
|
250
309
|
const task = findOptimisticallyCompletableTask(getState().tasks);
|
|
251
310
|
if (!task) return false;
|
|
@@ -264,6 +323,7 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
264
323
|
nudgeTimer = setTimeout(() => {
|
|
265
324
|
nudgeTimer = undefined;
|
|
266
325
|
try {
|
|
326
|
+
activateTodoStateScope(ctx);
|
|
267
327
|
if (!ctx.isIdle()) {
|
|
268
328
|
if (attempt < TODO_NUDGE_MAX_IDLE_ATTEMPTS) scheduleTodoNudge(ctx, attempt + 1);
|
|
269
329
|
return;
|
|
@@ -286,6 +346,11 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
286
346
|
// queueing followUp from inside agent_end can be too late to be drained.
|
|
287
347
|
pi.sendUserMessage(nudge.message);
|
|
288
348
|
} catch (err) {
|
|
349
|
+
if (isAgentBusyRaceError(err)) {
|
|
350
|
+
if (attempt < TODO_NUDGE_MAX_IDLE_ATTEMPTS) scheduleTodoNudge(ctx, attempt + 1);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (isStaleExtensionContextError(err)) return;
|
|
289
354
|
console.warn(`rpiv-todo: failed to auto-nudge unfinished todos — ${(err as Error).message}`);
|
|
290
355
|
}
|
|
291
356
|
}, delayMs);
|
|
@@ -295,6 +360,7 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
295
360
|
registerTodosCommand(pi);
|
|
296
361
|
|
|
297
362
|
pi.on("session_start", async (_event, ctx) => {
|
|
363
|
+
activateTodoStateScope(ctx);
|
|
298
364
|
currentModel = ctx.model;
|
|
299
365
|
registerTodoToolWithCurrentPrompt();
|
|
300
366
|
const persisted = loadPersistedPlan(ctx.cwd);
|
|
@@ -313,12 +379,14 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
313
379
|
});
|
|
314
380
|
|
|
315
381
|
pi.on("session_compact", async (_event, ctx) => {
|
|
382
|
+
activateTodoStateScope(ctx);
|
|
316
383
|
replaceState(autoClearCompletedTodos(loadPersistedPlan(ctx.cwd)?.state ?? replayFromBranch(ctx)).state);
|
|
317
384
|
publishTodoState(pi as any, ctx);
|
|
318
385
|
lastNudgedSignature = undefined;
|
|
319
386
|
});
|
|
320
387
|
|
|
321
388
|
pi.on("session_tree", async (_event, ctx) => {
|
|
389
|
+
activateTodoStateScope(ctx);
|
|
322
390
|
replaceState(autoClearCompletedTodos(loadPersistedPlan(ctx.cwd)?.state ?? replayFromBranch(ctx)).state);
|
|
323
391
|
publishTodoState(pi as any, ctx);
|
|
324
392
|
lastNudgedSignature = undefined;
|
|
@@ -345,12 +413,14 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
345
413
|
if (isAskUserToolName(event.toolName)) pendingAskUserToolCallIds.delete(event.toolCallId);
|
|
346
414
|
});
|
|
347
415
|
|
|
348
|
-
pi.on("agent_start", async () => {
|
|
416
|
+
pi.on("agent_start", async (_event, ctx) => {
|
|
417
|
+
activateTodoStateScope(ctx);
|
|
349
418
|
pendingAskUserToolCallIds.clear();
|
|
350
419
|
inProgressAtAgentStart = new Set(selectVisibleTasks(getState()).filter((task) => task.status === "in_progress").map((task) => task.id));
|
|
351
420
|
});
|
|
352
421
|
|
|
353
422
|
pi.on("message_end", async (event, ctx) => {
|
|
423
|
+
activateTodoStateScope(ctx);
|
|
354
424
|
if (!isCompletedAssistantReply((event as { message?: AgentMessageLike } | undefined)?.message)) return;
|
|
355
425
|
if (maybeRecoverCompletedCurrentTask([(event as { message?: AgentMessageLike }).message], ctx)) {
|
|
356
426
|
lastNudgedSignature = undefined;
|
|
@@ -359,6 +429,7 @@ function isCompletedAssistantReply(message: AgentMessageLike | undefined): boole
|
|
|
359
429
|
});
|
|
360
430
|
|
|
361
431
|
pi.on("agent_end", async (event, ctx) => {
|
|
432
|
+
activateTodoStateScope(ctx);
|
|
362
433
|
const completedAssistantReply = hasCompletedAssistantReply((event as { messages?: readonly unknown[] } | undefined)?.messages);
|
|
363
434
|
|
|
364
435
|
if (suppressNextNudgeForThinkingSwitch) {
|
|
@@ -1,28 +1,57 @@
|
|
|
1
1
|
import type { Task } from "../tool/types.js";
|
|
2
2
|
import { EMPTY_STATE, type TaskState } from "./state.js";
|
|
3
3
|
|
|
4
|
+
const DEFAULT_SCOPE_KEY = "__default__";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
|
-
* Module-level live state
|
|
6
|
-
*
|
|
7
|
-
* single
|
|
7
|
+
* Module-level live state cells, keyed by the active Pi session identity.
|
|
8
|
+
* Pi can keep multiple SDK runtimes/tabs alive in one Node process, so a
|
|
9
|
+
* single module-level todo cell leaks tasks across sessions. Keep the legacy
|
|
10
|
+
* getState()/commitState() API, but make it resolve through the current scope.
|
|
8
11
|
*/
|
|
9
|
-
let
|
|
12
|
+
let activeScopeKey = DEFAULT_SCOPE_KEY;
|
|
13
|
+
const statesByScopeKey = new Map<string, TaskState>([
|
|
14
|
+
[DEFAULT_SCOPE_KEY, { tasks: [...EMPTY_STATE.tasks], nextId: EMPTY_STATE.nextId }],
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
function emptyState(): TaskState {
|
|
18
|
+
return { tasks: [...EMPTY_STATE.tasks], nextId: EMPTY_STATE.nextId };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function normalizedScopeKey(scopeKey: string | undefined): string {
|
|
22
|
+
const trimmed = scopeKey?.trim();
|
|
23
|
+
return trimmed ? trimmed : DEFAULT_SCOPE_KEY;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function activeState(): TaskState {
|
|
27
|
+
let state = statesByScopeKey.get(activeScopeKey);
|
|
28
|
+
if (!state) {
|
|
29
|
+
state = emptyState();
|
|
30
|
+
statesByScopeKey.set(activeScopeKey, state);
|
|
31
|
+
}
|
|
32
|
+
return state;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function activateStateScope(scopeKey: string | undefined): void {
|
|
36
|
+
activeScopeKey = normalizedScopeKey(scopeKey);
|
|
37
|
+
activeState();
|
|
38
|
+
}
|
|
10
39
|
|
|
11
40
|
/**
|
|
12
41
|
* Live tasks accessor. Returned `readonly Task[]` so callers cannot mutate the
|
|
13
42
|
* live cell. Consumers must not cast back.
|
|
14
43
|
*/
|
|
15
44
|
export function getTodos(): readonly Task[] {
|
|
16
|
-
return
|
|
45
|
+
return activeState().tasks;
|
|
17
46
|
}
|
|
18
47
|
|
|
19
48
|
export function getNextId(): number {
|
|
20
|
-
return
|
|
49
|
+
return activeState().nextId;
|
|
21
50
|
}
|
|
22
51
|
|
|
23
52
|
/** Snapshot accessor used by reducer callers to pass canonical state in. */
|
|
24
53
|
export function getState(): TaskState {
|
|
25
|
-
return
|
|
54
|
+
return activeState();
|
|
26
55
|
}
|
|
27
56
|
|
|
28
57
|
/**
|
|
@@ -31,7 +60,7 @@ export function getState(): TaskState {
|
|
|
31
60
|
* `replayFromBranch` decodes the latest snapshot.
|
|
32
61
|
*/
|
|
33
62
|
export function replaceState(next: TaskState): void {
|
|
34
|
-
|
|
63
|
+
statesByScopeKey.set(activeScopeKey, next);
|
|
35
64
|
}
|
|
36
65
|
|
|
37
66
|
/**
|
|
@@ -39,7 +68,7 @@ export function replaceState(next: TaskState): void {
|
|
|
39
68
|
* `state` output to publish the new canonical state to live readers.
|
|
40
69
|
*/
|
|
41
70
|
export function commitState(next: TaskState): void {
|
|
42
|
-
|
|
71
|
+
statesByScopeKey.set(activeScopeKey, next);
|
|
43
72
|
}
|
|
44
73
|
|
|
45
74
|
/**
|
|
@@ -48,5 +77,7 @@ export function commitState(next: TaskState): void {
|
|
|
48
77
|
* Plan §Decisions §Decision 7.
|
|
49
78
|
*/
|
|
50
79
|
export function __resetState(): void {
|
|
51
|
-
|
|
80
|
+
activeScopeKey = DEFAULT_SCOPE_KEY;
|
|
81
|
+
statesByScopeKey.clear();
|
|
82
|
+
statesByScopeKey.set(DEFAULT_SCOPE_KEY, emptyState());
|
|
52
83
|
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
import { resolve } from "node:path";
|
|
16
17
|
import { TODO_TOOL_DESCRIPTION } from "../tool-descriptions.js";
|
|
17
18
|
import {
|
|
18
19
|
disablePersistence,
|
|
@@ -25,7 +26,7 @@ import { AUTO_CLEAR_COMPLETED_MESSAGE, autoClearCompletedTodos } from "./state/a
|
|
|
25
26
|
import { replayFromBranch } from "./state/replay.js";
|
|
26
27
|
import { isTaskBlocked, selectTasksByStatus, selectTodoCounts } from "./state/selectors.js";
|
|
27
28
|
import { applyTaskMutation } from "./state/state-reducer.js";
|
|
28
|
-
import { commitState, getState, replaceState } from "./state/store.js";
|
|
29
|
+
import { activateStateScope, commitState, getState, replaceState } from "./state/store.js";
|
|
29
30
|
import { buildToolResult, formatContent } from "./tool/response-envelope.js";
|
|
30
31
|
import {
|
|
31
32
|
COMMAND_NAME,
|
|
@@ -75,7 +76,16 @@ const PERSIST_ARGUMENT_COMPLETIONS: CommandCompletion[] = [
|
|
|
75
76
|
];
|
|
76
77
|
|
|
77
78
|
interface TodoToolHooks {
|
|
78
|
-
|
|
79
|
+
prepareMutation?: (
|
|
80
|
+
state: ReturnType<typeof getState>,
|
|
81
|
+
ctx: ExtensionContext,
|
|
82
|
+
info: { action: TaskAction; params: TaskMutationParams },
|
|
83
|
+
) => TaskMutationParams | Promise<TaskMutationParams>;
|
|
84
|
+
afterCommit?: (
|
|
85
|
+
state: ReturnType<typeof getState>,
|
|
86
|
+
ctx: ExtensionContext,
|
|
87
|
+
info: { action: TaskAction; params: TaskMutationParams; committedState: ReturnType<typeof getState> },
|
|
88
|
+
) => void | Promise<void>;
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
interface TodoToolRegistrationOptions extends TodoToolHooks {
|
|
@@ -83,7 +93,7 @@ interface TodoToolRegistrationOptions extends TodoToolHooks {
|
|
|
83
93
|
promptGuidelines?: string[];
|
|
84
94
|
}
|
|
85
95
|
|
|
86
|
-
type TodoStateEventContext = { sessionManager?: { getSessionFile?: () => unknown } };
|
|
96
|
+
type TodoStateEventContext = { sessionManager?: { getSessionFile?: () => unknown; getSessionId?: () => unknown } };
|
|
87
97
|
type TodoStateEventEmitter = { events?: { emit?: (channel: string, data: unknown) => void } };
|
|
88
98
|
|
|
89
99
|
interface TodosCommandOptions {
|
|
@@ -183,14 +193,34 @@ function sessionFileFromContext(ctx: unknown): string | undefined {
|
|
|
183
193
|
return typeof sessionFile === "string" && sessionFile.trim() ? sessionFile : undefined;
|
|
184
194
|
}
|
|
185
195
|
|
|
196
|
+
function sessionIdFromContext(ctx: unknown): string | undefined {
|
|
197
|
+
const sessionId = (ctx as TodoStateEventContext | undefined)?.sessionManager?.getSessionId?.();
|
|
198
|
+
return typeof sessionId === "string" && sessionId.trim() ? sessionId : undefined;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function todoStateScopeFromContext(ctx: unknown): string | undefined {
|
|
202
|
+
const sessionFile = sessionFileFromContext(ctx);
|
|
203
|
+
if (sessionFile) return `file:${resolve(sessionFile)}`;
|
|
204
|
+
const sessionId = sessionIdFromContext(ctx);
|
|
205
|
+
if (sessionId) return `id:${sessionId}`;
|
|
206
|
+
const cwd = (ctx as { cwd?: unknown } | undefined)?.cwd;
|
|
207
|
+
return typeof cwd === "string" && cwd.trim() ? `cwd:${resolve(cwd)}` : undefined;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function activateTodoStateScope(ctx: unknown): void {
|
|
211
|
+
activateStateScope(todoStateScopeFromContext(ctx));
|
|
212
|
+
}
|
|
213
|
+
|
|
186
214
|
export function publishTodoState(
|
|
187
215
|
pi: TodoStateEventEmitter,
|
|
188
216
|
ctx: unknown,
|
|
189
217
|
action: TaskAction = "list",
|
|
190
218
|
params: Record<string, unknown> = {},
|
|
191
219
|
): void {
|
|
220
|
+
activateTodoStateScope(ctx);
|
|
192
221
|
const state = getState();
|
|
193
222
|
const sessionFile = sessionFileFromContext(ctx);
|
|
223
|
+
const sessionId = sessionIdFromContext(ctx);
|
|
194
224
|
pi.events?.emit?.(TODO_STATE_EVENT, {
|
|
195
225
|
version: 1,
|
|
196
226
|
details: {
|
|
@@ -200,6 +230,7 @@ export function publishTodoState(
|
|
|
200
230
|
nextId: state.nextId,
|
|
201
231
|
},
|
|
202
232
|
...(sessionFile ? { sessionFile } : {}),
|
|
233
|
+
...(sessionId ? { sessionId } : {}),
|
|
203
234
|
checkedAt: Date.now(),
|
|
204
235
|
});
|
|
205
236
|
}
|
|
@@ -363,15 +394,24 @@ export function registerTodoTool(pi: ExtensionAPI, hooks: TodoToolRegistrationOp
|
|
|
363
394
|
parameters: TodoParamsSchema,
|
|
364
395
|
|
|
365
396
|
async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
|
|
366
|
-
|
|
397
|
+
activateTodoStateScope(_ctx);
|
|
398
|
+
const preparedParams = await hooks.prepareMutation?.(getState(), _ctx as ExtensionContext, {
|
|
399
|
+
action: params.action,
|
|
400
|
+
params: params as TaskMutationParams,
|
|
401
|
+
}) ?? params as TaskMutationParams;
|
|
402
|
+
const result = applyTaskMutation(getState(), params.action, preparedParams);
|
|
367
403
|
if (result.op.kind === "error") {
|
|
368
404
|
throw new Error(result.op.message);
|
|
369
405
|
}
|
|
370
406
|
const autoClear = autoClearCompletedTodos(result.state);
|
|
371
407
|
commitState(autoClear.state);
|
|
372
408
|
publishTodoState(pi as TodoStateEventEmitter, _ctx, params.action, params as Record<string, unknown>);
|
|
373
|
-
await hooks.afterCommit?.(
|
|
374
|
-
|
|
409
|
+
await hooks.afterCommit?.(result.state, _ctx as ExtensionContext, {
|
|
410
|
+
action: params.action,
|
|
411
|
+
params: preparedParams,
|
|
412
|
+
committedState: autoClear.state,
|
|
413
|
+
});
|
|
414
|
+
const toolResult = buildToolResult(params.action, preparedParams, autoClear.state, result.op);
|
|
375
415
|
if (!autoClear.cleared) return toolResult;
|
|
376
416
|
return {
|
|
377
417
|
...toolResult,
|
|
@@ -391,6 +431,7 @@ export function registerTodosCommand(pi: ExtensionAPI): void {
|
|
|
391
431
|
description: "Show todos on the current branch. Flags: --active, --ready, --blocked, --tree, --status <status>, --export [json|markdown]. Commands: persist on|off|clear|status, scope <id...>",
|
|
392
432
|
getArgumentCompletions: (prefix) => completeCommandArguments(String(prefix ?? ""), TODOS_ARGUMENT_COMPLETIONS),
|
|
393
433
|
handler: async (args, ctx) => {
|
|
434
|
+
activateTodoStateScope(ctx);
|
|
394
435
|
if (handlePersistCommand(args, ctx)) return;
|
|
395
436
|
if (handleScopeCommand(args, ctx, () => publishTodoState(pi as TodoStateEventEmitter, ctx))) return;
|
|
396
437
|
if (!ctx.hasUI) {
|
|
@@ -459,6 +500,7 @@ export function registerTodosCommand(pi: ExtensionAPI): void {
|
|
|
459
500
|
description: "Enable, disable, clear, or inspect project todo persistence. Args: on|off|clear|status.",
|
|
460
501
|
getArgumentCompletions: (prefix) => completeCommandArguments(String(prefix ?? ""), PERSIST_ARGUMENT_COMPLETIONS),
|
|
461
502
|
handler: async (args, ctx) => {
|
|
503
|
+
activateTodoStateScope(ctx);
|
|
462
504
|
handlePersistCommand(`persist ${getCommandText(args)}`, ctx);
|
|
463
505
|
},
|
|
464
506
|
});
|
|
@@ -466,6 +508,7 @@ export function registerTodosCommand(pi: ExtensionAPI): void {
|
|
|
466
508
|
pi.registerCommand(SCOPE_COMMAND_NAME, {
|
|
467
509
|
description: "Select todo ids to continue from a persisted plan; pending/in_progress items outside the scope become deferred.",
|
|
468
510
|
handler: async (args, ctx) => {
|
|
511
|
+
activateTodoStateScope(ctx);
|
|
469
512
|
handleScopeCommand(`scope ${getCommandText(args)}`, ctx, () => publishTodoState(pi as TodoStateEventEmitter, ctx));
|
|
470
513
|
},
|
|
471
514
|
});
|
|
@@ -27,10 +27,10 @@ export const COMPRESS_TOOL_DESCRIPTION: ToolDescription = {
|
|
|
27
27
|
name: "compress",
|
|
28
28
|
label: "Compress Context",
|
|
29
29
|
description: COMPRESS_RANGE_DESCRIPTION,
|
|
30
|
-
promptSnippet: "Compress closed conversation slices as steady context housekeeping;
|
|
30
|
+
promptSnippet: "Compress closed conversation slices as steady context housekeeping; before any new search/read/test/web lookup, compress older completed work unless exact raw text is still needed.",
|
|
31
31
|
promptGuidelines: [
|
|
32
|
-
"Treat completed implementation
|
|
33
|
-
"Do not carry large stale
|
|
32
|
+
"Treat completed implementation, verification, config/doc edits, answered exploration, dead ends, and log inspection as compression candidates immediately.",
|
|
33
|
+
"Do not carry large stale shell/read/repo/web outputs, diffs, or passing logs across task boundaries; summarize their actionable result instead.",
|
|
34
34
|
"Keep active, still-needed context raw; compress only closed ranges whose exact content is unlikely to be needed next.",
|
|
35
35
|
],
|
|
36
36
|
};
|
|
@@ -329,7 +329,7 @@ export const CODEX_ALIAS_TOOL_DESCRIPTIONS = {
|
|
|
329
329
|
shellCommand: {
|
|
330
330
|
name: "shell",
|
|
331
331
|
label: "shell",
|
|
332
|
-
description: "Run shell commands for builds, tests, package managers, git, and project CLIs.
|
|
332
|
+
description: "Run shell commands for builds, tests, package managers, git, and project CLIs. For long/verification output, redirect to a log and show only bounded tail on failure; summarize passing logs. Set workdir/cwd instead of cd; prefer read for simple file reads.",
|
|
333
333
|
},
|
|
334
334
|
applyPatch: {
|
|
335
335
|
name: "apply_patch",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ui-extend",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -43,12 +43,14 @@
|
|
|
43
43
|
"watch:pix": "npm run link:pix --silent && mise exec node@24.16.0 -- tsc -p tsconfig.json --watch --preserveWatchOutput --noEmitOnError",
|
|
44
44
|
"check": "mise exec node@24.16.0 -- npm run check:inner",
|
|
45
45
|
"precheck:inner": "npm run generate-schemas --silent",
|
|
46
|
-
"check:inner": "tsc --noEmit && npm run test:inner",
|
|
46
|
+
"check:inner": "npm run sync:sdk-pin:check --silent && tsc --noEmit && npm run test:inner",
|
|
47
47
|
"test": "mise exec node@24.16.0 -- npm run test:inner",
|
|
48
48
|
"test:inner": "node --import tsx --test \"tests/**/*.test.ts\"",
|
|
49
49
|
"test:tools-suite": "npm --prefix external/pi-tools-suite test",
|
|
50
50
|
"sync:pi-tools-suite": "node scripts/sync-pi-tools-suite.mjs",
|
|
51
51
|
"sync:pi-tools-suite:check": "node scripts/sync-pi-tools-suite.mjs --check",
|
|
52
|
+
"sync:sdk-pin": "node scripts/sync-sdk-pin.mjs",
|
|
53
|
+
"sync:sdk-pin:check": "node scripts/sync-sdk-pin.mjs --check",
|
|
52
54
|
"test:coverage": "mise exec node@24.16.0 -- node --import tsx --test --experimental-test-coverage --test-coverage-include=src/**/*.ts --test-coverage-exclude=src/main.ts --test-coverage-lines=95 --test-coverage-branches=80 --test-coverage-functions=95 \"tests/**/*.test.ts\"",
|
|
53
55
|
"update-sdk-references": "mise exec node@24.16.0 -- node .pi/skills/pi-sdk/scripts/update-references.mjs",
|
|
54
56
|
"prepack": "npm run generate-schemas --silent",
|
|
@@ -62,9 +64,9 @@
|
|
|
62
64
|
"prepublishOnly": "npm run check && npm run build:pix && npm run generate-schemas"
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
|
-
"@earendil-works/pi-ai": "0.79.
|
|
66
|
-
"@earendil-works/pi-coding-agent": "0.79.
|
|
67
|
-
"@earendil-works/pi-tui": "0.79.
|
|
67
|
+
"@earendil-works/pi-ai": "0.79.4",
|
|
68
|
+
"@earendil-works/pi-coding-agent": "0.79.4",
|
|
69
|
+
"@earendil-works/pi-tui": "0.79.4",
|
|
68
70
|
"@mariozechner/clipboard": "^0.3.9",
|
|
69
71
|
"jsonc-parser": "3.3.1",
|
|
70
72
|
"typebox": "1.1.38",
|