pinokiod 8.3.9 → 8.3.11

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.
@@ -1961,6 +1961,18 @@ body.columns .containers {
1961
1961
  */
1962
1962
  overflow: auto;
1963
1963
  }
1964
+ /* The terminal takes the room its container has. "height: 100%" alone is read
1965
+ by iPhone browsers as the height of the whole page, so the terminal counted
1966
+ more rows than fit and its last rows (the prompt) sat below the visible
1967
+ part, out of reach once the keyboard is up. */
1968
+ body > .terminal-container {
1969
+ display: flex;
1970
+ flex-direction: column;
1971
+ }
1972
+ body > .terminal-container > #terminal {
1973
+ flex: 1 1 0;
1974
+ min-height: 0;
1975
+ }
1964
1976
  .terminal-container #terminal-resize {
1965
1977
  position: absolute;
1966
1978
  bottom: 10px;
@@ -2055,6 +2067,13 @@ body.columns .containers {
2055
2067
  font-variant-ligatures: none;
2056
2068
  font-feature-settings: "liga" 0, "clig" 0, "calt" 0, "rlig" 0;
2057
2069
  }
2070
+ /* A finger drag that starts on text keeps scrolling. A touch belongs to the
2071
+ element it started on, and the terminal replaces a row's text elements when
2072
+ it redraws, so a drag that started on one stopped after the first line.
2073
+ With this the touch lands on the screen behind the rows, which stays. */
2074
+ .xterm .xterm-rows {
2075
+ pointer-events: none;
2076
+ }
2058
2077
  .xterm {
2059
2078
  padding: 0 10px !important;
2060
2079
  /*
@@ -0,0 +1,79 @@
1
+ // Terminal input that the terminal library (xterm.js) does not send to the
2
+ // shell by itself. Every page with a terminal you can type in calls, once per
3
+ // terminal, after it is opened:
4
+ //
5
+ // PinokioTerminalInput.attach(term, () => socket, () => shell_id)
6
+ //
7
+ // 1. Bytes. Typing and pastes come as text (onData), which the pages already
8
+ // send. Mouse reports in the old format, used when a program tracks the
9
+ // mouse without asking for the SGR format, come as bytes on a second channel
10
+ // (onBinary), one byte per character. They are sent marked "binary", so the
11
+ // server writes them to the program as bytes.
12
+ //
13
+ // 2. Finger scrolling of full-screen programs. Under a finger the library
14
+ // scrolls only its own scrollback. When the program owns the screen
15
+ // (alternate screen) or tracks the mouse there is no scrollback to move, so
16
+ // a drag is replayed as wheel steps, one per row. The library turns those
17
+ // into what the program reads, exactly as it does for a real wheel: mouse
18
+ // reports, or arrow keys.
19
+ //
20
+ // The socket and shell id are read each time: pages create both after the terminal.
21
+ (function (window) {
22
+ 'use strict'
23
+
24
+ if (window.PinokioTerminalInput) return
25
+
26
+ function attach(term, getSocket, getShellId) {
27
+ // The shell that input goes to right now, or null. It must exist, and the
28
+ // connection must already be open: a send while it is still connecting (a
29
+ // reconnect) throws, and nothing here opens one.
30
+ const target = () => {
31
+ const socket = getSocket()
32
+ return (socket && socket.ws && socket.ws.readyState === window.WebSocket.OPEN && getShellId()) || null
33
+ }
34
+
35
+ term.onBinary((data) => {
36
+ const id = target()
37
+ if (id) getSocket().emit({ key: data, id, binary: true })
38
+ })
39
+
40
+ const programScrolls = () => term.buffer.active.type === 'alternate' || term.modes.mouseTrackingMode !== 'none'
41
+ // A drag belongs to the shell and program it started on. Any other touch is
42
+ // left to the library, which scrolls its scrollback.
43
+ let drag = null
44
+ term.element.addEventListener('touchstart', (event) => {
45
+ const shell = event.touches.length === 1 && programScrolls() && target()
46
+ drag = shell ? { shell, y: event.touches[0].clientY, pending: 0 } : null
47
+ }, { passive: true })
48
+ term.element.addEventListener('touchmove', (event) => {
49
+ if (!drag) return
50
+ const rowHeight = term.element.querySelector('.xterm-screen').clientHeight / term.rows
51
+ // Dropped if anything changed while the finger was down: a second finger,
52
+ // the program exited, the terminal was hidden (no row height), or the
53
+ // shell was replaced or its connection lost.
54
+ if (event.touches.length !== 1 || !programScrolls() || !rowHeight || target() !== drag.shell) {
55
+ drag = null
56
+ return
57
+ }
58
+ // from the first move on, or the browser takes the drag to pan the page
59
+ if (event.cancelable) event.preventDefault()
60
+ const touch = event.touches[0]
61
+ drag.pending += drag.y - touch.clientY
62
+ drag.y = touch.clientY
63
+ const rows = Math.trunc(drag.pending / rowHeight)
64
+ drag.pending -= rows * rowHeight
65
+ for (let i = 0; i < Math.abs(rows); i++) {
66
+ term.element.dispatchEvent(new window.WheelEvent('wheel', {
67
+ bubbles: true,
68
+ cancelable: true,
69
+ deltaMode: 1, // lines
70
+ deltaY: Math.sign(rows),
71
+ clientX: touch.clientX,
72
+ clientY: touch.clientY
73
+ }))
74
+ }
75
+ }, { passive: false })
76
+ }
77
+
78
+ window.PinokioTerminalInput = { attach }
79
+ })(window)
package/server/socket.js CHANGED
@@ -392,7 +392,8 @@ class Socket {
392
392
  this.parent.kernel.shell.emit({
393
393
  id: keyId,
394
394
  emit: req.key,
395
- paste: req.paste
395
+ paste: req.paste,
396
+ binary: req.binary === true
396
397
  })
397
398
  } else if (req.resize && req.id) {
398
399
  const targetId = this.shell_to_path[req.id] || req.id
@@ -8375,6 +8375,7 @@ body.dark .pinokio-custom-terminal-header {
8375
8375
  </script>
8376
8376
  <link rel="stylesheet" href="/agent-bar.css">
8377
8377
  <link rel="stylesheet" href="/agent-bar-app.css">
8378
+ <script src="/storage-sweep.js"></script>
8378
8379
  <script src="/agent-bar.js" data-agent-bar="true"></script>
8379
8380
  <script src="/agent-bar-app.js" data-agent-bar-app="true"></script>
8380
8381
  <link rel="stylesheet" href="/agent-bar-panel.css">
@@ -1497,6 +1497,7 @@ body.dark .ace-editor {
1497
1497
  <script src="/report.js"></script>
1498
1498
  <script src="/normalize.js"></script>
1499
1499
  <script src="/Socket.js"></script>
1500
+ <script src="/terminal-input.js"></script>
1500
1501
  <script src="/resizeSync.js"></script>
1501
1502
  <script src="/terminal-settings.js"></script>
1502
1503
  <script src="/pinokio-touch.js"></script>
@@ -2685,6 +2686,8 @@ const createTerm = async (_theme) => {
2685
2686
  })
2686
2687
  }
2687
2688
  });
2689
+ // input the terminal library does not send by itself (see terminal-input.js)
2690
+ window.PinokioTerminalInput.attach(term, () => socket, () => shell_id)
2688
2691
 
2689
2692
  let observer = new ResizeObserver(() => {
2690
2693
  fitAddon.fit()
@@ -500,6 +500,7 @@ body.install-page #terminal .xterm {
500
500
  <script src="/xterm-addon-web-links.js"></script>
501
501
  <script src="/xterm-theme.js"></script>
502
502
  <script src="/Socket.js"></script>
503
+ <script src="/terminal-input.js"></script>
503
504
  <script src="/terminal-settings.js"></script>
504
505
  <script src="/pinokio-touch.js"></script>
505
506
  <!--
@@ -846,6 +847,8 @@ document.addEventListener("DOMContentLoaded", async () => {
846
847
  })
847
848
  }
848
849
  })
850
+ // input the terminal library does not send by itself (see terminal-input.js)
851
+ window.PinokioTerminalInput.attach(term, () => socket, () => shell_id)
849
852
  let observer = new ResizeObserver(() => {
850
853
  fitAddon.fit()
851
854
  });
@@ -13,7 +13,7 @@
13
13
  --layout-dragger-bg: var(--layout-background);
14
14
  --layout-dragger-border: rgba(15, 23, 42, 0.06);
15
15
  --layout-shadow: rgba(0, 0, 0, 0.06);
16
- --layout-viewport-height: 100vh;
16
+ --layout-viewport-height: 100%;
17
17
  --layout-dragger-height: 0px;
18
18
  color-scheme: light dark;
19
19
  }
@@ -63,10 +63,17 @@
63
63
  color: #f3f3f3;
64
64
  }
65
65
 
66
+ /* The panes fill the part of the window that can be seen. That is the whole
67
+ window, except while a phone's on-screen keyboard is up: the keyboard
68
+ covers the bottom of the window without making it any smaller, and the
69
+ browser may also slide the page up under it. The script below measures the
70
+ part left visible (its height and where it starts). Using the height
71
+ without the start is what left an empty band above the keyboard. */
66
72
  #layout-root {
67
73
  position: relative;
74
+ top: var(--layout-viewport-top, 0px);
68
75
  width: 100%;
69
- height: calc(100% - var(--layout-dragger-height, 0px));
76
+ height: calc(var(--layout-viewport-height) - var(--layout-dragger-height, 0px));
70
77
  background: var(--layout-background);
71
78
  overflow: hidden;
72
79
  }
