@floless/app 0.150.0 → 0.152.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.
@@ -27,6 +27,7 @@
27
27
  dirty: false,
28
28
  banner: null, // { text, action?: { label, run } }
29
29
  saving: false,
30
+ pausing: false, // #2062: a Pause/Resume is being saved
30
31
  runs: [],
31
32
  runsKey: null,
32
33
  runsUnreadable: [],
@@ -258,7 +259,9 @@
258
259
  }
259
260
 
260
261
  function draftOf(agent) {
261
- return { name: agent.name, instructions: agent.instructions, scope: agent.scope.map((s) => ({ ...s })), mode: agent.mode, allowChanges: agent.allowChanges };
262
+ // `provider` is not edited on this page, but a save must not wipe one stored by another surface.
263
+ return { name: agent.name, instructions: agent.instructions, scope: agent.scope.map((s) => ({ ...s })), mode: agent.mode, allowChanges: agent.allowChanges,
264
+ provider: agent.provider ?? null };
262
265
  }
263
266
 
264
267
  // ── navigation ───────────────────────────────────────────────────────────────────────────────────────────────
@@ -290,19 +293,26 @@
290
293
  async function openAgent(agentId) {
291
294
  if (!(await confirmLeave())) return;
292
295
  if (!state.options) await loadOptions();
293
- state.pageGeneration += 1;
294
- state.view = 'page'; state.banner = null; state.pickerOpen = false; state.runs = []; state.runsKey = null;
296
+ const generation = ++state.pageGeneration;
297
+ // The page view is entered only once its draft exists (#2035 QA): a list load running alongside (opening the tab
298
+ // and an agent at once, as the Routines "Agent" button does) would otherwise paint a page with no draft.
299
+ state.banner = null; state.pickerOpen = false; state.runs = []; state.runsKey = null;
295
300
  if (state.selected || state.chatScope) { state.selected = null; state.chatScope = null; notifyChatScope(); }
296
301
  if (agentId) {
297
302
  try {
298
303
  const body = await api(`/api/chat/agents/${encodeURIComponent(agentId)}`);
299
- state.agent = body.agent; state.draft = draftOf(body.agent); state.dirty = false;
300
- } catch (error) { toast(error.message, 'warn'); state.view = 'list'; await loadAgents(); return; }
304
+ // Opening another agent meanwhile wins: an older, slower answer never replaces the newer page.
305
+ if (generation !== state.pageGeneration) return;
306
+ state.agent = body.agent; state.draft = draftOf(body.agent); state.dirty = false; state.view = 'page';
307
+ } catch (error) {
308
+ if (generation !== state.pageGeneration) return; // a newer page was opened meanwhile: this answer is stale either way
309
+ toast(error.message, 'warn'); state.view = 'list'; await loadAgents(); return;
310
+ }
301
311
  paint();
302
312
  $surface.querySelector('#ag-name')?.focus();
303
313
  await loadRuns();
304
314
  } else {
305
- state.agent = null; state.draft = blankDraft(); state.dirty = false;
315
+ state.agent = null; state.draft = blankDraft(); state.dirty = false; state.view = 'page';
306
316
  paint();
307
317
  $surface.querySelector('#ag-name')?.focus();
308
318
  }
