task-ledger 1.3.27 → 1.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/SKILL.md +5 -3
- package/assets/worklog.md +1 -1
- package/package.json +1 -1
- package/references/init-identity.md +3 -3
- package/references/log-note.md +1 -1
- package/references/troubleshooting.md +1 -1
- package/scripts/bin/ledger-darwin-arm64 +0 -0
- package/scripts/bin/ledger-linux-amd64 +0 -0
- package/scripts/bin/ledger-windows-amd64.exe +0 -0
- package/scripts/progress +44 -0
- package/scripts/ledgerkit/__init__.py +0 -0
- package/scripts/ledgerkit/actions/__init__.py +0 -0
- package/scripts/ledgerkit/actions/atom.py +0 -154
- package/scripts/ledgerkit/actions/bootstrap.py +0 -37
- package/scripts/ledgerkit/actions/claim.py +0 -88
- package/scripts/ledgerkit/actions/close_task.py +0 -191
- package/scripts/ledgerkit/actions/guard.py +0 -158
- package/scripts/ledgerkit/actions/handoff.py +0 -93
- package/scripts/ledgerkit/actions/init_identity.py +0 -90
- package/scripts/ledgerkit/actions/list_tasks.py +0 -74
- package/scripts/ledgerkit/actions/log_progress.py +0 -67
- package/scripts/ledgerkit/actions/new_task.py +0 -129
- package/scripts/ledgerkit/actions/query.py +0 -35
- package/scripts/ledgerkit/actions/query_history.py +0 -220
- package/scripts/ledgerkit/actions/registry.py +0 -82
- package/scripts/ledgerkit/actions/relabel.py +0 -89
- package/scripts/ledgerkit/actions/release.py +0 -76
- package/scripts/ledgerkit/actions/result.py +0 -90
- package/scripts/ledgerkit/actions/set_task.py +0 -71
- package/scripts/ledgerkit/actions/show_task.py +0 -55
- package/scripts/ledgerkit/actions/validate.py +0 -189
- package/scripts/ledgerkit/core/__init__.py +0 -0
- package/scripts/ledgerkit/core/history_md.py +0 -152
- package/scripts/ledgerkit/core/identity.py +0 -54
- package/scripts/ledgerkit/core/ids.py +0 -58
- package/scripts/ledgerkit/core/labels.py +0 -89
- package/scripts/ledgerkit/core/paths.py +0 -92
- package/scripts/ledgerkit/core/roots.py +0 -74
- package/scripts/ledgerkit/core/time.py +0 -103
- package/scripts/ledgerkit/core/worklog_md.py +0 -435
- package/scripts/ledgerkit/env.py +0 -94
- package/scripts/ledgerkit/errors.py +0 -15
- package/scripts/ledgerkit/notices.py +0 -28
- package/scripts/ledgerkit/shell/__init__.py +0 -0
- package/scripts/ledgerkit/shell/cli.py +0 -532
- package/scripts/ledgerkit/shell/gitops.py +0 -668
- package/scripts/ledgerkit/shell/merge.py +0 -266
- package/scripts/ledgerkit/shell/presync.py +0 -23
- package/scripts/ledgerkit/shell/render.py +0 -216
- package/scripts/ledgerkit/shell/runner.py +0 -232
- package/scripts/ledgerkit/store/__init__.py +0 -0
- package/scripts/ledgerkit/store/atomic.py +0 -130
- package/scripts/ledgerkit/store/dirty.py +0 -108
- package/scripts/ledgerkit/store/history_store.py +0 -134
- package/scripts/ledgerkit/store/json_store.py +0 -166
- package/scripts/ledgerkit/store/locks.py +0 -64
- package/scripts/ledgerkit/store/owners_index.py +0 -127
- package/scripts/ledgerkit/store/task_store.py +0 -28
- package/scripts/ledgerkit/store/worklog_store.py +0 -178
- package/scripts/progress.py +0 -20
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"""只读:查已结案(按结案时间过滤,倒序取最近)。不写任何字节、不依赖格式升级。
|
|
2
|
-
|
|
3
|
-
时间区间一律落在**结案时间** `finished` 上 —— 历史文件本来就按结案月归档
|
|
4
|
-
(`history/<结案年月>.md`),按创建时间过滤会漏掉「上月建、本月结」的记录。
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
from dataclasses import replace
|
|
10
|
-
from datetime import datetime, timedelta
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
from typing import Any
|
|
13
|
-
|
|
14
|
-
from ..core import history_md
|
|
15
|
-
from ..core.identity import Identity, normalize
|
|
16
|
-
from ..core.paths import HISTORY_DIR, month_of, to_repo_rel
|
|
17
|
-
from ..core.time import now, time_key
|
|
18
|
-
from ..errors import Fail
|
|
19
|
-
from ..store.history_store import HistoryStore
|
|
20
|
-
from ..store.owners_index import OwnersIndex
|
|
21
|
-
from .guard import is_mine, require_uuid
|
|
22
|
-
from .query import COUNT_CAP, HistoryQuery
|
|
23
|
-
from .result import HistoryResult, rel
|
|
24
|
-
|
|
25
|
-
#: 一次最多读多少个历史文件(按月分文件;不区分连续 / 分散,只数总数)。
|
|
26
|
-
MAX_HISTORY_FILES = 13
|
|
27
|
-
#: 没给任何时间参数时,默认只看最近几个自然月。
|
|
28
|
-
DEFAULT_HISTORY_MONTHS = 3
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def _recent_month_keys(count: int) -> list[str]:
|
|
32
|
-
"""最近 count 个自然月的月份键(含当月),按当前 UTC 推,从新到旧。"""
|
|
33
|
-
stamp = now()
|
|
34
|
-
year, month = int(stamp[0:4]), int(stamp[5:7])
|
|
35
|
-
keys: list[str] = []
|
|
36
|
-
for _ in range(max(count, 0)):
|
|
37
|
-
keys.append(f"{year:04d}{month:02d}")
|
|
38
|
-
month -= 1
|
|
39
|
-
if month == 0:
|
|
40
|
-
year, month = year - 1, 12
|
|
41
|
-
return keys
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def _shift_month(ym: str, delta: int) -> str:
|
|
45
|
-
"""`YYYYMM` 偏移 delta 个月;越过年份边界自动进位 / 借位。"""
|
|
46
|
-
idx = int(ym[0:4]) * 12 + (int(ym[4:6]) - 1) + delta
|
|
47
|
-
return f"{idx // 12:04d}{idx % 12 + 1:02d}"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def _month_keys_between(lo_ym: str, hi_ym: str) -> list[str]:
|
|
51
|
-
"""`[lo_ym, hi_ym]` 闭区间内的月份键(升序);两端给反了也能兜住。"""
|
|
52
|
-
if lo_ym > hi_ym:
|
|
53
|
-
lo_ym, hi_ym = hi_ym, lo_ym
|
|
54
|
-
keys: list[str] = []
|
|
55
|
-
cur = lo_ym
|
|
56
|
-
while cur <= hi_ym:
|
|
57
|
-
keys.append(cur)
|
|
58
|
-
cur = _shift_month(cur, 1)
|
|
59
|
-
return keys
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _month_end(ym: str) -> str:
|
|
63
|
-
"""`YYYYMM` 所在月的最后一秒(`YYYY-MM-DD HH:MM:SS`),用于把老平铺文件也框进区间。"""
|
|
64
|
-
year, month = int(ym[0:4]), int(ym[4:6])
|
|
65
|
-
nxt = datetime(year + (1 if month == 12 else 0), (month % 12) + 1, 1)
|
|
66
|
-
return (nxt - timedelta(seconds=1)).strftime("%Y-%m-%d %H:%M:%S")
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def _target_month_keys(q: HistoryQuery) -> list[str]:
|
|
70
|
-
"""由时间参数算出「要读的月份键」;超过上限直接 Fail(不碰磁盘)。
|
|
71
|
-
|
|
72
|
-
- 无任何时间参数 ⇒ 最近 `DEFAULT_HISTORY_MONTHS` 个自然月;
|
|
73
|
-
- `--months N` ⇒ 最近 N 个自然月(与 `--since/--until` 互斥);
|
|
74
|
-
- `--since/--until` ⇒ 结案月区间(只给一端时,另一端按默认口径补齐)。
|
|
75
|
-
"""
|
|
76
|
-
if q.months is not None and (q.since or q.until):
|
|
77
|
-
raise Fail("--months 与 --since/--until 不能同时用(时间口径二选一)。")
|
|
78
|
-
if q.months is not None:
|
|
79
|
-
if q.months < 1:
|
|
80
|
-
raise Fail("--months 至少为 1。")
|
|
81
|
-
keys = _recent_month_keys(q.months)
|
|
82
|
-
elif q.since or q.until:
|
|
83
|
-
if q.since:
|
|
84
|
-
lo = month_of(q.since)
|
|
85
|
-
elif q.until:
|
|
86
|
-
# 只给 --until:往前补到默认窗口(与「默认近 3 月」一致)
|
|
87
|
-
lo = _shift_month(month_of(q.until), -(DEFAULT_HISTORY_MONTHS - 1))
|
|
88
|
-
else: # pragma: no cover - 上面已保证至少给了一个
|
|
89
|
-
raise Fail("--since/--until 至少要给一个。")
|
|
90
|
-
hi = month_of(q.until) if q.until else month_of(now())
|
|
91
|
-
if not lo or not hi:
|
|
92
|
-
raise Fail("--since/--until 时间格式不对,算不出月份。")
|
|
93
|
-
keys = _month_keys_between(lo, hi)
|
|
94
|
-
else:
|
|
95
|
-
keys = _recent_month_keys(DEFAULT_HISTORY_MONTHS)
|
|
96
|
-
# 上限卡的是「要读的文件总数」,不是月跨度:按月分文件,一个键一个文件;
|
|
97
|
-
# 连不连续、将来把多段时间拼在一起也都只数总数。
|
|
98
|
-
files = sorted(set(keys))
|
|
99
|
-
if len(files) > MAX_HISTORY_FILES:
|
|
100
|
-
raise Fail(
|
|
101
|
-
f"历史查询一次最多读 {MAX_HISTORY_FILES} 个历史文件(按月分文件,不区分连续/分散),"
|
|
102
|
-
f"本次要读 {len(files)} 个 ⇒ 缩小 --since/--until 或 --months。"
|
|
103
|
-
)
|
|
104
|
-
return files
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def _candidate_paths(repo: Path, keys: list[str]) -> list[Path]:
|
|
108
|
-
"""按月键【直接拼】`history/<年月>.md`(不扫磁盘)。"""
|
|
109
|
-
return [repo / to_repo_rel(HISTORY_DIR / f"{ym}.md") for ym in keys]
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def query_history(repo: Path, me: Identity, q: HistoryQuery) -> HistoryResult:
|
|
113
|
-
"""`--owner` / `--mine` 一律按 **uuid 精确相等**;名字只能走 `--owner-name` 模糊筛。
|
|
114
|
-
|
|
115
|
-
`--since` / `--until` 比 `finished`(结案时间)。
|
|
116
|
-
"""
|
|
117
|
-
if q.owner is not None:
|
|
118
|
-
if q.mine:
|
|
119
|
-
raise Fail("--owner 不能和 --mine 一起用:一次只按一种范围筛。")
|
|
120
|
-
q = replace(q, owner=require_uuid(q.owner, field="--owner"))
|
|
121
|
-
keys = _target_month_keys(q)
|
|
122
|
-
store = HistoryStore(repo)
|
|
123
|
-
records: list[dict[str, Any]] = []
|
|
124
|
-
warnings: list[str] = []
|
|
125
|
-
for path in _candidate_paths(repo, keys):
|
|
126
|
-
if not path.is_file():
|
|
127
|
-
continue # 该月无记录 / 老平铺文件不存在 ⇒ 跳过,不报错
|
|
128
|
-
rows, warns = history_md.parse_history(store.read(path))
|
|
129
|
-
warnings.extend(f"{rel(repo, path)}:{w}" for w in warns)
|
|
130
|
-
for row in rows:
|
|
131
|
-
row = dict(row)
|
|
132
|
-
row["src"] = rel(repo, path)
|
|
133
|
-
row["created"] = time_key(row.get("created") or "") or row.get("created")
|
|
134
|
-
row["finished"] = time_key(row.get("finished") or "") or row.get("finished")
|
|
135
|
-
# 每行自带 `mine`(只比 uuid):调用方不必自己拿 uuid 再比一次
|
|
136
|
-
row["mine"] = is_mine(row, me)
|
|
137
|
-
records.append(row)
|
|
138
|
-
|
|
139
|
-
index = OwnersIndex(repo)
|
|
140
|
-
roster = index.all()
|
|
141
|
-
if q.mine:
|
|
142
|
-
wanted = {normalize(me.uuid)}
|
|
143
|
-
records = [r for r in records if normalize(r.get("owner") or "") in wanted]
|
|
144
|
-
elif q.owner:
|
|
145
|
-
key = normalize(q.owner)
|
|
146
|
-
records = [r for r in records if normalize(r.get("owner") or "") == key]
|
|
147
|
-
if q.owner_name:
|
|
148
|
-
# 名字已经落在历史行里 ⇒ 直接比它(子串、不分大小写)。落的是**当时**那个名字,
|
|
149
|
-
# 改名后的旧行仍留旧名 ⇒ 按新名筛不到旧行,这是快照语义,不是漏。
|
|
150
|
-
# 老行(升级前落的)没有名字列,退回按 uuid 片段比,不至于一条都筛不出来。
|
|
151
|
-
needle = q.owner_name.strip().lower()
|
|
152
|
-
records = [
|
|
153
|
-
r
|
|
154
|
-
for r in records
|
|
155
|
-
if needle in str(r.get("owner_name") or "").lower()
|
|
156
|
-
or needle in normalize(r.get("owner") or "")
|
|
157
|
-
]
|
|
158
|
-
|
|
159
|
-
# 名字**已经落盘**(`owner_name` / `creator_name` 两列)。这里只给没名字的**老行**
|
|
160
|
-
# 按名册兜底补一次 —— 补的是读时展示值,不回写文件。
|
|
161
|
-
for row in records:
|
|
162
|
-
for field, target in (("owner", "owner_name"), ("creator", "creator_name")):
|
|
163
|
-
if row.get(target):
|
|
164
|
-
continue
|
|
165
|
-
key = normalize(row.get(field) or "")
|
|
166
|
-
name = str((roster.get(key) or {}).get("name") or "")
|
|
167
|
-
if name:
|
|
168
|
-
row[target] = name
|
|
169
|
-
if q.category:
|
|
170
|
-
records = [r for r in records if (r.get("category") or "") == q.category]
|
|
171
|
-
if q.tag:
|
|
172
|
-
records = [r for r in records if q.tag in (r.get("tags") or ())]
|
|
173
|
-
|
|
174
|
-
# 有效结案区间:显式 --since/--until 优先(精确到秒),缺的一端用月份窗口补,
|
|
175
|
-
# 这样老平铺文件里的行也会被同一条规则框住,不会在月份查询里「漏网」。
|
|
176
|
-
lo_key, hi_key = min(keys), max(keys)
|
|
177
|
-
eff_since = q.since or f"{lo_key[0:4]}-{lo_key[4:6]}-01 00:00:00"
|
|
178
|
-
eff_until = q.until or _month_end(hi_key)
|
|
179
|
-
if eff_since > eff_until:
|
|
180
|
-
raise Fail(
|
|
181
|
-
f"时间区间反了:--since({eff_since})晚于 --until({eff_until})。\n"
|
|
182
|
-
" 处理:把两端换过来;只给一端就只给一端。"
|
|
183
|
-
)
|
|
184
|
-
records = [r for r in records if (r.get("finished") or "") >= eff_since]
|
|
185
|
-
records = [r for r in records if (r.get("finished") or "") <= eff_until]
|
|
186
|
-
|
|
187
|
-
records.sort(key=lambda r: str(r.get("finished") or ""), reverse=True)
|
|
188
|
-
if q.count_only and q.limit is not None:
|
|
189
|
-
raise Fail("--count-only 与 --limit 不能同时用:计数不截断,列表才截断。")
|
|
190
|
-
limit: int | None = None
|
|
191
|
-
if q.limit is not None:
|
|
192
|
-
limit = int(q.limit)
|
|
193
|
-
if limit < 1:
|
|
194
|
-
raise Fail(f"--limit 必须 ≥ 1(收到 {limit})。")
|
|
195
|
-
capped = False
|
|
196
|
-
if q.count_only and len(records) > COUNT_CAP:
|
|
197
|
-
capped = True
|
|
198
|
-
records = records[:COUNT_CAP]
|
|
199
|
-
elif limit is not None:
|
|
200
|
-
capped = len(records) > limit # 截断了要让调用方知道「还有更多」
|
|
201
|
-
records = records[:limit]
|
|
202
|
-
|
|
203
|
-
filters = {
|
|
204
|
-
"owner": q.owner,
|
|
205
|
-
"owner_name": q.owner_name,
|
|
206
|
-
"mine": q.mine,
|
|
207
|
-
"category": q.category,
|
|
208
|
-
"tag": q.tag,
|
|
209
|
-
"since": q.since,
|
|
210
|
-
"until": q.until,
|
|
211
|
-
"limit": q.limit,
|
|
212
|
-
"months": q.months,
|
|
213
|
-
}
|
|
214
|
-
return HistoryResult(
|
|
215
|
-
count=len(records),
|
|
216
|
-
filters=filters,
|
|
217
|
-
records=tuple(records),
|
|
218
|
-
warnings=tuple(warnings),
|
|
219
|
-
capped=capped,
|
|
220
|
-
)
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"""动作名册:命令写法 → `ActionSpec`。只有 `shell/cli.py` 与 `shell/runner.py` 会 import 它。
|
|
2
|
-
|
|
3
|
-
**渲染函数只存名字**,不 import `shell/render.py` —— 否则 actions → shell 的依赖就反了;
|
|
4
|
-
由 runner 用 `getattr(render, spec.render)` 取到函数。
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
from collections.abc import Callable
|
|
10
|
-
from dataclasses import dataclass, field
|
|
11
|
-
|
|
12
|
-
from ..errors import Fail
|
|
13
|
-
from . import (
|
|
14
|
-
bootstrap,
|
|
15
|
-
claim,
|
|
16
|
-
close_task,
|
|
17
|
-
list_tasks,
|
|
18
|
-
log_progress,
|
|
19
|
-
new_task,
|
|
20
|
-
query_history,
|
|
21
|
-
set_task,
|
|
22
|
-
show_task,
|
|
23
|
-
validate,
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@dataclass(frozen=True)
|
|
28
|
-
class ActionSpec:
|
|
29
|
-
func: Callable # (repo, me, **params) -> Result | 视图对象
|
|
30
|
-
render: str # 渲染函数**名**;runner 用 getattr 取
|
|
31
|
-
readonly: bool = False
|
|
32
|
-
lock_action: str = "" # 交给 lock_scope 的动作名;默认同命令名
|
|
33
|
-
params: tuple[str, ...] = field(default=()) # 从参数里挑哪些键传给 func
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
ACTIONS: dict[str, ActionSpec] = {
|
|
37
|
-
"new": ActionSpec(
|
|
38
|
-
new_task.new_task,
|
|
39
|
-
"result",
|
|
40
|
-
params=("title", "tid", "created", "category", "tags", "mine"),
|
|
41
|
-
),
|
|
42
|
-
"claim": ActionSpec(claim.claim, "result", params=("tid",)),
|
|
43
|
-
"set": ActionSpec(
|
|
44
|
-
set_task.set_task,
|
|
45
|
-
"result",
|
|
46
|
-
params=("tid", "owner", "release", "tags"),
|
|
47
|
-
lock_action="set",
|
|
48
|
-
),
|
|
49
|
-
"log": ActionSpec(log_progress.log_progress, "result", params=("tid", "note")),
|
|
50
|
-
"close": ActionSpec(
|
|
51
|
-
close_task.close_task,
|
|
52
|
-
"result",
|
|
53
|
-
params=("tid", "summary", "finished", "tags"),
|
|
54
|
-
),
|
|
55
|
-
"list": ActionSpec(
|
|
56
|
-
list_tasks.list_tasks, "list_view", readonly=True, params=("q",)
|
|
57
|
-
),
|
|
58
|
-
"show": ActionSpec(
|
|
59
|
-
show_task.show_task, "show_view", readonly=True, params=("tid",)
|
|
60
|
-
),
|
|
61
|
-
"history": ActionSpec(
|
|
62
|
-
query_history.query_history, "history_view", readonly=True, params=("q",)
|
|
63
|
-
),
|
|
64
|
-
"validate": ActionSpec(
|
|
65
|
-
validate.validate, "validate_view", readonly=True, params=("deep",)
|
|
66
|
-
),
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
READONLY = tuple(name for name, spec in ACTIONS.items() if spec.readonly)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def spec_of(command: str) -> ActionSpec:
|
|
73
|
-
"""按命令写法取名册项;不在名册里就是用法错(业务错,退 1 人话)。"""
|
|
74
|
-
spec = ACTIONS.get(command)
|
|
75
|
-
if spec is None:
|
|
76
|
-
raise Fail(f"未知命令:{command}")
|
|
77
|
-
return spec
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def bootstrap_func():
|
|
81
|
-
"""自举不是名册里的命令(runner 单独调),这里只给它的入口,避免 shell 直接 import 动作。"""
|
|
82
|
-
return bootstrap.bootstrap
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"""改标签:分片 `tags` + 过程文档头部标签行,一次写两处。
|
|
2
|
-
|
|
3
|
-
**分类不可改**(2026-10-27 用户拍板):它在 `new` 时定死,之后没有任何入口能改 —
|
|
4
|
-
不进过程文档、不进 `set` / `close` 参数;历史行里那个值就是建任务时那个值。
|
|
5
|
-
|
|
6
|
-
只动「标签」这一件事,不碰归属与状态 —— 归属走 `--owner` / `--release`,
|
|
7
|
-
状态只随命令语义变。已结案的任务不在任何分片里,改不了(历史行是快照)。
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
from __future__ import annotations
|
|
11
|
-
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
|
|
14
|
-
from ..core.identity import Identity
|
|
15
|
-
from ..core.labels import parse_tags
|
|
16
|
-
from ..core.paths import shard_rel
|
|
17
|
-
from ..core.time import now
|
|
18
|
-
from ..core.worklog_md import (
|
|
19
|
-
StatusLine,
|
|
20
|
-
append_exec_log,
|
|
21
|
-
exec_line,
|
|
22
|
-
rewrite_label_line,
|
|
23
|
-
rewrite_status_line,
|
|
24
|
-
)
|
|
25
|
-
from ..errors import Fail
|
|
26
|
-
from ..store.task_store import TaskStore
|
|
27
|
-
from ..store.worklog_store import WorklogStore
|
|
28
|
-
from .guard import require_owner
|
|
29
|
-
from .result import Result, rel
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def relabel(
|
|
33
|
-
repo: Path,
|
|
34
|
-
me: Identity,
|
|
35
|
-
tid: str,
|
|
36
|
-
*,
|
|
37
|
-
tags: str | tuple[str, ...] | None = None,
|
|
38
|
-
) -> Result:
|
|
39
|
-
"""写序:算最终值 → 过程文档(标签行 + 执行记录 + 状态行,一次写)→ 分片。
|
|
40
|
-
|
|
41
|
-
`tags` 收字符串(顿号 / 逗号分隔)或已切好的元组 —— 外壳可能已经切过一遍。
|
|
42
|
-
"""
|
|
43
|
-
new_tags = parse_tags(tags) if tags else None
|
|
44
|
-
if new_tags is None:
|
|
45
|
-
raise Fail("改标签要给 `--tags <a、b>`。")
|
|
46
|
-
|
|
47
|
-
mine = TaskStore(repo, shard_rel(me.uuid), identity=me)
|
|
48
|
-
task = mine.get(tid) # 锁内重读
|
|
49
|
-
if task is None:
|
|
50
|
-
raise Fail(
|
|
51
|
-
f"任务 {tid} 不在我的分片里(只能改自己名下在办的任务;已结案的任务改不了)。"
|
|
52
|
-
)
|
|
53
|
-
require_owner(task, tid, me)
|
|
54
|
-
|
|
55
|
-
final_tags: list[str] = [str(tag) for tag in new_tags]
|
|
56
|
-
if not final_tags:
|
|
57
|
-
raise Fail("标签是空的,没有可写的值。")
|
|
58
|
-
|
|
59
|
-
when = now()
|
|
60
|
-
updated = dict(task)
|
|
61
|
-
updated["tags"] = final_tags
|
|
62
|
-
updated["updated"] = when
|
|
63
|
-
|
|
64
|
-
logs = WorklogStore(repo)
|
|
65
|
-
path = logs.find(tid, task.get("worklog"))
|
|
66
|
-
if path is None:
|
|
67
|
-
mine.put(tid, updated)
|
|
68
|
-
return Result(
|
|
69
|
-
changed=("tags", "updated"),
|
|
70
|
-
where=rel(repo, mine.path),
|
|
71
|
-
message=f"{tid}:改标签",
|
|
72
|
-
notices=("提示:这条任务没有过程文档,只改了分片,文档与历史里看不到。",),
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
text = logs.read(path)
|
|
76
|
-
note = "改标签:" + "、".join(final_tags)
|
|
77
|
-
text = rewrite_label_line(text, final_tags)
|
|
78
|
-
text = append_exec_log(text, exec_line(when, me.stamp(), "set", note))
|
|
79
|
-
text = rewrite_status_line(
|
|
80
|
-
text, StatusLine(task.get("status") or "doing", me.name, me.uuid, when)
|
|
81
|
-
)
|
|
82
|
-
logs.write(path, text)
|
|
83
|
-
mine.put(tid, updated)
|
|
84
|
-
|
|
85
|
-
return Result(
|
|
86
|
-
changed=("tags", "updated"),
|
|
87
|
-
where=rel(repo, mine.path),
|
|
88
|
-
message=f"{tid}:改标签",
|
|
89
|
-
)
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"""释放:写回公共池,再删我分片那行,再记一笔。"""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
from ..core.identity import Identity
|
|
8
|
-
from ..core.paths import POOL_REL, shard_rel
|
|
9
|
-
from ..core.time import now
|
|
10
|
-
from ..core.worklog_md import StatusLine, exec_line
|
|
11
|
-
from ..errors import Fail
|
|
12
|
-
from ..store.task_store import TaskStore
|
|
13
|
-
from ..store.worklog_store import WorklogStore
|
|
14
|
-
from .guard import owner_of, require_owner, status_of
|
|
15
|
-
from .result import Result, rel
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def release(repo: Path, me: Identity, tid: str) -> Result:
|
|
19
|
-
"""写序:写回池(已有同号就不覆盖)→ 删我分片那行 → 过程文档记一笔。"""
|
|
20
|
-
pool = TaskStore(repo, POOL_REL)
|
|
21
|
-
mine = TaskStore(repo, shard_rel(me.uuid), identity=me)
|
|
22
|
-
task = mine.get(tid) # 锁内重读
|
|
23
|
-
if task is None:
|
|
24
|
-
in_pool = pool.get(tid)
|
|
25
|
-
if in_pool is not None:
|
|
26
|
-
# 幂等分支也要验「池里那条真的已经是没人要的开放任务」,
|
|
27
|
-
# 否则池里混进带 owner 的脏行时,release 会报「无需重复释放」而任务实际仍被占
|
|
28
|
-
if owner_of(in_pool) or status_of(in_pool) != "open":
|
|
29
|
-
raise Fail(
|
|
30
|
-
f"任务 {tid} 在公共池里,但身上还挂着 owner / 不是 open —— 台账脏了。\n"
|
|
31
|
-
" 处理:跑 validate 看清单,别用 release 强行覆盖。"
|
|
32
|
-
)
|
|
33
|
-
return Result(
|
|
34
|
-
already_done=True,
|
|
35
|
-
where=rel(repo, pool.path),
|
|
36
|
-
notices=(f"任务 {tid} 已经在公共池里,无需重复释放。",),
|
|
37
|
-
)
|
|
38
|
-
raise Fail(f"任务 {tid} 不在我的分片里,也没在公共池里。")
|
|
39
|
-
|
|
40
|
-
# 分片里在、但行内 owner 不是我 ⇒ 台账脏了(validate ⑤):不许把别人的行推进池
|
|
41
|
-
require_owner(task, tid, me)
|
|
42
|
-
|
|
43
|
-
back = dict(task)
|
|
44
|
-
back["owner"] = None
|
|
45
|
-
back["owner_name"] = None # 冗余显示名跟着 owner 一起清,否则池里那条仍显示原负责人
|
|
46
|
-
back["status"] = "open"
|
|
47
|
-
back["updated"] = now()
|
|
48
|
-
if pool.get(tid) is None:
|
|
49
|
-
pool.put(tid, back)
|
|
50
|
-
else:
|
|
51
|
-
# 池里已有同号:那份必须是干净的空位,否则不写回(它的 owner/owner_name 会被旧值带脏)
|
|
52
|
-
existing = pool.get(tid) or {}
|
|
53
|
-
if owner_of(existing) or status_of(existing) != "open":
|
|
54
|
-
raise Fail(
|
|
55
|
-
f"公共池里已经有一条 {tid},且它带着 owner / 不是 open —— 台账脏了。\n"
|
|
56
|
-
" 处理:跑 validate 看清单,先确认哪条是真的。"
|
|
57
|
-
)
|
|
58
|
-
mine.drop(tid)
|
|
59
|
-
|
|
60
|
-
logs = WorklogStore(repo)
|
|
61
|
-
path = logs.find(tid, back.get("worklog"))
|
|
62
|
-
note = None
|
|
63
|
-
if path is None:
|
|
64
|
-
note = f"任务 {tid} 已退回公共池,但过程文档没找到,跳过执行记录。"
|
|
65
|
-
else:
|
|
66
|
-
logs.append_exec(
|
|
67
|
-
path,
|
|
68
|
-
exec_line(now(), me.stamp(), "release", "释放回公共池"),
|
|
69
|
-
status=StatusLine("open", None, None, now()),
|
|
70
|
-
)
|
|
71
|
-
return Result(
|
|
72
|
-
changed=("owner", "owner_name", "status", "updated"),
|
|
73
|
-
where=rel(repo, pool.path),
|
|
74
|
-
message=f"释放 {tid}:{back.get('title') or ''}".strip(),
|
|
75
|
-
notices=(note,) if note else (),
|
|
76
|
-
)
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"""动作的返回值长什么样。字段名是**公开契约**,插件看板直接读,外壳不许重新算。
|
|
2
|
-
|
|
3
|
-
写动作返回 `Result`,只读动作返回各自的视图对象(不再套一层统一的壳)。
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from dataclasses import dataclass, field
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
from typing import Any
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def rel(repo: Path, path: Path) -> str:
|
|
14
|
-
"""绝对路径 → 相对 repo 的字符串(输出给人 / 给界面的一律这个基准)。"""
|
|
15
|
-
try:
|
|
16
|
-
return str(Path(path).resolve().relative_to(Path(repo).resolve()))
|
|
17
|
-
except ValueError:
|
|
18
|
-
return str(path)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@dataclass(frozen=True)
|
|
22
|
-
class WorklogView:
|
|
23
|
-
"""「这条任务的过程文档要怎么显示」。"""
|
|
24
|
-
|
|
25
|
-
path: str | None = None # 相对 repo
|
|
26
|
-
text: str | None = None # 全文;读不到时为 None
|
|
27
|
-
error: str | None = None # 读不到的原因(缺失 / 读不了),给人看
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@dataclass(frozen=True)
|
|
31
|
-
class Result:
|
|
32
|
-
"""写动作的返回。"""
|
|
33
|
-
|
|
34
|
-
changed: tuple[str, ...] = () # 改了哪些**字段名**(不是文件名、不是任务号)
|
|
35
|
-
where: str | None = None # 主要落在哪个文件(**相对 repo**)
|
|
36
|
-
already_done: bool = False # 重跑发现已经做过 ⇒ 退出码仍是 0
|
|
37
|
-
message: str | None = None # git 提交说明;None ⇒ 外壳用默认模板
|
|
38
|
-
worklog: WorklogView | None = None
|
|
39
|
-
payload: dict[str, Any] = field(default_factory=dict)
|
|
40
|
-
notices: tuple[str, ...] = ()
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
@dataclass(frozen=True)
|
|
44
|
-
class TaskRow:
|
|
45
|
-
"""人话表格的一行(9 字段投影)。`--json` 吐的是 `rows`(原样任务对象),不是它。"""
|
|
46
|
-
|
|
47
|
-
tid: str
|
|
48
|
-
title: str
|
|
49
|
-
status: str
|
|
50
|
-
owner: str | None = None # 显示名
|
|
51
|
-
created: str | None = None
|
|
52
|
-
started: str | None = None
|
|
53
|
-
category: str | None = None
|
|
54
|
-
tags: tuple[str, ...] = ()
|
|
55
|
-
where: str | None = None # 所在文件(相对 repo)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@dataclass(frozen=True)
|
|
59
|
-
class ListResult:
|
|
60
|
-
rows: dict[str, dict[str, Any]] = field(default_factory=dict) # tid → 原样任务对象
|
|
61
|
-
table: tuple[TaskRow, ...] = ()
|
|
62
|
-
notices: tuple[str, ...] = ()
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@dataclass(frozen=True)
|
|
66
|
-
class ShowResult:
|
|
67
|
-
task: dict[str, Any] = field(default_factory=dict)
|
|
68
|
-
worklog: WorklogView | None = None
|
|
69
|
-
others: tuple[str, ...] = () # 同一个任务号还出现在哪些文件里
|
|
70
|
-
#: 字段是从**在办索引**读来的(老文档没有状态行 / 文档丢了),不是文档自述
|
|
71
|
-
legacy: bool = False
|
|
72
|
-
notices: tuple[str, ...] = ()
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
@dataclass(frozen=True)
|
|
76
|
-
class HistoryResult:
|
|
77
|
-
count: int = 0
|
|
78
|
-
filters: dict[str, Any] = field(default_factory=dict) # 回显生效的筛选
|
|
79
|
-
records: tuple[dict[str, Any], ...] = ()
|
|
80
|
-
warnings: tuple[str, ...] = ()
|
|
81
|
-
capped: bool = False
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@dataclass(frozen=True)
|
|
85
|
-
class ValidationReport:
|
|
86
|
-
problems: tuple[str, ...] = () # 只有它影响退出码
|
|
87
|
-
notices: tuple[str, ...] = () # 只提示,不改退出码
|
|
88
|
-
checked_files: int = 0
|
|
89
|
-
total_tasks: int = 0
|
|
90
|
-
deep: bool = False # 本次是深度检查(--deep)还是默认浅度
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"""改归属 / 改标签的入口:决定走哪个动作,**自己不加锁、不改任何文件**。
|
|
2
|
-
|
|
3
|
-
它是全树唯一的跨动作引用点(import `release` / `handoff` / `claim` / `relabel`)。
|
|
4
|
-
|
|
5
|
-
任务状态只随命令语义变(认领 → 进行中、释放 → 待认领、结案 → 历史),
|
|
6
|
-
**没有单独的「改状态」入口**:`--status` 于 2026-10-23 删除 —— 全仓没有任何
|
|
7
|
-
产品调用方(看板只有 claim / release / close 三个写路由),且它能制造
|
|
8
|
-
:「归我名下、状态却还是待认领」的坏状态(看板上显示成没人认领)。
|
|
9
|
-
|
|
10
|
-
**也没有改分类的入口**(2026-10-27 删除 `--category`):分类在 `new` 时定死,
|
|
11
|
-
之后谁都改不了;标题与创建时间同理,建完即不可变。`--tags` 仍可随时改。
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
from __future__ import annotations
|
|
15
|
-
|
|
16
|
-
from pathlib import Path
|
|
17
|
-
|
|
18
|
-
from ..core.identity import Identity, is_me
|
|
19
|
-
from ..core.paths import shard_rel
|
|
20
|
-
from ..errors import Fail
|
|
21
|
-
from ..store.task_store import TaskStore
|
|
22
|
-
from . import claim as claim_mod
|
|
23
|
-
from . import handoff as handoff_mod
|
|
24
|
-
from . import relabel as relabel_mod
|
|
25
|
-
from . import release as release_mod
|
|
26
|
-
from .guard import require_uuid
|
|
27
|
-
from .result import Result, rel
|
|
28
|
-
|
|
29
|
-
_MIXED = "--tags 与 --release / --owner 不能同给:一个改标签,一个改归属。"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def set_task(
|
|
33
|
-
repo: Path,
|
|
34
|
-
me: Identity,
|
|
35
|
-
tid: str,
|
|
36
|
-
*,
|
|
37
|
-
owner: str | None = None,
|
|
38
|
-
release: bool = False,
|
|
39
|
-
tags: str | tuple[str, ...] | None = None,
|
|
40
|
-
) -> Result:
|
|
41
|
-
"""路由:`--release` = 释放;别人的 uuid = 交接;自己的 uuid = 已认领则空转、没认领先认领;
|
|
42
|
-
`--tags` = 改标签(写分片 + 过程文档头部标签行)。
|
|
43
|
-
"""
|
|
44
|
-
if release:
|
|
45
|
-
if owner is not None:
|
|
46
|
-
raise Fail("--release 与 --owner 不能同时给:释放不带人,交接不带释放。")
|
|
47
|
-
if tags:
|
|
48
|
-
raise Fail(_MIXED)
|
|
49
|
-
return release_mod.release(repo, me, tid)
|
|
50
|
-
if owner is not None:
|
|
51
|
-
if tags:
|
|
52
|
-
raise Fail(_MIXED)
|
|
53
|
-
else:
|
|
54
|
-
if tags:
|
|
55
|
-
return relabel_mod.relabel(repo, me, tid, tags=tags)
|
|
56
|
-
raise Fail(
|
|
57
|
-
"set 必须给一样:`--release`(释放回公共池)/ `--owner <对方 uuid>`(交接)/ "
|
|
58
|
-
"`--tags <a、b>`(改标签)。"
|
|
59
|
-
)
|
|
60
|
-
# 交接目标只收 uuid:名字查不到就当场报错,绝不去猜「他大概是这个人」
|
|
61
|
-
target = require_uuid(owner, field="--owner")
|
|
62
|
-
if not is_me(me, target):
|
|
63
|
-
return handoff_mod.handoff(repo, me, tid, to=target)
|
|
64
|
-
mine = TaskStore(repo, shard_rel(me.uuid), identity=me)
|
|
65
|
-
if mine.get(tid) is not None:
|
|
66
|
-
return Result(
|
|
67
|
-
already_done=True,
|
|
68
|
-
where=rel(repo, mine.path),
|
|
69
|
-
notices=(f"任务 {tid} 已经在你名下,无需操作。",),
|
|
70
|
-
)
|
|
71
|
-
return claim_mod.claim(repo, me, tid)
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"""只读:看一条任务。**文档优先**——读到文档就知道状态,不再翻索引(2026-10-27)。
|
|
2
|
-
|
|
3
|
-
两条路径:
|
|
4
|
-
- 文档存在且头部有状态行 ⇒ 完全按文档自述回答(`status` / 负责人 / 更新时间 / 标题),
|
|
5
|
-
pool、分片、历史一个都不读,已结案的任务同样看得到;
|
|
6
|
-
- 文档没有状态行(老文档)或根本没有文档 ⇒ 回退 `load_task` 查在办索引,
|
|
7
|
-
返回里标 `legacy=True`,让调用方知道这些字段不是文档自述的。
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
from __future__ import annotations
|
|
11
|
-
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
|
|
14
|
-
from ..core import worklog_md
|
|
15
|
-
from ..core.identity import Identity
|
|
16
|
-
from ..store.worklog_store import WorklogStore
|
|
17
|
-
from .guard import load_task
|
|
18
|
-
from .result import ShowResult, WorklogView, rel
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def show_task(repo: Path, me: Identity, tid: str) -> ShowResult:
|
|
22
|
-
logs = WorklogStore(repo)
|
|
23
|
-
path = logs.find(tid) # 只按任务号找文件名:不碰 pool / 分片 / 历史
|
|
24
|
-
text = logs.read(path) if path is not None else ""
|
|
25
|
-
status = worklog_md.read_status(text) if text else None
|
|
26
|
-
if status is not None and path is not None:
|
|
27
|
-
head_tid, title = worklog_md.head_title(text)
|
|
28
|
-
return ShowResult(
|
|
29
|
-
task={
|
|
30
|
-
"tid": head_tid or tid,
|
|
31
|
-
"title": title,
|
|
32
|
-
"status": status.status,
|
|
33
|
-
"owner": status.uuid,
|
|
34
|
-
"owner_name": status.name,
|
|
35
|
-
"created": worklog_md.head_created(text),
|
|
36
|
-
"updated": status.when,
|
|
37
|
-
"finished": worklog_md.head_frozen(text),
|
|
38
|
-
},
|
|
39
|
-
worklog=WorklogView(path=rel(repo, path), text=text, error=None),
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
# 老文档 / 文档缺失:回退查在办(找不到会抛,文案与既往一致)
|
|
43
|
-
task, where = load_task(repo, tid)
|
|
44
|
-
if path is None:
|
|
45
|
-
view = WorklogView(
|
|
46
|
-
path=None, text=None, error="这条任务没有过程文档(或文档已不在原处)。"
|
|
47
|
-
)
|
|
48
|
-
else:
|
|
49
|
-
view = WorklogView(path=rel(repo, path), text=text or None, error=None)
|
|
50
|
-
return ShowResult(
|
|
51
|
-
task=task,
|
|
52
|
-
worklog=view,
|
|
53
|
-
others=tuple(rel(repo, p) for p in where),
|
|
54
|
-
legacy=True,
|
|
55
|
-
)
|