@@ -129,19 +136,37 @@
129
136
  (function () {
130
137
  const root = document.documentElement;
131
138
  let lastViewportHeight = null;
139
+ let lastViewportTop = null;
132
140
  const updateViewportHeight = () => {
133
141
  const viewport = window.visualViewport;
142
+ // Pinch-zoomed in: the visible part is then a magnified piece of the page,
143
+ // not what a keyboard leaves free. The panes fill the window, as they do
144
+ // with no measurement.
145
+ if (viewport && Math.abs(viewport.scale - 1) > 0.01) {
146
+ if (lastViewportHeight !== null) {
147
+ lastViewportHeight = null;
148
+ root.style.removeProperty('--layout-viewport-height');
149
+ root.style.removeProperty('--layout-viewport-top');
150
+ window.dispatchEvent(new CustomEvent('pinokio:viewport-change'));
151
+ }
152
+ return;
153
+ }
134
154
  const height = viewport ? viewport.height : window.innerHeight;
135
155
  if (!height || !Number.isFinite(height)) {
136
156
  return;
137
157
  }
158
+ // where the visible part starts, in the page's own coordinates
159
+ const top = viewport ? viewport.pageTop : 0;
138
160
  const clampedHeight = Math.max(0, height);
139
161
  const roundedHeight = Number(clampedHeight.toFixed(2));
140
- if (lastViewportHeight === roundedHeight) {
162
+ const roundedTop = Number(Math.max(0, top || 0).toFixed(2));
163
+ if (lastViewportHeight === roundedHeight && lastViewportTop === roundedTop) {
141
164
  return;
142
165
  }
143
166
  lastViewportHeight = roundedHeight;
167
+ lastViewportTop = roundedTop;
144
168
  root.style.setProperty('--layout-viewport-height', `${roundedHeight}px`);
169
+ root.style.setProperty('--layout-viewport-top', `${roundedTop}px`);
145
170
  window.dispatchEvent(new CustomEvent('pinokio:viewport-change', {
146
171
  detail: { height: roundedHeight },
147
172
  }));
@@ -181,5 +206,6 @@
181
206
  <script src="/Socket.js"></script>
182
207
  <script src="/common.js"></script>
183
208
  <script src="/layout.js"></script>
209
+ <script src="/storage-sweep.js"></script>
184
210
  </body>
185
211
  </html>
@@ -2,6 +2,7 @@
2
2
  const sidebarSelected = (typeof selected !== "undefined" && selected) ? String(selected) : "";
3
3
  %>
4
4
  <link rel="stylesheet" href="/agent-bar.css">
5
+ <script src="/storage-sweep.js"></script>
5
6
  <script src="/agent-bar.js" data-agent-bar="true"></script>
6
7
  <link rel="stylesheet" href="/agent-bar-panel.css">
7
8
  <script src="/agent-bar-panel.js" data-agent-bar-panel="true"></script>
@@ -14,6 +14,7 @@
14
14
  <script src="/xterm-addon-search-bar.js"></script>
15
15
  <script src="/sweetalert2.js"></script>
16
16
  <script src="/Socket.js"></script>
17
+ <script src="/terminal-input.js"></script>
17
18
  <script src="/resizeSync.js"></script>
18
19
  <script src="/terminal-settings.js"></script>
19
20
  <script src="/pinokio-touch.js"></script>
@@ -287,6 +288,8 @@ const createTerm = async (_theme) => {
287
288
  })
288
289
  }
289
290
  });
