@promptframe/creation 0.2.2 → 0.2.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.
@@ -6,3 +6,40 @@ content-type/index.js:
6
6
  * Copyright(c) 2015 Douglas Christopher Wilson
7
7
  * MIT Licensed
8
8
  */
9
+
10
+ smol-toml/dist/error.js:
11
+ smol-toml/dist/primitive.js:
12
+ smol-toml/dist/date.js:
13
+ smol-toml/dist/extract.js:
14
+ smol-toml/dist/util.js:
15
+ smol-toml/dist/struct.js:
16
+ smol-toml/dist/parse.js:
17
+ smol-toml/dist/stringify.js:
18
+ smol-toml/dist/index.js:
19
+ /*!
20
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
21
+ * SPDX-License-Identifier: BSD-3-Clause
22
+ *
23
+ * Redistribution and use in source and binary forms, with or without
24
+ * modification, are permitted provided that the following conditions are met:
25
+ *
26
+ * 1. Redistributions of source code must retain the above copyright notice, this
27
+ * list of conditions and the following disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
29
+ * this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ * 3. Neither the name of the copyright holder nor the names of its contributors
32
+ * may be used to endorse or promote products derived from this software without
33
+ * specific prior written permission.
34
+ *
35
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
36
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
37
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
39
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
42
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
+ */
@@ -31,7 +31,7 @@
31
31
 
32
32
  源码经 GitHub Actions 打包发行到 npm;插件目录记录包名/版本或源码位置。安装后,Codex 加载本地副本并按配置启动 Node 桥;桥通过 stdio 接收调用,读取独立安全配置,再通过 HTTPS MCP 连接所选平台。GitHub、npm 与目录索引负责获取版本,不进入正常工具调用链。Token 不进入源码、插件包或命令参数。
33
33
 
34
- 0.2.2公开目录固定npm来源;`connect`复用来源和缓存定义可核的已启用官方npm插件;尚未注册时才准备用户级受管版本。受管身份按installation记录和原MCP定义核实,允许安装器Node路径变化,不将未知同名手工入口当作自身安装。`scripts/build-runtime.mjs`显式bundle MCP SDK及必要依赖,拒绝除Node builtins之外的外部import并附第三方许可证。npm_source仍只pack/unpack,不执行npm install;因此`test/package-runtime.test.mjs`从无node_modules解包核可运行。宿主注册/实际Skill及MCP启动另核,普通npm install不代替。
34
+ 当前公开目录固定npm来源;`connect`复用来源和缓存定义可核的已启用官方npm插件;尚未注册时才准备用户级受管版本。受管身份按installation记录和原MCP定义核实,允许安装器Node路径变化,不将未知同名手工入口当作自身安装。`scripts/build-runtime.mjs`显式bundle MCP SDK及必要依赖,拒绝除Node builtins之外的外部import并附第三方许可证。npm_source仍只pack/unpack,不执行npm install;因此`test/package-runtime.test.mjs`从无node_modules解包核可运行。宿主注册/实际Skill及MCP启动另核,普通npm install不代替。
35
35
 
36
36
  ## 相称验证
37
37
 
@@ -44,3 +44,9 @@
44
44
  ## 公开范围
45
45
 
46
46
  使用说明保持公开且可移植。平台私有配置、真实端点默认值、用户样本、Token、内部协作材料和业务权限实现不进入本仓。组件创作需要的工具按 README 指向独立 authoring 仓;不在本仓维护第二套组件 CLI 参数手册或四包发行流程。
47
+
48
+ 安装器按 connect 的固定目标版本比较实际安装:同版复用、更新版不降级、受管旧版准备独立目录。官方 npm 插件旧版先返回明确的待升级错误:Codex 0.160 的升级会删除旧缓存,不能假称能保护其他桥并自动升级。受管与官方复用均实际检查启动 Node 与包版本。安装结果新增 requestedVersion/versionStatus;安全错误只输出本地构造的版本、动作和指引,不输出宿主原始错误、环境或凭据。
49
+
50
+ 后继安装发现使用 `$CODEX_HOME/config.toml` 的结构化插件登记 ID、`codex plugin marketplace list --json` 的本地根索引、有界目录 JSON 和 `plugin list --marketplace <name> --json`。TOML 使用随运行文件打包的成熟解析器,只保留相关插件身份;目录条目删除后仍查询原登记,读面无法解析该登记就保持 unknown。覆盖全部相关入口,不把不可读目录当未安装,也不调用必需全量远端插件查询。注册前持久保存精确 pending 身份;写回程未知后只观察该身份,不第二次 add 或自动降回旧注册。测试从 pack 的实际 npx/connect 入口核隔离配置、两个 profile、并发和失 ACK,不读个人配置。
51
+
52
+ 宿主插件已安装/启用、平台连接验证与聊天加载分别报告。外部安装器不接私有 app-server 生产刷新通道;当前使用官方新聊天/新 session 路径,选择 Local 和独立非 Git 目录即可。候选包、公共 registry 固定包和真实宿主新聊天工具/两个 Skill 的验收分开记录。
@@ -5,14 +5,18 @@
5
5
  从 Studio 的“连接与授权”复制当前环境的指引。在本机终端执行:
6
6
 
7
7
  ```bash
8
- npx --yes @promptframe/creation@0.2.2 connect --endpoint <Studio提供的API地址>
8
+ npx --yes @promptframe/creation@0.2.3 connect --endpoint <Studio提供的API地址>
9
9
  ```
10
10
 
11
11
  `/api` 会规范化到 `/api/mcp`;也可直接提供 `/api/mcp`。保留 Studio 实际可达的 HTTPS origin,包括私有网络域名,不把远程地址替换成本机 localhost。`0.1.1` 是历史基础包;它不支持此用户级插件引导。新版本是否已发行,以 registry 的实际版本和对应固定标签为准。
12
12
 
