@tomflow/chatloop-tools 0.4.24 → 0.4.26
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/supervisor.mjs +8 -2
- package/lib/trace-gateway.mjs +32 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,10 @@ npx --yes --package=@tomflow/chatloop-tools@latest chatloop-tools upgrade
|
|
|
46
46
|
|
|
47
47
|
**0.4.24 防止文字误拦截**:`0.4.23` 在 Mac 本机执行已通过,但 Gateway 的图形终端拦截会把文档或 heredoc 内提及的命令当成真实执行,造成误拒。本版只检查实际 shell 命令位置,跳过 heredoc 正文;真实启动图形 Terminal/iTerm 的命令仍被阻止,普通代码、文档、目录和服务命令不受影响。独立回归覆盖实际启动和字符串/文档反例。**本机 MCP 权限/资源模型与 0.4.23 相同**。
|
|
48
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
|
+
|
|
51
|
+
**0.4.26 Trace 精确 Start 阻断原因**:真实 Extension Status 同时给出泛化 Owner 原因与更精确的 `lastStartFailureCode` 时,Trace 只在 `BLOCKED + action=START` 的情况下优先记录经过严格格式验证的故障码;无精确故障码仍使用原理由,不提权、不补发,不将 DOM 中的用户消息当作 Native 成功回执。真实 Gateway→Supervisor→唯一 Trace Writer 集成测试覆盖 `FIRST_SEND_RECEIPT_UNKNOWN`。
|
|
52
|
+
|
|
49
53
|
**Start 长页面准备(0.4.17)**:私人 MCP `chat_loop_extension__start` 的 CLI 子调用等待窗口最多 330 秒,仅用于允许 Chrome 安全校验和 ChatGPT 编辑器自然就绪。超时仍返回不确定错误,不重新启动或重发,必须单独查询 Status。
|
|
50
54
|
|
|
51
55
|
|
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/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};
|
package/lib/trace-gateway.mjs
CHANGED
|
@@ -70,28 +70,52 @@ 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
|
+
// Status may contain a specific Start failure beneath the generic
|
|
98
|
+
// START_SEND_UNVERIFIED owner reason. Keep the specific code in Trace
|
|
99
|
+
// without treating DOM observation as a Native send receipt.
|
|
100
|
+
const codes=proof.diagnostics?.action==='START'
|
|
101
|
+
?[proof.diagnostics?.lastStartFailureCode,proof.diagnostics?.reason]
|
|
102
|
+
:[proof.diagnostics?.reason];
|
|
103
|
+
const errorCode=blocked?codes.find(value=>typeof value==='string'&&
|
|
104
|
+
/^[A-Z][A-Z0-9_]{0,95}$/.test(value))||null:null;
|
|
105
|
+
// Observer message identity is an opaque DOM evidence reference, not chat
|
|
106
|
+
// content and not a Native send acknowledgement.
|
|
107
|
+
const assistantKey=proof.diagnostics?.assistantKey;
|
|
108
|
+
const messageEvidence=!intent&&typeof assistantKey==='string'&&
|
|
109
|
+
/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(assistantKey)
|
|
110
|
+
?assistantKey:null;
|
|
89
111
|
try{
|
|
90
112
|
await talk({contract:CONTRACT,action:'__trace_observation',
|
|
91
|
-
requestId:randomUUID(),traceId:
|
|
92
|
-
projectRef,taskRef:
|
|
93
|
-
sessionRef:
|
|
94
|
-
...(intent?{actionId:proof.intentId,evidenceRef:proof.intentId}
|
|
113
|
+
requestId:randomUUID(),traceId:session.sessionId,
|
|
114
|
+
projectRef,taskRef:session.taskId||args?.taskId||null,
|
|
115
|
+
sessionRef:session.sessionId,generation:session.generation??null,
|
|
116
|
+
...(intent?{actionId:proof.intentId,evidenceRef:proof.intentId}
|
|
117
|
+
:messageEvidence?{evidenceRef:messageEvidence}:{}),
|
|
118
|
+
...(errorCode?{errorCode}:{}),
|
|
95
119
|
event,status},1800);
|
|
96
120
|
}catch{
|
|
97
121
|
// Logging failures never cause the model's original intent to be replayed.
|