@smthrs/kernel 0.0.0-stage → 1.0.0-rc.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.
- package/CHANGELOG.md +206 -0
- package/LICENSE +21 -0
- package/README.md +154 -2
- package/dist/cjs/CapabilitySet.d.ts +6 -0
- package/dist/cjs/CapabilitySet.d.ts.map +1 -0
- package/dist/cjs/CapabilitySet.js +19 -0
- package/dist/cjs/CapabilitySet.js.map +7 -0
- package/dist/cjs/ChildProcessEnvironment.d.ts +60 -0
- package/dist/cjs/ChildProcessEnvironment.d.ts.map +1 -0
- package/dist/cjs/ChildProcessEnvironment.js +61 -0
- package/dist/cjs/ChildProcessEnvironment.js.map +7 -0
- package/dist/cjs/ChildProcessSpawner.d.ts +100 -0
- package/dist/cjs/ChildProcessSpawner.d.ts.map +1 -0
- package/dist/cjs/ChildProcessSpawner.js +291 -0
- package/dist/cjs/ChildProcessSpawner.js.map +7 -0
- package/dist/cjs/CommandLine.d.ts +173 -0
- package/dist/cjs/CommandLine.d.ts.map +1 -0
- package/dist/cjs/CommandLine.js +54 -0
- package/dist/cjs/CommandLine.js.map +7 -0
- package/dist/cjs/ContainedSpawner.d.ts +135 -0
- package/dist/cjs/ContainedSpawner.d.ts.map +1 -0
- package/dist/cjs/ContainedSpawner.js +141 -0
- package/dist/cjs/ContainedSpawner.js.map +7 -0
- package/dist/cjs/FileSystem.d.ts +452 -0
- package/dist/cjs/FileSystem.d.ts.map +1 -0
- package/dist/cjs/FileSystem.js +890 -0
- package/dist/cjs/FileSystem.js.map +7 -0
- package/dist/cjs/FileSystemBatch.d.ts +94 -0
- package/dist/cjs/FileSystemBatch.d.ts.map +1 -0
- package/dist/cjs/FileSystemBatch.js +31 -0
- package/dist/cjs/FileSystemBatch.js.map +7 -0
- package/dist/cjs/GrantEvent.d.ts +240 -0
- package/dist/cjs/GrantEvent.d.ts.map +1 -0
- package/dist/cjs/GrantEvent.js +115 -0
- package/dist/cjs/GrantEvent.js.map +7 -0
- package/dist/cjs/GrantStore.d.ts +270 -0
- package/dist/cjs/GrantStore.d.ts.map +1 -0
- package/dist/cjs/GrantStore.js +857 -0
- package/dist/cjs/GrantStore.js.map +7 -0
- package/dist/cjs/HostError.d.ts +36 -0
- package/dist/cjs/HostError.d.ts.map +1 -0
- package/dist/cjs/HostError.js +17 -0
- package/dist/cjs/HostError.js.map +7 -0
- package/dist/cjs/HostServices.d.ts +101 -0
- package/dist/cjs/HostServices.d.ts.map +1 -0
- package/dist/cjs/HostServices.js +66 -0
- package/dist/cjs/HostServices.js.map +7 -0
- package/dist/cjs/HttpClient.d.ts +177 -0
- package/dist/cjs/HttpClient.d.ts.map +1 -0
- package/dist/cjs/HttpClient.js +217 -0
- package/dist/cjs/HttpClient.js.map +7 -0
- package/dist/cjs/Jj.d.ts +67 -0
- package/dist/cjs/Jj.d.ts.map +1 -0
- package/dist/cjs/Jj.js +118 -0
- package/dist/cjs/Jj.js.map +7 -0
- package/dist/cjs/JournalGrantStore.d.ts +65 -0
- package/dist/cjs/JournalGrantStore.d.ts.map +1 -0
- package/dist/cjs/JournalGrantStore.js +354 -0
- package/dist/cjs/JournalGrantStore.js.map +7 -0
- package/dist/cjs/Path.d.ts +37 -0
- package/dist/cjs/Path.d.ts.map +1 -0
- package/dist/cjs/Path.js +46 -0
- package/dist/cjs/Path.js.map +7 -0
- package/dist/cjs/ProcessConfinement.d.ts +55 -0
- package/dist/cjs/ProcessConfinement.d.ts.map +1 -0
- package/dist/cjs/ProcessConfinement.js +94 -0
- package/dist/cjs/ProcessConfinement.js.map +7 -0
- package/dist/cjs/ProcessLedger.d.ts +260 -0
- package/dist/cjs/ProcessLedger.d.ts.map +1 -0
- package/dist/cjs/ProcessLedger.js +190 -0
- package/dist/cjs/ProcessLedger.js.map +7 -0
- package/dist/cjs/Rooted.d.ts +53 -0
- package/dist/cjs/Rooted.d.ts.map +1 -0
- package/dist/cjs/Rooted.js +101 -0
- package/dist/cjs/Rooted.js.map +7 -0
- package/dist/cjs/Unreachable.d.ts +27 -0
- package/dist/cjs/Unreachable.d.ts.map +1 -0
- package/dist/cjs/Unreachable.js +43 -0
- package/dist/cjs/Unreachable.js.map +7 -0
- package/dist/cjs/Workspace.d.ts +62 -0
- package/dist/cjs/Workspace.d.ts.map +1 -0
- package/dist/cjs/Workspace.js +35 -0
- package/dist/cjs/Workspace.js.map +7 -0
- package/dist/cjs/index.d.ts +161 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +73 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/Containment.d.ts +24 -0
- package/dist/cjs/internal/Containment.d.ts.map +1 -0
- package/dist/cjs/internal/Containment.js +30 -0
- package/dist/cjs/internal/Containment.js.map +7 -0
- package/dist/cjs/internal/Pipeline.d.ts +18 -0
- package/dist/cjs/internal/Pipeline.d.ts.map +1 -0
- package/dist/cjs/internal/Pipeline.js +90 -0
- package/dist/cjs/internal/Pipeline.js.map +7 -0
- package/dist/cjs/internal/makeCapability.d.ts +16 -0
- package/dist/cjs/internal/makeCapability.d.ts.map +1 -0
- package/dist/cjs/internal/makeCapability.js +44 -0
- package/dist/cjs/internal/makeCapability.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/FileSystemBatchContract.d.ts +15 -0
- package/dist/cjs/test/FileSystemBatchContract.d.ts.map +1 -0
- package/dist/cjs/test/FileSystemBatchContract.js +76 -0
- package/dist/cjs/test/FileSystemBatchContract.js.map +7 -0
- package/dist/cjs/test/HostContract.d.ts +225 -0
- package/dist/cjs/test/HostContract.d.ts.map +1 -0
- package/dist/cjs/test/HostContract.js +489 -0
- package/dist/cjs/test/HostContract.js.map +7 -0
- package/dist/cjs/test/TestGrantStore.d.ts +31 -0
- package/dist/cjs/test/TestGrantStore.d.ts.map +1 -0
- package/dist/cjs/test/TestGrantStore.js +65 -0
- package/dist/cjs/test/TestGrantStore.js.map +7 -0
- package/dist/esm/CapabilitySet.d.ts +6 -0
- package/dist/esm/CapabilitySet.d.ts.map +1 -0
- package/dist/esm/CapabilitySet.js +6 -0
- package/dist/esm/CapabilitySet.js.map +1 -0
- package/dist/esm/ChildProcessEnvironment.d.ts +60 -0
- package/dist/esm/ChildProcessEnvironment.d.ts.map +1 -0
- package/dist/esm/ChildProcessEnvironment.js +91 -0
- package/dist/esm/ChildProcessEnvironment.js.map +1 -0
- package/dist/esm/ChildProcessSpawner.d.ts +100 -0
- package/dist/esm/ChildProcessSpawner.d.ts.map +1 -0
- package/dist/esm/ChildProcessSpawner.js +342 -0
- package/dist/esm/ChildProcessSpawner.js.map +1 -0
- package/dist/esm/CommandLine.d.ts +173 -0
- package/dist/esm/CommandLine.d.ts.map +1 -0
- package/dist/esm/CommandLine.js +195 -0
- package/dist/esm/CommandLine.js.map +1 -0
- package/dist/esm/ContainedSpawner.d.ts +135 -0
- package/dist/esm/ContainedSpawner.d.ts.map +1 -0
- package/dist/esm/ContainedSpawner.js +180 -0
- package/dist/esm/ContainedSpawner.js.map +1 -0
- package/dist/esm/FileSystem.d.ts +452 -0
- package/dist/esm/FileSystem.d.ts.map +1 -0
- package/dist/esm/FileSystem.js +989 -0
- package/dist/esm/FileSystem.js.map +1 -0
- package/dist/esm/FileSystemBatch.d.ts +94 -0
- package/dist/esm/FileSystemBatch.d.ts.map +1 -0
- package/dist/esm/FileSystemBatch.js +26 -0
- package/dist/esm/FileSystemBatch.js.map +1 -0
- package/dist/esm/GrantEvent.d.ts +240 -0
- package/dist/esm/GrantEvent.d.ts.map +1 -0
- package/dist/esm/GrantEvent.js +155 -0
- package/dist/esm/GrantEvent.js.map +1 -0
- package/dist/esm/GrantStore.d.ts +270 -0
- package/dist/esm/GrantStore.d.ts.map +1 -0
- package/dist/esm/GrantStore.js +951 -0
- package/dist/esm/GrantStore.js.map +1 -0
- package/dist/esm/HostError.d.ts +36 -0
- package/dist/esm/HostError.d.ts.map +1 -0
- package/dist/esm/HostError.js +20 -0
- package/dist/esm/HostError.js.map +1 -0
- package/dist/esm/HostServices.d.ts +101 -0
- package/dist/esm/HostServices.d.ts.map +1 -0
- package/dist/esm/HostServices.js +76 -0
- package/dist/esm/HostServices.js.map +1 -0
- package/dist/esm/HttpClient.d.ts +177 -0
- package/dist/esm/HttpClient.d.ts.map +1 -0
- package/dist/esm/HttpClient.js +299 -0
- package/dist/esm/HttpClient.js.map +1 -0
- package/dist/esm/Jj.d.ts +67 -0
- package/dist/esm/Jj.d.ts.map +1 -0
- package/dist/esm/Jj.js +111 -0
- package/dist/esm/Jj.js.map +1 -0
- package/dist/esm/JournalGrantStore.d.ts +65 -0
- package/dist/esm/JournalGrantStore.d.ts.map +1 -0
- package/dist/esm/JournalGrantStore.js +350 -0
- package/dist/esm/JournalGrantStore.js.map +1 -0
- package/dist/esm/Path.d.ts +37 -0
- package/dist/esm/Path.d.ts.map +1 -0
- package/dist/esm/Path.js +34 -0
- package/dist/esm/Path.js.map +1 -0
- package/dist/esm/ProcessConfinement.d.ts +55 -0
- package/dist/esm/ProcessConfinement.d.ts.map +1 -0
- package/dist/esm/ProcessConfinement.js +106 -0
- package/dist/esm/ProcessConfinement.js.map +1 -0
- package/dist/esm/ProcessLedger.d.ts +260 -0
- package/dist/esm/ProcessLedger.d.ts.map +1 -0
- package/dist/esm/ProcessLedger.js +283 -0
- package/dist/esm/ProcessLedger.js.map +1 -0
- package/dist/esm/Rooted.d.ts +53 -0
- package/dist/esm/Rooted.d.ts.map +1 -0
- package/dist/esm/Rooted.js +104 -0
- package/dist/esm/Rooted.js.map +1 -0
- package/dist/esm/Unreachable.d.ts +27 -0
- package/dist/esm/Unreachable.d.ts.map +1 -0
- package/dist/esm/Unreachable.js +26 -0
- package/dist/esm/Unreachable.js.map +1 -0
- package/dist/esm/Workspace.d.ts +62 -0
- package/dist/esm/Workspace.d.ts.map +1 -0
- package/dist/esm/Workspace.js +51 -0
- package/dist/esm/Workspace.js.map +1 -0
- package/dist/esm/index.d.ts +161 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +151 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/Containment.d.ts +24 -0
- package/dist/esm/internal/Containment.d.ts.map +1 -0
- package/dist/esm/internal/Containment.js +27 -0
- package/dist/esm/internal/Containment.js.map +1 -0
- package/dist/esm/internal/Pipeline.d.ts +18 -0
- package/dist/esm/internal/Pipeline.d.ts.map +1 -0
- package/dist/esm/internal/Pipeline.js +68 -0
- package/dist/esm/internal/Pipeline.js.map +1 -0
- package/dist/esm/internal/makeCapability.d.ts +16 -0
- package/dist/esm/internal/makeCapability.d.ts.map +1 -0
- package/dist/esm/internal/makeCapability.js +22 -0
- package/dist/esm/internal/makeCapability.js.map +1 -0
- package/dist/esm/test/FileSystemBatchContract.d.ts +15 -0
- package/dist/esm/test/FileSystemBatchContract.d.ts.map +1 -0
- package/dist/esm/test/FileSystemBatchContract.js +57 -0
- package/dist/esm/test/FileSystemBatchContract.js.map +1 -0
- package/dist/esm/test/HostContract.d.ts +225 -0
- package/dist/esm/test/HostContract.d.ts.map +1 -0
- package/dist/esm/test/HostContract.js +460 -0
- package/dist/esm/test/HostContract.js.map +1 -0
- package/dist/esm/test/TestGrantStore.d.ts +31 -0
- package/dist/esm/test/TestGrantStore.d.ts.map +1 -0
- package/dist/esm/test/TestGrantStore.js +57 -0
- package/dist/esm/test/TestGrantStore.js.map +1 -0
- package/docs/README.md +162 -0
- package/docs/api.md +1532 -0
- package/docs/concepts/decoration-in-place.md +117 -0
- package/docs/concepts/filesystem-batches.md +58 -0
- package/docs/concepts/filesystem-confinement.md +168 -0
- package/docs/concepts/grant-decisions.md +181 -0
- package/docs/concepts/process-containment.md +155 -0
- package/docs/contract.md +14 -0
- package/docs/guides/adapt-a-new-host-platform.md +148 -0
- package/docs/guides/answer-permission-requests.md +151 -0
- package/docs/guides/authorize-network-and-model-calls.md +118 -0
- package/docs/guides/contain-spawned-processes.md +118 -0
- package/docs/guides/guard-a-host-bundle.md +109 -0
- package/docs/guides/persist-grants-across-restarts.md +135 -0
- package/docs/guides/write-a-capability-policy.md +159 -0
- package/docs/installation.md +115 -0
- package/docs/quickstart.md +182 -0
- package/docs/testing.md +108 -0
- package/docs/troubleshooting.md +281 -0
- package/package.json +344 -3
- package/src/CapabilitySet.ts +6 -0
- package/src/ChildProcessEnvironment.ts +98 -0
- package/src/ChildProcessSpawner.ts +414 -0
- package/src/CommandLine.ts +250 -0
- package/src/ContainedSpawner.ts +284 -0
- package/src/FileSystem.ts +1655 -0
- package/src/FileSystemBatch.ts +90 -0
- package/src/GrantEvent.ts +174 -0
- package/src/GrantStore.ts +1345 -0
- package/src/HostError.ts +37 -0
- package/src/HostServices.ts +133 -0
- package/src/HttpClient.ts +406 -0
- package/src/Jj.ts +159 -0
- package/src/JournalGrantStore.ts +461 -0
- package/src/Path.ts +47 -0
- package/src/ProcessConfinement.ts +156 -0
- package/src/ProcessLedger.ts +423 -0
- package/src/Rooted.ts +128 -0
- package/src/Unreachable.ts +30 -0
- package/src/Workspace.ts +65 -0
- package/src/index.ts +181 -0
- package/src/internal/Containment.ts +37 -0
- package/src/internal/Pipeline.ts +85 -0
- package/src/internal/makeCapability.ts +26 -0
- package/src/test/FileSystemBatchContract.ts +59 -0
- package/src/test/HostContract.ts +785 -0
- package/src/test/TestGrantStore.ts +73 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission-aware process spawning.
|
|
3
|
+
*
|
|
4
|
+
* Smithers has no shell service of its own — process execution is Effect's
|
|
5
|
+
* `effect/unstable/process`. The only thing the kernel adds is the
|
|
6
|
+
* `proc:spawn` capability check and the host confinement wrapper, applied to
|
|
7
|
+
* the one primitive every other helper is derived from.
|
|
8
|
+
*
|
|
9
|
+
* There is no kernel spawner interface and no kernel spawner tag. Effect owns
|
|
10
|
+
* both, and its tag fixes the error channel to `PlatformError`, so this module
|
|
11
|
+
* is only the middleware: a `Layer` over Effect's own tag. A denied command is
|
|
12
|
+
* projected into `PlatformError` by `Permission.toPlatformError`, which keeps
|
|
13
|
+
* the structured kernel failure on the error's `cause`. Because the channel
|
|
14
|
+
* stays `PlatformError`, the full six-method surface is derived from the one
|
|
15
|
+
* guarded `spawn` through Effect's own `ChildProcessSpawner.make` without a
|
|
16
|
+
* cast.
|
|
17
|
+
*
|
|
18
|
+
* Governing design:
|
|
19
|
+
* `docs/specs/Concepts/Permission Kernel.md` and
|
|
20
|
+
* `docs/specs/Concepts/Host Adapters.md`.
|
|
21
|
+
*
|
|
22
|
+
* @since 1.0.0-rc.0
|
|
23
|
+
*/
|
|
24
|
+
import { Layer, Path } from "effect";
|
|
25
|
+
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
26
|
+
import { GrantStore } from "./GrantStore.ts";
|
|
27
|
+
import { Workspace } from "./Workspace.ts";
|
|
28
|
+
/**
|
|
29
|
+
* Effect's own process spawner tag, unchanged. Re-exported so the kernel
|
|
30
|
+
* namespace stays one-stop; it is the *same* tag, never a second one.
|
|
31
|
+
*
|
|
32
|
+
* @category services
|
|
33
|
+
* @since 1.0.0-rc.0
|
|
34
|
+
*/
|
|
35
|
+
export { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
36
|
+
/**
|
|
37
|
+
* Derives the full six-method surface from one `spawn`, so `exitCode`,
|
|
38
|
+
* `string`, `lines`, and both `stream*` helpers can never bypass whatever
|
|
39
|
+
* `spawn` was given.
|
|
40
|
+
*
|
|
41
|
+
* @category constructors
|
|
42
|
+
* @since 1.0.0-rc.0
|
|
43
|
+
*/
|
|
44
|
+
export { make } from "effect/unstable/process/ChildProcessSpawner";
|
|
45
|
+
/**
|
|
46
|
+
* Constructs an unavailable spawner stub.
|
|
47
|
+
*
|
|
48
|
+
* Every derived helper reports the missing host as a `NotFound`
|
|
49
|
+
* `PlatformError` naming the command line, so an unconfigured capability
|
|
50
|
+
* answers rather than vanishing.
|
|
51
|
+
*
|
|
52
|
+
* @category constructors
|
|
53
|
+
* @since 1.0.0-rc.0
|
|
54
|
+
*/
|
|
55
|
+
export declare const makeNoop: (overrides?: Partial<ChildProcessSpawner["Service"]>) => ChildProcessSpawner["Service"];
|
|
56
|
+
/**
|
|
57
|
+
* Provides an unavailable spawner stub.
|
|
58
|
+
*
|
|
59
|
+
* @category layers
|
|
60
|
+
* @since 1.0.0-rc.0
|
|
61
|
+
*/
|
|
62
|
+
export declare const layerNoop: (overrides?: Partial<ChildProcessSpawner["Service"]>) => Layer.Layer<ChildProcessSpawner>;
|
|
63
|
+
/**
|
|
64
|
+
* Decorates the process spawner in place with a `proc:spawn` capability check.
|
|
65
|
+
*
|
|
66
|
+
* The check is suspended into the spawn itself, so building a `Command` or a
|
|
67
|
+
* stream neither requests permission nor starts a process; only running one
|
|
68
|
+
* does. Every pipeline stage is checked as its own capability, left to right,
|
|
69
|
+
* and no stage starts until all pass. A stage's resource is
|
|
70
|
+
* `CommandLine.resource`: the command line `CommandLine.render` produces, with
|
|
71
|
+
* a `shell: true` line that holds shell control syntax marked as
|
|
72
|
+
* `sh -c '<line>'`, any environment variable the child would not inherit from
|
|
73
|
+
* this process named in an `env <NAME>… -- ` prefix, and a working directory
|
|
74
|
+
* outside `Workspace.root` named in a `cwd <path> -- ` prefix. Custom shell
|
|
75
|
+
* paths are included explicitly in the resource; browser and remote adapters
|
|
76
|
+
* reject them rather than silently substituting a different shell.
|
|
77
|
+
*
|
|
78
|
+
* Every approved stage requires `ProcessConfinement` in the host context.
|
|
79
|
+
* A missing service refuses spawning; its `layerNoop` is the explicit choice
|
|
80
|
+
* for an unconfined host.
|
|
81
|
+
*
|
|
82
|
+
* Pipeline `from`/`to` routing remains outside the grant. The working
|
|
83
|
+
* directory and overridden environment names also reach attended surfaces as
|
|
84
|
+
* display metadata; environment values never leave the command.
|
|
85
|
+
*
|
|
86
|
+
* The layer provides the tag it also requires: compose it over a host spawner
|
|
87
|
+
* layer with `Layer.provide` and a `ChildProcess.Command` run as a plain
|
|
88
|
+
* `Effect` is checked too.
|
|
89
|
+
*
|
|
90
|
+
* A command with no `cwd`, or a relative one, runs in `Workspace.root`, never
|
|
91
|
+
* the process's own directory; the check sees that resolved directory. When
|
|
92
|
+
* the host filesystem is in the layer's context, the working directory and
|
|
93
|
+
* `Workspace.root` are compared by real path, so a symlink inside the
|
|
94
|
+
* workspace that leads out of it is named, as its target, in the `cwd` prefix.
|
|
95
|
+
*
|
|
96
|
+
* @category layers
|
|
97
|
+
* @since 1.0.0-rc.0
|
|
98
|
+
*/
|
|
99
|
+
export declare const layer: Layer.Layer<ChildProcessSpawner, never, ChildProcessSpawner | GrantStore | Path.Path | Workspace>;
|
|
100
|
+
//# sourceMappingURL=ChildProcessSpawner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChildProcessSpawner.d.ts","sourceRoot":"","sources":["../../src/ChildProcessSpawner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAsB,KAAK,EAAU,IAAI,EAAc,MAAM,QAAQ,CAAA;AAG5E,OAAO,EAAE,mBAAmB,EAAuB,MAAM,6CAA6C,CAAA;AAEtG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAK5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAgK1C;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AAEjF;;;;;;;GAOG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,6CAA6C,CAAA;AAElE;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ,GACnB,YAAW,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAM,KACtD,mBAAmB,CAAC,SAAS,CAY9B,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GACpB,YAAW,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAM,KACtD,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAA4D,CAAA;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAC7B,mBAAmB,EACnB,KAAK,EACL,mBAAmB,GAAG,UAAU,GAAG,IAAI,CAAC,IAAI,GAAG,SAAS,CA4HzD,CAAA"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var ChildProcessSpawner_exports = {};
|
|
30
|
+
__export(ChildProcessSpawner_exports, {
|
|
31
|
+
ChildProcessSpawner: () => import_ChildProcessSpawner2.ChildProcessSpawner,
|
|
32
|
+
layer: () => layer,
|
|
33
|
+
layerNoop: () => layerNoop,
|
|
34
|
+
make: () => import_ChildProcessSpawner3.make,
|
|
35
|
+
makeNoop: () => makeNoop
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(ChildProcessSpawner_exports);
|
|
38
|
+
var import_Permission = require("@smthrs/capability/Permission");
|
|
39
|
+
var import_effect = require("effect");
|
|
40
|
+
var import_PlatformError = require("effect/PlatformError");
|
|
41
|
+
var ChildProcess = __toESM(require("effect/unstable/process/ChildProcess"), 1);
|
|
42
|
+
var import_ChildProcessSpawner = require("effect/unstable/process/ChildProcessSpawner");
|
|
43
|
+
var CommandLine = __toESM(require("./CommandLine.js"), 1);
|
|
44
|
+
var import_GrantStore = require("./GrantStore.js");
|
|
45
|
+
var Containment = __toESM(require("./internal/Containment.js"), 1);
|
|
46
|
+
var import_makeCapability = require("./internal/makeCapability.js");
|
|
47
|
+
var ProcessConfinement = __toESM(require("./ProcessConfinement.js"), 1);
|
|
48
|
+
var Rooted = __toESM(require("./Rooted.js"), 1);
|
|
49
|
+
var import_Workspace = require("./Workspace.js");
|
|
50
|
+
var import_ChildProcessSpawner2 = require("effect/unstable/process/ChildProcessSpawner");
|
|
51
|
+
var import_ChildProcessSpawner3 = require("effect/unstable/process/ChildProcessSpawner");
|
|
52
|
+
const data = (value, name) => {
|
|
53
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
54
|
+
if (descriptor === void 0 || !("value" in descriptor)) {
|
|
55
|
+
throw new TypeError(`command ${String(name)} must be a data property`);
|
|
56
|
+
}
|
|
57
|
+
return descriptor.value;
|
|
58
|
+
};
|
|
59
|
+
const optionalData = (value, name) => {
|
|
60
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
61
|
+
if (descriptor === void 0) return void 0;
|
|
62
|
+
if (!("value" in descriptor)) throw new TypeError(`command ${String(name)} must be a data property`);
|
|
63
|
+
return descriptor.value;
|
|
64
|
+
};
|
|
65
|
+
const snapshotRecord = (value) => {
|
|
66
|
+
if (value === void 0) return void 0;
|
|
67
|
+
const snapshot = /* @__PURE__ */ Object.create(null);
|
|
68
|
+
for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
69
|
+
if (!descriptor.enumerable) continue;
|
|
70
|
+
if (!("value" in descriptor) || descriptor.value !== void 0 && typeof descriptor.value !== "string") {
|
|
71
|
+
throw new TypeError("command environment must contain string data properties");
|
|
72
|
+
}
|
|
73
|
+
snapshot[name] = descriptor.value;
|
|
74
|
+
}
|
|
75
|
+
return Object.freeze(snapshot);
|
|
76
|
+
};
|
|
77
|
+
const snapshotStreamConfig = (value) => {
|
|
78
|
+
if (typeof value !== "object" || value === null) return value;
|
|
79
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
80
|
+
if (descriptors.stream === void 0) return value;
|
|
81
|
+
if (!("value" in descriptors.stream)) throw new TypeError("command stream must be a data property");
|
|
82
|
+
const snapshot = { stream: descriptors.stream.value };
|
|
83
|
+
for (const name of ["endOnDone", "encoding"]) {
|
|
84
|
+
const descriptor = descriptors[name];
|
|
85
|
+
if (descriptor !== void 0) {
|
|
86
|
+
if (!("value" in descriptor)) throw new TypeError(`command ${name} must be a data property`);
|
|
87
|
+
snapshot[name] = descriptor.value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return Object.freeze(snapshot);
|
|
91
|
+
};
|
|
92
|
+
const snapshotAdditionalFds = (value) => {
|
|
93
|
+
if (value === void 0) return void 0;
|
|
94
|
+
const snapshot = {};
|
|
95
|
+
for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
96
|
+
if (!descriptor.enumerable) continue;
|
|
97
|
+
if (!("value" in descriptor) || typeof descriptor.value !== "object" || descriptor.value === null) {
|
|
98
|
+
throw new TypeError("additional file descriptors must be data records");
|
|
99
|
+
}
|
|
100
|
+
const config = descriptor.value;
|
|
101
|
+
const type = data(config, "type");
|
|
102
|
+
if (type === "input") {
|
|
103
|
+
const stream = Object.getOwnPropertyDescriptor(config, "stream");
|
|
104
|
+
snapshot[name] = Object.freeze({
|
|
105
|
+
type,
|
|
106
|
+
...stream === void 0 ? {} : "value" in stream ? { stream: stream.value } : (() => {
|
|
107
|
+
throw new TypeError("additional fd stream must be a data property");
|
|
108
|
+
})()
|
|
109
|
+
});
|
|
110
|
+
} else if (type === "output") {
|
|
111
|
+
const sink = Object.getOwnPropertyDescriptor(config, "sink");
|
|
112
|
+
snapshot[name] = Object.freeze({
|
|
113
|
+
type,
|
|
114
|
+
...sink === void 0 ? {} : "value" in sink ? { sink: sink.value } : (() => {
|
|
115
|
+
throw new TypeError("additional fd sink must be a data property");
|
|
116
|
+
})()
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
throw new TypeError("additional file descriptor type is invalid");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return Object.freeze(snapshot);
|
|
123
|
+
};
|
|
124
|
+
const snapshotOptions = (options) => Object.freeze({
|
|
125
|
+
killSignal: options.killSignal,
|
|
126
|
+
forceKillAfter: options.forceKillAfter,
|
|
127
|
+
cwd: options.cwd,
|
|
128
|
+
env: snapshotRecord(options.env),
|
|
129
|
+
extendEnv: options.extendEnv,
|
|
130
|
+
shell: options.shell,
|
|
131
|
+
detached: options.detached,
|
|
132
|
+
windowsHide: options.windowsHide,
|
|
133
|
+
stdin: snapshotStreamConfig(options.stdin),
|
|
134
|
+
stdout: snapshotStreamConfig(options.stdout),
|
|
135
|
+
stderr: snapshotStreamConfig(options.stderr),
|
|
136
|
+
additionalFds: snapshotAdditionalFds(options.additionalFds)
|
|
137
|
+
});
|
|
138
|
+
const snapshotCommand = (command) => {
|
|
139
|
+
const tag = data(command, "_tag");
|
|
140
|
+
if (tag === "StandardCommand") {
|
|
141
|
+
const executable = data(command, "command");
|
|
142
|
+
const args = data(command, "args");
|
|
143
|
+
const options = data(command, "options");
|
|
144
|
+
if (typeof executable !== "string" || !Array.isArray(args) || !args.every((arg) => typeof arg === "string")) {
|
|
145
|
+
throw new TypeError("standard command executable and arguments are invalid");
|
|
146
|
+
}
|
|
147
|
+
if (typeof options !== "object" || options === null) throw new TypeError("command options are invalid");
|
|
148
|
+
return ChildProcess.make(
|
|
149
|
+
executable,
|
|
150
|
+
Object.freeze([...args]),
|
|
151
|
+
snapshotOptions(options)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (tag === "PipedCommand") {
|
|
155
|
+
const left = data(command, "left");
|
|
156
|
+
const right = data(command, "right");
|
|
157
|
+
const options = data(command, "options");
|
|
158
|
+
if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) {
|
|
159
|
+
throw new TypeError("pipeline commands are invalid");
|
|
160
|
+
}
|
|
161
|
+
if (typeof options !== "object" || options === null) throw new TypeError("pipeline options are invalid");
|
|
162
|
+
const from = optionalData(options, "from");
|
|
163
|
+
const to = optionalData(options, "to");
|
|
164
|
+
return ChildProcess.pipeTo(
|
|
165
|
+
snapshotCommand(right),
|
|
166
|
+
Object.freeze({
|
|
167
|
+
...from === void 0 ? {} : { from },
|
|
168
|
+
...to === void 0 ? {} : { to }
|
|
169
|
+
})
|
|
170
|
+
)(snapshotCommand(left));
|
|
171
|
+
}
|
|
172
|
+
throw new TypeError("unsupported command shape");
|
|
173
|
+
};
|
|
174
|
+
const maximumEnvironmentNames = 64;
|
|
175
|
+
const ambientEnvironment = () => globalThis.process?.env ?? {};
|
|
176
|
+
const environmentNames = (command) => {
|
|
177
|
+
const environment = command.options.env;
|
|
178
|
+
if (environment === void 0) return void 0;
|
|
179
|
+
const names = Object.entries(environment).filter(([, value]) => value !== void 0).map(([name]) => name).sort();
|
|
180
|
+
if (names.length === 0) return void 0;
|
|
181
|
+
return names.length <= maximumEnvironmentNames ? names : [...names.slice(0, maximumEnvironmentNames), `+${names.length - maximumEnvironmentNames} more`];
|
|
182
|
+
};
|
|
183
|
+
const makeNoop = (overrides = {}) => ({
|
|
184
|
+
...(0, import_ChildProcessSpawner.make)(
|
|
185
|
+
(command) => import_effect.Effect.fail(
|
|
186
|
+
(0, import_PlatformError.systemError)({
|
|
187
|
+
_tag: "NotFound",
|
|
188
|
+
module: "ChildProcessSpawner",
|
|
189
|
+
method: "spawn",
|
|
190
|
+
description: `no process host for \`${CommandLine.render(command)}\``
|
|
191
|
+
})
|
|
192
|
+
)
|
|
193
|
+
),
|
|
194
|
+
...overrides
|
|
195
|
+
});
|
|
196
|
+
const layerNoop = (overrides = {}) => import_effect.Layer.succeed(import_ChildProcessSpawner.ChildProcessSpawner)(makeNoop(overrides));
|
|
197
|
+
const layer = import_effect.Layer.effect(
|
|
198
|
+
import_ChildProcessSpawner.ChildProcessSpawner,
|
|
199
|
+
import_effect.Effect.gen(function* () {
|
|
200
|
+
const spawner = yield* import_ChildProcessSpawner.ChildProcessSpawner;
|
|
201
|
+
const grants = yield* import_GrantStore.GrantStore;
|
|
202
|
+
const confinement = yield* import_effect.Effect.serviceOption(ProcessConfinement.ProcessConfinement);
|
|
203
|
+
const path = yield* import_effect.Path.Path;
|
|
204
|
+
const rooted = Rooted.path(path, path.resolve((yield* import_Workspace.Workspace).root));
|
|
205
|
+
const root = rooted.resolve(".");
|
|
206
|
+
const fileSystem = yield* import_effect.Effect.serviceOption(import_effect.FileSystem.FileSystem);
|
|
207
|
+
const real = (directory) => import_effect.Option.match(fileSystem, {
|
|
208
|
+
onNone: () => import_effect.Effect.succeed(directory),
|
|
209
|
+
onSome: (fs) => fs.realPath(directory).pipe(import_effect.Effect.orElseSucceed(() => directory))
|
|
210
|
+
});
|
|
211
|
+
const within = (base) => (directory) => {
|
|
212
|
+
const relative = path.relative(base, directory);
|
|
213
|
+
return relative.split(path.sep)[0] !== ".." && !path.isAbsolute(relative);
|
|
214
|
+
};
|
|
215
|
+
const checkStage = (stage) => import_effect.Effect.gen(function* () {
|
|
216
|
+
const cwd = stage.options.cwd;
|
|
217
|
+
const realRoot = yield* real(root);
|
|
218
|
+
const resolvedCwd = yield* real(cwd);
|
|
219
|
+
const contains = resolvedCwd === cwd ? (directory) => within(root)(directory) || within(realRoot)(directory) : within(realRoot);
|
|
220
|
+
return yield* checkResolved(
|
|
221
|
+
stage,
|
|
222
|
+
CommandLine.resource(stage, {
|
|
223
|
+
ambient: ambientEnvironment(),
|
|
224
|
+
contains,
|
|
225
|
+
resolvedCwd
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
const checkResolved = (stage, rendered) => {
|
|
230
|
+
const environment = environmentNames(stage);
|
|
231
|
+
return (0, import_makeCapability.makeCapability)("proc:spawn", rendered).pipe(
|
|
232
|
+
import_effect.Effect.flatMap(
|
|
233
|
+
(capability) => grants.check(capability, {
|
|
234
|
+
cwd: stage.options.cwd,
|
|
235
|
+
...environment === void 0 ? {} : { env: environment }
|
|
236
|
+
})
|
|
237
|
+
),
|
|
238
|
+
import_effect.Effect.mapError(
|
|
239
|
+
(error) => (0, import_Permission.toPlatformError)({
|
|
240
|
+
module: "ChildProcessSpawner",
|
|
241
|
+
method: "spawn",
|
|
242
|
+
pathOrDescriptor: rendered,
|
|
243
|
+
error
|
|
244
|
+
})
|
|
245
|
+
)
|
|
246
|
+
);
|
|
247
|
+
};
|
|
248
|
+
const check = (command) => import_effect.Effect.forEach(CommandLine.stages(command), checkStage, { discard: true });
|
|
249
|
+
const confine = (command) => import_effect.Option.match(confinement, {
|
|
250
|
+
onNone: () => import_effect.Effect.fail((0, import_PlatformError.systemError)({
|
|
251
|
+
_tag: "NotFound",
|
|
252
|
+
module: "ProcessConfinement",
|
|
253
|
+
method: "confine",
|
|
254
|
+
description: "process confinement is required; use ProcessConfinement.layerNoop to explicitly run unconfined"
|
|
255
|
+
})),
|
|
256
|
+
onSome: (service) => import_effect.Effect.gen(function* () {
|
|
257
|
+
const profile = yield* ProcessConfinement.profile(grants, root, path).pipe(
|
|
258
|
+
import_effect.Effect.mapError((error) => (0, import_Permission.toPlatformError)({ module: "ChildProcessSpawner", method: "spawn", error }))
|
|
259
|
+
);
|
|
260
|
+
const wrap = (command2) => command2._tag === "StandardCommand" ? service.confine(command2, profile) : import_effect.Effect.gen(function* () {
|
|
261
|
+
const left = yield* wrap(command2.left);
|
|
262
|
+
const right = yield* wrap(command2.right);
|
|
263
|
+
return ChildProcess.pipeTo(right, command2.options)(left);
|
|
264
|
+
});
|
|
265
|
+
return yield* wrap(command);
|
|
266
|
+
})
|
|
267
|
+
});
|
|
268
|
+
return Containment.inherit(
|
|
269
|
+
spawner,
|
|
270
|
+
(0, import_ChildProcessSpawner.make)(
|
|
271
|
+
import_effect.Effect.fn("ChildProcessSpawner.spawn")(
|
|
272
|
+
(command) => import_effect.Effect.try({
|
|
273
|
+
try: () => snapshotCommand(command),
|
|
274
|
+
catch: () => (0, import_PlatformError.systemError)({
|
|
275
|
+
_tag: "InvalidData",
|
|
276
|
+
module: "ChildProcessSpawner",
|
|
277
|
+
method: "spawn",
|
|
278
|
+
description: "command must be an immutable supported process description"
|
|
279
|
+
})
|
|
280
|
+
}).pipe(
|
|
281
|
+
import_effect.Effect.map((snapshot) => Rooted.command(snapshot, rooted)),
|
|
282
|
+
import_effect.Effect.flatMap(
|
|
283
|
+
(rooted2) => check(rooted2).pipe(import_effect.Effect.andThen(confine(rooted2)), import_effect.Effect.flatMap(spawner.spawn))
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
)
|
|
287
|
+
)
|
|
288
|
+
);
|
|
289
|
+
})
|
|
290
|
+
);
|
|
291
|
+
//# sourceMappingURL=ChildProcessSpawner.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ChildProcessSpawner.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Permission-aware process spawning.\n *\n * Smithers has no shell service of its own \u2014 process execution is Effect's\n * `effect/unstable/process`. The only thing the kernel adds is the\n * `proc:spawn` capability check and the host confinement wrapper, applied to\n * the one primitive every other helper is derived from.\n *\n * There is no kernel spawner interface and no kernel spawner tag. Effect owns\n * both, and its tag fixes the error channel to `PlatformError`, so this module\n * is only the middleware: a `Layer` over Effect's own tag. A denied command is\n * projected into `PlatformError` by `Permission.toPlatformError`, which keeps\n * the structured kernel failure on the error's `cause`. Because the channel\n * stays `PlatformError`, the full six-method surface is derived from the one\n * guarded `spawn` through Effect's own `ChildProcessSpawner.make` without a\n * cast.\n *\n * Governing design:\n * `docs/specs/Concepts/Permission Kernel.md` and\n * `docs/specs/Concepts/Host Adapters.md`.\n *\n * @since 1.0.0-rc.0\n */\n\nimport { toPlatformError } from \"@smthrs/capability/Permission\"\nimport { Effect, FileSystem, Layer, Option, Path, type Scope } from \"effect\"\nimport { type PlatformError, systemError } from \"effect/PlatformError\"\nimport * as ChildProcess from \"effect/unstable/process/ChildProcess\"\nimport { ChildProcessSpawner, make as makeSpawner } from \"effect/unstable/process/ChildProcessSpawner\"\nimport * as CommandLine from \"./CommandLine.ts\"\nimport { GrantStore } from \"./GrantStore.ts\"\nimport * as Containment from \"./internal/Containment.ts\"\nimport { makeCapability } from \"./internal/makeCapability.ts\"\nimport * as ProcessConfinement from \"./ProcessConfinement.ts\"\nimport * as Rooted from \"./Rooted.ts\"\nimport { Workspace } from \"./Workspace.ts\"\n\nconst data = (value: object, name: PropertyKey): unknown => {\n const descriptor = Object.getOwnPropertyDescriptor(value, name)\n if (descriptor === undefined || !(\"value\" in descriptor)) {\n throw new TypeError(`command ${String(name)} must be a data property`)\n }\n return descriptor.value\n}\n\nconst optionalData = (value: object, name: PropertyKey): unknown => {\n const descriptor = Object.getOwnPropertyDescriptor(value, name)\n if (descriptor === undefined) return undefined\n if (!(\"value\" in descriptor)) throw new TypeError(`command ${String(name)} must be a data property`)\n return descriptor.value\n}\n\nconst snapshotRecord = (\n value: Readonly<Record<string, string | undefined>> | undefined\n): Record<string, string | undefined> | undefined => {\n if (value === undefined) return undefined\n const snapshot: Record<string, string | undefined> = Object.create(null)\n for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {\n if (!descriptor.enumerable) continue\n if (!(\"value\" in descriptor) || (descriptor.value !== undefined && typeof descriptor.value !== \"string\")) {\n throw new TypeError(\"command environment must contain string data properties\")\n }\n snapshot[name] = descriptor.value\n }\n return Object.freeze(snapshot)\n}\n\nconst snapshotStreamConfig = <A>(value: A): A => {\n if (typeof value !== \"object\" || value === null) return value\n const descriptors = Object.getOwnPropertyDescriptors(value)\n if (descriptors.stream === undefined) return value\n if (!(\"value\" in descriptors.stream)) throw new TypeError(\"command stream must be a data property\")\n const snapshot: Record<string, unknown> = { stream: descriptors.stream.value }\n for (const name of [\"endOnDone\", \"encoding\"] as const) {\n const descriptor = descriptors[name]\n if (descriptor !== undefined) {\n if (!(\"value\" in descriptor)) throw new TypeError(`command ${name} must be a data property`)\n snapshot[name] = descriptor.value\n }\n }\n return Object.freeze(snapshot) as A\n}\n\nconst snapshotAdditionalFds = (\n value: ChildProcess.CommandOptions[\"additionalFds\"]\n): ChildProcess.CommandOptions[\"additionalFds\"] => {\n if (value === undefined) return undefined\n const snapshot: Record<`fd${number}`, ChildProcess.AdditionalFdConfig> = {}\n for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {\n if (!descriptor.enumerable) continue\n if (!(\"value\" in descriptor) || typeof descriptor.value !== \"object\" || descriptor.value === null) {\n throw new TypeError(\"additional file descriptors must be data records\")\n }\n const config = descriptor.value as ChildProcess.AdditionalFdConfig\n const type = data(config, \"type\")\n if (type === \"input\") {\n const stream = Object.getOwnPropertyDescriptor(config, \"stream\")\n snapshot[name as `fd${number}`] = Object.freeze({\n type,\n ...(stream === undefined ? {} : \"value\" in stream ? { stream: stream.value } : (() => {\n throw new TypeError(\"additional fd stream must be a data property\")\n })())\n })\n } else if (type === \"output\") {\n const sink = Object.getOwnPropertyDescriptor(config, \"sink\")\n snapshot[name as `fd${number}`] = Object.freeze({\n type,\n ...(sink === undefined ? {} : \"value\" in sink ? { sink: sink.value } : (() => {\n throw new TypeError(\"additional fd sink must be a data property\")\n })())\n })\n } else {\n throw new TypeError(\"additional file descriptor type is invalid\")\n }\n }\n return Object.freeze(snapshot)\n}\n\nconst snapshotOptions = (options: ChildProcess.CommandOptions): ChildProcess.CommandOptions =>\n Object.freeze({\n killSignal: options.killSignal,\n forceKillAfter: options.forceKillAfter,\n cwd: options.cwd,\n env: snapshotRecord(options.env),\n extendEnv: options.extendEnv,\n shell: options.shell,\n detached: options.detached,\n windowsHide: options.windowsHide,\n stdin: snapshotStreamConfig(options.stdin),\n stdout: snapshotStreamConfig(options.stdout),\n stderr: snapshotStreamConfig(options.stderr),\n additionalFds: snapshotAdditionalFds(options.additionalFds)\n })\n\nconst snapshotCommand = (command: ChildProcess.Command): ChildProcess.Command => {\n const tag = data(command, \"_tag\")\n if (tag === \"StandardCommand\") {\n const executable = data(command, \"command\")\n const args = data(command, \"args\")\n const options = data(command, \"options\")\n if (typeof executable !== \"string\" || !Array.isArray(args) || !args.every((arg) => typeof arg === \"string\")) {\n throw new TypeError(\"standard command executable and arguments are invalid\")\n }\n if (typeof options !== \"object\" || options === null) throw new TypeError(\"command options are invalid\")\n return ChildProcess.make(\n executable,\n Object.freeze([...args]),\n snapshotOptions(options)\n )\n }\n if (tag === \"PipedCommand\") {\n const left = data(command, \"left\")\n const right = data(command, \"right\")\n const options = data(command, \"options\")\n if (typeof left !== \"object\" || left === null || typeof right !== \"object\" || right === null) {\n throw new TypeError(\"pipeline commands are invalid\")\n }\n if (typeof options !== \"object\" || options === null) throw new TypeError(\"pipeline options are invalid\")\n const from = optionalData(options, \"from\")\n const to = optionalData(options, \"to\")\n return ChildProcess.pipeTo(\n snapshotCommand(right as ChildProcess.Command),\n Object.freeze({\n ...(from === undefined ? {} : { from: from as ChildProcess.PipeFromOption }),\n ...(to === undefined ? {} : { to: to as ChildProcess.PipeToOption })\n })\n )(snapshotCommand(left as ChildProcess.Command))\n }\n throw new TypeError(\"unsupported command shape\")\n}\n\nconst maximumEnvironmentNames = 64\n\n/**\n * The environment this process holds, which a child built with\n * `ChildProcessEnvironment.make` inherits its bootstrap names from. Empty on a\n * host with no process environment, so every declared bootstrap name counts\n * as an override there.\n */\nconst ambientEnvironment = (): Readonly<Record<string, string | undefined>> =>\n (globalThis as { readonly process?: { readonly env?: Record<string, string | undefined> } }).process?.env ?? {}\n\nconst environmentNames = (command: ChildProcess.StandardCommand): ReadonlyArray<string> | undefined => {\n const environment = command.options.env\n if (environment === undefined) return undefined\n const names = Object.entries(environment)\n .filter(([, value]) => value !== undefined)\n .map(([name]) => name)\n .sort()\n if (names.length === 0) return undefined\n return names.length <= maximumEnvironmentNames\n ? names\n : [...names.slice(0, maximumEnvironmentNames), `+${names.length - maximumEnvironmentNames} more`]\n}\n\n/**\n * Effect's own process spawner tag, unchanged. Re-exported so the kernel\n * namespace stays one-stop; it is the *same* tag, never a second one.\n *\n * @category services\n * @since 1.0.0-rc.0\n */\nexport { ChildProcessSpawner } from \"effect/unstable/process/ChildProcessSpawner\"\n\n/**\n * Derives the full six-method surface from one `spawn`, so `exitCode`,\n * `string`, `lines`, and both `stream*` helpers can never bypass whatever\n * `spawn` was given.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport { make } from \"effect/unstable/process/ChildProcessSpawner\"\n\n/**\n * Constructs an unavailable spawner stub.\n *\n * Every derived helper reports the missing host as a `NotFound`\n * `PlatformError` naming the command line, so an unconfigured capability\n * answers rather than vanishing.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const makeNoop = (\n overrides: Partial<ChildProcessSpawner[\"Service\"]> = {}\n): ChildProcessSpawner[\"Service\"] => ({\n ...makeSpawner((command) =>\n Effect.fail(\n systemError({\n _tag: \"NotFound\",\n module: \"ChildProcessSpawner\",\n method: \"spawn\",\n description: `no process host for \\`${CommandLine.render(command)}\\``\n })\n )\n ),\n ...overrides\n})\n\n/**\n * Provides an unavailable spawner stub.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layerNoop = (\n overrides: Partial<ChildProcessSpawner[\"Service\"]> = {}\n): Layer.Layer<ChildProcessSpawner> => Layer.succeed(ChildProcessSpawner)(makeNoop(overrides))\n\n/**\n * Decorates the process spawner in place with a `proc:spawn` capability check.\n *\n * The check is suspended into the spawn itself, so building a `Command` or a\n * stream neither requests permission nor starts a process; only running one\n * does. Every pipeline stage is checked as its own capability, left to right,\n * and no stage starts until all pass. A stage's resource is\n * `CommandLine.resource`: the command line `CommandLine.render` produces, with\n * a `shell: true` line that holds shell control syntax marked as\n * `sh -c '<line>'`, any environment variable the child would not inherit from\n * this process named in an `env <NAME>\u2026 -- ` prefix, and a working directory\n * outside `Workspace.root` named in a `cwd <path> -- ` prefix. Custom shell\n * paths are included explicitly in the resource; browser and remote adapters\n * reject them rather than silently substituting a different shell.\n *\n * Every approved stage requires `ProcessConfinement` in the host context.\n * A missing service refuses spawning; its `layerNoop` is the explicit choice\n * for an unconfined host.\n *\n * Pipeline `from`/`to` routing remains outside the grant. The working\n * directory and overridden environment names also reach attended surfaces as\n * display metadata; environment values never leave the command.\n *\n * The layer provides the tag it also requires: compose it over a host spawner\n * layer with `Layer.provide` and a `ChildProcess.Command` run as a plain\n * `Effect` is checked too.\n *\n * A command with no `cwd`, or a relative one, runs in `Workspace.root`, never\n * the process's own directory; the check sees that resolved directory. When\n * the host filesystem is in the layer's context, the working directory and\n * `Workspace.root` are compared by real path, so a symlink inside the\n * workspace that leads out of it is named, as its target, in the `cwd` prefix.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layer: Layer.Layer<\n ChildProcessSpawner,\n never,\n ChildProcessSpawner | GrantStore | Path.Path | Workspace\n> = Layer.effect(\n ChildProcessSpawner,\n Effect.gen(function*() {\n const spawner = yield* ChildProcessSpawner\n const grants = yield* GrantStore\n const confinement = yield* Effect.serviceOption(ProcessConfinement.ProcessConfinement)\n const path = yield* Path.Path\n const rooted = Rooted.path(path, path.resolve((yield* Workspace).root))\n const root = rooted.resolve(\".\")\n // The raw host filesystem this layer is composed over, when there is one.\n // A symlink inside the workspace can lead out of it, so containment is\n // judged on real paths; a directory that cannot be resolved (it does not\n // exist, or the host has no filesystem) is judged lexically.\n const fileSystem = yield* Effect.serviceOption(FileSystem.FileSystem)\n const real = (directory: string) =>\n Option.match(fileSystem, {\n onNone: () => Effect.succeed(directory),\n onSome: (fs) => fs.realPath(directory).pipe(Effect.orElseSucceed(() => directory))\n })\n const within = (base: string) => (directory: string) => {\n const relative = path.relative(base, directory)\n return relative.split(path.sep)[0] !== \"..\" && !path.isAbsolute(relative)\n }\n const checkStage = (stage: ChildProcess.StandardCommand) =>\n Effect.gen(function*() {\n // Rooted.command gives every stage an absolute cwd.\n const cwd = stage.options.cwd!\n const realRoot = yield* real(root)\n const resolvedCwd = yield* real(cwd)\n const contains = resolvedCwd === cwd\n ? (directory: string) => within(root)(directory) || within(realRoot)(directory)\n : within(realRoot)\n return yield* checkResolved(\n stage,\n CommandLine.resource(stage, {\n ambient: ambientEnvironment(),\n contains,\n resolvedCwd\n })\n )\n })\n const checkResolved = (stage: ChildProcess.StandardCommand, rendered: string) => {\n const environment = environmentNames(stage)\n return makeCapability(\"proc:spawn\", rendered).pipe(\n Effect.flatMap((capability) =>\n grants.check(capability, {\n cwd: stage.options.cwd,\n ...(environment === undefined ? {} : { env: environment })\n })\n ),\n Effect.mapError((error) =>\n toPlatformError({\n module: \"ChildProcessSpawner\",\n method: \"spawn\",\n pathOrDescriptor: rendered,\n error\n })\n )\n )\n }\n const check = (command: ChildProcess.Command) =>\n Effect.forEach(CommandLine.stages(command), checkStage, { discard: true })\n const confine = (\n command: ChildProcess.Command\n ): Effect.Effect<\n ChildProcess.Command,\n PlatformError,\n Scope.Scope\n > =>\n Option.match(confinement, {\n onNone: () =>\n Effect.fail(systemError({\n _tag: \"NotFound\",\n module: \"ProcessConfinement\",\n method: \"confine\",\n description:\n \"process confinement is required; use ProcessConfinement.layerNoop to explicitly run unconfined\"\n })),\n onSome: (service) =>\n Effect.gen(function*() {\n const profile = yield* ProcessConfinement.profile(grants, root, path).pipe(\n Effect.mapError((error) => toPlatformError({ module: \"ChildProcessSpawner\", method: \"spawn\", error }))\n )\n const wrap = (\n command: ChildProcess.Command\n ): Effect.Effect<\n ChildProcess.Command,\n PlatformError,\n Scope.Scope\n > =>\n command._tag === \"StandardCommand\"\n ? service.confine(command, profile)\n : Effect.gen(function*() {\n const left = yield* wrap(command.left)\n const right = yield* wrap(command.right)\n return ChildProcess.pipeTo(right, command.options)(left)\n })\n return yield* wrap(command)\n })\n })\n return Containment.inherit(\n spawner,\n makeSpawner(\n Effect.fn(\"ChildProcessSpawner.spawn\")((command: ChildProcess.Command) =>\n Effect.try({\n try: () => snapshotCommand(command),\n catch: () =>\n systemError({\n _tag: \"InvalidData\",\n module: \"ChildProcessSpawner\",\n method: \"spawn\",\n description: \"command must be an immutable supported process description\"\n })\n }).pipe(\n Effect.map((snapshot) => Rooted.command(snapshot, rooted)),\n Effect.flatMap((rooted) =>\n check(rooted).pipe(Effect.andThen(confine(rooted)), Effect.flatMap(spawner.spawn))\n )\n )\n )\n )\n )\n })\n)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,wBAAgC;AAChC,oBAAoE;AACpE,2BAAgD;AAChD,mBAA8B;AAC9B,iCAAyD;AACzD,kBAA6B;AAC7B,wBAA2B;AAC3B,kBAA6B;AAC7B,4BAA+B;AAC/B,yBAAoC;AACpC,aAAwB;AACxB,uBAA0B;AAuK1B,IAAAA,8BAAoC;AAUpC,IAAAA,8BAAqB;AA/KrB,MAAM,OAAO,CAAC,OAAe,SAA+B;AAC1D,QAAM,a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AA,MAC5B,CAAC;AAAA,IACL,CAAC;AACH,WAAO,YAAY;AAAA,MACjB;AAAA,UACA,2BAAAD;AAAA,QACE,qBAAO,GAAG,2BAA2B;AAAA,UAAE,CAAC,YACtC,qBAAO,IAAI;AAAA,YACT,KAAK,MAAM,gBAAgB,OAAO;AAAA,YAClC,OAAO,UACL,kCAAY;AAAA,cACV,MAAM;AAAA,cACN,QAAQ;AAAA,cACR,QAAQ;AAAA,cACR,aAAa;AAAA,YACf,CAAC;AAAA,UACL,CAAC,EAAE;AAAA,YACD,qBAAO,IAAI,CAAC,aAAa,OAAO,QAAQ,UAAU,MAAM,CAAC;AAAA,YACzD,qBAAO;AAAA,cAAQ,CAACE,YACd,MAAMA,OAAM,EAAE,KAAK,qBAAO,QAAQ,QAAQA,OAAM,CAAC,GAAG,qBAAO,QAAQ,QAAQ,KAAK,CAAC;AAAA,YACnF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
|
+
"names": ["import_ChildProcessSpawner", "makeSpawner", "command", "rooted"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0-rc.0
|
|
3
|
+
*
|
|
4
|
+
* Rendering an `effect/unstable/process` `Command` back to a shell command
|
|
5
|
+
* line.
|
|
6
|
+
*
|
|
7
|
+
* Two callers need the same string and must agree on it exactly:
|
|
8
|
+
*
|
|
9
|
+
* 1. `@smthrs/kernel/ChildProcessSpawner` uses it as the `proc:spawn`
|
|
10
|
+
* capability resource, so a grant reads the way an operator wrote it; and
|
|
11
|
+
* 2. `@smthrs/platform-browser/BrowserChildProcessSpawner` uses it as the line
|
|
12
|
+
* it hands to the in-browser bash interpreter, which has no `argv` to spawn
|
|
13
|
+
* with.
|
|
14
|
+
*
|
|
15
|
+
* A single renderer keeps a granted capability and the command a browser
|
|
16
|
+
* actually runs from drifting apart.
|
|
17
|
+
*
|
|
18
|
+
* The module is pure string handling — no host access — so it stays on the
|
|
19
|
+
* browser-safe side of the package.
|
|
20
|
+
*/
|
|
21
|
+
import type * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
22
|
+
/**
|
|
23
|
+
* Quotes one token for a POSIX shell, leaving obviously safe tokens alone.
|
|
24
|
+
*
|
|
25
|
+
* @category rendering
|
|
26
|
+
* @since 1.0.0-rc.0
|
|
27
|
+
*/
|
|
28
|
+
export declare const quote: (token: string) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Renders a `Command` as a single shell command line.
|
|
31
|
+
*
|
|
32
|
+
* A standard command with `shell: true` renders its tokens verbatim, matching
|
|
33
|
+
* the line Node and the browser interpreter hand to the default shell. A
|
|
34
|
+
* custom shell renders as an explicit `<shell> -c <line>` invocation so the
|
|
35
|
+
* selected executable is part of the permission resource. Without `shell`,
|
|
36
|
+
* every token is POSIX-quoted to preserve literal argv semantics. These
|
|
37
|
+
* distinctions are security-sensitive: the rendered value is also the
|
|
38
|
+
* `proc:spawn` capability resource, so it must describe what will execute.
|
|
39
|
+
* The rendering is POSIX-only by contract: on Windows, Node invokes the shell
|
|
40
|
+
* with `/d /s /c` rather than `-c`, so the rendered line describes the POSIX
|
|
41
|
+
* invocation, not a cmd.exe one.
|
|
42
|
+
*
|
|
43
|
+
* The `proc:spawn` capability resource is {@link resource}, which starts from
|
|
44
|
+
* this line and adds what the line alone cannot show.
|
|
45
|
+
*
|
|
46
|
+
* A `PipedCommand` renders with `|` between its sides. That is a faithful
|
|
47
|
+
* rendering of what the pipeline does, and it is the only form an interpreter
|
|
48
|
+
* that takes a command line rather than an `argv` can be given. `from`/`to`
|
|
49
|
+
* pipe options are *not* expressible this way; rendering ignores them, so a
|
|
50
|
+
* pipeline that redirects `stderr` renders like one that pipes `stdout`.
|
|
51
|
+
* Capability checks therefore see the commands, never the plumbing.
|
|
52
|
+
*
|
|
53
|
+
* @category rendering
|
|
54
|
+
* @since 1.0.0-rc.0
|
|
55
|
+
*/
|
|
56
|
+
export declare const render: (command: ChildProcess.Command) => string;
|
|
57
|
+
/**
|
|
58
|
+
* What {@link resource} compares a stage against, supplied by the spawner that
|
|
59
|
+
* checks it.
|
|
60
|
+
*
|
|
61
|
+
* @category models
|
|
62
|
+
* @since 1.0.0-rc.1
|
|
63
|
+
*/
|
|
64
|
+
export interface ResourceContext {
|
|
65
|
+
/**
|
|
66
|
+
* The environment the spawning process itself holds. A bootstrap name
|
|
67
|
+
* (`PATH`, `HOME`, ...) whose declared value equals the ambient value is the
|
|
68
|
+
* inherited default and stays out of the resource; one set to anything else
|
|
69
|
+
* is named. Omitted, every declared bootstrap name is named.
|
|
70
|
+
*/
|
|
71
|
+
readonly ambient?: Readonly<Record<string, string | undefined>> | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a stage's working directory is inside the directory the flow
|
|
74
|
+
* already governs. A `cwd` it rejects is named in the resource. Omitted,
|
|
75
|
+
* every `cwd` a stage sets is named.
|
|
76
|
+
*/
|
|
77
|
+
readonly contains?: ((directory: string) => boolean) | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* The stage `cwd` with every symlink resolved, when the host could resolve
|
|
80
|
+
* it. It replaces the lexical `cwd` both for `contains` and in the
|
|
81
|
+
* `cwd <path> -- ` prefix, so a symlink inside the governed directory that
|
|
82
|
+
* leads out of it is judged, and shown, by where the command really runs.
|
|
83
|
+
*/
|
|
84
|
+
readonly resolvedCwd?: string | undefined;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The stages of a command in execution order: the command itself, or every
|
|
88
|
+
* `StandardCommand` of a pipeline from left to right. The spawner checks each
|
|
89
|
+
* stage as its own `proc:spawn` capability.
|
|
90
|
+
*
|
|
91
|
+
* @category rendering
|
|
92
|
+
* @since 1.0.0-rc.1
|
|
93
|
+
*/
|
|
94
|
+
export declare const stages: (command: ChildProcess.Command) => ReadonlyArray<ChildProcess.StandardCommand>;
|
|
95
|
+
/**
|
|
96
|
+
* The `proc:spawn` capability resource for one stage: {@link render}, with
|
|
97
|
+
* three additions that keep a prefix grant from authorizing code the stage
|
|
98
|
+
* never named.
|
|
99
|
+
*
|
|
100
|
+
* - A `shell: true` stage whose line holds shell control syntax (`;`, `&`,
|
|
101
|
+
* `|`, `` ` ``, `$`, `<`, `>`, `(`, `)`, or a line break) is marked as the
|
|
102
|
+
* explicit `sh -c '<line>'` it is. A grant such as `git status *` then
|
|
103
|
+
* cannot match `git status; curl x | sh`, while a simple shell line such as
|
|
104
|
+
* `git status --short` keeps its verbatim resource. An fd duplication such
|
|
105
|
+
* as `2>&1` and a discard to `/dev/null` do not count as control syntax.
|
|
106
|
+
* - A stage that sets an environment variable the child would not otherwise
|
|
107
|
+
* inherit is prefixed with `env <NAME>… -- `, sorted names only. That is
|
|
108
|
+
* every name outside the bootstrap set `ChildProcessEnvironment` inherits
|
|
109
|
+
* (`PATH`, `HOME`, `USER`, `LANG`, `TERM`, `TMPDIR`, `SHELL`, `LC_*`), and a
|
|
110
|
+
* bootstrap name whose value differs from `context.ambient`. A grant for
|
|
111
|
+
* `git status` covers neither `env GIT_SSH_COMMAND -- git status` nor
|
|
112
|
+
* `env PATH -- git status`. Values never enter the resource because they
|
|
113
|
+
* often carry credentials.
|
|
114
|
+
* - A stage whose `cwd` `context.contains` rejects is prefixed with
|
|
115
|
+
* `cwd <path> -- `, so a grant does not follow the command into a
|
|
116
|
+
* directory whose configuration the flow does not govern. When
|
|
117
|
+
* `context.resolvedCwd` is given, that real path is judged and named
|
|
118
|
+
* instead of the lexical `cwd`.
|
|
119
|
+
*
|
|
120
|
+
* A pipeline has no single resource: the spawner checks every one of its
|
|
121
|
+
* {@link stages}, so `git status | sh` needs a grant for `sh` too.
|
|
122
|
+
*
|
|
123
|
+
* The `env` and `cwd` prefixes share their spelling with a literal command:
|
|
124
|
+
* `make("env", ["PATH", "--", "git", "status"])` renders as
|
|
125
|
+
* `env PATH -- git status`, the resource of `git status` with `PATH`
|
|
126
|
+
* overridden. The alias grants nothing extra. The literal command runs a
|
|
127
|
+
* program named `PATH` (or `cwd`) from the ambient `PATH`, not `git`. A grant
|
|
128
|
+
* with `*` inside the prefix, such as `env * -- git status`, also matches
|
|
129
|
+
* `env -C /x -- git status`, but it already admits any variable name,
|
|
130
|
+
* including `GIT_SSH_COMMAND` and `LD_PRELOAD`, which run arbitrary code.
|
|
131
|
+
* Grant a prefixed resource exactly as the request shows it.
|
|
132
|
+
*
|
|
133
|
+
* @category rendering
|
|
134
|
+
* @since 1.0.0-rc.1
|
|
135
|
+
*/
|
|
136
|
+
export declare const resource: (command: ChildProcess.StandardCommand, context?: ResourceContext) => string;
|
|
137
|
+
/**
|
|
138
|
+
* The executable a command runs, without its arguments.
|
|
139
|
+
*
|
|
140
|
+
* A durable record of a spawned process names its program with this rather
|
|
141
|
+
* than with {@link render}: arguments carry credentials (`curl -u user:pass`,
|
|
142
|
+
* `mysql -phunter2`), and a journal that keeps them keeps them permanently.
|
|
143
|
+
* Nothing that reads such a record needs more than the program name; a reaper
|
|
144
|
+
* matches processes by pid and process group.
|
|
145
|
+
*
|
|
146
|
+
* Without `shell`, `command` is the executable itself, spaces and all. With a
|
|
147
|
+
* shell, the line is what runs, so the program is its first token: both
|
|
148
|
+
* `make("mysql -phunter2", [], { shell: true })` and
|
|
149
|
+
* `make("mysql", ["-phunter2"])` yield `mysql`. A pipeline names one
|
|
150
|
+
* executable per stage, joined the way {@link render} joins the stages.
|
|
151
|
+
*
|
|
152
|
+
* @category rendering
|
|
153
|
+
* @since 1.0.0-rc.0
|
|
154
|
+
*/
|
|
155
|
+
export declare const executable: (command: ChildProcess.Command) => string;
|
|
156
|
+
/**
|
|
157
|
+
* The working directory a command runs in, taking the leftmost stage of a
|
|
158
|
+
* pipeline, which is the stage `setCwd` and the spawners agree to treat as the
|
|
159
|
+
* pipeline's own directory.
|
|
160
|
+
*
|
|
161
|
+
* @category rendering
|
|
162
|
+
* @since 1.0.0-rc.0
|
|
163
|
+
*/
|
|
164
|
+
export declare const cwd: (command: ChildProcess.Command) => string | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* The environment overrides a command runs with, taking the leftmost stage of
|
|
167
|
+
* a pipeline for the same reason {@link cwd} does.
|
|
168
|
+
*
|
|
169
|
+
* @category rendering
|
|
170
|
+
* @since 1.0.0-rc.0
|
|
171
|
+
*/
|
|
172
|
+
export declare const env: (command: ChildProcess.Command) => Record<string, string | undefined> | undefined;
|
|
173
|
+
//# sourceMappingURL=CommandLine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLine.d.ts","sourceRoot":"","sources":["../../src/CommandLine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,KAAK,YAAY,MAAM,sCAAsC,CAAA;AAMzE;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAG,MAC4C,CAAA;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,YAAY,CAAC,OAAO,KAAG,MAOG,CAAA;AAiB1D;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAA;IAC3E;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAA;IAChE;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1C;AAgBD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,YAAY,CAAC,OAAO,KAAG,aAAa,CAAC,YAAY,CAAC,eAAe,CACK,CAAA;AAEtG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;G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