@cxi-lmai/ci-agent-platform 3.0.1 → 3.1.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.
Files changed (34) hide show
  1. package/README.md +12 -4
  2. package/package.json +2 -2
  3. package/payload/INSTALL.md +8 -2
  4. package/payload/ci-templates/claude-pipeline.gitlab-ci.yml +210 -0
  5. package/payload/ci-templates/scripts/agent-architect.sh +233 -0
  6. package/payload/ci-templates/scripts/code.sh +26 -27
  7. package/payload/ci-templates/scripts/codebase-audit.sh +252 -0
  8. package/payload/ci-templates/scripts/coverage-ratchet.sh +77 -0
  9. package/payload/ci-templates/scripts/cve-fix.sh +246 -0
  10. package/payload/ci-templates/scripts/docs-sync.sh +225 -0
  11. package/payload/ci-templates/scripts/e2e-test-gen.sh +201 -0
  12. package/payload/ci-templates/scripts/lib/failure-notice.sh +104 -0
  13. package/payload/ci-templates/scripts/lib/issue-loop.sh +155 -40
  14. package/payload/ci-templates/scripts/lib/pipeline-common.sh +95 -21
  15. package/payload/ci-templates/scripts/lib/platform.sh +270 -13
  16. package/payload/ci-templates/scripts/lib/usage-capture-omp.sh +7 -1
  17. package/payload/ci-templates/scripts/lib/usage-capture.sh +7 -1
  18. package/payload/ci-templates/scripts/metrics-snapshot.sh +377 -0
  19. package/payload/ci-templates/scripts/orchestrate.sh +55 -37
  20. package/payload/ci-templates/scripts/postmortem.sh +10 -0
  21. package/payload/ci-templates/scripts/review-fix.sh +22 -11
  22. package/payload/ci-templates/scripts/review.sh +11 -7
  23. package/payload/ci-templates/scripts/test-fix.sh +7 -0
  24. package/payload/skills/agent-architect/SKILL.md +45 -0
  25. package/payload/skills/codebase-audit/SKILL.md +84 -0
  26. package/payload/skills/cve-fix/SKILL.md +98 -0
  27. package/payload/skills/docs-sync/SKILL.md +74 -0
  28. package/payload/skills/e2e-test-gen/SKILL.md +65 -0
  29. package/payload/skills/fix-review-findings/SKILL.md +2 -2
  30. package/payload/skills/fix-tests/SKILL.md +2 -2
  31. package/payload/templates/memory-index.template.md +34 -0
  32. package/payload/templates/pipeline-config.template.md +11 -1
  33. package/payload/templates/review_suppressions.template.md +55 -0
  34. package/payload/templates/spec-issue.template.md +39 -7
