@floless/app 0.132.1 → 0.133.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web/aware.js CHANGED
@@ -151,12 +151,174 @@
151
151
  // (fired before this script runs) would otherwise drip stale demo lines into
152
152
  // our chat. Replace it with a synchronous version, and clear any stragglers
153
153
  // already scheduled by the original before we took over.
154
+ let instructorAnswers = [];
155
+ let hydratedInstructorAnswers = false;
156
+ const ANSWER_KNOWN_KEY = 'floless:instructor-answers:known';
157
+ const ANSWER_READ_KEY = 'floless:instructor-answers:read';
158
+ function storedAnswerIds(key) {
159
+ try {
160
+ const value = JSON.parse(localStorage.getItem(key) || '[]');
161
+ return new Set(Array.isArray(value) ? value.filter((id) => typeof id === 'string') : []);
162
+ } catch { return new Set(); }
163
+ }
164
+ function persistAnswerIds(key, ids) {
165
+ try { localStorage.setItem(key, JSON.stringify(Array.from(ids).slice(-500))); } catch { /* private mode/quota */ }
166
+ }
167
+ let hadAnswerKnownSnapshot = false;
168
+ try { hadAnswerKnownSnapshot = localStorage.getItem(ANSWER_KNOWN_KEY) !== null; } catch { /* private mode */ }
169
+ const notifiedInstructorAnswerIds = storedAnswerIds(ANSWER_KNOWN_KEY);
170
+ const arrivedInstructorAnswerIds = new Set();
171
+ const readInstructorAnswerIds = storedAnswerIds(ANSWER_READ_KEY);
172
+ let answerGlowTimer = null;
173
+ let leftPaneTab = 'narrative';
174
+
175
+ function selectLeftPaneTab(tab, { focus = false, explicit = false } = {}) {
176
+ leftPaneTab = tab === 'answers' ? 'answers' : 'narrative';
177
+ const narrativeTab = document.getElementById('narrative-tab');
178
+ const answersTab = document.getElementById('ai-answers-tab');
179
+ const answersFeed = document.getElementById('ai-answers');
180
+ const showAnswers = leftPaneTab === 'answers';
181
+ $messages.hidden = showAnswers;
182
+ if (answersFeed) answersFeed.hidden = !showAnswers;
183
+ narrativeTab?.classList.toggle('active', !showAnswers);
184
+ answersTab?.classList.toggle('active', showAnswers);
185
+ narrativeTab?.setAttribute('aria-selected', String(!showAnswers));
186
+ answersTab?.setAttribute('aria-selected', String(showAnswers));
187
+ narrativeTab?.setAttribute('tabindex', showAnswers ? '-1' : '0');
188
+ answersTab?.setAttribute('tabindex', showAnswers ? '0' : '-1');
189
+ if (showAnswers && explicit) {
190
+ instructorAnswers.filter(answerInVisibleScope).forEach((answer) => readInstructorAnswerIds.add(answer.id));
191
+ persistAnswerIds(ANSWER_READ_KEY, readInstructorAnswerIds);
192
+ document.getElementById('answer-unread')?.setAttribute('hidden', '');
193
+ answersTab?.removeAttribute('aria-label');
194
+ }
195
+ if (focus) (showAnswers ? answersTab : narrativeTab)?.focus();
196
+ }
197
+
198
+ function onLeftPaneTabKey(event) {
199
+ if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
200
+ event.preventDefault();
201
+ const answers = event.key === 'ArrowRight' || event.key === 'End';
202
+ selectLeftPaneTab(answers ? 'answers' : 'narrative', { focus: true, explicit: true });
203
+ }
204
+
205
+ document.getElementById('narrative-tab')?.addEventListener('click', () => selectLeftPaneTab('narrative', { explicit: true }));
206
+ document.getElementById('ai-answers-tab')?.addEventListener('click', () => selectLeftPaneTab('answers', { explicit: true }));
207
+ document.getElementById('narrative-tab')?.addEventListener('keydown', onLeftPaneTabKey);
208
+ document.getElementById('ai-answers-tab')?.addEventListener('keydown', onLeftPaneTabKey);
209
+
210
+ function answerInVisibleScope(answer) {
211
+ if (!answer || !answer.instructorContext) return false;
212
+ if (wsRequestScope) {
213
+ if (wsRequestScope.kind === 'project') return answer.project === wsRequestScope.project;
214
+ return !answer.project && !answer.appId && answer.instructorContext.surface === 'workspaces';
215
+ }
216
+ return !answer.project && !!currentId && answer.appId === currentId;
217
+ }
218
+
219
+ function answerCard(answer, isNew) {
220
+ const subject = escapeHtml(answer.instructorContext.subject || 'this context');
221
+ const prose = escapeHtml(answer.answer || '').replace(/\r?\n/g, '<br>');
222
+ const runtime = answer.runtime === 'claude' ? 'Claude' : answer.runtime === 'codex' ? 'Codex' : 'terminal AI';
223
+ const card = msgEl(`aware instructor-answer${isNew ? ' instructor-answer-new' : ''}`,
224
+ `${runtime} · ${subject}`,
225
+ `<span class="answer-new-badge">New answer</span>${prose}`,
226
+ answer.finishedAt);
227
+ card.dataset.answerId = answer.id;
228
+ return card;
229
+ }
230
+
231
+ function acceptInstructorAnswers(answers, { initial = false } = {}) {
232
+ instructorAnswers = answers;
233
+ if (initial) {
234
+ answers.forEach((answer) => {
235
+ notifiedInstructorAnswerIds.add(answer.id);
236
+ if (!hadAnswerKnownSnapshot) readInstructorAnswerIds.add(answer.id);
237
+ });
238
+ persistAnswerIds(ANSWER_KNOWN_KEY, notifiedInstructorAnswerIds);
239
+ if (!hadAnswerKnownSnapshot) persistAnswerIds(ANSWER_READ_KEY, readInstructorAnswerIds);
240
+ hadAnswerKnownSnapshot = true;
241
+ renderInstructorAnswers({ revealNew: false });
242
+ return;
243
+ }
244
+ // Arrival is recorded globally before scope filtering. An answer for another project stays
245
+ // unread there, but visiting that project later must not replay an old arrival as a new one.
246
+ answers.forEach((answer) => {
247
+ if (notifiedInstructorAnswerIds.has(answer.id)) return;
248
+ notifiedInstructorAnswerIds.add(answer.id);
249
+ if (answerInVisibleScope(answer)) arrivedInstructorAnswerIds.add(answer.id);
250
+ });
251
+ persistAnswerIds(ANSWER_KNOWN_KEY, notifiedInstructorAnswerIds);
252
+ renderInstructorAnswers({ revealNew: true });
253
+ }
254
+
255
+ function renderInstructorAnswers({ revealNew = true } = {}) {
256
+ const feed = document.getElementById('ai-answers');
257
+ if (!feed) return;
258
+ const visible = instructorAnswers.filter(answerInVisibleScope);
259
+ const wasNearBottom = feed.scrollHeight - feed.scrollTop - feed.clientHeight < 72;
260
+ const unseen = revealNew ? visible.filter((answer) => arrivedInstructorAnswerIds.has(answer.id)) : [];
261
+ const unreadCount = visible.filter((answer) => !readInstructorAnswerIds.has(answer.id)).length;
262
+ const unreadBadge = document.getElementById('answer-unread');
263
+ const answersTab = document.getElementById('ai-answers-tab');
264
+ if (unreadBadge) {
265
+ unreadBadge.textContent = unreadCount > 9 ? '9+' : String(unreadCount);
266
+ unreadBadge.hidden = unreadCount === 0;
267
+ }
268
+ if (unreadCount) answersTab?.setAttribute('aria-label', `AI answers, ${unreadCount} unread`);
269
+ else answersTab?.removeAttribute('aria-label');
270
+ const newAnswer = unseen.length ? unseen[unseen.length - 1] : null;
271
+ feed.innerHTML = '';
272
+ if (!visible.length) {
273
+ const scope = wsRequestScope?.kind === 'project' ? 'this project' : wsRequestScope ? 'Workspaces' : 'this workflow';
274
+ feed.innerHTML = `<div class="ai-answers-empty">No AI answers for ${scope} yet. Direct answers you start from Instructor will appear here.</div>`;
275
+ } else {
276
+ visible.forEach((answer) => feed.appendChild(answerCard(answer, answer === newAnswer)));
277
+ }
278
+ if (!newAnswer) {
279
+ return;
280
+ }
281
+
282
+ const obscured = !!document.querySelector('.modal-backdrop.show') || !!($contractEditor && !$contractEditor.hidden);
283
+ const wasCollapsed = state.collapse.left;
284
+ const collapsedToggleHadFocus = wasCollapsed
285
+ && document.activeElement?.matches('.collapsed-stub .panel-toggle[data-side="left"]');
286
+ if (wasCollapsed && !obscured) {
287
+ state.collapse.left = false;
288
+ applyCollapse(); // session reveal only; the user's saved collapse preference remains untouched
289
+ if (collapsedToggleHadFocus) {
290
+ requestAnimationFrame(() => document.querySelector('.panel-label .panel-toggle[data-side="left"]')?.focus({ preventScroll: true }));
291
+ }
292
+ }
293
+ const paneAlreadyOpenOnAnswers = !wasCollapsed && leftPaneTab === 'answers';
294
+ if (wasCollapsed && !obscured) selectLeftPaneTab('answers');
295
+ else if (!paneAlreadyOpenOnAnswers) {
296
+ if (unreadBadge) unreadBadge.hidden = false;
297
+ document.getElementById('ai-answers-tab')?.classList.add('instructor-answer-new');
298
+ }
299
+ const card = feed.querySelector(`[data-answer-id="${CSS.escape(newAnswer.id)}"]`);
300
+ if (card && !obscured && (wasCollapsed || (paneAlreadyOpenOnAnswers && wasNearBottom))) requestAnimationFrame(() => card.scrollIntoView({ block: 'nearest' }));
301
+ const status = document.getElementById('narrative-answer-status');
302
+ if (status) status.textContent = wasCollapsed && !obscured
303
+ ? `Terminal AI answered about ${newAnswer.instructorContext.subject}. AI answers opened.`
304
+ : `New AI answer about ${newAnswer.instructorContext.subject}. Open AI answers.`;
305
+ unseen.forEach((answer) => arrivedInstructorAnswerIds.delete(answer.id));
306
+ if (answerGlowTimer) clearTimeout(answerGlowTimer);
307
+ answerGlowTimer = setTimeout(() => {
308
+ card?.classList.remove('instructor-answer-new');
309
+ document.getElementById('ai-answers-tab')?.classList.remove('instructor-answer-new');
310
+ if (status) status.textContent = '';
311
+ answerGlowTimer = null;
312
+ }, 2100);
313
+ }
314
+
154
315
  renderChat = function renderChatSync() {
155
316
  const p = PROMPTS[state.promptKey];
156
317
  $messages.innerHTML = '';
157
- if (!p) return;
158
- $messages.appendChild(msgEl('user', '$ you', p.userText));
159
- (p.narration || []).forEach((line) => $messages.appendChild(msgEl('aware', 'claude', mdInline(line))));
318
+ if (p) {
319
+ $messages.appendChild(msgEl('user', '$ you', p.userText));
320
+ (p.narration || []).forEach((line) => $messages.appendChild(msgEl('aware', 'claude', mdInline(line))));
321
+ }
160
322
  $messages.scrollTop = $messages.scrollHeight;
161
323
  };
