@floless/app 0.161.0 → 0.162.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.
@@ -5473,7 +5473,7 @@
5473
5473
  * Two points matter. Drawing-first creation opens the project before its read is queued, so the
5474
5474
  * lifecycle probe commonly caches `absent`; gating on `filter-checkpoint` left the two competing
5475
5475
  * status bands standing in the most ordinary path there is. But an unresolved (`unknown`)
5476
- * lifecycle un-gates every tab, so the strip paints nothing — and retiring against that would
5476
+ * lifecycle un-gates every tab, so without live progress the strip paints nothing — and retiring against that would
5477
5477
  * leave the user with no status at all. Asking the strip itself settles both without a second
5478
5478
  * predicate that has to be kept in agreement with `stageGateFor`.
5479
5479
  */
@@ -5846,7 +5846,7 @@
5846
5846
  review.dataset.commandId = 'shell.revision-filter-open';
5847
5847
  review.setAttribute('data-tip', 'Focus the Drawing Filter below');
5848
5848
  actions.appendChild(review);
5849
- $stageGuidance.appendChild(actions);
5849
+ ($stageGuidance.querySelector('#ws-stage-guidance-body') || $stageGuidance).appendChild(actions);
5850
5850
  markScrollable($stageGuidance);
5851
5851
  }
5852
5852
 
@@ -5943,23 +5943,75 @@
5943
5943
  /**
5944
5944
  * Avoid re-announcing unchanged progress every time the three-second request poll repaints.
5945
5945
  *
5946
- * The bounded visible region is named and becomes keyboard-scrollable when needed. Its prose is
5947
- * mirrored into the one established live region so progress changes are announced only once.
5946
+ * The bounded visible region is named and becomes keyboard-scrollable when needed. A separate
5947
+ * concise live region announces status changes; complete details remain readable on expansion.
5948
5948
  */
