pi-dev-flow 0.99.0 → 0.99.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,13 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.99.1] - 2026-12-03
8
+
9
+ **Jira attachments work with the token the Atlassian MCP server needs.**
10
+
11
+ ### Fixed
12
+ - **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.
13
+
7
14
  ## [0.99.0] - 2026-12-03
8
15
 
9
16
  **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.
@@ -63,6 +63,6 @@ In a synced project, dev-flow also registers the Atlassian MCP server for the ag
63
63
  ## Limits
64
64
 
65
65
  - 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`).
66
+ - 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.
67
+ - 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
68
  - 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.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": [
@@ -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) {