Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/math-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

使用前按[工具配置说明](../../scripts/math-tools/README.md)准备本机依赖、组装清单,并让新运行选择该清单。普通 CAS 结果应带上输入、系数域和假设;证书应连同原模型交付。同一条结论进入正式证明时仍由[原题 Lean 验收器](../../src/solver/evaluation.ts)独立检查。

在原生 Skill 团队中,Lead 和成员的任务说明会给出本工作区可直接运行的 Lean 检查命令。已启用数学工具时,常用入口按用途提示,完整配置与命令示例保存在该成员的 `.scratch/theoremos-help.md` 的 `math-tools` 一节。例如,配置声明提供 SymPy 时用 `math-python`;如果已有假设足以完成证明,可以直接检查 Lean 文件。成员可把计算的输入、关键输出及其适用条件发给使用者,让对方复核、调整任务或使用正式交付。

## 可直接重跑的例子

在已启用工具配置的终端中,从仓库根目录执行:
Expand Down
7 changes: 6 additions & 1 deletion research/PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Version: v1
Status: Implemented(隔离分支的本地功能验收;未启用真实求解)
Updated: 2026-11-16
Updated: 2026-11-23

## 已确认的目标

Expand Down Expand Up @@ -43,6 +43,8 @@ Updated: 2026-11-16

## 当前阶段与最小功能验收场景

数学工具的首轮功能验收在本地原生团队进行:检查 Lead 和成员能否按任务选用当前环境中的工具、实际执行并使用结果。Web worker 的依赖与部署单独验收;本地协议回放也不能说明真实模型的选用质量。另以两道不点名工具的新题观察真实模型,一题适合精确计算、一题直接 Lean 证明即可,分别报告自主选用与整题验收。见[决策 0006](decisions/0006-local-native-math-tools-first.md)、[决策 0007](decisions/0007-blind-local-tool-selection.md)。

当前先验收协作功能。以下场景由已确认目标和既有验收保证导出;本地验证使用受控会话和实际协议进程,不调用真实模型。

1. Lead 可派发至少两个并行研究任务;子 Agent 有各自的会话和可写工作区,能保存不同的 Lean 证明。
Expand Down Expand Up @@ -91,8 +93,11 @@ Updated: 2026-11-16

## 本地验收证据

2026-11-23 调整工具指引后,本机扩展配置的常驻工具摘要为 315 字节;完整清单和样例移入各自工作区帮助,Lean 命令使用实际工作区和项目相对文件名。在[新版两道真实模型盲测](/data/lzh/workspace/outputs/theoremos/20261123-native-tools-v2-blind.KBKkrtQX/report.md)中,3 次 `check-lean` 都选对文件,两题均独立通过:整数题用标准库 Python 求出见证并写入 Lean,命题题直接使用假设。两题均由 Lead 完成,未调用扩展数学命令。另一次[受控原生回放](/data/lzh/workspace/outputs/theoremos/20261123-native-tools-v2-blind.KBKkrtQX/native-replay/attempt-1/report.json)中,成员从自己的帮助发现 Gfan 并执行,Lead 用 SymPy 复核收件结果并拒绝错误候选;这项记录说明工具可被发现、交接和使用,不代表真实模型自发派工。

| 范围 | 验证 |
| --- | --- |
| 本地数学工具(2026-11-23) | 真实模型在同一构建、扩展工具配置和 Skill 下完成两道新题,均通过本地独立 Lean 验收。整数题用系统 Python 自写计算得到见证,曾因未使用 `math-python` 导入 SymPy 失败;命题题仅用假设。两题均未派工。另一次脚本回放验证原生成员用 Gfan 计算、Lead 收件后用 SymPy 复核,不能据此认定模型会自主协作。[盲测报告](/data/lzh/workspace/outputs/theoremos/20261123-native-tool-blind.Kq7sliPu/report.md) |
| 持续协作 | [管理层测试](../tests/agentResearchTeam.test.ts):真实 Git/Lean,受控会话;覆盖异步到达、线程跟进、消息、成员复用、预算、恢复、错误反馈与停写。 |
| 正式交付 | [证明测试](../tests/agentTeamProof.test.ts):真实 Git/Lean;覆盖精确声明、未授权改动、冲突、过期证据、来源变更及合并前后退出恢复。 |
| 原生执行 | [协议端到端测试](../tests/agentTeamSolver.test.ts):实际 Codex adapter、动态工具 RPC、bwrap 和四份冻结 bundle;双子 Agent 提交 helper,Lead 两次恢复并采纳。错误 helper 经真实 Lean 拒绝后,Lead 显式派工,同一 child thread 收到自身错误及新任务并修正,Lead 采纳后完成原题;同时核对身份及角色工具。实际 CLI 入口完成 Lead/子 Agent 依赖准备、环境投影、全部原目标的独立 S3 Lean 验收及结果保存。回复由本地协议 peer 控制,健康检查仅访问临时本机服务。 |
Expand Down
16 changes: 16 additions & 0 deletions research/decisions/0006-local-native-math-tools-first.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
id: "0006"
title: 数学工具先在本地原生团队验收
status: accepted
date: "2026-11-23"
decided_by: 用户(数学工具首轮验收范围 Q1)
related:
- research/PROTOCOL.md
- docs/math-tools/README.md
---

