@rightkit/release 0.6.78 → 0.6.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/seam-broker.mjs CHANGED
@@ -119,6 +119,26 @@ const isPipe = (endpoint) => /^\\\\\.\\pipe\\/i.test(String(endpoint));
119
119
  * Where a control query to the broker goes and what identity it carries: the endpoint RustRight's discovery names (a user-owned socket, or a pipe) and the
120
120
  * runtime identity of the manifest beside the installed `client`. `{ ok, endpoint, identity }` or `{ ok: false, problem }`.
121
121
  */
122
+ /**
123
+ * Why `endpoint` is not this user's broker socket, or null when it is. The managed root may name the socket through a link to the broker's control
124
+ * root (the Mac: <managed>/broker.sock -> ~/Library/Application Support/RightKit/build-control/broker.sock). The link is followed: the socket it reaches
125
+ * must be a socket and, like the link itself, this user's. Checking only the link refused it as "not a socket", so the reclaim judge never asked the
126
+ * broker and a dead run's lock was kept for good (Mac, 2026-11-25, snapshot 770a65dcafd91981). `o` may inject lstat, realpath and uid.
127
+ */
128
+ export function socketProblem(endpoint, o = {}) {
129
+ try {
130
+ const lstat = o?.lstat ?? fs.lstatSync;
131
+ const uid = typeof (o?.uid ?? process.getuid?.()) === "number" ? (o?.uid ?? process.getuid()) : null;
132
+ const link = lstat(endpoint);
133
+ if (link.isSymbolicLink() && uid !== null && link.uid !== uid) return `${endpoint} is a link owned by another user (uid ${link.uid}), so it is not this user's broker`;
134
+ const target = link.isSymbolicLink() ? (o?.realpath ?? fs.realpathSync.native)(endpoint) : endpoint;
135
+ const stat = link.isSymbolicLink() ? lstat(target) : link;
136
+ if (!stat.isSocket()) return `${target === endpoint ? endpoint : `${endpoint} -> ${target}`} is not a socket, so it is not the broker's endpoint`;
137
+ if (uid !== null && stat.uid !== uid) return `${target} is owned by another user (uid ${stat.uid}), so it is not this user's broker`;
138
+ return null;
139
+ } catch (error) { return `cannot connect to the broker at ${endpoint} (${error?.code ?? error?.message ?? error})`; }
140
+ }
141
+
122
142
  export function brokerControlTarget(o, { client = o?.client } = {}) {
123
143
  const platform = o?.platform ?? process.platform;
124
144
  const env = o?.env ?? process.env;
@@ -138,12 +158,8 @@ export function brokerControlTarget(o, { client = o?.client } = {}) {
138
158
  try { endpoint = (o?.discoverEndpoint ?? discoverBrokerSocket)(env, { platform, exists: fs.existsSync }); } catch (error) { return { ok: false, problem: `the broker endpoint cannot be discovered (${error.message})` }; }
139
159
  if (!endpoint) return { ok: false, problem: "no broker endpoint is configured (no explicit socket variable and no broker.sock under a managed control root)" };
140
160
  if (platform !== "win32" && !isPipe(endpoint)) {
141
- try {
142
- const stat = (o?.lstat ?? fs.lstatSync)(endpoint);
143
- const uid = typeof (o?.uid ?? process.getuid?.()) === "number" ? (o?.uid ?? process.getuid()) : null;
144
- if (!stat.isSocket()) return { ok: false, problem: `${endpoint} is not a socket, so it is not the broker's endpoint` };
145
- if (uid !== null && stat.uid !== uid) return { ok: false, problem: `${endpoint} is owned by another user (uid ${stat.uid}), so it is not this user's broker` };
146
- } catch (error) { return { ok: false, problem: `cannot connect to the broker at ${endpoint} (${error?.code ?? error?.message ?? error})` }; }
161
+ const problem = socketProblem(endpoint, o);
162
+ if (problem) return { ok: false, problem };
147
163
  }
148
164
  return { ok: true, endpoint, identity: identity.identity };
149
165
  }
@@ -164,12 +180,16 @@ export function snapshotReclaimJudge({ o, client, snapshotPath, query = snapshot
164
180
  if (typeof snapshotPath !== "string" || !path.isAbsolute(snapshotPath)) throw new TypeError("snapshotReclaimJudge: snapshotPath must be absolute");
165
181
  const bound = { o, client: typeof client === "string" && client ? client : null, snapshotPath };
166
182
  return (holder) => {
183
+ // Every "no proof" says why: the reason was swallowed, so a link the endpoint check refused looked like a broker that would not answer (Mac,
184
+ // 2026-11-25).
185
+ const why = (text) => { try { bound.o?.err?.(`rightkit-gate: note: no reclaim proof for ${bound.snapshotPath}: ${text}`); } catch { /* a note only */ } return false; };
167
186
  try {
168
- if (!bound.client) return false;
187
+ if (!bound.client) return why("the RustRight client is not on PATH");
169
188
  const target = brokerControlTarget(bound.o, { client: bound.client });
170
- if (!target.ok) return false;
189
+ if (!target.ok) return why(target.problem);
171
190
  const message = snapshotStatusMessage({ protocol: BUILD_CONTROL_PROTOCOL, runtime: target.identity, snapshot: bound.snapshotPath, owner: holder });
172
- return snapshotStatusAllowsReclaim(query({ endpoint: target.endpoint, message, timeoutMs }), { snapshot: bound.snapshotPath, owner: holder });
173
- } catch { return false; }
191
+ const reply = query({ endpoint: target.endpoint, message, timeoutMs });
192
+ return snapshotStatusAllowsReclaim(reply, { snapshot: bound.snapshotPath, owner: holder }) || why(reply ? `the broker answered ${JSON.stringify(reply).slice(0, 600)}` : `the broker gave no answer within ${Math.round(timeoutMs / 1000)} s`);
193
+ } catch (error) { return why(error?.message ?? String(error)); }
174
194
  };
175
195
  }
@@ -780,6 +780,38 @@ const grantFinding = (source, id) => ({ file: source.file,
780
780
  });
781
781
 
782
782
  // ---- R6 qa-window-label ------------------------------------------------------------------------------------------------------
783
+ /** Windows an app builds through the shell's own hub_window builder: each `WindowBuild { label: X, .. }` (handed to
784
+ * `hub_window::build_window` / `build_window_with_native_options`) creates the label X at run time. Returns the labels, plus whether
785
+ * one could not be read (then nothing about the main label is concluded). */
786
+ export function hubWindowLabels(parsedFiles, consts = stringConsts(parsedFiles)) {
787
+ const labels = new Set();
788
+ let unknown = false;
789
+ for (const f of parsedFiles) for (const m of f.skel.matchAll(/\b(?:hub_window\s*::\s*)?WindowBuild\s*\{/g)) {
790
+ const open = m.index + m[0].length - 1;
791
+ const close = matchClose(f.skel, open);
792
+ if (close < 0) { unknown = true; continue; }
793
+ // The `label:` field at the struct's own depth.
794
+ let depth = 0; let found = null;
795
+ for (let k = open + 1; k < close && found === null; k++) {
796
+ const c = f.skel[k];
797
+ if (c === "(" || c === "[" || c === "{") depth += 1;
798
+ else if (c === ")" || c === "]" || c === "}") depth -= 1;
799
+ else if (depth === 0 && /\blabel\s*:/y.test(f.skel.slice(k, k + 64)) && !/\w/.test(f.skel[k - 1])) found = k;
800
+ }
801
+ if (found === null) { unknown = true; continue; }
802
+ const valueFrom = f.skel.indexOf(":", found) + 1;
803
+ let end = valueFrom;
804
+ for (let d = 0; end < close; end++) {
805
+ const c = f.skel[end];
806
+ if (c === "(" || c === "[" || c === "{") d += 1;
807
+ else if (c === ")" || c === "]" || c === "}") d -= 1;
808
+ else if (c === "," && d === 0) break;
809
+ }
810
+ const label = labelOf(f.code.slice(valueFrom, end).trim(), consts);
811
+ if (label === undefined) unknown = true; else labels.add(label);
812
+ }
813
+ return { labels, unknown };
814
+ }
783
815
  const qaWindowLabel = perApp(({ app, root }) => {
784
816
  const out = [];
785
817
  const parsed = readRust(root, app);
@@ -865,6 +897,10 @@ const qaWindowLabel = perApp(({ app, root }) => {
865
897
  const label = arg ? labelOf(f.code.slice(arg[0], arg[1]), consts) : undefined;
866
898
  if (label === undefined) unknownBuilder = true; else created.add(label);
867
899
  }
900
+ // The shell's hub_window builder creates its WindowBuild's label at run time (Pulse's "main", created by create_hub_window).
901
+ const hub = hubWindowLabels(parsed, consts);
902
+ for (const label of hub.labels) created.add(label);
903
+ if (hub.unknown) unknownBuilder = true;
868
904
  if (created.size > 0 && !created.has(shellLabel) && !unknownBuilder) {
869
905
  out.push({
870
906
  file: shellAt.file,