pinokiod 8.3.15 → 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.
@@ -2404,6 +2404,120 @@ body.dark .terminal-config-menu .terminal-config-input:focus {
2404
2404
  .terminal-config-open .terminal-config-menu {
2405
2405
  display: block;
2406
2406
  }
2407
+ /* The parts terminal-settings-sheet.js adds. They show on a phone only. */
2408
+ .terminal-config-sheet-head,
2409
+ .terminal-config-step,
2410
+ .terminal-config-fold {
2411
+ display: none;
2412
+ }
2413
+ .terminal-config-stepper {
2414
+ display: contents;
2415
+ }
2416
+ /* A phone: the menu is a sheet at the bottom of the screen. (The menu is placed
2417
+ by its own script and, in the agent panel, by the panel: the sheet's place
2418
+ has to win over both.) */
2419
+ @media (max-width: 768px) and (pointer: coarse) {
2420
+ html body > .terminal-config-menu.terminal-config-sheet {
2421
+ left: 0 !important;
2422
+ right: 0 !important;
2423
+ top: auto !important;
2424
+ bottom: 0 !important;
2425
+ max-height: 85%;
2426
+ padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px));
2427
+ border-radius: 16px 16px 0 0;
2428
+ border-width: 1px 0 0;
2429
+ box-sizing: border-box;
2430
+ overscroll-behavior: contain;
2431
+ }
2432
+ .terminal-config-sheet .terminal-config-title {
2433
+ display: none;
2434
+ }
2435
+ .terminal-config-sheet .terminal-config-sheet-head {
2436
+ display: flex;
2437
+ align-items: center;
2438
+ justify-content: space-between;
2439
+ position: sticky;
2440
+ top: 0;
2441
+ z-index: 1;
2442
+ padding: 14px 0 10px;
2443
+ background: inherit;
2444
+ }
2445
+ .terminal-config-sheet .terminal-config-sheet-title {
2446
+ font-size: 16px;
2447
+ font-weight: 600;
2448
+ }
2449
+ .terminal-config-sheet .terminal-config-sheet-done,
2450
+ .terminal-config-sheet .terminal-config-step,
2451
+ .terminal-config-sheet .terminal-config-fold {
2452
+ font: inherit;
2453
+ font-size: 16px;
2454
+ color: inherit;
2455
+ background: transparent;
2456
+ border: 1px solid rgba(128, 128, 128, 0.4);
2457
+ border-radius: 8px;
2458
+ min-height: 44px;
2459
+ cursor: pointer;
2460
+ touch-action: manipulation;
2461
+ }
2462
+ .terminal-config-sheet .terminal-config-sheet-done {
2463
+ padding: 0 16px;
2464
+ font-weight: 600;
2465
+ }
2466
+ .terminal-config-sheet .terminal-config-label,
2467
+ .terminal-config-sheet .terminal-config-note,
2468
+ .terminal-config-sheet .terminal-config-help {
2469
+ font-size: 13px;
2470
+ }
2471
+ /* 16px: smaller text in a field makes the phone zoom the page in on a tap */
2472
+ .terminal-config-sheet .terminal-config-select,
2473
+ .terminal-config-sheet .terminal-config-input {
2474
+ font-size: 16px;
2475
+ min-height: 44px;
2476
+ box-sizing: border-box;
2477
+ }
2478
+ .terminal-config-sheet .terminal-config-stepper {
2479
+ display: flex;
2480
+ gap: 8px;
2481
+ }
2482
+ .terminal-config-sheet .terminal-config-stepper .terminal-config-input {
2483
+ flex: 1;
2484
+ min-width: 0;
2485
+ text-align: center;
2486
+ }
2487
+ .terminal-config-sheet .terminal-config-step {
2488
+ display: block;
2489
+ flex: 0 0 56px;
2490
+ font-size: 22px;
2491
+ line-height: 1;
2492
+ }
2493
+ /* the theme colors are folded away until their row is pressed */
2494
+ .terminal-config-sheet .terminal-config-fold {
2495
+ display: flex;
2496
+ align-items: center;
2497
+ justify-content: space-between;
2498
+ padding: 0 12px;
2499
+ }
2500
+ .terminal-config-sheet .terminal-config-fold::after {
2501
+ content: '\203A';
2502
+ font-size: 20px;
2503
+ transform: rotate(90deg);
2504
+ }
2505
+ .terminal-config-sheet .terminal-config-fold[aria-expanded='true']::after {
2506
+ transform: rotate(-90deg);
2507
+ }
2508
+ .terminal-config-sheet .terminal-config-theme .terminal-config-subtitle,
2509
+ .terminal-config-sheet .terminal-config-theme:not(.terminal-config-theme--open) .terminal-config-help,
2510
+ .terminal-config-sheet .terminal-config-theme:not(.terminal-config-theme--open) .terminal-config-theme-grid {
2511
+ display: none;
2512
+ }
2513
+ .terminal-config-sheet .terminal-config-theme-row {
2514
+ grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr) 44px;
2515
+ }
2516
+ .terminal-config-sheet .terminal-config-theme-clear,
2517
+ .terminal-config-sheet .terminal-config-reset {
2518
+ min-height: 44px;
2519
+ }
2520
+ }
2407
2521
  .terminal-keyboard-backdrop {
2408
2522
  position: fixed;
2409
2523
  inset: 0;
@@ -0,0 +1,66 @@
1
+ // The terminal appearance menu on a phone.
2
+ //
3
+ // terminal-settings.js builds the menu and decides everything it sets. This
4
+ // file adds three parts to it, which the stylesheet shows on a phone only (a
5
+ // narrow screen that is used with a finger) where the menu is a sheet at the
6
+ // bottom of the screen:
7
+ // - a head with a Done button,
8
+ // - a minus and a plus beside the font size,
9
+ // - a row that opens the theme colors, which start folded away.
10
+ // Everywhere else the parts are hidden and the menu is as it was.
11
+ (function (window, document) {
12
+ 'use strict';
13
+ const settings = window.PinokioTerminalSettings;
14
+ if (!settings) return;
15
+
16
+ function el(tag, className, text) {
17
+ const node = document.createElement(tag);
18
+ node.className = className;
19
+ if (tag === 'button') node.type = 'button';
20
+ if (text) node.textContent = text;
21
+ return node;
22
+ }
23
+
24
+ function dress(record) {
25
+ const { menu, sizeInput, themeSection } = record;
26
+ if (menu.classList.contains('terminal-config-sheet')) return;
27
+ menu.classList.add('terminal-config-sheet');
28
+
29
+ const head = el('div', 'terminal-config-sheet-head');
30
+ const done = el('button', 'terminal-config-sheet-done', 'Done');
31
+ done.addEventListener('click', () => record.close());
32
+ head.append(el('span', 'terminal-config-sheet-title', 'Terminal appearance'), done);
33
+ menu.insertBefore(head, menu.firstChild);
34
+
35
+ // one step from the size in use: the one set here, or else the terminal's own
36
+ const step = (by, label, sign) => {
37
+ const button = el('button', 'terminal-config-step', sign);
38
+ button.setAttribute('aria-label', label);
39
+ button.addEventListener('click', () => {
40
+ const size = Number(sizeInput.value || sizeInput.placeholder);
41
+ if (size) settings.updateFontSize(size + by);
42
+ });
43
+ return button;
44
+ };
45
+ const stepper = el('div', 'terminal-config-stepper');
46
+ sizeInput.parentNode.insertBefore(stepper, sizeInput);
47
+ stepper.append(step(-1, 'Smaller text', '\u2212'), sizeInput, step(1, 'Larger text', '+'));
48
+
49
+ const fold = el('button', 'terminal-config-fold', 'Theme colors');
50
+ fold.setAttribute('aria-expanded', 'false');
51
+ fold.addEventListener('click', () => {
52
+ fold.setAttribute('aria-expanded', String(themeSection.classList.toggle('terminal-config-theme--open')));
53
+ });
54
+ themeSection.insertBefore(fold, themeSection.firstChild);
55
+ }
56
+
57
+ // A menu is dressed as its button is pressed, before it opens: terminals, and
58
+ // their menus, can be made at any time.
59
+ document.addEventListener('click', (event) => {
60
+ const button = event.target.closest && event.target.closest('.terminal-config-button');
61
+ if (!button) return;
62
+ settings.menus.forEach((record) => {
63
+ if (record.button === button) dress(record);
64
+ });
65
+ }, true);
66
+ })(window, document);
@@ -1890,7 +1890,12 @@
1890
1890
  }