5949
- function paintStageGuidance(content, state = 'info') {
5949
+ function paintStageGuidance(content, state = 'info', projectId = null) {
5950
5950
  if (!$stageGuidance) return;
5951
5951
  // Only a real projection may take the progress path. Any other object would render `undefined`
5952
5952
  // into the heading with no throw and no log, which is the failure this surface exists to remove.
5953
5953
  const progress = content && typeof content === 'object' && !Array.isArray(content)
5954
5954
  && typeof content.heading === 'string' && typeof content.state === 'string'
5955
5955
  && Number.isSafeInteger(content.doneCount) ? content : null;
5956
- const key = progress
5956
+ // Presentation belongs to a project in this window, not to a polling revision or a read stage.
5957
+ // A fresh window starts expanded; switching away and back keeps the person's choice.
5958
+ const scope = projectId ?? (typeof current !== 'undefined' && current ? current.id : '');
5959
+ const choices = $stageGuidance._collapseChoices ||= new Map();
5960
+ const key = `${scope}:` + (progress
5957
5961
  ? `progress:${progress.requestId}:${progress.state}:${progress.revision}:${progress.heading}`
5958
- : `text:${state}:${typeof content === 'string' ? content : ''}`;
5962
+ : `text:${state}:${typeof content === 'string' ? content : ''}`);
5959
5963
  $stageGuidance.hidden = false;
5960
5964
  if ($stageGuidance._renderKey === key) return;
5961
5965
  $stageGuidance._renderKey = key;
5962
5966
  $stageGuidance.className = `ws-stage-guidance state-${progress ? progress.state : state}`;
5967
+ const restoreToggleFocus = document.activeElement?.matches?.('.wsg-toggle');
5968
+ let compactAnnouncement = '';
5969
+ const mountToggle = () => {
5970
+ const body = document.createElement('div');
5971
+ body.id = 'ws-stage-guidance-body';
5972
+ while ($stageGuidance.firstChild) body.appendChild($stageGuidance.firstChild);
5973
+ $stageGuidance.appendChild(body);
5974
+ const toolbar = document.createElement('div');
5975
+ toolbar.className = 'wsg-toolbar';
5976
+ const summary = document.createElement('span');
5977
+ summary.className = 'wsg-compact';
5978
+ summary.setAttribute('aria-hidden', 'true');
5979
+ if (progress) {
5980
+ const title = document.createElement('strong');
5981
+ title.textContent = progress.heading;
5982
+ summary.append(title);
5983
+ for (const [label, text] of [
5984
+ [progress.nowLabel || 'Now', progress.now], ['Heads up', progress.caution],
5985
+ ['Done', progress.done], ['Next', progress.next],
5986
+ ]) {
5987
+ if (!text) continue;
5988
+ const highlight = document.createElement('b');
5989
+ highlight.className = 'wsg-compact-label';
5990
+ highlight.textContent = ` · ${label}: `;
5991
+ summary.append(highlight, document.createTextNode(text));
5992
+ }
5993
+ } else summary.textContent = typeof content === 'string' ? content : '';
5994
+ const toggle = document.createElement('button');
5995
+ toggle.type = 'button';
5996
+ toggle.className = 'wsg-toggle';
5997
+ toggle.dataset.commandId = 'shell.workspace-progress-toggle';
5998
+ toggle.setAttribute('aria-controls', body.id);
5999
+ const apply = () => {
6000
+ const collapsed = choices.get(scope) === true;
6001
+ $stageGuidance.classList.toggle('is-collapsed', collapsed);
6002
+ toggle.textContent = collapsed ? 'Expand' : 'Collapse';
6003
+ toggle.setAttribute('aria-label', `${collapsed ? 'Expand' : 'Collapse'} drawing read progress`);
6004
+ toggle.setAttribute('aria-expanded', String(!collapsed));
6005
+ toggle.setAttribute('data-tip', collapsed ? 'Show full drawing read progress' : 'Keep drawing read progress on one line');
6006
+ if (live && live.textContent !== compactAnnouncement) live.textContent = compactAnnouncement;
6007
+ markScrollable($stageGuidance);
6008
+ };
6009
+ toggle.addEventListener('click', () => { choices.set(scope, choices.get(scope) !== true); apply(); });
6010
+ toolbar.append(summary, toggle);
6011
+ $stageGuidance.prepend(toolbar);
6012
+ apply();
6013
+ if (restoreToggleFocus) toggle.focus();
6014
+ };
5963
6015
  let live = document.getElementById('ws-stage-guidance-live');
5964
6016
  if (!live) {
5965
6017
  live = document.createElement('span');
@@ -5974,18 +6026,17 @@
5974
6026
  // Only a string is guidance. Coercing an object here would paint the literal `[object Object]`
5975
6027
  // into the strip with no throw and no log.
5976
6028
  const text = typeof content === 'string' ? content : '';
5977
- if (live) live.textContent = text;
6029
+ compactAnnouncement = text.length > 200 ? `${text.slice(0, 199)}…` : text;
5978
6030
  const visible = document.createElement('span');
5979
- visible.setAttribute('aria-hidden', 'true');
5980
6031
  visible.textContent = text;
5981
6032
  $stageGuidance.replaceChildren(visible);
6033
+ mountToggle();
5982
6034
  markScrollable($stageGuidance);
5983
6035
  return;
5984
6036
  }
5985
6037
 
5986
6038
  const head = document.createElement('div');
5987
6039
  head.className = 'wsg-head';
5988
- head.setAttribute('aria-hidden', 'true');
5989
6040
  const signal = document.createElement('span');
5990
6041
  signal.className = 'wsg-signal';
5991
6042
  signal.setAttribute('aria-hidden', 'true');
@@ -6003,7 +6054,6 @@
6003
6054
 
6004
6055
  const details = document.createElement('div');
6005
6056
  details.className = 'wsg-details';
6006
- details.setAttribute('aria-hidden', 'true');
6007
6057
  details.appendChild(stageGuidanceRow('Done', progress.done));
6008
6058
  if (progress.now) details.appendChild(stageGuidanceRow(progress.nowLabel, progress.now));
6009
6059
  if (progress.caution) details.appendChild(stageGuidanceRow('Heads up', progress.caution));
@@ -6011,24 +6061,25 @@
6011
6061
 
6012
6062
  const instant = new Date(progress.updatedAt);
6013
6063
  const updatedText = `Updated ${instant.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`;
6014
- if (live) live.textContent = [
6015
- progress.heading,
6016
- `${progress.doneCount} check${progress.doneCount === 1 ? '' : 's'} complete`,
6017
- `Done: ${progress.done}`,
6064
+ // The full panel stays readable separately. The established live region announces only the
6065
+ // current status, action and warnings, in either mode, without replaying history and the clock.
6066
+ compactAnnouncement = [progress.heading, `${progress.doneCount} check${progress.doneCount === 1 ? '' : 's'} complete`,
6018
6067
  progress.now ? `${progress.nowLabel}: ${progress.now}` : '',
6019
6068
  progress.caution ? `Heads up: ${progress.caution}` : '',
6020
6069
  progress.next ? `Next: ${progress.next}` : '',
6021
- updatedText,
6022
- ].filter(Boolean).map((part) => (/[.!?]$/.test(part) ? part : `${part}.`)).join(' ').trim();
6070
+ ].filter(Boolean).map((part) => {
6071
+ const bounded = part.length > 200 ? `${part.slice(0, 199)}…` : part;
6072
+ return /[.!?…]$/.test(bounded) ? bounded : `${bounded}.`;
6073
+ }).join(' ');
6023
6074
 
6024
6075
  // Server summaries are prose and usually end in a full stop already. Joining with another one
6025
6076
  // makes a screen reader read "confirmed dot dot", so only unpunctuated segments get a stop.
6026
6077
  const updated = document.createElement('time');
6027
6078
  updated.className = 'wsg-updated';
6028
- updated.setAttribute('aria-hidden', 'true');
6029
6079
  updated.dateTime = progress.updatedAt;
6030
6080
  updated.textContent = updatedText;
6031
6081
  $stageGuidance.replaceChildren(head, activity, details, updated);
6082
+ mountToggle();
6032
6083
  markScrollable($stageGuidance);
6033
6084
  }
6034
6085
 
@@ -6160,10 +6211,6 @@
6160
6211
  const stagedInitial = initialRead && lastRevState === 'staged';
6161
6212
  const failedInitial = initialRead && lastRevState === 'failed';
6162
6213
  const unavailableInitial = initialRead && lastRevState === 'unavailable';
6163
- if (!locked && !stripPending) {
6164
- clearStageGuidance();
6165
- return;
6166
- }
6167
6214
  const ownsProgress = waitingForInitial && stageGuidanceOwnsSavedCheckpoint(revCardReq);
6168
6215
  const liveProgress = ownsProgress ? drawingProgressView(revCardReq, Date.now(), revRequestsFailed) : null;
6169
6216
  if (ownsProgress && revCardReq?.steelProgress && !liveProgress) {
@@ -6186,6 +6233,12 @@
6186
6233
  paintStageGuidance(liveProgress);
6187
6234
  return;
6188
6235
  }
6236
+ // Saving the Filter can unlock the tabs while its initial drawing read is still running.
6237
+ // Progress belongs to that read, not to the prerequisite gate; only idle guidance needs a gate.
6238
+ if (!locked && !stripPending) {
6239
+ clearStageGuidance();
6240
+ return;
6241
+ }
6189
6242
  // An unfinished Filter save (being written, waiting on its confirmation, refused, needing a reload,
6190
6243
  // or never pressed) outranks every sentence below — the one they would otherwise show here is "The
6191
6244
  // Drawing Filter is saved" (#1781). Live progress above still wins: a read already running works from
@@ -7409,6 +7462,21 @@
7409
7462
  // A state label, distinct from an interrupted attempt's "ended safely"; the notice says what and why.
7410
7463
  $approvalSub.textContent = 'The approval was refused';
7411
7464
  $approvalConfirm.focus();
7465
+ if (typeof bridge !== 'undefined' && typeof bridge.reviewWorkflowUpdate === 'function'
7466
+ && /E_APP_AGENT_PIN_UNSATISFIED/.test(refusal.technical || '')) void offerApprovalWorkflowUpdate(project, st);
7467
+ }
7468
+
7469
+ /** Offer the same scoped update review after a known source/tool mismatch; never repeat the approval. */
7470
+ async function offerApprovalWorkflowUpdate(project, dialogState) {
7471
+ try {
7472
+ const inventory = await api('/api/workflows/updates');
7473
+ const offer = (inventory.updates || []).find((item) => item.id === project.app);
7474
+ if (!offer || approvalDialogState !== dialogState || dialogState.phase !== 'abandoned') return;
7475
+ const notice = $approvalBody.querySelector('[data-approval-refusal]');
7476
+ if (!notice) return;
7477
+ notice.insertAdjacentHTML('beforeend', '<p>A bundled workflow update may resolve this tool mismatch. Updating does not approve your model. Afterwards return here to Review and approve.</p>'
7478
+ + `<div class="approval-notice-actions"><button type="button" class="btn-mini" data-approval-workflow-update data-command-id="shell.workflow-update#approval:${escapeAttr(project.id)}:${escapeAttr(project.app)}" data-command-instance-label="${escapeAttr(project.name || project.app)}">Review workflow update</button></div>`);
7479
+ } catch { /* Keep the original refusal and its actionable AI Chat/report guidance if inventory is unavailable. */ }
7412
7480
  }
