@promptframe/creation 0.3.9 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,7 @@
13
13
  | 依赖闭包/许可证 | `scripts/build-runtime.mjs` |
14
14
  | 环境地址与安全凭据 | `lib/credentials.mjs` |
15
15
  | 平台 MCP HTTP 连接 | `lib/connection.mjs` |
16
+ | 共享本机账号目录与当前宿主会话的连接选择 | `lib/local-accounts.mjs`、`lib/account-bridge.mjs`,格式见[本机账号目录](local-account-directory.md) |
16
17
  | 当前源码的宿主 thread 与控制版本接线 | `lib/host-context.mjs` |
17
18
  | 新会话固定版本选择、完整性缓存与 stdio 接续 | `lib/runtime-bootstrap.mjs`、`lib/runtime-package.mjs`、`lib/runtime-launch.mjs` |
18
19
  | 插件加载与启动 | `.codex-plugin/plugin.json`、`.mcp.json` |
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": "creation-install-guidance/v1",
3
3
  "package": "@promptframe/creation",
4
- "version": "0.3.9",
4
+ "version": "0.3.11",
5
5
  "hosts": [
6
6
  {
7
7
  "kind": "codex",
@@ -6,7 +6,7 @@
6
6
 
7
7
  <!-- creation-install-command -->
8
8
  ```bash
9
- npx --yes @promptframe/creation@0.3.9 connect --endpoint <Studio提供的API地址>
9
+ npx --yes @promptframe/creation@0.3.11 connect --endpoint <Studio提供的API地址>
10
10
  ```
11
11
  <!-- /creation-install-command -->
12
12
 
@@ -26,7 +26,7 @@ npx --yes @promptframe/creation@0.3.9 connect --endpoint <Studio提供的API地
26
26
 
27
27
  <!-- creation-install-command -->
28
28
  ```bash
29
- npx --yes @promptframe/creation@0.3.9 connect --host claude-code --endpoint <Studio提供的API地址>
29
+ npx --yes @promptframe/creation@0.3.11 connect --host claude-code --endpoint <Studio提供的API地址>
30
30
  ```
31
31
  <!-- /creation-install-command -->
32
32
 
@@ -46,7 +46,7 @@ CLI 优先使用 PATH 中的 Claude;桌面版远程连接 WSL 时,也识别
46
46
 
47
47
  <!-- creation-install-command -->
48
48
  ```bash
49
- npx --yes @promptframe/creation@0.3.9 connect --profile work-account --endpoint <另一环境API地址>
49
+ npx --yes @promptframe/creation@0.3.11 connect --profile work-account --endpoint <另一环境API地址>
50
50
  ```
51
51
  <!-- /creation-install-command -->
52
52
 
@@ -0,0 +1,51 @@
1
+ # 本机账号目录格式
2
+
3
+ 当前主分支新增的目录能力与已发行版本分别核实。目录记录可发现的本机授权引用,不保存 Token 或 Cookie,也不授予平台权限。创作 MCP 与组件 CLI 继续使用各自的安全配置和实际服务校验。
4
+
5
+ `promptframe-creation accounts list` 读取已登记摘要;`accounts refresh --profile <名称>` 沿原 profile 作一次正常认证观察并更新其引用,不签发或轮换 Token。正常 setup/connect 和桥启动也登记已验证身份。旧的自定义配置只有显式使用后才能发现,不递归扫描用户磁盘。
6
+
7
+ 新桥提供 `promptframe_local_accounts` 与 `promptframe_local_select_account`。前者列出本机摘要,后者使用列表中的 `identityKey`,同账号有多份授权时可附 `referenceId`。选择前验证原配置和认证连接的身份,成功后仅更新当前宿主会话。选择不申请作品编辑权,不重新提交已受理请求,不终止旧账号正在返回的请求。
8
+
9
+ 多份授权的 `referenceId` 选择保留在当前桥中;宿主会话的持久选择只记录账号。重启桥后,若该账号仍有多份候选且没有匹配的原 profile,需要再次明确引用,不能猜哪份权限较大。
10
+
11
+ ## 身份与授权引用
12
+
13
+ 身份使用平台经认证连接返回的 `promptframe-account-identity/v1`:
14
+
15
+ ```json
16
+ {
17
+ "contractVersion": "promptframe-account-identity/v1",
18
+ "platformDigest": "sha256:<64个小写十六进制字符>",
19
+ "accountDigest": "sha256:<64个小写十六进制字符>"
20
+ }
21
+ ```
22
+
23
+ 平台和账号摘要沿实际认证合同;显示名、邮箱、项目名和业务正文不能建立身份。Creation 从 MCP initialize 的 `experimental.promptframe.accountIdentity` 取得摘要。旧平台没有该扩展时,原 profile 流程保持兼容;显式按目录选择账号需要可核身份。
24
+
25
+ 目录默认位于 `XDG_CONFIG_HOME/promptframe/accounts/v1`;未指定 XDG 时使用用户配置目录。测试可用 `PROMPTFRAME_ACCOUNT_DIRECTORY` 指定隔离根,不能以此覆盖个人 Token。目录须支持当前用户属主、0700 目录、0600 普通文件、无符号链接检查;无法可靠检查时明确拒绝目录操作,已有 profile 不依赖目录存在。
26
+
27
+ 每份引用使用独立文件,避免两个客户端覆盖同一个总 JSON:
28
+
29
+ ```text
30
+ identities/<platformHex>/<accountHex>/<client>/<referenceHex>.json
31
+ ```
32
+
33
+ `client` 为 `creation` 或 `component-cli`。`referenceId` 是 `sha256(JSON.stringify([client, path.resolve(configFile)]))`。同一身份合为一行,多份 profile 是这一行下的不同授权引用;重复登记同一引用只更新同一文件。
34
+
35
+ 引用包含 `contractVersion: promptframe-local-account-directory/v1`、`identity`、`client`、`referenceId`、本机绝对路径 `configFile`、`endpoint`、`credentialDigest`、`observedAt`,以及可选的 `profile`、`expiresAt`、`scopes`。`credentialDigest` 是原 Token 字符串的 SHA-256,用于识别引用变化,不是认证证明。绝对路径和摘要只留在私有目录,不出现在账号列表中。
36
+
37
+ 列表只返回身份键、账号摘要、授权种类、引用 ID、profile、观察时间和存储或到期状态。`stored` 表示本机有一次授权记录,不表示平台当前仍批准它;操作前仍读取原安全配置并核对实际账号、scope、撤销和期限。没有组件 CLI 授权,或只有过期的 CLI 引用时,明确报告缺失,不能借另一个账号的授权。
38
+
39
+ 单个元数据文件限制为 16 KiB,目录读取每级最多 256 项,超过时明确报告不完整的读取条件,不把截断内容当作全部账号。按准确身份读取引用不依赖全目录扫描。这些限制仅约束本机索引元数据,不限制作品或上传文件大小。
40
+
41
+ ## 当前 Agent 的选择
42
+
43
+ 选择文件位于 `selections/<kind>-<agentHex>.json`。`kind` 为 `codex` 或 `claude-code`,`agentDigest` 为 `sha256(JSON.stringify([kind, sessionId.toLowerCase()]))`。调用方必须沿原宿主 transport/hook 取得当前会话身份,不能采用模型业务参数中的任意会话号。
44
+
45
+ 文件包含 `contractVersion: promptframe-local-agent-account/v1`、`agentKind`、`agentDigest`、随机 UUID `generation`、`identity` 和 `selectedAt`。不存在全局 selected/default 账号文件。切换只写当前 Agent 对应的一格,不覆盖其它 profile、修改其它 Agent 的桥或改变已受理任务的归属。缺少合法宿主身份时不能写持久选择。
46
+
47
+ 实际连接须与所选身份一致;本机索引不能让旧授权获得新权限。在途请求仍保留其发起时的账号和回执,晚回结果不能填进另一个账号的控制或作品缓存。
48
+
49
+ Codex 使用请求的原宿主上下文;Claude 使用已验证的当前 hook 凭证,选择连接与转发业务只消费一次同一凭证。切换后的调用需要可核宿主身份,缺失时明确拒绝,不猜另一个会话。新账号的上传检查点按账号与宿主分开,原 profile 的已有检查点保持原位,旧请求不改归属。
50
+
51
+ 目录不存在时仍可使用原 profile。已选账号的目录损坏或读取失败返回 `accounts.storage_unavailable` 或相应安全错误,不静默换回另一个账号。缺少创作引用、授权到期、引用文件变化与认证身份不符分别报告,不重新登录或自动扩大权限。原生 Windows 的文件 ACL 与实际桌面会话加载仍需单独验证。
@@ -0,0 +1,7 @@
1
+ # 0.3.10
2
+
3
+ 本机文件上传失败时,返回 `lastTransferDiagnostic`,包含原上传、分片和请求的关联、失败阶段、单调耗时、本地读取字节、预期字节和实际取得的 HTTP 状态。
4
+
5
+ 原因采用固定分类,区分本地读取失败、DNS/连接中断、TLS 拒绝、HTTP 拒绝、字节数不符、缺失 ETag、取消和超时。不输出签名 URL、请求头、异常原文或堆栈。本地读完不代表对象端已完整接收。
6
+
7
+ 不确定的分片效果继续保留在原上传身份下。状态读取不自动重发 PUT,也不自动重新完成上传;恢复仍观察原请求和分片回执。
@@ -0,0 +1,9 @@
1
+ # 0.3.11:本机账号目录与当前 Agent 选择
2
+
3
+ 本机目录按平台和经认证的不可变账号身份分组,分别引用 Creation 与组件 CLI 已有授权,不复制 Token 或 Cookie。`accounts list` 显示安全摘要;`accounts refresh --profile <名称>` 验证并登记原 profile,不签发或轮换授权。
4
+
5
+ MCP 新增 `promptframe_local_accounts` 和 `promptframe_local_select_account`。选择前读取原安全配置并核对认证连接,选择只属于当前宿主会话,不改变其它 Agent、作品编辑权或已受理任务。切换前的在途调用保留原身份和回执,新账号的上传检查点按账号和宿主分开。
6
+
7
+ 显式账号选择需要平台在 MCP initialize 返回 `experimental.promptframe.accountIdentity`。缺少该扩展的旧平台仍支持原 profile;缺少可核宿主身份、授权缺失或到期、凭据变化、目录不可读时明确说明原因,不借用其它账号权限。目录中的特殊文件会立即拒绝,不等待其写端。
8
+
9
+ 完整格式、授权状态和多 profile 的选择见[本机账号目录](../local-account-directory.md)。实际宿主加载、原生 Windows ACL 以及组件 CLI 的对应功能按各自版本和实际验证记录核实。此版本不替换正在运行的桥,也不自动轮换凭据。
@@ -0,0 +1,132 @@
1
+ import path from 'node:path';
2
+ import { CreationClientError, readCredentials, normalizeEndpoint } from './credentials.mjs';
3
+ import { connectPlatform, connectionAccountIdentity } from './connection.mjs';
4
+ import { createHostCallBridge, resolveHostCallBinding, hostParameters } from './host-context.mjs';
5
+ import { CLAUDE_HOST_PROOF } from './claude-host-session.mjs';
6
+ import { localAccountsRoot, localAccountKey, localAgentDigest, localCredentialDigest, localReferenceId,
7
+ listLocalAccounts, readLocalAuthorizations, readSelectedLocalAccount, selectLocalAccount } from './local-accounts.mjs';
8
+
9
+ const listName = 'promptframe_local_accounts';
10
+ const selectName = 'promptframe_local_select_account';
11
+ const error = code => new CreationClientError('accounts.' + code);
12
+ const sameIdentity = (a,b) => a && b && localAccountKey(a) === localAccountKey(b);
13
+
14
+ function identityFromKey(key) {
15
+ if (typeof key !== 'string' || !/^[a-f0-9]{64}-[a-f0-9]{64}$/.test(key)) throw error('identity_invalid');
16
+ return { contractVersion: 'promptframe-account-identity/v1', platformDigest: 'sha256:' + key.slice(0,64),
17
+ accountDigest: 'sha256:' + key.slice(65) };
18
+ }
19
+
20
+ function localTool(name,host) {
21
+ const properties = name === selectName ? {
22
+ identityKey: {type:'string',pattern:'^[a-f0-9]{64}-[a-f0-9]{64}$'},
23
+ referenceId: {type:'string',pattern:'^sha256:[a-f0-9]{64}$',description:'同一账号有多份创作授权时可明确选择列表中的引用。'},
24
+ } : {};
25
+ if(host.kind==='claude-code')properties[CLAUDE_HOST_PROOF]={type:'string',pattern:'^[a-f0-9]{64}$',description:'由当前宿主hook填入,保留原值。'};
26
+ return {name,description:name===listName?'列出本机已登记账号的安全摘要和缺少的授权类型,不返回凭据或本机路径。'
27
+ :'只为当前宿主会话选择本机已授权账号;不切换其它Agent,不申请编辑权或重放业务。',
28
+ inputSchema:{type:'object',properties,additionalProperties:false,...(name===selectName?{required:['identityKey']}:{})},
29
+ annotations:{readOnlyHint:name===listName,destructiveHint:false,openWorldHint:false}};
30
+ }
31
+
32
+ /** Keep connections and their control/upload caches separate. Changing one
33
+ * host selection never mutates credentials or closes an in-flight old caller. */
34
+ export function createAccountAwareBridge(defaultClient,{credentials,configFile,host,hostSession,
35
+ root=localAccountsRoot(),connect=connectPlatform,connectionOptions={},localUploads,createLocalUploads,
36
+ onCatalogChange=()=>{},onKnowledgeChange=()=>{}}={}){
37
+ const primaryIdentity=connectionAccountIdentity(defaultClient),contexts=new Map(),preferences=new Map();
38
+ let switched=false;
39
+ const makeBridge=(client,creds,uploads)=>createHostCallBridge(client,{credentials:creds,host,
40
+ localUploads:uploads,onCatalogChange,onKnowledgeChange});
41
+ const primary={client:defaultClient,bridge:makeBridge(defaultClient,credentials,localUploads),identity:primaryIdentity,owned:false};
42
+
43
+ function caller(raw,binding,required=false){
44
+ const params={...raw,arguments:binding.arguments};
45
+ hostParameters(params,binding.host,required?'authority':'independent-read');
46
+ const sessionId=binding.host.kind==='claude-code'?binding.host.threadId:params._meta?.threadId;
47
+ return sessionId?{kind:binding.host.kind,sessionId}:undefined;
48
+ }
49
+ async function context(identity,agent,referenceId){
50
+ if(sameIdentity(identity,primaryIdentity)&&(!referenceId||referenceId===localReferenceId('creation',path.resolve(configFile))))return primary;
51
+ const refs=await readLocalAuthorizations({root,identity,client:'creation'});
52
+ if(!refs.length)throw error('creation_authorization_missing');
53
+ let ref=referenceId?refs.find(value=>value.referenceId===referenceId):refs.length===1?refs[0]:undefined;
54
+ if(!ref)throw error(referenceId?'reference_unavailable':'authorization_ambiguous');
55
+ if(ref.expiresAt&&Date.parse(ref.expiresAt)<=Date.now())throw error('authorization_expired');
56
+ const key=[localAccountKey(identity),ref.referenceId,localAgentDigest(agent)].join('|');
57
+ if(!contexts.has(key)){
58
+ const pending=(async()=>{
59
+ const saved=await readCredentials(ref.configFile);
60
+ if(!saved||localCredentialDigest(saved.token)!==ref.credentialDigest
61
+ ||normalizeEndpoint(saved.endpoint)!==normalizeEndpoint(ref.endpoint))throw error('reference_changed');
62
+ const client=await connect(saved,{...connectionOptions,host,expectedIdentity:identity});
63
+ try{
64
+ connectionAccountIdentity(client,identity);
65
+ return{client,bridge:makeBridge(client,saved,createLocalUploads?.({identity,agent,configFile:ref.configFile})),identity,owned:true};
66
+ }catch(cause){await client.close().catch(()=>{});throw cause;}
67
+ })();
68
+ contexts.set(key,pending);pending.catch(()=>{if(contexts.get(key)===pending)contexts.delete(key);});
69
+ }
70
+ return contexts.get(key);
71
+ }
72
+ async function selected(raw,binding){
73
+ const agent=caller(raw,binding);
74
+ if(!agent){if(switched)throw new CreationClientError('creation.host_identity_required');return{entry:primary};}
75
+ const choice=await readSelectedLocalAccount({root,agent});
76
+ if(!choice)return{entry:primary,agent};
77
+ const preference=preferences.get(localAgentDigest(agent));
78
+ const referenceId=preference?.generation===choice.generation?preference.referenceId:undefined;
79
+ return{entry:await context(choice.identity,agent,referenceId),agent,choice};
80
+ }
81
+ async function knowledge(method,raw={}){
82
+ const binding=await resolveHostCallBinding(raw,{host,hostSession});await binding.assertCurrent();
83
+ const {entry}=await selected(raw,binding);
84
+ // Knowledge calls do not consume another Claude hook proof. They keep the
85
+ // original verified host metadata and the selected connection's token.
86
+ return entry.bridge[method]({...raw,arguments:binding.arguments});
87
+ }
88
+ return{
89
+ knowledgeCapabilities:primary.bridge.knowledgeCapabilities,
90
+ async listTools(raw={}){
91
+ let entry=primary;
92
+ // ListTools has no required hook proof. A caller that supplies its real
93
+ // Codex context can obtain that account's platform catalog directly.
94
+ if(host.kind==='codex'&&raw._meta?.threadId){
95
+ const binding=await resolveHostCallBinding(raw,{host,hostSession});entry=(await selected(raw,binding)).entry;
96
+ }
97
+ const directory=await entry.bridge.listTools();
98
+ if(directory.tools.some(tool=>[listName,selectName].includes(tool.name)))throw error('tool_name_conflict');
99
+ return{...directory,tools:[...directory.tools,localTool(listName,host),localTool(selectName,host)]};
100
+ },
101
+ listResources:raw=>knowledge('listResources',raw),listResourceTemplates:raw=>knowledge('listResourceTemplates',raw),
102
+ readResource:raw=>knowledge('readResource',raw),listPrompts:raw=>knowledge('listPrompts',raw),getPrompt:raw=>knowledge('getPrompt',raw),
103
+ async call(raw,options={}){
104
+ const binding=await resolveHostCallBinding(raw,{host,hostSession});await binding.assertCurrent();
105
+ if(raw.name===listName||raw.name===selectName){
106
+ const input=binding.arguments??{},allowed=raw.name===selectName?['identityKey','referenceId']:[];
107
+ if(!input||typeof input!=='object'||Array.isArray(input)||Object.keys(input).some(key=>!allowed.includes(key)))throw error('request_invalid');
108
+ let value;
109
+ if(raw.name===listName)value=await listLocalAccounts({root});
110
+ else{
111
+ const agent=caller(raw,binding,true),identity=identityFromKey(input.identityKey);
112
+ if(!agent)throw error('agent_required');
113
+ if(input.referenceId!==undefined&&(typeof input.referenceId!=='string'||!/^sha256:[a-f0-9]{64}$/.test(input.referenceId)))throw error('reference_invalid');
114
+ await context(identity,agent,input.referenceId);await binding.assertCurrent();
115
+ const choice=await selectLocalAccount({root,agent,identity});await binding.assertCurrent();
116
+ preferences.set(localAgentDigest(agent),{generation:choice.generation,referenceId:input.referenceId});switched=true;
117
+ Promise.resolve().then(onCatalogChange).catch(()=>{});
118
+ value={selected:true,identityKey:localAccountKey(identity),identity,generation:choice.generation,otherAgentsChanged:0};
119
+ }
120
+ return{content:[{type:'text',text:JSON.stringify(value)}]};
121
+ }
122
+ const {entry}=await selected(raw,binding);await binding.assertCurrent();
123
+ return entry.bridge.call({...raw,arguments:binding.arguments},{...options,resolvedBinding:binding});
124
+ },
125
+ async close(){
126
+ await primary.bridge.close();
127
+ for(const result of await Promise.allSettled(contexts.values()))if(result.status==='fulfilled'){
128
+ await result.value.bridge.close();await result.value.client.close().catch(()=>{});
129
+ }
130
+ },
131
+ };
132
+ }
package/lib/cli.mjs CHANGED
@@ -22,8 +22,9 @@ import {
22
22
  readCredentials,
23
23
  writeCredentials,
24
24
  } from "./credentials.mjs";
25
- import { connectPlatform } from "./connection.mjs";
26
- import { createHostCallBridge } from "./host-context.mjs";
25
+ import { connectPlatform, connectionAccountIdentity } from "./connection.mjs";
26
+ import { recordLocalAuthorization, listLocalAccounts, localAccountKey, localAgentDigest } from './local-accounts.mjs';
27
+ import { createAccountAwareBridge } from './account-bridge.mjs';
27
28
  import { resolveHostIdentity } from "./host-identity.mjs";
28
29
  import {createClaudeHostSession,runClaudeHostHook} from './claude-host-session.mjs';
29
30
  import {declaredHostContentCapabilities,readPlatformBridgePolicy,bridgeErrorDetails} from './bridge-negotiation.mjs';
@@ -48,11 +49,23 @@ const configFile=()=>value('--config')?path.resolve(value('--config')):
48
49
  async function probe(credentials) {
49
50
  const client = await connectPlatform(credentials,{host:resolveHostIdentity({host:value('--host')})});
50
51
  try {
51
- return (await client.listTools()).tools.length;
52
+ return {tools:(await client.listTools()).tools.length,accountIdentity:connectionAccountIdentity(client)};
52
53
  } finally {
53
54
  await client.close();
54
55
  }
55
56
  }
57
+ async function rememberAuthorization(credentials,file,accountIdentity){
58
+ if(!accountIdentity)return;
59
+ try{
60
+ await recordLocalAuthorization({identity:accountIdentity,client:'creation',configFile:file,
61
+ endpoint:credentials.endpoint,token:credentials.token,profile:value('--profile')??'default'});
62
+ return{status:'recorded'};
63
+ }catch(error){
64
+ // A discovery-index failure does not invalidate a verified profile or
65
+ // rotate its credential. Explicit directory operations still fail clearly.
66
+ return{status:'unavailable',reasonCode:error instanceof CreationClientError?error.message:'accounts.storage_unavailable'};
67
+ }
68
+ }
56
69
  async function tokenInput() {
57
70
  if (args.includes("--token-stdin")) {
58
71
  let text = "";
@@ -117,8 +130,9 @@ async function setup({silent=false}={}) {
117
130
  );
118
131
  if (existing && !args.includes("--replace")) {
119
132
  try {
120
- const tools = await probe(existing);
121
- const result={connected:true,reused:true,endpoint,tools};
133
+ const {tools,accountIdentity} = await probe(existing);
134
+ const accountDirectory=await rememberAuthorization(existing,file,accountIdentity);
135
+ const result={connected:true,reused:true,endpoint,tools,...(accountIdentity?{accountIdentity,accountDirectory}:{})};
122
136
  if(!silent)log(result);
123
137
  return result;
124
138
  } catch {
@@ -164,9 +178,10 @@ async function setup({silent=false}={}) {
164
178
  };
165
179
  // Verify before replacing the secure local file. This never calls a token
166
180
  // rotate API, starts a model, creates work or approves production.
167
- const tools = await probe(credentials);
181
+ const {tools,accountIdentity} = await probe(credentials);
168
182
  await writeCredentials(credentials, file);
169
- const result={connected:true,reused:false,endpoint,tools};
183
+ const accountDirectory=await rememberAuthorization(credentials,file,accountIdentity);
184
+ const result={connected:true,reused:false,endpoint,tools,...(accountIdentity?{accountIdentity,accountDirectory}:{})};
170
185
  if(!silent)log(result);
171
186
  return result;
172
187
  }
@@ -192,15 +207,20 @@ async function bridge() {
192
207
  await client.close();const result=await launchSelectedBridge(selection,{host:identity,configFile:configFile()});
193
208
  process.exitCode=result.code;return;
194
209
  }
210
+ await rememberAuthorization(credentials,configFile(),connectionAccountIdentity(client));
195
211
  const hostSession=identity.kind==='claude-code'?await createClaudeHostSession({configFile:configFile()}):undefined;
196
212
  const server = new Server(
197
213
  { name: "promptframe-creation", version: CLIENT_VERSION },
198
214
  { capabilities: { tools: {listChanged:true},...(upstream.resources?{resources:{listChanged:true}}:{}),
199
215
  ...(upstream.prompts?{prompts:{listChanged:true}}:{}),
200
216
  experimental:{...(policy?{'promptframe.creation':policy}:{}),
201
- 'promptframe.runtime':{version:selection.version,locked:selection.locked,status:selection.status}} } },
217
+ 'promptframe.runtime':{version:selection.version,locked:selection.locked,status:selection.status},
218
+ 'promptframe.localAccounts':{contractVersion:'promptframe-local-account-directory/v1',selectionScope:'host-session'}} } },
202
219
  ),
203
- host=createHostCallBridge(client,{credentials,host:identity,hostSession,
220
+ host=createAccountAwareBridge(client,{credentials,configFile:configFile(),host:identity,hostSession,
221
+ connectionOptions:{contentTypes:()=>contentTypes,contentSource:()=>contentSource},
222
+ createLocalUploads:({identity:account,agent,configFile:file})=>createLocalUploadManager({
223
+ stateRoot:path.join(path.dirname(file),'local-upload-state','accounts',localAccountKey(account),localAgentDigest(agent).slice(7))}),
204
224
  localUploads:createLocalUploadManager({stateRoot:path.join(path.dirname(configFile()),'local-upload-state')}),onCatalogChange:()=>server.sendToolListChanged(),
205
225
  onKnowledgeChange:kind=>kind==='resources'?server.sendResourceListChanged():server.sendPromptListChanged()});
206
226
  server.oninitialized=()=>{const declared=declaredHostContentCapabilities(server.getClientCapabilities(),
@@ -227,9 +247,9 @@ async function bridge() {
227
247
  knowledgeHandler(ListPromptsRequestSchema,'listPrompts');
228
248
  knowledgeHandler(GetPromptRequestSchema,'getPrompt');
229
249
  }
230
- server.setRequestHandler(ListToolsRequestSchema, async () => {
250
+ server.setRequestHandler(ListToolsRequestSchema, async request => {
231
251
  try {
232
- return await host.listTools();
252
+ return await host.listTools(request.params??{});
233
253
  } catch {
234
254
  throw new Error("creation.connection_unresolved");
235
255
  }
@@ -307,17 +327,30 @@ try {
307
327
  else if (command === "bridge") await bridge();
308
328
  else if(command==='claude-host-hook')await runClaudeHostHook({configFile:configFile()});
309
329
  else if(command==='--version')process.stdout.write(CLIENT_VERSION+'\n');
330
+ else if(command==='accounts'){
331
+ if(args[0]==='refresh'){
332
+ const file=configFile(),saved=await readCredentials(file);
333
+ if(!saved)throw new CreationClientError('setup.required');
334
+ const {accountIdentity}=await probe(saved);
335
+ if(!accountIdentity)throw new CreationClientError('accounts.identity_unavailable');
336
+ const accountDirectory=await rememberAuthorization(saved,file,accountIdentity);
337
+ if(accountDirectory.status!=='recorded')throw new CreationClientError(accountDirectory.reasonCode);
338
+ log({accountIdentity,accountDirectory});
339
+ }else if(args[0]===undefined||args[0]==='list')log(await listLocalAccounts());
340
+ else throw new CreationClientError('command.unknown');
341
+ }
310
342
  else if (command === "status") {
311
343
  const saved = await readCredentials(configFile());
312
344
  if (!saved) throw new CreationClientError("setup.required");
345
+ const observation=await probe(saved);
313
346
  log({
314
347
  connected: true,
315
348
  endpoint: saved.endpoint,
316
- tools: await probe(saved),
349
+ ...observation,
317
350
  });
318
351
  } else if (command === "help" || command === "--help" || !command) {
319
352
  process.stdout.write(
320
- "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",
353
+ "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 accounts list\npromptframe-creation accounts refresh [--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",
321
354
  );
322
355
  } else throw new CreationClientError("command.unknown");
323
356
  } catch (error) {
@@ -3,8 +3,27 @@ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/
3
3
  import {CLIENT_VERSION,CLIENT_PROTOCOL} from './version.mjs';
4
4
  import {resolveHostIdentity,hostClientName} from './host-identity.mjs';
5
5
  import {assertBridgeCompatible,declaredHostContentTypes,readPlatformBridgePolicy} from './bridge-negotiation.mjs';
6
+ import {parseAccountIdentity} from './local-accounts.mjs';
7
+ import {CreationClientError} from './credentials.mjs';
6
8
 
7
- export async function connectPlatform(credentials,{host=resolveHostIdentity(),contentTypes=()=>['text'],contentSource=()=> 'text-fallback',enforceMinimum=true,signal}={}) {
9
+ /** Only initialize metadata from this authenticated connection is accepted.
10
+ * Business output and local directory captions cannot establish identity. */
11
+ export function connectionAccountIdentity(client, expected) {
12
+ const raw=client.getServerCapabilities()?.experimental?.['promptframe.accountIdentity'];
13
+ if(raw===undefined){
14
+ if(expected)throw new CreationClientError('accounts.identity_unavailable');
15
+ return undefined;
16
+ }
17
+ const actual=parseAccountIdentity(raw);
18
+ if(expected){
19
+ expected=parseAccountIdentity(expected);
20
+ if(actual.platformDigest!==expected.platformDigest)throw new CreationClientError('accounts.platform_mismatch');
21
+ if(actual.accountDigest!==expected.accountDigest)throw new CreationClientError('accounts.account_mismatch');
22
+ }
23
+ return actual;
24
+ }
25
+
26
+ export async function connectPlatform(credentials,{host=resolveHostIdentity(),contentTypes=()=>['text'],contentSource=()=> 'text-fallback',enforceMinimum=true,signal,expectedIdentity}={}) {
8
27
  const client = new Client(
9
28
  { name: "promptframe-creation-bridge", version: CLIENT_VERSION },
10
29
  { capabilities: {} },
@@ -35,6 +54,7 @@ export async function connectPlatform(credentials,{host=resolveHostIdentity(),co
35
54
  );
36
55
  try {
37
56
  await client.connect(transport,signal?{signal}:undefined);
57
+ connectionAccountIdentity(client,expectedIdentity);
38
58
  if(enforceMinimum)assertBridgeCompatible(client.getServerCapabilities(),CLIENT_VERSION);
39
59
  else readPlatformBridgePolicy(client.getServerCapabilities());
40
60
  return client;
@@ -20,6 +20,21 @@ const canonical=value=>{
20
20
  const argumentsDigest=value=>digest(canonical(value));
21
21
  const boundedSet=(map,key,value)=>{if(!map.has(key)&&map.size>=1024)map.delete(map.keys().next().value);map.set(key,value);};
22
22
 
23
+ /** Resolve the original host proof once, including when a local account router
24
+ * chooses the connection before handing this same call to its platform bridge. */
25
+ export async function resolveHostCallBinding(raw,{host=resolveHostIdentity(),hostSession}={}){
26
+ for(const field of ['threadId','controller','clientDigest','token','controlVersion','developmentPairing'])if(Object.hasOwn(raw.arguments??{},field))
27
+ throw new CreationClientError('creation.transport_authority_managed_by_bridge');
28
+ if(host.kind==='claude-code'){
29
+ if(hostSession)return hostSession.begin(raw);
30
+ if(raw.arguments?.[CLAUDE_HOST_PROOF]!==undefined)throw new CreationClientError('creation.host_identity_invalid');
31
+ return{host:{kind:'claude-code'},arguments:raw.arguments,assertCurrent:async()=>{}};
32
+ }
33
+ if(Object.hasOwn(raw.arguments??{},CLAUDE_HOST_PROOF))throw new CreationClientError('creation.transport_authority_managed_by_bridge');
34
+ hostParameters(raw,host,'independent-read');
35
+ return{host,arguments:raw.arguments,assertCurrent:async()=>{}};
36
+ }
37
+
23
38
  /** The authenticated platform owns classification and editor authority.
24
39
  * Business text and model annotations never populate this cache. */
25
40
  export function createHostCallBridge(client,{credentials,host=resolveHostIdentity(),hostSession,localUploads,onCatalogChange=()=>{},onKnowledgeChange=()=>{}}={}){
@@ -134,16 +149,14 @@ export function createHostCallBridge(client,{credentials,host=resolveHostIdentit
134
149
  listResourceTemplates:params=>knowledgeRead('resources','listResourceTemplates',params),
135
150
  readResource:params=>knowledgeRead('resources','readResource',params),
136
151
  listPrompts:params=>knowledgeRead('prompts','listPrompts',params),
137
- getPrompt:params=>knowledgeRead('prompts','getPrompt',params),close:()=>localUploads?.close(),async call(raw,{signal}={}){
152
+ getPrompt:params=>knowledgeRead('prompts','getPrompt',params),close:()=>localUploads?.close(),async call(raw,{signal,resolvedBinding}={}){
138
153
  for(const field of ['threadId','controller','clientDigest','token','controlVersion','developmentPairing'])if(Object.hasOwn(raw.arguments??{},field))
139
154
  throw new CreationClientError('creation.transport_authority_managed_by_bridge');
140
- let binding={host,arguments:raw.arguments,assertCurrent:async()=>{}};
155
+ const binding=resolvedBinding??await resolveHostCallBinding(raw,{host,hostSession});
156
+ if(binding.host.kind!==host.kind)throw new CreationClientError('creation.host_identity_invalid');
141
157
  if(host.kind==='claude-code'){
142
- if(hostSession)binding=await hostSession.begin(raw);
143
- else if(raw.arguments?.[CLAUDE_HOST_PROOF]!==undefined)throw new CreationClientError('creation.host_identity_invalid');
144
- else binding={host:{kind:'claude-code'},arguments:raw.arguments,assertCurrent:async()=>{}};
145
158
  if(binding.epoch!==hostEpoch){versions.clear();controllers.clear();inflight.clear();hostEpoch=binding.epoch;}
146
- }else if(Object.hasOwn(raw.arguments??{},CLAUDE_HOST_PROOF))throw new CreationClientError('creation.transport_authority_managed_by_bridge');
159
+ }
147
160
  raw={...raw,arguments:binding.arguments};
148
161
  await ensureDirectory();await binding.assertCurrent();const definition=directory.tools.get(raw.name);
149
162
  if(!definition)throw new CreationClientError('creation.tool_unavailable');