@@ -52,6 +52,27 @@ _gli_issues_by_label() {
52
52
  milestone_id: (.milestone.id // null)}]'
53
53
  }
54
54
 
55
+ # $1=primary label $2=optional secondary label $3=state $4=limit. Unlike the
56
+ # older single-label helpers this preserves fetch failure so callers never
57
+ # mistake a forge outage for an empty work queue.
58
+ _gli_issues_by_labels() {
59
+ local primary="$1" secondary="$2" state="$3" limit="$4" labels response state_param=""
60
+ [[ "$limit" =~ ^[1-9][0-9]*$ ]] || return 1
61
+ case "$state" in
62
+ all|'') ;;
63
+ opened|closed) state_param="&state=$state" ;;
64
+ *) return 1 ;;
65
+ esac
66
+ labels=$(printf '%s' "$primary${secondary:+,$secondary}" | jq -sRr @uri)
67
+ response=$(curl -s --fail -H "PRIVATE-TOKEN: $PIPE_TOKEN" \
68
+ "$(_gli_api)/issues?labels=$labels${state_param}&per_page=$limit") || return 1
69
+ jq --arg primary "$primary" --arg secondary "$secondary" --argjson limit "$limit" \
70
+ '[.[] | select((.labels // []) | index($primary))
71
+ | select($secondary == "" or ((.labels // []) | index($secondary)))
72
+ | {iid, title: (.title // ""), description: (.description // ""),
73
+ labels: ((.labels // []) | join(","))}] | .[0:$limit]' <<< "$response"
74
+ }
75
+
55
76
  _gli_issues_closed_by_label() {
56
77
  # $1=label. Closed issues still carrying a lifecycle label (janitor input).
57
78
  curl -s -H "PRIVATE-TOKEN: $PIPE_TOKEN" \
@@ -59,6 +80,21 @@ _gli_issues_closed_by_label() {
59
80
  | jq '[.[] | {iid}]'
60
81
  }
61
82
 
83
+ _gli_issues_by_label_created() {
84
+ # $1=label $2=state("all"|"opened"|"closed") $3=limit. Companion to
85
+ # _gli_issues_by_label that preserves created_at (dropped there); the
86
+ # codebase-audit job needs it to find the most recently filed audit issue.
87
+ # Captured into a variable (not piped straight into jq) so a fetch failure
88
+ # propagates via `return 1` instead of being swallowed as an empty result
89
+ # indistinguishable from "no audit issue exists yet" (review round 2 finding).
90
+ local state_param="" response
91
+ [ -n "$2" ] && [ "$2" != "all" ] && state_param="&state=$2"
92
+ response=$(curl -s --fail -H "PRIVATE-TOKEN: $PIPE_TOKEN" \
93
+ "$(_gli_api)/issues?labels=$1${state_param}&order_by=created_at&sort=desc&per_page=$3") || return 1
94
+ jq '[.[] | {iid, title: (.title // ""), description: (.description // ""),
95
+ labels: ((.labels // []) | join(",")), created_at: (.created_at // "")}]' <<< "$response"
96
+ }
97
+
62
98
  _gli_issue_notes() {
63
99
  # $1=iid. Non-system notes, newest first. The caller (orchestrate.sh) caps
64
100
  # the total volume and adds a visible truncation marker, so the newest and
@@ -113,12 +149,15 @@ _gli_children_state() {
113
149
  echo "$total $open"
114
150
  }
115
151
 
116
- _gli_create_issue() {
117
- # $1=title $2=desc $3=labels(comma). Prints new iid or empty.
118
- curl -s -X POST -H "PRIVATE-TOKEN: $PIPE_TOKEN" -H "Content-Type: application/json" \
119
- "$(_gli_api)/issues" \
120
- -d "$(jq -n --arg t "$1" --arg b "$2" --arg l "$3" '{title:$t,description:$b,labels:$l}')" \
121
- | jq -r '.iid // empty'
152
+ _gli_create_issue_file() {
153
+ # $1=title $2=description file $3=labels(comma). Prints new iid or empty.
154
+ local payload result
155
+ payload=$(mktemp "$PIPE_CONTEXT_DIR/gitlab-issue.XXXXXX.json")
156
+ jq -n --arg t "$1" --rawfile b "$2" --arg l "$3" '{title:$t,description:$b,labels:$l}' > "$payload"
157
+ result=$(curl -s -X POST -H "PRIVATE-TOKEN: $PIPE_TOKEN" -H "Content-Type: application/json" \
158
+ "$(_gli_api)/issues" --data-binary "@$payload" | jq -r '.iid // empty')
159
+ rm -f "$payload"
160
+ printf '%s\n' "$result"
122
161
  }
123
162
 
124
163
  _gli_link_blocked_by() {
@@ -140,9 +179,10 @@ _gli_close_issue() {
140
179
  "$(_gli_api)/issues/$1" -d '{"state_event":"close"}' > /dev/null || true
141
180
  }
142
181
 
143
- _gli_issue_comment() {
182
+ _gli_issue_comment_file() {
183
+ # $1=iid $2=comment file.
144
184
  curl -s -X POST -H "PRIVATE-TOKEN: $PIPE_TOKEN" "$(_gli_api)/issues/$1/notes" \
145
- --data-urlencode "body=$2" > /dev/null
185
+ --data-urlencode "body@$2" > /dev/null
146
186
  }
147
187
 
148
188
  _gli_code_trigger() {
@@ -164,13 +204,16 @@ _gli_code_trigger() {
164
204
  }
165
205
  }
166
206
 
167
- _gli_mr_create() {
168
- # $1=source $2=target $3=title $4=desc $5=labels(comma). Prints web_url.
169
- curl --fail-with-body -s -X POST -H "PRIVATE-TOKEN: $PIPE_TOKEN" -H "Content-Type: application/json" \
170
- "$(_gli_api)/merge_requests" \
171
- -d "$(jq -n --arg s "$1" --arg t "$2" --arg ti "$3" --arg d "$4" --arg l "$5" \
172
- '{source_branch:$s, target_branch:$t, title:$ti, description:$d, labels:$l, remove_source_branch:true}')" \
173
- | jq -r '.web_url // empty'
207
+ _gli_mr_create_file() {
208
+ # $1=source $2=target $3=title $4=description file $5=labels(comma). Prints web_url.
209
+ local payload result
210
+ payload=$(mktemp "$PIPE_CONTEXT_DIR/gitlab-mr.XXXXXX.json")
211
+ jq -n --arg s "$1" --arg t "$2" --arg ti "$3" --rawfile d "$4" --arg l "$5" \
212
+ '{source_branch:$s, target_branch:$t, title:$ti, description:$d, labels:$l, remove_source_branch:true}' > "$payload"
213
+ result=$(curl --fail-with-body -s -X POST -H "PRIVATE-TOKEN: $PIPE_TOKEN" -H "Content-Type: application/json" \
214
+ "$(_gli_api)/merge_requests" --data-binary "@$payload" | jq -r '.web_url // empty')
215
+ rm -f "$payload"
216
+ printf '%s\n' "$result"
174
217
  }
175
218
 
176
219
  # =============================================================================
@@ -194,6 +237,28 @@ _ghi_issues_by_label() {
194
237
  milestone_id: (.milestone.number // null)}]'
195
238
  }
196
239
 
240
+ # $1=primary label $2=optional secondary label $3=state $4=limit. GitHub's
241
+ # shared issues endpoint returns pull requests too, so filter those before the
242
+ # requested slice; otherwise a recent PR can starve an issue queue.
243
+ _ghi_issues_by_labels() {
244
+ local primary="$1" secondary="$2" state="$3" limit="$4" gh_state response
245
+ [[ "$limit" =~ ^[1-9][0-9]*$ ]] || return 1
246
+ case "$state" in
247
+ opened|'') gh_state=open ;;
248
+ closed) gh_state=closed ;;
249
+ all) gh_state=all ;;
250
+ *) return 1 ;;
251
+ esac
252
+ response=$(gh api --paginate "repos/$PIPE_REPO/issues?labels=$primary&state=$gh_state&per_page=100") || return 1
253
+ jq -s 'add // []' <<< "$response" \
254
+ | jq --arg primary "$primary" --arg secondary "$secondary" --argjson limit "$limit" \
255
+ '[.[] | select(has("pull_request") | not)
256
+ | select(((.labels // []) | map(.name) | index($primary)))
257
+ | select($secondary == "" or ((.labels // []) | map(.name) | index($secondary)))
258
+ | {iid: .number, title: (.title // ""), description: (.body // ""),
259
+ labels: ((.labels // []) | map(.name) | join(","))}] | .[0:$limit]'
260
+ }
261
+
197
262
  _ghi_issues_closed_by_label() {
198
263
  # $1=label. Closed issues still carrying a lifecycle label (janitor input).
199
264
  # PRs share the issues endpoint; keep issues only, closed PR labels stay
@@ -202,6 +267,29 @@ _ghi_issues_closed_by_label() {
202
267
  | jq '[.[] | select(has("pull_request") | not) | {iid: .number}]'
203
268
  }
204
269
 
270
+ _ghi_issues_by_label_created() {
271
+ # $1=label $2=state("all"|"opened"|"closed") $3=limit. GitHub's shared
272
+ # issues/PRs endpoint has no server-side "issues only" filter, so applying
273
+ # $3 as per_page before the pull_request filter can empty the result: once
274
+ # this job's own auto-fix PR carries the same label, it is newer than the
275
+ # audit issues and a limit of 1 would fetch only that PR, filter it away,
276
+ # and return nothing (review round 1 finding). Fetch a full page (GitHub's
277
+ # per-page max) and slice to the requested limit after the PR filter.
278
+ # Captured into a variable (not piped straight into jq) so a fetch failure
279
+ # propagates via `return 1` instead of being swallowed as an empty result
280
+ # indistinguishable from "no audit issue exists yet" (review round 2 finding).
281
+ local gh_state response
282
+ case "$2" in
283
+ closed) gh_state=closed ;;
284
+ all) gh_state=all ;;
285
+ *) gh_state=open ;;
286
+ esac
287
+ response=$(gh api "repos/$PIPE_REPO/issues?labels=$1&state=$gh_state&sort=created&direction=desc&per_page=100") || return 1
288
+ jq --argjson limit "$3" '[.[] | select(has("pull_request") | not)
289
+ | {iid: .number, title: (.title // ""), description: (.body // ""),
290
+ labels: ((.labels // []) | map(.name) | join(",")), created_at: (.created_at // "")}] | .[0:$limit]' <<< "$response"
291
+ }
292
+
205
293
  _ghi_issue_notes() {
206
294
  # $1=iid. Comments newest first (GitHub returns them oldest first, so reverse).
207
295
  # The caller (orchestrate.sh) caps the total volume and adds a visible
@@ -231,21 +319,32 @@ _ghi_link_blocked_by() {
231
319
  # dependent issue body after all local decomposition keys have been mapped.
232
320
  # The marker is visible and deliberately idempotent because the release poll
233
321
  # parses the same "Blocked by #N" convention.
234
- local blocked="$1" blocker="$2" body marker
235
- body=$(_ghi_issue_body "$blocked")
322
+ local blocked="$1" blocker="$2" body_file payload marker
323
+ body_file=$(mktemp "$PIPE_CONTEXT_DIR/github-issue-body.XXXXXX")
324
+ _ghi_issue_body "$blocked" > "$body_file"
236
325
  marker="Blocked by #$blocker"
237
- printf '%s\n' "$body" | grep -qiE "(^|[[:space:]])Blocked by #${blocker}([^0-9]|$)" && return 0
326
+ grep -qiE "(^|[[:space:]])Blocked by #${blocker}([^0-9]|$)" "$body_file" && {
327
+ rm -f "$body_file"
328
+ return 0
329
+ }
330
+ payload=$(mktemp "$PIPE_CONTEXT_DIR/github-issue.XXXXXX.json")
331
+ jq -n --rawfile body "$body_file" --arg marker "$marker" \
332
+ '{body: $body + (if $body == "" then "" else "\n\n" end) + $marker}' > "$payload"
238
333
  gh api -X PATCH "repos/$PIPE_REPO/issues/$blocked" \
239
- -f "body=${body}${body:+$'\n\n'}$marker" > /dev/null
334
+ -H "Content-Type: application/json" --input "$payload" > /dev/null
335
+ rm -f "$body_file" "$payload"
240
336
  }
241
337
 
242
- _ghi_create_issue() {
243
- # $1=title $2=desc $3=labels(comma). Prints new number.
244
- local args=() l
245
- IFS=',' read -ra _labels <<< "$3"
246
- for l in "${_labels[@]}"; do [ -n "$l" ] && args+=(-f "labels[]=$l"); done
247
- gh api -X POST "repos/$PIPE_REPO/issues" -f "title=$1" -f "body=$2" "${args[@]}" \
248
- --jq '.number // empty'
338
+ _ghi_create_issue_file() {
339
+ # $1=title $2=description file $3=labels(comma). Prints new number.
340
+ local payload result
341
+ payload=$(mktemp "$PIPE_CONTEXT_DIR/github-issue.XXXXXX.json")
342
+ jq -n --arg t "$1" --rawfile b "$2" --arg l "$3" \
343
+ '{title:$t, body:$b, labels: ($l | split(",") | map(select(length > 0)))}' > "$payload"
344
+ result=$(gh api -X POST "repos/$PIPE_REPO/issues" \
345
+ -H "Content-Type: application/json" --input "$payload" --jq '.number // empty')
346
+ rm -f "$payload"
347
+ printf '%s\n' "$result"
249
348
  }
250
349
 
251
350
  _ghi_set_issue_labels() {
@@ -260,8 +359,15 @@ _ghi_close_issue() {
260
359
  gh api -X PATCH "repos/$PIPE_REPO/issues/$1" -f "state=closed" > /dev/null 2>&1 || true
261
360
  }
262
361
 
263
- _ghi_issue_comment() {
264
- gh api -X POST "repos/$PIPE_REPO/issues/$1/comments" -f "body=$2" > /dev/null
362
+ _ghi_issue_comment_file() {
363
+ # $1=iid $2=comment file.
364
+ local payload status=0
365
+ payload=$(mktemp "$PIPE_CONTEXT_DIR/github-comment.XXXXXX.json")
366
+ jq -n --rawfile body "$2" '{body:$body}' > "$payload"
367
+ gh api -X POST "repos/$PIPE_REPO/issues/$1/comments" \
368
+ -H "Content-Type: application/json" --input "$payload" > /dev/null || status=$?
369
+ rm -f "$payload"
370
+ return "$status"
265
371
  }
266
372
 
267
373
  _ghi_code_trigger() {
@@ -278,21 +384,27 @@ _ghi_code_trigger() {
278
384
  }
279
385
  }
280
386
 
281
- _ghi_pr_create() {
282
- # $1=source $2=target $3=title $4=desc $5=labels(comma). Prints html_url.
387
+ _ghi_pr_create_file() {
388
+ # $1=source $2=target $3=title $4=description file $5=labels(comma). Prints html_url.
283
389
  # Created as a draft and flipped to ready only after the labels are on
284
390
  # (finding P5): GitHub cannot attach labels at PR creation, so a non-draft
285
391
  # PR emits an `opened` + `labeled` event pair and the review workflow runs
286
392
  # twice. Draft PRs do not trigger the review job, which makes the single
287
393
  # `ready_for_review` event the only trigger. Falls back to a plain PR when
288
394
  # the plan does not support drafts on this repo (free plan, private repo).
289
- local url num
395
+ local url num payload
396
+ payload=$(mktemp "$PIPE_CONTEXT_DIR/github-pr.XXXXXX.json")
397
+ jq -n --arg h "$1" --arg b "$2" --arg t "$3" --rawfile d "$4" \
398
+ '{head:$h, base:$b, title:$t, body:$d, draft:true}' > "$payload"
290
399
  url=$(gh api -X POST "repos/$PIPE_REPO/pulls" \
291
- -f "head=$1" -f "base=$2" -f "title=$3" -f "body=$4" -F "draft=true" --jq '.html_url // empty' 2>/dev/null || true)
400
+ -H "Content-Type: application/json" --input "$payload" --jq '.html_url // empty' 2>/dev/null || true)
292
401
  if [ -z "$url" ]; then
402
+ jq -n --arg h "$1" --arg b "$2" --arg t "$3" --rawfile d "$4" \
403
+ '{head:$h, base:$b, title:$t, body:$d}' > "$payload"
293
404
  url=$(gh api -X POST "repos/$PIPE_REPO/pulls" \
294
- -f "head=$1" -f "base=$2" -f "title=$3" -f "body=$4" --jq '.html_url // empty' 2>/dev/null || true)
405
+ -H "Content-Type: application/json" --input "$payload" --jq '.html_url // empty' 2>/dev/null || true)
295
406
  fi
407
+ rm -f "$payload"
296
408
  num=$(echo "$url" | grep -oE '[0-9]+$' || true)
297
409
  if [ -n "$num" ] && [ -n "$5" ]; then
298
410
  # Labels go through the issues API (a PR is an issue on GitHub).
@@ -309,17 +421,19 @@ _ghi_pr_create() {
309
421
 
310
422
  issue_ensure_label() { case "$PIPE_PLATFORM" in gitlab) _gli_ensure_label "$1" "$2" "$3" ;; github) _ghi_ensure_label "$1" "$2" "$3" ;; esac; }
311
423
  issues_by_label() { case "$PIPE_PLATFORM" in gitlab) _gli_issues_by_label "$1" ;; github) _ghi_issues_by_label "$1" ;; esac; }
424
+ issues_by_labels() { case "$PIPE_PLATFORM" in gitlab) _gli_issues_by_labels "$1" "$2" "$3" "$4" ;; github) _ghi_issues_by_labels "$1" "$2" "$3" "$4" ;; esac; }
312
425
  issues_closed_by_label() { case "$PIPE_PLATFORM" in gitlab) _gli_issues_closed_by_label "$1" ;; github) _ghi_issues_closed_by_label "$1" ;; esac; }
426
+ issues_by_label_created() { case "$PIPE_PLATFORM" in gitlab) _gli_issues_by_label_created "$1" "$2" "$3" ;; github) _ghi_issues_by_label_created "$1" "$2" "$3" ;; esac; }
313
427
  issue_notes() { case "$PIPE_PLATFORM" in gitlab) _gli_issue_notes "$1" ;; github) _ghi_issue_notes "$1" ;; esac; }
314
428
  issue_body() { case "$PIPE_PLATFORM" in gitlab) _gli_issue_body "$1" ;; github) _ghi_issue_body "$1" ;; esac; }
315
429
  issue_meta() { case "$PIPE_PLATFORM" in gitlab) _gli_issue_meta "$1" ;; github) _ghi_issue_meta "$1" ;; esac; }
316
430
  issue_state() { case "$PIPE_PLATFORM" in gitlab) _gli_issue_state "$1" ;; github) _ghi_issue_state "$1" ;; esac; }
317
- issue_create() { case "$PIPE_PLATFORM" in gitlab) _gli_create_issue "$1" "$2" "$3" ;; github) _ghi_create_issue "$1" "$2" "$3" ;; esac; }
431
+ issue_create_file() { case "$PIPE_PLATFORM" in gitlab) _gli_create_issue_file "$1" "$2" "$3" ;; github) _ghi_create_issue_file "$1" "$2" "$3" ;; esac; }
318
432
  issue_set_labels() { case "$PIPE_PLATFORM" in gitlab) _gli_set_issue_labels "$1" "$2" "$3" ;; github) _ghi_set_issue_labels "$1" "$2" "$3" ;; esac; }
319
433
  issue_close() { case "$PIPE_PLATFORM" in gitlab) _gli_close_issue "$1" ;; github) _ghi_close_issue "$1" ;; esac; }
320
- issue_comment() { case "$PIPE_PLATFORM" in gitlab) _gli_issue_comment "$1" "$2" ;; github) _ghi_issue_comment "$1" "$2" ;; esac; }
434
+ issue_comment_file() { case "$PIPE_PLATFORM" in gitlab) _gli_issue_comment_file "$1" "$2" ;; github) _ghi_issue_comment_file "$1" "$2" ;; esac; }
321
435
  code_trigger() { case "$PIPE_PLATFORM" in gitlab) _gli_code_trigger "$1" "$2" ;; github) _ghi_code_trigger "$1" "$2" ;; esac; }
