Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 522afdd4bd | |||
| ca644dabaa | |||
| 9d9c00df98 | |||
| a1c5dc3e92 | |||
| c85980f604 | |||
| eff5fb332a | |||
| 658a4a24ef | |||
| aabfd90a87 | |||
| 0207f93303 | |||
| e1423f196b | |||
| ae6954a02f | |||
| aede8f7613 | |||
| 6d1e0498ba | |||
| 6cce5e2593 | |||
| d3a7ed9062 | |||
| e7f733c393 | |||
| d4bb4a9324 | |||
| 39540d9ae8 |
@@ -0,0 +1,8 @@
|
|||||||
|
# Changesets
|
||||||
|
|
||||||
|
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
||||||
|
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
||||||
|
find the full documentation for it [in our repository](https://github.com/changesets/changesets).
|
||||||
|
|
||||||
|
We have a quick list of common questions to get you started engaging with this project in
|
||||||
|
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://unpkg.com/@changesets/config@3.1.4/schema.json",
|
||||||
|
"changelog": "@changesets/cli/changelog",
|
||||||
|
"commit": false,
|
||||||
|
"fixed": [
|
||||||
|
[
|
||||||
|
"@uncaged/*"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"linked": [],
|
||||||
|
"access": "restricted",
|
||||||
|
"baseBranch": "main",
|
||||||
|
"updateInternalDependencies": "patch",
|
||||||
|
"ignore": [
|
||||||
|
"@uncaged/workflow-dashboard"
|
||||||
|
]
|
||||||
|
}
|
||||||
+6
-2
@@ -13,11 +13,15 @@
|
|||||||
"link": "./scripts/link-all.sh",
|
"link": "./scripts/link-all.sh",
|
||||||
"link:consume": "./scripts/link-all.sh --consume",
|
"link:consume": "./scripts/link-all.sh --consume",
|
||||||
"link:unlink": "./scripts/link-all.sh --unlink",
|
"link:unlink": "./scripts/link-all.sh --unlink",
|
||||||
"publish:gitea": "./scripts/publish-all.sh",
|
"publish:gitea": "./scripts/publish.sh patch",
|
||||||
"publish:gitea:dry": "./scripts/publish-all.sh --dry-run"
|
"publish:gitea:dry": "./scripts/publish.sh --dry-run patch",
|
||||||
|
"changeset": "bunx changeset",
|
||||||
|
"version": "bunx changeset version",
|
||||||
|
"release": "bunx changeset publish --no-git-tag"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^2.4.14",
|
"@biomejs/biome": "^2.4.14",
|
||||||
|
"@changesets/cli": "^2.31.0",
|
||||||
"@types/node": "^25.7.0",
|
"@types/node": "^25.7.0",
|
||||||
"@types/xxhashjs": "^0.2.4",
|
"@types/xxhashjs": "^0.2.4",
|
||||||
"bun-types": "^1.3.13"
|
"bun-types": "^1.3.13"
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# @uncaged/cli-workflow
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-cas@0.4.0
|
||||||
|
- @uncaged/workflow-execute@0.4.0
|
||||||
|
- @uncaged/workflow-gateway@0.4.0
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
|
- @uncaged/workflow-register@0.4.0
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
|
- @uncaged/workflow-util@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/cli-workflow",
|
"name": "@uncaged/cli-workflow",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"dist",
|
"dist",
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# @uncaged/workflow-agent-cursor
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
|
- @uncaged/workflow-reactor@0.4.0
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
|
- @uncaged/workflow-util-agent@0.4.0
|
||||||
|
- @uncaged/workflow-util@0.4.0
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-agent-cursor",
|
"name": "@uncaged/workflow-agent-cursor",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
"types": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test"
|
"test": "bun test"
|
||||||
@@ -21,8 +20,9 @@
|
|||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-agent-hermes
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
|
- @uncaged/workflow-util-agent@0.4.0
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-agent-hermes",
|
"name": "@uncaged/workflow-agent-hermes",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
"types": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test"
|
"test": "bun test"
|
||||||
@@ -17,8 +16,9 @@
|
|||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-agent-llm
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
|
- @uncaged/workflow-util-agent@0.4.0
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-agent-llm",
|
"name": "@uncaged/workflow-agent-llm",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
"types": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test"
|
"test": "bun test"
|
||||||
@@ -20,8 +19,9 @@
|
|||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# @uncaged/workflow-agent-react
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
|
- @uncaged/workflow-reactor@0.4.0
|
||||||
|
- @uncaged/workflow-util-agent@0.4.0
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-agent-react",
|
"name": "@uncaged/workflow-agent-react",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
"types": "src/index.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./src/index.ts",
|
"bun": "./src/index.ts",
|
||||||
"default": "./src/index.ts"
|
"types": "./dist/index.d.ts",
|
||||||
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-cas
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
|
- @uncaged/workflow-util@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-cas",
|
"name": "@uncaged/workflow-cas",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -11,8 +11,9 @@
|
|||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -13,9 +13,7 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dagrejs/dagre": "^3.0.0",
|
|
||||||
"@xyflow/react": "^12.10.2",
|
"@xyflow/react": "^12.10.2",
|
||||||
"elkjs": "^0.11.1",
|
|
||||||
"react": "^19.2.6",
|
"react": "^19.2.6",
|
||||||
"react-dom": "^19.2.6",
|
"react-dom": "^19.2.6",
|
||||||
"react-markdown": "^10.1.0",
|
"react-markdown": "^10.1.0",
|
||||||
|
|||||||
@@ -6,6 +6,42 @@ import {
|
|||||||
} from "@xyflow/react";
|
} from "@xyflow/react";
|
||||||
import type { ConditionEdgeData } from "./types.ts";
|
import type { ConditionEdgeData } from "./types.ts";
|
||||||
|
|
||||||
|
// Must match the FEEDBACK_OFFSET_X in use-layout.ts
|
||||||
|
const FEEDBACK_OFFSET_X = 100;
|
||||||
|
// Radius for feedback edge corners
|
||||||
|
const FEEDBACK_RADIUS = 16;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build an SVG path for a feedback (back) edge that routes to the right of the nodes.
|
||||||
|
* The path goes: source right → arc → vertical up → arc → target right
|
||||||
|
*/
|
||||||
|
function feedbackPath(
|
||||||
|
sourceX: number,
|
||||||
|
sourceY: number,
|
||||||
|
targetX: number,
|
||||||
|
targetY: number,
|
||||||
|
): string {
|
||||||
|
const rightX = Math.max(sourceX, targetX) + FEEDBACK_OFFSET_X;
|
||||||
|
const r = FEEDBACK_RADIUS;
|
||||||
|
|
||||||
|
// Start from source right side, go right, then up, then left to target right side
|
||||||
|
const segments = [
|
||||||
|
`M ${sourceX} ${sourceY}`,
|
||||||
|
// Horizontal to the right
|
||||||
|
`L ${rightX - r} ${sourceY}`,
|
||||||
|
// Arc turning upward
|
||||||
|
`Q ${rightX} ${sourceY} ${rightX} ${sourceY - r}`,
|
||||||
|
// Vertical upward
|
||||||
|
`L ${rightX} ${targetY + r}`,
|
||||||
|
// Arc turning left
|
||||||
|
`Q ${rightX} ${targetY} ${rightX - r} ${targetY}`,
|
||||||
|
// Horizontal left to target
|
||||||
|
`L ${targetX} ${targetY}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
return segments.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
export function ConditionEdge(props: EdgeProps) {
|
export function ConditionEdge(props: EdgeProps) {
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
@@ -23,25 +59,41 @@ export function ConditionEdge(props: EdgeProps) {
|
|||||||
const edgeData = data as ConditionEdgeData | undefined;
|
const edgeData = data as ConditionEdgeData | undefined;
|
||||||
const isFallback = edgeData?.isFallback ?? false;
|
const isFallback = edgeData?.isFallback ?? false;
|
||||||
const isSelfLoop = source === target;
|
const isSelfLoop = source === target;
|
||||||
|
const isFeedback = edgeData?.isFeedback ?? false;
|
||||||
|
|
||||||
const [path, defaultLabelX, defaultLabelY] = getSmoothStepPath({
|
let path: string;
|
||||||
sourceX,
|
let defaultLabelX: number;
|
||||||
sourceY,
|
let defaultLabelY: number;
|
||||||
targetX,
|
|
||||||
targetY,
|
if (isFeedback) {
|
||||||
sourcePosition,
|
// Custom feedback path routed to the right
|
||||||
targetPosition,
|
path = feedbackPath(sourceX, sourceY, targetX, targetY);
|
||||||
borderRadius: isSelfLoop ? 20 : 8,
|
const rightX = Math.max(sourceX, targetX) + FEEDBACK_OFFSET_X;
|
||||||
offset: isSelfLoop ? 50 : undefined,
|
defaultLabelX = rightX;
|
||||||
});
|
defaultLabelY = (sourceY + targetY) / 2;
|
||||||
|
} else {
|
||||||
|
const result = getSmoothStepPath({
|
||||||
|
sourceX,
|
||||||
|
sourceY,
|
||||||
|
targetX,
|
||||||
|
targetY,
|
||||||
|
sourcePosition,
|
||||||
|
targetPosition,
|
||||||
|
borderRadius: isSelfLoop ? 20 : 8,
|
||||||
|
offset: isSelfLoop ? 50 : undefined,
|
||||||
|
});
|
||||||
|
path = result[0];
|
||||||
|
defaultLabelX = result[1];
|
||||||
|
defaultLabelY = result[2];
|
||||||
|
}
|
||||||
|
|
||||||
const stroke = isFallback ? "var(--color-text-muted)" : "var(--color-accent)";
|
const stroke = isFallback ? "var(--color-text-muted)" : "var(--color-accent)";
|
||||||
const strokeDasharray = isFallback ? "5 4" : undefined;
|
const strokeDasharray = isFallback ? "5 4" : undefined;
|
||||||
const label = edgeData?.condition ?? "";
|
const label = edgeData?.condition ?? "";
|
||||||
|
|
||||||
// Use ELK-computed label position if available, otherwise fall back to ReactFlow default
|
// Use pre-computed label position if available, otherwise fall back to default
|
||||||
const labelX = edgeData?.elkLabelX ?? defaultLabelX;
|
const labelX = edgeData?.labelX ?? defaultLabelX;
|
||||||
const labelY = edgeData?.elkLabelY ?? defaultLabelY;
|
const labelY = edgeData?.labelY ?? defaultLabelY;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ export type ConditionEdgeData = {
|
|||||||
condition: string;
|
condition: string;
|
||||||
conditionDescription: string | null;
|
conditionDescription: string | null;
|
||||||
isFallback: boolean;
|
isFallback: boolean;
|
||||||
elkLabelX: number | null;
|
isFeedback: boolean;
|
||||||
elkLabelY: number | null;
|
isSelfLoop: boolean;
|
||||||
|
labelX: number | null;
|
||||||
|
labelY: number | null;
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { Edge, Node } from "@xyflow/react";
|
import type { Edge, Node } from "@xyflow/react";
|
||||||
import ELK, { type ElkExtendedEdge, type ElkNode } from "elkjs/lib/elk.bundled.js";
|
import { useMemo } from "react";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import type { WorkflowGraphEdge } from "../../api.ts";
|
import type { WorkflowGraphEdge } from "../../api.ts";
|
||||||
import type { ConditionEdgeData, NodeState, RoleNodeData, TerminalNodeData } from "./types.ts";
|
import type { ConditionEdgeData, NodeState, RoleNodeData, TerminalNodeData } from "./types.ts";
|
||||||
|
|
||||||
@@ -10,6 +9,11 @@ const ROLE_NODE_WIDTH = 180;
|
|||||||
const ROLE_NODE_HEIGHT = 60;
|
const ROLE_NODE_HEIGHT = 60;
|
||||||
const TERMINAL_NODE_SIZE = 40;
|
const TERMINAL_NODE_SIZE = 40;
|
||||||
|
|
||||||
|
// Vertical gap between nodes in the spine
|
||||||
|
const LAYER_GAP = 80;
|
||||||
|
// Horizontal offset for feedback (back) edges routed on the right side
|
||||||
|
const FEEDBACK_OFFSET_X = 100;
|
||||||
|
|
||||||
type LayoutInput = {
|
type LayoutInput = {
|
||||||
edges: readonly WorkflowGraphEdge[];
|
edges: readonly WorkflowGraphEdge[];
|
||||||
roles: Record<string, { description: string }>;
|
roles: Record<string, { description: string }>;
|
||||||
@@ -21,15 +25,6 @@ type LayoutResult = {
|
|||||||
edges: Edge[];
|
edges: Edge[];
|
||||||
};
|
};
|
||||||
|
|
||||||
function collectNodeIds(edges: readonly WorkflowGraphEdge[]): Set<string> {
|
|
||||||
const ids = new Set<string>();
|
|
||||||
for (const e of edges) {
|
|
||||||
ids.add(e.from);
|
|
||||||
ids.add(e.to);
|
|
||||||
}
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
function nodeSize(id: string): { width: number; height: number } {
|
function nodeSize(id: string): { width: number; height: number } {
|
||||||
if (id === START_ID || id === END_ID) {
|
if (id === START_ID || id === END_ID) {
|
||||||
return { width: TERMINAL_NODE_SIZE, height: TERMINAL_NODE_SIZE };
|
return { width: TERMINAL_NODE_SIZE, height: TERMINAL_NODE_SIZE };
|
||||||
@@ -41,6 +36,75 @@ function edgeKey(e: WorkflowGraphEdge): string {
|
|||||||
return `${e.from}->${e.to}::${e.condition}`;
|
return `${e.from}->${e.to}::${e.condition}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the linear spine from the graph using topological ordering.
|
||||||
|
* Forward edges go from lower rank to higher rank; feedback edges go backwards.
|
||||||
|
* Self-loops are neither forward nor feedback — they're handled separately.
|
||||||
|
*/
|
||||||
|
function extractSpine(edges: readonly WorkflowGraphEdge[]): string[] {
|
||||||
|
// Collect all node IDs
|
||||||
|
const ids = new Set<string>();
|
||||||
|
for (const e of edges) {
|
||||||
|
ids.add(e.from);
|
||||||
|
ids.add(e.to);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build adjacency for forward edges only (non-self-loop, non-FALLBACK-back)
|
||||||
|
// Strategy: BFS from __start__, picking the first non-FALLBACK forward edge,
|
||||||
|
// or FALLBACK if no other option.
|
||||||
|
const forwardAdj = new Map<string, string[]>();
|
||||||
|
for (const e of edges) {
|
||||||
|
if (e.from === e.to) continue;
|
||||||
|
const existing = forwardAdj.get(e.from) ?? [];
|
||||||
|
existing.push(e.to);
|
||||||
|
forwardAdj.set(e.from, existing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Walk the main path: prefer non-FALLBACK edges for the spine ordering
|
||||||
|
const visited = new Set<string>();
|
||||||
|
const spine: string[] = [];
|
||||||
|
|
||||||
|
// Build a set of "primary" next targets per node (non-FALLBACK first)
|
||||||
|
const primaryNext = new Map<string, string>();
|
||||||
|
const edgesByFrom = new Map<string, WorkflowGraphEdge[]>();
|
||||||
|
for (const e of edges) {
|
||||||
|
if (e.from === e.to) continue;
|
||||||
|
const list = edgesByFrom.get(e.from) ?? [];
|
||||||
|
list.push(e);
|
||||||
|
edgesByFrom.set(e.from, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For each node, the "primary" next is the first non-FALLBACK target,
|
||||||
|
// or the FALLBACK target if all edges are FALLBACK
|
||||||
|
for (const [from, edgeList] of edgesByFrom) {
|
||||||
|
const nonFallback = edgeList.find((e) => e.condition !== "FALLBACK");
|
||||||
|
const fallback = edgeList.find((e) => e.condition === "FALLBACK");
|
||||||
|
primaryNext.set(from, nonFallback?.to ?? fallback?.to ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Walk the spine from __start__
|
||||||
|
let current: string | null = START_ID;
|
||||||
|
while (current !== null && !visited.has(current)) {
|
||||||
|
visited.add(current);
|
||||||
|
spine.push(current);
|
||||||
|
const next = primaryNext.get(current);
|
||||||
|
if (next !== undefined && next !== "" && !visited.has(next)) {
|
||||||
|
current = next;
|
||||||
|
} else {
|
||||||
|
current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add any remaining nodes not on the main path (shouldn't normally happen)
|
||||||
|
for (const id of ids) {
|
||||||
|
if (!visited.has(id)) {
|
||||||
|
spine.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return spine;
|
||||||
|
}
|
||||||
|
|
||||||
function buildRoleNode(
|
function buildRoleNode(
|
||||||
id: string,
|
id: string,
|
||||||
pos: { x: number; y: number },
|
pos: { x: number; y: number },
|
||||||
@@ -72,143 +136,95 @@ function buildTerminalNode(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildEdge(e: WorkflowGraphEdge, elkEdgeMap: Map<string, ElkExtendedEdge>): Edge<ConditionEdgeData> {
|
function computeLayout(input: LayoutInput): LayoutResult {
|
||||||
const isFallback = e.condition === "FALLBACK";
|
const spine = extractSpine(input.edges);
|
||||||
const key = edgeKey(e);
|
const rank = new Map<string, number>();
|
||||||
const elkEdge = elkEdgeMap.get(key);
|
for (let i = 0; i < spine.length; i++) {
|
||||||
|
rank.set(spine[i], i);
|
||||||
// Extract ELK's computed label position
|
|
||||||
let labelX: number | null = null;
|
|
||||||
let labelY: number | null = null;
|
|
||||||
if (elkEdge?.labels && elkEdge.labels.length > 0) {
|
|
||||||
const label = elkEdge.labels[0];
|
|
||||||
if (label.x !== undefined && label.y !== undefined) {
|
|
||||||
labelX = label.x + (label.width ?? 0) / 2;
|
|
||||||
labelY = label.y + (label.height ?? 0) / 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
// Position nodes along a vertical spine, centered horizontally
|
||||||
id: key,
|
const centerX = ROLE_NODE_WIDTH / 2; // left edge at x=0, center at width/2
|
||||||
source: e.from,
|
const nodePositions = new Map<string, { x: number; y: number; w: number; h: number }>();
|
||||||
target: e.to,
|
|
||||||
type: "condition",
|
|
||||||
data: {
|
|
||||||
condition: e.condition,
|
|
||||||
conditionDescription: e.conditionDescription,
|
|
||||||
isFallback,
|
|
||||||
elkLabelX: labelX,
|
|
||||||
elkLabelY: labelY,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const elk = new ELK();
|
let y = 0;
|
||||||
|
for (const id of spine) {
|
||||||
async function computeLayout(input: LayoutInput): Promise<LayoutResult> {
|
|
||||||
const ids = collectNodeIds(input.edges);
|
|
||||||
|
|
||||||
const elkNodes: ElkNode[] = [];
|
|
||||||
for (const id of ids) {
|
|
||||||
const size = nodeSize(id);
|
const size = nodeSize(id);
|
||||||
elkNodes.push({ id, width: size.width, height: size.height });
|
// Center-align all nodes on the spine
|
||||||
}
|
const x = centerX - size.width / 2;
|
||||||
|
nodePositions.set(id, { x, y, w: size.width, h: size.height });
|
||||||
const elkEdges: ElkExtendedEdge[] = input.edges
|
y += size.height + LAYER_GAP;
|
||||||
.filter((e) => e.from !== e.to)
|
|
||||||
.map((e) => ({
|
|
||||||
id: edgeKey(e),
|
|
||||||
sources: [e.from],
|
|
||||||
targets: [e.to],
|
|
||||||
labels: e.condition !== ""
|
|
||||||
? [{ text: e.condition, width: Math.max(e.condition.length * 7 + 16, 60), height: 22 }]
|
|
||||||
: [],
|
|
||||||
}));
|
|
||||||
|
|
||||||
const graph: ElkNode = {
|
|
||||||
id: "root",
|
|
||||||
layoutOptions: {
|
|
||||||
"elk.algorithm": "layered",
|
|
||||||
"elk.direction": "DOWN",
|
|
||||||
// Node spacing
|
|
||||||
"elk.spacing.nodeNode": "30",
|
|
||||||
"elk.layered.spacing.nodeNodeBetweenLayers": "50",
|
|
||||||
// Edge spacing — keep edges apart from each other and from nodes
|
|
||||||
"elk.spacing.edgeNode": "25",
|
|
||||||
"elk.spacing.edgeEdge": "15",
|
|
||||||
"elk.layered.spacing.edgeNodeBetweenLayers": "25",
|
|
||||||
"elk.layered.spacing.edgeEdgeBetweenLayers": "15",
|
|
||||||
// Edge routing
|
|
||||||
"elk.edgeRouting": "ORTHOGONAL",
|
|
||||||
"elk.layered.mergeEdges": "false",
|
|
||||||
// Node placement
|
|
||||||
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
|
|
||||||
// Edge label placement
|
|
||||||
"elk.edgeLabels.placement": "CENTER",
|
|
||||||
// Crossing minimization
|
|
||||||
"elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
|
|
||||||
// Compaction
|
|
||||||
"elk.layered.compaction.postCompaction.strategy": "EDGE_LENGTH",
|
|
||||||
// Cycle breaking — keep main flow top-to-bottom
|
|
||||||
"elk.layered.cycleBreaking.strategy": "DEPTH_FIRST",
|
|
||||||
},
|
|
||||||
children: elkNodes,
|
|
||||||
edges: elkEdges,
|
|
||||||
};
|
|
||||||
|
|
||||||
const laid = await elk.layout(graph);
|
|
||||||
|
|
||||||
// Build map of ELK edge results for label positions
|
|
||||||
const elkEdgeMap = new Map<string, ElkExtendedEdge>();
|
|
||||||
for (const e of laid.edges ?? []) {
|
|
||||||
elkEdgeMap.set(e.id, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build nodes
|
||||||
const nodes: Node[] = [];
|
const nodes: Node[] = [];
|
||||||
for (const child of laid.children ?? []) {
|
for (const id of spine) {
|
||||||
const pos = { x: child.x ?? 0, y: child.y ?? 0 };
|
const pos = nodePositions.get(id);
|
||||||
const state = input.nodeStates.get(child.id) ?? "default";
|
if (pos === undefined) continue;
|
||||||
if (child.id === START_ID || child.id === END_ID) {
|
const state = input.nodeStates.get(id) ?? "default";
|
||||||
nodes.push(buildTerminalNode(child.id, pos, state));
|
if (id === START_ID || id === END_ID) {
|
||||||
|
nodes.push(buildTerminalNode(id, { x: pos.x, y: pos.y }, state));
|
||||||
} else {
|
} else {
|
||||||
nodes.push(buildRoleNode(child.id, pos, input.roles, state));
|
nodes.push(buildRoleNode(id, { x: pos.x, y: pos.y }, input.roles, state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const edges: Edge[] = input.edges.map((e) => buildEdge(e, elkEdgeMap));
|
// Build edges with label positions
|
||||||
|
// For feedback edges (target rank < source rank), we'll compute label at midpoint
|
||||||
|
// of the right-side arc. The actual SVG path is drawn by ConditionEdge component.
|
||||||
|
const edges: Edge[] = input.edges.map((e) => {
|
||||||
|
const isFallback = e.condition === "FALLBACK";
|
||||||
|
const isSelfLoop = e.from === e.to;
|
||||||
|
const sourceRank = rank.get(e.from) ?? 0;
|
||||||
|
const targetRank = rank.get(e.to) ?? 0;
|
||||||
|
const isFeedback = !isSelfLoop && targetRank <= sourceRank;
|
||||||
|
|
||||||
|
const sourcePos = nodePositions.get(e.from);
|
||||||
|
const targetPos = nodePositions.get(e.to);
|
||||||
|
|
||||||
|
let labelX: number | null = null;
|
||||||
|
let labelY: number | null = null;
|
||||||
|
|
||||||
|
if (sourcePos !== undefined && targetPos !== undefined) {
|
||||||
|
if (isFeedback) {
|
||||||
|
// Label on the right side of the feedback arc
|
||||||
|
const rightX = centerX + ROLE_NODE_WIDTH / 2 + FEEDBACK_OFFSET_X;
|
||||||
|
const midY = (sourcePos.y + sourcePos.h / 2 + targetPos.y + targetPos.h / 2) / 2;
|
||||||
|
labelX = rightX;
|
||||||
|
labelY = midY;
|
||||||
|
} else if (!isSelfLoop) {
|
||||||
|
// Forward edge: label between source bottom and target top
|
||||||
|
const midX = centerX;
|
||||||
|
const midY = (sourcePos.y + sourcePos.h + targetPos.y) / 2;
|
||||||
|
labelX = midX;
|
||||||
|
labelY = midY;
|
||||||
|
}
|
||||||
|
// Self-loop: let ReactFlow default handle it
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: edgeKey(e),
|
||||||
|
source: e.from,
|
||||||
|
target: e.to,
|
||||||
|
type: "condition",
|
||||||
|
data: {
|
||||||
|
condition: e.condition,
|
||||||
|
conditionDescription: e.conditionDescription,
|
||||||
|
isFallback,
|
||||||
|
isFeedback,
|
||||||
|
isSelfLoop,
|
||||||
|
labelX,
|
||||||
|
labelY,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return { nodes, edges };
|
return { nodes, edges };
|
||||||
}
|
}
|
||||||
|
|
||||||
const EMPTY_LAYOUT: LayoutResult = { nodes: [], edges: [] };
|
|
||||||
|
|
||||||
export function useLayout(input: LayoutInput): LayoutResult {
|
export function useLayout(input: LayoutInput): LayoutResult {
|
||||||
const [layout, setLayout] = useState<LayoutResult>(EMPTY_LAYOUT);
|
return useMemo(
|
||||||
|
() => computeLayout(input),
|
||||||
const edgeJson = JSON.stringify(input.edges);
|
[input.edges, input.roles, input.nodeStates],
|
||||||
const roleJson = JSON.stringify(input.roles);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let cancelled = false;
|
|
||||||
const parsed = {
|
|
||||||
edges: JSON.parse(edgeJson) as readonly WorkflowGraphEdge[],
|
|
||||||
roles: JSON.parse(roleJson) as Record<string, { description: string }>,
|
|
||||||
nodeStates: input.nodeStates,
|
|
||||||
};
|
|
||||||
computeLayout(parsed)
|
|
||||||
.then((result) => {
|
|
||||||
if (!cancelled) setLayout(result);
|
|
||||||
})
|
|
||||||
.catch((err: unknown) => {
|
|
||||||
if (!cancelled) {
|
|
||||||
// biome-ignore lint/suspicious/noConsole: layout error reporting
|
|
||||||
console.error("ELK layout failed:", err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}, [edgeJson, roleJson, input.nodeStates]);
|
|
||||||
|
|
||||||
return layout;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ import {
|
|||||||
type NodeTypes,
|
type NodeTypes,
|
||||||
type OnNodeClick,
|
type OnNodeClick,
|
||||||
ReactFlow,
|
ReactFlow,
|
||||||
ReactFlowProvider,
|
|
||||||
useReactFlow,
|
|
||||||
} from "@xyflow/react";
|
} from "@xyflow/react";
|
||||||
import "@xyflow/react/dist/style.css";
|
import "@xyflow/react/dist/style.css";
|
||||||
import { useEffect, useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import type { WorkflowGraph as WorkflowGraphData } from "../../api.ts";
|
import type { WorkflowGraph as WorkflowGraphData } from "../../api.ts";
|
||||||
import { ConditionEdge } from "./condition-edge.tsx";
|
import { ConditionEdge } from "./condition-edge.tsx";
|
||||||
import { RoleNode } from "./role-node.tsx";
|
import { RoleNode } from "./role-node.tsx";
|
||||||
@@ -39,30 +37,12 @@ function handleRoleNodeClick(onRoleClick: (roleName: string) => void, node: Node
|
|||||||
onRoleClick(node.id);
|
onRoleClick(node.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function WorkflowGraphInner({ graph, roles, nodeStates, onNodeClick }: Props) {
|
export function WorkflowGraph({ graph, roles, nodeStates, onNodeClick }: Props) {
|
||||||
const layout = useLayout({ edges: graph.edges, roles, nodeStates });
|
const layout = useLayout({ edges: graph.edges, roles, nodeStates });
|
||||||
const { fitView } = useReactFlow();
|
|
||||||
|
|
||||||
const onNodeClickHandler: OnNodeClick | undefined =
|
const onNodeClickHandler: OnNodeClick | undefined =
|
||||||
onNodeClick !== null ? (_e, node) => handleRoleNodeClick(onNodeClick, node) : undefined;
|
onNodeClick !== null ? (_e, node) => handleRoleNodeClick(onNodeClick, node) : undefined;
|
||||||
|
|
||||||
// Re-fit when layout changes (ELK is async)
|
|
||||||
// Use requestAnimationFrame + setTimeout to ensure ReactFlow has processed nodes
|
|
||||||
useEffect(() => {
|
|
||||||
if (layout.nodes.length > 0) {
|
|
||||||
let cancelled = false;
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
if (cancelled) return;
|
|
||||||
setTimeout(() => {
|
|
||||||
if (!cancelled) fitView({ padding: 0.1, duration: 300 });
|
|
||||||
}, 300);
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [layout.nodes, layout.edges, fitView]);
|
|
||||||
|
|
||||||
const styledEdges = useMemo(
|
const styledEdges = useMemo(
|
||||||
() =>
|
() =>
|
||||||
layout.edges.map((e) => ({
|
layout.edges.map((e) => ({
|
||||||
@@ -77,25 +57,17 @@ function WorkflowGraphInner({ graph, roles, nodeStates, onNodeClick }: Props) {
|
|||||||
[layout.edges],
|
[layout.edges],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Generate a stable key that changes when layout changes, to force ReactFlow remount + fitView
|
|
||||||
const layoutKey = useMemo(
|
|
||||||
() => layout.nodes.map((n) => `${n.id}:${n.position.x}:${n.position.y}`).join(","),
|
|
||||||
[layout.nodes],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
key={layoutKey}
|
|
||||||
nodes={layout.nodes}
|
nodes={layout.nodes}
|
||||||
edges={styledEdges}
|
edges={styledEdges}
|
||||||
nodeTypes={nodeTypes}
|
nodeTypes={nodeTypes}
|
||||||
edgeTypes={edgeTypes}
|
edgeTypes={edgeTypes}
|
||||||
onNodeClick={onNodeClickHandler}
|
onNodeClick={onNodeClickHandler}
|
||||||
fitView
|
fitView
|
||||||
fitViewOptions={{ padding: 0.1, minZoom: 0.1, maxZoom: 1.5 }}
|
fitViewOptions={{ padding: 0.15 }}
|
||||||
minZoom={0.1}
|
minZoom={0.3}
|
||||||
maxZoom={1.5}
|
maxZoom={2}
|
||||||
defaultViewport={{ x: 0, y: 0, zoom: 0.5 }}
|
|
||||||
nodesDraggable={false}
|
nodesDraggable={false}
|
||||||
nodesConnectable={false}
|
nodesConnectable={false}
|
||||||
elementsSelectable={false}
|
elementsSelectable={false}
|
||||||
@@ -107,11 +79,3 @@ function WorkflowGraphInner({ graph, roles, nodeStates, onNodeClick }: Props) {
|
|||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WorkflowGraph(props: Props) {
|
|
||||||
return (
|
|
||||||
<ReactFlowProvider>
|
|
||||||
<WorkflowGraphInner {...props} />
|
|
||||||
</ReactFlowProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# @uncaged/workflow-execute
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-cas@0.4.0
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
|
- @uncaged/workflow-reactor@0.4.0
|
||||||
|
- @uncaged/workflow-register@0.4.0
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
|
- @uncaged/workflow-util@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-execute",
|
"name": "@uncaged/workflow-execute",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# @uncaged/workflow-gateway
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-gateway",
|
"name": "@uncaged/workflow-gateway",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# @uncaged/workflow-protocol
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-protocol",
|
"name": "@uncaged/workflow-protocol",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -8,12 +8,14 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"./moderator-table.js": {
|
"./moderator-table.js": {
|
||||||
|
"bun": "./src/moderator-table.ts",
|
||||||
"types": "./dist/moderator-table.d.ts",
|
"types": "./dist/moderator-table.d.ts",
|
||||||
"import": "./src/moderator-table.ts"
|
"import": "./dist/moderator-table.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# @uncaged/workflow-reactor
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-reactor",
|
"name": "@uncaged/workflow-reactor",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-register
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
|
- @uncaged/workflow-util@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-register",
|
"name": "@uncaged/workflow-register",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-runtime
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-cas@0.4.0
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-runtime",
|
"name": "@uncaged/workflow-runtime",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
"types": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun test"
|
"test": "bun test"
|
||||||
@@ -23,8 +22,9 @@
|
|||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-template-develop
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-register@0.4.0
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-template-develop",
|
"name": "@uncaged/workflow-template-develop",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-template-solve-issue
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-register@0.4.0
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-template-solve-issue",
|
"name": "@uncaged/workflow-template-solve-issue",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# @uncaged/workflow-util-agent
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-cas@0.4.0
|
||||||
|
- @uncaged/workflow-runtime@0.4.0
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-util-agent",
|
"name": "@uncaged/workflow-util-agent",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
"types": "src/index.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./src/index.ts",
|
"bun": "./src/index.ts",
|
||||||
"default": "./src/index.ts"
|
"types": "./dist/index.d.ts",
|
||||||
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# @uncaged/workflow-util
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- Fix package exports for published packages and adopt changesets for version management.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @uncaged/workflow-protocol@0.4.0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@uncaged/workflow-util",
|
"name": "@uncaged/workflow-util",
|
||||||
"version": "0.3.18",
|
"version": "0.4.0",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"package.json"
|
"package.json"
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"bun": "./src/index.ts",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./src/index.ts"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Link / unlink all @uncaged/* packages from the workflow monorepo.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# ./scripts/link-all.sh # Register all packages (run from monorepo root)
|
|
||||||
# ./scripts/link-all.sh --consume # Link all packages into CWD's project
|
|
||||||
# ./scripts/link-all.sh --unlink # Unregister all packages and restore CWD's deps
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
||||||
MONOREPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
||||||
|
|
||||||
# Iterate package dirs, calling callback(dir, name) for each
|
|
||||||
each_pkg() {
|
|
||||||
local cb="$1"
|
|
||||||
for dir in "$MONOREPO_ROOT"/packages/*/; do
|
|
||||||
[[ -f "$dir/package.json" ]] || continue
|
|
||||||
local name
|
|
||||||
name=$(grep -m1 '"name"' "$dir/package.json" | sed 's/.*: *"\(.*\)".*/\1/')
|
|
||||||
"$cb" "$dir" "$name"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
do_register() { printf " register %s\n" "$2"; (cd "$1" && bun link 2>&1) > /dev/null; }
|
|
||||||
do_consume() { printf " link %s\n" "$2"; (bun link "$2" 2>&1) > /dev/null; }
|
|
||||||
do_unlink() { printf " unlink %s\n" "$2"; (cd "$1" && bun unlink 2>&1) > /dev/null || true; }
|
|
||||||
|
|
||||||
case "${1:-}" in
|
|
||||||
--consume)
|
|
||||||
each_pkg do_consume
|
|
||||||
echo "✅ All @uncaged/* packages linked into $(pwd)"
|
|
||||||
echo " ⚠️ Do NOT run 'bun install' after this — it will overwrite the links"
|
|
||||||
echo " To restore: $0 --unlink"
|
|
||||||
;;
|
|
||||||
--unlink)
|
|
||||||
each_pkg do_unlink
|
|
||||||
if [[ -f "package.json" ]]; then
|
|
||||||
echo " reinstalling deps..."
|
|
||||||
bun install 2>&1 > /dev/null || true
|
|
||||||
fi
|
|
||||||
echo "✅ All @uncaged/* packages unlinked, deps restored"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
each_pkg do_register
|
|
||||||
echo "✅ All @uncaged/* packages registered"
|
|
||||||
echo " cd <project> && $0 --consume"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Publish all public @uncaged/* packages to Gitea npm registry.
|
|
||||||
#
|
|
||||||
# PITFALL: After bumping versions in package.json, bun pm pack still reads the
|
|
||||||
# old bun.lock and resolves workspace:* to the previous (stale) versions.
|
|
||||||
# This script deletes bun.lock and runs bun install before packing to force
|
|
||||||
# correct resolution of workspace:* dependencies.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# ./scripts/publish-all.sh # Publish all packages
|
|
||||||
# ./scripts/publish-all.sh --dry-run # Show what would be published
|
|
||||||
#
|
|
||||||
# Package order is auto-resolved via topological sort of workspace:* dependencies.
|
|
||||||
#
|
|
||||||
# Prerequisites:
|
|
||||||
# - .npmrc in monorepo root with Gitea auth token
|
|
||||||
# - bun (for packing with workspace:* resolution)
|
|
||||||
# - npm (for publishing tarballs)
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
||||||
MONOREPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
||||||
|
|
||||||
REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/"
|
|
||||||
DRY_RUN=""
|
|
||||||
|
|
||||||
if [[ "${1:-}" == "--dry-run" ]]; then
|
|
||||||
DRY_RUN="--dry-run"
|
|
||||||
echo "🔍 Dry run mode — no packages will be published"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Topological sort: read all package.json files, build dependency graph, emit leaf-first order
|
|
||||||
ORDERED=$(python3 -c "
|
|
||||||
import json, os, sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
pkgs_dir = Path('$MONOREPO_ROOT/packages')
|
|
||||||
# name -> dir_name, and dependency edges
|
|
||||||
name_to_dir = {}
|
|
||||||
deps_graph = {} # name -> set of @uncaged/* dependency names
|
|
||||||
|
|
||||||
for d in sorted(pkgs_dir.iterdir()):
|
|
||||||
pj = d / 'package.json'
|
|
||||||
if not pj.exists():
|
|
||||||
continue
|
|
||||||
data = json.loads(pj.read_text())
|
|
||||||
name = data.get('name', '')
|
|
||||||
if not name.startswith('@uncaged/'):
|
|
||||||
continue
|
|
||||||
if data.get('private'):
|
|
||||||
continue
|
|
||||||
name_to_dir[name] = d.name
|
|
||||||
local_deps = set()
|
|
||||||
for section in ('dependencies', 'devDependencies', 'peerDependencies'):
|
|
||||||
for dep, ver in data.get(section, {}).items():
|
|
||||||
if dep.startswith('@uncaged/') and dep in name_to_dir or ver == 'workspace:*':
|
|
||||||
local_deps.add(dep)
|
|
||||||
deps_graph[name] = local_deps
|
|
||||||
|
|
||||||
# Kahn's algorithm
|
|
||||||
in_degree = {n: 0 for n in deps_graph}
|
|
||||||
for n, ds in deps_graph.items():
|
|
||||||
for d in ds:
|
|
||||||
if d in in_degree:
|
|
||||||
in_degree[d] = in_degree.get(d, 0) # ensure exists
|
|
||||||
|
|
||||||
# Recount
|
|
||||||
in_degree = {n: 0 for n in deps_graph}
|
|
||||||
for n, ds in deps_graph.items():
|
|
||||||
for d in ds:
|
|
||||||
if d in in_degree:
|
|
||||||
in_degree[d] += 1
|
|
||||||
|
|
||||||
# Wait, direction is wrong. If A depends on B, B must be published first.
|
|
||||||
# So edge is: A -> B means B must come before A.
|
|
||||||
# in_degree[A] = number of deps A has (that are in our set)
|
|
||||||
in_degree = {n: 0 for n in deps_graph}
|
|
||||||
for n, ds in deps_graph.items():
|
|
||||||
for d in ds:
|
|
||||||
if d in in_degree:
|
|
||||||
pass # d is a dependency of n
|
|
||||||
in_degree[n] = len([d for d in ds if d in deps_graph])
|
|
||||||
|
|
||||||
queue = [n for n, deg in in_degree.items() if deg == 0]
|
|
||||||
queue.sort() # stable order
|
|
||||||
result = []
|
|
||||||
while queue:
|
|
||||||
node = queue.pop(0)
|
|
||||||
result.append(node)
|
|
||||||
for n, ds in deps_graph.items():
|
|
||||||
if node in ds:
|
|
||||||
in_degree[n] -= 1
|
|
||||||
if in_degree[n] == 0:
|
|
||||||
queue.append(n)
|
|
||||||
queue.sort()
|
|
||||||
|
|
||||||
for name in result:
|
|
||||||
print(name_to_dir[name])
|
|
||||||
")
|
|
||||||
|
|
||||||
# Regenerate lockfile so bun pm pack resolves workspace:* to freshly-bumped versions
|
|
||||||
cd "$MONOREPO_ROOT"
|
|
||||||
rm -f bun.lock
|
|
||||||
bun install
|
|
||||||
|
|
||||||
ok=0
|
|
||||||
fail=0
|
|
||||||
|
|
||||||
while IFS= read -r pkg; do
|
|
||||||
dir="$MONOREPO_ROOT/packages/$pkg"
|
|
||||||
name=$(grep -m1 '"name"' "$dir/package.json" | sed 's/.*: *"\(.*\)".*/\1/')
|
|
||||||
|
|
||||||
cd "$dir"
|
|
||||||
|
|
||||||
# bun pm pack resolves workspace:* → actual versions
|
|
||||||
tgz=$(bun pm pack 2>&1 | grep '\.tgz' | grep -v packed | head -1 | tr -d ' ')
|
|
||||||
|
|
||||||
if [[ -z "$tgz" || ! -f "$tgz" ]]; then
|
|
||||||
echo "❌ $name — pack failed"
|
|
||||||
((fail++)) || true
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if npm publish "$tgz" --registry="$REGISTRY" $DRY_RUN 2>&1 | tail -1 | grep -q '+'; then
|
|
||||||
echo "✅ $name"
|
|
||||||
((ok++)) || true
|
|
||||||
else
|
|
||||||
echo "⚠️ $name (may already exist at this version)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f "$tgz"
|
|
||||||
done <<< "$ORDERED"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Published: $ok Skipped/Failed: $fail"
|
|
||||||
+105
-79
@@ -1,20 +1,31 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# publish.sh — Bump version & publish all @uncaged/workflow-* packages
|
# publish.sh — Bump version, build, test, topologically publish @uncaged/* to Gitea npm
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./scripts/publish.sh 0.4.0 # explicit version
|
# ./scripts/publish.sh 0.4.0 # explicit version
|
||||||
# ./scripts/publish.sh patch # 0.3.1 → 0.3.2
|
# ./scripts/publish.sh patch # 0.3.1 → 0.3.2
|
||||||
# ./scripts/publish.sh minor # 0.3.1 → 0.4.0
|
# ./scripts/publish.sh minor # 0.3.1 → 0.4.0
|
||||||
|
# ./scripts/publish.sh major # 0.3.1 → 1.0.0
|
||||||
|
# ./scripts/publish.sh --dry-run patch # dry-run bun publish only (no git commit/push)
|
||||||
#
|
#
|
||||||
# Env (via `cfg` or export):
|
# Env (via `cfg` or export):
|
||||||
# GITEA_TOKEN — Gitea npm registry auth
|
# GITEA_TOKEN — Gitea npm registry auth (see root .npmrc)
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
cd "$REPO_ROOT"
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
GITEA_TOKEN="${GITEA_TOKEN:?GITEA_TOKEN is required}"
|
GITEA_TOKEN="${GITEA_TOKEN:?GITEA_TOKEN is required}"
|
||||||
GITEA_NPM_REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/"
|
|
||||||
|
REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/"
|
||||||
|
DRY_RUN=""
|
||||||
|
|
||||||
|
if [[ "${1:-}" == "--dry-run" ]]; then
|
||||||
|
DRY_RUN="--dry-run"
|
||||||
|
shift
|
||||||
|
echo "🔍 Dry run — bun publish will not upload; git commit/push skipped"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
# ─── Version ─────────────────────────────────────────────────────────────────
|
# ─── Version ─────────────────────────────────────────────────────────────────
|
||||||
current_version() {
|
current_version() {
|
||||||
@@ -33,28 +44,10 @@ bump_version() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CURRENT=$(current_version)
|
CURRENT=$(current_version)
|
||||||
VERSION=$(bump_version "$CURRENT" "${1:?Usage: publish.sh <version|patch|minor|major>}")
|
VERSION=$(bump_version "$CURRENT" "${1:?Usage: publish.sh [--dry-run] <version|patch|minor|major>}")
|
||||||
echo "📦 Publish: $CURRENT → $VERSION"
|
echo "📦 Publish: $CURRENT → $VERSION"
|
||||||
|
|
||||||
# ─── Topological publish order ───────────────────────────────────────────────
|
# ─── Bump version ─────────────────────────────────────────────────────────────
|
||||||
PUBLISH_ORDER=(
|
|
||||||
workflow-protocol
|
|
||||||
workflow-util
|
|
||||||
workflow-cas
|
|
||||||
workflow-runtime
|
|
||||||
workflow-reactor
|
|
||||||
workflow-register
|
|
||||||
workflow-execute
|
|
||||||
cli-workflow
|
|
||||||
workflow-util-agent
|
|
||||||
workflow-agent-cursor
|
|
||||||
workflow-agent-hermes
|
|
||||||
workflow-agent-llm
|
|
||||||
workflow-template-develop
|
|
||||||
workflow-template-solve-issue
|
|
||||||
)
|
|
||||||
|
|
||||||
# ─── Bump version ────────────────────────────────────────────────────────────
|
|
||||||
echo "🔢 Bumping versions..."
|
echo "🔢 Bumping versions..."
|
||||||
for dir in packages/*/; do
|
for dir in packages/*/; do
|
||||||
pkg="$dir/package.json"
|
pkg="$dir/package.json"
|
||||||
@@ -69,66 +62,99 @@ for dir in packages/*/; do
|
|||||||
"
|
"
|
||||||
done
|
done
|
||||||
|
|
||||||
# ─── Replace workspace:* ─────────────────────────────────────────────────────
|
# ─── Topological publish order (workspace:* deps first) ───────────────────────
|
||||||
echo "🔗 Replacing workspace:* → $VERSION..."
|
ORDERED=$(python3 -c "
|
||||||
for dir in packages/*/; do
|
import json, sys
|
||||||
pkg="$dir/package.json"
|
from pathlib import Path
|
||||||
[[ -f "$pkg" ]] || continue
|
|
||||||
node -e "
|
|
||||||
const fs = require('fs');
|
|
||||||
const p = JSON.parse(fs.readFileSync('$pkg','utf8'));
|
|
||||||
let c = false;
|
|
||||||
for (const k of ['dependencies','peerDependencies','devDependencies']) {
|
|
||||||
if (!p[k]) continue;
|
|
||||||
for (const [n, v] of Object.entries(p[k])) {
|
|
||||||
if (n.startsWith('@uncaged/') && v === 'workspace:*') { p[k][n] = '$VERSION'; c = true; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (c) fs.writeFileSync('$pkg', JSON.stringify(p, null, 2) + '\n');
|
|
||||||
"
|
|
||||||
done
|
|
||||||
|
|
||||||
# ─── Build ───────────────────────────────────────────────────────────────────
|
pkgs_dir = Path('$REPO_ROOT/packages')
|
||||||
|
name_to_dir = {}
|
||||||
|
for d in sorted(pkgs_dir.iterdir()):
|
||||||
|
pj = d / 'package.json'
|
||||||
|
if not pj.exists():
|
||||||
|
continue
|
||||||
|
data = json.loads(pj.read_text())
|
||||||
|
name = data.get('name', '')
|
||||||
|
if not name.startswith('@uncaged/') or data.get('private'):
|
||||||
|
continue
|
||||||
|
name_to_dir[name] = d.name
|
||||||
|
|
||||||
|
deps_graph = {}
|
||||||
|
for name, dirname in name_to_dir.items():
|
||||||
|
pj = pkgs_dir / dirname / 'package.json'
|
||||||
|
data = json.loads(pj.read_text())
|
||||||
|
local_deps = set()
|
||||||
|
for section in ('dependencies', 'devDependencies', 'peerDependencies'):
|
||||||
|
for dep, ver in data.get(section, {}).items():
|
||||||
|
if dep.startswith('@uncaged/') and dep in name_to_dir and ver.startswith('workspace:'):
|
||||||
|
local_deps.add(dep)
|
||||||
|
deps_graph[name] = local_deps
|
||||||
|
|
||||||
|
in_degree = {n: 0 for n in deps_graph}
|
||||||
|
for n, ds in deps_graph.items():
|
||||||
|
in_degree[n] = len(ds)
|
||||||
|
|
||||||
|
queue = sorted([n for n, deg in in_degree.items() if deg == 0])
|
||||||
|
result = []
|
||||||
|
while queue:
|
||||||
|
node = queue.pop(0)
|
||||||
|
result.append(node)
|
||||||
|
for n, ds in deps_graph.items():
|
||||||
|
if node in ds:
|
||||||
|
in_degree[n] -= 1
|
||||||
|
if in_degree[n] == 0:
|
||||||
|
queue.append(n)
|
||||||
|
queue.sort()
|
||||||
|
|
||||||
|
if len(result) != len(deps_graph):
|
||||||
|
missing = set(deps_graph) - set(result)
|
||||||
|
sys.stderr.write('publish: cyclic @uncaged/ workspace:* dependencies among: ' + ', '.join(sorted(missing)) + '\n')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for name in result:
|
||||||
|
print(name_to_dir[name])
|
||||||
|
")
|
||||||
|
|
||||||
|
# ─── Build ────────────────────────────────────────────────────────────────────
|
||||||
echo "🔨 Building..."
|
echo "🔨 Building..."
|
||||||
npm run build
|
bun run build
|
||||||
|
|
||||||
# ─── Publish ─────────────────────────────────────────────────────────────────
|
# ─── Self-test ────────────────────────────────────────────────────────────────
|
||||||
echo "🚀 Publishing..."
|
echo "🧪 Running tests..."
|
||||||
cat > "$REPO_ROOT/.npmrc" <<EOF
|
if ! bun test; then
|
||||||
@uncaged:registry=${GITEA_NPM_REGISTRY}
|
echo "❌ Tests failed — aborting publish"
|
||||||
//${GITEA_NPM_REGISTRY#https://}:_authToken=${GITEA_TOKEN}
|
exit 1
|
||||||
EOF
|
fi
|
||||||
|
|
||||||
FAIL=0
|
# ─── Publish (bun resolves workspace:* for publish) ──────────────────────────
|
||||||
for pkg_dir in "${PUBLISH_ORDER[@]}"; do
|
echo "🚀 Publishing to $REGISTRY ..."
|
||||||
if (cd "packages/$pkg_dir" && npm publish 2>&1); then
|
ok=0
|
||||||
echo " ✅ @uncaged/$pkg_dir@$VERSION"
|
fail=0
|
||||||
|
|
||||||
|
while IFS= read -r pkg; do
|
||||||
|
[[ -n "$pkg" ]] || continue
|
||||||
|
dir="$REPO_ROOT/packages/$pkg"
|
||||||
|
name=$(node -e "console.log(require('$dir/package.json').name)")
|
||||||
|
|
||||||
|
if ( cd "$dir" && bun publish --registry="$REGISTRY" ${DRY_RUN:+"$DRY_RUN"} ); then
|
||||||
|
echo "✅ $name"
|
||||||
|
ok=$((ok + 1))
|
||||||
else
|
else
|
||||||
echo " ❌ @uncaged/$pkg_dir"
|
echo "⚠️ $name (publish failed or version may already exist)"
|
||||||
FAIL=1
|
fail=$((fail + 1))
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
# ─── Restore workspace:* ─────────────────────────────────────────────────────
|
done <<< "$ORDERED"
|
||||||
echo "🔄 Restoring workspace:*..."
|
|
||||||
for dir in packages/*/; do
|
echo
|
||||||
pkg="$dir/package.json"
|
echo "Published: $ok Skipped/Failed: $fail"
|
||||||
[[ -f "$pkg" ]] || continue
|
|
||||||
node -e "
|
# ─── Commit ───────────────────────────────────────────────────────────────────
|
||||||
const fs = require('fs');
|
if [[ -n "$DRY_RUN" ]]; then
|
||||||
const p = JSON.parse(fs.readFileSync('$pkg','utf8'));
|
echo "⏭️ Skipping git commit/push (dry run). Revert bumps with: git checkout -- packages/*/package.json"
|
||||||
let c = false;
|
exit 0
|
||||||
for (const k of ['dependencies','peerDependencies','devDependencies']) {
|
fi
|
||||||
if (!p[k]) continue;
|
|
||||||
for (const [n, v] of Object.entries(p[k])) {
|
|
||||||
if (n.startsWith('@uncaged/') && v === '$VERSION') { p[k][n] = 'workspace:*'; c = true; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (c) fs.writeFileSync('$pkg', JSON.stringify(p, null, 2) + '\n');
|
|
||||||
"
|
|
||||||
done
|
|
||||||
|
|
||||||
# ─── Commit ──────────────────────────────────────────────────────────────────
|
|
||||||
echo "📝 Committing..."
|
echo "📝 Committing..."
|
||||||
git add -A
|
git add -A
|
||||||
git commit -m "chore: publish v${VERSION}
|
git commit -m "chore: publish v${VERSION}
|
||||||
@@ -136,4 +162,4 @@ git commit -m "chore: publish v${VERSION}
|
|||||||
小橘 <xiaoju@shazhou.work>"
|
小橘 <xiaoju@shazhou.work>"
|
||||||
git push
|
git push
|
||||||
|
|
||||||
[[ "$FAIL" -eq 0 ]] && echo "✅ v${VERSION} published" || echo "⚠️ v${VERSION} published with errors"
|
echo "✅ v${VERSION} published"
|
||||||
|
|||||||
Reference in New Issue
Block a user