291
+ // input the terminal library does not send by itself (see terminal-input.js)
292
+ window.PinokioTerminalInput.attach(term, () => socket, () => shell_id)
290
293
 
291
294
  let observer = new ResizeObserver(() => {
292
295
  fitAddon.fit()
@@ -981,6 +981,7 @@ body.dark .appcanvas {
981
981
  <script src="/report.js"></script>
982
982
  <script src="/normalize.js"></script>
983
983
  <script src="/Socket.js"></script>
984
+ <script src="/terminal-input.js"></script>
984
985
  <script src="/resizeSync.js"></script>
985
986
  <script src="/terminal-settings.js"></script>
986
987
  <script src="/pinokio-touch.js"></script>
@@ -1619,6 +1620,8 @@ async function displayResults(config) {
1619
1620
  })
1620
1621
  }
1621
1622
  });
1623
+ // input the terminal library does not send by itself (see terminal-input.js)
1624
+ window.PinokioTerminalInput.attach(term, () => socket, () => shell_id)
1622
1625
  const fitAddon = new FitAddon.FitAddon();
1623
1626
  term.loadAddon(fitAddon);
1624
1627
  fitAddon.fit();
@@ -14,6 +14,7 @@
14
14
  <script src="/xterm-addon-search-bar.js"></script>
