@steerable/steer 0.3.28 → 0.3.29
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/products/steer/active.js +3 -1
- package/dist/products/steer/foreign-import/deps.js +1 -0
- package/dist/products/steer/foreign-import/experts.js +62 -0
- package/dist/products/steer/foreign-import/ledger.js +68 -0
- package/dist/products/steer/foreign-import/scan.js +657 -0
- package/dist/products/steer/foreign-import/skills.js +206 -0
- package/dist/products/steer/foreign-import/sources.js +127 -0
- package/dist/products/steer/foreign-import/tasks.js +187 -0
- package/dist/products/steer/foreign-import/types.js +12 -0
- package/dist/products/steer/foreign-import-routes.js +87 -0
- package/dist/products/steer/locales/zh.json +41 -1
- package/package.json +1 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 发现用户技能目录,并复制到 Steer 的用户技能根。不覆盖已有目录。
|
|
3
|
+
*/
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { parseSkillNameFromMarkdown } from '@steerable/agent-shell/local-backend/skill-install';
|
|
8
|
+
import { EXCLUDED_PATH_SEGMENTS } from './sources.js';
|
|
9
|
+
export const SKILL_WALK_DEPTH = 4;
|
|
10
|
+
function pathInside(root, candidate) {
|
|
11
|
+
const base = root.endsWith(path.sep) ? root.slice(0, -1) : root;
|
|
12
|
+
return candidate === base || candidate.startsWith(base + path.sep);
|
|
13
|
+
}
|
|
14
|
+
function note(probe, filePath) {
|
|
15
|
+
probe.observe?.(filePath);
|
|
16
|
+
}
|
|
17
|
+
function isSecretFileName(name) {
|
|
18
|
+
return name === '.env'
|
|
19
|
+
|| name === 'credentials.json'
|
|
20
|
+
|| name.endsWith('.pem')
|
|
21
|
+
|| name.endsWith('.key');
|
|
22
|
+
}
|
|
23
|
+
/** frontmatter 的原始 name。没有则用目录名。展示用,不参与目录净化。 */
|
|
24
|
+
export function skillDisplayName(markdown, dirBase) {
|
|
25
|
+
if (markdown.startsWith('---')) {
|
|
26
|
+
const rest = markdown.slice(3).replace(/^\r?\n/, '');
|
|
27
|
+
const end = rest.search(/\r?\n---\s*(?:\r?\n|$)/);
|
|
28
|
+
if (end !== -1) {
|
|
29
|
+
const nameMatch = rest.slice(0, end).match(/^name:\s*(.+)$/m);
|
|
30
|
+
const raw = nameMatch?.[1]?.trim().replace(/^["']|["']$/g, '');
|
|
31
|
+
if (raw)
|
|
32
|
+
return raw;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return dirBase;
|
|
36
|
+
}
|
|
37
|
+
/** 目标目录名。中文或空净化结果改用来源 id 加路径哈希。 */
|
|
38
|
+
export function skillDestName(source, realPath, markdown, dirBase) {
|
|
39
|
+
const parsed = parseSkillNameFromMarkdown(markdown, dirBase);
|
|
40
|
+
const hashed = `${source}-${crypto.createHash('sha256').update(realPath).digest('hex').slice(0, 8)}`;
|
|
41
|
+
const preferred = /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(parsed) && parsed.length <= 81
|
|
42
|
+
? parsed
|
|
43
|
+
: hashed;
|
|
44
|
+
return /^[a-z0-9][a-z0-9-]{0,80}$/.test(preferred) ? preferred : hashed;
|
|
45
|
+
}
|
|
46
|
+
function skillMarkdownEscapes(skillDir, probe) {
|
|
47
|
+
note(probe, skillDir);
|
|
48
|
+
let skillReal;
|
|
49
|
+
try {
|
|
50
|
+
skillReal = fs.realpathSync(skillDir);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
note(probe, skillReal);
|
|
56
|
+
const stack = [skillDir];
|
|
57
|
+
while (stack.length > 0) {
|
|
58
|
+
const dir = stack.pop();
|
|
59
|
+
if (!dir)
|
|
60
|
+
continue;
|
|
61
|
+
note(probe, dir);
|
|
62
|
+
let entries;
|
|
63
|
+
try {
|
|
64
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
for (const ent of entries) {
|
|
70
|
+
if (isSecretFileName(ent.name) || EXCLUDED_PATH_SEGMENTS.has(ent.name))
|
|
71
|
+
continue;
|
|
72
|
+
const abs = path.join(dir, ent.name);
|
|
73
|
+
if (!ent.isSymbolicLink()) {
|
|
74
|
+
if (ent.isDirectory())
|
|
75
|
+
stack.push(abs);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
note(probe, abs);
|
|
79
|
+
try {
|
|
80
|
+
const target = fs.realpathSync(abs);
|
|
81
|
+
note(probe, target);
|
|
82
|
+
if (!pathInside(skillReal, target))
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
/** 技能根下最多 4 层目录里,直接含有常规文件 SKILL.md 的目录。 */
|
|
93
|
+
export function discoverSkillDirs(skillRootReal, probe) {
|
|
94
|
+
const found = [];
|
|
95
|
+
const walk = (dir, depth) => {
|
|
96
|
+
note(probe, dir);
|
|
97
|
+
let entries;
|
|
98
|
+
try {
|
|
99
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
let skillFile = null;
|
|
105
|
+
const children = [];
|
|
106
|
+
for (const ent of entries) {
|
|
107
|
+
if (EXCLUDED_PATH_SEGMENTS.has(ent.name))
|
|
108
|
+
continue;
|
|
109
|
+
const abs = path.join(dir, ent.name);
|
|
110
|
+
if (ent.isSymbolicLink())
|
|
111
|
+
continue;
|
|
112
|
+
if (ent.isDirectory()) {
|
|
113
|
+
if (depth < SKILL_WALK_DEPTH)
|
|
114
|
+
children.push(abs);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (ent.isFile() && ent.name === 'SKILL.md' && depth >= 1)
|
|
118
|
+
skillFile = abs;
|
|
119
|
+
}
|
|
120
|
+
if (skillFile) {
|
|
121
|
+
note(probe, skillFile);
|
|
122
|
+
try {
|
|
123
|
+
const real = fs.realpathSync(dir);
|
|
124
|
+
note(probe, real);
|
|
125
|
+
if (pathInside(skillRootReal, real)) {
|
|
126
|
+
const st = fs.lstatSync(dir);
|
|
127
|
+
found.push({
|
|
128
|
+
dir,
|
|
129
|
+
real,
|
|
130
|
+
mtime: st.mtime,
|
|
131
|
+
escaped: skillMarkdownEscapes(dir, probe),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// 目录在列出之后消失:这项不进清单。
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const child of children)
|
|
140
|
+
walk(child, depth + 1);
|
|
141
|
+
};
|
|
142
|
+
walk(skillRootReal, 0);
|
|
143
|
+
return found;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 只复制常规文件和目录。密钥文件名不打开。
|
|
147
|
+
* 指向技能目录外的符号链接会删掉已创建的目标。
|
|
148
|
+
*/
|
|
149
|
+
export function copySkillDirectory(sourceDir, destDir) {
|
|
150
|
+
let sourceReal;
|
|
151
|
+
try {
|
|
152
|
+
sourceReal = fs.realpathSync(sourceDir);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return 'copy-failed';
|
|
156
|
+
}
|
|
157
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
158
|
+
const walk = (current) => {
|
|
159
|
+
let entries;
|
|
160
|
+
try {
|
|
161
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return 'copy-failed';
|
|
165
|
+
}
|
|
166
|
+
for (const ent of entries) {
|
|
167
|
+
if (isSecretFileName(ent.name) || EXCLUDED_PATH_SEGMENTS.has(ent.name))
|
|
168
|
+
continue;
|
|
169
|
+
const from = path.join(current, ent.name);
|
|
170
|
+
const rel = path.relative(sourceDir, from);
|
|
171
|
+
if (rel.startsWith('..') || path.isAbsolute(rel))
|
|
172
|
+
return 'copy-failed';
|
|
173
|
+
const to = path.join(destDir, rel);
|
|
174
|
+
if (ent.isSymbolicLink()) {
|
|
175
|
+
try {
|
|
176
|
+
const target = fs.realpathSync(from);
|
|
177
|
+
if (!pathInside(sourceReal, target))
|
|
178
|
+
return 'symlink-escape';
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return 'symlink-escape';
|
|
182
|
+
}
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
if (ent.isDirectory()) {
|
|
187
|
+
fs.mkdirSync(to, { recursive: true });
|
|
188
|
+
const nested = walk(from);
|
|
189
|
+
if (nested !== 'ok')
|
|
190
|
+
return nested;
|
|
191
|
+
}
|
|
192
|
+
else if (ent.isFile()) {
|
|
193
|
+
fs.copyFileSync(from, to);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return 'copy-failed';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return 'ok';
|
|
201
|
+
};
|
|
202
|
+
const result = walk(sourceDir);
|
|
203
|
+
if (result !== 'ok')
|
|
204
|
+
fs.rmSync(destDir, { recursive: true, force: true });
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 七家来源的根目录。只认这里列出的路径,环境变量只替换对应的那一个根。
|
|
3
|
+
*/
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
export { SOURCE_ORDER } from './types.js';
|
|
6
|
+
export const EXCLUDED_PATH_SEGMENTS = new Set([
|
|
7
|
+
'node_modules',
|
|
8
|
+
'plugins',
|
|
9
|
+
'plugin-data',
|
|
10
|
+
'builtin',
|
|
11
|
+
'skills-cursor',
|
|
12
|
+
'.skills',
|
|
13
|
+
]);
|
|
14
|
+
function envDir(env, name) {
|
|
15
|
+
const value = env[name];
|
|
16
|
+
if (typeof value !== 'string')
|
|
17
|
+
return null;
|
|
18
|
+
const trimmed = value.trim();
|
|
19
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
20
|
+
}
|
|
21
|
+
function doubaoSkillRoots(input) {
|
|
22
|
+
const roots = [path.join(input.homedir, 'DoubaoWork', 'skills')];
|
|
23
|
+
if (input.platform === 'win32') {
|
|
24
|
+
const base = envDir(input.env, 'LOCALAPPDATA')
|
|
25
|
+
?? path.join(input.homedir, 'AppData', 'Local');
|
|
26
|
+
roots.push(path.join(base, 'Doubao', 'User Data', 'Default', '.doubao', 'agent_mode', 'workspace', '.user_skills'));
|
|
27
|
+
}
|
|
28
|
+
else if (input.platform === 'darwin') {
|
|
29
|
+
roots.push(path.join(input.homedir, 'Library', 'Application Support', 'DoubaoWork', 'Default', '.doubaowork', 'agent_mode', 'workspace', '.user_skills'));
|
|
30
|
+
}
|
|
31
|
+
return roots;
|
|
32
|
+
}
|
|
33
|
+
function doubaoAppDir(input) {
|
|
34
|
+
if (input.platform === 'win32') {
|
|
35
|
+
const base = envDir(input.env, 'LOCALAPPDATA')
|
|
36
|
+
?? path.join(input.homedir, 'AppData', 'Local');
|
|
37
|
+
return path.join(base, 'Doubao');
|
|
38
|
+
}
|
|
39
|
+
if (input.platform === 'darwin') {
|
|
40
|
+
return path.join(input.homedir, 'Library', 'Application Support', 'DoubaoWork');
|
|
41
|
+
}
|
|
42
|
+
return path.join(input.homedir, '.config', 'DoubaoWork');
|
|
43
|
+
}
|
|
44
|
+
/** 按主目录和环境变量列出本期要看的根。不访问磁盘。 */
|
|
45
|
+
export function foreignImportRoots(input) {
|
|
46
|
+
const home = input.homedir;
|
|
47
|
+
const claude = path.join(home, '.claude');
|
|
48
|
+
const workbuddy = path.join(home, '.codebuddy');
|
|
49
|
+
const codex = path.join(home, '.codex');
|
|
50
|
+
const cursor = path.join(home, '.cursor');
|
|
51
|
+
const qoder = envDir(input.env, 'QODER_CONFIG_DIR') ?? path.join(home, '.qoder');
|
|
52
|
+
const qoderCn = envDir(input.env, 'QODERCN_CONFIG_DIR') ?? path.join(home, '.qoder-cn');
|
|
53
|
+
const trae = envDir(input.env, 'TRAE_HOME') ?? path.join(home, '.trae');
|
|
54
|
+
const traeCn = path.join(home, '.trae-cn');
|
|
55
|
+
const standard = (source, family, variant, root, taskShape, agents) => ({
|
|
56
|
+
source,
|
|
57
|
+
family,
|
|
58
|
+
variant,
|
|
59
|
+
root,
|
|
60
|
+
unsupported: null,
|
|
61
|
+
taskShape,
|
|
62
|
+
skillRoots: [path.join(root, 'skills')],
|
|
63
|
+
agentsDir: agents ? path.join(root, 'agents') : null,
|
|
64
|
+
});
|
|
65
|
+
return [
|
|
66
|
+
standard('claude', 'claude', null, claude, 'claude-jsonl', true),
|
|
67
|
+
standard('workbuddy', 'workbuddy', null, workbuddy, 'claude-jsonl', true),
|
|
68
|
+
standard('codex', 'codex', null, codex, 'codex-rollout', false),
|
|
69
|
+
standard('cursor', 'cursor', null, cursor, 'cursor-transcript', false),
|
|
70
|
+
standard('qoder', 'qoder', 'global', qoder, 'qoder-jsonl', true),
|
|
71
|
+
standard('qoder-cn', 'qoder', 'cn', qoderCn, 'qoder-jsonl', true),
|
|
72
|
+
{
|
|
73
|
+
source: 'trae',
|
|
74
|
+
family: 'trae',
|
|
75
|
+
variant: 'global',
|
|
76
|
+
root: trae,
|
|
77
|
+
unsupported: 'encrypted-db',
|
|
78
|
+
taskShape: 'unsupported',
|
|
79
|
+
skillRoots: [path.join(trae, 'skills')],
|
|
80
|
+
agentsDir: null,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
source: 'trae-cn',
|
|
84
|
+
family: 'trae',
|
|
85
|
+
variant: 'cn',
|
|
86
|
+
root: traeCn,
|
|
87
|
+
unsupported: 'encrypted-db',
|
|
88
|
+
taskShape: 'unsupported',
|
|
89
|
+
skillRoots: [path.join(traeCn, 'skills')],
|
|
90
|
+
agentsDir: null,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
source: 'doubao-work',
|
|
94
|
+
family: 'doubao',
|
|
95
|
+
variant: null,
|
|
96
|
+
root: doubaoAppDir(input),
|
|
97
|
+
unsupported: 'indexed-db',
|
|
98
|
+
taskShape: 'unsupported',
|
|
99
|
+
skillRoots: doubaoSkillRoots(input),
|
|
100
|
+
agentsDir: null,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
export function sourceBaseLabel(source) {
|
|
105
|
+
switch (source) {
|
|
106
|
+
case 'claude':
|
|
107
|
+
return 'Claude Code';
|
|
108
|
+
case 'workbuddy':
|
|
109
|
+
return 'WorkBuddy';
|
|
110
|
+
case 'codex':
|
|
111
|
+
return 'Codex';
|
|
112
|
+
case 'cursor':
|
|
113
|
+
return 'Cursor';
|
|
114
|
+
case 'qoder':
|
|
115
|
+
case 'qoder-cn':
|
|
116
|
+
return 'Qoder';
|
|
117
|
+
case 'trae':
|
|
118
|
+
case 'trae-cn':
|
|
119
|
+
return 'Trae';
|
|
120
|
+
case 'doubao-work':
|
|
121
|
+
return 'Doubao Work';
|
|
122
|
+
default: {
|
|
123
|
+
const neverSource = source;
|
|
124
|
+
return neverSource;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从四家明文 jsonl 里抽出用户和助手的文本。不保留工具调用。
|
|
3
|
+
*/
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
export const FOREIGN_MESSAGE_LIMIT = 1000;
|
|
6
|
+
export const FOREIGN_MESSAGE_CHARS = 100_000;
|
|
7
|
+
const TITLE_CHARS = 64;
|
|
8
|
+
/** 单条超过 10 万字符时保留前段并标明截断。 */
|
|
9
|
+
export function clipForeignMessage(text) {
|
|
10
|
+
if (text.length <= FOREIGN_MESSAGE_CHARS)
|
|
11
|
+
return text;
|
|
12
|
+
return `${text.slice(0, FOREIGN_MESSAGE_CHARS)}\n…[truncated]`;
|
|
13
|
+
}
|
|
14
|
+
/** 标题用第一条非空用户文本,压成一行,最多 64 字。没有则用会话 id 前 8 位。 */
|
|
15
|
+
export function foreignTaskBareTitle(session) {
|
|
16
|
+
const user = session.messages.find((message) => message.role === 'user' && message.text.trim());
|
|
17
|
+
if (!user)
|
|
18
|
+
return session.sessionId.slice(0, 8);
|
|
19
|
+
return user.text.replace(/\s+/g, ' ').trim().slice(0, TITLE_CHARS);
|
|
20
|
+
}
|
|
21
|
+
function pushText(messages, role, text) {
|
|
22
|
+
if (!text.trim())
|
|
23
|
+
return;
|
|
24
|
+
messages.push({ role, text });
|
|
25
|
+
}
|
|
26
|
+
function blocksText(content, extraTypes = []) {
|
|
27
|
+
if (typeof content === 'string')
|
|
28
|
+
return content;
|
|
29
|
+
if (!Array.isArray(content))
|
|
30
|
+
return '';
|
|
31
|
+
const parts = [];
|
|
32
|
+
for (const block of content) {
|
|
33
|
+
if (!block || typeof block !== 'object')
|
|
34
|
+
continue;
|
|
35
|
+
const rec = block;
|
|
36
|
+
const type = rec.type;
|
|
37
|
+
if (typeof rec.text !== 'string')
|
|
38
|
+
continue;
|
|
39
|
+
if (type === 'text' || extraTypes.includes(String(type)))
|
|
40
|
+
parts.push(rec.text);
|
|
41
|
+
}
|
|
42
|
+
return parts.join('');
|
|
43
|
+
}
|
|
44
|
+
function messageText(message) {
|
|
45
|
+
if (typeof message === 'string')
|
|
46
|
+
return message;
|
|
47
|
+
if (!message || typeof message !== 'object')
|
|
48
|
+
return '';
|
|
49
|
+
return blocksText(message.content);
|
|
50
|
+
}
|
|
51
|
+
function asRecord(value) {
|
|
52
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
53
|
+
return null;
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function parseClaudeLike(raw, filename, allowAgentFile) {
|
|
57
|
+
if (!allowAgentFile && path.basename(filename).startsWith('agent-'))
|
|
58
|
+
return null;
|
|
59
|
+
const session = {
|
|
60
|
+
sessionId: path.basename(filename, '.jsonl'),
|
|
61
|
+
cwd: null,
|
|
62
|
+
messages: [],
|
|
63
|
+
};
|
|
64
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
65
|
+
if (!line.trim())
|
|
66
|
+
continue;
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = JSON.parse(line);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const rec = asRecord(parsed);
|
|
75
|
+
if (!rec)
|
|
76
|
+
continue;
|
|
77
|
+
if (typeof rec.cwd === 'string' && rec.cwd.trim() && !session.cwd)
|
|
78
|
+
session.cwd = rec.cwd;
|
|
79
|
+
if (typeof rec.sessionId === 'string' && rec.sessionId.trim())
|
|
80
|
+
session.sessionId = rec.sessionId;
|
|
81
|
+
if (rec.type === 'workspace-directories' || rec.type === 'runtime-config' || rec.type === 'active-leaf') {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (rec.type !== 'user' && rec.type !== 'assistant')
|
|
85
|
+
continue;
|
|
86
|
+
pushText(session.messages, rec.type, messageText(rec.message));
|
|
87
|
+
}
|
|
88
|
+
return session;
|
|
89
|
+
}
|
|
90
|
+
function codexRole(payload) {
|
|
91
|
+
if (payload.role === 'user' || payload.type === 'user_message')
|
|
92
|
+
return 'user';
|
|
93
|
+
if (payload.role === 'assistant' || payload.type === 'agent_message')
|
|
94
|
+
return 'assistant';
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
function codexText(payload) {
|
|
98
|
+
if (typeof payload.message === 'string')
|
|
99
|
+
return payload.message;
|
|
100
|
+
if (typeof payload.text === 'string')
|
|
101
|
+
return payload.text;
|
|
102
|
+
const fromMessage = messageText(payload.message);
|
|
103
|
+
if (fromMessage.trim())
|
|
104
|
+
return fromMessage;
|
|
105
|
+
return blocksText(payload.content, ['input_text', 'output_text']);
|
|
106
|
+
}
|
|
107
|
+
function parseCodex(raw, filename) {
|
|
108
|
+
const session = {
|
|
109
|
+
sessionId: path.basename(filename, '.jsonl'),
|
|
110
|
+
cwd: null,
|
|
111
|
+
messages: [],
|
|
112
|
+
};
|
|
113
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
114
|
+
if (!line.trim())
|
|
115
|
+
continue;
|
|
116
|
+
let parsed;
|
|
117
|
+
try {
|
|
118
|
+
parsed = JSON.parse(line);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const rec = asRecord(parsed);
|
|
124
|
+
const payload = rec ? asRecord(rec.payload) : null;
|
|
125
|
+
if (!rec || !payload)
|
|
126
|
+
continue;
|
|
127
|
+
if (rec.type === 'session_meta') {
|
|
128
|
+
if (typeof payload.id === 'string' && payload.id.trim())
|
|
129
|
+
session.sessionId = payload.id;
|
|
130
|
+
if (typeof payload.cwd === 'string' && payload.cwd.trim())
|
|
131
|
+
session.cwd = payload.cwd;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (rec.type !== 'event_msg' && rec.type !== 'response_item')
|
|
135
|
+
continue;
|
|
136
|
+
const role = codexRole(payload);
|
|
137
|
+
if (!role)
|
|
138
|
+
continue;
|
|
139
|
+
pushText(session.messages, role, codexText(payload));
|
|
140
|
+
}
|
|
141
|
+
return session;
|
|
142
|
+
}
|
|
143
|
+
function parseCursor(raw, filename) {
|
|
144
|
+
const session = {
|
|
145
|
+
sessionId: path.basename(filename, '.jsonl'),
|
|
146
|
+
cwd: null,
|
|
147
|
+
messages: [],
|
|
148
|
+
};
|
|
149
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
150
|
+
if (!line.trim())
|
|
151
|
+
continue;
|
|
152
|
+
let parsed;
|
|
153
|
+
try {
|
|
154
|
+
parsed = JSON.parse(line);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const rec = asRecord(parsed);
|
|
160
|
+
if (!rec)
|
|
161
|
+
continue;
|
|
162
|
+
if (typeof rec.cwd === 'string' && rec.cwd.trim() && !session.cwd)
|
|
163
|
+
session.cwd = rec.cwd;
|
|
164
|
+
if (rec.role !== 'user' && rec.role !== 'assistant')
|
|
165
|
+
continue;
|
|
166
|
+
const text = typeof rec.message === 'string' ? rec.message : messageText(rec.message);
|
|
167
|
+
pushText(session.messages, rec.role, text);
|
|
168
|
+
}
|
|
169
|
+
return session;
|
|
170
|
+
}
|
|
171
|
+
/** 解析一份已经确认落在来源根里的会话文件。agent-*.jsonl 在 Claude 形状下返回 null。 */
|
|
172
|
+
export function parseForeignSession(shape, filename, raw) {
|
|
173
|
+
switch (shape) {
|
|
174
|
+
case 'claude-jsonl':
|
|
175
|
+
return parseClaudeLike(raw, filename, false);
|
|
176
|
+
case 'qoder-jsonl':
|
|
177
|
+
return parseClaudeLike(raw, filename, true);
|
|
178
|
+
case 'codex-rollout':
|
|
179
|
+
return parseCodex(raw, filename);
|
|
180
|
+
case 'cursor-transcript':
|
|
181
|
+
return parseCursor(raw, filename);
|
|
182
|
+
default: {
|
|
183
|
+
const neverShape = shape;
|
|
184
|
+
return neverShape;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Steer 的「从其他智能体导入」路由。扫描和复制都在产品里,存储仍用宿主的会话库。
|
|
3
|
+
*/
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import { matchPackBackendRoute, registerPackBackendRoutes, } from '@steerable/agent-shell/local-backend/pack-backend-routes';
|
|
6
|
+
import { importForeignSelection, scanForeignImport } from './foreign-import/scan.js';
|
|
7
|
+
export const FOREIGN_IMPORT_PREFIX = '/api/v2/steer/foreign-import/';
|
|
8
|
+
export const FOREIGN_IMPORT_SCAN_ROUTE = '/api/v2/steer/foreign-import/scan';
|
|
9
|
+
export const FOREIGN_IMPORT_RUN_ROUTE = '/api/v2/steer/foreign-import/import';
|
|
10
|
+
function detail(status, message) {
|
|
11
|
+
return { status, data: { detail: message } };
|
|
12
|
+
}
|
|
13
|
+
/** ids 必须是字符串数组。重复的 id 只处理一次。 */
|
|
14
|
+
export function foreignImportIds(body) {
|
|
15
|
+
if (!body || typeof body !== 'object')
|
|
16
|
+
return null;
|
|
17
|
+
const ids = body.ids;
|
|
18
|
+
if (!Array.isArray(ids) || ids.some((id) => typeof id !== 'string'))
|
|
19
|
+
return null;
|
|
20
|
+
return [...new Set(ids)];
|
|
21
|
+
}
|
|
22
|
+
export async function handleForeignImportScan(deps) {
|
|
23
|
+
try {
|
|
24
|
+
const scan = await scanForeignImport(deps);
|
|
25
|
+
const data = { items: scan.items };
|
|
26
|
+
if (scan.ledgerWarning)
|
|
27
|
+
data.ledgerWarning = scan.ledgerWarning;
|
|
28
|
+
return { status: 200, data };
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return detail(500, 'Could not scan this Mac.');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export async function handleForeignImport(body, deps) {
|
|
35
|
+
const ids = foreignImportIds(body);
|
|
36
|
+
if (!ids)
|
|
37
|
+
return detail(400, 'ids must be an array of strings');
|
|
38
|
+
try {
|
|
39
|
+
return { status: 200, data: await importForeignSelection(deps, ids) };
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return detail(500, 'Could not copy this item.');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function liveDeps() {
|
|
46
|
+
const { getScopedStore, LOCAL_SCOPE } = await import('@steerable/agent-shell/storage/driver');
|
|
47
|
+
const { getUserDataDir } = await import('@steerable/agent-shell/runtime');
|
|
48
|
+
const { getUserSkillsDir } = await import('@steerable/agent-shell/local-backend/skill-loader');
|
|
49
|
+
const { ProjectRegistry } = await import('@steerable/agent-shell/project-registry');
|
|
50
|
+
const { createJsonStore } = await import('@steerable/agent-shell/json-store');
|
|
51
|
+
const store = getScopedStore(LOCAL_SCOPE);
|
|
52
|
+
const saved = createJsonStore({
|
|
53
|
+
name: 'agent-projects',
|
|
54
|
+
defaults: { projects: [] },
|
|
55
|
+
});
|
|
56
|
+
const projects = new ProjectRegistry({
|
|
57
|
+
get: () => saved.get('projects'),
|
|
58
|
+
set: (_key, value) => { saved.set('projects', value); },
|
|
59
|
+
mutate: (_key, update) => saved.mutate('projects', update),
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
env: process.env,
|
|
63
|
+
homedir: os.homedir(),
|
|
64
|
+
platform: process.platform,
|
|
65
|
+
userDataDir: getUserDataDir(),
|
|
66
|
+
userSkillsDir: getUserSkillsDir(),
|
|
67
|
+
store,
|
|
68
|
+
projects,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** 宿主启动时注册。重复调用直接返回,避免热重载登记两次。 */
|
|
72
|
+
export function registerSteerForeignImport() {
|
|
73
|
+
if (matchPackBackendRoute('POST', FOREIGN_IMPORT_SCAN_ROUTE))
|
|
74
|
+
return;
|
|
75
|
+
registerPackBackendRoutes('steer', FOREIGN_IMPORT_PREFIX, [
|
|
76
|
+
{
|
|
77
|
+
method: 'POST',
|
|
78
|
+
path: FOREIGN_IMPORT_SCAN_ROUTE,
|
|
79
|
+
handler: async () => handleForeignImportScan(await liveDeps()),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
method: 'POST',
|
|
83
|
+
path: FOREIGN_IMPORT_RUN_ROUTE,
|
|
84
|
+
handler: async ({ body }) => handleForeignImport(body, await liveDeps()),
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
@@ -94,5 +94,45 @@
|
|
|
94
94
|
"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)时开启;本机宿主控制端口与调试端口始终保持拦截。",
|
|
95
95
|
"Browser settings saved.": "浏览器设置已保存。",
|
|
96
96
|
"Install the command-line tool on your PATH.": "将命令行工具安装到系统 PATH。",
|
|
97
|
-
"Configure Chromium browser binary and CDP session mode.": "配置 Chromium 浏览器路径与 CDP 会话模式。"
|
|
97
|
+
"Configure Chromium browser binary and CDP session mode.": "配置 Chromium 浏览器路径与 CDP 会话模式。",
|
|
98
|
+
"Import from other agents": "从其他智能体导入",
|
|
99
|
+
"Copy tasks, skills, and experts from other agents on this computer.": "把这台电脑上其他智能体的任务、技能和专家复制过来。",
|
|
100
|
+
"Existing Steer chats, skills, and agents stay as they are.": "Steer 里已有的任务、技能和智能体保持原样。",
|
|
101
|
+
"Scan this Mac": "扫描这台 Mac",
|
|
102
|
+
"Scanning…": "正在扫描…",
|
|
103
|
+
"Scan to see tasks, skills, and experts on this Mac.": "扫描后可以看到这台 Mac 上的任务、技能和专家。",
|
|
104
|
+
"Could not scan this Mac.": "无法扫描这台 Mac。",
|
|
105
|
+
"Tasks": "任务",
|
|
106
|
+
"Skills and experts": "技能和专家",
|
|
107
|
+
"Experts": "专家",
|
|
108
|
+
"Not found": "未发现",
|
|
109
|
+
"Already imported": "已导入",
|
|
110
|
+
"An item with this name already exists and will be skipped": "已有同名项,将跳过",
|
|
111
|
+
"Trae keeps chats in an encrypted database. This import does not read it.": "Trae 的对话在加密库里,本期不读。",
|
|
112
|
+
"Doubao Work keeps tasks in the app database. This import does not read it.": "豆包工作的任务在应用数据库里,本期不读。",
|
|
113
|
+
"This Cursor chat is not a transcript file. This import does not read it.": "这条 Cursor 对话不是会话记录文件,本期不读。",
|
|
114
|
+
"This file is larger than 32 MB and was skipped": "这个文件超过 32 MB,已跳过",
|
|
115
|
+
"This item links outside its folder and was skipped": "链接指向目录外",
|
|
116
|
+
"No local expert files": "没有本地专家文件",
|
|
117
|
+
"Import selected": "导入所选",
|
|
118
|
+
"Import selected · {count}": "导入所选 · {count}",
|
|
119
|
+
"Importing…": "正在导入…",
|
|
120
|
+
"{count} messages": "{count} 条消息",
|
|
121
|
+
"{count} messages · newest 1,000 will be kept": "{count} 条消息 · 只保留最近 1,000 条",
|
|
122
|
+
"1 chat": "1 个任务",
|
|
123
|
+
"{count} chats": "{count} 个任务",
|
|
124
|
+
"1 skill": "1 个技能",
|
|
125
|
+
"{count} skills": "{count} 个技能",
|
|
126
|
+
"1 expert": "1 位专家",
|
|
127
|
+
"{count} experts": "{count} 位专家",
|
|
128
|
+
"Imported": "已导入",
|
|
129
|
+
"Skipped {count}.": "已跳过 {count}。",
|
|
130
|
+
"Failed {count}.": "失败 {count}。",
|
|
131
|
+
"Skills show up under Skills. Experts show up under Agents.": "技能会出现在 Skills 里。专家会出现在智能体里。",
|
|
132
|
+
"The import record could not be read. Items may be offered again.": "导入记录读不出来,这些项可能会再次出现。",
|
|
133
|
+
"Could not read this file.": "无法读取这个文件。",
|
|
134
|
+
"Could not copy this item.": "无法复制这项。",
|
|
135
|
+
"{source} · Global": "{source} · 国际版",
|
|
136
|
+
"{source} · CN": "{source} · 国内版",
|
|
137
|
+
"Kept the newest 1,000 messages.": "已截断,保留最近 1000 条。"
|
|
98
138
|
}
|