@floless/app 0.124.0 → 0.125.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/web/aware.js CHANGED
@@ -6750,9 +6750,14 @@
6750
6750
 
6751
6751
  // ── reverse channel: record intent for the host AI, copy a paste-ready line ──
6752
6752
  function instructionFor(req) {
6753
+ // `t.node` guarded, not assumed: a template saved by an older build (or hand-edited in
6754
+ // templates.json) can carry a name and no node, and reading `.agent` off undefined THREW out of
6755
+ // renderRequests' .map(), so `$list.innerHTML` was never assigned and loadRequests' `catch {}`
6756
+ // ate it — the chip kept counting requests over a list that had silently stopped rendering.
6753
6757
  if (req.type === 'use-template' && req.template) {
6754
6758
  const t = req.template;
6755
- return `In floless app "${req.appId}", add a node from my saved template "${t.name}" (agent ${t.node.agent || t.node.kind}${t.node.command ? ' / ' + t.node.command : ''}, config ${JSON.stringify(t.node.config || {})}). Edit the .flo, then run \`aware app compile\`.`;
6759
+ const n = t.node || {};
6760
+ return `In floless app "${req.appId}", add a node from my saved template "${t.name}" (agent ${n.agent || n.kind || 'unspecified — read the template from GET /api/templates'}${n.command ? ' / ' + n.command : ''}, config ${JSON.stringify(n.config || {})}). Edit the .flo, then run \`aware app compile\`.`;
6756
6761
  }
6757
6762
  if (req.type === 'tweak') {
6758
6763
  const base = `In floless app "${req.appId}", change only node "${req.nodeId}": ${req.instruction}. Edit just that node in the .flo, then run \`aware app compile\`.`;
@@ -6821,6 +6826,29 @@
6821
6826
  }
6822
6827
  return `In floless project "${req.project}" (app "${req.appId}"), a REVISED drawing set was attached — re-read it into the SAME project as a new version (do NOT create a new project). Follow the floless-app-steel-takeoff skill's mandatory two-phase gate. FIRST, GET /api/contract/${req.appId}?project=${req.project} to read the CURRENT contract, then do the deterministic PyMuPDF steel-filter pass only for the revised drawing set: identify the framing-plan sheets, enumerate drawing elements by layer/thickness/color into contract.filter.sheets/facets, preserve any compatible existing filter selections, send ONLY the pre-read blocks to PUT /api/projects/${req.project}/steel-prepass with { filter } and If-Match: <the ETag from the GET you just did> — never the whole contract, because this project already holds a model and a full PUT would replace its members without review. The verb takes filter, datum and per-sheet { grid, datum_at, datum_ref, control2_at, control2_ref, elevation_in } and refuses everything else by name. A write with no precondition is refused with 428, and If-Match must be the exact ETag — If-Match: * is refused, because this verb patches the document you read. On 412 re-GET, re-apply, and retry rather than repeating the same body. Then STOP and tell me to open Drawings → Steel Filter, review/narrow the steel facets, and Save. Do NOT read members, build the model, open 3D, or POST /revision-read until I explicitly come back after saving the filter. AFTER that saved-filter checkpoint, read members from the saved filter selection, compose the updated steel.takeoff/v1 contract, and PRESERVE each still-present member's id AND its sheet label (mint a NEW id only for a genuinely new member; drop the id of a member the revision deleted) so the version comparison matches members — do NOT renumber the whole model. ${post}${snaps}${note}`;
6823
6828
  }
6829
+ // The steel-model editor's "Ask AI" box, and the SAME channel its "insert a detail" flow uses.
6830
+ // Deliberately does NOT name a contract shape: this channel serves both steel.takeoff/v1 and
6831
+ // steel.model/v2 projects, and the stored document's own `type` is the authoritative answer the
6832
+ // AI reads in the GET below. Naming a shape here would send a v2 project's edit at a v1 take-off
6833
+ // — the same failure `contractType` exists to prevent on revision-read, solved one rung cheaper
6834
+ // because this verb re-writes the document it just read rather than composing a new one.
6835
+ if (req.type === 'tweak-contract') {
6836
+ const where = req.project ? `?project=${req.project}` : '';
6837
+ const scope = req.project ? `floless project "${req.project}" (app "${req.appId}")` : `floless app "${req.appId}"`;
6838
+ // The insert flow carries a machine-readable intent + target so the AI creates a new detail
6839
+ // rather than editing a placed one (or vice versa) — absent on an ordinary Ask AI request.
6840
+ const detail = req.intent
6841
+ ? `\nThis is an insert-a-detail request: intent "${req.intent}"${req.target && req.target.sheet ? ` on sheet "${req.target.sheet}"` : ''}${req.target && req.target.ids && req.target.ids.length ? `, target id(s) ${req.target.ids.join(', ')}` : ''}.`
6842
+ : '';
6843
+ const snaps = req.snapshots && req.snapshots.length
6844
+ ? `\nScreenshot${req.snapshots.length > 1 ? 's' : ''} (read these — they show which member or region "this" means): ${req.snapshots.join(', ')}`
6845
+ : '';
6846
+ return `In ${scope}, edit the steel contract per the floless-app-tweak-contract skill: ${req.instruction || 'apply the requested change'}. ` +
6847
+ `GET /api/contract/${req.appId}${where} first and KEEP its ETag — the document's own \`type\` tells you which shape you are editing, and you write back that SAME shape. ` +
6848
+ `Apply the change, preserving every field you are not changing, then PUT the full document to /api/contract/${req.appId}${where} with If-Match: <that ETag> ` +
6849
+ `(If-None-Match: * only when the GET returned no ETag at all). A blind write is refused with 428; on 412 re-GET, re-apply your edit to the NEW document, and retry rather than repeating the same body. ` +
6850
+ `Writing a tweak is not approval — leave the approval gate to the user.${detail}${snaps}`;
6851
+ }
6824
6852
  // The Knowledge step's Organize verb. The lifecycle is SERVER-owned: start claims the organize
