@floless/app 0.126.4 → 0.127.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.
@@ -2,7 +2,7 @@
2
2
  name: floless-app-new-workflow
3
3
  description: This skill should be used to build a brand-new FloLess .flo workflow from scratch, step by step, as the host terminal AI — interviewing the user about what they want, checking that the AWARE agents the workflow needs are installed (installing an available one on consent, or reporting a not-yet-existing agent as an idea), then authoring the .flo node by node and verifying each step with the real toolchain (plain-English descriptions, aware app validate, aware app compile, a real run) before installing it so it appears in the floless.app picker for Compile and Run. Use it on triggers like "build a new workflow", "create a workflow from scratch", "build me a workflow", "new workflow", the floless.app "New workflow…" menu item, a queued new-workflow request, or "/floless-app-new-workflow". It leans on floless-app-workflows for the exec contract and hands back a runnable, approved app.
4
4
  metadata:
5
- version: 0.2.0
5
+ version: 0.3.0
6
6
  ---
7
7
 
8
8
  # Build a new floless.app workflow from scratch
@@ -91,6 +91,23 @@ user's practice — a plausible bolt spacing rather than *their* bolt spacing.
91
91
  3. **Bake what it says in as literal values, and cite the page** in the node's plain-English
92
92
  Description — e.g. "Spacing per `shop-standard-bolts`." That is what makes the decision traceable
93
93
  to the firm's own document instead of looking like your preference.
94
+ 4. **Record what you built from**, once the workflow is installed and has an `<appId>`:
95
+
96
+ ```
97
+ PUT <base>/api/kb-pin/<appId>
98
+ { "projectId": "<project>",
99
+ "generationId": "<the generation.generationId the feed returned>",
100
+ "pages": [{ "slug": "shop-standard-bolts", "title": "Shop Standard Bolts" }] }
101
+ ```
102
+
103
+ Only the pages you actually relied on (at most 20). The app renders this as "Informed by …" and
104
+ tells the user when that knowledge has changed since.
105
+
106
+ **Send the generation id you READ, not whatever is current when you finish.** If the knowledge
107
+ base is re-organized mid-build, the generation you actually read is still the right thing to
108
+ record and the route accepts it — this is a record of what the workflow was built from, not a
109
+ claim about what is current. Pinning "the latest" instead would record a generation whose
110
+ contents never touched your work.
94
111
 
95
112
  `hasKnowledge: true` only means a knowledge base was published, not that it covers your subject. If
96
113
  nothing relevant comes back, **say so and proceed on stated assumptions** — never invent a standard.
@@ -2,14 +2,14 @@
2
2
  name: floless-app-queue
3
3
  description: This skill should be used when the user has MULTIPLE floless.app requests queued from the Dashboard and wants to see them and choose which to process, rather than the AI just picking up the oldest one. Use it when the user says things like "what's in my floless queue", "list my queued floless requests", "show me the pending requests and let me pick", "I queued a few tweaks — which should I apply?", "let me choose what to process", or "pick from the floless queue". It lists the pending requests from GET /api/requests in plain language (type, which app/node/project, the instruction), asks the user which one(s) to apply, then hands each chosen request to the owning skill (floless-app-workflows / -tweak-contract / -ui / -rebake / -onboarding / -new-workflow / -steel-takeoff / -vectorize / -knowledge) which applies it and clears it. It is the interactive picker that sits in front of floless-app-bridge (which is the actual pull-apply-clear engine).
4
4
  metadata:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  ---
7
7
 
8
8
  # floless.app queue picker
9
9
 
10
10
  floless.app is the **thin web UI**; the **terminal AI (you) is the brain**. The UI cannot edit
11
11
  `.flo` files — it **queues requests** (Tweak / use-template / customize-UI / rebake / edit-contract /
12
- walk-me-through / new-workflow / read-this-drawing / organize-or-adjust-the-knowledge-base) to a
12
+ walk-me-through / new-workflow / read-this-drawing / organize-or-adjust-the-knowledge-base / add-a-deterministic-knowledge-consult) to a
13
13
  local API. The **`floless-app-bridge`** skill pulls those and applies them, but it processes
14
14
  the queue **oldest-first with no choice step**. This skill adds the missing affordance: **list the
15
15
  whole queue in plain English and let the user pick which one(s) to process** — then route each pick
@@ -57,6 +57,7 @@ map to:
57
57
  | `revision-read` | "Read the attached drawing(s) into project **`<project>`** as a new version (+N file(s))" — the **initial** read when `baseVersion` is absent or ≤ 0, otherwise a **re-read** of a revised set | `floless-app-steel-takeoff` — but `floless-app-vectorize` when the app's lineage root (`appTemplateId`, falling back to `appId`) is `vectorize` |
58
58
  | `knowledge-organize` | "Organize the Project Knowledge Base for project **`<project>`**" | `floless-app-knowledge` |
59
59
  | `knowledge-adjust` | "Reshape the Project Knowledge Base for project **`<project>`** — *<instruction>*" | `floless-app-knowledge` |
60
+ | `knowledge-consult` | "Add a deterministic Workspace knowledge read (`kb`) and HTTP-200 gate (`gate`) to **`<appId>`**, then compile" | `floless-app-workflows` |
60
61
 
61
62
  The type union itself is `FlolessRequest` in `server/floless-store.ts` — a type in the union with no row
62
63
  above means this table is stale, and the union is right. The routing is `REQUEST_SKILL` in
@@ -2,7 +2,7 @@
2
2
  name: floless-app-workflows