13
13
  首次连接由用户在 Studio 生成创作授权,在终端隐藏输入框输入 Token。自动化可从受限管道使用 `--token-stdin`,不得把 Token 放在参数、聊天、URL、业务仓或日志中。已有有效凭据直接验证复用;失败时保留原凭据,不自动撤销或轮换。仅明确替换时使用 `setup --replace`。
14
14
 
15
- 连接入口校验完整包,把自包含运行文件、插件声明及两个 Skill 放入用户级版本目录,通过 `codex plugin marketplace add` 和 `codex plugin add` 注册并核回已启用版本。无需在当前业务仓运行 npm install,也不依赖开发者的 node_modules。目录注册成功与当前聊天已加载分别报告:首次安装或升级后正常重载插件或开新聊天,确认 creation-setup、video-creation 和 MCP 工具均可见。
15
+ 连接入口校验完整包,把自包含运行文件、插件声明及两个 Skill 放入用户级版本目录,通过 `codex plugin marketplace add` 和 `codex plugin add` 注册并核回已启用版本。无需在当前业务仓运行 npm install,也不依赖开发者的 node_modules。目录注册成功与当前聊天已加载分别报告。
16
+
17
+ 安装后在同一主机开一个 **Local 新聊天**;CLI 使用新 session。选择独立的非 Git 创作目录即可,不必复制产品仓或创建 Worktree,也不用重装或更换 Token。在新聊天确认 `creation-setup`、`video-creation` 两个 Skill 和 PromptFrame MCP 工具一起可用,再开始创作。现有聊天不必关闭;安装器不重启宿主或其它聊天,也不承诺能从外部 npx 强刷原 GUI 会话。[官方插件说明](https://learn.chatgpt.com/docs/plugins)要求安装后使用新聊天/新 session。
18
+
19
+ 安装输出分别报告插件已安装、已启用、平台凭据连接已核验;`hostMcpConnected` 与 `sessionLoaded` 在安装器中仍为 `not_verified`。当前聊天是否已加载,要由该聊天实际发现 Skill 和调用 MCP 只读工具验证。若宿主将来提供明确受支持的同会话刷新入口,也须同时核回这两类能力后才能报告加载成功。
16
20
 
17
21
  ## 环境与账号
18
22
 
@@ -21,16 +25,20 @@ npx --yes @promptframe/creation@0.2.2 connect --endpoint <Studio提供的API地
21
25
  另一个环境或账号应由用户选择不同名称:
22
26
 
23
27
  ```bash
24
- npx --yes @promptframe/creation@0.2.2 connect --profile work-account --endpoint <另一环境API地址>
28
+ npx --yes @promptframe/creation@0.2.3 connect --profile work-account --endpoint <另一环境API地址>
25
29
  ```
26
30
 
27
31
  命名 profile 使用独立凭据和独立插件名;新桥配置固定具体凭据文件。已有文件绑定另一 endpoint 时拒绝覆盖,运行中的桥也不会热切环境。相同 endpoint 的不同账号同样用不同 profile;不要尝试从 Token 或作品名猜账号。`--config <安全文件>` 可指定已存在的私有配置,但不得把不同环境指向同一文件。
28
32
 
29
33
  ## 版本与失败
30
34
 
35
+ 推荐版本由 Studio 当前连接指引提供,入口每次对照命令中的固定版本检查安装。同版本复用;受管旧版准备新版并切换后续入口;已安装更新版返回 `newer_retained`,不降级。没有后台自动追踪 latest;再次连接时从 Studio 复制当前指令,不沿用旧聊天中的版本。
36
+
31
37
  每个 profile 的安装位于 `$XDG_DATA_HOME/promptframe-creation/<profile>`(默认用户 `.local/share`),版本在 `versions/<version>`。同版本完整内容复用,不再次下载运行依赖;两个入口串行合并。新版本先完整准备和检查,再注册并原子更新 `current.json`。旧版本及其依赖保留,不覆盖、不枚举或终止其它聊天。
32
38
 
33
- 更新失败保留旧默认、旧文件及 Token。`registration_unconfirmed_keep_existing` 表示宿主命令结果未确认;先核 Codex 当前插件状态,不根据错误盲重发或删除缓存。普通重试会核原完整版本和实际宿主状态。只在确认本工具 `install.lock/owner.json` 的进程已退出后,才手动移除该精确安装锁并重试;活动或无法确认的进程不清锁。安装锁不决定平台编辑权。
39
+ 更新失败保留旧默认、旧文件及 Token。`registration_unconfirmed_keep_existing` 表示宿主写命令结果未确认;先核 Codex 当前插件状态,不根据错误盲重发或删除缓存。安装器在写前保存该 profile 的 `registration-pending.json`;再次 connect 只观察同一插件和版本。确认已登记则正常完成,否则保留待核状态,不自动第二次 add 或用旧版 add 作补偿。只有原宿主登记责任核清后才安排后续处理。只在确认本工具 `install.lock/owner.json` 的进程已退出后,才手动移除该精确安装锁并重试;活动或无法确认的进程不清锁。安装锁不决定平台编辑权。
40
+
41
+ 源码后继的安装核验读取宿主结构化本地 marketplace 索引和有界目录文件,再仅查询全部相关 marketplace;无关远端目录不进入安装必需路径。目录不可读、JSON/输出超限、查询超时不代表“未安装”。错误只报告阶段、命令种类、耗时、期限、退出码/信号及下一动作,不透传子进程 stdout/stderr、环境或凭据。此行为属于后继源码/候选,不回填已发行 0.2.3。
34
42
 
35
43
  从旧手工 `codex mcp add promptframe` 迁移时,若发现同名定义,引导会停止并给出 `legacy_mcp_entry_requires_review`,不会删除不明配置。确认它是旧的 PromptFrame 手工入口后可用 `codex mcp remove promptframe` 移除定义,再重复 connect。移除定义不取消已接受平台任务、不撤销 Token;在途桥及原结果应沿原 task 观察。
36
44
 
@@ -44,6 +52,13 @@ npx --yes @promptframe/creation@0.2.2 connect --profile work-account --endpoint
44
52
 
45
53
  ## 已有官方插件与 Node 路径变更
46
54
 
47
- 已通过官方 npm 来源安装并启用的插件,`connect`核来源、缓存版本与实际MCP定义后复用现有入口和配置,不另注册第二个插件。未知手工MCP仍需明确核对;自定义配置或独立账号使用显式profile,不能借官方插件名切换其环境。
55
+ 已通过官方 npm 来源安装并启用的插件,`connect` 核来源、缓存、实际 MCP 定义及可执行运行环境。同版本复用;比指令更新的版本保留并返回 `newer_retained`;旧版明确返回 `installation.npm_plugin_upgrade_required`,附实际版本和请求版本,退出码为1,不报告升级成功,也不创建第二个入口。
56
+
57
+ Codex CLI 0.160.0 的 `plugin add` 升级 npm 插件会移除旧缓存,当前没有可保留旧缓存的升级选项。因此不能在不知道其他聊天是否仍用旧桥时自动执行该命令。处理步骤:
58
+
59
+ 1. 等使用该插件的活动聊天和桥结束。平台已受理的媒体任务保持原 task,升级后继续查询,不重派。
60
+ 2. 用 `codex plugin marketplace list --json` 和 `codex plugin list --marketplace <原准确目录名> --json` 确认原插件 ID、目录来源和当前版本。
61
+ 3. Git 来源目录使用 `codex plugin marketplace upgrade <原目录名> --json` 更新目录;本地目录由其维护者更新到包含目标 npm 版本的目录。不要新注册一个同名插件来绕过升级。
62
+ 4. 确认目录中的版本是目标版本后,执行 `codex plugin add <原插件ID> --json`。再次 `codex plugin list --marketplace <原准确目录名> --json` 核目标版本已启用,再运行 Studio 的 `connect` 指令并开 Local 新聊天。目录未提供目标版或升级失败时保持待升级,不循环卸载重装。
48
63
 
49
- 受管入口按原安装记录核身份,不以当前Node可执行文件路径认领。相同版本继续使用已记录的Node路径;换Node后运行connect可复用原安装,需保留该旧Node以供新聊天启动。后继兼容版本采用安装该版本时的Node路径,旧版本和活动桥不被覆盖或终止。
64
+ 受管入口按原安装记录核身份,不以当前 Node 路径认领。每次复用会实际运行已记录的 Node 和该版本 `--version`(各最多10秒,无平台调用),缺失、低于20或无法启动时返回 `installation.recorded_node_unavailable`。可恢复原 Node.js 20+ 路径,或运行 Studio 提供的较新版本 connect:新的受管版本使用当前 Node,保留旧代码及原凭据。相同版本不会偷偷重写旧启动配置。官方 npm 插件的 `node` 按当前宿主环境的 PATH 检查;Desktop 重载后的真实 MCP 启动仍须单独确认。
@@ -0,0 +1,8 @@
1
+ # 0.2.3 — 安装版本与运行环境检查
2
+
3
+ - `connect` 返回实际 `version`、指令的 `requestedVersion` 和 `versionStatus`。同版本复用,已装更新版本保留,不默认降级。
4
+ - 受管旧版本沿独立版本目录升级,旧代码、凭据及原任务保持。复用时实际检查已记录 Node 和 CLI;缺失或不可用时返回明确恢复指引,较新版本可用当前 Node 准备新桥。
5
+ - 官方 npm 来源旧插件返回 `installation.npm_plugin_upgrade_required`,不再误报已升级。Codex CLI 0.160.0 升级 npm 插件会删除旧缓存,因此不能自动保证活动桥保留;按[安装说明](../installing.md)在活动桥结束后升级原插件并核回版本。
6
+ - 设置和创作 Skill 统一指向固定推荐版 `connect`;`setup` 只处理凭据。推荐版本由 Studio 连接入口提供,没有后台自动更新守护程序。
7
+
8
+ 以上不代表每台用户 Desktop 已加载新版,或完整视频创作旅程已验收。首次安装/升级后仍需按宿主正常方式重载,并确认两个 Skill 和 MCP 工具同时可见。
@@ -0,0 +1,10 @@
1
+ # 0.2.4 安装发现候选
2
+
3
+ 发行状态以 registry、provenance 和固定 creation-v0.2.4 标签为准;源码和本地打包候选不等于已发行。候选准备阶段 main 的公开目录保留实际已发行的 0.2.3,候选分支同步 package、lock、插件、目录和 CLIENT_VERSION,正式发行沿发布手册合入并使用新标签。0.2.3 原包和标签不改。
4
+
5
+ - 安装前后从宿主本地 marketplace 索引发现全部相关目录,只做相关插件查询,无关远端目录不阻塞安装。
6
+ - 目录或读结果未知保持未知,保留版本/来源/Node/MCP/profile 验证;错误只报告安全阶段与退出事实。
7
+ - 宿主登记前持久保存精确 pending 身份,写回程未知后先观察原登记,不第二次 add 或自动补偿覆盖旧注册。
8
+ - 已安装、已启用、平台连接验证与当前聊天加载分开报告。在同一主机开 Local 新聊天或 CLI 新 session,复用 Token;纯 MCP 创作不需要产品仓或 Worktree。
9
+
10
+ 候选使用隔离 HOME/CODEX_HOME/XDG、匿名本地 MCP 与替身 Codex CLI,经真实打包产物 npx/connect 检查。公共 registry 固定包、真实桌面新聊天的两个 Skill/MCP tools/list 与完整创作另行验收,不以候选测试代替。
package/lib/cli.mjs CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  } from "./credentials.mjs";
17
17
  import { connectPlatform } from "./connection.mjs";
