@floless/app 0.155.1 → 0.156.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.
Files changed (46) hide show
  1. package/cli-actions.mjs +376 -0
  2. package/dist/floless-server.cjs +101615 -87681
  3. package/dist/skills/floless-app-actions/SKILL.md +137 -0
  4. package/dist/skills/floless-app-approval/SKILL.md +8 -5
  5. package/dist/skills/floless-app-bridge/SKILL.md +12 -9
  6. package/dist/skills/floless-app-knowledge/SKILL.md +30 -13
  7. package/dist/skills/floless-app-new-workflow/SKILL.md +4 -4
  8. package/dist/skills/floless-app-onboarding/SKILL.md +1 -1
  9. package/dist/skills/floless-app-onboarding/references/aware-runtime.md +4 -4
  10. package/dist/skills/floless-app-queue/SKILL.md +10 -6
  11. package/dist/skills/floless-app-report-issue/SKILL.md +13 -10
  12. package/dist/skills/floless-app-rfi/SKILL.md +59 -68
  13. package/dist/skills/floless-app-routines/SKILL.md +19 -14
  14. package/dist/skills/floless-app-routines/references/routines-api.md +8 -2
  15. package/dist/skills/floless-app-workflows/SKILL.md +5 -4
  16. package/dist/web/agent-steps.js +933 -0
  17. package/dist/web/agents.js +5 -0
  18. package/dist/web/app.css +210 -5
  19. package/dist/web/app.js +1 -0
  20. package/dist/web/aware.js +584 -44
  21. package/dist/web/chat.css +9 -0
  22. package/dist/web/chat.js +195 -13
  23. package/dist/web/commands-shell.js +299 -1
  24. package/dist/web/commands-tekla-parser.js +7 -0
  25. package/dist/web/index.html +52 -1
  26. package/dist/web/instructor.js +5 -3
  27. package/dist/web/leave-guard.js +4 -2
  28. package/dist/web/left-pane.js +145 -42
  29. package/dist/web/model-editor.css +10 -0
  30. package/dist/web/model-group-navigator.js +331 -0
  31. package/dist/web/model-panel-bridge.js +63 -5
  32. package/dist/web/model-pointer-dock.js +55 -5
  33. package/dist/web/model-revit-module.js +15 -0
  34. package/dist/web/model-selection-tools.js +53 -17
  35. package/dist/web/model-tekla-selection.js +75 -2
  36. package/dist/web/model-viewport-revit-adapter.js +17 -10
  37. package/dist/web/pages.js +27 -3
  38. package/dist/web/panels.js +3 -3
  39. package/dist/web/project-reconciliation.js +357 -0
  40. package/dist/web/revit-editor.js +464 -76
  41. package/dist/web/steel-3d-view.js +1 -0
  42. package/dist/web/terminal-requests.js +541 -0
  43. package/dist/web/tool-updates.js +147 -13
  44. package/dist/web/workspaces.js +213 -12
  45. package/launch.mjs +80 -2
  46. package/package.json +1 -1
