pinokiod 8.3.17 → 8.3.19

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.17",
3
+ "version": "8.3.19",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -436,11 +436,32 @@ html .agent-bar.agent-compose[data-compose="centre"] .agent-compose__bg {
436
436
  .agent-bar[data-compose="centre"] .agent-compose__greet {
437
437
  display: block;
438
438
  }
439
+ /* A link's text is often long (a template's address and answers), so it is set
440
+ a step smaller than typed text, and the greeting with it. */
439
441
  html .agent-bar.agent-compose[data-compose="centre"] .agent-bar__input {
440
442
  min-height: 82px;
441
443
  padding: 2px 4px;
442
- font-size: 18px;
443
- line-height: 26px;
444
+ font-size: 15px;
445
+ line-height: 22px;
446
+ }
447
+ .agent-bar[data-compose="centre"] .agent-compose__greet {
448
+ font-size: 15px;
449
+ line-height: 22px;
450
+ }
451
+ /* Dark theme: the open view's face is filled off-white with dark features, so
452
+ it is the same light-faced character as on the light theme and as the mark
453
+ at rest, not white lines around a dark face. While working it is the
454
+ outlined face again: the line that runs around the head needs the outline to
455
+ run on. */
456
+ body.dark .agent-bar[data-compose] .agent-compose__face:not([data-face="working"]) {
457
+ color: #1b1c1d;
458
+ }
459
+ body.dark .agent-bar[data-compose] .agent-compose__face:not([data-face="working"]) .agent-compose__head {
460
+ fill: #d9d9da;
461
+ stroke: #d9d9da;
462
+ }
463
+ body.dark .agent-bar[data-compose] .agent-compose__face:not([data-face="working"]) .agent-compose__nose {
464
+ fill: #d9d9da;
444
465
  }
445
466
  html .agent-bar.agent-compose[data-compose="centre"] .agent-bar__footer {
446
467
  margin: 0 -16px;
@@ -820,6 +820,8 @@
820
820
  const frameUrl = settings.launchUrl || session.url;
821
821
  if (frameUrl && (settings.launchUrl || !part.frame.dataset.url)) {
822
822
  part.frame.dataset.url = frameUrl;
823
+ // Restoring a session must leave focus on the page that just opened.
824
+ part.frame.toggleAttribute('data-skip-startup-focus', settings.still === true);
823
825
  part.frame.src = frameUrl;
824
826
  embedSoon(win);
825
827
  }
@@ -902,6 +904,7 @@
902
904
  whenRunning(session, () => {
903
905
  if (!wins.has(win.key)) return;
904
906
  win.part.frame.dataset.url = session.url;
907
+ win.part.frame.removeAttribute('data-skip-startup-focus');
905
908
  win.part.frame.src = session.url;
906
909
  embedSoon(win);
907
910
  });
@@ -1789,7 +1789,7 @@ document.addEventListener("DOMContentLoaded", async () => {
1789
1789
  this.tabCaptionHelper = window.PinokioTabCaptionHelper.attach(term, { tracker: this.inputTracker })
1790
1790
 
1791
1791
  }
1792
- this.term.focus()
1792
+ if (!window.frameElement?.hasAttribute('data-skip-startup-focus')) this.term.focus()
1793
1793
  this.observer = new ResizeObserver(() => {
1794
1794
  this.fit.fit()
1795
1795
  this.resizeSync.sendResize(this.term.cols, this.term.rows)
@@ -3245,7 +3245,7 @@ document.addEventListener("DOMContentLoaded", async () => {
3245
3245
  this.tabCaptionHelper = window.PinokioTabCaptionHelper.attach(term, { tracker: this.inputTracker })
3246
3246
 
3247
3247
  }
3248
- this.term.focus()
3248
+ if (!window.frameElement?.hasAttribute('data-skip-startup-focus')) this.term.focus()
3249
3249
  this.observer = new ResizeObserver(() => {
3250
3250
  this.fit.fit()
3251
3251
  this.resizeSync.sendResize(this.term.cols, this.term.rows)
@@ -13,6 +13,97 @@ class TerminalPage extends ResourceLoader {
13
13
  }
14
14
  }
15
15
 
16
+ class StartupTerminalPage extends ResourceLoader {
17
+ fetch(url) {
18
+ const view = new URL(url).pathname.startsWith('/shell/') ? 'shell' : 'terminal'
19
+ const template = fs.readFileSync(path.resolve(__dirname, '../server/views', `${view}.ejs`), 'utf8')
20
+ const startup = template.match(/^ {6}(.*this\.term\.focus\(\))\n {6}this\.observer = new ResizeObserver/m)
21
+ assert.ok(startup, `${view} has a terminal startup focus statement`)
22
+ return Promise.resolve(Buffer.from(`<!doctype html><textarea></textarea><script>
23
+ window.focus = () => {};
24
+ const term = {
25
+ focus() {
26
+ document.querySelector('textarea').focus();
27
+ // JSDOM moves focus into the frame but omits the parent window's blur.
28
+ window.parent.dispatchEvent(new window.parent.Event('blur'));
29
+ },
30
+ onRender() {},
31
+ };
32
+ window.PinokioTerminalSettings = { terminals: new Map([[1, term]]) };
33
+ (function () { ${startup[1]} }).call({ term });
34
+ </script>`))
35
+ }
36
+ }
37
+
38
+ test('restoring agent and shell windows leaves a prefilled composer focused', { timeout: 3000 }, async (t) => {
39
+ const dom = new JSDOM('<!doctype html><body class="main-sidebar-page"><header class="navheader"><h1><div class="flexible"></div></h1></header></body>', {
40
+ url: 'https://pinokio.example/home?universal=&type=create_app&prompt=Build',
41
+ resources: new StartupTerminalPage(),
42
+ runScripts: 'dangerously',
43
+ pretendToBeVisual: true,
44
+ })
45
+ t.after(() => dom.window.close())
46
+ const { window } = dom
47
+ const { document } = window
48
+ window.innerWidth = 1760
49
+ window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
50
+ window.Element.prototype.getBoundingClientRect = () => ({ left: 300, top: 8, right: 900, bottom: 40, width: 600, height: 32 })
51
+ const shell = 'shell/demo_bash?session=shell'
52
+ const running = [
53
+ { id: 'agent', group: '/home/plugin/codex/pinokio.js?cwd=/home/brain&session=agent' },
54
+ { id: shell, path: '/home/api/demo' },
55
+ ]
56
+ window.sessionStorage.setItem('pinokio.agentBar.dock.tabs', JSON.stringify([
57
+ { key: '/plugin/codex/pinokio.js|/home/brain|agent', kind: 'agent', open: true, docked: true, z: 1 },
58
+ { key: shell, kind: 'shell', open: true, z: 2 },
59
+ ]))
60
+ let publishRunning
61
+ const runningResponse = new Promise((resolve) => { publishRunning = resolve })
62
+ window.fetch = async (url) => {
63
+ if (url === '/info/shells') return runningResponse
64
+ return { ok: true, json: async () => ({
65
+ menu: [{ href: '/pinokio/run/plugin/codex/pinokio.js', title: 'Codex', default: true }],
66
+ projectShell: { items: [{ href: '/shell/demo_bash', title: 'Bash' }] },
67
+ }) }
68
+ }
69
+ const restored = new Promise((resolve) => {
70
+ const frames = []
71
+ const loaded = (event) => {
72
+ const frame = event.target
73
+ if (!frame.matches?.('.agent-bar-panel__frame') || !frame.contentWindow.PinokioTerminalSettings) return
74
+ frames.push(frame)
75
+ if (frames.length === 2) {
76
+ document.removeEventListener('load', loaded, true)
77
+ resolve(frames)
78
+ }
79
+ }
80
+ document.addEventListener('load', loaded, true)
81
+ })
82
+ for (const name of ['agent-bar.js', 'agent-bar-compose.js', 'agent-bar-panel.js']) window.eval(script(name))
83
+ await window.PinokioAgentBar.ready
84
+ assert.equal(window.PinokioAgentBar.open({ type: 'create_app', prompt: 'Build' }), true)
85
+ const bar = document.querySelector('.agent-bar')
86
+ const draft = bar.querySelector('textarea')
87
+ const settleFocus = () => new Promise((resolve) => window.setTimeout(resolve, 0))
88
+ assert.equal(bar.dataset.compose, 'centre')
89
+ publishRunning({ ok: true, json: async () => running })
90
+ const frames = await restored
91
+ await settleFocus()
92
+ assert.equal(bar.dataset.compose, 'centre')
93
+ assert.equal(document.activeElement, draft)
94
+ assert.equal(draft.value, 'Build')
95
+
96
+ const shellFrame = frames.find((frame) => new URL(frame.src).pathname.startsWith('/shell/'))
97
+ const panel = shellFrame.closest('aside')
98
+ const refreshed = new Promise((resolve) => shellFrame.addEventListener('load', resolve, { once: true }))
99
+ panel.querySelector('[aria-label="More"]').click()
100
+ Array.from(panel.querySelectorAll('.agent-dock__more-row')).find((row) => row.textContent === 'Refresh').click()
101
+ await refreshed
102
+ await settleFocus()
103
+ assert.equal(document.activeElement, shellFrame, 'an explicit refresh still focuses the terminal')
104
+ assert.equal(bar.dataset.compose, undefined)
105
+ })
106
+
16
107
  test('the mobile Agent Bar panel stays under a terminal tap until Safari delivers its click', async (t) => {
17
108
  const dom = new JSDOM('<!doctype html><body class="app-page"></body>', {
18
109
  url: 'https://pinokio.example/p/demo',