Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote-agent): 沙箱 glob 按字面保留本机目录名,POSIX 上不保留 Windows 网络路径

fmfsaisai5e8d00ecbcba
diff --git a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts b/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts
index 6ec240c642..1e0b7ef4f8 100644
--- a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts
+++ b/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts
@@ -148,9 +148,14 @@ function asJsonRecord(value: unknown): JsonRecord | null {
return value && typeof value === 'object' && !Array.isArray(value) ? value as JsonRecord : null;
}
-/** 本机能用的绝对路径:任务电脑是 Windows 时必须带盘符或是 UNC,`/Users/…` 这类 POSIX 路径不算。 */
+/**
+ * 本机能用的绝对路径:任务电脑是 Windows 时必须带盘符或是 UNC,以 `/` 开头的 POSIX 路径不算;
+ * 是 POSIX 时 `//server/share` 是 Windows 网络路径(本机 exec-server 不认带主机名的 file URI),也不算。
+ */
function isLocalAbsolutePath(value: string): boolean {
- return process.platform === 'win32' ? /^(?:[A-Za-z]:[\\/]|[\\/]{2}[^\\/])/.test(value) : path.posix.isAbsolute(value);
+ return process.platform === 'win32'
+ ? /^(?:[A-Za-z]:[\\/]|[\\/]{2}[^\\/])/.test(value)
+ : path.posix.isAbsolute(value) && !/^[\\/]{2}/.test(value);
}
/** Agent 发来的 file URI 还原成它那边的路径写法(`file:///C:/x` → `C:/x`,UNC 带回主机名)。 */
@@ -205,7 +210,7 @@ function mapSandboxEntry(entry: unknown, workspace: ExecutorWorkspace): unknown[
return deny && agentPath !== null && isLocalAbsolutePath(agentPath) ? [entry] : [];
}
if (target.type === 'glob_pattern' && typeof target.pattern === 'string' && /^(?:[A-Za-z]:|[\\/])/.test(target.pattern)) {
- const local = workspace.localPathFromAgent(target.pattern);
+ const local = workspace.localGlobFromAgent(target.pattern);
if (local !== null) return [{ ...record, path: { ...target, pattern: local } }];
return deny && isLocalAbsolutePath(target.pattern) ? [entry] : [];
}
diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts
index 09239134fe..dac8485fa9 100644
--- a/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts
+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts
@@ -422,6 +422,9 @@ describe('virtual workspace', () => {
{ path: { type: 'path', path: 'file:///C:/Agent/codex-home/memories' }, access: 'write' },
{ path: { type: 'glob_pattern', pattern: 'C:\\Agent\\codex-home\\**' }, access: 'write' },
{ path: { type: 'path', path: 'file:///C:/Agent/secrets' }, access: 'deny' },
+ // Windows 网络路径:POSIX 本机的 exec-server 不认带主机名的 file URI,留下会让每条命令都被拒。
+ { path: { type: 'path', path: 'file://server/share/secret' }, access: 'deny' },
+ { path: { type: 'glob_pattern', pattern: '\\\\server\\share\\**' }, access: 'deny' },
] } },
cwd: 'file:///C:/Agent/mirror/workspace',
policyContext: { cwd: 'file:///C:/Agent/mirror/workspace', workspaceRoots: ['file:///C:/Agent/mirror/workspace', 'file:///C:/Agent/other'] },
@@ -436,7 +439,7 @@ describe('virtual workspace', () => {
{ path: { type: 'special', value: { kind: 'root' } }, access: 'read' },
{ path: { type: 'path', path: local(project) }, access: 'write' },
{ path: { type: 'path', path: local(path.join(project, '.git')) }, access: 'read' },
- { path: { type: 'glob_pattern', pattern: path.join(project, '**', '*.env') }, access: 'deny' },
+ { path: { type: 'glob_pattern', pattern: project + '/**/*.env' }, access: 'deny' },
{ path: { type: 'glob_pattern', pattern: '**/*.pem' }, access: 'deny' },
] } },
cwd: local(project),
@@ -449,6 +452,20 @@ describe('virtual workspace', () => {
expect(read.sandbox).toEqual(params.sandbox);
});
+ it('keeps glob characters in the local directory name literal when mapping absolute sandbox globs', () => {
+ const project = path.join(root, 'project[1]{a}');
+ fs.mkdirSync(project);
+ const workspace = new ExecutorWorkspace({ workingDir: project, aliases: [{ from: 'C:\\Agent\\mirror\\workspace', to: project }] });
+ workspace.setVirtualRoot('C:\\Agent\\mirror');
+ const literal = path.join(root, 'project[[]1[]][{]a[}]');
+ expect(workspace.localGlobFromAgent('C:\\Agent\\mirror\\workspace\\**\\*.env')).toBe(literal + '/**/*.env');
+ expect(workspace.localGlobFromAgent('C:\\Agent\\mirror\\workspace')).toBe(literal);
+ expect(workspace.localGlobFromAgent('C:\\Agent\\other\\**')).toBeNull();
+ // POSIX Agent 的模式里反斜杠是转义,不能当成分隔符。
+ const posix = new ExecutorWorkspace({ workingDir: project, aliases: [{ from: '/home/agent/workspace', to: project }] });
+ expect(posix.localGlobFromAgent('/home/agent/workspace/\\*.lock')).toBe(literal + '/\\*.lock');
+ });
+
it('maps Codex sandbox permissions from a POSIX agent and keeps deny rules that are valid on this computer', async () => {
const { workspace, project, executor } = setup('/home/agent/workspace');
const sandbox = {
diff --git a/apps/desktop/src/main/remote-agent/executor/workspace.ts b/apps/desktop/src/main/remote-agent/executor/workspace.ts
index d9493c3002..e86e2a3bc0 100644
--- a/apps/desktop/src/main/remote-agent/executor/workspace.ts
+++ b/apps/desktop/src/main/remote-agent/executor/workspace.ts
@@ -605,6 +605,22 @@ export class ExecutorWorkspace {
return null;
}
+ /**
+ * Agent 给的绝对 glob:影子前缀换成本机目录,目录名里的通配字符写成字符类按字面匹配(`[` → `[[]`,
+ * 两种路径约定都认);前缀后面的模式保持 Agent 的写法,POSIX 模式里的反斜杠转义不当成分隔符。
+ */
+ localGlobFromAgent(pattern: string): string | null {
+ for (const alias of this.aliases) {
+ if (stripAliasPrefix(pattern, alias.from) === null) continue;
+ const from = alias.from.replace(/[\\/]+$/, '');
+ const rest = pattern.slice(from.length).replace(/^[\\/]/, '');
+ const base = alias.to.replace(/[\\/]+$/, '').replace(/[*?[\]{}]/g, (char) => `[${char}]`);
+ if (!rest) return base;
+ return `${base}/${WINDOWS_PATH.test(from) ? rest.replace(/\\/g, '/') : rest}`;
+ }
+ return null;
+ }
+
/** 本机真实路径投影到 Agent 主机上的路径;仅匹配完整路径段。 */
toAgentPath(input: string): string {
if (!this.virtualRoot) return input;