MCPcopy Create free account
hub / github.com/Qinbf/groundmap / create_workspace

Function create_workspace

scripts/k.py:2725–2791  ·  view source on GitHub ↗

在 DATA_ROOT/workspaces/ 下创建一个新的空知识库骨架。 生成:标准目录结构 + wiki/root_index.md(标准 frontmatter 的空根索引) + log.md(首条 human 日志)。不碰已存在的 workspace(直接拒绝)。 返回创建摘要 dict(给 --json 输出用)。

(name: str)

Source from the content-addressed store, hash-verified

2723
2724
2725def create_workspace(name: str) -> dict:
2726 """在 DATA_ROOT/workspaces/ 下创建一个新的空知识库骨架。
2727
2728 生成:标准目录结构 + wiki/root_index.md(标准 frontmatter 的空根索引)
2729 + log.md(首条 human 日志)。不碰已存在的 workspace(直接拒绝)。
2730 返回创建摘要 dict(给 --json 输出用)。
2731 """
2732 if not WORKSPACE_NAME_RE.match(name or ""):
2733 raise ValueError(
2734 f"非法 workspace 名 {name!r}——只允许小写字母/数字/连字符/下划线,"
2735 f"且以字母或数字开头(如 my-research)"
2736 )
2737 ws = DATA_ROOT / "workspaces" / name
2738 if ws.exists():
2739 raise ValueError(f"workspace 已存在: {ws}")
2740
2741 today = datetime.now().strftime("%Y-%m-%d")
2742 for sub_dir in _WORKSPACE_SKELETON:
2743 (ws / sub_dir).mkdir(parents=True)
2744 for keep in ("exports", "my_thoughts", "raw/articles", "raw/papers"):
2745 (ws / keep / ".gitkeep").write_text("", encoding="utf-8")
2746
2747 root_index = f"""---
2748title: "知识库根索引 — {name}"
2749type: index
2750created_date: {today}
2751last_modified: {today}
2752last_modified_by: Human
2753status: draft
2754confidence: high
2755source_count: 0
2756sources: []
2757tags:
2758 - root
2759scope: "wiki/concepts/*, wiki/entities/*, wiki/sources/*, wiki/indexes/*, wiki/analyses/*"
2760page_count: 0
2761---
2762
2763# 根索引 — {name}
2764
2765> 这是一个新建的空知识库。第一次 ingest 之后,由 agent 在下方「领域目录」表中登记子索引(MOC),查询时从这里下钻。
2766
2767## 领域目录
2768
2769| 领域 | 子索引 | 页面数 | 最近更新 |
2770|------|--------|--------|----------|
2771
2772## 近期更新
2773
2774(暂无——把第一份资料放进 `raw/articles/` 或 `raw/papers/`,跑 `convert.py` 后让 agent ingest 即可。)
2775"""
2776 (ws / "wiki" / "root_index.md").write_text(root_index, encoding="utf-8")
2777
2778 log_md = (
2779 f"# 操作日志 — {name}\n\n"
2780 f"## [{today}] human | 创建 workspace\n"
2781 f"- 由 `python scripts/k.py new-workspace {name}` 脚手架生成\n"
2782 )

Callers 1

_main_implFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected