pinokiod 8.3.31 → 8.3.34
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/package.json +1 -1
- package/server/public/agent-bar-about.js +27 -7
- package/server/public/agent-bar.js +4 -1
- package/server/public/resizeSync.js +13 -1
- package/server/views/partials/home_ask_button.ejs +1 -1
- package/server/views/pro.ejs +1 -4
- package/server/views/shell.ejs +1 -3
- package/server/views/terminal.ejs +1 -4
- package/test/agent-bar-about.test.js +38 -0
- package/test/resize-sync.test.js +100 -0
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// ("Ask · <app>"), the empty text ("Ask Pinokio about <app>…"),
|
|
10
10
|
// what the face says in the open view, and a chip with the
|
|
11
11
|
// app's icon and name at the left of the open view's bottom row.
|
|
12
|
+
// click again -> close the view, keeping the app and the draft.
|
|
12
13
|
// the chip's x, or another mode -> an ordinary Ask again.
|
|
13
14
|
// send -> the same request the app's own page sends for "Ask Pinokio
|
|
14
15
|
// about <app>" (POST /brain/ask with `app`), so the agent starts
|
|
@@ -35,12 +36,19 @@
|
|
|
35
36
|
let chipIcon = null;
|
|
36
37
|
let chipName = null;
|
|
37
38
|
let chipX = null;
|
|
39
|
+
let activeButton = null;
|
|
38
40
|
// { id, name, folder, icon }: the app's folder name, what it is called, the
|
|
39
41
|
// folder's full path and its icon's address
|
|
40
42
|
let app = null;
|
|
41
43
|
|
|
42
44
|
const isBusy = () => Boolean(root) && root.dataset.busy === 'true';
|
|
43
45
|
const onAsk = () => Boolean(root) && root.dataset.item === 'ask';
|
|
46
|
+
const isEngaged = () => root.dataset.engaged === 'true';
|
|
47
|
+
|
|
48
|
+
function setExpanded(button, expanded) {
|
|
49
|
+
button.classList.toggle('is-open', expanded);
|
|
50
|
+
button.setAttribute('aria-expanded', String(expanded));
|
|
51
|
+
}
|
|
44
52
|
|
|
45
53
|
// The chip sits in the open view's bottom row (made by agent-bar-compose.js,
|
|
46
54
|
// possibly after this file runs), at the left, after the mode chip.
|
|
@@ -80,6 +88,10 @@
|
|
|
80
88
|
if (!root) return;
|
|
81
89
|
// another mode: an Ask pointed at an app is no longer what the bar shows
|
|
82
90
|
if (app && !onAsk()) app = null;
|
|
91
|
+
if (activeButton) {
|
|
92
|
+
setExpanded(activeButton, Boolean(app) && isEngaged());
|
|
93
|
+
if (!app) activeButton = null;
|
|
94
|
+
}
|
|
83
95
|
if (!placeChip()) return;
|
|
84
96
|
setHidden(chip, !app);
|
|
85
97
|
if (!app) return;
|
|
@@ -92,13 +104,21 @@
|
|
|
92
104
|
chipX.disabled = isBusy();
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
function toggle(button) {
|
|
108
|
+
if (!root || isBusy()) return;
|
|
109
|
+
const next = fromButton(button);
|
|
110
|
+
if (!next.id || !next.folder) return;
|
|
111
|
+
if (onAsk() && isEngaged() && app?.folder === next.folder) {
|
|
112
|
+
bar.leave();
|
|
113
|
+
button.focus();
|
|
114
|
+
sync();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (activeButton && activeButton !== button) setExpanded(activeButton, false);
|
|
118
|
+
activeButton = button;
|
|
98
119
|
app = next;
|
|
99
120
|
bar.choose('ask');
|
|
100
121
|
sync();
|
|
101
|
-
return true;
|
|
102
122
|
}
|
|
103
123
|
|
|
104
124
|
// The user took the app off: an ordinary Ask, the cursor still in the text.
|
|
@@ -155,7 +175,7 @@
|
|
|
155
175
|
// the home bar only; an app's page has its own bar, which is about that app already
|
|
156
176
|
if (!document.body || document.body.classList.contains('app-page')) return;
|
|
157
177
|
root = document.querySelector('.agent-bar');
|
|
158
|
-
if (!root || typeof bar.choose !== 'function' || typeof bar.refresh !== 'function') {
|
|
178
|
+
if (!root || typeof bar.choose !== 'function' || typeof bar.refresh !== 'function' || typeof bar.leave !== 'function') {
|
|
159
179
|
root = null;
|
|
160
180
|
return;
|
|
161
181
|
}
|
|
@@ -170,7 +190,7 @@
|
|
|
170
190
|
};
|
|
171
191
|
new MutationObserver(sync).observe(root, {
|
|
172
192
|
attributes: true,
|
|
173
|
-
attributeFilter: ['data-item', 'data-busy', 'data-compose', 'data-about'],
|
|
193
|
+
attributeFilter: ['data-item', 'data-busy', 'data-compose', 'data-about', 'data-engaged'],
|
|
174
194
|
});
|
|
175
195
|
sync();
|
|
176
196
|
}
|
|
@@ -192,7 +212,7 @@
|
|
|
192
212
|
if (!button) return;
|
|
193
213
|
event.preventDefault();
|
|
194
214
|
event.stopPropagation();
|
|
195
|
-
|
|
215
|
+
toggle(button);
|
|
196
216
|
}, true);
|
|
197
217
|
// (and Enter or Space on the button is the button's, not the row's)
|
|
198
218
|
document.addEventListener('keydown', (event) => {
|
|
@@ -285,7 +285,7 @@
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
// The keyboard and click-away behaviour of a bar. `bar` is the bar's own
|
|
288
|
-
// { isBusy, hasMenu, closeMenu, leave, fit }.
|
|
288
|
+
// { isBusy, hasMenu, closeMenu, leave, fit, trigger }.
|
|
289
289
|
function bindBar(root, inner, bar) {
|
|
290
290
|
// Keys typed in the bar must not reach page shortcuts.
|
|
291
291
|
['keydown', 'keypress', 'keyup'].forEach((type) => {
|
|
@@ -308,6 +308,8 @@
|
|
|
308
308
|
// menu away. On a phone the box is the whole screen, so there is no outside.
|
|
309
309
|
document.addEventListener('pointerdown', (event) => {
|
|
310
310
|
const at = event.target;
|
|
311
|
+
// An external trigger handles opening and closing on its own click.
|
|
312
|
+
if (bar.trigger && at.closest?.(bar.trigger)) return;
|
|
311
313
|
if (!inner.contains(at)) bar.leave();
|
|
312
314
|
else if (bar.hasMenu() && !(at.closest && at.closest('.agent-bar__menu, button'))) bar.closeMenu();
|
|
313
315
|
}, true);
|
|
@@ -1380,6 +1382,7 @@
|
|
|
1380
1382
|
});
|
|
1381
1383
|
go.addEventListener('click', submit);
|
|
1382
1384
|
bindBar(root, inner, {
|
|
1385
|
+
trigger: '.home-ask-button',
|
|
1383
1386
|
isBusy: () => state.busy,
|
|
1384
1387
|
hasMenu: () => Boolean(state.menu),
|
|
1385
1388
|
closeMenu: () => { state.menu = null; render(); },
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
lastSize: null,
|
|
9
9
|
initialSent: false,
|
|
10
10
|
suppressNext: false,
|
|
11
|
-
allowLocalFit: true
|
|
11
|
+
allowLocalFit: true,
|
|
12
|
+
lastShellSeen: null
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
function sameSize(cols, rows) {
|
|
@@ -76,6 +77,17 @@
|
|
|
76
77
|
sendResize(state.term.cols, state.term.rows, true)
|
|
77
78
|
state.initialSent = true
|
|
78
79
|
},
|
|
80
|
+
// Called with the id of the shell whose output just arrived. A shell the
|
|
81
|
+
// page has not had output from before is sent the page's size: it was
|
|
82
|
+
// started at the size its run was launched with, which need not be the
|
|
83
|
+
// page's size now. Every step of a script run is a new shell. The id a
|
|
84
|
+
// page is handed when it connects is not counted: it can be the finished
|
|
85
|
+
// shell of an earlier run, and a size sent there reaches no one.
|
|
86
|
+
shellSeen: function(id) {
|
|
87
|
+
if (!id || id === state.lastShellSeen || !state.term) return
|
|
88
|
+
state.lastShellSeen = id
|
|
89
|
+
sendResize(state.term.cols, state.term.rows, true)
|
|
90
|
+
},
|
|
79
91
|
handleResizePacket: function(packet) {
|
|
80
92
|
if (!state.term || !packet || !packet.data) return
|
|
81
93
|
const cols = packet.data.cols
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
const askLabel = `Ask Pinokio about ${askName}`;
|
|
10
10
|
%>
|
|
11
11
|
<% if (askApp) { %>
|
|
12
|
-
<button class='btn home-icon-btn home-ask-button' type='button' data-ask-app="<%= askApp %>" data-ask-folder="<%= askFolder %>" data-ask-name="<%= askName %>" data-ask-icon="<%= askIcon %>" title="<%= askLabel %>" aria-label="<%= askLabel %>">
|
|
12
|
+
<button class='btn home-icon-btn home-ask-button' type='button' data-ask-app="<%= askApp %>" data-ask-folder="<%= askFolder %>" data-ask-name="<%= askName %>" data-ask-icon="<%= askIcon %>" title="<%= askLabel %>" aria-label="<%= askLabel %>" aria-expanded="false">
|
|
13
13
|
<i class="fa-regular fa-comment" aria-hidden="true"></i>
|
|
14
14
|
</button>
|
|
15
15
|
<% } %>
|
package/server/views/pro.ejs
CHANGED
|
@@ -339,13 +339,10 @@ async function displayResults(config) {
|
|
|
339
339
|
}
|
|
340
340
|
} else if (packet.type === "stream") {
|
|
341
341
|
// set the current shell id
|
|
342
|
-
const previousShellId = shell_id
|
|
343
342
|
if (packet.data.id) {
|
|
344
343
|
shell_id = packet.data.id
|
|
345
344
|
}
|
|
346
|
-
|
|
347
|
-
resizeSync.sendInitial()
|
|
348
|
-
}
|
|
345
|
+
resizeSync.shellSeen(shell_id)
|
|
349
346
|
if (packet.data.raw) {
|
|
350
347
|
write(packet.data.raw)
|
|
351
348
|
} else if (packet.data.json) {
|
package/server/views/shell.ejs
CHANGED
|
@@ -689,9 +689,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
689
689
|
if (!previousShellId) {
|
|
690
690
|
this.flushPendingInput()
|
|
691
691
|
}
|
|
692
|
-
|
|
693
|
-
this.resizeSync.sendInitial()
|
|
694
|
-
}
|
|
692
|
+
this.resizeSync.shellSeen(shell_id)
|
|
695
693
|
notifyShellSession(shell_id)
|
|
696
694
|
}
|
|
697
695
|
if (packet.data.raw) {
|
|
@@ -1944,14 +1944,11 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
1944
1944
|
refreshParent(packet)
|
|
1945
1945
|
pluginTerminalDiscoveryRefresher.markActivity()
|
|
1946
1946
|
// set the current shell id
|
|
1947
|
-
const previousShellId = shell_id
|
|
1948
1947
|
if (packet.data.id) {
|
|
1949
1948
|
shell_id = packet.data.id
|
|
1950
1949
|
this.flushPendingInput()
|
|
1951
1950
|
}
|
|
1952
|
-
|
|
1953
|
-
this.resizeSync.sendInitial()
|
|
1954
|
-
}
|
|
1951
|
+
this.resizeSync.shellSeen(shell_id)
|
|
1955
1952
|
if (packet.data.raw) {
|
|
1956
1953
|
this.writeBatched(packet.data.raw)
|
|
1957
1954
|
} else if (packet.data.json) {
|
|
@@ -131,6 +131,42 @@ test('a click on a row\'s button points the bar at that app and does not open th
|
|
|
131
131
|
assert.deepEqual(p.posts, [])
|
|
132
132
|
})
|
|
133
133
|
|
|
134
|
+
test('pressing the same row button closes and reopens the bar with its draft', async (t) => {
|
|
135
|
+
const p = await home(t)
|
|
136
|
+
const button = p.askButton('demo')
|
|
137
|
+
const icon = button.querySelector('i')
|
|
138
|
+
const clickIcon = async () => {
|
|
139
|
+
icon.dispatchEvent(new p.window.MouseEvent('pointerdown', { bubbles: true, cancelable: true }))
|
|
140
|
+
button.focus()
|
|
141
|
+
await p.settle()
|
|
142
|
+
await p.click(icon)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await clickIcon()
|
|
146
|
+
assert.equal(p.root.dataset.compose, 'place')
|
|
147
|
+
|
|
148
|
+
p.input.value = 'a draft'
|
|
149
|
+
await clickIcon()
|
|
150
|
+
assert.equal(p.root.dataset.compose, undefined)
|
|
151
|
+
assert.equal(button.getAttribute('aria-expanded'), 'false')
|
|
152
|
+
assert.ok(!button.classList.contains('is-open'))
|
|
153
|
+
assert.equal(p.document.activeElement, button)
|
|
154
|
+
|
|
155
|
+
await clickIcon()
|
|
156
|
+
assert.equal(p.root.dataset.compose, 'place')
|
|
157
|
+
assert.equal(button.getAttribute('aria-expanded'), 'true')
|
|
158
|
+
assert.ok(button.classList.contains('is-open'))
|
|
159
|
+
assert.equal(p.root.dataset.about, 'demo')
|
|
160
|
+
assert.equal(p.input.value, 'a draft')
|
|
161
|
+
assert.deepEqual(p.rowClicks, [])
|
|
162
|
+
assert.deepEqual(p.posts, [])
|
|
163
|
+
|
|
164
|
+
p.document.body.dispatchEvent(new p.window.MouseEvent('pointerdown', { bubbles: true }))
|
|
165
|
+
await p.settle()
|
|
166
|
+
assert.equal(p.root.dataset.compose, undefined)
|
|
167
|
+
assert.equal(button.getAttribute('aria-expanded'), 'false')
|
|
168
|
+
})
|
|
169
|
+
|
|
134
170
|
test('the remembered agent is shown as soon as the page opens, before the bar is used', async (t) => {
|
|
135
171
|
const p = await home(t)
|
|
136
172
|
assert.equal(p.bar.tool().value, 'codex')
|
|
@@ -169,6 +205,8 @@ test('another row\'s button points the bar at the other app', async (t) => {
|
|
|
169
205
|
await p.click(p.askButton('demo'))
|
|
170
206
|
await p.click(p.askButton('other'))
|
|
171
207
|
assert.equal(p.root.dataset.about, 'other')
|
|
208
|
+
assert.equal(p.askButton('demo').getAttribute('aria-expanded'), 'false')
|
|
209
|
+
assert.equal(p.askButton('other').getAttribute('aria-expanded'), 'true')
|
|
172
210
|
assert.equal(p.label(), 'Ask · Other')
|
|
173
211
|
// no icon: the chip shows the name alone
|
|
174
212
|
assert.equal(p.chip().querySelector('.agent-bar__about-icon').hidden, true)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// The size a terminal page sends to its shell (server/public/resizeSync.js),
|
|
2
|
+
// driven with the packets a script's page gets, in the order it gets them.
|
|
3
|
+
const assert = require('node:assert/strict')
|
|
4
|
+
const fs = require('node:fs')
|
|
5
|
+
const path = require('node:path')
|
|
6
|
+
const test = require('node:test')
|
|
7
|
+
const vm = require('node:vm')
|
|
8
|
+
|
|
9
|
+
const source = fs.readFileSync(path.resolve(__dirname, '../server/public/resizeSync.js'), 'utf8')
|
|
10
|
+
|
|
11
|
+
// A page: its terminal, the id of the shell it believes it is on, and what it
|
|
12
|
+
// has sent. `connect` and `stream` do what the page does on those packets.
|
|
13
|
+
const page = (cols, rows) => {
|
|
14
|
+
const window = {}
|
|
15
|
+
vm.runInNewContext(source, { window })
|
|
16
|
+
const sent = []
|
|
17
|
+
const term = { cols, rows }
|
|
18
|
+
let shellId = null
|
|
19
|
+
const sync = window.PinokioResizeSync.create({
|
|
20
|
+
term,
|
|
21
|
+
socket: { run: (message) => sent.push({ id: message.id, cols: message.resize.cols, rows: message.resize.rows }) },
|
|
22
|
+
getShellId: () => shellId,
|
|
23
|
+
})
|
|
24
|
+
return {
|
|
25
|
+
term, sent, sync,
|
|
26
|
+
launch() { sync.reset() },
|
|
27
|
+
connect(shell) {
|
|
28
|
+
if (shell) shellId = shell
|
|
29
|
+
if (shellId) sync.sendInitial()
|
|
30
|
+
},
|
|
31
|
+
stream(id) {
|
|
32
|
+
if (id) shellId = id
|
|
33
|
+
sync.shellSeen(shellId)
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test('the first shell of a first run is sent the page size', () => {
|
|
39
|
+
const p = page(120, 40)
|
|
40
|
+
p.launch()
|
|
41
|
+
p.connect(null) // nothing has run under this script before
|
|
42
|
+
p.stream('shell-1')
|
|
43
|
+
assert.deepEqual(p.sent, [{ id: 'shell-1', cols: 120, rows: 40 }])
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('a run started again sends its size to the new shell, not only to the finished one it was handed', () => {
|
|
47
|
+
const p = page(260, 61)
|
|
48
|
+
p.launch()
|
|
49
|
+
// the page is one column wider by the time the server answers
|
|
50
|
+
p.term.cols = 261
|
|
51
|
+
// the server hands over the last shell of the earlier run, which is finished
|
|
52
|
+
p.connect('old-run-last-shell')
|
|
53
|
+
assert.deepEqual(p.sent, [{ id: 'old-run-last-shell', cols: 261, rows: 61 }])
|
|
54
|
+
// output arrives from the new run's first shell, started at the launch size
|
|
55
|
+
p.stream('new-run-shell-1')
|
|
56
|
+
assert.deepEqual(p.sent[1], { id: 'new-run-shell-1', cols: 261, rows: 61 })
|
|
57
|
+
assert.equal(p.sent.length, 2)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('every step of a run is a new shell and each is sent the size once', () => {
|
|
61
|
+
const p = page(100, 30)
|
|
62
|
+
p.launch()
|
|
63
|
+
p.connect(null)
|
|
64
|
+
p.stream('step-1')
|
|
65
|
+
p.stream('step-1')
|
|
66
|
+
p.stream('step-1')
|
|
67
|
+
// resized while step 1 runs: goes to step 1 as before
|
|
68
|
+
p.term.cols = 140
|
|
69
|
+
p.sync.sendResize(p.term.cols, p.term.rows)
|
|
70
|
+
p.stream('step-2')
|
|
71
|
+
p.stream('step-2')
|
|
72
|
+
p.stream('step-3')
|
|
73
|
+
assert.deepEqual(p.sent, [
|
|
74
|
+
{ id: 'step-1', cols: 100, rows: 30 },
|
|
75
|
+
{ id: 'step-1', cols: 140, rows: 30 },
|
|
76
|
+
{ id: 'step-2', cols: 140, rows: 30 },
|
|
77
|
+
{ id: 'step-3', cols: 140, rows: 30 },
|
|
78
|
+
])
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('output with no shell id sends nothing', () => {
|
|
82
|
+
const p = page(100, 30)
|
|
83
|
+
p.launch()
|
|
84
|
+
p.stream(null)
|
|
85
|
+
assert.deepEqual(p.sent, [])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('every page that shows a shell reports each shell it gets output from', () => {
|
|
89
|
+
// Each page's own handling of a stream packet is inline in its view. If the
|
|
90
|
+
// call goes from one, a shell started again under that page is back to
|
|
91
|
+
// having its size sent only to a finished shell.
|
|
92
|
+
for (const name of ['terminal.ejs', 'shell.ejs', 'pro.ejs']) {
|
|
93
|
+
const view = fs.readFileSync(path.resolve(__dirname, '../server/views', name), 'utf8')
|
|
94
|
+
const stream = view.slice(view.indexOf('packet.type === "stream"'))
|
|
95
|
+
const handler = stream.slice(0, stream.indexOf("packet.type === 'disconnect'"))
|
|
96
|
+
assert.ok(handler.length > 0, name)
|
|
97
|
+
assert.match(handler, /shell_id = packet\.data\.id[\s\S]*resizeSync\.shellSeen\(shell_id\)/, name)
|
|
98
|
+
assert.doesNotMatch(handler, /sendInitial/, name)
|
|
99
|
+
}
|
|
100
|
+
})
|