@tomflow/chatloop-tools 0.4.18 → 0.4.19
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/README.md +5 -1
- package/bin/cli.mjs +2 -2
- package/lib/approval-form-probe.mjs +55 -0
- package/lib/control.mjs +2 -0
- package/lib/extension-contract.mjs +15 -5
- package/lib/gateway.mjs +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@ Usage: chatloop-tools start [desktop-commander|tunnel]
|
|
|
21
21
|
Start all enabled tools or one.
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
**同 Chat 新接口(候选)**:`chat_loop_extension__start({projectId,mode:'adopt',confirmed:true})`(无 prompt)只尝试接管原 Chat,并由扩展自己检查 R/P 真实用户回合与版本。`mode:'adopt'` 与 `prompt` 互斥;从原 Chat 提出执行请求不能降级为新 Chat。
|
|
25
|
+
|
|
24
26
|
MCP `chat_loop_extension__start` 入参为 `{projectId, prompt, confirmed:true}`,可选 `replaceBlockedSessionId` 仅用于在双重核验旧 Session `BLOCKED` 且新 projectId 不同的情况下显式开启**新任务**;不提供 `force`,不重发旧任务。`status` 保持只读,未知回执不自动重试。
|
|
25
27
|
|
|
26
28
|
Extension Actions 委托 `@tomflow/chatloop-extension` 公共 CLI,不复制浏览器操作。具体安全边界和协议见 [Local Tools 产品文档](../../docs/local-tools.md),实际部署与已验证状态见 [CURRENT](../../context/CURRENT.md)。
|
|
@@ -37,4 +39,6 @@ npx --yes --package=@tomflow/chatloop-tools@latest chatloop-tools upgrade
|
|
|
37
39
|
**Start 长页面准备(0.4.17)**:私人 MCP `chat_loop_extension__start` 的 CLI 子调用等待窗口最多 330 秒,仅用于允许 Chrome 安全校验和 ChatGPT 编辑器自然就绪。超时仍返回不确定错误,不重新启动或重发,必须单独查询 Status。
|
|
38
40
|
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
**0.4.18 原有接口结构(历史候选)**:九个 Extension MCP 接口的名字、参数 Schema、CLI 映射和本机参数准入统一维护于 lib/extension-contract.mjs(纯契约、无进程副作用);extension-proxy.mjs 仅负责 npx 转发、超时和回执验证,Gateway 单独暴露一个安全限定 UUID 的 operation_status 查询。发布工具总数为 36:26 DC + 9 Extension + 1 Runtime 回执。发行/运行版本与源码候选需分开核验。
|
|
43
|
+
|
|
44
|
+
**源码候选 0.4.19(未发布)**:在不增加公开 Extension 工具数量的前提下,原 `chat_loop_extension__start` 增加只允许 `mode:adopt`、不含 prompt 的同 Chat 原地接管方式;可选 `chatUrl` 精确限制候选。真实 Chrome 正向链路、用户交互原生表单和 npm 正式发布仍须单独验收。
|
package/bin/cli.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import {randomUUID} from 'node:crypto';
|
|
|
5
5
|
import {createRequire} from 'node:module';
|
|
6
6
|
import {dirname,join} from 'node:path';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
|
-
import {CONTRACT,ACTIONS,registry,ensurePrivateDir,paths,
|
|
8
|
+
import {lifecycleDeadlineMs,CONTRACT,ACTIONS,registry,ensurePrivateDir,paths,
|
|
9
9
|
safeFallback,recoverStaleLock,exitCode,talk} from '../lib/control.mjs';
|
|
10
10
|
import {runGateway} from '../lib/gateway.mjs';
|
|
11
11
|
import {tunnelDoctor,runTunnel} from '../lib/tunnel.mjs';
|
|
@@ -95,7 +95,7 @@ async function runControl(action=command, params=extra){
|
|
|
95
95
|
}
|
|
96
96
|
// Real Desktop Commander cold startup can exceed 12s on loaded macOS.
|
|
97
97
|
const req={contract:CONTRACT,requestId,action,scope:target?'tool':'all',
|
|
98
|
-
deadlineMs:action
|
|
98
|
+
deadlineMs:lifecycleDeadlineMs(action)};
|
|
99
99
|
if(target)req.toolId=target;
|
|
100
100
|
let reply;
|
|
101
101
|
try{
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// INERT, opt-in MCP 2026-07-28 MRTR form probe.
|
|
2
|
+
// No browser actions, approvals, persistent state, or business side effects.
|
|
3
|
+
// The returned test selection MUST NOT authorize a real Chat Loop Start.
|
|
4
|
+
export const probeTool = Object.freeze({
|
|
5
|
+
name: 'chat_loop_test__approval_form',
|
|
6
|
+
description: 'TEST ONLY: display a native choice form. No approval, no Start, no persistence.',
|
|
7
|
+
inputSchema: {type:'object',properties:{},additionalProperties:false}
|
|
8
|
+
});
|
|
9
|
+
const names=['confirm','revise','reject','other'];
|
|
10
|
+
const options=[
|
|
11
|
+
{const:'confirm',title:'确认(仅测试,不批准任何真实任务)'},
|
|
12
|
+
{const:'revise',title:'需要修改(仅测试)'},
|
|
13
|
+
{const:'reject',title:'不通过(仅测试)'},
|
|
14
|
+
{const:'other',title:'自定义回答(仅测试)'}
|
|
15
|
+
];
|
|
16
|
+
const failed=reason=>({resultType:'complete',isError:true,
|
|
17
|
+
content:[{type:'text',text:'FORM_PROBE_'+reason}]});
|
|
18
|
+
const completed=value=>({resultType:'complete',
|
|
19
|
+
content:[{type:'text',text:JSON.stringify({probeOnly:true, ...value})}]});
|
|
20
|
+
const supportsForm=caps=>!!caps?.elicitation
|
|
21
|
+
&& (caps.elicitation.form!==undefined || Object.keys(caps.elicitation).length===0);
|
|
22
|
+
export function handleProbeForm(params={}) {
|
|
23
|
+
if(params?.arguments===null || typeof params?.arguments!=='object'
|
|
24
|
+
|| Array.isArray(params.arguments) || Object.keys(params.arguments||{}).length)
|
|
25
|
+
return failed('INVALID_ARGUMENT');
|
|
26
|
+
// MCP 2026-07-28 requires per-request client capabilities. Never elicit
|
|
27
|
+
// input unless the client explicitly declares support for form mode.
|
|
28
|
+
const capabilities=params?._meta?.['io.modelcontextprotocol/clientCapabilities'];
|
|
29
|
+
if(params?._meta?.['io.modelcontextprotocol/protocolVersion']!=='2026-07-28')
|
|
30
|
+
return failed('MODERN_METADATA_REQUIRED');
|
|
31
|
+
if(!supportsForm(capabilities))return failed('CLIENT_FORM_UNSUPPORTED');
|
|
32
|
+
if(params.requestState!==undefined)return failed('UNEXPECTED_REQUEST_STATE');
|
|
33
|
+
const received=params.inputResponses;
|
|
34
|
+
if(received===undefined)return {resultType:'input_required',
|
|
35
|
+
inputRequests:{test_choice:{
|
|
36
|
+
method:'elicitation/create',
|
|
37
|
+
params:{mode:'form',message:'Chat Loop 原生选项技术测试:不会批准任务或启动循环。',
|
|
38
|
+
requestedSchema:{type:'object',properties:{
|
|
39
|
+
choice:{type:'string',title:'请选择一个测试选项',oneOf:options},
|
|
40
|
+
note:{type:'string',title:'自定义回答(选自定义时必填)',maxLength:300}
|
|
41
|
+
},required:['choice']}
|
|
42
|
+
}
|
|
43
|
+
}}};
|
|
44
|
+
if(!received || typeof received!=='object'||Array.isArray(received)
|
|
45
|
+
||Object.keys(received).some(k=>k!=='test_choice'))
|
|
46
|
+
return failed('INVALID_RESPONSE');
|
|
47
|
+
const result=received.test_choice;
|
|
48
|
+
if(!result || !['accept','decline','cancel'].includes(result.action))
|
|
49
|
+
return failed('INVALID_RESPONSE');
|
|
50
|
+
if(result.action!=='accept')return completed({userAction:result.action,choice:null});
|
|
51
|
+
const choice=result.content?.choice, note=result.content?.note??'';
|
|
52
|
+
if(!names.includes(choice)||typeof note!=='string'||note.length>300
|
|
53
|
+
||choice==='other'&&!note.trim())return failed('INVALID_CHOICE');
|
|
54
|
+
return completed({userAction:'accept',choice,note});
|
|
55
|
+
}
|
package/lib/control.mjs
CHANGED
|
@@ -13,6 +13,8 @@ export const toolCallDeadlineMs = args => {
|
|
|
13
13
|
const requested = Number.isSafeInteger(args?.timeout_ms) && args.timeout_ms > 0 ? args.timeout_ms : 0;
|
|
14
14
|
return Math.min(42000, Math.max(12000, requested + 8000));
|
|
15
15
|
};
|
|
16
|
+
// Lifecycle wait contract shared by CLI callers and integration tests.
|
|
17
|
+
export const lifecycleDeadlineMs = action => ['start','restart'].includes(action) ? 25000 : 12000;
|
|
16
18
|
export const ACTIONS = new Set(['start','stop','restart','status']);
|
|
17
19
|
export const directory = () => process.env.CHAT_LOOP_LOCAL_TOOLS_STATE_DIR || join(homedir(), '.chat-loop', 'local-tools');
|
|
18
20
|
export const paths = () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Pure public API: MCP schemas, CLI routes and their argument gate.
|
|
2
2
|
// No process creation, filesystem access, browser actions or user side effects.
|
|
3
3
|
const PROJECT_ID=/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;
|
|
4
|
+
const CHAT_URL=/^https:\/\/chatgpt\.com\/(?:c\/[0-9a-f-]{12,}|g\/[^/]+\/c\/[0-9a-f-]{12,})$/i;
|
|
4
5
|
const REPLACE_SESSION=/^[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$/;
|
|
5
6
|
const TURN_TOKEN=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
6
7
|
const INTENT_ID=/^[a-f0-9]{32}$/;
|
|
@@ -18,10 +19,14 @@ const endpoints=[
|
|
|
18
19
|
{tabId:{type:'integer',minimum:1}},['tabId'])],
|
|
19
20
|
[['extension','reload'],extensionTool('reload','Request reload of Chat Loop Extension; final health is unverified.',false)],
|
|
20
21
|
[['extension','status'],extensionTool('status','Read the unique current Mac Chrome Web Chat Owner; never starts or sends.',true)],
|
|
21
|
-
[['extension','start'],extensionTool('start',
|
|
22
|
-
|
|
22
|
+
[['extension','start'],extensionTool('start',
|
|
23
|
+
'Start a new Chat with prompt, OR mode=adopt for an existing Chat with two browser-verified R/P approvals. Adopt never creates a tab or resends a message; ambiguous or absent approvals are denied.',false,
|
|
24
|
+
{projectId:{type:'string',minLength:1,maxLength:128,pattern:PROJECT_ID.source},
|
|
25
|
+
prompt:{type:'string',minLength:1,maxLength:4000,pattern:'\\S'},confirmed:{const:true},
|
|
26
|
+
mode:{type:'string',enum:['adopt']},
|
|
27
|
+
chatUrl:{type:'string',pattern:CHAT_URL.source},
|
|
23
28
|
replaceBlockedSessionId:{type:'string',pattern:REPLACE_SESSION.source}},
|
|
24
|
-
['projectId','
|
|
29
|
+
['projectId','confirmed'])],
|
|
25
30
|
[['extension','continue'],extensionTool('continue','Submit next-turn text with turnToken and nextPrompt; alternatively query its final status with turnToken and intentId. Only the Extension can send after Turn completion.',false,
|
|
26
31
|
{turnToken:{type:'string',pattern:TURN_TOKEN.source},nextPrompt:{type:'string',minLength:1,maxLength:4000,pattern:'\\S'},
|
|
27
32
|
intentId:{type:'string',pattern:INTENT_ID.source},lookup:{type:'boolean'}},['turnToken'])],
|
|
@@ -47,10 +52,15 @@ export function validExtensionArgs(name,args){
|
|
|
47
52
|
}else if(!control && Object.keys(args).length)return false;
|
|
48
53
|
if(name==='start'){
|
|
49
54
|
if(!PROJECT_ID.test(args.projectId||'')
|
|
50
|
-
||typeof args.prompt!=='string'||!args.prompt.trim()||args.prompt.length>4000
|
|
51
55
|
||args.confirmed!==true
|
|
52
56
|
||(args.replaceBlockedSessionId!==undefined
|
|
53
|
-
&& !REPLACE_SESSION.test(args.replaceBlockedSessionId))
|
|
57
|
+
&& !REPLACE_SESSION.test(args.replaceBlockedSessionId))
|
|
58
|
+
||(args.mode!==undefined && args.mode!=='adopt')
|
|
59
|
+
||(args.chatUrl!==undefined && (args.mode!=='adopt'
|
|
60
|
+
||typeof args.chatUrl!=='string'||!CHAT_URL.test(args.chatUrl)))
|
|
61
|
+
||(args.mode==='adopt'
|
|
62
|
+
? Object.hasOwn(args,'prompt')
|
|
63
|
+
: typeof args.prompt!=='string'||!args.prompt.trim()||args.prompt.length>4000))
|
|
54
64
|
return false;
|
|
55
65
|
}
|
|
56
66
|
if(control&&name!=='start'){
|
package/lib/gateway.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import {randomUUID} from 'node:crypto';
|
|
|
3
3
|
import {readFileSync} from 'node:fs';
|
|
4
4
|
import {CONTRACT,PACKAGE_VERSION,registry,talk,toolCallDeadlineMs} from './control.mjs';
|
|
5
5
|
import {extensionTools,forwardExtensionAction} from './extension-proxy.mjs';
|
|
6
|
+
import {probeTool,handleProbeForm} from './approval-form-probe.mjs';
|
|
6
7
|
import {runtimeNeedsUpgrade} from './release.mjs';
|
|
7
8
|
|
|
8
9
|
const desktopTools=JSON.parse(readFileSync(new URL('./desktop-commander-tools.json',import.meta.url),'utf8'));
|
|
@@ -13,6 +14,8 @@ const prefix=id=>id.replaceAll('-','_')+'__';
|
|
|
13
14
|
// The pinned child's UI metadata advertises resources this tools-only Gateway does not serve.
|
|
14
15
|
// Do not expose those references until resources/read is explicitly supported.
|
|
15
16
|
const extEnabled=()=>process.env.CHAT_LOOP_LOCAL_TOOLS_FIXTURES!=='1';
|
|
17
|
+
// Opt-in isolated research probe; never shipped as an active production tool.
|
|
18
|
+
const formProbeEnabled=()=>process.env.CHAT_LOOP_FORM_PROBE==='1';
|
|
16
19
|
// The only extra Gateway-owned API: read an existing operation receipt.
|
|
17
20
|
// Its identifier is always a generated UUID, never an arbitrary selector.
|
|
18
21
|
const RECEIPT_ID=/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
|
|
@@ -24,6 +27,7 @@ const published=()=>[
|
|
|
24
27
|
...registry().filter(t=>t.enabled).flatMap(t=>
|
|
25
28
|
toolsFor(t).map(({_meta,...x})=>({...x,name:prefix(t.id)+x.name}))),
|
|
26
29
|
...(extEnabled()?extensionTools.map(t=>({...t,name:'chat_loop_extension__'+t.name})):[]),
|
|
30
|
+
...(formProbeEnabled()?[probeTool]:[]),
|
|
27
31
|
receiptTool
|
|
28
32
|
];
|
|
29
33
|
function resolveTool(name){
|
|
@@ -44,16 +48,18 @@ function resolveTool(name){
|
|
|
44
48
|
const failure=code=>({isError:true,content:[{type:'text',text:code}]});
|
|
45
49
|
const rpcError=(code,message)=>({code,message});
|
|
46
50
|
export function runGateway(){
|
|
47
|
-
let buf='',connected=false;
|
|
51
|
+
let buf='',connected=false,negotiatedVersion=null;
|
|
48
52
|
const write=message=>process.stdout.write(JSON.stringify(message)+'\n');
|
|
49
53
|
const reply=(id,result)=>write({jsonrpc:'2.0',id,result});
|
|
50
54
|
const reject=(id,code,message)=>write({jsonrpc:'2.0',id,error:rpcError(code,message)});
|
|
51
55
|
const processMessage=async m=>{
|
|
52
56
|
if(!m||m.jsonrpc!=='2.0'||m.id===undefined)return;
|
|
53
57
|
if(m.method==='initialize'){
|
|
54
|
-
if(!['2025-11-25','2025-06-18','2025-03-26','2024-11-05']
|
|
58
|
+
if(![...(['2025-11-25','2025-06-18','2025-03-26','2024-11-05']),
|
|
59
|
+
...(formProbeEnabled()?['2026-07-28']:[])].includes(m.params?.protocolVersion))
|
|
55
60
|
return reject(m.id,-32602,'UNSUPPORTED_MCP_VERSION');
|
|
56
61
|
connected=true;
|
|
62
|
+
negotiatedVersion=m.params.protocolVersion;
|
|
57
63
|
return reply(m.id,{protocolVersion:m.params.protocolVersion,
|
|
58
64
|
capabilities:{tools:{}},serverInfo:{name:'chat-loop-local-tools',version:PACKAGE_VERSION}});
|
|
59
65
|
}
|
|
@@ -64,6 +70,11 @@ export function runGateway(){
|
|
|
64
70
|
if(m.method==='ping')return reply(m.id,{});
|
|
65
71
|
if(m.method==='tools/list')return reply(m.id,{tools:published()});
|
|
66
72
|
if(m.method==='tools/call'){
|
|
73
|
+
if(formProbeEnabled() && m.params?.name===probeTool.name)
|
|
74
|
+
return reply(m.id,negotiatedVersion==='2026-07-28'
|
|
75
|
+
?handleProbeForm(m.params)
|
|
76
|
+
:{resultType:'complete',isError:true,
|
|
77
|
+
content:[{type:'text',text:'FORM_PROBE_MODERN_PROTOCOL_REQUIRED'}]});
|
|
67
78
|
const routed=m.params?.name===receiptTool.name?
|
|
68
79
|
{toolId:'runtime',name:'operation_status'}:resolveTool(m.params?.name);
|
|
69
80
|
if(!routed)return reply(m.id,failure('UNKNOWN_TOOL'));
|