@floless/app 0.85.0 → 0.86.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web/aware.js CHANGED
@@ -601,10 +601,10 @@
601
601
  // step = the first not-done row, so the arrow lands on the next real action.
602
602
  function workspaceGuideSteps(ctx) {
603
603
  return [
604
- { label: 'Drop a drawing', note: 'PDF or image — vectors come out editable', done: true },
605
- { label: 'Review the vectors', note: 'check layers, isolate low-confidence traces', done: !!ctx.approved },
604
+ { label: 'Drop a drawing', note: 'PDF or image — traced linework comes out editable', done: true },
605
+ { label: 'Review the traced lines', note: 'check layers, isolate low-confidence traces', done: !!ctx.approved },
606
606
  { label: 'Approve', note: 'signs off this version, unlocks Export', done: !!ctx.approved },
607
- { label: 'Export SVG', note: 'clean vectors, take them anywhere', done: !!ctx.exported },
607
+ { label: 'Export SVG', note: 'clean SVG linework, take it anywhere', done: !!ctx.exported },
608
608
  ];
609
609
  }
610
610
 
@@ -716,7 +716,7 @@
716
716
  if ($title) $title.textContent = ctx.name || ctx.displayName || ctx.app;
717
717
  if ($eyebrow) $eyebrow.textContent = wsBeaconIsNew(ctx.app) ? '✦ Start here' : '✦ Project guide';
718
718
  if ($sub) $sub.textContent = 'What this project does, and how to take it from drawing to export.';
719
- const descHtml = `<div class="guide-desc"><p>Drop in a drawing — a PDF, scan, or photo — and it comes back as clean, editable 2D vectors. Anything the trace wasn’t sure about gets flagged for you to check before you approve and export.</p></div>`;
719
+ const descHtml = `<div class="guide-desc"><p>Drop in a drawing — a PDF, scan, or photo — and it comes back as clean, editable traced linework. Anything the trace wasn’t sure about gets flagged for you to check before you approve and export.</p></div>`;
720
720
  const stepsHtml = guideStepsHtml(workspaceGuideSteps(ctx));
721
721
  $body.innerHTML =
722
722
  `<div class="guide-section-label">What this does</div>` + descHtml +
@@ -1364,13 +1364,18 @@
1364
1364
  function inputNodeId() {
1365
1365
  const app = currentId && apps.get(currentId);
1366
1366
  if (!app || !Array.isArray(app.inputs) || !app.inputs.length) return null;
1367
+ // The input node is the first node templating {{ inputs.* }} ANYWHERE in its
1368
+ // config. An exec node carries it under `config.args`, but a REST/agent node
1369
+ // (e.g. floless-workspace/read-approved) carries it in a plain config field,
1370
+ // so scan the whole config recursively — not just args.
1371
+ const usesInput = (v) => {
1372
+ if (typeof v === 'string') return /\{\{\s*inputs\.[A-Za-z0-9._-]+\s*\}\}/.test(v);
1373
+ if (Array.isArray(v)) return v.some(usesInput);
1374
+ if (v && typeof v === 'object') return Object.values(v).some(usesInput);
1375
+ return false;
1376
+ };
1367
1377
  for (const n of app.nodes) {
1368
- const args = n.config && n.config.args;
1369
- if (args && typeof args === 'object') {
1370
- for (const v of Object.values(args)) {
1371
- if (typeof v === 'string' && /\{\{\s*inputs\.[A-Za-z0-9._-]+\s*\}\}/.test(v)) return n.id;
1372
- }
1373
- }
1378
+ if (n.config && usesInput(n.config)) return n.id;
1374
1379
  }
1375
1380
  return null;
1376
1381
  }
@@ -1660,6 +1665,21 @@
1660
1665
  }
1661
1666
  }
1662
1667
 
