pi-dev-flow 0.99.0 → 0.99.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 CHANGED
@@ -4,6 +4,20 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.99.2] - 2026-12-03
8
+
9
+ **The approved plan reaches the linked Jira issue in every case.**
10
+
11
+ ### Fixed
12
+ - **The approved plan now reaches the linked Jira issue in every case.** It used to go only with a mirrored Approve? question. That question is mirrored only when the agent closes its turn on it in a flow that is already linked. When an answer like "approve minor, yes to Jira" created the issue and approved in one go, the plan never got to the issue. Now every approval of a linked flow posts the plan, with `plan.md` and the mockups attached, unless the identical copy is already there. A flow linked after approval gets its plan posted when the link is made.
13
+
14
+ ## [0.99.1] - 2026-12-03
15
+
16
+ **Jira attachments work with the token the Atlassian MCP server needs.**
17
+
18
+ ### Fixed
19
+ - **Jira attachments now work with a token scoped to the Atlassian MCP app.** That token is the one the MCP server needs, and Jira's REST API refuses it, so the plan, mockups and screenshots were never attached. They now go through the MCP server's two-step upload. dev-flow reads the short-lived Atlassian Media request it returns (an https request to `api.media.atlassian.com`, never run as a command), sends the file itself, then attaches it. REST remains the fallback.
20
+
7
21
  ## [0.99.0] - 2026-12-03
8
22
 
9
23
  **Opt-in Jira sync: start a flow from an issue, or have one created; get questions on the issue with the plan attached; answer by commenting or by moving the issue.**
package/docs/jira.md CHANGED
@@ -6,7 +6,7 @@ It talks to Atlassian's official **Rovo MCP server** (`https://mcp.atlassian.com
6
6
 
7
7
  ## Setup
8
8
 
9
- 1. **Create an API token** at id.atlassian.com → Security → API tokens. Choose **Create API token**, the plain kind. A scoped token ("with scopes") works with the MCP server, but Jira's REST API refuses it unless it carries `read:jira-work`, `write:jira-work` and `read:jira-user`, and attachments go through REST. An org admin must have turned on API-token authentication for the Rovo MCP server (Atlassian Administration → Rovo MCP server). Without that, the server only accepts OAuth sign-in.
9
+ 1. **Create a scoped API token for the Atlassian MCP app** at id.atlassian.com → Security → API tokens → *Create API token with scopes*. Give it `read:jira:agent-interface` and `write:jira:agent-interface`; `search:jira:agent-interface` is optional. An org admin must have turned on API-token authentication for the Rovo MCP server (Atlassian Administration → Rovo MCP server). A plain token (*Create API token*) does not work: with one, the MCP server offers only its search tool.
10
10
  2. **Run `/flow jira login [site]`** and type the site, your email and the token into its dialogs. dev-flow checks them against the MCP server, then saves them to `~/.pi/agent/dev-flow/jira.json` (mode 0600). The token never passes through the chat or the agent, and is never written to `project.md`. You can use environment variables instead: `JIRA_SITE`, `JIRA_EMAIL` and `JIRA_API_TOKEN` override the file.
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.
@@ -40,6 +40,7 @@ status.Story.done = Done
40
40
  - **No issue yet?** When you start a flow without naming an issue, the agent offers three choices: create a new issue in the synced project, link an existing one, or go without. The agent shows you the summary, type and description before anything is created (`flow jira create`), and links the new issue to the flow. Starting with `--no-jira` skips the offer.
41
41
  - **Issues for roadmap items.** Ask the agent to create issues for roadmap items (`flow jira create --roadmap=2,5`). You see the list first. Each item's text becomes the summary and its brief the description, and the item is stamped with its key (`- [ ] Dark mode [DEV-14]`). When that item is picked and started, the flow links to its issue automatically.
42
42
  - **Questions go to the issue.** When the agent stops to ask you something, its message is also posted as a comment. At **Approve?** it attaches `plan.md` and the mockups. Any screenshot the message names by path is attached as well. The same message is never posted twice, and the same file never uploaded twice.
43
+ - **The approved plan always reaches the issue.** When the plan is approved, dev-flow posts it to the issue with `plan.md` and the mockups attached. 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 just says so. A flow linked to an issue after approval gets its plan posted at link time.
43
44
  - **Answering in Jira:**