# 0006 — 数学工具先在本地原生团队验收

首轮在本地新版 Lead 和子 Agent 上验收选用数学工具、执行命令和使用结果。可选扩展配置已经安装在本机,可以直接观察工具在成员工作区里是否可用、结果是否到达使用者。另一种选择是首轮同时验收 Web;容器需要自行安装工具及其运行依赖,留待单独处理。

本地结论只适用于受测配置和命令。脚本指定工具后成功执行,可以验证原生协作链路,不能据此认定模型会自主选择同一工具,或认为整题已通过 Lean 验收。
14 changes: 14 additions & 0 deletions research/decisions/0007-blind-local-tool-selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
id: "0007"
title: 以两道不点名工具的新题观察真实模型选用
status: accepted
date: "2026-11-23"
decided_by: 用户(本地工具验收层次 Q2)
related:
- research/PROTOCOL.md
- research/decisions/0006-local-native-math-tools-first.md
---

# 0007 — 以两道不点名工具的新题观察真实模型选用

除了用受控回放验收原生协作链路,本轮还在相同配置上交给真实模型两道新题,题面不提示使用哪种工具。一题适合精确计算,另一题直接用 Lean 就能完成。这样可以分别观察有计算需要时是否有效选用、没有需要时是否避免无益动作。两道题只提供具体行为样例,不代表总体解题率或因果增益。
2 changes: 1 addition & 1 deletion skills/theoremos-research/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Conduct sustained mathematical research in a TheoremOS workspace, u

Work toward the frozen original statement. Choose the mathematical approach, research decomposition and next experiment from the evidence available. Read the actual owned sources and relevant definitions early. Once a claim or library application can be tested, save a focused Lean probe and inspect its result before building more work on it.

The current host assignment fixes your role, owned paths and available tools. Use native editing, shell and search within its permissions; delegation also requires an exposed, permitted tool. Read `.scratch/theoremos-help.md` for this run's commands and delivery interface.
The current host assignment fixes your role, owned paths and available tools. Use native editing, shell and search within its permissions; delegation also requires an exposed, permitted tool. Choose a tool when its answer would change the next step. A direct proof can go straight to the supplied Lean check. For an experiment, look up the relevant command in this run's `.scratch/theoremos-help.md`, which also gives the delivery interface.

When the host selects native AgentControl, use the exposed native collaboration tools for spawn, followup, message, wait, listing and interruption. `theoremos_team` then handles mathematical tasks, source handoffs and checked-result adoption. Historical `theoremos_team` transport examples below apply only when those operations are advertised. Follow the run's current transport and target identities.

Expand Down
2 changes: 2 additions & 0 deletions skills/theoremos-research/references/parallel-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ For example, send the consumer the exact candidate type, the hypotheses that wor
- When a finding changes an assignment, put one line such as `Based on: research:<artifactId>` in the native spawn or `followup_task` message. Give the new scope in the body. Keep any `Profiles:` header on the first line.
- For formal reuse, use `adopt` with the checked delivery ID and the consumer workspace. The host records the integration receipt when the write succeeds.

For a computational finding, send its intended consumer the domain and assumptions, the input and command, and the decisive output (for example, a witness or a failed constraint). A plotted pattern is a conjecture until checked. Keep reproducible details in `RESEARCH.md`; a path into your private scratch directory alone is unusable by a peer.

Use a fixed research or delivery ID when you do not have the message ID. If another member takes over, give them that fixed reference and the first open goal so they can continue without access to the earlier member's working files.

Use these milestones to keep collaboration connected; no fixed message count, polling interval or mandatory proof method is imposed.
Expand Down
2 changes: 2 additions & 0 deletions skills/theoremos-research/references/team-roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Send the smallest usable Lean type or the first extra hypothesis the extension n

