pinokiod 8.3.12 → 8.3.14

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.
Files changed (53) hide show
  1. package/kernel/agent_instructions.js +0 -1
  2. package/kernel/api/index.js +76 -12
  3. package/kernel/environment.js +1 -1
  4. package/kernel/index.js +15 -2
  5. package/kernel/plugin_sources.js +1 -1
  6. package/kernel/prototype.js +1 -1
  7. package/kernel/request_file.js +5 -14
  8. package/kernel/shell.js +12 -0
  9. package/kernel/shells.js +13 -1
  10. package/package.json +1 -1
  11. package/server/index.js +10 -5
  12. package/server/lib/agent_jobs.js +198 -0
  13. package/server/lib/agent_sessions.js +131 -0
  14. package/server/lib/brain.js +161 -91
  15. package/server/lib/content_validation.js +1 -1
  16. package/server/public/agent-bar-app.js +28 -6
  17. package/server/public/agent-bar-compose.css +675 -0
  18. package/server/public/agent-bar-compose.js +618 -0
  19. package/server/public/agent-bar-panel.css +2 -0
  20. package/server/public/agent-bar-panel.js +22 -7
  21. package/server/public/agent-bar-shell.css +38 -0
  22. package/server/public/agent-bar-shell.js +128 -34
  23. package/server/public/agent-bar.css +7 -1
  24. package/server/public/agent-bar.js +8 -1
  25. package/server/public/terminal_input_utils.js +9 -1
  26. package/server/views/app.ejs +5 -1
  27. package/server/views/partials/main_sidebar.ejs +2 -0
  28. package/system/plugin/antigravity-cli-auto/pinokio.js +44 -6
  29. package/system/plugin/claude/pinokio.js +43 -1
  30. package/system/plugin/claude-auto/pinokio.js +43 -1
  31. package/system/plugin/codex/pinokio.js +42 -1
  32. package/system/plugin/codex-auto/pinokio.js +42 -1
  33. package/system/plugin/grok/pinokio.js +1 -1
  34. package/system/plugin/grok-auto/pinokio.js +37 -10
  35. package/system/plugin/opencode/pinokio.js +24 -0
  36. package/system/plugin/opencode-auto/pinokio.js +82 -10
  37. package/test/agent-bar-compose.test.js +487 -0
  38. package/test/agent-bar-shell.test.js +149 -0
  39. package/test/agent-instructions.test.js +0 -2
  40. package/test/agent-jobs.test.js +534 -0
  41. package/test/agent-sessions.test.js +130 -0
  42. package/test/antigravity-cli-plugin.test.js +63 -18
  43. package/test/anywhere-api.test.js +1 -1
  44. package/test/anywhere-onboarding.test.js +1 -2
  45. package/test/brain.test.js +116 -69
  46. package/test/grok-plugin.test.js +2 -1
  47. package/test/opencode-plugin.test.js +7 -4
  48. package/test/plugin-action-functions.test.js +423 -0
  49. package/test/request-file.test.js +1 -12
  50. package/test/shell-log-path.test.js +64 -0
  51. package/test/shell-stop-while-starting.test.js +70 -0
  52. package/test/shells-live-error.test.js +66 -2
  53. package/test/terminal-mouse-input.test.js +27 -0
