bazilion 0.24.0 → 0.25.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.
Files changed (113) hide show
  1. package/README.md +20 -8
  2. package/dist/browser-keychain.js +83 -0
  3. package/dist/browser-keychain.js.map +1 -0
  4. package/dist/cli-main.js +55 -24
  5. package/dist/cli-main.js.map +1 -1
  6. package/dist/daemon-main.js +15060 -7470
  7. package/dist/daemon-main.js.map +1 -1
  8. package/dist/migrations/0001_init.sql +6 -4
  9. package/dist/native-darwin-entry.js +692 -0
  10. package/dist/native-darwin-entry.js.map +1 -0
  11. package/dist/native-linux-entry.js +60 -0
  12. package/dist/native-linux-entry.js.map +1 -0
  13. package/dist/runtime-version.js +2 -2
  14. package/dist/runtime-version.js.map +1 -1
  15. package/dist/web/client/assets/{AgentTabs-0mMqUuts.js → AgentTabs-kEd-oDRM.js} +1 -1
  16. package/dist/web/client/assets/ChatPane-DhvlzNPJ.js +76 -0
  17. package/dist/web/client/assets/{ConfigPage-CbALCsl0.js → ConfigPage-CMKsWDjh.js} +1 -1
  18. package/dist/web/client/assets/{ConfirmDialog-CB1a-szq.js → ConfirmDialog-DpAzoNG8.js} +1 -1
  19. package/dist/web/client/assets/{FieldRow-BHGq10hz.js → FieldRow-OQ-Ezw5t.js} +1 -1
  20. package/dist/web/client/assets/{ProductionTeamPolicyEditor-B4Ysob7y.js → ProductionTeamPolicyEditor-DhT-Q13a.js} +1 -1
  21. package/dist/web/client/assets/{ProfileCommunicationEditor-Bi1SwX0T.js → ProfileCommunicationEditor-CnQIp4e6.js} +1 -1
  22. package/dist/web/client/assets/{RecoveryState-CDWhoT3x.js → RecoveryState-B4Rne9N_.js} +1 -1
  23. package/dist/web/client/assets/{ResultCard-Crmt8j95.js → ResultCard-BxAlMky1.js} +1 -1
  24. package/dist/web/client/assets/{ResultSourceConversation-CqwZKlKb.js → ResultSourceConversation-BzIw43-r.js} +1 -1
  25. package/dist/web/client/assets/{SectionTabs-mghnc98b.js → SectionTabs-D3M6F_HR.js} +1 -1
  26. package/dist/web/client/assets/{TeamTabs-BuZ3DvCw.js → TeamTabs-BZbg-UFx.js} +1 -1
  27. package/dist/web/client/assets/{TemplatesTabs-D71oTTXM.js → TemplatesTabs-D8geEOte.js} +1 -1
  28. package/dist/web/client/assets/{UnsavedChangesGuard-CiCtGDIH.js → UnsavedChangesGuard-CPQe9VLw.js} +1 -1
  29. package/dist/web/client/assets/{_id-BVY0iUYM.js → _id-1RIodFdi.js} +1 -1
  30. package/dist/web/client/assets/_id-BV3w2kDj.js +1 -0
  31. package/dist/web/client/assets/{_id-DRiwwqZL.js → _id-C9zxKqvQ.js} +1 -1
  32. package/dist/web/client/assets/{_id-B-8ssJLW.js → _id-CLG_POnZ.js} +1 -1
  33. package/dist/web/client/assets/{_id-DaqX-WEB.js → _id-Cha845UH.js} +1 -1
  34. package/dist/web/client/assets/{_id-CeALz6bj.js → _id-DssxcwBl.js} +1 -1
  35. package/dist/web/client/assets/{_id-C7A_A3eM.js → _id-IDHR-MEm.js} +1 -1
  36. package/dist/web/client/assets/{_id-CQlUNjzV.js → _id-SGs5zOcT.js} +1 -1
  37. package/dist/web/client/assets/{activity-C5aaqPEN.js → activity-0srO4qbd.js} +1 -1
  38. package/dist/web/client/assets/{activity-D4Nt8GQM.js → activity-DxQGr6eP.js} +1 -1
  39. package/dist/web/client/assets/{agents-BPLszpKx.js → agents-CVTYoXKu.js} +1 -1
  40. package/dist/web/client/assets/{agents-DFOLPsgX.js → agents-DPTu6Sm_.js} +1 -1
  41. package/dist/web/client/assets/{agents-BUqq1VBQ.js → agents-nHiIbumu.js} +1 -1
  42. package/dist/web/client/assets/{approvals-MVCITL8Q.js → approvals-Di_Bux_Q.js} +1 -1
  43. package/dist/web/client/assets/{approvals-8PPXdZxV.js → approvals-ScNrQg7q.js} +1 -1
  44. package/dist/web/client/assets/{attention-DiyHVOcZ.js → attention-BF-Llt9z.js} +1 -1
  45. package/dist/web/client/assets/{attention-e273gZ8d.js → attention-D7xB17sN.js} +1 -1
  46. package/dist/web/client/assets/chevron-right-CJ2wat15.js +1 -0
  47. package/dist/web/client/assets/config-BOuIcP1T.js +3 -0
  48. package/dist/web/client/assets/{context-DhgSlMk5.js → context-wo9lNjHx.js} +1 -1
  49. package/dist/web/client/assets/{inbox-B3To3KpL.js → inbox-CNLmz0Jp.js} +1 -1
  50. package/dist/web/client/assets/{inbox-C1_vHPb8.js → inbox-De6HOll3.js} +1 -1
  51. package/dist/web/client/assets/{index-DtEE9JX2.js → index-CjI7_vB3.js} +2 -2
  52. package/dist/web/client/assets/{learning-B7wX_mkT.js → learning-591SFAKg.js} +1 -1
  53. package/dist/web/client/assets/{learning-DDwUAKmq.js → learning-D6bO0NeB.js} +1 -1
  54. package/dist/web/client/assets/{login-CWaSGdgc.js → login-Q7uP-v0M.js} +1 -1
  55. package/dist/web/client/assets/mcp-BGy64VOv.js +1 -0
  56. package/dist/web/client/assets/{mcp-CO5iBKHD.js → mcp-DSCjhc5I.js} +1 -1
  57. package/dist/web/client/assets/{members-Dx9OcdY1.js → members-CBVor-P4.js} +1 -1
  58. package/dist/web/client/assets/{members-Bd3z1Mbb.js → members-CCcecjC3.js} +1 -1
  59. package/dist/web/client/assets/{memory-BIZi6bBM.js → memory-CSE8EQ48.js} +1 -1
  60. package/dist/web/client/assets/{memory-DrYbH0we.js → memory-DgGz0wh4.js} +1 -1
  61. package/dist/web/client/assets/{policy-CcnTn0qG.js → policy-6j-NQvBj.js} +1 -1
  62. package/dist/web/client/assets/{policy-Dsj-SWqE.js → policy-Do0TvNWc.js} +1 -1
  63. package/dist/web/client/assets/{results-GeOLM5Cw.js → results-CCQGn0dE.js} +1 -1
  64. package/dist/web/client/assets/{results-t7jAchgU.js → results-Cx6_ChIY.js} +1 -1
  65. package/dist/web/client/assets/{review-CQaZNlyx.js → review-CyS5b0fz.js} +1 -1
  66. package/dist/web/client/assets/{review-CYvx-3K2.js → review-qG-2gqEp.js} +1 -1
  67. package/dist/web/client/assets/{routes-DoK4DMdi.js → routes-DRic0xNy.js} +1 -1
  68. package/dist/web/client/assets/{services-c9HkxKEP.js → services-B_7lf-mx.js} +1 -1
  69. package/dist/web/client/assets/{services-BI7iyTHh.js → services-ByBA_yA-.js} +1 -1
  70. package/dist/web/client/assets/{skills-Ddf5PBNn.js → skills--lnDzPWe.js} +1 -1
  71. package/dist/web/client/assets/{skills-B0O0zwg1.js → skills-C70btgIg.js} +1 -1
  72. package/dist/web/client/assets/{teams-BNQ4z_k3.js → teams-BL-Fr2xF.js} +1 -1
  73. package/dist/web/client/assets/{teams-kRB5hV3h.js → teams-BeoxArzy.js} +1 -1
  74. package/dist/web/client/assets/{teams-Wvr8-LhE.js → teams-C4mb790r.js} +1 -1
  75. package/dist/web/client/assets/{teams-BDbkurIa.js → teams-DHStw3OS.js} +1 -1
  76. package/dist/web/client/assets/{telegram-Dx9tzt9d.js → telegram-BIMiebJl.js} +1 -1
  77. package/dist/web/client/assets/{templates-CGQ93r-m.js → templates-CzHXXiA_.js} +1 -1
  78. package/dist/web/client/assets/{tokens-CsOJULk9.js → tokens-B9ehOc1o.js} +1 -1
  79. package/dist/web/client/assets/{tokens-zqJy3CQD.js → tokens-DhaMzFWK.js} +1 -1
  80. package/dist/web/client/assets/{triggers-9UUKTR6l.js → triggers--xMpHFW7.js} +1 -1
  81. package/dist/web/client/assets/{triggers-BiXb1VFy.js → triggers-DLzZu8bB.js} +1 -1
  82. package/dist/web/client/assets/verifications-FzypGVwW.js +2 -0
  83. package/dist/web/client/assets/{verifications-BKoHhRqF.js → verifications-fR9W-adv.js} +1 -1
  84. package/dist/web/client/assets/{welcome-BdcpBETx.js → welcome-pjZD7pq4.js} +1 -1
  85. package/dist/web/client/assets/{x-DtPVZP1O.js → x-CZxV4X-6.js} +1 -1
  86. package/dist/web/server/assets/{ChatPane-3CIVTz7o.js → ChatPane-CeDUEjmn.js} +10 -2
  87. package/dist/web/server/assets/{ResultSourceConversation-DwuGuTa-.js → ResultSourceConversation-xn4EKjaP.js} +1 -1
  88. package/dist/web/server/assets/{_id-C1-ygfez.js → _id-CGMvV1p5.js} +3 -3
  89. package/dist/web/server/assets/{_id-BXOT74Jd.js → _id-DhheAcWL.js} +149 -14
  90. package/dist/web/server/assets/{_id-CWlZT9kI.js → _id-t8AepTB2.js} +1 -1
  91. package/dist/web/server/assets/{_id-BS4MnPa3.js → _id-ujm4R5OF.js} +1 -1
  92. package/dist/web/server/assets/{_tanstack-start-manifest_v-LR-ldomm.js → _tanstack-start-manifest_v-CXwNJhX2.js} +132 -132
  93. package/dist/web/server/assets/{config-CMxeC2Bd.js → config-0_5yhRKg.js} +39 -24
  94. package/dist/web/server/assets/{config-CbioK6nX.js → config-VsmvCulS.js} +1 -1
  95. package/dist/web/server/assets/{mcp-CLWr5_0I.js → mcp-BEdnl_TT.js} +1 -1
  96. package/dist/web/server/assets/{mcp-DmzP8n2G.js → mcp-Dhryb75M.js} +2 -2
  97. package/dist/web/server/assets/{results-C6edENBF.js → results-CkNoVDrY.js} +2 -2
  98. package/dist/web/server/assets/{results-DjTerNLY.js → results-DSGwi3vj.js} +1 -1
  99. package/dist/web/server/assets/{router-Doy5hj6V.js → router-BFqyjkYu.js} +7 -7
  100. package/dist/web/server/assets/{routes-Bz-Gprcp.js → routes-BfEa101d.js} +1 -1
  101. package/dist/web/server/assets/{routes-ByEYvEFv.js → routes-pUMIGzyy.js} +2 -2
  102. package/dist/web/server/assets/{verifications-EIw3Xh61.js → verifications-DvOyI3Mr.js} +1 -1
  103. package/dist/web/server/assets/{verifications-BVR0OK7x.js → verifications-YrEdiZmk.js} +8 -5
  104. package/dist/web/server/server.js +2 -2
  105. package/dist/worker.js +666 -165
  106. package/dist/worker.js.map +1 -1
  107. package/package.json +5 -4
  108. package/dist/web/client/assets/ChatPane-C4ZAMSqQ.js +0 -76
  109. package/dist/web/client/assets/_id-DQqcn57I.js +0 -1
  110. package/dist/web/client/assets/chevron-right-DgJy0QeF.js +0 -1
  111. package/dist/web/client/assets/config-Dm6OgnLh.js +0 -3
  112. package/dist/web/client/assets/mcp-DO8sSn5c.js +0 -1
  113. package/dist/web/client/assets/verifications-CElk4UQp.js +0 -2