322
- mr_create() { case "$PIPE_PLATFORM" in gitlab) _gli_mr_create "$1" "$2" "$3" "$4" "$5" ;; github) _ghi_pr_create "$1" "$2" "$3" "$4" "$5" ;; esac; }
436
+ mr_create_file() { case "$PIPE_PLATFORM" in gitlab) _gli_mr_create_file "$1" "$2" "$3" "$4" "$5" ;; github) _ghi_pr_create_file "$1" "$2" "$3" "$4" "$5" ;; esac; }
323
437
  issue_link_blocked_by() { case "$PIPE_PLATFORM" in gitlab) _gli_link_blocked_by "$1" "$2" ;; github) _ghi_link_blocked_by "$1" "$2" ;; esac; }
324
438
 
325
439
  # Count how many issues that block $1 are still open. GitLab uses native links,
@@ -376,13 +490,13 @@ issue_children_state() {
376
490
  # templates/spec-issue.template.md. If you rename a section
377
491
  # header or change a placeholder token in the template, update both lists here.
378
492
  DECOMP_REJECT_REASON=""
379
- pipe_validate_decomposition() {
493
+ pipe_validate_decomposition_file() {
380
494
  # Prints the first problem to stdout on failure (empty on success). Sets
381
495
  # DECOMP_REJECT_REASON and returns 1 when invalid, 0 when valid.
382
- local json="$1"
496
+ local json_file="$1"
383
497
  DECOMP_REJECT_REASON=""
384
498
  local reason
385
- reason=$(printf '%s' "$json" | jq -r '
499
+ reason=$(jq -r '
386
500
  def required: ["## 1. Outcome","## 2. Context","## 3. Acceptance Criteria",
387
501
  "## 4. Scope Envelope","## 5. Existing Code Anchors","## 6. Risk Flags",
388
502
  "## 7. Test Plan","## 8. Out of Scope"];
@@ -394,6 +508,7 @@ pipe_validate_decomposition() {
394
508
  | if ($conf != "high" and $conf != "low") then "confidence must be high or low, got: \($conf)"
395
509
  elif (($subs | length) < 2 or ($subs | length) > 5) then "sub_issues count must be 2-5, got: \($subs | length)"
396
510
  elif ($keys | any(. == null or . == "")) then "every sub_issue needs a non-empty key"
511
+ elif ($keys | length) != ($keys | unique | length) then "sub_issue keys must be unique"
397
512
  else
398
513
  ( [ $subs[] | (.depends_on // [])[] as $d | select(($keys | index($d)) == null) | $d ] | first ) as $unknown
399
514
  | if $unknown != null then "depends_on references unknown key: \($unknown)"
@@ -420,7 +535,7 @@ pipe_validate_decomposition() {
420
535
  end
421
536
  end
422
537
  end
423
- ' 2>/dev/null || echo "invalid JSON")
538
+ ' "$json_file" 2>/dev/null || echo "invalid JSON")
424
539
  if [ -n "$reason" ]; then
425
540
  # shellcheck disable=SC2034 # read by orchestrate.sh once this returns 1
426
541
  DECOMP_REJECT_REASON="$reason"
@@ -13,6 +13,8 @@ source "$SCRIPT_LIB_DIR/usage-capture.sh"
13
13
  source "$SCRIPT_LIB_DIR/usage-capture-omp.sh"
14
14
  # shellcheck source=./platform.sh
15
15
  source "$SCRIPT_LIB_DIR/platform.sh"
16
+ # shellcheck source=./failure-notice.sh
17
+ source "$SCRIPT_LIB_DIR/failure-notice.sh"
16
18
 
17
19
  # --- Defaults ---------------------------------------------------------------
18
20
  # Every PIPE_ variable has a default here so a project that overrides nothing
@@ -25,6 +27,7 @@ pipe_defaults() {
25
27
  : "${PIPE_CONFIG_PATH:=.claude/pipeline-config.md}"
26
28
  : "${PIPE_CONTEXT_DIR:=build/pipeline}"
27
29
  : "${PIPE_METRICS_DIR:=$PIPE_CONTEXT_DIR/metrics}"
30
+ : "${PIPE_AGENT_STDERR:=$PIPE_CONTEXT_DIR/agent-stderr.log}"
28
31
  : "${PIPE_TARGET_BRANCH:=main}"
29
32
  : "${PIPE_FIX_LOOP_CAP:=2}"
30
33
  : "${PIPE_CODER_CAP:=3}"
@@ -44,18 +47,67 @@ pipe_defaults() {
44
47
  : "${PIPE_COMMIT_TESTFIX:=Fix test errors}"
45
48
  : "${PIPE_COMMIT_REVIEWFIX:=Fix review findings}"
46
49
  : "${PIPE_COMMIT_COVERAGE:=Add coverage tests}"
50
+ : "${PIPE_COMMIT_DOCSSYNC:=Update docs per docs-sync findings}"
51
+ : "${PIPE_COMMIT_AUDIT:=docs: apply convention audit findings}"
52
+ : "${PIPE_COMMIT_CVEFIX:=Update dependencies to resolve CVEs}"
47
53
  : "${PIPE_LABEL_READY:=pipe-ready}"
48
54
  : "${PIPE_LABEL_WIP:=pipe-wip}"
49
55
  : "${PIPE_LABEL_STUCK:=pipe-stuck}"
50
56
  : "${PIPE_LABEL_BLOCKER:=pipe-blocker}"
51
57
  : "${PIPE_LABEL_BLOCKED:=pipe-blocked}"
52
58
  : "${PIPE_LABEL_DECOMPOSED:=pipe-decomposed}"
59
+ : "${PIPE_LABEL_AUDIT:=codebase-audit}"
53
60
  : "${PIPE_RESULT_REVIEW:=$PIPE_CONTEXT_DIR/code-review-result.txt}"
54
61
  : "${PIPE_RESULT_REVIEWFIX:=$PIPE_CONTEXT_DIR/review-fix-result.json}"
62
+ : "${PIPE_RESULT_DOCSSYNC:=$PIPE_CONTEXT_DIR/docs-sync.json}"
55
63
  : "${PIPE_VERIFY_CMD:=}"
56
64
  : "${PIPE_COMPILE_CMD:=${PIPE_VERIFY_CMD}}"
57
65
  : "${PIPE_TEST_REPORT_GLOB:=}"
66
+ : "${PIPE_COVERAGE_RATCHET:=0}"
67
+ : "${PIPE_COVERAGE_REPORT:=}"
68
+ : "${PIPE_COVERAGE_REPORT_KIND:=jacoco}"
58
69
  : "${PIPE_COVERAGE_SIGNAL:=}"
70
+ # CVE remediation. Off by default: project-local scanners provide the
71
+ # HIGH/CRITICAL identifier list when PIPE_CVE_FIX=1 enables this job.
72
+ : "${PIPE_CVE_FIX:=0}"
73
+ : "${PIPE_DEPENDENCY_MANIFEST:=build.gradle}"
74
+ : "${PIPE_CVE_SUPPRESSIONS:=owasp-suppressions.xml}"
75
+ # Issue-driven E2E generation. Off by default; PIPE_VERIFY_CMD is the
76
+ # configured verification command and must be non-empty before tests run.
77
+ : "${PIPE_E2E_TEST_GEN:=0}"
78
+ : "${PIPE_LABEL_TESTREADY:=test-ready}"
79
+ : "${PIPE_LABEL_E2E_SCOPE:=}"
80
+ : "${PIPE_E2E_TEST_DIR:=e2e/tests}"
81
+ : "${PIPE_E2E_BASE_URL:=}"
82
+ : "${PIPE_E2E_VERIFY_CMD:=}"
83
+ # Documentation sync. Off by default: the job only runs when the pipeline
84
+ # sets PIPE_DOCS_SYNC=1. PIPE_DOCS_ROOTS is the comma-separated set of paths
85
+ # the docs-sync agent may edit and the runner may commit.
86
+ : "${PIPE_DOCS_SYNC:=0}"
87
+ : "${PIPE_DOCS_ROOTS:=docs,CLAUDE.md,.claude/memory}"
88
+ # Codebase audit. Off by default: the job only runs on a schedule that sets
89
+ # PIPE_CODEBASE_AUDIT=1. Reuses PIPE_DOCS_ROOTS for the optional auto-fix
90
+ # phase's coder scope.
91
+ : "${PIPE_CODEBASE_AUDIT:=0}"
92
+ # Agent architect. Off by default: a scheduled pipeline explicitly enables
93
+ # this evidence-backed proposal job after a project has reviewed its output.
94
+ : "${PIPE_AGENT_ARCHITECT:=0}"
95
+ : "${PIPE_ARCHITECT_WINDOW_DAYS:=7}"
96
+ : "${PIPE_ARCHITECT_DRY_RUN:=true}"
97
+ : "${PIPE_LABEL_IMPROVEMENT:=pipe-improvement}"
98
+ # Metrics aggregation. Off by default: the job only runs on a schedule that
99
+ # sets PIPE_METRICS_SNAPSHOT=1, and it publishes an artifact unless the
100
+ # project explicitly opts in to committing generated data to its repository.
101
+ : "${PIPE_METRICS_SNAPSHOT:=0}"
102
+ : "${PIPE_METRICS_OUTPUT_DIR:=data/metrics/snapshots}"
103
+ : "${PIPE_METRICS_WINDOW_DAYS:=1}"
104
+ : "${PIPE_METRICS_COMMIT_REPO:=false}"
105
+ : "${PIPE_METRICS_REVIEW_AGENTS:=code-reviewer,review-verdict,review-fix}"
106
+ # Commit subjects that mark a defect in already-merged work. Keep in sync with
107
+ # the Metrics Conventions section of the pipeline config.
108
+ : "${PIPE_METRICS_DEFECT_REVERT:=Reverts !}"
109
+ : "${PIPE_METRICS_DEFECT_REGRESSION:=Fixes regression from !}"
110
+ : "${PIPE_METRICS_DEFECT_REINTRODUCE:=Reintroduces work from !}"
59
111
  # Spec template path. GitHub projects usually keep it under .github, GitLab
60
112
  # under .gitlab, so the default follows the detected platform.
61
113
  if [ "$PIPE_PLATFORM" = "github" ]; then
@@ -69,12 +121,20 @@ pipe_defaults() {
69
121
  # would pick up result files (E2E finding N-6). A `*` gitignore inside the
70
122
  # dir hides everything in it, including itself, from any git add.
71
123
  [ -f "$PIPE_CONTEXT_DIR/.gitignore" ] || printf '*\n' > "$PIPE_CONTEXT_DIR/.gitignore"
72
- export PIPE_PLATFORM PIPE_CONFIG_PATH PIPE_CONTEXT_DIR PIPE_METRICS_DIR \
124
+ export PIPE_PLATFORM PIPE_CONFIG_PATH PIPE_CONTEXT_DIR PIPE_METRICS_DIR PIPE_AGENT_STDERR \
73
125
  PIPE_TARGET_BRANCH PIPE_FIX_LOOP_CAP PIPE_CODER_CAP PIPE_ISSUE_SCAN PIPE_COMMIT_TESTFIX \
74
- PIPE_COMMIT_REVIEWFIX PIPE_COMMIT_COVERAGE PIPE_LABEL_READY PIPE_LABEL_WIP \
75
- PIPE_LABEL_STUCK PIPE_LABEL_BLOCKER PIPE_LABEL_BLOCKED PIPE_LABEL_DECOMPOSED \
76
- PIPE_RESULT_REVIEW PIPE_RESULT_REVIEWFIX PIPE_VERIFY_CMD PIPE_COMPILE_CMD \
77
- PIPE_TEST_REPORT_GLOB PIPE_COVERAGE_SIGNAL PIPE_SPEC_TEMPLATE_PATH \
126
+ PIPE_COMMIT_REVIEWFIX PIPE_COMMIT_COVERAGE PIPE_COMMIT_CVEFIX PIPE_LABEL_READY PIPE_LABEL_WIP \
127
+ PIPE_LABEL_STUCK PIPE_LABEL_BLOCKER PIPE_LABEL_BLOCKED PIPE_LABEL_DECOMPOSED PIPE_LABEL_AUDIT \
128
+ PIPE_RESULT_REVIEW PIPE_RESULT_REVIEWFIX PIPE_RESULT_DOCSSYNC PIPE_COMMIT_DOCSSYNC PIPE_COMMIT_AUDIT \
129
+ PIPE_CVE_FIX PIPE_DEPENDENCY_MANIFEST PIPE_CVE_SUPPRESSIONS PIPE_E2E_TEST_GEN PIPE_LABEL_TESTREADY \
130
+ PIPE_LABEL_E2E_SCOPE PIPE_E2E_TEST_DIR PIPE_E2E_BASE_URL PIPE_E2E_VERIFY_CMD PIPE_DOCS_SYNC PIPE_DOCS_ROOTS PIPE_VERIFY_CMD PIPE_COMPILE_CMD \
131
+ PIPE_TEST_REPORT_GLOB PIPE_COVERAGE_RATCHET PIPE_COVERAGE_REPORT PIPE_COVERAGE_REPORT_KIND \
132
+ PIPE_COVERAGE_SIGNAL PIPE_SPEC_TEMPLATE_PATH PIPE_CODEBASE_AUDIT PIPE_AGENT_ARCHITECT \
133
+ PIPE_ARCHITECT_WINDOW_DAYS PIPE_ARCHITECT_DRY_RUN PIPE_LABEL_IMPROVEMENT \
134
+ PIPE_METRICS_SNAPSHOT PIPE_METRICS_OUTPUT_DIR PIPE_METRICS_WINDOW_DAYS \
135
+ PIPE_METRICS_COMMIT_REPO PIPE_METRICS_REVIEW_AGENTS PIPE_METRICS_DEFECT_REVERT \
136
+ PIPE_METRICS_DEFECT_REGRESSION PIPE_METRICS_DEFECT_REINTRODUCE \
137
+ PIPE_METRICS_SNAPSHOT_DATE PIPE_METRICS_RAW_DIR PIPE_METRICS_MRS_FILE \
78
138
  PIPE_HARNESS PIPE_MODEL_TRIAGE PIPE_MODEL_CODE PIPE_MODEL_REVIEW
79
139
  }
80
140
 
@@ -99,6 +159,17 @@ pipe_git_identity() {
99
159
  # Checkout the real source branch so commits land on the branch tip, not on the
100
160
  # detached MR/PR ref that can fall behind and cause non-fast-forward push errors.
101
161
  pipe_checkout_source() {
162
+ # The MR/PR itself is the authoritative source of the branch name. A
163
+ # workflow_run or branch pipeline carries no merge-request source ref, and
164
+ # without one this checkout used to no-op silently, leaving the fix commit on
165
+ # a detached head that no push could land.
166
+ if [ -z "${PIPE_SOURCE_BRANCH:-}" ] && [ -n "${PIPE_MR_IID:-}" ]; then
167
+ # `|| PIPE_SOURCE_BRANCH=""` is the whole error path: an unreachable or
168
+ # unconfigured API must leave the caller where it was, not abort it.
169
+ PIPE_SOURCE_BRANCH=$(platform_mr_meta 2>/dev/null | jq -r '.source_branch // ""' 2>/dev/null) \
170
+ || PIPE_SOURCE_BRANCH=""
171
+ export PIPE_SOURCE_BRANCH
172
+ fi
102
173
  [ -z "${PIPE_SOURCE_BRANCH:-}" ] && return 0
103
174
  git fetch origin "$PIPE_TARGET_BRANCH" "$PIPE_SOURCE_BRANCH" 2>/dev/null || true
104
175
  git checkout -B "$PIPE_SOURCE_BRANCH" "origin/$PIPE_SOURCE_BRANCH" 2>/dev/null || true
@@ -117,15 +188,17 @@ pipe_rebase_and_push() {
117
188
  }
118
189
 
119
190
  # --- Cap counting -----------------------------------------------------------
120
- # Count consecutive commits from the tip back toward the target branch whose
121
- # subject matches a pattern. The skill also computes this, but the runner needs
122
- # it to decide whether the agent actually committed this run.
123
-
191
+ # Count consecutive matching commits from the tip back toward the target branch.
192
+ # Docs-sync commits are transparent: they do not count, but do not interrupt a
193
+ # fix streak. The skills use the same exact-subject rules for their cap checks;
194
+ # the runner needs this count only to detect whether a fix commit landed.
124
195
  pipe_count_fix_commits() {
125
196
  local pattern="$1" count=0 subject
126
197
  while IFS= read -r subject; do
127
- if echo "$subject" | grep -qF "$pattern"; then
198
+ if [ "$subject" = "$pattern" ]; then
128
199
  count=$((count + 1))
200
+ elif [ "$subject" = "$PIPE_COMMIT_DOCSSYNC" ]; then
201
+ continue
129
202
  else
130
203
  break
131
204
  fi
@@ -368,23 +441,24 @@ pipe_get_env() {
368
441
  pipe_apply_escalation() {
369
442
  local pm_env="$PIPE_CONTEXT_DIR/postmortem.env"
370
443
  local pm_body="$PIPE_CONTEXT_DIR/postmortem.md"
371
- local add remove category diag
444
+ local add remove category comment_file
372
445
  add=$(pipe_get_env "$pm_env" ADD_LABELS); add=${add:-$PIPE_LABEL_STUCK}
373
446
  remove=$(pipe_get_env "$pm_env" REMOVE_LABELS); remove=${remove:-$PIPE_LABEL_WIP}
374
447
  category=$(pipe_get_env "$pm_env" FAILURE_CATEGORY); category=${category:-${1:-other}}
375
448
 
376
449
  platform_set_labels "$add" "$remove"
377
450
 
378
- if [ -s "$pm_body" ]; then
379
- diag=$(cat "$pm_body")
380
- else
381
- diag="Automated fixes were exhausted after $PIPE_FIX_LOOP_CAP attempts. A human needs to take over."
382
- fi
383
- platform_post_comment "🤖 **Auto-fix stuck after $PIPE_FIX_LOOP_CAP attempts. Diagnostic analysis:**
384
-
385
- $diag
386
-
387
- Human intervention needed."
451
+ comment_file="$PIPE_CONTEXT_DIR/auto-fix-stuck.md"
452
+ {
453
+ printf '🤖 **Auto-fix stuck after %s attempts. Diagnostic analysis:**\n\n' "$PIPE_FIX_LOOP_CAP"
454
+ if [ -s "$pm_body" ]; then
455
+ cat "$pm_body"
456
+ else
457
+ printf 'Automated fixes were exhausted after %s attempts. A human needs to take over.' "$PIPE_FIX_LOOP_CAP"
458
+ fi
459
+ printf '\n\nHuman intervention needed.\n'
460
+ } > "$comment_file"
461
+ platform_post_comment_file "$comment_file"
388
462
 
389
463
  pipe_metric_event postmortem dev_stuck \
390
464
  "$(jq -n --arg c "$category" --arg ctx "${2:-unknown}" '{failure_category: $c, context: $ctx}')"