@galaxy-stack/blackhole-cli 2.0.1 → 2.0.3

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.
Files changed (64) hide show
  1. package/dist/application.d.ts.map +1 -1
  2. package/dist/application.js +3 -0
  3. package/dist/application.js.map +1 -1
  4. package/dist/cli.js +24 -0
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands.d.ts.map +1 -1
  7. package/dist/commands.js +2 -0
  8. package/dist/commands.js.map +1 -1
  9. package/dist/config-command.d.ts +35 -0
  10. package/dist/config-command.d.ts.map +1 -0
  11. package/dist/config-command.js +273 -0
  12. package/dist/config-command.js.map +1 -0
  13. package/dist/flow.d.ts.map +1 -1
  14. package/dist/flow.js +14 -3
  15. package/dist/flow.js.map +1 -1
  16. package/dist/info.d.ts +21 -0
  17. package/dist/info.d.ts.map +1 -0
  18. package/dist/info.js +33 -0
  19. package/dist/info.js.map +1 -0
  20. package/dist/logs.d.ts.map +1 -1
  21. package/dist/logs.js +10 -2
  22. package/dist/logs.js.map +1 -1
  23. package/dist/manual-config.d.ts +17 -0
  24. package/dist/manual-config.d.ts.map +1 -1
  25. package/dist/manual-config.js +35 -0
  26. package/dist/manual-config.js.map +1 -1
  27. package/dist/options.d.ts +2 -2
  28. package/dist/options.d.ts.map +1 -1
  29. package/dist/options.js +5 -1
  30. package/dist/options.js.map +1 -1
  31. package/dist/tui.d.ts.map +1 -1
  32. package/dist/tui.js +39 -1
  33. package/dist/tui.js.map +1 -1
  34. package/dist/update.d.ts +45 -0
  35. package/dist/update.d.ts.map +1 -0
  36. package/dist/update.js +158 -0
  37. package/dist/update.js.map +1 -0
  38. package/dist/web/web.d.ts.map +1 -1
  39. package/dist/web/web.js +16 -5
  40. package/dist/web/web.js.map +1 -1
  41. package/package.json +4 -3
  42. package/skills/galaxy-ui/SKILL.md +18 -0
  43. package/skills/orbit-framework/SKILL.md +18 -0
  44. package/web/brand/app-icon-192.png +0 -0
  45. package/web/brand/app-icon-512.png +0 -0
  46. package/web/brand/client.template.js +581 -79
  47. package/web/brand/dsh-locale-keys.json +2020 -0
  48. package/web/brand/favicon.png +0 -0
  49. package/web/brand/favicon.svg +12 -0
  50. package/web/brand/lib/app-icons.js +3 -0
  51. package/web/brand/lib/client.js +2303 -88
  52. package/web/brand/lib/favicon.js +1 -1
  53. package/web/brand/lib/index.js +618 -18
  54. package/web/brand/lib/journey-host.js +282 -0
  55. package/web/brand/lib/journey-run.d.ts +66 -0
  56. package/web/brand/lib/journey-run.js +315 -0
  57. package/web/brand/lib/journey-store.d.ts +61 -0
  58. package/web/brand/lib/journey-store.js +177 -0
  59. package/web/brand/logo.png +0 -0
  60. package/web/brand/logo.svg +20 -0
  61. package/web/brand/panel/journey-panel.js +884 -0
  62. package/web/brand/vi.locales.json +838 -8
  63. package/web/brand/zalo.jpg +0 -0
  64. package/web/patches/gbh-web.patch.yml +51 -2
