@floless/app 0.120.0 → 0.120.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52944,6 +52944,9 @@ async function execTeklaUnlocked(code, opts = {}) {
52944
52944
  async function execTekla(code, opts = {}) {
52945
52945
  return withAwareShared(() => withSidecarRead(() => execTeklaUnlocked(code, opts)));
52946
52946
  }
52947
+ function newRunTicket() {
52948
+ return { child: null, cancelled: false, adopted: false };
52949
+ }
52947
52950
  var activeRun = null;
52948
52951
  var runChain = Promise.resolve();
52949
52952
  function killTree(child) {
@@ -52959,16 +52962,19 @@ function killTree(child) {
52959
52962
  } catch {
52960
52963
  }
52961
52964
  }
52965
+ function cancelRun(ticket) {
52966
+ ticket.cancelled = true;
52967
+ if (!ticket.child) return false;
52968
+ killTree(ticket.child);
52969
+ return true;
52970
+ }
52962
52971
  function cancelActiveRun() {
52963
52972
  const run = activeRun;
52964
- if (!run) return false;
52973
+ if (!run || !run.child) return false;
52965
52974
  run.cancelled = true;
52966
52975
  killTree(run.child);
52967
52976
  return true;
52968
52977
  }
52969
- function isRunActive() {
52970
- return activeRun !== null;
52971
- }
52972
52978
  var LOGS_DIR = process.env.AWARE_HOME ? (0, import_node_path7.join)(process.env.AWARE_HOME, "logs") : (0, import_node_path7.join)((0, import_node_os7.homedir)(), ".aware", "logs");
52973
52979
  var TRIGGER_POLL_MS = 250;
52974
52980
  function parseRunHandle(stdout) {
@@ -53673,18 +53679,21 @@ var awareImpl = {
53673
53679
  args.push("--input", `${k}=${String(v)}`);
53674
53680
  }
53675
53681
  }
53682
+ const ticket = opts.ticket ?? newRunTicket();
53683
+ if (ticket.adopted) throw new AwareError("this RunTicket has already been used \u2014 mint a fresh one per run");
53684
+ ticket.adopted = true;
53676
53685
  const prev = runChain;
53677
53686
  let release;
53678
53687
  runChain = new Promise((r) => release = r);
53679
53688
  await prev.catch(() => {
53680
53689
  });
53681
- let reg2 = null;
53682
53690
  try {
53691
+ if (ticket.cancelled) throw new AwareError("Run cancelled", { cancelled: true });
53683
53692
  const { code, stdout, stderr } = await runRaw(args, (child) => {
53684
- reg2 = { child, cancelled: false };
53685
- activeRun = reg2;
53693
+ ticket.child = child;
53694
+ activeRun = ticket;
53686
53695
  }, opts.env, opts.timeoutMs);
53687
- if (reg2 && reg2.cancelled) {
53696
+ if (ticket.cancelled) {
53688
53697
  throw new AwareError("Run cancelled", { cancelled: true });
53689
53698
  }
53690
53699
  if (code !== 0) throw new AwareError(`aware app run failed (exit ${code})`, { stdout, stderr });
@@ -53693,7 +53702,8 @@ var awareImpl = {
53693
53702
  const traceText = tracePath && (0, import_node_fs8.existsSync)(tracePath) ? (0, import_node_fs8.readFileSync)(tracePath, "utf8") : null;
53694
53703
  return { runId, tracePath, traceText, output: stdout.trim() };
53695
53704
  } finally {
53696
- if (activeRun === reg2) activeRun = null;
53705
+ if (activeRun === ticket) activeRun = null;
53706
+ ticket.child = null;
53697
53707
  release();
53698
53708
  }
53699
53709
  },
@@ -54519,7 +54529,7 @@ function appVersion() {
54519
54529
  return resolveVersion({
54520
54530
  isSea: isSea2(),
54521
54531
  sqVersionXml: readSqVersionXml(),
54522
- define: true ? "0.120.0" : void 0,
54532
+ define: true ? "0.120.1" : void 0,
54523
54533
  pkgVersion: readPkgVersion()
54524
54534
  });
54525
54535
  }
@@ -54535,7 +54545,7 @@ function resolveChannel(s) {
54535
54545
  function appChannel() {
54536
54546
  return resolveChannel({
54537
54547
  isSea: isSea2(),
54538
- define: true ? "0.120.0" : void 0,
54548
+ define: true ? "0.120.1" : void 0,
54539
54549
  // argv[1] is the entry the runtime actually loaded (…/dist/floless-server.cjs), which is what
54540
54550
  // carries the npx cache prefix. Absent under the SEA exe, which never reaches the npx branch.
54541
54551
  modulePath: process.argv[1]
@@ -58757,7 +58767,7 @@ function nodeOutput(traceText, node) {
58757
58767
  const data = ev ? ev.data : null;
58758
58768
  return data && typeof data === "object" ? data : null;
58759
58769
  }
58760
- async function runReader(companionId, command, ifcPath, id) {
58770
+ async function runReader(companionId, command, ifcPath, id, opts = {}) {
58761
58771
  const prev = readerChain;
58762
58772
  let release;
58763
58773
  readerChain = new Promise((r) => release = r);
@@ -58772,7 +58782,7 @@ async function runReader(companionId, command, ifcPath, id) {
58772
58782
  }
58773
58783
  let traceText;
58774
58784
  try {
58775
- ({ traceText } = await aware.run(companionId, {}));
58785
+ ({ traceText } = await aware.run(companionId, { ticket: opts.ticket }));
58776
58786
  } catch (e) {
58777
58787
  const reason = e instanceof AwareError ? String(e.detail?.stderr ?? "").trim() : "";
58778
58788
  throw new ConnectionImportError(reason || (e instanceof Error ? e.message : "the connection reader failed"));
@@ -58784,9 +58794,9 @@ async function runReader(companionId, command, ifcPath, id) {
58784
58794
  release();
58785
58795
  }
58786
58796
  }
58787
- async function listConnections(companionId, ifcPath) {
58797
+ async function listConnections(companionId, ifcPath, opts = {}) {
58788
58798
  await ensureConnectionReader();
58789
- const out = await runReader(companionId, "list", ifcPath);
58799
+ const out = await runReader(companionId, "list", ifcPath, void 0, opts);
58790
58800
  if (!Array.isArray(out.connections)) {
58791
58801
  throw new ConnectionImportError(typeof out.message === "string" ? out.message : "no connections found in that IFC file");
58792
58802
  }
@@ -58931,9 +58941,9 @@ function sanitizeRecipe(raw) {
58931
58941
  }
58932
58942
  return Object.keys(num6).length ? { kind: r.kind, params: num6 } : void 0;
58933
58943
  }
58934
- async function extractConnection(companionId, ifcPath, id) {
58944
+ async function extractConnection(companionId, ifcPath, id, opts = {}) {
58935
58945
  await ensureConnectionReader();
58936
- const out = await runReader(companionId, "extract", ifcPath, id);
58946
+ const out = await runReader(companionId, "extract", ifcPath, id, opts);
58937
58947
  return toCustomConnection(out, id);
58938
58948
  }
58939
58949
 
@@ -61112,18 +61122,35 @@ function planTransform(plan) {
61112
61122
  var V1_SCHEMA_ADDITION_REASONS = Object.freeze({
61113
61123
  // "$.$defs.example.properties.futureField": "reader",
61114
61124
  });
61115
- function migrationBlockingCodes(report, candidate) {
61116
- const projectionCodes = [];
61125
+ function planBlockers(candidate) {
61126
+ const out = [];
61117
61127
  for (const plan of candidate?.plans ?? []) {
61118
61128
  if (plan.viewKind !== "plan") continue;
61119
61129
  try {
61120
61130
  planTransform({ ...plan, grid: candidate?.grid });
61121
61131
  } catch (error) {
61122
- projectionCodes.push(
61123
- `plan-uneditable:${error instanceof PlanTransformError ? error.code : "unknown"}`
61124
- );
61132
+ out.push({
61133
+ code: error instanceof PlanTransformError ? error.code : "unknown",
61134
+ sheet: plan.sheet || "?"
61135
+ });
61125
61136
  }
61126
61137
  }
61138
+ return out;
61139
+ }
61140
+ function planBlockerSummary(candidate, cap = 8) {
61141
+ const bySheet = /* @__PURE__ */ new Map();
61142
+ for (const { code, sheet } of planBlockers(candidate)) {
61143
+ if (!bySheet.has(code)) bySheet.set(code, []);
61144
+ bySheet.get(code).push(sheet);
61145
+ }
61146
+ return [...bySheet].map(([code, sheets]) => {
61147
+ const shown = sheets.slice(0, cap).join(", ");
61148
+ const more = sheets.length > cap ? ` and ${sheets.length - cap} more` : "";
61149
+ return `plan-uneditable:${code} on ${sheets.length === 1 ? "sheet" : "sheets"} ${shown}${more}`;
61150
+ });
61151
+ }
61152
+ function migrationBlockingCodes(report, candidate) {
61153
+ const projectionCodes = planBlockers(candidate).map((b) => `plan-uneditable:${b.code}`);
61127
61154
  return [.../* @__PURE__ */ new Set(
61128
61155
  [
61129
61156
  ...report.issues.filter((issue) => issue.severity === "block").map((issue) => issue.code),
@@ -61132,6 +61159,48 @@ function migrationBlockingCodes(report, candidate) {
61132
61159
  )].sort();
61133
61160
  }
61134
61161
 
61162
+ // provisional-preread.ts
61163
+ var PRE_READ_ROOT_KEYS = ["type", "filter", "datum", "source", "weights", "palette"];
61164
+ var PRE_READ_PLAN_KEYS = [
61165
+ "sheet",
61166
+ "title",
61167
+ "clip",
61168
+ "pt_per_ft",
61169
+ "raster_b64",
61170
+ "segments",
61171
+ "labels",
61172
+ "grid",
61173
+ "datum_at",
61174
+ "datum_ref",
61175
+ "control2_at",
61176
+ "control2_ref",
61177
+ "elevation_in"
61178
+ ];
61179
+ function holdsContent(v, depth = 0) {
61180
+ if (depth > 6) return true;
61181
+ if (Array.isArray(v)) return v.length > 0;
61182
+ if (v && typeof v === "object") return Object.values(v).some((x) => holdsContent(x, depth + 1));
61183
+ return typeof v === "string" ? v.length > 0 : false;
61184
+ }
61185
+ function carriesWork(obj2, allowed, skip) {
61186
+ const ok = new Set(allowed);
61187
+ for (const [key, value] of Object.entries(obj2)) {
61188
+ if (key === skip) continue;
61189
+ if (!ok.has(key) && holdsContent(value)) return true;
61190
+ }
61191
+ return false;
61192
+ }
61193
+ function v1CarriesAuthoredModel(doc) {
61194
+ if (!doc || typeof doc !== "object" || Array.isArray(doc)) return false;
61195
+ const d = doc;
61196
+ if (carriesWork(d, PRE_READ_ROOT_KEYS, "plans")) return true;
61197
+ for (const plan of Array.isArray(d.plans) ? d.plans : []) {
61198
+ if (!plan || typeof plan !== "object" || Array.isArray(plan)) continue;
61199
+ if (carriesWork(plan, PRE_READ_PLAN_KEYS)) return true;
61200
+ }
61201
+ return false;
61202
+ }
61203
+
61135
61204
  // contract-transaction.ts
61136
61205
  var ContractTransactionError = class extends Error {
61137
61206
  code;
@@ -61395,6 +61464,12 @@ async function runInitialReadToV2(opts) {
61395
61464
  "contract-already-exists"
61396
61465
  );
61397
61466
  }
61467
+ if (current != null && v1CarriesAuthoredModel(current)) {
61468
+ throw new ContractTransactionError(
61469
+ `this project already holds a populated ${STEEL_V1} model, which a first read would replace and activate without review \u2014 converting it is a migration decision, so run the migration instead`,
61470
+ "not-provisional"
61471
+ );
61472
+ }
61398
61473
  const head = ledgerHead(projectId);
61399
61474
  if (head !== 0) {
61400
61475
  throw new ContractTransactionError("the initial-read transaction requires empty project history", "history-already-exists");
@@ -61402,11 +61477,22 @@ async function runInitialReadToV2(opts) {
61402
61477
  if (declaredTypeOf(opts.v1) !== STEEL_V1) {
61403
61478
  throw new ContractTransactionError(`the reader staging document must be "${STEEL_V1}"`, "contract-type-unsupported");
61404
61479
  }
61480
+ if (opts.baseContract !== void 0 && opts.baseContract.length > 0) {
61481
+ const now = current == null ? null : `"${contractHash(current)}"`;
61482
+ if (now === null || !opts.baseContract.includes(now)) {
61483
+ throw new ContractTransactionError(
61484
+ "the project contract changed while this read was in progress \u2014 re-read the current version",
61485
+ "contract-changed"
61486
+ );
61487
+ }
61488
+ }
61405
61489
  const { candidate, report } = previewMigration(opts.v1);
61406
61490
  const codes = migrationBlockingCodes(report, candidate);
61407
61491
  if (!candidate || codes.length) {
61492
+ const where = planBlockerSummary(candidate);
61493
+ const nonPlan = codes.filter((c) => !c.startsWith("plan-uneditable:"));
61408
61494
  throw new ContractTransactionError(
61409
- `v1 reader staging must end because this fresh read cannot become ${STEEL_V2}: ${codes.join(", ") || "candidate unavailable"}`,
61495
+ `v1 reader staging must end because this fresh read cannot become ${STEEL_V2}: ${[...nonPlan, ...where].join(", ") || "candidate unavailable"}`,
61410
61496
  "v1-staging-exit"
61411
61497
  );
61412
61498
  }
@@ -67349,10 +67435,25 @@ function registerRevisionRoutes(app) {
67349
67435
  if (!request || request.type !== "revision-read" || request.project !== project.id) {
67350
67436
  return reply.status(400).send({ ok: false, error: "a valid queued revision-read requestId for this project is required" });
67351
67437
  }
67438
+ const alreadyCommitted = listVersions(project.id).find((row) => row.source?.requestId === request.id);
67439
+ if (alreadyCommitted) {
67440
+ deleteRequest(request.id);
67441
+ broadcast(contractChangedWithReason(project.app, project.id, "revision-read"));
67442
+ return { ok: true, version: alreadyCommitted, contractType: storedContractType(project.app, project.id) };
67443
+ }
67352
67444
  const head = listVersions(project.id)[0]?.n ?? 0;
67353
67445
  if ((request.baseVersion ?? 0) !== head) {
67354
67446
  return reply.status(409).send({ ok: false, error: `project changed since this read started (base v${request.baseVersion ?? 0}, now v${head}) \u2014 re-read the current version` });
67355
67447
  }
67448
+ const ifMatch = typeof req.headers["if-match"] === "string" ? req.headers["if-match"].trim() : "";
67449
+ const ifMatchTags = ifMatch.split(",").map((t) => t.trim()).filter(Boolean);
67450
+ if (ifMatch === "*") {
67451
+ return reply.status(400).send({
67452
+ ok: false,
67453
+ code: "precondition-unusable",
67454
+ error: "If-Match: * is not usable on a revision read \u2014 send the exact ETag of the contract this read was composed from, or omit the header entirely"
67455
+ });
67456
+ }
67356
67457
  const guardError = revisionReadContractError(resolveTemplateId(project.app), req.body.contract);
67357
67458
  if (guardError) {
67358
67459
  return reply.status(400).send({
@@ -67370,7 +67471,12 @@ function registerRevisionRoutes(app) {
67370
67471
  projectId: project.id,
67371
67472
  v1: req.body.contract,
67372
67473
  message,
67373
- ...source ? { source } : {}
67474
+ ...source ? { source } : {},
67475
+ // The base the READER composed against, carried as `If-Match` — the repo's CAS idiom, and
67476
+ // the same header the skill already has the AI send to `/steel-prepass`. It CANNOT be the
67477
+ // ledger-head-style guard the route computes for itself: only the reader knows which
67478
+ // document it read. See the header comment on this route.
67479
+ ...ifMatch ? { baseContract: ifMatchTags } : {}
67374
67480
  });
67375
67481
  const version2 = listVersions(project.id).find((row) => row.n === committed.versionN);
67376
67482
  broadcast(contractChangedWithReason(project.app, project.id, "revision-read"));
@@ -67769,10 +67875,27 @@ function renderable(o) {
67769
67875
  const q = o;
67770
67876
  return !!q && Array.isArray(q.positions) && Array.isArray(q.indices) && q.positions.length >= 9 && q.indices.length >= 3 && q.positions.length % 3 === 0;
67771
67877
  }
67878
+ var FILE_Z_UP = "z-up";
67879
+ var FILE_Y_UP = "y-up";
67880
+ function yUpToZUp(positions) {
67881
+ const out = new Array(positions.length);
67882
+ for (let i = 0; i + 2 < positions.length; i += 3) {
67883
+ out[i] = positions[i];
67884
+ out[i + 1] = -positions[i + 2];
67885
+ out[i + 2] = positions[i + 1];
67886
+ }
67887
+ return out;
67888
+ }
67772
67889
  function toReferenceObjects(raw) {
67773
67890
  if (!raw || !Array.isArray(raw.objects)) {
67774
67891
  throw new ReferenceImportError("the reference reader returned no objects");
67775
67892
  }
67893
+ const alreadyZUp = raw.frame === FILE_Z_UP;
67894
+ if (!alreadyZUp && raw.frame !== void 0 && raw.frame !== FILE_Y_UP) {
67895
+ throw new ReferenceImportError(
67896
+ `the reference reader returned a coordinate frame this version of FloLess does not understand (${JSON.stringify(raw.frame)}) \u2014 updating FloLess should fix it`
67897
+ );
67898
+ }
67776
67899
  const all = raw.objects;
67777
67900
  const objects = all.filter(renderable).map((o) => ({
67778
67901
  id: typeof o.id === "string" ? o.id : "",
@@ -67781,7 +67904,7 @@ function toReferenceObjects(raw) {
67781
67904
  storey: typeof o.storey === "string" ? o.storey : null,
67782
67905
  profile: typeof o.profile === "string" ? o.profile : null,
67783
67906
  material: typeof o.material === "string" ? o.material : null,
67784
- positions: o.positions.slice(),
67907
+ positions: alreadyZUp ? o.positions.slice() : yUpToZUp(o.positions),
67785
67908
  indices: o.indices.slice()
67786
67909
  }));
67787
67910
  return { objects, dropped: all.length - objects.length };
@@ -67814,7 +67937,13 @@ function writeReaderApp2(companionId, command, ifcPath) {
67814
67937
  `description: ${JSON.stringify(command === "probe" ? "Check what an IFC file says about itself \u2014 its units, schema, element count and rough extent \u2014 without reading its geometry, so an oversized file can be refused before it is loaded." : "Read a whole IFC file as reference geometry \u2014 every element as a mesh, with the name, type, storey, profile and material the file records for it.")}`,
67815
67938
  "exposes-as-agent: false",
67816
67939
  "requires:",
67817
- ` - ${AGENT2}@0.1.x`,
67940
+ // BOTH READER LINES, DELIBERATELY — do not narrow this to either one. floless supports 0.1.x and
67941
+ // 1.0.x alike and tells them apart by the `frame` in the response, so a pin that admits only one
67942
+ // would contradict the code that reads it. Measured on this machine 2026-08-01: the installed agent
67943
+ // manifest was 0.1.0 while the separately-installed bridge was 1.0.0 and returned `frame: "z-up"` —
67944
+ // the two are versioned independently, so no single pin describes what you will actually get.
67945
+ // (`0.1.x` alone was a plain misstatement: we consume 1.0.0's output every day.)
67946
+ ` - ${AGENT2}@>=0.1.0`,
67818
67947
  "layout: linear",
67819
67948
  "nodes:",
67820
67949
  ` - id: ${command}`,
@@ -67844,7 +67973,7 @@ async function ensureReferenceReader() {
67844
67973
  );
67845
67974
  }
67846
67975
  }
67847
- async function runReader2(companionId, command, ifcPath) {
67976
+ async function runReader2(companionId, command, ifcPath, opts = {}) {
67848
67977
  const prev = readerChain2;
67849
67978
  let release;
67850
67979
  readerChain2 = new Promise((r) => release = r);
@@ -67859,7 +67988,7 @@ async function runReader2(companionId, command, ifcPath) {
67859
67988
  }
67860
67989
  let traceText;
67861
67990
  try {
67862
- ({ traceText } = await aware.run(companionId, {}));
67991
+ ({ traceText } = await aware.run(companionId, { ticket: opts.ticket }));
67863
67992
  } catch (e) {
67864
67993
  const reason = e instanceof AwareError ? String(e.detail?.stderr ?? "").trim() : "";
67865
67994
  throw new ReferenceImportError(reason || (e instanceof Error ? e.message : "the reference reader failed"));
@@ -67871,9 +68000,9 @@ async function runReader2(companionId, command, ifcPath) {
67871
68000
  release();
67872
68001
  }
67873
68002
  }
67874
- async function probeReference(companionId, ifcPath) {
68003
+ async function probeReference(companionId, ifcPath, opts = {}) {
67875
68004
  await ensureReferenceReader();
67876
- const out = await runReader2(companionId, "probe", ifcPath);
68005
+ const out = await runReader2(companionId, "probe", ifcPath, opts);
67877
68006
  const units = out.units ?? {};
67878
68007
  const bbox = out.bbox;
67879
68008
  return {
@@ -67885,9 +68014,9 @@ async function probeReference(companionId, ifcPath) {
67885
68014
  bbox: bbox && Array.isArray(bbox.min) && Array.isArray(bbox.max) ? bbox : null
67886
68015
  };
67887
68016
  }
67888
- async function readReferenceModel(companionId, ifcPath) {
68017
+ async function readReferenceModel(companionId, ifcPath, opts = {}) {
67889
68018
  await ensureReferenceReader();
67890
- const out = await runReader2(companionId, "read-model", ifcPath);
68019
+ const out = await runReader2(companionId, "read-model", ifcPath, opts);
67891
68020
  return toReferenceObjects(out);
67892
68021
  }
67893
68022
 
@@ -67964,7 +68093,7 @@ function cachedGeometry(projectId, refId2, expectHash) {
67964
68093
  if (!(0, import_node_fs32.existsSync)(p)) return null;
67965
68094
  try {
67966
68095
  const parsed = JSON.parse((0, import_node_fs32.readFileSync)(p, "utf8"));
67967
- if (!parsed || parsed.v !== 1 || !Array.isArray(parsed.objects)) return null;
68096
+ if (!parsed || parsed.v !== 2 || !Array.isArray(parsed.objects)) return null;
67968
68097
  if (parsed.sourceHash !== expectHash) return null;
67969
68098
  return parsed;
67970
68099
  } catch {
@@ -67985,6 +68114,27 @@ function takenReferencePaths(refs) {
67985
68114
  // reference-routes.ts
67986
68115
  var APPID = /^[a-z0-9][a-z0-9._-]*$/i;
67987
68116
  var REFERENCE_BODY_LIMIT = 210 * 1024 * 1024;
68117
+ function runScope(deps, req) {
68118
+ let done = false;
68119
+ let abandoned = false;
68120
+ let current = null;
68121
+ req.raw.on("close", () => {
68122
+ if (done) return;
68123
+ abandoned = true;
68124
+ if (current) deps.runControl.cancel(current);
68125
+ });
68126
+ return {
68127
+ /** A fresh identity for the next run — already cancelled if the client has gone. */
68128
+ ticket() {
68129
+ current = deps.runControl.newTicket();
68130
+ if (abandoned) deps.runControl.cancel(current);
68131
+ return current;
68132
+ },
68133
+ finish() {
68134
+ done = true;
68135
+ }
68136
+ };
68137
+ }
67988
68138
  var companion = (appId) => `${appId}-refimport`;
67989
68139
  var ReferenceLockedError = class extends Error {
67990
68140
  constructor(refName2) {
@@ -68066,12 +68216,9 @@ function registerReferenceRoutes(app, deps) {
68066
68216
  if (r) return reply.status(r.status).send(r.body);
68067
68217
  throw e;
68068
68218
  }
68069
- let done = false;
68070
- req.raw.on("close", () => {
68071
- if (!done && deps.runControl.isRunActive()) deps.runControl.cancelActiveRun();
68072
- });
68219
+ const scope = runScope(deps, req);
68073
68220
  try {
68074
- const probe = await deps.reader.probe(companion(g.appId), stored.path);
68221
+ const probe = await deps.reader.probe(companion(g.appId), stored.path, { ticket: scope.ticket() });
68075
68222
  return { ok: true, sha: stored.sha256, bytes: stored.bytes, warn, probe, verdict: verdictFor(probe, req.body?.nativeSpan, req.body?.nativeCenter) };
68076
68223
  } catch (e) {
68077
68224
  const r = importRefusal(e);
@@ -68079,7 +68226,7 @@ function registerReferenceRoutes(app, deps) {
68079
68226
  app.log.error({ appId: g.appId, err: e instanceof Error ? e.message : e }, "reference probe failed");
68080
68227
  return reply.status(500).send({ ok: false, error: "could not read that IFC file" });
68081
68228
  } finally {
68082
- done = true;
68229
+ scope.finish();
68083
68230
  }
68084
68231
  }
68085
68232
  );
@@ -68120,21 +68267,18 @@ function registerReferenceRoutes(app, deps) {
68120
68267
  app.log.error({ project: g.project, id, rel, err: e instanceof Error ? e.message : e }, "reference rollback failed \u2014 an orphaned original is left on disk");
68121
68268
  }
68122
68269
  };
68123
- let done = false;
68124
- req.raw.on("close", () => {
68125
- if (!done && deps.runControl.isRunActive()) deps.runControl.cancelActiveRun();
68126
- });
68270
+ const scope = runScope(deps, req);
68127
68271
  try {
68128
68272
  const abs = originalPath(g.project, rel);
68129
68273
  if (!abs) throw new ReferenceImportError("the copied file vanished before it could be read");
68130
- const probe = await deps.reader.probe(companion(g.appId), abs);
68274
+ const probe = await deps.reader.probe(companion(g.appId), abs, { ticket: scope.ticket() });
68131
68275
  const sourceHash = await hashFile(abs);
68132
- const geometry = await deps.reader.readModel(companion(g.appId), abs);
68276
+ const geometry = await deps.reader.readModel(companion(g.appId), abs, { ticket: scope.ticket() });
68133
68277
  if (!geometry.objects.length) {
68134
68278
  rollback();
68135
68279
  return reply.status(400).send({ ok: false, error: `"${displayName}" has no geometry we can draw` });
68136
68280
  }
68137
- writeCache2(g.project, id, { v: 1, sourceHash, dropped: geometry.dropped, objects: geometry.objects });
68281
+ writeCache2(g.project, id, { v: 2, sourceHash, dropped: geometry.dropped, objects: geometry.objects });
68138
68282
  const entry2 = {
68139
68283
  id,
68140
68284
  file: rel,
@@ -68168,7 +68312,7 @@ function registerReferenceRoutes(app, deps) {
68168
68312
  app.log.error({ appId: g.appId, err: e instanceof Error ? e.message : e }, "reference insert failed");
68169
68313
  return reply.status(500).send({ ok: false, error: "could not load that reference model" });
68170
68314
  } finally {
68171
- done = true;
68315
+ scope.finish();
68172
68316
  }
68173
68317
  }
68174
68318
  );
@@ -68195,12 +68339,9 @@ function registerReferenceRoutes(app, deps) {
68195
68339
  }
68196
68340
  const hit = cachedGeometry(g.project, entry2.id, sourceHash);
68197
68341
  if (hit) return { ok: true, cached: true, objects: hit.objects, dropped: hit.dropped, spanMm: spanOf(hit.objects) };
68198
- let done = false;
68199
- req.raw.on("close", () => {
68200
- if (!done && deps.runControl.isRunActive()) deps.runControl.cancelActiveRun();
68201
- });
68342
+ const scope = runScope(deps, req);
68202
68343
  try {
68203
- const geometry = await deps.reader.readModel(companion(g.appId), abs);
68344
+ const geometry = await deps.reader.readModel(companion(g.appId), abs, { ticket: scope.ticket() });
68204
68345
  if (!geometry.objects.length) {
68205
68346
  return reply.status(409).send({
68206
68347
  ok: false,
@@ -68208,7 +68349,7 @@ function registerReferenceRoutes(app, deps) {
68208
68349
  error: `"${entry2.name}" was read, but produced nothing we can draw` + (geometry.dropped ? ` (${geometry.dropped} object${geometry.dropped === 1 ? "" : "s"} had no usable mesh)` : "") + ". The file may be a newer IFC flavour than the reader handles."
68209
68350
  });
68210
68351
  }
68211
- writeCache2(g.project, entry2.id, { v: 1, sourceHash, dropped: geometry.dropped, objects: geometry.objects });
68352
+ writeCache2(g.project, entry2.id, { v: 2, sourceHash, dropped: geometry.dropped, objects: geometry.objects });
68212
68353
  return { ok: true, cached: false, objects: geometry.objects, dropped: geometry.dropped, spanMm: spanOf(geometry.objects) };
68213
68354
  } catch (e) {
68214
68355
  const r = importRefusal(e);
@@ -68216,7 +68357,7 @@ function registerReferenceRoutes(app, deps) {
68216
68357
  app.log.error({ appId: g.appId, id: entry2.id, err: e instanceof Error ? e.message : e }, "reference rebuild failed");
68217
68358
  return reply.status(500).send({ ok: false, error: `could not re-read "${entry2.name}"` });
68218
68359
  } finally {
68219
- done = true;
68360
+ scope.finish();
68220
68361
  }
68221
68362
  }
68222
68363
  );
@@ -84155,7 +84296,7 @@ async function startServer() {
84155
84296
  getProject,
84156
84297
  broadcast,
84157
84298
  reader: { probe: probeReference, readModel: readReferenceModel },
84158
- runControl: { isRunActive, cancelActiveRun }
84299
+ runControl: { newTicket: newRunTicket, cancel: cancelRun }
84159
84300
  });
84160
84301
  const CONN_APPID = /^[a-z0-9][a-z0-9._-]*$/i;
84161
84302
  app.post(
@@ -84174,11 +84315,12 @@ async function startServer() {
84174
84315
  throw e;
84175
84316
  }
84176
84317
  let done = false;
84318
+ const ticket = newRunTicket();
84177
84319
  req.raw.on("close", () => {
84178
- if (!done && isRunActive()) cancelActiveRun();
84320
+ if (!done) cancelRun(ticket);
84179
84321
  });
84180
84322
  try {
84181
- const connections = await listConnections(`${appId}-connimport`, stored.path);
84323
+ const connections = await listConnections(`${appId}-connimport`, stored.path, { ticket });
84182
84324
  return { ok: true, sha: stored.sha256, connections };
84183
84325
  } catch (e) {
84184
84326
  if (e instanceof ConnectionImportError) return reply.send({ ok: false, error: e.message });
@@ -84198,11 +84340,12 @@ async function startServer() {
84198
84340
  const path = ifcInputPath(appId, sha);
84199
84341
  if (!path) return reply.status(404).send({ ok: false, error: "the uploaded IFC is no longer available \u2014 drop the file again" });
84200
84342
  let done = false;
84343
+ const ticket = newRunTicket();
84201
84344
  req.raw.on("close", () => {
84202
- if (!done && isRunActive()) cancelActiveRun();
84345
+ if (!done) cancelRun(ticket);
84203
84346
  });
84204
84347
  try {
84205
- const connection = await extractConnection(`${appId}-connimport`, path, id);
84348
+ const connection = await extractConnection(`${appId}-connimport`, path, id, { ticket });
84206
84349
  if (!connection.geometry.length) return reply.send({ ok: false, error: "that connection has no importable geometry" });
84207
84350
  return { ok: true, connection };
84208
84351
  } catch (e) {
@@ -2,7 +2,7 @@
2
2
  name: floless-app-steel-takeoff
3
3
  description: Read a structural steel drawing into an editable steel.takeoff/v1 contract in floless.app — the "Steel Takeoff" reader. Triggers on a pending floless `rebake` request for the `steel-model` app (queued from its "Re-read & re-bake ▸" button), or asks like "read this framing plan into a takeoff", "turn this structural drawing into a takeoff", "bake my drawing into steel-model", "extract members from this PDF". Teaches the host AI to READ a steel drawing (PDF/image) with its own vision at COMPOSE time, build a steel.takeoff/v1 contract (members + profiles + elevations + weights from AISC lookup), write it to the contract store, and hand control to the editor — no model in the run path, no API key.
4
4
  metadata:
5
- version: 0.13.0
5
+ version: 0.15.0
6
6
  ---
7
7
 
8
8
  # Steel Takeoff — read a drawing into a steel.takeoff/v1 contract
@@ -315,7 +315,12 @@ text layer. You CAN read them: you already have vision on the sheet. So:
315
315
  onto the other, silently. The 1b write already happened, and the user's next Filter-node Save writes
316
316
  back the contract *it loaded*; an unwritten grid (and its vision-read labels) would be silently dropped.
317
317
 
318
- Skip silently only when the sheet genuinely has no grid bubbles (rare for framing plans); say so.
318
+ **Do not "skip silently" a gridless sheet — the same trap as the registration one below.** A plan with
319
+ no `grid` raises `grid-missing` at severity **block**, which refuses the ENTIRE first read exactly as a
320
+ missing control does. If a framing plan genuinely prints no grid bubbles (rare), it cannot be presented
321
+ as a plan at all: leave it out of `plans[]`, follow *Registration is mandatory on every plan sheet*
322
+ (§1d) — including its warning that an omitted sheet's MEMBERS are dropped with it — and tell the user
323
+ which sheet and why.
319
324
 
320
325
  ### 1d. Model datum — ASK which grid intersection is global 0,0,0
321
326
 
@@ -388,15 +393,75 @@ Same flat shape as the datum above — a point plus which intersection it is:
388
393
  baseline, the smaller the angular error. Diagonally opposite is ideal.
389
394
  - Same reading rules as the datum: take the labels from `labels_x` / `labels_y`, never guess from
390
395
  appearance, never invent an intersection the sheet does not print.
391
- - **When the sheet prints only one labelled intersection**, omit both fields and say so. That sheet can
392
- be positioned but not orientation-checked, and a later step may have to ask for another control.
396
+ - **When the sheet prints only one labelled intersection, you cannot omit these and carry on.** Earlier
397
+ guidance here said to omit both fields and say so; that is now wrong, and following it fails the whole
398
+ read. `control2_at` and `control2_ref` are REQUIRED on every plan sheet — see *Registration is
399
+ mandatory* immediately below for what to do instead.
393
400
  - Do NOT ask the user for this one — unlike the datum, it is not a project decision. It is a second
394
401
  reading of something already printed, so read it.
395
402
 
396
- - **Any intersection is a valid datum** — verified: the choice moves registration by under 1 mm. What
397
- matters is that **every sheet uses the same one**, not which one gets picked.
398
- - Never guess a datum. When a sheet prints no labelled intersection at all, leave `datum_at` unset and
399
- say which sheets are unregistered — do NOT substitute an unlabelled crossing.
403
+ - **Any intersection is a valid datum** — verified: the choice moves registration by under 1 mm. Pick
404
+ one for the model and prefer it on every sheet that prints it, because a shared datum makes the set
405
+ easiest to reason about. But sheets do NOT have to agree: `planTransform` resolves each sheet's own
406
+ `datum_ref` against the model grid, so a sheet that cannot print the chosen intersection may name a
407
+ different one and still register correctly. (An earlier version of this line said every sheet must use
408
+ the same one, which contradicted the `datum_ref` mechanism three paragraphs above.)
409
+ - Never guess a datum, and never substitute an unlabelled crossing. When a sheet prints no labelled
410
+ intersection at all, see *Registration is mandatory* below — you cannot simply leave `datum_at` unset
411
+ and continue.
412
+ ### Registration is MANDATORY on every plan sheet — an unregistered sheet fails the whole read
413
+
414
+ **`datum_at`, `control2_at` and `control2_ref` are required on every sheet you present as a framing
415
+ plan.** Not best-effort, not "record it when the sheet prints it". A first read composes a
416
+ `steel.takeoff/v1` staging document, and the server converts it to `steel.model/v2` inside one
417
+ transaction. That conversion runs `planTransform` over every plan sheet, and a sheet missing any of
418
+ those three is refused with `plan-uneditable:registration-incomplete` — which **fails the entire read**.
419
+ Nothing is published: no model, no version, no partial import. One unregistered sheet in a twenty-sheet
420
+ set costs you all twenty.
421
+
422
+ (That is why the older advice above — "omit both fields and say so", "leave `datum_at` unset and say
423
+ which sheets are unregistered" — no longer holds. It predates the born-v2 transaction and, followed
424
+ literally, guarantees a 400.)
425
+
426
+ **When the drawing genuinely will not give you two labelled intersections on a sheet:**
427
+
428
+ 1. **Look harder first, in this order.** Grid bubbles are often outside the framing area — check the
429
+ full page, not the crop. Continuation/match lines carry axis labels. An enlarged plan usually prints
430
+ at least one bubble pair even when the main crop does not. A second control does not have to be near
431
+ the steel; furthest-apart is better.
432
+ 2. **If it still prints only one, or none: do NOT present that sheet as a plan.** Leave it out of
433
+ `plans[]` for this read and record why in `read_notes` — name the sheet and say what was missing.
434
+ The rest of the set then imports normally, and the user gets a model instead of a refusal.
435
+
436
+ **An omitted sheet contributes NOTHING — not just its registration, but its members.** The read only
437
+ ever sees the plans you submit, so nothing from that sheet reaches the model. Registering it in the
438
+ editor afterwards cannot recover members that were never read: the sheet needs a fresh read once it
439
+ can be registered. Say that to the user, or they will assume the steel is there and unpositioned.
440
+
441
+ **AND CLEAR EVERY MODEL-LEVEL REFERENCE TO THOSE MEMBERS, or the read still fails.** v1 stores
442
+ members inside their plan, but several blocks point AT them from the document root, and a dangling
443
+ reference is its own blocking issue — you escape `registration-incomplete` straight into
444
+ `prop-label-unresolved`, `joint-ref-unresolved` or `candidate-references-broken`, which is more
445
+ cryptic and, because no candidate gets built, names **no sheet at all**. Before dropping a sheet,
446
+ remove every id belonging to it from:
447
+
448
+ `prop_labels.ids` · `joints[].main` and `joints[].secondaries` · `views[].objects` ·
449
+ `detail_placements[].sheet` · any cross-sheet `dims` reference.
450
+ 3. **If it is the ONLY framing plan in the set, there is no way through.** A read with no plans is
451
+ refused with `no-plans`. Say so and stop — do not invent a datum to get past the gate.
452
+ 4. **Tell the user plainly which sheets you left out and why**, so they can decide: mark up the drawing
453
+ with a labelled control and re-read, or accept the omission. That is their call, not yours to make
454
+ silently either way.
455
+
456
+ **Never** invent a datum, reuse another sheet's coordinates, or fabricate `control2_ref` labels to get
457
+ past the gate. A registration that is wrong is worse than a sheet that is absent: every member read
458
+ from that sheet lands in the wrong place, and nothing downstream can tell.
459
+
460
+ If a read is refused anyway, the error names the sheets — e.g.
461
+ `plan-uneditable:registration-incomplete on sheets S-203, S-207`. Fix or drop exactly those and re-read.
462
+ (Verified against the message the server actually produces — `steel-takeoff-skill-registration.test.ts`
463
+ pins the two in step, because an example the AI cannot find in the error is worse than no example.)
464
+
400
465
  - **Say so when a sheet is rotated or mirrored** relative to the others (a plan drawn at a skew, or a
401
466
  reversed-hand view). A datum point fixes translation only; it cannot correct orientation, and
402
467
  registering such a sheet as if it were square would silently distort every member read from it.
@@ -743,15 +808,22 @@ excluded from the average and counted separately as the headline drag).
743
808
  **The score endpoint is your gauge — call it, don't guess:**
744
809
 
745
810
  ```
746
- POST http://localhost:<port>/api/contract/steel-model/score
811
+ POST http://localhost:<port>/api/contract/steel-model/score?project=<projectId>
747
812
  Content-Type: application/json
748
813
  { "contract": <your draft contract>, "target": <target_confidence, e.g. 70> }
749
814
  ```
750
815
 
816
+ **Pass `?project=` whenever you are working inside a project.** It scopes the fallback read and the
817
+ confidence target to that project. Without it — and this route used to IGNORE the parameter entirely
818
+ (#511) — a body-less call scores the APP-level document instead: a confidence answer about a model you
819
+ did not ask about, returned with no error. This route is the gauge the read-loop uses to decide when to
820
+ STOP reading, so a confident number about the wrong model is the worst possible answer. It is safe to
821
+ omit only when there is genuinely no project.
822
+
751
823
  Returns `{ score, target, meetsTarget, gap, rfiCount, counts, worklist, filterMissing }` — the SAME
752
824
  aggregate the editor's Confidence chip shows. `worklist` is the rfi/low/med members dragging the score,
753
825
  worst-first (heaviest first within a band), each with a `reason`. (Omit `contract` to score the stored
754
- one.)
826
+ one — that is the read the `?project=` scope governs.)
755
827
 
756
828
  **`filterMissing` is the completeness gate — independent of the confidence score.** `true` means the
757
829
  contract has no usable `filter` block: step 1b never ran, so the members were bound by the length
@@ -1259,6 +1331,11 @@ So the re-read must keep identity stable:
1259
1331
  > that was stored. If the staging cannot be converted the answer is a `400` naming the reason
1260
1332
  > (`v1-staging-exit`, e.g. `grid-lines-unmigrated` or `plan-uneditable:registration-incomplete`) and
1261
1333
  > **nothing is published** — no contract, no activation, no version. Fix the read and re-post.
1334
+ >
1335
+ > **`plan-uneditable:registration-incomplete` or `grid-missing` → go back to
1336
+ > §1d *Registration is mandatory on every plan sheet*.** The message names the sheets. That section
1337
+ > is where the fix is, and it is 900 lines above this one — this pointer exists because this 400 is
1338
+ > where you will be standing when you need it.
1262
1339
 
1263
1340
  > **On a `steel.model/v2` project compose a `steel.model/v2` document instead** — check the `type`
1264
1341
  > of the contract you GET-ed in step 1. Members live in one root `members[]` in world millimetres,
@@ -918,24 +918,23 @@ const XREF_SNAP_BUDGET = 6000;
918
918
  */
919
919
  const XREF_SNAP_KEEP = 40_000;
920
920
 
921
- /**
922
- * Y-UP INTO Z-UP, and this is the one thing here that was found by measuring rather than by reading.
923
- *
924
- * The reader's two commands disagree about which axis is up, inside one agent. `probe` reports
925
- * `example-steel-framing.ifc` as 12000 x 6000 x **4500** — Z is the 4500 mm column height, read
926
- * straight off the file's own IFCCARTESIANPOINTs. The mesh `read-model` returns for the same file
927
- * measures 12150 x **4625** x 6150: height has moved into Y. web-ifc hands back a Y-up tessellation
928
- * while the bbox stays in the file's frame.
929
- *
930
- * Our scene is Z-up (`contractToScene` emits `meta.up='z'`), so without this every reference lies on
931
- * its side — which is exactly what the acceptance list's first case is for: our own export, loaded
932
- * back, must coincide with the native model. It did not.
933
- *
934
- * Corrected HERE rather than by scaling or by asking the user, because it is a frame convention and
935
- * this is the renderer that owns the frame. Filed against AWARE separately: the disagreement between
936
- * `probe`'s bbox and `read-model`'s mesh belongs in the agent, not in every consumer of it.
937
- */
938
- const XREF_Y_UP_TO_Z_UP = new THREE.Matrix4().makeRotationX(Math.PI / 2);
921
+ // NO FRAME CORRECTION HERE — deliberately, and this is where one used to live.
922
+ //
923
+ // Reference vertices arrive already in the file's own Z-up world frame, the same frame our scene uses
924
+ // (`contractToScene` emits `meta.up='z'`). `toReferenceObjects` (server/reference-import.ts) settles
925
+ // that on the way in: it turns web-ifc's Y-up tessellation UNLESS the reader states `frame: 'z-up'`.
926
+ // An absent `frame` means the pre-1.0.0 reader, and IS turned — that omission is the whole upgrade
927
+ // path, so "only when it says y-up" would describe the opposite of the default that carries this.
928
+ //
929
+ // Until AWARE's `ifc-reference-reader` 1.0.0 this renderer composed a `makeRotationX(PI/2)` of its own,
930
+ // because `read-model` shipped web-ifc's Y-up mesh while `probe` reported the file's Z-up box
931
+ // (aware-aeco/aware#343, fixed upstream in CLI v0.114.0). Against a current bridge that rotation is now
932
+ // WRONG — it would take correct geometry and lay it on its side, the very defect it was written to
933
+ // cure. It moved to the adapter rather than being deleted outright because a stale bridge still returns
934
+ // Y-up, and only the response itself can say which one arrived.
935
+ //
936
+ // So: do not reintroduce a rotation here — in any spelling. If a reference renders on its side, the
937
+ // question is which `frame` the reader sent, and the answer belongs in `toReferenceObjects`.
939
938
 
940
939
  /** Scale about the insertion point, then rotate about Z, then move — the order the schema documents. */
941
940
  function xrefMatrix(placement) {
@@ -946,8 +945,7 @@ function xrefMatrix(placement) {
946
945
  return new THREE.Matrix4()
947
946
  .makeTranslation(o[0] || 0, o[1] || 0, o[2] || 0)
948
947
  .multiply(new THREE.Matrix4().makeRotationZ(rot))
949
- .multiply(new THREE.Matrix4().makeScale(s, s, s))
950
- .multiply(XREF_Y_UP_TO_Z_UP); // innermost: the reader's frame becomes ours BEFORE anything is placed
948
+ .multiply(new THREE.Matrix4().makeScale(s, s, s));
951
949
  }
952
950
 
953
951
  /** Unique world points for snapping, quantised so a tessellated corner is one target and not thirty. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.120.0",
3
+ "version": "0.120.1",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {