@yandy-r/ycc-opencode 6.1.1 → 6.2.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.
Files changed (126) hide show
  1. package/README.md +7 -3
  2. package/agents/code-researcher.md +3 -3
  3. package/agents/feature-researcher.md +1 -1
  4. package/agents/implementor.md +4 -4
  5. package/agents/pr-comment-fixer.md +1 -1
  6. package/agents/release-fix-applier.md +1 -1
  7. package/agents/review-fixer.md +1 -1
  8. package/index.js +146 -95
  9. package/package.json +1 -1
  10. package/registration.json +0 -4
  11. package/shared/references/artifact-store.md +613 -0
  12. package/shared/references/branch-prep.md +2 -0
  13. package/shared/references/forge-detection.md +3 -2
  14. package/shared/references/review-artifact-format.md +13 -6
  15. package/shared/references/review-checklist.md +3 -2
  16. package/shared/references/review-dispatch.md +15 -10
  17. package/shared/references/target-capability-matrix.md +140 -32
  18. package/shared/references/visual-mode.md +19 -13
  19. package/shared/references/worktree-strategy.md +12 -8
  20. package/shared/scripts/artifact-body.sh +71 -0
  21. package/shared/scripts/artifact-store-pointer.sh +245 -0
  22. package/shared/scripts/ci-monitor.sh +9 -4
  23. package/shared/scripts/collect-linear-keys.sh +77 -0
  24. package/shared/scripts/lib/ci-classify.sh +13 -10
  25. package/shared/scripts/lib/forge.sh +13 -4
  26. package/shared/scripts/prepare-feature-branch.sh +118 -10
  27. package/shared/scripts/release-ci-monitor.sh +2 -2
  28. package/shared/scripts/report-bundle-drift.sh +1 -1
  29. package/shared/scripts/resolve-artifact-store.sh +636 -0
  30. package/shared/scripts/validate-file-paths.sh +11 -4
  31. package/skills/blueprint/SKILL.md +48 -13
  32. package/skills/bundle-release/scripts/draft-notes.sh +1 -1
  33. package/skills/bundle-release/scripts/release_versions.py +9 -1
  34. package/skills/clean/SKILL.md +1 -1
  35. package/skills/clean/scripts/detect-project-type.sh +2 -2
  36. package/skills/clean/scripts/generate-report.sh +34 -5
  37. package/skills/clean/scripts/validate-safety.sh +9 -6
  38. package/skills/code-report/SKILL.md +26 -14
  39. package/skills/code-report/scripts/check-prerequisites.sh +72 -12
  40. package/skills/code-report/templates/report-structure.md +1 -1
  41. package/skills/code-review/SKILL.md +68 -17
  42. package/skills/code-review/references/pr-procedure.md +28 -15
  43. package/skills/compatibility-audit/SKILL.md +10 -5
  44. package/skills/compatibility-audit/references/reading-the-report.md +4 -1
  45. package/skills/compatibility-audit/scripts/audit-install-assumptions.sh +64 -7
  46. package/skills/compatibility-audit/scripts/audit-target-features.sh +13 -10
  47. package/skills/deep-research/SKILL.md +28 -5
  48. package/skills/deep-research/references/completion-summary-template.md +3 -2
  49. package/skills/deep-research/scripts/validate-research.sh +8 -2
  50. package/skills/feature-research/SKILL.md +48 -25
  51. package/skills/feature-research/scripts/validate-research.sh +51 -12
  52. package/skills/feature-research/scripts/validate-spec.sh +53 -22
  53. package/skills/feature-research/templates/research-agents.md +15 -14
  54. package/skills/feature-research/templates/spec-structure.md +5 -0
  55. package/skills/formatters/scripts/apply-aliases.sh +3 -1
  56. package/skills/formatters/scripts/apply-ci.sh +3 -1
  57. package/skills/git-workflow/SKILL.md +2 -1
  58. package/skills/git-workflow/references/pr-creation.md +10 -0
  59. package/skills/git-workflow/scripts/analyze-changes.sh +21 -11
  60. package/skills/git-workflow/scripts/create-pr.sh +51 -6
  61. package/skills/git-workflow/scripts/validate-commit.sh +26 -14
  62. package/skills/hooks-workflow/scripts/verify-hooks.sh +1 -1
  63. package/skills/implement-plan/SKILL.md +35 -16
  64. package/skills/implement-plan/references/agent-task-prompt.md +8 -5
  65. package/skills/implement-plan/references/linear-sync.md +20 -0
  66. package/skills/implement-plan/references/output-formats.md +17 -2
  67. package/skills/implement-plan/references/plan-inputs.md +23 -4
  68. package/skills/implement-plan/scripts/check-prerequisites.sh +95 -49
  69. package/skills/implement-plan/scripts/parse-dependencies.sh +10 -10
  70. package/skills/init/SKILL.md +77 -42
  71. package/skills/init/references/flag-reference.md +41 -17
  72. package/skills/init/references/project-profile-heuristics.md +3 -0
  73. package/skills/init/references/template-library.md +15 -5
  74. package/skills/init/scripts/profile-project.sh +26 -0
  75. package/skills/init/scripts/render-template.py +2 -2
  76. package/skills/init/templates/AGENTS.md.tmpl +6 -0
  77. package/skills/init/templates/git/gitignore.tmpl +5 -0
  78. package/skills/orchestrate/SKILL.md +17 -2
  79. package/skills/parallel-plan/SKILL.md +14 -8
  80. package/skills/plan/SKILL.md +18 -2
  81. package/skills/plan/references/planning-tracks.md +1 -1
  82. package/skills/plan-workflow/SKILL.md +67 -32
  83. package/skills/plan-workflow/references/checkpoint-messages.md +23 -14
  84. package/skills/plan-workflow/references/plan-structure.md +1 -1
  85. package/skills/plan-workflow/references/planning-agents.md +11 -9
  86. package/skills/plan-workflow/references/research-agents-optimized.md +12 -10
  87. package/skills/plan-workflow/references/research-agents.md +11 -10
  88. package/skills/plan-workflow/scripts/check-prerequisites.sh +50 -11
  89. package/skills/plan-workflow/scripts/check-state.sh +53 -9
  90. package/skills/plan-workflow/scripts/persist-or-fail.sh +21 -7
  91. package/skills/plan-workflow/scripts/validate-analysis-artifacts.sh +28 -14
  92. package/skills/plan-workflow/scripts/validate-research-artifacts.sh +35 -10
  93. package/skills/plan-workflow/scripts/validate-shared.sh +56 -15
  94. package/skills/plan-workflow/scripts/validate-workflow-plan.sh +48 -17
  95. package/skills/pr-autofix/SKILL.md +19 -4
  96. package/skills/pr-autofix/references/output-templates.md +3 -2
  97. package/skills/pr-autofix/scripts/fetch-pr-comments.sh +1 -2
  98. package/skills/pr-autofix/scripts/post-summary.sh +1 -2
  99. package/skills/pr-autofix/scripts/resolve-thread.sh +3 -4
  100. package/skills/prp-implement/SKILL.md +31 -16
  101. package/skills/prp-implement/references/agent-task-prompt.md +5 -2
  102. package/skills/prp-implement/references/detection.md +4 -1
  103. package/skills/prp-implement/references/linear-sync.md +25 -0
  104. package/skills/prp-implement/references/report-output.md +15 -2
  105. package/skills/prp-plan/SKILL.md +62 -30
  106. package/skills/prp-plan/references/enhanced-researchers.md +8 -9
  107. package/skills/prp-plan/scripts/validate-prp-plan.sh +42 -18
  108. package/skills/prp-pr/SKILL.md +14 -1
  109. package/skills/prp-prd/SKILL.md +21 -9
  110. package/skills/prp-spec/SKILL.md +30 -20
  111. package/skills/quick-fix/SKILL.md +6 -4
  112. package/skills/quick-review/SKILL.md +62 -25
  113. package/skills/release-model/scripts/collect-signals.sh +9 -3
  114. package/skills/releaser/scripts/publish-release.sh +6 -3
  115. package/skills/research-to-issues/SKILL.md +33 -14
  116. package/skills/research-to-issues/scripts/validate-prerequisites.sh +45 -23
  117. package/skills/research-to-issues/templates/task-issue.md +4 -0
  118. package/skills/research-to-issues/templates/tracking-issue.md +3 -0
  119. package/skills/review-fix/SKILL.md +96 -14
  120. package/skills/review-fix/references/fix-report.md +10 -10
  121. package/skills/review-fix/references/plan.md +5 -2
  122. package/skills/shared-context/SKILL.md +14 -11
  123. package/skills/visual-plan/SKILL.md +26 -8
  124. package/skills/visual-recap/SKILL.md +1 -1
  125. package/skills/write-docs/scripts/audit-documentation.sh +44 -10
  126. package/skills/write-docs/scripts/generate-doc-index.sh +10 -3
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env bash
2
+ # Write and optionally commit the portable repository artifact-store pointer.
3
+ # workspace/label/project are read indirectly via ${!name} in the validation and merge loops.
4
+ # shellcheck disable=SC2034
5
+ set -euo pipefail
6
+ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd -P)"
7
+ usage() {
8
+ printf '%s\n' 'Usage: artifact-store-pointer.sh --store=linear|local [--linear-workspace=<slug>] [--linear-team=<KEY>] [--linear-label=<label> | --linear-project=<id-or-slug>] [--dry-run] [--no-commit] [--force] [<dir>]'
9
+ }
10
+ die() { printf 'ERROR: %s\n' "$2" >&2; exit "$1"; }
11
+ store='' workspace='' team='' label='' project='' dir=''
12
+ workspace_set=0 team_set=0 label_set=0 project_set=0 dry_run=0 no_commit=0 force=0
13
+ while [[ $# -gt 0 ]]; do
14
+ case "$1" in
15
+ --help|-h) usage; exit 0 ;;
16
+ --store=*) store=${1#*=} ;;
17
+ --linear-workspace=*) workspace=${1#*=}; workspace_set=1 ;;
18
+ --linear-team=*) team=${1#*=}; team_set=1 ;;
19
+ --linear-label=*) label=${1#*=}; label_set=1 ;;
20
+ --linear-project=*) project=${1#*=}; project_set=1 ;;
21
+ --dry-run) dry_run=1 ;;
22
+ --no-commit) no_commit=1 ;;
23
+ --force) force=1 ;;
24
+ -*) die 2 "Unknown option: $1" ;;
25
+ *) [[ -z "$dir" && -n "$1" ]] || die 2 'Expected one directory'; dir=$1 ;;
26
+ esac
27
+ shift
28
+ done
29
+ [[ "$store" == linear || "$store" == local ]] || die 2 '--store must be linear or local'
30
+ value_pattern='^[A-Za-z0-9][A-Za-z0-9._:/@+-]*$'
31
+ for name in workspace label project; do
32
+ set_name="${name}_set"
33
+ if [[ "${!set_name}" == 1 ]]; then
34
+ [[ "${!name}" =~ $value_pattern ]] || die 2 "Invalid --linear-${name} value"
35
+ fi
36
+ done
37
+ if [[ "$team_set" == 1 ]]; then
38
+ [[ "$team" =~ ^[A-Z][A-Z0-9]{0,9}$ ]] || die 2 'Invalid --linear-team value'
39
+ fi
40
+ [[ "$label_set$project_set" != 11 ]] || die 2 '--linear-label and --linear-project are mutually exclusive'
41
+ if [[ "$store" == linear ]]; then
42
+ [[ "$workspace_set$team_set" == 11 && "$label_set$project_set" != 00 ]] || die 2 'Linear store requires --linear-workspace, --linear-team, and --linear-label or --linear-project'
43
+ fi
44
+ dir=${dir:-.}
45
+ [[ "$(git -C "$dir" rev-parse --is-inside-work-tree 2>/dev/null || :)" == true ]] || die 2 'Artifact-store pointer requires a Git work tree'
46
+ root=$(git -C "$dir" rev-parse --show-toplevel)
47
+ root=$(CDPATH='' cd -- "$root" >/dev/null && pwd -P)
48
+ pointer="${root}/.plans-config"
49
+ for path in .plans-config .gitignore .ycc; do
50
+ [[ ! -L "${root}/${path}" ]] || die 2 "Refusing symlinked ${path}"
51
+ done
52
+ [[ ! -e "$pointer" || -f "$pointer" ]] || die 2 '.plans-config must be a regular file'
53
+ [[ ! -e "${root}/.gitignore" || -f "${root}/.gitignore" ]] || die 2 '.gitignore must be a regular file'
54
+ if [[ -f "$pointer" ]] && grep -q $'\r' "$pointer"; then
55
+ die 2 'CRLF .plans-config; convert .plans-config to LF line endings and retry'
56
+ fi
57
+ # Source in the target repository so auto-resolution never consults the caller.
58
+ start_pwd=$PWD
59
+ CDPATH='' cd -- "$root"
60
+ # shellcheck source=resolve-artifact-store.sh
61
+ source "${SCRIPT_DIR}/resolve-artifact-store.sh"
62
+ CDPATH='' cd -- "$start_pwd"
63
+ set -euo pipefail
64
+ keys=(store) values=("$store") seen=(0) old_values=()
65
+ for name in workspace team label project; do
66
+ set_name="${name}_set"
67
+ if [[ "${!set_name}" == 1 ]]; then
68
+ keys+=("linear_${name}"); values+=("${!name}"); seen+=(0)
69
+ fi
70
+ done
71
+ for ((i=0; i<${#keys[@]}; i++)); do
72
+ if old=$(_artifact_config_value "${keys[i]}" "$pointer"); then
73
+ [[ "$old" == "${values[i]}" || "$force" == 1 ]] || die 3 "Conflicting ${keys[i]}: ${old} -> ${values[i]} (use --force)"
74
+ old_values+=("$old")
75
+ else
76
+ old_values+=('')
77
+ fi
78
+ done
79
+ # A label <-> project mapping switch must be explicit: the other key's existing
80
+ # line conflicts, and --force removes it instead of leaving both mappings.
81
+ remove_keys=()
82
+ other_key=''
83
+ if [[ "$label_set$project_set" == 10 ]]; then
84
+ other_key=linear_project
85
+ elif [[ "$label_set$project_set" == 01 ]]; then
86
+ other_key=linear_label
87
+ fi
88
+ if [[ -n "$other_key" && -f "$pointer" ]]; then
89
+ if old=$(_artifact_config_value "$other_key" "$pointer"); then
90
+ if [[ "$force" == 1 ]]; then
91
+ remove_keys=("$other_key")
92
+ elif [[ "$other_key" == linear_project ]]; then
93
+ die 3 'Conflicting linear_project mapping; use --force to switch to --linear-label'
94
+ else
95
+ die 3 'Conflicting linear_label mapping; use --force to switch to --linear-project'
96
+ fi
97
+ fi
98
+ fi
99
+ # Creating a root pointer would make nested, non-local configs inherit its
100
+ # plans_dir. Refuse before changing that resolution unless explicitly forced.
101
+ if [[ ! -e "$pointer" && "$force" == 0 ]]; then
102
+ nested_configs=()
103
+ while IFS= read -r -d '' nested_config; do
104
+ scope=$(_artifact_config_value scope "${root}/${nested_config}") || scope=''
105
+ [[ "$scope" == local ]] || nested_configs+=("$nested_config")
106
+ done < <({
107
+ git -C "$root" ls-files -z --cached -- '*/.plans-config'
108
+ git -C "$root" ls-files -z --others --exclude-standard -- '*/.plans-config'
109
+ } | sort -zu)
110
+ if [[ ${#nested_configs[@]} -gt 0 ]]; then
111
+ printf 'ERROR: Creating a root .plans-config would change plan resolution for nested configs without scope: local:\n' >&2
112
+ printf ' %s\n' "${nested_configs[@]}" >&2
113
+ die 3 'Add scope: local to those configs or rerun with --force.'
114
+ fi
115
+ fi
116
+ # Every refusal runs before any write, for both stores.
117
+ if git -C "$root" check-ignore -q --no-index -- .plans-config; then
118
+ die 4 '.plans-config is ignored; a committed artifact-store pointer cannot be ignored. Remove the ignore rule and retry.'
119
+ fi
120
+ ignore=skipped
121
+ # Dry-run checks coverage without invoking the resolver's write entry point.
122
+ # The actual write always uses the canonical helper, including wider repo rules.
123
+ if [[ "$store" == linear ]]; then
124
+ export ARTIFACT_STORE=linear ARTIFACT_ROOT="$root" ARTIFACT_DIR="${root}/.ycc/artifacts"
125
+ _artifact_require_git_root || die 2 'Cannot ensure repository artifact-cache ignore rule'
126
+ if [[ -e "${root}/.gitignore" ]]; then
127
+ [[ -w "${root}/.gitignore" ]] || die 2 '.gitignore is not writable'
128
+ else
129
+ [[ -w "$root" ]] || die 2 'Repository root is not writable; cannot create .gitignore'
130
+ fi
131
+ coverage=0
132
+ _artifact_gitignore_present || coverage=$?
133
+ case "$coverage" in
134
+ 0) ignore=present ;;
135
+ 1) ignore=added ;;
136
+ 2) die 2 'A negated (!) ignore rule re-includes .ycc/artifacts/ paths; refusing to override it' ;;
137
+ 3) die 2 'Cannot check .ycc/artifacts/ ignore coverage (git check-ignore, .gitignore scan, or TMPDIR scratch failed)' ;;
138
+ *) die 2 'Cannot ensure repository artifact-cache ignore rule' ;;
139
+ esac
140
+ fi
141
+ # Pre-existing uncommitted .plans-config edits (unstaged or staged-only) keep
142
+ # the user's commit boundary: the pointer is written but never committed.
143
+ pointer_dirty=0
144
+ if [[ -f "$pointer" ]]; then
145
+ if git -C "$root" rev-parse -q --verify HEAD >/dev/null 2>&1; then
146
+ if ! git -C "$root" diff --quiet HEAD -- .plans-config || ! git -C "$root" diff --cached --quiet -- .plans-config; then
147
+ pointer_dirty=1
148
+ fi
149
+ fi
150
+ if [[ "$pointer_dirty" == 0 ]] && ! git --literal-pathspecs -C "$root" ls-files --error-unmatch -- .plans-config >/dev/null 2>&1; then
151
+ while IFS= read -r line || [[ -n "$line" ]]; do
152
+ [[ "$line" =~ ^[[:space:]]*(#|$) ]] && continue
153
+ [[ "$line" =~ ^(store|linear_[A-Za-z0-9_]*)[[:space:]]*[:=] ]] || pointer_dirty=1
154
+ done <"$pointer"
155
+ fi
156
+ fi
157
+ planned=''
158
+ if [[ -f "$pointer" ]]; then
159
+ while IFS= read -r line || [[ -n "$line" ]]; do
160
+ drop=0
161
+ if [[ ${#remove_keys[@]} -gt 0 ]]; then
162
+ for remove_key in "${remove_keys[@]}"; do
163
+ if [[ "$line" =~ ^${remove_key}[[:space:]]*[:=] ]]; then drop=1; fi
164
+ done
165
+ fi
166
+ if [[ "$drop" == 0 ]]; then
167
+ for ((i=0; i<${#keys[@]}; i++)); do
168
+ if [[ "$line" =~ ^${keys[i]}[[:space:]]*[:=] ]]; then
169
+ seen[i]=1
170
+ old=${old_values[i]}
171
+ if [[ "$old" != "${values[i]}" ]]; then
172
+ comment=''
173
+ comment_pattern='([[:space:]]*#.*)$'
174
+ if [[ "$line" =~ $comment_pattern ]]; then comment=${BASH_REMATCH[1]}; fi
175
+ line="${keys[i]}: ${values[i]}${comment}"
176
+ fi
177
+ break
178
+ fi
179
+ done
180
+ planned+="${line}"$'\n'
181
+ fi
182
+ done <"$pointer"
183
+ fi
184
+ for ((i=0; i<${#keys[@]}; i++)); do
185
+ if [[ "${seen[i]}" == 0 ]]; then planned+="${keys[i]}: ${values[i]}"$'\n'; fi
186
+ done
187
+ change=created
188
+ if [[ -f "$pointer" ]]; then
189
+ change=updated
190
+ same=1
191
+ for ((i=0; i<${#keys[@]}; i++)); do
192
+ [[ "${seen[i]}" == 1 && "${old_values[i]}" == "${values[i]}" ]] || same=0
193
+ done
194
+ if [[ "$same" == 1 && ${#remove_keys[@]} -eq 0 ]]; then change=unchanged; fi
195
+ fi
196
+ commit=none
197
+ if [[ "$dry_run" == 1 ]]; then
198
+ printf '%s\n' '--- .plans-config (planned) ---'
199
+ printf '%s' "$planned"
200
+ printf '%s\n' '--- end ---' "Plan: ${change} .plans-config; gitignore=${ignore}; commit only eligible pointer paths."
201
+ commit=skipped
202
+ else
203
+ if [[ "$store" == linear ]]; then
204
+ before_ignore=$(if [[ -f "${root}/.gitignore" ]]; then cat "${root}/.gitignore"; fi; printf '\001')
205
+ ensure_artifact_gitignore || die 2 'Cannot ensure repository artifact-cache ignore rule'
206
+ after_ignore=$(cat "${root}/.gitignore" 2>/dev/null || :; printf '\001')
207
+ if [[ "$before_ignore" != "$after_ignore" ]]; then ignore=added; else ignore=present; fi
208
+ fi
209
+ if [[ "$change" != unchanged ]]; then printf '%s' "$planned" >"$pointer"; fi
210
+ paths=()
211
+ if ! git -C "$root" ls-files --error-unmatch -- .plans-config >/dev/null 2>&1 || ! git -C "$root" diff --quiet HEAD -- .plans-config; then paths+=(.plans-config); fi
212
+ if [[ "$store" == linear && -f "${root}/.gitignore" ]]; then
213
+ base=$(git -C "$root" show HEAD:.gitignore 2>/dev/null && printf '\001') || base=$'\001'
214
+ base=${base%$'\001'}
215
+ expected=$base
216
+ if [[ -n "$expected" && "$expected" != *$'\n' ]]; then expected+=$'\n'; fi
217
+ expected+=$'.ycc/artifacts/\n'
218
+ if ! git -C "$root" ls-files --error-unmatch -- .gitignore >/dev/null 2>&1 || ! git -C "$root" diff --quiet HEAD -- .gitignore; then
219
+ if cmp -s "${root}/.gitignore" <(printf '%s' "$expected"); then
220
+ paths+=(.gitignore)
221
+ else
222
+ printf 'WARNING: .gitignore has unrelated changes; committing only .plans-config.\n' >&2
223
+ fi
224
+ fi
225
+ fi
226
+ if [[ "$no_commit" == 1 ]]; then
227
+ commit=skipped
228
+ elif [[ "$pointer_dirty" == 1 ]]; then
229
+ printf 'WARNING: .plans-config has pre-existing uncommitted changes; leaving the pointer commit to you (commit=skipped).\n' >&2
230
+ commit=skipped
231
+ elif [[ ${#paths[@]} -gt 0 ]]; then
232
+ if ! git -C "$root" add -- "${paths[@]}" || ! git -C "$root" commit -m "chore(ycc): configure ${store/linear/Linear} artifact store" -- "${paths[@]}"; then
233
+ if git -C "$root" rev-parse -q --verify HEAD >/dev/null 2>&1; then
234
+ git -C "$root" reset -q -- "${paths[@]}" || :
235
+ else
236
+ git -C "$root" rm --cached -q --ignore-unmatch -- "${paths[@]}" || :
237
+ fi
238
+ die 5 'Artifact-store pointer commit failed; files remain written and staged pointer paths were unstaged (Git error above).'
239
+ fi
240
+ commit=$(git -C "$root" rev-parse --short HEAD)
241
+ elif [[ "$store" == local ]]; then
242
+ commit=skipped
243
+ fi
244
+ fi
245
+ printf 'pointer=%s\npointer_change=%s\ngitignore=%s\ncommit=%s\n' "$pointer" "$change" "$ignore" "$commit"
@@ -231,8 +231,13 @@ has_pr_checks() {
231
231
  fi
232
232
 
233
233
  # Strategy 2: plain `gh pr checks` text output (one row per check). Works on
234
- # all supported gh versions and survives shape changes in --json.
235
- if gh pr checks "$pr" 2>/dev/null | grep -qE '^[^[:space:]]'; then
234
+ # all supported gh versions and survives shape changes in --json. Capture the
235
+ # output and match with a here-string, not `gh ... | grep -q`: under pipefail
236
+ # the early-exiting grep SIGPIPEs gh on long check lists (YAN-1587). gh exits
237
+ # non-zero for failing/pending checks, which still counts as "has checks".
238
+ local rows
239
+ rows="$(gh pr checks "$pr" 2>/dev/null || true)"
240
+ if grep -qE '^[^[:space:]]' <<<"$rows"; then
236
241
  return 0
237
242
  fi
238
243
 
@@ -270,7 +275,7 @@ extract_step_name() {
270
275
  # gh run view --log-failed output has lines like:
271
276
  # <job-name> <step-name> <timestamp> <log-line>
272
277
  local step
273
- step="$(printf '%s\n' "$log_content" | grep -m1 '^\S' | awk '{print $2}' | head -n1 || printf '')"
278
+ step="$(grep -m1 '^\S' <<<"$log_content" | awk '{print $2}' | head -n1 || printf '')"
274
279
  if [[ -z "$step" ]]; then
275
280
  step="unknown-step"
276
281
  fi
@@ -365,7 +370,7 @@ main() {
365
370
  for pair in "max-pushes:$max_pushes" "max-same-failure:$max_same_failure" "timeout-min:$timeout_min" "pr:$pr"; do
366
371
  local flag_n="${pair%%:*}"
367
372
  local val_n="${pair#*:}"
368
- if ! printf '%s' "$val_n" | grep -qE '^[0-9]+$'; then
373
+ if ! grep -qE '^[0-9]+$' <<<"$val_n"; then
369
374
  printf 'ci-monitor.sh: --%s must be a non-negative integer, got: %s\n' "$flag_n" "$val_n" >&2
370
375
  exit 1
371
376
  fi
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env bash
2
+ # Collect candidate Linear keys only; callers verify them before PR linking.
3
+ set -euo pipefail
4
+ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd -P)"
5
+ base='' team='' team_set=0 start_dir=''
6
+ while [[ $# -gt 0 ]]; do
7
+ case "$1" in
8
+ --base)
9
+ if [[ $# -lt 2 || "$2" == --* ]]; then usage; exit 1; fi
10
+ if [[ "$1" == --base ]]; then
11
+ [[ -n "$2" ]] || { usage; exit 1; }
12
+ base=$2
13
+ else
14
+ team=$2; team_set=1
15
+ fi
16
+ shift
17
+ ;;
18
+ --*) usage; exit 1 ;;
19
+ *)
20
+ [[ -z "$start_dir" && -n "$1" ]] || { usage; exit 1; }
21
+ start_dir=$1
22
+ ;;
23
+ esac
24
+ shift
25
+ done
26
+ start_dir=${start_dir:-$PWD}
27
+ cd -- "$start_dir" 2>/dev/null || { usage; exit 1; }
28
+ # shellcheck source=resolve-artifact-store.sh
29
+ source "${SCRIPT_DIR}/resolve-artifact-store.sh"
30
+ if [[ "$team_set" == 0 ]]; then team=${ARTIFACT_LINEAR_TEAM:-}; fi
31
+ team=$(printf '%s' "$team" | tr '[:lower:]' '[:upper:]')
32
+ [[ -z "$team" || "$team" =~ ^[A-Z0-9]+$ ]] || { usage; exit 1; }
33
+ # Apply an explicit team override to the branch matcher as well as commit keys.
34
+ if [[ "$team_set" == 1 ]]; then ARTIFACT_LINEAR_HINT=$(_artifact_branch_hint "$PWD" "$team"); fi
35
+ # Buffer candidates so a later closing keyword upgrades an earlier Refs row
36
+ # without changing its first-seen position or source.
37
+ {
38
+ if [[ -n "${ARTIFACT_LINEAR_HINT:-}" ]]; then
39
+ printf '%s\tbranch\tcloses\n' "$ARTIFACT_LINEAR_HINT"
40
+ fi
41
+ if [[ -n "$base" ]] && git show-ref --verify --quiet "refs/remotes/origin/$base"; then
42
+ base="refs/remotes/origin/$base"
43
+ fi
44
+ if [[ -z "$base" ]]; then
45
+ for candidate in origin/HEAD origin/main main; do
46
+ if base=$(git merge-base HEAD "$candidate" 2>/dev/null); then break; fi
47
+ base=''
48
+ done
49
+ fi
50
+ if [[ -n "$base" ]] && git rev-parse --verify "${base}^{commit}" >/dev/null 2>&1; then
51
+ git log --format=%B "${base}..HEAD" -- 2>/dev/null | awk '
52
+ {
53
+ text = $0
54
+ while (match(tolower(text), /(^|[^a-z0-9_])(closes|fixes|resolves|refs)[:[:space:]]+[a-z][a-z0-9]+-[0-9]+/)) {
55
+ end = RSTART + RLENGTH
56
+ matched = substr(text, RSTART, RLENGTH)
57
+ key = matched
58
+ sub(/^.*[:[:space:]]/, "", key)
59
+ prefix = key
60
+ sub(/-[0-9]+$/, "", prefix)
61
+ action = (tolower(matched) ~ /(^|[^a-z0-9_])refs[:[:space:]]/) ? "refs" : "closes"
62
+ if (length(prefix) <= 10 && substr(text, end, 1) !~ /[A-Za-z0-9]/)
63
+ print toupper(key) "\tcommit\t" action
64
+ text = substr(text, end)
65
+ }
66
+ }
67
+ '
68
+ else
69
+ printf '%s\n' 'Warning: skipping Linear commit scan: no resolvable base.' >&2
70
+ fi
71
+ } | awk -F '\t' -v team="$team" '
72
+ team != "" && index($1, team "-") != 1 { next }
73
+ !seen[$1]++ { keys[++count] = $1; source[$1] = $2; action[$1] = $3 }
74
+ $3 == "closes" { action[$1] = "closes" }
75
+ END { for (i = 1; i <= count; i++) print keys[i] "\t" source[keys[i]] "\t" action[keys[i]] }
76
+ '
77
+ exit 0
@@ -30,42 +30,45 @@ _YCC_CI_CLASSIFY_SOURCED=1
30
30
  classify_failure() {
31
31
  local log_content="$1"
32
32
 
33
- # Fixable categories (pattern-matched in priority order)
34
- if printf '%s\n' "$log_content" | grep -qiE '(eslint|pylint|ruff|flake8|rubocop|golangci|lint(ing)?[: ]|linter (error|fail)|SC[0-9]{4})'; then
33
+ # Match the log blob with here-strings, not `printf | grep -q`: CI logs are
34
+ # regularly larger than the 64 KiB pipe buffer, so under pipefail the
35
+ # early-exiting grep SIGPIPEs the writer and a present category signature
36
+ # reads as absent (YAN-1587).
37
+ if grep -qiE '(eslint|pylint|ruff|flake8|rubocop|golangci|lint(ing)?[: ]|linter (error|fail)|SC[0-9]{4})' <<<"$log_content"; then
35
38
  printf 'lint'
36
39
  return
37
40
  fi
38
- if printf '%s\n' "$log_content" | grep -qiE '(prettier|black|gofmt|rustfmt|format(ting)?[: ]|autoformat|code style)'; then
41
+ if grep -qiE '(prettier|black|gofmt|rustfmt|format(ting)?[: ]|autoformat|code style)' <<<"$log_content"; then
39
42
  printf 'format'
40
43
  return
41
44
  fi
42
- if printf '%s\n' "$log_content" | grep -qiE '(tsc|mypy|pyright|type.check|type error|TypeScript error|type-check|typecheck)'; then
45
+ if grep -qiE '(tsc|mypy|pyright|type.check|type error|TypeScript error|type-check|typecheck)' <<<"$log_content"; then
43
46
  printf 'type-check'
44
47
  return
45
48
  fi
46
- if printf '%s\n' "$log_content" | grep -qiE '(jest|pytest|cargo test|go test|rspec|mocha|vitest|unit.test|test (fail|error)|FAIL.*\.test\.)'; then
49
+ if grep -qiE '(jest|pytest|cargo test|go test|rspec|mocha|vitest|unit.test|test (fail|error)|FAIL.*\.test\.)' <<<"$log_content"; then
47
50
  printf 'unit-test'
48
51
  return
49
52
  fi
50
- if printf '%s\n' "$log_content" | grep -qiE '(npm (run )?build|cargo build|go build|webpack|vite build|next build|build (fail|error)|compilation failed)'; then
53
+ if grep -qiE '(npm (run )?build|cargo build|go build|webpack|vite build|next build|build (fail|error)|compilation failed)' <<<"$log_content"; then
51
54
  printf 'build'
52
55
  return
53
56
  fi
54
57
 
55
58
  # Non-fixable categories
56
- if printf '%s\n' "$log_content" | grep -qiE '(integration.test|e2e|end.to.end|cypress|playwright)'; then
59
+ if grep -qiE '(integration.test|e2e|end.to.end|cypress|playwright)' <<<"$log_content"; then
57
60
  printf 'integration-test'
58
61
  return
59
62
  fi
60
- if printf '%s\n' "$log_content" | grep -qiE '(terraform|ansible|kubernetes|k8s|helm|infra(structure)?|deploy(ment)?|provisioning)'; then
63
+ if grep -qiE '(terraform|ansible|kubernetes|k8s|helm|infra(structure)?|deploy(ment)?|provisioning)' <<<"$log_content"; then
61
64
  printf 'infra'
62
65
  return
63
66
  fi
64
- if printf '%s\n' "$log_content" | grep -qiE '(secret (not found|missing|undefined)|API.?key (not|missing)|token (not found|missing|expired)|credentials missing|env.*not set)'; then
67
+ if grep -qiE '(secret (not found|missing|undefined)|API.?key (not|missing)|token (not found|missing|expired)|credentials missing|env.*not set)' <<<"$log_content"; then
65
68
  printf 'secret-missing'
66
69
  return
67
70
  fi
68
- if printf '%s\n' "$log_content" | grep -qiE '(flake|intermittent|timeout|rate.limit|network error|connection refused|socket hang|ECONNRESET|ETIMEDOUT)'; then
71
+ if grep -qiE '(flake|intermittent|timeout|rate.limit|network error|connection refused|socket hang|ECONNRESET|ETIMEDOUT)' <<<"$log_content"; then
69
72
  printf 'flake-suspected'
70
73
  return
71
74
  fi
@@ -104,10 +104,15 @@ forge_host_is_gitlab() {
104
104
  # forge_host_in_tea <host> — true if the host matches a configured `tea` login
105
105
  # (Gitea/Forgejo). Reads `tea login list` so no network call is made.
106
106
  forge_host_in_tea() {
107
- local host="$1"
107
+ local host="$1" logins
108
+ [[ -n "$host" ]] || return 1
108
109
  command -v tea >/dev/null 2>&1 || return 1
109
110
  # `tea login list` prints a table containing the URL and SSH host columns.
110
- tea login list 2>/dev/null | grep -qiF "$host"
111
+ # Capture it and match with a here-string, not `tea login list | grep -q`:
112
+ # under pipefail the early-exiting grep SIGPIPEs tea and a configured login
113
+ # reads as absent (YAN-1607).
114
+ logins="$(tea login list 2>/dev/null || true)"
115
+ grep -qiF -- "$host" <<<"$logins"
111
116
  }
112
117
 
113
118
  # ---------------------------------------------------------------------------
@@ -129,7 +134,7 @@ forge_probe_gitea_family() {
129
134
  *version*)
130
135
  local server
131
136
  server="$(curl -fsSLI --max-time 5 "https://${host}/api/v1/version" 2>/dev/null | tr -d '\r')"
132
- if printf '%s' "$server" | grep -qi 'forgejo'; then
137
+ if grep -qi 'forgejo' <<<"$server"; then
133
138
  printf 'forgejo'
134
139
  else
135
140
  printf 'gitea'
@@ -221,7 +226,11 @@ forge_auth_ok() {
221
226
  github) command -v gh >/dev/null 2>&1 && gh auth status >/dev/null 2>&1 ;;
222
227
  forgejo|gitea)
223
228
  # `tea` has no `auth status`; a configured login list is the local signal.
224
- command -v tea >/dev/null 2>&1 && tea login list 2>/dev/null | grep -q '://'
229
+ # Captured, not piped into grep -q (SIGPIPE under pipefail; YAN-1607).
230
+ command -v tea >/dev/null 2>&1 || return 1
231
+ local logins
232
+ logins="$(tea login list 2>/dev/null || true)"
233
+ grep -q '://' <<<"$logins"
225
234
  ;;
226
235
  gitlab) command -v glab >/dev/null 2>&1 && glab auth status >/dev/null 2>&1 ;;
227
236
  *) return 1 ;;
@@ -9,7 +9,9 @@
9
9
  # Behavior:
10
10
  # - Rejects an unrelated dirty checkout (only plan-artifact paths allowed:
11
11
  # docs/plans/<slug>/*, docs/orchestration/<slug>*,
12
- # docs/prps/{plans,specs,prds}/<slug>*).
12
+ # docs/prps/{plans,specs,prds}/<slug>*, from the repo root or the cwd,
13
+ # plus a .gitignore whose only change appends one .ycc/artifacts/ rule
14
+ # line).
13
15
  # - On feat/<slug>: idempotent no-op.
14
16
  # - On trunk (main/master/trunk/develop, plus the RELEASING.md trunk) and
15
17
  # feat/<slug> exists: switch to it.
@@ -162,9 +164,99 @@ fi
162
164
  #
163
165
  # Allow plan-artifact paths; reject anything else.
164
166
 
165
- is_plan_artifact() {
166
- local path="$1"
167
- case "$path" in
167
+ # Succeed when content $2 equals $1 or $1 plus exactly one trailing cache rule
168
+ # line, as `--ensure` writes it, including after a missing final newline. $1
169
+ # may already hold the rule: a later `!` line can void it, so the resolver
170
+ # appends another.
171
+ is_head_plus_rule() {
172
+ local head="$1" content="$2" rest rule='^/?\.ycc/artifacts/?$'
173
+ [[ "$content" == "$head" ]] && return 0
174
+ if [[ -n "$head" && "$head" != *$'\n' ]]; then head="${head}"$'\n'; fi
175
+ [[ "$content" == "$head"* ]] || return 1
176
+ rest=${content#"$head"}
177
+ rest=${rest%$'\n'}
178
+ [[ "$rest" != *$'\n'* && "$rest" =~ $rule ]]
179
+ }
180
+
181
+ REPO_ROOT="$(git rev-parse --show-toplevel)"
182
+ # cwd relative to REPO_ROOT ("" at the root, else ending in "/").
183
+ REPO_PREFIX="$(git rev-parse --show-prefix)"
184
+
185
+ # is_blob_text <oid> <text> — succeed when <text> hashes to blob <oid>, so
186
+ # content bash read into a string lost no NUL bytes on the way.
187
+ is_blob_text() {
188
+ [[ "$1" == "$(printf '%s' "$2" | git -C "$REPO_ROOT" hash-object --no-filters --stdin)" ]]
189
+ }
190
+
191
+ # Accept a .gitignore (path relative to REPO_ROOT) whose working-tree and
192
+ # stage-0 contents each equal its HEAD content (empty when new) or HEAD plus
193
+ # one cache rule line, and at least one differs from HEAD. The working tree
194
+ # must be a regular non-symlink file whose mode matches the index (or HEAD,
195
+ # else 100644); the index mode must be 100644 or 100755 and equal HEAD's.
196
+ # Refuse conflict stages and staged deletions; no index entry for a path new
197
+ # to HEAD counts as equal to HEAD. Blobs are read by oid so a path like
198
+ # `0:x/.gitignore` is never parsed as a revision. The working tree passes when
199
+ # either its bytes or, under a line-ending conversion (core.autocrlf, eol=crlf,
200
+ # text=auto), the content Git's clean conversion produces is HEAD or HEAD plus
201
+ # the rule; the latter only when that content is the bytes with CRLF turned
202
+ # into LF. Content holding NUL bytes, which bash strings drop, is refused.
203
+ is_artifact_gitignore() {
204
+ local path="$1" file head='' index work norm entry mode type oid stage
205
+ local head_mode='' index_mode='' index_oid='' work_mode clean_oid
206
+ file="$REPO_ROOT/$path"
207
+ [[ -f "$file" && ! -L "$file" ]] || return 1
208
+ # The x sentinel keeps trailing newlines that command substitution strips.
209
+ work=$(cat -- "$file" && printf x) || return 1
210
+ work=${work%x}
211
+ oid=$(git -C "$REPO_ROOT" hash-object --no-filters -- "$path") || return 1
212
+ is_blob_text "$oid" "$work" || return 1
213
+ # ls-tree -z: "<mode> <type> <oid>\t<path>".
214
+ while IFS= read -r -d '' entry; do
215
+ [[ "${entry#*$'\t'}" == "$path" ]] || continue
216
+ read -r mode type oid <<<"${entry%%$'\t'*}"
217
+ [[ "$type" == blob ]] || return 1
218
+ head_mode=$mode
219
+ head=$(git -C "$REPO_ROOT" cat-file blob "$oid" && printf x) || return 1
220
+ head=${head%x}
221
+ is_blob_text "$oid" "$head" || return 1
222
+ done < <(git -C "$REPO_ROOT" --literal-pathspecs ls-tree -z HEAD -- "$path" 2>/dev/null)
223
+ # ls-files -s -z: "<mode> <oid> <stage>\t<path>", one entry per stage.
224
+ while IFS= read -r -d '' entry; do
225
+ [[ "${entry#*$'\t'}" == "$path" ]] || continue
226
+ read -r mode oid stage <<<"${entry%%$'\t'*}"
227
+ [[ "$stage" == 0 && -z "$index_oid" ]] || return 1
228
+ index_mode=$mode index_oid=$oid
229
+ done < <(git -C "$REPO_ROOT" --literal-pathspecs ls-files -s -z -- "$path")
230
+ index=$head
231
+ if [[ -n "$index_oid" ]]; then
232
+ [[ "$index_mode" == 100644 || "$index_mode" == 100755 ]] || return 1
233
+ [[ -z "$head_mode" || "$index_mode" == "$head_mode" ]] || return 1
234
+ index=$(git -C "$REPO_ROOT" cat-file blob "$index_oid" && printf x) || return 1
235
+ index=${index%x}
236
+ is_blob_text "$index_oid" "$index" || return 1
237
+ elif [[ -n "$head_mode" ]]; then
238
+ return 1
239
+ fi
240
+ # diff-files -z --raw: ":<srcmode> <dstmode> <srcoid> <dstoid> <status>\0".
241
+ if IFS= read -r -d '' entry < <(git -C "$REPO_ROOT" --literal-pathspecs diff-files -z --raw -- "$path"); then
242
+ read -r _ work_mode _ <<<"${entry#:}"
243
+ [[ "$work_mode" == "${index_mode:-${head_mode:-100644}}" ]] || return 1
244
+ fi
245
+ is_head_plus_rule "$head" "$index" || return 1
246
+ if ! is_head_plus_rule "$head" "$work"; then
247
+ # Only a clean conversion that just turns CRLF into LF may qualify.
248
+ norm=${work//$'\r\n'/$'\n'}
249
+ [[ "$norm" != "$work" ]] || return 1
250
+ clean_oid=$(git -C "$REPO_ROOT" hash-object --path="$path" -- "$path") || return 1
251
+ is_blob_text "$clean_oid" "$norm" && is_head_plus_rule "$head" "$norm" || return 1
252
+ work=$norm
253
+ fi
254
+ [[ "$work" != "$head" || "$index" != "$head" ]]
255
+ }
256
+
257
+ # Plan-artifact paths relative to the directory the plan was written from.
258
+ is_plan_path() {
259
+ case "$1" in
168
260
  docs/plans/"${FEATURE_SLUG}"/*) return 0 ;;
169
261
  docs/orchestration/"${FEATURE_SLUG}"*) return 0 ;;
170
262
  docs/prps/plans/"${FEATURE_SLUG}"*) return 0 ;;
@@ -174,23 +266,39 @@ is_plan_artifact() {
174
266
  esac
175
267
  }
176
268
 
269
+ # $1 is root-relative. Plan paths match from the root or, for package-local
270
+ # (`scope: local`) plans, from the cwd; .gitignore checks stay root-relative.
271
+ is_plan_artifact() {
272
+ local path="$1"
273
+ is_plan_path "$path" && return 0
274
+ if [[ -n "$REPO_PREFIX" && "$path" == "$REPO_PREFIX"* ]]; then
275
+ is_plan_path "${path#"$REPO_PREFIX"}" && return 0
276
+ fi
277
+ case "$path" in
278
+ .gitignore|*/.gitignore) is_artifact_gitignore "$path" ;;
279
+ *) return 1 ;;
280
+ esac
281
+ }
282
+
177
283
  UNRELATED_DIRTY=()
284
+ # NUL-separated root-relative paths; --no-renames reports both sides of a
285
+ # rename so a staged deletion cannot hide behind an allowed new path.
178
286
  collect_dirty() {
179
287
  # Untracked files (file-level — avoids `?? dir/` collapsed entries from
180
288
  # `git status --porcelain` and `--untracked-files=all`'s memory cost).
181
- git ls-files --others --exclude-standard
289
+ git -C "$REPO_ROOT" ls-files -z --others --exclude-standard
182
290
  # Modified-but-unstaged tracked files.
183
- git diff --name-only
184
- # Staged tracked files (added/modified/renamed/deleted).
185
- git diff --name-only --cached
291
+ git -C "$REPO_ROOT" diff -z --name-only --no-renames
292
+ # Staged tracked files (added/modified/deleted).
293
+ git -C "$REPO_ROOT" diff -z --name-only --no-renames --cached
186
294
  }
187
295
 
188
- while IFS= read -r path; do
296
+ while IFS= read -r -d '' path; do
189
297
  [[ -z "$path" ]] && continue
190
298
  if ! is_plan_artifact "$path"; then
191
299
  UNRELATED_DIRTY+=("$path")
192
300
  fi
193
- done < <(collect_dirty | sort -u)
301
+ done < <(collect_dirty | sort -zu)
194
302
 
195
303
  if (( ${#UNRELATED_DIRTY[@]} > 0 )); then
196
304
  _error "working tree has unrelated changes; stash or commit them first:"
@@ -371,7 +371,7 @@ run_conclusion() {
371
371
  extract_step_name() {
372
372
  local log_content="$1"
373
373
  local step
374
- step="$(printf '%s\n' "$log_content" | grep -m1 '^\S' | awk '{print $2}' | head -n1 || printf '')"
374
+ step="$(grep -m1 '^\S' <<<"$log_content" | awk '{print $2}' | head -n1 || printf '')"
375
375
  if [[ -z "$step" ]]; then
376
376
  step="unknown-step"
377
377
  fi
@@ -429,7 +429,7 @@ main() {
429
429
  for pair in "max-pushes:$max_pushes" "max-same-failure:$max_same_failure" "timeout-min:$timeout_min"; do
430
430
  local flag_n="${pair%%:*}"
431
431
  local val_n="${pair#*:}"
432
- if ! printf '%s' "$val_n" | grep -qE '^[0-9]+$'; then
432
+ if ! grep -qE '^[0-9]+$' <<<"$val_n"; then
433
433
  printf 'release-ci-monitor.sh: --%s must be a non-negative integer, got: %s\n' "$flag_n" "$val_n" >&2
434
434
  exit 1
435
435
  fi
@@ -249,7 +249,7 @@ print_human_section() {
249
249
  else
250
250
  echo "- ${name}: FAIL"
251
251
  if [[ -n "${COMBINED[$i]}" ]]; then
252
- while IFS= read -r line; do printf ' %s\n' "$line"; done < <(printf '%s\n' "${COMBINED[$i]}" | head -3)
252
+ while IFS= read -r line; do printf ' %s\n' "$line"; done < <(head -n 3 <<<"${COMBINED[$i]}")
253
253
  echo " ---"
254
254
  while IFS= read -r line; do printf ' %s\n' "$line"; done <<< "${COMBINED[$i]}"
255
255
  fi