@@ -0,0 +1,61 @@
1
+ /** Types for the gbh journey blueprint store (see journey-store.js). */
2
+
3
+ export interface JourneyNode {
4
+ id: string;
5
+ kind: string;
6
+ label?: string;
7
+ x?: number;
8
+ y?: number;
9
+ gate?: Record<string, unknown>;
10
+ actions?: Record<string, unknown>[];
11
+ [key: string]: unknown;
12
+ }
13
+
14
+ export interface JourneyEdge {
15
+ id?: string;
16
+ from: string;
17
+ to: string;
18
+ when?: string;
19
+ }
20
+
21
+ export interface JourneyDocument {
22
+ version?: number;
23
+ revision?: number;
24
+ updatedAt?: string;
25
+ updatedBy?: string;
26
+ variables?: Record<string, unknown>;
27
+ nodes: JourneyNode[];
28
+ edges: JourneyEdge[];
29
+ }
30
+
31
+ export interface JourneyIssue {
32
+ code: string;
33
+ message: string;
34
+ nodeId?: string;
35
+ edgeId?: string;
36
+ }
37
+
38
+ export type JourneyWriteResult =
39
+ | { ok: true; revision: number; hash: string; path: string }
40
+ | { ok: false; code: string; issues?: JourneyIssue[]; current?: { revision: number; document: JourneyDocument } };
41
+
42
+ export declare const BLUEPRINT_FILE: string;
43
+ export declare const JOURNEY_NODE_KINDS: readonly string[];
44
+ export declare const JOURNEY_EDGE_WHENS: readonly string[];
45
+ export declare const JOURNEY_ACTION_KINDS: readonly string[];
46
+ export declare function canonicalJson(value: unknown): string;
47
+ export declare function defaultBlueprint(now?: string): JourneyDocument;
48
+ export declare function blueprintPathFor(workspaceRoot: string): string;
49
+ export declare function validateBlueprint(document: unknown): JourneyIssue[];
50
+ export declare function readBlueprint(workspaceRoot: string): {
51
+ path: string;
52
+ exists: boolean;
53
+ document?: JourneyDocument;
54
+ hash?: string;
55
+ parseError?: string;
56
+ };
57
+ export declare function writeBlueprint(
58
+ root: string,
59
+ document: unknown,
60
+ options?: { expectedRevision?: number; updatedBy?: string },
61
+ ): JourneyWriteResult;
@@ -0,0 +1,177 @@
1
+ //#region gbh journey blueprint store
2
+ /**
3
+ * Blueprint storage for the Galaxy delivery journey.
4
+ *
5
+ * One blueprint per workspace root: \`<workspace>/journey.json\`. When the workspace
6
+ * is a repository that file is tracked by git, so both the panel and the agent edit
7
+ * a reviewable document instead of hidden UI state.
8
+ *
9
+ * The host owns every filesystem touch: the browser sends a session id and a
10
+ * document, never a path. The workspace root is resolved from the trusted session
11
+ * record, and every write is compare-and-swap on the document revision plus an
12
+ * atomic replace, so two writers can never silently overwrite each other.
13
+ */
14
+ import { createHash } from "node:crypto";
15
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
16
+ import { dirname, join, resolve, sep } from "node:path";
17
+
18
+ /** Blueprint file name at the workspace root. */
19
+ export const BLUEPRINT_FILE = "journey.json";
20
+ /** Node kinds the canvas and the validator understand. */
21
+ export const JOURNEY_NODE_KINDS = ["trigger", "gate", "action", "approval", "join", "notify", "rollback"];
22
+ /** Edge conditions a branch may carry. */
23
+ export const JOURNEY_EDGE_WHENS = ["success", "failure", "always"];
24
+
25
+ /** Action adapters the host may execute; only declared kinds are ever run. */
26
+ export const JOURNEY_ACTION_KINDS = ["command", "npm", "git", "http", "ci", "mcp", "manual"];
27
+
28
+ function sha256(value) {
29
+ return "sha256:" + createHash("sha256").update(value).digest("hex");
30
+ }
31
+
32
+ /** Canonical JSON: sorted keys, so a hash never depends on property order. */
33
+ export function canonicalJson(value) {
34
+ if (Array.isArray(value)) return "[" + value.map(canonicalJson).join(",") + "]";
35
+ if (value !== null && typeof value === "object") {
36
+ const keys = Object.keys(value).sort();
37
+ return "{" + keys.map(key => JSON.stringify(key) + ":" + canonicalJson(value[key])).join(",") + "}";
38
+ }
39
+ return JSON.stringify(value ?? null);
40
+ }
41
+
42
+ /** The blueprint a workspace starts from. */
43
+ export function defaultBlueprint(now = new Date().toISOString()) {
44
+ return {
45
+ version: 1,
46
+ revision: 0,
47
+ updatedAt: now,
48
+ updatedBy: "template",
49
+ variables: {},
50
+ 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
+ ],
58
+ edges: [
59
+ { id: "e1", from: "dev", to: "ci", when: "always" },
60
+ { id: "e2", from: "ci", to: "uat", when: "success" },
61
+ { id: "e3", from: "uat", to: "approve", when: "success" },
62
+ { id: "e4", from: "approve", to: "prod", when: "success" },
63
+ { id: "e5", from: "prod", to: "notify", when: "success" },
64
+ ],
65
+ };
66
+ }
67
+
68
+ /** Workspace root a blueprint belongs to, from a trusted session directory. */
69
+ export function blueprintPathFor(workspaceRoot) {
70
+ if (typeof workspaceRoot !== "string" || workspaceRoot.trim().length === 0) {
71
+ throw new Error("journey: the session has no workspace directory");
72
+ }
73
+ const root = resolve(workspaceRoot.trim());
74
+ const path = join(root, BLUEPRINT_FILE);
75
+ if (!(path === join(root, BLUEPRINT_FILE) && resolve(path).startsWith(root + sep))) {
76
+ throw new Error("journey: refusing a blueprint outside the workspace root");
77
+ }
78
+ return path;
79
+ }
80
+
81
+ /** Structural validation shared by the panel route and the agent tools. */
82
+ export function validateBlueprint(document) {
83
+ const issues = [];
84
+ if (document === null || typeof document !== "object" || Array.isArray(document)) {
85
+ return [{ code: "document", message: "Blueprint must be a JSON object." }];
86
+ }
87
+ if (!Array.isArray(document.nodes) || document.nodes.length === 0) {
88
+ issues.push({ code: "nodes", message: "Blueprint needs at least one node." });
89
+ }
90
+ const ids = new Set();
91
+ for (const node of Array.isArray(document.nodes) ? document.nodes : []) {
92
+ if (node === null || typeof node !== "object") {
93
+ issues.push({ code: "node", message: "Every node must be an object." });
94
+ continue;
95
+ }
96
+ if (typeof node.id !== "string" || node.id.length === 0) issues.push({ code: "node.id", message: "Node id is required." });
97
+ else if (ids.has(node.id)) issues.push({ code: "node.id", message: "Duplicate node id: " + node.id, nodeId: node.id });
98
+ else ids.add(node.id);
99
+ if (!JOURNEY_NODE_KINDS.includes(node.kind)) {
100
+ issues.push({ code: "node.kind", message: "Unknown node kind: " + String(node.kind), nodeId: node.id });
101
+ }
102
+ if (node.kind === "action" && (!Array.isArray(node.actions) || node.actions.length === 0)) {
103
+ issues.push({ code: "node.actions", message: "An action node needs at least one action.", nodeId: node.id });
104
+ }
105
+ for (const action of Array.isArray(node.actions) ? node.actions : []) {
106
+ if (!JOURNEY_ACTION_KINDS.includes(action?.kind)) {
107
+ issues.push({ code: "action.kind", message: "Unknown action kind: " + String(action?.kind), nodeId: node.id });
108
+ }
109
+ if (typeof action?.secret === "string") {
110
+ issues.push({ code: "action.secret", message: "Secrets must be referenced as secretRef, never inlined.", nodeId: node.id });
111
+ }
112
+ }
113
+ }
114
+ for (const edge of Array.isArray(document.edges) ? document.edges : []) {
115
+ if (!ids.has(edge?.from) || !ids.has(edge?.to)) {
116
+ issues.push({ code: "edge.endpoint", message: "Edge refers to a missing node.", edgeId: edge?.id });
117
+ }
118
+ if (edge?.from === edge?.to) issues.push({ code: "edge.loop", message: "Edge cannot loop on one node.", edgeId: edge?.id });
119
+ if (edge?.when !== undefined && !JOURNEY_EDGE_WHENS.includes(edge.when)) {
120
+ issues.push({ code: "edge.when", message: "Unknown edge condition: " + String(edge.when), edgeId: edge?.id });
121
+ }
122
+ }
123
+ return issues;
124
+ }
125
+
126
+ /** Read a workspace blueprint; a missing file reports the default document. */
127
+ export function readBlueprint(workspaceRoot) {
128
+ const path = blueprintPathFor(workspaceRoot);
129
+ if (!existsSync(path)) {
130
+ return { path, exists: false, document: defaultBlueprint(), hash: undefined };
131
+ }
132
+ const raw = readFileSync(path, "utf8");
133
+ let document;
134
+ try {
135
+ document = JSON.parse(raw);
136
+ } catch (error) {
137
+ return { path, exists: true, document: undefined, hash: sha256(raw), parseError: error instanceof Error ? error.message : String(error) };
138
+ }
139
+ return { path, exists: true, document, hash: sha256(canonicalJson(document)) };
140
+ }
141
+
142
+ /**
143
+ * Write a workspace blueprint under compare-and-swap.
144
+ *
145
+ * @param root - workspace root from the trusted session record.
146
+ * @param document - the blueprint the caller edited.
147
+ * @param options.expectedRevision - revision the caller read; a mismatch refuses.
148
+ * @param options.updatedBy - "human" for the panel, "agent" for tooling.
149
+ * @returns the stored revision and hash.
150
+ */
151
+ export function writeBlueprint(root, document, options = {}) {
152
+ const issues = validateBlueprint(document);
153
+ if (issues.length > 0) return { ok: false, code: "journey/invalid", issues };
154
+ const path = blueprintPathFor(root);
155
+ const current = readBlueprint(root);
156
+ const expected = options.expectedRevision;
157
+ if (typeof expected === "number" && current.exists && current.document !== undefined) {
158
+ const live = typeof current.document.revision === "number" ? current.document.revision : 0;
159
+ if (live !== expected) {
160
+ return { ok: false, code: "journey/conflict", current: { revision: live, document: current.document } };
161
+ }
162
+ }
163
+ const revision = (current.exists && typeof current.document?.revision === "number" ? current.document.revision : 0) + 1;
164
+ const stored = {
165
+ ...document,
166
+ version: typeof document.version === "number" ? document.version : 1,
167
+ revision,
168
+ updatedAt: new Date().toISOString(),
169
+ updatedBy: typeof options.updatedBy === "string" ? options.updatedBy : "human",
170
+ };
171
+ mkdirSync(dirname(path), { recursive: true });
172
+ const temporary = path + ".tmp-" + process.pid;
173
+ writeFileSync(temporary, JSON.stringify(stored, null, 2) + "\n", { encoding: "utf8", mode: 0o644 });
174
+ renameSync(temporary, path);
175
+ return { ok: true, revision, hash: sha256(canonicalJson(stored)), path };
176
+ }
177
+ //#endregion
Binary file
@@ -0,0 +1,20 @@
1
+ <svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Galaxy Blackhole">
2
+ <defs>
3
+ <radialGradient id="ring" cx="50%" cy="50%" r="50%">
4
+ <stop offset="55%" stop-color="#8b7bff" stop-opacity="0.05"/>
5
+ <stop offset="78%" stop-color="#8b7bff" stop-opacity="0.85"/>
6
+ <stop offset="92%" stop-color="#6ee7f0" stop-opacity="0.9"/>
7
+ <stop offset="100%" stop-color="#6ee7f0" stop-opacity="0"/>
8
+ </radialGradient>
9
+ <linearGradient id="arc" x1="18" y1="30" x2="110" y2="98" gradientUnits="userSpaceOnUse">
10
+ <stop stop-color="#a99bff"/>
11
+ <stop offset="1" stop-color="#6ee7f0"/>
12
+ </linearGradient>
13
+ </defs>
14
+ <circle cx="64" cy="64" r="62" fill="#0b0a14"/>
15
+ <circle cx="64" cy="64" r="46" fill="url(#ring)"/>
16
+ <circle cx="64" cy="64" r="22" fill="#05040a"/>
17
+ <circle cx="64" cy="64" r="22" stroke="#a99bff" stroke-opacity="0.55" stroke-width="1.5"/>
18
+ <ellipse cx="64" cy="64" rx="52" ry="18" stroke="url(#arc)" stroke-width="3" stroke-linecap="round" transform="rotate(-18 64 64)"/>
19
+ <ellipse cx="64" cy="64" rx="40" ry="12" stroke="#6ee7f0" stroke-opacity="0.45" stroke-width="1.5" transform="rotate(-18 64 64)"/>
20
+ </svg>