@yandy-r/ycc-opencode 6.1.0 → 6.2.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 (119) 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/package.json +1 -1
  9. package/shared/references/artifact-store.md +613 -0
  10. package/shared/references/branch-prep.md +2 -0
  11. package/shared/references/forge-detection.md +3 -2
  12. package/shared/references/review-artifact-format.md +13 -6
  13. package/shared/references/review-checklist.md +3 -2
  14. package/shared/references/review-dispatch.md +15 -10
  15. package/shared/references/target-capability-matrix.md +42 -6
  16. package/shared/references/visual-mode.md +19 -13
  17. package/shared/references/worktree-strategy.md +12 -8
  18. package/shared/scripts/artifact-body.sh +71 -0
  19. package/shared/scripts/artifact-store-pointer.sh +245 -0
  20. package/shared/scripts/ci-monitor.sh +9 -4
  21. package/shared/scripts/collect-linear-keys.sh +77 -0
  22. package/shared/scripts/lib/ci-classify.sh +13 -10
  23. package/shared/scripts/lib/forge.sh +13 -4
  24. package/shared/scripts/prepare-feature-branch.sh +96 -10
  25. package/shared/scripts/release-ci-monitor.sh +2 -2
  26. package/shared/scripts/report-bundle-drift.sh +1 -1
  27. package/shared/scripts/resolve-artifact-store.sh +636 -0
  28. package/shared/scripts/validate-file-paths.sh +11 -4
  29. package/skills/blueprint/SKILL.md +48 -13
  30. package/skills/clean/SKILL.md +1 -1
  31. package/skills/clean/scripts/detect-project-type.sh +2 -2
  32. package/skills/clean/scripts/generate-report.sh +34 -5
  33. package/skills/clean/scripts/validate-safety.sh +9 -6
  34. package/skills/code-report/SKILL.md +26 -14
  35. package/skills/code-report/scripts/check-prerequisites.sh +72 -12
  36. package/skills/code-report/templates/report-structure.md +1 -1
  37. package/skills/code-review/SKILL.md +68 -17
  38. package/skills/code-review/references/pr-procedure.md +28 -15
  39. package/skills/compatibility-audit/scripts/audit-target-features.sh +1 -1
  40. package/skills/deep-research/SKILL.md +28 -5
  41. package/skills/deep-research/references/completion-summary-template.md +3 -2
  42. package/skills/deep-research/scripts/validate-research.sh +8 -2
  43. package/skills/feature-research/SKILL.md +48 -25
  44. package/skills/feature-research/scripts/validate-research.sh +51 -12
  45. package/skills/feature-research/scripts/validate-spec.sh +53 -22
  46. package/skills/feature-research/templates/research-agents.md +15 -14
  47. package/skills/feature-research/templates/spec-structure.md +5 -0
  48. package/skills/formatters/scripts/apply-aliases.sh +3 -1
  49. package/skills/formatters/scripts/apply-ci.sh +3 -1
  50. package/skills/git-workflow/SKILL.md +2 -1
  51. package/skills/git-workflow/references/pr-creation.md +10 -0
  52. package/skills/git-workflow/scripts/analyze-changes.sh +21 -11
  53. package/skills/git-workflow/scripts/create-pr.sh +51 -6
  54. package/skills/git-workflow/scripts/validate-commit.sh +26 -14
  55. package/skills/hooks-workflow/scripts/verify-hooks.sh +1 -1
  56. package/skills/implement-plan/SKILL.md +35 -16
  57. package/skills/implement-plan/references/agent-task-prompt.md +8 -5
  58. package/skills/implement-plan/references/linear-sync.md +20 -0
  59. package/skills/implement-plan/references/output-formats.md +17 -2
  60. package/skills/implement-plan/references/plan-inputs.md +23 -4
  61. package/skills/implement-plan/scripts/check-prerequisites.sh +95 -49
  62. package/skills/implement-plan/scripts/parse-dependencies.sh +10 -10
  63. package/skills/init/SKILL.md +77 -42
  64. package/skills/init/references/flag-reference.md +41 -17
  65. package/skills/init/references/project-profile-heuristics.md +3 -0
  66. package/skills/init/references/template-library.md +15 -5
  67. package/skills/init/scripts/profile-project.sh +26 -0
  68. package/skills/init/scripts/render-template.py +2 -2
  69. package/skills/init/templates/AGENTS.md.tmpl +6 -0
  70. package/skills/init/templates/git/gitignore.tmpl +5 -0
  71. package/skills/orchestrate/SKILL.md +17 -2
  72. package/skills/parallel-plan/SKILL.md +14 -8
  73. package/skills/plan/SKILL.md +18 -2
  74. package/skills/plan/references/planning-tracks.md +1 -1
  75. package/skills/plan-workflow/SKILL.md +67 -32
  76. package/skills/plan-workflow/references/checkpoint-messages.md +23 -14
  77. package/skills/plan-workflow/references/plan-structure.md +1 -1
  78. package/skills/plan-workflow/references/planning-agents.md +11 -9
  79. package/skills/plan-workflow/references/research-agents-optimized.md +12 -10
  80. package/skills/plan-workflow/references/research-agents.md +11 -10
  81. package/skills/plan-workflow/scripts/check-prerequisites.sh +50 -11
  82. package/skills/plan-workflow/scripts/check-state.sh +53 -9
  83. package/skills/plan-workflow/scripts/persist-or-fail.sh +21 -7
  84. package/skills/plan-workflow/scripts/validate-analysis-artifacts.sh +28 -14
  85. package/skills/plan-workflow/scripts/validate-research-artifacts.sh +35 -10
  86. package/skills/plan-workflow/scripts/validate-shared.sh +56 -15
  87. package/skills/plan-workflow/scripts/validate-workflow-plan.sh +48 -17
  88. package/skills/pr-autofix/SKILL.md +19 -4
  89. package/skills/pr-autofix/references/output-templates.md +3 -2
  90. package/skills/pr-autofix/scripts/fetch-pr-comments.sh +1 -2
  91. package/skills/pr-autofix/scripts/post-summary.sh +1 -2
  92. package/skills/pr-autofix/scripts/resolve-thread.sh +3 -4
  93. package/skills/prp-implement/SKILL.md +31 -16
  94. package/skills/prp-implement/references/agent-task-prompt.md +5 -2
  95. package/skills/prp-implement/references/detection.md +4 -1
  96. package/skills/prp-implement/references/linear-sync.md +25 -0
  97. package/skills/prp-implement/references/report-output.md +15 -2
  98. package/skills/prp-plan/SKILL.md +62 -30
  99. package/skills/prp-plan/references/enhanced-researchers.md +8 -9
  100. package/skills/prp-plan/scripts/validate-prp-plan.sh +42 -18
  101. package/skills/prp-pr/SKILL.md +14 -1
  102. package/skills/prp-prd/SKILL.md +21 -9
  103. package/skills/prp-spec/SKILL.md +30 -20
  104. package/skills/quick-fix/SKILL.md +6 -4
  105. package/skills/quick-review/SKILL.md +62 -25
  106. package/skills/release-model/scripts/collect-signals.sh +9 -3
  107. package/skills/releaser/scripts/publish-release.sh +6 -3
  108. package/skills/research-to-issues/SKILL.md +33 -14
  109. package/skills/research-to-issues/scripts/validate-prerequisites.sh +45 -23
  110. package/skills/research-to-issues/templates/task-issue.md +4 -0
  111. package/skills/research-to-issues/templates/tracking-issue.md +3 -0
  112. package/skills/review-fix/SKILL.md +96 -14
  113. package/skills/review-fix/references/fix-report.md +10 -10
  114. package/skills/review-fix/references/plan.md +5 -2
  115. package/skills/shared-context/SKILL.md +14 -11
  116. package/skills/visual-plan/SKILL.md +26 -8
  117. package/skills/visual-recap/SKILL.md +1 -1
  118. package/skills/write-docs/scripts/audit-documentation.sh +44 -10
  119. package/skills/write-docs/scripts/generate-doc-index.sh +10 -3
