pinokiod 8.3.18 → 8.3.20

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/shell.js CHANGED
@@ -23,6 +23,7 @@ const ShellStateSync = require('./shell_state_sync')
23
23
  const ShellRunTemplate = require('./api/shell_run_template')
24
24
  const { PYTHON_INSTALL_SPEC, PIP_WHEEL, PIP_SEED_SCRIPT } = require('./bin/conda-pins')
25
25
  const CondaRuntimeGuard = require('./shell_conda_runtime_guard')
26
+ const WindowsConsole = require('./windows_console')
26
27
  const { managedCertPaths, applyManagedCertEnv, repairPipVendoredBundle, explorerHref } = require('./cert_env')
27
28
  const escapeHtml = require('escape-html')
28
29
  const home = os.homedir()
@@ -875,6 +876,7 @@ class Shell {
875
876
  config.cwd = path.resolve(cwd)
876
877
  }
877
878
  config.env = this.env
879
+ Object.assign(config, WindowsConsole.ptyOptions(this.kernel))
878
880
  //let re = /(.+\r\n)(\1)/gs
879
881
 
880
882
  //let re = /([\r\n]+[^\r\n]+)(\1)/gs
@@ -1549,6 +1551,7 @@ class Shell {
1549
1551
  }
1550
1552
 
1551
1553
  config.env = this.env
1554
+ Object.assign(config, WindowsConsole.ptyOptions(this.kernel))
1552
1555
  if (!this.ptyProcess) {
1553
1556
  // ptyProcess doesn't exist => create
1554
1557
  this.done = false
@@ -0,0 +1,68 @@
1
+ // Which console layer a shell starts on, on Windows.
2
+ //
3
+ // Every Windows shell runs behind a console layer (ConPTY) that sits between
4
+ // the program and the terminal page. The one built into Windows 10 keeps a
5
+ // full-screen program's "I own the screen" and "send me the mouse" requests to
6
+ // itself, so the page never hears them: it keeps its own scrollback and
7
+ // scrollbar next to the one the program draws, and the wheel and clicks never
8
+ // reach the program. The pty library ships a newer copy of the layer that
9
+ // passes both on.
10
+ //
11
+ // The newer copy is used only when the user picks it in Settings. The choice
12
+ // is read each time a shell starts, so it applies to shells started after it
13
+ // is saved. Anywhere but Windows nothing here does anything.
14
+ const fs = require('fs')
15
+ const path = require('path')
16
+
17
+ const KEY = "windows_console"
18
+ const DEFAULT = "default"
19
+ const BUNDLED = "bundled"
20
+
21
+ // Where the pty library's install step puts its copy: next to its native module.
22
+ const bundledFiles = () => {
23
+ const root = path.dirname(require.resolve('@homebridge/node-pty-prebuilt-multiarch/package.json'))
24
+ const dir = path.join(root, 'build', 'Release', 'conpty')
25
+ return ['conpty.dll', 'OpenConsole.exe'].map((file) => path.join(dir, file))
26
+ }
27
+
28
+ // A shell asked to use the copy while a file is missing does not start at all,
29
+ // so the copy is used only when both files are there.
30
+ const bundledAvailable = (files = bundledFiles()) => {
31
+ try {
32
+ return files.every((file) => fs.existsSync(file))
33
+ } catch (_) {
34
+ return false
35
+ }
36
+ }
37
+
38
+ const choice = (store) => (store && store.get(KEY) === BUNDLED ? BUNDLED : DEFAULT)
39
+
40
+ // The row for the Settings page's General list: none except on Windows.
41
+ const settings = (kernel) => {
42
+ if (!kernel || kernel.platform !== "win32") return []
43
+ return [{
44
+ key: KEY,
45
+ val: choice(kernel.store),
46
+ options: [DEFAULT, BUNDLED],
47
+ description: [
48
+ "The console layer terminals run on. \"default\" is the one built into Windows.",
49
+ "Choose \"bundled\" if a full-screen terminal app shows two scrollbars or ignores the mouse wheel (seen on Windows 10). Applies to terminals started after saving.",
50
+ ]
51
+ }]
52
+ }
53
+
54
+ // Called with what the Settings page posted. The row is absent off Windows, and
55
+ // anything but the two choices is ignored.
56
+ const save = (store, config) => {
57
+ const value = config && config[KEY]
58
+ if (value === DEFAULT || value === BUNDLED) store.set(KEY, value)
59
+ }
60
+
61
+ // Extra options for the pty library when a shell is started.
62
+ const ptyOptions = (kernel, available = bundledAvailable) => {
63
+ if (!kernel || kernel.platform !== "win32") return {}
64
+ if (choice(kernel.store) !== BUNDLED) return {}
65
+ return available() ? { useConptyDll: true } : {}
66
+ }
67
+
68
+ module.exports = { KEY, settings, save, ptyOptions, bundledAvailable, bundledFiles }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.18",
3
+ "version": "8.3.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -76,6 +76,7 @@ const Socket = require('./socket')
76
76
  const Kernel = require("../kernel")
77
77
  const packagejson = require("../package.json")
78
78
  const Environment = require("../kernel/environment")
79
+ const WindowsConsole = require("../kernel/windows_console")
79
80
  const Cloudflare = require("../kernel/api/cloudflare")
80
81
  const Util = require("../kernel/util")
81
82
  const Info = require("../kernel/info")
@@ -3309,7 +3310,7 @@ class Server {
3309
3310
  key: "mode",
3310
3311
  val: this.mode,
3311
3312
  options: ["desktop", "background"]
3312
- }, {
3313
+ }, ...WindowsConsole.settings(this.kernel), {
3313
3314
  key: "HTTP_PROXY",
3314
3315
  val: (system_env.HTTP_PROXY || ""),
3315
3316
  show_on_click: "#proxy",
@@ -5571,6 +5572,7 @@ class Server {
5571
5572
  }
5572
5573
  this.kernel.store.set("mode", config.mode)
5573
5574
  }
5575
+ WindowsConsole.save(this.kernel.store, config)
5574
5576
  // // 3. Handle Drive
5575
5577
  // if (config.drive) {
5576
5578
  // // if the home is different from the existing home, go forward
@@ -6084,150 +6086,6 @@ class Server {
6084
6086
  }
6085
6087
  return shellOptions
6086
6088
  }