15
15
  <script src="/sweetalert2.js"></script>
16
16
  <script src="/Socket.js"></script>
17
+ <script src="/terminal-input.js"></script>
17
18
  <script src="/resizeSync.js"></script>
18
19
  <script src="/terminal_input_tracker.js"></script>
19
20
  <script src="/terminal_input_utils.js"></script>
@@ -1763,6 +1764,8 @@ document.addEventListener("DOMContentLoaded", async () => {
1763
1764
  this.captureTextInput(data)
1764
1765
  }
1765
1766
  })
1767
+ // input the terminal library does not send by itself (see terminal-input.js)
1768
+ window.PinokioTerminalInput.attach(term, () => this.socket, () => shell_id)
1766
1769
 
1767
1770
  const fitAddon = new FitAddon.FitAddon();
1768
1771
  // const searchAddon = new SearchAddon.SearchAddon();
@@ -14,6 +14,7 @@
14
14
  <script src="/xterm-addon-search-bar.js"></script>
15
15
  <script src="/sweetalert2.js"></script>
16
16
  <script src="/Socket.js"></script>
17
+ <script src="/terminal-input.js"></script>
17
18
  <script src="/resizeSync.js"></script>
18
19
  <script src="/terminal_input_tracker.js"></script>
19
20
  <script src="/terminal_input_utils.js"></script>
@@ -3219,6 +3220,8 @@ document.addEventListener("DOMContentLoaded", async () => {
3219
3220
  this.captureTextInput(data)
3220
3221
  }
3221
3222
  })
3223
+ // input the terminal library does not send by itself (see terminal-input.js)
3224
+ window.PinokioTerminalInput.attach(term, () => this.socket, () => shell_id)
3222
3225
 
3223
3226
  const fitAddon = new FitAddon.FitAddon();
3224
3227
  // const searchAddon = new SearchAddon.SearchAddon();
@@ -48,6 +48,10 @@ const ask = (brain, body = {}) => new Promise((resolve) => {
48
48
  brain.handleAsk({ body: { prompt: "p", tool: "claude", ...body } }, res)
49
49
  })