1668
+ // Friendly app label for a workspace project row (steel-model → "Steel model").
1669
+ const APP_LABELS = { 'steel-model': 'Steel model', vectorize: 'Vectorize' };
1670
+ const appLabel = (a) => APP_LABELS[a] || String(a || '').replace(/[-_]+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
1671
+
1672
+ // Approved Workspace projects for a `widget: workspace-project` input picker. Returns
1673
+ // [] on any error (→ the picker shows its "approve a project first" empty state).
1674
+ async function fetchApprovedProjects(appFilter) {
1675
+ try {
1676
+ const url = '/api/workspace-projects/approved' + (appFilter ? `?app=${encodeURIComponent(appFilter)}` : '');
1677
+ const r = await fetch(url);
1678
+ const j = await r.json().catch(() => null);
1679
+ return j && j.ok && Array.isArray(j.projects) ? j.projects : [];
1680
+ } catch { return []; }
1681
+ }
1682
+
1663
1683
  // Double-click the input node → styled dialog to set the declared inputs. Writes
1664
1684
  // to appInputValues; the header "▶ Run workflow" uses them. No native window.prompt.
1665
1685
  async function openInputsDialog() {
@@ -1667,21 +1687,47 @@
1667
1687
  if (!app || !Array.isArray(app.inputs) || !app.inputs.length) return;
1668
1688
  const cur = currentInputs();
1669
1689
  const isVisual = (inp) => inp.widget === 'file' || inp.type === 'image' || inp.type === 'file';
1690
+ const isProject = (inp) => inp.widget === 'workspace-project';
1670
1691
  const visualNames = new Set(app.inputs.filter(isVisual).map((i) => i.name));
1671
- const fields = app.inputs.map((inp) => isVisual(inp)
1672
- ? {
1692
+ // A project-picker input needs the live list of approved projects — fetch once per open.
1693
+ const approved = app.inputs.some(isProject) ? await fetchApprovedProjects() : [];
1694
+ const fields = app.inputs.map((inp) => {
1695
+ if (isVisual(inp)) return {
1696
+ name: inp.name,
1697
+ label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
1698
+ type: 'file',
1699
+ accept: inp.accept,
1700
+ value: cur[inp.name] != null ? cur[inp.name] : '',
1701
+ };
1702
+ if (isProject(inp)) {
1703
+ const wantApp = typeof inp.workspaceApp === 'string' ? inp.workspaceApp : null;
1704
+ const options = approved
1705
+ .filter((p) => !wantApp || p.app === wantApp)
1706
+ .slice().sort((a, b) => String(a.name).localeCompare(String(b.name)))
1707
+ .map((p) => ({
1708
+ value: p.id,
1709
+ label: p.name,
1710
+ meta: `${appLabel(p.app)} · v${p.latestApprovedVersion}`,
1711
+ search: `${p.name} ${p.app} ${appLabel(p.app)}`,
1712
+ }));
1713
+ return {
1673
1714
  name: inp.name,
1674
1715
  label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
1675
- type: 'file',
1676
- accept: inp.accept,
1716
+ type: 'select',
1717
+ options,
1677
1718
  value: cur[inp.name] != null ? cur[inp.name] : '',
1678
- }
1679
- : {
1680
- name: inp.name,
1681
- label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
1682
- type: inp.type === 'integer' || inp.type === 'number' ? 'number' : 'text',
1683
- value: cur[inp.name] != null ? cur[inp.name] : inp.default != null ? inp.default : '',
1684
- });
1719
+ placeholder: 'Select an approved project…',
1720
+ disabledLabel: 'Approve a project first',
1721
+ emptyNote: 'No approved projects yet — open <strong>Workspaces</strong>, create a project, and Approve it to use it here.',
1722
+ };
1723
+ }
1724
+ return {
1725
+ name: inp.name,
1726
+ label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
1727
+ type: inp.type === 'integer' || inp.type === 'number' ? 'number' : 'text',
1728
+ value: cur[inp.name] != null ? cur[inp.name] : inp.default != null ? inp.default : '',
1729
+ };
1730
+ });
1685
1731
  const res = await formModal({ title: `Inputs · ${app.displayName}`, sub: 'Set the values this run uses, then ▶ Run workflow.', fields, okLabel: 'Set inputs' });
1686
1732
  if (!res) return;
1687
1733
  const store = {};
@@ -1950,7 +1996,7 @@
1950
1996
  }
1951
1997
  document.getElementById('contract-editor-close').onclick = closeContractEditor;
1952
1998
 
1953
- // Export 3D ▸ — render the approved takeoff as an interactive 3D model. Calls the server's
1999
+ // Export 3D ▸ — render the approved model as an interactive 3D model. Calls the server's
1954
2000
  // export-3d (transform → companion viewer-3d app → compile → run) and paints the returned
1955
2001
  // interactive report in the same viewer a normal run uses. api() throws on any failure (non-2xx
1956
2002
  // OR in-band ok:false), so one catch covers "no contract", "all RFI", and compile/render errors.
@@ -1958,7 +2004,7 @@
1958
2004
  const app = currentId && apps.get(currentId);
1959
2005
  if (!app) return;
1960
2006
  $reportTitle.textContent = `3D Viewer · ${app.displayName}`;
1961
- $reportSub.textContent = 'Rendering the 3D model from the approved takeoff…';
2007
+ $reportSub.textContent = 'Rendering the 3D model from the approved version…';
1962
2008
  $reportModal.dataset.nodeId = appId;
1963
2009
  showModal($reportModal);
1964
2010
  clearReportFrames(); // reset both frames + the ↗ Open buffer so a failure can't show a stale report
@@ -1973,7 +2019,7 @@
1973
2019
  // surface that, never let an incomplete model read as complete.
1974
2020
  const dropped = Array.isArray(res.skipped) ? res.skipped.length : 0;
1975
2021
  $reportSub.textContent = (dropped ? `${dropped} member(s) not shown (no AISC size — RFI). ` : '')
1976
- + 'Live 3D view from the approved takeoff — drag to orbit, scroll to zoom, click an element to inspect.';
2022
+ + 'Live 3D view from the approved model — drag to orbit, scroll to zoom, click an element to inspect.';
1977
2023
  if (dropped) showToast(`3D: ${dropped} member(s) skipped — no resolvable AISC size`, 'info');
1978
2024
  paintReport(html, true);
1979
2025
  lastReportByApp.set(currentId, { nodeId: res.report.nodeId, label: '3D', html, interactive: true });
@@ -1985,7 +2031,7 @@
1985
2031
  }
1986
2032
  }
1987
2033
 
1988
- // Export IFC ▸ — write the approved takeoff OUT to a universal .ifc and download it. The server
2034
+ // Export IFC ▸ — write the approved model OUT to a universal .ifc and download it. The server
1989
2035
  // builds a model-free ifc companion, runs it, and returns the .ifc text (res.content); the browser
1990
2036
  // turns it into a download. api() throws on any failure (no contract, all-RFI, compile/write error).
1991
2037
  async function exportContractIfc(appId, isVector) {
@@ -2011,7 +2057,7 @@
2011
2057
  }
2012
2058
  }
2013
2059
 
2014
- // Export BOM ▸ — write the approved takeoff's Bill of Materials OUT to a CSV or a real .xlsx and
2060
+ // Export BOM ▸ — write the approved model's Bill of Materials OUT to a CSV or a real .xlsx and
2015
2061
  // download it. Generated host-side (no model): the server reuses the same BOM aggregation the
