@promptframe/creation 0.3.10 → 0.3.11
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 +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +3 -1
- package/dist/cli.mjs +1204 -685
- package/docs/development.md +1 -0
- package/docs/install-guidance.json +1 -1
- package/docs/installing.md +3 -3
- package/docs/local-account-directory.md +51 -0
- package/docs/releases/0.3.11.md +9 -0
- package/lib/account-bridge.mjs +132 -0
- package/lib/cli.mjs +46 -13
- package/lib/connection.mjs +21 -1
- package/lib/host-context.mjs +19 -6
- package/lib/local-accounts.mjs +263 -0
- package/lib/version.mjs +1 -1
- package/package.json +2 -2
- package/skills/creation-setup/SKILL.md +2 -2
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { open, lstat, mkdir, rename, unlink, opendir } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
6
|
+
import { CreationClientError } from './credentials.mjs';
|
|
7
|
+
import { threadFormat } from './host-identity.mjs';
|
|
8
|
+
|
|
9
|
+
export const LOCAL_ACCOUNT_DIRECTORY_VERSION = 'promptframe-local-account-directory/v1';
|
|
10
|
+
export const LOCAL_AGENT_ACCOUNT_VERSION = 'promptframe-local-agent-account/v1';
|
|
11
|
+
const clients = ['creation', 'component-cli'];
|
|
12
|
+
const digestFormat = /^sha256:[a-f0-9]{64}$/;
|
|
13
|
+
const hexFormat = /^[a-f0-9]{64}$/;
|
|
14
|
+
const recordLimit = 16 * 1024;
|
|
15
|
+
const hash = value => 'sha256:' + createHash('sha256').update(value).digest('hex');
|
|
16
|
+
const failure = code => new CreationClientError('accounts.' + code);
|
|
17
|
+
const plain = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
18
|
+
const date = value => typeof value === 'string' && Number.isFinite(Date.parse(value));
|
|
19
|
+
|
|
20
|
+
export function localAccountsRoot(env = process.env) {
|
|
21
|
+
return path.resolve(env.PROMPTFRAME_ACCOUNT_DIRECTORY ?? path.join(
|
|
22
|
+
env.XDG_CONFIG_HOME ?? path.join(homedir(), '.config'), 'promptframe', 'accounts', 'v1'));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseAccountIdentity(value) {
|
|
26
|
+
if (!plain(value) || Object.keys(value).length !== 3
|
|
27
|
+
|| value.contractVersion !== 'promptframe-account-identity/v1'
|
|
28
|
+
|| !digestFormat.test(value.platformDigest ?? '') || !digestFormat.test(value.accountDigest ?? ''))
|
|
29
|
+
throw failure('identity_invalid');
|
|
30
|
+
return { contractVersion: value.contractVersion, platformDigest: value.platformDigest, accountDigest: value.accountDigest };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function localAccountKey(identity) {
|
|
34
|
+
const value = parseAccountIdentity(identity);
|
|
35
|
+
return value.platformDigest.slice(7) + '-' + value.accountDigest.slice(7);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function localReferenceId(client, configFile) {
|
|
39
|
+
if (!clients.includes(client) || typeof configFile !== 'string' || !path.isAbsolute(configFile))
|
|
40
|
+
throw failure('reference_invalid');
|
|
41
|
+
return hash(JSON.stringify([client, path.resolve(configFile)]));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function localCredentialDigest(token) {
|
|
45
|
+
if (typeof token !== 'string' || !token || token.length > 4096) throw failure('reference_invalid');
|
|
46
|
+
return hash(token);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function privateOwner(info, directory = false) {
|
|
50
|
+
const uid = process.getuid?.();
|
|
51
|
+
if (uid === undefined || info.uid !== uid || (info.mode & 0o077) !== 0
|
|
52
|
+
|| info.isSymbolicLink() || !(directory ? info.isDirectory() : info.isFile()))
|
|
53
|
+
throw failure('private_storage_required');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function directory(file, create = false) {
|
|
57
|
+
if (create) await mkdir(file, { recursive: true, mode: 0o700 });
|
|
58
|
+
try { privateOwner(await lstat(file), true); return true; }
|
|
59
|
+
catch (error) { if (!create && error.code === 'ENOENT') return false; throw error; }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function ownedPath(root, segments, create = false) {
|
|
63
|
+
if (!await directory(root, create)) return undefined;
|
|
64
|
+
let current = root;
|
|
65
|
+
for (const segment of segments) {
|
|
66
|
+
current = path.join(current, segment);
|
|
67
|
+
if (!await directory(current, create)) return undefined;
|
|
68
|
+
}
|
|
69
|
+
return current;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function readJson(file) {
|
|
73
|
+
let fd;
|
|
74
|
+
try {
|
|
75
|
+
fd = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW | (constants.O_NONBLOCK ?? 0));
|
|
76
|
+
const before = await fd.stat(); privateOwner(before);
|
|
77
|
+
if (before.size > recordLimit) throw failure('record_too_large');
|
|
78
|
+
const buffer = Buffer.alloc(recordLimit + 1);
|
|
79
|
+
const { bytesRead } = await fd.read(buffer, 0, buffer.length, 0);
|
|
80
|
+
const after = await fd.stat(), current = await lstat(file);
|
|
81
|
+
if (bytesRead !== before.size || after.size !== before.size || after.mtimeMs !== before.mtimeMs
|
|
82
|
+
|| current.dev !== before.dev || current.ino !== before.ino) throw failure('reference_changed');
|
|
83
|
+
try { return JSON.parse(buffer.subarray(0, bytesRead).toString('utf8')); }
|
|
84
|
+
catch { throw failure('record_invalid'); }
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error.code === 'ENOENT') return undefined;
|
|
87
|
+
if (error.code === 'ELOOP') throw failure('private_storage_required');
|
|
88
|
+
throw error;
|
|
89
|
+
} finally { await fd?.close(); }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function writeJson(directoryPath, name, value) {
|
|
93
|
+
const payload = JSON.stringify(value) + '\n';
|
|
94
|
+
if (Buffer.byteLength(payload) > recordLimit) throw failure('record_too_large');
|
|
95
|
+
const parent = await open(directoryPath, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
96
|
+
const temporary = path.join(directoryPath, '.' + randomUUID() + '.tmp');
|
|
97
|
+
try {
|
|
98
|
+
const owner = await parent.stat(); privateOwner(owner, true);
|
|
99
|
+
const fd = await open(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
|
100
|
+
try { await fd.writeFile(payload); await fd.sync(); } finally { await fd.close(); }
|
|
101
|
+
const current = await lstat(directoryPath);
|
|
102
|
+
if (current.dev !== owner.dev || current.ino !== owner.ino) throw failure('reference_changed');
|
|
103
|
+
try { privateOwner(await lstat(path.join(directoryPath, name))); }
|
|
104
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
105
|
+
await rename(temporary, path.join(directoryPath, name));
|
|
106
|
+
await parent.sync();
|
|
107
|
+
} finally {
|
|
108
|
+
await parent.close();
|
|
109
|
+
await unlink(temporary).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function referencePath(identity, client) {
|
|
114
|
+
const value = parseAccountIdentity(identity);
|
|
115
|
+
if (!clients.includes(client)) throw failure('reference_invalid');
|
|
116
|
+
return ['identities', value.platformDigest.slice(7), value.accountDigest.slice(7), client];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function parseReference(value, identity, client, id) {
|
|
120
|
+
const fields = ['contractVersion', 'identity', 'client', 'referenceId', 'configFile', 'endpoint',
|
|
121
|
+
'credentialDigest', 'observedAt', 'expiresAt', 'profile', 'scopes'];
|
|
122
|
+
if (!plain(value) || Object.keys(value).some(key => !fields.includes(key))
|
|
123
|
+
|| value.contractVersion !== LOCAL_ACCOUNT_DIRECTORY_VERSION || value.client !== client
|
|
124
|
+
|| value.referenceId !== id || localAccountKey(value.identity) !== localAccountKey(identity)
|
|
125
|
+
|| typeof value.configFile !== 'string' || value.configFile.length > 4096
|
|
126
|
+
|| localReferenceId(client, value.configFile) !== id || !digestFormat.test(value.credentialDigest ?? '')
|
|
127
|
+
|| !date(value.observedAt) || value.expiresAt !== undefined && !date(value.expiresAt)
|
|
128
|
+
|| value.profile !== undefined && (typeof value.profile !== 'string' || !/^[A-Za-z0-9._-]{1,80}$/.test(value.profile))
|
|
129
|
+
|| value.scopes !== undefined && (!Array.isArray(value.scopes) || value.scopes.length > 20
|
|
130
|
+
|| value.scopes.some(scope => typeof scope !== 'string' || !/^[a-z0-9_.:-]{1,100}$/.test(scope))))
|
|
131
|
+
throw failure('record_invalid');
|
|
132
|
+
let endpoint;
|
|
133
|
+
try { endpoint = new URL(value.endpoint); } catch { throw failure('record_invalid'); }
|
|
134
|
+
if (typeof value.endpoint !== 'string' || value.endpoint.length > 500 || endpoint.username || endpoint.password
|
|
135
|
+
|| endpoint.search || endpoint.hash || endpoint.protocol !== 'https:'
|
|
136
|
+
&& !(endpoint.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(endpoint.hostname)))
|
|
137
|
+
throw failure('record_invalid');
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Called only with identity observed on an authenticated transport. This is
|
|
142
|
+
* discovery metadata, never an authorization proof or a token copy. */
|
|
143
|
+
async function recordAuthorization({ root = localAccountsRoot(), identity, client,
|
|
144
|
+
configFile, endpoint, token, observedAt = new Date().toISOString(), expiresAt, profile, scopes }) {
|
|
145
|
+
identity = parseAccountIdentity(identity);
|
|
146
|
+
if (typeof configFile !== 'string' || !path.isAbsolute(configFile)) throw failure('reference_invalid');
|
|
147
|
+
configFile = path.resolve(configFile);
|
|
148
|
+
const referenceId = localReferenceId(client, configFile);
|
|
149
|
+
const record = parseReference({ contractVersion: LOCAL_ACCOUNT_DIRECTORY_VERSION, identity, client,
|
|
150
|
+
referenceId, configFile, endpoint, credentialDigest: localCredentialDigest(token), observedAt,
|
|
151
|
+
...(expiresAt !== undefined ? { expiresAt } : {}), ...(profile !== undefined ? { profile } : {}),
|
|
152
|
+
...(scopes !== undefined ? { scopes } : {}) }, identity, client, referenceId);
|
|
153
|
+
const parent = await ownedPath(root, referencePath(identity, client), true);
|
|
154
|
+
await writeJson(parent, referenceId.slice(7) + '.json', record);
|
|
155
|
+
return { identityKey: localAccountKey(identity), referenceId };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function readAuthorization({ root = localAccountsRoot(), identity, client, referenceId }) {
|
|
159
|
+
if (!digestFormat.test(referenceId ?? '')) throw failure('reference_invalid');
|
|
160
|
+
const parent = await ownedPath(root, referencePath(identity, client));
|
|
161
|
+
const value = parent ? await readJson(path.join(parent, referenceId.slice(7) + '.json')) : undefined;
|
|
162
|
+
return value === undefined ? undefined : parseReference(value, identity, client, referenceId);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Private reference data for the owning client, not a model-facing list. */
|
|
166
|
+
async function readAuthorizations({ root = localAccountsRoot(), identity, client }) {
|
|
167
|
+
const parent = await ownedPath(root, referencePath(identity, client));
|
|
168
|
+
if (!parent) return [];
|
|
169
|
+
const records = [];
|
|
170
|
+
for (const entry of await entries(parent)) {
|
|
171
|
+
if (!/^[a-f0-9]{64}\.json$/.test(entry.name)) throw failure('record_invalid');
|
|
172
|
+
const value = await readLocalAuthorization({ root, identity, client, referenceId: 'sha256:' + entry.name.slice(0, -5) });
|
|
173
|
+
if (value) records.push(value);
|
|
174
|
+
}
|
|
175
|
+
return records.sort((a,b) => a.referenceId.localeCompare(b.referenceId));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function entries(file) {
|
|
179
|
+
const output = [];
|
|
180
|
+
const handle = await opendir(file);
|
|
181
|
+
for await (const entry of handle) {
|
|
182
|
+
if (entry.name.startsWith('.')) continue;
|
|
183
|
+
if (output.length === 256) throw failure('listing_limit');
|
|
184
|
+
output.push(entry);
|
|
185
|
+
}
|
|
186
|
+
return output;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** No config paths, fingerprints, raw tenant/user ids or tokens leave this view.
|
|
190
|
+
* Stored is a local observation; remote expiry/revocation/scope is rechecked. */
|
|
191
|
+
async function listAccounts({ root = localAccountsRoot(), now = Date.now() } = {}) {
|
|
192
|
+
const base = await ownedPath(root, ['identities']);
|
|
193
|
+
if (!base) return { accounts: [], complete: true };
|
|
194
|
+
const accounts = [];
|
|
195
|
+
for (const platform of await entries(base)) {
|
|
196
|
+
if (!hexFormat.test(platform.name)) throw failure('record_invalid');
|
|
197
|
+
const platformPath = await ownedPath(root, ['identities', platform.name]);
|
|
198
|
+
for (const account of await entries(platformPath)) {
|
|
199
|
+
if (!hexFormat.test(account.name) || accounts.length === 256) throw failure('listing_limit');
|
|
200
|
+
const identity = { contractVersion: 'promptframe-account-identity/v1',
|
|
201
|
+
platformDigest: 'sha256:' + platform.name, accountDigest: 'sha256:' + account.name };
|
|
202
|
+
const grants = {};
|
|
203
|
+
for (const client of clients) {
|
|
204
|
+
grants[client] = [];
|
|
205
|
+
const parent = await ownedPath(root, referencePath(identity, client));
|
|
206
|
+
if (!parent) continue;
|
|
207
|
+
for (const entry of await entries(parent)) {
|
|
208
|
+
if (!/^[a-f0-9]{64}\.json$/.test(entry.name)) throw failure('record_invalid');
|
|
209
|
+
const ref = await readLocalAuthorization({ root, identity, client, referenceId: 'sha256:' + entry.name.slice(0, -5) });
|
|
210
|
+
if (!ref) continue;
|
|
211
|
+
grants[client].push({ referenceId: ref.referenceId, ...(ref.profile ? { profile: ref.profile } : {}),
|
|
212
|
+
status: ref.expiresAt && Date.parse(ref.expiresAt) <= now ? 'expired' : 'stored',
|
|
213
|
+
observedAt: ref.observedAt, ...(ref.expiresAt ? { expiresAt: ref.expiresAt } : {}) });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
accounts.push({ identityKey: localAccountKey(identity), identity, grants,
|
|
217
|
+
missingClients: clients.filter(client => !grants[client].some(ref => ref.status === 'stored')) });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { accounts, complete: true };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function localAgentDigest(agent) {
|
|
224
|
+
if (!agent || !['codex', 'claude-code'].includes(agent.kind) || typeof agent.sessionId !== 'string'
|
|
225
|
+
|| !threadFormat.test(agent.sessionId)) throw failure('agent_required');
|
|
226
|
+
return hash(JSON.stringify([agent.kind, agent.sessionId.toLowerCase()]));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** The caller supplies identity from the original host transport/hook, never
|
|
230
|
+
* from a business argument. There is no global selected/default account. */
|
|
231
|
+
async function selectAccount({ root = localAccountsRoot(), agent, identity }) {
|
|
232
|
+
const agentDigest = localAgentDigest(agent);
|
|
233
|
+
const parent = await ownedPath(root, ['selections'], true);
|
|
234
|
+
const value = { contractVersion: LOCAL_AGENT_ACCOUNT_VERSION, agentKind: agent.kind, agentDigest,
|
|
235
|
+
generation: randomUUID(), identity: parseAccountIdentity(identity), selectedAt: new Date().toISOString() };
|
|
236
|
+
await writeJson(parent, agent.kind + '-' + agentDigest.slice(7) + '.json', value);
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async function readSelectedAccount({ root = localAccountsRoot(), agent }) {
|
|
241
|
+
const agentDigest = localAgentDigest(agent), parent = await ownedPath(root, ['selections']);
|
|
242
|
+
const value = parent ? await readJson(path.join(parent, agent.kind + '-' + agentDigest.slice(7) + '.json')) : undefined;
|
|
243
|
+
if (value === undefined) return undefined;
|
|
244
|
+
if (!plain(value) || Object.keys(value).length !== 6 || value.contractVersion !== LOCAL_AGENT_ACCOUNT_VERSION
|
|
245
|
+
|| value.agentKind !== agent.kind || value.agentDigest !== agentDigest || !threadFormat.test(value.generation ?? '')
|
|
246
|
+
|| !date(value.selectedAt)) throw failure('record_invalid');
|
|
247
|
+
return { ...value, identity: parseAccountIdentity(value.identity) };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const accountIO = operation => async (...args) => {
|
|
251
|
+
try { return await operation(...args); }
|
|
252
|
+
catch (cause) {
|
|
253
|
+
if (cause instanceof CreationClientError) throw cause;
|
|
254
|
+
throw failure(['EACCES','EPERM','ENOTDIR','ELOOP'].includes(cause?.code)
|
|
255
|
+
? 'private_storage_required' : 'storage_unavailable');
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
export const recordLocalAuthorization = accountIO(recordAuthorization);
|
|
259
|
+
export const readLocalAuthorization = accountIO(readAuthorization);
|
|
260
|
+
export const readLocalAuthorizations = accountIO(readAuthorizations);
|
|
261
|
+
export const listLocalAccounts = accountIO(listAccounts);
|
|
262
|
+
export const selectLocalAccount = accountIO(selectAccount);
|
|
263
|
+
export const readSelectedLocalAccount = accountIO(readSelectedAccount);
|
package/lib/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const CLIENT_VERSION = "0.3.
|
|
1
|
+
export const CLIENT_VERSION = "0.3.11";
|
|
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.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "PromptFrame video creation Skill, Codex plugin and MCP client bridge.",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"promptframe-creation": "bin/promptframe-creation.mjs"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"test": "npm run build && node
|
|
35
|
+
"test": "npm run build && node scripts/test-runtime.mjs",
|
|
36
36
|
"build": "node scripts/build-runtime.mjs"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
@@ -10,11 +10,11 @@ description: 安装、连接或升级 PromptFrame Creation,复用平台创作
|
|
|
10
10
|
先确认使用 Codex 还是 Claude Code。Claude 接入使用 `connect --host claude-code`,两种宿主可共用同一 profile 凭据,插件登记分别核实。使用 Studio 对当前环境提供的固定版本;旧版入口不会因平台更新自动改变。Claude 桌面版远程连接 WSL 时,在同一 WSL 安装;没有终端命令时可通过 `--claude-bin <实际可执行文件>` 指定桌面版提供的入口,不固定桌面构建文件名。
|
|
11
11
|
|
|
12
12
|
<!-- creation-install-command -->
|
|
13
|
-
在用户本机终端运行 `npx --yes @promptframe/creation@0.3.
|
|
13
|
+
在用户本机终端运行 `npx --yes @promptframe/creation@0.3.11 connect --endpoint <Studio提供的API地址>`。需要隔离另一个环境或账号时显式加 `--profile <用户选择的名称>`;正在运行的桥不会切换。此命令管理用户级版本和 Codex 插件,不向当前项目安装依赖。优先使用 Studio 当前提供的固定推荐版本;每次重新进入此入口比较已安装版本,不后台追踪 latest,也不把旧聊天里的命令当最新版本。已安装更新版不默认降级。
|
|
14
14
|
<!-- /creation-install-command -->
|
|
15
15
|
|
|
16
16
|
<!-- creation-install-command -->
|
|
17
|
-
Claude Code 使用 `npx --yes @promptframe/creation@0.3.
|
|
17
|
+
Claude Code 使用 `npx --yes @promptframe/creation@0.3.11 connect --host claude-code --endpoint <Studio提供的API地址>`。桌面版远程连接 WSL 时,在该 WSL 执行;保留相同 profile 和有效凭据。
|
|
18
18
|
<!-- /creation-install-command -->
|
|
19
19
|
|
|
20
20
|
命令会复用并验证有效凭据。首次授权或明确更换已失效凭据时,由用户在 Studio 登录并在终端的不回显输入框提供 Token;不要要求用户把 Token 粘进聊天,也不要把它写进命令参数、URL或日志。网络失败不等于授权失效,不自动轮换或覆盖凭据。
|