@steerable/steer 0.3.23 → 0.3.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 +1 -1
- package/dist/packages/doc-preview/src/office-routes.js +1 -1
- package/dist/products/steer/file-preview.js +27 -4
- package/dist/products/steer/locales/shell.zh.json +32 -1
- package/dist/products/steer/markdown-preview.js +19 -3
- package/dist/products/steer/turn-changes.js +191 -56
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @steerable/steer
|
|
2
2
|
|
|
3
|
-
Official command-line interface and terminal TUI (`steer`) for [Steer Agent](https://steeragent.app) (v0.3.
|
|
3
|
+
Official command-line interface and terminal TUI (`steer`) for [Steer Agent](https://steeragent.app) (v0.3.26).
|
|
4
4
|
|
|
5
5
|
Runs directly on macOS, Linux (`x64` / `arm64`), and Windows — including headless SSH servers — and automatically pulls the portable Python sidecar runtime for your platform. When installed alongside the Steer desktop app, `steer` shares the same local `~/.steer` workspace history, skills, and model configuration.
|
|
6
6
|
|
|
@@ -144,7 +144,7 @@ export async function handleOfficePreviewRaw(query, deps) {
|
|
|
144
144
|
}
|
|
145
145
|
export function createOfficePreviewRoutes() {
|
|
146
146
|
const deps = {
|
|
147
|
-
listMessages: (chatId) => getScopedStore(LOCAL_SCOPE).listMessages(chatId,
|
|
147
|
+
listMessages: (chatId) => getScopedStore(LOCAL_SCOPE).listMessages(chatId, 2000),
|
|
148
148
|
};
|
|
149
149
|
return [
|
|
150
150
|
{
|
|
@@ -27,6 +27,7 @@ const IMAGE_MIME = {
|
|
|
27
27
|
'.jpeg': 'image/jpeg',
|
|
28
28
|
'.webp': 'image/webp',
|
|
29
29
|
'.gif': 'image/gif',
|
|
30
|
+
'.svg': 'image/svg+xml',
|
|
30
31
|
};
|
|
31
32
|
const RAW_MIME = {
|
|
32
33
|
...IMAGE_MIME,
|
|
@@ -68,14 +69,27 @@ export function parseDelimitedTable(text, delimiter, limits = { maxRows: MAX_TAB
|
|
|
68
69
|
const header = records[0] ?? [];
|
|
69
70
|
const columns = header.slice(0, limits.maxCols);
|
|
70
71
|
const body = records.slice(1);
|
|
71
|
-
|
|
72
|
+
let maxRowCols = header.length;
|
|
73
|
+
for (const row of body) {
|
|
74
|
+
if (row.length > maxRowCols)
|
|
75
|
+
maxRowCols = row.length;
|
|
76
|
+
}
|
|
77
|
+
const truncated = body.length > limits.maxRows ||
|
|
78
|
+
header.length > limits.maxCols ||
|
|
79
|
+
body.some((row) => row.length > limits.maxCols);
|
|
72
80
|
const rows = body.slice(0, limits.maxRows).map((row) => {
|
|
73
81
|
const cells = row.slice(0, limits.maxCols);
|
|
74
82
|
while (cells.length < columns.length)
|
|
75
83
|
cells.push('');
|
|
76
84
|
return cells;
|
|
77
85
|
});
|
|
78
|
-
return {
|
|
86
|
+
return {
|
|
87
|
+
columns,
|
|
88
|
+
rows,
|
|
89
|
+
totalRows: body.length,
|
|
90
|
+
totalColumns: maxRowCols,
|
|
91
|
+
truncated,
|
|
92
|
+
};
|
|
79
93
|
}
|
|
80
94
|
function parseRecords(text, delimiter) {
|
|
81
95
|
const normalized = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
@@ -291,7 +305,16 @@ export async function loadFilePreview(input) {
|
|
|
291
305
|
const table = parseDelimitedTable(text, delimiter);
|
|
292
306
|
return {
|
|
293
307
|
status: 200,
|
|
294
|
-
data: {
|
|
308
|
+
data: {
|
|
309
|
+
file: {
|
|
310
|
+
kind: 'sheet',
|
|
311
|
+
fileName,
|
|
312
|
+
path: realPath,
|
|
313
|
+
size,
|
|
314
|
+
rawPath: rawPreviewPath(chatId, realPath),
|
|
315
|
+
...table,
|
|
316
|
+
},
|
|
317
|
+
},
|
|
295
318
|
};
|
|
296
319
|
}
|
|
297
320
|
if (!workbookKind(realPath)) {
|
|
@@ -372,7 +395,7 @@ export function registerSteerFilePreview() {
|
|
|
372
395
|
return;
|
|
373
396
|
const listMessages = async (chatId) => {
|
|
374
397
|
const { getScopedStore, LOCAL_SCOPE } = await import('@steerable/agent-shell/storage/driver');
|
|
375
|
-
const messages = await getScopedStore(LOCAL_SCOPE).listMessages(chatId,
|
|
398
|
+
const messages = await getScopedStore(LOCAL_SCOPE).listMessages(chatId, 2000);
|
|
376
399
|
return messages.map((message) => ({
|
|
377
400
|
messageMetadata: typeof message.messageMetadata === 'string' ? message.messageMetadata : null,
|
|
378
401
|
}));
|
|
@@ -894,6 +894,7 @@
|
|
|
894
894
|
"Turns off the command sandbox so any path on this computer can be written. Tool approvals still apply.": "关闭命令沙箱,可写本机任意路径。工具审批仍然生效。",
|
|
895
895
|
"Command sandbox": "命令沙箱",
|
|
896
896
|
"Failed to open": "打开失败",
|
|
897
|
+
"Failed to open file": "打开文件失败",
|
|
897
898
|
"{path} ({error})": "{path}({error})",
|
|
898
899
|
"Click to open {path}": "点击打开 {path}",
|
|
899
900
|
"The last reply was interrupted because the app quit or crashed, so it did not finish.": "上次回复因应用退出或异常中断,未能完成。",
|
|
@@ -1312,5 +1313,35 @@
|
|
|
1312
1313
|
"Usage: /refine <preference or project rule to remember>": "用法:/refine <要记住的个人偏好或项目规范>",
|
|
1313
1314
|
"This memory rule was previously withdrawn or conflicts with manual edits.": "该记忆条目曾被撤回,或与手动编辑内容存在冲突。",
|
|
1314
1315
|
"Select project workspace": "选择项目工作区",
|
|
1315
|
-
"Unlinked workspace (default)": "未关联项目工作区(默认)"
|
|
1316
|
+
"Unlinked workspace (default)": "未关联项目工作区(默认)",
|
|
1317
|
+
"Fit window": "适应窗口",
|
|
1318
|
+
"Fit width": "适合宽度",
|
|
1319
|
+
"Toggle fit window / fit width / 100%": "切换适应窗口 / 适合宽度 / 100%",
|
|
1320
|
+
"Backdrop: Checkerboard": "底纹:透明棋盘格",
|
|
1321
|
+
"Backdrop: Light": "底纹:浅色",
|
|
1322
|
+
"Backdrop: Dark": "底纹:深色",
|
|
1323
|
+
"Switch image backdrop": "切换图片背景底纹",
|
|
1324
|
+
"rows": "行",
|
|
1325
|
+
"cols": "列",
|
|
1326
|
+
"sheets": "张工作表",
|
|
1327
|
+
"Read-only cached values": "只读缓存结果",
|
|
1328
|
+
"Outline": "目录",
|
|
1329
|
+
"Toggle document outline": "展开或收起文档目录大纲",
|
|
1330
|
+
"Rendered": "预览",
|
|
1331
|
+
"Source": "源码",
|
|
1332
|
+
"Show rendered Markdown": "查看渲染后的 Markdown 排版",
|
|
1333
|
+
"Show Markdown source": "查看带行号的原始 Markdown 源码",
|
|
1334
|
+
"Copy Markdown": "复制全文",
|
|
1335
|
+
"Copy Markdown content": "复制 Markdown 原文",
|
|
1336
|
+
"Wrap lines": "自动换行",
|
|
1337
|
+
"Changed file": "变更文件",
|
|
1338
|
+
"Collapse all": "收起全部",
|
|
1339
|
+
"Connect a model API key to get started": "先配置模型 API Key 即可开始对话",
|
|
1340
|
+
"Paste a DeepSeek, OpenAI, or Claude key, or switch to local Ollama. Stored on this device only.": "支持 DeepSeek、OpenAI、Claude 等密钥或切换本地免密 Ollama,密钥仅保存在本机。",
|
|
1341
|
+
"No model API key configured. Set up a key or switch to local Ollama before sending.": "尚未配置模型 API Key,发送前请先配置密钥或切换本地 Ollama。",
|
|
1342
|
+
"Set up API key": "配置 API Key",
|
|
1343
|
+
"Set up API key…": "配置 API Key…",
|
|
1344
|
+
"API key not configured — click to set up ({model})": "尚未配置 API Key — 点击前往配置({model})",
|
|
1345
|
+
"Save a model API key below (or switch Provider to local Ollama) — your message will be sent automatically.": "在下方保存模型 API Key(或切换为本地免密 Ollama)后,将自动发送你刚输入的消息。",
|
|
1346
|
+
"No API key is configured yet. Paste a key below and click Save, or switch Provider to Ollama (Local).": "尚未填写可用的 API Key:请在下方粘贴密钥后点「保存」,或将服务商切换为本地 Ollama。"
|
|
1316
1347
|
}
|
|
@@ -81,8 +81,21 @@ export async function readMarkdownPreviewFile(filePath, maxBytes = MAX_MARKDOWN_
|
|
|
81
81
|
return { size: 0, content: null, error: 'read_failed' };
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
export async function loadMarkdownPreviewFiles(messages, explicitPath) {
|
|
84
|
+
export async function loadMarkdownPreviewFiles(messages, explicitPath, options) {
|
|
85
85
|
const listed = listMarkdownTurnFiles(messages);
|
|
86
|
+
if (options?.single && explicitPath && isMarkdownTurnPath(explicitPath)) {
|
|
87
|
+
const resolved = path.resolve(explicitPath);
|
|
88
|
+
const match = listed.find((file) => file.path === resolved);
|
|
89
|
+
const read = await readMarkdownPreviewFile(resolved);
|
|
90
|
+
return [
|
|
91
|
+
{
|
|
92
|
+
path: resolved,
|
|
93
|
+
name: match?.name ?? path.basename(resolved),
|
|
94
|
+
...(match?.description ? { description: match.description } : {}),
|
|
95
|
+
...read,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
}
|
|
86
99
|
const files = [];
|
|
87
100
|
for (const file of listed) {
|
|
88
101
|
const read = await readMarkdownPreviewFile(file.path);
|
|
@@ -112,9 +125,12 @@ export async function handleSteerMarkdownPreview(query, listMessages) {
|
|
|
112
125
|
}
|
|
113
126
|
try {
|
|
114
127
|
const messages = await listMessages(chatId);
|
|
128
|
+
const single = query.get('single') === '1';
|
|
115
129
|
return {
|
|
116
130
|
status: 200,
|
|
117
|
-
data: {
|
|
131
|
+
data: {
|
|
132
|
+
files: await loadMarkdownPreviewFiles(messages, query.get('path'), { single }),
|
|
133
|
+
},
|
|
118
134
|
};
|
|
119
135
|
}
|
|
120
136
|
catch (err) {
|
|
@@ -132,7 +148,7 @@ export function registerSteerMarkdownPreview() {
|
|
|
132
148
|
path: MARKDOWN_PREVIEW_ROUTE,
|
|
133
149
|
handler: async ({ query }) => {
|
|
134
150
|
const { getScopedStore, LOCAL_SCOPE } = await import('@steerable/agent-shell/storage/driver');
|
|
135
|
-
return handleSteerMarkdownPreview(query, (chatId) => getScopedStore(LOCAL_SCOPE).listMessages(chatId,
|
|
151
|
+
return handleSteerMarkdownPreview(query, (chatId) => getScopedStore(LOCAL_SCOPE).listMessages(chatId, 2000));
|
|
136
152
|
},
|
|
137
153
|
},
|
|
138
154
|
]);
|
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Steer
|
|
2
|
+
* Steer 的本轮变更。从助手消息里的写文件、改文件、补丁工具与回合脚本产物中回收 diff,
|
|
3
3
|
* 交给右侧栏位。不进框架,其他产品不注册这条路由。
|
|
4
4
|
*/
|
|
5
|
+
import fs from 'node:fs/promises';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { extractFileChangePreview } from '@steerable/agent-protocol';
|
|
5
8
|
import { matchPackBackendRoute, registerPackBackendRoutes, } from '@steerable/agent-shell/local-backend/pack-backend-routes';
|
|
6
9
|
export const TURN_CHANGES_ROUTE = '/api/v2/steer/turn-changes';
|
|
7
10
|
/** 单份 diff 放进侧栏前的上限。行数仍按完整文本计。 */
|
|
8
11
|
const MAX_DIFF_CHARS = 200_000;
|
|
12
|
+
/** 回合脚本生成但未经过写文件工具的文本/源码文件兜底读取上限。 */
|
|
13
|
+
const MAX_FALLBACK_SOURCE_BYTES = 256 * 1024;
|
|
14
|
+
const FALLBACK_TEXT_EXTENSIONS = new Set([
|
|
15
|
+
'.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs',
|
|
16
|
+
'.py', '.go', '.rs', '.java', '.kt', '.kts', '.rb', '.php',
|
|
17
|
+
'.c', '.cc', '.cpp', '.h', '.hpp', '.cs', '.swift', '.scala',
|
|
18
|
+
'.dart', '.lua', '.r', '.ex', '.exs', '.erl', '.zig', '.nim',
|
|
19
|
+
'.css', '.scss', '.less', '.html', '.vue', '.svelte', '.mdx',
|
|
20
|
+
'.json', '.yaml', '.yml', '.toml', '.ini', '.cfg', '.conf', '.env',
|
|
21
|
+
'.sh', '.bash', '.zsh', '.sql', '.xml', '.gradle', '.prisma',
|
|
22
|
+
'.graphql', '.gql', '.proto', '.tf', '.hcl', '.txt',
|
|
23
|
+
]);
|
|
24
|
+
const FALLBACK_BASENAMES = new Set([
|
|
25
|
+
'dockerfile',
|
|
26
|
+
'makefile',
|
|
27
|
+
'cmakelists.txt',
|
|
28
|
+
'.gitignore',
|
|
29
|
+
'.env',
|
|
30
|
+
]);
|
|
9
31
|
function validChatId(chatId) {
|
|
10
32
|
return /^[0-9a-zA-Z_-]{1,200}$/.test(chatId);
|
|
11
33
|
}
|
|
@@ -13,6 +35,15 @@ function fileNameOf(filePath) {
|
|
|
13
35
|
const slash = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
|
|
14
36
|
return slash >= 0 ? filePath.slice(slash + 1) : filePath;
|
|
15
37
|
}
|
|
38
|
+
export function isFallbackSourceTurnPath(filePath) {
|
|
39
|
+
if (!filePath || filePath.includes('\0') || !path.isAbsolute(filePath))
|
|
40
|
+
return false;
|
|
41
|
+
const base = path.basename(filePath).toLowerCase();
|
|
42
|
+
if (FALLBACK_BASENAMES.has(base))
|
|
43
|
+
return true;
|
|
44
|
+
const ext = path.extname(base);
|
|
45
|
+
return FALLBACK_TEXT_EXTENSIONS.has(ext);
|
|
46
|
+
}
|
|
16
47
|
function diffStats(diffText) {
|
|
17
48
|
let additions = 0;
|
|
18
49
|
let deletions = 0;
|
|
@@ -24,38 +55,27 @@ function diffStats(diffText) {
|
|
|
24
55
|
}
|
|
25
56
|
return { additions, deletions };
|
|
26
57
|
}
|
|
27
|
-
function editDiffOf(result) {
|
|
28
|
-
if (!result || typeof result !== 'object')
|
|
29
|
-
return null;
|
|
30
|
-
const record = result;
|
|
31
|
-
if (typeof record.diff === 'string')
|
|
32
|
-
return record.diff;
|
|
33
|
-
const data = record.data;
|
|
34
|
-
if (data && typeof data === 'object' && typeof data.diff === 'string') {
|
|
35
|
-
return data.diff;
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
58
|
function actionFailed(action) {
|
|
40
59
|
if (action.success === false || action.threw === true)
|
|
41
60
|
return true;
|
|
42
61
|
const result = action.result;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
if (result && typeof result === 'object' && result.success === false) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (typeof result === 'string' && result.trimStart().startsWith('{')) {
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(result);
|
|
68
|
+
if (parsed && parsed.success === false)
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Truncated JSON envelope is handled downstream by extractFileChangePreview.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
56
76
|
}
|
|
57
77
|
/** 整文件写入记成一份只有新增行的 unified diff。 */
|
|
58
|
-
function diffForWrittenFile(filePath, content) {
|
|
78
|
+
export function diffForWrittenFile(filePath, content) {
|
|
59
79
|
const lines = content.split('\n');
|
|
60
80
|
if (lines.length > 0 && lines[lines.length - 1] === '')
|
|
61
81
|
lines.pop();
|
|
@@ -65,11 +85,13 @@ function diffForWrittenFile(filePath, content) {
|
|
|
65
85
|
`+++ ${filePath}`,
|
|
66
86
|
`@@ -0,0 +1,${lines.length} @@`,
|
|
67
87
|
body,
|
|
68
|
-
]
|
|
88
|
+
]
|
|
89
|
+
.filter((line, index) => index < 3 || line !== '')
|
|
90
|
+
.join('\n');
|
|
69
91
|
}
|
|
70
|
-
function
|
|
92
|
+
function parseMetadata(message) {
|
|
71
93
|
if (!message.messageMetadata)
|
|
72
|
-
return
|
|
94
|
+
return null;
|
|
73
95
|
let parsed;
|
|
74
96
|
try {
|
|
75
97
|
parsed = JSON.parse(message.messageMetadata);
|
|
@@ -77,13 +99,60 @@ function actionsOf(message) {
|
|
|
77
99
|
catch (err) {
|
|
78
100
|
if (!(err instanceof SyntaxError))
|
|
79
101
|
throw err;
|
|
80
|
-
return
|
|
102
|
+
return null;
|
|
81
103
|
}
|
|
82
104
|
if (!parsed || typeof parsed !== 'object')
|
|
105
|
+
return null;
|
|
106
|
+
return parsed;
|
|
107
|
+
}
|
|
108
|
+
function actionsOf(message) {
|
|
109
|
+
const meta = parseMetadata(message);
|
|
110
|
+
if (!meta)
|
|
83
111
|
return [];
|
|
84
|
-
const actions =
|
|
112
|
+
const actions = meta.executedActions;
|
|
85
113
|
return Array.isArray(actions) ? actions.filter((item) => item && typeof item === 'object') : [];
|
|
86
114
|
}
|
|
115
|
+
function turnFilePathsOf(message) {
|
|
116
|
+
const meta = parseMetadata(message);
|
|
117
|
+
if (!meta || !Array.isArray(meta.turnFiles))
|
|
118
|
+
return [];
|
|
119
|
+
const paths = [];
|
|
120
|
+
for (const item of meta.turnFiles) {
|
|
121
|
+
if (!item || typeof item !== 'object')
|
|
122
|
+
continue;
|
|
123
|
+
const rawPath = item.path;
|
|
124
|
+
if (typeof rawPath === 'string' && rawPath.trim()) {
|
|
125
|
+
paths.push(rawPath.trim());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return paths;
|
|
129
|
+
}
|
|
130
|
+
function splitMultiFilePatch(rawDiff, fallbackPath) {
|
|
131
|
+
const lines = rawDiff.replace(/\r\n/g, '\n').split('\n');
|
|
132
|
+
const sections = [];
|
|
133
|
+
let current = null;
|
|
134
|
+
for (const line of lines) {
|
|
135
|
+
const gitHeader = /^diff --git a\/.+ b\/(.+)$/.exec(line);
|
|
136
|
+
if (gitHeader) {
|
|
137
|
+
current = { path: gitHeader[1].trim(), lines: [line] };
|
|
138
|
+
sections.push(current);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const patchHeader = /^\*\*\* (?:Update|Add|Delete) File:\s*(.+)$/.exec(line);
|
|
142
|
+
if (patchHeader) {
|
|
143
|
+
current = { path: patchHeader[1].trim(), lines: [line] };
|
|
144
|
+
sections.push(current);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (current) {
|
|
148
|
+
current.lines.push(line);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (sections.length <= 1) {
|
|
152
|
+
return [{ path: fallbackPath, diff: rawDiff }];
|
|
153
|
+
}
|
|
154
|
+
return sections.map((sec) => ({ path: sec.path, diff: sec.lines.join('\n') }));
|
|
155
|
+
}
|
|
87
156
|
function finishFile(file) {
|
|
88
157
|
const full = file.parts.join('\n');
|
|
89
158
|
const stats = diffStats(full);
|
|
@@ -104,44 +173,64 @@ function filesFromActions(actions) {
|
|
|
104
173
|
for (const action of actions) {
|
|
105
174
|
if (actionFailed(action))
|
|
106
175
|
continue;
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
176
|
+
const toolName = typeof action.tool === 'string' ? action.tool : '';
|
|
177
|
+
if (!toolName)
|
|
109
178
|
continue;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
byPath.set(filePath, { path: filePath, parts: [diffForWrittenFile(filePath, content)] });
|
|
179
|
+
const preview = extractFileChangePreview({
|
|
180
|
+
tool: toolName,
|
|
181
|
+
arguments: action.arguments,
|
|
182
|
+
result: action.result,
|
|
183
|
+
});
|
|
184
|
+
if (!preview || preview.error)
|
|
117
185
|
continue;
|
|
118
|
-
|
|
119
|
-
if (action.tool !== 'local_edit_file')
|
|
186
|
+
if (!preview.path || preview.path === 'file')
|
|
120
187
|
continue;
|
|
121
|
-
|
|
122
|
-
|
|
188
|
+
if (preview.isWrite) {
|
|
189
|
+
const diff = preview.diff ??
|
|
190
|
+
(preview.contentPreview !== null
|
|
191
|
+
? diffForWrittenFile(preview.path, preview.contentPreview)
|
|
192
|
+
: null);
|
|
193
|
+
if (!diff)
|
|
194
|
+
continue;
|
|
195
|
+
if (!byPath.has(preview.path))
|
|
196
|
+
order.push(preview.path);
|
|
197
|
+
byPath.set(preview.path, { path: preview.path, parts: [diff] });
|
|
123
198
|
continue;
|
|
124
|
-
|
|
125
|
-
if (!
|
|
126
|
-
order.push(filePath);
|
|
127
|
-
byPath.set(filePath, { path: filePath, parts: [diff] });
|
|
199
|
+
}
|
|
200
|
+
if (!preview.diff)
|
|
128
201
|
continue;
|
|
202
|
+
const segments = toolName === 'apply_patch'
|
|
203
|
+
? splitMultiFilePatch(preview.diff, preview.path)
|
|
204
|
+
: [{ path: preview.path, diff: preview.diff }];
|
|
205
|
+
for (const seg of segments) {
|
|
206
|
+
if (!seg.path)
|
|
207
|
+
continue;
|
|
208
|
+
const existing = byPath.get(seg.path);
|
|
209
|
+
if (!existing) {
|
|
210
|
+
order.push(seg.path);
|
|
211
|
+
byPath.set(seg.path, { path: seg.path, parts: [seg.diff] });
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
existing.parts.push(seg.diff);
|
|
215
|
+
}
|
|
129
216
|
}
|
|
130
|
-
existing.parts.push(diff);
|
|
131
217
|
}
|
|
132
218
|
return order.flatMap((filePath) => {
|
|
133
219
|
const file = byPath.get(filePath);
|
|
134
220
|
return file ? [finishFile(file)] : [];
|
|
135
221
|
});
|
|
136
222
|
}
|
|
223
|
+
function findChosenMessage(messages, messageId) {
|
|
224
|
+
return messageId
|
|
225
|
+
? messages.find((message) => message.id === messageId)
|
|
226
|
+
: messages.find((message) => message.role !== 'user');
|
|
227
|
+
}
|
|
137
228
|
/**
|
|
138
|
-
*
|
|
229
|
+
* 同步收出一轮动作中的文件变更。
|
|
139
230
|
* `messages` 按新到旧排列。不传 messageId 时用最新一条助手消息,这一轮没改文件就是空列表。
|
|
140
231
|
*/
|
|
141
232
|
export function collectTurnChanges(messages, messageId) {
|
|
142
|
-
const chosen = messageId
|
|
143
|
-
? messages.find((message) => message.id === messageId)
|
|
144
|
-
: messages.find((message) => message.role !== 'user');
|
|
233
|
+
const chosen = findChosenMessage(messages, messageId);
|
|
145
234
|
if (!chosen)
|
|
146
235
|
return { messageId: messageId || null, files: [] };
|
|
147
236
|
return {
|
|
@@ -149,6 +238,46 @@ export function collectTurnChanges(messages, messageId) {
|
|
|
149
238
|
files: filesFromActions(actionsOf(chosen)),
|
|
150
239
|
};
|
|
151
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* 为本轮由命令行脚本生成、出现在 `turnFiles` 中但未经过写文件工具的源码文件补充新增视图。
|
|
243
|
+
*/
|
|
244
|
+
export async function enrichTurnChangesFromTurnFiles(base, chosen) {
|
|
245
|
+
if (!chosen)
|
|
246
|
+
return base;
|
|
247
|
+
const candidatePaths = turnFilePathsOf(chosen);
|
|
248
|
+
if (candidatePaths.length === 0)
|
|
249
|
+
return base;
|
|
250
|
+
const known = new Set(base.files.map((f) => path.resolve(f.path)));
|
|
251
|
+
const extras = [];
|
|
252
|
+
for (const candidate of candidatePaths) {
|
|
253
|
+
if (!isFallbackSourceTurnPath(candidate))
|
|
254
|
+
continue;
|
|
255
|
+
const resolved = path.resolve(candidate);
|
|
256
|
+
if (known.has(resolved))
|
|
257
|
+
continue;
|
|
258
|
+
try {
|
|
259
|
+
const st = await fs.stat(resolved);
|
|
260
|
+
if (!st.isFile() || st.size > MAX_FALLBACK_SOURCE_BYTES)
|
|
261
|
+
continue;
|
|
262
|
+
const buf = await fs.readFile(resolved);
|
|
263
|
+
// Skip binary files containing NUL bytes.
|
|
264
|
+
if (buf.includes(0))
|
|
265
|
+
continue;
|
|
266
|
+
const text = buf.toString('utf8').replace(/^\uFEFF/, '');
|
|
267
|
+
known.add(resolved);
|
|
268
|
+
extras.push(finishFile({ path: candidate, parts: [diffForWrittenFile(candidate, text)] }));
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (extras.length === 0)
|
|
275
|
+
return base;
|
|
276
|
+
return {
|
|
277
|
+
messageId: base.messageId,
|
|
278
|
+
files: [...base.files, ...extras],
|
|
279
|
+
};
|
|
280
|
+
}
|
|
152
281
|
export async function handleSteerTurnChanges(query, listMessages) {
|
|
153
282
|
const chatId = query.get('chatId') ?? '';
|
|
154
283
|
if (!validChatId(chatId)) {
|
|
@@ -156,9 +285,13 @@ export async function handleSteerTurnChanges(query, listMessages) {
|
|
|
156
285
|
}
|
|
157
286
|
try {
|
|
158
287
|
const messages = await listMessages(chatId);
|
|
288
|
+
const wantedMessageId = query.get('messageId');
|
|
289
|
+
const chosen = findChosenMessage(messages, wantedMessageId);
|
|
290
|
+
const base = collectTurnChanges(messages, wantedMessageId);
|
|
291
|
+
const enriched = await enrichTurnChangesFromTurnFiles(base, chosen);
|
|
159
292
|
return {
|
|
160
293
|
status: 200,
|
|
161
|
-
data:
|
|
294
|
+
data: enriched,
|
|
162
295
|
};
|
|
163
296
|
}
|
|
164
297
|
catch (err) {
|
|
@@ -176,7 +309,9 @@ export function registerSteerTurnChanges() {
|
|
|
176
309
|
path: TURN_CHANGES_ROUTE,
|
|
177
310
|
handler: async ({ query }) => {
|
|
178
311
|
const { getScopedStore, LOCAL_SCOPE } = await import('@steerable/agent-shell/storage/driver');
|
|
179
|
-
return handleSteerTurnChanges(query, (chatId) => getScopedStore(LOCAL_SCOPE)
|
|
312
|
+
return handleSteerTurnChanges(query, (chatId) => getScopedStore(LOCAL_SCOPE)
|
|
313
|
+
.listMessages(chatId, 2000)
|
|
314
|
+
.then((messages) => messages.map((message) => ({
|
|
180
315
|
id: message.id,
|
|
181
316
|
role: message.role,
|
|
182
317
|
messageMetadata: typeof message.messageMetadata === 'string' ? message.messageMetadata : null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerable/steer",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.26",
|
|
4
4
|
"description": "Steer Agent CLI & TUI — local-first AI assistant for your terminal and server.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://steeragent.app",
|
|
@@ -25,17 +25,18 @@
|
|
|
25
25
|
"node": ">=22.19.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@steerable/agent-cli": "0.14.
|
|
29
|
-
"@steerable/agent-
|
|
28
|
+
"@steerable/agent-cli": "0.14.8",
|
|
29
|
+
"@steerable/agent-protocol": "0.14.8",
|
|
30
|
+
"@steerable/agent-shell": "0.14.8",
|
|
30
31
|
"fflate": "^0.8.2",
|
|
31
32
|
"playwright-core": "1.63.0",
|
|
32
33
|
"sharp": "^0.33.5"
|
|
33
34
|
},
|
|
34
35
|
"optionalDependencies": {
|
|
35
|
-
"@steerable/runtime-darwin-arm64": "0.14.
|
|
36
|
-
"@steerable/runtime-darwin-x64": "0.14.
|
|
37
|
-
"@steerable/runtime-linux-arm64": "0.14.
|
|
38
|
-
"@steerable/runtime-linux-x64": "0.14.
|
|
39
|
-
"@steerable/runtime-win32-x64": "0.14.
|
|
36
|
+
"@steerable/runtime-darwin-arm64": "0.14.8",
|
|
37
|
+
"@steerable/runtime-darwin-x64": "0.14.8",
|
|
38
|
+
"@steerable/runtime-linux-arm64": "0.14.8",
|
|
39
|
+
"@steerable/runtime-linux-x64": "0.14.8",
|
|
40
|
+
"@steerable/runtime-win32-x64": "0.14.8"
|
|
40
41
|
}
|
|
41
42
|
}
|