pinokiod 8.3.13 → 8.3.15
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/kernel/agent_instructions.js +0 -1
- package/kernel/api/index.js +76 -12
- package/kernel/environment.js +1 -1
- package/kernel/index.js +15 -2
- package/kernel/plugin_sources.js +1 -1
- package/kernel/prototype.js +1 -1
- package/kernel/request_file.js +5 -14
- package/kernel/shell.js +12 -0
- package/kernel/shells.js +13 -1
- package/package.json +1 -1
- package/server/index.js +10 -5
- package/server/lib/agent_jobs.js +198 -0
- package/server/lib/agent_sessions.js +131 -0
- package/server/lib/brain.js +161 -91
- package/server/lib/content_validation.js +1 -1
- package/server/public/agent-bar-app.js +28 -6
- package/server/public/agent-bar-compose.css +675 -0
- package/server/public/agent-bar-compose.js +658 -0
- package/server/public/agent-bar-panel.css +2 -0
- package/server/public/agent-bar-panel.js +22 -7
- package/server/public/agent-bar-shell.css +38 -0
- package/server/public/agent-bar-shell.js +128 -34
- package/server/public/agent-bar.css +7 -1
- package/server/public/agent-bar.js +10 -1
- package/server/public/terminal_input_utils.js +4 -0
- package/server/views/app.ejs +5 -1
- package/server/views/partials/main_sidebar.ejs +2 -0
- package/system/plugin/antigravity-cli-auto/pinokio.js +44 -6
- package/system/plugin/claude/pinokio.js +43 -1
- package/system/plugin/claude-auto/pinokio.js +43 -1
- package/system/plugin/codex/pinokio.js +42 -1
- package/system/plugin/codex-auto/pinokio.js +42 -1
- package/system/plugin/grok/pinokio.js +1 -1
- package/system/plugin/grok-auto/pinokio.js +37 -10
- package/system/plugin/opencode/pinokio.js +24 -0
- package/system/plugin/opencode-auto/pinokio.js +82 -10
- package/test/agent-bar-compose.test.js +544 -0
- package/test/agent-bar-shell.test.js +149 -0
- package/test/agent-instructions.test.js +0 -2
- package/test/agent-jobs.test.js +534 -0
- package/test/agent-sessions.test.js +130 -0
- package/test/antigravity-cli-plugin.test.js +63 -18
- package/test/anywhere-api.test.js +1 -1
- package/test/anywhere-onboarding.test.js +1 -2
- package/test/brain.test.js +116 -69
- package/test/grok-plugin.test.js +2 -1
- package/test/opencode-plugin.test.js +7 -4
- package/test/plugin-action-functions.test.js +423 -0
- package/test/request-file.test.js +1 -12
- package/test/shell-log-path.test.js +64 -0
- package/test/shell-stop-while-starting.test.js +70 -0
- package/test/shells-live-error.test.js +66 -2
- package/test/terminal-mouse-input.test.js +12 -0
|
@@ -0,0 +1,544 @@
|
|
|
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('with the large face and no cursor in the text, the empty text says where to type', async (t) => {
|
|
244
|
+
const p = await page(t, { search: '?universal&type=ask' })
|
|
245
|
+
assert.equal(p.window.PinokioAgentBar.open({ type: 'ask' }), true)
|
|
246
|
+
await settle(p.window)
|
|
247
|
+
assert.equal(p.shape(), 'centre')
|
|
248
|
+
assert.equal(p.input.placeholder, '', 'the cursor is there')
|
|
249
|
+
p.input.blur()
|
|
250
|
+
await settle(p.window)
|
|
251
|
+
assert.equal(p.shape(), 'centre')
|
|
252
|
+
assert.equal(p.input.placeholder, 'Ask Pinokio anything…')
|
|
253
|
+
await p.focus()
|
|
254
|
+
assert.equal(p.input.placeholder, '')
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
test('on a phone the cursor counts only with the keyboard up', async (t) => {
|
|
258
|
+
const p = await page(t, { media: [PHONE, TOUCH] })
|
|
259
|
+
// the keyboard takes part of the screen, or none of it
|
|
260
|
+
const vv = { height: 400, offsetTop: 0, addEventListener() {} }
|
|
261
|
+
p.window.visualViewport = vv
|
|
262
|
+
p.window.innerHeight = 800
|
|
263
|
+
await p.focus()
|
|
264
|
+
assert.equal(p.shape(), 'screen')
|
|
265
|
+
assert.equal(p.input.placeholder, '')
|
|
266
|
+
// put away: the cursor is still in the text as far as the page knows
|
|
267
|
+
vv.height = 800
|
|
268
|
+
p.window.dispatchEvent(new p.window.Event('resize'))
|
|
269
|
+
await settle(p.window)
|
|
270
|
+
assert.equal(p.document.activeElement, p.input)
|
|
271
|
+
assert.equal(p.input.placeholder, 'Ask Pinokio anything…')
|
|
272
|
+
// a mode whose line at rest is its greeting does not say it twice
|
|
273
|
+
await p.mode(1)
|
|
274
|
+
assert.equal(p.root.querySelector('.agent-compose__greet').textContent, 'What should this app do?')
|
|
275
|
+
assert.equal(p.input.placeholder, 'Type here…')
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test('a press on the box, off its buttons, puts the cursor in the text', async (t) => {
|
|
279
|
+
const p = await page(t, { search: '?universal&type=ask' })
|
|
280
|
+
p.window.PinokioAgentBar.open({ type: 'ask' })
|
|
281
|
+
await settle(p.window)
|
|
282
|
+
p.input.blur()
|
|
283
|
+
await settle(p.window)
|
|
284
|
+
assert.notEqual(p.document.activeElement, p.input)
|
|
285
|
+
const greet = p.root.querySelector('.agent-compose__greet')
|
|
286
|
+
const down = new p.window.Event('pointerdown', { bubbles: true, cancelable: true })
|
|
287
|
+
greet.dispatchEvent(down)
|
|
288
|
+
assert.equal(down.defaultPrevented, true, 'the press does not take the cursor away')
|
|
289
|
+
greet.click()
|
|
290
|
+
await settle(p.window)
|
|
291
|
+
assert.equal(p.document.activeElement, p.input)
|
|
292
|
+
assert.equal(p.shape(), 'centre')
|
|
293
|
+
// a button of the box keeps its own press
|
|
294
|
+
p.input.blur()
|
|
295
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
296
|
+
await settle(p.window)
|
|
297
|
+
assert.equal(p.root.querySelector('.agent-bar__menu').hidden, false)
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
test('on a phone the bar at rest is one button: the mark opens the view, not the mode menu', async (t) => {
|
|
301
|
+
const p = await page(t, { media: [PHONE, TOUCH] })
|
|
302
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
303
|
+
await settle(p.window)
|
|
304
|
+
assert.equal(p.shape(), 'screen')
|
|
305
|
+
assert.equal(p.document.activeElement, p.input)
|
|
306
|
+
assert.equal(p.root.querySelector('.agent-bar__menu').hidden, true)
|
|
307
|
+
// in the view the mode chip opens its menu as usual
|
|
308
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
309
|
+
await settle(p.window)
|
|
310
|
+
assert.equal(p.root.querySelector('.agent-bar__menu').hidden, false)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
test('on desktop the mode chip at rest still opens its menu', async (t) => {
|
|
314
|
+
const p = await page(t)
|
|
315
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
316
|
+
await settle(p.window)
|
|
317
|
+
assert.equal(p.shape(), '')
|
|
318
|
+
assert.equal(p.root.querySelector('.agent-bar__menu').hidden, false)
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
test('the bar knows when a draft is left in a mode other than Ask', async (t) => {
|
|
322
|
+
const p = await page(t, { media: [PHONE, TOUCH] })
|
|
323
|
+
const draft = () => p.root.dataset.composeDraft
|
|
324
|
+
assert.equal(draft(), 'false')
|
|
325
|
+
await p.focus()
|
|
326
|
+
await p.type('just asking')
|
|
327
|
+
assert.equal(draft(), 'false', 'Ask is never named')
|
|
328
|
+
await p.mode(2)
|
|
329
|
+
await p.type('A Pinokio plugin for: ')
|
|
330
|
+
assert.equal(draft(), 'false', 'the starter text alone is not a draft')
|
|
331
|
+
await p.type('A Pinokio plugin for: resizing images')
|
|
332
|
+
assert.equal(draft(), 'true')
|
|
333
|
+
await p.mode(1)
|
|
334
|
+
await p.type('')
|
|
335
|
+
assert.equal(draft(), 'false')
|
|
336
|
+
const name = p.root.querySelector('#agent-bar-create-name')
|
|
337
|
+
name.value = 'my-app'
|
|
338
|
+
name.dispatchEvent(new p.window.Event('input', { bubbles: true }))
|
|
339
|
+
await settle(p.window)
|
|
340
|
+
assert.equal(draft(), 'true', 'a folder name alone is a draft')
|
|
341
|
+
p.root.querySelector('.agent-compose__x').click()
|
|
342
|
+
await settle(p.window)
|
|
343
|
+
assert.equal(p.shape(), '')
|
|
344
|
+
assert.equal(draft(), 'true')
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
test('on a phone with no room for the large face, it stays small and the greeting is the placeholder', async (t) => {
|
|
348
|
+
// what the on-screen keyboard and the folder rows can leave
|
|
349
|
+
const p = await page(t, { media: [PHONE, TOUCH], rowHeight: 120 })
|
|
350
|
+
await p.focus()
|
|
351
|
+
assert.equal(p.shape(), 'screen')
|
|
352
|
+
assert.ok(p.face.closest('.agent-compose__slot--top'))
|
|
353
|
+
assert.equal(p.input.placeholder, 'What should we do?')
|
|
354
|
+
assert.equal(p.root.dataset.composeRoomy, 'false')
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
test('with a keyboard, Enter sends and Shift+Enter adds a line', async (t) => {
|
|
358
|
+
const p = await page(t)
|
|
359
|
+
await p.focus()
|
|
360
|
+
await p.type('ask this')
|
|
361
|
+
assert.equal(p.key(p.input, { key: 'Enter', shiftKey: true }).defaultPrevented, false)
|
|
362
|
+
assert.equal(p.input.enterKeyHint, 'send')
|
|
363
|
+
assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, true)
|
|
364
|
+
await settle(p.window)
|
|
365
|
+
assert.ok(p.posts.includes('/brain/ask'))
|
|
366
|
+
// the send failed: the view stays open with everything typed
|
|
367
|
+
assert.equal(p.shape(), 'place')
|
|
368
|
+
assert.equal(p.input.value, 'ask this')
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
test('on a touch screen Return adds a line and only the send button sends', async (t) => {
|
|
372
|
+
const p = await page(t, { media: [PHONE, TOUCH] })
|
|
373
|
+
await p.focus()
|
|
374
|
+
await p.type('ask this')
|
|
375
|
+
assert.equal(p.input.enterKeyHint, 'enter')
|
|
376
|
+
assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, false, 'Return is left to add a line')
|
|
377
|
+
await settle(p.window)
|
|
378
|
+
assert.equal(p.posts.includes('/brain/ask'), false)
|
|
379
|
+
// Cmd/Ctrl+Enter still sends, for an attached keyboard
|
|
380
|
+
assert.equal(p.key(p.input, { key: 'Enter', metaKey: true }).defaultPrevented, true)
|
|
381
|
+
await settle(p.window)
|
|
382
|
+
assert.ok(p.posts.includes('/brain/ask'))
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
test('on a touch screen Return still sends from a link and from a folder name', async (t) => {
|
|
386
|
+
const p = await page(t, { media: [PHONE, TOUCH] })
|
|
387
|
+
await p.focus()
|
|
388
|
+
await p.mode(3)
|
|
389
|
+
assert.equal(p.input.enterKeyHint, 'go')
|
|
390
|
+
await p.type('https://github.com/owner/repo')
|
|
391
|
+
// handled by the bar: it sends, or goes to the folder name
|
|
392
|
+
assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, true)
|
|
393
|
+
const name = p.root.querySelector('#agent-bar-download-name')
|
|
394
|
+
assert.equal(name.enterKeyHint, 'go')
|
|
395
|
+
assert.equal(p.key(name, { key: 'Enter' }).defaultPrevented, true)
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
test('send on the bar at rest opens the view in a mode that has a folder name', async (t) => {
|
|
399
|
+
const p = await page(t)
|
|
400
|
+
await p.focus()
|
|
401
|
+
await p.mode(1)
|
|
402
|
+
await p.type('an app')
|
|
403
|
+
await p.escape()
|
|
404
|
+
assert.equal(p.shape(), '')
|
|
405
|
+
p.root.querySelector('.agent-bar__go').click()
|
|
406
|
+
await settle(p.window)
|
|
407
|
+
assert.equal(p.shape(), 'place')
|
|
408
|
+
assert.equal(p.document.activeElement, p.root.querySelector('#agent-bar-create-name'), 'the empty folder name is next')
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
test('send on the bar at rest in Ask does not open the view', async (t) => {
|
|
412
|
+
const p = await page(t, { sends: true })
|
|
413
|
+
p.root.querySelector('.agent-bar__go').click()
|
|
414
|
+
await settle(p.window)
|
|
415
|
+
assert.ok(p.posts.includes('/brain/ask'))
|
|
416
|
+
assert.equal(p.shape(), '')
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
test('a send that goes through closes the view and empties the bar', async (t) => {
|
|
420
|
+
const p = await page(t, { sends: true })
|
|
421
|
+
await p.focus()
|
|
422
|
+
await p.type('ask this')
|
|
423
|
+
p.key(p.input, { key: 'Enter' })
|
|
424
|
+
await settle(p.window)
|
|
425
|
+
assert.equal(p.shape(), '')
|
|
426
|
+
assert.equal(p.input.value, '')
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
test('opening a session from the running list closes the view and keeps the text', async (t) => {
|
|
430
|
+
const p = await page(t)
|
|
431
|
+
// the list agent-bar-panel.js adds
|
|
432
|
+
const list = p.document.createElement('div')
|
|
433
|
+
list.className = 'agent-bar__menu agent-bar__menu--running'
|
|
434
|
+
list.innerHTML = '<button type="button" class="agent-bar__row">a session</button>'
|
|
435
|
+
p.root.querySelector('.agent-bar__inner').appendChild(list)
|
|
436
|
+
await p.focus()
|
|
437
|
+
await p.type('still here')
|
|
438
|
+
list.querySelector('.agent-bar__row').click()
|
|
439
|
+
await settle(p.window)
|
|
440
|
+
assert.equal(p.shape(), '')
|
|
441
|
+
assert.equal(p.input.value, 'still here')
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
// ---- the bar on an app's page: Ask only, the same view ----
|
|
445
|
+
|
|
446
|
+
test('app page: going to the input opens the box in place, with no mode chip', async (t) => {
|
|
447
|
+
const p = await page(t, { app: true })
|
|
448
|
+
assert.equal(p.root.dataset.item, 'ask_app')
|
|
449
|
+
assert.ok(p.root.classList.contains('agent-compose'))
|
|
450
|
+
assert.ok(p.face.closest('.agent-bar__top'), 'at rest the face stands where the bar had its mark')
|
|
451
|
+
const parentBefore = p.input.parentNode
|
|
452
|
+
await p.focus()
|
|
453
|
+
assert.equal(p.shape(), 'place')
|
|
454
|
+
assert.equal(p.input.parentNode, parentBefore)
|
|
455
|
+
assert.deepEqual(classes(p.controls), ['agent-compose__grow', 'agent-bar__agent', 'agent-bar__go'])
|
|
456
|
+
assert.equal(p.root.querySelector('.agent-bar__go-label').textContent, 'Ask')
|
|
457
|
+
// the greeting is the bar's own line, which names the app
|
|
458
|
+
assert.equal(p.input.placeholder, 'Ask Pinokio about Demo App…')
|
|
459
|
+
await p.type('a question')
|
|
460
|
+
await p.escape()
|
|
461
|
+
assert.equal(p.shape(), '')
|
|
462
|
+
assert.equal(p.input.value, 'a question')
|
|
463
|
+
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'])
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
test('app page: its own phone layout gets the full screen and the slim bar', async (t) => {
|
|
467
|
+
// wider than the home bar's phone width, narrower than the app page's
|
|
468
|
+
const p = await page(t, { app: true, media: [APP_PHONE, TOUCH] })
|
|
469
|
+
assert.ok(p.root.closest('.mobile-bottom-nav'), 'the bar is in the page\'s strip')
|
|
470
|
+
assert.equal(p.root.dataset.composePhone, 'true')
|
|
471
|
+
await p.focus()
|
|
472
|
+
assert.equal(p.shape(), 'screen')
|
|
473
|
+
assert.equal(p.root.querySelector('.agent-compose__greet').textContent, 'Ask Pinokio about Demo App')
|
|
474
|
+
assert.equal(p.input.placeholder, '')
|
|
475
|
+
// Return adds a line on a touch screen
|
|
476
|
+
await p.type('ask this')
|
|
477
|
+
assert.equal(p.key(p.input, { key: 'Enter' }).defaultPrevented, false)
|
|
478
|
+
await settle(p.window)
|
|
479
|
+
assert.equal(p.posts.includes('/brain/ask'), false)
|
|
480
|
+
p.root.querySelector('.agent-compose__x').click()
|
|
481
|
+
await settle(p.window)
|
|
482
|
+
assert.equal(p.shape(), '')
|
|
483
|
+
assert.equal(p.input.placeholder, 'Ask Pinokio about Demo App…')
|
|
484
|
+
assert.equal(p.input.value, 'ask this')
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
test('app page: the home bar\'s phone width alone does not make it a phone', async (t) => {
|
|
488
|
+
const p = await page(t, { app: true, media: [PHONE] })
|
|
489
|
+
assert.equal(p.root.dataset.composePhone, 'false')
|
|
490
|
+
await p.focus()
|
|
491
|
+
assert.equal(p.shape(), 'place')
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
test('app page: a send that goes through closes the view and empties the bar', async (t) => {
|
|
495
|
+
const p = await page(t, { app: true, sends: true })
|
|
496
|
+
await p.focus()
|
|
497
|
+
await p.type('ask this')
|
|
498
|
+
p.key(p.input, { key: 'Enter' })
|
|
499
|
+
await settle(p.window)
|
|
500
|
+
await settle(p.window)
|
|
501
|
+
assert.ok(p.posts.includes('/brain/ask'))
|
|
502
|
+
assert.equal(p.shape(), '')
|
|
503
|
+
assert.equal(p.input.value, '')
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
// what the dock says when what it sees running has changed: the list it just read
|
|
507
|
+
const sessionsChanged = (p, shells) => {
|
|
508
|
+
p.window.dispatchEvent(new p.window.CustomEvent('pinokio:sessions-changed', { detail: { shells } }))
|
|
509
|
+
return settle(p.window)
|
|
510
|
+
}
|
|
511
|
+
const OWN = { id: 'x', group: '/home/plugin/codex/pinokio.js?cwd=/home/api/demo&session=s1', start_time: 1 }
|
|
512
|
+
const ELSEWHERE = { id: 'y', group: '/home/plugin/codex/pinokio.js?cwd=/home/api/other&session=s2', start_time: 2 }
|
|
513
|
+
|
|
514
|
+
test('app page: the running count follows the dock when the running sessions change', async (t) => {
|
|
515
|
+
const p = await page(t, { app: true, shells: () => [OWN] })
|
|
516
|
+
const count = p.root.querySelector('.agent-bar__running')
|
|
517
|
+
assert.equal(count.hidden, false)
|
|
518
|
+
assert.match(count.textContent, /^1 running/)
|
|
519
|
+
// stopped from the dock's window
|
|
520
|
+
await sessionsChanged(p, [])
|
|
521
|
+
assert.equal(count.hidden, true)
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
test('app page: a change to another app\'s sessions redraws nothing and reads nothing again', async (t) => {
|
|
525
|
+
let reads = 0
|
|
526
|
+
const p = await page(t, { app: true, shells: () => { reads += 1; return [OWN] } })
|
|
527
|
+
p.root.querySelector('.agent-bar__running').click()
|
|
528
|
+
await settle(p.window)
|
|
529
|
+
// a Stop waiting for its second click is in this row: a redraw would reset it
|
|
530
|
+
const row = p.root.querySelector('.agent-bar__menu .agent-bar__row')
|
|
531
|
+
assert.ok(row)
|
|
532
|
+
const readsBefore = reads
|
|
533
|
+
await sessionsChanged(p, [OWN, ELSEWHERE])
|
|
534
|
+
assert.equal(row.isConnected, true, 'the list was not drawn again')
|
|
535
|
+
assert.equal(reads, readsBefore, 'the dock\'s list is used, not asked for again')
|
|
536
|
+
})
|
|
537
|
+
|
|
538
|
+
test('app page: send on the bar at rest does not open the view', async (t) => {
|
|
539
|
+
const p = await page(t, { app: true, sends: true })
|
|
540
|
+
p.root.querySelector('.agent-bar__go').click()
|
|
541
|
+
await settle(p.window)
|
|
542
|
+
await settle(p.window)
|
|
543
|
+
assert.equal(p.shape(), '')
|
|
544
|
+
})
|