@floless/app 0.165.0 → 0.166.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.
@@ -1339,6 +1339,15 @@
1339
1339
  reads as a different pane rather than the same one in a different state. */
1340
1340
  const HIST_HEAD = '<div class="step-head"><span>History</span></div>';
1341
1341
 
1342
+ // #2470 R6.5b: a module project's History step has two views, its approval ledger ('approvals', the default) and its
1343
+ // activity journal ('activity'), chosen with the switch at the end of the step row. The choice holds while the same
1344
+ // project stays open; another project opens on Approvals, the view of record. Plan 2026-10-30-2470-r6-5b-module-journal-PLAN.md.
1345
+ let historyView = { project: null, view: 'approvals' };
1346
+ const historyViewKey = (project) => `${project.id}|${String(project.uuid || '').toLowerCase()}`;
1347
+ /** Whether kind `d`'s History step has the two views: it is the approval ledger's `history` step (a module kind). */
1348
+ function hasHistoryViews(d) { return !!d?.steps?.some((x) => x.key === 'history'); }
1349
+ const APPROVALS_TIP = 'Approved versions, saved work and rollback.';
1350
+
1342
1351
  /**
1343
1352
  * The server's own plain-English refusal for a project that cannot be signed off at all, or `''`
1344
1353
  * when approval is merely unavailable for the moment (loading, a failed probe, nothing read yet).
@@ -2092,11 +2101,11 @@
2092
2101
  || !['available', 'unavailable'].includes(registration.status)) {
2093
2102
  throw new Error('The project view no longer matches this registration.');
2094
2103
  }
2095
- const wasUnits = cached.displayUnits === 'mm' ? 'mm' : 'ft-in';
2104
+ const wasUnits = (cached?.displayUnits === 'mm' || cached?.displayUnits === 'ft-in' ? cached.displayUnits : cached?.environment === 'UK' ? 'mm' : 'ft-in');
2096
2105
  const wasApproved = cached.approvedAt;
2097
2106
  const wasSortKeys = { name: cached.name, createdAt: cached.createdAt, updatedAt: cached.updatedAt };
2098
2107
  Object.assign(cached, fresh, {
2099
- displayUnits: fresh.displayUnits === 'mm' ? 'mm' : 'ft-in',
2108
+ displayUnits: (fresh?.displayUnits === 'mm' || fresh?.displayUnits === 'ft-in' ? fresh.displayUnits : fresh?.environment === 'UK' ? 'mm' : 'ft-in'),
2100
2109
  registrationState: registration.status,
2101
2110
  registrationRevision: registration.entryRevision,
2102
2111
  registrationReason: registration.reason,
@@ -2288,7 +2297,7 @@
2288
2297
  // that never had a unit choice arrives as `undefined` — and assigning that raw made the
2289
2298
  // `!==` test true on every `projects-changed`, discarding the server's `exportUnits` and
2290
2299
  // repainting for nothing. (Review round 5.)
2291
- const freshUnits = mine.displayUnits === 'mm' ? 'mm' : 'ft-in';
2300
+ const freshUnits = (mine?.displayUnits === 'mm' || mine?.displayUnits === 'ft-in' ? mine.displayUnits : mine?.environment === 'UK' ? 'mm' : 'ft-in');
2292
2301
  const freshName = typeof mine.name === 'string' ? mine.name : current.name;
2293
2302
  if (current && current.id === id && current.name !== freshName) {
2294
2303
  current.name = freshName;
@@ -3888,9 +3897,20 @@
3888
3897
  else localStorage.removeItem(PROJECT_CHAT_INTAKE_KEY);
3889
3898
  }
3890
3899
 
3891
- function setProjectSetupError(message, { workspaceAction = false } = {}) {
3900
+ function setProjectSetupError(message, { workspaceAction = false, withoutLinkAction = null } = {}) {
3892
3901
  $projectSetupError.hidden = !message;
3893
3902
  $projectSetupError.textContent = message || '';
3903
+ // #2470 R6.7b: a link to the General project that can't be made is a choice, never a refusal.
3904
+ if (message && withoutLinkAction) {
3905
+ const action = document.createElement('button');
3906
+ action.type = 'button';
3907
+ action.className = 'project-setup-error-action';
3908
+ action.textContent = 'Create without linking';
3909
+ action.setAttribute('data-command-id', 'shell.project-setup-without-link');
3910
+ action.setAttribute('data-tip', 'Creates the project and starts its chat without linking it. You can link it later from the General project’s Modules step.');
3911
+ action.addEventListener('click', withoutLinkAction);
3912
+ $projectSetupError.append(' ', action);
3913
+ }
3894
3914
  if (message && workspaceAction) {
3895
3915
  const action = document.createElement('button');
3896
3916
  action.type = 'button';
@@ -3904,6 +3924,24 @@
3904
3924
  }
3905
3925
  }
3906
3926
 
3927
+ /**
3928
+ * #2470 R6.7b: why the General project can't take the link now, named the way the person knows it, and the choice. The
3929
+ * server's sentence is kept only where it already says what to do (a busy project says to wait).
3930
+ */
3931
+ function projectSetupLinkChoiceMessage(state, code, serverText) {
3932
+ const general = state.linkFrom?.name ? `“${state.linkFrom.name}”` : 'The General project';
3933
+ const why = {
3934
+ 'project-archived': `${general} was archived, so it can’t take the link.`,
3935
+ 'project-not-found': `${general} is no longer in this Workspace, so it can’t take the link.`,
3936
+ 'not-general': `${general} is no longer in this Workspace, so it can’t take the link.`,
3937
+ 'project-unavailable': `${general}’s folder can’t be read right now, so it can’t take the link.`,
3938
+ 'project-links-stale': `${general} or the Workspace changed since this dialog opened, so it can’t take the link.`,
3939
+ 'project-links-changed': `${general}’s modules changed since this dialog opened, so it can’t take the link.`,
3940
+ }[code] || String(serverText || `${general} can’t take the link right now.`).trim();
3941
+ const name = String(state.name || '').trim();
3942
+ return `${why} You can still create ${name ? `“${name}”` : 'the project'} without linking it.`;
3943
+ }
3944
+
3907
3945
  function projectSetupErrorMessage(error) {
3908
3946
  // A sentence the server wrote for the person (#1965 review) — what to fix, or what restarting costs —
3909
3947
  // names their own folders, so it is shown as written rather than run through the filter below.
@@ -3962,7 +4000,7 @@
3962
4000
  $projectSetupCreate.textContent = label || 'Create project & start chat';
3963
4001
  $projectSetupCreateOnly.textContent = busy && !projectSetupState.settingUp
3964
4002
  ? 'Creating…'
3965
- : projectSetupState.linkFrom ? 'Create project' : createOnlyLabel(projectSetupState.kind);
4003
+ : createOnlyLabel(projectSetupState.kind);
3966
4004
  if (!busy) {
3967
4005
  $projectSetupCreate.disabled = !projectSetupReady();
3968
4006
  $projectSetupCreateOnly.disabled = !projectSetupReady();
@@ -3995,7 +4033,7 @@
3995
4033
  // Setup kinds that start from no file at all: a Drawing Checker profile and a General project.
3996
4034
  const NO_FILE_SETUP_KINDS = ['drawing-check-profile', 'general-project'];
3997
4035
  function projectSetupProvider(state) {
3998
- if (!state || NO_CHAT_SETUP_KINDS.includes(state.kind) || state.linkFrom) return null;
4036
+ if (!state || NO_CHAT_SETUP_KINDS.includes(state.kind)) return null;
3999
4037
  const runtimes = bridge.chatProviderRuntimes?.() || [];
4000
4038
  const readiness = (id) => (id ? projectSetupProviderReadiness(runtimes.find((runtime) => runtime.id === id)) : 'unavailable');
4001
4039
  const canStart = (id) => readiness(id) !== 'unavailable';
@@ -4217,7 +4255,7 @@
4217
4255
  const $sourceKicker = $projectSetupSourceName.previousElementSibling;
4218
4256
  if ($sourceKicker) $sourceKicker.textContent = state.kind === 'general-project' ? 'Starting point' : 'Source';
4219
4257
  $projectSetupSourceName.parentElement?.setAttribute('aria-label', state.kind === 'general-project' ? 'Starting point' : 'Selected source drawings');
4220
- $projectSetupCreateOnly.textContent = state.busy ? 'Creating…' : state.linkFrom ? 'Create project' : createOnlyLabel(state.kind);
4258
+ $projectSetupCreateOnly.textContent = state.busy ? 'Creating…' : createOnlyLabel(state.kind);
4221
4259
  $projectSetupSourceCount.textContent = state.files.length > 1 ? `+ ${state.files.length - 1} more` : '';
4222
4260
  $projectSetupFolder.textContent = state.directory
4223
4261
  ? state.directory.path
@@ -4404,10 +4442,14 @@
4404
4442
  ...(state.sentBuildMode === 'quick' ? { buildMode: 'quick' } : {}),
4405
4443
  ...(state.sentBuildMode === 'quick' && state.sentFilterChoice === 'ai' ? { quickFilterByAi: true } : {}),
4406
4444
  ...(state.sentBuildMode === 'quick' && state.sentFilterChoice === 'ai' && state.sentExclusionsChoice === 'ai' ? { quickFilterExclusionsByAi: true } : {}),
4445
+ // #2470 R6.7b: added from a General project's Modules step, the project is made already linked there.
4446
+ ...(state.linkFrom ? { linkFrom: { projectId: state.linkFrom.projectId, sourceUuid: state.linkFrom.sourceUuid, rootId: state.linkFrom.rootId } } : {}),
4447
+ ...(state.linkFrom && state.withoutLink ? { withoutLink: true } : {}),
4407
4448
  });
4408
4449
  const project = result.project;
4409
4450
  state.project = project;
4410
4451
  state.request = result.request;
4452
+ state.moduleLink = result.moduleLink || null;
4411
4453
  state.buildModeNotice = result.buildModeNotice || null;
4412
4454
  if (!projects.some((item) => item.id === project.id)) {
4413
4455
  projects.unshift(project);
@@ -4428,13 +4470,25 @@
4428
4470
  $projectSetupFolderChoose.textContent = 'Choose…';
4429
4471
  }
4430
4472
  const outsideWorkspace = code === 'project-directory-outside-root';
4431
- setProjectSetupError(projectSetupErrorMessage(error), { workspaceAction: outsideWorkspace });
4473
+ // #2470 R6.7b: the server's own sentence on why the link can't be made, and the choice to go on without it.
4474
+ const linkChoice = startChat && state.linkFrom && error?.linkChoice === true;
4475
+ setProjectSetupError(linkChoice ? projectSetupLinkChoiceMessage(state, code, error.message) : projectSetupErrorMessage(error), {
4476
+ workspaceAction: outsideWorkspace,
4477
+ withoutLinkAction: linkChoice ? () => { state.withoutLink = true; void createProjectFromSetup(true); } : null,
4478
+ });
4432
4479
  setProjectSetupBusy(false);
4433
4480
  renderProjectSetup();
4434
4481
  return;
4435
4482
  }
4436
4483
  setProjectSetupBusy(false);
4437
4484
  closeProjectSetup({ restoreFocus: false });
4485
+ if (state.linkFrom) {
4486
+ // #2470 R6.7b: one message from the real outcome — the link to the General project, then what the chat is doing.
4487
+ globalThis.flolessProjectModules?.afterCreate?.({ project: state.project, linkFrom: state.linkFrom, moduleLink: state.moduleLink,
4488
+ outcome: 'ok', next: state.request?.buildMode === 'quick' ? 'The Quick model read is running in AI Chat.' : 'The drawing task is running in AI Chat.' });
4489
+ if (state.buildModeNotice?.why) showToast(state.buildModeNotice.why, 'warn');
4490
+ return;
4491
+ }
4438
4492
  // A General project's chat is Flo's kickoff; its first reply may still be on its way (#2470 R6.4).
4439
4493
  // #2521 row 7a: said from what was queued, never from the button still pressed.
4440
4494
  if (state.buildModeNotice?.why) showToast(`Project created. ${state.buildModeNotice.why}`, 'warn');
@@ -4444,6 +4498,24 @@
4444
4498
  : 'Project created — the drawing task is running in AI Chat.', 'ok');
4445
4499
  }
4446
4500
 
4501
+ // #2470 R6.7b: a recovery that asked the person to choose about the link is asked once per page.
4502
+ const projectChatIntakeLinkChoiceShown = new Set();
4503
+ async function recoverProjectChatIntake(submissionId, options) {
4504
+ const result = await bridge.resumeProjectChatIntake(submissionId, options);
4505
+ if (!result) return;
4506
+ if (!projects.some((item) => item.id === result.project.id)) projects.unshift(result.project);
4507
+ await openProject(result.project.id, result.project.app === 'floless-general' ? 'knowledge' : 'drawings');
4508
+ await bridge.openChatConversation(result.chat.chatId);
4509
+ forgetProjectChatIntake(submissionId);
4510
+ // #2470 R6.7b: started from a General project's Modules step: say what became of the link, never a silent "linked".
4511
+ const unlinked = result.moduleLink && result.moduleLink.ok === false
4512
+ ? (result.moduleLink.code === 'link-skipped' ? ' It isn’t linked to the General project, as you chose.'
4513
+ : ' It couldn’t be linked to the General project; link it from that project’s Modules step.')
4514
+ : '';
4515
+ // #2521 row 7a: a Quick choice queued Precise is said on recovery too, from the saved receipt.
4516
+ if (result.buildModeNotice?.why) showToast(`Recovered the project and its AI Chat.${unlinked} ${result.buildModeNotice.why}`, 'warn');
4517
+ else showToast(`Recovered the project and its AI Chat.${unlinked}`, unlinked && result.moduleLink.code !== 'link-skipped' ? 'warn' : 'ok');
4518
+ }
4447
4519
  async function resumeInterruptedProjectChatIntake() {
4448
4520
  if (projectChatIntakeRecoveryStarted) return;
4449
4521
  const submissionIds = pendingProjectChatIntakes();
@@ -4451,18 +4523,26 @@
4451
4523
  projectChatIntakeRecoveryStarted = true;
4452
4524
  for (const submissionId of submissionIds) {
4453
4525
  try {
4454
- const result = await bridge.resumeProjectChatIntake(submissionId);
4455
- if (!result) continue;
4456
- if (!projects.some((item) => item.id === result.project.id)) projects.unshift(result.project);
4457
- await openProject(result.project.id, result.project.app === 'floless-general' ? 'knowledge' : 'drawings');
4458
- await bridge.openChatConversation(result.chat.chatId);
4459
- forgetProjectChatIntake(submissionId);
4460
- // #2521 row 7a: a Quick choice queued Precise is said on recovery too, from the saved receipt.
4461
- if (result.buildModeNotice?.why) showToast(`Recovered the project and its AI Chat. ${result.buildModeNotice.why}`, 'warn');
4462
- else showToast('Recovered the project and its AI Chat.', 'ok');
4526
+ await recoverProjectChatIntake(submissionId);
4463
4527
  } catch (error) {
4464
4528
  const code = error && (error.code || error.body && error.body.code);
4465
- if (code === 'project-intake-not-found' || code === 'project-intake-damaged') {
4529
+ if (error?.linkChoice === true) {
4530
+ // The General project it was started from can't take the link now: ask once per page, never decide for them.
4531
+ // It stays until the person acts on it; a choice that fails is offered again.
4532
+ if (!projectChatIntakeLinkChoiceShown.has(submissionId)) {
4533
+ projectChatIntakeLinkChoiceShown.add(submissionId);
4534
+ showToast(`A project you started from a General project wasn’t created yet. ${projectSetupLinkChoiceMessage({}, code, error.message)}`, 'warn', {
4535
+ persistent: true,
4536
+ action: { label: 'Create without linking', commandId: 'shell.project-setup-recover-without-link',
4537
+ onClick: () => recoverProjectChatIntake(submissionId, { withoutLink: true }).catch((retryError) => {
4538
+ projectChatIntakeLinkChoiceShown.delete(submissionId);
4539
+ showToast(projectSetupErrorMessage(retryError), 'error');
4540
+ projectChatIntakeRecoveryStarted = false;
4541
+ void resumeInterruptedProjectChatIntake();
4542
+ }) },
4543
+ });
4544
+ }
4545
+ } else if (code === 'project-intake-not-found' || code === 'project-intake-damaged') {
4466
4546
  forgetProjectChatIntake(submissionId);
4467
4547
  } else if (code === 'project-intake-project-missing') {
4468
4548
  // The project this setup made was removed or replaced: nothing is left to resume, so say so once (#2470 R6.4).
@@ -4523,7 +4603,7 @@
4523
4603
  renderProjectSetup();
4524
4604
  $projectSetup.classList.add('show');
4525
4605
  $projectSetupFolderChoose.focus();
4526
- if (!NO_CHAT_SETUP_KINDS.includes(kind) && !linkFrom) void refreshProjectSetupProviders(state);
4606
+ if (!NO_CHAT_SETUP_KINDS.includes(kind)) void refreshProjectSetupProviders(state);
4527
4607
  try {
4528
4608
  if (kind !== 'tekla-source') {
4529
4609
  await Promise.all(files.map(assertProjectSourceReadable));
@@ -5383,6 +5463,8 @@
5383
5463
  if (!nav.skipLeaveGuard && current && current.id !== p.id && !(await leaveOpenProject(nav.returnFocus))) return STAYED_IN_PROJECT;
5384
5464
  if (unwanted()) return STAYED_IN_PROJECT;
5385
5465
  if (current?.uuid !== p.uuid) revisionNoteEditorGeneration++;
5466
+ // #2470 R6.5b: the History view chosen on the project being left is not carried back to it after another one.
5467
+ if (current?.uuid !== p.uuid || current?.id !== p.id) historyView = { project: null, view: 'approvals' };
5386
5468
  current = p;
5387
5469
  // #2470 R6.6c: whatever editor is still loaded belongs to the project as it was before this open, and the frame is
5388
5470
  // reset below; until the new document says it is ready, no step message goes to the old one.
@@ -5530,7 +5612,9 @@
5530
5612
  applyModelPresence(present);
5531
5613
  // Restore only when this same project's authoritative answer says a model exists. A confirmed
5532
5614
  // preliminary lifecycle remains on Drawing Filter and gets the real prerequisite gate below.
5533
- if (present === 'model' && restore && currentStep === 'drawings') setStep(restore);
5615
+ // #2470 R6.5b: History on a kind with two views is never gated (its Activity view needs no model), so it is
5616
+ // restored on any known answer too, and opens on Activity when Approvals still has to wait.
5617
+ if (restore && currentStep === 'drawings' && (present === 'model' || (present !== 'unknown' && restore === 'history' && !stageGateFor(restore)))) setStep(restore);
5534
5618
  return true;
5535
5619
  })();
5536
5620
  modelPresenceProbe = { projectId, promise };
@@ -6371,8 +6455,11 @@
6371
6455
  : 'Then press Save filter in the top-right corner. After Save, return to the terminal AI that prepared it and tell it to continue.';
6372
6456
  }
6373
6457
 
6374
- function stageGateFor(step) {
6458
+ function stageGateFor(step, opts) {
6375
6459
  const d = wsApp();
6460
+ // #2470 R6.5b: the History step's Activity view needs no model, so where the step has two views it is never locked;
6461
+ // only its Approvals view is (`{ ledger: true }` asks for that), and syncHistoryViews opens the step on Activity then.
6462
+ if (step === 'history' && !opts?.ledger && typeof hasHistoryViews === 'function' && hasHistoryViews(d)) return '';
6376
6463
  if (!d || !d.filter || !['model', 'rfis', 'exports', 'history'].includes(step)) return '';
6377
6464
  const initialRead = revCardReq && isInitialRevisionRead(revCardReq);
6378
6465
  const waitingForInitial = initialRead && lastRevState === 'pending';
@@ -6406,15 +6493,23 @@
6406
6493
  if (projectContractLifecycle === 'filter-checkpoint') return 'Attach the drawing set again in Drawing Filter to restart the read. The earlier request is no longer available to receive a saved filter.';
6407
6494
  return 'Read and save a Drawing Filter first. The model will unlock after the first drawing read.';
6408
6495
  }
6409
- if (waitingForInitial) return `The ${step === 'exports' ? 'steel model' : 'first model'} must be ready before ${step === 'exports' ? 'exports' : 'history'} is available.`;
6496
+ // The History step's own gate names the step; its Approvals view's gate (#2470 R6.5b) names that view, and RFIs names RFIs.
6497
+ const later = step === 'exports' ? 'Exports' : step === 'rfis' ? 'RFIs' : opts?.ledger ? 'Approvals' : 'History';
6498
+ if (waitingForInitial) return `The ${step === 'exports' ? 'steel model' : 'first model'} must be ready before ${step === 'exports' ? 'exports' : step === 'rfis' ? 'RFIs' : opts?.ledger ? 'approvals' : 'history'} ${opts?.ledger || step === 'rfis' ? 'are' : 'is'} available.`;
6410
6499
  if (projectContractLifecycle === 'filter-checkpoint' && !revisionListKnown) return 'Checking the drawing read. Stages open once FloLess knows where it stands.';
6411
- if (projectContractLifecycle === 'filter-checkpoint') return `Attach the drawing set again in Drawing Filter before opening ${step === 'exports' ? 'Exports' : 'History'}. The earlier request can no longer continue.`;
6412
- return `Create the first steel model before opening ${step === 'exports' ? 'Exports' : 'History'}.`;
6500
+ if (projectContractLifecycle === 'filter-checkpoint') return `Attach the drawing set again in Drawing Filter before opening ${later}. The earlier request can no longer continue.`;
6501
+ return `Create the first steel model before opening ${later}.`;
6413
6502
  }
6414
6503
 
6415
6504
  function applyStageGating() {
6416
6505
  const d = wsApp();
6417
6506
  if (!$stepTabs) return;
6507
+ // The History step's Approvals view has its own gate (#2470 R6.5b): repaint the switch as the model arrives or goes.
6508
+ if (typeof syncHistoryViews === 'function' && typeof currentStep !== 'undefined') {
6509
+ const activity = syncHistoryViews(currentStep, d);
6510
+ // A gate that appears under the open ledger moves the step to Activity (once: setStep leaves the panes matching).
6511
+ if (currentStep === 'history' && activity && !$wsHistory.hidden) setStep('history');
6512
+ }
6418
6513
  if (!d || !d.filter) {
6419
6514
  // The tab strip is shared across projects. Remove every steel-only gate when switching to an
6420
6515
  // app without a Drawing Filter, or the next app inherits disabled tabs from the previous one.
@@ -6518,7 +6613,7 @@
6518
6613
  return;
6519
6614
  }
6520
6615
  const guidance = stagedInitial
6521
- ? 'The drawing read is complete · Open Drawing Filter and choose Review changes before moving to Model, Exports, or History.'
6616
+ ? 'The drawing read is complete · Open Drawing Filter and choose Review changes before moving to Model, Exports, or Approvals in History.'
6522
6617
  : failedInitial
6523
6618
  ? (revCardReq?.canClear === true
6524
6619
  ? 'The drawing read failed · Return to Drawing Filter, press Dismiss, then attach the drawing set again.'
@@ -6561,7 +6656,7 @@
6561
6656
  : 'Checking the drawing read · FloLess is looking up this project’s drawing request.')
6562
6657
  : projectContractLifecycle === 'filter-checkpoint'
6563
6658
  ? 'Drawing read needs restarting · The earlier drawing request is no longer available. Attach the drawing set again in Drawing Filter to restart the read.'
6564
- : 'Start in Drawing Filter by attaching a PDF drawing set. The Model, Exports, and History stages unlock after the first steel model is created.';
6659
+ : 'Start in Drawing Filter by attaching a PDF drawing set. The Model and Exports stages, and Approvals in History, unlock after the first steel model is created. History’s Activity is open now.';
6565
6660
  paintStageGuidance(guidance, failedInitial || unavailableInitial ? 'failed' : 'info');
6566
6661
  if (waitingForInitial && revCardReq?.prepassReady && !revCardReq?.filterCheckpointCurrent) {
6567
6662
  appendStageGuidanceFilterAction();
@@ -6607,6 +6702,60 @@
6607
6702
  return true;
6608
6703
  }
6609
6704
 
6705
+ /**
6706
+ * Show or hide the History view switch for step `s` and say which view it is on. Returns true when the step shows the
6707
+ * activity journal instead of the ledger. Called from setStep, which reaches it through `typeof` (harnesses lift
6708
+ * setStep alone).
6709
+ */
6710
+ function syncHistoryViews(s, d) {
6711
+ const project = typeof current !== 'undefined' ? current : null;
6712
+ const shown = s === 'history' && hasHistoryViews(d) && !!project;
6713
+ // Before a Steel project's first model the ledger has nothing to show and its readiness checks would refuse, so the
6714
+ // step opens on Activity and Approvals says why instead (nothing refuses: the step still opens).
6715
+ const ledgerGate = shown ? stageGateFor('history', { ledger: true }) : '';
6716
+ // Opened on Activity for that reason, it stays there when the model arrives: the view never changes under the person.
6717
+ if (ledgerGate) historyView = { project: historyViewKey(project), view: 'activity' };
6718
+ const view = shown && historyView.project === historyViewKey(project) ? historyView.view : 'approvals';
6719
+ const box = document.getElementById('ws-history-views');
6720
+ if (box) {
6721
+ box.hidden = !shown;
6722
+ for (const b of box.querySelectorAll('[data-history-view]')) {
6723
+ const on = b.dataset.historyView === view;
6724
+ b.setAttribute('aria-checked', String(on));
6725
+ b.setAttribute('tabindex', on ? '0' : '-1');
6726
+ if (b.dataset.historyView !== 'approvals') continue;
6727
+ if (ledgerGate) { b.setAttribute('aria-disabled', 'true'); b.dataset.tip = ledgerGate; }
6728
+ else { b.removeAttribute('aria-disabled'); b.dataset.tip = APPROVALS_TIP; }
6729
+ }
6730
+ }
6731
+ return shown && view === 'activity';
6732
+ }
6733
+ /** The person picked a History view: remember it for this project, show it, and keep focus on the choice. */
6734
+ function chooseHistoryView(view) {
6735
+ if (!current || currentStep !== 'history' || (view !== 'approvals' && view !== 'activity')) return;
6736
+ const ledgerGate = view === 'approvals' ? stageGateFor('history', { ledger: true }) : '';
6737
+ if (ledgerGate) { showToast(ledgerGate, 'warn'); return; }
6738
+ const was = syncHistoryViews('history', wsApp()) ? 'activity' : 'approvals';
6739
+ historyView = { project: historyViewKey(current), view };
6740
+ if (was === view) return;
6741
+ setStep('history');
6742
+ document.querySelector(`#ws-history-views [data-history-view="${view}"]`)?.focus();
6743
+ }
6744
+ {
6745
+ const box = document.getElementById('ws-history-views');
6746
+ box?.addEventListener('click', (e) => {
6747
+ const b = e.target.closest('[data-history-view]');
6748
+ if (b) chooseHistoryView(b.dataset.historyView);
6749
+ });
6750
+ // Arrow keys move the choice, as in any radio group; Space and Enter press the focused one (a button already does).
6751
+ box?.addEventListener('keydown', (e) => {
6752
+ if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key)) return;
6753
+ e.preventDefault();
6754
+ const checked = box.querySelector('[aria-checked="true"]')?.dataset.historyView;
6755
+ chooseHistoryView(checked === 'activity' ? 'approvals' : 'activity');
6756
+ });
6757
+ }
6758
+
6610
6759
  /**
6611
6760
  * A step the PERSON picked (a tab or a "go to" link), as opposed to one the shell restores. While a
6612
6761
  * project opens, `pendingPresenceStep` holds the step to restore once the lifecycle probe answers;
@@ -6644,6 +6793,7 @@
6644
6793
  b.classList.toggle('active', on);
6645
6794
  b.setAttribute('aria-selected', String(on));
6646
6795
  });
6796
+ if (typeof revealActiveStepTab === 'function') revealActiveStepTab();
6647
6797
  // An app with no filter (vectorize) has an empty `drawings` frame URL — never src it; its Source
6648
6798
  // step shows a lightweight placeholder pane instead of an about:blank iframe.
6649
6799
  const d = wsApp();
@@ -6698,8 +6848,12 @@
6698
6848
  const showExports = s === 'exports';
6699
6849
  $wsExports.hidden = !showExports;
6700
6850
  if (showExports) safeRenderExports('when you opened the Exports step');
6701
- // History is likewise a shell-rendered pane: the project's version ledger.
6702
- const showHistory = s === 'history';
6851
+ // History is likewise a shell-rendered pane: the project's version ledger. On a module project its step has a second
6852
+ // view, the activity journal (#2470 R6.5b), which shows in the journal pane below instead of the ledger.
6853
+ const historyActivity = typeof syncHistoryViews === 'function' && syncHistoryViews(s, d);
6854
+ const showHistory = s === 'history' && !historyActivity;
6855
+ // Leaving the ledger by any route (another step, its Activity view, or a gate that appeared) ends what it started.
6856
+ if (!showHistory && !$wsHistory.hidden && typeof leaveHistoryLedger === 'function') leaveHistoryLedger();
6703
6857
  $wsHistory.hidden = !showHistory;
6704
6858
  if (showHistory) renderHistory();
6705
6859
  else { closeRollbackConfirm(); closeBaseMenu(); } // don't leave a popover open behind a step switch
@@ -6745,14 +6899,15 @@
6745
6899
  const project = typeof current !== 'undefined' ? current : null;
6746
6900
  if (showModules && project && window.flolessProjectModules) window.flolessProjectModules.render($modulesPane, project);
6747
6901
  }
6748
- // #2470 R6.5: a General project's History is a shell-rendered pane too: its journal (project-history.js). Reached
6902
+ // #2470 R6.5: a General project's History is a shell-rendered pane too: its journal (project-history.js); #2470 R6.5b:
6903
+ // so is a module project's History step on its Activity view (historyActivity, above). Reached
6749
6904
  // through globalThis, like the RFIs one, so a harness that lifts setStep without it still runs.
6750
6905
  const $journalPane = document.getElementById('ws-journal');
6751
6906
  if ($journalPane) {
6752
- const showJournal = s === 'journal';
6907
+ const showJournal = s === 'journal' || historyActivity;
6753
6908
  $journalPane.hidden = !showJournal;
6754
6909
  const project = typeof current !== 'undefined' ? current : null;
6755
- if (showJournal && project) globalThis.flolessProjectHistory?.render?.($journalPane, project);
6910
+ if (showJournal && project) globalThis.flolessProjectHistory?.render?.($journalPane, project, historyActivity ? { variant: 'module' } : undefined);
6756
6911
  }
6757
6912
  // Knowledge is a shell-rendered pane too: the project's Knowledge Base (References column).
6758
6913
  const showKnowledge = s === 'knowledge';
@@ -6765,6 +6920,48 @@
6765
6920
  applyStageGating();
6766
6921
  syncWorkspaceReporter();
6767
6922
  }
6923
+ // When the window is too narrow for every step tab, the tabs scroll sideways inside the row (web/app.css
6924
+ // .ws-steps-row) so the step's own control at the end stays on screen. Mark which side has more tabs, keep the
6925
+ // chosen tab in view, and let a plain mouse wheel scroll them (a trackpad and Shift+wheel already do).
6926
+ function syncStepTabsOverflow() {
6927
+ const rest = $stepTabs.scrollWidth - $stepTabs.clientWidth - $stepTabs.scrollLeft;
6928
+ const start = $stepTabs.scrollLeft > 1;
6929
+ const end = rest > 1;
6930
+ const fade = start && end ? 'both' : start ? 'start' : end ? 'end' : 'none';
6931
+ if ($stepTabs.dataset.fade !== fade) $stepTabs.dataset.fade = fade;
6932
+ }
6933
+ function revealActiveStepTab() {
6934
+ revealStepTab($stepTabs.querySelector('button.active'));
6935
+ }
6936
+ function revealStepTab(b) {
6937
+ if (b && !b.hidden && $stepTabs.scrollWidth > $stepTabs.clientWidth) {
6938
+ // Clear of the 24px fade, so the chosen tab is never half-faded. Scrolled by hand rather than scrollIntoView,
6939
+ // which would also scroll the clipped workspace panes around it.
6940
+ const before = b.offsetLeft - 24;
6941
+ const after = b.offsetLeft + b.offsetWidth + 24 - $stepTabs.clientWidth;
6942
+ if (before < $stepTabs.scrollLeft) $stepTabs.scrollLeft = Math.max(0, before);
6943
+ else if (after > $stepTabs.scrollLeft) $stepTabs.scrollLeft = after;
6944
+ }
6945
+ syncStepTabsOverflow();
6946
+ }
6947
+ $stepTabs.addEventListener('scroll', syncStepTabsOverflow, { passive: true });
6948
+ // The browser brings a focused tab only to the edge, under the fade; bring it clear of it like the chosen tab.
6949
+ $stepTabs.addEventListener('focusin', (e) => revealStepTab(e.target.closest('button[data-step]')));
6950
+ $stepTabs.addEventListener('wheel', (e) => {
6951
+ if (e.deltaX || !e.deltaY || e.ctrlKey) return;
6952
+ const from = $stepTabs.scrollLeft;
6953
+ // A wheel that counts in lines or pages (Firefox) is turned into pixels, or one notch would move about 3px.
6954
+ const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? $stepTabs.clientWidth : 1;
6955
+ $stepTabs.scrollLeft = from + e.deltaY * unit;
6956
+ if ($stepTabs.scrollLeft !== from) e.preventDefault();
6957
+ }, { passive: false });
6958
+ // A tab shown, hidden, relabelled or locked changes how much room the tabs need, and the window or a side panel
6959
+ // changes how much they have: either can start or end the overflow.
6960
+ if (typeof ResizeObserver === 'function') {
6961
+ const stepTabsSize = new ResizeObserver(() => revealActiveStepTab());
6962
+ stepTabsSize.observe($stepTabs);
6963
+ $stepTabs.querySelectorAll('button[data-step]').forEach((b) => stepTabsSize.observe(b));
6964
+ }
6768
6965
  $stepTabs.addEventListener('click', (e) => {
6769
6966
  const b = e.target.closest('button[data-step]');
6770
6967
  if (b?.getAttribute('aria-disabled') === 'true') {
@@ -8242,6 +8439,7 @@
8242
8439
  // than a switch into an empty History pane.
8243
8440
  function wsOpenHistory() {
8244
8441
  if (!current) return;
8442
+ historyView = { project: historyViewKey(current), view: 'approvals' }; // reverting is the ledger's (#2470 R6.5b)
8245
8443
  setStep('history');
8246
8444
  // Move focus with the step. The click that gets here comes from a button inside the Model
8247
8445
  // iframe, which setStep() has just hidden — focus would otherwise collapse to <body>, leaving a
@@ -9647,7 +9845,10 @@
9647
9845
  return '<section class="kb-col kb-viewer kb-page"><div class="kb-view-head">' +
9648
9846
  `<span class="kb-view-name" data-tip="${escapeAttr(pg.title)}">${escapeHtml(pg.title)}</span>${type}${cited}` +
9649
9847
  '<button type="button" class="kb-x" data-kb-close data-tip="Back to graph" aria-label="Back to graph">✕</button></div>' +
9650
- `<div class="kb-page-body"><div class="kb-page-body-measure">${escapeHtml(pg.body)}</div></div></section>`;
9848
+ // #3003: rendered like the chat viewers (markdown, [[links]] as page titles); raw text only if chat is not loaded.
9849
+ (window.flolessChat?.knowledgePageHtml
9850
+ ? `<div class="kb-page-body"><div class="kb-page-body-measure kb-page-md">${window.flolessChat.knowledgePageHtml(pg.body, pg.links, 'workspace.kb-page-link')}</div></div></section>`
9851
+ : `<div class="kb-page-body"><div class="kb-page-body-measure">${escapeHtml(pg.body)}</div></div></section>`);
9651
9852
  }
9652
9853
  function kbPageLoading() { return '<section class="kb-col kb-viewer kb-page"><div class="kb-view-head"><span class="kb-view-name">Loading…</span></div><div class="kb-view-msg"><div class="kb-view-spin" role="status" aria-label="Loading page"></div></div></section>'; }
9653
9854
  /** `opts.citedGone` — the read carried a pinned generation and the server does not have it.
@@ -10071,7 +10272,7 @@
10071
10272
  // drift flag says the opposite in that state, so the strip and the page would disagree.
10072
10273
  const cur = knowledgeState && knowledgeState.currentGeneration ? knowledgeState.currentGeneration.generationId : null;
10073
10274
  const cited = !!generationId && cur !== generationId;
10074
- const h = kbViewHost(); if (h) h.innerHTML = kbPageShell(body.page, { cited });
10275
+ const h = kbViewHost(); if (h) { h.innerHTML = kbPageShell(body.page, { cited }); h.dataset.kbGeneration = body.generationId || ''; }
10075
10276
  } catch (err) {
10076
10277
  if (err && err.name === 'AbortError') return;
10077
10278
  // One sentence used to cover five causes with no record anywhere. The status separates the one
@@ -11907,6 +12108,9 @@
11907
12108
  // One delegated listener for the whole pane — the column is re-rendered wholesale on every state
11908
12109
  // change, so per-render wiring would leak handlers.
11909
12110
  $wsKnowledge.addEventListener('click', (e) => {
12111
+ // #3003: a [[link]] on an open page opens the page it names, at the version this one was read from.
12112
+ const kbLink = e.target.closest('button[data-kb-link]');
12113
+ if (kbLink && current) { openKnowledgePage(current.id, kbLink.dataset.kbLink, kbViewHost()?.dataset.kbGeneration || null); return; }
11910
12114
  // #2491 R6.9: categories, selection and Move to… first — their menus share the design set's menu look.
11911
12115
  const rowAct = e.target.closest('[data-kb-row-act]');
11912
12116
  if (rowAct) { kbRowAct(rowAct); return; }
@@ -12451,7 +12655,7 @@
12451
12655
  ];
12452
12656
  };
12453
12657
  /** The units this project's bill is written in: the server's answer, else the client's own copy. */
12454
- const bomUnits = () => exportUnits ?? (current && current.displayUnits === 'mm' ? 'mm' : 'ft-in');
12658
+ const bomUnits = () => exportUnits ?? (current?.displayUnits === 'mm' || current?.displayUnits === 'ft-in' ? current.displayUnits : current?.environment === 'UK' ? 'mm' : 'ft-in');
12455
12659
  const BOM_DESCRIPTIVE = ['profile', 'grade', 'type'];
12456
12660
  const DEFAULT_BOM_FORMATS = ['csv', 'xlsx'];
12457
12661
  const DEFAULT_BOM_COLUMNS = ['profile', 'qty', 'length', 'lbft', 'weight'];
@@ -14555,7 +14759,12 @@
14555
14759
  let selector = option.selector;
14556
14760
  if (option.selector.kind === 'working') {
14557
14761
  const win = frames.model && frames.model.contentWindow;
14558
- if (win && typeof win.flushContract === 'function') await win.flushContract();
14762
+ // Only an editor with unsaved input is flushed (#2981), as approval does. A flush always PUTs the
14763
+ // whole in-memory contract, including the presentation defaults the editor fills in on load, so an
14764
+ // export from an untouched model wrote a new working revision nobody made. An unknown state (no
14765
+ // editor loaded yet) still flushes.
14766
+ const saveState = win && typeof win.contractSaveState === 'function' ? win.contractSaveState() : null;
14767
+ if (win && typeof win.flushContract === 'function' && saveState !== 'clean') await win.flushContract();
14559
14768
  const fresh = await api(`/api/projects/${encodeURIComponent(projectId)}/export-sources`);
14560
14769
  if (!fresh || !fresh.working || typeof fresh.working.etag !== 'string') throw new Error('Working revision identity is unavailable.');
14561
14770
  selector = { kind: 'working', expectedEtag: fresh.working.etag };
@@ -16307,7 +16516,7 @@
16307
16516
  // into test harnesses, where a free name it assigns would not exist. A review opened before this
16308
16517
  // settles (a fresh page, a slow disk) reads in millimetres, never in nothing.
16309
16518
  import('./display-units.js').then((m) => { reviewUnitsModule = m; }, () => {});
16310
- const reviewUnits = () => (current && current.displayUnits === 'mm' ? 'mm' : 'ft-in');
16519
+ const reviewUnits = () => (current?.displayUnits === 'mm' || current?.displayUnits === 'ft-in' ? current.displayUnits : current?.environment === 'UK' ? 'mm' : 'ft-in');
16311
16520
  const reviewElevation = (mm) => (reviewUnitsModule ? reviewUnitsModule.formatElevation(mm, reviewUnits()) : `${Math.round(mm)} mm`);
16312
16521
  const reviewLength = (mm) => (reviewUnitsModule ? reviewUnitsModule.formatLength(mm, reviewUnits()) : `${Math.round(mm)} mm`);
16313
16522
  const isEndpointValue = (v) => !!v && typeof v === 'object' && !Array.isArray(v)
@@ -18140,14 +18349,27 @@
18140
18349
  return `<section class="saved-work" aria-labelledby="saved-work-title"><div class="saved-work-head"><h3 id="saved-work-title">Saved work</h3><span>Unapproved checkpoints</span></div>${body}</section>`;
18141
18350
  }
18142
18351
 
18352
+ // #2470 R6.5b: each ledger render is numbered, so one overtaken by a newer render (the person went to Activity and back
18353
+ // while it was reading) neither paints nor speaks.
18354
+ let historyRenderGen = 0;
18355
+ /**
18356
+ * The ledger was on screen and is being hidden (setStep): a render still reading neither paints nor speaks, and a
18357
+ * revision-note editor it opened will not reopen or repaint it. A note the person already pressed Save on is still
18358
+ * saved to its own project and version; only the hidden ledger is left alone.
18359
+ */
18360
+ function leaveHistoryLedger() {
18361
+ historyRenderGen++;
18362
+ revisionNoteEditorGeneration++;
18363
+ }
18143
18364
  async function renderHistory() {
18144
18365
  if (!current) return;
18145
18366
  const id = current.id;
18367
+ const renderGen = ++historyRenderGen;
18146
18368
  const previousHistory = $wsHistory.dataset.historyProjectId === id ? $wsHistory.innerHTML : '';
18147
18369
  closeBaseMenu(); // this re-render replaces the History HTML — drop any open base-picker's listener first
18148
18370
  $wsHistory.innerHTML = HIST_HEAD + '<div class="hist-note">Loading history…</div>';
18149
18371
  await awaitApprovalVerdict();
18150
- if (!current || current.id !== id || $wsHistory.hidden) return; // switched away while it settled
18372
+ if (!current || current.id !== id || $wsHistory.hidden || renderGen !== historyRenderGen) return; // switched away while it settled
18151
18373
  let rows = [];
18152
18374
  let approvedAt;
18153
18375
  let nextDiffSupported = false;
@@ -18177,7 +18399,7 @@
18177
18399
  try {
18178
18400
  const r = await api(`/api/projects/${encodeURIComponent(id)}/versions`);
18179
18401
  strictHistoryUnavailable = r.historyAvailable === false;
18180
- if (r.revisionNotesUnavailable) showToast('Revision notes are unavailable. Approved history is unchanged.', 'warn');
18402
+ if (r.revisionNotesUnavailable && renderGen === historyRenderGen) showToast('Revision notes are unavailable. Approved history is unchanged.', 'warn');
18181
18403
  rows = Array.isArray(r.versions) ? r.versions : [];
18182
18404
  // Absent on an older server → fall back to the descriptor, which is the pre-change behaviour.
18183
18405
  nextDiffSupported = typeof r.diffSupported === 'boolean' ? r.diffSupported : !!(wsApp() && wsApp().diff);
@@ -18197,6 +18419,7 @@
18197
18419
  // `defaultUnavailable`, and reaches here through this throw. A bare network failure has no
18198
18420
  // body, so it still gets the retry line it deserves.
18199
18421
  const served = err && err.body && typeof err.body.error === 'string' ? err.body.error.trim() : '';
18422
+ if (renderGen !== historyRenderGen) return;
18200
18423
  showToast('We couldn’t load this history because FloLess could not reach it. Try again.', 'warn');
18201
18424
  if (current && current.id === id && !$wsHistory.hidden) {
18202
18425
  // The header comes too. A step that keeps its band while loading and while listing but drops
@@ -18210,7 +18433,7 @@
18210
18433
  const { saved } = await checkpointPromise;
18211
18434
  if (saved === null) checkpointsUnavailable = true;
18212
18435
  else checkpoints = Array.isArray(saved.checkpoints) ? saved.checkpoints : [];
18213
- if (!current || current.id !== id || $wsHistory.hidden) return; // switched away mid-await
18436
+ if (!current || current.id !== id || $wsHistory.hidden || renderGen !== historyRenderGen) return; // switched away mid-await
18214
18437
  if (strictHistoryUnavailable) {
18215
18438
  if (previousHistory) $wsHistory.innerHTML = previousHistory;
18216
18439
  else $wsHistory.innerHTML = HIST_HEAD + '<div class="hist-empty">Model readiness unavailable — History could not be verified within its safety limits.</div>';
@@ -18240,7 +18463,7 @@
18240
18463
  // same "don't route it through a string template at all" rule `importFailedCmdRow` follows.
18241
18464
  const gen = ++modelPresenceGen;
18242
18465
  const hasModel = await projectContractState(id, current.app);
18243
- if (gen !== modelPresenceGen || !current || current.id !== id || $wsHistory.hidden) return;
18466
+ if (gen !== modelPresenceGen || !current || current.id !== id || $wsHistory.hidden || renderGen !== historyRenderGen) return;
18244
18467
  applyModelPresence(hasModel); // one answer, every surface — History used to keep its own
18245
18468
  const empty = document.createElement('div');
18246
18469
  empty.className = 'hist-empty';
@@ -19794,11 +20017,13 @@
19794
20017
  const member = !!target && !validId(target.jointId) && validId(target.memberId);
19795
20018
  // #2874: or one RFI a chat message mentioned, shown on the project's RFIs step (in the editor, or the shell's own pane).
19796
20019
  const rfi = !!target && !validId(target.jointId) && !member && validId(target.rfiId) && /^RFI-\d{3,16}$/.test(target.rfiId);
20020
+ // #2521 row 9: or Make precise itself, opened in the editor for the chat's "Open Make precise".
20021
+ const precise = !!target && !validId(target.jointId) && !member && !rfi && target.makePrecise === true;
19797
20022
  // Sentences say "the member was not shown", but "RFI-007 was not shown".
19798
- const thing = member ? 'the member' : rfi ? target.rfiId : 'the connection';
19799
- const again = member ? 'Show in the model' : rfi ? `${target.rfiId} in the chat` : 'Open in the model';
20023
+ const thing = member ? 'the member' : rfi ? target.rfiId : precise ? 'Make precise' : 'the connection';
20024
+ const again = member ? 'Show in the model' : rfi ? `${target.rfiId} in the chat` : precise ? 'Open Make precise' : 'Open in the model';
19800
20025
  const step = rfi ? 'rfis' : 'model';
19801
- if (!target || !validId(target.projectId) || !(validId(target.jointId) || member || rfi)) throw connectionError(`That ${member ? 'member' : rfi ? 'RFI' : 'connection'} could not be opened. Open its project from Workspaces.`);
20026
+ if (!target || !validId(target.projectId) || !(validId(target.jointId) || member || rfi || precise)) throw connectionError(`That ${member ? 'member' : rfi ? 'RFI' : precise ? 'model' : 'connection'} could not be opened. Open its project from Workspaces.`);
19802
20027
  const mine = { id: `connection-${++connectionRequestSeq}`, page: null };
19803
20028
  withdrawConnectionRequest(connectionRequest);
19804
20029
  connectionRequest = mine;
@@ -19905,7 +20130,7 @@
19905
20130
  if (citedElsewhere()) throw citedGone();
19906
20131
  // The frame's window survives a reload; its DOCUMENT does not. That is what tells a reload apart.
19907
20132
  page = child; doc = child.document;
19908
- answer = child.flolessEditorFocus(member ? { memberId: target.memberId, requestId: mine.id } : rfi ? { rfiId: target.rfiId, requestId: mine.id } : { jointId: target.jointId, requestId: mine.id,
20133
+ answer = child.flolessEditorFocus(member ? { memberId: target.memberId, requestId: mine.id } : precise ? { makePrecise: true, requestId: mine.id } : rfi ? { rfiId: target.rfiId, requestId: mine.id } : { jointId: target.jointId, requestId: mine.id,
19909
20134
  // #2450: the readiness card's "Raise an RFI" also opens the editor's review dialog for it.
19910
20135
  ...(target.raiseRfi === true ? { raiseRfi: true } : {}), ...(validId(target.checkId) ? { checkId: target.checkId } : {}) });
19911
20136
  if (!answer || typeof answer.then !== 'function') return { ok: false, said: notTaken };