instar 1.3.152 → 1.3.153

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "1.3.152",
3
+ "version": "1.3.153",
4
4
  "description": "Coherence infrastructure for self-evolving AI agents — on the Claude Code or Codex subscription you already have.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,311 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * assemble-next-md — fold per-PR release-note FRAGMENTS into a single NEXT.md.
4
+ *
5
+ * ── Why this exists ───────────────────────────────────────────────────
6
+ * The release pipeline consumes a single shared `upgrades/NEXT.md` per merge.
7
+ * With many agents merging concurrently, EVERY PR rewrote that one file, so
8
+ * every PR collided on it within minutes — the release notes became an
9
+ * un-landable hot file. The fix is per-PR FRAGMENTS: each PR ships its note as
10
+ * `upgrades/next/<slug>.md`, touching a distinct file, so two PRs never
11
+ * collide. This script concatenates the fragments into `upgrades/NEXT.md`
12
+ * BEFORE the existing publish pipeline runs, leaving everything downstream
13
+ * unchanged.
14
+ *
15
+ * ── What it does ──────────────────────────────────────────────────────
16
+ * 1. Reads every `upgrades/next/*.md` fragment (deterministic filename sort).
17
+ * 2. Folds in a legacy `upgrades/NEXT.md` too, if one exists (backward compat).
18
+ * 3. Merges by section: the result has ONE "## What Changed", ONE
19
+ * "## Summary of New Capabilities", ONE "## What to Tell Your User", ONE
20
+ * "## Evidence" — each section is the concatenation of that section across
21
+ * all inputs (in source order). Any non-canonical H2 section is preserved
22
+ * and appended after the canonical ones (also concatenated by title).
23
+ * 4. The bump directive is the HIGHEST tier among the inputs
24
+ * (major > minor > patch), emitted as `<!-- bump: X -->`. This is a
25
+ * documentation hint only — the REAL release tier is
26
+ * `.instar/release-tier.json`, which this script never touches.
27
+ * 5. Writes the merged result to `upgrades/NEXT.md`.
28
+ *
29
+ * ── No-op / failure semantics ─────────────────────────────────────────
30
+ * - NO fragments AND NO legacy NEXT.md → does nothing, exits 0 quietly. The
31
+ * existing publish "skip if no NEXT.md" logic then fires unchanged.
32
+ * - A real malformation (a fragment with content but no parseable H2 section
33
+ * at all) → exits non-zero with a clear message, so the workflow fails
34
+ * loudly rather than shipping a broken guide.
35
+ * - Idempotent: running twice produces the same NEXT.md. (When a generated
36
+ * NEXT.md is the ONLY input — no fragments — it is re-emitted byte-stable.)
37
+ *
38
+ * The core `assembleNextMd()` function is pure (string in / string out) and is
39
+ * exported for unit testing. The CLI wrapper at the bottom handles I/O.
40
+ *
41
+ * Usage:
42
+ * node scripts/assemble-next-md.mjs # assemble + write upgrades/NEXT.md
43
+ * node scripts/assemble-next-md.mjs --upgrades-dir <path> # override (tests)
44
+ */
45
+
46
+ import fs from 'node:fs';
47
+ import path from 'node:path';
48
+ import { fileURLToPath, pathToFileURL } from 'node:url';
49
+
50
+ // ── Canonical section order ───────────────────────────────────────────
51
+ // These four are the sections check-upgrade-guide.js / upgrade-guide-validator
52
+ // know about. We emit them in this order; any other H2 is appended after.
53
+ export const CANONICAL_SECTIONS = [
54
+ 'What Changed',
55
+ 'What to Tell Your User',
56
+ 'Summary of New Capabilities',
57
+ 'Evidence',
58
+ ];
59
+
60
+ const BUMP_RANK = { patch: 0, minor: 1, major: 2 };
61
+ const RANK_BUMP = ['patch', 'minor', 'major'];
62
+
63
+ const H1_HEADER = '# Upgrade Guide — vNEXT';
64
+
65
+ // Stable marker stamped into every machine-assembled NEXT.md. It lets us
66
+ // recognize (and skip re-folding) a NEXT.md that this script generated, which
67
+ // is what keeps the on-disk assemble idempotent: a second run shouldn't fold
68
+ // the previous run's output back in on top of the still-present fragments. A
69
+ // hand-authored legacy NEXT.md (no marker) is still folded for backward compat.
70
+ export const GENERATED_MARKER = '<!-- assembled-by: assemble-next-md -->';
71
+
72
+ /** True when content was produced by this assembler (carries the marker). */
73
+ export function isAssembledOutput(content) {
74
+ return String(content).includes(GENERATED_MARKER);
75
+ }
76
+
77
+ /**
78
+ * Parse the declared bump type from a fragment's `<!-- bump: TYPE -->` comment.
79
+ * Returns 'patch' | 'minor' | 'major' | null.
80
+ */
81
+ export function parseBumpType(content) {
82
+ const match = /<!--\s*bump:\s*(patch|minor|major)\s*-->/i.exec(content);
83
+ return match ? match[1].toLowerCase() : null;
84
+ }
85
+
86
+ /**
87
+ * Split a fragment body into H2 sections: [{ title, body }] in source order.
88
+ * `body` excludes the heading line itself and is right-trimmed.
89
+ * Content before the first H2 (H1 header, bump comment, stray prose) is dropped
90
+ * from the section map — the assembler synthesizes a fresh H1 + bump comment.
91
+ */
92
+ export function parseSections(content) {
93
+ const out = [];
94
+ const lines = String(content).replace(/\r\n/g, '\n').split('\n');
95
+ let current = null;
96
+ for (const line of lines) {
97
+ const m = /^##\s+(.+?)\s*$/.exec(line);
98
+ if (m) {
99
+ if (current) out.push(current);
100
+ current = { title: m[1].trim(), lines: [] };
101
+ } else if (current) {
102
+ current.lines.push(line);
103
+ }
104
+ }
105
+ if (current) out.push(current);
106
+ return out.map((s) => ({ title: s.title, body: s.lines.join('\n').replace(/\s+$/, '') }));
107
+ }
108
+
109
+ /**
110
+ * Is this fragment content "empty" for assembly purposes? True when stripping
111
+ * HTML comments and whitespace leaves nothing.
112
+ */
113
+ function isEffectivelyEmpty(content) {
114
+ return String(content).replace(/<!--[\s\S]*?-->/g, '').trim().length === 0;
115
+ }
116
+
117
+ /**
118
+ * Core assembler. Pure: takes named fragment inputs, returns the merged NEXT.md
119
+ * string (or throws on a real malformation).
120
+ *
121
+ * @param {Array<{ name: string, content: string }>} fragments
122
+ * Each input fragment, in the order they should be concatenated. `name` is
123
+ * used only for error messages.
124
+ * @returns {string} the assembled NEXT.md content (with trailing newline).
125
+ * @throws {Error} when a fragment has content but no parseable H2 section.
126
+ */
127
+ export function assembleNextMd(fragments) {
128
+ // Idempotency guard: a previously-assembled NEXT.md (carrying GENERATED_MARKER)
129
+ // is the FOLD of the current fragments — folding it again on top of the same
130
+ // fragments would duplicate every section. So when at least one non-generated
131
+ // input is present, drop the generated one(s). When a generated output is the
132
+ // SOLE input (no fragments), keep it: parse→emit is stable, so it re-emits
133
+ // identically.
134
+ const nonGenerated = fragments.filter((f) => !isAssembledOutput(f.content ?? ''));
135
+ const effective = nonGenerated.length > 0 ? nonGenerated : fragments;
136
+
137
+ // Map title -> array of section bodies (in source order).
138
+ const merged = new Map();
139
+ // Preserve first-seen order of non-canonical titles.
140
+ const extraOrder = [];
141
+ let maxBumpRank = 0;
142
+ let sawAnyBump = false;
143
+
144
+ for (const frag of effective) {
145
+ const content = frag.content ?? '';
146
+ const bump = parseBumpType(content);
147
+ if (bump) {
148
+ sawAnyBump = true;
149
+ maxBumpRank = Math.max(maxBumpRank, BUMP_RANK[bump]);
150
+ }
151
+
152
+ const sections = parseSections(content);
153
+ if (sections.length === 0) {
154
+ // No H2 sections. An effectively-empty fragment (only comments/whitespace)
155
+ // is malformed — a fragment file should always carry real notes.
156
+ // A fragment with real prose but no headings is also malformed: we can't
157
+ // place its content under a known section.
158
+ throw new Error(
159
+ `release-note fragment "${frag.name}" has no recognizable "## " section. ` +
160
+ `Every fragment must contain at least one section heading ` +
161
+ `(e.g. "## What Changed"). Fix or remove this fragment.`,
162
+ );
163
+ }
164
+
165
+ for (const sec of sections) {
166
+ const body = sec.body.trim();
167
+ // Skip a section whose body is only whitespace/comments — nothing to fold.
168
+ if (isEffectivelyEmpty(body)) continue;
169
+ if (!merged.has(sec.title)) {
170
+ merged.set(sec.title, []);
171
+ if (!CANONICAL_SECTIONS.includes(sec.title)) extraOrder.push(sec.title);
172
+ }
173
+ merged.get(sec.title).push(body);
174
+ }
175
+ }
176
+
177
+ // If after folding there is genuinely nothing to say, that's a malformation
178
+ // for a non-empty input set (every fragment was comments-only).
179
+ if (merged.size === 0) {
180
+ throw new Error(
181
+ 'release-note fragments produced no content — every section was empty. ' +
182
+ 'Fill in at least "## What Changed" in one fragment.',
183
+ );
184
+ }
185
+
186
+ // Emit canonical sections first (only when present), then extras in
187
+ // first-seen order.
188
+ const titleOrder = [
189
+ ...CANONICAL_SECTIONS.filter((t) => merged.has(t)),
190
+ ...extraOrder,
191
+ ];
192
+
193
+ const bump = sawAnyBump ? RANK_BUMP[maxBumpRank] : 'patch';
194
+
195
+ const parts = [];
196
+ parts.push(H1_HEADER);
197
+ parts.push('');
198
+ parts.push(GENERATED_MARKER);
199
+ parts.push(`<!-- bump: ${bump} -->`);
200
+ parts.push('');
201
+ for (const title of titleOrder) {
202
+ const bodies = merged.get(title);
203
+ parts.push(`## ${title}`);
204
+ parts.push('');
205
+ // Concatenate each fragment's body for this section, separated by a blank
206
+ // line. Bodies were already trimmed.
207
+ parts.push(bodies.join('\n\n'));
208
+ parts.push('');
209
+ }
210
+
211
+ // Single trailing newline, no duplicate blank lines at EOF.
212
+ return parts.join('\n').replace(/\n+$/, '\n');
213
+ }
214
+
215
+ // ── CLI entry point ────────────────────────────────────────────────────
216
+
217
+ /**
218
+ * Gather fragment inputs from disk in deterministic order: legacy NEXT.md first
219
+ * (so its content leads), then `next/*.md` sorted by filename.
220
+ */
221
+ export function gatherFragmentInputs(upgradesDir) {
222
+ const inputs = [];
223
+
224
+ const legacyPath = path.join(upgradesDir, 'NEXT.md');
225
+ const fragmentsDir = path.join(upgradesDir, 'next');
226
+
227
+ let legacyContent = null;
228
+ if (fs.existsSync(legacyPath)) {
229
+ legacyContent = fs.readFileSync(legacyPath, 'utf-8');
230
+ }
231
+
232
+ let fragmentFiles = [];
233
+ if (fs.existsSync(fragmentsDir)) {
234
+ fragmentFiles = fs
235
+ .readdirSync(fragmentsDir)
236
+ .filter((f) => f.endsWith('.md'))
237
+ .sort((a, b) => a.localeCompare(b, 'en'));
238
+ }
239
+
240
+ // Fold the legacy NEXT.md in first — only when it carries real content
241
+ // (skip a bare template/empty file so re-runs are idempotent and a fresh
242
+ // template doesn't masquerade as content).
243
+ if (legacyContent !== null && !isEffectivelyEmpty(legacyContent)) {
244
+ inputs.push({ name: 'NEXT.md', content: legacyContent });
245
+ }
246
+
247
+ for (const file of fragmentFiles) {
248
+ const content = fs.readFileSync(path.join(fragmentsDir, file), 'utf-8');
249
+ inputs.push({ name: `next/${file}`, content });
250
+ }
251
+
252
+ return { inputs, hadLegacy: legacyContent !== null, fragmentCount: fragmentFiles.length };
253
+ }
254
+
255
+ function main() {
256
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
257
+ const ROOT = path.resolve(__dirname, '..');
258
+
259
+ // Allow tests / callers to point at an alternate upgrades dir.
260
+ const argIdx = process.argv.indexOf('--upgrades-dir');
261
+ const upgradesDir =
262
+ argIdx !== -1 && process.argv[argIdx + 1]
263
+ ? path.resolve(process.argv[argIdx + 1])
264
+ : path.join(ROOT, 'upgrades');
265
+
266
+ const { inputs, hadLegacy, fragmentCount } = gatherFragmentInputs(upgradesDir);
267
+
268
+ if (inputs.length === 0) {
269
+ // No fragments and no (content-bearing) legacy NEXT.md. Do nothing — the
270
+ // existing publish skip logic handles the "nothing to publish" case.
271
+ console.log(
272
+ `[assemble-next-md] no fragments in ${path.join(upgradesDir, 'next')} ` +
273
+ `and no content-bearing NEXT.md — nothing to assemble.`,
274
+ );
275
+ process.exit(0);
276
+ }
277
+
278
+ let assembled;
279
+ try {
280
+ assembled = assembleNextMd(inputs);
281
+ } catch (err) {
282
+ console.error(`[assemble-next-md] ERROR: ${err instanceof Error ? err.message : String(err)}`);
283
+ process.exit(1);
284
+ }
285
+
286
+ const nextPath = path.join(upgradesDir, 'NEXT.md');
287
+ fs.mkdirSync(upgradesDir, { recursive: true });
288
+ fs.writeFileSync(nextPath, assembled);
289
+
290
+ console.log(
291
+ `[assemble-next-md] assembled ${fragmentCount} fragment(s)` +
292
+ `${hadLegacy ? ' + legacy NEXT.md' : ''} → ${path.relative(ROOT, nextPath)}`,
293
+ );
294
+ process.exit(0);
295
+ }
296
+
297
+ // Only run main() when invoked directly (not when imported by tests).
298
+ // Compare resolved file URLs rather than string-concatenating argv[1] — that
299
+ // naive form breaks on relative paths and paths containing spaces.
300
+ function invokedDirectly() {
301
+ if (!process.argv[1]) return false;
302
+ try {
303
+ return import.meta.url === pathToFileURL(fs.realpathSync(process.argv[1])).href;
304
+ } catch {
305
+ return import.meta.url === pathToFileURL(process.argv[1]).href;
306
+ }
307
+ }
308
+
309
+ if (invokedDirectly()) {
310
+ main();
311
+ }
@@ -14,11 +14,11 @@ import fs from 'node:fs';
14
14
  import path from 'node:path';
