pi-dev-flow 0.101.0 → 0.101.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 CHANGED
@@ -4,6 +4,16 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.101.1] - 2026-12-04
8
+
9
+ **A reply in Jira reaches the session within about a minute.**
10
+
11
+ ### Changed
12
+ - **A reply in Jira reaches the session within about a minute.** dev-flow used to check for your answer after 30 minutes, then 1, 2 and every 4 hours, so a quick answer could wait hours. Now, while a question is open, it probes the issue every minute with one small call that reads only when the issue last changed. When that moves, it reads the comments and status at once. Jira gives that time only to the minute, so a change is checked once more a minute later, and an answer in the same minute is not missed. The old schedule stays as the backstop. `probe = 2m` in the `flow-jira` block sets the interval (15 seconds at least); `probe = off` turns it off. A failing probe backs off to every 15 minutes.
13
+
14
+ ### Fixed
15
+ - **The doctor no longer misses an empty feature dir made the same millisecond it looks.** It compared the dir's age against zero, and a filesystem time a fraction of a millisecond past the clock made a brand-new dir look younger than that. With no minimum age asked for, the age is no longer checked. This also made a test fail now and then, which once stopped a release publish.
16
+
7
17
  ## [0.101.0] - 2026-12-04
8
18
 
9
19
  **Jira issues get the plan as a PDF, mockups included, one per round of the plan discussion.**
package/docs/jira.md CHANGED
@@ -51,7 +51,11 @@ status.Story.done = Done
51
51
 
52
52
  ## Watching for your reply
53
53
 
54
- After a question is posted, dev-flow checks the issue on the `watch` schedule: after 30 minutes, then 1 hour later, 2 hours later, and every 4 hours after that, for up to 72 hours. Each check is two HTTP calls and costs no model tokens.
54
+ After a question is posted, dev-flow watches the issue for up to 72 hours (`watchCap`). It costs no model tokens.
55
+
56
+ - **Every minute it probes**: one small call that reads only the issue's last-changed time and status. A comment or a status move changes them, and the full check (comments and status, two calls) runs at once. So your answer reaches the session within about a minute. Jira reports that time only to the minute, so after a change dev-flow checks once more a minute later; an answer posted in the same minute is not missed. Set the interval with `probe = 2m` in the `flow-jira` block (15 seconds at least), or turn it off with `probe = off`. A failing probe slows down, up to every 15 minutes, until it succeeds again.
57
+ - **The `watch` schedule is the backstop**: full checks after 30 minutes, then 1 hour later, 2 hours later, and every 4 hours after that. They report errors the probe keeps quiet about. With `probe = off`, they are the only checks.
58
+ - An open question costs about 60 small calls an hour; nothing is polled while no question is open.
55
59
 
56
60
  - **In pi-web**, an idle session is normally shut down after 10 minutes. While a watch is waiting, dev-flow holds pi-web's session-liveness lease, so the session stays alive to receive your answer. The lease is released when you answer, when the cap passes, or when you reply in chat instead.
57
61
  - **If the session ends anyway** (pi-web restarted, or you closed it), the question stays recorded. When you open the session again, dev-flow checks Jira right away and resumes watching.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dev-flow",
3
- "version": "0.101.0",
3
+ "version": "0.101.1",
4
4
  "description": "Enforced feature workflow for Pi: plan → implement → pre-release → release, gated checkpoints, self-improvement reflections, one git worktree per feature, changelog + publish as part of the release",
5
5
  "type": "module",
6
6
  "keywords": [
package/src/core.ts CHANGED
@@ -153,6 +153,8 @@ export interface JiraConfig {
153
153
  watch: number[];
154
154
  /** seconds after the question when the watch gives up */
155
155
  watchCap: number;
156
+ /** seconds between cheap "did the issue change?" probes while a question waits; 0 = off; unset = 60 */
157
+ probe?: number;
156
158
  }
157
159
 
158
160
  /** A flow's link to its Jira issue, in state.json. */
@@ -178,6 +180,8 @@ export interface JiraLink {
178
180
  seeded?: string;
179
181
  /** sha1 of the last closing message mirrored — the same message is never posted twice */
180
182
  mirrored?: string;
183
+ /** the issue's `updated` time as the probe last saw it, once a full check had read up to it */
184
+ updatedSeen?: string;
181
185
  /** the open question a watch is waiting on: armed when it was posted, `checks` made since */
182
186
  watch?: { ask: string; since: string; checks: number };
183
187
  }
@@ -311,6 +311,18 @@ export class JiraClient {
311
311
  };
312
312
  }