162
324
 
@@ -324,7 +486,7 @@
324
486
  'default', 'get', 'set', 'async', 'await', 'yield', 'lock', 'params', 'when', 'where',
325
487
  ]);
326
488
  function highlightCSharp(src) {
327
- const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
489
+ const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
328
490
  const span = (cls, text) => `<span class="${cls}">${esc(text)}</span>`;
329
491
  const n = src.length;
330
492
  let out = '';
@@ -964,10 +1126,18 @@
964
1126
  } catch (e) { reportErr(e); }
965
1127
  }
966
1128
 
967
- // The Instructor's Ask button uses the same durable reverse channel as the onboarding guide,
968
- // but carries the exact structured context the strip rendered. The SERVER turns that state into
969
- // prose; this browser seam only queues intent, attempts the convenience copy, and reports delivery.
970
- async function requestInstructorHelp(instructorContext) {
1129
+ const activeInstructorRuns = new Map();
1130
+
1131
+ function reconcileActiveInstructorRuns(requests = [], answers = []) {
1132
+ for (const [fingerprint, requestId] of activeInstructorRuns) {
1133
+ const stillRunning = requests.some((request) => request?.id === requestId
1134
+ && (request.run?.state === 'queued' || request.run?.state === 'running'));
1135
+ const answered = answers.some((answer) => answer.id === requestId);
1136
+ if (answered || !stillRunning) activeInstructorRuns.delete(fingerprint);
1137
+ }
1138
+ }
1139
+
1140
+ function instructorRequestBody(instructorContext) {
971
1141
  const body = { instructorContext };
972
1142
  // Workspaces is a replacement surface but deliberately leaves the last workflow selected
973
1143
  // underneath it. Scope from the visible surface, never from that hidden selection: an open
@@ -981,6 +1151,59 @@
981
1151
  } else if (currentId) {
982
1152
  body.appId = currentId;
983
1153
  }
1154
+ return body;
1155
+ }
1156
+
1157
+ async function instructorAskOptions() {
1158
+ const info = await refreshHeadless();
1159
+ const found = info && Array.isArray(info.runtimes)
1160
+ ? info.runtimes.filter((runtime) => runtime && runtime.state === 'found')
1161
+ : [];
1162
+ return { found, provider: info && info.provider };
1163
+ }
1164
+
1165
+ async function startInstructorAnswer(request, runtime, fingerprint) {
1166
+ try {
1167
+ const res = await api(`/api/requests/${encodeURIComponent(request.id)}/run`, {
1168
+ method: 'POST', body: JSON.stringify(runtime ? { runtime } : {}),
1169
+ });
1170
+ const chosen = (res.run && res.run.runtime) || runtime;
1171
+ activeInstructorRuns.set(fingerprint, request.id);
1172
+ showToast(`Asked ${runtimeLabel(chosen)} — the answer will appear in AI answers`, 'ok');
1173
+ await loadRequests();
1174
+ return true;
1175
+ } catch (error) {
1176
+ const copied = await copyToClipboard(markedInstruction(request));
1177
+ const chosen = runtime ? runtimeLabel(runtime) : 'your terminal AI';
1178
+ showToast(copied
1179
+ ? `Couldn’t start ${chosen}. Request queued and copied — paste it in your terminal.`
1180
+ : `Couldn’t start ${chosen}. Request queued — open Requests to copy it.`, 'err');
1181
+ try { await loadRequests(); } catch (refreshError) { console.error(refreshError); }
1182
+ return false;
1183
+ }
1184
+ }
1185
+
1186
+ // The Instructor can either start the verified read-only answer immediately or preserve the
1187
+ // original interactive queue/copy handoff. Both begin with the same durable server-owned request.
1188
+ const instructorRequestsInFlight = new Map();
1189
+ async function performInstructorHelp(instructorContext, options = {}) {
1190
+ const body = instructorRequestBody(instructorContext);
1191
+ const mode = options.mode === 'direct' ? 'direct' : 'queue';
1192
+ const fingerprint = JSON.stringify(body);
1193
+ const matchingPending = mode === 'direct' && pendingRequests.find((request) => {
1194
+ if (request.type !== 'guide' || (request.run?.state !== 'queued' && request.run?.state !== 'running')) return false;
1195
+ const storedBody = { instructorContext: request.instructorContext };
1196
+ if (request.project) {
1197
+ storedBody.project = request.project;
1198
+ storedBody.projectLabel = request.projectLabel;
1199
+ storedBody.appId = request.appId;
1200
+ } else if (request.appId) storedBody.appId = request.appId;
1201
+ return JSON.stringify(storedBody) === fingerprint;
1202
+ });
1203
+ if (mode === 'direct' && (activeInstructorRuns.has(fingerprint) || matchingPending)) {
1204
+ showToast('That answer is already running — watch Requests for progress', 'ok');
1205
+ return true;
1206
+ }
984
1207
 
985
1208
  let request;
986
1209
  try {
@@ -992,6 +1215,8 @@
992
1215
  return false;
993
1216
  }
994
1217
 
1218
+ if (mode === 'direct') return startInstructorAnswer(request, options.runtime, fingerprint);
1219
+
995
1220
  // Delivery is already durable at this point. Clipboard and refresh are conveniences: neither
996
1221
  // may turn a successfully queued request into a false failure report.
997
1222
  const copied = await copyToClipboard(markedInstruction(request));
@@ -1003,6 +1228,33 @@
1003
1228
  return true;
1004
1229
  }