2016
2062
  // canvas BOM node shows, saves the file under ~/.floless/exports/<appId>/, and returns the bytes
2017
2063
  // (csv text, or xlsx base64) which the browser turns into a download. api() throws on any failure
@@ -2045,7 +2091,7 @@
2045
2091
  return out;
2046
2092
  }
2047
2093
 
2048
- // Send to Tekla ▸ — create native parts in the OPEN Tekla model from the approved takeoff. Needs
2094
+ // Send to Tekla ▸ — create native parts in the OPEN Tekla model from the approved model. Needs
2049
2095
  // Tekla running with a model; when it's not, the server returns a clear needsTekla state (api()
2050
2096
  // throws with err.body.needsTekla) — surfaced as an informational nudge, not a hard error.
2051
2097
  async function exportContractTekla(appId) {
@@ -2461,6 +2507,29 @@
2461
2507
  <input type="file" accept="${escapeAttr(acceptAttr)}" multiple class="fm-file-input" tabindex="-1" aria-hidden="true">
2462
2508
  <div class="fm-files-list" aria-live="polite" hidden></div>
2463
2509
  </div>`;
2510
+ } else if (f.type === 'select') {
2511
+ // Themed picker (reuses the .wf-combo/.wf-popover/.wf-option language). The VALUE
2512
+ // lives in a hidden [data-fm] input so collect() reads it like any other field;
2513
+ // the combo just displays a friendly label and updates that input. Popover flows
2514
+ // in-line (not absolute) so it can't be clipped by the modal body's scroll.
2515
+ const opts = Array.isArray(f.options) ? f.options : [];
2516
+ const sel = opts.find((o) => String(o.value) === val);
2517
+ const disabled = !opts.length;
2518
+ const trigLabel = disabled ? (f.disabledLabel || 'None available')
2519
+ : sel ? sel.label + (sel.meta ? ` (${sel.meta})` : '') : (f.placeholder || 'Select…');
2520
+ const rows = opts.map((o) =>
2521
+ `<div class="wf-option" role="option" data-id="${escapeAttr(String(o.value))}" data-search="${escapeAttr(String(o.search || o.label).toLowerCase())}" tabindex="-1" aria-selected="${String(o.value) === val ? 'true' : 'false'}"><span class="wf-option-name">${escapeHtml(o.label)}</span>${o.meta ? `<span class="wf-option-meta">${escapeHtml(o.meta)}</span>` : ''}</div>`).join('');
2522
+ ctl = `<div class="wf-combo fm-select" data-fm-select="${escapeAttr(f.name)}">
2523
+ <input type="hidden" data-fm="${escapeHtml(f.name)}" value="${escapeAttr(val)}">
2524
+ <button type="button" class="wf-trigger fm-select-trigger" aria-haspopup="listbox" aria-expanded="false"${disabled ? ' disabled' : ''}>
2525
+ <span class="wf-trigger-label fm-select-label"${sel ? '' : ' data-empty="1"'}>${escapeHtml(trigLabel)}</span>
2526
+ <svg class="wf-caret" width="10" height="6" viewBox="0 0 10 6" aria-hidden="true"><path fill="currentColor" d="M0 0l5 6 5-6z"/></svg>
2527
+ </button>
2528
+ <div class="wf-popover fm-select-popover" role="listbox" aria-label="${escapeAttr(f.label || f.name)}" hidden>
2529
+ <div class="wf-search-wrap"><input class="wf-search fm-select-search" type="text" placeholder="Search…" autocomplete="off" aria-label="Search"></div>
2530
+ <div class="wf-list fm-select-list">${rows}<div class="wf-empty-search" hidden>No matches</div></div>
2531
+ </div>${disabled && f.emptyNote ? `<div class="fm-select-note">${f.emptyNote}</div>` : ''}
2532
+ </div>`;
2464
2533
  } else {
2465
2534
  ctl = f.multiline
2466
2535
  ? `<textarea id="${id}" rows="4" data-fm="${escapeHtml(f.name)}" placeholder="${ph}">${escapeHtml(val)}</textarea>`
@@ -2649,6 +2718,67 @@
2649
2718
  if (box.dataset.required) fileGateProbes.push(() => (state.some((s) => s.reading) ? 0 : readyCount()));
2650
2719
  renderList(); syncDrop();
2651
2720
  });
2721
+ // ── select field setup (themed picker: search + keyboard + click-to-choose) ──
2722
+ $body.querySelectorAll('.fm-select').forEach((box) => {
2723
+ const hidden = box.querySelector('input[type="hidden"][data-fm]');
2724
+ const trigger = box.querySelector('.fm-select-trigger');
2725
+ const label = box.querySelector('.fm-select-label');
2726
+ const popover = box.querySelector('.fm-select-popover');
2727
+ const search = box.querySelector('.fm-select-search');
2728
+ const list = box.querySelector('.fm-select-list');
2729
+ if (!trigger || trigger.disabled || !popover || !list) return;
2730
+ let hi = -1;
2731
+ const opts = () => [...list.querySelectorAll('.wf-option')];
2732
+ const visible = () => opts().filter((o) => !o.hidden);
2733
+ const clearHi = () => { list.querySelectorAll('.wf-option.highlighted').forEach((o) => o.classList.remove('highlighted')); hi = -1; };
2734
+ const filter = (q) => {
2735
+ q = (q || '').toLowerCase().trim();
2736
+ let any = false;
2737
+ opts().forEach((o) => { const m = !q || o.dataset.search.includes(q); o.hidden = !m; if (m) any = true; });
2738
+ const empty = list.querySelector('.wf-empty-search'); if (empty) empty.hidden = any;
2739
+ clearHi();
2740
+ };
2741
+ const move = (d) => {
2742
+ const vis = visible(); if (!vis.length) return;
2743
+ hi = hi < 0 ? (d > 0 ? 0 : vis.length - 1) : Math.max(0, Math.min(vis.length - 1, hi + d));
2744
+ vis.forEach((o, i) => o.classList.toggle('highlighted', i === hi));
2745
+ vis[hi].scrollIntoView({ block: 'nearest' });
2746
+ };
2747
+ const open = () => { popover.hidden = false; trigger.classList.add('open'); trigger.setAttribute('aria-expanded', 'true'); if (search) { search.value = ''; filter(''); setTimeout(() => search.focus(), 0); } };
2748
+ const close = (focusTrig) => { popover.hidden = true; trigger.classList.remove('open'); trigger.setAttribute('aria-expanded', 'false'); clearHi(); if (focusTrig) trigger.focus(); };
2749
+ const choose = (opt) => {
2750
+ if (hidden) hidden.value = opt.dataset.id;
2751
+ opts().forEach((o) => { const s = o === opt; o.classList.toggle('selected', s); o.setAttribute('aria-selected', s ? 'true' : 'false'); });
2752
+ const nm = opt.querySelector('.wf-option-name');
2753
+ const mt = opt.querySelector('.wf-option-meta');
2754
+ if (label) { label.textContent = (nm ? nm.textContent : opt.dataset.id) + (mt ? ` (${mt.textContent})` : ''); label.removeAttribute('data-empty'); }
2755
+ close(true);
2756
+ };
2757
+ trigger.addEventListener('click', (e) => { e.stopPropagation(); popover.hidden ? open() : close(false); });
2758
+ trigger.addEventListener('keydown', (e) => { if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') { e.preventDefault(); open(); } });
2759
+ list.addEventListener('click', (e) => { const o = e.target.closest('.wf-option'); if (o) { e.stopPropagation(); choose(o); } });
2760
+ if (search) search.addEventListener('input', () => filter(search.value));
2761
+ // Keep combo keys inside the combo — don't submit/cancel the whole modal.
2762
+ box.addEventListener('keydown', (e) => {
2763
+ if (popover.hidden) return;
2764
+ if (e.key === 'ArrowDown') { e.preventDefault(); e.stopPropagation(); move(1); }
2765
+ else if (e.key === 'ArrowUp') { e.preventDefault(); e.stopPropagation(); move(-1); }
2766
+ else if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); const vis = visible(); if (hi >= 0 && vis[hi]) choose(vis[hi]); }
2767
+ else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close(true); }
2768
+ });
2769
+ });
2770
+ // Click elsewhere in the form closes any open select popover (trigger/option clicks
2771
+ // stopPropagation, so this only fires for genuine outside clicks). Cleared in done().
2772
+ $body.onclick = (e) => {
2773
+ $body.querySelectorAll('.fm-select').forEach((box) => {
2774
+ const pop = box.querySelector('.fm-select-popover');
2775
+ if (pop && !pop.hidden && !box.contains(e.target)) {
2776
+ pop.hidden = true;
2777
+ const t = box.querySelector('.fm-select-trigger');
2778
+ if (t) { t.classList.remove('open'); t.setAttribute('aria-expanded', 'false'); }
2779
+ }
2780
+ });
2781
+ };
2652
2782
  // ── paste support: an image into the modal → the images field, else the file field ──
2653
2783
  $body.onpaste = (e) => {
2654
2784
  const items = Array.from((e.clipboardData && e.clipboardData.items) || []);
@@ -2729,7 +2859,7 @@
2729
2859
  _formModalOpen = false;
2730
2860
  modalClosed = true;
2731
2861
  hideModal($formModal);
2732
- $ok.onclick = null; $cancel.onclick = null; $formModal.onclick = null; $formModal.onkeydown = null; $body.onpaste = null; $body.ondragover = null; $body.ondrop = null;
2862
+ $ok.onclick = null; $cancel.onclick = null; $formModal.onclick = null; $formModal.onkeydown = null; $body.onpaste = null; $body.onclick = null; $body.ondragover = null; $body.ondrop = null;
2733
2863
  $ok.classList.remove('danger'); $ok.classList.add('primary'); $cancel.classList.remove('primary'); $ok.disabled = false; // reset chrome for the next caller
2734
2864
  resolve(result);
2735
2865
  };
@@ -3250,13 +3380,18 @@
3250
3380
  if ($canvasMain && $dropTarget) {
3251
3381
  // dragenter stays file-only on purpose: it shows the ".flo import" overlay ($dropTarget),
3252
3382
  // which must NOT appear for a node-card drag. dragover alone suppresses the no-drop cursor.
3253
- $canvasMain.addEventListener('dragenter', (e) => { if (isFileDrag(e)) { e.preventDefault(); $dropTarget.classList.add('active'); } });
3383
+ // Gate all handlers: .flo import is Workflows-only, not available in Workspaces mode.
3384
+ $canvasMain.addEventListener('dragenter', (e) => {
3385
+ if ($app.classList.contains('mode-workspaces')) return; // .flo not used in Workspaces
3386
+ if (isFileDrag(e)) { e.preventDefault(); $dropTarget.classList.add('active'); }
3387
+ });
3254
3388
  $canvasMain.addEventListener('dragover', (e) => {
3255
3389
  if (isFileDrag(e)) { e.preventDefault(); return; } // required to allow the file drop
3256
3390
  if (isCardDrag(e)) { e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; } // suppress the no-drop cursor (#96)
3257
3391
  });
3258
3392
  $canvasMain.addEventListener('dragleave', (e) => { if (!$canvasMain.contains(e.relatedTarget)) $dropTarget.classList.remove('active'); });
3259
3393
  $canvasMain.addEventListener('drop', (e) => {
3394
+ if ($app.classList.contains('mode-workspaces')) return; // .flo not used in Workspaces
3260
3395
  // A card dropped on the bare canvas is a no-op: saving as a Template only happens on the
3261
3396
  // Templates bar (its own drop handler, which runs first as the drop bubbles up). Now that
3262
3397
  // the canvas accepts the dragover we must swallow that drop so the browser performs no
@@ -4761,18 +4896,45 @@
4761
4896
  return `Help me build a brand-new floless workflow from scratch, step by step, with your floless-app-new-workflow skill. Ask me what I want it to do, then before writing any node confirm the agents it needs are installed (offer to install a missing one from the catalogue, or to report a not-yet-existing agent as an idea). Author the .flo node by node, verifying each step is correct (plain-English descriptions, validate, compile, a real run), and finish by installing → Compile → ▶ Run so I can see it work and approve.`;
4762
4897
  }
4763
4898
  if (req.type === 'revision-read') {
4899
+ const isInitialRead = !req.baseVersion || req.baseVersion <= 0;
4764
4900
  const snaps = req.snapshots && req.snapshots.length
4765
- ? `\nRevised drawing${req.snapshots.length > 1 ? 's' : ''} (read these): ${req.snapshots.join(', ')}`
4901
+ ? `\n${isInitialRead ? 'Initial' : 'Revised'} drawing${req.snapshots.length > 1 ? 's' : ''} (read these): ${req.snapshots.join(', ')}`
4766
4902
  : '';
4767
4903
  const note = req.instruction ? `\nMy note: ${req.instruction}` : '';
4768
- const post = `Then POST /api/projects/${req.project}/revision-read with { contract, message: "<plain-English what changed>", requestId: "${req.id}" }. The server derives the base version + source provenance from this queued request, records a "revision-read" version, and clears the request — do NOT DELETE the request yourself. If you can't read the set, POST /api/projects/${req.project}/revision-requests/${req.id}/fail with { error }.`;
4904
+ const messageHint = isInitialRead ? '<plain-English what was read>' : '<plain-English what changed>';
4905
+ const post = `Only after the review checkpoint is complete, POST /api/projects/${req.project}/revision-read with { contract, message: "${messageHint}", requestId: "${req.id}" }. The server derives the base version + source provenance from this queued request, records a "revision-read" version, and clears the request — do NOT DELETE the request yourself. If you can't read the set, POST /api/projects/${req.project}/revision-requests/${req.id}/fail with { error }.`;
4769
4906
  // App-aware: the target contract shape differs per workspace app. A vectorize project holds a
4770
4907
  // drawing.vector/v1 (clean editable 2D linework), NOT a steel takeoff — instructing the AI to
4771
4908
  // read steel members would produce the wrong contract for the vector editor (spec §3.3g).
4772
4909
  if (req.appId === 'vectorize') {
4910
+ if (isInitialRead) {
4911
+ return `In floless project "${req.project}" (app "${req.appId}"), an initial drawing was attached — trace it into this project as its first version (do NOT create a new project). Vectorize the drawing per the floless-app-vectorize skill into a drawing.vector/v1 contract: emit clean, editable 2D vector geometry (sheets → elements: lines / polylines / curves / text, each on its layer), NOT steel members or a takeoff. A vector PDF is read deterministically (exact geometry, no guessing); a photo, scan or hand sketch is traced by a fenced vision extraction that flags every uncertain stroke (low confidence) for the user's review. ${post}${snaps}${note}`;
4912
+ }
4773
4913
  return `In floless project "${req.project}" (app "${req.appId}"), a REVISED drawing was attached — re-read (vectorize) it into the SAME project as a new version (do NOT create a new project). Vectorize the drawing per the floless-app-vectorize skill into a drawing.vector/v1 contract: emit clean, editable 2D vector geometry (sheets → elements: lines / polylines / curves / text, each on its layer), NOT steel members or a takeoff. A vector PDF is read deterministically (exact geometry, no guessing); a photo, scan or hand sketch is traced by a fenced vision extraction that flags every uncertain stroke (low confidence) for the user's review. ${post}${snaps}${note}`;
4774
4914
  }
4775
- 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). Read the drawings per the floless-app-steel-takeoff skill, compose the updated steel.takeoff/v1 contract. First GET /api/contract/${req.appId}?project=${req.project} to read the CURRENT 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}`;
4915
+ if (isInitialRead) {
4916
+ return `In floless project "${req.project}" (app "${req.appId}"), an initial drawing set was attached — read it into this project as its first steel model version (do NOT create a new project). Follow the floless-app-steel-takeoff skill's mandatory two-phase gate. FIRST, do the deterministic PyMuPDF steel-filter pass only: identify the framing-plan sheets, enumerate the drawing elements by layer/thickness/color into contract.filter.sheets/facets, PUT that project contract to /api/contract/${req.appId}?project=${req.project}, 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 and compose the steel.takeoff/v1 contract. ${post}${snaps}${note}`;
4917
+ }
4918
+ 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, PUT that project contract back to /api/contract/${req.appId}?project=${req.project}, 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}`;
4919
+ }
4920
+ // The Knowledge step's Organize verb. The lifecycle is SERVER-owned: start claims the organize
4921
+ // lock and mints the generation dir; finish publishes it and clears this request; fail releases
4922
+ // the lock. Naming the exact project-scoped routes matters — /api/requests/<id> is NOT the
4923
+ // completion path here, and a stray DELETE would strand the lock until its stale timeout.
4924
+ if (req.type === 'knowledge-organize') {
4925
+ const kb = `/api/projects/${req.project}/knowledge`;
4926
+ return `In floless project "${req.project}", organize the Project Knowledge Base with your floless-app-knowledge skill. ` +
4927
+ `Claim the pass with POST ${kb}/requests/${req.id}/start — it takes the organize lock and returns { baseRevision, generationId, wikiDir }. ` +
4928
+ `Read the source set from GET ${kb}/status (the rows it marks state:"organizing" ARE this pass's snapshot), read each source's bytes from that project's knowledge/blobs/<blobSha256>, ` +
4929
+ `and compile the project wiki INTO the returned wikiDir — never invent a path. ` +
4930
+ `Publish with POST ${kb}/requests/${req.id}/finish { generationId, lintSummary }; on any failure release the lock with POST ${kb}/requests/${req.id}/fail { error }. ` +
4931
+ `Do NOT DELETE this request and do NOT use /api/requests/${req.id} — finish/fail resolves it server-side. ` +
4932
+ `If finish returns { rerun: true } the sources changed mid-pass: POST ${kb}/organize once for a FRESH request, then run start → compile → finish on that new id exactly once.`;
4933
+ }
4934
+ // The KB "reshape it" box (its UI lands in a later slice; the verb + route already exist).
4935
+ if (req.type === 'knowledge-adjust') {
4936
+ return `In floless project "${req.project}", reshape the Project Knowledge Base with your floless-app-knowledge skill: ${req.instruction || 'apply the requested change'}. ` +
4937
+ `Edit the project's wiki notes accordingly, then re-organize so the published generation reflects the change.`;
4776
4938
  }
