@josephyulei/summon-foundation 0.1.3 → 0.1.4
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/README.md +4 -2
- package/bin/summon.mjs +15 -10
- package/lib/acquisition-task.mjs +24 -0
- package/lib/acquisition-worker.mjs +17 -0
- package/lib/journey-view.mjs +12 -0
- package/lib/operation-result.mjs +5 -3
- package/lib/progress-page.mjs +38 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# summon foundation
|
|
2
2
|
|
|
3
|
+
0.1.4 提供获取期间只读进度页。获取成功后同一页面关联运行程序返回的目录/确认页,仍由 Codex 内置浏览器打开;配合 Foundation 0.2.10 展示本次流程、当前目标和剩余动作。临时服务只随本次任务运行,不是守护进程,不执行未核验归档,也不替本人确认。原操作回执仍可独立只读查询,页断开不改写已核实终态。
|
|
4
|
+
|
|
3
5
|
Foundation 的薄获取入口,不包含完整运行包,没有 npm 安装生命周期脚本。
|
|
4
6
|
只有明确执行才查询/获取;安装和 Skill 注册继续各自需要用户确认。
|
|
5
7
|
|
|
6
8
|
可用性以 npm registry 的实际版本和公共 GitHub Release 为准;本目录或说明存在不是发布回执。只使用本项目已核验的包名,缺包时不换同名来源。
|
|
7
9
|
|
|
8
10
|
```text
|
|
9
|
-
npx --yes --package @josephyulei/summon-foundation@0.1.
|
|
11
|
+
npx --yes --package @josephyulei/summon-foundation@0.1.4 summon foundation
|
|
10
12
|
```
|
|
11
13
|
|
|
12
|
-
0.1.
|
|
14
|
+
0.1.4 入口配合 Foundation 0.2.10 正式发行使用。默认命令实际查询、固定版本、披露缓存、下载并校验,然后保持运行等待安装页目录选择。选择目录后还要亲自确认精确安装计划;不会自动注册 Skill 或接入项目。实际获取仍须通过 registry 与 Release 校验,本文不替代发布证明。
|
|
13
15
|
|
|
14
16
|
Codex 需要打开返回的内置浏览器网址,并分段等待同次操作结果。npm 不能自行操控或唤醒 Codex,对话主动告知不是程序退出码保证;新对话接续仍待真人验收。系统浏览器只是明确告知后的备用,不自动打开。
|
|
15
17
|
|
package/bin/summon.mjs
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {spawn,spawnSync} from 'node:child_process';
|
|
5
|
-
import {inspectRelease,
|
|
5
|
+
import {inspectRelease,plainPath} from '../lib/acquire.mjs';
|
|
6
6
|
|
|
7
|
+
import {acquireInWorker} from '../lib/acquisition-task.mjs';
|
|
8
|
+
import {startProgressPage} from '../lib/progress-page.mjs';
|
|
7
9
|
import {parseSummonArgs} from '../lib/cli-options.mjs';
|
|
8
10
|
import {createOperation,saveOperation,readOperation,runtimeObservation} from '../lib/operation-result.mjs';
|
|
9
11
|
|
|
@@ -37,8 +39,8 @@ function stageDirectory(){
|
|
|
37
39
|
const stat=fs.lstatSync(cache);if(stat.uid!==process.getuid()||(stat.mode&0o777)!==0o700)fail('获取缓存必须由当前用户独占 0700;不会自动 chmod 已有目录');
|
|
38
40
|
return fs.mkdtempSync(path.join(cache,'acquisition.'));
|
|
39
41
|
}
|
|
40
|
-
let operation=null,stage=null;
|
|
41
|
-
function updateOperation(patch){if(!operation)return;Object.assign(operation,patch,{updatedAt:new Date().toISOString()});const file=saveOperation(operation,stage);console.log(JSON.stringify({status:'FOUNDATION_INSTALL_OPERATION',...operation,resultFile:file,recordSaved:!!file}));}
|
|
42
|
+
let operation=null,stage=null,progressPage=null;
|
|
43
|
+
function updateOperation(patch){if(!operation)return;Object.assign(operation,patch,{updatedAt:new Date().toISOString()});const file=saveOperation(operation,stage);if(file)operation.resultFile=file;progressPage?.publish();console.log(JSON.stringify({status:'FOUNDATION_INSTALL_OPERATION',...operation,resultFile:file,recordSaved:!!file}));}
|
|
42
44
|
async function openInstalledWorkbench(root,env){
|
|
43
45
|
let child;
|
|
44
46
|
try{
|
|
@@ -66,25 +68,28 @@ try{
|
|
|
66
68
|
if(args.prepare||args.acquire)sourceGuard();
|
|
67
69
|
if(args.prepare||args.acquire){operation=createOperation();stage=stageDirectory();updateOperation({});if(!saveOperation(operation,stage))fail('无法在已披露的获取目录保存操作记录;尚未联网或安装');}
|
|
68
70
|
if(args.prepare)console.log('正在准备 Foundation 安装:将查询并固定本次正式版本,说明缓存位置后下载核验。未选目录会在安装页选择;之后仍需本人确认精确计划。请保持当前 Codex 任务等待并打开返回的内置浏览器网址;不会自动改用系统浏览器。');
|
|
69
|
-
const context=inspectRelease(args.version);
|
|
70
|
-
const guide=`https://github.com/${context.repository.full_name}/blob/${context.documentationCommit}/docs/install-with-codex.md`;
|
|
71
71
|
if(!args.prepare&&!args.acquire){
|
|
72
|
+
const context=inspectRelease(args.version);
|
|
73
|
+
const guide=`https://github.com/${context.repository.full_name}/blob/${context.documentationCommit}/docs/install-with-codex.md`;
|
|
72
74
|
console.log(JSON.stringify({schemaVersion:'1.0.0',status:'RELEASE_DISCOVERED_NOT_ACQUIRED',product:'Foundation',version:context.version,sourceCommit:context.sourceCommit,documentationCommit:context.documentationCommit,repository:context.repository.full_name,guide,installationPerformed:false,skillRegistered:false,
|
|
73
75
|
conversationNextStep:'本次 --inspect 仅查询;未下载、未安装,不自动接续写入。需要安装时由用户发起默认安装入口,并核对当前任务权限。',
|
|
74
76
|
terminalBoundary:'普通终端无法创建或唤醒 Codex 对话;请在有相应权限的 Codex 任务发起安装。',
|
|
75
77
|
acquisition:'尚未下载或验证运行归档。默认入口或 --prepare 执行匿名 GitHub 证明与完整性核验。'},null,2));
|
|
76
78
|
}else{
|
|
77
79
|
if(args.destination)plainPath(args.destination);console.log(`本次独占获取目录:${stage}`);
|
|
78
|
-
|
|
80
|
+
progressPage=await startProgressPage(()=>operation);
|
|
81
|
+
updateOperation({progressUrl:progressPage.url});
|
|
82
|
+
console.log(JSON.stringify({status:'FOUNDATION_ACQUISITION_PROGRESS_PAGE',url:progressPage.url,operationId:operation.operationId,next:'在 Codex 内置浏览器打开同次只读进度页,保持任务等待;不会自动打开系统浏览器。'}));
|
|
83
|
+
const {context,receipt}=await acquireInWorker({version:args.version,stage,operationId:operation.operationId,onContext:context=>updateOperation({version:context.version,sourceCommit:context.sourceCommit}),onProgress:download=>updateOperation({download}),onPhase:phase=>updateOperation({phase})});console.log(JSON.stringify({status:'GITHUB_ACQUISITION_VERIFIED',...receipt,destinationIntent:args.destination}));
|
|
79
84
|
updateOperation({phase:'acquired',version:context.version,sourceCommit:context.sourceCommit});
|
|
80
|
-
if(args.acquire){updateOperation({state:'update-input-ready',terminal:true});console.log(JSON.stringify({status:'UPDATE_INPUT_READY_NOT_APPLIED',candidate:path.dirname(receipt.launcher),receipt:path.join(stage,'acquisition.json'),next:'使用当前健康安装的稳定入口生成独立更新计划;本人确认后才更新。获取回执不是删除授权。'}));process.exit(0);}
|
|
85
|
+
if(args.acquire){updateOperation({state:'update-input-ready',terminal:true});console.log(JSON.stringify({status:'UPDATE_INPUT_READY_NOT_APPLIED',candidate:path.dirname(receipt.launcher),receipt:path.join(stage,'acquisition.json'),next:'使用当前健康安装的稳定入口生成独立更新计划;本人确认后才更新。获取回执不是删除授权。'}));await progressPage.close();progressPage=null;process.exit(0);}
|
|
81
86
|
const env={...process.env};for(const key of ['NODE_OPTIONS','NODE_PATH','NODE_V8_COVERAGE','NODE_REDIRECT_WARNINGS','NODE_COMPILE_CACHE','NODE_COMPILE_CACHE_PORTABLE','NODE_PRESERVE_SYMLINKS'])delete env[key];
|
|
87
|
+
const supported=spawnSync(receipt.launcher,['--help'],{encoding:'utf8',env,timeout:15000});
|
|
82
88
|
if(!args.destination){
|
|
83
|
-
const supported=spawnSync(receipt.launcher,['--help'],{encoding:'utf8',env,timeout:15000});
|
|
84
89
|
if(supported.status!==0||!supported.stdout.includes('--choose-destination'))fail('本次发行尚不支持页面选择目录;未启动安装。请由当前对话取得目录后使用明确的 --destination,或等待新版发行,不静默采用默认位置');
|
|
85
90
|
}
|
|
86
91
|
updateOperation({phase:'starting-confirmation-service',installationWrites:'unknown'});
|
|
87
|
-
const child=spawn(receipt.launcher,['install',...(args.destination?['--destination',args.destination]:['--choose-destination']),'--browser','codex'],{stdio:['inherit','pipe','inherit'],env});
|
|
92
|
+
const child=spawn(receipt.launcher,['install',...(!args.destination&&supported.stdout?.includes('--journey-id')?['--journey-id',operation.operationId]:[]),...(args.destination?['--destination',args.destination]:['--choose-destination']),'--browser','codex'],{stdio:['inherit','pipe','inherit'],env});
|
|
88
93
|
child.stdout.setEncoding('utf8');
|
|
89
94
|
let pending='',json='';
|
|
90
95
|
child.stdout.on('data',bytes=>{process.stdout.write(bytes);pending+=bytes.toString();if(pending.length>1_000_000){pending='';json='';return;}let end;while((end=pending.indexOf('\n'))>=0){const line=pending.slice(0,end);pending=pending.slice(end+1);if(!json&&!line.trim().startsWith('{'))continue;json+=line+'\n';if(json.length>1_000_000){json='';continue;}let e;try{e=JSON.parse(json)}catch{continue}json='';
|
|
@@ -102,4 +107,4 @@ try{
|
|
|
102
107
|
}
|
|
103
108
|
process.exitCode=ended.code;
|
|
104
109
|
}
|
|
105
|
-
}catch(e){updateOperation({state:operation&&operation.installationWrites!=='none'?'verification-required':'failed',terminal:true,errorCode:['ACQUISITION_TRANSPORT_FAILED','ACQUISITION_VALIDATION_FAILED'].includes(e.code)?e.code:'INSTALL_ENTRY_FAILED',diagnostic:e.diagnostic||null,next:'先核验旧工具进程已结束及同次结果;保留材料,不自动重试或重放安装确认'});const message=String(e.message).replace(/https?:\/\/\S+/g,'[已脱敏网址]').replace(/(?:github_pat_|ghp_|npm_)[A-Za-z0-9_]+/g,'[已脱敏凭据]');console.error(`错误:${message}`);process.exitCode=1;}
|
|
110
|
+
}catch(e){updateOperation({state:operation&&operation.installationWrites!=='none'?'verification-required':'failed',terminal:true,errorCode:['ACQUISITION_TRANSPORT_FAILED','ACQUISITION_VALIDATION_FAILED'].includes(e.code)?e.code:'INSTALL_ENTRY_FAILED',diagnostic:e.diagnostic||null,next:'先核验旧工具进程已结束及同次结果;保留材料,不自动重试或重放安装确认'});const message=String(e.message).replace(/https?:\/\/\S+/g,'[已脱敏网址]').replace(/(?:github_pat_|ghp_|npm_)[A-Za-z0-9_]+/g,'[已脱敏凭据]');console.error(`错误:${message}`);process.exitCode=1;}finally{if(progressPage)await progressPage.close();}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {Worker} from 'node:worker_threads';
|
|
2
|
+
|
|
3
|
+
export function acquireInWorker({version,stage,operationId,onContext=()=>{},onPhase=()=>{},onProgress=()=>{}}) {
|
|
4
|
+
return new Promise((resolve,reject)=>{
|
|
5
|
+
const worker=new Worker(new URL('./acquisition-worker.mjs',import.meta.url),{workerData:{version,stage,operationId}});
|
|
6
|
+
let receipt,context,failure;
|
|
7
|
+
const interrupt=()=>{failure=Object.assign(Error('获取任务被中断;保留本次材料'),{code:'ACQUISITION_INTERRUPTED'});void worker.terminate();};
|
|
8
|
+
process.once('SIGINT',interrupt);process.once('SIGTERM',interrupt);
|
|
9
|
+
worker.on('message',event=>{
|
|
10
|
+
if(event.type==='context'){context=event.context;onContext(context);}
|
|
11
|
+
else if(event.type==='phase')onPhase(event.phase);
|
|
12
|
+
else if(event.type==='progress')onProgress(event.download);
|
|
13
|
+
else if(event.type==='complete')receipt=event.receipt;
|
|
14
|
+
else if(event.type==='failure')failure=Object.assign(Error(event.message),{code:event.code,diagnostic:event.diagnostic});
|
|
15
|
+
});
|
|
16
|
+
worker.on('error',error=>{failure=error;});
|
|
17
|
+
worker.once('exit',code=>{
|
|
18
|
+
process.off('SIGINT',interrupt);process.off('SIGTERM',interrupt);
|
|
19
|
+
if(failure)reject(failure);
|
|
20
|
+
else if(code!==0||!receipt||!context)reject(Error('获取进程未提供已验证结果;不启动运行文件'));
|
|
21
|
+
else resolve({context,receipt});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Trusted npm code only. Network/proof routines contain synchronous calls;
|
|
2
|
+
// isolate those calls so the read-only progress server remains responsive.
|
|
3
|
+
import {parentPort, workerData} from 'node:worker_threads';
|
|
4
|
+
import {inspectRelease, acquireRelease} from './acquire.mjs';
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const context = inspectRelease(workerData.version);
|
|
8
|
+
parentPort.postMessage({type:'context',context});
|
|
9
|
+
const receipt = await acquireRelease(context, workerData.stage, {
|
|
10
|
+
operationId:workerData.operationId,
|
|
11
|
+
onPhase:phase=>parentPort.postMessage({type:'phase',phase}),
|
|
12
|
+
onProgress:download=>parentPort.postMessage({type:'progress',download}),
|
|
13
|
+
});
|
|
14
|
+
parentPort.postMessage({type:'complete',receipt});
|
|
15
|
+
} catch(error) {
|
|
16
|
+
parentPort.postMessage({type:'failure',code:error.code,diagnostic:error.diagnostic||null,message:String(error.message).replace(/https?:\/\/\S+/g,'[已脱敏网址]').replace(/(?:github_pat_|ghp_|npm_)[A-Za-z0-9_]+/g,'[已脱敏凭据]')});
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Presentation only. Planned steps never grant execution authority.
|
|
2
|
+
export function journeyView({id,kind='install',observations={},skillChoice='undecided',includeAcquisition=false,includeSelection=false,includeHealth=true,includeCleanup=false,includeSkillRemoval=false}) {
|
|
3
|
+
const labels={acquire:'获取并核验运行文件',select:'选择安装目录',program:({install:'安装程序',update:'更新程序',uninstall:'移除程序'})[kind]||'执行当前维护',health:'验证稳定入口',cleanup:'处理本次暂存',material:'准备对话能力材料',register:'注册到 Codex',remove:'移除 Codex 注册'};
|
|
4
|
+
const statusLabels={completed:'已完成',pending:'待确认',planned:'尚待处理',running:'进行中',executing:'进行中',consumed:'进行中',failed:'失败',cancelled:'已取消',expired:'已过期',skipped:'已跳过',undecided:'可选,待选择',retained:'已处理,保留部分材料','verification-required':'待核实'};
|
|
5
|
+
const keys=[...(includeAcquisition?['acquire']:[]),...(includeSelection?['select']:[]),...(includeSkillRemoval?['remove']:[]),'program',...(includeHealth?['health']:[]),...(includeCleanup?['cleanup']:[])];
|
|
6
|
+
if(kind!=='uninstall'&&(observations.material||observations.register||skillChoice==='selected'))keys.push('material','register');else if(kind!=='uninstall')keys.push('optional-skill');
|
|
7
|
+
const steps=keys.map(key=>{const supplied=observations[key],state=key==='optional-skill'?(skillChoice==='skipped'?'skipped':'undecided'):supplied?.state||'planned';return{id:`${id}:${key}`,key,title:labels[key]||'Codex 对话能力',state,label:statusLabels[state]||'待核实',evidence:supplied?.evidence||null,required:key!=='optional-skill'};});
|
|
8
|
+
const unresolved=steps.filter(s=>s.required&&!['completed','skipped','retained'].includes(s.state)),name=({install:'安装',update:'更新',uninstall:'卸载'})[kind]||'维护';
|
|
9
|
+
const program=observations.program?.state==='completed',trouble=unresolved.find(s=>['failed','cancelled','expired','verification-required'].includes(s.state));
|
|
10
|
+
const title=!unresolved.length?`${name}完成`:program?`程序已完成,${(trouble||unresolved[0]).title}${trouble?'未完成':'仍待处理'}`:trouble?`${name}未完成`:`${name}流程`;
|
|
11
|
+
return {schemaVersion:'1.1.0',id,kind,title,ended:unresolved.length===0,steps,remaining:unresolved.map(s=>s.title),summary:unresolved.length?`尚余:${unresolved.map(s=>s.title+'('+s.label+')').join('、')}`:kind==='uninstall'?'本次卸载步骤已完成。请查看卸载回执中的实际删除范围、保留文件与清理说明。':skillChoice==='undecided'&&!observations.register?'已确定操作已完成;对话能力可选,尚未选择。项目接入独立。':'本次已选择步骤均已处理;新任务发现及项目接入另验。',executionAuthority:false};
|
|
12
|
+
}
|
package/lib/operation-result.mjs
CHANGED
|
@@ -7,12 +7,14 @@ export function createOperation() {
|
|
|
7
7
|
}
|
|
8
8
|
// Observations from the verified runtime, never confirmation or execution authority.
|
|
9
9
|
export function runtimeObservation(event) {
|
|
10
|
-
|
|
11
|
-
if(
|
|
10
|
+
let confirmationUrl;
|
|
11
|
+
if(event.url){const url=new URL(event.url);if(url.protocol==='http:'&&url.hostname==='127.0.0.1'&&!url.username&&!url.password)confirmationUrl=url.href;}
|
|
12
|
+
if(event.status==='AWAITING_FOUNDATION_DIRECTORY_SELECTION')return {phase:'selecting-directory',selectionId:event.selectionId,journeyContext:event.journeyContext,installationWrites:'none',...(confirmationUrl?{confirmationUrl}:{})};
|
|
13
|
+
if(['FOUNDATION_SELECTION_BOUND','AWAITING_FOUNDATION_UI_CONFIRMATION'].includes(event.status))return {phase:'awaiting-confirmation',...(event.journeyContext?{journeyContext:event.journeyContext}:{}),sessionId:event.sessionId,planHash:event.planHash,installationWrites:'none',...(confirmationUrl?{confirmationUrl}:{})};
|
|
12
14
|
if(event.status==='FOUNDATION_OPERATION_STATE'&&['executing','consumed'].includes(event.state))return {phase:'executing',sessionId:event.sessionId,installationWrites:'possible'};
|
|
13
15
|
if(event.status==='BOOTSTRAP_OPERATION_ENDED'){
|
|
14
16
|
const state=['completed','failed','cancelled','expired'].includes(event.state)?event.state:'verification-required';
|
|
15
|
-
return {phase:'runtime-ended',state,terminal:state!=='verification-required',sessionId:event.sessionId,installationRoot:event.installationRoot,installationWrites:state==='completed'?'runtime-reported-installed':'unknown',runtimeHealth:event.result?.executableHealth||'unknown',next:'只读核验稳定 installed launcher 或同次 session 结果,不重放确认'};
|
|
17
|
+
return {phase:'runtime-ended',state,terminal:state!=='verification-required',sessionId:event.sessionId,installationRoot:event.installationRoot,installationWrites:state==='completed'?'runtime-reported-installed':'unknown',runtimeHealth:event.result?.stableLauncherHealth||event.result?.lifecycleResult?.stableLauncherHealth||event.result?.executableHealth||'unknown',journeyContext:event.journeyContext,next:'只读核验稳定 installed launcher 或同次 session 结果,不重放确认'};
|
|
16
18
|
}
|
|
17
19
|
if(['cancelled-no-install','expired-no-install','shutdown-no-install'].includes(event.state))return {phase:'directory-selection-ended',state:event.state,terminal:true,installationWrites:'none'};
|
|
18
20
|
return null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import {journeyView} from './journey-view.mjs';
|
|
4
|
+
|
|
5
|
+
export function acquisitionProgress(record) {
|
|
6
|
+
const phases={discovering:'查询正式发行','verifying-trust':'核验发行来源','fetching-and-verifying-catalog':'获取并核验发行清单','fetching-and-verifying-runtime':'下载并核验运行文件','extracting-and-validating':'展开并检查文件','acquired':'获取验证完成','starting-confirmation-service':'准备目录选择与确认页','selecting-directory':'等待你选择目录','awaiting-confirmation':'等待你确认安装',executing:'正在安装','runtime-ended':'读取安装结果',finished:'安装结果已返回'};
|
|
7
|
+
const terminal=record.terminal;
|
|
8
|
+
const acquired=['acquired','starting-confirmation-service','selecting-directory','directory-selection-ended','awaiting-confirmation','executing','runtime-ended','finished'].includes(record.phase);
|
|
9
|
+
const observations={acquire:{state:acquired?'completed':terminal?'failed':'running',evidence:record.resultFile}};
|
|
10
|
+
if(record.phase==='selecting-directory')observations.select={state:'pending'};
|
|
11
|
+
if(record.phase==='directory-selection-ended')observations.select={state:record.state==='cancelled-no-install'?'cancelled':record.state==='expired-no-install'?'expired':'verification-required',evidence:record.selectionId};
|
|
12
|
+
if(['awaiting-confirmation','executing','runtime-ended','finished'].includes(record.phase))observations.select={state:'completed',evidence:record.selectionId};
|
|
13
|
+
if(record.phase==='awaiting-confirmation')observations.program={state:'pending',evidence:record.sessionId};
|
|
14
|
+
if(record.phase==='executing')observations.program={state:'running',evidence:record.sessionId};
|
|
15
|
+
if(['runtime-ended','finished'].includes(record.phase))observations.program={state:record.state,evidence:record.sessionId};
|
|
16
|
+
if(record.runtimeHealth==='passed')observations.health={state:'completed',evidence:record.sessionId};
|
|
17
|
+
const journey=journeyView({id:record.operationId,includeAcquisition:true,includeSelection:true,observations,skillChoice:record.journeyContext?.skillChoice||'undecided'});
|
|
18
|
+
return {journey,operationId:record.operationId,title:terminal?(record.state==='completed'?'安装结果已返回':record.state==='update-input-ready'?'更新材料已就绪':record.state==='failed'?'获取或安装失败':'本次结果需查看'):'正在准备 Foundation',phase:phases[record.phase]||'阶段待核实',state:record.state,version:record.version||null,download:record.download||null,program:record.installationWrites==='runtime-reported-installed'?'程序安装已返回成功,健康以记录为准':record.installationWrites==='none'?'尚未写入安装目录':'安装结果待核实',skill:record.skillRegistered===true?'已有注册记录;新对话发现待验证':'未自动注册,可选独立步骤',project:'未自动接入项目',next:record.terminal&&record.state==='completed'?(record.journeyContext?.skillChoice==='skipped'?'程序已完成,本次已跳过对话能力;需要时再单独接入。':'程序结果已返回;对话能力和项目按当前选择分别处理。'):record.next||'保持当前任务观察;页面选择目录后仍需本人确认。',nextUrl:record.terminal?(record.workbench?.state==='ready'?record.workbench.url:null):record.confirmationUrl||null,nextLabel:record.terminal?'打开已安装工作台':'继续到目录选择 / 本人确认页',resultFile:record.resultFile||null,terminal,diagnostic:record.diagnostic||null};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// A bounded, read-only loopback view over the existing in-memory operation.
|
|
22
|
+
// No POST, launch endpoint, confirmation authority or downloaded executable.
|
|
23
|
+
export async function startProgressPage(readRecord) {
|
|
24
|
+
const token=crypto.randomBytes(24).toString('hex'),base=`/${token}`,clients=new Set();
|
|
25
|
+
const html=`<!doctype html><html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Foundation 获取与安装进度</title><style>body{font:16px/1.6 system-ui;max-width:760px;margin:24px auto;padding:0 20px;color:#18181b;background:#fafafa;overflow-wrap:anywhere}section{background:white;border:1px solid #e4e4e7;border-radius:12px;padding:16px;margin:16px 0}h1{font-size:24px}h2{font-size:18px}a{display:inline-block;padding:12px;border:1px solid #71717a;border-radius:8px;color:inherit}pre{white-space:pre-wrap}a:focus-visible,summary:focus-visible{outline:3px solid #2563eb}[hidden]{display:none}</style><body><h1>正在准备 Foundation</h1><section role="status" aria-live="polite"><h2 id="phase">正在读取同次操作</h2><div id="journey-steps"></div><p id="journey-summary"></p><p id="download"></p><p id="program"></p><p id="skill"></p><p id="project"></p><p id="next"></p><a id="continue" hidden>继续到目录选择 / 本人确认页</a><p id="connection"></p></section><p>此页面只读,不批准安装;程序、对话能力与项目分别确认。未知长度不显示百分比。临时服务结束后,可从原对话读取保留的操作结果。</p><details><summary>操作与恢复详情</summary><pre id="raw"></pre></details><script>let last=null;function show(p){last=p;document.querySelector('h1').textContent=p.journey.title;document.getElementById('journey-summary').textContent=p.journey.summary;const steps=document.getElementById('journey-steps');steps.replaceChildren();for(const step of p.journey.steps){const line=document.createElement('p');line.textContent=step.title+':'+step.label;steps.append(line);}for(const key of ['phase','program','skill','project','next'])document.getElementById(key).textContent=p[key]||'';const d=p.download;document.getElementById('download').textContent=d&&Number.isFinite(d.downloadedBytes)?'本次实际接收 '+d.downloadedBytes+' 字节'+(Number.isFinite(d.totalBytes)?' / '+d.totalBytes+' 字节':'(总长度未知)'):'';const link=document.getElementById('continue');link.hidden=!p.nextUrl;link.textContent=p.nextLabel;if(p.nextUrl)link.href=p.nextUrl;document.getElementById('raw').textContent=JSON.stringify(p,null,2);}const events=new EventSource(location.pathname+'/events');events.onmessage=e=>show(JSON.parse(e.data));events.onerror=()=>{events.close();document.getElementById('connection').textContent=last&&last.terminal?'临时进度服务已结束,上方保留最后收到的结果。':'连接已中断,当前状态待核实;不自动重试安装。'};window.addEventListener('pagehide',()=>events.close(),{once:true});</script></body></html>`;
|
|
26
|
+
let origin;
|
|
27
|
+
const current=()=>JSON.stringify(acquisitionProgress(readRecord()));
|
|
28
|
+
const server=http.createServer((req,res)=>{
|
|
29
|
+
if(req.method!=='GET'||req.headers.host!==origin||req.headers.origin&&req.headers.origin!==`http://${origin}`){res.writeHead(403).end();return;}
|
|
30
|
+
const headers={'cache-control':'no-store','x-content-type-options':'nosniff','content-security-policy':"default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'"};
|
|
31
|
+
if(req.url===base){res.writeHead(200,{...headers,'content-type':'text/html; charset=utf-8'}).end(html);}
|
|
32
|
+
else if(req.url===base+'/events'){res.writeHead(200,{...headers,'content-type':'text/event-stream'});res.write(`data: ${current()}\n\n`);clients.add(res);req.on('close',()=>clients.delete(res));}
|
|
33
|
+
else{res.writeHead(404).end();}
|
|
34
|
+
});
|
|
35
|
+
await new Promise((resolve,reject)=>{server.once('error',reject);server.listen(0,'127.0.0.1',resolve);});
|
|
36
|
+
origin=`127.0.0.1:${server.address().port}`;
|
|
37
|
+
return {url:`http://${origin}${base}`,publish(){for(const res of clients)res.write(`data: ${current()}\n\n`);},close(){for(const res of clients)res.end();clients.clear();return new Promise(resolve=>server.close(resolve));}};
|
|
38
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@josephyulei/summon-foundation",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@josephyulei/summon-foundation",
|
|
9
|
-
"version": "0.1.
|
|
9
|
+
"version": "0.1.4",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@sigstore/bundle": "4.0.0",
|
package/package.json
CHANGED