@@ -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,77 @@ 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
+ # Accept a .gitignore (path relative to REPO_ROOT) whose working-tree and
186
+ # stage-0 contents each equal its HEAD content (empty when new) or HEAD plus
187
+ # one cache rule line, and at least one differs from HEAD. The working tree
188
+ # must be a regular non-symlink file whose mode matches the index (or HEAD,
189
+ # else 100644); the index mode must be 100644 or 100755 and equal HEAD's.
190
+ # Refuse conflict stages and staged deletions; no index entry for a path new
191
+ # to HEAD counts as equal to HEAD. Blobs are read by oid so a path like
192
+ # `0:x/.gitignore` is never parsed as a revision.
193
+ is_artifact_gitignore() {
194
+ local path="$1" file head='' index work entry mode type oid stage
195
+ local head_mode='' index_mode='' index_oid='' work_mode
196
+ file="$REPO_ROOT/$path"
197
+ [[ -f "$file" && ! -L "$file" ]] || return 1
198
+ # The x sentinel keeps trailing newlines that command substitution strips.
199
+ work=$(cat -- "$file" && printf x) || return 1
200
+ work=${work%x}
201
+ # ls-tree -z: "<mode> <type> <oid>\t<path>".
202
+ while IFS= read -r -d '' entry; do
203
+ [[ "${entry#*$'\t'}" == "$path" ]] || continue
204
+ read -r mode type oid <<<"${entry%%$'\t'*}"
205
+ [[ "$type" == blob ]] || return 1
206
+ head_mode=$mode
207
+ head=$(git -C "$REPO_ROOT" cat-file blob "$oid" && printf x) || return 1
208
+ head=${head%x}
209
+ done < <(git -C "$REPO_ROOT" --literal-pathspecs ls-tree -z HEAD -- "$path" 2>/dev/null)
210
+ # ls-files -s -z: "<mode> <oid> <stage>\t<path>", one entry per stage.
211
+ while IFS= read -r -d '' entry; do
212
+ [[ "${entry#*$'\t'}" == "$path" ]] || continue
213
+ read -r mode oid stage <<<"${entry%%$'\t'*}"
214
+ [[ "$stage" == 0 && -z "$index_oid" ]] || return 1
215
+ index_mode=$mode index_oid=$oid
216
+ done < <(git -C "$REPO_ROOT" --literal-pathspecs ls-files -s -z -- "$path")
217
+ index=$head
218
+ if [[ -n "$index_oid" ]]; then
219
+ [[ "$index_mode" == 100644 || "$index_mode" == 100755 ]] || return 1
220
+ [[ -z "$head_mode" || "$index_mode" == "$head_mode" ]] || return 1
221
+ index=$(git -C "$REPO_ROOT" cat-file blob "$index_oid" && printf x) || return 1
222
+ index=${index%x}
223
+ elif [[ -n "$head_mode" ]]; then
224
+ return 1
225
+ fi
226
+ # diff-files -z --raw: ":<srcmode> <dstmode> <srcoid> <dstoid> <status>\0".
227
+ if IFS= read -r -d '' entry < <(git -C "$REPO_ROOT" --literal-pathspecs diff-files -z --raw -- "$path"); then
228
+ read -r _ work_mode _ <<<"${entry#:}"
229
+ [[ "$work_mode" == "${index_mode:-${head_mode:-100644}}" ]] || return 1
230
+ fi
231
+ [[ "$work" != "$head" || "$index" != "$head" ]] || return 1
232
+ is_head_plus_rule "$head" "$work" && is_head_plus_rule "$head" "$index"
233
+ }
234
+
235
+ # Plan-artifact paths relative to the directory the plan was written from.
236
+ is_plan_path() {
237
+ case "$1" in
168
238
  docs/plans/"${FEATURE_SLUG}"/*) return 0 ;;
169
239
  docs/orchestration/"${FEATURE_SLUG}"*) return 0 ;;
170
240
  docs/prps/plans/"${FEATURE_SLUG}"*) return 0 ;;
@@ -174,23 +244,39 @@ is_plan_artifact() {
174
244
  esac
175
245
  }
176
246
 
247
+ # $1 is root-relative. Plan paths match from the root or, for package-local
248
+ # (`scope: local`) plans, from the cwd; .gitignore checks stay root-relative.
249
+ is_plan_artifact() {
250
+ local path="$1"
251
+ is_plan_path "$path" && return 0
252
+ if [[ -n "$REPO_PREFIX" && "$path" == "$REPO_PREFIX"* ]]; then
253
+ is_plan_path "${path#"$REPO_PREFIX"}" && return 0
254
+ fi
255
+ case "$path" in
256
+ .gitignore|*/.gitignore) is_artifact_gitignore "$path" ;;
257
+ *) return 1 ;;
258
+ esac
259
+ }
260
+
177
261
  UNRELATED_DIRTY=()