@@ -0,0 +1,376 @@
1
+ // `floless-app actions` / `floless-app do` (#2248, design §2.2): drive FloLess from a terminal through
2
+ // its action catalog — the same live list the AI chat and `/api/actions` read, so nothing here is a
3
+ // second copy of what FloLess can do.
4
+ //
5
+ // floless-app actions [area] [--json]
6
+ // floless-app actions describe <id> [--json]
7
+ // floless-app do <id> [--input '<json>' | --input-file <file>] [--wait] [--json]
8
+ //
9
+ // Dependency-free (Node built-ins only), like the rest of the launcher: it talks to the local server
10
+ // over HTTP and starts it when it is not running, as `login` does. Every gate on the server applies
11
+ // (sign-in 402, AWARE readiness, the Run drift gate) because each action is the UI's own route.
12
+ //
13
+ // There is no `--yes` (owner ruling): an action the catalog will not run straight from a terminal —
14
+ // a real workflow run, anything destructive, anything only a person does — comes back as a request
15
+ // the person answers IN FloLess. This file prints what it will do and where to answer it, and with
16
+ // `--wait` it watches the request until it is done, declined or expired. It never confirms anything:
17
+ // it has no confirm verb and never names the route the in-app card uses (a convention, not a security
18
+ // boundary — design §3). Its one proposal verb is Stop, on Ctrl+C while a run it waits on is running.
19
+ //
20
+ // `--json` prints AWARE's envelope `{ ok, data, error: { code, message, details }, meta }` on stdout;
21
+ // human output is plain English. The exit code says how it ended (EXIT below).
22
+ import { readFileSync } from 'node:fs';
23
+
24
+ /** Exit codes. `waiting` is not a failure: the request was made and nothing has run yet. */
25
+ export const EXIT = Object.freeze({ ok: 0, failed: 1, usage: 2, waiting: 3 });
26
+
27
+ /** The commands this module owns; the launcher hands it every argv that starts with one of them. */
28
+ export const ACTIONS_CLI_COMMANDS = Object.freeze(['actions', 'do']);
29
+
30
+ /** The one proposal verb a terminal uses: stopping a run it is waiting on (Ctrl+C). It has no other. */
31
+ const STOP_VERB = 'cancel';
32
+
33
+ /** How long `--wait` keeps asking between polls, and its ceiling past the request's own expiry. */
34
+ export const WAIT_POLL_MS = 1500;
35
+ const EXPIRY_GRACE_MS = 5000;
36
+ /** How many times a failed status check is tried before --wait gives up on it. */
37
+ const POLL_TRIES = 3;
38
+
39
+ const USAGE = [
40
+ 'Use:',
41
+ ' floless-app actions [area] [--json] list what FloLess can do',
42
+ ' floless-app actions describe <id> [--json] what one action does and the input it takes',
43
+ ' floless-app do <id> [--input \'<json>\' | --input-file <file>] [--wait] [--json]',
44
+ ].join('\n');
45
+
46
+ class UsageError extends Error {}
47
+
48
+ /**
49
+ * Parse the argv that follows the program name, e.g. `['do', 'projects.list', '--json']`.
50
+ * Returns `{ ok: true, command, ... }` or `{ ok: false, message }` (a usage error, nothing sent).
51
+ */
52
+ export function parseActionsArgv(argv) {
53
+ try {
54
+ return { ok: true, ...parseOrThrow([...argv]) };
55
+ } catch (error) {
56
+ if (error instanceof UsageError) return { ok: false, message: error.message };
57
+ throw error;
58
+ }
59
+ }
60
+
61
+ function parseOrThrow(args) {
62
+ const verb = args.shift();
63
+ const flags = { json: false, wait: false, input: undefined, inputFile: undefined };
64
+ const positional = [];
65
+ while (args.length) {
66
+ const arg = args.shift();
67
+ const [name, inline] = arg.startsWith('--') && arg.includes('=') ? [arg.slice(0, arg.indexOf('=')), arg.slice(arg.indexOf('=') + 1)] : [arg, undefined];
68
+ if (name === '--json') flags.json = true;
69
+ else if (name === '--wait') flags.wait = true;
70
+ else if (name === '--input' || name === '--input-file') {
71
+ const value = inline ?? args.shift();
72
+ if (value === undefined) throw new UsageError(`${name} needs a value.`);
73
+ const key = name === '--input' ? 'input' : 'inputFile';
74
+ if (flags[key] !== undefined) throw new UsageError(`${name} was given twice.`);
75
+ flags[key] = value;
76
+ } else if (name.startsWith('-')) throw new UsageError(`"${name}" is not an option here.`);
77
+ else positional.push(arg);
78
+ }
79
+ const doOnly = flags.wait || flags.input !== undefined || flags.inputFile !== undefined;
80
+ if (verb === 'actions') {
81
+ if (doOnly) throw new UsageError('--input, --input-file and --wait belong to "floless-app do".');
82
+ if (positional[0] === 'describe') {
83
+ if (positional.length !== 2) throw new UsageError('Name one action to describe, e.g. "floless-app actions describe projects.list".');
84
+ return { command: 'describe', id: positional[1], json: flags.json };
85
+ }
86
+ if (positional.length > 1) throw new UsageError('Give at most one area, e.g. "floless-app actions workflows".');
87
+ return { command: 'list', area: positional[0] ?? null, json: flags.json };
88
+ }
89
+ if (verb === 'do') {
90
+ if (positional.length !== 1) throw new UsageError('Name one action to do, e.g. "floless-app do projects.list".');
91
+ if (flags.input !== undefined && flags.inputFile !== undefined) throw new UsageError('Give --input or --input-file, not both.');
92
+ return { command: 'do', id: positional[0], input: flags.input, inputFile: flags.inputFile, wait: flags.wait, json: flags.json };
93
+ }
94
+ throw new UsageError(`"${verb ?? ''}" is not an actions command.`);
95
+ }
96
+
97
+ /** Read the action input from `--input` or `--input-file`: a JSON object, or `{}` when neither is given. */
98
+ export function resolveInput(parsed, readFile = (f) => readFileSync(f, 'utf8')) {
99
+ let text;
100
+ if (parsed.inputFile !== undefined) {
101
+ try { text = readFile(parsed.inputFile); }
102
+ catch (error) { return { ok: false, code: 'input-unreadable', message: `FloLess could not read ${parsed.inputFile}: ${error?.code === 'ENOENT' ? 'there is no such file' : error?.message ?? error}.` }; }
103
+ text = text.replace(/^/, '');
104
+ } else if (parsed.input !== undefined) text = parsed.input;
105
+ else return { ok: true, input: {} };
106
+ let value;
107
+ try { value = JSON.parse(text); }
108
+ catch (error) { return { ok: false, code: 'invalid-input', message: `The input is not valid JSON (${error.message}). Give an object, e.g. --input '{"workflowId":"dummy-report"}'.` }; }
109
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
110
+ return { ok: false, code: 'invalid-input', message: 'The input must be a JSON object, e.g. {"workflowId":"dummy-report"}.' };
111
+ }
112
+ return { ok: true, input: value };
113
+ }
114
+
115
+ /** AWARE's envelope: all four keys, always. */
116
+ export function envelope(ok, data, error, meta) {
117
+ return { ok, data: ok ? (data ?? null) : null, error: ok ? null : { code: error.code, message: error.message, details: error.details ?? null }, meta };
118
+ }
119
+
120
+ const SIGN_IN = 'FloLess needs you to sign in before it can do this. Run "floless-app login", then try again.';
121
+ const SEAT_TAKEN = 'Your FloLess subscription is in use on another computer. Open FloLess there to sign out, or run "floless-app login" here to take it over.';
122
+
123
+ /** The proposal states after which nothing more will happen. */
124
+ const FINAL = new Set(['done', 'failed', 'cancelled', 'unknown', 'declined', 'expired']);
125
+
126
+ /**
127
+ * Run one actions command. Every side effect is injected so it can be tested without a server:
128
+ * request(method, path, body?) → { status, body } (body parsed JSON, or null) — throws when unreachable
129
+ * ensureServer() → boolean start the server if needed; false when it would not start
130
+ * out(text) / err(text) stdout / stderr lines
131
+ * readFile(path) → string, sleep(ms), now() → ms, onInterrupt(fn) → unsubscribe
132
+ * Returns the exit code.
133
+ */
134
+ export async function runActionsCli(argv, deps) {
135
+ const started = deps.now();
136
+ const parsed = parseActionsArgv(argv);
137
+ const json = parsed.ok ? parsed.json : argv.includes('--json');
138
+ const commandName = parsed.ok ? (parsed.command === 'list' ? 'actions' : parsed.command === 'describe' ? 'actions describe' : 'do') : String(argv[0] ?? '');
139
+ const meta = (extra = {}) => ({ command: commandName, 'duration-ms': deps.now() - started, ...extra });
140
+ const fail = (code, message, details, exit = EXIT.failed, extraMeta = {}) => {
141
+ if (json) deps.out(JSON.stringify(envelope(false, null, { code, message, details }, meta(extraMeta))));
142
+ else deps.err(message);
143
+ return exit;
144
+ };
145
+ const succeed = (data, lines, extraMeta = {}, exit = EXIT.ok) => {
146
+ if (json) deps.out(JSON.stringify(envelope(true, data, null, meta(extraMeta))));
147
+ else for (const line of lines) deps.out(line);
148
+ return exit;
149
+ };
150
+
151
+ if (!parsed.ok) return fail('usage', `${parsed.message}\n${USAGE}`, null, EXIT.usage);
152
+
153
+ let input = {};
154
+ if (parsed.command === 'do') {
155
+ const read = resolveInput(parsed, deps.readFile);
156
+ if (!read.ok) return fail(read.code, read.message, null, EXIT.usage);
157
+ input = read.input;
158
+ }
159
+
160
+ if (!(await deps.ensureServer())) {
161
+ return fail('server-unavailable', 'FloLess is not running and did not start. Open FloLess (or run "floless-app open"), then try again.');
162
+ }
163
+
164
+ /** One request; a 402 or an unreachable server becomes a plain failure the caller returns. */
165
+ const call = async (method, path, body) => {
166
+ let res;
167
+ try { res = await deps.request(method, path, body); }
168
+ catch (error) {
169
+ return { failed: fail('server-unavailable', 'FloLess stopped answering. Check that it is still running, then try again.', { reason: String(error?.message ?? error) }) };
170
+ }
171
+ if (res.status === 402) {
172
+ const reason = res.body && typeof res.body === 'object' ? res.body.reason : undefined;
173
+ return { failed: fail('subscription-required', reason === 'seat-taken' ? SEAT_TAKEN : SIGN_IN, { reason: reason ?? null }) };
174
+ }
175
+ return { res };
176
+ };
177
+
178
+ if (parsed.command === 'list') {
179
+ const { res, failed } = await call('GET', `/api/actions${parsed.area ? `?area=${encodeURIComponent(parsed.area)}` : ''}`);
180
+ if (failed !== undefined) return failed;
181
+ if (res.status !== 200 || !Array.isArray(res.body?.actions)) return fail('failed', "FloLess could not list its actions just now. Check that it is running and signed in, then try again.", { status: res.status, body: res.body });
182
+ const actions = res.body.actions;
183
+ const tools = Array.isArray(res.body.tools) ? res.body.tools : [];
184
+ return succeed({ actions, tools }, humanList(actions, parsed.area), { area: parsed.area });
185
+ }
186
+
187
+ if (parsed.command === 'describe') {
188
+ const { res, failed } = await call('GET', `/api/actions/${encodeURIComponent(parsed.id)}`);
189
+ if (failed !== undefined) return failed;
190
+ if (res.status === 404) return fail('unknown-action', `FloLess has no action called "${parsed.id}". Run "floless-app actions" to see the ones it has.`);
191
+ if (res.status !== 200 || !res.body?.action) return fail('failed', `FloLess could not describe "${parsed.id}" just now. Try again in a moment.`, { status: res.status, body: res.body });
192
+ return succeed(res.body.action, humanDescribe(res.body.action), { action: parsed.id });
193
+ }
194
+
195
+ // do
196
+ const { res, failed } = await call('POST', `/api/actions/${encodeURIComponent(parsed.id)}`, { input });
197
+ if (failed !== undefined) return failed;
198
+ const body = res.body && typeof res.body === 'object' ? res.body : null;
199
+ if (res.status === 404 && body?.error?.code === 'unknown-action') {
200
+ return fail('unknown-action', `FloLess has no action called "${parsed.id}". Run "floless-app actions" to see the ones it has.`);
201
+ }
202
+ if (!body || typeof body.ok !== 'boolean' || !body.meta) {
203
+ return fail('failed', "FloLess answered in a way this command does not understand; it may be a different version. Update FloLess, then try again.", { status: res.status, body });
204
+ }
205
+ const actionMeta = { action: body.meta.action ?? parsed.id, callId: body.meta.callId ?? null, outcome: body.meta.outcome ?? null, consent: body.meta.consent ?? null, ...(body.meta.status ? { status: body.meta.status } : {}) };
206
+ if (!body.ok) {
207
+ const code = body.error?.code ?? 'failed';
208
+ const message = code === 'subscription-required' ? SIGN_IN : body.error?.message ?? 'It did not complete.';
209
+ return fail(code, message, body.error?.details ?? null, code === 'invalid-input' ? EXIT.usage : EXIT.failed, actionMeta);
210
+ }
211
+ const proposal = body.data && typeof body.data === 'object' ? body.data.proposal : null;
212
+ if (!proposal && actionMeta.outcome === 'pending') {
213
+ // FloLess says a request is waiting but did not send it: reporting that as done would claim a run that never happened.
214
+ return fail('failed', "FloLess answered in a way this command does not understand; it may be a different version. Update FloLess, then try again.", { body }, EXIT.failed, actionMeta);
215
+ }
216
+ if (!proposal) {
217
+ // It ran (a read, or a write a terminal may make): the result is the action's own answer.
218
+ return succeed(body.data, humanResult(parsed.id, body.data), actionMeta);
219
+ }
220
+ // A request the person answers in FloLess. Nothing has run.
221
+ const reviewUrl = typeof body.data.reviewUrl === 'string' ? body.data.reviewUrl : null;
222
+ // A step only a person does never finishes in FloLess's records (it is done on its own screen), so there is
223
+ // nothing to wait for: --wait reports it and returns at once.
224
+ if (!parsed.wait || proposal.risk === 'human-only') {
225
+ const lines = humanProposal(proposal, reviewUrl);
226
+ if (parsed.wait) lines.push('There is nothing to wait for: FloLess never does this step, so it cannot report when you have.');
227
+ return succeed({ proposal, reviewUrl }, lines, { ...actionMeta, outcome: 'pending' }, EXIT.waiting);
228
+ }
229
+ if (!json) for (const line of humanProposal(proposal, reviewUrl)) deps.out(line);
230
+ if (!json) deps.out('Waiting for your answer in FloLess… (Ctrl+C stops waiting; once it is running, Ctrl+C stops the run.)');
231
+ return waitForAnswer(proposal, reviewUrl, { deps, call, fail, succeed, json, actionMeta });
232
+ }
233
+
234
+ /** Poll one proposal until it ends, following a replacement when the person was shown a fresh one. */
235
+ async function waitForAnswer(first, firstUrl, { deps, call, fail, succeed, json, actionMeta }) {
236
+ let proposal = first;
237
+ let reviewUrl = firstUrl;
238
+ let interrupted = false;
239
+ const stop = deps.onInterrupt?.(() => { interrupted = true; }) ?? (() => {});
240
+ try {
241
+ for (;;) {
242
+ if (interrupted) {
243
+ // The person may have pressed Run it since the last poll: decide from the current state, not a cached one.
244
+ const latest = await call('GET', `/api/actions/proposals/${encodeURIComponent(proposal.id)}`);
245
+ if (latest.res?.status === 200 && latest.res.body?.proposal) proposal = latest.res.body.proposal;
246
+ if (proposal.state !== 'executing') {
247
+ return fail('interrupted', 'Stopped waiting. The request is still open in FloLess until it expires.', { proposal, reviewUrl }, EXIT.waiting, { ...actionMeta, proposalId: proposal.id });
248
+ }
249
+ // Ctrl+C while it runs stops the run, as Stop on its card does (design §1: a CLI interrupt cancels the run it
250
+ // waited on). Asking to stop is all this does; it never starts or confirms anything.
251
+ const { res, failed } = await call('POST', `/api/actions/proposals/${encodeURIComponent(proposal.id)}/${STOP_VERB}`, {});
252
+ if (failed !== undefined) return failed;
253
+ const asked = res.status === 200;
254
+ return fail('interrupted', asked
255
+ ? 'Stopped: FloLess asked the run to stop. Work already sent to the host may remain.'
256
+ : 'Stopped waiting. FloLess could not stop the run (it may have just finished); check it in FloLess.', { proposal, reviewUrl }, EXIT.failed, { ...actionMeta, proposalId: proposal.id });
257
+ }
258
+ // A card that was replaced is marked `superseded` (its approved version changed) or `expired` (it timed out or FloLess
259
+ // restarted, and the person pressed Run it): either way a fresh card is waiting for the answer, so it is followed.
260
+ if ((proposal.state === 'superseded' || proposal.state === 'expired') && typeof proposal.supersededBy === 'string') {
261
+ const { res, failed } = await call('GET', `/api/actions/proposals/${encodeURIComponent(proposal.supersededBy)}`);
262
+ if (failed !== undefined) return failed;
263
+ if (res.status !== 200 || !res.body?.proposal) return fail('proposal-gone', 'FloLess replaced the request with a newer one that no longer exists. Ask again.', null);
264
+ proposal = res.body.proposal;
265
+ reviewUrl = typeof res.body.reviewUrl === 'string' ? res.body.reviewUrl : reviewUrl;
266
+ if (!json) deps.out(`${proposal.changedNote ?? 'It changed after it was asked.'} FloLess shows the current request: ${reviewUrl ?? 'open FloLess to answer it'}`);
267
+ continue;
268
+ }
269
+ if (proposal.state === 'superseded') return fail('proposal-gone', 'FloLess replaced the request but did not say with what. Ask again.', { proposal }, EXIT.failed, { ...actionMeta, proposalId: proposal.id });
270
+ if (FINAL.has(proposal.state)) return finish(proposal, { fail, succeed, actionMeta });
271
+ // FloLess only marks an unanswered request expired when someone opens it; past its expiry nobody can confirm it.
272
+ if (proposal.state === 'proposed' && deps.now() > Date.parse(proposal.expiresAt) + EXPIRY_GRACE_MS) {
273
+ return finish({ ...proposal, state: 'expired' }, { fail, succeed, actionMeta });
274
+ }
275
+ await deps.sleep(WAIT_POLL_MS);
276
+ if (interrupted) continue;
277
+ // One poll that fails is not the end: the run may be going fine, so a few tries are made before giving up.
278
+ let answer;
279
+ for (let attempt = 1; attempt <= POLL_TRIES; attempt++) {
280
+ answer = await call('GET', `/api/actions/proposals/${encodeURIComponent(proposal.id)}`);
281
+ const ok = answer.failed === undefined && (answer.res.status === 404 || (answer.res.status === 200 && answer.res.body?.proposal));
282
+ if (ok || attempt === POLL_TRIES || interrupted) break;
283
+ await deps.sleep(WAIT_POLL_MS);
284
+ }
285
+ const { res, failed } = answer;
286
+ if (failed !== undefined) return failed;
287
+ if (res.status === 404) return fail('proposal-gone', 'FloLess no longer has that request (it may have restarted). Ask again.', null, EXIT.failed, { ...actionMeta, proposalId: proposal.id });
288
+ if (res.status !== 200 || !res.body?.proposal) return fail('failed', "FloLess could not say how the request is going. Check it in FloLess.", { status: res.status, body: res.body });
289
+ proposal = res.body.proposal;
290
+ }
291
+ } finally {
292
+ stop();
293
+ }
294
+ }
295
+
296
+ /** How a request ended → exit code + words. Only `done` is success. */
297
+ function finish(p, { fail, succeed, actionMeta }) {
298
+ const meta = { ...actionMeta, proposalId: p.id, outcome: p.state === 'done' ? 'ok' : p.state };
299
+ const title = p.title ?? p.actionId;
300
+ if (p.state === 'done') {
301
+ const lines = [`Done: ${p.summary ?? title}.`];
302
+ if (p.doneNote) lines.push(p.doneNote);
303
+ if (p.next?.label) lines.push(`In FloLess: ${p.next.label}${p.next.runId ? ` (run ${p.next.runId})` : ''}.`);
304
+ return succeed({ proposal: p }, lines, meta);
305
+ }
306
+ const words = {
307
+ declined: `You chose Not now in FloLess, so nothing ran: ${p.summary ?? title}.`,
308
+ expired: `The request expired before anyone answered it, so nothing ran. Ask again if you still want it: ${p.summary ?? title}.`,
309
+ failed: `It did not complete: ${(p.result?.message ?? 'FloLess reported a failure').replace(/[.\s]+$/, '')}.`,
310
+ cancelled: 'It was stopped in FloLess. Work already sent to the host may remain.',
311
+ unknown: 'FloLess restarted while this was running, so how it ended is not known. Check the result in FloLess.',
312
+ }[p.state] ?? `It ended as "${p.state}".`;
313
+ return fail(p.state === 'failed' ? (p.result?.code ?? 'failed') : p.state, words, { proposal: p }, EXIT.failed, meta);
314
+ }
315
+
316
+ // ── Plain-English output ────────────────────────────────────────────────────────────────────────
317
+
318
+ const RISK_WORDS = { read: 'reads only', write: 'makes a change', destructive: 'asks you first', 'human-only': 'you do it in FloLess' };
319
+
320
+ function humanList(actions, area) {
321
+ if (!actions.length) return [area ? `FloLess has no actions in "${area}". Run "floless-app actions" to see every area.` : 'FloLess has no actions yet.'];
322
+ const lines = [];
323
+ let current = null;
324
+ const width = Math.min(32, Math.max(...actions.map((a) => String(a.id).length)));
325
+ for (const a of actions) {
326
+ if (a.area !== current) { if (current !== null) lines.push(''); lines.push(`${a.area}`); current = a.area; }
327
+ lines.push(` ${String(a.id).padEnd(width)} ${a.title} (${RISK_WORDS[a.risk] ?? a.risk})`);
328
+ }
329
+ lines.push('', 'Run "floless-app actions describe <id>" to see what an action takes.');
330
+ return lines;
331
+ }
332
+
333
+ function humanDescribe(a) {
334
+ const lines = [`${a.id}: ${a.title}`, '', a.description, '', `Risk: ${a.risk} (${RISK_WORDS[a.risk] ?? a.risk}). ${a.riskReason}`];
335
+ const schema = a.inputSchema && typeof a.inputSchema === 'object' ? a.inputSchema : {};
336
+ const props = schema.properties && typeof schema.properties === 'object' ? Object.entries(schema.properties) : [];
337
+ const required = new Set(Array.isArray(schema.required) ? schema.required : []);
338
+ lines.push('');
339
+ if (!props.length) lines.push('Input: none. Run it with "floless-app do ' + a.id + '".');
340
+ else {
341
+ lines.push('Input:');
342
+ for (const [name, p] of props) {
343
+ const type = p && typeof p === 'object' ? (p.type ?? (p.anyOf ? 'one of several' : 'value')) : 'value';
344
+ lines.push(` ${name} (${Array.isArray(type) ? type.join(' or ') : type}${required.has(name) ? ', required' : ''})${p?.description ? `: ${p.description}` : ''}`);
345
+ }
346
+ const example = Object.fromEntries(props.filter(([n]) => required.has(n)).map(([n]) => [n, '…']));
347
+ lines.push('', `Example: floless-app do ${a.id} --input '${JSON.stringify(example)}'`);
348
+ }
349
+ if (a.risk === 'destructive' || a.risk === 'human-only') {
350
+ lines.push('', a.risk === 'human-only'
351
+ ? 'FloLess never does this for you: "do" opens the screen where you do it yourself.'
352
+ : 'Nothing runs straight away: "do" asks you to confirm it in FloLess first. Add --wait to wait for your answer.');
353
+ }
354
+ return lines;
355
+ }
356
+
357
+ function humanResult(id, data) {
358
+ const text = JSON.stringify(data, null, 2) ?? 'null';
359
+ return [`Done: ${id}.`, text];
360
+ }
361
+
362
+ function humanProposal(p, reviewUrl) {
363
+ if (p.risk === 'human-only') {
364
+ return [
365
+ `Only you can do this: ${p.summary ?? p.title}.`,
366
+ 'Nothing has been done. FloLess opens the screen where you do it yourself.',
367
+ reviewUrl ? `Open it in FloLess: ${reviewUrl}` : 'Open FloLess to find it.',
368
+ ];
369
+ }
370
+ return [
371
+ `FloLess needs your OK first: ${p.summary ?? p.title}.`,
372
+ 'Nothing has run yet.',
373
+ reviewUrl ? `Answer it in FloLess: ${reviewUrl}` : 'Open FloLess to answer it.',
374
+ `The request stays open until ${new Date(p.expiresAt).toLocaleTimeString()}.`,
375
+ ];
376
+ }