ttsc 0.18.3 → 0.18.4

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 (50) hide show
  1. package/cmd/ttscgraph/main.go +18 -12
  2. package/cmd/ttscgraph/run_help_version_and_bad_flags_exit_codes_test.go +23 -5
  3. package/cmd/ttscgraph/serve.go +863 -0
  4. package/cmd/ttscgraph/serve_protocol_rejects_invalid_request_line_test.go +43 -0
  5. package/cmd/ttscgraph/serve_protocol_retries_session_creation_test.go +83 -0
  6. package/cmd/ttscgraph/serve_protocol_reuses_session_test.go +35 -0
  7. package/cmd/ttscgraph/serve_session_applies_source_edit_incrementally_test.go +55 -0
  8. package/cmd/ttscgraph/serve_session_fails_closed_on_deleted_config_test.go +68 -0
  9. package/cmd/ttscgraph/serve_session_fails_closed_on_invalid_config_test.go +50 -0
  10. package/cmd/ttscgraph/serve_session_keeps_missing_literal_root_unchanged_test.go +46 -0
  11. package/cmd/ttscgraph/serve_session_rebuilds_import_graph_change_test.go +60 -0
  12. package/cmd/ttscgraph/serve_session_reloads_created_literal_root_test.go +44 -0
  13. package/cmd/ttscgraph/serve_session_reloads_extended_config_change_test.go +45 -0
  14. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_conditional_export_test.go +60 -0
  15. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_config_types_test.go +44 -0
  16. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_excluded_import_test.go +62 -0
  17. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_package_export_test.go +46 -0
  18. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_package_import_test.go +46 -0
  19. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_path_alias_test.go +47 -0
  20. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_reference_path_test.go +42 -0
  21. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_root_dirs_target_test.go +46 -0
  22. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_type_reference_test.go +42 -0
  23. package/cmd/ttscgraph/serve_session_reloads_root_file_set_test.go +52 -0
  24. package/cmd/ttscgraph/serve_session_reloads_source_deleted_during_load_test.go +60 -0
  25. package/cmd/ttscgraph/serve_session_reloads_transitive_project_reference_test.go +55 -0
  26. package/cmd/ttscgraph/serve_session_reloads_when_program_plugin_linked_test.go +53 -0
  27. package/cmd/ttscgraph/serve_session_reuses_unchanged_preamble_source_test.go +45 -0
  28. package/cmd/ttscgraph/serve_session_reuses_unchanged_snapshot_test.go +52 -0
  29. package/cmd/ttscgraph/serve_session_revisits_source_edited_during_load_test.go +61 -0
  30. package/cmd/ttscgraph/serve_session_tolerates_os_invalid_resolution_candidate_test.go +56 -0
  31. package/cmd/ttscgraph/serve_session_tracks_all_module_specifier_forms_test.go +41 -0
  32. package/cmd/ttscgraph/serve_session_tracks_diamond_project_references_once_test.go +61 -0
  33. package/driver/plugins.go +21 -5
  34. package/driver/program.go +18 -2
  35. package/driver/session.go +11 -3
  36. package/lib/TtscCompiler.d.ts +3 -2
  37. package/lib/TtscCompiler.js +6 -14
  38. package/lib/TtscCompiler.js.map +1 -1
  39. package/lib/compiler/internal/compileProjectInMemory.js +14 -1
  40. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  41. package/lib/compiler/internal/runBuild.d.ts +7 -0
  42. package/lib/compiler/internal/runBuild.js +176 -16
  43. package/lib/compiler/internal/runBuild.js.map +1 -1
  44. package/lib/structures/ITtscCompilerResult.d.ts +8 -5
  45. package/package.json +8 -8
  46. package/shim/printer/shim.go +22 -4
  47. package/src/TtscCompiler.ts +4 -16
  48. package/src/compiler/internal/compileProjectInMemory.ts +17 -1
  49. package/src/compiler/internal/runBuild.ts +237 -23
  50. package/src/structures/ITtscCompilerResult.ts +8 -5
@@ -1,9 +1,7 @@
1
- // Command ttscgraph builds the checker-resolved code graph for a project and
2
- // prints it as JSON (`ttscgraph dump`). It is the native data provider for
3
- // @ttsc/graph: the JavaScript launcher runs `ttscgraph dump` once, then serves
4
- // the Model Context Protocol from the in-memory graph itself. The MCP server,
5
- // its tools, and their schemas live in @ttsc/graph (TypeScript); nothing here
6
- // answers tool calls.
1
+ // Command ttscgraph builds the checker-resolved code graph for a project. The
2
+ // one-shot `dump` command prints JSON; the internal `serve` command keeps an
3
+ // incremental compiler session resident for @ttsc/graph. MCP tools and schemas
4
+ // remain in the TypeScript package.
7
5
  package main
8
6
 