7413
7481
 
7414
7482
  /** "Check again" on a result FloLess could not read yet: reads it again, never sends a second approval. */
@@ -7795,6 +7863,12 @@
7795
7863
  return;
7796
7864
  }
7797
7865
  if (event.target.closest('[data-approval-check-again]')) { checkApprovalAgain(); return; }
7866
+ if (event.target.closest('[data-approval-workflow-update]') && approvalDialogState && approvalDismissible(approvalDialogState.phase)) {
7867
+ const appId = current?.app;
7868
+ closeApprovalReview();
7869
+ if (appId) bridge.reviewWorkflowUpdate(appId).catch((error) => showToast(error.message, 'warn'));
7870
+ return;
7871
+ }
7798
7872
  const openAudit = event.target.closest('[data-approval-open-audit]');
7799
7873
  if (openAudit && approvalDialogState && approvalDismissible(approvalDialogState.phase)) {
7800
7874
  // #1840: show the findings themselves. Nothing is approved; the review can be reopened.
@@ -7940,8 +8014,8 @@
7940
8014
 
7941
8015
  // ── Knowledge step (Slice 8 Stage B) ──────────────────────────────────────────
7942
8016
  // The per-project Knowledge Base, References column: drop references → per-source useAsKb
7943
- // toggle → remove → Organize. The UI NEVER parses a source or edits the wiki — Organize queues a
7944
- // `knowledge-organize` Request that the terminal AI drains with the floless-app-knowledge skill
8017
+ // toggle → remove → Organize. The UI NEVER parses a source or edits the wiki — Organize hands a
8018
+ // `knowledge-organize` task to project AI Chat with the floless-app-knowledge skill
7945
8019
  // (start → compile into the server-minted wikiDir → finish). Routes: server/knowledge-routes.ts.
7946
8020
  // The graph + note columns are Stage C/D; their area shows a forthcoming placeholder.
7947
8021
  //
@@ -7985,6 +8059,22 @@
7985
8059
  let kbAdjustBusy = null; // project id of an in-flight Adjust submit (or null) — scoped to the
7986
8060
  // project so switching away can't strand another project's box; also the
7987
8061
  // re-entry guard (no duplicate queue). See kbAdjustActive.
8062
+ let kbOrganizeBusy = null;
8063
+ let kbLastTaskAnnouncement = '';
8064
+ const kbSubmissionKey = (projectId, kind) => `floless:knowledge-submit:${projectId}:${kind}`;
8065
+ function kbSubmissionId(projectId, kind, prompt = '') {
8066
+ const key = kbSubmissionKey(projectId, kind);
8067
+ try {
8068
+ const prior = JSON.parse(sessionStorage.getItem(key) || 'null');
8069
+ if (prior?.id && prior.prompt === prompt) return prior.id;
8070
+ } catch { /* a fresh submission can still be deduplicated by the server */ }
8071
+ const id = crypto.randomUUID();
8072
+ try { sessionStorage.setItem(key, JSON.stringify({ id, prompt })); } catch { /* private mode */ }
8073
+ return id;
8074
+ }
8075
+ function kbSubmissionDone(projectId, kind) {
8076
+ try { sessionStorage.removeItem(kbSubmissionKey(projectId, kind)); } catch { /* private mode */ }
8077
+ }
7988
8078
 
7989
8079
  const kbUrl = (id, tail = '') => `/api/projects/${encodeURIComponent(id)}/knowledge${tail}`;
7990
8080
  const kbRawUrl = (id, sourceId) => kbUrl(id, `/sources/${encodeURIComponent(sourceId)}/raw`);
@@ -8038,6 +8128,7 @@
8038
8128
 
8039
8129
  /** Leaving the project or the step: close the viewer and drop every cache. */
8040
8130
  function kbResetViewer() {
8131
+ kbLastTaskAnnouncement = '';
8041
8132
  setViewer({ mode: 'graph', sourceId: null });
8042
8133
  lastRefsHtml = null;
8043
8134
  kbFocusSourceId = null;
@@ -8085,9 +8176,10 @@
8085
8176
  sources: Array.isArray(manifest.sources) ? manifest.sources : [],
8086
8177
  currentGeneration: status.currentGeneration || null,
8087
8178
  organize: status.organize || null,
8179
+ handoff: status.handoff || null,
8088
8180
  // #2491 R6.9: the person's categories and where each reference sits.
8089
8181
  categories: status.categories || { v: 1, revision: 0, categories: [], placements: {}, state: 'absent' },
8090
- queued: list.filter((r) => r && r.type === 'knowledge-organize' && r.project === proj.id),
8182
+ queued: status.pendingRequests || list.filter((r) => r && r.type === 'knowledge-organize' && r.project === proj.id),
8091
8183
  company,
8092
8184
  designSet,
8093
8185
  };
@@ -8095,10 +8187,12 @@
8095
8187
 
8096
8188
  // Pending = started (organize.json, has startedAt) OR merely queued (a request, has createdAt).
8097
8189
  function kbPending(st) {
8098
- if (st.organize) return { started: true, since: Date.parse(st.organize.startedAt) };
8099
- const q = st.queued[0];
8190
+ if (st.organize) return { started: true, since: Date.parse(st.organize.startedAt), handoff: (st.queued || []).find((r) => r.id === st.organize.requestId)?.handoff || st.handoff || null };
8191
+ const q = (st.queued || []).find((r) => r.type === 'knowledge-organize');
8100
8192
  // id: which queued request Cancel deletes; wait (#2131): its start met work already changing the project.
8101
- if (q) return { started: false, since: Date.parse(q.createdAt), id: q.id, wait: q.organizeWait || null };
8193
+ if (q) return { started: false, since: Date.parse(q.createdAt), id: q.id, wait: q.organizeWait || null,
8194
+ retryable: q.knowledgeChat?.state !== 'accepted',
8195
+ handoff: q.handoff || (st.handoff?.requestId === q.id ? st.handoff : q.knowledgeChat || null) };
8102
8196
  return null;
8103
8197
  }
8104
8198
  const kbAgo = (ms) => {
@@ -8343,7 +8437,8 @@
8343
8437
  const files = issue.files || [];
8344
8438
  const active = files.filter((f) => !f.withdrawn).length;
8345
8439
  const date = issue.issuedOn ? `<span class="kb-ds-date">${escapeHtml(issue.issuedOn)}</span>` : '';
8346
- const count = `${active} file${active === 1 ? '' : 's'}${active !== files.length ? ` of ${files.length}` : ''}`;
8440
+ const selected = files.filter((f) => (st.sources || []).some((s) => s.sourceId === f.sourceId && s.blobSha256 === f.blobSha256 && s.useAsKb)).length;
8441
+ const count = `${active} file${active === 1 ? '' : 's'}${active !== files.length ? ` of ${files.length}` : ''} · ${selected} for Organize`;
8347
8442
  const chips = (issue.current ? '<span class="kb-chip run">Current</span>' : '') + (issue.withdrawn ? '<span class="kb-chip kb-chip-wd">Withdrawn</span>' : '');
8348
8443
  const all = kbDsShowAll.has(issue.issueId);
8349
8444
  const shown = all ? files : files.slice(0, KB_DS_FILES_SHOWN);
@@ -8376,8 +8471,8 @@
8376
8471
  '</div>';
8377
8472
  return `<details class="kb-ds-issue${issue.current ? ' current' : ''}${issue.withdrawn ? ' wd' : ''}" data-kb-ds-issue-id="${id}"${open ? ' open' : ''}>` +
8378
8473
  `<summary class="kb-ds-sum" data-command-id="shell.kb-design-issue-open"><span class="kb-adjust-caret" aria-hidden="true">▸</span>` +
8379
- `<span class="kb-ds-line1"><span class="kb-ds-label">${escapeHtml(issue.label)}</span>${date}<span class="kb-ds-count">${escapeHtml(count)}</span></span>` +
8380
- (chips ? `<span class="kb-ds-line2">${chips}</span>` : '') + '</summary>' +
8474
+ `<span class="kb-ds-line1"><span class="kb-ds-label">${escapeHtml(issue.label)}</span>${date}</span>` +
8475
+ `<span class="kb-ds-line2"><span class="kb-ds-count">${escapeHtml(count)}</span>${chips}</span></summary>` +
8381
8476
  '<div class="kb-ds-body">' +
8382
8477
  (origin ? `<div class="kb-ds-origin">${escapeHtml(origin)}</div>` : '') + warnings +
8383
8478
  `<ul class="kb-ds-files" role="list">${shown.map((f) => kbIssueFileRow(f, issue, st)).join('')}</ul>${more}` +
@@ -8442,7 +8537,7 @@
8442
8537
  const recordWarnings = (ds.warnings || []).filter((w) => !w.issueId).map((w) =>
8443
8538
  `<div class="kb-ds-warn-line" role="status"><span class="kb-ds-bang" aria-hidden="true">!</span><span>${escapeHtml(w.message)}</span></div>`).join('');
8444
8539
  return `<section class="kb-src kb-ds${ds.status === 'changed' ? ' changed' : ''}" role="region" aria-labelledby="kb-ds-title">` +
8445
- head(add) + '<div class="kb-ds-sub">Each issue is one release of the drawings.</div>' + recordWarnings +
8540
+ head(add) + `<div class="kb-ds-sub">Each issue is one release of the drawings. ${st.sources.filter((s) => kbInDesignSet(s, st)).length} source files · included in Organize only when switched on.</div>` + recordWarnings +
8446
8541
  kbAddIssuePanel(st) + body + '</section>';
8447
8542
  }
8448
8543
 
@@ -9094,8 +9189,7 @@
9094
9189
  const pending = kbPending(st);
9095
9190
  const gen = st.currentGeneration;
9096
9191
 
9097
- // Queued ≠ running. Only a `started` pass (organize.json exists) may claim to be organizing;
9098
- // before that the terminal AI hasn't picked the request up yet, so no spinner.
9192
+ // Accepted by Chat is distinct from the server lifecycle actually starting to organize.
9099
9193
  let pendingLine = '';
9100
9194
  if (pending) {
9101
9195
  const age = kbAgo(Date.now() - pending.since);
@@ -9107,25 +9201,43 @@
9107
9201
  const lead = pending.started
9108
9202
  ? `Organizing…${age ? ` started ${escapeHtml(age)}` : ''}`
9109
9203
  : pending.wait ? kbWaitLead(pending.wait)
9110
- : `Queued for your terminal AI — waiting to start…${age ? ` (${escapeHtml(age)})` : ''}`;
9204
+ : pending.handoff?.error ? escapeHtml(pending.handoff.error)
9205
+ : pending.handoff?.state === 'legacy-active' ? 'An earlier organization task is still active. Follow it with the AI that started it.'
9206
+ : pending.handoff?.chatId ? 'Organization sent to this project’s AI Chat — waiting to start…'
9207
+ : 'Organization is waiting for AI Chat. Use Retry handoff to send this saved task.';
9111
9208
  // A queued organize (not yet started) can be cancelled — at that point there is no organize lock
9112
9209
  // to strand, so this is the immediate, user-initiated escape from a button wedged by an organize
9113
9210
  // no terminal AI drains (the 24h TTL sweep is the automatic backstop). It sits INSIDE the text
9114
9211
  // span, flowing like a trailing word: the rail is too narrow to pin a separate control beside text
9115
9212
  // that may wrap. Never offered once started — a running pass is lifecycle-owned (its finish/fail
9116
9213
  // clears it), and the guarded DELETE route refuses it (409) anyway.
9117
- const cancel = (!pending.started && pending.id)
9118
- ? ` <button type="button" class="kb-pending-cancel" data-kb-cancel-organize="${escapeAttr(pending.id)}" data-tip="Cancel — you can queue a new organize anytime">Cancel</button>`
9214
+ const cancel = (!pending.started && pending.id && (!pending.handoff || pending.handoff.state === 'legacy-pending' || pending.handoff.canCancel))
9215
+ ? ` <button type="button" class="kb-pending-cancel" data-kb-cancel-organize="${escapeAttr(pending.id)}" data-command-id="shell.kb-organize-cancel" data-tip="Cancel this saved organization task">Cancel</button>`
9119
9216
  : '';
9217
+ const chat = pending.handoff?.chatId
9218
+ ? ` <button type="button" class="kb-pending-cancel" data-kb-open-chat="${escapeAttr(pending.handoff.chatId)}" data-command-id="shell.kb-open-chat">Open chat</button>` : '';
9219
+ const retry = !pending.started && pending.retryable && pending.handoff?.state !== 'legacy-active' && (!pending.handoff?.chatId || pending.handoff.error)
9220
+ ? ' <button type="button" class="kb-pending-cancel" data-kb-retry-handoff data-command-id="shell.kb-retry-handoff">Retry handoff</button>' : '';
9120
9221
  pendingLine = `<div class="${cls}">${ico}<span>${lead}` +
9121
- (stale ? ' <span class="kb-stale">taking longer than expected — check your terminal AI is running.</span>' : '') +
9122
- cancel + '</span></div>';
9222
+ (stale ? ' <span class="kb-stale">Taking longer than expected — check AI Chat.</span>' : '') +
9223
+ chat + retry + cancel + '</span></div>';
9123
9224
  }
9124
9225
 
9226
+ const adjustment = (st.queued || []).find((r) => r.type === 'knowledge-adjust');
9227
+ const adjustmentHandoff = adjustment && (adjustment.handoff || (st.handoff?.requestId === adjustment.id ? st.handoff : adjustment.knowledgeChat));
9228
+ if (!pending && adjustment) {
9229
+ pendingLine = '<div class="kb-pending queued"><span>' +
9230
+ escapeHtml(adjustmentHandoff?.error || 'Adjustment saved for this project’s AI Chat.') +
9231
+ (adjustmentHandoff?.chatId ? ` <button type="button" class="kb-pending-cancel" data-kb-open-chat="${escapeAttr(adjustmentHandoff.chatId)}" data-command-id="shell.kb-open-chat">Open chat</button>` : '') +
9232
+ (adjustment.knowledgeChat?.state !== 'accepted' && (adjustmentHandoff?.error || !adjustmentHandoff?.chatId) ? ' <button type="button" class="kb-pending-cancel" data-kb-retry-adjustment data-command-id="shell.kb-retry-adjustment">Retry handoff</button>' : '') +
9233
+ '</span></div>';
9234
+ }
9125
9235
  let status;
9126
9236
  if (st.sources.some((s) => s.state === 'error')) status = '<span class="err">✕ last organize failed</span>';
9127
9237
  else if (gen) {
9238
+ const fresh = st.sources.filter((s) => s.useAsKb && s.state !== 'organized').length;
9128
9239
  status = `<span class="ok">✓ organized</span> · ${escapeHtml(kbAgo(Date.now() - Date.parse(gen.publishedAt)))}` +
9240
+ (fresh ? ` · ${fresh} selected reference${fresh === 1 ? '' : 's'} await organization` : '') +
9129
9241
  (st.manifest.lastLintSummary ? ` · ${escapeHtml(st.manifest.lastLintSummary)}` : '');
9130
9242
  } else if (pending) status = ''; // the pending line already narrates it — never invite a press on the (correctly) disabled Organize
9131
9243
  else status = st.sources.length ? 'Not yet organized — press Organize when you’re ready.' : '';
@@ -9137,30 +9249,26 @@
9137
9249
  // tooltip actually fires; the click handler no-ops on it.
9138
9250
  // The label stays plain "Organize": a pass is a FULL recompile from the truth set, so "Organize
9139
9251
  // new" would misdescribe it.
9140
- const why = pending ? 'An organize is already queued for your terminal AI'
9141
- : !st.sources.length ? 'Drop a reference above to get started'
9252
+ const why = kbOrganizeBusy === current?.id ? 'Sending organization to AI Chat'
9253
+ : pending ? 'An organization task is already saved for this project'
9254
+ : !st.sources.length ? 'Add a reference below the list to get started'
9142
9255
  : enabled === 0 ? 'Turn on at least one reference to organize'
9143
- : 'Queue an organize — your terminal AI compiles these references into this project’s wiki';
9144
- const off = !!pending || enabled === 0 || !st.sources.length;
9256
+ : 'Send the selected references to this project’s AI Chat to create knowledge summaries';
9257
+ const off = !!pending || kbOrganizeBusy === current?.id || enabled === 0 || !st.sources.length;
9145
9258
  const organizeBtn = `<button type="button" class="primary kb-organize" id="kb-organize"` +
9146
- `${off ? ' aria-disabled="true"' : ''} data-tip="${escapeAttr(why)}">✦ Organize</button>`;
9147
-
9148
- // Adjust: steer the compiled wiki in plain English. Only once a wiki exists (you can't reshape what
9149
- // hasn't been compiled). Queues a knowledge-adjust request the terminal AI applies — the UI never
9150
- // edits the wiki. A queued adjust is invisible to /status by design, so its ONLY pending signal is the
9151
- // footer Requests counter; nothing here fakes per-request progress. The textarea always renders empty
9152
- // and the submit disabled — the live draft/enabled state and the in-flight "Queuing…" state are
9153
- // DOM-owned and never repainted away, because paintKnowledge suppresses the refs repaint while the box
9154
- // is active (kbAdjustActive), so what the user is typing in / submitting is never swapped out.
9259
+ ` data-command-id="shell.kb-organize"${off ? ` aria-disabled="true" data-blocked-reason="${escapeAttr(why)}"` : ''} data-tip="${escapeAttr(why)}">✦ Organize</button>`;
9260
+
9261
+ // Adjust uses the same project Chat handoff. The draft stays DOM-owned while the box is active,
9262
+ // so polling cannot erase the person's instruction or move the caret during submission.
9155
9263
  const adjustBox = gen
9156
9264
  ? '<details class="kb-adjust">' +
9157
- '<summary class="kb-adjust-summary"><span class="kb-adjust-caret" aria-hidden="true">▸</span>Adjust the wiki</summary>' +
9265
+ '<summary class="kb-adjust-summary" data-command-id="shell.kb-adjust-open"><span class="kb-adjust-caret" aria-hidden="true">▸</span>Adjust summaries</summary>' +
9158
9266
  '<div class="kb-adjust-body">' +
9159
- '<label class="kb-adjust-label" for="kb-adjust-input">Tell your terminal AI what to change</label>' +
9160
- '<textarea id="kb-adjust-input" class="kb-adjust-input" rows="2" maxlength="2000" placeholder="e.g. “Merge the two RFI pages”"></textarea>' +
9267
+ '<label class="kb-adjust-label" for="kb-adjust-input">Tell AI Chat what to change</label>' +
9268
+ '<textarea id="kb-adjust-input" class="kb-adjust-input" data-command-id="shell.kb-adjust-input" rows="2" maxlength="2000" placeholder="e.g. “Merge the two RFI pages”"></textarea>' +
9161
9269
  '<div class="kb-adjust-foot">' +
9162
- '<span class="kb-adjust-hint">Queues an instruction — your terminal AI edits the wiki notes, then re-organizes.</span>' +
9163
- '<button type="button" class="primary kb-adjust-submit" id="kb-adjust-submit" aria-disabled="true" data-tip="Type an instruction first">✎ Adjust</button>' +
9270
+ '<span class="kb-adjust-hint">Sends this adjustment to the project’s AI Chat.</span>' +
9271
+ '<button type="button" class="primary kb-adjust-submit" id="kb-adjust-submit" data-command-id="shell.kb-adjust-submit" aria-disabled="true" data-blocked-reason="Type an instruction first" data-tip="Type an instruction first">✎ Adjust</button>' +
9164
9272
  '</div>' +
9165
9273
  '</div>' +
9166
9274
  '</details>'
@@ -9217,11 +9325,25 @@
9217
9325
  function kbGraphTruncatedEmpty() { return '<section class="kb-col kb-placeholder"><div class="kb-ph-inner"><span class="kb-ph-ico" aria-hidden="true">✦</span><div class="kb-ph-title">Graph incomplete</div><div class="kb-ph-sub">Some knowledge pages couldn’t be loaded, so the graph is incomplete and nothing could be shown. Click a file on the left to preview it.</div></div></section>'; }
9218
9326
  function kbGraphEmpty(st) {
9219
9327
  const done = st && st.currentGeneration;
9328
+ const sources = st?.sources || [];
9329
+ const enabled = sources.filter((s) => s.useAsKb).length;
9330
+ const pending = st && kbPending(st);
9331
+ const handoffFailed = pending?.handoff?.error;
9332
+ const failed = sources.some((s) => s.state === 'error');
9333
+ const title = done ? 'Nothing to graph yet' : handoffFailed ? 'Organization needs attention' : pending?.started ? 'Organizing your references' : pending ? 'Organization is pending'
9334
+ : failed ? 'Organization didn’t finish' : sources.length ? 'Your reference files are here' : 'Add reference files';
9335
+ const sub = done ? 'This project’s references are organized, but their pages aren’t linked to each other yet. Click a file on the left to preview it.'
9336
+ : handoffFailed ? (pending.retryable ? 'Your files are kept. Use Retry handoff, or open AI Chat to see what happened.' : 'Your files are kept. Open AI Chat to see what happened and continue the saved task.')
9337
+ : pending?.handoff?.state === 'legacy-active' ? 'An earlier organization task is still active. Follow it with the AI that started it. Your files are kept.'
9338
+ : pending?.started ? 'Your AI is creating knowledge summaries from the selected references. You can preview your files while you wait.'
9339
+ : pending ? (pending.handoff?.chatId ? 'Follow the organization task in this project’s AI Chat. You can preview your files while you wait.' : 'Your organization task is saved. Use Retry handoff to send it to AI Chat. You can preview your files now.')
9340
+ : failed ? 'Your files are kept. Use Organize to try again, or open AI Chat to see what happened.'
9341
+ : enabled ? `Organize the ${enabled} selected reference${enabled === 1 ? '' : 's'} to create browsable knowledge summaries. You can preview any file now.`
9342
+ : sources.length ? 'Turn on references to include them in Organize. Design-set files are not included automatically. You can preview any file now.'
9343
+ : 'Add files below the references list, then choose which ones to organize.';
9220
9344
  return '<section class="kb-col kb-placeholder"><div class="kb-ph-inner"><span class="kb-ph-ico" aria-hidden="true">✦</span>' +
9221
- '<div class="kb-ph-title">' + (done ? 'Nothing to graph yet' : 'No knowledge base yet') + '</div>' +
9222
- '<div class="kb-ph-sub">' + (done
9223
- ? 'This project’s references are organized, but their pages aren’t linked to each other yet. Click a file on the left to preview it.'
9224
- : 'No knowledge base yet — add references and Organize to build one. Click a file on the left to preview it in the meantime.') + '</div></div></section>';
9345
+ '<div class="kb-ph-title">' + title + '</div>' +
9346
+ '<div class="kb-ph-sub">' + escapeHtml(sub) + '</div></div></section>';
9225
9347
  }
9226
9348
  // loading + error REUSE the file viewer's own message idiom (.kb-view-msg / .kb-view-spin /
9227
9349
  // .kb-view-ico.err / .primary Retry) so the graph's "can't show content yet" states look identical
@@ -9999,10 +10121,9 @@
9999
10121
  }
10000
10122
 
10001
10123
  function kbColumn(st) {
10002
- // #2399 slice 0c: a file of an issue is listed under its issue, not again here; the list says how many went there.
10124
+ // One collection: issued drawings, reference groups, then upload. Presentation never changes membership.
10003
10125
  const loose = st.sources.filter((source) => !kbInDesignSet(source, st));
10004
10126
  const inSet = st.sources.length - loose.length;
10005
- const jump = inSet ? `<button type="button" class="kb-link kb-ds-jump" data-kb-ds-jump data-command-id="shell.kb-design-set-jump" data-tip="Go to the Design set">${inSet} more in the design set</button>` : '';
10006
10127
  // #2491 R6.9: once the first category exists the list is a tree; until then it is exactly the flat list, plus a way to
10007
10128
  // make one. A categories file that cannot be read shows every reference flat and says so.
10008
10129
  kbSelFor(current, st);
@@ -10010,15 +10131,17 @@
10010
10131
  const newCat = kbCatUsable(st) && loose.length && !(kbCatEdit && kbCatEdit.mode === 'new' && !kbCatEdit.parentId)
10011
10132
  ? '<button type="button" class="kb-link kb-cat-new" data-kb-cat-new data-command-id="shell.kb-category-new" data-tip="Group references into categories">+ New category</button>' : '';
10012
10133
  const flatEdit = !tree && kbCatEdit && kbCatEdit.mode === 'new' ? kbCatEditHtml(0) : '';
10013
- const body = kbCatUnavailableHtml(st) + (loose.length
10014
- ? (tree ? kbTreeHtml(st, loose) : flatEdit + loose.map((source) => kbSourceRow(source, st)).join(''))
10015
- : (inSet ? '' : '<div class="kb-empty">No references yet — drop files above (PDF, Word, Excel, email, pictures or text), or ask your terminal AI to add them.</div>')) + newCat + jump + kbSelBarHtml(st);
10134
+ const body = '<div class="kb-reference-head"><h3>Reference files</h3>' + newCat + '</div>' +
10135
+ kbCatUnavailableHtml(st) + (loose.length
10136
+ ? (tree ? kbTreeHtml(st, loose) : flatEdit + '<h4 class="kb-uncategorized-head">Uncategorized references</h4>' + loose.map((source) => kbSourceRow(source, st)).join(''))
10137
+ : '<div class="kb-empty">' + (inSet ? 'Other reference files will appear here. Drawings are listed in the Design set above.' : 'No references added yet. Add files below to get started.') + '</div>') + kbSelBarHtml(st);
10138
+ const selected = st.sources.filter((s) => s.useAsKb).length;
10016
10139
  return '<section class="kb-col">' +
10017
- '<div class="kb-refs-body">' + kbDesignSetStrip(st) +
10140
+ '<div class="kb-refs-body">' + `<div class="kb-source-summary">${st.sources.length} source${st.sources.length === 1 ? '' : 's'} · ${selected} selected for Organize</div>` + kbDesignSetStrip(st) + body +
10018
10141
  '<button type="button" class="kb-drop" id="kb-drop" data-command-id="shell.add-knowledge" data-tip="Drop PDF, Word, Excel, email (.msg, .eml), picture or text files here, or click to pick them">' +
10019
10142
  '<span class="di" aria-hidden="true">⤓</span><span class="dt">Drop references here</span>' +
10020
10143
  '<span class="ds">PDF · Word · Excel · email · images · text</span>' +
10021
- '</button>' + body +
10144
+ '</button>' +
10022
10145
  '</div>' + kbFoot(st) + '</section>';
10023
10146
  }
