pi-dev-flow 0.101.0 → 0.101.2
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 +17 -0
- package/docs/jira.md +9 -2
- package/package.json +1 -1
- package/skills/dev-flow/references/start.md +4 -1
- package/src/core.ts +7 -0
- package/src/jira/client.ts +32 -2
- package/src/jira/config.ts +29 -0
- package/src/jira/sync.ts +12 -4
- package/src/projectmd.ts +2 -1
- package/src/runtime/jira-watch.ts +57 -13
- package/src/runtime/jira.ts +47 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,23 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.101.2] - 2026-12-04
|
|
8
|
+
|
|
9
|
+
**Your Jira comments count as answers when dev-flow posts as a separate account.**
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **Your Jira comments count as answers when dev-flow posts as a separate account.** dev-flow treated only the token owner's comments as your answer. With a token made for a separate agent account, your own comments were shown as "information only" and never answered a question or approved a gate. A new `answerers` key in the `flow-jira` block names the accounts whose comments count: Jira account ids, or `token` for the token's own account (the default). `flow jira init` now asks **Who answers?** and lists the people on the project's recent issues with their account ids. A project already set up with a separate agent account adds the key by hand, or re-runs `flow jira init`.
|
|
13
|
+
|
|
14
|
+
## [0.101.1] - 2026-12-04
|
|
15
|
+
|
|
16
|
+
**A reply in Jira reaches the session within about a minute.**
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- **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.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- **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.
|
|
23
|
+
|
|
7
24
|
## [0.101.0] - 2026-12-04
|
|
8
25
|
|
|
9
26
|
**Jira issues get the plan as a PDF, mockups included, one per round of the plan discussion.**
|
package/docs/jira.md
CHANGED
|
@@ -11,6 +11,7 @@ It talks to Atlassian's official **Rovo MCP server** (`https://mcp.atlassian.com
|
|
|
11
11
|
3. **Ask the agent to set up Jira sync.** It runs `flow jira init`, which asks you one question at a time:
|
|
12
12
|
- **Jira project?** Which project this repo syncs with.
|
|
13
13
|
- **Issue types?** The types a flow may start from, such as Story or Bug.
|
|
14
|
+
- **Who answers?** Whose comments count as your answer. dev-flow posts as the token's account. If that is a separate account, such as a bot made for the agent, name the account you comment as. dev-flow lists the people on the project's recent issues with their account ids. Pick `token` when the token is your own.
|
|
14
15
|
- **Mapping OK?** For each type, dev-flow reads its workflow and suggests a status for each flow stage. You can change any of them.
|
|
15
16
|
|
|
16
17
|
The answers are written to `project.md`:
|
|
@@ -20,6 +21,7 @@ site = acme.atlassian.net
|
|
|
20
21
|
cloudId = …
|
|
21
22
|
project = DEV
|
|
22
23
|
issueTypes = Story, Bug
|
|
24
|
+
answerers = 557058:1361862d-…
|
|
23
25
|
status.Story.plan = To Do, Backlog
|
|
24
26
|
status.Story.implement = In Progress
|
|
25
27
|
status.Story.pre-release = In Review
|
|
@@ -30,6 +32,7 @@ status.Story.done = Done
|
|
|
30
32
|
| Key | Meaning |
|
|
31
33
|
|---|---|
|
|
32
34
|
| `status.<Type>.<stage>` | Statuses that mean that stage: `plan`, `implement`, `pre-release`, `release` or `done`. dev-flow moves the issue to the first one listed. |
|
|
35
|
+
| `answerers` | Whose comments answer dev-flow's questions and can approve its gates: Jira account ids, or `token` for the token's own account. The default is `token`. Set it when dev-flow posts as a bot account and you answer as yourself; otherwise your comments are shown as information only. An account id is the last part of your Jira profile URL (`…/jira/people/<id>`). |
|
|
33
36
|
| `mirror` | `asks` (the default) posts the agent's closing message when it asks you something. `all` posts every closing message. |
|
|
34
37
|
| `watch` | How long to wait between checks for your reply after a question: `30m, 1h, 2h, 4h` by default. The last interval repeats. |
|
|
35
38
|
| `watchCap` | Stop checking this long after the question. Default `72h`. |
|
|
@@ -43,7 +46,7 @@ status.Story.done = Done
|
|
|
43
46
|
- **The plan goes as a PDF, one per round.** Jira can't show `plan.md` with its embedded mockups, so at the plan stage dev-flow prints the plan to a PDF with the mockups in it and attaches it to the comment, for example `DEV-12-plan-v1.pdf`. When the plan changes and you are asked again, the next comment gets `DEV-12-plan-v2.pdf`, so each round of the plan discussion has its own PDF on the issue. A re-rendered mockup counts as a change. If you are asked about an unchanged plan, the comment names the PDF already on the issue instead of attaching another. Until the plan is more than the issue's own description, no PDF is attached. The PDF is printed with the same headless chromium the plan stage renders mockups with: `chromium` or `google-chrome` on `PATH`, Playwright's browser cache, or the binary in `DEV_FLOW_CHROMIUM`. Without one, dev-flow attaches `plan.md` and the mockup images as files and says why.
|
|
44
47
|
- **The approved plan always reaches the issue.** When the plan is approved, dev-flow posts it to the issue, with its PDF attached unless that version is already there. This covers approvals that never passed through a mirrored question: you approved in chat, or the issue was created or linked at the moment you approved. If the identical plan was already posted with the Approve? question, the approval comment names that PDF. A flow linked to an issue after approval gets its plan posted at link time.
|
|
45
48
|
- **Answering in Jira:**
|
|
46
|
-
- **Comment**, for example "Approved", "Verified", or a change request. Only comments from your
|
|
49
|
+
- **Comment**, for example "Approved", "Verified", or a change request. Only comments from the `answerers` accounts count as your answer: by default the token's owner, which is you when the token is your own. Other people's comments are shown in the session as information and never approve anything.
|
|
47
50
|
- **Move the issue** to the status mapped to the next stage. A move to `implement` answers Approve?, `pre-release` answers Verified?, `release` answers Release?, and `done` answers Finish?. Any other move is shown as information.
|
|
48
51
|
|
|
49
52
|
Your answer arrives in the session as your own message, so the gates treat it exactly like a chat reply.
|
|
@@ -51,7 +54,11 @@ status.Story.done = Done
|
|
|
51
54
|
|
|
52
55
|
## Watching for your reply
|
|
53
56
|
|
|
54
|
-
After a question is posted, dev-flow
|
|
57
|
+
After a question is posted, dev-flow watches the issue for up to 72 hours (`watchCap`). It costs no model tokens.
|
|
58
|
+
|
|
59
|
+
- **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.
|
|
60
|
+
- **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.
|
|
61
|
+
- An open question costs about 60 small calls an hour; nothing is polled while no question is open.
|
|
55
62
|
|
|
56
63
|
- **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
64
|
- **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.
|
|
3
|
+
"version": "0.101.2",
|
|
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": [
|
|
@@ -63,7 +63,10 @@ knobs · merge-policy state.
|
|
|
63
63
|
ask for the token in chat.
|
|
64
64
|
2. `Jira project?` → `--project=KEY`.
|
|
65
65
|
3. `Issue types?` → `--types=A,B`.
|
|
66
|
-
4. `
|
|
66
|
+
4. `Who answers?` → `--answerers=<account id>[,…]`, or `--answerers=token`
|
|
67
|
+
when the token is the operator's own. Only these accounts' comments
|
|
68
|
+
answer questions and grant gates.
|
|
69
|
+
5. `Mapping OK?` — show the proposed status mapping. The operator can
|
|
67
70
|
change it with `--map=<Type>.<stage>=<Status>`. On their word,
|
|
68
71
|
re-run with `--confirmed`.
|
|
69
72
|
- **Starting from an issue.** When the operator names an issue key, run
|
package/src/core.ts
CHANGED
|
@@ -153,6 +153,11 @@ export interface JiraConfig {
|
|
|
153
153
|
watch: number[];
|
|
154
154
|
/** seconds after the question when the watch gives up */
|
|
155
155
|
watchCap: number;
|
|
156
|
+
/** the Jira accounts whose comments answer dev-flow's questions (and so may grant a gate): account ids, or
|
|
157
|
+
* `token` for the token's own account. Unset = the token's account — wrong when the token is a bot's */
|
|
158
|
+
answerers?: string[];
|
|
159
|
+
/** seconds between cheap "did the issue change?" probes while a question waits; 0 = off; unset = 60 */
|
|
160
|
+
probe?: number;
|
|
156
161
|
}
|
|
157
162
|
|
|
158
163
|
/** A flow's link to its Jira issue, in state.json. */
|
|
@@ -178,6 +183,8 @@ export interface JiraLink {
|
|
|
178
183
|
seeded?: string;
|
|
179
184
|
/** sha1 of the last closing message mirrored — the same message is never posted twice */
|
|
180
185
|
mirrored?: string;
|
|
186
|
+
/** the issue's `updated` time as the probe last saw it, once a full check had read up to it */
|
|
187
|
+
updatedSeen?: string;
|
|
181
188
|
/** the open question a watch is waiting on: armed when it was posted, `checks` made since */
|
|
182
189
|
watch?: { ask: string; since: string; checks: number };
|
|
183
190
|
}
|
package/src/jira/client.ts
CHANGED
|
@@ -54,12 +54,15 @@ const TOOLS = {
|
|
|
54
54
|
transitions: ["listJiraIssueTransitions", "getTransitionsForJiraIssue"],
|
|
55
55
|
transition: ["transitionJiraIssue"],
|
|
56
56
|
create: ["createJiraIssue"],
|
|
57
|
+
search: ["searchJiraIssuesUsingJql"],
|
|
57
58
|
} as const;
|
|
58
59
|
type Op = keyof typeof TOOLS;
|
|
59
60
|
|
|
60
61
|
/** Ops that change nothing: a lost answer may be asked for again. The rest (comment, upload, transition,
|
|
61
62
|
* create) are retried only when the server said it did not run them. */
|
|
62
|
-
const READ_OPS: ReadonlySet<Op> = new Set<Op>(["me", "resources", "projects", "issueTypes", "statuses", "issue", "comments", "transitions"]);
|
|
63
|
+
const READ_OPS: ReadonlySet<Op> = new Set<Op>(["me", "resources", "projects", "issueTypes", "statuses", "issue", "comments", "transitions", "search"]);
|
|
64
|
+
/** Ops sync works without: check() does not require them. */
|
|
65
|
+
const OPTIONAL_OPS: ReadonlySet<Op> = new Set<Op>(["search"]);
|
|
63
66
|
|
|
64
67
|
const COMMENTS_PAGE = 20; // the server's cap per page
|
|
65
68
|
const COMMENTS_MAX = 100;
|
|
@@ -239,7 +242,7 @@ export class JiraClient {
|
|
|
239
242
|
try {
|
|
240
243
|
await this.cloudId();
|
|
241
244
|
const tools = await this.mcp.listTools();
|
|
242
|
-
const missing = (Object.keys(TOOLS) as Op[]).filter((op) => !TOOLS[op].some((n) => tools.some((x) => x.name === n)));
|
|
245
|
+
const missing = (Object.keys(TOOLS) as Op[]).filter((op) => !OPTIONAL_OPS.has(op) && !TOOLS[op].some((n) => tools.some((x) => x.name === n)));
|
|
243
246
|
if (missing.length) return { ok: false, error: missing.map(missingTool).join("; ") };
|
|
244
247
|
} catch (e) {
|
|
245
248
|
return { ok: false, error: explain((e as Error).message) };
|
|
@@ -256,6 +259,21 @@ export class JiraClient {
|
|
|
256
259
|
return { ok: true, value: { accountId, displayName: str(v.displayName ?? v.name ?? v.email) || accountId } };
|
|
257
260
|
}
|
|
258
261
|
|
|
262
|
+
/** The people on a project's recently updated issues (reporter, assignee, creator) — candidates for who
|
|
263
|
+
* answers dev-flow, with the account ids the playbook needs. */
|
|
264
|
+
async people(project: string): Promise<JiraResult<JiraUser[]>> {
|
|
265
|
+
const r = await this.call("search", { jql: `project = "${project.replace(/"/g, "")}" ORDER BY updated DESC`, max: 30, fields: ["reporter", "assignee", "creator"], view: "full" });
|
|
266
|
+
if (!r.ok) return r;
|
|
267
|
+
const seen = new Map<string, JiraUser>();
|
|
268
|
+
for (const i of arr(r.value, "issues").map(rec))
|
|
269
|
+
for (const k of ["reporter", "assignee", "creator"]) {
|
|
270
|
+
const u = rec(rec(i.fields)[k]);
|
|
271
|
+
const id = str(u.accountId);
|
|
272
|
+
if (id && !seen.has(id)) seen.set(id, { accountId: id, displayName: str(u.displayName) || id });
|
|
273
|
+
}
|
|
274
|
+
return { ok: true, value: [...seen.values()] };
|
|
275
|
+
}
|
|
276
|
+
|
|
259
277
|
async projects(): Promise<JiraResult<{ key: string; name: string }[]>> {
|
|
260
278
|
const r = await this.call("projects", { max: 100 });
|
|
261
279
|
if (!r.ok) return r;
|
|
@@ -311,6 +329,18 @@ export class JiraClient {
|
|
|
311
329
|
};
|
|
312
330
|
}
|
|
313
331
|
|
|
332
|
+
/** The issue's `updated` time and status — one small read, the watch's probe. A comment, an edit or a move
|
|
333
|
+
* all bump `updated`. An empty `updated` (the server left it out) means "unknown": treat it as changed. */
|
|
334
|
+
async stamp(key: string): Promise<JiraResult<{ updated: string; status: string }>> {
|
|
335
|
+
const t = await this.tool("issue").catch(() => undefined);
|
|
336
|
+
const asString = (t?.inputSchema?.properties as Record<string, { type?: string }> | undefined)?.fields?.type === "string";
|
|
337
|
+
const r = await this.call("issue", { issue: key, fields: asString ? "updated,status" : ["updated", "status"] });
|
|
338
|
+
if (!r.ok) return r;
|
|
339
|
+
const v = rec(r.value);
|
|
340
|
+
const f = rec(v.fields ?? v);
|
|
341
|
+
return { ok: true, value: { updated: str(f.updated), status: str(rec(f.status).name ?? f.status) } };
|
|
342
|
+
}
|
|
343
|
+
|
|
314
344
|
/** The newest comments, newest first: pages of 20 (the server's cap) up to COMMENTS_MAX. */
|
|
315
345
|
async comments(key: string): Promise<JiraResult<JiraComment[]>> {
|
|
316
346
|
const toC = (c: Record<string, unknown>): JiraComment => {
|
package/src/jira/config.ts
CHANGED
|
@@ -13,6 +13,10 @@
|
|
|
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
|
+
* answerers = 557058:…, token whose comments answer dev-flow (account ids; token = the token's own account,
|
|
17
|
+
* the default) — set it when dev-flow posts as a bot account and you answer as yourself
|
|
18
|
+
* probe = 1m while a question waits, look this often whether the issue changed (one
|
|
19
|
+
* small call); a change runs the full check. off = the schedule only
|
|
16
20
|
*
|
|
17
21
|
* A status value may name several statuses (`To Do, Backlog`): any of them means that stage; the first is
|
|
18
22
|
* the one dev-flow moves the issue to. Pure module.
|
|
@@ -22,6 +26,12 @@ import type { JiraConfig, JiraStage } from "../core.ts";
|
|
|
22
26
|
export const JIRA_STAGES: readonly JiraStage[] = ["plan", "implement", "pre-release", "release", "done"];
|
|
23
27
|
export const DEFAULT_WATCH = [30 * 60, 60 * 60, 2 * 3600, 4 * 3600];
|
|
24
28
|
export const DEFAULT_WATCH_CAP = 72 * 3600;
|
|
29
|
+
export const DEFAULT_PROBE = 60;
|
|
30
|
+
/** The shortest probe interval accepted: a faster one would only spend the token's rate limit. */
|
|
31
|
+
export const MIN_PROBE = 15;
|
|
32
|
+
|
|
33
|
+
/** Seconds between probes for `cfg` (0 = off). */
|
|
34
|
+
export const probeSecs = (cfg: Pick<JiraConfig, "probe">) => cfg.probe ?? DEFAULT_PROBE;
|
|
25
35
|
|
|
26
36
|
/** `30m` / `1h` / `2d` / `90s` / `45` (seconds) → seconds; undefined for junk. */
|
|
27
37
|
export function parseDuration(raw: string): number | undefined {
|
|
@@ -93,6 +103,23 @@ export function parseJiraBlock(entries: { line: string; where: string }[]): { cf
|
|
|
93
103
|
else cfg.watchCap = s;
|
|
94
104
|
break;
|
|
95
105
|
}
|
|
106
|
+
case "answerers": {
|
|
107
|
+
const ids = list(value);
|
|
108
|
+
const bad = ids.filter((x) => x !== "token" && !/^[\w:-]{6,}$/.test(x));
|
|
109
|
+
if (!ids.length || bad.length) warn.push(`${where}: flow-jira answerers = "${value}" — expected Jira account ids or token — keeping the token's account`);
|
|
110
|
+
else cfg.answerers = ids;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "probe": {
|
|
114
|
+
const v = value.trim().toLowerCase();
|
|
115
|
+
const s = /^(off|no|none|0)$/.test(v) ? 0 : parseDuration(v);
|
|
116
|
+
if (s === undefined) warn.push(`${where}: flow-jira probe = "${value}" — expected a duration like 1m, or off — keeping 1m`);
|
|
117
|
+
else if (s && s < MIN_PROBE) {
|
|
118
|
+
warn.push(`${where}: flow-jira probe = "${value}" is below ${MIN_PROBE}s — using ${MIN_PROBE}s`);
|
|
119
|
+
cfg.probe = MIN_PROBE;
|
|
120
|
+
} else cfg.probe = s;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
96
123
|
default:
|
|
97
124
|
warn.push(`${where}: unknown flow-jira key "${key}" — ignored`);
|
|
98
125
|
}
|
|
@@ -115,6 +142,8 @@ export function renderJiraBlock(cfg: JiraConfig): string[] {
|
|
|
115
142
|
if (cfg.mirror !== "asks") L.push(`mirror = ${cfg.mirror}`);
|
|
116
143
|
if (cfg.watch.join() !== DEFAULT_WATCH.join()) L.push(`watch = ${cfg.watch.map(fmtDuration).join(", ")}`);
|
|
117
144
|
if (cfg.watchCap !== DEFAULT_WATCH_CAP) L.push(`watchCap = ${fmtDuration(cfg.watchCap)}`);
|
|
145
|
+
if (cfg.answerers?.length) L.push(`answerers = ${cfg.answerers.join(", ")}`);
|
|
146
|
+
if (cfg.probe !== undefined && cfg.probe !== DEFAULT_PROBE) L.push(`probe = ${cfg.probe ? fmtDuration(cfg.probe) : "off"}`);
|
|
118
147
|
return L;
|
|
119
148
|
}
|
|
120
149
|
|
package/src/jira/sync.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Jira sync decisions — pure, no I/O: what a mirrored comment says, which Jira activity is the operator's
|
|
3
3
|
* answer, and when the watch checks next.
|
|
4
4
|
*
|
|
5
|
-
* Who may answer:
|
|
6
|
-
*
|
|
7
|
-
* footer marker. Anyone else's comment, and any
|
|
5
|
+
* Who may answer: the accounts in the playbook's `answerers` (answererIds), by default the token owner's
|
|
6
|
+
* (`link.accountId`) — you, replying in Jira. dev-flow posts as the token's account, so its own comments are
|
|
7
|
+
* told apart by the ids it saved (`link.posted`) and by the footer marker. Anyone else's comment, and any
|
|
8
|
+
* status move that answers nothing, is relayed as information.
|
|
8
9
|
*/
|
|
9
10
|
import type { FlowState, JiraConfig, JiraLink, JiraStage } from "../core.ts";
|
|
10
11
|
import { stageOfStatus, statusForStage } from "./config.ts";
|
|
@@ -53,6 +54,13 @@ export interface Relay {
|
|
|
53
54
|
text: string;
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
/** The account ids whose comments are answers: the configured `answerers` (`token` = the token's own
|
|
58
|
+
* account), else the token's account. */
|
|
59
|
+
export function answererIds(cfg: Pick<JiraConfig, "answerers">, link: Pick<JiraLink, "accountId">): string[] {
|
|
60
|
+
const ids = cfg.answerers?.length ? cfg.answerers : ["token"];
|
|
61
|
+
return ids.map((a) => (a === "token" ? (link.accountId ?? "") : a)).filter(Boolean);
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
/** Read new Jira activity against the link: the relays to deliver, and the link fields to store. */
|
|
57
65
|
export function classifyActivity(o: {
|
|
58
66
|
link: JiraLink;
|
|
@@ -78,7 +86,7 @@ export function classifyActivity(o: {
|
|
|
78
86
|
if (link.posted.includes(c.id) || c.body.includes(MARKER)) continue;
|
|
79
87
|
const body = c.body.trim();
|
|
80
88
|
if (!body) continue;
|
|
81
|
-
if (
|
|
89
|
+
if (c.authorId && answererIds(cfg, link).includes(c.authorId)) relays.push({ kind: "answer", text: `[Jira ${link.key} · your comment] ${body}` });
|
|
82
90
|
else relays.push({ kind: "info", text: `[Jira ${link.key} · comment from ${c.authorName || "someone else"} — information only, not an answer] ${body}` });
|
|
83
91
|
}
|
|
84
92
|
if (o.status && link.lastStatus && o.status.toLowerCase() !== link.lastStatus.toLowerCase()) {
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
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,
|
|
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,
|
|
110
|
+
await this.tick(key, root, slug, "check");
|
|
93
111
|
}
|
|
94
112
|
|
|
95
|
-
private async tick(key: string, root: string, slug: string,
|
|
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
|
|
102
|
-
if (
|
|
103
|
-
|
|
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
|
}
|
package/src/runtime/jira.ts
CHANGED
|
@@ -84,6 +84,25 @@ export async function gateJiraInit(root: string, cfg: Config, rest: string[], fl
|
|
|
84
84
|
if (unknown.length) return { text: `${project} has no issue type ${unknown.join(", ")} — it has ${offered.map((t) => t.name).join(", ")}`, isError: true };
|
|
85
85
|
const canon = chosen.map((t) => types.value.find((x) => x.name.toLowerCase() === t.toLowerCase())!.name);
|
|
86
86
|
|
|
87
|
+
// who answers: dev-flow posts as the token's account, which may be a bot's — then the operator's own
|
|
88
|
+
// comments would read as a teammate's and never answer anything
|
|
89
|
+
const ansArg = flagValue(rest, "answerers");
|
|
90
|
+
const answerers = ansArg !== null ? ansArg.split(",").map((a) => a.trim()).filter(Boolean) : cfg.jira?.project === project ? cfg.jira.answerers : undefined;
|
|
91
|
+
if (answerers?.some((a) => a !== "token" && !/^[\w:-]{6,}$/.test(a))) return { text: `--answerers takes Jira account ids or token, comma-separated — got ${ansArg}`, isError: true };
|
|
92
|
+
if (!answerers?.length) {
|
|
93
|
+
const people = await client.people(project);
|
|
94
|
+
const others = people.ok ? people.value.filter((p) => p.accountId !== me.value.accountId) : [];
|
|
95
|
+
const lines = [` token — ${me.value.displayName}, the account this token belongs to (pick it when the token is your own)`, ...others.map((p) => ` ${p.accountId} — ${p.displayName}`)];
|
|
96
|
+
return {
|
|
97
|
+
text: needsOperator(
|
|
98
|
+
`${head}, project ${project}\nWhose Jira comments answer dev-flow's questions (and may approve its gates)? dev-flow posts as ${me.value.displayName}; when that is not the account you comment as, name yours.\n${lines.join("\n")}${others.length ? "" : `\n (no one else found on ${project}'s recent issues${people.ok ? "" : ` — ${people.error}`}; an account id is the last part of your Jira profile URL, …/jira/people/<id>)`}`,
|
|
99
|
+
"Who answers?",
|
|
100
|
+
`ask the operator, then re-run flow jira init --project=${project} --types=${canon.join(",")} --answerers=<id>[,<id>] (or --answerers=token)`,
|
|
101
|
+
),
|
|
102
|
+
isError: true,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
87
106
|
const st = await client.statuses(project);
|
|
88
107
|
if (!st.ok) return { text: `${head}\ncould not read the workflow statuses of ${project}: ${st.error}`, isError: true };
|
|
89
108
|
// mapping: what is configured for this project, else the suggestion; --map overrides one stage of one type
|
|
@@ -119,6 +138,8 @@ export async function gateJiraInit(root: string, cfg: Config, rest: string[], fl
|
|
|
119
138
|
mirror: (mirrorArg as "asks" | "all" | null) ?? cfg.jira?.mirror ?? "asks",
|
|
120
139
|
watch: cfg.jira?.watch ?? [...DEFAULT_WATCH],
|
|
121
140
|
watchCap: cfg.jira?.watchCap ?? DEFAULT_WATCH_CAP,
|
|
141
|
+
...(cfg.jira?.probe !== undefined ? { probe: cfg.jira.probe } : {}),
|
|
142
|
+
answerers,
|
|
122
143
|
};
|
|
123
144
|
const block = ["```flow-jira", ...renderJiraBlock(next), "```"].join("\n");
|
|
124
145
|
const table = canon.map((t) => ` ${t}: ${JIRA_STAGES.map((g) => `${g} ← ${status[t][g]?.join(" | ") || "—"}`).join("; ")}`).join("\n");
|
|
@@ -127,7 +148,7 @@ export async function gateJiraInit(root: string, cfg: Config, rest: string[], fl
|
|
|
127
148
|
text: needsOperator(
|
|
128
149
|
`${head}, project ${project}\n${notes.join("\n")}\nProposed mapping (a move into a stage's status answers that stage's question: implement answers Approve?, pre-release Verified?, release Release?, done Finish?; dev-flow moves the issue to the first status listed):\n${table}\n\nproject.md ## global gets:\n${block}`,
|
|
129
150
|
"Mapping OK?",
|
|
130
|
-
`show the operator the mapping; on their word re-run flow jira init --project=${project} --types=${canon.join(",")} [--map=<Type>.<stage>=<Status>…] --confirmed`,
|
|
151
|
+
`show the operator the mapping; on their word re-run flow jira init --project=${project} --types=${canon.join(",")} --answerers=${answerers.join(",")} [--map=<Type>.<stage>=<Status>…] --confirmed`,
|
|
131
152
|
),
|
|
132
153
|
isError: true,
|
|
133
154
|
};
|
|
@@ -470,8 +491,30 @@ export async function mirrorClosingMessage(root: string, cfg: Config, slug: stri
|
|
|
470
491
|
|
|
471
492
|
// ---------------------------------------------------------------- inbound: one reply check
|
|
472
493
|
|
|
473
|
-
/**
|
|
474
|
-
|
|
494
|
+
/** The watch's probe: one small read of the issue. `changed` when its `updated` time (or status) moved since the
|
|
495
|
+
* last full check the probe triggered, or when either is unknown; `stamp` is what to record once the full
|
|
496
|
+
* check has read past it (recordStamp). */
|
|
497
|
+
export async function probeIssue(root: string, cfg: Config, slug: string): Promise<{ changed: boolean; stamp: string } | { error: string }> {
|
|
498
|
+
const st = readState(root, slug);
|
|
499
|
+
if (!cfg.jira || !st?.jira) return { changed: false, stamp: "" };
|
|
500
|
+
const c = jiraClient(cfg.jira);
|
|
501
|
+
if ("error" in c) return { error: c.error };
|
|
502
|
+
const r = await c.client.stamp(st.jira.key);
|
|
503
|
+
if (!r.ok) return { error: r.error };
|
|
504
|
+
const { updated, status } = r.value;
|
|
505
|
+
const moved = !!status && !!st.jira.lastStatus && status.toLowerCase() !== st.jira.lastStatus.toLowerCase();
|
|
506
|
+
return { changed: !updated || !st.jira.updatedSeen || updated !== st.jira.updatedSeen || moved, stamp: updated };
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** The full check the probe ran has read everything up to `stamp`. */
|
|
510
|
+
export function recordStamp(root: string, slug: string, stamp: string): void {
|
|
511
|
+
const st = readState(root, slug);
|
|
512
|
+
if (st?.jira && stamp) writeState(root, { ...st, jira: { ...st.jira, updatedSeen: stamp } });
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** Read the linked issue's new comments and its status; advance the link; return what to relay. A check the
|
|
516
|
+
* probe triggered (`scheduled: false`) does not advance the watch schedule. */
|
|
517
|
+
export async function checkReplies(root: string, cfg: Config, slug: string, opts: { scheduled?: boolean } = {}): Promise<{ relays: Relay[]; error?: string }> {
|
|
475
518
|
const st = readState(root, slug);
|
|
476
519
|
if (!cfg.jira || !st?.jira) return { relays: [] };
|
|
477
520
|
const c = jiraClient(cfg.jira);
|
|
@@ -488,7 +531,7 @@ export async function checkReplies(root: string, cfg: Config, slug: string): Pro
|
|
|
488
531
|
const fresh = readState(root, slug) ?? st;
|
|
489
532
|
const next: JiraLink = { ...(fresh.jira ?? link), accountId: link.accountId, seenUntil: r.seenUntil ?? link.seenUntil, seenCommentId: r.seenCommentId ?? link.seenCommentId, lastStatus: r.lastStatus };
|
|
490
533
|
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 };
|
|
534
|
+
else if (next.watch && opts.scheduled !== false) next.watch = { ...next.watch, checks: next.watch.checks + 1 };
|
|
492
535
|
writeState(root, { ...fresh, jira: next });
|
|
493
536
|
return { relays: r.relays };
|
|
494
537
|
}
|