18
18
  import { createHostCallBridge } from "./host-context.mjs";
19
- import {installForUser,profileCredentialsPath} from './user-installation.mjs';
19
+ import {installForUser,profileCredentialsPath,installationErrorDetails} from './user-installation.mjs';
20
20
  import {fileURLToPath} from 'node:url';
21
21
  import path from 'node:path';
22
22
 
@@ -224,9 +224,11 @@ try {
224
224
  const installed=await installForUser({sourceRoot:fileURLToPath(new URL('..',import.meta.url)),
225
225
  profile:value('--profile')??'default',configFile:configFile(),signal:signal.signal});
226
226
  log({...connection,pluginRegistered:installed.registered,version:installed.version,
227
+ pluginInstalled:true,pluginEnabled:true,hostMcpConnected:'not_verified',sessionLoaded:'not_verified',
227
228
  installationReused:installed.reused,profile:installed.profile,
229
+ requestedVersion:installed.requestedVersion,versionStatus:installed.versionStatus,
228
230
  recordedRuntimeRetained:installed.recordedRuntimeRetained??false,
229
- next:installed.recordedRuntimeRetained?'This version retains its recorded Node path. Keep that Node available; a new version uses the installer\'s current Node.':installed.reloadRequired?'Open a new Codex chat or reload plugins, then use the creation Skill.':'Use the creation Skill in a chat that has this plugin loaded.',
231
+ next:'On this host, open a new Local chat (CLI: start a new session). Check creation-setup, video-creation and the PromptFrame MCP tools together. Keep the existing Token; no reinstall or product repository is needed.'+(installed.recordedRuntimeRetained?' Keep this version\'s recorded Node path available.':''),
230
232
  hostThreadIdentity:'verified_by_the_platform_on_actual_host_tool_calls'});
231
233
  }finally{process.removeListener('SIGINT',abort);process.removeListener('SIGTERM',abort);}
