@tomflow/chatloop-tools 0.4.21 → 0.4.23
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/mcp-child.mjs +17 -7
- package/lib/gateway.mjs +5 -1
- package/lib/release.mjs +4 -1
- package/lib/terminal-app-policy.mjs +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,10 @@ npx --yes --package=@tomflow/chatloop-tools@latest chatloop-tools upgrade
|
|
|
40
40
|
|
|
41
41
|
**M10 Tools 0.4.21 新候选(尚未发布/生产激活)**:上一轮真实用户根中已暂存的 0.4.20 归档 SHA-256 为 `a2dbf4da...`,与 M10 最新单包归档 `6f9447d3...` 不相同,实际多出三项文件内容差异(README、Gateway、Trace Gateway);**不可激活旧 0.4.20 暂存版冒充新交付物**。新 CLI 改为 `upgrade activate <expected-artifact-sha256>`,在旧 Supervisor 停机前校验不可变准备回执与调用者指定包哈希,缺参/不一致一律 BLOCKED。0.4.21 离线单包已完成隔离 `STAGED_ONLY` 验证,但正式 HOME 下未准备、发布或激活。完整源码与回归证据见 [M10 模块计划](../../docs/research/chat-loop-module-api-alignment-plan-20261110.md)。
|
|
42
42
|
|
|
43
|
+
**0.4.22 GUI Terminal 禁用与纯 MCP 执行**:执行命令只走已授权 Chat Loop MCP `desktop_commander__start_process` / `read_process_output`,或用户明确授权的 Local Dev MCP 备用通道;**禁止**通过 `open -n -a Terminal`、`osascript`、iTerm 或 .app 二进制启动图形终端窗口。Gateway 对直接启动 Terminal/iTerm 的 `start_process` 和 `interact_with_process` 返回 `GUI_TERMINAL_LAUNCH_PROHIBITED`,普通 shell/CLI 命令、文件与目录访问不受此规则限制。本机正式用户 HOME 的 CLI 验收可以直接经 Local Dev MCP 完成,不需要打开任何 Terminal 窗口。此检查仅能拦截明确命令形式;Tooling Skill 同时约束调用者,不声称能拦截任意嵌套脚本。
|
|
44
|
+
|
|
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
|
+
|
|
43
47
|
**Start 长页面准备(0.4.17)**:私人 MCP `chat_loop_extension__start` 的 CLI 子调用等待窗口最多 330 秒,仅用于允许 Chrome 安全校验和 ChatGPT 编辑器自然就绪。超时仍返回不确定错误,不重新启动或重发,必须单独查询 Status。
|
|
44
48
|
|
|
45
49
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {spawn} from 'node:child_process';
|
|
2
2
|
import {createRequire} from 'node:module';
|
|
3
|
-
import {dirname,join} from 'node:path';
|
|
4
|
-
import {
|
|
3
|
+
import {dirname,join,isAbsolute} from 'node:path';
|
|
4
|
+
import {readFileSync} from 'node:fs';
|
|
5
5
|
import {randomUUID} from 'node:crypto';
|
|
6
|
+
import {userInfo} from 'node:os';
|
|
6
7
|
import {paths,toolCallDeadlineMs,PACKAGE_VERSION} from '../control.mjs';
|
|
7
8
|
|
|
8
9
|
const require=createRequire(import.meta.url);
|
|
@@ -14,6 +15,16 @@ const result=(tool,before,after,outcome,error=null,pid=null,evidence=null)=>({to
|
|
|
14
15
|
// Deadlines bound an individual caller's wait, not a child process' lifetime.
|
|
15
16
|
const timeout=ctx=>Math.max(0,ctx.remaining());
|
|
16
17
|
export const startupHandshakeBudget=ctx=>Math.max(0,ctx.remaining());
|
|
18
|
+
// The Tools-owned Desktop Commander is an ordinary MCP child process of the
|
|
19
|
+
// logged-in macOS account. No synthetic HOME and no GUI Terminal app.
|
|
20
|
+
export function desktopCommanderEnvironment(parent=process.env,account=userInfo()){
|
|
21
|
+
if(!isAbsolute(account?.homedir||'')||!account?.username)
|
|
22
|
+
throw Object.assign(Error('LOCAL_ACCOUNT_UNAVAILABLE'),{code:'LOCAL_ACCOUNT_UNAVAILABLE'});
|
|
23
|
+
return {...parent,HOME:account.homedir,USER:account.username,
|
|
24
|
+
LOGNAME:account.username,
|
|
25
|
+
DESKTOP_COMMANDER_DISABLE_TELEMETRY:'true',DC_REMOTE_DEVICE:'false'};
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
function entryFor(tool){
|
|
18
29
|
if(tool.id!=='desktop-commander')throw Object.assign(Error('Unknown MCP child'),{code:'UNKNOWN_TOOL'});
|
|
19
30
|
const pkg=require.resolve('@wonderwhy-er/desktop-commander/package.json');
|
|
@@ -93,11 +104,10 @@ export function createMcpChildAdapter({records,log},options={}){
|
|
|
93
104
|
if(health.after==='RUNNING')return result(tool,before,'RUNNING','ALREADY_RUNNING',null,old.pid,'MCP_TOOLS_LIST');
|
|
94
105
|
return {...health,outcome:'HEALTH_NOT_CONFIRMED'};
|
|
95
106
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
DC_REMOTE_DEVICE:'false'};
|
|
107
|
+
// Keep the same actual Mac account, HOME, shell services and auth context
|
|
108
|
+
// as the Supervisor. File/command calls no longer resolve inside the
|
|
109
|
+
// Chat Loop-private fake home, and still never launch a GUI Terminal.
|
|
110
|
+
const env=desktopCommanderEnvironment();
|
|
101
111
|
const child=spawnChild(process.execPath,[childEntry(tool),'--no-onboarding'],
|
|
102
112
|
{stdio:['pipe','pipe','pipe'],env,windowsHide:true});
|
|
103
113
|
const rec=setup(tool,child);
|
package/lib/gateway.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import {managedTaskRegistry} from './task-registry-managed.mjs';
|
|
|
9
9
|
import {contextGatewayTools,contextGatewayEnabled,runContextGateway} from './context-gateway.mjs';
|
|
10
10
|
import {runtimeNeedsUpgrade} from './release.mjs';
|
|
11
11
|
import {traceDiagnoseTool,traceGatewayEnabled,runTraceDiagnose,observeExtensionResult} from './trace-gateway.mjs';
|
|
12
|
+
import {isGraphicalTerminalCommand} from './terminal-app-policy.mjs';
|
|
12
13
|
|
|
13
14
|
// Keep the pinned Desktop Commander as the implementation, but expose only
|
|
14
15
|
// the file/search/process API useful to Chat Loop. Hidden tools are NOT routable
|
|
@@ -29,7 +30,7 @@ const desktopDescriptions={
|
|
|
29
30
|
start_search:'Search filenames (searchType=files) or file contents (searchType=content) from an authorized root. Returns a session for paginated results.',
|
|
30
31
|
get_more_search_results:'Get additional results from an existing search session using sessionId and pagination.',
|
|
31
32
|
edit_block:'Apply an exact targeted edit; pass file_path and old_string/new_string for text, or range/content for spreadsheets. Refuse ambiguous replacements.',
|
|
32
|
-
start_process:'Run
|
|
33
|
+
start_process:'Run CLI commands through the MCP process, never launch macOS Terminal/iTerm apps. A PID is not completion; read its output.',
|
|
33
34
|
read_process_output:'Read output of an already-started PID with optional offset/length/timeout_ms. Does not start the command again.',
|
|
34
35
|
interact_with_process:'Send input to an existing interactive PID and obtain output. Do not repeat commands with unknown side effects.',
|
|
35
36
|
get_config:'Read Desktop Commander configuration/allowed directories for diagnosis; does not grant or change permissions.'
|
|
@@ -163,6 +164,9 @@ export function runGateway(){
|
|
|
163
164
|
const args=m.params?.arguments??{};
|
|
164
165
|
if(args===null||typeof args!=='object'||Array.isArray(args))
|
|
165
166
|
return reply(m.id,failure('INVALID_ARGUMENT'));
|
|
167
|
+
if(routed.toolId==='desktop-commander'&&
|
|
168
|
+
isGraphicalTerminalCommand(routed.name,args))
|
|
169
|
+
return reply(m.id,failure('GUI_TERMINAL_LAUNCH_PROHIBITED'));
|
|
166
170
|
try{
|
|
167
171
|
if(routed.toolId==='runtime'){
|
|
168
172
|
if(Object.keys(args).length!==1 || typeof args.requestId!=='string'
|
package/lib/release.mjs
CHANGED
|
@@ -15,7 +15,10 @@ function checkedUpgradeBase(options){
|
|
|
15
15
|
if(options.base!==undefined)return options.base; // Explicit test/API base.
|
|
16
16
|
try{
|
|
17
17
|
const accountHome=userInfo().homedir;
|
|
18
|
-
|
|
18
|
+
// os.homedir() may be cached in a long-running Node process. Verify
|
|
19
|
+
// the live process HOME as well as the account home, no GUI Terminal needed.
|
|
20
|
+
if(homedir()!==accountHome||process.env.HOME&&process.env.HOME!==accountHome)
|
|
21
|
+
return null;
|
|
19
22
|
const currentState=process.env.CHAT_LOOP_LOCAL_TOOLS_STATE_DIR;
|
|
20
23
|
if(currentState&¤tState!==join(accountHome,'.chat-loop','local-tools'))
|
|
21
24
|
return null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Prevent accidental GUI Terminal launches from Chat Loop's local MCP command API.
|
|
2
|
+
// This does not restrict ordinary CLI/shell execution, files, services or directories.
|
|
3
|
+
const terminalApp=String.raw`(?:Terminal|iTerm2?)(?:\.app)?`;
|
|
4
|
+
const appTarget=new RegExp(String.raw`(?:^|\s|\/|["'])${terminalApp}(?:\/|["'\s;]|$)`,'i');
|
|
5
|
+
export function isGraphicalTerminalCommand(toolName,args){
|
|
6
|
+
if(toolName!=='start_process' && toolName!=='interact_with_process')return false;
|
|
7
|
+
const command=toolName==='start_process'?args?.command:args?.input;
|
|
8
|
+
if(typeof command!=='string')return false;
|
|
9
|
+
// open -n -a Terminal / open -a /System/Applications/Utilities/Terminal.app
|
|
10
|
+
const open=/\b(?:\/usr\/bin\/)?open\s+[^;\n|]{0,240}/gi;
|
|
11
|
+
for(const m of command.matchAll(open)){
|
|
12
|
+
if(/(?:^|\s)-a(?:\s|=)/.test(m[0]) && appTarget.test(m[0]))return true;
|
|
13
|
+
}
|
|
14
|
+
// AppleScript calls into Terminal/iTerm and direct .app binary launch.
|
|
15
|
+
if(/\b(?:\/usr\/bin\/)?osascript\b[\s\S]{0,450}\b(?:Terminal|iTerm2?)\b/i.test(command))return true;
|
|
16
|
+
if(/\/(?:Terminal|iTerm2?)\.app\/Contents\/MacOS\//i.test(command))return true;
|
|
17
|
+
return false;
|
|
18
|
+
}
|