50
50
  const query = (answer) => new URL(answer.url, "http://x").searchParams
51
+ // spec/requirements/request-files.md: the agent gets this line, the request is in the file
52
+ const requestPath = (id) => `.pinokio-temp/requests/${id}.md`
53
+ const requestLine = (id) => `My message is in ${requestPath(id)}. Read it and respond as if I had typed it here.`
54
+ const requestIn = (dir, id) => fs.readFileSync(path.join(dir, ".pinokio-temp", "requests", `${id}.md`), "utf8")
51
55
  const seen = async (kernel, name) => (await Brain.addSkills(kernel, [{ app_id: name }]))[0]
52
56
  const logLines = (dir) => fs.readFileSync(path.join(dir, "me", "log.md"), "utf8").trim().split("\n")
53
57
  const tree = (dir) => fs.readdirSync(dir).sort().join(" ")
@@ -71,14 +75,16 @@ test("a top-bar Ask starts in the brain with the request and a log line", async
71
75
  assert.equal(query(a).get("cwd"), t.dir)
72
76
  assert.equal(query(a).get("chrome"), "full")
73
77
  assert.match(id, /^\d{8}-[a-f0-9]{8}$/)
74
- assert.equal(query(a).get("prompt"), `say hello\n\nOutput folder: me/files/${id}/`)
75
- assert.equal(tree(t.dir), "AGENTS.md CLAUDE.md GEMINI.md me")
78
+ assert.equal(query(a).get("prompt"), requestLine(id), "the agent is started with the request line, not the request")
79
+ assert.equal(requestIn(t.dir, id), `say hello\n\nOutput folder: me/files/${id}/\n`)
80
+ assert.equal(tree(t.dir), ".pinokio-temp AGENTS.md CLAUDE.md GEMINI.md me")
76
81
  assert.equal(tree(path.join(t.dir, "me")), "files log.md")
77
82
  assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id)), false, "the output folder is named, not created")
78
83
  assert.match(logLines(t.dir)[0], new RegExp(`^- \\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d \\| ${id} \\| claude \\| say hello$`))
79
84
 
80
85
  const empty = await ask(t.brain, { prompt: "" })
81
86
  assert.equal(query(empty).get("prompt"), null)
87
+ assert.equal(tree(path.join(t.dir, ".pinokio-temp", "requests")), `${id}.md`, "an empty request has no file")
82
88
  })
83
89
  })
84
90
 
@@ -86,17 +92,34 @@ test("attached files are copied into the Ask's folder and named in the request",
86
92
  await withHome({ copyUploads: async (token, dir) => { fs.writeFileSync(path.join(dir, "a.jpg"), "x"); return ["a.jpg"] } }, async (t) => {
87
93
  const a = await ask(t.brain, { prompt: "crop", uploadToken: "a".repeat(32) })
88
94
  const id = query(a).get("session")
89
- assert.equal(query(a).get("prompt"), `crop\n\nAttached files:\n- me/files/${id}/a.jpg\n\nOutput folder: me/files/${id}/`)
95
+ assert.equal(query(a).get("prompt"), requestLine(id))
96
+ assert.equal(requestIn(t.dir, id), `crop\n\nAttached files:\n- me/files/${id}/a.jpg\n\nOutput folder: me/files/${id}/\n`)
90
97
  assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id, "a.jpg")), true)
91
98
  })
92
99
  await withHome({}, async (t) => {
93
100
  const a = await ask(t.brain, { prompt: "nothing copied", uploadToken: "a".repeat(32) })
94
101
  assert.equal(fs.existsSync(path.join(t.dir, "me", "files", query(a).get("session"))), false)
95
- assert.equal(query(a).get("prompt").includes("Attached files"), false)
102
+ assert.equal(requestIn(t.dir, query(a).get("session")).includes("Attached files"), false)
96
103
  })
97
104
  })
98
105
 