4777
4939
  return '';
4778
4940
  }
@@ -4790,6 +4952,9 @@
4790
4952
  guide: 'floless-app-onboarding',
4791
4953
  // Build-a-workflow-from-scratch: its own guide skill (interview → author → verify).
4792
4954
  'new-workflow': 'floless-app-new-workflow',
4955
+ // Project Knowledge Base: one self-contained skill drives both the organize lifecycle and adjusts.
4956
+ 'knowledge-organize': 'floless-app-knowledge',
4957
+ 'knowledge-adjust': 'floless-app-knowledge',
4793
4958
  };
4794
4959
 
4795
4960
  // The COPIED form of a request: instructionFor() prefixed with a self-identifying
@@ -4805,11 +4970,17 @@
4805
4970
  let skill = REQUEST_SKILL[req.type] || 'floless-app-workflows';
4806
4971
  if (req.type === 'revision-read' && req.appId === 'vectorize') skill = 'floless-app-vectorize';
4807
4972
  const base = (typeof location !== 'undefined' && location.origin) ? location.origin : 'http://127.0.0.1:4317';
4808
- // A revision-read is cleared by its own /revision-read POST — a separate DELETE would 404. Every
4809
- // other type is applied-then-DELETEd by the terminal AI.
4973
+ // A revision-read is cleared by its own /revision-read POST — a separate DELETE would 404. A
4974
+ // knowledge-organize is likewise lifecycle-owned: its finish/fail POST clears it, and a stray
4975
+ // DELETE would strand the organize lock until the stale timeout. Every other type is
4976
+ // applied-then-DELETEd by the terminal AI.
4810
4977
  const clears = req.type === 'revision-read'