6087
- normalizeBundledPluginSpec(value) {
6088
- if (this.appRegistry && typeof this.appRegistry.normalizeRelativeScriptPath === "function") {
6089
- return this.appRegistry.normalizeRelativeScriptPath(value)
6090
- }
6091
- if (typeof value !== "string") {
6092
- return ""
6093
- }
6094
- const trimmed = value.trim()
6095
- if (!trimmed) {
6096
- return ""
6097
- }
6098
- const normalized = path.posix.normalize(trimmed.replace(/\\/g, "/"))
6099
- if (!normalized || normalized === "." || normalized.startsWith("../") || normalized.startsWith("/")) {
6100
- return ""
6101
- }
6102
- return normalized
6103
- }
6104
- isValidBundledPluginConfig(pluginConfig) {
6105
- return PluginSources.isValidPluginConfig(pluginConfig)
6106
- }
6107
- isPathInsideRootForBundledPlugin(candidatePath, rootPath) {
6108
- const relative = path.relative(rootPath, candidatePath)
6109
- return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative))
6110
- }
6111
- async getBundledPluginAppDescriptor(appName, metaOverride) {
6112
- if (typeof appName !== "string" || !appName.trim()) {
6113
- return null
6114
- }
6115
- const workspacePath = this.kernel.path("api", appName)
6116
- let meta = metaOverride
6117
- if (!meta) {
6118
- try {
6119
- meta = await this.kernel.api.meta(appName)
6120
- } catch (metaError) {
6121
- console.warn("Failed to load app metadata for bundled plugins", appName, metaError)
6122
- meta = null
6123
- }
6124
- }
6125
- const launcherPath = meta && meta.path ? meta.path : workspacePath
6126
- return {
6127
- name: appName,
6128
- title: meta && meta.title ? meta.title : appName,
6129
- description: meta && meta.description ? meta.description : "",
6130
- icon: meta && meta.icon ? meta.icon : "/pinokio-black.png",
6131
- workspacePath,
6132
- launcherPath,
6133
- meta: meta || {
6134
- title: appName,
6135
- description: "",
6136
- icon: "/pinokio-black.png",
6137
- path: launcherPath
6138
- }
6139
- }
6140
- }
6141
- async getBundledPluginMenuItems(appDescriptor) {
6142
- if (!appDescriptor || !appDescriptor.meta) {
6143
- return []
6144
- }
6145
- const pluginSpecs = Array.isArray(appDescriptor.meta.plugins) ? appDescriptor.meta.plugins : []
6146
- if (pluginSpecs.length === 0) {
6147
- return []
6148
- }
6149
-
6150
- const bundledMenu = []
6151
- for (const pluginSpec of pluginSpecs) {
6152
- const normalizedSpec = this.normalizeBundledPluginSpec(pluginSpec)
6153
- if (!normalizedSpec || path.posix.basename(normalizedSpec) !== "pinokio.js") {
6154
- continue
6155
- }
6156
- const pluginAbsolutePath = path.resolve(appDescriptor.launcherPath, normalizedSpec)
6157
- if (!this.isPathInsideRootForBundledPlugin(pluginAbsolutePath, appDescriptor.launcherPath)) {
6158
- continue
6159
- }
6160
-
6161
- let pluginConfig
6162
- try {
6163
- pluginConfig = (await this.kernel.loader.load(pluginAbsolutePath)).resolved
6164
- } catch (pluginLoadError) {
6165
- console.warn("Failed to load bundled plugin", pluginAbsolutePath, pluginLoadError)
6166
- continue
6167
- }
6168
- if (!this.isValidBundledPluginConfig(pluginConfig)) {
6169
- continue
6170
- }
6171
-
6172
- const pluginRelativePath = path.relative(appDescriptor.workspacePath, pluginAbsolutePath).split(path.sep).join("/")
6173
- const menuItem = {
6174
- ...safeStructuredClone(pluginConfig),
6175
- href: `/run/api/${appDescriptor.name}/${pluginRelativePath}`,
6176
- src: `/api/${appDescriptor.name}/${pluginRelativePath}`,
6177
- ownerApp: {
6178
- name: appDescriptor.name,
6179
- title: appDescriptor.title,
6180
- cwd: appDescriptor.workspacePath
6181
- },
6182
- defaultCwd: appDescriptor.workspacePath
6183
- }
6184
- if (typeof menuItem.text !== "string" || !menuItem.text.trim()) {
6185
- if (typeof menuItem.title === "string" && menuItem.title.trim()) {
6186
- menuItem.text = menuItem.title.trim()
6187
- } else {
6188
- menuItem.text = path.posix.basename(path.posix.dirname(normalizedSpec))
6189
- }
6190
- }
6191
- if (typeof pluginConfig.icon === "string" && pluginConfig.icon.trim()) {
6192
- const iconAbsolutePath = path.resolve(path.dirname(pluginAbsolutePath), pluginConfig.icon)
6193
- if (this.isPathInsideRootForBundledPlugin(iconAbsolutePath, appDescriptor.workspacePath)) {
6194
- const iconRelativePath = path.relative(appDescriptor.workspacePath, iconAbsolutePath).split(path.sep).join("/")
6195
- menuItem.image = `/api/${appDescriptor.name}/${iconRelativePath}?raw=true`
6196
- }
6197
- }
6198
- bundledMenu.push(menuItem)
6199
- }
6200
- return bundledMenu
6201
- }
6202
- async getBundledPluginMenuForApp(appName) {
6203
- const appDescriptor = await this.getBundledPluginAppDescriptor(appName)
6204
- return this.getBundledPluginMenuItems(appDescriptor)
6205
- }
6206
- async getBundledPluginMenu() {
6207
- let apps = []
6208
- try {
6209
- apps = await this.kernel.api.listApps()
6210
- } catch (error) {
6211
- console.warn("Failed to enumerate apps for bundled plugins", error)
6212
- return []
6213
- }
6214
-
6215
- const bundledMenu = []
6216
- for (const app of apps) {
6217
- const appDescriptor = {
6218
- name: app.name,
6219
- title: app.title,
6220
- description: app.description,
6221
- icon: app.icon,
6222
- workspacePath: app.workspace_path,
6223
- launcherPath: app.launcher_path,
6224
- meta: app.meta
6225
- }
6226
- const menuItems = await this.getBundledPluginMenuItems(appDescriptor)
6227
- bundledMenu.push(...menuItems)
6228
- }
6229
- return bundledMenu
6230
- }
6231
6089
  async getPluginGlobal(req, config, terminal, filepath) {
6232
6090
  // if (!this.kernel.plugin.config) {
6233
6091
  // await this.kernel.plugin.init()
@@ -6237,9 +6095,8 @@ class Server {
6237
6095
  c.menu = []
6238
6096
  }
6239
6097
  try {
6240
- const bundledMenu = await this.getBundledPluginMenu()
6241
6098
  let menu = safeStructuredClone(terminal.menu || [])
6242
- c.menu = c.menu.concat(bundledMenu, menu)
6099
+ c.menu = c.menu.concat(menu)
6243
6100
  let info = new Info(this.kernel)
6244
6101
  info.cwd = () => {
6245
6102
  return filepath
@@ -6282,8 +6139,7 @@ class Server {
6282
6139
  try {
6283
6140
  let filepath = this.kernel.path("api", name)
6284
6141
  let terminal = await this.terminals(filepath)
6285
- const bundledMenu = await this.getBundledPluginMenu()
6286
- c.menu = c.menu.concat(bundledMenu, terminal.menu)
6142
+ c.menu = c.menu.concat(terminal.menu)
6287
6143
  let menu = c.menu.map((item) => {
6288
6144
  return {
6289
6145
  params: {
@@ -7664,7 +7520,6 @@ class Server {
7664
7520
  ? trimmed
7665
7521
  : `${trimmed.replace(/\/+$/, "")}/pinokio.js`
7666
7522
  }
7667
- const loadBundledPluginMenu = async () => this.getBundledPluginMenu()
7668
7523
  const evaluatePluginInstalled = async (pluginItem) => {
7669
7524
  if (!PluginSources.isInstalledCheck(pluginItem && pluginItem.installed)) {
7670
7525
  return null
@@ -7737,14 +7592,6 @@ class Server {
7737
7592
  pluginPath: normalizedPluginPath,
7738
7593
  pluginKey: normalizePluginLookupKey(normalizedPluginPath),
7739
7594
  extraParams,
7740
- defaultCwd: typeof pluginItem?.defaultCwd === "string" ? pluginItem.defaultCwd : "",
7741
- ownerApp: pluginItem && pluginItem.ownerApp && typeof pluginItem.ownerApp === "object"
7742
- ? {
7743
- name: typeof pluginItem.ownerApp.name === "string" ? pluginItem.ownerApp.name : "",
7744
- title: typeof pluginItem.ownerApp.title === "string" ? pluginItem.ownerApp.title : "",
7745
- cwd: typeof pluginItem.ownerApp.cwd === "string" ? pluginItem.ownerApp.cwd : "",
7746
- }
7747
- : null,
7748
7595
  hasInstall: PluginSources.isAction(pluginItem?.install),
7749
7596
  hasUninstall: PluginSources.isAction(pluginItem?.uninstall),
7750
7597
  hasUpdate: PluginSources.isAction(pluginItem?.update),
@@ -7772,14 +7619,7 @@ class Server {
7772
7619
  } catch (err) {
7773
7620
  console.warn("Failed to initialize plugins", err)
7774
7621
  }
7775
- let bundledPluginMenu = []
7776
- try {
7777
- bundledPluginMenu = await loadBundledPluginMenu()
7778
- } catch (bundledError) {
7779
- console.warn("Failed to load bundled plugins", bundledError)
7780
- }
7781
- const mergedPluginMenu = pluginMenu.concat(bundledPluginMenu)
7782
- return Promise.all(mergedPluginMenu.map((pluginItem, index) => serializePluginMenuItem(pluginItem, index)))
7622
+ return Promise.all(pluginMenu.map((pluginItem, index) => serializePluginMenuItem(pluginItem, index)))
7783
7623
  }
7784
7624
  const buildPluginCategories = (plugins) => {
7785
7625
  const buckets = { ide: [], cli: [] }
@@ -7903,8 +7743,6 @@ class Server {
7903
7743
  pluginPath: normalizedPluginPath,
7904
7744
  pluginKey: normalizePluginLookupKey(normalizedPluginPath),
7905
7745
  extraParams: [],
7906
- defaultCwd: "",
7907
- ownerApp: null,
7908
7746
  hasInstall: !!context.hasInstall,
7909
7747
  hasUninstall: !!context.hasUninstall,
7910
7748
  hasUpdate: !!context.hasUpdate,
@@ -10764,7 +10602,7 @@ class Server {
10764
10602
  key: "mode",
10765
10603
  val: this.mode,
10766
10604
  options: ["desktop", "background"]
10767
- }, {
10605
+ }, ...WindowsConsole.settings(this.kernel), {
10768
10606
  key: "HTTP_PROXY",
10769
10607
  val: (system_env.HTTP_PROXY || ""),
10770
10608
  show_on_click: "#proxy",
@@ -121,21 +121,6 @@ function createContentValidationService({ kernel }) {
121
121
  return PluginSources.normalizePluginPath(value)
122
122
  }
123
123
 
124
- const normalizeBundledPluginSpec = (value) => {
125
- if (typeof value !== "string") {
126
- return ""
127
- }
128
- const trimmed = value.trim()
129
- if (!trimmed) {
130
- return ""
131
- }
132
- const normalized = path.posix.normalize(trimmed.replace(/\\/g, "/"))
133
- if (!normalized || normalized === "." || normalized.startsWith("../") || normalized.startsWith("/")) {
134
- return ""
135
- }
136
- return normalized
137
- }
138
-
139
124
  const buildPluginContext = ({ normalizedPath, absolutePath, config }) => {
140
125
  const pluginDir = path.dirname(absolutePath)
141
126
  const title = config && typeof config.title === "string" && config.title.trim()
@@ -403,26 +388,6 @@ function createContentValidationService({ kernel }) {
403
388
  { file: appJson.exists ? appJsonPath : launcherScriptPath }
404
389
  ))
405
390
  }
406
- if ("plugins" in merged) {
407
- if (!Array.isArray(merged.plugins)) {
408
- errors.push(buildError(
409
- "App plugins must be declared as an array.",
410
- "Set `plugins` to an array of relative pinokio.js paths.",
411
- { file: launcherScriptPath }
412
- ))
413
- } else {
414
- merged.plugins.forEach((pluginSpec, index) => {
415
- const normalizedSpec = normalizeBundledPluginSpec(pluginSpec)
416
- if (!normalizedSpec || path.posix.basename(normalizedSpec) !== "pinokio.js") {
417
- errors.push(buildError(
418
- `plugins[${index}] must point to a relative pinokio.js file.`,
419
- "Use entries like `plugins/no-gateway/pinokio.js`.",
420
- { file: launcherScriptPath }
421
- ))
422
- }
423
- })
424
- }
425
- }
426
391
  }
427
392
 
428
393
  if (errors.length > 0) {
@@ -820,6 +820,8 @@
820
820
  const frameUrl = settings.launchUrl || session.url;
821
821
  if (frameUrl && (settings.launchUrl || !part.frame.dataset.url)) {
822
822
  part.frame.dataset.url = frameUrl;
823
+ // Restoring a session must leave focus on the page that just opened.
824
+ part.frame.toggleAttribute('data-skip-startup-focus', settings.still === true);
823
825
  part.frame.src = frameUrl;
824
826
  embedSoon(win);
825
827
  }
@@ -902,6 +904,7 @@
902
904
  whenRunning(session, () => {
903
905
  if (!wins.has(win.key)) return;
904
906
  win.part.frame.dataset.url = session.url;
907
+ win.part.frame.removeAttribute('data-skip-startup-focus');
905
908
  win.part.frame.src = session.url;
906
909
  embedSoon(win);
907
910
  });
@@ -300,9 +300,6 @@
300
300
  if (!normalizedPath) return null;
301
301
  const encodedPath = normalizedPath.split("/").map((segment) => encodeURIComponent(segment)).join("/");
302
302
  const params = new URLSearchParams();
303
- if (plugin.defaultCwd) {
304
- params.set("cwd", plugin.defaultCwd);
305
- }
306
303
  params.set("__pinokio_event_panel", "1");
307
304
  params.set("ts", String(Date.now()));
308
305
  return `/action/${encodeURIComponent(actionType)}/${encodedPath}?${params.toString()}`;
@@ -320,7 +320,6 @@
320
320
  pluginPath: plugin.pluginPath || "",
321
321
  cwd: currentPluginCwd,
322
322
  extraParams: Array.isArray(plugin.extraParams) ? plugin.extraParams : [],
323
- defaultCwd: plugin.defaultCwd || "",
324
323
  hasInstall: !!plugin.hasInstall,
325
324
  hasUninstall: !!plugin.hasUninstall,
326
325
  hasUpdate: !!plugin.hasUpdate,
@@ -1789,7 +1789,7 @@ document.addEventListener("DOMContentLoaded", async () => {
1789
1789
  this.tabCaptionHelper = window.PinokioTabCaptionHelper.attach(term, { tracker: this.inputTracker })
1790
1790
 
1791
1791
  }
1792
- this.term.focus()
1792
+ if (!window.frameElement?.hasAttribute('data-skip-startup-focus')) this.term.focus()
1793
1793
  this.observer = new ResizeObserver(() => {
1794
1794
  this.fit.fit()
1795
1795
  this.resizeSync.sendResize(this.term.cols, this.term.rows)
@@ -3245,7 +3245,7 @@ document.addEventListener("DOMContentLoaded", async () => {
3245
3245
  this.tabCaptionHelper = window.PinokioTabCaptionHelper.attach(term, { tracker: this.inputTracker })
3246
3246
 
3247
3247
  }
3248
- this.term.focus()
3248
+ if (!window.frameElement?.hasAttribute('data-skip-startup-focus')) this.term.focus()
3249
3249
  this.observer = new ResizeObserver(() => {
3250
3250
  this.fit.fit()
3251
3251
  this.resizeSync.sendResize(this.term.cols, this.term.rows)
@@ -136,12 +136,29 @@ function runSteps(kernel, info, context, options = {}) {
136
136
  }]
137
137
  }
138
138
 
139
+ // The same agent's one-off command: it does the request, prints its answer and
140
+ // ends. It is started with permission to act, since nobody is there to give it.
141
+ function jobSteps(kernel, info, context) {
142
+ return [{
143
+ method: "shell.run",
144
+ params: {
145
+ conda: { skip: true },
146
+ message: {
147
+ _: [binaryPath(kernel, currentPlatform(kernel)), "--dangerously-skip-permissions"],
148
+ print: promptFor(context)
149
+ },
150
+ path: workspaceFor(context, kernel),
151
+ }
152
+ }]
153
+ }
154
+
139
155
  module.exports = {
140
156
  binaryPath,
141
157
  installDir,
142
158
  installed,
143
159
  installerPath,
144
160
  installSteps,
161
+ jobSteps,
145
162
  metadataPath,
146
163
  pluginDetailHref,
147
164
  runSteps,
@@ -10,4 +10,5 @@ module.exports = {
10
10
  uninstall: antigravity.uninstallSteps,
11
11
  installed: antigravity.installed,
12
12
  run: antigravity.runSteps,
13
+ job: antigravity.jobSteps,
13
14
  }
@@ -47,5 +47,18 @@ module.exports = {
47
47
  buffer: 1024,
48
48
  input: true
49
49
  }
50
+ }],
51
+ // The same agent's one-off command: it does the request, prints its answer and
52
+ // ends. It is started with permission to act, since nobody is there to give it.
53
+ job: [{
54
+ method: "shell.run",
55
+ params: {
56
+ conda,
57
+ message: {
58
+ _: [agy, "--dangerously-skip-permissions"],
59
+ print: "{{args.prompt}}"
60
+ },
61
+ path: "{{args.cwd}}"
62
+ }
50
63
  }]
51
64
  }
@@ -40,5 +40,44 @@ module.exports = {
40
40
  input: true,
41
41
  buffer: 1024
42
42
  }
43
+ }],
44
+ // The same agent's one-off command: it does the request, prints its answer and
45
+ // ends. It is started with permission to act, since nobody is there to give it.
46
+ job: [{
47
+ when: "{{platform === 'win32'}}",
48
+ method: "shell.run",
49
+ params: {
50
+ shell: "bash",
51
+ conda: {
52
+ skip: true
53
+ },
54
+ message: {
55
+ _: [
56
+ "npx",
57
+ "-y",
58
+ "@xai-official/grok@latest",
59
+ "--always-approve",
60
+ "--single",
61
+ "{{args.prompt}}"
62
+ ]
63
+ },
64
+ path: "{{args.cwd}}"
65
+ }
66
+ }, {
67
+ when: "{{platform !== 'win32'}}",
68
+ method: "shell.run",
69
+ params: {
70
+ message: {
71
+ _: [
72
+ "npx",
73
+ "-y",
74
+ "@xai-official/grok@latest",
75
+ "--always-approve",
76
+ "--single",
77
+ "{{args.prompt}}"
78
+ ]
79
+ },
80
+ path: "{{args.cwd}}"
81
+ }
43
82
  }]
44
83
  }
@@ -43,5 +43,44 @@ module.exports = {
43
43
  input: true,
44
44
  buffer: 1024
45
45
  }
46
+ }],
47
+ // The same agent's one-off command: it does the request, prints its answer and
48
+ // ends. It is started with permission to act, since nobody is there to give it.
49
+ job: [{
50
+ when: "{{platform === 'win32'}}",
51
+ method: "shell.run",
52
+ params: {
53
+ shell: "bash",
54
+ conda: {
55
+ skip: true
56
+ },
57
+ message: {
58
+ _: [
59
+ "npx",
60
+ "-y",
61
+ "@xai-official/grok@latest",
62
+ "--always-approve",
63
+ "--single",
64
+ "{{args.prompt}}"
65
+ ]
66
+ },
67
+ path: "{{args.cwd}}"
68
+ }
69
+ }, {
70
+ when: "{{platform !== 'win32'}}",
71
+ method: "shell.run",
72
+ params: {
73
+ message: {
74
+ _: [
75
+ "npx",
76
+ "-y",
77
+ "@xai-official/grok@latest",
78
+ "--always-approve",
79
+ "--single",
80
+ "{{args.prompt}}"
81
+ ]
82
+ },
83
+ path: "{{args.cwd}}"
84
+ }
46
85
  }]
47
86
  }
@@ -13,6 +13,97 @@ class TerminalPage extends ResourceLoader {
13
13
  }
14
14
  }
15
15
 
16
+ class StartupTerminalPage extends ResourceLoader {
17
+ fetch(url) {
18
+ const view = new URL(url).pathname.startsWith('/shell/') ? 'shell' : 'terminal'
19
+ const template = fs.readFileSync(path.resolve(__dirname, '../server/views', `${view}.ejs`), 'utf8')
20
+ const startup = template.match(/^ {6}(.*this\.term\.focus\(\))\n {6}this\.observer = new ResizeObserver/m)
21
+ assert.ok(startup, `${view} has a terminal startup focus statement`)
22
+ return Promise.resolve(Buffer.from(`<!doctype html><textarea></textarea><script>
23
+ window.focus = () => {};
24
+ const term = {
25
+ focus() {
26
+ document.querySelector('textarea').focus();
27
+ // JSDOM moves focus into the frame but omits the parent window's blur.
28
+ window.parent.dispatchEvent(new window.parent.Event('blur'));
29
+ },
30
+ onRender() {},
31
+ };
32
+ window.PinokioTerminalSettings = { terminals: new Map([[1, term]]) };
33
+ (function () { ${startup[1]} }).call({ term });
34
+ </script>`))
35
+ }
36
+ }
37
+
38
+ test('restoring agent and shell windows leaves a prefilled composer focused', { timeout: 3000 }, async (t) => {
39
+ const dom = new JSDOM('<!doctype html><body class="main-sidebar-page"><header class="navheader"><h1><div class="flexible"></div></h1></header></body>', {
40
+ url: 'https://pinokio.example/home?universal=&type=create_app&prompt=Build',
41
+ resources: new StartupTerminalPage(),
42
+ runScripts: 'dangerously',
43
+ pretendToBeVisual: true,
44
+ })
45
+ t.after(() => dom.window.close())
46
+ const { window } = dom
47
+ const { document } = window
48
+ window.innerWidth = 1760
49
+ window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
50
+ window.Element.prototype.getBoundingClientRect = () => ({ left: 300, top: 8, right: 900, bottom: 40, width: 600, height: 32 })
51
+ const shell = 'shell/demo_bash?session=shell'
52
+ const running = [
53
+ { id: 'agent', group: '/home/plugin/codex/pinokio.js?cwd=/home/brain&session=agent' },
54
+ { id: shell, path: '/home/api/demo' },
55
+ ]
56
+ window.sessionStorage.setItem('pinokio.agentBar.dock.tabs', JSON.stringify([
57
+ { key: '/plugin/codex/pinokio.js|/home/brain|agent', kind: 'agent', open: true, docked: true, z: 1 },
58
+ { key: shell, kind: 'shell', open: true, z: 2 },
59
+ ]))
60
+ let publishRunning
61
+ const runningResponse = new Promise((resolve) => { publishRunning = resolve })
62
+ window.fetch = async (url) => {
63
+ if (url === '/info/shells') return runningResponse
64
+ return { ok: true, json: async () => ({
65
+ menu: [{ href: '/pinokio/run/plugin/codex/pinokio.js', title: 'Codex', default: true }],
66
+ projectShell: { items: [{ href: '/shell/demo_bash', title: 'Bash' }] },
67
+ }) }
68
+ }
69
+ const restored = new Promise((resolve) => {
70
+ const frames = []
71
+ const loaded = (event) => {
72
+ const frame = event.target
73
+ if (!frame.matches?.('.agent-bar-panel__frame') || !frame.contentWindow.PinokioTerminalSettings) return
74
+ frames.push(frame)
75
+ if (frames.length === 2) {
76
+ document.removeEventListener('load', loaded, true)
77
+ resolve(frames)
78
+ }
79
+ }
80
+ document.addEventListener('load', loaded, true)
81
+ })
82
+ for (const name of ['agent-bar.js', 'agent-bar-compose.js', 'agent-bar-panel.js']) window.eval(script(name))
83
+ await window.PinokioAgentBar.ready
84
+ assert.equal(window.PinokioAgentBar.open({ type: 'create_app', prompt: 'Build' }), true)
85
+ const bar = document.querySelector('.agent-bar')
86
+ const draft = bar.querySelector('textarea')
87
+ const settleFocus = () => new Promise((resolve) => window.setTimeout(resolve, 0))
88
+ assert.equal(bar.dataset.compose, 'centre')
89
+ publishRunning({ ok: true, json: async () => running })
90
+ const frames = await restored
91
+ await settleFocus()
92
+ assert.equal(bar.dataset.compose, 'centre')
93
+ assert.equal(document.activeElement, draft)
94
+ assert.equal(draft.value, 'Build')
95
+
96
+ const shellFrame = frames.find((frame) => new URL(frame.src).pathname.startsWith('/shell/'))
97
+ const panel = shellFrame.closest('aside')
98
+ const refreshed = new Promise((resolve) => shellFrame.addEventListener('load', resolve, { once: true }))
99
+ panel.querySelector('[aria-label="More"]').click()
100
+ Array.from(panel.querySelectorAll('.agent-dock__more-row')).find((row) => row.textContent === 'Refresh').click()
101
+ await refreshed
102
+ await settleFocus()
103
+ assert.equal(document.activeElement, shellFrame, 'an explicit refresh still focuses the terminal')
104
+ assert.equal(bar.dataset.compose, undefined)
105
+ })
106
+
16
107
  test('the mobile Agent Bar panel stays under a terminal tap until Safari delivers its click', async (t) => {
17
108
  const dom = new JSDOM('<!doctype html><body class="app-page"></body>', {
18
109
  url: 'https://pinokio.example/p/demo',
@@ -192,6 +192,39 @@ test("Antigravity CLI Auto adds the current permission-skip flag", async () => {
192
192
  }
193
193
  })
194
194
 
195
+ test("both Antigravity CLI plugins have a job: the one-off command, with the request and the folder", async () => {
196
+ const root = await fsp.mkdtemp(path.join(os.tmpdir(), "pinokio-antigravity-job-"))
197
+ try {
198
+ const kernel = createKernel(root)
199
+ const args = { cwd: "/tmp/workspace", prompt: "My message is in jobs/j1/request.md." }
200
+
201
+ const [plain] = antigravityCli.job(kernel, {}, { args, input: {} })
202
+ assert.equal(plain.method, "shell.run")
203
+ assert.deepEqual(plain.params.message, {
204
+ _: [antigravityCommon.binaryPath(kernel, "darwin"), "--dangerously-skip-permissions"],
205
+ print: args.prompt,
206
+ })
207
+ assert.equal(plain.params.path, "/tmp/workspace")
208
+ assert.equal("input" in plain.params, false, "nobody is there to type")
209
+
210
+ const template = new Template()
211
+ await template.init({})
212
+ assert.equal(antigravityCliAuto.job.length, 1)
213
+ const [step] = antigravityCliAuto.job
214
+ for (const platform of ["darwin", "win32"]) {
215
+ const params = template.render(step.params, { platform, kernel, args, input: {} })
216
+ assert.deepEqual(params.message, {
217
+ _: [path.join(root, "plugin", "antigravity-cli-auto", "runtime", platform === "win32" ? "agy.exe" : "agy"), "--dangerously-skip-permissions"],
218
+ print: args.prompt,
219
+ })
220
+ assert.equal(params.path, "/tmp/workspace")
221
+ assert.equal("input" in params, false)
222
+ }
223
+ } finally {
224
+ await fsp.rm(root, { recursive: true, force: true })
225
+ }
226
+ })
227
+
195
228
  test("Antigravity CLI run asks for Pinokio install when managed binary is missing", async () => {
196
229
  const root = await fsp.mkdtemp(path.join(os.tmpdir(), "pinokio-antigravity-missing-"))
197
230
  try {
@@ -0,0 +1,61 @@
1
+ "use strict"
2
+
3
+ // An app's launcher used to be able to declare plugins of its own in a
4
+ // `plugins` list. Pinokio no longer reads that list: plugins come with Pinokio
5
+ // or live in the plugin folder, and nowhere else.
6
+
7
+ const test = require("node:test")
8
+ const assert = require("node:assert/strict")
9
+ const fs = require("fs")
10
+ const os = require("os")
11
+ const path = require("path")
12
+ const { createContentValidationService } = require("../server/lib/content_validation")
13
+ const { loadPluginMenu } = require("../kernel/plugin_sources")
14
+
15
+ const withHome = async (run) => {
16
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), "pinokio-app-plugins-"))
17
+ try {
18
+ await run(home)
19
+ } finally {
20
+ fs.rmSync(home, { recursive: true, force: true })
21
+ }
22
+ }
23
+ const PLUGIN = 'module.exports = { title: "From an app", run: [{ method: "shell.run", params: { message: "echo hi", path: "{{args.cwd}}" } }] }\n'
24
+
25
+ test("a plugins list in an app's launcher is not checked: the field means nothing", async () => {
26
+ await withHome(async (home) => {
27
+ const app = path.join(home, "api", "demo")
28
+ fs.mkdirSync(app, { recursive: true })
29
+ const kernel = { path: (...parts) => path.join(home, ...parts), api: { launcher_path: async () => app } }
30
+ const validation = createContentValidationService({ kernel })
31
+ // a list, and two shapes that were errors while the list was read
32
+ for (const plugins of ['["plugins/tool/pinokio.js"]', '"plugins/tool/pinokio.js"', '["../outside.js"]']) {
33
+ fs.writeFileSync(path.join(app, "pinokio.js"), `module.exports = { title: "Demo", plugins: ${plugins}, menu: [] }\n`)
34
+ const result = await validation.validateAppByName("demo")
35
+ assert.equal(result.valid, true, `plugins: ${plugins}`)
36
+ assert.deepEqual(result.errors, [])
37
+ }
38
+ })
39
+ })
40
+
41
+ test("a plugin file inside an app's folder is not in the plugin list", async () => {
42
+ await withHome(async (home) => {
43
+ const inApp = path.join(home, "api", "demo", "plugins", "tool")
44
+ const inPluginFolder = path.join(home, "plugin", "tool")
45
+ fs.mkdirSync(inApp, { recursive: true })
46
+ fs.mkdirSync(inPluginFolder, { recursive: true })
47
+ fs.writeFileSync(path.join(home, "api", "demo", "pinokio.js"), 'module.exports = { title: "Demo", plugins: ["plugins/tool/pinokio.js"], menu: [] }\n')
48
+ fs.writeFileSync(path.join(inApp, "pinokio.js"), PLUGIN)
49
+ fs.writeFileSync(path.join(inPluginFolder, "pinokio.js"), PLUGIN.replace("From an app", "In the plugin folder").replace("{ title", '{ path: "plugin", title'))
50
+
51
+ const kernel = { homedir: home, require: async (file) => require(file) }
52
+ const titles = (await loadPluginMenu(kernel)).filter((plugin) => plugin.source === "local").map((plugin) => plugin.title)
53
+ assert.deepEqual(titles, ["In the plugin folder"])
54
+ })
55
+ })
56
+
57
+ test("nothing in the server reads an app's plugins list", () => {
58
+ const server = fs.readFileSync(path.resolve(__dirname, "../server/index.js"), "utf8")
59
+ assert.equal(/meta\.plugins\b/.test(server), false)
60
+ assert.equal(/ownerApp/.test(server), false, "no plugin is owned by an app")
61
+ })
@@ -77,3 +77,21 @@ test("Grok Build Auto shares the base wrapper and enables always-approve", () =>
77
77
 
78
78
  assert.equal(grok.run.every((step) => !step.params.message._.includes("--always-approve")), true)
79
79
  })
80
+
81
+ test("both Grok plugins have a job: the single-turn command, with the request and the folder", () => {
82
+ for (const plugin of [grok, grokAuto]) {
83
+ assert.equal(plugin.job.length, 2)
84
+ for (const step of plugin.job) {
85
+ assert.equal(step.method, "shell.run")
86
+ assert.deepEqual(step.params.message, {
87
+ _: ["npx", "-y", "@xai-official/grok@latest", "--always-approve", "--single", "{{args.prompt}}"]
88
+ })
89
+ assert.equal(step.params.path, "{{args.cwd}}")
90
+ assert.equal("input" in step.params, false, "nobody is there to type")
91
+ }
92
+ assert.match(plugin.job[0].when, /=== 'win32'/)
93
+ assert.equal(plugin.job[0].params.shell, "bash")
94
+ assert.match(plugin.job[1].when, /!== 'win32'/)
95
+ assert.equal("shell" in plugin.job[1].params, false)
96
+ }
97
+ })
@@ -15,7 +15,6 @@ function basePlugin(overrides = {}) {
15
15
  icon: "fa-solid fa-terminal",
16
16
  pluginPath: "/plugin/demo/pinokio.js",
17
17
  extraParams: [],
18
- defaultCwd: "",
19
18
  hasInstall: true,
20
19
  hasUpdate: true,
21
20
  hasUninstall: true,
@@ -0,0 +1,105 @@
1
+ // The Windows console choice (kernel/windows_console.js): the row it adds to
2
+ // the Settings page, what saving it stores, and the option it hands the pty
3
+ // library when a shell starts. No shell is started here, and none of it runs
4
+ // the bundled console layer itself: that exists only on Windows.
5
+ const assert = require('node:assert/strict')
6
+ const fs = require('node:fs')
7
+ const os = require('node:os')
8
+ const path = require('node:path')
9
+ const test = require('node:test')
10
+ const ejs = require('ejs')
11
+
12
+ const WindowsConsole = require('../kernel/windows_console')
13
+
14
+ const store = (initial = {}) => {
15
+ const data = { ...initial }
16
+ return { get: (key) => (key in data ? data[key] : null), set: (key, val) => { data[key] = val }, data }
17
+ }
18
+ const kernel = (platform, initial) => ({ platform, store: store(initial) })
19
+ const present = () => true
20
+ const missing = () => false
21
+
22
+ test('the Settings row exists on Windows only and starts on the built-in layer', () => {
23
+ assert.deepEqual(WindowsConsole.settings(kernel('darwin')), [])
24
+ assert.deepEqual(WindowsConsole.settings(kernel('linux')), [])
25
+
26
+ const [row, ...rest] = WindowsConsole.settings(kernel('win32'))
27
+ assert.equal(rest.length, 0)
28
+ assert.equal(row.key, 'windows_console')
29
+ assert.equal(row.val, 'default')
30
+ assert.deepEqual(row.options, ['default', 'bundled'])
31
+
32
+ assert.equal(WindowsConsole.settings(kernel('win32', { windows_console: 'bundled' }))[0].val, 'bundled')
33
+ // a value nobody could have picked reads as the built-in layer
34
+ assert.equal(WindowsConsole.settings(kernel('win32', { windows_console: 'nonsense' }))[0].val, 'default')
35
+ })
36
+
37
+ test('saving stores one of the two choices and nothing else', () => {
38
+ const s = store()
39
+ WindowsConsole.save(s, { theme: 'dark' }) // the row is absent off Windows
40
+ assert.deepEqual(s.data, {})
41
+ WindowsConsole.save(s, { windows_console: 'nonsense' })
42
+ assert.deepEqual(s.data, {})
43
+ WindowsConsole.save(s, { windows_console: 'bundled' })
44
+ assert.deepEqual(s.data, { windows_console: 'bundled' })
45
+ WindowsConsole.save(s, { windows_console: 'default' })
46
+ assert.deepEqual(s.data, { windows_console: 'default' })
47
+ })
48
+
49
+ test('a shell gets the bundled layer only on Windows, only when chosen, only when its files are there', () => {
50
+ const chosen = { windows_console: 'bundled' }
51
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', chosen), present), { useConptyDll: true })
52
+
53
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32'), present), {})
54
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', { windows_console: 'default' }), present), {})
55
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('darwin', chosen), present), {})
56
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('linux', chosen), present), {})
57
+ // chosen, but the install has no copy: the shell starts as it always did
58
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', chosen), missing), {})
59
+ })
60
+
61
+ test('the choice is read each time a shell starts', () => {
62
+ const k = kernel('win32')
63
+ assert.deepEqual(WindowsConsole.ptyOptions(k, present), {})
64
+ WindowsConsole.save(k.store, { windows_console: 'bundled' })
65
+ assert.deepEqual(WindowsConsole.ptyOptions(k, present), { useConptyDll: true })
66
+ WindowsConsole.save(k.store, { windows_console: 'default' })
67
+ assert.deepEqual(WindowsConsole.ptyOptions(k, present), {})
68
+ })
69
+
70
+ test('the bundled layer counts as there only when both of its files are', (t) => {
71
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pinokio-conpty-'))
72
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }))
73
+ const files = ['conpty.dll', 'OpenConsole.exe'].map((name) => path.join(dir, name))
74
+ assert.equal(WindowsConsole.bundledAvailable(files), false)
75
+ fs.writeFileSync(files[0], '')
76
+ assert.equal(WindowsConsole.bundledAvailable(files), false)
77
+ fs.writeFileSync(files[1], '')
78
+ assert.equal(WindowsConsole.bundledAvailable(files), true)
79
+
80
+ // looked for where the pty library's install step puts them
81
+ const expected = WindowsConsole.bundledFiles().map((file) => file.split(path.sep).slice(-4).join('/'))
82
+ assert.deepEqual(expected, ['build/Release/conpty/conpty.dll', 'build/Release/conpty/OpenConsole.exe'])
83
+ })
84
+
85
+ test('the pty library still takes the option this hands it', () => {
86
+ // The option is passed straight to the library. If an upgrade renames or
87
+ // drops it, the Settings choice would silently do nothing.
88
+ const root = path.dirname(require.resolve('@homebridge/node-pty-prebuilt-multiarch/package.json'))
89
+ const source = fs.readFileSync(path.join(root, 'lib', 'windowsTerminal.js'), 'utf8')
90
+ assert.match(source, /opt\.useConptyDll/)
91
+ })
92
+
93
+ test('the Settings page draws the row as a dropdown with its explanation', async () => {
94
+ const view = fs.readFileSync(path.resolve(__dirname, '../server/views/settings.ejs'), 'utf8')
95
+ // the General form's loop over the rows, as the page has it
96
+ const start = view.indexOf('<% config.forEach((c) => { %>')
97
+ const end = view.indexOf('<% }) %>', view.indexOf("<div class='explanation'><%=c.description%></div>")) + '<% }) %>'.length
98
+ assert.ok(start > 0 && end > start)
99
+ const html = ejs.render(view.slice(start, end), { config: WindowsConsole.settings(kernel('win32', { windows_console: 'bundled' })) })
100
+
101
+ assert.match(html, /<select name="windows_console">/)
102
+ assert.match(html, /<option value="default">default<\/option>/)
103
+ assert.match(html, /<option value="bundled" selected>bundled<\/option>/)
104
+ assert.equal((html.match(/class='explanation'/g) || []).length, 2)
105
+ })