@@ -0,0 +1,487 @@
1
+ // The agent bar's compose view (server/public/agent-bar-compose.js): when it
2
+ // opens and closes,
3
+ // which shape it takes, what the keys do, and that the text area is never moved.
4
+ //
5
+ // The real agent-bar.js and agent-bar-compose.js run here in a page that has
6
+ // only a top bar. Sizes and motion are not covered: this page has no layout.
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 publicDir = path.resolve(__dirname, '../server/public')
14
+ const barScript = fs.readFileSync(path.join(publicDir, 'agent-bar.js'), 'utf8')
15
+ const appScript = fs.readFileSync(path.join(publicDir, 'agent-bar-app.js'), 'utf8')
16
+ const composeScript = fs.readFileSync(path.join(publicDir, 'agent-bar-compose.js'), 'utf8')
17
+
18
+ const PHONE = '(max-width: 768px)'
19
+ const TOUCH = '(pointer: coarse)'
20
+ // an app page's own phone layout starts wider than the home bar's
21
+ const APP_PHONE = '(max-width: 980px)'
22
+
23
+ const HOME_PAGE = '<!doctype html><body><header class="navheader"><h1><div class="flexible"></div></h1></header><main id="page"></main></body>'
24
+ // what agent-bar-app.js needs of an app's page: the app's name in the top bar,
25
+ // the sidebar its card moves to, the Ask AI button (Run mode, the app's folder)
26
+ // and the strip that holds the bar in the phone layout
27
+ const APP_PAGE = '<!doctype html><body class="app-page"><header class="navheader"><h1>'
28
+ + '<div class="app-header-identity"><span class="app-header-identity-title">Demo App</span></div>'
29
+ + '<button id="ask-ai-tab" data-workspace-cwd="/home/api/demo"></button><div class="flexible"></div></h1></header>'
30
+ + '<div class="appcanvas"><aside id="app-sidebar"><div class="menu-scroller"></div></aside><main id="page"></main>'
31
+ + '<div class="mobile-bottom-nav"><div class="mobile-bottom-nav__identity"></div></div></div></body>'
32
+
33
+ async function page(t, options = {}) {
34
+ const media = new Set(options.media || [])
35
+ const posts = []
36
+ const dom = new JSDOM(options.app ? APP_PAGE : HOME_PAGE, {
37
+ url: `http://127.0.0.1:42000/${options.app ? 'p/demo' : 'home'}${options.search || ''}`,
38
+ runScripts: 'outside-only',
39
+ pretendToBeVisual: true,
40
+ beforeParse(window) {
41
+ window.matchMedia = (query) => ({ matches: media.has(query), addEventListener() {}, removeEventListener() {} })
42
+ // This page lays nothing out. The bar only checks that it is on screen; the
43
+ // compose view reads how tall the text's row is (a phone's free space).
44
+ const height = options.rowHeight || 600
45
+ window.Element.prototype.getBoundingClientRect = function () {
46
+ return { left: 300, top: 8, right: 900, bottom: 8 + height, width: 600, height, x: 300, y: 8 }
47
+ }
48
+ window.fetch = async (url, init) => {
49
+ if (init && init.method === 'POST') posts.push(String(url))
50
+ if (String(url) === '/info/shells') return { ok: true, json: async () => (options.shells ? options.shells() : []) }
51
+ if (String(url).split('?')[0] === '/api/plugin/menu') {
52
+ return { ok: true, json: async () => ({ menu: [{ href: '/run/plugin/codex/pinokio.js', title: 'Codex', default: true }] }) }
53
+ }
54
+ if (String(url) === '/pinokio/install/exists') return { ok: true, json: async () => ({ exists: false }) }
55
+ // a send that goes through hands its session to whatever shows sessions
56
+ if (options.sends) return { ok: true, json: async () => ({ ok: true, url: '/run/plugin/codex/pinokio.js?cwd=/x', prompt: 'My message is in a file.' }) }
57
+ // otherwise a send is answered with an error, so nothing leaves the page
58
+ return { ok: false, json: async () => ({ ok: false, error: 'not sent in this test' }) }
59
+ }
60
+ }
61
+ })
62
+ t.after(() => dom.window.close())
63
+ const { window } = dom
64
+ window.eval(barScript)
65
+ if (options.app) window.eval(appScript)
66
+ window.eval(composeScript)
67
+ // the dock takes a session that was started (agent-bar-panel.js)
68
+ window.PinokioAgentBar.deliver = () => true
69
+ window.PinokioAgentDock = { openWithAgent: () => true, openWithUrl: () => true, isOpen: () => false, openUrls: () => [] }
70
+ await window.PinokioAgentBar.ready
71
+ await settle(window)
72
+ const { document } = window
73
+ const root = document.querySelector('.agent-bar')
74
+ const input = root.querySelector('.agent-bar__input')
75
+ const key = (target, init) => {
76
+ const event = new window.KeyboardEvent('keydown', { bubbles: true, cancelable: true, ...init })
77
+ target.dispatchEvent(event)
78
+ return event
79
+ }
80
+ return {
81
+ window,
82
+ document,
83
+ root,
84
+ input,
85
+ posts,
86
+ media,
87
+ top: root.querySelector('.agent-bar__top'),
88
+ controls: root.querySelector('.agent-compose__controls'),
89
+ face: root.querySelector('.agent-compose__face'),
90
+ shape: () => root.dataset.compose || '',
91
+ key,
92
+ async focus(target = input) {
93
+ target.focus()
94
+ await settle(window)
95
+ },
96
+ async type(text) {
97
+ input.value = text
98
+ input.dispatchEvent(new window.Event('input', { bubbles: true }))
99
+ await settle(window)
100
+ },
101
+ async mode(index) {
102
+ root.querySelector('.agent-bar__scope').click()
103
+ await settle(window)
104
+ root.querySelectorAll('.agent-bar__menu .agent-bar__row')[index].click()
105
+ await settle(window)
106
+ },
107
+ async escape() {
108
+ key(input, { key: 'Escape' })
109
+ await settle(window)
110
+ }
111
+ }
112
+ }
113
+
114
+ // the bar draws itself, then the compose view follows in a microtask
115
+ async function settle(window) {
116
+ for (let i = 0; i < 4; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
117
+ }
118
+
119
+ const classes = (parent) => Array.from(parent.children).map((node) => node.className.split(' ')[0])
120
+
121
+ test('at rest the bar is as before, with the face in the mode chip', async (t) => {
122
+ const p = await page(t)
123
+ assert.equal(p.shape(), '')
124
+ assert.ok(p.root.classList.contains('agent-compose'))
125
+ assert.ok(p.face.closest('.agent-bar__scope'), 'the face is in the mode chip')
126
+ assert.deepEqual(classes(p.top).filter((name) => name.startsWith('agent-bar__')), ['agent-bar__scope', 'agent-bar__input', 'agent-bar__agent', 'agent-bar__go'])
127
+ assert.equal(p.input.placeholder, 'Ask Pinokio anything…')
128
+ })
129
+
130
+ test('going to the input opens the box in place and never moves the text area', async (t) => {
131
+ const p = await page(t)
132
+ const parentBefore = p.input.parentNode
133
+ await p.focus()
134
+ assert.equal(p.shape(), 'place')
135
+ assert.equal(p.input.parentNode, parentBefore, 'the text area stays where it is in the page')
136
+ assert.equal(p.document.activeElement, p.input)
137
+ // mode at the left of the controls row; agent and send at its right
138
+ assert.deepEqual(classes(p.controls), ['agent-bar__scope', 'agent-compose__grow', 'agent-bar__agent', 'agent-bar__go'])
139
+ assert.ok(p.face.closest('.agent-compose__slot--side'), 'the face sits beside the text')
140
+ // the greeting is the placeholder while the face is small
141
+ assert.equal(p.input.placeholder, 'What should we do?')
142
+ assert.equal(p.root.querySelector('.agent-compose__agent-name').textContent, 'Codex')
143
+ })
144
+
145
+ test('Escape closes it, keeps what was typed and puts the buttons back in order', async (t) => {
146
+ const p = await page(t)
147
+ await p.focus()
148
+ await p.type('a draft')
149
+ await p.escape()
150
+ assert.equal(p.shape(), '')
151
+ assert.equal(p.input.value, 'a draft')
152
+ assert.deepEqual(classes(p.top).filter((name) => name.startsWith('agent-bar__')), ['agent-bar__scope', 'agent-bar__input', 'agent-bar__agent', 'agent-bar__go'])
153
+ assert.ok(p.face.closest('.agent-bar__scope'))
154
+ assert.equal(p.input.placeholder, 'Ask Pinokio anything…')
155
+ })
156
+
157
+ test('a click outside closes it', async (t) => {
158
+ const p = await page(t)
159
+ await p.focus()
160
+ p.document.getElementById('page').dispatchEvent(new p.window.Event('pointerdown', { bubbles: true }))
161
+ await settle(p.window)
162
+ assert.equal(p.shape(), '')
163
+ })
164
+
165
+ test('a press on the text puts an open menu away and keeps the view; a press in the menu does not', async (t) => {
166
+ const p = await page(t, { media: [PHONE, TOUCH] })
167
+ await p.focus()
168
+ const menu = p.root.querySelector('.agent-bar__menu:not(.agent-bar__menu--running)')
169
+ const press = (target) => target.dispatchEvent(new p.window.Event('pointerdown', { bubbles: true }))
170
+ p.root.querySelector('.agent-bar__agent').click()
171
+ await settle(p.window)
172
+ assert.equal(menu.hidden, false)
173
+ press(menu.querySelector('.agent-bar__row'))
174
+ await settle(p.window)
175
+ assert.equal(menu.hidden, false, 'a press on a row leaves the menu for the click that picks it')
176
+ press(p.input)
177
+ await settle(p.window)
178
+ assert.equal(menu.hidden, true)
179
+ assert.equal(p.shape(), 'screen', 'the view stays open')
180
+ })
181
+
182
+ test('each mode has its greeting; Download keeps its example link', async (t) => {
183
+ const p = await page(t)
184
+ await p.focus()
185
+ await p.mode(1)
186
+ assert.equal(p.input.placeholder, 'What should this app do?')
187
+ await p.mode(2)
188
+ assert.equal(p.input.placeholder, 'What should this plugin do?')
189
+ assert.equal(p.input.value, 'A Pinokio plugin for: ')
190
+ await p.mode(3)
191
+ assert.equal(p.input.placeholder, 'https://github.com/owner/repo')
192
+ assert.equal(p.shape(), 'place')
193
+ })
194
+
195
+ test('a pre-filled link opens the centred box; a button on the page opens it in place', async (t) => {
196
+ const p = await page(t, { search: '?universal&type=ask&prompt=hello' })
197
+ // what common.js does with the link
198
+ assert.equal(p.window.PinokioAgentBar.open({ type: 'ask', prompt: 'hello there' }), true)
199
+ await settle(p.window)
200
+ assert.equal(p.shape(), 'centre')
201
+ assert.equal(p.input.value, 'hello there')
202
+ assert.equal(p.posts.filter((url) => url !== '/pinokio/install/exists').length, 0, 'nothing is sent by arriving')
203
+ assert.ok(p.face.closest('.agent-compose__slot--hero'))
204
+ assert.equal(p.root.querySelector('.agent-compose__greet').textContent, 'Ready when you are')
205
+ assert.equal(p.input.placeholder, '')
206
+
207
+ await p.escape()
208
+ assert.equal(p.shape(), '')
209
+ // a Create button on the page
210
+ assert.equal(p.window.PinokioAgentBar.open({ type: 'create_app' }), true)
211
+ await settle(p.window)
212
+ assert.equal(p.shape(), 'place')
213
+ assert.equal(p.root.dataset.item, 'create_app')
214
+ })
215
+
216
+ test('on a phone it is the full screen, with a close button and the back gesture', async (t) => {
217
+ const p = await page(t, { media: [PHONE, TOUCH] })
218
+ await p.focus()
219
+ assert.equal(p.shape(), 'screen')
220
+ assert.ok(p.document.documentElement.classList.contains('agent-compose-screen'))
221
+ assert.equal(p.window.history.state.agentCompose, true)
222
+ // nothing typed: the large face says the greeting; with text it is in the top row
223
+ assert.ok(p.face.closest('.agent-compose__slot--hero'))
224
+ assert.equal(p.input.placeholder, '')
225
+ assert.equal(p.root.querySelector('.agent-compose__greet').textContent, 'What should we do?')
226
+ await p.type('hi')
227
+ assert.ok(p.face.closest('.agent-compose__slot--top'))
228
+
229
+ p.root.querySelector('.agent-compose__x').click()
230
+ await settle(p.window)
231
+ assert.equal(p.shape(), '')
232
+ assert.equal(p.input.value, 'hi')
233
+ assert.ok(!p.document.documentElement.classList.contains('agent-compose-screen'))
234
+
235
+ // the back gesture
236
+ await p.focus()
237
+ assert.equal(p.shape(), 'screen')
238
+ p.window.dispatchEvent(new p.window.PopStateEvent('popstate', { state: null }))
239
+ await settle(p.window)
240
+ assert.equal(p.shape(), '')
241
+ })
242
+
243
+ test('on a phone the bar at rest is one button: the mark opens the view, not the mode menu', async (t) => {
244
+ const p = await page(t, { media: [PHONE, TOUCH] })
245
+ p.root.querySelector('.agent-bar__scope').click()
246
+ await settle(p.window)
247
+ assert.equal(p.shape(), 'screen')
248
+ assert.equal(p.document.activeElement, p.input)
249
+ assert.equal(p.root.querySelector('.agent-bar__menu').hidden, true)
250
+ // in the view the mode chip opens its menu as usual
251
+ p.root.querySelector('.agent-bar__scope').click()
252
+ await settle(p.window)
253
+ assert.equal(p.root.querySelector('.agent-bar__menu').hidden, false)
254
+ })
255
+
256
+ test('on desktop the mode chip at rest still opens its menu', async (t) => {
257
+ const p = await page(t)
258
+ p.root.querySelector('.agent-bar__scope').click()
259
+ await settle(p.window)
260
+ assert.equal(p.shape(), '')
261
+ assert.equal(p.root.querySelector('.agent-bar__menu').hidden, false)
262
+ })
263
+
264
+ test('the bar knows when a draft is left in a mode other than Ask', async (t) => {
265
+ const p = await page(t, { media: [PHONE, TOUCH] })
266
+ const draft = () => p.root.dataset.composeDraft
267
+ assert.equal(draft(), 'false')
268
+ await p.focus()
269
+ await p.type('just asking')
270
+ assert.equal(draft(), 'false', 'Ask is never named')
271
+ await p.mode(2)
272
+ await p.type('A Pinokio plugin for: ')
273
+ assert.equal(draft(), 'false', 'the starter text alone is not a draft')
274
+ await p.type('A Pinokio plugin for: resizing images')
275
+ assert.equal(draft(), 'true')
276
+ await p.mode(1)
277
+ await p.type('')
278
+ assert.equal(draft(), 'false')
279
+ const name = p.root.querySelector('#agent-bar-create-name')
280
+ name.value = 'my-app'
281
+ name.dispatchEvent(new p.window.Event('input', { bubbles: true }))
282
+ await settle(p.window)
283
+ assert.equal(draft(), 'true', 'a folder name alone is a draft')
284
+ p.root.querySelector('.agent-compose__x').click()
285
+ await settle(p.window)
286
+ assert.equal(p.shape(), '')
287
+ assert.equal(draft(), 'true')
288
+ })
289
+
290
+ test('on a phone with no room for the large face, it stays small and the greeting is the placeholder', async (t) => {
291
+ // what the on-screen keyboard and the folder rows can leave
292
+ const p = await page(t, { media: [PHONE, TOUCH], rowHeight: 120 })
293
+ await p.focus()
294
+ assert.equal(p.shape(), 'screen')
295
+ assert.ok(p.face.closest('.agent-compose__slot--top'))
296
+ assert.equal(p.input.placeholder, 'What should we do?')
297
+ assert.equal(p.root.dataset.composeRoomy, 'false')
298
+ })
299
+
300
+ test('with a keyboard, Enter sends and Shift+Enter adds a line', async (t) => {
301
+ const p = await page(t)
302
+ await p.focus()
303
+ await p.type('ask this')
304
+ assert.equal(p.key(p.input, { key: 'Enter', shiftKey: true }).defaultPrevented, false)
305
+ assert.equal(p.input.enterKeyHint, 'send')
306
+ assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, true)
307
+ await settle(p.window)
308
+ assert.ok(p.posts.includes('/brain/ask'))
309
+ // the send failed: the view stays open with everything typed
310
+ assert.equal(p.shape(), 'place')
311
+ assert.equal(p.input.value, 'ask this')
312
+ })
313
+
314
+ test('on a touch screen Return adds a line and only the send button sends', async (t) => {
315
+ const p = await page(t, { media: [PHONE, TOUCH] })
316
+ await p.focus()
317
+ await p.type('ask this')
318
+ assert.equal(p.input.enterKeyHint, 'enter')
319
+ assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, false, 'Return is left to add a line')
320
+ await settle(p.window)
321
+ assert.equal(p.posts.includes('/brain/ask'), false)
322
+ // Cmd/Ctrl+Enter still sends, for an attached keyboard
323
+ assert.equal(p.key(p.input, { key: 'Enter', metaKey: true }).defaultPrevented, true)
324
+ await settle(p.window)
325
+ assert.ok(p.posts.includes('/brain/ask'))
326
+ })
327
+
328
+ test('on a touch screen Return still sends from a link and from a folder name', async (t) => {
329
+ const p = await page(t, { media: [PHONE, TOUCH] })
330
+ await p.focus()
331
+ await p.mode(3)
332
+ assert.equal(p.input.enterKeyHint, 'go')
333
+ await p.type('https://github.com/owner/repo')
334
+ // handled by the bar: it sends, or goes to the folder name
335
+ assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, true)
336
+ const name = p.root.querySelector('#agent-bar-download-name')
337
+ assert.equal(name.enterKeyHint, 'go')
338
+ assert.equal(p.key(name, { key: 'Enter' }).defaultPrevented, true)
339
+ })
340
+
341
+ test('send on the bar at rest opens the view in a mode that has a folder name', async (t) => {
342
+ const p = await page(t)
343
+ await p.focus()
344
+ await p.mode(1)
345
+ await p.type('an app')
346
+ await p.escape()
347
+ assert.equal(p.shape(), '')
348
+ p.root.querySelector('.agent-bar__go').click()
349
+ await settle(p.window)
350
+ assert.equal(p.shape(), 'place')
351
+ assert.equal(p.document.activeElement, p.root.querySelector('#agent-bar-create-name'), 'the empty folder name is next')
352
+ })
353
+
354
+ test('send on the bar at rest in Ask does not open the view', async (t) => {
355
+ const p = await page(t, { sends: true })
356
+ p.root.querySelector('.agent-bar__go').click()
357
+ await settle(p.window)
358
+ assert.ok(p.posts.includes('/brain/ask'))
359
+ assert.equal(p.shape(), '')
360
+ })
361
+
362
+ test('a send that goes through closes the view and empties the bar', async (t) => {
363
+ const p = await page(t, { sends: true })
364
+ await p.focus()
365
+ await p.type('ask this')
366
+ p.key(p.input, { key: 'Enter' })
367
+ await settle(p.window)
368
+ assert.equal(p.shape(), '')
369
+ assert.equal(p.input.value, '')
370
+ })
371
+
372
+ test('opening a session from the running list closes the view and keeps the text', async (t) => {
373
+ const p = await page(t)
374
+ // the list agent-bar-panel.js adds
375
+ const list = p.document.createElement('div')
376
+ list.className = 'agent-bar__menu agent-bar__menu--running'
377
+ list.innerHTML = '<button type="button" class="agent-bar__row">a session</button>'
378
+ p.root.querySelector('.agent-bar__inner').appendChild(list)
379
+ await p.focus()
380
+ await p.type('still here')
381
+ list.querySelector('.agent-bar__row').click()
382
+ await settle(p.window)
383
+ assert.equal(p.shape(), '')
384
+ assert.equal(p.input.value, 'still here')
385
+ })
386
+
387
+ // ---- the bar on an app's page: Ask only, the same view ----
388
+
389
+ test('app page: going to the input opens the box in place, with no mode chip', async (t) => {
390
+ const p = await page(t, { app: true })
391
+ assert.equal(p.root.dataset.item, 'ask_app')
392
+ assert.ok(p.root.classList.contains('agent-compose'))
393
+ assert.ok(p.face.closest('.agent-bar__top'), 'at rest the face stands where the bar had its mark')
394
+ const parentBefore = p.input.parentNode
395
+ await p.focus()
396
+ assert.equal(p.shape(), 'place')
397
+ assert.equal(p.input.parentNode, parentBefore)
398
+ assert.deepEqual(classes(p.controls), ['agent-compose__grow', 'agent-bar__agent', 'agent-bar__go'])
399
+ assert.equal(p.root.querySelector('.agent-bar__go-label').textContent, 'Ask')
400
+ // the greeting is the bar's own line, which names the app
401
+ assert.equal(p.input.placeholder, 'Ask Pinokio about Demo App…')
402
+ await p.type('a question')
403
+ await p.escape()
404
+ assert.equal(p.shape(), '')
405
+ assert.equal(p.input.value, 'a question')
406
+ assert.deepEqual(classes(p.top).filter((name) => name.startsWith('agent-bar__') && name !== 'agent-bar__mark'), ['agent-bar__input', 'agent-bar__running', 'agent-bar__agent', 'agent-bar__go'])
407
+ })
408
+
409
+ test('app page: its own phone layout gets the full screen and the slim bar', async (t) => {
410
+ // wider than the home bar's phone width, narrower than the app page's
411
+ const p = await page(t, { app: true, media: [APP_PHONE, TOUCH] })
412
+ assert.ok(p.root.closest('.mobile-bottom-nav'), 'the bar is in the page\'s strip')
413
+ assert.equal(p.root.dataset.composePhone, 'true')
414
+ await p.focus()
415
+ assert.equal(p.shape(), 'screen')
416
+ assert.equal(p.root.querySelector('.agent-compose__greet').textContent, 'Ask Pinokio about Demo App')
417
+ assert.equal(p.input.placeholder, '')
418
+ // Return adds a line on a touch screen
419
+ await p.type('ask this')
420
+ assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, false)
421
+ await settle(p.window)
422
+ assert.equal(p.posts.includes('/brain/ask'), false)
423
+ p.root.querySelector('.agent-compose__x').click()
424
+ await settle(p.window)
425
+ assert.equal(p.shape(), '')
426
+ assert.equal(p.input.placeholder, 'Ask Pinokio about Demo App…')
427
+ assert.equal(p.input.value, 'ask this')
428
+ })
429
+
430
+ test('app page: the home bar\'s phone width alone does not make it a phone', async (t) => {
431
+ const p = await page(t, { app: true, media: [PHONE] })
432
+ assert.equal(p.root.dataset.composePhone, 'false')
433
+ await p.focus()
434
+ assert.equal(p.shape(), 'place')
435
+ })
436
+
437
+ test('app page: a send that goes through closes the view and empties the bar', async (t) => {
438
+ const p = await page(t, { app: true, sends: true })
439
+ await p.focus()
440
+ await p.type('ask this')
441
+ p.key(p.input, { key: 'Enter' })
442
+ await settle(p.window)
443
+ await settle(p.window)
444
+ assert.ok(p.posts.includes('/brain/ask'))
445
+ assert.equal(p.shape(), '')
446
+ assert.equal(p.input.value, '')
447
+ })
448
+
449
+ // what the dock says when what it sees running has changed: the list it just read
450
+ const sessionsChanged = (p, shells) => {
451
+ p.window.dispatchEvent(new p.window.CustomEvent('pinokio:sessions-changed', { detail: { shells } }))
452
+ return settle(p.window)
453
+ }
454
+ const OWN = { id: 'x', group: '/home/plugin/codex/pinokio.js?cwd=/home/api/demo&session=s1', start_time: 1 }
455
+ const ELSEWHERE = { id: 'y', group: '/home/plugin/codex/pinokio.js?cwd=/home/api/other&session=s2', start_time: 2 }
456
+
457
+ test('app page: the running count follows the dock when the running sessions change', async (t) => {
458
+ const p = await page(t, { app: true, shells: () => [OWN] })
459
+ const count = p.root.querySelector('.agent-bar__running')
460
+ assert.equal(count.hidden, false)
461
+ assert.match(count.textContent, /^1 running/)
462
+ // stopped from the dock's window
463
+ await sessionsChanged(p, [])
464
+ assert.equal(count.hidden, true)
465
+ })
466
+
467
+ test('app page: a change to another app\'s sessions redraws nothing and reads nothing again', async (t) => {
468
+ let reads = 0
469
+ const p = await page(t, { app: true, shells: () => { reads += 1; return [OWN] } })
470
+ p.root.querySelector('.agent-bar__running').click()
471
+ await settle(p.window)
472
+ // a Stop waiting for its second click is in this row: a redraw would reset it
473
+ const row = p.root.querySelector('.agent-bar__menu .agent-bar__row')
474
+ assert.ok(row)
475
+ const readsBefore = reads
476
+ await sessionsChanged(p, [OWN, ELSEWHERE])
477
+ assert.equal(row.isConnected, true, 'the list was not drawn again')
478
+ assert.equal(reads, readsBefore, 'the dock\'s list is used, not asked for again')
479
+ })
480
+
481
+ test('app page: send on the bar at rest does not open the view', async (t) => {
482
+ const p = await page(t, { app: true, sends: true })
483
+ p.root.querySelector('.agent-bar__go').click()
484
+ await settle(p.window)
485
+ await settle(p.window)
486
+ assert.equal(p.shape(), '')
487
+ })
@@ -0,0 +1,149 @@
1
+ // The shell button of an app page (server/public/agent-bar-shell.js): the
2
+ // button in the top bar and, for the page's phone layout, the "Open a shell" row
3
+ // at the end of the slide-in menu's list. Both show the same list and open a
4
+ // shell the same way.
5
+ //
6
+ // The real script runs here in a page that has only what it looks for. Layout
7
+ // is not covered: this page lays nothing out.
8
+ const assert = require('node:assert/strict')
9
+ const fs = require('node:fs')
10
+ const path = require('node:path')
11
+ const test = require('node:test')
12
+ const { JSDOM } = require('jsdom')
13
+
14
+ const script = fs.readFileSync(path.resolve(__dirname, '../server/public/agent-bar-shell.js'), 'utf8')
15
+
16
+ // Run mode has the Ask AI button (it carries the app's folder); Dev has the
17
+ // folder on the app card's disk figure.
18
+ const appPage = (run) => '<!doctype html><body class="app-page">'
19
+ + '<header class="navheader"><h1>'
20
+ + (run ? '<button id="ask-ai-tab" data-workspace-cwd="/home/api/demo"></button>' : '<span class="disk-usage" data-filepath="/home/api/demo"></span>')
21
+ + '<div class="home-server-popover"></div></h1></header>'
22
+ + '<div class="appcanvas"><aside id="app-sidebar"><div class="menu-container"><div class="menu-scroller">'
23
+ + '<div class="workspace-mode-switch"></div><div class="m h menu"><a class="btn header-item frame-link" id="settings-tab"></a></div><div class="m s temp-menu"></div>'
24
+ + '</div></div></aside></div>'
25
+ + '<button class="mobile-menu-backdrop" data-mobile-menu-backdrop></button></body>'
26
+
27
+ const SHELLS = {
28
+ projectShell: {
29
+ items: [
30
+ { title: 'Shell', subtitle: 'Open a plain Bash shell', href: '/shell/demo_dev.bash.plain?path=%2Fhome%2Fapi%2Fdemo&session=running-one' },
31
+ { title: 'Python', href: '/shell/demo_dev.python?path=%2Fhome%2Fapi%2Fdemo' }
32
+ ]
33
+ }
34
+ }
35
+
36
+ async function page(t, options = {}) {
37
+ const reads = []
38
+ const opened = []
39
+ const posted = []
40
+ let failing = options.fail === true
41
+ const dom = new JSDOM(appPage(options.dev !== true), {
42
+ url: 'http://127.0.0.1:42000/p/demo',
43
+ runScripts: 'outside-only',
44
+ pretendToBeVisual: true,
45
+ beforeParse(window) {
46
+ window.fetch = async (url) => {
47
+ reads.push(String(url))
48
+ if (failing) return { ok: false, json: async () => ({}) }
49
+ return { ok: true, json: async () => SHELLS }
50
+ }
51
+ }
52
+ })
53
+ t.after(() => dom.window.close())
54
+ const { window } = dom
55
+ window.PinokioAgentDock = { openShellTool: (shell) => { opened.push(shell) } }
56
+ window.addEventListener('message', (event) => posted.push(event.data))
57
+ window.eval(script)
58
+ const { document } = window
59
+ // the row is put in once the page has been read to its end
60
+ if (document.readyState === 'loading') await new Promise((resolve) => document.addEventListener('DOMContentLoaded', resolve, { once: true }))
61
+ const row = document.querySelector('.agent-bar-shell-row')
62
+ return {
63
+ window,
64
+ document,
65
+ reads,
66
+ opened,
67
+ posted,
68
+ row,
69
+ toggle: row.querySelector('.agent-bar-shell-row__toggle'),
70
+ list: row.querySelector('.agent-bar-shell-row__list'),
71
+ items: () => Array.from(row.querySelectorAll('.agent-bar-shell-row__list .agent-bar-shell-row__item')),
72
+ recover() { failing = false },
73
+ settle: async () => { for (let i = 0; i < 4; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0)) }
74
+ }
75
+ }
76
+
77
+ test('the row is the last thing in the menu\'s list, after the rows the page redraws', async (t) => {
78
+ const p = await page(t)
79
+ const scroller = p.document.querySelector('.menu-scroller')
80
+ assert.equal(scroller.lastElementChild, p.row)
81
+ assert.equal(p.row.closest('.menu'), null, 'not inside the part the page replaces')
82
+ assert.equal(p.toggle.querySelector('.display').textContent, 'Open a shell')
83
+ assert.equal(p.list.hidden, true)
84
+ assert.equal(p.reads.length, 0, 'nothing is read until it is asked for')
85
+ })
86
+
87
+ test('a tap shows the app\'s shells under the row; another tap puts them away', async (t) => {
88
+ const p = await page(t)
89
+ p.toggle.click()
90
+ await p.settle()
91
+ assert.equal(p.list.hidden, false)
92
+ assert.equal(p.toggle.getAttribute('aria-expanded'), 'true')
93
+ assert.deepEqual(p.items().map((item) => item.querySelector('.display').textContent), ['Shell', 'Python'])
94
+ assert.equal(p.items()[0].querySelector('.agent-bar-shell-row__note').textContent, 'Open a plain Bash shell')
95
+ p.toggle.click()
96
+ assert.equal(p.list.hidden, true)
97
+ })
98
+
99
+ test('picking a shell closes the open menu and opens a new shell in the dock', async (t) => {
100
+ const p = await page(t)
101
+ let backdropPressed = 0
102
+ p.document.querySelector('[data-mobile-menu-backdrop]').addEventListener('click', () => { backdropPressed += 1 })
103
+ p.document.body.classList.add('mobile-menu-open')
104
+ p.toggle.click()
105
+ await p.settle()
106
+ p.items()[0].click()
107
+ await p.settle()
108
+ assert.equal(p.opened.length, 1)
109
+ assert.equal(p.opened[0].label, 'Shell')
110
+ // a new shell, not the one that is already running
111
+ assert.equal(p.opened[0].href, '/shell/demo_dev.bash.plain?path=%2Fhome%2Fapi%2Fdemo')
112
+ assert.equal(backdropPressed, 1)
113
+ assert.equal(p.list.hidden, true)
114
+ })
115
+
116
+ test('the row and the top bar\'s button read the list once between them', async (t) => {
117
+ const p = await page(t)
118
+ p.toggle.click()
119
+ await p.settle()
120
+ p.document.querySelector('.agent-bar-shell__trigger').click()
121
+ await p.settle()
122
+ assert.equal(p.reads.length, 1)
123
+ assert.equal(p.document.querySelectorAll('.agent-bar-shell__menu .agent-bar-shell__row').length, 2)
124
+ })
125
+
126
+ test('a list that cannot be read says so, and is read again on the next tap', async (t) => {
127
+ const p = await page(t, { fail: true })
128
+ p.toggle.click()
129
+ await p.settle()
130
+ assert.equal(p.list.textContent, "Couldn't read this app's shells.")
131
+ p.toggle.click()
132
+ p.recover()
133
+ p.toggle.click()
134
+ await p.settle()
135
+ assert.equal(p.items().length, 2)
136
+ assert.equal(p.reads.length, 2)
137
+ })
138
+
139
+ test('in Dev the pick is sent to the page as the Plugins page sends it', async (t) => {
140
+ const p = await page(t, { dev: true })
141
+ p.toggle.click()
142
+ await p.settle()
143
+ p.items()[1].click()
144
+ await p.settle()
145
+ assert.equal(p.opened.length, 0)
146
+ assert.equal(p.posted.length, 1)
147
+ assert.equal(p.posted[0].launch.label, 'Python')
148
+ assert.match(p.posted[0].launch.href, /^\/shell\/demo_dev\.python\?path=%2Fhome%2Fapi%2Fdemo&session=.+/)
149
+ })
@@ -6,8 +6,6 @@ const test = require("node:test")
6
6
 
7
7
  const AgentInstructions = require("../kernel/agent_instructions")
8
8
 
9
- // spec/requirements/instruction-sync.md, section 3
10
-
11
9
  const guide = "# Development Guide for Pinokio Projects\n\nthe guide for <%= app_root %>\n"
12
10
  const newHome = () => {
13
11
  const home = fs.mkdtempSync(path.join(os.tmpdir(), "pinokio-guide-"))