4811
- ? `apply it via the route in the line below (that POST clears this request — do NOT DELETE it separately).`
4812
- : `apply that request, then DELETE ${base}/api/requests/${req.id}.`;
4978
+ ? (req.appId === 'steel-model'
4979
+ ? `apply it in two phases: first write the Steel Filter checkpoint to the project contract and stop for user Save; only after that checkpoint use the route in the line below (that POST clears this request — do NOT DELETE it separately).`
4980
+ : `apply it via the route in the line below (that POST clears this request — do NOT DELETE it separately).`)
4981
+ : req.type === 'knowledge-organize'
4982
+ ? `drive it through the start → finish/fail lifecycle routes in the line below (finish or fail clears this request — do NOT DELETE it separately, that would strand the organize lock).`
4983
+ : `apply that request, then DELETE ${base}/api/requests/${req.id}.`;
4813
4984
  const marker =
4814
4985
  `[floless-request type=${req.type} id=${req.id}] — queued from the FloLess Dashboard. ` +
4815
4986
  `Apply it with your ${skill} skill: fetch the authoritative spec from GET ${base}/api/requests, ` +
@@ -4821,6 +4992,47 @@
4821
4992
  try { await navigator.clipboard.writeText(text); return true; } catch { return false; }
4822
4993
  }
