@ttsc/unplugin 0.36.3 → 0.37.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 (145) hide show
  1. package/lib/api.js +5 -2
  2. package/lib/api.js.map +1 -1
  3. package/lib/api.mjs +1 -1
  4. package/lib/core/bridge/TtscProjectRecord.d.cts +7 -0
  5. package/lib/core/bridge/TtscProjectRecord.d.mts +7 -0
  6. package/lib/core/bridge/TtscProjectRecord.d.ts +7 -0
  7. package/lib/core/bridge/projectRecordArgumentsMatch.d.cts +8 -5
  8. package/lib/core/bridge/projectRecordArgumentsMatch.d.mts +8 -5
  9. package/lib/core/bridge/projectRecordArgumentsMatch.d.ts +8 -5
  10. package/lib/core/bridge/projectRecordArgumentsMatch.js +15 -8
  11. package/lib/core/bridge/projectRecordArgumentsMatch.js.map +1 -1
  12. package/lib/core/bridge/projectRecordArgumentsMatch.mjs +15 -8
  13. package/lib/core/bridge/projectRecordArgumentsMatch.mjs.map +1 -1
  14. package/lib/core/bridge/readProjectRecordFile.js +8 -1
  15. package/lib/core/bridge/readProjectRecordFile.js.map +1 -1
  16. package/lib/core/bridge/readProjectRecordFile.mjs +8 -1
  17. package/lib/core/bridge/readProjectRecordFile.mjs.map +1 -1
  18. package/lib/core/index.js +5 -2
  19. package/lib/core/index.js.map +1 -1
  20. package/lib/core/index.mjs +1 -1
  21. package/lib/core/next/next.js +2 -2
  22. package/lib/core/next/next.js.map +1 -1
  23. package/lib/core/next/next.mjs +1 -1
  24. package/lib/core/rollup/rollupDeliveryOptions.js +2 -2
  25. package/lib/core/rollup/rollupDeliveryOptions.js.map +1 -1
  26. package/lib/core/rollup/rollupDeliveryOptions.mjs +1 -1
  27. package/lib/core/transform/cache/selectCachedGenerationAction.d.cts +12 -4
  28. package/lib/core/transform/cache/selectCachedGenerationAction.d.mts +12 -4
  29. package/lib/core/transform/cache/selectCachedGenerationAction.d.ts +12 -4
  30. package/lib/core/transform/cache/selectCachedGenerationAction.js +16 -9
  31. package/lib/core/transform/cache/selectCachedGenerationAction.js.map +1 -1
  32. package/lib/core/transform/cache/selectCachedGenerationAction.mjs +16 -9
  33. package/lib/core/transform/cache/selectCachedGenerationAction.mjs.map +1 -1
  34. package/lib/core/transform/clock/filesystemListingDevices.d.cts +24 -0
  35. package/lib/core/transform/clock/filesystemListingDevices.d.mts +24 -0
  36. package/lib/core/transform/clock/filesystemListingDevices.d.ts +24 -0
  37. package/lib/core/transform/clock/filesystemListingDevices.js +36 -0
  38. package/lib/core/transform/clock/filesystemListingDevices.js.map +1 -0
  39. package/lib/core/transform/clock/filesystemListingDevices.mjs +34 -0
  40. package/lib/core/transform/clock/filesystemListingDevices.mjs.map +1 -0
  41. package/lib/core/transform/clock/refreshFilesystemClockReference.d.cts +10 -4
  42. package/lib/core/transform/clock/refreshFilesystemClockReference.d.mts +10 -4
  43. package/lib/core/transform/clock/refreshFilesystemClockReference.d.ts +10 -4
  44. package/lib/core/transform/clock/refreshFilesystemClockReference.js +40 -4
  45. package/lib/core/transform/clock/refreshFilesystemClockReference.js.map +1 -1
  46. package/lib/core/transform/clock/refreshFilesystemClockReference.mjs +40 -4
  47. package/lib/core/transform/clock/refreshFilesystemClockReference.mjs.map +1 -1
  48. package/lib/core/transform/generation/captureTransformGeneration.js +8 -2
  49. package/lib/core/transform/generation/captureTransformGeneration.js.map +1 -1
  50. package/lib/core/transform/generation/captureTransformGeneration.mjs +8 -2
  51. package/lib/core/transform/generation/captureTransformGeneration.mjs.map +1 -1
  52. package/lib/core/transform/inputs/pluginSourceFilesDigest.d.cts +7 -1
  53. package/lib/core/transform/inputs/pluginSourceFilesDigest.d.mts +7 -1
  54. package/lib/core/transform/inputs/pluginSourceFilesDigest.d.ts +7 -1
  55. package/lib/core/transform/inputs/pluginSourceFilesDigest.js +66 -4
  56. package/lib/core/transform/inputs/pluginSourceFilesDigest.js.map +1 -1
  57. package/lib/core/transform/inputs/pluginSourceFilesDigest.mjs +66 -4
  58. package/lib/core/transform/inputs/pluginSourceFilesDigest.mjs.map +1 -1
  59. package/lib/core/transform/session/claimSharedCompile.d.cts +12 -1
  60. package/lib/core/transform/session/claimSharedCompile.d.mts +12 -1
  61. package/lib/core/transform/session/claimSharedCompile.d.ts +12 -1
  62. package/lib/core/transform/session/claimSharedCompile.js +22 -4
  63. package/lib/core/transform/session/claimSharedCompile.js.map +1 -1
  64. package/lib/core/transform/session/claimSharedCompile.mjs +22 -4
  65. package/lib/core/transform/session/claimSharedCompile.mjs.map +1 -1
  66. package/lib/core/transform/transformTtsc.js +3 -2
  67. package/lib/core/transform/transformTtsc.js.map +1 -1
  68. package/lib/core/transform/transformTtsc.mjs +2 -1
  69. package/lib/core/transform/transformTtsc.mjs.map +1 -1
  70. package/lib/core/transform/tsconfig/resolveCompilerEnvironment.d.cts +1 -17
  71. package/lib/core/transform/tsconfig/resolveCompilerEnvironment.d.mts +1 -17
  72. package/lib/core/transform/tsconfig/resolveCompilerEnvironment.d.ts +1 -17
  73. package/lib/core/transform/tsconfig/resolveCompilerEnvironment.js +7 -53
  74. package/lib/core/transform/tsconfig/resolveCompilerEnvironment.js.map +1 -1
  75. package/lib/core/transform/tsconfig/resolveCompilerEnvironment.mjs +1 -54
  76. package/lib/core/transform/tsconfig/resolveCompilerEnvironment.mjs.map +1 -1
  77. package/lib/core/transform/validation/captureUniversalHostInputValidation.d.cts +10 -2
  78. package/lib/core/transform/validation/captureUniversalHostInputValidation.d.mts +10 -2
  79. package/lib/core/transform/validation/captureUniversalHostInputValidation.d.ts +10 -2
  80. package/lib/core/transform/validation/captureUniversalHostInputValidation.js +19 -2
  81. package/lib/core/transform/validation/captureUniversalHostInputValidation.js.map +1 -1
  82. package/lib/core/transform/validation/captureUniversalHostInputValidation.mjs +19 -2
  83. package/lib/core/transform/validation/captureUniversalHostInputValidation.mjs.map +1 -1
  84. package/lib/core/transform/validation/environmentInputMismatch.d.cts +23 -0
  85. package/lib/core/transform/validation/environmentInputMismatch.d.mts +23 -0
  86. package/lib/core/transform/validation/environmentInputMismatch.d.ts +23 -0
  87. package/lib/core/transform/validation/environmentInputMismatch.js +46 -0
  88. package/lib/core/transform/validation/environmentInputMismatch.js.map +1 -0
  89. package/lib/core/transform/validation/environmentInputMismatch.mjs +44 -0
  90. package/lib/core/transform/validation/environmentInputMismatch.mjs.map +1 -0
  91. package/lib/core/transform/validation/isEnvironmentInputs.d.cts +15 -0
  92. package/lib/core/transform/validation/isEnvironmentInputs.d.mts +15 -0
  93. package/lib/core/transform/validation/isEnvironmentInputs.d.ts +15 -0
  94. package/lib/core/transform/validation/isEnvironmentInputs.js +26 -0
  95. package/lib/core/transform/validation/isEnvironmentInputs.js.map +1 -0
  96. package/lib/core/transform/validation/isEnvironmentInputs.mjs +24 -0
  97. package/lib/core/transform/validation/isEnvironmentInputs.mjs.map +1 -0
  98. package/lib/core/transform/watch/TtscTransformHooks.d.cts +6 -4
  99. package/lib/core/transform/watch/TtscTransformHooks.d.mts +6 -4
  100. package/lib/core/transform/watch/TtscTransformHooks.d.ts +6 -4
  101. package/lib/core/transform/watch/handWatchInputs.d.cts +3 -1
  102. package/lib/core/transform/watch/handWatchInputs.d.mts +3 -1
  103. package/lib/core/transform/watch/handWatchInputs.d.ts +3 -1
  104. package/lib/core/transform/watch/handWatchInputs.js +7 -2
  105. package/lib/core/transform/watch/handWatchInputs.js.map +1 -1
  106. package/lib/core/transform/watch/handWatchInputs.mjs +7 -2
  107. package/lib/core/transform/watch/handWatchInputs.mjs.map +1 -1
  108. package/lib/core/transform/watch/notifyFailedGenerationInputs.js +3 -1
  109. package/lib/core/transform/watch/notifyFailedGenerationInputs.js.map +1 -1
  110. package/lib/core/transform/watch/notifyFailedGenerationInputs.mjs +3 -1
  111. package/lib/core/transform/watch/notifyFailedGenerationInputs.mjs.map +1 -1
  112. package/lib/core/transform/watch/notifyProjectRecord.js +4 -0
  113. package/lib/core/transform/watch/notifyProjectRecord.js.map +1 -1
  114. package/lib/core/transform/watch/notifyProjectRecord.mjs +4 -0
  115. package/lib/core/transform/watch/notifyProjectRecord.mjs.map +1 -1
  116. package/lib/core/transform/watch/notifyWatchInputs.js +3 -1
  117. package/lib/core/transform/watch/notifyWatchInputs.js.map +1 -1
  118. package/lib/core/transform/watch/notifyWatchInputs.mjs +3 -1
  119. package/lib/core/transform/watch/notifyWatchInputs.mjs.map +1 -1
  120. package/lib/core/turbopack/turbopack.js +2 -2
  121. package/lib/core/turbopack/turbopack.js.map +1 -1
  122. package/lib/core/turbopack/turbopack.mjs +1 -1
  123. package/lib/core/unplugin.js +3 -3
  124. package/lib/core/unplugin.js.map +1 -1
  125. package/lib/core/unplugin.mjs +1 -1
  126. package/package.json +3 -3
  127. package/src/core/bridge/TtscProjectRecord.ts +8 -0
  128. package/src/core/bridge/projectRecordArgumentsMatch.ts +19 -7
  129. package/src/core/bridge/readProjectRecordFile.ts +8 -1
  130. package/src/core/transform/cache/selectCachedGenerationAction.ts +19 -4
  131. package/src/core/transform/clock/filesystemListingDevices.ts +38 -0
  132. package/src/core/transform/clock/refreshFilesystemClockReference.ts +42 -4
  133. package/src/core/transform/generation/captureTransformGeneration.ts +8 -1
  134. package/src/core/transform/inputs/pluginSourceFilesDigest.ts +73 -5
  135. package/src/core/transform/session/claimSharedCompile.ts +35 -5
  136. package/src/core/transform/transformTtsc.ts +1 -0
  137. package/src/core/transform/tsconfig/resolveCompilerEnvironment.ts +1 -61
  138. package/src/core/transform/validation/captureUniversalHostInputValidation.ts +21 -1
  139. package/src/core/transform/validation/environmentInputMismatch.ts +43 -0
  140. package/src/core/transform/validation/isEnvironmentInputs.ts +28 -0
  141. package/src/core/transform/watch/TtscTransformHooks.ts +6 -3
  142. package/src/core/transform/watch/handWatchInputs.ts +5 -1
  143. package/src/core/transform/watch/notifyFailedGenerationInputs.ts +3 -0
  144. package/src/core/transform/watch/notifyProjectRecord.ts +5 -0
  145. package/src/core/transform/watch/notifyWatchInputs.ts +8 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttsc/unplugin",
