@promptframe/creation 0.1.1 → 0.2.1
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/.agents/plugins/marketplace.json +10 -3
- package/.codex-plugin/plugin.json +10 -3
- package/README.md +27 -58
- package/bin/promptframe-creation.mjs +5 -226
- package/dist/THIRD_PARTY_NOTICES.txt +276 -0
- package/dist/cli.mjs +20324 -0
- package/dist/cli.mjs.LEGAL.txt +8 -0
- package/docs/development.md +46 -0
- package/docs/installing.md +43 -0
- package/docs/releases/0.2.1.md +7 -0
- package/docs/releasing.md +7 -1
- package/lib/cli.mjs +258 -0
- package/lib/connection.mjs +5 -1
- package/lib/host-context.mjs +125 -0
- package/lib/user-installation.mjs +174 -0
- package/lib/version.mjs +2 -0
- package/package.json +7 -4
- package/skills/creation-setup/SKILL.md +20 -0
- package/skills/video-creation/SKILL.md +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# 客户端与插件开发维护
|
|
2
|
+
|
|
3
|
+
本仓维护公开创作 Skill、setup、凭据处理、本地 MCP 薄桥和插件声明。平台业务与任务仍由平台 API 执行。开发者先读 AGENTS,确认实际 Git 根、origin、分支和差额,再修改本次任务相关路径。
|
|
4
|
+
|
|
5
|
+
## 源码路由
|
|
6
|
+
|
|
7
|
+
| 内容 | 入口 |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| 命令和 stdio 桥 | `bin/promptframe-creation.mjs`预检 → `lib/cli.mjs` / `dist/cli.mjs`自包含构建 |
|
|
10
|
+
| 用户级安装与profile | `lib/user-installation.mjs` |
|
|
11
|
+
| 依赖闭包/许可证 | `scripts/build-runtime.mjs` |
|
|
12
|
+
| 环境地址与安全凭据 | `lib/credentials.mjs` |
|
|
13
|
+
| 平台 MCP HTTP 连接 | `lib/connection.mjs` |
|
|
14
|
+
| 当前源码的宿主 thread 与控制版本接线 | `lib/host-context.mjs` |
|
|
15
|
+
| 插件加载与启动 | `.codex-plugin/plugin.json`、`.mcp.json` |
|
|
16
|
+
| 公开视频创作规则 | `skills/video-creation/SKILL.md` |
|
|
17
|
+
| 插件目录索引 | `.agents/plugins/marketplace.json` |
|
|
18
|
+
| 发行内容、版本约束与同包核验 | `scripts/package-release.mjs`、`.github/workflows/ci.yml`、`.github/workflows/publish.yml` |
|
|
19
|
+
|
|
20
|
+
## 三种版本分别核实
|
|
21
|
+
|
|
22
|
+
1. 当前工作分支的源码 ref 和未提交差额。
|
|
23
|
+
2. 已发行 npm 包对应的固定 tag、registry 版本和 integrity/provenance。
|
|
24
|
+
3. 用户宿主实际加载的插件缓存、Skill 和 MCP 连接。
|
|
25
|
+
|
|
26
|
+
已有 `0.1.1` npm 包固定在 `creation-v0.1.1` / `3da232e267117794fcbcbb1920cbdf9f3f294c14`。后续源码即使尚未 bump package 版本,也不属于这个不可变包。文档描述新宿主行为时注明源码范围;真实发行时按[发布手册](releasing.md)同步包/lock/插件版本并使用新标签。
|
|
27
|
+
|
|
28
|
+
## 安装与运行路径
|
|
29
|
+
|
|
30
|
+
当前源码的宿主桥为四个内置只读工具读取真实作品控制版本作为请求元信息;Web或另一线程持写时仍可在原读权限内查询。该版本不会缓存成自己的编辑权。平台还须以当前工具注册表的只读属性及原白名单双重核验,写操作继续要求本线程已获编辑权;模型不能提供控制版本或声明只读来绕过。此源码行为不代表固定npm0.1.1已经包含。
|
|
31
|
+
|
|
32
|
+
源码经 GitHub Actions 打包发行到 npm;插件目录记录包名/版本或源码位置。安装后,Codex 加载本地副本并按配置启动 Node 桥;桥通过 stdio 接收调用,读取独立安全配置,再通过 HTTPS MCP 连接所选平台。GitHub、npm 与目录索引负责获取版本,不进入正常工具调用链。Token 不进入源码、插件包或命令参数。
|
|
33
|
+
|
|
34
|
+
0.2.1公开目录固定npm来源;`connect`另以用户级受管版本注册本地插件。`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
|
+
|
|
36
|
+
## 相称验证
|
|
37
|
+
|
|
38
|
+
- 普通源码检查使用本仓 `npm ci --ignore-scripts`、`npm test` 和[发布手册](releasing.md)的 pack/smoke;测试使用临时配置目录。
|
|
39
|
+
- 修改宿主接线时核实际宿主元数据、缺失身份和多聊天隔离,不要求模型记忆身份字段;源码控制与真实宿主旅程分别记录。
|
|
40
|
+
- 修改插件内容或安装流程时,从无既有依赖/凭据污染的目标环境核 manifest、Skill、桥启动和平台连接;保持现有有效凭据,升级不默认轮换 Token。
|
|
41
|
+
- 普通打包/文档检查不调用真实平台 setup、生成媒体或模型。真实接入、任务和费用按当前实际授权执行;Skill 或 README 本身不授予权限。
|
|
42
|
+
- 只改文档不自动发包或更新服务。交付说明记录源码、技术检查、registry 发行、宿主注册和真实创作的实际结果,未做项保持未验证。
|
|
43
|
+
|
|
44
|
+
## 公开范围
|
|
45
|
+
|
|
46
|
+
使用说明保持公开且可移植。平台私有配置、真实端点默认值、用户样本、Token、内部协作材料和业务权限实现不进入本仓。组件创作需要的工具按 README 指向独立 authoring 仓;不在本仓维护第二套组件 CLI 参数手册或四包发行流程。
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# 安装、连接与升级
|
|
2
|
+
|
|
3
|
+
需要 Node.js 20+、支持插件命令的 Codex(本版最低0.160.0),以及可以访问 Studio 的网络。原生 Windows ACL 尚未验证;Linux、WSL、macOS 使用用户目录和私有文件权限,不需要 sudo。
|
|
4
|
+
|
|
5
|
+
从 Studio 的“连接与授权”复制当前环境的指引。在本机终端执行:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx --yes @promptframe/creation@0.2.1 connect --endpoint <Studio提供的API地址>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`/api` 会规范化到 `/api/mcp`;也可直接提供 `/api/mcp`。保留 Studio 实际可达的 HTTPS origin,包括私有网络域名,不把远程地址替换成本机 localhost。`0.1.1` 是历史基础包;它不支持此用户级插件引导。新版本是否已发行,以 registry 的实际版本和对应固定标签为准。
|
|
12
|
+
|
|
13
|
+
首次连接由用户在 Studio 生成创作授权,在终端隐藏输入框输入 Token。自动化可从受限管道使用 `--token-stdin`,不得把 Token 放在参数、聊天、URL、业务仓或日志中。已有有效凭据直接验证复用;失败时保留原凭据,不自动撤销或轮换。仅明确替换时使用 `setup --replace`。
|
|
14
|
+
|
|
15
|
+
连接入口校验完整包,把自包含运行文件、插件声明及两个 Skill 放入用户级版本目录,通过 `codex plugin marketplace add` 和 `codex plugin add` 注册并核回已启用版本。无需在当前业务仓运行 npm install,也不依赖开发者的 node_modules。目录注册成功与当前聊天已加载分别报告:首次安装或升级后正常重载插件或开新聊天,确认 creation-setup、video-creation 和 MCP 工具均可见。
|
|
16
|
+
|
|
17
|
+
## 环境与账号
|
|
18
|
+
|
|
19
|
+
默认凭据沿用 `$XDG_CONFIG_HOME/promptframe-creation/credentials.json`(未配置 XDG 时位于用户 `.config`)。旧的 `PROMPTFRAME_CREATION_CONFIG` 仍可显式引用安全文件。
|
|
20
|
+
|
|
21
|
+
另一个环境或账号应由用户选择不同名称:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx --yes @promptframe/creation@0.2.1 connect --profile work-account --endpoint <另一环境API地址>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
命名 profile 使用独立凭据和独立插件名;新桥配置固定具体凭据文件。已有文件绑定另一 endpoint 时拒绝覆盖,运行中的桥也不会热切环境。相同 endpoint 的不同账号同样用不同 profile;不要尝试从 Token 或作品名猜账号。`--config <安全文件>` 可指定已存在的私有配置,但不得把不同环境指向同一文件。
|
|
28
|
+
|
|
29
|
+
## 版本与失败
|
|
30
|
+
|
|
31
|
+
每个 profile 的安装位于 `$XDG_DATA_HOME/promptframe-creation/<profile>`(默认用户 `.local/share`),版本在 `versions/<version>`。同版本完整内容复用,不再次下载运行依赖;两个入口串行合并。新版本先完整准备和检查,再注册并原子更新 `current.json`。旧版本及其依赖保留,不覆盖、不枚举或终止其它聊天。
|
|
32
|
+
|
|
33
|
+
更新失败保留旧默认、旧文件及 Token。`registration_unconfirmed_keep_existing` 表示宿主命令结果未确认;先核 Codex 当前插件状态,不根据错误盲重发或删除缓存。普通重试会核原完整版本和实际宿主状态。只在确认本工具 `install.lock/owner.json` 的进程已退出后,才手动移除该精确安装锁并重试;活动或无法确认的进程不清锁。安装锁不决定平台编辑权。
|
|
34
|
+
|
|
35
|
+
从旧手工 `codex mcp add promptframe` 迁移时,若发现同名定义,引导会停止并给出 `legacy_mcp_entry_requires_review`,不会删除不明配置。确认它是旧的 PromptFrame 手工入口后可用 `codex mcp remove promptframe` 移除定义,再重复 connect。移除定义不取消已接受平台任务、不撤销 Token;在途桥及原结果应沿原 task 观察。
|
|
36
|
+
|
|
37
|
+
卸载用户级默认插件:`codex plugin remove promptframe-creation@promptframe-creation-user`。命名 profile 的插件和目录名带该 profile 后缀,可先 `codex plugin list` 查看准确 ID。按需用 `codex plugin marketplace remove <准确目录名>` 移除入口。卸载不撤销授权、不取消订单,旧版本也不自动删除;确认无桥进程使用后再清理相应版本目录。撤销 Token 仍由本人在 Studio 操作。
|
|
38
|
+
|
|
39
|
+
## 开始创作
|
|
40
|
+
|
|
41
|
+
安装不接管作品、不派发制作。让新聊天按 video-creation 读取当前项目、作品及 schema;已有作品正常申请本人确认,新建空作品沿用户意图。工具调用的宿主 thread 身份由 Codex 自动提供,模型不用填写身份、权限或控制版本。对原 task 的观察与新写入分开:不兼容版本的新写入应升级后再做,原任务不重派、不丢失。
|
|
42
|
+
|
|
43
|
+
组件复用通过平台目录和 schema;确需开发组件时使用 README 指向的独立 authoring Skill/CLI。MCP 连接不要求安装组件四包。
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# 0.2.1
|
|
2
|
+
|
|
3
|
+
本版提供自包含的 Codex 插件运行文件、用户级 connect 安装、setup/video-creation 两类 Skill、独立环境/账号 profile 和版本目录升级。已有有效凭据复用,旧桥与旧文件不因升级被覆盖。使用方法见[安装说明](../installing.md)。具体发行及宿主验证范围仍按 registry、固定标签和真实安装结果核实。
|
|
4
|
+
|
|
5
|
+
0.2.0 的固定标签保留。其正式 run [39998826031](https://github.com/ty-teams/promptframe-creation/actions/runs/39998826031) 在“安装依赖之前验证标签”步骤因提前导入 esbuild 失败;npm ci、打包、artifact 上传和 publish 均未执行。0.2.1 将构建依赖延迟到 pack 调用内,并增加无 node_modules 的标签预检回归。发布 job 继续只用 Node 和原已核 artifact,不更改 OIDC、账号信任或既有标签。
|
|
6
|
+
|
|
7
|
+
历史0.1.1基础包及其固定来源保持。插件注册、平台连接、宿主加载与完整创作分别验证;本版说明不代表所有操作系统或完整作品验收通过。
|
package/docs/releasing.md
CHANGED
|
@@ -15,6 +15,12 @@ node scripts/package-release.mjs smoke /tmp/creation-package
|
|
|
15
15
|
|
|
16
16
|
安装包必须包含运行脚本、Skill、三个隐藏插件入口、README 和 LICENSE;排除测试、工作流、发行脚本及个人配置。隔离安装会从 registry 安装普通依赖并运行 `--help`,只使用临时配置目录。此项不代表特定宿主插件缓存、原生 Windows ACL 或完整创作旅程已经验收。
|
|
17
17
|
|
|
18
|
+
## npm 安装与宿主插件安装的验证范围
|
|
19
|
+
|
|
20
|
+
现有 `smoke` 明确执行普通 `npm install`,由 npm 补齐 `package.json.dependencies` 后运行 CLI。Codex 的 npm 来源插件安装在已核[官方实现](https://github.com/openai/codex/blob/de06fd0be4f465bc28c3111bdadaabda5dfdebcd/codex-rs/core-plugins/src/npm_source.rs)中使用 `npm pack --ignore-scripts` 后解包,不执行相同的依赖安装步骤。
|
|
21
|
+
|
|
22
|
+
0.2.1由`build-runtime.mjs`显式生成自包含运行文件,SDK为构建/测试依赖;`pack`先构建再按既有ignore-scripts打包。包必须含dist运行文件/许可证、两个Skill及插件入口,不能依赖安装后脚本。CI同时核纯解包运行;真实Codex npm来源安装、Skill发现和MCP启动仍分别记录,不用普通npm install smoke替代。用户级安装见[安装说明](installing.md)。
|
|
23
|
+
|
|
18
24
|
## 一次性发布配置
|
|
19
25
|
|
|
20
26
|
GitHub 仓库创建 Environment `npm-production`,部署规则只允许 `creation-v*` 标签。无需 npm 长期发布 Token。npm 账号所有者完成新包初始化后,在该包的 Trusted Publisher 页面配置:
|
|
@@ -38,7 +44,7 @@ GitHub 仓库创建 Environment `npm-production`,部署规则只允许 `creati
|
|
|
38
44
|
|
|
39
45
|
在 GitHub Actions 手工运行 **Publish Creation** 是无发布的检查:测试、打包、隔离安装并保存7天artifact。只有 `creation-v<version>` 标签的 push 能进入正式发布,手工运行不会发布 npm。
|
|
40
46
|
|
|
41
|
-
正式发行前以一个正常提交完成:`private: false`,同步 package.json、package-lock.json
|
|
47
|
+
正式发行前以一个正常提交完成:`private: false`,同步 package.json、package-lock.json、插件manifest、npm目录source.version及lib/version.mjs中的CLIENT_VERSION,并验证当前版本所承诺的功能。当前流程接受稳定 `X.Y.Z` 版本。将该提交合入 main,再创建匹配标签,例如 `creation-v0.1.1`;无需为测试这套工作流提前推正式标签。
|
|
42
48
|
|
|
43
49
|
正式tag必须属于 main 历史。打包job没有OIDC权限;通过检查的同一个tgz及manifest传给独立publish job,后者才取得 `id-token: write`。publish job使用Node24自带兼容npm,通过OIDC向官方registry发布public包,禁用脚本并生成provenance。源码commit、包/lock/插件版本、tag及SHA-512 integrity必须一致;不在发布时重新打包。
|
|
44
50
|
|
package/lib/cli.mjs
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {CLIENT_VERSION} from "./version.mjs";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
|
+
import {
|
|
8
|
+
CallToolRequestSchema,
|
|
9
|
+
ListToolsRequestSchema,
|
|
10
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
+
import {
|
|
12
|
+
CreationClientError,
|
|
13
|
+
normalizeEndpoint,
|
|
14
|
+
readCredentials,
|
|
15
|
+
writeCredentials,
|
|
16
|
+
} from "./credentials.mjs";
|
|
17
|
+
import { connectPlatform } from "./connection.mjs";
|
|
18
|
+
import { createHostCallBridge } from "./host-context.mjs";
|
|
19
|
+
import {installForUser,profileCredentialsPath} from './user-installation.mjs';
|
|
20
|
+
import {fileURLToPath} from 'node:url';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2),
|
|
24
|
+
command = args.shift(),
|
|
25
|
+
value = (key) => {
|
|
26
|
+
const i = args.indexOf(key);
|
|
27
|
+
return i < 0 ? undefined : args[i + 1];
|
|
28
|
+
};
|
|
29
|
+
const log = (value) => process.stdout.write(JSON.stringify(value) + "\n");
|
|
30
|
+
const configFile=()=>value('--config')?path.resolve(value('--config')):
|
|
31
|
+
profileCredentialsPath(value('--profile')??'default');
|
|
32
|
+
async function probe(credentials) {
|
|
33
|
+
const client = await connectPlatform(credentials);
|
|
34
|
+
try {
|
|
35
|
+
return (await client.listTools()).tools.length;
|
|
36
|
+
} finally {
|
|
37
|
+
await client.close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function tokenInput() {
|
|
41
|
+
if (args.includes("--token-stdin")) {
|
|
42
|
+
let text = "";
|
|
43
|
+
for await (const chunk of process.stdin) {
|
|
44
|
+
text += chunk;
|
|
45
|
+
if (text.length > 4096) throw new CreationClientError("token.too_long");
|
|
46
|
+
}
|
|
47
|
+
return text.trim();
|
|
48
|
+
}
|
|
49
|
+
if (!process.stdin.isTTY || typeof process.stdin.setRawMode !== "function")
|
|
50
|
+
throw new CreationClientError(
|
|
51
|
+
"setup.interactive_tty_or_token_stdin_required",
|
|
52
|
+
);
|
|
53
|
+
process.stderr.write("创作 Token(不回显):");
|
|
54
|
+
const input = process.stdin,
|
|
55
|
+
wasRaw = input.isRaw;
|
|
56
|
+
input.setRawMode(true);
|
|
57
|
+
input.resume();
|
|
58
|
+
try {
|
|
59
|
+
return await new Promise((resolve, reject) => {
|
|
60
|
+
let text = "";
|
|
61
|
+
const read = (chunk) => {
|
|
62
|
+
for (const byte of chunk) {
|
|
63
|
+
if (byte === 3) {
|
|
64
|
+
finish();
|
|
65
|
+
reject(new CreationClientError("setup.cancelled"));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (byte === 10 || byte === 13) {
|
|
69
|
+
finish();
|
|
70
|
+
resolve(text);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (byte === 8 || byte === 127) text = text.slice(0, -1);
|
|
74
|
+
else if (byte >= 32 && byte <= 126) text += String.fromCharCode(byte);
|
|
75
|
+
if (text.length > 4096) {
|
|
76
|
+
finish();
|
|
77
|
+
reject(new CreationClientError("token.too_long"));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const finish = () => {
|
|
83
|
+
input.removeListener("data", read);
|
|
84
|
+
input.pause();
|
|
85
|
+
};
|
|
86
|
+
input.on("data", read);
|
|
87
|
+
});
|
|
88
|
+
} finally {
|
|
89
|
+
input.setRawMode(Boolean(wasRaw));
|
|
90
|
+
process.stderr.write("\n");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function setup({silent=false}={}) {
|
|
94
|
+
const file = configFile(),
|
|
95
|
+
existing = await readCredentials(file),
|
|
96
|
+
requested = value("--endpoint");
|
|
97
|
+
const endpoint = normalizeEndpoint(requested ?? existing?.endpoint ?? "");
|
|
98
|
+
if (existing && existing.endpoint !== endpoint)
|
|
99
|
+
throw new CreationClientError(
|
|
100
|
+
"setup.different_endpoint_requires_separate_config",
|
|
101
|
+
);
|
|
102
|
+
if (existing && !args.includes("--replace")) {
|
|
103
|
+
try {
|
|
104
|
+
const tools = await probe(existing);
|
|
105
|
+
const result={connected:true,reused:true,endpoint,tools};
|
|
106
|
+
if(!silent)log(result);
|
|
107
|
+
return result;
|
|
108
|
+
} catch {
|
|
109
|
+
throw new CreationClientError(
|
|
110
|
+
"setup.saved_credential_unverified_retry_or_explicit_replace",
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const studio = new URL(endpoint);
|
|
115
|
+
studio.pathname = studio.pathname.replace(/\/api\/mcp$/, "/studio");
|
|
116
|
+
studio.search = "?connectExternal=1";
|
|
117
|
+
process.stderr.write(
|
|
118
|
+
"在 Studio 登录,在“连接外部 Agent”生成或复制创作 Token。重复 setup 不会自动轮换。\n" +
|
|
119
|
+
studio.href +
|
|
120
|
+
"\n",
|
|
121
|
+
);
|
|
122
|
+
if (!args.includes("--no-open")) {
|
|
123
|
+
const executable =
|
|
124
|
+
process.platform === "darwin"
|
|
125
|
+
? "open"
|
|
126
|
+
: process.platform === "linux"
|
|
127
|
+
? "xdg-open"
|
|
128
|
+
: null;
|
|
129
|
+
if (executable) {
|
|
130
|
+
const child = spawn(executable, [studio.href], {
|
|
131
|
+
stdio: "ignore",
|
|
132
|
+
detached: true,
|
|
133
|
+
});
|
|
134
|
+
child.on("error", () => {});
|
|
135
|
+
child.unref();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const token = await tokenInput();
|
|
139
|
+
if (!/^pf_create_[A-Za-z0-9_-]{43}$/.test(token))
|
|
140
|
+
throw new CreationClientError("token.invalid");
|
|
141
|
+
const credentials = {
|
|
142
|
+
version: 1,
|
|
143
|
+
endpoint,
|
|
144
|
+
token,
|
|
145
|
+
clientId: existing?.clientId ?? randomBytes(24).toString("base64url"),
|
|
146
|
+
clientName: value("--name") ?? existing?.clientName ?? "Codex PromptFrame",
|
|
147
|
+
createdAt: existing?.createdAt ?? new Date().toISOString(),
|
|
148
|
+
};
|
|
149
|
+
// Verify before replacing the secure local file. This never calls a token
|
|
150
|
+
// rotate API, starts a model, creates work or approves production.
|
|
151
|
+
const tools = await probe(credentials);
|
|
152
|
+
await writeCredentials(credentials, file);
|
|
153
|
+
const result={connected:true,reused:false,endpoint,tools};
|
|
154
|
+
if(!silent)log(result);
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
async function bridge() {
|
|
158
|
+
const credentials = await readCredentials(configFile());
|
|
159
|
+
if (!credentials) throw new CreationClientError("setup.required");
|
|
160
|
+
const client = await connectPlatform(credentials),
|
|
161
|
+
host = createHostCallBridge(client),
|
|
162
|
+
server = new Server(
|
|
163
|
+
{ name: "promptframe-creation", version: CLIENT_VERSION },
|
|
164
|
+
{ capabilities: { tools: {} } },
|
|
165
|
+
);
|
|
166
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
167
|
+
try {
|
|
168
|
+
return await host.listTools();
|
|
169
|
+
} catch {
|
|
170
|
+
throw new Error("creation.connection_unresolved");
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
174
|
+
try {
|
|
175
|
+
return await host.call(request.params);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
return {
|
|
178
|
+
isError: true,
|
|
179
|
+
content: [
|
|
180
|
+
{
|
|
181
|
+
type: "text",
|
|
182
|
+
text: JSON.stringify({
|
|
183
|
+
success: false,
|
|
184
|
+
errorCode: error instanceof CreationClientError
|
|
185
|
+
? error.message : "creation.connection_unresolved",
|
|
186
|
+
action: error instanceof CreationClientError
|
|
187
|
+
? error.message.startsWith("creation.host_")
|
|
188
|
+
? "use_supported_codex_plugin_with_host_thread_identity"
|
|
189
|
+
: error.message === "creation.editor_not_current"
|
|
190
|
+
? "request_control_and_confirm_in_studio"
|
|
191
|
+
: "read_current_platform_facts_without_replaying_business"
|
|
192
|
+
: "read_original_task_or_retry_same_idempotency_key",
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
let closing = false;
|
|
200
|
+
const close = async () => {
|
|
201
|
+
if (closing) return;
|
|
202
|
+
closing = true;
|
|
203
|
+
await server.close().catch(() => {});
|
|
204
|
+
await client.close().catch(() => {});
|
|
205
|
+
};
|
|
206
|
+
server.onclose = () => {
|
|
207
|
+
void close();
|
|
208
|
+
};
|
|
209
|
+
process.once("SIGINT", () => {
|
|
210
|
+
void close();
|
|
211
|
+
});
|
|
212
|
+
process.once("SIGTERM", () => {
|
|
213
|
+
void close();
|
|
214
|
+
});
|
|
215
|
+
await server.connect(new StdioServerTransport());
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
if (command === "setup") await setup();
|
|
219
|
+
else if(command==='connect'||command==='install'){
|
|
220
|
+
const connection=await setup({silent:true});
|
|
221
|
+
const signal=new AbortController();
|
|
222
|
+
const abort=()=>signal.abort();process.once('SIGINT',abort);process.once('SIGTERM',abort);
|
|
223
|
+
try{
|
|
224
|
+
const installed=await installForUser({sourceRoot:fileURLToPath(new URL('..',import.meta.url)),
|
|
225
|
+
profile:value('--profile')??'default',configFile:configFile(),signal:signal.signal});
|
|
226
|
+
log({...connection,pluginRegistered:installed.registered,version:installed.version,
|
|
227
|
+
installationReused:installed.reused,profile:installed.profile,
|
|
228
|
+
next: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.',
|
|
229
|
+
hostThreadIdentity:'verified_by_the_platform_on_actual_host_tool_calls'});
|
|
230
|
+
}finally{process.removeListener('SIGINT',abort);process.removeListener('SIGTERM',abort);}
|
|
231
|
+
}
|
|
232
|
+
else if (command === "bridge") await bridge();
|
|
233
|
+
else if(command==='--version')process.stdout.write(CLIENT_VERSION+'\n');
|
|
234
|
+
else if (command === "status") {
|
|
235
|
+
const saved = await readCredentials(configFile());
|
|
236
|
+
if (!saved) throw new CreationClientError("setup.required");
|
|
237
|
+
log({
|
|
238
|
+
connected: true,
|
|
239
|
+
endpoint: saved.endpoint,
|
|
240
|
+
tools: await probe(saved),
|
|
241
|
+
});
|
|
242
|
+
} else if (command === "help" || command === "--help" || !command) {
|
|
243
|
+
process.stdout.write(
|
|
244
|
+
"promptframe-creation connect --endpoint <platform-api-base> [--profile <environment-account>] [--no-open]\npromptframe-creation setup --endpoint <platform-api-base> [--no-open] [--replace] [--name <client-name>]\npromptframe-creation status [--profile <environment-account>]\npromptframe-creation bridge [--config <private-file>]\npromptframe-creation --version\nNode.js >=20 and Codex >=0.160.0 are required for user-level plugin installation. Token input is masked in a terminal or accepted through --token-stdin; never use a Token command argument.\n",
|
|
245
|
+
);
|
|
246
|
+
} else throw new CreationClientError("command.unknown");
|
|
247
|
+
} catch (error) {
|
|
248
|
+
// Never print raw SDK/fetch errors, response bodies or credentials.
|
|
249
|
+
process.stderr.write(
|
|
250
|
+
JSON.stringify({
|
|
251
|
+
error:
|
|
252
|
+
error instanceof CreationClientError
|
|
253
|
+
? error.message
|
|
254
|
+
: "creation.connection_failed",
|
|
255
|
+
}) + "\n",
|
|
256
|
+
);
|
|
257
|
+
process.exitCode = 1;
|
|
258
|
+
}
|
package/lib/connection.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
import {CLIENT_VERSION,CLIENT_PROTOCOL} from './version.mjs';
|
|
3
4
|
|
|
4
5
|
export async function connectPlatform(credentials) {
|
|
5
6
|
const client = new Client(
|
|
6
|
-
{ name: "promptframe-creation-bridge", version:
|
|
7
|
+
{ name: "promptframe-creation-bridge", version: CLIENT_VERSION },
|
|
7
8
|
{ capabilities: {} },
|
|
8
9
|
);
|
|
9
10
|
const transport = new StreamableHTTPClientTransport(
|
|
@@ -12,6 +13,9 @@ export async function connectPlatform(credentials) {
|
|
|
12
13
|
requestInit: {
|
|
13
14
|
headers: {
|
|
14
15
|
Authorization: "Bearer " + credentials.token,
|
|
16
|
+
"X-PromptFrame-Host-Kind": "codex",
|
|
17
|
+
"X-PromptFrame-Creation-Protocol": CLIENT_PROTOCOL,
|
|
18
|
+
"X-PromptFrame-Client-Version": CLIENT_VERSION,
|
|
15
19
|
"X-PromptFrame-Client-Id": credentials.clientId,
|
|
16
20
|
"X-PromptFrame-Client-Name": encodeURIComponent(
|
|
17
21
|
credentials.clientName,
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { CreationClientError } from "./credentials.mjs";
|
|
2
|
+
|
|
3
|
+
const observations = new Set([
|
|
4
|
+
"platform_list_projects", "platform_list_sessions", "platform_read_session",
|
|
5
|
+
"platform_list_tools", "platform_describe_tool", "platform_list_tasks",
|
|
6
|
+
"platform_task", "platform_read_budget",
|
|
7
|
+
]);
|
|
8
|
+
const threadFormat = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
9
|
+
|
|
10
|
+
export function hostParameters(params) {
|
|
11
|
+
const thread = params._meta?.threadId;
|
|
12
|
+
if (thread === undefined) {
|
|
13
|
+
if (observations.has(params.name)) return params;
|
|
14
|
+
throw new CreationClientError("creation.host_identity_required");
|
|
15
|
+
}
|
|
16
|
+
if (typeof thread !== "string" || !threadFormat.test(thread))
|
|
17
|
+
throw new CreationClientError("creation.host_identity_invalid");
|
|
18
|
+
return params;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const controlled = new Set([
|
|
22
|
+
"platform_call_tool", "platform_save_brief", "platform_release_control", "platform_handoff",
|
|
23
|
+
]);
|
|
24
|
+
// Candidates only: the platform still checks its current registry isReadOnly
|
|
25
|
+
// flag and built-in allowlist. A model-supplied readOnly flag grants nothing.
|
|
26
|
+
const independentReads = new Set([
|
|
27
|
+
"read_spec", "read_creative_plan", "get_creative_plan", "list_assets",
|
|
28
|
+
]);
|
|
29
|
+
const authorityReads = new Set([
|
|
30
|
+
"platform_create_session", "platform_read_session", "platform_request_control",
|
|
31
|
+
"platform_release_control", "platform_handoff",
|
|
32
|
+
]);
|
|
33
|
+
const data = (result) => {
|
|
34
|
+
const text = result.content?.find((part) => part.type === "text")?.text;
|
|
35
|
+
try { return text ? JSON.parse(text) : null; } catch { return null; }
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** A bridge process freezes its endpoint/account/installation credentials at
|
|
39
|
+
* startup. Inside that boundary each host thread and work has its own approved
|
|
40
|
+
* generation cache. Cache loss only causes an authoritative ownership read;
|
|
41
|
+
* neither that read nor a schema refresh requests or grants control. */
|
|
42
|
+
export function createHostCallBridge(client) {
|
|
43
|
+
const versions = new Map();
|
|
44
|
+
const keyFor = (params) => {
|
|
45
|
+
const { projectId, sessionId } = params.arguments ?? {};
|
|
46
|
+
if (typeof projectId !== "string" || typeof sessionId !== "string"
|
|
47
|
+
|| !projectId || !sessionId || projectId.length > 160 || sessionId.length > 160)
|
|
48
|
+
return null;
|
|
49
|
+
return JSON.stringify([params._meta?.threadId?.toLowerCase(), projectId, sessionId]);
|
|
50
|
+
};
|
|
51
|
+
const remember = (params, result) => {
|
|
52
|
+
if (!authorityReads.has(params.name)) return;
|
|
53
|
+
const value = data(result);
|
|
54
|
+
if (result.isError || !value) return;
|
|
55
|
+
const target = params.name === "platform_create_session"
|
|
56
|
+
&& value.projectId === params.arguments?.projectId && typeof value.sessionId === "string"
|
|
57
|
+
? { ...params, arguments: { ...params.arguments, sessionId: value.sessionId } } : params;
|
|
58
|
+
const key = keyFor(target);
|
|
59
|
+
if (!key || !value.control) return;
|
|
60
|
+
if (params.name === "platform_read_session" && value.sessionId !== params.arguments.sessionId) {
|
|
61
|
+
versions.delete(key);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const control = value.control;
|
|
65
|
+
if (control.editor?.kind === "client" && control.editor.isCurrentClient === true
|
|
66
|
+
&& Number.isSafeInteger(control.controlVersion) && control.controlVersion > 0) {
|
|
67
|
+
versions.delete(key);
|
|
68
|
+
if (versions.size >= 1024) versions.delete(versions.keys().next().value);
|
|
69
|
+
versions.set(key, control.controlVersion);
|
|
70
|
+
} else versions.delete(key);
|
|
71
|
+
};
|
|
72
|
+
const send = (params) => client.callTool(params, undefined, { timeout: 60_000 });
|
|
73
|
+
return {
|
|
74
|
+
async listTools() {
|
|
75
|
+
const result = await client.listTools();
|
|
76
|
+
return { ...result, tools: result.tools.map((tool) => {
|
|
77
|
+
if (!controlled.has(tool.name)) return tool;
|
|
78
|
+
const { controlVersion: _managed, ...properties } = tool.inputSchema.properties ?? {};
|
|
79
|
+
return { ...tool, inputSchema: { ...tool.inputSchema, properties,
|
|
80
|
+
...(tool.inputSchema.required ? {
|
|
81
|
+
required: tool.inputSchema.required.filter((name) => name !== "controlVersion"),
|
|
82
|
+
} : {}),
|
|
83
|
+
} };
|
|
84
|
+
}) };
|
|
85
|
+
},
|
|
86
|
+
async call(raw) {
|
|
87
|
+
const params = hostParameters(raw);
|
|
88
|
+
for (const field of ["threadId", "controller", "clientDigest", "token", "controlVersion"])
|
|
89
|
+
if (Object.hasOwn(params.arguments ?? {}, field))
|
|
90
|
+
throw new CreationClientError("creation.transport_authority_managed_by_bridge");
|
|
91
|
+
const key = keyFor(params);
|
|
92
|
+
let outgoing = params;
|
|
93
|
+
if (controlled.has(params.name)) {
|
|
94
|
+
if (!key) throw new CreationClientError("creation.request_invalid");
|
|
95
|
+
let controlVersion = versions.get(key);
|
|
96
|
+
if (!controlVersion) {
|
|
97
|
+
const read = { name: "platform_read_session", _meta: params._meta,
|
|
98
|
+
arguments: { projectId: params.arguments.projectId, sessionId: params.arguments.sessionId, pageSize: 1 } };
|
|
99
|
+
const result = await send(read);
|
|
100
|
+
if (result.isError) return result;
|
|
101
|
+
remember(read, result);
|
|
102
|
+
controlVersion = versions.get(key);
|
|
103
|
+
if (params.name === "platform_call_tool" && independentReads.has(params.arguments.tool)) {
|
|
104
|
+
const observed = data(result);
|
|
105
|
+
if (observed?.sessionId !== params.arguments.sessionId
|
|
106
|
+
|| !["web", "client"].includes(observed.control?.editor?.kind)
|
|
107
|
+
|| !Number.isSafeInteger(observed.control?.controlVersion) || observed.control.controlVersion <= 0)
|
|
108
|
+
throw new CreationClientError("creation.control_unverified");
|
|
109
|
+
// This is scoped read metadata, never an owned editor cache entry.
|
|
110
|
+
controlVersion = observed.control.controlVersion;
|
|
111
|
+
}
|
|
112
|
+
if (!controlVersion) {
|
|
113
|
+
if (!data(result)?.control) throw new CreationClientError("creation.control_unverified");
|
|
114
|
+
throw new CreationClientError("creation.editor_not_current");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
outgoing = { ...params, arguments: { ...params.arguments, controlVersion } };
|
|
118
|
+
}
|
|
119
|
+
const result = await send(outgoing);
|
|
120
|
+
if (result.isError && key) versions.delete(key);
|
|
121
|
+
else remember(params, result);
|
|
122
|
+
return result;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|