@remoteshell/device 0.1.0-beta.4 → 0.1.0-beta.5
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/bin/device.mjs
CHANGED
|
@@ -27,6 +27,7 @@ import {runWindowsUserPlan} from './windows-user-lifecycle.mjs';
|
|
|
27
27
|
import {windowsInstallLayout} from './windows-install-layout.mjs';
|
|
28
28
|
import {installWindowsNative,statusWindowsNative,uninstallWindowsNative} from './windows-native-installer.mjs';
|
|
29
29
|
import {ensureWindowsPrivateStore} from './windows-private-store.mjs';
|
|
30
|
+
import {directPaths,directRegister,directRun} from './direct-npx-runtime.mjs';
|
|
30
31
|
const require=createRequire(import.meta.url);
|
|
31
32
|
const pkg=require('../package.json');
|
|
32
33
|
const packageRoot=resolve(dirname(fileURLToPath(import.meta.url)),'..');
|
|
@@ -159,7 +160,14 @@ function uninstall(p){
|
|
|
159
160
|
return {removed:true,credentialsPreserved:true,systemdUntouched:true};
|
|
160
161
|
}
|
|
161
162
|
try{
|
|
162
|
-
if(action==='
|
|
163
|
+
if(action==='run'&&process.argv.length===3){
|
|
164
|
+
const outcome=await directRun(directPaths(),{packageRoot});
|
|
165
|
+
process.exitCode=outcome.exitCode;
|
|
166
|
+
}
|
|
167
|
+
else if(action==='register'&&process.argv.length===3){
|
|
168
|
+
console.log(JSON.stringify(await directRegister(directPaths())));
|
|
169
|
+
}
|
|
170
|
+
else if(action==='install-preflight'&&process.argv.length===3){
|
|
163
171
|
let wsl=false;
|
|
164
172
|
if(platform()==='linux'){try{wsl=/microsoft|wsl/i.test(readFileSync('/proc/version','utf8'));}catch{}}
|
|
165
173
|
console.log(JSON.stringify(installPreflight({os:platform(),arch:process.arch,nodeVersion:process.version,wsl})));
|
|
@@ -357,7 +365,7 @@ try{
|
|
|
357
365
|
process.exitCode=2;
|
|
358
366
|
}else{console.error('Usage: remoteshell-device version|install|setup https://host/dev/ [foreground|manual|login|boot --confirm-linger]|dev-run-once|dev-mode manual|login|boot [--confirm-linger]|dev-start|dev-stop|dev-status|dev-autostart-enable|dev-autostart-disable|status|dev-service-uninstall|uninstall|dev-check https://host/dev/|dev-enroll https://host/dev/ ENROLLMENT_ID < capability-file|dev-heartbeat|dev-heartbeat-once|dev-agent-run GATEWAY_URL ROOT_ID ABSOLUTE_ROOT');process.exitCode=2;}
|
|
359
367
|
}catch(e){
|
|
360
|
-
const codes=new Set(['DEVICE_INSTALL_DENIED','DEVICE_INSTALL_MANIFEST_DENIED','DEVICE_INSTALL_TRUST_ANCHOR_INVALID','DEVICE_INSTALL_TRUST_ANCHOR_MISSING','DEVICE_INSTALL_SIGNATURE_DENIED','DEVICE_INSTALL_CHECKSUM_DENIED','DEVICE_INSTALL_ARTIFACT_DENIED','DEVICE_INSTALL_VERSION_DENIED','DEVICE_INSTALL_VERSION_REVIEW_REQUIRED','DEVICE_INSTALL_DOWNGRADE_DENIED','DEVICE_INSTALL_DOWNLOAD_DENIED','DEVICE_INSTALL_DOWNLOAD_TIMEOUT','DEVICE_INSTALL_DOWNLOAD_TOO_LARGE','DEVICE_INSTALL_STATE_DENIED','DEVICE_PLATFORM_UNSUPPORTED','DEVICE_INSTALL_OS_UNSUPPORTED','DEVICE_INSTALL_WSL_BETA_EXCLUDED','DEVICE_INSTALL_NODE_UNSUPPORTED','DEVICE_ALREADY_INSTALLED','DEVICE_DEPENDENCY_INVALID','DEVICE_INSTALL_DEPENDENCY_FAILED','DEVICE_INSTALL_PACKAGE_FAILED','DEVICE_LIFECYCLE_DENIED','DEVICE_WINDOWS_LIFECYCLE_DENIED','DEVICE_WINDOWS_WORKER_NOT_READY','DEVICE_WINDOWS_LAYOUT_DENIED','DEVICE_WINDOWS_PRIVATE_STORE_DENIED','DEVICE_ALREADY_REGISTERED','DEVICE_WINDOWS_INSTALL_DENIED','DEVICE_ENROLLMENT_DENIED','DEVICE_DEV_PROBE_DENIED','DEVICE_DEV_AGENT_DENIED','DEVICE_DEV_ENROLLMENT_INPUT_DENIED','DEVICE_UNIT_MUST_BE_REMOVED_FIRST','DEVICE_PAIRING_DENIED','DEVICE_REREGISTRATION_CONFIRM_REQUIRED','DEVICE_REREGISTRATION_CANCELLED','DEVICE_DEV_CREDENTIAL_REVOKED','DEVICE_DEV_SERVICE_DENIED','L2_DEV_CREDENTIAL_DENIED']);
|
|
368
|
+
const codes=new Set(['DEVICE_INSTALL_DENIED','DEVICE_INSTALL_MANIFEST_DENIED','DEVICE_INSTALL_TRUST_ANCHOR_INVALID','DEVICE_INSTALL_TRUST_ANCHOR_MISSING','DEVICE_INSTALL_SIGNATURE_DENIED','DEVICE_INSTALL_CHECKSUM_DENIED','DEVICE_INSTALL_ARTIFACT_DENIED','DEVICE_INSTALL_VERSION_DENIED','DEVICE_INSTALL_VERSION_REVIEW_REQUIRED','DEVICE_INSTALL_DOWNGRADE_DENIED','DEVICE_INSTALL_DOWNLOAD_DENIED','DEVICE_INSTALL_DOWNLOAD_TIMEOUT','DEVICE_INSTALL_DOWNLOAD_TOO_LARGE','DEVICE_INSTALL_STATE_DENIED','DEVICE_PLATFORM_UNSUPPORTED','DEVICE_INSTALL_OS_UNSUPPORTED','DEVICE_INSTALL_WSL_BETA_EXCLUDED','DEVICE_INSTALL_NODE_UNSUPPORTED','DEVICE_ALREADY_INSTALLED','DEVICE_DEPENDENCY_INVALID','DEVICE_INSTALL_DEPENDENCY_FAILED','DEVICE_INSTALL_PACKAGE_FAILED','DEVICE_LIFECYCLE_DENIED','DEVICE_WINDOWS_LIFECYCLE_DENIED','DEVICE_WINDOWS_WORKER_NOT_READY','DEVICE_WINDOWS_LAYOUT_DENIED','DEVICE_WINDOWS_PRIVATE_STORE_DENIED','DEVICE_ALREADY_REGISTERED','DEVICE_WINDOWS_INSTALL_DENIED','DEVICE_ENROLLMENT_DENIED','DEVICE_DEV_PROBE_DENIED','DEVICE_DEV_AGENT_DENIED','DEVICE_DEV_ENROLLMENT_INPUT_DENIED','DEVICE_UNIT_MUST_BE_REMOVED_FIRST','DEVICE_PAIRING_DENIED','DEVICE_REREGISTRATION_CONFIRM_REQUIRED','DEVICE_REREGISTRATION_CANCELLED','DEVICE_DEV_CREDENTIAL_REVOKED','DEVICE_DEV_SERVICE_DENIED','L2_DEV_CREDENTIAL_DENIED','DEVICE_DIRECT_PLATFORM_DENIED','DEVICE_DIRECT_LEGACY_INSTALLED','DEVICE_DIRECT_OWNER_DENIED','DEVICE_DIRECT_LOCK_DENIED','DEVICE_DIRECT_ALREADY_RUNNING','DEVICE_DIRECT_STALE_LOCK','DEVICE_DIRECT_REGISTRATION_REQUIRED','DEVICE_DIRECT_PACKAGE_INVALID','DEVICE_DIRECT_EXISTING_SERVICE','DEVICE_DIRECT_SERVICE_UNVERIFIED']);
|
|
361
369
|
console.error(codes.has(e.message)?e.message:'DEVICE_INSTALL_DENIED');
|
|
362
370
|
process.exitCode=1;
|
|
363
371
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// #327 S1: direct public-npx runtime. Never copies or installs the package.
|
|
2
|
+
import {existsSync,mkdirSync,openSync,closeSync,readFileSync,rmSync,writeFileSync,lstatSync} from 'node:fs';
|
|
3
|
+
import {join,resolve} from 'node:path';
|
|
4
|
+
import {spawnSync} from 'node:child_process';
|
|
5
|
+
import {homedir,platform} from 'node:os';
|
|
6
|
+
import {devOfficialRegistration} from './dev-agent-client.mjs';
|
|
7
|
+
import {devPairDevice} from './dev-pairing-client.mjs';
|
|
8
|
+
import {ensureWindowsPrivateStore} from './windows-private-store.mjs';
|
|
9
|
+
import {windowsInstallLayout} from './windows-install-layout.mjs';
|
|
10
|
+
import {runDevAgentWorker} from './dev-agent-runner.mjs';
|
|
11
|
+
const FAIL=code=>{throw Error(code);};
|
|
12
|
+
export const DIRECT_DEV_URL='https://ailab-remoteshell.duckdns.org/dev/';
|
|
13
|
+
const GATEWAY='https://ailab-remoteshell.duckdns.org/gateway/v1/';
|
|
14
|
+
export function directPaths({home=homedir(),os=platform(),localAppData=process.env.LOCALAPPDATA}={}){
|
|
15
|
+
if(os==='win32'){
|
|
16
|
+
const layout=windowsInstallLayout({home,localAppData});
|
|
17
|
+
return {home,base:layout.base,storageDir:layout.credentials,legacyInstall:layout.install,os};
|
|
18
|
+
}
|
|
19
|
+
if(os!=='linux'||!home.startsWith('/')||resolve(home)!==home)FAIL('DEVICE_DIRECT_PLATFORM_DENIED');
|
|
20
|
+
const base=join(home,'.local/share/remoteshell-device');
|
|
21
|
+
return {home,base,storageDir:join(base,'dev-credentials'),legacyInstall:join(base,'install'),os};
|
|
22
|
+
}
|
|
23
|
+
export function requireNoLegacyInstall(p,{exists=existsSync,run=spawnSync}={}){
|
|
24
|
+
// Do not overlap any preexisting install, service, or user autostart.
|
|
25
|
+
// Presence of an install directory itself is sufficient to fail closed:
|
|
26
|
+
// an incomplete install is not automatically eligible for migration.
|
|
27
|
+
if(exists(p.legacyInstall))FAIL('DEVICE_DIRECT_LEGACY_INSTALLED');
|
|
28
|
+
if(p.os==='linux'){
|
|
29
|
+
if(exists(join(p.home,'.config/systemd/user/remoteshell-device-dev-heartbeat.service'))||
|
|
30
|
+
exists(join(p.home,'.config/systemd/user/remoteshell-device.service')))
|
|
31
|
+
FAIL('DEVICE_DIRECT_EXISTING_SERVICE');
|
|
32
|
+
}else if(p.os==='win32'){
|
|
33
|
+
const result=run('schtasks.exe',['/Query','/TN','RemoteShell Device Agent (User)'],{
|
|
34
|
+
shell:false,windowsHide:true,encoding:'utf8',timeout:10000,maxBuffer:8192,stdio:'pipe'});
|
|
35
|
+
// A missing task has a nonzero exit. All other query failures are
|
|
36
|
+
// deliberately treated as conflicts rather than claiming safe isolation.
|
|
37
|
+
if(result.error||result.signal)FAIL('DEVICE_DIRECT_SERVICE_UNVERIFIED');
|
|
38
|
+
if(result.status===0)FAIL('DEVICE_DIRECT_EXISTING_SERVICE');
|
|
39
|
+
if(result.status!==1)FAIL('DEVICE_DIRECT_SERVICE_UNVERIFIED');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function privateLockDir(p){
|
|
44
|
+
// Place run state alongside the already user-private credential, not in
|
|
45
|
+
// a newly created Windows folder with inherited broad ACL.
|
|
46
|
+
if(p.os==='win32'){
|
|
47
|
+
ensureWindowsPrivateStore(p.storageDir,{home:p.home});
|
|
48
|
+
}else{
|
|
49
|
+
const st=lstatSync(p.storageDir);
|
|
50
|
+
if(!st.isDirectory()||st.isSymbolicLink()||st.uid!==process.getuid?.()||
|
|
51
|
+
(st.mode&0o777)!==0o700)FAIL('DEVICE_DIRECT_OWNER_DENIED');
|
|
52
|
+
}
|
|
53
|
+
return p.storageDir;
|
|
54
|
+
}
|
|
55
|
+
export function acquireDirectLock(p,{pid=process.pid,alive=id=>{try{process.kill(id,0);return true;}catch(e){return e?.code==='EPERM';}}}={}){
|
|
56
|
+
const dir=privateLockDir(p),lock=join(dir,'direct-run.lock');
|
|
57
|
+
let fd;
|
|
58
|
+
for(let attempt=0;attempt<1;attempt++){
|
|
59
|
+
try{fd=openSync(lock,'wx',0o600);writeFileSync(fd,JSON.stringify({pid,created:Date.now()}));closeSync(fd);fd=undefined;
|
|
60
|
+
return ()=>{try{const info=JSON.parse(readFileSync(lock,'utf8'));if(info.pid===pid)rmSync(lock);}catch{}};
|
|
61
|
+
}catch(e){
|
|
62
|
+
if(fd!==undefined)closeSync(fd);
|
|
63
|
+
if(e.code!=='EEXIST')FAIL('DEVICE_DIRECT_LOCK_DENIED');
|
|
64
|
+
// Fail closed even for stale locks: explicit owner cleanup required.
|
|
65
|
+
let old;try{old=JSON.parse(readFileSync(lock,'utf8'));}catch{}
|
|
66
|
+
if(Number.isSafeInteger(old?.pid)&&alive(old.pid))FAIL('DEVICE_DIRECT_ALREADY_RUNNING');
|
|
67
|
+
FAIL('DEVICE_DIRECT_STALE_LOCK');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
FAIL('DEVICE_DIRECT_ALREADY_RUNNING');
|
|
71
|
+
}
|
|
72
|
+
export async function directRegister(p,{pair=devPairDevice,onApprove=url=>console.log(JSON.stringify({next:'approve-device-in-browser',approval_url:url,ownerApprovalRequired:true}))}={}){
|
|
73
|
+
requireNoLegacyInstall(p);
|
|
74
|
+
if(p.os==='win32')ensureWindowsPrivateStore(p.storageDir,{home:p.home});
|
|
75
|
+
const existing=devOfficialRegistration({storageDir:p.storageDir});
|
|
76
|
+
if(existing)return {registered:true,deviceId:existing.deviceId,reused:true,credentialsPreserved:true};
|
|
77
|
+
const result=await pair({base:DIRECT_DEV_URL,storageDir:p.storageDir,onApprove});
|
|
78
|
+
return {...result,reused:false};
|
|
79
|
+
}
|
|
80
|
+
export async function directRun(p,{packageRoot,runWorker=runDevAgentWorker,guard=requireNoLegacyInstall}={}){
|
|
81
|
+
guard(p);
|
|
82
|
+
const registration=devOfficialRegistration({storageDir:p.storageDir});
|
|
83
|
+
if(!registration)FAIL('DEVICE_DIRECT_REGISTRATION_REQUIRED');
|
|
84
|
+
const mainFile=join(packageRoot,'src/device-agent/main.mjs');
|
|
85
|
+
if(!existsSync(mainFile))FAIL('DEVICE_DIRECT_PACKAGE_INVALID');
|
|
86
|
+
const release=acquireDirectLock(p);
|
|
87
|
+
try{
|
|
88
|
+
const child=runWorker({gatewayUrl:GATEWAY,credentialFile:join(p.storageDir,'device.json'),
|
|
89
|
+
rootId:registration.deviceId,rootPath:p.home,home:p.home,mainFile});
|
|
90
|
+
return await new Promise((ok,fail)=>{
|
|
91
|
+
const onInt=()=>child.kill('SIGINT'),onTerm=()=>child.kill('SIGTERM');
|
|
92
|
+
const cleanup=()=>{process.removeListener('SIGINT',onInt);process.removeListener('SIGTERM',onTerm);};
|
|
93
|
+
child.once('error',error=>{cleanup();fail(error);});
|
|
94
|
+
child.once('exit',(code,signal)=>{cleanup();ok({exitCode:signal?1:(code??1),signal:signal||null});});
|
|
95
|
+
process.once('SIGINT',onInt);process.once('SIGTERM',onTerm);
|
|
96
|
+
});
|
|
97
|
+
}finally{release();}
|
|
98
|
+
}
|
|
@@ -30,7 +30,7 @@ function StageComplete([string]$root){
|
|
|
30
30
|
$a=Get-Content -LiteralPath $agentFile -Raw | ConvertFrom-Json
|
|
31
31
|
$d=Get-Content -LiteralPath $dcFile -Raw | ConvertFrom-Json
|
|
32
32
|
$k=Get-Content -LiteralPath $sdkFile -Raw | ConvertFrom-Json
|
|
33
|
-
return ($a.name -eq '@remoteshell/device' -and $a.version -eq
|
|
33
|
+
return ($a.name -eq '@remoteshell/device' -and $a.version -eq $script:agentVersion -and
|
|
34
34
|
$d.version -eq '0.3.1' -and $k.version -eq '1.32.1')
|
|
35
35
|
}catch{return $false}
|
|
36
36
|
}
|
|
@@ -91,6 +91,9 @@ try{
|
|
|
91
91
|
Demand (Test-Path -LiteralPath $manifestFile -PathType Leaf) 'MANIFEST_MISSING'
|
|
92
92
|
$manifest=Get-Content -LiteralPath $manifestFile -Raw | ConvertFrom-Json
|
|
93
93
|
Demand ($manifest.schema -eq 1 -and $manifest.platform -eq 'win32' -and $manifest.arch -eq 'x64' -and $manifest.devOnly -eq $true) 'MANIFEST_INVALID'
|
|
94
|
+
# Backward-compatible with older DEV-only Windows bundles; each new bundle pins its public beta explicitly.
|
|
95
|
+
$script:agentVersion=if($manifest.agentVersion){[string]$manifest.agentVersion}else{'0.1.0'}
|
|
96
|
+
Demand ($script:agentVersion -match '^0\.1\.0(-beta\.[1-9][0-9]*)?$') 'AGENT_VERSION_DENIED'
|
|
94
97
|
$paths=@{
|
|
95
98
|
node=(Join-Path $source 'runtime\node.exe');
|
|
96
99
|
npm=(Join-Path $source 'runtime\node_modules\npm\bin\npm-cli.js');
|
|
@@ -64,7 +64,11 @@ try {
|
|
|
64
64
|
$receipt=Join-Path $install 'receipt.json'
|
|
65
65
|
Demand (Test-Path -LiteralPath $receipt -PathType Leaf) 'RECEIPT_MISSING'
|
|
66
66
|
$r=Get-Content -LiteralPath $receipt -Raw|ConvertFrom-Json
|
|
67
|
-
Demand ($r.schema -eq 1 -and $r.distribution -eq 'synthetic-private' -and $r.version -
|
|
67
|
+
Demand ($r.schema -eq 1 -and $r.distribution -eq 'synthetic-private' -and $r.version -match '^0\.1\.0(-beta\.[1-9][0-9]*)?$') 'FOREIGN_INSTALL_DENIED'
|
|
68
|
+
$pkg=Join-Path $install 'node_modules\@remoteshell\device\package.json'
|
|
69
|
+
Demand (Test-Path -LiteralPath $pkg -PathType Leaf) 'FOREIGN_INSTALL_DENIED'
|
|
70
|
+
$metadata=Get-Content -LiteralPath $pkg -Raw | ConvertFrom-Json
|
|
71
|
+
Demand ($metadata.name -eq '@remoteshell/device' -and $metadata.version -eq $r.version) 'FOREIGN_INSTALL_DENIED'
|
|
68
72
|
}
|
|
69
73
|
if(Test-Path $credentials){
|
|
70
74
|
$files=@(Get-ChildItem -LiteralPath $credentials -Force)
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteshell/device",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@remoteshell/device",
|
|
9
|
-
"version": "0.1.0-beta.
|
|
9
|
+
"version": "0.1.0-beta.5",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
12
12
|
"@wonderwhy-er/desktop-commander": "0.3.1"
|