1005
1230
 
1231
+ async function requestInstructorHelp(instructorContext, options = {}) {
1232
+ const fingerprint = JSON.stringify(instructorRequestBody(instructorContext));
1233
+ const existing = instructorRequestsInFlight.get(fingerprint);
1234
+ if (existing) return existing;
1235
+ const task = performInstructorHelp(instructorContext, options);
1236
+ instructorRequestsInFlight.set(fingerprint, task);
1237
+ try { return await task; }
1238
+ finally { if (instructorRequestsInFlight.get(fingerprint) === task) instructorRequestsInFlight.delete(fingerprint); }
1239
+ }
1240
+
1241
+ async function chooseInstructorRuntime(instructorContext) {
1242
+ const { found, provider } = await instructorAskOptions();
1243
+ if (!found.length) return requestInstructorHelp(instructorContext, { mode: 'queue' });
1244
+ const result = await formModal({
1245
+ title: 'Choose terminal AI',
1246
+ sub: 'This read-only answer runs in an isolated FloLess folder and appears in AI answers.',
1247
+ fields: [{
1248
+ name: 'runtime', label: 'Terminal AI', type: 'select', value: provider || found[0].id,
1249
+ commandId: 'shell.instructor-ask-runtime',
1250
+ options: found.map((runtime) => ({ value: runtime.id, label: runtime.label, meta: runtime.command })),
1251
+ }],
1252
+ okLabel: 'Ask AI now',
1253
+ });
1254
+ if (!result) return false;
1255
+ return requestInstructorHelp(instructorContext, { mode: 'direct', runtime: result.runtime });
1256
+ }
1257
+
1006
1258
  // ≡ menu "New workflow…" — the create-from-scratch sibling of requestGuide(). No open
