dsh-ios-webview-app-control 0.0.0-stage → 0.2.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE +21 -0
  3. package/README.md +250 -2
  4. package/THIRD_PARTY_NOTICES.md +42 -0
  5. package/cordis.patch.yml +20 -0
  6. package/docs/installation.md +68 -0
  7. package/docs/new-session-prompt.md +29 -0
  8. package/docs/runtime-environment.md +40 -0
  9. package/docs/sdk-contract.md +79 -0
  10. package/docs/verification.md +64 -0
  11. package/icon.svg +8 -0
  12. package/lib/cli.mjs +51 -0
  13. package/lib/client.js +223 -0
  14. package/lib/core/dom.mjs +26 -0
  15. package/lib/core/leases.mjs +31 -0
  16. package/lib/core/protocol.mjs +101 -0
  17. package/lib/core/python.mjs +47 -0
  18. package/lib/core/service.mjs +122 -0
  19. package/lib/host/environment-service.mjs +175 -0
  20. package/lib/host/subprocess-runner.mjs +34 -0
  21. package/lib/plugin.mjs +303 -0
  22. package/lib/runtime/environment-manager.mjs +544 -0
  23. package/lib/runtime/errors.mjs +33 -0
  24. package/lib/runtime/runner.mjs +75 -0
  25. package/lib/runtime/safe-tar.mjs +179 -0
  26. package/lib/typert-environment.mjs +103 -0
  27. package/locale/en.json +6 -0
  28. package/locale/zh.json +6 -0
  29. package/package.json +72 -4
  30. package/requirements.txt +1 -0
  31. package/resources/notices/PBS-LICENSE.bdb.txt +126 -0
  32. package/resources/notices/PBS-LICENSE.bzip2.txt +37 -0
  33. package/resources/notices/PBS-LICENSE.cpython.txt +771 -0
  34. package/resources/notices/PBS-LICENSE.expat.txt +21 -0
  35. package/resources/notices/PBS-LICENSE.libX11.txt +942 -0
  36. package/resources/notices/PBS-LICENSE.libXau.txt +21 -0
  37. package/resources/notices/PBS-LICENSE.libedit.txt +29 -0
  38. package/resources/notices/PBS-LICENSE.libffi.txt +21 -0
  39. package/resources/notices/PBS-LICENSE.liblzma.txt +13 -0
  40. package/resources/notices/PBS-LICENSE.libuuid.txt +27 -0
  41. package/resources/notices/PBS-LICENSE.libxcb.txt +30 -0
  42. package/resources/notices/PBS-LICENSE.mpdecimal.txt +24 -0
  43. package/resources/notices/PBS-LICENSE.ncurses.txt +29 -0
  44. package/resources/notices/PBS-LICENSE.openssl-3.txt +177 -0
  45. package/resources/notices/PBS-LICENSE.sqlite.txt +23 -0
  46. package/resources/notices/PBS-LICENSE.tcl.txt +40 -0
  47. package/resources/notices/PBS-LICENSE.tix.txt +54 -0
  48. package/resources/notices/PBS-LICENSE.zlib-ng.txt +19 -0
  49. package/resources/notices/PBS-LICENSE.zlib.txt +21 -0
  50. package/resources/notices/PBS-LICENSE.zstd.txt +30 -0
  51. package/resources/notices/PYMOBILEDEVICE3-LICENSE.txt +674 -0
  52. package/resources/notices/PYTHON-LICENSE.txt +277 -0
  53. package/resources/notices/provenance.json +134 -0
  54. package/resources/runtime-lock.json +4252 -0
  55. package/scripts/manage-desktop.ps1 +56 -0
  56. package/scripts/package-validation.mjs +223 -0
  57. package/scripts/verify-package.mjs +13 -0
