@tracecode/harness 0.16.2 → 0.16.3

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 (42) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/{browser-runtime-provider-45ND6W3K.js → browser-runtime-provider-C53ZJH3D.js} +4 -4
  3. package/dist/{chunk-HK62URW2.js → chunk-53ROKKGU.js} +2 -2
  4. package/dist/{chunk-J54PE2JS.js → chunk-6SWX35P2.js} +2 -2
  5. package/dist/{chunk-DGXNINFR.js → chunk-BXUGUGWL.js} +9 -9
  6. package/dist/{chunk-K4424WAS.js → chunk-DI7WIHES.js} +3 -3
  7. package/dist/{chunk-5SU2JQGI.js → chunk-TXDHVV6B.js} +16 -14
  8. package/dist/{chunk-MJOC6WVB.js → chunk-YID2AAYD.js} +2 -2
  9. package/dist/cli.js +0 -0
  10. package/dist/core.cjs +8 -8
  11. package/dist/core.d.cts +2 -2
  12. package/dist/core.d.ts +2 -2
  13. package/dist/core.js +1 -1
  14. package/dist/{cpp-worker-client-I6CPM7TA.js → cpp-worker-client-FLJ2YLSW.js} +3 -3
  15. package/dist/{csharp-worker-client-X7R4VXF4.js → csharp-worker-client-S4U6MCVF.js} +3 -3
  16. package/dist/internal/tracekernel-workspace.cjs +171 -31
  17. package/dist/internal/tracekernel-workspace.d.cts +8 -2
  18. package/dist/internal/tracekernel-workspace.d.ts +8 -2
  19. package/dist/internal/tracekernel-workspace.js +164 -24
  20. package/dist/{java-project-MLWER3CQ.js → java-project-GK6MHT3I.js} +2 -2
  21. package/dist/{java-project-client-R7CKC72F.js → java-project-client-PEQKFTH6.js} +11 -2
  22. package/dist/judge.cjs +186 -35
  23. package/dist/judge.d.cts +1 -1
  24. package/dist/judge.d.ts +1 -1
  25. package/dist/judge.js +6 -6
  26. package/dist/{project-browser-UALCR5KR.js → project-browser-3I5FVB5N.js} +2 -2
  27. package/dist/{project-browser-EIQ2FOXP.js → project-browser-ADXGG5RZ.js} +2 -2
  28. package/dist/{project-browser-JR2WG7DG.js → project-browser-B5T7WJWP.js} +2 -2
  29. package/dist/{project-browser-V3W4CQAQ.js → project-browser-JXJ74RDZ.js} +2 -2
  30. package/dist/{project-browser-T3EIQCMD.js → project-browser-TDL4LMJJ.js} +2 -2
  31. package/dist/{python-worker-client-MRWQTXOF.js → python-worker-client-2RF6IYIN.js} +3 -3
  32. package/dist/{runtime-environment-D7mZm8SA.d.cts → runtime-environment-BO5I1fAC.d.cts} +5 -0
  33. package/dist/{runtime-environment-Q60S0pUa.d.ts → runtime-environment-Dfg6ZoCj.d.ts} +5 -0
  34. package/dist/{runtime-open-source-info-BQtIRJ9F.d.cts → runtime-open-source-info-CaBpNicy.d.cts} +4 -2
  35. package/dist/{runtime-open-source-info-FkIxlAcm.d.ts → runtime-open-source-info-D0OJc4zH.d.ts} +4 -2
  36. package/dist/tracekernel.cjs +351 -60
  37. package/dist/tracekernel.d.cts +4 -4
  38. package/dist/tracekernel.d.ts +4 -4
  39. package/dist/tracekernel.js +166 -26
  40. package/package.json +44 -32
  41. package/runtime-assets.lock.json +7 -7
  42. package/workers/javascript/javascript-project-worker.js +7 -7