1007
1259
  // workflow to target (none exists yet), so no currentId gate: relay the ask to the
1008
1260
  // terminal AI the same house way (queue a request, copy the marked prompt, toast, light
@@ -1119,6 +1371,7 @@
1119
1371
  setComboTriggerLabel(id);
1120
1372
  setComboSelected(id);
1121
1373
  renderChat();
1374
+ renderInstructorAnswers({ revealNew: hydratedInstructorAnswers });
1122
1375
  renderTopology(); // selects first node + renderInspect
1123
1376
  paintModes();
1124
1377
  markStars();
@@ -3535,11 +3788,18 @@
3535
3788
  const searchable = opts.length > SELECT_SEARCH_MIN;
3536
3789
  const trigLabel = disabled ? (f.disabledLabel || 'None available')
3537
3790
  : sel ? sel.label + (sel.meta ? ` (${sel.meta})` : '') : (f.placeholder || 'Select…');
3791
+ // Command IDs are literal registry identities. Only the selected runtime is dynamic;
3792
+ // never interpolate an arbitrary form field into the Instructor trust boundary.
3793
+ const commandCarrier = f.commandId === 'shell.instructor-ask-runtime'
3794
+ ? ' data-command-id="shell.instructor-ask-runtime"'
3795
+ : f.commandId === 'shell.requests-runtime'
3796
+ ? ' data-command-id="shell.requests-runtime"'
3797
+ : '';
3538
3798
  const rows = opts.map((o) =>
3539
- `<div class="wf-option${isOn(o) ? ' selected' : ''}" role="option" data-id="${escapeAttr(String(o.value))}" data-search="${escapeAttr(String(o.search || o.label).toLowerCase())}" tabindex="-1" aria-selected="${isOn(o) ? 'true' : 'false'}"><span class="wf-option-name">${escapeHtml(o.label)}</span>${o.meta ? `<span class="wf-option-meta">${escapeHtml(o.meta)}</span>` : ''}</div>`).join('');
3799
+ `<div class="wf-option${isOn(o) ? ' selected' : ''}" role="option" data-id="${escapeAttr(String(o.value))}"${commandCarrier}${commandCarrier ? ` data-command-instance="${escapeAttr(String(o.value))}"` : ''} data-search="${escapeAttr(String(o.search || o.label).toLowerCase())}" tabindex="-1" aria-selected="${isOn(o) ? 'true' : 'false'}"><span class="wf-option-name">${escapeHtml(o.label)}</span>${o.meta ? `<span class="wf-option-meta">${escapeHtml(o.meta)}</span>` : ''}</div>`).join('');
3540
3800
  ctl = `<div class="wf-combo fm-select">
3541
3801
  <input type="hidden" data-fm="${escapeHtml(f.name)}" value="${escapeAttr(val)}">
3542
- <button type="button" class="wf-trigger fm-select-trigger" aria-haspopup="listbox" aria-expanded="false"${disabled ? ' disabled' : ''}>
3802
+ <button type="button" class="wf-trigger fm-select-trigger"${commandCarrier}${commandCarrier && sel ? ` data-command-instance="${escapeAttr(String(sel.value))}"` : ''} aria-haspopup="listbox" aria-expanded="false"${disabled ? ' disabled' : ''}>
3543
3803
  <span class="wf-trigger-label fm-select-label"${sel ? '' : ' data-empty="1"'}>${escapeHtml(trigLabel)}</span>
3544
3804
  <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>
3545
3805
  </button>
@@ -3870,6 +4130,7 @@
3870
4130
  const nameOf = (o) => { const n = o.querySelector('.wf-option-name'); return n ? n.textContent : o.dataset.id; };
3871
4131
  const choose = (opt) => {
3872
4132
  if (hidden) hidden.value = opt.dataset.id;
4133
+ if (trigger.dataset.commandId) trigger.dataset.commandInstance = opt.dataset.id;
3873
4134
  opts().forEach((o) => { const s = o === opt; o.classList.toggle('selected', s); o.setAttribute('aria-selected', s ? 'true' : 'false'); });
3874
4135
  const mt = opt.querySelector('.wf-option-meta');
3875
4136
  if (label) { label.textContent = nameOf(opt) + (mt ? ` (${mt.textContent})` : ''); label.removeAttribute('data-empty'); }
@@ -6342,6 +6603,8 @@
6342
6603
  // idea whether Node.js is missing. Telling someone to install what they already
6343
6604
  // have is the exact bug this reason exists to prevent.
6344
6605
  return "Couldn't check whether Node.js is installed — the check didn't finish, which usually means the machine was busy. Nothing is necessarily missing; try again.";
6606
+ case 'aware-version-required':
6607
+ return 'This FloLess release needs AWARE 0.125.0 or newer. Update AWARE, then try again.';
6345
6608
  case 'offline':
6346
6609
  return 'No network connection was detected. Connect to the internet, then try again.';
6347
6610
  case 'smoke-failed':
@@ -6743,6 +7006,7 @@
6743
7006
  // the catch-up question. (Found by review.)
6744
7007
  if (everOpened) {
6745
7008
  window.dispatchEvent(new CustomEvent('floless:projects-changed', { detail: {} }));
7009
+ loadRequests();
6746
7010
  // The SAME catch-up for the other half a live `projects-changed` drives (see that arm): the
6747
7011
  // open workflow's publication availability turns on project state, so a gap leaves the card
6748
7012
  // asserting a state that may no longer hold. Re-asking for Workspaces but not for Workflows
@@ -7359,6 +7623,7 @@
7359
7623
  },
7360
7624
  {
7361
7625
  name: 'runtime', label: 'Which terminal AI', type: 'select', value: info.provider || found[0].id,
7626
+ commandId: 'shell.requests-runtime',
7362
7627
  options: found.map((r) => ({ value: r.id, label: r.label, meta: r.command })),
7363
7628
  },
7364
7629
  ],
@@ -7532,9 +7797,19 @@
7532
7797
  // has not been delivered — cleared only once it has actually flashed on a visible list, or once the
7533
7798
  // request it names is gone.
7534
7799
  let pendingRevealId = null;
7800
+ let requestFetchEpoch = 0;
7535
7801
  async function loadRequests() {
7536
7802
  try {
7537
- const { requests } = await api('/api/requests');
7803
+ const epoch = ++requestFetchEpoch;
7804
+ const { requests, answers = [] } = await api('/api/requests');
7805
+ if (epoch !== requestFetchEpoch) return;
7806
+ reconcileActiveInstructorRuns(requests, answers);
7807
+ if (!hydratedInstructorAnswers) {
7808
+ acceptInstructorAnswers(answers, { initial: true });
7809
+ hydratedInstructorAnswers = true;
7810
+ } else {
7811
+ acceptInstructorAnswers(answers);
7812
+ }
7538
7813
  pendingRequests = requests;
7539
7814
  const $rc = document.getElementById('req-count');
7540
7815
  const $rs = document.getElementById('req-stat');
@@ -7824,7 +8099,7 @@
7824
8099
  const runBtn = inFlight
7825
8100
  ? `<button class="req-stop" data-id="${escapeAttr(r.id)}" data-tip="Stop this run">■</button>`
7826
8101
  : canRunNow
7827
- ? `<button class="req-run" data-id="${escapeAttr(r.id)}" data-tip="${run ? 'Run it again in your terminal AI, headless' : 'Let floless run this in your terminal AI'}">▶</button>`
8102
+ ? `<button class="req-run" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-run" data-command-instance="${escapeAttr(r.id)}" aria-label="Run this request" data-tip="${run ? 'Run it again in your terminal AI, headless' : 'Let floless run this in your terminal AI'}">▶</button>`
7828
8103
  : '';
