@marktiderman/genesis-config 0.0.0-stage → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +461 -2
- package/dist/blocks.d.ts +473 -0
- package/dist/blocks.js +5 -0
- package/dist/blocks.js.map +1 -0
- package/dist/chunk-B6WRD3WF.js +6 -0
- package/dist/chunk-B6WRD3WF.js.map +1 -0
- package/dist/chunk-HIOKZIZP.js +218 -0
- package/dist/chunk-HIOKZIZP.js.map +1 -0
- package/dist/chunk-M7IY6LUN.js +123 -0
- package/dist/chunk-M7IY6LUN.js.map +1 -0
- package/dist/chunk-OW46SL2G.js +10 -0
- package/dist/chunk-OW46SL2G.js.map +1 -0
- package/dist/chunk-SEFG2QV6.js +413 -0
- package/dist/chunk-SEFG2QV6.js.map +1 -0
- package/dist/chunk-UD7SPYZH.js +354 -0
- package/dist/chunk-UD7SPYZH.js.map +1 -0
- package/dist/chunk-VYUX7VAX.js +52 -0
- package/dist/chunk-VYUX7VAX.js.map +1 -0
- package/dist/chunk-Y7NUBTWA.js +494 -0
- package/dist/chunk-Y7NUBTWA.js.map +1 -0
- package/dist/gate-CNTkn-Fv.d.ts +202 -0
- package/dist/gate-react.d.ts +48 -0
- package/dist/gate-react.js +37 -0
- package/dist/gate-react.js.map +1 -0
- package/dist/gate.d.ts +18 -0
- package/dist/gate.js +5 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +128 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/model-uON71G4u.d.ts +437 -0
- package/dist/node.d.ts +159 -0
- package/dist/node.js +486 -0
- package/dist/node.js.map +1 -0
- package/dist/packages-CWhdXtzS.d.ts +203 -0
- package/dist/platforms-NR0liM8L.d.ts +10 -0
- package/dist/react.d.ts +60 -0
- package/dist/react.js +236 -0
- package/dist/react.js.map +1 -0
- package/dist/settings-protocol.d.ts +515 -0
- package/dist/settings-protocol.js +4 -0
- package/dist/settings-protocol.js.map +1 -0
- package/dist/settings-react.d.ts +143 -0
- package/dist/settings-react.js +943 -0
- package/dist/settings-react.js.map +1 -0
- package/dist/settings.d.ts +373 -0
- package/dist/settings.js +3 -0
- package/dist/settings.js.map +1 -0
- package/dist/types-D4hs16bJ.d.ts +39 -0
- package/package.json +141 -4
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { F as Features, a as Flags } from './model-uON71G4u.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
import './platforms-NR0liM8L.js';
|
|
4
|
+
import './types-D4hs16bJ.js';
|
|
5
|
+
import './packages-CWhdXtzS.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Where a repo keeps its registry's outputs and what `check` scans. Every
|
|
9
|
+
* path is relative to `root`; `false` turns an output or a scan off. The CLI
|
|
10
|
+
* reads these from genesis.config.json → `features` (or package.json → `"genesisFeatures"`), and its options win.
|
|
11
|
+
*
|
|
12
|
+
* @stability Beta
|
|
13
|
+
*/
|
|
14
|
+
interface FeatureProjectOptions {
|
|
15
|
+
/** The repository root. */
|
|
16
|
+
root: string;
|
|
17
|
+
features: Features;
|
|
18
|
+
flags?: Flags;
|
|
19
|
+
/** The registry file, named in generated output. Default `src/features.ts`. */
|
|
20
|
+
source?: string;
|
|
21
|
+
/** How people run the CLI here, named in generated output. Default `genesis features`. */
|
|
22
|
+
command?: string;
|
|
23
|
+
/** The AGENTS.md that holds the pointer block. Default `AGENTS.md`. */
|
|
24
|
+
agents?: string | false;
|
|
25
|
+
/** The CLAUDE.md that must import AGENTS.md (`@AGENTS.md`). Default `CLAUDE.md`. */
|
|
26
|
+
claude?: string | false;
|
|
27
|
+
/** The JSON copy, which is also the record of every id ever used. Default `features.json`. */
|
|
28
|
+
json?: string | false;
|
|
29
|
+
/** The OpenFeature flag manifest, written when there are flags. Default `flags.json`. */
|
|
30
|
+
openfeature?: string | false;
|
|
31
|
+
/** The agent skill. Default `.claude/skills/features/SKILL.md`. */
|
|
32
|
+
skill?: string | false;
|
|
33
|
+
/** A file to keep the marketing block in (e.g. README.md). Default none. */
|
|
34
|
+
marketing?: string | false;
|
|
35
|
+
/** The marketing block's heading. Default `Features`. */
|
|
36
|
+
marketingHeading?: string;
|
|
37
|
+
/**
|
|
38
|
+
* How code reads a flag: a function name (`useFlag`, read as its first
|
|
39
|
+
* argument) or a JSX attribute (`<Flag name>`). Default `useFlag`, `getFlag`
|
|
40
|
+
* and `<Flag name>`.
|
|
41
|
+
*/
|
|
42
|
+
flagAccessors?: readonly string[];
|
|
43
|
+
/** Code scanned for flag reads. Default `src`, `app` and `packages/*\/src`. */
|
|
44
|
+
scan?: readonly string[] | false;
|
|
45
|
+
/**
|
|
46
|
+
* Files the flag scan skips: the flags runtime that defines the accessors and
|
|
47
|
+
* reads by variable, and tests, which build keys on purpose. Default the test
|
|
48
|
+
* globs (`tests`).
|
|
49
|
+
*/
|
|
50
|
+
scanIgnore?: readonly string[];
|
|
51
|
+
/** Test files scanned for `@feat:<id>` tags. */
|
|
52
|
+
tests?: readonly string[] | false;
|
|
53
|
+
/** The changesets folder, scanned for `Features: <id>` lines. Default `.changeset`. */
|
|
54
|
+
changesets?: string | false;
|
|
55
|
+
/** The PR's labels, checked for `feature:<id>`. */
|
|
56
|
+
labels?: readonly string[];
|
|
57
|
+
/** Route and server-function files every one of which some `links.code` should cover. */
|
|
58
|
+
coverage?: readonly string[] | false;
|
|
59
|
+
coverageIgnore?: readonly string[];
|
|
60
|
+
/** Warn when `reviewedAt` is older than this many days. Default 90. */
|
|
61
|
+
reviewDays?: number;
|
|
62
|
+
/** `YYYY-MM-DD`. Default today (UTC). */
|
|
63
|
+
today?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Shipped work gathered elsewhere (the CLI's `--prs` reads it with `gh`).
|
|
66
|
+
* A planned feature with any of it gets a warning, as do changesets that
|
|
67
|
+
* name it.
|
|
68
|
+
*/
|
|
69
|
+
evidence?: FeatureEvidence;
|
|
70
|
+
}
|
|
71
|
+
/** A merged PR labelled `feature:<id>`. @stability Beta */
|
|
72
|
+
interface FeaturePrEvidence {
|
|
73
|
+
number: number;
|
|
74
|
+
title: string;
|
|
75
|
+
}
|
|
76
|
+
/** @stability Beta */
|
|
77
|
+
interface FeatureEvidence {
|
|
78
|
+
/** Merged PRs by the feature id (or alias) on their `feature:<id>` label. */
|
|
79
|
+
prs?: Record<string, readonly FeaturePrEvidence[]>;
|
|
80
|
+
}
|
|
81
|
+
/** A feature still marked planned (or an idea) that already has shipped work tagged with it. @stability Beta */
|
|
82
|
+
interface PlannedButShipped {
|
|
83
|
+
id: string;
|
|
84
|
+
/** Changeset files with a `Features: <id>` line. */
|
|
85
|
+
changesets: string[];
|
|
86
|
+
prs: FeaturePrEvidence[];
|
|
87
|
+
}
|
|
88
|
+
/** @stability Beta */
|
|
89
|
+
interface FeatureCheckResult {
|
|
90
|
+
ok: boolean;
|
|
91
|
+
/** Hard failures: stale generated output, missing code paths, flag rules, removed ids, bad tags, no `@AGENTS.md`. */
|
|
92
|
+
errors: string[];
|
|
93
|
+
/** Everything else: reviews due, untested live features, uncovered routes, missing docs. */
|
|
94
|
+
warnings: string[];
|
|
95
|
+
/** Generated files that differ from what the generator makes now. */
|
|
96
|
+
stale: string[];
|
|
97
|
+
expiredFlags: string[];
|
|
98
|
+
/** Building features with someone on them: `[id, claimedBy]`. */
|
|
99
|
+
claims: [string, string][];
|
|
100
|
+
/** Planned features with shipped work; each is also a warning. */
|
|
101
|
+
plannedButShipped: PlannedButShipped[];
|
|
102
|
+
}
|
|
103
|
+
/** A glob (`*`, `**`, `?`, `{a,b}`) as a RegExp over `/`-separated relative paths. */
|
|
104
|
+
declare function globToRegExp(glob: string): RegExp;
|
|
105
|
+
/**
|
|
106
|
+
* `text` with its comments blanked to spaces (newlines kept), so a flag named
|
|
107
|
+
* in a comment isn't read as a flag read and line numbers stay right. Strings,
|
|
108
|
+
* regex literals and template text are left alone; a template's `${…}` is code.
|
|
109
|
+
* With `strings`, string and template-text contents are blanked too (quotes
|
|
110
|
+
* stay), so prose in a string ("…the release flag (off)") can't look like a call.
|
|
111
|
+
*/
|
|
112
|
+
declare function blankComments(text: string, strings?: boolean): string;
|
|
113
|
+
/**
|
|
114
|
+
* Flag reads in `text`: each key read through an accessor with a literal, and
|
|
115
|
+
* each read whose key isn't a literal (`dynamic`), as `path:line`. Comments
|
|
116
|
+
* don't count.
|
|
117
|
+
*/
|
|
118
|
+
declare function scanFlagReads(path: string, source: string, accessors?: readonly string[]): {
|
|
119
|
+
keys: {
|
|
120
|
+
key: string;
|
|
121
|
+
where: string;
|
|
122
|
+
}[];
|
|
123
|
+
dynamic: string[];
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Writes every generated output (the AGENTS.md block, the JSON, the flag
|
|
127
|
+
* manifest, the skill, the marketing block) and adds `@AGENTS.md` to
|
|
128
|
+
* CLAUDE.md when it's missing. Refuses, writing nothing, when an id recorded
|
|
129
|
+
* in the JSON has disappeared, or the JSON can't be read (each side of a merge
|
|
130
|
+
* conflict is read). Returns the paths it changed.
|
|
131
|
+
*
|
|
132
|
+
* @stability Beta
|
|
133
|
+
*/
|
|
134
|
+
declare function buildFeatureOutputs(options: FeatureProjectOptions): string[];
|
|
135
|
+
/**
|
|
136
|
+
* Checks the registry against the repo. Errors (exit 1): generated output that
|
|
137
|
+
* is stale, `links.code` paths that don't exist, the flag rules (a permission
|
|
138
|
+
* flag, an expired flag, a dynamic key, a key read but not defined or defined
|
|
139
|
+
* but never read, a missing runbook), an id that disappeared, an unknown id in
|
|
140
|
+
* a test, changeset or PR tag, and a CLAUDE.md without `@AGENTS.md`.
|
|
141
|
+
* Warnings: reviews due, live features without tagged tests, planned features
|
|
142
|
+
* with shipped work (changesets, and `evidence.prs`), route and
|
|
143
|
+
* server-function files no feature covers, missing docs.
|
|
144
|
+
*
|
|
145
|
+
* It only ever compares generated output with the generator, never two
|
|
146
|
+
* hand-written files.
|
|
147
|
+
*
|
|
148
|
+
* @stability Beta
|
|
149
|
+
*/
|
|
150
|
+
declare function checkFeatureOutputs(options: FeatureProjectOptions): FeatureCheckResult;
|
|
151
|
+
/**
|
|
152
|
+
* A few lines for a session's start: counts, stale output, expired flags,
|
|
153
|
+
* planned features with shipped work and open claims. Meant for a SessionStart hook (`genesis features check --summary`).
|
|
154
|
+
*
|
|
155
|
+
* @stability Beta
|
|
156
|
+
*/
|
|
157
|
+
declare function summarizeCheck(result: FeatureCheckResult, features: Features): string;
|
|
158
|
+
|
|
159
|
+
export { type FeatureCheckResult, type FeatureEvidence, type FeaturePrEvidence, type FeatureProjectOptions, type PlannedButShipped, blankComments, buildFeatureOutputs, checkFeatureOutputs, globToRegExp, scanFlagReads, summarizeCheck };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { BrokenBlockError, expiredFlags, toAgentsMarkdown, readAgentsBlock, replaceAgentsBlock, toJson, toOpenFeatureManifest, toSkillMarkdown, toMarketingMarkdown, readBlock, MARKETING_BLOCK_START, MARKETING_BLOCK_END, replaceBlock } from './chunk-SEFG2QV6.js';
|
|
2
|
+
import './chunk-VYUX7VAX.js';
|
|
3
|
+
import './chunk-B6WRD3WF.js';
|
|
4
|
+
import './chunk-OW46SL2G.js';
|
|
5
|
+
import { existsSync, readFileSync, readdirSync, mkdirSync, writeFileSync } from 'fs';
|
|
6
|
+
import { join, dirname } from 'path';
|
|
7
|
+
|
|
8
|
+
var CODE = "{ts,tsx,js,jsx,mjs,cjs}";
|
|
9
|
+
var DEFAULT_SCAN = [`src/**/*.${CODE}`, `app/**/*.${CODE}`, `packages/*/src/**/*.${CODE}`];
|
|
10
|
+
var DEFAULT_TESTS = [`**/*.{test,spec}.${CODE}`, "**/__tests__/**/*", "supabase/tests/**/*.sql"];
|
|
11
|
+
var DEFAULT_COVERAGE = [`src/routes/**/*.${CODE}`, `app/routes/**/*.${CODE}`, "**/*.functions.ts"];
|
|
12
|
+
var DEFAULT_COVERAGE_IGNORE = ["**/routeTree.gen.ts", "**/__root.tsx", "**/*.d.ts"];
|
|
13
|
+
var DEFAULT_ACCESSORS = ["useFlag", "getFlag", "<Flag name>"];
|
|
14
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "coverage", "out", "storybook-static"]);
|
|
15
|
+
function read(file) {
|
|
16
|
+
return existsSync(file) ? readFileSync(file, "utf8").replace(/\r\n/g, "\n") : null;
|
|
17
|
+
}
|
|
18
|
+
function globToRegExp(glob) {
|
|
19
|
+
let out = "";
|
|
20
|
+
for (let i = 0; i < glob.length; i++) {
|
|
21
|
+
const c = glob[i];
|
|
22
|
+
if (c === "*" && glob[i + 1] === "*") {
|
|
23
|
+
const slash = glob[i + 2] === "/";
|
|
24
|
+
out += slash ? "(?:.*/)?" : ".*";
|
|
25
|
+
i += slash ? 2 : 1;
|
|
26
|
+
} else if (c === "*") out += "[^/]*";
|
|
27
|
+
else if (c === "?") out += "[^/]";
|
|
28
|
+
else if (c === "{") {
|
|
29
|
+
const close = glob.indexOf("}", i);
|
|
30
|
+
out += `(?:${glob.slice(i + 1, close).split(",").map((s) => s.replace(/[.+^$()|[\]\\]/g, "\\$&")).join("|")})`;
|
|
31
|
+
i = close;
|
|
32
|
+
} else out += c.replace(/[.+^$()|[\]\\]/g, "\\$&");
|
|
33
|
+
}
|
|
34
|
+
return new RegExp(`^${out}$`);
|
|
35
|
+
}
|
|
36
|
+
function listFiles(root) {
|
|
37
|
+
const out = [];
|
|
38
|
+
const walk = (rel) => {
|
|
39
|
+
let entries;
|
|
40
|
+
try {
|
|
41
|
+
entries = readdirSync(join(root, rel), { withFileTypes: true });
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const path = rel ? `${rel}/${entry.name}` : entry.name;
|
|
47
|
+
if (entry.isDirectory()) {
|
|
48
|
+
if (!entry.name.startsWith(".") && !SKIP_DIRS.has(entry.name)) walk(path);
|
|
49
|
+
} else if (entry.isFile()) out.push(path);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
walk("");
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
function matcher(globs) {
|
|
56
|
+
const res = globs.map(globToRegExp);
|
|
57
|
+
return (path) => res.some((re) => re.test(path));
|
|
58
|
+
}
|
|
59
|
+
var at = (path, text, index) => `${path}:${text.slice(0, index).split("\n").length}`;
|
|
60
|
+
function literalAt(text, i) {
|
|
61
|
+
const quote = text[i];
|
|
62
|
+
if (quote !== '"' && quote !== "'" && quote !== "`") return null;
|
|
63
|
+
const end = text.indexOf(quote, i + 1);
|
|
64
|
+
if (end === -1) return null;
|
|
65
|
+
const value = text.slice(i + 1, end);
|
|
66
|
+
if (quote === "`" && value.includes("${")) return null;
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
function blankComments(text, strings = false) {
|
|
70
|
+
return blankFrom(text, 0, false, strings).out;
|
|
71
|
+
}
|
|
72
|
+
var BEFORE_REGEX = new Set("(,=:[!&|?{};+-*%<>~^");
|
|
73
|
+
var REGEX_KEYWORDS = /(?:^|[^\w$.])(?:return|typeof|instanceof|in|new|delete|void|throw|case|do|else|yield|await)$/;
|
|
74
|
+
function blankFrom(text, i, inTemplate, strings = false) {
|
|
75
|
+
const keep = (chunk) => strings ? chunk.replace(/[^\n]/g, " ") : chunk;
|
|
76
|
+
let out = "";
|
|
77
|
+
let depth = 0;
|
|
78
|
+
while (i < text.length) {
|
|
79
|
+
const c = text[i];
|
|
80
|
+
const next = text[i + 1];
|
|
81
|
+
if (inTemplate && c === "}" && depth === 0) return { out, end: i };
|
|
82
|
+
if (c === "{") depth++;
|
|
83
|
+
else if (c === "}") depth--;
|
|
84
|
+
if (c === "/" && next === "/") {
|
|
85
|
+
const end = text.indexOf("\n", i);
|
|
86
|
+
const stop = end === -1 ? text.length : end;
|
|
87
|
+
out += " ".repeat(stop - i);
|
|
88
|
+
i = stop;
|
|
89
|
+
} else if (c === "/" && next === "*") {
|
|
90
|
+
const end = text.indexOf("*/", i + 2);
|
|
91
|
+
const stop = end === -1 ? text.length : end + 2;
|
|
92
|
+
out += text.slice(i, stop).replace(/[^\n]/g, " ");
|
|
93
|
+
i = stop;
|
|
94
|
+
} else if (c === "/" && next !== ">" && startsRegex(out)) {
|
|
95
|
+
let j = i + 1;
|
|
96
|
+
let inClass = false;
|
|
97
|
+
while (j < text.length && text[j] !== "\n") {
|
|
98
|
+
const r = text[j];
|
|
99
|
+
if (r === "\\") j += 2;
|
|
100
|
+
else {
|
|
101
|
+
if (r === "[") inClass = true;
|
|
102
|
+
else if (r === "]") inClass = false;
|
|
103
|
+
else if (r === "/" && !inClass) break;
|
|
104
|
+
j++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (text[j] !== "/") {
|
|
108
|
+
out += c;
|
|
109
|
+
i++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
out += text.slice(i, j + 1);
|
|
113
|
+
i = j + 1;
|
|
114
|
+
} else if (c === "`") {
|
|
115
|
+
out += c;
|
|
116
|
+
let j = i + 1;
|
|
117
|
+
while (j < text.length && text[j] !== "`") {
|
|
118
|
+
if (text[j] === "\\") {
|
|
119
|
+
out += keep(text.slice(j, j + 2));
|
|
120
|
+
j += 2;
|
|
121
|
+
} else if (text[j] === "$" && text[j + 1] === "{") {
|
|
122
|
+
out += "${";
|
|
123
|
+
const inner = blankFrom(text, j + 2, true, strings);
|
|
124
|
+
out += inner.out;
|
|
125
|
+
j = inner.end;
|
|
126
|
+
if (j < text.length) out += text[j];
|
|
127
|
+
j++;
|
|
128
|
+
} else {
|
|
129
|
+
out += keep(text[j]);
|
|
130
|
+
j++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (j < text.length) out += "`";
|
|
134
|
+
i = j + 1;
|
|
135
|
+
} else if (c === '"' || c === "'") {
|
|
136
|
+
let j = i + 1;
|
|
137
|
+
while (j < text.length && text[j] !== c && text[j] !== "\n") j += text[j] === "\\" ? 2 : 1;
|
|
138
|
+
if (text[j] === c) {
|
|
139
|
+
out += c + keep(text.slice(i + 1, j)) + c;
|
|
140
|
+
i = j + 1;
|
|
141
|
+
} else {
|
|
142
|
+
out += c;
|
|
143
|
+
i++;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
out += c;
|
|
147
|
+
i++;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { out, end: i };
|
|
151
|
+
}
|
|
152
|
+
function startsRegex(before) {
|
|
153
|
+
const trimmed = before.replace(/\s+$/, "");
|
|
154
|
+
if (trimmed === "") return true;
|
|
155
|
+
if (before.endsWith("<")) return false;
|
|
156
|
+
return BEFORE_REGEX.has(trimmed[trimmed.length - 1]) || REGEX_KEYWORDS.test(trimmed);
|
|
157
|
+
}
|
|
158
|
+
function scanFlagReads(path, source, accessors = DEFAULT_ACCESSORS) {
|
|
159
|
+
const text = blankComments(source);
|
|
160
|
+
const code = blankComments(source, true);
|
|
161
|
+
const keys = [];
|
|
162
|
+
const dynamic = [];
|
|
163
|
+
for (const accessor of accessors) {
|
|
164
|
+
const jsx = /^<(\w[\w.]*)\s+(\w+)>$/.exec(accessor);
|
|
165
|
+
if (jsx) {
|
|
166
|
+
const re2 = new RegExp(`<${jsx[1].replace(/\./g, "\\.")}\\b[^>]*?\\b${jsx[2]}\\s*=\\s*`, "g");
|
|
167
|
+
for (const m of code.matchAll(re2)) {
|
|
168
|
+
let i = m.index + m[0].length;
|
|
169
|
+
if (text[i] === "{") i = text.slice(i + 1).search(/\S/) + i + 1;
|
|
170
|
+
const key = literalAt(text, i);
|
|
171
|
+
if (key === null) dynamic.push(at(path, text, m.index));
|
|
172
|
+
else keys.push({ key, where: at(path, text, m.index) });
|
|
173
|
+
}
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const re = new RegExp(`(?<![\\w$.])(function\\s+)?${accessor.replace(/\$/g, "\\$")}\\s*(?:<[^>()]*>)?\\s*\\(\\s*`, "g");
|
|
177
|
+
for (const m of code.matchAll(re)) {
|
|
178
|
+
if (m[1]) continue;
|
|
179
|
+
const i = m.index + m[0].length;
|
|
180
|
+
if (text[i] === ")") continue;
|
|
181
|
+
const key = literalAt(text, i);
|
|
182
|
+
if (key !== null) keys.push({ key, where: at(path, text, m.index) });
|
|
183
|
+
else if (!/^[\w$]+\??\s*:/.test(text.slice(i))) dynamic.push(at(path, text, m.index));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { keys, dynamic };
|
|
187
|
+
}
|
|
188
|
+
var ids = (features) => new Set(Object.entries(features).flatMap(([id, f]) => [id, ...f.aliases ?? []]));
|
|
189
|
+
function removedIds(options) {
|
|
190
|
+
const json = options.json === void 0 ? "features.json" : options.json;
|
|
191
|
+
if (!json) return [];
|
|
192
|
+
const doc = read(join(options.root, json));
|
|
193
|
+
if (doc === null) return [];
|
|
194
|
+
const sides = conflictSides(doc) ?? [{ side: "", text: doc }];
|
|
195
|
+
const previous = [];
|
|
196
|
+
for (const { side, text } of sides) {
|
|
197
|
+
const recorded = recordedIds(text);
|
|
198
|
+
if (!recorded) {
|
|
199
|
+
throw new Error(
|
|
200
|
+
`${json} can't be read as JSON${side ? ` on the ${side} side of its merge conflict` : ""}, so the check that feature ids are permanent can't run. Fix it, or restore it from git, and run again`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
previous.push(...recorded);
|
|
204
|
+
}
|
|
205
|
+
const now = ids(options.features);
|
|
206
|
+
return [...new Set(previous)].filter((id) => !now.has(id));
|
|
207
|
+
}
|
|
208
|
+
function recordedIds(doc) {
|
|
209
|
+
try {
|
|
210
|
+
return JSON.parse(doc.replace(/^\uFEFF/, "")).features?.flatMap((f) => [...f.status === "idea" || f.status === "planned" ? [] : [f.id], ...f.aliases ?? []]) ?? [];
|
|
211
|
+
} catch {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
var markers = {
|
|
216
|
+
ours: /^<{7}(?: .*)?\r?$/,
|
|
217
|
+
base: /^\|{7}(?: .*)?\r?$/,
|
|
218
|
+
theirs: /^={7}\r?$/,
|
|
219
|
+
end: /^>{7}(?: .*)?\r?$/
|
|
220
|
+
};
|
|
221
|
+
function conflictSides(doc) {
|
|
222
|
+
const ours = [];
|
|
223
|
+
const theirs = [];
|
|
224
|
+
let state = "both";
|
|
225
|
+
let conflicted = false;
|
|
226
|
+
for (const line of doc.split("\n")) {
|
|
227
|
+
if (state === "both" && markers.ours.test(line)) {
|
|
228
|
+
state = "ours";
|
|
229
|
+
conflicted = true;
|
|
230
|
+
} else if (state === "ours" && markers.base.test(line)) state = "base";
|
|
231
|
+
else if ((state === "ours" || state === "base") && markers.theirs.test(line)) state = "theirs";
|
|
232
|
+
else if (state === "theirs" && markers.end.test(line)) state = "both";
|
|
233
|
+
else {
|
|
234
|
+
if (state === "both" || state === "ours") ours.push(line);
|
|
235
|
+
if (state === "both" || state === "theirs") theirs.push(line);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!conflicted) return null;
|
|
239
|
+
return [
|
|
240
|
+
{ side: "ours", text: ours.join("\n") },
|
|
241
|
+
{ side: "theirs", text: theirs.join("\n") }
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
var canonical = (features) => new Map(Object.entries(features).flatMap(([id, f]) => [id, ...f.aliases ?? []].map((name) => [name, id])));
|
|
245
|
+
var and = (items) => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
246
|
+
var removedMessage = (id) => `the feature id "${id}" was removed. Ids are permanent once a feature is being built: keep the entry with status "retired", or list "${id}" in the new entry's aliases`;
|
|
247
|
+
function outputs(options) {
|
|
248
|
+
const { features, flags, source, command } = options;
|
|
249
|
+
const agents = options.agents === void 0 ? "AGENTS.md" : options.agents;
|
|
250
|
+
const json = options.json === void 0 ? "features.json" : options.json;
|
|
251
|
+
const openfeature = options.openfeature === void 0 ? "flags.json" : options.openfeature;
|
|
252
|
+
const skill = options.skill === void 0 ? ".claude/skills/features/SKILL.md" : options.skill;
|
|
253
|
+
const whole = (content) => ({ next: () => content, same: (current, next) => current === next });
|
|
254
|
+
const list = [];
|
|
255
|
+
if (agents) {
|
|
256
|
+
const block = toAgentsMarkdown(features, flags, { source, command, skill });
|
|
257
|
+
list.push({
|
|
258
|
+
path: agents,
|
|
259
|
+
next: (current) => replaceAgentsBlock(current ?? "", block),
|
|
260
|
+
same: (current) => current !== null && readAgentsBlock(current) === block
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (json) list.push({ path: json, ...whole(toJson(features, flags, { source })) });
|
|
264
|
+
if (openfeature && flags && Object.keys(flags).length) list.push({ path: openfeature, ...whole(toOpenFeatureManifest(flags, features)) });
|
|
265
|
+
const writesFlags = Boolean(openfeature && flags && Object.keys(flags).length);
|
|
266
|
+
const generated = [
|
|
267
|
+
...agents ? [`the ${agents} block`] : [],
|
|
268
|
+
...json ? [`\`${json}\``] : [],
|
|
269
|
+
...writesFlags ? [`\`${openfeature}\` (the OpenFeature flag manifest)`] : [],
|
|
270
|
+
...options.marketing ? [`the ${options.marketing} Features section`] : [],
|
|
271
|
+
...skill ? ["this skill"] : []
|
|
272
|
+
];
|
|
273
|
+
if (skill) list.push({ path: skill, ...whole(toSkillMarkdown({ source, command, outputs: generated })) });
|
|
274
|
+
if (options.marketing) {
|
|
275
|
+
const block = toMarketingMarkdown(features, { heading: options.marketingHeading, source });
|
|
276
|
+
list.push({
|
|
277
|
+
path: options.marketing,
|
|
278
|
+
next: (current) => replaceBlock(current ?? "", block, MARKETING_BLOCK_START, MARKETING_BLOCK_END),
|
|
279
|
+
same: (current) => current !== null && readBlock(current, MARKETING_BLOCK_START, MARKETING_BLOCK_END) === block
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return list;
|
|
283
|
+
}
|
|
284
|
+
function claudeImport(options) {
|
|
285
|
+
const agents = options.agents === void 0 ? "AGENTS.md" : options.agents;
|
|
286
|
+
const claude = options.claude === void 0 ? "CLAUDE.md" : options.claude;
|
|
287
|
+
return agents && claude ? { path: claude, line: `@${agents}` } : null;
|
|
288
|
+
}
|
|
289
|
+
var hasImport = (doc, line) => doc !== null && new RegExp(`^${line.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*$`, "m").test(doc);
|
|
290
|
+
function buildFeatureOutputs(options) {
|
|
291
|
+
const removed = removedIds(options);
|
|
292
|
+
if (removed.length) throw new Error(removed.map(removedMessage).join("\n"));
|
|
293
|
+
const changed = [];
|
|
294
|
+
const write = (rel, next) => {
|
|
295
|
+
const file = join(options.root, rel);
|
|
296
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
297
|
+
writeFileSync(file, next);
|
|
298
|
+
changed.push(rel);
|
|
299
|
+
};
|
|
300
|
+
for (const output of outputs(options)) {
|
|
301
|
+
const current = read(join(options.root, output.path));
|
|
302
|
+
let next;
|
|
303
|
+
try {
|
|
304
|
+
next = output.next(current);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (error instanceof BrokenBlockError) throw new Error(`${output.path}: ${error.message}`);
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
if (!output.same(current, next)) write(output.path, next);
|
|
310
|
+
}
|
|
311
|
+
const claude = claudeImport(options);
|
|
312
|
+
if (claude) {
|
|
313
|
+
const current = read(join(options.root, claude.path));
|
|
314
|
+
if (!hasImport(current, claude.line)) {
|
|
315
|
+
const base = current === null || current === "" ? "" : current.endsWith("\n") ? `${current}
|
|
316
|
+
` : `${current}
|
|
317
|
+
|
|
318
|
+
`;
|
|
319
|
+
write(claude.path, `${base}${claude.line}
|
|
320
|
+
`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return changed;
|
|
324
|
+
}
|
|
325
|
+
function checkFeatureOutputs(options) {
|
|
326
|
+
const { root, features, flags } = options;
|
|
327
|
+
const today = options.today ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
328
|
+
const errors = [];
|
|
329
|
+
const warnings = [];
|
|
330
|
+
const stale = [];
|
|
331
|
+
const known = ids(features);
|
|
332
|
+
for (const output of outputs(options)) {
|
|
333
|
+
const current = read(join(root, output.path));
|
|
334
|
+
let same;
|
|
335
|
+
try {
|
|
336
|
+
same = output.same(current, output.next(current));
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (!(error instanceof BrokenBlockError)) throw error;
|
|
339
|
+
errors.push(`${output.path}: ${error.message}`);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (!same) {
|
|
343
|
+
stale.push(output.path);
|
|
344
|
+
errors.push(`${output.path} is stale. Run \`${options.command ?? "genesis features"} build\` and commit the result.`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const claude = claudeImport(options);
|
|
348
|
+
if (claude && !hasImport(read(join(root, claude.path)), claude.line)) {
|
|
349
|
+
errors.push(`${claude.path} must import the agent notes with a line \`${claude.line}\` (\`build\` adds it).`);
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
for (const id of removedIds(options)) errors.push(removedMessage(id));
|
|
353
|
+
} catch (error) {
|
|
354
|
+
errors.push(error.message);
|
|
355
|
+
}
|
|
356
|
+
const reviewCutoff = new Date(Date.parse(today) - (options.reviewDays ?? 90) * 864e5).toISOString().slice(0, 10);
|
|
357
|
+
const claims = [];
|
|
358
|
+
for (const [id, def] of Object.entries(features)) {
|
|
359
|
+
for (const path of def.links?.code ?? []) {
|
|
360
|
+
if (!existsSync(join(root, path))) errors.push(`${id}.links.code: ${path} doesn't exist`);
|
|
361
|
+
}
|
|
362
|
+
for (const path of def.links?.docs ?? []) {
|
|
363
|
+
if (!/^https?:\/\//.test(path) && !existsSync(join(root, path))) warnings.push(`${id}.links.docs: ${path} doesn't exist`);
|
|
364
|
+
}
|
|
365
|
+
if (def.claimedBy) claims.push([id, def.claimedBy]);
|
|
366
|
+
if (def.layer !== void 0) warnings.push(`${id}.layer: deprecated, write kind: "${def.layer === "primitive" ? "element" : def.layer}" (layer will be the owning package's, derived)`);
|
|
367
|
+
if (def.status !== "idea" && def.status !== "planned" && def.status !== "retired") {
|
|
368
|
+
if (!def.reviewedAt) warnings.push(`${id}: never reviewed (set reviewedAt)`);
|
|
369
|
+
else if (def.reviewedAt < reviewCutoff) warnings.push(`${id}: last reviewed ${def.reviewedAt}, over ${options.reviewDays ?? 90} days ago`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const files = listFiles(root);
|
|
373
|
+
const expired = expiredFlags(flags, today);
|
|
374
|
+
if (flags) {
|
|
375
|
+
for (const [name, flag] of Object.entries(flags)) {
|
|
376
|
+
if (flag.kind === "permission") errors.push(`${name}: a permission flag. Paid or role access belongs in the feature's \`access\` (entitlements), not a flag`);
|
|
377
|
+
if (flag.runbook && !/^https?:\/\//.test(flag.runbook) && !existsSync(join(root, flag.runbook))) {
|
|
378
|
+
errors.push(`${name}.runbook: ${flag.runbook} doesn't exist`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
for (const name of expired) errors.push(`${name} expired on ${flags[name].expires}: remove its code path, then the flag`);
|
|
382
|
+
if (options.scan !== false) {
|
|
383
|
+
const inScan = matcher(options.scan ?? DEFAULT_SCAN);
|
|
384
|
+
const skipped = matcher(options.scanIgnore ?? (options.tests || DEFAULT_TESTS));
|
|
385
|
+
const used = /* @__PURE__ */ new Map();
|
|
386
|
+
for (const path of files.filter((p) => inScan(p) && !skipped(p) && !p.endsWith(".d.ts"))) {
|
|
387
|
+
const { keys, dynamic } = scanFlagReads(path, readFileSync(join(root, path), "utf8"), options.flagAccessors ?? DEFAULT_ACCESSORS);
|
|
388
|
+
for (const where of dynamic) errors.push(`${where}: a flag read with a computed key. Use a literal key, so the read can be checked`);
|
|
389
|
+
for (const { key, where } of keys) {
|
|
390
|
+
if (!Object.hasOwn(flags, key)) errors.push(`${where}: the flag "${key}" is read but not defined`);
|
|
391
|
+
if (!used.has(key)) used.set(key, where);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
for (const name of Object.keys(flags)) {
|
|
395
|
+
if (!used.has(name)) errors.push(`${name}: defined but never read. Remove it, or read it through the flag accessor`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const tagged = /* @__PURE__ */ new Set();
|
|
400
|
+
if (options.tests !== false) {
|
|
401
|
+
const inTests = matcher(options.tests ?? DEFAULT_TESTS);
|
|
402
|
+
for (const path of files.filter(inTests)) {
|
|
403
|
+
const text = readFileSync(join(root, path), "utf8");
|
|
404
|
+
for (const m of text.matchAll(/@feat:([a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*)/g)) {
|
|
405
|
+
if (!known.has(m[1])) errors.push(`${at(path, text, m.index)}: @feat:${m[1]} is not a feature`);
|
|
406
|
+
else tagged.add(m[1]);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
for (const [id, def] of Object.entries(features)) {
|
|
410
|
+
const names = [id, ...def.aliases ?? []];
|
|
411
|
+
if (def.status === "live" && !names.some((n) => tagged.has(n))) warnings.push(`${id}: live, but no test is tagged @feat:${id}`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const idOf = canonical(features);
|
|
415
|
+
const shippedIn = /* @__PURE__ */ new Map();
|
|
416
|
+
const shipped = (name) => {
|
|
417
|
+
const id = idOf.get(name);
|
|
418
|
+
if (!shippedIn.has(id)) shippedIn.set(id, { changesets: [], prs: [] });
|
|
419
|
+
return shippedIn.get(id);
|
|
420
|
+
};
|
|
421
|
+
const changesets = options.changesets === void 0 ? ".changeset" : options.changesets;
|
|
422
|
+
if (changesets) {
|
|
423
|
+
for (const path of listChangesets(root, changesets)) {
|
|
424
|
+
const text = read(join(root, path)).replace(/^---\n[\s\S]*?\n---\n/, "");
|
|
425
|
+
for (const m of text.matchAll(/^features:[ \t]*\[?([^\]\n]*)\]?[ \t]*$/gim)) {
|
|
426
|
+
for (const id of m[1].split(/[\s,]+/).filter(Boolean)) {
|
|
427
|
+
if (!known.has(id)) errors.push(`${path}: Features: ${id} is not a feature`);
|
|
428
|
+
else if (!shipped(id).changesets.includes(path)) shipped(id).changesets.push(path);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
for (const [name, prs] of Object.entries(options.evidence?.prs ?? {})) {
|
|
434
|
+
if (!known.has(name)) continue;
|
|
435
|
+
const list = shipped(name).prs;
|
|
436
|
+
for (const pr of prs) if (!list.some((p) => p.number === pr.number)) list.push(pr);
|
|
437
|
+
}
|
|
438
|
+
const plannedButShipped = [];
|
|
439
|
+
for (const [id, def] of Object.entries(features)) {
|
|
440
|
+
const found = shippedIn.get(id);
|
|
441
|
+
if (def.status !== "planned" && def.status !== "idea" || !found || !found.changesets.length && !found.prs.length) continue;
|
|
442
|
+
const prs = [...found.prs].sort((a, b) => a.number - b.number);
|
|
443
|
+
plannedButShipped.push({ id, changesets: found.changesets, prs });
|
|
444
|
+
warnings.push(`${id} is still ${def.status === "idea" ? "an idea" : "planned"}, but ${and([...found.changesets, ...prs.map((p) => `PR #${p.number}`)])} shipped work for it`);
|
|
445
|
+
}
|
|
446
|
+
for (const label of options.labels ?? []) {
|
|
447
|
+
const id = /^feature:(.+)$/.exec(label.trim())?.[1];
|
|
448
|
+
if (id && !known.has(id)) errors.push(`PR label ${label}: ${id} is not a feature`);
|
|
449
|
+
}
|
|
450
|
+
if (options.coverage !== false) {
|
|
451
|
+
const inCoverage = matcher(options.coverage ?? DEFAULT_COVERAGE);
|
|
452
|
+
const ignored = matcher(options.coverageIgnore ?? DEFAULT_COVERAGE_IGNORE);
|
|
453
|
+
const covered = Object.values(features).flatMap((f) => f.links?.code ?? []).map((p) => p.replace(/\/+$/, ""));
|
|
454
|
+
for (const path of files.filter((p) => inCoverage(p) && !ignored(p))) {
|
|
455
|
+
if (!covered.some((c) => path === c || path.startsWith(`${c}/`))) warnings.push(`${path}: no feature's links.code covers it`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return { ok: errors.length === 0, errors, warnings, stale, expiredFlags: expired, claims, plannedButShipped };
|
|
459
|
+
}
|
|
460
|
+
function listChangesets(root, dir) {
|
|
461
|
+
try {
|
|
462
|
+
return readdirSync(join(root, dir)).filter((f) => f.endsWith(".md") && f.toLowerCase() !== "readme.md").map((f) => `${dir}/${f}`);
|
|
463
|
+
} catch {
|
|
464
|
+
return [];
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function summarizeCheck(result, features) {
|
|
468
|
+
const total = Object.keys(features).length;
|
|
469
|
+
const lines = [
|
|
470
|
+
`Features: ${total} in the registry; ${result.errors.length} error${result.errors.length === 1 ? "" : "s"}, ${result.warnings.length} warning${result.warnings.length === 1 ? "" : "s"}.`
|
|
471
|
+
];
|
|
472
|
+
if (result.stale.length) lines.push(`- Stale generated files: ${result.stale.join(", ")}. Run the features build.`);
|
|
473
|
+
if (result.expiredFlags.length) lines.push(`- Expired flags: ${result.expiredFlags.join(", ")}. Remove the code path, then the flag.`);
|
|
474
|
+
if (result.plannedButShipped.length) {
|
|
475
|
+
const n = result.plannedButShipped.length;
|
|
476
|
+
lines.push(`- ${n} planned feature${n === 1 ? " has" : "s have"} shipped work: ${result.plannedButShipped.map((s) => s.id).join(", ")}. Move ${n === 1 ? "its" : "their"} status on.`);
|
|
477
|
+
}
|
|
478
|
+
if (result.claims.length) lines.push(`- Being built: ${result.claims.map(([id, by]) => `${id} (${by})`).join(", ")}.`);
|
|
479
|
+
const other = result.errors.length - result.stale.length - result.expiredFlags.length;
|
|
480
|
+
if (other > 0) lines.push(`- ${other} other error${other === 1 ? "" : "s"}: run the features check for details.`);
|
|
481
|
+
return lines.join("\n");
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export { blankComments, buildFeatureOutputs, checkFeatureOutputs, globToRegExp, scanFlagReads, summarizeCheck };
|
|
485
|
+
//# sourceMappingURL=node.js.map
|
|
486
|
+
//# sourceMappingURL=node.js.map
|