@@ -353,8 +363,8 @@
353
363
  const choice = await dialog({
354
364
  title: `Archive “${state.agent.name}”?`,
355
365
  sub: dirty
356
- ? 'It moves to Archived and can’t be run until you restore it. Past runs are kept, and runs already going keep going. You have unsaved changes: save them first, or archive without them.'
357
- : 'It moves to Archived and can’t be run until you restore it. Past runs are kept, and runs already going keep going.',
366
+ ? 'It moves to Archived and can’t be run until you restore it. Its routines stop starting it until then. Past runs are kept, and runs already going keep going. You have unsaved changes: save them first, or archive without them.'
367
+ : 'It moves to Archived and can’t be run until you restore it. Its routines stop starting it until then. Past runs are kept, and runs already going keep going.',
358
368
  actions: dirty ? [
359
369
  { id: 'cancel', label: 'Cancel', commandId: 'shell.agents-archive-cancel' },
360
370
  { id: 'discard', label: 'Archive without changes', commandId: 'shell.agents-archive-discard' },
@@ -375,6 +385,47 @@
375
385
  } catch (error) { state.banner = { text: error.message }; paint(); }
376
386
  }
377
387
 
388
+ /**
389
+ * #2062: Pause is the agent's state, not an edit, so it never touches the draft: unsaved edits stay unsaved and
390
+ * still save (the server keeps the revision as it is).
391
+ */
392
+ async function setPaused(paused) {
393
+ if (!state.agent || state.pausing) return;
394
+ const agentId = state.agent.agentId;
395
+ // The answer belongs to this agent: if the person opened another one meanwhile, it is not painted onto that page.
396
+ const stillHere = () => state.view === 'page' && state.agent?.agentId === agentId;
397
+ state.pausing = true; paint();
398
+ try {
399
+ const body = await api(`/api/chat/agents/${encodeURIComponent(agentId)}/pause`, { method: 'POST', body: { paused } });
400
+ if (stillHere()) { state.agent = { ...state.agent, pausedAt: body.agent.pausedAt }; state.banner = null; }
401
+ toast(paused ? 'Agent paused. Its routines won’t start it until you resume it.' : 'Agent resumed. Its routines run on their schedule again.', 'ok');
402
+ } catch (error) { if (stillHere()) state.banner = { text: error.message }; else toast(error.message, 'err'); }
403
+ state.pausing = false;
404
+ paint();
405
+ void loadAgents();
406
+ }
407
+
408
+ /**
409
+ * #2062: another page paused, resumed, archived or restored this agent — take its state. With unsaved edits the
410
+ * draft stays, and so does the revision it was opened at, so a save over a changed agent still asks first.
411
+ */
412
+ async function refreshAgentState(agentId) {
413
+ if (!state.open) return;
414
+ if (state.view !== 'page' || state.agent?.agentId !== agentId) { if (state.view !== 'page') void loadAgents(); return; }
415
+ try {
416
+ const fresh = (await api(`/api/chat/agents/${encodeURIComponent(agentId)}`)).agent;
417
+ if (state.agent?.agentId !== agentId) return;
418
+ if (!state.dirty) { state.agent = fresh; state.draft = draftOf(fresh); }
419
+ else state.agent = { ...state.agent, pausedAt: fresh.pausedAt, archivedAt: fresh.archivedAt };
420
+ paint();
421
+ } catch (error) {
422
+ if (state.agent?.agentId !== agentId) return;
423
+ console.warn('[agents] could not read this agent again after it changed elsewhere:', error);
424
+ state.banner = { text: 'This agent was changed in another window and FloLess couldn’t read it again. Go back to all agents and open it again to see where it stands.' };
425
+ paint();
426
+ }
427
+ }
428
+
378
429
  // ── run ──────────────────────────────────────────────────────────────────────────────────────────────────────
379
430
 
380
431
  function preferredProvider() {
@@ -383,6 +434,49 @@
383
434
  return stored === 'codex' || stored === 'claude' ? stored : 'claude';
384
435
  }
385
436
 
437
+ /** #2035: open the Routines editor with this agent chosen. */
438
+ async function scheduleAgent() {
439
+ if (state.dirty || !state.agent) {
440
+ const saved = await save();
441
+ if (!saved) return;
442
+ }
443
+ if (!window.flolessRoutines?.editForAgent) {
444
+ state.banner = { text: 'Routines aren’t ready yet. Try again in a moment.' };
445
+ paint();
446
+ return;
447
+ }
448
+ await window.flolessRoutines.editForAgent(state.agent.agentId, $surface.querySelector('#ag-schedule'));
449
+ }
450
+
451
+ // #2035: what each recorded decline became, in the person's words.
452
+ const DECLINE_LABEL = { declined: 'Declined', 'not-sent': 'Stopped before it was answered' };
453
+
454
+ /** The steps a routine-started run declined because nobody was watching: the "Questions for you" list. */
455
+ function questionsFor(run, target, label) {
456
+ const d = target.declines;
457
+ if (!d) return null;
458
+ const total = d.list.length + d.moreDeclined + d.moreNotSent;
459
+ if (!total) return null;
460
+ const declined = d.list.filter((entry) => entry.state === 'declined').length + d.moreDeclined;
461
+ const working = target.live === 'working' || target.live === 'starting';
462
+ const details = el('details', { class: 'ag-questions' },
463
+ el('summary', { 'data-command-id': `shell.agents-run-questions#${label}`, 'data-command-instance-label': label, text: `Questions for you (${total})` }));
464
+ details.append(el('p', { class: 'ag-help', text: declined === 0
465
+ ? `${total === 1 ? 'One step' : `${total} steps`} needed your approval while nobody was watching; none ${total === 1 ? 'was' : 'were'} confirmed as declined. Run the agent by hand to do ${total === 1 ? 'it' : 'them'} with you watching.`
466
+ : declined === 1
467
+ ? 'One step was declined because nobody was watching. Run the agent by hand to do it with you watching.'
468
+ : `${declined} steps were declined because nobody was watching. Run the agent by hand to do them with you watching.` }));
469
+ const list = el('ul', { class: 'ag-question-list' });
470
+ for (const entry of d.list) {
471
+ const status = DECLINE_LABEL[entry.state] || (working ? 'Being declined' : 'Could not confirm whether it was answered');
472
+ list.append(el('li', {}, el('span', { class: 'ag-state', text: status }), el('span', { class: 'ag-question-text', text: entry.summary })));
473
+ }
474
+ details.append(list);
475
+ const more = d.moreDeclined + d.moreNotSent;
476
+ if (more) details.append(el('p', { class: 'ag-help', text: `…and ${more} more not listed here (${d.moreDeclined} declined, ${d.moreNotSent} stopped before they were answered).` }));
477
+ return details;
478
+ }
479
+
386
480
  async function openRunSheet() {
387
481
  if (state.dirty || !state.agent) {
388
482
  const saved = await save();
@@ -416,8 +510,9 @@
416
510
  busy = true; render();
417
511
  try {
418
512
  try { localStorage.setItem(LS_PROVIDER, provider); } catch { /* private mode */ }
513
+ // #2061: the sheet said this agent is already running and the person chose "Start another run".
419
514
  const body = await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}/runs`, { method: 'POST',
420
- body: { runKey: preview.runKey, previewToken: preview.previewToken, provider } });
515
+ body: { runKey: preview.runKey, previewToken: preview.previewToken, provider, ...(preview.alreadyRunning ? { confirmOverlap: true } : {}) } });
421
516
  close();
422
517
  // They start in the background (some may wait their turn), so this says what was set going, not what began.
423
518
  const queued = body.run.targets.filter((t) => t.live !== 'skipped').length;
@@ -426,6 +521,9 @@
426
521
  $surface.querySelector('#ag-runs-title')?.focus();
427
522
  } catch (failure) {
428
523
  if (failure.code === 'agent-run-preview-changed' && failure.body?.preview) { preview = failure.body.preview; error = failure.message; }
524
+ // #2061: a run of this agent started meanwhile — ask, with the sheet's own "Start another run".
525
+ // The server's own sentence is kept: it says whether the run is going or FloLess can't tell.
526
+ else if (failure.code === 'agent-run-overlap') { preview = { ...preview, alreadyRunning: { ...(preview.alreadyRunning || { startedAt: null }), message: failure.message } }; error = null; }
429
527
  else error = failure.message;
430
528
  busy = false; render();
431
529
  }
@@ -439,6 +537,10 @@
439
537
  if (!preview) { modal.append(el('div', { class: 'modal-actions' }, el('button', { type: 'button', text: 'Close', 'data-command-id': 'shell.agents-run-cancel', onclick: close }))); return; }
440
538
  const nonProvider = preview.issues.filter((i) => i.kind !== 'provider');
441
539
  for (const issue of nonProvider) modal.append(el('p', { class: 'ag-run-issue', text: issue.message }));
540
+ // #2062: Pause holds only the schedule; this run is by hand, so it goes ahead.
541
+ if (state.agent?.pausedAt && !state.agent.archivedAt) {
542
+ modal.append(el('p', { class: 'ag-note', id: 'ag-run-paused-note', text: 'This agent is paused, so its routines won’t start it. Running it now by hand still works.' }));
543
+ }
442
544
  if (preview.conversations.length) {
443
545
  const count = preview.conversations.length;
444
546
  const head = preview.mode === 'compare'
@@ -453,6 +555,37 @@
453
555
  if (skipped.length && preview.conversations.length) {
454
556
  modal.append(el('div', { class: 'ag-run-skipped' }, skipped.map((item) => el('p', { text: item.reason }))));
455
557
  }
558
+ // #2061: asked, never refused. Another piece of work changing a project: this part waits by itself (the default),
559
+ // or the person opens it or stops it. The same agent already running: start another only on a clear yes.
560
+ const busyItems = !nonProvider.length && Array.isArray(preview.busy) ? preview.busy : [];
561
+ if (busyItems.length) {
562
+ modal.append(el('div', { class: 'ag-run-skipped ag-run-busy', role: 'status' }, busyItems.map((row) => {
563
+ const knowledge = row.holder?.kind === 'knowledge';
564
+ const who = row.holder?.kind === 'chat' ? `“${row.holder.title}”` : (row.holder?.title || 'other work');
565
+ const line = el('p', { text: knowledge
566
+ ? `FloLess is organizing ${row.label}’s knowledge. If you run now, this part waits and starts by itself when organizing finishes.`
567
+ : `${row.label} is being changed by ${who}. If you run now, this part waits and starts by itself when it’s free.` });
568
+ const links = el('span', { class: 'ag-run-busy-actions' });
569
+ const canOpen = knowledge ? Boolean(row.holder.projectId)
570
+ : row.holder?.kind === 'chat' ? Boolean(row.holder.owner && row.holder.chatId) : Boolean(row.holder?.requestId);
571
+ if (canOpen) links.append(el('button', { type: 'button', class: 'ag-link', text: 'Open it', 'data-command-id': `shell.agents-run-busy-open#${row.label}`,
572
+ 'data-command-instance-label': row.label, onclick: () => { close(); void openBusyHolder(row.holder); } }));
573
+ // #2106: organizing is driven from outside FloLess, so it is never offered "Stop it".
574
+ if (canOpen && !row.holder.waiting && !knowledge) links.append(el('button', { type: 'button', class: 'ag-link ag-link-warn', text: 'Stop it', 'data-command-id': `shell.agents-run-busy-stop#${row.label}`,
575
+ 'data-command-instance-label': row.label, onclick: async (event) => { event.currentTarget.disabled = true; await stopBusyHolder(row.holder); preview = null; render(); void load(); } }));
576
+ if (links.childNodes.length) line.append(' ', links);
577
+ return line;
578
+ })));
579
+ }
580
+ if (!nonProvider.length && preview.alreadyRunning) {
581
+ const since = preview.alreadyRunning.startedAt ? new Date(preview.alreadyRunning.startedAt) : null;
582
+ const when = since && !isNaN(since) ? ` (started ${since.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}, ${(() => { const m = Math.round((Date.now() - since) / 60000); return m < 1 ? 'just now' : `${m} min ago`; })()})` : '';
583
+ modal.append(el('div', { class: 'ag-run-skipped ag-run-overlap', role: 'alert' },
584
+ el('p', { text: preview.alreadyRunning.message
585
+ || (preview.alreadyRunning.unknown
586
+ ? `FloLess can’t tell whether the last run of “${state.agent.name}” has finished${when}. Start another run anyway?`
587
+ : `“${state.agent.name}” is already running${when}. Start another run anyway?`) })));
588
+ }
456
589
  // The AI that answers.