1891
1891
  });
1892
1892
 
1893
- const handleSizeChange = () => {
1893
+ const handleSizeChange = (event) => {
1894
+ // While typing, a number that is not a size yet ("1" on the way to "14")
1895
+ // is left as typed. Leaving the field settles it.
1896
+ if (event.type === 'input' && !sizeInput.validity.valid) {
1897
+ return;
1898
+ }
1894
1899
  const raw = sizeInput.value.trim();
1895
1900
  if (!raw) {
1896
1901
  settings.updateFontSize(null);
@@ -8378,6 +8378,8 @@ body.dark .pinokio-custom-terminal-header {
8378
8378
  <script src="/storage-sweep.js"></script>
8379
8379
  <script src="/agent-bar.js" data-agent-bar="true"></script>
8380
8380
  <script src="/agent-bar-app.js" data-agent-bar-app="true"></script>
8381
+ <link rel="stylesheet" href="/agent-bar-files.css">
8382
+ <script src="/agent-bar-files.js" data-agent-bar-files="true"></script>
8381
8383
  <link rel="stylesheet" href="/agent-bar-panel.css">
8382
8384
  <script src="/agent-bar-panel.js" data-agent-bar-panel="true"></script>
8383
8385
  <link rel="stylesheet" href="/agent-bar-attach.css">
@@ -89,6 +89,7 @@ body {
89
89
  <script src="/sweetalert2.js"></script>
90
90
  <script src="/Socket.js"></script>
91
91
  <script src="/terminal-settings.js"></script>
92
+ <script src="/terminal-settings-sheet.js"></script>
92
93
  <script>
93
94
  function isASCII(str) {
94
95
  for (let i = 0; i < str.length; i++) {
@@ -16,6 +16,7 @@
16
16
  <script src="/Socket.js"></script>
17
17
  <script src="/resizeSync.js"></script>
18
18
  <script src="/terminal-settings.js"></script>
19
+ <script src="/terminal-settings-sheet.js"></script>
19
20
  <script src="/pinokio-touch.js"></script>
20
21
  <script src="/common.js"></script>
21
22
  <script src="/he.js"></script>
@@ -1500,6 +1500,7 @@ body.dark .ace-editor {
1500
1500
  <script src="/terminal-input.js"></script>
1501
1501
  <script src="/resizeSync.js"></script>
1502
1502
  <script src="/terminal-settings.js"></script>
1503
+ <script src="/terminal-settings-sheet.js"></script>
1503
1504
  <script src="/pinokio-touch.js"></script>
1504
1505
  <script src="/noty.js"></script>
1505
1506
  <script src="/notyq.js"></script>
@@ -502,6 +502,7 @@ body.install-page #terminal .xterm {
502
502
  <script src="/Socket.js"></script>
503
503
  <script src="/terminal-input.js"></script>
504
504
  <script src="/terminal-settings.js"></script>
505
+ <script src="/terminal-settings-sheet.js"></script>
505
506
  <script src="/pinokio-touch.js"></script>
506
507
  <!--
507
508
  <script src="/install.js"></script>
@@ -137,7 +137,9 @@
137
137
  const root = document.documentElement;
138
138
  let lastViewportHeight = null;
139
139
  let lastViewportTop = null;
140
+ const viewportHolds = new Set();
140
141
  const updateViewportHeight = () => {
142
+ if (viewportHolds.size) return;
141
143
  const viewport = window.visualViewport;
142
144
  // Pinch-zoomed in: the visible part is then a magnified piece of the page,
143
145
  // not what a keyboard leaves free. The panes fill the window, as they do
@@ -172,6 +174,17 @@
172
174
  }));
173
175
  };
174
176
 
177
+ // The Agent Bar in a pane protects its terminal tap from both levels of resize.
178
+ window.PinokioLayoutViewport = {
179
+ hold() {
180
+ const token = {};
181
+ viewportHolds.add(token);
182
+ return () => {
183
+ if (viewportHolds.delete(token) && !viewportHolds.size) updateViewportHeight();
184
+ };
185
+ },
186
+ };
187
+
175
188
  const resizeEvents = ['resize', 'orientationchange'];
176
189
  const boundUpdate = () => requestAnimationFrame(updateViewportHeight);
177
190
 
@@ -4,6 +4,8 @@
4
4
  <link rel="stylesheet" href="/agent-bar.css">
5
5
  <script src="/storage-sweep.js"></script>
6
6
  <script src="/agent-bar.js" data-agent-bar="true"></script>
7
+ <link rel="stylesheet" href="/agent-bar-files.css">
8
+ <script src="/agent-bar-files.js" data-agent-bar-files="true"></script>
7
9
  <link rel="stylesheet" href="/agent-bar-panel.css">
8
10
  <script src="/agent-bar-panel.js" data-agent-bar-panel="true"></script>
9
11
  <link rel="stylesheet" href="/agent-bar-attach.css">
@@ -17,6 +17,7 @@
17
17
  <script src="/terminal-input.js"></script>
18
18
  <script src="/resizeSync.js"></script>
19
19
  <script src="/terminal-settings.js"></script>
20
+ <script src="/terminal-settings-sheet.js"></script>
20
21
  <script src="/pinokio-touch.js"></script>
21
22
  <script src="/common.js"></script>
22
23
  <script src="/he.js"></script>
@@ -984,6 +984,7 @@ body.dark .appcanvas {
984
984
  <script src="/terminal-input.js"></script>
985
985
  <script src="/resizeSync.js"></script>
986
986
  <script src="/terminal-settings.js"></script>
987
+ <script src="/terminal-settings-sheet.js"></script>
987
988
  <script src="/pinokio-touch.js"></script>
988
989
  <script src="/noty.js"></script>
989
990
  <script src="/notyq.js"></script>
@@ -20,6 +20,7 @@
20
20
  <script src="/terminal_input_utils.js"></script>
21
21
  <script src="/terminal_key_caption.js"></script>
22
22
  <script src="/terminal-settings.js"></script>
23
+ <script src="/terminal-settings-sheet.js"></script>
23
24
  <script src="/pinokio-touch.js"></script>
24
25
  <script src="/common.js"></script>
25
26
  <script src="/run-task-save.js"></script>
@@ -20,6 +20,7 @@
20
20
  <script src="/terminal_input_utils.js"></script>
21
21
  <script src="/terminal_key_caption.js"></script>
22
22
  <script src="/terminal-settings.js"></script>
23
+ <script src="/terminal-settings-sheet.js"></script>
23
24
  <script src="/pinokio-touch.js"></script>
24
25
  <script src="/common.js"></script>
25
26
  <script src="/run-task-save.js"></script>
@@ -275,6 +275,47 @@ test('on a phone the cursor counts only with the keyboard up', async (t) => {
275
275
  assert.equal(p.input.placeholder, 'Type here…')
276
276
  })
277
277
 
278
+ test('in a layout pane the keyboard is measured on the layout\'s window', async (t) => {
279
+ const p = await page(t, { media: [PHONE, TOUCH] })
280
+ // the pane is cut to what the keyboard leaves: its own sizes show no keyboard
281
+ p.window.visualViewport = { height: 400, offsetTop: 0, addEventListener() {} }
282
+ p.window.innerHeight = 400
283
+ const layout = { innerHeight: 800, visualViewport: { height: 400 } }
284
+ Object.defineProperty(p.window, 'frameElement', { value: {}, configurable: true })
285
+ Object.defineProperty(p.window, 'parent', { value: layout, configurable: true })
286
+ await p.focus()
287
+ assert.equal(p.shape(), 'screen')
288
+ assert.equal(p.input.placeholder, '', 'the cursor is there')
289
+ layout.visualViewport.height = 800
290
+ p.window.dispatchEvent(new p.window.Event('resize'))
291
+ await settle(p.window)
292
+ assert.equal(p.input.placeholder, 'Ask Pinokio anything…')
293
+ })
294
+
295
+ test('on a phone the agent menu opens upward when the keyboard covers the room below', async (t) => {
296
+ // the window is 1000 tall; the agent button's lower edge is at 608
297
+ const hung = async (seen) => {
298
+ const p = await page(t, { media: [PHONE, TOUCH] })
299
+ p.window.visualViewport = { height: seen, offsetTop: 0, addEventListener() {} }
300
+ p.window.innerHeight = 1000
301
+ await p.focus()
302
+ assert.equal(p.shape(), 'screen')
303
+ p.root.querySelector('.agent-bar__agent').click()
304
+ await settle(p.window)
305
+ const menu = p.root.querySelector('.agent-bar__menu[data-menu="agent"]')
306
+ assert.equal(menu.hidden, false)
307
+ return menu.style
308
+ }
309
+ // no keyboard: there is room below the button
310
+ const down = await hung(1000)
311
+ assert.match(down.top, /px$/)
312
+ assert.equal(down.bottom, '')
313
+ // the keyboard covers everything under the button
314
+ const up = await hung(560)
315
+ assert.match(up.bottom, /px$/, 'it hangs above the button')
316
+ assert.equal(up.top, '', 'and not down under the keyboard')
317
+ })
318
+
278
319
  test('a press on the box, off its buttons, puts the cursor in the text', async (t) => {
279
320
  const p = await page(t, { search: '?universal&type=ask' })
280
321
  p.window.PinokioAgentBar.open({ type: 'ask' })
@@ -290,6 +331,10 @@ test('a press on the box, off its buttons, puts the cursor in the text', async (
290
331
  await settle(p.window)
291
332
  assert.equal(p.document.activeElement, p.input)
292
333
  assert.equal(p.shape(), 'centre')
334
+ // a message keeps its own press too: its words can be selected
335
+ const onNote = new p.window.Event('pointerdown', { bubbles: true, cancelable: true })
336
+ p.root.querySelector('.agent-bar__note').dispatchEvent(onNote)
337
+ assert.equal(onNote.defaultPrevented, false)
293
338
  // a button of the box keeps its own press
294
339
  p.input.blur()
295
340
  p.root.querySelector('.agent-bar__scope').click()
@@ -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
+ })