@cotal-ai/workspace 0.100.1 → 0.101.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 (171) hide show
  1. package/build/Release/darwin-arm64/build.json +20 -0
  2. package/build/Release/darwin-arm64/process.node +0 -0
  3. package/build/Release/darwin-x64/build.json +20 -0
  4. package/build/Release/darwin-x64/process.node +0 -0
  5. package/build/Release/win32-arm64/build.json +4 -3
  6. package/build/Release/win32-x64/build.json +4 -3
  7. package/dist/agent-grants.d.ts +21 -0
  8. package/dist/agent-grants.d.ts.map +1 -0
  9. package/dist/agent-grants.js +21 -0
  10. package/dist/agent-grants.js.map +1 -0
  11. package/dist/auth-paths.d.ts +34 -0
  12. package/dist/auth-paths.d.ts.map +1 -1
  13. package/dist/auth-paths.js +99 -3
  14. package/dist/auth-paths.js.map +1 -1
  15. package/dist/broker-display.d.ts +12 -0
  16. package/dist/broker-display.d.ts.map +1 -1
  17. package/dist/broker-display.js +14 -0
  18. package/dist/broker-display.js.map +1 -1
  19. package/dist/connect.d.ts +21 -7
  20. package/dist/connect.d.ts.map +1 -1
  21. package/dist/connect.js +152 -22
  22. package/dist/connect.js.map +1 -1
  23. package/dist/control-target.d.ts.map +1 -1
  24. package/dist/control-target.js +12 -10
  25. package/dist/control-target.js.map +1 -1
  26. package/dist/cotal-config.d.ts +7 -0
  27. package/dist/cotal-config.d.ts.map +1 -1
  28. package/dist/cotal-config.js +29 -2
  29. package/dist/cotal-config.js.map +1 -1
  30. package/dist/cotal-home.d.ts +23 -0
  31. package/dist/cotal-home.d.ts.map +1 -0
  32. package/dist/cotal-home.js +36 -0
  33. package/dist/cotal-home.js.map +1 -0
  34. package/dist/credential-actions.d.ts +17 -3
  35. package/dist/credential-actions.d.ts.map +1 -1
  36. package/dist/credential-actions.js +62 -10
  37. package/dist/credential-actions.js.map +1 -1
  38. package/dist/darwin-process.d.ts +20 -0
  39. package/dist/darwin-process.d.ts.map +1 -0
  40. package/dist/darwin-process.js +24 -0
  41. package/dist/darwin-process.js.map +1 -0
  42. package/dist/deprecated-daemon-entries.d.ts +3 -0
  43. package/dist/deprecated-daemon-entries.d.ts.map +1 -1
  44. package/dist/deprecated-daemon-entries.js +6 -1
  45. package/dist/deprecated-daemon-entries.js.map +1 -1
  46. package/dist/extensions.d.ts +4 -2
  47. package/dist/extensions.d.ts.map +1 -1
  48. package/dist/extensions.js +7 -2
  49. package/dist/extensions.js.map +1 -1
  50. package/dist/flags.d.ts +2 -0
  51. package/dist/flags.d.ts.map +1 -1
  52. package/dist/flags.js +1 -1
  53. package/dist/flags.js.map +1 -1
  54. package/dist/index.d.ts +7 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +7 -1
  57. package/dist/index.js.map +1 -1
  58. package/dist/join-target.d.ts +3 -1
  59. package/dist/join-target.d.ts.map +1 -1
  60. package/dist/join-target.js +15 -3
  61. package/dist/join-target.js.map +1 -1
  62. package/dist/maintenance.d.ts +61 -2
  63. package/dist/maintenance.d.ts.map +1 -1
  64. package/dist/maintenance.js +153 -14
  65. package/dist/maintenance.js.map +1 -1
  66. package/dist/manager-name.d.ts +15 -0
  67. package/dist/manager-name.d.ts.map +1 -0
  68. package/dist/manager-name.js +54 -0
  69. package/dist/manager-name.js.map +1 -0
  70. package/dist/mesh-registry.d.ts +39 -35
  71. package/dist/mesh-registry.d.ts.map +1 -1
  72. package/dist/mesh-registry.js +57 -36
  73. package/dist/mesh-registry.js.map +1 -1
  74. package/dist/mesh-target.d.ts +120 -3
  75. package/dist/mesh-target.d.ts.map +1 -1
  76. package/dist/mesh-target.js +319 -48
  77. package/dist/mesh-target.js.map +1 -1
  78. package/dist/official-connectors.d.ts +3 -0
  79. package/dist/official-connectors.d.ts.map +1 -1
  80. package/dist/official-connectors.js +5 -0
  81. package/dist/official-connectors.js.map +1 -1
  82. package/dist/output.d.ts +34 -6
  83. package/dist/output.d.ts.map +1 -1
  84. package/dist/output.js +38 -5
  85. package/dist/output.js.map +1 -1
  86. package/dist/pid.d.ts +42 -7
  87. package/dist/pid.d.ts.map +1 -1
  88. package/dist/pid.js +189 -26
  89. package/dist/pid.js.map +1 -1
  90. package/dist/preferences.d.ts +25 -3
  91. package/dist/preferences.d.ts.map +1 -1
  92. package/dist/preferences.js +77 -14
  93. package/dist/preferences.js.map +1 -1
  94. package/dist/preflight.d.ts +17 -5
  95. package/dist/preflight.d.ts.map +1 -1
  96. package/dist/preflight.js +22 -32
  97. package/dist/preflight.js.map +1 -1
  98. package/dist/prepared-spaces.d.ts +20 -2
  99. package/dist/prepared-spaces.d.ts.map +1 -1
  100. package/dist/prepared-spaces.js +90 -15
  101. package/dist/prepared-spaces.js.map +1 -1
  102. package/dist/present.d.ts +2 -12
  103. package/dist/present.d.ts.map +1 -1
  104. package/dist/present.js +24 -40
  105. package/dist/present.js.map +1 -1
  106. package/dist/protected-records.d.ts +22 -3
  107. package/dist/protected-records.d.ts.map +1 -1
  108. package/dist/protected-records.js +198 -27
  109. package/dist/protected-records.js.map +1 -1
  110. package/dist/registration-policy.d.ts +2 -1
  111. package/dist/registration-policy.d.ts.map +1 -1
  112. package/dist/render.d.ts +2 -1
  113. package/dist/render.d.ts.map +1 -1
  114. package/dist/render.js +42 -11
  115. package/dist/render.js.map +1 -1
  116. package/dist/renewal.d.ts +4 -0
  117. package/dist/renewal.d.ts.map +1 -1
  118. package/dist/renewal.js +20 -1
  119. package/dist/renewal.js.map +1 -1
  120. package/dist/service-adapter.d.ts +1 -2
  121. package/dist/service-adapter.d.ts.map +1 -1
  122. package/dist/service-adapter.js +9 -4
  123. package/dist/service-adapter.js.map +1 -1
  124. package/dist/service-custody.js +2 -2
  125. package/dist/service-custody.js.map +1 -1
  126. package/dist/service-definition.d.ts +3 -0
  127. package/dist/service-definition.d.ts.map +1 -1
  128. package/dist/service-definition.js +56 -2
  129. package/dist/service-definition.js.map +1 -1
  130. package/dist/service-definition.schema.json +2 -1
  131. package/dist/service-identity.js +4 -4
  132. package/dist/service-identity.js.map +1 -1
  133. package/dist/service-stop.js +3 -3
  134. package/dist/service-stop.js.map +1 -1
  135. package/dist/service-target.d.ts.map +1 -1
  136. package/dist/service-target.js +9 -2
  137. package/dist/service-target.js.map +1 -1
  138. package/dist/signer-export.d.ts +1 -0
  139. package/dist/signer-export.d.ts.map +1 -1
  140. package/dist/signer-export.js +20 -4
  141. package/dist/signer-export.js.map +1 -1
  142. package/dist/space-streams.d.ts +18 -0
  143. package/dist/space-streams.d.ts.map +1 -0
  144. package/dist/space-streams.js +41 -0
  145. package/dist/space-streams.js.map +1 -0
  146. package/dist/space.d.ts +5 -0
  147. package/dist/space.d.ts.map +1 -1
  148. package/dist/space.js +5 -0
  149. package/dist/space.js.map +1 -1
  150. package/dist/store-entries.d.ts +6 -0
  151. package/dist/store-entries.d.ts.map +1 -0
  152. package/dist/store-entries.js +17 -0
  153. package/dist/store-entries.js.map +1 -0
  154. package/dist/system-rotation.d.ts +3 -1
  155. package/dist/system-rotation.d.ts.map +1 -1
  156. package/dist/system-rotation.js +19 -4
  157. package/dist/system-rotation.js.map +1 -1
  158. package/dist/telemetry.d.ts +4 -3
  159. package/dist/telemetry.d.ts.map +1 -1
  160. package/dist/telemetry.js +13 -6
  161. package/dist/telemetry.js.map +1 -1
  162. package/dist/text-wrap.d.ts +18 -0
  163. package/dist/text-wrap.d.ts.map +1 -0
  164. package/dist/text-wrap.js +60 -0
  165. package/dist/text-wrap.js.map +1 -0
  166. package/native/README.md +5 -3
  167. package/native/darwin-process.c +173 -0
  168. package/package.json +2 -2
  169. package/scripts/assert-shipped-natives.mjs +3 -3
  170. package/scripts/build-native.mjs +39 -25
  171. package/scripts/native-contract.mjs +36 -16