10024
10147
 
@@ -10210,7 +10333,9 @@
10210
10333
  const gen = viewer.mode === 'graph' && st.currentGeneration ? st.currentGeneration.generationId : '';
10211
10334
  // The text state too (#2491): a Word, Excel or email file whose text lands while it is open repaints with it.
10212
10335
  const text = row && row.text ? `${row.text.state}:${row.text.blobSha256 || ''}` : '';
10213
- return [current && current.id, viewer.mode, viewer.sourceId || '', row ? row.blobSha256 : '', text, gen].join('|');
10336
+ const emptyState = viewer.mode === 'graph' && !st.currentGeneration
10337
+ ? JSON.stringify([st.sources.map((s) => [s.sourceId, s.useAsKb, s.state]), kbPending(st)]) : '';
10338
+ return [current && current.id, viewer.mode, viewer.sourceId || '', row ? row.blobSha256 : '', text, gen, emptyState].join('|');
10214
10339
  }
10215
10340
 
10216
10341
  function paintKnowledge(st) {
@@ -10219,6 +10344,10 @@
10219
10344
  setViewer({ mode: 'graph', sourceId: null });
10220
10345
  }
10221
10346
  kbEnsureShell();
10347
+ const task = kbPending(st);
10348
+ const announcement = task?.handoff?.error || (task?.started ? 'AI Chat is organizing your references.'
10349
+ : task ? 'Organization is waiting to start.' : st.handoff?.error || (st.handoff?.state === 'completed' ? 'Knowledge task completed.' : ''));
10350
+ if (announcement !== kbLastTaskAnnouncement) { kbLastTaskAnnouncement = announcement; if (announcement) kbAnnounce(announcement); }
10222
10351
  kbPaintStepHead(st); // the source count lives up there now, so it tracks the same state