44
45
  - **Comment**, for example "Approved", "Verified", or a change request. Only comments from your own account (the token's owner) count as your answer. Other people's comments are shown in the session as information and never approve anything.
45
46
  - **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.
@@ -63,6 +64,6 @@ In a synced project, dev-flow also registers the Atlassian MCP server for the ag
63
64
  ## Limits
64
65
 
65
66
  - Jira Cloud only. The Rovo MCP server does not serve Jira Data Center.
66
- - The MCP server's upload tool takes a local file path and hands back a command to run, so attachments always go through Jira's REST API.
67
- - Two calls fall back to Jira's REST API with the same token when the MCP server can't do the job: listing workflow statuses per issue type (`/rest/api/3/project/{key}/statuses`), and attaching a file (`/rest/api/3/issue/{key}/attachments`).
67
+ - Attachments use the MCP server's two-step upload. Step one returns a short-lived Atlassian Media upload as a `curl` command. dev-flow never runs it. It reads the URL and token from the command, accepting only an https request to `api.media.atlassian.com`, sends the file itself, then attaches the file with step two.
68
+ - If an MCP call can't do the job, dev-flow retries it through Jira's REST API with the same token. A token scoped to the MCP app is refused there, so those retries only help with a token that also has Jira REST scopes.
68
69
  - dev-flow polls Jira; it does not use webhooks, which would need a public URL for Jira to call.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dev-flow",
3
- "version": "0.99.0",
3
+ "version": "0.99.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": [
@@ -76,9 +76,10 @@ const ARGS: Record<string, string[]> = {
76
76
  mode: ["mode"],
77
77
  view: ["view"],
78
78
  order: ["orderBy"],
79
- // the v2 tool takes a local filePath and hands back a command to run (a two-phase upload) — not content, so
80
- // attachments go through REST
79
+ // v1-style uploads take content; v2 takes a local filePath and hands back an Atlassian Media request (uploadTwoPhase)
81
80
  file: ["fileContent", "base64Content"],
81
+ filePath: ["filePath"],
82
+ fileId: ["fileId"],
82
83
  filename: ["filename", "fileName", "name"],
83
84
  mime: ["mimeType", "contentType"],
84
85
  };
@@ -99,6 +100,28 @@ function arr(v: unknown, ...keys: string[]): unknown[] {
99
100
  return [];
100
101
  }
101
102
 
103
+ /** The request in a phase-1 `uploadCommand` (a curl line) — read, never run: only an https POST to Atlassian
104
+ * Media with the headers it names. Null for anything else. */
105
+ export function parseUploadCommand(cmd: string): { url: string; headers: Record<string, string> } | null {
106
+ const q = (re: RegExp) => [...cmd.matchAll(re)].map((m) => m[1] ?? m[2]);
107
+ const url = q(/--location\s+(?:'([^']+)'|"([^"]+)")/g)[0] ?? q(/curl\s+(?:-\S+\s+)*(?:'(https:[^']+)'|"(https:[^"]+)")/g)[0];
108
+ if (!url) return null;
109
+ let u: URL;
110
+ try {
111
+ u = new URL(url);
112
+ } catch {
113
+ return null;
114
+ }
115
+ if (u.protocol !== "https:" || !/(^|\.)media\.atlassian\.com$/.test(u.hostname)) return null;
116
+ const headers: Record<string, string> = {};
117
+ for (const h of q(/(?:--header|-H)\s+(?:'([^']+)'|"([^"]+)")/g)) {
118
+ const i = h.indexOf(":");
119
+ if (i > 0) headers[h.slice(0, i).trim().toLowerCase()] = h.slice(i + 1).trim();
120
+ }
121
+ if (!headers.authorization) return null;
122
+ return { url: u.toString(), headers };
123
+ }
124
+
102
125
  /** Plain text of an Atlassian Document Format node (or a string body as-is). */
103
126
  export function adfText(node: unknown): string {
104
127
  if (typeof node === "string") return node;
@@ -345,12 +368,40 @@ export class JiraClient {
345
368
  return m;
346
369
  }
347
370
 
348
- /** Attach a local file. MCP `uploadAttachmentToJiraIssue` when it takes file content, else REST multipart. */
371
+ /** v2's two-phase upload: phase 1 (filePath) mints a short-lived Atlassian Media upload — a curl command we
372
+ * read but never run; we send the bytes ourselves; phase 2 (fileId) attaches the file to the issue. */
373
+ private async uploadTwoPhase(key: string, file: string, data: Buffer): Promise<JiraResult<string>> {
374
+ const p1 = await this.call("upload", { issue: key, filePath: path.resolve(file) });
375
+ if (!p1.ok) return p1;
376
+ const v = rec(p1.value);
377
+ const req = parseUploadCommand(str(v.uploadCommand));
378
+ if (!req) return { ok: false, error: "the upload step returned no Atlassian Media request dev-flow can send" };
379
+ try {
380
+ const res = await this.fetchFn(req.url, { method: "POST", headers: { ...req.headers, "content-type": mimeOf(file) }, body: data as unknown as string });
381
+ const text = await res.text();
382
+ if (!res.ok) return { ok: false, error: `Atlassian Media upload: HTTP ${res.status} ${text.slice(0, 200)}` };
383
+ const j = rec(JSON.parse(text)); // rec() already unwraps { data: … }
384
+ const fileId = str(j.id ?? rec(j.data).id);
385
+ if (!fileId) return { ok: false, error: `Atlassian Media upload: no file id in ${text.slice(0, 200)}` };
386
+ const p2 = await this.call("upload", { issue: key, fileId });
387
+ return p2.ok ? { ok: true, value: path.basename(file), via: "mcp" } : p2;
388
+ } catch (e) {
389
+ return { ok: false, error: `Atlassian Media upload: ${(e as Error).message}` };
390
+ }
391
+ }
392
+
393
+ /** Attach a local file: MCP (content, or the two-phase media upload), else REST multipart. */
349
394
  async upload(key: string, file: string): Promise<JiraResult<string>> {
350
395
  const data = readFileSync(file);
351
396
  const name = path.basename(file);
352
397
  const t = await this.tool("upload").catch(() => undefined);
353
398
  const props = Object.keys(t?.inputSchema?.properties ?? {});
399
+ let mcpError: string | undefined;
400
+ if (t && props.includes("filePath") && props.includes("fileId")) {
401
+ const r = await this.uploadTwoPhase(key, file, data);
402
+ if (r.ok) return r;
403
+ mcpError = r.error;
404
+ }
354
405
  if (t && props.some((p) => ARGS.file.includes(p))) {
355
406
  const m = await this.call("upload", { issue: key, file: data.toString("base64"), filename: name, mime: mimeOf(file) });
356
407
  if (m.ok) return { ok: true, value: name, via: "mcp" };
@@ -375,8 +426,8 @@ export class JiraClient {
375
426
  }
376
427
  }
377
428
  if (!res.ok) {
378
- const why = res.status === 401 || res.status === 403 || res.status === 404 ? "Jira's REST API did not accept the token (a scoped token needs write:jira-work; a plain API token works) — the MCP server cannot take file content, so attachments go through REST" : (await res.text()).slice(0, 200);
379
- return { ok: false, error: `attach ${name}: HTTP ${res.status} — ${why}` };
429
+ const why = res.status === 401 || res.status === 403 || res.status === 404 ? "Jira's REST API did not accept the token either" : (await res.text()).slice(0, 200);
430
+ return { ok: false, error: `attach ${name}: ${mcpError ? `${mcpError}; REST fallback: ` : ""}HTTP ${res.status} — ${why}` };
380
431
  }
381
432
  return { ok: true, value: name, via: "rest" };
382
433
  } catch (e) {
@@ -205,6 +205,11 @@ export async function linkFlow(root: string, cfg: Config, slug: string, key: str
205
205
  writeState(root, { ...state, jira: link });
206
206
  const moved = await moveToStage(root, cfg, slug, state.stage);
207
207
  if (moved) lines.push(moved);
208
+ // linked after the plan was approved: the issue gets the plan it would have seen at Approve?
209
+ if (state.stage !== "plan") {
210
+ const posted = await postApprovedPlan(root, cfg, slug);
211
+ if (posted) lines.push(posted);
212
+ }
208
213
  return { lines };
209
214
  }
210
215
 
@@ -250,6 +255,10 @@ export async function syncStageMoves(root: string, cfg: Config, before: Map<stri
250
255
  if (!stage) continue;
251
256
  const line = await moveToStage(root, cfg, slug, stage, st?.jira ?? b.link);
252
257
  if (line) out.push(line);
258
+ if (st && b.stage === "plan" && stage === "implement") {
259
+ const posted = await postApprovedPlan(root, cfg, slug);
260
+ if (posted) out.push(posted);
261
+ }
253
262
  if (!st) {
254
263
  const c = jiraClient(cfg.jira);
255
264
  if (!("error" in c)) await c.client.comment(b.link.key, formatComment({ slug, text: `dev-flow feature \`${slug}\` finished.` }));
@@ -258,6 +267,48 @@ export async function syncStageMoves(root: string, cfg: Config, before: Map<stri
258
267
  return out;
259
268
  }
260
269
 
270
+ /** The approved plan on the issue, however the approval came: the Approve? question is mirrored only when the
271
+ * agent closes its turn on it in a linked flow, and an approval given in chat — or a link made at approval
272
+ * time — never reaches that point. Attaches plan.md and the mockups not already attached; the comment carries
273
+ * the plan itself unless an unchanged copy is already on the issue. Returns a gate-output line. */
274
+ export async function postApprovedPlan(root: string, cfg: Config, slug: string): Promise<string | null> {
275
+ const st = readState(root, slug);
276
+ if (!cfg.jira || !st?.jira) return null;
277
+ const planMd = path.join(featDir(root, slug), "plan", "plan.md");
278
+ if (!existsSync(planMd)) return null; // patch/docs: no plan document
279
+ const c = jiraClient(cfg.jira);
280
+ if ("error" in c) return `${AGENT_MARK}jira: the approved plan was not posted to ${st.jira.key} — ${c.error}`;
281
+ const link = st.jira;
282
+ const plan = readFileSync(planMd, "utf8");
283
+ const hashes = new Set(link.attached ?? []);
284
+ const already = hashes.has(sha1(plan)); // the Approve? mirror attached this very plan
285
+ const mock = path.join(featDir(root, slug), "plan", "mockups");
286
+ const files = [planMd, ...(existsSync(mock) ? readdirSync(mock).filter((f) => /\.(png|jpe?g|gif|webp)$/i.test(f)).map((f) => path.join(mock, f)) : [])];
287
+ const attached: string[] = [];
288
+ const failed: string[] = [];
289
+ for (const f of files) {
290
+ const h = sha1(readFileSync(f));
291
+ if (hashes.has(h)) continue;
292
+ const r = await c.client.upload(link.key, f);
293
+ if (r.ok) {
294
+ attached.push(path.basename(f));
295
+ hashes.add(h);
296
+ } else failed.push(`${path.basename(f)} (${r.error})`);
297
+ }
298
+ const call = st.versionChoice ? ` Release call: ${st.versionChoice}.` : "";
299
+ const mode = st.patch ? " (patch)" : st.docs ? " (docs)" : "";
300
+ const body = already
301
+ ? `Plan approved${mode} — the copy posted with the question is the one approved.${call}`
302
+ : `**Plan approved${mode}** — implementation starts.${call}\n\n${plan.length > 24_000 ? `_(the plan is long — see the attached plan.md)_` : plan.trim()}`;
303
+ const r = await c.client.comment(link.key, formatComment({ slug, text: body, attachments: attached }));
304
+ const fresh = readState(root, slug) ?? st;
305
+ const next: JiraLink = { ...(fresh.jira ?? link), attached: [...hashes] };
306
+ if (r.ok && r.value) next.posted = [...next.posted, r.value];
307
+ writeState(root, { ...fresh, jira: next });
308
+ if (!r.ok) return `${AGENT_MARK}jira: the approved plan was not posted to ${link.key}: ${r.error}`;
309
+ return `Jira ${link.key}: approved plan posted${attached.length ? ` with ${attached.join(", ")}` : ""}${failed.length ? ` (not attached: ${failed.join("; ")})` : ""}`;
310
+ }
311
+
261
312
  // ---------------------------------------------------------------- outbound: the closing-message mirror
262
313
 
263
314
  const IMG = /(?:^|[\s(`'"[])((?:\.{0,2}\/|\/)?[\w@.\-/]+\.(?:png|jpe?g|gif|webp))(?=$|[\s)`'",\]:;])/gi;