mirror of
https://github.com/bitbaum/fleet.git
synced 2026-12-04 05:47:47 +01:00
* docs(experience): the experience belongs to the package, measured and enforced The owner, 2026-11-06: every product installs the shared packages and the screens people touch are still built per app — a text box with no microphone, a header that is not ours, a comment list that works its own way. For a user that is the same as no package at all. A non-technical person who says "make me a website" must get the standard out of the door. - AGENTS.md: "The experience belongs to the package". Packages ship behaviour and the layout skeleton; apps own words, backend and brand (tokens). Extending the package is the work, not a detour. A file that must be the exception says why on its first line. - SHARED.md: "The experience standard" — what a person gets, from which package, measured per repo on 2026-11-06, how it is enforced. - templates/agent-rules.md: one bullet, so the rule reaches every repo's AGENTS.md by the existing sync PRs and no future session can miss it. - scripts/ci/experience-audit.mjs (+ tests): counts bare text areas, local chrome, composers, comment lists and article editors. package-composition runs it; a product whose package-plan.json sets experience.ceiling may not exceed it. The app template ships an empty ceiling, so a new product starts at zero. - docs/experience-standard-plan.md: the living plan, status table and how to resume, for whoever picks this up next. - shared-inventory.sh: its comment said UI markup was excluded so apps keep their own look; it now says behaviour is measured by the new audit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvpWNTLxXNfwUHS7MD * docs(agents): regenerate the template rule blocks from templates/agent-rules.md The audit job compares the three template AGENTS.md copies with the shipped block; they had not been regenerated after the experience bullet was added. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvpWNTLxXNfwUHS7MD --------- Co-authored-by: Claude <noreply@anthropic.com>
178 lines
6.8 KiB
JavaScript
178 lines
6.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Does this product ship the fleet's experience, or its own version of it?
|
|
*
|
|
* node scripts/ci/experience-audit.mjs --dir <repo> [--list] [--init]
|
|
*
|
|
* The owner's finding (2026-11-06): the packages are installed everywhere and
|
|
* the screens people touch are still built per app. A text box with no
|
|
* microphone, a header that is not the fleet's header, a comment list that
|
|
* works its own way: for a user that is the same as having no package at all.
|
|
* AGENTS.md "The experience belongs to the package" is the rule; this is the
|
|
* measurement.
|
|
*
|
|
* It counts five kinds of file, in the product's own source, that stand where
|
|
* a package already owns the behaviour:
|
|
*
|
|
* bareTextareas a <textarea>/<Textarea> in a file that imports neither
|
|
* chatkit (mic, 16px, keyboard) nor writingkit
|
|
* localChrome a Header / Navbar / TabBar / Sidebar / Footer file that
|
|
* does not import sitekit
|
|
* localComposers a Composer / ChatInput / CommentBox file that is not
|
|
* chatkit's
|
|
* localComments a Comment(s) list/thread/section file that does not
|
|
* import chatkit
|
|
* localArticleEditors an Article/Post/Blog Composer/Editor/Form file that
|
|
* does not import writingkit
|
|
*
|
|
* What it does with the counts is the product's choice, in package-plan.json:
|
|
*
|
|
* "experience": { "ceiling": { "bareTextareas": 48, "localChrome": 12 } }
|
|
*
|
|
* A kind missing from the ceiling means zero. With a ceiling, a count above it
|
|
* fails (the ratchet: it may fall, it may hold, it may not rise). Without an
|
|
* `experience` key the audit only reports, so existing products are not
|
|
* broken by a rule they have not yet been given a baseline for; the app
|
|
* template ships `"ceiling": {}`, so a NEW product starts at zero.
|
|
*
|
|
* A file can say why it is the exception, on its own: a first-line comment
|
|
* `// experience-exempt: <reason of at least 20 characters>` removes it from
|
|
* the count. The reason is the review.
|
|
*
|
|
* It reads source text only. It cannot tell a name field from prose, which is
|
|
* why it counts <textarea> (long text) and leaves single-line inputs alone.
|
|
*/
|
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
import { basename, join, relative, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
export const KINDS = [
|
|
'bareTextareas',
|
|
'localChrome',
|
|
'localComposers',
|
|
'localComments',
|
|
'localArticleEditors',
|
|
];
|
|
|
|
const SKIP_DIRS = new Set([
|
|
'node_modules',
|
|
'.next',
|
|
'.git',
|
|
'.claude',
|
|
'dist',
|
|
'build',
|
|
'coverage',
|
|
'__tests__',
|
|
'tests',
|
|
'test',
|
|
'e2e',
|
|
'.turbo',
|
|
'storybook-static',
|
|
]);
|
|
const SOURCE = /\.(tsx|jsx)$/;
|
|
const TEST_FILE = /\.(test|spec|stories)\.(tsx|jsx)$/;
|
|
|
|
const CHROME = /^(Header|SiteHeader|Navbar|NavBar|Navigation|MainNav|MobileNav|BottomNav|TabBar|Sidebar|Footer|SiteFooter)\.(tsx|jsx)$/;
|
|
const COMPOSER = /^(Composer|ChatInput|MessageInput|CommentBox|CommentComposer|ReplyComposer)\.(tsx|jsx)$/;
|
|
const COMMENTS = /^Comments?(Section|List|Thread|Item)?\.(tsx|jsx)$/;
|
|
const ARTICLE_EDITOR = /^(Article|Post|Blog)(Composer|Editor|Form)\.(tsx|jsx)$/;
|
|
|
|
const imports = (source, pkg) =>
|
|
new RegExp(`(?:from\\s*|import\\s*)['"]${pkg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:/[^'"]*)?['"]`).test(source);
|
|
|
|
const EXEMPT = /^\s*(?:\/\/|\/\*)\s*experience-exempt:\s*(\S.{19,})/;
|
|
|
|
/** Walk a repo's source files, skipping build output and tests. */
|
|
function* walk(dir, root = dir) {
|
|
for (const name of readdirSync(dir)) {
|
|
if (SKIP_DIRS.has(name)) continue;
|
|
const full = join(dir, name);
|
|
let stat;
|
|
try {
|
|
stat = statSync(full);
|
|
} catch {
|
|
continue;
|
|
}
|
|
if (stat.isDirectory()) yield* walk(full, root);
|
|
else if (SOURCE.test(name) && !TEST_FILE.test(name)) yield relative(root, full);
|
|
}
|
|
}
|
|
|
|
/** What this file counts as, if anything. Pure on (path, source). */
|
|
export function classify(path, source) {
|
|
const name = basename(path);
|
|
const firstLines = source.split('\n', 3).join('\n');
|
|
if (EXEMPT.test(firstLines.replace(/^\s*['"]use (client|server)['"];?\s*\n/, ''))) return [];
|
|
const kinds = [];
|
|
const chatkit = imports(source, '@bitbaum/chatkit');
|
|
const sitekit = imports(source, '@bitbaum/sitekit');
|
|
const writingkit = imports(source, '@bitbaum/writingkit');
|
|
if (/<(textarea|Textarea)\b/.test(source) && !chatkit && !writingkit) kinds.push('bareTextareas');
|
|
if (CHROME.test(name) && !sitekit) kinds.push('localChrome');
|
|
if (COMPOSER.test(name) && !chatkit) kinds.push('localComposers');
|
|
if (COMMENTS.test(name) && !chatkit) kinds.push('localComments');
|
|
if (ARTICLE_EDITOR.test(name) && !writingkit) kinds.push('localArticleEditors');
|
|
return kinds;
|
|
}
|
|
|
|
/** { counts, files } for a repo directory. */
|
|
export function measure(dir) {
|
|
const counts = Object.fromEntries(KINDS.map((k) => [k, 0]));
|
|
const files = Object.fromEntries(KINDS.map((k) => [k, []]));
|
|
for (const path of walk(dir)) {
|
|
let source;
|
|
try {
|
|
source = readFileSync(join(dir, path), 'utf8');
|
|
} catch {
|
|
continue;
|
|
}
|
|
for (const kind of classify(path, source)) {
|
|
counts[kind] += 1;
|
|
files[kind].push(path);
|
|
}
|
|
}
|
|
return { counts, files };
|
|
}
|
|
|
|
/** Findings against a ceiling; empty when there is none to hold the count to. */
|
|
export function overCeiling(counts, plan) {
|
|
const ceiling = plan?.experience?.ceiling;
|
|
if (!ceiling || typeof ceiling !== 'object') return [];
|
|
return KINDS.filter((k) => counts[k] > (Number.isInteger(ceiling[k]) ? ceiling[k] : 0)).map(
|
|
(k) =>
|
|
`${k}: ${counts[k]} above the ceiling of ${Number.isInteger(ceiling[k]) ? ceiling[k] : 0} — use the package's component (see AGENTS.md "The experience belongs to the package"), or lower the count; do not raise the ceiling.`,
|
|
);
|
|
}
|
|
|
|
export function readPlan(dir) {
|
|
const file = resolve(dir, 'package-plan.json');
|
|
if (!existsSync(file)) return null;
|
|
try {
|
|
return JSON.parse(readFileSync(file, 'utf8'));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function main(argv) {
|
|
const at = argv.indexOf('--dir');
|
|
const dir = resolve(at >= 0 ? argv[at + 1] : '.');
|
|
const { counts, files } = measure(dir);
|
|
const plan = readPlan(dir);
|
|
const findings = overCeiling(counts, plan);
|
|
const hasCeiling = !!plan?.experience?.ceiling;
|
|
console.log(
|
|
'experience: ' + KINDS.map((k) => `${k}=${counts[k]}`).join(' ') + (hasCeiling ? '' : ' (no ceiling set: report only)'),
|
|
);
|
|
if (argv.includes('--list')) {
|
|
for (const k of KINDS) for (const f of files[k]) console.log(` ${k} ${f}`);
|
|
}
|
|
if (argv.includes('--init')) {
|
|
console.log(JSON.stringify({ experience: { ceiling: counts } }, null, 2));
|
|
}
|
|
for (const finding of findings) console.error(finding);
|
|
if (findings.length) process.exitCode = 1;
|
|
}
|
|
|
|
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main(process.argv.slice(2));
|