@kw-yeh/vibeflow 4.11.58 → 4.11.61

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.
@@ -45,6 +45,7 @@ const PR_QUERY = `query($owner:String!,$repo:String!,$number:Int!){
45
45
  repository(owner:$owner,name:$repo){
46
46
  pullRequest(number:$number){
47
47
  number title state merged headRefName headRefOid baseRefName
48
+ mergeable mergeStateStatus
48
49
  isCrossRepository
49
50
  reviews(last:50){nodes{databaseId author{login} state body createdAt}}
50
51
  comments(last:100){nodes{databaseId author{login} body createdAt}}
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: pr-watch
3
- description: Watch a GitHub pull request until it is merged or closed, waking only when it needs work — new review comments are handled with address-review, a base branch that moved ahead is rebased onto. Use when the user asks to watch, monitor, follow or babysit a PR, or says "監聽 PR", "盯著 PR", "看著這個 PR", "PR 有 comment 就處理", "watch the PR", "keep an eye on the PR".
3
+ description: Watch a GitHub pull request until it is merged or closed, waking only when it needs work — new review comments are handled with address-review, a PR that conflicts with its base or must catch up with it is rebased. Use when the user asks to watch, monitor, follow or babysit a PR, or says "監聽 PR", "盯著 PR", "看著這個 PR", "PR 有 comment 就處理", "watch the PR", "keep an eye on the PR".
4
4
  ---
5
5
 
6
6
  # Watch a PR
@@ -32,21 +32,27 @@ node "<skill>/scripts/pr-watch.mjs" --pr <n>
32
32
  Options: `--interval <sec>` (default 60, min 20); `--since-now` to skip items that are
33
33
  already there when watching starts (by default they are reported on the first poll, so a
34
34
  backlog gets handled first); `--state <file>` (default: under `$VIBEFLOW_SCRATCH_DIR`, or
35
- the system temp dir).
35
+ the system temp dir); `--rebase-on-any-base-change` to also wake for every new commit on
36
+ the base branch the PR lacks (default off: a base that merely moved ahead is ignored).
37
+
38
+ By default the watcher wakes for the base branch only when GitHub reports the PR conflicts
39
+ with it (`mergeable: CONFLICTING`) or branch protection requires catching up
40
+ (`mergeStateStatus: BEHIND`). While GitHub is still computing (`UNKNOWN`) it waits for the
41
+ next poll. Each base commit is reported once.
36
42
 
37
43
  ## 2. On exit
38
44
 
39
45
  | Exit | Event | Do |
40
46
  | --- | --- | --- |
41
47
  | 10 | `comments` | Run the **address-review** skill for this PR. |
42
- | 11 | `base` | Rebase (step 3). |
48
+ | 11 | `base` | Read `reason`: `behind` → rebase (step 3). `conflict` → step 3 to find the conflicting files, then report them and stop watching. |
43
49
  | 0 | `merged` / `closed` | Report and stop. Do not restart. |
44
50
  | 3 | `timeout` | Restart the watcher as it was. |
45
51
  | 2 | `error` | Report the message and stop. |
46
52
 
47
- After handling `comments` or `base`, restart the watcher with the same options unless
48
- the handling stopped (see below). The watcher remembers what it already reported, so a
49
- restart never re-reports the same comments or the same base commit.
53
+ After handling `comments` or a `behind` event, restart the watcher with the same options
54
+ unless the handling stopped (see below). The watcher remembers what it already reported, so
55
+ a restart never re-reports the same comments or the same base commit.
50
56
 
51
57
  Whether to stop for the user follows `VIBEFLOW_AUTO_MODE`:
52
58
 
@@ -58,14 +64,19 @@ Whether to stop for the user follows `VIBEFLOW_AUTO_MODE`:
58
64
 
59
65
  ## 3. Rebase
60
66
 
67
+ The event's `reason` decides what happens on a conflict: `behind` means the rebase is
68
+ expected to be clean; `conflict` means GitHub says it is not, so the rebase below is run
69
+ to name the conflicting files (if it does finish clean, carry on as for `behind`).
70
+
61
71
  ```bash
62
72
  git status --porcelain # must be empty; otherwise stop and tell the user
63
73
  git fetch origin <base>
64
74
  git rebase origin/<base>
