@floless/app 0.150.0 → 0.151.0
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/dist/floless-server.cjs +7467 -5068
- package/dist/skills/floless-app-onboarding/SKILL.md +200 -87
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +27 -18
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +207 -0
- package/dist/web/agents.js +108 -12
- package/dist/web/app.css +98 -20
- package/dist/web/app.js +14 -107
- package/dist/web/aware.js +459 -59
- package/dist/web/chat.css +12 -0
- package/dist/web/chat.js +95 -18
- package/dist/web/commands-shell.js +198 -10
- package/dist/web/guide.js +675 -0
- package/dist/web/index.html +64 -4
- package/dist/web/instructor.js +8 -2
- package/dist/web/tool-updates.js +175 -9
- package/dist/web/workspaces.js +217 -64
- package/package.json +2 -2
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +0 -158
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The Guide (#2046): FloLess's built-in onboarding agent in AI Chat.
|
|
3
|
+
*
|
|
4
|
+
* This file owns everything the person sees of it outside the conversation itself: the first-launch question (with a
|
|
5
|
+
* preview of exactly what would be sent), the ways in ("Guide" in the ≡ menu, "Ask the Guide" on the empty Workflows
|
|
6
|
+
* and Workspaces pages), Turn off and Delete Guide history, and the next-move cards AI Chat shows in a Guide
|
|
7
|
+
* conversation. The server decides everything that matters (consent, what is sent, whether a turn may go); this file
|
|
8
|
+
* only shows it and relays the person's answers. Plan: docs/superpowers/specs/2026-10-07-2046-guide-agent-PLAN.md.
|
|
9
|
+
*/
|
|
10
|
+
(function () {
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const PROVIDER_LABEL = { claude: 'Claude', codex: 'Codex' };
|
|
14
|
+
const PAGE_LABEL = {
|
|
15
|
+
workspaces: 'Workspaces', workflows: 'Workflows', agents: 'Agents', routines: 'Routines', tools: 'Tools',
|
|
16
|
+
discover: 'Discover Local Tools', integrations: 'Integrations', requests: 'Requests',
|
|
17
|
+
};
|
|
18
|
+
const SECTION_LABEL = {
|
|
19
|
+
apps: 'Installed programs', running: 'Open now', recentFiles: 'Recent files', accounts: 'Connected accounts',
|
|
20
|
+
};
|
|
21
|
+
const FLOLESS_LABEL = { projects: 'Projects', workflows: 'Workflows', agents: 'Agents', routines: 'Routines', tools: 'Tools' };
|
|
22
|
+
|
|
23
|
+
const state = {
|
|
24
|
+
sessionReady: false,
|
|
25
|
+
status: null,
|
|
26
|
+
preview: null,
|
|
27
|
+
previewError: '',
|
|
28
|
+
share: { windowTitles: true, recentFiles: true },
|
|
29
|
+
provider: null,
|
|
30
|
+
mode: 'consent', // 'consent' | 'start' | 'folder'
|
|
31
|
+
busy: false,
|
|
32
|
+
banner: '',
|
|
33
|
+
returnFocus: null,
|
|
34
|
+
lookSeq: 0,
|
|
35
|
+
launchAsked: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const $modal = document.getElementById('guide-agent-modal');
|
|
39
|
+
const $title = document.getElementById('guide-modal-title');
|
|
40
|
+
const $sub = document.getElementById('guide-modal-sub');
|
|
41
|
+
const $body = document.getElementById('guide-modal-body');
|
|
42
|
+
const $live = document.getElementById('guide-modal-live');
|
|
43
|
+
const $foot = document.getElementById('guide-modal-foot');
|
|
44
|
+
const $secondary = document.getElementById('guide-modal-secondary');
|
|
45
|
+
const $primary = document.getElementById('guide-modal-primary');
|
|
46
|
+
|
|
47
|
+
// ── talking to the server ─────────────────────────────────────────────────────────────────────────────────────
|
|
48
|
+
async function ensureSession() {
|
|
49
|
+
if (state.sessionReady) return;
|
|
50
|
+
let response;
|
|
51
|
+
try { response = await fetch('/api/chat/session', { credentials: 'same-origin' }); }
|
|
52
|
+
catch { throw new Error('FloLess could not be reached. Make sure it is still running, then try again.'); }
|
|
53
|
+
if (!response.ok) throw new Error('FloLess could not open AI Chat’s session, so the Guide could not load. Reload FloLess and try again.');
|
|
54
|
+
state.sessionReady = true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function api(path, body, retried = false) {
|
|
58
|
+
await ensureSession();
|
|
59
|
+
const init = { credentials: 'same-origin', method: body ? 'POST' : 'GET' };
|
|
60
|
+
if (body) { init.body = JSON.stringify(body); init.headers = { 'content-type': 'application/json' }; }
|
|
61
|
+
if (typeof AbortSignal?.timeout === 'function') init.signal = AbortSignal.timeout(60_000);
|
|
62
|
+
let response;
|
|
63
|
+
try { response = await fetch(path, init); }
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new Error(error?.name === 'TimeoutError'
|
|
66
|
+
? 'FloLess took too long to answer, most likely because it is busy. Try again in a moment.'
|
|
67
|
+
: 'FloLess could not be reached. Make sure it is still running, then try again.');
|
|
68
|
+
}
|
|
69
|
+
let data = null;
|
|
70
|
+
try { data = await response.json(); } catch { data = null; }
|
|
71
|
+
if (response.status === 401 && data?.code === 'chat-session-required' && !retried) {
|
|
72
|
+
state.sessionReady = false;
|
|
73
|
+
return api(path, body, true);
|
|
74
|
+
}
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const failure = new Error(data?.error || 'FloLess couldn’t do that just now. Try again; if it keeps happening, restart FloLess.');
|
|
77
|
+
failure.code = data?.code || null; failure.body = data;
|
|
78
|
+
throw failure;
|
|
79
|
+
}
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const toast = (message, kind) => (typeof showToast === 'function' ? showToast(message, kind) : console.warn('[guide]', message));
|
|
84
|
+
|
|
85
|
+
async function loadStatus() {
|
|
86
|
+
const body = await api('/api/chat/guide');
|
|
87
|
+
state.status = body.guide;
|
|
88
|
+
return state.status;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** AIs the person can choose: ready ones, and ones FloLess could not finish checking (a busy computer). */
|
|
92
|
+
function readyProviders() {
|
|
93
|
+
return (state.status?.providers || []).filter((row) => row.ready || row.state === 'unknown').map((row) => row.provider);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function providerUnchecked(provider) {
|
|
97
|
+
return (state.status?.providers || []).some((row) => row.provider === provider && row.state === 'unknown');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function chooseProvider() {
|
|
101
|
+
const ready = readyProviders();
|
|
102
|
+
const current = window.flolessChat?.currentProvider?.() || null;
|
|
103
|
+
if (state.provider && ready.includes(state.provider)) return state.provider;
|
|
104
|
+
if (current && ready.includes(current)) return current;
|
|
105
|
+
return ready[0] || current || 'claude';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ── opening the Guide conversation ────────────────────────────────────────────────────────────────────────────
|
|
109
|
+
async function openGuideChat(chatId) {
|
|
110
|
+
const chat = window.flolessChat;
|
|
111
|
+
if (!chat?.openConversation) { toast('AI Chat isn’t ready yet. Try again in a moment.', 'warn'); return false; }
|
|
112
|
+
try {
|
|
113
|
+
await chat.openConversation(chatId, { owner: { kind: 'workspace' } });
|
|
114
|
+
return true;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
toast(error?.message || 'FloLess couldn’t open the Guide conversation. Try again.', 'warn');
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The one way in, from every entry point. Signed out → says so. Guide on with a conversation → opens it. Anything
|
|
123
|
+
* else → the question (a click is never an unprompted ask, so it asks again after Not now or Turn off).
|
|
124
|
+
*/
|
|
125
|
+
async function open(options = {}) {
|
|
126
|
+
state.returnFocus = options.returnFocus || (document.activeElement instanceof HTMLElement ? document.activeElement : null);
|
|
127
|
+
let status;
|
|
128
|
+
try { status = await loadStatus(); }
|
|
129
|
+
catch (error) { toast(error.message, 'warn'); return; }
|
|
130
|
+
if (!status.signedIn) { toast('Sign in to FloLess first. The Guide belongs to your FloLess account, so it starts once you are signed in.', 'warn'); return; }
|
|
131
|
+
if (status.consent?.choice === 'on' && status.activeChatId) { await openGuideChat(status.activeChatId); return; }
|
|
132
|
+
await showModal(status.consent?.choice === 'on' ? 'start' : 'consent');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** First launch: ask once, after boot, never over another dialog. Not now and Turn off are never asked again here. */
|
|
136
|
+
async function maybeAskOnLaunch() {
|
|
137
|
+
if (state.launchAsked) return;
|
|
138
|
+
state.launchAsked = true;
|
|
139
|
+
let status;
|
|
140
|
+
try { status = await loadStatus(); }
|
|
141
|
+
catch (error) {
|
|
142
|
+
// Not this time: the next start of FloLess asks again.
|
|
143
|
+
console.warn('[guide] could not check whether to ask about the Guide:', error);
|
|
144
|
+
state.launchAsked = false;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (!status.signedIn || !status.ask) return;
|
|
148
|
+
const waitForQuiet = async () => {
|
|
149
|
+
for (let tries = 0; tries < 120; tries += 1) {
|
|
150
|
+
if (!document.querySelector('.modal-backdrop.show')) return true;
|
|
151
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
};
|
|
155
|
+
if (!(await waitForQuiet())) return;
|
|
156
|
+
// The person may have answered meanwhile (≡ → Guide, Ask the Guide): never ask again after an answer.
|
|
157
|
+
try { status = await loadStatus(); } catch { return; }
|
|
158
|
+
if (!status.signedIn || !status.ask || $modal.classList.contains('show')) return;
|
|
159
|
+
await showModal('consent');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ── the modal ─────────────────────────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
function el(tag, className, text) {
|
|
164
|
+
const node = document.createElement(tag);
|
|
165
|
+
if (className) node.className = className;
|
|
166
|
+
if (text !== undefined) node.textContent = text;
|
|
167
|
+
return node;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function sectionList(items, render) {
|
|
171
|
+
const list = el('ul', 'guide-preview-list');
|
|
172
|
+
for (const item of items) list.append(el('li', '', render(item)));
|
|
173
|
+
return list;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function previewSection(label, section, render, extra) {
|
|
177
|
+
const details = el('details', 'guide-preview-section');
|
|
178
|
+
const summary = el('summary');
|
|
179
|
+
summary.dataset.commandId = `shell.guide-preview-section#${label}`;
|
|
180
|
+
const count = section?.items?.length || 0;
|
|
181
|
+
const omitted = section?.omitted || 0;
|
|
182
|
+
summary.textContent = `${label} · ${section?.problem ? 'couldn’t read' : omitted ? `${count} of ${count + omitted}` : count}`;
|
|
183
|
+
details.append(summary);
|
|
184
|
+
if (section?.problem) {
|
|
185
|
+
details.append(el('p', 'guide-preview-problem', `${section.problem} Only this note goes to the AI for this part.`));
|
|
186
|
+
} else if (extra) {
|
|
187
|
+
details.append(extra);
|
|
188
|
+
} else if (!count) {
|
|
189
|
+
details.append(el('p', 'guide-preview-empty', 'Nothing here.'));
|
|
190
|
+
} else {
|
|
191
|
+
details.append(sectionList(section.items, render));
|
|
192
|
+
}
|
|
193
|
+
if (omitted && !section?.problem) details.append(el('p', 'guide-preview-cut', `…and ${omitted} more not included.`));
|
|
194
|
+
return details;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function renderPreview() {
|
|
198
|
+
const wrap = el('div', 'guide-preview');
|
|
199
|
+
const look = state.preview?.look;
|
|
200
|
+
if (!look) {
|
|
201
|
+
const line = el('p', 'guide-preview-loading');
|
|
202
|
+
line.textContent = state.previewError || 'Looking at this computer… this takes a few seconds.';
|
|
203
|
+
if (!state.previewError) line.prepend(el('span', 'ws-source-spin'));
|
|
204
|
+
wrap.append(line);
|
|
205
|
+
if (state.previewError) {
|
|
206
|
+
const again = el('button', '', 'Try again');
|
|
207
|
+
again.type = 'button';
|
|
208
|
+
again.dataset.commandId = 'shell.guide-preview-retry';
|
|
209
|
+
again.dataset.tip = 'Looks at this computer again.';
|
|
210
|
+
again.addEventListener('click', () => { void takeLook(); });
|
|
211
|
+
wrap.append(again);
|
|
212
|
+
}
|
|
213
|
+
return wrap;
|
|
214
|
+
}
|
|
215
|
+
const counts = look.recentFiles?.countsByType || {};
|
|
216
|
+
const countLine = Object.keys(counts).length
|
|
217
|
+
? el('p', 'guide-preview-empty', `Only counts: ${Object.entries(counts).map(([type, n]) => `${n} × .${type}`).join(', ')}. No names or folders.`)
|
|
218
|
+
: null;
|
|
219
|
+
const flo = look.floless || {};
|
|
220
|
+
const floBlock = el('div');
|
|
221
|
+
for (const key of Object.keys(FLOLESS_LABEL)) {
|
|
222
|
+
const section = flo[key];
|
|
223
|
+
const line = el('p', 'guide-preview-empty');
|
|
224
|
+
line.textContent = section?.problem
|
|
225
|
+
? `${FLOLESS_LABEL[key]}: couldn’t read`
|
|
226
|
+
: `${FLOLESS_LABEL[key]}: ${(section?.items || []).length ? section.items.join(', ') : 'none'}`;
|
|
227
|
+
floBlock.append(line);
|
|
228
|
+
}
|
|
229
|
+
const summary = el('p', 'guide-preview-summary');
|
|
230
|
+
const part = (section, count, noun) => (section?.problem ? `${noun}: couldn’t read` : `${count} ${noun}`);
|
|
231
|
+
summary.textContent = `Looks like: ${part(look.apps, look.apps?.items?.length || 0, 'programs')} · ${part(look.running, look.running?.items?.length || 0, 'open')} · `
|
|
232
|
+
+ `${part(look.recentFiles, state.share.recentFiles ? (look.recentFiles?.items?.length || 0) : Object.values(counts).reduce((a, b) => a + b, 0), 'recent files')} · `
|
|
233
|
+
+ `${part(look.accounts, look.accounts?.items?.length || 0, 'accounts')}.`;
|
|
234
|
+
const region = el('div', 'guide-preview-scroll');
|
|
235
|
+
region.setAttribute('role', 'region');
|
|
236
|
+
region.setAttribute('aria-label', 'Preview of what will be sent');
|
|
237
|
+
region.tabIndex = 0;
|
|
238
|
+
region.append(
|
|
239
|
+
previewSection(SECTION_LABEL.apps, look.apps, (app) => (app.version ? `${app.name} (${app.version})` : app.name)),
|
|
240
|
+
previewSection(SECTION_LABEL.running, look.running, (row) => (row.title ? `${row.name} — ${row.title}` : row.name)),
|
|
241
|
+
previewSection(SECTION_LABEL.recentFiles, look.recentFiles, (file) => `${file.name} — ${file.folder}`, state.share.recentFiles ? null : countLine),
|
|
242
|
+
previewSection(SECTION_LABEL.accounts, look.accounts, (row) => `${row.service}: ${row.status}`),
|
|
243
|
+
(() => {
|
|
244
|
+
const details = el('details', 'guide-preview-section');
|
|
245
|
+
const holds = el('summary', '', 'What FloLess holds');
|
|
246
|
+
holds.dataset.commandId = 'shell.guide-preview-section#What FloLess holds';
|
|
247
|
+
details.append(holds, floBlock);
|
|
248
|
+
return details;
|
|
249
|
+
})(),
|
|
250
|
+
);
|
|
251
|
+
const disclosure = el('details', 'guide-preview-disclosure');
|
|
252
|
+
const open = el('summary', '', 'Preview exactly what will be sent');
|
|
253
|
+
open.dataset.commandId = 'shell.guide-preview-open';
|
|
254
|
+
disclosure.append(open, region,
|
|
255
|
+
el('p', 'guide-preview-foot', 'Sent as plain facts, marked as data — never as instructions.'));
|
|
256
|
+
if (state.banner) disclosure.open = true;
|
|
257
|
+
wrap.append(summary, disclosure);
|
|
258
|
+
return wrap;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function switchRow(id, label, help, key) {
|
|
262
|
+
const row = el('div', 'guide-switch');
|
|
263
|
+
const toggle = el('label', 'rtn-toggle');
|
|
264
|
+
const input = document.createElement('input');
|
|
265
|
+
input.type = 'checkbox'; input.id = id; input.setAttribute('role', 'switch');
|
|
266
|
+
input.checked = state.share[key];
|
|
267
|
+
input.dataset.commandId = `shell.guide-share-${key === 'windowTitles' ? 'window-titles' : 'recent-files'}`;
|
|
268
|
+
input.setAttribute('aria-describedby', `${id}-help`);
|
|
269
|
+
input.addEventListener('change', () => { state.share = { ...state.share, [key]: input.checked }; void takeLook(); });
|
|
270
|
+
toggle.append(input, el('span', 'rtn-toggle-track'));
|
|
271
|
+
const text = el('div', 'guide-switch-text');
|
|
272
|
+
const name = el('label', 'guide-switch-label', label); name.htmlFor = id;
|
|
273
|
+
const note = el('div', 'guide-switch-help', help); note.id = `${id}-help`;
|
|
274
|
+
text.append(name, note);
|
|
275
|
+
row.append(toggle, text);
|
|
276
|
+
return row;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function providerChoice() {
|
|
280
|
+
const ready = readyProviders();
|
|
281
|
+
const wrap = el('div', 'guide-provider');
|
|
282
|
+
if (ready.length === 2) {
|
|
283
|
+
const group = el('div', 'guide-provider-group');
|
|
284
|
+
group.setAttribute('role', 'radiogroup');
|
|
285
|
+
group.setAttribute('aria-label', 'Which AI reads this?');
|
|
286
|
+
group.append(el('span', 'guide-switch-label', 'Which AI reads this?'));
|
|
287
|
+
for (const provider of ready) {
|
|
288
|
+
const option = el('label', 'guide-provider-option');
|
|
289
|
+
const radio = document.createElement('input');
|
|
290
|
+
radio.type = 'radio'; radio.name = 'guide-provider'; radio.value = provider;
|
|
291
|
+
radio.checked = provider === state.provider;
|
|
292
|
+
radio.dataset.commandId = `shell.guide-provider#${PROVIDER_LABEL[provider]}`;
|
|
293
|
+
radio.addEventListener('change', () => { state.provider = provider; void takeLook(); });
|
|
294
|
+
option.append(radio, document.createTextNode(` ${PROVIDER_LABEL[provider]}`));
|
|
295
|
+
group.append(option);
|
|
296
|
+
}
|
|
297
|
+
wrap.append(group);
|
|
298
|
+
} else if (ready.length === 1) {
|
|
299
|
+
wrap.append(el('p', 'guide-switch-help', providerUnchecked(ready[0])
|
|
300
|
+
? `Sent to ${PROVIDER_LABEL[ready[0]]}. FloLess couldn’t finish checking it just now; the Guide will try anyway, and says so if it can’t start.`
|
|
301
|
+
: `Sent to ${PROVIDER_LABEL[ready[0]]}, the AI you’re signed in with.`));
|
|
302
|
+
} else {
|
|
303
|
+
wrap.append(el('p', 'guide-switch-help', 'No AI is signed in yet. You can still turn the Guide on; it starts once you sign in to Claude Code or Codex in AI Chat.'));
|
|
304
|
+
}
|
|
305
|
+
return wrap;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Repaint the question. A repaint replaces the controls, so a focused one is gone and focus would fall to the page
|
|
310
|
+
* behind, out of reach of the dialog's own keys (independent QA, #2046). When focus WAS in the question, it goes back
|
|
311
|
+
* to the control with the same id, else the title. When it was elsewhere (a dialog opened over the Guide), it is left
|
|
312
|
+
* there.
|
|
313
|
+
*/
|
|
314
|
+
function paint() {
|
|
315
|
+
const active = document.activeElement;
|
|
316
|
+
const wasInside = Boolean(active && active !== document.body && $modal.contains(active));
|
|
317
|
+
const focusedId = wasInside && active.id ? active.id : null;
|
|
318
|
+
paintBody();
|
|
319
|
+
if (!wasInside || !$modal.classList.contains('show')) return;
|
|
320
|
+
const again = focusedId ? document.getElementById(focusedId) : null;
|
|
321
|
+
if (again && $modal.contains(again)) again.focus();
|
|
322
|
+
else $title.focus();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function paintBody() {
|
|
326
|
+
const providerName = PROVIDER_LABEL[state.provider] || 'the AI you chose';
|
|
327
|
+
$body.replaceChildren();
|
|
328
|
+
$foot.textContent = '';
|
|
329
|
+
if (state.mode === 'folder') {
|
|
330
|
+
$title.textContent = 'Let the Guide show you around?';
|
|
331
|
+
$sub.textContent = 'First, choose where your projects live.';
|
|
332
|
+
$body.append(el('p', 'guide-copy', 'The Guide keeps its conversation in your projects folder, next to your work. Choose it now; you can change it later in ≡ → Workspace directory.'));
|
|
333
|
+
$primary.textContent = 'Choose folder…';
|
|
334
|
+
$primary.dataset.commandId = 'shell.guide-choose-folder';
|
|
335
|
+
$secondary.textContent = 'Not now';
|
|
336
|
+
$secondary.dataset.commandId = 'shell.guide-not-now';
|
|
337
|
+
$foot.textContent = 'You can turn the Guide on later: ≡ menu → Guide.';
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const off = state.status?.consent?.choice === 'off';
|
|
341
|
+
$title.textContent = state.mode === 'start' ? 'Start the Guide' : off ? 'Turn the Guide back on?' : 'Let the Guide show you around?';
|
|
342
|
+
$sub.textContent = state.mode === 'start'
|
|
343
|
+
? 'The Guide takes a fresh look at this computer and starts its conversation in AI Chat. Here is what it would send.'
|
|
344
|
+
: 'The Guide is an assistant in AI Chat. It looks at what you work with on this computer, tells you what it sees, and suggests what to set up next.';
|
|
345
|
+
if (state.mode === 'consent') {
|
|
346
|
+
const reads = el('div', 'guide-block');
|
|
347
|
+
reads.append(el('h3', 'guide-heading', 'What it looks at'));
|
|
348
|
+
reads.append(sectionList([
|
|
349
|
+
'Programs installed on this computer, and which ones are open right now.',
|
|
350
|
+
'Files you opened recently — names and folders; FloLess doesn’t read inside them.',
|
|
351
|
+
'The accounts you’ve connected in FloLess — their names and whether they work, never passwords.',
|
|
352
|
+
'Email and Teams only if you later turn on your own connectors in the Guide chat. Claude asks before each use; Codex asks too, except for tools that declare themselves read-only.',
|
|
353
|
+
'While you talk, the Guide may open more files or folders to answer you.',
|
|
354
|
+
], (line) => line));
|
|
355
|
+
const lock = el('div', 'guide-callout');
|
|
356
|
+
lock.append(el('strong', '', 'It only reads — but read-only isn’t a lock. '),
|
|
357
|
+
document.createTextNode('The Guide is told never to change anything, and every change is a button you press. That is a rule the AI follows, not a lock: the AI program can open any folder you can.'));
|
|
358
|
+
const where = el('p', 'guide-copy');
|
|
359
|
+
where.textContent = `What the Guide sees is sent to ${providerName} under your own subscription, and kept in this conversation’s history on this computer. You can turn the Guide off or delete its history at any time; whatever ${providerName} already received stays under its own rules.`;
|
|
360
|
+
const gives = el('p', 'guide-copy', 'You get a short briefing on what you seem to be working on, then suggested next moves as buttons.');
|
|
361
|
+
$body.append(reads, lock, where, gives);
|
|
362
|
+
}
|
|
363
|
+
$body.append(
|
|
364
|
+
switchRow('guide-share-titles', 'Window titles', 'Shows what is open inside each running program. Off: program names only.', 'windowTitles'),
|
|
365
|
+
switchRow('guide-share-files', 'Recent file names', 'Off: only counts, such as “12 drawings, 3 models”. No names or folders.', 'recentFiles'),
|
|
366
|
+
providerChoice(),
|
|
367
|
+
renderPreview(),
|
|
368
|
+
);
|
|
369
|
+
if (state.banner) {
|
|
370
|
+
const banner = el('p', 'guide-banner', state.banner);
|
|
371
|
+
banner.setAttribute('role', 'status');
|
|
372
|
+
$body.append(banner);
|
|
373
|
+
}
|
|
374
|
+
$primary.textContent = state.busy ? 'Starting…' : state.mode === 'start' ? 'Start the Guide' : 'Turn on the Guide';
|
|
375
|
+
$primary.dataset.commandId = state.mode === 'start' ? 'shell.guide-start' : 'shell.guide-turn-on';
|
|
376
|
+
$primary.setAttribute('aria-busy', String(state.busy));
|
|
377
|
+
$secondary.textContent = state.mode === 'start' ? 'Cancel' : 'Not now';
|
|
378
|
+
$secondary.dataset.commandId = state.mode === 'start' ? 'shell.dialog-cancel#the Guide' : 'shell.guide-not-now';
|
|
379
|
+
if (state.mode === 'consent') $foot.textContent = 'You can turn the Guide on later: ≡ menu → Guide.';
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function takeLook() {
|
|
383
|
+
const seq = ++state.lookSeq;
|
|
384
|
+
state.preview = null; state.previewError = '';
|
|
385
|
+
paint();
|
|
386
|
+
try {
|
|
387
|
+
const body = await api('/api/chat/guide/preview', { provider: state.provider, share: state.share });
|
|
388
|
+
if (seq !== state.lookSeq) return;
|
|
389
|
+
state.preview = body.preview;
|
|
390
|
+
$live.textContent = 'Preview updated.';
|
|
391
|
+
} catch (error) {
|
|
392
|
+
if (seq !== state.lookSeq) return;
|
|
393
|
+
state.previewError = `FloLess couldn’t look at this computer: ${error.message}`;
|
|
394
|
+
}
|
|
395
|
+
if ($modal.classList.contains('show')) paint();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
let keyHandler = null;
|
|
399
|
+
async function showModal(mode) {
|
|
400
|
+
// One question at a time: a second ask while it is open (two clicks, the launch question racing ≡ → Guide) changes
|
|
401
|
+
// nothing, and never adds a second key listener.
|
|
402
|
+
if ($modal.classList.contains('show')) return;
|
|
403
|
+
if (keyHandler) { $modal.removeEventListener('keydown', keyHandler); keyHandler = null; }
|
|
404
|
+
state.provider = chooseProvider();
|
|
405
|
+
state.share = state.status?.consent?.share ? { ...state.status.consent.share } : { windowTitles: true, recentFiles: true };
|
|
406
|
+
state.banner = ''; state.busy = false; state.preview = null;
|
|
407
|
+
state.mode = !state.status?.workspace ? 'folder' : mode;
|
|
408
|
+
paint();
|
|
409
|
+
$modal.classList.add('show');
|
|
410
|
+
$title.focus();
|
|
411
|
+
keyHandler = (event) => {
|
|
412
|
+
if (event.key === 'Escape') { event.preventDefault(); void dismiss(); }
|
|
413
|
+
if (event.key === 'Tab') {
|
|
414
|
+
const focusable = [...$modal.querySelectorAll('button, input, summary, [tabindex="0"]')].filter((node) => !node.disabled && node.offsetParent !== null);
|
|
415
|
+
if (!focusable.length) return;
|
|
416
|
+
const first = focusable[0]; const last = focusable[focusable.length - 1];
|
|
417
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
418
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
// Heard on the dialog only: Esc pressed in a dialog opened over the Guide belongs to that dialog.
|
|
422
|
+
$modal.addEventListener('keydown', keyHandler);
|
|
423
|
+
if (state.mode !== 'folder') await takeLook();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function closeModal() {
|
|
427
|
+
$modal.classList.remove('show');
|
|
428
|
+
if (keyHandler) $modal.removeEventListener('keydown', keyHandler);
|
|
429
|
+
keyHandler = null;
|
|
430
|
+
state.lookSeq += 1;
|
|
431
|
+
const back = state.returnFocus?.isConnected ? state.returnFocus : document.getElementById('menu-btn');
|
|
432
|
+
back?.focus?.();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Not now (or Esc): remembered for a first-launch question; Cancel in start mode changes nothing. */
|
|
436
|
+
async function dismiss() {
|
|
437
|
+
const asking = state.mode !== 'start' && state.status?.consent?.choice !== 'off' && state.status?.consent?.choice !== 'on';
|
|
438
|
+
closeModal();
|
|
439
|
+
if (!asking) return;
|
|
440
|
+
try { await api('/api/chat/guide/consent', { choice: 'not-now', share: state.share }); }
|
|
441
|
+
catch (error) { toast(error.message, 'warn'); }
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async function chooseFolder() {
|
|
445
|
+
if (typeof openWorkspaceRoot !== 'function') { toast('Open ≡ → Workspace directory to choose where your projects live, then open the Guide again.', 'warn'); return; }
|
|
446
|
+
closeModal();
|
|
447
|
+
await openWorkspaceRoot();
|
|
448
|
+
// The folder chooser is its own dialog; when it closes with a folder set, this question continues.
|
|
449
|
+
const until = Date.now() + 10 * 60 * 1000;
|
|
450
|
+
while (Date.now() < until && document.querySelector('.modal-backdrop.show')) await new Promise((resolve) => setTimeout(resolve, 500));
|
|
451
|
+
try { await loadStatus(); }
|
|
452
|
+
catch (error) { toast(`FloLess couldn’t continue to the Guide: ${error.message} Open it again from ≡ → Guide.`, 'warn'); return; }
|
|
453
|
+
if (state.status?.workspace) await showModal('consent');
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async function confirm() {
|
|
457
|
+
if (state.mode === 'folder') { await chooseFolder(); return; }
|
|
458
|
+
if (state.busy) return;
|
|
459
|
+
if (!state.preview) { state.banner = 'Looking first, so you can see what goes. Press again once the preview is shown.'; paint(); return; }
|
|
460
|
+
state.busy = true; paint();
|
|
461
|
+
try {
|
|
462
|
+
const agreed = state.status?.consent?.share;
|
|
463
|
+
const changed = !agreed || agreed.windowTitles !== state.share.windowTitles || agreed.recentFiles !== state.share.recentFiles;
|
|
464
|
+
// Turning on, or (already on) a switch changed: the agreement is what the switches now show, with this preview.
|
|
465
|
+
if (state.mode === 'consent' || changed) {
|
|
466
|
+
await api('/api/chat/guide/consent', { choice: 'on', share: state.share, previewId: state.preview.previewId });
|
|
467
|
+
if (state.status) state.status = { ...state.status, consent: { choice: 'on', share: { ...state.share } } };
|
|
468
|
+
}
|
|
469
|
+
if (!readyProviders().includes(state.provider)) {
|
|
470
|
+
closeModal();
|
|
471
|
+
toast(`The Guide is on. It starts once you sign in to ${PROVIDER_LABEL[state.provider] || 'Claude Code or Codex'} in AI Chat — then open it from ≡ → Guide.`, 'info');
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
const started = await api('/api/chat/guide/start', {
|
|
475
|
+
provider: state.provider, previewId: state.preview.previewId, submissionId: crypto.randomUUID(),
|
|
476
|
+
});
|
|
477
|
+
closeModal();
|
|
478
|
+
await openGuideChat(started.chatId);
|
|
479
|
+
} catch (error) {
|
|
480
|
+
if (error.code === 'guide-preview-needed' && error.body?.preview) {
|
|
481
|
+
// Something changed since the person looked: show the fresh look; the next press sends that one.
|
|
482
|
+
state.mode = 'start';
|
|
483
|
+
state.preview = error.body.preview;
|
|
484
|
+
// The switches show exactly what this fresh preview was taken with.
|
|
485
|
+
if (error.body.preview.share) state.share = { ...error.body.preview.share };
|
|
486
|
+
state.banner = 'Something changed since you looked (or it’s been a while), so here is a fresh preview. Check it, then press Start the Guide.';
|
|
487
|
+
} else {
|
|
488
|
+
state.banner = error.message;
|
|
489
|
+
}
|
|
490
|
+
state.busy = false;
|
|
491
|
+
paint();
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
$primary?.addEventListener('click', () => { void confirm(); });
|
|
496
|
+
$secondary?.addEventListener('click', () => { void dismiss(); });
|
|
497
|
+
|
|
498
|
+
// ── Turn off / Delete (AI Chat's settings in a Guide conversation) ────────────────────────────────────────────
|
|
499
|
+
async function turnOff() {
|
|
500
|
+
try {
|
|
501
|
+
const body = await api('/api/chat/guide/consent', { choice: 'off' });
|
|
502
|
+
if (body.notStopped) {
|
|
503
|
+
toast('The Guide is off, but an answer it was writing could not be stopped. Press Stop in AI Chat to end it.', 'warn');
|
|
504
|
+
} else {
|
|
505
|
+
// Only this projects folder's answers can be stopped from here; one still running in another folder finishes
|
|
506
|
+
// the answer it is writing, and nothing more is sent to it (plan §1, as built). Say so rather than promise more.
|
|
507
|
+
const elsewhere = ' An answer it may still be writing for another projects folder finishes on its own; nothing more is sent to it.';
|
|
508
|
+
toast((body.stopped ? 'The Guide is off, and its work in progress here was stopped.' : 'The Guide is off. It won’t look at this computer again until you turn it on (≡ → Guide).') + elsewhere, 'info');
|
|
509
|
+
}
|
|
510
|
+
await loadStatus().catch(() => null);
|
|
511
|
+
return true;
|
|
512
|
+
} catch (error) { toast(error.message, 'warn'); return false; }
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async function deleteHistory() {
|
|
516
|
+
const ok = await confirmDelete();
|
|
517
|
+
if (!ok) return false;
|
|
518
|
+
try {
|
|
519
|
+
const body = await api('/api/chat/guide/delete', {});
|
|
520
|
+
if (body.failed) {
|
|
521
|
+
toast(`${body.deleted ? `Deleted ${body.deleted} Guide conversation${body.deleted === 1 ? '' : 's'}, but` : 'FloLess couldn’t delete'} ${body.failed} ${body.failed === 1 ? 'is' : 'are'} still busy or locked. Stop any answer in AI Chat, then delete again.`, 'warn');
|
|
522
|
+
} else {
|
|
523
|
+
toast(body.deleted ? 'Guide history deleted.' : 'There was no Guide history here to delete.', 'info');
|
|
524
|
+
}
|
|
525
|
+
await window.flolessChat?.refreshScope?.(true);
|
|
526
|
+
return true;
|
|
527
|
+
} catch (error) { toast(error.message, 'warn'); return false; }
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function confirmDelete() {
|
|
531
|
+
return new Promise((resolve) => {
|
|
532
|
+
const $confirm = document.getElementById('guide-delete-modal');
|
|
533
|
+
const cancel = document.getElementById('guide-delete-cancel');
|
|
534
|
+
const go = document.getElementById('guide-delete-confirm');
|
|
535
|
+
const back = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
536
|
+
const done = (value) => {
|
|
537
|
+
$confirm.classList.remove('show');
|
|
538
|
+
$confirm.removeEventListener('keydown', onKey);
|
|
539
|
+
cancel.removeEventListener('click', onCancel); go.removeEventListener('click', onGo);
|
|
540
|
+
back?.focus?.();
|
|
541
|
+
resolve(value);
|
|
542
|
+
};
|
|
543
|
+
const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); done(false); } };
|
|
544
|
+
const onCancel = () => done(false);
|
|
545
|
+
const onGo = () => done(true);
|
|
546
|
+
$confirm.addEventListener('keydown', onKey);
|
|
547
|
+
cancel.addEventListener('click', onCancel); go.addEventListener('click', onGo);
|
|
548
|
+
$confirm.classList.add('show');
|
|
549
|
+
cancel.focus();
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// ── next-move cards ───────────────────────────────────────────────────────────────────────────────────────────
|
|
554
|
+
function moveText(move) {
|
|
555
|
+
switch (move?.kind) {
|
|
556
|
+
case 'install-tool': return { title: `Install ${move.toolName}`, action: 'Review and install…' };
|
|
557
|
+
case 'create-workflow': return { title: `Create a workflow: ${move.name}`, action: 'Start this workflow…', detail: move.purpose };
|
|
558
|
+
case 'create-agent': return { title: `Set up an agent: ${move.name}`, action: 'Review this agent…' };
|
|
559
|
+
case 'create-routine': return { title: `Run ${move.target?.name || 'it'} on a schedule`, action: 'Set up the schedule…' };
|
|
560
|
+
case 'open': return { title: `Open ${PAGE_LABEL[move.page] || 'this page'}`, action: `Open ${PAGE_LABEL[move.page] || 'it'}` };
|
|
561
|
+
default: return null;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/** Opens the existing flow for a move; true when it opened. Nothing is done from here. */
|
|
566
|
+
async function openFlow(move) {
|
|
567
|
+
const bridge = window.flolessBridge;
|
|
568
|
+
switch (move.kind) {
|
|
569
|
+
case 'install-tool':
|
|
570
|
+
if (typeof openLibrary !== 'function') return false;
|
|
571
|
+
openLibrary(move.toolId, { tab: 'available' }); return true; // not installed yet: where its Install button is
|
|
572
|
+
case 'create-workflow':
|
|
573
|
+
if (typeof bridge?.newWorkflow !== 'function') return false;
|
|
574
|
+
await bridge.newWorkflow({ name: move.name }); return true;
|
|
575
|
+
case 'create-agent':
|
|
576
|
+
return Boolean(await window.flolessAgents?.newDraft?.({ name: move.name, instructions: move.instructions }));
|
|
577
|
+
case 'create-routine':
|
|
578
|
+
if (move.target?.kind === 'agent') { await window.flolessRoutines?.editForAgent?.(move.target.id); return Boolean(window.flolessRoutines); }
|
|
579
|
+
await window.flolessRoutines?.editForWorkflow?.(move.target?.id); return Boolean(window.flolessRoutines?.editForWorkflow);
|
|
580
|
+
case 'open':
|
|
581
|
+
if (['workspaces', 'workflows', 'agents'].includes(move.page)) { await window.flolessWorkspaces?.setMode?.(move.page); return Boolean(window.flolessWorkspaces); }
|
|
582
|
+
if (move.page === 'routines' && typeof openRoutines === 'function') { openRoutines(); return true; }
|
|
583
|
+
if (move.page === 'tools' && typeof openLibrary === 'function') { openLibrary(); return true; }
|
|
584
|
+
if (move.page === 'integrations' && typeof openIntegrations === 'function') { openIntegrations(); return true; }
|
|
585
|
+
// Discover Local Tools answers the same ≡-menu action the Tools window's button uses (web/local-discovery.js).
|
|
586
|
+
if (move.page === 'discover' && typeof handleMenuAction === 'function') { handleMenuAction('discover-local'); return Boolean(document.querySelector('#local-discovery-modal.show')); }
|
|
587
|
+
if (move.page === 'requests' && typeof bridge?.openRequest === 'function') { await bridge.openRequest(null); return true; }
|
|
588
|
+
return false;
|
|
589
|
+
default: return false;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const SET_ASIDE_KEY = 'floless:guide-moves-set-aside';
|
|
594
|
+
function setAside() {
|
|
595
|
+
try { return new Set(JSON.parse(localStorage.getItem(SET_ASIDE_KEY) || '[]')); } catch { return new Set(); }
|
|
596
|
+
}
|
|
597
|
+
function markSetAside(moveId, on) {
|
|
598
|
+
const ids = setAside();
|
|
599
|
+
if (on) ids.add(moveId); else ids.delete(moveId);
|
|
600
|
+
try { localStorage.setItem(SET_ASIDE_KEY, JSON.stringify([...ids].slice(-200))); } catch { /* private window: this view only */ }
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** A next-move event as a card. Its text is the AI's: textContent only. */
|
|
604
|
+
function renderNextMove(event) {
|
|
605
|
+
const payload = event.payload || {};
|
|
606
|
+
const move = payload.move;
|
|
607
|
+
const text = moveText(move);
|
|
608
|
+
const moveId = String(payload.moveId || event.eventId || '');
|
|
609
|
+
if (!text) return null;
|
|
610
|
+
const card = el('section', 'ai-chat-filter-card ai-chat-connection-card guide-move-card');
|
|
611
|
+
card.dataset.eventId = event.eventId;
|
|
612
|
+
card.dataset.eventSequence = String(event.sequence);
|
|
613
|
+
card.setAttribute('role', 'group');
|
|
614
|
+
card.setAttribute('aria-label', `Suggestion: ${text.title}`);
|
|
615
|
+
const status = el('p', 'ai-chat-filter-note guide-move-status');
|
|
616
|
+
status.setAttribute('role', 'status');
|
|
617
|
+
const paintCard = () => {
|
|
618
|
+
card.replaceChildren();
|
|
619
|
+
if (setAside().has(moveId)) {
|
|
620
|
+
const line = el('div', 'ai-chat-connection-collapsed');
|
|
621
|
+
const undo = el('button', '', 'Undo');
|
|
622
|
+
undo.type = 'button';
|
|
623
|
+
undo.dataset.commandId = 'shell.guide-move-undo';
|
|
624
|
+
undo.dataset.commandInstanceLabel = text.title;
|
|
625
|
+
undo.dataset.tip = 'Shows this suggestion again.';
|
|
626
|
+
undo.addEventListener('click', () => { markSetAside(moveId, false); paintCard(); });
|
|
627
|
+
line.append(el('span', '', `Not now: ${text.title}`), undo);
|
|
628
|
+
card.append(line);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const head = el('div', 'ai-chat-filter-card-head');
|
|
632
|
+
head.append(el('span', 'guide-move-eyebrow', 'Suggested'), el('strong', '', text.title));
|
|
633
|
+
card.append(head);
|
|
634
|
+
const why = typeof payload.why === 'string' ? payload.why.trim() : '';
|
|
635
|
+
if (text.detail) card.append(el('p', 'ai-chat-filter-why', text.detail));
|
|
636
|
+
if (why) card.append(el('p', 'ai-chat-filter-why', why));
|
|
637
|
+
const actions = el('div', 'ai-chat-filter-actions');
|
|
638
|
+
const go = el('button', 'ai-chat-filter-apply', text.action);
|
|
639
|
+
go.type = 'button';
|
|
640
|
+
go.dataset.commandId = `shell.guide-move-open#${move.kind}`;
|
|
641
|
+
go.dataset.commandInstanceLabel = text.title;
|
|
642
|
+
go.dataset.tip = 'Opens the place to do this. Nothing happens until you confirm there.';
|
|
643
|
+
go.addEventListener('click', async () => {
|
|
644
|
+
go.disabled = true; go.setAttribute('aria-busy', 'true'); go.textContent = 'Checking…';
|
|
645
|
+
status.textContent = '';
|
|
646
|
+
try {
|
|
647
|
+
const { check } = await api('/api/chat/guide/next-moves/recheck', { move });
|
|
648
|
+
if (!check.ok) { status.textContent = check.message; return; }
|
|
649
|
+
const opened = await openFlow(move);
|
|
650
|
+
if (!opened) status.textContent = 'FloLess couldn’t open that from here. Open it from the ≡ menu instead.';
|
|
651
|
+
} catch (error) {
|
|
652
|
+
status.textContent = error.message;
|
|
653
|
+
} finally {
|
|
654
|
+
go.disabled = false; go.removeAttribute('aria-busy'); go.textContent = text.action;
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
const later = el('button', '', 'Not now');
|
|
658
|
+
later.type = 'button';
|
|
659
|
+
later.dataset.commandId = 'shell.guide-move-not-now';
|
|
660
|
+
later.dataset.commandInstanceLabel = text.title;
|
|
661
|
+
later.dataset.tip = 'Sets this suggestion aside. You can bring it back.';
|
|
662
|
+
later.addEventListener('click', () => { markSetAside(moveId, true); paintCard(); });
|
|
663
|
+
actions.append(go, later);
|
|
664
|
+
card.append(actions, el('p', 'ai-chat-filter-note', 'Nothing happens until you confirm in the next step.'), status);
|
|
665
|
+
};
|
|
666
|
+
paintCard();
|
|
667
|
+
return card;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
window.flolessGuide = { open, maybeAskOnLaunch, turnOff, deleteHistory, renderNextMove, status: loadStatus };
|
|
671
|
+
|
|
672
|
+
// Ask once, after AI Chat is ready and the app has settled.
|
|
673
|
+
const askLater = () => setTimeout(() => { void maybeAskOnLaunch(); }, 2500);
|
|
674
|
+
if (window.flolessChat) askLater(); else window.addEventListener('floless:chat-ready', askLater, { once: true });
|
|
675
|
+
})();
|