457
590
  const seg = el('div', { class: 'ag-seg', role: 'radiogroup', 'aria-label': 'Which AI runs this' });
458
591
  for (const [value, label] of [['claude', 'Claude'], ['codex', 'Codex']]) {
@@ -464,7 +597,7 @@
464
597
  if (preview.providerMessage) modal.append(el('p', { class: 'ag-run-issue', role: 'status', text: preview.providerMessage }));
465
598
  if (preview.conversations.length) {
466
599
  modal.append(el('p', { class: 'ag-run-line', text: preview.allowChanges
467
- ? 'Can change files: yes, in the project or workflow each conversation is homed in. A file edit anywhere else asks you first; commands follow your Claude or Codex approval settings.'
600
+ ? 'Can change files: yes, in Auto — in the project or workflow each conversation is homed in, the AI does safe work by itself and checks risky steps first. Claude still asks you before an edit anywhere else; Codex’s own review may approve one and notes each decision in the conversation.'
468
601
  : 'Can change files: no — it reads and reports.' }));
469
602
  if (preview.conversations.length > preview.maxActive) modal.append(el('p', { class: 'ag-run-line', text: `Up to ${preview.maxActive} run at a time; the rest wait their turn.` }));
470
603
  modal.append(el('p', { class: 'ag-note', text: isolationNote(preview.mode, preview.allowChanges) }));
@@ -483,11 +616,12 @@
483
616
  }
484
617
  } else {
485
618
  actions.append(el('button', { type: 'button', class: 'primary', 'data-command-id': 'shell.agents-run-confirm',
486
- disabled: busy || !preview.canRun, text: busy ? 'Starting…' : skipped.length ? 'Run on the rest' : 'Run', onclick: start,
619
+ disabled: busy || !preview.canRun, text: busy ? 'Starting…' : preview.alreadyRunning ? 'Start another run' : skipped.length ? 'Run on the rest' : 'Run', onclick: start,
487
620
  'data-blocked-reason': busy ? 'Starting this run now.' : !preview.canRun ? (preview.providerMessage || preview.issues[0]?.message || 'This agent can’t run yet.') : null }));
488
621
  }
