@steerable/steer 0.0.0-stage → 0.3.13
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/LICENSE +21 -0
- package/README.md +35 -2
- package/bin/steer.js +2 -0
- package/dist/packages/doc-preview/src/assemble.js +183 -0
- package/dist/packages/doc-preview/src/edit-failure.js +116 -0
- package/dist/packages/doc-preview/src/edit-service.js +879 -0
- package/dist/packages/doc-preview/src/edit.js +437 -0
- package/dist/packages/doc-preview/src/export.js +540 -0
- package/dist/packages/doc-preview/src/index.js +5 -0
- package/dist/packages/doc-preview/src/migrations.js +77 -0
- package/dist/packages/doc-preview/src/office-converter.js +186 -0
- package/dist/packages/doc-preview/src/office-file-preview.js +457 -0
- package/dist/packages/doc-preview/src/office-media.js +80 -0
- package/dist/packages/doc-preview/src/office-raster.js +146 -0
- package/dist/packages/doc-preview/src/office-routes.js +191 -0
- package/dist/packages/doc-preview/src/office-runtime.js +251 -0
- package/dist/packages/doc-preview/src/preview.js +296 -0
- package/dist/packages/doc-preview/src/render.js +351 -0
- package/dist/packages/doc-preview/src/routes.js +376 -0
- package/dist/packages/doc-preview/src/settings.js +58 -0
- package/dist/packages/doc-preview/src/store.js +134 -0
- package/dist/packages/doc-preview/src/tasks.js +16 -0
- package/dist/packages/doc-preview/src/word-font.js +232 -0
- package/dist/packages/doc-preview/src/word-preview.js +292 -0
- package/dist/packages/doc-preview/src/word-render.js +283 -0
- package/dist/packages/doc-preview/src/word-routes.js +203 -0
- package/dist/packages/doc-preview/src/workspace.js +100 -0
- package/dist/products/bundled-python.js +110 -0
- package/dist/products/load-locale.js +38 -0
- package/dist/products/manifest.json +13 -0
- package/dist/products/node-gate.js +132 -0
- package/dist/products/steer/active.js +93 -0
- package/dist/products/steer/browser-detect.js +230 -0
- package/dist/products/steer/browser-protocol.js +2 -0
- package/dist/products/steer/browser-session.js +811 -0
- package/dist/products/steer/browser.js +521 -0
- package/dist/products/steer/cli-main.js +13 -0
- package/dist/products/steer/cli.js +8 -0
- package/dist/products/steer/computer-macos.js +126 -0
- package/dist/products/steer/computer-session.js +118 -0
- package/dist/products/steer/computer.js +186 -0
- package/dist/products/steer/file-preview.js +392 -0
- package/dist/products/steer/locales/shell.zh.json +1120 -0
- package/dist/products/steer/locales/zh.json +95 -0
- package/dist/products/steer/markdown-preview.js +139 -0
- package/dist/products/steer/migrate-legacy-data.js +238 -0
- package/dist/products/steer/permissions.js +174 -0
- package/dist/products/steer/product.json +85 -0
- package/dist/products/steer/server.js +8 -0
- package/dist/products/steer/skill-read.js +105 -0
- package/dist/products/steer/turn-changes.js +187 -0
- package/package.json +38 -4
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Your local personal agent": "你的本地个人 Agent",
|
|
3
|
+
"Type what you want done. It starts on this computer.": "输入你想做的事,直接在这台电脑上开始。",
|
|
4
|
+
"Markdown preview": "Markdown 预览",
|
|
5
|
+
"Close Markdown preview": "关闭 Markdown 预览",
|
|
6
|
+
"Loading Markdown preview…": "正在加载 Markdown 预览…",
|
|
7
|
+
"Could not load Markdown preview.": "Markdown 预览加载失败",
|
|
8
|
+
"This chat has no Markdown files yet.": "本会话还没有 Markdown 文件",
|
|
9
|
+
"Markdown written in this chat shows up here.": "本会话写出的 Markdown 会在这里预览。",
|
|
10
|
+
"This Markdown file is too large to preview.": "这个 Markdown 文件太大,无法预览",
|
|
11
|
+
"This path is not a file.": "这个路径不是文件",
|
|
12
|
+
"Could not read this Markdown file.": "无法读取这个 Markdown 文件",
|
|
13
|
+
"Markdown file": "Markdown 文件",
|
|
14
|
+
"File · {name}": "文件 · {name}",
|
|
15
|
+
"File preview": "文件预览",
|
|
16
|
+
"Close file preview": "关闭文件预览",
|
|
17
|
+
"Open": "打开",
|
|
18
|
+
"Open with default app": "用默认应用打开",
|
|
19
|
+
"Folder": "文件夹",
|
|
20
|
+
"Show in folder": "在文件夹中显示",
|
|
21
|
+
"Copy path": "复制路径",
|
|
22
|
+
"Copy file path": "复制文件路径",
|
|
23
|
+
"Copied": "已复制",
|
|
24
|
+
"Loading file preview…": "正在加载文件预览…",
|
|
25
|
+
"This chat has no previewable files yet.": "本会话还没有可预览的文件",
|
|
26
|
+
"PDF, spreadsheets, and images from this chat show up here.": "本会话写出的 PDF、表格和图片会在这里预览。",
|
|
27
|
+
"Showing the first rows.": "只显示前面的行。",
|
|
28
|
+
"Previous page": "上一页",
|
|
29
|
+
"Next page": "下一页",
|
|
30
|
+
"Changes · {name}": "变更 · {name}",
|
|
31
|
+
"Changes": "变更",
|
|
32
|
+
"Close changes": "关闭变更",
|
|
33
|
+
"Loading changes…": "正在加载变更…",
|
|
34
|
+
"This turn has no code changes.": "这一轮没有代码变更。",
|
|
35
|
+
"Edits from this turn show up here.": "这一轮改过的文件会显示在这里。",
|
|
36
|
+
"Browser · {title}": "浏览器 · {title}",
|
|
37
|
+
"Browser": "浏览器",
|
|
38
|
+
"Close browser": "关闭浏览器",
|
|
39
|
+
"Back": "后退",
|
|
40
|
+
"Forward": "前进",
|
|
41
|
+
"Address": "地址",
|
|
42
|
+
"Enter a web address": "输入网址",
|
|
43
|
+
"Go": "打开",
|
|
44
|
+
"Loading page…": "正在加载页面…",
|
|
45
|
+
"No page open yet.": "还没有打开网页。",
|
|
46
|
+
"Pages opened in this chat show up here.": "这个会话打开的网页会显示在这里。",
|
|
47
|
+
"The agent can control the browser": "智能体可以操作浏览器",
|
|
48
|
+
"You are controlling the browser": "你正在操作浏览器",
|
|
49
|
+
"Open browser window": "打开浏览器窗口",
|
|
50
|
+
"Take control": "我来操作",
|
|
51
|
+
"Return control": "交还智能体",
|
|
52
|
+
"Open the browser window to view this page.": "请打开浏览器窗口查看这个页面。",
|
|
53
|
+
"Enter an http(s) URL.": "请输入 http(s) 地址。",
|
|
54
|
+
"No page is open.": "还没有打开网页。",
|
|
55
|
+
"Nothing to go back to.": "没有上一页。",
|
|
56
|
+
"Nothing to go forward to.": "没有下一页。",
|
|
57
|
+
"Screen · {title}": "屏幕 · {title}",
|
|
58
|
+
"Screen": "屏幕",
|
|
59
|
+
"Close screen": "关闭屏幕",
|
|
60
|
+
"Application": "应用",
|
|
61
|
+
"Allow": "允许",
|
|
62
|
+
"Allow frontmost": "允许当前应用",
|
|
63
|
+
"Loading screen…": "正在加载屏幕…",
|
|
64
|
+
"No app is allowed yet.": "还没有允许的应用。",
|
|
65
|
+
"Allow an application to watch its screen here.": "允许一个应用后,可以在这里看着它的屏幕。",
|
|
66
|
+
"Enter an application id such as com.example.notes.": "请输入应用标识,例如 com.example.notes。",
|
|
67
|
+
"Click coordinates are out of range.": "点击坐标超出范围。",
|
|
68
|
+
"No application is in front.": "当前没有前台应用。",
|
|
69
|
+
"Enter text to type.": "请输入要键入的文字。",
|
|
70
|
+
"That text is too long to type.": "这段文字太长,无法键入。",
|
|
71
|
+
"No application is selected.": "还没有选中应用。",
|
|
72
|
+
"This app has no window to show.": "这个应用没有可显示的窗口。",
|
|
73
|
+
"Could not control this application.": "无法操作这个应用。",
|
|
74
|
+
"Loading browser settings…": "正在加载浏览器设置…",
|
|
75
|
+
"Browser application": "浏览器程序",
|
|
76
|
+
"Choose which Chromium browser the agent launches. Your system default browser (such as Safari) is not affected.": "选择智能体调用的 Chromium 内核浏览器,不影响系统默认浏览器(如 Safari)。",
|
|
77
|
+
"Automatic (prefer Google Chrome)": "自动选择(优先 Google Chrome)",
|
|
78
|
+
"Not installed": "未安装",
|
|
79
|
+
"Custom executable path": "自定义可执行文件路径",
|
|
80
|
+
"Save": "保存",
|
|
81
|
+
"Browser session mode": "浏览器会话模式",
|
|
82
|
+
"Isolated agent browser (default)": "独立工作浏览器(默认)",
|
|
83
|
+
"Starts a dedicated browser profile separate from your personal tabs.": "启动独立的持久化配置目录,与个人日常标签页隔离。",
|
|
84
|
+
"Attach to running browser (reuse signed-in sessions)": "连接当前已打开的浏览器(复用登录态)",
|
|
85
|
+
"Connects over local Chrome DevTools Protocol to reuse your active cookies and SSO without closing your browser.": "通过本机 CDP 协议附着到已运行的浏览器,直接复用已登录的 Cookie 与企业 SSO,退出时不会关闭你的浏览器。",
|
|
86
|
+
"Local CDP endpoint": "本机 CDP 调试端点",
|
|
87
|
+
"Testing…": "正在测试…",
|
|
88
|
+
"Test connection": "测试连接",
|
|
89
|
+
"In Chrome, open chrome://inspect/#remote-debugging to enable local debugging, or launch Chrome with --remote-debugging-port=9222.": "在 Chrome 地址栏打开 chrome://inspect/#remote-debugging 开启本地远程调试,或使用 --remote-debugging-port=9222 启动浏览器。",
|
|
90
|
+
"Connected to {version}": "已连接到 {version}",
|
|
91
|
+
"Connection failed: {error}": "连接失败:{error}",
|
|
92
|
+
"Allow intranet and private network addresses": "允许访问企业内网与局域网地址",
|
|
93
|
+
"Enable this when the agent needs to read internal company portals (10.x, 172.16.x, 192.168.x, or .local). Local host control ports remain blocked.": "需要读取公司内网系统(10.x、172.16.x、192.168.x 或 .local)时开启;本机宿主控制端口与调试端口始终保持拦截。",
|
|
94
|
+
"Browser settings saved.": "浏览器设置已保存。"
|
|
95
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Steer 的 Markdown 预览。只服务本产品:从当前会话已记录的回合产物里
|
|
3
|
+
* 找出 Markdown,读出正文交给右侧栏位。不进框架,其他产品不注册这条路由。
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs/promises';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { matchPackBackendRoute, registerPackBackendRoutes, } from '@steerable/agent-shell/local-backend/pack-backend-routes';
|
|
8
|
+
export const MARKDOWN_PREVIEW_ROUTE = '/api/v2/steer/markdown-preview';
|
|
9
|
+
export const MAX_MARKDOWN_PREVIEW_BYTES = 512 * 1024;
|
|
10
|
+
const MAX_MARKDOWN_PREVIEW_FILES = 20;
|
|
11
|
+
const MARKDOWN_EXTENSIONS = new Set(['.md', '.markdown']);
|
|
12
|
+
/** 绝对路径且扩展名是 Markdown。相对路径不读,避免落到进程工作目录。 */
|
|
13
|
+
export function isMarkdownTurnPath(filePath) {
|
|
14
|
+
if (!filePath || filePath.includes('\0') || !path.isAbsolute(filePath))
|
|
15
|
+
return false;
|
|
16
|
+
return MARKDOWN_EXTENSIONS.has(path.extname(filePath).toLowerCase());
|
|
17
|
+
}
|
|
18
|
+
function turnFilesFromMetadata(raw) {
|
|
19
|
+
if (!raw)
|
|
20
|
+
return [];
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
if (!parsed || typeof parsed !== 'object')
|
|
29
|
+
return [];
|
|
30
|
+
const files = parsed.turnFiles;
|
|
31
|
+
if (!Array.isArray(files))
|
|
32
|
+
return [];
|
|
33
|
+
const found = [];
|
|
34
|
+
for (const item of files) {
|
|
35
|
+
if (!item || typeof item !== 'object')
|
|
36
|
+
continue;
|
|
37
|
+
const filePath = item.path;
|
|
38
|
+
if (typeof filePath !== 'string' || !isMarkdownTurnPath(filePath))
|
|
39
|
+
continue;
|
|
40
|
+
const description = item.description;
|
|
41
|
+
found.push({
|
|
42
|
+
path: path.resolve(filePath),
|
|
43
|
+
...(typeof description === 'string' && description ? { description } : {}),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 会话消息按新到旧排列。同一路径只保留最新一条里的说明。
|
|
50
|
+
*/
|
|
51
|
+
export function listMarkdownTurnFiles(messages) {
|
|
52
|
+
const seen = new Set();
|
|
53
|
+
const files = [];
|
|
54
|
+
for (const message of messages) {
|
|
55
|
+
for (const file of turnFilesFromMetadata(message.messageMetadata)) {
|
|
56
|
+
if (seen.has(file.path))
|
|
57
|
+
continue;
|
|
58
|
+
seen.add(file.path);
|
|
59
|
+
files.push({
|
|
60
|
+
path: file.path,
|
|
61
|
+
name: path.basename(file.path),
|
|
62
|
+
...(file.description ? { description: file.description } : {}),
|
|
63
|
+
});
|
|
64
|
+
if (files.length >= MAX_MARKDOWN_PREVIEW_FILES)
|
|
65
|
+
return files;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return files;
|
|
69
|
+
}
|
|
70
|
+
export async function readMarkdownPreviewFile(filePath, maxBytes = MAX_MARKDOWN_PREVIEW_BYTES) {
|
|
71
|
+
try {
|
|
72
|
+
const stat = await fs.stat(filePath);
|
|
73
|
+
if (!stat.isFile())
|
|
74
|
+
return { size: 0, content: null, error: 'not_a_file' };
|
|
75
|
+
if (stat.size > maxBytes)
|
|
76
|
+
return { size: stat.size, content: null, error: 'too_large' };
|
|
77
|
+
const content = (await fs.readFile(filePath, 'utf8')).replace(/^\uFEFF/, '');
|
|
78
|
+
return { size: stat.size, content };
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return { size: 0, content: null, error: 'read_failed' };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export async function loadMarkdownPreviewFiles(messages, explicitPath) {
|
|
85
|
+
const listed = listMarkdownTurnFiles(messages);
|
|
86
|
+
const files = [];
|
|
87
|
+
for (const file of listed) {
|
|
88
|
+
const read = await readMarkdownPreviewFile(file.path);
|
|
89
|
+
files.push({ ...file, ...read });
|
|
90
|
+
}
|
|
91
|
+
if (!explicitPath || !isMarkdownTurnPath(explicitPath))
|
|
92
|
+
return files;
|
|
93
|
+
const resolved = path.resolve(explicitPath);
|
|
94
|
+
const existing = files.findIndex((file) => file.path === resolved);
|
|
95
|
+
if (existing >= 0) {
|
|
96
|
+
const [chosen] = files.splice(existing, 1);
|
|
97
|
+
files.unshift(chosen);
|
|
98
|
+
return files;
|
|
99
|
+
}
|
|
100
|
+
const read = await readMarkdownPreviewFile(resolved);
|
|
101
|
+
files.unshift({
|
|
102
|
+
path: resolved,
|
|
103
|
+
name: path.basename(resolved),
|
|
104
|
+
...read,
|
|
105
|
+
});
|
|
106
|
+
return files;
|
|
107
|
+
}
|
|
108
|
+
export async function handleSteerMarkdownPreview(query, listMessages) {
|
|
109
|
+
const chatId = query.get('chatId')?.trim() ?? '';
|
|
110
|
+
if (!chatId || chatId.length > 200) {
|
|
111
|
+
return { status: 400, data: { detail: 'chatId is required' } };
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const messages = await listMessages(chatId);
|
|
115
|
+
return {
|
|
116
|
+
status: 200,
|
|
117
|
+
data: { files: await loadMarkdownPreviewFiles(messages, query.get('path')) },
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
122
|
+
return { status: 500, data: { detail } };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** 宿主启动时注册。存储要等 initializeStorage 之后才能用,所以放在请求里再取。 */
|
|
126
|
+
export function registerSteerMarkdownPreview() {
|
|
127
|
+
if (matchPackBackendRoute('GET', MARKDOWN_PREVIEW_ROUTE))
|
|
128
|
+
return;
|
|
129
|
+
registerPackBackendRoutes('steer', MARKDOWN_PREVIEW_ROUTE, [
|
|
130
|
+
{
|
|
131
|
+
method: 'GET',
|
|
132
|
+
path: MARKDOWN_PREVIEW_ROUTE,
|
|
133
|
+
handler: async ({ query }) => {
|
|
134
|
+
const { getScopedStore, LOCAL_SCOPE } = await import('@steerable/agent-shell/storage/driver');
|
|
135
|
+
return handleSteerMarkdownPreview(query, (chatId) => getScopedStore(LOCAL_SCOPE).listMessages(chatId, 200));
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 启动期自动迁移旧版 Aroli 用户数据目录(`~/.aroli` → `~/.steer`)与 CLI 会话库
|
|
3
|
+
* (`~/.steerable/sessions-aroli.db` → `~/.steerable/sessions-steer.db`)。
|
|
4
|
+
*
|
|
5
|
+
* 采用非破坏式复制(保留原 `~/.aroli` 不删除):
|
|
6
|
+
* - 显式指定 `DEEPPATH_USER_DATA_DIR` 指向其他隔离目录(测试、dev:bs、Arena 等)时跳过;
|
|
7
|
+
* - 若 `~/.steer/steer.db` 或 `~/.steer/.migrated-from-aroli` 已存在,跳过目录迁移;
|
|
8
|
+
* - 跳过锁文件、宿主瞬态文件与 Chromium 进程套接字,避免运行态文件阻塞拷贝;
|
|
9
|
+
* - 自动重写 `python-runner/config.json` 中指向 `~/.aroli` 的解释器路径。
|
|
10
|
+
*/
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
export const LEGACY_MIGRATION_MARKER = '.migrated-from-aroli';
|
|
15
|
+
const SKIPPED_TOP_LEVEL_NAMES = new Set([
|
|
16
|
+
'locks',
|
|
17
|
+
'host-ready.json',
|
|
18
|
+
'host-spawn.txt',
|
|
19
|
+
'host-error.txt',
|
|
20
|
+
'host-runtime.json',
|
|
21
|
+
'host-node.log',
|
|
22
|
+
]);
|
|
23
|
+
const SKIPPED_BROWSER_SINGLETONS = new Set([
|
|
24
|
+
'SingletonLock',
|
|
25
|
+
'SingletonSocket',
|
|
26
|
+
'SingletonCookie',
|
|
27
|
+
]);
|
|
28
|
+
const PRIORITY_TOP_LEVEL_ORDER = [
|
|
29
|
+
'aroli.db',
|
|
30
|
+
'aroli.db-wal',
|
|
31
|
+
'aroli.db-shm',
|
|
32
|
+
'config.json',
|
|
33
|
+
'aroli-browser-settings.json',
|
|
34
|
+
'zoom.json',
|
|
35
|
+
'sidecar',
|
|
36
|
+
'skills',
|
|
37
|
+
'files',
|
|
38
|
+
'deliverables',
|
|
39
|
+
'memories',
|
|
40
|
+
'python-runner',
|
|
41
|
+
];
|
|
42
|
+
function resolveHomeDir(options) {
|
|
43
|
+
if (options.homeDir?.trim())
|
|
44
|
+
return options.homeDir.trim();
|
|
45
|
+
const env = options.env ?? process.env;
|
|
46
|
+
const fromEnv = process.platform === 'win32'
|
|
47
|
+
? env.USERPROFILE || env.HOME
|
|
48
|
+
: env.HOME || env.USERPROFILE;
|
|
49
|
+
return fromEnv?.trim() || os.homedir();
|
|
50
|
+
}
|
|
51
|
+
function shouldSkipRelativeEntry(relPosix, baseName) {
|
|
52
|
+
if (baseName.endsWith('.lock'))
|
|
53
|
+
return true;
|
|
54
|
+
if (SKIPPED_BROWSER_SINGLETONS.has(baseName))
|
|
55
|
+
return true;
|
|
56
|
+
if (!relPosix.includes('/') && SKIPPED_TOP_LEVEL_NAMES.has(baseName))
|
|
57
|
+
return true;
|
|
58
|
+
if (relPosix === 'sidecar/tmp' || relPosix.startsWith('sidecar/tmp/'))
|
|
59
|
+
return true;
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
function mapLegacyRelativePath(relPosix) {
|
|
63
|
+
switch (relPosix) {
|
|
64
|
+
case 'aroli.db':
|
|
65
|
+
return 'steer.db';
|
|
66
|
+
case 'aroli.db-wal':
|
|
67
|
+
return 'steer.db-wal';
|
|
68
|
+
case 'aroli.db-shm':
|
|
69
|
+
return 'steer.db-shm';
|
|
70
|
+
case 'aroli-browser-settings.json':
|
|
71
|
+
return 'steer-browser-settings.json';
|
|
72
|
+
case 'sidecar/sessions-aroli.db':
|
|
73
|
+
return 'sidecar/sessions-steer.db';
|
|
74
|
+
case 'sidecar/sessions-aroli.db-wal':
|
|
75
|
+
return 'sidecar/sessions-steer.db-wal';
|
|
76
|
+
case 'sidecar/sessions-aroli.db-shm':
|
|
77
|
+
return 'sidecar/sessions-steer.db-shm';
|
|
78
|
+
default:
|
|
79
|
+
return relPosix;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function rewriteLegacyPrefix(value, legacyRoot, targetRoot) {
|
|
83
|
+
for (const sep of [path.sep, '/', '\\']) {
|
|
84
|
+
const prefix = `${legacyRoot}${sep}`;
|
|
85
|
+
if (value.startsWith(prefix)) {
|
|
86
|
+
return `${targetRoot}${sep}${value.slice(prefix.length)}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (value === legacyRoot)
|
|
90
|
+
return targetRoot;
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
function copyTreeNonDestructive(legacyRoot, targetRoot, relPosix = '') {
|
|
94
|
+
const srcDir = relPosix ? path.join(legacyRoot, ...relPosix.split('/')) : legacyRoot;
|
|
95
|
+
let entries;
|
|
96
|
+
try {
|
|
97
|
+
entries = fs.readdirSync(srcDir);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!relPosix) {
|
|
103
|
+
const rank = new Map(PRIORITY_TOP_LEVEL_ORDER.map((name, idx) => [name, idx]));
|
|
104
|
+
entries.sort((a, b) => {
|
|
105
|
+
const ra = rank.get(a) ?? PRIORITY_TOP_LEVEL_ORDER.length;
|
|
106
|
+
const rb = rank.get(b) ?? PRIORITY_TOP_LEVEL_ORDER.length;
|
|
107
|
+
return ra !== rb ? ra - rb : a.localeCompare(b);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
for (const name of entries) {
|
|
111
|
+
const childRelPosix = relPosix ? `${relPosix}/${name}` : name;
|
|
112
|
+
if (shouldSkipRelativeEntry(childRelPosix, name))
|
|
113
|
+
continue;
|
|
114
|
+
const mappedRelPosix = mapLegacyRelativePath(childRelPosix);
|
|
115
|
+
const srcPath = path.join(legacyRoot, ...childRelPosix.split('/'));
|
|
116
|
+
const destPath = path.join(targetRoot, ...mappedRelPosix.split('/'));
|
|
117
|
+
let stat;
|
|
118
|
+
try {
|
|
119
|
+
stat = fs.lstatSync(srcPath);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (stat.isSymbolicLink()) {
|
|
125
|
+
try {
|
|
126
|
+
if (fs.existsSync(destPath))
|
|
127
|
+
continue;
|
|
128
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
129
|
+
const linkTarget = fs.readlinkSync(srcPath);
|
|
130
|
+
const rewrittenTarget = rewriteLegacyPrefix(linkTarget, legacyRoot, targetRoot);
|
|
131
|
+
fs.symlinkSync(rewrittenTarget, destPath);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// 忽略单个损坏软链(如残留浏览器锁)
|
|
135
|
+
}
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (stat.isDirectory()) {
|
|
139
|
+
try {
|
|
140
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
copyTreeNonDestructive(legacyRoot, targetRoot, childRelPosix);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (stat.isFile()) {
|
|
149
|
+
try {
|
|
150
|
+
if (fs.existsSync(destPath))
|
|
151
|
+
continue;
|
|
152
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
153
|
+
fs.copyFileSync(srcPath, destPath);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// 单个缓存文件不可读时不阻断主库与配置迁移
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function rewritePythonRunnerConfig(legacyRoot, targetRoot) {
|
|
162
|
+
const configPath = path.join(targetRoot, 'python-runner', 'config.json');
|
|
163
|
+
if (!fs.existsSync(configPath))
|
|
164
|
+
return;
|
|
165
|
+
try {
|
|
166
|
+
const raw = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
167
|
+
let changed = false;
|
|
168
|
+
for (const key of ['runner', 'path']) {
|
|
169
|
+
const val = raw[key];
|
|
170
|
+
if (typeof val === 'string') {
|
|
171
|
+
const next = rewriteLegacyPrefix(val, legacyRoot, targetRoot);
|
|
172
|
+
if (next !== val) {
|
|
173
|
+
raw[key] = next;
|
|
174
|
+
changed = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (changed) {
|
|
179
|
+
fs.writeFileSync(configPath, `${JSON.stringify(raw, null, 2)}\n`, 'utf8');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// 非法 JSON 留给 python-runner 自身恢复逻辑处理
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function migrateSharedSteerableSidecarDb(homeDir) {
|
|
187
|
+
const steerableDir = path.join(homeDir, '.steerable');
|
|
188
|
+
const legacyDb = path.join(steerableDir, 'sessions-aroli.db');
|
|
189
|
+
const targetDb = path.join(steerableDir, 'sessions-steer.db');
|
|
190
|
+
if (!fs.existsSync(legacyDb) || fs.existsSync(targetDb))
|
|
191
|
+
return false;
|
|
192
|
+
try {
|
|
193
|
+
for (const suffix of ['', '-wal', '-shm']) {
|
|
194
|
+
const src = `${legacyDb}${suffix}`;
|
|
195
|
+
const dst = `${targetDb}${suffix}`;
|
|
196
|
+
if (fs.existsSync(src) && !fs.existsSync(dst)) {
|
|
197
|
+
fs.copyFileSync(src, dst);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return fs.existsSync(targetDb);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export function migrateLegacyAroliData(options = {}) {
|
|
207
|
+
const env = options.env ?? process.env;
|
|
208
|
+
const homeDir = resolveHomeDir(options);
|
|
209
|
+
if (!homeDir) {
|
|
210
|
+
return { migratedUserData: false, migratedSharedSidecarDb: false };
|
|
211
|
+
}
|
|
212
|
+
const legacyDir = path.join(homeDir, '.aroli');
|
|
213
|
+
const targetDir = path.join(homeDir, '.steer');
|
|
214
|
+
const explicitDataDir = env.DEEPPATH_USER_DATA_DIR?.trim();
|
|
215
|
+
if (explicitDataDir && path.resolve(explicitDataDir) !== path.resolve(targetDir)) {
|
|
216
|
+
return { migratedUserData: false, migratedSharedSidecarDb: false };
|
|
217
|
+
}
|
|
218
|
+
let migratedUserData = false;
|
|
219
|
+
const markerPath = path.join(targetDir, LEGACY_MIGRATION_MARKER);
|
|
220
|
+
const targetDbPath = path.join(targetDir, 'steer.db');
|
|
221
|
+
try {
|
|
222
|
+
const legacyStat = fs.existsSync(legacyDir) ? fs.statSync(legacyDir) : null;
|
|
223
|
+
if (legacyStat?.isDirectory() &&
|
|
224
|
+
!fs.existsSync(markerPath) &&
|
|
225
|
+
!fs.existsSync(targetDbPath)) {
|
|
226
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
227
|
+
copyTreeNonDestructive(legacyDir, targetDir);
|
|
228
|
+
rewritePythonRunnerConfig(legacyDir, targetDir);
|
|
229
|
+
fs.writeFileSync(markerPath, `${JSON.stringify({ migratedAt: new Date().toISOString(), from: legacyDir })}\n`, 'utf8');
|
|
230
|
+
migratedUserData = true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// 迁移失败不阻断应用启动
|
|
235
|
+
}
|
|
236
|
+
const migratedSharedSidecarDb = migrateSharedSteerableSidecarDb(homeDir);
|
|
237
|
+
return { migratedUserData, migratedSharedSidecarDb };
|
|
238
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Steer 的回合中权限申请。
|
|
3
|
+
* 审批卡先看到同样的路径和理由;用户允许之后,这个会话后面的回合把目录放进可写根。
|
|
4
|
+
* 本回合开始时已经定下的系统沙箱不会中途改写。
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { getPackAssemblies, registerPackAssembly, } from '@steerable/agent-shell/host/pack-assembly';
|
|
9
|
+
import { registerPackTurnHooks } from '@steerable/agent-shell/local-backend/pack-turn-hooks';
|
|
10
|
+
import { isProductApprovalEnabled } from '@steerable/agent-shell/host-tools-runtime';
|
|
11
|
+
const ALLOWED = new Set(['allow_once', 'allow_for_session', 'allow_always']);
|
|
12
|
+
const MAX_PATHS = 8;
|
|
13
|
+
const MAX_REASON = 500;
|
|
14
|
+
const grants = new Map();
|
|
15
|
+
let hooksReady = false;
|
|
16
|
+
function ensureHooks() {
|
|
17
|
+
if (hooksReady)
|
|
18
|
+
return;
|
|
19
|
+
hooksReady = true;
|
|
20
|
+
registerPackTurnHooks('steer-permissions', {
|
|
21
|
+
execWritableRoots: (chatId) => grantedPaths(chatId),
|
|
22
|
+
worldState: (chatId) => {
|
|
23
|
+
const paths = grantedPaths(chatId);
|
|
24
|
+
const network = grants.get(chatId)?.network === true;
|
|
25
|
+
if (paths.length === 0 && !network)
|
|
26
|
+
return {};
|
|
27
|
+
return { steer_permissions: { paths, network } };
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function grantedPaths(chatId) {
|
|
32
|
+
return [...(grants.get(chatId)?.paths ?? [])];
|
|
33
|
+
}
|
|
34
|
+
/** 审批卡上的那一份申请。字段和宿主审批请求一致。 */
|
|
35
|
+
export function permissionCardPayload(request) {
|
|
36
|
+
return {
|
|
37
|
+
toolName: 'request_permissions',
|
|
38
|
+
arguments: {
|
|
39
|
+
paths: [...request.paths],
|
|
40
|
+
network: request.network,
|
|
41
|
+
reason: request.reason,
|
|
42
|
+
},
|
|
43
|
+
mode: 'other',
|
|
44
|
+
category: 'request_permissions',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function readRequest(args) {
|
|
48
|
+
const paths = Array.isArray(args.paths)
|
|
49
|
+
? args.paths.filter((item) => typeof item === 'string')
|
|
50
|
+
: [];
|
|
51
|
+
return {
|
|
52
|
+
paths,
|
|
53
|
+
network: args.network === true,
|
|
54
|
+
reason: typeof args.reason === 'string' ? args.reason.trim() : '',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function acceptPaths(paths) {
|
|
58
|
+
if (paths.length > MAX_PATHS)
|
|
59
|
+
return { error: `Ask for at most ${MAX_PATHS} directories.` };
|
|
60
|
+
const accepted = [];
|
|
61
|
+
for (const raw of paths) {
|
|
62
|
+
if (!path.isAbsolute(raw))
|
|
63
|
+
return { error: `Directory must be absolute: ${raw}` };
|
|
64
|
+
let real;
|
|
65
|
+
try {
|
|
66
|
+
real = await fs.realpath(raw);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
70
|
+
return { error: message || `Cannot use ${raw}` };
|
|
71
|
+
}
|
|
72
|
+
const info = await fs.stat(real);
|
|
73
|
+
if (!info.isDirectory())
|
|
74
|
+
return { error: `That path is not a directory: ${real}` };
|
|
75
|
+
if (real === path.parse(real).root)
|
|
76
|
+
return { error: 'Refusing to grant the filesystem root.' };
|
|
77
|
+
if (!accepted.includes(real))
|
|
78
|
+
accepted.push(real);
|
|
79
|
+
}
|
|
80
|
+
return accepted;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 按审批卡的决定记下或拒绝这次申请。
|
|
84
|
+
* 允许之后,后续回合的可写根包含这些目录。
|
|
85
|
+
*/
|
|
86
|
+
export async function applyPermissionDecision(chatId, request, decision) {
|
|
87
|
+
const card = permissionCardPayload(request);
|
|
88
|
+
if (!ALLOWED.has(decision.kind)) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: 'The approval card denied this permission request.',
|
|
92
|
+
card,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (!request.reason)
|
|
96
|
+
return { success: false, error: 'Say why this permission is needed.', card };
|
|
97
|
+
if (request.reason.length > MAX_REASON) {
|
|
98
|
+
return { success: false, error: 'That reason is too long.', card };
|
|
99
|
+
}
|
|
100
|
+
if (request.paths.length === 0 && !request.network) {
|
|
101
|
+
return { success: false, error: 'Ask for a directory or network access.', card };
|
|
102
|
+
}
|
|
103
|
+
const accepted = await acceptPaths(request.paths);
|
|
104
|
+
if (!Array.isArray(accepted))
|
|
105
|
+
return { success: false, error: accepted.error, card };
|
|
106
|
+
ensureHooks();
|
|
107
|
+
const previous = grants.get(chatId);
|
|
108
|
+
const paths = [...(previous?.paths ?? [])];
|
|
109
|
+
for (const dir of accepted) {
|
|
110
|
+
if (!paths.includes(dir))
|
|
111
|
+
paths.push(dir);
|
|
112
|
+
}
|
|
113
|
+
const network = request.network || previous?.network === true;
|
|
114
|
+
grants.set(chatId, { paths, network });
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
paths,
|
|
118
|
+
network,
|
|
119
|
+
note: 'These directories are writable on later turns in this chat. This turn keeps the sandbox it started with.',
|
|
120
|
+
card,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export function createSteerPermissionTools() {
|
|
124
|
+
return [
|
|
125
|
+
{
|
|
126
|
+
name: 'request_permissions',
|
|
127
|
+
description: 'Ask the user for extra directories when the current sandbox cannot write there. '
|
|
128
|
+
+ 'The approval card shows the paths and the reason. '
|
|
129
|
+
+ 'After they allow it, later turns in this chat can write those directories. '
|
|
130
|
+
+ 'This turn keeps the sandbox it started with. Network is already available.',
|
|
131
|
+
mode: 'local',
|
|
132
|
+
inputSchema: {
|
|
133
|
+
type: 'object',
|
|
134
|
+
properties: {
|
|
135
|
+
paths: {
|
|
136
|
+
type: 'array',
|
|
137
|
+
items: { type: 'string' },
|
|
138
|
+
description: 'Absolute directories to write. At most 8.',
|
|
139
|
+
},
|
|
140
|
+
network: {
|
|
141
|
+
type: 'boolean',
|
|
142
|
+
description: 'Whether the request includes network access.',
|
|
143
|
+
},
|
|
144
|
+
reason: { type: 'string', description: 'Why this access is needed. Shown on the approval card.' },
|
|
145
|
+
},
|
|
146
|
+
required: ['reason'],
|
|
147
|
+
additionalProperties: false,
|
|
148
|
+
},
|
|
149
|
+
handler: async (args, context) => {
|
|
150
|
+
if (!context.chatId)
|
|
151
|
+
return { success: false, error: 'No chat is open.' };
|
|
152
|
+
if (!isProductApprovalEnabled()) {
|
|
153
|
+
return { success: false, error: 'Permission requests need the approval card.' };
|
|
154
|
+
}
|
|
155
|
+
return applyPermissionDecision(context.chatId, readRequest(args), { kind: 'allow_once' });
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
export function assembleSteerPermissions(deps) {
|
|
161
|
+
ensureHooks();
|
|
162
|
+
deps.registerTools(createSteerPermissionTools());
|
|
163
|
+
}
|
|
164
|
+
/** 宿主启动时注册。重复调用安全。 */
|
|
165
|
+
export function registerSteerPermissions() {
|
|
166
|
+
ensureHooks();
|
|
167
|
+
if (getPackAssemblies().has('steer-permissions'))
|
|
168
|
+
return;
|
|
169
|
+
registerPackAssembly('steer-permissions', assembleSteerPermissions);
|
|
170
|
+
}
|
|
171
|
+
/** 测试收尾:清掉已同意的目录。 */
|
|
172
|
+
export function resetSteerPermissionsForTests() {
|
|
173
|
+
grants.clear();
|
|
174
|
+
}
|