@apilift/cli 1.10.2 → 1.10.3-dev.1795080340.6d0fd10a3db49e459f451c6ed939a5f24e5fcf8e

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.
@@ -19876,58 +19876,48 @@ var extensionPageMessageSchema = external_exports.discriminatedUnion("operation"
19876
19876
  ]);
19877
19877
 
19878
19878
  // src/capture-server/windows-owner.ts
19879
- import { Worker } from "node:worker_threads";
19880
- var script = `$ErrorActionPreference='Stop'; while ($null -ne ($line=[Console]::ReadLine())) { $parts=$line.Split('|'); try { $p=[System.Diagnostics.Process]::GetProcessById([int]$parts[1]); $stamp=([DateTimeOffset]$p.StartTime.ToUniversalTime()).ToUnixTimeMilliseconds(); $p.Dispose() } catch { $stamp=0 }; [Console]::WriteLine($parts[0]+'|'+$stamp); [Console]::Out.Flush() }`;
19881
- var workerSource = `
19882
- const {workerData}=require('node:worker_threads');
19883
- const {spawn}=require('node:child_process');
19884
- const state=new Int32Array(workerData.memory,0,4), value=new Float64Array(workerData.memory,16,1);
19885
- const child=spawn('powershell.exe',['-NoLogo','-NoProfile','-NonInteractive','-Command',workerData.script],{windowsHide:true,stdio:['pipe','pipe','ignore']});
19886
- const fail=()=>{Atomics.store(state,0,3);Atomics.notify(state,0);};
19887
- child.on('error',fail);child.on('exit',fail);
19888
- let text='';
19889
- child.stdout.on('data',chunk=>{
19890
- text+=chunk.toString();
19891
- let end;
19892
- while((end=text.indexOf('\\n'))>=0){
19893
- const [id,stamp]=text.slice(0,end).trim().split('|').map(Number);text=text.slice(end+1);
19894
- if(id!==Atomics.load(state,1)||Atomics.load(state,0)!==1)continue;
19895
- value[0]=Number.isFinite(stamp)?stamp:0;Atomics.store(state,2,id);Atomics.store(state,0,2);Atomics.notify(state,0);
19896
- }
19897
- if(text.length>1024){child.kill();fail();}
19898
- });
19899
- const {parentPort}=require('node:worker_threads');
19900
- parentPort.on('message',({id,pid})=>{try{child.stdin.write(id+'|'+pid+'\\n');}catch{fail();}});
19901
- `;
19902
- var worker;
19903
- var memory;
19904
- var sequence = 0;
19905
- function windowsProcessStart(pid, isAlive) {
19906
- if (!worker) {
19907
- memory = new SharedArrayBuffer(24);
19908
- worker = new Worker(workerSource, { eval: true, workerData: { memory, script } });
19909
- worker.on("error", () => {
19910
- });
19911
- worker.unref();
19912
- }
19913
- const state = new Int32Array(memory, 0, 4), value = new Float64Array(memory, 16, 1);
19914
- const deadline = performance.now() + 8e3;
19915
- for (let attempt = 0; attempt < 2; attempt++) {
19916
- if (!isAlive()) return null;
19917
- const remaining = deadline - performance.now();
19918
- if (remaining <= 0) break;
19919
- const id2 = ++sequence;
19920
- Atomics.store(state, 1, id2);
19921
- Atomics.store(state, 0, 1);
19922
- worker.postMessage({ id: id2, pid });
19923
- const result = Atomics.wait(state, 0, 1, Math.min(4e3, remaining));
19924
- const status = Atomics.load(state, 0);
19925
- if (status === 2) return Atomics.load(state, 2) === id2 && Number.isFinite(value[0]) && value[0] > 0 && isAlive() ? value[0] : null;
19926
- if (result !== "timed-out" || status !== 1) break;
19927
- }
19928
- void worker.terminate();
19929
- worker = void 0;
19930
- return null;
19879
+ import { createRequire as createNativeRequire } from "node:module";
19880
+ var requireNative = createNativeRequire(import.meta.url);
19881
+ var queryAndSynchronize = 1052672;
19882
+ var waitTimeout = 258;
19883
+ var unixEpochFileTime = 116444736000000000n;
19884
+ var cachedApi;
19885
+ function windowsProcessApi() {
19886
+ if (cachedApi) return cachedApi;
19887
+ const koffi = requireNative("koffi");
19888
+ const kernel = koffi.load("kernel32.dll");
19889
+ const open2 = kernel.func("void * __stdcall OpenProcess(uint32_t access, int inherit, uint32_t pid)");
19890
+ const times = kernel.func("int __stdcall GetProcessTimes(void *process, void *created, void *exited, void *kernel, void *user)");
19891
+ const wait = kernel.func("uint32_t __stdcall WaitForSingleObject(void *handle, uint32_t milliseconds)");
19892
+ const close = kernel.func("int __stdcall CloseHandle(void *handle)");
19893
+ cachedApi = {
19894
+ open: (pid) => open2(queryAndSynchronize, 0, pid),
19895
+ query(handle) {
19896
+ const values = Buffer.alloc(32);
19897
+ if (!times(handle, values.subarray(0, 8), values.subarray(8, 16), values.subarray(16, 24), values.subarray(24))) return null;
19898
+ return { created: values.readBigUInt64LE(), running: wait(handle, 0) === waitTimeout };
19899
+ },
19900
+ close
19901
+ };
19902
+ return cachedApi;
19903
+ }
19904
+ function windowsProcessStart(pid, load = windowsProcessApi) {
19905
+ if (!Number.isInteger(pid) || pid <= 0 || pid > 4294967295) return null;
19906
+ try {
19907
+ const api = load();
19908
+ const handle = api.open(pid);
19909
+ if (!handle) return null;
19910
+ try {
19911
+ const info = api.query(handle);
19912
+ if (!info?.running || info.created <= unixEpochFileTime) return null;
19913
+ const created = Number((info.created - unixEpochFileTime) / 10000n);
19914
+ return Number.isSafeInteger(created) ? created : null;
19915
+ } finally {
19916
+ api.close(handle);
19917
+ }
19918
+ } catch {
19919
+ return null;
19920
+ }
19931
19921
  }
19932
19922
 
19933
19923
  // src/capture-server/store.ts
@@ -19983,9 +19973,6 @@ function inspectOwner(pid, expectedStartedAt, probe) {
19983
19973
  const alive = probe.alive ?? pidAlive;
19984
19974
  const inspect = probe.inspect ?? inspectProcess;
19985
19975
  const platform2 = probe.platform ?? process.platform;
19986
- const now = probe.now ?? Date.now;
19987
- const started = now();
19988
- const windows = platform2 === "win32";
19989
19976
  if (platform2 === "linux") {
19990
19977
  try {
19991
19978
  const read = probe.read ?? ((path) => readFileSync2(path, "utf8"));
@@ -19999,23 +19986,18 @@ function inspectOwner(pid, expectedStartedAt, probe) {
19999
19986
  return false;
20000
19987
  }
20001
19988
  }
20002
- if (windows && !probe.inspect) {
20003
- const observed = windowsProcessStart(pid, () => alive(pid));
19989
+ if (platform2 === "win32") {
19990
+ const observed = (probe.readWindows ?? windowsProcessStart)(pid);
20004
19991
  return observed !== null && Math.abs(observed - expectedStartedAt) <= 5e3;
20005
19992
  }
20006
- for (let attempt = 0; attempt < (windows ? 2 : 1); attempt++) {
20007
- if (!alive(pid)) return false;
20008
- const remaining = windows ? 8e3 - (now() - started) : 2e3;
20009
- if (remaining <= 0) return false;
20010
- try {
20011
- const raw = windows ? inspect("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", `(Get-Process -Id ${pid} -ErrorAction Stop).StartTime.ToUniversalTime().ToString('o')`], Math.min(4e3, remaining)) : inspect("ps", ["-o", "lstart=", "-p", String(pid)], 2e3);
20012
- const observed = Date.parse(windows ? raw.trim() : `${raw.trim()} UTC`);
20013
- return Number.isFinite(observed) && Math.abs(observed - expectedStartedAt) <= 5e3;
20014
- } catch (error62) {
20015
- if (!windows || error62.code !== "ETIMEDOUT") return false;
20016
- }
19993
+ if (!alive(pid)) return false;
19994
+ try {
19995
+ const raw = inspect("ps", ["-o", "lstart=", "-p", String(pid)], 2e3);
19996
+ const observed = Date.parse(`${raw.trim()} UTC`);
19997
+ return Number.isFinite(observed) && Math.abs(observed - expectedStartedAt) <= 5e3;
19998
+ } catch {
19999
+ return false;
20017
20000
  }
20018
- return false;
20019
20001
  }
20020
20002
  var CaptureStore = class {
20021
20003
  constructor(root, clock = Date.now, alive = ownerProcessAlive) {
@@ -29231,6 +29231,13 @@ var init_essential_output = __esm({
29231
29231
  }
29232
29232
  });
29233
29233
 
29234
+ // ../../packages/core/dist/definitions/html-response-authoring.js
29235
+ var init_html_response_authoring = __esm({
29236
+ "../../packages/core/dist/definitions/html-response-authoring.js"() {
29237
+ "use strict";
29238
+ }
29239
+ });
29240
+
29234
29241
  // ../../packages/core/dist/definitions/categories.js
29235
29242
  var labels, descriptions, categories;
29236
29243
  var init_categories = __esm({
@@ -29269,6 +29276,7 @@ var init_definitions = __esm({
29269
29276
  init_rules();
29270
29277
  init_analysis();
29271
29278
  init_metadata();
29279
+ init_html_response_authoring();
29272
29280
  init_categories();
29273
29281
  init_credential_contract();
29274
29282
  }
@@ -172905,6 +172913,15 @@ var init_file_artifacts = __esm({
172905
172913
  }
172906
172914
  });
172907
172915
 
172916
+ // src/execution/response-framing.ts
172917
+ var maxInspectionBytes;
172918
+ var init_response_framing = __esm({
172919
+ "src/execution/response-framing.ts"() {
172920
+ "use strict";
172921
+ maxInspectionBytes = 4 * 1024 * 1024;
172922
+ }
172923
+ });
172924
+
172908
172925
  // src/execution/web-response.ts
172909
172926
  var init_web_response = __esm({
172910
172927
  "src/execution/web-response.ts"() {
@@ -172912,6 +172929,7 @@ var init_web_response = __esm({
172912
172929
  init_file_artifacts();
172913
172930
  init_slim();
172914
172931
  init_definitions();
172932
+ init_response_framing();
172915
172933
  init_html_secrets();
172916
172934
  }
172917
172935
  });