@firstpick/pi-package-webui 0.8.3 → 0.8.5
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 +67 -16
- package/bin/pi-webui.mjs +777 -131
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +26 -0
- package/lib/optional-feature-catalog.mjs +29 -0
- package/lib/optional-feature-migration.mjs +410 -0
- package/lib/session-summary-core.mjs +320 -0
- package/lib/session-summary-preferences.mjs +267 -0
- package/package.json +5 -42
- package/public/app.js +1325 -51
- package/public/index.html +43 -1
- package/public/service-worker.js +1 -1
- package/public/styles.css +345 -1
- package/session-summary.ts +403 -0
- package/tests/aur-review-widget-static.test.mjs +3 -2
- package/tests/boot-failure-diagnostics.test.mjs +2 -2
- package/tests/browser/session-summary.spec.mjs +271 -0
- package/tests/codex-fast-mode-static.test.mjs +10 -9
- package/tests/composer-action-grid-reorder-static.test.mjs +2 -2
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +1 -1
- package/tests/http-endpoints-harness.test.mjs +429 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +2 -2
- package/tests/mobile-foundation-static.test.mjs +2 -2
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +91 -92
- package/tests/native-parity-harness.test.mjs +9 -1
- package/tests/native-parity.test.mjs +23 -1
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +75 -0
- package/tests/optional-feature-migration.test.mjs +142 -0
- package/tests/persistent-ui-layout-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +2 -2
- package/tests/session-summary-core.test.mjs +491 -0
- package/tests/session-summary-preferences.test.mjs +103 -0
- package/tests/side-panel-section-reorder-static.test.mjs +2 -2
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { completeSimple } from "@earendil-works/pi-ai/compat";
|
|
3
|
+
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { Markdown } from "@earendil-works/pi-tui";
|
|
6
|
+
import {
|
|
7
|
+
SESSION_SUMMARY_DISPLAY_TYPE,
|
|
8
|
+
SESSION_SUMMARY_MAX_OUTPUT_TOKENS,
|
|
9
|
+
SESSION_SUMMARY_NAME_PROVENANCE_TYPE,
|
|
10
|
+
SESSION_SUMMARY_PROMPT_REVISION,
|
|
11
|
+
SESSION_SUMMARY_RPC_TYPE,
|
|
12
|
+
SESSION_SUMMARY_STATE_TYPE,
|
|
13
|
+
SESSION_SUMMARY_SYSTEM_PROMPT,
|
|
14
|
+
SESSION_SUMMARY_TIMEOUT_MS,
|
|
15
|
+
boundedRpcPayload,
|
|
16
|
+
buildSummaryUserPrompt,
|
|
17
|
+
captureSummarySource,
|
|
18
|
+
createSummaryScheduler,
|
|
19
|
+
filterAndInjectSummaryContext,
|
|
20
|
+
isSummarySourceCurrent,
|
|
21
|
+
latestSummaryNameProvenance,
|
|
22
|
+
latestSummaryState,
|
|
23
|
+
parseSummaryOutput,
|
|
24
|
+
shouldApplySummaryTitle,
|
|
25
|
+
} from "./lib/session-summary-core.mjs";
|
|
26
|
+
import {
|
|
27
|
+
readSessionSummaryPreferences,
|
|
28
|
+
sessionSummaryPreferencesSummary,
|
|
29
|
+
supportedSessionSummaryThinkingLevels,
|
|
30
|
+
writeSessionSummaryPreferences,
|
|
31
|
+
} from "./lib/session-summary-preferences.mjs";
|
|
32
|
+
|
|
33
|
+
type SummaryContext = ExtensionContext | ExtensionCommandContext;
|
|
34
|
+
type CompleteFunction = typeof completeSimple;
|
|
35
|
+
type GenerationInput = { ctx: SummaryContext; manual: boolean };
|
|
36
|
+
|
|
37
|
+
function modelKey(model: any): string {
|
|
38
|
+
return `${model?.provider || ""}/${model?.id || model?.modelId || ""}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function errorMessage(error: unknown): string {
|
|
42
|
+
return (error instanceof Error ? error.message : String(error)).replace(/[\r\n]+/g, " ").slice(0, 512);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isAbort(error: unknown): boolean {
|
|
46
|
+
return error instanceof Error && (error.name === "AbortError" || error.message.toLowerCase().includes("abort"));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function sendRpc(pi: ExtensionAPI, ctx: SummaryContext, kind: string, payload: Record<string, unknown> = {}): void {
|
|
50
|
+
pi.sendMessage({
|
|
51
|
+
customType: SESSION_SUMMARY_RPC_TYPE,
|
|
52
|
+
content: "",
|
|
53
|
+
display: false,
|
|
54
|
+
details: boundedRpcPayload(kind, {
|
|
55
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
56
|
+
durable: !!ctx.sessionManager.getSessionFile(),
|
|
57
|
+
...payload,
|
|
58
|
+
}),
|
|
59
|
+
}, { triggerTurn: false });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function displaySummary(pi: ExtensionAPI, state: any): void {
|
|
63
|
+
if (!state?.result?.summaryMarkdown) return;
|
|
64
|
+
pi.appendEntry(SESSION_SUMMARY_DISPLAY_TYPE, {
|
|
65
|
+
version: 1,
|
|
66
|
+
title: state.result.title || "Session summary",
|
|
67
|
+
summaryMarkdown: state.result.summaryMarkdown,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function availableModels(ctx: ExtensionCommandContext): any[] {
|
|
72
|
+
return ctx.modelRegistry.getAvailable()
|
|
73
|
+
.filter((model: any) => model?.provider && model?.id)
|
|
74
|
+
.sort((left: any, right: any) => modelKey(left).localeCompare(modelKey(right)));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function selectValue(
|
|
78
|
+
ctx: ExtensionCommandContext,
|
|
79
|
+
title: string,
|
|
80
|
+
options: Array<{ value: string; label: string }>,
|
|
81
|
+
current?: string,
|
|
82
|
+
): Promise<string | undefined> {
|
|
83
|
+
const labels = options.map((option) => option.value === current ? `${option.label} (current)` : option.label);
|
|
84
|
+
const selected = await ctx.ui.select(title, labels);
|
|
85
|
+
if (!selected) return undefined;
|
|
86
|
+
const index = labels.indexOf(selected);
|
|
87
|
+
return index < 0 ? undefined : options[index].value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function runSetup(pi: ExtensionAPI, ctx: ExtensionCommandContext): Promise<boolean> {
|
|
91
|
+
if (!ctx.hasUI) {
|
|
92
|
+
ctx.ui.notify("Session summary setup requires TUI or RPC dialog support.", "warning");
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const current = await readSessionSummaryPreferences();
|
|
97
|
+
const models = availableModels(ctx);
|
|
98
|
+
if (!models.length) {
|
|
99
|
+
ctx.ui.notify("No authenticated Pi models are available. Run /login or configure a provider first.", "warning");
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const preferred = modelKey(current.model);
|
|
103
|
+
const defaultKey = "openai-codex/gpt-5.6-luna";
|
|
104
|
+
const availableKeys = new Set(models.map(modelKey));
|
|
105
|
+
const selectedModelKey = await selectValue(
|
|
106
|
+
ctx,
|
|
107
|
+
`Session summary model\n\n${sessionSummaryPreferencesSummary(current)}`,
|
|
108
|
+
models.map((model: any) => ({ value: modelKey(model), label: `${modelKey(model)}${model.name && model.name !== model.id ? ` — ${model.name}` : ""}` })),
|
|
109
|
+
availableKeys.has(preferred) ? preferred : (availableKeys.has(defaultKey) ? defaultKey : undefined),
|
|
110
|
+
);
|
|
111
|
+
if (!selectedModelKey) return false;
|
|
112
|
+
const selectedModel = models.find((model: any) => modelKey(model) === selectedModelKey);
|
|
113
|
+
if (!selectedModel) return false;
|
|
114
|
+
|
|
115
|
+
const levels = supportedSessionSummaryThinkingLevels(selectedModel);
|
|
116
|
+
const selectedThinking = await selectValue(
|
|
117
|
+
ctx,
|
|
118
|
+
"Session summary reasoning effort",
|
|
119
|
+
levels.map((value: string) => ({ value, label: value })),
|
|
120
|
+
levels.includes(current.model.thinkingLevel) ? current.model.thinkingLevel : (levels.includes("low") ? "low" : levels[0]),
|
|
121
|
+
);
|
|
122
|
+
if (!selectedThinking) return false;
|
|
123
|
+
const enabled = await selectValue(ctx, "Generate automatically after settled turns?", [
|
|
124
|
+
{ value: "yes", label: "Yes" },
|
|
125
|
+
{ value: "no", label: "No (manual /summary only)" },
|
|
126
|
+
], current.enabled ? "yes" : "no");
|
|
127
|
+
if (!enabled) return false;
|
|
128
|
+
const titleEnabled = await selectValue(ctx, "Allow generated session titles?", [
|
|
129
|
+
{ value: "yes", label: "Yes" },
|
|
130
|
+
{ value: "no", label: "No" },
|
|
131
|
+
], current.title.enabled ? "yes" : "no");
|
|
132
|
+
if (!titleEnabled) return false;
|
|
133
|
+
const minSettledTurns = await selectValue(ctx, "Minimum settled user turns between changed titles", [1, 2, 3, 5, 10, 20].map((value) => ({ value: String(value), label: String(value) })), String(current.title.minSettledTurns));
|
|
134
|
+
if (!minSettledTurns) return false;
|
|
135
|
+
const injectLatest = await selectValue(ctx, "Inject the latest summary into main-agent context?", [
|
|
136
|
+
{ value: "no", label: "No (privacy-first default)" },
|
|
137
|
+
{ value: "yes", label: "Yes, latest active-branch summary only" },
|
|
138
|
+
], current.context.injectLatest ? "yes" : "no");
|
|
139
|
+
if (!injectLatest) return false;
|
|
140
|
+
const titlePrompt = await ctx.ui.editor("Editable title prompt (maximum 8 KiB)", current.prompts.title);
|
|
141
|
+
if (titlePrompt === undefined) return false;
|
|
142
|
+
const summaryPrompt = await ctx.ui.editor("Editable Markdown summary prompt (maximum 8 KiB)", current.prompts.summary);
|
|
143
|
+
if (summaryPrompt === undefined) return false;
|
|
144
|
+
|
|
145
|
+
const next = {
|
|
146
|
+
configured: true,
|
|
147
|
+
enabled: enabled === "yes",
|
|
148
|
+
model: { provider: selectedModel.provider, modelId: selectedModel.id, thinkingLevel: selectedThinking },
|
|
149
|
+
prompts: { title: titlePrompt, summary: summaryPrompt },
|
|
150
|
+
input: { scope: "text-and-tool-names" },
|
|
151
|
+
context: { injectLatest: injectLatest === "yes" },
|
|
152
|
+
title: { enabled: titleEnabled === "yes", minSettledTurns: Number(minSettledTurns) },
|
|
153
|
+
};
|
|
154
|
+
const disclosure = [
|
|
155
|
+
sessionSummaryPreferencesSummary(next),
|
|
156
|
+
"",
|
|
157
|
+
"Privacy/cost: each automatic settled refresh sends active-branch user text, final assistant text, and tool names to the selected model in one request. Thinking, images, tool arguments/results, credentials, and prior summary messages are excluded. There is no fallback or automatic provider retry.",
|
|
158
|
+
].join("\n");
|
|
159
|
+
if (!await ctx.ui.confirm("Save session summary setup?", disclosure)) return false;
|
|
160
|
+
const saved = await writeSessionSummaryPreferences(next);
|
|
161
|
+
sendRpc(pi, ctx, "setup", { configured: saved.configured, enabled: saved.enabled });
|
|
162
|
+
ctx.ui.notify(`Session summary setup saved.\n\n${sessionSummaryPreferencesSummary(saved)}`, "info");
|
|
163
|
+
return true;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
ctx.ui.notify(`Session summary setup failed: ${errorMessage(error)}`, "error");
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function createSessionSummaryExtension({ completeFn = completeSimple }: { completeFn?: CompleteFunction } = {}) {
|
|
171
|
+
return function registerSessionSummary(pi: ExtensionAPI): void {
|
|
172
|
+
let selfGeneratedName: { sessionId: string; name: string } | undefined;
|
|
173
|
+
|
|
174
|
+
const publishCurrentState = async (ctx: SummaryContext): Promise<void> => {
|
|
175
|
+
const state = latestSummaryState(ctx.sessionManager.getBranch());
|
|
176
|
+
const preferences = await readSessionSummaryPreferences();
|
|
177
|
+
sendRpc(pi, ctx, "state", {
|
|
178
|
+
configured: preferences.configured,
|
|
179
|
+
enabled: preferences.enabled,
|
|
180
|
+
title: state?.result?.title,
|
|
181
|
+
summaryMarkdown: state?.result?.summaryMarkdown,
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const scheduler = createSummaryScheduler({
|
|
186
|
+
run: async ({ ctx, manual }: GenerationInput, outerSignal: AbortSignal) => {
|
|
187
|
+
try {
|
|
188
|
+
const preferences = await readSessionSummaryPreferences();
|
|
189
|
+
if (!preferences.configured || (!manual && !preferences.enabled)) return { skipped: true };
|
|
190
|
+
|
|
191
|
+
sendRpc(pi, ctx, "generating", { configured: true, enabled: preferences.enabled });
|
|
192
|
+
const captured = captureSummarySource(ctx.sessionManager);
|
|
193
|
+
if (!captured.serialized.text.trim()) throw new Error("No conversation text found");
|
|
194
|
+
const previousState = latestSummaryState(captured.entries);
|
|
195
|
+
const model = ctx.modelRegistry.find(preferences.model.provider, preferences.model.modelId);
|
|
196
|
+
if (!model) throw new Error(`Configured summary model is unavailable: ${preferences.model.provider}/${preferences.model.modelId}`);
|
|
197
|
+
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
198
|
+
if (!auth?.ok) throw new Error(auth?.error || `Authentication failed for ${preferences.model.provider}`);
|
|
199
|
+
|
|
200
|
+
const timeoutSignal = AbortSignal.timeout(SESSION_SUMMARY_TIMEOUT_MS);
|
|
201
|
+
const signal = AbortSignal.any([outerSignal, timeoutSignal]);
|
|
202
|
+
const response = await completeFn(model, {
|
|
203
|
+
systemPrompt: SESSION_SUMMARY_SYSTEM_PROMPT,
|
|
204
|
+
messages: [{
|
|
205
|
+
role: "user",
|
|
206
|
+
content: [{ type: "text", text: buildSummaryUserPrompt({
|
|
207
|
+
transcript: captured.serialized.text,
|
|
208
|
+
titlePrompt: preferences.prompts.title,
|
|
209
|
+
summaryPrompt: preferences.prompts.summary,
|
|
210
|
+
previousState,
|
|
211
|
+
}) }],
|
|
212
|
+
timestamp: Date.now(),
|
|
213
|
+
}],
|
|
214
|
+
}, {
|
|
215
|
+
apiKey: auth.apiKey,
|
|
216
|
+
headers: auth.headers,
|
|
217
|
+
env: auth.env,
|
|
218
|
+
reasoning: preferences.model.thinkingLevel,
|
|
219
|
+
cacheRetention: "none",
|
|
220
|
+
sessionId: randomUUID(),
|
|
221
|
+
signal,
|
|
222
|
+
timeoutMs: SESSION_SUMMARY_TIMEOUT_MS,
|
|
223
|
+
maxRetries: 0,
|
|
224
|
+
maxTokens: SESSION_SUMMARY_MAX_OUTPUT_TOKENS,
|
|
225
|
+
});
|
|
226
|
+
if (response.stopReason === "error" || response.stopReason === "aborted") throw new Error(`Summary model stopped with ${response.stopReason}`);
|
|
227
|
+
const output = parseSummaryOutput(response.content
|
|
228
|
+
.filter((part: any) => part?.type === "text" && typeof part.text === "string")
|
|
229
|
+
.map((part: any) => part.text)
|
|
230
|
+
.join("\n"));
|
|
231
|
+
if (!isSummarySourceCurrent(ctx.sessionManager, captured)) {
|
|
232
|
+
const currentState = latestSummaryState(ctx.sessionManager.getBranch());
|
|
233
|
+
sendRpc(pi, ctx, "state", {
|
|
234
|
+
configured: preferences.configured,
|
|
235
|
+
enabled: preferences.enabled,
|
|
236
|
+
title: currentState?.result?.title,
|
|
237
|
+
summaryMarkdown: currentState?.result?.summaryMarkdown,
|
|
238
|
+
});
|
|
239
|
+
return { stale: true };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const currentName = pi.getSessionName();
|
|
243
|
+
const applyTitle = shouldApplySummaryTitle({
|
|
244
|
+
candidate: output.title,
|
|
245
|
+
currentSessionName: currentName,
|
|
246
|
+
previousState,
|
|
247
|
+
explicitName: latestSummaryNameProvenance(captured.entries)?.explicit,
|
|
248
|
+
settledTurnOrdinal: captured.serialized.userTurns,
|
|
249
|
+
enabled: preferences.title.enabled,
|
|
250
|
+
minSettledTurns: preferences.title.minSettledTurns,
|
|
251
|
+
});
|
|
252
|
+
const previouslyAppliedTitle = previousState?.titleAppliedAtOrdinal !== undefined ? previousState.result.title : undefined;
|
|
253
|
+
const durableTitle = applyTitle ? output.title : (previouslyAppliedTitle || output.title);
|
|
254
|
+
const titleAppliedAtOrdinal = applyTitle
|
|
255
|
+
? captured.serialized.userTurns
|
|
256
|
+
: previousState?.titleAppliedAtOrdinal;
|
|
257
|
+
const state = {
|
|
258
|
+
version: 1,
|
|
259
|
+
source: {
|
|
260
|
+
sessionId: captured.source.sessionId,
|
|
261
|
+
leafId: captured.source.leafId,
|
|
262
|
+
fingerprint: captured.source.fingerprint,
|
|
263
|
+
entryCount: captured.source.entryCount,
|
|
264
|
+
},
|
|
265
|
+
result: { ...(durableTitle ? { title: durableTitle } : {}), summaryMarkdown: output.summaryMarkdown },
|
|
266
|
+
generation: {
|
|
267
|
+
provider: preferences.model.provider,
|
|
268
|
+
modelId: preferences.model.modelId,
|
|
269
|
+
thinkingLevel: preferences.model.thinkingLevel,
|
|
270
|
+
promptRevision: SESSION_SUMMARY_PROMPT_REVISION,
|
|
271
|
+
},
|
|
272
|
+
generatedAt: new Date().toISOString(),
|
|
273
|
+
settledTurnOrdinal: captured.serialized.userTurns,
|
|
274
|
+
...(titleAppliedAtOrdinal === undefined ? {} : { titleAppliedAtOrdinal }),
|
|
275
|
+
};
|
|
276
|
+
pi.appendEntry(SESSION_SUMMARY_STATE_TYPE, state);
|
|
277
|
+
if (applyTitle && output.title) {
|
|
278
|
+
selfGeneratedName = { sessionId: captured.source.sessionId, name: output.title };
|
|
279
|
+
try {
|
|
280
|
+
pi.setSessionName(output.title);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
selfGeneratedName = undefined;
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
sendRpc(pi, ctx, "title", { title: output.title });
|
|
286
|
+
}
|
|
287
|
+
sendRpc(pi, ctx, "success", { title: state.result.title, summaryMarkdown: state.result.summaryMarkdown });
|
|
288
|
+
if (!ctx.sessionManager.getSessionFile() && manual) ctx.ui.notify("Summary created in memory; this session has no durable session file.", "warning");
|
|
289
|
+
return { state, appliedTitle: applyTitle };
|
|
290
|
+
} catch (error) {
|
|
291
|
+
if (!isAbort(error)) sendRpc(pi, ctx, "failure", { message: errorMessage(error) });
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
pi.registerEntryRenderer<{ summaryMarkdown?: string }>(SESSION_SUMMARY_DISPLAY_TYPE, (entry) => {
|
|
298
|
+
const markdown = typeof entry.data?.summaryMarkdown === "string" ? entry.data.summaryMarkdown : "";
|
|
299
|
+
return new Markdown(markdown, 1, 1, getMarkdownTheme());
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
pi.on("agent_settled", (_event, ctx) => {
|
|
303
|
+
void readSessionSummaryPreferences().then((preferences) => {
|
|
304
|
+
if (!preferences.configured || !preferences.enabled) return;
|
|
305
|
+
void scheduler.schedule({ ctx, manual: false });
|
|
306
|
+
}).catch((error) => {
|
|
307
|
+
sendRpc(pi, ctx, "failure", { message: errorMessage(error) });
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
pi.on("context", async (event, ctx) => {
|
|
312
|
+
const state = latestSummaryState(ctx.sessionManager.getBranch());
|
|
313
|
+
try {
|
|
314
|
+
const preferences = await readSessionSummaryPreferences();
|
|
315
|
+
return { messages: filterAndInjectSummaryContext(event.messages, { injectLatest: preferences.configured && preferences.context.injectLatest, state }) };
|
|
316
|
+
} catch {
|
|
317
|
+
return { messages: filterAndInjectSummaryContext(event.messages) };
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
pi.on("session_info_changed", (event, ctx) => {
|
|
322
|
+
if (selfGeneratedName?.sessionId === ctx.sessionManager.getSessionId() && selfGeneratedName.name === event.name) {
|
|
323
|
+
selfGeneratedName = undefined;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
selfGeneratedName = undefined;
|
|
327
|
+
pi.appendEntry(SESSION_SUMMARY_NAME_PROVENANCE_TYPE, {
|
|
328
|
+
version: 1,
|
|
329
|
+
explicit: event.name !== undefined,
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
334
|
+
selfGeneratedName = undefined;
|
|
335
|
+
try {
|
|
336
|
+
await publishCurrentState(ctx);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
sendRpc(pi, ctx, "failure", { message: errorMessage(error) });
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
pi.on("session_tree", async (_event, ctx) => {
|
|
343
|
+
try {
|
|
344
|
+
await publishCurrentState(ctx);
|
|
345
|
+
} catch (error) {
|
|
346
|
+
sendRpc(pi, ctx, "failure", { message: errorMessage(error) });
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
pi.on("session_shutdown", () => {
|
|
351
|
+
selfGeneratedName = undefined;
|
|
352
|
+
scheduler.abort();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const generateManual = async (ctx: ExtensionCommandContext): Promise<any> => {
|
|
356
|
+
const result = await scheduler.schedule({ ctx, manual: true }, { manual: true });
|
|
357
|
+
if (result.status === "failure") {
|
|
358
|
+
const message = errorMessage(result.error);
|
|
359
|
+
ctx.ui.notify(`Session summary failed: ${message}`, "error");
|
|
360
|
+
} else if (result.status === "aborted") {
|
|
361
|
+
ctx.ui.notify("Session summary generation was cancelled.", "warning");
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
pi.registerCommand("summary", {
|
|
367
|
+
description: "Show the latest session summary or generate one; use /summary refresh to force an update",
|
|
368
|
+
handler: async (args, ctx) => {
|
|
369
|
+
const preferences = await readSessionSummaryPreferences().catch((error) => {
|
|
370
|
+
ctx.ui.notify(`Session summary settings failed: ${errorMessage(error)}`, "error");
|
|
371
|
+
return undefined;
|
|
372
|
+
});
|
|
373
|
+
if (!preferences) return;
|
|
374
|
+
if (!preferences.configured) {
|
|
375
|
+
if (!await runSetup(pi, ctx)) return;
|
|
376
|
+
await generateManual(ctx);
|
|
377
|
+
} else {
|
|
378
|
+
const state = latestSummaryState(ctx.sessionManager.getBranch());
|
|
379
|
+
const refresh = args.trim().toLowerCase() === "refresh";
|
|
380
|
+
if (args.trim() && !refresh) {
|
|
381
|
+
ctx.ui.notify("Usage: /summary [refresh]", "warning");
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (!state || refresh) await generateManual(ctx);
|
|
385
|
+
}
|
|
386
|
+
const latest = latestSummaryState(ctx.sessionManager.getBranch());
|
|
387
|
+
if (latest) displaySummary(pi, latest);
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
pi.registerCommand("summary-setup", {
|
|
392
|
+
description: "Configure persistent session titles and Markdown summaries",
|
|
393
|
+
handler: async (_args, ctx) => {
|
|
394
|
+
if (!await runSetup(pi, ctx)) return;
|
|
395
|
+
await generateManual(ctx);
|
|
396
|
+
const latest = latestSummaryState(ctx.sessionManager.getBranch());
|
|
397
|
+
if (latest) displaySummary(pi, latest);
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export default createSessionSummaryExtension();
|
|
@@ -4,12 +4,13 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
-
const [app, css, pkg, server, payloadParser] = await Promise.all([
|
|
7
|
+
const [app, css, pkg, server, payloadParser, optionalFeatureCatalog] = await Promise.all([
|
|
8
8
|
readFile(join(root, "public", "app.js"), "utf8"),
|
|
9
9
|
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
10
10
|
readFile(join(root, "package.json"), "utf8"),
|
|
11
11
|
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
12
12
|
readFile(join(root, "public", "aur-review-payload.mjs"), "utf8"),
|
|
13
|
+
readFile(join(root, "lib", "optional-feature-catalog.mjs"), "utf8"),
|
|
13
14
|
]);
|
|
14
15
|
|
|
15
16
|
assert.match(app, /const AUR_REVIEW_RPC_WIDGET_KEY = "aur-review:rpc"[\s\S]*AUR_REVIEW_RPC_PAYLOAD_PREFIX = "AUR_REVIEW_RPC_PAYLOAD "[\s\S]*AUR_REVIEW_RPC_PAYLOAD_TYPE = "firstpick\.pi-extension-aur-review\.review"[\s\S]*AUR_REVIEW_RPC_PAYLOAD_VERSION = 3/, "WebUI should identify the versioned AUR review payload");
|
|
@@ -30,7 +31,7 @@ assert.match(app, /if \(key === AUR_REVIEW_RPC_WIDGET_KEY\) return "aurReview"[\
|
|
|
30
31
|
assert.match(css, /\.aur-review-widget \{[\s\S]*\.aur-review-actions[\s\S]*\.aur-review-file-list[\s\S]*@media \(max-width: 720px\)[\s\S]*\.aur-review-action,[\s\S]*\.aur-review-report/, "AUR review card should be styled responsively for desktop and mobile");
|
|
31
32
|
assert.equal(JSON.parse(pkg).optionalDependencies?.["@firstpick/pi-extension-aur-review"], undefined, "WebUI must not reference the unpublished review extension from clean npm installs");
|
|
32
33
|
assert.equal(JSON.parse(pkg).pi?.extensions?.some((entry) => String(entry).includes("pi-extension-aur-review")), false, "WebUI must not bundle an unpublished nested review extension path");
|
|
33
|
-
assert.match(
|
|
34
|
+
assert.match(optionalFeatureCatalog, /\["aurReview", "@firstpick\/pi-extension-aur-review", "\^0\.1\.1"\]/, "optional-feature catalog should retain the future/local review companion mapping without bundling it");
|
|
34
35
|
assert.match(server, /"aur-review-payload\.mjs", "guided-git-command-state\.mjs", "guided-git-review-state\.mjs"/, "server must serve every browser module used by the review gate");
|
|
35
36
|
assert.match(server, /STAGED_CONTENT_HASH_DOMAIN = "firstpick\/aur-review\/staged-content\/v1\\0"[\s\S]*git diff --cached[\s\S]*\/api\/git-workflow\/staged-content/, "server must expose the bounded read-only staged-content hash helper");
|
|
36
37
|
assert.match(server, /async function getAurReviewReportContentData\(tab, \{ path: requestedPath = "", repoRoot = "" \} = \{\}\)[\s\S]*repoRoot !== root[\s\S]*lstat\(targetPath\)[\s\S]*isSymbolicLink\(\)[\s\S]*readBoundedAurReviewReport[\s\S]*\/api\/aur-review\/report-content/s, "server must bind report reads to the canonical Git root and reject symlinked paths through a dedicated read-only route");
|
|
@@ -84,7 +84,7 @@ function makeEnvironment({
|
|
|
84
84
|
removeEventListener(name) { listeners.delete(name); },
|
|
85
85
|
};
|
|
86
86
|
const document = {
|
|
87
|
-
currentScript: new FakeElement({ dataset: { appSrc: "/app.js?v=
|
|
87
|
+
currentScript: new FakeElement({ dataset: { appSrc: "/app.js?v=113" } }),
|
|
88
88
|
readyState: "complete",
|
|
89
89
|
querySelector(selector) {
|
|
90
90
|
return {
|
|
@@ -232,7 +232,7 @@ for (const moduleName of startupModuleNames) {
|
|
|
232
232
|
assert.ok(serviceWorker.includes(`"/${moduleName}"`), `the PWA app shell should include every app.js startup module: ${moduleName}`);
|
|
233
233
|
}
|
|
234
234
|
assert.match(serviceWorker, /pi-webui-pwa-v\d+/, "the app-shell cache should retain a versioned identity");
|
|
235
|
-
assert.ok(html.indexOf('id="webuiBootLoader"') < html.indexOf("/app.js?v=
|
|
235
|
+
assert.ok(html.indexOf('id="webuiBootLoader"') < html.indexOf("/app.js?v=113"), "the inline loader should own app module startup");
|
|
236
236
|
assert.doesNotMatch(html, /<script type="module" src="\/app\.js/, "the app module should not bypass the guarded loader");
|
|
237
237
|
|
|
238
238
|
console.log("boot-failure-diagnostics.test.mjs passed");
|