Initial commit: company-kb framework
- 完整的知识库框架(P0-P5 路线图) - 12篇治理文档 - 工具脚本(kb-init.sh, kb-lint-fm.py, feishu-sync.py, kb-bot) - 7个 Claude 命令 - 示例项目和测试项目(wanniu-l1) - 契约文件(meta/kb-contract.yaml) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
80
tools/kb-init.sh
Executable file
80
tools/kb-init.sh
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
# kb-init.sh —— 幂等建项目骨架
|
||||
# 用法:
|
||||
# bash tools/kb-init.sh <代号> # 建 projects/<代号>/ 骨架 + _index.md(type: project, status: seed)
|
||||
# bash tools/kb-init.sh --stats # 打印源计数(更新 meta/stats.md 参考值)
|
||||
# 约束: <代号> 用英文/拼音,禁纯中文目录名(Claude Code 会把中文编码为 - 导致碰撞)。
|
||||
set -euo pipefail
|
||||
|
||||
# 定位库根(本脚本在 tools/ 下)
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
usage() { grep '^#' "$0" | sed 's/^# \{0,1\}//'; exit "${1:-0}"; }
|
||||
|
||||
# ── --stats: 红线观察点 ──
|
||||
if [[ "${1:-}" == "--stats" ]]; then
|
||||
proj=$(find "$ROOT/projects" -mindepth 1 -maxdepth 1 -type d ! -name '_example' 2>/dev/null | wc -l | tr -d ' ')
|
||||
pages=$(grep -rl '^type:' "$ROOT/projects" "$ROOT/entities" "$ROOT/concepts" "$ROOT/questions" 2>/dev/null | wc -l | tr -d ' ')
|
||||
srcs=$(grep -rh '^source_link:' "$ROOT/projects" 2>/dev/null | sort -u | wc -l | tr -d ' ')
|
||||
echo "项目数: $proj | 知识页数: $pages | 外部源数(去重): $srcs"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CODE="${1:-}"
|
||||
[[ -z "$CODE" || "$CODE" == "-h" || "$CODE" == "--help" ]] && usage 0
|
||||
|
||||
# 中文目录名保护
|
||||
if echo "$CODE" | LC_ALL=C grep -q '[^ -~]'; then
|
||||
echo "错误: 代号 '$CODE' 含非 ASCII 字符。请用英文/拼音(禁纯中文目录名)。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PDIR="$ROOT/projects/$CODE"
|
||||
if [[ -d "$PDIR" ]]; then
|
||||
echo "项目已存在: projects/$CODE (幂等:不覆盖,仅补齐缺失子目录)"
|
||||
fi
|
||||
|
||||
mkdir -p "$PDIR"/{docs,decisions,conversations,assets}
|
||||
for sub in docs assets; do [[ -f "$PDIR/$sub/.gitkeep" ]] || touch "$PDIR/$sub/.gitkeep"; done
|
||||
|
||||
INDEX="$PDIR/_index.md"
|
||||
if [[ -f "$INDEX" ]]; then
|
||||
echo "保留已有 _index.md(幂等): projects/$CODE/_index.md"
|
||||
else
|
||||
TODAY="$(date +%F)"
|
||||
cat > "$INDEX" <<EOF
|
||||
---
|
||||
type: project
|
||||
title: "$CODE"
|
||||
description:
|
||||
status: seed
|
||||
created: $TODAY
|
||||
ingested: $TODAY
|
||||
tags: []
|
||||
related: []
|
||||
---
|
||||
|
||||
# $CODE
|
||||
|
||||
## 概览
|
||||
一句话说明本项目是什么、当前在做什么。
|
||||
|
||||
## 进展
|
||||
-
|
||||
|
||||
## 关键决策
|
||||
(见 decisions/,用 [[slug]] 链接)
|
||||
|
||||
## 需求方 / 参与人
|
||||
-
|
||||
|
||||
## 资料索引
|
||||
- docs/ :外部汇入文档
|
||||
- conversations/ :聊天沉淀
|
||||
- decisions/ :决策记录
|
||||
EOF
|
||||
echo "已创建: projects/$CODE/_index.md (type: project, status: seed)"
|
||||
fi
|
||||
|
||||
echo "骨架就绪: projects/$CODE/{docs,decisions,conversations,assets}"
|
||||
echo "下一步: 丢资料 + 一句说明,或运行 kb-lint-fm.py 校验。"
|
||||
Reference in New Issue
Block a user