ttsc 0.34.3 → 0.35.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 (58) hide show
  1. package/lib/compiler/internal/build/BuildExecution.d.ts +26 -0
  2. package/lib/compiler/internal/build/BuildExecution.js +13 -3
  3. package/lib/compiler/internal/build/BuildExecution.js.map +1 -1
  4. package/lib/compiler/internal/build/RunBuildOptions.d.ts +2 -0
  5. package/lib/compiler/internal/build/RuntimeBuildCache.d.ts +47 -0
  6. package/lib/compiler/internal/build/RuntimeBuildCache.js +235 -0
  7. package/lib/compiler/internal/build/RuntimeBuildCache.js.map +1 -0
  8. package/lib/compiler/internal/build/RuntimeBuildInputs.d.ts +44 -0
  9. package/lib/compiler/internal/build/RuntimeBuildInputs.js +282 -0
  10. package/lib/compiler/internal/build/RuntimeBuildInputs.js.map +1 -0
  11. package/lib/compiler/internal/build/RuntimeInputProof.d.ts +50 -0
  12. package/lib/compiler/internal/build/RuntimeInputProof.js +315 -0
  13. package/lib/compiler/internal/build/RuntimeInputProof.js.map +1 -0
  14. package/lib/compiler/internal/build/TsgoArguments.d.ts +5 -4
  15. package/lib/compiler/internal/build/TsgoArguments.js +11 -5
  16. package/lib/compiler/internal/build/TsgoArguments.js.map +1 -1
  17. package/lib/compiler/internal/build/runBuild.d.ts +3 -3
  18. package/lib/compiler/internal/build/runBuild.js +17 -4
  19. package/lib/compiler/internal/build/runBuild.js.map +1 -1
  20. package/lib/compiler/internal/runNativeCheckWithObservations.d.ts +18 -14
  21. package/lib/compiler/internal/runNativeCheckWithObservations.js +42 -18
  22. package/lib/compiler/internal/runNativeCheckWithObservations.js.map +1 -1
  23. package/lib/flags/FLAG_SCHEMA.js +7 -0
  24. package/lib/flags/FLAG_SCHEMA.js.map +1 -1
  25. package/lib/launcher/internal/parseTtsxCLI.d.ts +1 -0
  26. package/lib/launcher/internal/parseTtsxCLI.js +1 -0
  27. package/lib/launcher/internal/parseTtsxCLI.js.map +1 -1
  28. package/lib/launcher/internal/prepareExecution.d.ts +2 -0
  29. package/lib/launcher/internal/prepareExecution.js +6 -0
  30. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  31. package/lib/launcher/internal/runTtsx.js +5 -0
  32. package/lib/launcher/internal/runTtsx.js.map +1 -1
  33. package/lib/launcher/internal/runtime/installRuntimeHooks.js +7 -0
  34. package/lib/launcher/internal/runtime/installRuntimeHooks.js.map +1 -1
  35. package/lib/plugin/internal/load/loadProjectPlugins.js +1 -0
  36. package/lib/plugin/internal/load/loadProjectPlugins.js.map +1 -1
  37. package/lib/plugin/internal/source/SourceBuildCacheLayout.d.ts +2 -0
  38. package/lib/plugin/internal/source/SourceBuildCacheLayout.js +3 -0
  39. package/lib/plugin/internal/source/SourceBuildCacheLayout.js.map +1 -1
  40. package/lib/structures/ITtscPluginCapabilities.d.ts +13 -2
  41. package/package.json +8 -8
  42. package/src/compiler/internal/build/BuildExecution.ts +32 -16
  43. package/src/compiler/internal/build/RunBuildOptions.ts +3 -0
  44. package/src/compiler/internal/build/RuntimeBuildCache.ts +252 -0
  45. package/src/compiler/internal/build/RuntimeBuildInputs.ts +349 -0
  46. package/src/compiler/internal/build/RuntimeInputProof.ts +346 -0
  47. package/src/compiler/internal/build/TsgoArguments.ts +11 -5
  48. package/src/compiler/internal/build/runBuild.ts +20 -5
  49. package/src/compiler/internal/runNativeCheckWithObservations.ts +41 -18
  50. package/src/flags/FLAG_SCHEMA.ts +7 -0
  51. package/src/launcher/internal/parseTtsxCLI.ts +1 -0
  52. package/src/launcher/internal/prepareExecution.ts +13 -0
  53. package/src/launcher/internal/runTtsx.ts +5 -0
  54. package/src/launcher/internal/runtime/installRuntimeHooks.ts +11 -0
  55. package/src/plugin/internal/load/loadProjectPlugins.ts +1 -0
  56. package/src/plugin/internal/source/SourceBuildCacheLayout.ts +4 -0
  57. package/src/structures/ITtscPluginCapabilities.ts +14 -2
  58. package/utility/host.go +22 -1
