@srobroek/pi-speckit-beads 2.1.3 → 2.3.0
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/README.md +22 -0
- package/extensions/speckit-beads.js +375 -5
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## speckit-beads [2.3.0](https://github.com/srobroek/harness-plugins/compare/speckit-beads--v2.2.0...speckit-beads--v2.3.0) (2026-12-02)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **beads:** add beads-hygiene ledger audit skill and ledger-auditor agents ([611b67a](https://github.com/srobroek/harness-plugins/commit/611b67a0a6e02ec7a1917170843feb946766a4a7))
|
|
6
|
+
|
|
7
|
+
## speckit-beads [2.2.0](https://github.com/srobroek/harness-plugins/compare/speckit-beads--v2.1.3...speckit-beads--v2.2.0) (2026-12-01)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **speckit-beads:** watch for newly ready implementation beads ([3b24bf1](https://github.com/srobroek/harness-plugins/commit/3b24bf1cfc1f8850d4dc90016eaa7728082ac474))
|
|
12
|
+
|
|
1
13
|
## speckit-beads [2.1.3](https://github.com/srobroek/harness-plugins/compare/speckit-beads--v2.1.2...speckit-beads--v2.1.3) (2026-11-30)
|
|
2
14
|
|
|
3
15
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -167,6 +167,28 @@ it cannot run.
|
|
|
167
167
|
| Analyze command | Gets a beads preamble ahead of the upstream text. The preamble drops `--require-tasks --include-tasks` from the prerequisite script. It also says to read the task beads where the command reads tasks.md. The spec and plan analysis stays as upstream wrote it. OpenCode adds the preamble to the skill. pi sends it as a message with a typed `/speckit.analyze`, and adds it to a `read` of the prompt file. |
|
|
168
168
|
| `speckit-taskstoissues`, `speckit-github-taskstoissues` | Refused. OpenCode: the `skill` tool does not load them, and their content becomes the refusal. pi: a typed command stops and shows the refusal. A `read` of the file returns it. |
|
|
169
169
|
|
|
170
|
+
On interactive Pi, the main agent starts `speckit_watch` for the selected implement
|
|
171
|
+
step, but only after you typed `/speckit.implement`, the step's prerequisites and
|
|
172
|
+
gates are closed, and you confirm the exact parent, filter and ledger in a dialog.
|
|
173
|
+
The watch only reads readiness and launches nothing itself. The extension checks readiness every few seconds without starting a model
|
|
174
|
+
turn. It wakes the agent only when beads become ready and the session is idle; alerts found while it is busy wait, and survive a failed scan. The agent also checks when
|
|
175
|
+
workers finish and fills free lanes from all eligible beads. Empty or blocked
|
|
176
|
+
queues keep the watch alive. It stops when the selected work is complete, the
|
|
177
|
+
session ends, or you run `/speckit-watch-stop`.
|
|
178
|
+
|
|
179
|
+
Known limit: Pi can defer a wake behind other work and does not let an extension recall it.
|
|
180
|
+
The watch keeps one wake in flight until Pi starts it and folds later ready beads into the
|
|
181
|
+
next one. A stop therefore leaves at most one already queued wake. It names the stopped
|
|
182
|
+
watch, finds that watch inactive and dispatches no worker. A restarted watch's alert waits
|
|
183
|
+
for that wake to be delivered, then goes out normally.
|
|
184
|
+
|
|
185
|
+
Pi 1.7.0 discards a deferred wake without any event when an earlier deferred user prompt fails
|
|
186
|
+
its preflight, for example on an authentication error. The watch never clears its latch on
|
|
187
|
+
time alone, since that could stack stale wakes. After two minutes with ready beads waiting, it
|
|
188
|
+
warns once. Run `/reload`, which rebinds the extension and drops the watch, then run
|
|
189
|
+
`/speckit.implement` again. Until then, finishing workers still prompt a readiness check.
|
|
190
|
+
Other hosts check readiness after workers finish but do not watch in the background.
|
|
191
|
+
|
|
170
192
|
Upstream writers the guard denies: `speckit-tasks`, `speckit-converge` (it appends a
|
|
171
193
|
`## Phase N: Convergence` section), and the bugfix, cleanup, iterate, reconcile and
|
|
172
194
|
refine extensions.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// Generated by scripts/build.ts. Do not edit.
|
|
3
3
|
// plugins/speckit-beads/pi-src/speckit-beads.ts
|
|
4
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
4
5
|
import { join as join8 } from "path";
|
|
5
6
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
6
7
|
|
|
@@ -649,6 +650,9 @@ function loadPiPluginSettings(path, plugin, fallback) {
|
|
|
649
650
|
return { options: value };
|
|
650
651
|
}
|
|
651
652
|
|
|
653
|
+
// plugins/speckit-beads/pi-src/speckit-beads.ts
|
|
654
|
+
import { Type } from "typebox";
|
|
655
|
+
|
|
652
656
|
// plugins/speckit-beads/opencode/instructions/speckit-workflow.md
|
|
653
657
|
var speckit_workflow_default = `# SpecKit workflow (srobroek.speckit-beads)
|
|
654
658
|
|
|
@@ -1585,9 +1589,42 @@ molecule's unconditional \`implement\` step instead:
|
|
|
1585
1589
|
1. Find the run: \`bd query 'spec_id="<NNN-slug>"' --json\`, then \`bd mol current <root-id>\`.
|
|
1586
1590
|
2. Check the implement step's prerequisites are closed, including every analysis
|
|
1587
1591
|
approval gate that was not waived. Stop and report when one is open.
|
|
1588
|
-
3.
|
|
1589
|
-
|
|
1590
|
-
|
|
1592
|
+
3. When the user starts implementation, the main agent owns the ready-bead watch and
|
|
1593
|
+
dispatch. Start the watch before the first scan, then scan immediately. Keep the
|
|
1594
|
+
implement step open until every child is closed; then close it with evidence.
|
|
1595
|
+
|
|
1596
|
+
## Ready-bead watch
|
|
1597
|
+
|
|
1598
|
+
- On Pi, call \`speckit_watch\` with \`action: "start"\` and \`parent\` set to the selected
|
|
1599
|
+
implement-step bead ID. Pass \`only\` for an explicit list of selected bead IDs.
|
|
1600
|
+
The watch starts only after the user typed \`/speckit.implement\`, the step's
|
|
1601
|
+
prerequisites and gates are closed, and the user confirms that exact scope in a Pi
|
|
1602
|
+
dialog; a declined or unavailable dialog means no watch. Keep the watch ID. Do not use model turns or scheduled prompts to poll readiness.
|
|
1603
|
+
- On a watch alert, check \`speckit_watch\` status with the alert's \`watchId\`. Ignore
|
|
1604
|
+
alerts from stopped or replaced watches: a queued wake can arrive once after a stop, and
|
|
1605
|
+
only an active status for exactly that \`watchId\` allows work. Check it again
|
|
1606
|
+
immediately before each launch. On start, on a valid alert and when a
|
|
1607
|
+
worker finishes, run \`bd ready --parent <implement-step-id> --limit 0 --json\` in the
|
|
1608
|
+
same ledger. Recheck the run, approval gates and user filter. Only dispatch open,
|
|
1609
|
+
unclaimed work beads in scope. Skip containers and human gates. After a failed scan, leave the run open and retry readiness.
|
|
1610
|
+
- The watch displays newly ready beads, including work a closed dependency unblocks.
|
|
1611
|
+
Fill free lanes from **all** eligible beads, not just the IDs in the alert. Route by
|
|
1612
|
+
\`metadata.execution_agent_type\`; use the host's implementer for untyped work.
|
|
1613
|
+
Report missing agents. Follow the host's Beads dispatch and checkpoint rules.
|
|
1614
|
+
Recheck eligibility just before launch. Workers claim with \`bd update <id> --claim\`
|
|
1615
|
+
before editing, use isolated worktrees for code changes, and close only with evidence.
|
|
1616
|
+
On Pi, use native asynchronous workers with \`Bead: FULL_ID\` on the first line of
|
|
1617
|
+
the brief and explicit verified acceptance where supported. Otherwise use a tracked
|
|
1618
|
+
foreground worker. Do not launch work already starting or running.
|
|
1619
|
+
Keep a pending launch in the lane count until its result is known. Use the session's
|
|
1620
|
+
lane limit, or one worker if none is set. Report a launch failure and check its handoff
|
|
1621
|
+
before retrying; do not retry it on every tick.
|
|
1622
|
+
- Do not overlap scans. Leave the watch running when readiness is empty, work is blocked,
|
|
1623
|
+
or every lane is busy. Stop it with \`speckit_watch\` when the authorized scope is
|
|
1624
|
+
complete or the run ends. The user can also run \`/speckit-watch-stop\`. Check the
|
|
1625
|
+
watch is still active before dispatching from an alert. A filtered run does not close
|
|
1626
|
+
the whole implement step. If the host cannot start a watch, say so and rescan after
|
|
1627
|
+
worker completions; do not claim to be watching in the background.
|
|
1591
1628
|
|
|
1592
1629
|
Do not create or edit \`specs/*/tasks.md\`; the speckit-beads plugin refuses those writes.
|
|
1593
1630
|
If a check script demands tasks.md (\`check-prerequisites.sh --require-tasks\`), skip it
|
|
@@ -3160,9 +3197,191 @@ async function executeStart(input, directory, signal, lock = BEADS_LOCK) {
|
|
|
3160
3197
|
}
|
|
3161
3198
|
}
|
|
3162
3199
|
|
|
3200
|
+
// plugins/speckit-beads/pi-src/ready-watch.ts
|
|
3201
|
+
import { execFile } from "child_process";
|
|
3202
|
+
import { resolve as resolve8 } from "path";
|
|
3203
|
+
import { promisify } from "util";
|
|
3204
|
+
|
|
3205
|
+
// lib/src/beads-pin.ts
|
|
3206
|
+
var EMBEDDED_PIN_ENV = { BEADS_DOLT_SHARED_SERVER: "" };
|
|
3207
|
+
var PIN_MARKER_ENV = "HARNESS_BEADS_PIN";
|
|
3208
|
+
function pinVariables(store) {
|
|
3209
|
+
return { ...EMBEDDED_PIN_ENV, BEADS_DIR: store, [PIN_MARKER_ENV]: store };
|
|
3210
|
+
}
|
|
3211
|
+
function inheritsPin(env) {
|
|
3212
|
+
const marker = env[PIN_MARKER_ENV];
|
|
3213
|
+
return marker !== undefined && marker !== "" && env.BEADS_DIR === marker;
|
|
3214
|
+
}
|
|
3215
|
+
function withoutInheritedPin(env) {
|
|
3216
|
+
if (env[PIN_MARKER_ENV] === undefined)
|
|
3217
|
+
return env;
|
|
3218
|
+
const { [PIN_MARKER_ENV]: _marker, ...rest } = env;
|
|
3219
|
+
if (inheritsPin(env))
|
|
3220
|
+
delete rest.BEADS_DIR;
|
|
3221
|
+
return rest;
|
|
3222
|
+
}
|
|
3223
|
+
function shellPin(cwd, env, pinFor = sessionPinFor) {
|
|
3224
|
+
const own = withoutInheritedPin(env);
|
|
3225
|
+
if (own.BEADS_DIR !== undefined && own.BEADS_DIR !== "")
|
|
3226
|
+
return;
|
|
3227
|
+
return ambientStore(cwd, { ...own, BEADS_DIR: undefined }, pinFor);
|
|
3228
|
+
}
|
|
3229
|
+
function selectStore(cwd, base, pinFor = sessionPinFor) {
|
|
3230
|
+
const own = withoutInheritedPin(base);
|
|
3231
|
+
const pin = shellPin(cwd, own, pinFor);
|
|
3232
|
+
const set = pin === undefined ? {} : pinVariables(pin);
|
|
3233
|
+
const unset = [];
|
|
3234
|
+
if (pin === undefined) {
|
|
3235
|
+
if (base.BEADS_DIR !== undefined && own.BEADS_DIR === undefined)
|
|
3236
|
+
unset.push("BEADS_DIR");
|
|
3237
|
+
if (base[PIN_MARKER_ENV] !== undefined)
|
|
3238
|
+
unset.push(PIN_MARKER_ENV);
|
|
3239
|
+
}
|
|
3240
|
+
const env = { ...own, ...set };
|
|
3241
|
+
return { env, set, unset };
|
|
3242
|
+
}
|
|
3243
|
+
function pinnedEnvironment(cwd, base, pinFor = sessionPinFor) {
|
|
3244
|
+
return selectStore(cwd, base, pinFor).env;
|
|
3245
|
+
}
|
|
3246
|
+
|
|
3247
|
+
// plugins/speckit-beads/pi-src/ready-watch.ts
|
|
3248
|
+
var exec = promisify(execFile);
|
|
3249
|
+
var POLL_MS2 = 3000;
|
|
3250
|
+
var LIMITS = { timeout: 8000, maxBuffer: 4 * 1024 * 1024, windowsHide: true };
|
|
3251
|
+
var BEAD_ID = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,255}$/;
|
|
3252
|
+
var WORK_TYPES = new Set(["task", "bug", "chore"]);
|
|
3253
|
+
var validBeadId = (id) => typeof id === "string" && BEAD_ID.test(id);
|
|
3254
|
+
function object2(value) {
|
|
3255
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
3256
|
+
}
|
|
3257
|
+
function readyIds(value, only) {
|
|
3258
|
+
if (!Array.isArray(value))
|
|
3259
|
+
throw new Error("Expected a Beads readiness list");
|
|
3260
|
+
const selected = new Set(only);
|
|
3261
|
+
const ids = new Set;
|
|
3262
|
+
for (const item of value) {
|
|
3263
|
+
const row = object2(item);
|
|
3264
|
+
if (row === undefined || !validBeadId(row.id) || typeof row.status !== "string" || typeof row.issue_type !== "string") {
|
|
3265
|
+
throw new Error("Invalid Beads readiness row");
|
|
3266
|
+
}
|
|
3267
|
+
const { id, status, issue_type, assignee } = row;
|
|
3268
|
+
if (status !== "open" || !WORK_TYPES.has(issue_type) || assignee !== undefined && assignee !== null && assignee !== "")
|
|
3269
|
+
continue;
|
|
3270
|
+
if (selected.size === 0 || selected.has(id))
|
|
3271
|
+
ids.add(id);
|
|
3272
|
+
}
|
|
3273
|
+
return [...ids].sort();
|
|
3274
|
+
}
|
|
3275
|
+
async function watchLedger(cwd, env = process.env) {
|
|
3276
|
+
const store = pinnedEnvironment(cwd, env).BEADS_DIR;
|
|
3277
|
+
if (store === undefined || store === "")
|
|
3278
|
+
throw new Error("No Beads ledger resolves for this checkout");
|
|
3279
|
+
return resolve8(cwd, store);
|
|
3280
|
+
}
|
|
3281
|
+
function watchEnv(ledger, base = process.env) {
|
|
3282
|
+
const env = {
|
|
3283
|
+
...withoutInheritedPin(base),
|
|
3284
|
+
...pinVariables(ledger),
|
|
3285
|
+
BD_NON_INTERACTIVE: "1",
|
|
3286
|
+
BD_NO_PAGER: "1",
|
|
3287
|
+
PAGER: "cat"
|
|
3288
|
+
};
|
|
3289
|
+
delete env.BEADS_DB;
|
|
3290
|
+
return env;
|
|
3291
|
+
}
|
|
3292
|
+
async function scanReady(scope, signal) {
|
|
3293
|
+
const { stdout } = await exec("bd", ["ready", "--parent", scope.parent, "--limit", "0", "--json"], {
|
|
3294
|
+
...LIMITS,
|
|
3295
|
+
cwd: scope.cwd,
|
|
3296
|
+
env: watchEnv(scope.ledger),
|
|
3297
|
+
signal
|
|
3298
|
+
});
|
|
3299
|
+
return readyIds(JSON.parse(stdout), scope.only);
|
|
3300
|
+
}
|
|
3301
|
+
function unmetPrerequisite(value, parent) {
|
|
3302
|
+
const issue = Array.isArray(value) ? object2(value[0]) : object2(value);
|
|
3303
|
+
if (issue === undefined || issue.id !== parent)
|
|
3304
|
+
return `${parent} is not an implement step in this ledger`;
|
|
3305
|
+
if (issue.status === "closed")
|
|
3306
|
+
return `${parent} is already closed`;
|
|
3307
|
+
const dependencies = issue.dependencies;
|
|
3308
|
+
if (dependencies !== undefined && !Array.isArray(dependencies))
|
|
3309
|
+
return "Beads reported unreadable prerequisites";
|
|
3310
|
+
for (const item of dependencies ?? []) {
|
|
3311
|
+
const dependency = object2(item);
|
|
3312
|
+
if (dependency === undefined || !validBeadId(dependency.id))
|
|
3313
|
+
return "Beads reported unreadable prerequisites";
|
|
3314
|
+
if (dependency.dependency_type === "parent-child")
|
|
3315
|
+
continue;
|
|
3316
|
+
if (dependency.status !== "closed")
|
|
3317
|
+
return `Prerequisite ${dependency.id} (${String(dependency.issue_type)}) is not closed`;
|
|
3318
|
+
}
|
|
3319
|
+
return;
|
|
3320
|
+
}
|
|
3321
|
+
async function verifyImplementStep(scope, signal) {
|
|
3322
|
+
const { stdout } = await exec("bd", ["show", scope.parent, "--json"], { ...LIMITS, cwd: scope.cwd, env: watchEnv(scope.ledger), signal });
|
|
3323
|
+
return unmetPrerequisite(JSON.parse(stdout), scope.parent);
|
|
3324
|
+
}
|
|
3325
|
+
var defer = (callback) => {
|
|
3326
|
+
const timer = setTimeout(callback, POLL_MS2);
|
|
3327
|
+
timer.unref();
|
|
3328
|
+
return () => clearTimeout(timer);
|
|
3329
|
+
};
|
|
3330
|
+
function createReadyWatch(scope, options) {
|
|
3331
|
+
const abort = new AbortController;
|
|
3332
|
+
const scan = options.scan ?? scanReady;
|
|
3333
|
+
const later = options.defer ?? defer;
|
|
3334
|
+
let previous = new Set;
|
|
3335
|
+
let available = false;
|
|
3336
|
+
let warned = false;
|
|
3337
|
+
let inFlight;
|
|
3338
|
+
let cancelTimer;
|
|
3339
|
+
let initial;
|
|
3340
|
+
function poll(announce) {
|
|
3341
|
+
if (abort.signal.aborted)
|
|
3342
|
+
return Promise.resolve();
|
|
3343
|
+
if (inFlight !== undefined)
|
|
3344
|
+
return inFlight;
|
|
3345
|
+
inFlight = Promise.resolve().then(async () => {
|
|
3346
|
+
try {
|
|
3347
|
+
const ids = await scan(scope, abort.signal);
|
|
3348
|
+
if (abort.signal.aborted)
|
|
3349
|
+
return;
|
|
3350
|
+
const added = ids.filter((id) => !previous.has(id));
|
|
3351
|
+
previous = new Set(ids);
|
|
3352
|
+
available = true;
|
|
3353
|
+
warned = false;
|
|
3354
|
+
if (announce && added.length > 0)
|
|
3355
|
+
options.onReady(added);
|
|
3356
|
+
options.onScan?.(ids);
|
|
3357
|
+
} catch {
|
|
3358
|
+
if (abort.signal.aborted)
|
|
3359
|
+
return;
|
|
3360
|
+
available = false;
|
|
3361
|
+
if (!warned)
|
|
3362
|
+
options.onUnavailable();
|
|
3363
|
+
warned = true;
|
|
3364
|
+
} finally {
|
|
3365
|
+
inFlight = undefined;
|
|
3366
|
+
if (!abort.signal.aborted)
|
|
3367
|
+
cancelTimer = later(() => poll(true));
|
|
3368
|
+
}
|
|
3369
|
+
});
|
|
3370
|
+
return inFlight;
|
|
3371
|
+
}
|
|
3372
|
+
return {
|
|
3373
|
+
start: () => initial ??= poll(false),
|
|
3374
|
+
snapshot: () => ({ ready: available ? [...previous] : [], available }),
|
|
3375
|
+
stop() {
|
|
3376
|
+
abort.abort();
|
|
3377
|
+
cancelTimer?.();
|
|
3378
|
+
}
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3163
3382
|
// plugins/speckit-beads/pi-src/routes.ts
|
|
3164
3383
|
import { homedir as homedir2 } from "os";
|
|
3165
|
-
import { isAbsolute as isAbsolute8, resolve as
|
|
3384
|
+
import { isAbsolute as isAbsolute8, resolve as resolve9 } from "path";
|
|
3166
3385
|
var WORKFLOW_SECTION = "speckit_workflow";
|
|
3167
3386
|
var MESSAGE_TYPE = "speckit-beads";
|
|
3168
3387
|
function guardReason(settingsPath) {
|
|
@@ -3194,7 +3413,7 @@ User input: ${command.args}` };
|
|
|
3194
3413
|
function toolPath(path, cwd) {
|
|
3195
3414
|
const plain = path.startsWith("@") ? path.slice(1) : path;
|
|
3196
3415
|
const expanded = plain === "~" ? homedir2() : plain.startsWith("~/") ? `${homedir2()}${plain.slice(1)}` : plain;
|
|
3197
|
-
return isAbsolute8(expanded) ? expanded :
|
|
3416
|
+
return isAbsolute8(expanded) ? expanded : resolve9(cwd, expanded);
|
|
3198
3417
|
}
|
|
3199
3418
|
function readCommand(path) {
|
|
3200
3419
|
const normal = path.replaceAll("\\", "/");
|
|
@@ -3212,6 +3431,9 @@ function guardInput(input, cwd) {
|
|
|
3212
3431
|
}
|
|
3213
3432
|
|
|
3214
3433
|
// plugins/speckit-beads/pi-src/speckit-beads.ts
|
|
3434
|
+
var READY_TYPE = "speckit-ready";
|
|
3435
|
+
var STALL_MS = 120000;
|
|
3436
|
+
var STALL_WARNING = "SpecKit ready alerts are paused: Pi has not started the last alert, and ready beads are waiting. Run /reload, then /speckit.implement again; finishing workers still prompt a readiness check.";
|
|
3215
3437
|
var schema = (value) => value;
|
|
3216
3438
|
var firstLine = (text) => text.split(`
|
|
3217
3439
|
`, 1)[0] ?? text;
|
|
@@ -3248,6 +3470,152 @@ function setupSpeckitPi(pi, deps = {}) {
|
|
|
3248
3470
|
if (loaded.warning !== undefined)
|
|
3249
3471
|
notify(ctx, loaded.warning);
|
|
3250
3472
|
});
|
|
3473
|
+
let watch;
|
|
3474
|
+
let starting;
|
|
3475
|
+
let implementRequest;
|
|
3476
|
+
const held = new Set;
|
|
3477
|
+
let wakeInFlight = false;
|
|
3478
|
+
let wakeSentAt = 0;
|
|
3479
|
+
let stallWarned = false;
|
|
3480
|
+
const now = deps.now ?? Date.now;
|
|
3481
|
+
const warnIfStalled = (ctx) => {
|
|
3482
|
+
if (!wakeInFlight || stallWarned || held.size === 0 || now() - wakeSentAt < STALL_MS)
|
|
3483
|
+
return;
|
|
3484
|
+
stallWarned = true;
|
|
3485
|
+
notify(ctx, STALL_WARNING);
|
|
3486
|
+
};
|
|
3487
|
+
const stopWatch = () => {
|
|
3488
|
+
implementRequest = undefined;
|
|
3489
|
+
held.clear();
|
|
3490
|
+
starting?.abort();
|
|
3491
|
+
starting = undefined;
|
|
3492
|
+
watch?.runner.stop();
|
|
3493
|
+
watch = undefined;
|
|
3494
|
+
};
|
|
3495
|
+
pi.on("session_shutdown", () => {
|
|
3496
|
+
stopWatch();
|
|
3497
|
+
wakeInFlight = false;
|
|
3498
|
+
});
|
|
3499
|
+
pi.on("message_start", (event) => {
|
|
3500
|
+
const message = event.message;
|
|
3501
|
+
if (message.role === "custom" && message.customType === READY_TYPE)
|
|
3502
|
+
wakeInFlight = false;
|
|
3503
|
+
});
|
|
3504
|
+
const flush = (ctx, expected) => {
|
|
3505
|
+
if (wakeInFlight || watch?.id !== expected || held.size === 0 || !ctx.isIdle())
|
|
3506
|
+
return;
|
|
3507
|
+
const snapshot = watch.runner.snapshot();
|
|
3508
|
+
if (!snapshot.available)
|
|
3509
|
+
return;
|
|
3510
|
+
const { id, parent } = watch;
|
|
3511
|
+
const ids = [...held].filter((candidate) => snapshot.ready.includes(candidate)).sort();
|
|
3512
|
+
held.clear();
|
|
3513
|
+
if (ids.length === 0)
|
|
3514
|
+
return;
|
|
3515
|
+
wakeInFlight = true;
|
|
3516
|
+
wakeSentAt = now();
|
|
3517
|
+
stallWarned = false;
|
|
3518
|
+
pi.sendMessage({
|
|
3519
|
+
customType: READY_TYPE,
|
|
3520
|
+
content: `Newly ready under ${parent}: ${ids.join(", ")}. Check speckit_watch status for watchId ${id} before acting; ignore this alert unless it reports active for exactly that ID. If active, recheck approval and fresh readiness and fill free lanes from all eligible beads in scope.`,
|
|
3521
|
+
display: true
|
|
3522
|
+
}, { triggerTurn: true });
|
|
3523
|
+
};
|
|
3524
|
+
pi.on("agent_settled", (event, ctx) => {
|
|
3525
|
+
if (!event.aborted && watch !== undefined)
|
|
3526
|
+
flush(ctx, watch.id);
|
|
3527
|
+
});
|
|
3528
|
+
pi.registerCommand("speckit-watch-stop", {
|
|
3529
|
+
description: "Stop the current SpecKit readiness watch",
|
|
3530
|
+
handler: async (_args, ctx) => {
|
|
3531
|
+
stopWatch();
|
|
3532
|
+
if (ctx.hasUI)
|
|
3533
|
+
ctx.ui.notify("SpecKit readiness watch stopped", "info");
|
|
3534
|
+
}
|
|
3535
|
+
});
|
|
3536
|
+
pi.registerTool({
|
|
3537
|
+
name: "speckit_watch",
|
|
3538
|
+
label: "SpecKit readiness watch",
|
|
3539
|
+
description: "Start, inspect, or stop the main session's SpecKit readiness watch.",
|
|
3540
|
+
parameters: Type.Object({
|
|
3541
|
+
action: Type.Union([Type.Literal("start"), Type.Literal("status"), Type.Literal("stop")]),
|
|
3542
|
+
parent: Type.Optional(Type.String({ description: "Implement-step bead ID; required to start." })),
|
|
3543
|
+
only: Type.Optional(Type.Array(Type.String(), { description: "Limit alerts to these bead IDs, if requested." })),
|
|
3544
|
+
watchId: Type.Optional(Type.String({ description: "Check this watch ID before acting on an alert." }))
|
|
3545
|
+
}),
|
|
3546
|
+
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
3547
|
+
const output = (data) => ({ content: [{ type: "text", text: JSON.stringify(data) }], details: data });
|
|
3548
|
+
if (params.watchId !== undefined && params.watchId !== watch?.id)
|
|
3549
|
+
return output({ active: false });
|
|
3550
|
+
if (params.action === "stop") {
|
|
3551
|
+
stopWatch();
|
|
3552
|
+
return output({ active: false });
|
|
3553
|
+
}
|
|
3554
|
+
const status = () => watch === undefined ? output({ active: false }) : output({ active: true, watchId: watch.id, parent: watch.parent, only: watch.only, ...watch.runner.snapshot() });
|
|
3555
|
+
if (params.action === "status")
|
|
3556
|
+
return status();
|
|
3557
|
+
if (params.action !== "start" || !validBeadId(params.parent))
|
|
3558
|
+
return output({ error: "An implement-step bead ID is required" });
|
|
3559
|
+
if (!ctx.hasUI || workspaceOf(ctx.cwd) === undefined)
|
|
3560
|
+
return output({ error: "A live Pi UI in a SpecKit workspace is required" });
|
|
3561
|
+
const only = Array.isArray(params.only) ? [...new Set(params.only)].sort() : [];
|
|
3562
|
+
if (!only.every(validBeadId))
|
|
3563
|
+
return output({ error: "Invalid selected bead ID" });
|
|
3564
|
+
if (watch !== undefined) {
|
|
3565
|
+
return watch.parent === params.parent && JSON.stringify(watch.only) === JSON.stringify(only) ? status() : output({ error: "Stop the existing watch before starting one for a different scope" });
|
|
3566
|
+
}
|
|
3567
|
+
if (starting !== undefined)
|
|
3568
|
+
return output({ error: "A watch is already starting" });
|
|
3569
|
+
const request = implementRequest;
|
|
3570
|
+
if (request === undefined)
|
|
3571
|
+
return output({ error: "A watch starts only after the user runs /speckit.implement in this session" });
|
|
3572
|
+
const init = new AbortController;
|
|
3573
|
+
starting = init;
|
|
3574
|
+
try {
|
|
3575
|
+
const parent = params.parent;
|
|
3576
|
+
const initSignal = signal === undefined ? init.signal : AbortSignal.any([signal, init.signal]);
|
|
3577
|
+
const ledger = await (deps.watchLedger ?? watchLedger)(ctx.cwd);
|
|
3578
|
+
const unmet = await (deps.verifyStep ?? verifyImplementStep)({ cwd: ctx.cwd, ledger, parent, only }, initSignal);
|
|
3579
|
+
if (unmet !== undefined)
|
|
3580
|
+
return output({ error: unmet });
|
|
3581
|
+
const scope = only.length === 0 ? "all eligible work beads under it" : `only ${only.join(", ")}`;
|
|
3582
|
+
const approved = await ctx.ui.confirm("Start SpecKit readiness watch?", `Implement step ${parent} in ${ledger}: ${scope}.${request === "" ? "" : `
|
|
3583
|
+
Your request: ${request}`}
|
|
3584
|
+
The watch only reads readiness and alerts when idle; it launches nothing.`, { signal: initSignal });
|
|
3585
|
+
if (initSignal.aborted || init !== starting || implementRequest !== request)
|
|
3586
|
+
return output({ active: false });
|
|
3587
|
+
if (!approved)
|
|
3588
|
+
return output({ error: "The user did not authorize this watch scope" });
|
|
3589
|
+
implementRequest = undefined;
|
|
3590
|
+
const id = randomUUID2();
|
|
3591
|
+
const runner = createReadyWatch({ cwd: ctx.cwd, ledger, parent, only }, {
|
|
3592
|
+
...deps.readyWatch,
|
|
3593
|
+
onReady(ids) {
|
|
3594
|
+
for (const ready of ids)
|
|
3595
|
+
held.add(ready);
|
|
3596
|
+
},
|
|
3597
|
+
onScan(ready) {
|
|
3598
|
+
for (const candidate of held)
|
|
3599
|
+
if (!ready.includes(candidate))
|
|
3600
|
+
held.delete(candidate);
|
|
3601
|
+
warnIfStalled(ctx);
|
|
3602
|
+
flush(ctx, id);
|
|
3603
|
+
},
|
|
3604
|
+
onUnavailable() {
|
|
3605
|
+
notify(ctx, "SpecKit could not read readiness; the watch will retry");
|
|
3606
|
+
}
|
|
3607
|
+
});
|
|
3608
|
+
watch = { id, parent, only, runner };
|
|
3609
|
+
await runner.start();
|
|
3610
|
+
return watch?.id === id ? status() : output({ active: false });
|
|
3611
|
+
} catch {
|
|
3612
|
+
return output({ error: "Could not verify the Beads ledger and implement step for the watch" });
|
|
3613
|
+
} finally {
|
|
3614
|
+
if (starting === init)
|
|
3615
|
+
starting = undefined;
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
});
|
|
3251
3619
|
pi.on("input", async (event, ctx) => {
|
|
3252
3620
|
analyzePending = false;
|
|
3253
3621
|
const command = routedCommand(event.text);
|
|
@@ -3264,6 +3632,8 @@ function setupSpeckitPi(pi, deps = {}) {
|
|
|
3264
3632
|
notify(ctx, route.reason);
|
|
3265
3633
|
return { action: "handled" };
|
|
3266
3634
|
}
|
|
3635
|
+
if (event.source === "interactive")
|
|
3636
|
+
implementRequest = command.args;
|
|
3267
3637
|
return { action: "transform", text: route.text };
|
|
3268
3638
|
});
|
|
3269
3639
|
pi.on("before_agent_start", (event, ctx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@srobroek/pi-speckit-beads",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "SpecKit on Beads: a tasks.md guard, setup, ledger and bugfix skills, formulas, and the speckit-sync and speckit-verify subagents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"provenance": true
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@earendil-works/pi-coding-agent": "*"
|
|
29
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
30
|
+
"typebox": "*"
|
|
30
31
|
},
|
|
31
32
|
"pi": {
|
|
32
33
|
"extensions": [
|