6825
6853
  // lock and mints the generation dir; finish publishes it and clears this request; fail releases
6826
6854
  // the lock. Naming the exact project-scoped routes matters — /api/requests/<id> is NOT the
@@ -6840,7 +6868,19 @@
6840
6868
  return `In floless project "${req.project}", reshape the Project Knowledge Base with your floless-app-knowledge skill: ${req.instruction || 'apply the requested change'}. ` +
6841
6869
  `Edit the project's wiki notes accordingly, then re-organize so the published generation reflects the change.`;
6842
6870
  }
6843
- return '';
6871
+ // No branch matched. Fall back to what the USER typed rather than to nothing.
6872
+ //
6873
+ // Every type in the union has an arm today — 'tweak-contract' was the last one missing and #629
6874
+ // gave it one. This is the floor for the NEXT type added to FlolessRequest before its arm lands,
6875
+ // because of what that gap cost last time: a blank row in the Requests window AND a
6876
+ // markedInstruction() of '', so the ⧉ silently put nothing on the clipboard while still toasting
6877
+ // success. The request was never empty — it carried a real instruction — it was just unreadable
6878
+ // and uncopyable, which reads as noise worth deleting.
6879
+ //
6880
+ // A composed arm is strictly better (it tells the terminal AI the protocol, not just the wish),
6881
+ // so this never competes with one: every arm above returns first. A type that legitimately
6882
+ // carries no instruction still lands on '' here, and the row says so in words.
6883
+ return req.instruction ? String(req.instruction).trim() : '';
6844
6884
  }
6845
6885
 
6846
6886
  // Which product skill applies each request type (named in the copied marker so the
@@ -6849,6 +6889,7 @@
6849
6889
  'use-template': 'floless-app-workflows',
6850
6890
  tweak: 'floless-app-workflows',
6851
6891
  'ui-customize': 'floless-app-ui',
6892
+ 'tweak-contract': 'floless-app-tweak-contract',
6852
6893
  rebake: 'floless-app-rebake',
6853
6894
  'revision-read': 'floless-app-steel-takeoff',
6854
6895
  // The guided-tour ask is picked up by onboarding; the instruction body names the
@@ -6893,9 +6934,36 @@
6893
6934
  }
6894
6935
 
6895
6936
  async function copyToClipboard(text) {
6937
+ // Nothing in this app ever legitimately copies an empty string — every caller passes a command
6938
+ // or an instruction body. An empty one means the caller has a hole (a request type with no
6939
+ // instructionFor() arm returns '' from markedInstruction), and writing it would still resolve,
6940
+ // so the user gets a green "Copied" over an empty clipboard. Report the failure instead.
6941
+ if (!text) return false;
6896
6942
  try { await navigator.clipboard.writeText(text); return true; } catch { return false; }
6897
6943
  }
6898
6944
 
6945
+ // Copy ONE request, distinguishing the two ways it can fail. `copyToClipboard`'s boolean cannot:
6946
+ // "the clipboard API refused" is worth retrying and is usually a permission, while "this type has
6947
+ // no instruction body" will never copy no matter how often it is clicked and needs a developer.
6948
+ // Reporting the second as the first sends the user to debug the wrong thing — and on the
6949
+ // request-help modal it leaves a Copy button offering a retry that cannot succeed.
6950
+ //
6951
+ // WHICH SURFACES MUST USE THIS: every one whose failure message BLAMES a cause — the row ⧉, the
6952
+ // request-help modal, the revision card. The queue-then-best-effort-copy callers (useTemplate,
6953
+ // tweakNode, requestGuide, requestNewWorkflow, panels.js's customize box) say only "queued, not
6954
+ // copied" and name no cause, so they cannot conflate anything and are deliberately left alone. Add
6955
+ // a new surface that names a cause and it belongs here.
6956
+ async function copyRequest(req) {
6957
+ const line = req ? markedInstruction(req) : '';
6958
+ if (!line) return 'empty';
6959
+ return (await copyToClipboard(line)) ? 'ok' : 'denied';
6960
+ }
6961
+ // Total by construction: a lookup miss here would spread `undefined` into showToast and throw inside
6962
+ // an async onclick — silence, which is worse than the wrong message this exists to replace.
6963
+ const copyFailToast = (res) => (res === 'empty'
6964
+ ? ['Nothing to copy — this request has no instruction', 'err']
6965
+ : ['copy failed', 'err']);
6966
+
6899
6967
  let requestHelpReq = null;
6900
6968
  let requestHelpReturnFocus = null;
6901
6969
  function closeRequestHelp({ restoreFocus = true } = {}) {
@@ -6977,6 +7045,12 @@
6977
7045
  }
6978
7046
 
6979
7047
  let pendingRequests = [];
7048
+ // The Workspaces project the Requests window scopes to, pushed by workspaces.js's applyMode()
7049
+ // (null in Workflows mode, or on the Workspaces landing). Non-null ⇒ Workspaces with a project
7050
+ // open, which is why activeRequestScope() can pick between the two modes from this alone.
7051
+ let wsRequestScope = null;
7052
+ let requestScopeAll = false; // the scope tab: false = what's open, true = every queued request
7053
+ let requestQuery = '';
6980
7054
  let previousRequestCount = 0;
