hive-tasks 1.11.0 → 1.11.1
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/CHANGELOG.md +24 -0
- package/README.md +5 -0
- package/README.zh-CN.md +4 -0
- package/SPEC.md +9 -0
- package/package.json +1 -1
- package/src/cli.js +3 -1
- package/src/store.js +89 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@ All notable changes to this project are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [1.11.1] - 2026-12-06
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- A board write no longer leaves its temporary Git index in `.hive/`: the
|
|
12
|
+
`GIT_INDEX_FILE` lives under `os.tmpdir()` with a unique pid+random name, is
|
|
13
|
+
registered for exit cleanup and is always removed by `finally` on success and on
|
|
14
|
+
thrown errors. Killed writers previously leaked binary `index-tasks-*` files into
|
|
15
|
+
the repository (82 were found in a real checkout).
|
|
16
|
+
- Command startup sweeps stale temp index files: legacy `index-tasks-*` in the state
|
|
17
|
+
dir and current `hive-tasks-index-*` in `os.tmpdir()` are removed when older than
|
|
18
|
+
ten minutes and their embedded pid is no longer alive; fresh files and files owned
|
|
19
|
+
by a live process are kept.
|
|
20
|
+
|
|
21
|
+
### Tests
|
|
22
|
+
|
|
23
|
+
- `test/temp-index.test.mjs`: a successful write leaves no files in `.hive/` or the
|
|
24
|
+
temp dir, a throwing write still cleans up (and the board stays readable), and the
|
|
25
|
+
startup sweep removes stale dead-pid files while keeping live/fresh ones.
|
|
26
|
+
|
|
7
27
|
## [1.11.0] - 2026-12-06
|
|
8
28
|
|
|
9
29
|
### Fixed
|
|
@@ -44,6 +64,10 @@ All notable changes to this project are documented here. The format follows
|
|
|
44
64
|
must write no event or presence ref.
|
|
45
65
|
- `test/pagination.test.mjs` was rewritten for the read-only index, validation, skipped
|
|
46
66
|
rows, `reindex`, strict flags and the 100k `ready --limit`/page/counts budget.
|
|
67
|
+
### Published
|
|
68
|
+
|
|
69
|
+
- npm: `hive-tasks@1.11.0` on 2026-12-06.
|
|
70
|
+
|
|
47
71
|
## [1.10.0] - 2026-12-06
|
|
48
72
|
|
|
49
73
|
### Added
|
package/README.md
CHANGED
|
@@ -159,6 +159,11 @@ $ hive-tasks list --json --state pending --limit 50 --cursor 50 # next page
|
|
|
159
159
|
error. A row whose card id disagrees with the tree entry is counted in `skipped`
|
|
160
160
|
(and `show` refuses it) instead of disappearing silently.
|
|
161
161
|
|
|
162
|
+
The temporary `GIT_INDEX_FILE` used by a board write lives under the system temp
|
|
163
|
+
directory, not `.hive/`, and is removed on success and on failures. A command start
|
|
164
|
+
also sweeps stale temp index files older than ten minutes whose pid is dead, so a
|
|
165
|
+
killed writer cannot grow a pile of binary index files in the repository.
|
|
166
|
+
|
|
162
167
|
A `list` without `--limit`/`--cursor` keeps returning the full array. `counts --json`
|
|
163
168
|
returns the per-state numbers from that index without parsing any card:
|
|
164
169
|
|
package/README.zh-CN.md
CHANGED
|
@@ -149,6 +149,10 @@ $ hive-tasks list --json --state pending --limit 50 --cursor 50 # 下一页
|
|
|
149
149
|
扫描或崩溃。索引行 id 与卡片 id 不一致时计入 `skipped`(`show` 会拒绝),不再
|
|
150
150
|
静默丢卡。
|
|
151
151
|
|
|
152
|
+
写板用的临时 `GIT_INDEX_FILE` 放在系统临时目录,不落在 `.hive/`;成功和失败路径都会
|
|
153
|
+
删除。命令启动时还会清理超过 10 分钟且 pid 已死的陈旧临时索引文件,进程被杀也不会在
|
|
154
|
+
仓库里堆积二进制索引文件。
|
|
155
|
+
|
|
152
156
|
不带 `--limit`/`--cursor` 的 `list` 仍返回完整数组。`counts --json` 直接从索引返回
|
|
153
157
|
各状态计数,不解析任何卡片:
|
|
154
158
|
|
package/SPEC.md
CHANGED
|
@@ -47,6 +47,15 @@ Implementation sketch (plumbing, no working tree involved):
|
|
|
47
47
|
GIT_INDEX_FILE=tmp git write-tree # new tree
|
|
48
48
|
git update-ref refs/hive/v1/tasks <new-tree> <old-tree>
|
|
49
49
|
|
|
50
|
+
`tmp` is a unique file under `os.tmpdir()` (`hive-tasks-index-<pid>-<random>`), never a
|
|
51
|
+
path inside the repository: binary Git index files must not leak into `.hive/` when a
|
|
52
|
+
writer is killed. The file is removed in a `finally` block on success and on every
|
|
53
|
+
thrown error, and a normal exit also sweeps it. At command startup the CLI removes stale
|
|
54
|
+
temp index files — older than ten minutes and whose embedded pid is no longer alive —
|
|
55
|
+
scanning both the repository state dir (legacy `index-tasks-*` names from 1.11.0 and
|
|
56
|
+
earlier) and `os.tmpdir()` (current names). Fresh files and files owned by a live pid
|
|
57
|
+
are kept.
|
|
58
|
+
|
|
50
59
|
A derived index lives next to the tree and is never the source of truth:
|
|
51
60
|
|
|
52
61
|
refs/hive/v1/tasks-index -> blob { v: 2, tasks: <tasks tree sha>, entries: [...] }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-tasks",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "Task cards for agent teams: one git tree behind one ref, with a state machine, optional stage chains, role resolution, dependencies and hive leases.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import fs from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { git, out } from "./git.js";
|
|
5
5
|
import { ensureState, repoInfo } from "./repo.js";
|
|
6
|
-
import { DEFAULT_PAGE_LIMIT, listRaw, mutate, pageFromEntries, readIndexForRead, readTask, readTasksByIdsAligned, readyEntries, reindex, repositoryWritable, summarizeEntries } from "./store.js";
|
|
6
|
+
import { DEFAULT_PAGE_LIMIT, cleanupStaleTempIndexes, listRaw, mutate, pageFromEntries, readIndexForRead, readTask, readTasksByIdsAligned, readyEntries, reindex, repositoryWritable, summarizeEntries } from "./store.js";
|
|
7
7
|
import { create, isDraft, isReady, isReclaimable, isSuperseded, now, order, reopenPatch, transition } from "./task.js";
|
|
8
8
|
import {
|
|
9
9
|
advanceStage,
|
|
@@ -481,6 +481,8 @@ function run(argv) {
|
|
|
481
481
|
if (command === "-V" || command === "--version" || command === "version") return process.stdout.write(VERSION + "\n");
|
|
482
482
|
|
|
483
483
|
const repo = repoInfo(process.cwd());
|
|
484
|
+
// Remove temp Git index files left by killed writers before doing any work.
|
|
485
|
+
cleanupStaleTempIndexes(repo);
|
|
484
486
|
|
|
485
487
|
if (command === "init") {
|
|
486
488
|
ensureState(repo);
|
package/src/store.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { git, gitBuffer, out } from "./git.js";
|
|
5
6
|
import { currentStage, isStaged } from "./stage.js";
|
|
@@ -379,6 +380,90 @@ export function summarizeIndex(repo) {
|
|
|
379
380
|
return summarizeEntries(readIndexForRead(repo).entries);
|
|
380
381
|
}
|
|
381
382
|
|
|
383
|
+
/** GIT_INDEX_FILE temp files never live in the repository. Old releases wrote
|
|
384
|
+
* `index-tasks-*` into .hive/, so a killed process leaked binary Git index files
|
|
385
|
+
* there; startup cleanup removes stale ones (older than 10 minutes and a dead pid).
|
|
386
|
+
*/
|
|
387
|
+
export const TEMP_INDEX_PREFIX = "hive-tasks-index-";
|
|
388
|
+
const LEGACY_INDEX_PREFIX = "index-tasks-";
|
|
389
|
+
const STALE_TEMP_INDEX_MS = 10 * 60 * 1000;
|
|
390
|
+
const activeTempIndexes = new Set();
|
|
391
|
+
let exitCleanupInstalled = false;
|
|
392
|
+
|
|
393
|
+
function installExitCleanup() {
|
|
394
|
+
if (exitCleanupInstalled) return;
|
|
395
|
+
exitCleanupInstalled = true;
|
|
396
|
+
// Best effort for a normal exit path; killed processes are covered by the
|
|
397
|
+
// startup sweep. `finally` in write() handles every thrown error.
|
|
398
|
+
process.once("exit", () => {
|
|
399
|
+
for (const file of activeTempIndexes) {
|
|
400
|
+
try { fs.rmSync(file, { force: true }); } catch { /* best effort */ }
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function tempIndexPath() {
|
|
406
|
+
installExitCleanup();
|
|
407
|
+
const file = path.join(os.tmpdir(), TEMP_INDEX_PREFIX + process.pid + "-" + crypto.randomBytes(6).toString("hex"));
|
|
408
|
+
activeTempIndexes.add(file);
|
|
409
|
+
return file;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function removeTempIndex(file) {
|
|
413
|
+
try { fs.rmSync(file, { force: true }); } catch { /* already gone */ }
|
|
414
|
+
activeTempIndexes.delete(file);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function indexFilePid(name) {
|
|
418
|
+
for (const prefix of [LEGACY_INDEX_PREFIX, TEMP_INDEX_PREFIX]) {
|
|
419
|
+
if (!name.startsWith(prefix)) continue;
|
|
420
|
+
const match = /^(\d+)(?:-|$)/.exec(name.slice(prefix.length));
|
|
421
|
+
return match ? Number(match[1]) : null;
|
|
422
|
+
}
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function processAlive(pid) {
|
|
427
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
428
|
+
if (pid === process.pid) return true;
|
|
429
|
+
try {
|
|
430
|
+
process.kill(pid, 0);
|
|
431
|
+
return true;
|
|
432
|
+
} catch (error) {
|
|
433
|
+
return Boolean(error && error.code === "EPERM");
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Remove temp Git index files left behind by killed processes. A file is stale
|
|
439
|
+
* only when it is older than ten minutes and its embedded pid is no longer alive;
|
|
440
|
+
* fresh files and live writers are kept. Scans the repository state dir (legacy
|
|
441
|
+
* `index-tasks-*` names) and os.tmpdir() (current `hive-tasks-index-*`).
|
|
442
|
+
*/
|
|
443
|
+
export function cleanupStaleTempIndexes(repo, { now = Date.now(), isAlive = processAlive } = {}) {
|
|
444
|
+
const dirs = [];
|
|
445
|
+
if (repo && repo.stateDir) dirs.push(repo.stateDir);
|
|
446
|
+
dirs.push(os.tmpdir());
|
|
447
|
+
const seen = new Set();
|
|
448
|
+
for (const dir of dirs) {
|
|
449
|
+
if (!dir || seen.has(dir)) continue;
|
|
450
|
+
seen.add(dir);
|
|
451
|
+
let names;
|
|
452
|
+
try { names = fs.readdirSync(dir); } catch { continue; }
|
|
453
|
+
for (const name of names) {
|
|
454
|
+
if (!name.startsWith(LEGACY_INDEX_PREFIX) && !name.startsWith(TEMP_INDEX_PREFIX)) continue;
|
|
455
|
+
const file = path.join(dir, name);
|
|
456
|
+
let stat;
|
|
457
|
+
try { stat = fs.statSync(file); } catch { continue; }
|
|
458
|
+
if (!stat.isFile()) continue;
|
|
459
|
+
if (now - stat.mtimeMs <= STALE_TEMP_INDEX_MS) continue;
|
|
460
|
+
const pid = indexFilePid(name);
|
|
461
|
+
if (pid !== null && isAlive(pid)) continue;
|
|
462
|
+
try { fs.rmSync(file, { force: true }); } catch { /* best effort */ }
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
382
467
|
function hashBlob(repo, value) {
|
|
383
468
|
return out(["hash-object", "-w", "--stdin"], { cwd: repo.top, input: JSON.stringify(value) });
|
|
384
469
|
}
|
|
@@ -390,7 +475,9 @@ function hashBlob(repo, value) {
|
|
|
390
475
|
* moved underneath us (caller retries).
|
|
391
476
|
*/
|
|
392
477
|
function write(repo, tasks, expectedSha) {
|
|
393
|
-
|
|
478
|
+
// The temp index goes to the system temp dir, not the repository: a killed
|
|
479
|
+
// process must never leave a binary Git index inside .hive/.
|
|
480
|
+
const indexFile = tempIndexPath();
|
|
394
481
|
const env = { GIT_INDEX_FILE: indexFile };
|
|
395
482
|
try {
|
|
396
483
|
fs.mkdirSync(repo.stateDir, { recursive: true });
|
|
@@ -414,7 +501,7 @@ function write(repo, tasks, expectedSha) {
|
|
|
414
501
|
writeIndex(repo, tree, buildIndexEntries(tasks));
|
|
415
502
|
return true;
|
|
416
503
|
} finally {
|
|
417
|
-
|
|
504
|
+
removeTempIndex(indexFile);
|
|
418
505
|
}
|
|
419
506
|
}
|
|
420
507
|
|