@redue/cli 0.0.0-stage → 0.1.0-alpha.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 +34 -0
- package/LICENSE +180 -0
- package/README.md +126 -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/receipt-selection-notice.md +60 -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 +42 -0
- package/src/cli.mjs +401 -0
- package/src/control-endpoint.mjs +11 -0
- package/src/daemon.mjs +1004 -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 +73 -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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Read-only applicability probe. Its output is one digest or a fixed reason;
|
|
3
|
+
// source, configuration, environment values, and command output are not logged.
|
|
4
|
+
import {compilerFiles} from './typescript-list.mjs';
|
|
5
|
+
import {contextOnly,probeResult} from './probe-result.mjs';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import {createHash} from 'node:crypto';
|
|
10
|
+
import {spawnSync} from 'node:child_process';
|
|
11
|
+
import {yarnWorkspaceTypecheckInputs,yarnLocalTsc} from './yarn-workspace-inputs.mjs';
|
|
12
|
+
import {withinPath as within,realObservedPath} from './path-identity.mjs';
|
|
13
|
+
import {windowsLaunch} from './windows-command.mjs';
|
|
14
|
+
|
|
15
|
+
const [rootArg,workspace,script,yarnArg]=process.argv.slice(2);
|
|
16
|
+
const hash=value=>createHash('sha256').update(value).digest('hex');
|
|
17
|
+
const digestFile=file=>hash(fs.readFileSync(file));
|
|
18
|
+
const fail=code=>{throw Object.assign(Error(code),{code});};
|
|
19
|
+
function yarnDistribution(yarn,version){
|
|
20
|
+
let loader=yarn;
|
|
21
|
+
if(process.platform==='win32'&&/\.cmd$/i.test(yarn)){
|
|
22
|
+
const body=fs.readFileSync(yarn,'utf8').replace(/\r\n/g,'\n').trim();
|
|
23
|
+
const line=body.split('\n')[2]||'';
|
|
24
|
+
const match=/^ "%~dp0\\node\.exe" "%~dp0\\(.+\\corepack\\dist\\yarn\.js)" %\*$/.exec(line);
|
|
25
|
+
if(!match)fail('yarn-distribution-unobservable');
|
|
26
|
+
const relative=match[1];
|
|
27
|
+
const standard=`@SETLOCAL
|
|
28
|
+
@IF EXIST "%~dp0\\node.exe" (
|
|
29
|
+
"%~dp0\\node.exe" "%~dp0\\${relative}" %*
|
|
30
|
+
) ELSE (
|
|
31
|
+
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
|
32
|
+
node "%~dp0\\${relative}" %*
|
|
33
|
+
)`;
|
|
34
|
+
if(body!==standard)fail('yarn-distribution-unobservable');
|
|
35
|
+
loader=realObservedPath(path.resolve(path.dirname(yarn),relative));
|
|
36
|
+
}
|
|
37
|
+
if(!/[/\\]corepack[/\\]dist[/\\]yarn\.js$/.test(loader))
|
|
38
|
+
return {distribution:yarn,loader};
|
|
39
|
+
if(process.env.COREPACK_HOME&&!path.isAbsolute(process.env.COREPACK_HOME))
|
|
40
|
+
fail('yarn-distribution-unobservable');
|
|
41
|
+
const candidates=process.env.COREPACK_HOME?
|
|
42
|
+
[path.join(process.env.COREPACK_HOME,'v1/yarn',version,'yarn.js')]:[
|
|
43
|
+
...(process.platform==='win32'&&path.isAbsolute(process.env.LOCALAPPDATA||'')?
|
|
44
|
+
[path.join(process.env.LOCALAPPDATA,'node/corepack/v1/yarn',version,'yarn.js')]:[]),
|
|
45
|
+
path.join(os.homedir(),'.cache/node/corepack/v1/yarn',version,'yarn.js'),
|
|
46
|
+
path.join(os.homedir(),'Library/Caches/node/corepack/v1/yarn',version,'yarn.js')];
|
|
47
|
+
const found=candidates.find(file=>fs.existsSync(file));
|
|
48
|
+
if(!found)fail('yarn-distribution-unobservable');
|
|
49
|
+
return {distribution:found,loader};
|
|
50
|
+
}
|
|
51
|
+
try{
|
|
52
|
+
if(!rootArg||!workspace||!script||!yarnArg)fail('probe-arguments');
|
|
53
|
+
const root=realObservedPath(rootArg),yarn=realObservedPath(yarnArg);
|
|
54
|
+
const pkg=JSON.parse(fs.readFileSync(path.join(root,'package.json')));
|
|
55
|
+
if(process.env.NODE_OPTIONS||process.env.NODE_PATH||process.env.BASH_ENV||
|
|
56
|
+
process.env.ENV||Object.entries(process.env).some(([key,value])=>{
|
|
57
|
+
if(/^npm_config_prefix$/i.test(key)&&process.platform==='win32'){
|
|
58
|
+
return !path.isAbsolute(value);
|
|
59
|
+
}
|
|
60
|
+
if(key==='COREPACK_HOME')return !path.isAbsolute(value);
|
|
61
|
+
return /^(YARN_|COREPACK_|npm_config_|DYLD_|TSGO_)/i.test(key);
|
|
62
|
+
}))
|
|
63
|
+
fail('workspace-execution-environment-unsupported');
|
|
64
|
+
const launch=windowsLaunch([yarn,'--version']);
|
|
65
|
+
const version=spawnSync(launch.file,launch.args,{cwd:root,env:process.env,
|
|
66
|
+
...launch.options,
|
|
67
|
+
encoding:'utf8',timeout:3000,maxBuffer:1024*1024,stdio:['ignore','pipe','pipe']});
|
|
68
|
+
if(version.error||version.signal||version.status!==0||
|
|
69
|
+
`yarn@${version.stdout.trim()}`!==pkg.packageManager)
|
|
70
|
+
fail('yarn-toolchain-unavailable');
|
|
71
|
+
const distribution=yarnDistribution(yarn,version.stdout.trim());
|
|
72
|
+
const contextFacts={yarnVersion:version.stdout.trim(),yarnShim:digestFile(yarn),
|
|
73
|
+
yarnLoader:digestFile(distribution.loader),
|
|
74
|
+
yarnDistribution:digestFile(distribution.distribution),node:process.version};
|
|
75
|
+
const contextHash=hash(JSON.stringify(contextFacts));
|
|
76
|
+
if(contextOnly(contextHash))process.exit(0);
|
|
77
|
+
const contract=yarnWorkspaceTypecheckInputs(root,workspace,script);
|
|
78
|
+
const cwd=path.join(root,contract.workspace.dir);
|
|
79
|
+
const tsc=yarnLocalTsc(root);
|
|
80
|
+
const captured=process.argv.includes('--redue-checkpoint')?compilerFiles(path.join(root,'node_modules/typescript'),cwd):null;
|
|
81
|
+
const listed=captured?{status:0,stdout:captured.files.join('\n')}:spawnSync(process.execPath,[tsc,'-p','.','--listFilesOnly'],
|
|
82
|
+
{cwd,env:process.env,encoding:'utf8',timeout:4000,maxBuffer:16*1024*1024,
|
|
83
|
+
stdio:['ignore','pipe','pipe']});
|
|
84
|
+
if(listed.error||listed.signal||listed.status!==0)fail('typescript-input-list-unavailable');
|
|
85
|
+
const inputs=listed.stdout.trim().split(/\r?\n/).filter(Boolean)
|
|
86
|
+
.map(file=>realObservedPath(file));
|
|
87
|
+
if(!inputs.length)fail('typescript-input-list-unavailable');
|
|
88
|
+
const selectedRoot=path.join(cwd,'src'),installedRoot=path.join(root,'node_modules');
|
|
89
|
+
const nestedInstalled=[contract.workspace,...contract.closure]
|
|
90
|
+
.map(member=>path.join(root,member.dir,'node_modules'));
|
|
91
|
+
const generated=contract.generated.map(value=>path.join(root,value.slice(0,-3)));
|
|
92
|
+
for(const file of inputs){
|
|
93
|
+
const covered=within(file,installedRoot)||nestedInstalled.some(dir=>within(file,dir))||
|
|
94
|
+
within(file,selectedRoot)||
|
|
95
|
+
generated.some(dir=>within(file,dir));
|
|
96
|
+
if(!covered||!within(file,root))fail('typescript-input-outside-workspace-contract');
|
|
97
|
+
}
|
|
98
|
+
const files=[...new Set(inputs)].sort().map(file=>
|
|
99
|
+
[hash(path.relative(root,file)),digestFile(file)]);
|
|
100
|
+
const configs=contract.configs.map(file=>[hash(file),digestFile(path.join(root,file))]);
|
|
101
|
+
probeResult(hash(JSON.stringify({schema:1,workspace,script,
|
|
102
|
+
files,configs,yarnVersion:version.stdout.trim(),yarnShim:digestFile(yarn),
|
|
103
|
+
yarnLoader:digestFile(distribution.loader),
|
|
104
|
+
yarnDistribution:digestFile(distribution.distribution),
|
|
105
|
+
node:process.version,tsc:digestFile(tsc)})),contextHash,captured?.queries);
|
|
106
|
+
}catch(e){console.error(`VSTATE_REASON:${e.code&&/^[a-z-]+$/.test(e.code)?e.code:
|
|
107
|
+
'workspace-typecheck-contract-unavailable'}`);process.exitCode=2;}
|