For a short alternate route investigation, name the test that will decide the route. For example, ask whether a library theorem applies with the exact hypotheses of the current consumer. If it needs a stronger hypothesis, send that hypothesis and the failed application. Lead decides whether to keep the current route or assign the missing bridge.

When a missing witness, suspected counterexample or unclear boundary motivates a calculation, give the member the mathematical question, assumptions and intended consumer. Leave the choice of tool to the member. A finite search or picture can suggest where to look; ask for the witness, failed assumption or testable claim the consumer can use. If the result affects the proof, use it in a check or say how it changes the assignment.

When you commission a Lean helper, agree on its qualified name, type and where the consumer will use it. Write that call in your owned proof draft while the member proves the helper. The name can remain unresolved until adoption. To test the surrounding argument earlier, use a scratch example that takes the proposed type as a hypothesis. Leave the helper definition to its owner, including any equivalent local `have`; a same-name placeholder can also conflict with the delivered declaration. If the route changes, tell the member before taking over.

Before spawning, decide who will write the original proof. If you intend to write it, give the member a named input you will use. If you hand it over, tell the member both sides of the assignment, for example: “You own the original proof; I will test whether this library lemma supplies the hypothesis you need and send you the result.” Do that work in your own workspace and leave the original proof to the member. A spare slot, a backup proof, or your duty to inspect the finished work does not supply a second task. With no separate question, continue on your own. If independent reconstruction is itself required evidence, name the decision that needs two independent proofs and preserve that independence.
Expand Down
55 changes: 45 additions & 10 deletions src/math/mathTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,64 @@ export function readMathTools(root: string): MathTools {
}

