pinokiod 8.3.26 → 8.3.28

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.
@@ -11,12 +11,10 @@ module.exports = function registerGitPageRoutes(app, options = {}) {
11
11
  app.get("/pinokio/git/:name", async (req, res) => {
12
12
  const name = req.params.name
13
13
  const cwd = kernel.path("api", name)
14
- try {
15
- const stat = await fs.promises.stat(cwd)
16
- if (!stat.isDirectory()) {
17
- throw new Error("not a folder")
18
- }
19
- } catch (_) {
14
+ // an app is one folder directly inside the apps folder, nothing else
15
+ const valid = name && name !== "." && name !== ".." && !/[\\/\0]/.test(name)
16
+ const stat = valid ? await fs.promises.stat(cwd).catch(() => null) : null
17
+ if (!stat || !stat.isDirectory()) {
20
18
  res.status(404).send("App not found")
21
19
  return
22
20
  }
@@ -8636,6 +8636,20 @@ body.dark .pinokio-custom-terminal-header {
8636
8636
  <div class='flexible'></div>
8637
8637
  </div>
8638
8638
  </button>
8639
+ <button type='button' class='btn header-item' data-mobile-proxy="#files-tab" data-mobile-close-menu="true" aria-label="Files">
8640
+ <div class='tab'>
8641
+ <i class="fa-solid fa-file-lines menu-action-leading-icon"></i>
8642
+ <div class='display'>Files</div>
8643
+ <div class='flexible'></div>
8644
+ </div>
8645
+ </button>
8646
+ <button type='button' class='btn header-item' data-mobile-proxy="#git-tab" data-mobile-close-menu="true" aria-label="Git">
8647
+ <div class='tab'>
8648
+ <i class="fa-brands fa-git-alt menu-action-leading-icon"></i>
8649
+ <div class='display'>Git</div>
8650
+ <div class='flexible'></div>
8651
+ </div>
8652
+ </button>
8639
8653
  <% } %>
8640
8654
  <% if (registryEnabled) { %>
8641
8655
  <button type='button' class='btn header-item mobile-nav-community' data-mobile-proxy="#community-mode-toggle" data-mobile-panel="feed" data-mobile-close-menu="true" aria-pressed="false" aria-label="Project feed">
@@ -12174,10 +12188,10 @@ const rerenderMenuSection = (container, html) => {
12174
12188
  e.preventDefault()
12175
12189
  e.stopPropagation()
12176
12190
  await FSEditor({
12177
- title: `<%=config.title%>`,
12178
- description: `<%=config.description%>`,
12179
- old_path: `<%=name%>`,
12180
- icon: `<%=config.icon%>`,
12191
+ title: <%-JSON.stringify(config.title || '').replace(/</g, '\\u003c')%>,
12192
+ description: <%-JSON.stringify(config.description || '').replace(/</g, '\\u003c')%>,
12193
+ old_path: <%-JSON.stringify(name)%>,
12194
+ icon: <%-JSON.stringify(config.icon || '').replace(/</g, '\\u003c')%>,
12181
12195
  <% if (config.iconpath) { %>
12182
12196
  iconpath: `<%-JSON.stringify(config.iconpath).slice(1, -1)%>`,
12183
12197
  <% } %>
@@ -27,11 +27,10 @@
27
27
  </div>
28
28
  </aside>
29
29
  <main class="files-app__main">
30
- <button class="files-app__sidebar-toggle" id="files-app-toggle-sidebar" type="button" aria-controls="files-app-tree" aria-expanded="true">
31
- <span class="sr-only">Hide files</span>
32
- <i class="fa-solid fa-chevron-left" aria-hidden="true"></i>
33
- </button>
34
30
  <div class="files-app__tabbar">
31
+ <button class="files-app__sidebar-toggle" id="files-app-toggle-sidebar" type="button" aria-controls="files-app-tree" aria-expanded="true" title="Hide files" aria-label="Hide files">
32
+ <i class="fa-solid fa-chevron-left" aria-hidden="true"></i>
33
+ </button>
35
34
  <button class="files-app__mobile-back" id="files-app-mobile-back" type="button" aria-label="Back to files">
36
35
  <i class="fa-solid fa-chevron-left" aria-hidden="true"></i>
37
36
  <span>Files</span>
@@ -1866,7 +1866,7 @@ body.dark aside .current.selected {
1866
1866
  <% const runningTerminalOnlineCount = Number(item.terminal_online_count || 0) %>
1867
1867
  <% const runningTerminalLabel = runningTerminalOnlineCount > 0 ? `${runningTerminalOnlineCount} terminal${runningTerminalOnlineCount === 1 ? "" : "s"} online` : "Terminals" %>
1868
1868
  <% if (runningTerminalOnlineCount > 0) { %>
1869
- <button class='btn browse terminals-link is-online' type='button' data-src="<%=item.view_url%>" title="<%=runningTerminalLabel%>">
1869
+ <button class='btn browse terminals-link is-online' type='button' data-src="<%=item.dev_url%>" title="<%=runningTerminalLabel%>">
1870
1870
  <i class="fa-solid fa-terminal" aria-hidden="true"></i>
1871
1871
  <span><%=runningTerminalLabel%></span>
1872
1872
  <i class="fa-solid fa-circle-notch fa-spin terminals-link-indicator" aria-hidden="true"></i>
@@ -1956,7 +1956,7 @@ body.dark aside .current.selected {
1956
1956
  </button>
1957
1957
  <% if (notRunningTerminalOnlineCount > 0) { %>
1958
1958
  <% const notRunningTerminalLabel = notRunningTerminalOnlineCount > 0 ? `${notRunningTerminalOnlineCount} terminal${notRunningTerminalOnlineCount === 1 ? "" : "s"} online` : "Terminals" %>
1959
- <button class='btn browse terminals-link is-online' type='button' data-src="<%=item.view_url%>" title="<%=notRunningTerminalLabel%>">
1959
+ <button class='btn browse terminals-link is-online' type='button' data-src="<%=item.dev_url%>" title="<%=notRunningTerminalLabel%>">
1960
1960
  <i class="fa-solid fa-terminal" aria-hidden="true"></i>
1961
1961
  <span><%=notRunningTerminalLabel%></span>
1962
1962
  <i class="fa-solid fa-circle-notch fa-spin terminals-link-indicator" aria-hidden="true"></i>
@@ -0,0 +1,60 @@
1
+ // "Open in a new tab" in a session window's menu opens a top-level Pinokio
2
+ // window that shows the session's own page. In the desktop app only that
3
+ // top-level page has the strip a window is dragged by.
4
+ const assert = require('node:assert/strict')
5
+ const fs = require('node:fs')
6
+ const path = require('node:path')
7
+ const test = require('node:test')
8
+ const { JSDOM, ResourceLoader } = require('jsdom')
9
+
10
+ const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
11
+
12
+ class TerminalPage extends ResourceLoader {
13
+ fetch() {
14
+ return Promise.resolve(Buffer.from('<!doctype html><div id="terminal"><textarea></textarea></div>'))
15
+ }
16
+ }
17
+
18
+ test('"Open in a new tab" opens the session\'s page inside a top-level window', { timeout: 3000 }, async (t) => {
19
+ const dom = new JSDOM('<!doctype html><body class="main-sidebar-page"><header class="navheader"><h1><div class="flexible"></div></h1></header></body>', {
20
+ url: 'http://127.0.0.1:42000/home',
21
+ resources: new TerminalPage(),
22
+ runScripts: 'outside-only',
23
+ pretendToBeVisual: true,
24
+ })
25
+ t.after(() => dom.window.close())
26
+ const { window } = dom
27
+ const { document } = window
28
+ window.innerWidth = 1760
29
+ window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
30
+ window.Element.prototype.getBoundingClientRect = () => ({ left: 300, top: 8, right: 900, bottom: 40, width: 600, height: 32 })
31
+ window.sessionStorage.setItem('pinokio.agentBar.dock.tabs', JSON.stringify([
32
+ { key: '/plugin/codex/pinokio.js|/home/brain|s1', kind: 'agent', open: true, z: 1 },
33
+ ]))
34
+ window.fetch = async (url) => {
35
+ if (url === '/info/shells') {
36
+ return { ok: true, json: async () => [{ id: 'agent', group: '/home/plugin/codex/pinokio.js?cwd=/home/brain&session=s1' }] }
37
+ }
38
+ return { ok: true, json: async () => ({ menu: [{ href: '/pinokio/run/plugin/codex/pinokio.js', title: 'Codex', default: true }] }) }
39
+ }
40
+ const opened = new Promise((resolve) => { window.open = (...args) => resolve(args) })
41
+ for (const name of ['agent-bar.js', 'agent-bar-panel.js']) window.eval(script(name))
42
+ await window.PinokioAgentBar.ready
43
+ let row = null
44
+ for (let i = 0; i < 50 && !row; i += 1) {
45
+ await new Promise((resolve) => window.setTimeout(resolve, 10))
46
+ row = Array.from(document.querySelectorAll('.agent-dock__more-row')).find((item) => item.textContent === 'Open in a new tab')
47
+ }
48
+ assert.ok(row, 'the session window has the row')
49
+ row.click()
50
+
51
+ const [address, target] = await opened
52
+ assert.equal(target, '_blank')
53
+ const top = new URL(address, window.location.href)
54
+ assert.equal(top.pathname, '/', 'the new window is the top-level page')
55
+ const shown = new URL(top.searchParams.get('page'), window.location.href)
56
+ assert.equal(shown.pathname, '/pinokio/run/plugin/codex/pinokio.js')
57
+ assert.equal(shown.searchParams.get('cwd'), '/home/brain')
58
+ assert.equal(shown.searchParams.get('session'), 's1')
59
+ assert.equal(shown.searchParams.get('chrome'), 'full')
60
+ })
@@ -0,0 +1,84 @@
1
+ // The app page's Files and Git tabs: which tab a page opens on, where old Dev
2
+ // addresses go, and the Git page's address.
3
+ const assert = require('node:assert/strict')
4
+ const fs = require('node:fs')
5
+ const os = require('node:os')
6
+ const path = require('node:path')
7
+ const test = require('node:test')
8
+
9
+ const AppRunTabs = require('../server/lib/app_run_tabs')
10
+ const registerGitPageRoutes = require('../server/routes/git_page')
11
+
12
+ const tempDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'pinokio-tabs-'))
13
+ const launcherMenu = { menu: [{ default: true, text: 'Start', href: 'start.js' }] }
14
+ const htmlOnly = { menu: [{ default: true, text: 'index.html', href: '/asset/api/demo/index.html' }] }
15
+ const listingOnly = { menu: [{ default: true, text: 'Project Files', href: '/files/api/demo' }] }
16
+
17
+ const page = (query) => ({ params: { name: 'demo' }, query })
18
+
19
+ test('a link that asks for a tab is recognised, so the page opens without launching the app', () => {
20
+ assert.equal(AppRunTabs.chosen(page({ pinokio_tab: 'files' })), 'files')
21
+ assert.equal(AppRunTabs.chosen(page({ pinokio_tab: 'git' })), 'git')
22
+ assert.equal(AppRunTabs.chosen(page({ git_publish: '1' })), 'git')
23
+ assert.equal(AppRunTabs.chosen(page({ pinokio_tab: 'other' })), '')
24
+ assert.equal(AppRunTabs.chosen(page({})), '')
25
+ })
26
+
27
+ test('the page opens on the tab that was asked for', () => {
28
+ assert.deepEqual(AppRunTabs.locals(page({ pinokio_tab: 'git' }), 'run', launcherMenu), { run_initial_tab: 'git', git_initial_publish: false })
29
+ assert.deepEqual(AppRunTabs.locals(page({ git_publish: '1' }), 'run', launcherMenu), { run_initial_tab: 'git', git_initial_publish: true })
30
+ assert.deepEqual(AppRunTabs.locals(page({}), 'run', launcherMenu), { run_initial_tab: '', git_initial_publish: false })
31
+ })
32
+
33
+ test('a folder with only an index.html keeps opening on that page', () => {
34
+ assert.equal(AppRunTabs.locals(page({}), 'run', htmlOnly).run_initial_tab, '')
35
+ })
36
+
37
+ test('a folder with nothing of its own to show opens on Files', () => {
38
+ assert.equal(AppRunTabs.locals(page({}), 'run', listingOnly).run_initial_tab, 'files')
39
+ // unless the link came for something else: a plugin to start, Settings from Home, a file to reveal
40
+ for (const query of [{ plugin: '/plugin/x' }, { pinokio_home_select: '{}' }, { reveal: 'a.bin' }]) {
41
+ assert.equal(AppRunTabs.locals(page(query), 'run', listingOnly).run_initial_tab, '')
42
+ }
43
+ // or its launcher chose a page of its own, even one under the same address
44
+ const docs = { menu: [{ default: true, text: 'Docs', href: '/files/api/demo/docs' }] }
45
+ assert.equal(AppRunTabs.locals(page({}), 'run', docs).run_initial_tab, '')
46
+ })
47
+
48
+ test('old Dev addresses go to the app page without launching, on the matching tab', () => {
49
+ const redirect = (query, tab) => {
50
+ let target = ''
51
+ AppRunTabs.redirectDev({ params: { name: 'my app' }, query }, { redirect: (url) => { target = url } }, tab)
52
+ return target
53
+ }
54
+ assert.equal(redirect({}), '/v/my%20app')
55
+ assert.equal(redirect({}, 'files'), '/v/my%20app?pinokio_tab=files')
56
+ assert.equal(redirect({ pinokio_dev_tab: 'files' }), '/v/my%20app?pinokio_tab=files')
57
+ assert.equal(redirect({ 'pinokio.publish': '1' }), '/v/my%20app?git_publish=1')
58
+ assert.equal(redirect({ plugin: '/plugin/x', prompt: 'hi' }), '/v/my%20app?plugin=%2Fplugin%2Fx&prompt=hi')
59
+ assert.equal(redirect({ prompt: ['first', 'second'] }), '/v/my%20app?prompt=first&prompt=second')
60
+ })
61
+
62
+ test('the Git page only opens for a folder directly inside the apps folder', async () => {
63
+ const apiRoot = tempDir()
64
+ fs.mkdirSync(path.join(apiRoot, 'demo'))
65
+ let handler
66
+ registerGitPageRoutes({ get: (route, fn) => { handler = fn } }, {
67
+ kernel: { path: (first, ...rest) => path.join(apiRoot, ...rest) },
68
+ getPageContext: () => ({ theme: 'light' }),
69
+ })
70
+ const open = async (name) => {
71
+ const result = {}
72
+ await handler({ params: { name }, query: {} }, {
73
+ status: (code) => { result.status = code; return { send: () => {} } },
74
+ render: (view, locals) => { result.view = view; result.locals = locals },
75
+ })
76
+ return result
77
+ }
78
+ const ok = await open('demo')
79
+ assert.equal(ok.view, 'git_page')
80
+ assert.equal(ok.locals.cwd, path.join(apiRoot, 'demo'))
81
+ for (const name of ['..', '.', 'missing', 'a/b', 'a\\b']) {
82
+ assert.equal((await open(name)).status, 404, name)
83
+ }
84
+ })