pi-note 0.37.0 → 0.39.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.
- package/README.md +45 -15
- package/dist-mcp/mcp/core.js +85 -36
- package/dist-mcp/mcp/field-events.js +295 -0
- package/dist-mcp/mcp/http.js +20 -1
- package/examples/field-events.mjs +86 -0
- package/mcp/FIELD_EVENTS.md +151 -0
- package/mcp/README.md +7 -0
- package/mcp/core.ts +80 -38
- package/mcp/field-events.ts +238 -0
- package/mcp/http.ts +14 -1
- package/package.json +2 -1
- package/remote/dialogs.ts +150 -0
- package/remote/footer.ts +2 -1
- package/remote/menu.ts +107 -57
- package/remote/navigation.ts +90 -0
- package/remote/protocol.ts +2 -1
- package/remote/session.ts +14 -4
- package/remote/ui.ts +153 -131
- package/remote.ts +6 -1
package/remote/ui.ts
CHANGED
|
@@ -1,61 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type ExtensionAPI, type ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { Text, truncateToWidth } from '@earendil-works/pi-tui';
|
|
3
3
|
import { NativeFooter } from './footer.ts';
|
|
4
|
-
import { clean,
|
|
4
|
+
import { clean, editorText, footerText, type NativeControl, type NativeView } from './protocol.ts';
|
|
5
5
|
import { RemoteFailure } from './client.ts';
|
|
6
6
|
import { RemoteSession } from './session.ts';
|
|
7
|
-
import {
|
|
7
|
+
import { remoteMenu, type MenuState } from './menu.ts';
|
|
8
|
+
import { document, editValue, working, type Draft } from './dialogs.ts';
|
|
9
|
+
import { disclosure, menuView, parentScreen, serverScreen, type Screen } from './navigation.ts';
|
|
8
10
|
|
|
9
11
|
const line = (text: string) => clean(text).replace(/\n/g, ' ');
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// Escaped values can exceed the wire text limit. Every disclosure line must remain reviewable.
|
|
16
|
-
const disclosure = cleanUnbounded(text);
|
|
17
|
-
const reviewed = await ctx.ui.custom<boolean>((tui, theme, keys, done) => {
|
|
18
|
-
let offset = 0, page = 1, max = 0, geometry = '', usable = false;
|
|
19
|
-
let seen = new Set<number>();
|
|
20
|
-
const cancel = () => done(false);
|
|
21
|
-
signal.addEventListener('abort', cancel, { once: true });
|
|
22
|
-
const component: Component & { dispose(): void } = {
|
|
23
|
-
render(width) {
|
|
24
|
-
const height = inlineHeight(tui, width, component);
|
|
25
|
-
const current = `${width}:${tui.terminal.rows}:${height}`;
|
|
26
|
-
if (geometry !== current) seen = new Set();
|
|
27
|
-
geometry = current;
|
|
28
|
-
page = Math.max(1, Math.min(18, height - 5));
|
|
29
|
-
usable = width >= 20 && height >= 6 && tui.terminal.rows >= 14;
|
|
30
|
-
if (!usable) return [truncateToWidth('Enlarge terminal · Esc cancel', width)];
|
|
31
|
-
const lines = disclosure.split('\n').flatMap((s) => wrapTextWithAnsi(s, width));
|
|
32
|
-
max = Math.max(0, lines.length - page); offset = Math.min(offset, max);
|
|
33
|
-
for (let i = offset; i < Math.min(lines.length, offset + page); i++) seen.add(i);
|
|
34
|
-
const complete = seen.size === lines.length;
|
|
35
|
-
const border = new DynamicBorder((s) => theme.fg('border', s)).render(width);
|
|
36
|
-
return [...border, truncateToWidth(theme.fg('accent', line(title)), width), ...lines.slice(offset, offset + page), '',
|
|
37
|
-
truncateToWidth(complete ? `Review complete · ${keyText('tui.select.confirm')} to choose · ${keyText('tui.select.cancel')} cancel` : `${keyText('tui.select.up')}/${keyText('tui.select.down')} review ALL · ${keyText('tui.select.cancel')} cancel`, width), ...border];
|
|
38
|
-
},
|
|
39
|
-
handleInput(data) {
|
|
40
|
-
if (keys.matches(data, 'tui.select.cancel') || matchesKey(data, Key.ctrl('c'))) cancel();
|
|
41
|
-
else if (usable && geometry === `${tui.terminal.columns}:${tui.terminal.rows}:${inlineHeight(tui, tui.terminal.columns, component)}`) {
|
|
42
|
-
if (keys.matches(data, 'tui.select.confirm') && !signal.aborted) {
|
|
43
|
-
// Every wrapped line must have been visible in this geometry.
|
|
44
|
-
const lines = disclosure.split('\n').flatMap((s) => wrapTextWithAnsi(s, tui.terminal.columns));
|
|
45
|
-
if (seen.size === lines.length) done(true);
|
|
46
|
-
} else if (keys.matches(data, 'tui.select.down')) offset = Math.min(max, offset + 1);
|
|
47
|
-
else if (keys.matches(data, 'tui.select.up')) offset = Math.max(0, offset - 1);
|
|
48
|
-
else if (matchesKey(data, Key.pageDown)) offset = Math.min(max, offset + page);
|
|
49
|
-
else if (matchesKey(data, Key.pageUp)) offset = Math.max(0, offset - page);
|
|
50
|
-
}
|
|
51
|
-
tui.requestRender();
|
|
52
|
-
},
|
|
53
|
-
invalidate() {},
|
|
54
|
-
dispose() { signal.removeEventListener('abort', cancel); },
|
|
55
|
-
};
|
|
56
|
-
return component;
|
|
57
|
-
});
|
|
58
|
-
return reviewed && !signal.aborted && await ctx.ui.select(line(title), ['Cancel', 'Confirm'], { signal }) === 'Confirm';
|
|
13
|
+
/** Review and approval are separate; Enter can never approve by default. */
|
|
14
|
+
export async function review(ctx: ExtensionContext, title: string, text: string, signal: AbortSignal, accept = 'Confirm'): Promise<boolean> {
|
|
15
|
+
return await document(ctx, title, text, signal, true) && !signal.aborted &&
|
|
16
|
+
await ctx.ui.select(line(title), ['Cancel', accept], { signal }) === accept && !signal.aborted;
|
|
59
17
|
}
|
|
60
18
|
|
|
61
19
|
export class RemoteUI {
|
|
@@ -63,7 +21,9 @@ export class RemoteUI {
|
|
|
63
21
|
private repaint = () => {};
|
|
64
22
|
private menuChanged?: () => void;
|
|
65
23
|
private opening = false;
|
|
24
|
+
private acting = false;
|
|
66
25
|
private closing = false;
|
|
26
|
+
private failure?: RemoteFailure;
|
|
67
27
|
private pi: ExtensionAPI;
|
|
68
28
|
private session: RemoteSession;
|
|
69
29
|
private exitOnComplete: (taskId: number) => boolean;
|
|
@@ -80,6 +40,7 @@ export class RemoteUI {
|
|
|
80
40
|
if (!this.session.fullscreen) return { render: () => [], invalidate() {} };
|
|
81
41
|
return new NativeFooter(() => this.session.view ? [{ uri: 'pinote://ui', view: this.session.view }] : [], theme,
|
|
82
42
|
async ({ view }, item, action) => {
|
|
43
|
+
if (this.opening || this.acting) return false;
|
|
83
44
|
if (item.openApp) { await this.open(ctx); return true; }
|
|
84
45
|
const control = view.controls.find((c) => c.id === action && c.kind === 'action');
|
|
85
46
|
return control ? this.dispatch(ctx, view, control) : false;
|
|
@@ -96,21 +57,44 @@ export class RemoteUI {
|
|
|
96
57
|
}
|
|
97
58
|
private render(): void {
|
|
98
59
|
if (this.ctx?.mode !== 'tui') return;
|
|
99
|
-
|
|
60
|
+
const theme = this.ctx.ui.theme;
|
|
61
|
+
this.ctx.ui.setStatus('pinote-remote', this.session.fullscreen ? undefined : this.session.view ? footerText(this.session.view, truncateToWidth, (text, style) => {
|
|
62
|
+
let rendered = style.color ? theme.fg(style.color, text) : text;
|
|
63
|
+
if (style.italic) rendered = theme.italic(rendered);
|
|
64
|
+
return style.strikethrough ? theme.strikethrough(rendered) : rendered;
|
|
65
|
+
}) : 'Pinote · unavailable (/pinote to reconnect)');
|
|
100
66
|
this.repaint();
|
|
101
67
|
}
|
|
102
68
|
async dispatch(ctx: ExtensionContext, view: NativeView, control: NativeControl, value?: NativeControl['value']): Promise<boolean> {
|
|
103
69
|
if (ctx.mode !== 'tui') throw new Error('Pinote UI actions require TUI mode');
|
|
70
|
+
if (this.acting) return false;
|
|
104
71
|
if (control.id === 'done' && !ctx.isIdle()) {
|
|
105
72
|
ctx.ui.notify('Wait for the current agent run before completing this task.', 'warning'); return false;
|
|
106
73
|
}
|
|
74
|
+
this.acting = true; this.failure = undefined;
|
|
107
75
|
const current = this.session.current(), signal = this.session.signal;
|
|
108
76
|
try {
|
|
109
77
|
if (typeof value === 'string') editorText(value);
|
|
110
|
-
if (control.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
78
|
+
if (control.id === 'done') {
|
|
79
|
+
const exits = typeof view.state.selectedId === 'number' && this.exitOnComplete(view.state.selectedId);
|
|
80
|
+
const accept = exits ? 'Complete task and exit' : 'Complete task';
|
|
81
|
+
const summary = truncateToWidth(line(view.body ?? ''), 100);
|
|
82
|
+
if (await ctx.ui.select(`Pinote / ${accept} #${view.state.selectedId}\n${summary}\n${exits ? 'Closes this dedicated Pi session.' : 'Clears selection; keeps this conversation and editor.'}`,
|
|
83
|
+
['Cancel', accept], { signal }) !== accept) return false;
|
|
84
|
+
}
|
|
85
|
+
if (control.confirm) {
|
|
86
|
+
const details = control.kind === 'action' ? control.confirm : `${control.confirm}\n\n${control.id === 'add' || control.id === 'add-field' ? '' : `Before:\n${disclosure(control.value)}\n\n`}After:\n${disclosure(value)}`;
|
|
87
|
+
const accept = control.id === 'add' ? 'Create, start and select' : control.id === 'proposal:accept' ? 'Accept suggestion' :
|
|
88
|
+
control.id === 'remove-field' ? 'Remove display field' : control.id === 'add-field' ? 'Add field' : 'Save change';
|
|
89
|
+
if (!await review(ctx, line(control.label), details, signal, accept)) return false;
|
|
90
|
+
}
|
|
91
|
+
if (!current() || signal.aborted) return false;
|
|
92
|
+
if (control.id === 'continue' && ctx.ui.getEditorText().length) {
|
|
93
|
+
ctx.ui.notify('Draft not inserted: your editor already contains text. Clear or save it first.', 'warning'); return false;
|
|
94
|
+
}
|
|
95
|
+
const result = await working(ctx, control.id === 'preview' || control.id === 'proposal:preview' ? 'Loading preview…' : 'Applying Pinote action…',
|
|
96
|
+
() => this.session.action(view, control, value, () => control.id !== 'done' || ctx.isIdle()), signal);
|
|
97
|
+
if (!current() || !result) return false;
|
|
114
98
|
const selected = this.session.view;
|
|
115
99
|
if (selected && typeof selected.state.selectedId === 'number' && selected.state.selectedId !== view.state.selectedId) {
|
|
116
100
|
await this.renameKittyTab(ctx, selected, signal);
|
|
@@ -118,122 +102,160 @@ export class RemoteUI {
|
|
|
118
102
|
}
|
|
119
103
|
if (control.id === 'done' && ctx.isIdle() && typeof view.state.selectedId === 'number' &&
|
|
120
104
|
this.session.view && this.session.view.state.selectedId == null && this.exitOnComplete(view.state.selectedId)) {
|
|
121
|
-
this.closing = true;
|
|
122
|
-
ctx.shutdown();
|
|
123
|
-
return true;
|
|
105
|
+
this.closing = true; ctx.shutdown(); return true;
|
|
124
106
|
}
|
|
125
|
-
if (result.preview)
|
|
126
|
-
if (result.draft && await review(ctx, 'Insert
|
|
107
|
+
if (result.preview) await document(ctx, `Pinote / ${control.id === 'proposal:preview' ? 'Suggestion' : 'Task preview'}`, result.preview, signal);
|
|
108
|
+
if (result.draft && await review(ctx, 'Pinote / Insert task prompt', `Insert into the editor only; never submit.\n\n${disclosure(result.draft)}`, signal, 'Insert draft') && current()) {
|
|
127
109
|
if (ctx.ui.getEditorText().length) ctx.ui.notify('Draft not inserted: clear the editor first.', 'warning');
|
|
128
110
|
else ctx.ui.setEditorText(editorText(result.draft));
|
|
129
111
|
}
|
|
130
112
|
return true;
|
|
131
113
|
} catch (error) {
|
|
132
114
|
if (current()) {
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
this.failure = error instanceof RemoteFailure ? error : new RemoteFailure(true);
|
|
116
|
+
ctx.ui.notify(this.failure.message, 'warning');
|
|
117
|
+
// Reconnection is an explicit read, never an automatic replay of a write.
|
|
135
118
|
}
|
|
136
119
|
return false;
|
|
137
|
-
}
|
|
120
|
+
} finally { this.acting = false; }
|
|
138
121
|
}
|
|
139
122
|
private async renameKittyTab(ctx: ExtensionContext, view: NativeView, signal: AbortSignal): Promise<void> {
|
|
140
123
|
const window = process.env.KITTY_WINDOW_ID, socket = process.env.KITTY_LISTEN_ON;
|
|
141
124
|
const title = line(view.footer?.find((item) => item.action === 'preview')?.text ?? '').trim();
|
|
142
|
-
// Never fall back to the focused tab or discover an unrelated Kitty instance.
|
|
143
125
|
if (!window || !/^[1-9]\d*$/.test(window) || !socket || !title || process.env.SSH_CONNECTION || process.env.SSH_TTY) return;
|
|
144
126
|
try {
|
|
145
|
-
const result = await this.pi.exec('kitty', ['@', '--to', socket, 'set-tab-title', `--match=window_id:${window}`, '--', title], {
|
|
146
|
-
signal, timeout: 1500,
|
|
147
|
-
});
|
|
127
|
+
const result = await this.pi.exec('kitty', ['@', '--to', socket, 'set-tab-title', `--match=window_id:${window}`, '--', title], { signal, timeout: 1500 });
|
|
148
128
|
if (result.code !== 0) throw new Error('Kitty title update failed');
|
|
149
129
|
} catch {
|
|
150
130
|
if (!signal.aborted) ctx.ui.notify('Pinote task selected, but the Kitty tab could not be renamed.', 'warning');
|
|
151
131
|
}
|
|
152
132
|
}
|
|
133
|
+
private async refresh(ctx: ExtensionContext): Promise<boolean> {
|
|
134
|
+
try {
|
|
135
|
+
await working(ctx, 'Refreshing Pinote…', () => this.session.refresh(true), this.session.signal);
|
|
136
|
+
this.failure = undefined;
|
|
137
|
+
return !!this.session.view && !this.session.signal.aborted;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
this.failure = error instanceof RemoteFailure ? error : new RemoteFailure();
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
153
143
|
async open(ctx: ExtensionContext): Promise<void> {
|
|
154
144
|
if (ctx.mode !== 'tui') { ctx.ui.notify('Pinote UI actions require TUI mode', 'warning'); return; }
|
|
155
|
-
if (this.opening) return;
|
|
145
|
+
if (this.opening || this.acting) return;
|
|
156
146
|
this.opening = true;
|
|
157
147
|
const current = this.session.current(), signal = this.session.signal;
|
|
158
|
-
const menus = new Map<string, MenuState>();
|
|
148
|
+
const menus = new Map<string, MenuState>(), drafts = new Map<string, Draft>();
|
|
149
|
+
let screen = 'home' as Screen, notice = '';
|
|
150
|
+
const go = async (next: Screen): Promise<boolean> => {
|
|
151
|
+
const view = this.session.view;
|
|
152
|
+
if (!view) return false;
|
|
153
|
+
const target = serverScreen(next);
|
|
154
|
+
if ((view.state.screen ?? 'tasks') !== target) {
|
|
155
|
+
const control = view.controls.find((c) => c.id === `screen:${target}`);
|
|
156
|
+
if (!control) return false;
|
|
157
|
+
try { await working(ctx, 'Opening Pinote…', () => this.session.action(view, control), signal); }
|
|
158
|
+
catch (error) { this.failure = error instanceof RemoteFailure ? error : new RemoteFailure(); return false; }
|
|
159
|
+
}
|
|
160
|
+
screen = next; notice = ''; return true;
|
|
161
|
+
};
|
|
159
162
|
try {
|
|
160
|
-
await this.
|
|
163
|
+
await this.refresh(ctx);
|
|
164
|
+
await go('home');
|
|
161
165
|
while (current() && !signal.aborted && !this.closing) {
|
|
166
|
+
if (this.failure || !this.session.view) {
|
|
167
|
+
const failure = this.failure;
|
|
168
|
+
const title = failure?.uncertain ? 'Pinote / Verify result' : failure?.stale ? 'Pinote / State changed' : 'Pinote / Unavailable';
|
|
169
|
+
const choice = await ctx.ui.select(`${title}\n${failure?.message ?? 'Task state could not be verified.'}\nNo automatic retries. Invalid config needs repair on the service.`,
|
|
170
|
+
['Refresh and verify', 'Close'], { signal });
|
|
171
|
+
if (choice !== 'Refresh and verify' || !current()) return;
|
|
172
|
+
if (await this.refresh(ctx)) await go(screen === 'field' ? 'fields' : screen);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
162
175
|
const view = this.session.view;
|
|
163
|
-
if (
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
menus.
|
|
167
|
-
|
|
176
|
+
if (screen === 'field' && view.state.screen !== 'field') screen = 'fields';
|
|
177
|
+
const menu = menuView(view, screen);
|
|
178
|
+
const key = screen === 'field' ? `field:${String(view.state.field)}` : screen;
|
|
179
|
+
const state = menus.get(key) ?? { search: screen === 'tasks' ? String(view.state.search ?? '') : '' };
|
|
180
|
+
menus.set(key, state);
|
|
181
|
+
const choice = await remoteMenu(ctx, menu, state, signal, (changed) => {
|
|
168
182
|
this.menuChanged = changed;
|
|
169
183
|
return () => { if (this.menuChanged === changed) this.menuChanged = undefined; };
|
|
184
|
+
}, { search: screen === 'tasks' ? 'tasks' : screen === 'fields' ? 'local' : 'none', notice,
|
|
185
|
+
searchLabel: screen === 'fields' ? 'Filter fields' : undefined,
|
|
186
|
+
onSearch: async (query) => {
|
|
187
|
+
const latest = this.session.view, control = latest?.controls.find((c) => c.id === 'search');
|
|
188
|
+
if (!current() || !latest || !control) throw new RemoteFailure();
|
|
189
|
+
try { await this.session.action(latest, control, query); }
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (current()) { this.failure = error instanceof RemoteFailure ? error : new RemoteFailure(); this.menuChanged?.(); }
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
},
|
|
170
195
|
});
|
|
171
196
|
if (!current()) return;
|
|
172
197
|
if (!choice) {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return;
|
|
198
|
+
const parent = parentScreen(screen);
|
|
199
|
+
if (!parent) return;
|
|
200
|
+
await go(parent); continue;
|
|
177
201
|
}
|
|
178
202
|
if (choice.id === '__changed') continue;
|
|
179
|
-
if (choice.id === '__refresh') { await this.
|
|
203
|
+
if (choice.id === '__refresh') { await this.refresh(ctx); continue; }
|
|
204
|
+
if (choice.id.startsWith('__preview:')) {
|
|
205
|
+
const id = Number(choice.id.slice('__preview:'.length));
|
|
206
|
+
try {
|
|
207
|
+
const result = await working(ctx, 'Loading task text…', () => this.session.tool('get_task', { task_id: id }, signal), signal);
|
|
208
|
+
if (!current() || !result) return;
|
|
209
|
+
const content = result.content.find((item) => item.type === 'text');
|
|
210
|
+
const task = JSON.parse(content?.type === 'text' ? content.text : 'null');
|
|
211
|
+
if (task?.id !== id || typeof task.text !== 'string') throw new RemoteFailure();
|
|
212
|
+
await document(ctx, `Pinote / Task text #${id}`, task.text, signal);
|
|
213
|
+
} catch (error) { if (current()) this.failure = error instanceof RemoteFailure ? error : new RemoteFailure(); }
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (['__tasks', '__settings', '__prompts', '__footer', '__fields'].includes(choice.id)) { await go(choice.id.slice(2) as Screen); continue; }
|
|
180
217
|
const control = view.controls.find((c) => c.id === choice.id);
|
|
181
218
|
if (!control) continue;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
219
|
+
if (control.id.startsWith('field:')) {
|
|
220
|
+
if (await this.dispatch(ctx, view, control)) { screen = 'field'; notice = ''; }
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
let applied = false;
|
|
224
|
+
if (control.kind === 'text' || control.kind === 'number') {
|
|
225
|
+
const draftKey = `${key}:${control.id}`;
|
|
226
|
+
const draft = drafts.get(draftKey) ?? { text: String(control.value ?? '') };
|
|
227
|
+
drafts.set(draftKey, draft);
|
|
228
|
+
do {
|
|
229
|
+
let value: NativeControl['value'];
|
|
230
|
+
try { value = await editValue(ctx, `${menu.title} / ${line(control.label)}`, view, control, draft, signal); }
|
|
231
|
+
catch { ctx.ui.notify('This value cannot be edited safely in the terminal. Edit it on the service.', 'warning'); break; }
|
|
232
|
+
if (value === undefined || !current()) break;
|
|
233
|
+
applied = await this.dispatch(ctx, view, control, value);
|
|
234
|
+
if (applied) drafts.delete(draftKey);
|
|
235
|
+
// Approval cancellation returns to the draft; a stale/uncertain action returns to recovery.
|
|
236
|
+
} while (!applied && !this.failure && current() && !signal.aborted);
|
|
237
|
+
} else if (control.kind === 'toggle' || control.kind === 'select') {
|
|
238
|
+
const options = control.kind === 'toggle' ? [{ label: 'On', value: true }, { label: 'Off', value: false }] : control.options ?? [];
|
|
239
|
+
const choices = options.map((o, i) => ({ id: `option:${i}`, kind: 'action' as const,
|
|
240
|
+
label: `${line(o.label)}${o.value === control.value ? ' [current]' : ''}`, description: control.description }));
|
|
241
|
+
const picked = await remoteMenu(ctx, { ...view, title: `${menu.title} / ${line(control.label)}`, body: 'Choose a value, then review and confirm the shared change.', controls: choices },
|
|
242
|
+
{ search: '', selected: `option:${Math.max(0, options.findIndex((o) => o.value === control.value))}` }, signal, () => () => {}, { search: 'none' });
|
|
243
|
+
const option = picked && options[Number(picked.id.split(':')[1])];
|
|
244
|
+
if (option && current()) applied = await this.dispatch(ctx, view, control, option.value);
|
|
245
|
+
} else applied = await this.dispatch(ctx, view, control);
|
|
246
|
+
if (applied) {
|
|
247
|
+
if (control.id.startsWith('select:') || ['add', 'proposal:accept', 'continue'].includes(control.id)) return;
|
|
248
|
+
if (control.id === 'remove-field') screen = 'fields';
|
|
249
|
+
notice = control.id === 'clear' ? 'Selection cleared; task progress is unchanged.' : control.id === 'done' ? 'Task completed.' :
|
|
250
|
+
control.id === 'proposal:dismiss' ? 'Suggestion dismissed; tasks are unchanged.' : control.confirm ? `Saved: ${line(control.label)}.` : '';
|
|
201
251
|
}
|
|
202
|
-
if (current() && await this.dispatch(ctx, view, control, value) && control.id.startsWith('select:')) return;
|
|
203
252
|
}
|
|
204
|
-
}
|
|
205
|
-
finally { this.opening = false; }
|
|
253
|
+
} finally { this.opening = false; this.menuChanged = undefined; }
|
|
206
254
|
}
|
|
207
255
|
}
|
|
208
256
|
|
|
257
|
+
/** Historical TUI-only preview entries remain readable after upgrading. */
|
|
209
258
|
export function registerPreview(pi: ExtensionAPI): void {
|
|
210
259
|
pi.registerEntryRenderer<{ title: string; text: string }>('pinote-remote-preview', (entry, _options, theme) =>
|
|
211
260
|
new Text(`${theme.fg('accent', line(entry.data?.title ?? 'Pinote preview'))}\n\n${clean(entry.data?.text ?? '')}`, 0, 0));
|
|
212
261
|
}
|
|
213
|
-
|
|
214
|
-
/** JSON input preserves exact whitespace and does not confuse a placeholder with an initial value. */
|
|
215
|
-
async function jsonInput(ctx: ExtensionContext, title: string, value: string, signal: AbortSignal): Promise<string | undefined> {
|
|
216
|
-
if (signal.aborted) return undefined;
|
|
217
|
-
return ctx.ui.custom<string | undefined>((tui, theme, keys, done) => {
|
|
218
|
-
const input = new Input(); input.setValue(value.replace(/[^\x20-\x7e]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`));
|
|
219
|
-
const cancel = () => done(undefined);
|
|
220
|
-
input.onSubmit = (text) => { if (!signal.aborted) done(text); };
|
|
221
|
-
signal.addEventListener('abort', cancel, { once: true });
|
|
222
|
-
return {
|
|
223
|
-
get focused() { return input.focused; },
|
|
224
|
-
set focused(value: boolean) { input.focused = value; },
|
|
225
|
-
render(width) {
|
|
226
|
-
const border = new DynamicBorder((s) => theme.fg('border', s)).render(width);
|
|
227
|
-
return [...border, truncateToWidth(theme.fg('accent', title), width), ...input.render(width),
|
|
228
|
-
truncateToWidth('JSON value · Enter submit · Esc cancel', width), ...border];
|
|
229
|
-
},
|
|
230
|
-
handleInput(data) {
|
|
231
|
-
if (keys.matches(data, 'tui.select.cancel') || matchesKey(data, Key.ctrl('c'))) cancel();
|
|
232
|
-
else input.handleInput(data);
|
|
233
|
-
tui.requestRender();
|
|
234
|
-
},
|
|
235
|
-
invalidate() { input.invalidate(); },
|
|
236
|
-
dispose() { signal.removeEventListener('abort', cancel); },
|
|
237
|
-
};
|
|
238
|
-
});
|
|
239
|
-
}
|
package/remote.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ENTRY_TYPE, RemoteSession, type SavedState } from './remote/session.ts'
|
|
|
5
5
|
import { registerTools } from './remote/tools.ts';
|
|
6
6
|
import { registerPreview, RemoteUI } from './remote/ui.ts';
|
|
7
7
|
import { registerRemoteExit } from './remote/exit.ts';
|
|
8
|
-
import { editorText } from './remote/protocol.ts';
|
|
8
|
+
import { clean, editorText } from './remote/protocol.ts';
|
|
9
9
|
import { taskCompleted } from './remote/completion.ts';
|
|
10
10
|
|
|
11
11
|
// Only an accepted /new (previousSessionFile) may carry this process-local selection.
|
|
@@ -47,6 +47,11 @@ export default function pinoteRemote(pi: ExtensionAPI): void {
|
|
|
47
47
|
try {
|
|
48
48
|
const config = remoteConfig();
|
|
49
49
|
session = new RemoteSession(config, (saved) => pi.appendEntry(ENTRY_TYPE, saved));
|
|
50
|
+
session.onFieldNotification = (notice) => {
|
|
51
|
+
if (!ctx.hasUI) return false;
|
|
52
|
+
ctx.ui.notify(clean(`Pinote #${notice.taskId} · ${notice.field}: ${notice.message}`).replace(/\n/g, ' '), 'warning');
|
|
53
|
+
return true; // Observation only; fresh task-scoped context reaches the next agent run.
|
|
54
|
+
};
|
|
50
55
|
session.onCompleted = (taskId, signal) => taskCompleted(pi.events, taskId, signal, () => {
|
|
51
56
|
if (ctx.hasUI) ctx.ui.notify('Pinote: completion hook did not finish successfully. The task completion remains confirmed.', 'warning');
|
|
52
57
|
});
|