3
- "version": "0.36.3",
3
+ "version": "0.37.0",
4
4
  "description": "Bundler adapters for ttsc plugins.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -202,7 +202,7 @@
202
202
  "fsevents": "^2.3.3"
203
203
  },
204
204
  "peerDependencies": {
205
- "ttsc": "^0.36.3"
205
+ "ttsc": "^0.37.0"
206
206
  },
207
207
  "devDependencies": {
208
208
  "@wrtnlabs/evidence": "^0.5.1",
@@ -218,7 +218,7 @@
218
218
  "typescript": "^7.0.2",
219
219
  "vite": "^7.3.5",
220
220
  "vite8": "npm:vite@^8.3.4",
221
- "ttsc": "0.36.3"
221
+ "ttsc": "0.37.0"
222
222
  },
223
223
  "repository": {
224
224
  "type": "git",
@@ -61,6 +61,14 @@ export interface TtscProjectRecord {
61
61
  */
62
62
  dependencies?: readonly string[];
63
63
 
64
+ /**
65
+ * The environment variables the generation's plugins read through `ctx.Env`
66
+ * (the envelope's `environmentInputs`), with the value read or null when
67
+ * unset; absent when they read none. A later process proves each against its
68
+ * own compiler environment before the record may stand for the output.
69
+ */
70
+ environmentInputs?: Record<string, string | null>;
71
+
64
72
  /**
65
73
  * Evidenced delivery inputs, keyed by absolute path, with the state the
66
74
  * generation recorded for them. An input whose generation recorded no state,
@@ -1,5 +1,6 @@
1
1
  import { captureCompilerArguments } from "../transform/tsconfig/captureCompilerArguments";
2
2
  import { resolveCompilerEnvironment } from "../transform/tsconfig/resolveCompilerEnvironment";
3
+ import { environmentInputMismatch } from "../transform/validation/environmentInputMismatch";
3
4
  import type { TtscProjectRecord } from "./TtscProjectRecord";
4
5
 
5
6
  /**
@@ -8,13 +9,16 @@ import type { TtscProjectRecord } from "./TtscProjectRecord";
8
9
  * A supplied identity describes the active adapter's explicit override too.
9
10
  * Generic detached readers instead replay the recorded override against current
10
11
  * inheritance. Older records lack that authority and require a new delivery.
12
+ * Every environment variable the generation's plugins read must also still have
13
+ * its recorded value, or stay unset, in the current compiler environment: the
14
+ * record stands for output those reads produced.
11
15
  *
12
- * @evidence contracts/common.md#principled-implementation Recorded effective arguments must match the active context or a current derivation using the recorded override; absent witnesses never certify unknown prior arguments.
16
+ * @evidence contracts/common.md#principled-implementation Recorded effective arguments must match the active context or a current derivation using the recorded override, and recorded environment reads must hold in the current compiler environment; absent witnesses never certify unknown prior arguments.
13
17
  * @evidence contracts/common.md#clear-and-simple-design One predicate serves detached proof and watching bridge admission before filesystem evidence can authorize host cache restoration.
14
- * @evidence contracts/common.md#prohibited-implementation-shortcuts Malformed inherited transport declines reuse rather than restoring a result compiled under different permission.
15
- * @evidence contracts/common.md#meaningful-documentation Native prose states active versus generic comparison and legacy migration.
16
- * @evidence contracts/portability.md#os-neutral-implementation The shared environment owner applies native Windows name selection and preserves argv/cwd spelling without platform guesses.
17
- * @evidence contracts/performance.md#efficient-algorithms An active digest requires scalar comparison; generic replay additionally snapshots environment keys and encodes/hashes argument bytes through existing owners.
18
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Malformed inherited transport declines reuse rather than restoring a result compiled under different permission, and a changed environment read is not excused by matching argument transport.
19
+ * @evidence contracts/common.md#meaningful-documentation Native prose states active versus generic comparison, environment reads and legacy migration.
20
+ * @evidence contracts/portability.md#os-neutral-implementation The shared environment owner applies native Windows name selection and preserves argv/cwd spelling without platform guesses; recorded reads compare under the same native name rule.
21
+ * @evidence contracts/performance.md#efficient-algorithms An active digest requires scalar comparison; generic replay additionally snapshots environment keys and encodes/hashes argument bytes through existing owners. Recorded reads add one environment snapshot and a lookup per name, only when the record carries any.
18
22
  * @evidenceExclude contracts/performance.md#reuse-equivalent-work Current inheritance is observed on each generic proof; no prior environment verdict is retained.
19
23
  * @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Only call-local environment/encoding data is allocated; the record owner retains the witness.
20
24
  */
@@ -24,12 +28,20 @@ export function projectRecordArgumentsMatch(
24
28
  ): boolean {
25
29
  if (record.compilerArguments === undefined) return false;
26
30
  try {
27
- return (
28
- record.compilerArguments.identity ===
31
+ if (
32
+ record.compilerArguments.identity !==
29
33
  (currentIdentity ??
30
34
  captureCompilerArguments(
31
35
  resolveCompilerEnvironment(record.compilerArguments.runExternalCode),
32
36
  ).identity)
37
+ )
38
+ return false;
39
+ return (
40
+ record.environmentInputs === undefined ||
41
+ environmentInputMismatch(
42
+ record.environmentInputs,
43
+ resolveCompilerEnvironment(record.compilerArguments.runExternalCode),
44
+ ) === undefined
33
45
  );
34
46
  } catch {
35
47
  return false;
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
 
3
3
  import { normalizeGraphInputObservation } from "../transform/envelope/normalizeGraphInputObservation";
4
+ import { isEnvironmentInputs } from "../transform/validation/isEnvironmentInputs";
4
5
  import type { TtscProjectRecord } from "./TtscProjectRecord";
5
6
 
6
7
  /**
@@ -51,7 +52,10 @@ export function readProjectRecordFile(
51
52
  !isMembership(candidate.membership) ||
52
53
  (candidate.compilerArguments !== undefined &&
53
54
  !isCompilerArguments(candidate.compilerArguments)) ||
54
- (candidate.dependencies !== undefined && !isStrings(candidate.dependencies))
55
+ (candidate.dependencies !== undefined &&
56
+ !isStrings(candidate.dependencies)) ||
57
+ (candidate.environmentInputs !== undefined &&
58
+ !isEnvironmentInputs(candidate.environmentInputs))
55
59
  ) {
56
60
  return undefined;
57
61
  }
@@ -62,6 +66,9 @@ export function readProjectRecordFile(
62
66
  ...(candidate.dependencies === undefined
63
67
  ? {}
64
68
  : { dependencies: candidate.dependencies }),
69
+ ...(candidate.environmentInputs === undefined
70
+ ? {}
71
+ : { environmentInputs: candidate.environmentInputs }),
65
72
  inputs: candidate.inputs,
66
73
  membership: candidate.membership,
67
74
  root: candidate.root,
@@ -1,6 +1,7 @@
1
1
  import { envelopeDerivation } from "../envelope/envelopeDerivation";
2
2
  import { isVolatileFile } from "../envelope/isVolatileFile";
3
3
  import type { TtscGenerationProof } from "../validation/TtscGenerationProof";
4
+ import { environmentInputMismatch } from "../validation/environmentInputMismatch";
4
5
  import { matchesCachedSource } from "../validation/matchesCachedSource";
5
6
  import type { TtscCachedProjectTransform } from "./TtscCachedProjectTransform";
6
7
  import type { TtscTransformCache } from "./TtscTransformCache";
@@ -12,11 +13,14 @@ import { evictGeneration } from "./evictGeneration";
12
13
  * The caller owns awaiting, Promise-ownership checks and required native
13
14
  * notification settling. A volatile or mismatching generation is evicted by
14
15
  * identity; if eviction exposed a sibling replacement, the caller retries it.
15
- * Otherwise the caller must capture a new generation. A serving decision does
16
- * not perform output selection or host notification, which remain with
17
- * delivery.
16
+ * Otherwise the caller must capture a new generation. A generation whose
17
+ * plugins read an environment variable that `environment`, the delivery's
18
+ * compiler environment snapshot, no longer gives the recorded value is
19
+ * mismatching on every path, the pass-shared first delivery included: no file
20
+ * proof can stand in for it. A serving decision does not perform output
21
+ * selection or host notification, which remain with delivery.
18
22
  *
19
- * @evidence contracts/common.md#principled-implementation The actual generation's volatility and recorded source proof decide serving; identity-guarded eviction then distinguishes a sibling's current replacement from an empty capture slot.
23
+ * @evidence contracts/common.md#principled-implementation The actual generation's volatility, recorded environment reads and recorded source proof decide serving; identity-guarded eviction then distinguishes a sibling's current replacement from an empty capture slot.
20
24
  * @evidence contracts/common.md#clear-and-simple-design One synchronous operation selects serve/retry/capture and owns mismatch eviction, while its production caller owns awaiting, notification settling, native capture and output delivery.
21
25
  * @evidence contracts/common.md#prohibited-implementation-shortcuts Decisions inspect the supplied actual generation and validators without fabricating a producer result, capability or success; no injectable compiler callback or test-only branch is introduced.
22
26
  * @evidence contracts/common.md#meaningful-documentation Native prose states the caller's awaited-Promise and settled-notification responsibilities and separates the decision from producer and delivery effects.
@@ -43,11 +47,22 @@ export function selectCachedGenerationAction(props: {
43
47
  generation: Promise<TtscCachedProjectTransform>;
44
48
  key: string;
45
49
  source: string;
50
+ /**
51
+ * The delivery's compiler environment snapshot, the one a recompile would run
52
+ * under, against which recorded environment reads are compared.
53
+ */
54
+ environment: NodeJS.ProcessEnv;
46
55
  /** False only for speculative source reads before an actual module delivery. */
47
56
  reportDivergence?: boolean;
48
57
  proof?: TtscGenerationProof.Transaction;
49
58
  }): "serve" | "retry" | "capture" {
50
59
  if (
60
+ environmentInputMismatch(
61
+ props.cached.result.type === "exception"
62
+ ? undefined
63
+ : props.cached.result.environmentInputs,
64
+ props.environment,
65
+ ) === undefined &&
51
66
  !isVolatileFile(envelopeDerivation(props.cached), {
52
67
  file: props.file,
53
68
  projectRoot: props.cached.projectRoot,
@@ -0,0 +1,38 @@
1
+ import type { TtscTransformFilesystemOperations } from "../filesystem/TtscTransformFilesystemOperations";
2
+
3
+ /**
4
+ * The devices on which an observing view saw its adapter-owned probe directory
5
+ * move both of its stamps when the probe was recreated, keyed by the operations
6
+ * object, as `filesystemClockReferences` keys their references.
7
+ *
8
+ * A directory's stamps move when an entry is created, removed or renamed in it,
9
+ * so while they hold still a directory still holds the entries a walk read
10
+ * (`IPluginSourceListing` from `ttsc/plugin-source`). That premise is offered
11
+ * as evidence only on a device where the view has seen it hold, and each
12
+ * refresh clears and re-establishes it with the reference it mints.
13
+ *
14
+ * @evidence contracts/common.md#principled-implementation A device enters only after the view observed a fresh entry change in owned storage move that directory's modification and change stamps; refresh clears the set before minting.
15
+ * @evidence contracts/common.md#clear-and-simple-design One WeakMap owns the sets by operation identity, beside the reference tables they qualify.
16
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts No device is assumed to keep directory stamps from its platform or filesystem name.
17
+ * @evidence contracts/common.md#meaningful-documentation Native prose states the premise, how a device is admitted and when it is cleared.
18
+ * @evidence contracts/portability.md#os-neutral-implementation Devices are the observing view's bigint identifiers; the premise is observed, not inferred from the OS.
19
+ * @evidence contracts/performance.md#efficient-algorithms One WeakMap lookup selects the set.
20
+ * @evidence contracts/performance.md#reuse-equivalent-work Every proof through one operations object shares its admitted devices until the next refresh.
21
+ * @evidence contracts/performance.md#bound-retention-and-release-resources Weak association does not retain the operations object, and a set holds at most the devices of its probes.
22
+ */
23
+ export function filesystemListingDevices(
24
+ /** Coherent observing view whose probe established the premise. */
25
+ filesystem: TtscTransformFilesystemOperations,
26
+ ): Set<bigint> {
27
+ let devices = FILESYSTEM_LISTING_DEVICES.get(filesystem);
28
+ if (devices === undefined) {
29
+ devices = new Set();
30
+ FILESYSTEM_LISTING_DEVICES.set(filesystem, devices);
31
+ }
32
+ return devices;
33
+ }
34
+
35
+ const FILESYSTEM_LISTING_DEVICES = new WeakMap<
36
+ TtscTransformFilesystemOperations,
37
+ Set<bigint>
38
+ >();
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
 
4
4
  import type { TtscTransformFilesystemOperations } from "../filesystem/TtscTransformFilesystemOperations";
5
5
  import { filesystemClockReferences } from "./filesystemClockReferences";
6
+ import { filesystemListingDevices } from "./filesystemListingDevices";
6
7
 
7
8
  /**
8
9
  * Replace every prior clock proof with one reference minted by a fresh write.
@@ -24,6 +25,12 @@ import { filesystemClockReferences } from "./filesystemClockReferences";
24
25
  * valid price for this optimization, so the cross-volume case degrades to more
25
26
  * reads instead.
26
27
  *
28
+ * Recreating the probe is also an entry change in the owned directory. When the
29
+ * view sees that directory's modification and change stamps both move, its
30
+ * device is admitted as one whose directory stamps witness their entries
31
+ * (`filesystemListingDevices`), so a plugin source listing can be replayed
32
+ * there instead of enumerated.
33
+ *
27
34
  * @evidence contracts/common.md#principled-implementation Clearing old references before a fresh owned probe write prevents previous or rolled-back stamps from certifying content; only observed regular-file metadata establishes a same-device reference.
28
35
  * @evidence contracts/common.md#clear-and-simple-design This operation mints and records one probe stamp; input metadata comparison remains in the separability consumer.
29
36
  * @evidence contracts/common.md#prohibited-implementation-shortcuts Failed writes, inaccessible probes, or another device cannot be replaced by Date.now or a historical maximum; actual content proof remains necessary.
@@ -31,10 +38,10 @@ import { filesystemClockReferences } from "./filesystemClockReferences";
31
38
  * @evidence contracts/portability.md#os-neutral-implementation OS-neutral clock proof uses native owned-path writes and the observing view's bigint device/time metadata, preserving cross-volume and unavailable-probe behavior without a platform clock assumption.
32
39
  * @evidence contracts/performance.md#efficient-algorithms
33
40
  * Clear the view's prior entries, then an available directory performs native
34
- * path joining, one write of process-counter text and one observed metadata
35
- * read. Costs include path/counter text and native I/O; a missing directory
36
- * skips I/O. Clearing/recording follows the current reference population,
37
- * not a scan of project inputs.
41
+ * path joining, one removal and one write of process-counter text and three
42
+ * observed metadata reads. Costs include path/counter text and native I/O; a
43
+ * missing directory skips I/O. Clearing/recording follows the current
44
+ * reference population, not a scan of project inputs.
38
45
  * @evidence contracts/performance.md#reuse-equivalent-work The existing probe path and shared per-view reference table are reused; only a newly minted stamp can authorize signature reuse.
39
46
  * @evidence contracts/performance.md#bound-retention-and-release-resources
40
47
  * Refresh clears history and retains at most one regular-file device stamp;
@@ -49,17 +56,48 @@ export function refreshFilesystemClockReference(
49
56
  filesystem: TtscTransformFilesystemOperations,
50
57
  ): void {
51
58
  const references = filesystemClockReferences(filesystem);
59
+ const listings = filesystemListingDevices(filesystem);
52
60
  references.clear();
61
+ listings.clear();
53
62
  if (referenceDirectory === undefined) return;
54
63
  try {
55
64
  const probe = path.join(referenceDirectory, "clock-reference");
65
+ // The probe is recreated rather than rewritten, so the owned directory sees
66
+ // an entry change whose effect on its stamps qualifies the device.
67
+ const directory = ():
68
+ | { dev: bigint; mtimeNs: bigint; ctimeNs: bigint }
69
+ | undefined => {
70
+ try {
71
+ return filesystem.lstat(referenceDirectory);
72
+ } catch {
73
+ // A view that cannot state the directory only forgoes the listing.
74
+ return undefined;
75
+ }
76
+ };
77
+ const parent = directory();
78
+ try {
79
+ fs.rmSync(probe, { force: true });
80
+ } catch {
81
+ // A probe that cannot be removed is rewritten in place, which moves no
82
+ // directory stamp, so the device is simply not admitted.
83
+ }
56
84
  fs.writeFileSync(probe, `${process.hrtime.bigint()}\n`);
57
85
  const stats = filesystem.lstat(probe);
58
86
  if (stats.isFile()) {
59
87
  references.set(stats.dev, stats.mtimeNs);
88
+ const moved = parent === undefined ? undefined : directory();
89
+ if (
90
+ parent !== undefined &&
91
+ moved !== undefined &&
92
+ moved.dev === stats.dev &&
93
+ moved.mtimeNs > parent.mtimeNs &&
94
+ moved.ctimeNs > parent.ctimeNs
95
+ )
96
+ listings.add(stats.dev);
60
97
  }
61
98
  } catch {
62
99
  // A failed refresh leaves no reference, so content comparison continues.
63
100
  references.clear();
101
+ listings.clear();
64
102
  }
65
103
  }
@@ -367,7 +367,11 @@ export async function captureTransformGeneration(props: {
367
367
  props.session,
368
368
  sharedCompileIdentity({ ...props, projectRoot }),
369
369
  state,
370
- { adopt: true, rejectedPublication: props.rejected },
370
+ {
371
+ adopt: true,
372
+ environment: compilerEnvironment,
373
+ rejectedPublication: props.rejected,
374
+ },
371
375
  )
372
376
  : undefined;
373
377
  if (claim?.kind === "compile") {
@@ -799,9 +803,12 @@ export async function captureTransformGeneration(props: {
799
803
  const graphFailures = compilerGraphInputProofFailures(cached);
800
804
  mergeGenerationProofFailures(failures, graphFailures);
801
805
  mergeGenerationProofFailures(failures, externalInputSnapshot.failures);
806
+ // Recorded environment reads must hold under the environment this worker
807
+ // compiles under; a publication recorded under another value is refuted.
802
808
  const universalInputCapture = captureUniversalHostInputValidation(
803
809
  cached,
804
810
  props.currentFile,
811
+ compilerEnvironment,
805
812
  );
806
813
  restrictNotificationCoverageToProvenInputs(
807
814
  hostInputTracker,
@@ -1,9 +1,13 @@
1
+ import type fs from "node:fs";
1
2
  import path from "node:path";
2
3
  import {
4
+ type IPluginSourceListing,
3
5
  pluginSourceFilesSignature,
4
6
  provenPluginSourceDigest,
5
7
  } from "ttsc/plugin-source";
6
8
 
9
+ import { filesystemClockReferences } from "../clock/filesystemClockReferences";
10
+ import { filesystemListingDevices } from "../clock/filesystemListingDevices";
7
11
  import { DEFAULT_FILESYSTEM_OPERATIONS } from "../filesystem/DEFAULT_FILESYSTEM_OPERATIONS";
8
12
  import type { TtscTransformFilesystemOperations } from "../filesystem/TtscTransformFilesystemOperations";
9
13
  import { inputMetadataEvidence } from "./inputMetadataEvidence";
@@ -18,6 +22,12 @@ import { inputMetadataEvidence } from "./inputMetadataEvidence";
18
22
  * separability again against the caller's refreshed device clock references; a
19
23
  * historical reference cannot establish safety after a clock rollback.
20
24
  *
25
+ * The population's listing is kept with the digest, so a later proof states the
26
+ * listed directories' stamps instead of enumerating them, on a device where
27
+ * this view saw directory stamps move with an entry change
28
+ * (`filesystemListingDevices`). A directory whose stamps moved, or that cannot
29
+ * be stated, sends the proof back to the walk.
30
+ *
21
31
  * Source enumeration and byte reads use ttsc's native filesystem. Injected
22
32
  * metadata must describe that same source tree; this adapter does not make
23
33
  * arbitrary foreign filesystems interchangeable. The process-wide map has no
@@ -39,7 +49,7 @@ import { inputMetadataEvidence } from "./inputMetadataEvidence";
39
49
  * @evidence contracts/common.md#prohibited-implementation-shortcuts A quiet tracker or equal timestamps alone cannot certify reuse; changed or unavailable evidence requires the real source digest rather than expected output or a compensating cache exception.
40
50
  * @evidence contracts/common.md#meaningful-documentation Native paragraphs explain population invalidation, before/after proof, fresh clock ordering, native-view assumptions and unbounded retained entries, with separated tags following documentation guidance.
41
51
  * @evidence contracts/portability.md#os-neutral-implementation OS-neutral native source paths use Node resolution and ttsc's native selector; injected metadata must observe those paths. A different filesystem view or path dialect is not supported by the native enumeration/read calls here.
42
- * @evidence contracts/performance.md#efficient-algorithms Reuse still enumerates and stats F files; a miss performs two metadata walks and one O(B) byte digest. Selection sorts its population, and temporary storage follows the file list and largest file buffer.
52
+ * @evidence contracts/performance.md#efficient-algorithms Reuse with a held listing stats D directories and F files without enumerating any; without one it enumerates D directories. A miss performs two metadata walks and one O(B) byte digest. Selection sorts its population, and temporary storage follows the file list and largest file buffer.
43
53
  * @evidence contracts/performance.md#reuse-equivalent-work All calls share DIGESTS by resolved directory spelling; current separable metadata must match the signature recorded around the producer read. The key does not partition filesystem owners, so sharing assumes one native source view. A miss of a caller naming its project takes the digest the load recorded in that project's plugin cache, across processes.
44
54
  * @evidence contracts/performance.md#bound-retention-and-release-resources DIGESTS is module-owned and retains one digest/signature per encountered key until failed stabilization deletes that key or the process ends; no historical-directory bound or explicit teardown currently exists.
45
55
  */
@@ -54,24 +64,36 @@ export function pluginSourceFilesDigest(
54
64
  * The filesystem must observe the same source tree the selector enumerates.
55
65
  */
56
66
  const evidence = (file: string) => inputMetadataEvidence(file, filesystem);
57
- const before = pluginSourceFilesSignature(key, evidence);
58
67
  const known = DIGESTS.get(key);
68
+ const before = pluginSourceFilesSignature(key, evidence, {
69
+ directory: (entry) => directoryEvidence(entry, filesystem),
70
+ known: known?.listing,
71
+ });
59
72
  if (
60
73
  before !== undefined &&
61
74
  before.separable &&
62
75
  known?.signature === before.signature
63
76
  ) {
77
+ // A walk that stated every directory leaves its listing for the next proof.
78
+ if (before.listing !== undefined && before.listing !== known.listing)
79
+ DIGESTS.set(key, { ...known, listing: before.listing });
64
80
  return known.digest;
65
81
  }
66
82
  const digest = provenPluginSourceDigest(key, projectRoot);
67
- const after = pluginSourceFilesSignature(key, evidence);
83
+ const after = pluginSourceFilesSignature(key, evidence, {
84
+ directory: (entry) => directoryEvidence(entry, filesystem),
85
+ });
68
86
  if (
69
87
  before !== undefined &&
70
88
  after !== undefined &&
71
89
  after.signature === before.signature &&
72
90
  after.separable
73
91
  ) {
74
- DIGESTS.set(key, { digest, signature: after.signature });
92
+ DIGESTS.set(key, {
93
+ digest,
94
+ signature: after.signature,
95
+ listing: after.listing,
96
+ });
75
97
  } else {
76
98
  DIGESTS.delete(key);
77
99
  }
@@ -82,4 +104,50 @@ export function pluginSourceFilesDigest(
82
104
  * The digests kept, by directory, each with the signature of the metadata it
83
105
  * was read under.
84
106
  */
85
- const DIGESTS = new Map<string, { digest: string; signature: string }>();
107
+ const DIGESTS = new Map<
108
+ string,
109
+ { digest: string; signature: string; listing?: IPluginSourceListing }
110
+ >();
111
+
112
+ /**
113
+ * A directory's metadata signature when its stamps witness its entries in this
114
+ * view: a device the view admitted (`filesystemListingDevices`), and both
115
+ * stamps strictly older than the view's reference on it.
116
+ */
117
+ function directoryEvidence(
118
+ directory: string,
119
+ filesystem: TtscTransformFilesystemOperations,
120
+ ): string | undefined {
121
+ const stated = (stats: fs.BigIntStats): string | undefined => {
122
+ const reference = filesystemClockReferences(filesystem).get(stats.dev);
123
+ return filesystemListingDevices(filesystem).has(stats.dev) &&
124
+ reference !== undefined &&
125
+ stats.mtimeNs < reference &&
126
+ stats.ctimeNs < reference
127
+ ? [
128
+ stats.dev,
129
+ stats.ino,
130
+ stats.mode,
131
+ stats.nlink,
132
+ stats.mtimeNs,
133
+ stats.ctimeNs,
134
+ ].join(":")
135
+ : undefined;
136
+ };
137
+ try {
138
+ const entry = filesystem.lstat(directory);
139
+ // A source root reached through a link is stated by the link and by the
140
+ // directory it names: a retarget moves the first, an entry change the
141
+ // second.
142
+ const target = entry.isSymbolicLink()
143
+ ? filesystem.statBigInt(directory)
144
+ : entry;
145
+ if (!target.isDirectory()) return undefined;
146
+ const own = stated(entry);
147
+ if (own === undefined || target === entry) return own;
148
+ const named = stated(target);
149
+ return named === undefined ? undefined : `${own}>${named}`;
150
+ } catch {
151
+ return undefined;
152
+ }
153
+ }
@@ -3,6 +3,8 @@ import fs from "node:fs";
3
3
  import path from "node:path";
4
4
 
5
5
  import { isZombieProcess } from "../utils/isZombieProcess";
6
+ import { environmentInputMismatch } from "../validation/environmentInputMismatch";
7
+ import { isEnvironmentInputs } from "../validation/isEnvironmentInputs";
6
8
  import type { TtscSharedCompileClaim } from "./TtscSharedCompileClaim";
7
9
  import type { TtscSharedCompilePublication } from "./TtscSharedCompilePublication";
8
10
 
@@ -66,6 +68,12 @@ const KEPT_STORE_BYTES = 256 * 1024 * 1024;
66
68
  * for independent adoption proof. The digest is computed from the already read
67
69
  * UTF-8 publication, without another filesystem query.
68
70
  *
71
+ * Neither key names the environment variables the plugins read: only the
72
+ * compile discovers them. A publication is therefore adoptable only while each
73
+ * variable its envelope recorded has the recorded value, or stays unset, in the
74
+ * adopter's `environment`. An ineligible publication is treated like a rejected
75
+ * one: the worker takes the lock and its compile replaces it.
76
+ *
69
77
  * Its place in the adapter's invalidation model, and the units beside it, are
70
78
  * mapped in the maintainer page
71
79
  * `website/src/content/docs/development/reference/unplugin-invalidation.mdx`.
@@ -74,6 +82,8 @@ const KEPT_STORE_BYTES = 256 * 1024 * 1024;
74
82
  * @param identity Caller-provided hex configuration digest used in store names.
75
83
  * @param state Caller-provided hex project-state digest used in store names.
76
84
  * @param options.adopt Whether an existing publication may be adopted.
85
+ * @param options.environment The adopter's compiler environment, which every
86
+ * recorded environment read of an adopted publication must still match.
77
87
  * @param options.rejectedPublication Digest of the exact previously refuted
78
88
  * payload; a replacement still requires the caller's full proof.
79
89
  * @evidence contracts/common.md#principled-implementation
@@ -142,7 +152,13 @@ export async function claimSharedCompile(
142
152
  store: string,
143
153
  identity: string,
144
154
  state: string,
145
- options: { adopt: boolean; rejectedPublication?: string },
155
+ options:
156
+ | { adopt: false }
157
+ | {
158
+ adopt: true;
159
+ environment: NodeJS.ProcessEnv;
160
+ rejectedPublication?: string;
161
+ },
146
162
  ): Promise<TtscSharedCompileClaim | undefined> {
147
163
  const name = `${identity}-${state}`;
148
164
  const publication = path.join(store, `${name}.json`);
@@ -154,7 +170,13 @@ export async function claimSharedCompile(
154
170
  const published = await readPublication(publication);
155
171
  if (
156
172
  published !== undefined &&
157
- published.fingerprint !== options.rejectedPublication
173
+ published.fingerprint !== options.rejectedPublication &&
174
+ environmentInputMismatch(
175
+ published.value.result.type === "exception"
176
+ ? undefined
177
+ : published.value.result.environmentInputs,
178
+ options.environment,
179
+ ) === undefined
158
180
  ) {
159
181
  await markUsed(publication);
160
182
  return {
@@ -173,7 +195,13 @@ export async function claimSharedCompile(
173
195
  const published = await readPublication(publication);
174
196
  if (
175
197
  published !== undefined &&
176
- published.fingerprint !== options.rejectedPublication
198
+ published.fingerprint !== options.rejectedPublication &&
199
+ environmentInputMismatch(
200
+ published.value.result.type === "exception"
201
+ ? undefined
202
+ : published.value.result.environmentInputs,
203
+ options.environment,
204
+ ) === undefined
177
205
  ) {
178
206
  claim.release();
179
207
  await markUsed(publication);
@@ -496,7 +524,7 @@ function isPublicationRecord(value: unknown): value is Record<string, unknown> {
496
524
  return typeof value === "object" && value !== null && !Array.isArray(value);
497
525
  }
498
526
 
499
- /** Check the envelope fields read directly before advisory index validation. */
527
+ /** Check consumed envelope fields, including the complete environment witness. */
500
528
  function isPublicationResult(value: unknown): boolean {
501
529
  if (
502
530
  !isPublicationRecord(value) ||
@@ -504,7 +532,9 @@ function isPublicationResult(value: unknown): boolean {
504
532
  !isPublicationRecord(value.typescript) ||
505
533
  !Object.values(value.typescript).every(
506
534
  (source) => typeof source === "string",
507
- )
535
+ ) ||
536
+ (value.environmentInputs !== undefined &&
537
+ !isEnvironmentInputs(value.environmentInputs))
508
538
  )
509
539
  return false;
510
540
  // Neither an explicit incomplete observer nor failed per-input authority can
@@ -274,6 +274,7 @@ async function runTransformTtsc(
274
274
  generation: transformed,
275
275
  key,
276
276
  source,
277
+ environment: compilerEnvironment,
277
278
  reportDivergence: !preparing,
278
279
  });
279
280
  if (action === "retry") {
@@ -1,61 +1 @@
1
- /**
2
- * Capture one invocation's environment and explicit content-mapper permission.
3
- *
4
- * Omission preserves inherited arguments. An explicit boolean appends its
5
- * upstream assignment after inherited arguments, keeping their order and cwd.
6
- * Invalid transport fails instead of discarding inherited choices.
7
- *
8
- * @evidence contracts/common.md#principled-implementation A detached environment and ordered JSON argv preserve inherited choices; an explicit boolean assignment has final precedence.
9
- * @evidence contracts/common.md#clear-and-simple-design Capture happens before cache selection; scratch routing derives a child copy afterward.
10
- * @evidence contracts/common.md#prohibited-implementation-shortcuts No process global or compiler behavior is replaced.
11
- * @evidence contracts/common.md#meaningful-documentation Native prose documents omission, precedence, cwd and invalid transport.
12
- * @evidence contracts/portability.md#os-neutral-implementation Windows environment names follow their native case-insensitive rule; POSIX names remain exact. JSON preserves argv without shell syntax.
13
- * @evidence contracts/performance.md#efficient-algorithms Copying visits environment keys; Windows normalization scans them once, and an explicit permission parses and serializes argument bytes once.
14
- * @evidenceExclude contracts/performance.md#reuse-equivalent-work Every invocation observes current inherited values; cache owners compare its snapshot.
15
- * @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The detached result transfers to its caller and acquires no handle or history.
16
- */
17
- export function resolveCompilerEnvironment(
18
- runExternalCode?: boolean,
19
- inherited: NodeJS.ProcessEnv = process.env,
20
- ): NodeJS.ProcessEnv {
21
- const env = { ...inherited };
22
- if (process.platform === "win32") {
23
- const selected = new Map<
24
- string,
25
- { key: string; value: string | undefined }
26
- >();
27
- for (const key of Object.keys(env)) {
28
- const name = key.toUpperCase();
29
- if (name === "TTSC_TSGO_ARGS" || name === "TTSC_TSGO_ARGS_CWD") {
30
- const prior = selected.get(name);
31
- if (prior === undefined || key < prior.key)
32
- selected.set(name, { key, value: env[key] });
33
- delete env[key];
34
- }
35
- }
36
- for (const [name, value] of selected) env[name] = value.value;
37
- }
38
- // Own absent channels too: a later process.env edit must not become a new
39
- // inherited argument between this cache lookup and the compiler spawn.
40
- env.TTSC_TSGO_ARGS = env.TTSC_TSGO_ARGS;
41
- env.TTSC_TSGO_ARGS_CWD = env.TTSC_TSGO_ARGS_CWD;
42
- if (runExternalCode === undefined) return env;
43
- if (typeof runExternalCode !== "boolean")
44
- throw new TypeError("@ttsc/unplugin: runExternalCode must be a boolean");
45
- // Go's environment transport trims Unicode White_Space, which excludes BOM.
46
- const raw = env.TTSC_TSGO_ARGS?.replace(
47
- /^\p{White_Space}+|\p{White_Space}+$/gu,
48
- "",
49
- );
50
- const args: unknown = raw === undefined || raw === "" ? [] : JSON.parse(raw);
51
- if (!Array.isArray(args) || args.some((value) => typeof value !== "string"))
52
- throw new TypeError(
53
- "@ttsc/unplugin: TTSC_TSGO_ARGS must be a JSON string array",
54
- );
55
- env.TTSC_TSGO_ARGS = JSON.stringify([
56
- ...args,
57
- "--runExternalCode",
58
- String(runExternalCode),
59
- ]);
60
- return env;
61
- }
1
+ export { resolveCompilerEnvironment } from "ttsc";