@ttsc/graph 0.36.3 → 0.36.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.
- package/lib/IProjectOptions.d.ts +4 -2
- package/lib/TtscGraphLauncherArguments.js +7 -0
- package/lib/TtscGraphLauncherArguments.js.map +1 -1
- package/lib/launcherArgs.js +4 -0
- package/lib/launcherArgs.js.map +1 -1
- package/lib/model/TtscGraphLinePeer.d.ts +1 -0
- package/lib/model/TtscGraphLinePeer.js +1 -0
- package/lib/model/TtscGraphLinePeer.js.map +1 -1
- package/lib/model/TtscGraphNativeArguments.d.ts +35 -8
- package/lib/model/TtscGraphNativeArguments.js +48 -8
- package/lib/model/TtscGraphNativeArguments.js.map +1 -1
- package/lib/model/TtscGraphSession.d.ts +1 -0
- package/lib/model/TtscGraphSession.js +19 -6
- package/lib/model/TtscGraphSession.js.map +1 -1
- package/lib/model/TtscGraphSessionOptions.d.ts +2 -0
- package/lib/model/TtscLintDaemon.d.ts +2 -1
- package/lib/model/TtscLintDaemon.js +8 -2
- package/lib/model/TtscLintDaemon.js.map +1 -1
- package/lib/model/loadGraph.d.ts +2 -0
- package/lib/model/loadGraph.js +8 -1
- package/lib/model/loadGraph.js.map +1 -1
- package/lib/model/publishedArtifacts.d.ts +14 -5
- package/lib/model/publishedArtifacts.js +40 -15
- package/lib/model/publishedArtifacts.js.map +1 -1
- package/lib/runGraph.js +4 -4
- package/lib/runGraph.js.map +1 -1
- package/lib/server/startServer.d.ts +2 -0
- package/lib/server/startServer.js +5 -1
- package/lib/server/startServer.js.map +1 -1
- package/lib/view.js +3 -0
- package/lib/view.js.map +1 -1
- package/package.json +10 -10
- package/src/IProjectOptions.ts +5 -2
- package/src/TtscGraphLauncherArguments.ts +7 -0
- package/src/launcherArgs.ts +4 -0
- package/src/model/TtscGraphLinePeer.ts +6 -1
- package/src/model/TtscGraphNativeArguments.ts +51 -7
- package/src/model/TtscGraphSession.ts +37 -11
- package/src/model/TtscGraphSessionOptions.ts +3 -0
- package/src/model/TtscLintDaemon.ts +6 -1
- package/src/model/loadGraph.ts +13 -1
- package/src/model/publishedArtifacts.ts +70 -23
- package/src/runGraph.ts +5 -4
- package/src/server/startServer.ts +8 -1
- package/src/view.ts +3 -0
|
@@ -1,18 +1,41 @@
|
|
|
1
|
+
import { resolveCompilerEnvironment } from "ttsc";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Native argument vectors
|
|
4
|
+
* Native argument vectors and publisher environments for graph processes.
|
|
3
5
|
*
|
|
4
6
|
* @evidence contracts/common.md#principled-implementation Separate argv elements preserve project and artifact coordinates exactly, while lint's existing equals-form flags carry its manifest and context.
|
|
5
|
-
* @evidence contracts/common.md#clear-and-simple-design
|
|
6
|
-
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
7
|
+
* @evidence contracts/common.md#clear-and-simple-design Resident vectors and publisher environments share one permission validator with one-shot launchers; the SDK owns environment capture.
|
|
8
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Native options are explicit argv fields rather than shell strings, coercions or fixture-specific arguments.
|
|
7
9
|
* @evidence contracts/common.md#meaningful-documentation Each builder states its protocol and the absence meaning of optional artifact/context coordinates.
|
|
8
|
-
* @evidenceExclude contracts/portability.md#os-neutral-implementation The namespace groups
|
|
9
|
-
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources returns plain
|
|
10
|
-
* @evidenceExclude contracts/performance.md#efficient-algorithms groups
|
|
10
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The namespace groups launch contracts; individual builders own native coordinate and environment representation.
|
|
11
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources returns plain launch data and holds no handle.
|
|
12
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms The namespace only groups builders; each member documents its actual work.
|
|
11
13
|
* @evidenceExclude contracts/performance.md#reuse-equivalent-work its builders recompute a small array per spawn, so nothing is shared.
|
|
12
14
|
*/
|
|
13
15
|
export namespace TtscGraphNativeArguments {
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
17
|
+
* Capture the compiler permission and inherited argument context for a
|
|
18
|
+
* publisher.
|
|
19
|
+
*
|
|
20
|
+
* @evidence contracts/common.md#principled-implementation The SDK's shared capture preserves inherited argv/cwd and appends an explicit permission assignment without changing process.env.
|
|
21
|
+
* @evidence contracts/common.md#clear-and-simple-design One environment builder serves synchronous publishers, resident daemons and asynchronous direct fallbacks.
|
|
22
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The existing compiler argument transport reaches real sidecars without inventing a new native flag or replacing compiler parsing.
|
|
23
|
+
* @evidence contracts/common.md#meaningful-documentation Native prose states compiler-context capture and its publisher consumers.
|
|
24
|
+
* @evidence contracts/portability.md#os-neutral-implementation The SDK applies native Windows channel aliases and preserves JSON argv and cwd without shell syntax.
|
|
25
|
+
* @evidence contracts/performance.md#efficient-algorithms Delegated capture copies environment keys and parses/serializes argument bytes only for an explicit permission.
|
|
26
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The publication owner captures once and shares this value across both verbs and their daemon or fallback; this builder adds no cache.
|
|
27
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The detached value transfers to the process owner and retains no handle or history.
|
|
28
|
+
*/
|
|
29
|
+
export function environment(
|
|
30
|
+
runExternalCode?: boolean,
|
|
31
|
+
inherited: NodeJS.ProcessEnv = process.env,
|
|
32
|
+
): NodeJS.ProcessEnv {
|
|
33
|
+
permission(runExternalCode);
|
|
34
|
+
return resolveCompilerEnvironment(runExternalCode, inherited);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Graph serve argv; absent artifacts or permission add no corresponding flag.
|
|
16
39
|
*
|
|
17
40
|
* @evidence contracts/common.md#principled-implementation Separate argv fields preserve graph cwd/config and the optional artifact path without shell parsing.
|
|
18
41
|
* @evidence contracts/common.md#clear-and-simple-design This builder is the actual facade's single launch-vector owner for serve.
|
|
@@ -27,6 +50,7 @@ export namespace TtscGraphNativeArguments {
|
|
|
27
50
|
cwd: string,
|
|
28
51
|
tsconfig: string,
|
|
29
52
|
artifacts: string | null,
|
|
53
|
+
runExternalCode?: boolean,
|
|
30
54
|
): string[] {
|
|
31
55
|
return [
|
|
32
56
|
"serve",
|
|
@@ -35,9 +59,29 @@ export namespace TtscGraphNativeArguments {
|
|
|
35
59
|
"--tsconfig",
|
|
36
60
|
tsconfig,
|
|
37
61
|
...(artifacts === null ? [] : ["--artifacts", artifacts]),
|
|
62
|
+
...permission(runExternalCode),
|
|
38
63
|
];
|
|
39
64
|
}
|
|
40
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Preserve omission or encode an explicit upstream permission assignment.
|
|
68
|
+
*
|
|
69
|
+
* @evidence contracts/common.md#principled-implementation A boolean assignment preserves true and false, while omission leaves inherited compiler arguments unchanged.
|
|
70
|
+
* @evidence contracts/common.md#clear-and-simple-design One validator supplies dump, viewer and resident argument construction.
|
|
71
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Nonboolean JavaScript input throws before a native invocation rather than granting permission through coercion.
|
|
72
|
+
* @evidence contracts/common.md#meaningful-documentation Native prose identifies optional-state and assignment semantics.
|
|
73
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The returned argv token contains no native path or shell syntax.
|
|
74
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms One scalar validation produces at most one token.
|
|
75
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work Each invocation constructs its own permission token.
|
|
76
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The returned array transfers to the caller without retaining state.
|
|
77
|
+
*/
|
|
78
|
+
export function permission(value?: boolean): string[] {
|
|
79
|
+
if (value === undefined) return [];
|
|
80
|
+
if (typeof value !== "boolean")
|
|
81
|
+
throw new TypeError("@ttsc/graph: runExternalCode must be a boolean");
|
|
82
|
+
return [`--runExternalCode=${String(value)}`];
|
|
83
|
+
}
|
|
84
|
+
|
|
41
85
|
/**
|
|
42
86
|
* Lint daemon argv; absent context retains the context-free rule contract.
|
|
43
87
|
*
|
|
@@ -43,6 +43,7 @@ export class TtscGraphSession {
|
|
|
43
43
|
private readonly cwd: string;
|
|
44
44
|
private readonly tsconfig: string;
|
|
45
45
|
private readonly binary: string;
|
|
46
|
+
private readonly runExternalCode: boolean | undefined;
|
|
46
47
|
/**
|
|
47
48
|
* The artifact answer the resident child was last handed, and the state of
|
|
48
49
|
* the inputs it came from.
|
|
@@ -71,6 +72,8 @@ export class TtscGraphSession {
|
|
|
71
72
|
private readonly retiredDaemons = new Set<Promise<void>>();
|
|
72
73
|
|
|
73
74
|
public constructor(options: TtscGraphSessionOptions) {
|
|
75
|
+
TtscGraphNativeArguments.permission(options.runExternalCode);
|
|
76
|
+
this.runExternalCode = options.runExternalCode;
|
|
74
77
|
// The producer belongs to this package's installation, so an MCP server
|
|
75
78
|
// started from any directory spawns a binary of its own release: the one
|
|
76
79
|
// of the graphed project's TypeScript line.
|
|
@@ -193,10 +196,15 @@ export class TtscGraphSession {
|
|
|
193
196
|
let failure: unknown;
|
|
194
197
|
try {
|
|
195
198
|
next = await publishArtifactsResident(
|
|
196
|
-
{
|
|
197
|
-
|
|
199
|
+
{
|
|
200
|
+
cwd: this.cwd,
|
|
201
|
+
tsconfig: this.tsconfig,
|
|
202
|
+
runExternalCode: this.runExternalCode,
|
|
203
|
+
signal: active,
|
|
204
|
+
},
|
|
205
|
+
(plugin, environment) => {
|
|
198
206
|
publishers.add(plugin.binary);
|
|
199
|
-
return this.daemon(plugin);
|
|
207
|
+
return this.daemon(plugin, environment);
|
|
200
208
|
},
|
|
201
209
|
this.resolver,
|
|
202
210
|
);
|
|
@@ -243,14 +251,22 @@ export class TtscGraphSession {
|
|
|
243
251
|
}
|
|
244
252
|
|
|
245
253
|
/** The open sidecar for one plugin, opened on first use. */
|
|
246
|
-
private async daemon(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
254
|
+
private async daemon(
|
|
255
|
+
plugin: {
|
|
256
|
+
binary: string;
|
|
257
|
+
manifest: string;
|
|
258
|
+
projectContext?: string;
|
|
259
|
+
},
|
|
260
|
+
environment: NodeJS.ProcessEnv,
|
|
261
|
+
): Promise<TtscLintDaemon> {
|
|
251
262
|
this.shutdown.signal.throwIfAborted();
|
|
252
263
|
const open = this.daemons.get(plugin.binary);
|
|
253
|
-
const identity = JSON.stringify([
|
|
264
|
+
const identity = JSON.stringify([
|
|
265
|
+
plugin.manifest,
|
|
266
|
+
plugin.projectContext,
|
|
267
|
+
environment.TTSC_TSGO_ARGS,
|
|
268
|
+
environment.TTSC_TSGO_ARGS_CWD,
|
|
269
|
+
]);
|
|
254
270
|
if (
|
|
255
271
|
open !== undefined &&
|
|
256
272
|
this.daemonIdentities.get(plugin.binary) === identity
|
|
@@ -261,7 +277,12 @@ export class TtscGraphSession {
|
|
|
261
277
|
await closing;
|
|
262
278
|
}
|
|
263
279
|
this.shutdown.signal.throwIfAborted();
|
|
264
|
-
const created = new TtscLintDaemon(
|
|
280
|
+
const created = new TtscLintDaemon(
|
|
281
|
+
plugin,
|
|
282
|
+
this.cwd,
|
|
283
|
+
this.tsconfig,
|
|
284
|
+
environment,
|
|
285
|
+
);
|
|
265
286
|
this.daemons.set(plugin.binary, created);
|
|
266
287
|
this.daemonIdentities.set(plugin.binary, identity);
|
|
267
288
|
return created;
|
|
@@ -285,7 +306,12 @@ export class TtscGraphSession {
|
|
|
285
306
|
throw new Error("@ttsc/graph: artifact publication was not admitted");
|
|
286
307
|
return TtscGraphLinePeer.open(
|
|
287
308
|
this.binary,
|
|
288
|
-
TtscGraphNativeArguments.serve(
|
|
309
|
+
TtscGraphNativeArguments.serve(
|
|
310
|
+
this.cwd,
|
|
311
|
+
this.tsconfig,
|
|
312
|
+
artifacts.file,
|
|
313
|
+
this.runExternalCode,
|
|
314
|
+
),
|
|
289
315
|
events,
|
|
290
316
|
{ stderr: "capture" },
|
|
291
317
|
);
|
|
@@ -17,6 +17,9 @@ export interface TtscGraphSessionOptions {
|
|
|
17
17
|
/** Project tsconfig passed to `ttscgraph serve`. */
|
|
18
18
|
tsconfig: string;
|
|
19
19
|
|
|
20
|
+
/** Upstream mapper permission for this session and every reload. */
|
|
21
|
+
runExternalCode?: boolean;
|
|
22
|
+
|
|
20
23
|
/**
|
|
21
24
|
* Absolute native binary path; omitted, the installed
|
|
22
25
|
* `@ttsc/graph-<platform>-<arch>` binary runs.
|
|
@@ -36,6 +36,7 @@ export class TtscLintDaemon {
|
|
|
36
36
|
private readonly target: ITtscLintDaemonTarget,
|
|
37
37
|
private readonly cwd: string,
|
|
38
38
|
private readonly tsconfig: string,
|
|
39
|
+
private readonly environment: NodeJS.ProcessEnv = TtscGraphNativeArguments.environment(),
|
|
39
40
|
) {
|
|
40
41
|
this.state = new TtscLintDaemonState((events) =>
|
|
41
42
|
TtscGraphLinePeer.open(
|
|
@@ -47,7 +48,11 @@ export class TtscLintDaemon {
|
|
|
47
48
|
this.target.projectContext,
|
|
48
49
|
),
|
|
49
50
|
events,
|
|
50
|
-
{
|
|
51
|
+
{
|
|
52
|
+
cwd: this.cwd,
|
|
53
|
+
stderr: "drain",
|
|
54
|
+
env: this.environment,
|
|
55
|
+
},
|
|
51
56
|
),
|
|
52
57
|
);
|
|
53
58
|
}
|
package/src/model/loadGraph.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { captureProcessOutput, ensureExecutable } from "../nativeExecutable";
|
|
|
6
6
|
import { resolveGraphBinary } from "../resolveGraphBinary";
|
|
7
7
|
import { ITtscGraphDump } from "../structures/ITtscGraphDump";
|
|
8
8
|
import { TtscGraphMemory } from "./TtscGraphMemory";
|
|
9
|
+
import { TtscGraphNativeArguments } from "./TtscGraphNativeArguments";
|
|
9
10
|
import { publishArtifacts } from "./publishedArtifacts";
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -48,6 +49,9 @@ export function loadGraph(
|
|
|
48
49
|
/** Project tsconfig, relative to `cwd` (default: `tsconfig.json`). */
|
|
49
50
|
tsconfig?: string;
|
|
50
51
|
|
|
52
|
+
/** Upstream mapper permission; explicit false overrides inherited flags. */
|
|
53
|
+
runExternalCode?: boolean;
|
|
54
|
+
|
|
51
55
|
/**
|
|
52
56
|
* Absolute path to the `ttscgraph` binary. Defaults to the per-platform
|
|
53
57
|
* binary installed with `@ttsc/graph`; pass it explicitly to point at a
|
|
@@ -58,6 +62,9 @@ export function loadGraph(
|
|
|
58
62
|
): TtscGraphMemory {
|
|
59
63
|
const cwd = options.cwd ?? process.cwd();
|
|
60
64
|
const tsconfig = options.tsconfig ?? "tsconfig.json";
|
|
65
|
+
const permission = TtscGraphNativeArguments.permission(
|
|
66
|
+
options.runExternalCode,
|
|
67
|
+
);
|
|
61
68
|
// The producer belongs to this package's installation; the selected project
|
|
62
69
|
// becomes the native process's --cwd and, by its TypeScript line, picks
|
|
63
70
|
// which of the installation's producers runs.
|
|
@@ -77,7 +84,11 @@ export function loadGraph(
|
|
|
77
84
|
// before the dump runs, so the producer can resolve a documentation target
|
|
78
85
|
// into a relation rather than leaving it a token. A project with no lint
|
|
79
86
|
// install, or none that publishes, contributes no file and no claim.
|
|
80
|
-
const artifacts = publishArtifacts({
|
|
87
|
+
const artifacts = publishArtifacts({
|
|
88
|
+
cwd,
|
|
89
|
+
tsconfig,
|
|
90
|
+
runExternalCode: options.runExternalCode,
|
|
91
|
+
});
|
|
81
92
|
result = GraphProcessTrace.spawnSync(
|
|
82
93
|
binary,
|
|
83
94
|
[
|
|
@@ -87,6 +98,7 @@ export function loadGraph(
|
|
|
87
98
|
"--tsconfig",
|
|
88
99
|
tsconfig,
|
|
89
100
|
...(artifacts.file === null ? [] : ["--artifacts", artifacts.file]),
|
|
101
|
+
...permission,
|
|
90
102
|
],
|
|
91
103
|
{
|
|
92
104
|
stdio: ["ignore", capture.stdoutFd, capture.stderrFd],
|
|
@@ -14,12 +14,15 @@ import type { IArtifactDirectory } from "./IArtifactDirectory";
|
|
|
14
14
|
import type { IArtifactInputs } from "./IArtifactInputs";
|
|
15
15
|
import type { IPublishedArtifacts } from "./IPublishedArtifacts";
|
|
16
16
|
import type { IPublishedArtifactsResident } from "./IPublishedArtifactsResident";
|
|
17
|
+
import { TtscGraphNativeArguments } from "./TtscGraphNativeArguments";
|
|
17
18
|
import { TtscLintDaemon } from "./TtscLintDaemon";
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Discover configured publishers and synchronously publish their artifact set.
|
|
21
22
|
* Input identity is captured before the graph-nodes verbs to avoid accepting a
|
|
22
|
-
* concurrent document edit as already represented by an older answer.
|
|
23
|
+
* concurrent document edit as already represented by an older answer. Both
|
|
24
|
+
* verbs use one captured compiler environment; exchange paths distinguish
|
|
25
|
+
* compiler argument and permission contexts for the same project.
|
|
23
26
|
*
|
|
24
27
|
* @evidence contracts/common.md#principled-implementation Capability discovery and each sidecar's project-inputs/graph-nodes verbs remain the authorities for plugin selection and artifact meaning.
|
|
25
28
|
* @evidence contracts/common.md#clear-and-simple-design The one-shot path composes discovery, input capture and publication through helpers also used by resident requests.
|
|
@@ -27,13 +30,18 @@ import { TtscLintDaemon } from "./TtscLintDaemon";
|
|
|
27
30
|
* @evidence contracts/common.md#meaningful-documentation Native prose documents synchronous ownership and the freshness snapshot's required ordering.
|
|
28
31
|
* @evidence contracts/performance.md#efficient-algorithms Discovery runs once per publication, distinct input paths are merged and fingerprinted once, and publisher JSON is concatenated in one pass.
|
|
29
32
|
* @evidence contracts/performance.md#reuse-equivalent-work This one-shot caller has no resident sidecar owner; resident consumers use publishArtifactsResident and session freshness reuse instead of repeatedly spawning this path.
|
|
30
|
-
* @evidence contracts/performance.md#bound-retention-and-release-resources SpawnSync owns each child through completion; the exchange file is overwritten per process/project, but historical
|
|
33
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources SpawnSync owns each child through completion; the exchange file is overwritten per process/project/compiler context, but historical context files have no explicit reclamation yet.
|
|
31
34
|
* @evidence contracts/portability.md#os-neutral-implementation Native paths and temporary storage use Node path/os APIs; sidecars receive argument arrays and hidden Windows child windows without shell composition.
|
|
32
35
|
*/
|
|
33
36
|
export function publishArtifacts(options: {
|
|
34
37
|
cwd: string;
|
|
35
38
|
tsconfig: string;
|
|
39
|
+
runExternalCode?: boolean;
|
|
36
40
|
}): IPublishedArtifacts {
|
|
41
|
+
const invocation = {
|
|
42
|
+
...options,
|
|
43
|
+
environment: TtscGraphNativeArguments.environment(options.runExternalCode),
|
|
44
|
+
};
|
|
37
45
|
const discovery = resolveCapabilityPluginResolution({
|
|
38
46
|
capability: "graphNodes",
|
|
39
47
|
cwd: options.cwd,
|
|
@@ -49,15 +57,15 @@ export function publishArtifacts(options: {
|
|
|
49
57
|
// the set, and the edit that landed in the gap would read as already
|
|
50
58
|
// accounted for — the exact staleness this exists to remove.
|
|
51
59
|
const inputs = readInputs(
|
|
52
|
-
plugins.map((plugin) => runVerb(plugin, "project-inputs",
|
|
60
|
+
plugins.map((plugin) => runVerb(plugin, "project-inputs", invocation)),
|
|
53
61
|
options,
|
|
54
62
|
);
|
|
55
63
|
const fingerprint = fingerprintInputs(inputs);
|
|
56
64
|
return assemble(
|
|
57
|
-
|
|
65
|
+
invocation,
|
|
58
66
|
inputs,
|
|
59
67
|
fingerprint,
|
|
60
|
-
plugins.map((plugin) => runVerb(plugin, "graph-nodes",
|
|
68
|
+
plugins.map((plugin) => runVerb(plugin, "graph-nodes", invocation)),
|
|
61
69
|
discovery,
|
|
62
70
|
);
|
|
63
71
|
}
|
|
@@ -76,19 +84,30 @@ export function publishArtifacts(options: {
|
|
|
76
84
|
* fallback matters more here than most: a daemon that quietly answered nothing
|
|
77
85
|
* would be indistinguishable from a project that publishes nothing.
|
|
78
86
|
*
|
|
87
|
+
* Compiler environment capture precedes asynchronous discovery. The optional
|
|
88
|
+
* environment supplies inherited invocation context; explicit permission is
|
|
89
|
+
* applied once, and the daemon and fallback receive that same captured value.
|
|
90
|
+
*
|
|
79
91
|
* @evidence contracts/common.md#principled-implementation Both paths ask the same configured sidecar verbs; input identity is captured before publication and invalidation clears the daemon's stale Program first.
|
|
80
92
|
* @evidence contracts/common.md#clear-and-simple-design The caller supplies daemon and asynchronous resolver ownership while this function owns ordered input and artifact phases and the shared result assembly.
|
|
81
93
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts A failed daemon falls back to the public direct verb, not an invented empty-success result or a reimplementation of its parser.
|
|
82
94
|
* @evidence contracts/common.md#meaningful-documentation Native prose explains resident reuse, direct-command fallback and the reason to invalidate the Program before input collection.
|
|
83
95
|
* @evidence contracts/performance.md#efficient-algorithms Independent publishers run concurrently within each of two ordered phases; deduplication avoids repeatedly hashing the same declared file path.
|
|
84
|
-
* @evidence contracts/performance.md#reuse-equivalent-work Session-owned daemons reuse process and plugin loading only while binary, manifest and
|
|
85
|
-
* @evidence contracts/performance.md#bound-retention-and-release-resources The session owns the resolver and daemons. Failed publication joins every selected verb and releases its proof; successful publication transfers proof release to the session. Cancellation closes and joins an active daemon or supervised direct command. One exchange file per process/project still has no historical-file reclamation.
|
|
96
|
+
* @evidence contracts/performance.md#reuse-equivalent-work Session-owned daemons reuse process and plugin loading only while binary, manifest, project and compiler argument contexts match; changed inputs rebuild the publication.
|
|
97
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources The session owns the resolver and daemons. Failed publication joins every selected verb and releases its proof; successful publication transfers proof release to the session. Cancellation closes and joins an active daemon or supervised direct command. One exchange file per process/project/compiler context still has no historical-file reclamation.
|
|
86
98
|
* @evidence contracts/portability.md#os-neutral-implementation The fallback preserves native argument-vector invocation and Node path resolution; daemon ownership uses the same cross-platform process boundary.
|
|
87
99
|
*/
|
|
88
100
|
export async function publishArtifactsResident(
|
|
89
|
-
options: {
|
|
101
|
+
options: {
|
|
102
|
+
cwd: string;
|
|
103
|
+
tsconfig: string;
|
|
104
|
+
runExternalCode?: boolean;
|
|
105
|
+
environment?: NodeJS.ProcessEnv;
|
|
106
|
+
signal?: AbortSignal;
|
|
107
|
+
},
|
|
90
108
|
daemon: (
|
|
91
109
|
plugin: ITtscCapabilityPlugin,
|
|
110
|
+
environment: NodeJS.ProcessEnv,
|
|
92
111
|
) =>
|
|
93
112
|
| Pick<TtscLintDaemon, "ask" | "close">
|
|
94
113
|
| undefined
|
|
@@ -96,6 +115,13 @@ export async function publishArtifactsResident(
|
|
|
96
115
|
resolver: Pick<CapabilityPluginResolver, "resolve" | "runCommand">,
|
|
97
116
|
): Promise<IPublishedArtifactsResident> {
|
|
98
117
|
options.signal?.throwIfAborted();
|
|
118
|
+
const invocation = {
|
|
119
|
+
...options,
|
|
120
|
+
environment: TtscGraphNativeArguments.environment(
|
|
121
|
+
options.runExternalCode,
|
|
122
|
+
options.environment,
|
|
123
|
+
),
|
|
124
|
+
};
|
|
99
125
|
const discovery = await resolver.resolve(
|
|
100
126
|
{ capability: "graphNodes", cwd: options.cwd, tsconfig: options.tsconfig },
|
|
101
127
|
{ signal: options.signal },
|
|
@@ -118,8 +144,8 @@ export async function publishArtifactsResident(
|
|
|
118
144
|
askVerb(
|
|
119
145
|
plugin,
|
|
120
146
|
"project-inputs",
|
|
121
|
-
|
|
122
|
-
await daemon(plugin),
|
|
147
|
+
invocation,
|
|
148
|
+
await daemon(plugin, invocation.environment),
|
|
123
149
|
true,
|
|
124
150
|
resolver,
|
|
125
151
|
),
|
|
@@ -133,15 +159,15 @@ export async function publishArtifactsResident(
|
|
|
133
159
|
askVerb(
|
|
134
160
|
plugin,
|
|
135
161
|
"graph-nodes",
|
|
136
|
-
|
|
137
|
-
await daemon(plugin),
|
|
162
|
+
invocation,
|
|
163
|
+
await daemon(plugin, invocation.environment),
|
|
138
164
|
false,
|
|
139
165
|
resolver,
|
|
140
166
|
),
|
|
141
167
|
),
|
|
142
168
|
);
|
|
143
169
|
options.signal?.throwIfAborted();
|
|
144
|
-
return assemble(
|
|
170
|
+
return assemble(invocation, inputs, fingerprint, outputs, discovery);
|
|
145
171
|
} catch (error) {
|
|
146
172
|
try {
|
|
147
173
|
await discovery.release();
|
|
@@ -177,7 +203,7 @@ async function joinedPublications(
|
|
|
177
203
|
function runVerb(
|
|
178
204
|
plugin: ITtscCapabilityPlugin,
|
|
179
205
|
verb: string,
|
|
180
|
-
options: { cwd: string; tsconfig: string },
|
|
206
|
+
options: { cwd: string; tsconfig: string; environment: NodeJS.ProcessEnv },
|
|
181
207
|
): string | null {
|
|
182
208
|
const result = GraphProcessTrace.spawnSync(
|
|
183
209
|
plugin.binary,
|
|
@@ -199,6 +225,7 @@ function runVerb(
|
|
|
199
225
|
// bounded by the project's own documentation, not by its source — so the
|
|
200
226
|
// default pipe ceiling is raised rather than removed.
|
|
201
227
|
maxBuffer: 256 * 1024 * 1024,
|
|
228
|
+
env: options.environment,
|
|
202
229
|
encoding: "utf8",
|
|
203
230
|
windowsHide: true,
|
|
204
231
|
},
|
|
@@ -217,7 +244,12 @@ function runVerb(
|
|
|
217
244
|
async function askVerb(
|
|
218
245
|
plugin: ITtscCapabilityPlugin,
|
|
219
246
|
verb: string,
|
|
220
|
-
options: {
|
|
247
|
+
options: {
|
|
248
|
+
cwd: string;
|
|
249
|
+
tsconfig: string;
|
|
250
|
+
environment: NodeJS.ProcessEnv;
|
|
251
|
+
signal?: AbortSignal;
|
|
252
|
+
},
|
|
221
253
|
daemon: Pick<TtscLintDaemon, "ask" | "close"> | undefined,
|
|
222
254
|
invalidate: boolean,
|
|
223
255
|
resolver: Pick<CapabilityPluginResolver, "runCommand">,
|
|
@@ -265,7 +297,12 @@ async function askVerb(
|
|
|
265
297
|
`--plugins-json=${plugin.manifest}`,
|
|
266
298
|
...projectContextArgs(plugin),
|
|
267
299
|
],
|
|
268
|
-
{
|
|
300
|
+
{
|
|
301
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
302
|
+
encoding: "utf8",
|
|
303
|
+
windowsHide: true,
|
|
304
|
+
env: options.environment,
|
|
305
|
+
},
|
|
269
306
|
{ signal: options.signal },
|
|
270
307
|
);
|
|
271
308
|
options.signal?.throwIfAborted();
|
|
@@ -282,7 +319,7 @@ function assemble<
|
|
|
282
319
|
| ITtscCapabilityPluginResolution
|
|
283
320
|
| CapabilityPluginResolver.Resolution,
|
|
284
321
|
>(
|
|
285
|
-
options: { cwd: string; tsconfig: string },
|
|
322
|
+
options: { cwd: string; tsconfig: string; environment: NodeJS.ProcessEnv },
|
|
286
323
|
inputs: IArtifactInputs,
|
|
287
324
|
fingerprint: string,
|
|
288
325
|
outputs: readonly (string | null)[],
|
|
@@ -302,7 +339,7 @@ function assemble<
|
|
|
302
339
|
if (published.length === 0)
|
|
303
340
|
return { file: null, fingerprint, inputs, discovery };
|
|
304
341
|
|
|
305
|
-
// One file per process and
|
|
342
|
+
// One file per process, project and compiler context, overwritten, rather than a fresh temp
|
|
306
343
|
// directory per call. A directory per call is a leak nothing here is
|
|
307
344
|
// positioned to clean — the path outlives this function by design, since the
|
|
308
345
|
// native producer reads it after we return — and `loadGraph` is a library
|
|
@@ -549,17 +586,27 @@ function projectContextArgs(plugin: {
|
|
|
549
586
|
}
|
|
550
587
|
|
|
551
588
|
/**
|
|
552
|
-
* The project a published set belongs to, as a
|
|
589
|
+
* The project and compiler context a published set belongs to, as a
|
|
590
|
+
* filename-safe tag.
|
|
553
591
|
*
|
|
554
592
|
* Short rather than the whole digest: it distinguishes the projects one process
|
|
555
593
|
* drives, which is a handful, and the process id beside it already separates
|
|
556
594
|
* two runs.
|
|
557
595
|
*/
|
|
558
|
-
function projectKey(options: {
|
|
596
|
+
function projectKey(options: {
|
|
597
|
+
cwd: string;
|
|
598
|
+
tsconfig: string;
|
|
599
|
+
environment: NodeJS.ProcessEnv;
|
|
600
|
+
}): string {
|
|
559
601
|
return createHash("sha256")
|
|
560
|
-
.update(
|
|
561
|
-
|
|
562
|
-
|
|
602
|
+
.update(
|
|
603
|
+
JSON.stringify([
|
|
604
|
+
path.resolve(options.cwd),
|
|
605
|
+
options.tsconfig,
|
|
606
|
+
options.environment.TTSC_TSGO_ARGS,
|
|
607
|
+
options.environment.TTSC_TSGO_ARGS_CWD,
|
|
608
|
+
]),
|
|
609
|
+
)
|
|
563
610
|
.digest("hex")
|
|
564
611
|
.slice(0, 16);
|
|
565
612
|
}
|
package/src/runGraph.ts
CHANGED
|
@@ -36,8 +36,9 @@ export function runGraph(
|
|
|
36
36
|
if (argv[0] === "view") return runView(argv.slice(1));
|
|
37
37
|
if (argv[0] === "dump") return runDump(argv.slice(1));
|
|
38
38
|
|
|
39
|
-
const { cwd, tsconfig } =
|
|
40
|
-
|
|
39
|
+
const { cwd, tsconfig, runExternalCode } =
|
|
40
|
+
TtscGraphLauncherArguments.project(argv);
|
|
41
|
+
void startServer({ cwd, tsconfig, runExternalCode, version: VERSION }).catch(
|
|
41
42
|
(error: unknown) => {
|
|
42
43
|
process.stderr.write(
|
|
43
44
|
`@ttsc/graph: ${error instanceof Error ? error.message : String(error)}\n`,
|
|
@@ -55,7 +56,7 @@ function runDump(argv: readonly string[]): number {
|
|
|
55
56
|
// The producer belongs to this package's installation; `--cwd` selects the
|
|
56
57
|
// project the native process graphs and, by its TypeScript line, which of
|
|
57
58
|
// the installation's producers graphs it.
|
|
58
|
-
const { cwd, tsconfig, artifactsSpecified } =
|
|
59
|
+
const { cwd, tsconfig, artifactsSpecified, runExternalCode } =
|
|
59
60
|
TtscGraphLauncherArguments.dump(argv);
|
|
60
61
|
const binary = resolveGraphBinary(process.env, cwd);
|
|
61
62
|
if (binary === null) {
|
|
@@ -75,7 +76,7 @@ function runDump(argv: readonly string[]): number {
|
|
|
75
76
|
// named `--artifacts` itself owns the answer and is not overridden.
|
|
76
77
|
const published = artifactsSpecified
|
|
77
78
|
? null
|
|
78
|
-
: publishArtifacts({ cwd, tsconfig });
|
|
79
|
+
: publishArtifacts({ cwd, tsconfig, runExternalCode });
|
|
79
80
|
const result = GraphProcessTrace.spawnSync(
|
|
80
81
|
binary,
|
|
81
82
|
TtscGraphLauncherArguments.dumpVector(argv, published?.file ?? null),
|
|
@@ -31,6 +31,9 @@ export async function startServer(options: {
|
|
|
31
31
|
*/
|
|
32
32
|
tsconfig?: string;
|
|
33
33
|
|
|
34
|
+
/** Upstream mapper permission fixed for this server's resident session. */
|
|
35
|
+
runExternalCode?: boolean;
|
|
36
|
+
|
|
34
37
|
/** Server version reported in the MCP handshake. */
|
|
35
38
|
version: string;
|
|
36
39
|
}): Promise<void> {
|
|
@@ -39,7 +42,11 @@ export async function startServer(options: {
|
|
|
39
42
|
let session: TtscGraphSession | undefined;
|
|
40
43
|
const server = createServer(async () => {
|
|
41
44
|
if (closed) throw new Error("@ttsc/graph: server is closed");
|
|
42
|
-
session ??= new TtscGraphSession({
|
|
45
|
+
session ??= new TtscGraphSession({
|
|
46
|
+
cwd,
|
|
47
|
+
tsconfig,
|
|
48
|
+
runExternalCode: options.runExternalCode,
|
|
49
|
+
});
|
|
43
50
|
return session.graph();
|
|
44
51
|
}, options.version);
|
|
45
52
|
const transport = new StdioServerTransport();
|
package/src/view.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { TtscGraphLauncherArguments } from "./TtscGraphLauncherArguments";
|
|
|
7
7
|
import { TtscGraphViewSnapshot } from "./TtscGraphViewSnapshot";
|
|
8
8
|
import { GraphProcessTrace } from "./internal/GraphProcessTrace";
|
|
9
9
|
import { InstalledGraphBinary } from "./internal/InstalledGraphBinary";
|
|
10
|
+
import { TtscGraphNativeArguments } from "./model/TtscGraphNativeArguments";
|
|
10
11
|
import { publishArtifacts } from "./model/publishedArtifacts";
|
|
11
12
|
import { captureProcessOutput, ensureExecutable } from "./nativeExecutable";
|
|
12
13
|
import { reduce } from "./reduce";
|
|
@@ -223,6 +224,7 @@ function prepareView(
|
|
|
223
224
|
const artifacts = publishArtifacts({
|
|
224
225
|
cwd: opts.cwd,
|
|
225
226
|
tsconfig: opts.tsconfig,
|
|
227
|
+
runExternalCode: opts.runExternalCode,
|
|
226
228
|
});
|
|
227
229
|
dump = GraphProcessTrace.spawnSync(
|
|
228
230
|
binary,
|
|
@@ -233,6 +235,7 @@ function prepareView(
|
|
|
233
235
|
"--tsconfig",
|
|
234
236
|
opts.tsconfig,
|
|
235
237
|
...(artifacts.file === null ? [] : ["--artifacts", artifacts.file]),
|
|
238
|
+
...TtscGraphNativeArguments.permission(opts.runExternalCode),
|
|
236
239
|
],
|
|
237
240
|
{
|
|
238
241
|
stdio: ["ignore", capture.stdoutFd, capture.stderrFd],
|