4823
4994
 
4995
+ let requestHelpReq = null;
4996
+ let requestHelpReturnFocus = null;
4997
+ function closeRequestHelp({ restoreFocus = true } = {}) {
4998
+ const $m = document.getElementById('request-help-modal');
4999
+ if ($m) hideModal($m);
5000
+ const target = requestHelpReturnFocus;
5001
+ requestHelpReturnFocus = null;
5002
+ if (restoreFocus && target && target.isConnected) {
5003
+ try { target.focus(); } catch { /* focus is best-effort */ }
5004
+ }
5005
+ }
5006
+ function showRequestQueuedModal(req, opts = {}) {
5007
+ const $m = document.getElementById('request-help-modal');
5008
+ if (!$m || !req) return;
5009
+ requestHelpReq = req;
5010
+ requestHelpReturnFocus = opts.returnFocus || document.activeElement;
5011
+ const copied = opts.copied !== false;
5012
+ const n = Number(opts.fileCount || (req.snapshots && req.snapshots.length) || 1);
5013
+ const isRevisionRead = req.type === 'revision-read';
5014
+ const isInitial = isRevisionRead && (!req.baseVersion || req.baseVersion <= 0);
5015
+ const $title = document.getElementById('request-help-title');
5016
+ const $sub = document.getElementById('request-help-sub');
5017
+ const $note = document.getElementById('request-help-note');
5018
+ const $copy = document.getElementById('request-help-copy');
5019
+ if ($title) $title.textContent = isRevisionRead
5020
+ ? `${isInitial ? 'Initial drawing read' : 'Revision read'} queued`
5021
+ : 'Request queued';
5022
+ if ($sub) {
5023
+ $sub.textContent = copied
5024
+ ? `${n} drawing file${n === 1 ? '' : 's'} added to Requests. The terminal instructions were copied to your clipboard.`
5025
+ : `${n} drawing file${n === 1 ? '' : 's'} added to Requests. Copy the terminal instructions from here or from the Requests panel.`;
5026
+ }
5027
+ if ($note) $note.textContent = isRevisionRead
5028
+ ? 'The web UI queues the drawing read; your terminal agent applies it and reports progress back here.'
5029
+ : 'The web UI queues the request; your terminal agent applies it and reports progress back here.';
5030
+ if ($copy) $copy.hidden = copied;
5031
+ showModal($m);
5032
+ const shell = $m.querySelector('.modal.request-help');
5033
+ if (shell) { try { shell.focus(); } catch { /* not focusable */ } }
5034
+ }
5035
+
4824
5036
  async function useTemplate(templateId) {
4825
5037
  if (!currentId) { showToast('open a workflow first', 'warn'); return; }
4826
5038
  try {
@@ -4861,6 +5073,9 @@
4861
5073
  }
4862
5074
 
4863
5075
  let pendingRequests = [];
5076
+ let previousRequestCount = 0;
5077
+ let previousRequestIds = null;
5078
+ let reqPulseTimer = null;
4864
5079
  async function loadRequests() {
4865
5080
  try {
4866
5081
  const { requests } = await api('/api/requests');
@@ -4869,6 +5084,20 @@
4869
5084
  const $rs = document.getElementById('req-stat');
4870
5085
  if ($rc) $rc.textContent = requests.length;
4871
5086
  if ($rs) $rs.classList.toggle('has-pending', requests.length > 0);
5087
+ const ids = new Set(requests.map((r) => r && r.id).filter(Boolean));
5088
+ const hasNewId = previousRequestIds
5089
+ ? requests.some((r) => r && r.id && !previousRequestIds.has(r.id))
5090
+ : requests.length > previousRequestCount;
5091
+ // Add the shake animation when a new request appears in the poll/SSE refresh.
5092
+ if ((hasNewId || requests.length > previousRequestCount) && $rs) {
5093
+ $rs.classList.remove('req-pulse'); // force reflow to restart animation
5094
+ void $rs.offsetWidth; // trigger reflow
5095
+ $rs.classList.add('req-pulse');
5096
+ if (reqPulseTimer) clearTimeout(reqPulseTimer);
5097
+ reqPulseTimer = setTimeout(() => { $rs.classList.remove('req-pulse'); reqPulseTimer = null; }, 2100);
5098
+ }
5099
+ previousRequestCount = requests.length;
5100
+ previousRequestIds = ids;
4872
5101
  const $rm = document.getElementById('requests-modal');
4873
5102
  if ($rm && $rm.classList.contains('show')) renderRequests(); // keep an open list live
4874
5103
  } catch { /* non-fatal */ }
@@ -4892,8 +5121,8 @@
4892
5121
  return;
4893
5122
  }
4894
5123
  $list.innerHTML = pendingRequests.map((r) => {
4895
- 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' : 'tweak';
4896
- const badgeCls = r.type === 'tweak' || r.type === 'ui-customize' || r.type === 'rebake' || r.type === 'revision-read' ? 'req-type req-type-tweak' : 'req-type';
5124
+ 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';
5125
+ 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';
4897
5126
  const target = r.type === 'tweak' && r.nodeId
4898
5127
  ? ` · node <code>${escapeHtml(r.nodeId)}</code>`
4899
5128
  : r.type === 'rebake' && r.inputName
@@ -4901,6 +5130,13 @@
4901
5130
  : '';
4902
5131
  const when = r.createdAt ? new Date(r.createdAt) : null;
4903
5132
  const time = when && !isNaN(when) ? `<span class="req-time">${escapeHtml(nowStamp(when))}</span>` : '';
5133
+ // A knowledge-organize is resolved by its own finish/fail lifecycle POST. Offering a ✕ here
5134
+ // would let the user delete a request the terminal AI is mid-way through, 404-ing finish/fail
5135
+ // and stranding the organize lock until its stale timeout. Show why it can't be cleared instead.
5136
+ const lifecycleOwned = r.type === 'knowledge-organize';
5137
+ const del = lifecycleOwned
5138
+ ? '<span class="req-lifecycle" data-tip="This clears itself when your terminal AI finishes or fails the organize">finishing in your terminal</span>'
5139
+ : `<button class="req-del" data-id="${escapeAttr(r.id)}" data-tip="Clear this request">×</button>`;
4904
5140
  return `
4905
5141
  <div class="req-item">
4906
5142
  <div class="req-info">
@@ -4910,7 +5146,7 @@
4910
5146
  </div>
4911
5147
  <div class="req-actions">
4912
5148
  <button class="req-copy" data-id="${escapeAttr(r.id)}" data-tip="Copy this instruction">⧉</button>
4913
- <button class="req-del" data-id="${escapeAttr(r.id)}" data-tip="Clear this request">×</button>
5149
+ ${del}
4914
5150
  </div>
4915
5151
  </div>`;
4916
5152
  }).join('');
@@ -4932,14 +5168,36 @@
4932
5168
  try { await api(`/api/requests/${encodeURIComponent(id)}`, { method: 'DELETE' }); await loadRequests(); renderRequests(); }
4933
5169
  catch (e) { reportErr(e); }
4934
5170
  }
