Skip to content

Commit b50bfb0

Browse files
committed
feat: add host-supervised background execution
1 parent 76c1a1a commit b50bfb0

26 files changed

Lines changed: 2248 additions & 903 deletions

‎.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helloloop",
3-
"version": "0.8.4",
3+
"version": "0.8.5",
44
"description": "HelloLoop 的 Claude Code 原生插件元数据,用于多 CLI 宿主分发。",
55
"author": {
66
"name": "HelloLoop"

‎.codex-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helloloop",
3-
"version": "0.8.4",
3+
"version": "0.8.5",
44
"description": "面向 Codex CLI、Claude Code、Gemini CLI 的多宿主开发工作流插件,Codex 路径为首发与参考实现。",
55
"author": {
66
"name": "HelloLoop"

‎README.md‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ npx helloloop gemini <PATH> 接续完成剩余开发
9797
- 如果 backlog 清空了,但主线终态复核仍发现文档目标还有缺口,`HelloLoop` 会自动重新分析并继续推进
9898
- 如果模型只做了一半就想停下来给“下一步建议”,`HelloLoop` 会优先按主线目标继续推进,而不是把半成品当完成
9999

100+
## 后台监督执行
101+
102+
从 `Codex CLI`、`Claude Code`、`Gemini CLI` 这些宿主里发起 `HelloLoop` 时,确认自动执行后会默认切到 **detached supervisor + host lease** 模式:
103+
104+
- 当前对话 turn 就算被误按 `Esc`、被宿主暂停、或当前工具调用被中断,后台 supervisor 仍会继续
105+
- 原有的 15 分钟级恢复、健康探测、同引擎自动恢复,也会继续由这个后台 supervisor 接管
106+
- 这不是“当前进程死掉后每 15 分钟重新拉起一遍主进程”,而是 supervisor 本身持续存活,所以恢复链不会因为当前 turn 消失而断掉
107+
- 真正的停止边界改成 **宿主租约**:只要宿主 CLI 窗口 / 进程还活着,任务就继续;如果宿主窗口真的关闭,HelloLoop 才会停止当前子进程并把任务回退为 `pending`
108+
109+
常见场景:
110+
111+
- 在 `Codex` / `Claude` / `Gemini` 宿主里运行 `helloloop`:确认后默认转入后台执行,可用 `helloloop status` 查看进度
112+
- 在普通终端里运行 `npx helloloop run-once --supervised` 或 `npx helloloop run-loop --supervised`:即使中途 `Ctrl+C` 当前命令,只要终端窗口没关,后台 supervisor 仍会继续
113+
100114
## 无人值守恢复
101115

102116
`HelloLoop` 的设计目标不是“跑一轮停一轮”,而是启动前确认一次,启动后持续无人值守推进。
@@ -122,10 +136,10 @@ npx helloloop gemini <PATH> 接续完成剩余开发
122136

123137
但要特别注意:
124138

125-
- 上述自动恢复只在 **当前 `HelloLoop` 主进程仍然存活** 时生效
126-
- 如果用户手动按 `Esc` / `Ctrl+C`、直接关闭宿主窗口、结束终端进程,或宿主自身把这次会话彻底中止,当前这条自动恢复链也会一起结束
127-
- 也就是说,这类“人为 / 宿主级取消”不会让 `HelloLoop` 脱离当前会话,在后台继续每 15 分钟自行重试
128-
- 发生这类中断后,需要你重新执行 `npx helloloop`、`npx helloloop next`,或回到宿主里再次显式调用 `helloloop` 来接续
139+
- 在 `Codex` / `Claude` / `Gemini` 宿主里,当前 turn 被误按 `Esc`、当前工具调用被取消,或当前会话暂时暂停时,只要宿主窗口本身还活着,后台 supervisor 仍会继续,原有自动恢复节奏也会继续生效
140+
- 如果真正关闭了宿主 CLI 窗口、终端进程结束,或宿主租约已经失效,HelloLoop 会停止当前子进程,并把未完成任务回退为 `pending`
141+
- 也就是说:**当前 turn 取消 ≠ 停止 HelloLoop;关闭宿主窗口 = 停止 HelloLoop**
142+
- 宿主窗口已经关闭后,HelloLoop 不会再脱离宿主自行无限后台驻留;这时需要你重新打开宿主并再次显式调用 `helloloop` 来接续
129143

130144
## 全局告警配置
131145

@@ -400,6 +414,7 @@ npx helloloop
400414
| `-y` / `--yes` | 跳过执行确认直接开始;但如果未显式指定引擎,会直接报错而不是自动选引擎 |
401415
| `--repo <dir>` | 高级覆盖:显式指定项目仓库 |
402416
| `--docs <dir|file>` | 高级覆盖:显式指定开发文档 |
417+
| `--supervised` | 在普通终端里显式启用 detached supervisor;当前命令被打断时,后台执行仍可继续 |
403418
| `--rebuild-existing` | 项目与文档冲突时,自动清理现有项目后重建 |
404419
| `--host <name>` | 安装宿主:`codex` / `claude` / `gemini` / `all` |
405420
| `--config-dir <dir>` | 状态目录名,默认 `.helloloop` |
@@ -470,7 +485,7 @@ git push origin vX.Y.Z-beta.N
470485

471486
- 正式版本使用 npm `latest` 渠道,beta 版本使用 npm `beta` 渠道
472487
- 如果测试、版本校验或打包检查失败,npm 发布与 GitHub Release 都不会继续执行
473-
- `0.8.4` 起已补齐 Codex Structured Outputs 严格 schema 兼容,并修复快退出 CLI 在 CI 中可能触发的 `stdin EPIPE` 问题,避免发布工作流被非业务性故障打断
488+
- `0.8.5` 起已补齐 host-aware supervisor 后台执行链路:宿主内自动执行默认后台化,当前 turn 被 `Esc` / cancel 不再直接打断 HelloLoop 主线
474489
- GitHub Release 阶段现已改为使用官方 `gh` CLI + `generate-notes` API 创建 / 更新 release,不再依赖会触发 Node runtime deprecation warning 的第三方 action
475490

476491
## 宿主写入范围

‎hosts/claude/marketplace/plugins/helloloop/.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helloloop",
3-
"version": "0.8.4",
3+
"version": "0.8.5",
44
"description": "HelloLoop 的 Claude Code 原生插件元数据,用于多 CLI 宿主分发。",
55
"author": {
66
"name": "HelloLoop"

‎hosts/gemini/extension/gemini-extension.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helloloop",
3-
"version": "0.8.4",
3+
"version": "0.8.5",
44
"description": "HelloLoop 的 Gemini CLI 原生扩展,用于按开发文档接续推进项目开发。",
55
"contextFileName": "GEMINI.md",
66
"excludeTools": [

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helloloop",
3-
"version": "0.8.4",
3+
"version": "0.8.5",
44
"description": "面向 Codex CLI、Claude Code、Gemini CLI 的多宿主开发工作流插件",
55
"author": "HelloLoop",
66
"license": "Apache-2.0",
@@ -30,7 +30,7 @@
3030
"templates"
3131
],
3232
"scripts": {
33-
"test": "node --test tests/analyze_cli.test.mjs tests/analyze_intent_cli.test.mjs tests/analyze_runtime_failure.test.mjs tests/output_schema_contract.test.mjs tests/engine_process_support.test.mjs tests/engine_selection_cli.test.mjs tests/cli_surface.test.mjs tests/cli_doctor_surface.test.mjs tests/host_lifecycle_integrity.test.mjs tests/host_single_host_integrity.test.mjs tests/install_script.test.mjs tests/mainline_continuation.test.mjs tests/multi_host_runtime.test.mjs tests/process_shell.test.mjs tests/prompt_guardrails.test.mjs tests/ralph_loop.test.mjs tests/runtime_recovery.test.mjs tests/plugin_bundle.test.mjs"
33+
"test": "node --test tests/analyze_cli.test.mjs tests/analyze_intent_cli.test.mjs tests/analyze_runtime_failure.test.mjs tests/output_schema_contract.test.mjs tests/engine_process_support.test.mjs tests/engine_selection_cli.test.mjs tests/cli_surface.test.mjs tests/cli_doctor_surface.test.mjs tests/host_lifecycle_integrity.test.mjs tests/host_single_host_integrity.test.mjs tests/install_script.test.mjs tests/mainline_continuation.test.mjs tests/multi_host_runtime.test.mjs tests/process_shell.test.mjs tests/prompt_guardrails.test.mjs tests/ralph_loop.test.mjs tests/runtime_recovery.test.mjs tests/plugin_bundle.test.mjs tests/supervisor_runtime.test.mjs"
3434
},
3535
"engines": {
3636
"node": ">=20"

‎src/analyzer.mjs‎

Lines changed: 20 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import path from "node:path";
22

3-
import { summarizeBacklog, selectNextTask } from "./backlog.mjs";
3+
import { summarizeBacklog } from "./backlog.mjs";
44
import { nowIso, writeJson, writeText, readTextIfExists } from "./common.mjs";
55
import {
6-
loadBacklog,
76
loadPolicy,
87
loadProjectConfig,
98
scaffoldIfMissing,
@@ -17,205 +16,17 @@ import {
1716
rememberEngineSelection,
1817
resolveEngineSelection,
1918
} from "./engine_selection.mjs";
19+
import {
20+
buildAnalysisSummaryText,
21+
buildCurrentWorkspaceDiscovery,
22+
normalizeAnalysisPayload,
23+
persistAnalysisFailure,
24+
renderAnalysisState,
25+
summarizeFailedAnalysisResult,
26+
} from "./analyzer_support.mjs";
2027
import { runEngineTask } from "./process.mjs";
2128
import { buildAnalysisPrompt } from "./analyze_prompt.mjs";
2229

23-
function renderAnalysisState(context, backlog, analysis) {
24-
const summary = summarizeBacklog(backlog);
25-
const nextTask = selectNextTask(backlog);
26-
27-
return [
28-
"## 当前状态",
29-
`- backlog 文件:${path.relative(context.repoRoot, context.backlogFile).replaceAll("\\", "/")}`,
30-
`- 总任务数:${summary.total}`,
31-
`- 已完成:${summary.done}`,
32-
`- 待处理:${summary.pending}`,
33-
`- 进行中:${summary.inProgress}`,
34-
`- 失败:${summary.failed}`,
35-
`- 阻塞:${summary.blocked}`,
36-
`- 当前任务:${nextTask ? nextTask.title : "无"}`,
37-
`- 最近结果:${analysis.summary.currentState}`,
38-
`- 下一建议:${analysis.summary.nextAction}`,
39-
].join("\n");
40-
}
41-
42-
function createEmptyBacklogSummary() {
43-
return {
44-
total: 0,
45-
pending: 0,
46-
inProgress: 0,
47-
done: 0,
48-
failed: 0,
49-
blocked: 0,
50-
};
51-
}
52-
53-
function getExistingBacklogSnapshot(context) {
54-
try {
55-
const backlog = loadBacklog(context);
56-
return {
57-
summary: summarizeBacklog(backlog),
58-
nextTask: selectNextTask(backlog),
59-
};
60-
} catch {
61-
return {
62-
summary: createEmptyBacklogSummary(),
63-
nextTask: null,
64-
};
65-
}
66-
}
67-
68-
function firstMeaningfulLine(text, fallback) {
69-
return String(text || "")
70-
.split(/\r?\n/)
71-
.map((line) => line.trim())
72-
.find(Boolean) || fallback;
73-
}
74-
75-
function summarizeFailedAnalysisResult(result, fallback) {
76-
const combined = [
77-
String(result?.stdout || "").trim(),
78-
String(result?.stderr || "").trim(),
79-
].filter(Boolean).join("\n\n").trim();
80-
return combined || fallback;
81-
}
82-
83-
function renderAnalysisFailureState(context, backlogSummary, nextTask, failureSummary, runDir = "") {
84-
const runDirHint = runDir
85-
? path.relative(context.repoRoot, runDir).replaceAll("\\", "/")
86-
: "";
87-
88-
return [
89-
"## 当前状态",
90-
`- backlog 文件:${path.relative(context.repoRoot, context.backlogFile).replaceAll("\\", "/")}`,
91-
`- 总任务数:${backlogSummary.total}`,
92-
`- 已完成:${backlogSummary.done}`,
93-
`- 待处理:${backlogSummary.pending}`,
94-
`- 进行中:${backlogSummary.inProgress}`,
95-
`- 失败:${backlogSummary.failed}`,
96-
`- 阻塞:${backlogSummary.blocked}`,
97-
`- 当前任务:${nextTask ? nextTask.title : "无"}`,
98-
`- 最近结果:${firstMeaningfulLine(failureSummary, "HelloLoop 分析失败")}`,
99-
`- 下一建议:${runDirHint ? `先检查 ${runDirHint} 中的日志后再重新执行 npx helloloop` : "修复错误后重新执行 npx helloloop"}`,
100-
].join("\n");
101-
}
102-
103-
function persistAnalysisFailure(context, failureSummary, runDir = "") {
104-
const snapshot = getExistingBacklogSnapshot(context);
105-
writeStatus(context, {
106-
ok: false,
107-
stage: "analysis_failed",
108-
taskId: null,
109-
taskTitle: "",
110-
runDir,
111-
summary: snapshot.summary,
112-
message: failureSummary,
113-
});
114-
writeStateMarkdown(
115-
context,
116-
renderAnalysisFailureState(context, snapshot.summary, snapshot.nextTask, failureSummary, runDir),
117-
);
118-
}
119-
120-
function sanitizeTask(task) {
121-
return {
122-
id: String(task.id || "").trim(),
123-
title: String(task.title || "").trim(),
124-
status: ["done", "blocked"].includes(String(task.status || "")) ? String(task.status) : "pending",
125-
priority: ["P0", "P1", "P2", "P3"].includes(String(task.priority || "")) ? String(task.priority) : "P2",
126-
risk: ["medium", "high", "critical"].includes(String(task.risk || "")) ? String(task.risk) : "low",
127-
goal: String(task.goal || "").trim(),
128-
docs: Array.isArray(task.docs) ? task.docs.map((item) => String(item || "").trim()).filter(Boolean) : [],
129-
paths: Array.isArray(task.paths) ? task.paths.map((item) => String(item || "").trim()).filter(Boolean) : [],
130-
acceptance: Array.isArray(task.acceptance) ? task.acceptance.map((item) => String(item || "").trim()).filter(Boolean) : [],
131-
dependsOn: Array.isArray(task.dependsOn) ? task.dependsOn.map((item) => String(item || "").trim()).filter(Boolean) : [],
132-
verify: Array.isArray(task.verify) ? task.verify.map((item) => String(item || "").trim()).filter(Boolean) : [],
133-
};
134-
}
135-
136-
function normalizeAnalysisPayload(payload, docsEntries) {
137-
const summary = {
138-
currentState: String(payload?.summary?.currentState || "").trim() || "已完成接续分析。",
139-
implemented: Array.isArray(payload?.summary?.implemented) ? payload.summary.implemented.map((item) => String(item || "").trim()).filter(Boolean) : [],
140-
remaining: Array.isArray(payload?.summary?.remaining) ? payload.summary.remaining.map((item) => String(item || "").trim()).filter(Boolean) : [],
141-
nextAction: String(payload?.summary?.nextAction || "").trim() || "查看下一任务。",
142-
};
143-
const tasks = Array.isArray(payload.tasks)
144-
? payload.tasks.map((task) => sanitizeTask(task)).filter((task) => (
145-
task.id && task.title && task.goal && task.acceptance.length
146-
))
147-
: [];
148-
149-
if (!tasks.length && summary.remaining.length) {
150-
throw new Error("分析结果无效:仍存在剩余工作,但未生成可用任务。");
151-
}
152-
153-
const requestInterpretation = payload?.requestInterpretation && typeof payload.requestInterpretation === "object"
154-
? {
155-
summary: String(payload.requestInterpretation.summary || "").trim(),
156-
priorities: Array.isArray(payload.requestInterpretation.priorities)
157-
? payload.requestInterpretation.priorities.map((item) => String(item || "").trim()).filter(Boolean)
158-
: [],
159-
cautions: Array.isArray(payload.requestInterpretation.cautions)
160-
? payload.requestInterpretation.cautions.map((item) => String(item || "").trim()).filter(Boolean)
161-
: [],
162-
}
163-
: null;
164-
const repoDecision = payload?.repoDecision && typeof payload.repoDecision === "object"
165-
? {
166-
compatibility: ["compatible", "conflict", "uncertain"].includes(String(payload.repoDecision.compatibility || ""))
167-
? String(payload.repoDecision.compatibility)
168-
: "compatible",
169-
action: ["continue_existing", "confirm_rebuild", "start_new"].includes(String(payload.repoDecision.action || ""))
170-
? String(payload.repoDecision.action)
171-
: "continue_existing",
172-
reason: String(payload.repoDecision.reason || "").trim(),
173-
}
174-
: null;
175-
176-
return {
177-
project: String(payload.project || "").trim() || "helloloop-project",
178-
summary,
179-
constraints: Array.isArray(payload.constraints)
180-
? payload.constraints.map((item) => String(item || "").trim()).filter(Boolean)
181-
: [],
182-
requestInterpretation: requestInterpretation && (
183-
requestInterpretation.summary
184-
|| requestInterpretation.priorities.length
185-
|| requestInterpretation.cautions.length
186-
)
187-
? requestInterpretation
188-
: null,
189-
repoDecision: repoDecision && repoDecision.reason
190-
? repoDecision
191-
: null,
192-
tasks,
193-
requiredDocs: docsEntries,
194-
};
195-
}
196-
197-
function buildAnalysisSummaryText(context, analysis, backlog, engineResolution) {
198-
const summary = summarizeBacklog(backlog);
199-
const nextTask = selectNextTask(backlog);
200-
201-
return [
202-
"HelloLoop 已完成接续分析。",
203-
`项目仓库:${context.repoRoot}`,
204-
`开发文档:${analysis.requiredDocs.join(", ")}`,
205-
`执行引擎:${engineResolution?.displayName || "未记录"}`,
206-
"",
207-
"当前进度:",
208-
analysis.summary.currentState,
209-
"",
210-
`任务统计:done ${summary.done} / pending ${summary.pending} / blocked ${summary.blocked}`,
211-
nextTask ? `下一任务:${nextTask.title}` : "下一任务:暂无可执行任务",
212-
"",
213-
"下一步建议:",
214-
`- npx helloloop`,
215-
`- npx helloloop --dry-run`,
216-
].join("\n");
217-
}
218-
21930
async function analyzeResolvedWorkspace(context, discovery, options = {}) {
22031
scaffoldIfMissing(context);
22132
const policy = loadPolicy(context);
@@ -268,9 +79,20 @@ async function analyzeResolvedWorkspace(context, discovery, options = {}) {
26879
outputSchemaFile: schemaFile,
26980
outputPrefix: `${engineResolution.engine}-analysis`,
27081
skipGitRepoCheck: true,
82+
hostLease: options.hostLease || null,
27183
});
27284

27385
if (!analysisResult.ok) {
86+
if (analysisResult.leaseExpired) {
87+
return {
88+
ok: false,
89+
code: "host-lease-stopped",
90+
summary: analysisResult.leaseReason || "检测到宿主窗口已关闭,主线终态复核已停止。",
91+
stopped: true,
92+
engineResolution,
93+
discovery,
94+
};
95+
}
27496
const failureSummary = summarizeFailedAnalysisResult(
27597
analysisResult,
27698
`${engineResolution.displayName} 接续分析失败。`,
@@ -368,38 +190,6 @@ async function analyzeResolvedWorkspace(context, discovery, options = {}) {
368190
};
369191
}
370192

371-
function buildCurrentWorkspaceDiscovery(context, docsEntries) {
372-
return {
373-
ok: true,
374-
repoRoot: context.repoRoot,
375-
docsEntries,
376-
resolvedDocs: docsEntries,
377-
resolution: {
378-
repo: {
379-
source: "current_repo",
380-
sourceLabel: "当前项目",
381-
confidence: "high",
382-
confidenceLabel: "高",
383-
path: context.repoRoot,
384-
exists: true,
385-
basis: [
386-
"已在当前项目基础上执行主线终态复核。",
387-
],
388-
},
389-
docs: {
390-
source: "existing_state",
391-
sourceLabel: "已有 .helloloop 配置",
392-
confidence: "high",
393-
confidenceLabel: "高",
394-
entries: docsEntries,
395-
basis: [
396-
"已复用 `.helloloop/project.json` 中记录的 requiredDocs。",
397-
],
398-
},
399-
},
400-
};
401-
}
402-
403193
export async function reanalyzeCurrentWorkspace(context, options = {}) {
404194
const existingProjectConfig = loadProjectConfig(context);
405195
const docsEntries = Array.isArray(options.requiredDocs) && options.requiredDocs.length

0 commit comments

Comments
 (0)