@lune_99/pi-recap 0.0.0-stage → 0.2.0

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.
@@ -0,0 +1,10 @@
1
+ export declare const recapPanel: import("@lune_99/pi-lune-extensions-core").SettingsPanelDefinition<import("typebox").TObject<{
2
+ enabled: import("typebox").TBoolean;
3
+ autoDelaySeconds: import("typebox").TInteger;
4
+ maxRetries: import("typebox").TInteger;
5
+ model: import("typebox").TUnion<[import("typebox").TNull, import("typebox").TObject<{
6
+ provider: import("typebox").TString;
7
+ id: import("typebox").TString;
8
+ }>]>;
9
+ thinkingLevel: import("typebox").TUnion<[import("typebox").TLiteral<"off">, import("typebox").TLiteral<"minimal">, import("typebox").TLiteral<"low">, import("typebox").TLiteral<"medium">, import("typebox").TLiteral<"high">, import("typebox").TLiteral<"xhigh">, import("typebox").TLiteral<"max">]>;
10
+ }>>;
package/dist/panel.js ADDED
@@ -0,0 +1,54 @@
1
+ import { clampThinkingLevel, getSupportedThinkingLevels } from "@earendil-works/pi-ai";
2
+ import { defineSettingsPanel, modelChoices } from "@lune_99/pi-lune-extensions-core/panel";
3
+ import { recapSettings, resolveRecapModel } from "./settings.js";
4
+ export const recapPanel = defineSettingsPanel(recapSettings, {
5
+ id: "recap",
6
+ label: "Recap",
7
+ fields: [
8
+ {
9
+ path: "enabled",
10
+ label: "Automatic recap",
11
+ description: "Off by default. Automatic recap requires real terminal focus reports (e.g. fullscreen); ordinary scrollback may only support /recap.",
12
+ },
13
+ {
14
+ path: "autoDelaySeconds",
15
+ label: "Auto recap delay (seconds)",
16
+ description: "Time after the agent settles before automatic recap can start while the terminal is unfocused. Defaults to 180 seconds. Set to 0 to allow it as soon as eligible.",
17
+ },
18
+ {
19
+ path: "model",
20
+ label: "Recap model",
21
+ formatValue: (value) => value ? `${value.provider}/${value.id}` : "Follow session model",
22
+ choiceSource: modelChoices({
23
+ specialChoices: [{ value: null, label: "Follow session model" }],
24
+ }),
25
+ },
26
+ {
27
+ path: "thinkingLevel",
28
+ label: "Recap thinking level",
29
+ formatValue: (value, { context, values }) => {
30
+ const model = resolveRecapModel(context, values);
31
+ if (!model)
32
+ return `${value} (select an available model first)`;
33
+ const effective = clampThinkingLevel(model, value);
34
+ return effective === value ? value : `${value} → ${effective} (model limit)`;
35
+ },
36
+ choiceSource: {
37
+ load: ({ context, values }) => {
38
+ const model = resolveRecapModel(context, values);
39
+ if (!model)
40
+ throw new Error("Select an available model first");
41
+ return getSupportedThinkingLevels(model).map((value) => ({
42
+ value,
43
+ label: value,
44
+ }));
45
+ },
46
+ },
47
+ },
48
+ {
49
+ path: "maxRetries",
50
+ label: "Maximum retries",
51
+ description: "Retries after the initial attempt, for temporary provider errors only. Intermediate failures stay silent. 0 disables retries.",
52
+ },
53
+ ],
54
+ });
@@ -0,0 +1,124 @@
1
+ import type { AgentActivityOutcome, ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { type TerminalInputSource } from "./focus.ts";
3
+ import { generateRecap } from "./generate.ts";
4
+ import { type RecapSettingsView } from "./settings.ts";
5
+ export declare class RecapRuntime {
6
+ private ctx;
7
+ private focus;
8
+ private timer?;
9
+ private request?;
10
+ private generation;
11
+ private disposed;
12
+ private prompts;
13
+ private settledAt;
14
+ private outcome?;
15
+ private running;
16
+ private pendingDisplay?;
17
+ private displayedKey?;
18
+ private readonly outcomes;
19
+ private readonly records;
20
+ private readonly releases;
21
+ private effectiveSettings;
22
+ diagnostics?: Awaited<ReturnType<typeof generateRecap>>;
23
+ private releaseFocus?;
24
+ private readonly focusInput;
25
+ private readonly pi;
26
+ private readonly view;
27
+ constructor(pi: ExtensionAPI, ctx: ExtensionContext, view: RecapSettingsView, focusInput?: TerminalInputSource);
28
+ private settings;
29
+ private settingsKey;
30
+ /**
31
+ * Capture the exact recap input and derive its identity from the same
32
+ * representation that will be sent to the model.
33
+ */
34
+ private captureInput;
35
+ /**
36
+ * Focus observation exists only while automatic recap is enabled.
37
+ */
38
+ private bindFocus;
39
+ /**
40
+ * Manual and automatic entry points share the same runtime safety gate.
41
+ */
42
+ private ready;
43
+ private clearTimer;
44
+ update(ctx: ExtensionContext): void;
45
+ /**
46
+ * Abort in-flight work and remove any hint derived from stale state.
47
+ */
48
+ invalidate(): void;
49
+ start(ctx: ExtensionContext): void;
50
+ beforeSettle(outcome: AgentActivityOutcome, ctx: ExtensionContext): void;
51
+ /**
52
+ * A round is considered completed only when this runtime observed a clean
53
+ * settle and the corresponding assistant response stopped normally.
54
+ */
55
+ settled(ctx: ExtensionContext): void;
56
+ input(ctx: ExtensionContext): void;
57
+ /**
58
+ * Cached records belong to the previous branch view and must be rebuilt
59
+ * from the newly selected branch.
60
+ */
61
+ branchChanged(ctx: ExtensionContext): void;
62
+ prompt(start: boolean, ctx: ExtensionContext): void;
63
+ /**
64
+ * Pi removes extension widgets before /reload, and a restarted process
65
+ * starts with none. Show the saved recap that still matches the restored
66
+ * session; with automatic recap off, only one the user already saw.
67
+ */
68
+ sessionStarted(ctx: ExtensionContext): void;
69
+ /**
70
+ * Restore persisted recap records and settle markers without re-running a
71
+ * request merely because the process or extension was reloaded.
72
+ */
73
+ private restore;
74
+ /**
75
+ * Automatic recap is worth a model request only after a cleanly completed
76
+ * round that did real work, measured on the latest such round because that
77
+ * is the work the returning user has not seen.
78
+ *
79
+ * Runtime-observed outcomes win because persisted assistant messages alone
80
+ * cannot always distinguish interrupted work from a completed round.
81
+ */
82
+ private hasSubstantialRound;
83
+ /**
84
+ * Build the identity of one model request.
85
+ *
86
+ * Only request-affecting state belongs in the cache key. Runtime scheduling
87
+ * state such as enabled/disabled or settledAt must not force regeneration.
88
+ */
89
+ private snapshot;
90
+ /**
91
+ * Failed model resolution also needs a stable identity so automatic
92
+ * retries wait for meaningful state to change.
93
+ */
94
+ private unresolvedKey;
95
+ /**
96
+ * Persistence receives a complete record. It never re-reads session input,
97
+ * because doing so could associate a result with a newer snapshot.
98
+ */
99
+ private remember;
100
+ /**
101
+ * If the terminal is temporarily busy, retain the record key and display
102
+ * the same cached result once the runtime becomes ready.
103
+ */
104
+ private display;
105
+ private showCached;
106
+ private recapDeadline;
107
+ private schedule;
108
+ /**
109
+ * Manual recap skips focus, delay, and completed-round thresholds while
110
+ * retaining the same idle and prompt-safety conditions.
111
+ */
112
+ manual(ctx: ExtensionContext): Promise<void>;
113
+ private run;
114
+ /**
115
+ * Shutdown and session reload may both dispose the same runtime.
116
+ */
117
+ dispose(): void;
118
+ }
119
+ /**
120
+ * A widget can be removed when the next round starts; notify() would leave
121
+ * stale recap text in the terminal history.
122
+ */
123
+ export declare function showRecap(ctx: ExtensionContext, text: string): void;
124
+ export declare function clearRecap(ctx: ExtensionContext): void;