5171
+ // Clear-all must never take out a knowledge-organize: the bulk DELETE would 404 its finish/fail and
5172
+ // strand the organize lock until the stale timeout. The request list can't tell "queued" from
5173
+ // "already started", so ALL organizes are kept — they clear themselves via their lifecycle.
4935
5174
  async function clearAllRequests() {
4936
5175
  if (!pendingRequests.length) return;
4937
- try { await api('/api/requests', { method: 'DELETE' }); await loadRequests(); renderRequests(); showToast('Cleared all requests', 'ok'); }
4938
- catch (e) { reportErr(e); }
5176
+ const keep = pendingRequests.filter((r) => r && r.type === 'knowledge-organize');
5177
+ try {
5178
+ if (!keep.length) {
5179
+ await api('/api/requests', { method: 'DELETE' }); // nothing lifecycle-owned — the atomic bulk clear is fine
5180
+ } else {
5181
+ const drop = pendingRequests.filter((r) => r && r.type !== 'knowledge-organize');
5182
+ for (const r of drop) await api(`/api/requests/${encodeURIComponent(r.id)}`, { method: 'DELETE' });
5183
+ }
5184
+ await loadRequests();
5185
+ renderRequests();
5186
+ showToast(
5187
+ keep.length
5188
+ ? `Cleared the other requests — kept ${keep.length} in-progress organize${keep.length === 1 ? '' : 's'}`
5189
+ : 'Cleared all requests',
5190
+ 'ok',
5191
+ );
5192
+ } catch (e) { reportErr(e); }
4939
5193
  }