313
313
 
314
+ /** The issue's `updated` time and status — one small read, the watch's probe. A comment, an edit or a move
315
+ * all bump `updated`. An empty `updated` (the server left it out) means "unknown": treat it as changed. */
316
+ async stamp(key: string): Promise<JiraResult<{ updated: string; status: string }>> {
317
+ const t = await this.tool("issue").catch(() => undefined);
318
+ const asString = (t?.inputSchema?.properties as Record<string, { type?: string }> | undefined)?.fields?.type === "string";
319
+ const r = await this.call("issue", { issue: key, fields: asString ? "updated,status" : ["updated", "status"] });
320
+ if (!r.ok) return r;
321
+ const v = rec(r.value);
322
+ const f = rec(v.fields ?? v);
323
+ return { ok: true, value: { updated: str(f.updated), status: str(rec(f.status).name ?? f.status) } };
324
+ }
325
+
314
326
  /** The newest comments, newest first: pages of 20 (the server's cap) up to COMMENTS_MAX. */
315
327
  async comments(key: string): Promise<JiraResult<JiraComment[]>> {
316
328
  const toC = (c: Record<string, unknown>): JiraComment => {
@@ -13,6 +13,8 @@
13
13
  * mirror = asks asks (default) | all — which of the agent's closing messages become comments
14
14
  * watch = 30m, 1h, 2h, 4h reply-check intervals after a question; the last repeats
15
15
  * watchCap = 72h stop watching this long after the question
16
+ * probe = 1m while a question waits, look this often whether the issue changed (one
17
+ * small call); a change runs the full check. off = the schedule only
16
18
  *
17
19
  * A status value may name several statuses (`To Do, Backlog`): any of them means that stage; the first is
18
20
  * the one dev-flow moves the issue to. Pure module.
@@ -22,6 +24,12 @@ import type { JiraConfig, JiraStage } from "../core.ts";
22
24
  export const JIRA_STAGES: readonly JiraStage[] = ["plan", "implement", "pre-release", "release", "done"];
23
25
  export const DEFAULT_WATCH = [30 * 60, 60 * 60, 2 * 3600, 4 * 3600];
24
26
  export const DEFAULT_WATCH_CAP = 72 * 3600;
27
+ export const DEFAULT_PROBE = 60;
28
+ /** The shortest probe interval accepted: a faster one would only spend the token's rate limit. */
29
+ export const MIN_PROBE = 15;
30
+
31
+ /** Seconds between probes for `cfg` (0 = off). */
32
+ export const probeSecs = (cfg: Pick<JiraConfig, "probe">) => cfg.probe ?? DEFAULT_PROBE;
25
33
 
26
34
  /** `30m` / `1h` / `2d` / `90s` / `45` (seconds) → seconds; undefined for junk. */
27
35
  export function parseDuration(raw: string): number | undefined {
@@ -93,6 +101,16 @@ export function parseJiraBlock(entries: { line: string; where: string }[]): { cf
93
101
  else cfg.watchCap = s;
94
102
  break;
95
103
  }
104
+ case "probe": {
105
+ const v = value.trim().toLowerCase();
106
+ const s = /^(off|no|none|0)$/.test(v) ? 0 : parseDuration(v);
107
+ if (s === undefined) warn.push(`${where}: flow-jira probe = "${value}" — expected a duration like 1m, or off — keeping 1m`);
108
+ else if (s && s < MIN_PROBE) {
109
+ warn.push(`${where}: flow-jira probe = "${value}" is below ${MIN_PROBE}s — using ${MIN_PROBE}s`);
110
+ cfg.probe = MIN_PROBE;
111
+ } else cfg.probe = s;
112
+ break;
113
+ }
96
114
  default:
97
115
  warn.push(`${where}: unknown flow-jira key "${key}" — ignored`);
98
116
  }
@@ -115,6 +133,7 @@ export function renderJiraBlock(cfg: JiraConfig): string[] {
115
133
  if (cfg.mirror !== "asks") L.push(`mirror = ${cfg.mirror}`);
116
134
  if (cfg.watch.join() !== DEFAULT_WATCH.join()) L.push(`watch = ${cfg.watch.map(fmtDuration).join(", ")}`);
117
135
  if (cfg.watchCap !== DEFAULT_WATCH_CAP) L.push(`watchCap = ${fmtDuration(cfg.watchCap)}`);
136
+ if (cfg.probe !== undefined && cfg.probe !== DEFAULT_PROBE) L.push(`probe = ${cfg.probe ? fmtDuration(cfg.probe) : "off"}`);
118
137
  return L;
119
138
  }
120
139
 
package/src/projectmd.ts CHANGED
@@ -564,7 +564,8 @@ export function emptyFeatureDirs(root: string, minAgeMs = 0, nowMs = Date.now())
564
564
  const df = path.join(root, ".dev-flow");
565
565
  if (!existsSync(df)) return [];
566
566
  return readdirSync(df, { withFileTypes: true })
567
- .filter((d) => d.isDirectory() && holdsNoFile(path.join(df, d.name)) && nowMs - statSync(path.join(df, d.name)).mtimeMs >= minAgeMs)
567
+ // no minimum age: skip the clock — a dir made this very millisecond has an mtime a fraction past Date.now()
568
+ .filter((d) => d.isDirectory() && holdsNoFile(path.join(df, d.name)) && (minAgeMs <= 0 || nowMs - statSync(path.join(df, d.name)).mtimeMs >= minAgeMs))
568
569
  .map((d) => `.dev-flow/${d.name}`);
569
570
  }
570
571
 
@@ -1,15 +1,19 @@
1
1
  /** dev-flow runtime — the Jira reply watch: per session, one timer checking the linked issue on the playbook's
2
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.
3
+ * HTTP calls. Between scheduled checks a probe looks every `probe` seconds (default 1m) whether the issue
4
+ * changed — one small call — and runs the full check as soon as it did, so an answer arrives within about a
5
+ * minute; the schedule stays as the backstop. An answer is delivered as the operator's message and ends the
6
+ * watch.
4
7
  *
5
8
  * While a watch is armed, pi-web's session-liveness registry keeps the session from being reaped as idle
6
9
  * (pi-web docs/integrations.md: Symbol.for("@agegr/pi-web/session-liveness/v1")); elsewhere the lease is a
7
10
  * no-op and the timer simply lives as long as the process. A session that ends keeps `jira.watch` in state,
8
11
  * and the next session_start catches up and re-arms it. */
9
12
  import { loadProject } from "../projectmd.ts";
13
+ import { probeSecs } from "../jira/config.ts";
10
14
  import { nextCheckDelay, type Relay } from "../jira/sync.ts";
11
15
  import { dfDir, readState } from "./base.ts";
12
- import { checkReplies, disarmWatch } from "./jira.ts";
16
+ import { checkReplies, disarmWatch, probeIssue, recordStamp } from "./jira.ts";
13
17
 
14
18
  export interface WatchDeps {
15
19
  /** deliver relays to the session `key` */
@@ -32,11 +36,23 @@ type LivenessRegistry = { version: number; register: (o: { name: string; session
32
36
 
33
37
  /** The longest a single timer waits; a long interval is reached by re-arming (Node timers cap near 24.8 days). */
34
38
  const MAX_TIMER_MS = 6 * 3600 * 1000;
39
+ const MINUTE_MS = 60_000;
40
+ /** A failing probe backs off, doubling, up to this; the scheduled checks still report the failure. */
41
+ const MAX_PROBE_BACKOFF_MS = 15 * 60_000;
42
+
43
+ /** What a timer does when it fires: the scheduled full check, a probe, or just re-arm (a long wait in parts). */
44
+ type Wake = "check" | "probe" | "partial";
35
45
 
36
46
  export class JiraWatch {
37
47
  private readonly armed = new Map<string, Armed>();
38
48
  private readonly leases = new Map<string, () => void>();
39
49
  private readonly busy = new Set<string>();
50
+ /** the probe interval of a session whose probe is failing (backed off); absent = the configured one */
51
+ private readonly backoff = new Map<string, number>();
52
+ /** a stamp the probe has seen but not yet settled: Jira's `updated` is minute-precision (17:03-0800), so a
53
+ * comment later in the same minute leaves it unchanged — the stamp counts as read only after a full check
54
+ * that ran a minute or more after it was first seen, i.e. after that minute ended */
55
+ private readonly unsettled = new Map<string, { stamp: string; firstSeen: number }>();
40
56
  private readonly deps: WatchDeps;
41
57
 
42
58
  constructor(deps: WatchDeps) {
@@ -67,8 +83,8 @@ export class JiraWatch {
67
83
  }
68
84
  }
69
85
 
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. */
86
+ /** (Re)arm the watch of `slug` in session `key` from its state: the next probe or scheduled check, whichever
87
+ * comes first, or nothing when the flow has no open question; past the cap the watch is dropped with a note. */
72
88
  arm(key: string, root: string, slug: string): void {
73
89
  this.cancel(key);
74
90
  const st = readState(root, slug);
@@ -78,31 +94,57 @@ export class JiraWatch {
78
94
  const delay = nextCheckDelay(cfg, Date.parse(w.since), w.checks, this.now());
79
95
  if (delay === null) {
80
96
  disarmWatch(root, slug);
97
+ this.backoff.delete(key);
81
98
  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
99
  return;
83
100
  }
84
- const ms = Math.min(delay, MAX_TIMER_MS);
101
+ const probeMs = probeSecs(cfg) ? (this.backoff.get(key) ?? probeSecs(cfg) * 1000) : Infinity;
102
+ const [ms, wake]: [number, Wake] = probeMs < delay ? [Math.min(probeMs, MAX_TIMER_MS), "probe"] : delay > MAX_TIMER_MS ? [MAX_TIMER_MS, "partial"] : [delay, "check"];
85
103
  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);
104
+ const timer = set(() => void this.tick(key, root, slug, wake), ms);
87
105
  this.armed.set(key, { root, slug, timer, at: this.now() + ms });
88
106
  }
89
107
 
90
108
  /** Run one check now (catch-up), then re-arm. */
91
109
  async checkNow(key: string, root: string, slug: string): Promise<void> {
92
- await this.tick(key, root, slug, false);
110
+ await this.tick(key, root, slug, "check");
93
111
  }
94
112
 
95
- private async tick(key: string, root: string, slug: string, partial: boolean): Promise<void> {
113
+ private async tick(key: string, root: string, slug: string, wake: Wake): Promise<void> {
96
114
  this.armed.delete(key);
97
- if (partial) return this.arm(key, root, slug);
115
+ if (wake === "partial") return this.arm(key, root, slug);
98
116
  if (this.busy.has(key)) return;
99
117
  this.busy.add(key);
100
118
  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);
119
+ const cfg = loadProject(dfDir(root)).cfg;
120
+ if (wake === "probe") {
121
+ const p = await probeIssue(root, cfg, slug);
122
+ if ("error" in p) {
123
+ const cur = this.backoff.get(key) ?? probeSecs(cfg.jira ?? {}) * 1000;
124
+ this.backoff.set(key, Math.min(cur * 2, MAX_PROBE_BACKOFF_MS));
125
+ } else {
126
+ this.backoff.delete(key);
127
+ if (p.changed) {
128
+ const at = this.now();
129
+ const r = await checkReplies(root, cfg, slug, { scheduled: false });
130
+ if (r.relays.length) this.deps.relay(key, r.relays);
131
+ if (!r.error && p.stamp) {
132
+ const u = this.unsettled.get(key);
133
+ if (u?.stamp !== p.stamp) this.unsettled.set(key, { stamp: p.stamp, firstSeen: at });
134
+ else if (at - u.firstSeen >= MINUTE_MS) {
135
+ recordStamp(root, slug, p.stamp);
136
+ this.unsettled.delete(key);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ } else {
142
+ const r = await checkReplies(root, cfg, slug);
143
+ if (r.error) this.deps.note(key, `Jira check failed (will retry on schedule): ${r.error}`);
144
+ if (r.relays.length) this.deps.relay(key, r.relays);
145
+ }
104
146
  } catch (e) {
105
- this.deps.note(key, `Jira check failed (will retry on schedule): ${(e as Error).message}`);
147
+ if (wake === "check") this.deps.note(key, `Jira check failed (will retry on schedule): ${(e as Error).message}`);
106
148
  } finally {
107
149
  this.busy.delete(key);
108
150
  }
@@ -120,6 +162,8 @@ export class JiraWatch {
120
162
  /** The session ended: stop the timer and give the lease back. */
121
163
  release(key: string): void {
122
164
  this.cancel(key);
165
+ this.backoff.delete(key);
166
+ this.unsettled.delete(key);
123
167
  this.leases.get(key)?.();
124
168
  this.leases.delete(key);
125
169
  }
@@ -119,6 +119,7 @@ export async function gateJiraInit(root: string, cfg: Config, rest: string[], fl
119
119
  mirror: (mirrorArg as "asks" | "all" | null) ?? cfg.jira?.mirror ?? "asks",
120
120
  watch: cfg.jira?.watch ?? [...DEFAULT_WATCH],
121
121
  watchCap: cfg.jira?.watchCap ?? DEFAULT_WATCH_CAP,
122
+ ...(cfg.jira?.probe !== undefined ? { probe: cfg.jira.probe } : {}),
122
123
  };
123
124
  const block = ["```flow-jira", ...renderJiraBlock(next), "```"].join("\n");
124
125
  const table = canon.map((t) => ` ${t}: ${JIRA_STAGES.map((g) => `${g} ← ${status[t][g]?.join(" | ") || "—"}`).join("; ")}`).join("\n");
@@ -470,8 +471,30 @@ export async function mirrorClosingMessage(root: string, cfg: Config, slug: stri
470
471
 
471
472
  // ---------------------------------------------------------------- inbound: one reply check
472
473
 
473
- /** Read the linked issue's new comments and its status; advance the link; return what to relay. */
474
- export async function checkReplies(root: string, cfg: Config, slug: string): Promise<{ relays: Relay[]; error?: string }> {
474
+ /** The watch's probe: one small read of the issue. `changed` when its `updated` time (or status) moved since the
475
+ * last full check the probe triggered, or when either is unknown; `stamp` is what to record once the full
476
+ * check has read past it (recordStamp). */
477
+ export async function probeIssue(root: string, cfg: Config, slug: string): Promise<{ changed: boolean; stamp: string } | { error: string }> {
478
+ const st = readState(root, slug);
479
+ if (!cfg.jira || !st?.jira) return { changed: false, stamp: "" };
480
+ const c = jiraClient(cfg.jira);
481
+ if ("error" in c) return { error: c.error };
482
+ const r = await c.client.stamp(st.jira.key);
483
+ if (!r.ok) return { error: r.error };
484
+ const { updated, status } = r.value;
485
+ const moved = !!status && !!st.jira.lastStatus && status.toLowerCase() !== st.jira.lastStatus.toLowerCase();
486
+ return { changed: !updated || !st.jira.updatedSeen || updated !== st.jira.updatedSeen || moved, stamp: updated };
487
+ }
488
+
489
+ /** The full check the probe ran has read everything up to `stamp`. */
490
+ export function recordStamp(root: string, slug: string, stamp: string): void {
491
+ const st = readState(root, slug);
492
+ if (st?.jira && stamp) writeState(root, { ...st, jira: { ...st.jira, updatedSeen: stamp } });
493
+ }
494
+
495
+ /** Read the linked issue's new comments and its status; advance the link; return what to relay. A check the
496
+ * probe triggered (`scheduled: false`) does not advance the watch schedule. */
497
+ export async function checkReplies(root: string, cfg: Config, slug: string, opts: { scheduled?: boolean } = {}): Promise<{ relays: Relay[]; error?: string }> {
475
498
  const st = readState(root, slug);
476
499
  if (!cfg.jira || !st?.jira) return { relays: [] };
477
500
  const c = jiraClient(cfg.jira);
@@ -488,7 +511,7 @@ export async function checkReplies(root: string, cfg: Config, slug: string): Pro
488
511
  const fresh = readState(root, slug) ?? st;
489
512
  const next: JiraLink = { ...(fresh.jira ?? link), accountId: link.accountId, seenUntil: r.seenUntil ?? link.seenUntil, seenCommentId: r.seenCommentId ?? link.seenCommentId, lastStatus: r.lastStatus };
490
513
  if (r.relays.some((x) => x.kind === "answer")) delete next.watch;
491
- else if (next.watch) next.watch = { ...next.watch, checks: next.watch.checks + 1 };
514
+ else if (next.watch && opts.scheduled !== false) next.watch = { ...next.watch, checks: next.watch.checks + 1 };
492
515
  writeState(root, { ...fresh, jira: next });
493
516
  return { relays: r.relays };
494
517
  }