@promptframe/creation 0.2.7 → 0.3.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 +1 -1
- package/.claude-mcp.json +8 -0
- package/.claude-plugin/marketplace.json +5 -0
- package/.claude-plugin/plugin.json +60 -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 +6222 -1557
- package/docs/development.md +20 -1
- package/docs/install-guidance.json +36 -0
- package/docs/installing.md +23 -3
- package/docs/releases/0.3.0.md +10 -0
- package/docs/releases/0.3.1.md +7 -0
- package/lib/bridge-negotiation.mjs +54 -0
- package/lib/claude-command.mjs +57 -0
- package/lib/claude-hook-definition.mjs +11 -0
- package/lib/claude-hook-registration.mjs +66 -0
- package/lib/claude-host-process.mjs +48 -0
- package/lib/claude-host-session.mjs +150 -0
- package/lib/claude-installation.mjs +195 -0
- package/lib/claude-local-state.mjs +17 -0
- package/lib/claude-mcp-installation.mjs +177 -0
- package/lib/cli.mjs +89 -15
- package/lib/connection.mjs +15 -4
- package/lib/content-budget.mjs +15 -0
- package/lib/host-context.mjs +178 -123
- package/lib/host-identity.mjs +34 -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,195 @@
|
|
|
1
|
+
import {createHash,randomBytes} from 'node:crypto';
|
|
2
|
+
import {mkdir,open,readFile,rename,rm} from 'node:fs/promises';
|
|
3
|
+
import {homedir} from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {claudeHostHooks} from './claude-hook-definition.mjs';
|
|
6
|
+
import {CreationClientError} from './credentials.mjs';
|
|
7
|
+
import {inspectRuntimePackage} from './runtime-package.mjs';
|
|
8
|
+
import {profileCredentialsPath,installationFiles} from './user-installation.mjs';
|
|
9
|
+
import {createClaudeRunner,claudeErrorDetails} from './claude-command.mjs';
|
|
10
|
+
import {readClaudeUserServer} from './claude-local-state.mjs';
|
|
11
|
+
import {installClaudeMcpFallback} from './claude-mcp-installation.mjs';
|
|
12
|
+
|
|
13
|
+
const {info,privateDirectory,privateRead,atomicJSON,acquire,runNode,checkInstalledRuntime,compareVersions,validProfile}=installationFiles;
|
|
14
|
+
const hash=b=>createHash('sha256').update(b).digest('hex');
|
|
15
|
+
const effectiveRoot=plugin=>plugin.readFromFolder??plugin.installPath;
|
|
16
|
+
class ClaudeInstallationError extends CreationClientError{
|
|
17
|
+
constructor(code,details){super('installation.'+code);this.details=details;}
|
|
18
|
+
}
|
|
19
|
+
export const claudeInstallationDetails=error=>error instanceof ClaudeInstallationError?error.details:undefined;
|
|
20
|
+
const fail=(code,details)=>{throw new ClaudeInstallationError(code,details);};
|
|
21
|
+
async function jsonCommand(run,args){
|
|
22
|
+
const body=await run(args);let value;
|
|
23
|
+
try{if(typeof body!=='string'||Buffer.byteLength(body)>2*1024*1024)throw Error();value=JSON.parse(body);}catch{fail('claude_local_registration_unconfirmed');}
|
|
24
|
+
if(!Array.isArray(value)||value.length>1024)fail('claude_local_registration_unconfirmed');return value;
|
|
25
|
+
}
|
|
26
|
+
async function registrations(run,pluginName,marketplace,root){
|
|
27
|
+
const [plugins,markets]=await Promise.all([jsonCommand(run,['plugin','list','--json']),
|
|
28
|
+
jsonCommand(run,['plugin','marketplace','list','--json'])]);
|
|
29
|
+
if(plugins.some(p=>!p||typeof p.id!=='string'||!p.id||p.id.length>256||typeof p.scope!=='string'
|
|
30
|
+
||typeof p.version!=='string'||typeof p.enabled!=='boolean'||typeof p.installPath!=='string')
|
|
31
|
+
||markets.some(p=>!p||typeof p.name!=='string'||!p.name||typeof p.source!=='string'))
|
|
32
|
+
fail('claude_local_registration_unconfirmed');
|
|
33
|
+
const related=plugins.filter(p=>typeof p?.id==='string'&&p.id.startsWith(pluginName+'@'));
|
|
34
|
+
if(related.length>1||related.some(p=>p.id!==pluginName+'@'+marketplace||p.scope!=='user'
|
|
35
|
+
||typeof p.enabled!=='boolean'||!/^\d+\.\d+\.\d+$/.test(p.version??'')||!path.isAbsolute(p.installPath??'')
|
|
36
|
+
||p.readFromFolder!==undefined&&(!path.isAbsolute(p.readFromFolder)||p.folderVersion!==p.version)))
|
|
37
|
+
fail('claude_existing_registration_requires_review');
|
|
38
|
+
const found=markets.filter(p=>p?.name===marketplace);
|
|
39
|
+
if(found.length>1||found.some(p=>p.source!=='directory'||p.path!==root||p.installLocation!==root))
|
|
40
|
+
fail('claude_existing_registration_requires_review');
|
|
41
|
+
return{plugin:related[0],market:found[0]};
|
|
42
|
+
}
|
|
43
|
+
async function legacyUserMcp(env,serverName){
|
|
44
|
+
// Reading configuration does not start or health-check any MCP server.
|
|
45
|
+
if(await readClaudeUserServer(serverName,env))fail('legacy_mcp_entry_requires_review');
|
|
46
|
+
}
|
|
47
|
+
function transport(serverName,configFile,command=process.execPath){
|
|
48
|
+
return{mcpServers:{[serverName]:{command,
|
|
49
|
+
args:['${CLAUDE_PLUGIN_ROOT}/bin/promptframe-creation.mjs','bridge','--config',configFile,'--host','claude-code']}}};
|
|
50
|
+
}
|
|
51
|
+
async function verifyVersion(root,{version,profile,configFile,payloadDigest,pluginName,serverName}){
|
|
52
|
+
const directory=await info(root);
|
|
53
|
+
if(!directory?.isDirectory()||directory.isSymbolicLink()||directory.uid!==process.getuid?.()||(directory.mode&0o077))
|
|
54
|
+
fail('claude_installed_files_invalid');
|
|
55
|
+
const ready=await privateRead(path.join(root,'installation.json'));
|
|
56
|
+
if(!ready||ready.host!=='claude-code'||ready.version!==version||ready.profile!==profile||ready.configFile!==configFile
|
|
57
|
+
||ready.payloadDigest!==payloadDigest||!Array.isArray(ready.files)||ready.files.length>1024)fail('claude_installed_files_invalid');
|
|
58
|
+
const actual=await inspectRuntimePackage(root);
|
|
59
|
+
if(actual.version!==version||JSON.stringify(actual.files.map(({path,bytes,sha256})=>({path,bytes,sha256})))!==JSON.stringify(ready.files))
|
|
60
|
+
fail('claude_installed_files_invalid');
|
|
61
|
+
const manifest=JSON.parse(await readFile(path.join(root,'.claude-plugin/plugin.json'),'utf8'));
|
|
62
|
+
if(manifest.name!==pluginName||manifest.version!==version||manifest.skills!=='./skills/'||manifest.mcpServers!=='./.claude-mcp.json')
|
|
63
|
+
fail('claude_installed_files_invalid');
|
|
64
|
+
let runtimeCommand;
|
|
65
|
+
for(const file of['.mcp.json','.claude-mcp.json']){
|
|
66
|
+
const mcp=JSON.parse(await readFile(path.join(root,file),'utf8'));
|
|
67
|
+
const command=mcp.mcpServers?.[serverName]?.command;
|
|
68
|
+
if(!path.isAbsolute(command??'')||runtimeCommand!==undefined&&command!==runtimeCommand
|
|
69
|
+
||JSON.stringify(mcp)!==JSON.stringify(transport(serverName,configFile,command)))fail('claude_installed_files_invalid');
|
|
70
|
+
runtimeCommand=command;
|
|
71
|
+
}
|
|
72
|
+
if(compareVersions(version,'0.3.1')>=0&&JSON.stringify(manifest.hooks)!==JSON.stringify(claudeHostHooks({pluginName,configFile,nodeCommand:runtimeCommand})))
|
|
73
|
+
fail('claude_installed_files_invalid');
|
|
74
|
+
return{...ready,runtimeCommand};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Official local-directory marketplace only. The host loads immutable version
|
|
78
|
+
* directories in place; this adapter never updates/prunes host caches or starts
|
|
79
|
+
* Claude model sessions. Codex registration and credentials stay independent. */
|
|
80
|
+
export async function installForClaudeUser(options={}){
|
|
81
|
+
const profile=options.profile??'default',env=options.env??process.env;validProfile(profile);
|
|
82
|
+
// One installer-owned mode guard covers selection and registration for this
|
|
83
|
+
// host/profile. It does not lock Claude's configuration or other clients.
|
|
84
|
+
const modeRoot=path.resolve(env.XDG_DATA_HOME??path.join(homedir(),'.local/share'),'promptframe-creation',profile,'claude-code-mode');
|
|
85
|
+
await privateDirectory(modeRoot);const release=await acquire(modeRoot,options.signal);
|
|
86
|
+
try{return await installClaudeUserLocked(options);}finally{await release();}
|
|
87
|
+
}
|
|
88
|
+
async function installClaudeUserLocked({sourceRoot,profile='default',env=process.env,
|
|
89
|
+
configFile=profileCredentialsPath(profile,env),executable,signal,
|
|
90
|
+
runClaude=createClaudeRunner({env,executable,signal}),checkRuntime=runNode,verifyInstalledRuntime=checkInstalledRuntime,
|
|
91
|
+
nodeCommand=process.execPath}={}){
|
|
92
|
+
validProfile(profile);
|
|
93
|
+
if(!path.isAbsolute(nodeCommand))fail('runtime_command_invalid');
|
|
94
|
+
const hostVersion=(await runClaude(['--version'])).trim().match(/^(\d+\.\d+\.\d+) \(Claude Code\)$/);
|
|
95
|
+
if(!hostVersion||compareVersions(hostVersion[1],'2.1.295')<0)fail('claude_21295_required');
|
|
96
|
+
const help=await runClaude(['--help']);
|
|
97
|
+
if(typeof help!=='string'||Buffer.byteLength(help)>128*1024)fail('claude_capabilities_unconfirmed');
|
|
98
|
+
const hasPlugin=/^\s+plugin(?:\|plugins)?\s/m.test(help),hasMcp=/^\s+mcp\s/m.test(help);
|
|
99
|
+
const base=path.resolve(env.XDG_DATA_HOME??path.join(homedir(),'.local/share'),'promptframe-creation',profile),
|
|
100
|
+
fallbackRoot=path.join(base,'claude-code-mcp'),pluginRoot=path.join(base,'claude-code');
|
|
101
|
+
const pluginPending=await info(path.join(pluginRoot,'registration-pending.json')),pluginCurrent=await info(path.join(pluginRoot,'current.json')),
|
|
102
|
+
fallbackState=await info(path.join(fallbackRoot,'current.json'))||await info(path.join(fallbackRoot,'registration-pending.json'));
|
|
103
|
+
if((!hasPlugin||fallbackState)&&(pluginPending||pluginCurrent))fail('registration_unconfirmed_keep_existing');
|
|
104
|
+
if(!hasPlugin||fallbackState){
|
|
105
|
+
if(!hasMcp)fail('claude_capabilities_unconfirmed');
|
|
106
|
+
return installClaudeMcpFallback({sourceRoot,profile,env,configFile,signal,runClaude,checkRuntime,verifyInstalledRuntime,nodeCommand});
|
|
107
|
+
}
|
|
108
|
+
const payload=await inspectRuntimePackage(path.resolve(sourceRoot));
|
|
109
|
+
if(!payload.files.some(f=>f.path==='.claude-plugin/plugin.json')||!payload.files.some(f=>f.path==='.claude-mcp.json'))
|
|
110
|
+
fail('claude_package_incomplete');
|
|
111
|
+
const root=path.resolve(env.XDG_DATA_HOME??path.join(homedir(),'.local/share'),'promptframe-creation',profile,'claude-code');
|
|
112
|
+
await privateDirectory(root);const release=await acquire(root,signal);
|
|
113
|
+
const suffix=profile==='default'?'':'-'+profile,pluginName='promptframe-creation'+suffix,
|
|
114
|
+
marketplace='promptframe-creation-user'+suffix,pluginId=pluginName+'@'+marketplace,serverName='promptframe'+suffix;
|
|
115
|
+
const versions=path.join(root,'versions'),currentFile=path.join(root,'current.json'),pendingFile=path.join(root,'registration-pending.json'),
|
|
116
|
+
catalogFile=path.join(root,'.claude-plugin/marketplace.json'),versionRoot=path.join(versions,payload.version),
|
|
117
|
+
temporary=path.join(versions,'.partial-'+randomBytes(12).toString('hex'));
|
|
118
|
+
let registrationStarted=false,newFiles=0;
|
|
119
|
+
try{
|
|
120
|
+
signal?.throwIfAborted();await privateDirectory(versions);await privateDirectory(path.dirname(catalogFile));
|
|
121
|
+
await legacyUserMcp(env,serverName);
|
|
122
|
+
let previous=await privateRead(currentFile),pending=await privateRead(pendingFile),state=await registrations(runClaude,pluginName,marketplace,root);
|
|
123
|
+
const binding={profile,configFile,pluginId,pluginName,serverName,host:'claude-code'};
|
|
124
|
+
const checkBinding=record=>{if(record&&(record.profile!==profile||record.configFile!==configFile||record.pluginId!==pluginId
|
|
125
|
+
||record.host!=='claude-code'||!/^\d+\.\d+\.\d+$/.test(record.version??'')
|
|
126
|
+
||record.versionRoot!==path.join(versions,record.version)))fail('profile_binding_conflict');};
|
|
127
|
+
checkBinding(previous);checkBinding(pending);
|
|
128
|
+
const runtimeCommands=new Map();
|
|
129
|
+
const observed=async record=>{
|
|
130
|
+
if(!state.market||!state.plugin||state.plugin.enabled!==true||state.plugin.version!==record.version||effectiveRoot(state.plugin)!==record.versionRoot)return false;
|
|
131
|
+
const ready=await verifyVersion(record.versionRoot,{...record,pluginName,serverName});
|
|
132
|
+
runtimeCommands.set(record.versionRoot,ready.runtimeCommand);return true;
|
|
133
|
+
};
|
|
134
|
+
if(pending){
|
|
135
|
+
if(await observed(pending)){
|
|
136
|
+
await atomicJSON(currentFile,pending);await rm(pendingFile);previous=pending;pending=null;
|
|
137
|
+
}else if(pending.phase!=='marketplace'||!state.market||state.plugin)
|
|
138
|
+
fail('registration_unconfirmed_keep_existing',{phase:'registration_observation',localRegistrationState:'unknown',action:'inspect_same_registration_no_second_add'});
|
|
139
|
+
}
|
|
140
|
+
if(state.plugin&&!previous&&!pending)fail('claude_existing_registration_requires_review');
|
|
141
|
+
if(previous&&(!await observed(previous))&&!pending)fail('claude_local_registration_unconfirmed');
|
|
142
|
+
if(previous&&compareVersions(previous.version,payload.version)>0){
|
|
143
|
+
const recorded=runtimeCommands.get(previous.versionRoot);
|
|
144
|
+
await verifyInstalledRuntime(previous.versionRoot,previous.version,recorded,{env});
|
|
145
|
+
return{...previous,currentFile,reused:true,installedFiles:0,registered:true,pluginInstalled:true,versionStatus:'newer_retained',
|
|
146
|
+
requestedVersion:payload.version,recordedRuntimeRetained:recorded!==nodeCommand};
|
|
147
|
+
}
|
|
148
|
+
const complete={...binding,version:payload.version,versionRoot,payloadDigest:payload.payloadDigest};
|
|
149
|
+
if(pending&&(pending.version!==complete.version||pending.payloadDigest!==complete.payloadDigest))
|
|
150
|
+
fail('registration_unconfirmed_keep_existing');
|
|
151
|
+
if(await info(versionRoot)){
|
|
152
|
+
const ready=await verifyVersion(versionRoot,{...complete,pluginName,serverName});runtimeCommands.set(versionRoot,ready.runtimeCommand);
|
|
153
|
+
}
|
|
154
|
+
else{
|
|
155
|
+
await mkdir(temporary,{mode:0o700});
|
|
156
|
+
for(const file of payload.files){signal?.throwIfAborted();const dest=path.join(temporary,file.path);
|
|
157
|
+
await mkdir(path.dirname(dest),{recursive:true,mode:0o700});const fd=await open(dest,'wx',0o600);
|
|
158
|
+
try{await fd.writeFile(file.body);await fd.sync();}finally{await fd.close();}}
|
|
159
|
+
const manifest=JSON.parse(await readFile(path.join(temporary,'.claude-plugin/plugin.json'),'utf8'));manifest.name=pluginName;
|
|
160
|
+
if(manifest.hooks)manifest.hooks=claudeHostHooks({pluginName,configFile,nodeCommand});
|
|
161
|
+
await atomicJSON(path.join(temporary,'.claude-plugin/plugin.json'),manifest);
|
|
162
|
+
for(const file of['.mcp.json','.claude-mcp.json'])await atomicJSON(path.join(temporary,file),transport(serverName,configFile,nodeCommand));
|
|
163
|
+
await checkRuntime(temporary,payload.version);
|
|
164
|
+
const installed=await inspectRuntimePackage(temporary);
|
|
165
|
+
await atomicJSON(path.join(temporary,'installation.json'),{...binding,version:payload.version,payloadDigest:payload.payloadDigest,
|
|
166
|
+
files:installed.files.map(({path,bytes,sha256})=>({path,bytes,sha256}))});
|
|
167
|
+
signal?.throwIfAborted();await rename(temporary,versionRoot);newFiles=payload.files.length;
|
|
168
|
+
}
|
|
169
|
+
if(newFiles===0)await verifyInstalledRuntime(versionRoot,payload.version,runtimeCommands.get(versionRoot),{env});
|
|
170
|
+
const already=previous?.version===payload.version&&previous.payloadDigest===payload.payloadDigest&&await observed(complete);
|
|
171
|
+
if(!already){
|
|
172
|
+
await atomicJSON(catalogFile,{name:marketplace,owner:{name:'PromptFrame'},plugins:[{name:pluginName,source:'./versions/'+payload.version}]});
|
|
173
|
+
if(!state.market){
|
|
174
|
+
if(pending)fail('registration_unconfirmed_keep_existing');
|
|
175
|
+
await atomicJSON(pendingFile,{...complete,phase:'marketplace'});registrationStarted=true;
|
|
176
|
+
await runClaude(['plugin','marketplace','add',root,'--scope','user','--json']);
|
|
177
|
+
state=await registrations(runClaude,pluginName,marketplace,root);
|
|
178
|
+
if(!state.market)fail('claude_registration_unconfirmed');
|
|
179
|
+
}
|
|
180
|
+
await atomicJSON(pendingFile,{...complete,phase:'plugin'});registrationStarted=true;
|
|
181
|
+
await runClaude(['plugin','install',pluginId,'--scope','user','--json']);
|
|
182
|
+
state=await registrations(runClaude,pluginName,marketplace,root);
|
|
183
|
+
if(!await observed(complete))fail('claude_registration_unconfirmed');
|
|
184
|
+
await atomicJSON(currentFile,complete);await rm(pendingFile);
|
|
185
|
+
}
|
|
186
|
+
return{...complete,currentFile,reused:newFiles===0,installedFiles:newFiles,registered:true,pluginInstalled:true,
|
|
187
|
+
reloadRequired:!already,versionStatus:'current',requestedVersion:payload.version,
|
|
188
|
+
recordedRuntimeRetained:runtimeCommands.has(versionRoot)&&runtimeCommands.get(versionRoot)!==nodeCommand};
|
|
189
|
+
}catch(error){
|
|
190
|
+
if(registrationStarted)fail('registration_unconfirmed_keep_existing',{...claudeErrorDetails(error),
|
|
191
|
+
phase:'registration_observation',localRegistrationState:'unknown',action:'inspect_same_registration_no_second_add'});
|
|
192
|
+
if(error instanceof CreationClientError)throw error;
|
|
193
|
+
fail(signal?.aborted?'interrupted_keep_existing':'failed_keep_existing');
|
|
194
|
+
}finally{await rm(temporary,{recursive:true,force:true});await release();}
|
|
195
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {readFile,lstat} from 'node:fs/promises';
|
|
2
|
+
import {homedir} from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {CreationClientError} from './credentials.mjs';
|
|
5
|
+
|
|
6
|
+
export function claudeConfigRoot(env=process.env){return path.resolve(env.CLAUDE_CONFIG_DIR??path.join(homedir(),'.claude'));}
|
|
7
|
+
export async function readClaudeUserServer(serverName,env=process.env){
|
|
8
|
+
const file=env.CLAUDE_CONFIG_DIR?path.join(claudeConfigRoot(env),'.claude.json'):path.join(homedir(),'.claude.json');
|
|
9
|
+
let info;try{info=await lstat(file);}catch(e){if(e.code==='ENOENT')return null;throw new CreationClientError('installation.claude_local_registration_unconfirmed');}
|
|
10
|
+
if(!info.isFile()||info.isSymbolicLink()||info.uid!==process.getuid?.()||info.size>4*1024*1024)
|
|
11
|
+
throw new CreationClientError('installation.claude_local_registration_unconfirmed');
|
|
12
|
+
let state;try{state=JSON.parse(await readFile(file,'utf8'));}catch{throw new CreationClientError('installation.claude_local_registration_unconfirmed');}
|
|
13
|
+
if(!state||typeof state!=='object'||Array.isArray(state))throw new CreationClientError('installation.claude_local_registration_unconfirmed');
|
|
14
|
+
if(state?.mcpServers!==undefined&&(!state.mcpServers||typeof state.mcpServers!=='object'||Array.isArray(state.mcpServers)))
|
|
15
|
+
throw new CreationClientError('installation.claude_local_registration_unconfirmed');
|
|
16
|
+
return state?.mcpServers?.[serverName]??null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
import {registerClaudeFallbackHooks,verifyClaudeFallbackHooks} from './claude-hook-registration.mjs';
|
|
10
|
+
|
|
11
|
+
const {info,privateDirectory,privateRead,atomicJSON,acquire,compareVersions}=installationFiles;
|
|
12
|
+
const hash=body=>createHash('sha256').update(body).digest('hex');
|
|
13
|
+
class FallbackError extends CreationClientError{
|
|
14
|
+
constructor(code,details){super('installation.'+code);this.details=details;}
|
|
15
|
+
}
|
|
16
|
+
export const fallbackErrorDetails=error=>error instanceof FallbackError?error.details:undefined;
|
|
17
|
+
const fail=(code,details)=>{throw new FallbackError(code,details);};
|
|
18
|
+
export async function claimSkillDirectory(root){
|
|
19
|
+
try{await mkdir(root,{mode:0o700});}catch(error){if(error.code==='EEXIST')fail('claude_skill_requires_review');throw error;}
|
|
20
|
+
}
|
|
21
|
+
function same(a,b,depth=0){
|
|
22
|
+
if(a===b)return true;if(depth>8||!a||!b||typeof a!=='object'||typeof b!=='object'||Array.isArray(a)!==Array.isArray(b))return false;
|
|
23
|
+
const left=Object.keys(a).sort(),right=Object.keys(b).sort();
|
|
24
|
+
return left.length<=256&&left.length===right.length&&left.every((key,i)=>key===right[i]&&same(a[key],b[key],depth+1));
|
|
25
|
+
}
|
|
26
|
+
async function atomicText(file,body){
|
|
27
|
+
const temporary=file+'.'+randomBytes(12).toString('hex')+'.tmp';
|
|
28
|
+
try{const fd=await open(temporary,'wx',0o600);try{await fd.writeFile(body);await fd.sync();}finally{await fd.close();}
|
|
29
|
+
await rename(temporary,file);const dir=await open(path.dirname(file),'r');try{await dir.sync();}finally{await dir.close();}
|
|
30
|
+
}finally{if(await info(temporary))await rm(temporary);}
|
|
31
|
+
}
|
|
32
|
+
async function verifyVersion(root,record){
|
|
33
|
+
const directory=await info(root);
|
|
34
|
+
if(!directory?.isDirectory()||directory.isSymbolicLink()||directory.uid!==process.getuid?.()||(directory.mode&0o077))fail('claude_installed_files_invalid');
|
|
35
|
+
const marker=await privateRead(path.join(root,'installation.json')),payload=await inspectRuntimePackage(root);
|
|
36
|
+
if(!marker||marker.host!=='claude-code'||marker.mode!=='mcp-and-skills'||marker.profile!==record.profile
|
|
37
|
+
||marker.configFile!==record.configFile||marker.version!==record.version||marker.payloadDigest!==record.payloadDigest
|
|
38
|
+
||payload.payloadDigest!==marker.payloadDigest||!path.isAbsolute(marker.nodeCommand??''))fail('claude_installed_files_invalid');
|
|
39
|
+
return marker;
|
|
40
|
+
}
|
|
41
|
+
function mcpDefinition(record,nodeCommand){return{type:'stdio',command:nodeCommand,
|
|
42
|
+
args:[path.join(record.versionRoot,'bin/promptframe-creation.mjs'),'bridge','--config',record.configFile,'--host','claude-code']};}
|
|
43
|
+
function skillBody(payload,sourceName,name){
|
|
44
|
+
const file=payload.files.find(f=>f.path==='skills/'+sourceName+'/SKILL.md');if(!file)fail('package_incomplete');
|
|
45
|
+
const body=file.body.toString('utf8');
|
|
46
|
+
if(!body.startsWith('---\n')||!body.includes('\nname: '+sourceName+'\n'))fail('package_incomplete');
|
|
47
|
+
return body.replace('\nname: '+sourceName+'\n','\nname: '+name+'\n');
|
|
48
|
+
}
|
|
49
|
+
async function observedSkill(plan,record,{allowBefore=false}={}){
|
|
50
|
+
const directory=await info(plan.root);if(!directory)return false;
|
|
51
|
+
if(!directory.isDirectory()||directory.isSymbolicLink()||directory.uid!==process.getuid?.()||(directory.mode&0o077))fail('claude_skill_requires_review');
|
|
52
|
+
const names=await readdir(plan.root);
|
|
53
|
+
if(names.some(n=>!['SKILL.md','promptframe-installation.json'].includes(n)))fail('claude_skill_requires_review');
|
|
54
|
+
const marker=await privateRead(path.join(plan.root,'promptframe-installation.json')),file=path.join(plan.root,'SKILL.md'),s=await info(file);
|
|
55
|
+
if(!marker||marker.host!=='claude-code'||marker.profile!==record.profile||marker.configFile!==record.configFile||marker.name!==plan.name)
|
|
56
|
+
fail('claude_skill_requires_review');
|
|
57
|
+
if(!s&&allowBefore&&plan.beforeSHA===null&&marker.sha256===null)return false;
|
|
58
|
+
if(!s?.isFile()||s.isSymbolicLink()||s.size>256*1024)fail('claude_skill_requires_review');
|
|
59
|
+
const digest=hash(await readFile(file));
|
|
60
|
+
if(digest===plan.sha256&&marker.sha256===plan.sha256)return true;
|
|
61
|
+
if(allowBefore&&(digest===plan.beforeSHA||digest===plan.sha256)&&marker.sha256===plan.beforeSHA)return false;
|
|
62
|
+
fail('claude_skill_requires_review');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Used only when help positively lacks plugin commands, or for an existing
|
|
66
|
+
* owned fallback. It never follows an unknown plugin-registration attempt. */
|
|
67
|
+
export async function installClaudeMcpFallback({sourceRoot,profile,env,configFile,signal,runClaude,checkRuntime,verifyInstalledRuntime,nodeCommand,
|
|
68
|
+
writeSkill=atomicText}){
|
|
69
|
+
const payload=await inspectRuntimePackage(path.resolve(sourceRoot)),suffix=profile==='default'?'':'-'+profile,
|
|
70
|
+
serverName='promptframe'+suffix,root=path.resolve(env.XDG_DATA_HOME??path.join(homedir(),'.local/share'),'promptframe-creation',profile,'claude-code-mcp');
|
|
71
|
+
await privateDirectory(root);const release=await acquire(root,signal),versions=path.join(root,'versions'),currentFile=path.join(root,'current.json'),
|
|
72
|
+
pendingFile=path.join(root,'registration-pending.json'),versionRoot=path.join(versions,payload.version),
|
|
73
|
+
temporary=path.join(versions,'.partial-'+randomBytes(12).toString('hex'));
|
|
74
|
+
let writeStarted=false,newFiles=0;
|
|
75
|
+
const complete={host:'claude-code',mode:'mcp-and-skills',profile,configFile,serverName,version:payload.version,versionRoot,payloadDigest:payload.payloadDigest};
|
|
76
|
+
const checkBinding=record=>{
|
|
77
|
+
if(record&&(record.host!=='claude-code'||record.mode!=='mcp-and-skills'||record.profile!==profile||record.configFile!==configFile
|
|
78
|
+
||record.serverName!==serverName||!/^\d+\.\d+\.\d+$/.test(record.version??'')||record.versionRoot!==path.join(versions,record.version)))fail('profile_binding_conflict');
|
|
79
|
+
};
|
|
80
|
+
try{
|
|
81
|
+
await privateDirectory(versions);let previous=await privateRead(currentFile),pending=await privateRead(pendingFile);
|
|
82
|
+
checkBinding(previous);checkBinding(pending);
|
|
83
|
+
let saved=await readClaudeUserServer(serverName,env);
|
|
84
|
+
complete.beforeServer=pending?.beforeServer??saved;
|
|
85
|
+
const settled=async record=>{
|
|
86
|
+
const ready=await verifyVersion(record.versionRoot,record);
|
|
87
|
+
if(!same(record.server,mcpDefinition(record,ready.nodeCommand)))fail('claude_installed_files_invalid');
|
|
88
|
+
if(!same(saved,record.server))return false;
|
|
89
|
+
if(compareVersions(record.version,'0.3.1')>=0)await verifyClaudeFallbackHooks(record.hostHooks,env);
|
|
90
|
+
if(!Array.isArray(record.skills)||record.skills.length!==2)fail('claude_skill_requires_review');
|
|
91
|
+
for(const [i,skill]of record.skills.entries()){
|
|
92
|
+
const name=['creation-setup','video-creation'][i]+suffix;
|
|
93
|
+
if(skill.name!==name||skill.root!==path.join(claudeConfigRoot(env),'skills',name)||!/^[a-f0-9]{64}$/.test(skill.sha256??''))
|
|
94
|
+
fail('claude_skill_requires_review');
|
|
95
|
+
if(!await observedSkill(skill,record))return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
};
|
|
99
|
+
if(pending){
|
|
100
|
+
writeStarted=true;
|
|
101
|
+
if(pending.version!==complete.version||pending.payloadDigest!==complete.payloadDigest)fail('registration_unconfirmed_keep_existing');
|
|
102
|
+
if(pending.phase==='mcp'){
|
|
103
|
+
if(!await settled(pending))fail('registration_unconfirmed_keep_existing');
|
|
104
|
+
await atomicJSON(currentFile,pending);await rm(pendingFile);previous=pending;pending=null;
|
|
105
|
+
}else if(pending.phase!=='skills'||!same(saved,pending.beforeServer))fail('registration_unconfirmed_keep_existing');
|
|
106
|
+
}
|
|
107
|
+
if(previous&&!pending){
|
|
108
|
+
if(!await settled(previous))fail('claude_local_registration_unconfirmed');
|
|
109
|
+
if(compareVersions(previous.version,payload.version)>=0){
|
|
110
|
+
const ready=await verifyVersion(previous.versionRoot,previous);
|
|
111
|
+
await verifyInstalledRuntime(previous.versionRoot,previous.version,ready.nodeCommand,{env});
|
|
112
|
+
return{...previous,currentFile,registered:true,pluginInstalled:false,pluginEnabled:false,skillsInstalled:true,
|
|
113
|
+
installationMode:'mcp-and-skills',reused:true,installedFiles:0,requestedVersion:payload.version,
|
|
114
|
+
versionStatus:previous.version===payload.version?'current':'newer_retained',recordedRuntimeRetained:ready.nodeCommand!==nodeCommand};
|
|
115
|
+
}
|
|
116
|
+
}else if(saved&&!pending)fail('legacy_mcp_entry_requires_review');
|
|
117
|
+
if(await info(versionRoot))await verifyVersion(versionRoot,complete);
|
|
118
|
+
else{
|
|
119
|
+
await mkdir(temporary,{mode:0o700});
|
|
120
|
+
for(const file of payload.files){signal?.throwIfAborted();const dest=path.join(temporary,file.path);
|
|
121
|
+
await mkdir(path.dirname(dest),{recursive:true,mode:0o700});const fd=await open(dest,'wx',0o600);
|
|
122
|
+
try{await fd.writeFile(file.body);await fd.sync();}finally{await fd.close();}}
|
|
123
|
+
await checkRuntime(temporary,payload.version);
|
|
124
|
+
await atomicJSON(path.join(temporary,'installation.json'),{...complete,nodeCommand});
|
|
125
|
+
signal?.throwIfAborted();await rename(temporary,versionRoot);newFiles=payload.files.length;
|
|
126
|
+
}
|
|
127
|
+
const ready=await verifyVersion(versionRoot,complete);complete.server=mcpDefinition(complete,ready.nodeCommand);
|
|
128
|
+
if(newFiles===0)await verifyInstalledRuntime(versionRoot,payload.version,ready.nodeCommand,{env});
|
|
129
|
+
const skillRoot=path.join(claudeConfigRoot(env),'skills');await mkdir(skillRoot,{recursive:true,mode:0o700});
|
|
130
|
+
const parent=await lstat(skillRoot);
|
|
131
|
+
if(!parent.isDirectory()||parent.isSymbolicLink()||parent.uid!==process.getuid?.())fail('claude_skill_requires_review');
|
|
132
|
+
const plans=[];
|
|
133
|
+
for(const sourceName of['creation-setup','video-creation']){
|
|
134
|
+
const name=sourceName+suffix,body=skillBody(payload,sourceName,name),skill={name,root:path.join(skillRoot,name),sha256:hash(body)};
|
|
135
|
+
if(pending){const old=pending.skills?.find(s=>s.name===name);
|
|
136
|
+
if(!old||old.root!==skill.root||old.sha256!==skill.sha256)fail('registration_unconfirmed_keep_existing');
|
|
137
|
+
plans.push({...old,body});
|
|
138
|
+
}else{
|
|
139
|
+
const existing=await info(skill.root);let beforeSHA=null;
|
|
140
|
+
if(existing){
|
|
141
|
+
const marker=await privateRead(path.join(skill.root,'promptframe-installation.json'));
|
|
142
|
+
if(!marker||marker.profile!==profile||marker.configFile!==configFile||marker.name!==name)fail('claude_skill_requires_review');
|
|
143
|
+
const old={...skill,sha256:marker.sha256};if(!await observedSkill(old,complete))fail('claude_skill_requires_review');beforeSHA=marker.sha256;
|
|
144
|
+
}
|
|
145
|
+
plans.push({...skill,beforeSHA,body});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
complete.skills=plans.map(({body,...p})=>p);
|
|
149
|
+
if(!pending){await atomicJSON(pendingFile,{...complete,phase:'skills'});writeStarted=true;}
|
|
150
|
+
for(const plan of plans){
|
|
151
|
+
signal?.throwIfAborted();
|
|
152
|
+
if(await info(plan.root)){
|
|
153
|
+
if(await observedSkill(plan,complete,{allowBefore:true}))continue;
|
|
154
|
+
}else{
|
|
155
|
+
if(plan.beforeSHA!==null)fail('claude_skill_requires_review');await claimSkillDirectory(plan.root);
|
|
156
|
+
// A marker is written before the first body so interruption is tied to
|
|
157
|
+
// this pending identity rather than an unowned existing skill.
|
|
158
|
+
await atomicJSON(path.join(plan.root,'promptframe-installation.json'),{host:'claude-code',profile,configFile,name:plan.name,sha256:null});
|
|
159
|
+
}
|
|
160
|
+
await writeSkill(path.join(plan.root,'SKILL.md'),plan.body);
|
|
161
|
+
await atomicJSON(path.join(plan.root,'promptframe-installation.json'),{host:'claude-code',profile,configFile,name:plan.name,sha256:plan.sha256});
|
|
162
|
+
}
|
|
163
|
+
signal?.throwIfAborted();
|
|
164
|
+
if(compareVersions(payload.version,'0.3.1')>=0)complete.hostHooks=await registerClaudeFallbackHooks({record:complete,root,env,nodeCommand:ready.nodeCommand,signal});
|
|
165
|
+
if(!same(await readClaudeUserServer(serverName,env),complete.beforeServer))fail('claude_local_registration_changed');
|
|
166
|
+
await atomicJSON(pendingFile,{...complete,phase:'mcp'});writeStarted=true;
|
|
167
|
+
await runClaude(['mcp','add-json','--scope','user',serverName,JSON.stringify(complete.server)]);
|
|
168
|
+
saved=await readClaudeUserServer(serverName,env);
|
|
169
|
+
if(!await settled(complete))fail('registration_unconfirmed_keep_existing');
|
|
170
|
+
await atomicJSON(currentFile,complete);await rm(pendingFile);
|
|
171
|
+
return{...complete,currentFile,registered:true,pluginInstalled:false,pluginEnabled:false,skillsInstalled:true,
|
|
172
|
+
installationMode:'mcp-and-skills',reused:newFiles===0,installedFiles:newFiles,requestedVersion:payload.version,versionStatus:'current'};
|
|
173
|
+
}catch(error){
|
|
174
|
+
if(writeStarted)fail('registration_unconfirmed_keep_existing',{phase:'registration_observation',localRegistrationState:'unknown',action:'inspect_same_registration_no_second_add'});
|
|
175
|
+
if(error instanceof CreationClientError)throw error;fail(signal?.aborted?'interrupted_keep_existing':'failed_keep_existing');
|
|
176
|
+
}finally{await rm(temporary,{recursive:true,force:true});await release();}
|
|
177
|
+
}
|
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,15 @@ 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 {createClaudeHostSession,runClaudeHostHook} from './claude-host-session.mjs';
|
|
28
|
+
import {declaredHostContentCapabilities,readPlatformBridgePolicy,bridgeErrorDetails} from './bridge-negotiation.mjs';
|
|
29
|
+
import {selectBridgeRuntime,runtimeErrorDetails} from './runtime-bootstrap.mjs';
|
|
30
|
+
import {launchSelectedBridge} from './runtime-launch.mjs';
|
|
19
31
|
import {installForUser,profileCredentialsPath,installationErrorDetails} from './user-installation.mjs';
|
|
32
|
+
import {installForClaudeUser,claudeInstallationDetails} from './claude-installation.mjs';
|
|
33
|
+
import {claudeErrorDetails} from './claude-command.mjs';
|
|
34
|
+
import {fallbackErrorDetails} from './claude-mcp-installation.mjs';
|
|
20
35
|
import {fileURLToPath} from 'node:url';
|
|
21
36
|
import path from 'node:path';
|
|
22
37
|
|
|
@@ -30,7 +45,7 @@ const log = (value) => process.stdout.write(JSON.stringify(value) + "\n");
|
|
|
30
45
|
const configFile=()=>value('--config')?path.resolve(value('--config')):
|
|
31
46
|
profileCredentialsPath(value('--profile')??'default');
|
|
32
47
|
async function probe(credentials) {
|
|
33
|
-
const client = await connectPlatform(credentials);
|
|
48
|
+
const client = await connectPlatform(credentials,{host:resolveHostIdentity({host:value('--host')})});
|
|
34
49
|
try {
|
|
35
50
|
return (await client.listTools()).tools.length;
|
|
36
51
|
} finally {
|
|
@@ -143,7 +158,7 @@ async function setup({silent=false}={}) {
|
|
|
143
158
|
endpoint,
|
|
144
159
|
token,
|
|
145
160
|
clientId: existing?.clientId ?? randomBytes(24).toString("base64url"),
|
|
146
|
-
clientName: value("--name") ?? existing?.clientName ??
|
|
161
|
+
clientName: value("--name") ?? existing?.clientName ?? (resolveHostIdentity({host:value('--host')}).kind==='claude-code'?'Claude Code PromptFrame':'Codex PromptFrame'),
|
|
147
162
|
createdAt: existing?.createdAt ?? new Date().toISOString(),
|
|
148
163
|
};
|
|
149
164
|
// Verify before replacing the secure local file. This never calls a token
|
|
@@ -157,12 +172,58 @@ async function setup({silent=false}={}) {
|
|
|
157
172
|
async function bridge() {
|
|
158
173
|
const credentials = await readCredentials(configFile());
|
|
159
174
|
if (!credentials) throw new CreationClientError("setup.required");
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
175
|
+
let contentTypes=['text'],contentSource='text-fallback';
|
|
176
|
+
const identity=resolveHostIdentity({host:value('--host')}),startup=new AbortController(),abort=()=>startup.abort();
|
|
177
|
+
let client,upstream,policy,selection;
|
|
178
|
+
process.once('SIGINT',abort);process.once('SIGTERM',abort);
|
|
179
|
+
try{
|
|
180
|
+
client=await connectPlatform(credentials,{host:identity,contentTypes:()=>contentTypes,contentSource:()=>contentSource,
|
|
181
|
+
enforceMinimum:false,signal:startup.signal});
|
|
182
|
+
upstream=client.getServerCapabilities()??{};policy=readPlatformBridgePolicy(upstream);
|
|
183
|
+
selection=await selectBridgeRuntime({policy,currentVersion:CLIENT_VERSION,lockedVersion:value('--bridge-version'),
|
|
184
|
+
resolvedVersion:value('--resolved-runtime-version'),signal:startup.signal,hostKind:identity.kind,
|
|
185
|
+
cacheRoot:path.join(path.dirname(configFile()),'runtime-cache')});
|
|
186
|
+
startup.signal.throwIfAborted();
|
|
187
|
+
}catch(error){await client?.close().catch(()=>{});
|
|
188
|
+
if(startup.signal.aborted)throw new CreationClientError('creation.runtime_selection_interrupted');throw error;}
|
|
189
|
+
finally{process.removeListener('SIGINT',abort);process.removeListener('SIGTERM',abort);}
|
|
190
|
+
if(!selection.current){
|
|
191
|
+
await client.close();const result=await launchSelectedBridge(selection,{host:identity,configFile:configFile()});
|
|
192
|
+
process.exitCode=result.code;return;
|
|
193
|
+
}
|
|
194
|
+
const hostSession=identity.kind==='claude-code'?await createClaudeHostSession({configFile:configFile()}):undefined;
|
|
195
|
+
const server = new Server(
|
|
163
196
|
{ name: "promptframe-creation", version: CLIENT_VERSION },
|
|
164
|
-
{ capabilities: { tools: {}
|
|
165
|
-
|
|
197
|
+
{ capabilities: { tools: {listChanged:true},...(upstream.resources?{resources:{listChanged:true}}:{}),
|
|
198
|
+
...(upstream.prompts?{prompts:{listChanged:true}}:{}),
|
|
199
|
+
experimental:{...(policy?{'promptframe.creation':policy}:{}),
|
|
200
|
+
'promptframe.runtime':{version:selection.version,locked:selection.locked,status:selection.status}} } },
|
|
201
|
+
),
|
|
202
|
+
host=createHostCallBridge(client,{credentials,host:identity,hostSession,onCatalogChange:()=>server.sendToolListChanged(),
|
|
203
|
+
onKnowledgeChange:kind=>kind==='resources'?server.sendResourceListChanged():server.sendPromptListChanged()});
|
|
204
|
+
server.oninitialized=()=>{const declared=declaredHostContentCapabilities(server.getClientCapabilities());
|
|
205
|
+
contentTypes=declared.types;contentSource=declared.source;};
|
|
206
|
+
const knowledgeHandler=(schema,method)=>server.setRequestHandler(schema,async request=>{
|
|
207
|
+
try{return await host[method](request.params??{});}catch(error){
|
|
208
|
+
const remote=error?.data?.errorCode;
|
|
209
|
+
const code=error instanceof CreationClientError?error.message
|
|
210
|
+
:typeof remote==='string'&&/^(?:creation|creative_skill)\.[a-z0-9_.:-]{1,160}$/.test(remote)
|
|
211
|
+
?remote:'creation.connection_unresolved';
|
|
212
|
+
const knownRemote=typeof remote==='string'&&code===remote
|
|
213
|
+
&&typeof error.code==='number'&&Object.values(ErrorCode).includes(error.code);
|
|
214
|
+
throw new McpError(knownRemote?error.code:error instanceof CreationClientError
|
|
215
|
+
?ErrorCode.InvalidParams:ErrorCode.InternalError,code,{errorCode:code});
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
if(upstream.resources){
|
|
219
|
+
knowledgeHandler(ListResourcesRequestSchema,'listResources');
|
|
220
|
+
knowledgeHandler(ListResourceTemplatesRequestSchema,'listResourceTemplates');
|
|
221
|
+
knowledgeHandler(ReadResourceRequestSchema,'readResource');
|
|
222
|
+
}
|
|
223
|
+
if(upstream.prompts){
|
|
224
|
+
knowledgeHandler(ListPromptsRequestSchema,'listPrompts');
|
|
225
|
+
knowledgeHandler(GetPromptRequestSchema,'getPrompt');
|
|
226
|
+
}
|
|
166
227
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
167
228
|
try {
|
|
168
229
|
return await host.listTools();
|
|
@@ -183,9 +244,11 @@ async function bridge() {
|
|
|
183
244
|
success: false,
|
|
184
245
|
errorCode: error instanceof CreationClientError
|
|
185
246
|
? error.message : "creation.connection_unresolved",
|
|
247
|
+
...(error instanceof CreationClientError&&error.message==='creation.host_session_changed'
|
|
248
|
+
?{effectStatus:'unknown',automaticReplayAllowed:false}:{}),
|
|
186
249
|
action: error instanceof CreationClientError
|
|
187
|
-
? error.message.startsWith("creation.host_")
|
|
188
|
-
? "
|
|
250
|
+
? error.message==='creation.host_session_changed'?'read_original_task_without_replaying_business':error.message.startsWith("creation.host_")
|
|
251
|
+
? "use_supported_host_with_session_identity"
|
|
189
252
|
: error.message === "creation.editor_not_current"
|
|
190
253
|
? "request_control_and_confirm_in_studio"
|
|
191
254
|
: "read_current_platform_facts_without_replaying_business"
|
|
@@ -221,18 +284,24 @@ try {
|
|
|
221
284
|
const signal=new AbortController();
|
|
222
285
|
const abort=()=>signal.abort();process.once('SIGINT',abort);process.once('SIGTERM',abort);
|
|
223
286
|
try{
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
287
|
+
const host=resolveHostIdentity({host:value('--host')}),installer=host.kind==='claude-code'?installForClaudeUser:installForUser;
|
|
288
|
+
const installed=await installer({sourceRoot:fileURLToPath(new URL('..',import.meta.url)),
|
|
289
|
+
executable:value('--claude-bin'),profile:value('--profile')??'default',configFile:configFile(),signal:signal.signal});
|
|
290
|
+
const skillNames=installed.skills?.map(skill=>skill.name)??['creation-setup','video-creation'];
|
|
291
|
+
log({...connection,pluginRegistered:(installed.pluginInstalled??true)&&installed.registered,
|
|
292
|
+
mcpRegistered:installed.registered,version:installed.version,
|
|
293
|
+
host:host.kind,pluginInstalled:installed.pluginInstalled??true,pluginEnabled:installed.pluginEnabled??true,
|
|
294
|
+
...(installed.installationMode?{installationMode:installed.installationMode,skillsInstalled:installed.skillsInstalled,skills:skillNames}:{}),
|
|
295
|
+
hostMcpConnected:'not_verified',sessionLoaded:'not_verified',
|
|
228
296
|
installationReused:installed.reused,profile:installed.profile,
|
|
229
297
|
requestedVersion:installed.requestedVersion,versionStatus:installed.versionStatus,
|
|
230
298
|
recordedRuntimeRetained:installed.recordedRuntimeRetained??false,
|
|
231
|
-
next:'On this host, open a new Local chat (CLI: start a new session). Check
|
|
299
|
+
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
300
|
hostThreadIdentity:'verified_by_the_platform_on_actual_host_tool_calls'});
|
|
233
301
|
}finally{process.removeListener('SIGINT',abort);process.removeListener('SIGTERM',abort);}
|
|
234
302
|
}
|
|
235
303
|
else if (command === "bridge") await bridge();
|
|
304
|
+
else if(command==='claude-host-hook')await runClaudeHostHook({configFile:configFile()});
|
|
236
305
|
else if(command==='--version')process.stdout.write(CLIENT_VERSION+'\n');
|
|
237
306
|
else if (command === "status") {
|
|
238
307
|
const saved = await readCredentials(configFile());
|
|
@@ -244,7 +313,7 @@ try {
|
|
|
244
313
|
});
|
|
245
314
|
} else if (command === "help" || command === "--help" || !command) {
|
|
246
315
|
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
|
|
316
|
+
"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.1.295 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
317
|
);
|
|
249
318
|
} else throw new CreationClientError("command.unknown");
|
|
250
319
|
} catch (error) {
|
|
@@ -252,6 +321,11 @@ try {
|
|
|
252
321
|
process.stderr.write(
|
|
253
322
|
JSON.stringify({
|
|
254
323
|
...installationErrorDetails(error),
|
|
324
|
+
...claudeInstallationDetails(error),
|
|
325
|
+
...claudeErrorDetails(error),
|
|
326
|
+
...fallbackErrorDetails(error),
|
|
327
|
+
...bridgeErrorDetails(error),
|
|
328
|
+
...runtimeErrorDetails(error),
|
|
255
329
|
error:
|
|
256
330
|
error instanceof CreationClientError
|
|
257
331
|
? 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(() => {});
|