@yaks/process 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +249 -2
  3. package/_dist/clock.d.ts +5 -0
  4. package/_dist/clock.d.ts.map +1 -0
  5. package/_dist/command.d.ts +43 -0
  6. package/_dist/command.d.ts.map +1 -0
  7. package/_dist/comp.d.ts +49 -0
  8. package/_dist/comp.d.ts.map +1 -0
  9. package/_dist/env.d.ts +8 -0
  10. package/_dist/env.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +3 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/http.d.ts +11 -0
  14. package/_dist/http.d.ts.map +1 -0
  15. package/_dist/isolate.d.ts +11 -0
  16. package/_dist/isolate.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +49 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/modules.d.ts +31 -0
  20. package/_dist/modules.d.ts.map +1 -0
  21. package/_dist/platform.d.ts +7 -0
  22. package/_dist/platform.d.ts.map +1 -0
  23. package/_dist/plugin.d.ts +15 -0
  24. package/_dist/plugin.d.ts.map +1 -0
  25. package/_dist/run.d.ts +219 -0
  26. package/_dist/run.d.ts.map +1 -0
  27. package/_dist/self.d.ts +32 -0
  28. package/_dist/self.d.ts.map +1 -0
  29. package/_dist/socket.d.ts +11 -0
  30. package/_dist/socket.d.ts.map +1 -0
  31. package/_dist/store.d.ts +22 -0
  32. package/_dist/store.d.ts.map +1 -0
  33. package/_dist/system.d.ts +64 -0
  34. package/_dist/system.d.ts.map +1 -0
  35. package/_dist/trash.d.ts +6 -0
  36. package/_dist/trash.d.ts.map +1 -0
  37. package/_dist/views.d.ts +4 -0
  38. package/_dist/views.d.ts.map +1 -0
  39. package/_dist/vocab.d.ts +8 -0
  40. package/_dist/vocab.d.ts.map +1 -0
  41. package/_dist/wind.d.ts +35 -0
  42. package/_dist/wind.d.ts.map +1 -0
  43. package/clock.js +11 -0
  44. package/clock.js.map +1 -0
  45. package/clock.ts +11 -0
  46. package/command.js +172 -0
  47. package/command.js.map +1 -0
  48. package/command.ts +215 -0
  49. package/comp.js +54 -0
  50. package/comp.js.map +1 -0
  51. package/comp.ts +123 -0
  52. package/deno.json +1 -0
  53. package/detached.js +60 -0
  54. package/detached.js.map +1 -0
  55. package/detached.ts +92 -0
  56. package/detached_worker.ts +22 -0
  57. package/env.js +13 -0
  58. package/env.js.map +1 -0
  59. package/env.ts +24 -0
  60. package/graph.js +7 -0
  61. package/graph.js.map +1 -0
  62. package/graph.ts +8 -0
  63. package/http.js +158 -0
  64. package/http.js.map +1 -0
  65. package/http.ts +184 -0
  66. package/isolate.js +41 -0
  67. package/isolate.js.map +1 -0
  68. package/isolate.ts +52 -0
  69. package/mod.js +49 -0
  70. package/mod.js.map +1 -0
  71. package/mod.ts +50 -0
  72. package/modules.js +41 -0
  73. package/modules.js.map +1 -0
  74. package/modules.ts +69 -0
  75. package/package.json +81 -4
  76. package/platform.js +9 -0
  77. package/platform.js.map +1 -0
  78. package/platform.ts +9 -0
  79. package/plugin.js +27 -0
  80. package/plugin.js.map +1 -0
  81. package/plugin.ts +28 -0
  82. package/run.js +899 -0
  83. package/run.js.map +1 -0
  84. package/run.ts +1139 -0
  85. package/self.js +93 -0
  86. package/self.js.map +1 -0
  87. package/self.ts +144 -0
  88. package/socket.js +38 -0
  89. package/socket.js.map +1 -0
  90. package/socket.ts +49 -0
  91. package/store.js +30 -0
  92. package/store.js.map +1 -0
  93. package/store.ts +50 -0
  94. package/system.js +161 -0
  95. package/system.js.map +1 -0
  96. package/system.ts +216 -0
  97. package/testing.ts +39 -0
  98. package/tidy.ts +28 -0
  99. package/trash.js +117 -0
  100. package/trash.js.map +1 -0
  101. package/trash.ts +117 -0
  102. package/views.js +28 -0
  103. package/views.js.map +1 -0
  104. package/views.ts +30 -0
  105. package/vocab.js +16 -0
  106. package/vocab.js.map +1 -0
  107. package/vocab.json +154 -0
  108. package/vocab.ts +18 -0
  109. package/wind.js +88 -0
  110. package/wind.js.map +1 -0
  111. package/wind.ts +114 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,250 @@