3
3
  description: This skill should be used when building, modifying, or reasoning about FloLess .flo workflows for floless.app — especially reusable apps that take inputs (e.g. a phase number) and run across different Tekla models, exec nodes that run Roslyn C# against the live model, the in-app HTML Viewer, the Code tab, or "Debug in VS". Covers the exec contract, the install→validate→compile→run loop, app inputs templating, reading an approved Workspace project's data from a running workflow via the floless-workspace REST seam plus its workspace-project input picker, and the server seams (aware-adapter, app-reader, index).
4
4
  metadata:
5
- version: 0.4.0
5
+ version: 0.5.2
6
6
  ---
7
7
 
8
8
  # Building reusable .flo workflows in floless.app
@@ -316,6 +316,36 @@ Let the user **pick** the project (never type an opaque id): flag the input
316
316
  (by name, searchable) and stores the opaque id. Client-only hint, never sent to `aware`
317
317
  (like `widget: file`); optional `workspaceApp:` pre-filters to one app. See `references/workspace-data.md`.
318
318
 
319
+ ## Consult and cite the project's knowledge at run time — retrieval only
320
+
321
+ Use `floless-workspace/read-knowledge` only when a run must retrieve a project's compiled knowledge
322
+ summaries. It is not a model or an interpretation step: AWARE receives a normal REST read, and the
323
+ approved `.lock` still determines every run decision. Add `floless-workspace@0.2.x`, then use the
324
+ proven `kb → gate` pair from `demos/floless-workspace-knowledge`:
325
+
326
+ The `kb` and `gate` pair must feed the existing terminal report. A pair that is not on the terminal
327
+ report path is incomplete: it reads knowledge without making the report's provenance visible.
328
+
329
+ Let the user pick the target by name with **`widget: workspace-knowledge-project`**. The themed
330
+ picker calls `GET /api/workspace-projects` and offers only rows where `hasKnowledge` is true; it does
331
+ not use `workspace-project` or `/approved`, because model approval is unrelated to published knowledge.
332
+ Its empty state must send the user to **Organize** the project's Knowledge step, never to approve a
333
+ model.
334
+
335
+ - **Cite:** pass `kb.body.generation.generationId` and the top page slug to a downstream report so it
336
+ can say which generation/page it consulted. Both `generation` and `pages[0]` are optional on a 200:
337
+ use `{% if kb.body.generation %}…{% endif %}` and `{% if kb.body.pages %}…{% endif %}` to short-circuit
338
+ each deep reference. `default()` cannot protect an undefined path because minijinja raises while
339
+ resolving the path, before applying the filter.
340
+ - **Gate:** put `inline: { kind: predicate, code: "e.status == 200" }` immediately after the read.
341
+ Its plain-English `description:` must say it stops cleanly when the read fails and directs the user
342
+ to press **Organize** on the project's Knowledge step. A 200 with no published knowledge or no page
343
+ matching the subject is legitimate retrieval, not an excuse to invent a citation; make the report
344
+ say so honestly.
345
+
346
+ Never add an agent/LLM node, vector store, or KB-drift Run gate to this path. Interpretation belongs
347
+ at compose time; runtime knowledge may only be retrieved, cited, or deterministically gated.
348
+
319
349
  ## Author against the project's knowledge, not your priors — COMPOSE TIME
320
350
 
321
351
  The section above is the workflow reading project data **at run time**. This is a different thing:
@@ -342,6 +372,25 @@ When work is tied to a Workspace project (the user names one, or a queued reques
342
372
  3. **Bake what it says in as literal values and cite the page** in the node's plain-English
343
373
  Description ("Spacing per `shop-standard-bolts`"), so the choice is traceable to the firm's
344
374
  document rather than to you. If nothing relevant matches, say so — never invent a standard.
375
+ 4. **Record what you built from**, so the app can show it and can warn the user when that knowledge
376
+ later changes:
377
+
378
+ ```
379
+ PUT <base>/api/kb-pin/<appId>
380
+ { "projectId": "<project>",
381
+ "generationId": "<the generation.generationId the feed returned>",
382
+ "pages": [{ "slug": "shop-standard-bolts", "title": "Shop Standard Bolts" }] }
383
+ ```
384
+
385
+ Only the pages you actually relied on (at most 20). Consulting the KB and finding nothing
386
+ relevant is a normal outcome — skip the pin rather than recording an empty list.
387
+
388
+ **Send the generation id you READ, not whatever is current when you finish.** If an Organize pass
389
+ republishes the knowledge base while you are working, the generation you actually read is still
390
+ the correct thing to record, and the route accepts it — the pin is a record of what this workflow
391
+ was built from, not a claim about what is current. The app compares the two itself and tells the
392
+ user when they have diverged. Re-reading the feed to "pin the latest" would record a generation
393
+ whose contents never touched your work, which is the one failure this record exists to prevent.
345
394
 
346
395
  Compose time only: what you learn is baked into the `.flo`. A model in the run path is refused by
347
396
  AWARE (`E_APP_RUNTIME_MODEL_FORBIDDEN`) and would void "build once, run forever" — **outside the one
package/dist/web/app.css CHANGED
@@ -2,6 +2,10 @@
2
2
  /* Block 1: base tokens + full component styling */
3
3
  * { box-sizing: border-box; margin: 0; padding: 0; }
4
4
 
5
+ /* The semantic hidden state must win over every component display declaration.
6
+ Components restore their intended layout by removing the attribute. */
7
+ [hidden] { display: none !important; }
8
+
5
9
  :root {
6
10
  --bg: #070a0f;
7
11
  --surface: #0f141c;
@@ -472,7 +476,8 @@
472
476
  /* fav-bar is already opaque (surface); the notes pill stays translucent by design
473
477
  — both just need to paint ABOVE the panned content (the notes stay readable). */
474
478
  .canvas > .fav-bar,
475
- .canvas > .notes-strip { position: relative; z-index: 6; }
479
+ .canvas > .notes-strip,
480
+ .canvas > .kb-informed { position: relative; z-index: 6; }
476
481
 
477
482
  /* LINEAR */
478
483
  .topology:not(.dag) .agent-card { flex: 0 0 210px; }
@@ -1073,6 +1078,13 @@
1073
1078
  transition: all 0.15s;
1074
1079
  user-select: none;
1075
1080
  }
1081
+ button.fav-chip {
1082
+ appearance: none;
1083
+ font: inherit;
1084
+ color: inherit;
1085
+ cursor: pointer;
1086
+ }
1087
+ button.fav-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
1076
1088
  .fav-chip:hover {
1077
1089
  border-color: var(--accent);
1078
1090
  transform: translateY(-1px);
@@ -1574,6 +1586,12 @@
1574
1586
  .lib-update:hover { color: var(--accent); border-color: var(--accent); }
1575
1587
  .lib-update[aria-busy="true"] { color: var(--text-dim); border-color: var(--border-strong); cursor: default; pointer-events: none; }
1576
1588
  .lib-update .rtn-spinner { width: 11px; height: 11px; border-width: 2px; }
1589
+ /* A background update can finish long after its initiating click. Keep its reason
1590
+ with that agent card, using the existing compact slate surface and a restrained
1591
+ error edge rather than making a transient toast carry essential information. */
1592
+ .lib-update-error { margin: 4px 0 0; padding: 7px 10px; border-left: 2px solid var(--err);
1593
+ background: var(--surface-2); color: var(--text-muted); font-size: 11px; line-height: 1.45; }
1594
+ .lib-update-error strong { color: var(--err); font-weight: 600; }
1577
1595
 
1578
1596
  /* Two-tab Agent Library: the tab bar sits between title and panes; each pane is a
1579
1597
  flex column so its inner .lib-list keeps scrolling within the modal's max-height.
@@ -1803,10 +1821,8 @@
1803
1821
  Warehouse"), and uppercasing those misreads them. Long names ellipsize; the full name
1804
1822
  is on the tab's data-tip. */
1805
1823
  .req-scope { margin: 2px 0 12px; }
1806
- /* `hidden` is a no-op without this. The UA's [hidden]{display:none} loses to .tabs{display:flex}
1807
- on specificity, so `$scope.hidden = true` left the row on screen showing its UNRENDERED
1808
- markup — a blank first tab and the literal "All" placeholder from index.html — whenever there
1809
- was no scope to name (the Workspaces landing, or no workflow open). */
1824
+ /* Component-local backstop for the scope tabs; the base `[hidden]` invariant
1825
+ above is the authoritative semantic hide rule. */
1810
1826
  .req-scope[hidden] { display: none; }
1811
1827
  /* The tab is a flex row, NOT one ellipsizing line, because the count is the trailing child:
1812
1828
  `text-overflow: ellipsis` clips the END, so a long project name would truncate away the very
@@ -1993,14 +2009,8 @@
1993
2009
  /* The split: ▶ runs with the current default, ▾ opens the options form. Two buttons sharing one
1994
2010
  silhouette via joined radii — a real menu popover would need outside-click, focus trapping and
1995
2011
  its own scroll container for two decisions a themed form already asks better. */
1996
- /* [hidden] LOSES TO A CLASS THAT SETS display, and this file has no global `[hidden]` rule — a
1997
- trap this repo has now been caught by six times. Without these three, `$split.hidden = true`
1998
- is a NO-OP: the queued-request modal's one caller queues a `revision-read`, which the run
1999
- policy refuses, so "▶ Run it for me" painted on the one surface it could never work from —
2000
- worse than a disabled control, because it looks live. `.request-help-steps` is pre-existing
2001
- but only became a TOGGLED element in this change, and it is the other half: without it the
2002
- modal shows "Paste the copied instructions" beside "Running in Claude Code". Found by review,
2003
- invisible to any assertion that reads `.hidden` rather than computed style. */
2012
+ /* Component-local backstops retained for the request-help state machine; the
2013
+ base `[hidden]` invariant above protects every future display declaration too. */
2004
2014
  .run-split[hidden],
2005
2015
  .request-help-run-status[hidden],
2006
2016
  .request-help-steps[hidden] { display: none; }
@@ -3141,6 +3151,54 @@ body {
3141
3151
  /* Collapsed → faint single line; the whole row re-expands on click. */
3142
3152
  .notes-strip.collapsed { background: transparent; border-color: color-mix(in srgb, var(--info) 18%, transparent); cursor: pointer; }
3143
3153
  .notes-strip.collapsed ul { display: none; }
3154
+
3155
+ /* "Informed by …" — which of the firm's own knowledge built this workflow.
3156
+ Box model borrowed from .notes-strip above (same margin/padding/radius, so the two stack as one
3157
+ family) but NEUTRAL, not info-tinted: the notes strip's blue/amber/red ladder means "the compiler
3158
+ has something to say about your nodes", and wearing that costume would make provenance read as a
3159
+ compiler warning about the topology. This is quiet baseline metadata. */
3160
+ .kb-informed {
3161
+ margin: 8px 12px 0;
3162
+ padding: 6px 12px;
3163
+ border: 1px solid var(--border-strong);
3164
+ background: var(--surface-2);
3165
+ border-radius: 6px;
3166
+ color: var(--text-muted);
3167
+ font-size: 12px;
3168
+ line-height: 1.6;
3169
+ /* Wraps rather than scrolls. A pin cites a handful of pages in practice (20 is the store's hard
3170
+ cap, not the shape), so a scroll container would be chrome for a case that does not happen. */
3171
+ display: flex;
3172
+ flex-wrap: wrap;
3173
+ align-items: center;
3174
+ gap: 6px 10px;
3175
+ }
3176
+ .kb-informed[hidden] { display: none; } /* the flex display would otherwise defeat [hidden] */
3177
+ .kb-informed-label { color: var(--text-dim); flex: none; }
3178
+ .kb-informed-pages { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
3179
+ /* A real <button>, so the global button:focus-visible ring already covers keyboard focus. */
3180
+ .kb-page-link {
3181
+ background: none; border: none; padding: 0;
3182
+ font: inherit; color: var(--accent); cursor: pointer;
3183
+ display: inline-flex; align-items: baseline; gap: 3px;
3184
+ }
3185
+ .kb-page-link:hover { color: var(--accent-bright, var(--accent)); text-decoration: underline; }
3186
+ .kb-page-link .kb-page-ico { font-size: 10px; opacity: 0.7; }
3187
+ .kb-informed-sep { color: var(--text-dim); }
3188
+ /* Mirrors .wf-forked-pill's recipe exactly: amber, informational, not a fault. Sits over the canvas,
3189
+ a panel away from the header's run-state pill, so the two ambers never read as one state. */
3190
+ .kb-drift-chip {
3191
+ border: 1px solid var(--warn);
3192
+ background: rgba(251, 191, 36, 0.08);
3193
+ color: var(--warn);
3194
+ font-size: 10px;
3195
+ padding: 1px 8px;
3196
+ border-radius: 999px;
3197
+ line-height: 1.5;
3198
+ white-space: nowrap;
3199
+ cursor: default;
3200
+ }
3201
+ .kb-drift-chip:not([hidden]) { display: inline-flex; align-items: center; }
3144
3202
  .notes-strip.collapsed .notes-head { color: var(--text-dim); margin-bottom: 0; }
3145
3203
  .notes-strip.collapsed .notes-dismiss { display: none; }
3146
3204
  .notes-strip.collapsed .notes-title::after { content: " — show"; color: var(--text-dim); font-weight: 400; }
@@ -4090,7 +4148,7 @@ body.mode-workspaces #menu .menu-item[data-action="graft"],
4090
4148
  body.mode-workspaces #menu .menu-item[data-action="bake"] { display:none; }
4091
4149
  .app.mode-workspaces .topology, .app.mode-workspaces .canvas-toolbar,
4092
4150
  .app.mode-workspaces .hint, .app.mode-workspaces .fav-bar, .app.mode-workspaces .dashboard,
4093
- .app.mode-workspaces .notes-strip, .app.mode-workspaces .find-overlay,
4151
+ .app.mode-workspaces .notes-strip, .app.mode-workspaces .kb-informed, .app.mode-workspaces .find-overlay,
4094
4152
  .app.mode-workspaces #canvas-drop-target, .app.mode-workspaces #wf-templates-stats,
4095
4153
  /* the ws surfaces carry their own headings — hide the canvas's "Canvas · transparency layer" label */
4096
4154
  .app.mode-workspaces .canvas > .panel-label { display:none !important; }
package/dist/web/aware.js CHANGED
@@ -16,6 +16,9 @@
16
16
  const $simBtn = document.getElementById('sim-btn');
17
17
  const $runState = document.getElementById('run-state');
18
18
  const $notesStrip = document.getElementById('notes-strip');
19
+ const $kbInformed = document.getElementById('kb-informed');
20
+ const $kbInformedPages = document.getElementById('kb-informed-pages');
21
+ const $kbDriftChip = document.getElementById('kb-drift-chip');
19
22
  const $reportModal = document.getElementById('report-modal');
20
23
  const $reportFrame = document.getElementById('report-frame');
21
24
  const $reportFrame3d = document.getElementById('report-frame-3d');
@@ -627,6 +630,72 @@
627
630
  }
628
631
  }
629
632
 
633
+ // ── "Informed by" — which knowledge built this workflow ────────────────────
634
+ //
635
+ // WORKFLOW-LEVEL, not per node. The pin the server keeps is app-scoped — a project, a knowledge
636
+ // generation, and the pages that were cited — with no node granularity, so rendering it under each
637
+ // node's Description would repeat one identical list down the Inspect panel while implying each
638
+ // node had its own sources. Attribution that fine needs the AI to report which page informed which
639
+ // node, which is a different record than the one that exists. (Decided with Pawel, 2026-08-10.)
640
+ //
641
+ // Never blocks Run, and that is deliberate: the determinism gate is the `.flo`↔`.lock` pair, and
642
+ // treating stale knowledge as the same class of problem would make a workflow that runs perfectly
643
+ // well look broken. Say it, don't block it.
644
+ let kbPinRead = 0;
645
+
646
+ /** Paint the strip, or hide it outright. No pin → nothing at all: not a disabled control, not an
647
+ * "unknown" row. Most workflows were never built against a knowledge base, and that is ordinary. */
648
+ function paintKbInformed(pin, drift) {
649
+ if (!$kbInformed) return;
650
+ if (!pin || !pin.pages || !pin.pages.length) {
651
+ $kbInformed.hidden = true;
652
+ $kbInformedPages.innerHTML = '';
653
+ delete $kbInformed.dataset.kbProject;
654
+ return;
655
+ }
656
+ // The pin's own project, so the click handler opens the KB that actually informed this workflow
657
+ // rather than whichever project Workspaces happens to have open.
658
+ $kbInformed.dataset.kbProject = String(pin.projectId || '');
659
+ // Every value here is file-derived (a wiki page's own slug and title) and lands in innerHTML, so
660
+ // it is escaped exactly like the node/agent strings in buildAgentEntry above.
661
+ $kbInformedPages.innerHTML = pin.pages.map((pg, i) => {
662
+ const slug = String(pg.slug || '');
663
+ // The TITLE reads as a sentence; the slug reads as a filename. The slug still rides the tooltip
664
+ // so a user can trace the citation back to the page as the KB names it. `|| slug` rather than a
665
+ // humanizer: a title is always present in a well-formed pin, and inventing prose from a slug
666
+ // would be guessing at the one place this feature must not guess.
667
+ const label = String(pg.title || slug);
668
+ const sep = i ? '<span class="kb-informed-sep">·</span>' : '';
669
+ return `${sep}<button type="button" class="kb-page-link" data-kb-slug="${escapeAttr(slug)}"`
670
+ + ` data-tip="Open “${escapeAttr(label)}” (${escapeAttr(slug)}) in the Knowledge Base"`
671
+ // The visible label alone does not say this leaves Workflows, and `data-tip` is a purely
672
+ // VISUAL tooltip (web/app.js wires no aria-describedby), so the full action goes in an
673
+ // aria-label or a screen-reader user loses it entirely.
674
+ + ` aria-label="Open ${escapeAttr(label)} in the Knowledge Base">`
675
+ + `<span class="kb-page-ico" aria-hidden="true">↗</span>${escapeHtml(label)}</button>`;
676
+ }).join('');
677
+ $kbDriftChip.hidden = !drift;
678
+ $kbInformed.hidden = false;
679
+ }
680
+
681
+ /** Read the pin for `id`. Guarded by a read counter, not by the response: the user can switch
682
+ * workflows while this is in flight, and a late answer must never paint another workflow's
683
+ * provenance over the one now on screen. A failed read hides the strip rather than guessing. */
684
+ async function refreshKbInformed(id) {
685
+ const read = ++kbPinRead;
686
+ paintKbInformed(null, false); // clear the previous workflow's row before the await, not after
687
+ if (!id) return;
688
+ try {
689
+ const r = await fetch(`/api/kb-pin/${encodeURIComponent(id)}`, { cache: 'no-store' });
690
+ const d = await r.json();
691
+ if (read !== kbPinRead || currentId !== id) return; // superseded — a newer workflow owns the strip
692
+ if (r.ok && d.ok) paintKbInformed(d.pin, !!d.drift);
693
+ } catch {
694
+ /* Offline or a route that isn't there: provenance is additive, so its absence is not an error
695
+ the user needs told about. The strip stays hidden, cleared above. */
696
+ }
697
+ }
698
+
630
699
  function paintModes() {
631
700
  document.querySelectorAll('.agent-card').forEach((card) => {
632
701
  const a = AGENTS[card.dataset.agentId];
@@ -981,6 +1050,9 @@
981
1050
  // publication clears, rather than keeping the previous answer forever.
982
1051
  await commitPublicationAvailability(id, read, contractState);
983
1052
  currentId = id;
1053
+ // The Templates strip also carries app-scoped quick actions. Templates may have
1054
+ // loaded before this app did, so repaint it once the ownership boundary is known.
1055
+ renderFavBar();
984
1056
  try { localStorage.setItem(LS_LAST_APP, id); } catch { /* private mode / quota */ }
985
1057
  transform(app);
986
1058
  liveTrace.length = 0;
@@ -997,6 +1069,7 @@
997
1069
  seedAppInputs(app);
998
1070
  markSpecialNodes();
999
1071
  paintGate(app);
1072
+ refreshKbInformed(id); // detached: provenance is additive, and must not hold up the canvas paint
1000
1073
  paintBeacon(app); // pulse "Start here" while this workflow is new to the user
1001
1074
  refreshDirtyIndicator(); // clean app → dot off; switched back to a dirty one → dot on
1002
1075
  renderWfUpdatePill(); // show the "↑ Update to vX" pill when THIS app has a newer published version
@@ -1033,6 +1106,18 @@
1033
1106
  return waitForPublicationAvailabilityIdle();
1034
1107
  }
1035
1108
 
1109
+ // Workspaces keeps the existing workflow selected underneath its project surface. Returning to
1110
+ // Workflows is therefore a re-open of that workflow: refresh both its publication state and the
1111
+ // additive provenance strip, so a KB organize that happened while the project was open cannot
1112
+ // leave a stale "Informed by" answer on the canvas.
1113
+ function refreshCurrentWorkflow() {
1114
+ const id = currentId;
1115
+ return Promise.all([
1116
+ refreshCurrentWorkflowAvailability(),
1117
+ refreshKbInformed(id),
1118
+ ]).then(() => {});
1119
+ }
1120
+
1036
1121
  async function loadApps() {
1037
1122
  // …and mean it: the trigger said "loading…" but stayed CLICKABLE, so a click during the fetch
1038
1123
  // opened the popover onto an empty #wf-list — the exact "picker opens and stays empty, it never
@@ -1060,6 +1145,8 @@
1060
1145
  // don't also raise the warn-coloured notes strip (it's for real compiler
1061
1146
  // notes, and a yellow band for a neutral first-run reads as a false alarm).
1062
1147
  $notesStrip.hidden = true;
1148
+ currentId = null;
1149
+ refreshKbInformed(null); // invalidate any in-flight app read and remove workflow-only provenance
1063
1150
  $runBtn.disabled = true;
1064
1151
  $compileBtn.disabled = true;
1065
1152
  if ($menuBakeItem) $menuBakeItem.disabled = true;
@@ -2320,6 +2407,17 @@
2320
2407
  } catch { return []; }
2321
2408
  }
2322
2409
 
2410
+ // Knowledge reads are scoped by a published knowledge base, never by a model approval. Keep this
2411
+ // separate from `workspace-project`: approval answers whether a model is runnable, while this
2412
+ // picker answers whether the project has knowledge the read-knowledge node can consult.
2413
+ async function fetchKnowledgeProjects() {
2414
+ try {
2415
+ const r = await fetch('/api/workspace-projects');
2416
+ const j = await r.json().catch(() => null);
2417
+ return j && j.ok && Array.isArray(j.projects) ? j.projects.filter((p) => p && p.hasKnowledge === true) : [];
2418
+ } catch { return []; }
2419
+ }
2420
+
2323
2421
  // Double-click the input node → styled dialog to set the declared inputs. Writes
2324
2422
  // to appInputValues; the header "▶ Run workflow" uses them. No native window.prompt.
2325
2423
  async function openInputsDialog() {
@@ -2328,6 +2426,7 @@
2328
2426
  const cur = currentInputs();
2329
2427
  const isVisual = (inp) => inp.widget === 'file' || inp.type === 'image' || inp.type === 'file';
2330
2428
  const isProject = (inp) => inp.widget === 'workspace-project';
2429
+ const isKnowledgeProject = (inp) => inp.widget === 'workspace-knowledge-project';
2331
2430
  const visualNames = new Set(app.inputs.filter(isVisual).map((i) => i.name));
2332
2431
  // A project-picker input needs the live list of approved projects. Fetch ONE list per DISTINCT
2333
2432
  // `workspaceApp` filter and let the SERVER decide what matches, rather than fetching everything
@@ -2344,6 +2443,7 @@
2344
2443
  .map((i) => (typeof i.workspaceApp === 'string' && i.workspaceApp ? i.workspaceApp : '')))];
2345
2444
  const approvedByFilter = new Map();
2346
2445
  for (const f of projectFilters) approvedByFilter.set(f, await fetchApprovedProjects(f || undefined));
2446
+ const knowledgeProjects = app.inputs.some(isKnowledgeProject) ? await fetchKnowledgeProjects() : [];
2347
2447
  const fields = app.inputs.map((inp) => {
2348
2448
  if (isVisual(inp)) return {
2349
2449
  name: inp.name,
@@ -2375,6 +2475,26 @@
2375
2475
  emptyNote: 'No approved projects yet — open <strong>Workspaces</strong>, create a project, and Approve it to use it here.',
2376
2476
  };
2377
2477
  }
2478
+ if (isKnowledgeProject(inp)) {
2479
+ const options = knowledgeProjects
2480
+ .slice().sort((a, b) => String(a.name).localeCompare(String(b.name)))
2481
+ .map((p) => ({
2482
+ value: p.id,
2483
+ meta: `${appLabel(p.templateId || p.app)} · Knowledge published`,
2484
+ label: p.name,
2485
+ search: `${p.name} ${p.id} ${p.app} ${appLabel(p.templateId || p.app)}`,
2486
+ }));
2487
+ return {
2488
+ name: inp.name,
2489
+ label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
2490
+ type: 'select',
2491
+ options,
2492
+ value: cur[inp.name] != null ? cur[inp.name] : '',
2493
+ placeholder: 'Select a project with knowledge…',
2494
+ disabledLabel: 'No project knowledge yet',
2495
+ emptyNote: 'No Workspace project has published knowledge yet — open <strong>Workspaces</strong>, choose a project, and Organize its Knowledge step before running this workflow.',
2496
+ };
2497
+ }
2378
2498
  return {
2379
2499
  name: inp.name,
2380
2500
  label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
@@ -6506,6 +6626,10 @@
6506
6626
  if (typeof m.appId !== 'string' || m.appId === currentId) {
6507
6627
  refreshCurrentWorkflowAvailability().catch(reportErr);
6508
6628
  }
6629
+ } else if (m.type === 'kb-pin-changed' && m.id === currentId && !inWorkspacesMode()) {
6630
+ // The event is only an invalidation. Re-read the workflow-scoped pin so the server remains
6631
+ // the source of truth; refresh clears first and its epoch rejects any older response.
6632
+ refreshKbInformed(currentId);
6509
6633
  } else if (m.type === 'trace' && m.id === currentId) {
6510
6634
  pushTrace(m.event);
6511
6635
  if (state.currentTab === 'execution') renderInspect();
@@ -6548,6 +6672,7 @@
6548
6672
  const isUpdate = m.action === 'update';
6549
6673
  installingIds.delete(m.id);
6550
6674
  if (m.ok) {
6675
+ if (isUpdate) agentUpdateFailures.delete(m.id);
6551
6676
  if (isUpdate) {
6552
6677
  showToast(`Updated “${m.id}”`, 'ok');
6553
6678
  } else {
@@ -6587,7 +6712,12 @@
6587
6712
  importFailedOfferRetry();
6588
6713
  });
6589
6714
  } else {
6590
- showToast(`${isUpdate ? 'Update' : 'Install'} failed: ${String(m.error || '').slice(0, 80)}`, 'err');
6715
+ if (isUpdate) {
6716
+ agentUpdateFailures.set(m.id, String(m.error || `Could not update ${m.id}.`));
6717
+ showToast(`Could not update ${m.id} — see the card for details.`, 'err');
6718
+ } else {
6719
+ showToast(`Could not install ${m.id}: ${String(m.error || '').slice(0, 120)}`, 'err');
6720
+ }
6591
6721
  if (_importFailedVersions.has(m.id)) {
6592
6722
  // A failed update is NOT the "nothing to update" answer — say which it was, and re-arm the
6593
6723
  // row's own button so the user can try that one again without redoing the others.
@@ -6800,20 +6930,40 @@
6800
6930
  catch (e) { reportErr(e); }
6801
6931
  }
6802
6932
 
6933
+ async function requestKnowledgeConsult() {
6934
+ const app = currentId && apps.get(currentId);
6935
+ // A maintained workflow is form-only until the user explicitly forks it. Hide the affordance in
6936
+ // renderFavBar in that state, and retain this guard so a stale DOM click cannot queue a logic edit.
6937
+ if (!app || (app.publisher === 'floless' && !app.forked)) return;
6938
+ try {
6939
+ const { request } = await api('/api/knowledge-consult', { method: 'POST', body: JSON.stringify({ appId: app.id }) });
6940
+ const copied = await copyToClipboard(markedInstruction(request));
6941
+ appendNarration(`Queued a deterministic <code>kb → gate</code> knowledge read for <code>${escapeHtml(app.id)}</code> — your terminal AI will add it. Choose the project and subject, then compile.${copied ? ' The instruction is on your clipboard.' : ''}`);
6942
+ showToast(copied ? 'Knowledge read + gate queued · copied to clipboard' : 'Knowledge read + gate queued', 'ok');
6943
+ loadRequests();
6944
+ } catch (e) { reportErr(e); }
6945
+ }
6946
+
6803
6947
  // Template chips: click = "use in this app" (reverse channel); × = delete.
6804
6948
  renderFavBar = function renderFavBarTpl() {
6949
+ const app = currentId && apps.get(currentId);
6950
+ const canConsultKnowledge = !!app && !(app.publisher === 'floless' && !app.forked);
6805
6951
  const tpls = state.favorites;
6806
6952
  $favCount.textContent = tpls.length;
6807
- if (!tpls.length) { $favChipRow.innerHTML = ''; $favBarEmpty.style.display = 'block'; return; }
6808
- $favBarEmpty.style.display = 'none';
6809
- $favChipRow.innerHTML = tpls.map((t) => `
6953
+ $favBarEmpty.style.display = tpls.length ? 'none' : 'block';
6954
+ $favChipRow.innerHTML = (canConsultKnowledge
6955
+ ? `<button type="button" class="fav-chip knowledge-consult" data-knowledge-consult data-tip="Add a knowledge read and deterministic gate to this workflow. Choose the project and subject before compiling."><span class="cat">ADD</span><span class="name">Consult knowledge</span></button>`
6956
+ : '') + tpls.map((t) => `
6810
6957
  <div class="fav-chip" data-tpl="${escapeAttr(t.id)}" data-tip="Click to use · ${escapeAttr(t.category)} · ${escapeAttr((t.node.agent || t.node.kind) + (t.node.command ? '/' + t.node.command : ''))}">
6811
6958
  <span class="cat">${escapeHtml(t.category)}</span>
6812
6959
  <span class="name">${escapeHtml(t.name)}</span>
6813
6960
  <span class="edit" data-tip="Rename / recategorize" aria-label="Edit template">✎</span>
6814
6961
  <span class="del" data-tip="Delete template" aria-label="Delete template">×</span>
6815
6962
  </div>`).join('');
6963
+ const consult = $favChipRow.querySelector('[data-knowledge-consult]');
6964
+ if (consult) consult.onclick = requestKnowledgeConsult;
6816
6965
  $favChipRow.querySelectorAll('.fav-chip').forEach((chip) => {
6966
+ if (chip.dataset.knowledgeConsult !== undefined) return;
6817
6967
  const id = chip.dataset.tpl;
6818
6968
  chip.onclick = (e) => { if (e.target.closest('.del') || e.target.closest('.edit')) return; useTemplate(id); };
6819
6969
  chip.querySelector('.edit').onclick = (e) => { e.stopPropagation(); openEditTemplate(id); };
@@ -7287,7 +7437,7 @@
7287
7437
  }
7288
7438
 
7289
7439
  function requestLabel(r) {
7290
- 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';
7440
+ 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 === 'knowledge-consult' ? 'knowledge' : r.type === 'tweak-contract' ? 'contract' : 'tweak';
7291
7441
  }
7292
7442
 
7293
7443
  // Escape `text`, wrapping every case-insensitive occurrence of `q` in <mark>. Splits the RAW
@@ -7774,6 +7924,10 @@
7774
7924
  // not disabled, when up to date. A pull in flight shows a spinner instead.
7775
7925
  const latest = availableLoaded ? latestVersionFor(a.id) : null;
7776
7926
  const canUpdate = !!latest && cmpVer(latest, a.version) > 0;
7927
+ const failure = agentUpdateFailures.get(a.id);
7928
+ const failureHtml = failure
7929
+ ? `<p class="lib-update-error"><strong>Update stopped.</strong> ${escapeHtml(failure)} <button class="lib-update" data-update="${id}" aria-label="Retry update for ${id}" data-tip="Retry update for ${id}">Retry</button></p>`
7930
+ : '';
7777
7931
  const updateBtn = installingIds.has(a.id)
7778
7932
  ? `<button class="lib-update" aria-busy="true" aria-label="Updating ${escapeAttr(a.id)}…" data-tip="Downloading update from the registry — this can take a minute"><span class="rtn-spinner"></span></button>`
7779
7933
  : canUpdate
@@ -7791,6 +7945,7 @@
7791
7945
  <button class="lib-fav" data-expand="${id}" data-tip="Show commands">⌄</button>
7792
7946
  </div>
7793
7947
  </div>
7948
+ ${failureHtml}
7794
7949
  <div class="lib-commands" id="cmds-${id}" hidden></div>
7795
7950
  </div>`;
7796
7951
  }).join('') || '<div class="empty-state">No agents match.</div>';
@@ -7870,6 +8025,10 @@
7870
8025
  let availableUnsupported = false; // CLI too old to know `agent catalog`
7871
8026
  let libTab = 'installed';
7872
8027
  const installingIds = new Set(); // ids with an install in flight (server runs it async)
8028
+ // A failed background update must stay visible on its originating card after
8029
+ // renderLibrary() restores the button. A toast alone disappears before someone
8030
+ // can read the reason or decide whether retrying is appropriate.
8031
+ const agentUpdateFailures = new Map(); // id -> safe, user-facing failure reason
7873
8032
 
7874
8033
  async function loadAvailableAgents() {
7875
8034
  const { agents, unsupported } = await api('/api/agents/available');
@@ -8010,6 +8169,8 @@
8010
8169
  function updateAgent(id, btn, onStartError) {
8011
8170
  if (installingIds.has(id)) return; // already in flight (server dedupes too)
8012
8171
  installingIds.add(id);
8172
+ agentUpdateFailures.delete(id);
8173
+ if ($libModal && $libModal.classList.contains('show') && libTab === 'installed') renderLibrary();
8013
8174
  if (btn) { // immediate feedback before the next render
8014
8175
  btn.setAttribute('aria-busy', 'true');
8015
8176
  btn.setAttribute('aria-label', `Updating ${id}…`);
@@ -9213,6 +9374,23 @@
9213
9374
  if (id && sig) saveNotesCollapsed(id, sig, $notesStrip.classList.contains('collapsed'));
9214
9375
  });
9215
9376
 
9377
+ // "Informed by" → open that page in the Knowledge Base. Delegated, since the row is rebuilt on
9378
+ // every workflow open. The viewer lives in workspaces.js's own closure, so this hands off through
9379
+ // the one seam it publishes — and degrades to a toast if that seam is absent, because the two files
9380
+ // are separate IIFEs and nothing guarantees load order at this callsite.
9381
+ if ($kbInformedPages) $kbInformedPages.addEventListener('click', (e) => {
9382
+ const btn = e.target.closest('[data-kb-slug]');
9383
+ if (!btn) return;
9384
+ const ws = window.flolessWorkspaces;
9385
+ if (!ws || typeof ws.openKnowledgePage !== 'function') {
9386
+ showToast('Open the project’s Knowledge step to read this page.', 'warn');
9387
+ return;
9388
+ }
9389
+ // The pin's OWN projectId, stashed on the row when it was painted — never a guess about which
9390
+ // project is "current" in the other mode.
9391
+ ws.openKnowledgePage($kbInformed.dataset.kbProject, btn.dataset.kbSlug);
9392
+ });
9393
+
9216
9394
  // Take over the menu/keyboard Save from app.js's demo stub: in the real app the
9217
9395
  // UI can't author the .flo (that's the terminal AI's job), so "Save" persists the
9218
9396
  // current workflow's input values locally. "Save to…" (demo .flo download) is
@@ -9516,7 +9694,12 @@
9516
9694
  if ($rm && $rm.classList.contains('show')) renderRequests();
9517
9695
  },
9518
9696
  refreshCurrentWorkflow() {
9519
- return refreshCurrentWorkflowAvailability();
9697
+ return refreshCurrentWorkflow();
9698
+ },
9699
+ // Workspaces is a replacement surface. Invalidate a pending workflow-pin read as soon as it
9700
+ // opens, rather than allowing a late answer to survive behind the project UI until the return.
9701
+ clearKbInformed() {
9702
+ refreshKbInformed(null);
9520
9703
  },
9521
9704
  copyToClipboard,
9522
9705
  instructionFor,
@@ -159,6 +159,18 @@
159
159
  <button class="find-close" id="find-close" data-tip="Close">×</button>
160
160
  </div>
161
161
  <div class="notes-strip" id="notes-strip" hidden></div>
162
+ <!-- Which of the firm's own knowledge this workflow was built from, and whether it has changed
163
+ since. Deliberately NOT in the header beside the run-state pill: that pill's "Needs refresh"
164
+ state is amber and means Run is blocked, and a second amber chip inches away saying the
165
+ knowledge moved would read as the same kind of problem. Knowledge drift never blocks Run.
166
+ Hidden outright when the workflow was never built against a knowledge base — which is most
167
+ of them, and is a normal state rather than something to render an empty row about. -->
168
+ <div class="kb-informed" id="kb-informed" hidden>
169
+ <span class="kb-informed-label">Informed by</span>
170
+ <span class="kb-informed-pages" id="kb-informed-pages"></span>
171
+ <span class="kb-drift-chip" id="kb-drift-chip" role="status" hidden
172
+ data-tip="Re-approving isn’t required — this workflow still runs as it is. But the Knowledge Base has changed since these pages were read, so double-check any values that came from them.">Knowledge Base updated since this was built</span>
173
+ </div>
162
174
  <div class="topology" id="topology"></div>
163
175
  <div class="canvas-toolbar">
164
176
  <div class="toolbar-group">