task-ledger 1.3.22 → 1.3.24
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 +2 -2
- package/SKILL.md +43 -13
- package/assets/worklog.md +5 -2
- package/package.json +1 -1
- package/references/state-model.md +6 -1
- package/references/troubleshooting.md +5 -5
- package/scripts/ledgerkit/actions/claim.py +7 -2
- package/scripts/ledgerkit/actions/close_task.py +8 -0
- package/scripts/ledgerkit/actions/handoff.py +5 -2
- package/scripts/ledgerkit/actions/list_tasks.py +4 -1
- package/scripts/ledgerkit/actions/log_progress.py +6 -2
- package/scripts/ledgerkit/actions/new_task.py +7 -1
- package/scripts/ledgerkit/actions/query_history.py +3 -1
- package/scripts/ledgerkit/actions/release.py +6 -2
- package/scripts/ledgerkit/actions/result.py +2 -0
- package/scripts/ledgerkit/actions/show_task.py +32 -4
- package/scripts/ledgerkit/actions/validate.py +6 -49
- package/scripts/ledgerkit/core/identity.py +3 -3
- package/scripts/ledgerkit/core/labels.py +16 -4
- package/scripts/ledgerkit/core/time.py +2 -1
- package/scripts/ledgerkit/core/worklog_md.py +216 -31
- package/scripts/ledgerkit/shell/cli.py +24 -2
- package/scripts/ledgerkit/shell/render.py +48 -4
- package/scripts/ledgerkit/store/worklog_store.py +17 -5
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
## 为什么这么设计
|
|
26
26
|
|
|
27
|
-
跨项目固定用 `ledger/`(不占项目的 `docs/`);状态用 JSON 而非 Markdown
|
|
27
|
+
跨项目固定用 `ledger/`(不占项目的 `docs/`);状态用 JSON 而非 Markdown(改动面最小);状态与过程正文分离(互不踩);一人一份分片把并发冲突面从整份文件缩到公共池里几行;**所有存盘时间(含过程文档里的日志行)一律 UTC**,脚本输出时统一转本机时区(人话与 `--json` 一致)。
|
|
28
28
|
|
|
29
29
|
## 怎么用(执行规则在 SKILL.md)
|
|
30
30
|
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
python3 <SKILL.md 所在目录>/scripts/progress.py <子命令> --repo <工作区根>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
子命令:`new` `claim` `set` `log` `close` `list` `history` `show` `validate`。命令参考(参数 / 一句话 / 举例)、任务生命周期、纪律(数据完整性 / 人类授权 / 故障处置)全在 `SKILL.md`;参数细节看 `<子命令> --help`(不要凭记忆编)。
|
|
37
|
+
子命令:`new` `claim` `set` `log` `close` `list` `history` `show` `whoami` `validate`。命令参考(参数 / 一句话 / 举例)、任务生命周期、纪律(数据完整性 / 人类授权 / 故障处置)全在 `SKILL.md`;参数细节看 `<子命令> --help`(不要凭记忆编)。
|
|
38
38
|
|
|
39
39
|
## 深入参考(references/,按需读)
|
|
40
40
|
|
package/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: task-ledger
|
|
3
3
|
description: 本地任务台账,跨会话记录在办任务的归属、进度与起止。当用户要登记一件新的事(新建任务 / 建个坑 / 这活我领了)、记录已有任务的进展(接着做 / 记一条进展 / 这轮先记下)、查看任务状态或历史(现在该做什么 / 这活谁在做 / 上周做过什么)、给任务结案或退回(做完了 / 验收通过 / 不做了 / 退回待认领)、整理标签或检查台账一致性时加载;只是改代码、讨论方案时不要用。
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.24
|
|
5
5
|
allowed-tools: Read,Edit,Bash,Grep
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -21,11 +21,11 @@ allowed-tools: Read,Edit,Bash,Grep
|
|
|
21
21
|
|
|
22
22
|
- **唯一能手写的是任务的过程文档(worklog)前五节**(怎么写见「过程文档」节);末节「执行记录」由脚本维护,**禁止手写、禁止手工添加**。
|
|
23
23
|
- **其他所有文件一律不许手改**:修改 / 删除 / 任何操作都走命令;手改台账文件即数据损坏。
|
|
24
|
-
- 台账看着不对劲(任务凭空少了、状态怪、分片对不上)⇒ **不要动手修**:让用户跑 `validate
|
|
24
|
+
- 台账看着不对劲(任务凭空少了、状态怪、分片对不上)⇒ **不要动手修**:让用户跑 `validate`(老月份的历史也要查就跑 `validate --deep`),把清单交给用户。
|
|
25
25
|
|
|
26
26
|
## 命令参考
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
十一个子命令:`init`(初始化本机身份,一台机器一次)+ 前五个写命令(`new`/`claim`/`set`/`log`/`close`)+ 后五个只读命令(`list` / `show` / `history` / `whoami` / `validate`);何时用哪个见「任务生命周期」。参数语法看 `<子命令> --help`;下表说每个参数干什么、何时用。
|
|
29
29
|
|
|
30
30
|
### init — 初始化本机身份
|
|
31
31
|
|
|
@@ -110,7 +110,7 @@ allowed-tools: Read,Edit,Bash,Grep
|
|
|
110
110
|
| `--status open\|doing` | 按状态筛(逗号分隔可多选;合法值只有 `open` / `doing`) |
|
|
111
111
|
| `--category` / `--tag` | 按分类(精确)/ 标签(包含)筛 |
|
|
112
112
|
| `--since` / `--until` | 按创建时间筛(只给日期含当天) |
|
|
113
|
-
| `--json` | 输出 JSON(`{任务号: 任务对象}
|
|
113
|
+
| `--json` | 输出 JSON(`{任务号: 任务对象}`);**每行带 `mine`**(是不是自己名下的,只比 uuid) |
|
|
114
114
|
|
|
115
115
|
干什么:合并公共池 + 各人名下的任务,列出在办。**默认就是全量**,没有 `--all` 参数;收窄用 `--mine` / `--pool`。
|
|
116
116
|
|
|
@@ -120,10 +120,10 @@ allowed-tools: Read,Edit,Bash,Grep
|
|
|
120
120
|
|
|
121
121
|
| 参数 | 含义 |
|
|
122
122
|
|---|---|
|
|
123
|
-
| `--id <任务号>` |
|
|
124
|
-
| `--json` |
|
|
123
|
+
| `--id <任务号>` | 看哪条(必填;谁名下的、在办还是已结案都能看) |
|
|
124
|
+
| `--json` | 任务字段 + 过程文档全文一起给(人话模式只给路径) |
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
干什么:**看一条 = 任务字段 + 过程文档全文**,一次拿全;已结案的任务同样能看,不必先查 `history`。`--json` 里 `legacy: true` 表示这些字段是回退查在办得到的(老文档没有状态行)。
|
|
127
127
|
|
|
128
128
|
举例:「这个任务到哪一步了」→ `show --id <任务号> --json`。
|
|
129
129
|
|
|
@@ -138,12 +138,32 @@ allowed-tools: Read,Edit,Bash,Grep
|
|
|
138
138
|
| `--months N` | 最近 N 个自然月(与 `--since` / `--until` **互斥**,同传直接报错) |
|
|
139
139
|
| `--limit N` | 最近 N 条 |
|
|
140
140
|
| `--count-only` | 只输出 `{"count","capped"}`(与 `--json`、`--limit` 都互斥) |
|
|
141
|
-
| `--json` | JSON
|
|
141
|
+
| `--json` | JSON 输出;**每条记录带 `mine`**(是不是自己结的,只比 uuid) |
|
|
142
142
|
|
|
143
143
|
干什么:按结案时间倒序排列,每条一行,只列结案时间、负责人、标题,其他都不在表格里;要摘要 / 分类 / 标签 / 完整时间加 `--json`。不给时间参数 = 最近 3 个自然月;最多 13 个月,超了直接报错。
|
|
144
144
|
|
|
145
145
|
举例:「上周做过什么」→ `history --since <上周一日期>`;「今年都结掉哪些」→ `history --months 12`(超过 13 个月要分段查)。
|
|
146
146
|
|
|
147
|
+
### whoami — 我是谁
|
|
148
|
+
|
|
149
|
+
| 参数 | 含义 |
|
|
150
|
+
|---|---|
|
|
151
|
+
| (无) | 打印本机身份:`@名字 uuid` |
|
|
152
|
+
| `--json` | `{"uuid","name"}`;**未初始化给双 null**(照常退 0,不是错误) |
|
|
153
|
+
|
|
154
|
+
干什么:本机身份的只读查询,**不依赖 `--repo`、不写任何文件**,回答「这台机器上我是谁」。判断要不要引导用户 `init` 就看这条命令,别去解析 `~/.taskledger/identity.json`。
|
|
155
|
+
|
|
156
|
+
举例:`whoami --json` 拿到 `uuid` 是 `null` ⇒ 这台机器还没初始化身份,先引导用户跑 `init`。
|
|
157
|
+
|
|
158
|
+
### validate — 台账体检
|
|
159
|
+
|
|
160
|
+
| 参数 | 含义 |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `--deep` | 历史读全部月份(默认只读当月那个月文件) |
|
|
163
|
+
| `--json` | `{"problems","notices","checked_files","total_tasks","deep"}` |
|
|
164
|
+
|
|
165
|
+
干什么:只读体检,查公共池 + 各分片的字段格式、索引与文件对不对得上、历史格式。**不读过程文档正文**(浅度 / 深度都不读)。查出问题时退 1 —— 把清单原样交给用户,agent 不自行修。
|
|
166
|
+
|
|
147
167
|
## 怎么调用
|
|
148
168
|
|
|
149
169
|
```bash
|
|
@@ -152,7 +172,8 @@ python3 <本 SKILL.md 所在目录>/scripts/progress.py <子命令> --repo <工
|
|
|
152
172
|
|
|
153
173
|
- 定位项目:`--repo <工作区根>`(**直接含有 `ledger/` 的那个目录**)给了就校验后用;不给就从当前目录逐级向上找。`ledger/` 本身、以及它下面的任何子目录都不是根,指过去会被直接拒绝(判据只看位置,不看目录里有哪些文件 —— 项目根自带 `pool.json`、`history/`、`worklog/` 都不影响)。
|
|
154
174
|
- `--no-sync`(放在子命令**前**):用户明确要求「先别同步」时才用;之后自己 `git add ledger && commit && push`。
|
|
155
|
-
- `--json` 只对只读命令(`list` / `show` / `history` / `validate`)有意义;写命令不接收 `--json
|
|
175
|
+
- `--json` 只对只读命令(`list` / `show` / `history` / `whoami` / `validate`)有意义;写命令不接收 `--json`,传了是用法错。
|
|
176
|
+
- **时间**:存盘一律 UTC,脚本对外**一律给本机时区**(人话表格与 `--json` 都是),拿到直接显示,不要再转一次;`--since` / `--until` / `--created` / `--finished` 也按本机时区给,脚本内部转 UTC 比较。过程文档正文里的时间是原文,脚本不碰。
|
|
156
177
|
- 命令回执只用来确认生效;任务状态以 `show` / `list` 为准。
|
|
157
178
|
|
|
158
179
|
## 任务生命周期
|
|
@@ -186,15 +207,24 @@ python3 <本 SKILL.md 所在目录>/scripts/progress.py <子命令> --repo <工
|
|
|
186
207
|
|
|
187
208
|
- 「执行记录」节名一个字都别动;老文档缺这一节也不用补。
|
|
188
209
|
- 过程文档找不到时 `log` 只提示不失败;用 `show` 查路径,不要手写。
|
|
189
|
-
-
|
|
190
|
-
|
|
210
|
+
- 头部是四行,由脚本维护、**都不要手改**,顺序固定 `分类/标签 → 状态 → 创建 → 封卷`,值一律 `· ` 分隔:
|
|
211
|
+
|
|
212
|
+
```markdown
|
|
213
|
+
- **分类**:建设 · **标签**:DSH、台账
|
|
214
|
+
- **状态**:doing · 2026-10-27 09:12:33 · @某人 · 8d557c6d-…
|
|
215
|
+
- **创建**:2026-10-26 23:38:02 · @某人 · 8d557c6d-…
|
|
216
|
+
- **封卷**:2026-10-27 09:20:10 · @某人 · 8d557c6d-…
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
分类 / 标签行与封卷行不一定有(没给分类、没结案就没有)。老文档没有状态行是合法的(`show` 回退查在办,`--json` 标 `legacy: true`),不用补。
|
|
220
|
+
- 执行记录行格式 `- 时间(UTC) · 类型 · @谁 · 说明`,`@谁` 是这次动手的人、不是任务现归属;只追加、不改旧行。行首「类型」是脚本内部动作名(会见到 `release`,它就是 `set --release`);认不出就别当成新命令,按 `--help` 查。
|
|
191
221
|
- 只改某条任务的正文:`show --id <任务号>` 拿路径直接改,不另建 md;已结案的用 `history --months 12 --json` 找回链接(**人话输出里没有链接,必须加 `--json`**)——默认只查近 3 个月,结案久了的要显式放大窗口;只读不改。
|
|
192
222
|
|
|
193
223
|
### 收工三步(「收工」= 这一轮对用户有可见产出)
|
|
194
224
|
|
|
195
225
|
1. 改正文:这轮变化的事实都落笔,「下一步」写具体动作。
|
|
196
226
|
2. 跑 `log`:这一轮只要改过正文就必须记(一轮至少一条;纪律见下文)。正文没变也能记一条推进,但要同时重写「下一步」。
|
|
197
|
-
3. 回读末行(`tail -n 3 <路径>`):说明 =
|
|
227
|
+
3. 回读末行(`tail -n 3 <路径>`):说明 = 这轮的事。执行记录行的时间是 **UTC**(比本机本地时间早若干小时,看时差别以为没记上)。
|
|
198
228
|
|
|
199
229
|
**什么算一个节点**:明天自己想不起来、或换个人接手会看不出的事,就记一条;一次状态 / 结论变化对应一条,不对应一次工具调用。拿不准够不够格、`--note` 不会写 → 见 `references/log-note.md`。
|
|
200
230
|
|
|
@@ -217,7 +247,7 @@ python3 <本 SKILL.md 所在目录>/scripts/progress.py <子命令> --repo <工
|
|
|
217
247
|
| `new` / `claim` / `set` | 动手类 | 执行前复述完整参数并取得确认;**`new` 仅当用户原话点名要建且标题可直取原话时免复述**,标题需另拟或拿不准仍复述一次(`claim`/`set` 一律复述) |
|
|
218
248
|
| `log` | 免确认 | 本任务的推进 / 卡点 / 交付记录直接跑,跑完一句话交代「已记执行记录:…」;要替用户下结论,先问(任务不在自己名下会直接被拒) |
|
|
219
249
|
| `close` | 独立授权 | 仅认明确说「结束掉 / close 掉」(完整判定见生命周期第 8 条);说得含糊必须反问「是要结束这个任务吗?」;**agent 自判「干完了」不算** |
|
|
220
|
-
| `list` / `show` / `history` / `validate` | 只读 | 直接跑 |
|
|
250
|
+
| `list` / `show` / `history` / `whoami` / `validate` | 只读 | 直接跑 |
|
|
221
251
|
|
|
222
252
|
### 故障处置(跑之后出事怎么办)
|
|
223
253
|
|
package/assets/worklog.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# <id>:<title>
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
- **状态**:<status>
|
|
4
|
+
- **创建**:<created> · @<creator>
|
|
4
5
|
|
|
5
|
-
<!--
|
|
6
|
+
<!-- 头部四行由脚本维护,顺序固定:分类/标签 → 状态 → 创建 → 封卷。
|
|
7
|
+
「- **分类**:… · **标签**:…」按 new --category / --tags 插在最上面,两者皆空则不写;
|
|
8
|
+
「- **封卷**:…」在结案时加在最后。 -->
|
|
6
9
|
|
|
7
10
|
## 背景
|
|
8
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "task-ledger",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.24",
|
|
4
4
|
"description": "Task-ledger skill for coding agents: per-workspace progress tracking (ledger/pool.json + owners/<hash>.json shards + owners.json index, history, worklog) driven by a CLI script. Standalone install for CodeBuddy and other agents; also bundled inside the dsh-task-ledger DSH plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"skill",
|
|
@@ -24,7 +24,12 @@ close → 历史层 + 封卷 + 移出自己名下
|
|
|
24
24
|
- **只在补录过去时间时传**:`new --created`、`close --finished`。格式 `YYYY-MM-DD[ HH:MM[:SS]]`,按本地墙钟给、脚本内部转 UTC。`new --created` 补录时 `updated` 一并等于该时间 —— 之后补一条 `log` 把 `updated` 刷回当前。
|
|
25
25
|
- 注意:任务号前缀与 worklog 月份目录按 **UTC** 推 —— UTC+8 下裸日期 `--created 2026-01-05` 存成 `2026-01-04 16:00:00`,任务号前缀变成 `20260104-1600`;临午夜补录要连时间一起传。
|
|
26
26
|
- **筛选语义**:`list` 的 `--since` / `--until` 按**创建时间**;`history` 的按**结案时间**(历史文件按结案月归档,按创建时间比较会漏「上月建、本月结」的记录)。只给日期时起 = 当天 `00:00:00`、止 = 当天 `23:59:59`(含当天)。
|
|
27
|
-
-
|
|
27
|
+
- **时区**:**存盘一律 UTC,出门一律本机时区**。
|
|
28
|
+
- 存盘:任务号、worklog 目录 / 文件名、台账 JSON 的 `created`/`started`/`updated`/`finished`、history 行、worklog 头部「创建」行与「状态」行、封卷行、每条执行记录行。
|
|
29
|
+
- 出门:`list` / `show` / `history` 的输出(人话表格与 `--json` 同一个值)都是本机时区,**拿到的就是能直接显示的**,不要再转。
|
|
30
|
+
- 进门:`--since` / `--until` / `--created` / `--finished` 按本机墙钟给,脚本内部转 UTC 再比较 / 落盘;除这四个参数没有任何地方要调用方传时间。
|
|
31
|
+
- **过程文档正文不动**:`show --json` 的 `worklog.text` 是原文,里面的时间是当时写进去的 UTC。
|
|
32
|
+
- 存量老数据写的是写入者本地时间、无标记,无法与 UTC 区分(JSON 是 2026-10-22 前,执行记录行是 2026-10-27 前)。
|
|
28
33
|
- **history 文件 11 列**:结案时间 / 创建时间 / 工作包(= `new --title` 的任务标题)/ 分类 / 标签 / owner / owner_name / creator / creator_name / 摘要 / 过程文档;排序与 `--since` / `--until` 按**结案时间**。(`history` 命令的人话输出只展示其中几列:结案时间、负责人、标题。)
|
|
29
34
|
- **owner / creator 两列存的是 uuid**(与任务里一致,身份只认 uuid);紧随其后的 `owner_name` / `creator_name` 两列**落盘**结案那一刻的显示名 —— 改名不回写旧行,看历史看到的就是当时那个名字。老行(升级前落的)没有名字时按名册兜底补一次展示值,**不回写文件**。
|
|
30
35
|
|
|
@@ -96,19 +96,19 @@
|
|
|
96
96
|
- **「提示:当前目录不是 git 仓库,台账只写了本地文件」**:没有 git 也能用;想纳入版本管理就 `git init`,否则继续本地写(多人各写各的,后写覆盖先写)。
|
|
97
97
|
- **「提示:任务 X 没有过程文档,已跳过封卷,历史末列留空」**:老数据没有 worklog 字段,结案照常,只是没有文档可封。
|
|
98
98
|
- **`无需重复:这次没有新的改动。`**(`claim` / `set` / `close` 的 already_done 通道):上次已经做成过,重跑是幂等空转;`close` 重跑还会顺手补齐上次崩在半途的封卷与移出。
|
|
99
|
-
- **`validate` 的 notices
|
|
99
|
+
- **`validate` 的 notices**(同号任务出现在多个文件、历史解析警告等):只提示不判错,照实转述。
|
|
100
100
|
|
|
101
101
|
## validate 查什么(有问题 ⇒ 退出码 1)
|
|
102
102
|
|
|
103
|
-
两档:默认**浅度**只查格式与结构(账本 JSON +
|
|
103
|
+
两档:默认**浅度**只查格式与结构(账本 JSON + 当月历史);加 **`--deep`** 才多读全部历史月份。**两档都不读过程文档正文**(存量可达上万篇;过程文档是附件,格式与内容不在体检范围)。
|
|
104
104
|
|
|
105
|
-
problems(任一即退 1):① 池里任务带着 owner;② 池里任务 status 不是 open/doing;③ 索引登记了身份但分片文件不在;④ 分片任务没有 owner;⑤ 分片任务 owner 与分片所属键不一致;⑥ 分片任务 status 非法;⑦ `owners/` 里有索引没登记的 `*.json
|
|
106
|
-
notices
|
|
105
|
+
problems(任一即退 1):① 池里任务带着 owner;② 池里任务 status 不是 open/doing;③ 索引登记了身份但分片文件不在;④ 分片任务没有 owner;⑤ 分片任务 owner 与分片所属键不一致;⑥ 分片任务 status 非法;⑦ `owners/` 里有索引没登记的 `*.json`。
|
|
106
|
+
notices(只提示):历史解析警告、历史有结案行但任务还在办、还没有 `owners.json`。
|
|
107
107
|
①~⑦ 里结构类的属人工裁决:读原文确认哪份是真的,删多余那份或把索引改对,**不要用脚本猜**。索引或任一 JSON 损坏 ⇒ 退 3。
|
|
108
108
|
|
|
109
109
|
## 读命令只读本地(跨机器要先取最新)
|
|
110
110
|
|
|
111
|
-
- **读命令(`list` / `show` / `history` / `validate`)不会自动 `git pull
|
|
111
|
+
- **读命令(`list` / `show` / `history` / `whoami` / `validate`)不会自动 `git pull`**:看到的是**这台机器上一次同步后的**台账(`whoami` 连台账都不读,只看本机身份)。
|
|
112
112
|
- 想看别的机器刚写的东西:先 `git pull`,或者跑任意一条写命令(写命令进入时会先取最新)。
|
|
113
113
|
|
|
114
114
|
## 写前取最新与写后同步(机制)
|
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
|
7
7
|
from ..core.identity import Identity, normalize
|
|
8
8
|
from ..core.paths import POOL_REL, shard_rel
|
|
9
9
|
from ..core.time import now
|
|
10
|
-
from ..core.worklog_md import exec_line
|
|
10
|
+
from ..core.worklog_md import StatusLine, exec_line
|
|
11
11
|
from ..errors import Fail
|
|
12
12
|
from ..store.owners_index import OwnersIndex
|
|
13
13
|
from ..store.task_store import TaskStore
|
|
@@ -41,6 +41,7 @@ def claim(repo: Path, me: Identity, tid: str) -> Result:
|
|
|
41
41
|
logs.append_exec(
|
|
42
42
|
path,
|
|
43
43
|
exec_line(now(), me.uuid, "claim", "认领(补齐上次未完成的清理)"),
|
|
44
|
+
status=StatusLine("doing", me.name, me.uuid, now()),
|
|
44
45
|
)
|
|
45
46
|
return Result(
|
|
46
47
|
already_done=True,
|
|
@@ -72,7 +73,11 @@ def claim(repo: Path, me: Identity, tid: str) -> Result:
|
|
|
72
73
|
logs = WorklogStore(repo)
|
|
73
74
|
path = logs.find(tid, moved.get("worklog"))
|
|
74
75
|
if path is not None:
|
|
75
|
-
logs.append_exec(
|
|
76
|
+
logs.append_exec(
|
|
77
|
+
path,
|
|
78
|
+
exec_line(now(), me.stamp(), "claim", "认领 → doing"),
|
|
79
|
+
status=StatusLine("doing", me.name, me.uuid, now()),
|
|
80
|
+
)
|
|
76
81
|
note = None
|
|
77
82
|
return Result(
|
|
78
83
|
changed=("owner", "started", "updated"),
|
|
@@ -12,10 +12,12 @@ from ..core.identity import Identity
|
|
|
12
12
|
from ..core.labels import normalize_label, parse_tags
|
|
13
13
|
from ..core.paths import history_path_for, shard_rel, to_repo_rel, worklog_name
|
|
14
14
|
from ..core.worklog_md import (
|
|
15
|
+
StatusLine,
|
|
15
16
|
append_exec_log,
|
|
16
17
|
exec_line,
|
|
17
18
|
has_frozen_line,
|
|
18
19
|
rewrite_label_line,
|
|
20
|
+
rewrite_status_line,
|
|
19
21
|
stamp_frozen,
|
|
20
22
|
)
|
|
21
23
|
from ..errors import Fail
|
|
@@ -99,6 +101,9 @@ def close_task(
|
|
|
99
101
|
frozen = append_exec_log(
|
|
100
102
|
frozen, exec_line(finished, me.stamp(), "close", "结案封卷")
|
|
101
103
|
)
|
|
104
|
+
frozen = rewrite_status_line(
|
|
105
|
+
frozen, StatusLine("closed", me.name, me.uuid, finished)
|
|
106
|
+
)
|
|
102
107
|
logs.write(doc_path, frozen)
|
|
103
108
|
notes.append("补齐上次未完成的封卷。")
|
|
104
109
|
if mine.get(tid) is not None:
|
|
@@ -160,6 +165,9 @@ def close_task(
|
|
|
160
165
|
frozen = append_exec_log(
|
|
161
166
|
frozen, exec_line(finished, me.stamp(), "close", "结案封卷")
|
|
162
167
|
)
|
|
168
|
+
frozen = rewrite_status_line(
|
|
169
|
+
frozen, StatusLine("closed", me.name, me.uuid, finished)
|
|
170
|
+
)
|
|
163
171
|
logs.write(doc_path, frozen)
|
|
164
172
|
|
|
165
173
|
# ④ 删我分片那行(永远最后)
|
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
|
7
7
|
from ..core.identity import Identity, normalize
|
|
8
8
|
from ..core.paths import shard_rel
|
|
9
9
|
from ..core.time import now
|
|
10
|
-
from ..core.worklog_md import exec_line
|
|
10
|
+
from ..core.worklog_md import StatusLine, exec_line
|
|
11
11
|
from ..errors import Fail
|
|
12
12
|
from ..store.owners_index import OwnersIndex
|
|
13
13
|
from ..store.task_store import TaskStore
|
|
@@ -62,6 +62,7 @@ def handoff(repo: Path, me: Identity, tid: str, *, to: str) -> Result:
|
|
|
62
62
|
logs.append_exec(
|
|
63
63
|
path,
|
|
64
64
|
exec_line(now(), me.stamp(), "set", f"交接给 @{who_stamp}(补齐)"),
|
|
65
|
+
status=StatusLine("doing", to_name, to_key, now()),
|
|
65
66
|
)
|
|
66
67
|
return Result(
|
|
67
68
|
already_done=True,
|
|
@@ -80,7 +81,9 @@ def handoff(repo: Path, me: Identity, tid: str, *, to: str) -> Result:
|
|
|
80
81
|
note = f"任务 {tid} 已交给 {who},但过程文档没找到,跳过执行记录。"
|
|
81
82
|
else:
|
|
82
83
|
logs.append_exec(
|
|
83
|
-
path,
|
|
84
|
+
path,
|
|
85
|
+
exec_line(now(), me.stamp(), "set", f"交接给 @{who_stamp}"),
|
|
86
|
+
status=StatusLine("doing", to_name, to_key, now()),
|
|
84
87
|
)
|
|
85
88
|
return Result(
|
|
86
89
|
changed=("owner", "owner_name", "updated"),
|
|
@@ -12,7 +12,7 @@ from ..core.paths import POOL_REL
|
|
|
12
12
|
from ..errors import Fail
|
|
13
13
|
from ..store.owners_index import OwnersIndex
|
|
14
14
|
from ..store.task_store import TaskStore
|
|
15
|
-
from .guard import in_scope, owner_of, require_uuid, status_of
|
|
15
|
+
from .guard import in_scope, is_mine, owner_of, require_uuid, status_of
|
|
16
16
|
from .query import ListQuery
|
|
17
17
|
from .result import ListResult, TaskRow, rel
|
|
18
18
|
|
|
@@ -52,6 +52,9 @@ def list_tasks(repo: Path, me: Identity, q: ListQuery) -> ListResult:
|
|
|
52
52
|
kept = {
|
|
53
53
|
tid: t for tid, t in rows.items() if in_scope(t, q, me=me, name_keys=name_keys)
|
|
54
54
|
}
|
|
55
|
+
# 每行自带 `mine`(只比 uuid,零额外 IO):调用方不必自己拿 uuid 再比一次
|
|
56
|
+
for task in kept.values():
|
|
57
|
+
task["mine"] = is_mine(task, me)
|
|
55
58
|
table = tuple(
|
|
56
59
|
TaskRow(
|
|
57
60
|
tid=tid,
|
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
|
7
7
|
from ..core.identity import Identity
|
|
8
8
|
from ..core.paths import shard_rel
|
|
9
9
|
from ..core.time import now
|
|
10
|
-
from ..core.worklog_md import exec_line
|
|
10
|
+
from ..core.worklog_md import StatusLine, exec_line
|
|
11
11
|
from ..errors import Fail
|
|
12
12
|
from ..store.task_store import TaskStore
|
|
13
13
|
from ..store.worklog_store import WorklogStore
|
|
@@ -46,7 +46,11 @@ def log_progress(repo: Path, me: Identity, tid: str, note: str) -> Result:
|
|
|
46
46
|
"提示:这条任务没有过程文档,已跳过执行记录(分片的最后更新已刷)。",
|
|
47
47
|
),
|
|
48
48
|
)
|
|
49
|
-
ok = logs.append_exec(
|
|
49
|
+
ok = logs.append_exec(
|
|
50
|
+
path,
|
|
51
|
+
exec_line(now(), me.stamp(), "log", text),
|
|
52
|
+
status=StatusLine("doing", me.name, me.uuid, now()),
|
|
53
|
+
)
|
|
50
54
|
if not ok:
|
|
51
55
|
return Result(
|
|
52
56
|
changed=("updated",),
|
|
@@ -17,7 +17,7 @@ from ..core.paths import (
|
|
|
17
17
|
to_repo_rel,
|
|
18
18
|
worklog_rel,
|
|
19
19
|
)
|
|
20
|
-
from ..core.worklog_md import exec_line
|
|
20
|
+
from ..core.worklog_md import StatusLine, exec_line
|
|
21
21
|
from ..errors import Fail
|
|
22
22
|
from ..store.atomic import ensure_dir, restore, snapshot
|
|
23
23
|
from ..store.task_store import TaskStore
|
|
@@ -102,6 +102,12 @@ def new_task(
|
|
|
102
102
|
creator=me.stamp(),
|
|
103
103
|
category=category,
|
|
104
104
|
tags=tag_list,
|
|
105
|
+
status=StatusLine(
|
|
106
|
+
"doing" if mine else "open",
|
|
107
|
+
me.name if mine else None,
|
|
108
|
+
me.uuid if mine else None,
|
|
109
|
+
created,
|
|
110
|
+
),
|
|
105
111
|
first_exec=exec_line(
|
|
106
112
|
created, me.stamp(), "new", "创建任务并认领" if mine else "创建任务"
|
|
107
113
|
),
|
|
@@ -18,7 +18,7 @@ from ..core.time import now, time_key
|
|
|
18
18
|
from ..errors import Fail
|
|
19
19
|
from ..store.history_store import HistoryStore
|
|
20
20
|
from ..store.owners_index import OwnersIndex
|
|
21
|
-
from .guard import require_uuid
|
|
21
|
+
from .guard import is_mine, require_uuid
|
|
22
22
|
from .query import COUNT_CAP, HistoryQuery
|
|
23
23
|
from .result import HistoryResult, rel
|
|
24
24
|
|
|
@@ -132,6 +132,8 @@ def query_history(repo: Path, me: Identity, q: HistoryQuery) -> HistoryResult:
|
|
|
132
132
|
row["src"] = rel(repo, path)
|
|
133
133
|
row["created"] = time_key(row.get("created") or "") or row.get("created")
|
|
134
134
|
row["finished"] = time_key(row.get("finished") or "") or row.get("finished")
|
|
135
|
+
# 每行自带 `mine`(只比 uuid):调用方不必自己拿 uuid 再比一次
|
|
136
|
+
row["mine"] = is_mine(row, me)
|
|
135
137
|
records.append(row)
|
|
136
138
|
|
|
137
139
|
index = OwnersIndex(repo)
|
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
|
7
7
|
from ..core.identity import Identity
|
|
8
8
|
from ..core.paths import POOL_REL, shard_rel
|
|
9
9
|
from ..core.time import now
|
|
10
|
-
from ..core.worklog_md import exec_line
|
|
10
|
+
from ..core.worklog_md import StatusLine, exec_line
|
|
11
11
|
from ..errors import Fail
|
|
12
12
|
from ..store.task_store import TaskStore
|
|
13
13
|
from ..store.worklog_store import WorklogStore
|
|
@@ -63,7 +63,11 @@ def release(repo: Path, me: Identity, tid: str) -> Result:
|
|
|
63
63
|
if path is None:
|
|
64
64
|
note = f"任务 {tid} 已退回公共池,但过程文档没找到,跳过执行记录。"
|
|
65
65
|
else:
|
|
66
|
-
logs.append_exec(
|
|
66
|
+
logs.append_exec(
|
|
67
|
+
path,
|
|
68
|
+
exec_line(now(), me.stamp(), "release", "释放回公共池"),
|
|
69
|
+
status=StatusLine("open", None, None, now()),
|
|
70
|
+
)
|
|
67
71
|
return Result(
|
|
68
72
|
changed=("owner", "owner_name", "status", "updated"),
|
|
69
73
|
where=rel(repo, pool.path),
|
|
@@ -67,6 +67,8 @@ class ShowResult:
|
|
|
67
67
|
task: dict[str, Any] = field(default_factory=dict)
|
|
68
68
|
worklog: WorklogView | None = None
|
|
69
69
|
others: tuple[str, ...] = () # 同一个任务号还出现在哪些文件里
|
|
70
|
+
#: 字段是从**在办索引**读来的(老文档没有状态行 / 文档丢了),不是文档自述
|
|
71
|
+
legacy: bool = False
|
|
70
72
|
notices: tuple[str, ...] = ()
|
|
71
73
|
|
|
72
74
|
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""只读:看一条任务。**文档优先**——读到文档就知道状态,不再翻索引(2026-10-27)。
|
|
2
|
+
|
|
3
|
+
两条路径:
|
|
4
|
+
- 文档存在且头部有状态行 ⇒ 完全按文档自述回答(`status` / 负责人 / 更新时间 / 标题),
|
|
5
|
+
pool、分片、历史一个都不读,已结案的任务同样看得到;
|
|
6
|
+
- 文档没有状态行(老文档)或根本没有文档 ⇒ 回退 `load_task` 查在办索引,
|
|
7
|
+
返回里标 `legacy=True`,让调用方知道这些字段不是文档自述的。
|
|
8
|
+
"""
|
|
2
9
|
|
|
3
10
|
from __future__ import annotations
|
|
4
11
|
|
|
5
12
|
from pathlib import Path
|
|
6
13
|
|
|
14
|
+
from ..core import worklog_md
|
|
7
15
|
from ..core.identity import Identity
|
|
8
16
|
from ..store.worklog_store import WorklogStore
|
|
9
17
|
from .guard import load_task
|
|
@@ -11,17 +19,37 @@ from .result import ShowResult, WorklogView, rel
|
|
|
11
19
|
|
|
12
20
|
|
|
13
21
|
def show_task(repo: Path, me: Identity, tid: str) -> ShowResult:
|
|
14
|
-
task, where = load_task(repo, tid)
|
|
15
22
|
logs = WorklogStore(repo)
|
|
16
|
-
path = logs.find(tid
|
|
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)
|
|
17
44
|
if path is None:
|
|
18
45
|
view = WorklogView(
|
|
19
46
|
path=None, text=None, error="这条任务没有过程文档(或文档已不在原处)。"
|
|
20
47
|
)
|
|
21
48
|
else:
|
|
22
|
-
view = WorklogView(path=rel(repo, path), text=
|
|
49
|
+
view = WorklogView(path=rel(repo, path), text=text or None, error=None)
|
|
23
50
|
return ShowResult(
|
|
24
51
|
task=task,
|
|
25
52
|
worklog=view,
|
|
26
53
|
others=tuple(rel(repo, p) for p in where),
|
|
54
|
+
legacy=True,
|
|
27
55
|
)
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
"""只读:台账体检。两档:默认浅度只查格式,`--deep`
|
|
1
|
+
"""只读:台账体检。两档:默认浅度只查格式,`--deep` 才读全部历史。
|
|
2
2
|
|
|
3
|
-
浅度(默认):池 +
|
|
4
|
-
深度(`--deep
|
|
3
|
+
浅度(默认):池 + 各分片的字段格式、索引与文件对不对得上、**当月**历史。
|
|
4
|
+
深度(`--deep`):历史不止当月(全部月份)。
|
|
5
|
+
|
|
6
|
+
**两档都不读过程文档正文**(2026-10-27 用户拍板):过程文档是附件、存量可以上万篇,
|
|
7
|
+
逐篇读全文换不来体检结论,只白花时间;文档自身的格式与内容不在体检范围。
|
|
5
8
|
|
|
6
9
|
只查格式,不查业务(该谁结案、逾期与否都不管);也不查「同一任务号落在多个文件」——
|
|
7
10
|
读侧只显示一次(`show` 会点名)、写侧已有防护,撞上了不关体检的事(2026-10-24 用户拍板)。
|
|
@@ -21,16 +24,9 @@ from ..core.paths import (
|
|
|
21
24
|
to_repo_rel,
|
|
22
25
|
)
|
|
23
26
|
from ..core.time import now
|
|
24
|
-
from ..core.worklog_md import (
|
|
25
|
-
duplicated_sections,
|
|
26
|
-
format_problems,
|
|
27
|
-
is_skeleton,
|
|
28
|
-
lacks_exec_section,
|
|
29
|
-
)
|
|
30
27
|
from ..store.history_store import HistoryStore
|
|
31
28
|
from ..store.owners_index import OwnersIndex
|
|
32
29
|
from ..store.task_store import TaskStore
|
|
33
|
-
from ..store.worklog_store import WorklogStore
|
|
34
30
|
from .guard import owner_of, status_of
|
|
35
31
|
from .result import ValidationReport, rel
|
|
36
32
|
|
|
@@ -138,43 +134,6 @@ def _check_history(
|
|
|
138
134
|
return checked
|
|
139
135
|
|
|
140
136
|
|
|
141
|
-
def _check_worklog(
|
|
142
|
-
repo: Path,
|
|
143
|
-
logs: WorklogStore,
|
|
144
|
-
problems: list[str],
|
|
145
|
-
notices: list[str],
|
|
146
|
-
*,
|
|
147
|
-
deep: bool,
|
|
148
|
-
) -> int:
|
|
149
|
-
"""每篇过程文档:模板格式(浅度就查)+ 空骨架判定(只有 `--deep` 才判)。
|
|
150
|
-
|
|
151
|
-
一趟读完两件事都做 —— 格式要看全文找节标题,骨架吃同一份文本,别为此读第二遍。
|
|
152
|
-
"""
|
|
153
|
-
checked = 0
|
|
154
|
-
for path in logs.all():
|
|
155
|
-
checked += 1
|
|
156
|
-
try:
|
|
157
|
-
text = logs.read(path)
|
|
158
|
-
except ValueError:
|
|
159
|
-
continue
|
|
160
|
-
if not text:
|
|
161
|
-
continue
|
|
162
|
-
where = rel(repo, path)
|
|
163
|
-
problems.extend(f"{where} 格式:{line}" for line in format_problems(text))
|
|
164
|
-
if lacks_exec_section(text):
|
|
165
|
-
notices.append(
|
|
166
|
-
f"{where} 没有「执行记录」节(老文档;写一条记录会自动补上)。"
|
|
167
|
-
)
|
|
168
|
-
dup = duplicated_sections(text)
|
|
169
|
-
if dup:
|
|
170
|
-
notices.append(
|
|
171
|
-
f"{where} 有重复的节:{'、'.join(f'`## {s}`' for s in dup)}。"
|
|
172
|
-
)
|
|
173
|
-
if deep and is_skeleton(text):
|
|
174
|
-
notices.append(f"{where} 还是骨架(正文没填)。")
|
|
175
|
-
return checked
|
|
176
|
-
|
|
177
|
-
|
|
178
137
|
def validate(repo: Path, me: Identity, deep: bool = False) -> ValidationReport:
|
|
179
138
|
problems: list[str] = []
|
|
180
139
|
notices: list[str] = []
|
|
@@ -183,7 +142,6 @@ def validate(repo: Path, me: Identity, deep: bool = False) -> ValidationReport:
|
|
|
183
142
|
|
|
184
143
|
index = OwnersIndex(repo)
|
|
185
144
|
history = HistoryStore(repo)
|
|
186
|
-
logs = WorklogStore(repo)
|
|
187
145
|
|
|
188
146
|
files, tasks = _check_task_files(repo, index, problems)
|
|
189
147
|
checked += files
|
|
@@ -197,7 +155,6 @@ def validate(repo: Path, me: Identity, deep: bool = False) -> ValidationReport:
|
|
|
197
155
|
history,
|
|
198
156
|
notices,
|
|
199
157
|
)
|
|
200
|
-
checked += _check_worklog(repo, logs, problems, notices, deep=deep)
|
|
201
158
|
|
|
202
159
|
if not (repo / to_repo_rel(OWNERS_REL)).exists():
|
|
203
160
|
notices.append("还没有 owners.json(索引):跑一条写命令会自动建。")
|
|
@@ -27,10 +27,10 @@ class Identity:
|
|
|
27
27
|
def stamp(self) -> str:
|
|
28
28
|
"""**落盘**用的身份串:`名字 · uuid` —— 名字在前给人读,uuid 在后给机器对。
|
|
29
29
|
|
|
30
|
-
与 `label()` 一样**不带 `@`**(`@`
|
|
31
|
-
`exec_line` 拼 ` · @{who} ·
|
|
30
|
+
与 `label()` 一样**不带 `@`**(`@` 由各落点自己加:头部各行拼 ` · @{stamp}`、
|
|
31
|
+
`exec_line` 拼 ` · @{who} · `)。
|
|
32
32
|
|
|
33
|
-
过程文档(创建行 / 封卷行 / 执行记录)是这个串唯一的落点:文件是最终产物,
|
|
33
|
+
过程文档(创建行 / 状态行 / 封卷行 / 执行记录)是这个串唯一的落点:文件是最终产物,
|
|
34
34
|
创建人和封卷人可能不是同一个人、也可能中途改过名,所以**两个都要留**,不靠
|
|
35
35
|
历史表回链。没名字就只写 uuid。
|
|
36
36
|
"""
|
|
@@ -15,7 +15,7 @@ LABEL_MAX_WORDS_EN = 3 # 纯 ASCII 时按「词」算
|
|
|
15
15
|
TAGS_MAX_COUNT = 5
|
|
16
16
|
|
|
17
17
|
CJK_RE = re.compile(r"[\u4e00-\u9fff]")
|
|
18
|
-
LABEL_CAT_RE = re.compile(r"分类\*\*\s*[::]\s*([
|
|
18
|
+
LABEL_CAT_RE = re.compile(r"分类\*\*\s*[::]\s*([^||·]+)")
|
|
19
19
|
LABEL_TAG_RE = re.compile(r"标签\*\*\s*[::]\s*(.+)$")
|
|
20
20
|
_SPLIT_RE = re.compile(r"[,,、]")
|
|
21
21
|
|
|
@@ -49,21 +49,33 @@ def parse_tags(raw: str | Iterable[str] | None) -> tuple[str, ...]:
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def label_line(category: str | None, tags: Iterable[str] | None) -> str:
|
|
52
|
-
"""
|
|
52
|
+
"""过程文档头部的「分类 / 标签」行;两者皆空返回空串(此行不写)。"""
|
|
53
53
|
segs: list[str] = []
|
|
54
54
|
if category:
|
|
55
55
|
segs.append(f"**分类**:{category}")
|
|
56
56
|
tag_list = [t for t in (tags or ()) if t]
|
|
57
57
|
if tag_list:
|
|
58
58
|
segs.append(f"**标签**:{'、'.join(tag_list)}")
|
|
59
|
-
return "
|
|
59
|
+
return "- " + " · ".join(segs) if segs else ""
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
def parse_label_line(text: str) -> tuple[str | None, tuple[str, ...]]:
|
|
63
|
-
"""从过程文档头部(第一个 `## ` 小节之前)解析分类与标签。
|
|
63
|
+
"""从过程文档头部(第一个 `## ` 小节之前)解析分类与标签。
|
|
64
|
+
|
|
65
|
+
跳过 HTML 注释块:模板注释里举例写着「**分类**:…」,那不是数据。
|
|
66
|
+
"""
|
|
67
|
+
in_comment = False
|
|
64
68
|
for line in text.splitlines():
|
|
65
69
|
if line.startswith("## "):
|
|
66
70
|
break
|
|
71
|
+
stripped = line.lstrip()
|
|
72
|
+
if in_comment:
|
|
73
|
+
if "-->" in stripped:
|
|
74
|
+
in_comment = False
|
|
75
|
+
continue
|
|
76
|
+
if stripped.startswith("<!--"):
|
|
77
|
+
in_comment = "-->" not in stripped
|
|
78
|
+
continue
|
|
67
79
|
mc = LABEL_CAT_RE.search(line)
|
|
68
80
|
mt = LABEL_TAG_RE.search(line)
|
|
69
81
|
if not (mc or mt):
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
进门规则:不读文件、不写文件、不打印;只依赖 errors。
|
|
4
4
|
所有**存盘**时间都是 UTC(`YYYY-MM-DD HH:MM:SS`,不带偏移量);
|
|
5
|
-
|
|
5
|
+
所有**对外输出**(人话表格与 `--json`)的时间字段都过 `fmt_local` 转本机时区,
|
|
6
|
+
内部筛选 / 排序一律用存盘的 UTC —— 调用方拿到的时间不用再转。
|
|
6
7
|
"""
|
|
7
8
|
|
|
8
9
|
from __future__ import annotations
|
|
@@ -8,28 +8,57 @@ from __future__ import annotations
|
|
|
8
8
|
import re
|
|
9
9
|
from collections.abc import Iterable
|
|
10
10
|
from itertools import takewhile
|
|
11
|
+
from typing import NamedTuple
|
|
11
12
|
|
|
12
13
|
from ..errors import Fail
|
|
13
14
|
from .identity import UUID_RE
|
|
14
15
|
from .labels import label_line, parse_label_line
|
|
15
|
-
from .time import
|
|
16
|
+
from .time import normalize_time
|
|
16
17
|
|
|
17
18
|
EXEC_HEAD = "## 执行记录"
|
|
18
19
|
EXEC_HINT = (
|
|
19
20
|
"<!-- 本节由脚本维护:new / claim / set / release / log / close 自动追加,请勿手改。\n"
|
|
20
21
|
' 补记用 progress.py log --id <任务号> --note "一句话"。 -->'
|
|
21
22
|
)
|
|
22
|
-
FROZEN_MARK = "
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
FROZEN_MARK = "封卷"
|
|
24
|
+
#: 头部四行的规范顺序:分类/标签 → 状态 → 创建 → 封卷。
|
|
25
|
+
#: 「分类」只在有分类 / 标签时写,「封卷」只在结案时写,另两行必有。
|
|
26
|
+
HEAD_KEY_ORDER = ("meta", "status", "created", "frozen")
|
|
27
|
+
#: 头部行前缀:新格式是无序列表 `- `,老文档是引用块 `> ` —— 读的时候两种都认。
|
|
28
|
+
_HEAD_BULLET = r"^(?:\s*>\s?|\s*[-*]\s+)"
|
|
29
|
+
FROZEN_RE = re.compile(
|
|
30
|
+
_HEAD_BULLET + r"(?:\*\*" + FROZEN_MARK + r"\*\*|✅ 完成封卷)", re.MULTILINE
|
|
31
|
+
)
|
|
32
|
+
#: 封卷行的时间(老文档是 `> ✅ 完成封卷:<时间>(@…)`,新格式是 `- **封卷**:<时间> · @…`)。
|
|
33
|
+
_FROZEN_AT_RE = re.compile(
|
|
34
|
+
_HEAD_BULLET + r"(?:\*\*" + FROZEN_MARK + r"\*\*|✅ 完成封卷)[^::]*[::]\s*"
|
|
35
|
+
r"(\d{4}-\d{2}-\d{2}(?:[ T]\d{1,2}:\d{2}(?::\d{2})?)?)"
|
|
36
|
+
)
|
|
37
|
+
# 头部「创建」行:`- **创建**:2026-10-06 00:00 · @某人 · uuid`。
|
|
38
|
+
# 值一律 `时间 · @名字 · uuid`,与执行记录行同一种分隔符;老文档是 `(@名字 · uuid)`,读得到就认。
|
|
39
|
+
CREATED_RE = re.compile(_HEAD_BULLET + r"\*\*创建\*\*")
|
|
28
40
|
CREATED_AT_RE = re.compile(
|
|
29
|
-
r"
|
|
41
|
+
_HEAD_BULLET + r"\*\*创建\*\*\s*[::]\s*"
|
|
30
42
|
r"(\d{4}-\d{2}-\d{2}(?: +\d{1,2}:\d{1,2}(?::\d{1,2})?)?)"
|
|
31
43
|
)
|
|
32
|
-
CREATOR_RE = re.compile(r"
|
|
44
|
+
CREATOR_RE = re.compile(_HEAD_BULLET + r"\*\*创建\*\*\s*[::].*?@(.+?)\s*[))]?\s*$")
|
|
45
|
+
|
|
46
|
+
# 头部「状态」行:`- **状态**:doing · 2026-10-27 08:28:22 · @某人 · uuid`。
|
|
47
|
+
# 它是**镜像**:分片 / 池里的 `status` / `owner` 才是权威,这行只是让「看一条详情」
|
|
48
|
+
# 不必再翻索引。老文档没有这行 ⇒ 合法,读取方回退查分片。
|
|
49
|
+
STATUS_MARK = "状态"
|
|
50
|
+
STATUS_LINE_RE = re.compile(_HEAD_BULLET + r"\*\*" + STATUS_MARK + r"\*\*")
|
|
51
|
+
STATUS_RE = re.compile(
|
|
52
|
+
_HEAD_BULLET + r"\*\*" + STATUS_MARK + r"\*\*\s*[::]\s*([A-Za-z_]+)"
|
|
53
|
+
)
|
|
54
|
+
#: 状态取值(与 `core/labels.STATUSES` + 结案后的 `closed` 同口径,全链路英文)。
|
|
55
|
+
STATUS_VALUES = ("open", "doing", "closed")
|
|
56
|
+
_STATUS_UUID_RE = re.compile(
|
|
57
|
+
r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
|
|
58
|
+
)
|
|
59
|
+
_STATUS_NAME_RE = re.compile(r"@([^((·]+)")
|
|
60
|
+
_STATUS_WHEN_RE = re.compile(r"(\d{4}-\d{2}-\d{2}(?:[ T]\d{1,2}:\d{2}(?::\d{2})?)?)")
|
|
61
|
+
_TITLE_RE = re.compile(r"^#\s*(.+?)\s*[::]\s*(.*)$")
|
|
33
62
|
|
|
34
63
|
_HEAD_RE = re.compile(r"\A(.*?)(?=^## |\Z)", re.DOTALL | re.MULTILINE)
|
|
35
64
|
|
|
@@ -66,10 +95,20 @@ def format_problems(text: str) -> list[str]:
|
|
|
66
95
|
head = _head_lines(lines)
|
|
67
96
|
if not any(CREATED_AT_RE.match(line) for line in head):
|
|
68
97
|
problems.append(
|
|
69
|
-
"头部缺「创建」时间行(应为
|
|
98
|
+
"头部缺「创建」时间行(应为 `- **创建**:YYYY-MM-DD HH:MM:SS · @某人 · uuid`)"
|
|
70
99
|
)
|
|
71
100
|
elif not any(CREATOR_RE.match(line) for line in head):
|
|
72
|
-
problems.append("头部「创建」行缺发起人(应为
|
|
101
|
+
problems.append("头部「创建」行缺发起人(应为 `… · @某人 · uuid`)")
|
|
102
|
+
# 状态行:**有就必须合法**;缺了不报——老文档没有这行是合法的(读取方回退查分片)
|
|
103
|
+
for line in head:
|
|
104
|
+
if not STATUS_LINE_RE.match(line):
|
|
105
|
+
continue
|
|
106
|
+
m = STATUS_RE.match(line)
|
|
107
|
+
if m is None or m.group(1) not in STATUS_VALUES:
|
|
108
|
+
problems.append(
|
|
109
|
+
"头部「状态」行的值不合法(应为 " + " / ".join(STATUS_VALUES) + ")"
|
|
110
|
+
)
|
|
111
|
+
break
|
|
73
112
|
heads = section_heads(body)
|
|
74
113
|
missing = [s for s in REQUIRED_SECTIONS if s not in heads]
|
|
75
114
|
if missing:
|
|
@@ -131,37 +170,171 @@ def render_worklog(
|
|
|
131
170
|
creator: str,
|
|
132
171
|
category: str | None = None,
|
|
133
172
|
tags: Iterable[str] | None = None,
|
|
173
|
+
status: StatusLine | None = None,
|
|
134
174
|
template: str,
|
|
135
175
|
) -> str:
|
|
136
|
-
"""把模板套成一篇过程文档(`<id>` / `<title>` / `<created>` / `<creator>`
|
|
176
|
+
"""把模板套成一篇过程文档(`<id>` / `<title>` / `<created>` / `<creator>` / `<status>`)。
|
|
177
|
+
|
|
178
|
+
`<status>` 只占状态行的**内容**(`doing · 时间 · @某人 · uuid`);模板里的
|
|
179
|
+
`- **状态**:` 前缀是字面量。不传 status ⇒ 整行删掉(不留空壳)。
|
|
180
|
+
"""
|
|
137
181
|
text = (
|
|
138
182
|
template.replace("<id>", tid)
|
|
139
183
|
.replace("<title>", title or "")
|
|
140
184
|
.replace("<created>", created or "")
|
|
141
185
|
.replace("<creator>", creator or "")
|
|
142
186
|
)
|
|
187
|
+
if status is None:
|
|
188
|
+
text = (
|
|
189
|
+
"\n".join(
|
|
190
|
+
ln
|
|
191
|
+
for ln in text.splitlines()
|
|
192
|
+
if not (STATUS_LINE_RE.match(ln) and "<status>" in ln)
|
|
193
|
+
)
|
|
194
|
+
+ "\n"
|
|
195
|
+
)
|
|
196
|
+
else:
|
|
197
|
+
text = text.replace(
|
|
198
|
+
"<status>",
|
|
199
|
+
render_status_body(status.status, status.name, status.uuid, status.when),
|
|
200
|
+
)
|
|
143
201
|
meta = label_line(category, tags)
|
|
144
202
|
if not meta:
|
|
145
203
|
return text
|
|
146
|
-
return "\n".join(
|
|
204
|
+
return "\n".join(_insert_head_line(text.splitlines(), meta, "meta")) + "\n"
|
|
205
|
+
|
|
147
206
|
|
|
207
|
+
_META_LINE_RE = re.compile(_HEAD_BULLET + r"\*\*(?:分类|标签)\*\*")
|
|
148
208
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if
|
|
209
|
+
|
|
210
|
+
def _head_key(line: str) -> str | None:
|
|
211
|
+
"""这一行是头部哪个字段(`meta` / `status` / `created` / `frozen`);都不是给 None。"""
|
|
212
|
+
if _META_LINE_RE.search(line):
|
|
213
|
+
return "meta"
|
|
214
|
+
if STATUS_LINE_RE.match(line):
|
|
215
|
+
return "status"
|
|
216
|
+
if CREATED_RE.match(line):
|
|
217
|
+
return "created"
|
|
218
|
+
if FROZEN_RE.match(line):
|
|
219
|
+
return "frozen"
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _insert_head_line(lines: list[str], line: str, key: str) -> list[str]:
|
|
224
|
+
"""按 `HEAD_KEY_ORDER` 把一行插进头部(第一个 `## ` 之前)。
|
|
225
|
+
|
|
226
|
+
排在它后面的字段行先出现就插在那行前面;没有就接在最后一个字段行之后;
|
|
227
|
+
一个字段行都没有就插在标题(及其后的空行)下面。
|
|
228
|
+
"""
|
|
229
|
+
rank = HEAD_KEY_ORDER.index(key)
|
|
230
|
+
last: int | None = None
|
|
231
|
+
for i, ln in enumerate(lines):
|
|
232
|
+
if ln.startswith("## "):
|
|
233
|
+
break
|
|
234
|
+
found = _head_key(ln)
|
|
235
|
+
if found is None:
|
|
236
|
+
continue
|
|
237
|
+
if HEAD_KEY_ORDER.index(found) > rank:
|
|
238
|
+
lines.insert(i, line)
|
|
239
|
+
return lines
|
|
240
|
+
last = i
|
|
241
|
+
if last is None:
|
|
153
242
|
at = 1 if lines and lines[0].startswith("# ") else 0
|
|
154
|
-
|
|
243
|
+
while at + 1 < len(lines) and not lines[at + 1].strip():
|
|
244
|
+
at += 1
|
|
245
|
+
lines.insert(at + 1, line)
|
|
246
|
+
else:
|
|
247
|
+
lines.insert(last + 1, line)
|
|
155
248
|
return lines
|
|
156
249
|
|
|
157
250
|
|
|
251
|
+
class StatusLine(NamedTuple):
|
|
252
|
+
"""头部状态行的四样内容(`when` 传 UTC,与执行记录同口径)。"""
|
|
253
|
+
|
|
254
|
+
status: str
|
|
255
|
+
name: str | None = None
|
|
256
|
+
uuid: str | None = None
|
|
257
|
+
when: str | None = None
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def render_status_body(
|
|
261
|
+
status: str,
|
|
262
|
+
name: str | None = None,
|
|
263
|
+
uuid: str | None = None,
|
|
264
|
+
when: str | None = None,
|
|
265
|
+
) -> str:
|
|
266
|
+
"""状态行的**内容**部分(`- **状态**:` 之后那段):`状态 · 时间 · @名字 · uuid`。"""
|
|
267
|
+
parts = [status]
|
|
268
|
+
if when:
|
|
269
|
+
parts.append(when)
|
|
270
|
+
if name:
|
|
271
|
+
parts.append(f"@{name}")
|
|
272
|
+
if uuid:
|
|
273
|
+
parts.append(uuid)
|
|
274
|
+
return " · ".join(parts)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def render_status_line(
|
|
278
|
+
status: str,
|
|
279
|
+
name: str | None = None,
|
|
280
|
+
uuid: str | None = None,
|
|
281
|
+
when: str | None = None,
|
|
282
|
+
) -> str:
|
|
283
|
+
return f"- **{STATUS_MARK}**:{render_status_body(status, name, uuid, when)}"
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def rewrite_status_line(text: str, status: StatusLine) -> str:
|
|
287
|
+
"""把头部状态行改成 `status`:有就就地替换,没有就按头部顺序插进去。"""
|
|
288
|
+
line = render_status_line(status.status, status.name, status.uuid, status.when)
|
|
289
|
+
lines = (text or "").splitlines()
|
|
290
|
+
for i, ln in enumerate(lines):
|
|
291
|
+
if ln.startswith("## "):
|
|
292
|
+
break
|
|
293
|
+
if STATUS_LINE_RE.match(ln):
|
|
294
|
+
lines[i] = line
|
|
295
|
+
return "\n".join(lines) + "\n"
|
|
296
|
+
return "\n".join(_insert_head_line(lines, line, "status")) + "\n"
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def read_status(text: str) -> StatusLine | None:
|
|
300
|
+
"""头部状态行 → `StatusLine`;没有这行、或值不合法 ⇒ None(调用方回退查分片)。"""
|
|
301
|
+
for line in _head_lines((text or "").lstrip("\ufeff").splitlines()):
|
|
302
|
+
m = STATUS_RE.match(line)
|
|
303
|
+
if not (m and m.group(1) in STATUS_VALUES):
|
|
304
|
+
continue
|
|
305
|
+
u = _STATUS_UUID_RE.search(line)
|
|
306
|
+
name = _STATUS_NAME_RE.search(line)
|
|
307
|
+
when = _STATUS_WHEN_RE.search(line)
|
|
308
|
+
return StatusLine(
|
|
309
|
+
m.group(1),
|
|
310
|
+
(name.group(1).strip() or None) if name else None,
|
|
311
|
+
(u.group(0).lower() if u else None),
|
|
312
|
+
(when.group(1) if when else None),
|
|
313
|
+
)
|
|
314
|
+
return None
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def head_title(text: str) -> tuple[str | None, str | None]:
|
|
318
|
+
"""第一行 `# <任务号>:<标题>` → (任务号, 标题);读不出给 (None, None)。"""
|
|
319
|
+
for line in (text or "").lstrip("\ufeff").splitlines():
|
|
320
|
+
if not line.startswith("# "):
|
|
321
|
+
continue
|
|
322
|
+
m = _TITLE_RE.match(line)
|
|
323
|
+
if m:
|
|
324
|
+
return m.group(1).strip() or None, m.group(2).strip() or None
|
|
325
|
+
return None, None
|
|
326
|
+
return None, None
|
|
327
|
+
|
|
328
|
+
|
|
158
329
|
def exec_line(when: str, who: str | None, kind: str, note: str) -> str:
|
|
159
|
-
"""一条执行记录:`-
|
|
330
|
+
"""一条执行记录:`- 时刻 · 类型 · @某人 · 说明`。
|
|
160
331
|
|
|
161
|
-
|
|
162
|
-
|
|
332
|
+
时刻与台账其它存盘时间同口径:**UTC**(调用方一律传 UTC,这里不再转本地)。
|
|
333
|
+
正文整篇由 `readWorklog` / `show` 原样读出,脚本无法逐行回转 ⇒ 存什么就显示什么;
|
|
334
|
+
转本地是消费方(终端 / 看板)的事。
|
|
335
|
+
类型取动作名(new / claim / set / release / log / close)。
|
|
163
336
|
"""
|
|
164
|
-
head = f"- {
|
|
337
|
+
head = f"- {when} · {kind}"
|
|
165
338
|
tail = f" · @{who} · {note}" if who else f" · {note}"
|
|
166
339
|
return head + tail
|
|
167
340
|
|
|
@@ -180,25 +353,25 @@ def has_frozen_line(text: str) -> bool:
|
|
|
180
353
|
|
|
181
354
|
|
|
182
355
|
def stamp_frozen(text: str, finished: str, who: str | None = "") -> str:
|
|
183
|
-
"""
|
|
184
|
-
mark = f"
|
|
356
|
+
"""封卷:在头部打「封卷」行(`finished` 传 UTC,原样写盘——见 exec_line 的口径说明)。"""
|
|
357
|
+
mark = f"- **{FROZEN_MARK}**:{finished}"
|
|
185
358
|
if who:
|
|
186
|
-
mark += f"
|
|
359
|
+
mark += f" · @{who}"
|
|
187
360
|
if FROZEN_RE.search(text or ""):
|
|
188
361
|
return text
|
|
189
|
-
return "\n".join(
|
|
362
|
+
return "\n".join(_insert_head_line(text.splitlines(), mark, "frozen")) + "\n"
|
|
190
363
|
|
|
191
364
|
|
|
192
365
|
def rewrite_label_line(
|
|
193
366
|
text: str, category: str | None, tags: Iterable[str] | None
|
|
194
367
|
) -> str:
|
|
195
|
-
"""改写头部的分类 /
|
|
368
|
+
"""改写头部的分类 / 标签行:有就地替换,没有就按头部顺序插进去。"""
|
|
196
369
|
line = label_line(category, tags)
|
|
197
370
|
lines = text.splitlines()
|
|
198
371
|
for i, ln in enumerate(lines):
|
|
199
372
|
if ln.startswith("## "):
|
|
200
373
|
break
|
|
201
|
-
if
|
|
374
|
+
if _META_LINE_RE.match(ln):
|
|
202
375
|
if line:
|
|
203
376
|
lines[i] = line
|
|
204
377
|
else:
|
|
@@ -206,7 +379,7 @@ def rewrite_label_line(
|
|
|
206
379
|
return "\n".join(lines) + "\n"
|
|
207
380
|
if not line:
|
|
208
381
|
return text
|
|
209
|
-
return "\n".join(
|
|
382
|
+
return "\n".join(_insert_head_line(lines, line, "meta")) + "\n"
|
|
210
383
|
|
|
211
384
|
|
|
212
385
|
def head_meta(text: str) -> tuple[str | None, tuple[str, ...]]:
|
|
@@ -226,8 +399,20 @@ def head_created(text: str) -> str | None:
|
|
|
226
399
|
return None
|
|
227
400
|
|
|
228
401
|
|
|
402
|
+
def head_frozen(text: str) -> str | None:
|
|
403
|
+
"""头部「封卷」行的时间(原样返回,不转时区);没封卷 / 读不到返回 None。"""
|
|
404
|
+
for line in text.splitlines():
|
|
405
|
+
m = _FROZEN_AT_RE.match(line)
|
|
406
|
+
if m:
|
|
407
|
+
try:
|
|
408
|
+
return normalize_time(m.group(1), field="封卷")
|
|
409
|
+
except Fail:
|
|
410
|
+
return None
|
|
411
|
+
return None
|
|
412
|
+
|
|
413
|
+
|
|
229
414
|
def head_creator(text: str) -> str | None:
|
|
230
|
-
"""
|
|
415
|
+
"""头部「创建」行的发起人**名字**(不带 @、不带 uuid);读不到返回 None。"""
|
|
231
416
|
for line in text.splitlines():
|
|
232
417
|
m = CREATOR_RE.match(line)
|
|
233
418
|
if m and m.group(1).strip():
|
|
@@ -236,7 +421,7 @@ def head_creator(text: str) -> str | None:
|
|
|
236
421
|
|
|
237
422
|
|
|
238
423
|
def head_creator_uuid(text: str) -> str | None:
|
|
239
|
-
"""
|
|
424
|
+
"""头部「创建」行的发起人 **uuid**;老文档没落 uuid 时返回 None。
|
|
240
425
|
|
|
241
426
|
`UUID_RE` 带 `^$` 锚点,只能整串匹配 —— 所以先按 ` · ` 切出尾段再判,不能 search。
|
|
242
427
|
"""
|
|
@@ -14,7 +14,7 @@ from pathlib import Path
|
|
|
14
14
|
from ..actions.query import HistoryQuery, ListQuery
|
|
15
15
|
from ..core.roots import as_root, root_of
|
|
16
16
|
from ..core.time import to_utc
|
|
17
|
-
from ..errors import BUSINESS, USAGE, Fail
|
|
17
|
+
from ..errors import BUSINESS, OK, USAGE, Fail
|
|
18
18
|
from . import render, runner
|
|
19
19
|
from .gitops import repo_sync_lock
|
|
20
20
|
|
|
@@ -99,11 +99,15 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
99
99
|
hist.add_argument("--json", action="store_true")
|
|
100
100
|
|
|
101
101
|
valp = sub.add_parser(
|
|
102
|
-
"validate",
|
|
102
|
+
"validate",
|
|
103
|
+
help="台账体检(默认浅度;--deep 历史读全部月份;两档都不读过程文档)",
|
|
103
104
|
)
|
|
104
105
|
valp.add_argument("--deep", action="store_true")
|
|
105
106
|
valp.add_argument("--json", action="store_true")
|
|
106
107
|
|
|
108
|
+
who = sub.add_parser("whoami", help="我是谁(本机身份;未初始化也照常回答)")
|
|
109
|
+
who.add_argument("--json", action="store_true")
|
|
110
|
+
|
|
107
111
|
initp = sub.add_parser("init", help="初始化本机身份(一台机器只一次)")
|
|
108
112
|
initp.add_argument("--claim", help="认领名册里已有的 uuid")
|
|
109
113
|
initp.add_argument("--new", action="store_true", dest="new_id", help="新建身份")
|
|
@@ -229,6 +233,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
229
233
|
to_query(args)
|
|
230
234
|
|
|
231
235
|
command = command_of(args)
|
|
236
|
+
if command == "whoami":
|
|
237
|
+
return _run_whoami(args)
|
|
232
238
|
if command == "init":
|
|
233
239
|
return _run_init(args)
|
|
234
240
|
try:
|
|
@@ -405,6 +411,22 @@ def _confirm(question: str) -> bool:
|
|
|
405
411
|
print("请输入 Y 或 N。")
|
|
406
412
|
|
|
407
413
|
|
|
414
|
+
def _run_whoami(args: argparse.Namespace) -> int:
|
|
415
|
+
"""只读机器身份:不解析台账、不碰 git、不看 `--repo`。
|
|
416
|
+
|
|
417
|
+
未初始化**不是错误**:照常回答(`uuid` / `name` 双 null),由调用方据此引导 init。
|
|
418
|
+
"""
|
|
419
|
+
from .. import env
|
|
420
|
+
|
|
421
|
+
try:
|
|
422
|
+
identity = env.read_identity()
|
|
423
|
+
except Fail as exc:
|
|
424
|
+
render.fail_message(exc)
|
|
425
|
+
return BUSINESS
|
|
426
|
+
render.whoami_view(identity, as_json=bool(getattr(args, "json", False)))
|
|
427
|
+
return OK
|
|
428
|
+
|
|
429
|
+
|
|
408
430
|
def _run_init(args: argparse.Namespace) -> int:
|
|
409
431
|
"""init 不进 runner、不解析台账、不碰 git:只写机器身份文件。
|
|
410
432
|
|
|
@@ -18,6 +18,7 @@ from ..actions.result import (
|
|
|
18
18
|
ShowResult,
|
|
19
19
|
ValidationReport,
|
|
20
20
|
)
|
|
21
|
+
from ..core.identity import Identity
|
|
21
22
|
from ..core.time import fmt_local
|
|
22
23
|
|
|
23
24
|
|
|
@@ -51,6 +52,23 @@ def _json(data: Any) -> None:
|
|
|
51
52
|
sys.stdout.write(json.dumps(data, ensure_ascii=False, indent=2) + "\n")
|
|
52
53
|
|
|
53
54
|
|
|
55
|
+
#: 任务 / 历史行里要转本机时区的时间字段(存盘一律 UTC,出门一律本机时区)。
|
|
56
|
+
TIME_FIELDS = ("created", "started", "updated", "finished")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def localize_times(data: dict) -> dict:
|
|
60
|
+
"""复制一份,把上面四个时间字段转成本机时区;其余字段原样。
|
|
61
|
+
|
|
62
|
+
**只动这四个**:任务号里嵌的时间戳、过程文档正文里的时间都不动(原文照旧)。
|
|
63
|
+
"""
|
|
64
|
+
out = dict(data)
|
|
65
|
+
for key in TIME_FIELDS:
|
|
66
|
+
value = out.get(key)
|
|
67
|
+
if value:
|
|
68
|
+
out[key] = fmt_local(value)
|
|
69
|
+
return out
|
|
70
|
+
|
|
71
|
+
|
|
54
72
|
def result(res: Result, *, as_json: bool) -> None:
|
|
55
73
|
"""写动作:一律人话(`--json` 不挂写动作,传进来也按人话打)。"""
|
|
56
74
|
del as_json
|
|
@@ -71,7 +89,7 @@ def result(res: Result, *, as_json: bool) -> None:
|
|
|
71
89
|
|
|
72
90
|
def list_view(res: ListResult, q: ListQuery | None, *, as_json: bool) -> None:
|
|
73
91
|
if as_json:
|
|
74
|
-
_json({tid: task for tid, task in res.rows.items()})
|
|
92
|
+
_json({tid: localize_times(task) for tid, task in res.rows.items()})
|
|
75
93
|
return
|
|
76
94
|
if not res.table:
|
|
77
95
|
_out("没有符合条件的在办任务。")
|
|
@@ -84,11 +102,33 @@ def list_view(res: ListResult, q: ListQuery | None, *, as_json: bool) -> None:
|
|
|
84
102
|
_err(line)
|
|
85
103
|
|
|
86
104
|
|
|
105
|
+
def whoami_view(identity: Identity | None, *, as_json: bool) -> None:
|
|
106
|
+
"""本机身份:未初始化给 `uuid` / `name` 双 null(不是错误,调用方据此引导 init)。"""
|
|
107
|
+
if as_json:
|
|
108
|
+
_json(
|
|
109
|
+
{
|
|
110
|
+
"uuid": identity.uuid if identity else None,
|
|
111
|
+
"name": identity.name if identity else None,
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
return
|
|
115
|
+
if identity is None:
|
|
116
|
+
_out("这台机器还没有初始化身份。")
|
|
117
|
+
_out(
|
|
118
|
+
" 处理:请用户在自己的终端运行 "
|
|
119
|
+
"`progress.py init --repo <工作区根>`,由 ta 亲自选择/新建并确认。"
|
|
120
|
+
)
|
|
121
|
+
return
|
|
122
|
+
_out(f"@{identity.label()} {identity.uuid}")
|
|
123
|
+
|
|
124
|
+
|
|
87
125
|
def show_view(res: ShowResult, *, as_json: bool) -> None:
|
|
88
126
|
if as_json:
|
|
89
127
|
_json(
|
|
90
128
|
{
|
|
91
|
-
"task": res.task,
|
|
129
|
+
"task": localize_times(res.task),
|
|
130
|
+
# 文档自述还是回退查在办:调用方据此知道字段来源(老文档 / 文档缺失)
|
|
131
|
+
"legacy": res.legacy,
|
|
92
132
|
"worklog": {
|
|
93
133
|
"path": res.worklog.path if res.worklog else None,
|
|
94
134
|
"text": res.worklog.text if res.worklog else None,
|
|
@@ -125,11 +165,15 @@ def history_view(res: HistoryResult, q: HistoryQuery | None, *, as_json: bool) -
|
|
|
125
165
|
_json({"count": res.count, "capped": res.capped})
|
|
126
166
|
return
|
|
127
167
|
if as_json:
|
|
168
|
+
filters = dict(res.filters)
|
|
169
|
+
for key in ("since", "until"):
|
|
170
|
+
if filters.get(key):
|
|
171
|
+
filters[key] = fmt_local(filters[key])
|
|
128
172
|
_json(
|
|
129
173
|
{
|
|
130
174
|
"count": res.count,
|
|
131
|
-
"filters":
|
|
132
|
-
"records":
|
|
175
|
+
"filters": filters,
|
|
176
|
+
"records": [localize_times(row) for row in res.records],
|
|
133
177
|
"warnings": list(res.warnings),
|
|
134
178
|
"capped": res.capped,
|
|
135
179
|
}
|
|
@@ -23,7 +23,8 @@ from .atomic import ensure_dir, write_text_atomic
|
|
|
23
23
|
|
|
24
24
|
FALLBACK_TEMPLATE = """# <id>:<title>
|
|
25
25
|
|
|
26
|
-
>
|
|
26
|
+
- **状态**:<status>
|
|
27
|
+
- **创建**:<created> · @<creator>
|
|
27
28
|
|
|
28
29
|
## 背景
|
|
29
30
|
|
|
@@ -131,9 +132,10 @@ class WorklogStore:
|
|
|
131
132
|
creator: str,
|
|
132
133
|
category: str | None = None,
|
|
133
134
|
tags: tuple[str, ...] = (),
|
|
135
|
+
status: worklog_md.StatusLine | None = None,
|
|
134
136
|
first_exec: str | None = None,
|
|
135
137
|
) -> Path:
|
|
136
|
-
"""
|
|
138
|
+
"""一次写完整篇(含状态行与首条执行记录)。返回绝对路径。"""
|
|
137
139
|
rel = worklog_rel(tid, created)
|
|
138
140
|
path = self.repo / to_repo_rel(rel)
|
|
139
141
|
ensure_dir(path.parent)
|
|
@@ -144,6 +146,7 @@ class WorklogStore:
|
|
|
144
146
|
creator=creator,
|
|
145
147
|
category=category,
|
|
146
148
|
tags=tags,
|
|
149
|
+
status=status,
|
|
147
150
|
template=self.template(),
|
|
148
151
|
)
|
|
149
152
|
if first_exec:
|
|
@@ -155,14 +158,23 @@ class WorklogStore:
|
|
|
155
158
|
"""写回「锚点编辑后的新全文」;不许用它替换前五节正文。"""
|
|
156
159
|
write_text_atomic(path, text)
|
|
157
160
|
|
|
158
|
-
def append_exec(
|
|
159
|
-
|
|
161
|
+
def append_exec(
|
|
162
|
+
self, path: Path, line: str, *, status: worklog_md.StatusLine | None = None
|
|
163
|
+
) -> bool:
|
|
164
|
+
"""追加一条执行记录,并在**同一次写盘**里顺带刷新头部状态行(`status` 给了才刷)。
|
|
165
|
+
|
|
166
|
+
写不进返回 False,**不抛**(调用方自己决定报不报)。状态行与执行记录必须一起落地:
|
|
167
|
+
分两写就会留下「记录写了、状态没刷」这种不报错的不一致。
|
|
168
|
+
"""
|
|
160
169
|
try:
|
|
161
170
|
text = path.read_text(encoding="utf-8-sig")
|
|
162
171
|
except (OSError, UnicodeDecodeError):
|
|
163
172
|
return False
|
|
164
173
|
try:
|
|
165
|
-
|
|
174
|
+
new = worklog_md.append_exec_log(text, line)
|
|
175
|
+
if status is not None:
|
|
176
|
+
new = worklog_md.rewrite_status_line(new, status)
|
|
177
|
+
write_text_atomic(path, new)
|
|
166
178
|
except Exception: # noqa: BLE001 —— 写不进是这条记录的失败,不该掀翻整条命令
|
|
167
179
|
return False
|
|
168
180
|
return True
|