Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

Windows folder window: the host waits for the window to report it is opening and otherwise asks for the path in words, so the button is released; Add skill from another computer says why it cannot

Niko1221e0aa3b872afb
diff --git a/apps/host/server/folder-dialog.mjs b/apps/host/server/folder-dialog.mjs
index bb2a9d365..8821bd196 100644
--- a/apps/host/server/folder-dialog.mjs
+++ b/apps/host/server/folder-dialog.mjs
@@ -23,6 +23,8 @@ export function windowsFolderScript(prompt) {
'$dialog = New-Object System.Windows.Forms.FolderBrowserDialog',
`$dialog.Description = '${text}'`,
'$dialog.ShowNewFolderButton = $true',
+ // READY tells the host the window is about to open; a host that never sees it gives up and asks for the path in words (QA F06).
+ '[Console]::Out.WriteLine("READY"); [Console]::Out.Flush()',
'if ($dialog.ShowDialog($owner) -eq "OK") { [Console]::Out.Write($dialog.SelectedPath) }',
'$owner.Close()',
].join('; ');
@@ -42,11 +44,33 @@ export function cleanChosenPath(value) {
const missing = error => error?.code === 'ENOENT';
+/** What the script printed, without its READY line. */
+const answerOf = stdout => String(stdout ?? '').split(/\r?\n/).filter(line => line.trim() && line.trim() !== 'READY').join('\n');
+
+/**
+ * Runs the Windows dialog and watches it. Resolves { stdout } when it ends, { noDialog: true } when its window never got as far as
+ * opening (no READY within `readyMs`: PowerShell blocked, stuck or without a desktop), and rejects with { code } as exec does.
+ * The person's own time with the open dialog is not limited (a day at most).
+ */
+export function watchedWindowsDialog(shell, args, { readyMs = 30_000, openMs = 24 * 3600_000, spawnProcess = spawn } = {}) {
+ return new Promise((resolve, reject) => {
+ const child = spawnProcess(shell, args, { windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
+ let stdout = '', ready = false, settled = false;
+ const end = (fn, value) => { if (settled) return; settled = true; clearTimeout(timer); try { child.kill(); } catch { /* gone */ } fn(value); };
+ const timer = setTimeout(() => end(resolve, ready ? { stdout: '' } : { noDialog: true }), readyMs);
+ const later = () => { clearTimeout(timer); ready = true; setTimeout(() => end(resolve, { stdout: '' }), openMs).unref?.(); };
+ child.stdout?.on('data', chunk => { stdout += chunk; if (!ready && /^READY\s*$/m.test(stdout)) { clearTimeout(timer); later(); } });
+ child.on('error', error => end(reject, error));
+ child.on('close', code => { if (settled) return; settled = true; clearTimeout(timer); code === 0 ? resolve({ stdout }) : reject(Object.assign(new Error('exit ' + code), { code })); });
+ });
+}
+
/**
* Ask for a folder. Resolves { path } | { cancelled: true } | { unavailable: true, reason }.
* `run` is injectable for tests: (command, args) => Promise<{ stdout }>.
*/
-export async function chooseFolder(prompt, { platform = process.platform, run = exec, portal = portalFolder } = {}) {
+export async function chooseFolder(prompt, options = {}) {
+ const { platform = process.platform, run = exec, portal = portalFolder, windowsDialog = options.run ? null : watchedWindowsDialog } = options;
if (platform === 'darwin') {
try {
const { stdout } = await run('osascript', ['-e', MAC_SCRIPT(prompt)]);
@@ -58,8 +82,10 @@ export async function chooseFolder(prompt, { platform = process.platform, run =
if (platform === 'win32') {
const shell = `${process.env.SystemRoot || 'C:\\Windows'}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
try {
- const { stdout } = await run(shell, windowsFolderArgs(prompt));
- return stdout.trim() ? { path: cleanChosenPath(stdout) } : { cancelled: true };
+ const done = windowsDialog ? await windowsDialog(shell, windowsFolderArgs(prompt)) : await run(shell, windowsFolderArgs(prompt));
+ if (done.noDialog) return { unavailable: true, failed: true, reason: 'The folder window did not open. Type the folder path instead.' };
+ const answer = answerOf(done.stdout).trim();
+ return answer ? { path: cleanChosenPath(answer) } : { cancelled: true };
} catch (error) {
if (missing(error)) return { unavailable: true, reason: 'Windows PowerShell was not found.' };
throw new Error('The folder chooser could not open.');
diff --git a/apps/host/src/lib/folder-pick.ts b/apps/host/src/lib/folder-pick.ts
index 81bef53e8..08dbe38b0 100644
--- a/apps/host/src/lib/folder-pick.ts
+++ b/apps/host/src/lib/folder-pick.ts
@@ -43,3 +43,8 @@ export async function postWithFolderFallback<T>(url: string): Promise<T | { canc
}
}
}
+
+/** Is this page open on the computer that runs Strata? A folder window opens on that computer's screen, so a page opened from another one cannot use it. */
+export function pageIsOnThisComputer(hostname: string): boolean {
+ return /^(localhost|127(\.\d{1,3}){3}|\[?::1\]?)$/i.test(hostname);
+}
diff --git a/apps/host/src/screens/Skills.tsx b/apps/host/src/screens/Skills.tsx
index 1a4c5be92..8fc6ab73d 100644
--- a/apps/host/src/screens/Skills.tsx
+++ b/apps/host/src/screens/Skills.tsx
@@ -4,7 +4,7 @@ import { useState } from 'react';
import { Btn, Dialog, Empty, Icon, IconBtn, Select, ErrorNotice } from '../components/ui';
import { Screen } from '../components/layout';
import { api } from '../lib/client';
-import { postWithFolderFallback } from '../lib/folder-pick';
+import { pageIsOnThisComputer, postWithFolderFallback } from '../lib/folder-pick';
import { editSkill, loadSkills, toggleSkill, useStore } from '../lib/store';
import type { Skill } from '../lib/types';
export function SkillsScreen() {
@@ -32,6 +32,9 @@ export function SkillsScreen() {
}
}
async function add() {
+ // The folder window opens on the computer that runs Strata. From a page on another computer there is nothing to see, so say so instead of waiting.
+ if (!pageIsOnThisComputer(window.location.hostname))
+ throw new Error(tr("Adding a skill opens a folder window on the computer that runs Strata. Open Strata on that computer to add one."));
const result = await postWithFolderFallback<{
cancelled?: boolean;
added?: string;
diff --git a/apps/host/tests/folder-dialog.test.mjs b/apps/host/tests/folder-dialog.test.mjs
index 5c41dba78..0fde55a3a 100644
--- a/apps/host/tests/folder-dialog.test.mjs
+++ b/apps/host/tests/folder-dialog.test.mjs
@@ -119,3 +119,39 @@ test('the host accepts a typed folder path for the picker and for adding a skill
await rm(home, { recursive: true, force: true }).catch(() => {});
}
});
+
+// QA report F06: a Windows folder window that never opens must not leave the button disabled forever.
+import { EventEmitter } from 'node:events';
+import { watchedWindowsDialog } from '../server/folder-dialog.mjs';
+function fakeShell() {
+ const child = new EventEmitter(); child.stdout = new EventEmitter(); child.killed = false; child.kill = () => { child.killed = true; };
+ return { child, spawnProcess: () => child };
+}
+test('Windows: no READY from the dialog script means the host gives up and the app asks for the path', async () => {
+ const f = fakeShell();
+ const result = await watchedWindowsDialog('powershell.exe', [], { readyMs: 30, spawnProcess: f.spawnProcess });
+ assert.deepEqual(result, { noDialog: true }); assert.equal(f.child.killed, true, 'the stuck PowerShell is ended');
+ const answer = await chooseFolder('Pick', { platform: 'win32', windowsDialog: async () => ({ noDialog: true }) });
+ assert.equal(answer.unavailable, true); assert.match(answer.reason, /Type the folder path/);
+});
+test('Windows: once READY has come the person may take their time, and the answer is read without the READY line', async () => {
+ const f = fakeShell();
+ const pending = watchedWindowsDialog('powershell.exe', [], { readyMs: 30, spawnProcess: f.spawnProcess });
+ f.child.stdout.emit('data', 'READY\r\n');
+ await new Promise(r => setTimeout(r, 80)); // longer than readyMs: still waiting, not given up
+ assert.equal(f.child.killed, false);
+ f.child.stdout.emit('data', 'C:\Users\me\Skills'); f.child.emit('close', 0);
+ const done = await pending;
+ const answer = await chooseFolder('Pick', { platform: 'win32', windowsDialog: async () => done });
+ assert.deepEqual(answer, { path: 'C:\Users\me\Skills' });
+ const cancelled = await chooseFolder('Pick', { platform: 'win32', windowsDialog: async () => ({ stdout: 'READY\r\n' }) });
+ assert.deepEqual(cancelled, { cancelled: true });
+});
+test('Windows: a PowerShell that is missing or fails is reported as before', async () => {
+ const f = fakeShell();
+ const missing = watchedWindowsDialog('powershell.exe', [], { spawnProcess: f.spawnProcess });
+ f.child.emit('error', Object.assign(new Error('x'), { code: 'ENOENT' }));
+ await assert.rejects(missing, e => e.code === 'ENOENT');
+ const g = fakeShell(); const failed = watchedWindowsDialog('powershell.exe', [], { spawnProcess: g.spawnProcess });
+ g.child.emit('close', 1); await assert.rejects(failed, e => e.code === 1);
+});
diff --git a/apps/host/tests/split-qa2-fields.test.mjs b/apps/host/tests/split-qa2-fields.test.mjs
index d6f2cada5..30548f664 100644
--- a/apps/host/tests/split-qa2-fields.test.mjs
+++ b/apps/host/tests/split-qa2-fields.test.mjs
@@ -38,3 +38,14 @@ test('the Response settings dialog uses it: wrong numbers show the sentence and
assert.match(source, /if \(!dirty \|\| pending \|\| invalid\)/);
assert.match(source, /aria-invalid=\{problem \? true : undefined\}/);
});
+
+test('F07: a page opened from another computer says why Add skill cannot work instead of waiting', async () => {
+ const pick = await loadTs('../src/lib/folder-pick.ts').catch(() => null);
+ const source = (await readFile(new URL('../src/lib/folder-pick.ts', import.meta.url), 'utf8'));
+ const fn = new Function(`${source.slice(source.indexOf('export function pageIsOnThisComputer')).replace('export function', 'function')}; return pageIsOnThisComputer;`.replace(/: string|: boolean/g, ''))();
+ for (const yes of ['localhost', '127.0.0.1', '127.1.2.3', '[::1]', '::1']) assert.equal(fn(yes), true, yes);
+ for (const no of ['192.168.1.5', 'strata.example.com', 'my-pc.trycloudflare.com']) assert.equal(fn(no), false, no);
+ const skills = (await readFile(new URL('../src/screens/Skills.tsx', import.meta.url), 'utf8'));
+ assert.match(skills, /pageIsOnThisComputer\(window\.location\.hostname\)/);
+ void pick;
+});