489
622
  modal.append(actions);
490
- (actions.querySelector('button.primary:not([disabled])') || actions.querySelector('button'))?.focus();
623
+ // A second run of the same agent is the riskier choice, so focus rests on Cancel then (#2061).
624
+ (preview.alreadyRunning ? actions.querySelector('button') : actions.querySelector('button.primary:not([disabled])') || actions.querySelector('button'))?.focus();
491
625
  };
492
626
  render();
493
627
  await load();
@@ -496,7 +630,7 @@
496
630
  function isolationNote(mode, allowChanges) {
497
631
  const where = mode === 'compare' ? 'This run is told only about these projects' : 'Each run is told only about its own project';
498
632
  const change = allowChanges
499
- ? '; it may change files in the project or workflow its conversation is homed in, and a file edit anywhere else asks you first'
633
+ ? '; it may change files in the project or workflow its conversation is homed in, working in Auto'
500
634
  : ' and only reads';
501
635
  return `${where}${change}. This is not a lock: the AI on this computer can still open other folders you can open.`;
502
636
  }
@@ -527,6 +661,41 @@
527
661
  await loadRuns();
528
662
  }
529
663
 
664
+ /** #2106: a project's Knowledge step. A missing Workspaces bridge is said, never a silent no-op. */
665
+ async function openKnowledgeStepOf(projectId) {
666
+ const open = window.flolessWorkspaces?.openKnowledgeStep;
667
+ if (typeof open !== 'function') throw new Error('FloLess couldn’t open that project’s Knowledge step. Open it from Workspaces.');
668
+ await open(projectId);
669
+ }
670
+
671
+ /** #2061: show the work a busy project is held by — its conversation in its project, or its row in Requests. */
672
+ async function openBusyHolder(holder) {
673
+ // #2106: knowledge organizing shows on its project's Knowledge step.
674
+ if (holder?.kind === 'knowledge') {
675
+ if (!(await confirmLeave())) return;
676
+ try { await openKnowledgeStepOf(holder.projectId); }
677
+ catch (error) { toast(error?.message || 'FloLess couldn’t open that project’s Knowledge step. Open it from Workspaces.', 'warn'); }
678
+ return;
679
+ }
680
+ if (holder?.kind === 'chat' && holder.owner && holder.chatId) { await openInProject({ owner: holder.owner, chatId: holder.chatId, label: holder.title }); return; }
681
+ if (holder?.requestId && typeof window.flolessBridge?.openRequest === 'function') await window.flolessBridge.openRequest(holder.requestId);
682
+ }
683
+
684
+ /** #2061: stop exactly the work the sheet named; work that already finished is said, never a different one stopped. */
685
+ async function stopBusyHolder(holder) {
686
+ if (holder?.kind === 'knowledge') return; // #2106: organizing is never stopped from here (no Stop it is offered)
687
+ try {
688
+ if (holder?.kind === 'chat' && holder.owner && holder.chatId) {
689
+ await api(`/api/chat/conversations/${encodeURIComponent(holder.chatId)}/stop`, { method: 'POST', body: { owner: holder.owner, expectTurnId: holder.turnId || undefined } });
690
+ } else if (holder?.requestId) {
691
+ await api(`/api/requests/${encodeURIComponent(holder.requestId)}/run/stop`, { method: 'POST', body: holder.leaseId ? { expectLeaseId: holder.leaseId } : {} });
692
+ }
693
+ toast(`Stopped ${holder?.kind === 'chat' ? `“${holder.title}”` : holder?.title || 'that work'}.`, 'ok');
694
+ } catch (error) {
695
+ toast(error?.code === 'stop-stale' ? 'That work had already finished, so nothing was stopped.' : error?.message || 'FloLess couldn’t stop that work.', 'warn');
696
+ }
697
+ }
698
+
530
699
  async function openInProject(target) {
531
700
  if (!(await confirmLeave())) return;
532
701
  state.dirty = false;
@@ -594,7 +763,7 @@
594
763
  wrap.append(head);
595
764
  if (!state.showArchived) {
596
765
  wrap.append(el('div', { class: 'ws-create-grid' },
597
- el('div', { class: 'ws-card ws-create ag-create', role: 'button', tabindex: '0', 'data-ag-new': '1', 'data-command-id': 'shell.agents-new' },
766
+ el('div', { class: 'ws-card ws-create ws-card-create ag-create', role: 'button', tabindex: '0', 'data-ag-new': '1', 'data-command-id': 'shell.agents-new' },
598
767
  el('div', { class: 'ws-thumb', 'aria-hidden': 'true', text: '+' }),
599
768
  el('div', { class: 'ws-body' }, el('div', {},
600
769
  el('div', { class: 'ws-name', text: 'New agent' }),
@@ -611,7 +780,7 @@
611
780
  wrap.append(el('div', { class: 'ws-grid' }, rows.map((agent) => el('div', { class: `ws-card wf-card ag-card${agent.archivedAt ? ' is-archived' : ''}`, role: 'button', tabindex: '0',
612
781
  'data-ag-id': agent.agentId, 'data-command-id': `shell.agents-open#${agent.name}`, 'data-command-instance-label': agent.name },
613
782
  el('div', { class: 'ws-body' }, el('div', { class: 'wf-card-text' },
614
- el('span', { class: 'ws-kind wf-kind', text: agent.archivedAt ? 'Archived' : agent.mode === 'compare' && agent.scope.length > 1 ? 'Compares' : 'Agent' }),
783
+ el('span', { class: 'ws-kind wf-kind', text: agent.archivedAt ? 'Archived' : agent.pausedAt ? 'Paused' : agent.mode === 'compare' && agent.scope.length > 1 ? 'Compares' : 'Agent' }),
615
784
  el('div', { class: 'ws-name', text: agent.name }),
616
785
  el('div', { class: 'ws-meta', text: scopeSummary(agent) }),
617
786
  el('div', { class: 'ws-meta wf-card-nodes', text: agent.lastRunAt ? `Last run ${agoText(agent.lastRunAt)}` : agent.lastRunUnreadable ? 'Last run unknown' : 'Never run' })))))));
@@ -625,6 +794,7 @@
625
794
  function renderPage() {
626
795
  const draft = state.draft;
627
796
  const archived = Boolean(state.agent?.archivedAt);
797
+ const paused = Boolean(state.agent?.pausedAt);
628
798
  const page = el('div', { class: 'ag-page' });
629
799
  page.append(el('div', { class: 'ag-head' },
630
800
  el('button', { type: 'button', class: 'ag-back', 'data-command-id': 'shell.agents-back', 'aria-label': 'Back to all agents', 'data-tip': 'Back to all agents', onclick: () => void openList() }, '‹ Agents'),
@@ -636,10 +806,20 @@
636
806
  archived
637
807
  ? el('button', { type: 'button', class: 'primary', 'data-command-id': 'shell.agents-restore', text: 'Restore', onclick: () => void setArchived(false) })
638
808
  : [
809
+ // #2062: Pause holds the agent's routines; a hand Run still works. One reversible click, so no confirm.
810
+ state.agent ? el('button', { type: 'button', class: 'ag-quiet', id: 'ag-pause', disabled: state.pausing,
811
+ 'data-command-id': paused ? 'shell.agents-resume' : 'shell.agents-pause', text: paused ? 'Resume' : 'Pause',
812
+ 'data-blocked-reason': state.pausing ? 'Saving this now.' : null,
813
+ 'data-tip': paused ? 'Lets its routines start it on their schedule again' : 'Stops its routines from starting it on a schedule. Run… still works.',
814
+ onclick: () => void setPaused(!paused) }) : null,
639
815
  state.agent ? el('button', { type: 'button', class: 'ag-quiet', 'data-command-id': 'shell.agents-archive', text: 'Archive', onclick: () => void setArchived(true) }) : null,
640
816
  el('button', { type: 'button', id: 'ag-save', 'data-command-id': 'shell.agents-save', disabled: state.saving || (!state.dirty && Boolean(state.agent)),
641
817
  'data-blocked-reason': state.saving ? 'Saving now.' : !state.dirty && state.agent ? 'Nothing has changed since you last saved.' : null,
642
818
  text: state.saving ? 'Saving…' : state.agent ? 'Save' : 'Create', onclick: () => void save() }),
819
+ // #2035: a routine can run this agent on a schedule, with nobody watching (saves first, like Run).
820
+ el('button', { type: 'button', id: 'ag-schedule', 'data-command-id': 'shell.agents-schedule', text: 'Schedule…',
821
+ 'data-tip': state.dirty || !state.agent ? 'Saves your changes, then opens a new routine that runs this agent' : 'Opens a new routine that runs this agent on a schedule',
822
+ onclick: () => void scheduleAgent() }),
643
823
  el('button', { type: 'button', id: 'ag-run', class: 'primary', 'data-command-id': 'shell.agents-run', text: 'Run…',
644
824
  'data-tip': state.dirty || !state.agent ? 'Saves your changes, then shows what will start' : 'Shows exactly what will start before anything runs',
645
825
  onclick: () => void openRunSheet() }),
@@ -648,7 +828,14 @@
648
828
  page.append(el('div', { class: 'ag-banner', role: 'alert' }, el('span', { text: state.banner.text }),
649
829
  state.banner.action ? el('button', { type: 'button', class: 'ag-link', 'data-command-id': state.banner.action.commandId, text: state.banner.action.label, onclick: state.banner.action.run }) : null));
650
830
  }
651
- if (archived) page.append(el('p', { class: 'ag-note', text: 'This agent is archived. Restore it to change or run it. Its past runs are below.' }));
831
+ if (archived) {
832
+ page.append(el('p', { class: 'ag-note', text: paused
833
+ ? 'This agent is archived and paused. Restore it to change or run it; its routines stay paused until you resume it. Its past runs are below.'
834
+ : 'This agent is archived, so its routines don’t start it. Restore it to change or run it. Its past runs are below.' }));
835
+ } else if (paused) {
836
+ page.append(el('p', { class: 'ag-note', id: 'ag-paused-note', role: 'status',
837
+ text: 'Paused. Its routines won’t start it on a schedule until you resume it. Run… still works.' }));
838
+ }
652
839
 
653
840
  // What it does
654
841
  const count = el('div', { class: 'ag-count', id: 'ag-count', 'aria-live': 'polite' });
@@ -709,7 +896,7 @@
709
896
  el('div', {},
710
897
  el('div', { class: 'ag-label', id: 'ag-allow-label', text: 'Can change files' }),
711
898
  el('p', { class: 'ag-help', text: draft.allowChanges
712
- ? 'On: it may change files in the project or workflow its conversation is homed in. A file edit anywhere else asks you first; commands follow your Claude or Codex approval settings.'
899
+ ? 'On: it works in Auto, like AI Chat — safe changes in the project or workflow its conversation is homed in go ahead by themselves, and risky steps are checked first. Claude asks you before an edit anywhere else; Codex’s own review may approve one and notes each decision. When a routine runs it with nobody watching, anything that would ask you is declined and listed for you.'
713
900
  : 'Off: it only reads and reports.' }))));
714
901
  page.append(el('p', { class: 'ag-note', text: isolationNote(draft.mode, draft.allowChanges) }));
715
902
 
@@ -774,11 +961,13 @@
774
961
 
775
962
  const LIVE_LABEL = {
776
963
  waiting: 'Waiting', starting: 'Starting', working: 'Working', 'waiting-for-you': 'Waiting for you', 'needs-recovery': 'Needs you',
964
+ // #2105: it waited the full time for busy work, changed nothing, and stopped; "Start this one again" is the answer.
965
+ 'needs-you': 'Needs you',
777
966
  done: 'Done', 'failed-reply': 'Stopped with an error', stopped: 'Stopped', skipped: 'Skipped', failed: 'Didn’t start',
778
967
  uncertain: 'Not sure it started', stale: 'Earlier workspace', archived: 'Archived', unreadable: 'Can’t open',
779
968
  };
780
969
  const LIVE_TONE = {
781
- working: 'accent', starting: 'accent', 'waiting-for-you': 'warn', 'needs-recovery': 'warn', done: 'ok', 'failed-reply': 'err',
970
+ working: 'accent', starting: 'accent', 'waiting-for-you': 'warn', 'needs-recovery': 'warn', 'needs-you': 'warn', done: 'ok', 'failed-reply': 'err',
782
971
  failed: 'warn', uncertain: 'warn', unreadable: 'warn',
783
972
  };
784
973
 
@@ -799,16 +988,24 @@
799
988
  }
800
989
  for (const run of state.runs) {
801
990
  const group = el('div', { class: 'ag-run' });
802
- group.append(el('div', { class: 'ag-run-meta', text: `${timeText(run.startedAt)} · ${run.provider === 'codex' ? 'Codex' : 'Claude'} · ${run.allowChanges ? 'can change files' : 'read only'}${run.mode === 'compare' ? ' · compare' : ''}` }));
991
+ const origin = run.startedBy ? `Started by routine “${run.startedBy.routineName}” · ` : '';
992
+ group.append(el('div', { class: 'ag-run-meta', text: `${origin}${timeText(run.startedAt)} · ${run.provider === 'codex' ? 'Codex' : 'Claude'} · ${run.allowChanges ? 'can change files' : 'read only'}${run.mode === 'compare' ? ' · compare' : ''}` }));
993
+ // #2035: FloLess sees what it declined, not what Claude's own safety check held back by itself.
994
+ if (run.startedBy && run.provider === 'claude' && run.allowChanges) {
995
+ group.append(el('p', { class: 'ag-help', text: 'Claude’s own safety check may also have held steps back; those appear only in its reply.' }));
996
+ }
803
997
  for (const target of run.targets) {
804
998
  const selected = state.selected?.runId === run.runId && state.selected?.index === target.index;
805
- const canOpen = Boolean(target.chatId) && !['stale', 'skipped', 'unreadable'].includes(target.live);
999
+ // #2060: a run from an earlier workspace folder keeps its conversation when this folder can still open it; the
1000
+ // server sends its id only then, and its message says plainly when it can't.
1001
+ const canOpen = Boolean(target.chatId) && !['skipped', 'unreadable'].includes(target.live);
806
1002
  const row = el('div', { class: `ag-target${selected ? ' is-selected' : ''}`, 'aria-current': selected ? 'true' : null });
807
1003
  const label = target.covers.length > 1 ? target.covers.join(' · ') : target.label;
808
1004
  const info = el('div', { class: 'ag-target-info' },
809
1005
  el('span', { class: 'ag-target-name', text: label }),
810
1006
  el('span', { class: `ag-state${LIVE_TONE[target.live] ? ` tone-${LIVE_TONE[target.live]}` : ''}`, text: LIVE_LABEL[target.live] || target.live }),
811
- target.message ? el('span', { class: 'ag-target-msg', text: target.message }) : null);
1007
+ target.message ? el('span', { class: 'ag-target-msg', text: target.message }) : null,
1008
+ questionsFor(run, target, label));
812
1009
  row.append(info);
813
1010
  const actions = el('div', { class: 'ag-target-actions' });
814
1011
  if (canOpen) {
@@ -879,6 +1076,42 @@
879
1076
  if (state.chatScope) return { owner: state.chatScope.owner, label: state.chatScope.label, chatId: state.chatScope.chatId };
880
1077
  return { owner: { kind: 'workspace' }, label: state.view === 'page' && state.agent ? `Agents · ${state.agent.name}` : 'All projects and workflows' };
881
1078
  },
1079
+ /** #2035: the Routines editor lists this folder's agents through the same chat session as this page. */
1080
+ async list() {
1081
+ const body = await api('/api/chat/agents');
1082
+ return body.agents || [];
1083
+ },
1084
+ /** #2035: a routine's history row asks how the agent run it started is going. */
1085
+ async runs(agentId) {
1086
+ return api(`/api/chat/agents/${encodeURIComponent(agentId)}/runs`);
1087
+ },
1088
+ /** #2035: a routine fire ended; an open agent page reads its runs again so the run it started shows up. */
1089
+ refreshRuns() {
1090
+ if (state.open && state.view === 'page' && state.agent) void loadRuns();
1091
+ },
1092
+ /** #2062: an agent was paused, resumed, archived or restored (maybe in another tab). */
1093
+ refreshAgent(agentId) { void refreshAgentState(agentId); },
1094
+ /**
1095
+ * #2046: a Guide suggestion — a new agent's page with its name and instructions filled in. Nothing is saved until the
1096
+ * person reviews it and presses Save.
1097
+ */
1098
+ async newDraft(prefill = {}) {
1099
+ await window.flolessWorkspaces?.setMode?.('agents');
1100
+ if (!state.open) return false;
1101
+ await openAgent(null);
1102
+ if (state.view !== 'page' || state.agent || !state.draft) return false;
1103
+ if (typeof prefill.name === 'string') state.draft.name = prefill.name.slice(0, 120);
1104
+ if (typeof prefill.instructions === 'string') state.draft.instructions = prefill.instructions.slice(0, 2000);
1105
+ state.dirty = true;
1106
+ paint();
1107
+ $surface.querySelector('#ag-name')?.focus();
1108
+ return true;
1109
+ },
1110
+ /** #2035: open an agent's page (its runs are listed there), from the Routines list. */
1111
+ async open(agentId) {
1112
+ await window.flolessWorkspaces?.setMode?.('agents');
1113
+ if (state.open) await openAgent(agentId);
1114
+ },
882
1115
  /** For AI Chat's context line: which Agents surface is on screen. */
883
1116
  surface: () => (state.view === 'page' ? 'agent-page' : 'agent-list'),
884
1117
  };