package/dist/telemetry.js CHANGED
@@ -68,7 +68,14 @@ function write(settings) {
68
68
  }
69
69
  /** The settings file, created at `regular` with a fresh install id when there is none. */
70
70
  export function readTelemetrySettings() {
71
- return readFile() ?? write({ v: 1, level: "regular", installId: randomUUID(), createdAt: new Date().toISOString() });
71
+ return readOrCreate().settings;
72
+ }
73
+ /** {@link readTelemetrySettings}, saying whether this read created the file. */
74
+ function readOrCreate() {
75
+ const found = readFile();
76
+ if (found)
77
+ return { settings: found, created: false };
78
+ return { settings: write({ v: 1, level: "regular", installId: randomUUID(), createdAt: new Date().toISOString() }), created: true };
72
79
  }
73
80
  export function setTelemetryLevel(level) {
74
81
  return write({ ...readTelemetrySettings(), level });
@@ -95,14 +102,14 @@ export function telemetryLevelFromEnv(env) {
95
102
  throw new CommandFailure("refused", "USAGE_INVALID", "COTAL_TELEMETRY must be off, minimal or regular", { remedy: "unset it, or set it to one of those levels" });
96
103
  return { level: named, source: "COTAL_TELEMETRY" };
97
104
  }
98
- /** The level in force and where it comes from, with the settings file that holds the install id.
99
- * The file is neither read nor created when the environment forces `off`, so a machine that opts
100
- * out by environment keeps no install id. */
105
+ /** The level in force and where it comes from, with the settings file that holds the install id
106
+ * and whether this read created that file. The file is neither read nor created when the
107
+ * environment forces `off`, so a machine that opts out by environment keeps no install id. */
101
108
  export function effectiveTelemetry(env) {
102
109
  const forced = telemetryLevelFromEnv(env);
103
110
  if (forced?.level === "off")
104
111
  return forced;
105
- const settings = readTelemetrySettings();
106
- return forced ? { ...forced, settings } : { level: settings.level, source: "file", settings };
112
+ const { settings, created } = readOrCreate();
113
+ return forced ? { ...forced, settings, created } : { level: settings.level, source: "file", settings, created };
107
114
  }
108
115
  //# sourceMappingURL=telemetry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD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nC,MAAM,UAAU,qBAAqB,CAAC,GAAsB;IAC1D,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IAC9E,IAAI,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACtG,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC;IAClC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAC1D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,eAAe,EAAE,iDAAiD,EAAE,EAAE,MAAM,EAAE,4CAA4C,EAAE,CAAC,CAAC;IACvL,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;AACrD,CAAC;AAED;;+FAE+F;AAC/F,MAAM,UAAU,kBAAkB,CAAC,GAAsB;IACvD,MAAM,MAAM,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC1C,IAAI,MAAM,EAAE,KAAK,KAAK,KAAK;QAAE,OAAO,MAAM,CAAC;IAC3C,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;IAC7C,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAClH,CAAC"}
@@ -0,0 +1,18 @@
1
+ /** The columns `text` occupies on a terminal: grapheme clusters, wide East Asian and emoji
2
+ * characters as two, combining marks and zero-width characters as none, ANSI sequences as none. */
3
+ export declare function displayWidth(text: string): number;
4
+ /** `command` as a sentence names it: between backticks or, when it holds a backtick itself, as a
5
+ * quoted path can, between a run of backticks one longer than any run it holds, as Markdown writes
6
+ * such code. A command starts with its program and the CLI quotes any argument that holds a
7
+ * backtick, so it neither starts nor ends with one. */
8
+ export declare function codeSpan(command: string): string;
9
+ /** `text` in lines of at most `width` display columns, broken at spaces, or only between the given
10
+ * words. A word wider than `width` keeps a line of its own, so an identity, path or command is never
11
+ * split. Below 20 columns, and when the output is not a terminal, nothing is wrapped. */
12
+ export declare function wrapWords(text: string | readonly string[], width: number): string[];
13
+ /** The columns a stream can show: its terminal's width, or unbounded when it is not a terminal. */
14
+ export declare function terminalWidth(stream: {
15
+ readonly isTTY?: boolean;
16
+ readonly columns?: number;
17
+ }): number;
18
+ //# sourceMappingURL=text-wrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-wrap.d.ts","sourceRoot":"","sources":["../src/text-wrap.ts"],"names":[],"mappings":"AAEA;oGACoG;AACpG,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;wDAGwD;AACxD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGhD;AAsBD;;0FAE0F;AAC1F,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAcnF;AAED,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAErG"}
@@ -0,0 +1,60 @@
1
+ import stringWidth from "string-width";
2
+ /** The columns `text` occupies on a terminal: grapheme clusters, wide East Asian and emoji
3
+ * characters as two, combining marks and zero-width characters as none, ANSI sequences as none. */
4
+ export function displayWidth(text) {
5
+ return stringWidth(text);
6
+ }
7
+ /** `command` as a sentence names it: between backticks or, when it holds a backtick itself, as a
8
+ * quoted path can, between a run of backticks one longer than any run it holds, as Markdown writes
9
+ * such code. A command starts with its program and the CLI quotes any argument that holds a
10
+ * backtick, so it neither starts nor ends with one. */
11
+ export function codeSpan(command) {
12
+ const fence = "`".repeat(Math.max(0, ...(command.match(/`+/g) ?? []).map((run) => run.length)) + 1);
13
+ return `${fence}${command}${fence}`;
14
+ }
15
+ /** `text` split at spaces into the words {@link wrapWords} breaks between. A command a sentence
16
+ * names in backticks after other words, from its `cotal` to the next run of as many backticks as
17
+ * opened it, is one word, so no line holds part of it, whatever words its arguments are. A line
18
+ * that starts with a command, as a usage line or a code line does, wraps at its spaces. */
19
+ function wrapUnits(text) {
20
+ const parts = text.split(" "), words = [];
21
+ for (let i = 0; i < parts.length; i++) {
22
+ let end = i;
23
+ const open = i > 0 ? /^[("']*(`+)(cotal|pnpm|npx)$/.exec(parts[i]) : null;
24
+ if (open) {
25
+ const fence = new RegExp(`(?<!\`)\`{${open[1].length}}(?!\`)`);
26
+ const close = parts.findIndex((part, j) => j > i && fence.test(part));
27
+ if (close > 0)
28
+ end = close;
29
+ }
30
+ words.push(parts.slice(i, end + 1).join(" "));
31
+ i = end;
32
+ }
33
+ return words;
34
+ }
35
+ /** `text` in lines of at most `width` display columns, broken at spaces, or only between the given
36
+ * words. A word wider than `width` keeps a line of its own, so an identity, path or command is never
37
+ * split. Below 20 columns, and when the output is not a terminal, nothing is wrapped. */
38
+ export function wrapWords(text, width) {
39
+ const words = typeof text === "string" ? wrapUnits(text) : text;
40
+ if (!(width >= 20) || displayWidth(words.join(" ")) <= width)
41
+ return [words.join(" ")];
42
+ const lines = [];
43
+ let line = "";
44
+ for (const word of words) {
45
+ const next = line ? `${line} ${word}` : word;
46
+ if (line && displayWidth(next) > width) {
47
+ lines.push(line);
48
+ line = word;
49
+ }
50
+ else
51
+ line = next;
52
+ }
53
+ lines.push(line);
54
+ return lines;
55
+ }
56
+ /** The columns a stream can show: its terminal's width, or unbounded when it is not a terminal. */
57
+ export function terminalWidth(stream) {
58
+ return stream.isTTY && stream.columns ? stream.columns : Number.POSITIVE_INFINITY;
59
+ }
60
+ //# sourceMappingURL=text-wrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-wrap.js","sourceRoot":"","sources":["../src/text-wrap.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC;oGACoG;AACpG,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;;wDAGwD;AACxD,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,KAAK,EAAE,CAAC;AACtC,CAAC;AAED;;;4FAG4F;AAC5F,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,GAAa,EAAE,CAAC;IACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3E,IAAI,IAAI,EAAE,CAAC;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CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,IAAI,GAAG,IAAI,CAAC;QACd,CAAC;;YAAM,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,aAAa,CAAC,MAA+D;IAC3F,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC;AACpF,CAAC"}
package/native/README.md CHANGED
@@ -1,7 +1,9 @@
1
- # Windows creation identity
1
+ # Native process identity
2
2
 
3
3
  `win32-process.c` uses the stable Node-API C interface and Windows process-query APIs. It returns the creation FILETIME as a decimal string. It has no runtime dependency or PowerShell fallback.
4
4
 
5
- Build on native Windows x64 and arm64 in the matching MSVC Developer Command Prompt with `pnpm --filter @cotal-ai/workspace build:native`. The script downloads only the checksum-pinned Node headers and import library in `node-sdk.json`. It records source, SDK, compiler and binary provenance beside the output. An existing binary must verify before reuse; stale output is an error.
5
+ `darwin-process.c` uses the same interface and the documented macOS kernel interfaces. `sysctl` with `KERN_PROC_PID` gives a process's start time in microseconds, its process group and whether it is stopped. `KERN_PROC_PGRP` lists the members of a process group. `gethostuuid` gives the machine's UUID and `kern.bootsessionuuid` gives this boot's UUID. It does not use `libproc`, whose header calls its interfaces private and subject to change, and it never runs `ps`.
6
6
 
7
- Both architecture directories and their receipts must be assembled under `build/Release` before packing or publishing workspace. Customer installation uses these prebuilt files and runs no compiler or native download. The native CI suite runs the same Node-API 8 binaries on Node 22, 24 and 26. Its PowerShell compatibility oracle is test-only and runs after the first cold production read.
7
+ Build on native Windows x64 and arm64 in the matching MSVC Developer Command Prompt, or on macOS x64 and arm64 with Xcode or its command line tools, with `pnpm --filter @cotal-ai/workspace build:native`. The script downloads only the checksum-pinned Node headers in `node-sdk.json`, and on Windows the import library. A macOS bundle targets macOS 11.0, the oldest macOS Node 22 supports, and resolves Node-API symbols from the loading `node`. The script records source, SDK, compiler and binary provenance beside the output. An existing binary must verify before reuse; stale output is an error.
8
+
9
+ Both Windows and both macOS architecture directories and their receipts must be assembled under `build/Release` before packing or publishing workspace; the shared native workflow builds the macOS pair on `macos-15-intel` and `macos-15` when a caller asks for it with `darwin: true`. Customer installation uses these prebuilt files and runs no compiler or native download. The native CI suite runs the same Node-API 8 binaries on Node 22, 24 and 26. Its PowerShell compatibility oracle is test-only and runs after the first cold production read. `smoke/darwin-process-native.smoke.ts` runs the macOS binding on a macOS runner.
@@ -0,0 +1,173 @@
1
+ #define _DARWIN_C_SOURCE
2
+ #define NAPI_VERSION 8
3
+ #include <node_api.h>
4
+ #include <errno.h>
5
+ #include <math.h>
6
+ #include <stdint.h>
7
+ #include <stdio.h>
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+ #include <sys/types.h>
11
+ #include <sys/proc.h>
12
+ #include <sys/sysctl.h>
13
+ #include <time.h>
14
+ #include <unistd.h>
15
+ #include <uuid/uuid.h>
16
+
17
+ static napi_value undefined_value(napi_env env) {
18
+ napi_value value;
19
+ if (napi_get_undefined(env, &value) != napi_ok) return NULL;
20
+ return value;
21
+ }
22
+
23
+ static napi_value fail(napi_env env, const char *what, int error) {
24
+ char message[160];
25
+ snprintf(message, sizeof(message), "%s failed: %s", what, strerror(error));
26
+ napi_throw_error(env, NULL, message);
27
+ return NULL;
28
+ }
29
+
30
+ /* A positive integer within pid_t, or 0 for any other argument. */
31
+ static pid_t pid_argument(napi_env env, napi_callback_info info) {
32
+ size_t argc = 1;
33
+ napi_value arg;
34
+ double value;
35
+ if (napi_get_cb_info(env, info, &argc, &arg, NULL, NULL) != napi_ok || argc != 1 ||
36
+ napi_get_value_double(env, arg, &value) != napi_ok || !isfinite(value) ||
37
+ value < 1 || value > INT32_MAX || value != (double)(int32_t)value) return 0;
38
+ return (pid_t)value;
39
+ }
40
+
41
+ static int set_number(napi_env env, napi_value object, const char *name, double number) {
42
+ napi_value value;
43
+ return napi_create_double(env, number, &value) == napi_ok && napi_set_named_property(env, object, name, value) == napi_ok;
44
+ }
45
+
46
+ static int set_boolean(napi_env env, napi_value object, const char *name, int flag) {
47
+ napi_value value;
48
+ return napi_get_boolean(env, flag != 0, &value) == napi_ok && napi_set_named_property(env, object, name, value) == napi_ok;
49
+ }
50
+
51
+ /* One process's kernel entry: its start time, its process group and whether it is stopped.
52
+ * Undefined when no process has that ID; a failed read throws. */
53
+ static napi_value process_info(napi_env env, napi_callback_info info) {
54
+ pid_t pid = pid_argument(env, info);
55
+ if (pid == 0) return undefined_value(env);
56
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
57
+ struct kinfo_proc entry;
58
+ size_t length = sizeof(entry);
59
+ memset(&entry, 0, sizeof(entry));
60
+ if (sysctl(mib, 4, &entry, &length, NULL, 0) != 0) return fail(env, "sysctl KERN_PROC_PID", errno);
61
+ if (length == 0) return undefined_value(env);
62
+ if (length != sizeof(entry) || entry.kp_proc.p_pid != pid) {
63
+ napi_throw_error(env, NULL, "sysctl KERN_PROC_PID returned another process entry");
64
+ return NULL;
65
+ }
66
+
67
+ // The start time is a timeval. Keep every microsecond through the JS boundary as a decimal string.
68
+ struct timeval start = entry.kp_proc.p_starttime;
69
+ if (start.tv_sec < 0 || start.tv_usec < 0 || start.tv_usec >= 1000000) {
70
+ napi_throw_error(env, NULL, "the process start time is out of range");
71
+ return NULL;
72
+ }
73
+ char token[32];
74
+ int written = snprintf(token, sizeof(token), "%llu", (unsigned long long)start.tv_sec * 1000000ULL + (unsigned long long)start.tv_usec);
75
+ if (written < 1 || written >= (int)sizeof(token)) {
76
+ napi_throw_error(env, NULL, "the process start time could not be formatted");
77
+ return NULL;
78
+ }
79
+
80
+ napi_value result, text;
81
+ if (napi_create_object(env, &result) != napi_ok ||
82
+ napi_create_string_utf8(env, token, (size_t)written, &text) != napi_ok ||
83
+ napi_set_named_property(env, result, "token", text) != napi_ok ||
84
+ !set_number(env, result, "pgid", (double)entry.kp_eproc.e_pgid) ||
85
+ !set_boolean(env, result, "stopped", entry.kp_proc.p_stat == SSTOP)) return NULL;
86
+ return result;
87
+ }
88
+
89
+ /* The processes in one process group that have not exited. A failed read throws, so an unread group
90
+ * is never reported empty. */
91
+ static napi_value group_members(napi_env env, napi_callback_info info) {
92
+ pid_t pgid = pid_argument(env, info);
93
+ if (pgid == 0) return undefined_value(env);
94
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PGRP, pgid};
95
+ struct kinfo_proc *entries = NULL;
96
+ size_t length = 0;
97
+ for (int attempt = 0;; attempt++) {
98
+ size_t needed = 0;
99
+ if (sysctl(mib, 4, NULL, &needed, NULL, 0) != 0) return fail(env, "sysctl KERN_PROC_PGRP", errno);
100
+ length = needed + 8 * sizeof(struct kinfo_proc);
101
+ entries = malloc(length);
102
+ if (entries == NULL) return fail(env, "process group allocation", ENOMEM);
103
+ if (sysctl(mib, 4, entries, &length, NULL, 0) == 0) break;
104
+ int error = errno;
105
+ free(entries);
106
+ entries = NULL;
107
+ // The group grew between the size query and the read; ask again, a bounded number of times.
108
+ if (error != ENOMEM || attempt == 7) return fail(env, "sysctl KERN_PROC_PGRP", error);
109
+ }
110
+ if (length % sizeof(struct kinfo_proc) != 0) {
111
+ free(entries);
112
+ napi_throw_error(env, NULL, "sysctl KERN_PROC_PGRP returned a partial process entry");
113
+ return NULL;
114
+ }
115
+ size_t count = length / sizeof(struct kinfo_proc);
116
+ napi_value result;
117
+ if (napi_create_array(env, &result) != napi_ok) {
118
+ free(entries);
119
+ return NULL;
120
+ }
121
+ uint32_t index = 0;
122
+ for (size_t i = 0; i < count; i++) {
123
+ if (entries[i].kp_eproc.e_pgid != pgid || entries[i].kp_proc.p_stat == SZOMB) continue;
124
+ napi_value member;
125
+ if (napi_create_double(env, (double)entries[i].kp_proc.p_pid, &member) != napi_ok ||
126
+ napi_set_element(env, result, index++, member) != napi_ok) {
127
+ free(entries);
128
+ return NULL;
129
+ }
130
+ }
131
+ free(entries);
132
+ return result;
133
+ }
134
+
135
+ /* The machine's hardware UUID and this boot's session UUID, as the kernel reports them. */
136
+ static napi_value host_identity(napi_env env, napi_callback_info info) {
137
+ (void)info;
138
+ uuid_t id;
139
+ struct timespec wait = {5, 0};
140
+ if (gethostuuid(id, &wait) != 0) return fail(env, "gethostuuid", errno);
141
+ if (uuid_is_null(id)) {
142
+ napi_throw_error(env, NULL, "gethostuuid returned the null UUID");
143
+ return NULL;
144
+ }
145
+ uuid_string_t machine;
146
+ uuid_unparse_lower(id, machine);
147
+
148
+ char boot[64];
149
+ size_t length = sizeof(boot);
150
+ if (sysctlbyname("kern.bootsessionuuid", boot, &length, NULL, 0) != 0) return fail(env, "sysctl kern.bootsessionuuid", errno);
151
+ if (length == 0 || length > sizeof(boot) || boot[length - 1] != '\0') {
152
+ napi_throw_error(env, NULL, "kern.bootsessionuuid is not a string");
153
+ return NULL;
154
+ }
155
+
156
+ napi_value result, machine_value, boot_value;
157
+ if (napi_create_object(env, &result) != napi_ok ||
158
+ napi_create_string_utf8(env, machine, NAPI_AUTO_LENGTH, &machine_value) != napi_ok ||
159
+ napi_set_named_property(env, result, "machine", machine_value) != napi_ok ||
160
+ napi_create_string_utf8(env, boot, NAPI_AUTO_LENGTH, &boot_value) != napi_ok ||
161
+ napi_set_named_property(env, result, "boot", boot_value) != napi_ok) return NULL;
162
+ return result;
163
+ }
164
+
165
+ NAPI_MODULE_INIT() {
166
+ napi_property_descriptor functions[] = {
167
+ {"processInfo", NULL, process_info, NULL, NULL, NULL, napi_enumerable, NULL},
168
+ {"groupMembers", NULL, group_members, NULL, NULL, NULL, napi_enumerable, NULL},
169
+ {"hostIdentity", NULL, host_identity, NULL, NULL, NULL, napi_enumerable, NULL},
170
+ };
171
+ if (napi_define_properties(env, exports, sizeof(functions) / sizeof(functions[0]), functions) != napi_ok) return NULL;
172
+ return exports;
173
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cotal-ai/workspace",
3
3
  "description": "Cotal machine-local workstation layer: the ~/.cotal mesh registry, target resolution, preflight, on-disk auth-path I/O, and the command-copy renderer — operator concerns over a local checkout, kept separate from the wire protocol in @cotal-ai/core.",
4
- "version": "0.100.1",
4
+ "version": "0.101.0",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@cotal-ai/core": "0.100.1",
21
+ "@cotal-ai/core": "0.101.0",
22
22
  "ajv": "^8.20.0",
23
23
  "string-width": "^8.2.1",
24
24
  "yaml": "^2.9.0",
@@ -2,8 +2,8 @@
2
2
  import { verifyNative } from "./native-contract.mjs";
3
3
 
4
4
  try {
5
- for (const arch of ["x64", "arm64"]) verifyNative(arch);
6
- console.log("Windows creation identity: both native architectures verified");
5
+ for (const platform of ["win32", "darwin"]) for (const arch of ["x64", "arm64"]) verifyNative(platform, arch);
6
+ console.log("Native process identity: Windows and macOS bindings verified for both architectures");
7
7
  } catch (cause) {
8
- throw new Error("@cotal-ai/workspace requires source-matched Windows x64 and arm64 identity bindings before pack or publish", { cause });
8
+ throw new Error("@cotal-ai/workspace requires source-matched Windows and macOS x64 and arm64 identity bindings before pack or publish", { cause });
9
9
  }
@@ -4,19 +4,21 @@ import { execFileSync } from "node:child_process";
4
4
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
6
6
  import { join } from "node:path";
7
- import { root, sdk, sha256, sourceHashes, verifyNative } from "./native-contract.mjs";
7
+ import { darwinTarget, nativeDir, nativeFile, root, sdk, sha256, sourceHashes, verifyNative } from "./native-contract.mjs";
8
8
 
9
- if (process.platform !== "win32") process.exit(0);
9
+ const platform = process.platform;
10
+ if (platform !== "win32" && platform !== "darwin") process.exit(0);
10
11
  const arch = process.arch;
11
- assert(arch === "x64" || arch === "arm64", `unsupported Windows native architecture: ${arch}`);
12
- const dest = join(root, "build/Release", `win32-${arch}`);
13
- if (existsSync(join(dest, "creation.node")) || existsSync(join(dest, "build.json"))) {
12
+ const name = platform === "win32" ? "Windows creation identity" : "macOS process identity";
13
+ assert(arch === "x64" || arch === "arm64", `unsupported ${name} architecture: ${arch}`);
14
+ const dest = nativeDir(platform, arch);
15
+ if (existsSync(join(dest, nativeFile(platform))) || existsSync(join(dest, "build.json"))) {
14
16
  // A verified prebuilt needs no compiler. Stale or damaged artifacts are not silently rebuilt.
15
- verifyNative(arch, dest);
17
+ verifyNative(platform, arch, dest);
16
18
  process.exit(0);
17
19
  }
18
- assert(process.env.VCToolsVersion && process.env.WindowsSDKVersion, "build Windows identity in the matching MSVC Developer Command Prompt");
19
- const temp = mkdtempSync(join(tmpdir(), "cotal-win32-native-"));
20
+ if (platform === "win32") assert(process.env.VCToolsVersion && process.env.WindowsSDKVersion, "build Windows identity in the matching MSVC Developer Command Prompt");
21
+ const temp = mkdtempSync(join(tmpdir(), `cotal-${platform}-native-`));
20
22
  try {
21
23
  const download = async (path, expected, output) => {
22
24
  const response = await fetch(`https://nodejs.org/dist/v${sdk.version}/${path}`, { signal: AbortSignal.timeout(60_000) });
@@ -31,34 +33,46 @@ try {
31
33
  mkdirSync(buildDir);
32
34
  const headers = join(sdkDir, "headers.tar.gz");
33
35
  const library = join(sdkDir, "node.lib");
36
+ // A macOS bundle resolves Node-API symbols from the loading node at runtime, so it needs no import library.
34
37
  await Promise.all([
35
38
  download(`node-v${sdk.version}-headers.tar.gz`, sdk.headers, headers),
36
- download(`win-${arch}/node.lib`, sdk.libraries[arch], library),
39
+ ...(platform === "win32" ? [download(`win-${arch}/node.lib`, sdk.libraries[arch], library)] : []),
37
40
  ]);
38
- execFileSync("tar.exe", ["-xzf", headers, "-C", sdkDir], { stdio: "inherit" });
41
+ execFileSync(platform === "win32" ? "tar.exe" : "tar", ["-xzf", headers, "-C", sdkDir], { stdio: "inherit" });
39
42
  const include = join(sdkDir, `node-v${sdk.version}`, "include/node");
40
- const output = join(buildDir, "creation.node");
41
- execFileSync("cl.exe", ["/nologo", "/LD", "/O2", "/MT", "/W4", "/WX", "/std:c11",
42
- `/I${include}`, `/Fo${join(buildDir, "creation.obj")}`, join(root, "native/win32-process.c"),
43
- "/link", "/Brepro", `/OUT:${output}`, library, "kernel32.lib"], { cwd: buildDir, stdio: "inherit" });
44
- if (process.argv.includes("--test-controls")) {
45
- const testDir = join(root, "build/test", `win32-${arch}`);
46
- mkdirSync(testDir, { recursive: true });
43
+ const output = join(buildDir, nativeFile(platform));
44
+ if (platform === "win32") {
47
45
  execFileSync("cl.exe", ["/nologo", "/LD", "/O2", "/MT", "/W4", "/WX", "/std:c11",
48
- `/I${include}`, `/Fo${join(buildDir, "query-denied.obj")}`, join(root, "smoke/fixtures/win32-query-denied.c"),
49
- "/link", "/Brepro", `/OUT:${join(testDir, "query-denied.node")}`, library, "advapi32.lib"], { cwd: buildDir, stdio: "inherit" });
46
+ `/I${include}`, `/Fo${join(buildDir, "creation.obj")}`, join(root, "native/win32-process.c"),
47
+ "/link", "/Brepro", `/OUT:${output}`, library, "kernel32.lib"], { cwd: buildDir, stdio: "inherit" });
48
+ if (process.argv.includes("--test-controls")) {
49
+ const testDir = join(root, "build/test", `win32-${arch}`);
50
+ mkdirSync(testDir, { recursive: true });
51
+ execFileSync("cl.exe", ["/nologo", "/LD", "/O2", "/MT", "/W4", "/WX", "/std:c11",
52
+ `/I${include}`, `/Fo${join(buildDir, "query-denied.obj")}`, join(root, "smoke/fixtures/win32-query-denied.c"),
53
+ "/link", "/Brepro", `/OUT:${join(testDir, "query-denied.node")}`, library, "advapi32.lib"], { cwd: buildDir, stdio: "inherit" });
54
+ }
55
+ } else {
56
+ // The node-gyp shape of a macOS addon: a bundle whose Node-API symbols resolve at load. On arm64 the
57
+ // linker signs it ad hoc, as macOS requires of native code there.
58
+ execFileSync("xcrun", ["clang", "-bundle", "-undefined", "dynamic_lookup", "-arch", arch === "x64" ? "x86_64" : "arm64",
59
+ `-mmacosx-version-min=${darwinTarget}`, "-O2", "-std=c11", "-Wall", "-Wextra", "-Werror",
60
+ `-I${include}`, "-o", output, join(root, "native/darwin-process.c")], { cwd: buildDir, stdio: "inherit" });
50
61
  }
51
62
  const bytes = readFileSync(output);
52
- const receipt = { version: 1, platform: "win32", arch, nodeApi: 8,
63
+ const tool = (args) => execFileSync("xcrun", args, { encoding: "utf8" }).trim();
64
+ const receipt = { version: 1, platform, arch, nodeApi: 8,
53
65
  source: execFileSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" }).trim(),
54
66
  sourceHashes: sourceHashes(), nodeHeaders: sdk.version, headersSha256: sdk.headers,
55
- librarySha256: sdk.libraries[arch], compiler: process.env.VCToolsVersion.trim(),
56
- windowsSdk: process.env.WindowsSDKVersion.trim(), sha256: sha256(bytes) };
67
+ ...(platform === "win32"
68
+ ? { librarySha256: sdk.libraries[arch], compiler: process.env.VCToolsVersion.trim(), windowsSdk: process.env.WindowsSDKVersion.trim() }
69
+ : { compiler: tool(["clang", "--version"]).split("\n")[0], macosSdk: tool(["--show-sdk-version"]), deploymentTarget: darwinTarget }),
70
+ sha256: sha256(bytes) };
57
71
  mkdirSync(dest, { recursive: true });
58
- writeFileSync(join(dest, "creation.node"), bytes, { flag: "wx" });
72
+ writeFileSync(join(dest, nativeFile(platform)), bytes, { flag: "wx" });
59
73
  writeFileSync(join(dest, "build.json"), JSON.stringify(receipt, null, 2) + "\n", { flag: "wx" });
60
- verifyNative(arch, dest);
61
- console.log(`Windows creation identity built and verified (${arch}, Node-API 8)`);
74
+ verifyNative(platform, arch, dest);
75
+ console.log(`${name} built and verified (${arch}, Node-API 8)`);
62
76
  } finally {
63
77
  rmSync(temp, { recursive: true, force: true });
64
78
  }
@@ -5,35 +5,55 @@ import { join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
 
7
7
  export const root = fileURLToPath(new URL("..", import.meta.url));
8
- export const sourceFiles = ["native/win32-process.c", "native/node-sdk.json", "scripts/build-native.mjs", "scripts/native-contract.mjs"];
8
+ export const sourceFiles = ["native/win32-process.c", "native/darwin-process.c", "native/node-sdk.json", "scripts/build-native.mjs", "scripts/native-contract.mjs"];
9
9
  export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
10
10
  export const sourceHashes = () => Object.fromEntries(sourceFiles.map((path) => [path, sha256(readFileSync(join(root, path)))]));
11
11
  export const sdk = JSON.parse(readFileSync(join(root, "native/node-sdk.json"), "utf8"));
12
+ /** The oldest macOS the binding loads on: Node 22's own macOS floor. */
13
+ export const darwinTarget = "11.0";
14
+ /** The binding file each platform ships, under `build/Release/<platform>-<arch>`. */
15
+ export const nativeFile = (platform) => (platform === "win32" ? "creation.node" : "process.node");
16
+ export const nativeDir = (platform, arch) => join(root, "build/Release", `${platform}-${arch}`);
17
+ const label = (platform) => (platform === "win32" ? "Windows identity" : "macOS process identity");
12
18
 
13
19
  /** Verify bytes and their native build receipt before reuse, assembly or publication. */
14
- export function verifyNative(arch, dir = join(root, "build/Release", `win32-${arch}`), expectedSource) {
15
- assert(arch === "x64" || arch === "arm64", `unsupported Windows native architecture: ${arch}`);
16
- const bytes = readFileSync(join(dir, "creation.node"));
17
- assert(bytes.length >= 64 && bytes.toString("ascii", 0, 2) === "MZ", "Windows identity binding is not a PE binary");
18
- const offset = bytes.readUInt32LE(60);
19
- assert(offset + 24 <= bytes.length && bytes.toString("ascii", offset, offset + 4) === "PE\0\0", "invalid Windows identity PE header");
20
- assert.equal(bytes.readUInt16LE(offset + 4), arch === "x64" ? 0x8664 : 0xaa64, "Windows identity binding architecture mismatch");
21
- assert(bytes.readUInt16LE(offset + 22) & 0x2000, "Windows identity binding is not a DLL");
20
+ export function verifyNative(platform, arch, dir = nativeDir(platform, arch), expectedSource) {
21
+ assert(platform === "win32" || platform === "darwin", `unsupported native platform: ${platform}`);
22
+ assert(arch === "x64" || arch === "arm64", `unsupported ${label(platform)} architecture: ${arch}`);
23
+ const bytes = readFileSync(join(dir, nativeFile(platform)));
24
+ if (platform === "win32") {
25
+ assert(bytes.length >= 64 && bytes.toString("ascii", 0, 2) === "MZ", "Windows identity binding is not a PE binary");
26
+ const offset = bytes.readUInt32LE(60);
27
+ assert(offset + 24 <= bytes.length && bytes.toString("ascii", offset, offset + 4) === "PE\0\0", "invalid Windows identity PE header");
28
+ assert.equal(bytes.readUInt16LE(offset + 4), arch === "x64" ? 0x8664 : 0xaa64, "Windows identity binding architecture mismatch");
29
+ assert(bytes.readUInt16LE(offset + 22) & 0x2000, "Windows identity binding is not a DLL");
30
+ } else {
31
+ // mach_header_64: MH_MAGIC_64, then cputype (CPU_TYPE_X86_64 or CPU_TYPE_ARM64) and, at 12, filetype MH_BUNDLE.
32
+ assert(bytes.length >= 32 && bytes.readUInt32LE(0) === 0xfeedfacf, "macOS process identity binding is not a 64-bit Mach-O binary");
33
+ assert.equal(bytes.readUInt32LE(4), arch === "x64" ? 0x01000007 : 0x0100000c, "macOS process identity binding architecture mismatch");
34
+ assert.equal(bytes.readUInt32LE(12), 8, "macOS process identity binding is not a loadable bundle");
35
+ }
22
36
  const receipt = JSON.parse(readFileSync(join(dir, "build.json"), "utf8"));
23
37
  assert.equal(receipt.version, 1);
24
- assert.equal(receipt.platform, "win32");
38
+ assert.equal(receipt.platform, platform);
25
39
  assert.equal(receipt.arch, arch);
26
40
  assert.equal(receipt.nodeApi, 8);
27
41
  assert.match(receipt.source, /^[a-f0-9]{40}$/);
28
- if (expectedSource !== undefined) assert.equal(receipt.source, expectedSource, "Windows identity native checkout provenance mismatch");
29
- assert.deepEqual(receipt.sourceHashes, sourceHashes(), "Windows identity native source provenance mismatch");
42
+ if (expectedSource !== undefined) assert.equal(receipt.source, expectedSource, `${label(platform)} native checkout provenance mismatch`);
43
+ assert.deepEqual(receipt.sourceHashes, sourceHashes(), `${label(platform)} native source provenance mismatch`);
30
44
  assert.equal(receipt.nodeHeaders, sdk.version);
31
45
  assert.equal(typeof receipt.compiler, "string");
32
46
  assert(receipt.compiler.length > 0);
33
- assert.equal(typeof receipt.windowsSdk, "string");
34
- assert(receipt.windowsSdk.length > 0);
35
47
  assert.equal(receipt.headersSha256, sdk.headers);
36
- assert.equal(receipt.librarySha256, sdk.libraries[arch]);
37
- assert.equal(receipt.sha256, sha256(bytes), "Windows identity binary hash mismatch");
48
+ if (platform === "win32") {
49
+ assert.equal(typeof receipt.windowsSdk, "string");
50
+ assert(receipt.windowsSdk.length > 0);
51
+ assert.equal(receipt.librarySha256, sdk.libraries[arch]);
52
+ } else {
53
+ assert.equal(typeof receipt.macosSdk, "string");
54
+ assert(receipt.macosSdk.length > 0);
55
+ assert.equal(receipt.deploymentTarget, darwinTarget);
56
+ }
57
+ assert.equal(receipt.sha256, sha256(bytes), `${label(platform)} binary hash mismatch`);
38
58
  return receipt;
39
59
  }