10223
10352
  const refsHost = $wsKnowledge.querySelector('.kb-refs-host');
10224
10353
  const viewHost = kbViewHost();
@@ -10235,10 +10364,12 @@
10235
10364
  if (html !== lastRefsHtml && !kbAdjustActive() && !kbDsPanelBusy() && !kbCatEditActive() && !kbDragIds && !kbDragHover) {
10236
10365
  const oldBody = refsHost.querySelector('.kb-refs-body');
10237
10366
  const scrollTop = oldBody ? oldBody.scrollTop : 0;
10367
+ const focusedCommand = refsHost.contains(document.activeElement) ? document.activeElement?.getAttribute('data-command-id') : null;
10238
10368
  refsHost.innerHTML = html;
10239
10369
  lastRefsHtml = html;
10240
10370
  const newBody = refsHost.querySelector('.kb-refs-body');
10241
10371
  if (newBody) newBody.scrollTop = scrollTop;
10372
+ if (focusedCommand) Array.from(refsHost.querySelectorAll('[data-command-id]')).find((el) => el.getAttribute('data-command-id') === focusedCommand)?.focus({ preventScroll: true });
10242
10373
  // Selecting a row changes its HTML (it gains aria-current), so the repaint destroys the very
10243
10374
  // button the user just clicked. Put focus back — but only when a handler asked for it, never on
10244
10375
  // a poll tick, which must not steal focus.
@@ -10925,18 +11056,42 @@
10925
11056
 
10926
11057
  async function kbOrganize() {
10927
11058
  const proj = current;
10928
- if (!proj) return;
11059
+ if (!proj || kbOrganizeBusy) return;
11060
+ kbOrganizeBusy = proj.id;
11061
+ const button = $wsKnowledge.querySelector('#kb-organize');
11062
+ if (button) { button.setAttribute('aria-disabled', 'true'); button.setAttribute('data-blocked-reason', 'Sending organization to AI Chat'); }
10929
11063
  try {
10930
- await api(kbUrl(proj.id, '/organize'), { method: 'POST', body: '{}' });
11064
+ const result = await api(kbUrl(proj.id, '/organize'), { method: 'POST', body: JSON.stringify({ clientSubmissionId: kbSubmissionId(proj.id, 'organize') }) });
11065
+ kbSubmissionDone(proj.id, 'organize');
10931
11066
  // Refresh the footer Requests counter in THIS tab — there is no server `request-added`
10932
11067
  // broadcast, so nothing else would move the badge.
10933
11068
  if (bridge.loadRequests) await bridge.loadRequests();
10934
- showToast('Organize queued for your terminal AI', 'ok');
11069
+ showToast(result.handoff?.error || (result.handoff?.state === 'legacy-active'
11070
+ ? 'An earlier organization task is still active. Its work has been kept.'
11071
+ : result.handoff?.chatId ? 'Organization sent to this project’s AI Chat' : 'Organization saved. Retry handoff to send it to AI Chat.'), result.handoff?.error ? 'warn' : 'ok');
11072
+ if (current?.id === proj.id && result.handoff?.chatId && bridge.openChatConversation) await bridge.openChatConversation(result.handoff.chatId);
10935
11073
  track('kb_organize_queued', { app: proj.app });
10936
- } catch { showToast('Couldn’t queue Knowledge organization. Try again.', 'warn'); }
11074
+ } catch { showToast('Couldn’t confirm delivery to AI Chat. Retry Organize to check the same task; your files are kept.', 'warn'); }
11075
+ finally { kbOrganizeBusy = null; }
10937
11076
  if (current === proj) renderKnowledge();
10938
11077
  }