1
- # Temporary Holding Version
1
+ # @yaks/process
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@yaks/process` starts, adopts, monitors, stops, and supervises operating-system
4
+ processes while recording their state in a graph.
5
+
6
+ ```sh
7
+ deno add jsr:@yaks/process
8
+ ```
9
+
10
+ ## Stored components
11
+
12
+ <a id="the-components"></a>
13
+
14
+ A **bundle** is one entity's components as a JSON object. This package defines:
15
+
16
+ | Component | Meaning |
17
+ | ------------------------------------------ | ------------------------------ |
18
+ | `service{command, cwd, restart, attempts}` | a program that should run |
19
+ | `process{pid, command, cwd}` | a tracked running process |
20
+ | `runtime{name, version, os}` | what a process of ours runs on |
21
+ | `exit{code, oom, reason}` | the observed end of a process |
22
+
23
+ A process that opens a graph writes its own row when it starts (`started()`),
24
+ with `runtime` beside `process`: `deno`, its version, and the operating system
25
+ and its release (`linux 6.8.0-45-generic`).
26
+
27
+ An adopted process may contain only `pid`; `command` and `cwd` are recorded for
28
+ processes launched by this package. A missing `exit` means the process is still
29
+ considered active. On a supervised entity, starting the next attempt removes the
30
+ previous `exit` in the same transaction. An unsupervised process retains its
31
+ `exit`; launching it again creates a new entity.
32
+
33
+ `service.restart` accepts `never`, `on-failure`, or `always`, and defaults to
34
+ `never`. To stop a service, add the `stop` marker from `@yaks/session` to the
35
+ same entity.
36
+
37
+ The graph stores process state, never output. What a process prints stays in its
38
+ stdout and stderr files: `await tail(eid, n)` reads their last lines, and
39
+ `await clean(eid)` moves a finished run's files into private `.trash/` beside
40
+ them once its reader is done with them, and `sweep(age, opts, store)` cleans
41
+ files with a launch marker and a complete exit code older than `age`
42
+ milliseconds. With a store, it preserves sessions, services and processes whose
43
+ exit is not recorded. Machines pass their store and share one sweep per
44
+ process-file directory at most once an hour, with no overlapping sweeps. A
45
+ service's output files are its log, appended to across attempts. Supervisor
46
+ files are stored under `opts.dir`, then `$PROCESS_DIR`, then
47
+ `$TASKS_HOME/processes`, then `~/.tasks/processes`. For tests, set `TASKS_HOME`
48
+ instead of changing `HOME` so Deno can reuse its module cache. This changes
49
+ supervisor file locations, not the child environment.
50
+
51
+ On Linux, if the wrapper cannot write the exit record beside the logs, it writes
52
+ the provider's exit code and the failed write's reason to the systemd user
53
+ manager's runtime filesystem. A replacement watcher can recover that record. The
54
+ watcher retries a graph write that runs out of disk space.
55
+
56
+ `@yaks/process/trash` supplies the host filesystem's shared `trash(path, root?)`
57
+ and `restore(record)` operations. Each private record retains `source.json` with
58
+ its original path and time plus `data` with the original bytes. The default root
59
+ is `~/.yak/trash/files`, including files made in temporary directories.
60
+ `restore` returns the restored path. If the original path is occupied, it
61
+ chooses a free name. The box's nightly backup evicts older records above its
62
+ local trash budgets.
63
+
64
+ ## Launching and adopting processes
65
+
66
+ <a id="the-process-you-are-in"></a>
67
+ <a id="four-entry-points-one-loop"></a>
68
+
69
+ Given an application graph loaded with the process vocabulary (the example
70
+ starts a process under systemd, so it is not run as a test):
71
+
72
+ ```ts ignore
73
+ import { adopt, launch, store, watch } from '@yaks/process'
74
+
75
+ const processes = store(graph)
76
+ const run = await launch(processes, {
77
+ command: 'sh',
78
+ args: ['-c', 'echo hi'],
79
+ })
80
+ const code = await run.done
81
+
82
+ // Replace 4242 with the PID of an existing process to monitor.
83
+ await adopt(processes, 4242)
84
+ await watch(processes)
85
+ ```
86
+
87
+ `launch()` records the process, writes stdout and stderr to files, and returns
88
+ `{ eid, pid, done }`. `adopt()` monitors a process that this package did not
89
+ start. `watch()` resumes monitoring every stored process without an `exit`.
90
+ `vanished()` finds the rows without an `exit` whose pid is gone from this
91
+ machine and that this package did not launch: a process that ended without
92
+ writing its own ending, for whoever cleans up after it. `gone()` asks whether
93
+ one process is over: its row records an `exit`, or it is among the vanished.
94
+ `launch()` passes only the environment supplied in its specification.
95
+
96
+ Launched processes run through a short-lived launcher and a wrapper in a session
97
+ and process group of its own. The wrapper writes a pidfile and an exit-code
98
+ file, which on Linux also counts the processes the kernel's OOM killer ended in
99
+ the run's control group (`exit.oom`); the launch writes a start file. The
100
+ pidfile contains the wrapper's process-group ID and the child's PID. Monitoring
101
+ uses signals and the files because the tracked program is not a direct child;
102
+ this package does not call `waitpid` or reap children. This allows a child to
103
+ outlive the process that opened the graph and be monitored again after restart.
104
+ A run launched before the machine last started went with that restart: `watch`
105
+ follows none of its pids, which may name other processes now, and records
106
+ `exit{reason: 'reboot'}` with no code. On Linux, a transient service tracks the
107
+ wrapper's lifetime. When it exits, systemd stops every remaining process in that
108
+ service, including fixtures started with `setsid` or `nohup`, with two seconds
109
+ to drain before SIGKILL. Independently managed launches have their own services
110
+ and survive that cleanup.
111
+
112
+ Only the detaching differs by operating system:
113
+
114
+ | OS | Detached by | Needs |
115
+ | ----- | --------------------------------------------------- | ---------------------------------- |
116
+ | Linux | `systemd-run --user`, then `setsid` | util-linux, a systemd user manager |
117
+ | macOS | perl's `setsid()`; launchd stops only a job's group | `/usr/bin/perl` |
118
+
119
+ Any other OS is refused at launch. `opts.os` picks another OS's launcher, which
120
+ is how a Linux machine tests the macOS one.
121
+
122
+ The process that opens a graph is the **host**. `started()` returns the bundle
123
+ that records the host's process entity, named by the command a person ran
124
+ (`yak task new Buy the cake`, which is also how it reads wherever it is named,
125
+ ./views.ts), `ended()` records its exit, and `selfEid()` returns the stable
126
+ in-memory entity ID for that host run. The host can sign writes with this
127
+ entity, so `created.by` identifies the specific program run that wrote a row. A
128
+ host's row also says which roles it serves (`process.roles`, from @yaks/cli
129
+ `compose`): `graph`, `web`, `effects`, or a plugin's service by its name.
130
+
131
+ A Worker thread that opens a graph is a host of its own, with its own row in the
132
+ pid it runs in. The pid lives on after the thread, so its `exit` is what
133
+ `gone()` reads: a process that ends its thread where it stands names it first
134
+ with `become(eid)`, and writes that `exit` for it.
135
+
136
+ ```ts
137
+ import { equal } from '@yaks/testing'
138
+ import { ended, started } from '@yaks/process'
139
+ import * as system from '@yaks/process/system'
140
+
141
+ let beginning = started()
142
+ let ending = ended(0)
143
+ equal(ending.entity, beginning.entity)
144
+ // The command is the program and its arguments; under `deno run`, the program
145
+ // is the script, so `deno run -A yak.ts task new` is `yak task new`.
146
+ let script = system.mainModule.split('/').pop()!.replace(/\.[cm]?[jt]sx?$/, '')
147
+ equal(beginning.process, {
148
+ pid: system.pid,
149
+ command: [script, ...system.args].join(' '),
150
+ cwd: system.cwd(),
151
+ })
152
+ equal(beginning.runtime, {
153
+ name: system.runtimeName,
154
+ version: system.runtimeVersion,
155
+ os: `${system.os} ${system.osRelease()}`,
156
+ })
157
+ equal(ending.exit, { code: 0 })
158
+
159
+ // The host records these bundles in its graph:
160
+ // await g.apply([beginning])
161
+ // on shutdown:
162
+ // await g.apply([ending])
163
+ ```
164
+
165
+ ## Supervision
166
+
167
+ `supervise(store, options)` returns one reconciliation pass. Call it from the
168
+ host's timer: `setInterval(supervise(store(graph)), 2000)`.
169
+
170
+ Each pass starts services without a process, restarts eligible exited services
171
+ with exponential backoff capped by the configured `ceiling`, stops entities
172
+ marked `stop`, and stops processes whose service entity was deleted. Monitoring
173
+ code writes `exit`; the supervisor does not infer an exit from missing in-memory
174
+ state. The `refuse` option prevents specified commands from being supervised and
175
+ always refuses the supervisor's own command.
176
+
177
+ `Store` is the minimal persistence interface used by launch and supervision:
178
+ `apply()` writes a **batch** (a list of bundles committed in one transaction),
179
+ `get()` reads given rows, `running()` reads processes without an exit, and
180
+ `services()` reads service entities. `store(graph)` implements it with graph
181
+ reads.
182
+
183
+ ## Exports
184
+
185
+ <a id="the-store"></a>
186
+
187
+ The main module exports:
188
+
189
+ - vocabulary: `processDoc`, `SERVICE`, `PROCESS`, `EXIT`, and their TypeScript
190
+ types;
191
+ - host identity: `selfEid()`, `become()`, `started()`, and `ended()`;
192
+ - storage: `Store`, `store()`, `RUNNING`, and `SERVICES`;
193
+ - graph integration: `processes()`;
194
+ - process operations: `dirOf()`, `paths()`, `clean()`, `launch()`, `adopt()`,
195
+ `watch()`, `vanished()`, `gone()`, `signal()`, and `supervise()`.
196
+
197
+ Additional entry points are `@yaks/process/vocab`, `@yaks/process/graph` and
198
+ `@yaks/process/wind`.
199
+
200
+ `@yaks/process/command` launches commands with independent stdin, stdout and
201
+ stderr modes. `ipc: true` adds a parent-child channel separate from those
202
+ streams; `disconnected()` from `@yaks/process/system` settles in the child when
203
+ its parent closes the channel or exits, including an exit before the child
204
+ starts listening. A child's `kill()` signals it by pid and leaves that channel
205
+ open, so a child told to drain is not also told its parent is gone.
206
+ `detached: true` gives the child its own session and process group, led by its
207
+ pid. Where util-linux's `setsid` is on `PATH`, the child starts through it: Deno
208
+ would otherwise fork to detach, copying the parent's page tables on the calling
209
+ thread (about 50 ms per GB of the parent's memory). `started` settles once the
210
+ child runs and rejects when it cannot start (a missing program), before any of
211
+ its streams is used. `unref()` lets the parent exit while the child runs, its
212
+ piped streams included; `ref()` holds the parent open again.
213
+
214
+ `@yaks/process/modules` says which modules a set of roots reaches:
215
+ `modules(roots, cwd)` runs `deno info` in the tree at `cwd`, under its config
216
+ and a copy of its lock, and answers the graph, literal dynamic imports included,
217
+ or undefined when deno cannot say.
218
+
219
+ ## Winding down
220
+
221
+ `@yaks/process/wind` is how a process ends when it is asked to. An interrupt is
222
+ a signal (`listen()` hears SIGTERM, SIGINT and SIGHUP) or a Ctrl-C typed into a
223
+ raw terminal. Whatever keeps the process open calls
224
+ `wind.hold({ drain, force })`. The first interrupt asks every hold to drain,
225
+ with no deadline; a second forces them. `wind.done` settles with the interrupt's
226
+ code once every hold has answered. There is one `wind` per process; `winding()`
227
+ makes another for a test.
228
+
229
+ ## Workspace execution
230
+
231
+ File-and-command execution belongs to
232
+ [@yaks/machine](../machine/README.md#durable-execution). Every managed launch
233
+ records `process.workspace` and its original `process.cwd`. Changing a session's
234
+ default workspace does not change process recovery or stop that process. Sandbox
235
+ provisioning belongs to [@yaks/sandbox](../sandbox/README.md).
236
+
237
+ ## Linux isolation
238
+
239
+ `@yaks/process/isolate` provides `scope(unit)`, the argv prefix that runs a
240
+ command in an independent systemd user scope, and `bus(uid)`, its user-manager
241
+ environment. Receipt-based launchers use this same boundary without adopting the
242
+ local supervisor's files or graph ownership.
243
+
244
+ ```ts
245
+ import { equal } from '@yaks/testing'
246
+ import { bus, scope } from '@yaks/process/isolate'
247
+
248
+ equal(bus(1000).XDG_RUNTIME_DIR, '/run/user/1000')
249
+ equal(scope('example-run').at(-1), '--unit=example-run')
250
+ ```
@@ -0,0 +1,5 @@
1
+ export declare let clock: {
2
+ readonly now: any;
3
+ readonly after: (ms: number, run: () => void) => () => void;
4
+ };
5
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sources":["../clock.ts"],"names":[],"mappings":"AAGA,OAAO,YAAI;WACT;WACA,QAAQ,IAAI,MAAM,EAAE,WAAW,IAAI,WAAS,IAAI;EAKjD"}
@@ -0,0 +1,43 @@
1
+ import process from 'node:process';
2
+ import { type Signal } from "./system.js";
3
+ export type CommandOptions = {
4
+ args?: string[];
5
+ cwd?: string | URL;
6
+ env?: Record<string, string>;
7
+ clearEnv?: boolean;
8
+ stdin?: 'piped' | 'inherit' | 'null';
9
+ stdout?: 'piped' | 'inherit' | 'null';
10
+ stderr?: 'piped' | 'inherit' | 'null';
11
+ signal?: AbortSignal;
12
+ detached?: boolean;
13
+ ipc?: boolean;
14
+ uid?: number;
15
+ gid?: number;
16
+ windowsRawArguments?: boolean;
17
+ };
18
+ export type CommandStatus = {
19
+ success: boolean;
20
+ code: number;
21
+ signal: Signal | null;
22
+ };
23
+ export type CommandOutput = CommandStatus & {
24
+ stdout: Uint8Array<ArrayBuffer>;
25
+ stderr: Uint8Array<ArrayBuffer>;
26
+ };
27
+ export type ChildProcess = {
28
+ pid: number;
29
+ /** Settles once the child is running, or rejects when it could not start
30
+ * (a missing program), before any of its pipes are used. */ started: Promise<void>;
31
+ status: Promise<CommandStatus>;
32
+ stdin: WritableStream<Uint8Array>;
33
+ stdout: ReadableStream<Uint8Array<ArrayBuffer>>;
34
+ stderr: ReadableStream<Uint8Array<ArrayBuffer>>;
35
+ output: () => Promise<CommandOutput>;
36
+ kill: (signal?: Signal) => void;
37
+ ref: () => void;
38
+ unref: () => void;
39
+ [Symbol.asyncDispose]: () => Promise<void>;
40
+ };
41
+ /** The executable a bare program name runs from `PATH`, as `execvp` finds it. */ export declare let found: (name: string) => string | undefined;
42
+ export declare let command: (program: string | URL, o?: CommandOptions) => any;
43
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sources":["../command.ts"],"names":[],"mappings":"AAOA,OAAO,aAAa,eAAc;AAIlC,SAAS,KAAK,MAAM,sBAAiC;AAErD,YAAY;EACV,OAAO,MAAM;EACb,MAAM,MAAM,GAAG;EACf,MAAM,OAAO,MAAM,EAAE,MAAM;EAC3B,WAAW,OAAO;EAClB,QAAQ,UAAU,YAAY;EAC9B,SAAS,UAAU,YAAY;EAC/B,SAAS,UAAU,YAAY;EAC/B,SAAS;EACT,WAAW,OAAO;EAClB,MAAM,OAAO;EACb,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,sBAAsB,OAAO;;AAE/B,YAAY;EACV,SAAS,OAAO;EAChB,MAAM,MAAM;EACZ,QAAQ,SAAS,IAAI;;AAEvB,YAAY,gBAAgB;EAC1B,QAAQ,WAAW;EACnB,QAAQ,WAAW;;AAErB,YAAY;EACV,KAAK,MAAM;EACX;4DAC0D,GAC1D,SAAS,QAAQ,IAAI;EACrB,QAAQ,QAAQ;EAChB,OAAO,eAAe;EACtB,QAAQ,eAAe,WAAW;EAClC,QAAQ,eAAe,WAAW;EAClC,cAAc,QAAQ;EACtB,OAAO,SAAS,WAAW,IAAI;EAC/B,WAAW,IAAI;EACf,aAAa,IAAI;GAChB,OAAO,YAAY,SAAS,QAAQ,IAAI;;AAiH3C,+EAA+E,GAC/E,OAAO,YAAI,QACT,MAAM,MAAM,KAEX,MAAM,GAAG,SAAS,CAMlB;AA2BH,OAAO,YAAI,UAAW,SAAS,MAAM,GAAG,KAAK,IAAG,uBAc9C"}
@@ -0,0 +1,49 @@
1
+ import type { Entity } from "@yaks/graph";
2
+ import type { VocabDoc } from "@yaks/vocab";
3
+ /** The component recording that a program should be running. */ export declare let SERVICE: string;
4
+ /** The component naming a running program. */ export declare let PROCESS: string;
5
+ /** The component recording what a process of ours runs on. */ export declare let RUNTIME: string;
6
+ /** The component recording that it is over. */ export declare let EXIT: string;
7
+ /** What to do when a service's process exits — systemd's three values. */ export type Restart = 'never' | 'on-failure' | 'always';
8
+ /** A program that should be running. */ export type Service = {
9
+ /** the command line to run, argv joined by spaces */ command?: string | null;
10
+ /** where to run it; absent means the supervisor's own working directory */ cwd?: string | null;
11
+ /** what to do when it exits; absent means never */ restart?: Restart | null;
12
+ /** how many times it has been started again after an exit */ attempts?: number | null;
13
+ };
14
+ /** A tracked process. */ export type Process = {
15
+ /** original launch workspace; a local observer must not inspect its pid */ workspace?: string | null;
16
+ /** the process id on the machine tracking it */ pid?: number | null;
17
+ /** the command line it was launched with — absent on an adopted process */ command?: string | null;
18
+ /** where it was launched — absent on an adopted process */ cwd?: string | null;
19
+ /** the roles it serves, where it opened a graph */ roles?: string[] | null;
20
+ /** the process launching it and reading how it goes, or the one that took
21
+ * it up after: an entity, not a pid */ watcher?: string | null;
22
+ };
23
+ /** What a process of ours runs on, as it says about itself. */ export type Runtime = {
24
+ /** the runtime, lowercase: `deno` */ name?: string | null;
25
+ /** the runtime's version */ version?: string | null;
26
+ /** the operating system and its release: `linux 6.8.0-45-generic` */ os?: string | null;
27
+ };
28
+ /** What is recorded about a process that has ended. */ export type Exit = {
29
+ /** the exit code it reported; absent when the end was observed but the code
30
+ * was not */ code?: number | null;
31
+ /** how many of the run's processes the kernel's OOM killer ended at its
32
+ * memory limit while it ran (Linux, its scope's memory.events); absent when
33
+ * none were or nothing counts them */ oom?: number;
34
+ /** a storage failure observed while the process was ending, or the machine
35
+ * restarting under it (`reboot`), which ends a run with no code */ reason?: 'disk_full' | 'exit_write_failed' | 'reboot';
36
+ };
37
+ /** A bundle carrying a process, as {@link Store.running} returns. */ export type Tracked = {
38
+ entity: Entity;
39
+ } & {
40
+ process: Process;
41
+ exit?: Exit;
42
+ };
43
+ /**
44
+ * The process vocabulary, to load beside your own:
45
+ * `loadVocab([processDoc, ...mine])`. It does not describe why a process
46
+ * runs — that is an ordinary entity in your own vocabulary pointing at this
47
+ * one.
48
+ */ export declare let processDoc: VocabDoc;
49
+ //# sourceMappingURL=comp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comp.d.ts","sources":["../comp.ts"],"names":[],"mappings":"AAyCA,cAAc,MAAM,2BAAgC;AACpD,cAAc,QAAQ,2BAAgC;AAGtD,8DAA8D,GAC9D,OAAO,YAAI,gBAAmB;AAE9B,4CAA4C,GAC5C,OAAO,YAAI,gBAAmB;AAE9B,4DAA4D,GAC5D,OAAO,YAAI,gBAAmB;AAE9B,6CAA6C,GAC7C,OAAO,YAAI,aAAa;AAExB,wEAAwE,GACxE,YAAY,UAAU,UAAU,eAAe;AAE/C,sCAAsC,GACtC,YAAY;EACV,mDAAmD,GACnD,UAAU,MAAM,GAAG,IAAI;EACvB,yEAAyE,GACzE,MAAM,MAAM,GAAG,IAAI;EACnB,iDAAiD,GACjD,UAAU,UAAU,IAAI;EACxB,2DAA2D,GAC3D,WAAW,MAAM,GAAG,IAAI;;AAG1B,uBAAuB,GACvB,YAAY;EACV,yEAAyE,GACzE,YAAY,MAAM,GAAG,IAAI;EACzB,8CAA8C,GAC9C,MAAM,MAAM,GAAG,IAAI;EACnB,yEAAyE,GACzE,UAAU,MAAM,GAAG,IAAI;EACvB,yDAAyD,GACzD,MAAM,MAAM,GAAG,IAAI;EACnB,iDAAiD,GACjD,QAAQ,MAAM,KAAK,IAAI;EACvB;uCACqC,GACrC,UAAU,MAAM,GAAG,IAAI;;AAGzB,6DAA6D,GAC7D,YAAY;EACV,mCAAmC,GACnC,OAAO,MAAM,GAAG,IAAI;EACpB,0BAA0B,GAC1B,UAAU,MAAM,GAAG,IAAI;EACvB,mEAAmE,GACnE,KAAK,MAAM,GAAG,IAAI;;AAGpB,qDAAqD,GACrD,YAAY;EACV;aACW,GACX,OAAO,MAAM,GAAG,IAAI;EACpB;;sCAEoC,GACpC,MAAM,MAAM;EACZ;mEACiE,GACjE,SAAS,cAAc,sBAAsB;;AAG/C,mEAAmE,GACnE,YAAY;EAAY,QAAQ;;EAAa,SAAS;EAAS,OAAO;;AAEtE;;;;;CAKC,GACD,OAAO,YAAI,YAAY,SAAc"}
package/_dist/env.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type Env = {
2
+ get: (name: string) => string | undefined;
3
+ set: (name: string, value: string) => void;
4
+ delete: (name: string) => void;
5
+ toObject: () => Record<string, string>;
6
+ };
7
+ export declare let env: Env;
8
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sources":["../env.ts"],"names":[],"mappings":"AAGA,YAAY;EACV,MAAM,MAAM,MAAM,KAAK,MAAM,GAAG,SAAS;EACzC,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,KAAK,IAAI;EAC1C,SAAS,MAAM,MAAM,KAAK,IAAI;EAC9B,gBAAgB,OAAO,MAAM,EAAE,MAAM;;AAEvC,OAAO,YAAI,KAAK,IAcf"}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "@yaks/graph";
2
+ /** `process`, `service` and `exit`, as a graph plugin. */ export declare let plugins: () => Plugin[];
3
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAGA,cAAc,MAAM,2BAAgC;AAGpD,wDAAwD,GACxD,OAAO,YAAI,eAAc,SAAyB"}
@@ -0,0 +1,11 @@
1
+ import type { Dispatcher } from "undici";
2
+ type Client = {
3
+ fetch: typeof fetch;
4
+ /** ends the pool once its requests finish */ close: () => void | Promise<void>;
5
+ /** ends the pool and its connections now */ destroy?: () => void | Promise<void>;
6
+ };
7
+ /** A fetch pool with an explicit lifetime, shared by Node and Deno callers.
8
+ * Without a dispatcher, its own pool opens with its first request. */ export declare let httpClient: (given?: Dispatcher) => Client;
9
+ /** Collect each answer before closing its request's private connection pool. */ export declare let freshFetch: (create?: () => Client) => typeof fetch;
10
+ /** A streamed request gets its own connection until its response ends. */ export declare let streamingFetch: (create?: () => Client) => typeof fetch;
11
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sources":["../http.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,iBAA4B;KAK/C;EACH,cAAc;EACd,2CAA2C,GAC3C,aAAa,IAAI,GAAG,QAAQ,IAAI;EAChC,0CAA0C,GAC1C,gBAAgB,IAAI,GAAG,QAAQ,IAAI;;AAkErC;oEACoE,GACpE,OAAO,YAAI,aAAc,QAAQ,eAAa,OA4C7C;AAED,8EAA8E,GAC9E,OAAO,YAAI,aACR,eAAc,kBAA6B,MAe3C;AAEH,wEAAwE,GACxE,OAAO,YAAI,iBACR,eAAc,kBAA6B,MAkC3C"}
@@ -0,0 +1,11 @@
1
+ /** The user manager's address, available while user@<uid> is active. */ export declare let bus: (uid: number) => Record<string, string>;
2
+ /** The systemd user slice that holds managed runs. */ export declare let applicationSlice: string;
3
+ /** Lift the following command out of the launcher's systemd unit. Failure to
4
+ * reach that manager must fail the launch, never fall back inside its unit.
5
+ * `properties` are the scope's own, such as `MemoryMax=6G`: a command that
6
+ * grows past its cap is the one the kernel ends. */ export declare let scope: (unit: string, properties?: string[]) => string[];
7
+ /** A managed run owns its descendants until its main process exits. Unlike a
8
+ * scope, this service then ends even descendants that made their own session.
9
+ * Environment references are expanded by systemd into single argv elements;
10
+ * env clears the user manager's extras without putting values in the unit. */ export declare let service: (unit: string, cwd: string, names: string[]) => string[];
11
+ //# sourceMappingURL=isolate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isolate.d.ts","sources":["../isolate.ts"],"names":[],"mappings":"AAGA,sEAAsE,GACtE,OAAO,YAAI,MAAO,KAAK,MAAM,KAAG,OAAO,MAAM,EAAE,MAAM,EAGnD;AAEF,oDAAoD,GACpD,OAAO,YAAI,yBAA8B;AAEzC;;;kDAGkD,GAClD,OAAO,YAAI,QAAS,MAAM,MAAM,EAAE,aAAY,MAAM,OAAU,MAAM,GAQnE;AAED;;;4EAG4E,GAC5E,OAAO,YAAI,UACT,MAAM,MAAM,EACZ,KAAK,MAAM,EACX,OAAO,MAAM,OACZ,MAAM,GAiBR"}