@srobroek/pi-speckit-beads 3.2.5 → 3.2.7
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 +12 -0
- package/extensions/speckit-beads.js +154 -32
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## speckit-beads [3.2.7](https://github.com/srobroek/harness-plugins/compare/speckit-beads--v3.2.6...speckit-beads--v3.2.7) (2026-12-06)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **beads:** find the store by walking ancestors the way bd does ([35b332f](https://github.com/srobroek/harness-plugins/commit/35b332f8624bd4c056cc1a0a5d6165c85f390188))
|
|
6
|
+
|
|
7
|
+
## speckit-beads [3.2.6](https://github.com/srobroek/harness-plugins/compare/speckit-beads--v3.2.5...speckit-beads--v3.2.6) (2026-12-05)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* review follow-ups from the sweep PRs (speckit-beads, ratchet, code-challenge, docs, tests) ([#385](https://github.com/srobroek/harness-plugins/issues/385)) ([4fa9eb6](https://github.com/srobroek/harness-plugins/commit/4fa9eb6570bccea9d0dfae1a7b4af4922b5876b5))
|
|
12
|
+
|
|
1
13
|
## speckit-beads [3.2.5](https://github.com/srobroek/harness-plugins/compare/speckit-beads--v3.2.4...speckit-beads--v3.2.5) (2026-12-05)
|
|
2
14
|
|
|
3
15
|
### Bug Fixes
|
|
@@ -2605,8 +2605,15 @@ function canonicalPath(path) {
|
|
|
2605
2605
|
|
|
2606
2606
|
// lib/src/beads-store.ts
|
|
2607
2607
|
import { spawnSync } from "child_process";
|
|
2608
|
-
import { lstatSync as lstatSync5, realpathSync as realpathSync3, statSync as statSync4 } from "fs";
|
|
2608
|
+
import { lstatSync as lstatSync5, readdirSync, realpathSync as realpathSync3, statSync as statSync4 } from "fs";
|
|
2609
2609
|
import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute7, resolve as resolve7 } from "path";
|
|
2610
|
+
|
|
2611
|
+
class StoreUnresolvedError extends Error {
|
|
2612
|
+
constructor(message) {
|
|
2613
|
+
super(message);
|
|
2614
|
+
this.name = "StoreUnresolvedError";
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2610
2617
|
function repoIdentity(cwd) {
|
|
2611
2618
|
if (cwd.includes("\x00"))
|
|
2612
2619
|
return;
|
|
@@ -2651,34 +2658,101 @@ function repositoryState(cwd) {
|
|
|
2651
2658
|
current = parent;
|
|
2652
2659
|
}
|
|
2653
2660
|
}
|
|
2654
|
-
function
|
|
2661
|
+
function hasProjectFiles(store) {
|
|
2662
|
+
if (isFile(resolve7(store, "metadata.json")) || isFile(resolve7(store, "config.yaml")))
|
|
2663
|
+
return true;
|
|
2664
|
+
if (isDir(resolve7(store, "dolt")) || isDir(resolve7(store, "embeddeddolt")))
|
|
2665
|
+
return true;
|
|
2666
|
+
try {
|
|
2667
|
+
return readdirSync(store).some((name) => name.endsWith(".db") && !name.includes(".backup") && name !== "vc.db");
|
|
2668
|
+
} catch {
|
|
2669
|
+
return false;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
function isFile(path) {
|
|
2673
|
+
try {
|
|
2674
|
+
return statSync4(path).isFile();
|
|
2675
|
+
} catch {
|
|
2676
|
+
return false;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
var BD_WHERE_TIMEOUT_MS = 5000;
|
|
2680
|
+
var bdWhere = (cwd, env, selectors = []) => {
|
|
2681
|
+
const clean = {};
|
|
2682
|
+
for (const [key, value] of Object.entries(env)) {
|
|
2683
|
+
if (value !== undefined && key !== "BEADS_DIR" && key !== "BEADS_DB")
|
|
2684
|
+
clean[key] = value;
|
|
2685
|
+
}
|
|
2686
|
+
if (clean.PATH === undefined && process.env.PATH !== undefined)
|
|
2687
|
+
clean.PATH = process.env.PATH;
|
|
2688
|
+
const result = spawnSync("bd", [...selectors, "where", "--json"], {
|
|
2689
|
+
cwd,
|
|
2690
|
+
env: clean,
|
|
2691
|
+
encoding: "utf8",
|
|
2692
|
+
timeout: BD_WHERE_TIMEOUT_MS,
|
|
2693
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2694
|
+
});
|
|
2695
|
+
if (result.error)
|
|
2696
|
+
throw new StoreUnresolvedError(`bd where could not run in ${cwd}: ${result.error.message}`);
|
|
2697
|
+
if (result.signal !== null)
|
|
2698
|
+
throw new StoreUnresolvedError(`bd where failed in ${cwd} (${result.signal})`);
|
|
2699
|
+
let parsed;
|
|
2700
|
+
try {
|
|
2701
|
+
parsed = JSON.parse(String(result.stdout ?? ""));
|
|
2702
|
+
} catch {
|
|
2703
|
+
throw new StoreUnresolvedError(`bd where ${result.status === 0 ? "printed output that is not JSON" : `exited ${result.status}`} in ${cwd}`);
|
|
2704
|
+
}
|
|
2705
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
2706
|
+
throw new StoreUnresolvedError(`bd where printed unexpected JSON in ${cwd}`);
|
|
2707
|
+
if (parsed.error === "no_beads_directory")
|
|
2708
|
+
return;
|
|
2709
|
+
if (result.status !== 0)
|
|
2710
|
+
throw new StoreUnresolvedError(`bd where failed in ${cwd} (exit ${result.status})`);
|
|
2711
|
+
const answer = parsed;
|
|
2712
|
+
if (typeof answer.path !== "string" || answer.path === "") {
|
|
2713
|
+
throw new StoreUnresolvedError(`bd where gave no store path in ${cwd}`);
|
|
2714
|
+
}
|
|
2715
|
+
return answer.path;
|
|
2716
|
+
};
|
|
2717
|
+
var storeResolver = bdWhere;
|
|
2718
|
+
function sessionPinFor(cwd, env = process.env) {
|
|
2719
|
+
try {
|
|
2720
|
+
return strictSessionPinFor(cwd, env);
|
|
2721
|
+
} catch (error) {
|
|
2722
|
+
if (error instanceof StoreUnresolvedError)
|
|
2723
|
+
return;
|
|
2724
|
+
throw error;
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
function strictSessionPinFor(cwd, env = process.env, resolver = storeResolver, selectors = []) {
|
|
2655
2728
|
const local = resolve7(cwd, ".beads");
|
|
2656
2729
|
const common = repoIdentity(cwd);
|
|
2657
2730
|
if (common === undefined)
|
|
2658
|
-
return
|
|
2731
|
+
return;
|
|
2732
|
+
const found = selectors.length === 0 ? resolver(cwd, env) : resolver(cwd, env, selectors);
|
|
2733
|
+
if (found !== undefined)
|
|
2734
|
+
return found;
|
|
2659
2735
|
if (common !== cwd && common.endsWith("/.git")) {
|
|
2660
2736
|
const primaryRoot = resolve7(common, "..");
|
|
2661
2737
|
try {
|
|
2662
|
-
if (realpathSync3(cwd) === primaryRoot)
|
|
2663
|
-
return
|
|
2738
|
+
if (realpathSync3(cwd) === primaryRoot && isDir(local))
|
|
2739
|
+
return local;
|
|
2664
2740
|
} catch {
|
|
2665
|
-
return
|
|
2741
|
+
return;
|
|
2666
2742
|
}
|
|
2667
|
-
|
|
2743
|
+
const primary = resolve7(primaryRoot, ".beads");
|
|
2744
|
+
if (isDir(primary))
|
|
2745
|
+
return primary;
|
|
2668
2746
|
}
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
return candidates.find(isDirectory2);
|
|
2673
|
-
}
|
|
2674
|
-
function sessionPinFor(cwd) {
|
|
2675
|
-
return existingStore(sessionPinCandidates(cwd));
|
|
2747
|
+
if (isDir(local))
|
|
2748
|
+
return local;
|
|
2749
|
+
return;
|
|
2676
2750
|
}
|
|
2677
2751
|
function storeFromBeadsDb(value, cwd) {
|
|
2678
2752
|
const path = resolve7(cwd, value);
|
|
2679
2753
|
return basename3(path) === ".beads" ? path : dirname5(path);
|
|
2680
2754
|
}
|
|
2681
|
-
function ambientStore(cwd, env, walkUp = sessionPinFor) {
|
|
2755
|
+
function ambientStore(cwd, env, walkUp = (dir) => sessionPinFor(dir, env)) {
|
|
2682
2756
|
const dir = env.BEADS_DIR;
|
|
2683
2757
|
if (dir !== undefined && dir !== "")
|
|
2684
2758
|
return resolve7(cwd, dir);
|
|
@@ -2688,6 +2762,13 @@ function ambientStore(cwd, env, walkUp = sessionPinFor) {
|
|
|
2688
2762
|
const db = env.BEADS_DB;
|
|
2689
2763
|
return db !== undefined && db !== "" ? storeFromBeadsDb(db, cwd) : undefined;
|
|
2690
2764
|
}
|
|
2765
|
+
function isDir(path) {
|
|
2766
|
+
try {
|
|
2767
|
+
return statSync4(path).isDirectory();
|
|
2768
|
+
} catch {
|
|
2769
|
+
return false;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2691
2772
|
|
|
2692
2773
|
// lib/src/bd-embedded-write-lock.ts
|
|
2693
2774
|
var LOCK_NAME = "omp-embedded-write.lock";
|
|
@@ -2782,9 +2863,40 @@ function selectedStoreFor(globals, cwd, env) {
|
|
|
2782
2863
|
return;
|
|
2783
2864
|
return isDirectory2(target) ? target : join8(target, "..");
|
|
2784
2865
|
}
|
|
2785
|
-
if (directory !== undefined)
|
|
2786
|
-
|
|
2787
|
-
|
|
2866
|
+
if ((env.BD_DB ?? "") !== "" && (directory !== undefined || (env.BEADS_DIR ?? "") === "")) {
|
|
2867
|
+
throw new StoreUnresolvedError("the environment sets `BD_DB`, and bd where follows it while a write may use the ambient store; name the store as `BEADS_DIR=<store> bd ...` (or `bd --db <store> ...`), and do not work around this refusal with a wrapper, `eval` or another tool");
|
|
2868
|
+
}
|
|
2869
|
+
if (directory !== undefined) {
|
|
2870
|
+
const store = strictSessionPinFor(base, env, undefined, ["-C", base]);
|
|
2871
|
+
refuseDotenvDb(store, base);
|
|
2872
|
+
return store;
|
|
2873
|
+
}
|
|
2874
|
+
const store = ambientStore(cwd, env, (dir) => strictSessionPinFor(dir, env));
|
|
2875
|
+
refuseDotenvDb(store, cwd);
|
|
2876
|
+
return store;
|
|
2877
|
+
}
|
|
2878
|
+
function refuseDotenvDb(store, base) {
|
|
2879
|
+
const files = new Set;
|
|
2880
|
+
if (store !== undefined)
|
|
2881
|
+
files.add(join8(store, ".env"));
|
|
2882
|
+
for (let dir = resolve8(base);; dir = dirname6(dir)) {
|
|
2883
|
+
files.add(join8(dir, ".beads", ".env"));
|
|
2884
|
+
if (dirname6(dir) === dir)
|
|
2885
|
+
break;
|
|
2886
|
+
}
|
|
2887
|
+
for (const file of files) {
|
|
2888
|
+
if (!existsSync5(file))
|
|
2889
|
+
continue;
|
|
2890
|
+
let text;
|
|
2891
|
+
try {
|
|
2892
|
+
text = Buffer.from(readFileSync5(file).filter((byte) => byte !== 0)).toString("latin1");
|
|
2893
|
+
} catch {
|
|
2894
|
+
text = "BD_DB";
|
|
2895
|
+
}
|
|
2896
|
+
if (/BD_DB|BEADS_DB/.test(text)) {
|
|
2897
|
+
throw new StoreUnresolvedError(`${file} mentions BD_DB or BEADS_DB (or cannot be read), so the store of this write is not certain; name the store as \`BEADS_DIR=<store> bd ...\`, and do not work around this refusal with a wrapper, \`eval\` or another tool`);
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2788
2900
|
}
|
|
2789
2901
|
function absolute(path, cwd) {
|
|
2790
2902
|
return isAbsolute8(path) ? path : resolve8(cwd, path);
|
|
@@ -2793,12 +2905,15 @@ function canonicalStore(store) {
|
|
|
2793
2905
|
return store === undefined ? undefined : canonicalPath(store);
|
|
2794
2906
|
}
|
|
2795
2907
|
function embedded(store) {
|
|
2908
|
+
let unknown = false;
|
|
2796
2909
|
for (const file of ["metadata.json", "config.yaml"]) {
|
|
2797
2910
|
const read = readBounded(join8(store, file));
|
|
2798
2911
|
if (read.kind === "unreadable" || read.kind === "text" && read.text !== "")
|
|
2799
2912
|
return true;
|
|
2913
|
+
if (read.kind === "text")
|
|
2914
|
+
unknown = true;
|
|
2800
2915
|
}
|
|
2801
|
-
return isDirectory2(join8(store, "embeddeddolt"));
|
|
2916
|
+
return unknown || isDirectory2(join8(store, "embeddeddolt")) || hasProjectFiles(store);
|
|
2802
2917
|
}
|
|
2803
2918
|
function embeddedStoreFor(cwd, env = process.env) {
|
|
2804
2919
|
const store = storeFor([], cwd, env);
|
|
@@ -3138,7 +3253,14 @@ function renewLease(lock, owner, token) {
|
|
|
3138
3253
|
} catch {}
|
|
3139
3254
|
}
|
|
3140
3255
|
async function withEmbeddedWriteLock(cwd, owner, write, env = process.env, deadline, signal) {
|
|
3141
|
-
|
|
3256
|
+
let store;
|
|
3257
|
+
try {
|
|
3258
|
+
store = embeddedStoreFor(cwd, env);
|
|
3259
|
+
} catch (error) {
|
|
3260
|
+
if (error instanceof StoreUnresolvedError)
|
|
3261
|
+
return { kind: "failed", reason: `the Beads write lock cannot establish the store: ${error.message}` };
|
|
3262
|
+
throw error;
|
|
3263
|
+
}
|
|
3142
3264
|
if (store === undefined)
|
|
3143
3265
|
return { kind: "done", value: await write() };
|
|
3144
3266
|
const waitMs = deadline === undefined ? WAIT_MS : Math.max(0, deadline - Date.now());
|
|
@@ -3180,6 +3302,14 @@ function createdRootOf(created, formula) {
|
|
|
3180
3302
|
const id = mapping[formula];
|
|
3181
3303
|
return typeof id === "string" ? id : undefined;
|
|
3182
3304
|
}
|
|
3305
|
+
function captureUtf8(stream) {
|
|
3306
|
+
let text = "";
|
|
3307
|
+
stream.setEncoding("utf8");
|
|
3308
|
+
stream.on("data", (chunk) => {
|
|
3309
|
+
text += chunk;
|
|
3310
|
+
});
|
|
3311
|
+
return () => text;
|
|
3312
|
+
}
|
|
3183
3313
|
async function runSpecStart(options, signal, commandMs = COMMAND_MS, module = BEADS_LOCK, timers = globalThis) {
|
|
3184
3314
|
const started = Date.now();
|
|
3185
3315
|
const cwd = realpathSync4(options.workspace);
|
|
@@ -3241,16 +3371,8 @@ async function runSpecStart(options, signal, commandMs = COMMAND_MS, module = BE
|
|
|
3241
3371
|
timers.clearTimeout(grace);
|
|
3242
3372
|
signal?.removeEventListener("abort", cancel);
|
|
3243
3373
|
};
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
child.stdout.setEncoding("utf8");
|
|
3247
|
-
child.stderr.setEncoding("utf8");
|
|
3248
|
-
child.stdout.on("data", (text) => {
|
|
3249
|
-
stdout += text;
|
|
3250
|
-
});
|
|
3251
|
-
child.stderr.on("data", (text) => {
|
|
3252
|
-
stderr += text;
|
|
3253
|
-
});
|
|
3374
|
+
const stdout = captureUtf8(child.stdout);
|
|
3375
|
+
const stderr = captureUtf8(child.stderr);
|
|
3254
3376
|
child.on("error", (error) => {
|
|
3255
3377
|
settle();
|
|
3256
3378
|
reject(error);
|
|
@@ -3262,7 +3384,7 @@ async function runSpecStart(options, signal, commandMs = COMMAND_MS, module = BE
|
|
|
3262
3384
|
return;
|
|
3263
3385
|
}
|
|
3264
3386
|
if (code !== 0) {
|
|
3265
|
-
reject(new Error(stderr.trim() || `Beads command exited ${code}; inspect the run before retrying`));
|
|
3387
|
+
reject(new Error(stderr().trim() || `Beads command exited ${code}; inspect the run before retrying`));
|
|
3266
3388
|
return;
|
|
3267
3389
|
}
|
|
3268
3390
|
completedSteps.push(step);
|
|
@@ -3272,7 +3394,7 @@ async function runSpecStart(options, signal, commandMs = COMMAND_MS, module = BE
|
|
|
3272
3394
|
}
|
|
3273
3395
|
let value;
|
|
3274
3396
|
try {
|
|
3275
|
-
value = JSON.parse(stdout);
|
|
3397
|
+
value = JSON.parse(stdout());
|
|
3276
3398
|
} catch {
|
|
3277
3399
|
reject(new Error("Beads returned invalid JSON; inspect the run before retrying"));
|
|
3278
3400
|
return;
|
package/package.json
CHANGED