15
15
  import { fileURLToPath } from 'node:url';
16
16
  import { validateGuideContent } from './upgrade-guide-validator.mjs';
17
+ import { assembleNextMd, gatherFragmentInputs } from './assemble-next-md.mjs';
17
18
 
18
19
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
20
  const ROOT = path.resolve(__dirname, '..');
20
21
  const upgradesDir = path.join(ROOT, 'upgrades');
21
- const nextPath = path.join(ROOT, 'upgrades', 'NEXT.md');
22
22
  const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf-8'));
23
23
  const version = pkg.version;
24
24
 
@@ -34,38 +34,66 @@ const REQUIRED_SECTIONS = [
34
34
  let errors = [];
35
35
  let warnings = [];
36
36
 
37
- // ── 1. NEXT.md validation ─────────────────────────────────────────────
37
+ // ── 1. Release-note validation (fragment-aware) ───────────────────────
38
+ //
39
+ // Release notes are authored as per-PR FRAGMENTS in upgrades/next/<slug>.md
40
+ // (so concurrent PRs never collide on a single shared NEXT.md). The pre-push
41
+ // gate validates the ASSEMBLED result — fragments folded together with any
42
+ // legacy upgrades/NEXT.md — so a PR that ships only a fragment passes the same
43
+ // section/content checks the publish gate enforces. We assemble in-memory and
44
+ // NEVER write NEXT.md to disk here: the PR keeps its fragment, not a generated
45
+ // guide. publish.yml runs the real assemble step before publishing.
38
46
 
39
47
  const versionedGuidePath = path.join(upgradesDir, `${version}.md`);
40
48
  const versionedGuideExists = fs.existsSync(versionedGuidePath);
41
- const nextExists = fs.existsSync(nextPath);
42
-
43
- // Pick the active guide for this push. NEXT.md wins if present (in-flight
44
- // release notes); fall back to the versioned guide once NEXT.md has been
45
- // renamed during a publish.
46
- const activeGuidePath = nextExists
47
- ? nextPath
48
- : (versionedGuideExists ? versionedGuidePath : null);
49
- const activeGuideLabel = nextExists
50
- ? 'NEXT.md'
51
- : (versionedGuideExists ? `${version}.md` : null);
52
49
 
53
- if (activeGuidePath && activeGuideLabel) {
54
- const content = fs.readFileSync(activeGuidePath, 'utf-8');
50
+ // Assemble fragments + legacy NEXT.md in-memory.
51
+ let assembledContent = null;
52
+ let assembleError = null;
53
+ {
54
+ const { inputs } = gatherFragmentInputs(upgradesDir);
55
+ if (inputs.length > 0) {
56
+ try {
57
+ assembledContent = assembleNextMd(inputs);
58
+ } catch (err) {
59
+ assembleError = err instanceof Error ? err.message : String(err);
60
+ }
61
+ }
62
+ }
55
63
 
64
+ // The active guide for validation: the assembled fragments/NEXT.md (in-flight
65
+ // release notes) win when present; otherwise fall back to the versioned guide
66
+ // (post-release-cut state, when NEXT.md has been renamed and no new fragment is
67
+ // staged yet).
68
+ const activeGuideLabel = assembledContent !== null
69
+ ? 'assembled release notes (upgrades/next/*.md + NEXT.md)'
70
+ : (versionedGuideExists ? `${version}.md` : null);
71
+
72
+ if (assembleError) {
73
+ // A malformed fragment must fail the push loudly — the same loud failure the
74
+ // publish workflow would hit.
75
+ errors.push(`Release-note fragments are malformed: ${assembleError}`);
76
+ } else if (assembledContent !== null) {
56
77
  // Run the shared validator (same checks as check-upgrade-guide.js at publish
57
78
  // time). This catches the publish-blocker bugs that previously slipped past
58
79
  // pre-push: inline code / fenced blocks / camelCase config keys in "What to
59
80
  // Tell Your User", and missing "## Evidence" when "What Changed" claims a fix.
60
81
  // Before this gate, those defects only surfaced as silently-dropped publish
61
82
  // runs on main — agents never received the merged code.
62
- const validatorIssues = validateGuideContent(content);
83
+ const validatorIssues = validateGuideContent(assembledContent);
63
84
  for (const issue of validatorIssues) {
64
85
  errors.push(`${activeGuideLabel}: ${issue}`);
65
86
  }
87
+ } else if (versionedGuideExists) {
88
+ const content = fs.readFileSync(versionedGuidePath, 'utf-8');
89
+ const validatorIssues = validateGuideContent(content);
90
+ for (const issue of validatorIssues) {
91
+ errors.push(`${version}.md: ${issue}`);
92
+ }
66
93
  } else {
67
94
  errors.push(
68
- `No upgrade guide found. Create upgrades/NEXT.md with sections: ${REQUIRED_SECTIONS.join(', ')}`
95
+ `No upgrade guide found. Create a release-note fragment ` +
96
+ `upgrades/next/<slug>.md (or legacy upgrades/NEXT.md) with sections: ${REQUIRED_SECTIONS.join(', ')}`
69
97
  );
70
98
  }
71
99
 
@@ -221,14 +249,16 @@ if (!process.env.CI) {
221
249
  /\bnew\b/i,
222
250
  ];
223
251
 
224
- // When NEXT.md exists, it represents the *next* shipment being prepared in
225
- // this push — prefer it over the (frozen) versioned guide, which describes
226
- // the already-released version and isn't what this PR is changing. This is
227
- // the post-release-cut + new-PR state: both files coexist, but only NEXT.md
228
- // is in flight. Falls back to the versioned guide when no NEXT.md is staged.
229
- const guidePath = nextExists ? nextPath : (versionedGuideExists ? versionedGuidePath : null);
230
- if (guidePath && fs.existsSync(guidePath)) {
231
- const guideContent = fs.readFileSync(guidePath, 'utf-8');
252
+ // The in-flight release notes (assembled fragments + legacy NEXT.md) represent
253
+ // the *next* shipment being prepared in this push — prefer them over the
254
+ // (frozen) versioned guide, which describes the already-released version and
255
+ // isn't what this PR is changing. Falls back to the versioned guide when no
256
+ // fragment / NEXT.md is staged (post-release-cut state).
257
+ const inFlight = assembledContent !== null;
258
+ const guideContent = inFlight
259
+ ? assembledContent
260
+ : (versionedGuideExists ? fs.readFileSync(versionedGuidePath, 'utf-8') : null);
261
+ if (guideContent !== null) {
232
262
  // Extract "## What Changed" section
233
263
  const whatChangedMatch = guideContent.match(/## What Changed\s*([\s\S]*?)(?=\n##\s|$)/);
234
264
  const whatChanged = whatChangedMatch ? whatChangedMatch[1] : '';
@@ -237,10 +267,10 @@ if (!process.env.CI) {
237
267
 
238
268
  if (qualifies) {
239
269
  const sideEffectsDir = path.join(ROOT, 'upgrades', 'side-effects');
240
- // If NEXT.md is the active guide, any fresh artifact (last 24h) counts —
241
- // the versioned-filename requirement only applies when a versioned guide
242
- // is being validated without an in-flight NEXT.md.
243
- const artifactName = (!nextExists && versionedGuideExists) ? `${version}.md` : null;
270
+ // When in-flight notes (fragments/NEXT.md) drive the push, any fresh
271
+ // artifact (last 24h) counts — the versioned-filename requirement only
272
+ // applies when a versioned guide is being validated without in-flight notes.
273
+ const artifactName = (!inFlight && versionedGuideExists) ? `${version}.md` : null;
244
274
  let artifactFound = false;
245
275
 
246
276
  if (fs.existsSync(sideEffectsDir)) {
@@ -248,9 +278,9 @@ if (!process.env.CI) {
248
278
  if (artifactName) {
249
279
  artifactFound = files.includes(artifactName);
250
280
  } else {
251
- // For NEXT.md, any fresh artifact from the last 24h counts.
252
- // The expectation is that during release cut, NEXT.md -> <version>.md
253
- // rename will pair with the artifact rename as well.
281
+ // For in-flight notes (fragments/NEXT.md), any fresh artifact from the
282
+ // last 24h counts. The expectation is that during release cut, the
283
+ // fragment/NEXT.md -> <version>.md rename pairs with an artifact rename.
254
284
  const recent = files.filter((f) => {
255
285
  const stat = fs.statSync(path.join(sideEffectsDir, f));
256
286
  return Date.now() - stat.mtimeMs < 24 * 60 * 60 * 1000;
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "./builtin-manifest.schema.json",
3
3
  "schemaVersion": 1,
4
- "generatedAt": "2026-05-31T09:03:11.651Z",
5
- "instarVersion": "1.3.152",
4
+ "generatedAt": "2026-05-31T09:19:20.889Z",
5
+ "instarVersion": "1.3.153",
6
6
  "entryCount": 193,
7
7
  "entries": {
8
8
  "hook:session-start": {
@@ -0,0 +1,51 @@
1
+ # Upgrade Guide — vNEXT
2
+
3
+ <!-- assembled-by: assemble-next-md -->
4
+ <!-- bump: minor -->
5
+
6
+ ## What Changed
7
+
8
+ Release notes are now authored as per-PR **fragments** instead of a single shared
9
+ `upgrades/NEXT.md`. Each PR drops its release note at `upgrades/next/<slug>.md`,
10
+ touching a distinct file, so two concurrent PRs never collide on the release
11
+ notes — the bottleneck that made many-agent merges un-landable in real time.
12
+
13
+ A new pure script, `scripts/assemble-next-md.mjs`, folds every fragment (sorted
14
+ deterministically by filename) — plus any legacy `upgrades/NEXT.md`, for backward
15
+ compatibility — into a single `upgrades/NEXT.md`, merging by section: one What
16
+ Changed, one What to Tell Your User, one Summary of New Capabilities, one Evidence,
17
+ each being the concatenation of that section across all inputs. Non-canonical
18
+ sections are preserved and appended. The emitted bump directive is the highest tier
19
+ among the fragments (major beats minor beats patch); it is a documentation hint only
20
+ — the real release tier still comes from `.instar/release-tier.json`, which is
21
+ untouched.
22
+
23
+ The publish workflow gains ONE new step, "Assemble release-note fragments", placed
24
+ immediately before the existing "Check if NEXT.md has content to publish" step.
25
+ Everything downstream — the tier gate, version resolution, the rename, the upgrade
26
+ guide check, publish, and commit — is unchanged. With no fragments and no legacy
27
+ NEXT.md, the assemble step does nothing and the existing skip logic fires exactly as
28
+ before, so the no-fragments path reproduces current behavior byte-for-byte. After a
29
+ release is cut, consumed fragments are deleted (`rm -f upgrades/next/*.md`) and the
30
+ existing commit step stages the deletions. The pre-push gate is now fragment-aware:
31
+ it validates the assembled result in-memory (never writing NEXT.md to disk during
32
+ pre-push), so a PR that ships only a fragment passes the same section and content
33
+ checks the publish gate enforces, and a malformed fragment fails the push loudly.
34
+ `upgrades/NEXT.md` remains fully supported as a legacy, backward-compatible path.
35
+
36
+ ## What to Tell Your User
37
+
38
+ Behind the scenes, the way I prepare release notes got a lot more robust. Each
39
+ change now writes its own small note in its own file, instead of every change
40
+ fighting over one shared notes file. That means when several updates are being
41
+ prepared at the same time, they no longer block each other, so improvements reach
42
+ you faster and with less risk of a release getting stuck. Nothing changes about how
43
+ I talk to you — this is purely a smoother release pipeline on my side.
44
+
45
+ ## Summary of New Capabilities
46
+
47
+ | Capability | How to Use |
48
+ |-----------|-----------|
49
+ | Per-PR release-note fragments | Write `upgrades/next/<slug>.md` (one file per change) |
50
+ | Fragment assembler | `node scripts/assemble-next-md.mjs` (runs automatically in publish) |
51
+ | Legacy NEXT.md | Still supported — folded in for backward compatibility |
@@ -0,0 +1,151 @@
1
+ # Side-Effects Review — Per-PR release-note fragments
2
+
3
+ **Version / slug:** `nextmd-release-note-fragments`
4
+ **Date:** `2026-05-31`
5
+ **Author:** `echo`
6
+ **Second-pass reviewer:** `required` (release-pipeline blast radius — see §1, §7)
7
+
8
+ ## Summary of the change
9
+
10
+ The release pipeline consumed a single shared `upgrades/NEXT.md` per merge. With
11
+ many agents merging concurrently, every PR rewrote NEXT.md, so every PR collided on
12
+ it within minutes — the release notes became an un-landable hot file. This change
13
+ introduces per-PR release-note FRAGMENTS (`upgrades/next/<slug>.md`): two PRs touch
14
+ different fragment files and never collide.
15
+
16
+ The mechanism is an ASSEMBLE PRE-STEP. A new pure script
17
+ (`scripts/assemble-next-md.mjs`) folds every fragment (deterministic filename sort)
18
+ plus any legacy `upgrades/NEXT.md` into a single `upgrades/NEXT.md`, merging by
19
+ section. The publish workflow runs it immediately BEFORE the existing
20
+ "Check if NEXT.md has content to publish" step; everything downstream is unchanged.
21
+ The pre-push gate validates the assembled result in-memory (never writing NEXT.md).
22
+
23
+ ## Decision-point inventory
24
+
25
+ 1. **No-fragments / no-legacy-NEXT.md → no-op (exit 0 quietly).** The existing skip
26
+ logic then fires. This is the load-bearing backward-compat boundary.
27
+ 2. **Malformed fragment (content but no parseable `## ` section, or only
28
+ comments/whitespace) → loud non-zero exit.** Fails the workflow rather than
29
+ shipping a broken guide.
30
+ 3. **Idempotency guard:** an input carrying `GENERATED_MARKER` is dropped when any
31
+ non-generated input is present; folded straight through (stable re-emit) when it
32
+ is the sole input. Decides "is this a fresh fragment set or a re-run on prior
33
+ output?"
34
+ 4. **Bump tier = MAX(fragments).** A hint only; the real tier is
35
+ `.instar/release-tier.json` (untouched).
36
+ 5. **pre-push gate active-guide selection:** assembled in-flight notes win; else fall
37
+ back to the versioned guide; else "no guide" error.
38
+
39
+ ## 1. Over-block
40
+
41
+ **What legitimate inputs does this change reject?** A fragment with real prose but no
42
+ `## ` heading is rejected — intentional, because the assembler can't place headless
43
+ prose under a known section. An effectively-empty fragment (comments/whitespace only)
44
+ is rejected — intentional, an empty fragment file is a mistake. A hand-authored legacy
45
+ `upgrades/NEXT.md` is NOT rejected: it is folded in (backward compat). The
46
+ no-fragments-and-no-NEXT.md case is NOT an error — it is a clean exit-0 no-op, so the
47
+ existing "nothing to publish" skip is preserved exactly. **No legitimate current input
48
+ is newly rejected:** today's flow ships a NEXT.md, which still validates and publishes
49
+ unchanged.
50
+
51
+ ## 2. Under-block
52
+
53
+ **What does this still miss?** The assembler does not deep-validate each fragment's
54
+ section CONTENT (camelCase keys, inline code, missing Evidence) — that remains the job
55
+ of `validateGuideContent`, which runs against the ASSEMBLED result in both the pre-push
56
+ gate and (post-rename) `check-upgrade-guide.js`. So a defect in a fragment is caught at
57
+ the assembled layer, not per-fragment; this is acceptable because the assembled doc is
58
+ exactly what publishes. It does not detect two fragments making contradictory claims —
59
+ out of scope (humans review notes). It does not garbage-collect stale fragments that
60
+ were never released; the publish path deletes only the fragments it just consumed.
61
+
62
+ ## 3. Level-of-abstraction fit
63
+
64
+ **Right layer?** Yes. The assembler is a pure string→string function with a thin CLI
65
+ wrapper (same shape as `resolve-release-tier.mjs` / `resolve-publish-version.mjs`),
66
+ unit-tested in isolation. The workflow change is one additive step plus one `rm` in the
67
+ existing consumption path — it does not touch the tier gate, version resolution, rename,
68
+ guide check, publish, or commit logic. The pre-push gate reuses the SAME assemble
69
+ function (single source of truth), so pre-push and publish can never diverge on how
70
+ fragments fold.
71
+
72
+ ## 4. Signal vs authority compliance
73
+
74
+ **Required reference:** [docs/signal-vs-authority.md](../../docs/signal-vs-authority.md)
75
+
76
+ No new blocking AUTHORITY over releases is added. The assembler is a transform, not a
77
+ gate: its only failure mode is a malformation (exit non-zero), which is the same loud
78
+ behavior the publish workflow already wants. The real publish AUTHORITY is unchanged —
79
+ `.instar/release-tier.json` (Layer 2) and `validateGuideContent` (the section/content
80
+ gate) still decide what ships. The emitted bump comment is explicitly a documentation
81
+ SIGNAL, not authority (the code comment and the artifact both say so).
82
+
83
+ ## 5. Interactions
84
+
85
+ - **UpgradeGuideProcessor**: scans `upgrades/` for files matching
86
+ `^(\d+\.\d+\.\d+)\.md$`. `readdirSync` returns the subdir name `next` (no `.md`
87
+ suffix) → not matched → ignored. Verified by reading `getAvailableGuides`. The
88
+ `upgrades/next/` directory is invisible to guide delivery.
89
+ - **check-upgrade-guide.js**: iterates `upgrades/*.md` files (skips `NEXT.md`); the
90
+ `next/` subdir is not a `.md` file → skipped. By publish time fragments are already
91
+ deleted and NEXT.md renamed, so it validates the assembled+renamed guide. Verified
92
+ end-to-end in a scratch dir (assemble → rename → check → exit 0).
93
+ - **pre-push-gate.js**: now imports the assembler; assembles in-memory; the side-effects
94
+ artifact check (§5 of the gate) reads the assembled "What Changed" instead of raw
95
+ NEXT.md. No NEXT.md is written during pre-push.
96
+ - **Idempotency / re-runs**: the `GENERATED_MARKER` guard prevents a re-run from
97
+ double-folding prior output back over still-present fragments.
98
+ - No interaction with SessionReaper, sentinels, recovery, or any runtime path — this is
99
+ build/CI tooling only.
100
+
101
+ ## 6. External surfaces
102
+
103
+ - New directory `upgrades/next/` and new file convention `upgrades/next/<slug>.md`.
104
+ - New script `scripts/assemble-next-md.mjs` (build-time only; never shipped to agent
105
+ runtime paths).
106
+ - One new publish workflow step + one `rm` in the existing rename step.
107
+ - New CLAUDE.md / build-skill guidance instructing fragment authoring; a
108
+ `PostUpdateMigrator` CLAUDE.md backfill for deployed agents.
109
+ - No HTTP routes, no config keys, no Telegram, no agent runtime behavior change.
110
+
111
+ ## 7. Rollback cost
112
+
113
+ **Low and clean.** Three independent revert points, each safe on its own:
114
+ - Remove the "Assemble release-note fragments" workflow step + the `rm` line → publish
115
+ reverts to consuming NEXT.md directly (NEXT.md authoring still works).
116
+ - Revert the pre-push gate to validating NEXT.md directly.
117
+ - Delete `scripts/assemble-next-md.mjs` + its test.
118
+ Because the no-fragments path is a byte-for-byte no-op, a half-rollback (e.g. removing
119
+ only the workflow step while authors still write fragments) degrades gracefully: the
120
+ release simply skips (no NEXT.md), which the release-readiness sentinel surfaces — it
121
+ never ships a wrong or partial guide. No state, no schema, no irreversible op, no data
122
+ migration. Fragments are plain markdown files.
123
+
124
+ ## Conclusion
125
+
126
+ Additive, backward-compatible, pure-function-at-the-core change to build/CI tooling.
127
+ The release-critical invariant — "the no-fragments path reproduces exact current
128
+ behavior" — is enforced by code (clean exit-0 no-op) and covered by tests (CLI exits 0
129
+ and writes nothing; pre-push accepts a fragment-only push and rejects a malformed one).
130
+ Blast radius is contained to the assemble pre-step; the tier gate, version resolution,
131
+ and content validation that actually authorize a release are untouched.
132
+
133
+ ## Second-pass review (if required)
134
+
135
+ Required (release-pipeline). Reviewer focus: confirm the publish.yml diff is additive
136
+ (the assemble step precedes the unchanged skip-check; the `rm` rides the existing
137
+ `if:` guard and the existing `git add upgrades/`), and that the no-fragments path still
138
+ skips cleanly. Pending.
139
+
140
+ ## Evidence pointers
141
+
142
+ - `tests/unit/assemble-next-md.test.ts` — 25 tests: section merge, deterministic order,
143
+ max bump tier, single fragment, legacy fold, no-op/quiet, malformed→loud, idempotent
144
+ (in-memory + on-disk CLI), WTTYU backtick-free.
145
+ - `tests/unit/pre-push-gate.test.ts` — fragment-aware integration: accepts fragment-only
146
+ push (writes no NEXT.md), rejects WTTYU inline code via assembled validation, rejects
147
+ malformed fragment loudly.
148
+ - Manual end-to-end (scratch dir): fragment → `assemble-next-md.mjs` →
149
+ `mv NEXT.md <version>.md` + `rm next/*.md` → `check-upgrade-guide.js` exit 0.
150
+ - `upgrades/next/release-note-fragments.md` — this PR's own release note (dogfoods the
151
+ mechanism; the PR does not touch `upgrades/NEXT.md`).