pi-dev-flow 0.97.0 → 0.99.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 +42 -0
- package/README.md +5 -0
- package/docs/gates.md +11 -4
- package/docs/guardrails.md +12 -4
- package/docs/jira.md +68 -0
- package/docs/playbook.md +10 -3
- package/extensions/dev-flow.ts +194 -31
- package/package.json +1 -1
- package/skills/dev-flow/references/start.md +33 -0
- package/src/core.ts +148 -5
- package/src/jira/client.ts +425 -0
- package/src/jira/config.ts +192 -0
- package/src/jira/creds.ts +57 -0
- package/src/jira/mcp.ts +176 -0
- package/src/jira/sync.ts +123 -0
- package/src/projectmd.ts +45 -3
- package/src/runtime/base.ts +1 -1
- package/src/runtime/checks.ts +2 -0
- package/src/runtime/gates.ts +78 -5
- package/src/runtime/grants.ts +28 -1
- package/src/runtime/jira-watch.ts +126 -0
- package/src/runtime/jira.ts +533 -0
- package/src/runtime/ship.ts +31 -6
package/src/runtime/grants.ts
CHANGED
|
@@ -29,6 +29,30 @@ export function operatorMessageCount(entries: readonly unknown[] | null | undefi
|
|
|
29
29
|
return n;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/** The text of the operator's newest message in the branch, or null when it cannot be read. */
|
|
33
|
+
export function lastOperatorText(entries: readonly unknown[] | null | undefined): string | null {
|
|
34
|
+
if (!Array.isArray(entries)) return null;
|
|
35
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
36
|
+
// SAFETY: narrow structural view of the SessionEntry union; only a user message's text is read
|
|
37
|
+
const m = entries[i] as { type?: string; message?: { role?: string; content?: unknown } };
|
|
38
|
+
if (m.type !== "message" || m.message?.role !== "user") continue;
|
|
39
|
+
const c = m.message.content;
|
|
40
|
+
if (typeof c === "string") return c;
|
|
41
|
+
if (Array.isArray(c)) return c.map((p) => (p && typeof p === "object" && (p as { type?: string }).type === "text" ? String((p as { text?: unknown }).text ?? "") : "")).join(" ");
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Whether the operator's words name this release call (gh#299): `minor` for minor, `unreleased` / `no version`
|
|
48
|
+
* / `don't release` for unreleased. Null words (unreadable) are taken as naming it — nothing to check against. */
|
|
49
|
+
export function namesReleaseCall(words: string | null, choice: string): boolean {
|
|
50
|
+
if (words === null) return true;
|
|
51
|
+
const w = words.toLowerCase();
|
|
52
|
+
if (choice === "unreleased") return /\bunreleased\b|\bno[- ]?version\b|\bdon'?t (?:release|version|bump)\b|\bwithout (?:a )?(?:release|version|bump)\b|\bno (?:release|bump)\b/.test(w);
|
|
53
|
+
return new RegExp(`\\b${choice}\\b`).test(w);
|
|
54
|
+
}
|
|
55
|
+
|
|
32
56
|
export interface GrantLedger {
|
|
33
57
|
/** per session: the gate that last asked for the operator's word, and the operator-message count then */
|
|
34
58
|
asked: Map<string, { sub: string; users: number }>;
|
|
@@ -69,7 +93,10 @@ export function grantCheck(args: readonly string[], key: string, users: number |
|
|
|
69
93
|
export function grantRecord(args: readonly string[], key: string, users: number | null, res: { text: string; isError?: boolean }, ledger: GrantLedger): void {
|
|
70
94
|
if (users === null) return;
|
|
71
95
|
const sub = args[0] ?? "";
|
|
72
|
-
|
|
96
|
+
// gh#283: a stopped or waiting publish resumes on a re-run and asks nobody — its prose may still mention the
|
|
97
|
+
// operator's word (a real failure's way forward), which must not turn the resume into a question
|
|
98
|
+
const resumable = /(?:^|\n)publish (?:stopped|waiting) —/.test(res.text);
|
|
99
|
+
if (res.isError && !resumable && (res.text.startsWith(NEEDS_OPERATOR) || ASKS_FOR_WORD.test(res.text))) {
|
|
73
100
|
ledger.asked.set(key, { sub, users });
|
|
74
101
|
return;
|
|
75
102
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** dev-flow runtime — the Jira reply watch: per session, one timer checking the linked issue on the playbook's
|
|
2
|
+
* schedule (30m, 1h, 2h, 4h, … until watchCap after the question), with no model turn — each check is two
|
|
3
|
+
* HTTP calls. An answer is delivered as the operator's message and ends the watch.
|
|
4
|
+
*
|
|
5
|
+
* While a watch is armed, pi-web's session-liveness registry keeps the session from being reaped as idle
|
|
6
|
+
* (pi-web docs/integrations.md: Symbol.for("@agegr/pi-web/session-liveness/v1")); elsewhere the lease is a
|
|
7
|
+
* no-op and the timer simply lives as long as the process. A session that ends keeps `jira.watch` in state,
|
|
8
|
+
* and the next session_start catches up and re-arms it. */
|
|
9
|
+
import { loadProject } from "../projectmd.ts";
|
|
10
|
+
import { nextCheckDelay, type Relay } from "../jira/sync.ts";
|
|
11
|
+
import { dfDir, readState } from "./base.ts";
|
|
12
|
+
import { checkReplies, disarmWatch } from "./jira.ts";
|
|
13
|
+
|
|
14
|
+
export interface WatchDeps {
|
|
15
|
+
/** deliver relays to the session `key` */
|
|
16
|
+
relay: (key: string, relays: Relay[]) => void;
|
|
17
|
+
/** a note for the operator only (watch stopped, check failed) */
|
|
18
|
+
note: (key: string, text: string) => void;
|
|
19
|
+
setTimer?: (fn: () => void, ms: number) => unknown;
|
|
20
|
+
clearTimer?: (t: unknown) => void;
|
|
21
|
+
nowMs?: () => number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Armed {
|
|
25
|
+
root: string;
|
|
26
|
+
slug: string;
|
|
27
|
+
timer: unknown;
|
|
28
|
+
at: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type LivenessRegistry = { version: number; register: (o: { name: string; sessionId: string; sessionFile?: string; isActive: () => boolean }) => () => void };
|
|
32
|
+
|
|
33
|
+
/** The longest a single timer waits; a long interval is reached by re-arming (Node timers cap near 24.8 days). */
|
|
34
|
+
const MAX_TIMER_MS = 6 * 3600 * 1000;
|
|
35
|
+
|
|
36
|
+
export class JiraWatch {
|
|
37
|
+
private readonly armed = new Map<string, Armed>();
|
|
38
|
+
private readonly leases = new Map<string, () => void>();
|
|
39
|
+
private readonly busy = new Set<string>();
|
|
40
|
+
private readonly deps: WatchDeps;
|
|
41
|
+
|
|
42
|
+
constructor(deps: WatchDeps) {
|
|
43
|
+
this.deps = deps;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private now() {
|
|
47
|
+
return this.deps.nowMs?.() ?? Date.now();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
isArmed(key: string): boolean {
|
|
51
|
+
return this.armed.has(key);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
nextAt(key: string): number | undefined {
|
|
55
|
+
return this.armed.get(key)?.at;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Hold pi-web's liveness lease for this session while a watch is armed (once per session). */
|
|
59
|
+
lease(key: string, sessionId: string | undefined, sessionFile: string | undefined): void {
|
|
60
|
+
if (this.leases.has(key) || !sessionId) return;
|
|
61
|
+
const reg = (globalThis as Record<symbol, unknown>)[Symbol.for("@agegr/pi-web/session-liveness/v1")] as LivenessRegistry | undefined;
|
|
62
|
+
if (reg?.version !== 1) return;
|
|
63
|
+
try {
|
|
64
|
+
this.leases.set(key, reg.register({ name: "pi-dev-flow jira watch", sessionId, sessionFile, isActive: () => this.armed.has(key) }));
|
|
65
|
+
} catch {
|
|
66
|
+
/* a registry that refuses leaves pi-web's idle timeout in charge */
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** (Re)arm the watch of `slug` in session `key` from its state: the next check on the schedule, or nothing
|
|
71
|
+
* when the flow has no open question; past the cap the watch is dropped with a note. */
|
|
72
|
+
arm(key: string, root: string, slug: string): void {
|
|
73
|
+
this.cancel(key);
|
|
74
|
+
const st = readState(root, slug);
|
|
75
|
+
const cfg = loadProject(dfDir(root)).cfg.jira;
|
|
76
|
+
const w = st?.jira?.watch;
|
|
77
|
+
if (!cfg || !w) return;
|
|
78
|
+
const delay = nextCheckDelay(cfg, Date.parse(w.since), w.checks, this.now());
|
|
79
|
+
if (delay === null) {
|
|
80
|
+
disarmWatch(root, slug);
|
|
81
|
+
this.deps.note(key, `Jira ${st!.jira!.key}: no answer to ${w.ask} within the watch window — stopped watching. Answer here, or run flow jira check after answering in Jira.`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const ms = Math.min(delay, MAX_TIMER_MS);
|
|
85
|
+
const set = this.deps.setTimer ?? ((fn: () => void, t: number) => setTimeout(fn, t).unref?.() ?? undefined);
|
|
86
|
+
const timer = set(() => void this.tick(key, root, slug, ms < delay), ms);
|
|
87
|
+
this.armed.set(key, { root, slug, timer, at: this.now() + ms });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Run one check now (catch-up), then re-arm. */
|
|
91
|
+
async checkNow(key: string, root: string, slug: string): Promise<void> {
|
|
92
|
+
await this.tick(key, root, slug, false);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private async tick(key: string, root: string, slug: string, partial: boolean): Promise<void> {
|
|
96
|
+
this.armed.delete(key);
|
|
97
|
+
if (partial) return this.arm(key, root, slug);
|
|
98
|
+
if (this.busy.has(key)) return;
|
|
99
|
+
this.busy.add(key);
|
|
100
|
+
try {
|
|
101
|
+
const r = await checkReplies(root, loadProject(dfDir(root)).cfg, slug);
|
|
102
|
+
if (r.error) this.deps.note(key, `Jira check failed (will retry on schedule): ${r.error}`);
|
|
103
|
+
if (r.relays.length) this.deps.relay(key, r.relays);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
this.deps.note(key, `Jira check failed (will retry on schedule): ${(e as Error).message}`);
|
|
106
|
+
} finally {
|
|
107
|
+
this.busy.delete(key);
|
|
108
|
+
}
|
|
109
|
+
this.arm(key, root, slug);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Stop the timer (the state keeps its watch, so a later session can resume it). */
|
|
113
|
+
cancel(key: string): void {
|
|
114
|
+
const a = this.armed.get(key);
|
|
115
|
+
if (!a) return;
|
|
116
|
+
(this.deps.clearTimer ?? ((t: unknown) => clearTimeout(t as NodeJS.Timeout)))(a.timer);
|
|
117
|
+
this.armed.delete(key);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The session ended: stop the timer and give the lease back. */
|
|
121
|
+
release(key: string): void {
|
|
122
|
+
this.cancel(key);
|
|
123
|
+
this.leases.get(key)?.();
|
|
124
|
+
this.leases.delete(key);
|
|
125
|
+
}
|
|
126
|
+
}
|