@ttsc/graph 0.30.4 → 0.31.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.
- package/README.md +122 -30
- package/lib/CapturedProcessOutput.d.ts +47 -0
- package/lib/CapturedProcessOutput.js +3 -0
- package/lib/CapturedProcessOutput.js.map +1 -0
- package/lib/ILauncherOption.d.ts +22 -0
- package/lib/ILauncherOption.js +3 -0
- package/lib/ILauncherOption.js.map +1 -0
- package/lib/IProjectOptions.d.ts +18 -0
- package/lib/IProjectOptions.js +3 -0
- package/lib/IProjectOptions.js.map +1 -0
- package/lib/ParsedLauncherOptions.d.ts +13 -0
- package/lib/ParsedLauncherOptions.js +3 -0
- package/lib/ParsedLauncherOptions.js.map +1 -0
- package/lib/TtscGraphApplication.d.ts +38 -1
- package/lib/TtscGraphApplication.js +26 -1
- package/lib/TtscGraphApplication.js.map +1 -1
- package/lib/TtscGraphLauncherArguments.d.ts +115 -0
- package/lib/TtscGraphLauncherArguments.js +181 -0
- package/lib/TtscGraphLauncherArguments.js.map +1 -0
- package/lib/TtscGraphViewSnapshot.d.ts +35 -0
- package/lib/TtscGraphViewSnapshot.js +48 -0
- package/lib/TtscGraphViewSnapshot.js.map +1 -0
- package/lib/index.d.ts +9 -24
- package/lib/index.js +6 -128
- package/lib/index.js.map +1 -1
- package/lib/internal/GraphProcessTrace.d.ts +1 -0
- package/lib/internal/GraphProcessTrace.js +235 -0
- package/lib/internal/GraphProcessTrace.js.map +1 -0
- package/lib/launcherArgs.d.ts +75 -16
- package/lib/launcherArgs.js +77 -8
- package/lib/launcherArgs.js.map +1 -1
- package/lib/model/IArtifactDirectory.d.ts +26 -0
- package/lib/model/IArtifactDirectory.js +3 -0
- package/lib/model/IArtifactDirectory.js.map +1 -0
- package/lib/model/IArtifactInputs.d.ts +19 -0
- package/lib/model/IArtifactInputs.js +3 -0
- package/lib/model/IArtifactInputs.js.map +1 -0
- package/lib/model/IPublishedArtifacts.d.ts +76 -0
- package/lib/model/IPublishedArtifacts.js +3 -0
- package/lib/model/IPublishedArtifacts.js.map +1 -0
- package/lib/model/IPublishedArtifactsResident.d.ts +19 -0
- package/lib/model/IPublishedArtifactsResident.js +3 -0
- package/lib/model/IPublishedArtifactsResident.js.map +1 -0
- package/lib/model/ITtscLintDaemonTarget.d.ts +20 -0
- package/lib/model/ITtscLintDaemonTarget.js +3 -0
- package/lib/model/ITtscLintDaemonTarget.js.map +1 -0
- package/lib/model/TtscGraphLinePeer.d.ts +146 -0
- package/lib/model/TtscGraphLinePeer.js +213 -0
- package/lib/model/TtscGraphLinePeer.js.map +1 -0
- package/lib/model/TtscGraphMemory.d.ts +156 -16
- package/lib/model/TtscGraphMemory.js +228 -222
- package/lib/model/TtscGraphMemory.js.map +1 -1
- package/lib/model/TtscGraphNativeArguments.d.ts +40 -0
- package/lib/model/TtscGraphNativeArguments.js +64 -0
- package/lib/model/TtscGraphNativeArguments.js.map +1 -0
- package/lib/model/TtscGraphNodeId.d.ts +55 -3
- package/lib/model/TtscGraphNodeId.js +40 -2
- package/lib/model/TtscGraphNodeId.js.map +1 -1
- package/lib/model/TtscGraphProjection.d.ts +156 -0
- package/lib/model/TtscGraphProjection.js +390 -0
- package/lib/model/TtscGraphProjection.js.map +1 -0
- package/lib/model/TtscGraphProtocol.d.ts +28 -0
- package/lib/model/TtscGraphProtocol.js +928 -0
- package/lib/model/TtscGraphProtocol.js.map +1 -0
- package/lib/model/TtscGraphReadonly.d.ts +15 -0
- package/lib/model/TtscGraphReadonly.js +3 -0
- package/lib/model/TtscGraphReadonly.js.map +1 -0
- package/lib/model/TtscGraphRequestOptions.d.ts +16 -0
- package/lib/model/TtscGraphRequestOptions.js +3 -0
- package/lib/model/TtscGraphRequestOptions.js.map +1 -0
- package/lib/model/TtscGraphSession.d.ts +82 -36
- package/lib/model/TtscGraphSession.js +164 -1238
- package/lib/model/TtscGraphSession.js.map +1 -1
- package/lib/model/TtscGraphSessionOptions.d.ts +20 -0
- package/lib/model/TtscGraphSessionOptions.js +3 -0
- package/lib/model/TtscGraphSessionOptions.js.map +1 -0
- package/lib/model/TtscGraphSessionState.d.ts +187 -0
- package/lib/model/TtscGraphSessionState.js +417 -0
- package/lib/model/TtscGraphSessionState.js.map +1 -0
- package/lib/model/TtscGraphShardStore.d.ts +64 -3
- package/lib/model/TtscGraphShardStore.js +85 -15
- package/lib/model/TtscGraphShardStore.js.map +1 -1
- package/lib/model/TtscGraphSourceReader.d.ts +31 -8
- package/lib/model/TtscGraphSourceReader.js +37 -13
- package/lib/model/TtscGraphSourceReader.js.map +1 -1
- package/lib/model/TtscLintDaemon.d.ts +35 -17
- package/lib/model/TtscLintDaemon.js +39 -117
- package/lib/model/TtscLintDaemon.js.map +1 -1
- package/lib/model/TtscLintDaemonState.d.ts +69 -0
- package/lib/model/TtscLintDaemonState.js +166 -0
- package/lib/model/TtscLintDaemonState.js.map +1 -0
- package/lib/model/copyGraphRecords.d.ts +14 -0
- package/lib/model/copyGraphRecords.js +19 -0
- package/lib/model/copyGraphRecords.js.map +1 -0
- package/lib/model/copyGraphSnapshot.d.ts +17 -0
- package/lib/model/copyGraphSnapshot.js +33 -0
- package/lib/model/copyGraphSnapshot.js.map +1 -0
- package/lib/model/loadGraph.d.ts +19 -10
- package/lib/model/loadGraph.js +21 -12
- package/lib/model/loadGraph.js.map +1 -1
- package/lib/model/publishedArtifacts.d.ts +78 -97
- package/lib/model/publishedArtifacts.js +271 -85
- package/lib/model/publishedArtifacts.js.map +1 -1
- package/lib/nativeExecutable.d.ts +19 -8
- package/lib/nativeExecutable.js +75 -15
- package/lib/nativeExecutable.js.map +1 -1
- package/lib/reduce.d.ts +19 -45
- package/lib/reduce.js +19 -3
- package/lib/reduce.js.map +1 -1
- package/lib/resolveGraphBinary.d.ts +9 -0
- package/lib/resolveGraphBinary.js +11 -3
- package/lib/resolveGraphBinary.js.map +1 -1
- package/lib/runGraph.d.ts +21 -0
- package/lib/runGraph.js +83 -0
- package/lib/runGraph.js.map +1 -0
- package/lib/server/IResolvedGraphHandle.d.ts +22 -0
- package/lib/server/IResolvedGraphHandle.js +3 -0
- package/lib/server/IResolvedGraphHandle.js.map +1 -0
- package/lib/server/createServer.d.ts +14 -10
- package/lib/server/createServer.js +42 -39
- package/lib/server/createServer.js.map +1 -1
- package/lib/server/exportSurface.d.ts +23 -1
- package/lib/server/exportSurface.js +23 -1
- package/lib/server/exportSurface.js.map +1 -1
- package/lib/server/formatGraphFailure.d.ts +20 -0
- package/lib/server/formatGraphFailure.js +35 -0
- package/lib/server/formatGraphFailure.js.map +1 -0
- package/lib/server/pathPolicy.d.ts +70 -5
- package/lib/server/pathPolicy.js +66 -4
- package/lib/server/pathPolicy.js.map +1 -1
- package/lib/server/resolveHandle.d.ts +10 -5
- package/lib/server/resolveHandle.js +39 -7
- package/lib/server/resolveHandle.js.map +1 -1
- package/lib/server/resultAudit.d.ts +17 -14
- package/lib/server/resultAudit.js +56 -27
- package/lib/server/resultAudit.js.map +1 -1
- package/lib/server/resultNext.d.ts +26 -1
- package/lib/server/resultNext.js +14 -0
- package/lib/server/resultNext.js.map +1 -1
- package/lib/server/runDetails.d.ts +72 -15
- package/lib/server/runDetails.js +104 -69
- package/lib/server/runDetails.js.map +1 -1
- package/lib/server/runEntrypoints.d.ts +9 -0
- package/lib/server/runEntrypoints.js +9 -0
- package/lib/server/runEntrypoints.js.map +1 -1
- package/lib/server/runLookup.d.ts +13 -3
- package/lib/server/runLookup.js +19 -6
- package/lib/server/runLookup.js.map +1 -1
- package/lib/server/runOverview.d.ts +13 -4
- package/lib/server/runOverview.js +13 -4
- package/lib/server/runOverview.js.map +1 -1
- package/lib/server/runTour.d.ts +9 -0
- package/lib/server/runTour.js +33 -65
- package/lib/server/runTour.js.map +1 -1
- package/lib/server/runTrace.d.ts +25 -1
- package/lib/server/runTrace.js +133 -88
- package/lib/server/runTrace.js.map +1 -1
- package/lib/server/startServer.d.ts +16 -0
- package/lib/server/startServer.js +24 -1
- package/lib/server/startServer.js.map +1 -1
- package/lib/structures/ITtscGraphApplication.d.ts +95 -41
- package/lib/structures/ITtscGraphDecorator.d.ts +18 -0
- package/lib/structures/ITtscGraphDetails.d.ts +81 -6
- package/lib/structures/ITtscGraphDocTag.d.ts +17 -8
- package/lib/structures/ITtscGraphDump.d.ts +106 -8
- package/lib/structures/ITtscGraphEdge.d.ts +14 -2
- package/lib/structures/ITtscGraphEntrypoints.d.ts +81 -6
- package/lib/structures/ITtscGraphEscape.d.ts +24 -2
- package/lib/structures/ITtscGraphEvidence.d.ts +9 -0
- package/lib/structures/ITtscGraphLookup.d.ts +42 -9
- package/lib/structures/ITtscGraphNext.d.ts +12 -1
- package/lib/structures/ITtscGraphNode.d.ts +38 -11
- package/lib/structures/ITtscGraphOverview.d.ts +81 -6
- package/lib/structures/ITtscGraphSnapshot.d.ts +97 -2
- package/lib/structures/ITtscGraphSpan.d.ts +9 -0
- package/lib/structures/ITtscGraphTour.d.ts +83 -9
- package/lib/structures/ITtscGraphTrace.d.ts +99 -14
- package/lib/structures/RawDump.d.ts +22 -0
- package/lib/structures/RawDump.js +3 -0
- package/lib/structures/RawDump.js.map +1 -0
- package/lib/structures/RawEdge.d.ts +20 -0
- package/lib/structures/RawEdge.js +3 -0
- package/lib/structures/RawEdge.js.map +1 -0
- package/lib/structures/RawNode.d.ts +26 -0
- package/lib/structures/RawNode.js +3 -0
- package/lib/structures/RawNode.js.map +1 -0
- package/lib/structures/TtscGraphArtifactNodeKind.d.ts +9 -0
- package/lib/structures/TtscGraphArtifactNodeKind.js +9 -0
- package/lib/structures/TtscGraphArtifactNodeKind.js.map +1 -1
- package/lib/structures/TtscGraphDumpEdgeKind.d.ts +15 -1
- package/lib/structures/TtscGraphDumpNodeKind.d.ts +9 -0
- package/lib/structures/TtscGraphEdgeKind.d.ts +13 -4
- package/lib/structures/TtscGraphNodeKind.d.ts +9 -0
- package/lib/structures/TtscGraphNodeModifier.d.ts +9 -0
- package/lib/structures/ViewerLink.d.ts +20 -0
- package/lib/structures/ViewerLink.js +3 -0
- package/lib/structures/ViewerLink.js.map +1 -0
- package/lib/structures/ViewerNode.d.ts +24 -0
- package/lib/structures/ViewerNode.js +3 -0
- package/lib/structures/ViewerNode.js.map +1 -0
- package/lib/structures/ViewerPayload.d.ts +42 -0
- package/lib/structures/ViewerPayload.js +3 -0
- package/lib/structures/ViewerPayload.js.map +1 -0
- package/lib/view.d.ts +9 -0
- package/lib/view.js +203 -91
- package/lib/view.js.map +1 -1
- package/lib/viewer/viewer.js +1 -1
- package/package.json +8 -6
- package/src/CapturedProcessOutput.ts +50 -0
- package/src/ILauncherOption.ts +24 -0
- package/src/IProjectOptions.ts +19 -0
- package/src/ParsedLauncherOptions.ts +13 -0
- package/src/TtscGraphApplication.ts +38 -1
- package/src/TtscGraphLauncherArguments.ts +207 -0
- package/src/TtscGraphViewSnapshot.ts +46 -0
- package/src/index.ts +9 -160
- package/src/internal/GraphProcessTrace.ts +242 -0
- package/src/launcherArgs.ts +89 -23
- package/src/model/IArtifactDirectory.ts +27 -0
- package/src/model/IArtifactInputs.ts +21 -0
- package/src/model/IPublishedArtifacts.ts +81 -0
- package/src/model/IPublishedArtifactsResident.ts +24 -0
- package/src/model/ITtscLintDaemonTarget.ts +22 -0
- package/src/model/TtscGraphLinePeer.ts +318 -0
- package/src/model/TtscGraphMemory.ts +284 -246
- package/src/model/TtscGraphNativeArguments.ts +67 -0
- package/src/model/TtscGraphNodeId.ts +57 -3
- package/src/model/TtscGraphProjection.ts +473 -0
- package/src/model/TtscGraphProtocol.ts +90 -0
- package/src/model/TtscGraphReadonly.ts +17 -0
- package/src/model/TtscGraphRequestOptions.ts +16 -0
- package/src/model/TtscGraphSession.ts +196 -475
- package/src/model/TtscGraphSessionOptions.ts +22 -0
- package/src/model/TtscGraphSessionState.ts +558 -0
- package/src/model/TtscGraphShardStore.ts +99 -23
- package/src/model/TtscGraphSourceReader.ts +37 -15
- package/src/model/TtscLintDaemon.ts +55 -136
- package/src/model/TtscLintDaemonState.ts +174 -0
- package/src/model/copyGraphRecords.ts +17 -0
- package/src/model/copyGraphSnapshot.ts +30 -0
- package/src/model/loadGraph.ts +23 -12
- package/src/model/publishedArtifacts.ts +361 -182
- package/src/nativeExecutable.ts +93 -26
- package/src/reduce.ts +24 -51
- package/src/resolveGraphBinary.ts +13 -3
- package/src/runGraph.ts +90 -0
- package/src/server/IResolvedGraphHandle.ts +24 -0
- package/src/server/createServer.ts +16 -22
- package/src/server/exportSurface.ts +23 -1
- package/src/server/formatGraphFailure.ts +32 -0
- package/src/server/pathPolicy.ts +70 -5
- package/src/server/resolveHandle.ts +45 -14
- package/src/server/resultAudit.ts +58 -27
- package/src/server/resultNext.ts +26 -1
- package/src/server/runDetails.ts +138 -73
- package/src/server/runEntrypoints.ts +13 -1
- package/src/server/runLookup.ts +23 -7
- package/src/server/runOverview.ts +17 -5
- package/src/server/runTour.ts +44 -82
- package/src/server/runTrace.ts +175 -102
- package/src/server/startServer.ts +29 -1
- package/src/structures/ITtscGraphApplication.ts +95 -41
- package/src/structures/ITtscGraphDecorator.ts +18 -0
- package/src/structures/ITtscGraphDetails.ts +81 -6
- package/src/structures/ITtscGraphDocTag.ts +17 -8
- package/src/structures/ITtscGraphDump.ts +106 -8
- package/src/structures/ITtscGraphEdge.ts +14 -2
- package/src/structures/ITtscGraphEntrypoints.ts +81 -6
- package/src/structures/ITtscGraphEscape.ts +24 -2
- package/src/structures/ITtscGraphEvidence.ts +9 -0
- package/src/structures/ITtscGraphLookup.ts +42 -9
- package/src/structures/ITtscGraphNext.ts +12 -1
- package/src/structures/ITtscGraphNode.ts +38 -11
- package/src/structures/ITtscGraphOverview.ts +88 -6
- package/src/structures/ITtscGraphSnapshot.ts +117 -2
- package/src/structures/ITtscGraphSpan.ts +9 -0
- package/src/structures/ITtscGraphTour.ts +83 -9
- package/src/structures/ITtscGraphTrace.ts +100 -14
- package/src/structures/RawDump.ts +25 -0
- package/src/structures/RawEdge.ts +22 -0
- package/src/structures/RawNode.ts +31 -0
- package/src/structures/TtscGraphArtifactNodeKind.ts +9 -0
- package/src/structures/TtscGraphDumpEdgeKind.ts +15 -1
- package/src/structures/TtscGraphDumpNodeKind.ts +9 -0
- package/src/structures/TtscGraphEdgeKind.ts +13 -4
- package/src/structures/TtscGraphNodeKind.ts +9 -0
- package/src/structures/TtscGraphNodeModifier.ts +9 -0
- package/src/structures/ViewerLink.ts +22 -0
- package/src/structures/ViewerNode.ts +28 -0
- package/src/structures/ViewerPayload.ts +52 -0
- package/src/view.ts +208 -110
- package/src/viewer/legend.ts +119 -27
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
|
|
3
|
+
import { GraphProcessTrace } from "../internal/GraphProcessTrace";
|
|
4
|
+
|
|
5
|
+
const TERMINATION_GRACE_MS = 1_000;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Native line transport shared by graph and lint resident owners.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/common.md#principled-implementation Node stdout line framing and explicit process events preserve the native protocols while request correlation remains with their state owners.
|
|
11
|
+
* @evidence contracts/common.md#clear-and-simple-design A connection exposes only liveness, diagnostics, writes and retirement; EOF retirement and authoritative process/stdio joining serve both state owners.
|
|
12
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The default adapter invokes the actual binary and argv without a shell, synthetic responses or replaced foreign methods.
|
|
13
|
+
* @evidence contracts/common.md#meaningful-documentation Connection comments state line/event ownership, bounded diagnostic capture and the difference between reader retirement and process termination.
|
|
14
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms open owns process and line setup; the namespace groups its connection protocol.
|
|
15
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work Resident state owners decide peer reuse; this namespace adds no result cache.
|
|
16
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources open and its returned close implementation own actual child/reader acquisition and retirement.
|
|
17
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation Events, Connection and open document the native representation and operations rather than the namespace grouping them.
|
|
18
|
+
*/
|
|
19
|
+
export namespace TtscGraphLinePeer {
|
|
20
|
+
/**
|
|
21
|
+
* Events produced by a native child, addressed by its connection owner.
|
|
22
|
+
*
|
|
23
|
+
* @evidence contracts/common.md#principled-implementation Complete stdout lines, startup errors and nullable code/signal exit coordinates represent distinct Node process events.
|
|
24
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
25
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
26
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
27
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
28
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
29
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
30
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
31
|
+
*/
|
|
32
|
+
export interface Events {
|
|
33
|
+
/**
|
|
34
|
+
* One complete stdout line.
|
|
35
|
+
*
|
|
36
|
+
* @evidence contracts/common.md#principled-implementation The callback receives a complete UTF-8 stdout line without imposing graph syntax or response correlation.
|
|
37
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
38
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
39
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
40
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
41
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
42
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
43
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
44
|
+
*/
|
|
45
|
+
line(line: string): void;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Child startup or transport failure.
|
|
49
|
+
*
|
|
50
|
+
* @evidence contracts/common.md#principled-implementation The callback preserves the actual child Error as a failure event rather than a synthetic success frame.
|
|
51
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
52
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
53
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
54
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
55
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
56
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
57
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
58
|
+
*/
|
|
59
|
+
error(error: Error): void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Actual process exit; a retired reader cannot publish later lines.
|
|
63
|
+
*
|
|
64
|
+
* @evidence contracts/common.md#principled-implementation Nullable numeric code and Node signal name preserve whether a native process exited normally or by signal.
|
|
65
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
66
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
67
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
68
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
69
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
70
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
71
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
72
|
+
*/
|
|
73
|
+
exit(code: number | null, signal: NodeJS.Signals | null): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Owned native handle used by resident state machines.
|
|
78
|
+
*
|
|
79
|
+
* @evidence contracts/common.md#principled-implementation A connection groups actual process liveness, bounded diagnostics, writes and reader/process retirement under one owned identity.
|
|
80
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
81
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
82
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
83
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
84
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
85
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
86
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
87
|
+
*/
|
|
88
|
+
export interface Connection {
|
|
89
|
+
/**
|
|
90
|
+
* Up to the last 65,536 UTF-16 code units of diagnostics when capture is
|
|
91
|
+
* selected.
|
|
92
|
+
*/
|
|
93
|
+
readonly stderr: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Whether the underlying child still has no exit status.
|
|
97
|
+
*
|
|
98
|
+
* @evidence contracts/common.md#principled-implementation Liveness reflects the Node child exitCode/signalCode pair; a sent kill signal alone is not a completed exit.
|
|
99
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
100
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
101
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
102
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
103
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
104
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
105
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
106
|
+
*/
|
|
107
|
+
alive(): boolean;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Write one complete request; errors belong to the request owner.
|
|
111
|
+
*
|
|
112
|
+
* @evidence contracts/common.md#principled-implementation The actual stdin callback transfers write failure to its request owner without manufacturing a response.
|
|
113
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
114
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
115
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
116
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
117
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
118
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
119
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
120
|
+
*/
|
|
121
|
+
write(line: string, done: (error?: Error | null) => void): void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Detach the reader, or end stdin and await the owned process and stdio.
|
|
125
|
+
*
|
|
126
|
+
* @evidence contracts/common.md#principled-implementation Reader retirement is distinct from joined shutdown; repeated close(true) returns the same completion, which rejects unknown or forced termination.
|
|
127
|
+
* @evidence contracts/common.md#clear-and-simple-design The signature transfers only its stated process operation or event; resident state owns protocol decisions.
|
|
128
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Node-native representations remain explicit rather than shell strings, process stand-ins or replaced foreign methods.
|
|
129
|
+
* @evidence contracts/common.md#meaningful-documentation Native member prose states event, liveness or retirement meaning needed by the state owner.
|
|
130
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms This boundary signature defines an operation or event; open and its returned adapter implementations own the work.
|
|
131
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The boundary descriptor computes no reusable graph result; state coordinates continued peer reuse.
|
|
132
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The signature acquires no handle itself; open and the returned close implementation own actual lifetime.
|
|
133
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node numeric exit status, signal names, stdin callbacks and decoded line strings preserve native process semantics without assuming shell quoting or platform path spelling.
|
|
134
|
+
*/
|
|
135
|
+
close(terminate: boolean): void | Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Open the actual Node child and attach its reader and diagnostic drain.
|
|
140
|
+
*
|
|
141
|
+
* EOF permits the resident loop to finish. close(true) resolves only after
|
|
142
|
+
* Node joins the process and all stdio after a normal numeric exit, including
|
|
143
|
+
* a nonzero status already delivered to the request owner. A transport
|
|
144
|
+
* failure, signal, forced kill or unjoined deadline rejects instead.
|
|
145
|
+
*
|
|
146
|
+
* @evidence contracts/common.md#principled-implementation Node spawn and readline preserve executable, argv and complete lines; the close callback's private retirementError decision accepts normal numeric exit after process/stdio join while transport failure, unknown status, signal and forced termination remain failures. Exit events separately preserve failed request outcomes.
|
|
147
|
+
* @evidence contracts/common.md#clear-and-simple-design One adapter owns actual process I/O and joined EOF shutdown; its private retirementError helper qualifies completion without changing the resident state owners' protocol or diagnostic decisions.
|
|
148
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Real process APIs retain their defaults and explicit argv; no test-only executable or response path is supplied.
|
|
149
|
+
* @evidence contracts/common.md#meaningful-documentation Prose explains EOF completion and unknown/forced failure and connection comments describe bounded stderr and retirement.
|
|
150
|
+
* @evidence contracts/performance.md#efficient-algorithms One spawn/reader setup is constant-count; writes and line decoding process frame bytes once, while captured diagnostics retain a tail of at most 65,536 UTF-16 code units and draining avoids pipe backpressure.
|
|
151
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work This effectful opener creates one native peer; resident state determines when that peer remains reusable or must be replaced.
|
|
152
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources The returned close owns one reader and child, detaches once and terminates at most once; a delivery deadline bounds an unread pipe after the caller yields, while child grace starts after EOF delivery. Streams drain through authoritative completion; an unjoined deadline first rejects and then releases only this connection's handles without terminating foreign pipe holders.
|
|
153
|
+
* @evidence contracts/portability.md#os-neutral-implementation Node spawn receives an executable and argv vector directly with windowsHide; Node stream/process APIs own native signals and optional cwd, without a shell or manual path normalization.
|
|
154
|
+
*/
|
|
155
|
+
export function open(
|
|
156
|
+
binary: string,
|
|
157
|
+
args: string[],
|
|
158
|
+
events: Events,
|
|
159
|
+
options: { cwd?: string; stderr: "capture" | "drain" },
|
|
160
|
+
): Connection {
|
|
161
|
+
const child = GraphProcessTrace.spawn(binary, args, {
|
|
162
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
163
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
164
|
+
windowsHide: true,
|
|
165
|
+
});
|
|
166
|
+
const lines = readline.createInterface({ input: child.stdout });
|
|
167
|
+
let stderr = "";
|
|
168
|
+
let readerClosed = false;
|
|
169
|
+
let terminated = false;
|
|
170
|
+
let joined = false;
|
|
171
|
+
let forced = false;
|
|
172
|
+
let joinFailed = false;
|
|
173
|
+
let failure: Error | undefined;
|
|
174
|
+
let force: ReturnType<typeof setTimeout> | undefined;
|
|
175
|
+
let flushDeadline: ReturnType<typeof setTimeout> | undefined;
|
|
176
|
+
let deadline: ReturnType<typeof setTimeout> | undefined;
|
|
177
|
+
let resolve!: () => void;
|
|
178
|
+
let reject!: (error: Error) => void;
|
|
179
|
+
const completion = new Promise<void>((res, rej) => {
|
|
180
|
+
resolve = res;
|
|
181
|
+
reject = rej;
|
|
182
|
+
});
|
|
183
|
+
// Existing fire-and-forget disposal remains safe; awaiting the original
|
|
184
|
+
// promise still exposes failure instead of turning it into joined success.
|
|
185
|
+
void completion.catch(() => undefined);
|
|
186
|
+
child.on("error", (error) => {
|
|
187
|
+
failure = error;
|
|
188
|
+
});
|
|
189
|
+
for (const stream of [child.stdin, child.stdout, child.stderr])
|
|
190
|
+
stream.on("error", (error) => {
|
|
191
|
+
failure = error;
|
|
192
|
+
events.error(error);
|
|
193
|
+
});
|
|
194
|
+
child.once("close", (code, signal) => {
|
|
195
|
+
joined = true;
|
|
196
|
+
if (force !== undefined) clearTimeout(force);
|
|
197
|
+
if (flushDeadline !== undefined) clearTimeout(flushDeadline);
|
|
198
|
+
if (deadline !== undefined) clearTimeout(deadline);
|
|
199
|
+
if (joinFailed) return;
|
|
200
|
+
const error = retirementError(code, signal, forced, failure);
|
|
201
|
+
if (error !== undefined) reject(error);
|
|
202
|
+
else resolve();
|
|
203
|
+
});
|
|
204
|
+
const captureStderr = (chunk: string) => {
|
|
205
|
+
stderr = (stderr + chunk).slice(-64 * 1024);
|
|
206
|
+
};
|
|
207
|
+
if (options.stderr === "capture") {
|
|
208
|
+
child.stderr.setEncoding("utf8");
|
|
209
|
+
child.stderr.on("data", captureStderr);
|
|
210
|
+
} else child.stderr.resume();
|
|
211
|
+
lines.on("line", events.line);
|
|
212
|
+
child.on("error", events.error);
|
|
213
|
+
child.on("exit", events.exit);
|
|
214
|
+
const forceTerminationAndJoin = () => {
|
|
215
|
+
if (joined || deadline !== undefined) return;
|
|
216
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
217
|
+
forced = true;
|
|
218
|
+
try {
|
|
219
|
+
child.kill("SIGKILL");
|
|
220
|
+
} catch (error) {
|
|
221
|
+
failure = error instanceof Error ? error : new Error(String(error));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
deadline = setTimeout(() => {
|
|
225
|
+
if (joined) return;
|
|
226
|
+
// Failure is final before destroying our streams can induce Node close.
|
|
227
|
+
// Foreign descendants may retain inherited pipe endpoints; release our
|
|
228
|
+
// endpoints without claiming their lifetime was joined or killing them.
|
|
229
|
+
joinFailed = true;
|
|
230
|
+
reject(new Error("@ttsc/graph: peer shutdown could not be joined"));
|
|
231
|
+
if (force !== undefined) clearTimeout(force);
|
|
232
|
+
if (flushDeadline !== undefined) clearTimeout(flushDeadline);
|
|
233
|
+
if (deadline !== undefined) clearTimeout(deadline);
|
|
234
|
+
lines.removeListener("line", events.line);
|
|
235
|
+
lines.close();
|
|
236
|
+
child.removeListener("error", events.error);
|
|
237
|
+
child.removeListener("exit", events.exit);
|
|
238
|
+
child.stderr.removeListener("data", captureStderr);
|
|
239
|
+
for (const stream of [child.stdin, child.stdout, child.stderr])
|
|
240
|
+
stream.destroy();
|
|
241
|
+
child.unref();
|
|
242
|
+
}, TERMINATION_GRACE_MS);
|
|
243
|
+
};
|
|
244
|
+
const startTerminationGrace = () => {
|
|
245
|
+
if (flushDeadline !== undefined) clearTimeout(flushDeadline);
|
|
246
|
+
if (joined || force !== undefined || deadline !== undefined) return;
|
|
247
|
+
force = setTimeout(forceTerminationAndJoin, TERMINATION_GRACE_MS);
|
|
248
|
+
};
|
|
249
|
+
return {
|
|
250
|
+
get stderr() {
|
|
251
|
+
return stderr;
|
|
252
|
+
},
|
|
253
|
+
alive: () => child.exitCode === null && child.signalCode === null,
|
|
254
|
+
write: (line, done) => {
|
|
255
|
+
child.stdin.write(line, done);
|
|
256
|
+
},
|
|
257
|
+
close: (terminate) => {
|
|
258
|
+
if (!readerClosed) {
|
|
259
|
+
readerClosed = true;
|
|
260
|
+
lines.close();
|
|
261
|
+
}
|
|
262
|
+
if (!terminate) return;
|
|
263
|
+
if (terminated || joined) return completion;
|
|
264
|
+
terminated = true;
|
|
265
|
+
// Keep output drained until Node's close event joins both the process
|
|
266
|
+
// and inherited stdio. EOF permits the real resident loop to finish.
|
|
267
|
+
child.stdout.resume();
|
|
268
|
+
// The child cannot act on EOF until the pipe finishes. Starting its
|
|
269
|
+
// grace period before that callback charged a blocked parent event
|
|
270
|
+
// loop against a shutdown request it had not yet delivered.
|
|
271
|
+
if (!child.stdin.destroyed) {
|
|
272
|
+
try {
|
|
273
|
+
child.stdin.end(startTerminationGrace);
|
|
274
|
+
// An unread pipe can prevent the EOF callback indefinitely. Start
|
|
275
|
+
// delivery's own deadline only after synchronous caller work yields.
|
|
276
|
+
queueMicrotask(() => {
|
|
277
|
+
if (joined || force !== undefined || deadline !== undefined)
|
|
278
|
+
return;
|
|
279
|
+
flushDeadline = setTimeout(
|
|
280
|
+
forceTerminationAndJoin,
|
|
281
|
+
TERMINATION_GRACE_MS,
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
} catch (error) {
|
|
285
|
+
failure = error instanceof Error ? error : new Error(String(error));
|
|
286
|
+
child.stdin.destroy();
|
|
287
|
+
startTerminationGrace();
|
|
288
|
+
}
|
|
289
|
+
} else startTerminationGrace();
|
|
290
|
+
return completion;
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Qualify an authoritative Node close event for resource retirement.
|
|
297
|
+
*
|
|
298
|
+
* A normal numeric exit establishes joined release regardless of the work's
|
|
299
|
+
* status. The exit callback owns that status; retirement still rejects an
|
|
300
|
+
* unknown exit, signal, forced termination or actual transport failure. This
|
|
301
|
+
* internal decision does not establish joining before Node closes stdio.
|
|
302
|
+
*
|
|
303
|
+
* @internal
|
|
304
|
+
*/
|
|
305
|
+
export function retirementError(
|
|
306
|
+
code: number | null,
|
|
307
|
+
signal: NodeJS.Signals | null,
|
|
308
|
+
forced: boolean,
|
|
309
|
+
failure?: Error,
|
|
310
|
+
): Error | undefined {
|
|
311
|
+
if (failure !== undefined) return failure;
|
|
312
|
+
if (forced || code === null || signal !== null)
|
|
313
|
+
return new Error(
|
|
314
|
+
`@ttsc/graph: peer shutdown failed (code=${String(code)}, signal=${String(signal)}, forced=${forced})`,
|
|
315
|
+
);
|
|
316
|
+
return undefined;
|
|
317
|
+
}
|
|
318
|
+
}
|