@josephyulei/summon-foundation 0.1.6 → 0.1.8

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 CHANGED
@@ -1,6 +1,10 @@
1
1
  # summon foundation
2
2
 
3
- 0.1.6 单页试用入口与 Foundation 0.2.12 起的运行引擎共同支持同一页面内的目录选择、程序和 Skill 独立确认;旧发行版本不具备本次单页修订。真实安装、新任务发现和主动告知仍需独立验收。
3
+ 当前用户共用一份程序与一份可选对话功能。安装仅选择软件位置,不选择业务项目。各项目随后单独接入,资料各自保管;旧安装不自动迁移或覆盖。
4
+
5
+ 保留真实下载状态与独立确认。基础环境不能安全启动页面时,由 Codex 对话先披露并取得独立批准,再准备专用环境;页面启动后全程同页。具体方法见仓库 `docs/install-with-codex.md`,不能先运行 npx 来准备缺失的 Node。不修改共享 PATH;获取器专用环境及其回执按缓存保留,程序另用随包运行时。发行发现仅需 curl,获取还需 tar;已验证载荷的确认、恢复和卸载不依赖下载工具。
6
+
7
+ 0.1.8 单页试用入口与 Foundation 0.2.14 的运行引擎共同支持当前用户共用安装及清晰的完成、取消和部分完成反馈。同一页面内保留目录选择、程序和 Skill 独立确认。真实安装、新任务发现和主动告知仍需独立验收。
4
8
 
5
9
  首次 URL 持续显示本次流程;确认仅转交本次受控子进程的当前计划,不新开manager页。--acquire仍只读获取;--resume仅在用户明确要求后恢复未完成Skill,不重放程序安装。
6
10
 
@@ -12,7 +16,7 @@ Foundation 的薄获取入口,不包含完整运行包,没有 npm 安装生
12
16
  确认 registry 中存在本版本及对应不可变 Release 后,在具备安装权限的新 Codex 对话粘贴:
13
17
 
14
18
  ```text
15
- npx --yes --package @josephyulei/summon-foundation@0.1.6 summon foundation
19
+ npx --yes --package @josephyulei/summon-foundation@0.1.8 summon foundation
16
20
  ```
17
21
 
