@zero2webmaster/starter-kit 0.2.1 → 0.3.1
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 +12 -14
- package/dist/airtable.d.ts +119 -0
- package/dist/airtable.js +273 -0
- package/dist/cli.js +116 -18
- package/dist/confirm.d.ts +5 -4
- package/dist/confirm.js +41 -29
- package/dist/index.d.ts +179 -6
- package/dist/index.js +155 -6
- package/dist/inventory.d.ts +137 -0
- package/dist/inventory.js +258 -0
- package/dist/license.js +8 -6
- package/dist/parse-brief.d.ts +28 -2
- package/dist/parse-brief.js +151 -16
- package/dist/scaffolders/cf-worker.js +2 -2
- package/dist/scaffolders/common.d.ts +30 -1
- package/dist/scaffolders/common.js +538 -21
- 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 +250 -24
- package/dist/scaffolders/node-service.d.ts +3 -0
- package/dist/scaffolders/node-service.js +320 -0
- package/dist/scaffolders/pro-seo-extension.js +1 -1
- package/dist/scaffolders/python-service.js +5 -2
- package/dist/standards.d.ts +1 -1
- package/dist/standards.js +123 -3
- package/dist/substitute.d.ts +14 -3
- package/dist/substitute.js +8 -5
- package/dist/summary.d.ts +9 -0
- package/dist/summary.js +27 -10
- package/dist/templates.d.ts +43 -57
- package/dist/templates.js +108 -175
- package/dist/with-init.d.ts +18 -2
- package/dist/with-init.js +105 -16
- package/dist/wizard.js +21 -0
- package/dist/writer.d.ts +3 -5
- package/dist/writer.js +88 -15
- package/package.json +2 -1
package/dist/summary.d.ts
CHANGED
|
@@ -7,6 +7,15 @@ export interface SummaryOptions {
|
|
|
7
7
|
forceColor?: boolean;
|
|
8
8
|
/** Where to write the summary. Defaults to {@link process.stdout}. */
|
|
9
9
|
output?: NodeJS.WritableStream;
|
|
10
|
+
/**
|
|
11
|
+
* When true, the CLI is about to create the private GitHub repo itself
|
|
12
|
+
* (default-on for the interactive flows — Track D decision 2026-06-16), so
|
|
13
|
+
* the manual `git init` + `gh repo create` next-actions are omitted to avoid
|
|
14
|
+
* telling the user to redo what the CLI just did. Defaults to false, so
|
|
15
|
+
* direct callers (and the --dry-run / --input / --no-repo paths) still see
|
|
16
|
+
* the manual commands.
|
|
17
|
+
*/
|
|
18
|
+
repoAutoCreated?: boolean;
|
|
10
19
|
}
|
|
11
20
|
/**
|
|
12
21
|
* Render the post-scaffold summary block.
|
package/dist/summary.js
CHANGED
|
@@ -44,6 +44,7 @@ function installCommandFor(projectType) {
|
|
|
44
44
|
case "cf-worker":
|
|
45
45
|
case "cf-pages":
|
|
46
46
|
case "nextjs":
|
|
47
|
+
case "node-service":
|
|
47
48
|
case "library":
|
|
48
49
|
return "npm install";
|
|
49
50
|
case "python-service":
|
|
@@ -55,17 +56,21 @@ function installCommandFor(projectType) {
|
|
|
55
56
|
function isDecisionInserted(decisions, key) {
|
|
56
57
|
return decisions.some((d) => d.key === key && d.state === "inserted-inline");
|
|
57
58
|
}
|
|
58
|
-
function buildNextActions(inputs, result) {
|
|
59
|
-
const actions = [
|
|
60
|
-
|
|
59
|
+
function buildNextActions(inputs, result, repoAutoCreated) {
|
|
60
|
+
const actions = [];
|
|
61
|
+
// The git init + gh repo create steps are only surfaced when the CLI is NOT
|
|
62
|
+
// creating the repo itself. In the default interactive flow the CLI does it
|
|
63
|
+
// (Track D decision 2026-06-16), so repeating the commands here would tell
|
|
64
|
+
// the user to redo work that's already done.
|
|
65
|
+
if (!repoAutoCreated) {
|
|
66
|
+
actions.push({
|
|
61
67
|
label: `cd ${result.targetPath} && git init -b main && git config user.email "kerry@zero2webmaster.com" && git add . && git commit -m "Initial scaffold"`,
|
|
62
68
|
note: "RUN THIS FROM INSIDE THE PROJECT DIRECTORY ABOVE — never run `git init`/`git add` from your home directory (a bare `git add -A` in ~ stages credentials, .ssh, and every .env). The cd is baked into this command so it's safe to paste as-is. The repo-local user.email is the Vercel-Hobby commit-author workaround per [[z2w-magic-link-auth]] §8.",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
69
|
+
}, {
|
|
65
70
|
label: `gh repo create ${inputs.githubOrg}/${inputs.slug} --private --source=. --push`,
|
|
66
71
|
note: `run from inside ${result.targetPath}; add --description "…" and then \`gh repo edit --add-topic …\` to set the repo's About blurb + topics`,
|
|
67
|
-
}
|
|
68
|
-
|
|
72
|
+
});
|
|
73
|
+
}
|
|
69
74
|
const installCmd = installCommandFor(inputs.projectType);
|
|
70
75
|
if (installCmd !== null) {
|
|
71
76
|
actions.push({ label: installCmd });
|
|
@@ -95,6 +100,18 @@ function buildNextActions(inputs, result) {
|
|
|
95
100
|
note: "see [[uptime-kuma-monitor]] — 60s heartbeat, 2 retries, 60s retry interval, 48s timeout, accepted 200-299",
|
|
96
101
|
});
|
|
97
102
|
}
|
|
103
|
+
if (isDecisionInserted(result.decisions, "sentry")) {
|
|
104
|
+
actions.push({
|
|
105
|
+
label: `Wire Sentry: run \`npx @sentry/wizard@latest -i nextjs\`, smoke a throwaway /api/boom route, then delete it + the wizard's example page`,
|
|
106
|
+
note: "see [[sentry-runtime-errors]] — DSN in config (not an env var); SENTRY_AUTH_TOKEN Production-only in Vercel; alert rules live at /alerts/rules/ and Test Notification does NOT auto-save the rule",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (isDecisionInserted(result.decisions, "moderation")) {
|
|
110
|
+
actions.push({
|
|
111
|
+
label: `Before the first UGC surface ships, build moderation per [[moderation-system]] (entity-agnostic report→queue; reporting is a safety action; enforcement reuses existing gates; the AI scan is a fail-open seam)`,
|
|
112
|
+
note: "battle-tested across z2w-social + event-engine — do not hand-roll per-content-type; see [[moderation-system]] for the data model + verification checklist",
|
|
113
|
+
});
|
|
114
|
+
}
|
|
98
115
|
if (inputs.projectType === "wp-plugin") {
|
|
99
116
|
actions.push({
|
|
100
117
|
label: `Symlink the plugin folder into Local by Flywheel (ln -s ...)`,
|
|
@@ -154,10 +171,10 @@ function renderPromotionsSection(chalk, result) {
|
|
|
154
171
|
}
|
|
155
172
|
return lines.join("\n");
|
|
156
173
|
}
|
|
157
|
-
function renderNextActionsSection(chalk, inputs, result) {
|
|
174
|
+
function renderNextActionsSection(chalk, inputs, result, repoAutoCreated) {
|
|
158
175
|
const heading = chalk.hex(Z2W_GREEN).bold;
|
|
159
176
|
const item = chalk.hex(Z2W_GOLD);
|
|
160
|
-
const actions = buildNextActions(inputs, result);
|
|
177
|
+
const actions = buildNextActions(inputs, result, repoAutoCreated);
|
|
161
178
|
const lines = [heading("Next actions (NOT done by the CLI — your call):")];
|
|
162
179
|
for (const action of actions) {
|
|
163
180
|
lines.push(` ${item("□")} ${item(action.label)}`);
|
|
@@ -186,6 +203,6 @@ export function renderSummary(inputs, result, opts = {}) {
|
|
|
186
203
|
const promotions = renderPromotionsSection(chalk, result);
|
|
187
204
|
if (promotions !== null)
|
|
188
205
|
sections.push(promotions);
|
|
189
|
-
sections.push(renderNextActionsSection(chalk, inputs, result));
|
|
206
|
+
sections.push(renderNextActionsSection(chalk, inputs, result, opts.repoAutoCreated === true));
|
|
190
207
|
output.write("\n" + sections.join("\n\n") + "\n");
|
|
191
208
|
}
|
package/dist/templates.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
export declare const DEFAULT_TEMPLATES_PATH: string;
|
|
2
|
-
export declare const REQUIRED_FILES: readonly string[];
|
|
3
2
|
export declare const REQUIRED_DIRECTORIES: readonly string[];
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
/**
|
|
7
|
-
|
|
3
|
+
/** Which canonical AGENTS body: the general framework vs the WordPress edition. */
|
|
4
|
+
export type AgentsKind = "general" | "wp";
|
|
5
|
+
/**
|
|
6
|
+
* Glob patterns for the two canonical AGENTS bodies in the Templates root.
|
|
7
|
+
* Strict 3-part semver so:
|
|
8
|
+
* - the `general` pattern never matches `AGENTS_WP_v…` (after `AGENTS_` comes
|
|
9
|
+
* `v`, not `WP_`); and
|
|
10
|
+
* - neither matches the historical 4-part typo `AGENTS_v2.0.0.0.md` (which is
|
|
11
|
+
* archived anyway).
|
|
12
|
+
* Discovering the body by glob is what lets a canonical filename bump
|
|
13
|
+
* (`AGENTS_v2.13.0.md` → `AGENTS_v2.14.0.md`) flow through with NO code change.
|
|
14
|
+
*/
|
|
15
|
+
export declare const AGENTS_FILE_RE: Record<AgentsKind, RegExp>;
|
|
8
16
|
export declare class TemplatesError extends Error {
|
|
9
17
|
constructor(message: string);
|
|
10
18
|
}
|
|
@@ -31,72 +39,50 @@ export declare function resolveTemplatesPath(override?: string): Promise<string>
|
|
|
31
39
|
* Templates root, or otherwise cannot be read.
|
|
32
40
|
*/
|
|
33
41
|
export declare function readTemplate(name: string, templatesPath?: string): Promise<string>;
|
|
42
|
+
/** Parse the `X.Y.Z` version out of a canonical AGENTS filename, or null. */
|
|
43
|
+
export declare function agentsVersionFromName(name: string): string | null;
|
|
34
44
|
/**
|
|
35
|
-
*
|
|
45
|
+
* Discover the canonical AGENTS body for `kind` by globbing `root`.
|
|
46
|
+
*
|
|
47
|
+
* Archive-first discipline keeps exactly one match in the Templates root. If
|
|
48
|
+
* more than one is present (a missed archive), we WARN and pick the highest
|
|
49
|
+
* semver so the CLI keeps working rather than silently hiding the slip. Zero
|
|
50
|
+
* matches throws — the folder is incomplete or misnamed.
|
|
51
|
+
*
|
|
52
|
+
* @returns `{ name, version }` — the on-disk filename and the version parsed
|
|
53
|
+
* out of it (the single source of truth for `{{framework_version}}`).
|
|
36
54
|
*/
|
|
37
|
-
export
|
|
55
|
+
export declare function discoverAgentsTemplate(root: string, kind: AgentsKind, onWarn?: (message: string) => void): Promise<{
|
|
56
|
+
name: string;
|
|
57
|
+
version: string;
|
|
58
|
+
}>;
|
|
38
59
|
/**
|
|
39
|
-
* Options for {@link
|
|
60
|
+
* Options for {@link resolveAgentsTemplate}.
|
|
40
61
|
* Every field is optional; defaults preserve the documented production behavior.
|
|
41
62
|
*/
|
|
42
63
|
export interface ReadTemplateOptions {
|
|
43
64
|
/**
|
|
44
65
|
* Explicit Templates folder path (e.g. from `--templates-path`).
|
|
45
|
-
* When set,
|
|
46
|
-
*
|
|
66
|
+
* When set, ONLY this folder is consulted. If the path is invalid or the
|
|
67
|
+
* AGENTS body is missing there, the call throws.
|
|
47
68
|
*/
|
|
48
69
|
templatesPath?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Force-bypass the local cache and fetch from the mirror unconditionally
|
|
51
|
-
* (e.g. from `--refresh-templates`). Falls back to stale cache only if the
|
|
52
|
-
* mirror is unreachable.
|
|
53
|
-
*/
|
|
54
|
-
refreshTemplates?: boolean;
|
|
55
|
-
/** Override the mirror URL (tests). Default {@link MIRROR_URL}. */
|
|
56
|
-
mirrorUrl?: string;
|
|
57
|
-
/** Override the cache directory (tests). Default {@link CACHE_DIR}. */
|
|
58
|
-
cacheDir?: string;
|
|
59
|
-
/** Override the fetch implementation (tests). Default global `fetch`. */
|
|
60
|
-
fetchImpl?: typeof fetch;
|
|
61
|
-
/** Override the clock (tests). Default `() => Date.now()`. */
|
|
62
|
-
now?: () => number;
|
|
63
|
-
/** Where to write user-facing warnings (e.g. stale-cache fallback). */
|
|
70
|
+
/** Where to write user-facing warnings (e.g. the multiple-bodies notice). */
|
|
64
71
|
onWarn?: (message: string) => void;
|
|
65
|
-
/**
|
|
66
|
-
* Internal: force-skip the local-folder check (Step 2) and go straight to
|
|
67
|
-
* cache/mirror. Used by tests so the DEFAULT_TEMPLATES_PATH on the runner's
|
|
68
|
-
* machine doesn't short-circuit the fallback chain.
|
|
69
|
-
*/
|
|
70
|
-
skipLocalFolder?: boolean;
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* 1. Explicit `templatesPath` override → strict, no fallback
|
|
76
|
-
* 2. Local Templates folder at the default path → use it
|
|
77
|
-
* 3. Fresh local cache (mtime < 24h) → use it
|
|
78
|
-
* 4. Mirror fetch → cache + return
|
|
79
|
-
* 5. Stale local cache (with warning) → use it
|
|
80
|
-
* 6. Hard fail with `--templates-path <path>` hint
|
|
74
|
+
* Resolve the canonical AGENTS body for `kind`, returning the content, the
|
|
75
|
+
* version parsed from its filename, and the filename.
|
|
81
76
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* by an inconsistent local state.
|
|
77
|
+
* Local-folder only: an explicit `templatesPath` override, or the default
|
|
78
|
+
* location. Either way the filename is glob-discovered, then read fresh — so a
|
|
79
|
+
* canonical filename bump (AGENTS_v2.13.0 → v2.14.0) flows through with no code
|
|
80
|
+
* change. When no local folder is present the call hard-fails (via
|
|
81
|
+
* {@link resolveTemplatesPath}) with a `--templates-path` hint; the v0.2.0
|
|
82
|
+
* hosted-mirror fallback was retired 2026-06-23.
|
|
89
83
|
*/
|
|
90
|
-
export declare function
|
|
84
|
+
export declare function resolveAgentsTemplate(kind: AgentsKind, opts?: ReadTemplateOptions): Promise<{
|
|
91
85
|
content: string;
|
|
92
|
-
|
|
86
|
+
version: string;
|
|
87
|
+
name: string;
|
|
93
88
|
}>;
|
|
94
|
-
/**
|
|
95
|
-
* Fetches a single template file from the hosted mirror.
|
|
96
|
-
*
|
|
97
|
-
* @param name - the template file name (e.g. "AGENTS_v2.13.0.md",
|
|
98
|
-
* "Resources/README.md"). Path-traversal sequences are refused.
|
|
99
|
-
* @returns the file contents as a UTF-8 string.
|
|
100
|
-
* @throws TemplatesError on network failure, non-2xx response, or unsafe name.
|
|
101
|
-
*/
|
|
102
|
-
export declare function fetchFromMirror(name: string, opts?: Pick<ReadTemplateOptions, "mirrorUrl" | "fetchImpl">): Promise<string>;
|
package/dist/templates.js
CHANGED
|
@@ -9,24 +9,32 @@
|
|
|
9
9
|
// upstream Template version bumps (e.g. AGENTS_WP_v3.1.0 → v3.2.0) are
|
|
10
10
|
// picked up automatically.
|
|
11
11
|
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// the
|
|
12
|
+
// The CLI resolves Templates from the local folder ONLY — the default
|
|
13
|
+
// location (~/Desktop/Zero2Webmaster/AI/Templates) or an explicit
|
|
14
|
+
// --templates-path override. The v0.2.0 hosted-mirror fallback
|
|
15
|
+
// (templates.z2w.us + a 24h local cache) was RETIRED 2026-06-23 to protect
|
|
16
|
+
// the framework IP: the public mirror was taken down, so when no local
|
|
17
|
+
// Templates folder is present the CLI now hard-fails with a --templates-path
|
|
18
|
+
// hint rather than fetching over HTTP.
|
|
17
19
|
import { promises as fs } from "node:fs";
|
|
18
20
|
import * as path from "node:path";
|
|
19
21
|
import * as os from "node:os";
|
|
20
22
|
export const DEFAULT_TEMPLATES_PATH = path.join(os.homedir(), "Desktop", "Zero2Webmaster", "AI", "Templates");
|
|
21
|
-
export const REQUIRED_FILES = [
|
|
22
|
-
"AGENTS_v2.13.0.md",
|
|
23
|
-
"AGENTS_WP_v3.1.0.md",
|
|
24
|
-
];
|
|
25
23
|
export const REQUIRED_DIRECTORIES = ["Resources"];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Glob patterns for the two canonical AGENTS bodies in the Templates root.
|
|
26
|
+
* Strict 3-part semver so:
|
|
27
|
+
* - the `general` pattern never matches `AGENTS_WP_v…` (after `AGENTS_` comes
|
|
28
|
+
* `v`, not `WP_`); and
|
|
29
|
+
* - neither matches the historical 4-part typo `AGENTS_v2.0.0.0.md` (which is
|
|
30
|
+
* archived anyway).
|
|
31
|
+
* Discovering the body by glob is what lets a canonical filename bump
|
|
32
|
+
* (`AGENTS_v2.13.0.md` → `AGENTS_v2.14.0.md`) flow through with NO code change.
|
|
33
|
+
*/
|
|
34
|
+
export const AGENTS_FILE_RE = {
|
|
35
|
+
general: /^AGENTS_v(\d+)\.(\d+)\.(\d+)\.md$/,
|
|
36
|
+
wp: /^AGENTS_WP_v(\d+)\.(\d+)\.(\d+)\.md$/,
|
|
37
|
+
};
|
|
30
38
|
export class TemplatesError extends Error {
|
|
31
39
|
constructor(message) {
|
|
32
40
|
super(message);
|
|
@@ -42,15 +50,6 @@ async function isDirectory(p) {
|
|
|
42
50
|
return false;
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
|
-
async function isFile(p) {
|
|
46
|
-
try {
|
|
47
|
-
const stat = await fs.stat(p);
|
|
48
|
-
return stat.isFile();
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
53
|
/**
|
|
55
54
|
* Resolves the Templates folder path and verifies required entries are present.
|
|
56
55
|
*
|
|
@@ -75,21 +74,30 @@ export async function resolveTemplatesPath(override) {
|
|
|
75
74
|
`--templates-path <absolute-path> to point the CLI at an alternative location.`);
|
|
76
75
|
}
|
|
77
76
|
const missing = [];
|
|
78
|
-
for (const file of REQUIRED_FILES) {
|
|
79
|
-
if (!(await isFile(path.join(candidate, file)))) {
|
|
80
|
-
missing.push(file);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
77
|
for (const dir of REQUIRED_DIRECTORIES) {
|
|
84
78
|
if (!(await isDirectory(path.join(candidate, dir)))) {
|
|
85
79
|
missing.push(`${dir}/`);
|
|
86
80
|
}
|
|
87
81
|
}
|
|
82
|
+
// Require at least one general + one WP AGENTS body, discovered by glob rather
|
|
83
|
+
// than a pinned filename — so canonical version bumps don't trip this check.
|
|
84
|
+
let entries = [];
|
|
85
|
+
try {
|
|
86
|
+
entries = await fs.readdir(candidate);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Left as missing patterns below.
|
|
90
|
+
}
|
|
91
|
+
for (const kind of ["general", "wp"]) {
|
|
92
|
+
if (!entries.some((name) => AGENTS_FILE_RE[kind].test(name))) {
|
|
93
|
+
missing.push(`${AGENTS_FILE_RE[kind].source} (no match)`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
88
96
|
if (missing.length > 0) {
|
|
89
97
|
throw new TemplatesError(`Templates folder at ${candidate} is incomplete. Missing required ` +
|
|
90
98
|
`${missing.length === 1 ? "entry" : "entries"}: ${missing.join(", ")}.\n` +
|
|
91
|
-
`Expected
|
|
92
|
-
`
|
|
99
|
+
`Expected: a general AGENTS body (AGENTS_v*.md), a WordPress AGENTS body ` +
|
|
100
|
+
`(AGENTS_WP_v*.md), and the ${REQUIRED_DIRECTORIES.map((d) => `${d}/`).join(", ")} directory.`);
|
|
93
101
|
}
|
|
94
102
|
return candidate;
|
|
95
103
|
}
|
|
@@ -131,162 +139,87 @@ export async function readTemplate(name, templatesPath) {
|
|
|
131
139
|
throw new TemplatesError(`Failed to read template "${name}": ${err.message}`);
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
throw new TemplatesError(`readTemplateWithFallback() requires a non-empty name; got ${JSON.stringify(name)}.`);
|
|
155
|
-
}
|
|
156
|
-
// Step 1: explicit override → strict semantics (caller asked for this exact location).
|
|
157
|
-
if (opts.templatesPath) {
|
|
158
|
-
const content = await readTemplate(name, opts.templatesPath);
|
|
159
|
-
return { content, source: "local-folder" };
|
|
160
|
-
}
|
|
161
|
-
// Step 2: local Templates folder? (Skipped in tests via skipLocalFolder.)
|
|
162
|
-
if (!opts.skipLocalFolder) {
|
|
163
|
-
let localPath = null;
|
|
164
|
-
try {
|
|
165
|
-
localPath = await resolveTemplatesPath();
|
|
166
|
-
}
|
|
167
|
-
catch (err) {
|
|
168
|
-
if (!(err instanceof TemplatesError))
|
|
169
|
-
throw err;
|
|
170
|
-
// No (or incomplete) local folder — fall through to cache/mirror chain.
|
|
171
|
-
}
|
|
172
|
-
if (localPath) {
|
|
173
|
-
const content = await readTemplate(name, localPath);
|
|
174
|
-
return { content, source: "local-folder" };
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
const cacheDir = opts.cacheDir ?? CACHE_DIR;
|
|
178
|
-
const now = opts.now ?? Date.now;
|
|
179
|
-
const cached = opts.refreshTemplates
|
|
180
|
-
? null
|
|
181
|
-
: await readFromCache(name, cacheDir);
|
|
182
|
-
// Step 3: fresh cache hit?
|
|
183
|
-
if (cached && now() - cached.mtimeMs < CACHE_TTL_MS) {
|
|
184
|
-
return { content: cached.content, source: "fresh-cache" };
|
|
185
|
-
}
|
|
186
|
-
// Step 4: mirror fetch.
|
|
187
|
-
try {
|
|
188
|
-
const content = await fetchFromMirror(name, opts);
|
|
189
|
-
await writeToCache(name, content, cacheDir);
|
|
190
|
-
return { content, source: "mirror" };
|
|
191
|
-
}
|
|
192
|
-
catch (fetchErr) {
|
|
193
|
-
if (!(fetchErr instanceof TemplatesError))
|
|
194
|
-
throw fetchErr;
|
|
195
|
-
// Step 5: stale cache? (Either a stale cached copy, OR a cache we refused
|
|
196
|
-
// in Step 3 because --refresh-templates was set — both are usable
|
|
197
|
-
// now that the mirror is down.)
|
|
198
|
-
const fallbackCached = cached ?? (await readFromCache(name, cacheDir));
|
|
199
|
-
if (fallbackCached) {
|
|
200
|
-
const onWarn = opts.onWarn ?? defaultWarn;
|
|
201
|
-
onWarn(`⚠ Using stale cached copy of "${name}" — mirror fetch failed. ` +
|
|
202
|
-
`Run with --refresh-templates when network is restored.`);
|
|
203
|
-
return { content: fallbackCached.content, source: "stale-cache" };
|
|
204
|
-
}
|
|
205
|
-
// Step 6: hard fail.
|
|
206
|
-
const mirrorUrl = opts.mirrorUrl ?? MIRROR_URL;
|
|
207
|
-
throw new TemplatesError(`Cannot resolve template "${name}".\n` +
|
|
208
|
-
` • No local Templates folder at ${DEFAULT_TEMPLATES_PATH}\n` +
|
|
209
|
-
` • No cached copy at ${cacheDir}\n` +
|
|
210
|
-
` • Mirror at ${mirrorUrl} is unreachable: ${fetchErr.message}\n\n` +
|
|
211
|
-
`If you have a Templates folder elsewhere, pass --templates-path <absolute-path>.\n` +
|
|
212
|
-
`Otherwise restore your network connection and retry.`);
|
|
213
|
-
}
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// Canonical AGENTS body discovery (glob the version out of the filename)
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
/** Parse the `X.Y.Z` version out of a canonical AGENTS filename, or null. */
|
|
146
|
+
export function agentsVersionFromName(name) {
|
|
147
|
+
for (const kind of ["general", "wp"]) {
|
|
148
|
+
const m = name.match(AGENTS_FILE_RE[kind]);
|
|
149
|
+
if (m)
|
|
150
|
+
return `${m[1]}.${m[2]}.${m[3]}`;
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
function compareSemverDesc(a, b) {
|
|
155
|
+
const pa = a.split(".").map(Number);
|
|
156
|
+
const pb = b.split(".").map(Number);
|
|
157
|
+
for (let i = 0; i < 3; i++) {
|
|
158
|
+
if (pa[i] !== pb[i])
|
|
159
|
+
return pb[i] - pa[i]; // descending: highest first
|
|
160
|
+
}
|
|
161
|
+
return 0;
|
|
214
162
|
}
|
|
215
163
|
/**
|
|
216
|
-
*
|
|
164
|
+
* Discover the canonical AGENTS body for `kind` by globbing `root`.
|
|
217
165
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
166
|
+
* Archive-first discipline keeps exactly one match in the Templates root. If
|
|
167
|
+
* more than one is present (a missed archive), we WARN and pick the highest
|
|
168
|
+
* semver so the CLI keeps working rather than silently hiding the slip. Zero
|
|
169
|
+
* matches throws — the folder is incomplete or misnamed.
|
|
170
|
+
*
|
|
171
|
+
* @returns `{ name, version }` — the on-disk filename and the version parsed
|
|
172
|
+
* out of it (the single source of truth for `{{framework_version}}`).
|
|
222
173
|
*/
|
|
223
|
-
export async function
|
|
224
|
-
|
|
225
|
-
throw new TemplatesError(`fetchFromMirror() requires a non-empty name; got ${JSON.stringify(name)}.`);
|
|
226
|
-
}
|
|
227
|
-
if (name.startsWith("/") ||
|
|
228
|
-
name.includes("..") ||
|
|
229
|
-
name.startsWith("\\")) {
|
|
230
|
-
throw new TemplatesError(`Template name "${name}" contains path-traversal characters; refusing to fetch.`);
|
|
231
|
-
}
|
|
232
|
-
const mirrorUrl = (opts.mirrorUrl ?? MIRROR_URL).replace(/\/+$/, "");
|
|
233
|
-
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
234
|
-
if (typeof fetchImpl !== "function") {
|
|
235
|
-
throw new TemplatesError(`fetch() is not available in this runtime. Upgrade to Node 20+ or pass opts.fetchImpl.`);
|
|
236
|
-
}
|
|
237
|
-
const url = `${mirrorUrl}/${encodeURI(name)}`;
|
|
238
|
-
let response;
|
|
239
|
-
try {
|
|
240
|
-
response = await fetchImpl(url);
|
|
241
|
-
}
|
|
242
|
-
catch (err) {
|
|
243
|
-
throw new TemplatesError(`Failed to fetch "${name}" from mirror ${mirrorUrl}: ${err.message}`);
|
|
244
|
-
}
|
|
245
|
-
if (!response.ok) {
|
|
246
|
-
throw new TemplatesError(`Mirror returned ${response.status} ${response.statusText || ""} for "${name}" (${url}).`);
|
|
247
|
-
}
|
|
174
|
+
export async function discoverAgentsTemplate(root, kind, onWarn = defaultWarn) {
|
|
175
|
+
let entries;
|
|
248
176
|
try {
|
|
249
|
-
|
|
177
|
+
entries = await fs.readdir(root);
|
|
250
178
|
}
|
|
251
179
|
catch (err) {
|
|
252
|
-
throw new TemplatesError(`
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return null;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (cachePath === null) {
|
|
273
|
-
throw new TemplatesError(`Refusing to cache "${name}" — name resolves outside the cache directory.`);
|
|
274
|
-
}
|
|
275
|
-
await fs.mkdir(path.dirname(cachePath), { recursive: true });
|
|
276
|
-
await fs.writeFile(cachePath, content, "utf8");
|
|
180
|
+
throw new TemplatesError(`Cannot list Templates folder ${root}: ${err.message}`);
|
|
181
|
+
}
|
|
182
|
+
const re = AGENTS_FILE_RE[kind];
|
|
183
|
+
const matches = entries
|
|
184
|
+
.map((name) => {
|
|
185
|
+
const m = name.match(re);
|
|
186
|
+
return m ? { name, version: `${m[1]}.${m[2]}.${m[3]}` } : null;
|
|
187
|
+
})
|
|
188
|
+
.filter((x) => x !== null)
|
|
189
|
+
.sort((a, b) => compareSemverDesc(a.version, b.version));
|
|
190
|
+
if (matches.length === 0) {
|
|
191
|
+
throw new TemplatesError(`No ${kind === "wp" ? "WordPress" : "general"} AGENTS body found in ${root} ` +
|
|
192
|
+
`(expected a file matching ${re.source}). The Templates folder is incomplete or misnamed.`);
|
|
193
|
+
}
|
|
194
|
+
if (matches.length > 1) {
|
|
195
|
+
onWarn(`⚠ Multiple ${kind} AGENTS bodies in ${root}: ${matches.map((m) => m.name).join(", ")}. ` +
|
|
196
|
+
`Archive-first discipline expects exactly one — using the highest (${matches[0].name}). ` +
|
|
197
|
+
`Move superseded file(s) to Archives/.`);
|
|
198
|
+
}
|
|
199
|
+
return matches[0];
|
|
277
200
|
}
|
|
278
201
|
/**
|
|
279
|
-
*
|
|
280
|
-
*
|
|
202
|
+
* Resolve the canonical AGENTS body for `kind`, returning the content, the
|
|
203
|
+
* version parsed from its filename, and the filename.
|
|
204
|
+
*
|
|
205
|
+
* Local-folder only: an explicit `templatesPath` override, or the default
|
|
206
|
+
* location. Either way the filename is glob-discovered, then read fresh — so a
|
|
207
|
+
* canonical filename bump (AGENTS_v2.13.0 → v2.14.0) flows through with no code
|
|
208
|
+
* change. When no local folder is present the call hard-fails (via
|
|
209
|
+
* {@link resolveTemplatesPath}) with a `--templates-path` hint; the v0.2.0
|
|
210
|
+
* hosted-mirror fallback was retired 2026-06-23.
|
|
281
211
|
*/
|
|
282
|
-
function
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
212
|
+
export async function resolveAgentsTemplate(kind, opts = {}) {
|
|
213
|
+
// An explicit override skips the Resources/ completeness check (the caller
|
|
214
|
+
// pointed us at this exact folder); the default location is verified by
|
|
215
|
+
// resolveTemplatesPath(), which throws the actionable --templates-path hint
|
|
216
|
+
// when nothing is there.
|
|
217
|
+
const localRoot = opts.templatesPath
|
|
218
|
+
? path.resolve(opts.templatesPath)
|
|
219
|
+
: await resolveTemplatesPath();
|
|
220
|
+
const { name, version } = await discoverAgentsTemplate(localRoot, kind, opts.onWarn);
|
|
221
|
+
const content = await readTemplate(name, localRoot);
|
|
222
|
+
return { content, version, name };
|
|
290
223
|
}
|
|
291
224
|
function defaultWarn(message) {
|
|
292
225
|
// eslint-disable-next-line no-console
|
package/dist/with-init.d.ts
CHANGED
|
@@ -10,7 +10,23 @@ export declare class WithInitError extends Error {
|
|
|
10
10
|
constructor(message: string);
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Build the repo's GitHub `--description` (the "About" blurb). Prefers the
|
|
14
|
+
* brief's Purpose section when scaffolding from a brief, else the project
|
|
15
|
+
* description. Collapses whitespace/newlines to a single line and caps the
|
|
16
|
+
* length so a multi-paragraph Purpose doesn't become an unwieldy blurb.
|
|
17
|
+
* Returns `null` when there's nothing meaningful to set.
|
|
18
|
+
*/
|
|
19
|
+
export declare function repoDescription(inputs: ScaffoldInputs): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Build the repo's GitHub topics: the project type plus the brand preset
|
|
22
|
+
* (skipping `custom`, which isn't a meaningful public topic). Lowercased,
|
|
23
|
+
* de-duplicated, and order-stable. Topic strings from the enums are already
|
|
24
|
+
* GitHub-legal (lowercase, hyphenated).
|
|
25
|
+
*/
|
|
26
|
+
export declare function repoTopics(inputs: ScaffoldInputs): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Runs the post-scaffold git + gh chain that creates the private GitHub repo.
|
|
29
|
+
* THROWS {@link WithInitError} on a hard failure; the caller decides whether to
|
|
30
|
+
* warn-and-proceed (it does — see src/cli.ts).
|
|
15
31
|
*/
|
|
16
32
|
export declare function runWithInit(inputs: ScaffoldInputs, targetPath: string, opts?: WithInitOptions): Promise<void>;
|