@tomflow/chatloop-tools 0.4.23 → 0.4.25
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 +4 -0
- package/lib/adapters/tunnel.mjs +17 -1
- package/lib/release.mjs +3 -2
- package/lib/supervisor.mjs +8 -2
- package/lib/terminal-app-policy.mjs +29 -11
- package/lib/trace-gateway.mjs +27 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,10 @@ npx --yes --package=@tomflow/chatloop-tools@latest chatloop-tools upgrade
|
|
|
44
44
|
|
|
45
45
|
**0.4.23 正式 Mac 用户环境(本轮目标)**:Chat Loop 自己的 MCP Gateway 仍路由同一 pinned Desktop Commander 子进程;Supervisor 不再给它创建 `~/.chat-loop/local-tools/tools/desktop-commander/home` 假 HOME,改从 OS 实际登录账号 `userInfo()` 取得用户 HOME/USER/LOGNAME,保留原有 PATH 和本机服务环境。意味着 MCP 文件、shell、npm、配置与用户的 Mac 账号目录一致,不必使用 Local Dev 或桌面 Terminal 中转。独立 Local Dev MCP 仅用于本轮迁移/研发;新 Gateway 仍拒绝图形 Terminal/iTerm 启动。新增真实 Gateway→Desktop Commander→`node os.homedir()` 的本机回读测试。**该包需单独正式发布和真实生产激活;源码回归通过不等于云端已切换。**
|
|
46
46
|
|
|
47
|
+
**0.4.24 防止文字误拦截**:`0.4.23` 在 Mac 本机执行已通过,但 Gateway 的图形终端拦截会把文档或 heredoc 内提及的命令当成真实执行,造成误拒。本版只检查实际 shell 命令位置,跳过 heredoc 正文;真实启动图形 Terminal/iTerm 的命令仍被阻止,普通代码、文档、目录和服务命令不受影响。独立回归覆盖实际启动和字符串/文档反例。**本机 MCP 权限/资源模型与 0.4.23 相同**。
|
|
48
|
+
|
|
49
|
+
**0.4.25 Trace 真实会话关联修复**:Tunnel 显式继承唯一 Tools Supervisor 的 Context/Trace opt-in Gateway 配置(不继承其它账号密钥),避免线上 Gateway 无法暴露 `chat_loop_trace_diagnose`。Trace Gateway 兼容 Chrome Status 的真实嵌套 `session.sessionId` 回执,对 BLOCKED Status 记录故障码和助手消息身份引用(不写原文、不冒充 Native 发送确认)。专项真实 Supervisor/Gateway 桥接测试覆盖同一 Session 的日志、诊断和不泄漏消息正文。生产必须分别验证 Runtime 环境、Tunnel MCP tools/list、Trace writerHealth 和 Chrome DOM/文字回执。旧日志仍保留,缺失的历史事件不能补造成已确认事件。
|
|
50
|
+
|
|
47
51
|
**Start 长页面准备(0.4.17)**:私人 MCP `chat_loop_extension__start` 的 CLI 子调用等待窗口最多 330 秒,仅用于允许 Chrome 安全校验和 ChatGPT 编辑器自然就绪。超时仍返回不确定错误,不重新启动或重发,必须单独查询 Status。
|
|
48
52
|
|
|
49
53
|
|
package/lib/adapters/tunnel.mjs
CHANGED
|
@@ -12,6 +12,21 @@ const err=code=>({code});
|
|
|
12
12
|
const result=(t,before,after,outcome,error=null,pid=null,evidence=null,connection='UNVERIFIED')=>
|
|
13
13
|
({toolId:t.id,enabled:t.enabled,before,after,outcome,pid,evidence,error,connection});
|
|
14
14
|
const pause=ms=>new Promise(resolve=>setTimeout(resolve,ms));
|
|
15
|
+
// The Gateway spawned inside Tunnel must see the same opt-in Context/Trace
|
|
16
|
+
// settings as the Supervisor; otherwise production tools/list silently omits
|
|
17
|
+
// both SDKs. Forward only known non-secret integration settings.
|
|
18
|
+
const gatewaySettings=[
|
|
19
|
+
'CHAT_LOOP_CONTEXT_API_ENABLE','CHAT_LOOP_CONTEXT_ROOT',
|
|
20
|
+
'CHAT_LOOP_CONTEXT_DB','CHAT_LOOP_CONTEXT_ALLOWED_PROJECTS',
|
|
21
|
+
'CHAT_LOOP_CONTEXT_NODE_BIN',
|
|
22
|
+
'CHAT_LOOP_TRACE_API_ENABLE','CHAT_LOOP_TRACE_ALLOWED_PROJECTS',
|
|
23
|
+
'CHAT_LOOP_LOCAL_TOOLS_STATE_DIR'
|
|
24
|
+
];
|
|
25
|
+
export function gatewayChildSettings(parent=process.env){
|
|
26
|
+
return Object.fromEntries(gatewaySettings.filter(key=>
|
|
27
|
+
typeof parent[key]==='string'&&parent[key].length>0)
|
|
28
|
+
.map(key=>[key,parent[key]]));
|
|
29
|
+
}
|
|
15
30
|
function probe(socketPath,ms=350){
|
|
16
31
|
return new Promise(resolve=>{
|
|
17
32
|
const req=httpRequest({socketPath,path:'/readyz',method:'GET',timeout:ms},res=>{
|
|
@@ -97,7 +112,8 @@ export function createTunnelAdapter({records,log,onChildExit=()=>{}},options={})
|
|
|
97
112
|
// Never inherit Local Dev's CONTROL_PLANE_API_KEY or OPENAI_ADMIN_KEY.
|
|
98
113
|
const env={HOME:homedir(),PATH:process.env.PATH||'/usr/bin:/bin',
|
|
99
114
|
USER:process.env.USER||'',LANG:process.env.LANG||'en_US.UTF-8',
|
|
100
|
-
TMPDIR:process.env.TMPDIR||'/tmp'
|
|
115
|
+
TMPDIR:process.env.TMPDIR||'/tmp',
|
|
116
|
+
...gatewayChildSettings()};
|
|
101
117
|
if(process.env.CHAT_LOOP_TUNNEL_CONTROL_PLANE_API_KEY)
|
|
102
118
|
env.CONTROL_PLANE_API_KEY=process.env.CHAT_LOOP_TUNNEL_CONTROL_PLANE_API_KEY;
|
|
103
119
|
let child;
|
package/lib/release.mjs
CHANGED
|
@@ -9,8 +9,9 @@ import {PACKAGE_VERSION} from './control.mjs';
|
|
|
9
9
|
const name='@tomflow/chatloop-tools';
|
|
10
10
|
const entryIn=prefix=>join(prefix,'node_modules','@tomflow','chatloop-tools','bin','cli.mjs');
|
|
11
11
|
const runtimeRoot=()=>join(homedir(),'.chat-loop');
|
|
12
|
-
//
|
|
13
|
-
//
|
|
12
|
+
// An external MCP or test shell may still inherit an isolated HOME. The
|
|
13
|
+
// production Tools Desktop Commander now uses the actual Mac account HOME;
|
|
14
|
+
// upgrades must also resolve that same account root, never a sandbox copy.
|
|
14
15
|
function checkedUpgradeBase(options){
|
|
15
16
|
if(options.base!==undefined)return options.base; // Explicit test/API base.
|
|
16
17
|
try{
|
package/lib/supervisor.mjs
CHANGED
|
@@ -38,15 +38,21 @@ function handleTraceObservation(req){
|
|
|
38
38
|
if(req?.contract!==CONTRACT||!validEvent
|
|
39
39
|
||!(intent?(req.event.endsWith('.intent.queued')?req.status==='BEGIN'
|
|
40
40
|
:['CONFIRMED','UNKNOWN'].includes(req.status))
|
|
41
|
-
:['CONFIRMED','UNKNOWN'].includes(req.status))
|
|
41
|
+
:['CONFIRMED','UNKNOWN','BLOCKED'].includes(req.status))
|
|
42
42
|
||typeof req.traceId!=='string'
|
|
43
43
|
||(intent&&(!/^[a-f0-9]{32}$/.test(req.actionId||'')
|
|
44
44
|
||req.evidenceRef!==req.actionId)))throw error('TRACE_INVALID_ARGUMENT');
|
|
45
|
+
const errorCode=typeof req.errorCode==='string'&&
|
|
46
|
+
/^[A-Z][A-Z0-9_]{0,95}$/.test(req.errorCode)?req.errorCode:null;
|
|
45
47
|
const written=traceWriter.record({
|
|
46
48
|
traceId:req.traceId,sessionRef:req.sessionRef,projectRef:req.projectRef,
|
|
47
49
|
taskRef:req.taskRef??null,generation:req.generation??null,
|
|
48
50
|
requestId:req.requestId,component:'gateway',
|
|
49
|
-
...(intent?{actionId:req.actionId,evidenceRef:req.evidenceRef}
|
|
51
|
+
...(intent?{actionId:req.actionId,evidenceRef:req.evidenceRef}
|
|
52
|
+
:req.event==='extension.status.observed'&&typeof req.evidenceRef==='string'
|
|
53
|
+
&&/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(req.evidenceRef)
|
|
54
|
+
?{evidenceRef:req.evidenceRef}:{}),
|
|
55
|
+
...(req.status==='BLOCKED'&&errorCode?{errorCode}:{}),
|
|
50
56
|
event:req.event,status:req.status
|
|
51
57
|
});
|
|
52
58
|
return {contract:CONTRACT,requestId:req.requestId,status:'OK',eventId:written.eventId};
|
|
@@ -1,18 +1,36 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// Direct macOS GUI Terminal launch prevention at the Chat Loop MCP boundary.
|
|
2
|
+
// Ordinary shell/CLI commands and text containing examples are not blocked.
|
|
3
3
|
const terminalApp=String.raw`(?:Terminal|iTerm2?)(?:\.app)?`;
|
|
4
4
|
const appTarget=new RegExp(String.raw`(?:^|\s|\/|["'])${terminalApp}(?:\/|["'\s;]|$)`,'i');
|
|
5
|
+
function shellStatementsOnly(input){
|
|
6
|
+
const lines=input.split(/\r?\n/),outside=[];
|
|
7
|
+
let hereEnd=null;
|
|
8
|
+
for(const line of lines){
|
|
9
|
+
if(hereEnd!==null){
|
|
10
|
+
if(line.trim()===hereEnd)hereEnd=null;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
outside.push(line);
|
|
14
|
+
const here=line.match(/<<-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);
|
|
15
|
+
if(here)hereEnd=here[2];
|
|
16
|
+
}
|
|
17
|
+
return outside.join('\n');
|
|
18
|
+
}
|
|
5
19
|
export function isGraphicalTerminalCommand(toolName,args){
|
|
6
|
-
if(toolName!=='start_process'
|
|
20
|
+
if(toolName!=='start_process'&&toolName!=='interact_with_process')return false;
|
|
7
21
|
const command=toolName==='start_process'?args?.command:args?.input;
|
|
8
22
|
if(typeof command!=='string')return false;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
const statements=shellStatementsOnly(command);
|
|
24
|
+
// A command has to be at shell position, not quoted as data or in a heredoc.
|
|
25
|
+
const start=String.raw`(?:^|[;&|]\s*|\bthen\s+|\bdo\s+)\s*`;
|
|
26
|
+
const open=new RegExp(start+String.raw`(?:\/usr\/bin\/)?open\s+[^;\n|]{0,240}`,'gim');
|
|
27
|
+
for(const match of statements.matchAll(open)){
|
|
28
|
+
if(/(?:^|\s)-a(?:\s|=)/.test(match[0])&&appTarget.test(match[0]))return true;
|
|
29
|
+
}
|
|
30
|
+
const osa=new RegExp(start+String.raw`(?:\/usr\/bin\/)?osascript\s+[^;\n|]{0,450}`,'gim');
|
|
31
|
+
for(const match of statements.matchAll(osa)){
|
|
32
|
+
if(/\b(?:Terminal|iTerm2?)\b/i.test(match[0]))return true;
|
|
13
33
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if(/\/(?:Terminal|iTerm2?)\.app\/Contents\/MacOS\//i.test(command))return true;
|
|
17
|
-
return false;
|
|
34
|
+
const direct=new RegExp(start+String.raw`\/[^;\n|]*\/(?:Terminal|iTerm2?)\.app\/Contents\/MacOS\/\S+`,'gim');
|
|
35
|
+
return direct.test(statements);
|
|
18
36
|
}
|
package/lib/trace-gateway.mjs
CHANGED
|
@@ -70,28 +70,47 @@ export async function observeExtensionResult(name,args,result){
|
|
|
70
70
|
let proof;
|
|
71
71
|
try{proof=JSON.parse(result?.content?.find(x=>x.type==='text')?.text||'null')}
|
|
72
72
|
catch{return}
|
|
73
|
-
|
|
73
|
+
// Real Extension Status wraps the Native session under "session"; the
|
|
74
|
+
// intent/start receipts instead report a flat sessionId. Do not assume
|
|
75
|
+
// fixture-only flat Status, or silently lose production Trace events.
|
|
76
|
+
const session=name==='status'&&proof?.session &&
|
|
77
|
+
typeof proof.session==='object'&&!Array.isArray(proof.session)
|
|
78
|
+
?proof.session:proof;
|
|
79
|
+
if(!session||!new RegExp(UUID).test(session.sessionId||''))return;
|
|
74
80
|
const intent=['continue','handoff'].includes(name);
|
|
75
81
|
if(intent&&(!/^[a-f0-9]{32}$/.test(proof.intentId||'')
|
|
76
82
|
||!['QUEUED','STATUS'].includes(proof.status)))return;
|
|
77
|
-
const projectRef=
|
|
83
|
+
const projectRef=session.projectId||(intent?null:args?.projectId);
|
|
78
84
|
if(!getAllowedProjects().includes(projectRef)||
|
|
79
|
-
args?.projectId&&
|
|
85
|
+
args?.projectId&&session.projectId&&args.projectId!==session.projectId)return;
|
|
80
86
|
const event=intent
|
|
81
87
|
?'extension.'+name+(proof.status==='QUEUED'?'.intent.queued':'.receipt.observed')
|
|
82
88
|
:'extension.'+name+'.observed';
|
|
83
89
|
const matchingAction=!proof.actualAction
|
|
84
90
|
||proof.actualAction===name.toUpperCase();
|
|
91
|
+
const phase=session.phase||proof.phase;
|
|
92
|
+
const blocked=!intent&&(phase==='BLOCKED'||proof.state==='BLOCKED');
|
|
85
93
|
const status=intent
|
|
86
94
|
?proof.status==='QUEUED'?'BEGIN'
|
|
87
95
|
:proof.phase==='SENT_CONFIRMED'&&matchingAction?'CONFIRMED':'UNKNOWN'
|
|
88
|
-
:proof.status==='OK'?'CONFIRMED':'UNKNOWN';
|
|
96
|
+
:blocked?'BLOCKED':proof.status==='OK'?'CONFIRMED':'UNKNOWN';
|
|
97
|
+
const reason=proof.diagnostics?.reason;
|
|
98
|
+
const errorCode=blocked&&typeof reason==='string'&&
|
|
99
|
+
/^[A-Z][A-Z0-9_]{0,95}$/.test(reason)?reason:null;
|
|
100
|
+
// Observer message identity is an opaque DOM evidence reference, not chat
|
|
101
|
+
// content and not a Native send acknowledgement.
|
|
102
|
+
const assistantKey=proof.diagnostics?.assistantKey;
|
|
103
|
+
const messageEvidence=!intent&&typeof assistantKey==='string'&&
|
|
104
|
+
/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(assistantKey)
|
|
105
|
+
?assistantKey:null;
|
|
89
106
|
try{
|
|
90
107
|
await talk({contract:CONTRACT,action:'__trace_observation',
|
|
91
|
-
requestId:randomUUID(),traceId:
|
|
92
|
-
projectRef,taskRef:
|
|
93
|
-
sessionRef:
|
|
94
|
-
...(intent?{actionId:proof.intentId,evidenceRef:proof.intentId}
|
|
108
|
+
requestId:randomUUID(),traceId:session.sessionId,
|
|
109
|
+
projectRef,taskRef:session.taskId||args?.taskId||null,
|
|
110
|
+
sessionRef:session.sessionId,generation:session.generation??null,
|
|
111
|
+
...(intent?{actionId:proof.intentId,evidenceRef:proof.intentId}
|
|
112
|
+
:messageEvidence?{evidenceRef:messageEvidence}:{}),
|
|
113
|
+
...(errorCode?{errorCode}:{}),
|
|
95
114
|
event,status},1800);
|
|
96
115
|
}catch{
|
|
97
116
|
// Logging failures never cause the model's original intent to be replayed.
|