@galaxy-stack/blackhole-cli 2.1.4 → 2.1.6

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.
@@ -110,12 +110,63 @@ const TITLE_SCRIPT = [
110
110
  "})();",
111
111
  ].join("");
112
112
 
113
- const GALAXY_SEARCH_ID = "auto";
113
+ /* A real provider id. "auto" is the seam's policy (pick the only usable provider), not an id:
114
+ registering under it made the seam report the provider as configured but unavailable. */
115
+ const GALAXY_SEARCH_ID = "galaxy";
114
116
  const GALAXY_SEARCH_URL = "https://ollama.com/api/web_search";
117
+ const GALAXY_REF = "GBH_GALAXY_API_KEY";
118
+
119
+ /** A quoted scalar ends at its closing quote — a comment may follow it on the same line. */
120
+ function unquoteValue(raw) {
121
+ const value = raw.trim();
122
+ const quote = value.charAt(0);
123
+ if ((quote === '"' || quote === "'") && value.length >= 2) {
124
+ const end = value.indexOf(quote, 1);
125
+ if (end !== -1) return dequote(value.slice(0, end + 1));
126
+ }
127
+ const comment = value.search(/\s#/);
128
+ return (comment === -1 ? value : value.slice(0, comment)).trim();
129
+ }
130
+
131
+ function dequote(value) {
132
+ if (value.charAt(0) === '"') {
133
+ try { return JSON.parse(value); } catch (error) { return value.slice(1, -1); }
134
+ }
135
+ return value.slice(1, -1);
136
+ }
115
137
 
138
+ /**
139
+ * The key the first-run journey wrote, from the environment or the shared credential document
140
+ * (~/.galaxy/credentials.yaml, refs: GBH_GALAXY_API_KEY).
141
+ *
142
+ * Reading only the environment is why web_search reported "registered but unavailable" for every
143
+ * user who configured the key through setup instead of an env var.
144
+ */
116
145
  function galaxyKey() {
117
- const key = process.env.GBH_GALAXY_API_KEY;
118
- return typeof key === "string" && key.length > 0 ? key : undefined;
146
+ const fromEnv = process.env[GALAXY_REF];
147
+ if (typeof fromEnv === "string" && fromEnv.trim().length > 0) return fromEnv.trim();
148
+ return readGalaxyKeyFromDocument();
149
+ }
150
+
151
+ function readGalaxyKeyFromDocument() {
152
+ try {
153
+ const home = process.env.HOME ?? process.env.USERPROFILE;
154
+ if (typeof home !== "string" || home.length === 0) return undefined;
155
+ const lines = readFileSync(join(home, ".galaxy", "credentials.yaml"), "utf8").split(/\r?\n/);
156
+ let inRefs = false;
157
+ for (const line of lines) {
158
+ if (!inRefs) { inRefs = /^refs:\s*(#.*)?$/.test(line); continue; }
159
+ if (line.trim().length === 0 || line.trimStart().startsWith("#")) continue;
160
+ const match = /^\s+([^\s#][^:]*):\s*(.*)$/.exec(line);
161
+ if (match === null) break;
162
+ if (unquoteValue(match[1] ?? "") !== GALAXY_REF) continue;
163
+ const value = unquoteValue(match[2] ?? "");
164
+ return value.length === 0 ? undefined : value;
165
+ }
166
+ return undefined;
167
+ } catch (error) {
168
+ return undefined;
169
+ }
119
170
  }
120
171
 
121
172
  /** A ctx.web search provider over the Galaxy web search endpoint. */
@@ -156,13 +156,14 @@ function journeyToolDefinitions(host) {
156
156
  return [
157
157
  {
158
158
  name: "journey_get",
159
- description: "Read the workspace delivery-journey blueprint (journey.json): nodes, edges, revision, and validation issues. Read it before journey_set so the revision you send is current.",
159
+ description: "Read the workspace delivery-journey blueprint (journey.json): nodes, edges, revision, validation issues, and missingDescriptions — the nodes that still lack the description the run hands you for their step. Read it before journey_set so the revision you send is current.",
160
160
  parameters: objectSchema({ sessionId: { type: "string", description: "Session whose workspace holds the blueprint." } }, ["sessionId"]),
161
161
  output: textOutput,
162
162
  execute: async args => {
163
163
  const root = await workspaceRootOf(String(args.sessionId ?? ""));
164
164
  if (root === undefined) return { ok: false, code: "journey/no-workspace", message: "This session has no workspace directory." };
165
165
  const blueprint = readBlueprint(root);
166
+ const nodes = Array.isArray(blueprint.document?.nodes) ? blueprint.document.nodes : [];
166
167
  return {
167
168
  ok: blueprint.parseError === undefined,
168
169
  path: blueprint.path,
@@ -170,6 +171,11 @@ function journeyToolDefinitions(host) {
170
171
  revision: typeof blueprint.document?.revision === "number" ? blueprint.document.revision : 0,
171
172
  document: blueprint.document,
172
173
  issues: blueprint.document === undefined ? [] : validateBlueprint(blueprint.document),
174
+ /* A description is how the author tells the agent what a step means; naming the
175
+ gaps lets the agent fill them with journey_set instead of guessing. */
176
+ missingDescriptions: nodes
177
+ .filter(node => typeof node?.description !== "string" || node.description.trim().length === 0)
178
+ .map(node => node.id),
173
179
  };
174
180
  },
175
181
  },
@@ -194,7 +200,7 @@ function journeyToolDefinitions(host) {
194
200
  },
195
201
  {
196
202
  name: "journey_run",
197
- description: "Drive the delivery run of this workspace: op=start begins a run for a feature, op=advance executes the next runnable nodes, op=status and op=list read progress, op=decide approves, rejects, or retries a waiting node, op=cancel stops the run. Command actions execute in the workspace root.",
203
+ description: "Drive the delivery run of this workspace: op=start begins a run for a feature, op=advance executes the next runnable nodes, op=status and op=list read progress, op=decide approves, rejects, or retries a waiting node, op=cancel stops the run. Command actions execute in the workspace root. Every node row reports the kind, label, and description frozen from the blueprint, so read them before deciding a step.",
198
204
  parameters: objectSchema({
199
205
  sessionId: { type: "string", description: "Session whose workspace holds the blueprint." },
200
206
  op: { type: "string", description: "start | advance | status | list | decide | cancel" },
@@ -3,6 +3,10 @@
3
3
  export interface JourneyRunNodeState {
4
4
  state: string;
5
5
  attempts: number;
6
+ /** Node kind, label, and description frozen from the blueprint the run started from. */
7
+ kind?: string;
8
+ label?: string;
9
+ description?: string;
6
10
  evidence: Record<string, unknown>[];
7
11
  }
8
12
 
@@ -62,5 +66,5 @@ export declare function summarizeRun(run: JourneyRun): {
62
66
  status: string;
63
67
  blueprintRevision: number;
64
68
  counts: Record<string, number>;
65
- nodes: { nodeId: string; state: string; attempts: number; last: Record<string, unknown> | null }[];
69
+ nodes: { nodeId: string; state: string; attempts: number; kind?: string; label?: string; description?: string; last: Record<string, unknown> | null }[];
66
70
  };
@@ -111,9 +111,18 @@ export function createRun(input) {
111
111
  const document = input.document;
112
112
  const nodes = {};
113
113
  for (const node of document.nodes || []) {
114
- nodes[node.id] = { state: node.kind === "trigger" ? "done" : "pending", attempts: 0, evidence: [] };
114
+ /* The frozen blueprint travels with the run: whoever drives it (or reads the
115
+ evidence later) sees the label and description the author wrote for that step. */
116
+ nodes[node.id] = {
117
+ state: node.kind === "trigger" ? "done" : "pending",
118
+ attempts: 0,
119
+ kind: typeof node.kind === "string" ? node.kind : "action",
120
+ label: typeof node.label === "string" && node.label.length > 0 ? node.label : node.id,
121
+ description: typeof node.description === "string" ? node.description : "",
122
+ evidence: [],
123
+ };
115
124
  if (node.kind === "trigger") {
116
- nodes[node.id].evidence.push({ at: nowIso(input.now), status: "done", note: "trigger" });
125
+ nodes[node.id].evidence.push({ at: nowIso(input.now), status: "done", note: "trigger", description: nodes[node.id].description });
117
126
  }
118
127
  }
119
128
  const createdAt = nowIso(input.now);
@@ -309,7 +318,15 @@ export function summarizeRun(run) {
309
318
  status: run.status,
310
319
  blueprintRevision: run.blueprintRevision,
311
320
  counts,
312
- nodes: Object.entries(run.nodes).map(([nodeId, state]) => ({ nodeId, state: state.state, attempts: state.attempts, last: state.evidence[state.evidence.length - 1] ?? null })),
321
+ nodes: Object.entries(run.nodes).map(([nodeId, state]) => ({
322
+ nodeId,
323
+ state: state.state,
324
+ attempts: state.attempts,
325
+ kind: state.kind,
326
+ label: state.label,
327
+ description: state.description,
328
+ last: state.evidence[state.evidence.length - 1] ?? null,
329
+ })),
313
330
  };
314
331
  }
315
332
  //#endregion
@@ -39,7 +39,13 @@ export function canonicalJson(value) {
39
39
  return JSON.stringify(value ?? null);
40
40
  }
41
41
 
42
- /** The blueprint a workspace starts from. */
42
+ /**
43
+ * The blueprint a workspace starts from.
44
+ *
45
+ * Every node carries a `description`: the panel shows it on the card and the agent
46
+ * reads it (with the label and kind) before running that step, so the copy is part of
47
+ * the contract, not decoration.
48
+ */
43
49
  export function defaultBlueprint(now = new Date().toISOString()) {
44
50
  return {
45
51
  version: 1,
@@ -48,12 +54,12 @@ export function defaultBlueprint(now = new Date().toISOString()) {
48
54
  updatedBy: "template",
49
55
  variables: {},
50
56
  nodes: [
51
- { id: "dev", kind: "trigger", label: "Dev xong", x: 120, y: 80 },
52
- { id: "ci", kind: "gate", label: "CI xanh", x: 360, y: 80, gate: { kind: "ci", workflow: "ci.yml", ref: "main" } },
53
- { id: "uat", kind: "action", label: "UAT", x: 600, y: 80, actions: [{ kind: "npm", distTag: "alpha" }] },
54
- { id: "approve", kind: "approval", label: "Duyệt UAT", x: 840, y: 80 },
55
- { id: "prod", kind: "action", label: "PROD", x: 1080, y: 80, actions: [{ kind: "npm", distTag: "latest" }] },
56
- { id: "notify", kind: "notify", label: "Thông báo", x: 1320, y: 80 },
57
+ { id: "dev", kind: "trigger", label: "Dev xong", description: "Việc trong workspace đã xong: mã nguồn đã commit, sẵn sàng đi tiếp.", x: 120, y: 80 },
58
+ { id: "ci", kind: "gate", label: "CI xanh", description: "Cổng kiểm: pipeline CI phải xanh trên nhánh main trước khi đóng gói.", x: 360, y: 80, gate: { kind: "ci", workflow: "ci.yml", ref: "main" } },
59
+ { id: "uat", kind: "action", label: "UAT", description: "Đóng gói bản alpha để người dùng thử (npm dist-tag alpha).", x: 600, y: 80, actions: [{ kind: "npm", distTag: "alpha" }] },
60
+ { id: "approve", kind: "approval", label: "Duyệt UAT", description: "Người duyệt xác nhận bản alpha đạt yêu cầu trước khi lên PROD.", x: 840, y: 80 },
61
+ { id: "prod", kind: "action", label: "PROD", description: "Phát hành bản chính thức (npm dist-tag latest).", x: 1080, y: 80, actions: [{ kind: "npm", distTag: "latest" }] },
62
+ { id: "notify", kind: "notify", label: "Thông báo", description: "Thông báo kết quả hành trình cho người theo dõi.", x: 1320, y: 80 },
57
63
  ],
58
64
  edges: [
59
65
  { id: "e1", from: "dev", to: "ci", when: "always" },
@@ -5,6 +5,11 @@
5
5
  * __JOURNEY_PANEL__. The panel owns presentation only: the blueprint document it
6
6
  * renders comes from the Host route and every edit goes back through it, so the
7
7
  * agent and the canvas always share one reviewable source of truth.
8
+ *
9
+ * The canvas reads as a sequence: every edge leaves the out port of its source and
10
+ * lands on the in port of its target with an arrowhead plus the condition it carries,
11
+ * every node shows the step number of its longest path, and every node keeps a
12
+ * description the agent reads before it runs that step.
8
13
  */
9
14
  function createJourneyPanel(runtime) {
10
15
  const react = runtime.react;
@@ -16,6 +21,8 @@ function createJourneyPanel(runtime) {
16
21
  const KIND_LABEL = { trigger: "Bắt đầu", gate: "Cổng kiểm", action: "Hành động", approval: "Phê duyệt", join: "Gộp nhánh", notify: "Thông báo", rollback: "Hoàn tác" };
17
22
  const KIND_COLOR = { trigger: "#4f7cff", gate: "#e0a92b", action: "#2fa36b", approval: "#b06bd6", join: "#5a6472", notify: "#3aa0c9", rollback: "#e5484d" };
18
23
  const WHEN_LABEL = { success: "thành công", failure: "thất bại", always: "luôn" };
24
+ /** Edge colour by condition; the SVG arrowheads are keyed by the same names. */
25
+ const EDGE_COLOR = { success: "#4f7cff", failure: "#e5484d", always: "#8b93a1" };
19
26
  const GRID = 10;
20
27
  const NODE_W = 190;
21
28
  const NODE_H = 62;
@@ -60,19 +67,53 @@ function createJourneyPanel(runtime) {
60
67
  }), { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity });
61
68
  }
62
69
 
63
- function nodeCenter(node) {
64
- return { x: (node.x ?? 0) + NODE_W, y: (node.y ?? 0) + NODE_H / 2 };
70
+ /** Where an edge leaves its source: the out port on the right edge. */
71
+ function outAnchor(node) {
72
+ return { x: (node.x ?? 0) + NODE_W + 7, y: (node.y ?? 0) + NODE_H / 2 };
65
73
  }
66
74
 
67
- function edgePath(fromNode, toNode) {
68
- const a = nodeCenter(fromNode);
69
- const b = { x: (toNode.x ?? 0), y: (toNode.y ?? 0) + NODE_H / 2 };
75
+ /** Where an edge enters its target: the in port on the left edge. */
76
+ function inAnchor(node) {
77
+ return { x: (node.x ?? 0) - 7, y: (node.y ?? 0) + NODE_H / 2 };
78
+ }
79
+
80
+ /** The cubic one edge is drawn as, port to port. */
81
+ function edgeCurve(fromNode, toNode) {
82
+ const a = outAnchor(fromNode);
83
+ const b = inAnchor(toNode);
70
84
  const bend = Math.max(40, Math.abs(b.x - a.x) / 2);
71
- return "M " + a.x + " " + a.y + " C " + (a.x + bend) + " " + a.y + ", " + (b.x - bend) + " " + b.y + ", " + b.x + " " + b.y;
85
+ return { a: a, b: b, c1: { x: a.x + bend, y: a.y }, c2: { x: b.x - bend, y: b.y } };
86
+ }
87
+
88
+ function edgePath(fromNode, toNode) {
89
+ const curve = edgeCurve(fromNode, toNode);
90
+ return "M " + curve.a.x + " " + curve.a.y + " C " + curve.c1.x + " " + curve.c1.y + ", " + curve.c2.x + " " + curve.c2.y + ", " + curve.b.x + " " + curve.b.y;
91
+ }
92
+
93
+ /** Midpoint of that cubic, where the condition chip sits. */
94
+ function edgeMidpoint(fromNode, toNode) {
95
+ const curve = edgeCurve(fromNode, toNode);
96
+ return {
97
+ x: (curve.a.x + 3 * curve.c1.x + 3 * curve.c2.x + curve.b.x) / 8,
98
+ y: (curve.a.y + 3 * curve.c1.y + 3 * curve.c2.y + curve.b.y) / 8,
99
+ };
100
+ }
101
+
102
+ /** Longest path from a source node: the step number the canvas reads out. */
103
+ function depthMap(nodes, edges) {
104
+ const depth = new Map(nodes.map(node => [node.id, 0]));
105
+ for (let pass = 0; pass < nodes.length; pass += 1) {
106
+ for (const edge of edges) {
107
+ const from = depth.get(edge.from) ?? 0;
108
+ const to = depth.get(edge.to) ?? 0;
109
+ if (to < from + 1) depth.set(edge.to, from + 1);
110
+ }
111
+ }
112
+ return depth;
72
113
  }
73
114
 
74
115
  function Toolbar(props) {
75
- const { doc, dirty, status, path, view, run, mode, onSave, onReload, onZoom, onFit, onLayout, onAdd, onUndo, onRedo, onRun, onMode } = props;
116
+ const { doc, dirty, status, view, run, mode, onSave, onReload, onZoom, onFit, onLayout, onAdd, onUndo, onRedo, onRun, onMode } = props;
76
117
  const button = (label, onClick, options) => jsx("button", {
77
118
  type: "button",
78
119
  onClick,
@@ -95,11 +136,10 @@ function createJourneyPanel(runtime) {
95
136
  style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap", padding: "10px 12px", borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))" },
96
137
  children: [
97
138
  jsx("span", {
98
- title: path || t("toolbar.path"),
99
- style: { fontSize: "12px", opacity: 0.7, fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", maxWidth: "320px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
100
- children: path || t("toolbar.path"),
139
+ title: t("toolbar.revision"),
140
+ style: { fontSize: "12px", padding: "2px 8px", borderRadius: "999px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))" },
141
+ children: "rev " + String(doc && typeof doc.revision === "number" ? doc.revision : 0),
101
142
  }),
102
- jsx("span", { style: { fontSize: "12px", padding: "2px 8px", borderRadius: "999px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))" }, children: "rev " + String(doc && typeof doc.revision === "number" ? doc.revision : 0) }),
103
143
  button(t("toolbar.save") + (dirty ? " •" : ""), onSave, { primary: true, disabled: dirty === false, hook: "save" }),
104
144
  button(t("toolbar.reload"), onReload),
105
145
  button("↶", onUndo, { title: t("toolbar.undo") }),
@@ -132,17 +172,19 @@ function createJourneyPanel(runtime) {
132
172
  }
133
173
 
134
174
  function NodeCard(props) {
135
- const { node, selected, issue, runState, onPointerDown, onPortDown, onPortUp, onSelect } = props;
175
+ const { node, selected, issue, runState, step, dropTarget, onPointerDown, onPortDown, onSelect } = props;
136
176
  const color = KIND_COLOR[node.kind] || "#5a6472";
137
177
  const badgeColor = RUN_COLOR[runState] || "transparent";
178
+ const description = typeof node.description === "string" ? node.description.trim() : "";
179
+ const edgeColor = dropTarget ? "#2fa36b" : selected ? "#4f7cff" : "var(--dsw-alias-border-l2, rgba(127,127,127,.4))";
138
180
  return jsxs("div", {
139
181
  "data-gbh-node": node.id,
140
182
  onPointerDown: event => { onSelect(node.id, event.shiftKey); onPointerDown(event, node); },
141
183
  style: {
142
184
  position: "absolute", left: node.x ?? 0, top: node.y ?? 0, width: NODE_W + "px", minHeight: NODE_H + "px",
143
185
  borderRadius: "10px", background: "var(--dsw-alias-bg-module-platform, #23232a)",
144
- border: "1px solid " + (selected ? "#4f7cff" : "var(--dsw-alias-border-l2, rgba(127,127,127,.4))"),
145
- boxShadow: selected ? "0 0 0 2px rgba(79,124,255,.35)" : "0 6px 18px rgba(0,0,0,.25)",
186
+ border: "1px solid " + edgeColor,
187
+ boxShadow: dropTarget ? "0 0 0 3px rgba(47,163,107,.45)" : selected ? "0 0 0 2px rgba(79,124,255,.35)" : "0 6px 18px rgba(0,0,0,.25)",
146
188
  cursor: "grab", userSelect: "none", overflow: "visible",
147
189
  },
148
190
  children: [
@@ -150,7 +192,18 @@ function createJourneyPanel(runtime) {
150
192
  style: { display: "flex", alignItems: "center", gap: "6px", padding: "8px 10px", borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.22))" },
151
193
  children: [
152
194
  jsx("span", { style: { width: "8px", height: "8px", borderRadius: "50%", background: color, flex: "0 0 auto" } }),
195
+ step === undefined ? null : jsx("span", {
196
+ title: t("node.step"),
197
+ style: { flex: "0 0 auto", fontSize: "10px", opacity: 0.6, fontVariantNumeric: "tabular-nums" },
198
+ children: String(step),
199
+ }),
153
200
  jsx("span", { style: { fontSize: "12.5px", fontWeight: 600, flex: "1 1 auto", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: node.label || node.id }),
201
+ description.length > 0 ? null : jsx("span", {
202
+ "data-gbh-node-nodesc": "1",
203
+ title: t("node.noDescription"),
204
+ style: { flex: "0 0 auto", fontSize: "10.5px", color: "#e0a92b", cursor: "help" },
205
+ children: "?",
206
+ }),
154
207
  runState === undefined ? null : jsx("span", {
155
208
  title: RUN_LABEL[runState] || runState,
156
209
  style: { flex: "0 0 auto", fontSize: "10.5px", padding: "1px 6px", borderRadius: "999px", background: badgeColor, color: runState === "pending" ? "inherit" : "#101014" },
@@ -163,6 +216,11 @@ function createJourneyPanel(runtime) {
163
216
  children: [
164
217
  jsx("span", { children: KIND_LABEL[node.kind] || node.kind }),
165
218
  node.kind === "action" ? jsx("span", { children: (node.actions || []).map(a => a.kind).join(", ") || "—" }) : null,
219
+ description.length > 0 ? jsx("span", {
220
+ title: description,
221
+ style: { display: "-webkit-box", WebkitLineClamp: "3", WebkitBoxOrient: "vertical", overflow: "hidden", lineHeight: "14px", opacity: 0.95 },
222
+ children: description,
223
+ }) : null,
166
224
  issue ? jsx("span", { style: { color: "#ff8a8a" }, children: "⚠ " + issue.message }) : null,
167
225
  ],
168
226
  }),
@@ -172,7 +230,7 @@ function createJourneyPanel(runtime) {
172
230
  style: { position: "absolute", right: "-7px", top: (NODE_H / 2 - 7) + "px", width: "14px", height: "14px", borderRadius: "50%", background: color, border: "2px solid var(--dsw-alias-bg-module-platform, #23232a)", cursor: "crosshair" },
173
231
  }),
174
232
  jsx("span", {
175
- onPointerUp: event => { event.stopPropagation(); onPortUp(event, node); },
233
+ "data-gbh-port-in": node.id,
176
234
  title: t("node.inPort"),
177
235
  style: { position: "absolute", left: "-7px", top: (NODE_H / 2 - 7) + "px", width: "14px", height: "14px", borderRadius: "50%", background: "var(--dsw-alias-bg-module-platform, #23232a)", border: "2px solid " + color, cursor: "crosshair" },
178
236
  }),
@@ -200,6 +258,14 @@ function createJourneyPanel(runtime) {
200
258
  jsx("input", { style: field, value: node.id, disabled: true }),
201
259
  jsx("span", { style: label, children: t("inspector.label") }),
202
260
  jsx("input", { style: field, value: node.label || "", onChange: event => onPatchNode(node.id, { label: event.target.value }) }),
261
+ jsx("span", { style: label, children: t("inspector.description") }),
262
+ jsx("textarea", {
263
+ "data-gbh-description": node.id,
264
+ style: { ...field, height: "76px", padding: "6px 8px", resize: "vertical", fontFamily: "inherit" },
265
+ placeholder: t("inspector.descriptionHint"),
266
+ value: node.description || "",
267
+ onChange: event => onPatchNode(node.id, { description: event.target.value }),
268
+ }),
203
269
  jsx("span", { style: label, children: t("inspector.kind") }),
204
270
  jsx("select", {
205
271
  style: field, value: node.kind, onChange: event => onPatchNode(node.id, { kind: event.target.value }),
@@ -273,7 +339,6 @@ function createJourneyPanel(runtime) {
273
339
  const [canvasSize, setCanvasSize] = react.useState({ width: 900, height: 520 });
274
340
  const clipboard = react.useRef(null);
275
341
  const [status, setStatus] = react.useState(t("status.loading"));
276
- const [path, setPath] = react.useState("");
277
342
  const [dirty, setDirty] = react.useState(false);
278
343
  const [conflict, setConflict] = react.useState(null);
279
344
  const [pending, setPending] = react.useState(null);
@@ -288,7 +353,6 @@ function createJourneyPanel(runtime) {
288
353
  setDoc(result.document);
289
354
  setDirty(false);
290
355
  setConflict(null);
291
- setPath(typeof result.path === "string" ? result.path : "");
292
356
  history.current = { past: [], future: [] };
293
357
  setStatus(result.exists ? t("status.loaded") : t("status.newBlueprint"));
294
358
  });
@@ -479,11 +543,6 @@ function createJourneyPanel(runtime) {
479
543
  });
480
544
  return;
481
545
  }
482
- if (state.type === "edge") {
483
- const point = pointerToCanvas(event);
484
- setPending({ from: state.from, x: point.x, y: point.y });
485
- return;
486
- }
487
546
  if (state.type === "box") {
488
547
  const point = pointerToCanvas(event);
489
548
  setBox({
@@ -497,6 +556,10 @@ function createJourneyPanel(runtime) {
497
556
 
498
557
  const endDrag = () => {
499
558
  const state = drag.current;
559
+ /* An edge drag is owned by the window listeners that resolve its drop, so this
560
+ handler leaves it alone. Everything else — a node drag, a pan, a rubber band —
561
+ is released here: forget that and the node keeps following the pointer. */
562
+ if (state !== null && state !== undefined && state.type === "edge") return;
500
563
  drag.current = null;
501
564
  if (state === null || state === undefined || state.type !== "box") return;
502
565
  setBox(current => {
@@ -513,23 +576,71 @@ function createJourneyPanel(runtime) {
513
576
  });
514
577
  };
515
578
 
516
- const startEdge = (event, node, side) => {
579
+ /** The node under a viewport point: a connection may land anywhere on the card. */
580
+ const nodeAtPoint = event => {
581
+ const point = pointerToCanvas(event);
582
+ const nodes = (doc && doc.nodes) || [];
583
+ for (let index = nodes.length - 1; index >= 0; index -= 1) {
584
+ const node = nodes[index];
585
+ const x = node.x ?? 0;
586
+ const y = node.y ?? 0;
587
+ if (point.x >= x - 8 && point.x <= x + NODE_W + 8 && point.y >= y - 8 && point.y <= y + NODE_H + 46) return node.id;
588
+ }
589
+ return undefined;
590
+ };
591
+
592
+ /**
593
+ * Drag from an out port to any other node to connect them.
594
+ *
595
+ * The listeners live on the window (capture) instead of a pointer capture on the
596
+ * port: a capture retargets the release to the port itself, so the drop target
597
+ * never hears it and no edge is ever created.
598
+ */
599
+ const startEdge = (event, node) => {
600
+ if (event.button !== 0) return;
517
601
  const point = pointerToCanvas(event);
518
602
  drag.current = { type: "edge", from: node.id };
519
- setPending({ from: node.id, x: point.x, y: point.y });
520
- try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
603
+ setPending({ from: node.id, x: point.x, y: point.y, to: undefined });
604
+ const move = moveEvent => {
605
+ const next = pointerToCanvas(moveEvent);
606
+ setPending({ from: node.id, x: next.x, y: next.y, to: nodeAtPoint(moveEvent) });
607
+ };
608
+ const finish = upEvent => {
609
+ window.removeEventListener("pointermove", move, true);
610
+ window.removeEventListener("pointerup", finish, true);
611
+ const state = drag.current;
612
+ drag.current = null;
613
+ setPending(null);
614
+ if (state === null || state === undefined || state.type !== "edge") return;
615
+ const to = nodeAtPoint(upEvent);
616
+ if (to !== undefined) addEdge(state.from, to);
617
+ };
618
+ window.addEventListener("pointermove", move, true);
619
+ window.addEventListener("pointerup", finish, true);
521
620
  };
522
621
 
523
- const endEdge = (event, node) => {
524
- const state = drag.current;
525
- setPending(null);
526
- drag.current = null;
527
- if (state !== null && state !== undefined && state.type === "edge") addEdge(state.from, node.id);
622
+ /** Zoom so the canvas point under `anchor` (viewport pixels) stays put. */
623
+ const zoomAt = react.useCallback((factor, anchor) => {
624
+ setView(current => {
625
+ const z = Math.min(1.8, Math.max(0.4, current.z * factor));
626
+ if (z === current.z) return current;
627
+ const k = z / current.z;
628
+ return { z: z, tx: anchor.x - (anchor.x - current.tx) * k, ty: anchor.y - (anchor.y - current.ty) * k };
629
+ });
630
+ }, []);
631
+
632
+ /** The toolbar buttons zoom around the middle of the canvas. */
633
+ const zoomAtCenter = factor => {
634
+ const element = canvasRef.current;
635
+ if (element === null) { zoomAt(factor, { x: 450, y: 260 }); return; }
636
+ const rect = element.getBoundingClientRect();
637
+ zoomAt(factor, { x: rect.width / 2, y: rect.height / 2 });
528
638
  };
529
639
 
640
+ /* The wheel zooms where the pointer is, not at the canvas origin. */
530
641
  const onWheel = event => {
531
- const factor = event.deltaY < 0 ? 1.08 : 1 / 1.08;
532
- setView(current => ({ ...current, z: Math.min(1.8, Math.max(0.4, current.z * factor)) }));
642
+ const rect = canvasRef.current ? canvasRef.current.getBoundingClientRect() : { left: 0, top: 0 };
643
+ zoomAt(event.deltaY < 0 ? 1.08 : 1 / 1.08, { x: event.clientX - rect.left, y: event.clientY - rect.top });
533
644
  };
534
645
 
535
646
  const fit = () => {
@@ -689,6 +800,13 @@ function createJourneyPanel(runtime) {
689
800
  };
690
801
 
691
802
  const onKeyDown = event => {
803
+ if (event.key === "Escape") {
804
+ if (pending === null) return;
805
+ event.preventDefault();
806
+ drag.current = null;
807
+ setPending(null);
808
+ return;
809
+ }
692
810
  if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "z") {
693
811
  event.preventDefault();
694
812
  if (event.shiftKey) redo(); else undo();
@@ -718,6 +836,9 @@ function createJourneyPanel(runtime) {
718
836
  const byId = new Map(nodes.map(node => [node.id, node]));
719
837
  const issueByNode = new Map();
720
838
  for (const issue of issues) if (issue.nodeId !== undefined && !issueByNode.has(issue.nodeId)) issueByNode.set(issue.nodeId, issue);
839
+ /* Read order of the graph, and the node(s) whose edges stay lit while inspecting. */
840
+ const steps = depthMap(nodes, edges);
841
+ const focusIds = pickedNodes();
721
842
 
722
843
  return jsxs("div", {
723
844
  onKeyDown,
@@ -725,9 +846,9 @@ function createJourneyPanel(runtime) {
725
846
  style: { display: "flex", flexDirection: "column", height: "100%", outline: "none", background: "var(--dsw-alias-bg-base, #1b1b20)", color: "var(--dsw-alias-label-primary, #f2f2f2)" },
726
847
  children: [
727
848
  jsx(Toolbar, {
728
- doc, dirty, status: conflict === null ? status : t("status.conflict"), path,
849
+ doc, dirty, status: conflict === null ? status : t("status.conflict"),
729
850
  view, onSave: save, onReload: load,
730
- onZoom: factor => setView(current => ({ ...current, z: Math.min(1.8, Math.max(0.4, current.z * factor)) })),
851
+ onZoom: zoomAtCenter,
731
852
  onFit: fit, onLayout: autoLayout, onAdd: addNode, onUndo: undo, onRedo: redo,
732
853
  run, mode, onMode: switchMode,
733
854
  onRun: op => runAction(typeof op === "string" ? op : (run === null ? "start" : "advance")),
@@ -766,24 +887,54 @@ function createJourneyPanel(runtime) {
766
887
  width: "6000", height: "4000",
767
888
  style: { position: "absolute", left: 0, top: 0, pointerEvents: "none", overflow: "visible" },
768
889
  children: [
890
+ /* One arrowhead per condition, so an edge shows which way it runs. */
891
+ jsx("defs", {
892
+ children: Object.entries(EDGE_COLOR).map(entry => jsx("marker", {
893
+ id: "gbh-journey-arrow-" + entry[0],
894
+ viewBox: "0 0 8 8", refX: "8", refY: "4", markerWidth: "8", markerHeight: "8",
895
+ markerUnits: "userSpaceOnUse", orient: "auto",
896
+ children: jsx("path", { d: "M 0 0 L 8 4 L 0 8 z", fill: entry[1] }),
897
+ }, entry[0])),
898
+ }),
769
899
  ...edges.map(edge => {
770
900
  const from = byId.get(edge.from);
771
901
  const to = byId.get(edge.to);
772
902
  if (from === undefined || to === undefined) return null;
773
903
  const selected = picked.indexOf("edge:" + edge.id) !== -1;
774
- const color = edge.when === "failure" ? "#e5484d" : edge.when === "always" ? "#8b93a1" : "#4f7cff";
775
- return jsx("path", {
904
+ const kind = edge.when === "failure" ? "failure" : edge.when === "always" ? "always" : "success";
905
+ const color = EDGE_COLOR[kind];
906
+ const incident = focusIds.indexOf(edge.from) !== -1 || focusIds.indexOf(edge.to) !== -1;
907
+ const mid = edgeMidpoint(from, to);
908
+ return jsxs("g", {
776
909
  "data-gbh-edge": edge.id,
777
- d: edgePath(from, to), fill: "none", stroke: color,
778
- strokeWidth: selected ? 3 : 2,
779
- strokeDasharray: edge.when === "failure" ? "6 5" : undefined,
780
- style: { pointerEvents: "stroke", cursor: "pointer" },
781
- onPointerDown: event => { event.stopPropagation(); pickEdge(edge.id, event.shiftKey); },
910
+ "data-gbh-edge-when": kind,
911
+ opacity: focusIds.length > 0 && !incident ? 0.22 : 1,
912
+ children: [
913
+ jsx("path", {
914
+ d: edgePath(from, to), fill: "none", stroke: color,
915
+ strokeWidth: selected ? 3 : 2,
916
+ strokeDasharray: kind === "failure" ? "6 5" : undefined,
917
+ markerEnd: "url(#gbh-journey-arrow-" + kind + ")",
918
+ style: { pointerEvents: "stroke", cursor: "pointer" },
919
+ onPointerDown: event => { event.stopPropagation(); pickEdge(edge.id, event.shiftKey); },
920
+ }),
921
+ jsx("text", {
922
+ x: mid.x, y: mid.y - 7, textAnchor: "middle", fontSize: "10.5", fill: color,
923
+ style: { paintOrder: "stroke", stroke: "var(--dsw-alias-bg-base, #1b1b20)", strokeWidth: "4px", pointerEvents: "none", userSelect: "none" },
924
+ children: WHEN_LABEL[kind] || kind,
925
+ }),
926
+ ],
782
927
  }, edge.id);
783
928
  }),
784
929
  pending === null ? null : jsx("path", {
785
- d: "M " + ((byId.get(pending.from)?.x ?? 0) + NODE_W) + " " + ((byId.get(pending.from)?.y ?? 0) + NODE_H / 2) + " L " + pending.x + " " + pending.y,
930
+ d: (() => {
931
+ const source = byId.get(pending.from);
932
+ if (source === undefined) return "";
933
+ const anchor = outAnchor(source);
934
+ return "M " + anchor.x + " " + anchor.y + " L " + pending.x + " " + pending.y;
935
+ })(),
786
936
  fill: "none", stroke: "#4f7cff", strokeWidth: 2, strokeDasharray: "5 4",
937
+ markerEnd: "url(#gbh-journey-arrow-success)",
787
938
  }),
788
939
  ],
789
940
  }),
@@ -794,7 +945,9 @@ function createJourneyPanel(runtime) {
794
945
  node, selected: isPicked({ kind: "node", id: node.id }),
795
946
  issue: issueByNode.get(node.id),
796
947
  runState: run !== null && run.nodes !== undefined ? (run.nodes.find(entry => entry.nodeId === node.id) || {}).state : undefined,
797
- onPointerDown: startNodeDrag, onPortDown: startEdge, onPortUp: endEdge,
948
+ step: (steps.get(node.id) ?? 0) + 1,
949
+ dropTarget: pending !== null && pending.to === node.id,
950
+ onPointerDown: startNodeDrag, onPortDown: startEdge,
798
951
  onSelect: (id, additive) => pick({ kind: "node", id: id }, additive),
799
952
  }, node.id)),
800
953
  ],
@@ -1000,7 +1000,7 @@
1000
1000
  },
1001
1001
  "gbh.journey": {
1002
1002
  "view.journey": "Hành trình",
1003
- "toolbar.path": "chưa có blueprint",
1003
+ "toolbar.revision": "Bản sửa đổi blueprint",
1004
1004
  "toolbar.save": "Lưu",
1005
1005
  "toolbar.reload": "Tải lại",
1006
1006
  "toolbar.undo": "Hoàn tác",
@@ -1011,11 +1011,15 @@
1011
1011
  "toolbar.layout": "Tự xếp",
1012
1012
  "node.outPort": "Kéo để nối",
1013
1013
  "node.inPort": "Thả kết nối vào đây",
1014
+ "node.step": "Bước chạy theo thứ tự",
1015
+ "node.noDescription": "Chưa có mô tả — agent đọc mô tả này trước khi chạy bước.",
1014
1016
  "inspector.empty": "Chọn một node hoặc edge để sửa.",
1015
1017
  "inspector.node": "Node",
1016
1018
  "inspector.edge": "Edge",
1017
1019
  "inspector.id": "Id",
1018
1020
  "inspector.label": "Nhãn",
1021
+ "inspector.description": "Mô tả",
1022
+ "inspector.descriptionHint": "Bước này làm gì — cho agent chạy bước, và cho người đọc sơ đồ.",
1019
1023
  "inspector.kind": "Loại",
1020
1024
  "inspector.workflow": "Workflow",
1021
1025
  "inspector.actions": "Hành động (JSON)",