@thiagodiogo/pscode 2.4.0 → 2.5.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.
@@ -118,10 +118,35 @@ function getApplyInstructions() {
118
118
  > - Descrição do PR: use o template definido em \`pr.description.template\`
119
119
  > - Ao abrir o PR: \`<"comente o link do PR nesta task" se pr.comments.linkInTask: true, senão omita>\`
120
120
 
121
- The agent MUST create the branch with the configured pattern before making any code changes.
122
121
  Template variables available: \`{change-name}\` = current change name, \`{type}\` = feat/fix/chore, \`{ticket}\` = ticket ID if available.
123
122
 
124
- **If \`pscode/config.yaml\` does not exist, or \`pr.enabled: false\`, or file not found:** continue normally without any PR instructions.
123
+ **Detect whether a PR already exists for this change** (it may have been opened in \`/ps:propose\`). Resolve the branch name from \`pr.branch.pattern\`, then check the current branch and its PR:
124
+ \`\`\`bash
125
+ git checkout <branch> # if it already exists; otherwise it will be created below
126
+ gh pr view --json state,url
127
+ \`\`\`
128
+
129
+ - **If a PR already exists** (the \`gh pr view\` returns an open PR): do NOT open another — just continue working on the existing PR. Save its URL as \`prUrl\`.
130
+
131
+ - **If NO PR exists:** open one in **DRAFT automatically, without asking the user**:
132
+ 1. Create the branch with the configured \`pr.branch.pattern\` if it does not exist yet (\`git checkout -b <branch>\`) — the agent MUST be on this branch before making any code changes.
133
+ 2. Commit any pending planning artifacts: \`git add -A && git commit -m "chore(<change-name>): planning artifacts"\` (skip if nothing to commit).
134
+ 3. Push and set upstream: \`git push -u origin <branch>\`.
135
+ 4. Open the PR in DRAFT, deriving the title from \`pr.title.template\` and the body from \`pr.description.template\`:
136
+ \`gh pr create --draft --title "<resolved title>" --body "<resolved description>"\`.
137
+ 5. Capture the PR URL as \`prUrl\`.
138
+
139
+ **Comentário do link no tracker:** after opening a PR (or detecting an existing one just opened), if \`pr.comments.linkInTask: true\` and a Trello \`cardId\` was saved in Step 2, comment the PR link on the card:
140
+ \`\`\`tool
141
+ mcp__claude_ai_Trello_Custom__add_comment
142
+ card_id: "<cardId>"
143
+ text: |
144
+ 🔀 Pull Request (DRAFT): <prUrl>
145
+ \`\`\`
146
+
147
+ **Tratamento de falha (não-bloqueante):** if \`gh\` or \`git\` fails — \`gh\` not installed, not authenticated, or no GitHub remote — **do NOT block**: state what failed and how to fix it (e.g., \`gh auth login\`), ask whether the user wants the agent to resolve it in parallel, and **continue the implementation regardless**. The branch and local commits are preserved.
148
+
149
+ **If \`pscode/config.yaml\` does not exist, or \`pr.enabled: false\`, or file not found:** continue normally without any PR instructions — no branch, no PR.
125
150
 
126
151
  6. **Show current progress**
127
152
 
@@ -64,12 +64,52 @@ When ready to implement, run /ps:apply
64
64
 
65
65
  Os artefatos gerados a partir do Passo 2 SHALL refletir esse entendimento refinado.
66
66
 
67
+ 1c. **PR Integration — abrir PR draft no início (opcional)**
68
+
69
+ Use the **Read tool** (NOT a shell command) to read \`pscode/config.yaml\` from the current working directory.
70
+ If the Read tool returns an error (file not found), or \`pr.enabled\` is not \`true\`, **skip this step entirely** — no PR, no branch, no checkpoint commits — and continue to Step 2. Opening the PR is then left to \`/ps:apply\`. Set \`PR_OPENED = false\`.
71
+
72
+ **If \`pscode/config.yaml\` exists and \`pr.enabled: true\`:**
73
+
74
+ Ask **once**, using the **AskUserQuestion tool**, whether to open the draft PR now:
75
+ > "Quer abrir o Pull Request em DRAFT agora? O PR nasce em draft e cresce junto com o refinamento."
76
+ > - ✅ Sim, abrir o PR draft agora (Recomendada)
77
+ > - ❌ Não, deixar para o apply
78
+
79
+ **If the user declines (Não):** continue the normal flow from Step 2 without any PR steps. Do NOT create a branch or commit automatically. The PR will be opened later by \`/ps:apply\`. Set \`PR_OPENED = false\`.
80
+
81
+ **If the user accepts (Sim):** proceed **without asking for any further authorization**:
82
+ 1. Resolve the branch name from \`pr.branch.pattern\`, substituting \`{change-name}\` with the change name, \`{type}\` with feat/fix/chore (infer from the change; default \`feat\`), and \`{ticket}\` with the ticket ID if available.
83
+ 2. Create and switch to the branch: \`git checkout -b <branch>\`.
84
+ 3. Create the change scaffold (this is Step 2): \`pscode new change "<name>"\`.
85
+ 4. Stage and commit the scaffold: \`git add -A && git commit -m "chore(<name>): scaffold change"\`.
86
+ 5. Push and set upstream: \`git push -u origin <branch>\`.
87
+ 6. Open the PR in **DRAFT**, deriving the title from \`pr.title.template\` and the body from \`pr.description.template\` (substitute \`{change-name}\`/\`{type}\`/\`{ticket}\`):
88
+ \`gh pr create --draft --title "<resolved title>" --body "<resolved description>"\`.
89
+ 7. Capture the PR URL from the \`gh\` output, save it as \`prUrl\`, and set \`PR_OPENED = true\`.
90
+
91
+ **Comentário do link no tracker:** after the PR is opened, if \`pr.comments.linkInTask: true\` and a Trello \`cardId\` exists, comment the PR link on the card:
92
+ \`\`\`tool
93
+ mcp__claude_ai_Trello_Custom__add_comment
94
+ card_id: "<cardId>"
95
+ text: |
96
+ 🔀 Pull Request (DRAFT) aberto: <prUrl>
97
+ \`\`\`
98
+ The \`cardId\` is resolved in Step 3 — if it is not available yet when the PR is opened, post this comment right after Step 3 instead.
99
+
100
+ **Tratamento de falha (não-bloqueante):** if \`gh\` or \`git\` fails — \`gh\` not installed, not authenticated, or no GitHub remote — **do NOT block**:
101
+ - Clearly state what failed and how to fix it (e.g., "instale o \`gh\` CLI", "rode \`gh auth login\`", "configure um remote GitHub").
102
+ - Ask whether the user wants the agent to resolve it in parallel (e.g., run \`gh auth login\`).
103
+ - **Continue the propose flow regardless.** Any branch already created and local commits are preserved; set \`PR_OPENED = true\` only if the PR was actually opened.
104
+
67
105
  2. **Create the change directory**
68
106
  \`\`\`bash
69
107
  pscode new change "<name>"
70
108
  \`\`\`
71
109
  This creates a scaffolded change in the planning home resolved by the CLI with \`.pscode.yaml\`.
72
110
 
111
+ **If you already created the change scaffold in Step 1c** (PR accepted), skip this step — the change directory already exists.
112
+
73
113
  3. **Trello Integration (optional)**
74
114
 
75
115
  Use the **Read tool** (NOT a shell command) to read \`pscode/trello.yaml\` from the current working directory.
@@ -190,6 +230,14 @@ When ready to implement, run /ps:apply
190
230
  pscode status --change "<name>"
191
231
  \`\`\`
192
232
 
233
+ 7. **Checkpoint commit — após gerar os artefatos (only if \`PR_OPENED = true\`)**
234
+
235
+ If a draft PR was opened in Step 1c, commit and push the generated artifacts as a checkpoint so the PR reflects the refined plan:
236
+ \`\`\`bash
237
+ git add -A && git commit -m "docs(<name>): add planning artifacts" && git push
238
+ \`\`\`
239
+ If \`PR_OPENED = false\`, skip — no automatic commits. Failures here are non-blocking (same handling as Step 1c).
240
+
193
241
  ---
194
242
 
195
243
  ## Refinement Validation Loop
@@ -334,7 +382,14 @@ ${applyNextStep}
334
382
  - Changes to technical approach → update \`design.md\`
335
383
  - Changes to tasks → update \`tasks.md\`
336
384
 
337
- 3. **Go back to Step R1** and show the updated refinement summary, then **re-run Step R1b**
385
+ 3. **Checkpoint commit após o ajuste (only if \`PR_OPENED = true\`)**:
386
+ If a draft PR was opened in Step 1c, commit and push the adjusted artifacts as a checkpoint:
387
+ \`\`\`bash
388
+ git add -A && git commit -m "docs(<name>): refine plan" && git push
389
+ \`\`\`
390
+ If \`PR_OPENED = false\`, skip. Failures here are non-blocking (same handling as Step 1c).
391
+
392
+ 4. **Go back to Step R1** and show the updated refinement summary, then **re-run Step R1b**
338
393
  so the Trello card description and comment reflect the adjusted plan before asking again.
339
394
  Keep looping until the user approves or cancels.
340
395
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thiagodiogo/pscode",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "AI-native system for spec-driven development",
5
5
  "keywords": [
6
6
  "pscode",