Add a Python SDK: flows declared in your own repository

A data scientist keeps their code where it is and decorates it: `@node`
declares a function's ports beside the function, `Flow(name, nodes=[...])`
says which of them make a flow, and `use(fn, wire=..., **settings)` rebinds
one for a single flow. `fluksio sync` uploads the document plus a generated
import shim per node, so the store still holds a complete, runnable,
git-versioned definition while the code it imports stays theirs.

`fluksio login|run|runs` and `flow.submit().wait()` are the client half, over
the run endpoints that already existed. Runs record the user repository's
commit beside the store's, so "what code produced this number" is answerable
on the side that now holds the code.

- `fluksio/sdk/`: ports, decorators, the flow builder and its checks, the shim
  generator, an HTTP client and sync. Standard library only at import, so
  `from fluksio import node` in a training script pulls in no engine.
- `FlowDef.origin` marks a flow code-defined; `Run.origin_commit` carries the
  repository's commit; `POST /modules/refresh` retires the workers without an
  install, which every sync calls — a worker holds the imported package in
  memory, so an edit to it is invisible until the process goes.
- The canvas shows a generated body read-only and names the repository to edit
  instead; a body edited there stops the next sync rather than being discarded.
- The worker's reporter carries inert `Port`, `node`, `use` and `Flow`, since
  the shim imports a module whose first line declares them.
- `examples/myresearch` is the worked example, `make sync-example` uploads it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ue1tkFWB1bcGy3aWhCKpU
This commit is contained in:
2026-08-23 20:16:08 +02:00
co-authored by Claude Fable 5
parent 775d151307
commit a38e2745eb
35 changed files with 2693 additions and 142 deletions
@@ -1123,6 +1123,20 @@ function FlowEditorInner({
<span className="truncate px-3 py-1.5 text-sm font-medium">
{flowDoc.title || flowName}
</span>
{/* Declared in code somewhere else, at a commit that names what
actually ran. A dirty tree says so, because then it does not. */}
{flowDoc.origin ? (
<span
className="shrink-0 rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground"
title={flowDoc.origin.repo || "a repository"}
data-testid="flow-origin"
>
{flowDoc.origin.commit
? flowDoc.origin.commit.slice(0, 7)
: "no commit"}
{flowDoc.origin.dirty ? "*" : ""}
</span>
) : null}
</CanvasTitle>
<FlowDock
@@ -1198,6 +1212,7 @@ function FlowEditorInner({
node={selected}
flow={flowName}
nodeTypes={nodeTypeInfo ?? []}
origin={flowDoc.origin}
suggestions={suggestions}
expanded={editorExpanded}
onToggleExpand={() => setEditorExpanded((wide) => !wide)}
@@ -13,9 +13,12 @@ import { monacoFontFamily, setupMonaco } from "./monacoSetup"
export default function NodeEditor({
value,
onChange,
readOnly = false,
}: {
value: string
onChange: (next: string) => void
/** Generated code: readable, and not this panel's to change. */
readOnly?: boolean
}) {
const { resolvedTheme } = useTheme()
const [ready, setReady] = useState(false)
@@ -37,6 +40,7 @@ export default function NodeEditor({
onChange={(next) => onChange(next ?? "")}
loading={<Skeleton className="h-full w-full rounded-md" />}
options={{
readOnly,
fontFamily,
fontSize: 13,
minimap: { enabled: false },
+22 -1
View File
@@ -11,6 +11,7 @@ import {
import {
type DType,
type FlowOrigin,
FlowsService,
type MessageSpec,
type NodeDef_Input,
@@ -997,6 +998,7 @@ function PanelBody({
node,
flow,
nodeType,
origin,
suggestions,
expanded,
onChange,
@@ -1008,6 +1010,7 @@ function PanelBody({
node: NodeDef_Input
flow: string
nodeType: NodeTypeInfo | undefined
origin: FlowOrigin | null | undefined
suggestions: PortSuggestions
expanded: boolean
onChange: (next: NodeDef_Input) => void
@@ -1060,7 +1063,7 @@ function PanelBody({
const editNode = (next: NodeDef_Input) => {
onChange(next)
const current = code ?? source?.code
if (!hasSource || next.source_ref || current === undefined) return
if (!hasSource || next.source_ref || origin || current === undefined) return
const wanted = scaffoldFor(next)
if (current !== wanted && SCAFFOLD_SHAPE.test(current)) editCode(wanted)
}
@@ -1224,6 +1227,19 @@ function PanelBody({
{expanded ? <Minimize2 /> : <Maximize2 />}
</Button>
</div>
{origin ? (
/* The body below is an import of the real function, and the real
function is somewhere else. Editing it here would be undone by
the next sync, so it is read-only and says where to go. */
<p
className="text-xs text-muted-foreground"
data-testid="node-source-generated"
>
Generated by <span className="font-mono">fluksio sync</span> from{" "}
<span className="font-mono">{origin.repo || "a repository"}</span>{" "}
edit it there and sync again.
</p>
) : null}
<div className="min-h-0 flex-1 overflow-hidden rounded-md border border-border">
<Suspense
fallback={
@@ -1233,6 +1249,7 @@ function PanelBody({
<NodeEditor
value={code ?? source?.code ?? ""}
onChange={editCode}
readOnly={Boolean(origin)}
/>
</Suspense>
</div>
@@ -1253,6 +1270,7 @@ export function NodePanel({
node,
flow,
nodeTypes,
origin,
suggestions,
expanded,
onChange,
@@ -1266,6 +1284,8 @@ export function NodePanel({
node: NodeDef_Input | null
flow: string
nodeTypes: NodeTypeInfo[]
/** Set when the flow was declared in code elsewhere; its bodies are generated. */
origin: FlowOrigin | null | undefined
suggestions: PortSuggestions
expanded: boolean
onChange: (next: NodeDef_Input) => void
@@ -1318,6 +1338,7 @@ export function NodePanel({
node={node}
flow={flow}
nodeType={nodeType}
origin={origin}
suggestions={suggestions}
expanded={expanded}
onChange={onChange}