4940
- function openRequests() {
4941
- renderRequests();
5194
+ // Re-fetch before showing: there is no server `request-added` broadcast, so a request queued in
5195
+ // another tab (or by the Knowledge step) would otherwise render from a stale cache.
5196
+ async function openRequests() {
4942
5197
  document.getElementById('requests-modal').classList.add('show');
5198
+ renderRequests(); // paint the cache immediately — no empty flash
5199
+ await loadRequests();
5200
+ renderRequests(); // then reconcile with the truth
4943
5201
  }
4944
5202
 
4945
5203
  // ── Agents library: real installed agents + their commands ───────────────────
@@ -6387,7 +6645,32 @@
6387
6645
  const copied = await copyToClipboard(text);
6388
6646
  showToast(copied ? `Copied ${pendingRequests.length} request(s) — paste to your terminal AI` : 'copy failed', copied ? 'ok' : 'err');
6389
6647
  };
6648
+ const $requestHelpModal = document.getElementById('request-help-modal');
6649
+ const $requestHelpOpen = document.getElementById('request-help-open');
6650
+ const $requestHelpKeep = document.getElementById('request-help-keep');
6651
+ const $requestHelpCopy = document.getElementById('request-help-copy');
6652
+ if ($requestHelpOpen) $requestHelpOpen.onclick = () => {
6653
+ closeRequestHelp({ restoreFocus: false });
6654
+ openRequests();
6655
+ };
6656
+ if ($requestHelpKeep) $requestHelpKeep.onclick = () => closeRequestHelp();
6657
+ if ($requestHelpCopy) $requestHelpCopy.onclick = async () => {
6658
+ if (!requestHelpReq) return;
6659
+ const copied = await copyToClipboard(markedInstruction(requestHelpReq));
6660
+ showToast(copied ? 'Copied — paste it to your terminal AI' : 'copy failed', copied ? 'ok' : 'err');
6661
+ if (copied) {
6662
+ $requestHelpCopy.hidden = true;
6663
+ const $sub = document.getElementById('request-help-sub');
6664
+ if ($sub) $sub.textContent = 'Terminal instructions copied. Open the terminal agent and paste them there.';
6665
+ }
6666
+ };
6667
+ if ($requestHelpModal) onBackdropDismiss($requestHelpModal, () => closeRequestHelp());
6390
6668
  document.addEventListener('keydown', (e) => {
6669
+ if (e.key === 'Escape' && $requestHelpModal && $requestHelpModal.classList.contains('show')) {
6670
+ e.preventDefault();
6671
+ closeRequestHelp();
6672
+ return;
6673
+ }
6391
6674
  if (e.key === 'Escape' && $reqModal && $reqModal.classList.contains('show')) $reqModal.classList.remove('show');
6392
6675
  });
6393
6676
 
@@ -6573,6 +6856,7 @@
6573
6856
  copyToClipboard,
6574
6857
  instructionFor,
6575
6858
  markedInstruction, // marked (paste-safe) form for clipboard copies — panels.js uses it (#73)
6859
+ showRequestQueuedModal,
6576
6860
  formModal, // the shared styled prompt/form modal — workspaces.js reuses it (never a native prompt)
6577
6861
  // ── Workspaces guide beacon (the SAME #guide-beacon/#guide-modal, document variant) ──
6578
6862
  // workspaces.js owns the open project + its lifecycle state; aware.js owns the beacon