262
+ # NUL-separated root-relative paths; --no-renames reports both sides of a
263
+ # rename so a staged deletion cannot hide behind an allowed new path.
178
264
  collect_dirty() {
179
265
  # Untracked files (file-level — avoids `?? dir/` collapsed entries from
180
266
  # `git status --porcelain` and `--untracked-files=all`'s memory cost).
181
- git ls-files --others --exclude-standard
267
+ git -C "$REPO_ROOT" ls-files -z --others --exclude-standard
182
268
  # Modified-but-unstaged tracked files.
183
- git diff --name-only
184
- # Staged tracked files (added/modified/renamed/deleted).
185
- git diff --name-only --cached
269
+ git -C "$REPO_ROOT" diff -z --name-only --no-renames
270
+ # Staged tracked files (added/modified/deleted).
271
+ git -C "$REPO_ROOT" diff -z --name-only --no-renames --cached
186
272
  }
187
273
 
188
- while IFS= read -r path; do
274
+ while IFS= read -r -d '' path; do
189
275
  [[ -z "$path" ]] && continue
190
276
  if ! is_plan_artifact "$path"; then
191
277
  UNRELATED_DIRTY+=("$path")
192
278
  fi
193
- done < <(collect_dirty | sort -u)
279
+ done < <(collect_dirty | sort -zu)
194
280
 
195
281
  if (( ${#UNRELATED_DIRTY[@]} > 0 )); then
196
282
  _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