Space Goal
Provide a personal knowledge base management center:
- The left side is a tree-style category of the knowledge base, supporting multi-level folders (unlimited depth). You can create Markdown files or table files.
- Files/folders support rename and delete; when deleting a folder you must confirm: delete only the folder (children move up one level) or delete the folder together with its children.
- Supports importing files to create nodes:
md / pdf / doc / docx / xlsx / xls. Excel is parsed into a table, everything else is parsed into Markdown. - Clicking a file enters view mode; clicking "Edit" enters edit mode: Markdown supports text / table-cell dual-mode editing (when the content contains tables it defaults to table-cell mode, parsing Markdown tables into cells; after editing cell by cell, the content is automatically reassembled back into Markdown); tables use the same table-cell editing (with row/column add/delete).
Access
Opening this space enters the knowledge base home page:
- Top toolbar:
📁 New Folder,📄 New File(Markdown/table optional),📥 Import. - Left tree: click ▸/▾ to expand/collapse folders, click a node name to view its content;
✎/🗑at the end of a row renames/deletes. - Right panel: folders show an info card; files show content (Markdown rendering or table grid); click "Edit" to enter edit mode (when Markdown content contains tables it defaults to "Table" mode; you can switch between "▣ Text / ▢ Table" at the top at any time; tables use a cell grid), then click "💾 Save" after editing.
- Operation results are shown via a toast at the bottom right.
Markdown Table-Cell Editing (md files)
- When entering Markdown editing, the content is parsed automatically:
| ... |table blocks are extracted into editable cells (md_tables), and the remaining text is kept as segments (md_segments); "Table" mode is the default when tables are present, otherwise "Text" mode is used. - In "Table" mode each table is rendered as a cell grid: header and cells are all input boxes, with onInput/onBlur events syncing in real time to state; each table has a "+Row / +Column / -Last Row / -Last Column" toolbar.
- On "Save", table data is reassembled into Markdown tables in segment order (preserving alignment markers and empty cells), merged with the original text and saved.
Table Editing (table files)
- Table file editing also uses a cell grid (no longer TSV text): header and cells are input boxes, synced in real time to
table_edit_cols/table_edit_rows. - Supports "+Row / +Column / -Last Row / -Last Column"; on "Save" the latest content of all cells is read and reassembled into
{columns, rows}and written to the table.
Development Notes
MCL (mcl file)
- Layout:
app_root(left/right split) →sidebar(toolbar + tree) +main_panel(view/edit area) + modal dialogs (new folder/file, import, rename, delete confirmation) + toast. - The tree uses flat-row rendering (
tree_rows, containingdepth/display/chevron); level indentation is precomputed by MCS (full-width spaces); events inside loops pass arguments vianode_id=row.id. - State:
expanded_ids(expanded set),selected_id,editing_md/editing_table, dialog switches, etc.; Markdown cell mode:md_table_mode,md_has_tables,md_segments,md_tables({columns, align, rows[{row_index, row_no, cells[{value}]}]}); table grid:table_edit_cols,table_edit_rows({row_index, row_no, cells[{value}]}). - Cell input does not rely on dynamic ids:
[input]bindsonInput/onBlurevent handlers (md usescell_edited/col_edited, tables usetable_cell_edited/table_col_edited); event arguments carryinput_contextand the loop scope (tbl,trow,index), located bytbl.table_index/trow.row_indexand written back to state. - Fallback:
poll kb_initial_loadautomatically ensures the tree is loaded (stops afterhas_tree == true).
MCS (mcs file)
- Data storage:
self.data["kb"] = {nodes: {id: node}, root_ids: [...]}; node containstype(folder/file),file_kind(md/table),parent_id,children,content,table{columns,rows}, timestamps. - Methods:
kb_get_tree(flat tree rows),kb_get_node,kb_create_folder,kb_create_file,kb_rename_node,kb_delete_node(controlled bydelete_children),kb_save_md,kb_save_table,kb_import_file,md_parse_tables(extract Markdown tables into cells),md_build_content(reassemble cells back into Markdown); private helpers:_split_ext,_fetch_bytes,_create_node_with_content,_table_from_rows,_parse_excel(openpyxl/xlrd + zipfile fallback),_parse_pdf(pypdf),_parse_doc(zipfile+xml / python-docx),_is_table_start,_is_separator_line,_is_table_body_line,_parse_table_block,_split_row,_build_table_block. - The md table cells and the table grid share the same "cell input → state sync → reassemble on save" pattern: md goes through
md_build_contentto reassemble into Markdown; tables are reassembled directly fromtable_edit_cols/table_edit_rowsinto{columns, rows}. - Dependencies (already available in the MCS host):
openpyxl,xlrd,pypdf,python-docx,urllib.request(verified viakb_probe_env). - Testing: use
mcl_invoke_spacewithCALL_MCS/CALL_MCL_SCRIPTto verify method by method; import parsing was previously verified end-to-end using in-memory constructed files.
Directory Description
mcl: frontend page (view structure / style / script interaction logic).mcs: backend service methods (knowledge base CRUD and file import parsing).SPACE.md: this document.
Notes
- All data is persisted in
self.data["kb"]; delete operations are unrecoverable (a second confirmation is required before deleting a folder). - Import relies on the file access URL returned by the upload component: MCS downloads it via
_fetch_bytes(urllib) and parses it; if the platform does not return a URL, a clear message is shown instead of silently failing. - MCS
@flowis a Python subset: assigning to a variable with the same name as an input parameter is forbidden (it triggersUnboundLocalError); for example thename = name or ""pattern in_split_extcannot be used — use a new variable name instead. - Text bindings must start with
$(mixed interpolation is not supported); display text shown in the UI (e.g. "Item count: N") must be pre-concatenated in the script. - Components inside loops should not use dynamic
ids (the server-side view registry resolves by static attributes); event arguments should use thenode_id=row.idform.



