ralphflow-dsh 2.5.0 → 2.6.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 +14 -1
- package/lib/assets.d.ts +6 -2
- package/lib/assets.js +7 -4
- package/lib/engine.d.ts +13 -13
- package/lib/engine.js +143 -48
- package/lib/facade.d.ts +8 -7
- package/lib/facade.js +50 -19
- package/lib/graph/assets.d.ts +9 -4
- package/lib/graph/assets.js +51 -15
- package/lib/graph/engine.d.ts +2 -1
- package/lib/graph/engine.js +49 -36
- package/lib/graph/report.d.ts +6 -2
- package/lib/graph/report.js +5 -5
- package/lib/graph/state.d.ts +14 -14
- package/lib/graph/state.js +28 -28
- package/lib/graph/workspace.d.ts +3 -2
- package/lib/graph/workspace.js +6 -5
- package/lib/index.d.ts +10 -0
- package/lib/index.js +10 -5
- package/lib/paths.d.ts +52 -0
- package/lib/paths.js +75 -2
- package/lib/terminal.d.ts +29 -0
- package/lib/terminal.js +57 -0
- package/lib/tools.js +2 -2
- package/lib/verify.js +2 -0
- package/package.json +1 -1
package/lib/graph/state.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { HistoryEntry } from "../engine.js";
|
|
2
2
|
import type { GraphAsset, GraphNode } from "./asset.js";
|
|
3
3
|
export type GraphRunStatus = "running" | "paused" | "waiting" | "interrupted" | "completed" | "failed" | "cancelled";
|
|
4
4
|
export type GraphNodeStatus = "pending" | "blocked" | "running" | "verifying" | "reworking" | "waiting_review" | "waiting" | "integrating" | "accepting" | "completed" | "failed" | "cancelled" | "interrupted";
|
|
@@ -137,18 +137,17 @@ export interface GraphInstanceState {
|
|
|
137
137
|
};
|
|
138
138
|
history: HistoryEntry[];
|
|
139
139
|
}
|
|
140
|
-
export declare function
|
|
141
|
-
export declare function
|
|
142
|
-
export declare function
|
|
143
|
-
export declare function
|
|
144
|
-
export declare function
|
|
145
|
-
export declare function
|
|
146
|
-
export declare function
|
|
147
|
-
export declare function
|
|
148
|
-
export declare function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
export declare function listGraphStates(workspace: string): Array<{
|
|
140
|
+
export declare function graphInstancesDirAt(root: string): string;
|
|
141
|
+
export declare function graphReportsDirAt(root: string): string;
|
|
142
|
+
export declare function graphInstanceDirAt(root: string, instId: string): string;
|
|
143
|
+
export declare function graphStatePathAt(root: string, instId: string): string;
|
|
144
|
+
export declare function graphArtifactsRootAt(root: string): string;
|
|
145
|
+
export declare function graphArtifactsDirAt(root: string, state: Pick<GraphInstanceState, "artifacts_dir_name">): string;
|
|
146
|
+
export declare function graphNodeArtifactDirAt(root: string, state: Pick<GraphInstanceState, "artifacts_dir_name">, nodeId: string, attemptId: string): string;
|
|
147
|
+
export declare function readGraphStateAt(root: string, instId: string): GraphInstanceState | null;
|
|
148
|
+
export declare function writeGraphStateAt(root: string, state: GraphInstanceState, instId: string): void;
|
|
149
|
+
/** 扫描运行态根下的所有 Graph 实例状态(包含已结束但保留的实例)。 */
|
|
150
|
+
export declare function listGraphStatesAt(root: string): Array<{
|
|
152
151
|
id: string;
|
|
153
152
|
state: GraphInstanceState;
|
|
154
153
|
}>;
|
|
@@ -239,6 +238,7 @@ export interface GraphRunProjection {
|
|
|
239
238
|
report: string | null;
|
|
240
239
|
}
|
|
241
240
|
export declare function nodeNameOf(state: GraphInstanceState, node: GraphNode): string;
|
|
242
|
-
|
|
241
|
+
/** `reportPath` = 报告在人话里的写法(默认布局相对路径 / 外部化绝对路径),由调用方按运行态布局给。 */
|
|
242
|
+
export declare function projectionOf(state: GraphInstanceState, id: string, reportPath: string): GraphRunProjection;
|
|
243
243
|
/** 运行输入与提示词共用的安全路径:只接受相对路径,拒绝逃出工作区。 */
|
|
244
244
|
export declare function resolveInside(root: string, relative: string): string | null;
|
package/lib/graph/state.js
CHANGED
|
@@ -8,40 +8,39 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import fs from "node:fs";
|
|
10
10
|
import path from "node:path";
|
|
11
|
-
import { RALPH_FLOW_DIR } from "../engine.js";
|
|
12
11
|
import { pauseLabel } from "../pause.js";
|
|
13
12
|
import { nodeBranchFor } from "./branches.js";
|
|
14
13
|
export const GRAPH_ACTIVE_STATUSES = ["running", "paused", "waiting", "interrupted"];
|
|
15
14
|
export function isGraphTerminal(status) {
|
|
16
15
|
return status === "completed" || status === "failed" || status === "cancelled";
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// ── 运行态路径:`root` 是运行态根(默认 `<项目根>/.dsh/ralph-flow`,外部化时 = 外部目录)──
|
|
18
|
+
// 这里只接受**根**,不接受工作区:外部状态目录与项目根是两个不同的概念,混用一个参数会让
|
|
19
|
+
// 「实例放哪」在两处调用里悄悄分叉。
|
|
20
|
+
export function graphInstancesDirAt(root) {
|
|
21
|
+
return path.join(root, "instances");
|
|
20
22
|
}
|
|
21
|
-
export function
|
|
22
|
-
return path.join(
|
|
23
|
+
export function graphReportsDirAt(root) {
|
|
24
|
+
return path.join(root, "reports");
|
|
23
25
|
}
|
|
24
|
-
export function
|
|
25
|
-
return path.join(
|
|
26
|
+
export function graphInstanceDirAt(root, instId) {
|
|
27
|
+
return path.join(graphInstancesDirAt(root), instId);
|
|
26
28
|
}
|
|
27
|
-
export function
|
|
28
|
-
return path.join(
|
|
29
|
+
export function graphStatePathAt(root, instId) {
|
|
30
|
+
return path.join(graphInstanceDirAt(root, instId), "state.json");
|
|
29
31
|
}
|
|
30
|
-
export function
|
|
31
|
-
return path.join(
|
|
32
|
+
export function graphArtifactsRootAt(root) {
|
|
33
|
+
return path.join(root, "artifacts");
|
|
32
34
|
}
|
|
33
|
-
export function
|
|
34
|
-
return path.join(
|
|
35
|
+
export function graphArtifactsDirAt(root, state) {
|
|
36
|
+
return path.join(graphArtifactsRootAt(root), state.artifacts_dir_name);
|
|
35
37
|
}
|
|
36
|
-
export function
|
|
37
|
-
return path.join(
|
|
38
|
+
export function graphNodeArtifactDirAt(root, state, nodeId, attemptId) {
|
|
39
|
+
return path.join(graphArtifactsDirAt(root, state), "nodes", nodeId, attemptId);
|
|
38
40
|
}
|
|
39
|
-
export function
|
|
40
|
-
return path.join(graphArtifactsDirOf(workspace, state), "nodes", nodeId, attemptId);
|
|
41
|
-
}
|
|
42
|
-
export function readGraphState(workspace, instId) {
|
|
41
|
+
export function readGraphStateAt(root, instId) {
|
|
43
42
|
try {
|
|
44
|
-
const raw = fs.readFileSync(
|
|
43
|
+
const raw = fs.readFileSync(graphStatePathAt(root, instId), "utf-8");
|
|
45
44
|
const parsed = JSON.parse(raw);
|
|
46
45
|
if (!parsed || parsed.kind !== "graph" || !parsed.graph || !parsed.graph.asset)
|
|
47
46
|
return null;
|
|
@@ -83,18 +82,18 @@ export function readGraphState(workspace, instId) {
|
|
|
83
82
|
return null;
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
|
-
export function
|
|
85
|
+
export function writeGraphStateAt(root, state, instId) {
|
|
87
86
|
state.updated_at = new Date().toISOString();
|
|
88
|
-
const dir =
|
|
87
|
+
const dir = graphInstanceDirAt(root, instId);
|
|
89
88
|
fs.mkdirSync(dir, { recursive: true });
|
|
90
89
|
const target = path.join(dir, "state.json");
|
|
91
90
|
const tmp = path.join(dir, `.state.${process.pid}.tmp`);
|
|
92
91
|
fs.writeFileSync(tmp, `${JSON.stringify(state, null, 2)}\n`, "utf-8");
|
|
93
92
|
fs.renameSync(tmp, target);
|
|
94
93
|
}
|
|
95
|
-
/**
|
|
96
|
-
export function
|
|
97
|
-
const dir =
|
|
94
|
+
/** 扫描运行态根下的所有 Graph 实例状态(包含已结束但保留的实例)。 */
|
|
95
|
+
export function listGraphStatesAt(root) {
|
|
96
|
+
const dir = graphInstancesDirAt(root);
|
|
98
97
|
let entries = [];
|
|
99
98
|
try {
|
|
100
99
|
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
@@ -106,7 +105,7 @@ export function listGraphStates(workspace) {
|
|
|
106
105
|
for (const entry of entries) {
|
|
107
106
|
if (!entry.isDirectory())
|
|
108
107
|
continue;
|
|
109
|
-
const state =
|
|
108
|
+
const state = readGraphStateAt(root, entry.name);
|
|
110
109
|
if (state)
|
|
111
110
|
out.push({ id: entry.name, state });
|
|
112
111
|
}
|
|
@@ -230,7 +229,8 @@ function checkProjection(state, node) {
|
|
|
230
229
|
return { mode, status: "pending", reason: "", reworks: state.graph.rework_counts[node.id] ?? 0 };
|
|
231
230
|
return { mode, status: verdict.status, reason: verdict.reason, reworks: state.graph.rework_counts[node.id] ?? 0 };
|
|
232
231
|
}
|
|
233
|
-
|
|
232
|
+
/** `reportPath` = 报告在人话里的写法(默认布局相对路径 / 外部化绝对路径),由调用方按运行态布局给。 */
|
|
233
|
+
export function projectionOf(state, id, reportPath) {
|
|
234
234
|
const nodes = state.graph.asset.nodes.map((node) => {
|
|
235
235
|
const status = nodeStatusOf(state, node);
|
|
236
236
|
const attempt = latestAttemptOfNode(state, node.id);
|
|
@@ -345,7 +345,7 @@ export function projectionOf(state, id) {
|
|
|
345
345
|
},
|
|
346
346
|
startedAt: state.started_at,
|
|
347
347
|
updatedAt: state.updated_at,
|
|
348
|
-
report: isGraphTerminal(state.graph.status) ?
|
|
348
|
+
report: isGraphTerminal(state.graph.status) ? reportPath : null,
|
|
349
349
|
};
|
|
350
350
|
}
|
|
351
351
|
/** 运行输入与提示词共用的安全路径:只接受相对路径,拒绝逃出工作区。 */
|
package/lib/graph/workspace.d.ts
CHANGED
|
@@ -16,8 +16,9 @@ export declare function branchTip(root: string, branch: string): Promise<string
|
|
|
16
16
|
/** 快进集成分支。调用方先证明节点分支包含 previous,这里只做引用前进。 */
|
|
17
17
|
export declare function advanceIntegration(root: string, branch: string, previous: string, commit: string): Promise<void>;
|
|
18
18
|
export declare function containsCommit(cwd: string, ancestor: string, descendant: string): Promise<boolean>;
|
|
19
|
-
|
|
20
|
-
export declare function
|
|
19
|
+
/** 节点 worktree 的根:跟随运行态根(外部化时也在项目根之外,不污染目标仓库)。 */
|
|
20
|
+
export declare function worktreeRootOf(root: string, instId: string): string;
|
|
21
|
+
export declare function nodeWorktreePathOf(root: string, instId: string, nodeId: string): string;
|
|
21
22
|
/** 节点 worktree 建在节点自己的分支上:`git worktree add -b <branch> <path> <起点>`。 */
|
|
22
23
|
export declare function ensureNodeWorktree(root: string, workspacePath: string, branch: string, startPoint: string): Promise<{
|
|
23
24
|
path: string;
|
package/lib/graph/workspace.js
CHANGED
|
@@ -11,7 +11,7 @@ import { createHash } from "node:crypto";
|
|
|
11
11
|
import fs from "node:fs";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import { promisify } from "node:util";
|
|
14
|
-
import {
|
|
14
|
+
import { graphInstanceDirAt } from "./state.js";
|
|
15
15
|
import { INTEGRATION_BRANCH_PREFIX, NODE_BRANCH_PREFIX, integrationBranchFor, nodeBranchFor } from "./branches.js";
|
|
16
16
|
const execFile = promisify(execFileCallback);
|
|
17
17
|
export { INTEGRATION_BRANCH_PREFIX, NODE_BRANCH_PREFIX, integrationBranchFor, nodeBranchFor };
|
|
@@ -86,11 +86,12 @@ export async function containsCommit(cwd, ancestor, descendant) {
|
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
/** 节点 worktree 的根:跟随运行态根(外部化时也在项目根之外,不污染目标仓库)。 */
|
|
90
|
+
export function worktreeRootOf(root, instId) {
|
|
91
|
+
return path.join(graphInstanceDirAt(root, instId), WORKTREES_DIRNAME);
|
|
91
92
|
}
|
|
92
|
-
export function nodeWorktreePathOf(
|
|
93
|
-
return path.join(worktreeRootOf(
|
|
93
|
+
export function nodeWorktreePathOf(root, instId, nodeId) {
|
|
94
|
+
return path.join(worktreeRootOf(root, instId), nodeId);
|
|
94
95
|
}
|
|
95
96
|
async function listedWorktrees(root) {
|
|
96
97
|
const listing = await git(root, "worktree", "list", "--porcelain");
|
package/lib/index.d.ts
CHANGED
|
@@ -10,5 +10,15 @@ export declare const inject: string[];
|
|
|
10
10
|
*/
|
|
11
11
|
export interface Config {
|
|
12
12
|
verifierProvider?: string;
|
|
13
|
+
/**
|
|
14
|
+
* 外部状态目录(等价于 `$RALPH_FLOW_STATE_DIR`):`instances/`、`reports/`、`artifacts/`
|
|
15
|
+
* 全部落这里,项目根下**不建** `.dsh/ralph-flow/`。非空即启用;空值按未配置处理。
|
|
16
|
+
*/
|
|
17
|
+
stateDir?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 无头模式(等价于 `$RALPH_FLOW_HEADLESS=1`):工作流发现与加载跳过项目级资产目录,
|
|
20
|
+
* 只认用户级与内置;带顶层 `manual_step` 的 Flow / Graph 在加载期拒绝(没有人能放行审查门)。
|
|
21
|
+
*/
|
|
22
|
+
ignoreWorkspaceWorkflows?: boolean;
|
|
13
23
|
}
|
|
14
24
|
export declare function apply(ctx: Context, config?: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -59,6 +59,11 @@ export function apply(ctx, config = {}) {
|
|
|
59
59
|
// 未声明 Config schema(宿主不需要额外依赖),非法类型按未配置处理,不让 apply 抛错。
|
|
60
60
|
const configuredProvider = typeof config?.verifierProvider === "string" ? config.verifierProvider.trim() : "";
|
|
61
61
|
const verifierProvider = configuredProvider || DEFAULT_VERIFIER_PROVIDER;
|
|
62
|
+
/** 运行态选项:插件配置优先,缺省由 `paths.ts` 读环境变量。 */
|
|
63
|
+
const runtime = {
|
|
64
|
+
...(typeof config?.stateDir === "string" && config.stateDir.trim() ? { stateDir: config.stateDir.trim() } : {}),
|
|
65
|
+
...(config?.ignoreWorkspaceWorkflows === true ? { ignoreWorkspaceWorkflows: true } : {}),
|
|
66
|
+
};
|
|
62
67
|
/** 插件加载目录的项目根(没有会话可问时的唯一回落;不再有环境变量旁路)。 */
|
|
63
68
|
const workspace = projectRootOf(process.cwd());
|
|
64
69
|
const log = (level, event, data) => {
|
|
@@ -461,7 +466,7 @@ export function apply(ctx, config = {}) {
|
|
|
461
466
|
const key = ws && ws.trim() ? ws.trim() : workspace;
|
|
462
467
|
let e = engines.get(key);
|
|
463
468
|
if (!e) {
|
|
464
|
-
e = createFacade(key, { ctx, ports });
|
|
469
|
+
e = createFacade(key, { ctx, ports, ...runtime });
|
|
465
470
|
engines.set(key, e);
|
|
466
471
|
// **不在这里建目录**:engineFor 是所有工具(含只读的 list/doctor/status)的入口,
|
|
467
472
|
// 在这里 ensureLayout 会让只读命令在用户从没用过 ralphflow 的项目里创建整棵
|
|
@@ -477,7 +482,7 @@ export function apply(ctx, config = {}) {
|
|
|
477
482
|
// 工作流 → 快捷技能。带上会话 id:名字不合语法的工作流要**当场把原因说给用户听**
|
|
478
483
|
// (引擎也可能由无会话的路径创建,那就只写日志 —— 见 src/skills.ts)。
|
|
479
484
|
try {
|
|
480
|
-
registerWorkflowSkills?.(discoverAssetsIn(key), sessionId ? { sessionId } : undefined);
|
|
485
|
+
registerWorkflowSkills?.(discoverAssetsIn(key, runtime), sessionId ? { sessionId } : undefined);
|
|
481
486
|
}
|
|
482
487
|
catch { }
|
|
483
488
|
}
|
|
@@ -498,14 +503,14 @@ export function apply(ctx, config = {}) {
|
|
|
498
503
|
pause(session) {
|
|
499
504
|
const cwd = cwdOf(session);
|
|
500
505
|
const key = cwd ? projectRootOf(cwd) : workspace;
|
|
501
|
-
const engine = engines.get(key) ?? createFacade(key, { ctx, ports });
|
|
506
|
+
const engine = engines.get(key) ?? createFacade(key, { ctx, ports, ...runtime });
|
|
502
507
|
return engine.pauseForUserStop(session.id);
|
|
503
508
|
},
|
|
504
509
|
async read(session) {
|
|
505
510
|
// Viewing status never runs restore or registers skills / sends a notice.
|
|
506
511
|
const cwd = cwdOf(session);
|
|
507
512
|
const key = cwd ? projectRootOf(cwd) : workspace;
|
|
508
|
-
const engine = engines.get(key) ?? createFacade(key, { ctx, ports });
|
|
513
|
+
const engine = engines.get(key) ?? createFacade(key, { ctx, ports, ...runtime });
|
|
509
514
|
const active = engine.uiStatus(session.id);
|
|
510
515
|
const catalog = engine.viewerCatalog();
|
|
511
516
|
if (active.status && engine.readState(active.status.id)?.active)
|
|
@@ -699,7 +704,7 @@ export function apply(ctx, config = {}) {
|
|
|
699
704
|
if (!cwd)
|
|
700
705
|
return;
|
|
701
706
|
try {
|
|
702
|
-
registerWorkflowSkills?.(discoverAssetsIn(projectRootOf(cwd)), s?.id ? { sessionId: s.id } : undefined);
|
|
707
|
+
registerWorkflowSkills?.(discoverAssetsIn(projectRootOf(cwd), runtime), s?.id ? { sessionId: s.id } : undefined);
|
|
703
708
|
}
|
|
704
709
|
catch { }
|
|
705
710
|
});
|
package/lib/paths.d.ts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
/** 插件命名空间:项目内 `.dsh/ralph-flow/`,用户级 `<DSH_HOME>/ralph-flow/`。 */
|
|
2
2
|
export declare const RALPH_FLOW_NAME = "ralph-flow";
|
|
3
|
+
/**
|
|
4
|
+
* 项目内的运行时根目录。**项目根 dot-dir**(§1.8):项目根 = 最近的含 `.git` 的祖先目录,
|
|
5
|
+
* 与原生 Skill 的 `<projectRoot>/.dsh/skills` 用同一条规则;用户级命名空间
|
|
6
|
+
* `<DSH_HOME>/ralph-flow/` 由本文件解析。
|
|
7
|
+
*
|
|
8
|
+
* 注意:这里是**项目根相对路径**(含 `/`),`path.join(projectRoot, RALPH_FLOW_DIR)` 仍成立。
|
|
9
|
+
*/
|
|
10
|
+
export declare const RALPH_FLOW_DIR = ".dsh/ralph-flow";
|
|
11
|
+
/** 运行态外部化:设置后 instances/reports/artifacts 全部落这个目录(支持 `~`)。 */
|
|
12
|
+
export declare const RALPH_FLOW_STATE_DIR_ENV = "RALPH_FLOW_STATE_DIR";
|
|
13
|
+
/** 无头模式开关:为真时忽略项目级工作流资产,并拒绝带人工审查门的 Flow / Graph。 */
|
|
14
|
+
export declare const RALPH_FLOW_HEADLESS_ENV = "RALPH_FLOW_HEADLESS";
|
|
15
|
+
/** 运行态选项:环境变量的显式版本(插件配置 > 环境变量 > 默认)。 */
|
|
16
|
+
export interface RuntimeOptions {
|
|
17
|
+
/** 外部状态目录(等价于 `$RALPH_FLOW_STATE_DIR`)。 */
|
|
18
|
+
stateDir?: string;
|
|
19
|
+
/** 无头模式(等价于 `$RALPH_FLOW_HEADLESS=1`)。 */
|
|
20
|
+
ignoreWorkspaceWorkflows?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** 一份解析好的运行态布局:Flow 与 Graph 的所有运行目录都从这里取。 */
|
|
23
|
+
export interface RalphFlowLayout {
|
|
24
|
+
/** 运行态根:默认 `<项目根>/.dsh/ralph-flow`;外部化时 = 外部目录。 */
|
|
25
|
+
root: string;
|
|
26
|
+
/** 项目级资产目录:始终 `<项目根>/.dsh/ralph-flow/workflows`(只读发现用)。 */
|
|
27
|
+
workflowsDir: string;
|
|
28
|
+
instancesDir: string;
|
|
29
|
+
reportsDir: string;
|
|
30
|
+
artifactsDir: string;
|
|
31
|
+
/** 外部化:运行态不在项目根下,报告/提示词里的路径要给绝对路径。 */
|
|
32
|
+
external: boolean;
|
|
33
|
+
/** 无头:发现与加载跳过项目级资产目录,Flow / Graph 的人工审查门在加载期拒绝。 */
|
|
34
|
+
headless: boolean;
|
|
35
|
+
}
|
|
3
36
|
/**
|
|
4
37
|
* 项目根:最近的含 `.git` 的祖先目录;没有就用 `dir` 本身。
|
|
5
38
|
*
|
|
@@ -10,3 +43,22 @@ export declare function projectRootOf(dir: string): string;
|
|
|
10
43
|
export declare function dshUserRoot(): string;
|
|
11
44
|
/** 用户级插件目录:`<DSH_HOME|~/.dsh>/ralph-flow[/...]`。 */
|
|
12
45
|
export declare function userRalphFlowDir(...segments: string[]): string;
|
|
46
|
+
/**
|
|
47
|
+
* 一类资产的搜索目录,顺序 = 优先级:项目级优先,用户级兜底;无头运行只剩用户级。
|
|
48
|
+
* 资产类型的目录名(`workflows/` / `graphs/`)只在这里拼一次。
|
|
49
|
+
*/
|
|
50
|
+
export declare function assetSearchDirs(workspace: string, kind: "workflows" | "graphs", headless: boolean): string[];
|
|
51
|
+
/**
|
|
52
|
+
* 报告与提示词里的路径写法:外部化时给绝对路径(工作区里读不到它),否则给项目根相对路径。
|
|
53
|
+
* Flow 的报告/产出与 Graph 的报告共用这一条规则。
|
|
54
|
+
*/
|
|
55
|
+
export declare function displayPath(projectRoot: string, absolute: string, external: boolean): string;
|
|
56
|
+
/** 展开 `~` / `~/...`(与 `$DSH_HOME` 的解析口径一致);其余原样返回。 */
|
|
57
|
+
export declare function expandHomePath(value: string): string;
|
|
58
|
+
/** 无头模式是否开启:插件配置显式开启,或 `$RALPH_FLOW_HEADLESS` 非空且不为假值。 */
|
|
59
|
+
export declare function headlessModeEnabled(explicit?: boolean): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* 解析运行态布局。`stateDir` 非空即外部化(显式配置优先于环境变量);
|
|
62
|
+
* 相对路径按项目根解析 —— 插件只有一个项目根,写相对路径的人指的就是项目旁边。
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveRalphFlowLayout(projectRoot: string, options?: RuntimeOptions): RalphFlowLayout;
|
package/lib/paths.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 运行态布局:**项目根 / 用户根 / 外部状态根**。
|
|
3
3
|
*
|
|
4
4
|
* 规则与 `@deepseek-ai/dsh-skill-filesystem` 的 Skill 根一致(源码在
|
|
5
5
|
* `findProjectRoot` 与 `@deepseek-ai/dsh-home-paths` 的 `resolveDshHome`):
|
|
@@ -9,14 +9,31 @@
|
|
|
9
9
|
* - 用户根:`resolveDshHome()` —— 显式配置 > `$DSH_HOME`(支持 `~`,空值视为未设置)
|
|
10
10
|
* > `~/.dsh`。
|
|
11
11
|
*
|
|
12
|
-
* 插件的项目级数据(资产 +
|
|
12
|
+
* 插件的项目级数据(资产 + 实例/报告/产出)默认全部挂在项目根;用户级资产挂在用户根。
|
|
13
|
+
* 无人值守运行时可以把**运行态**(实例、报告、产出)搬出项目根(`RALPH_FLOW_STATE_DIR`),
|
|
14
|
+
* 并让工作流来源只认用户级与内置(`RALPH_FLOW_HEADLESS`)。两件事都在这里解析成一份布局,
|
|
15
|
+
* Flow 与 Graph 共用,绝不各自拼路径。
|
|
16
|
+
*
|
|
13
17
|
* 这里只解析路径,不建目录、不校验内容。
|
|
14
18
|
*/
|
|
15
19
|
import fs from "node:fs";
|
|
20
|
+
import os from "node:os";
|
|
16
21
|
import path from "node:path";
|
|
17
22
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
18
23
|
/** 插件命名空间:项目内 `.dsh/ralph-flow/`,用户级 `<DSH_HOME>/ralph-flow/`。 */
|
|
19
24
|
export const RALPH_FLOW_NAME = "ralph-flow";
|
|
25
|
+
/**
|
|
26
|
+
* 项目内的运行时根目录。**项目根 dot-dir**(§1.8):项目根 = 最近的含 `.git` 的祖先目录,
|
|
27
|
+
* 与原生 Skill 的 `<projectRoot>/.dsh/skills` 用同一条规则;用户级命名空间
|
|
28
|
+
* `<DSH_HOME>/ralph-flow/` 由本文件解析。
|
|
29
|
+
*
|
|
30
|
+
* 注意:这里是**项目根相对路径**(含 `/`),`path.join(projectRoot, RALPH_FLOW_DIR)` 仍成立。
|
|
31
|
+
*/
|
|
32
|
+
export const RALPH_FLOW_DIR = ".dsh/ralph-flow";
|
|
33
|
+
/** 运行态外部化:设置后 instances/reports/artifacts 全部落这个目录(支持 `~`)。 */
|
|
34
|
+
export const RALPH_FLOW_STATE_DIR_ENV = "RALPH_FLOW_STATE_DIR";
|
|
35
|
+
/** 无头模式开关:为真时忽略项目级工作流资产,并拒绝带人工审查门的 Flow / Graph。 */
|
|
36
|
+
export const RALPH_FLOW_HEADLESS_ENV = "RALPH_FLOW_HEADLESS";
|
|
20
37
|
/**
|
|
21
38
|
* 项目根:最近的含 `.git` 的祖先目录;没有就用 `dir` 本身。
|
|
22
39
|
*
|
|
@@ -42,3 +59,59 @@ export function dshUserRoot() {
|
|
|
42
59
|
export function userRalphFlowDir(...segments) {
|
|
43
60
|
return path.join(dshUserRoot(), RALPH_FLOW_NAME, ...segments);
|
|
44
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* 一类资产的搜索目录,顺序 = 优先级:项目级优先,用户级兜底;无头运行只剩用户级。
|
|
64
|
+
* 资产类型的目录名(`workflows/` / `graphs/`)只在这里拼一次。
|
|
65
|
+
*/
|
|
66
|
+
export function assetSearchDirs(workspace, kind, headless) {
|
|
67
|
+
const userDir = userRalphFlowDir(kind);
|
|
68
|
+
return headless ? [userDir] : [path.join(path.resolve(workspace), RALPH_FLOW_DIR, kind), userDir];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 报告与提示词里的路径写法:外部化时给绝对路径(工作区里读不到它),否则给项目根相对路径。
|
|
72
|
+
* Flow 的报告/产出与 Graph 的报告共用这一条规则。
|
|
73
|
+
*/
|
|
74
|
+
export function displayPath(projectRoot, absolute, external) {
|
|
75
|
+
return external ? absolute : path.relative(path.resolve(projectRoot), absolute).split(path.sep).join("/");
|
|
76
|
+
}
|
|
77
|
+
/** 展开 `~` / `~/...`(与 `$DSH_HOME` 的解析口径一致);其余原样返回。 */
|
|
78
|
+
export function expandHomePath(value) {
|
|
79
|
+
if (value === "~")
|
|
80
|
+
return os.homedir();
|
|
81
|
+
if (value.startsWith("~/") || value.startsWith("~\\"))
|
|
82
|
+
return path.join(os.homedir(), value.slice(2));
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
function nonEmpty(value) {
|
|
86
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
87
|
+
return trimmed ? trimmed : undefined;
|
|
88
|
+
}
|
|
89
|
+
/** 环境变量里的布尔开关:空值与 `0/false/no/off` 算关闭,其余非空值算开启。 */
|
|
90
|
+
function truthyEnv(name) {
|
|
91
|
+
const raw = process.env[name];
|
|
92
|
+
const value = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
93
|
+
return value !== "" && value !== "0" && value !== "false" && value !== "no" && value !== "off";
|
|
94
|
+
}
|
|
95
|
+
/** 无头模式是否开启:插件配置显式开启,或 `$RALPH_FLOW_HEADLESS` 非空且不为假值。 */
|
|
96
|
+
export function headlessModeEnabled(explicit) {
|
|
97
|
+
return explicit === true || truthyEnv(RALPH_FLOW_HEADLESS_ENV);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 解析运行态布局。`stateDir` 非空即外部化(显式配置优先于环境变量);
|
|
101
|
+
* 相对路径按项目根解析 —— 插件只有一个项目根,写相对路径的人指的就是项目旁边。
|
|
102
|
+
*/
|
|
103
|
+
export function resolveRalphFlowLayout(projectRoot, options = {}) {
|
|
104
|
+
const project = path.resolve(projectRoot);
|
|
105
|
+
const configured = nonEmpty(options.stateDir) ?? nonEmpty(process.env[RALPH_FLOW_STATE_DIR_ENV]);
|
|
106
|
+
const externalRoot = configured ? path.resolve(project, expandHomePath(configured)) : undefined;
|
|
107
|
+
const root = externalRoot ?? path.join(project, RALPH_FLOW_DIR);
|
|
108
|
+
return {
|
|
109
|
+
root,
|
|
110
|
+
workflowsDir: path.join(project, RALPH_FLOW_DIR, "workflows"),
|
|
111
|
+
instancesDir: path.join(root, "instances"),
|
|
112
|
+
reportsDir: path.join(root, "reports"),
|
|
113
|
+
artifactsDir: path.join(root, "artifacts"),
|
|
114
|
+
external: externalRoot !== undefined,
|
|
115
|
+
headless: headlessModeEnabled(options.ignoreWorkspaceWorkflows),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PauseReason } from "./pause.js";
|
|
2
|
+
/** 契约版本:宿主按这个字段判断解析规则;形状不兼容时才升。 */
|
|
3
|
+
export declare const TERMINAL_RECORD_SCHEMA_VERSION = 1;
|
|
4
|
+
/** 记录的三种状态:终态(done / cancelled)与暂停态(paused)。 */
|
|
5
|
+
export type TerminalRecordStatus = "done" | "cancelled" | "paused";
|
|
6
|
+
/** 两个**终态**(会归档报告并销毁实例);暂停态不在其中。 */
|
|
7
|
+
export type ArchiveStatus = Exclude<TerminalRecordStatus, "paused">;
|
|
8
|
+
/** 一份结构化终态记录(磁盘上的 `reports/<instanceId>.json`)。 */
|
|
9
|
+
export interface TerminalRecord {
|
|
10
|
+
schemaVersion: typeof TERMINAL_RECORD_SCHEMA_VERSION;
|
|
11
|
+
instanceId: string;
|
|
12
|
+
workflow: string;
|
|
13
|
+
status: TerminalRecordStatus;
|
|
14
|
+
/** 暂停原因:仅 `status === "paused"` 时有值;引擎所有暂停路径都会写入原因。 */
|
|
15
|
+
pauseReason: PauseReason | null;
|
|
16
|
+
/** 已归档 Markdown 报告的绝对路径;未归档暂停态为 `null`。 */
|
|
17
|
+
reportPath: string | null;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 原子写一份终态记录;失败**抛出**(临时文件已清理)。
|
|
22
|
+
* 调用方负责把失败变成一条告警,而不是让实例卡在销毁前。
|
|
23
|
+
*/
|
|
24
|
+
export declare function writeTerminalRecord(reportsDir: string, instanceId: string, record: TerminalRecord): void;
|
|
25
|
+
/**
|
|
26
|
+
* 移除某个实例的终态记录(不存在是正常情况:运行中的实例本就不该有记录)。
|
|
27
|
+
* 删除失败**抛出**:留着一份过期的 `paused` 会冒充真实状态,调用方必须把它变成告警。
|
|
28
|
+
*/
|
|
29
|
+
export declare function removeTerminalRecord(reportsDir: string, instanceId: string): void;
|
package/lib/terminal.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 结构化终态 JSON:Flow 进入终态(`done` / `cancelled`)或暂停态(`paused`)时,在生效状态
|
|
3
|
+
* 目录的 `reports/<instanceId>.json` 落一份**机器可读**的事实。
|
|
4
|
+
*
|
|
5
|
+
* 为什么要有它:无头宿主(`dsh --profile headless`)退出后必须 100% 确定性地裁定真实终态。
|
|
6
|
+
* 人类可读的 Markdown 报告是中文散文,用正则解析它既脆弱又会在文案微调时静默出错;
|
|
7
|
+
* 这份 JSON 是同一个状态的机器投影,宿主只读字段。
|
|
8
|
+
*
|
|
9
|
+
* 契约(`schemaVersion: 1`):
|
|
10
|
+
* - 字段固定为七个:`schemaVersion` / `instanceId` / `workflow` / `status` /
|
|
11
|
+
* `pauseReason` / `reportPath` / `updatedAt`;
|
|
12
|
+
* - `status === "paused"` 带 `pauseReason`(统一 `PauseReason` 词表);`done` / `cancelled`
|
|
13
|
+
* 为 `null`;
|
|
14
|
+
* - `reportPath` 是**已归档** Markdown 报告的绝对路径;尚未归档的暂停态为 `null`;
|
|
15
|
+
* - `updatedAt` 是这份记录最后一次被写的 ISO 时间戳。
|
|
16
|
+
*
|
|
17
|
+
* 单一事实源:记录只由 `state.json` / 报告的落盘结果推导,绝不反过来影响引擎判定。
|
|
18
|
+
* 恢复运行后旧的 `paused` 记录必须消失(否则它会继续冒充“当前已暂停”)。
|
|
19
|
+
*
|
|
20
|
+
* 原子写:同目录临时文件 + `rename`,读者永远看不到半写文件。写失败抛出,由调用方决定
|
|
21
|
+
* 告警口径(终态记录是派生事实,不阻塞实例销毁)。
|
|
22
|
+
*/
|
|
23
|
+
import fs from "node:fs";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
/** 契约版本:宿主按这个字段判断解析规则;形状不兼容时才升。 */
|
|
26
|
+
export const TERMINAL_RECORD_SCHEMA_VERSION = 1;
|
|
27
|
+
/** 终态记录的文件路径:与 Markdown 报告同目录(`reports/`),按实例一份。 */
|
|
28
|
+
function terminalRecordPath(reportsDir, instanceId) {
|
|
29
|
+
return path.join(reportsDir, `${instanceId}.json`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 原子写一份终态记录;失败**抛出**(临时文件已清理)。
|
|
33
|
+
* 调用方负责把失败变成一条告警,而不是让实例卡在销毁前。
|
|
34
|
+
*/
|
|
35
|
+
export function writeTerminalRecord(reportsDir, instanceId, record) {
|
|
36
|
+
fs.mkdirSync(reportsDir, { recursive: true });
|
|
37
|
+
const file = terminalRecordPath(reportsDir, instanceId);
|
|
38
|
+
const tmp = path.join(reportsDir, `.${instanceId}.json.${process.pid}.tmp`);
|
|
39
|
+
try {
|
|
40
|
+
fs.writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\n`, "utf-8");
|
|
41
|
+
fs.renameSync(tmp, file);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
try {
|
|
45
|
+
fs.rmSync(tmp, { force: true });
|
|
46
|
+
}
|
|
47
|
+
catch { }
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 移除某个实例的终态记录(不存在是正常情况:运行中的实例本就不该有记录)。
|
|
53
|
+
* 删除失败**抛出**:留着一份过期的 `paused` 会冒充真实状态,调用方必须把它变成告警。
|
|
54
|
+
*/
|
|
55
|
+
export function removeTerminalRecord(reportsDir, instanceId) {
|
|
56
|
+
fs.rmSync(terminalRecordPath(reportsDir, instanceId), { force: true });
|
|
57
|
+
}
|
package/lib/tools.js
CHANGED
|
@@ -221,7 +221,7 @@ export function registerCommands(deps) {
|
|
|
221
221
|
description: "列出可用工作流与活跃实例。示例:/ralphflow-list",
|
|
222
222
|
shim: () => ({
|
|
223
223
|
kind: "directive",
|
|
224
|
-
text: "用户执行了 /ralphflow-list。请调用 `ralphflow_list` 工具获取数据,然后把「可用工作流」整理成**表格**(列:工作流 | 用途描述),把「活跃实例」按工具返回的字段简要列给用户(实例 id
|
|
224
|
+
text: "用户执行了 /ralphflow-list。请调用 `ralphflow_list` 工具获取数据,然后把「可用工作流」整理成**表格**(列:工作流 | 用途描述),把「活跃实例」按工具返回的字段简要列给用户(实例 id、工作流、任务、步骤、状态、属主),并转达工具给的「已结束的运行」报告目录。数据以工具返回为准,不要编造;没有就直说。工作流来源顺序:默认项目根(从当前目录向上最近的含 `.git` 的祖先目录)的自定义资产优先于用户级,用户级优先于插件内置;无头模式只认用户级与插件内置。",
|
|
225
225
|
}),
|
|
226
226
|
},
|
|
227
227
|
{
|
|
@@ -234,7 +234,7 @@ export function registerCommands(deps) {
|
|
|
234
234
|
const reason = parts.length > 1 ? `,reason = \`${parts.slice(1).join(" ")}\`` : "";
|
|
235
235
|
return {
|
|
236
236
|
kind: "directive",
|
|
237
|
-
text: `用户执行了 /ralphflow-cancel,要取消工作流实例${instance}。请调用 \`ralphflow_cancel\` 工具${reason}
|
|
237
|
+
text: `用户执行了 /ralphflow-cancel,要取消工作流实例${instance}。请调用 \`ralphflow_cancel\` 工具${reason}——它会中止任何在飞的独立验证会话、把最终报告归档到精确路径并销毁实例目录;产出目录保留。若报告归档失败,它会保留实例目录不销毁并告警,请如实转达。然后向用户简短确认已取消(或转达错误),并把工具返回的报告路径给用户。`,
|
|
238
238
|
};
|
|
239
239
|
},
|
|
240
240
|
},
|
package/lib/verify.js
CHANGED
|
@@ -139,6 +139,8 @@ function waitForProvider(ctx, svc, name, waitMs) {
|
|
|
139
139
|
const VERIFIER_TOOL_ALLOW = ["read", "grep", "glob", "bash", "read_image"];
|
|
140
140
|
function resolveToolAllow(ctx) {
|
|
141
141
|
try {
|
|
142
|
+
// 宿主 0.2.3 的 ToolsService 类型不再声明 `schemas`,但运行期仍可直接调用;
|
|
143
|
+
// 走 `unknown` 转一手,保持运行期行为与旧版本一致(缺失时由下面的 catch 兜底)。
|
|
142
144
|
const schemas = ctx.tools.schemas();
|
|
143
145
|
const names = new Set(schemas.map((s) => s.name));
|
|
144
146
|
return VERIFIER_TOOL_ALLOW.filter((n) => names.has(n));
|
package/package.json
CHANGED