18
22
  旧版退出推荐入口;支持边界见[现行支持策略](https://github.com/y15801172513-lang/foundation/blob/main/docs/install-platform-024.md#现行支持策略)。旧不可变版本不修改,不自动迁移或清除旧安装。
@@ -0,0 +1,51 @@
1
+ #!/bin/sh
2
+ # C6: bootstrap the npm entry, not Foundation itself. No Node/npm is needed
3
+ # to inspect this plan. Keep pins aligned with official-node-runtime.mjs.
4
+ set -eu
5
+ umask 077
6
+ fail(){ printf '错误:%s\n' "$1" >&2; exit 1; }
7
+ version=24.14.1
8
+ archive_hash=25495ff85bd89e2d8a24d88566d7e2f827c6b0d3d872b2cebf75371f93fcb1fe
9
+ node_hash=35d4bc736bbe4161f0c074aa140ddb74586e46969bc2ad63d32c838bec4463ff
10
+ license_hash=4573185d56580da2b890ba34a85a409257640f1c5632eade4300137266194d18
11
+ url=https://nodejs.org/dist/v24.14.1/node-v24.14.1-darwin-arm64.tar.gz
12
+ prefix=node-v24.14.1-darwin-arm64
13
+ mode=${1:-}; destination=${2:-}; approval=${3:-}
14
+ [ "$#" -ge 2 ] && [ "$#" -le 3 ] || fail '用法:sh prepare-environment.sh --inspect /绝对独立目录;本人批准后以 --prepare 同一路径 精确计划摘要执行'
15
+ case "$mode" in --inspect|--prepare) ;; *) fail '仅支持查看计划或按批准准备环境' ;; esac
16
+ case "$destination" in /*) ;; *) fail '环境位置必须是绝对路径' ;; esac
17
+ case "$destination" in *'
18
+ '*|*'/../'*|*'/./'*|*/|'/') fail '环境位置必须是规范化独立目录' ;; esac
19
+ [ "$(/usr/bin/uname -s)" = Darwin ] && [ "$(/usr/bin/uname -m)" = arm64 ] || fail '此设备暂不支持;不会通过准备环境绕过平台限制'
20
+ for tool in /usr/bin/curl /usr/bin/tar /usr/bin/shasum /usr/bin/stat /bin/mkdir /bin/chmod; do [ -x "$tool" ] || fail "缺少可信系统工具:$tool"; done
21
+ parent=${destination%/*}; [ -n "$parent" ] || fail '不能写系统根目录'
22
+ [ -d "$parent" ] && [ -w "$parent" ] && [ -x "$parent" ] || fail '父目录不存在或无权限;不会代建系统目录'
23
+ [ "$(CDPATH= cd -- "$parent" && pwd -P)" = "$parent" ] || fail '父目录含链接或非规范路径'
24
+ cursor=$parent
25
+ while [ "$cursor" != / ]; do [ ! -L "$cursor" ] || fail '拒绝符号链接祖先'; cursor=${cursor%/*}; [ -n "$cursor" ] || cursor=/; done
26
+ [ ! -e "$destination" ] && [ ! -L "$destination" ] || fail '目标已经存在;保留已有或失败材料,请核验后选择新的独立目录'
27
+ parent_identity=$(/usr/bin/stat -f '%d:%i:%u:%Lp' "$parent")
28
+ plan=$(printf 'foundation-entry-environment-v1\n%s\n%s\n%s\n%s\n%s\nno-shared-settings\n' "$version" "$destination" "$parent_identity" "$url" "$archive_hash" | /usr/bin/shasum -a 256)
29
+ plan=${plan%% *}
30
+ printf '基础环境计划:Node.js %s(含 npm),仅用于启动获取器\n来源:%s\n位置:%s\n影响:不修改现有 Node、Shell、PATH 或系统设置;不安装 Foundation、不注册 Skill\n保留:失败材料和环境回执;不自动清理\n计划摘要:%s\n' "$version" "$url" "$destination" "$plan"
31
+ [ "$mode" = --prepare ] || exit 0
32
+ [ -n "$approval" ] && [ "$approval" = "$plan" ] || fail '缺少匹配的本人批准计划摘要;没有准备环境'
33
+ # The invoking Codex task must obtain human approval for the displayed plan.
34
+ # This argument binds that request; it is not evidence of a UI confirmation.
35
+ [ "$(CDPATH= cd -- "$parent" && pwd -P)" = "$parent" ] && [ "$(/usr/bin/stat -f '%d:%i:%u:%Lp' "$parent")" = "$parent_identity" ] || fail '父目录在批准后变化;没有准备环境'
36
+ /bin/mkdir -m 700 -- "$destination" || fail '创建独占环境目录失败'
37
+ printf 'state=preparing\nplan=%s\nsource=%s\narchive_sha256=%s\nshared_settings_changed=false\n' "$plan" "$url" "$archive_hash" > "$destination/environment-result.txt"
38
+ trap 'printf "state=failed-or-interrupted\n" >> "$destination/environment-result.txt"' EXIT
39
+ /usr/bin/curl -q --fail --silent --show-error --location --max-redirs 3 --proto '=https' --proto-redir '=https' --connect-timeout 15 --max-time 600 --max-filesize 134217728 -o "$destination/node.tar.gz" "$url" || fail '官方环境下载失败;保留材料,不执行'
40
+ observed=$(/usr/bin/shasum -a 256 "$destination/node.tar.gz"); [ "${observed%% *}" = "$archive_hash" ] || fail '官方环境归档摘要不匹配'
41
+ /usr/bin/tar -xzpf "$destination/node.tar.gz" --no-same-owner --no-acls --no-fflags --no-mac-metadata --no-xattrs -C "$destination" || fail '已验证归档解包失败'
42
+ node="$destination/$prefix/bin/node"
43
+ [ -f "$node" ] && [ ! -L "$node" ] && [ -x "$node" ] || fail '缺少绑定运行时'
44
+ observed=$(/usr/bin/shasum -a 256 "$node"); [ "${observed%% *}" = "$node_hash" ] || fail '运行时字节不符'
45
+ observed=$(/usr/bin/shasum -a 256 "$destination/$prefix/LICENSE"); [ "${observed%% *}" = "$license_hash" ] || fail '许可字节不符'
46
+ unset NODE_OPTIONS NODE_PATH NODE_V8_COVERAGE NODE_REDIRECT_WARNINGS NODE_COMPILE_CACHE NODE_COMPILE_CACHE_PORTABLE NODE_PRESERVE_SYMLINKS
47
+ [ "$("$node" --version)" = "v$version" ] || fail '环境准备后版本复检失败'
48
+ [ -f "$destination/$prefix/lib/node_modules/npm/bin/npm-cli.js" ] || fail '官方环境缺少 npm 入口'
49
+ printf 'state=prepared-and-rechecked\nnode_version=%s\nnode_sha256=%s\nnode=%s\nnpm_cli=%s\n' "$version" "$node_hash" "$node" "$destination/$prefix/lib/node_modules/npm/bin/npm-cli.js" >> "$destination/environment-result.txt"
50
+ trap - EXIT
51
+ printf '基础环境已准备并复检。由当前任务以此 Node 和 npm 入口启动已固定版本的 Foundation 单页;不要更改全局 PATH。\n回执:%s/environment-result.txt\n' "$destination"
package/bin/summon.mjs CHANGED
@@ -13,6 +13,7 @@ import {resumeSkillHandoff} from '../lib/resume-handoff.mjs';
13
13
  import {parseSummonArgs} from '../lib/cli-options.mjs';
14
14
  import {createOperation,saveOperation,readOperation,runtimeObservation} from '../lib/operation-result.mjs';
15
15
  import {createJourneyControl} from '../lib/journey-control.mjs';
16
+ import {inspectEntryEnvironment} from '../lib/environment-check.mjs';
16
17
 
17
18
  const help=`summon foundation [--version x.y.z] [--destination /absolute/folder]
18
19
  summon foundation --inspect [--version x.y.z]
@@ -50,21 +51,25 @@ function stageDirectory(){
50
51
  return fs.mkdtempSync(path.join(cache,'acquisition.'));
51
52
  }
52
53
  let operation=null,stage=null,progressPage=null;
53
- const journeyControl=createJourneyControl(()=>operation,()=>progressPage?.publish());
54
+ const journeyControl=createJourneyControl(()=>operation,patch=>patch?updateOperation(patch):progressPage?.publish());
54
55
  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}));}
55
56
  try{
56
57
  const args=parseSummonArgs(process.argv.slice(2));
57
58
  if(args.help){console.log(help);process.exit(0);}
58
59
  if(args.status){console.log(JSON.stringify(readOperation(args.status),null,2));process.exit(0);}
59
- const [major,minor]=process.versions.node.split('.').map(Number);
60
- if(major<22||(major===22&&minor<9))fail('获取入口需要 Node.js 22.9 或以上;尚未安装,不自动安装依赖');
61
- if(process.platform!=='darwin'||process.arch!=='arm64')fail('当前仅支持 macOS arm64;尚未安装');
60
+ const initialEnvironment=inspectEntryEnvironment({purpose:args.uninstall?'uninstall':args.resume?'resume':args.inspect?'discover':'acquire'});
61
+ if(!initialEnvironment.supported||!initialEnvironment.compatible){
62
+ operation=createOperation();updateOperation({phase:'checking-environment',environment:initialEnvironment});
63
+ fail(!initialEnvironment.supported?'当前仅支持 macOS arm64;尚未安装':'获取入口需要 Node.js 22.9 或以上;当前入口不能安全承诺同页准备,请按安装说明在对话中先确认独立基础环境,不自动安装依赖');
64
+ }
62
65
  const maintenance=args.update||args.uninstall;
63
66
  if(args.prepare||args.acquire||maintenance||args.resume)sourceGuard();
64
- if(args.prepare||args.acquire||maintenance){operation=createOperation();stage=stageDirectory();updateOperation({});if(!saveOperation(operation,stage))fail('无法在已披露的获取目录保存操作记录;尚未联网或安装');}
67
+ if(args.prepare||args.acquire||maintenance){operation=createOperation();Object.assign(operation,{phase:'checking-environment',environment:initialEnvironment});stage=stageDirectory();updateOperation({});if(!saveOperation(operation,stage))fail('无法在已披露的获取目录保存操作记录;尚未联网或安装');}
65
68
  if(args.prepare)console.log('正在准备 Foundation 安装:将查询并固定本次正式版本,说明缓存位置后下载核验。未选目录会在安装页选择;之后仍需本人确认精确计划。请保持当前 Codex 任务等待并打开返回的内置浏览器网址;不会自动改用系统浏览器。');
66
69
  if(args.resume){
67
70
  operation=readOperation(args.resume);stage=path.dirname(plainPath(args.resume));
71
+ updateOperation({environment:initialEnvironment});
72
+ if(initialEnvironment.state!=='ready')fail('恢复所需环境无法核实;保留已有安装和操作记录');
68
73
  progressPage=await startProgressPage(()=>operation,{control:journeyControl});
69
74
  console.log(JSON.stringify({status:'FOUNDATION_SINGLE_PAGE',url:progressPage.url,operationId:operation.operationId}));
70
75
  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];
@@ -77,12 +82,14 @@ try{
77
82
  if(!current?.identity?.installId)fail('当前安装身份无法核实;尚未获取或执行维护');
78
83
  const capability=spawnSync(installed.launcher,['--help'],{encoding:'utf8',env,timeout:15000});
79
84
  if(capability.status!==0||!capability.stdout.includes('--journey-channel'))fail('当前安装不受新版单页流程支持。请另行确认卸载旧版并重新安装新版;本次不删除、不迁移、不回退旧页面');
80
- updateOperation({kind:args.update?'update':'uninstall',installationRoot:args.root,currentVersion:current.version,installId:current.identity.installId});
85
+ const environment=inspectEntryEnvironment({purpose:args.update?'acquire':'uninstall'});
86
+ updateOperation({kind:args.update?'update':'uninstall',installationRoot:args.root,currentVersion:current.version,installId:current.identity.installId,environment,usageScope:current.usageScope||{kind:'user',project:null}});
81
87
  progressPage=await startProgressPage(()=>operation,{control:journeyControl});updateOperation({progressUrl:progressPage.url});
82
88
  console.log(JSON.stringify({status:'FOUNDATION_SINGLE_PAGE',url:progressPage.url,operationId:operation.operationId}));
89
+ if(environment.state!=='ready')fail('环境复检未通过:'+environment.state+';缺少 '+environment.missing.join('、')+';保留当前安装,不修改系统工具');
83
90
  let candidate;
84
91
  if(args.update){
85
- 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})});
92
+ 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,...(phase==='fetching-and-verifying-runtime'?{download:null}:{})})});
86
93
  const directory=plainPath(path.dirname(receipt.launcher)),manifest=JSON.parse(fs.readFileSync(plainPath(path.join(directory,'manifest.json'))));
87
94
  if(manifest.productVersion!==context.version)fail('获取版本与候选不一致');
88
95
  candidate={path:directory,manifestHash:manifest.candidateHash,version:manifest.productVersion,bytes:manifest.totalBytes,runtimeHash:manifest.files.find(f=>f.path===manifest.runtime.path)?.sha256};
@@ -92,6 +99,7 @@ try{
92
99
  process.exitCode=operation.state==='completed'?0:1;
93
100
  await progressPage.close();progressPage=null;
94
101
  }else if(!args.prepare&&!args.acquire){
102
+ if(initialEnvironment.state!=='ready'){operation=createOperation();updateOperation({phase:'checking-environment',environment:initialEnvironment});fail('发行查询所需环境无法核实;尚未联网');}
95
103
  const context=inspectRelease(args.version);
96
104
  const guide=`https://github.com/${context.repository.full_name}/blob/${context.documentationCommit}/docs/install-with-codex.md`;
97
105
  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,
@@ -103,13 +111,16 @@ try{
103
111
  progressPage=await startProgressPage(()=>operation,args.acquire?{}:{control:journeyControl});
104
112
  updateOperation({progressUrl:progressPage.url});
105
113
  console.log(JSON.stringify({status:'FOUNDATION_ACQUISITION_PROGRESS_PAGE',url:progressPage.url,operationId:operation.operationId,next:'在 Codex 内置浏览器打开本次页面,所有所需确认在原页展开;保持任务等待,不自动打开系统浏览器。'}));
114
+ const environment=inspectEntryEnvironment({purpose:'acquire'});updateOperation({phase:'checking-environment',environment});
115
+ if(environment.state!=='ready')fail('获取环境检查未通过:'+environment.state+';缺少 '+environment.missing.join('、')+';不会以安装 Node 替代缺失的系统工具');
106
116
  if(!args.acquire){
117
+ updateOperation({phase:'discovering'});
107
118
  const metadata=inspectRelease(args.version);args.version=metadata.version;
108
- updateOperation({phase:'choosing-intent',version:metadata.version,sourceCommit:metadata.sourceCommit,acquisitionRoot:stage,destinationIntent:args.destination||'',journeyContext:{id:operation.operationId,skillChoice:'undecided'}});
119
+ updateOperation({phase:'choosing-intent',environment,version:metadata.version,sourceCommit:metadata.sourceCommit,acquisitionRoot:stage,destinationIntent:args.destination||'',journeyContext:{id:operation.operationId,skillChoice:'undecided'}});
109
120
  const choice=await journeyControl.waitChoice();
110
- updateOperation({phase:'discovering',intentSelected:true,destinationIntent:choice.destination,journeyContext:{id:operation.operationId,skillChoice:choice.skillChoice}});
121
+ updateOperation({phase:'discovering',intentSelected:true,destinationIntent:choice.destination,scopeIntent:{kind:choice.scopeKind,projectRoot:choice.projectRoot},destinationCheck:choice.destinationCheck,journeyContext:{id:operation.operationId,skillChoice:choice.skillChoice}});
111
122
  }
112
- 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}));
123
+ 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,...(phase==='fetching-and-verifying-runtime'?{download:null}:{})})});console.log(JSON.stringify({status:'GITHUB_ACQUISITION_VERIFIED',...receipt,destinationIntent:args.destination}));
113
124
  updateOperation({phase:'acquired',version:context.version,sourceCommit:context.sourceCommit});
114
125
  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);}
115
126
  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];
package/lib/acquire.mjs CHANGED
@@ -91,9 +91,10 @@ async function trustRoot(stage) {
91
91
  await updater.refresh();const info=await updater.getTargetInfo('trusted_root.json');if(!info)fail('GitHub 信任目标缺失');
92
92
  return json(fs.readFileSync(await updater.downloadTarget(info)));
93
93
  }
94
- async function verifiedAsset(context,asset,stage,trust,onProgress) {
94
+ async function verifiedAsset(context,asset,stage,trust,onProgress=()=>{},onDownloaded=()=>{}) {
95
95
  if(!asset||!Number.isSafeInteger(asset.size)||asset.size<=0||asset.size>250_000_000||!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(asset.name)||!/^sha256:[a-f0-9]{64}$/.test(asset.digest)||asset.browser_download_url!==`https://github.com/${policy.repository}/releases/download/${context.release.tag_name}/${asset.name}`)fail('资产元数据无效');
96
- const bytes=asset.size>10_000_000?await downloadLarge(asset.browser_download_url,asset.size,onProgress):download(asset.browser_download_url,asset.size+1);
96
+ const bytes=asset.size>10_000_000?await downloadLarge(asset.browser_download_url,asset.size,p=>onProgress({...p,asset:asset.name})):download(asset.browser_download_url,asset.size+1);
97
+ onDownloaded();
97
98
  if(bytes.length!==asset.size||`sha256:${hash(bytes)}`!==asset.digest)fail('下载长度或摘要不匹配');
98
99
  const proofs=api(`attestations/${asset.digest}?predicate_type=release&per_page=100`).attestations;
99
100
  if(!Array.isArray(proofs)||proofs.length>=100)fail('证明列表不完整或分页待核实');
@@ -152,7 +153,7 @@ export async function acquireRelease(context,stage,{onPhase=()=>{},onProgress=()
152
153
  if(release.repositoryId!==policy.repositoryId||release.sourceCommit!==context.sourceCommit||!/^[a-f0-9]{64}$/.test(release.candidateHash)||release.url!==`https://github.com/${policy.repository}/releases/download/${context.release.tag_name}/${assetName}`||!/^\d+\.\d+\.\d+$/.test(release.runtime?.version)||release.runtime.url!==`https://nodejs.org/dist/v${release.runtime.version}/node-v${release.runtime.version}-darwin-arm64.tar.gz`)fail('清单不能更换仓库、提交或官方运行时来源');
153
154
  const assets=context.release.assets.filter(x=>x.name===assetName&&x.size===release.bytes&&x.digest===`sha256:${release.sha256}`);if(assets.length!==1)fail('归档身份不匹配');
154
155
  onPhase('fetching-and-verifying-runtime');
155
- const archive=await verifiedAsset(context,assets[0],stage,trust,onProgress);
156
+ const archive=await verifiedAsset(context,assets[0],stage,trust,onProgress,()=>onPhase('verifying-runtime'));
156
157
  onPhase('extracting-and-validating');
157
158
  const listing=spawnSync('/usr/bin/tar',['-tzf',archive.file],{encoding:'utf8',maxBuffer:10_000_000});
158
159
  const types=spawnSync('/usr/bin/tar',['-tvzf',archive.file],{encoding:'utf8',maxBuffer:10_000_000});
@@ -7,7 +7,7 @@ export function acquireInWorker({version,stage,operationId,onContext=()=>{},onPh
7
7
  const interrupt=()=>{failure=Object.assign(Error('获取任务被中断;保留本次材料'),{code:'ACQUISITION_INTERRUPTED'});void worker.terminate();};
8
8
  process.once('SIGINT',interrupt);process.once('SIGTERM',interrupt);
9
9
  worker.on('message',event=>{
10
- if(event.type==='context'){context=event.context;onContext(context);}
10
+ if(event.type==='context'){context=event.context;onContext(context);worker.postMessage({type:'context-recorded'});}
11
11
  else if(event.type==='phase')onPhase(event.phase);
12
12
  else if(event.type==='progress')onProgress(event.download);
13
13
  else if(event.type==='complete')receipt=event.receipt;
@@ -5,7 +5,14 @@ import {inspectRelease, acquireRelease} from './acquire.mjs';
5
5
 
6
6
  try {
7
7
  const context = inspectRelease(workerData.version);
8
+ // The parent persists context atomically in the stage. Finish that write
9
+ // before checking that the stage contains only this operation's record.
10
+ const recorded = new Promise(resolve=>parentPort.once('message',message=>{
11
+ if(message.type!=='context-recorded')throw Error('获取上下文确认无效');
12
+ resolve();
13
+ }));
8
14
  parentPort.postMessage({type:'context',context});
15
+ await recorded;
9
16
  const receipt = await acquireRelease(context, workerData.stage, {
10
17
  operationId:workerData.operationId,
11
18
  onPhase:phase=>parentPort.postMessage({type:'phase',phase}),
@@ -0,0 +1,47 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import crypto from 'node:crypto';
4
+ import {plainPath} from './acquire.mjs';
5
+
6
+ export function classifyEntryEnvironment({platform,arch,nodeVersion,tools}){
7
+ const [major,minor]=String(nodeVersion||'').split('.').map(Number);
8
+ const supported=platform==='darwin'&&arch==='arm64';
9
+ const compatible=Number.isInteger(major)&&Number.isInteger(minor)&&(major>22||major===22&&minor>=9);
10
+ const missing=tools.filter(x=>!x.available).map(x=>x.path);
11
+ return{platform,arch,nodeVersion,supported,compatible,tools,state:!supported?'unsupported':!compatible?'environment-required':missing.length?'blocked':'ready',missing,sharedSettingsChanged:false};
12
+ }
13
+ export function inspectEntryEnvironment({purpose='acquire'}={}){
14
+ // Hash/proof verification uses Node crypto. System shasum belongs only to the
15
+ // no-Node preparation script, not an npm action or installed confirmation.
16
+ const requirements={discover:['/usr/bin/curl'],acquire:['/usr/bin/curl','/usr/bin/tar'],confirm:[],uninstall:[],resume:[]};
17
+ if(!Object.hasOwn(requirements,purpose))throw Error('未知环境检查动作');
18
+ const tools=requirements[purpose].map(file=>{let available=false;try{fs.accessSync(file,fs.constants.X_OK);available=fs.statSync(file).isFile();}catch{}return{path:file,available};});
19
+ const result={...classifyEntryEnvironment({platform:process.platform,arch:process.arch,nodeVersion:process.versions.node,tools}),purpose,entryRuntime:process.execPath,checkedAt:new Date().toISOString(),programRuntime:'随程序携带,不替换现有 Node'};
20
+ const receipt=path.resolve(path.dirname(process.execPath),'../..','environment-result.txt');
21
+ try{if(fs.existsSync(receipt)){
22
+ plainPath(receipt);const stat=fs.lstatSync(receipt);if(!stat.isFile()||stat.size>65536)throw Error('基础环境回执异常,保留并核实');
23
+ const fields=Object.fromEntries(fs.readFileSync(receipt,'utf8').trim().split('\n').map(line=>{const i=line.indexOf('=');return[line.slice(0,i),line.slice(i+1)];}));
24
+ const hash=crypto.createHash('sha256').update(fs.readFileSync(process.execPath)).digest('hex');
25
+ if(fields.state!=='prepared-and-rechecked'||fields.node!==process.execPath||fields.node_sha256!==hash||fields.node_version!==process.versions.node)throw Error('基础环境回执与当前运行文件不一致,不继续');
26
+ result.preparation={receipt,plan:fields.plan,state:fields.state,humanApproval:'由启动任务核验,本记录不是人类批准证明',retention:'获取器专用环境保留为缓存,不自动清理;不属于程序安装根'};
27
+ }}catch{result.state='blocked';result.preparation={receipt,state:'verification-required',reason:'基础环境回执与当前运行文件无法核实;保留材料,不继续'};}
28
+ return result;
29
+ }
30
+ export function inspectEntryDestination(input){
31
+ let destination=String(input||'').trim();
32
+ if((destination.startsWith('"')&&destination.endsWith('"'))||(destination.startsWith("'")&&destination.endsWith("'")))destination=destination.slice(1,-1);
33
+ plainPath(destination);
34
+ if(fs.existsSync(destination)&&(!fs.lstatSync(destination).isDirectory()||fs.readdirSync(destination).length))throw Error('安装目录已有内容或不是目录;请选择独立空目录,不覆盖已有文件');
35
+ const parent=path.dirname(destination);plainPath(parent);if(!fs.existsSync(parent)||!fs.lstatSync(parent).isDirectory())throw Error('安装目录的父目录必须存在');
36
+ fs.accessSync(parent,fs.constants.W_OK|fs.constants.X_OK);
37
+ const disk=fs.statfsSync(parent),availableBytes=Number(disk.bavail)*Number(disk.bsize);
38
+ if(!Number.isFinite(availableBytes)||availableBytes<=0)throw Error('无法确认可用空间;尚未下载或安装');
39
+ return{destination,parent,availableBytes,checkedAt:new Date().toISOString(),authority:'intent-only; runtime rechecks exact bytes and plan'};
40
+ }
41
+
42
+ // Intent preflight only. The installed engine repeats identity checks and seals
43
+ // the actual scope in the independently confirmed lifecycle plan.
44
+ export function inspectScopeIntent(kind, input, destination){
45
+ if(kind==='user'&&input==null)return {kind,projectRoot:null};
46
+ throw Error('新安装供当前用户的不同项目共用,不接受项目范围;已有项目安装不会自动迁移');
47
+ }
@@ -1,4 +1,12 @@
1
1
  import crypto from 'node:crypto';
2
+ import {inspectEntryDestination,inspectScopeIntent,inspectEntryEnvironment} from './environment-check.mjs';
3
+
4
+ // Fresh installs are shared by the current user. Reject stale project intent;
5
+ // never silently reinterpret it. Existing maintenance keeps its signed scope.
6
+ function scopeFields(value){
7
+ inspectScopeIntent(value.scopeKind===undefined?'user':value.scopeKind,value.projectRoot);
8
+ return {};
9
+ }
2
10
 
3
11
  // Only the exact child created by this invocation may supply an active view.
4
12
  // Browser input cannot name a URL, route, transport token or future plan.
@@ -31,7 +39,7 @@ export function createJourneyControl(readRecord, changed) {
31
39
  if(!selection&&result.body.session.sessionId!==event.sessionId)throw Error('确认会话不匹配');
32
40
  active={owner,type:selection?'selection':'manager',view:result.body};changed();
33
41
  if(selection&&choice){
34
- const selected=await request(owner,'__foundation/install/selection',{nonce:result.body.nonce,action:'select',destination:choice.destination,skillChoice:choice.skillChoice});
42
+ const selected=await request(owner,'__foundation/install/selection',{nonce:result.body.nonce,action:'select',destination:choice.destination,skillChoice:choice.skillChoice,...scopeFields(choice)});
35
43
  if(selected.status!==200){active.error=selected.body.message;choice=null;changed();}
36
44
  }
37
45
  },
@@ -50,17 +58,26 @@ export function createJourneyControl(readRecord, changed) {
50
58
  }
51
59
  if(body.action==='choose'&&resolveChoice){
52
60
  if(typeof body.destination!=='string'||!body.destination.trim()||!['selected','skipped'].includes(body.skillChoice))throw Error('请选择完整目录和 Skill 意向');
53
- choice={destination:body.destination,skillChoice:body.skillChoice};const resolve=resolveChoice;clearTimeout(choiceTimer);resolveChoice=null;rejectChoice=null;resolve(choice);changed();return {status:200,body:{state:'intent-selected'}};
61
+ scopeFields(body);
62
+ const destinationCheck=inspectEntryDestination(body.destination);
63
+ choice={destination:destinationCheck.destination,skillChoice:body.skillChoice,scopeKind:'user',projectRoot:null,destinationCheck};const resolve=resolveChoice;clearTimeout(choiceTimer);resolveChoice=null;rejectChoice=null;resolve(choice);changed();return {status:200,body:{state:'intent-selected'}};
54
64
  }
55
65
  if(!active)throw Error('当前没有可确认的计划;请等待或查询结果');
56
66
  const a=active;
57
67
  if(a.type==='selection'){
58
68
  if(!['select','cancel'].includes(body.action))throw Error('目录操作无效');
59
- const result=await request(a.owner,'__foundation/install/selection',{nonce:a.view.nonce,action:body.action,destination:body.destination,skillChoice:body.skillChoice});
69
+ const result=await request(a.owner,'__foundation/install/selection',body.action==='cancel'?{nonce:a.view.nonce,action:'cancel'}:{nonce:a.view.nonce,action:body.action,destination:body.destination,skillChoice:body.skillChoice,...scopeFields(body)});
60
70
  if(result.status!==200)a.error=result.body.message;changed();return result;
61
71
  }
62
72
  const s=a.view.session;
63
73
  if(body.sessionId!==s.sessionId||body.planHash!==s.planHash||body.managerNonce!==a.view.managerNonce||!['cancel-no-change',a.view.action].includes(body.action))throw Error('当前计划已变化或请求无效');
74
+ if(body.action!=='cancel-no-change'){
75
+ const environment=inspectEntryEnvironment({purpose:'confirm'});
76
+ // Keep the failed snapshot with this operation even if no mutation is
77
+ // forwarded; acquisition-only tools must not gate a verified plan.
78
+ Object.assign(readRecord(),{environment});changed({environment});
79
+ if(environment.state!=='ready')throw Error('执行前环境复检未通过;没有提交确认,请核实当前工具环境');
80
+ }
64
81
  const result=await request(a.owner,'__foundation/manager/confirm',{operationId:body.operationId,sessionId:s.sessionId,planHash:s.planHash,managerNonce:body.managerNonce,action:body.action});
65
82
  if(active===a&&result.body.state)a.view.session={...s,...result.body};changed();return result;
66
83
  }
@@ -1,4 +1,44 @@
1
1
  // Presentation only. Planned steps never grant execution authority.
2
+ export function lifecycleContent(record, observations) {
3
+ const kind=record.kind||'install',verb={install:'安装',update:'更新',uninstall:'卸载'}[kind]||'处理';
4
+ const programDone=record.programState==='completed'||observations.program?.state==='completed';
5
+ const registration=observations.register?.state,removal=observations.remove?.state;
6
+ const skipped=record.journeyContext?.skillChoice==='skipped';
7
+ const stepStates=Object.values(observations).map(x=>x?.state);
8
+ const cancelled=['cancelled','cancelled-no-install','shutdown-no-install'].includes(record.state)||record.terminal&&stepStates.includes('cancelled');
9
+ const expired=['expired','expired-no-install'].includes(record.state)||record.terminal&&stepStates.includes('expired');
10
+ const environmentBlocked=record.environment&&record.environment.state!=='ready';
11
+ const anyCompleted=Object.entries(observations).some(([key,value])=>['program','material','register','remove'].includes(key)&&value?.state==='completed');
12
+ let title=verb+' Foundation';
13
+ if(record.terminal){
14
+ if(programDone)title='Foundation 已'+verb;
15
+ else if(cancelled)title='已取消'+verb;
16
+ else if(expired)title=verb+'确认已到期';
17
+ else if(environmentBlocked)title='运行环境需要处理';
18
+ else if(record.state==='failed'||stepStates.includes('failed'))title=verb+'未成功';
19
+ else title=anyCompleted?'部分步骤已完成':'操作结果待确认';
20
+ if(programDone&&kind!=='uninstall'&&!skipped&&!record.skillRegistered)title+=';对话功能'+(['cancelled','skipped'].includes(registration)?'未启用':registration==='failed'?'未处理成功':'尚未完成');
21
+ }
22
+ let program=programDone?'程序'+verb+'已完成。'+(kind==='uninstall'?'卸载结果已保存。':record.runtimeHealth==='passed'?'已检查,可以正常打开。':'能否正常打开仍需检查。')
23
+ :record.installationWrites==='none'||['not-started','cancelled','expired'].includes(record.programState)||['cancelled','expired'].includes(observations.program?.state)?'尚未'+(kind==='install'?'安装 Foundation':'执行程序'+verb)+'。':'程序是否发生变化仍需查看本次结果,请勿重复执行。';
24
+ if(programDone&&kind==='update'&&record.programResult?.cleanup)program+=record.programResult.cleanup.state==='completed'?'本次下载暂存已按计划清理。':'部分下载文件已保留,不影响已完成的更新。';
25
+ const skill=kind==='uninstall'?(removal==='completed'?'已处理本安装的对话功能文件;修改或未知文件按计划保留。':removal?'对话功能尚未移除成功,原文件保留。':record.hadSkill===false?'本安装没有已登记的对话功能,此次未删除其他 Skill。':'尚未确认是否需要移除对话功能。')
26
+ :record.skillRegistered===true?'对话功能文件已就位,请在新 Codex 对话中尝试“打开 Foundation”。'
27
+ :skipped?(kind==='update'?'本次未新增对话功能。':'本次不启用 Codex 对话功能。')
28
+ :['cancelled','skipped'].includes(registration)?'本次未启用 Codex 对话功能。'
29
+ :registration==='failed'?'对话功能未处理成功;只需检查这一项,不必重装程序。'
30
+ :record.terminal&&!programDone&&(cancelled||expired)?'本次未启用 Codex 对话功能。'
31
+ :observations.material?.state==='completed'?'Skill 已准备,还需要你确认启用到 Codex。'
32
+ :record.journeyContext?.skillChoice==='selected'?'已选择对话功能,仍需单独确认后才能启用。':'可选择是否启用 Codex 对话功能。';
33
+ const description=record.terminal?program+' '+skill:kind==='install'?'给当前用户安装一份 Foundation,不同项目按需使用,项目资料各自保管。'+(skipped?'本次不启用对话功能。':'对话功能可选,需另外确认。')
34
+ :kind==='update'?'更新这份 Foundation,具体保留范围见本步计划。'+(record.hadSkill===true?'已有对话功能会另行询问是否更新。':record.hadSkill===false?'本次不新增对话功能。':'正在检查已有对话功能。')
35
+ :'只移除本次确认的 Foundation 文件,不清空整个文件夹。'+(removal==='completed'?'对话功能已按前一步结果处理,现在确认程序卸载。':record.hadSkill===true?'先单独确认移除它的对话功能。':record.hadSkill===false?'本安装未登记对话功能,不删除其他 Skill。':'正在检查是否存在关联的对话功能。');
36
+ const environment=environmentBlocked?'运行环境检查未通过。'+(record.environment.missing?.length?'缺少:'+record.environment.missing.join('、')+'。':'')+(record.environment.preparation?.reason||'请在当前 Codex 对话中检查所需环境;不会自动安装或更改系统工具。'):'环境已就绪。';
37
+ const summaries={select:'已确认本次软件位置;项目仍在各自的位置。',acquire:'下载文件已通过来源与完整性检查。',program,material:'Skill 已准备;是否启用到 Codex,请看后续结果。',register:skill,remove:skill,health:'已检查程序,能够正常打开。',environment,cleanup:'本次下载文件已按结果处理;未能安全删除的文件保留。'};
38
+ const next=environmentBlocked?environment:record.terminal&&programDone?(kind==='uninstall'?'保留本次卸载结果;其中列有剩余文件和缓存清理说明。':record.skillRegistered?'请在新 Codex 对话中尝试“打开 Foundation”;使用具体项目时再单独接入。':skipped?'可从程序安装位置重新打开 Foundation。需要对话功能时,再在当前对话中提出。':'在当前对话中说明只继续未完成的对话功能;先检查结果,不重复安装程序。'):record.terminal&&(cancelled||expired)?'本次不会继续执行。如仍需'+verb+',请在当前对话中重新提出,并核对新的计划。':record.next;
39
+ return {title,program,skill,description,environment,summaries,next,project:kind==='install'?'本次没有接入任何项目;以后在需要的项目中单独确认。':'项目文件仍按各自项目管理;本次不会自动接入其他项目。'};
40
+ }
41
+
2
42
  export function journeyView({id,kind='install',observations={},skillChoice='undecided',includeAcquisition=false,includeSelection=false,includeHealth=true,includeCleanup=false,includeSkillRemoval=false}) {
3
43
  const labels={acquire:'获取并核验运行文件',select:'选择安装目录',program:({install:'安装程序',update:'更新程序',uninstall:'移除程序'})[kind]||'执行当前维护',health:'验证稳定入口',cleanup:'处理本次暂存',material:'准备对话能力材料',register:'注册到 Codex',remove:'移除 Codex 注册'};
4
44
  const statusLabels={completed:'已完成',pending:'待确认',planned:'尚待处理',running:'进行中',executing:'进行中',consumed:'进行中',failed:'失败',cancelled:'已取消',expired:'已过期',skipped:'已跳过',undecided:'可选,待选择',retained:'已处理,保留部分材料','verification-required':'待核实'};
@@ -30,6 +30,7 @@ export async function followMaintenance({operation,kind,candidate,env,onChange,j
30
30
  // validates its receipt and files. It does not authorize removal.
31
31
  const registration=plainPath(path.join(root,'state/codex-skill-registration.json'));
32
32
  const hadSkill=fs.existsSync(registration);
33
+ onChange({hadSkill});
33
34
  let previousPlanRef=null;
34
35
  const steps={};
35
36
  onChange({kind,currentVersion:current.version,installId:current.identity.installId,previousCandidateHash:current.candidateHash,journeyContext:{id:operation.operationId,skillChoice:kind==='update'&&hadSkill?'selected':'skipped'},next:hadSkill?(kind==='update'?'先确认程序更新,再确认刷新完整归属的 Codex 文件;未知或修改文件保留。':'先核对并确认解除已关联的 Codex 副本,再继续程序卸载;未知或修改文件保留。'):'核对程序操作;本次不会新增 Codex Skill。'});
@@ -1,20 +1,37 @@
1
1
  import http from 'node:http';
2
2
  import crypto from 'node:crypto';
3
- import {journeyView} from './journey-view.mjs';
3
+ import {journeyView,lifecycleContent} from './journey-view.mjs';
4
4
  import {singlePageDocument} from './single-page-view.mjs';
5
5
 
6
- export function downloadText(download) {
6
+ export function downloadText(download, compact = false) {
7
7
  if(!download||!Number.isFinite(download.downloadedBytes)||download.downloadedBytes<0)return '';
8
8
  const amount=n=>(n/1048576).toFixed(2)+' MiB';
9
9
  const known=Number.isFinite(download.totalBytes)&&download.totalBytes>0;
10
- return '已接收 '+amount(download.downloadedBytes)+(known?' / '+amount(download.totalBytes)+(download.downloadedBytes<=download.totalBytes?' · '+Math.floor(download.downloadedBytes/download.totalBytes*100)+'%':'(长度待核实)'):'(总量未知)');
10
+ const valid=known&&download.downloadedBytes<=download.totalBytes;
11
+ const percent=valid&&download.downloadedBytes>0?Math.floor(download.downloadedBytes/download.totalBytes*100):null;
12
+ if(compact)return (percent===null?'已下载 ':'下载 '+percent+'% · ')+amount(download.downloadedBytes)+(known?' / '+amount(download.totalBytes)+(valid?'':'(长度待核实)'):'');
13
+ return '已接收 '+amount(download.downloadedBytes)+(known?' / '+amount(download.totalBytes)+(valid?(percent===null?'':' · '+percent+'%'):'(长度待核实)'):'(总量未知)');
14
+ }
15
+
16
+ export function downloadStatus(record) {
17
+ if(record.kind==='uninstall')return '';
18
+ if(record.terminal)return record.state==='failed'&&['discovering','verifying-trust','fetching-and-verifying-catalog','fetching-and-verifying-runtime','verifying-runtime','extracting-and-validating'].includes(record.phase)?'下载检查失败':'本次获取已结束';
19
+ if(record.phase==='fetching-and-verifying-runtime'){
20
+ const d=record.download,prefix=Number.isSafeInteger(d?.attempt)&&d.attempt>1?'重试 '+d.attempt+' · ':'';
21
+ if(d?.downloadedBytes===0)return prefix+'等待下载';
22
+ if(Number.isFinite(d?.totalBytes)&&d.totalBytes>0&&d.downloadedBytes===d.totalBytes)return '正在检查文件';
23
+ return prefix+(downloadText(d,true)||'等待下载');
24
+ }
25
+ return ({discovering:'正在查询版本','verifying-trust':'正在检查来源','fetching-and-verifying-catalog':'正在检查清单','verifying-runtime':'正在检查文件','extracting-and-validating':'正在展开检查','acquired':'检查完成'})[record.phase]||'';
11
26
  }
12
27
 
13
28
  export function acquisitionProgress(record) {
14
- 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:'安装结果已返回'};
29
+ const phases={discovering:'查询正式发行','verifying-trust':'核验发行来源','fetching-and-verifying-catalog':'获取并核验发行清单','fetching-and-verifying-runtime':'正在下载运行文件','verifying-runtime':'正在检查文件摘要与发行证明','extracting-and-validating':'展开并检查文件','acquired':'获取验证完成','starting-confirmation-service':'准备目录选择与确认页','selecting-directory':'等待你选择目录','awaiting-confirmation':'等待你确认安装',executing:'正在安装','runtime-ended':'读取安装结果',finished:'安装结果已返回'};
15
30
  const terminal=record.terminal;
16
31
  const acquired=['acquired','starting-confirmation-service','selecting-directory','directory-selection-ended','awaiting-confirmation','executing','runtime-ended','finished'].includes(record.phase);
17
- const observations={acquire:{state:acquired?'completed':terminal?'failed':'running',evidence:record.resultFile}};
32
+ const beforeAcquisition=['checking-environment','choosing-intent'].includes(record.phase);
33
+ const observations={acquire:{state:acquired?'completed':beforeAcquisition?'planned':terminal?'failed':'running',evidence:record.resultFile}};
34
+ if(record.phase==='choosing-intent')observations.select={state:record.state==='cancelled-no-install'?'cancelled':record.state==='expired-no-install'?'expired':'pending'};
18
35
  if(record.phase==='selecting-directory')observations.select={state:'pending'};
19
36
  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};
20
37
  if(['awaiting-confirmation','executing','runtime-ended','finished'].includes(record.phase))observations.select={state:'completed',evidence:record.selectionId};
@@ -33,9 +50,10 @@ export function acquisitionProgress(record) {
33
50
  const journey=journeyView({id:record.operationId,kind,includeAcquisition:kind!=='uninstall',includeSelection:kind==='install',includeHealth:kind!=='uninstall',includeSkillRemoval:Boolean(observations.remove),observations,skillChoice:record.journeyContext?.skillChoice||'undecided'});
34
51
  if(record.terminal&&record.state==='partial'){journey.ended=false;journey.title=record.programState==='completed'?'程序已完成,Codex 接入未完成':'本次操作尚未全部完成';journey.summary=record.next;}
35
52
  const verb=kind==='uninstall'?'卸载':kind==='update'?'更新':'安装';
53
+ const content=lifecycleContent(record,observations);
36
54
  Object.assign(phases,{'awaiting-confirmation':'等待你确认'+verb,executing:'正在'+verb,'runtime-ended':'读取'+verb+'结果',finished:verb+'结果已返回'});
37
55
  if(record.terminal&&record.state==='partial'&&record.programState==='completed'&&kind==='update')journey.title='程序已更新,Skill 尚未更新';
38
- return {journey,operationId:record.operationId,title:journey.title,phase:({'skill-confirmation':'等待你确认 Codex 操作','skill-executing':'正在处理 Codex 对话能力'})[record.phase]||phases[record.phase]||'正在核实本次操作',state:record.state,version:record.currentVersion&&kind==='update'?record.currentVersion+' → '+record.version:record.version||record.currentVersion||null,download:record.download||null,program:record.programState==='completed'?'程序'+verb+'已完成;'+(kind==='uninstall'?'结果由独立回执保留':record.runtimeHealth==='passed'?'稳定入口健康已核验':'健康待核实'):record.installationWrites==='none'?'尚未执行程序操作':'程序结果以同次记录为准',skill:kind==='uninstall'?(observations.remove?.state==='completed'?'已解除已归属 Codex 注册;修改和未知文件按计划保留':'本次没有已核实的注册移除结果'):record.skillRegistered===true?'Skill 文件与归属已核验;新对话识别另验':record.journeyContext?.skillChoice==='skipped'?'本次不接入 Codex':record.journeyContext?.skillChoice==='selected'?'已选择接入 Codex;仅在分别确认后执行':'Codex 接入可选,尚未选择',project:'未自动接入项目',installationRoot:record.installationRoot||null,skillDestination:record.skillDestination||null,next:record.next||(record.terminal&&record.state==='completed'&&record.journeyContext?.skillChoice==='skipped'?'本次已跳过 Codex 接入;程序操作已完成,项目另行确认。':journey.summary),nextUrl:record.terminal?(kind!=='uninstall'&&record.workbench?.state==='ready'?record.workbench.url:null):record.confirmationUrl||null,nextLabel:record.terminal?'打开已安装工作台':record.phase?.startsWith('skill-')?'查看 Codex 精确确认':kind==='install'?'继续到目录选择 / 本人确认页':'查看'+verb+'确认',resultFile:record.resultFile||null,terminal,diagnostic:record.diagnostic||null};
56
+ return {content,journey,operationId:record.operationId,title:journey.title,phase:({'skill-confirmation':'等待你确认 Codex 操作','skill-executing':'正在处理 Codex 对话能力'})[record.phase]||phases[record.phase]||'正在核实本次操作',state:record.state,version:record.currentVersion&&kind==='update'?record.currentVersion+' → '+record.version:record.version||record.currentVersion||null,download:record.download||null,downloadStatus:downloadStatus(record),program:record.programState==='completed'?'程序'+verb+'已完成;'+(kind==='uninstall'?'结果由独立回执保留':record.runtimeHealth==='passed'?'稳定入口健康已核验':'健康待核实'):record.installationWrites==='none'?'尚未执行程序操作':'程序结果以同次记录为准',skill:kind==='uninstall'?(observations.remove?.state==='completed'?'已解除已归属 Codex 注册;修改和未知文件按计划保留':'本次没有已核实的注册移除结果'):record.skillRegistered===true?'Skill 文件与归属已核验;新对话识别另验':record.journeyContext?.skillChoice==='skipped'?'本次不接入 Codex':record.journeyContext?.skillChoice==='selected'?'已选择接入 Codex;仅在分别确认后执行':'Codex 接入可选,尚未选择',project:'未自动接入项目',installationRoot:record.installationRoot||null,skillDestination:record.skillDestination||null,next:record.next||(record.terminal&&record.state==='completed'&&record.journeyContext?.skillChoice==='skipped'?'本次已跳过 Codex 接入;程序操作已完成,项目另行确认。':journey.summary),nextUrl:record.terminal?(kind!=='uninstall'&&record.workbench?.state==='ready'?record.workbench.url:null):record.confirmationUrl||null,nextLabel:record.terminal?'打开已安装工作台':record.phase?.startsWith('skill-')?'查看 Codex 精确确认':kind==='install'?'继续到目录选择 / 本人确认页':'查看'+verb+'确认',resultFile:record.resultFile||null,terminal,diagnostic:record.diagnostic||null};
39
57
  }
40
58
 
41
59
  // A bounded, read-only loopback view over the existing in-memory operation.
@@ -1,4 +1,5 @@
1
1
  // Product-area CSS transplanted from the approved 040 reference.
2
2
  // Source SHA-256: e9949cc0d67e979b0297ca654eda1f163f2178b3338d4c4cf3ea9363e3cd8644
3
3
  // Demo-only selectors remain inert; there are no demo controls in production.
4
- export const singlePageStyle = "#foundation-flow-demo{--fp-bg:light-dark(#fff,#191b20);--fp-soft:light-dark(#f7f8fa,#23262c);--fp-text:light-dark(#20252d,#eff1f5);--fp-muted:light-dark(#606a78,#adb5c3);--fp-line:light-dark(#e5e8ee,#383d46);--fp-accent:light-dark(#315ee8,#98b3ff);--fp-active:light-dark(#f3f6ff,#232f48);--fp-good:light-dark(#23784c,#8ddcb1);--fp-error:light-dark(#b33434,#ffadad);font-family:Inter,-apple-system,BlinkMacSystemFont,\"Segoe UI\",sans-serif;color:var(--fp-text);font-size:14px;line-height:1.6;color-scheme:light dark}\n#foundation-flow-demo *{box-sizing:border-box}#foundation-flow-demo [hidden]{display:none!important}#foundation-flow-demo button,#foundation-flow-demo input,#foundation-flow-demo select{font:inherit;color:inherit}#foundation-flow-demo button,#foundation-flow-demo select{cursor:pointer}#foundation-flow-demo button{border:1px solid var(--fp-line);background:var(--fp-bg);border-radius:7px;padding:9px 15px;min-height:42px}#foundation-flow-demo button:disabled{opacity:.55;cursor:default}#foundation-flow-demo .demo-tools{display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin-bottom:14px;color:var(--fp-muted);font-size:12px}#foundation-flow-demo .demo-tools label{margin-left:auto;display:flex;align-items:center;gap:8px}#foundation-flow-demo select{padding:7px;border:1px solid var(--fp-line);border-radius:6px;background:var(--fp-bg)}#foundation-flow-demo .product{background:var(--fp-bg);border:1px solid var(--fp-line);border-radius:14px;overflow:hidden}#foundation-flow-demo .brand{display:flex;align-items:center;gap:9px;padding:18px 26px;border-bottom:1px solid var(--fp-line);font-weight:500}#foundation-flow-demo .brand-mark{display:grid;place-items:center;width:26px;height:26px;border-radius:6px;background:var(--fp-text);color:var(--fp-bg)}#foundation-flow-demo .private-label{margin-left:auto;font-size:12px;color:var(--fp-muted);font-weight:400}#foundation-flow-demo .overview{padding:24px 26px 20px}#foundation-flow-demo h1{font-size:25px;font-weight:500;line-height:1.3;margin:5px 0 8px}#foundation-flow-demo p{margin:6px 0}#foundation-flow-demo .eyebrow{color:var(--fp-accent);font-size:12px;font-weight:500}#foundation-flow-demo #flow-description{color:var(--fp-muted)}#foundation-flow-demo .metadata{display:flex;flex-direction:column;gap:4px;margin:15px 0;color:var(--fp-muted);font-size:12px;overflow-wrap:anywhere}#foundation-flow-demo .progress-label{display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;font-size:12px;margin-bottom:8px}#foundation-flow-demo #flow-status{color:var(--fp-accent)}#foundation-flow-demo .track{height:5px;background:var(--fp-soft);border-radius:4px;overflow:hidden}#foundation-flow-demo #flow-bar{height:100%;background:var(--fp-accent);width:0;transition:width .2s}#foundation-flow-demo .steps{list-style:none;padding:0 26px;margin:0}#foundation-flow-demo .step{border-top:1px solid var(--fp-line);padding:15px 0}#foundation-flow-demo .step.current{background:var(--fp-active);border:1px solid var(--fp-line);border-radius:10px;padding:16px;margin:4px -16px 8px}#foundation-flow-demo .step-top{display:flex;align-items:center;gap:12px}#foundation-flow-demo .step-number{flex:none;border:1px solid var(--fp-line);border-radius:50%;width:25px;height:25px;display:grid;place-items:center;font-size:12px;color:var(--fp-muted)}#foundation-flow-demo .done .step-number{color:var(--fp-good);border-color:transparent;background:var(--fp-soft)}#foundation-flow-demo .current .step-number{background:var(--fp-accent);color:var(--fp-bg);border-color:transparent}#foundation-flow-demo .step-title{font-weight:500;flex:1}#foundation-flow-demo .step-state{font-size:12px;color:var(--fp-muted)}#foundation-flow-demo .done .step-state{color:var(--fp-good)}#foundation-flow-demo .step-body{margin:12px 0 0 37px;color:var(--fp-muted)}#foundation-flow-demo .field{display:block;margin:13px 0 5px;color:var(--fp-text)}#foundation-flow-demo input[type=text]{width:100%;min-width:0;font-size:16px;background:var(--fp-bg);border:1px solid var(--fp-line);border-radius:7px;padding:10px}#foundation-flow-demo .check{display:flex;align-items:flex-start;gap:9px;margin:14px 0;color:var(--fp-text)}#foundation-flow-demo .check input{margin-top:6px;accent-color:var(--fp-accent)}#foundation-flow-demo .hint{font-size:12px;color:var(--fp-muted);overflow-wrap:anywhere}#foundation-flow-demo .actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:17px}#foundation-flow-demo .primary{background:var(--fp-accent);border-color:var(--fp-accent);color:var(--fp-bg);font-weight:500}#foundation-flow-demo .danger{background:var(--fp-error);border-color:var(--fp-error);color:var(--fp-bg)}#foundation-flow-demo .error{color:var(--fp-error);font-size:13px;margin-top:6px}#foundation-flow-demo .facts{border-left:2px solid var(--fp-line);padding-left:12px;margin:12px 0;overflow-wrap:anywhere}#foundation-flow-demo .result{margin:14px 26px 24px;padding:18px;background:var(--fp-soft);border-radius:10px}#foundation-flow-demo .result h2{font-size:18px;font-weight:500;margin:0 0 8px}#foundation-flow-demo footer{padding:17px 26px;border-top:1px solid var(--fp-line);color:var(--fp-muted);font-size:12px}#foundation-flow-demo summary{cursor:pointer}#foundation-flow-demo .completed-detail{margin-left:37px;font-size:12px;color:var(--fp-muted)}\n@media(max-width:480px){#foundation-flow-demo .overview,#foundation-flow-demo .brand,#foundation-flow-demo footer{padding-left:17px;padding-right:17px}#foundation-flow-demo .steps{padding:0 17px}#foundation-flow-demo .step.current{margin-left:-8px;margin-right:-8px;padding:12px 8px}#foundation-flow-demo .step-body{margin-left:0}#foundation-flow-demo .step-top{gap:8px}#foundation-flow-demo .step-state{max-width:82px;text-align:right}#foundation-flow-demo .demo-tools label{margin-left:0}#foundation-flow-demo .result{margin:14px 17px}#foundation-flow-demo h1{font-size:23px}}\n@media(prefers-reduced-motion:reduce){#foundation-flow-demo #flow-bar{transition:none}}";
4
+ // C5: download metadata wraps within the existing right-hand status slot.
5
+ export const singlePageStyle = "#foundation-flow-demo{--fp-bg:light-dark(#fff,#191b20);--fp-soft:light-dark(#f7f8fa,#23262c);--fp-text:light-dark(#20252d,#eff1f5);--fp-muted:light-dark(#606a78,#adb5c3);--fp-line:light-dark(#e5e8ee,#383d46);--fp-accent:light-dark(#315ee8,#98b3ff);--fp-active:light-dark(#f3f6ff,#232f48);--fp-good:light-dark(#23784c,#8ddcb1);--fp-error:light-dark(#b33434,#ffadad);font-family:Inter,-apple-system,BlinkMacSystemFont,\"Segoe UI\",sans-serif;color:var(--fp-text);font-size:14px;line-height:1.6;color-scheme:light dark}\n#foundation-flow-demo *{box-sizing:border-box}#foundation-flow-demo [hidden]{display:none!important}#foundation-flow-demo button,#foundation-flow-demo input,#foundation-flow-demo select{font:inherit;color:inherit}#foundation-flow-demo button,#foundation-flow-demo select{cursor:pointer}#foundation-flow-demo button{border:1px solid var(--fp-line);background:var(--fp-bg);border-radius:7px;padding:9px 15px;min-height:42px}#foundation-flow-demo button:disabled{opacity:.55;cursor:default}#foundation-flow-demo .demo-tools{display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin-bottom:14px;color:var(--fp-muted);font-size:12px}#foundation-flow-demo .demo-tools label{margin-left:auto;display:flex;align-items:center;gap:8px}#foundation-flow-demo select{padding:7px;border:1px solid var(--fp-line);border-radius:6px;background:var(--fp-bg)}#foundation-flow-demo .product{background:var(--fp-bg);border:1px solid var(--fp-line);border-radius:14px;overflow:hidden}#foundation-flow-demo .brand{display:flex;align-items:center;gap:9px;padding:18px 26px;border-bottom:1px solid var(--fp-line);font-weight:500}#foundation-flow-demo .brand-mark{display:grid;place-items:center;width:26px;height:26px;border-radius:6px;background:var(--fp-text);color:var(--fp-bg)}#foundation-flow-demo .private-label{margin-left:auto;font-size:12px;color:var(--fp-muted);font-weight:400}#foundation-flow-demo .overview{padding:24px 26px 20px}#foundation-flow-demo h1{font-size:25px;font-weight:500;line-height:1.3;margin:5px 0 8px}#foundation-flow-demo p{margin:6px 0}#foundation-flow-demo .eyebrow{color:var(--fp-accent);font-size:12px;font-weight:500}#foundation-flow-demo #flow-description{color:var(--fp-muted)}#foundation-flow-demo .metadata{display:flex;flex-direction:column;gap:4px;margin:15px 0;color:var(--fp-muted);font-size:12px;overflow-wrap:anywhere}#foundation-flow-demo .progress-label{display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;font-size:12px;margin-bottom:8px}#foundation-flow-demo #flow-status{color:var(--fp-accent)}#foundation-flow-demo .track{height:5px;background:var(--fp-soft);border-radius:4px;overflow:hidden}#foundation-flow-demo #flow-bar{height:100%;background:var(--fp-accent);width:0;transition:width .2s}#foundation-flow-demo .steps{list-style:none;padding:0 26px;margin:0}#foundation-flow-demo .step{border-top:1px solid var(--fp-line);padding:15px 0}#foundation-flow-demo .step.current{background:var(--fp-active);border:1px solid var(--fp-line);border-radius:10px;padding:16px;margin:4px -16px 8px}#foundation-flow-demo .step-top{display:flex;align-items:center;gap:12px}#foundation-flow-demo .step-number{flex:none;border:1px solid var(--fp-line);border-radius:50%;width:25px;height:25px;display:grid;place-items:center;font-size:12px;color:var(--fp-muted)}#foundation-flow-demo .done .step-number{color:var(--fp-good);border-color:transparent;background:var(--fp-soft)}#foundation-flow-demo .current .step-number{background:var(--fp-accent);color:var(--fp-bg);border-color:transparent}#foundation-flow-demo .step-title{font-weight:500;flex:1;min-width:0;overflow-wrap:anywhere}#foundation-flow-demo .step-state{font-size:12px;color:var(--fp-muted);max-width:48%;text-align:right;overflow-wrap:anywhere}#foundation-flow-demo .done .step-state{color:var(--fp-good)}#foundation-flow-demo .step-body{margin:12px 0 0 37px;color:var(--fp-muted)}#foundation-flow-demo .field{display:block;margin:13px 0 5px;color:var(--fp-text)}#foundation-flow-demo input[type=text]{width:100%;min-width:0;font-size:16px;background:var(--fp-bg);border:1px solid var(--fp-line);border-radius:7px;padding:10px}#foundation-flow-demo .check{display:flex;align-items:flex-start;gap:9px;margin:14px 0;color:var(--fp-text)}#foundation-flow-demo .check input{margin-top:6px;accent-color:var(--fp-accent)}#foundation-flow-demo .hint{font-size:12px;color:var(--fp-muted);overflow-wrap:anywhere}#foundation-flow-demo .actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:17px}#foundation-flow-demo .primary{background:var(--fp-accent);border-color:var(--fp-accent);color:var(--fp-bg);font-weight:500}#foundation-flow-demo .danger{background:var(--fp-error);border-color:var(--fp-error);color:var(--fp-bg)}#foundation-flow-demo .error{color:var(--fp-error);font-size:13px;margin-top:6px}#foundation-flow-demo .facts{border-left:2px solid var(--fp-line);padding-left:12px;margin:12px 0;overflow-wrap:anywhere}#foundation-flow-demo .result{margin:14px 26px 24px;padding:18px;background:var(--fp-soft);border-radius:10px}#foundation-flow-demo .result h2{font-size:18px;font-weight:500;margin:0 0 8px}#foundation-flow-demo footer{padding:17px 26px;border-top:1px solid var(--fp-line);color:var(--fp-muted);font-size:12px}#foundation-flow-demo summary{cursor:pointer}#foundation-flow-demo .completed-detail{margin-left:37px;font-size:12px;color:var(--fp-muted)}\n@media(max-width:480px){#foundation-flow-demo .overview,#foundation-flow-demo .brand,#foundation-flow-demo footer{padding-left:17px;padding-right:17px}#foundation-flow-demo .steps{padding:0 17px}#foundation-flow-demo .step.current{margin-left:-8px;margin-right:-8px;padding:12px 8px}#foundation-flow-demo .step-body{margin-left:0}#foundation-flow-demo .step-top{gap:8px}#foundation-flow-demo .step-state{max-width:82px;text-align:right}#foundation-flow-demo .demo-tools label{margin-left:0}#foundation-flow-demo .result{margin:14px 17px}#foundation-flow-demo h1{font-size:23px}}\n@media(prefers-reduced-motion:reduce){#foundation-flow-demo #flow-bar{transition:none}}";
@@ -7,16 +7,17 @@ export function singlePageDocument(csrf) {
7
7
 
8
8
  function singlePageClient(csrf) {
9
9
  const q=s=>document.querySelector(s),esc=s=>String(s??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
10
- let last=null,busy=false,revision=null,stopped=false;
10
+ let last=null,busy=false,revision=null,stopped=false,formIdentity=null;
11
11
  const verbs={install:'安装',update:'更新',uninstall:'卸载'};
12
12
  function cleanupText(session){const c=session?.hostCleanup;if(!c)return '';return '<div class="facts"><p>更新成功并通过健康检查后,清理本次下载的归档和展开候选。</p><p>清理位置:'+esc(c.root)+'</p><p>范围:'+esc(c.files?.length??'待核实')+' 个文件;'+(Number.isFinite(c.bytes)?(c.bytes/1048576).toFixed(2)+' MiB':'大小待核实')+'</p><p>保留获取回执、验证材料、回退版本、项目和未知或已修改文件;仍在使用的材料不会强删。</p></div>';}
13
13
  function show(p){
14
- last=p;const r=p.record,v=p.view,kind=r.kind||'install',verb=verbs[kind],choice=r.phase==='choosing-intent';
14
+ last=p;const r=p.record,v=p.view,c=p.progress.content,kind=r.kind||'install',verb=verbs[kind],choice=r.phase==='choosing-intent'&&!r.terminal;
15
15
  const titles={select:'选择安装位置',acquire:kind==='update'?'下载并检查新版':'下载并检查文件',program:verb+' Foundation',material:'准备安装 Skill',register:kind==='update'?'更新 Codex 中的 Skill':'将 Skill 安装到 Codex',remove:'移除 Codex 中的 Skill',health:'检查'+verb+'结果','optional-skill':'Foundation Skill'};
16
16
  const stateLabels={failed:'本步失败',cancelled:'已取消',expired:'已过期','verification-required':'结果待核实',running:'正在执行',executing:'正在执行',consumed:'正在执行',undecided:'可选,待选择'};
17
17
  const order=kind==='uninstall'?['remove','program']:['select','acquire','program','material','register','optional-skill','health'];
18
18
  const steps=p.progress.journey.steps.map(s=>({...s})).sort((a,b)=>order.indexOf(a.key)-order.indexOf(b.key));
19
19
  if(choice)for(const s of steps)s.state=s.key==='select'?'pending':'planned';
20
+ if(r.environment)steps.unshift({key:'environment',title:'检查运行环境',state:r.environment.state==='ready'?'completed':'failed',evidence:(r.environment.preparation?'对话准备的基础环境已复检;':'复用现有入口环境;')+r.environment.platform+' '+r.environment.arch+';入口 Node '+r.environment.nodeVersion+';程序使用随包运行时,不修改共享设置'+(r.environment.preparation?'。独立环境回执:'+r.environment.preparation.receipt+';缓存不自动清理':'')});
20
21
  if(r.intentSelected){const s=steps.find(s=>s.key==='select');if(s)s.state='completed';}
21
22
  let active=choice?'select':v?.type==='selection'?'select':v?.session?.capabilityId?(v.session.operation==='install'?'material':v.session.operation==='uninstall'?'remove':'register'):v?.session?'program':steps.find(s=>!['completed','skipped','retained'].includes(s.state))?.key;
22
23
  // The final result check must not look finished while a chosen Skill step
@@ -26,31 +27,44 @@ function singlePageClient(csrf) {
26
27
  if(r.terminal)active=null;
27
28
  const executing=['executing','consumed'].includes(v?.session?.state)||['executing','skill-executing'].includes(r.phase);
28
29
  const count=steps.filter(s=>['completed','skipped','retained'].includes(s.state)).length;
29
- q('#flow-title').textContent=r.terminal?(r.state==='completed'?'Foundation '+verb+'完成':'本次'+verb+'未全部完成'):verb+' Foundation';
30
+ q('#flow-title').textContent=c.title;
30
31
  q('#flow-eyebrow').textContent=r.terminal?'本次结果':executing?'正在执行':busy?'正在提交请求':v||choice?'等待你的操作':'正在进行';
31
- q('#flow-description').textContent=kind==='install'?'安装程序和 Skill,让 Codex 可以使用 Foundation。':kind==='update'?'更新程序和已有 Skill,保留你的项目与制作资料。':'移除 Foundation 和它的 Skill,保留你的项目与制作资料。';
32
+ q('#flow-description').textContent=c.description;
32
33
  q('#flow-version').textContent='版本:'+(p.progress.version||'待核实');q('#flow-destination').textContent='程序位置:'+(r.installationRoot||r.destinationIntent||'等待选择');
33
34
  q('#flow-count').textContent='已处理 '+count+' / '+steps.length+' 步';q('#flow-status').textContent=executing?'正在执行当前步骤':busy?'正在提交请求':r.terminal?(r.state==='completed'?'本次流程已完成':'查看未完成项'):('当前:'+(titles[active]||p.progress.phase));
34
35
  const percent=steps.length?count/steps.length*100:0;q('#flow-bar').style.width=percent+'%';q('.track').setAttribute('aria-valuenow',String(Math.round(percent)));
35
36
  const key=JSON.stringify([active,v?.session?.sessionId,v?.session?.state,v?.selectionId,r.terminal,steps.map(s=>s.state),v?.error]);
36
37
  if(key!==revision&&!busy){
37
- revision=key;
38
+ const identity=JSON.stringify([r.operationId,active,v?.session?.sessionId]);
39
+ const previous=q('#current-form'),draft=formIdentity===identity&&previous?{destination:previous.elements.destination?.value,skill:previous.elements.includeSkill?.checked,error:q('#step-error')?.textContent,focus:document.activeElement?.id}:null;
40
+ formIdentity=identity;revision=key;
38
41
  q('#flow-steps').innerHTML=steps.map((s,i)=>{
39
42
  const done=['completed','retained'].includes(s.state),skip=s.state==='skipped',current=s.key===active;
40
43
  let body='';
41
- if(current&&(choice||v?.type==='selection'))body='<form id="current-form"><label class="field" for="install-path">安装到哪里?</label><input id="install-path" name="destination" type="text" value="'+esc(r.destinationIntent||v?.suggestion||'')+'" spellcheck="false" required><p class="hint">请输入完整路径,可以包含成对引号。不会覆盖已有内容,最终目录仍由程序检查。</p><label class="check"><input id="include-skill" name="includeSkill" type="checkbox" '+(r.journeyContext?.skillChoice==='skipped'?'':'checked')+'><span>同时安装 Foundation Skill<br><span class="hint">让 Codex 能识别 Foundation 指令,并按 Foundation 规范工作。</span></span></label><p class="hint">获取缓存:'+esc(r.acquisitionRoot||'以当前任务已披露位置为准')+'。选择不是安装批准。</p><div id="step-error" class="error" role="alert">'+esc(v?.error||'')+'</div><div class="actions"><button class="primary" name="action" value="'+(choice?'choose':'select')+'">使用这个位置</button><button name="action" value="'+(choice?'cancel-intent':'cancel')+'" formnovalidate>取消本步</button></div></form>';
42
- else if(current&&v?.session){const f=v.feedback;body='<p>'+esc(f.detail)+'</p><div class="facts">'+f.namedTargets.map(t=>'<p>'+esc(t.label)+':'+esc(t.path||'待核实')+'</p>').join('')+'<p>保留:'+esc(f.preserves.join(';'))+'</p><p>'+esc(f.notDone)+'</p>'+cleanupText(v.session)+((v.session.deletes||[]).length?'<details open><summary>删除范围</summary>'+v.session.deletes.map(x=>'<p>'+esc(x==='foundation-installation:full'?'本安装中经所有权核验的程序、运行时和状态文件;未知或用户修改的文件保留。':typeof x==='string'?x:JSON.stringify(x))+'</p>').join('')+'</details>':'')+'</div><p class="hint">每次确认只针对当前计划,不批准后续步骤。Skill 文件就位不等于新对话已识别。</p><form id="current-form"><div id="step-error" class="error" role="alert"></div><div class="actions">'+(v.session.state==='pending'?'<button class="'+(kind==='uninstall'?'danger':'primary')+'" name="action" value="'+esc(v.action)+'">确认'+esc(titles[s.key])+'</button><button name="action" value="cancel-no-change">取消本步</button>':'<p>本步已开始或结束,不能重复确认。</p>')+'</div></form>';}
43
- else if(current)body='<p role="status">'+esc(p.progress.phase)+'</p><p class="hint">下一步会在本页展开,不需要查找其他网址。</p>';
44
- return '<li class="step '+(current?'current':done||skip?'done':'later')+'"><div class="step-top"><span class="step-number">'+(skip?'−':done?'✓':i+1)+'</span><span class="step-title">'+esc(titles[s.key]||s.title)+'</span><span class="step-state">'+esc(skip?'已跳过':done?'已完成':stateLabels[s.state]||(current?(choice?'等待选择':p.progress.phase):r.terminal?'本次未执行':'等待前序步骤'))+'</span></div>'+(current?'<div class="step-body">'+body+'</div>':done||skip?'<details class="completed-detail"><summary>查看结果</summary><p>'+esc(skip?'本次未执行此步骤。':s.evidence?JSON.stringify(s.evidence):'结果来自本次操作记录')+'</p></details>':'')+'</li>';
44
+ if(current&&(choice||v?.type==='selection'))body='<form id="current-form"><label class="field" for="install-path">Foundation 安装位置</label><input id="install-path" name="destination" type="text" value="'+esc(r.destinationIntent||v?.suggestion||'')+'" spellcheck="false" required><p class="hint">这里只存放 Foundation 程序。以后不同项目都可以使用它,项目文件仍保存在各自的位置。请输入完整路径,可以包含成对引号;不会覆盖已有文件。</p><label class="check"><input id="include-skill" name="includeSkill" type="checkbox" '+(r.journeyContext?.skillChoice==='skipped'?'':'checked')+'><span>同时启用 Codex 对话功能(Foundation Skill)<br><span class="hint">以后可在 Codex 中说“打开 Foundation”或“用 Foundation 做这个项目”。启用后请在新对话中尝试。</span></span></label><p class="hint">获取缓存:'+esc(r.acquisitionRoot||'以当前任务已披露位置为准')+'。选择不是安装批准。</p><div id="step-error" class="error" role="alert">'+esc(v?.error||'')+'</div><div class="actions"><button class="primary" name="action" value="'+(choice?'choose':'select')+'">使用这个位置</button><button name="action" value="'+(choice?'cancel-intent':'cancel')+'" formnovalidate>取消本步</button></div></form>';
45
+ else if(current&&v?.session){const f=v.feedback;body='<p>'+esc(f.detail)+'</p><div class="facts">'+f.namedTargets.map(t=>'<p>'+esc(t.label)+':'+esc(t.path||'待核实')+'</p>').join('')+'<p>保留:'+esc(f.preserves.join(';'))+'</p><p>'+esc(f.notDone)+'</p>'+cleanupText(v.session)+((v.session.deletes||[]).length?'<details open><summary>删除范围</summary>'+v.session.deletes.map(x=>'<p>'+esc(x==='foundation-installation:full'?'本安装中经所有权核验的程序、运行时和状态文件;未知或用户修改的文件保留。':typeof x==='string'?x:JSON.stringify(x))+'</p>').join('')+'</details>':'')+'</div><p class="hint">这次只执行上面列出的操作,不批准后续步骤。</p><form id="current-form"><div id="step-error" class="error" role="alert"></div><div class="actions">'+(v.session.state==='pending'?'<button class="'+(kind==='uninstall'?'danger':'primary')+'" name="action" value="'+esc(v.action)+'">'+esc(({program:verb+' Foundation',material:'准备安装 Skill',register:kind==='update'?'更新对话功能':'启用对话功能',remove:'移除对话功能'})[s.key]||'确认本步')+'</button><button name="action" value="cancel-no-change">取消本步</button>':'<p>本步已开始或结束,不能重复确认。</p>')+'</div></form>';}
46
+ else if(current)body='<p role="status" '+(s.key==='acquire'?'data-acquisition-phase':'')+'>'+esc(p.progress.phase)+'</p><p class="hint">下一步会在本页展开,不需要查找其他网址。</p>'+(s.key==='acquire'?'<p class="error" data-download-connection role="status"></p>':'');
47
+ else if(['failed','cancelled','expired','verification-required'].includes(s.state))body='<p class="error">'+esc(s.key==='environment'?c.environment:c.next||p.progress.next)+'</p>';
48
+
49
+ return '<li data-step="'+esc(s.key)+'" class="step '+(current?'current':done||skip?'done':'later')+'"><div class="step-top"><span class="step-number">'+(skip?'−':done?'✓':i+1)+'</span><span class="step-title">'+esc(titles[s.key]||s.title)+'</span><span class="step-state">'+esc(skip?'已跳过':done?'已完成':stateLabels[s.state]||(current?(choice?'等待选择':p.progress.phase):r.terminal?'本次未执行':'等待前序步骤'))+'</span></div>'+(body?'<div class="step-body">'+body+'</div>':done||skip?'<details class="completed-detail"><summary>查看结果</summary><p>'+esc(skip?'本次未执行此步骤。':c.summaries[s.key]||'本步已处理;详细记录见技术详情。')+'</p></details>':'')+'</li>';
45
50
  }).join('');
51
+ const form=q('#current-form');if(draft&&form){if(form.elements.destination&&draft.destination!==undefined)form.elements.destination.value=draft.destination;if(form.elements.includeSkill&&draft.skill!==undefined)form.elements.includeSkill.checked=draft.skill;if(q('#step-error'))q('#step-error').textContent=draft.error||'';if(draft.focus)document.getElementById(draft.focus)?.focus();}
46
52
  }
47
53
  if(busy&&executing){const live=q('.current .step-state');if(live)live.textContent='正在执行';}
54
+ // Byte/phase updates must not rebuild the form or depend on its revision key.
55
+ const downloadRow=q('[data-step="acquire"]');
56
+ if(downloadRow&&(active==='acquire'||r.terminal&&steps.find(s=>s.key==='acquire')?.state==='failed')){
57
+ downloadRow.querySelector('.step-state').textContent=p.progress.downloadStatus||p.progress.phase;
58
+ const phase=downloadRow.querySelector('[data-acquisition-phase]');if(phase)phase.textContent=p.progress.downloadStatus==='正在检查文件'?'正在检查文件':p.progress.phase;
59
+ const connection=downloadRow.querySelector('[data-download-connection]');if(connection)connection.textContent='';
60
+ }
48
61
  q('#flow-result').hidden=!r.terminal;
49
- if(r.terminal)q('#flow-result').innerHTML='<h2>'+esc(r.state==='completed'?verb+'完成':'部分完成 / 待核实')+'</h2><p>'+esc(p.progress.program)+'</p><p>Skill:'+esc(p.progress.skill)+'</p><p>项目:'+esc(p.progress.project)+'</p><p class="hint">下一步:'+esc(p.progress.next)+'</p>';
62
+ if(r.terminal)q('#flow-result').innerHTML='<h2>'+esc(c.title)+'</h2><p>'+esc(c.program)+'</p><p>Codex 对话功能:'+esc(c.skill)+'</p><p>项目:'+esc(c.project)+'</p><p class="hint">下一步:'+esc(c.next||p.progress.next)+'</p>';
50
63
  const safe=JSON.parse(JSON.stringify(p));if(safe.view){delete safe.view.managerNonce;delete safe.view.nonce;}q('#raw').textContent=JSON.stringify(safe,null,2);
51
64
  }
52
65
  document.addEventListener('submit',async e=>{if(e.target.id!=='current-form')return;e.preventDefault();if(busy||!last)return;busy=true;const form=e.target;form.querySelectorAll('button').forEach(b=>b.disabled=true);q('#flow-status').textContent='正在提交请求';const action=e.submitter.value,v=last.view;const body={csrf,operationId:last.record.operationId,action,...(['choose','select'].includes(action)?{destination:form.elements.destination.value,skillChoice:form.elements.includeSkill.checked?'selected':'skipped'}:{managerNonce:v?.managerNonce,sessionId:v?.session?.sessionId,planHash:v?.session?.planHash})};
66
+
53
67
  try{const response=await fetch(location.pathname+'/action',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(body)});const result=await response.json();if(!response.ok){q('#step-error').textContent=result.message||result.code||'本步未完成,请核实';busy=false;form.querySelectorAll('button').forEach(b=>b.disabled=false);return;}busy=false;revision=null;await refresh();}catch{q('#connection').textContent='请求结果待核实,不自动重试。已收到的结果保留;刷新查询同次流程。';}});
54
- async function refresh(){try{const response=await fetch(location.pathname+'/state');if(!response.ok)throw Error();show(await response.json());q('#connection').textContent='';}catch{q('#connection').textContent=last?.record?.terminal?'结果服务已结束,上方保留最后核实结果。可在对话中按本次操作记录再次查询。':'连接已中断,保留最后核实结果;不自动重试操作。';}}
68
+ async function refresh(){try{const response=await fetch(location.pathname+'/state');if(!response.ok)throw Error();show(await response.json());q('#connection').textContent='';}catch{q('#connection').textContent=last?.record?.terminal?'结果服务已结束,上方保留最后核实结果。可在对话中按本次操作记录再次查询。':'连接已中断,保留最后核实结果;不自动重试操作。';const note=q('.current [data-download-connection]');if(note){note.textContent='连接中断,进度待核实;保留上次收到的数值。';q('.current .step-state').textContent=(last.progress.downloadStatus||last.progress.phase)+' · 待核实';}}}
55
69
  async function poll(){if(stopped)return;await refresh();if(!stopped)setTimeout(poll,750);}poll();window.addEventListener('pagehide',()=>{stopped=true},{once:true});
56
70
  }
@@ -13,7 +13,8 @@ export async function followSelectedSkill({operation,env,onChange,journeyControl
13
13
  const identity=initial.installation?.current;
14
14
  if(!identity?.identity?.installId||initial.bridge?.currentVersion!==identity.version)throw Error('当前安装身份无法核实,停止 Skill 接续');
15
15
  if(operation.installId&&operation.installId!==identity.identity.installId)throw Error('恢复记录属于另一安装,停止接续');
16
- onChange({installId:identity.identity.installId,installedCandidateHash:identity.candidateHash});
16
+ onChange({installId:identity.identity.installId,installedCandidateHash:identity.candidateHash,usageScope:identity.usageScope||{kind:'user',project:null}});
17
+ const discoveryNext=identity.usageScope?.kind==='project'?'请在绑定项目 '+identity.usageScope.project.path+' 内新开 Codex 对话验证识别;不会供其他项目使用。':'新开 Codex 对话验证识别。';
17
18
  const manifestFile=plainPath(path.join(root,identity.appPath,'artifacts/skills/ai-product-foundation-kit/capability.json'));
18
19
  if(!manifestFile.startsWith(root+path.sep))throw Error('Skill 材料必须属于当前安装');
19
20
  if(initial.codexSkill?.state==='files-installed-host-discovery-unverified'){
@@ -49,5 +50,5 @@ const event=await observePlan(client,requested,observation=>onChange({phase:obse
49
50
  }
50
51
  const verified=checkIdentity().codexSkill;
51
52
  if(verified?.state!=='files-installed-host-discovery-unverified')throw Error('Skill 注册文件与归属未通过核验;程序成功保留');
52
- return {state:'completed',phase:'finished',terminal:true,skillRegistered:true,skillDestination:verified.destination,skillSteps:steps,hostDiscoveryVerified:false,next:'程序与所选 Skill 文件已就位;新开 Codex 对话验证识别,项目接入另行确认。'};
53
+ return {state:'completed',phase:'finished',terminal:true,skillRegistered:true,skillDestination:verified.destination,skillSteps:steps,hostDiscoveryVerified:false,next:'程序与所选 Skill 文件已就位;'+discoveryNext+' 项目接入另行确认。'};
53
54
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@josephyulei/summon-foundation",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@josephyulei/summon-foundation",
9
- "version": "0.1.6",
9
+ "version": "0.1.8",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@sigstore/bundle": "4.0.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@josephyulei/summon-foundation",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Prepare a verified Foundation release for an explicitly confirmed Codex installation",
5
5
  "type": "module",
6
6
  "bin": {"summon": "bin/summon.mjs"},