@@ -0,0 +1,56 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [ValidateSet('install','remove','list')][string]$Action='list',
4
+ [string]$Archive,
5
+ [string]$DesktopExe=(Join-Path $env:LOCALAPPDATA 'Programs\DeepSeek Harness\DeepSeek Harness.exe'),
6
+ [switch]$CheckOnly
7
+ )
8
+ $previousErrorAction=$ErrorActionPreference
9
+ $ErrorActionPreference='Stop'
10
+ $previous=$env:ELECTRON_RUN_AS_NODE
11
+ try{
12
+ if($CheckOnly -and $Action -ne 'install'){throw '-CheckOnly is supported only with -Action install.'}
13
+ $projectRoot=Split-Path -Parent $PSScriptRoot
14
+ $manifestPath=Join-Path $projectRoot 'package.json'
15
+ $manifest=Get-Content -LiteralPath $manifestPath -Raw | ConvertFrom-Json
16
+ $packageName=[string]$manifest.name
17
+ $packageVersion=[string]$manifest.version
18
+ if($packageName -notmatch '^(?:@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*$'){throw 'Invalid package name in local manifest.'}
19
+ if($packageVersion -notmatch '^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$'){throw 'Invalid package version in local manifest.'}
20
+ if($Action -eq 'install'){
21
+ if(-not $Archive){
22
+ $archiveName=($packageName -replace '^@','' -replace '/','-')+'-'+$packageVersion+'.tgz'
23
+ $Archive=Join-Path (Join-Path $projectRoot 'artifacts') $archiveName
24
+ }
25
+ if(-not(Test-Path -LiteralPath $Archive -PathType Leaf)){
26
+ throw ('Package archive not found: '+$Archive+'. Build and pack '+$packageName+'@'+$packageVersion+', or pass -Archive with an explicit current package. Older archives are never selected automatically.')
27
+ }
28
+ $file=Get-Item -LiteralPath $Archive -ErrorAction Stop
29
+ if($file.PSIsContainer -or $file.Extension -ne '.tgz'){throw 'Pass the local packaged tgz, not an unverified registry package.'}
30
+ $verify=Join-Path $PSScriptRoot 'verify-package.mjs'
31
+ if(-not(Test-Path -LiteralPath $verify -PathType Leaf)){throw 'Missing packaged archive validator: scripts/verify-package.mjs.'}
32
+ }
33
+ if(-not(Test-Path -LiteralPath $DesktopExe -PathType Leaf)){throw 'Desktop executable not found; pass the confirmed running installation.'}
34
+ $installDir=Split-Path -Parent $DesktopExe
35
+ $cli=Join-Path $installDir 'resources\app.asar\dsh\node_modules\@deepseek-ai\dsh-desktop-host\lib\cli.js'
36
+ $env:ELECTRON_RUN_AS_NODE='1'
37
+ $arguments=@($cli,'plugin','--profile','desktop')
38
+ if($Action -eq 'install'){
39
+ # The Desktop Node carrier runs a read-only validator before the official CLI.
40
+ # Explicit -Archive changes the location, never the required current identity.
41
+ & $DesktopExe $verify '--check-only' $file.FullName | Out-Host
42
+ $verifyCode=$LASTEXITCODE
43
+ if($null -eq $verifyCode -or $verifyCode -ne 0){throw 'Archive preflight failed; Desktop installation was not attempted.'}
44
+ if($CheckOnly){return}
45
+ $arguments+=@('add',$file.FullName,'--ignore-scripts')
46
+ }elseif($Action -eq 'remove'){$arguments+=@('remove',$packageName)}
47
+ else{$arguments+=@('list','--depth=0')}
48
+ # Only the official Desktop CLI may mutate the protected profile.
49
+ & $DesktopExe @arguments | Out-Host
50
+ $code=$LASTEXITCODE
51
+ if($null -eq $code){throw 'Desktop CLI process exit was not observed; inspect installation before retry.'}
52
+ if($code -ne 0){throw ('Desktop plugin manager exited '+$code)}
53
+ }finally{
54
+ $env:ELECTRON_RUN_AS_NODE=$previous
55
+ $ErrorActionPreference=$previousErrorAction
56
+ }
@@ -0,0 +1,223 @@
1
+ import assert from 'node:assert/strict';
2
+ import {createHash} from 'node:crypto';
3
+ import {readFile,readdir} from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import {fileURLToPath} from 'node:url';
6
+ import {gunzipSync} from 'node:zlib';
7
+
8
+ export const PROJECT_ROOT=fileURLToPath(new URL('../',import.meta.url));
9
+ const REQUIRED_FILES=[
10
+ 'package.json','lib/plugin.mjs','lib/core/service.mjs','cordis.patch.yml',
11
+ 'README.md','docs/verification.md','locale/en.json','locale/zh.json','icon.svg',
12
+ 'scripts/manage-desktop.ps1','scripts/verify-package.mjs','scripts/package-validation.mjs',
13
+ 'lib/client.js','resources/runtime-lock.json','resources/notices/provenance.json','THIRD_PARTY_NOTICES.md',
14
+ ];
15
+ const RUNTIME_FIELDS=[
16
+ 'name','version','type','main','exports','bin','files','engines','dependencies',
17
+ 'optionalDependencies','peerDependencies','peerDependenciesMeta','dsh','icon',
18
+ ];
19
+ const PRIVATE_PARTS=new Set(['node_modules','artifacts','.runtime','evidence','.verify','.git']);
20
+ const BUSINESS_CONTENT=/\/pages\/|ApiServices|ACT-SIGNUP|ACT-DETAIL|POWER-RANK|DEFEATED-|趣运动/;
21
+
22
+ /** Match npm's archive basename, including scoped package names. */
23
+ export function archiveFilename(manifest){
24
+ assert.match(manifest.name||'',/^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/,'Invalid package name');
25
+ assert.match(manifest.version||'',/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/,'Invalid package version');
26
+ return manifest.name.replace(/^@/,'').replaceAll('/','-')+'-'+manifest.version+'.tgz';
27
+ }
28
+
29
+ export async function readProjectManifest(projectRoot=PROJECT_ROOT){
30
+ return JSON.parse(await readFile(path.join(projectRoot,'package.json'),'utf8'));
31
+ }
32
+
33
+ export function defaultArchivePath(manifest,projectRoot=PROJECT_ROOT){
34
+ return path.join(projectRoot,'artifacts',archiveFilename(manifest));
35
+ }
36
+
37
+ function tarString(header,start,end){
38
+ return header.toString('utf8',start,end).replace(/\0.*$/s,'');
39
+ }
40
+
41
+ function tarOctal(header,start,end,label){
42
+ const text=tarString(header,start,end).trim();
43
+ assert.match(text,/^[0-7]+$/,`Invalid tar ${label}`);
44
+ const value=parseInt(text,8);
45
+ assert.ok(Number.isSafeInteger(value)&&value>=0,`Invalid tar ${label}`);
46
+ return value;
47
+ }
48
+
49
+ function safeArchiveName(name,directory=false){
50
+ assert.ok(typeof name==='string'&&!/[\\:\u0000-\u001f\u007f]/.test(name),'Unsafe archive path');
51
+ const normalized=directory?name.replace(/\/$/,''):name;
52
+ assert.ok(normalized==='package'||normalized.startsWith('package/'),'Archive entries must stay under package/');
53
+ assert.ok(normalized.split('/').every(part=>part&&part!=='.'&&part!=='..'),'Unsafe archive path');
54
+ assert.ok(directory||normalized!=='package','Invalid archive file path');
55
+ return normalized;
56
+ }
57
+
58
+ /** Read only ordinary npm tar files; refuse links and unsupported extensions before extraction. */
59
+ export function readPackageArchive(bytes){
60
+ const tar=gunzipSync(bytes,{maxOutputLength:64*1024*1024});
61
+ assert.ok(tar.length>=1024&&tar.length%512===0,'Invalid tar block length');
62
+ const files=new Map();
63
+ const names=new Set();
64
+ let ended=false;
65
+ for(let offset=0;offset+512<=tar.length;){
66
+ const header=tar.subarray(offset,offset+512);
67
+ if(header.every(value=>value===0)){
68
+ assert.ok(offset+1024<=tar.length&&tar.subarray(offset).every(value=>value===0),'Invalid tar end marker');
69
+ ended=true;
70
+ break;
71
+ }
72
+ const checksum=tarOctal(header,148,156,'checksum');
73
+ let actualChecksum=0;
74
+ for(let index=0;index<512;index++)actualChecksum+=index>=148&&index<156?32:header[index];
75
+ assert.equal(actualChecksum,checksum,'Tar checksum mismatch');
76
+ const size=tarOctal(header,124,136,'size');
77
+ const paddedSize=Math.ceil(size/512)*512;
78
+ assert.ok(offset+512+paddedSize<=tar.length,'Invalid archive size');
79
+ const type=header[156];
80
+ assert.ok(type===0||type===48||type===53,'Unsupported tar entry type: only regular files and directories are accepted');
81
+ const prefix=tarString(header,345,500);
82
+ const rawName=(prefix?prefix+'/':'')+tarString(header,0,100);
83
+ const name=safeArchiveName(rawName,type===53);
84
+ const folded=name.toLowerCase();
85
+ assert.ok(!names.has(folded),'Duplicate archive path: '+name);
86
+ names.add(folded);
87
+ assert.ok(names.size<=5000,'Archive contains too many entries');
88
+ if(type===53)assert.equal(size,0,'Tar directory contains data');
89
+ else files.set(name.slice('package/'.length),Buffer.from(tar.subarray(offset+512,offset+512+size)));
90
+ offset+=512+paddedSize;
91
+ }
92
+ assert.ok(ended,'Missing tar end marker');
93
+ return files;
94
+ }
95
+
96
+ function filePatternMatches(pattern,file){
97
+ const clean=pattern.replace(/^\.\//,'').replace(/\/$/,'');
98
+ if(file===clean||file.startsWith(clean+'/'))return true;
99
+ let expression='';
100
+ for(let index=0;index<clean.length;index++){
101
+ const char=clean[index];
102
+ if(char==='*'){
103
+ if(clean[index+1]==='*'){expression+='.*';index++;}
104
+ else expression+='[^/]*';
105
+ }else if(char==='?')expression+='[^/]';
106
+ else expression+=char.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');
107
+ }
108
+ return new RegExp('^'+expression+'$').test(file);
109
+ }
110
+
111
+ function includedByFiles(manifest,file){
112
+ assert.ok(Array.isArray(manifest.files)&&manifest.files.every(item=>typeof item==='string'),'Manifest files must be an array of strings');
113
+ return manifest.files.some(item=>!item.startsWith('!')&&filePatternMatches(item,file))
114
+ &&!manifest.files.some(item=>item.startsWith('!')&&filePatternMatches(item.slice(1),file));
115
+ }
116
+
117
+ function assertManifestResources(manifest){
118
+ archiveFilename(manifest);
119
+ assert.ok(typeof manifest.engines?.dsh==='string'&&manifest.engines.dsh.trim(),'Manifest must declare engines.dsh');
120
+ assert.ok(manifest.peerDependencies&&typeof manifest.peerDependencies==='object','Manifest must declare peerDependencies');
121
+ assert.equal(manifest.dsh?.bundle?.patch,'./cordis.patch.yml','Missing DSH bundle declaration');
122
+ assert.equal(manifest.exports?.['./locale/*.json'],'./locale/*.json','Missing locale wildcard export');
123
+ assert.equal(manifest.exports?.['./icon'],'./icon.svg','Missing icon export');
124
+ assert.equal(manifest.exports?.['./client'],'./lib/client.js','Missing Client export');
125
+ assert.equal(manifest.dsh?.client?.platform,'web','Missing Client declaration');
126
+ // Fixture packages used by packaging unit tests may be Host-only; the real
127
+ // manifest is checked by check.mjs and the live Client tests.
128
+ if(manifest.dsh?.client) assert.ok(Array.isArray(manifest.dsh.client.external)&&manifest.dsh.client.external.includes('zod'),'Missing Client external zod');
129
+ assert.equal(manifest.dsh?.client?.platform,'web','Missing Client declaration');
130
+ for(const file of REQUIRED_FILES){
131
+ // npm always includes these two files independently of its files allowlist.
132
+ if(file==='package.json'||file==='README.md')continue;
133
+ assert.ok(includedByFiles(manifest,file),'Manifest files does not include '+file);
134
+ }
135
+ }
136
+
137
+ async function localLibFiles(projectRoot){
138
+ const files=[];
139
+ async function walk(relative){
140
+ for(const entry of await readdir(path.join(projectRoot,relative),{withFileTypes:true})){
141
+ const name=relative+'/'+entry.name;
142
+ assert.ok(!entry.isSymbolicLink(),'Local lib must not contain links: '+name);
143
+ if(entry.isDirectory())await walk(name);
144
+ else{assert.ok(entry.isFile(),'Local lib must contain ordinary files: '+name);files.push(name);}
145
+ }
146
+ }
147
+ await walk('lib');
148
+ return files.sort();
149
+ }
150
+
151
+ function digest(bytes){return createHash('sha256').update(bytes).digest('hex');}
152
+
153
+ /** Read-only, fail-closed validation shared by verification, smoke and Desktop preflight. */
154
+ export async function verifyArchive(input,{projectRoot=PROJECT_ROOT}={}){
155
+ projectRoot=path.resolve(projectRoot);
156
+ const manifest=await readProjectManifest(projectRoot);
157
+ const archive=path.resolve(input||defaultArchivePath(manifest,projectRoot));
158
+ assert.equal(path.extname(archive).toLowerCase(),'.tgz','Pass a local .tgz archive');
159
+ let bytes;
160
+ try{bytes=await readFile(archive);}catch(error){
161
+ if(error.code==='ENOENT')throw new Error(`Package archive not found: ${archive}. Build and pack ${manifest.name}@${manifest.version}, or pass an explicit current archive; older archives are never selected automatically.`,{cause:error});
162
+ throw error;
163
+ }
164
+ const files=readPackageArchive(bytes);
165
+ assert.ok(files.has('package.json'),'Archive is missing package.json');
166
+ const packaged=JSON.parse(files.get('package.json').toString('utf8'));
167
+ for(const field of RUNTIME_FIELDS)assert.deepEqual(packaged[field],manifest[field],'Archive manifest mismatch: '+field);
168
+ assertManifestResources(manifest);
169
+ assertManifestResources(packaged);
170
+ for(const file of REQUIRED_FILES)assert.ok(files.has(file),'Archive is missing '+file);
171
+ for(const locale of ['en','zh']){
172
+ const data=JSON.parse(files.get('locale/'+locale+'.json').toString('utf8'));
173
+ assert.ok(typeof data.meta?.title==='string'&&data.meta.title.trim(),'Missing locale meta.title: '+locale);
174
+ assert.ok(typeof data.meta?.description==='string'&&data.meta.description.trim(),'Missing locale meta.description: '+locale);
175
+ }
176
+ const resourceLock=JSON.parse(files.get('resources/runtime-lock.json').toString('utf8'));
177
+ assert.equal(resourceLock.schemaVersion,1,'Unsupported runtime lock');
178
+ assert.ok(resourceLock.environments?.cp312&&resourceLock.environments?.cp313,'Missing host/fallback dependency locks');
179
+ if(resourceLock.fallback){
180
+ assert.equal(resourceLock.fallback?.version,'3.13.18','Fallback runtime drift');
181
+ assert.equal(resourceLock.fallback?.archive?.sha256,'7369f7a35f261222a6ac8b3a87c1c88eeebee8af945d85346202591a64038dd3','Fallback runtime hash drift');
182
+ }
183
+ for(const [abi,environment]of Object.entries(resourceLock.environments)){
184
+ assert.ok(environment.wheels?.some(wheel=>wheel.name==='pymobiledevice3'&&wheel.version===resourceLock.pymobiledevice3),'Missing complete dependency lock: '+abi);
185
+ for(const asset of [environment.pip,...environment.wheels]){
186
+ assert.match(asset.sha256,/^[a-f0-9]{64}$/,'Invalid runtime asset hash');
187
+ assert.ok(asset.size>0&&asset.url.startsWith('https://'),'Invalid runtime asset');
188
+ }
189
+ }
190
+ const notices=JSON.parse(files.get('resources/notices/provenance.json').toString('utf8'));
191
+ for(const record of notices){
192
+ assert.ok(!record.error,'Incomplete license record');
193
+ const notice=files.get('resources/notices/'+record.filename);
194
+ assert.ok(notice&&notice.length===record.bytes&&digest(notice)===record.sha256,'Missing or changed license text: '+record.filename);
195
+ }
196
+ const icon=files.get('icon.svg');
197
+ assert.ok(icon.length>0&&icon.length<=256*1024,'Icon exceeds the 256KiB limit or is empty');
198
+ const svg=icon.toString('utf8');
199
+ assert.ok(/<svg\b[^>]*>/i.test(svg)&&(/<\/svg\s*>/i.test(svg)||/<svg\b[^>]*\/\s*>/i.test(svg)),'Icon is not SVG content');
200
+ assert.ok(!/<!DOCTYPE|<!ENTITY/i.test(svg),'External SVG declarations are not accepted');
201
+ const expectedLib=await localLibFiles(projectRoot);
202
+ const archivedLib=[...files.keys()].filter(file=>file.startsWith('lib/')).sort();
203
+ assert.deepEqual(archivedLib,expectedLib,'Archive lib file list differs from local lib');
204
+ const libHashes={};
205
+ for(const [file,content]of files){
206
+ assert.ok(!file.split('/').some(part=>PRIVATE_PARTS.has(part)),'Private/unexpected archive artifact: '+file);
207
+ if(file.startsWith('lib/'))assert.ok(!BUSINESS_CONTENT.test(content.toString('utf8')),'Business/framework coupling: '+file);
208
+ // Documentation records may legitimately change after pack/install verification.
209
+ // Freeze executable code, configuration and display resources, not historical reports.
210
+ const immutable=file.startsWith('lib/')||file.startsWith('resources/')||file.startsWith('scripts/')||file.startsWith('locale/')
211
+ ||file==='icon.svg'||file==='cordis.patch.yml'||file==='requirements.txt';
212
+ if(!immutable)continue;
213
+ const source=await readFile(path.join(projectRoot,...file.split('/')));
214
+ assert.ok(content.equals(source),'Archive content differs from local file: '+file);
215
+ if(file.startsWith('lib/'))libHashes[file]=digest(content);
216
+ }
217
+ return {
218
+ files,manifest,projectRoot,archive,
219
+ summary:{ok:true,file:archive,name:packaged.name,version:packaged.version,bytes:bytes.length,
220
+ sha256:digest(bytes),packagedFiles:files.size,entry:packaged.main,bundlePatch:packaged.dsh.bundle.patch,
221
+ libFilesMatched:expectedLib.length,libHashes},
222
+ };
223
+ }
@@ -0,0 +1,13 @@
1
+ import {writeFile} from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import {verifyArchive} from './package-validation.mjs';
4
+
5
+ const args=process.argv.slice(2);
6
+ const checkOnly=args.includes('--check-only');
7
+ const positional=args.filter(arg=>arg!=='--check-only');
8
+ if(positional.length>1||positional.some(arg=>arg.startsWith('--')))throw new Error('Usage: node scripts/verify-package.mjs [--check-only] [archive.tgz]');
9
+ const verified=await verifyArchive(positional[0]);
10
+ if(!checkOnly){
11
+ await writeFile(verified.archive+'.sha256',verified.summary.sha256+' '+path.basename(verified.archive)+'\n');
12
+ }
13
+ console.log(JSON.stringify({...verified.summary,checkOnly},null,2));