232
234
  }
@@ -249,6 +251,7 @@ try {
249
251
  // Never print raw SDK/fetch errors, response bodies or credentials.
250
252
  process.stderr.write(
251
253
  JSON.stringify({
254
+ ...installationErrorDetails(error),
252
255
  error:
253
256
  error instanceof CreationClientError
254
257
  ? error.message
@@ -1,13 +1,25 @@
1
1
  import {execFile} from 'node:child_process';
2
2
  import {promisify} from 'node:util';
3
3
  import {createHash,randomBytes} from 'node:crypto';
4
- import {lstat,mkdir,readdir,readFile,writeFile,rename,rm} from 'node:fs/promises';
4
+ import {lstat,mkdir,readdir,readFile,writeFile,rename,rm,open} from 'node:fs/promises';
5
5
  import {homedir} from 'node:os';
6
6
  import path from 'node:path';
7
+ import {parse as parseToml} from 'smol-toml';
7
8
  import {CreationClientError,credentialsPath} from './credentials.mjs';
8
9
 
9
10
  const execute=promisify(execFile),hash=b=>createHash('sha256').update(b).digest('hex');
10
- const fail=code=>{throw new CreationClientError('installation.'+code);};
11
+ class InstallationError extends CreationClientError {
12
+ constructor(code,details){super('installation.'+code);this.details=details;}
13
+ }
14
+ const fail=(code,details)=>{throw new InstallationError(code,details);};
15
+ // Only locally constructed, safe installer facts reach the CLI. Never forward a
16
+ // raw host error, environment, credential or response body.
17
+ export const installationErrorDetails=error=>error instanceof InstallationError?error.details:undefined;
18
+ function compareVersions(a,b){
19
+ const left=a.split('.').map(BigInt),right=b.split('.').map(BigInt);
20
+ for(let i=0;i<3;i++){if(left[i]>right[i])return 1;if(left[i]<right[i])return -1;}return 0;
21
+ }
22
+
11
23
  const entries=['package.json','README.md','LICENSE','bin','dist','lib','skills','docs','.codex-plugin','.mcp.json'];
12
24
  const json=async file=>JSON.parse(await readFile(file,'utf8'));
13
25
  const pause=ms=>new Promise(r=>setTimeout(r,ms));
@@ -81,7 +93,12 @@ async function officialNpmInstallation(installed,servers,env,profile,configFile)
81
93
  }
82
94
  async function atomicJSON(file,value){
83
95
  const temp=file+'.'+randomBytes(12).toString('hex')+'.tmp';
84
- try{await writeFile(temp,JSON.stringify(value,null,2)+'\n',{flag:'wx',mode:0o600});await rename(temp,file);}
96
+ try{
97
+ const out=await open(temp,'wx',0o600);
98
+ try{await out.writeFile(JSON.stringify(value,null,2)+'\n');await out.sync();}finally{await out.close();}
99
+ await rename(temp,file);const directory=await open(path.dirname(file),'r');
100
+ try{await directory.sync();}finally{await directory.close();}
101
+ }
85
102
  finally{await rm(temp,{force:true});}
86
103
  }
87
104
  async function packageFiles(root){
@@ -120,9 +137,72 @@ async function acquire(root,signal){
120
137
  catch(e){await rm(lock,{recursive:true,force:true});throw e;}
121
138
  return()=>rm(lock,{recursive:true,force:true});
122
139
  }
140
+ function commandKind(args){
141
+ if(args[0]==='--version')return 'host_version';
142
+ if(args[0]==='mcp'&&args[1]==='list')return 'mcp_read';
143
+ if(args[1]==='marketplace')return args[2]==='list'?'marketplace_read':'marketplace_register';
144
+ return args[1]==='list'?'plugin_read':'plugin_register';
145
+ }
123
146
  export async function runCodexCommand(args,{env=process.env}={}){
124
- try{return(await execute('codex',args,{env,encoding:'utf8',timeout:30_000,maxBuffer:2*1024*1024})).stdout;}
125
- catch(e){throw new CreationClientError(e.code==='ENOENT'?'installation.codex_required':'installation.codex_command_unconfirmed');}
147
+ const kind=commandKind(args),write=kind.endsWith('_register'),timeoutMs=write?30_000:5_000,start=performance.now();
148
+ try{return(await execute('codex',args,{env,encoding:'utf8',timeout:timeoutMs,maxBuffer:2*1024*1024})).stdout;}
149
+ catch(e){
150
+ const cause=e.code==='ENOENT'?'codex_required':e.code==='ERR_CHILD_PROCESS_STDIO_MAXBUFFER'?'command_output_limit'
151
+ :e.killed?'command_timeout':'command_failed';
152
+ fail(cause,{phase:write?'registration':'local_check',commandKind:kind,elapsedMs:Math.round(performance.now()-start),timeoutMs,
153
+ exitCode:Number.isInteger(e.code)?e.code:null,signal:['SIGTERM','SIGKILL','SIGINT'].includes(e.signal)?e.signal:null,
154
+ localRegistrationState:'unknown',action:write?'observe_same_registration_before_retry':'retry_local_read'});
155
+ }
156
+ }
157
+ async function codexJSON(runCodex,args){
158
+ const body=await runCodex(args);
159
+ try{if(typeof body!=='string'||Buffer.byteLength(body)>2*1024*1024)throw Error();return JSON.parse(body);}
160
+ catch{fail('command_json_unconfirmed',{phase:'local_check',commandKind:commandKind(args),localRegistrationState:'unknown',action:'retry_local_read'});}
161
+ }
162
+ // Marketplace roots are the host's structured, local discovery index. Read only
163
+ // their bounded catalogs, then ask the supported CLI about every related entry.
164
+ // An unreadable catalog is unknown, never evidence that no plugin is installed.
165
+ async function relatedPlugins(runCodex,pluginName,env){
166
+ const related=new Set(),registered=new Set(),config=path.join(path.resolve(env.CODEX_HOME??path.join(homedir(),'.codex')),'config.toml');
167
+ try{
168
+ const s=await info(config);
169
+ if(s){
170
+ if(!s.isFile()||s.isSymbolicLink()||s.size>2*1024*1024)throw Error();
171
+ const plugins=parseToml(await readFile(config,'utf8')).plugins??{};
172
+ if(!plugins||typeof plugins!=='object'||Array.isArray(plugins)||Object.keys(plugins).length>1024)throw Error();
173
+ for(const id of Object.keys(plugins))if(id.startsWith(pluginName+'@')){
174
+ const market=id.slice(pluginName.length+1);
175
+ if(!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market))throw Error();
176
+ related.add(market);registered.add(id);
177
+ }
178
+ }
179
+ }catch{fail('local_config_unconfirmed',{phase:'local_check',commandKind:'local_config_read',localRegistrationState:'unknown',action:'review_local_plugin_registration'});}
180
+ const state=await codexJSON(runCodex,['plugin','marketplace','list','--json']);
181
+ if(!Array.isArray(state?.marketplaces)||state.marketplaces.length>128)fail('local_catalog_unconfirmed');
182
+ for(const market of state.marketplaces){
183
+ if(typeof market.name!=='string'||!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,140}$/.test(market.name)
184
+ ||typeof market.root!=='string'||!path.isAbsolute(market.root))fail('local_catalog_unconfirmed');
185
+ let catalog;
186
+ try{catalog=await packageJSON(path.join(market.root,'.agents/plugins/marketplace.json'));}
187
+ catch{fail('local_catalog_unconfirmed',{phase:'local_check',commandKind:'marketplace_read',localRegistrationState:'unknown',action:'restore_local_marketplace_catalog'});}
188
+ if(!Array.isArray(catalog?.plugins)||catalog.plugins.length>1024)fail('local_catalog_unconfirmed');
189
+ if(catalog.plugins.some(p=>p?.name===pluginName))related.add(market.name);
190
+ }
191
+ const installed=[];
192
+ for(const market of related){
193
+ const list=await codexJSON(runCodex,['plugin','list','--marketplace',market,'--json']);
194
+ if(!Array.isArray(list?.installed)||list.installed.length>1024)fail('local_registration_unconfirmed');
195
+ for(const p of list.installed){
196
+ if(typeof p?.pluginId!=='string'||typeof p.enabled!=='boolean')fail('local_registration_unconfirmed');
197
+ if(p?.pluginId!==pluginName+'@'+market)continue;
198
+ if(p.marketplaceName!==undefined&&p.marketplaceName!==market)fail('local_registration_unconfirmed');
199
+ installed.push(p);
200
+ }
201
+ }
202
+ if(new Set(installed.map(p=>p.pluginId)).size!==installed.length)fail('local_registration_unconfirmed');
203
+ if([...registered].some(id=>!installed.some(p=>p.pluginId===id)))fail('local_registration_unconfirmed',{
204
+ phase:'local_check',commandKind:'plugin_read',localRegistrationState:'unknown',action:'review_same_local_registration'});
205
+ return installed;
126
206
  }
127
207
  async function runNode(root,version){
128
208
  try{const result=await execute(process.execPath,[path.join(root,'bin/promptframe-creation.mjs'),'--version'],{encoding:'utf8',timeout:10_000,maxBuffer:8192});
@@ -130,12 +210,26 @@ async function runNode(root,version){
130
210
  }catch(e){if(e instanceof CreationClientError)throw e;fail('runtime_check_failed');}
131
211
  }
132
212
 
213
+ async function checkInstalledRuntime(root,version,command,{env=process.env}={}){
214
+ try{
215
+ const runtime=await execute(command,['--version'],{env,encoding:'utf8',timeout:10_000,maxBuffer:8192});
216
+ const major=runtime.stdout.trim().match(/^v(\d+)\./);
217
+ if(!major||Number(major[1])<20)throw Error('unsupported_node');
218
+ const result=await execute(command,[path.join(root,'bin/promptframe-creation.mjs'),'--version'],
219
+ {env,encoding:'utf8',timeout:10_000,maxBuffer:8192});
220
+ if(result.stdout.trim()!==version)throw Error('wrong_version');
221
+ }catch{
222
+ fail('recorded_node_unavailable',{installedVersion:version,action:'restore_recorded_node_or_connect_newer_version',
223
+ next:'恢复该插件记录的 Node.js 20+;或从 Studio 获取较新的推荐版 connect 指令,为新桥准备当前 Node。不要删除旧版本、凭据或重派原任务。'});
224
+ }
225
+ }
226
+
133
227
  /** No daemon or global environment switch. All writes are confined to this
134
228
  * user's managed profile. Host registration uses Codex's ordinary commands.
135
229
  * Completed versions are retained: a running bridge may still use any of them. */
136
230
  export async function installForUser({sourceRoot,profile='default',env=process.env,
137
231
  configFile=profileCredentialsPath(profile,env),runCodex=args=>runCodexCommand(args,{env}),
138
- checkRuntime=runNode,signal}={}){
232
+ checkRuntime=runNode,verifyInstalledRuntime=checkInstalledRuntime,signal}={}){
139
233
  validProfile(profile);
140
234
  const versionOutput=await runCodex(['--version']);
141
235
  const match=versionOutput.match(/codex-cli (\d+)\.(\d+)\.(\d+)/);
@@ -143,28 +237,62 @@ export async function installForUser({sourceRoot,profile='default',env=process.e
143
237
  const payload=await packageFiles(path.resolve(sourceRoot));
144
238
  const root=path.resolve(env.XDG_DATA_HOME??path.join(homedir(),'.local/share'),'promptframe-creation',profile);
145
239
  await privateDirectory(root);const release=await acquire(root,signal);
146
- const versions=path.join(root,'versions'),currentFile=path.join(root,'current.json');
240
+ const versions=path.join(root,'versions'),currentFile=path.join(root,'current.json'),pendingFile=path.join(root,'registration-pending.json');
147
241
  const marketplaceFile=path.join(root,'.agents/plugins/marketplace.json');
148
242
  const pluginName='promptframe-creation'+(profile==='default'?'':'-'+profile),marketplace='promptframe-creation-user'+(profile==='default'?'':'-'+profile);
149
243
  const pluginId=pluginName+'@'+marketplace;
150
244
  const versionRoot=path.join(versions,payload.version),temporary=path.join(versions,'.partial-'+randomBytes(12).toString('hex'));
151
- let previousCatalog,previous,registrationStarted=false,newFiles=0;
245
+ let previous,registrationStarted=false,newFiles=0;
152
246
  try{
153
247
  signal?.throwIfAborted();await privateDirectory(versions);await privateDirectory(path.dirname(marketplaceFile));
154
- previous=await privateRead(currentFile);previousCatalog=await privateRead(marketplaceFile);
248
+ previous=await privateRead(currentFile);
155
249
  if(previous&&(previous.profile!==profile||previous.pluginId!==pluginId||previous.configFile!==configFile))fail('profile_binding_conflict');
156
- const state=JSON.parse(await runCodex(['plugin','list','--json']));
157
- const installed=state.installed?.find(x=>x.pluginId===pluginId);
158
- const legacy=JSON.parse(await runCodex(['mcp','list','--json']));
250
+ const state={installed:await relatedPlugins(runCodex,pluginName,env)};
251
+ const installed=state.installed.find(x=>x.pluginId===pluginId);
252
+ const legacy=await codexJSON(runCodex,['mcp','list','--json']);
253
+ if(!Array.isArray(legacy))fail('local_registration_unconfirmed');
159
254
  const serverName='promptframe'+(profile==='default'?'':'-'+profile);
160
255
  const servers=legacy.filter(x=>x.name===serverName);
256
+ const pending=await privateRead(pendingFile);
257
+ if(pending){
258
+ if(pending.profile!==profile||pending.pluginId!==pluginId||pending.configFile!==configFile
259
+ ||pending.versionRoot!==path.join(versions,pending.version))fail('profile_binding_conflict');
260
+ if(installed?.version!==pending.version||installed.enabled!==true||installed.source?.path!==pending.versionRoot)
261
+ fail('registration_unconfirmed_keep_existing',{phase:'registration_observation',localRegistrationState:'unknown',action:'inspect_same_registration_no_second_add'});
262
+ const transport=await managedTransport(installed,versions,serverName,profile,configFile);
263
+ if(servers.length!==1||servers[0].enabled===false||!sameTransport(servers[0].transport,transport))fail('registration_unconfirmed_keep_existing');
264
+ const ready=await privateRead(path.join(pending.versionRoot,'installation.json'));
265
+ if(ready?.payloadDigest!==pending.payloadDigest)fail('installed_files_invalid');
266
+ previous=pending;await atomicJSON(currentFile,pending);await rm(pendingFile);
267
+ }
161
268
  const official=await officialNpmInstallation(state.installed??[],servers,env,profile,configFile);
162
- if(official){if(installed||previous)fail('existing_registration_requires_review');return official;}
269
+ if(official){
270
+ if(installed||previous)fail('existing_registration_requires_review');
271
+ const compared=compareVersions(official.version,payload.version);
272
+ if(compared<0){
273
+ // Codex 0.160 plugin add replaces npm caches and removes the old version.
274
+ // We cannot infer whether other chats still use it. Do not silently call it
275
+ // or claim the requested version is installed; leave host-owned files alone.
276
+ fail('npm_plugin_upgrade_required',{installedVersion:official.version,requestedVersion:payload.version,
277
+ pluginId:official.pluginId,action:'upgrade_in_codex_after_active_bridges_finish',
278
+ next:'当前 npm 来源插件仍是旧版。确认使用该插件的活动聊天和桥已结束后,在 Codex 更新原插件目录并升级同一插件;核对实际版本,再运行 connect。具体步骤见 docs/installing.md;不要删除缓存或重新生成 Token。'});
279
+ }
280
+ await verifyInstalledRuntime(official.versionRoot,official.version,'node',{env});
281
+ return{...official,requestedVersion:payload.version,versionStatus:compared>0?'newer_retained':'current'};
282
+ }
163
283
  const recorded=await managedTransport(installed,versions,serverName,profile,configFile);
164
284
  if(legacy.some(x=>{
165
285
  if(x.name!==serverName)return false;
166
286
  return !recorded||!sameTransport(x.transport,recorded);
167
287
  }))fail('legacy_mcp_entry_requires_review');
288
+ if(state.installed.some(p=>p.pluginId!==pluginId))fail('existing_registration_requires_review');
289
+ if(installed&&compareVersions(installed.version,payload.version)>0){
290
+ if(!previous||previous.version!==installed.version||previous.versionRoot!==installed.source.path||installed.enabled!==true)
291
+ fail('existing_registration_requires_review');
292
+ await verifyInstalledRuntime(previous.versionRoot,previous.version,recorded.command,{env});
293
+ return{...previous,currentFile,reused:true,installedFiles:0,registered:true,reloadRequired:false,
294
+ requestedVersion:payload.version,versionStatus:'newer_retained',recordedRuntimeRetained:recorded.command!==process.execPath};
295
+ }
168
296
  const target=await info(versionRoot);
169
297
  if(target){
170
298
  if(!target.isDirectory()||target.isSymbolicLink())fail('version_content_conflict');
@@ -190,36 +318,39 @@ export async function installForUser({sourceRoot,profile='default',env=process.e
190
318
  await atomicJSON(path.join(temporary,'installation.json'),{version:payload.version,profile,configFile,payloadDigest:payload.payloadDigest,files});
191
319
  signal?.throwIfAborted();await rename(temporary,versionRoot);newFiles=payload.files.length;
192
320
  }
321
+ if(newFiles===0){
322
+ const launch=(await json(path.join(versionRoot,'.mcp.json'))).mcpServers?.[serverName];
323
+ await verifyInstalledRuntime(versionRoot,payload.version,launch.command,{env});
324
+ }
193
325
  const complete={version:payload.version,profile,configFile,pluginId,versionRoot,payloadDigest:payload.payloadDigest};
194
326
  const already=previous?.version===payload.version&&previous.payloadDigest===payload.payloadDigest&&installed?.version===payload.version&&installed.enabled===true;
195
327
  if(!already){
196
328
  const catalog={name:marketplace,interface:{displayName:'PromptFrame Creation'},plugins:[{name:pluginName,
197
329
  source:{source:'local',path:'./versions/'+payload.version},policy:{installation:'AVAILABLE',authentication:'ON_USE'},category:'Productivity'}]};
198
- await atomicJSON(marketplaceFile,catalog);signal?.throwIfAborted();registrationStarted=true;
330
+ await atomicJSON(marketplaceFile,catalog);signal?.throwIfAborted();
331
+ // Persist the exact identity before either registration write. An unknown
332
+ // reply is reconciled by reads on the next connect, never another add here.
333
+ await atomicJSON(pendingFile,complete);registrationStarted=true;
199
334
  await runCodex(['plugin','marketplace','add',root,'--json']);
200
335
  await runCodex(['plugin','add',pluginId,'--json']);
201
- const observed=JSON.parse(await runCodex(['plugin','list','--json'])).installed?.find(x=>x.pluginId===pluginId);
336
+ const observed=(await relatedPlugins(runCodex,pluginName,env)).find(x=>x.pluginId===pluginId);
202
337
  if(observed?.version!==payload.version||observed.enabled!==true)fail('registration_unconfirmed');
203
- await atomicJSON(currentFile,complete);
338
+ const launch=await managedTransport(observed,versions,serverName,profile,configFile);
339
+ const hostMcp=await codexJSON(runCodex,['mcp','list','--json']);
340
+ if(!Array.isArray(hostMcp))fail('registration_unconfirmed');
341
+ const effective=hostMcp.filter(x=>x.name===serverName);
342
+ if(effective.length!==1||effective[0].enabled===false||!sameTransport(effective[0].transport,launch))fail('registration_unconfirmed');
343
+ await atomicJSON(currentFile,complete);await rm(pendingFile);
204
344
  }
205
- return{...complete,currentFile,reused:newFiles===0,installedFiles:newFiles,registered:true,reloadRequired:!already,
345
+ return{...complete,currentFile,requestedVersion:payload.version,versionStatus:'current',reused:newFiles===0,installedFiles:newFiles,registered:true,reloadRequired:!already,
206
346
  recordedRuntimeRetained:Boolean(already&&recorded&&recorded.command!==process.execPath)};
207
347
  }catch(error){
208
348
  if(registrationStarted){
209
- // A lost command result may already have installed the complete candidate.
210
- // Keep all versions and the old default; never delete a possibly running copy.
211
- if(previousCatalog){
212
- await atomicJSON(marketplaceFile,previousCatalog);
213
- // Compensate only our exact earlier registration. If the command outcome
214
- // cannot be verified, report pending; the old files/default remain intact.
215
- if(previous){try{
216
- await runCodex(['plugin','add',pluginId,'--json']);
217
- const restored=JSON.parse(await runCodex(['plugin','list','--json'])).installed?.find(x=>x.pluginId===pluginId);
218
- if(restored?.version!==previous.version||restored.enabled!==true)fail('registration_unconfirmed');
219
- }catch{ /* No deletion, retry loop, token replacement or claim of restoration. */ }}
220
- }
221
- else await rm(marketplaceFile,{force:true});
222
- fail('registration_unconfirmed_keep_existing');
349
+ // Preserve the candidate catalog, old default, files and exact pending
350
+ // identity. Restoring a catalog and adding again could replay a committed
351
+ // write whose ACK was lost. Only a read may settle this attempt.
352
+ fail('registration_unconfirmed_keep_existing',{...installationErrorDetails(error),
353
+ phase:'registration_observation',localRegistrationState:'unknown',action:'inspect_same_registration_no_second_add'});
223
354
  }
224
355
  if(error instanceof CreationClientError)throw error;
225
356
  if(signal?.aborted)fail('interrupted_keep_existing');
package/lib/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const CLIENT_VERSION = "0.2.2";
1
+ export const CLIENT_VERSION = "0.2.4";
2
2
  export const CLIENT_PROTOCOL = "creation-client/v1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptframe/creation",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "private": false,
5
5
  "description": "PromptFrame video creation Skill, Codex plugin and MCP client bridge.",
6
6
  "repository": {
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@modelcontextprotocol/sdk": "1.32.1",
38
- "esbuild": "0.27.7"
38
+ "esbuild": "0.27.7",
39
+ "smol-toml": "1.9.1"
39
40
  }
40
41
  }
@@ -7,7 +7,7 @@ description: 安装、连接或升级 PromptFrame Creation 的 Codex 插件,
7
7
 
8
8
  使用 Studio“连接与授权”提供的完整 API 地址及公开安装入口。保留用户当前环境的 origin 和 `/api`,不替换成 localhost,不从旧聊天猜另一账号或环境。
9
9
 
10
- 在用户本机终端运行 `npx --yes @promptframe/creation connect --endpoint <Studio提供的API地址>`。需要隔离另一个环境或账号时显式加 `--profile <用户选择的名称>`;正在运行的桥不会切换。此命令管理用户级版本和 Codex 插件,不向当前项目安装依赖。
10
+ 在用户本机终端运行 `npx --yes @promptframe/creation@0.2.3 connect --endpoint <Studio提供的API地址>`。需要隔离另一个环境或账号时显式加 `--profile <用户选择的名称>`;正在运行的桥不会切换。此命令管理用户级版本和 Codex 插件,不向当前项目安装依赖。优先使用 Studio 当前提供的固定推荐版本;每次重新进入此入口比较已安装版本,不后台追踪 latest,也不把旧聊天里的命令当最新版本。已安装更新版不默认降级。
11
11
 
12
12
  命令会复用并验证有效凭据。首次授权或明确更换已失效凭据时,由用户在 Studio 登录并在终端的不回显输入框提供 Token;不要要求用户把 Token 粘进聊天,也不要把它写进命令参数、URL或日志。网络失败不等于授权失效,不自动轮换或覆盖凭据。
13
13
 
@@ -17,4 +17,6 @@ description: 安装、连接或升级 PromptFrame Creation 的 Codex 插件,
17
17
 
18
18
  如需自行开发组件,沿 README 的独立组件 authoring Skill/CLI;普通创作与平台组件复用不要求安装四个组件包。
19
19
 
20
+ 官方 npm 来源旧插件返回 `installation.npm_plugin_upgrade_required` 时,升级尚未完成;按包内安装说明处理原插件,不再创建第二个入口。`setup` 仅管理凭据,不能代替 `connect` 的插件安装和版本检查。
21
+
20
22
  出现 `installation.*` 或 `setup.*` 时保留旧版本、凭据及明确错误。不要删除不明配置、终止其它聊天或反复重装追绿。卸载和排障见包内[安装与排障](../../docs/installing.md)。
@@ -7,7 +7,7 @@ description: 在 PromptFrame 中调研、规划、制作和接续视频,复用
7
7
 
8
8
  ## 连接与选择作品
9
9
 
10
- 未连接时按仓库 README 运行 setup,提供用户选择的平台 API 地址。凭据只交本地 setup 的安全输入,不写聊天、源码、命令行参数或 MCP 业务参数。创作 Token 与组件上传凭据用途不同,也不是 OAuth `mcp login`。
10
+ 未连接时先按 creation-setup Skill 和 Studio 当前固定版本指引运行 `connect`,提供用户选择的平台 API 地址。`setup` 只处理凭据,不能代替插件注册。凭据只交本地连接流程的安全输入,不写聊天、源码、命令行参数或 MCP 业务参数。创作 Token 与组件上传凭据用途不同,也不是 OAuth `mcp login`。
11
11
 
12
12
  使用平台项目和作品列表选择目标。新作品使用稳定的幂等请求键;已有作品先读取最新历史、Plan、Spec、素材和在途任务,再申请编辑权,由本人在 Studio 确认。不要修改已有作品的运行时来换端。断线和思考不代表释放编辑权。
13
13
 
@@ -39,6 +39,12 @@ CLI 的端点与组件上传授权按其公开说明配置,创作 Token 不代
39
39
 
40
40
  费用以平台原 receipt/账务读面为准,区分实计、预留、待结算和未知。成功媒体、工具终态和财务终态可以不同;未知不是免费。平台工具调用与外部自费推理/素材费用分开说明。
41
41
 
42
+ ## 旁白与字幕
43
+
44
+ 整篇旁白先发现当前平台的规划与绑定工具,提交完整正文并核其真实能力限制。平台支持时,默认按句/段语义规划,短旁白可整段;音频段、字幕行和分镜不必一一对应。按计划使用同一音色版本及公共参数,每个合成调用只对应一个明确段和原报价。
45
+
46
+ 保存每段原文范围、有效发声文本、原计划及已采用资产/operation。局部改文案沿原计划保持音色版本、seed 和公共参数,优先复用未改的成功段;结果未知只核原任务,不能重新生成追结果。字幕分块、样式或时序修复只绑定现有音频,不重TTS;仅凭时长估算仍标明estimated,不能冒精确逐字时间。当前目录未提供相关工具时准确说明限制,不在客户端另建合成队列或参数副本。
47
+
42
48
  ## 接回与完成
43
49
 
44
50
  交接前可保存简明外部报告,随后释放自己当前代次的编辑权。没有报告也不阻止本人从 Studio 接回。旧订单可按原事实收尾、晚结果入素材与原账;旧客户端不能覆盖新 Spec。