9
7
  import (
@@ -35,9 +33,9 @@ func main() {
35
33
  os.Exit(run(os.Args[1:]))
36
34
  }
37
35
 
38
- // run dispatches the top-level command and returns an exit code. ttscgraph is
39
- // dump-only; anything that is not help/version/dump prints usage and exits 2,
40
- // since serving MCP is the launcher's job.
36
+ // run dispatches the top-level command and returns an exit code. Anything that
37
+ // is not help, version, dump, or the internal serve protocol prints usage and
38
+ // exits 2; serving MCP itself remains the launcher's job.
41
39
  func run(args []string) int {
42
40
  if len(args) > 0 {
43
41
  switch args[0] {
@@ -49,6 +47,8 @@ func run(args []string) int {
49
47
  return 0
50
48
  case "dump":
51
49
  return runDump(args[1:])
50
+ case "serve":
51
+ return runServe(args[1:])
52
52
  }
53
53
  }
54
54
  printHelp(stderr)
@@ -72,12 +72,12 @@ func printHelp(w io.Writer) {
72
72
  fmt.Fprintln(w, strings.TrimSpace(`
73
73
  ttscgraph — checker-resolved code graph for ttsc.
74
74
 
75
- Builds the project's code graph and prints it as JSON. The @ttsc/graph launcher
76
- runs this and serves the Model Context Protocol from the result; the MCP tools
77
- live in @ttsc/graph, not here.
75
+ Builds the project's code graph as JSON or keeps an incremental compiler session
76
+ for the @ttsc/graph launcher. The MCP tools live in @ttsc/graph, not here.
78
77
 
79
78
  Usage:
80
79
  ttscgraph dump [--cwd <dir>] [--tsconfig <path>] [--pretty] > graph.json
80
+ ttscgraph serve [--cwd <dir>] [--tsconfig <path>]
81
81
  ttscgraph --version
82
82
  ttscgraph --help
83
83
 
@@ -87,5 +87,11 @@ Dump:
87
87
  --cwd <dir> Project root (defaults to the process working directory).
88
88
  --tsconfig <path> Project tsconfig path (default: tsconfig.json).
89
89
  --pretty Indent the JSON output.
90
+
91
+ Serve:
92
+ serve Internal newline-delimited snapshot protocol used by
93
+ @ttsc/graph. Keeps the compiler Program resident, applies
94
+ source edits incrementally, and reloads on structural
95
+ project changes.
90
96
  `))
91
97
  }
@@ -8,9 +8,10 @@ import (
8
8
  )
9
9
 
10
10
  // TestRunHelpVersionAndBadFlagsExitCodes verifies the top-level run dispatcher
11
- // returns the documented exit codes for the dump-only command surface: help and
12
- // version short-circuit to 0, an unknown command prints usage and exits 2, and a
13
- // dump that cannot resolve its working directory exits 2 with an explanation.
11
+ // returns the documented exit codes for the command surface: help and version
12
+ // short-circuit to 0, an unknown command prints usage and exits 2, and dump or
13
+ // serve invocations that cannot parse flags or resolve their working directory
14
+ // exit 2 with an explanation.
14
15
  //
15
16
  // These are the non-load paths a user hits with a typo or `--help`; each must
16
17
  // resolve to a code without building a Program. The getwd seam stands in for an
@@ -19,8 +20,8 @@ import (
19
20
  //
20
21
  // 1. run --help and run --version exit 0, printing the command name / version.
21
22
  // 2. run --bogus (unknown command) exits 2 and prints usage.
22
- // 3. run dump --nope exits 2 (dump flag parse failure).
23
- // 4. With getwd forced to fail, run dump exits 2 and explains why.
23
+ // 3. run dump --nope and run serve --nope exit 2 (flag parse failure).
24
+ // 4. With getwd forced to fail, run dump and run serve exit 2 and explain why.
24
25
  func TestRunHelpVersionAndBadFlagsExitCodes(t *testing.T) {
25
26
  oldStdout, oldStderr, oldGetwd := stdout, stderr, getwd
26
27
  defer func() { stdout, stderr, getwd = oldStdout, oldStderr, oldGetwd }()
@@ -62,6 +63,13 @@ func TestRunHelpVersionAndBadFlagsExitCodes(t *testing.T) {
62
63
  t.Fatalf("run dump --nope exit = %d, want 2", code)
63
64
  }
64
65
 
66
+ // An unknown serve flag is an invalid invocation: serve's flag.Parse fails -> 2.
67
+ var serveFlagErr bytes.Buffer
68
+ stderr = &serveFlagErr
69
+ if code := run([]string{"serve", "--nope"}); code != 2 {
70
+ t.Fatalf("run serve --nope exit = %d, want 2", code)
71
+ }
72
+
65
73
  // A getwd failure (no --cwd given) is an invalid invocation -> 2, explained.
66
74
  var wdErr bytes.Buffer
67
75
  stderr = &wdErr
@@ -72,4 +80,14 @@ func TestRunHelpVersionAndBadFlagsExitCodes(t *testing.T) {
72
80
  if !strings.Contains(wdErr.String(), "could not resolve working directory") {
73
81
  t.Fatalf("getwd failure did not explain itself:\n%s", wdErr.String())
74
82
  }
83
+
84
+ // serve resolves the working directory the same way before touching stdin.
85
+ var serveWdErr bytes.Buffer
86
+ stderr = &serveWdErr
87
+ if code := run([]string{"serve"}); code != 2 {
88
+ t.Fatalf("run serve with getwd failure exit = %d, want 2", code)
89
+ }
90
+ if !strings.Contains(serveWdErr.String(), "could not resolve working directory") {
91
+ t.Fatalf("serve getwd failure did not explain itself:\n%s", serveWdErr.String())
92
+ }
75
93
  }