99
- test("only an unknown tool, the brain folder or a failed copy can stop a top-bar Ask", async () => {
106
+ test("an Ask whose request file cannot be written is not sent", async () => {
107
+ await withHome({}, async (t) => {
108
+ fs.mkdirSync(t.dir, { recursive: true })
109
+ fs.writeFileSync(path.join(t.dir, ".pinokio-temp"), "not a folder")
110
+ const a = await ask(t.brain)
111
+ assert.deepEqual([a.code, a.ok, "url" in a], [500, false, false])
112
+
113
+ const app = path.join(t.api, "Thing")
114
+ fs.mkdirSync(app, { recursive: true })
115
+ fs.writeFileSync(path.join(app, ".pinokio-temp"), "not a folder")
116
+ const b = await ask(t.brain, { app: "Thing" })
117
+ assert.deepEqual([b.code, b.ok, "prompt" in b], [500, false, false])
118
+ assert.equal(fs.existsSync(path.join(t.dir, "me", "log.md")), false, "an Ask that was not sent is not logged")
119
+ })
120
+ })
121
+
122
+ test("only an unknown tool, the brain folder, a failed copy or the request file can stop a top-bar Ask", async () => {
100
123
  await withHome({ pluginHref: () => { throw Object.assign(new Error("No such plugin."), { status: 400 }) } }, async (t) => {
101
124
  const a = await ask(t.brain)
102
125
  assert.deepEqual([a.code, a.ok, a.error], [400, false, "No such plugin."])
@@ -230,21 +253,42 @@ test("the version covers the app's folder and the code repositories it keeps", a
230
253
  })
231
254
  })
232
255
 
233
- test("an app-page Ask gets back only what the page adds to the request", async () => {
256
+ test("an app-page Ask writes the request into the app's folder and gets back the request line", async () => {
234
257
  await withHome({}, async (t) => {
235
258
  const app = path.join(t.api, "Plain")
236
259
  const version = await commit(app, "pinokio.js", "1")
237
260
  skill(app, "older")
238
261
  const a = await ask(t.brain, { app: "Plain", prompt: "say hi" })
239
262
  const id = logLines(t.dir)[0].split(" | ")[1]
240
- assert.deepEqual(Object.keys(a).sort(), ["append", "code", "ok"])
241
- assert.equal(a.append, `Pinokio brain:\n- This app's skill (skill_dir): ${path.join(app, ".pinokio-skill")} (skill_state: check, app_version: ${version})\n- Output folder: ${path.join(t.dir, "me", "files", id)}`)
263
+ const brainLines = (appDir, state, outputId) => `Pinokio brain:\n- This app's skill (skill_dir): ${path.join(appDir, ".pinokio-skill")} (skill_state: ${state})\n- Output folder: ${path.join(t.dir, "me", "files", outputId)}`
264
+ assert.deepEqual(Object.keys(a).sort(), ["code", "ok", "prompt"])
265
+ assert.equal(a.prompt, requestLine(id))
266
+ assert.equal(requestIn(app, id), `say hi\n\n${brainLines(app, `check, app_version: ${version}`, id)}\n`)
242
267
  assert.match(logLines(t.dir)[0], new RegExp(`\\| ${id} \\| claude in Plain \\| say hi$`))
243
268
  assert.equal(tree(t.dir), "me", "the instruction files are not written")
244
269
 
245
270
  fs.mkdirSync(path.join(t.api, "NoGit"))
246
- const plain = await ask(t.brain, { app: "NoGit", prompt: "x" })
247
- assert.ok(plain.append.includes("(skill_state: none)\n"), "no version, so none is named")
271
+ const noGit = path.join(t.api, "NoGit")
272
+ await ask(t.brain, { app: "NoGit", prompt: "x" })
273
+ const plainId = logLines(t.dir)[1].split(" | ")[1]
274
+ assert.ok(requestIn(noGit, plainId).includes("(skill_state: none)\n"), "no version, so none is named")
275
+
276
+ // files the page uploaded for this app are named in the request; with no words they are still a request
277
+ const upload = path.join(noGit, ".pinokio-temp", "uploads", "t", "a.png")
278
+ await ask(t.brain, { app: "NoGit", prompt: "", files: [upload] })
279
+ const fileId = logLines(t.dir)[2].split(" | ")[1]
280
+ assert.equal(requestIn(noGit, fileId), `Attached files:\n- ${upload}\n\n${brainLines(noGit, "none", fileId)}\n`)
281
+
282
+ // anything else is refused and nothing is written
283
+ const before = tree(path.join(noGit, ".pinokio-temp", "requests"))
284
+ for (const files of [[path.join(noGit, "pinokio.js")], [path.join(noGit, ".pinokio-temp", "uploads")], [path.join(noGit, ".pinokio-temp", "uploads", "..", "..", "x")], [path.join(t.api, "Plain", ".pinokio-temp", "uploads", "t", "a.png")], [7]]) {
285
+ const refused = await ask(t.brain, { app: "NoGit", prompt: "x", files })
286
+ assert.deepEqual([refused.code, refused.ok], [400, false], JSON.stringify(files))
287
+ }
288
+ const emptyAsk = await ask(t.brain, { app: "NoGit", prompt: "", files: [] })
289
+ assert.deepEqual([emptyAsk.code, emptyAsk.ok], [400, false], "an empty request is not an Ask")
290
+ assert.equal(tree(path.join(noGit, ".pinokio-temp", "requests")), before)
291
+ assert.equal(logLines(t.dir).length, 3)
248
292
  })
249
293
  await withHome({}, async (t) => {
250
294
  fs.mkdirSync(path.join(t.api, "Thing"), { recursive: true })
@@ -0,0 +1,125 @@
1
+ // The layout shell (server/views/layout.ejs, the page at "/") and a phone's
2
+ // on-screen keyboard.
3
+ //
4
+ // A keyboard covers the bottom of the window without making the window smaller,
5
+ // and the browser may slide the page up under it. The shell measures the part
6
+ // left visible (window.visualViewport) and its panes must fill exactly that
7
+ // part, so a terminal's last rows (an agent's input line) stay above the keyboard.
8
+ //
9
+ // History this guards: the measurement was added in Nov 2025 using the height
10
+ // only, which left an empty band above the keyboard when the page had slid up;
11
+ // the fix for the band stopped using the measurement at all, so the bottom of
12
+ // every pane was hidden under the keyboard again.
13
+ const assert = require('node:assert/strict')
14
+ const fs = require('node:fs')
15
+ const path = require('node:path')
16
+ const test = require('node:test')
17
+ const ejs = require('ejs')
18
+ const { JSDOM } = require('jsdom')
19
+
20
+ const filename = path.resolve(__dirname, '../server/views/layout.ejs')
21
+ const template = fs.readFileSync(filename, 'utf8')
22
+
23
+ // a phone window with no keyboard up
24
+ function fullWindow() {
25
+ return { height: 812, offsetTop: 0, pageTop: 0, scale: 1, addEventListener() {} }
26
+ }
27
+
28
+ function shell(t, viewport) {
29
+ const html = ejs.render(template, {
30
+ theme: 'dark',
31
+ agent: 'browser',
32
+ platform: 'darwin',
33
+ initialPath: '/home',
34
+ defaultPath: '/home',
35
+ sessionId: null
36
+ }, { filename })
37
+ const frames = []
38
+ const changes = []
39
+ const dom = new JSDOM(html, {
40
+ url: 'http://127.0.0.1:42000/',
41
+ // inline scripts only: Socket.js, common.js and layout.js are not loaded
42
+ runScripts: 'dangerously',
43
+ beforeParse(window) {
44
+ window.requestAnimationFrame = (callback) => frames.push(callback)
45
+ window.visualViewport = viewport
46
+ window.addEventListener('pinokio:viewport-change', (event) => changes.push(event.detail))
47
+ }
48
+ })
49
+ t.after(() => dom.window.close())
50
+ const { window } = dom
51
+ const style = window.document.documentElement.style
52
+ return {
53
+ window,
54
+ changes,
55
+ // what the browser does when the keyboard moves: an event, then a frame
56
+ resize() {
57
+ window.dispatchEvent(new window.Event('resize'))
58
+ frames.splice(0).forEach((callback) => callback())
59
+ },
60
+ measured: () => ({
61
+ height: style.getPropertyValue('--layout-viewport-height'),
62
+ top: style.getPropertyValue('--layout-viewport-top')
63
+ })
64
+ }
65
+ }
66
+
67
+ test('the panes are sized and placed by the measured visible part of the window', () => {
68
+ const css = template.slice(template.indexOf('#layout-root {'), template.indexOf('}', template.indexOf('#layout-root {')))
69
+ assert.match(css, /height:\s*calc\(var\(--layout-viewport-height\)/)
70
+ assert.match(css, /top:\s*var\(--layout-viewport-top/)
71
+ })
72
+
73
+ test('with the keyboard up, the visible part is what is left above it', (t) => {
74
+ const viewport = fullWindow()
75
+ const page = shell(t, viewport)
76
+ assert.deepEqual(page.measured(), { height: '812px', top: '0px' })
77
+
78
+ viewport.height = 470
79
+ page.resize()
80
+ assert.deepEqual(page.measured(), { height: '470px', top: '0px' })
81
+ assert.equal(page.changes.at(-1).height, 470)
82
+
83
+ viewport.height = 812
84
+ page.resize()
85
+ assert.deepEqual(page.measured(), { height: '812px', top: '0px' })
86
+ })
87
+
88
+ test('when the browser slides the page up under the keyboard, the panes follow', (t) => {
89
+ const viewport = fullWindow()
90
+ const page = shell(t, viewport)
91
+ Object.assign(viewport, { height: 470, offsetTop: 120, pageTop: 120 })
92
+ page.resize()
93
+ assert.deepEqual(page.measured(), { height: '470px', top: '120px' })
94
+
95
+ // only the position changes: still followed
96
+ Object.assign(viewport, { offsetTop: 40, pageTop: 40 })
97
+ page.resize()
98
+ assert.deepEqual(page.measured(), { height: '470px', top: '40px' })
99
+ })
100
+
101
+ test('pinch zoom is not mistaken for a keyboard', (t) => {
102
+ const viewport = fullWindow()
103
+ const page = shell(t, viewport)
104
+ Object.assign(viewport, { height: 470, offsetTop: 120, pageTop: 120 })
105
+ page.resize()
106
+ assert.deepEqual(page.measured(), { height: '470px', top: '120px' })
107
+
108
+ // zoomed in: no measurement, so the panes fill the window as the stylesheet says
109
+ Object.assign(viewport, { height: 235, offsetTop: 300, pageTop: 300, scale: 2 })
110
+ page.resize()
111
+ assert.deepEqual(page.measured(), { height: '', top: '' })
112
+ const changes = page.changes.length
113
+ page.resize()
114
+ assert.equal(page.changes.length, changes)
115
+
116
+ // zoomed back out: measured again
117
+ Object.assign(viewport, { height: 470, offsetTop: 120, pageTop: 120, scale: 1 })
118
+ page.resize()
119
+ assert.deepEqual(page.measured(), { height: '470px', top: '120px' })
120
+ })
121
+
122
+ test('without a visual viewport the window height is used', (t) => {
123
+ const page = shell(t, undefined)
124
+ assert.deepEqual(page.measured(), { height: `${page.window.innerHeight}px`, top: '0px' })
125
+ })
@@ -448,6 +448,7 @@ test("successful runtime cleanup resubmits the interrupted install", async (t) =
448
448
  window.WebLinksAddon = { WebLinksAddon: class {} }
449
449
  window.xtermTheme = { FrontEndDelight: {} }
450
450
  window.PinokioTouch = { bindTerminalFocus() {} }
451
+ window.PinokioTerminalInput = { attach() {} }
451
452
  window.PinokioPathRemoval = {
452
453
  show: async ({ retry }) => await retry(),
453
454
  tryRemove: async (payload) => {
@@ -522,6 +523,7 @@ test("fresh install shows removal status and waits for cleanup before starting",
522
523
  window.WebLinksAddon = { WebLinksAddon: class {} }
523
524
  window.xtermTheme = { FrontEndDelight: {} }
524
525
  window.PinokioTouch = { bindTerminalFocus() {} }
526
+ window.PinokioTerminalInput = { attach() {} }
525
527
  window.PinokioPathRemoval = {
526
528
  remove: async () => {
527
529
  cleanupStarted = true