@@ -22,7 +22,9 @@ import { createCanonicalTempDirectory } from "../../../internal/createCanonicalT
22
22
  import { runtimeExecutableIdentity } from "../../../internal/runtimeExecutableIdentity";
23
23
  import { moduleResolutionBaseSelects } from "../../../plugin/internal/load/moduleResolutionBaseSelects";
24
24
  import { PluginContentIdentities } from "../../../plugin/internal/source/PluginContentIdentities";
25
+ import { SourceBuildCacheLayout } from "../../../plugin/internal/source/SourceBuildCacheLayout";
25
26
  import { recordCacheFileUse } from "../../../plugin/internal/source/recordCacheFileUse";
27
+ import { resolveSourceBuildCachePaths } from "../../../plugin/internal/source/resolveSourceBuildCachePaths";
26
28
  import { buildSingleRootProject } from "../buildSingleRootProject";
27
29
  import { inlineServedSourceMap } from "../inlineServedSourceMap";
28
30
  import { runtimeCompilerArgs } from "../runtimeCompilerArgs";
@@ -2192,6 +2194,15 @@ function buildDependency(
2192
2194
  fs.mkdirSync(emitDir, { recursive: true });
2193
2195
  const result = runBuild({
2194
2196
  cwd: project.root,
2197
+ runtimeCacheDir:
2198
+ process.env.TTSX_DISABLE_CACHE === "1" ||
2199
+ process.env.TTSC_PLUGIN_DESCRIPTOR_LOAD === "1"
2200
+ ? undefined
2201
+ : path.join(
2202
+ runtimeRecordStore()?.root ??
2203
+ resolveSourceBuildCachePaths(project.root).root,
2204
+ SourceBuildCacheLayout.RUNTIME_BUILD_CACHE_DIRNAME,
2205
+ ),
2195
2206
  forceEmitProvenance: true,
2196
2207
  // Emit-only means diagnostics never withhold the emit, so a dependency's
2197
2208
  // own `noEmitOnError` is switched off: honoured, it would turn any
@@ -824,6 +824,7 @@ export namespace loadProjectPlugins {
824
824
  ...record.capabilities,
825
825
  compilerArgsCwd: true,
826
826
  emitProvenance: true,
827
+ emitObservations: true,
827
828
  }
828
829
  : record.capabilities,
829
830
  config: record.config,
@@ -80,6 +80,9 @@ export namespace SourceBuildCacheLayout {
80
80
  /** Directory of the lowered orphan sources inside the cache root. */
81
81
  export const ORPHAN_CACHE_DIRNAME = "ttsx-orphan";
82
82
 
83
+ /** Checksummed completed runtime project emits, independent of run lifetime. */
84
+ export const RUNTIME_BUILD_CACHE_DIRNAME = "runtime-builds";
85
+
83
86
  /**
84
87
  * The parts of the cache root whose entries are single files, each collected
85
88
  * by `pruneCacheFileRoot` and removed by `ttsc clean`.
@@ -90,6 +93,7 @@ export namespace SourceBuildCacheLayout {
90
93
  IDENTITY_CACHE_DIRNAME,
91
94
  ANSWER_CACHE_DIRNAME,
92
95
  ORPHAN_CACHE_DIRNAME,
96
+ RUNTIME_BUILD_CACHE_DIRNAME,
93
97
  ];
94
98
 
95
99
  /**
@@ -83,13 +83,25 @@ export interface ITtscPluginCapabilities {
83
83
  * from an output filename or configuration prediction.
84
84
  *
85
85
  * When omitted, ttsc does not pass the option to a strict third-party host. A
86
- * runtime operation requiring verified emit provenance must then report that
87
- * the selected host does not support it.
86
+ * runtime operation then uses the existing externally observed provenance
87
+ * adapter, whose incomplete proof remains visible to the runtime consumer.
88
88
  *
89
89
  * @default false
90
90
  */
91
91
  emitProvenance?: true;
92
92
 
93
+ /**
94
+ * Whether build accepts `--emit-observations-json=<absolute private path>`
95
+ * and publishes its generation's compiler and native input observations.
96
+ * Missing support keeps runtime emits fresh rather than assuming reusable
97
+ * input completeness. This protocol is independent of output ownership. Hosts
98
+ * publish the same observation envelope as checkObservations, including
99
+ * failures, before releasing their Program.
100
+ *
101
+ * @default false
102
+ */
103
+ emitObservations?: true;
104
+
93
105
  /**
94
106
  * Whether the sidecar accepts ttsc's `--project-context-json` identity
95
107
  * protocol. The payload keeps lexical selection paths, physical Program
package/utility/host.go CHANGED
@@ -40,6 +40,9 @@ type hostOptions struct {
40
40
  // checkObservationsJSON is the caller-owned absolute check input result path.
41
41
  checkObservationsJSON string
42
42
 
43
+ // emitObservationsJSON is the caller-owned absolute build input result path.
44
+ emitObservationsJSON string
45
+
43
46
  // observationsIncomplete points to the resident host's committed generation
44
47
  // state. It is nil for non-resident calls and updated only after success.
45
48
  observationsIncomplete *bool
@@ -201,6 +204,10 @@ func RunBuild(args []string) int {
201
204
  // diagnostics. Analysis-only success writes an empty map. The original build
202
205
  // status remains authoritative; absent or invalid metadata supplies no ownership
203
206
  // proof. Callers own the artifact's removal.
207
+ // A separately negotiated absolute emit-observations path receives this same
208
+ // Program's compiler and native input witnesses before its checker lease closes,
209
+ // including failing loaded builds. Unavailable optional observations withhold
210
+ // reuse without changing the build status. They supply no authority by themselves.
204
211
  // Program.Close returns its checker lease; it does not remove emitted files or
205
212
  // private metadata. Summary and diagnostic stream writes are best-effort here,
206
213
  // so a zero status does not certify delivery to the supplied io.Writer values.
@@ -211,7 +218,7 @@ func RunBuild(args []string) int {
211
218
  // @evidence contracts/common.md#meaningful-documentation Native paragraphs identify stream ownership, failure statuses, private metadata admission and caller artifact removal following the documentation skill.
212
219
  // @evidence contracts/portability.md#os-neutral-implementation Driver loading and DefaultWriteFile own native paths and filesystem APIs; output streams are not replaced globally.
213
220
  // @evidence contracts/performance.md#efficient-algorithms Admission and loading include argument/plugin-manifest parsing, native project and diagnostic work. Emission dispatches linked AST transforms through the driver, which owns native generation and one authored-coordinate correction. The final writer indexes compiler carrier/map paths and shifts generated map coordinates only when it inserts missing preamble text, including JSON/base64/VLQ and output-byte work. Optional provenance adds output-path candidate collection, successful-write bookkeeping, source-proof checks, owner sorting and JSON/file publication; costs depend on source/graph, output and metadata bytes rather than only the number of emit calls.
214
- // @evidence contracts/performance.md#reuse-equivalent-work The same loaded compiler generation validates and emits; linked program hooks remain latched rather than independently reexecuted for output files.
221
+ // @evidence contracts/performance.md#reuse-equivalent-work The same loaded compiler generation validates, emits and optionally publishes its input witnesses; linked program hooks remain latched rather than independently reexecuted for output files. Completed-generation reuse belongs to the caller.
215
222
  // @evidence contracts/performance.md#bound-retention-and-release-resources Successful loading transfers one Program checker lease to a deferred Close on analysis-only, normal and failure returns. The final writer retains output-path decisions and maps awaiting their carrier without a byte cap, releases pending map entries as their carrier arrives, and reports unfinished pairs at emit completion. Facade graphs, provenance maps, writer closures and serialization buffers lose local ownership when the invocation ends; Close does not destroy all program memory, supplied-stream state or emitted disk artifacts. Callers own stream lifetime and metadata/output removal, with no invocation-enforced byte cap.
216
223
  func RunBuildWithIO(args []string, stdout, stderr io.Writer) int {
217
224
  opts, ok := parseHostOptions("build", args, stdout, stderr)
@@ -224,6 +231,13 @@ func RunBuildWithIO(args []string, stdout, stderr io.Writer) int {
224
231
  return 2
225
232
  }
226
233
  defer prog.Close()
234
+ defer func() {
235
+ if opts.emitObservationsJSON != "" {
236
+ if err := driver.WriteCheckObservationsJSON(opts.emitObservationsJSON, prog); err != nil {
237
+ fmt.Fprintf(opts.stderr, "ttsc utility: emit observations write failed: %v\n", err)
238
+ }
239
+ }
240
+ }()
227
241
  driver.WritePrettyDiagnostics(opts.stderr, diags, opts.cwd)
228
242
  if opts.noEmit {
229
243
  if len(diags) != 0 {
@@ -446,8 +460,10 @@ func parseHostOptions(command string, args []string, stdout, stderr io.Writer) (
446
460
  tsgoArgsRaw := fs.String("tsgo-args", "", "JSON array of forwarded tsgo CLI flags")
447
461
  provenanceJSON := ""
448
462
  checkObservationsJSON := ""
463
+ emitObservationsJSON := ""
449
464
  if command == "build" {
450
465
  fs.StringVar(&provenanceJSON, "emit-provenance-json", "", "private absolute emit provenance result path")
466
+ fs.StringVar(&emitObservationsJSON, "emit-observations-json", "", "private absolute build input result path")
451
467
  }
452
468
  if command == "check" {
453
469
  fs.StringVar(&checkObservationsJSON, "check-observations-json", "", "private absolute check input result path")
@@ -463,6 +479,10 @@ func parseHostOptions(command string, args []string, stdout, stderr io.Writer) (
463
479
  fmt.Fprintln(stderr, "ttsc utility: check observations path must be absolute")
464
480
  return hostOptions{}, false
465
481
  }
482
+ if emitObservationsJSON != "" && !filepath.IsAbs(emitObservationsJSON) {
483
+ fmt.Fprintln(stderr, "ttsc utility: emit observations path must be absolute")
484
+ return hostOptions{}, false
485
+ }
466
486
  var tsgoArgs []string
467
487
  if *tsgoArgsRaw != "" {
468
488
  if err := json.Unmarshal([]byte(*tsgoArgsRaw), &tsgoArgs); err != nil {
@@ -507,6 +527,7 @@ func parseHostOptions(command string, args []string, stdout, stderr io.Writer) (
507
527
  stderr: stderr,
508
528
  provenanceJSON: provenanceJSON,
509
529
  checkObservationsJSON: checkObservationsJSON,
530
+ emitObservationsJSON: emitObservationsJSON,
510
531
  }, true
511
532
  }
512
533