Files
workbuddy_skills/session-mechanism/scripts/lock/handoff-status.py
T
admin 9e779c4889 仓级:按新规则重新规范化行尾符(--renormalize)
上一步立了 .gitattributes(text eol=lf),这一步把已入库的文件按新规则
统一成 LF。245 个文件,其中 product-planning 239 个、session-mechanism 6 个。

这批改动**只有行尾符**:`git diff --ignore-cr-at-eol` 对全部 245 个文件
零内容差异,未触碰任何二进制与资源文件。

单独一笔的理由:把"改规则"与"按规则刷数据"分开,将来若有谁的改动撞上,
可以直接对着这一笔回退,而不牵连 .gitattributes 本身。
2026-10-14 11:23:56 +08:00

95 lines
4.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""handoff-status.py — 一条命令看清 05-交接单 里哪些单子【待执行】/【已完成】/【无状态】。
为什么需要它:`05-交接单/交接单-已完成/` 那层目录摊平后,**"目录位置"不再表达状态**。
状态改由**机读字段**承载(与布局解耦,摊平/搬家都不失效):
① 单子头部 `- 状态:…` 行(模板已有)→ ② 回退取 `05-交接单/README.md` 台账表的「状态」列
用法:python 07-scripts/handoff-status.py
"""
# [session-mechanism] roots.env 外置(由 install.py 生成 ⇒ `<包>/env/roots.env`)
# 查找顺序:向上 4 层 × (env/roots.env 优先 → 包根 roots.env 兼容) → 技能库那份。
def _sm_load_roots():
import os as _os
_here = _os.path.dirname(_os.path.abspath(__file__))
_cands = []
for _up in range(4):
_base = _os.path.normpath(_os.path.join(_here, *([".."] * _up)))
for _rel in (("env", "roots.env"), ("roots.env",)):
_cands.append(_os.path.join(_base, *_rel))
_conf = _os.environ.get("CODEBUDDY_CONFIG_DIR") or _os.path.expanduser("~/.workbuddy")
_cands.append(_os.path.join(_conf, "skills", "session-mechanism", "env", "roots.env"))
for _p in _cands:
if _os.path.isfile(_p):
try:
with open(_p, encoding="utf-8") as _f:
for _ln in _f:
_ln = _ln.strip()
if _ln and not _ln.startswith("#") and "=" in _ln:
_k, _v = _ln.split("=", 1)
_os.environ.setdefault(_k.strip(), _v.strip())
except Exception:
pass
return
_sm_load_roots()
import os
import re
ROOT = os.environ.get("DSH_DOCS_ROOT") or os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
D = os.path.join(ROOT, "05-交接单")
README = os.path.join(D, "README.md")
HEAD_STATUS = re.compile(r"^[\s>*\-|#]*\*{0,2}状态\*{0,2}\s*[::]\s*(.+?)\s*$", re.M)
DONE_KW = ("已完成", "已落地", "已归档", "已收口", "已闭合", "已实施", "已上线",
"已修复", "已释放", "已结束", "已通过", "全部完成", "全绿", "✅")
WAIT_KW = ("待执行", "待开工", "进行中", "在途", "待验证", "待跑", "规划中", "未开工",
"部分执行", "受阻", "未做", "设计定稿", "🔄", "⏳", "⏸", "🟡")
table = {}
if os.path.exists(README):
with open(README, encoding="utf-8") as fh:
for line in fh:
if not line.startswith("|"):
continue
cells = [c.strip() for c in line.strip().strip("|").split("|")]
if len(cells) < 2 or ".md" not in cells[0]:
continue
table[cells[0].strip("`").split("/")[-1].strip()] = cells[1]
groups = {"待执行": [], "已完成": [], "无状态": []}
targets = []
for root2, dirs2, _f in os.walk(D):
dirs2[:] = [x for x in dirs2 if not x.startswith(".")]
for f2 in _f:
if f2.endswith(".md") and f2 != "README.md" and not f2.startswith("."):
rel = os.path.relpath(os.path.join(root2, f2), D).replace("\\", "/")
targets.append((rel, os.path.join(root2, f2)))
for n, path in sorted(targets):
base = n.split("/")[-1]
with open(path, encoding="utf-8", errors="ignore") as fh:
head = "".join(fh.readlines()[:30])
m = HEAD_STATUS.search(head)
if m:
s, src = m.group(1)[:44], "头部"
elif base in table:
s, src = table[base][:44], "台账表"
else:
s, src = "", ""
if not s:
groups["无状态"].append((n, "—"))
elif any(k in s for k in DONE_KW):
groups["已完成"].append((n, "%s ·%s" % (s, src)))
elif any(k in s for k in WAIT_KW):
groups["待执行"].append((n, "%s ·%s" % (s, src)))
else:
groups["无状态"].append((n, "%s ·%s未识别" % (s, src)))
for g in ("待执行", "已完成", "无状态"):
print("【%s】%d 个" % (g, len(groups[g])))
for n, s in groups[g]:
print(" %-44s %s" % (n[:44], s))
print()
print("合计 %d 个单子(不含 README.md)" % sum(len(v) for v in groups.values()))