scientify 1.2.2 → 1.4.0
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 +38 -14
- package/README.zh.md +38 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/src/services/auto-updater.d.ts +15 -0
- package/dist/src/services/auto-updater.d.ts.map +1 -0
- package/dist/src/services/auto-updater.js +188 -0
- package/dist/src/services/auto-updater.js.map +1 -0
- package/dist/src/tools/arxiv-download.d.ts +25 -0
- package/dist/src/tools/arxiv-download.d.ts.map +1 -0
- package/dist/src/tools/arxiv-download.js +179 -0
- package/dist/src/tools/arxiv-download.js.map +1 -0
- package/dist/src/tools/{arxiv-tool.d.ts → arxiv-search.d.ts} +11 -8
- package/dist/src/tools/arxiv-search.d.ts.map +1 -0
- package/dist/src/tools/arxiv-search.js +140 -0
- package/dist/src/tools/arxiv-search.js.map +1 -0
- package/dist/src/tools/github-search-tool.d.ts +5 -1
- package/dist/src/tools/github-search-tool.d.ts.map +1 -1
- package/dist/src/tools/github-search-tool.js +10 -30
- package/dist/src/tools/github-search-tool.js.map +1 -1
- package/dist/src/tools/result.d.ts +37 -0
- package/dist/src/tools/result.d.ts.map +1 -0
- package/dist/src/tools/result.js +39 -0
- package/dist/src/tools/result.js.map +1 -0
- package/dist/src/tools/workspace.d.ts +32 -0
- package/dist/src/tools/workspace.d.ts.map +1 -0
- package/dist/src/tools/workspace.js +69 -0
- package/dist/src/tools/workspace.js.map +1 -0
- package/openclaw.plugin.json +22 -1
- package/package.json +13 -2
- package/skills/_shared/workspace-spec.md +139 -0
- package/skills/idea-generation/SKILL.md +4 -0
- package/skills/install-scientify/SKILL.md +15 -7
- package/skills/literature-survey/SKILL.md +86 -212
- package/skills/research-experiment/SKILL.md +114 -0
- package/skills/research-implement/SKILL.md +166 -0
- package/skills/research-pipeline/SKILL.md +104 -188
- package/skills/research-plan/SKILL.md +121 -0
- package/skills/research-review/SKILL.md +110 -0
- package/skills/research-survey/SKILL.md +140 -0
- package/skills/write-review-paper/SKILL.md +4 -0
- package/dist/src/tools/arxiv-tool.d.ts.map +0 -1
- package/dist/src/tools/arxiv-tool.js +0 -258
- package/dist/src/tools/arxiv-tool.js.map +0 -1
- package/skills/research-pipeline/references/prompts/implement.md +0 -135
- package/skills/research-pipeline/references/prompts/plan.md +0 -142
- package/skills/research-pipeline/references/prompts/review.md +0 -118
- package/skills/research-pipeline/references/prompts/survey.md +0 -105
- package/skills/research-pipeline/references/workspace-spec.md +0 -81
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: research-review
|
|
3
|
+
description: "Review ML implementation against plan and survey. Iterates fix-rerun-review up to 3 times. Requires ml_res.md from /research-implement."
|
|
4
|
+
metadata:
|
|
5
|
+
{
|
|
6
|
+
"openclaw":
|
|
7
|
+
{
|
|
8
|
+
"emoji": "🔍",
|
|
9
|
+
"requires": { "bins": ["python3", "uv"] },
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Research Review
|
|
15
|
+
|
|
16
|
+
**Don't ask permission. Just do it.**
|
|
17
|
+
|
|
18
|
+
**Workspace:** See `../_shared/workspace-spec.md`. Set `$W` to the active project directory.
|
|
19
|
+
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
| File | Source |
|
|
23
|
+
|------|--------|
|
|
24
|
+
| `$W/ml_res.md` | /research-implement |
|
|
25
|
+
| `$W/project/` | /research-implement |
|
|
26
|
+
| `$W/plan_res.md` | /research-plan |
|
|
27
|
+
| `$W/survey_res.md` | /research-survey |
|
|
28
|
+
|
|
29
|
+
**If `ml_res.md` is missing, STOP:** "需要先运行 /research-implement 完成代码实现"
|
|
30
|
+
|
|
31
|
+
## Output
|
|
32
|
+
|
|
33
|
+
| File | Content |
|
|
34
|
+
|------|---------|
|
|
35
|
+
| `$W/iterations/judge_v{N}.md` | 每轮审查报告 |
|
|
36
|
+
|
|
37
|
+
最终报告中 `verdict: PASS` 表示审查通过。
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Workflow
|
|
42
|
+
|
|
43
|
+
### Step 1: 审查代码
|
|
44
|
+
|
|
45
|
+
读取以下内容:
|
|
46
|
+
- `$W/plan_res.md` — 每个组件的预期
|
|
47
|
+
- `$W/survey_res.md` — 核心公式
|
|
48
|
+
- `$W/project/` — 实际代码
|
|
49
|
+
- `$W/ml_res.md` — 执行结果
|
|
50
|
+
|
|
51
|
+
### Step 2: 逐项检查
|
|
52
|
+
|
|
53
|
+
| 检查项 | 方法 |
|
|
54
|
+
|--------|------|
|
|
55
|
+
| 数据管道匹配 plan | 对比 plan Dataset Plan vs `data/` 实现 |
|
|
56
|
+
| 模型架构匹配公式 | 对比 survey 公式 vs `model/` 实现 |
|
|
57
|
+
| Loss 函数正确 | 对比 plan Training Plan vs `training/loss.py` |
|
|
58
|
+
| 评估指标正确 | 对比 plan Testing Plan vs `testing/` |
|
|
59
|
+
| [RESULT] 行存在 | 检查 ml_res.md 中的数值来源 |
|
|
60
|
+
| Loss 合理 | 非 NaN/Inf,有下降趋势 |
|
|
61
|
+
| 无 mock 数据(除非已声明) | 搜索 `# MOCK DATA` 注释 |
|
|
62
|
+
|
|
63
|
+
### Step 3: 写入审查报告
|
|
64
|
+
|
|
65
|
+
写入 `$W/iterations/judge_v1.md`:
|
|
66
|
+
|
|
67
|
+
```markdown
|
|
68
|
+
# Review v1
|
|
69
|
+
|
|
70
|
+
## Verdict: PASS / NEEDS_REVISION
|
|
71
|
+
|
|
72
|
+
## Checklist
|
|
73
|
+
- [x/✗] Dataset loading matches plan
|
|
74
|
+
- [x/✗] Model architecture matches formulas
|
|
75
|
+
- [x/✗] Loss function correct
|
|
76
|
+
- [x/✗] Training loop proper
|
|
77
|
+
- [x/✗] Evaluation metrics correct
|
|
78
|
+
- [x/✗] Results are from real execution (not fabricated)
|
|
79
|
+
|
|
80
|
+
## Issues (if NEEDS_REVISION)
|
|
81
|
+
1. **{issue}**: {description} → **Fix**: {specific fix instruction}
|
|
82
|
+
2. ...
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Step 4: 迭代(如果 NEEDS_REVISION)
|
|
86
|
+
|
|
87
|
+
循环最多 3 次:
|
|
88
|
+
|
|
89
|
+
1. 读取 `judge_v{N}.md` 的修改建议
|
|
90
|
+
2. 修改 `$W/project/` 中的代码
|
|
91
|
+
3. 重新执行:
|
|
92
|
+
```bash
|
|
93
|
+
cd $W/project && source .venv/bin/activate && python run.py --epochs 2
|
|
94
|
+
```
|
|
95
|
+
4. 读取执行输出,验证修复
|
|
96
|
+
5. 写入 `judge_v{N+1}.md`
|
|
97
|
+
6. 如果 PASS → 停止;否则继续
|
|
98
|
+
|
|
99
|
+
### Step 5: 最终判定
|
|
100
|
+
|
|
101
|
+
3 轮后仍 NEEDS_REVISION → 在最后一份 judge 中列出剩余问题,标记 `verdict: BLOCKED`,等待用户介入。
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Rules
|
|
106
|
+
|
|
107
|
+
1. 审查必须逐项对照 plan,不能只看"代码能跑"
|
|
108
|
+
2. 每个 issue 必须给出具体的修复指令(不是"请改进")
|
|
109
|
+
3. 验证修复后必须重新执行代码并检查输出
|
|
110
|
+
4. PASS 的前提:所有 checklist 项通过 + [RESULT] 数值合理
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: research-survey
|
|
3
|
+
description: "Deep analysis of downloaded papers: read .tex sources, extract core methods/formulas, map formulas to reference code, write structured notes. Requires papers already downloaded via /literature-survey."
|
|
4
|
+
metadata:
|
|
5
|
+
{
|
|
6
|
+
"openclaw":
|
|
7
|
+
{
|
|
8
|
+
"emoji": "📖",
|
|
9
|
+
},
|
|
10
|
+
}
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Research Survey (Deep Analysis)
|
|
14
|
+
|
|
15
|
+
**Don't ask permission. Just do it.**
|
|
16
|
+
|
|
17
|
+
**Workspace:** See `../_shared/workspace-spec.md`. Set `$W` to the active project directory.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
Read and verify these files exist before starting:
|
|
22
|
+
|
|
23
|
+
| File | Source |
|
|
24
|
+
|------|--------|
|
|
25
|
+
| `$W/papers/_meta/*.json` | /literature-survey |
|
|
26
|
+
| `$W/papers/_downloads/` or `$W/papers/{direction}/` | /literature-survey |
|
|
27
|
+
| `$W/repos/` (optional) | git clone in /literature-survey or manually |
|
|
28
|
+
|
|
29
|
+
**If any prerequisite is missing, STOP and report:** "需要先运行 /literature-survey 完成论文下载"
|
|
30
|
+
|
|
31
|
+
## Output
|
|
32
|
+
|
|
33
|
+
| File | Content |
|
|
34
|
+
|------|---------|
|
|
35
|
+
| `$W/notes/paper_{arxiv_id}.md` | Per-paper structured notes |
|
|
36
|
+
| `$W/survey_res.md` | Synthesis report |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Workflow
|
|
41
|
+
|
|
42
|
+
### Step 1: 收集论文列表
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
ls $W/papers/_meta/
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
读取所有 `.json` 元数据,构建论文列表。按 score 降序排列。
|
|
49
|
+
|
|
50
|
+
### Step 2: 逐篇深度分析
|
|
51
|
+
|
|
52
|
+
**对每篇论文**(优先高分论文):
|
|
53
|
+
|
|
54
|
+
#### 2.1 读 .tex 源码
|
|
55
|
+
|
|
56
|
+
找到论文的 .tex 文件(在 `_downloads/{arxiv_id}/` 或 `{direction}/{arxiv_id}/` 下),重点读取:
|
|
57
|
+
- **Method / Approach** section
|
|
58
|
+
- **Model Architecture** section
|
|
59
|
+
- 数学公式定义
|
|
60
|
+
|
|
61
|
+
如果没有 .tex(只有 PDF),基于 abstract 分析。
|
|
62
|
+
|
|
63
|
+
#### 2.2 提取核心内容
|
|
64
|
+
|
|
65
|
+
从 .tex 中提取:
|
|
66
|
+
- **核心方法**:1-2 段描述
|
|
67
|
+
- **数学公式**:至少 1 个关键公式(保留 LaTeX 格式)
|
|
68
|
+
- **创新点**:与同领域其他方法的区别
|
|
69
|
+
|
|
70
|
+
#### 2.3 映射到代码(如果 repos/ 存在)
|
|
71
|
+
|
|
72
|
+
如果 `$W/repos/` 中有相关仓库:
|
|
73
|
+
- 找到公式对应的代码实现
|
|
74
|
+
- 记录文件路径和行号
|
|
75
|
+
|
|
76
|
+
#### 2.4 写入笔记
|
|
77
|
+
|
|
78
|
+
写入 `$W/notes/paper_{arxiv_id}.md`:
|
|
79
|
+
|
|
80
|
+
```markdown
|
|
81
|
+
# {Paper Title}
|
|
82
|
+
|
|
83
|
+
- **arXiv:** {arxiv_id}
|
|
84
|
+
- **核心方法:** {1-2 sentences}
|
|
85
|
+
|
|
86
|
+
## 数学公式
|
|
87
|
+
|
|
88
|
+
$$
|
|
89
|
+
{key formula in LaTeX}
|
|
90
|
+
$$
|
|
91
|
+
|
|
92
|
+
含义:{解释}
|
|
93
|
+
|
|
94
|
+
## 代码映射
|
|
95
|
+
|
|
96
|
+
文件:`repos/{repo}/path/to/file.py:L42-L60`
|
|
97
|
+
```python
|
|
98
|
+
# relevant code excerpt (< 20 lines)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 与本研究的关系
|
|
102
|
+
|
|
103
|
+
{如何应用到当前研究}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Step 3: 综合报告
|
|
107
|
+
|
|
108
|
+
读取所有 `notes/paper_*.md`,写入 `$W/survey_res.md`:
|
|
109
|
+
|
|
110
|
+
```markdown
|
|
111
|
+
# Survey Synthesis
|
|
112
|
+
|
|
113
|
+
## 论文总览
|
|
114
|
+
- 分析论文数: {N}
|
|
115
|
+
- 涉及方向: {list}
|
|
116
|
+
|
|
117
|
+
## 核心方法对比
|
|
118
|
+
|
|
119
|
+
| 论文 | 方法 | 核心公式 | 复杂度 | 优势 |
|
|
120
|
+
|------|------|----------|--------|------|
|
|
121
|
+
| ... | ... | ... | ... | ... |
|
|
122
|
+
|
|
123
|
+
## 技术路线建议
|
|
124
|
+
|
|
125
|
+
基于以上分析,推荐的技术路线是:
|
|
126
|
+
{建议}
|
|
127
|
+
|
|
128
|
+
## 关键公式汇总
|
|
129
|
+
|
|
130
|
+
{列出所有提取的核心公式}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Rules
|
|
136
|
+
|
|
137
|
+
1. 每篇论文必须读 .tex 原文(如有),不能只读 abstract
|
|
138
|
+
2. 每篇笔记必须包含至少 1 个数学公式
|
|
139
|
+
3. 如果有 repos/,必须尝试找到公式到代码的映射
|
|
140
|
+
4. survey_res.md 必须包含方法对比表
|
|
@@ -12,8 +12,12 @@ metadata:
|
|
|
12
12
|
|
|
13
13
|
# Literature Review Writing
|
|
14
14
|
|
|
15
|
+
**Don't ask permission. Just do it.**
|
|
16
|
+
|
|
15
17
|
Guide for writing a structured literature review or survey paper from papers you've already collected. This skill helps with reading strategy, note organization, and academic writing.
|
|
16
18
|
|
|
19
|
+
**Workspace:** See `../_shared/workspace-spec.md` for directory structure. Outputs go to `$WORKSPACE/review/`.
|
|
20
|
+
|
|
17
21
|
## Prerequisites
|
|
18
22
|
|
|
19
23
|
Before starting, ensure you have:
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arxiv-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/arxiv-tool.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,eAAe;;;;;;;EA+B1B,CAAC;AA2LH,wBAAgB,eAAe;;;;;;;;;;;;2BAOE,MAAM,WAAW,OAAO;;;;EA6ExD"}
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { Type } from "@sinclair/typebox";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import * as os from "node:os";
|
|
5
|
-
import * as tar from "tar";
|
|
6
|
-
const ARXIV_API_URL = "https://export.arxiv.org/api/query";
|
|
7
|
-
const DEFAULT_MAX_RESULTS = 10;
|
|
8
|
-
const MAX_RESULTS_LIMIT = 50;
|
|
9
|
-
export const ArxivToolSchema = Type.Object({
|
|
10
|
-
query: Type.String({ description: "Search query for arXiv papers (e.g. 'graph neural network')." }),
|
|
11
|
-
max_results: Type.Optional(Type.Number({
|
|
12
|
-
description: "Maximum number of results to return (1-50). Default: 10.",
|
|
13
|
-
minimum: 1,
|
|
14
|
-
maximum: MAX_RESULTS_LIMIT,
|
|
15
|
-
})),
|
|
16
|
-
sort_by: Type.Optional(Type.String({
|
|
17
|
-
description: 'Sort order: "relevance" (default), "lastUpdatedDate", or "submittedDate".',
|
|
18
|
-
})),
|
|
19
|
-
date_from: Type.Optional(Type.String({
|
|
20
|
-
description: "Filter papers submitted after this date (YYYY-MM-DD).",
|
|
21
|
-
})),
|
|
22
|
-
download: Type.Optional(Type.Boolean({
|
|
23
|
-
description: "If true, download .tex source for each paper to output_dir. Default: false.",
|
|
24
|
-
})),
|
|
25
|
-
output_dir: Type.Optional(Type.String({
|
|
26
|
-
description: "Directory to download .tex source files into. Default: workspace/papers/",
|
|
27
|
-
})),
|
|
28
|
-
});
|
|
29
|
-
const SORT_MAP = {
|
|
30
|
-
relevance: "relevance",
|
|
31
|
-
lastupdateddate: "lastUpdatedDate",
|
|
32
|
-
submitteddate: "submittedDate",
|
|
33
|
-
};
|
|
34
|
-
function readStringParam(params, key, opts) {
|
|
35
|
-
const value = params[key];
|
|
36
|
-
if (value === undefined || value === null) {
|
|
37
|
-
if (opts?.required) {
|
|
38
|
-
throw new Error(`Missing required parameter: ${key}`);
|
|
39
|
-
}
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
return String(value);
|
|
43
|
-
}
|
|
44
|
-
function readNumberParam(params, key, opts) {
|
|
45
|
-
const value = params[key];
|
|
46
|
-
if (value === undefined || value === null)
|
|
47
|
-
return undefined;
|
|
48
|
-
const num = Number(value);
|
|
49
|
-
if (isNaN(num))
|
|
50
|
-
return undefined;
|
|
51
|
-
return opts?.integer ? Math.floor(num) : num;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Download and extract .tex source from arXiv
|
|
55
|
-
*/
|
|
56
|
-
async function downloadTexSource(arxivId, outputDir) {
|
|
57
|
-
const paperDir = path.join(outputDir, arxivId);
|
|
58
|
-
await fs.promises.mkdir(paperDir, { recursive: true });
|
|
59
|
-
const srcUrl = `https://arxiv.org/src/${arxivId}`;
|
|
60
|
-
const tarPath = path.join(paperDir, "source.tar.gz");
|
|
61
|
-
try {
|
|
62
|
-
// Try to download .tex source
|
|
63
|
-
const response = await fetch(srcUrl);
|
|
64
|
-
if (!response.ok) {
|
|
65
|
-
// Fallback to PDF
|
|
66
|
-
return await downloadPdfFallback(arxivId, outputDir);
|
|
67
|
-
}
|
|
68
|
-
const buffer = Buffer.from(await response.arrayBuffer());
|
|
69
|
-
await fs.promises.writeFile(tarPath, buffer);
|
|
70
|
-
// Check if it's actually a tar.gz or just a single file
|
|
71
|
-
const isTarGz = buffer[0] === 0x1f && buffer[1] === 0x8b;
|
|
72
|
-
if (isTarGz) {
|
|
73
|
-
// Extract tar.gz
|
|
74
|
-
await tar.x({ file: tarPath, cwd: paperDir });
|
|
75
|
-
await fs.promises.unlink(tarPath); // Remove tar.gz after extraction
|
|
76
|
-
// Find all .tex files
|
|
77
|
-
const files = await findTexFiles(paperDir);
|
|
78
|
-
if (files.length === 0) {
|
|
79
|
-
return await downloadPdfFallback(arxivId, outputDir);
|
|
80
|
-
}
|
|
81
|
-
return { success: true, format: "tex", files };
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// Single file (probably .tex directly)
|
|
85
|
-
const texPath = path.join(paperDir, "main.tex");
|
|
86
|
-
await fs.promises.rename(tarPath, texPath);
|
|
87
|
-
return { success: true, format: "tex", files: ["main.tex"] };
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
// Fallback to PDF on any error
|
|
92
|
-
return await downloadPdfFallback(arxivId, outputDir);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async function downloadPdfFallback(arxivId, outputDir) {
|
|
96
|
-
try {
|
|
97
|
-
const pdfUrl = `https://arxiv.org/pdf/${arxivId}.pdf`;
|
|
98
|
-
const response = await fetch(pdfUrl);
|
|
99
|
-
if (!response.ok) {
|
|
100
|
-
return { success: false, format: "pdf", files: [], error: `PDF download failed: ${response.status}` };
|
|
101
|
-
}
|
|
102
|
-
const pdfPath = path.join(outputDir, `${arxivId}.pdf`);
|
|
103
|
-
const buffer = Buffer.from(await response.arrayBuffer());
|
|
104
|
-
await fs.promises.writeFile(pdfPath, buffer);
|
|
105
|
-
return { success: true, format: "pdf", files: [`${arxivId}.pdf`] };
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
return { success: false, format: "pdf", files: [], error: String(error) };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async function findTexFiles(dir) {
|
|
112
|
-
const files = [];
|
|
113
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
114
|
-
for (const entry of entries) {
|
|
115
|
-
const fullPath = path.join(dir, entry.name);
|
|
116
|
-
if (entry.isDirectory()) {
|
|
117
|
-
const subFiles = await findTexFiles(fullPath);
|
|
118
|
-
files.push(...subFiles.map((f) => path.join(entry.name, f)));
|
|
119
|
-
}
|
|
120
|
-
else if (entry.name.endsWith(".tex")) {
|
|
121
|
-
files.push(entry.name);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return files;
|
|
125
|
-
}
|
|
126
|
-
function buildSearchUrl(query, maxResults, sortBy, dateFrom) {
|
|
127
|
-
let searchQuery = query;
|
|
128
|
-
if (dateFrom) {
|
|
129
|
-
// ArXiv date filter format: submittedDate:[YYYYMMDD0000+TO+*]
|
|
130
|
-
const dateFormatted = dateFrom.replace(/-/g, "");
|
|
131
|
-
searchQuery = `${query} AND submittedDate:[${dateFormatted}0000 TO 99991231]`;
|
|
132
|
-
}
|
|
133
|
-
const params = new URLSearchParams({
|
|
134
|
-
search_query: searchQuery,
|
|
135
|
-
start: "0",
|
|
136
|
-
max_results: String(maxResults),
|
|
137
|
-
sortBy,
|
|
138
|
-
sortOrder: "descending",
|
|
139
|
-
});
|
|
140
|
-
return `${ARXIV_API_URL}?${params.toString()}`;
|
|
141
|
-
}
|
|
142
|
-
function parseAtomXml(xml) {
|
|
143
|
-
const papers = [];
|
|
144
|
-
const entryRegex = /<entry>([\s\S]*?)<\/entry>/g;
|
|
145
|
-
let match;
|
|
146
|
-
while ((match = entryRegex.exec(xml)) !== null) {
|
|
147
|
-
const entry = match[1];
|
|
148
|
-
const getTag = (tag) => {
|
|
149
|
-
const m = entry.match(new RegExp(`<${tag}[^>]*>([\\s\\S]*?)<\\/${tag}>`));
|
|
150
|
-
return m ? m[1].trim() : "";
|
|
151
|
-
};
|
|
152
|
-
const title = getTag("title").replace(/\s+/g, " ");
|
|
153
|
-
const abstract = getTag("summary").replace(/\s+/g, " ");
|
|
154
|
-
const published = getTag("published");
|
|
155
|
-
const updated = getTag("updated");
|
|
156
|
-
// Extract arXiv ID from <id> tag
|
|
157
|
-
const idUrl = getTag("id");
|
|
158
|
-
const arxivId = idUrl.replace("http://arxiv.org/abs/", "").replace(/v\d+$/, "");
|
|
159
|
-
// Extract authors
|
|
160
|
-
const authors = [];
|
|
161
|
-
const authorRegex = /<author>\s*<name>([^<]+)<\/name>/g;
|
|
162
|
-
let authorMatch;
|
|
163
|
-
while ((authorMatch = authorRegex.exec(entry)) !== null) {
|
|
164
|
-
authors.push(authorMatch[1].trim());
|
|
165
|
-
}
|
|
166
|
-
// Extract PDF link
|
|
167
|
-
const pdfMatch = entry.match(/<link[^>]+title="pdf"[^>]+href="([^"]+)"/);
|
|
168
|
-
const pdfUrl = pdfMatch ? pdfMatch[1] : `https://arxiv.org/pdf/${arxivId}`;
|
|
169
|
-
// Extract categories
|
|
170
|
-
const categories = [];
|
|
171
|
-
const catRegex = /<category[^>]+term="([^"]+)"/g;
|
|
172
|
-
let catMatch;
|
|
173
|
-
while ((catMatch = catRegex.exec(entry)) !== null) {
|
|
174
|
-
categories.push(catMatch[1]);
|
|
175
|
-
}
|
|
176
|
-
if (title && arxivId) {
|
|
177
|
-
papers.push({ title, authors, abstract, arxivId, pdfUrl, published, updated, categories });
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return papers;
|
|
181
|
-
}
|
|
182
|
-
export function createArxivTool() {
|
|
183
|
-
return {
|
|
184
|
-
label: "ArXiv",
|
|
185
|
-
name: "arxiv",
|
|
186
|
-
description: "Search arXiv.org for academic papers by keyword. Returns titles, authors, abstracts, and IDs. Optionally downloads .tex source files.",
|
|
187
|
-
parameters: ArxivToolSchema,
|
|
188
|
-
execute: async (_toolCallId, rawArgs) => {
|
|
189
|
-
const params = rawArgs;
|
|
190
|
-
const query = readStringParam(params, "query", { required: true });
|
|
191
|
-
const maxResults = Math.min(readNumberParam(params, "max_results", { integer: true }) ?? DEFAULT_MAX_RESULTS, MAX_RESULTS_LIMIT);
|
|
192
|
-
const rawSort = readStringParam(params, "sort_by") ?? "relevance";
|
|
193
|
-
const sortBy = SORT_MAP[rawSort.toLowerCase()] ?? "relevance";
|
|
194
|
-
const dateFrom = readStringParam(params, "date_from");
|
|
195
|
-
const download = params.download === true || params.download === "true";
|
|
196
|
-
const outputDir = readStringParam(params, "output_dir") ??
|
|
197
|
-
path.join(os.homedir(), ".openclaw", "workspace", "papers");
|
|
198
|
-
const url = buildSearchUrl(query, maxResults, sortBy, dateFrom);
|
|
199
|
-
let response;
|
|
200
|
-
try {
|
|
201
|
-
response = await fetch(url);
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
return {
|
|
205
|
-
type: "tool_result",
|
|
206
|
-
content: JSON.stringify({
|
|
207
|
-
error: "network_error",
|
|
208
|
-
message: `Failed to reach arXiv API: ${error instanceof Error ? error.message : String(error)}`,
|
|
209
|
-
}),
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
if (!response.ok) {
|
|
213
|
-
return {
|
|
214
|
-
type: "tool_result",
|
|
215
|
-
content: JSON.stringify({
|
|
216
|
-
error: "api_error",
|
|
217
|
-
message: `arXiv API returned ${response.status}: ${response.statusText}`,
|
|
218
|
-
}),
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
const xml = await response.text();
|
|
222
|
-
const papers = parseAtomXml(xml);
|
|
223
|
-
// If download requested, download .tex source for each paper
|
|
224
|
-
let downloads;
|
|
225
|
-
if (download && papers.length > 0) {
|
|
226
|
-
await fs.promises.mkdir(outputDir, { recursive: true });
|
|
227
|
-
downloads = [];
|
|
228
|
-
for (const paper of papers) {
|
|
229
|
-
const result = await downloadTexSource(paper.arxivId, outputDir);
|
|
230
|
-
downloads.push({
|
|
231
|
-
arxiv_id: paper.arxivId,
|
|
232
|
-
format: result.format,
|
|
233
|
-
files: result.files,
|
|
234
|
-
error: result.error,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
type: "tool_result",
|
|
240
|
-
content: JSON.stringify({
|
|
241
|
-
query,
|
|
242
|
-
total: papers.length,
|
|
243
|
-
papers: papers.map((p) => ({
|
|
244
|
-
title: p.title,
|
|
245
|
-
authors: p.authors,
|
|
246
|
-
abstract: p.abstract,
|
|
247
|
-
arxiv_id: p.arxivId,
|
|
248
|
-
pdf_url: p.pdfUrl,
|
|
249
|
-
published: p.published,
|
|
250
|
-
categories: p.categories,
|
|
251
|
-
})),
|
|
252
|
-
...(downloads && { downloads, output_dir: outputDir }),
|
|
253
|
-
}),
|
|
254
|
-
};
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
//# sourceMappingURL=arxiv-tool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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M,CAAC,MAAM;oBACpB,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;wBACzB,KAAK,EAAE,CAAC,CAAC,KAAK;wBACd,OAAO,EAAE,CAAC,CAAC,OAAO;wBAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;wBACpB,QAAQ,EAAE,CAAC,CAAC,OAAO;wBACnB,OAAO,EAAE,CAAC,CAAC,MAAM;wBACjB,SAAS,EAAE,CAAC,CAAC,SAAS;wBACtB,UAAU,EAAE,CAAC,CAAC,UAAU;qBACzB,CAAC,CAAC;oBACH,GAAG,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;iBACvD,CAAC;aACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
# Implementation Guide
|
|
2
|
-
|
|
3
|
-
You are implementing an ML research project based on the plan in `workspace/plan_res.md`. The goal is a self-contained, runnable codebase in `workspace/project/`.
|
|
4
|
-
|
|
5
|
-
## Core Principles
|
|
6
|
-
|
|
7
|
-
### 1. Self-Contained Project
|
|
8
|
-
|
|
9
|
-
ALL code must reside within `workspace/project/`. No direct imports from `workspace/repos/`. Reference code should be studied, understood, and rewritten to fit the project's architecture.
|
|
10
|
-
|
|
11
|
-
When adapting reference code:
|
|
12
|
-
|
|
13
|
-
- Understand the core logic and algorithm, not just copy the syntax.
|
|
14
|
-
- Rewrite to fit consistent naming conventions and coding style.
|
|
15
|
-
- Document the origin: add a comment like `# Adapted from repos/xyz/model/attention.py`.
|
|
16
|
-
- Include all necessary utility functions — do not rely on external helpers.
|
|
17
|
-
|
|
18
|
-
### 2. Follow the Plan Exactly
|
|
19
|
-
|
|
20
|
-
Implement every component listed in `workspace/plan_res.md`:
|
|
21
|
-
|
|
22
|
-
- Every atomic definition from the Model Plan becomes a class or module.
|
|
23
|
-
- The dataset pipeline matches the Dataset Plan.
|
|
24
|
-
- The loss function matches the Training Plan formula.
|
|
25
|
-
- The evaluation matches the Testing Plan metrics.
|
|
26
|
-
|
|
27
|
-
Do not skip components. Do not substitute simpler alternatives. If a component seems wrong, flag it rather than silently changing it.
|
|
28
|
-
|
|
29
|
-
### 3. Real Data, Not Toy Data
|
|
30
|
-
|
|
31
|
-
Use the actual datasets specified in the plan. If the dataset requires downloading, write the download logic. Never substitute with random data or tiny synthetic datasets for the implementation (the quick validation uses real data with 2 epochs, not fake data).
|
|
32
|
-
|
|
33
|
-
## Project Structure
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
workspace/project/
|
|
37
|
-
model/
|
|
38
|
-
__init__.py
|
|
39
|
-
[component files matching Model Plan]
|
|
40
|
-
data/
|
|
41
|
-
__init__.py
|
|
42
|
-
dataset.py # Dataset class
|
|
43
|
-
loader.py # DataLoader configuration
|
|
44
|
-
preprocess.py # Preprocessing logic
|
|
45
|
-
training/
|
|
46
|
-
__init__.py
|
|
47
|
-
trainer.py # Training loop
|
|
48
|
-
loss.py # Loss functions
|
|
49
|
-
testing/
|
|
50
|
-
__init__.py
|
|
51
|
-
evaluator.py # Evaluation logic
|
|
52
|
-
metrics.py # Metric implementations
|
|
53
|
-
utils/
|
|
54
|
-
__init__.py
|
|
55
|
-
[shared utilities]
|
|
56
|
-
run.py # Main entry point
|
|
57
|
-
requirements.txt # All dependencies with versions
|
|
58
|
-
README.md # Brief description of the project
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Implementation Sequence
|
|
62
|
-
|
|
63
|
-
Follow this order to catch issues early:
|
|
64
|
-
|
|
65
|
-
1. **requirements.txt**: List all dependencies. Pin major versions.
|
|
66
|
-
2. **Data pipeline**: Implement dataset loading first. Verify with a small print test.
|
|
67
|
-
3. **Model architecture**: Implement each component. Verify shapes with dummy input.
|
|
68
|
-
4. **Loss function**: Implement and verify with dummy predictions.
|
|
69
|
-
5. **Training loop**: Wire everything together. Include logging.
|
|
70
|
-
6. **Evaluation**: Implement metrics and test evaluation pipeline.
|
|
71
|
-
7. **run.py**: Main entry point with argument parsing.
|
|
72
|
-
|
|
73
|
-
After each step, run a quick sanity check before moving on.
|
|
74
|
-
|
|
75
|
-
## Quick Validation Run
|
|
76
|
-
|
|
77
|
-
The first run uses 2 epochs only:
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
cd workspace/project
|
|
81
|
-
pip install -r requirements.txt
|
|
82
|
-
python run.py --epochs 2
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Expected outcomes:
|
|
86
|
-
- No import errors or missing dependencies.
|
|
87
|
-
- Loss decreases (even slightly) over 2 epochs.
|
|
88
|
-
- No NaN or Inf in loss or gradients.
|
|
89
|
-
- Evaluation metrics produce reasonable (not necessarily good) numbers.
|
|
90
|
-
- Memory usage stays within limits.
|
|
91
|
-
|
|
92
|
-
If the run fails, debug and fix before reporting. Common issues:
|
|
93
|
-
- Shape mismatches: print tensor shapes at each step.
|
|
94
|
-
- OOM: reduce batch size or model size for validation.
|
|
95
|
-
- Data loading errors: verify file paths and formats.
|
|
96
|
-
|
|
97
|
-
## Debugging Tips
|
|
98
|
-
|
|
99
|
-
- Add `print(f"tensor.shape = {tensor.shape}")` at critical points during initial debugging.
|
|
100
|
-
- Use `torch.autograd.set_detect_anomaly(True)` to catch gradient issues.
|
|
101
|
-
- If training is unstable, check learning rate and gradient norms.
|
|
102
|
-
- Remove debugging prints before the final version.
|
|
103
|
-
|
|
104
|
-
## Implementation Report
|
|
105
|
-
|
|
106
|
-
After the quick validation succeeds, write `workspace/ml_res.md`:
|
|
107
|
-
|
|
108
|
-
```markdown
|
|
109
|
-
# Implementation Report
|
|
110
|
-
|
|
111
|
-
## Components Implemented
|
|
112
|
-
- [List each module with brief description]
|
|
113
|
-
|
|
114
|
-
## Quick Validation Results
|
|
115
|
-
- Epochs: 2
|
|
116
|
-
- Final training loss: [value]
|
|
117
|
-
- Validation metrics: [values]
|
|
118
|
-
- Runtime: [time]
|
|
119
|
-
- GPU memory: [peak usage]
|
|
120
|
-
|
|
121
|
-
## Deviations from Plan
|
|
122
|
-
- [Any changes made and why]
|
|
123
|
-
|
|
124
|
-
## Known Issues
|
|
125
|
-
- [Any issues encountered]
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## Rules
|
|
129
|
-
|
|
130
|
-
1. Never import from `workspace/repos/` — adapt and rewrite instead.
|
|
131
|
-
2. Never use toy/synthetic data — use real datasets from the plan.
|
|
132
|
-
3. Never skip plan components — implement everything or flag the issue.
|
|
133
|
-
4. Always validate with 2 epochs before declaring success.
|
|
134
|
-
5. Always write `requirements.txt` with pinned versions.
|
|
135
|
-
6. If you cannot resolve an issue after 3 attempts, document the problem and ask the user.
|