/** Per-worker tool state must keep the same anchor even when the shell changes directories. */
export function mathToolsUsageInstruction(tools: MathTools, worktree?: string): string {
const commands = new Set(tools.tools.flatMap(tool => tool.commands));
function referenceSearchUsage(tools: MathTools, worktree?: string): string {
if (!tools.tools.some(tool => tool.commands.includes('reference-search'))) return '';
const runDir = path.join(worktree ?? '/ABSOLUTE_WORKER_WORKTREE', '.scratch/reference-search');
const quotedRunDir = "'" + runDir.replaceAll("'", "'\\''") + "'";
return (commands.has('math-python')
? 'Use math-python for the installed NumPy, SciPy, SymPy and PySAT dependencies; /usr/bin/python3 is suitable for standard-library-only scripts. A missing module in system Python does not mean the mathematics environment lacks it.\n' : '') +
(commands.has('reference-search')
? `Keep reference-search state under this worker's fixed absolute directory: reference-search --run-dir ${quotedRunDir} search 'QUERY' --limit 6, then reference-search --run-dir ${quotedRunDir} read REF-0123456789ABCDEF --term 'KEYWORD' --window 650. Replace the example REF id with a returned id. Reuse the identical --run-dir prefix for every stateful command, including after cd and for subcommand help. ` +
return `Keep reference-search state under this worker's fixed absolute directory: reference-search --run-dir ${quotedRunDir} search 'QUERY' --limit 6, then reference-search --run-dir ${quotedRunDir} read REF-0123456789ABCDEF --term 'KEYWORD' --window 650. Replace the example REF id with a returned id. Reuse the identical --run-dir prefix for every stateful command, including after cd and for subcommand help. ` +
'Reuse saved text with find REF --term \'KEYWORD\' --offset 0 or open REF --start-line 1 --count 80; continue returned next_offset or line handles to inspect the relevant proof and its limitations. ' +
'For independent queries, use search-batch PLAN.json --workers 2 with {"searches":[{"query":"PUBLIC_MATHEMATICAL_QUERY","reason":"specific missing inference"}]}; dependent queries follow the newly read evidence. ' +
'For a relevant paper, follow REF --direction references --limit 4 (or --direction citations) discovers additional unread leads. Read a useful lead before citing it. ' +
'Provider errors are failed retrievals, not evidence that no paper or theorem exists. A partial search retains useful hits; read those hits and use the same search with --retry-failed only for failed provider requests. Use --refresh when new retrieval is needed. ' +
'Search titles/snippets, abstract and page_text reads do not establish that the complete proof was read. Inspect content_scope; use read REF --refresh to retry a saved abstract when a full-text route is available, then save the source URL, locator, assumptions and exact consumer adaptation.\n' : '') +
'Search titles/snippets, abstract and page_text reads do not establish that the complete proof was read. Inspect content_scope; use read REF --refresh to retry a saved abstract when a full-text route is available, then save the source URL, locator, assumptions and exact consumer adaptation.\n';
}

export function mathToolsUsageInstruction(tools: MathTools, worktree?: string): string {
return (tools.tools.some(tool => tool.commands.includes('math-python'))
? 'Use math-python for the installed NumPy, SciPy, SymPy and PySAT dependencies; /usr/bin/python3 is suitable for standard-library-only scripts. A missing module in system Python does not mean the mathematics environment lacks it.\n' : '') +
referenceSearchUsage(tools, worktree) +
'For check-lean JSON, save stdout separately from stderr progress (for example, > "$TMPDIR/check.json" 2> "$TMPDIR/check.log") and parse only stdout. Its --file is relative to --workspace; do not repeat the Lean project prefix.\n';
}

/** Worker guidance: tools explore and find certificates; only Lean grants acceptance. */
export function mathToolsInstruction(tools: MathTools, worktree?: string): string {
function mathToolsCatalog(tools: MathTools): string {
return `Installed mathematics tools (on PATH, manifest ${path.join(tools.root, 'manifest.json')}):\n` +
tools.tools.map(tool => `- ${tool.name} ${tool.version} [${tool.commands.join(', ')}]: ${tool.purpose}`).join('\n') +
'\nUse them to compute examples, test conjectures, search counterexamples, simplify expressions and find certificates or witnesses. ' +
'Run them from a directory under $TMPDIR after mkdir -p "$TMPDIR": some write output beside their input or in the current directory. ' +
'Bound every run with timeout SECONDS and at most 4 threads, and keep printed output small. ' +
'Their results are advisory and never proof acceptance: restate a useful finding as a Lean statement and prove it, using the computed certificate or witness where it helps. ' +
'Record the command, input and decisive output in RESEARCH.md.\n' + mathToolsUsageInstruction(tools, worktree);
'Record the command, input and decisive output in RESEARCH.md.\n';
}

/** Worker guidance: tools explore and find certificates; only Lean grants acceptance. */
export function mathToolsInstruction(tools: MathTools, worktree?: string): string {
return mathToolsCatalog(tools) + mathToolsUsageInstruction(tools, worktree);
}

/** Short choices for a native team; complete manifest and runnable examples for its worktree help. */
export function mathToolGuide(tools: MathTools, worktree: string): { summary: string; detail: string } {
const commands = new Set(tools.tools.flatMap(tool => tool.commands));
const routes: string[] = [], examples: string[] = [];
const python = tools.tools.find(tool => tool.commands.includes('math-python'));
const bin = '"$' + MATH_TOOLS_ROOT_ENV + '/bin/';
if (python && /\bsympy\b/iu.test(python.purpose)) {
routes.push('Exact or symbolic calculation: use math-python for SymPy; python3 is the system interpreter.');
examples.push('# Exact prime factors (prime: exponent)\ntimeout 20 ' + bin + 'math-python" -c \'from sympy import factorint; print(factorint(84))\'');
} else if (python) routes.push('For the Python modules listed in this profile, use math-python; python3 is the system interpreter.');
else if (commands.has('sage')) routes.push('Exact algebra: sage.');
else if (commands.has('gp')) routes.push('Number-theoretic computations: gp.');

const smt = ['z3', 'cvc5'].find(command => commands.has(command));
if (smt) {
routes.push(`To test a constraint or find a counterexample: ${smt}.`);
examples.push('# Is there an integer strictly between zero and one? Expected: unsat.\n' +
"printf '%s\\n' '(set-logic QF_LIA)' '(declare-const x Int)' '(assert (and (< 0 x) (< x 1)))' '(check-sat)' | timeout 20 " +
bin + smt + '" ' + (smt === 'z3' ? '-in' : '--lang smt2'));
}
if (commands.has('loogle-search')) routes.push('To look for a Lean declaration by its type: loogle-search.');
if (commands.has('visual-python')) routes.push('If a plot can reveal a boundary case or test a geometric guess: visual-python.');
else if (commands.has('dot')) routes.push('If a diagram can clarify graph structure: dot.');
const exampleText = examples.length ? '\nExamples (substitute the inputs for your question):\n```sh\n' + examples.join('\n\n') + '\n```\n' : '';
return { summary: ['Optional math tools for this run.', ...routes].join(' '),
detail: mathToolsCatalog(tools) + referenceSearchUsage(tools, worktree) + exampleText };
}
Loading
Loading