Outline Module¶
The outline module is the first self-contained plugin for the Knowledge Platform. It implements a hierarchical document outline backed by a typed graph.
Graph Type: outline¶
graph TD
ROOT["OutlineItem (root)"]
CH1["OutlineItem (child)"]
CH2["OutlineItem (child)"]
GCH1["OutlineItem (grandchild)"]
ROOT -->|ParentOf| CH1
ROOT -->|ParentOf| CH2
CH1 -->|ParentOf| GCH1
Node Type: OutlineItem¶
| Attribute | Type | Required | Default | Description |
|---|---|---|---|---|
title |
str |
Yes | — | Heading text for this item |
content |
str |
No | "" |
Optional body text |
position |
int |
No | 0 |
Sibling sort order (ascending) |
Edge Type: ParentOf¶
| Property | Value |
|---|---|
| Source types | OutlineItem only |
| Target types | OutlineItem only |
| Attributes | None |
| Description | Directed parent-to-child relationship |
OutlineService¶
OutlineService is the high-level API for working with outline graphs. It wraps IGraphService and adds outline-specific operations like adding items with parent relationships, subtree removal, and tree projection.
Creating an Outline¶
from knowledge_platform.modules.outline.service import OutlineService
svc = OutlineService(graph_service)
graph = svc.create_outline(workspace_id, "My Book")
# Graph now contains one root OutlineItem with title="My Book"
Building a Hierarchy¶
# Add a chapter under the root
root_node = list(graph.nodes("OutlineItem"))[0]
chapter = svc.add_item(graph.id, parent_id=root_node.id, title="Chapter 1", position=0)
# Add a section under the chapter
section = svc.add_item(graph.id, parent_id=chapter.id, title="1.1 Introduction", position=0)
# Add a root-level item (no parent)
appendix = svc.add_item(graph.id, parent_id=None, title="Appendix", position=1)
Updating an Item¶
Only non-None arguments are merged:
updated = svc.update_item(chapter.id, title="Chapter 1: Getting Started")
# content and position are unchanged
Removing an Item and Its Subtree¶
svc.remove_item(graph.id, chapter.id)
# Removes chapter and all its descendants (sections, subsections, etc.)
Moving an Item¶
svc.move_item(
graph.id,
node_id=section.id,
new_parent_id=appendix.id,
new_position=0,
)
# Removes existing ParentOf edge, creates new one under appendix
Getting the Tree Projection¶
roots = svc.get_tree(graph.id)
for root in roots:
print(root.title)
for child in root.children:
print(f" {child.title}")
Tree Projection: OutlineTreeProjection¶
OutlineTreeProjection converts a flat graph into an ordered tree structure. It is used internally by OutlineService.get_tree() and by the UI view model.
How it Works¶
- Collect all
OutlineItemnodes. - Build a
parent_id → [child_node, ...]mapping fromParentOfedges. - Sort each sibling list by the
positionattribute. - Identify roots: nodes with no incoming
ParentOfedges. - Recursively build
OutlineTreeNodetrees from roots.
OutlineTreeNode¶
OutlineTreeNode is the view object returned by the projection. It provides convenient property accessors:
tree_node.title # str
tree_node.content # str
tree_node.position # int
tree_node.depth # int (0 = root)
tree_node.node_id # NodeId
tree_node.children # list[OutlineTreeNode]
Flat Iteration¶
projection = OutlineTreeProjection()
roots = projection.project(graph)
flat = projection.flat_list(roots) # depth-first order
for item in flat:
indent = " " * item.depth
print(f"{indent}{item.title}")
Module Entry Point: OutlineModule¶
from knowledge_platform.modules.outline.module import OutlineModule
module = OutlineModule()
print(module.module_id) # "outline"
print(module.display_name) # "Outline"
print(module.primary_graph_type) # "outline"
# module.graph_types contains an OutlineGraphType instance
OutlineModule.create_widget() lazily imports OutlineView to avoid loading PySide6 in headless environments. The module also implements create_document() and list_documents() so the host can create and open outlines without importing OutlineService directly.
API Reference¶
knowledge_platform.modules.outline.graph_type.OutlineGraphType ¶
Bases: GraphType
Semantic type for outline graphs.
An outline is a rooted tree of :class:OutlineItem nodes connected by
:class:ParentOf edges (parent → child). There is exactly one root node
(an :class:OutlineItem with no incoming ParentOf edges).
Class attributes
type_name: "outline"
node_schemas: {"OutlineItem": OUTLINE_ITEM_SCHEMA}
edge_schemas: {"ParentOf": PARENT_OF_SCHEMA}
Source code in src/knowledge_platform/modules/outline/graph_type.py
knowledge_platform.modules.outline.service.OutlineService ¶
High-level operations for creating and managing outline graphs.
This service wraps :class:~knowledge_platform.services.interfaces.IGraphService
and adds outline-specific helpers (e.g. adding child items, re-ordering).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_service
|
IGraphService
|
Underlying application graph service. |
required |
Source code in src/knowledge_platform/modules/outline/service.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
Functions¶
add_item ¶
add_item(
graph_id: GraphId,
parent_id: NodeId | None,
title: str,
content: str = "",
position: int = 0,
) -> Node
Add a new :class:OutlineItem node, optionally as a child of parent_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Owning outline graph. |
required |
parent_id
|
NodeId | None
|
If provided, creates a |
required |
title
|
str
|
Node title. |
required |
content
|
str
|
Optional body text. |
''
|
position
|
int
|
Sibling sort order. |
0
|
Returns:
| Type | Description |
|---|---|
Node
|
The created :class: |
Source code in src/knowledge_platform/modules/outline/service.py
create_outline ¶
Create a new outline graph with a default root item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_id
|
WorkspaceId
|
Owning workspace. |
required |
name
|
str
|
Display name for the outline. |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
Newly created outline :class: |
Source code in src/knowledge_platform/modules/outline/service.py
get_outline ¶
Return an outline graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Target graph identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
The |
Graph
|
class: |
get_tree ¶
Return the tree projection for an outline graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Target outline graph. |
required |
Returns:
| Type | Description |
|---|---|
list[OutlineTreeNode]
|
Ordered list of root :class: |
Source code in src/knowledge_platform/modules/outline/service.py
list_outlines ¶
Return all outline graphs in a workspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_id
|
WorkspaceId
|
Owning workspace. |
required |
Returns:
| Type | Description |
|---|---|
list[Graph]
|
List of outline :class: |
Source code in src/knowledge_platform/modules/outline/service.py
move_item ¶
move_item(
graph_id: GraphId,
node_id: NodeId,
new_parent_id: NodeId | None,
new_position: int,
) -> None
Move an item to a new parent and/or position.
Removes any existing ParentOf edge that points to node_id and
creates a new one if new_parent_id is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Owning outline graph. |
required |
node_id
|
NodeId
|
Node to move. |
required |
new_parent_id
|
NodeId | None
|
New parent node ID, or |
required |
new_position
|
int
|
New sibling position. |
required |
Source code in src/knowledge_platform/modules/outline/service.py
remove_item ¶
Remove an :class:OutlineItem and all its descendant items.
Performs a depth-first traversal to collect all descendants before removing them bottom-up, avoiding dangling edge references.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Owning outline graph. |
required |
node_id
|
NodeId
|
Root of the sub-tree to remove. |
required |
Source code in src/knowledge_platform/modules/outline/service.py
update_item ¶
update_item(
node_id: NodeId,
title: str | None = None,
content: str | None = None,
position: int | None = None,
) -> Node
Update fields on an :class:OutlineItem.
Only non-None arguments are merged into the node's attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
NodeId
|
Target node. |
required |
title
|
str | None
|
New title, or |
None
|
content
|
str | None
|
New content, or |
None
|
position
|
int | None
|
New position, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Updated |
Node
|
class: |
Source code in src/knowledge_platform/modules/outline/service.py
knowledge_platform.modules.outline.projection.OutlineTreeProjection ¶
Projects an outline :class:Graph into an ordered tree structure.
The projection traverses ParentOf edges (parent → child) from each
node to build a tree. Nodes with no incoming ParentOf edges are
considered roots (a well-formed outline has exactly one root).
Example::
projection = OutlineTreeProjection()
roots = projection.project(graph)
for root in roots:
print(root.title)
for child in root.children:
print(" ", child.title)
Source code in src/knowledge_platform/modules/outline/projection.py
Functions¶
flat_list ¶
Return a depth-first flat iteration of the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roots
|
list[OutlineTreeNode]
|
Output of :meth: |
required |
Returns:
| Type | Description |
|---|---|
list[OutlineTreeNode]
|
Flat ordered list of all :class: |
Source code in src/knowledge_platform/modules/outline/projection.py
project ¶
Build a forest of :class:OutlineTreeNode trees from graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
Outline graph to project. |
required |
Returns:
| Type | Description |
|---|---|
list[OutlineTreeNode]
|
Ordered list of root :class: |
list[OutlineTreeNode]
|
a single-element list for a well-formed outline). |
Source code in src/knowledge_platform/modules/outline/projection.py
knowledge_platform.modules.outline.projection.OutlineTreeNode
dataclass
¶
A node in the projected tree view.
This is a view object – it holds a reference to the underlying domain
:class:~knowledge_platform.core.node.Node and its resolved children,
ordered by position attribute.
Attributes:
| Name | Type | Description |
|---|---|---|
node |
Node
|
The underlying domain node. |
children |
list['OutlineTreeNode']
|
Ordered list of child :class: |
depth |
int
|
Zero-based depth in the tree (0 = root). |
Source code in src/knowledge_platform/modules/outline/projection.py
Attributes¶
knowledge_platform.modules.outline.module.OutlineModule ¶
Plugin entry-point for the Outline module.
Registers the :class:OutlineGraphType with the platform's type registry
and provides the factory for the module's primary UI widget.
Attributes:
| Name | Type | Description |
|---|---|---|
module_id |
str
|
|
display_name |
str
|
|
graph_type |
str
|
:class: |
Source code in src/knowledge_platform/modules/outline/module.py
Functions¶
configure ¶
create_document ¶
Create a new outline document.
Source code in src/knowledge_platform/modules/outline/module.py
create_widget ¶
Construct and return the Outline module's main UI widget.
Lazily imports PySide6 so the module can be used in headless contexts (e.g. unit tests) without a display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_service
|
IGraphService
|
Application graph service passed from the platform. |
required |
parent
|
'QWidget | None'
|
Optional Qt parent widget. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
'QWidget'
|
class: |
Source code in src/knowledge_platform/modules/outline/module.py
list_documents ¶
List all outline documents in a workspace.
supports_graph_type ¶
Return whether this module owns type_name.