gestalt-mobile 0.78.4 → 0.79.1
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/README.md +22 -13
- package/dist/client/assets/index-PmiNsocJ.css +1 -0
- package/dist/client/assets/{index-jLy1t3Qp.js → index-t6olwrqi.js} +58 -53
- package/dist/client/index.html +2 -2
- package/dist/server/server/app.js +3 -0
- package/dist/server/server/cli.js +3 -0
- package/dist/server/server/composition.contracts.js +2 -0
- package/dist/server/server/composition.js +66 -0
- package/dist/server/server/config.js +39 -7
- package/dist/server/server/features/catalog/get-bootstrap/use-case.js +2 -0
- package/dist/server/server/features/previews/application/service.js +80 -0
- package/dist/server/server/features/previews/open-preview/endpoint.js +39 -0
- package/dist/server/server/features/previews/register-routes.js +11 -0
- package/dist/server/server/features/previews/stop-preview/endpoint.js +16 -0
- package/dist/server/server/features/sessions/get-impeccable/endpoint.js +10 -0
- package/dist/server/server/features/sessions/register-routes.js +3 -0
- package/dist/server/server/platform/previews/gateway.js +185 -0
- package/dist/server/server/platform/previews/impeccable.js +269 -0
- package/dist/server/server/platform/previews/proxy.js +179 -0
- package/dist/server/shared/contracts/impeccable.js +104 -0
- package/dist/server/shared/contracts/preview.js +6 -0
- package/package.json +1 -1
- package/dist/client/assets/index-DRiZTklh.css +0 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { constants } from 'node:fs';
|
|
8
|
+
import { open, realpath } from 'node:fs/promises';
|
|
9
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
10
|
+
import { Readable, Transform, pipeline } from 'node:stream';
|
|
11
|
+
export const impeccablePath = '/.impeccable-live';
|
|
12
|
+
const bootstrapPath = `${impeccablePath}/bootstrap.js`;
|
|
13
|
+
const liveAssets = new Set(['/live.js', '/detect.js', '/modern-screenshot.js']);
|
|
14
|
+
const reads = new Set([
|
|
15
|
+
...liveAssets,
|
|
16
|
+
'/events',
|
|
17
|
+
'/status',
|
|
18
|
+
'/source',
|
|
19
|
+
'/design-system.json',
|
|
20
|
+
'/design-system/raw',
|
|
21
|
+
'/manual-edit-stash',
|
|
22
|
+
]);
|
|
23
|
+
const writes = new Set([
|
|
24
|
+
'/events',
|
|
25
|
+
'/annotation',
|
|
26
|
+
'/manual-edit-stash',
|
|
27
|
+
'/manual-edit-commit',
|
|
28
|
+
'/manual-edit-discard',
|
|
29
|
+
'/manual-edit-repair-decision',
|
|
30
|
+
]);
|
|
31
|
+
const maxJsonBytes = 2 * 1024 * 1024;
|
|
32
|
+
const maxAnnotationBytes = 8 * 1024 * 1024;
|
|
33
|
+
function within(root, path) {
|
|
34
|
+
const tail = relative(root, path);
|
|
35
|
+
return !isAbsolute(tail) && tail !== '..' && !tail.startsWith(`..${sep}`);
|
|
36
|
+
}
|
|
37
|
+
async function boundedBody(stream, limit) {
|
|
38
|
+
const chunks = [];
|
|
39
|
+
let size = 0;
|
|
40
|
+
for await (const chunk of stream) {
|
|
41
|
+
size += chunk.byteLength;
|
|
42
|
+
if (size > limit)
|
|
43
|
+
throw new Error('Impeccable request exceeded its size limit');
|
|
44
|
+
chunks.push(chunk);
|
|
45
|
+
}
|
|
46
|
+
return Buffer.concat(chunks, size);
|
|
47
|
+
}
|
|
48
|
+
function helperStream(response) {
|
|
49
|
+
return response.body
|
|
50
|
+
? Readable.fromWeb(response.body)
|
|
51
|
+
: Readable.from([]);
|
|
52
|
+
}
|
|
53
|
+
function helperUrl(helper, path, search = '') {
|
|
54
|
+
const url = new URL(path, `http://127.0.0.1:${helper.port}`);
|
|
55
|
+
url.search = search;
|
|
56
|
+
url.searchParams.set('token', helper.token);
|
|
57
|
+
return url;
|
|
58
|
+
}
|
|
59
|
+
export async function findImpeccableHelper(workspace) {
|
|
60
|
+
try {
|
|
61
|
+
const root = await realpath(workspace);
|
|
62
|
+
const path = await realpath(join(root, '.impeccable', 'live', 'server.json'));
|
|
63
|
+
if (!within(root, path))
|
|
64
|
+
return;
|
|
65
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK | constants.O_NOFOLLOW);
|
|
66
|
+
let marker;
|
|
67
|
+
try {
|
|
68
|
+
if (!(await file.stat()).isFile())
|
|
69
|
+
return;
|
|
70
|
+
const buffer = Buffer.alloc(4097);
|
|
71
|
+
const { bytesRead } = await file.read(buffer);
|
|
72
|
+
if (bytesRead > 4096)
|
|
73
|
+
return;
|
|
74
|
+
marker = JSON.parse(buffer.subarray(0, bytesRead).toString());
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await file.close();
|
|
78
|
+
}
|
|
79
|
+
if (typeof marker.port !== 'number' ||
|
|
80
|
+
!Number.isSafeInteger(marker.port) ||
|
|
81
|
+
marker.port < 1024 ||
|
|
82
|
+
marker.port > 65535 ||
|
|
83
|
+
typeof marker.pid !== 'number' ||
|
|
84
|
+
!Number.isSafeInteger(marker.pid) ||
|
|
85
|
+
marker.pid <= 0 ||
|
|
86
|
+
typeof marker.token !== 'string' ||
|
|
87
|
+
!/^[a-zA-Z0-9_-]{24,128}$/.test(marker.token))
|
|
88
|
+
return;
|
|
89
|
+
process.kill(marker.pid, 0);
|
|
90
|
+
const helper = { root, marker: path, port: marker.port, token: marker.token };
|
|
91
|
+
const response = await fetch(helperUrl(helper, '/status'), {
|
|
92
|
+
redirect: 'error',
|
|
93
|
+
signal: AbortSignal.timeout(1000),
|
|
94
|
+
});
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
await response.body?.cancel();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const status = JSON.parse((await boundedBody(helperStream(response), maxJsonBytes)).toString());
|
|
100
|
+
if (status?.port === helper.port && typeof status.agentPolling === 'boolean')
|
|
101
|
+
return helper;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// The helper may still be starting or its previous process may have exited.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function injectImpeccableBootstrap() {
|
|
108
|
+
let head = Buffer.alloc(0);
|
|
109
|
+
let injected = false;
|
|
110
|
+
const script = Buffer.from(`<script src="${bootstrapPath}" defer></script>`);
|
|
111
|
+
return new Transform({
|
|
112
|
+
transform(chunk, _encoding, callback) {
|
|
113
|
+
if (!head)
|
|
114
|
+
return callback(null, chunk);
|
|
115
|
+
head = Buffer.concat([head, chunk]);
|
|
116
|
+
const index = head.toString('latin1').toLowerCase().indexOf('</head>');
|
|
117
|
+
if (index >= 0 || head.length >= 64 * 1024) {
|
|
118
|
+
injected = index >= 0;
|
|
119
|
+
const body = injected
|
|
120
|
+
? Buffer.concat([head.subarray(0, index), script, head.subarray(index)])
|
|
121
|
+
: head;
|
|
122
|
+
head = undefined;
|
|
123
|
+
callback(null, body);
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
callback();
|
|
127
|
+
},
|
|
128
|
+
flush(callback) {
|
|
129
|
+
callback(null, injected ? undefined : head ? Buffer.concat([head, script]) : script);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function send(response, status, type, body) {
|
|
134
|
+
response
|
|
135
|
+
.writeHead(status, {
|
|
136
|
+
'content-type': type,
|
|
137
|
+
'cache-control': 'no-store',
|
|
138
|
+
'cross-origin-resource-policy': 'same-origin',
|
|
139
|
+
'x-content-type-options': 'nosniff',
|
|
140
|
+
})
|
|
141
|
+
.end(body);
|
|
142
|
+
}
|
|
143
|
+
const bootstrap = `(() => {
|
|
144
|
+
async function connect() {
|
|
145
|
+
try {
|
|
146
|
+
const result = await fetch('${impeccablePath}/ready', { cache: 'no-store' });
|
|
147
|
+
if (result.status === 401 || result.status === 403) return;
|
|
148
|
+
if (result.status === 204) {
|
|
149
|
+
const script = document.createElement('script');
|
|
150
|
+
script.src = '${impeccablePath}/live.js';
|
|
151
|
+
script.onerror = () => { script.remove(); setTimeout(connect, 1500); };
|
|
152
|
+
document.head.appendChild(script);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
} catch {}
|
|
156
|
+
setTimeout(connect, 1500);
|
|
157
|
+
}
|
|
158
|
+
connect();
|
|
159
|
+
})();`;
|
|
160
|
+
export function browserScript(script, token) {
|
|
161
|
+
return script
|
|
162
|
+
.replaceAll(token, createHash('sha256').update(token).digest('base64url'))
|
|
163
|
+
.replace(/(['"])http:\/\/localhost:\1\s*\+\s*PORT\s*\+\s*(['"])(?=\/)/g, (_match, _first, quote) => `${quote}${impeccablePath}`)
|
|
164
|
+
.replaceAll('http://localhost:${PORT}', impeccablePath);
|
|
165
|
+
}
|
|
166
|
+
export async function serveImpeccable(request, response, url, findHelper, track) {
|
|
167
|
+
const path = url.pathname.slice(impeccablePath.length);
|
|
168
|
+
if (path === '/bootstrap.js' && request.method === 'GET') {
|
|
169
|
+
send(response, 200, 'text/javascript; charset=utf-8', bootstrap);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const reading = request.method === 'GET' && (reads.has(path) || path === '/ready');
|
|
173
|
+
const writing = request.method === 'POST' && writes.has(path);
|
|
174
|
+
if (!reading && !writing) {
|
|
175
|
+
send(response, 404, 'text/plain', 'Unknown Impeccable route.');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const controller = new AbortController();
|
|
179
|
+
const untrack = track(() => {
|
|
180
|
+
controller.abort();
|
|
181
|
+
response.destroy();
|
|
182
|
+
});
|
|
183
|
+
response.once('close', () => {
|
|
184
|
+
untrack();
|
|
185
|
+
controller.abort();
|
|
186
|
+
});
|
|
187
|
+
try {
|
|
188
|
+
const helper = await findHelper();
|
|
189
|
+
if (controller.signal.aborted)
|
|
190
|
+
return;
|
|
191
|
+
if (path === '/ready') {
|
|
192
|
+
send(response, helper ? 204 : 200, 'text/plain', '');
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (!helper) {
|
|
196
|
+
send(response, 503, 'text/plain', 'Waiting for the Impeccable Live helper.');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (path === '/source') {
|
|
200
|
+
const name = url.searchParams.get('path');
|
|
201
|
+
const source = name && (await realpath(resolve(helper.root, name)).catch(() => undefined));
|
|
202
|
+
if (!source || source === helper.marker || !within(helper.root, source)) {
|
|
203
|
+
send(response, 404, 'text/plain', 'Impeccable source is unavailable.');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
url.searchParams.set('path', source);
|
|
207
|
+
}
|
|
208
|
+
let body;
|
|
209
|
+
let contentType = 'application/json';
|
|
210
|
+
if (writing) {
|
|
211
|
+
const annotation = path === '/annotation';
|
|
212
|
+
const stream = request.iterator({ destroyOnReturn: false });
|
|
213
|
+
let bytes;
|
|
214
|
+
try {
|
|
215
|
+
bytes = await boundedBody(stream, annotation ? maxAnnotationBytes : maxJsonBytes);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
request.resume();
|
|
219
|
+
send(response, 413, 'text/plain', 'Impeccable request body is too large.');
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (annotation) {
|
|
223
|
+
body = new Uint8Array(bytes);
|
|
224
|
+
contentType = 'image/png';
|
|
225
|
+
}
|
|
226
|
+
else if (bytes.length ||
|
|
227
|
+
(path !== '/manual-edit-commit' && path !== '/manual-edit-discard')) {
|
|
228
|
+
let payload;
|
|
229
|
+
try {
|
|
230
|
+
payload = JSON.parse(bytes.toString());
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
// The Live browser endpoints send a JSON object.
|
|
234
|
+
}
|
|
235
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
236
|
+
send(response, 400, 'text/plain', 'Impeccable request body is invalid.');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
body = JSON.stringify({ ...payload, token: helper.token });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const timeout = setTimeout(() => controller.abort(), 10_000);
|
|
243
|
+
const upstream = await fetch(helperUrl(helper, path, url.search), {
|
|
244
|
+
method: request.method,
|
|
245
|
+
...(body === undefined ? {} : { body, headers: { 'content-type': contentType } }),
|
|
246
|
+
signal: controller.signal,
|
|
247
|
+
redirect: 'error',
|
|
248
|
+
}).finally(() => clearTimeout(timeout));
|
|
249
|
+
if (path === '/live.js' && upstream.ok) {
|
|
250
|
+
const script = (await boundedBody(helperStream(upstream), maxJsonBytes)).toString();
|
|
251
|
+
send(response, 200, 'text/javascript; charset=utf-8', browserScript(script, helper.token));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
response.writeHead(upstream.status, {
|
|
255
|
+
'content-type': upstream.headers.get('content-type') ?? 'application/octet-stream',
|
|
256
|
+
'cache-control': 'no-store',
|
|
257
|
+
'cross-origin-resource-policy': 'same-origin',
|
|
258
|
+
'x-content-type-options': 'nosniff',
|
|
259
|
+
});
|
|
260
|
+
response.flushHeaders();
|
|
261
|
+
pipeline(helperStream(upstream), response, () => { });
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
if (!response.headersSent && !response.destroyed)
|
|
265
|
+
send(response, 502, 'text/plain', 'The Impeccable Live helper is unavailable.');
|
|
266
|
+
else
|
|
267
|
+
response.destroy();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { request, } from 'node:http';
|
|
7
|
+
import { pipeline } from 'node:stream';
|
|
8
|
+
import { injectImpeccableBootstrap } from './impeccable.js';
|
|
9
|
+
export const previewCookie = '__Host-gestalt-preview';
|
|
10
|
+
const hopHeaders = [
|
|
11
|
+
'connection',
|
|
12
|
+
'keep-alive',
|
|
13
|
+
'proxy-authenticate',
|
|
14
|
+
'proxy-authorization',
|
|
15
|
+
'proxy-connection',
|
|
16
|
+
'te',
|
|
17
|
+
'trailer',
|
|
18
|
+
'transfer-encoding',
|
|
19
|
+
'upgrade',
|
|
20
|
+
];
|
|
21
|
+
function endToEndHeaders(original) {
|
|
22
|
+
const headers = { ...original };
|
|
23
|
+
const nominated = original.connection?.split(',').map((name) => name.trim().toLowerCase()) ?? [];
|
|
24
|
+
for (const name of [...hopHeaders, ...nominated])
|
|
25
|
+
delete headers[name];
|
|
26
|
+
return headers;
|
|
27
|
+
}
|
|
28
|
+
export function cookieName(part) {
|
|
29
|
+
return part.split('=', 1)[0].trim();
|
|
30
|
+
}
|
|
31
|
+
function requestHeaders(browser, origin) {
|
|
32
|
+
const headers = endToEndHeaders(browser.headers);
|
|
33
|
+
for (const name of Object.keys(headers)) {
|
|
34
|
+
if (name === 'forwarded' || name.startsWith('x-forwarded-'))
|
|
35
|
+
delete headers[name];
|
|
36
|
+
}
|
|
37
|
+
const appCookies = headers.cookie
|
|
38
|
+
?.split(';')
|
|
39
|
+
.filter((part) => ![previewCookie, 'gestalt_mobile_session'].includes(cookieName(part)));
|
|
40
|
+
if (appCookies?.length)
|
|
41
|
+
headers.cookie = appCookies.join(';').trim();
|
|
42
|
+
else
|
|
43
|
+
delete headers.cookie;
|
|
44
|
+
headers.host = origin.host;
|
|
45
|
+
headers['x-forwarded-host'] = origin.host;
|
|
46
|
+
headers['x-forwarded-proto'] = 'https';
|
|
47
|
+
return headers;
|
|
48
|
+
}
|
|
49
|
+
function responseHeaders(upstream) {
|
|
50
|
+
const headers = endToEndHeaders(upstream);
|
|
51
|
+
const cookies = headers['set-cookie']?.filter((cookie) => {
|
|
52
|
+
const [value, ...attributes] = cookie.split(';');
|
|
53
|
+
return (![previewCookie, 'gestalt_mobile_session'].includes(cookieName(value)) &&
|
|
54
|
+
!attributes.some((attribute) => cookieName(attribute).toLowerCase() === 'domain'));
|
|
55
|
+
});
|
|
56
|
+
if (cookies?.length)
|
|
57
|
+
headers['set-cookie'] = cookies;
|
|
58
|
+
else
|
|
59
|
+
delete headers['set-cookie'];
|
|
60
|
+
headers['cache-control'] = 'no-store';
|
|
61
|
+
// Native same-origin form POSTs need their Origin to pass the gateway check.
|
|
62
|
+
headers['referrer-policy'] = 'same-origin';
|
|
63
|
+
headers['x-frame-options'] = 'DENY';
|
|
64
|
+
const policy = headers['content-security-policy'];
|
|
65
|
+
headers['content-security-policy'] = [
|
|
66
|
+
...(typeof policy === 'string' ? [policy] : (policy ?? [])),
|
|
67
|
+
"frame-ancestors 'none'",
|
|
68
|
+
];
|
|
69
|
+
return headers;
|
|
70
|
+
}
|
|
71
|
+
export function unavailable(response) {
|
|
72
|
+
response
|
|
73
|
+
.writeHead(502, { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' })
|
|
74
|
+
.end('The preview server is unavailable. Start the configured dev server and retry.');
|
|
75
|
+
}
|
|
76
|
+
export function rejectUpgrade(socket, status) {
|
|
77
|
+
socket.end(`HTTP/1.1 ${status}\r\nConnection: close\r\nContent-Length: 0\r\n\r\n`);
|
|
78
|
+
}
|
|
79
|
+
function upstreamRequest(browser, headers, port) {
|
|
80
|
+
const upstream = request({
|
|
81
|
+
hostname: '127.0.0.1',
|
|
82
|
+
port,
|
|
83
|
+
method: browser.method,
|
|
84
|
+
path: browser.url,
|
|
85
|
+
headers,
|
|
86
|
+
});
|
|
87
|
+
upstream.setTimeout(10_000, () => upstream.destroy(new Error('Preview upstream timed out')));
|
|
88
|
+
return upstream;
|
|
89
|
+
}
|
|
90
|
+
export function proxyHttp(browser, response, target, track, impeccable = false) {
|
|
91
|
+
const headers = requestHeaders(browser, target.origin);
|
|
92
|
+
const document = impeccable && browser.method === 'GET' && headers.accept?.includes('text/html');
|
|
93
|
+
if (document)
|
|
94
|
+
headers['accept-encoding'] = 'identity';
|
|
95
|
+
const upstream = upstreamRequest(browser, headers, target.port);
|
|
96
|
+
const untrack = track(() => {
|
|
97
|
+
upstream.destroy();
|
|
98
|
+
response.destroy();
|
|
99
|
+
});
|
|
100
|
+
response.once('close', () => {
|
|
101
|
+
untrack();
|
|
102
|
+
if (!response.writableFinished)
|
|
103
|
+
upstream.destroy();
|
|
104
|
+
});
|
|
105
|
+
upstream.once('error', () => {
|
|
106
|
+
browser.unpipe(upstream);
|
|
107
|
+
browser.resume();
|
|
108
|
+
if (!response.headersSent && !response.destroyed)
|
|
109
|
+
unavailable(response);
|
|
110
|
+
else
|
|
111
|
+
response.destroy();
|
|
112
|
+
});
|
|
113
|
+
upstream.once('response', (incoming) => {
|
|
114
|
+
upstream.setTimeout(0);
|
|
115
|
+
const headers = responseHeaders(incoming.headers);
|
|
116
|
+
const decorate = document &&
|
|
117
|
+
incoming.statusCode === 200 &&
|
|
118
|
+
headers['content-type']?.startsWith('text/html') &&
|
|
119
|
+
(!headers['content-encoding'] || headers['content-encoding'] === 'identity');
|
|
120
|
+
if (decorate) {
|
|
121
|
+
delete headers['content-length'];
|
|
122
|
+
delete headers.etag;
|
|
123
|
+
}
|
|
124
|
+
response.writeHead(incoming.statusCode ?? 502, headers);
|
|
125
|
+
if (decorate)
|
|
126
|
+
pipeline(incoming, injectImpeccableBootstrap(), response, () => { });
|
|
127
|
+
else
|
|
128
|
+
pipeline(incoming, response, () => { });
|
|
129
|
+
});
|
|
130
|
+
browser.pipe(upstream);
|
|
131
|
+
}
|
|
132
|
+
export function proxyWebSocket(browser, socket, head, target, track) {
|
|
133
|
+
const headers = requestHeaders(browser, target.origin);
|
|
134
|
+
headers.connection = 'Upgrade';
|
|
135
|
+
headers.upgrade = 'websocket';
|
|
136
|
+
const upstream = upstreamRequest(browser, headers, target.port);
|
|
137
|
+
let peer;
|
|
138
|
+
const untrack = track(() => socket.destroy());
|
|
139
|
+
socket.once('error', () => socket.destroy());
|
|
140
|
+
socket.once('close', () => {
|
|
141
|
+
untrack();
|
|
142
|
+
upstream.destroy();
|
|
143
|
+
peer?.destroy();
|
|
144
|
+
});
|
|
145
|
+
upstream.once('error', () => {
|
|
146
|
+
if (!peer && !socket.destroyed)
|
|
147
|
+
rejectUpgrade(socket, '502 Bad Gateway');
|
|
148
|
+
});
|
|
149
|
+
upstream.once('response', (response) => {
|
|
150
|
+
response.destroy();
|
|
151
|
+
if (!socket.destroyed)
|
|
152
|
+
rejectUpgrade(socket, '502 Bad Gateway');
|
|
153
|
+
});
|
|
154
|
+
upstream.once('upgrade', (response, connected, initial) => {
|
|
155
|
+
if (socket.destroyed) {
|
|
156
|
+
connected.destroy();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
connected.setTimeout(0);
|
|
160
|
+
peer = connected;
|
|
161
|
+
connected.once('error', () => socket.destroy());
|
|
162
|
+
connected.once('close', () => socket.destroy());
|
|
163
|
+
const handshake = responseHeaders(response.headers);
|
|
164
|
+
handshake.connection = 'Upgrade';
|
|
165
|
+
handshake.upgrade = 'websocket';
|
|
166
|
+
let reply = 'HTTP/1.1 101 Switching Protocols\r\n';
|
|
167
|
+
for (const [name, values] of Object.entries(handshake)) {
|
|
168
|
+
for (const value of typeof values === 'string' ? [values] : (values ?? []))
|
|
169
|
+
reply += `${name}: ${value}\r\n`;
|
|
170
|
+
}
|
|
171
|
+
socket.write(`${reply}\r\n`);
|
|
172
|
+
if (initial.length)
|
|
173
|
+
socket.write(initial);
|
|
174
|
+
if (head.length)
|
|
175
|
+
connected.write(head);
|
|
176
|
+
socket.pipe(connected).pipe(socket);
|
|
177
|
+
});
|
|
178
|
+
upstream.end();
|
|
179
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
export const impeccableGroups = [
|
|
7
|
+
{
|
|
8
|
+
label: 'Build',
|
|
9
|
+
actions: [
|
|
10
|
+
{ name: 'shape', argument: 'feature', description: 'Plan UX/UI before coding' },
|
|
11
|
+
{ name: 'document', description: 'Derive DESIGN.md from an existing interface' },
|
|
12
|
+
{ name: 'extract', argument: 'target', description: 'Create reusable tokens and components' },
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: 'Evaluate',
|
|
17
|
+
actions: [
|
|
18
|
+
{ name: 'critique', argument: 'target', description: 'Review UX and visual quality' },
|
|
19
|
+
{
|
|
20
|
+
name: 'audit',
|
|
21
|
+
argument: 'target',
|
|
22
|
+
description: 'Check accessibility, responsiveness, and performance',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'Refine',
|
|
28
|
+
actions: [
|
|
29
|
+
{ name: 'polish', argument: 'target', description: 'Final pre-release quality pass' },
|
|
30
|
+
{ name: 'bolder', argument: 'target', description: 'Make a bland design more distinctive' },
|
|
31
|
+
{ name: 'quieter', argument: 'target', description: 'Reduce visual noise' },
|
|
32
|
+
{ name: 'distill', argument: 'target', description: 'Simplify the interface' },
|
|
33
|
+
{
|
|
34
|
+
name: 'harden',
|
|
35
|
+
argument: 'target',
|
|
36
|
+
description: 'Handle errors, edge cases, and internationalization',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'onboard',
|
|
40
|
+
argument: 'target',
|
|
41
|
+
description: 'Improve first-run flows and empty states',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: 'Enhance',
|
|
47
|
+
actions: [
|
|
48
|
+
{ name: 'animate', argument: 'target', description: 'Add purposeful motion' },
|
|
49
|
+
{ name: 'colorize', argument: 'target', description: 'Improve strategic color use' },
|
|
50
|
+
{ name: 'typeset', argument: 'target', description: 'Strengthen typography' },
|
|
51
|
+
{ name: 'layout', argument: 'target', description: 'Fix spacing and visual hierarchy' },
|
|
52
|
+
{ name: 'delight', argument: 'target', description: 'Add memorable details' },
|
|
53
|
+
{
|
|
54
|
+
name: 'overdrive',
|
|
55
|
+
argument: 'target',
|
|
56
|
+
description: 'Pursue a highly ambitious visual treatment',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: 'Fix',
|
|
62
|
+
actions: [
|
|
63
|
+
{
|
|
64
|
+
name: 'clarify',
|
|
65
|
+
argument: 'target',
|
|
66
|
+
description: 'Improve labels, instructions, and errors',
|
|
67
|
+
},
|
|
68
|
+
{ name: 'adapt', argument: 'target', description: 'Improve mobile and responsive behavior' },
|
|
69
|
+
{ name: 'optimize', argument: 'target', description: 'Diagnose UI performance' },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
label: 'Browser iteration',
|
|
74
|
+
actions: [{ name: 'live', description: 'Explore visual variants interactively' }],
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
export function hasImpeccableSkill(skills) {
|
|
78
|
+
return (skills?.some(({ name, enabled }) => enabled && (name === 'impeccable' || name.endsWith(':impeccable'))) ?? false);
|
|
79
|
+
}
|
|
80
|
+
export function parseImpeccableCommand(text) {
|
|
81
|
+
const match = /^\/impeccable(?:\s+(\S+)(?:\s+([\s\S]*))?)?$/i.exec(text.trim());
|
|
82
|
+
if (!match)
|
|
83
|
+
return null;
|
|
84
|
+
const name = match[1]?.toLowerCase();
|
|
85
|
+
const action = impeccableGroups
|
|
86
|
+
.map((group) => group.actions.find((item) => item.name === name))
|
|
87
|
+
.find(Boolean);
|
|
88
|
+
return { action, target: match[2] ?? '' };
|
|
89
|
+
}
|
|
90
|
+
export function impeccablePrompt(action, target, remoteLive) {
|
|
91
|
+
const prompt = `$impeccable ${action.name}${target ? ` ${target}` : ''}`;
|
|
92
|
+
const context = target
|
|
93
|
+
? ''
|
|
94
|
+
: '\nUse the current interface or feature from this conversation as the target.';
|
|
95
|
+
if (!remoteLive)
|
|
96
|
+
return prompt + context;
|
|
97
|
+
return (prompt +
|
|
98
|
+
context +
|
|
99
|
+
`
|
|
100
|
+
|
|
101
|
+
The user opened an Impeccable editor through Gestalt's HTTPS dev preview. Load the Impeccable Live reference.
|
|
102
|
+
Resolve the target and apply the project setup from live-setup.md if the Live configuration is missing. The picker and the helper connection use the same origin as the dev preview.
|
|
103
|
+
Start or reuse the loopback helper with the skill's \`impeccable live-server --background\` launcher from this chat's workspace root. Gestalt injects the picker and forwards browser requests, so skip the localhost script injection and let the user interact in their preview tab. Continue with the skill's local live-poll, variant handling, and cleanup. Keep the helper and the poll on this machine.`);
|
|
104
|
+
}
|