@@ -0,0 +1,692 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../daemon/src/runtime/shell/native/darwin-entry.ts
4
+ import { realpathSync } from "fs";
5
+ import { constants as constants3 } from "os";
6
+ import { posix } from "path";
7
+
8
+ // ../daemon/src/lib/process/darwin.ts
9
+ import { createRequire } from "module";
10
+ import { constants } from "os";
11
+ var BSD_BYTES = 136;
12
+ var RUSAGE_BYTES = 96;
13
+ var MAX_MEMBERS = 16384;
14
+ var INSPECTION_MS = 500;
15
+ var ESRCH = constants.errno.ESRCH;
16
+ function validPid(pid) {
17
+ return Number.isSafeInteger(pid) && pid > 0 && pid <= 2147483647;
18
+ }
19
+ function unavailable() {
20
+ throw new Error("macOS process ownership cannot be inspected");
21
+ }
22
+ var DarwinProcessInspector = class {
23
+ calls;
24
+ constructor(calls2) {
25
+ this.calls = calls2;
26
+ }
27
+ bsd(pid) {
28
+ if (!validPid(pid)) return unavailable();
29
+ const buffer = Buffer.alloc(BSD_BYTES);
30
+ const result = this.calls.bsd(pid, buffer);
31
+ if (result.bytes === 0 && result.errno === ESRCH) return null;
32
+ if (result.bytes !== BSD_BYTES) return unavailable();
33
+ const state = buffer.readUInt32LE(4);
34
+ const returnedPid = buffer.readUInt32LE(12);
35
+ const parent = buffer.readUInt32LE(16);
36
+ const uid = buffer.readUInt32LE(20);
37
+ const group = buffer.readUInt32LE(100);
38
+ const seconds = buffer.readBigUInt64LE(120);
39
+ const micros = buffer.readBigUInt64LE(128);
40
+ if (returnedPid !== pid || !validPid(group) || parent > 2147483647 || state < 1 || state > 5 || seconds === 0n || micros >= 1000000n)
41
+ return unavailable();
42
+ return {
43
+ pid,
44
+ parent,
45
+ group,
46
+ uid,
47
+ start: `${seconds}:${micros}`,
48
+ state: state === 5 ? "Z" : String(state)
49
+ };
50
+ }
51
+ birth(pid) {
52
+ const buffer = Buffer.alloc(RUSAGE_BYTES);
53
+ const result = this.calls.birth(pid, buffer);
54
+ if (result.status === -1 && result.errno === ESRCH) return null;
55
+ if (result.status !== 0) return unavailable();
56
+ const birth = buffer.readBigUInt64LE(80);
57
+ if (birth === 0n) return unavailable();
58
+ return birth;
59
+ }
60
+ member(pid) {
61
+ const before = this.bsd(pid);
62
+ if (!before) return null;
63
+ if (before.state === "Z") return { ...before, session: 0 };
64
+ const birth = this.birth(pid);
65
+ if (birth === null) return null;
66
+ const session = this.calls.session(pid);
67
+ if (session.id === -1 && session.errno === ESRCH) return null;
68
+ if (!validPid(session.id)) return unavailable();
69
+ const after = this.bsd(pid);
70
+ if (!after) return null;
71
+ const afterBirth = this.birth(pid);
72
+ if (afterBirth === null) return null;
73
+ if (after.start !== before.start || after.group !== before.group || after.uid !== before.uid || birth !== afterBirth)
74
+ throw new Error("macOS process ownership changed during inspection");
75
+ return { ...after, start: `${after.start}:${birth}`, session: session.id };
76
+ }
77
+ pids(group) {
78
+ if (!validPid(group)) return unavailable();
79
+ const buffer = Buffer.alloc((MAX_MEMBERS + 1) * 4);
80
+ const { count, errno } = this.calls.pids(group, buffer);
81
+ if (count === -1 && errno === ESRCH) return [];
82
+ if (!Number.isSafeInteger(count) || count < 0 || count > MAX_MEMBERS) return unavailable();
83
+ if (count === 0 && errno !== 0 && errno !== ESRCH) return unavailable();
84
+ const seen = /* @__PURE__ */ new Set();
85
+ for (let i = 0; i < count; i++) {
86
+ const pid = buffer.readInt32LE(i * 4);
87
+ if (!validPid(pid) || seen.has(pid)) return unavailable();
88
+ seen.add(pid);
89
+ }
90
+ return [...seen];
91
+ }
92
+ group(pid) {
93
+ if (!validPid(pid) || pid <= 1) return unavailable();
94
+ const started = performance.now();
95
+ const members = [];
96
+ const stopped = /* @__PURE__ */ new Set();
97
+ for (const memberPid of this.pids(pid)) {
98
+ if (performance.now() - started > INSPECTION_MS)
99
+ throw new Error("macOS process inspection over budget");
100
+ const member = this.member(memberPid);
101
+ if (!member) continue;
102
+ if (member.state === "Z") {
103
+ if (member.group === pid) stopped.add(memberPid);
104
+ } else {
105
+ if (member.group !== pid || member.session !== pid)
106
+ throw new Error("macOS process group changed during inspection");
107
+ members.push(member);
108
+ }
109
+ }
110
+ if (!members.length && this.pids(pid).some((memberPid) => !stopped.has(memberPid)))
111
+ throw new Error("macOS process group changed during inspection");
112
+ if (performance.now() - started > INSPECTION_MS)
113
+ throw new Error("macOS process inspection over budget");
114
+ return members;
115
+ }
116
+ assertReady() {
117
+ const self = this.member(process.pid);
118
+ if (!self || self.parent !== process.ppid || self.state === "Z") unavailable();
119
+ if (!this.pids(self.group).includes(process.pid)) unavailable();
120
+ }
121
+ };
122
+ var inspector;
123
+ function getDarwinProcessInspector() {
124
+ if (process.platform !== "darwin" || !["arm64", "x64"].includes(process.arch))
125
+ return unavailable();
126
+ if (!inspector) {
127
+ try {
128
+ const require2 = createRequire(import.meta.url);
129
+ const ffi = require2("koffi");
130
+ if (ffi.version !== "3.3.3") return unavailable();
131
+ const proc = ffi.load("/usr/lib/libproc.dylib");
132
+ const system = ffi.load("/usr/lib/libSystem.B.dylib");
133
+ const bsd = proc.func(
134
+ "int proc_pidinfo(int pid, int flavor, uint64_t arg, _Out_ void *buffer, int size)"
135
+ );
136
+ const pids = proc.func("int proc_listpgrppids(int group, _Out_ void *buffer, int size)");
137
+ const session = system.func("int getsid(int pid)");
138
+ const birth = proc.func("int proc_pid_rusage(int pid, int flavor, _Out_ void *buffer)");
139
+ inspector = new DarwinProcessInspector({
140
+ bsd: (pid, buffer) => {
141
+ ffi.errno(0);
142
+ const bytes = bsd(pid, 3, 0n, buffer, buffer.length);
143
+ return { bytes, errno: ffi.errno() };
144
+ },
145
+ birth: (pid, buffer) => {
146
+ ffi.errno(0);
147
+ const status = birth(pid, 0, buffer);
148
+ return { status, errno: ffi.errno() };
149
+ },
150
+ pids: (group, buffer) => {
151
+ ffi.errno(0);
152
+ const count = pids(group, buffer, buffer.length);
153
+ return { count, errno: ffi.errno() };
154
+ },
155
+ session: (pid) => {
156
+ ffi.errno(0);
157
+ const id2 = session(pid);
158
+ return { id: id2, errno: ffi.errno() };
159
+ }
160
+ });
161
+ } catch {
162
+ return unavailable();
163
+ }
164
+ }
165
+ return inspector;
166
+ }
167
+
168
+ // ../daemon/src/lib/process/darwin-census.ts
169
+ import { createRequire as createRequire2 } from "module";
170
+ import { constants as constants2 } from "os";
171
+ var DARWIN_CENSUS_MAX_PIDS = 16384;
172
+ var DARWIN_CENSUS_BUDGET_MS = 500;
173
+ var IDENTITY_BYTES = 56;
174
+ var SHORT_BYTES = 64;
175
+ var EPERM = constants2.errno.EPERM;
176
+ var unknown = (reason) => Object.freeze({ kind: "unknown", reason });
177
+ function identityFailure(result, short = false) {
178
+ if (result.bytes !== 0) return unknown("identity");
179
+ if (result.errno === constants2.errno.ESRCH)
180
+ return unknown(short ? "short_esrch" : "identity_esrch");
181
+ if (result.errno === constants2.errno.EACCES)
182
+ return unknown(short ? "short_eacces" : "identity_eacces");
183
+ if (result.errno === EPERM) return unknown(short ? "short_eperm" : "identity_eperm");
184
+ return unknown("identity");
185
+ }
186
+ var validPid2 = (pid) => Number.isSafeInteger(pid) && pid > 0 && pid <= 2147483647;
187
+ function validIdentity(value) {
188
+ return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype && Object.keys(value).every((key) => ["pid", "uniqueId", "execVersion", "state"].includes(key)) && validPid2(value.pid) && typeof value.uniqueId === "string" && /^[1-9][0-9]{0,19}$/.test(value.uniqueId) && BigInt(value.uniqueId) <= 0xffffffffffffffffn && Number.isInteger(value.execVersion) && value.execVersion >= -2147483648 && value.execVersion <= 2147483647 && value.execVersion !== 0;
189
+ }
190
+ function sameDarwinCensusIdentity(left, right) {
191
+ return left.pid === right.pid && left.uniqueId === right.uniqueId && left.execVersion === right.execVersion;
192
+ }
193
+ function copyIdentity(value) {
194
+ return Object.freeze({ pid: value.pid, uniqueId: value.uniqueId, execVersion: value.execVersion });
195
+ }
196
+ function validRows(rows) {
197
+ if (!Array.isArray(rows) || rows.length === 0 || rows.length > DARWIN_CENSUS_MAX_PIDS)
198
+ return false;
199
+ let previous = 0;
200
+ for (const row of rows) {
201
+ if (!row || !validIdentity(row) || row.pid <= previous || row.state !== "live" && row.state !== "zombie")
202
+ return false;
203
+ previous = row.pid;
204
+ }
205
+ return true;
206
+ }
207
+ var DarwinCensusReader = class {
208
+ calls;
209
+ pid;
210
+ now;
211
+ constructor(calls2, pid = process.pid, now = () => performance.now()) {
212
+ this.calls = calls2;
213
+ this.pid = pid;
214
+ this.now = now;
215
+ }
216
+ overBudget(started) {
217
+ const elapsed = this.now() - started;
218
+ return !Number.isFinite(elapsed) || elapsed < 0 || elapsed > DARWIN_CENSUS_BUDGET_MS;
219
+ }
220
+ pids() {
221
+ const buffer = Buffer.alloc((DARWIN_CENSUS_MAX_PIDS + 1) * 4);
222
+ const result = this.calls.pids(buffer);
223
+ if (!Number.isInteger(result.count) || result.count <= 0 || result.count > DARWIN_CENSUS_MAX_PIDS || result.errno !== 0)
224
+ return unknown("pid_list");
225
+ const seen = /* @__PURE__ */ new Set();
226
+ let kernelSeen = false;
227
+ for (let index = 0; index < result.count; index++) {
228
+ const pid = buffer.readInt32LE(index * 4);
229
+ if (pid === 0 && !kernelSeen) {
230
+ kernelSeen = true;
231
+ continue;
232
+ }
233
+ if (!validPid2(pid) || seen.has(pid)) return unknown("pid_list");
234
+ seen.add(pid);
235
+ }
236
+ if (!seen.has(this.pid)) return unknown("owner");
237
+ return [...seen].sort((a, b) => a - b);
238
+ }
239
+ identity(pid) {
240
+ const buffer = Buffer.alloc(IDENTITY_BYTES);
241
+ const result = this.calls.identity(pid, buffer);
242
+ if (result.bytes !== IDENTITY_BYTES || result.errno !== 0) return identityFailure(result);
243
+ if (buffer.readBigUInt64LE(40) !== 0n || buffer.readBigUInt64LE(48) !== 0n)
244
+ return unknown("layout");
245
+ const identity = {
246
+ pid,
247
+ uniqueId: buffer.readBigUInt64LE(16).toString(),
248
+ execVersion: buffer.readInt32LE(32)
249
+ };
250
+ return validIdentity(identity) ? Object.freeze(identity) : unknown("layout");
251
+ }
252
+ row(pid) {
253
+ const before = this.identity(pid);
254
+ if ("kind" in before) return before;
255
+ const buffer = Buffer.alloc(SHORT_BYTES);
256
+ const result = this.calls.short(pid, buffer);
257
+ if (result.bytes !== SHORT_BYTES || result.errno !== 0) return identityFailure(result, true);
258
+ const state = buffer.readUInt32LE(12);
259
+ if (buffer.readUInt32LE(0) !== pid || state < 2 || state > 5) return unknown("layout");
260
+ const after = this.identity(pid);
261
+ if ("kind" in after) return after;
262
+ if (!sameDarwinCensusIdentity(before, after)) return unknown("drift");
263
+ return Object.freeze({ ...before, state: state === 5 ? "zombie" : "live" });
264
+ }
265
+ /** Self facts for a trusted scoped observer; not signalling or settlement authority. */
266
+ ownIdentity() {
267
+ try {
268
+ const row = this.row(this.pid);
269
+ if ("kind" in row) return row;
270
+ return row.state === "live" ? copyIdentity(row) : unknown("owner");
271
+ } catch {
272
+ return unknown("unavailable");
273
+ }
274
+ }
275
+ /** Trusted outside controller: bounded complete versioned inventory, including foreign zombies. */
276
+ inventory() {
277
+ const started = this.now();
278
+ try {
279
+ const first = this.pids();
280
+ if (!Array.isArray(first)) return first;
281
+ const rows = [];
282
+ for (const pid of first) {
283
+ if (this.overBudget(started)) return unknown("budget");
284
+ const row = this.row(pid);
285
+ if ("kind" in row) {
286
+ if (pid !== this.pid && ["identity_esrch", "short_esrch"].includes(row.reason)) {
287
+ if (this.overBudget(started)) return unknown("budget");
288
+ const after = this.pids();
289
+ if (this.overBudget(started)) return unknown("budget");
290
+ if (Array.isArray(after) && (first.length !== after.length || first.some((value, index) => value !== after[index])))
291
+ return unknown("drift");
292
+ }
293
+ return row;
294
+ }
295
+ rows.push(row);
296
+ }
297
+ const last = this.pids();
298
+ if (!Array.isArray(last)) return last;
299
+ if (first.length !== last.length || first.some((pid, index) => pid !== last[index]))
300
+ return unknown("drift");
301
+ if (this.overBudget(started)) return unknown("budget");
302
+ return Object.freeze({ kind: "inventory", rows: Object.freeze(rows) });
303
+ } catch {
304
+ return unknown("unavailable");
305
+ }
306
+ }
307
+ /**
308
+ * Only inside the admitted immutable same-sandbox policy. Flavor 17 and short BSD info
309
+ * do not apply the same-UID restriction, so a changed UID cannot be mistaken for foreign.
310
+ * Only EPERM is a policy exclusion; disappearance, partial data and all other errors are unknown.
311
+ */
312
+ scope(inventory, owner) {
313
+ const started = this.now();
314
+ try {
315
+ if (inventory.kind !== "inventory" || !validRows(inventory.rows) || !validIdentity(owner))
316
+ return unknown("scope_input");
317
+ if (owner.pid !== this.pid) return unknown("owner");
318
+ let ownerSeen = false;
319
+ let outsideCount = 0;
320
+ let zombieCount = 0;
321
+ const members = [];
322
+ for (const expected of inventory.rows) {
323
+ if (this.overBudget(started)) return unknown("budget");
324
+ const probe = Buffer.alloc(IDENTITY_BYTES);
325
+ const result = this.calls.identity(expected.pid, probe);
326
+ if (result.bytes === 0 && result.errno === EPERM && expected.pid !== owner.pid) {
327
+ outsideCount++;
328
+ continue;
329
+ }
330
+ if (result.bytes !== IDENTITY_BYTES || result.errno !== 0)
331
+ return expected.pid === owner.pid ? unknown("owner") : identityFailure(result);
332
+ const actual = this.row(expected.pid);
333
+ if ("kind" in actual) return expected.pid === owner.pid ? unknown("owner") : actual;
334
+ if (!sameDarwinCensusIdentity(expected, actual)) return unknown("drift");
335
+ if (expected.state === "zombie" && actual.state !== "zombie") return unknown("drift");
336
+ if (actual.pid === owner.pid) {
337
+ if (actual.state !== "live" || !sameDarwinCensusIdentity(actual, owner))
338
+ return unknown("owner");
339
+ ownerSeen = true;
340
+ } else if (actual.state === "zombie") zombieCount++;
341
+ else
342
+ members.push(
343
+ Object.freeze({
344
+ pid: actual.pid,
345
+ uniqueId: actual.uniqueId,
346
+ execVersion: actual.execVersion
347
+ })
348
+ );
349
+ }
350
+ if (!ownerSeen) return unknown("owner");
351
+ if (this.overBudget(started)) return unknown("budget");
352
+ return Object.freeze({
353
+ kind: "view",
354
+ owner: copyIdentity(owner),
355
+ members: Object.freeze(members),
356
+ outsideCount,
357
+ zombieCount
358
+ });
359
+ } catch {
360
+ return unknown("unavailable");
361
+ }
362
+ }
363
+ };
364
+ var calls;
365
+ function getDarwinCensusCalls() {
366
+ if (process.platform !== "darwin" || !["arm64", "x64"].includes(process.arch))
367
+ throw new Error("Native macOS process inventory is unavailable");
368
+ if (!calls) {
369
+ try {
370
+ const require2 = createRequire2(import.meta.url);
371
+ const ffi = require2("koffi");
372
+ if (ffi.version !== "3.3.3") throw new Error("unsupported binding");
373
+ const proc = ffi.load("/usr/lib/libproc.dylib");
374
+ const info = proc.func(
375
+ "int proc_pidinfo(int pid, int flavor, uint64_t arg, _Out_ void *buffer, int size)"
376
+ );
377
+ const pids = proc.func("int proc_listallpids(_Out_ void *buffer, int size)");
378
+ const read = (pid, flavor, buffer) => {
379
+ if (!validPid2(pid)) throw new Error("invalid process identity");
380
+ ffi.errno(0);
381
+ const bytes = info(pid, flavor, 1n, buffer, buffer.length);
382
+ return { bytes, errno: ffi.errno() };
383
+ };
384
+ calls = Object.freeze({
385
+ pids: (buffer) => {
386
+ ffi.errno(0);
387
+ const count = pids(buffer, buffer.length);
388
+ return { count, errno: ffi.errno() };
389
+ },
390
+ identity: (pid, buffer) => read(pid, 17, buffer),
391
+ short: (pid, buffer) => read(pid, 13, buffer)
392
+ });
393
+ } catch {
394
+ throw new Error("Native macOS process inventory is unavailable");
395
+ }
396
+ }
397
+ return calls;
398
+ }
399
+
400
+ // ../daemon/src/runtime/shell/native/darwin-job.ts
401
+ import { ChildProcess, spawn } from "child_process";
402
+
403
+ // ../daemon/src/runtime/shell/native/darwin-protocol.ts
404
+ var DARWIN_JOB_PROTOCOL = 1;
405
+ var DARWIN_JOB_MAX_FRAME_BYTES = 2 * 1024 * 1024;
406
+ var DARWIN_JOB_MAX_COMMAND_BYTES = 256 * 1024;
407
+ function unavailable2() {
408
+ throw new Error("Native macOS job protocol unavailable");
409
+ }
410
+ var id = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 && value <= 2147483647;
411
+ var record = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
412
+ function keys(value, names) {
413
+ if (Object.keys(value).length !== names.length || names.some((name) => !Object.hasOwn(value, name)))
414
+ unavailable2();
415
+ }
416
+ function parseDarwinJobRequest(value) {
417
+ if (!record(value) || !id(value.id)) unavailable2();
418
+ switch (value.type) {
419
+ case "execute": {
420
+ keys(value, ["type", "id", "command"]);
421
+ const command = value.command;
422
+ if (typeof command !== "string" || !command.trim() || command.includes("\0") || Buffer.byteLength(command) > DARWIN_JOB_MAX_COMMAND_BYTES || Buffer.from(command, "utf8").toString("utf8") !== command)
423
+ unavailable2();
424
+ return Object.freeze({ type: "execute", id: value.id, command });
425
+ }
426
+ case "signal":
427
+ keys(value, ["type", "id", "signal"]);
428
+ if (value.signal !== "SIGTERM" && value.signal !== "SIGKILL") unavailable2();
429
+ return Object.freeze({ type: "signal", id: value.id, signal: value.signal });
430
+ case "seal":
431
+ keys(value, ["type", "id"]);
432
+ return Object.freeze({ type: "seal", id: value.id });
433
+ case "scope": {
434
+ keys(value, ["type", "id", "inventory"]);
435
+ const inventory = value.inventory;
436
+ if (!record(inventory)) unavailable2();
437
+ keys(inventory, ["kind", "rows"]);
438
+ if (inventory.kind !== "inventory" || !Array.isArray(inventory.rows) || inventory.rows.length === 0 || inventory.rows.length > 16384)
439
+ unavailable2();
440
+ return Object.freeze({
441
+ type: "scope",
442
+ id: value.id,
443
+ inventory
444
+ });
445
+ }
446
+ case "exit":
447
+ keys(value, ["type", "id", "scopeId"]);
448
+ if (!id(value.scopeId)) unavailable2();
449
+ return Object.freeze({ type: "exit", id: value.id, scopeId: value.scopeId });
450
+ default:
451
+ unavailable2();
452
+ }
453
+ }
454
+ function nextDarwinJobPhase(phase, request) {
455
+ switch (request.type) {
456
+ case "execute":
457
+ if (phase === "waiting") return "running";
458
+ break;
459
+ case "signal":
460
+ if (phase === "running" || phase === "completed") return phase;
461
+ break;
462
+ case "seal":
463
+ if (phase === "waiting" || phase === "completed") return "sealed";
464
+ break;
465
+ case "scope":
466
+ if (phase === "sealed") return "sealed";
467
+ break;
468
+ case "exit":
469
+ if (phase === "sealed") return "closing";
470
+ break;
471
+ }
472
+ return unavailable2();
473
+ }
474
+
475
+ // ../daemon/src/runtime/shell/native/darwin-job.ts
476
+ var OUTPUT_BYTES = 2 * 1024 * 1024;
477
+ var CHUNK_BYTES = 64 * 1024;
478
+ var unavailable3 = () => new Error("Native macOS job unavailable");
479
+ var DarwinCommandJob = class {
480
+ phase = "waiting";
481
+ lastId = 0;
482
+ lastEmptyScope;
483
+ child;
484
+ childBirth;
485
+ childEOF = false;
486
+ retained = 0;
487
+ stdoutTruncated = false;
488
+ stderrTruncated = false;
489
+ reader;
490
+ owner;
491
+ inspection;
492
+ cwd;
493
+ env;
494
+ sink;
495
+ constructor(options) {
496
+ if (process.platform !== "darwin") throw unavailable3();
497
+ this.reader = options.reader;
498
+ this.owner = options.owner;
499
+ this.inspection = options.inspection;
500
+ this.cwd = options.cwd;
501
+ this.env = Object.freeze({ ...options.env });
502
+ this.sink = options.sink;
503
+ }
504
+ /** Return true only for the explicit fenced exit handshake, never stdin EOF or cancellation. */
505
+ accept(request) {
506
+ if (request.id !== this.lastId + 1) throw unavailable3();
507
+ const next = nextDarwinJobPhase(this.phase, request);
508
+ if (request.type === "seal" && this.child && !this.childEOF) throw unavailable3();
509
+ if (request.type === "exit" && (this.lastEmptyScope !== request.scopeId || this.phase !== "sealed"))
510
+ throw unavailable3();
511
+ this.lastId = request.id;
512
+ this.phase = next;
513
+ switch (request.type) {
514
+ case "execute":
515
+ this.execute(request);
516
+ return false;
517
+ case "signal":
518
+ this.sink({ type: "signal", id: request.id, accepted: this.signal(request.signal) });
519
+ return false;
520
+ case "seal":
521
+ this.sink({ type: "sealed", id: request.id });
522
+ return false;
523
+ case "scope": {
524
+ const view = this.reader.scope(request.inventory, this.owner);
525
+ this.lastEmptyScope = view.kind === "view" && view.members.length === 0 ? request.id : void 0;
526
+ this.sink({ type: "view", id: request.id, view });
527
+ return false;
528
+ }
529
+ case "exit":
530
+ this.sink({ type: "exiting", id: request.id });
531
+ return true;
532
+ }
533
+ }
534
+ output(stream, bytes) {
535
+ const available = Math.max(0, OUTPUT_BYTES - this.retained);
536
+ const selected = bytes.subarray(0, available);
537
+ if (selected.length !== bytes.length) {
538
+ if (stream === "stdout") this.stdoutTruncated = true;
539
+ else this.stderrTruncated = true;
540
+ }
541
+ this.retained += selected.length;
542
+ for (let offset = 0; offset < selected.length; offset += CHUNK_BYTES) {
543
+ this.sink({
544
+ type: "output",
545
+ stream,
546
+ data: selected.subarray(offset, offset + CHUNK_BYTES).toString("base64")
547
+ });
548
+ }
549
+ }
550
+ execute(request) {
551
+ if (this.child) throw unavailable3();
552
+ const child = spawn("/bin/bash", ["--noprofile", "--norc", "-s"], {
553
+ cwd: this.cwd,
554
+ env: this.env,
555
+ detached: true,
556
+ stdio: ["pipe", "pipe", "pipe"]
557
+ });
558
+ this.child = child;
559
+ child.once("error", () => this.sink({ type: "fatal", error: "native_job_unavailable" }));
560
+ child.stdout.on("data", (bytes) => this.output("stdout", bytes));
561
+ child.stderr.on("data", (bytes) => this.output("stderr", bytes));
562
+ child.once("close", (code, signal) => {
563
+ this.phase = "completed";
564
+ this.childEOF = child.stdout.readableEnded && child.stderr.readableEnded;
565
+ this.sink({
566
+ type: "completed",
567
+ code,
568
+ signal,
569
+ naturalEOF: this.childEOF,
570
+ stdoutTruncated: this.stdoutTruncated,
571
+ stderrTruncated: this.stderrTruncated
572
+ });
573
+ });
574
+ if (!(child instanceof ChildProcess) || !child.pid) throw unavailable3();
575
+ let member;
576
+ try {
577
+ member = this.inspection.member(child.pid);
578
+ } catch {
579
+ child.stdin.end();
580
+ throw unavailable3();
581
+ }
582
+ if (!member || member.parent !== process.pid || member.group !== child.pid || member.session !== child.pid || member.state === "Z") {
583
+ child.stdin.end();
584
+ throw unavailable3();
585
+ }
586
+ this.childBirth = Object.freeze({ ...member });
587
+ this.sink({ type: "started", id: request.id });
588
+ child.stdin.on("error", () => this.sink({ type: "fatal", error: "native_job_unavailable" }));
589
+ child.stdin.end(request.command);
590
+ }
591
+ signal(signal) {
592
+ const child = this.child, original = this.childBirth;
593
+ if (!child || !original || child.exitCode !== null || child.signalCode !== null) return false;
594
+ try {
595
+ const current = this.inspection.member(original.pid);
596
+ if (!current || current.pid !== child.pid || current.parent !== process.pid || current.start !== original.start || current.uid !== original.uid || current.group !== original.group || current.session !== original.session || current.state === "Z")
597
+ return false;
598
+ process.kill(-original.pid, signal);
599
+ return true;
600
+ } catch {
601
+ return false;
602
+ }
603
+ }
604
+ };
605
+
606
+ // ../daemon/src/runtime/shell/native/darwin-entry.ts
607
+ var closing = false;
608
+ function emit(message) {
609
+ if (closing) return;
610
+ const frame = Buffer.from(`${JSON.stringify(message)}
611
+ `);
612
+ if (frame.length > DARWIN_JOB_MAX_FRAME_BYTES || process.stdout.writableLength > 8 * DARWIN_JOB_MAX_FRAME_BYTES)
613
+ process.exit(1);
614
+ if (message.type === "fatal") {
615
+ closing = true;
616
+ process.stdout.write(frame, () => process.exit(1));
617
+ } else process.stdout.write(frame);
618
+ }
619
+ function fatal() {
620
+ emit({ type: "fatal", error: "native_job_unavailable" });
621
+ }
622
+ process.stdout.on("error", () => process.exit(1));
623
+ process.stdin.on("error", fatal);
624
+ try {
625
+ const nonce = process.argv[2], cwd = process.argv[3];
626
+ if (process.platform !== "darwin" || process.argv.length !== 4 || !nonce || !/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(nonce) || !cwd || !posix.isAbsolute(cwd) || cwd === "/" || posix.normalize(cwd) !== cwd || Buffer.byteLength(cwd) > 4096 || realpathSync(cwd) !== cwd)
627
+ throw new Error("unavailable");
628
+ delete process.env.__CF_USER_TEXT_ENCODING;
629
+ const safe = /* @__PURE__ */ new Set([
630
+ "PATH",
631
+ "HOME",
632
+ "TMPDIR",
633
+ "TMP",
634
+ "TEMP",
635
+ "LANG",
636
+ "LANGUAGE",
637
+ "LC_ALL",
638
+ "LC_CTYPE",
639
+ "TERM",
640
+ "SHELL",
641
+ "TZ",
642
+ "PWD",
643
+ "CI",
644
+ "NO_COLOR"
645
+ ]);
646
+ if (Object.keys(process.env).some((key) => !safe.has(key))) throw new Error("unavailable");
647
+ const calls2 = getDarwinCensusCalls();
648
+ const reader = new DarwinCensusReader(calls2);
649
+ const owner = reader.ownIdentity();
650
+ const outside = calls2.identity(process.ppid, Buffer.alloc(56));
651
+ if ("kind" in owner || outside.bytes !== 0 || outside.errno !== constants3.errno.EPERM)
652
+ throw new Error("unavailable");
653
+ const inspection = getDarwinProcessInspector();
654
+ const native = inspection.member(process.pid);
655
+ if (!native || native.state === "Z" || native.parent !== process.ppid || native.group !== process.pid || native.session !== process.pid)
656
+ throw new Error("unavailable");
657
+ const job = new DarwinCommandJob({ reader, owner, inspection, cwd, env: process.env, sink: emit });
658
+ emit({ type: "ready", version: DARWIN_JOB_PROTOCOL, nonce, owner, native });
659
+ let pending = Buffer.alloc(0);
660
+ process.stdin.on("data", (bytes) => {
661
+ if (closing) return;
662
+ try {
663
+ if (pending.length + bytes.length > 2 * DARWIN_JOB_MAX_FRAME_BYTES)
664
+ throw new Error("unavailable");
665
+ pending = Buffer.concat([pending, bytes]);
666
+ for (; ; ) {
667
+ const newline = pending.indexOf(10);
668
+ if (newline < 0) break;
669
+ if (newline <= 0 || newline > DARWIN_JOB_MAX_FRAME_BYTES) throw new Error("unavailable");
670
+ const raw = pending.subarray(0, newline);
671
+ pending = pending.subarray(newline + 1);
672
+ const line = raw.toString("utf8");
673
+ if (!Buffer.from(line, "utf8").equals(raw)) throw new Error("unavailable");
674
+ if (job.accept(parseDarwinJobRequest(JSON.parse(line)))) {
675
+ closing = true;
676
+ process.stdin.pause();
677
+ process.stdout.write("", () => process.exit(0));
678
+ return;
679
+ }
680
+ }
681
+ if (pending.length > DARWIN_JOB_MAX_FRAME_BYTES) throw new Error("unavailable");
682
+ } catch {
683
+ fatal();
684
+ }
685
+ });
686
+ process.stdin.once("end", () => {
687
+ if (!closing) process.exit(1);
688
+ });
689
+ } catch {
690
+ fatal();
691
+ }
692
+ //# sourceMappingURL=native-darwin-entry.js.map