@@ -13521,7 +13521,7 @@ var init_package = __esm({
13521
13521
  "package.json"() {
13522
13522
  package_default = {
13523
13523
  name: "@tracecode/harness",
13524
- version: "0.16.2",
13524
+ version: "0.16.3",
13525
13525
  license: "AGPL-3.0-only",
13526
13526
  homepage: "https://tracecode.app",
13527
13527
  repository: {
@@ -13791,7 +13791,7 @@ var init_runtime_language_info_data = __esm({
13791
13791
  "versionLabel": "Python 3.13.2",
13792
13792
  "executionPlatform": {
13793
13793
  "name": "TraceKernel",
13794
- "version": "0.16.2"
13794
+ "version": "0.16.3"
13795
13795
  },
13796
13796
  "description": "Python 3.13.2 runs in TraceKernel's isolated Python runtime.\n\nCommon algorithm helpers are imported automatically, including array, bisect, collections, functools, heapq, itertools. Other standard-library modules can be imported normally.\n\nOptional third-party packages are consumer-owned runtime assets and are available only when declared by the TraceKernel runtime manifest.",
13797
13797
  "runtime": {
@@ -13818,7 +13818,7 @@ var init_runtime_language_info_data = __esm({
13818
13818
  "versionLabel": "JavaScript (ECMAScript 2023)",
13819
13819
  "executionPlatform": {
13820
13820
  "name": "TraceKernel",
13821
- "version": "0.16.2"
13821
+ "version": "0.16.3"
13822
13822
  },
13823
13823
  "runtime": {
13824
13824
  "name": "TraceKernel JavaScript runtime",
@@ -13910,7 +13910,7 @@ Binary Search Tree, Trie, and Graph are bundled too, but are not exposed globall
13910
13910
  "versionLabel": "TypeScript 5.9.3",
13911
13911
  "executionPlatform": {
13912
13912
  "name": "TraceKernel",
13913
- "version": "0.16.2"
13913
+ "version": "0.16.3"
13914
13914
  },
13915
13915
  "description": `TypeScript 5.9.3 is compiled with the TypeScript compiler and executed by TraceKernel's JavaScript runtime.
13916
13916
 
@@ -14010,7 +14010,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
14010
14010
  "versionLabel": "Java 23",
14011
14011
  "executionPlatform": {
14012
14012
  "name": "TraceKernel",
14013
- "version": "0.16.2"
14013
+ "version": "0.16.3"
14014
14014
  },
14015
14015
  "description": "Java 23 is compiled with javac 23 and executed by the Java runtime on TraceKernel.\n\nCommon imports are added automatically: java.util.*, java.io.*, java.math.*, java.util.stream.*, javafx.util.Pair.",
14016
14016
  "runtime": {
@@ -14047,7 +14047,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
14047
14047
  "versionLabel": "C# 14",
14048
14048
  "executionPlatform": {
14049
14049
  "name": "TraceKernel",
14050
- "version": "0.16.2"
14050
+ "version": "0.16.3"
14051
14051
  },
14052
14052
  "description": "C# 14 source is compiled and executed by TraceKernel's isolated C# runtime.\n\nCommon namespaces are imported automatically: System, System.Collections, System.Collections.Generic, System.IO, System.Linq, System.Numerics, System.Text, System.Text.RegularExpressions.",
14053
14053
  "runtime": {
@@ -14076,7 +14076,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
14076
14076
  "versionLabel": "C++23",
14077
14077
  "executionPlatform": {
14078
14078
  "name": "TraceKernel",
14079
- "version": "0.16.2"
14079
+ "version": "0.16.3"
14080
14080
  },
14081
14081
  "description": "C++ source is compiled using the C++23 standard.\n\nSubmissions compile to WebAssembly and run in TraceKernel's WASI execution lane. The compiler currently uses -O0 and -fno-exceptions, with a fixed program stack size.\n\nCommon standard library headers are included automatically, including <algorithm>, <array>, <bitset>, <climits>, <cmath>, <cstdint>, <functional>, <limits>, <numeric>, <sstream>, <tuple>, <vector>, <unordered_map>, <unordered_set> and more.",
14082
14082
  "runtime": {
@@ -14241,7 +14241,7 @@ var init_runtime_open_source_info_data = __esm({
14241
14241
  {
14242
14242
  "kind": "modifications",
14243
14243
  "label": "Runtime modifications",
14244
- "url": "https://github.com/tracecodeapp/harness/tree/v0.16.2/workers/python/pyodide-0.29.3"
14244
+ "url": "https://github.com/tracecodeapp/harness/tree/v0.16.3/workers/python/pyodide-0.29.3"
14245
14245
  }
14246
14246
  ]
14247
14247
  }
@@ -89584,20 +89584,27 @@ var init_terminal_session = __esm({
89584
89584
  signalCharacter === "" ? "SIGINT" : "SIGQUIT"
89585
89585
  );
89586
89586
  }
89587
- const route = this.options.terminalInputRouter?.write(data) ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
89587
+ const routed = this.options.terminalInputRouter?.write(data);
89588
+ const route = routed === "rejected" && this.activeStdinPipe !== null ? "legacy" : routed ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
89588
89589
  if (route === "legacy") {
89589
- this.activeStdinPipe?.write(data);
89590
+ if (!this.activeStdinPipe) return false;
89591
+ try {
89592
+ this.activeStdinPipe.write(data);
89593
+ } catch {
89594
+ return false;
89595
+ }
89590
89596
  }
89591
89597
  const accepted = route !== "rejected";
89592
89598
  if (accepted && this.currentInputState.mode === "stdin") {
89593
89599
  this.activeStdinPrompt = "";
89594
- this.setInputState("busy", "stdin-submit");
89600
+ this.setInputState("stdin", "stdin-submit", "");
89595
89601
  }
89596
89602
  return accepted;
89597
89603
  }
89598
89604
  endStdin() {
89599
89605
  if (!this.activeRun || this.activeStdinEnded) return false;
89600
- const route = this.options.terminalInputRouter?.end() ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
89606
+ const routed = this.options.terminalInputRouter?.end();
89607
+ const route = routed === "rejected" && this.activeStdinPipe !== null ? "legacy" : routed ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
89601
89608
  if (route === "rejected") return false;
89602
89609
  this.activeStdinEnded = true;
89603
89610
  if (route === "legacy") {
@@ -89636,6 +89643,14 @@ var init_terminal_session = __esm({
89636
89643
  this.emitTerminalEvent(reason);
89637
89644
  return this.currentInputState;
89638
89645
  }
89646
+ showForegroundInputLine() {
89647
+ const acceptsInput = this.activeStdinPipe !== null || this.options.terminalInputRouter !== void 0;
89648
+ return this.setInputState(
89649
+ acceptsInput ? "stdin" : "busy",
89650
+ "command-start",
89651
+ acceptsInput ? "" : this.prompt.text
89652
+ );
89653
+ }
89639
89654
  async run(command, options = {}) {
89640
89655
  const trimmed = command.trim();
89641
89656
  if (!trimmed) return { stdout: "", stderr: "", exitCode: 0 };
@@ -89690,7 +89705,7 @@ var init_terminal_session = __esm({
89690
89705
  this.activeTerminalEventHandler = options.onTerminalEvent;
89691
89706
  this.activeStdinPrompt = "";
89692
89707
  this.activeCommand = submittedCommand;
89693
- this.setInputState("busy", "command-start");
89708
+ this.showForegroundInputLine();
89694
89709
  try {
89695
89710
  let stdout = "";
89696
89711
  let stderr = "";
@@ -89719,6 +89734,7 @@ var init_terminal_session = __esm({
89719
89734
  ...error ? { error } : {}
89720
89735
  };
89721
89736
  } finally {
89737
+ this.options.terminalInputRouter?.reset();
89722
89738
  ownedStdinPipe?.close();
89723
89739
  this.activeStdinPipe = previousStdinPipe;
89724
89740
  this.activeStdinEnded = previousStdinEnded;
@@ -89757,7 +89773,7 @@ var init_terminal_session = __esm({
89757
89773
  this.activeStdinPrompt = "";
89758
89774
  this.activeCommand = trimmed;
89759
89775
  this.activeCommandAbortController = commandAbortController;
89760
- this.setInputState("busy", "command-start");
89776
+ this.showForegroundInputLine();
89761
89777
  try {
89762
89778
  const result = await this.runForegroundTerminalCommand(
89763
89779
  trimmed,
@@ -89768,6 +89784,7 @@ var init_terminal_session = __esm({
89768
89784
  return result;
89769
89785
  } finally {
89770
89786
  options.signal?.removeEventListener("abort", forwardExternalAbort);
89787
+ this.options.terminalInputRouter?.reset();
89771
89788
  ownedStdinPipe?.close();
89772
89789
  this.activeStdinPipe = previousStdinPipe;
89773
89790
  this.activeStdinEnded = previousStdinEnded;
@@ -95602,21 +95619,26 @@ function createWorkspaceRuntimeRunnerBridge2(bridge) {
95602
95619
  ...requestWithoutLegacyStdin
95603
95620
  } = request;
95604
95621
  const activeStdinPipe = request.source !== "compile" && request.source !== "stdin" ? commandContext?.stdinPipe : void 0;
95622
+ const consumesLiveStdin = request.source !== "compile" && request.source !== "stdin";
95605
95623
  const stdinPipe = request.stdinPipe ?? activeStdinPipe;
95606
- const processBinding = commandContext ? bridge.bindProcess(commandContext, descriptorStdio) : {};
95624
+ const processBinding = commandContext ? bridge.bindProcess(
95625
+ commandContext,
95626
+ descriptorStdio,
95627
+ consumesLiveStdin
95628
+ ) : {};
95607
95629
  const signal = processBinding.signal ?? request.signal;
95608
95630
  const runtimeIo = commandContext?.runtimeIo;
95609
95631
  let acceptingRunnerEvents = true;
95610
95632
  let result;
95611
95633
  const kernelSyscalls = options.kernelSyscalls ? bridge.createKernelSyscallBridge(commandContext) : void 0;
95612
- if (descriptorStdio && commandContext) {
95634
+ if (descriptorStdio && commandContext && consumesLiveStdin) {
95613
95635
  bridge.startHostStandardInputPump(commandContext);
95614
95636
  }
95615
95637
  try {
95616
- result = await runner({
95617
- ...descriptorStdio ? requestWithoutLegacyStdin : request,
95638
+ const execution = runner({
95639
+ ...descriptorStdio || !consumesLiveStdin ? requestWithoutLegacyStdin : request,
95618
95640
  ...processBinding.process ? { process: processBinding.process } : {},
95619
- ...stdinPipe && !descriptorStdio ? { stdinPipe: { buffer: stdinPipe.buffer } } : {},
95641
+ ...stdinPipe && !descriptorStdio && consumesLiveStdin ? { stdinPipe: { buffer: stdinPipe.buffer } } : {},
95620
95642
  ...commandContext?.terminal ? { terminal: commandContext.terminal } : {},
95621
95643
  ...commandContext?.engineLease ? { engineLease: commandContext.engineLease } : {},
95622
95644
  ...signal ? { signal } : {},
@@ -95628,6 +95650,8 @@ function createWorkspaceRuntimeRunnerBridge2(bridge) {
95628
95650
  bridge.handleRuntimeCommandEvent(event, commandContext);
95629
95651
  }
95630
95652
  });
95653
+ await processBinding.replayStartupInput?.();
95654
+ result = await execution;
95631
95655
  } finally {
95632
95656
  acceptingRunnerEvents = false;
95633
95657
  kernelSyscalls?.close();
@@ -96671,7 +96695,7 @@ async function createRuntimeWorkspace2(options = {}) {
96671
96695
  }
96672
96696
  return workspace;
96673
96697
  }
96674
- var PRINCIPAL_ACTOR4, RUNTIME_ACTOR2, SYSTEM_ACTOR4, TRACEKERNEL_SYSCALL_ERROR_CODES2, TRACEKERNEL_ZOMBIE_RETENTION_MS2, RuntimeProjectWorkspace2;
96698
+ var PRINCIPAL_ACTOR4, RUNTIME_ACTOR2, SYSTEM_ACTOR4, TERMINAL_STARTUP_INPUT_MAX_BYTES2, TRACEKERNEL_SYSCALL_ERROR_CODES2, TRACEKERNEL_ZOMBIE_RETENTION_MS2, RuntimeProjectWorkspace2;
96675
96699
  var init_runtime_project_workspace = __esm({
96676
96700
  "packages/tracekernel/src/workspace/runtime-project-workspace.ts"() {
96677
96701
  "use strict";
@@ -96721,6 +96745,7 @@ var init_runtime_project_workspace = __esm({
96721
96745
  PRINCIPAL_ACTOR4 = runtimeWorkspaceActorPreset("principal");
96722
96746
  RUNTIME_ACTOR2 = runtimeWorkspaceActorPreset("runtime");
96723
96747
  SYSTEM_ACTOR4 = runtimeWorkspaceActorPreset("system");
96748
+ TERMINAL_STARTUP_INPUT_MAX_BYTES2 = 64 * 1024 - 1;
96724
96749
  TRACEKERNEL_SYSCALL_ERROR_CODES2 = /* @__PURE__ */ new Set([
96725
96750
  "E2BIG",
96726
96751
  "EAGAIN",
@@ -96795,6 +96820,7 @@ var init_runtime_project_workspace = __esm({
96795
96820
  processState = new WorkspaceProcessState2();
96796
96821
  terminalShells = /* @__PURE__ */ new Map();
96797
96822
  terminalResourceIds = /* @__PURE__ */ new Map();
96823
+ pendingTerminalStartupInput = /* @__PURE__ */ new Map();
96798
96824
  processProjection;
96799
96825
  // Temporary 0.13 introspection aliases. The process state module remains
96800
96826
  // authoritative; these preserve existing hardening probes while 0.14 moves
@@ -96976,17 +97002,24 @@ var init_runtime_project_workspace = __esm({
96976
97002
  });
96977
97003
  const withEvents = createWorkspaceRuntimeRunnerBridge2({
96978
97004
  resolveCommandContext: (context2) => this.resolveCommandContext(context2),
96979
- bindProcess: (context2, descriptorStdio) => {
97005
+ bindProcess: (context2, descriptorStdio, consumesLiveStdin) => {
96980
97006
  const executionHandle = this.processProjection.executionHandle(
96981
97007
  context2.process
96982
97008
  );
96983
97009
  if (executionHandle) {
96984
97010
  executionHandle.descriptorStdio = descriptorStdio;
97011
+ executionHandle.consumesLiveStdin = consumesLiveStdin;
96985
97012
  }
96986
97013
  const processSnapshot = this.processProjection.authoritativeSnapshot(
96987
97014
  context2.process
96988
97015
  );
96989
97016
  return {
97017
+ replayStartupInput: () => this.resolvePendingTerminalStartupInput(
97018
+ context2.process.pid,
97019
+ descriptorStdio,
97020
+ context2.stdinPipe,
97021
+ consumesLiveStdin
97022
+ ),
96990
97023
  ...executionHandle?.abortController?.signal ? { signal: executionHandle.abortController.signal } : {},
96991
97024
  ...executionHandle?.signalChannel ? { kernelSignals: executionHandle.signalChannel } : {},
96992
97025
  ...processSnapshot ? {
@@ -99534,24 +99567,106 @@ var init_runtime_project_workspace = __esm({
99534
99567
  )
99535
99568
  );
99536
99569
  }
99537
- kernelTerminalInputRoute(terminal) {
99570
+ kernelTerminalInputRoute(terminalSessionId, terminal) {
99538
99571
  const hasDescriptorConsumer = this.traceKernelAuthority?.session.processSnapshots().some(
99539
- (process4) => process4.sid === terminal.sessionId && process4.pgid === terminal.foregroundProcessGroupId && this.processState.executionHandles.get(process4.pid)?.descriptorStdio === true
99572
+ (process4) => process4.sid === terminal.sessionId && process4.pgid === terminal.foregroundProcessGroupId && this.processState.executionHandles.get(process4.pid)?.descriptorStdio === true && this.processState.executionHandles.get(process4.pid)?.consumesLiveStdin === true
99540
99573
  ) === true;
99541
- return hasDescriptorConsumer ? "kernel" : "legacy";
99574
+ if (hasDescriptorConsumer) return "kernel";
99575
+ const foregroundPid = this.processState.terminalForeground.get(
99576
+ terminalSessionId
99577
+ );
99578
+ if (foregroundPid === void 0) return "pending";
99579
+ const executionHandle = this.processState.executionHandles.get(foregroundPid);
99580
+ if (executionHandle?.consumesLiveStdin !== true) return "pending";
99581
+ const descriptorStdio = executionHandle.descriptorStdio;
99582
+ return descriptorStdio === void 0 ? "pending" : descriptorStdio ? "kernel" : "legacy";
99583
+ }
99584
+ queueTerminalStartupInput(terminalSessionId, input = {}) {
99585
+ const pending2 = this.pendingTerminalStartupInput.get(terminalSessionId) ?? {
99586
+ chunks: [],
99587
+ byteLength: 0,
99588
+ eof: false
99589
+ };
99590
+ if (input.data) {
99591
+ const byteLength = new TextEncoder().encode(input.data).byteLength;
99592
+ if (pending2.byteLength + byteLength > TERMINAL_STARTUP_INPUT_MAX_BYTES2) {
99593
+ return false;
99594
+ }
99595
+ pending2.chunks.push(input.data);
99596
+ pending2.byteLength += byteLength;
99597
+ }
99598
+ if (input.eof) pending2.eof = true;
99599
+ this.pendingTerminalStartupInput.set(terminalSessionId, pending2);
99600
+ return true;
99542
99601
  }
99543
- writeKernelTerminalInput(terminalSessionId, data) {
99602
+ async resolvePendingTerminalStartupInput(foregroundPid, descriptorStdio, stdinPipe, consumesLiveStdin = true) {
99603
+ const boundProcess = this.processProjection.find(foregroundPid);
99604
+ const boundSnapshot = boundProcess ? this.processProjection.authoritativeSnapshot(boundProcess) : void 0;
99605
+ const terminalSessionId = [...this.processState.terminalForeground].find(([, pid]) => {
99606
+ if (pid === foregroundPid) return true;
99607
+ const terminalProcess = this.processProjection.find(pid);
99608
+ const terminalSnapshot = terminalProcess ? this.processProjection.authoritativeSnapshot(terminalProcess) : void 0;
99609
+ return Boolean(
99610
+ boundSnapshot && terminalSnapshot && boundSnapshot.pgid === terminalSnapshot.pgid
99611
+ );
99612
+ })?.[0];
99613
+ if (!terminalSessionId) return;
99614
+ const pending2 = this.pendingTerminalStartupInput.get(terminalSessionId);
99615
+ if (!pending2) return;
99616
+ if (!consumesLiveStdin) return;
99617
+ this.pendingTerminalStartupInput.delete(terminalSessionId);
99618
+ if (!descriptorStdio) {
99619
+ if (!stdinPipe) return;
99620
+ try {
99621
+ for (const chunk2 of pending2.chunks) stdinPipe.write(chunk2);
99622
+ if (pending2.eof) stdinPipe.close();
99623
+ } catch {
99624
+ stdinPipe.close();
99625
+ }
99626
+ return;
99627
+ }
99544
99628
  const authority = this.traceKernelAuthority;
99545
99629
  const terminalId = this.terminalResourceIds.get(terminalSessionId);
99546
99630
  const terminal = terminalId === void 0 ? void 0 : authority?.session.terminalSnapshots().find(
99547
99631
  (candidate) => candidate.id === terminalId
99548
99632
  );
99549
- if (!authority || !terminal || terminal.closed) return "rejected";
99633
+ if (!authority || !terminal || terminal.closed) return;
99634
+ const bytes = new TextEncoder().encode(pending2.chunks.join(""));
99635
+ await runPromise(
99636
+ gen2(function* () {
99637
+ if (bytes.byteLength > 0) {
99638
+ yield* authority.session.writeTerminalInput(terminal.id, bytes);
99639
+ }
99640
+ if (pending2.eof) {
99641
+ yield* authority.session.sendTerminalInputEof(terminal.id);
99642
+ }
99643
+ }).pipe(catchAll2(() => _void))
99644
+ );
99645
+ }
99646
+ discardPendingTerminalStartupInput(terminalSessionId, foregroundPid) {
99647
+ if (terminalSessionId && (foregroundPid === void 0 || this.processState.terminalForeground.get(terminalSessionId) === foregroundPid)) {
99648
+ this.pendingTerminalStartupInput.delete(terminalSessionId);
99649
+ }
99650
+ }
99651
+ writeKernelTerminalInput(terminalSessionId, data) {
99550
99652
  const signalByte = new TextEncoder().encode(data).find(
99551
99653
  (byte) => byte === 3 || byte === 28
99552
99654
  );
99553
- if (signalByte === void 0 && this.kernelTerminalInputRoute(terminal) === "legacy") {
99554
- return "legacy";
99655
+ const authority = this.traceKernelAuthority;
99656
+ const terminalId = this.terminalResourceIds.get(terminalSessionId);
99657
+ const terminal = terminalId === void 0 ? void 0 : authority?.session.terminalSnapshots().find(
99658
+ (candidate) => candidate.id === terminalId
99659
+ );
99660
+ if (!authority || !terminal || terminal.closed) {
99661
+ if (signalByte !== void 0) return "rejected";
99662
+ return this.queueTerminalStartupInput(terminalSessionId, { data }) ? "pending" : "rejected";
99663
+ }
99664
+ if (signalByte === void 0) {
99665
+ const route = this.kernelTerminalInputRoute(terminalSessionId, terminal);
99666
+ if (route === "pending") {
99667
+ return this.queueTerminalStartupInput(terminalSessionId, { data }) ? "pending" : "rejected";
99668
+ }
99669
+ if (route === "legacy") return "legacy";
99555
99670
  }
99556
99671
  if (signalByte !== void 0) {
99557
99672
  const signal = signalByte === 3 ? "SIGINT" : "SIGQUIT";
@@ -99581,8 +99696,16 @@ var init_runtime_project_workspace = __esm({
99581
99696
  const terminal = terminalId === void 0 ? void 0 : authority?.session.terminalSnapshots().find(
99582
99697
  (candidate) => candidate.id === terminalId
99583
99698
  );
99584
- if (!authority || !terminal || terminal.closed) return "rejected";
99585
- if (this.kernelTerminalInputRoute(terminal) === "legacy") return "legacy";
99699
+ if (!authority || !terminal || terminal.closed) {
99700
+ this.queueTerminalStartupInput(terminalSessionId, { eof: true });
99701
+ return "pending";
99702
+ }
99703
+ const route = this.kernelTerminalInputRoute(terminalSessionId, terminal);
99704
+ if (route === "pending") {
99705
+ this.queueTerminalStartupInput(terminalSessionId, { eof: true });
99706
+ return "pending";
99707
+ }
99708
+ if (route === "legacy") return "legacy";
99586
99709
  runFork2(
99587
99710
  authority.session.sendTerminalInputEof(terminal.id).pipe(
99588
99711
  catchAll2(() => _void)
@@ -100736,6 +100859,10 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
100736
100859
  executionHandle.signalChannel?.close();
100737
100860
  this.processState.executionHandles.delete(process4.pid);
100738
100861
  if (options.terminalSessionId && this.processState.terminalForeground.get(options.terminalSessionId) === process4.pid) {
100862
+ this.discardPendingTerminalStartupInput(
100863
+ options.terminalSessionId,
100864
+ process4.pid
100865
+ );
100739
100866
  this.processState.terminalForeground.delete(options.terminalSessionId);
100740
100867
  }
100741
100868
  clearKernelSignalHandler();
@@ -100990,6 +101117,10 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
100990
101117
  executionHandle.signalChannel?.close();
100991
101118
  this.processState.executionHandles.delete(process4.pid);
100992
101119
  if (options.terminalSessionId && this.processState.terminalForeground.get(options.terminalSessionId) === process4.pid) {
101120
+ this.discardPendingTerminalStartupInput(
101121
+ options.terminalSessionId,
101122
+ process4.pid
101123
+ );
100993
101124
  this.processState.terminalForeground.delete(options.terminalSessionId);
100994
101125
  }
100995
101126
  this.observeKernelReparentedChildren(process4.pid);
@@ -101296,6 +101427,7 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
101296
101427
  const shellPromise = this.terminalShells.get(terminalSessionId);
101297
101428
  this.terminalShells.delete(terminalSessionId);
101298
101429
  this.terminalResourceIds.delete(terminalSessionId);
101430
+ this.pendingTerminalStartupInput.delete(terminalSessionId);
101299
101431
  if (!shellPromise) return;
101300
101432
  const disposal = shellPromise.then(async (shell) => {
101301
101433
  const authority = this.traceKernelAuthority;
@@ -101350,7 +101482,8 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
101350
101482
  signalForeground: (signal) => this.signalTerminalForeground(terminalSessionId, signal),
101351
101483
  terminalInputRouter: {
101352
101484
  write: (data) => this.writeKernelTerminalInput(terminalSessionId, data),
101353
- end: () => this.endKernelTerminalInput(terminalSessionId)
101485
+ end: () => this.endKernelTerminalInput(terminalSessionId),
101486
+ reset: () => this.discardPendingTerminalStartupInput(terminalSessionId)
101354
101487
  },
101355
101488
  resizeTerminal: (columns, rows) => this.resizeKernelTerminal(terminalSessionId, columns, rows),
101356
101489
  closeTerminal: () => this.closeTerminalShell(terminalSessionId),
@@ -101464,13 +101597,14 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
101464
101597
  const descriptorStdio = this.cppRunner.capabilities?.descriptorStdio === true;
101465
101598
  if (executionHandle) {
101466
101599
  executionHandle.descriptorStdio = descriptorStdio;
101600
+ executionHandle.consumesLiveStdin = true;
101467
101601
  }
101468
101602
  if (descriptorStdio) {
101469
101603
  this.startHostStandardInputPump(request.commandContext);
101470
101604
  }
101471
101605
  let result;
101472
101606
  try {
101473
- result = await this.cppRunner({
101607
+ const execution = this.cppRunner({
101474
101608
  code: "",
101475
101609
  source: "run",
101476
101610
  scriptPath,
@@ -101495,6 +101629,12 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
101495
101629
  this.handleRuntimeCommandEvent(event, request.commandContext);
101496
101630
  }
101497
101631
  });
101632
+ await this.resolvePendingTerminalStartupInput(
101633
+ request.commandContext.process.pid,
101634
+ descriptorStdio,
101635
+ request.stdinPipe
101636
+ );
101637
+ result = await execution;
101498
101638
  } finally {
101499
101639
  kernelSyscalls?.close();
101500
101640
  }
@@ -120539,6 +120679,13 @@ function normalizeBaseUrl(value) {
120539
120679
  const baseUrl = value ?? resolveBuiltInTraceJVMRuntimeAssetBaseUrl();
120540
120680
  return normalizeTraceJVMRuntimeAssetBaseUrl(baseUrl);
120541
120681
  }
120682
+ function normalizeWorkerUrl(value) {
120683
+ const workerUrl = value.trim();
120684
+ if (!workerUrl) {
120685
+ throw new TypeError("TraceJVM project Worker URL cannot be empty");
120686
+ }
120687
+ return workerUrl;
120688
+ }
120542
120689
  function createWorker(workerUrl, role) {
120543
120690
  return new Worker(workerUrl, {
120544
120691
  type: "module",
@@ -120547,7 +120694,9 @@ function createWorker(workerUrl, role) {
120547
120694
  }
120548
120695
  function createJavaProjectClientFactory(options = {}) {
120549
120696
  const runtimeAssetBaseUrl = normalizeBaseUrl(options.runtimeAssetBaseUrl);
120550
- const workerUrl = `${runtimeAssetBaseUrl}/browser-worker.js`;
120697
+ const workerUrl = normalizeWorkerUrl(
120698
+ options.workerUrl ?? `${runtimeAssetBaseUrl}/browser-worker.js`
120699
+ );
120551
120700
  const workerFor = (role) => options.createWorker?.(workerUrl, role) ?? createWorker(workerUrl, role);
120552
120701
  const runtimeProfile = options.runtimeProfile ?? "spring-server";
120553
120702
  const runtimeProfileBaseUrls = {
@@ -122642,7 +122791,6 @@ var init_cpp_worker_client = __esm({
122642
122791
  });
122643
122792
  }
122644
122793
  async executeProjectCpp(request, timeoutMs = this.executionTimeoutMs, onEvent, signal = request.signal, engineLease) {
122645
- engineLease?.attach({ release: () => void 0 });
122646
122794
  if (request.source === "compile" && this.options.trustedCompilerService) {
122647
122795
  const {
122648
122796
  signal: _signal,
@@ -122711,6 +122859,7 @@ var init_cpp_worker_client = __esm({
122711
122859
  }]
122712
122860
  };
122713
122861
  }
122862
+ engineLease?.attach({ release: () => void 0 });
122714
122863
  return this.runInDisposableExecutionWorker(async (lifecycleGeneration) => {
122715
122864
  const {
122716
122865
  signal: _signal,
@@ -123740,7 +123889,7 @@ function normalizeAssetBaseUrl(value) {
123740
123889
  }
123741
123890
  return normalized;
123742
123891
  }
123743
- function normalizeWorkerUrl(value) {
123892
+ function normalizeWorkerUrl2(value) {
123744
123893
  const normalized = value.trim();
123745
123894
  if (!normalized) {
123746
123895
  throw new TypeError("TraceCC worker URL must not be empty.");
@@ -123761,7 +123910,7 @@ function descriptor2(asset) {
123761
123910
  }
123762
123911
  function createTraceCCRuntimeManifest(assetBaseUrl, options = {}) {
123763
123912
  const normalizedAssetBaseUrl = normalizeAssetBaseUrl(assetBaseUrl);
123764
- const workerUrl = normalizeWorkerUrl(
123913
+ const workerUrl = normalizeWorkerUrl2(
123765
123914
  options.workerUrl ?? "/workers/cpp-worker.js"
123766
123915
  );
123767
123916
  const compilerWasm = descriptor2(
@@ -204596,20 +204745,27 @@ var RuntimeProjectWorkspaceTerminalSession = class {
204596
204745
  signalCharacter === "" ? "SIGINT" : "SIGQUIT"
204597
204746
  );
204598
204747
  }
204599
- const route = this.options.terminalInputRouter?.write(data) ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
204748
+ const routed = this.options.terminalInputRouter?.write(data);
204749
+ const route = routed === "rejected" && this.activeStdinPipe !== null ? "legacy" : routed ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
204600
204750
  if (route === "legacy") {
204601
- this.activeStdinPipe?.write(data);
204751
+ if (!this.activeStdinPipe) return false;
204752
+ try {
204753
+ this.activeStdinPipe.write(data);
204754
+ } catch {
204755
+ return false;
204756
+ }
204602
204757
  }
204603
204758
  const accepted = route !== "rejected";
204604
204759
  if (accepted && this.currentInputState.mode === "stdin") {
204605
204760
  this.activeStdinPrompt = "";
204606
- this.setInputState("busy", "stdin-submit");
204761
+ this.setInputState("stdin", "stdin-submit", "");
204607
204762
  }
204608
204763
  return accepted;
204609
204764
  }
204610
204765
  endStdin() {
204611
204766
  if (!this.activeRun || this.activeStdinEnded) return false;
204612
- const route = this.options.terminalInputRouter?.end() ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
204767
+ const routed = this.options.terminalInputRouter?.end();
204768
+ const route = routed === "rejected" && this.activeStdinPipe !== null ? "legacy" : routed ?? (this.activeStdinPipe !== null ? "legacy" : "rejected");
204613
204769
  if (route === "rejected") return false;
204614
204770
  this.activeStdinEnded = true;
204615
204771
  if (route === "legacy") {
@@ -204648,6 +204804,14 @@ var RuntimeProjectWorkspaceTerminalSession = class {
204648
204804
  this.emitTerminalEvent(reason);
204649
204805
  return this.currentInputState;
204650
204806
  }
204807
+ showForegroundInputLine() {
204808
+ const acceptsInput = this.activeStdinPipe !== null || this.options.terminalInputRouter !== void 0;
204809
+ return this.setInputState(
204810
+ acceptsInput ? "stdin" : "busy",
204811
+ "command-start",
204812
+ acceptsInput ? "" : this.prompt.text
204813
+ );
204814
+ }
204651
204815
  async run(command, options = {}) {
204652
204816
  const trimmed = command.trim();
204653
204817
  if (!trimmed) return { stdout: "", stderr: "", exitCode: 0 };
@@ -204702,7 +204866,7 @@ var RuntimeProjectWorkspaceTerminalSession = class {
204702
204866
  this.activeTerminalEventHandler = options.onTerminalEvent;
204703
204867
  this.activeStdinPrompt = "";
204704
204868
  this.activeCommand = submittedCommand;
204705
- this.setInputState("busy", "command-start");
204869
+ this.showForegroundInputLine();
204706
204870
  try {
204707
204871
  let stdout = "";
204708
204872
  let stderr = "";
@@ -204731,6 +204895,7 @@ var RuntimeProjectWorkspaceTerminalSession = class {
204731
204895
  ...error ? { error } : {}
204732
204896
  };
204733
204897
  } finally {
204898
+ this.options.terminalInputRouter?.reset();
204734
204899
  ownedStdinPipe?.close();
204735
204900
  this.activeStdinPipe = previousStdinPipe;
204736
204901
  this.activeStdinEnded = previousStdinEnded;
@@ -204769,7 +204934,7 @@ var RuntimeProjectWorkspaceTerminalSession = class {
204769
204934
  this.activeStdinPrompt = "";
204770
204935
  this.activeCommand = trimmed;
204771
204936
  this.activeCommandAbortController = commandAbortController;
204772
- this.setInputState("busy", "command-start");
204937
+ this.showForegroundInputLine();
204773
204938
  try {
204774
204939
  const result = await this.runForegroundTerminalCommand(
204775
204940
  trimmed,
@@ -204780,6 +204945,7 @@ var RuntimeProjectWorkspaceTerminalSession = class {
204780
204945
  return result;
204781
204946
  } finally {
204782
204947
  options.signal?.removeEventListener("abort", forwardExternalAbort);
204948
+ this.options.terminalInputRouter?.reset();
204783
204949
  ownedStdinPipe?.close();
204784
204950
  this.activeStdinPipe = previousStdinPipe;
204785
204951
  this.activeStdinEnded = previousStdinEnded;
@@ -210407,21 +210573,26 @@ function createWorkspaceRuntimeRunnerBridge(bridge) {
210407
210573
  ...requestWithoutLegacyStdin
210408
210574
  } = request;
210409
210575
  const activeStdinPipe = request.source !== "compile" && request.source !== "stdin" ? commandContext?.stdinPipe : void 0;
210576
+ const consumesLiveStdin = request.source !== "compile" && request.source !== "stdin";
210410
210577
  const stdinPipe = request.stdinPipe ?? activeStdinPipe;
210411
- const processBinding = commandContext ? bridge.bindProcess(commandContext, descriptorStdio) : {};
210578
+ const processBinding = commandContext ? bridge.bindProcess(
210579
+ commandContext,
210580
+ descriptorStdio,
210581
+ consumesLiveStdin
210582
+ ) : {};
210412
210583
  const signal = processBinding.signal ?? request.signal;
210413
210584
  const runtimeIo = commandContext?.runtimeIo;
210414
210585
  let acceptingRunnerEvents = true;
210415
210586
  let result;
210416
210587
  const kernelSyscalls = options.kernelSyscalls ? bridge.createKernelSyscallBridge(commandContext) : void 0;
210417
- if (descriptorStdio && commandContext) {
210588
+ if (descriptorStdio && commandContext && consumesLiveStdin) {
210418
210589
  bridge.startHostStandardInputPump(commandContext);
210419
210590
  }
210420
210591
  try {
210421
- result = await runner({
210422
- ...descriptorStdio ? requestWithoutLegacyStdin : request,
210592
+ const execution = runner({
210593
+ ...descriptorStdio || !consumesLiveStdin ? requestWithoutLegacyStdin : request,
210423
210594
  ...processBinding.process ? { process: processBinding.process } : {},
210424
- ...stdinPipe && !descriptorStdio ? { stdinPipe: { buffer: stdinPipe.buffer } } : {},
210595
+ ...stdinPipe && !descriptorStdio && consumesLiveStdin ? { stdinPipe: { buffer: stdinPipe.buffer } } : {},
210425
210596
  ...commandContext?.terminal ? { terminal: commandContext.terminal } : {},
210426
210597
  ...commandContext?.engineLease ? { engineLease: commandContext.engineLease } : {},
210427
210598
  ...signal ? { signal } : {},
@@ -210433,6 +210604,8 @@ function createWorkspaceRuntimeRunnerBridge(bridge) {
210433
210604
  bridge.handleRuntimeCommandEvent(event, commandContext);
210434
210605
  }
210435
210606
  });
210607
+ await processBinding.replayStartupInput?.();
210608
+ result = await execution;
210436
210609
  } finally {
210437
210610
  acceptingRunnerEvents = false;
210438
210611
  kernelSyscalls?.close();
@@ -211310,6 +211483,7 @@ function createRuntimeWorkspaceShellCommands(options) {
211310
211483
  var PRINCIPAL_ACTOR2 = runtimeWorkspaceActorPreset("principal");
211311
211484
  var RUNTIME_ACTOR = runtimeWorkspaceActorPreset("runtime");
211312
211485
  var SYSTEM_ACTOR2 = runtimeWorkspaceActorPreset("system");
211486
+ var TERMINAL_STARTUP_INPUT_MAX_BYTES = 64 * 1024 - 1;
211313
211487
  var TRACEKERNEL_SYSCALL_ERROR_CODES = /* @__PURE__ */ new Set([
211314
211488
  "E2BIG",
211315
211489
  "EAGAIN",
@@ -211443,6 +211617,7 @@ var RuntimeProjectWorkspace = class {
211443
211617
  processState = new WorkspaceProcessState();
211444
211618
  terminalShells = /* @__PURE__ */ new Map();
211445
211619
  terminalResourceIds = /* @__PURE__ */ new Map();
211620
+ pendingTerminalStartupInput = /* @__PURE__ */ new Map();
211446
211621
  processProjection;
211447
211622
  // Temporary 0.13 introspection aliases. The process state module remains
211448
211623
  // authoritative; these preserve existing hardening probes while 0.14 moves
@@ -211624,17 +211799,24 @@ var RuntimeProjectWorkspace = class {
211624
211799
  });
211625
211800
  const withEvents = createWorkspaceRuntimeRunnerBridge({
211626
211801
  resolveCommandContext: (context2) => this.resolveCommandContext(context2),
211627
- bindProcess: (context2, descriptorStdio) => {
211802
+ bindProcess: (context2, descriptorStdio, consumesLiveStdin) => {
211628
211803
  const executionHandle = this.processProjection.executionHandle(
211629
211804
  context2.process
211630
211805
  );
211631
211806
  if (executionHandle) {
211632
211807
  executionHandle.descriptorStdio = descriptorStdio;
211808
+ executionHandle.consumesLiveStdin = consumesLiveStdin;
211633
211809
  }
211634
211810
  const processSnapshot = this.processProjection.authoritativeSnapshot(
211635
211811
  context2.process
211636
211812
  );
211637
211813
  return {
211814
+ replayStartupInput: () => this.resolvePendingTerminalStartupInput(
211815
+ context2.process.pid,
211816
+ descriptorStdio,
211817
+ context2.stdinPipe,
211818
+ consumesLiveStdin
211819
+ ),
211638
211820
  ...executionHandle?.abortController?.signal ? { signal: executionHandle.abortController.signal } : {},
211639
211821
  ...executionHandle?.signalChannel ? { kernelSignals: executionHandle.signalChannel } : {},
211640
211822
  ...processSnapshot ? {
@@ -214182,24 +214364,106 @@ var RuntimeProjectWorkspace = class {
214182
214364
  )
214183
214365
  );
214184
214366
  }
214185
- kernelTerminalInputRoute(terminal) {
214367
+ kernelTerminalInputRoute(terminalSessionId, terminal) {
214186
214368
  const hasDescriptorConsumer = this.traceKernelAuthority?.session.processSnapshots().some(
214187
- (process32) => process32.sid === terminal.sessionId && process32.pgid === terminal.foregroundProcessGroupId && this.processState.executionHandles.get(process32.pid)?.descriptorStdio === true
214369
+ (process32) => process32.sid === terminal.sessionId && process32.pgid === terminal.foregroundProcessGroupId && this.processState.executionHandles.get(process32.pid)?.descriptorStdio === true && this.processState.executionHandles.get(process32.pid)?.consumesLiveStdin === true
214188
214370
  ) === true;
214189
- return hasDescriptorConsumer ? "kernel" : "legacy";
214371
+ if (hasDescriptorConsumer) return "kernel";
214372
+ const foregroundPid = this.processState.terminalForeground.get(
214373
+ terminalSessionId
214374
+ );
214375
+ if (foregroundPid === void 0) return "pending";
214376
+ const executionHandle = this.processState.executionHandles.get(foregroundPid);
214377
+ if (executionHandle?.consumesLiveStdin !== true) return "pending";
214378
+ const descriptorStdio = executionHandle.descriptorStdio;
214379
+ return descriptorStdio === void 0 ? "pending" : descriptorStdio ? "kernel" : "legacy";
214380
+ }
214381
+ queueTerminalStartupInput(terminalSessionId, input = {}) {
214382
+ const pending2 = this.pendingTerminalStartupInput.get(terminalSessionId) ?? {
214383
+ chunks: [],
214384
+ byteLength: 0,
214385
+ eof: false
214386
+ };
214387
+ if (input.data) {
214388
+ const byteLength = new TextEncoder().encode(input.data).byteLength;
214389
+ if (pending2.byteLength + byteLength > TERMINAL_STARTUP_INPUT_MAX_BYTES) {
214390
+ return false;
214391
+ }
214392
+ pending2.chunks.push(input.data);
214393
+ pending2.byteLength += byteLength;
214394
+ }
214395
+ if (input.eof) pending2.eof = true;
214396
+ this.pendingTerminalStartupInput.set(terminalSessionId, pending2);
214397
+ return true;
214190
214398
  }
214191
- writeKernelTerminalInput(terminalSessionId, data) {
214399
+ async resolvePendingTerminalStartupInput(foregroundPid, descriptorStdio, stdinPipe, consumesLiveStdin = true) {
214400
+ const boundProcess = this.processProjection.find(foregroundPid);
214401
+ const boundSnapshot = boundProcess ? this.processProjection.authoritativeSnapshot(boundProcess) : void 0;
214402
+ const terminalSessionId = [...this.processState.terminalForeground].find(([, pid]) => {
214403
+ if (pid === foregroundPid) return true;
214404
+ const terminalProcess = this.processProjection.find(pid);
214405
+ const terminalSnapshot = terminalProcess ? this.processProjection.authoritativeSnapshot(terminalProcess) : void 0;
214406
+ return Boolean(
214407
+ boundSnapshot && terminalSnapshot && boundSnapshot.pgid === terminalSnapshot.pgid
214408
+ );
214409
+ })?.[0];
214410
+ if (!terminalSessionId) return;
214411
+ const pending2 = this.pendingTerminalStartupInput.get(terminalSessionId);
214412
+ if (!pending2) return;
214413
+ if (!consumesLiveStdin) return;
214414
+ this.pendingTerminalStartupInput.delete(terminalSessionId);
214415
+ if (!descriptorStdio) {
214416
+ if (!stdinPipe) return;
214417
+ try {
214418
+ for (const chunk2 of pending2.chunks) stdinPipe.write(chunk2);
214419
+ if (pending2.eof) stdinPipe.close();
214420
+ } catch {
214421
+ stdinPipe.close();
214422
+ }
214423
+ return;
214424
+ }
214192
214425
  const authority = this.traceKernelAuthority;
214193
214426
  const terminalId = this.terminalResourceIds.get(terminalSessionId);
214194
214427
  const terminal = terminalId === void 0 ? void 0 : authority?.session.terminalSnapshots().find(
214195
214428
  (candidate) => candidate.id === terminalId
214196
214429
  );
214197
- if (!authority || !terminal || terminal.closed) return "rejected";
214430
+ if (!authority || !terminal || terminal.closed) return;
214431
+ const bytes = new TextEncoder().encode(pending2.chunks.join(""));
214432
+ await runPromise(
214433
+ gen2(function* () {
214434
+ if (bytes.byteLength > 0) {
214435
+ yield* authority.session.writeTerminalInput(terminal.id, bytes);
214436
+ }
214437
+ if (pending2.eof) {
214438
+ yield* authority.session.sendTerminalInputEof(terminal.id);
214439
+ }
214440
+ }).pipe(catchAll2(() => _void))
214441
+ );
214442
+ }
214443
+ discardPendingTerminalStartupInput(terminalSessionId, foregroundPid) {
214444
+ if (terminalSessionId && (foregroundPid === void 0 || this.processState.terminalForeground.get(terminalSessionId) === foregroundPid)) {
214445
+ this.pendingTerminalStartupInput.delete(terminalSessionId);
214446
+ }
214447
+ }
214448
+ writeKernelTerminalInput(terminalSessionId, data) {
214198
214449
  const signalByte = new TextEncoder().encode(data).find(
214199
214450
  (byte) => byte === 3 || byte === 28
214200
214451
  );
214201
- if (signalByte === void 0 && this.kernelTerminalInputRoute(terminal) === "legacy") {
214202
- return "legacy";
214452
+ const authority = this.traceKernelAuthority;
214453
+ const terminalId = this.terminalResourceIds.get(terminalSessionId);
214454
+ const terminal = terminalId === void 0 ? void 0 : authority?.session.terminalSnapshots().find(
214455
+ (candidate) => candidate.id === terminalId
214456
+ );
214457
+ if (!authority || !terminal || terminal.closed) {
214458
+ if (signalByte !== void 0) return "rejected";
214459
+ return this.queueTerminalStartupInput(terminalSessionId, { data }) ? "pending" : "rejected";
214460
+ }
214461
+ if (signalByte === void 0) {
214462
+ const route = this.kernelTerminalInputRoute(terminalSessionId, terminal);
214463
+ if (route === "pending") {
214464
+ return this.queueTerminalStartupInput(terminalSessionId, { data }) ? "pending" : "rejected";
214465
+ }
214466
+ if (route === "legacy") return "legacy";
214203
214467
  }
214204
214468
  if (signalByte !== void 0) {
214205
214469
  const signal = signalByte === 3 ? "SIGINT" : "SIGQUIT";
@@ -214229,8 +214493,16 @@ var RuntimeProjectWorkspace = class {
214229
214493
  const terminal = terminalId === void 0 ? void 0 : authority?.session.terminalSnapshots().find(
214230
214494
  (candidate) => candidate.id === terminalId
214231
214495
  );
214232
- if (!authority || !terminal || terminal.closed) return "rejected";
214233
- if (this.kernelTerminalInputRoute(terminal) === "legacy") return "legacy";
214496
+ if (!authority || !terminal || terminal.closed) {
214497
+ this.queueTerminalStartupInput(terminalSessionId, { eof: true });
214498
+ return "pending";
214499
+ }
214500
+ const route = this.kernelTerminalInputRoute(terminalSessionId, terminal);
214501
+ if (route === "pending") {
214502
+ this.queueTerminalStartupInput(terminalSessionId, { eof: true });
214503
+ return "pending";
214504
+ }
214505
+ if (route === "legacy") return "legacy";
214234
214506
  runFork2(
214235
214507
  authority.session.sendTerminalInputEof(terminal.id).pipe(
214236
214508
  catchAll2(() => _void)
@@ -215384,6 +215656,10 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
215384
215656
  executionHandle.signalChannel?.close();
215385
215657
  this.processState.executionHandles.delete(process32.pid);
215386
215658
  if (options.terminalSessionId && this.processState.terminalForeground.get(options.terminalSessionId) === process32.pid) {
215659
+ this.discardPendingTerminalStartupInput(
215660
+ options.terminalSessionId,
215661
+ process32.pid
215662
+ );
215387
215663
  this.processState.terminalForeground.delete(options.terminalSessionId);
215388
215664
  }
215389
215665
  clearKernelSignalHandler();
@@ -215638,6 +215914,10 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
215638
215914
  executionHandle.signalChannel?.close();
215639
215915
  this.processState.executionHandles.delete(process32.pid);
215640
215916
  if (options.terminalSessionId && this.processState.terminalForeground.get(options.terminalSessionId) === process32.pid) {
215917
+ this.discardPendingTerminalStartupInput(
215918
+ options.terminalSessionId,
215919
+ process32.pid
215920
+ );
215641
215921
  this.processState.terminalForeground.delete(options.terminalSessionId);
215642
215922
  }
215643
215923
  this.observeKernelReparentedChildren(process32.pid);
@@ -215944,6 +216224,7 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
215944
216224
  const shellPromise = this.terminalShells.get(terminalSessionId);
215945
216225
  this.terminalShells.delete(terminalSessionId);
215946
216226
  this.terminalResourceIds.delete(terminalSessionId);
216227
+ this.pendingTerminalStartupInput.delete(terminalSessionId);
215947
216228
  if (!shellPromise) return;
215948
216229
  const disposal = shellPromise.then(async (shell) => {
215949
216230
  const authority = this.traceKernelAuthority;
@@ -215998,7 +216279,8 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
215998
216279
  signalForeground: (signal) => this.signalTerminalForeground(terminalSessionId, signal),
215999
216280
  terminalInputRouter: {
216000
216281
  write: (data) => this.writeKernelTerminalInput(terminalSessionId, data),
216001
- end: () => this.endKernelTerminalInput(terminalSessionId)
216282
+ end: () => this.endKernelTerminalInput(terminalSessionId),
216283
+ reset: () => this.discardPendingTerminalStartupInput(terminalSessionId)
216002
216284
  },
216003
216285
  resizeTerminal: (columns, rows) => this.resizeKernelTerminal(terminalSessionId, columns, rows),
216004
216286
  closeTerminal: () => this.closeTerminalShell(terminalSessionId),
@@ -216112,13 +216394,14 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
216112
216394
  const descriptorStdio = this.cppRunner.capabilities?.descriptorStdio === true;
216113
216395
  if (executionHandle) {
216114
216396
  executionHandle.descriptorStdio = descriptorStdio;
216397
+ executionHandle.consumesLiveStdin = true;
216115
216398
  }
216116
216399
  if (descriptorStdio) {
216117
216400
  this.startHostStandardInputPump(request.commandContext);
216118
216401
  }
216119
216402
  let result;
216120
216403
  try {
216121
- result = await this.cppRunner({
216404
+ const execution = this.cppRunner({
216122
216405
  code: "",
216123
216406
  source: "run",
216124
216407
  scriptPath,
@@ -216143,6 +216426,12 @@ usage: tracekernelctl {status|reset|verbose [on|off|status]|kill <pid> [signal]|
216143
216426
  this.handleRuntimeCommandEvent(event, request.commandContext);
216144
216427
  }
216145
216428
  });
216429
+ await this.resolvePendingTerminalStartupInput(
216430
+ request.commandContext.process.pid,
216431
+ descriptorStdio,
216432
+ request.stdinPipe
216433
+ );
216434
+ result = await execution;
216146
216435
  } finally {
216147
216436
  kernelSyscalls?.close();
216148
216437
  }
@@ -219048,6 +219337,7 @@ async function createBrowserProjectWorkspace(options = {}) {
219048
219337
  runtimeProviders: _runtimeProviders,
219049
219338
  java,
219050
219339
  javaRuntimeAssetBaseUrl,
219340
+ javaProjectWorkerUrl,
219051
219341
  executionHost: executionHostOptions,
219052
219342
  nodeProject,
219053
219343
  typescriptProject,
@@ -219215,7 +219505,8 @@ async function createBrowserProjectWorkspace(options = {}) {
219215
219505
  const builtInJavaFactory = hasProvider("java") && !java && !injectedJavaProvider && builtInJavaAvailable && javaProvider ? javaProvider[2].createJavaProjectClientFactory({
219216
219506
  runtimeAssetBaseUrl: javaRuntimeAssetBaseUrl ?? javaProvider[2].resolveBuiltInTraceJVMRuntimeAssetBaseUrl(
219217
219507
  options.assetBaseUrl ?? "/workers"
219218
- )
219508
+ ),
219509
+ workerUrl: javaProjectWorkerUrl ?? `${javaProvider[2].resolveBuiltInTraceJVMRuntimeAssetBaseUrl()}/browser-worker.js`
219219
219510
  }) : void 0;
219220
219511
  if (builtInJavaFactory) ownedWorkers.push(builtInJavaFactory);
219221
219512
  const builtInJava = builtInJavaFactory ? {