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
package/README.md
CHANGED
|
@@ -31,9 +31,11 @@
|
|
|
31
31
|
直接跑:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
|
|
34
|
+
<SKILL.md 所在目录>/scripts/progress <子命令> --repo <工作区根>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
`scripts/progress` 按平台 exec `scripts/bin/ledger-<os>-<arch>`(静态二进制;已带 linux/amd64、darwin/arm64 与 windows/amd64)。
|
|
38
|
+
|
|
37
39
|
子命令:`new` `claim` `set` `log` `close` `list` `history` `show` `whoami` `validate`。命令参考(参数 / 一句话 / 举例)、任务生命周期、纪律(数据完整性 / 人类授权 / 故障处置)全在 `SKILL.md`;参数细节看 `<子命令> --help`(不要凭记忆编)。
|
|
38
40
|
|
|
39
41
|
## 深入参考(references/,按需读)
|
|
@@ -46,4 +48,4 @@ python3 <SKILL.md 所在目录>/scripts/progress.py <子命令> --repo <工作
|
|
|
46
48
|
|
|
47
49
|
## 本仓自己的台账
|
|
48
50
|
|
|
49
|
-
本仓库(`dsh-task-ledger
|
|
51
|
+
本仓库(`dsh-task-ledger`)也用自己的这套脚本(`scripts/progress` → `src/` 编译出的二进制)管自己的活,台账数据在 `ledger/`;它和本 skill 源码 `packages/skill/` 是两回事 —— **改 skill 请别动 `ledger/`**。
|
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.30
|
|
5
5
|
allowed-tools: Read,Edit,Bash,Grep
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -92,7 +92,7 @@ allowed-tools: Read,Edit,Bash,Grep
|
|
|
92
92
|
|
|
93
93
|
干什么:刷任务的最后进度时间 + 在过程文档「执行记录」节追加一行。改正文必配一条 log(见纪律)。
|
|
94
94
|
|
|
95
|
-
举例:一轮干完 → `log --id <任务号> --note "改了认领即 doing(claim.
|
|
95
|
+
举例:一轮干完 → `log --id <任务号> --note "改了认领即 doing(internal/actions/claim.go:56);下一步同步文档"`。
|
|
96
96
|
|
|
97
97
|
### close — 结案
|
|
98
98
|
|
|
@@ -175,9 +175,11 @@ allowed-tools: Read,Edit,Bash,Grep
|
|
|
175
175
|
## 怎么调用
|
|
176
176
|
|
|
177
177
|
```bash
|
|
178
|
-
|
|
178
|
+
<本 SKILL.md 所在目录>/scripts/progress <子命令> --repo <工作区根>
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
+
`scripts/progress` 是个薄 shell 包装,按平台 exec `scripts/bin/ledger-<os>-<arch>`(自带运行时的静态二进制;已提供 linux/amd64、darwin/arm64 与 windows/amd64)。平台或架构没有对应产物时,它会明确报错,不会静默失败。
|
|
182
|
+
|
|
181
183
|
- 定位项目:`--repo <工作区根>`(**直接含有 `ledger/` 的那个目录**)给了就校验后用;不给就从当前目录逐级向上找。`ledger/` 本身、以及它下面的任何子目录都不是根,指过去会被直接拒绝(判据只看位置,不看目录里有哪些文件 —— 项目根自带 `pool.json`、`history/`、`worklog/` 都不影响)。
|
|
182
184
|
- `--no-sync`(放在子命令**前**):用户明确要求「先别同步」时才用;之后自己 `git add ledger && commit && push`。
|
|
183
185
|
- `--json` 只对只读命令(`list` / `show` / `history` / `whoami` / `validate`)有意义;写命令不接收 `--json`,传了是用法错。
|
package/assets/worklog.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "task-ledger",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.30",
|
|
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",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
1. 只读报名单(你在非终端里裸跑,只会打印候选、零写):
|
|
12
12
|
|
|
13
13
|
```
|
|
14
|
-
|
|
14
|
+
<本 SKILL.md 所在目录>/scripts/progress init --repo <工作区根>
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
2. 把名册给用户选,并把这**同一条命令**交给用户在 ta 自己的终端跑(真终端里它自己会变成 ↑/↓
|
|
17
|
+
2. 把名册给用户选,并把这**同一条命令**交给用户在 ta 自己的终端跑(真终端里它自己会变成 ↑/↓ 选择框:↑/↓ 移动、Enter 确认、末尾「+ 新建身份」输入名字、最后 Y/N 确认、ESC/Ctrl-C 取消):
|
|
18
18
|
- 名册有内容 ⇒「名册现有:@A(uuid)、@B(uuid)。请在你的终端运行上面这条,它会让你选。」
|
|
19
19
|
- 名册为空 ⇒「名册为空。请在你的终端运行上面这条,输入一个用户名新建。」
|
|
20
20
|
|
|
@@ -26,7 +26,7 @@ python3 <本 SKILL.md 所在目录>/scripts/progress.py init --repo <工作区
|
|
|
26
26
|
|
|
27
27
|
## 硬规则
|
|
28
28
|
|
|
29
|
-
- **不诊断、不排查**:不要 `ls ~/.taskledger`、不要 `cat identity.json`、不要读 skill 源码(`env.
|
|
29
|
+
- **不诊断、不排查**:不要 `ls ~/.taskledger`、不要 `cat identity.json`、不要读 skill 源码(`internal/env/env.go` / `internal/actions/init_identity.go` 等)或台账去查「为什么没身份」。缺就是未初始化,忽略上下文里已做的排查动作,直接按上面流程走。
|
|
30
30
|
- **不得**替用户执行 `init --claim` / `init --new` / 任何带 `--yes` 的写法——脚本也会拒绝。
|
|
31
31
|
- **不得**基于「上一轮确认过 / 同名 / 记得 uuid」自行重建身份:身份文件缺失就是未初始化,必须让用户重新亲自选。重建会换新 uuid、断开旧任务关联。
|
|
32
32
|
- 不读 `ledger/*.json`、worklog、identity 文件去「自己看」。
|
package/references/log-note.md
CHANGED
|
@@ -117,7 +117,7 @@ notices(只提示):历史解析警告、历史有结案行但任务还在
|
|
|
117
117
|
- **写前**:先 guard 三查 —— scope 内非 worklog 台账文件有未提交改动 / 有未推送的台账提交 / 有未入库的同名文件,命中即中止;再定向取最新:自举 scope(`owners.json` + `pool.json` + 我的分片)加动作 scope(`new` 加目标文件与当月 worklog 目录;`claim` / `set` 还加索引里其他人的全部分片;`close` 加当月 `history/`;任务没有 `worklog` 字段时退整个 `worklog/`)。干净就刷成远端最新,本地有未提交手写改动就 stash → 快进 → 叠回,冲突即中止。`worklog/` 目录只刷新本地已存在的文件(上游新增的不会自动补下来)。
|
|
118
118
|
- **写后**:只 `git add` 台账路径,然后 `commit --no-verify` —— 提交失败退 1;push 失败只提示、退 0,被拒时自动 `rebase --autostash` 合并一次:不同任务自动合并,同一任务两边都改留冲突标记让人定;本地有非台账提交时不 rebase。
|
|
119
119
|
- **回滚**:命令失败时,写前刷下来的内容按字节还原、本次新建的文件删掉;业务写的自补偿只有两处 —— `new`(删任务行 + 删文档)、`close`(三个文件按字节还原)。
|
|
120
|
-
- **`--no-sync` / `TASK_LEDGER_NO_SYNC=1`**:跳过 guard、取最新、提交与推送;自举照跑;有写入时会提示「只写了本地文件、未签入 git」。注意它挂在**顶层**:`progress
|
|
120
|
+
- **`--no-sync` / `TASK_LEDGER_NO_SYNC=1`**:跳过 guard、取最新、提交与推送;自举照跑;有写入时会提示「只写了本地文件、未签入 git」。注意它挂在**顶层**:`progress --no-sync <子命令> …`,放子命令后面是用法错。
|
|
121
121
|
- **环境**:git ≥ 2.27(自动合并依赖 `rebase --autostash`)。不是 git 仓库 ⇒ 同步整体跳过、台账照写,并提示「只写了本地文件」;连 git 二进制都没装也照样写(身份只读本机 identity 文件,与 git 无关)。
|
|
122
122
|
|
|
123
123
|
## 硬约束
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/scripts/progress
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# 台账命令入口:只按平台选对二进制再 exec,逻辑全在编译产物里。
|
|
3
|
+
# 旧写法(Python 版已挪到 legacy-python/ 作对照):python3 legacy-python/progress.py <子命令> --repo <工作区根>
|
|
4
|
+
set -eu
|
|
5
|
+
|
|
6
|
+
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
7
|
+
|
|
8
|
+
case "$(uname -s)" in
|
|
9
|
+
Linux) os=linux ;;
|
|
10
|
+
Darwin) os=darwin ;;
|
|
11
|
+
MINGW* | MSYS* | CYGWIN*) os=windows ;;
|
|
12
|
+
*)
|
|
13
|
+
echo "错误:这个平台($(uname -s))还没有配套的台账二进制。" >&2
|
|
14
|
+
echo " 处理:在装有 Go 的机器上跑 packages/skill/go 的构建脚本,产出 scripts/bin/ledger-<os>-<arch>。" >&2
|
|
15
|
+
exit 1
|
|
16
|
+
;;
|
|
17
|
+
esac
|
|
18
|
+
|
|
19
|
+
case "$(uname -m)" in
|
|
20
|
+
x86_64 | amd64) arch=amd64 ;;
|
|
21
|
+
arm64 | aarch64) arch=arm64 ;;
|
|
22
|
+
*)
|
|
23
|
+
echo "错误:不认识的 CPU 架构($(uname -m)),没有配套的台账二进制。" >&2
|
|
24
|
+
exit 1
|
|
25
|
+
;;
|
|
26
|
+
esac
|
|
27
|
+
|
|
28
|
+
bin="$dir/bin/ledger-$os-$arch"
|
|
29
|
+
if [ "$os" = "windows" ]; then
|
|
30
|
+
bin="$bin.exe"
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
if [ ! -x "$bin" ]; then
|
|
34
|
+
# 打包 / 拷贝常常丢可执行位:自己救一次,救不回来再报错
|
|
35
|
+
chmod +x "$bin" 2>/dev/null || true
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
if [ ! -x "$bin" ]; then
|
|
39
|
+
echo "错误:找不到可执行的 $bin" >&2
|
|
40
|
+
echo " 处理:在装有 Go 的机器上跑 packages/skill/go 的构建脚本重新产出产物。" >&2
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
exec "$bin" "$@"
|
|
File without changes
|
|
File without changes
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"""事务的唯一入口,20 行:把这次要碰的文件按固定顺序一次锁住。
|
|
2
|
-
|
|
3
|
-
只加锁,不管写盘、不碰 git、不打印。
|
|
4
|
-
|
|
5
|
-
三条硬约束:
|
|
6
|
-
1. 锁集**只许宽不许窄**;锁集以外的文件一个字节都不许写。
|
|
7
|
-
2. **所有判定依据必须在锁内重读** —— 锁外读到的快照只能用来决定"锁多宽"。
|
|
8
|
-
3. **任何失败补偿都不许再开一个 `atom`**(文件锁不可重入),只能在同一事务内做完。
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
from __future__ import annotations
|
|
12
|
-
|
|
13
|
-
import contextlib
|
|
14
|
-
from collections.abc import Iterator
|
|
15
|
-
from dataclasses import dataclass
|
|
16
|
-
from pathlib import Path
|
|
17
|
-
from typing import Any
|
|
18
|
-
|
|
19
|
-
from ..core.identity import Identity, normalize
|
|
20
|
-
from ..core.paths import (
|
|
21
|
-
HISTORY_DIR,
|
|
22
|
-
OWNERS_REL,
|
|
23
|
-
POOL_REL,
|
|
24
|
-
WORKLOG_DIR,
|
|
25
|
-
history_path_for,
|
|
26
|
-
shard_rel,
|
|
27
|
-
worklog_dir_for,
|
|
28
|
-
worklog_rel,
|
|
29
|
-
)
|
|
30
|
-
from ..store.locks import ledger_lock
|
|
31
|
-
from ..store.owners_index import OwnersIndex
|
|
32
|
-
from ..store.task_store import TaskStore
|
|
33
|
-
|
|
34
|
-
ACTIONS = ("bootstrap", "new", "claim", "set", "log", "close", "tags")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@dataclass(frozen=True)
|
|
38
|
-
class Scope:
|
|
39
|
-
"""这次要碰哪些文件。`files` 加锁(也逐个刷),`dirs` 只刷盘(展开成已存在的文件)。"""
|
|
40
|
-
|
|
41
|
-
files: tuple[Path, ...] = ()
|
|
42
|
-
dirs: tuple[Path, ...] = ()
|
|
43
|
-
|
|
44
|
-
def __or__(self, other: Scope) -> Scope:
|
|
45
|
-
return Scope(
|
|
46
|
-
files=_merge(self.files, other.files),
|
|
47
|
-
dirs=_merge(self.dirs, other.dirs),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def _merge(a: tuple[Path, ...], b: tuple[Path, ...]) -> tuple[Path, ...]:
|
|
52
|
-
out: list[Path] = []
|
|
53
|
-
for item in (*a, *b):
|
|
54
|
-
if item not in out:
|
|
55
|
-
out.append(item)
|
|
56
|
-
return tuple(out)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def _pool(repo: Path) -> Path:
|
|
60
|
-
return POOL_REL
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def _shard(repo: Path, me: Identity) -> Path:
|
|
64
|
-
return shard_rel(me.uuid)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def _other_shards(repo: Path, me: Identity) -> tuple[Path, ...]:
|
|
68
|
-
"""索引里除我之外的分片(宁宽:认领的前置要查、交接要写对方那份)。"""
|
|
69
|
-
index = OwnersIndex(repo)
|
|
70
|
-
me_key = normalize(me.uuid)
|
|
71
|
-
out: list[Path] = []
|
|
72
|
-
for key, record in index.all().items():
|
|
73
|
-
if key == me_key:
|
|
74
|
-
continue
|
|
75
|
-
name = (record or {}).get("file")
|
|
76
|
-
if name:
|
|
77
|
-
out.append(Path("owners") / str(name))
|
|
78
|
-
return tuple(out)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def _worklog_of(
|
|
82
|
-
repo: Path, params: dict[str, Any]
|
|
83
|
-
) -> tuple[tuple[Path, ...], tuple[Path, ...]]:
|
|
84
|
-
"""这条任务的过程文档:查得到给文件,查不到退回整个 `worklog/` 目录(宁宽)。"""
|
|
85
|
-
tid = params.get("tid")
|
|
86
|
-
if not tid:
|
|
87
|
-
return (), (WORKLOG_DIR,)
|
|
88
|
-
pool = TaskStore(repo, POOL_REL)
|
|
89
|
-
task = pool.get(str(tid))
|
|
90
|
-
if task is None:
|
|
91
|
-
index = OwnersIndex(repo)
|
|
92
|
-
for path in index.shards().values():
|
|
93
|
-
rel = Path(path).relative_to(repo / "ledger")
|
|
94
|
-
task = TaskStore(repo, rel).get(str(tid))
|
|
95
|
-
if task is not None:
|
|
96
|
-
break
|
|
97
|
-
worklog = (task or {}).get("worklog")
|
|
98
|
-
if worklog:
|
|
99
|
-
return (Path(worklog),), ()
|
|
100
|
-
return (), (WORKLOG_DIR,)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def lock_scope(repo: Path, me: Identity, action: str, params: dict[str, Any]) -> Scope:
|
|
104
|
-
"""算出这次可能碰哪些文件(**在锁外跑**,宁可算宽)。七个分支与 §四 的表逐行对应。"""
|
|
105
|
-
if action not in ACTIONS:
|
|
106
|
-
raise ValueError(f"未知的 lock_scope action:{action!r}")
|
|
107
|
-
mine = _shard(repo, me)
|
|
108
|
-
pool = _pool(repo)
|
|
109
|
-
index = OWNERS_REL
|
|
110
|
-
others = _other_shards(repo, me)
|
|
111
|
-
|
|
112
|
-
if action == "bootstrap":
|
|
113
|
-
return Scope(files=(index, pool, mine))
|
|
114
|
-
|
|
115
|
-
if action == "new":
|
|
116
|
-
mine_flag = bool(params.get("mine"))
|
|
117
|
-
target = mine if mine_flag else pool
|
|
118
|
-
created = params.get("created") or ""
|
|
119
|
-
tid = params.get("tid")
|
|
120
|
-
# 本次要新建那篇文档:路径算得出来(锁集允许含不存在的路径),不放进去写集就超出锁集
|
|
121
|
-
doc = (
|
|
122
|
-
(Path(worklog_rel(str(tid), created)),) if tid and len(created) >= 7 else ()
|
|
123
|
-
)
|
|
124
|
-
month_dir = worklog_dir_for(created) if len(created) >= 7 else WORKLOG_DIR
|
|
125
|
-
return Scope(files=(target, *doc), dirs=(month_dir,))
|
|
126
|
-
|
|
127
|
-
if action == "claim":
|
|
128
|
-
wfiles, wdirs = _worklog_of(repo, params)
|
|
129
|
-
return Scope(files=(pool, mine, *others, *wfiles), dirs=wdirs)
|
|
130
|
-
|
|
131
|
-
if action == "set":
|
|
132
|
-
wfiles, wdirs = _worklog_of(repo, params)
|
|
133
|
-
# 分支取并集:release 写池、handoff 写对方分片、指向自己且未认领先认领(写我的分片);已在名下则空转不写盘
|
|
134
|
-
return Scope(files=(mine, pool, *others, *wfiles), dirs=wdirs)
|
|
135
|
-
|
|
136
|
-
if action == "log":
|
|
137
|
-
wfiles, wdirs = _worklog_of(repo, params)
|
|
138
|
-
return Scope(files=(mine, *wfiles), dirs=wdirs)
|
|
139
|
-
|
|
140
|
-
if action == "close":
|
|
141
|
-
wfiles, wdirs = _worklog_of(repo, params)
|
|
142
|
-
finished = params.get("finished") or ""
|
|
143
|
-
history = history_path_for(finished) if len(finished) >= 7 else HISTORY_DIR
|
|
144
|
-
return Scope(files=(mine, history, *wfiles), dirs=wdirs)
|
|
145
|
-
|
|
146
|
-
# 六个分支已覆盖 ACTIONS 全集(入口校验在前),走到这里说明表与分支不同步
|
|
147
|
-
raise ValueError(f"lock_scope 没有处理 {action!r}")
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
@contextlib.contextmanager
|
|
151
|
-
def atom(repo: Path, *rels: Path) -> Iterator[None]:
|
|
152
|
-
"""按路径排序后依次加锁,退出即完成。不建记账本、不写盘、不提交、不打印。"""
|
|
153
|
-
with ledger_lock(repo, *rels):
|
|
154
|
-
yield
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"""开工前的自举:台账文件不存在就建,没登记过就把自己登记进去、建自己的分片。
|
|
2
|
-
|
|
3
|
-
这三份由**外壳**单独一个 `atom` 包住,它自己不开事务、不拿锁。
|
|
4
|
-
不参与「提交说明 / where / 打印」。
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
|
|
11
|
-
from ..core.identity import Identity
|
|
12
|
-
from ..core.paths import LEDGER_DIR, OWNERS_DIR, POOL_REL, shard_rel, to_repo_rel
|
|
13
|
-
from ..core.roots import as_root
|
|
14
|
-
from ..store.atomic import ensure_dir
|
|
15
|
-
from ..store.owners_index import OwnersIndex
|
|
16
|
-
from ..store.task_store import TaskStore
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def bootstrap(repo: Path, me: Identity) -> Identity:
|
|
20
|
-
"""写序:`owners/` 目录 → 池 → **我的分片 → 索引(登记自己)**。已登记 ⇒ 零写。
|
|
21
|
-
|
|
22
|
-
分片必须排在登记之**前**:反过来的话,硬崩(SIGKILL / 断电)正好落在两步之间,
|
|
23
|
-
会留下「索引里有我、磁盘上没有我的分片」——此后**所有人**的 list / show 都在
|
|
24
|
-
`assert_present` 处报「登记的任务文件找不到了」,而 `ensure` 看到记录已存在就零写,
|
|
25
|
-
这个坏状态永远不自愈。按现在的顺序崩,最多留一份孤儿分片(`validate` 会报出来),
|
|
26
|
-
下一条写命令 bootstrap 时会把它登记回去。
|
|
27
|
-
"""
|
|
28
|
-
repo = as_root(
|
|
29
|
-
repo, source="工作区根"
|
|
30
|
-
) # 门 3:写前最后确认,绝不在 ledger/ 里再套一层
|
|
31
|
-
ensure_dir(repo / LEDGER_DIR) # 曾是 to_repo_rel(LEDGER_DIR) ⇒ 会拼出 ledger/ledger
|
|
32
|
-
ensure_dir(repo / to_repo_rel(OWNERS_DIR))
|
|
33
|
-
TaskStore(repo, POOL_REL).ensure_file()
|
|
34
|
-
TaskStore(repo, shard_rel(me.uuid), identity=me).ensure_file()
|
|
35
|
-
index = OwnersIndex(repo)
|
|
36
|
-
_, _ = index.ensure(me) # 登记自己(已登记则零写)
|
|
37
|
-
return me
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"""认领:先写进我的分片,再删池里那行。**顺序反了任务会凭空消失**。"""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
from ..core.identity import Identity, normalize
|
|
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.owners_index import OwnersIndex
|
|
13
|
-
from ..store.task_store import TaskStore
|
|
14
|
-
from ..store.worklog_store import WorklogStore
|
|
15
|
-
from .result import Result, rel
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def claim(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
|
-
me_key = normalize(me.uuid)
|
|
23
|
-
|
|
24
|
-
# 前置:别人正在改它(他的分片里已有这个号)⇒ 拒绝
|
|
25
|
-
for key, path in OwnersIndex(repo).shards().items():
|
|
26
|
-
if key == me_key:
|
|
27
|
-
continue
|
|
28
|
-
other = TaskStore(repo, Path(path).relative_to(repo / "ledger"))
|
|
29
|
-
if other.get(tid) is not None:
|
|
30
|
-
raise Fail(f"任务 {tid} 已在 {key} 的分片里(别人正在做),不能认领。")
|
|
31
|
-
|
|
32
|
-
task = pool.get(tid) # 锁内重读
|
|
33
|
-
if task is None:
|
|
34
|
-
already = mine.get(tid)
|
|
35
|
-
if already is not None:
|
|
36
|
-
# 重跑:分片里已有这个号(上次崩了一半)⇒ 只补删池里那行
|
|
37
|
-
pool.drop(tid)
|
|
38
|
-
logs = WorklogStore(repo)
|
|
39
|
-
path = logs.find(tid, already.get("worklog"))
|
|
40
|
-
if path is not None:
|
|
41
|
-
logs.append_exec(
|
|
42
|
-
path,
|
|
43
|
-
exec_line(now(), me.uuid, "claim", "认领(补齐上次未完成的清理)"),
|
|
44
|
-
status=StatusLine("doing", me.name, me.uuid, now()),
|
|
45
|
-
)
|
|
46
|
-
return Result(
|
|
47
|
-
already_done=True,
|
|
48
|
-
where=rel(repo, mine.path),
|
|
49
|
-
message=f"认领 {tid}:补齐上次未完成的清理",
|
|
50
|
-
notices=(f"任务 {tid} 已经在我的分片里,本次只补删公共池那行。",),
|
|
51
|
-
)
|
|
52
|
-
raise Fail(f"公共池里没有任务 {tid}(已经被人认领或不存在)。")
|
|
53
|
-
|
|
54
|
-
current = task.get("status")
|
|
55
|
-
if current != "open":
|
|
56
|
-
raise Fail(
|
|
57
|
-
f"任务 {tid} 在公共池里但状态是 {current}(应为 open)—— "
|
|
58
|
-
"先跑 validate 看台账是不是乱了。"
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
moved = dict(task)
|
|
62
|
-
moved["owner"] = me.uuid
|
|
63
|
-
moved["owner_name"] = me.name
|
|
64
|
-
# 认领即在做:看板把 doing 当「我的在办」算(home.service.ts),置 open 会让
|
|
65
|
-
# 认领后的任务看起来仍没人领。旧版 progress.py 置 doing,分片重构时丢了。
|
|
66
|
-
moved["status"] = "doing"
|
|
67
|
-
moved["started"] = moved.get("started") or now()
|
|
68
|
-
moved["updated"] = now()
|
|
69
|
-
mine.put(tid, moved)
|
|
70
|
-
pool.drop(tid)
|
|
71
|
-
|
|
72
|
-
note = f"任务 {tid} 已记到我的分片,过程文档没找到,跳过执行记录。"
|
|
73
|
-
logs = WorklogStore(repo)
|
|
74
|
-
path = logs.find(tid, moved.get("worklog"))
|
|
75
|
-
if path is not None:
|
|
76
|
-
logs.append_exec(
|
|
77
|
-
path,
|
|
78
|
-
exec_line(now(), me.stamp(), "claim", "认领 → doing"),
|
|
79
|
-
status=StatusLine("doing", me.name, me.uuid, now()),
|
|
80
|
-
)
|
|
81
|
-
note = None
|
|
82
|
-
return Result(
|
|
83
|
-
changed=("owner", "started", "updated"),
|
|
84
|
-
where=rel(repo, mine.path),
|
|
85
|
-
message=f"认领 {tid}:{moved.get('title') or ''}".strip(),
|
|
86
|
-
payload={},
|
|
87
|
-
notices=(note,) if note else (),
|
|
88
|
-
)
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"""结案:历史加一行 → 封卷过程文档 → **最后**删分片那行。
|
|
2
|
-
|
|
3
|
-
`finished` 必填、由外壳算好(同一个值也用于算锁集与刷取范围)—— 业务层不许再调时钟,
|
|
4
|
-
这是跨月刷错月份的唯一根因。
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
|
|
11
|
-
from ..core.identity import Identity
|
|
12
|
-
from ..core.labels import parse_tags
|
|
13
|
-
from ..core.paths import history_path_for, shard_rel, to_repo_rel, worklog_name
|
|
14
|
-
from ..core.worklog_md import (
|
|
15
|
-
StatusLine,
|
|
16
|
-
append_exec_log,
|
|
17
|
-
exec_line,
|
|
18
|
-
has_frozen_line,
|
|
19
|
-
rewrite_label_line,
|
|
20
|
-
rewrite_status_line,
|
|
21
|
-
stamp_frozen,
|
|
22
|
-
)
|
|
23
|
-
from ..errors import Fail
|
|
24
|
-
from ..store.atomic import ensure_dir, fingerprint, restore, snapshot
|
|
25
|
-
from ..store.history_store import HIT, UNDECIDABLE, HistoryStore
|
|
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 close_task(
|
|
33
|
-
repo: Path,
|
|
34
|
-
me: Identity,
|
|
35
|
-
tid: str,
|
|
36
|
-
*,
|
|
37
|
-
summary: str,
|
|
38
|
-
finished: str,
|
|
39
|
-
tags: tuple[str, ...] | None = None,
|
|
40
|
-
) -> Result:
|
|
41
|
-
"""写序四步:改标签行 → 历史加一行 → 封卷 → 删分片(永远是最后一步)。"""
|
|
42
|
-
if not finished:
|
|
43
|
-
raise Fail("结案必须由外壳先算好时间(内部错误:finished 为空)。")
|
|
44
|
-
text_summary = " ".join((summary or "").split())
|
|
45
|
-
if not text_summary:
|
|
46
|
-
raise Fail("结案要写一句「完成了什么」(--summary 不能为空)。")
|
|
47
|
-
new_tags = parse_tags(tags) if tags else None
|
|
48
|
-
|
|
49
|
-
logs = WorklogStore(repo)
|
|
50
|
-
history = HistoryStore(repo)
|
|
51
|
-
hist_path = repo / to_repo_rel(history_path_for(finished))
|
|
52
|
-
|
|
53
|
-
mine = TaskStore(repo, shard_rel(me.uuid), identity=me)
|
|
54
|
-
task = mine.get(tid) # 锁内重读
|
|
55
|
-
if task is None:
|
|
56
|
-
# 分片里已经没有这条:上次崩在「删分片」之后。只按过程文档名判重,命中即已结案
|
|
57
|
-
state = history.has_log(
|
|
58
|
-
hist_path, log_name=worklog_name(tid), created=None, title=None
|
|
59
|
-
)
|
|
60
|
-
if state == HIT:
|
|
61
|
-
return Result(
|
|
62
|
-
already_done=True,
|
|
63
|
-
where=rel(repo, hist_path),
|
|
64
|
-
notices=(f"任务 {tid} 已经结过案,无需重复。",),
|
|
65
|
-
)
|
|
66
|
-
raise Fail(f"任务 {tid} 不在我的分片里(只能结案自己的任务)。")
|
|
67
|
-
|
|
68
|
-
# 分片里在、但行内 owner 不是我 ⇒ 台账脏了(validate 会报⑤):先拦下来,别用我的 uuid 记历史
|
|
69
|
-
require_owner(task, tid, me)
|
|
70
|
-
|
|
71
|
-
# 分类取任务原值(**不可改**);标签给了参数用新值,没给沿用原值
|
|
72
|
-
final_category = task.get("category")
|
|
73
|
-
final_tags = tuple(new_tags) if new_tags else tuple(task.get("tags") or ())
|
|
74
|
-
|
|
75
|
-
doc_path = logs.find(tid, task.get("worklog"))
|
|
76
|
-
|
|
77
|
-
# 写前核对:指纹任一变了就中止,同时留三份字节备用
|
|
78
|
-
paths = [p for p in (mine.path, hist_path, doc_path) if p is not None]
|
|
79
|
-
stamps = {p: fingerprint(p) for p in paths}
|
|
80
|
-
backups = {p: snapshot(p) for p in paths}
|
|
81
|
-
|
|
82
|
-
try:
|
|
83
|
-
log_name = Path(doc_path).name if doc_path else None
|
|
84
|
-
state = history.has_log(
|
|
85
|
-
hist_path,
|
|
86
|
-
log_name=log_name,
|
|
87
|
-
created=task.get("created"),
|
|
88
|
-
title=task.get("title"),
|
|
89
|
-
)
|
|
90
|
-
if state == HIT:
|
|
91
|
-
# 崩在②(历史行已写)之后、③/④之前:历史里已有,但分片行可能还在、
|
|
92
|
-
# 过程文档可能还没封卷。不补齐就留下「已结案却仍在办」的僵尸 ——
|
|
93
|
-
# 它还能收 log,甚至被释放推回公共池让别人认领(2026-10-24 修)。
|
|
94
|
-
notes = [f"任务 {tid} 已经结过案,无需重复。"]
|
|
95
|
-
if doc_path is not None:
|
|
96
|
-
text = logs.read(doc_path)
|
|
97
|
-
if not has_frozen_line(text):
|
|
98
|
-
frozen = stamp_frozen(text, finished, me.stamp())
|
|
99
|
-
frozen = append_exec_log(
|
|
100
|
-
frozen, exec_line(finished, me.stamp(), "close", "结案封卷")
|
|
101
|
-
)
|
|
102
|
-
frozen = rewrite_status_line(
|
|
103
|
-
frozen, StatusLine("closed", me.name, me.uuid, finished)
|
|
104
|
-
)
|
|
105
|
-
logs.write(doc_path, frozen)
|
|
106
|
-
notes.append("补齐上次未完成的封卷。")
|
|
107
|
-
if mine.get(tid) is not None:
|
|
108
|
-
mine.drop(tid)
|
|
109
|
-
notes.append("补齐上次未完成的移出分片。")
|
|
110
|
-
return Result(
|
|
111
|
-
already_done=True,
|
|
112
|
-
where=rel(repo, hist_path),
|
|
113
|
-
notices=tuple(notes),
|
|
114
|
-
)
|
|
115
|
-
if state == UNDECIDABLE:
|
|
116
|
-
raise Fail(
|
|
117
|
-
f"历史里有一条没有过程文档链接的旧行,判不出是不是 {tid} ⇒ 已中止,"
|
|
118
|
-
f"请人工看一眼 {rel(repo, hist_path)} 再重跑。"
|
|
119
|
-
)
|
|
120
|
-
# 写前核对(2026-10-23 补):三个文件的指纹与读到时不一致 ⇒ 有人在锁外动过,
|
|
121
|
-
# 一个字节都不写(snapshot 那份留着给下面的异常分支按字节退回)。
|
|
122
|
-
for path in paths:
|
|
123
|
-
if fingerprint(path) != stamps[path]:
|
|
124
|
-
raise Fail(
|
|
125
|
-
f"{rel(repo, path)} 在本命令执行期间被改动过"
|
|
126
|
-
"(可能是编辑器或 git 操作),已中止、未写入任何内容;重跑一次即可。"
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
# ① 改标签行(给了 --tags 才做,且必须在封卷之前)
|
|
130
|
-
if doc_path is not None and new_tags:
|
|
131
|
-
text = logs.read(doc_path)
|
|
132
|
-
logs.write(doc_path, rewrite_label_line(text, final_tags))
|
|
133
|
-
|
|
134
|
-
# ② 历史加一行(先 ensure_dir:首次结案时 history/ 可能还不存在)
|
|
135
|
-
ensure_dir(hist_path.parent)
|
|
136
|
-
out = history.append_row(
|
|
137
|
-
hist_path,
|
|
138
|
-
{
|
|
139
|
-
"finished": finished,
|
|
140
|
-
"created": task.get("created"),
|
|
141
|
-
"title": task.get("title") or "",
|
|
142
|
-
"category": final_category,
|
|
143
|
-
"tags": final_tags,
|
|
144
|
-
# 历史里 uuid 与名字**都落盘**:uuid 是判定键(`@` + 裸 uuid,
|
|
145
|
-
# `--owner` / `--mine` 比它),名字是**结案那一刻的快照** —— 之后改名
|
|
146
|
-
# 不回写旧行,看历史看到的就是当时那个名字。
|
|
147
|
-
# 取值优先用任务行里认领 / 建任务时写下的那份;老任务没有就留空,不编造。
|
|
148
|
-
"owner": me.uuid,
|
|
149
|
-
"owner_name": task.get("owner_name") or me.name,
|
|
150
|
-
"creator": task.get("creator") or me.uuid,
|
|
151
|
-
"creator_name": task.get("creator_name"),
|
|
152
|
-
"summary": text_summary,
|
|
153
|
-
"worklog": task.get("worklog") if doc_path else None,
|
|
154
|
-
},
|
|
155
|
-
)
|
|
156
|
-
history.write(hist_path, out["text"])
|
|
157
|
-
|
|
158
|
-
# ③ 封卷(没有过程文档就跳过)
|
|
159
|
-
if doc_path is not None:
|
|
160
|
-
text = logs.read(doc_path)
|
|
161
|
-
if not has_frozen_line(text):
|
|
162
|
-
frozen = stamp_frozen(text, finished, me.stamp())
|
|
163
|
-
frozen = append_exec_log(
|
|
164
|
-
frozen, exec_line(finished, me.stamp(), "close", "结案封卷")
|
|
165
|
-
)
|
|
166
|
-
frozen = rewrite_status_line(
|
|
167
|
-
frozen, StatusLine("closed", me.name, me.uuid, finished)
|
|
168
|
-
)
|
|
169
|
-
logs.write(doc_path, frozen)
|
|
170
|
-
|
|
171
|
-
# ④ 删我分片那行(永远最后)
|
|
172
|
-
mine.drop(tid)
|
|
173
|
-
except Exception:
|
|
174
|
-
for path in paths:
|
|
175
|
-
if path in backups:
|
|
176
|
-
restore(path, backups[path])
|
|
177
|
-
raise
|
|
178
|
-
|
|
179
|
-
notices: list[str] = []
|
|
180
|
-
if doc_path is None:
|
|
181
|
-
notices.append(f"提示:任务 {tid} 没有过程文档,已跳过封卷,历史末列留空。")
|
|
182
|
-
return Result(
|
|
183
|
-
changed=("status", "finished"),
|
|
184
|
-
where=rel(repo, hist_path),
|
|
185
|
-
message=f"结案 {tid}:{task.get('title') or ''}".strip(),
|
|
186
|
-
payload={
|
|
187
|
-
"history_path": rel(repo, hist_path),
|
|
188
|
-
"worklog_path": rel(repo, doc_path) if doc_path else None,
|
|
189
|
-
},
|
|
190
|
-
notices=tuple(notices),
|
|
191
|
-
)
|