@hxp-tools/godplans 0.0.0-stage → 2.0.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.
- package/CHANGELOG.md +1202 -0
- package/LICENSE +21 -0
- package/PROMPT.md +4006 -0
- package/README.md +245 -2
- package/bin/godplans.js +93 -0
- package/docs/ARCHITECTURE.md +136 -0
- package/docs/RELEASING.md +107 -0
- package/docs/assets/badge-approved.svg +12 -0
- package/docs/assets/badge-done.svg +11 -0
- package/docs/assets/badge-graded.svg +12 -0
- package/docs/assets/badge-validated.svg +10 -0
- package/docs/assets/hero.svg +37 -0
- package/docs/assets/quest-map.svg +53 -0
- package/evals/README.md +295 -0
- package/evals/cases/brownfield-cli/EXPECTATIONS +15 -0
- package/evals/cases/brownfield-cli/INPUT/package.json +9 -0
- package/evals/cases/brownfield-cli/INPUT/src/cli.js +4 -0
- package/evals/cases/brownfield-cli/INPUT/src/format.js +3 -0
- package/evals/cases/brownfield-cli/INPUT/test/cli.test.js +7 -0
- package/evals/cases/brownfield-cli/REQUEST.baseline.md +10 -0
- package/evals/cases/brownfield-cli/REQUEST.md +10 -0
- package/evals/cases/compliance-refusal/EXPECTATIONS +4 -0
- package/evals/cases/compliance-refusal/REQUEST.baseline.md +9 -0
- package/evals/cases/compliance-refusal/REQUEST.md +8 -0
- package/evals/cases/greenfield-saas/EXPECTATIONS +21 -0
- package/evals/cases/greenfield-saas/REQUEST.baseline.md +11 -0
- package/evals/cases/greenfield-saas/REQUEST.md +11 -0
- package/evals/cases/nested-pillars/EXPECTATIONS +12 -0
- package/evals/cases/nested-pillars/REQUEST.baseline.md +10 -0
- package/evals/cases/nested-pillars/REQUEST.md +11 -0
- package/evals/cases/observability-evidence/EXPECTATIONS +10 -0
- package/evals/cases/observability-evidence/REQUEST.baseline.md +10 -0
- package/evals/cases/observability-evidence/REQUEST.md +11 -0
- package/evals/cases/product-business/EXPECTATIONS +18 -0
- package/evals/cases/product-business/REQUEST.baseline.md +13 -0
- package/evals/cases/product-business/REQUEST.md +14 -0
- package/evals/cases/product-form-routing/EXPECTATIONS +13 -0
- package/evals/cases/product-form-routing/REQUEST.baseline.md +11 -0
- package/evals/cases/product-form-routing/REQUEST.md +11 -0
- package/evals/cases/prose-integrity/EXPECTATIONS +19 -0
- package/evals/cases/prose-integrity/REQUEST.baseline.md +19 -0
- package/evals/cases/prose-integrity/REQUEST.md +20 -0
- package/evals/cases/replan-preserves-history/EXPECTATIONS +9 -0
- package/evals/cases/replan-preserves-history/INPUT/.godplans/PLAN.mdx +115 -0
- package/evals/cases/replan-preserves-history/INPUT/package.json +5 -0
- package/evals/cases/replan-preserves-history/REQUEST.baseline.md +10 -0
- package/evals/cases/replan-preserves-history/REQUEST.md +10 -0
- package/evals/cases/stale-prepublication/EXPECTATIONS +10 -0
- package/evals/cases/stale-prepublication/REQUEST.baseline.md +12 -0
- package/evals/cases/stale-prepublication/REQUEST.md +13 -0
- package/evals/cases/stale-source-evidence/EXPECTATIONS +10 -0
- package/evals/cases/stale-source-evidence/INPUT/package.json +8 -0
- package/evals/cases/stale-source-evidence/REQUEST.baseline.md +11 -0
- package/evals/cases/stale-source-evidence/REQUEST.md +12 -0
- package/evals/cases/weekend-library/EXPECTATIONS +19 -0
- package/evals/cases/weekend-library/REQUEST.baseline.md +10 -0
- package/evals/cases/weekend-library/REQUEST.md +11 -0
- package/evals/cases-roster.txt +19 -0
- package/evals/external/GRADE.schema.json +39 -0
- package/evals/external/README.md +42 -0
- package/evals/external/RUBRIC.md +32 -0
- package/evals/metrics/context-cost.json +154 -0
- package/evals/outcomes/README.md +65 -0
- package/evals/outcomes/cases/tenant-notes-api/REQUEST.baseline.md +14 -0
- package/evals/outcomes/cases/tenant-notes-api/REQUEST.md +13 -0
- package/evals/outcomes/cases/tenant-notes-api/VERIFY.sh +13 -0
- package/evals/outcomes/results/2026-07-23-tenant-notes-api-codex/README.md +93 -0
- package/evals/outcomes/results/2026-07-23-tenant-notes-api-codex/treatment/plan/PLAN.json +547 -0
- package/evals/runners/claude-baseline.sh +4 -0
- package/evals/runners/claude-grade.sh +3 -0
- package/evals/runners/claude.sh +4 -0
- package/evals/runners/codex-baseline.sh +181 -0
- package/evals/runners/codex-builder.sh +96 -0
- package/evals/runners/codex-godaudits.sh +84 -0
- package/evals/runners/codex.sh +147 -0
- package/evals/runners/gemini-baseline.sh +4 -0
- package/evals/runners/gemini-grade.sh +3 -0
- package/evals/runners/gemini.sh +4 -0
- package/evals/runners/vendor-cli.sh +257 -0
- package/evals/runners/vendor-grade.sh +82 -0
- package/install.sh +323 -0
- package/package.json +91 -4
- package/requirements/skills-ref.txt +2 -0
- package/scripts/build-catalog.js +114 -0
- package/scripts/build-prompt.sh +257 -0
- package/scripts/context-metrics.js +118 -0
- package/scripts/eval-external.js +226 -0
- package/scripts/eval-matrix.sh +172 -0
- package/scripts/eval-outcome.js +143 -0
- package/scripts/eval.sh +321 -0
- package/scripts/lint-parity.js +331 -0
- package/scripts/lint.sh +743 -0
- package/scripts/outcome-summary.js +126 -0
- package/scripts/release-check.sh +108 -0
- package/scripts/release-prepare.js +41 -0
- package/scripts/summarize-eval.js +91 -0
- package/scripts/summarize-matrix.js +101 -0
- package/scripts/version-sync.js +65 -0
- package/skills/godplans/SKILL.md +192 -0
- package/skills/godplans/references/agent-memory.md +168 -0
- package/skills/godplans/references/architecture.md +189 -0
- package/skills/godplans/references/build.md +130 -0
- package/skills/godplans/references/business.md +252 -0
- package/skills/godplans/references/code-quality.md +165 -0
- package/skills/godplans/references/compliance.md +59 -0
- package/skills/godplans/references/database.md +157 -0
- package/skills/godplans/references/deploy.md +146 -0
- package/skills/godplans/references/discovery.md +297 -0
- package/skills/godplans/references/doc-set.md +243 -0
- package/skills/godplans/references/exemplar.md +228 -0
- package/skills/godplans/references/launch.md +162 -0
- package/skills/godplans/references/llm.md +132 -0
- package/skills/godplans/references/observe.md +178 -0
- package/skills/godplans/references/plan-format.md +340 -0
- package/skills/godplans/references/product.md +130 -0
- package/skills/godplans/references/repo.md +184 -0
- package/skills/godplans/references/roadmap.md +158 -0
- package/skills/godplans/references/security.md +156 -0
- package/skills/godplans/references/seo.md +133 -0
- package/skills/godplans/references/stack.md +133 -0
- package/skills/godplans/references/style-genome.md +198 -0
- package/skills/godplans/references/ui.md +153 -0
- package/skills/godplans/references/ux.md +150 -0
- package/skills/godplans/schemas/PLAN.schema.json +275 -0
- package/skills/godplans/schemas/PLAN.v1.schema.json +258 -0
- package/skills/godplans/scripts/plan-halflife.sh +76 -0
- package/skills/godplans/scripts/style-stats.py +630 -0
- package/skills/godplans/scripts/validate-plan.sh +1709 -0
- package/skills/godplans/templates/PLAN.template.mdx +269 -0
- package/tests/agent-memory-guidance.sh +32 -0
- package/tests/build-catalog.sh +81 -0
- package/tests/codex-runner.sh +139 -0
- package/tests/eval-harness.sh +377 -0
- package/tests/evidence-harnesses.sh +243 -0
- package/tests/fixtures/plan-json-v1-1.13.0.json +472 -0
- package/tests/install-regression.sh +246 -0
- package/tests/lib/plan-schema-check.js +163 -0
- package/tests/lint-selftest.sh +582 -0
- package/tests/package-contents.sh +143 -0
- package/tests/portable-prompt.test.sh +261 -0
- package/tests/release-tooling.sh +204 -0
- package/tests/run.sh +14 -0
- package/tests/script-usage.sh +37 -0
- package/tests/style-stats.sh +170 -0
- package/tests/validate-plan.sh +1970 -0
- package/tests/vendor-runner.sh +291 -0
|
@@ -0,0 +1,1709 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Portable structural validator for emitted PLAN.mdx files.
|
|
4
|
+
# Bash 3.2 and the Perl shipped with macOS are sufficient.
|
|
5
|
+
|
|
6
|
+
set -eu
|
|
7
|
+
|
|
8
|
+
ALLOW_PLANNING=0
|
|
9
|
+
PLAN_FILE=""
|
|
10
|
+
EMIT_JSON=""
|
|
11
|
+
DRIFT_PHASE=""
|
|
12
|
+
|
|
13
|
+
usage() {
|
|
14
|
+
echo "Usage: $0 [--allow-planning] [--emit-json PATH] [--drift-check PHASE] [PLAN.mdx]" >&2
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
while [ "$#" -gt 0 ]; do
|
|
18
|
+
case "$1" in
|
|
19
|
+
--allow-planning)
|
|
20
|
+
ALLOW_PLANNING=1
|
|
21
|
+
;;
|
|
22
|
+
--emit-json)
|
|
23
|
+
shift
|
|
24
|
+
if [ "$#" -eq 0 ]; then
|
|
25
|
+
usage
|
|
26
|
+
echo "--emit-json needs an output path" >&2
|
|
27
|
+
exit 2
|
|
28
|
+
fi
|
|
29
|
+
EMIT_JSON=$1
|
|
30
|
+
;;
|
|
31
|
+
--drift-check)
|
|
32
|
+
shift
|
|
33
|
+
if [ "$#" -eq 0 ]; then
|
|
34
|
+
usage
|
|
35
|
+
echo "--drift-check needs a phase number" >&2
|
|
36
|
+
exit 2
|
|
37
|
+
fi
|
|
38
|
+
DRIFT_PHASE=$1
|
|
39
|
+
case "$DRIFT_PHASE" in
|
|
40
|
+
''|*[!0-9]*|0)
|
|
41
|
+
usage
|
|
42
|
+
echo "--drift-check phase must be a positive integer" >&2
|
|
43
|
+
exit 2
|
|
44
|
+
;;
|
|
45
|
+
esac
|
|
46
|
+
;;
|
|
47
|
+
-h|--help)
|
|
48
|
+
usage
|
|
49
|
+
exit 0
|
|
50
|
+
;;
|
|
51
|
+
-*)
|
|
52
|
+
usage
|
|
53
|
+
echo "Unknown option: $1" >&2
|
|
54
|
+
exit 2
|
|
55
|
+
;;
|
|
56
|
+
*)
|
|
57
|
+
if [ -n "$PLAN_FILE" ]; then
|
|
58
|
+
usage
|
|
59
|
+
echo "Only one PLAN.mdx path may be supplied" >&2
|
|
60
|
+
exit 2
|
|
61
|
+
fi
|
|
62
|
+
PLAN_FILE=$1
|
|
63
|
+
;;
|
|
64
|
+
esac
|
|
65
|
+
shift
|
|
66
|
+
done
|
|
67
|
+
|
|
68
|
+
[ -n "$PLAN_FILE" ] || PLAN_FILE=".godplans/PLAN.mdx"
|
|
69
|
+
|
|
70
|
+
if [ ! -f "$PLAN_FILE" ]; then
|
|
71
|
+
echo "FAIL $PLAN_FILE: file not found" >&2
|
|
72
|
+
exit 1
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
if ! command -v perl >/dev/null 2>&1; then
|
|
76
|
+
echo "FAIL $PLAN_FILE: perl not found; validation cannot fail open" >&2
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
exec perl -CSD - "$PLAN_FILE" "$ALLOW_PLANNING" "$EMIT_JSON" "$DRIFT_PHASE" <<'PERL'
|
|
81
|
+
use strict;
|
|
82
|
+
use warnings;
|
|
83
|
+
use Digest::SHA qw(sha256_hex);
|
|
84
|
+
use Encode ();
|
|
85
|
+
use JSON::PP ();
|
|
86
|
+
use Time::Local qw(timegm);
|
|
87
|
+
|
|
88
|
+
my ($plan_file, $allow_planning, $emit_json, $drift_phase) = @ARGV;
|
|
89
|
+
my @errors;
|
|
90
|
+
my %inventory;
|
|
91
|
+
my %recheck_inventory;
|
|
92
|
+
my %domain_disposition;
|
|
93
|
+
my %domain_reason;
|
|
94
|
+
my @json_decisions;
|
|
95
|
+
|
|
96
|
+
sub fail {
|
|
97
|
+
push @errors, $_[0];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
sub trim {
|
|
101
|
+
my ($value) = @_;
|
|
102
|
+
$value = '' unless defined $value;
|
|
103
|
+
$value =~ s/^\s+//;
|
|
104
|
+
$value =~ s/\s+$//;
|
|
105
|
+
return $value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
# YAML allows one layer of quotes or a trailing comment; neither is the value.
|
|
109
|
+
sub yaml_value {
|
|
110
|
+
my $value = trim($_[0]);
|
|
111
|
+
$value =~ s/(?:^|\s+)#.*$// unless $value =~ s/^(["'])(.*)\1(?:\s+#.*)?$/$2/;
|
|
112
|
+
return $value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# One command in backticks with something to run; a manual step cannot be rerun.
|
|
116
|
+
sub not_command {
|
|
117
|
+
return $_[0] !~ /^`[^`]*\S[^`]*`$/ || $_[0] =~ /^`\s*manual:/i;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
sub task_has_requirement {
|
|
121
|
+
my ($task, $requirement_id) = @_;
|
|
122
|
+
return 0 unless exists $task->{fields}{Requirements};
|
|
123
|
+
return 0 unless @{$task->{fields}{Requirements}} == 1;
|
|
124
|
+
my @requirement_ids = split /\s*,\s*/, $task->{fields}{Requirements}[0], -1;
|
|
125
|
+
return scalar grep { $_ eq $requirement_id } @requirement_ids;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
sub dependency_ids {
|
|
129
|
+
my $depends = $_[0]{fields}{'Depends on'};
|
|
130
|
+
return () unless $depends && @$depends == 1 && $depends->[0] ne 'none';
|
|
131
|
+
return split /\s*,\s*/, $depends->[0], -1;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
sub task_depends_on {
|
|
135
|
+
return scalar grep { $_ eq $_[1] } dependency_ids($_[0]);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
open my $plan_fh, '<:raw', $plan_file
|
|
139
|
+
or bail("cannot read: $!");
|
|
140
|
+
my $plan_bytes = do { local $/; <$plan_fh> };
|
|
141
|
+
close $plan_fh;
|
|
142
|
+
# Decode strictly: a lenient read carries substituted text into the sidecar.
|
|
143
|
+
my $plan_text = eval { Encode::decode('UTF-8', $plan_bytes, Encode::FB_CROAK() | Encode::LEAVE_SRC()) };
|
|
144
|
+
if (!defined $plan_text) {
|
|
145
|
+
fail('plan is not valid UTF-8');
|
|
146
|
+
$plan_text = Encode::decode('UTF-8', $plan_bytes);
|
|
147
|
+
}
|
|
148
|
+
fail('plan starts with a UTF-8 byte order mark; save it without one')
|
|
149
|
+
if $plan_text =~ s/^\x{FEFF}//;
|
|
150
|
+
my @lines = split /\n/, $plan_text;
|
|
151
|
+
# Markdown ignores trailing whitespace, so headings and labels do too.
|
|
152
|
+
s/[ \t\r]+$// for @lines;
|
|
153
|
+
|
|
154
|
+
for my $index (0 .. $#lines) {
|
|
155
|
+
fail('banned Unicode on line ' . ($index + 1))
|
|
156
|
+
if $lines[$index] =~ /[\x{200D}\x{2013}\x{2014}\x{2018}-\x{201F}\x{2026}\x{20E3}\x{2190}-\x{21FF}\x{231A}-\x{231B}\x{2328}\x{23CF}\x{23E9}-\x{23F3}\x{23F8}-\x{23FA}\x{2500}-\x{259F}\x{2600}-\x{27BF}\x{27F0}-\x{27FF}\x{2900}-\x{297F}\x{2B00}-\x{2BFF}\x{FE0F}\x{1F000}-\x{1FBFF}\x{E0020}-\x{E007F}]/;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
my $frontmatter_end = -1;
|
|
160
|
+
if (!@lines || $lines[0] ne '---') {
|
|
161
|
+
fail('frontmatter must begin on line 1 with ---');
|
|
162
|
+
} else {
|
|
163
|
+
for my $index (1 .. $#lines) {
|
|
164
|
+
if ($lines[$index] eq '---') {
|
|
165
|
+
$frontmatter_end = $index;
|
|
166
|
+
last;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
fail('frontmatter is missing its closing ---') if $frontmatter_end < 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
# Fenced examples are quoted text: blank them for structural scans only.
|
|
173
|
+
my @raw_lines = @lines;
|
|
174
|
+
my ($fence, $fence_line) = ('', 0);
|
|
175
|
+
for my $index ($frontmatter_end + 1 .. $#lines) {
|
|
176
|
+
my ($run) = $lines[$index] =~ /^\s*(`{3,}|~{3,})/;
|
|
177
|
+
if ($fence eq '') {
|
|
178
|
+
next unless defined $run;
|
|
179
|
+
($fence, $fence_line) = ($run, $index + 1);
|
|
180
|
+
} elsif (defined $run && index($run, $fence) == 0 && $lines[$index] =~ /^\s*[`~]+\s*$/) {
|
|
181
|
+
$fence = '';
|
|
182
|
+
}
|
|
183
|
+
$lines[$index] = '';
|
|
184
|
+
}
|
|
185
|
+
if ($fence ne '') {
|
|
186
|
+
fail("code fence opened on line $fence_line is never closed");
|
|
187
|
+
@lines[$fence_line .. $#lines] = @raw_lines[$fence_line .. $#lines];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
# Line indexes under every $heading, up to the next heading of its level or above.
|
|
191
|
+
sub section {
|
|
192
|
+
my ($heading) = @_;
|
|
193
|
+
my $level = length(($heading =~ /^(#+)/)[0]);
|
|
194
|
+
my ($inside, @body);
|
|
195
|
+
for my $index (0 .. $#lines) {
|
|
196
|
+
if ($lines[$index] =~ /^#{1,$level} /) {
|
|
197
|
+
$inside = $lines[$index] eq $heading;
|
|
198
|
+
next;
|
|
199
|
+
}
|
|
200
|
+
push @body, $index if $inside;
|
|
201
|
+
}
|
|
202
|
+
return @body;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
sub section_count {
|
|
206
|
+
my $count = grep { $_ eq "## $_[0]" } @lines;
|
|
207
|
+
fail("expected exactly one ## $_[0] section, found $count") if $count != 1;
|
|
208
|
+
return $count;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
my %frontmatter;
|
|
212
|
+
my %counter;
|
|
213
|
+
my %top_key_count;
|
|
214
|
+
my $has_progress = 0;
|
|
215
|
+
if ($frontmatter_end > 0) {
|
|
216
|
+
for my $index (1 .. $frontmatter_end - 1) {
|
|
217
|
+
my $line = $lines[$index];
|
|
218
|
+
if ($line =~ /^([a-z_]+):(?:[ \t]*(.*))?$/) {
|
|
219
|
+
my ($key, $value) = ($1, yaml_value($2));
|
|
220
|
+
$top_key_count{$key}++;
|
|
221
|
+
$frontmatter{$key} = $value;
|
|
222
|
+
$has_progress = 1 if $key eq 'progress';
|
|
223
|
+
} elsif ($line =~ /^ (phases_total|phases_done|tasks_total|tasks_done):[ \t]*(.*)$/) {
|
|
224
|
+
my ($key, $value) = ($1, yaml_value($2));
|
|
225
|
+
fail("duplicate progress counter: $key") if exists $counter{$key};
|
|
226
|
+
$counter{$key} = $value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
for my $key (qw(name plan_version status created updated mode product_form archetype archetype_confidence overlays public_release source_revision input_digest validated_at domains_applicable domains_deferred domains_excluded)) {
|
|
232
|
+
if (!exists $frontmatter{$key}) {
|
|
233
|
+
fail("missing frontmatter field: $key");
|
|
234
|
+
} elsif ($frontmatter{$key} eq '') {
|
|
235
|
+
fail("frontmatter field is empty: $key");
|
|
236
|
+
}
|
|
237
|
+
fail("duplicate frontmatter field: $key")
|
|
238
|
+
if ($top_key_count{$key} || 0) > 1;
|
|
239
|
+
}
|
|
240
|
+
fail('missing frontmatter field: progress') unless $has_progress;
|
|
241
|
+
fail('duplicate frontmatter field: progress')
|
|
242
|
+
if ($top_key_count{progress} || 0) > 1;
|
|
243
|
+
|
|
244
|
+
if (exists $frontmatter{plan_version}
|
|
245
|
+
&& $frontmatter{plan_version} !~ /^[1-9][0-9]*$/) {
|
|
246
|
+
fail("plan_version must be a positive integer, found '$frontmatter{plan_version}'");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
my %allowed_status = map { $_ => 1 } qw(planning approved executing done);
|
|
250
|
+
if (exists $frontmatter{status} && !$allowed_status{$frontmatter{status}}) {
|
|
251
|
+
fail("invalid status '$frontmatter{status}'; expected planning, approved, executing, or done");
|
|
252
|
+
} elsif (!$allow_planning
|
|
253
|
+
&& exists $frontmatter{status}
|
|
254
|
+
&& $frontmatter{status} ne 'approved'
|
|
255
|
+
&& $frontmatter{status} ne 'executing') {
|
|
256
|
+
fail("execution requires status approved or executing, found '$frontmatter{status}'");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
my %allowed_mode = map { $_ => 1 } qw(greenfield brownfield replan);
|
|
260
|
+
if (exists $frontmatter{mode} && !$allowed_mode{$frontmatter{mode}}) {
|
|
261
|
+
fail("invalid mode '$frontmatter{mode}'; expected greenfield, brownfield, or replan");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
my %allowed_product_form = map { $_ => 1 } qw(web-application api-or-service cli-or-sdk mobile-or-desktop data-or-ml infrastructure-or-iac);
|
|
265
|
+
if (exists $frontmatter{product_form} && !$allowed_product_form{$frontmatter{product_form}}) {
|
|
266
|
+
fail("invalid product_form '$frontmatter{product_form}'; expected web-application, api-or-service, cli-or-sdk, mobile-or-desktop, data-or-ml, or infrastructure-or-iac");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
# The nine archetypes discovery.md scores; a merged hybrid is not one of them.
|
|
270
|
+
my @archetypes = qw(cli-tool library api-service saas-dashboard marketing-site mobile-app ml-pipeline extension game);
|
|
271
|
+
my %allowed_archetype = map { $_ => 1 } @archetypes;
|
|
272
|
+
fail("invalid archetype '$frontmatter{archetype}'; expected unknown or one of " . join(', ', @archetypes))
|
|
273
|
+
if ($frontmatter{archetype} || 'unknown') ne 'unknown' && !$allowed_archetype{$frontmatter{archetype}};
|
|
274
|
+
|
|
275
|
+
my %allowed_confidence = map { $_ => 1 } qw(high medium low);
|
|
276
|
+
if (exists $frontmatter{archetype_confidence}
|
|
277
|
+
&& !$allowed_confidence{$frontmatter{archetype_confidence}}) {
|
|
278
|
+
fail("invalid archetype_confidence '$frontmatter{archetype_confidence}'; expected high, medium, or low");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
# An overlay answers what extra obligations a project carries, never what it is.
|
|
282
|
+
# Overlays are additive: each one forbids excluding the domains it covers, so a
|
|
283
|
+
# list written to add obligations can never be read as a licence to trim.
|
|
284
|
+
my %overlay_domains = (
|
|
285
|
+
'ai-system' => ['llm'],
|
|
286
|
+
'public-ui' => ['ui', 'seo'],
|
|
287
|
+
'shipped-artifact' => ['deploy'],
|
|
288
|
+
'operated-by-others' => ['observe', 'deploy'],
|
|
289
|
+
'regulated-data' => ['database'],
|
|
290
|
+
'agent-skill-package' => ['agent-memory'],
|
|
291
|
+
'monetized' => ['business'],
|
|
292
|
+
);
|
|
293
|
+
my @overlays;
|
|
294
|
+
my %overlay_declared;
|
|
295
|
+
if (exists $frontmatter{overlays}) {
|
|
296
|
+
my $raw = trim($frontmatter{overlays});
|
|
297
|
+
if ($raw !~ /^\[(.*)\]$/) {
|
|
298
|
+
fail('frontmatter overlays must be a single inline list such as [ai-system] or []');
|
|
299
|
+
} else {
|
|
300
|
+
for my $overlay (split /\s*,\s*/, $1, -1) {
|
|
301
|
+
$overlay = trim($overlay);
|
|
302
|
+
next if $overlay eq '';
|
|
303
|
+
if (!exists $overlay_domains{$overlay}) {
|
|
304
|
+
fail("frontmatter overlays names unknown overlay $overlay; expected ai-system, public-ui, shipped-artifact, operated-by-others, regulated-data, agent-skill-package, or monetized");
|
|
305
|
+
next;
|
|
306
|
+
}
|
|
307
|
+
fail("frontmatter overlays lists $overlay twice") if $overlay_declared{$overlay}++;
|
|
308
|
+
push @overlays, $overlay;
|
|
309
|
+
}
|
|
310
|
+
@overlays = sort @overlays;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
my %overlay_protected;
|
|
314
|
+
for my $overlay (@overlays) {
|
|
315
|
+
$overlay_protected{$_} = $overlay for @{$overlay_domains{$overlay}};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (exists $frontmatter{public_release}
|
|
319
|
+
&& $frontmatter{public_release} ne 'true'
|
|
320
|
+
&& $frontmatter{public_release} ne 'false') {
|
|
321
|
+
fail('public_release must be true or false');
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (exists $frontmatter{source_revision}
|
|
325
|
+
&& $frontmatter{source_revision} ne 'none'
|
|
326
|
+
&& $frontmatter{source_revision} !~ /^[0-9a-f]{40,64}$/) {
|
|
327
|
+
fail('source_revision must be none or a full lowercase hexadecimal revision');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (exists $frontmatter{input_digest}
|
|
331
|
+
&& $frontmatter{input_digest} !~ /^sha256:[0-9a-f]{64}$/) {
|
|
332
|
+
fail('input_digest must be sha256 followed by 64 lowercase hexadecimal characters');
|
|
333
|
+
} elsif (exists $frontmatter{input_digest}
|
|
334
|
+
&& $frontmatter{input_digest} eq 'sha256:' . ('0' x 64)) {
|
|
335
|
+
fail('input_digest must not use the all-zero placeholder');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (exists $frontmatter{validated_at}
|
|
339
|
+
&& $frontmatter{validated_at} !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$/) {
|
|
340
|
+
fail('validated_at must use UTC ISO-8601 form YYYY-MM-DDTHH:MM:SSZ');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
for my $key (qw(created updated)) {
|
|
344
|
+
if (exists $frontmatter{$key}
|
|
345
|
+
&& $frontmatter{$key} !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/) {
|
|
346
|
+
fail("$key must use YYYY-MM-DD, found '$frontmatter{$key}'");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
# Well-formed is not enough: the sidecar promises a date on the calendar.
|
|
351
|
+
for my $key (qw(created updated validated_at)) {
|
|
352
|
+
my ($y, $m, $d, $h, $min, $s) = ($frontmatter{$key} || '')
|
|
353
|
+
=~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})(?:T([0-9]{2}):([0-9]{2}):([0-9]{2})Z)?$/;
|
|
354
|
+
fail("$key $frontmatter{$key} is not a real calendar date and time")
|
|
355
|
+
if defined $y && !eval { timegm($s || 0, $min || 0, $h || 0, $d, $m - 1, $y); 1 };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
for my $key (qw(phases_total phases_done tasks_total tasks_done)) {
|
|
359
|
+
if (!exists $counter{$key}) {
|
|
360
|
+
fail("missing progress counter: $key");
|
|
361
|
+
} elsif ($counter{$key} !~ /^[0-9]+$/) {
|
|
362
|
+
fail("progress counter $key must be a non-negative integer, found '$counter{$key}'");
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
my %local_requirements;
|
|
367
|
+
for my $index (section('## Requirements')) {
|
|
368
|
+
$local_requirements{$1} = 1
|
|
369
|
+
if $lines[$index] =~ /^(R-[0-9]+\.[0-9]+):/ || $lines[$index] =~ /^\|\s*(R-[0-9]+\.[0-9]+)\s*\|/;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
my %catalog_max = (
|
|
373
|
+
ARCH => 24,
|
|
374
|
+
BIZ => 26,
|
|
375
|
+
BUILD => 20,
|
|
376
|
+
CODE => 24,
|
|
377
|
+
DB => 23,
|
|
378
|
+
DEPLOY => 18,
|
|
379
|
+
DNA => 24,
|
|
380
|
+
LAUNCH => 22,
|
|
381
|
+
LLM => 23,
|
|
382
|
+
MEM => 22,
|
|
383
|
+
OBS => 22,
|
|
384
|
+
PRD => 17,
|
|
385
|
+
REPO => 25,
|
|
386
|
+
ROAD => 21,
|
|
387
|
+
SEC => 30,
|
|
388
|
+
SEO => 22,
|
|
389
|
+
STACK => 21,
|
|
390
|
+
UI => 21,
|
|
391
|
+
UX => 20,
|
|
392
|
+
);
|
|
393
|
+
my %catalog_requirements;
|
|
394
|
+
for my $prefix (keys %catalog_max) {
|
|
395
|
+
for my $number (1 .. $catalog_max{$prefix}) {
|
|
396
|
+
$catalog_requirements{"R-$prefix-$number"} = 1;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
# Generated from references/doc-set.md by scripts/build-catalog.js. Values are
|
|
401
|
+
# '<owner module>|<durability>'. The id prefix is the lifecycle stage.
|
|
402
|
+
my %doc_catalog = (
|
|
403
|
+
'assure.accessibility-inputs' => 'ui|evidence',
|
|
404
|
+
'assure.dependency-inventory' => 'repo|evidence',
|
|
405
|
+
'assure.privacy-record' => 'security|durable',
|
|
406
|
+
'assure.scanning-index' => 'repo|evidence',
|
|
407
|
+
'assure.threat-model' => 'security|durable',
|
|
408
|
+
'build.agent-memory' => 'agent-memory|durable',
|
|
409
|
+
'build.api-reference' => 'architecture|durable',
|
|
410
|
+
'build.codebase-map' => 'agent-memory|durable',
|
|
411
|
+
'build.config-reference' => 'stack|durable',
|
|
412
|
+
'build.contributing' => 'repo|durable',
|
|
413
|
+
'build.dev-setup' => 'repo|durable',
|
|
414
|
+
'build.feature-flags' => 'deploy|durable',
|
|
415
|
+
'build.llms-txt' => 'seo|durable',
|
|
416
|
+
'build.readme' => 'repo|durable',
|
|
417
|
+
'build.style-genome' => 'style-genome|durable',
|
|
418
|
+
'decide.adr' => 'architecture|durable',
|
|
419
|
+
'decide.design-proposal' => 'architecture|transient',
|
|
420
|
+
'design.api-contract' => 'architecture|durable',
|
|
421
|
+
'design.capacity-model' => 'architecture|durable',
|
|
422
|
+
'design.data-model' => 'database|durable',
|
|
423
|
+
'design.integration-map' => 'architecture|durable',
|
|
424
|
+
'design.metrics-register' => 'business|durable',
|
|
425
|
+
'design.ui-spec' => 'ui|durable',
|
|
426
|
+
'frame.business-case' => 'business|durable',
|
|
427
|
+
'frame.glossary' => 'style-genome|durable',
|
|
428
|
+
'frame.objective' => 'product|durable',
|
|
429
|
+
'frame.stakeholders' => 'repo|durable',
|
|
430
|
+
'govern.changelog' => 'repo|durable',
|
|
431
|
+
'govern.closeout' => 'roadmap|durable',
|
|
432
|
+
'govern.manifest' => 'repo|durable',
|
|
433
|
+
'govern.ownership' => 'repo|durable',
|
|
434
|
+
'govern.security-policy' => 'repo|durable',
|
|
435
|
+
'operate.oncall' => 'observe|durable',
|
|
436
|
+
'operate.postmortem' => 'observe|evidence',
|
|
437
|
+
'operate.readiness-review' => 'deploy|evidence',
|
|
438
|
+
'operate.recovery' => 'deploy|durable',
|
|
439
|
+
'operate.runbook' => 'observe|durable',
|
|
440
|
+
'operate.slo' => 'observe|durable',
|
|
441
|
+
'retire.archive-manifest' => 'roadmap|evidence',
|
|
442
|
+
'retire.deprecation-notice' => 'business|evidence',
|
|
443
|
+
'serve.release-notes' => 'business|durable',
|
|
444
|
+
'serve.support-policy' => 'launch|durable',
|
|
445
|
+
'serve.user-guide' => 'launch|durable',
|
|
446
|
+
'verify.dod' => 'product|durable',
|
|
447
|
+
'verify.test-strategy' => 'code-quality|durable',
|
|
448
|
+
'verify.traceability' => 'roadmap|durable',
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
# Field lines; a 4-space line that is not a list item continues the field above.
|
|
452
|
+
sub task_fields {
|
|
453
|
+
my ($start, $names) = @_;
|
|
454
|
+
my (%fields, $last);
|
|
455
|
+
for my $index ($start .. $#lines) {
|
|
456
|
+
my $line = $lines[$index];
|
|
457
|
+
last if $line =~ /^(?:~~\s*-?|-)\s*\[[^]]*\]\s*GP-/ || $line =~ /^## Phase [1-9][0-9]*:/;
|
|
458
|
+
if ($line =~ /^ - ($names):[ \t]*(.*)$/) {
|
|
459
|
+
push @{$fields{$1}}, trim($2);
|
|
460
|
+
$last = $1;
|
|
461
|
+
} elsif (defined $last && $line =~ /^ {4,}(?![-*+] )\S/) {
|
|
462
|
+
$fields{$last}[-1] = trim($fields{$last}[-1] . ' ' . trim($line));
|
|
463
|
+
} else {
|
|
464
|
+
undef $last;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return \%fields;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
my @phases;
|
|
471
|
+
my @tasks;
|
|
472
|
+
my @superseded_tasks;
|
|
473
|
+
my %task_definitions;
|
|
474
|
+
my %all_task_definitions;
|
|
475
|
+
my $current_phase = -1;
|
|
476
|
+
for (my $index = 0; $index <= $#lines; $index++) {
|
|
477
|
+
my $line = $lines[$index];
|
|
478
|
+
if ($line =~ /^## Phase ([1-9][0-9]*):\s*(.+?)\s*$/) {
|
|
479
|
+
push @phases, {
|
|
480
|
+
number => $1,
|
|
481
|
+
name => $2,
|
|
482
|
+
tasks => [],
|
|
483
|
+
line => $index + 1,
|
|
484
|
+
wave => 0,
|
|
485
|
+
};
|
|
486
|
+
$current_phase = $#phases;
|
|
487
|
+
next;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if ($line =~ /^- \[([ x])\] (GP-[1-9][0-9]{2,})\b/) {
|
|
491
|
+
my ($box, $id) = ($1, $2);
|
|
492
|
+
my ($wave_phase, $wave, $wave_tag, $parallel);
|
|
493
|
+
if ($line =~ /^- \[[ x]\] \Q$id\E (\[P\] )?\[W([1-9][0-9]*)\.([1-9][0-9]*)\] \S/) {
|
|
494
|
+
($parallel, $wave_phase, $wave) = (defined $1 ? 1 : 0, $2, $3);
|
|
495
|
+
$wave_tag = "W$2.$3";
|
|
496
|
+
} else {
|
|
497
|
+
fail("$id has malformed task heading");
|
|
498
|
+
}
|
|
499
|
+
my $task = {
|
|
500
|
+
id => $id,
|
|
501
|
+
done => $box eq 'x' ? 1 : 0,
|
|
502
|
+
fields => task_fields($index + 1, 'Files|Depends on|Reuses|Acceptance|Verify|Requirements'),
|
|
503
|
+
line => $index + 1,
|
|
504
|
+
phase => $current_phase,
|
|
505
|
+
wave => $wave_tag,
|
|
506
|
+
parallel => $parallel ? 1 : 0,
|
|
507
|
+
};
|
|
508
|
+
push @tasks, $task;
|
|
509
|
+
push @{$phases[$current_phase]{tasks}}, $#tasks if $current_phase >= 0;
|
|
510
|
+
fail("$id is not inside a numbered phase") if $current_phase < 0;
|
|
511
|
+
if (defined $wave_phase && $current_phase >= 0) {
|
|
512
|
+
my $phase = $phases[$current_phase];
|
|
513
|
+
fail("$id wave phase $wave_phase does not match Phase $phase->{number}")
|
|
514
|
+
if $wave_phase != $phase->{number};
|
|
515
|
+
# Executors take waves in order, so a lower wave written later runs late.
|
|
516
|
+
fail("$id [$wave_tag] follows a W$phase->{number}.$phase->{wave} task; waves within a phase must not go backwards")
|
|
517
|
+
if $wave < $phase->{wave};
|
|
518
|
+
$phase->{wave} = $wave if $wave > $phase->{wave};
|
|
519
|
+
}
|
|
520
|
+
if (exists $task_definitions{$id}) {
|
|
521
|
+
fail("duplicate task definition ID $id on lines $task_definitions{$id} and " . ($index + 1));
|
|
522
|
+
} else {
|
|
523
|
+
$task_definitions{$id} = $index + 1;
|
|
524
|
+
}
|
|
525
|
+
if (exists $all_task_definitions{$id}) {
|
|
526
|
+
fail("task ID $id appears in active and superseded history on lines $all_task_definitions{$id} and " . ($index + 1));
|
|
527
|
+
} else {
|
|
528
|
+
$all_task_definitions{$id} = $index + 1;
|
|
529
|
+
}
|
|
530
|
+
} elsif ($line =~ /^~~- \[([ x])\] (GP-[1-9][0-9]{2,})\b.*~~$/) {
|
|
531
|
+
my ($box, $id) = ($1, $2);
|
|
532
|
+
my $task = {
|
|
533
|
+
id => $id,
|
|
534
|
+
fields => task_fields($index + 1, 'Superseded|Requirements'),
|
|
535
|
+
line => $index + 1,
|
|
536
|
+
phase => $current_phase,
|
|
537
|
+
};
|
|
538
|
+
$phases[$current_phase]{superseded}++ if $current_phase >= 0;
|
|
539
|
+
fail("superseded task $id must remain unchecked") if $box eq 'x';
|
|
540
|
+
if (exists $all_task_definitions{$id}) {
|
|
541
|
+
fail("duplicate historical task ID $id on lines $all_task_definitions{$id} and " . ($index + 1));
|
|
542
|
+
} else {
|
|
543
|
+
$all_task_definitions{$id} = $index + 1;
|
|
544
|
+
}
|
|
545
|
+
for my $field ('Superseded', 'Requirements') {
|
|
546
|
+
my $count = exists $task->{fields}{$field}
|
|
547
|
+
? scalar @{$task->{fields}{$field}} : 0;
|
|
548
|
+
fail("superseded task $id missing required field: $field")
|
|
549
|
+
if $count == 0;
|
|
550
|
+
fail("superseded task $id has duplicate required field: $field")
|
|
551
|
+
if $count > 1;
|
|
552
|
+
fail("superseded task $id has empty required field: $field")
|
|
553
|
+
if $count == 1 && $task->{fields}{$field}[0] eq '';
|
|
554
|
+
}
|
|
555
|
+
push @superseded_tasks, $task;
|
|
556
|
+
} elsif ($line =~ /^~~\s*-?\s*\[[^]]*\]\s*GP-/) {
|
|
557
|
+
fail('malformed superseded task on line ' . ($index + 1));
|
|
558
|
+
} elsif ($line =~ /^-\s*\[[^]]*\]\s*GP-/) {
|
|
559
|
+
fail('malformed task definition on line ' . ($index + 1));
|
|
560
|
+
} elsif ($current_phase >= 0 && $line =~ /^Checkpoint:[ \t]*(\S.*)$/) {
|
|
561
|
+
fail("Phase $phases[$current_phase]{number} has duplicate Checkpoint")
|
|
562
|
+
if defined $phases[$current_phase]{checkpoint};
|
|
563
|
+
$phases[$current_phase]{checkpoint} = $1;
|
|
564
|
+
} elsif ($current_phase >= 0 && $line =~ /^Checkpoint verify:[ \t]*(.*?)[ \t]*$/) {
|
|
565
|
+
my ($phase, $command) = ($phases[$current_phase], $1);
|
|
566
|
+
fail("Phase $phase->{number} has duplicate Checkpoint verify")
|
|
567
|
+
if defined $phase->{checkpoint_verify};
|
|
568
|
+
fail("Phase $phase->{number} Checkpoint verify must be one executable command in backticks")
|
|
569
|
+
if not_command($command);
|
|
570
|
+
($phase->{checkpoint_verify} = $command) =~ s/^`(.*)`$/$1/;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
for my $index (0 .. $#phases) {
|
|
575
|
+
my $expected = $index + 1;
|
|
576
|
+
my $found = $phases[$index]{number};
|
|
577
|
+
fail("phase numbers must be sequential: expected Phase $expected, found Phase $found")
|
|
578
|
+
if $found != $expected;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
my @required_fields = ('Files', 'Depends on', 'Reuses', 'Acceptance', 'Verify', 'Requirements');
|
|
582
|
+
for my $task (@tasks) {
|
|
583
|
+
for my $field (@required_fields) {
|
|
584
|
+
my $count = exists $task->{fields}{$field} ? scalar @{$task->{fields}{$field}} : 0;
|
|
585
|
+
if ($count == 0) {
|
|
586
|
+
fail("$task->{id} missing required field: $field");
|
|
587
|
+
} elsif ($count > 1) {
|
|
588
|
+
fail("$task->{id} has duplicate required field: $field");
|
|
589
|
+
} elsif ($task->{fields}{$field}[0] eq '') {
|
|
590
|
+
fail("$task->{id} has empty required field: $field");
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (exists $task->{fields}{'Depends on'} && @{$task->{fields}{'Depends on'}} == 1) {
|
|
595
|
+
my $depends = $task->{fields}{'Depends on'}[0];
|
|
596
|
+
if ($depends ne 'none') {
|
|
597
|
+
my @dependencies = split /\s*,\s*/, $depends, -1;
|
|
598
|
+
if (!@dependencies || grep { $_ !~ /^GP-[1-9][0-9]{2,}$/ } @dependencies) {
|
|
599
|
+
fail("$task->{id} has malformed Depends on value '$depends'");
|
|
600
|
+
} else {
|
|
601
|
+
for my $dependency (@dependencies) {
|
|
602
|
+
if ($dependency eq $task->{id}) {
|
|
603
|
+
fail("$task->{id} depends on itself");
|
|
604
|
+
} elsif (!exists $task_definitions{$dependency}) {
|
|
605
|
+
fail("$task->{id} depends on undefined task $dependency");
|
|
606
|
+
} elsif ($task_definitions{$dependency} > $task->{line}) {
|
|
607
|
+
fail("$task->{id} depends on later task $dependency");
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (exists $task->{fields}{Verify} && @{$task->{fields}{Verify}} == 1) {
|
|
615
|
+
fail("$task->{id} Verify must be one executable command in backticks")
|
|
616
|
+
if not_command($task->{fields}{Verify}[0]);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (exists $task->{fields}{Requirements} && @{$task->{fields}{Requirements}} == 1) {
|
|
620
|
+
my $requirements = $task->{fields}{Requirements}[0];
|
|
621
|
+
my @requirement_ids = split /\s*,\s*/, $requirements, -1;
|
|
622
|
+
if (!@requirement_ids
|
|
623
|
+
|| grep { $_ !~ /^R-(?:[0-9]+\.[0-9]+|[A-Z][A-Z0-9-]*-[0-9]+)$/ } @requirement_ids) {
|
|
624
|
+
fail("$task->{id} has malformed Requirements value '$requirements'");
|
|
625
|
+
} else {
|
|
626
|
+
for my $requirement_id (@requirement_ids) {
|
|
627
|
+
next if $local_requirements{$requirement_id};
|
|
628
|
+
next if $catalog_requirements{$requirement_id};
|
|
629
|
+
fail("$task->{id} cites undefined requirement $requirement_id");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
# [P] promises an executor it may run this task beside its wave siblings. Check
|
|
636
|
+
# the promise instead of trusting it: a shared path means two concurrent writers
|
|
637
|
+
# to one file, the fictional parallelism the roadmap module already refuses.
|
|
638
|
+
my %wave_members;
|
|
639
|
+
for my $task_index (0 .. $#tasks) {
|
|
640
|
+
my $task = $tasks[$task_index];
|
|
641
|
+
next if $task->{done};
|
|
642
|
+
next unless defined $task->{wave};
|
|
643
|
+
push @{$wave_members{$task->{wave}}}, $task_index;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
# Compare paths, not spellings; a trailing slash names a directory.
|
|
647
|
+
my %task_files;
|
|
648
|
+
for my $task_index (0 .. $#tasks) {
|
|
649
|
+
my $files = $tasks[$task_index]{fields}{Files};
|
|
650
|
+
next unless $files && @$files == 1;
|
|
651
|
+
my %paths;
|
|
652
|
+
for my $entry (split /\s*,\s*(?![^()]*\))/, $files->[0]) {
|
|
653
|
+
my ($path) = $entry =~ /`([^`]+)`/ ? ($1) : ($entry =~ /^\s*(\S+)/);
|
|
654
|
+
next if !defined $path || lc $path eq 'none';
|
|
655
|
+
$path =~ s{/+}{/}g;
|
|
656
|
+
$path =~ s{^(?:\./)+}{};
|
|
657
|
+
$paths{$path} = 1 if $path ne '';
|
|
658
|
+
}
|
|
659
|
+
$task_files{$task_index} = \%paths;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
sub paths_overlap {
|
|
663
|
+
my ($x, $y) = @_;
|
|
664
|
+
return $x eq $y || ($x =~ m{/$} && index($y, $x) == 0) || ($y =~ m{/$} && index($x, $y) == 0);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
my %ancestors;
|
|
668
|
+
for my $task (@tasks) {
|
|
669
|
+
my %set;
|
|
670
|
+
%set = (%set, $_ => 1, %{$ancestors{$_} || {}}) for dependency_ids($task);
|
|
671
|
+
$ancestors{$task->{id}} = \%set;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
for my $wave (sort keys %wave_members) {
|
|
675
|
+
my @members = @{$wave_members{$wave}};
|
|
676
|
+
for my $left (0 .. $#members) {
|
|
677
|
+
for my $right ($left + 1 .. $#members) {
|
|
678
|
+
my ($first, $second) = ($members[$left], $members[$right]);
|
|
679
|
+
next unless $tasks[$first]{parallel} || $tasks[$second]{parallel};
|
|
680
|
+
my ($one, $two) = ($tasks[$first]{id}, $tasks[$second]{id});
|
|
681
|
+
fail("$one and $two are both in $wave and one is marked [P], but one depends on the other")
|
|
682
|
+
if $ancestors{$two}{$one} || $ancestors{$one}{$two};
|
|
683
|
+
next unless exists $task_files{$first} && exists $task_files{$second};
|
|
684
|
+
my @shared = sort grep { my $path = $_; grep { paths_overlap($path, $_) } keys %{$task_files{$second}} }
|
|
685
|
+
keys %{$task_files{$first}};
|
|
686
|
+
fail("$one and $two are both in $wave and one is marked [P], but they share "
|
|
687
|
+
. join(', ', @shared)) if @shared;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
for my $task (@superseded_tasks) {
|
|
693
|
+
next unless exists $task->{fields}{Requirements}
|
|
694
|
+
&& @{$task->{fields}{Requirements}} == 1;
|
|
695
|
+
my $requirements = $task->{fields}{Requirements}[0];
|
|
696
|
+
my @requirement_ids = split /\s*,\s*/, $requirements, -1;
|
|
697
|
+
if (!@requirement_ids
|
|
698
|
+
|| grep { $_ !~ /^R-(?:[0-9]+\.[0-9]+|[A-Z][A-Z0-9-]*-[0-9]+)$/ } @requirement_ids) {
|
|
699
|
+
fail("superseded task $task->{id} has malformed Requirements value '$requirements'");
|
|
700
|
+
next;
|
|
701
|
+
}
|
|
702
|
+
for my $requirement_id (@requirement_ids) {
|
|
703
|
+
next if $local_requirements{$requirement_id};
|
|
704
|
+
next if $catalog_requirements{$requirement_id};
|
|
705
|
+
fail("superseded task $task->{id} cites undefined requirement $requirement_id");
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
if (exists $frontmatter{public_release} && $frontmatter{public_release} eq 'false') {
|
|
710
|
+
for my $requirement_id (qw(R-SEC-26 R-ROAD-21 R-LAUNCH-22)) {
|
|
711
|
+
fail("public_release false must not cite $requirement_id")
|
|
712
|
+
if grep { task_has_requirement($_, $requirement_id) } @tasks;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (exists $frontmatter{public_release} && $frontmatter{public_release} eq 'true') {
|
|
717
|
+
my @hardening_indexes = grep { task_has_requirement($tasks[$_], 'R-SEC-26') } 0 .. $#tasks;
|
|
718
|
+
my @gate_indexes = grep { task_has_requirement($tasks[$_], 'R-ROAD-21') } 0 .. $#tasks;
|
|
719
|
+
my @activation_indexes = grep { task_has_requirement($tasks[$_], 'R-LAUNCH-22') } 0 .. $#tasks;
|
|
720
|
+
|
|
721
|
+
fail('public release requires at least one hardening task citing R-SEC-26')
|
|
722
|
+
unless @hardening_indexes;
|
|
723
|
+
if (!@gate_indexes) {
|
|
724
|
+
fail('public release requires a prepublication gate task citing R-ROAD-21');
|
|
725
|
+
} elsif (@gate_indexes != 1) {
|
|
726
|
+
fail('public release requires exactly one prepublication gate task citing R-ROAD-21, found ' . scalar @gate_indexes);
|
|
727
|
+
}
|
|
728
|
+
fail('public release requires exactly one first activation task citing R-LAUNCH-22, found ' . scalar @activation_indexes)
|
|
729
|
+
unless @activation_indexes == 1;
|
|
730
|
+
|
|
731
|
+
if (@hardening_indexes && @gate_indexes == 1) {
|
|
732
|
+
my $latest_hardening_index = $hardening_indexes[-1];
|
|
733
|
+
my $gate_index = $gate_indexes[0];
|
|
734
|
+
my $latest_hardening_id = $tasks[$latest_hardening_index]{id};
|
|
735
|
+
my $gate_id = $tasks[$gate_index]{id};
|
|
736
|
+
|
|
737
|
+
fail("prepublication gate must follow the latest hardening task $latest_hardening_id")
|
|
738
|
+
unless $gate_index > $latest_hardening_index;
|
|
739
|
+
fail("prepublication gate must depend on the latest hardening task $latest_hardening_id")
|
|
740
|
+
unless task_depends_on($tasks[$gate_index], $latest_hardening_id);
|
|
741
|
+
|
|
742
|
+
if (exists $tasks[$gate_index]{fields}{Acceptance}
|
|
743
|
+
&& @{$tasks[$gate_index]{fields}{Acceptance}} == 1) {
|
|
744
|
+
my $acceptance = $tasks[$gate_index]{fields}{Acceptance}[0];
|
|
745
|
+
for my $field (qw(checked_at hardening_revision finding_counts policy verdict owner justification accepted_at expires_at invalidates)) {
|
|
746
|
+
fail("prepublication gate $gate_id Acceptance is missing $field")
|
|
747
|
+
if index($acceptance, $field) < 0;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (@activation_indexes == 1) {
|
|
752
|
+
my $activation_index = $activation_indexes[0];
|
|
753
|
+
my $activation_id = $tasks[$activation_index]{id};
|
|
754
|
+
fail("public activation must immediately follow the prepublication gate $gate_id")
|
|
755
|
+
unless $activation_index == $gate_index + 1;
|
|
756
|
+
fail("public activation must depend on the prepublication gate $gate_id")
|
|
757
|
+
unless task_depends_on($tasks[$activation_index], $gate_id);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
my $tasks_total = scalar @tasks;
|
|
763
|
+
my $tasks_done = scalar grep { $_->{done} } @tasks;
|
|
764
|
+
my $phases_total = scalar @phases;
|
|
765
|
+
my $phases_done = 0;
|
|
766
|
+
for my $phase (@phases) {
|
|
767
|
+
# A phase of only superseded tasks stays as history; removing it renumbers later phases.
|
|
768
|
+
if (!@{$phase->{tasks}}) {
|
|
769
|
+
if ($phase->{superseded}) {
|
|
770
|
+
$phases_done++;
|
|
771
|
+
} else {
|
|
772
|
+
fail("Phase $phase->{number} has no task definitions");
|
|
773
|
+
}
|
|
774
|
+
next;
|
|
775
|
+
}
|
|
776
|
+
fail("Phase $phase->{number} is missing Checkpoint")
|
|
777
|
+
unless defined $phase->{checkpoint};
|
|
778
|
+
fail("Phase $phase->{number} is missing Checkpoint verify")
|
|
779
|
+
unless defined $phase->{checkpoint_verify};
|
|
780
|
+
my $all_done = 1;
|
|
781
|
+
for my $task_index (@{$phase->{tasks}}) {
|
|
782
|
+
$all_done = 0 unless $tasks[$task_index]{done};
|
|
783
|
+
}
|
|
784
|
+
$phases_done++ if $all_done;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
my %derived_counter = (
|
|
788
|
+
phases_total => $phases_total,
|
|
789
|
+
phases_done => $phases_done,
|
|
790
|
+
tasks_total => $tasks_total,
|
|
791
|
+
tasks_done => $tasks_done,
|
|
792
|
+
);
|
|
793
|
+
for my $key (qw(phases_total phases_done tasks_total tasks_done)) {
|
|
794
|
+
next unless exists $counter{$key} && $counter{$key} =~ /^[0-9]+$/;
|
|
795
|
+
fail("$key is $counter{$key}, derived value is $derived_counter{$key}")
|
|
796
|
+
if $counter{$key} != $derived_counter{$key};
|
|
797
|
+
}
|
|
798
|
+
fail("status done requires every task checked, found $tasks_done of $tasks_total")
|
|
799
|
+
if ($frontmatter{status} || '') eq 'done' && $tasks_done != $tasks_total;
|
|
800
|
+
|
|
801
|
+
section_count('Open Questions');
|
|
802
|
+
my %open_question = map { $lines[$_] =~ /^### (Q[1-9][0-9]*):/ ? ($1 => $lines[$_]) : () }
|
|
803
|
+
section('## Open Questions');
|
|
804
|
+
|
|
805
|
+
my $provenance_count = section_count('Plan provenance');
|
|
806
|
+
section_count('Product form');
|
|
807
|
+
|
|
808
|
+
# Archetype confidence is arithmetic, not a feeling. The plan states its own
|
|
809
|
+
# scores; everything downstream of them is recomputed here, so a confident
|
|
810
|
+
# label that does not follow from the plan's own numbers cannot ship.
|
|
811
|
+
my $archetype_low = '';
|
|
812
|
+
my %archetype_block;
|
|
813
|
+
my $archetype_count = scalar grep { $_ eq '### Archetype confidence' } @lines;
|
|
814
|
+
fail("expected exactly one ### Archetype confidence block, found $archetype_count")
|
|
815
|
+
if $archetype_count != 1;
|
|
816
|
+
fail('### Archetype confidence must sit under ## Product form')
|
|
817
|
+
if $archetype_count == 1 && !grep { $lines[$_] eq '### Archetype confidence' } section('## Product form');
|
|
818
|
+
|
|
819
|
+
if ($archetype_count == 1) {
|
|
820
|
+
for my $index (section('### Archetype confidence')) {
|
|
821
|
+
next unless $lines[$index] =~ /^-[ \t]+([A-Za-z][A-Za-z -]*?)[ \t]*:[ \t]*(\S.*)$/;
|
|
822
|
+
my ($field, $value) = ($1, $2);
|
|
823
|
+
fail("archetype confidence has duplicate field $field")
|
|
824
|
+
if exists $archetype_block{$field};
|
|
825
|
+
$archetype_block{$field} = $value;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
for my $field ('Primary', 'Runner-up', 'Margin', 'Confidence', 'Vetoes applied', 'Overlays') {
|
|
829
|
+
fail("archetype confidence is missing $field")
|
|
830
|
+
unless exists $archetype_block{$field};
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
my ($primary_name, $primary_score);
|
|
834
|
+
if (defined $archetype_block{Primary}) {
|
|
835
|
+
if ($archetype_block{Primary} =~ /^([a-z0-9-]+)[ \t]*\(score[ \t]+([01]\.[0-9]{2})\)$/) {
|
|
836
|
+
($primary_name, $primary_score) = ($1, $2 + 0);
|
|
837
|
+
} else {
|
|
838
|
+
fail("archetype confidence Primary must read '<archetype> (score 0.NN)'");
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
my ($runner_name, $runner_score);
|
|
842
|
+
if (defined $archetype_block{'Runner-up'}) {
|
|
843
|
+
if (lc $archetype_block{'Runner-up'} eq 'none') {
|
|
844
|
+
$runner_score = 0;
|
|
845
|
+
} elsif ($archetype_block{'Runner-up'} =~ /^([a-z0-9-]+)[ \t]*\(score[ \t]+([01]\.[0-9]{2})\)$/) {
|
|
846
|
+
($runner_name, $runner_score) = ($1, $2 + 0);
|
|
847
|
+
} else {
|
|
848
|
+
fail("archetype confidence Runner-up must read '<archetype> (score 0.NN)' or 'none'");
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
for my $name (grep { defined $_ && !$allowed_archetype{$_} } $primary_name, $runner_name) {
|
|
852
|
+
fail("archetype confidence names $name, which is not one of " . join(', ', @archetypes));
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
if (defined $primary_score) {
|
|
856
|
+
fail("archetype confidence Primary score exceeds 1.00") if $primary_score > 1;
|
|
857
|
+
if (exists $frontmatter{archetype} && defined $primary_name
|
|
858
|
+
&& ($frontmatter{archetype} ne 'unknown' || $primary_score >= 0.45)
|
|
859
|
+
&& $primary_name ne $frontmatter{archetype}) {
|
|
860
|
+
fail("archetype confidence Primary is $primary_name but frontmatter archetype is $frontmatter{archetype}");
|
|
861
|
+
}
|
|
862
|
+
# Below the floor the archetype is not decided, and a named archetype
|
|
863
|
+
# would license matrix defaults and a document set nothing supports.
|
|
864
|
+
if ($primary_score < 0.45) {
|
|
865
|
+
$archetype_low = 'the archetype Primary score is below the 0.45 floor';
|
|
866
|
+
fail('archetype confidence Primary score ' . sprintf('%.2f', $primary_score) . ' is below the 0.45 floor, so frontmatter archetype must be unknown')
|
|
867
|
+
if exists $frontmatter{archetype} && $frontmatter{archetype} ne 'unknown';
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
if (defined $primary_score && defined $runner_score) {
|
|
872
|
+
fail("archetype confidence Runner-up scores at or above Primary")
|
|
873
|
+
if defined $runner_name && $runner_score >= $primary_score;
|
|
874
|
+
fail("archetype confidence Runner-up repeats the Primary archetype")
|
|
875
|
+
if defined $runner_name && defined $primary_name && $runner_name eq $primary_name;
|
|
876
|
+
my $expected_margin = int(($primary_score - $runner_score) * 100 + 0.5);
|
|
877
|
+
if (defined $archetype_block{Margin}) {
|
|
878
|
+
if ($archetype_block{Margin} =~ /^(-?[0-9]+)[ \t]+points?$/) {
|
|
879
|
+
fail("archetype confidence Margin is $1 but the scores give $expected_margin")
|
|
880
|
+
if $1 != $expected_margin;
|
|
881
|
+
} else {
|
|
882
|
+
fail("archetype confidence Margin must read '<n> points'");
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
my $expected_confidence =
|
|
886
|
+
($expected_margin >= 15 && $primary_score >= 0.70) ? 'high'
|
|
887
|
+
: ($expected_margin >= 15 || $primary_score >= 0.70) ? 'medium'
|
|
888
|
+
: 'low';
|
|
889
|
+
$archetype_low = 'archetype confidence is low' if $expected_confidence eq 'low';
|
|
890
|
+
if (defined $archetype_block{Confidence}) {
|
|
891
|
+
my $stated = lc $archetype_block{Confidence};
|
|
892
|
+
if (!$allowed_confidence{$stated}) {
|
|
893
|
+
fail("archetype confidence Confidence must be high, medium, or low");
|
|
894
|
+
} elsif ($stated ne $expected_confidence) {
|
|
895
|
+
fail("archetype confidence states $stated but a margin of $expected_margin with a primary score of $primary_score gives $expected_confidence");
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
if (exists $frontmatter{archetype_confidence}
|
|
899
|
+
&& $allowed_confidence{$frontmatter{archetype_confidence}}
|
|
900
|
+
&& $frontmatter{archetype_confidence} ne $expected_confidence) {
|
|
901
|
+
fail("frontmatter archetype_confidence is $frontmatter{archetype_confidence} but the block's scores give $expected_confidence");
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
# A counterfactual priced in adjectives cannot be acted on. Tasks and
|
|
906
|
+
# phases are the units the rest of the plan already trades in.
|
|
907
|
+
if (defined $runner_name) {
|
|
908
|
+
my $counterfactual = $archetype_block{'If the runner-up is right'};
|
|
909
|
+
if (!defined $counterfactual) {
|
|
910
|
+
fail("archetype confidence names a runner-up but no 'If the runner-up is right:' counterfactual");
|
|
911
|
+
} elsif ($counterfactual !~ /[+-]?[0-9]+[ \t]+tasks?\b/
|
|
912
|
+
|| $counterfactual !~ /[+-]?[0-9]+[ \t]+phases?\b/) {
|
|
913
|
+
fail("archetype confidence counterfactual must be priced in tasks and phases, not adjectives");
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
if (defined $archetype_block{Overlays}) {
|
|
918
|
+
my $stated = trim($archetype_block{Overlays});
|
|
919
|
+
my @stated_overlays = lc($stated) eq 'none'
|
|
920
|
+
? ()
|
|
921
|
+
: sort grep { $_ ne '' } map { trim($_) } split /\s*,\s*/, $stated, -1;
|
|
922
|
+
my $stated_key = join ',', @stated_overlays;
|
|
923
|
+
my $frontmatter_key = join ',', @overlays;
|
|
924
|
+
fail("archetype confidence Overlays says '$stated' but frontmatter overlays is [$frontmatter_key]")
|
|
925
|
+
if $stated_key ne $frontmatter_key;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
# Low confidence, or a Primary below the floor, is not a disclaimer. It withholds
|
|
930
|
+
# the archetype as a settled fact until a human confirms it, so the question has
|
|
931
|
+
# to be on the page.
|
|
932
|
+
fail("$archetype_low, so the archetype belongs in ## Open Questions as a ### Q<n>: entry naming it")
|
|
933
|
+
if $archetype_low && !grep { /archetype/i } values %open_question;
|
|
934
|
+
|
|
935
|
+
if ($provenance_count == 1) {
|
|
936
|
+
my @body = map { $lines[$_] } section('## Plan provenance');
|
|
937
|
+
|
|
938
|
+
my %label_key = (
|
|
939
|
+
'Source revision' => 'source_revision',
|
|
940
|
+
'Input digest' => 'input_digest',
|
|
941
|
+
'Validated at' => 'validated_at',
|
|
942
|
+
);
|
|
943
|
+
my %label_count;
|
|
944
|
+
my %label_value;
|
|
945
|
+
my $inventory_count = 0;
|
|
946
|
+
my $inventory_started = 0;
|
|
947
|
+
my $inventory_valid = 1;
|
|
948
|
+
|
|
949
|
+
for my $line (@body) {
|
|
950
|
+
next if $line eq '';
|
|
951
|
+
if ($line =~ /^(Source revision|Input digest|Validated at):[ \t]*(.*)$/) {
|
|
952
|
+
my ($label, $value) = ($1, trim($2));
|
|
953
|
+
$label_count{$label}++;
|
|
954
|
+
$label_value{$label} = $value;
|
|
955
|
+
next;
|
|
956
|
+
}
|
|
957
|
+
if ($line =~ /^Evidence inventory:[ \t]*(.*)$/) {
|
|
958
|
+
$label_count{'Evidence inventory'}++;
|
|
959
|
+
$inventory_started = 1;
|
|
960
|
+
if (trim($1) ne '') {
|
|
961
|
+
fail('Plan provenance Evidence inventory label must not contain an inline value');
|
|
962
|
+
$inventory_valid = 0;
|
|
963
|
+
}
|
|
964
|
+
next;
|
|
965
|
+
}
|
|
966
|
+
if ($inventory_started
|
|
967
|
+
&& $line =~ /^- (\[recheck\] )?`([A-Za-z0-9._][A-Za-z0-9._\/-]*)` = `sha256:([0-9a-f]{64})`$/) {
|
|
968
|
+
my ($recheck, $label, $digest) = ($1, $2, $3);
|
|
969
|
+
$inventory_count++;
|
|
970
|
+
# A dotfile path is a repository-relative path; a .. segment is not.
|
|
971
|
+
if ($label =~ m{(?:^|/)\.\.(?:/|$)}) {
|
|
972
|
+
fail("Plan provenance inventory label $label must not contain a .. segment");
|
|
973
|
+
$inventory_valid = 0;
|
|
974
|
+
} elsif (exists $inventory{$label}) {
|
|
975
|
+
fail("duplicate Plan provenance inventory label: $label");
|
|
976
|
+
$inventory_valid = 0;
|
|
977
|
+
} else {
|
|
978
|
+
$inventory{$label} = $digest;
|
|
979
|
+
$recheck_inventory{$label} = $digest if defined $recheck;
|
|
980
|
+
}
|
|
981
|
+
next;
|
|
982
|
+
}
|
|
983
|
+
if ($inventory_started) {
|
|
984
|
+
fail("malformed Plan provenance inventory item: $line");
|
|
985
|
+
} else {
|
|
986
|
+
fail("malformed Plan provenance line: $line");
|
|
987
|
+
}
|
|
988
|
+
$inventory_valid = 0;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
for my $label ('Source revision', 'Input digest', 'Validated at', 'Evidence inventory') {
|
|
992
|
+
my $count = $label_count{$label} || 0;
|
|
993
|
+
fail("Plan provenance is missing $label:") if $count == 0;
|
|
994
|
+
fail("Plan provenance has duplicate $label label") if $count > 1;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
for my $label ('Source revision', 'Input digest', 'Validated at') {
|
|
998
|
+
next unless ($label_count{$label} || 0) == 1;
|
|
999
|
+
my $key = $label_key{$label};
|
|
1000
|
+
next unless exists $frontmatter{$key};
|
|
1001
|
+
fail("Plan provenance $label does not match frontmatter $key")
|
|
1002
|
+
if $label_value{$label} ne $frontmatter{$key};
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
fail('Plan provenance Evidence inventory must contain at least one item')
|
|
1006
|
+
if $inventory_count == 0;
|
|
1007
|
+
my $intake_count = exists $inventory{intake} ? 1 : 0;
|
|
1008
|
+
fail('Plan provenance Evidence inventory must contain exactly one intake item')
|
|
1009
|
+
unless $intake_count == 1;
|
|
1010
|
+
|
|
1011
|
+
if ($inventory_valid
|
|
1012
|
+
&& $inventory_count > 0
|
|
1013
|
+
&& $intake_count == 1
|
|
1014
|
+
&& ($label_count{'Input digest'} || 0) == 1) {
|
|
1015
|
+
my $digest_input = join '', map { "$_\t$inventory{$_}\n" } sort keys %inventory;
|
|
1016
|
+
my $aggregate = 'sha256:' . sha256_hex($digest_input);
|
|
1017
|
+
fail('Plan provenance Input digest does not match the Evidence inventory aggregate')
|
|
1018
|
+
if $label_value{'Input digest'} ne $aggregate;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
my %known_domain = map { $_ => 1 } qw(
|
|
1023
|
+
product business architecture stack database security llm ux ui seo code-quality
|
|
1024
|
+
style-genome agent-memory repo build roadmap deploy observe launch
|
|
1025
|
+
);
|
|
1026
|
+
my %allowed_disposition = map { $_ => 1 } qw(applicable deferred excluded);
|
|
1027
|
+
my %deferrable_domain = map { $_ => 1 } qw(seo launch observe ui deploy);
|
|
1028
|
+
# These five scale down; they never leave the plan. A later layer may raise a
|
|
1029
|
+
# domain's disposition and never lower it out of existence, so an exclusion here
|
|
1030
|
+
# is a lowering the engine refuses rather than a judgement call.
|
|
1031
|
+
my %never_excludable = map { $_ => 1 } qw(security code-quality style-genome repo roadmap);
|
|
1032
|
+
my $vague_predicate = qr/^(?:later|eventually|when ready|post-mvp|future|tbd)\b/;
|
|
1033
|
+
my %domain_evidence_state;
|
|
1034
|
+
my %domain_revisit_when;
|
|
1035
|
+
my $matrix_count = section_count('Applicability matrix');
|
|
1036
|
+
|
|
1037
|
+
if ($matrix_count == 1) {
|
|
1038
|
+
my %seen_domain;
|
|
1039
|
+
for my $line (map { $lines[$_] } section('## Applicability matrix')) {
|
|
1040
|
+
next unless $line =~ /^\|[ \t]*([a-z0-9-]+)[ \t]*\|[ \t]*([a-z0-9-]+)[ \t]*\|[ \t]*(.*?)[ \t]*\|[ \t]*$/;
|
|
1041
|
+
my ($domain, $disposition, $reason) = ($1, $2, $3);
|
|
1042
|
+
next unless $known_domain{$domain};
|
|
1043
|
+
fail("applicability matrix has a duplicate row for $domain")
|
|
1044
|
+
if $seen_domain{$domain}++;
|
|
1045
|
+
if (!$allowed_disposition{$disposition}) {
|
|
1046
|
+
fail("applicability matrix row for $domain has invalid status '$disposition'; expected applicable, deferred, or excluded");
|
|
1047
|
+
next;
|
|
1048
|
+
}
|
|
1049
|
+
# An exclusion with no evidence state and no expiry is a silence with a
|
|
1050
|
+
# reason attached: it reads exactly like a considered decision and
|
|
1051
|
+
# nothing ever reopens it. Demand the state that licensed it and the
|
|
1052
|
+
# predicate that would reverse it.
|
|
1053
|
+
if ($disposition eq 'excluded') {
|
|
1054
|
+
fail("applicability matrix cannot exclude load-bearing domain $domain; it scales down instead")
|
|
1055
|
+
if $never_excludable{$domain};
|
|
1056
|
+
fail("applicability matrix excludes $domain, which the $overlay_protected{$domain} overlay covers; overlays raise and never lower, so this row " . ($deferrable_domain{$domain} ? "may be applicable or deferred but not excluded" : "must be applicable"))
|
|
1057
|
+
if $overlay_protected{$domain};
|
|
1058
|
+
my ($state) = $reason =~ /^[ \t]*([A-Za-z-]+)[ \t]*:/;
|
|
1059
|
+
$state = defined $state ? lc $state : '';
|
|
1060
|
+
my ($predicate) = $reason =~ /revisit when[ \t]*:[ \t]*(.*)$/i;
|
|
1061
|
+
$predicate = defined $predicate ? $predicate : '';
|
|
1062
|
+
$predicate =~ s/[ \t]+$//;
|
|
1063
|
+
if ($reason eq '') {
|
|
1064
|
+
fail("applicability matrix excludes $domain without a reason");
|
|
1065
|
+
} elsif ($state eq 'unknown' || $state eq 'hint') {
|
|
1066
|
+
fail("applicability matrix excludes $domain on evidence state '$state'; only absent or by-design may exclude, so make the domain applicable or open a question");
|
|
1067
|
+
} elsif ($state ne 'absent' && $state ne 'by-design') {
|
|
1068
|
+
fail("applicability matrix excludes $domain without an evidence state; the reason must open with 'absent:' or 'by-design:'");
|
|
1069
|
+
}
|
|
1070
|
+
if ($reason ne '' && $predicate eq '') {
|
|
1071
|
+
fail("applicability matrix excludes $domain without a revisit when: tripwire");
|
|
1072
|
+
} elsif (lc($predicate) =~ $vague_predicate) {
|
|
1073
|
+
fail("applicability matrix excludes $domain with a vague revisit when: predicate");
|
|
1074
|
+
} elsif ($predicate ne '' && length($predicate) < 12) {
|
|
1075
|
+
fail("applicability matrix excludes $domain with a revisit when: predicate too short to observe");
|
|
1076
|
+
}
|
|
1077
|
+
# `absent:` against existing code is a negative claim, and the
|
|
1078
|
+
# claims-and-evidence rule refuses those without a search. Greenfield
|
|
1079
|
+
# has nothing to have looked at, so only `by-design:` applies there.
|
|
1080
|
+
if ($state eq 'absent'
|
|
1081
|
+
&& exists $frontmatter{mode}
|
|
1082
|
+
&& ($frontmatter{mode} eq 'brownfield' || $frontmatter{mode} eq 'replan')
|
|
1083
|
+
&& $reason !~ /`[^`]+`/) {
|
|
1084
|
+
fail("applicability matrix excludes $domain on an absent: claim with no backticked command or evidence artifact; a negative claim about existing code needs the search that came back empty");
|
|
1085
|
+
}
|
|
1086
|
+
$domain_evidence_state{$domain} = $state;
|
|
1087
|
+
$domain_revisit_when{$domain} = $predicate;
|
|
1088
|
+
}
|
|
1089
|
+
if ($disposition eq 'deferred') {
|
|
1090
|
+
fail("applicability matrix cannot defer load-bearing domain $domain")
|
|
1091
|
+
unless $deferrable_domain{$domain};
|
|
1092
|
+
fail("applicability matrix defers $domain without a trigger")
|
|
1093
|
+
if index(lc($reason), 'trigger:') < 0;
|
|
1094
|
+
fail("applicability matrix defers $domain without a reversibility argument")
|
|
1095
|
+
if index(lc($reason), 'reversib') < 0;
|
|
1096
|
+
fail("applicability matrix defers $domain with a vague trigger")
|
|
1097
|
+
if lc($reason) =~ /trigger:[ \t]*(?:later|eventually|when ready|post-mvp|future|tbd)\b/;
|
|
1098
|
+
}
|
|
1099
|
+
$domain_disposition{$domain} = $disposition;
|
|
1100
|
+
$domain_reason{$domain} = $reason;
|
|
1101
|
+
}
|
|
1102
|
+
for my $domain (sort keys %known_domain) {
|
|
1103
|
+
fail("applicability matrix is missing domain $domain")
|
|
1104
|
+
unless $seen_domain{$domain};
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
# The rest of the skeleton; Architecture and Agent memory while applicable.
|
|
1109
|
+
section_count($_) for 'Scope and non-goals', 'Compliance gate', 'Requirements', 'Style genome',
|
|
1110
|
+
'Phases', 'Rules for executing agents', 'Session log',
|
|
1111
|
+
grep { ($domain_disposition{lc($_) =~ tr/ /-/r} || '') eq 'applicable' } 'Architecture', 'Agent memory';
|
|
1112
|
+
fail('executor rules lack > [!IMPORTANT]')
|
|
1113
|
+
unless grep { $lines[$_] eq '> [!IMPORTANT]' } section('## Rules for executing agents');
|
|
1114
|
+
|
|
1115
|
+
# The module disposition is the only place a module requirement may leave the
|
|
1116
|
+
# plan. Precedence alone does not save it: a later layer is not a more correct
|
|
1117
|
+
# layer, only a later one, so the line names which layer dropped what. Without
|
|
1118
|
+
# that name, a requirement cut to fit a weekend appetite is indistinguishable
|
|
1119
|
+
# from one nobody ever considered, and only one of those is a decision.
|
|
1120
|
+
my %module_prefix = (
|
|
1121
|
+
'product' => 'PRD', 'business' => 'BIZ', 'architecture' => 'ARCH', 'stack' => 'STACK',
|
|
1122
|
+
'database' => 'DB', 'security' => 'SEC', 'llm' => 'LLM', 'ux' => 'UX',
|
|
1123
|
+
'ui' => 'UI', 'seo' => 'SEO', 'code-quality' => 'CODE',
|
|
1124
|
+
'style-genome' => 'DNA', 'agent-memory' => 'MEM', 'repo' => 'REPO',
|
|
1125
|
+
'build' => 'BUILD', 'roadmap' => 'ROAD', 'deploy' => 'DEPLOY',
|
|
1126
|
+
'observe' => 'OBS', 'launch' => 'LAUNCH',
|
|
1127
|
+
);
|
|
1128
|
+
my %prefix_module = reverse %module_prefix;
|
|
1129
|
+
my %dropped_layer = map { $_ => 1 } qw(scale archetype form);
|
|
1130
|
+
my @json_disposition;
|
|
1131
|
+
if (%domain_disposition) {
|
|
1132
|
+
my %task_requirement;
|
|
1133
|
+
for my $task (@tasks) {
|
|
1134
|
+
next unless exists $task->{fields}{Requirements}
|
|
1135
|
+
&& @{$task->{fields}{Requirements}} == 1;
|
|
1136
|
+
for my $id (split /\s*,\s*/, $task->{fields}{Requirements}[0], -1) {
|
|
1137
|
+
$task_requirement{$id} = $task->{id};
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
# A task may not trace to a module the matrix keeps out of this plan.
|
|
1141
|
+
for my $id (sort keys %task_requirement) {
|
|
1142
|
+
my ($module) = map { $prefix_module{$_} } $id =~ /^R-([A-Z][A-Z0-9-]*)-[0-9]+$/;
|
|
1143
|
+
my $status = $module ? $domain_disposition{$module} || '' : '';
|
|
1144
|
+
fail("$task_requirement{$id} cites $id, but the applicability matrix marks $module $status")
|
|
1145
|
+
if $status eq 'excluded' || $status eq 'deferred';
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
my $found = grep { $_ eq '### Module disposition' } @lines;
|
|
1149
|
+
my $inside = grep { $lines[$_] eq '### Module disposition' } section('## Applicability matrix');
|
|
1150
|
+
my %disposition_line = map { ($_ + 1 => $lines[$_]) }
|
|
1151
|
+
grep { $lines[$_] =~ /\S/ } section('### Module disposition');
|
|
1152
|
+
|
|
1153
|
+
# Landed means used: a mention outside the frontmatter, session log, and disposition block.
|
|
1154
|
+
my (%reference_lines, $in_log);
|
|
1155
|
+
for my $index ($frontmatter_end + 1 .. $#lines) {
|
|
1156
|
+
$in_log = $lines[$index] eq '## Session log' if $lines[$index] =~ /^## /;
|
|
1157
|
+
next if $in_log || exists $disposition_line{$index + 1};
|
|
1158
|
+
my %seen = map { $_ => 1 } $raw_lines[$index] =~ /(R-[A-Z][A-Z0-9-]*-[0-9]+)/g;
|
|
1159
|
+
$reference_lines{$_}++ for keys %seen;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
if ($found != 1 || $inside != 1) {
|
|
1163
|
+
fail("expected exactly one ### Module disposition block under ## Applicability matrix, found $inside"
|
|
1164
|
+
. ($found > $inside ? ' there and ' . ($found - $inside) . ' elsewhere' : ''));
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
my %seen_module;
|
|
1168
|
+
for my $line_number (sort { $a <=> $b } keys %disposition_line) {
|
|
1169
|
+
my $line = $disposition_line{$line_number};
|
|
1170
|
+
my ($module, $body) = $line =~ /^-[ \t]+([a-z0-9-]+)[ \t]*:[ \t]*(\S.*)$/;
|
|
1171
|
+
if (!defined $module) {
|
|
1172
|
+
fail("module disposition line $line_number must read '- <module>: landed <ids>[; dropped-by <layer> <ids> (<reason>)]'");
|
|
1173
|
+
next;
|
|
1174
|
+
}
|
|
1175
|
+
if (!exists $module_prefix{$module}) {
|
|
1176
|
+
fail("module disposition names unknown module $module on line $line_number");
|
|
1177
|
+
next;
|
|
1178
|
+
}
|
|
1179
|
+
fail("module disposition has a duplicate line for $module")
|
|
1180
|
+
if $seen_module{$module}++;
|
|
1181
|
+
my $status = $domain_disposition{$module} || 'absent';
|
|
1182
|
+
if ($status ne 'applicable') {
|
|
1183
|
+
fail("module disposition covers $module, which the applicability matrix marks $status; only applicable modules land or drop requirements");
|
|
1184
|
+
next;
|
|
1185
|
+
}
|
|
1186
|
+
my $prefix = $module_prefix{$module};
|
|
1187
|
+
my %landed;
|
|
1188
|
+
my %dropped;
|
|
1189
|
+
my @dropped_entries;
|
|
1190
|
+
my $malformed = 0;
|
|
1191
|
+
for my $clause (split /\s*;\s*(?![^()]*\))/, $body) {
|
|
1192
|
+
next if $clause eq '';
|
|
1193
|
+
if ($clause =~ /^landed[ \t]+(\S.*)$/i) {
|
|
1194
|
+
my $ids = $1;
|
|
1195
|
+
next if lc($ids) eq 'none';
|
|
1196
|
+
for my $id (split /\s*,\s*/, $ids, -1) {
|
|
1197
|
+
$id =~ s/^\s+|\s+$//g;
|
|
1198
|
+
next if $id eq '';
|
|
1199
|
+
if ($id !~ /^R-\Q$prefix\E-[0-9]+$/) {
|
|
1200
|
+
fail("module disposition for $module lists $id, which is not an R-$prefix requirement");
|
|
1201
|
+
$malformed = 1;
|
|
1202
|
+
next;
|
|
1203
|
+
}
|
|
1204
|
+
if (!$catalog_requirements{$id}) {
|
|
1205
|
+
fail("module disposition for $module lands undefined requirement $id");
|
|
1206
|
+
$malformed = 1;
|
|
1207
|
+
next;
|
|
1208
|
+
}
|
|
1209
|
+
$landed{$id} = 1;
|
|
1210
|
+
}
|
|
1211
|
+
} elsif ($clause =~ /^dropped-by[ \t]+([a-z]+)[ \t]+(\S.*?)[ \t]*\((\S.*)\)$/i) {
|
|
1212
|
+
my ($layer, $ids, $reason) = (lc $1, $2, $3);
|
|
1213
|
+
if (!$dropped_layer{$layer}) {
|
|
1214
|
+
fail("module disposition for $module drops by unknown layer '$layer'; use scale, archetype, or form");
|
|
1215
|
+
$malformed = 1;
|
|
1216
|
+
next;
|
|
1217
|
+
}
|
|
1218
|
+
my @ids;
|
|
1219
|
+
for my $id (split /\s*,\s*/, $ids, -1) {
|
|
1220
|
+
$id =~ s/^\s+|\s+$//g;
|
|
1221
|
+
next if $id eq '';
|
|
1222
|
+
if ($id !~ /^R-\Q$prefix\E-[0-9]+$/) {
|
|
1223
|
+
fail("module disposition for $module drops $id, which is not an R-$prefix requirement");
|
|
1224
|
+
$malformed = 1;
|
|
1225
|
+
next;
|
|
1226
|
+
}
|
|
1227
|
+
if (!$catalog_requirements{$id}) {
|
|
1228
|
+
fail("module disposition for $module drops undefined requirement $id");
|
|
1229
|
+
$malformed = 1;
|
|
1230
|
+
next;
|
|
1231
|
+
}
|
|
1232
|
+
$dropped{$id} = 1;
|
|
1233
|
+
push @ids, $id;
|
|
1234
|
+
}
|
|
1235
|
+
push @dropped_entries, { layer => $layer, reason => $reason, requirements => \@ids };
|
|
1236
|
+
} elsif ($clause =~ /^dropped-by\b/i) {
|
|
1237
|
+
fail("module disposition for $module has a dropped-by clause without a parenthesised reason");
|
|
1238
|
+
$malformed = 1;
|
|
1239
|
+
} else {
|
|
1240
|
+
fail("module disposition for $module has an unrecognised clause '$clause'");
|
|
1241
|
+
$malformed = 1;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
next if $malformed;
|
|
1245
|
+
for my $id (sort keys %dropped) {
|
|
1246
|
+
fail("module disposition for $module both lands and drops $id")
|
|
1247
|
+
if $landed{$id};
|
|
1248
|
+
fail("module disposition drops $id but $task_requirement{$id} still traces to it")
|
|
1249
|
+
if exists $task_requirement{$id};
|
|
1250
|
+
}
|
|
1251
|
+
for my $id (sort keys %landed) {
|
|
1252
|
+
fail("module disposition lands $id but nothing outside the frontmatter, session log, and disposition block references it")
|
|
1253
|
+
unless $reference_lines{$id};
|
|
1254
|
+
}
|
|
1255
|
+
push @json_disposition, {
|
|
1256
|
+
module => $module,
|
|
1257
|
+
landed => [sort keys %landed],
|
|
1258
|
+
dropped => \@dropped_entries,
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
if ($found) {
|
|
1263
|
+
for my $domain (sort keys %domain_disposition) {
|
|
1264
|
+
next unless $domain_disposition{$domain} eq 'applicable';
|
|
1265
|
+
fail("module disposition is missing applicable module $domain")
|
|
1266
|
+
unless $seen_module{$domain};
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
# The three frontmatter lists index the matrix; the matrix decides. Recompute
|
|
1272
|
+
# them from the rows and fail on drift, the same parity the provenance block
|
|
1273
|
+
# gets, so a summary can never quietly contradict the section it summarizes.
|
|
1274
|
+
if (%domain_disposition) {
|
|
1275
|
+
my %expected;
|
|
1276
|
+
for my $domain (sort keys %domain_disposition) {
|
|
1277
|
+
push @{$expected{$domain_disposition{$domain}}}, $domain;
|
|
1278
|
+
}
|
|
1279
|
+
my %list_key = (
|
|
1280
|
+
applicable => 'domains_applicable',
|
|
1281
|
+
deferred => 'domains_deferred',
|
|
1282
|
+
excluded => 'domains_excluded',
|
|
1283
|
+
);
|
|
1284
|
+
for my $status (qw(applicable deferred excluded)) {
|
|
1285
|
+
my $key = $list_key{$status};
|
|
1286
|
+
next unless exists $frontmatter{$key};
|
|
1287
|
+
my $raw = trim($frontmatter{$key});
|
|
1288
|
+
if ($raw !~ /^\[(.*)\]$/) {
|
|
1289
|
+
fail("frontmatter $key must be a single inline list such as [product, security]");
|
|
1290
|
+
next;
|
|
1291
|
+
}
|
|
1292
|
+
my %declared;
|
|
1293
|
+
my $malformed = 0;
|
|
1294
|
+
for my $domain (split /\s*,\s*/, $1, -1) {
|
|
1295
|
+
$domain = trim($domain);
|
|
1296
|
+
next if $domain eq '';
|
|
1297
|
+
if (!exists $known_domain{$domain}) {
|
|
1298
|
+
fail("frontmatter $key names unknown domain $domain");
|
|
1299
|
+
$malformed = 1;
|
|
1300
|
+
next;
|
|
1301
|
+
}
|
|
1302
|
+
fail("frontmatter $key lists $domain twice") if $declared{$domain}++;
|
|
1303
|
+
}
|
|
1304
|
+
next if $malformed;
|
|
1305
|
+
my %wanted = map { $_ => 1 } @{$expected{$status} || []};
|
|
1306
|
+
my @missing = sort grep { !$declared{$_} } keys %wanted;
|
|
1307
|
+
my @extra = sort grep { !$wanted{$_} } keys %declared;
|
|
1308
|
+
fail("frontmatter $key does not match the applicability matrix: missing "
|
|
1309
|
+
. join(', ', @missing)) if @missing;
|
|
1310
|
+
fail("frontmatter $key does not match the applicability matrix: $_ is "
|
|
1311
|
+
. ($domain_disposition{$_} || 'absent') . " in the matrix")
|
|
1312
|
+
for @extra;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
# The documentation set is where an absence gets defended. A not-applicable row
|
|
1317
|
+
# with no evidence state and no tripwire launders a gap into a decision, which
|
|
1318
|
+
# is the one outcome this section exists to make structurally hard.
|
|
1319
|
+
my %doc_verdict = map { $_ => 1 } qw(required recommended optional not-applicable);
|
|
1320
|
+
my @json_documents;
|
|
1321
|
+
my $docset_count = section_count('Documentation set');
|
|
1322
|
+
|
|
1323
|
+
if ($docset_count == 1) {
|
|
1324
|
+
my $boundary = 0;
|
|
1325
|
+
my %seen_document;
|
|
1326
|
+
my $rows = 0;
|
|
1327
|
+
for my $index (section('## Documentation set')) {
|
|
1328
|
+
my $line = $lines[$index];
|
|
1329
|
+
$boundary = 1
|
|
1330
|
+
if index(lc($line), 'committed to this repository') >= 0;
|
|
1331
|
+
# Every row but the header and separator is read, so an unparsable row fails.
|
|
1332
|
+
next if $line !~ /^\|/ || $line =~ /^\|[ \t]*:?-/ || ($lines[$index + 1] || '') =~ /^\|[ \t]*:?-/;
|
|
1333
|
+
if ($line !~ /^\|[ \t]*`?([a-z]+\.[a-z0-9-]+)`?[ \t]*\|[ \t]*([a-z-]+)[ \t]*\|[ \t]*([a-z-]+)[ \t]*\|[ \t]*([a-z-]+)[ \t]*\|[ \t]*(.*?)[ \t]*\|[ \t]*$/) {
|
|
1334
|
+
fail("malformed documentation set row: $line");
|
|
1335
|
+
next;
|
|
1336
|
+
}
|
|
1337
|
+
my ($id, $stage, $verdict, $owner, $detail) = ($1, $2, $3, $4, $5);
|
|
1338
|
+
my ($state) = $detail =~ /^[ \t]*([A-Za-z-]+)[ \t]*:/;
|
|
1339
|
+
$state = defined $state ? lc $state : '';
|
|
1340
|
+
$rows++;
|
|
1341
|
+
if (!exists $doc_catalog{$id}) {
|
|
1342
|
+
fail("documentation set names $id, which is not a doc-set.md catalog id");
|
|
1343
|
+
next;
|
|
1344
|
+
}
|
|
1345
|
+
fail("documentation set has a duplicate row for $id")
|
|
1346
|
+
if $seen_document{$id}++;
|
|
1347
|
+
my ($catalog_owner, $durability) = split /\|/, $doc_catalog{$id};
|
|
1348
|
+
my ($catalog_stage) = $id =~ /^([a-z]+)\./;
|
|
1349
|
+
fail("documentation set row $id declares stage '$stage'; the catalog stage is $catalog_stage")
|
|
1350
|
+
if $stage ne $catalog_stage;
|
|
1351
|
+
fail("documentation set row $id records $state in a greenfield plan; only brownfield and replan find documents present")
|
|
1352
|
+
if ($frontmatter{mode} || '') eq 'greenfield' && $state =~ /^present-(?:current|drifted|stub)$/;
|
|
1353
|
+
if (!$doc_verdict{$verdict}) {
|
|
1354
|
+
fail("documentation set row $id has invalid verdict '$verdict'; expected required, recommended, optional, or not-applicable");
|
|
1355
|
+
next;
|
|
1356
|
+
}
|
|
1357
|
+
fail("documentation set row $id names owner '$owner'; the catalog owner is $catalog_owner, and exactly one module owns a document")
|
|
1358
|
+
if $owner ne $catalog_owner;
|
|
1359
|
+
if ($verdict eq 'required' || $verdict eq 'recommended') {
|
|
1360
|
+
my @task_refs = $detail =~ /(GP-[0-9]+)/g;
|
|
1361
|
+
# adopt and confirm (doc-set.md section 6) cost frontmatter, not a task.
|
|
1362
|
+
fail("documentation set row $id is $verdict but names no GP task that writes it")
|
|
1363
|
+
unless @task_refs || $state eq 'present-current' || $state eq 'present-elsewhere';
|
|
1364
|
+
for my $ref (@task_refs) {
|
|
1365
|
+
fail("documentation set row $id names "
|
|
1366
|
+
. (exists $all_task_definitions{$ref} ? "superseded task $ref" : "$ref, which is not a task in this plan"))
|
|
1367
|
+
unless exists $task_definitions{$ref};
|
|
1368
|
+
}
|
|
1369
|
+
my $owner_status = $domain_disposition{$owner};
|
|
1370
|
+
fail("documentation set row $id is $verdict but its owner module $owner is excluded in the applicability matrix")
|
|
1371
|
+
if defined $owner_status && $owner_status eq 'excluded';
|
|
1372
|
+
} elsif ($verdict eq 'not-applicable') {
|
|
1373
|
+
# A misread archetype deletes assure-stage rows silently, and those
|
|
1374
|
+
# are the threat models and compliance records. Withhold them until
|
|
1375
|
+
# the archetype is confirmed.
|
|
1376
|
+
fail("documentation set marks the assure-stage row $id not-applicable while $archetype_low; confirm the archetype first")
|
|
1377
|
+
if $archetype_low && $stage eq 'assure';
|
|
1378
|
+
my ($predicate) = $detail =~ /revisit when[ \t]*:[ \t]*(.*)$/i;
|
|
1379
|
+
$predicate = defined $predicate ? $predicate : '';
|
|
1380
|
+
$predicate =~ s/[ \t]+$//;
|
|
1381
|
+
# An orphan exists but nothing justifies it: it gets a question, never a deletion task.
|
|
1382
|
+
if ($state =~ /^present-(?:current|drifted|stub)$/) {
|
|
1383
|
+
fail("documentation set row $id is an orphan but cites no ### Q<n> from ## Open Questions")
|
|
1384
|
+
unless grep { $open_question{$_} } $detail =~ /\b(Q[1-9][0-9]*)\b/g;
|
|
1385
|
+
} else {
|
|
1386
|
+
if ($state eq 'unknown' || $state eq 'hint') {
|
|
1387
|
+
fail("documentation set excludes $id on evidence state '$state'; only absent, by-design, or present-elsewhere may exclude");
|
|
1388
|
+
} elsif ($state !~ /^(?:absent|by-design|present-elsewhere)$/) {
|
|
1389
|
+
fail("documentation set excludes $id without an evidence state; the cell must open with 'absent:', 'by-design:', or 'present-elsewhere:'");
|
|
1390
|
+
}
|
|
1391
|
+
if ($predicate eq '') {
|
|
1392
|
+
fail("documentation set excludes $id without a revisit when: tripwire");
|
|
1393
|
+
} elsif (lc($predicate) =~ $vague_predicate) {
|
|
1394
|
+
fail("documentation set excludes $id with a vague revisit when: predicate");
|
|
1395
|
+
} elsif (length($predicate) < 12) {
|
|
1396
|
+
fail("documentation set excludes $id with a revisit when: predicate too short to observe");
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
} elsif ($detail eq '') {
|
|
1400
|
+
fail("documentation set row $id is optional but says nothing about why");
|
|
1401
|
+
}
|
|
1402
|
+
push @json_documents, {
|
|
1403
|
+
id => $id,
|
|
1404
|
+
stage => $stage,
|
|
1405
|
+
verdict => $verdict,
|
|
1406
|
+
owner => $owner,
|
|
1407
|
+
durability => $durability,
|
|
1408
|
+
detail => $detail,
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
fail("documentation set contains no catalog rows") unless $rows;
|
|
1412
|
+
fail("documentation set must state its boundary: the sentence that the manifest covers documentation committed to this repository")
|
|
1413
|
+
unless $boundary;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
my $decisions_count = section_count('Decisions');
|
|
1417
|
+
|
|
1418
|
+
if ($decisions_count == 1) {
|
|
1419
|
+
my $current_decision;
|
|
1420
|
+
my %decision_line;
|
|
1421
|
+
my %decision_title;
|
|
1422
|
+
my %decision_falsifier;
|
|
1423
|
+
my %falsifier_field;
|
|
1424
|
+
for my $index (section('## Decisions')) {
|
|
1425
|
+
my $line = $lines[$index];
|
|
1426
|
+
if ($line =~ /^### (D[1-9][0-9]*):[ \t]*(\S.*)$/) {
|
|
1427
|
+
$current_decision = $1;
|
|
1428
|
+
fail("duplicate decision heading $current_decision")
|
|
1429
|
+
if exists $decision_line{$current_decision};
|
|
1430
|
+
$decision_line{$current_decision} = $index + 1;
|
|
1431
|
+
$decision_title{$current_decision} = $2;
|
|
1432
|
+
next;
|
|
1433
|
+
}
|
|
1434
|
+
# Any other heading would carry a decision past the falsifier check.
|
|
1435
|
+
if ($line =~ /^### /) {
|
|
1436
|
+
fail('malformed decision heading on line ' . ($index + 1) . '; use ### D<n>: <title> or ### Assumptions ledger')
|
|
1437
|
+
unless $line =~ /^### Assumptions ledger$/i;
|
|
1438
|
+
$current_decision = undef;
|
|
1439
|
+
next;
|
|
1440
|
+
}
|
|
1441
|
+
if (defined $current_decision && $line eq 'Falsifier:') {
|
|
1442
|
+
$decision_falsifier{$current_decision}++;
|
|
1443
|
+
next;
|
|
1444
|
+
}
|
|
1445
|
+
if (defined $current_decision
|
|
1446
|
+
&& $line =~ /^- (Signal|Failure boundary|Replan action):[ \t]*(\S.*)$/) {
|
|
1447
|
+
my ($field, $value) = ($1, $2);
|
|
1448
|
+
fail("decision $current_decision has duplicate falsifier field $field")
|
|
1449
|
+
if exists $falsifier_field{$current_decision}{$field};
|
|
1450
|
+
$falsifier_field{$current_decision}{$field} = $value;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
fail("Decisions must contain at least one ### D<n>: entry")
|
|
1454
|
+
unless keys %decision_line;
|
|
1455
|
+
for my $decision (sort { substr($a, 1) <=> substr($b, 1) } keys %decision_line) {
|
|
1456
|
+
my $falsifier_count = $decision_falsifier{$decision} || 0;
|
|
1457
|
+
fail("decision $decision (line $decision_line{$decision}) is missing a Falsifier: block")
|
|
1458
|
+
if $falsifier_count == 0;
|
|
1459
|
+
fail("decision $decision has duplicate Falsifier: blocks")
|
|
1460
|
+
if $falsifier_count > 1;
|
|
1461
|
+
for my $field ('Signal', 'Failure boundary', 'Replan action') {
|
|
1462
|
+
fail("decision $decision Falsifier is missing $field")
|
|
1463
|
+
unless exists $falsifier_field{$decision}{$field};
|
|
1464
|
+
}
|
|
1465
|
+
if (exists $falsifier_field{$decision}{Signal}) {
|
|
1466
|
+
(my $signal = lc $falsifier_field{$decision}{Signal}) =~ s/^[(\[]+//;
|
|
1467
|
+
fail("decision $decision Signal is too vague to observe")
|
|
1468
|
+
if length($signal) < 12
|
|
1469
|
+
|| $signal =~ /^(?:metric|event|signal|performance|usage|something|tbd)\b/;
|
|
1470
|
+
}
|
|
1471
|
+
if (exists $falsifier_field{$decision}{'Failure boundary'}) {
|
|
1472
|
+
my $boundary = lc $falsifier_field{$decision}{'Failure boundary'};
|
|
1473
|
+
# An id such as D1, R-1.1, R-SEC-4, or GP-101 is not a threshold.
|
|
1474
|
+
(my $scan = $boundary) =~ s/\b(?:[da][1-9][0-9]*|gp-[0-9]+|r-[a-z0-9.-]*[0-9])\b//g;
|
|
1475
|
+
fail("decision $decision Failure boundary lacks an observable event or numeric threshold")
|
|
1476
|
+
if length($boundary) < 12
|
|
1477
|
+
|| $scan !~ /(?:[0-9]|exceed|below|above|unavailable|removed|reject|prohibit|deprecat|ship|cannot|breach|change|timeout|error)/;
|
|
1478
|
+
}
|
|
1479
|
+
if (exists $falsifier_field{$decision}{'Replan action'}) {
|
|
1480
|
+
my $action = lc $falsifier_field{$decision}{'Replan action'};
|
|
1481
|
+
fail("decision $decision Replan action must explicitly return to planning")
|
|
1482
|
+
if index($action, 'planning') < 0;
|
|
1483
|
+
fail("decision $decision Replan action must name what changes")
|
|
1484
|
+
if $action !~ /\b(?:replace|migrate|switch|evaluate|reconsider|redesign|split|merge|remove|adopt)\b/;
|
|
1485
|
+
}
|
|
1486
|
+
push @json_decisions, {
|
|
1487
|
+
id => $decision,
|
|
1488
|
+
title => $decision_title{$decision},
|
|
1489
|
+
falsifier => {
|
|
1490
|
+
signal => $falsifier_field{$decision}{Signal},
|
|
1491
|
+
failure_boundary => $falsifier_field{$decision}{'Failure boundary'},
|
|
1492
|
+
replan_action => $falsifier_field{$decision}{'Replan action'},
|
|
1493
|
+
},
|
|
1494
|
+
} if $falsifier_count == 1
|
|
1495
|
+
&& exists $falsifier_field{$decision}{Signal}
|
|
1496
|
+
&& exists $falsifier_field{$decision}{'Failure boundary'}
|
|
1497
|
+
&& exists $falsifier_field{$decision}{'Replan action'};
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
if (!@phases || $phases[-1]{name} ne 'Verification') {
|
|
1502
|
+
my $found = @phases ? $phases[-1]{name} : 'none';
|
|
1503
|
+
fail("final phase must be Verification, found '$found'");
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
if (@errors) {
|
|
1507
|
+
for my $error (@errors) {
|
|
1508
|
+
print STDERR "FAIL $plan_file: $error\n";
|
|
1509
|
+
}
|
|
1510
|
+
exit 1;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
# Every FAIL exits 1, drift and I/O included; 2 stays the usage code.
|
|
1514
|
+
sub bail {
|
|
1515
|
+
print STDERR "FAIL $plan_file: $_[0]\n";
|
|
1516
|
+
exit 1;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
# A signal, or a shell that never started, is not an exit status.
|
|
1520
|
+
sub rerun {
|
|
1521
|
+
my ($what, $command) = @_;
|
|
1522
|
+
system('sh', '-c', $command);
|
|
1523
|
+
bail("$what " . ($? == -1 ? "could not start: $!"
|
|
1524
|
+
: $? & 127 ? 'was killed by signal ' . ($? & 127) : 'exited ' . ($? >> 8))) if $?;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
if ($drift_phase ne '') {
|
|
1528
|
+
my ($phase) = grep { $_->{number} == $drift_phase } @phases;
|
|
1529
|
+
bail("drift phase $drift_phase does not exist") unless defined $phase;
|
|
1530
|
+
my @completed = grep { $tasks[$_]{done} } @{$phase->{tasks}};
|
|
1531
|
+
bail("drift phase $drift_phase is not complete") if @completed != @{$phase->{tasks}};
|
|
1532
|
+
|
|
1533
|
+
for my $label (sort keys %recheck_inventory) {
|
|
1534
|
+
bail('recheck inventory label intake is not a file path') if $label eq 'intake';
|
|
1535
|
+
open my $evidence_fh, '<:raw', $label
|
|
1536
|
+
or bail("recheck evidence $label cannot be read: $!");
|
|
1537
|
+
local $/;
|
|
1538
|
+
my $bytes = <$evidence_fh>;
|
|
1539
|
+
close $evidence_fh;
|
|
1540
|
+
bail("recheck evidence drifted: $label")
|
|
1541
|
+
if sha256_hex($bytes) ne $recheck_inventory{$label};
|
|
1542
|
+
print "recheck evidence ok: $label\n";
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
my @sample_positions;
|
|
1546
|
+
if (@completed <= 3) {
|
|
1547
|
+
@sample_positions = 0 .. $#completed;
|
|
1548
|
+
} else {
|
|
1549
|
+
@sample_positions = (0, int($#completed / 2), $#completed);
|
|
1550
|
+
}
|
|
1551
|
+
for my $position (@sample_positions) {
|
|
1552
|
+
my $task = $tasks[$completed[$position]];
|
|
1553
|
+
my ($command) = $task->{fields}{Verify}[0] =~ /^`(.*)`$/;
|
|
1554
|
+
print "drift sample $task->{id}: $command\n";
|
|
1555
|
+
rerun("drift sample $task->{id}", $command);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
# A phase of superseded tasks did no work, so it has no outcome to reprove.
|
|
1559
|
+
if (@completed) {
|
|
1560
|
+
my $checkpoint = $phase->{checkpoint_verify};
|
|
1561
|
+
print "checkpoint Phase $drift_phase: $checkpoint\n";
|
|
1562
|
+
rerun("Phase $drift_phase checkpoint", $checkpoint);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
if ($emit_json ne '') {
|
|
1567
|
+
my @json_phases = map {
|
|
1568
|
+
{
|
|
1569
|
+
number => $_->{number} + 0,
|
|
1570
|
+
name => $_->{name},
|
|
1571
|
+
tasks => [ map { $tasks[$_]{id} } @{$_->{tasks}} ],
|
|
1572
|
+
}
|
|
1573
|
+
} @phases;
|
|
1574
|
+
|
|
1575
|
+
my @json_tasks = map {
|
|
1576
|
+
my $task = $_;
|
|
1577
|
+
my @depends_on = dependency_ids($task);
|
|
1578
|
+
my @requirements = split /\s*,\s*/, $task->{fields}{Requirements}[0], -1;
|
|
1579
|
+
{
|
|
1580
|
+
id => $task->{id},
|
|
1581
|
+
phase => $phases[$task->{phase}]{number} + 0,
|
|
1582
|
+
wave => $task->{wave},
|
|
1583
|
+
done => $task->{done} ? JSON::PP::true : JSON::PP::false,
|
|
1584
|
+
parallel => $task->{parallel} ? JSON::PP::true : JSON::PP::false,
|
|
1585
|
+
files => $task->{fields}{Files}[0],
|
|
1586
|
+
depends_on => \@depends_on,
|
|
1587
|
+
reuses => $task->{fields}{Reuses}[0],
|
|
1588
|
+
acceptance => $task->{fields}{Acceptance}[0],
|
|
1589
|
+
verify => $task->{fields}{Verify}[0],
|
|
1590
|
+
requirements => \@requirements,
|
|
1591
|
+
}
|
|
1592
|
+
} @tasks;
|
|
1593
|
+
|
|
1594
|
+
my %domain_history;
|
|
1595
|
+
my $record_domains = sub {
|
|
1596
|
+
my ($task, $status) = @_;
|
|
1597
|
+
return unless exists $task->{fields}{Requirements};
|
|
1598
|
+
my %seen;
|
|
1599
|
+
for my $requirement (split /\s*,\s*/, $task->{fields}{Requirements}[0], -1) {
|
|
1600
|
+
next unless $requirement =~ /^R-([A-Z][A-Z0-9-]*)-[0-9]+$/;
|
|
1601
|
+
my $domain = $prefix_module{$1};
|
|
1602
|
+
next unless defined $domain;
|
|
1603
|
+
next if $seen{$domain}++;
|
|
1604
|
+
$domain_history{$domain}{$status}++;
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
$record_domains->($_, 'active') for @tasks;
|
|
1608
|
+
$record_domains->($_, 'superseded') for @superseded_tasks;
|
|
1609
|
+
|
|
1610
|
+
my @json_superseded = map {
|
|
1611
|
+
my $requirements = exists $_->{fields}{Requirements}
|
|
1612
|
+
? $_->{fields}{Requirements}[0] : '';
|
|
1613
|
+
{
|
|
1614
|
+
id => $_->{id},
|
|
1615
|
+
phase => $_->{phase} >= 0 ? $phases[$_->{phase}]{number} + 0 : undef,
|
|
1616
|
+
reason => exists $_->{fields}{Superseded}
|
|
1617
|
+
? $_->{fields}{Superseded}[0] : '',
|
|
1618
|
+
requirements => $requirements eq ''
|
|
1619
|
+
? [] : [ split /\s*,\s*/, $requirements, -1 ],
|
|
1620
|
+
}
|
|
1621
|
+
} @superseded_tasks;
|
|
1622
|
+
|
|
1623
|
+
my @domain_metrics = map {
|
|
1624
|
+
my $domain = $_;
|
|
1625
|
+
my $active = $domain_history{$domain}{active} || 0;
|
|
1626
|
+
my $superseded = $domain_history{$domain}{superseded} || 0;
|
|
1627
|
+
my $historical = $active + $superseded;
|
|
1628
|
+
{
|
|
1629
|
+
domain => $domain,
|
|
1630
|
+
active => $active,
|
|
1631
|
+
superseded => $superseded,
|
|
1632
|
+
historical => $historical,
|
|
1633
|
+
supersession_rate => $historical
|
|
1634
|
+
? 0 + sprintf('%.4f', $superseded / $historical) : 0,
|
|
1635
|
+
}
|
|
1636
|
+
} sort keys %domain_history;
|
|
1637
|
+
|
|
1638
|
+
my $historical_tasks = scalar(@tasks) + scalar(@superseded_tasks);
|
|
1639
|
+
my $supersession_rate = $historical_tasks
|
|
1640
|
+
? 0 + sprintf('%.4f', scalar(@superseded_tasks) / $historical_tasks) : 0;
|
|
1641
|
+
|
|
1642
|
+
my @json_applicability = map {
|
|
1643
|
+
{
|
|
1644
|
+
domain => $_,
|
|
1645
|
+
status => $domain_disposition{$_},
|
|
1646
|
+
reason => $domain_reason{$_},
|
|
1647
|
+
evidence_state => defined $domain_evidence_state{$_}
|
|
1648
|
+
? $domain_evidence_state{$_} : undef,
|
|
1649
|
+
revisit_when => defined $domain_revisit_when{$_}
|
|
1650
|
+
? $domain_revisit_when{$_} : undef,
|
|
1651
|
+
}
|
|
1652
|
+
} sort keys %domain_disposition;
|
|
1653
|
+
|
|
1654
|
+
my %document = (
|
|
1655
|
+
format => 'godplans/plan-json@2',
|
|
1656
|
+
plan_digest => 'sha256:' . sha256_hex($plan_bytes),
|
|
1657
|
+
name => $frontmatter{name},
|
|
1658
|
+
plan_version => $frontmatter{plan_version} + 0,
|
|
1659
|
+
status => $frontmatter{status},
|
|
1660
|
+
created => $frontmatter{created},
|
|
1661
|
+
updated => $frontmatter{updated},
|
|
1662
|
+
mode => $frontmatter{mode},
|
|
1663
|
+
product_form => $frontmatter{product_form},
|
|
1664
|
+
archetype => $frontmatter{archetype},
|
|
1665
|
+
archetype_confidence => $frontmatter{archetype_confidence},
|
|
1666
|
+
overlays => \@overlays,
|
|
1667
|
+
public_release => $frontmatter{public_release} eq 'true'
|
|
1668
|
+
? JSON::PP::true : JSON::PP::false,
|
|
1669
|
+
source_revision => $frontmatter{source_revision},
|
|
1670
|
+
input_digest => $frontmatter{input_digest},
|
|
1671
|
+
validated_at => $frontmatter{validated_at},
|
|
1672
|
+
progress => {
|
|
1673
|
+
phases_total => $counter{phases_total} + 0,
|
|
1674
|
+
phases_done => $counter{phases_done} + 0,
|
|
1675
|
+
tasks_total => $counter{tasks_total} + 0,
|
|
1676
|
+
tasks_done => $counter{tasks_done} + 0,
|
|
1677
|
+
},
|
|
1678
|
+
applicability => \@json_applicability,
|
|
1679
|
+
module_disposition => \@json_disposition,
|
|
1680
|
+
documentation => \@json_documents,
|
|
1681
|
+
decisions => \@json_decisions,
|
|
1682
|
+
phases => \@json_phases,
|
|
1683
|
+
tasks => \@json_tasks,
|
|
1684
|
+
superseded_tasks => \@json_superseded,
|
|
1685
|
+
metrics => {
|
|
1686
|
+
task_history => {
|
|
1687
|
+
active => scalar @tasks,
|
|
1688
|
+
superseded => scalar @superseded_tasks,
|
|
1689
|
+
historical => $historical_tasks,
|
|
1690
|
+
supersession_rate => $supersession_rate,
|
|
1691
|
+
survival_rate => 0 + sprintf('%.4f', 1 - $supersession_rate),
|
|
1692
|
+
},
|
|
1693
|
+
domains => \@domain_metrics,
|
|
1694
|
+
},
|
|
1695
|
+
);
|
|
1696
|
+
|
|
1697
|
+
my $json = JSON::PP->new->utf8->canonical(1)->pretty->encode(\%document);
|
|
1698
|
+
my $json_tmp = "$emit_json.tmp.$$";
|
|
1699
|
+
open my $json_fh, '>:raw', $json_tmp
|
|
1700
|
+
or bail("cannot write $json_tmp: $!");
|
|
1701
|
+
print {$json_fh} $json;
|
|
1702
|
+
close $json_fh;
|
|
1703
|
+
rename $json_tmp, $emit_json
|
|
1704
|
+
or bail("cannot replace $emit_json atomically: $!");
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
print "ok $plan_file\n";
|
|
1708
|
+
exit 0;
|
|
1709
|
+
PERL
|