Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

refactor(view): move hosted release facts to src/view [N26,A2]

Corey Olson333d4c438b57
diff --git a/src/cockpit.js b/src/cockpit.js
index 839e22eb..8a306066 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -5,42 +5,11 @@ import {
} from './machine.js';
import { commandPhrases, VERSION } from './help.js';
import { personNeeds } from './needs.js';
-import { readFileSync } from 'node:fs';
+import { hostedReleaseDistance, shippedReleaseVersions } from './view/hosted-release.js';
/** The CLI's default phrases, ordered by depth for the existing prose inventory guard. */
export const PULLBOARD_COMMANDS = Object.freeze(commandPhrases().sort((left, right) => right.split(' ').length - left.split(' ').length));
-let hostedReleaseVersions;
-/** Return every shipped numeric release heading through the package version, including releases without headlines. */
-/**
- * @param {string} changelog - Shipped changelog contents.
- * @param {string} [currentVersion] - Highest package release to include.
- * @returns {string[]} Numeric release versions in ascending order, without duplicates.
- */
-export function releaseVersionsThrough(changelog, currentVersion = VERSION) {
- const numeric = (version) => version.split('.').map(Number);
- const compare = (left, right) => {
- const a = numeric(left), b = numeric(right);
- for (let index = 0; index < Math.max(a.length, b.length); index++) {
- const difference = (a[index] ?? 0) - (b[index] ?? 0);
- if (difference) return difference;
- }
- return 0;
- };
- return [...new Set([...changelog.matchAll(/^## \[(\d+\.\d+\.\d+)\](?:\s|$)/gmu)].map((match) => match[1]))]
- .filter((version) => compare(version, currentVersion) <= 0)
- .sort(compare);
-}
-
-/** Read and cache the shipped release ledger only when a hosted page needs its current version. */
-function shippedHostedReleaseVersions() {
- if (!hostedReleaseVersions) {
- const changelog = readFileSync(new URL('../CHANGELOG.md', import.meta.url), 'utf8');
- hostedReleaseVersions = Object.freeze(releaseVersionsThrough(changelog));
- }
- return hostedReleaseVersions;
-}
-
/**
* The item lifecycle as the page draws it (M1): each state with what it means and, for a final
* state, what every way in checks; each move with who makes it, its command or the clock's
@@ -92,7 +61,7 @@ export function cockpitPage(key = '', { snapshot = false, readOnly = false, requ
const requestMode = Boolean(readOnly && requests && !snapshot && transportModule);
if (signIn !== null && (typeof signIn !== 'string' || !signIn.startsWith('/') || signIn.startsWith('//'))) throw new TypeError('signIn must be a path on the hosting site, or null');
const hostedOptions = JSON.stringify({ local: Boolean(hostedLocal) && !snapshot, relaySession: Boolean(relaySession), signIn }).replace(/</g, '\\u003c');
- const releaseVersions = suppliedReleaseVersions ?? (hostedLocal && !snapshot ? shippedHostedReleaseVersions() : []);
+ const releaseVersions = suppliedReleaseVersions ?? (hostedLocal && !snapshot ? shippedReleaseVersions() : []);
const releaseInfo = JSON.stringify({ version: hostedReleaseVersion, versions: releaseVersions }).replace(/</g, '\\u003c');
const css = stylesheet ?? (snapshot ? 'view.css' : transportModule ? '/view.css' : '/view.css?k=' + encodeURIComponent(key));
const cssAttribute = css.replace(/[&<>"']/g, (character) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[character]);
@@ -249,6 +218,7 @@ let localReadHeaders = { ...connection.headers };
// anything else reads the address, and keeps it for this tab only. Every request then sends it in x-pullboard-key.
const hosted = ${hostedOptions};
const hostedRelease = ${releaseInfo};
+const hostedReleaseDistance = (${hostedReleaseDistance.toString()});
const LOCAL_VIEW = 'http://127.0.0.1:4890';
const LOCAL_TAB = 'pullboard.local.session';
const LOCAL_TRIPS = 'pullboard.local.trips';
@@ -353,13 +323,6 @@ function localNote(text, ways = false) {
if (hosted.signIn) $('local-note-sign-in').href = hosted.signIn;
}
-/** Count known, shipped release entries between the installed and hosted versions; unknown versions get no guessed count. */
-function hostedReleaseDistance(installed, current, releases) {
- if (typeof installed !== 'string' || typeof current !== 'string' || !Array.isArray(releases)) return 0;
- const installedAt = releases.indexOf(installed), currentAt = releases.indexOf(current);
- return installedAt >= 0 && currentAt > installedAt ? currentAt - installedAt : 0;
-}
-
/** Show one dismissable update line only after this hosted page has read a known older local release. */
function renderHostedReleaseNote(project) {
const region = $('hosted-release-note');
diff --git a/src/view/hosted-release.js b/src/view/hosted-release.js
new file mode 100644
index 00000000..9f743124
--- /dev/null
+++ b/src/view/hosted-release.js
@@ -0,0 +1,65 @@
+/**
+ * The hosted page's release facts for its update note (N26): which releases have shipped, and
+ * how far a local install trails the release the page was built from. Kept out of src/cockpit.js
+ * so the page module stays under its line cap; the page embeds hostedReleaseDistance as source.
+ */
+import { readFileSync } from 'node:fs';
+import { VERSION } from '../help.js';
+
+let shipped;
+
+/**
+ * Compare two dotted numeric versions.
+ *
+ * @param {string} left
+ * @param {string} right
+ * @returns {number} Negative, zero or positive, as for Array.prototype.sort.
+ */
+function compareVersions(left, right) {
+ const a = left.split('.').map(Number), b = right.split('.').map(Number);
+ for (let index = 0; index < Math.max(a.length, b.length); index++) {
+ const difference = (a[index] ?? 0) - (b[index] ?? 0);
+ if (difference) return difference;
+ }
+ return 0;
+}
+
+/**
+ * Return every shipped numeric release heading through the package version, including releases
+ * without headlines, so a count of releases behind matches the changelog a person reads.
+ *
+ * @param {string} changelog - Shipped changelog contents.
+ * @param {string} [currentVersion] - Highest package release to include.
+ * @returns {string[]} Numeric release versions in ascending order, without duplicates.
+ */
+export function releaseVersionsThrough(changelog, currentVersion = VERSION) {
+ return [...new Set([...changelog.matchAll(/^## \[(\d+\.\d+\.\d+)\](?:\s|$)/gmu)].map((match) => match[1]))]
+ .filter((version) => compareVersions(version, currentVersion) <= 0)
+ .sort(compareVersions);
+}
+
+/**
+ * Read and cache the shipped release ledger. Why read the packaged CHANGELOG: the hosted page's
+ * current release is the one it was built from, so nothing is fetched to learn it.
+ *
+ * @returns {readonly string[]}
+ */
+export function shippedReleaseVersions() {
+ if (!shipped) shipped = Object.freeze(releaseVersionsThrough(readFileSync(new URL('../../CHANGELOG.md', import.meta.url), 'utf8')));
+ return shipped;
+}
+
+/**
+ * Count known, shipped release entries between the installed and hosted versions. An unknown
+ * version gets 0, so the page shows no guessed count. Runs in the page as embedded source.
+ *
+ * @param {unknown} installed
+ * @param {unknown} current
+ * @param {unknown} releases
+ * @returns {number}
+ */
+export function hostedReleaseDistance(installed, current, releases) {
+ if (typeof installed !== 'string' || typeof current !== 'string' || !Array.isArray(releases)) return 0;
+ const installedAt = releases.indexOf(installed), currentAt = releases.indexOf(current);
+ return installedAt >= 0 && currentAt > installedAt ? currentAt - installedAt : 0;
+}