@promptframe/creation 0.3.0 → 0.3.2
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 +52 -2
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +3 -3
- package/dist/cli.mjs +1060 -646
- package/docs/development.md +7 -3
- package/docs/install-guidance.json +3 -3
- package/docs/installing.md +4 -4
- package/docs/releases/0.3.1.md +7 -0
- package/docs/releases/0.3.2.md +5 -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 +8 -3
- package/lib/claude-mcp-installation.mjs +3 -0
- package/lib/cli.mjs +8 -3
- package/lib/host-context.mjs +50 -17
- package/lib/host-identity.mjs +5 -6
- package/lib/runtime-launch.mjs +1 -1
- package/lib/version.mjs +1 -1
- package/package.json +1 -1
- package/skills/creation-setup/SKILL.md +2 -2
package/lib/host-context.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import {createHash} from 'node:crypto';
|
|
|
2
2
|
import {CreationClientError} from './credentials.mjs';
|
|
3
3
|
import {hostParameters,resolveHostIdentity} from './host-identity.mjs';
|
|
4
4
|
import {assertMcpResponseBudget} from './content-budget.mjs';
|
|
5
|
+
import {CLAUDE_HOST_PROOF} from './claude-host-session.mjs';
|
|
5
6
|
export {hostParameters} from './host-identity.mjs';
|
|
6
7
|
|
|
7
8
|
const digestPattern=/^sha256:[a-f0-9]{64}$/;
|
|
@@ -19,12 +20,12 @@ const boundedSet=(map,key,value)=>{if(!map.has(key)&&map.size>=1024)map.delete(m
|
|
|
19
20
|
|
|
20
21
|
/** The authenticated platform owns classification and editor authority.
|
|
21
22
|
* Business text and model annotations never populate this cache. */
|
|
22
|
-
export function createHostCallBridge(client,{credentials,host=resolveHostIdentity(),onCatalogChange=()=>{},onKnowledgeChange=()=>{}}={}){
|
|
23
|
+
export function createHostCallBridge(client,{credentials,host=resolveHostIdentity(),hostSession,onCatalogChange=()=>{},onKnowledgeChange=()=>{}}={}){
|
|
23
24
|
if(!credentials?.endpoint||!credentials.clientId)throw new CreationClientError('creation.bridge_identity_required');
|
|
24
25
|
const installationDigest=digest(credentials.clientId);
|
|
25
26
|
const versions=new Map(),controllers=new Map(),catalogs=new Map(),inflight=new Map();
|
|
26
27
|
const knowledgeVersions=new Map(),upstream=client.getServerCapabilities?.()??{};
|
|
27
|
-
let platformDigest,accountDigest,directory,directoryRead,sequence=0;
|
|
28
|
+
let platformDigest,accountDigest,directory,directoryRead,sequence=0,hostEpoch;
|
|
28
29
|
function catalog(channel,version,order){
|
|
29
30
|
if(typeof version!=='string'||!digestPattern.test(version))return;
|
|
30
31
|
const old=catalogs.get(channel);if(old&&old.order>order)return;
|
|
@@ -69,8 +70,10 @@ export function createHostCallBridge(client,{credentials,host=resolveHostIdentit
|
|
|
69
70
|
}
|
|
70
71
|
return v;
|
|
71
72
|
}
|
|
72
|
-
async function send(params){
|
|
73
|
+
async function send(params,binding){
|
|
74
|
+
await binding?.assertCurrent();
|
|
73
75
|
const order=++sequence,result=assertMcpResponseBudget(await client.callTool(params,undefined,{timeout:60000}));
|
|
76
|
+
await binding?.assertCurrent();
|
|
74
77
|
return {result,trusted:remember(params,result,order)};
|
|
75
78
|
}
|
|
76
79
|
async function listTools(){
|
|
@@ -79,9 +82,11 @@ export function createHostCallBridge(client,{credentials,host=resolveHostIdentit
|
|
|
79
82
|
if(!directory||order>=directory.order)directory={tools:new Map(result.tools.map(t=>[t.name,t])),order};
|
|
80
83
|
catalog('outer',result._meta?.['promptframe.catalogVersion'],order);
|
|
81
84
|
return {...result,tools:result.tools.map(tool=>{
|
|
82
|
-
const p=tool.inputSchema.properties;
|
|
83
|
-
const {controlVersion:_managed,...properties}=p;
|
|
84
|
-
return {...tool,inputSchema:{...tool.inputSchema,properties,...(
|
|
85
|
+
const p=tool.inputSchema.properties;
|
|
86
|
+
const {controlVersion:_managed,...properties}=p??{};
|
|
87
|
+
return {...tool,inputSchema:{...tool.inputSchema,properties:{...properties,...(host.kind==='claude-code'?{
|
|
88
|
+
[CLAUDE_HOST_PROOF]:{type:'string',pattern:'^[a-f0-9]{64}$',description:'由当前宿主hook填入的单次身份凭证;请保留,不自行填写。'}
|
|
89
|
+
}:{})},...(tool.inputSchema.required
|
|
85
90
|
?{required:tool.inputSchema.required.filter(name=>name!=='controlVersion')}:{})}};
|
|
86
91
|
})};
|
|
87
92
|
}
|
|
@@ -92,15 +97,19 @@ export function createHostCallBridge(client,{credentials,host=resolveHostIdentit
|
|
|
92
97
|
const found=[...directory.tools.values()].filter(t=>t._meta?.['promptframe.role']===name);
|
|
93
98
|
if(found.length!==1)throw new CreationClientError('creation.upgrade_required');return found[0].name;
|
|
94
99
|
}
|
|
95
|
-
async function controlRead(params,key){
|
|
96
|
-
if(!inflight.has(key))
|
|
97
|
-
|
|
100
|
+
async function controlRead(params,key,binding){
|
|
101
|
+
if(!inflight.has(key)){
|
|
102
|
+
const pending=send({name:role('control-read'),_meta:params._meta,
|
|
103
|
+
arguments:{projectId:params.arguments.projectId,sessionId:params.arguments.sessionId,pageSize:1}},binding)
|
|
104
|
+
.finally(()=>{if(inflight.get(key)===pending)inflight.delete(key);});
|
|
105
|
+
inflight.set(key,pending);
|
|
106
|
+
}
|
|
98
107
|
const observation=await inflight.get(key);if(observation.result.isError)return observation.result;
|
|
99
108
|
if(!observation.trusted||!versions.has(key)||versions.get(key).needsRead)throw new CreationClientError('creation.control_unverified');
|
|
100
109
|
}
|
|
101
110
|
async function knowledgeRead(kind,method,raw={}){
|
|
102
111
|
if(!upstream[kind])throw new CreationClientError('creation.knowledge_unsupported');
|
|
103
|
-
const params=hostParameters(raw,host,'independent-read'),order=++sequence;
|
|
112
|
+
const params=hostParameters(raw,host.kind==='claude-code'?{kind:host.kind}:host,'independent-read'),order=++sequence;
|
|
104
113
|
const result=assertMcpResponseBudget(await client[method](params,undefined,{timeout:60000}));
|
|
105
114
|
const version=result._meta?.[kind==='resources'&&method==='listResources'
|
|
106
115
|
?'promptframe.guideDirectoryVersion':'promptframe.guideVersion'];
|
|
@@ -123,34 +132,58 @@ export function createHostCallBridge(client,{credentials,host=resolveHostIdentit
|
|
|
123
132
|
getPrompt:params=>knowledgeRead('prompts','getPrompt',params),async call(raw){
|
|
124
133
|
for(const field of ['threadId','controller','clientDigest','token','controlVersion'])if(Object.hasOwn(raw.arguments??{},field))
|
|
125
134
|
throw new CreationClientError('creation.transport_authority_managed_by_bridge');
|
|
126
|
-
|
|
135
|
+
let binding={host,arguments:raw.arguments,assertCurrent:async()=>{}};
|
|
136
|
+
if(host.kind==='claude-code'){
|
|
137
|
+
if(hostSession)binding=await hostSession.begin(raw);
|
|
138
|
+
else if(raw.arguments?.[CLAUDE_HOST_PROOF]!==undefined)throw new CreationClientError('creation.host_identity_invalid');
|
|
139
|
+
else binding={host:{kind:'claude-code'},arguments:raw.arguments,assertCurrent:async()=>{}};
|
|
140
|
+
if(binding.epoch!==hostEpoch){versions.clear();controllers.clear();inflight.clear();hostEpoch=binding.epoch;}
|
|
141
|
+
}else if(Object.hasOwn(raw.arguments??{},CLAUDE_HOST_PROOF))throw new CreationClientError('creation.transport_authority_managed_by_bridge');
|
|
142
|
+
raw={...raw,arguments:binding.arguments};
|
|
143
|
+
await ensureDirectory();await binding.assertCurrent();const definition=directory.tools.get(raw.name);
|
|
127
144
|
if(!definition)throw new CreationClientError('creation.tool_unavailable');
|
|
128
145
|
const access=definition._meta['promptframe.access'],managed=Object.hasOwn(definition.inputSchema.properties??{},'controlVersion');
|
|
129
|
-
|
|
146
|
+
// Resolve parameter-dependent access before requiring a controller. A
|
|
147
|
+
// missing host UUID must not block an independently authorized read.
|
|
148
|
+
let params=hostParameters(raw,binding.host,'independent-read');let effectiveAccess=access,resolvedControl;
|
|
130
149
|
if(definition._meta['promptframe.resolveAccess']==='target'){
|
|
131
150
|
const {projectId,sessionId,tool,arguments:input}=params.arguments??{};
|
|
132
151
|
if(typeof tool!=='string'||!input||typeof input!=='object'||Array.isArray(input))throw new CreationClientError('creation.request_invalid');
|
|
133
|
-
const observed=await send({name:role('describe-target'),_meta:params._meta,arguments:{projectId,sessionId,tool,arguments:input}});
|
|
152
|
+
const observed=await send({name:role('describe-target'),_meta:params._meta,arguments:{projectId,sessionId,tool,arguments:input}},binding);
|
|
134
153
|
if(observed.result.isError)return observed.result;
|
|
135
154
|
const resolved=observed.trusted?.resolvedAccess;
|
|
136
|
-
|
|
155
|
+
const defaults=resolved?.scopeDefaults??{};
|
|
156
|
+
if(!defaults||typeof defaults!=='object'||Array.isArray(defaults)||Object.entries(defaults).some(([key,value])=>
|
|
157
|
+
!['projectId','sessionId'].includes(key)||value!==params.arguments[key]||Object.hasOwn(input,key)))
|
|
158
|
+
throw new CreationClientError('creation.access_unverified');
|
|
159
|
+
const normalized={...input,...defaults};
|
|
160
|
+
if(resolved?.tool!==tool||resolved.argumentsDigest!==argumentsDigest(normalized)||!accesses.has(resolved.access))throw new CreationClientError('creation.access_unverified');
|
|
161
|
+
params={...params,arguments:{...params.arguments,arguments:normalized}};
|
|
137
162
|
effectiveAccess=resolved.access;
|
|
163
|
+
resolvedControl=observed.trusted?.control;
|
|
138
164
|
}
|
|
165
|
+
hostParameters(raw,binding.host,effectiveAccess);
|
|
139
166
|
const key=keyFor(params);let outgoing=params;
|
|
140
167
|
if(managed){
|
|
141
|
-
if(!key)
|
|
142
|
-
|
|
168
|
+
if(!key){
|
|
169
|
+
if(effectiveAccess!=='independent-read'||!Number.isSafeInteger(resolvedControl?.controlVersion)||resolvedControl.controlVersion<=0)
|
|
170
|
+
throw new CreationClientError('creation.control_unverified');
|
|
171
|
+
outgoing={...params,arguments:{...params.arguments,controlVersion:resolvedControl.controlVersion}};
|
|
172
|
+
}else{let entry=versions.get(key);
|
|
173
|
+
if(!entry||entry.needsRead){const denied=await controlRead(params,key,binding);if(denied)return denied;entry=versions.get(key);}
|
|
143
174
|
if(effectiveAccess!=='independent-read'&&!entry.owned)throw new CreationClientError('creation.editor_not_current');
|
|
144
175
|
outgoing={...params,arguments:{...params.arguments,controlVersion:entry.version}};
|
|
176
|
+
}
|
|
145
177
|
}
|
|
146
178
|
const dispatched=key&&versions.get(key);
|
|
147
179
|
const invalidate=()=>{
|
|
180
|
+
if(host.kind==='claude-code'&&binding.epoch!==hostEpoch)return;
|
|
148
181
|
const current=key&&versions.get(key);
|
|
149
182
|
if(dispatched&¤t&¤t.version<=dispatched.version)
|
|
150
183
|
boundedSet(versions,key,{...current,needsRead:true,invalidatedAt:++sequence});
|
|
151
184
|
};
|
|
152
185
|
let response;
|
|
153
|
-
try{response=await send(outgoing);}catch(error){invalidate();throw error;}
|
|
186
|
+
try{response=await send(outgoing,binding);}catch(error){invalidate();throw error;}
|
|
154
187
|
if(response.result.isError)invalidate();
|
|
155
188
|
return response.result;
|
|
156
189
|
}};
|
package/lib/host-identity.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {randomUUID} from 'node:crypto';
|
|
2
1
|
import {CreationClientError} from './credentials.mjs';
|
|
3
2
|
|
|
4
3
|
export function hostClientName(savedName,host){
|
|
@@ -8,14 +7,13 @@ export function hostClientName(savedName,host){
|
|
|
8
7
|
|
|
9
8
|
export const threadFormat=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10
9
|
|
|
11
|
-
//
|
|
12
|
-
|
|
10
|
+
// Select the transport kind, not a controller. Claude's startup environment
|
|
11
|
+
// can remain stale after /clear; only a current host-hook call binds its UUID.
|
|
12
|
+
export function resolveHostIdentity({host,env=process.env}={}){
|
|
13
13
|
const kind=host??(env.CLAUDECODE==='1'?'claude-code':'codex');
|
|
14
14
|
if(!['codex','claude-code'].includes(kind))throw new CreationClientError('creation.host_unsupported');
|
|
15
15
|
if(kind==='codex')return Object.freeze({kind});
|
|
16
|
-
|
|
17
|
-
if(typeof threadId!=='string'||!threadFormat.test(threadId))throw new CreationClientError('creation.host_identity_invalid');
|
|
18
|
-
return Object.freeze({kind,threadId:threadId.toLowerCase()});
|
|
16
|
+
return Object.freeze({kind});
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
export function hostParameters(params,host,access){
|
|
@@ -24,6 +22,7 @@ export function hostParameters(params,host,access){
|
|
|
24
22
|
throw new CreationClientError('creation.transport_authority_managed_by_bridge');
|
|
25
23
|
if(host.kind==='claude-code'){
|
|
26
24
|
if(Object.hasOwn(meta,'threadId'))throw new CreationClientError('creation.transport_authority_managed_by_bridge');
|
|
25
|
+
if(!host.threadId){if(access==='independent-read')return params;throw new CreationClientError('creation.host_identity_unavailable');}
|
|
27
26
|
return {...params,_meta:{...meta,threadId:host.threadId}};
|
|
28
27
|
}
|
|
29
28
|
if(meta.threadId===undefined){
|
package/lib/runtime-launch.mjs
CHANGED
|
@@ -12,7 +12,7 @@ export async function launchSelectedBridge(selection,{host,configFile,spawnImpl=
|
|
|
12
12
|
try{child=spawnImpl(process.execPath,[path.join(selection.root,'bin/promptframe-creation.mjs'),'bridge',
|
|
13
13
|
'--config',configFile,'--host',host.kind,selection.locked?'--bridge-version':'--resolved-runtime-version',selection.version],
|
|
14
14
|
{stdio:'inherit',windowsHide:true,env:{...env,PROMPTFRAME_CREATION_CONFIG:configFile,
|
|
15
|
-
...(host.kind==='claude-code'?{CLAUDECODE:'1'
|
|
15
|
+
...(host.kind==='claude-code'?{CLAUDECODE:'1'}:{})}});}
|
|
16
16
|
catch{throw new CreationClientError('creation.runtime_start_unconfirmed');}
|
|
17
17
|
let signaled=false;
|
|
18
18
|
const forward=signal=>{if(!signaled){signaled=true;child.kill(signal);}};
|
package/lib/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const CLIENT_VERSION = "0.3.
|
|
1
|
+
export const CLIENT_VERSION = "0.3.2";
|
|
2
2
|
export const CLIENT_PROTOCOL = "creation-client/v1";
|
package/package.json
CHANGED
|
@@ -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.2 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.2 connect --host claude-code --endpoint <Studio提供的API地址>`。桌面版远程连接 WSL 时,在该 WSL 执行;保留相同 profile 和有效凭据。
|
|
18
18
|
<!-- /creation-install-command -->
|
|
19
19
|
|
|
20
20
|
命令会复用并验证有效凭据。首次授权或明确更换已失效凭据时,由用户在 Studio 登录并在终端的不回显输入框提供 Token;不要要求用户把 Token 粘进聊天,也不要把它写进命令参数、URL或日志。网络失败不等于授权失效,不自动轮换或覆盖凭据。
|