10939
11078
 
11079
+ async function kbRetryAdjustment() {
11080
+ const proj = current;
11081
+ const saved = knowledgeState?.queued?.find((r) => r.type === 'knowledge-adjust');
11082
+ if (!proj || !saved?.instruction || kbAdjustBusy) return;
11083
+ kbAdjustBusy = proj.id;
11084
+ try {
11085
+ const result = await api(kbUrl(proj.id, '/request'), { method: 'POST', body: JSON.stringify({
11086
+ prompt: saved.instruction, clientSubmissionId: kbSubmissionId(proj.id, 'adjust', saved.instruction),
11087
+ }) });
11088
+ if (!result.handoff?.error) kbSubmissionDone(proj.id, 'adjust');
11089
+ showToast(result.handoff?.error || 'Adjustment sent to this project’s AI Chat', result.handoff?.error ? 'warn' : 'ok');
11090
+ if (current?.id === proj.id && result.handoff?.chatId && bridge.openChatConversation) await bridge.openChatConversation(result.handoff.chatId);
11091
+ } catch { showToast('Couldn’t confirm the adjustment handoff. The saved task is kept; try again.', 'warn'); }
11092
+ finally { kbAdjustBusy = null; if (current?.id === proj.id) renderKnowledge(); }
11093
+ }
11094
+
10940
11095
  // Cancel a QUEUED (not-yet-started) organize via its GUARDED lifecycle route — the immediate,
