Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

refactor(workflows): satisfy session graph release gates

Rahman5a6392064dc8
diff --git a/frontend/slices/workflows/app.tsx b/frontend/slices/workflows/app.tsx
index 69223c88..a28cef4f 100644
--- a/frontend/slices/workflows/app.tsx
+++ b/frontend/slices/workflows/app.tsx
@@ -50,8 +50,7 @@ export default function WorkflowsApp(props: AppProps) {
const id = payloadSessionId(props.payload);
if (!id) return;
let alive = true;
- setLibraryMode("sessions"); setMessage("");
- void getSessionGraph(id).then((next) => { if (!alive) return; setSessionView(next); setSessionSelected("session-root"); }).catch((error: unknown) => { if (alive) setMessage(error instanceof Error ? error.message : "Could not load session"); });
+ void getSessionGraph(id).then((next) => { if (!alive) return; setLibraryMode("sessions"); setMessage(""); setSessionView(next); setSessionSelected("session-root"); }).catch((error: unknown) => { if (alive) setMessage(error instanceof Error ? error.message : "Could not load session"); });
return () => { alive = false; };
}, [props.payload]);
diff --git a/frontend/slices/workflows/components/workflow-session-details.tsx b/frontend/slices/workflows/components/workflow-session-details.tsx
index d1da5998..3bccf642 100644
--- a/frontend/slices/workflows/components/workflow-session-details.tsx
+++ b/frontend/slices/workflows/components/workflow-session-details.tsx
@@ -31,6 +31,6 @@ export function WorkflowSessionDetails({ view, node, onOpenTerminal }: { view: S
{terminalContext ? <Button className="w-full" variant="outline" onClick={onOpenTerminal}><TerminalSquare className="size-4"/>Open terminal here<ExternalLink className="ml-auto size-3.5"/></Button> : null}
</>}
</div></ScrollArea>
- <div className="border-t p-3 text-[10px] text-muted-foreground">Successful MCP/Alfa workflows continue through MSO's existing learned-from-session automation pipeline; this view does not duplicate that state.</div>
+ <div className="border-t p-3 text-[10px] text-muted-foreground">Successful MCP/Alfa workflows continue through MSO&apos;s existing learned-from-session automation pipeline; this view does not duplicate that state.</div>
</div>;
}
diff --git a/frontend/slices/workflows/components/workflow-session-library.tsx b/frontend/slices/workflows/components/workflow-session-library.tsx
index 972c8e11..4f23b891 100644
--- a/frontend/slices/workflows/components/workflow-session-library.tsx
+++ b/frontend/slices/workflows/components/workflow-session-library.tsx
@@ -13,8 +13,7 @@ export function WorkflowSessionLibrary({ activeId, onSelect }: { activeId?: stri
const [data, setData] = useState<SessionPage | null>(null), [error, setError] = useState(""), [nonce, setNonce] = useState(0);
useEffect(() => {
let alive = true;
- setError("");
- void listWorkflowSessions(page, query).then((value) => { if (alive) setData(value); }).catch((cause) => { if (alive) setError(cause instanceof Error ? cause.message : "Sessions unavailable"); });
+ void listWorkflowSessions(page, query).then((value) => { if (alive) { setError(""); setData(value); } }).catch((cause) => { if (alive) setError(cause instanceof Error ? cause.message : "Sessions unavailable"); });
return () => { alive = false; };
}, [page, query, nonce]);
return <div className="flex h-full min-h-0 flex-col bg-card/20">
diff --git a/lib/agent/session-graph.ts b/lib/agent/session-graph.ts
new file mode 100644
index 00000000..263033e4
--- /dev/null
+++ b/lib/agent/session-graph.ts
@@ -0,0 +1,112 @@
+import { SESSION_GRAPH_EVENT_LIMIT } from "@/lib/contracts/session-monitor";
+import type { SessionCard, SessionGraphView } from "@/lib/contracts/session-monitor";
+import type { WorkflowGraph, WorkflowGraphNode } from "@/lib/contracts/workflow-graph";
+import { redactText } from "@/lib/security/redact-text";
+import type { AgentSession, AgentSessionEvent } from "./session-types";
+
+function text(value: string | undefined, max = 500): string | undefined {
+ return value ? redactText(value, max).replace(/[\u0000-\u001f\u007f]/g, " ") : undefined;
+}
+
+function safeEvent(row: AgentSessionEvent) {
+ return {
+ at: row.at,
+ kind: text(row.kind, 40) || "note",
+ tool: text(row.tool, 100),
+ state: text(row.state, 60),
+ detail: text(row.detail, 1000),
+ workflowId: text(row.workflowId, 100),
+ };
+}
+
+function nodeName(event: ReturnType<typeof safeEvent>): string {
+ return (event.tool || event.kind || "event")
+ .replace(/[_.:-]+/g, " ")
+ .replace(/\b\w/g, (char) => char.toUpperCase())
+ .slice(0, 120);
+}
+
+function nodeType(event: ReturnType<typeof safeEvent>): WorkflowGraphNode["type"] {
+ if (event.kind === "workflow") return "subflow";
+ if (["note", "compacted", "archived"].includes(event.kind)) return "memory";
+ return "tool";
+}
+
+export function sessionGraph(
+ record: AgentSession,
+ session: SessionCard,
+ requestedLimit = SESSION_GRAPH_EVENT_LIMIT,
+): SessionGraphView {
+ const limit = Math.max(
+ 1,
+ Math.min(SESSION_GRAPH_EVENT_LIMIT, Math.trunc(requestedLimit) || SESSION_GRAPH_EVENT_LIMIT),
+ );
+ const totalEvents = record.events.length;
+ const omittedEvents = Math.max(0, totalEvents - limit);
+ const events = record.events.slice(-limit).map(safeEvent);
+ const root: WorkflowGraphNode = {
+ id: "session-root",
+ name: session.label,
+ type: "session",
+ position: { x: 70, y: 100 },
+ config: {
+ label: session.label,
+ source: session.source,
+ status: session.status,
+ title: session.title,
+ ...(session.cwd ? { cwd: session.cwd } : {}),
+ },
+ };
+ const eventNodes: WorkflowGraphNode[] = events.map((event, index) => {
+ const row = Math.floor(index / 4);
+ const column = index % 4;
+ const displayColumn = row % 2 === 0 ? column : 3 - column;
+ return {
+ id: `event-${omittedEvents + index + 1}`,
+ name: nodeName(event),
+ type: nodeType(event),
+ position: { x: 340 + displayColumn * 250, y: 70 + row * 140 },
+ config: {
+ at: event.at,
+ kind: event.kind,
+ ...(event.tool ? { tool: event.tool } : {}),
+ ...(event.state ? { state: event.state } : {}),
+ ...(event.detail ? { detail: event.detail } : {}),
+ terminalContext: Boolean(event.tool && /^(exec(?:_|\.)|terminal|shell)/i.test(event.tool)),
+ },
+ };
+ });
+ const nodes = [root, ...eventNodes];
+ const edges = eventNodes.map((node, index) => ({
+ id: `session-edge-${omittedEvents + index + 1}`,
+ source: index === 0 ? root.id : eventNodes[index - 1]!.id,
+ target: node.id,
+ }));
+ const graph: WorkflowGraph = {
+ version: 2,
+ id: `session:${record.id}`,
+ name: session.label,
+ description: session.title,
+ status: "archived",
+ inputs: {},
+ nodes,
+ edges,
+ metadata: {
+ provenance: "learned-from-session",
+ intent: session.title,
+ ...(session.cwd ? { project: session.cwd } : {}),
+ tags: ["session", session.source],
+ },
+ createdAt: record.createdAt,
+ updatedAt: record.updatedAt,
+ revision: `session-${Date.parse(record.updatedAt) || 0}`,
+ };
+ return {
+ session,
+ graph,
+ totalEvents,
+ shownEvents: events.length,
+ omittedEvents,
+ observedAt: new Date().toISOString(),
+ };
+}
diff --git a/lib/agent/session-monitor.ts b/lib/agent/session-monitor.ts
index bf6830a2..06133269 100644
--- a/lib/agent/session-monitor.ts
+++ b/lib/agent/session-monitor.ts
@@ -9,10 +9,6 @@ import type {
SessionGraphView,
SessionPage,
} from "@/lib/contracts/session-monitor";
-import type {
- WorkflowGraph,
- WorkflowGraphNode,
-} from "@/lib/contracts/workflow-graph";
import { redactText } from "@/lib/security/redact-text";
import {
listSessionRecords,
@@ -26,6 +22,7 @@ import {
import { localAgentConsumerConnected } from "./local-agent-events";
import { agentSessionLabel } from "./session-name";
import type { AgentSession, AgentSessionEvent } from "./session-types";
+import { sessionGraph } from "./session-graph";
import type { LocalAgentPresenceRecord } from "./local-agent-types";
function text(value: string | undefined, max = 500): string | undefined {
@@ -79,108 +76,6 @@ function safeEvent(row: AgentSessionEvent) {
workflowId: text(row.workflowId, 100),
};
}
-function nodeName(event: ReturnType<typeof safeEvent>): string {
- return (event.tool || event.kind || "event")
- .replace(/[_.:-]+/g, " ")
- .replace(/\b\w/g, (char) => char.toUpperCase())
- .slice(0, 120);
-}
-function nodeType(
- event: ReturnType<typeof safeEvent>,
-): WorkflowGraphNode["type"] {
- if (event.kind === "workflow") return "subflow";
- if (
- event.kind === "note" ||
- event.kind === "compacted" ||
- event.kind === "archived"
- )
- return "memory";
- return "tool";
-}
-function sessionGraph(
- record: AgentSession,
- session: SessionCard,
- requestedLimit: number,
-): SessionGraphView {
- const limit = Math.max(
- 1,
- Math.min(
- SESSION_GRAPH_EVENT_LIMIT,
- Math.trunc(requestedLimit) || SESSION_GRAPH_EVENT_LIMIT,
- ),
- );
- const totalEvents = record.events.length;
- const omittedEvents = Math.max(0, totalEvents - limit);
- const events = record.events.slice(-limit).map(safeEvent);
- const root: WorkflowGraphNode = {
- id: "session-root",
- name: session.label,
- type: "session",
- position: { x: 70, y: 100 },
- config: {
- label: session.label,
- source: session.source,
- status: session.status,
- title: session.title,
- ...(session.cwd ? { cwd: session.cwd } : {}),
- },
- };
- const eventNodes: WorkflowGraphNode[] = events.map((event, index) => {
- const row = Math.floor(index / 4),
- column = index % 4,
- displayColumn = row % 2 === 0 ? column : 3 - column;
- return {
- id: `event-${omittedEvents + index + 1}`,
- name: nodeName(event),
- type: nodeType(event),
- position: { x: 340 + displayColumn * 250, y: 70 + row * 140 },
- config: {
- at: event.at,
- kind: event.kind,
- ...(event.tool ? { tool: event.tool } : {}),
- ...(event.state ? { state: event.state } : {}),
- ...(event.detail ? { detail: event.detail } : {}),
- terminalContext: Boolean(
- event.tool && /^(exec(?:_|\.)|terminal|shell)/i.test(event.tool),
- ),
- },
- };
- });
- const nodes = [root, ...eventNodes];
- const edges = eventNodes.map((node, index) => ({
- id: `session-edge-${omittedEvents + index + 1}`,
- source: index === 0 ? root.id : eventNodes[index - 1]!.id,
- target: node.id,
- }));
- const graph: WorkflowGraph = {
- version: 2,
- id: `session:${record.id}`,
- name: session.label,
- description: session.title,
- status: "archived",
- inputs: {},
- nodes,
- edges,
- metadata: {
- provenance: "learned-from-session",
- intent: session.title,
- ...(session.cwd ? { project: session.cwd } : {}),
- tags: ["session", session.source],
- },
- createdAt: record.createdAt,
- updatedAt: record.updatedAt,
- revision: `session-${Date.parse(record.updatedAt) || 0}`,
- };
- return {
- session,
- graph,
- totalEvents,
- shownEvents: events.length,
- omittedEvents,
- observedAt: new Date().toISOString(),
- };
-}
-
/** Owner dashboard only. Model-facing directory remains strictly principal-scoped. */
export async function ownerSessionPage(
requested = 1,