7829
8104
  return `
7830
8105
  <div class="req-item" data-id="${escapeAttr(r.id)}">
@@ -10011,6 +10286,8 @@
10011
10286
  : null;
10012
10287
  const $rm = document.getElementById('requests-modal');
10013
10288
  if ($rm && $rm.classList.contains('show')) renderRequests();
10289
+ renderChat();
10290
+ renderInstructorAnswers({ revealNew: hydratedInstructorAnswers });
10014
10291
  },
10015
10292
  refreshCurrentWorkflow() {
10016
10293
  return refreshCurrentWorkflow();
@@ -10022,6 +10299,8 @@
10022
10299
  },
10023
10300
  copyToClipboard,
10024
10301
  requestInstructorHelp,
10302
+ chooseInstructorRuntime,
10303
+ instructorAskOptions,
10025
10304
  instructionFor,
10026
10305
  markedInstruction, // marked (paste-safe) form for clipboard copies — panels.js uses it (#73)
10027
10306
  copyRequest, // copy ONE request, telling "no instruction body" apart from "clipboard refused"
@@ -636,8 +636,8 @@
636
636
  /* ── the strip, the footer, and the two nudges ──────────────────────────── */
637
637
 
638
638
  def('shell.instructor-ask', {
639
- label: 'Ask my terminal AI',
640
- actsOn: 'Queues the current command, state, and blocker for your terminal AI',
639
+ label: 'Ask AI now',
640
+ actsOn: 'Starts a read-only terminal AI answer for the current Instructor context; the answer appears in AI answers',
641
641
  group: 'In the Instructor strip',
642
642
  persistence: 'external',
643
643
  interaction: 'instant',
@@ -645,6 +645,44 @@
645
645
  guidance: 'on-demand',
646
646
  });
647
647
 
648
+ def('shell.instructor-ask-options', {
649
+ label: 'More ways to ask',
650
+ actsOn: 'Opens choices for the runtime or the queue-and-copy handoff',
651
+ group: 'In the Instructor strip', persistence: 'none', interaction: 'dialog', risk: [], guidance: 'on-demand',
652
+ });
653
+
654
+ def('shell.instructor-ask-runtime', {
655
+ label: 'Choose terminal AI',
656
+ actsOn: 'Chooses which installed terminal AI answers this Instructor context',
657
+ group: 'In the Instructor strip', persistence: 'external', interaction: 'dialog', risk: ['costs-time'], guidance: 'on-demand',
658
+ });
659
+
660
+ def('shell.instructor-ask-queue', {
661
+ label: 'Queue & copy',
662
+ actsOn: 'Queues and copies the current Instructor context without starting it headless',
663
+ group: 'In the Instructor strip', persistence: 'external', interaction: 'instant', risk: ['costs-time'], guidance: 'on-demand',
664
+ });
665
+
666
+ def('shell.narrative-tab', {
667
+ label: 'Narrative', actsOn: 'Shows curated workflow and run narration', group: 'In the Narrative panel',
668
+ persistence: 'none', interaction: 'mode', risk: [], guidance: 'on-demand',
669
+ });
670
+
671
+ def('shell.ai-answers-tab', {
672
+ label: 'AI answers', actsOn: 'Shows durable read-only answers for the visible workflow or project', group: 'In the Narrative panel',
673
+ persistence: 'none', interaction: 'mode', risk: [], guidance: 'on-demand',
674
+ });
675
+
676
+ def('shell.requests-run', {
677
+ label: 'Run this request', actsOn: 'Starts this queued request headlessly in the selected terminal AI',
678
+ group: 'In the requests list', persistence: 'external', interaction: 'instant', risk: ['costs-time'], guidance: 'on-demand',
679
+ });
680
+
681
+ def('shell.requests-runtime', {
682
+ label: 'Which terminal AI', actsOn: 'Chooses the terminal AI used for this queued request',
683
+ group: 'In the run request dialog', persistence: 'none', interaction: 'dialog', risk: [], guidance: 'on-demand',
684
+ });
685
+
648
686
  def('shell.whats-new', {
649
687
  label: 'What’s new',
650
688
  actsOn: 'Shows what changed in this version',