@floless/app 0.133.1 → 0.134.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.
@@ -55037,7 +55037,7 @@ function appVersion() {
55037
55037
  return resolveVersion({
55038
55038
  isSea: isSea2(),
55039
55039
  sqVersionXml: readSqVersionXml(),
55040
- define: true ? "0.133.1" : void 0,
55040
+ define: true ? "0.134.0" : void 0,
55041
55041
  pkgVersion: readPkgVersion()
55042
55042
  });
55043
55043
  }
@@ -55053,7 +55053,7 @@ function resolveChannel(s) {
55053
55053
  function appChannel() {
55054
55054
  return resolveChannel({
55055
55055
  isSea: isSea2(),
55056
- define: true ? "0.133.1" : void 0,
55056
+ define: true ? "0.134.0" : void 0,
55057
55057
  // argv[1] is the entry the runtime actually loaded (…/dist/floless-server.cjs), which is what
55058
55058
  // carries the npx cache prefix. Absent under the SEA exe, which never reaches the npx branch.
55059
55059
  modulePath: process.argv[1]
@@ -55891,6 +55891,7 @@ function positionOffsetVector(frame, ex, depthFace, widthFace, rotDeg, widthOffM
55891
55891
  oy * frame.y[2] + oz * frame.z[2]
55892
55892
  ];
55893
55893
  }
55894
+ var POSITION_OFFSET_SNAP_MM = 25.4 / 4;
55894
55895
 
55895
55896
  // canonical-json.ts
55896
55897
  var import_node_crypto8 = require("node:crypto");
@@ -58810,6 +58811,7 @@ var RESERVED_PROJECT_INTERNAL = /(?:^|[\\/])(?:\.member-end-resolution(?:[\\/]|$
58810
58811
  function isReservedProjectInternalPath(path) {
58811
58812
  return RESERVED_PROJECT_INTERNAL.test(path);
58812
58813
  }
58814
+ var NO_INCARNATION_REFUSAL = "This project can\u2019t be approved \u2014 duplicate it from the Workspaces list to sign off";
58813
58815
  function isProjectId(name) {
58814
58816
  return typeof name === "string" && /^[a-z0-9][a-z0-9-]*$/.test(name);
58815
58817
  }
@@ -59485,11 +59487,11 @@ function parseIndexBytes(bytes2) {
59485
59487
  const kept = [];
59486
59488
  const opaque = [];
59487
59489
  const seen = /* @__PURE__ */ new Set();
59488
- const dropped = [];
59490
+ const dropped2 = [];
59489
59491
  for (const row of exportsValue) {
59490
59492
  const kind = row?.kind;
59491
59493
  if (!isExportKind(kind)) {
59492
- dropped.push(`unknown kind ${JSON.stringify(kind)}`);
59494
+ dropped2.push(`unknown kind ${JSON.stringify(kind)}`);
59493
59495
  opaque.push(row);
59494
59496
  continue;
59495
59497
  }
@@ -59498,16 +59500,16 @@ function parseIndexBytes(bytes2) {
59498
59500
  }
59499
59501
  const key2 = receiptKey(row.kind, row.variant);
59500
59502
  if (seen.has(key2)) {
59501
- dropped.push(`duplicate "${key2.trim()}"`);
59503
+ dropped2.push(`duplicate "${key2.trim()}"`);
59502
59504
  opaque.push(row);
59503
59505
  continue;
59504
59506
  }
59505
59507
  seen.add(key2);
59506
59508
  kept.push(row);
59507
59509
  }
59508
- if (dropped.length) {
59510
+ if (dropped2.length) {
59509
59511
  console.warn(
59510
- `project export index: ignored ${dropped.length} unreadable receipt(s) \u2014 ${dropped.join(", ")}`
59512
+ `project export index: ignored ${dropped2.length} unreadable receipt(s) \u2014 ${dropped2.join(", ")}`
59511
59513
  );
59512
59514
  }
59513
59515
  return { exports: kept, opaque };
@@ -61668,6 +61670,7 @@ var CODEX_COMPLETION_SCHEMA = {
61668
61670
  var MAX_QUESTION = 2e3;
61669
61671
  var MAX_ANSWER_CODE_UNITS = 8e3;
61670
61672
  var MAX_ANSWER_BYTES = 32 * 1024;
61673
+ var MAX_DROPPED = 500;
61671
61674
  function validateCompletion(value) {
61672
61675
  if (!value || typeof value !== "object" || Array.isArray(value)) {
61673
61676
  return { kind: "violation", why: "completion was not an object" };
@@ -61684,16 +61687,18 @@ function validateCompletion(value) {
61684
61687
  if (answerText.length > MAX_ANSWER_CODE_UNITS || answerBytes > MAX_ANSWER_BYTES) {
61685
61688
  return { kind: "violation", why: "outcome answered exceeded the answer limit" };
61686
61689
  }
61687
- if (text5) return { kind: "violation", why: "outcome answered also carried a question" };
61688
- return { kind: "answered", answer: answerText };
61690
+ return { kind: "answered", answer: answerText, ...dropped("question", text5) };
61689
61691
  }
61690
- if (answerText) return { kind: "violation", why: `outcome ${String(outcome)} also carried an answer` };
61691
61692
  if (outcome === "needs-you" && !text5) {
61692
61693
  return { kind: "violation", why: "outcome needs-you carried no question" };
61693
61694
  }
61694
- if (outcome === "needs-you") return { kind: "needs-you", question: text5 };
61695
- if (outcome === "refused") return { kind: "refused", question: text5 };
61696
- return { kind: "applied" };
61695
+ if (outcome === "needs-you") return { kind: "needs-you", question: text5, ...dropped("answer", answerText) };
61696
+ if (outcome === "refused") return { kind: "refused", question: text5, ...dropped("answer", answerText) };
61697
+ return { kind: "applied", ...dropped("answer", answerText) };
61698
+ }
61699
+ function dropped(field, text5) {
61700
+ const flat = text5.replace(/\s+/g, " ").trim();
61701
+ return flat ? { dropped: { field, text: flat.slice(0, MAX_DROPPED) } } : {};
61697
61702
  }
61698
61703
  function readCompletion(terminal) {
61699
61704
  const ev = terminal;
@@ -63427,8 +63432,8 @@ ${isInitialRead ? "Initial" : "Revised"} drawing${req.snapshots.length > 1 ? "s"
63427
63432
  My note: ${req.instruction}` : "";
63428
63433
  const messageHint = isInitialRead ? "<plain-English what was read>" : "<plain-English what changed>";
63429
63434
  const vectorPost = `GET the current contract again and keep its ETag, then POST /api/projects/${req.project}/revision-read with { contract, message: "${messageHint}", requestId: "${req.id}" } and If-Match: <that current ETag>. The server derives the base version and source provenance from this queued request. The first completed vector drawing publishes History version 1; later reads stage a review and publish only after confirmation. Do NOT DELETE the request yourself. If you can't read the drawing, POST /api/projects/${req.project}/revision-requests/${req.id}/fail with { error }.`;
63430
- const post = `After Filter Save, GET /api/projects/${req.project}/revision-requests/${req.id}/steel-manifest and GET the current contract with its ETag. Preserve every server-owned id. Account for every manifest page, layer, candidate line, reference/detail/connection marker, and every new or changed joint in a closed steel-read/v1 attestation. POST /api/projects/${req.project}/revision-read/audit with { requestId: "${req.id}", contract, attestation }; a blocked report is a mandatory checklist, so fix every blocker and repeat until status is read-complete. Then POST the exact same contract and attestation to /api/projects/${req.project}/revision-read with { contract, attestation, message: "${messageHint}", requestId: "${req.id}" } and If-Match: <that exact ETag>. A later read returns 202 for human review; when replacing an existing staged generation, also send If-Match-Stage with its exact stageId. Do NOT DELETE the request yourself. If you can't read the set, POST /api/projects/${req.project}/revision-requests/${req.id}/fail with { error }.`;
63431
- const manifestPhase = `FIRST POST /api/projects/${req.project}/revision-requests/${req.id}/steel-manifest with {}. This is the only allowed path to inventory source pages and mint Filter element ids. If it returns sheet-identification-required, inspect only the listed pages, establish each sheet identity, and retry with explicit { bindings: [{ pageId, sheet, title?, evidenceKind }] }. Never build or rename Filter geometry yourself.`;
63435
+ const post = `After Filter Save, GET /api/projects/${req.project}/revision-requests/${req.id}/steel-manifest and GET the current contract with its ETag. Preserve every server-owned id. Account for every manifest page, layer, candidate line, reference/detail/connection marker, and every new or changed joint in a closed steel-read/v1 attestation. Keep every disposition reason concise (a short phrase, not a paragraph): the whole attestation has an 8 MB limit, so on a very large set verbose reasons can push it over \u2014 prefer a modeling observation over a written disposition wherever a line is genuinely a member. POST /api/projects/${req.project}/revision-read/audit with { requestId: "${req.id}", contract, attestation }; a blocked report is a mandatory checklist, so fix every blocker and repeat until status is read-complete. Then POST the exact same contract and attestation to /api/projects/${req.project}/revision-read with { contract, attestation, message: "${messageHint}", requestId: "${req.id}" } and If-Match: <that exact ETag>. A later read returns 202 for human review; when replacing an existing staged generation, also send If-Match-Stage with its exact stageId. Do NOT DELETE the request yourself. If you can't read the set, POST /api/projects/${req.project}/revision-requests/${req.id}/fail with { error }.`;
63436
+ const manifestPhase = `FIRST POST /api/projects/${req.project}/revision-requests/${req.id}/steel-manifest with {}. This is the only allowed path to inventory source pages and mint Filter element ids. If it returns sheet-identification-required, inspect only the listed pages, establish each sheet identity, and retry with explicit { bindings: [{ pageId, sheet, title?, evidenceKind }] }. If it returns steel-manifest-over-budget, the drawing set is too large for a single read \u2014 do NOT retry; stop and tell me to split it into smaller revisions (the response lists each sheet's element count). Never build or rename Filter geometry yourself.`;
63432
63437
  if ((req.appTemplateId || req.appId) === "vectorize") {
63433
63438
  if (isInitialRead) {
63434
63439
  return `In floless project "${req.project}" (app "${req.appId}"), an initial drawing was attached \u2014 trace it into this project as its first version (do NOT create a new project). Vectorize the drawing per the floless-app-vectorize skill into a drawing.vector/v1 contract: emit clean, editable 2D vector geometry (sheets \u2192 elements: lines / polylines / curves / text, each on its layer), NOT steel members or a takeoff. A vector PDF is read deterministically (exact geometry, no guessing); a photo, scan or hand sketch is traced by a fenced vision extraction that flags every uncertain stroke (low confidence) for the user's review. ${vectorPost}${snaps}${note}`;
@@ -67826,7 +67831,7 @@ var import_node_path36 = require("node:path");
67826
67831
  var STEEL_FILTER_EXTRACTOR_VERSION = "pymupdf-steel-filter/v2";
67827
67832
  var STEEL_READ_MAX_SOURCES = 400;
67828
67833
  var STEEL_READ_MAX_PAGES = 2e3;
67829
- var STEEL_READ_MAX_ELEMENTS = 2e4;
67834
+ var STEEL_READ_MAX_ELEMENTS = 5e4;
67830
67835
  function steelFilterGeometryHash(filter) {
67831
67836
  const clone2 = filter == null ? filter : JSON.parse(JSON.stringify(filter));
67832
67837
  if (clone2 && typeof clone2 === "object" && !Array.isArray(clone2)) {
@@ -67938,7 +67943,7 @@ function dropSteelReadManifest(requestId) {
67938
67943
  // steel-read-audit.ts
67939
67944
  var STEEL_READ_AUDIT_POLICY = "steel-read-completion/v1";
67940
67945
  var MAX_ATTESTATION_BYTES = 8 * 1024 * 1024;
67941
- var MAX_LINES = 2e4;
67946
+ var MAX_LINES = STEEL_READ_MAX_ELEMENTS;
67942
67947
  var MAX_PAGES = 2e3;
67943
67948
  var MAX_JOINTS = 1e4;
67944
67949
  var MAX_MEMBERS = 1e4;
@@ -68061,17 +68066,22 @@ function lineInventory(filter) {
68061
68066
  function referenceInventory(filter, manifest) {
68062
68067
  if (!isObj3(filter)) return [];
68063
68068
  const out = [];
68069
+ const seen = /* @__PURE__ */ new Set();
68064
68070
  const marker = /(?:\d+\s*[\/-]\s*)?[A-Z]{1,3}-?\d{2,4}/i;
68065
68071
  for (const rawSheet of Array.isArray(filter.sheets) ? filter.sheets : []) {
68066
68072
  if (!isObj3(rawSheet)) continue;
68067
68073
  for (const raw of Array.isArray(rawSheet.elements) ? rawSheet.elements : []) {
68068
- if (isObj3(raw) && raw.kind === "text" && typeof raw.id === "string" && typeof raw.text === "string" && marker.test(raw.text)) out.push({ id: raw.id, text: raw.text });
68074
+ if (isObj3(raw) && raw.kind === "text" && typeof raw.id === "string" && typeof raw.text === "string" && marker.test(raw.text)) {
68075
+ out.push({ id: raw.id, text: raw.text });
68076
+ seen.add(raw.id);
68077
+ }
68069
68078
  }
68070
68079
  }
68071
68080
  for (const page of manifest.manifest.pages) for (const candidate of page.candidates ?? []) {
68072
- if (candidate.kind !== "reference-marker" || out.some((row) => row.id === candidate.id)) continue;
68081
+ if (candidate.kind !== "reference-marker" || seen.has(candidate.id)) continue;
68073
68082
  const element = isObj3(candidate.element) ? candidate.element : {};
68074
68083
  out.push({ id: candidate.id, text: typeof element.text === "string" ? element.text : "" });
68084
+ seen.add(candidate.id);
68075
68085
  }
68076
68086
  return out;
68077
68087
  }
@@ -68206,7 +68216,8 @@ function evaluateSteelRead(context) {
68206
68216
  add("layer-census", missingLayers.length || foreignLayers.length ? "block" : "pass", missingLayers.length || foreignLayers.length ? "layer census does not exactly cover Filter layers" : `${filterLayers.size} Filter layer(s) classified`, [...missingLayers, ...foreignLayers]);
68207
68217
  const observations2 = activeObservationElements(candidate);
68208
68218
  const dispositionById = new Map(proof3.lineDispositions.map((row) => [row.elementId, row]));
68209
- const lineIds = new Set(lines.map((line) => line.id));
68219
+ const linesById = new Map(lines.map((line) => [line.id, line]));
68220
+ const lineIds = new Set(linesById.keys());
68210
68221
  const missingLines = [], foreignLines = [], invalidObservations = [], excludedModeled = [];
68211
68222
  let observedLines = 0;
68212
68223
  for (const line of lines) {
@@ -68221,7 +68232,7 @@ function evaluateSteelRead(context) {
68221
68232
  if (!disposition) missingLines.push(line.id);
68222
68233
  }
68223
68234
  if (disposition?.disposition === "duplicate") {
68224
- const target = lines.find((row) => row.id === disposition.duplicateOf);
68235
+ const target = disposition.duplicateOf === void 0 ? void 0 : linesById.get(disposition.duplicateOf);
68225
68236
  if (!target || target.id === line.id || target.sourceHash !== line.sourceHash || target.pageId !== line.pageId || target.sheet !== line.sheet || target.geometry !== line.geometry) invalidObservations.push(line.id);
68226
68237
  }
68227
68238
  }
@@ -68253,14 +68264,16 @@ function evaluateSteelRead(context) {
68253
68264
  add("visual-coverage", badPageReviews.length ? "block" : "pass", badPageReviews.length ? "visual reviews do not cover the required source-page bounds" : `${pagesById.size} source page(s) visually reviewed`, badPageReviews);
68254
68265
  const refs = referenceInventory(filter, storedManifest);
68255
68266
  const refById = new Map(proof3.references.map((row) => [row.elementId, row]));
68267
+ const refIds = new Set(refs.map((ref) => ref.id));
68256
68268
  const badRefs = [];
68257
68269
  for (const ref of refs) {
68258
68270
  const row = refById.get(ref.id);
68259
68271
  if (!row || row.status === "resolved" && (!row.targetPageId || !pagesById.has(row.targetPageId))) badRefs.push(ref.id);
68260
68272
  }
68261
- for (const id of refById.keys()) if (!refs.some((ref) => ref.id === id)) badRefs.push(id);
68273
+ for (const id of refById.keys()) if (!refIds.has(id)) badRefs.push(id);
68262
68274
  add("reference-graph", badRefs.length ? "block" : proof3.references.some((row) => row.status === "missing") ? "warning" : "pass", badRefs.length ? "reference candidates are unaccounted or target foreign pages" : `${refs.length} reference marker(s) reach a fixed accounting point`, badRefs);
68263
68275
  const markerCandidates = storedManifest.manifest.pages.flatMap((page) => (page.candidates ?? []).filter((candidate2) => candidate2.kind === "detail-marker" || candidate2.kind === "connection-marker"));
68276
+ const markerIds = new Set(markerCandidates.map((marker) => marker.id));
68264
68277
  const dispositionByCandidate = new Map(proof3.candidateDispositions.map((row) => [row.elementId, row]));
68265
68278
  const jointIdSet = new Set((isObj3(candidate) && Array.isArray(candidate.joints) ? candidate.joints.filter(isObj3) : []).flatMap((joint) => typeof joint.id === "string" ? [joint.id] : []));
68266
68279
  const badCandidates = [];
@@ -68268,7 +68281,7 @@ function evaluateSteelRead(context) {
68268
68281
  const disposition = dispositionByCandidate.get(marker.id);
68269
68282
  if (!disposition || disposition.disposition === "modeled" && (!disposition.jointId || !jointIdSet.has(disposition.jointId))) badCandidates.push(marker.id);
68270
68283
  }
68271
- for (const id of dispositionByCandidate.keys()) if (!markerCandidates.some((candidate2) => candidate2.id === id)) badCandidates.push(id);
68284
+ for (const id of dispositionByCandidate.keys()) if (!markerIds.has(id)) badCandidates.push(id);
68272
68285
  const unresolvedCandidates = proof3.candidateDispositions.filter((row) => row.disposition === "unresolved").map((row) => row.elementId);
68273
68286
  add("detail-reconciliation", badCandidates.length ? "block" : unresolvedCandidates.length ? "warning" : "pass", badCandidates.length ? "detail/connection markers are unaccounted or bind to missing joints" : `${markerCandidates.length} detail/connection marker(s) reconciled`, [...badCandidates, ...unresolvedCandidates]);
68274
68287
  const candidateObj = isObj3(candidate) ? candidate : {};
@@ -68302,7 +68315,8 @@ function evaluateSteelRead(context) {
68302
68315
  if (currentJointHashes.get(joint.id) === dependencyHash) continue;
68303
68316
  if (reviewByJoint.get(joint.id)?.dependencyHash !== dependencyHash) changedReviewMissing.push(joint.id);
68304
68317
  }
68305
- for (const jointId of reviewByJoint.keys()) if (!joints.some((joint) => joint.id === jointId)) changedReviewMissing.push(jointId);
68318
+ const jointRowIds = new Set(joints.flatMap((joint) => typeof joint.id === "string" ? [joint.id] : []));
68319
+ for (const jointId of reviewByJoint.keys()) if (!jointRowIds.has(jointId)) changedReviewMissing.push(jointId);
68306
68320
  add("joint-review", changedReviewMissing.length ? "block" : "pass", changedReviewMissing.length ? "new/changed joints lack a dependency-bound visual review" : `${joints.length} joint dependency fingerprint(s) reviewed or unchanged`, changedReviewMissing);
68307
68321
  if (validation.valid && !budgetExceeded) {
68308
68322
  try {
@@ -72099,6 +72113,28 @@ for source in manifest["sources"]:
72099
72113
 
72100
72114
  json.dump({"pages":pages}, sys.stdout, separators=(",", ":"))
72101
72115
  `;
72116
+ var SteelFilterBudgetError = class extends Error {
72117
+ constructor(total, limit, pages) {
72118
+ super(`the drawing set carries ${total} elements, over the ${limit}-element read limit`);
72119
+ this.total = total;
72120
+ this.limit = limit;
72121
+ this.pages = pages;
72122
+ this.name = "SteelFilterBudgetError";
72123
+ }
72124
+ total;
72125
+ limit;
72126
+ pages;
72127
+ };
72128
+ var SteelFilterOutputTooLargeError = class extends Error {
72129
+ constructor() {
72130
+ super("the drawing set produced more extraction output than a single read can process");
72131
+ this.name = "SteelFilterOutputTooLargeError";
72132
+ }
72133
+ };
72134
+ function isStdoutTooLarge(error) {
72135
+ if (error?.code === "ERR_CHILD_PROCESS_STDOUT_MAXBUFFER") return true;
72136
+ return /stdout maxBuffer/i.test(error instanceof Error ? error.message : "");
72137
+ }
72102
72138
  var available = null;
72103
72139
  function steelFilterExtractorAvailable(python = "python") {
72104
72140
  if (python === "python" && available !== null) return available;
@@ -72120,9 +72156,11 @@ async function extractSteelFilter(manifest, options = {}) {
72120
72156
  const child = (0, import_node_child_process7.execFile)(options.python ?? "python", ["-c", PYTHON], {
72121
72157
  timeout: options.timeoutMs ?? 12e4,
72122
72158
  windowsHide: true,
72123
- maxBuffer: 25 * 1024 * 1024
72159
+ // 64 MB: at the raised 50k element cap a dense Filter (long SVG paths) plus per-sheet rasters
72160
+ // can exceed the old 25 MB stdout ceiling; the buffer is in-memory and short-lived (issue #805).
72161
+ maxBuffer: 64 * 1024 * 1024
72124
72162
  }, (error, stdout, stderr) => {
72125
- if (error) return reject(new Error(`Steel Filter extraction failed: ${(stderr || error.message).trim().slice(0, 1e3)}`));
72163
+ if (error) return reject(isStdoutTooLarge(error) ? new SteelFilterOutputTooLargeError() : new Error(`Steel Filter extraction failed: ${(stderr || error.message).trim().slice(0, 1e3)}`));
72126
72164
  resolve20(stdout);
72127
72165
  });
72128
72166
  child.stdin?.end(input);
@@ -72136,18 +72174,38 @@ async function extractSteelFilter(manifest, options = {}) {
72136
72174
  if (!filter || typeof filter !== "object" || !Array.isArray(filter.sheets) || filter.sheets.length === 0 || filter.sheets.length > STEEL_READ_MAX_PAGES) {
72137
72175
  throw new Error("Steel Filter extraction returned no populated sheets");
72138
72176
  }
72177
+ const sheets = filter.sheets;
72139
72178
  let elements = 0;
72140
- for (const sheet of filter.sheets) {
72179
+ for (const sheet of sheets) {
72141
72180
  if (!sheet || typeof sheet !== "object" || Array.isArray(sheet) || !Array.isArray(sheet.elements)) {
72142
72181
  throw new Error("Steel Filter extraction returned malformed sheet elements");
72143
72182
  }
72144
72183
  elements += sheet.elements.length;
72145
- if (elements > STEEL_READ_MAX_ELEMENTS) throw new Error("Steel Filter extraction exceeded the 20,000 element work limit");
72146
- const row = sheet;
72147
- if (typeof row.sheet === "string" && typeof row.sourceHash === "string") {
72148
- const sheetName = row.sheet;
72149
- const sourceHash = row.sourceHash;
72150
- row.elements.forEach((element, index) => {
72184
+ }
72185
+ if (elements > STEEL_READ_MAX_ELEMENTS) {
72186
+ const pages = [];
72187
+ const seen = /* @__PURE__ */ new Set();
72188
+ for (const sheet of sheets) {
72189
+ const count2 = sheet.elements.length;
72190
+ if (count2 === 0) continue;
72191
+ const sourceHash = sheet.sourceHash;
72192
+ const page = sheet.pageNumber;
72193
+ if (typeof sourceHash !== "string" || !/^[0-9a-f]{64}$/.test(sourceHash) || !Number.isInteger(page) || page < 1) {
72194
+ throw new Error("Steel Filter extraction returned a sheet with no valid source/page identity");
72195
+ }
72196
+ const key2 = `${sourceHash}\0${page}`;
72197
+ if (seen.has(key2)) throw new Error("Steel Filter extraction returned a duplicate source page");
72198
+ seen.add(key2);
72199
+ pages.push({ sourceHash, page, count: count2 });
72200
+ }
72201
+ pages.sort((a, b) => a.sourceHash < b.sourceHash ? -1 : a.sourceHash > b.sourceHash ? 1 : a.page - b.page);
72202
+ throw new SteelFilterBudgetError(elements, STEEL_READ_MAX_ELEMENTS, pages);
72203
+ }
72204
+ for (const sheet of sheets) {
72205
+ const sheetName = sheet.sheet;
72206
+ const sourceHash = sheet.sourceHash;
72207
+ if (typeof sheetName === "string" && typeof sourceHash === "string") {
72208
+ sheet.elements.forEach((element, index) => {
72151
72209
  if (element && typeof element === "object" && !Array.isArray(element)) {
72152
72210
  element.elementId = filterElementId(sourceHash, sheetName, index, element);
72153
72211
  }
@@ -72529,18 +72587,49 @@ function registerRevisionRoutes(app, deps = {}) {
72529
72587
  let evidenceFilter;
72530
72588
  try {
72531
72589
  const extractor = deps.extractSteelFilter ?? extractSteelFilter;
72590
+ evidenceFilter = await extractor({
72591
+ sources: sources.extractorSources,
72592
+ plans: pages.map((_page, index) => ({ sheet: `E${index + 1}` })),
72593
+ pages: pages.map((page, index) => ({ sourceHash: page.sourceHash, page: page.page, sheet: `E${index + 1}` }))
72594
+ });
72532
72595
  filter = await extractor({
72533
72596
  sources: sources.extractorSources,
72534
72597
  plans: modelPages.map((page) => ({ sheet: page.sheet, ...page.title ? { title: page.title } : {} })),
72535
72598
  pages: modelPages.map((page) => ({ sourceHash: page.sourceHash, page: page.page, sheet: page.sheet })),
72536
72599
  ...currentObj?.filter === void 0 ? {} : { filter: currentObj.filter }
72537
72600
  });
72538
- evidenceFilter = await extractor({
72539
- sources: sources.extractorSources,
72540
- plans: pages.map((_page, index) => ({ sheet: `E${index + 1}` })),
72541
- pages: pages.map((page, index) => ({ sourceHash: page.sourceHash, page: page.page, sheet: `E${index + 1}` }))
72542
- });
72543
72601
  } catch (error) {
72602
+ if (error instanceof SteelFilterBudgetError) {
72603
+ const labelByPage = new Map(pages.map((page) => [`${page.sourceHash} ${page.page}`, page.sheet]));
72604
+ const nameByHash = new Map(sources.manifestSources.map((source) => [source.sha256, source.name]));
72605
+ const overBudget = error.pages.map((row) => ({
72606
+ sheet: labelByPage.get(`${row.sourceHash} ${row.page}`) ?? `${nameByHash.get(row.sourceHash) ?? "source"} p.${row.page}`,
72607
+ sourceHash: row.sourceHash,
72608
+ page: row.page,
72609
+ count: row.count
72610
+ }));
72611
+ return reply.status(400).send({
72612
+ ok: false,
72613
+ code: "steel-manifest-over-budget",
72614
+ error: `This drawing set carries ${error.total} elements, over the ${error.limit}-element limit for a single read.`,
72615
+ recovery: `Close this request and re-submit the drawing set as smaller revisions \u2014 split the sheets so each revision stays under ${error.limit} elements.`,
72616
+ total: error.total,
72617
+ limit: error.limit,
72618
+ overBudget: overBudget.slice(0, STEEL_READ_MAX_PAGES)
72619
+ });
72620
+ }
72621
+ if (error instanceof SteelFilterOutputTooLargeError) {
72622
+ return reply.status(400).send({
72623
+ ok: false,
72624
+ code: "steel-manifest-over-budget",
72625
+ error: "This drawing set is too large to process in a single read.",
72626
+ recovery: "Close this request and re-submit the drawing set as several materially smaller revisions.",
72627
+ total: null,
72628
+ limit: null,
72629
+ overBudget: []
72630
+ });
72631
+ }
72632
+ req.log.warn({ projectId: project.id, requestId: request.id, error: error instanceof Error ? error.message : String(error) }, "steel manifest extraction failed");
72544
72633
  return reply.status(400).send({ ok: false, code: "steel-manifest-extraction-failed", error: error instanceof Error ? error.message : "could not extract Steel Filter geometry" });
72545
72634
  }
72546
72635
  const evidenceSheets = evidenceFilter && typeof evidenceFilter === "object" && !Array.isArray(evidenceFilter) && Array.isArray(evidenceFilter.sheets) ? evidenceFilter.sheets : [];
@@ -74243,9 +74332,9 @@ function publishProgress(id, event) {
74243
74332
  s.buffered.push({ seq, frame });
74244
74333
  s.bytes += frame.length;
74245
74334
  while (s.bytes > MAX_BUFFER_BYTES && s.buffered.length > 1) {
74246
- const dropped = s.buffered.shift();
74247
- s.bytes -= dropped.frame.length;
74248
- s.droppedBefore = dropped.seq;
74335
+ const dropped2 = s.buffered.shift();
74336
+ s.bytes -= dropped2.frame.length;
74337
+ s.droppedBefore = dropped2.seq;
74249
74338
  }
74250
74339
  }
74251
74340
  function subscribeProgress(id, reply, afterSeq, owner2) {
@@ -80918,11 +81007,7 @@ function mergeContractForward(base, latest, draft, resolutions = {}) {
80918
81007
  function prepareProjectApprovalReview(projectId, deps) {
80919
81008
  const project = getProject(projectId);
80920
81009
  if (!project) throw new WorkspaceSnapshotError(404, `unknown project: ${projectId}`);
80921
- if (!project.uuid) throw new WorkspaceSnapshotError(
80922
- 409,
80923
- "This project can\u2019t be approved \u2014 duplicate it from the Workspaces list to sign off",
80924
- "no-incarnation"
80925
- );
81010
+ if (!project.uuid) throw new WorkspaceSnapshotError(409, NO_INCARNATION_REFUSAL, "no-incarnation");
80926
81011
  const draft = readAcceptedForRequest(project.app, projectId, "read");
80927
81012
  if (draft == null) {
80928
81013
  if (storedContractBytesExist(project.app, projectId)) {
@@ -90386,6 +90471,11 @@ async function settle(deps, lease, code, out, err2, sessionCaptureError = null)
90386
90471
  const after = deps.getRequest(lease.requestId);
90387
90472
  const gone = !after || after.status === "staged";
90388
90473
  const base = { exitCode: code ?? void 0, lastOutput: tail(err2) || tail(prose(out)) };
90474
+ if (completion.kind !== "violation" && completion.dropped) {
90475
+ console.error(
90476
+ `[terminal-run] ${lease.requestType} run ${lease.requestId} finished ${completion.kind} carrying an unused \`${completion.dropped.field}\`; dropped: ${completion.dropped.text}`
90477
+ );
90478
+ }
90389
90479
  if (sessionCaptureError) {
90390
90480
  if (lease.runtime === "codex") {
90391
90481
  try {
@@ -93773,6 +93863,7 @@ async function startServer() {
93773
93863
  app.get("/api/projects/:id/checkpoints", async (req, reply) => {
93774
93864
  const project = getProject(req.params.id);
93775
93865
  if (!project) return reply.status(404).send({ ok: false, error: `unknown project: ${req.params.id}` });
93866
+ if (!project.uuid) return reply.status(409).send({ ok: false, error: NO_INCARNATION_REFUSAL, code: "no-incarnation" });
93776
93867
  return withLifecycleLock("project", project.id, () => ({
93777
93868
  ok: true,
93778
93869
  checkpoints: listProjectCheckpoints(project).map((saved) => ({
@@ -93912,6 +94003,7 @@ async function startServer() {
93912
94003
  app.get("/api/projects/:id/export-sources", async (req, reply) => {
93913
94004
  const project = getProject(req.params.id);
93914
94005
  if (!project) return reply.status(404).send({ ok: false, error: `unknown project: ${req.params.id}` });
94006
+ if (!project.uuid) return reply.status(409).send({ ok: false, error: NO_INCARNATION_REFUSAL, code: "no-incarnation" });
93915
94007
  return withLifecycleLock("project", project.id, () => {
93916
94008
  let defaultUnavailable = null;
93917
94009
  const recordRefusal = (error) => {
package/dist/web/app.css CHANGED
@@ -384,6 +384,42 @@
384
384
  }
385
385
  .msg.aware .body { border-left-color: var(--text-dim); }
386
386
  .msg.instructor-answer .body { border-left-color: var(--accent); }
387
+ /* Rendered answer prose (answerProse in aware.js). Scoped to this card so no other message body
388
+ inherits a document-ish scale, and re-scaled from the browser defaults an h3/ul would bring into
389
+ a card set at the body's own font-size (mostly down — h3 15.2px→15px, ul padding 40px→17px —
390
+ though h5 comes back UP, because the UA's .83em is smaller than the body text it introduces).
391
+ h3 must stay clear of `strong`, which shares its color and weight: at equal size the top heading
392
+ level and an inline bold phrase were indistinguishable, so h3 carries the heavier weight.
393
+ The new-answer badge is ALWAYS the first child (merely hidden until the answer is new), so the
394
+ heading after it needs the same top-trim a real first child gets. */
395
+ .msg.instructor-answer .body > :first-child,
396
+ .msg.instructor-answer .body > .answer-new-badge + * { margin-top: 0; }
397
+ .msg.instructor-answer .body > :last-child { margin-bottom: 0; }
398
+ .msg.instructor-answer .body h3,
399
+ .msg.instructor-answer .body h4,
400
+ .msg.instructor-answer .body h5 { margin: 14px 0 5px; line-height: 1.35; font-weight: 600; }
401
+ .msg.instructor-answer .body h3 { font-size: 15px; font-weight: 700; color: var(--text); }
402
+ .msg.instructor-answer .body h4 {
403
+ font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim);
404
+ }
405
+ .msg.instructor-answer .body h5 { font-size: 12px; color: var(--text); }
406
+ .msg.instructor-answer .body p { margin: 0 0 9px; }
407
+ .msg.instructor-answer .body ul, .msg.instructor-answer .body ol { margin: 0 0 9px; padding-left: 17px; }
408
+ .msg.instructor-answer .body li { margin: 0 0 4px; }
409
+ .msg.instructor-answer .body li::marker { color: var(--text-dim); }
410
+ .msg.instructor-answer .body code {
411
+ font-family: var(--mono); font-size: 11.5px; background: var(--surface-3);
412
+ padding: 1px 5px; border-radius: 3px; color: var(--text-muted);
413
+ }
414
+ .msg.instructor-answer .body pre {
415
+ margin: 0 0 9px; padding: 9px 10px; background: var(--surface-3); border-radius: 5px;
416
+ overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
417
+ }
418
+ .msg.instructor-answer .body pre::-webkit-scrollbar { height: 7px; }
419
+ .msg.instructor-answer .body pre::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 7px; }
420
+ .msg.instructor-answer .body pre::-webkit-scrollbar-track { background: transparent; }
421
+ .msg.instructor-answer .body pre code { background: none; padding: 0; font-size: 11.5px; }
422
+ .msg.instructor-answer .body strong { color: var(--text); font-weight: 600; }
387
423
  .answer-new-badge { display: none; margin-bottom: 6px; color: var(--accent); font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
388
424
  .msg.instructor-answer-new .answer-new-badge { display: block; }
389
425
  .msg.instructor-answer-new .body {
@@ -401,6 +437,71 @@
401
437
  }
402
438
  @keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
403
439
 
440
+ /* ── AI answers: bulk toolbar + per-card collapse/remove ─────────────────── */
441
+ /* Sticky bulk row, rendered as the first child of #ai-answers (only when ≥1 answer exists — it is
442
+ hidden by simply not existing over an empty feed, never a disabled control). --surface matches the
443
+ pane so cards scroll cleanly beneath it; the negative margins cancel .messages' 14px side padding
444
+ so the row spans full width. */
445
+ .answers-toolbar {
446
+ position: sticky; top: 0; z-index: 2;
447
+ display: flex; align-items: center; gap: 8px;
448
+ margin: 0 -14px 2px; padding: 7px 14px;
449
+ background: var(--surface);
450
+ border-bottom: 1px solid var(--border);
451
+ }
452
+ .answers-toolbar-spacer { flex: 1 1 auto; }
453
+ .answers-count {
454
+ font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
455
+ color: var(--text-dim); font-variant-numeric: tabular-nums;
456
+ }
457
+ .answers-bulk {
458
+ appearance: none; border: 1px solid var(--border-strong); background: transparent;
459
+ color: var(--text-muted); cursor: pointer; padding: 4px 9px; border-radius: 4px;
460
+ font-size: 11.5px; line-height: 1;
461
+ }
462
+ .answers-bulk:hover { color: var(--text); background: var(--surface-3); }
463
+ .answers-bulk:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
464
+ /* Reversible-destructive idiom (see #requests-clear): neutral at rest, --err only on hover. */
465
+ .answers-clear:hover { color: var(--err); border-color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); }
466
+
467
+ /* The card header carries the chevron on the left and the × on the right; who-name takes the slack
468
+ between them so the timestamp + × sit flush-right. Center-aligned (the base .who is baseline, which
469
+ reads crooked next to 26px-tall buttons).
470
+ padding-right clears the narrative panel's absolutely-positioned, vertically-centred collapse
471
+ toggle (`.panel-label .panel-toggle`, ~28px wide at the panel's right edge, z-index 12): it floats
472
+ OVER the feed, so whichever card lands at the panel's vertical midpoint would otherwise have its ×
473
+ stolen by the toggle's hit area. Both toggle and card are right-anchored, so a fixed inset clears
474
+ it at every panel width. Only the header's right controls need it — the body stays full width. */
475
+ .msg.instructor-answer .who.answer-who { align-items: center; gap: 6px; padding-right: 24px; }
476
+ .msg.instructor-answer .answer-who .who-name { margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
477
+ .answer-collapse-toggle, .answer-del {
478
+ display: inline-flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0;
479
+ appearance: none; border: 1px solid transparent; background: transparent;
480
+ color: var(--text-dim); cursor: pointer; width: 20px; height: 20px; border-radius: 4px;
481
+ font-size: 12px; line-height: 1;
482
+ }
483
+ .answer-collapse-toggle { transition: transform 0.15s ease; }
484
+ /* Chevron points right when collapsed, rotates down when open. Rotate the glyph, not a swap, so the
485
+ motion reads as a disclosure. */
486
+ .msg.instructor-answer:not(.answer-collapsed) .answer-collapse-toggle { transform: rotate(90deg); }
487
+ .answer-collapse-toggle:hover { color: var(--text); background: var(--surface-3); }
488
+ .answer-del:hover { color: var(--err); border-color: var(--err); }
489
+ .answer-collapse-toggle:focus-visible, .answer-del:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
490
+ @media (prefers-reduced-motion: reduce) { .answer-collapse-toggle { transition: none; } }
491
+ /* Collapsed: the prose body (and, with it, the new-answer badge inside it) is hidden via a class —
492
+ not a bare `hidden` attribute, which app.css has no global rule for and would fail to honour. */
493
+ .msg.instructor-answer.answer-collapsed .body { display: none; }
494
+
495
+ /* Undo toast: a real focusable action inside the shared #toast-container surface. */
496
+ .toast-undo { display: flex; align-items: center; gap: 12px; }
497
+ .toast-action {
498
+ appearance: none; border: 1px solid var(--border-strong); background: transparent;
499
+ color: var(--accent); cursor: pointer; padding: 3px 10px; border-radius: 4px;
500
+ font-size: 12px; line-height: 1; flex-shrink: 0;
501
+ }
502
+ .toast-action:hover { color: var(--accent-bright); background: var(--surface-3); }
503
+ .toast-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
504
+
404
505
  /* ========== COLLAPSED STUBS ========== */
405
506
  .collapsed-stub {
406
507
  display: none;
package/dist/web/app.js CHANGED
@@ -291,7 +291,42 @@ function msgEl(cls, who, html, timestamp = new Date()) {
291
291
  return div;
292
292
  }
293
293
  function mdInline(s) {
294
- return s.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>').replace(/`(.+?)`/g, '<code>$1</code>');
294
+ // CODE SPANS COME OUT FIRST and go back last. Emphasis used to run over them, rewriting the inside
295
+ // of a <code>: `demos/*/*.flo` came out as `demos/<em>/</em>.flo` — the asterisks GONE from a path
296
+ // a reader copies, and the same for globs (`**/*.ts`), flags, regexes and pointer code, which is a
297
+ // large share of what an Instructor answer is made of. Markdown never processes emphasis inside a
298
+ // code span. Lifting them out also keeps emphasis able to WRAP one (`*see `foo` now*`), which
299
+ // per-segment processing would have broken instead.
300
+ //
301
+ // Bold FIRST among what remains, so the single-asterisk pass that follows sees only real italics.
302
+ // That pass may span the <strong> markup the earlier one produced — `*"the **first** point"*` is
303
+ // ordinary prose, and a guard against `<` left its asterisks on screen.
304
+ //
305
+ // WHAT MAKES THAT SAFE HAS TWO SHAPES, and only one of them is a call-site rule. `answerProse`
306
+ // (aware.js) and the guide description escape the WHOLE string before calling in. The narration
307
+ // lines cannot: they carry authored `**`/`` ` `` on purpose, so their producer escapes each
308
+ // INTERPOLATED VALUE where the line is assembled (see transform() in aware.js) and hands the line
309
+ // over already safe. Adding a narration line means escaping every interpolation there — nothing at
310
+ // this end will catch it for you. Either way no `<` here came from a user, so no pass can build a
311
+ // tag or an attribute out of one.
312
+ //
313
+ // Crossing tags CAN misnest (`<strong>a <em>b</strong> c</em>` from overlapping markers); the
314
+ // parser reparents it into valid-but-different DOM. Acceptable for prose, and the reason this is a
315
+ // pass chain rather than a parser.
316
+ const NUL = String.fromCharCode(0);
317
+ const code = [];
318
+ // NUL is stripped from the input BEFORE any placeholder is minted, so the sentinel cannot collide
319
+ // with text that happened to contain one — the single hazard a mask-and-restore carries. Restored
320
+ // by split parity rather than a regex: placeholders are then the only NULs present, so every odd
321
+ // segment is one, and neither emphasis pass adds or removes a NUL.
322
+ const masked = String(s).split(NUL).join('')
323
+ .replace(/`([^`]+)`/g, (_, body) => NUL + (code.push(body) - 1) + NUL);
324
+ return masked
325
+ .replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
326
+ .replace(/\*(?!\s)([^*]+?)\*/g, '<em>$1</em>')
327
+ .split(NUL)
328
+ .map((part, i) => (i % 2 ? `<code>${code[Number(part)]}</code>` : part))
329
+ .join('');
295
330
  }
296
331
 
297
332
  function renderTopology() {
@@ -1441,6 +1476,38 @@ function showToast(msg, type) {
1441
1476
  return dismiss;
1442
1477
  }
1443
1478
 
1479
+ // A toast carrying a real, focusable Undo action. Distinct from showToast because that surface has no
1480
+ // action slot. The undo window is the caller's to own (it holds the commit timer) and it should pass
1481
+ // that same duration as `ms` so the visible toast can't outlive the window it advertises — the `6000`
1482
+ // default is a floor, not the source of truth. Reuses #toast-container (already role=status aria-live=polite).
1483
+ function showUndoToast(msg, onUndo, ms = 6000) {
1484
+ const c = document.getElementById('toast-container');
1485
+ if (!c) return () => {};
1486
+ const t = document.createElement('div');
1487
+ t.className = 'toast info toast-undo';
1488
+ const span = document.createElement('span');
1489
+ span.className = 'toast-msg';
1490
+ span.textContent = msg; // textContent — never innerHTML
1491
+ const action = document.createElement('button');
1492
+ action.type = 'button';
1493
+ action.className = 'toast-action';
1494
+ action.textContent = 'Undo';
1495
+ let done = false;
1496
+ const dismiss = () => {
1497
+ if (done) return;
1498
+ done = true;
1499
+ t.style.transition = 'opacity 0.3s, transform 0.3s';
1500
+ t.style.opacity = '0';
1501
+ t.style.transform = 'translateY(8px)';
1502
+ setTimeout(() => t.remove(), 300);
1503
+ };
1504
+ action.onclick = () => { dismiss(); if (typeof onUndo === 'function') onUndo(); };
1505
+ t.append(span, action);
1506
+ c.appendChild(t);
1507
+ if (ms > 0) setTimeout(dismiss, ms);
1508
+ return dismiss;
1509
+ }
1510
+
1444
1511
  /* ============= ZOOM + PAN ============= */
1445
1512
 
1446
1513
  const ZOOM_LEVELS = [0.5, 0.6, 0.75, 0.85, 1.0, 1.15, 1.3, 1.5, 1.75, 2.0];