@redue/cli 0.0.0-stage → 0.1.0-alpha.2
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 +22 -0
- package/LICENSE +180 -0
- package/README.md +123 -2
- package/bin/redue.mjs +329 -0
- package/bin/vstate.mjs +3 -0
- package/docs/README.md +20 -0
- package/docs/user/agents.md +32 -0
- package/docs/user/configuration.md +57 -0
- package/docs/user/getting-started.md +127 -0
- package/docs/user/json.md +59 -0
- package/docs/user/shell.md +25 -0
- package/docs/user/supported-projects.md +89 -0
- package/examples/redue.config.json +8 -0
- package/package.json +46 -4
- package/src/cached-state.mjs +27 -0
- package/src/cli.mjs +390 -0
- package/src/control-endpoint.mjs +11 -0
- package/src/daemon.mjs +989 -0
- package/src/decision-profile.mjs +18 -0
- package/src/decision-validation.mjs +41 -0
- package/src/declared-plan.mjs +125 -0
- package/src/executable-lookup.mjs +18 -0
- package/src/glob.mjs +9 -0
- package/src/history-worker.mjs +18 -0
- package/src/index.mjs +306 -0
- package/src/installed-inputs.mjs +110 -0
- package/src/linux-inotify.py +228 -0
- package/src/linux-observer.mjs +79 -0
- package/src/node-onboarding.mjs +263 -0
- package/src/npm-typecheck-probe.mjs +120 -0
- package/src/observation.mjs +37 -0
- package/src/owned-state.mjs +32 -0
- package/src/path-identity.mjs +43 -0
- package/src/plan-worker.mjs +131 -0
- package/src/plan.mjs +10 -0
- package/src/platform-observation.mjs +17 -0
- package/src/platform-state.mjs +14 -0
- package/src/pnpm-inputs.mjs +355 -0
- package/src/pnpm-typecheck-probe.mjs +47 -0
- package/src/presentation.mjs +52 -0
- package/src/probe-result.mjs +21 -0
- package/src/process-liveness.mjs +11 -0
- package/src/run-lock.mjs +77 -0
- package/src/state-store.mjs +37 -0
- package/src/toolchain-probe.mjs +21 -0
- package/src/typescript-contract-probe.mjs +188 -0
- package/src/typescript-list.mjs +68 -0
- package/src/typescript-qualification.mjs +96 -0
- package/src/windows-command.mjs +16 -0
- package/src/windows-process.mjs +15 -0
- package/src/yarn-workspace-inputs.mjs +148 -0
- package/src/yarn-workspace-typecheck-probe.mjs +107 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.2 — 2026-10-06
|
|
4
|
+
|
|
5
|
+
Install: `npm install --global @redue/cli@alpha`.
|
|
6
|
+
|
|
7
|
+
- npm distribution moved to the product-owned `@redue/cli` package.
|
|
8
|
+
- The executable remains `redue`; verification semantics and runtime code are unchanged.
|
|
9
|
+
- Alpha.1 (`@msiric/redue`) remains available but is superseded by the canonical package.
|
|
10
|
+
|
|
11
|
+
## 0.1.0-alpha.1 — 2026-10-06
|
|
12
|
+
|
|
13
|
+
Install: `npm install --global @msiric/redue@alpha`. The command remains `redue`.
|
|
14
|
+
|
|
15
|
+
- Persistent execution evidence with independent CURRENT, STALE, and UNVERIFIED applicability.
|
|
16
|
+
- Node/TypeScript onboarding for npm, supported Yarn node-modules workspaces, and pnpm 12 isolated/hoisted layouts.
|
|
17
|
+
- macOS, Linux, and Windows observation with conservative deterministic recovery.
|
|
18
|
+
- Human status/explain output, JSON integration contract, and recording-only checks.
|
|
19
|
+
- Standard npm tarball installation and scoped state cleanup.
|
|
20
|
+
|
|
21
|
+
Known limitations include incomplete test/lint/build contracts, uncaptured direct
|
|
22
|
+
commands, and synchronized decisions that can cost more than cheap checks. See README.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
15
|
+
other entities that control, are controlled by, or are under common
|
|
16
|
+
control with that entity. For the purposes of this definition,
|
|
17
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
18
|
+
direction or management of such entity, whether by contract or
|
|
19
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
22
|
+
exercising permissions granted by this License.
|
|
23
|
+
|
|
24
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
25
|
+
including but not limited to software source code, documentation
|
|
26
|
+
source, and configuration files.
|
|
27
|
+
"Object" form shall mean any form resulting from mechanical
|
|
28
|
+
transformation or translation of a Source form, including but
|
|
29
|
+
not limited to compiled object code, generated documentation,
|
|
30
|
+
and conversions to other media types.
|
|
31
|
+
|
|
32
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
33
|
+
Object form, made available under the License, as indicated by a
|
|
34
|
+
copyright notice that is included in or attached to the work
|
|
35
|
+
(an example is provided in the Appendix below).
|
|
36
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
37
|
+
form, that is based on (or derived from) the Work and for which the
|
|
38
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
39
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
40
|
+
of this License, Derivative Works shall not include works that remain
|
|
41
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
42
|
+
the Work and Derivative Works thereof.
|
|
43
|
+
"Contribution" shall mean any work of authorship, including
|
|
44
|
+
the original version of the Work and any modifications or additions
|
|
45
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
46
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
47
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
48
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
49
|
+
means any form of electronic, verbal, or written communication sent
|
|
50
|
+
to the Licensor or its representatives, including but not limited to
|
|
51
|
+
communication on electronic mailing lists, source code control systems,
|
|
52
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
53
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
54
|
+
excluding communication that is conspicuously marked or otherwise
|
|
55
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
56
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
57
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
58
|
+
subsequently incorporated within the Work.
|
|
59
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
60
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
61
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
62
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
63
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
64
|
+
Work and such Derivative Works in Source or Object form.
|
|
65
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
66
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
67
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
68
|
+
(except as stated in this section) patent license to make, have made,
|
|
69
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
70
|
+
where such license applies only to those patent claims licensable
|
|
71
|
+
by such Contributor that are necessarily infringed by their
|
|
72
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
73
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
74
|
+
institute patent litigation against any entity (including a
|
|
75
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
76
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
77
|
+
or contributory patent infringement, then any patent licenses
|
|
78
|
+
granted to You under this License for that Work shall terminate
|
|
79
|
+
as of the date such litigation is filed.
|
|
80
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
81
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
82
|
+
modifications, and in Source or Object form, provided that You
|
|
83
|
+
meet the following conditions:
|
|
84
|
+
|
|
85
|
+
(a) You must give any other recipients of the Work or
|
|
86
|
+
Derivative Works a copy of this License; and
|
|
87
|
+
|
|
88
|
+
(b) You must cause any modified files to carry prominent notices
|
|
89
|
+
stating that You changed the files; and
|
|
90
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
91
|
+
that You distribute, all copyright, patent, trademark, and
|
|
92
|
+
attribution notices from the Source form of the Work,
|
|
93
|
+
excluding those notices that do not pertain to any part of
|
|
94
|
+
the Derivative Works; and
|
|
95
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
96
|
+
distribution, then any Derivative Works that You distribute must
|
|
97
|
+
include a readable copy of the attribution notices contained
|
|
98
|
+
within such NOTICE file, excluding those notices that do not
|
|
99
|
+
pertain to any part of the Derivative Works, in at least one
|
|
100
|
+
of the following places: within a NOTICE text file distributed
|
|
101
|
+
as part of the Derivative Works; within the Source form or
|
|
102
|
+
documentation, if provided along with the Derivative Works; or,
|
|
103
|
+
within a display generated by the Derivative Works, if and
|
|
104
|
+
wherever such third-party notices normally appear. The contents
|
|
105
|
+
of the NOTICE file are for informational purposes only and
|
|
106
|
+
do not modify the License. You may add Your own attribution
|
|
107
|
+
notices within Derivative Works that You distribute, alongside
|
|
108
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
109
|
+
that such additional attribution notices cannot be construed
|
|
110
|
+
as modifying the License.
|
|
111
|
+
You may add Your own copyright statement to Your modifications and
|
|
112
|
+
may provide additional or different license terms and conditions
|
|
113
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
114
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
115
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
116
|
+
the conditions stated in this License.
|
|
117
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
118
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
119
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
120
|
+
this License, without any additional terms or conditions.
|
|
121
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
122
|
+
the terms of any separate license agreement you may have executed
|
|
123
|
+
with Licensor regarding such Contributions.
|
|
124
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
125
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
126
|
+
except as required for reasonable and customary use in describing the
|
|
127
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
128
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
129
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
130
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
131
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
132
|
+
implied, including, without limitation, any warranties or conditions
|
|
133
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
134
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
135
|
+
appropriateness of using or redistributing the Work and assume any
|
|
136
|
+
risks associated with Your exercise of permissions under this License.
|
|
137
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
138
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
139
|
+
unless required by applicable law (such as deliberate and grossly
|
|
140
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
141
|
+
liable to You for damages, including any direct, indirect, special,
|
|
142
|
+
incidental, or consequential damages of any character arising as a
|
|
143
|
+
result of this License or out of the use or inability to use the
|
|
144
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
145
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
146
|
+
other commercial damages or losses), even if such Contributor
|
|
147
|
+
has been advised of the possibility of such damages.
|
|
148
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
149
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
150
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
151
|
+
or other liability obligations and/or rights consistent with this
|
|
152
|
+
License. However, in accepting such obligations, You may act only
|
|
153
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
154
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
155
|
+
defend, and hold each Contributor harmless for any liability
|
|
156
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
157
|
+
of your accepting any such warranty or additional liability.
|
|
158
|
+
END OF TERMS AND CONDITIONS
|
|
159
|
+
|
|
160
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
161
|
+
To apply the Apache License to your work, attach the following
|
|
162
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
163
|
+
replaced with your own identifying information. (Don't include
|
|
164
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
165
|
+
comment syntax for the file format. We also recommend that a
|
|
166
|
+
file or class name and description of purpose be included on the
|
|
167
|
+
same "printed page" as the copyright notice for easier
|
|
168
|
+
identification within third-party archives.
|
|
169
|
+
Copyright [yyyy] [name of copyright owner]
|
|
170
|
+
|
|
171
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
172
|
+
you may not use this file except in compliance with the License.
|
|
173
|
+
You may obtain a copy of the License at
|
|
174
|
+
|
|
175
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
176
|
+
Unless required by applicable law or agreed to in writing, software
|
|
177
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
178
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
179
|
+
See the License for the specific language governing permissions and
|
|
180
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# REDUE
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Know what still holds. Redo what's due.**
|
|
4
|
+
|
|
5
|
+
You ran the checks. Then the code changed—or a new coding agent started with no
|
|
6
|
+
conversation history. Which results can you still use?
|
|
7
|
+
|
|
8
|
+
REDUE keeps persistent verification state for your codebase so developers and
|
|
9
|
+
coding agents can see which previous checks still apply to the code they have now.
|
|
10
|
+
It records evidence, not proofs of correctness.
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
$ redue status --sync
|
|
14
|
+
✓ typecheck CURRENT / PASS
|
|
15
|
+
? test UNVERIFIED / PASS
|
|
16
|
+
Recording-only: test runtime, transforms and cache inputs need review
|
|
17
|
+
|
|
18
|
+
# Later, after a relevant edit:
|
|
19
|
+
$ redue explain typecheck
|
|
20
|
+
typecheck: STALE / PASS
|
|
21
|
+
src/main.ts changed
|
|
22
|
+
Relevant inputs changed:
|
|
23
|
+
src/main.ts
|
|
24
|
+
Due again when verification is needed: redue run "typecheck"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Agent A verifies and exits. Agent B starts fresh. The receipt is still there;
|
|
28
|
+
REDUE checks whether it still applies. Unrelated documentation edits can preserve
|
|
29
|
+
it; relevant source edits make it stale. [Run the reproducible demo](docs/contributor/demo.md).
|
|
30
|
+
|
|
31
|
+
## Install the alpha
|
|
32
|
+
|
|
33
|
+
REDUE is published on npm as `@redue/cli`. The installed command is `redue`.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm install --global @redue/cli@alpha
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To test a source candidate, run `npm ci` and `npm pack --json`, then install the
|
|
40
|
+
reported tarball filename with `npm install --global ./<filename>`.
|
|
41
|
+
|
|
42
|
+
Use a Node installation you own; REDUE does not need administrator privileges.
|
|
43
|
+
If a global prefix is not writable, use a user-owned `--prefix` or run the
|
|
44
|
+
installed CLI with Node. [Installation and removal](docs/user/getting-started.md)
|
|
45
|
+
includes PowerShell and isolated-prefix instructions.
|
|
46
|
+
|
|
47
|
+
Inside an existing, trusted Git project with dependencies already installed:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
cd my-project
|
|
51
|
+
redue init
|
|
52
|
+
redue start
|
|
53
|
+
redue run typecheck # use a check name printed by init
|
|
54
|
+
redue status
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`init` discovers existing scripts, explains which can qualify and which are
|
|
58
|
+
recording-only, and writes a small `redue.config.json`. It never runs your checks
|
|
59
|
+
or changes your package manager, source, scripts, or dependencies. Commit the
|
|
60
|
+
reviewed project config; local evidence stays outside the checkout.
|
|
61
|
+
|
|
62
|
+
Start with ordinary `status`. When it cannot establish caller context, use
|
|
63
|
+
`redue status --sync` if that is worthwhile—or just rerun an inexpensive check.
|
|
64
|
+
**Synchronization can cost more than rerunning a cheap check, particularly on
|
|
65
|
+
Windows.** REDUE does not choose or execute that tradeoff for you.
|
|
66
|
+
|
|
67
|
+
## What the states mean
|
|
68
|
+
|
|
69
|
+
| State | Meaning | Normal next step |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| CURRENT | The recorded result applies to the declared inputs. | Reuse a passing result; do not rerun merely for freshness. |
|
|
72
|
+
| STALE | Relevant inputs changed since the recorded result. | Rerun when verification is needed. |
|
|
73
|
+
| UNVERIFIED | Applicability is unknown: no receipt, incomplete coverage, pending observation, or missing context. | Read the reason; synchronize if worthwhile, or run the check. |
|
|
74
|
+
| FAILED | The invocation failed. Its applicability is tracked separately. | Keep the failure visible; it is not green evidence. |
|
|
75
|
+
|
|
76
|
+
A historical PASS remains PASS when stale or unverified. A historical failure
|
|
77
|
+
never becomes a successful check. CURRENT does not mean every product behavior
|
|
78
|
+
has been verified.
|
|
79
|
+
|
|
80
|
+
## Supported alpha path
|
|
81
|
+
|
|
82
|
+
- macOS, Linux, and Windows on supported local filesystems; Node 22+.
|
|
83
|
+
- Linux also requires Python 3 for observation. No WSL or Git Bash needed on Windows.
|
|
84
|
+
- npm, pinned Yarn `node-modules`, and pinned pnpm 12 isolated/hoisted layouts.
|
|
85
|
+
- Automatic qualification for supported TypeScript invocations; workspace
|
|
86
|
+
boundaries follow the files actually consumed, including built declarations.
|
|
87
|
+
- Existing test/lint/build and arbitrary commands can record results while
|
|
88
|
+
their applicability remains unqualified.
|
|
89
|
+
|
|
90
|
+
The [supported-project boundary](docs/user/supported-projects.md) is deliberately
|
|
91
|
+
narrow. A script named `test` is not automatically a complete test contract.
|
|
92
|
+
|
|
93
|
+
## Alpha limitations
|
|
94
|
+
|
|
95
|
+
- REDUE records evidence; it does not prove correctness.
|
|
96
|
+
- Direct commands outside `redue run` do not create receipts.
|
|
97
|
+
- Some tests, lints, and builds remain UNVERIFIED/PASS because their input contract is incomplete.
|
|
98
|
+
- Synchronized applicability has nontrivial cost and can lose to an inexpensive rerun.
|
|
99
|
+
- Unsupported/exotic install layouts and filesystems remain conservative; they do not become green through guesses.
|
|
100
|
+
- No cloud/team synchronization, IDE extension, or automatic background check execution.
|
|
101
|
+
- Alpha configuration and APIs may evolve. Neither cached nor synchronized status is an atomic snapshot against concurrent edits.
|
|
102
|
+
|
|
103
|
+
## Humans, shells, and agents
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
redue explain typecheck # synchronized explanation; may run read-only probes
|
|
107
|
+
redue status --json # conservative cached data
|
|
108
|
+
redue status --sync --json # caller-aware decision
|
|
109
|
+
redue status --short # small cached indicator; never synchronizes
|
|
110
|
+
redue stop # retains historical receipts
|
|
111
|
+
redue remove-state # removes only this config's owned local state
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Agents should use [the documented JSON interface](docs/user/json.md), not parse
|
|
115
|
+
terminal prose. [The canonical agent loop](docs/user/agents.md) keeps the
|
|
116
|
+
sync-versus-rerun choice explicit. [Shell usage](docs/user/shell.md) does not put
|
|
117
|
+
synchronized work in a prompt.
|
|
118
|
+
|
|
119
|
+
[User docs](docs/README.md) · [Contributing](CONTRIBUTING.md) ·
|
|
120
|
+
[Architecture](docs/contributor/architecture.md) · [Acceptance evidence](docs/acceptance/README.md)
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
REDUE is licensed under [Apache-2.0](LICENSE). Dependencies retain their own licenses.
|
package/bin/redue.mjs
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {createHash} from 'node:crypto';
|
|
6
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
7
|
+
import {createRequire} from 'node:module';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import {discoverNodeProject} from '../src/node-onboarding.mjs';
|
|
10
|
+
import {processAlive} from '../src/process-liveness.mjs';
|
|
11
|
+
import {samePath,withinPath,realObservedPath} from '../src/path-identity.mjs';
|
|
12
|
+
import {stateIdentity,userStateBase} from '../src/platform-state.mjs';
|
|
13
|
+
import {findExecutable} from '../src/executable-lookup.mjs';
|
|
14
|
+
import {readCachedStatus} from '../src/cached-state.mjs';
|
|
15
|
+
import {assertOwnedStatePlacement} from '../src/owned-state.mjs';
|
|
16
|
+
import {renderStatus,renderExplain} from '../src/presentation.mjs';
|
|
17
|
+
|
|
18
|
+
const productRoot=path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
19
|
+
const engine=path.join(productRoot,'src','cli.mjs');
|
|
20
|
+
const version=JSON.parse(fs.readFileSync(path.join(productRoot,'package.json'))).version;
|
|
21
|
+
const help=`REDUE ${version}
|
|
22
|
+
Usage: redue [--config FILE] [--state-dir DIR] COMMAND [OPTIONS]
|
|
23
|
+
|
|
24
|
+
Commands:
|
|
25
|
+
init [--dry-run] [--workspace NAME] [--check KIND]
|
|
26
|
+
Discover existing scripts; optionally select one workspace/check
|
|
27
|
+
start Start the local observer
|
|
28
|
+
stop Stop this observer
|
|
29
|
+
status [--json|--short] Read conservative cached status
|
|
30
|
+
status --sync Reconcile inputs and caller context before answering
|
|
31
|
+
explain [CHECK] [--json] Explain applicability (synchronized; may cost more than a rerun)
|
|
32
|
+
detail [CHECK] [--json] Alias for explain
|
|
33
|
+
run CHECK Execute one configured check and record its outcome
|
|
34
|
+
remove-state Stop and remove only this configuration's owned local state
|
|
35
|
+
|
|
36
|
+
No checks run in the background. Direct commands outside redue create no receipts.`;
|
|
37
|
+
|
|
38
|
+
function error(message){console.error(`redue: ${message}`);process.exit(2);}
|
|
39
|
+
const args=process.argv.slice(2);
|
|
40
|
+
if(args.length===1&&args[0]==='--version'){console.log(version);process.exit(0);}
|
|
41
|
+
if(args.includes('--help')||args.includes('-h')||!args.length){console.log(help);process.exit(0);}
|
|
42
|
+
const preferredConfig=path.resolve('redue.config.json');
|
|
43
|
+
const legacyConfig=path.resolve('vstate.config.json');
|
|
44
|
+
let configFile=fs.existsSync(preferredConfig)||!fs.existsSync(legacyConfig)?
|
|
45
|
+
preferredConfig:legacyConfig,stateOverride=null;
|
|
46
|
+
for(let i=0;i<args.length;){
|
|
47
|
+
if(args[i]==='--config'||args[i]==='--state-dir'){
|
|
48
|
+
const flag=args[i],value=args[i+1];if(!value)error(`${flag} requires a path`);
|
|
49
|
+
if(flag==='--config')configFile=path.resolve(value);else stateOverride=path.resolve(value);
|
|
50
|
+
args.splice(i,2);
|
|
51
|
+
}else i++;
|
|
52
|
+
}
|
|
53
|
+
const command=args.shift();
|
|
54
|
+
if(!['init','start','stop','status','detail','explain','run','remove-state'].includes(command))
|
|
55
|
+
error(`unknown command ${command||'<none>'}; use --help`);
|
|
56
|
+
const json=args.includes('--json');
|
|
57
|
+
const sync=args.includes('--sync');
|
|
58
|
+
const dryRun=args.includes('--dry-run');
|
|
59
|
+
const short=args.includes('--short');
|
|
60
|
+
let workspaceSelection=null,checkSelection=null;
|
|
61
|
+
if(command==='init')for(let i=0;i<args.length;){
|
|
62
|
+
if(args[i]==='--workspace'||args[i]==='--check'){
|
|
63
|
+
const flag=args[i],value=args[i+1];if(!value||value.startsWith('--'))error(`${flag} requires a name`);
|
|
64
|
+
if(flag==='--workspace')workspaceSelection=value;else checkSelection=value;
|
|
65
|
+
args.splice(i,2);
|
|
66
|
+
}else i++;
|
|
67
|
+
}
|
|
68
|
+
const check=['run','detail','explain'].includes(command)&&args[0]&&!args[0].startsWith('--')?args.shift():null;
|
|
69
|
+
if(command==='run'&&!check)error('run requires a check name');
|
|
70
|
+
if(args.some(value=>!['--json','--sync','--dry-run','--short'].includes(value)))error('unknown option; use --help');
|
|
71
|
+
if(sync&&!['status','detail','explain'].includes(command))error('--sync is for status or detail');
|
|
72
|
+
if(short&&(command!=='status'||json||sync))error('--short is a cached status option; do not combine it with --sync or --json');
|
|
73
|
+
if(dryRun&&command!=='init')error('--dry-run is for init');
|
|
74
|
+
|
|
75
|
+
if(command==='init'){
|
|
76
|
+
let discovery;try{discovery=discoverNodeProject(process.cwd());}
|
|
77
|
+
catch(e){error(e.message);}
|
|
78
|
+
if(workspaceSelection||checkSelection){
|
|
79
|
+
const chosen=discovery.checks.filter(row=>
|
|
80
|
+
(!workspaceSelection||row.config.workspace===workspaceSelection||
|
|
81
|
+
row.config.command?.[2]===workspaceSelection)&&
|
|
82
|
+
(!checkSelection||row.config.kind===checkSelection));
|
|
83
|
+
if(!chosen.length)error('no discovered check matches the selected workspace and kind');
|
|
84
|
+
discovery.checks=chosen;discovery.config.checks=chosen.map(row=>row.config);
|
|
85
|
+
}
|
|
86
|
+
const configured=fs.existsSync(configFile),unsupported=Boolean(discovery.observationIssue||
|
|
87
|
+
discovery.manager.issue&&!['npm','yarn','pnpm'].includes(discovery.manager.name)||
|
|
88
|
+
discovery.manager.name==='yarn'&&!discovery.manager.version);
|
|
89
|
+
const willWrite=!dryRun&&!configured&&!unsupported&&discovery.checks.length>0;
|
|
90
|
+
const summary={schema:1,repository:discovery.root,node:discovery.node,
|
|
91
|
+
package_manager:discovery.manager.name,version:discovery.manager.version,
|
|
92
|
+
installation_layout:discovery.manager.layout,
|
|
93
|
+
issue:discovery.observationIssue||discovery.manager.issue,workspaces:discovery.workspaces,
|
|
94
|
+
ambiguous:discovery.ambiguous,
|
|
95
|
+
checks:discovery.checks.map(({config:check,level,reason})=>({name:check.name,
|
|
96
|
+
script:check.script||null,command:check.command||null,
|
|
97
|
+
workspace:check.workspace||null,level,reason})),config:configFile,
|
|
98
|
+
written:willWrite,existing:configured};
|
|
99
|
+
if(!json) {
|
|
100
|
+
console.log(`Node ${summary.node}; ${summary.package_manager||'unknown package manager'}`+
|
|
101
|
+
`${summary.version?' '+summary.version:''}; ${summary.installation_layout} installation.`);
|
|
102
|
+
if(summary.issue)console.log(`Boundary: ${summary.issue}`);
|
|
103
|
+
for(const row of summary.checks){
|
|
104
|
+
console.log(` ${row.name} (${row.script||row.command?.join(' ')}) — `+
|
|
105
|
+
`${{ready:'ready to qualify',recording:'recording-only',unsupported:'unsupported'}[row.level]||row.level}: ${row.reason}`);
|
|
106
|
+
if(row.script&&row.command)console.log(` Recorded invocation: ${row.command.map(value=>
|
|
107
|
+
value==='@node'?'node':value.startsWith('@typescript-bin:')?
|
|
108
|
+
`[installed TypeScript in ${value.slice('@typescript-bin:'.length)}]`:value).join(' ')}`);
|
|
109
|
+
}
|
|
110
|
+
for(const row of summary.ambiguous)
|
|
111
|
+
console.log(` ${row.kind}: ambiguous scripts (${row.scripts.join(', ')}); choose one explicitly`);
|
|
112
|
+
if(!summary.checks.length)console.log('No useful existing verification scripts found.');
|
|
113
|
+
console.log(configured?`Existing ${configFile} left unchanged.`:
|
|
114
|
+
dryRun?`Preview only; ${configFile} was not written.`:
|
|
115
|
+
willWrite?`Writing ${configFile}; inspect it before running checks.`:'No configuration will be written.');
|
|
116
|
+
}
|
|
117
|
+
if(willWrite){
|
|
118
|
+
if(!samePath(realObservedPath(path.dirname(configFile)),discovery.root))
|
|
119
|
+
error('init writes only at the repository root; use --config there or --dry-run');
|
|
120
|
+
fs.writeFileSync(configFile,JSON.stringify(discovery.config,null,2)+'\n',{flag:'wx'});
|
|
121
|
+
if(!json){console.log(`Created ${configFile}. No checks were executed.`);
|
|
122
|
+
console.log('Ready to qualify means the supported contract will be validated; it is not verification evidence.');
|
|
123
|
+
console.log(`Next: review the config, then redue start and redue run ${JSON.stringify(discovery.checks[0].config.name)}.`);
|
|
124
|
+
console.log('Use redue status first. --sync can establish applicability, but may cost more than rerunning a cheap check.');}
|
|
125
|
+
} else if(unsupported&&!json)console.log(`No config written: ${summary.issue||'unsupported discovery boundary'}.`);
|
|
126
|
+
if(json)console.log(JSON.stringify({...summary,proposed_config:discovery.config}));
|
|
127
|
+
process.exit(0);
|
|
128
|
+
}
|
|
129
|
+
function printLifecycle(output,action,machine){
|
|
130
|
+
if(machine){process.stdout.write(output);return;}
|
|
131
|
+
let value;try{value=JSON.parse(output);}catch{process.stdout.write(output);return;}
|
|
132
|
+
if(action==='start'){
|
|
133
|
+
console.log(value.ready?'Observer ready.':'Observer started; checking inputs. Applicability stays UNVERIFIED until ready.');
|
|
134
|
+
console.log('Use redue status. Stop with redue stop.');
|
|
135
|
+
}else if(action==='remove-state')console.log(`Removed only REDUE-owned state: ${value.removed}`);
|
|
136
|
+
else console.log(value.ok?'Observer stopped. Historical evidence is retained.':
|
|
137
|
+
`Observer unavailable: ${value.reason||'not running'}. Previous evidence is not CURRENT.`);
|
|
138
|
+
}
|
|
139
|
+
// Owned-state maintenance must not need the checkout, its package manager,
|
|
140
|
+
// or installed compiler to remain present. No command is run from this path.
|
|
141
|
+
if(stateOverride&&['stop','remove-state'].includes(command)){
|
|
142
|
+
const runtime=path.join(stateOverride,'project-runtime-v1.json');
|
|
143
|
+
if(!fs.existsSync(runtime)){console.log('No REDUE state exists at this path.');process.exit(0);}
|
|
144
|
+
const result=spawnSync(process.execPath,[engine,runtime,command==='stop'?'stop':'uninstall'],
|
|
145
|
+
{cwd:os.tmpdir(),stdio:['inherit','pipe','inherit'],encoding:'utf8',env:process.env});
|
|
146
|
+
if(result.error)error(result.error.message);
|
|
147
|
+
if(result.stdout)printLifecycle(result.stdout,command,json);
|
|
148
|
+
process.exit(result.status??2);
|
|
149
|
+
}
|
|
150
|
+
let publicConfig;
|
|
151
|
+
try{publicConfig=JSON.parse(fs.readFileSync(configFile,'utf8'));}
|
|
152
|
+
catch(e){error(e.code==='ENOENT'?`no configuration at ${configFile}; run redue init from the project root, or use --config FILE`:`cannot read ${configFile}: ${e.message}`);}
|
|
153
|
+
if(publicConfig.schema!==1)error('config schema must be 1');
|
|
154
|
+
if(!Array.isArray(publicConfig.checks)||!publicConfig.checks.length)
|
|
155
|
+
error('config needs at least one explicitly defined check');
|
|
156
|
+
for(const key of Object.keys(publicConfig))
|
|
157
|
+
if(!['schema','root','checks','packageManager'].includes(key))error(`unsupported config field ${key}`);
|
|
158
|
+
if(check&&!publicConfig.checks.some(row=>row.name===check))error(`unknown check ${check}; use redue status to list configured checks`);
|
|
159
|
+
const root=realObservedPath(path.resolve(path.dirname(configFile),publicConfig.root||'.'));
|
|
160
|
+
const stateBase=userStateBase(process.platform,process.env,os.homedir());
|
|
161
|
+
const state=stateOverride||path.join(stateBase,'vstate',
|
|
162
|
+
`vstate-${createHash('sha256').update(stateIdentity(root)+'\0'+
|
|
163
|
+
stateIdentity(configFile)).digest('hex').slice(0,16)}`);
|
|
164
|
+
if(!/^(?:vstate|redue)-/.test(path.basename(state)))
|
|
165
|
+
error('--state-dir must name a dedicated redue-* directory outside the checkout (legacy vstate-* is also supported)');
|
|
166
|
+
const runtimeFile=path.join(state,'project-runtime-v1.json');
|
|
167
|
+
function which(name){
|
|
168
|
+
const found=findExecutable(name);
|
|
169
|
+
if(found)return found;
|
|
170
|
+
error(`cannot resolve executable ${name} on PATH`);
|
|
171
|
+
}
|
|
172
|
+
function token(value){
|
|
173
|
+
if(value==='@node')return process.execPath;
|
|
174
|
+
if(value==='@project')return root;
|
|
175
|
+
if(value.startsWith('@typescript-bin:')){
|
|
176
|
+
const dir=value.slice('@typescript-bin:'.length);
|
|
177
|
+
if(!dir||path.isAbsolute(dir)||dir.split('/').includes('..'))
|
|
178
|
+
error('TypeScript executable workspace path is unsafe');
|
|
179
|
+
const manifest=path.join(root,dir,'package.json');
|
|
180
|
+
let resolved;try{resolved=createRequire(manifest).resolve('typescript/package.json');}
|
|
181
|
+
catch{error('installed TypeScript compiler cannot be resolved');}
|
|
182
|
+
const compiler=path.join(path.dirname(realObservedPath(resolved)),'bin','tsc');
|
|
183
|
+
if(!withinPath(compiler,root)||!fs.existsSync(compiler))
|
|
184
|
+
error('TypeScript executable is outside the observed project');
|
|
185
|
+
return compiler;
|
|
186
|
+
}
|
|
187
|
+
if(value==='@vstate/npm-typecheck-probe')return path.join(productRoot,'src','npm-typecheck-probe.mjs');
|
|
188
|
+
if(value==='@vstate/typescript-contract-probe')return path.join(productRoot,'src','typescript-contract-probe.mjs');
|
|
189
|
+
if(value==='@vstate/yarn-workspace-typecheck-probe')return path.join(productRoot,'src','yarn-workspace-typecheck-probe.mjs');
|
|
190
|
+
if(value==='@vstate/pnpm-typecheck-probe')return path.join(productRoot,'src','pnpm-typecheck-probe.mjs');
|
|
191
|
+
if(value==='@vstate/toolchain-probe')return path.join(productRoot,'src','toolchain-probe.mjs');
|
|
192
|
+
if(value.startsWith('@which:'))return which(value.slice(7));
|
|
193
|
+
return value;
|
|
194
|
+
}
|
|
195
|
+
function argv(values,label){
|
|
196
|
+
if(!Array.isArray(values)||!values.length||values.some(v=>typeof v!=='string'||!v))
|
|
197
|
+
error(`${label} must be nonempty exact argv`);
|
|
198
|
+
return values.map(token);
|
|
199
|
+
}
|
|
200
|
+
const categories=['source','generated','installedDependencies','environment','toolchain','runtime',
|
|
201
|
+
'probeContinuity'];
|
|
202
|
+
const checks=publicConfig.checks.map(check=>{
|
|
203
|
+
const allowed=['name','command','cwd','inputs','generatedInputs','installedInputs',
|
|
204
|
+
'allowedExternalRoots','probes','environment','coverage','coverageReview','coverageReasons',
|
|
205
|
+
'script','kind','qualification','workspace'];
|
|
206
|
+
for(const key of Object.keys(check))if(!allowed.includes(key))
|
|
207
|
+
error(`unsupported check field ${check.name}.${key}`);
|
|
208
|
+
for(const category of categories)if(check.coverage?.[category]&&
|
|
209
|
+
typeof check.coverageReview?.[category]!=='string')
|
|
210
|
+
error(`${check.name}: reviewed coverage ${category} needs a rationale`);
|
|
211
|
+
const pnpmTypecheck=check.qualification==='pnpm-tsc-v1';
|
|
212
|
+
if(check.script&&check.command&&!pnpmTypecheck)
|
|
213
|
+
error(`${check.name}: choose script or command, not both`);
|
|
214
|
+
const manager=publicConfig.packageManager;
|
|
215
|
+
if(check.script&&!['npm','yarn','pnpm'].includes(manager))
|
|
216
|
+
error(`${check.name}: script checks need supported npm, Yarn or pnpm packageManager`);
|
|
217
|
+
const scriptCommand=check.script&&!check.command?
|
|
218
|
+
[`@which:${manager}`,'run',check.script]:null;
|
|
219
|
+
const npmAutomatic=check.qualification==='typescript-noemit-v1';
|
|
220
|
+
const yarnWorkspace=check.qualification==='yarn-workspace-tsc-v1';
|
|
221
|
+
if(check.qualification&&!npmAutomatic&&!yarnWorkspace&&!pnpmTypecheck)
|
|
222
|
+
error(`${check.name}: unknown qualification contract`);
|
|
223
|
+
if(npmAutomatic&&(manager!=='npm'||check.cwd&&check.cwd!=='.'))
|
|
224
|
+
error(`${check.name}: automatic TypeScript qualification currently needs root npm script`);
|
|
225
|
+
if(yarnWorkspace&&(manager!=='yarn'||!check.workspace||check.cwd&&check.cwd!=='.'||
|
|
226
|
+
check.command?.length!==5||check.command[0]!=='@which:yarn'||
|
|
227
|
+
check.command[1]!=='workspace'||check.command[2]!==check.workspace||
|
|
228
|
+
check.command[3]!=='run'))
|
|
229
|
+
error(`${check.name}: Yarn workspace qualification needs its discovered workspace command`);
|
|
230
|
+
if(pnpmTypecheck&&(manager!=='pnpm'||!check.script||!check.command||
|
|
231
|
+
check.command[0]!=='@node'||
|
|
232
|
+
check.command[1]!==`@typescript-bin:${check.cwd||'.'}`||
|
|
233
|
+
check.workspace&&check.cwd==='.'||
|
|
234
|
+
!check.command.slice(2).every(value=>typeof value==='string'&&value)))
|
|
235
|
+
error(`${check.name}: pnpm qualification needs its discovered standalone TypeScript command`);
|
|
236
|
+
const reason=check.kind==='test'?'test runtime, transforms and cache inputs need review':
|
|
237
|
+
check.kind==='lint'?'lint plugins, config and resolver inputs need review':
|
|
238
|
+
check.kind==='build'?'build environment and generated inputs need review':
|
|
239
|
+
'check inputs need review';
|
|
240
|
+
const autoProbes=npmAutomatic?[['@node','@vstate/typescript-contract-probe',
|
|
241
|
+
'@project',check.script,'@which:npm']]:yarnWorkspace?
|
|
242
|
+
[['@node','@vstate/yarn-workspace-typecheck-probe','@project',
|
|
243
|
+
check.workspace,check.command[4],'@which:yarn']]:pnpmTypecheck?
|
|
244
|
+
[['@node','@vstate/pnpm-typecheck-probe','@project',
|
|
245
|
+
check.workspace||'.',check.script]]:[];
|
|
246
|
+
const windowsContext=process.platform==='win32'?
|
|
247
|
+
['ComSpec','COMSPEC','PATHEXT','USERPROFILE']:[];
|
|
248
|
+
const autoEnvironment=npmAutomatic?{variables:['NODE_OPTIONS','NODE_PATH','CI','HOME',
|
|
249
|
+
'NODE_ENV','BASH_ENV','ENV',...windowsContext],prefixes:['npm_config_','DYLD_','TSGO_'],
|
|
250
|
+
pathExecutables:['node','npm'],executableIdentity:true}:yarnWorkspace?
|
|
251
|
+
{variables:['NODE_OPTIONS','NODE_PATH','CI','HOME','NODE_ENV','BASH_ENV','ENV',...windowsContext],
|
|
252
|
+
prefixes:['YARN_','COREPACK_','npm_config_','DYLD_','TSGO_'],
|
|
253
|
+
pathExecutables:['node','yarn'],executableIdentity:true}:pnpmTypecheck?
|
|
254
|
+
{variables:['NODE_OPTIONS','NODE_PATH','CI','HOME','NODE_ENV','BASH_ENV','ENV',...windowsContext],
|
|
255
|
+
prefixes:['PNPM_','COREPACK_','npm_config_','DYLD_','TSGO_'],
|
|
256
|
+
pathExecutables:['node'],executableIdentity:true}:{};
|
|
257
|
+
return {name:check.name,command:argv(scriptCommand||check.command,`${check.name}.command`),
|
|
258
|
+
cwd:check.cwd,inputs:check.inputs||[],generatedInputs:check.generatedInputs||[],
|
|
259
|
+
installedInputs:check.installedInputs||(
|
|
260
|
+
npmAutomatic?['node_modules/**']:[]),
|
|
261
|
+
allowedExternalRoots:check.allowedExternalRoots||[],
|
|
262
|
+
probes:[...(check.probes||[]),...autoProbes]
|
|
263
|
+
.map((p,i)=>argv(p,`${check.name}.probes[${i}]`)),
|
|
264
|
+
environment:check.environment||autoEnvironment,coverage:check.coverage||{},
|
|
265
|
+
coverageReview:check.coverageReview||{},
|
|
266
|
+
coverageReasons:check.coverageReasons||Object.fromEntries(
|
|
267
|
+
categories.map(category=>[category,reason])),
|
|
268
|
+
qualification:check.qualification||null,script:check.script||null,
|
|
269
|
+
workspace:check.workspace||null,kind:check.kind||null};
|
|
270
|
+
});
|
|
271
|
+
const runtime={schema:1,provider:'declared-project@1',root,state,checks};
|
|
272
|
+
try{assertOwnedStatePlacement(runtime);}catch(e){error(e.message);}
|
|
273
|
+
const serialized=JSON.stringify(runtime,null,2)+'\n';
|
|
274
|
+
const maintenance=command==='stop'||command==='remove-state';
|
|
275
|
+
if(maintenance&&!fs.existsSync(runtimeFile)){
|
|
276
|
+
console.log(`No REDUE state exists for ${configFile}.`);
|
|
277
|
+
process.exit(0);
|
|
278
|
+
}
|
|
279
|
+
if(!maintenance)fs.mkdirSync(state,{recursive:true,mode:0o700});
|
|
280
|
+
if(!maintenance&&fs.existsSync(runtimeFile)){
|
|
281
|
+
const previous=fs.readFileSync(runtimeFile,'utf8');
|
|
282
|
+
if(previous!==serialized){
|
|
283
|
+
const pidFile=path.join(state,'observer.lock','pid');
|
|
284
|
+
if(fs.existsSync(pidFile)){
|
|
285
|
+
const pid=Number(fs.readFileSync(pidFile));
|
|
286
|
+
if(processAlive(pid))error('config changed while observer is running; stop it before restarting with the new plan');
|
|
287
|
+
}
|
|
288
|
+
fs.writeFileSync(runtimeFile,serialized,{mode:0o600});
|
|
289
|
+
}
|
|
290
|
+
}else if(!maintenance)fs.writeFileSync(runtimeFile,serialized,{flag:'wx',mode:0o600});
|
|
291
|
+
|
|
292
|
+
if(command==='status'&&!sync){
|
|
293
|
+
const value=readCachedStatus(state,publicConfig.checks);
|
|
294
|
+
console.log(json?JSON.stringify(value):renderStatus(value,{short}));
|
|
295
|
+
process.exit(0);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const details=command==='detail'||command==='explain';
|
|
299
|
+
const internal=command==='remove-state'?'uninstall':
|
|
300
|
+
details?'sync':command==='status'&&sync?'sync':command;
|
|
301
|
+
if(command==='run'){
|
|
302
|
+
const child=spawn(process.execPath,[engine,runtimeFile,internal,check,...(!json?['--human']:[])],
|
|
303
|
+
{stdio:['inherit','inherit','inherit','ipc'],env:process.env});
|
|
304
|
+
const forward=signal=>{if(child.exitCode!==null)return;
|
|
305
|
+
if(process.platform==='win32'&&child.connected)child.send({action:'cancel',signal});
|
|
306
|
+
else child.kill(signal);};
|
|
307
|
+
const interrupt=()=>forward('SIGINT'),terminate=()=>forward('SIGTERM');
|
|
308
|
+
process.on('SIGINT',interrupt);process.on('SIGTERM',terminate);
|
|
309
|
+
const outcome=await new Promise(resolve=>{
|
|
310
|
+
child.once('error',error=>resolve({error}));
|
|
311
|
+
child.once('close',(status,signal)=>resolve({status,signal}));
|
|
312
|
+
});
|
|
313
|
+
process.off('SIGINT',interrupt);process.off('SIGTERM',terminate);
|
|
314
|
+
if(outcome.error)error(outcome.error.message);
|
|
315
|
+
process.exit(outcome.status??(outcome.signal?128+os.constants.signals[outcome.signal]:1));
|
|
316
|
+
}
|
|
317
|
+
const result=spawnSync(process.execPath,[engine,runtimeFile,internal,...(check?[check]:[])],
|
|
318
|
+
{stdio:['inherit','pipe','inherit'],
|
|
319
|
+
encoding:'utf8',env:process.env});
|
|
320
|
+
if(result.error)error(result.error.message);
|
|
321
|
+
if(result.stdout){
|
|
322
|
+
if(['status','detail','explain'].includes(command)){
|
|
323
|
+
let value;try{value=JSON.parse(result.stdout);}catch{error('status response could not be read; applicability is unknown');}
|
|
324
|
+
if(details&&check)value={...value,checks:value.checks.filter(row=>row.name===check)};
|
|
325
|
+
if(json)console.log(JSON.stringify(value));
|
|
326
|
+
else console.log(details?renderExplain(value,check):renderStatus(value,{short}));
|
|
327
|
+
}else printLifecycle(result.stdout,command,json);
|
|
328
|
+
}
|
|
329
|
+
process.exit(result.status??1);
|