Cairn is a general-purpose AI state-space search engine, validated first on autonomous penetration testing. Sometimes misspelled as Carin.
Python aiai-agentai-cybersecurityai-hackerai-hackingblackbox-testingctfctf-toolsllmpenetration-testingpentestingred-teamingsecurity-automationsecurity-tools
feat: add optional project bootstrap and skip it when no worker supports the task
leixiao11b0256467e3
diff --git a/cairn/src/cairn/dispatcher/scheduler/loop.py b/cairn/src/cairn/dispatcher/scheduler/loop.pyindex 89ea6aa..77eb546 100644--- a/cairn/src/cairn/dispatcher/scheduler/loop.py+++ b/cairn/src/cairn/dispatcher/scheduler/loop.py@@ -215,7 +215,10 @@ class DispatcherLoop:if self._is_initial_project(project):if project.project.reason is not None:return False- return self._dispatch_initial_project(project)+ if self._project_requires_bootstrap(project):+ return self._dispatch_initial_project(project)+ export_yaml = self.client.export_project(summary.id)+ return self._dispatch_reason(project, export_yaml, "initial")if project.project.reason is None:reason_trigger = self._reason_trigger(project)if reason_trigger is not None:@@ -595,6 +598,13 @@ class DispatcherLoop:return Truereturn all(self._is_bootstrap_intent(intent) for intent in project.intents)+ def _project_requires_bootstrap(self, project: ProjectDetail) -> bool:+ if not project.project.bootstrap_enabled:+ return False+ if self._get_bootstrap_intent(project) is not None:+ return True+ return any("bootstrap" in worker.task_types for worker in self.config.workers)+def _create_bootstrap_intent(self, project_id: str) -> Intent | None:response = self.client.create_intent(project_id,diff --git a/cairn/src/cairn/server/db.py b/cairn/src/cairn/server/db.pyindex c2e87cc..903a39e 100644--- a/cairn/src/cairn/server/db.py+++ b/cairn/src/cairn/server/db.py@@ -21,6 +21,7 @@ CREATE TABLE IF NOT EXISTS projects (id TEXT PRIMARY KEY,title TEXT NOT NULL,status TEXT NOT NULL DEFAULT 'active',+ bootstrap_enabled INTEGER NOT NULL DEFAULT 1,created_at TEXT NOT NULL,reason_worker TEXT,reason_trigger TEXT,@@ -89,6 +90,17 @@ def configure(path: Path) -> None:_db_path.parent.mkdir(parents=True, exist_ok=True)with get_conn() as conn:conn.executescript(SCHEMA)+ _ensure_project_columns(conn)+++def _ensure_project_columns(conn: sqlite3.Connection) -> None:+ columns = {row["name"] for row in conn.execute("PRAGMA table_info(projects)")}+ if "bootstrap_enabled" not in columns:+ conn.execute("ALTER TABLE projects ADD COLUMN bootstrap_enabled INTEGER NOT NULL DEFAULT 1")+ if "bootstrap_mode" in columns:+ conn.execute(+ "UPDATE projects SET bootstrap_enabled = CASE WHEN bootstrap_mode = 'disabled' THEN 0 ELSE 1 END"+ )@contextmanagerdiff --git a/cairn/src/cairn/server/models.py b/cairn/src/cairn/server/models.pyindex a3ad1c4..bfab318 100644--- a/cairn/src/cairn/server/models.py+++ b/cairn/src/cairn/server/models.py@@ -47,6 +47,7 @@ class ProjectMeta(BaseModel):id: strtitle: strstatus: Literal["active", "stopped", "completed"]+ bootstrap_enabled: boolcreated_at: strreason: ProjectReason | None = None@@ -83,6 +84,7 @@ class CreateProjectRequest(BaseModel):title: strorigin: strgoal: str+ bootstrap_enabled: bool = Truehints: list[CreateHintInline] | None = None@field_validator("title", "origin", "goal")diff --git a/cairn/src/cairn/server/routers/export.py b/cairn/src/cairn/server/routers/export.pyindex 08d9ec6..e789a0d 100644--- a/cairn/src/cairn/server/routers/export.py+++ b/cairn/src/cairn/server/routers/export.py@@ -63,6 +63,7 @@ def _export_yaml(conn, project_id: str) -> str:"title": proj["title"],"origin": origin_desc,"goal": goal_desc,+ "bootstrap_enabled": bool(proj["bootstrap_enabled"]),}}diff --git a/cairn/src/cairn/server/routers/projects.py b/cairn/src/cairn/server/routers/projects.pyindex 9802b7d..53cd5d6 100644--- a/cairn/src/cairn/server/routers/projects.py+++ b/cairn/src/cairn/server/routers/projects.py@@ -61,6 +61,7 @@ def list_projects():id=row["id"],title=row["title"],status=row["status"],+ bootstrap_enabled=bool(row["bootstrap_enabled"]),created_at=row["created_at"],reason=project_reason_from_row(row),fact_count=row["fact_count"],@@ -80,8 +81,8 @@ def create_project(body: CreateProjectRequest):now = utcnow()conn.execute(- "INSERT INTO projects (id, title, status, created_at) VALUES (?, ?, 'active', ?)",- (pid, body.title, now),+ "INSERT INTO projects (id, title, status, bootstrap_enabled, created_at) VALUES (?, ?, 'active', ?, ?)",+ (pid, body.title, body.bootstrap_enabled, now),)conn.execute("INSERT INTO facts (id, project_id, description) VALUES (?, ?, ?)",@@ -103,7 +104,14 @@ def create_project(body: CreateProjectRequest):hints.append(Hint(id=hid, content=h.content, creator=h.creator, created_at=now))return ProjectDetail(- project=ProjectMeta(id=pid, title=body.title, status="active", created_at=now, reason=None),+ project=ProjectMeta(+ id=pid,+ title=body.title,+ status="active",+ bootstrap_enabled=body.bootstrap_enabled,+ created_at=now,+ reason=None,+ ),facts=[Fact(id="origin", description=body.origin),Fact(id="goal", description=body.goal),diff --git a/cairn/src/cairn/server/services.py b/cairn/src/cairn/server/services.pyindex 58a5f3c..f3741c4 100644--- a/cairn/src/cairn/server/services.py+++ b/cairn/src/cairn/server/services.py@@ -199,6 +199,7 @@ def project_meta_from_row(row: sqlite3.Row) -> ProjectMeta:id=row["id"],title=row["title"],status=row["status"],+ bootstrap_enabled=bool(row["bootstrap_enabled"]),created_at=row["created_at"],reason=project_reason_from_row(row),)diff --git a/cairn/src/cairn/server/static/index.html b/cairn/src/cairn/server/static/index.htmlindex 3040c09..a469185 100644--- a/cairn/src/cairn/server/static/index.html+++ b/cairn/src/cairn/server/static/index.html@@ -801,6 +801,10 @@<input x-model="newProject.title" placeholder="Project title" class="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-brand-100 focus:border-brand-400 transition placeholder:text-slate-300"><textarea x-model="newProject.origin" placeholder="Origin — starting point" rows="2" class="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-brand-100 focus:border-brand-400 transition placeholder:text-slate-300"></textarea><textarea x-model="newProject.goal" placeholder="Goal — what to achieve" rows="2" class="w-full px-3 py-2 border border-slate-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-brand-100 focus:border-brand-400 transition placeholder:text-slate-300"></textarea>+ <label class="flex items-center gap-2 px-1 text-sm text-slate-600">+ <input type="checkbox" x-model="newProject.bootstrap" class="h-4 w-4 rounded border-slate-300 text-brand-500 focus:ring-brand-200">+ <span>Run bootstrap attempt</span>+ </label><div><div class="flex items-center justify-between mb-2">@@ -1097,7 +1101,7 @@ function cairnApp() {exportProjectId: '',showDeleteModal: false,- newProject: { title: '', origin: '', goal: '', hints: [{ content: '' }] },+ newProject: { title: '', origin: '', goal: '', bootstrap: true, hints: [{ content: '' }] },intentForm: { description: '' },concludeForm: { description: '', intentId: '' },completeForm: { description: '' },@@ -3260,12 +3264,17 @@ function cairnApp() {try {const actor = this.actorName();const hintContents = this.newProject.hints.filter(h => h.content?.trim());- const body = { title: this.newProject.title, origin: this.newProject.origin, goal: this.newProject.goal };+ const body = {+ title: this.newProject.title,+ origin: this.newProject.origin,+ goal: this.newProject.goal,+ bootstrap_enabled: this.newProject.bootstrap+ };const hints = hintContents.map(h => ({ content: h.content.trim(), creator: actor }));if (hints.length > 0) body.hints = hints;const data = await this.api('POST', '/projects', body);this.showNewProject = false;- this.newProject = { title:'', origin:'', goal:'', hints: [{ content:'' }] };+ this.newProject = { title:'', origin:'', goal:'', bootstrap: true, hints: [{ content:'' }] };await this.loadProjects();await this.openProject(data.project.id);this.showToast('Project created');diff --git a/cairn/tests/conftest.py b/cairn/tests/conftest.pyindex 734ead5..8d835e4 100644--- a/cairn/tests/conftest.py+++ b/cairn/tests/conftest.py@@ -49,6 +49,7 @@ def make_project(*, intents: list[Intent] | None = None) -> ProjectDetail:id="proj_001",title="test",status="active",+ bootstrap_enabled=True,created_at="2026-01-01T00:00:00Z",),facts=[@@ -172,4 +173,3 @@ class FakeDriver:def extract_response_text(self, stdout: str, _stderr: str) -> str:return stdout-diff --git a/cairn/tests/test_db_migrations.py b/cairn/tests/test_db_migrations.pynew file mode 100644index 0000000..8393a61--- /dev/null+++ b/cairn/tests/test_db_migrations.py@@ -0,0 +1,70 @@+from __future__ import annotations++import sqlite3++from cairn.server import db+++def test_configure_adds_bootstrap_enabled_to_legacy_projects_table(tmp_path, monkeypatch) -> None:+ path = tmp_path / "legacy.db"+ with sqlite3.connect(path) as conn:+ conn.execute(+ """+ CREATE TABLE projects (+ id TEXT PRIMARY KEY,+ title TEXT NOT NULL,+ status TEXT NOT NULL DEFAULT 'active',+ created_at TEXT NOT NULL,+ reason_worker TEXT,+ reason_trigger TEXT,+ reason_started_at TEXT,+ reason_last_heartbeat_at TEXT+ )+ """+ )+ conn.execute(+ "INSERT INTO projects (id, title, created_at) VALUES ('proj_001', 'legacy', '2026-01-01T00:00:00Z')"+ )++ monkeypatch.setattr(db, "_db_path", None)+ db.configure(path)++ with db.get_conn() as conn:+ row = conn.execute("SELECT bootstrap_enabled FROM projects WHERE id = 'proj_001'").fetchone()+ assert row["bootstrap_enabled"] == 1+++def test_configure_maps_disabled_bootstrap_mode_to_false(tmp_path, monkeypatch) -> None:+ path = tmp_path / "intermediate.db"+ with sqlite3.connect(path) as conn:+ conn.execute(+ """+ CREATE TABLE projects (+ id TEXT PRIMARY KEY,+ title TEXT NOT NULL,+ status TEXT NOT NULL DEFAULT 'active',+ bootstrap_mode TEXT NOT NULL DEFAULT 'auto',+ created_at TEXT NOT NULL,+ reason_worker TEXT,+ reason_trigger TEXT,+ reason_started_at TEXT,+ reason_last_heartbeat_at TEXT+ )+ """+ )+ conn.execute(+ "INSERT INTO projects (id, title, bootstrap_mode, created_at) VALUES ('proj_001', 'disabled', 'disabled', '2026-01-01T00:00:00Z')"+ )+ conn.execute(+ "INSERT INTO projects (id, title, bootstrap_mode, created_at) VALUES ('proj_002', 'enabled', 'enabled', '2026-01-01T00:00:00Z')"+ )++ monkeypatch.setattr(db, "_db_path", None)+ db.configure(path)++ with db.get_conn() as conn:+ rows = conn.execute("SELECT id, bootstrap_enabled FROM projects ORDER BY id").fetchall()+ assert [(row["id"], row["bootstrap_enabled"]) for row in rows] == [+ ("proj_001", 0),+ ("proj_002", 1),+ ]diff --git a/cairn/tests/test_mock_end_to_end.py b/cairn/tests/test_mock_end_to_end.pyindex b7c6c4f..7b5b904 100644--- a/cairn/tests/test_mock_end_to_end.py+++ b/cairn/tests/test_mock_end_to_end.py@@ -196,7 +196,13 @@ def _phase(return json.dumps(payload)-def _config(*, bootstrap: str, reason: str, explore: str) -> DispatchConfig:+def _config(+ *,+ bootstrap: str,+ reason: str,+ explore: str,+ task_types: list[str] | None = None,+) -> DispatchConfig:return DispatchConfig.model_validate({"server": "in-process",@@ -222,7 +228,7 @@ def _config(*, bootstrap: str, reason: str, explore: str) -> DispatchConfig:{"name": "mock-worker","type": "mock",- "task_types": ["bootstrap", "reason", "explore"],+ "task_types": task_types or ["bootstrap", "reason", "explore"],"max_running": 1,"priority": 0,"env": {@@ -341,3 +347,32 @@ def test_mock_scheduler_runs_reason_explore_reason_complete_chain(http_client: T]assert any("/reason_execute-" in path and "f002" in content for _, path, content in containers.writes)assert any("/explore_execute-" in path and "f001" in content for _, path, content in containers.writes)+++def test_mock_scheduler_enabled_project_skips_bootstrap_when_worker_does_not_support_it(+ http_client: TestClient,+) -> None:+ client = InProcessClient(http_client)+ containers = LocalContainerManager()+ loop = _loop(+ _config(+ bootstrap=_phase("complete"),+ reason=_phase("complete", zero_outcomes=["intent"]),+ explore=_phase("fact"),+ task_types=["reason", "explore"],+ ),+ client,+ containers,+ )+ project_id = _create_project(http_client)++ try:+ _dispatch_and_wait(loop)+ project = client.get_project(project_id)+ finally:+ loop.close()++ assert project.project.status == "completed"+ assert [(intent.description, intent.to) for intent in project.intents] == [+ ("mock complete from origin", "goal")+ ]diff --git a/cairn/tests/test_scheduler_logic.py b/cairn/tests/test_scheduler_logic.pyindex eabd95b..1333e98 100644--- a/cairn/tests/test_scheduler_logic.py+++ b/cairn/tests/test_scheduler_logic.py@@ -30,6 +30,7 @@ def _summary(project_id: str, status: str) -> ProjectSummary:id=project_id,title=project_id,status=status,+ bootstrap_enabled=True,created_at="2026-01-01T00:00:00Z",fact_count=2,intent_count=0,@@ -150,6 +151,97 @@ def test_new_fact_dispatches_reason_before_unclaimed_explore_intent() -> None:assert dispatched == [("reason", "facts:3->4")]+def test_initial_enabled_project_without_bootstrap_worker_dispatches_reason() -> None:+ loop = _loop()+ config = make_config()+ loop.config = config.model_copy(+ update={+ "workers": [+ config.workers[0].model_copy(update={"task_types": ["reason", "explore"]})+ ]+ }+ )+ loop.futures = {}+ project = make_project()+ project.facts = project.facts[:2]+ loop.container_manager = type("Containers", (), {"container_name": lambda _self, project_id: project_id})()+ loop.client = type(+ "Client",+ (),+ {+ "get_project": lambda _self, _project_id: project,+ "export_project": lambda _self, _project_id: "graph",+ },+ )()+ dispatched: list[tuple[str, str]] = []+ loop._dispatch_initial_project = lambda _project: dispatched.append(("bootstrap", "")) or True+ loop._dispatch_reason = lambda _project, _graph, trigger: dispatched.append(("reason", trigger)) or True++ assert loop._try_dispatch_project(_summary("proj_001", "active"))+ assert dispatched == [("reason", "initial")]+++def test_initial_disabled_project_skips_configured_bootstrap_worker() -> None:+ loop = _loop()+ loop.config = make_config()+ loop.futures = {}+ project = make_project()+ project.project.bootstrap_enabled = False+ project.facts = project.facts[:2]+ loop.container_manager = type("Containers", (), {"container_name": lambda _self, project_id: project_id})()+ loop.client = type(+ "Client",+ (),+ {+ "get_project": lambda _self, _project_id: project,+ "export_project": lambda _self, _project_id: "graph",+ },+ )()+ dispatched: list[tuple[str, str]] = []+ loop._dispatch_initial_project = lambda _project: dispatched.append(("bootstrap", "")) or True+ loop._dispatch_reason = lambda _project, _graph, trigger: dispatched.append(("reason", trigger)) or True++ assert loop._try_dispatch_project(_summary("proj_001", "active"))+ assert dispatched == [("reason", "initial")]+++def test_initial_enabled_project_without_bootstrap_worker_skips_bootstrap() -> None:+ loop = _loop()+ config = make_config()+ loop.config = config.model_copy(+ update={+ "workers": [+ config.workers[0].model_copy(update={"task_types": ["reason", "explore"]})+ ]+ }+ )+ project = make_project()+ project.project.bootstrap_enabled = True+ project.facts = project.facts[:2]++ assert not loop._project_requires_bootstrap(project)+++def test_initial_enabled_project_keeps_existing_bootstrap_intent_when_workers_change() -> None:+ loop = _loop()+ config = make_config()+ loop.config = config.model_copy(+ update={+ "workers": [+ config.workers[0].model_copy(update={"task_types": ["reason", "explore"]})+ ]+ }+ )+ project = make_project(intents=[make_intent()])+ project.project.bootstrap_enabled = True+ project.facts = project.facts[:2]+ project.intents[0].description = "bootstrap"+ project.intents[0].creator = "dispatcher.bootstrap"+ project.intents[0].from_ = ["origin"]++ assert loop._project_requires_bootstrap(project)++def test_cancel_inactive_tasks_marks_stopped_and_deleted_projects() -> None:loop = _loop()stopped = TaskCancellation()diff --git a/cairn/tests/test_server_api.py b/cairn/tests/test_server_api.pyindex e178e4c..72f4c27 100644--- a/cairn/tests/test_server_api.py+++ b/cairn/tests/test_server_api.py@@ -26,6 +26,7 @@ def _create_project(client: TestClient) -> str:},)assert response.status_code == 201+ assert response.json()["project"]["bootstrap_enabled"] is Truereturn response.json()["project"]["id"]@@ -175,3 +176,34 @@ def test_live_reason_lease_rejects_competing_worker(client: TestClient) -> None:assert response.status_code == 409assert "worker-a" in response.json()["detail"]+++def test_project_creation_persists_disabled_bootstrap_and_exports_it(client: TestClient) -> None:+ response = client.post(+ "/projects",+ json={+ "title": "no bootstrap",+ "origin": "start",+ "goal": "finish",+ "bootstrap_enabled": False,+ },+ )++ assert response.status_code == 201+ project_id = response.json()["project"]["id"]+ assert client.get(f"/projects/{project_id}").json()["project"]["bootstrap_enabled"] is False+ assert "bootstrap_enabled: false" in client.get(f"/projects/{project_id}/export?format=yaml").text+++def test_project_creation_rejects_invalid_bootstrap_enabled(client: TestClient) -> None:+ response = client.post(+ "/projects",+ json={+ "title": "invalid bootstrap",+ "origin": "start",+ "goal": "finish",+ "bootstrap_enabled": "sometimes",+ },+ )++ assert response.status_code == 422diff --git a/docs/specs/dispatcher-design.md b/docs/specs/dispatcher-design.mdindex b9424ce..bda448d 100644--- a/docs/specs/dispatcher-design.md+++ b/docs/specs/dispatcher-design.md@@ -20,7 +20,7 @@ Agent 不直接认领 Intent,不直接 heartbeat,不直接调用 Cairn API2. Dispatcher 是唯一的协议写入者和控制面;Agent 不 claim、不 heartbeat、不直接调用 Cairn API。3. 超时策略按任务类型定义;`bootstrap` 和 `explore` 都支持“第一阶段执行 + timeout / parse-fail 后用同一 session 进入 conclude 收尾”的双阶段模式。4. Prompt 以 markdown 文件形式随代码分发;支持按 prompt 组切换;Worker 行为由 `claudecode`、`codex`、`mock` 等 driver 实现;`dispatch.yaml` 只描述运行期参数。-5. 调度上,项目初始态优先 `bootstrap`;非初始态项目内始终先 `explore`、后 `reason`;`reason` 的并发约束通过服务端的项目级 `project.reason` lease 表达为“单项目最多一个”,`bootstrap` 的并发约束是“单项目最多一个保留 bootstrap intent 且最多一个 bootstrap 任务”,跨项目允许并行;`runtime.interval` 被刻意复用为主循环节拍和带 claim 任务的 heartbeat 周期。+5. 调度上,项目初始态按 `project.bootstrap_enabled` 和 Worker 能力决定优先 `bootstrap` 或直接 `reason`;非初始态出现新 Fact / Hint 等新态势时优先 `reason`,否则优先消费可认领的 `explore` intent;`reason` 的并发约束通过服务端的项目级 `project.reason` lease 表达为“单项目最多一个”,`bootstrap` 的并发约束是“单项目最多一个保留 bootstrap intent 且最多一个 bootstrap 任务”,跨项目允许并行;`runtime.interval` 被刻意复用为主循环节拍和带 claim 任务的 heartbeat 周期。6. Worker 按独立的 LLM 并发配额单元建模;同一个 key 不拆成多个 Worker,因此并发控制使用 `workers[].max_running` 即可。7. 运行日志按“状态变化优先”设计:稳定轮询、正常 heartbeat、重复 skip 原则上不刷屏;容器创建、任务派发、容器内新进程启动、健康检查、超时、收尾、释放 intent、worker 进入短暂不可选窗口等事件必须可见。8. 项目容器收尾不应阻塞主调度循环;多个已完成项目的容器 cleanup 可以并行进行。@@ -139,7 +139,7 @@ Dispatcher 会同时读取两类数据:6. Worker 输出结构化 JSON7. Dispatcher 解析结果,并调用 `POST /projects/{project_id}/complete`、`POST /projects/{project_id}/intents`、`POST /projects/{project_id}/intents/{intent_id}/conclude`、`POST /projects/{project_id}/intents/{intent_id}/release` 或 `POST /projects/{project_id}/reason/release`-项目若被切到 `stopped`,这条主链路会在下一轮短路:Dispatcher 不再把该项目纳入 active 调度集合,会先取消本地仍在运行的任务,再转入容器 cleanup 流程并停止项目容器。对 `bootstrap` / `explore` 来说,被 `stopped` 取消后不会再进入 conclude fallback,因此不会再额外落 Fact。项目恢复为 `active` 后,Dispatcher 会重新读取图状态,再决定是继续 `explore`、进入 `reason`,还是在初始态重新 `bootstrap`。项目若在 `completed` 后被服务端 `reopen`,对 Dispatcher 来说也等价于“重新变成 active 且图上多了一个新 fact”;下一轮会按普通 active 项目继续调度。+项目若被切到 `stopped`,这条主链路会在下一轮短路:Dispatcher 不再把该项目纳入 active 调度集合,会先取消本地仍在运行的任务,再转入容器 cleanup 流程并停止项目容器。对 `bootstrap` / `explore` 来说,被 `stopped` 取消后不会再进入 conclude fallback,因此不会再额外落 Fact。项目恢复为 `active` 后,Dispatcher 会重新读取图状态,再决定是继续 `explore`、进入 `reason`,还是在初始态依据 `project.bootstrap_enabled` 和 Worker 能力重新选择 `bootstrap` 或 `reason`。项目若在 `completed` 后被服务端 `reopen`,对 Dispatcher 来说也等价于“重新变成 active 且图上多了一个新 fact”;下一轮会按普通 active 项目继续调度。Worker 选择规则:@@ -209,7 +209,7 @@ dispatcher/| 任务 | 触发条件 | 输入 | 输出 | 超时策略 || --- | --- | --- | --- | --- |-| `bootstrap` | 项目 `active`;facts 只有 `origin` 和 `goal`;当前没有普通 intent;允许不存在 bootstrap intent,或只存在保留的 open `bootstrap` intent | `{origin}`、`{goal}`、`{hints}` | 主阶段成功时固定返回 `fact + complete`;收尾阶段只返回 `fact` | 双阶段:`timeout` 后可进入 `conclude_timeout` 收尾;两阶段都失败则 release 保留 intent,下轮仍按新项目重试 |+| `bootstrap` | 项目 `active`;`project.bootstrap_enabled=true`,且配置中存在支持 `bootstrap` 的 Worker 或项目已经存在保留 bootstrap intent;facts 只有 `origin` 和 `goal`;当前没有普通 intent;允许不存在 bootstrap intent,或只存在保留的 open `bootstrap` intent | `{origin}`、`{goal}`、`{hints}` | 主阶段成功时固定返回 `fact + complete`;收尾阶段只返回 `fact` | 双阶段:`timeout` 后可进入 `conclude_timeout` 收尾;两阶段都失败则 release 保留 intent,下轮仍按新项目重试 || `reason` | 项目 `active`;当前项目无未认领 intent;当前项目内无其他 `reason`;首次触发或满足“新态势”重触发条件 | `{graph_yaml}`、`{fact_ids}`、`{open_intents}` | `complete` 对象;或 `intent` 对象;或空 `data` | 仅 `timeout`;超时或非法结果直接作废,不写图 || `explore` | 项目 `active`;存在一个当前可认领的未结论 intent | `{graph_yaml}`、`{intent_id}`、`{intent_description}` | 一个 Fact 结论描述 | 单阶段:超时直接作废;双阶段:超时或输出解析失败时可进入 `conclude` 收尾 |@@ -218,6 +218,7 @@ dispatcher/#### 触发条件- 当前项目仍然是 `active`+- `project.bootstrap_enabled = true`,且配置中存在支持 `bootstrap` 的 Worker 或项目已经存在保留 bootstrap intent- facts 恰好只有 `origin` 和 `goal`- intents 为空,或只存在保留的 open `bootstrap` intent- 保留 `bootstrap` intent 的约定固定为:@@ -542,12 +543,12 @@ for project in running_projects_round_robin:if has_dispatchable_bootstrap(project):dispatch_bootstrap(project)continue- if has_dispatchable_explore(project):- dispatch_explore(project)- continueif has_dispatchable_reason(project):dispatch_reason(project)continue+ if has_dispatchable_explore(project):+ dispatch_explore(project)+ continueif running_project_count < runtime.max_running_projects:maybe_start_one_new_project()@@ -557,9 +558,9 @@ if running_project_count < runtime.max_running_projects:对于单个项目,Dispatcher 读完整项目状态后,按下面顺序调度:-1. 如果项目仍处于初始态,优先确保存在且只存在一个保留 `bootstrap` intent,并只调度 `bootstrap`-2. 对非初始态项目,如果存在未认领 intent,优先派发 `explore`-3. 只有在没有未认领 intent 时,才考虑派发 `reason`+1. 如果项目仍处于初始态,先按 `project.bootstrap_enabled` 和 Worker 能力决定路径:未开启或没有支持 `bootstrap` 的 Worker 时直接 `reason`,否则执行 `bootstrap`;若已经存在保留 bootstrap intent,则继续该阶段+2. 如果满足“新态势”重触发条件,优先派发 `reason`+3. 否则如果存在未认领 intent,派发 `explore`4. `reason` 的去重按“态势”做,而不是按总图变化做:首次只有在当前没有任何 open intent 时才触发;之后只有当前 Fact / Hint 数量增加,或项目从“存在 open intents”进入“没有 open intents”时,才重新触发5. 如果 `reason` 返回 `data.complete`,Dispatcher 调用 `POST /projects/{project_id}/complete`6. 如果 `reason` 没有返回 `data.complete` 且带 `intent`,Dispatcher 调用 `POST /projects/{project_id}/intents`@@ -567,7 +568,7 @@ if running_project_count < runtime.max_running_projects:另外:-- 初始态项目里,如果 `bootstrap` intent 已被 claim,则这一轮不再派发 `reason` 或普通 `explore`+- 初始态项目里,如果选择了 `bootstrap` 路径且 bootstrap intent 已被 claim,则这一轮不再派发 `reason` 或普通 `explore`- 即使同一项目里已经有进行中的 `explore`,也允许继续派发一个 `reason` 任务- 但前提不是“刚新增了 intent”,而是“确实出现了新的 Fact / Hint 等新态势”;仅仅因为上一个 `reason` 刚创建了新的 intent,不应该立刻再次 `reason`- 仍然要求当前没有未认领 intent、当前项目内没有其他 `reason` 任务在运行、且没有超过 `runtime.max_project_workers`diff --git a/docs/specs/server-protocol.md b/docs/specs/server-protocol.mdindex 3cd39ac..dc93029 100644--- a/docs/specs/server-protocol.md+++ b/docs/specs/server-protocol.md@@ -104,6 +104,7 @@ Hint 代表外部补充的高纬输入,不属于探索执行本身。因此项idtitle # 项目名称status # "active" | "stopped" | "completed"+bootstrap_enabled # 是否允许消费者在初始态运行 bootstrap,默认 truecreated_atreason # 当前项目级 reason lease,null 表示当前无人执行 reason```@@ -221,6 +222,7 @@ Body:"id": "proj_001","title": "xx渗透测试","status": "active",+ "bootstrap_enabled": true,"created_at": "2026-03-21T10:00:00Z","reason": {"worker": "dispatcher-worker-A",@@ -241,7 +243,7 @@ Body:#### POST /projects-创建新项目。`origin` 和 `goal` 写入 `facts` 作为特殊 Fact。`hints` 可选。+创建新项目。`origin` 和 `goal` 写入 `facts` 作为特殊 Fact。`hints` 可选。`bootstrap_enabled` 可选,默认为 `true`;为 `false` 时消费者跳过 bootstrap。即使为 `true`,消费者没有 bootstrap 能力时也可直接进入 reason。Body:@@ -250,6 +252,7 @@ Body:"title": "xx渗透测试","origin": "目标 http://192.168.1.10","goal": "拿到 flag",+ "bootstrap_enabled": true,"hints": [{ "content": "优先看 web 服务", "creator": "human" },{ "content": "注意 80 端口", "creator": "human" }@@ -271,6 +274,7 @@ Body:"id": "proj_001","title": "xx渗透测试","status": "active",+ "bootstrap_enabled": true,"created_at": "2026-03-21T10:00:00Z","reason": {"worker": "dispatcher-worker-A",@@ -657,6 +661,7 @@ project:title: "xx渗透测试"origin: "目标 http://192.168.1.10"goal: "拿到 flag"+ bootstrap_enabled: truehints:- content: "优先看 web 服务"@@ -794,6 +799,7 @@ intents:3. 若项目仍处于最初阶段:典型判定是 facts 只有 `origin` 和 `goal`,且没有普通 intent;某些消费者会允许“没有任何 intent”,或“只存在保留 bootstrap intent”都视为初始态+ 若 `project.bootstrap_enabled=false`,或消费者不具备 bootstrap 能力,则直接进入 reason;a. 若尚不存在保留 bootstrap intent:POST /projects/{id}/intents{ from: ["origin"], description: "bootstrap", creator: "dispatcher.bootstrap", worker: null }