pinokiod 8.3.14 → 8.3.16
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/index.js +2 -0
- package/server/lib/session_files.js +248 -0
- package/server/public/agent-bar-app.js +28 -6
- package/server/public/agent-bar-compose.js +55 -6
- package/server/public/agent-bar-files.css +391 -0
- package/server/public/agent-bar-files.js +394 -0
- package/server/public/agent-bar-panel.js +104 -14
- package/server/public/agent-bar.js +3 -1
- package/server/public/style.css +114 -0
- package/server/public/terminal-settings-sheet.js +66 -0
- package/server/public/terminal-settings.js +6 -1
- package/server/views/app.ejs +2 -0
- package/server/views/bootstrap.ejs +1 -0
- package/server/views/editor.ejs +1 -0
- package/server/views/init/index.ejs +1 -0
- package/server/views/install.ejs +1 -0
- package/server/views/layout.ejs +13 -0
- package/server/views/partials/main_sidebar.ejs +2 -0
- package/server/views/pro.ejs +1 -0
- package/server/views/prototype/index.ejs +1 -0
- package/server/views/shell.ejs +1 -0
- package/server/views/terminal.ejs +1 -0
- package/test/agent-bar-compose.test.js +102 -0
- package/test/agent-bar-files.test.js +276 -0
- package/test/agent-bar-keyboard.test.js +84 -0
- package/test/agent-bar-running.test.js +148 -0
- package/test/agent-bar-step-aside.test.js +72 -0
- package/test/layout-soft-keyboard.test.js +12 -0
- package/test/session-files.test.js +214 -0
- package/test/terminal-settings-font-size.test.js +47 -0
- package/test/terminal-settings-sheet.test.js +58 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// A session's window shows the files the session made: a switch in its header
|
|
2
|
+
// (Terminal and Files) once there is a file, and the output folder in place.
|
|
3
|
+
//
|
|
4
|
+
// The real agent-bar.js, agent-bar-files.js and agent-bar-panel.js run here in a
|
|
5
|
+
// page that has only what they look for.
|
|
6
|
+
const assert = require('node:assert/strict')
|
|
7
|
+
const fs = require('node:fs')
|
|
8
|
+
const path = require('node:path')
|
|
9
|
+
const test = require('node:test')
|
|
10
|
+
const { JSDOM } = require('jsdom')
|
|
11
|
+
|
|
12
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
13
|
+
|
|
14
|
+
const HOME_PAGE = '<!doctype html><body class="main-sidebar-page"><header class="navheader"><h1><div class="flexible"></div></h1></header><main id="page"></main></body>'
|
|
15
|
+
const ID = '20261118-211145-a46df201'
|
|
16
|
+
const ASK = { id: 'a', group: `/home/plugin/codex/pinokio.js?cwd=/home/brain&session=${ID}`, start_time: 2 }
|
|
17
|
+
// a session in a folder that keeps none (a workspace), and one with an id that is not a request's
|
|
18
|
+
const WORKSPACE = { id: 'b', group: '/home/plugin/codex/pinokio.js?cwd=/home/workspaces/notes&session=s3', start_time: 1 }
|
|
19
|
+
const file = (filePath, size = 2048) => ({ path: filePath, size, modified: 1 })
|
|
20
|
+
const REPORT = [file('report/README.md'), file('report/assets/b2.png'), file('report/assets/b10.png'), file('report/notes/prompt.txt', 40), file('summary.wav', 8000), file('scene.blend')]
|
|
21
|
+
|
|
22
|
+
async function settle(window) {
|
|
23
|
+
for (let i = 0; i < 8; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The home page with one window open on `shell`; `made.files` is what the session's folder holds.
|
|
27
|
+
async function page(t, { shell = ASK, files = [], pages = {}, texts = {} } = {}) {
|
|
28
|
+
const made = { files, asked: [] }
|
|
29
|
+
const dom = new JSDOM(HOME_PAGE, {
|
|
30
|
+
url: 'http://127.0.0.1:42000/home',
|
|
31
|
+
runScripts: 'outside-only',
|
|
32
|
+
pretendToBeVisual: true,
|
|
33
|
+
beforeParse(window) {
|
|
34
|
+
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
|
|
35
|
+
window.Element.prototype.getBoundingClientRect = function () {
|
|
36
|
+
return { left: 300, top: 8, right: 900, bottom: 40, width: 600, height: 32, x: 300, y: 8 }
|
|
37
|
+
}
|
|
38
|
+
window.fetch = async (url) => {
|
|
39
|
+
const address = new window.URL(String(url), 'http://127.0.0.1:42000')
|
|
40
|
+
if (address.pathname === '/info/shells') return { ok: true, json: async () => [shell] }
|
|
41
|
+
if (address.pathname === '/api/plugin/menu') {
|
|
42
|
+
return { ok: true, json: async () => ({ menu: [{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true }] }) }
|
|
43
|
+
}
|
|
44
|
+
if (address.pathname === '/pinokio/session-files') {
|
|
45
|
+
made.asked.push({ cwd: address.searchParams.get('cwd'), session: address.searchParams.get('session') })
|
|
46
|
+
return { ok: true, json: async () => ({ ok: true, files: made.files, more: false }) }
|
|
47
|
+
}
|
|
48
|
+
if (address.pathname.startsWith('/pinokio/session-files/markdown/')) {
|
|
49
|
+
const name = decodeURIComponent(address.pathname.slice('/pinokio/session-files/markdown/'.length))
|
|
50
|
+
return name in pages ? { ok: true, status: 200, json: async () => ({ ok: true, html: pages[name] }) } : { ok: false, status: 404, json: async () => ({ ok: false }) }
|
|
51
|
+
}
|
|
52
|
+
if (address.pathname.startsWith('/pinokio/session-files/file/')) {
|
|
53
|
+
const name = decodeURIComponent(address.pathname.slice('/pinokio/session-files/file/'.length))
|
|
54
|
+
return name in texts ? { ok: true, status: 200, text: async () => texts[name] } : { ok: false, status: 404, text: async () => '' }
|
|
55
|
+
}
|
|
56
|
+
return { ok: false, json: async () => ({}) }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
t.after(() => dom.window.close())
|
|
61
|
+
const { window } = dom
|
|
62
|
+
window.eval(script('agent-bar.js'))
|
|
63
|
+
window.eval(script('agent-bar-files.js'))
|
|
64
|
+
window.eval(script('agent-bar-panel.js'))
|
|
65
|
+
await window.PinokioAgentBar.ready
|
|
66
|
+
await settle(window)
|
|
67
|
+
// open the running session from the bar's list, as a person does
|
|
68
|
+
window.document.querySelector('.agent-bar__running').click()
|
|
69
|
+
await settle(window)
|
|
70
|
+
window.document.querySelector('.agent-bar__menu--running .agent-bar__row').click()
|
|
71
|
+
await settle(window)
|
|
72
|
+
const win = window.document.querySelector('.agent-bar-panel')
|
|
73
|
+
const q = (selector) => win.querySelector(selector)
|
|
74
|
+
const all = (selector) => Array.from(win.querySelectorAll(selector))
|
|
75
|
+
const view = () => q('.agent-files')
|
|
76
|
+
return {
|
|
77
|
+
window,
|
|
78
|
+
win,
|
|
79
|
+
made,
|
|
80
|
+
q,
|
|
81
|
+
all,
|
|
82
|
+
view,
|
|
83
|
+
switcher: () => q('.agent-files__views'),
|
|
84
|
+
buttons: () => all('.agent-files__view'),
|
|
85
|
+
names: () => all('.agent-files__row .agent-files__name').map((node) => node.textContent),
|
|
86
|
+
crumbs: () => all('.agent-files__crumb').map((node) => node.textContent).join(' / '),
|
|
87
|
+
async press(node) {
|
|
88
|
+
node.click()
|
|
89
|
+
await settle(window)
|
|
90
|
+
},
|
|
91
|
+
async openRow(name) {
|
|
92
|
+
all('.agent-files__row').find((row) => row.querySelector('.agent-files__name').textContent === name).querySelector('.agent-files__open').click()
|
|
93
|
+
await settle(window)
|
|
94
|
+
},
|
|
95
|
+
// the window looks at the folder again, as it does every few seconds
|
|
96
|
+
async look(next) {
|
|
97
|
+
if (next) made.files = next
|
|
98
|
+
const before = made.asked.length
|
|
99
|
+
win.dataset.open = 'false'
|
|
100
|
+
await settle(window)
|
|
101
|
+
win.dataset.open = 'true'
|
|
102
|
+
await settle(window)
|
|
103
|
+
assert.ok(made.asked.length > before, 'the folder was read again')
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
test('a session that made nothing has a window exactly as before', async (t) => {
|
|
109
|
+
const p = await page(t)
|
|
110
|
+
assert.deepEqual(p.made.asked[0], { cwd: '/home/brain', session: ID }, 'the folder is found by where the session started and its id')
|
|
111
|
+
assert.equal(p.switcher().hidden, true, 'no switch')
|
|
112
|
+
assert.equal(p.win.dataset.files, 'false', 'so Stop keeps its word')
|
|
113
|
+
assert.equal(p.view().hidden, true, 'no files view')
|
|
114
|
+
assert.ok(p.q('.agent-bar-panel__frame'), 'the terminal is there')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('a session in a folder that keeps no requests is never asked about', async (t) => {
|
|
118
|
+
const p = await page(t, { shell: WORKSPACE, files: REPORT })
|
|
119
|
+
assert.equal(p.made.asked.length, 0)
|
|
120
|
+
assert.equal(p.switcher().hidden, true)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('once there is a file the header has the switch with the number of files', async (t) => {
|
|
124
|
+
const p = await page(t, { files: REPORT })
|
|
125
|
+
assert.equal(p.switcher().hidden, false)
|
|
126
|
+
assert.deepEqual(p.buttons().map((button) => button.querySelector('.agent-files__word').textContent), ['Terminal', 'Files'])
|
|
127
|
+
assert.equal(p.q('.agent-files__count').textContent, '6')
|
|
128
|
+
assert.deepEqual(p.buttons().map((button) => button.getAttribute('aria-pressed')), ['true', 'false'], 'it starts on the terminal')
|
|
129
|
+
assert.equal(p.view().hidden, true)
|
|
130
|
+
assert.equal(p.q('.agent-files__new').hidden, true, 'files that were already there are not new')
|
|
131
|
+
const header = Array.from(p.q('.agent-bar-panel__header').children)
|
|
132
|
+
assert.ok(header.indexOf(p.switcher()) < header.indexOf(p.q('.agent-dock__stop')), 'before Stop')
|
|
133
|
+
assert.equal(p.win.dataset.files, 'true', 'the mark a narrow window shows Stop as its icon by')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('Files lists the top of the output folder: folders first, each with how many files it holds', async (t) => {
|
|
137
|
+
const p = await page(t, { files: REPORT })
|
|
138
|
+
await p.press(p.buttons()[1])
|
|
139
|
+
assert.equal(p.view().hidden, false)
|
|
140
|
+
assert.equal(p.q('.agent-bar-panel__frame').hidden, false, 'the terminal stays underneath')
|
|
141
|
+
assert.deepEqual(p.names(), ['report', 'scene.blend', 'summary.wav'])
|
|
142
|
+
assert.deepEqual(p.all('.agent-files__row .agent-files__meta').map((node) => node.textContent), ['4 files', '2 KB', '8 KB'])
|
|
143
|
+
assert.equal(p.crumbs(), 'Files')
|
|
144
|
+
assert.equal(p.all('.agent-files__rowsave').length, 2, 'a file can be saved from the list; a folder cannot')
|
|
145
|
+
const save = p.all('.agent-files__rowsave')[1]
|
|
146
|
+
assert.equal(save.getAttribute('download'), 'summary.wav')
|
|
147
|
+
const address = new p.window.URL(save.href)
|
|
148
|
+
assert.equal(address.pathname, '/pinokio/session-files/file/summary.wav')
|
|
149
|
+
assert.equal(address.searchParams.get('download'), '1')
|
|
150
|
+
assert.equal(address.searchParams.get('session'), ID)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('a folder opens in place and the path leads back up', async (t) => {
|
|
154
|
+
const p = await page(t, { files: REPORT })
|
|
155
|
+
await p.press(p.buttons()[1])
|
|
156
|
+
await p.openRow('report')
|
|
157
|
+
assert.deepEqual(p.names(), ['assets', 'notes', 'README.md'])
|
|
158
|
+
assert.equal(p.crumbs(), 'Files / report')
|
|
159
|
+
await p.openRow('assets')
|
|
160
|
+
assert.deepEqual(p.names(), ['b2.png', 'b10.png'], 'by name, numbers in order')
|
|
161
|
+
assert.equal(p.crumbs(), 'Files / report / assets')
|
|
162
|
+
const thumb = p.q('.agent-files__icon img')
|
|
163
|
+
assert.equal(new p.window.URL(thumb.src).pathname, '/pinokio/session-files/file/report/assets/b2.png', 'a picture is its own icon')
|
|
164
|
+
await p.press(p.all('.agent-files__crumb')[1])
|
|
165
|
+
assert.equal(p.crumbs(), 'Files / report')
|
|
166
|
+
await p.press(p.all('.agent-files__crumb')[0])
|
|
167
|
+
assert.deepEqual(p.names(), ['report', 'scene.blend', 'summary.wav'])
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('a file opens in place by its kind, with Save', async (t) => {
|
|
171
|
+
const p = await page(t, { files: REPORT, texts: { 'report/notes/prompt.txt': 'a lighthouse <b>at dusk</b>' } })
|
|
172
|
+
await p.press(p.buttons()[1])
|
|
173
|
+
await p.openRow('summary.wav')
|
|
174
|
+
assert.equal(p.crumbs(), 'Files / summary.wav')
|
|
175
|
+
const audio = p.q('.agent-files__body audio')
|
|
176
|
+
assert.ok(audio && audio.controls)
|
|
177
|
+
assert.equal(new p.window.URL(audio.src).pathname, '/pinokio/session-files/file/summary.wav')
|
|
178
|
+
const save = p.q('.agent-files__save')
|
|
179
|
+
assert.equal(save.textContent, 'Save')
|
|
180
|
+
assert.equal(save.getAttribute('download'), 'summary.wav')
|
|
181
|
+
assert.equal(new p.window.URL(save.href).searchParams.get('download'), '1')
|
|
182
|
+
|
|
183
|
+
await p.press(p.all('.agent-files__crumb')[0])
|
|
184
|
+
await p.openRow('scene.blend')
|
|
185
|
+
assert.match(p.q('.agent-files__none').textContent, /This kind of file can't be shown here\..*Save it to open it on this device\./)
|
|
186
|
+
assert.ok(p.q('.agent-files__save'), 'it can still be saved')
|
|
187
|
+
|
|
188
|
+
await p.press(p.all('.agent-files__crumb')[0])
|
|
189
|
+
await p.openRow('report')
|
|
190
|
+
await p.openRow('notes')
|
|
191
|
+
await p.openRow('prompt.txt')
|
|
192
|
+
assert.equal(p.q('.agent-files__plain pre').textContent, 'a lighthouse <b>at dusk</b>', 'text is shown as text')
|
|
193
|
+
assert.equal(p.q('.agent-files__plain b'), null)
|
|
194
|
+
|
|
195
|
+
await p.press(p.all('.agent-files__crumb')[2])
|
|
196
|
+
await p.press(p.all('.agent-files__crumb')[1])
|
|
197
|
+
await p.openRow('assets')
|
|
198
|
+
await p.openRow('b2.png')
|
|
199
|
+
assert.equal(new p.window.URL(p.q('.agent-files__picture img').src).pathname, '/pinokio/session-files/file/report/assets/b2.png')
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test('markdown is shown as a page, and a link to another file of the session opens it here', async (t) => {
|
|
203
|
+
const p = await page(t, {
|
|
204
|
+
files: REPORT,
|
|
205
|
+
pages: { 'report/README.md': '<h1>Lighthouse</h1><p><a href="#" data-session-file="report/assets/b10.png">other</a> <a href="#" data-session-file="report/gone.png">gone</a></p>' },
|
|
206
|
+
})
|
|
207
|
+
await p.press(p.buttons()[1])
|
|
208
|
+
await p.openRow('report')
|
|
209
|
+
await p.openRow('README.md')
|
|
210
|
+
assert.equal(p.q('.agent-files__md h1').textContent, 'Lighthouse')
|
|
211
|
+
await p.press(p.all('.agent-files__md a')[1])
|
|
212
|
+
assert.equal(p.crumbs(), 'Files / report / README.md', 'a link to a file that is not there does nothing')
|
|
213
|
+
await p.press(p.all('.agent-files__md a')[0])
|
|
214
|
+
assert.equal(p.crumbs(), 'Files / report / assets / b10.png')
|
|
215
|
+
assert.ok(p.q('.agent-files__picture img'))
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('a file that arrives while you are on the terminal raises the number and shows a dot until you look', async (t) => {
|
|
219
|
+
const p = await page(t, { files: [file('a.png')] })
|
|
220
|
+
assert.equal(p.q('.agent-files__count').textContent, '1')
|
|
221
|
+
await p.look([file('a.png'), file('b.png')])
|
|
222
|
+
assert.equal(p.q('.agent-files__count').textContent, '2')
|
|
223
|
+
assert.equal(p.q('.agent-files__new').hidden, false)
|
|
224
|
+
await p.press(p.buttons()[1])
|
|
225
|
+
assert.equal(p.q('.agent-files__new').hidden, true)
|
|
226
|
+
assert.deepEqual(p.names(), ['a.png', 'b.png'])
|
|
227
|
+
await p.look([file('a.png'), file('b.png'), file('c.png')])
|
|
228
|
+
assert.deepEqual(p.names(), ['a.png', 'b.png', 'c.png'], 'the list follows the folder while you look at it')
|
|
229
|
+
await p.press(p.buttons()[0])
|
|
230
|
+
assert.equal(p.q('.agent-files__new').hidden, true, 'what you saw is not new')
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test('the first file brings the switch without a reload', async (t) => {
|
|
234
|
+
const p = await page(t)
|
|
235
|
+
assert.equal(p.switcher().hidden, true)
|
|
236
|
+
await p.look([file('a.png')])
|
|
237
|
+
assert.equal(p.switcher().hidden, false)
|
|
238
|
+
assert.equal(p.q('.agent-files__new').hidden, false, 'made while you watched the terminal')
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
test('Files is where you left it when you come back from the terminal', async (t) => {
|
|
242
|
+
const p = await page(t, { files: REPORT })
|
|
243
|
+
await p.press(p.buttons()[1])
|
|
244
|
+
await p.openRow('report')
|
|
245
|
+
await p.openRow('assets')
|
|
246
|
+
await p.press(p.buttons()[0])
|
|
247
|
+
assert.equal(p.view().hidden, true)
|
|
248
|
+
await p.press(p.buttons()[1])
|
|
249
|
+
assert.equal(p.crumbs(), 'Files / report / assets')
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
test('a file on screen is left alone while the folder is read again', async (t) => {
|
|
253
|
+
const p = await page(t, { files: REPORT })
|
|
254
|
+
await p.press(p.buttons()[1])
|
|
255
|
+
await p.openRow('summary.wav')
|
|
256
|
+
const audio = p.q('.agent-files__body audio')
|
|
257
|
+
await p.look(REPORT.concat(file('later.png')))
|
|
258
|
+
assert.equal(p.q('.agent-files__body audio'), audio, 'the same player: it was not started over')
|
|
259
|
+
assert.equal(p.q('.agent-files__count').textContent, '7')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('what was open and is gone falls back to what is still there', async (t) => {
|
|
263
|
+
const p = await page(t, { files: REPORT })
|
|
264
|
+
await p.press(p.buttons()[1])
|
|
265
|
+
await p.openRow('report')
|
|
266
|
+
await p.openRow('assets')
|
|
267
|
+
await p.openRow('b2.png')
|
|
268
|
+
await p.look(REPORT.filter((item) => item.path !== 'report/assets/b2.png'))
|
|
269
|
+
assert.equal(p.crumbs(), 'Files / report / assets', 'the file is gone: its folder')
|
|
270
|
+
await p.look(REPORT.filter((item) => !item.path.startsWith('report/assets/')))
|
|
271
|
+
assert.equal(p.crumbs(), 'Files / report', 'the folder is gone: the one above')
|
|
272
|
+
await p.look([])
|
|
273
|
+
assert.equal(p.switcher().hidden, true, 'nothing left: the terminal, with no switch')
|
|
274
|
+
assert.equal(p.win.dataset.files, 'false')
|
|
275
|
+
assert.equal(p.view().hidden, true)
|
|
276
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const assert = require('node:assert/strict')
|
|
2
|
+
const fs = require('node:fs')
|
|
3
|
+
const path = require('node:path')
|
|
4
|
+
const test = require('node:test')
|
|
5
|
+
const { JSDOM, ResourceLoader } = require('jsdom')
|
|
6
|
+
|
|
7
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
8
|
+
const keyboardInset = '--agent-dock-keyboard'
|
|
9
|
+
|
|
10
|
+
class TerminalPage extends ResourceLoader {
|
|
11
|
+
fetch() {
|
|
12
|
+
return Promise.resolve(Buffer.from('<!doctype html><div id="terminal"><textarea></textarea></div>'))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
test('the mobile Agent Bar panel stays under a terminal tap until Safari delivers its click', async (t) => {
|
|
17
|
+
const dom = new JSDOM('<!doctype html><body class="app-page"></body>', {
|
|
18
|
+
url: 'https://pinokio.example/p/demo',
|
|
19
|
+
resources: new TerminalPage(),
|
|
20
|
+
runScripts: 'outside-only',
|
|
21
|
+
pretendToBeVisual: true,
|
|
22
|
+
})
|
|
23
|
+
t.after(() => dom.window.close())
|
|
24
|
+
const { window } = dom
|
|
25
|
+
const { document } = window
|
|
26
|
+
const viewport = Object.assign(new window.EventTarget(), { height: 695, offsetTop: 0 })
|
|
27
|
+
window.innerWidth = 390
|
|
28
|
+
window.innerHeight = 695
|
|
29
|
+
window.visualViewport = viewport
|
|
30
|
+
window.fetch = async () => ({ ok: true, json: async () => [] })
|
|
31
|
+
window.eval(script('agent-bar.js'))
|
|
32
|
+
window.eval(script('agent-bar-panel.js'))
|
|
33
|
+
await window.PinokioAgentBar.ready
|
|
34
|
+
assert.equal(window.PinokioAgentDock.openWithAgent({
|
|
35
|
+
agentHref: '/pinokio/run/plugin/codex/pinokio.js?cwd=/home/api/demo&session=test',
|
|
36
|
+
}), true)
|
|
37
|
+
const panel = document.querySelector('.agent-bar-panel')
|
|
38
|
+
const frame = panel.querySelector('iframe')
|
|
39
|
+
await new Promise((resolve) => frame.addEventListener('load', resolve, { once: true }))
|
|
40
|
+
|
|
41
|
+
const terminal = frame.contentDocument.querySelector('#terminal')
|
|
42
|
+
const pointer = (type, pointerType = 'touch') => terminal.dispatchEvent(Object.assign(
|
|
43
|
+
new frame.contentWindow.Event(type, { bubbles: true }), { pointerType, isPrimary: true },
|
|
44
|
+
))
|
|
45
|
+
const resize = (height) => {
|
|
46
|
+
viewport.height = height
|
|
47
|
+
viewport.dispatchEvent(new window.Event('resize'))
|
|
48
|
+
}
|
|
49
|
+
const panelInset = () => panel.style.getPropertyValue(keyboardInset)
|
|
50
|
+
const pageInset = () => document.documentElement.style.getPropertyValue(keyboardInset)
|
|
51
|
+
const nextFrame = () => new Promise((resolve) => window.requestAnimationFrame(resolve))
|
|
52
|
+
|
|
53
|
+
pointer('pointerdown')
|
|
54
|
+
terminal.querySelector('textarea').focus()
|
|
55
|
+
pointer('pointerup')
|
|
56
|
+
resize(392)
|
|
57
|
+
assert.equal(pageInset(), '303px', 'the latest keyboard measurement is available')
|
|
58
|
+
assert.equal(panelInset(), '0px', 'the panel still covers the original tap target')
|
|
59
|
+
|
|
60
|
+
terminal.click()
|
|
61
|
+
assert.equal(panelInset(), '0px', 'the tap target stays in place through click dispatch')
|
|
62
|
+
await nextFrame()
|
|
63
|
+
assert.equal(panelInset(), '', 'the panel now uses the measured keyboard inset')
|
|
64
|
+
|
|
65
|
+
pointer('pointerdown')
|
|
66
|
+
assert.equal(panelInset(), '303px')
|
|
67
|
+
pointer('pointercancel')
|
|
68
|
+
assert.equal(panelInset(), '', 'a canceled tap releases the inset even without a click')
|
|
69
|
+
|
|
70
|
+
pointer('pointerdown', 'mouse')
|
|
71
|
+
assert.equal(panelInset(), '', 'mouse interactions keep the normal viewport updates')
|
|
72
|
+
|
|
73
|
+
pointer('pointerdown')
|
|
74
|
+
frame.contentWindow.dispatchEvent(new frame.contentWindow.Event('pagehide'))
|
|
75
|
+
assert.equal(panelInset(), '', 'leaving the frame releases a pending tap')
|
|
76
|
+
|
|
77
|
+
pointer('pointerdown')
|
|
78
|
+
await new Promise((resolve) => window.setTimeout(resolve, 1100))
|
|
79
|
+
assert.equal(panelInset(), '', 'a missing click cannot leave the panel pinned')
|
|
80
|
+
|
|
81
|
+
window.innerWidth = 1024
|
|
82
|
+
pointer('pointerdown')
|
|
83
|
+
assert.equal(panelInset(), '', 'wide floating panels keep their normal positioning')
|
|
84
|
+
})
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// "N running" in the agent bar is the same number on every page: every running
|
|
2
|
+
// agent session, wherever it runs, and every shell opened inside an app. On an
|
|
3
|
+
// app's page the list starts with that app's own sessions.
|
|
4
|
+
//
|
|
5
|
+
// The real agent-bar.js, agent-bar-app.js and agent-bar-panel.js run here in a
|
|
6
|
+
// page that has only what they look for.
|
|
7
|
+
const assert = require('node:assert/strict')
|
|
8
|
+
const fs = require('node:fs')
|
|
9
|
+
const path = require('node:path')
|
|
10
|
+
const test = require('node:test')
|
|
11
|
+
const { JSDOM } = require('jsdom')
|
|
12
|
+
|
|
13
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
14
|
+
|
|
15
|
+
const HOME_PAGE = '<!doctype html><body class="main-sidebar-page"><header class="navheader"><h1><div class="flexible"></div></h1></header><main id="page"></main></body>'
|
|
16
|
+
// an app's page in Run: the app's name, the Ask AI button and panel (which carry
|
|
17
|
+
// the app's folder) and the sidebar the app's card moves to
|
|
18
|
+
const APP_PAGE = '<!doctype html><body class="app-page"><header class="navheader"><h1>'
|
|
19
|
+
+ '<div class="app-header-identity"><span class="app-header-identity-title">Demo App</span></div>'
|
|
20
|
+
+ '<button id="ask-ai-tab" data-workspace-cwd="/home/api/demo"></button><div class="flexible"></div></h1></header>'
|
|
21
|
+
+ '<div class="appcanvas"><aside id="app-sidebar"><div class="menu-scroller"></div></aside><main id="page"></main></div>'
|
|
22
|
+
+ '<div id="ask-ai-drawer" data-workspace-cwd="/home/api/demo"></div></body>'
|
|
23
|
+
|
|
24
|
+
const agent = (id, cwd, session, start) => ({ id, group: `/home/plugin/codex/pinokio.js?cwd=${cwd}&session=${session}`, start_time: start })
|
|
25
|
+
const OWN = agent('a', '/home/api/demo', 's1', 1)
|
|
26
|
+
const OTHER_APP = agent('b', '/home/api/other', 's2', 2)
|
|
27
|
+
const WORKSPACE = agent('c', '/home/workspaces/notes', 's3', 3)
|
|
28
|
+
// a shell opened inside this app, and one of this app's own running scripts
|
|
29
|
+
const OWN_SHELL = { id: 'shell/demo_bash?session=s4', path: '/home/api/demo', start_time: 4 }
|
|
30
|
+
const OWN_SCRIPT = { id: '/home/api/demo/start.js', path: '/home/api/demo', start_time: 5 }
|
|
31
|
+
|
|
32
|
+
async function settle(window) {
|
|
33
|
+
for (let i = 0; i < 6; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function page(t, { app, shells }) {
|
|
37
|
+
const running = { list: shells }
|
|
38
|
+
const dom = new JSDOM(app ? APP_PAGE : HOME_PAGE, {
|
|
39
|
+
url: `http://127.0.0.1:42000/${app ? 'p/demo' : 'home'}`,
|
|
40
|
+
runScripts: 'outside-only',
|
|
41
|
+
pretendToBeVisual: true,
|
|
42
|
+
beforeParse(window) {
|
|
43
|
+
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
|
|
44
|
+
window.Element.prototype.getBoundingClientRect = function () {
|
|
45
|
+
return { left: 300, top: 8, right: 900, bottom: 40, width: 600, height: 32, x: 300, y: 8 }
|
|
46
|
+
}
|
|
47
|
+
window.fetch = async (url) => {
|
|
48
|
+
const address = String(url)
|
|
49
|
+
if (address === '/info/shells') return { ok: true, json: async () => running.list }
|
|
50
|
+
if (address.split('?')[0] === '/api/plugin/menu') {
|
|
51
|
+
return {
|
|
52
|
+
ok: true,
|
|
53
|
+
json: async () => ({
|
|
54
|
+
menu: [{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true }],
|
|
55
|
+
projectShell: { items: [{ href: '/shell/demo_bash', title: 'Bash' }] },
|
|
56
|
+
}),
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (address === '/info/apps') return { ok: true, json: async () => ({ apps: [{ name: 'other', title: 'Other App' }] }) }
|
|
60
|
+
return { ok: false, json: async () => ({}) }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
t.after(() => dom.window.close())
|
|
65
|
+
const { window } = dom
|
|
66
|
+
window.eval(script('agent-bar.js'))
|
|
67
|
+
if (app) window.eval(script('agent-bar-app.js'))
|
|
68
|
+
window.eval(script('agent-bar-panel.js'))
|
|
69
|
+
await window.PinokioAgentBar.ready
|
|
70
|
+
await settle(window)
|
|
71
|
+
const root = window.document.querySelector('.agent-bar')
|
|
72
|
+
const chip = () => root.querySelector('.agent-bar__running')
|
|
73
|
+
const list = () => root.querySelector(app ? '.agent-bar__menu[data-menu="running"]' : '.agent-bar__menu--running')
|
|
74
|
+
return {
|
|
75
|
+
window,
|
|
76
|
+
root,
|
|
77
|
+
chip,
|
|
78
|
+
list,
|
|
79
|
+
running,
|
|
80
|
+
count: () => (chip() && !chip().hidden ? parseInt(chip().textContent, 10) : 0),
|
|
81
|
+
titles: () => Array.from(list().querySelectorAll('.agent-bar__menu-title')).map((node) => node.textContent),
|
|
82
|
+
async open() {
|
|
83
|
+
chip().click()
|
|
84
|
+
await settle(window)
|
|
85
|
+
},
|
|
86
|
+
// the dock looks at what is running again, as it does every few seconds
|
|
87
|
+
async look() {
|
|
88
|
+
if (app) await window.PinokioAgentDock.look()
|
|
89
|
+
else window.document.dispatchEvent(new window.Event('visibilitychange'))
|
|
90
|
+
await settle(window)
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const EVERYTHING = [OWN, OTHER_APP, WORKSPACE, OWN_SHELL, OWN_SCRIPT]
|
|
96
|
+
|
|
97
|
+
test('the count is the same on the home page and on an app\'s page', async (t) => {
|
|
98
|
+
const home = await page(t, { shells: EVERYTHING })
|
|
99
|
+
const app = await page(t, { app: true, shells: EVERYTHING })
|
|
100
|
+
// three agents and the shell; the app's own script is not a session
|
|
101
|
+
assert.equal(home.count(), 4)
|
|
102
|
+
assert.equal(app.count(), 4)
|
|
103
|
+
assert.match(app.chip().textContent, /^4 running$/)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('app page: sessions that run only in other places are counted and listed', async (t) => {
|
|
107
|
+
const p = await page(t, { app: true, shells: [OTHER_APP, WORKSPACE] })
|
|
108
|
+
assert.equal(p.count(), 2)
|
|
109
|
+
await p.open()
|
|
110
|
+
assert.deepEqual(p.titles(), ['Workspaces', 'Other App'])
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('app page: the list starts with this app\'s sessions, then the other places', async (t) => {
|
|
114
|
+
const p = await page(t, { app: true, shells: EVERYTHING })
|
|
115
|
+
await p.open()
|
|
116
|
+
assert.deepEqual(p.titles(), ['This app', 'Workspaces', 'Other App'])
|
|
117
|
+
const rows = Array.from(p.list().children)
|
|
118
|
+
const firstOther = rows.findIndex((node) => node.textContent === 'Workspaces')
|
|
119
|
+
// this app's shell and its agent, before any other place's heading
|
|
120
|
+
assert.equal(rows.slice(1, firstOther).length, 2)
|
|
121
|
+
assert.equal(p.list().querySelectorAll('.agent-dock__liststop').length, 4, 'every row has Stop')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('home page: no "This app" heading, an app\'s sessions stay under the app', async (t) => {
|
|
125
|
+
const p = await page(t, { shells: EVERYTHING })
|
|
126
|
+
await p.open()
|
|
127
|
+
assert.deepEqual(p.titles(), ['Workspaces', 'demo', 'Other App'])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('app page: the count follows a session that ends in another place', async (t) => {
|
|
131
|
+
const p = await page(t, { app: true, shells: [OWN, OTHER_APP] })
|
|
132
|
+
assert.equal(p.count(), 2)
|
|
133
|
+
p.running.list = [OWN]
|
|
134
|
+
await p.look()
|
|
135
|
+
assert.equal(p.count(), 1)
|
|
136
|
+
p.running.list = []
|
|
137
|
+
await p.look()
|
|
138
|
+
assert.equal(p.chip().hidden, true)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('app page: choosing a row closes the list', async (t) => {
|
|
142
|
+
const p = await page(t, { app: true, shells: [OWN, OTHER_APP] })
|
|
143
|
+
await p.open()
|
|
144
|
+
assert.equal(p.list().hidden, false)
|
|
145
|
+
p.list().querySelector('.agent-bar__row').click()
|
|
146
|
+
await settle(p.window)
|
|
147
|
+
assert.equal(p.root.querySelector('.agent-bar__menu').hidden, true)
|
|
148
|
+
})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// On a phone a session's window covers the whole page. When the page changes,
|
|
2
|
+
// the window steps aside to its tab so the new page can be seen.
|
|
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 { JSDOM } = require('jsdom')
|
|
8
|
+
|
|
9
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
10
|
+
const TABS = 'pinokio.agentBar.dock.tabs'
|
|
11
|
+
const PAGE = 'pinokio.agentBar.dock.page'
|
|
12
|
+
|
|
13
|
+
// Loads `to` with one window left open on the page `from`; returns the saved tabs.
|
|
14
|
+
const arrive = (t, { from, to, width }) => {
|
|
15
|
+
const dom = new JSDOM('<!doctype html><body class="app-page"></body>', {
|
|
16
|
+
url: `https://pinokio.example${to}`,
|
|
17
|
+
runScripts: 'outside-only',
|
|
18
|
+
pretendToBeVisual: true,
|
|
19
|
+
})
|
|
20
|
+
t.after(() => dom.window.close())
|
|
21
|
+
const { window } = dom
|
|
22
|
+
window.innerWidth = width
|
|
23
|
+
window.innerHeight = 695
|
|
24
|
+
window.fetch = () => new Promise(() => {})
|
|
25
|
+
window.sessionStorage.setItem(TABS, JSON.stringify([
|
|
26
|
+
{ key: 'one', kind: 'agent', label: 'Agent', open: true, z: 2 },
|
|
27
|
+
{ key: 'two', kind: 'agent', label: 'Agent', open: false, z: 1 },
|
|
28
|
+
]))
|
|
29
|
+
if (from) window.sessionStorage.setItem(PAGE, JSON.stringify(from))
|
|
30
|
+
window.eval(script('agent-bar.js'))
|
|
31
|
+
window.eval(script('agent-bar-panel.js'))
|
|
32
|
+
return {
|
|
33
|
+
window,
|
|
34
|
+
tabs: JSON.parse(window.sessionStorage.getItem(TABS)),
|
|
35
|
+
page: JSON.parse(window.sessionStorage.getItem(PAGE)),
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
test('on a phone an open window steps aside to its tab when the page changes', (t) => {
|
|
40
|
+
const { tabs, page } = arrive(t, { from: '/p/demo', to: '/p/demo/dev', width: 390 })
|
|
41
|
+
assert.deepEqual(tabs.map((tab) => tab.key), ['one', 'two'], 'both tabs are kept')
|
|
42
|
+
assert.deepEqual(tabs.map((tab) => tab.open), [false, false], 'no window covers the new page')
|
|
43
|
+
assert.equal(page, '/p/demo/dev', 'the new page is remembered for the next change')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('on a phone the window comes back when the same page loads again', (t) => {
|
|
47
|
+
const { tabs } = arrive(t, { from: '/p/demo?tab=1', to: '/p/demo?tab=1', width: 390 })
|
|
48
|
+
assert.deepEqual(tabs.map((tab) => tab.open), [true, false])
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('on a phone a different address on the same path is a page change', (t) => {
|
|
52
|
+
const { tabs } = arrive(t, { from: '/p/demo?tab=1', to: '/p/demo?tab=2', width: 390 })
|
|
53
|
+
assert.deepEqual(tabs.map((tab) => tab.open), [false, false])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('on a wide screen the window follows you to the new page', (t) => {
|
|
57
|
+
const { tabs } = arrive(t, { from: '/p/demo', to: '/p/demo/dev', width: 1280 })
|
|
58
|
+
assert.deepEqual(tabs.map((tab) => tab.open), [true, false])
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('with no page remembered the windows are left as they were saved', (t) => {
|
|
62
|
+
const { tabs, page } = arrive(t, { from: '', to: '/p/demo', width: 390 })
|
|
63
|
+
assert.deepEqual(tabs.map((tab) => tab.open), [true, false])
|
|
64
|
+
assert.equal(page, '/p/demo')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('a page that rewrites its own address is remembered by the address it was left at', (t) => {
|
|
68
|
+
const { window } = arrive(t, { from: '', to: '/home', width: 390 })
|
|
69
|
+
window.history.replaceState(null, '', '/home?sort=most_used')
|
|
70
|
+
window.dispatchEvent(new window.Event('pagehide'))
|
|
71
|
+
assert.equal(JSON.parse(window.sessionStorage.getItem(PAGE)), '/home?sort=most_used')
|
|
72
|
+
})
|
|
@@ -85,6 +85,18 @@ test('with the keyboard up, the visible part is what is left above it', (t) => {
|
|
|
85
85
|
assert.deepEqual(page.measured(), { height: '812px', top: '0px' })
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
+
test('the outer layout defers its keyboard resize until a terminal tap finishes', (t) => {
|
|
89
|
+
const viewport = fullWindow()
|
|
90
|
+
const page = shell(t, viewport)
|
|
91
|
+
const finishTap = page.window.PinokioLayoutViewport.hold()
|
|
92
|
+
Object.assign(viewport, { height: 470, pageTop: 40 })
|
|
93
|
+
page.resize()
|
|
94
|
+
assert.deepEqual(page.measured(), { height: '812px', top: '0px' })
|
|
95
|
+
|
|
96
|
+
finishTap()
|
|
97
|
+
assert.deepEqual(page.measured(), { height: '470px', top: '40px' })
|
|
98
|
+
})
|
|
99
|
+
|
|
88
100
|
test('when the browser slides the page up under the keyboard, the panes follow', (t) => {
|
|
89
101
|
const viewport = fullWindow()
|
|
90
102
|
const page = shell(t, viewport)
|