10941
11096
  // user-initiated escape from an Organize button wedged by an organize no terminal AI drained (the
10942
11097
  // server-side 24h TTL sweep is the automatic backstop). The SERVER decides safety atomically: it
@@ -10979,8 +11134,8 @@
10979
11134
  const ta = $wsKnowledge.querySelector('#kb-adjust-input');
10980
11135
  const btn = $wsKnowledge.querySelector('#kb-adjust-submit');
10981
11136
  if (!ta || !btn) return;
10982
- if (ta.value.trim()) { btn.removeAttribute('aria-disabled'); btn.setAttribute('data-tip', 'Queue this adjustment for your terminal AI'); }
10983
- else { btn.setAttribute('aria-disabled', 'true'); btn.setAttribute('data-tip', 'Type an instruction first'); }
11137
+ if (ta.value.trim()) { btn.removeAttribute('aria-disabled'); btn.removeAttribute('data-blocked-reason'); btn.setAttribute('data-tip', 'Send this adjustment to the project’s AI Chat'); }
11138
+ else { btn.setAttribute('aria-disabled', 'true'); btn.setAttribute('data-blocked-reason', 'Type an instruction first'); btn.setAttribute('data-tip', 'Type an instruction first'); }
10984
11139
  }
10985
11140
 
10986
11141
  async function kbAdjustSubmit() {
@@ -11002,9 +11157,12 @@
11002
11157
  kbAdjustBusy = proj.id;
11003
11158
  ta.disabled = true; btn.disabled = true; btn.textContent = '✎ Queuing…';
11004
11159
  let ok = false;
11160
+ let handoff = null;
11005
11161
  try {
11006
- await api(kbUrl(proj.id, '/request'), { method: 'POST', body: JSON.stringify({ prompt }) });
11007
- ok = true;
11162
+ const result = await api(kbUrl(proj.id, '/request'), { method: 'POST', body: JSON.stringify({ prompt, clientSubmissionId: kbSubmissionId(proj.id, 'adjust', prompt) }) });
11163
+ handoff = result.handoff;
11164
+ ok = !handoff?.error;
11165
+ if (ok) kbSubmissionDone(proj.id, 'adjust');
11008
11166
  if (bridge.loadRequests) await bridge.loadRequests(); // bump the footer Requests counter (nothing else moves it here)
11009
11167
  } catch { /* the failure is reported through `ok` below — the message was never shown */ }
11010
11168
  kbAdjustBusy = null;
@@ -11020,13 +11178,14 @@
11020
11178
  kbSyncAdjustSubmit(); // empty draft → submit aria-disabled + rest tooltip
11021
11179
  const det = ta.closest('.kb-adjust');
11022
11180
  if (det) { det.open = false; const sum = det.querySelector('.kb-adjust-summary'); if (sum) sum.focus(); } // a11y: focus doesn't vanish
11023
- showToast('Adjustment queued for your terminal AI', 'ok');
11181
+ showToast('Adjustment sent to this project’s AI Chat', 'ok');
11182
+ if (handoff?.chatId && bridge.openChatConversation) await bridge.openChatConversation(handoff.chatId);
11024
11183
  track('kb_adjust_queued', { app: proj.app });
11025
11184
  } else {
11026
11185
  ta.disabled = false; ta.focus(); // preserve the text + caret, return focus for a retry
11027
11186
  btn.disabled = false; btn.textContent = '✎ Adjust';
11028
11187
  kbSyncAdjustSubmit();
11029
- showToast('We couldn’t save that adjustment because FloLess could not finish the request. Try again.', 'warn');
11188
+ showToast(handoff?.error || 'Couldn’t confirm delivery. Your instruction is kept here; retry to check the same task.', 'warn');
11030
11189
  }
11031
11190
  kbInvalidateRefs(); // the box stays active (focus) → next inactive tick settles the footer
11032
11191
  }
@@ -11576,6 +11735,13 @@
11576
11735
  }
11577
11736
  const cancelOrg = e.target.closest('[data-kb-cancel-organize]');
11578
11737
  if (cancelOrg) { kbCancelOrganize(cancelOrg.getAttribute('data-kb-cancel-organize')); return; }
11738
+ const openKnowledgeChat = e.target.closest('[data-kb-open-chat]');
11739
+ if (openKnowledgeChat) {
11740
+ if (bridge.openChatConversation) bridge.openChatConversation(openKnowledgeChat.dataset.kbOpenChat).catch(() => showToast('Couldn’t open AI Chat. Try again.', 'warn'));
11741
+ return;
11742
+ }
11743
+ if (e.target.closest('[data-kb-retry-handoff]')) { kbOrganize(); return; }
11744
+ if (e.target.closest('[data-kb-retry-adjustment]')) { kbRetryAdjustment(); return; }
11579
11745
  const org = e.target.closest('#kb-organize');
11580
11746
  if (org) { if (org.getAttribute('aria-disabled') !== 'true') kbOrganize(); return; } // aria-disabled still receives clicks
11581
11747
  const adjBtn = e.target.closest('#kb-adjust-submit');