65
75
  ```
66
76
 
67
- - Conflict → `git rebase --abort`, report the conflicting files, and **stop watching**,
68
- whatever the auto mode. Never resolve conflicts unattended.
77
+ - Conflict (the rebase stops) → `git rebase --abort`, report the
78
+ conflicting files, and **stop watching**, whatever the auto mode. Never resolve conflicts
79
+ unattended.
69
80
  - Clean → run the project's affected checks (typecheck, tests). A failure stops watching
70
81
  and is reported; nothing is pushed.
71
82
  - Passed → `git push --force-with-lease`, then restart the watcher.
@@ -45,6 +45,7 @@ const PR_QUERY = `query($owner:String!,$repo:String!,$number:Int!){
45
45
  repository(owner:$owner,name:$repo){
46
46
  pullRequest(number:$number){
47
47
  number title state merged headRefName headRefOid baseRefName
48
+ mergeable mergeStateStatus
48
49
  isCrossRepository
49
50
  reviews(last:50){nodes{databaseId author{login} state body createdAt}}
50
51
  comments(last:100){nodes{databaseId author{login} body createdAt}}
@@ -2,9 +2,16 @@
2
2
  // Wait, silently, until a PR needs the agent: prints ONE JSON line and exits.
3
3
  //
4
4
  // node pr-watch.mjs [--pr N] [--interval 60] [--state FILE] [--since-now] [--max-wait SEC] [--once]
5
+ // [--rebase-on-any-base-change]
5
6
  //
6
7
  // exit 10 {"event":"comments",...} review items nobody answered and not reported before
7
- // exit 11 {"event":"base",...} the base branch has commits the PR head lacks
8
+ // exit 11 {"event":"base","reason":"conflict"|"behind",...}
9
+ // the head lacks base commits AND GitHub says the PR conflicts
10
+ // (mergeable CONFLICTING) or must catch up (mergeStateStatus BEHIND).
11
+ // A base that merely moved ahead is silent, and so is UNKNOWN
12
+ // (GitHub still computing); --rebase-on-any-base-change reports
13
+ // every new base commit the head lacks, as "behind" unless conflicting.
14
+ // One report per base commit.
8
15
  // exit 0 {"event":"merged"|"closed",...}
9
16
  // exit 3 {"event":"timeout"} --max-wait passed (or --once found nothing); run it again
10
17
  // exit 2 {"event":"error",...} setup failed, or GitHub kept failing
@@ -20,7 +27,7 @@ const MAX_BACKOFF = 300
20
27
  const MAX_FAILURES = 10
21
28
 
22
29
  export function parseArgs(argv) {
23
- const opts = { interval: 60, sinceNow: false, once: false }
30
+ const opts = { interval: 60, sinceNow: false, once: false, rebaseOnAnyBaseChange: false }
24
31
  for (let i = 0; i < argv.length; i += 1) {
25
32
  const arg = argv[i]
26
33
  const value = () => {
@@ -34,6 +41,7 @@ export function parseArgs(argv) {
34
41
  else if (arg === '--max-wait') opts.maxWait = Number(value())
35
42
  else if (arg === '--since-now') opts.sinceNow = true
36
43
  else if (arg === '--once') opts.once = true
44
+ else if (arg === '--rebase-on-any-base-change') opts.rebaseOnAnyBaseChange = true
37
45
  else throw new Error(`unknown option ${arg}`)
38
46
  }
39
47
  return opts
@@ -60,14 +68,29 @@ export function writeState(file, state) {
60
68
  fs.renameSync(tmp, file)
61
69
  }
62
70
 
71
+ /**
72
+ * Why the base branch needs the agent now: 'conflict' when GitHub reports the
73
+ * PR cannot merge, 'behind' when branch protection requires catching up, null
74
+ * otherwise. Both require the head to actually lack base commits, since
75
+ * GitHub's status lags a push. UNKNOWN (still computing) is not an answer, so
76
+ * it waits for the next poll. With rebaseOnAnyBaseChange every lacked base
77
+ * commit counts.
78
+ */
79
+ export function baseReason(pr, base, opts = {}) {
80
+ if (!base || !(base.behindBy > 0)) return null
81
+ if (pr.mergeable === 'CONFLICTING') return 'conflict'
82
+ if (pr.mergeStateStatus === 'BEHIND' || opts.rebaseOnAnyBaseChange) return 'behind'
83
+ return null
84
+ }
85
+
63
86
  /**
64
87
  * What one poll means, given what was already reported. A finished PR wins,
65
88
  * then comments (answering them before a rebase keeps their line anchors
66
- * meaningful), then a base branch the head has fallen behind. A base already
89
+ * meaningful), then a base the PR must act on (see baseReason). A base already
67
90
  * reported at this commit is not reported again, so a rebase the agent could
68
91
  * not finish does not wake it in a loop.
69
92
  */
70
- export function decide(pr, base, state) {
93
+ export function decide(pr, base, state, opts = {}) {
71
94
  if (pr.merged) return { event: { event: 'merged', pr: pr.number }, state }
72
95
  if (pr.state === 'CLOSED') return { event: { event: 'closed', pr: pr.number }, state }
73
96
 
@@ -80,9 +103,10 @@ export function decide(pr, base, state) {
80
103
  state: { ...state, seen: [...state.seen, ...keys] },
81
104
  }
82
105
  }
83
- if (base && base.behindBy > 0 && base.oid !== state.baseOid) {
106
+ const reason = baseReason(pr, base, opts)
107
+ if (reason && base.oid !== state.baseOid) {
84
108
  return {
85
- event: { event: 'base', pr: pr.number, base: pr.baseRefName, sha: base.oid, behindBy: base.behindBy },
109
+ event: { event: 'base', reason, pr: pr.number, base: pr.baseRefName, sha: base.oid, behindBy: base.behindBy },
86
110
  state: { ...state, baseOid: base.oid },
87
111
  }
88
112
  }
@@ -90,8 +114,8 @@ export function decide(pr, base, state) {
90
114
  }
91
115
 
92
116
  /** Mark everything already there as reported, for --since-now. */
93
- export function baseline(pr, base) {
94
- return { seen: pendingItems(pr).map(itemKey), baseOid: base?.behindBy > 0 ? base.oid : null }
117
+ export function baseline(pr, base, opts = {}) {
118
+ return { seen: pendingItems(pr).map(itemKey), baseOid: baseReason(pr, base, opts) ? base.oid : null }
95
119
  }
96
120
 
97
121
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
@@ -133,10 +157,10 @@ export async function watch(opts, deps = {}) {
133
157
  }
134
158
  if (polled) {
135
159
  if (!state) {
136
- state = opts.sinceNow ? baseline(polled.pr, polled.base) : { seen: [], baseOid: null }
160
+ state = opts.sinceNow ? baseline(polled.pr, polled.base, opts) : { seen: [], baseOid: null }
137
161
  writeState(file, state)
138
162
  }
139
- const result = decide(polled.pr, polled.base, state)
163
+ const result = decide(polled.pr, polled.base, state, opts)
140
164
  if (result.event) {
141
165
  writeState(file, result.state)
142
166
  return { code: EXIT[result.event.event] ?? EXIT.done, event: result.event }