@zero2webmaster/starter-kit 0.2.0 → 0.3.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/README.md +14 -15
- package/dist/airtable.d.ts +119 -0
- package/dist/airtable.js +273 -0
- package/dist/brief.d.ts +2 -2
- package/dist/brief.js +11 -4
- package/dist/cli.js +290 -17
- package/dist/confirm.d.ts +16 -4
- package/dist/confirm.js +66 -32
- package/dist/index.d.ts +195 -3
- package/dist/index.js +155 -6
- package/dist/inventory.d.ts +137 -0
- package/dist/inventory.js +258 -0
- package/dist/license.d.ts +97 -0
- package/dist/license.js +474 -0
- package/dist/parse-brief.d.ts +45 -1
- package/dist/parse-brief.js +349 -21
- package/dist/scaffolders/common.d.ts +42 -1
- package/dist/scaffolders/common.js +753 -30
- package/dist/scaffolders/index.d.ts +1 -0
- package/dist/scaffolders/index.js +3 -0
- package/dist/scaffolders/library.js +26 -2
- package/dist/scaffolders/nextjs.d.ts +1 -1
- package/dist/scaffolders/nextjs.js +254 -24
- package/dist/scaffolders/node-service.d.ts +3 -0
- package/dist/scaffolders/node-service.js +320 -0
- package/dist/scaffolders/pro-seo-extension.d.ts +11 -0
- package/dist/scaffolders/pro-seo-extension.js +782 -0
- package/dist/scaffolders/python-service.js +10 -2
- package/dist/scaffolders/wp-plugin.js +8 -8
- package/dist/standards.d.ts +1 -1
- package/dist/standards.js +164 -5
- package/dist/substitute.d.ts +22 -3
- package/dist/substitute.js +19 -5
- package/dist/summary.d.ts +9 -0
- package/dist/summary.js +31 -13
- package/dist/templates.d.ts +43 -57
- package/dist/templates.js +108 -175
- package/dist/with-init.d.ts +32 -0
- package/dist/with-init.js +171 -0
- package/dist/wizard.js +21 -0
- package/dist/writer.d.ts +13 -6
- package/dist/writer.js +119 -21
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { writeScaffold } from "./writer.js";
|
|
2
|
+
import type { ScaffoldFile } from "./scaffolders/common.js";
|
|
3
|
+
import type { StandardDecision } from "./standards.js";
|
|
4
|
+
export declare const version = "0.3.0";
|
|
5
|
+
export type ProjectType = "wp-plugin" | "cf-worker" | "cf-pages" | "nextjs" | "python-service" | "node-service" | "library" | "protocol-repo";
|
|
3
6
|
export type BrandPreset = "save-the-frogs" | "bansuri-bliss" | "zero2webmaster" | "custom";
|
|
4
7
|
export type DbStrategy = "none" | "neon-postgres" | "supabase" | "sqlite" | "mysql-wp" | "other";
|
|
8
|
+
export declare const PROJECT_TYPES: readonly ProjectType[];
|
|
9
|
+
export declare const BRANDS: readonly BrandPreset[];
|
|
10
|
+
export declare const DB_STRATEGIES: readonly DbStrategy[];
|
|
5
11
|
/**
|
|
6
12
|
* Follow-up details a user supplies when `brand` is `"custom"`. Carries the
|
|
7
13
|
* four fields the confirmation / wizard flows ask for: brand name, the
|
|
@@ -14,6 +20,26 @@ export interface CustomBrandInputs {
|
|
|
14
20
|
primaryColor: string;
|
|
15
21
|
accentColor: string;
|
|
16
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Free-text sections lifted verbatim from a pasted project brief. Every field
|
|
25
|
+
* is optional — only the sections the brief actually contained are populated.
|
|
26
|
+
* Carried through to the scaffolder so the brief's planning content flows into
|
|
27
|
+
* the generated ROADMAP.md + README.md rather than being discarded after
|
|
28
|
+
* field inference (per [[instantiate-z2w-project]] SKILL Step 1a.4). Populated
|
|
29
|
+
* automatically by the brief-first flow; absent for `--wizard`. The `--input`
|
|
30
|
+
* path has no brief to parse, but a caller that already has the sections may
|
|
31
|
+
* supply them in the input JSON (`parseScaffoldInputs` reads them) so an
|
|
32
|
+
* `--input` scaffold still gets a concrete ROADMAP instead of a placeholder.
|
|
33
|
+
*/
|
|
34
|
+
export interface BriefSections {
|
|
35
|
+
purpose?: string;
|
|
36
|
+
keyApis?: string;
|
|
37
|
+
dataSources?: string;
|
|
38
|
+
expectedOutputs?: string;
|
|
39
|
+
edgeCases?: string;
|
|
40
|
+
roadmap?: string;
|
|
41
|
+
futureImprovements?: string;
|
|
42
|
+
}
|
|
17
43
|
export interface ScaffoldInputs {
|
|
18
44
|
slug: string;
|
|
19
45
|
description: string;
|
|
@@ -25,7 +51,173 @@ export interface ScaffoldInputs {
|
|
|
25
51
|
hasWebUi: boolean;
|
|
26
52
|
hasCron: boolean;
|
|
27
53
|
participateInBulletin: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Whether this project sends transactional / auth email (magic links,
|
|
56
|
+
* confirmations, notifications). When `true`, the `nextjs` and `node-service`
|
|
57
|
+
* scaffolders emit a provider-router mailer (`sendEmail()` with a stable,
|
|
58
|
+
* provider-agnostic signature) defaulting to Amazon SES with Resend as a
|
|
59
|
+
* one-env-var swappable alternative (`EMAIL_PROVIDER=resend`), plus both
|
|
60
|
+
* providers' env stubs and a `directives/email-setup.md` setup runbook. Per
|
|
61
|
+
* the 2026-06-28 email-default decision (event-engine, on Kerry's steer): when
|
|
62
|
+
* a stack already runs SES in production (STF / BB / Z2W), default to SES —
|
|
63
|
+
* zero new vendor, no domain warmup, cheap at volume — and keep Resend as the
|
|
64
|
+
* easier-DX alternative for non-developer clients. See [[email-service-router]].
|
|
65
|
+
*
|
|
66
|
+
* Optional and defaults to `false` (no mailer emitted). Honored ONLY by the
|
|
67
|
+
* `nextjs` and `node-service` types — WordPress uses FluentSMTP, Cloudflare
|
|
68
|
+
* Workers use the Cloudflare Email Service ([[cloudflare-email-service]]), and
|
|
69
|
+
* `python-service` is a different language, so those types ignore this flag.
|
|
70
|
+
*/
|
|
71
|
+
sendsEmail?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether this project accepts user-generated content (UGC) — a community
|
|
74
|
+
* platform, events app with public listings, marketplace, comments/forum,
|
|
75
|
+
* profiles, direct messages, or any surface where one user's input is shown
|
|
76
|
+
* to others. When `true`, the standards resolver inserts the "Moderation
|
|
77
|
+
* baseline (user-generated content)" standard pointing at [[moderation-system]]
|
|
78
|
+
* — the entity-agnostic report→queue model, reporting-as-a-safety-action,
|
|
79
|
+
* enforcement-that-reuses-existing-gates, the fail-open AI-scan seam, the
|
|
80
|
+
* public/anonymous-reporter variant, and the optional pre-publish gate — so a
|
|
81
|
+
* new UGC app treats moderation as an at-instantiation decision (like the SEO
|
|
82
|
+
* baseline for public web UIs) rather than a Phase-8 afterthought. Requested
|
|
83
|
+
* by the event-engine agent on the bulletin (2026-07-08), which built the
|
|
84
|
+
* second reference implementation of the pattern.
|
|
85
|
+
*
|
|
86
|
+
* Optional and defaults to `false` (no standard emitted). Skipped for the
|
|
87
|
+
* `wp-plugin` type (WordPress moderates comments natively / via Akismet), and
|
|
88
|
+
* for `library` / `protocol-repo` (no content surface).
|
|
89
|
+
*/
|
|
90
|
+
hasUserContent?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Whether this project should wire runtime error / APM observability
|
|
93
|
+
* (Sentry) at instantiation. When `true` AND the type is a Next.js / CF-Pages
|
|
94
|
+
* web app, the standards resolver inserts the "Sentry runtime-error tracking"
|
|
95
|
+
* standard pointing at [[sentry-runtime-errors]] — the `npx @sentry/wizard`
|
|
96
|
+
* invocation, DSN-in-config posture, `SENTRY_AUTH_TOKEN` Production-only
|
|
97
|
+
* scope, the tracing/replay feature-flag defaults, the smoke-route pattern,
|
|
98
|
+
* and the 2025 Sentry-UI quirks — so a customer-facing app treats runtime
|
|
99
|
+
* error capture as an at-instantiation decision (like Fathom for analytics and
|
|
100
|
+
* Uptime Kuma for liveness) rather than a post-incident afterthought. Sentry
|
|
101
|
+
* fills the gap uptime monitoring can't: a per-user 500 that `/health` never
|
|
102
|
+
* sees. Requested by the videomigrator-dashboard agent on the bulletin
|
|
103
|
+
* (2026-06-11) after wiring Sentry there; see [[sentry-runtime-errors]].
|
|
104
|
+
*
|
|
105
|
+
* Optional. Omitted (undefined) reads as `false` in the standards resolver —
|
|
106
|
+
* so the programmatic API and `--input` paths stay explicit/opt-in — while the
|
|
107
|
+
* interactive brief-first and wizard flows apply a smart default of ON for
|
|
108
|
+
* customer-facing Next.js / CF-Pages apps (a human can veto at the confirm
|
|
109
|
+
* screen). Skipped for every type except `nextjs` / `cf-pages`: WordPress
|
|
110
|
+
* gets error tracking via Admin Suite Diagnostics; CLI libraries, protocol
|
|
111
|
+
* repos, Workers, and API-only services have no "individual user request
|
|
112
|
+
* failed silently" surface.
|
|
113
|
+
*/
|
|
114
|
+
hasObservability?: boolean;
|
|
28
115
|
/** Present only when `brand === "custom"`. */
|
|
29
116
|
customBrand?: CustomBrandInputs;
|
|
117
|
+
/**
|
|
118
|
+
* Present when scaffolding from a pasted brief that had these sections (the
|
|
119
|
+
* brief-first flow), or when an `--input` payload supplies them explicitly.
|
|
120
|
+
*/
|
|
121
|
+
briefSections?: BriefSections;
|
|
122
|
+
/**
|
|
123
|
+
* The verbatim project-instantiation brief/prompt this project was scaffolded
|
|
124
|
+
* from. Captured automatically by the brief-first flow (the raw pasted brief);
|
|
125
|
+
* may be supplied on the `--input` JSON. Written to the Airtable inventory
|
|
126
|
+
* row's "Project Instantiation Prompt" column (Kerry's standing rule that
|
|
127
|
+
* every inventory row carries its instantiation prompt). Absent for the
|
|
128
|
+
* wizard path and `--input` payloads that omit it — in which case the agent
|
|
129
|
+
* is reminded to add it to the row by hand.
|
|
130
|
+
*/
|
|
131
|
+
instantiationPrompt?: string;
|
|
30
132
|
}
|
|
31
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Options for the programmatic {@link scaffold} / {@link previewScaffold} entry
|
|
135
|
+
* points. A deliberately small subset of {@link WriteScaffoldOptions} — the
|
|
136
|
+
* interactive-only knobs (`promoteStandards`, `prompter`, `output`,
|
|
137
|
+
* `showContents`) are omitted because a programmatic caller neither prompts nor
|
|
138
|
+
* prints. Reach for `writeScaffold` directly if you need those.
|
|
139
|
+
*/
|
|
140
|
+
export interface ScaffoldOptions {
|
|
141
|
+
/** Absolute target directory. Defaults to `inputs.targetPath`. */
|
|
142
|
+
targetPath?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Pin the scaffold date as `YYYY-MM-DD` for deterministic output (tests,
|
|
145
|
+
* reproducible builds). Defaults to today from the OS clock.
|
|
146
|
+
*/
|
|
147
|
+
date?: string;
|
|
148
|
+
/**
|
|
149
|
+
* Override the canonical Templates folder location. Defaults to the standard
|
|
150
|
+
* local resolution (`~/Desktop/Zero2Webmaster/AI/Templates/`). A server
|
|
151
|
+
* consumer bundles/mounts Templates and points this at it — the folder is
|
|
152
|
+
* read server-side and never delivered to the client.
|
|
153
|
+
*/
|
|
154
|
+
templatesPath?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Refuse to write into a non-empty directory. Defaults to `true`. Ignored by
|
|
157
|
+
* {@link previewScaffold} (which never touches disk).
|
|
158
|
+
*/
|
|
159
|
+
refuseNonEmpty?: boolean;
|
|
160
|
+
/** Layer the paid Pro SEO baseline extension (nextjs / cf-pages + hasWebUi only). */
|
|
161
|
+
withProSeo?: boolean;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The result of a scaffold or preview: the composed file list, the standards
|
|
165
|
+
* decision log, and the resolved absolute target path. For {@link scaffold}
|
|
166
|
+
* these are the files that WERE written; for {@link previewScaffold} they are
|
|
167
|
+
* the files that WOULD be written.
|
|
168
|
+
*/
|
|
169
|
+
export interface ScaffoldResult {
|
|
170
|
+
files: ScaffoldFile[];
|
|
171
|
+
decisions: StandardDecision[];
|
|
172
|
+
targetPath: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Scaffold a full project to disk and return the composed result.
|
|
176
|
+
*
|
|
177
|
+
* The high-level programmatic equivalent of `npx @zero2webmaster/starter-kit
|
|
178
|
+
* init` for a caller that already has validated {@link ScaffoldInputs} (e.g.
|
|
179
|
+
* from {@link parseScaffoldInputs} + {@link validateScaffoldInputs}). Delegates
|
|
180
|
+
* to {@link writeScaffold}; the canonical AGENTS body + standards are read and
|
|
181
|
+
* composed exactly as the CLI does. Throws `WriterError` on a non-absolute or
|
|
182
|
+
* (by default) non-empty target, or if any template marker / `{{placeholder}}`
|
|
183
|
+
* survives composition.
|
|
184
|
+
*/
|
|
185
|
+
export declare function scaffold(inputs: ScaffoldInputs, opts?: ScaffoldOptions): Promise<ScaffoldResult>;
|
|
186
|
+
/**
|
|
187
|
+
* Compose the exact same file list {@link scaffold} would write, but WITHOUT
|
|
188
|
+
* touching the filesystem and without printing anything — the files are
|
|
189
|
+
* returned as data. This is the entry point a web UI / server consumer wants:
|
|
190
|
+
* show the user what they'll get (file tree, standards inserted) before they
|
|
191
|
+
* commit to creating a repo.
|
|
192
|
+
*
|
|
193
|
+
* The only I/O is reading the Templates folder (needed to fill the AGENTS
|
|
194
|
+
* body). `inputs.targetPath` (or `opts.targetPath`) must still be an absolute
|
|
195
|
+
* path — it's used only to validate that every generated file resolves inside
|
|
196
|
+
* it; nothing is created there. `refuseNonEmpty` is not consulted.
|
|
197
|
+
*/
|
|
198
|
+
export declare function previewScaffold(inputs: ScaffoldInputs, opts?: ScaffoldOptions): Promise<ScaffoldResult>;
|
|
199
|
+
/** Outcome of {@link validateScaffoldInputs}: `ok` plus every error found. */
|
|
200
|
+
export interface ScaffoldInputValidation {
|
|
201
|
+
ok: boolean;
|
|
202
|
+
errors: string[];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Structurally validate a {@link ScaffoldInputs} without touching the
|
|
206
|
+
* filesystem, collecting ALL problems (not just the first). Complements
|
|
207
|
+
* {@link parseScaffoldInputs}, which checks primitive types + required-field
|
|
208
|
+
* presence but deliberately does NOT check the slug regex, enum membership, or
|
|
209
|
+
* that `targetPath` is absolute — this does, so a server can reject a bad form
|
|
210
|
+
* submission with a complete error list before attempting a scaffold.
|
|
211
|
+
*
|
|
212
|
+
* Note: does not check that `targetPath` is empty/writable on disk — that's an
|
|
213
|
+
* async filesystem concern the CLI's confirm flow owns, and `scaffold` enforces
|
|
214
|
+
* it at write time via `refuseNonEmpty`.
|
|
215
|
+
*/
|
|
216
|
+
export declare function validateScaffoldInputs(inputs: ScaffoldInputs): ScaffoldInputValidation;
|
|
217
|
+
export { writeScaffold };
|
|
218
|
+
export { parseScaffoldInputs, loadScaffoldInputs, WriterError } from "./writer.js";
|
|
219
|
+
export type { WriteScaffoldOptions, WriteScaffoldResult, PromotionDecision, } from "./writer.js";
|
|
220
|
+
export { resolveStandards, applyStandardsBlock, fathomEnvVarFor } from "./standards.js";
|
|
221
|
+
export type { StandardKey, StandardDecision, StandardDecisionState, StandardsResolution, } from "./standards.js";
|
|
222
|
+
export { scaffoldByType } from "./scaffolders/index.js";
|
|
223
|
+
export type { ScaffoldFile, ScaffolderOptions } from "./scaffolders/common.js";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,159 @@
|
|
|
1
1
|
// z2w-starter-kit programmatic API.
|
|
2
2
|
//
|
|
3
|
-
// This module
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// This module is the package's public entry point. It exports the same
|
|
4
|
+
// scaffolding logic the CLI uses so callers — the future Tier B web UI
|
|
5
|
+
// (`project-creator`, see _project-briefs/z2w-project-creator-brief.md),
|
|
6
|
+
// integration tests, or any other Z2W tool — can invoke it in-process without
|
|
7
|
+
// spawning `npx`. Two entry points cover the common needs:
|
|
6
8
|
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
// • `scaffold(inputs, opts?)` — write a full project to disk.
|
|
10
|
+
// • `previewScaffold(inputs, opts?)` — compose the same file list WITHOUT
|
|
11
|
+
// touching disk or writing to stdout,
|
|
12
|
+
// returning the files as data (what a
|
|
13
|
+
// web preview / server consumer wants).
|
|
14
|
+
//
|
|
15
|
+
// plus `validateScaffoldInputs(inputs)` for cheap structural validation before
|
|
16
|
+
// either, and re-exports of the lower-level building blocks (`writeScaffold`,
|
|
17
|
+
// `resolveStandards`, `scaffoldByType`, `parseScaffoldInputs`, …) so consumers
|
|
18
|
+
// import from the package root instead of deep-importing dist internals.
|
|
19
|
+
//
|
|
20
|
+
import * as path from "node:path";
|
|
21
|
+
import { Writable } from "node:stream";
|
|
22
|
+
import { isValidSlug } from "./parse-brief.js";
|
|
23
|
+
import { writeScaffold } from "./writer.js";
|
|
24
|
+
export const version = "0.3.0";
|
|
25
|
+
// Canonical enum value-arrays. These live here, next to the type unions they
|
|
26
|
+
// enumerate, so both the CLI's confirm/wizard flows (which re-export them) and
|
|
27
|
+
// the programmatic `validateScaffoldInputs` share one source of truth. Keep
|
|
28
|
+
// each array in sync with its union above.
|
|
29
|
+
export const PROJECT_TYPES = [
|
|
30
|
+
"wp-plugin",
|
|
31
|
+
"cf-worker",
|
|
32
|
+
"cf-pages",
|
|
33
|
+
"nextjs",
|
|
34
|
+
"python-service",
|
|
35
|
+
"node-service",
|
|
36
|
+
"library",
|
|
37
|
+
"protocol-repo",
|
|
38
|
+
];
|
|
39
|
+
export const BRANDS = [
|
|
40
|
+
"save-the-frogs",
|
|
41
|
+
"bansuri-bliss",
|
|
42
|
+
"zero2webmaster",
|
|
43
|
+
"custom",
|
|
44
|
+
];
|
|
45
|
+
export const DB_STRATEGIES = [
|
|
46
|
+
"none",
|
|
47
|
+
"neon-postgres",
|
|
48
|
+
"supabase",
|
|
49
|
+
"sqlite",
|
|
50
|
+
"mysql-wp",
|
|
51
|
+
"other",
|
|
52
|
+
];
|
|
53
|
+
function toResult(r) {
|
|
54
|
+
return { files: r.filesWritten, decisions: r.decisions, targetPath: r.targetPath };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Scaffold a full project to disk and return the composed result.
|
|
58
|
+
*
|
|
59
|
+
* The high-level programmatic equivalent of `npx @zero2webmaster/starter-kit
|
|
60
|
+
* init` for a caller that already has validated {@link ScaffoldInputs} (e.g.
|
|
61
|
+
* from {@link parseScaffoldInputs} + {@link validateScaffoldInputs}). Delegates
|
|
62
|
+
* to {@link writeScaffold}; the canonical AGENTS body + standards are read and
|
|
63
|
+
* composed exactly as the CLI does. Throws `WriterError` on a non-absolute or
|
|
64
|
+
* (by default) non-empty target, or if any template marker / `{{placeholder}}`
|
|
65
|
+
* survives composition.
|
|
66
|
+
*/
|
|
67
|
+
export async function scaffold(inputs, opts = {}) {
|
|
68
|
+
const result = await writeScaffold(inputs, opts.targetPath ?? inputs.targetPath, {
|
|
69
|
+
dryRun: false,
|
|
70
|
+
refuseNonEmpty: opts.refuseNonEmpty,
|
|
71
|
+
templatesPath: opts.templatesPath,
|
|
72
|
+
date: opts.date,
|
|
73
|
+
withProSeo: opts.withProSeo,
|
|
74
|
+
});
|
|
75
|
+
return toResult(result);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compose the exact same file list {@link scaffold} would write, but WITHOUT
|
|
79
|
+
* touching the filesystem and without printing anything — the files are
|
|
80
|
+
* returned as data. This is the entry point a web UI / server consumer wants:
|
|
81
|
+
* show the user what they'll get (file tree, standards inserted) before they
|
|
82
|
+
* commit to creating a repo.
|
|
83
|
+
*
|
|
84
|
+
* The only I/O is reading the Templates folder (needed to fill the AGENTS
|
|
85
|
+
* body). `inputs.targetPath` (or `opts.targetPath`) must still be an absolute
|
|
86
|
+
* path — it's used only to validate that every generated file resolves inside
|
|
87
|
+
* it; nothing is created there. `refuseNonEmpty` is not consulted.
|
|
88
|
+
*/
|
|
89
|
+
export async function previewScaffold(inputs, opts = {}) {
|
|
90
|
+
// Discard the dry-run banner/file-list writeScaffold emits — we return the
|
|
91
|
+
// files as structured data instead of printing them.
|
|
92
|
+
const sink = new Writable({ write(_chunk, _enc, cb) { cb(); } });
|
|
93
|
+
const result = await writeScaffold(inputs, opts.targetPath ?? inputs.targetPath, {
|
|
94
|
+
dryRun: true,
|
|
95
|
+
templatesPath: opts.templatesPath,
|
|
96
|
+
date: opts.date,
|
|
97
|
+
withProSeo: opts.withProSeo,
|
|
98
|
+
output: sink,
|
|
99
|
+
});
|
|
100
|
+
return toResult(result);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Structurally validate a {@link ScaffoldInputs} without touching the
|
|
104
|
+
* filesystem, collecting ALL problems (not just the first). Complements
|
|
105
|
+
* {@link parseScaffoldInputs}, which checks primitive types + required-field
|
|
106
|
+
* presence but deliberately does NOT check the slug regex, enum membership, or
|
|
107
|
+
* that `targetPath` is absolute — this does, so a server can reject a bad form
|
|
108
|
+
* submission with a complete error list before attempting a scaffold.
|
|
109
|
+
*
|
|
110
|
+
* Note: does not check that `targetPath` is empty/writable on disk — that's an
|
|
111
|
+
* async filesystem concern the CLI's confirm flow owns, and `scaffold` enforces
|
|
112
|
+
* it at write time via `refuseNonEmpty`.
|
|
113
|
+
*/
|
|
114
|
+
export function validateScaffoldInputs(inputs) {
|
|
115
|
+
const errors = [];
|
|
116
|
+
if (typeof inputs.slug !== "string" || !isValidSlug(inputs.slug)) {
|
|
117
|
+
errors.push(`slug ${JSON.stringify(inputs.slug)} is invalid: must match ^[a-z][a-z0-9-]{2,49}$ with no -v<n> version suffix.`);
|
|
118
|
+
}
|
|
119
|
+
if (typeof inputs.description !== "string" || inputs.description.trim().length === 0) {
|
|
120
|
+
errors.push(`description must be a non-empty string.`);
|
|
121
|
+
}
|
|
122
|
+
if (!PROJECT_TYPES.includes(inputs.projectType)) {
|
|
123
|
+
errors.push(`projectType ${JSON.stringify(inputs.projectType)} is invalid: expected one of ${PROJECT_TYPES.join(", ")}.`);
|
|
124
|
+
}
|
|
125
|
+
if (!BRANDS.includes(inputs.brand)) {
|
|
126
|
+
errors.push(`brand ${JSON.stringify(inputs.brand)} is invalid: expected one of ${BRANDS.join(", ")}.`);
|
|
127
|
+
}
|
|
128
|
+
if (!DB_STRATEGIES.includes(inputs.dbStrategy)) {
|
|
129
|
+
errors.push(`dbStrategy ${JSON.stringify(inputs.dbStrategy)} is invalid: expected one of ${DB_STRATEGIES.join(", ")}.`);
|
|
130
|
+
}
|
|
131
|
+
if (typeof inputs.githubOrg !== "string" || inputs.githubOrg.trim().length === 0) {
|
|
132
|
+
errors.push(`githubOrg must be a non-empty string.`);
|
|
133
|
+
}
|
|
134
|
+
if (typeof inputs.targetPath !== "string" || !path.isAbsolute(inputs.targetPath)) {
|
|
135
|
+
errors.push(`targetPath must be an absolute path. Got: ${JSON.stringify(inputs.targetPath)}.`);
|
|
136
|
+
}
|
|
137
|
+
if (inputs.brand === "custom") {
|
|
138
|
+
const cb = inputs.customBrand;
|
|
139
|
+
if (!cb || typeof cb !== "object") {
|
|
140
|
+
errors.push(`brand is "custom" but customBrand is missing.`);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
for (const k of ["brandName", "brandNameRule", "primaryColor", "accentColor"]) {
|
|
144
|
+
if (typeof cb[k] !== "string" || cb[k].trim().length === 0) {
|
|
145
|
+
errors.push(`customBrand.${k} must be a non-empty string when brand is "custom".`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { ok: errors.length === 0, errors };
|
|
10
151
|
}
|
|
152
|
+
// ── Public re-exports ────────────────────────────────────────────────────────
|
|
153
|
+
// The building blocks the CLI composes, surfaced at the package root so
|
|
154
|
+
// programmatic consumers import from one place rather than deep-importing
|
|
155
|
+
// `dist/` internals.
|
|
156
|
+
export { writeScaffold };
|
|
157
|
+
export { parseScaffoldInputs, loadScaffoldInputs, WriterError } from "./writer.js";
|
|
158
|
+
export { resolveStandards, applyStandardsBlock, fathomEnvVarFor } from "./standards.js";
|
|
159
|
+
export { scaffoldByType } from "./scaffolders/index.js";
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { type ScaffoldInputs } from "./index.js";
|
|
2
|
+
/** The Neon `projects` table the inventory rows live in. */
|
|
3
|
+
export declare const INVENTORY_TABLE = "projects";
|
|
4
|
+
/** The conflict key — the `projects/{slug}.md` filename the cron keys on. */
|
|
5
|
+
export declare const INVENTORY_CONFLICT_KEY = "slug";
|
|
6
|
+
export interface InventoryConfig {
|
|
7
|
+
/** Postgres connection string (Neon pooled "Connection String"). */
|
|
8
|
+
databaseUrl: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the Neon inventory config from the environment. Returns null when no
|
|
12
|
+
* Z2W_INVENTORY_DATABASE_URL is set — the signal that the Neon write is disabled
|
|
13
|
+
* for this caller (every CLI user who isn't Kerry). Mirrors
|
|
14
|
+
* `resolveAirtableConfig`'s no-op gate exactly.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveInventoryConfig(env?: NodeJS.ProcessEnv): InventoryConfig | null;
|
|
17
|
+
/** A single column's value. The `projects` columns we write are text or boolean. */
|
|
18
|
+
export type ProjectRowValue = string | boolean;
|
|
19
|
+
/** A row's CLI-owned columns, keyed by their snake_case Neon column name. */
|
|
20
|
+
export type ProjectRow = Record<string, ProjectRowValue>;
|
|
21
|
+
export interface BuildProjectRowOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the freshly-written scaffold was confirmed to carry the
|
|
24
|
+
* coordination block (see `scaffoldCarriesCoordinationBlock`). Same semantics
|
|
25
|
+
* as the Airtable mapper: a boolean gates the `agent_coordination = Registered`
|
|
26
|
+
* assertion ("verify, don't assert"); `undefined` (could not verify — dry-run
|
|
27
|
+
* or a direct unit-test call) falls back to the `participateInBulletin` flag.
|
|
28
|
+
*/
|
|
29
|
+
coordinationVerified?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Pure mapping from ScaffoldInputs to the Neon `projects` row. Mirrors the
|
|
33
|
+
* decisions in src/airtable.ts `buildProjectFields`, mapped to the FINAL 23-column
|
|
34
|
+
* snake_case schema (column audit executed 2026-06-22). Only columns the CLI can
|
|
35
|
+
* auto-fill at scaffold time are written — manually-curated columns (technology,
|
|
36
|
+
* licensing, notes, research_url, …) are intentionally omitted so the UPSERT's
|
|
37
|
+
* DO UPDATE never clobbers Kerry's hand-entered values.
|
|
38
|
+
*
|
|
39
|
+
* Difference from the Airtable mapper: `project_type` IS written here (the Neon
|
|
40
|
+
* column is plain text and the CLI knows the value, so it earns its place per the
|
|
41
|
+
* column-audit principle "a column earns its place only if the CLI can auto-fill
|
|
42
|
+
* it"). The Airtable mapper omitted it only because that base's Project Type is a
|
|
43
|
+
* single-select whose option names could 422 on first use. `skill_vault_aware` is
|
|
44
|
+
* a real boolean here (Neon column type), not the Airtable "Yes" string.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildProjectRow(inputs: ScaffoldInputs, opts?: BuildProjectRowOptions): ProjectRow;
|
|
47
|
+
/**
|
|
48
|
+
* A well-formed inventory slug: lowercase letters, digits, and hyphens only.
|
|
49
|
+
* This mirrors the coordination bulletin's `projects/{slug}.md` filename
|
|
50
|
+
* convention (the slug IS the filename), and rejects the historical CSV-imported
|
|
51
|
+
* junk the 2026-07-05 registry data-hygiene sweep found — e.g. `"Skill Vault"`
|
|
52
|
+
* (space + capitals) or `"Website - VimeoBunny"`. The CLI's input-side
|
|
53
|
+
* `project_slug` rule is stricter still (`^[a-z][a-z0-9-]{2,49}$`); this is the
|
|
54
|
+
* looser floor the inventory row must clear before it is written.
|
|
55
|
+
*/
|
|
56
|
+
export declare const INVENTORY_SLUG_RE: RegExp;
|
|
57
|
+
/**
|
|
58
|
+
* A well-formed GitHub URL: exactly `https://github.com/{owner}/{repo}` with no
|
|
59
|
+
* trailing slash or path. Rejects the malformed values the hygiene sweep found —
|
|
60
|
+
* a missing scheme (`github.com/owner/repo`, `owner/repo`) or a trailing slash
|
|
61
|
+
* (`.../website-aharon/`). Owner/repo allow the GitHub-legal set `[A-Za-z0-9_.-]`.
|
|
62
|
+
*/
|
|
63
|
+
export declare const INVENTORY_GITHUB_URL_RE: RegExp;
|
|
64
|
+
/**
|
|
65
|
+
* Validate the CLI-owned fields of a would-be inventory row. Returns a list of
|
|
66
|
+
* human-readable problems (empty = valid). Called before every write so a
|
|
67
|
+
* malformed `slug` / `github_url` can never be UPSERTed into the registry — the
|
|
68
|
+
* prevention half of the 2026-07-05 `z2w-agent-coordination` data-hygiene ask.
|
|
69
|
+
*/
|
|
70
|
+
export declare function validateProjectRow(row: ProjectRow): string[];
|
|
71
|
+
export interface UpsertStatement {
|
|
72
|
+
/** The parameterized SQL (column names are code-controlled — injection-safe). */
|
|
73
|
+
sql: string;
|
|
74
|
+
/** Positional parameter values, in $1..$n order. */
|
|
75
|
+
params: ProjectRowValue[];
|
|
76
|
+
/** The columns written, in order — for a secret-free dry-run preview. */
|
|
77
|
+
columns: string[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build the INSERT … ON CONFLICT (slug) DO UPDATE statement from a row. Column
|
|
81
|
+
* names come from `buildProjectRow` (our own code, never user input), so string
|
|
82
|
+
* interpolation of column names is injection-safe; all VALUES are parameterized.
|
|
83
|
+
* The DO UPDATE set list excludes `slug` (the conflict key) and touches only the
|
|
84
|
+
* columns present in `row`, so columns the CLI doesn't manage are never altered.
|
|
85
|
+
* `updated_at` is left to the table's auto-touch trigger.
|
|
86
|
+
*/
|
|
87
|
+
export declare function buildUpsert(row: ProjectRow): UpsertStatement;
|
|
88
|
+
export type NeonOutcome = "upserted" | "dry-run" | "skipped" | "failed";
|
|
89
|
+
export interface RegisterNeonResult {
|
|
90
|
+
outcome: NeonOutcome;
|
|
91
|
+
/** The row that was (or would be) written. */
|
|
92
|
+
row: ProjectRow;
|
|
93
|
+
/** The UPSERT SQL (column names only — never contains the connection string). */
|
|
94
|
+
sql?: string;
|
|
95
|
+
/** The created/updated row id, when outcome === "upserted". */
|
|
96
|
+
recordId?: string | number;
|
|
97
|
+
/** Human-readable, secret-free line for the CLI to surface. */
|
|
98
|
+
message: string;
|
|
99
|
+
/**
|
|
100
|
+
* Result of the on-disk coordination-block check, when it ran. `undefined`
|
|
101
|
+
* when verification was not attempted (dry-run / no targetPath / non-participant).
|
|
102
|
+
*/
|
|
103
|
+
coordinationVerified?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/** Query seam: run parameterized SQL, resolve to the RETURNING rows. */
|
|
106
|
+
export type QueryFn = (sql: string, params: ProjectRowValue[]) => Promise<Array<Record<string, unknown>>>;
|
|
107
|
+
export interface RegisterNeonOptions {
|
|
108
|
+
env?: NodeJS.ProcessEnv;
|
|
109
|
+
/** Build the statement but do not execute — for `init --dry-run`. */
|
|
110
|
+
dryRun?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Override config explicitly (tests). When provided (including `null`),
|
|
113
|
+
* bypasses env resolution. `null` forces the "skipped" path.
|
|
114
|
+
*/
|
|
115
|
+
config?: InventoryConfig | null;
|
|
116
|
+
/** Test/override seam for the DB client. Defaults to the Neon HTTP driver. */
|
|
117
|
+
queryImpl?: QueryFn;
|
|
118
|
+
/**
|
|
119
|
+
* Absolute path to the freshly-written scaffold. When provided (and not a
|
|
120
|
+
* dry-run) for a participating project, the coordination block is grep-verified
|
|
121
|
+
* on disk before `agent_coordination = Registered` is asserted.
|
|
122
|
+
*/
|
|
123
|
+
targetPath?: string;
|
|
124
|
+
/** Test seam for the filesystem read used by coordination verification. */
|
|
125
|
+
readFileImpl?: (path: string) => Promise<string>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* UPSERT the inventory row for a freshly-scaffolded project into Neon.
|
|
129
|
+
* Warn-and-proceed: always resolves (never rejects); the CLI surfaces `message`
|
|
130
|
+
* and continues.
|
|
131
|
+
*
|
|
132
|
+
* - No Z2W_INVENTORY_DATABASE_URL → outcome "skipped" (silent for normal users).
|
|
133
|
+
* - opts.dryRun → outcome "dry-run" (prints the would-be SQL).
|
|
134
|
+
* - success → outcome "upserted" (+ recordId).
|
|
135
|
+
* - query error → outcome "failed" (+ a diagnostic; row NOT written).
|
|
136
|
+
*/
|
|
137
|
+
export declare function registerProjectRowNeon(inputs: ScaffoldInputs, opts?: RegisterNeonOptions): Promise<RegisterNeonResult>;
|