@yandy-r/ycc-opencode 6.1.1 → 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.
- package/README.md +7 -3
- package/agents/code-researcher.md +3 -3
- package/agents/feature-researcher.md +1 -1
- package/agents/implementor.md +4 -4
- package/agents/pr-comment-fixer.md +1 -1
- package/agents/release-fix-applier.md +1 -1
- package/agents/review-fixer.md +1 -1
- package/package.json +1 -1
- package/shared/references/artifact-store.md +613 -0
- package/shared/references/branch-prep.md +2 -0
- package/shared/references/forge-detection.md +3 -2
- package/shared/references/review-artifact-format.md +13 -6
- package/shared/references/review-checklist.md +3 -2
- package/shared/references/review-dispatch.md +15 -10
- package/shared/references/target-capability-matrix.md +42 -6
- package/shared/references/visual-mode.md +19 -13
- package/shared/references/worktree-strategy.md +12 -8
- package/shared/scripts/artifact-body.sh +71 -0
- package/shared/scripts/artifact-store-pointer.sh +245 -0
- package/shared/scripts/ci-monitor.sh +9 -4
- package/shared/scripts/collect-linear-keys.sh +77 -0
- package/shared/scripts/lib/ci-classify.sh +13 -10
- package/shared/scripts/lib/forge.sh +13 -4
- package/shared/scripts/prepare-feature-branch.sh +96 -10
- package/shared/scripts/release-ci-monitor.sh +2 -2
- package/shared/scripts/report-bundle-drift.sh +1 -1
- package/shared/scripts/resolve-artifact-store.sh +636 -0
- package/shared/scripts/validate-file-paths.sh +11 -4
- package/skills/blueprint/SKILL.md +48 -13
- package/skills/clean/SKILL.md +1 -1
- package/skills/clean/scripts/detect-project-type.sh +2 -2
- package/skills/clean/scripts/generate-report.sh +34 -5
- package/skills/clean/scripts/validate-safety.sh +9 -6
- package/skills/code-report/SKILL.md +26 -14
- package/skills/code-report/scripts/check-prerequisites.sh +72 -12
- package/skills/code-report/templates/report-structure.md +1 -1
- package/skills/code-review/SKILL.md +68 -17
- package/skills/code-review/references/pr-procedure.md +28 -15
- package/skills/compatibility-audit/scripts/audit-target-features.sh +1 -1
- package/skills/deep-research/SKILL.md +28 -5
- package/skills/deep-research/references/completion-summary-template.md +3 -2
- package/skills/deep-research/scripts/validate-research.sh +8 -2
- package/skills/feature-research/SKILL.md +48 -25
- package/skills/feature-research/scripts/validate-research.sh +51 -12
- package/skills/feature-research/scripts/validate-spec.sh +53 -22
- package/skills/feature-research/templates/research-agents.md +15 -14
- package/skills/feature-research/templates/spec-structure.md +5 -0
- package/skills/formatters/scripts/apply-aliases.sh +3 -1
- package/skills/formatters/scripts/apply-ci.sh +3 -1
- package/skills/git-workflow/SKILL.md +2 -1
- package/skills/git-workflow/references/pr-creation.md +10 -0
- package/skills/git-workflow/scripts/analyze-changes.sh +21 -11
- package/skills/git-workflow/scripts/create-pr.sh +51 -6
- package/skills/git-workflow/scripts/validate-commit.sh +26 -14
- package/skills/hooks-workflow/scripts/verify-hooks.sh +1 -1
- package/skills/implement-plan/SKILL.md +35 -16
- package/skills/implement-plan/references/agent-task-prompt.md +8 -5
- package/skills/implement-plan/references/linear-sync.md +20 -0
- package/skills/implement-plan/references/output-formats.md +17 -2
- package/skills/implement-plan/references/plan-inputs.md +23 -4
- package/skills/implement-plan/scripts/check-prerequisites.sh +95 -49
- package/skills/implement-plan/scripts/parse-dependencies.sh +10 -10
- package/skills/init/SKILL.md +77 -42
- package/skills/init/references/flag-reference.md +41 -17
- package/skills/init/references/project-profile-heuristics.md +3 -0
- package/skills/init/references/template-library.md +15 -5
- package/skills/init/scripts/profile-project.sh +26 -0
- package/skills/init/scripts/render-template.py +2 -2
- package/skills/init/templates/AGENTS.md.tmpl +6 -0
- package/skills/init/templates/git/gitignore.tmpl +5 -0
- package/skills/orchestrate/SKILL.md +17 -2
- package/skills/parallel-plan/SKILL.md +14 -8
- package/skills/plan/SKILL.md +18 -2
- package/skills/plan/references/planning-tracks.md +1 -1
- package/skills/plan-workflow/SKILL.md +67 -32
- package/skills/plan-workflow/references/checkpoint-messages.md +23 -14
- package/skills/plan-workflow/references/plan-structure.md +1 -1
- package/skills/plan-workflow/references/planning-agents.md +11 -9
- package/skills/plan-workflow/references/research-agents-optimized.md +12 -10
- package/skills/plan-workflow/references/research-agents.md +11 -10
- package/skills/plan-workflow/scripts/check-prerequisites.sh +50 -11
- package/skills/plan-workflow/scripts/check-state.sh +53 -9
- package/skills/plan-workflow/scripts/persist-or-fail.sh +21 -7
- package/skills/plan-workflow/scripts/validate-analysis-artifacts.sh +28 -14
- package/skills/plan-workflow/scripts/validate-research-artifacts.sh +35 -10
- package/skills/plan-workflow/scripts/validate-shared.sh +56 -15
- package/skills/plan-workflow/scripts/validate-workflow-plan.sh +48 -17
- package/skills/pr-autofix/SKILL.md +19 -4
- package/skills/pr-autofix/references/output-templates.md +3 -2
- package/skills/pr-autofix/scripts/fetch-pr-comments.sh +1 -2
- package/skills/pr-autofix/scripts/post-summary.sh +1 -2
- package/skills/pr-autofix/scripts/resolve-thread.sh +3 -4
- package/skills/prp-implement/SKILL.md +31 -16
- package/skills/prp-implement/references/agent-task-prompt.md +5 -2
- package/skills/prp-implement/references/detection.md +4 -1
- package/skills/prp-implement/references/linear-sync.md +25 -0
- package/skills/prp-implement/references/report-output.md +15 -2
- package/skills/prp-plan/SKILL.md +62 -30
- package/skills/prp-plan/references/enhanced-researchers.md +8 -9
- package/skills/prp-plan/scripts/validate-prp-plan.sh +42 -18
- package/skills/prp-pr/SKILL.md +14 -1
- package/skills/prp-prd/SKILL.md +21 -9
- package/skills/prp-spec/SKILL.md +30 -20
- package/skills/quick-fix/SKILL.md +6 -4
- package/skills/quick-review/SKILL.md +62 -25
- package/skills/release-model/scripts/collect-signals.sh +9 -3
- package/skills/releaser/scripts/publish-release.sh +6 -3
- package/skills/research-to-issues/SKILL.md +33 -14
- package/skills/research-to-issues/scripts/validate-prerequisites.sh +45 -23
- package/skills/research-to-issues/templates/task-issue.md +4 -0
- package/skills/research-to-issues/templates/tracking-issue.md +3 -0
- package/skills/review-fix/SKILL.md +96 -14
- package/skills/review-fix/references/fix-report.md +10 -10
- package/skills/review-fix/references/plan.md +5 -2
- package/skills/shared-context/SKILL.md +14 -11
- package/skills/visual-plan/SKILL.md +26 -8
- package/skills/visual-recap/SKILL.md +1 -1
- package/skills/write-docs/scripts/audit-documentation.sh +44 -10
- package/skills/write-docs/scripts/generate-doc-index.sh +10 -3
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Resolve the artifact store without writing files or contacting Linear.
|
|
3
|
+
# Usage: source resolve-artifact-store.sh; get_feature_artifact_dir feature-name
|
|
4
|
+
# See ../references/artifact-store.md for the exported API and sync protocol.
|
|
5
|
+
# Like resolve-plans-dir.sh, leave errexit under the sourcing caller's control.
|
|
6
|
+
set -uo pipefail
|
|
7
|
+
|
|
8
|
+
# shellcheck source=resolve-plans-dir.sh
|
|
9
|
+
source "$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd -P)/resolve-plans-dir.sh" 2>/dev/null || {
|
|
10
|
+
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then exit 1; else return 1; fi
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
# Unlike _parse_config, a defined but empty value is still a hit. In particular,
|
|
14
|
+
# an empty store must fail validation rather than silently inherit a default.
|
|
15
|
+
_artifact_config_value() {
|
|
16
|
+
local key="$1" file="$2"
|
|
17
|
+
[[ -f "$file" ]] || return 1
|
|
18
|
+
grep -qE "^${key}[[:space:]]*[:=]" "$file" || return 1
|
|
19
|
+
_parse_config "$key" "$file" || printf '%s' ''
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# Each key inherits independently, but never from outside this repository.
|
|
23
|
+
_artifact_find_config_value() {
|
|
24
|
+
local key="$1" dir="$2" boundary="$3" value
|
|
25
|
+
# A boundary that is not an ancestor cannot bound a walk: inspect only start.
|
|
26
|
+
if [[ "$dir" != "$boundary" && "$dir" != "${boundary%/}/"* ]]; then boundary=$dir; fi
|
|
27
|
+
while :; do
|
|
28
|
+
if value=$(_artifact_config_value "$key" "${dir}/.plans-config"); then
|
|
29
|
+
printf '%s' "$value"
|
|
30
|
+
return 0
|
|
31
|
+
fi
|
|
32
|
+
[[ "$dir" != "$boundary" && "$dir" != / ]] || break
|
|
33
|
+
dir=$(dirname "$dir")
|
|
34
|
+
done
|
|
35
|
+
return 1
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_artifact_branch_hint() {
|
|
39
|
+
local start_dir="$1" team="$2" branch prefix regex
|
|
40
|
+
branch=$(git -C "$start_dir" branch --show-current 2>/dev/null) || return 0
|
|
41
|
+
[[ -n "$branch" ]] || return 0
|
|
42
|
+
branch=$(printf '%s' "$branch" | tr '[:lower:]' '[:upper:]')
|
|
43
|
+
prefix='[A-Z][A-Z0-9]{1,9}'
|
|
44
|
+
if [[ -n "$team" ]]; then
|
|
45
|
+
team=$(printf '%s' "$team" | tr '[:lower:]' '[:upper:]')
|
|
46
|
+
[[ "$team" =~ ^[A-Z0-9]+$ ]] || return 0
|
|
47
|
+
prefix=$team
|
|
48
|
+
fi
|
|
49
|
+
regex="(^|[/_-])(${prefix})-([0-9]+)([/_-]|$)"
|
|
50
|
+
if [[ "$branch" =~ $regex ]]; then
|
|
51
|
+
printf '%s-%s' "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}"
|
|
52
|
+
fi
|
|
53
|
+
return 0
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
resolve_artifact_store() {
|
|
57
|
+
unset ARTIFACT_STORE ARTIFACT_STORE_SOURCE ARTIFACT_ROOT ARTIFACT_DIR \
|
|
58
|
+
ARTIFACT_LINEAR_WORKSPACE ARTIFACT_LINEAR_TEAM ARTIFACT_LINEAR_PROJECT \
|
|
59
|
+
ARTIFACT_LINEAR_LABEL ARTIFACT_LINEAR_HINT ARTIFACT_REPO_ROOT
|
|
60
|
+
local start_dir='' store='' source_name='' flag_set=0 global_config git_root boundary
|
|
61
|
+
local phys_start phys_plans_root
|
|
62
|
+
while [[ $# -gt 0 ]]; do
|
|
63
|
+
case "$1" in
|
|
64
|
+
--store=*) store=${1#--store=}; source_name=flag; flag_set=1 ;;
|
|
65
|
+
--*) _error "Unknown artifact-store option: $1"; return 1 ;;
|
|
66
|
+
*)
|
|
67
|
+
if [[ -n "$start_dir" || -z "$1" ]]; then
|
|
68
|
+
_error 'Expected one start directory'; return 1
|
|
69
|
+
fi
|
|
70
|
+
start_dir=$1
|
|
71
|
+
;;
|
|
72
|
+
esac
|
|
73
|
+
shift
|
|
74
|
+
done
|
|
75
|
+
start_dir=${start_dir:-$PWD}
|
|
76
|
+
start_dir=$(CDPATH='' cd -- "$start_dir" >/dev/null 2>&1 && pwd) || {
|
|
77
|
+
_error 'Artifact-store start directory does not exist'; return 1
|
|
78
|
+
}
|
|
79
|
+
resolve_plans_dir "$start_dir" || return 1
|
|
80
|
+
phys_start=$(CDPATH='' cd -- "$start_dir" >/dev/null && pwd -P) || return 1
|
|
81
|
+
phys_plans_root=$(CDPATH='' cd -- "$PLANS_ROOT" >/dev/null 2>&1 && pwd -P) || phys_plans_root=$PLANS_ROOT
|
|
82
|
+
git_root=$(git -C "$phys_start" rev-parse --show-toplevel 2>/dev/null) || git_root=''
|
|
83
|
+
boundary=${git_root:-$phys_plans_root}
|
|
84
|
+
if [[ "$flag_set" == 0 ]]; then
|
|
85
|
+
if store=$(_artifact_find_config_value store "$phys_start" "$boundary"); then
|
|
86
|
+
source_name=config
|
|
87
|
+
else
|
|
88
|
+
global_config="${XDG_CONFIG_HOME:-${HOME}/.config}/ycc/config"
|
|
89
|
+
if store=$(_artifact_config_value store "$global_config"); then
|
|
90
|
+
source_name=global
|
|
91
|
+
else
|
|
92
|
+
store=linear
|
|
93
|
+
source_name=default
|
|
94
|
+
fi
|
|
95
|
+
fi
|
|
96
|
+
fi
|
|
97
|
+
case "$store" in
|
|
98
|
+
linear|local) ;;
|
|
99
|
+
*)
|
|
100
|
+
if [[ "${_ARTIFACT_AUTO_RESOLVE:-}" == 1 ]]; then
|
|
101
|
+
_warn "Invalid artifact store '${store}' (${source_name}); expected linear or local"
|
|
102
|
+
else
|
|
103
|
+
_error "Invalid artifact store '${store}' (${source_name}); expected linear or local"
|
|
104
|
+
fi
|
|
105
|
+
return 1
|
|
106
|
+
;;
|
|
107
|
+
esac
|
|
108
|
+
|
|
109
|
+
export ARTIFACT_STORE="$store" ARTIFACT_STORE_SOURCE="$source_name"
|
|
110
|
+
# Current checkout for repo-level kinds (prd, spec, prp-plan, prp-research,
|
|
111
|
+
# prp-report, blueprint) in local mode; not part of the --shell output.
|
|
112
|
+
export ARTIFACT_REPO_ROOT="${git_root:-$phys_start}"
|
|
113
|
+
export ARTIFACT_ROOT="$PLANS_ROOT"
|
|
114
|
+
if [[ "$store" == linear ]]; then
|
|
115
|
+
if [[ -n "$git_root" && "$phys_plans_root" != "$git_root" && "$phys_plans_root" != "$git_root/"* ]]; then
|
|
116
|
+
ARTIFACT_ROOT=$git_root
|
|
117
|
+
fi
|
|
118
|
+
export ARTIFACT_DIR="${ARTIFACT_ROOT}/.ycc/artifacts"
|
|
119
|
+
else
|
|
120
|
+
export ARTIFACT_DIR="$PLANS_DIR"
|
|
121
|
+
fi
|
|
122
|
+
ARTIFACT_LINEAR_WORKSPACE=$(_artifact_find_config_value linear_workspace "$phys_start" "$boundary") || ARTIFACT_LINEAR_WORKSPACE=''
|
|
123
|
+
ARTIFACT_LINEAR_TEAM=$(_artifact_find_config_value linear_team "$phys_start" "$boundary") || ARTIFACT_LINEAR_TEAM=''
|
|
124
|
+
ARTIFACT_LINEAR_PROJECT=$(_artifact_find_config_value linear_project "$phys_start" "$boundary") || ARTIFACT_LINEAR_PROJECT=''
|
|
125
|
+
ARTIFACT_LINEAR_LABEL=$(_artifact_find_config_value linear_label "$phys_start" "$boundary") || ARTIFACT_LINEAR_LABEL=''
|
|
126
|
+
export ARTIFACT_LINEAR_WORKSPACE ARTIFACT_LINEAR_TEAM ARTIFACT_LINEAR_PROJECT ARTIFACT_LINEAR_LABEL
|
|
127
|
+
export ARTIFACT_LINEAR_HINT
|
|
128
|
+
ARTIFACT_LINEAR_HINT=$(_artifact_branch_hint "$start_dir" "$ARTIFACT_LINEAR_TEAM")
|
|
129
|
+
_debug "Artifact store: $ARTIFACT_STORE ($ARTIFACT_STORE_SOURCE), directory: $ARTIFACT_DIR"
|
|
130
|
+
return 0
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get_feature_artifact_dir() {
|
|
134
|
+
local slug="${1:-}"
|
|
135
|
+
if [[ ! "$slug" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]]; then
|
|
136
|
+
_error 'Artifact feature slug must start with a letter or digit and contain only letters, digits, ., _, or -'
|
|
137
|
+
return 1
|
|
138
|
+
fi
|
|
139
|
+
[[ -n "${ARTIFACT_DIR:-}" ]] || resolve_artifact_store || return 1
|
|
140
|
+
printf '%s/%s\n' "$ARTIFACT_DIR" "$slug"
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get_artifact_path() {
|
|
144
|
+
local kind="${1:-}" slug="${2:-}" base lens name repo
|
|
145
|
+
[[ -n "${ARTIFACT_STORE:-}" && -n "${ARTIFACT_DIR:-}" ]] || resolve_artifact_store || return 1
|
|
146
|
+
base=$(get_feature_artifact_dir "$slug") || return 1
|
|
147
|
+
# Repo-level kinds stay relative to the current checkout in local mode (not
|
|
148
|
+
# PLANS_ROOT), matching the cwd-relative docs/prps/... paths used before.
|
|
149
|
+
repo=${ARTIFACT_REPO_ROOT:-$ARTIFACT_ROOT}
|
|
150
|
+
case "$kind" in
|
|
151
|
+
prd|spec|prp-plan)
|
|
152
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
153
|
+
printf '%s/%s.md\n' "$base" "$kind"
|
|
154
|
+
else
|
|
155
|
+
case "$kind" in
|
|
156
|
+
prd) printf '%s/docs/prps/prds/%s.prd.md\n' "$repo" "$slug" ;;
|
|
157
|
+
spec) printf '%s/docs/prps/specs/%s.spec.md\n' "$repo" "$slug" ;;
|
|
158
|
+
prp-plan) printf '%s/docs/prps/plans/%s.plan.md\n' "$repo" "$slug" ;;
|
|
159
|
+
esac
|
|
160
|
+
fi
|
|
161
|
+
;;
|
|
162
|
+
feature-spec|parallel-plan|shared|report)
|
|
163
|
+
printf '%s/%s.md\n' "$base" "$kind"
|
|
164
|
+
;;
|
|
165
|
+
prp-report)
|
|
166
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
167
|
+
printf '%s/report.md\n' "$base"
|
|
168
|
+
else
|
|
169
|
+
printf '%s/docs/prps/reports/%s-report.md\n' "$repo" "$slug"
|
|
170
|
+
fi
|
|
171
|
+
;;
|
|
172
|
+
code-report)
|
|
173
|
+
# Local parity: code-report keeps <PLANS_DIR>/<slug>/report.md. Linear
|
|
174
|
+
# gets its own Document so it never replaces the run report.
|
|
175
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
176
|
+
printf '%s/code-report.md\n' "$base"
|
|
177
|
+
else
|
|
178
|
+
printf '%s/report.md\n' "$base"
|
|
179
|
+
fi
|
|
180
|
+
;;
|
|
181
|
+
review-fixes-*|review-*)
|
|
182
|
+
# review-fixes-* first: its id never starts with fixes-, so the strip is
|
|
183
|
+
# unambiguous. Local paths match code-review/review-fix before the store.
|
|
184
|
+
name=${kind#review-fixes-}
|
|
185
|
+
[[ "$name" != "$kind" ]] || name=${kind#review-}
|
|
186
|
+
if [[ ! "$name" =~ ^(pr-[1-9][0-9]*|local-[0-9]{8}-[0-9]{6}|quick-[0-9]{8}-[0-9]{6})$ ]]; then
|
|
187
|
+
_error 'Review id must be pr-<N>, local-<YYYYMMDD-HHMMSS>, or quick-<YYYYMMDD-HHMMSS>'
|
|
188
|
+
return 1
|
|
189
|
+
fi
|
|
190
|
+
if [[ "$kind" == review-fixes-* ]]; then
|
|
191
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
192
|
+
printf '%s/reviews/%s-fixes.md\n' "$base" "$name"
|
|
193
|
+
else
|
|
194
|
+
printf '%s/docs/prps/reviews/fixes/%s-fixes.md\n' "$repo" "$name"
|
|
195
|
+
fi
|
|
196
|
+
elif [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
197
|
+
printf '%s/reviews/%s-review.md\n' "$base" "$name"
|
|
198
|
+
else
|
|
199
|
+
printf '%s/docs/prps/reviews/%s-review.md\n' "$repo" "$name"
|
|
200
|
+
fi
|
|
201
|
+
;;
|
|
202
|
+
pr-autofix-report-*)
|
|
203
|
+
# Local-only scratch in both modes: never pushed to Linear.
|
|
204
|
+
name=${kind#pr-autofix-report-}
|
|
205
|
+
if [[ ! "$name" =~ ^[1-9][0-9]*-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{6}Z$ ]]; then
|
|
206
|
+
_error 'pr-autofix report id must be <PR>-<YYYY-MM-DD>T<HHMMSS>Z'
|
|
207
|
+
return 1
|
|
208
|
+
fi
|
|
209
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
210
|
+
printf '%s/reports/pr-autofix-%s.md\n' "$base" "$name"
|
|
211
|
+
else
|
|
212
|
+
printf '%s/docs/prps/reports/pr-autofix-%s.md\n' "$repo" "$name"
|
|
213
|
+
fi
|
|
214
|
+
;;
|
|
215
|
+
research-dir)
|
|
216
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
217
|
+
printf '%s/research\n' "$base"
|
|
218
|
+
else
|
|
219
|
+
printf '%s\n' "$base"
|
|
220
|
+
fi
|
|
221
|
+
;;
|
|
222
|
+
research-*)
|
|
223
|
+
lens=${kind#research-}
|
|
224
|
+
if [[ ! "$lens" =~ ^[a-z0-9][a-z0-9-]*$ ]]; then
|
|
225
|
+
_error 'Artifact research lens must contain only lowercase letters, digits, or - and start with a letter or digit'
|
|
226
|
+
return 1
|
|
227
|
+
fi
|
|
228
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
229
|
+
printf '%s/research/research-%s.md\n' "$base" "$lens"
|
|
230
|
+
else
|
|
231
|
+
printf '%s/research-%s.md\n' "$base" "$lens"
|
|
232
|
+
fi
|
|
233
|
+
;;
|
|
234
|
+
analysis-*)
|
|
235
|
+
name=${kind#analysis-}
|
|
236
|
+
if [[ ! "$name" =~ ^[a-z0-9][a-z0-9-]*$ ]]; then
|
|
237
|
+
_error 'Artifact analysis name must contain only lowercase letters, digits, or - and start with a letter or digit'
|
|
238
|
+
return 1
|
|
239
|
+
fi
|
|
240
|
+
printf '%s/analysis-%s.md\n' "$base" "$name"
|
|
241
|
+
;;
|
|
242
|
+
prp-research)
|
|
243
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
244
|
+
printf '%s/.prp-research\n' "$base"
|
|
245
|
+
else
|
|
246
|
+
printf '%s/docs/prps/plans/.prp-research/%s\n' "$repo" "$slug"
|
|
247
|
+
fi
|
|
248
|
+
;;
|
|
249
|
+
deep-research)
|
|
250
|
+
if [[ "$ARTIFACT_STORE" == local ]]; then
|
|
251
|
+
_error "local mode keeps the skill's own output dir"
|
|
252
|
+
return 1
|
|
253
|
+
fi
|
|
254
|
+
printf '%s/deep-research\n' "$base"
|
|
255
|
+
;;
|
|
256
|
+
blueprint)
|
|
257
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
258
|
+
printf '%s/blueprint.md\n' "$base"
|
|
259
|
+
else
|
|
260
|
+
printf '%s/docs/blueprint.md\n' "$repo"
|
|
261
|
+
fi
|
|
262
|
+
;;
|
|
263
|
+
feature-dir) printf '%s\n' "$base" ;;
|
|
264
|
+
*)
|
|
265
|
+
_error "Unknown artifact kind: ${kind:-<empty>}"
|
|
266
|
+
return 1
|
|
267
|
+
;;
|
|
268
|
+
esac
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
# Feature directory for the read-only planning checks (check-prerequisites,
|
|
272
|
+
# check-state). Linear mode uses the strict artifact slug. Local mode keeps the
|
|
273
|
+
# legacy ${PLANS_DIR}/<name> resolution so every name accepted before still
|
|
274
|
+
# works, except empty names and names with a .. path segment, which would
|
|
275
|
+
# escape the plans directory.
|
|
276
|
+
get_plans_feature_dir() {
|
|
277
|
+
local name="${1:-}"
|
|
278
|
+
[[ -n "${ARTIFACT_STORE:-}" && -n "${ARTIFACT_DIR:-}" ]] || resolve_artifact_store || return 1
|
|
279
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
280
|
+
get_artifact_path feature-dir "$name"
|
|
281
|
+
return
|
|
282
|
+
fi
|
|
283
|
+
if [[ -z "$name" || "$name" == /* || "$name" == .. || "$name" == ../* || "$name" == */.. || "$name" == */../* ]]; then
|
|
284
|
+
_error "Invalid feature name: ${name:-<empty>}"
|
|
285
|
+
return 1
|
|
286
|
+
fi
|
|
287
|
+
printf '%s/%s\n' "$PLANS_DIR" "$name"
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
# Read-only planning checks: under the default store only, an existing local
|
|
291
|
+
# feature directory keeps local mode (artifact-store.md Implementation skills >
|
|
292
|
+
# Inputs). Uses the legacy local name rules, so names such as team/auth work.
|
|
293
|
+
# Prints the selection line when it switches; returns 1 only on resolver errors.
|
|
294
|
+
select_local_plan_store() {
|
|
295
|
+
local name="${1:-}" local_dir
|
|
296
|
+
[[ "${ARTIFACT_STORE_SOURCE:-}" == default ]] || return 0
|
|
297
|
+
local_dir=$( (resolve_artifact_store --store=local && get_plans_feature_dir "$name") 2>/dev/null) || return 0
|
|
298
|
+
[[ -d "$local_dir" ]] || return 0
|
|
299
|
+
resolve_artifact_store --store=local || return 1
|
|
300
|
+
printf 'Using local plan at %s; pin with store: local in .plans-config\n' "$local_dir"
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
# Check before either write entry point so a non-repository cannot gain a cache.
|
|
304
|
+
_artifact_require_git_root() {
|
|
305
|
+
local git_root inside phys_root
|
|
306
|
+
if [[ -L "${ARTIFACT_ROOT}/.gitignore" || -L "${ARTIFACT_ROOT}/.ycc" || -L "$ARTIFACT_DIR" ]]; then
|
|
307
|
+
_error 'Artifact writes refuse symlinked .gitignore, .ycc, or artifact directory'
|
|
308
|
+
return 1
|
|
309
|
+
fi
|
|
310
|
+
phys_root=$(CDPATH='' cd -- "$ARTIFACT_ROOT" >/dev/null 2>&1 && pwd -P) || phys_root=''
|
|
311
|
+
inside=$(git -C "$ARTIFACT_ROOT" rev-parse --is-inside-work-tree 2>/dev/null) || inside=''
|
|
312
|
+
git_root=$(git -C "$ARTIFACT_ROOT" rev-parse --show-toplevel 2>/dev/null) || git_root=''
|
|
313
|
+
if [[ "$inside" != true || -z "$git_root" || ( "$phys_root" != "$git_root" && "$phys_root" != "$git_root/"* ) ]]; then
|
|
314
|
+
_error 'Linear artifact writes require ARTIFACT_ROOT inside a Git work tree'
|
|
315
|
+
return 1
|
|
316
|
+
fi
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
# Write NUL-terminated `check-ignore -v -z` records for the cache probes to
|
|
320
|
+
# OUT. With GIT_ROOT, only that work tree's .gitignore files are consulted: an
|
|
321
|
+
# empty scratch Git dir drops .git/info/exclude and core.excludesFile=/dev/null
|
|
322
|
+
# drops global excludes, so a non-repository parent rule (for example a global
|
|
323
|
+
# `.ycc/`) cannot hide a deeper repository rule or negation.
|
|
324
|
+
_artifact_probe_ignores() {
|
|
325
|
+
local out="$1" git_root="${2:-}" status=0 ignorecase
|
|
326
|
+
local -a git_args=(-C "$ARTIFACT_ROOT")
|
|
327
|
+
if [[ -n "$git_root" ]]; then
|
|
328
|
+
git init -q --bare --template= "${out}.git" >/dev/null 2>&1 || return 1
|
|
329
|
+
# The scratch Git dir detects case folding from TMPDIR; match the repo's.
|
|
330
|
+
ignorecase=$(git -C "$ARTIFACT_ROOT" config --type=bool core.ignorecase 2>/dev/null) || ignorecase=false
|
|
331
|
+
git_args+=(--git-dir="${out}.git" --work-tree="$git_root" -c core.excludesFile=/dev/null -c core.ignoreCase="$ignorecase")
|
|
332
|
+
fi
|
|
333
|
+
# check-ignore exits 1 when nothing matches; only >1 is an error.
|
|
334
|
+
printf '.ycc/artifacts/probe\0.ycc/artifacts/probe-dir/probe\0.ycc/artifacts/feat/cache\0' | git "${git_args[@]}" check-ignore -v -z --no-index --stdin >"$out" 2>/dev/null || status=$?
|
|
335
|
+
[[ "$status" -le 1 ]]
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
# 0 when FILE has a negated (!) line, 1 when not, >1 when unreadable. A leading
|
|
339
|
+
# space makes `!` literal. A BOM is accepted on any line, broader than Git
|
|
340
|
+
# (which skips it only at file start), so this fails safe.
|
|
341
|
+
_artifact_has_negation() {
|
|
342
|
+
LC_ALL=C grep -qE $'^(\xef\xbb\xbf)?!' "$1"
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
# check-ignore -v reports only each probe's deciding pattern, so a negation in
|
|
346
|
+
# a .gitignore under .ycc can go unreported. Scan working-tree files (without
|
|
347
|
+
# following symlinks) and index blobs, since a tracked file deleted locally
|
|
348
|
+
# still applies in a clone. Returns 0 when none, 2 when negated, 3 on failure.
|
|
349
|
+
# OUT is a scratch path prefix.
|
|
350
|
+
_artifact_ycc_negation() {
|
|
351
|
+
local out="$1" file entry mode hash rc
|
|
352
|
+
if [[ -d "${ARTIFACT_ROOT}/.ycc" ]]; then
|
|
353
|
+
find -P "${ARTIFACT_ROOT}/.ycc" -name .gitignore -type f -print0 >"${out}.tree" 2>/dev/null || return 3
|
|
354
|
+
while IFS= read -r -d '' file; do
|
|
355
|
+
rc=0; _artifact_has_negation "$file" || rc=$?
|
|
356
|
+
[[ "$rc" == 0 ]] && return 2
|
|
357
|
+
[[ "$rc" == 1 ]] || return 3
|
|
358
|
+
done <"${out}.tree"
|
|
359
|
+
fi
|
|
360
|
+
git -C "$ARTIFACT_ROOT" ls-files -s -z -- .ycc >"${out}.index" 2>/dev/null || return 3
|
|
361
|
+
# Entries are "<mode> <hash> <stage>\t<path>"; symlinks are never read.
|
|
362
|
+
while IFS= read -r -d '' entry; do
|
|
363
|
+
[[ "${entry##*/}" == .gitignore ]] || continue
|
|
364
|
+
read -r mode hash _ <<<"${entry%%$'\t'*}"
|
|
365
|
+
[[ "$mode" == 100644 || "$mode" == 100755 ]] || continue
|
|
366
|
+
git -C "$ARTIFACT_ROOT" cat-file blob "$hash" >"${out}.blob" 2>/dev/null || return 3
|
|
367
|
+
rc=0; _artifact_has_negation "${out}.blob" || rc=$?
|
|
368
|
+
[[ "$rc" == 0 ]] && return 2
|
|
369
|
+
[[ "$rc" == 1 ]] || return 3
|
|
370
|
+
done <"${out}.index"
|
|
371
|
+
return 0
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
# 0 when the negated pattern PAT (without `!`) may re-include REL, the path
|
|
375
|
+
# from its .gitignore directory to .ycc/artifacts. Unanchored patterns, `\` or
|
|
376
|
+
# `(` (Bash and Git globs differ there), bracket expressions spanning `/`
|
|
377
|
+
# (segment splitting would cut them), and `**` once earlier segments match all
|
|
378
|
+
# count; an anchored pattern counts unless a leading segment cannot match.
|
|
379
|
+
_artifact_negation_relevant() {
|
|
380
|
+
local LC_ALL=C pat="${1%/}" rel="$2" pseg rseg
|
|
381
|
+
[[ "$pat" == */* ]] || return 0
|
|
382
|
+
[[ "$pat" != *[\\\(]* && "$pat" != *'['*'/'*']'* ]] || return 0
|
|
383
|
+
pat=${pat#/}
|
|
384
|
+
while [[ -n "$pat" && -n "$rel" ]]; do
|
|
385
|
+
pseg=${pat%%/*} rseg=${rel%%/*}
|
|
386
|
+
[[ "$pseg" != *'**'* ]] || return 0
|
|
387
|
+
# shellcheck disable=SC2053 # The gitignore segment is a glob.
|
|
388
|
+
[[ "$rseg" == $pseg ]] || return 1
|
|
389
|
+
if [[ "$pat" == */* ]]; then pat=${pat#*/}; else pat=''; fi
|
|
390
|
+
if [[ "$rel" == */* ]]; then rel=${rel#*/}; else rel=''; fi
|
|
391
|
+
done
|
|
392
|
+
return 0
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
# 0 when the negated pattern PAT (without `!`) may match the REL directory
|
|
396
|
+
# itself, the only way to undo an earlier `.ycc/artifacts/` rule in the same
|
|
397
|
+
# file. `\` or `(`, bracket expressions spanning `/`, and unanchored `**` match
|
|
398
|
+
# conservatively.
|
|
399
|
+
_artifact_negation_matches_dir() {
|
|
400
|
+
local LC_ALL=C pat="${1%/}" rel="$2" pseg rseg
|
|
401
|
+
[[ "$pat" != *[\\\(]* && "$pat" != *'['*'/'*']'* ]] || return 0
|
|
402
|
+
if [[ "$pat" != */* ]]; then
|
|
403
|
+
[[ "$pat" != *'**'* ]] || return 0
|
|
404
|
+
# shellcheck disable=SC2053 # The gitignore pattern is a glob.
|
|
405
|
+
[[ "${rel##*/}" == $pat ]]
|
|
406
|
+
return
|
|
407
|
+
fi
|
|
408
|
+
pat=${pat#/}
|
|
409
|
+
while [[ -n "$pat" && -n "$rel" ]]; do
|
|
410
|
+
pseg=${pat%%/*} rseg=${rel%%/*}
|
|
411
|
+
[[ "$pseg" != *'**'* ]] || return 0
|
|
412
|
+
# shellcheck disable=SC2053 # The gitignore segment is a glob.
|
|
413
|
+
[[ "$rseg" == $pseg ]] || return 1
|
|
414
|
+
if [[ "$pat" == */* ]]; then pat=${pat#*/}; else pat=''; fi
|
|
415
|
+
if [[ "$rel" == */* ]]; then rel=${rel#*/}; else rel=''; fi
|
|
416
|
+
done
|
|
417
|
+
[[ -z "$pat" && -z "$rel" ]]
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
# Print "BROAD STRICT": the numbers of FILE's last `!` line relevant to REL and
|
|
421
|
+
# last one matching the REL directory itself (0 if none); fails when
|
|
422
|
+
# unreadable. A BOM is accepted on any line, as in _artifact_has_negation.
|
|
423
|
+
# FOLD=true matches case-insensitively; call only in a subshell.
|
|
424
|
+
_artifact_last_negation() {
|
|
425
|
+
local file="$1" rel="$2" fold="${3:-false}" line n=0 last=0 strict=0
|
|
426
|
+
[[ -r "$file" ]] || return 1
|
|
427
|
+
[[ "$fold" != true ]] || shopt -s nocasematch
|
|
428
|
+
while IFS= read -r line || [[ -n "$line" ]]; do
|
|
429
|
+
n=$((n + 1))
|
|
430
|
+
line=${line#$'\xef\xbb\xbf'}
|
|
431
|
+
[[ "$line" == '!'* ]] || continue
|
|
432
|
+
line=${line%$'\r'}
|
|
433
|
+
while [[ "$line" == *' ' && "$line" != *'\ ' ]]; do line=${line% }; done
|
|
434
|
+
if _artifact_negation_relevant "${line#!}" "$rel"; then last=$n; fi
|
|
435
|
+
if _artifact_negation_matches_dir "${line#!}" "$rel"; then strict=$n; fi
|
|
436
|
+
done <"$file" || return 1
|
|
437
|
+
printf '%s %s\n' "$last" "$strict"
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
# Scan repository .gitignore files from GIT_ROOT down to ARTIFACT_ROOT, in the
|
|
441
|
+
# working tree (regular files only; Git skips symlinks) and the index, for `!`
|
|
442
|
+
# lines that may re-include .ycc/artifacts. Prints the last line number in the
|
|
443
|
+
# working-tree ${ARTIFACT_ROOT}/.gitignore whose `!` can match the
|
|
444
|
+
# .ycc/artifacts directory itself (0 if none). Returns 0 when any file has a
|
|
445
|
+
# relevant `!` line, 1 when none, 3 on failure. OUT is a scratch path prefix.
|
|
446
|
+
_artifact_chain_negation() {
|
|
447
|
+
local out="$1" git_root="$2" phys_root dir sub path entry mode hash last strict fold found=1 root_last=0
|
|
448
|
+
local -a paths=()
|
|
449
|
+
phys_root=$(CDPATH='' cd -- "$ARTIFACT_ROOT" >/dev/null 2>&1 && pwd -P) || return 3
|
|
450
|
+
fold=$(git -C "$ARTIFACT_ROOT" config --type=bool core.ignorecase 2>/dev/null) || fold=false
|
|
451
|
+
dir="$phys_root"
|
|
452
|
+
while :; do
|
|
453
|
+
sub=${dir#"$git_root"}; sub=${sub#/}
|
|
454
|
+
paths+=("${sub:+$sub/}.gitignore")
|
|
455
|
+
[[ "$dir" != "$git_root" ]] || break
|
|
456
|
+
[[ "$dir" == "$git_root"/* ]] || return 3
|
|
457
|
+
dir=$(dirname "$dir")
|
|
458
|
+
done
|
|
459
|
+
sub=${phys_root#"$git_root"}; sub=${sub#/}; sub=${sub:+$sub/}
|
|
460
|
+
for path in "${paths[@]}"; do
|
|
461
|
+
[[ -f "${git_root}/${path}" && ! -L "${git_root}/${path}" ]] || continue
|
|
462
|
+
last=$(_artifact_last_negation "${git_root}/${path}" "${sub#"${path%.gitignore}"}.ycc/artifacts" "$fold") || return 3
|
|
463
|
+
strict=${last#* } last=${last%% *}
|
|
464
|
+
[[ "$last" == 0 ]] || found=0
|
|
465
|
+
[[ "$path" != "${sub}.gitignore" ]] || root_last=$strict
|
|
466
|
+
done
|
|
467
|
+
git --literal-pathspecs -C "$git_root" ls-files -s -z -- "${paths[@]}" >"${out}.index" 2>/dev/null || return 3
|
|
468
|
+
# Entries are "<mode> <hash> <stage>\t<path>"; symlinks are never read.
|
|
469
|
+
while IFS= read -r -d '' entry; do
|
|
470
|
+
path=${entry#*$'\t'}
|
|
471
|
+
read -r mode hash _ <<<"${entry%%$'\t'*}"
|
|
472
|
+
[[ "$mode" == 100644 || "$mode" == 100755 ]] || continue
|
|
473
|
+
git -C "$git_root" cat-file blob "$hash" >"${out}.blob" 2>/dev/null || return 3
|
|
474
|
+
last=$(_artifact_last_negation "${out}.blob" "${sub#"${path%.gitignore}"}.ycc/artifacts" "$fold") || return 3
|
|
475
|
+
[[ "${last%% *}" == 0 ]] || found=0
|
|
476
|
+
done <"${out}.index"
|
|
477
|
+
printf '%s\n' "$root_last"
|
|
478
|
+
return "$found"
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
# Coverage check (never edits the repository; uses TMPDIR scratch): 0 means
|
|
482
|
+
# present, 1 means append, 2 means a negated rule makes it unsafe, 3 means the
|
|
483
|
+
# ignore probe or a .gitignore scan failed.
|
|
484
|
+
_artifact_gitignore_present() {
|
|
485
|
+
local file="${ARTIFACT_ROOT}/.gitignore" ignore_source ignore_pattern git_root count scratch made status=0 root_neg short=0
|
|
486
|
+
git_root=$(git -C "$ARTIFACT_ROOT" rev-parse --show-toplevel) || return 1
|
|
487
|
+
made=$(mktemp -d "${TMPDIR:-/tmp}/ycc-ignore.XXXXXX") || return 3
|
|
488
|
+
# Git resolves --git-dir after -C, so the scratch path must be absolute.
|
|
489
|
+
scratch=$(CDPATH='' cd -- "$made" >/dev/null && pwd -P) || { rm -rf "$made"; return 3; }
|
|
490
|
+
_artifact_ycc_negation "${scratch}/ycc" || status=$?
|
|
491
|
+
if [[ "$status" != 0 ]]; then
|
|
492
|
+
rm -rf "$scratch"
|
|
493
|
+
return "$status"
|
|
494
|
+
fi
|
|
495
|
+
if ! _artifact_probe_ignores "${scratch}/all" || ! _artifact_probe_ignores "${scratch}/repo" "$git_root"; then
|
|
496
|
+
rm -rf "$scratch"
|
|
497
|
+
return 3
|
|
498
|
+
fi
|
|
499
|
+
# Any negated (!) match that re-includes a probed cache path is unsafe to
|
|
500
|
+
# override and refuses, from repository, info, or global excludes alike.
|
|
501
|
+
# Only committed-style ignores within this repo are portable, so coverage is
|
|
502
|
+
# counted from repository .gitignore files alone; global or info excludes
|
|
503
|
+
# never count and the repository rule is appended. A non-negated repo rule
|
|
504
|
+
# must cover direct, nested, and representative feature-cache probes so
|
|
505
|
+
# partial exceptions cannot leave later cache files visible.
|
|
506
|
+
# Fields are NUL-terminated: source, line number (discarded into _), pattern,
|
|
507
|
+
# and path.
|
|
508
|
+
while IFS= read -r -d '' _ && IFS= read -r -d '' _ && IFS= read -r -d '' ignore_pattern && IFS= read -r -d '' _; do
|
|
509
|
+
[[ "$ignore_pattern" != '!'* ]] || { rm -rf "$scratch"; return 2; }
|
|
510
|
+
done <"${scratch}/all"
|
|
511
|
+
count=0
|
|
512
|
+
while IFS= read -r -d '' ignore_source && IFS= read -r -d '' _ && IFS= read -r -d '' ignore_pattern && IFS= read -r -d '' _; do
|
|
513
|
+
[[ "$ignore_pattern" != '!'* ]] || { rm -rf "$scratch"; return 2; }
|
|
514
|
+
[[ "$ignore_source" == /* ]] || ignore_source="${git_root}/${ignore_source}"
|
|
515
|
+
ignore_source="$(CDPATH='' cd -- "$(dirname "$ignore_source")" >/dev/null 2>&1 && pwd -P)/${ignore_source##*/}"
|
|
516
|
+
[[ "$ignore_source" == "$git_root/"* && "${ignore_source##*/}" == .gitignore ]] || continue
|
|
517
|
+
count=$((count + 1))
|
|
518
|
+
done <"${scratch}/repo"
|
|
519
|
+
# check-ignore misses rules that re-include paths beyond the probes, so a
|
|
520
|
+
# relevant `!` line from the Git root down voids probe coverage. The exact
|
|
521
|
+
# rule still counts when it follows every `!` line in its own file that can
|
|
522
|
+
# match the .ycc/artifacts directory itself: that directory rule excludes
|
|
523
|
+
# the cache, and Git cannot re-include files under an excluded directory.
|
|
524
|
+
status=0
|
|
525
|
+
root_neg=$(_artifact_chain_negation "${scratch}/chain" "$git_root") || status=$?
|
|
526
|
+
rm -rf "$scratch"
|
|
527
|
+
[[ "$status" -le 1 ]] || return 3
|
|
528
|
+
if [[ -f "$file" ]]; then
|
|
529
|
+
short=$(grep -anxE '/?\.ycc/artifacts/?' "$file") || short=''
|
|
530
|
+
short=${short##*$'\n'}; short=${short%%:*}
|
|
531
|
+
fi
|
|
532
|
+
[[ "${short:-0}" -gt "$root_neg" ]] && return 0
|
|
533
|
+
[[ "$status" == 1 && "$count" == 3 ]] && return 0
|
|
534
|
+
return 1
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
ensure_artifact_gitignore() {
|
|
538
|
+
[[ -n "${ARTIFACT_STORE:-}" ]] || resolve_artifact_store || return 1
|
|
539
|
+
[[ "$ARTIFACT_STORE" == linear ]] || return 0
|
|
540
|
+
_artifact_require_git_root || return 1
|
|
541
|
+
local file="${ARTIFACT_ROOT}/.gitignore" last_byte status=0
|
|
542
|
+
_artifact_gitignore_present || status=$?
|
|
543
|
+
case "$status" in
|
|
544
|
+
0) return 0 ;;
|
|
545
|
+
2) _error 'A negated (!) ignore rule re-includes .ycc/artifacts/ paths; refusing to override it'; return 1 ;;
|
|
546
|
+
3) _error 'Cannot check .ycc/artifacts/ ignore coverage (git check-ignore, .gitignore scan, or TMPDIR scratch failed)'; return 1 ;;
|
|
547
|
+
esac
|
|
548
|
+
if [[ -s "$file" ]]; then
|
|
549
|
+
# Command substitution strips a final newline, leaving an empty last byte.
|
|
550
|
+
last_byte=$(tail -c 1 "$file") || return 1
|
|
551
|
+
if [[ -n "$last_byte" ]]; then printf '\n' >>"$file" || return 1; fi
|
|
552
|
+
fi
|
|
553
|
+
printf '.ycc/artifacts/\n' >>"$file"
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
ensure_artifact_dir() {
|
|
557
|
+
[[ -n "${ARTIFACT_DIR:-}" ]] || resolve_artifact_store || return 1
|
|
558
|
+
# Check the ignore rule first so a refusal leaves no empty cache behind.
|
|
559
|
+
ensure_artifact_gitignore || return 1
|
|
560
|
+
mkdir -p "$ARTIFACT_DIR"
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
# Local --ensure creates only what the resolved artifact needs: the parent
|
|
564
|
+
# directory of a file kind, or the directory itself for a directory kind.
|
|
565
|
+
# Linear mode keeps the cache directory and its .gitignore rule.
|
|
566
|
+
_artifact_ensure_for() {
|
|
567
|
+
local kind="$1" artifact_path="$2"
|
|
568
|
+
if [[ "$ARTIFACT_STORE" == linear ]]; then
|
|
569
|
+
ensure_artifact_dir
|
|
570
|
+
return
|
|
571
|
+
fi
|
|
572
|
+
case "$kind" in
|
|
573
|
+
research-dir|feature-dir|prp-research|deep-research) mkdir -p -- "$artifact_path" ;;
|
|
574
|
+
*) mkdir -p -- "$(dirname "$artifact_path")" ;;
|
|
575
|
+
esac
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
_artifact_store_cli() {
|
|
579
|
+
local shell_output=0 ensure=0 kind='' slug='' kind_set=0 slug_set=0 key artifact_path=''
|
|
580
|
+
local -a args=()
|
|
581
|
+
while [[ $# -gt 0 ]]; do
|
|
582
|
+
case "$1" in
|
|
583
|
+
--help|-h)
|
|
584
|
+
printf '%s\n' 'Usage: resolve-artifact-store.sh [--store=linear|local] [--debug] [--shell] [--kind=<kind> --slug=<slug>] [--ensure] [start-dir]' \
|
|
585
|
+
'Resolve paths and Linear hints without writing files. Default output: ARTIFACT_DIR.' \
|
|
586
|
+
'--kind and --slug print an artifact path. --ensure creates what that path needs before printing' \
|
|
587
|
+
'(linear: the cache directory and its .gitignore rule; local: the parent directory, or the directory itself for directory kinds).' \
|
|
588
|
+
'--ensure without --kind and --slug creates ARTIFACT_DIR.' \
|
|
589
|
+
'Kinds: prd spec prp-plan feature-spec parallel-plan shared report prp-report code-report research-dir' \
|
|
590
|
+
'research-<lens> analysis-<name> prp-research deep-research blueprint feature-dir' \
|
|
591
|
+
'review-<id> review-fixes-<id> (id: pr-<N>, local-<YYYYMMDD-HHMMSS>, quick-<YYYYMMDD-HHMMSS>)' \
|
|
592
|
+
'pr-autofix-report-<N>-<YYYY-MM-DD>T<HHMMSS>Z.' \
|
|
593
|
+
'--shell prints shell-quoted ARTIFACT_* assignments. PLANS_DEBUG=1 enables debug output.'
|
|
594
|
+
return 0
|
|
595
|
+
;;
|
|
596
|
+
--debug) export PLANS_DEBUG=1 ;;
|
|
597
|
+
--shell) shell_output=1 ;;
|
|
598
|
+
--ensure) ensure=1 ;;
|
|
599
|
+
--kind=*) kind=${1#--kind=}; kind_set=1 ;;
|
|
600
|
+
--slug=*) slug=${1#--slug=}; slug_set=1 ;;
|
|
601
|
+
*) args+=("$1") ;;
|
|
602
|
+
esac
|
|
603
|
+
shift
|
|
604
|
+
done
|
|
605
|
+
if [[ "$kind_set" != "$slug_set" ]]; then
|
|
606
|
+
_error 'Artifact path output requires both --kind and --slug'
|
|
607
|
+
return 1
|
|
608
|
+
fi
|
|
609
|
+
resolve_artifact_store ${args[@]+"${args[@]}"} || return 1
|
|
610
|
+
if [[ "$kind_set" == 1 ]]; then
|
|
611
|
+
artifact_path=$(get_artifact_path "$kind" "$slug") || return 1
|
|
612
|
+
fi
|
|
613
|
+
if [[ "$ensure" == 1 ]]; then
|
|
614
|
+
if [[ "$kind_set" == 1 ]]; then
|
|
615
|
+
_artifact_ensure_for "$kind" "$artifact_path" || return 1
|
|
616
|
+
else
|
|
617
|
+
ensure_artifact_dir || return 1
|
|
618
|
+
fi
|
|
619
|
+
fi
|
|
620
|
+
if [[ "$kind_set" == 1 ]]; then
|
|
621
|
+
printf '%s\n' "$artifact_path"
|
|
622
|
+
elif [[ "$shell_output" == 1 ]]; then
|
|
623
|
+
for key in ARTIFACT_STORE ARTIFACT_STORE_SOURCE ARTIFACT_ROOT ARTIFACT_DIR \
|
|
624
|
+
ARTIFACT_LINEAR_WORKSPACE ARTIFACT_LINEAR_TEAM ARTIFACT_LINEAR_PROJECT \
|
|
625
|
+
ARTIFACT_LINEAR_LABEL ARTIFACT_LINEAR_HINT; do
|
|
626
|
+
printf '%s=%q\n' "$key" "${!key}"
|
|
627
|
+
done
|
|
628
|
+
else
|
|
629
|
+
printf '%s\n' "$ARTIFACT_DIR"
|
|
630
|
+
fi
|
|
631
|
+
}
|
|
632
|
+
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
|
633
|
+
_artifact_store_cli "$@"
|
|
634
|
+
else
|
|
635
|
+
_ARTIFACT_AUTO_RESOLVE=1 resolve_artifact_store || :
|
|
636
|
+
fi
|
|
@@ -43,11 +43,16 @@ else
|
|
|
43
43
|
NC=''
|
|
44
44
|
fi
|
|
45
45
|
|
|
46
|
+
# Strip leading frontmatter before section extraction (identity metadata is
|
|
47
|
+
# not body; see ../references/artifact-store.md, Frontmatter).
|
|
48
|
+
# shellcheck source=artifact-body.sh
|
|
49
|
+
source "${SCRIPT_DIR}/artifact-body.sh"
|
|
50
|
+
|
|
46
51
|
# Extract a section from a markdown file (between ## heading and next ##)
|
|
47
52
|
_extract_section() {
|
|
48
53
|
local file="$1"
|
|
49
54
|
local section="$2"
|
|
50
|
-
sed -n "/^## ${section}/,/^## /p"
|
|
55
|
+
artifact_body "$file" | sed -n "/^## ${section}/,/^## /p" | head -n -1
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
# Extract paths from a markdown table (backtick-quoted first column)
|
|
@@ -59,7 +64,7 @@ _extract_table_paths() {
|
|
|
59
64
|
echo "$section_content" | grep "^|" | grep -v "^|[[:space:]]*-" | while IFS= read -r line; do
|
|
60
65
|
# Find the first backtick-quoted path in ANY column
|
|
61
66
|
local path
|
|
62
|
-
path=$(
|
|
67
|
+
path=$(grep -oE '`[^`]+/[^`]+`' <<<"$line" | head -1 | sed 's/`//g')
|
|
63
68
|
|
|
64
69
|
# If no backtick path with slash found, try first column without backticks
|
|
65
70
|
if [[ -z "$path" ]]; then
|
|
@@ -75,8 +80,10 @@ _extract_table_paths() {
|
|
|
75
80
|
[[ -z "$path" ]] && continue
|
|
76
81
|
|
|
77
82
|
if [[ "$skip_create" == "true" ]]; then
|
|
78
|
-
#
|
|
79
|
-
|
|
83
|
+
# Match with a here-string, not `echo | grep -q`: under pipefail an
|
|
84
|
+
# early-exiting reader SIGPIPEs the echo writer and a present CREATE
|
|
85
|
+
# reads as missing (YAN-1587).
|
|
86
|
+
if grep -qi "CREATE" <<<"$line"; then
|
|
80
87
|
echo "SKIP:$path"
|
|
81
88
|
continue
|
|
82
89
|
fi
|