@promptframe/creation 0.2.7 → 0.3.0
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-mcp.json +8 -0
- package/.claude-plugin/marketplace.json +5 -0
- package/.claude-plugin/plugin.json +10 -0
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +6 -4
- package/dist/THIRD_PARTY_NOTICES.txt +59 -0
- package/dist/cli.mjs +5852 -1595
- package/docs/development.md +16 -1
- package/docs/install-guidance.json +36 -0
- package/docs/installing.md +23 -3
- package/docs/releases/0.3.0.md +10 -0
- package/lib/bridge-negotiation.mjs +54 -0
- package/lib/claude-command.mjs +57 -0
- package/lib/claude-installation.mjs +191 -0
- package/lib/claude-local-state.mjs +17 -0
- package/lib/claude-mcp-installation.mjs +174 -0
- package/lib/cli.mjs +83 -14
- package/lib/connection.mjs +15 -4
- package/lib/content-budget.mjs +15 -0
- package/lib/host-context.mjs +151 -123
- package/lib/host-identity.mjs +35 -0
- package/lib/runtime-bootstrap.mjs +208 -0
- package/lib/runtime-launch.mjs +27 -0
- package/lib/runtime-package.mjs +41 -0
- package/lib/user-installation.mjs +6 -25
- package/lib/version.mjs +1 -1
- package/package.json +5 -2
- package/skills/creation-setup/SKILL.md +9 -3
- package/skills/video-creation/SKILL.md +16 -40
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {createHash,randomBytes} from 'node:crypto';
|
|
2
|
+
import {mkdir,open,readFile,readdir,rename,rm,lstat} from 'node:fs/promises';
|
|
3
|
+
import {homedir} from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {CreationClientError} from './credentials.mjs';
|
|
6
|
+
import {inspectRuntimePackage} from './runtime-package.mjs';
|
|
7
|
+
import {installationFiles} from './user-installation.mjs';
|
|
8
|
+
import {claudeConfigRoot,readClaudeUserServer} from './claude-local-state.mjs';
|
|
9
|
+
|
|
10
|
+
const {info,privateDirectory,privateRead,atomicJSON,acquire,compareVersions}=installationFiles;
|
|
11
|
+
const hash=body=>createHash('sha256').update(body).digest('hex');
|
|
12
|
+
class FallbackError extends CreationClientError{
|
|
13
|
+
constructor(code,details){super('installation.'+code);this.details=details;}
|
|
14
|
+
}
|
|
15
|
+
export const fallbackErrorDetails=error=>error instanceof FallbackError?error.details:undefined;
|
|
16
|
+
const fail=(code,details)=>{throw new FallbackError(code,details);};
|
|
17
|
+
export async function claimSkillDirectory(root){
|
|
18
|
+
try{await mkdir(root,{mode:0o700});}catch(error){if(error.code==='EEXIST')fail('claude_skill_requires_review');throw error;}
|
|
19
|
+
}
|
|
20
|
+
function same(a,b,depth=0){
|
|
21
|
+
if(a===b)return true;if(depth>8||!a||!b||typeof a!=='object'||typeof b!=='object'||Array.isArray(a)!==Array.isArray(b))return false;
|
|
22
|
+
const left=Object.keys(a).sort(),right=Object.keys(b).sort();
|
|
23
|
+
return left.length<=256&&left.length===right.length&&left.every((key,i)=>key===right[i]&&same(a[key],b[key],depth+1));
|
|
24
|
+
}
|
|
25
|
+
async function atomicText(file,body){
|
|
26
|
+
const temporary=file+'.'+randomBytes(12).toString('hex')+'.tmp';
|
|
27
|
+
try{const fd=await open(temporary,'wx',0o600);try{await fd.writeFile(body);await fd.sync();}finally{await fd.close();}
|
|
28
|
+
await rename(temporary,file);const dir=await open(path.dirname(file),'r');try{await dir.sync();}finally{await dir.close();}
|
|
29
|
+
}finally{if(await info(temporary))await rm(temporary);}
|
|
30
|
+
}
|
|
31
|
+
async function verifyVersion(root,record){
|
|
32
|
+
const directory=await info(root);
|
|
33
|
+
if(!directory?.isDirectory()||directory.isSymbolicLink()||directory.uid!==process.getuid?.()||(directory.mode&0o077))fail('claude_installed_files_invalid');
|
|
34
|
+
const marker=await privateRead(path.join(root,'installation.json')),payload=await inspectRuntimePackage(root);
|
|
35
|
+
if(!marker||marker.host!=='claude-code'||marker.mode!=='mcp-and-skills'||marker.profile!==record.profile
|
|
36
|
+
||marker.configFile!==record.configFile||marker.version!==record.version||marker.payloadDigest!==record.payloadDigest
|
|
37
|
+
||payload.payloadDigest!==marker.payloadDigest||!path.isAbsolute(marker.nodeCommand??''))fail('claude_installed_files_invalid');
|
|
38
|
+
return marker;
|
|
39
|
+
}
|
|
40
|
+
function mcpDefinition(record,nodeCommand){return{type:'stdio',command:nodeCommand,
|
|
41
|
+
args:[path.join(record.versionRoot,'bin/promptframe-creation.mjs'),'bridge','--config',record.configFile,'--host','claude-code']};}
|
|
42
|
+
function skillBody(payload,sourceName,name){
|
|
43
|
+
const file=payload.files.find(f=>f.path==='skills/'+sourceName+'/SKILL.md');if(!file)fail('package_incomplete');
|
|
44
|
+
const body=file.body.toString('utf8');
|
|
45
|
+
if(!body.startsWith('---\n')||!body.includes('\nname: '+sourceName+'\n'))fail('package_incomplete');
|
|
46
|
+
return body.replace('\nname: '+sourceName+'\n','\nname: '+name+'\n');
|
|
47
|
+
}
|
|
48
|
+
async function observedSkill(plan,record,{allowBefore=false}={}){
|
|
49
|
+
const directory=await info(plan.root);if(!directory)return false;
|
|
50
|
+
if(!directory.isDirectory()||directory.isSymbolicLink()||directory.uid!==process.getuid?.()||(directory.mode&0o077))fail('claude_skill_requires_review');
|
|
51
|
+
const names=await readdir(plan.root);
|
|
52
|
+
if(names.some(n=>!['SKILL.md','promptframe-installation.json'].includes(n)))fail('claude_skill_requires_review');
|
|
53
|
+
const marker=await privateRead(path.join(plan.root,'promptframe-installation.json')),file=path.join(plan.root,'SKILL.md'),s=await info(file);
|
|
54
|
+
if(!marker||marker.host!=='claude-code'||marker.profile!==record.profile||marker.configFile!==record.configFile||marker.name!==plan.name)
|
|
55
|
+
fail('claude_skill_requires_review');
|
|
56
|
+
if(!s&&allowBefore&&plan.beforeSHA===null&&marker.sha256===null)return false;
|
|
57
|
+
if(!s?.isFile()||s.isSymbolicLink()||s.size>256*1024)fail('claude_skill_requires_review');
|
|
58
|
+
const digest=hash(await readFile(file));
|
|
59
|
+
if(digest===plan.sha256&&marker.sha256===plan.sha256)return true;
|
|
60
|
+
if(allowBefore&&(digest===plan.beforeSHA||digest===plan.sha256)&&marker.sha256===plan.beforeSHA)return false;
|
|
61
|
+
fail('claude_skill_requires_review');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Used only when help positively lacks plugin commands, or for an existing
|
|
65
|
+
* owned fallback. It never follows an unknown plugin-registration attempt. */
|
|
66
|
+
export async function installClaudeMcpFallback({sourceRoot,profile,env,configFile,signal,runClaude,checkRuntime,verifyInstalledRuntime,nodeCommand,
|
|
67
|
+
writeSkill=atomicText}){
|
|
68
|
+
const payload=await inspectRuntimePackage(path.resolve(sourceRoot)),suffix=profile==='default'?'':'-'+profile,
|
|
69
|
+
serverName='promptframe'+suffix,root=path.resolve(env.XDG_DATA_HOME??path.join(homedir(),'.local/share'),'promptframe-creation',profile,'claude-code-mcp');
|
|
70
|
+
await privateDirectory(root);const release=await acquire(root,signal),versions=path.join(root,'versions'),currentFile=path.join(root,'current.json'),
|
|
71
|
+
pendingFile=path.join(root,'registration-pending.json'),versionRoot=path.join(versions,payload.version),
|
|
72
|
+
temporary=path.join(versions,'.partial-'+randomBytes(12).toString('hex'));
|
|
73
|
+
let writeStarted=false,newFiles=0;
|
|
74
|
+
const complete={host:'claude-code',mode:'mcp-and-skills',profile,configFile,serverName,version:payload.version,versionRoot,payloadDigest:payload.payloadDigest};
|
|
75
|
+
const checkBinding=record=>{
|
|
76
|
+
if(record&&(record.host!=='claude-code'||record.mode!=='mcp-and-skills'||record.profile!==profile||record.configFile!==configFile
|
|
77
|
+
||record.serverName!==serverName||!/^\d+\.\d+\.\d+$/.test(record.version??'')||record.versionRoot!==path.join(versions,record.version)))fail('profile_binding_conflict');
|
|
78
|
+
};
|
|
79
|
+
try{
|
|
80
|
+
await privateDirectory(versions);let previous=await privateRead(currentFile),pending=await privateRead(pendingFile);
|
|
81
|
+
checkBinding(previous);checkBinding(pending);
|
|
82
|
+
let saved=await readClaudeUserServer(serverName,env);
|
|
83
|
+
complete.beforeServer=pending?.beforeServer??saved;
|
|
84
|
+
const settled=async record=>{
|
|
85
|
+
const ready=await verifyVersion(record.versionRoot,record);
|
|
86
|
+
if(!same(record.server,mcpDefinition(record,ready.nodeCommand)))fail('claude_installed_files_invalid');
|
|
87
|
+
if(!same(saved,record.server))return false;
|
|
88
|
+
if(!Array.isArray(record.skills)||record.skills.length!==2)fail('claude_skill_requires_review');
|
|
89
|
+
for(const [i,skill]of record.skills.entries()){
|
|
90
|
+
const name=['creation-setup','video-creation'][i]+suffix;
|
|
91
|
+
if(skill.name!==name||skill.root!==path.join(claudeConfigRoot(env),'skills',name)||!/^[a-f0-9]{64}$/.test(skill.sha256??''))
|
|
92
|
+
fail('claude_skill_requires_review');
|
|
93
|
+
if(!await observedSkill(skill,record))return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
if(pending){
|
|
98
|
+
writeStarted=true;
|
|
99
|
+
if(pending.version!==complete.version||pending.payloadDigest!==complete.payloadDigest)fail('registration_unconfirmed_keep_existing');
|
|
100
|
+
if(pending.phase==='mcp'){
|
|
101
|
+
if(!await settled(pending))fail('registration_unconfirmed_keep_existing');
|
|
102
|
+
await atomicJSON(currentFile,pending);await rm(pendingFile);previous=pending;pending=null;
|
|
103
|
+
}else if(pending.phase!=='skills'||!same(saved,pending.beforeServer))fail('registration_unconfirmed_keep_existing');
|
|
104
|
+
}
|
|
105
|
+
if(previous&&!pending){
|
|
106
|
+
if(!await settled(previous))fail('claude_local_registration_unconfirmed');
|
|
107
|
+
if(compareVersions(previous.version,payload.version)>=0){
|
|
108
|
+
const ready=await verifyVersion(previous.versionRoot,previous);
|
|
109
|
+
await verifyInstalledRuntime(previous.versionRoot,previous.version,ready.nodeCommand,{env});
|
|
110
|
+
return{...previous,currentFile,registered:true,pluginInstalled:false,pluginEnabled:false,skillsInstalled:true,
|
|
111
|
+
installationMode:'mcp-and-skills',reused:true,installedFiles:0,requestedVersion:payload.version,
|
|
112
|
+
versionStatus:previous.version===payload.version?'current':'newer_retained',recordedRuntimeRetained:ready.nodeCommand!==nodeCommand};
|
|
113
|
+
}
|
|
114
|
+
}else if(saved&&!pending)fail('legacy_mcp_entry_requires_review');
|
|
115
|
+
if(await info(versionRoot))await verifyVersion(versionRoot,complete);
|
|
116
|
+
else{
|
|
117
|
+
await mkdir(temporary,{mode:0o700});
|
|
118
|
+
for(const file of payload.files){signal?.throwIfAborted();const dest=path.join(temporary,file.path);
|
|
119
|
+
await mkdir(path.dirname(dest),{recursive:true,mode:0o700});const fd=await open(dest,'wx',0o600);
|
|
120
|
+
try{await fd.writeFile(file.body);await fd.sync();}finally{await fd.close();}}
|
|
121
|
+
await checkRuntime(temporary,payload.version);
|
|
122
|
+
await atomicJSON(path.join(temporary,'installation.json'),{...complete,nodeCommand});
|
|
123
|
+
signal?.throwIfAborted();await rename(temporary,versionRoot);newFiles=payload.files.length;
|
|
124
|
+
}
|
|
125
|
+
const ready=await verifyVersion(versionRoot,complete);complete.server=mcpDefinition(complete,ready.nodeCommand);
|
|
126
|
+
if(newFiles===0)await verifyInstalledRuntime(versionRoot,payload.version,ready.nodeCommand,{env});
|
|
127
|
+
const skillRoot=path.join(claudeConfigRoot(env),'skills');await mkdir(skillRoot,{recursive:true,mode:0o700});
|
|
128
|
+
const parent=await lstat(skillRoot);
|
|
129
|
+
if(!parent.isDirectory()||parent.isSymbolicLink()||parent.uid!==process.getuid?.())fail('claude_skill_requires_review');
|
|
130
|
+
const plans=[];
|
|
131
|
+
for(const sourceName of['creation-setup','video-creation']){
|
|
132
|
+
const name=sourceName+suffix,body=skillBody(payload,sourceName,name),skill={name,root:path.join(skillRoot,name),sha256:hash(body)};
|
|
133
|
+
if(pending){const old=pending.skills?.find(s=>s.name===name);
|
|
134
|
+
if(!old||old.root!==skill.root||old.sha256!==skill.sha256)fail('registration_unconfirmed_keep_existing');
|
|
135
|
+
plans.push({...old,body});
|
|
136
|
+
}else{
|
|
137
|
+
const existing=await info(skill.root);let beforeSHA=null;
|
|
138
|
+
if(existing){
|
|
139
|
+
const marker=await privateRead(path.join(skill.root,'promptframe-installation.json'));
|
|
140
|
+
if(!marker||marker.profile!==profile||marker.configFile!==configFile||marker.name!==name)fail('claude_skill_requires_review');
|
|
141
|
+
const old={...skill,sha256:marker.sha256};if(!await observedSkill(old,complete))fail('claude_skill_requires_review');beforeSHA=marker.sha256;
|
|
142
|
+
}
|
|
143
|
+
plans.push({...skill,beforeSHA,body});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
complete.skills=plans.map(({body,...p})=>p);
|
|
147
|
+
if(!pending){await atomicJSON(pendingFile,{...complete,phase:'skills'});writeStarted=true;}
|
|
148
|
+
for(const plan of plans){
|
|
149
|
+
signal?.throwIfAborted();
|
|
150
|
+
if(await info(plan.root)){
|
|
151
|
+
if(await observedSkill(plan,complete,{allowBefore:true}))continue;
|
|
152
|
+
}else{
|
|
153
|
+
if(plan.beforeSHA!==null)fail('claude_skill_requires_review');await claimSkillDirectory(plan.root);
|
|
154
|
+
// A marker is written before the first body so interruption is tied to
|
|
155
|
+
// this pending identity rather than an unowned existing skill.
|
|
156
|
+
await atomicJSON(path.join(plan.root,'promptframe-installation.json'),{host:'claude-code',profile,configFile,name:plan.name,sha256:null});
|
|
157
|
+
}
|
|
158
|
+
await writeSkill(path.join(plan.root,'SKILL.md'),plan.body);
|
|
159
|
+
await atomicJSON(path.join(plan.root,'promptframe-installation.json'),{host:'claude-code',profile,configFile,name:plan.name,sha256:plan.sha256});
|
|
160
|
+
}
|
|
161
|
+
signal?.throwIfAborted();
|
|
162
|
+
if(!same(await readClaudeUserServer(serverName,env),complete.beforeServer))fail('claude_local_registration_changed');
|
|
163
|
+
await atomicJSON(pendingFile,{...complete,phase:'mcp'});writeStarted=true;
|
|
164
|
+
await runClaude(['mcp','add-json','--scope','user',serverName,JSON.stringify(complete.server)]);
|
|
165
|
+
saved=await readClaudeUserServer(serverName,env);
|
|
166
|
+
if(!await settled(complete))fail('registration_unconfirmed_keep_existing');
|
|
167
|
+
await atomicJSON(currentFile,complete);await rm(pendingFile);
|
|
168
|
+
return{...complete,currentFile,registered:true,pluginInstalled:false,pluginEnabled:false,skillsInstalled:true,
|
|
169
|
+
installationMode:'mcp-and-skills',reused:newFiles===0,installedFiles:newFiles,requestedVersion:payload.version,versionStatus:'current'};
|
|
170
|
+
}catch(error){
|
|
171
|
+
if(writeStarted)fail('registration_unconfirmed_keep_existing',{phase:'registration_observation',localRegistrationState:'unknown',action:'inspect_same_registration_no_second_add'});
|
|
172
|
+
if(error instanceof CreationClientError)throw error;fail(signal?.aborted?'interrupted_keep_existing':'failed_keep_existing');
|
|
173
|
+
}finally{await rm(temporary,{recursive:true,force:true});await release();}
|
|
174
|
+
}
|
package/lib/cli.mjs
CHANGED
|
@@ -7,6 +7,13 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
7
7
|
import {
|
|
8
8
|
CallToolRequestSchema,
|
|
9
9
|
ListToolsRequestSchema,
|
|
10
|
+
ListResourcesRequestSchema,
|
|
11
|
+
ListResourceTemplatesRequestSchema,
|
|
12
|
+
ReadResourceRequestSchema,
|
|
13
|
+
ListPromptsRequestSchema,
|
|
14
|
+
GetPromptRequestSchema,
|
|
15
|
+
McpError,
|
|
16
|
+
ErrorCode,
|
|
10
17
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
11
18
|
import {
|
|
12
19
|
CreationClientError,
|
|
@@ -16,7 +23,14 @@ import {
|
|
|
16
23
|
} from "./credentials.mjs";
|
|
17
24
|
import { connectPlatform } from "./connection.mjs";
|
|
18
25
|
import { createHostCallBridge } from "./host-context.mjs";
|
|
26
|
+
import { resolveHostIdentity } from "./host-identity.mjs";
|
|
27
|
+
import {declaredHostContentCapabilities,readPlatformBridgePolicy,bridgeErrorDetails} from './bridge-negotiation.mjs';
|
|
28
|
+
import {selectBridgeRuntime,runtimeErrorDetails} from './runtime-bootstrap.mjs';
|
|
29
|
+
import {launchSelectedBridge} from './runtime-launch.mjs';
|
|
19
30
|
import {installForUser,profileCredentialsPath,installationErrorDetails} from './user-installation.mjs';
|
|
31
|
+
import {installForClaudeUser,claudeInstallationDetails} from './claude-installation.mjs';
|
|
32
|
+
import {claudeErrorDetails} from './claude-command.mjs';
|
|
33
|
+
import {fallbackErrorDetails} from './claude-mcp-installation.mjs';
|
|
20
34
|
import {fileURLToPath} from 'node:url';
|
|
21
35
|
import path from 'node:path';
|
|
22
36
|
|
|
@@ -30,7 +44,7 @@ const log = (value) => process.stdout.write(JSON.stringify(value) + "\n");
|
|
|
30
44
|
const configFile=()=>value('--config')?path.resolve(value('--config')):
|
|
31
45
|
profileCredentialsPath(value('--profile')??'default');
|
|
32
46
|
async function probe(credentials) {
|
|
33
|
-
const client = await connectPlatform(credentials);
|
|
47
|
+
const client = await connectPlatform(credentials,{host:resolveHostIdentity({host:value('--host')})});
|
|
34
48
|
try {
|
|
35
49
|
return (await client.listTools()).tools.length;
|
|
36
50
|
} finally {
|
|
@@ -143,7 +157,7 @@ async function setup({silent=false}={}) {
|
|
|
143
157
|
endpoint,
|
|
144
158
|
token,
|
|
145
159
|
clientId: existing?.clientId ?? randomBytes(24).toString("base64url"),
|
|
146
|
-
clientName: value("--name") ?? existing?.clientName ??
|
|
160
|
+
clientName: value("--name") ?? existing?.clientName ?? (resolveHostIdentity({host:value('--host')}).kind==='claude-code'?'Claude Code PromptFrame':'Codex PromptFrame'),
|
|
147
161
|
createdAt: existing?.createdAt ?? new Date().toISOString(),
|
|
148
162
|
};
|
|
149
163
|
// Verify before replacing the secure local file. This never calls a token
|
|
@@ -157,12 +171,57 @@ async function setup({silent=false}={}) {
|
|
|
157
171
|
async function bridge() {
|
|
158
172
|
const credentials = await readCredentials(configFile());
|
|
159
173
|
if (!credentials) throw new CreationClientError("setup.required");
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
174
|
+
let contentTypes=['text'],contentSource='text-fallback';
|
|
175
|
+
const identity=resolveHostIdentity({host:value('--host')}),startup=new AbortController(),abort=()=>startup.abort();
|
|
176
|
+
let client,upstream,policy,selection;
|
|
177
|
+
process.once('SIGINT',abort);process.once('SIGTERM',abort);
|
|
178
|
+
try{
|
|
179
|
+
client=await connectPlatform(credentials,{host:identity,contentTypes:()=>contentTypes,contentSource:()=>contentSource,
|
|
180
|
+
enforceMinimum:false,signal:startup.signal});
|
|
181
|
+
upstream=client.getServerCapabilities()??{};policy=readPlatformBridgePolicy(upstream);
|
|
182
|
+
selection=await selectBridgeRuntime({policy,currentVersion:CLIENT_VERSION,lockedVersion:value('--bridge-version'),
|
|
183
|
+
resolvedVersion:value('--resolved-runtime-version'),signal:startup.signal,hostKind:identity.kind,
|
|
184
|
+
cacheRoot:path.join(path.dirname(configFile()),'runtime-cache')});
|
|
185
|
+
startup.signal.throwIfAborted();
|
|
186
|
+
}catch(error){await client?.close().catch(()=>{});
|
|
187
|
+
if(startup.signal.aborted)throw new CreationClientError('creation.runtime_selection_interrupted');throw error;}
|
|
188
|
+
finally{process.removeListener('SIGINT',abort);process.removeListener('SIGTERM',abort);}
|
|
189
|
+
if(!selection.current){
|
|
190
|
+
await client.close();const result=await launchSelectedBridge(selection,{host:identity,configFile:configFile()});
|
|
191
|
+
process.exitCode=result.code;return;
|
|
192
|
+
}
|
|
193
|
+
const server = new Server(
|
|
163
194
|
{ name: "promptframe-creation", version: CLIENT_VERSION },
|
|
164
|
-
{ capabilities: { tools: {}
|
|
165
|
-
|
|
195
|
+
{ capabilities: { tools: {listChanged:true},...(upstream.resources?{resources:{listChanged:true}}:{}),
|
|
196
|
+
...(upstream.prompts?{prompts:{listChanged:true}}:{}),
|
|
197
|
+
experimental:{...(policy?{'promptframe.creation':policy}:{}),
|
|
198
|
+
'promptframe.runtime':{version:selection.version,locked:selection.locked,status:selection.status}} } },
|
|
199
|
+
),
|
|
200
|
+
host=createHostCallBridge(client,{credentials,host:identity,onCatalogChange:()=>server.sendToolListChanged(),
|
|
201
|
+
onKnowledgeChange:kind=>kind==='resources'?server.sendResourceListChanged():server.sendPromptListChanged()});
|
|
202
|
+
server.oninitialized=()=>{const declared=declaredHostContentCapabilities(server.getClientCapabilities());
|
|
203
|
+
contentTypes=declared.types;contentSource=declared.source;};
|
|
204
|
+
const knowledgeHandler=(schema,method)=>server.setRequestHandler(schema,async request=>{
|
|
205
|
+
try{return await host[method](request.params??{});}catch(error){
|
|
206
|
+
const remote=error?.data?.errorCode;
|
|
207
|
+
const code=error instanceof CreationClientError?error.message
|
|
208
|
+
:typeof remote==='string'&&/^(?:creation|creative_skill)\.[a-z0-9_.:-]{1,160}$/.test(remote)
|
|
209
|
+
?remote:'creation.connection_unresolved';
|
|
210
|
+
const knownRemote=typeof remote==='string'&&code===remote
|
|
211
|
+
&&typeof error.code==='number'&&Object.values(ErrorCode).includes(error.code);
|
|
212
|
+
throw new McpError(knownRemote?error.code:error instanceof CreationClientError
|
|
213
|
+
?ErrorCode.InvalidParams:ErrorCode.InternalError,code,{errorCode:code});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
if(upstream.resources){
|
|
217
|
+
knowledgeHandler(ListResourcesRequestSchema,'listResources');
|
|
218
|
+
knowledgeHandler(ListResourceTemplatesRequestSchema,'listResourceTemplates');
|
|
219
|
+
knowledgeHandler(ReadResourceRequestSchema,'readResource');
|
|
220
|
+
}
|
|
221
|
+
if(upstream.prompts){
|
|
222
|
+
knowledgeHandler(ListPromptsRequestSchema,'listPrompts');
|
|
223
|
+
knowledgeHandler(GetPromptRequestSchema,'getPrompt');
|
|
224
|
+
}
|
|
166
225
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
167
226
|
try {
|
|
168
227
|
return await host.listTools();
|
|
@@ -185,7 +244,7 @@ async function bridge() {
|
|
|
185
244
|
? error.message : "creation.connection_unresolved",
|
|
186
245
|
action: error instanceof CreationClientError
|
|
187
246
|
? error.message.startsWith("creation.host_")
|
|
188
|
-
? "
|
|
247
|
+
? "use_supported_host_with_session_identity"
|
|
189
248
|
: error.message === "creation.editor_not_current"
|
|
190
249
|
? "request_control_and_confirm_in_studio"
|
|
191
250
|
: "read_current_platform_facts_without_replaying_business"
|
|
@@ -221,14 +280,19 @@ try {
|
|
|
221
280
|
const signal=new AbortController();
|
|
222
281
|
const abort=()=>signal.abort();process.once('SIGINT',abort);process.once('SIGTERM',abort);
|
|
223
282
|
try{
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
283
|
+
const host=resolveHostIdentity({host:value('--host')}),installer=host.kind==='claude-code'?installForClaudeUser:installForUser;
|
|
284
|
+
const installed=await installer({sourceRoot:fileURLToPath(new URL('..',import.meta.url)),
|
|
285
|
+
executable:value('--claude-bin'),profile:value('--profile')??'default',configFile:configFile(),signal:signal.signal});
|
|
286
|
+
const skillNames=installed.skills?.map(skill=>skill.name)??['creation-setup','video-creation'];
|
|
287
|
+
log({...connection,pluginRegistered:(installed.pluginInstalled??true)&&installed.registered,
|
|
288
|
+
mcpRegistered:installed.registered,version:installed.version,
|
|
289
|
+
host:host.kind,pluginInstalled:installed.pluginInstalled??true,pluginEnabled:installed.pluginEnabled??true,
|
|
290
|
+
...(installed.installationMode?{installationMode:installed.installationMode,skillsInstalled:installed.skillsInstalled,skills:skillNames}:{}),
|
|
291
|
+
hostMcpConnected:'not_verified',sessionLoaded:'not_verified',
|
|
228
292
|
installationReused:installed.reused,profile:installed.profile,
|
|
229
293
|
requestedVersion:installed.requestedVersion,versionStatus:installed.versionStatus,
|
|
230
294
|
recordedRuntimeRetained:installed.recordedRuntimeRetained??false,
|
|
231
|
-
next:'On this host, open a new Local chat (CLI: start a new session). Check
|
|
295
|
+
next:(host.kind==='claude-code'?'On this host, start a new Claude Code session.':'On this host, open a new Local chat (CLI: start a new session).')+' Check '+skillNames.join(', ')+' 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.':''),
|
|
232
296
|
hostThreadIdentity:'verified_by_the_platform_on_actual_host_tool_calls'});
|
|
233
297
|
}finally{process.removeListener('SIGINT',abort);process.removeListener('SIGTERM',abort);}
|
|
234
298
|
}
|
|
@@ -244,7 +308,7 @@ try {
|
|
|
244
308
|
});
|
|
245
309
|
} else if (command === "help" || command === "--help" || !command) {
|
|
246
310
|
process.stdout.write(
|
|
247
|
-
"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
|
|
311
|
+
"promptframe-creation connect --endpoint <platform-api-base> [--host codex|claude-code] [--profile <environment-account>] [--claude-bin <absolute-file>] [--no-open]\npromptframe-creation setup --endpoint <platform-api-base> [--host codex|claude-code] [--no-open] [--replace] [--name <client-name>]\npromptframe-creation status [--profile <environment-account>] [--host codex|claude-code]\npromptframe-creation bridge [--config <private-file>] [--host codex|claude-code] [--bridge-version <X.Y.Z>]\npromptframe-creation --version\nNode.js >=20 is required. Plugin installation supports Codex >=0.160.0 or Claude Code >=2.0.12 with its structured plugin commands. Token input is masked in a terminal or accepted through --token-stdin; never use a Token command argument.\nBridge startup checks the platform minimum/recommended version. --bridge-version locks one exact compatible version for this new session; active bridges are not replaced.\n",
|
|
248
312
|
);
|
|
249
313
|
} else throw new CreationClientError("command.unknown");
|
|
250
314
|
} catch (error) {
|
|
@@ -252,6 +316,11 @@ try {
|
|
|
252
316
|
process.stderr.write(
|
|
253
317
|
JSON.stringify({
|
|
254
318
|
...installationErrorDetails(error),
|
|
319
|
+
...claudeInstallationDetails(error),
|
|
320
|
+
...claudeErrorDetails(error),
|
|
321
|
+
...fallbackErrorDetails(error),
|
|
322
|
+
...bridgeErrorDetails(error),
|
|
323
|
+
...runtimeErrorDetails(error),
|
|
255
324
|
error:
|
|
256
325
|
error instanceof CreationClientError
|
|
257
326
|
? error.message
|
package/lib/connection.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
3
|
import {CLIENT_VERSION,CLIENT_PROTOCOL} from './version.mjs';
|
|
4
|
+
import {resolveHostIdentity,hostClientName} from './host-identity.mjs';
|
|
5
|
+
import {assertBridgeCompatible,declaredHostContentTypes,readPlatformBridgePolicy} from './bridge-negotiation.mjs';
|
|
4
6
|
|
|
5
|
-
export async function connectPlatform(credentials) {
|
|
7
|
+
export async function connectPlatform(credentials,{host=resolveHostIdentity(),contentTypes=()=>['text'],contentSource=()=> 'text-fallback',enforceMinimum=true,signal}={}) {
|
|
6
8
|
const client = new Client(
|
|
7
9
|
{ name: "promptframe-creation-bridge", version: CLIENT_VERSION },
|
|
8
10
|
{ capabilities: {} },
|
|
@@ -10,22 +12,31 @@ export async function connectPlatform(credentials) {
|
|
|
10
12
|
const transport = new StreamableHTTPClientTransport(
|
|
11
13
|
new URL(credentials.endpoint),
|
|
12
14
|
{
|
|
15
|
+
fetch:(url,init)=>{
|
|
16
|
+
const headers=new Headers(init?.headers);
|
|
17
|
+
const types=declaredHostContentTypes({experimental:{'promptframe.contentTypes':contentTypes()}});
|
|
18
|
+
headers.set('X-PromptFrame-Content-Types',JSON.stringify(types));
|
|
19
|
+
headers.set('X-PromptFrame-Content-Source',contentSource());
|
|
20
|
+
return fetch(url,{...init,headers,...(signal?{signal:init?.signal?AbortSignal.any([init.signal,signal]):signal}:{})});
|
|
21
|
+
},
|
|
13
22
|
requestInit: {
|
|
14
23
|
headers: {
|
|
15
24
|
Authorization: "Bearer " + credentials.token,
|
|
16
|
-
"X-PromptFrame-Host-Kind":
|
|
25
|
+
"X-PromptFrame-Host-Kind": host.kind,
|
|
17
26
|
"X-PromptFrame-Creation-Protocol": CLIENT_PROTOCOL,
|
|
18
27
|
"X-PromptFrame-Client-Version": CLIENT_VERSION,
|
|
19
28
|
"X-PromptFrame-Client-Id": credentials.clientId,
|
|
20
29
|
"X-PromptFrame-Client-Name": encodeURIComponent(
|
|
21
|
-
credentials.clientName,
|
|
30
|
+
hostClientName(credentials.clientName,host),
|
|
22
31
|
),
|
|
23
32
|
},
|
|
24
33
|
},
|
|
25
34
|
},
|
|
26
35
|
);
|
|
27
36
|
try {
|
|
28
|
-
await client.connect(transport);
|
|
37
|
+
await client.connect(transport,signal?{signal}:undefined);
|
|
38
|
+
if(enforceMinimum)assertBridgeCompatible(client.getServerCapabilities(),CLIENT_VERSION);
|
|
39
|
+
else readPlatformBridgePolicy(client.getServerCapabilities());
|
|
29
40
|
return client;
|
|
30
41
|
} catch (error) {
|
|
31
42
|
await client.close().catch(() => {});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {CreationClientError} from './credentials.mjs';
|
|
2
|
+
|
|
3
|
+
export const MCP_BLOCK_BYTES=400_000;
|
|
4
|
+
export const MCP_RESPONSE_BYTES=2_000_000;
|
|
5
|
+
const bytes=value=>Buffer.byteLength(JSON.stringify(value),'utf8');
|
|
6
|
+
|
|
7
|
+
/** Inspect the serialized response, including base64 and metadata. Refusing
|
|
8
|
+
* an oversized result never retries the accepted business operation. */
|
|
9
|
+
export function assertMcpResponseBudget(result){
|
|
10
|
+
if(bytes(result)>MCP_RESPONSE_BYTES)throw new CreationClientError('creation.response_budget_exceeded');
|
|
11
|
+
const blocks=[...(result.content??[]),...(result.contents??[])];
|
|
12
|
+
for(const message of result.messages??[])if(message.content)blocks.push(message.content);
|
|
13
|
+
if(blocks.some(block=>bytes(block)>MCP_BLOCK_BYTES))throw new CreationClientError('creation.content_budget_exceeded');
|
|
14
|
+
return result;
|
|
15
|
+
}
|