6981
7055
  let previousRequestIds = null;
6982
7056
  let reqPulseTimer = null;
@@ -7007,6 +7081,161 @@
7007
7081
  } catch { /* non-fatal */ }
7008
7082
  }
7009
7083
 
7084
+ // What the Requests window is scoped to right now: the open Workspaces project, else the open
7085
+ // workflow, else nothing (the Workspaces landing / no workflow selected → no filter is offered).
7086
+ function activeRequestScope() {
7087
+ // A Workspaces scope answers for itself, INCLUDING when it says "nothing" ({kind:'none'} —
7088
+ // the landing). Falling through to currentId there would scope the window to a workflow while
7089
+ // the user is looking at project cards: the workflow combo isn't even visible in Workspaces
7090
+ // mode, so the filter would name a surface they can't see. Same inverse-scope trap
7091
+ // workspaces.js's applyMode() documents for the tab title.
7092
+ if (wsRequestScope) return wsRequestScope.kind === 'project' ? wsRequestScope : null;
7093
+ return currentId ? { kind: 'workflow', appId: currentId, label: currentId } : null;
7094
+ }
7095
+
7096
+ /**
7097
+ * Does this queued request belong to what the user has open? (Pure — unit-tested.)
7098
+ *
7099
+ * Three cases, and the middle one is the whole point of the filter:
7100
+ * - A request with NEITHER appId nor project ('ui-customize', 'new-workflow') belongs to no
7101
+ * scope at all, so it is always shown. Hiding it would strand it: it can never match any
7102
+ * scope, and a "New workflow…" you just queued vanishing while the footer counter ticks up
7103
+ * is worse than one extra row.
7104
+ * - A PROJECT scope matches on project id only. A Workspaces tweak-contract carries both a
7105
+ * project and its app, so matching on appId would pull in every OTHER project sharing that
7106
+ * app — six 'steel-model' projects here all bleed into each other.
7107
+ * - A WORKFLOW scope requires `!r.project` for the same reason in reverse: the workflow
7108
+ * `steel-model` is not the Workspaces projects built on it.
7109
+ */
7110
+ function requestInScope(r, scope) {
7111
+ if (!scope) return true;
7112
+ if (!r) return false;
7113
+ if (!r.appId && !r.project) return true;
7114
+ if (scope.project) return r.project === scope.project;
7115
+ return !r.project && !!scope.appId && r.appId === scope.appId;
7116
+ }
7117
+
7118
+ /** Scope + free-text filter over the queue. `textOf` yields a request's searchable text. (Pure.) */
7119
+ function visibleRequests(list, scope, query, textOf) {
7120
+ const q = String(query || '').trim().toLowerCase();
7121
+ return (list || []).filter((r) => requestInScope(r, scope)
7122
+ && (!q || String(textOf(r) || '').toLowerCase().includes(q)));
7123
+ }
7124
+
7125
+ /**
7126
+ * WHAT a request belongs to, in the words the user knows it by: the project's name in
7127
+ * Workspaces, the workflow's id in Workflows. (Pure — unit-tested.)
7128
+ *
7129
+ * The project name comes from the server (`projectName` on the request view), because the
7130
+ * request itself only carries the project ID and the id is neither the name nor stable against
7131
+ * a rename. Falls back to the id when the server could resolve no name — a stale id is honest,
7132
+ * an invented name is not. That fallback is reached most often after a RENAME (which mints a new
7133
+ * project id and leaves the queued request on the old one), not a delete; see the note on
7134
+ * requestProjectName in server/index.ts for what the user sees when it happens.
7135
+ *
7136
+ * A project-keyed request must NEVER fall through to appId: every steel-model project carries
7137
+ * `appId: "steel-model"`, so the old head line printed the same word against three unrelated
7138
+ * projects' work. Requests that belong to neither (ui-customize, new-workflow) get a plain-English
7139
+ * stand-in rather than a blank — the row still has to say what it is about.
7140
+ */
7141
+ function requestOwnerName(r) {
7142
+ if (!r) return '';
7143
+ if (r.project) return r.projectName || r.project;
7144
+ if (r.appId) return r.appId;
7145
+ return r.type === 'ui-customize' ? 'your dashboard' : r.type === 'new-workflow' ? 'a new workflow' : '';
7146
+ }
7147
+
7148
+ // Everything a search should match: the project/workflow the request belongs to, its badge
7149
+ // label, and the instruction the terminal AI would receive.
7150
+ //
7151
+ // `r.instruction` — what the USER actually typed — is searched alongside the composed
7152
+ // instruction, not instead of it. The two usually overlap, but the composed body is only as
7153
+ // complete as instructionFor()'s arms, and a request you can see but cannot find by the words
7154
+ // you wrote in it is the worst kind of search. Same forward-looking floor as the fallback at the
7155
+ // end of instructionFor(): keep this field even though every type has an arm today.
7156
+ //
7157
+ // Both the NAME and the raw ids are searchable: you may know a project as "Cedar Mill Warehouse"
7158
+ // or as the `take-5-6677ee` in its URL, and either should find it.
7159
+ function requestSearchText(r) {
7160
+ return [requestLabel(r), requestOwnerName(r), r.appId, r.project, r.nodeId, r.inputName, r.instruction, instructionFor(r)]
7161
+ .filter(Boolean).join(' ');
7162
+ }
7163
+
7164
+ function requestLabel(r) {
7165
+ return r.type === 'use-template' ? 'template' : r.type === 'ui-customize' ? 'dashboard' : r.type === 'rebake' ? 're-bake' : r.type === 'revision-read' ? 'revision' : r.type === 'guide' ? 'guide' : r.type === 'new-workflow' ? 'new workflow' : r.type === 'knowledge-organize' ? 'organize' : r.type === 'knowledge-adjust' ? 'adjust' : r.type === 'tweak-contract' ? 'contract' : 'tweak';
7166
+ }
7167
+
7168
+ // Escape `text`, wrapping every case-insensitive occurrence of `q` in <mark>. Splits the RAW
7169
+ // string and escapes each piece, so the match offsets stay valid (escaping first would shift
7170
+ // them) and no user text can escape into markup.
7171
+ //
7172
+ // Matches with a case-insensitive RegExp rather than indexOf over a lowercased copy, because
7173
+ // case folding is not length-preserving: 'İ'.toLowerCase() is TWO code units, so every offset
7174
+ // past one would slice the original at the wrong place and garble the text it rendered. The
7175
+ // needle is regex-escaped — a user typing `.` or `(` into the search box is a literal, not a
7176
+ // pattern.
7177
+ function highlightQuery(text, q) {
7178
+ const s = String(text == null ? '' : text);
7179
+ const needle = String(q || '').trim();
7180
+ if (!needle) return escapeHtml(s);
7181
+ const re = new RegExp(needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
7182
+ let out = '';
7183
+ let i = 0;
7184
+ for (let m = re.exec(s); m; m = re.exec(s)) {
7185
+ out += `${escapeHtml(s.slice(i, m.index))}<mark>${escapeHtml(m[0])}</mark>`;
7186
+ i = m.index + m[0].length;
7187
+ if (m[0].length === 0) re.lastIndex++; // defensive: an empty match would never advance
7188
+ }
7189
+ return out + escapeHtml(s.slice(i));
7190
+ }
7191
+
7192
+ // The set the window is currently showing — the ONE definition of "these requests", so the
7193
+ // rows and the counts on the scope tabs can never disagree.
7194
+ function shownRequests() {
7195
+ return visibleRequests(pendingRequests, requestScopeAll ? null : activeRequestScope(), requestQuery, requestSearchText);
7196
+ }
7197
+
7198
+ // Exactly what the OPEN window last painted. The bulk actions read THIS, never shownRequests().
7199
+ //
7200
+ // Re-deriving the scope at click time reads module state that changes with no repaint: `loadApps()`
7201
+ // reassigns `currentId` (it falls back to list[0] when the remembered app is gone) and it runs from
7202
+ // the `apps-changed` SSE — so the terminal AI reinstalling a workflow, or another tab deleting one,
7203
+ // silently moves the scope under an open modal. "Clear all" would then delete a set the user was
7204
+ // never shown while the rows and the tab label still named the old one. Before this window could be
7205
+ // scoped, both handlers read `pendingRequests` — the rendered array itself — so a stale `currentId`
7206
+ // was inert; scoping is what promoted it to an input of what a click DELETES.
7207
+ let shownSnapshot = [];
7208
+
7209
+ // The snapshot, re-resolved against the live queue: anything cleared elsewhere since the paint is
7210
+ // dropped rather than re-DELETEd into a 404.
7211
+ function paintedRequests() {
7212
+ const live = new Map(pendingRequests.map((r) => [r.id, r]));
7213
+ return shownSnapshot.map((r) => live.get(r.id)).filter(Boolean);
7214
+ }
7215
+
7216
+ /** Is the window currently narrowing the queue at all? (Pure — unit-tested.) */
7217
+ function requestFilterActive(scopeAll, scope, query) {
7218
+ return (!scopeAll && !!scope) || !!String(query || '').trim();
7219
+ }
7220
+
7221
+ /**
7222
+ * What a bulk clear should actually do. (Pure — unit-tested, because this is the decision that
7223
+ * DELETES.)
7224
+ *
7225
+ * `atomic` fires `DELETE /api/requests`, which wipes the server's whole requests dir — so it is
7226
+ * gated on "no filter is active", NOT on "the counts happened to coincide". A count test is true
7227
+ * for any single-project user whose scope covers the cached queue, which would hand a filtered
7228
+ * clear the delete-everything verb and take out both the requests hidden behind the filter and any
7229
+ * knowledge-organize queued since the paint (404-ing its finish/fail and stranding its lock). The
7230
+ * length check is kept as a second, independent condition, so a stale snapshot also falls to the
7231
+ * per-id loop rather than the atomic verb.
7232
+ */
7233
+ function bulkClearPlan(painted, all, filterActive) {
7234
+ const keep = painted.filter((r) => r && r.type === 'knowledge-organize');
7235
+ const drop = painted.filter((r) => r && r.type !== 'knowledge-organize');
7236
+ return { atomic: !filterActive && !keep.length && painted.length === all.length, keep, drop };
7237
+ }
7238
+
7010
7239
  // The Requests window: every queued change in a list, each copyable + clearable,
7011
7240
  // plus copy-all / clear-all. instructionFor() output (which embeds file-derived
7012
7241
  // appId/nodeId/instruction) is rendered via textContent-equivalent escaping.
@@ -7014,24 +7243,77 @@
7014
7243
  const $list = document.getElementById('requests-list');
7015
7244
  const $clear = document.getElementById('requests-clear');
7016
7245
  const $copy = document.getElementById('requests-copy');
7246
+ const $search = document.getElementById('requests-search');
7017
7247
  if (!$list) return;
7018
- const empty = pendingRequests.length === 0;
7248
+ // Search is pointless over an empty queue, and over a single request it is just clutter.
7249
+ // Drop the query WITH the box, and before anything is filtered by it: a hidden filter still
7250
+ // filtering is how a list ends up inexplicably empty (the last two requests clear while a
7251
+ // stale query is still narrowing).
7252
+ if ($search) {
7253
+ $search.hidden = pendingRequests.length < 2;
7254
+ if ($search.hidden && requestQuery) { requestQuery = ''; $search.value = ''; }
7255
+ }
7256
+ const scope = activeRequestScope();
7257
+ const inScope = visibleRequests(pendingRequests, scope, '', requestSearchText);
7258
+ const shown = shownRequests();
7259
+ shownSnapshot = shown; // the bulk actions act on THIS paint — see the note on shownSnapshot
7260
+ const nothingQueued = pendingRequests.length === 0;
7261
+
7262
+ // The scope tabs only earn their space when there is something to scope TO and something
7263
+ // queued to scope. Counts live ON the tabs so requests hidden by the filter are never a
7264
+ // silent omission — "All · 7" beside "Cedar Mill Warehouse · 2" says where the rest went.
7265
+ const $scope = document.getElementById('requests-scope');
7266
+ const $here = document.getElementById('requests-scope-here');
7267
+ const $all = document.getElementById('requests-scope-all');
7268
+ if ($scope) $scope.hidden = !scope || nothingQueued;
7269
+ if (scope && $here && $all) {
7270
+ const kind = scope.kind === 'project' ? 'project' : 'workflow';
7271
+ // The label is the REAL name, so you can see WHICH project you're scoped to — it can
7272
+ // ellipsize, which is why the tip repeats it in full rather than describing it generically.
7273
+ $here.innerHTML = `<span class="req-scope-name">${escapeHtml(scope.label)}</span><span class="req-scope-n">· ${inScope.length}</span>`;
7274
+ $here.setAttribute('data-tip', `Only what's queued for the ${kind} you have open — ${scope.label}`);
7275
+ $all.innerHTML = `<span class="req-scope-name">All requests</span><span class="req-scope-n">· ${pendingRequests.length}</span>`;
7276
+ $all.setAttribute('data-tip', 'Every queued request, including other projects and workflows');
7277
+ $here.classList.toggle('active', !requestScopeAll);
7278
+ $here.setAttribute('aria-selected', String(!requestScopeAll));
7279
+ $all.classList.toggle('active', requestScopeAll);
7280
+ $all.setAttribute('aria-selected', String(requestScopeAll));
7281
+ }
7282
+
7019
7283
  // Hide (not just disable) the bulk actions when there's nothing to act on — a
7020
- // disabled "Clear all"/"Copy all" over an empty list reads as broken UI.
7021
- if ($clear) $clear.hidden = empty;
7022
- if ($copy) $copy.hidden = empty;
7023
- if (empty) {
7024
- $list.innerHTML = '<div class="empty-state">No requests queued. Save a Template or ✎ Tweak a node to send a change to your terminal AI.</div>';
7284
+ // disabled "Clear all"/"Copy all" over an empty list reads as broken UI. They act on
7285
+ // what's SHOWN, so their tooltips say so rather than letting "all" quietly mean "some".
7286
+ const bulkTip = (verb) => (shown.length === pendingRequests.length
7287
+ ? `${verb} all ${pendingRequests.length} queued request${pendingRequests.length === 1 ? '' : 's'}`
7288
+ : `${verb} the ${shown.length} request${shown.length === 1 ? '' : 's'} shown here`);
7289
+ if ($clear) { $clear.hidden = shown.length === 0; $clear.setAttribute('data-tip', bulkTip('Clear')); }
7290
+ if ($copy) { $copy.hidden = shown.length === 0; $copy.setAttribute('data-tip', bulkTip('Copy')); }
7291
+
7292
+ if (shown.length === 0) {
7293
+ // Three different nothings, and conflating them is what makes a filter feel broken: an
7294
+ // empty queue, a queue with nothing for THIS project, and a search that missed.
7295
+ const msg = nothingQueued
7296
+ ? 'No requests queued. Save a Template or ✎ Tweak a node to send a change to your terminal AI.'
7297
+ : requestQuery.trim()
7298
+ ? `No request matches “${escapeHtml(requestQuery.trim())}”.${!requestScopeAll && inScope.length < pendingRequests.length ? ' Try All to search every queued request.' : ''}`
7299
+ : `Nothing queued for ${escapeHtml(scope ? scope.label : 'this')} — ${pendingRequests.length} request${pendingRequests.length === 1 ? '' : 's'} waiting elsewhere. <button type="button" class="req-showall">Show all</button>`;
7300
+ $list.innerHTML = `<div class="empty-state">${msg}</div>`;
7301
+ const $showAll = $list.querySelector('.req-showall');
7302
+ if ($showAll) $showAll.onclick = () => setRequestScopeAll(true);
7025
7303
  return;
7026
7304
  }
7027
- $list.innerHTML = pendingRequests.map((r) => {
7028
- const label = r.type === 'use-template' ? 'template' : r.type === 'ui-customize' ? 'dashboard' : r.type === 'rebake' ? 're-bake' : r.type === 'revision-read' ? 'revision' : r.type === 'guide' ? 'guide' : r.type === 'new-workflow' ? 'new workflow' : r.type === 'knowledge-organize' ? 'organize' : r.type === 'knowledge-adjust' ? 'adjust' : 'tweak';
7029
- const badgeCls = r.type === 'tweak' || r.type === 'ui-customize' || r.type === 'rebake' || r.type === 'revision-read' || r.type === 'knowledge-organize' || r.type === 'knowledge-adjust' ? 'req-type req-type-tweak' : 'req-type';
7030
- const target = r.type === 'tweak' && r.nodeId
7031
- ? ` · node <code>${escapeHtml(r.nodeId)}</code>`
7032
- : r.type === 'rebake' && r.inputName
7033
- ? ` · input <code>${escapeHtml(r.inputName)}</code>`
7034
- : '';
7305
+ $list.innerHTML = shown.map((r) => {
7306
+ const label = requestLabel(r);
7307
+ const badgeCls = r.type === 'tweak' || r.type === 'ui-customize' || r.type === 'rebake' || r.type === 'revision-read' || r.type === 'knowledge-organize' || r.type === 'knowledge-adjust' || r.type === 'tweak-contract' ? 'req-type req-type-tweak' : 'req-type';
7308
+ // One name, and only the name. The node/input/sheet chips that used to sit here ("· node
7309
+ // render") are already spelled out in the instruction body right below, so they cost a line
7310
+ // of chrome to repeat what the sentence underneath says in English.
7311
+ //
7312
+ // The sheet chip (#629) was justified by .req-instruction's 3-line clamp: it existed because
7313
+ // an Ask AI note's trailing intent sentence got CLIPPED. This change replaces that clamp with
7314
+ // a scroller, so the whole body — intent sentence included — is readable in place and the
7315
+ // chip has nothing left to rescue.
7316
+ const owner = requestOwnerName(r);
7035
7317
  const when = r.createdAt ? new Date(r.createdAt) : null;
7036
7318
  const time = when && !isNaN(when) ? `<span class="req-time">${escapeHtml(nowStamp(when))}</span>` : '';
7037
7319
  // A knowledge-organize is resolved by its own finish/fail lifecycle POST. Offering a ✕ here
@@ -7044,8 +7326,8 @@
7044
7326
  return `
7045
7327
  <div class="req-item">
7046
7328
  <div class="req-info">
7047
- <div class="req-head"><span class="${badgeCls}">${label}</span> ${r.appId ? `<code>${escapeHtml(r.appId)}</code>` : ''}${target}${time}</div>
7048
- <div class="req-instruction">${escapeHtml(instructionFor(r))}</div>
7329
+ <div class="req-head"><span class="${badgeCls}">${label}</span> ${owner ? `<span class="req-owner">${highlightQuery(owner, requestQuery)}</span>` : ''}${time}</div>
7330
+ <div class="req-instruction">${highlightQuery(instructionFor(r), requestQuery) || 'This request has no instruction, so it can’t be handed to your terminal AI. Clear it and queue it again.'}</div>
7049
7331
  ${r.snapshots && r.snapshots.length ? `<div class="req-thumbs">${r.snapshots.map((sp, i) => { const pdf = /\.pdf$/i.test(String(sp)); return `<button type="button" class="req-thumb" data-id="${escapeAttr(r.id)}" data-n="${i}" aria-label="View ${pdf ? 'PDF' : 'screenshot'} ${i + 1}">${pdf ? '<span class="req-thumb-pdf">PDF</span>' : `<img src="/api/requests/${encodeURIComponent(r.id)}/snapshot/${i}" alt="">`}</button>`; }).join('')}</div>` : ''}
7050
7332
  </div>
7051
7333
  <div class="req-actions">
@@ -7058,8 +7340,9 @@
7058
7340
  b.onclick = async () => {
7059
7341
  const r = pendingRequests.find((x) => x.id === b.dataset.id);
7060
7342
  if (!r) return;
7061
- const copied = await copyToClipboard(markedInstruction(r));
7062
- showToast(copied ? 'Copied — paste it to your terminal AI' : 'copy failed', copied ? 'ok' : 'err');
7343
+ const res = await copyRequest(r);
7344
+ if (res === 'ok') showToast('Copied — paste it to your terminal AI', 'ok');
7345
+ else showToast(...copyFailToast(res));
7063
7346
  };
7064
7347
  });
7065
7348
  $list.querySelectorAll('.req-del').forEach((b) => { b.onclick = () => deleteOneRequest(b.dataset.id); });
@@ -7075,29 +7358,47 @@
7075
7358
  // Clear-all must never take out a knowledge-organize: the bulk DELETE would 404 its finish/fail and
7076
7359
  // strand the organize lock until the stale timeout. The request list can't tell "queued" from
7077
7360
  // "already started", so ALL organizes are kept — they clear themselves via their lifecycle.
7361
+ //
7362
+ // It acts on the PAINTED requests, never the whole queue and never a freshly re-derived scope.
7363
+ // Once the window can be scoped to one project, a "Clear all" that reached past the filter would
7364
+ // delete other projects' queued work the user cannot even see.
7078
7365
  async function clearAllRequests() {
7079
- if (!pendingRequests.length) return;
7080
- const keep = pendingRequests.filter((r) => r && r.type === 'knowledge-organize');
7366
+ const painted = paintedRequests();
7367
+ if (!painted.length) return;
7368
+ const filterActive = requestFilterActive(requestScopeAll, activeRequestScope(), requestQuery);
7369
+ const { atomic, keep, drop } = bulkClearPlan(painted, pendingRequests, filterActive);
7081
7370
  try {
7082
- if (!keep.length) {
7083
- await api('/api/requests', { method: 'DELETE' }); // nothing lifecycle-owned — the atomic bulk clear is fine
7371
+ if (atomic) {
7372
+ await api('/api/requests', { method: 'DELETE' }); // no filter, nothing lifecycle-owned — the atomic bulk clear is fine
7084
7373
  } else {
7085
- const drop = pendingRequests.filter((r) => r && r.type !== 'knowledge-organize');
7086
7374
  for (const r of drop) await api(`/api/requests/${encodeURIComponent(r.id)}`, { method: 'DELETE' });
7087
7375
  }
7088
7376
  await loadRequests();
7089
7377
  renderRequests();
7090
7378
  showToast(
7091
7379
  keep.length
7092
- ? `Cleared the other requests — kept ${keep.length} in-progress organize${keep.length === 1 ? '' : 's'}`
7093
- : 'Cleared all requests',
7380
+ ? `Cleared ${drop.length} request${drop.length === 1 ? '' : 's'} — kept ${keep.length} in-progress organize${keep.length === 1 ? '' : 's'}`
7381
+ : atomic
7382
+ ? 'Cleared all requests'
7383
+ : `Cleared ${drop.length} request${drop.length === 1 ? '' : 's'} shown here`,
7094
7384
  'ok',
7095
7385
  );
7096
7386
  } catch (e) { reportErr(e); }
7097
7387
  }
7388
+ // Switch the scope tab (or the empty state's "Show all") and repaint.
7389
+ function setRequestScopeAll(all) {
7390
+ requestScopeAll = !!all;
7391
+ renderRequests();
7392
+ }
7098
7393
  // Re-fetch before showing: there is no server `request-added` broadcast, so a request queued in
7099
7394
  // another tab (or by the Knowledge step) would otherwise render from a stale cache.
7100
7395
  async function openRequests() {
7396
+ // Open on the scope + a clear search every time. A stuck "All" (or a leftover query) from a
7397
+ // previous visit would silently answer a different question than the one just asked.
7398
+ requestScopeAll = false;
7399
+ requestQuery = '';
7400
+ const $search = document.getElementById('requests-search');
7401
+ if ($search) $search.value = '';
7101
7402
  document.getElementById('requests-modal').classList.add('show');
7102
7403
  renderRequests(); // paint the cache immediately — no empty flash
7103
7404
  await loadRequests();
@@ -8547,11 +8848,31 @@
8547
8848
  if ($reqClear) $reqClear.onclick = () => clearAllRequests();
8548
8849
  const $reqCopy = document.getElementById('requests-copy');
8549
8850
  if ($reqCopy) $reqCopy.onclick = async () => {
8550
- if (!pendingRequests.length) return;
8551
- const text = pendingRequests.map(markedInstruction).filter(Boolean).join('\n\n');
8552
- const copied = await copyToClipboard(text);
8553
- showToast(copied ? `Copied ${pendingRequests.length} request(s) — paste to your terminal AI` : 'copy failed', copied ? 'ok' : 'err');
8851
+ const shown = paintedRequests(); // what was PAINTED, not a re-derived scope — see shownSnapshot
8852
+ if (!shown.length) return;
8853
+ // Count what actually made it, not what was in the list. `.filter(Boolean)` silently drops a
8854
+ // request with no instruction body, and reporting the list length over that is the
8855
+ // original bug wearing a bulk hat: the user pastes, the AI applies the ones that copied, and the
8856
+ // dropped request never reaches the terminal while the toast said it did.
8857
+ const lines = shown.map(markedInstruction).filter(Boolean);
8858
+ const dropped = shown.length - lines.length;
8859
+ if (!lines.length) { showToast('Nothing to copy — none of these requests has an instruction', 'err'); return; }
8860
+ const copied = await copyToClipboard(lines.join('\n\n'));
8861
+ if (!copied) { showToast('copy failed', 'err'); return; }
8862
+ showToast(
8863
+ dropped
8864
+ ? `Copied ${lines.length} of ${shown.length} — ${dropped} had no instruction and ${dropped === 1 ? 'was' : 'were'} skipped`
8865
+ : `Copied ${lines.length} request(s) — paste to your terminal AI`,
8866
+ dropped ? 'warn' : 'ok',
8867
+ );
8554
8868
  };
8869
+ const $reqScope = document.getElementById('requests-scope');
8870
+ if ($reqScope) $reqScope.onclick = (e) => {
8871
+ const b = e.target.closest('button[data-reqscope]');
8872
+ if (b) setRequestScopeAll(b.dataset.reqscope === 'all');
8873
+ };
8874
+ const $reqSearch = document.getElementById('requests-search');
8875
+ if ($reqSearch) $reqSearch.oninput = () => { requestQuery = $reqSearch.value; renderRequests(); };
8555
8876
  const $requestHelpModal = document.getElementById('request-help-modal');
8556
8877
  const $requestHelpOpen = document.getElementById('request-help-open');
8557
8878
  const $requestHelpKeep = document.getElementById('request-help-keep');
@@ -8563,8 +8884,15 @@
8563
8884
  if ($requestHelpKeep) $requestHelpKeep.onclick = () => closeRequestHelp();
8564
8885
  if ($requestHelpCopy) $requestHelpCopy.onclick = async () => {
8565
8886
  if (!requestHelpReq) return;
8566
- const copied = await copyToClipboard(markedInstruction(requestHelpReq));
8567
- showToast(copied ? 'Copied — paste it to your terminal AI' : 'copy failed', copied ? 'ok' : 'err');
8887
+ // Via copyRequest, so an instruction-less type says so rather than "copy failed".
8888
+ const res = await copyRequest(requestHelpReq);
8889
+ const copied = res === 'ok';
8890
+ if (copied) showToast('Copied — paste it to your terminal AI', 'ok');
8891
+ else showToast(...copyFailToast(res));
8892
+ // 'denied' keeps the button — a clipboard permission is worth retrying. 'empty' hides it exactly
8893
+ // as success does: there is no instruction body, so no number of clicks will ever produce one, and
8894
+ // leaving Copy there offers a retry that cannot succeed.
8895
+ if (res === 'empty') $requestHelpCopy.hidden = true;
8568
8896
  if (copied) {
8569
8897
  $requestHelpCopy.hidden = true;
8570
8898
  const $sub = document.getElementById('request-help-sub');
@@ -8761,12 +9089,30 @@
8761
9089
  },
8762
9090
  // Refresh the footer requests counter after the Customize box queues a request.
8763
9091
  loadRequests,
9092
+ // Which project the Requests window filters to. workspaces.js owns the open project;
9093
+ // aware.js owns the window. Called from applyMode() — the single funnel every path that
9094
+ // changes the open project (open, close, rename, mode switch, boot) already ends at.
9095
+ //
9096
+ // THREE states, not two, and collapsing the last two is a bug: an open project scopes to it;
9097
+ // the Workspaces LANDING has no scope and must not borrow the open workflow's; Workflows mode
9098
+ // passes null and lets aware.js scope to the open workflow. Pass `{}` (or anything without a
9099
+ // project) for the landing, `null` for Workflows mode.
9100
+ //
9101
+ // Repaints an already-open window so switching underneath it can't leave a stale scope on screen.
9102
+ setRequestScope(scope) {
9103
+ wsRequestScope = scope
9104
+ ? (scope.project ? { kind: 'project', ...scope } : { kind: 'none' })
9105
+ : null;
9106
+ const $rm = document.getElementById('requests-modal');
9107
+ if ($rm && $rm.classList.contains('show')) renderRequests();
9108
+ },
8764
9109
  refreshCurrentWorkflow() {
8765
9110
  return refreshCurrentWorkflowAvailability();
8766
9111
  },
8767
9112
  copyToClipboard,
8768
9113
  instructionFor,
8769
9114
  markedInstruction, // marked (paste-safe) form for clipboard copies — panels.js uses it (#73)
9115
+ copyRequest, // copy ONE request, telling "no instruction body" apart from "clipboard refused"
8770
9116
  showRequestQueuedModal,
8771
9117
  formModal, // the shared styled prompt/form modal — workspaces.js reuses it (never a native prompt)
8772
9118
  // One owner for runtime upgrades. Workspaces may open this surface but must
@@ -33,12 +33,16 @@
33
33
  </span>
34
34
  <span class="name">FloLess</span>
35
35
  </div>
36
- <!-- Top-level mode switch (Workflows = node canvas + Run; Workspaces = project/document
37
- apps, no Run). Segmented control, Ctrl+1/Ctrl+2. See docs/superpowers/specs/
38
- 2026-07-03-workspaces-two-mode-shell-design.md. -->
36
+ <!-- Top-level mode switch (Workspaces = project/document apps, no Run; Workflows = node
37
+ canvas + Run). Segmented control, Ctrl+1/Ctrl+2 — the shortcuts follow POSITION, so
38
+ they swap with the tabs (#623). See docs/superpowers/specs/
39
+ 2026-07-03-workspaces-two-mode-shell-design.md.
40
+ Workspaces leads because it is the primary entry point (#623); which mode the app
41
+ OPENS in is unchanged — that is the remembered `floless:mode`, defaulting to
42
+ Workflows. -->
39
43
  <div class="mode-switch" id="mode-switch" role="tablist" aria-label="Mode">
40
- <button type="button" data-mode="workflows" class="active" role="tab" aria-selected="true">Workflows</button>
41
44
  <button type="button" data-mode="workspaces" role="tab" aria-selected="false">Workspaces</button>
45
+ <button type="button" data-mode="workflows" class="active" role="tab" aria-selected="true">Workflows</button>
42
46
  </div>
43
47
  <!-- Workspace view switch (Canvas = the workflow topology; Dashboard = the user's
44
48
  custom panels from ~/.floless/ui/extensions.json) moved into the ≡ menu in #149.
@@ -741,6 +745,14 @@
741
745
  <div class="modal requests">
742
746
  <div class="modal-title">Requests for your terminal AI</div>
743
747
  <div class="modal-sub">The UI can’t edit workflows itself — these are the changes it queued for your terminal AI (Claude Code / Codex / OpenCode) to apply. Copy one to paste, or clear ones already handled.</div>
748
+ <!-- Scope + search. The scope row is hidden when nothing is open to scope TO (the
749
+ Workspaces landing, or Workflows with no workflow selected) — a filter with one
750
+ possible answer is noise. Labels/counts are written per-render in aware.js. -->
751
+ <div class="tabs req-scope" id="requests-scope" role="tablist" aria-label="Filter requests by what you have open" hidden>
752
+ <button type="button" data-reqscope="scoped" class="active" role="tab" aria-selected="true" id="requests-scope-here"></button>
753
+ <button type="button" data-reqscope="all" role="tab" aria-selected="false" id="requests-scope-all">All</button>
754
+ </div>
755
+ <input id="requests-search" class="lib-search req-search" type="text" placeholder="Search by project, workflow, or what you asked for" aria-label="Search requests">
744
756
  <div class="requests-list" id="requests-list"></div>
745
757
  <div class="modal-actions">
746
758
  <button id="requests-clear">Clear all</button>