@tideworthy/tidysites 0.1.24 → 0.1.25
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 +4 -0
- package/bin/tidysites.mjs +57 -10
- package/lib/folder.mjs +18 -0
- package/package.json +1 -1
- package/skill/SKILL.md +4 -0
package/README.md
CHANGED
|
@@ -96,6 +96,10 @@ names its own in `header_row`.
|
|
|
96
96
|
5. The look: brand colours and fonts on the Business record, `business/business.css` for what the tokens cannot say. The theme's own rules are written as `.ts.ts-accent` and `.ts.ts-ink .ts-prose a`, so a rule of yours needs the same weight (`.ts.ts-accent …`) to win.
|
|
97
97
|
6. `tidysites validate`, `tidysites push`, `tidysites shot / --all`, and look at every width: a design often shows a different header above 1440px.
|
|
98
98
|
|
|
99
|
+
## The website's own instructions
|
|
100
|
+
|
|
101
|
+
A website can carry standing instructions from the partner on how it is done. `pull` (and `init`) write them into `AGENTS.md` in the folder, with a `CLAUDE.md` that imports it (`@AGENTS.md`), and keep their version in `.tidysites/snapshot.json`. Both land as a marked block (`<!-- tidysites:instructions -->`), so a file you already keep under either name stays yours: the block is appended to it, replaced in place on every pull, and taken out when the website has no instructions. Read them before changing anything. `push`, `redirect`, and `publish` send that version with the change; when the website's instructions changed since the last pull, they stop and say to pull again. A website with no instructions gets no files, and ours are taken away on the pull that finds them gone (CLAUDE.md only while it is still the one line we wrote).
|
|
102
|
+
|
|
99
103
|
## The skill
|
|
100
104
|
|
|
101
105
|
`skill/SKILL.md` is the Working with Tidysites skill: how a site is put together, where every setting lives, the order to port or build, and this command line's part in it. It is the one copy. The connector serves it as `get_tidysite_skill`, the platform app imports it from this package, and `tidysites skill` writes it into a project. A change to a command here, to the content model, or to where a setting lives on the template edits `skill/SKILL.md` in the same pull request, and ships with the next `cli-v*` tag.
|
package/bin/tidysites.mjs
CHANGED
|
@@ -23,11 +23,16 @@
|
|
|
23
23
|
* The site is the remote: pull, edit, push. A push that would overwrite an
|
|
24
24
|
* entry changed on the website since the pull is refused until you pull
|
|
25
25
|
* again (or say --force).
|
|
26
|
+
*
|
|
27
|
+
* A website's own instructions (the partner's standing word on how the
|
|
28
|
+
* site is done) come down with the pull as AGENTS.md, with a CLAUDE.md that
|
|
29
|
+
* imports it. Read them first. Every change sends their version back, and
|
|
30
|
+
* a push is refused when they changed since the last pull.
|
|
26
31
|
*/
|
|
27
32
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
28
33
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
29
34
|
import { callTool, ApiError } from '../lib/api.mjs';
|
|
30
|
-
import { diffEntries, entryToFiles, filesToEntry, FILE_NAME, menuItems, menuTree, pushDocument, sameEntry, snapshotOf, SIDECARS, splitDocument, documentWeight, mergePushResults } from '../lib/folder.mjs';
|
|
35
|
+
import { diffEntries, entryToFiles, filesToEntry, FILE_NAME, menuItems, menuTree, pushDocument, sameEntry, snapshotOf, SIDECARS, splitDocument, documentWeight, mergePushResults, withBlock, CLAUDE_LINE } from '../lib/folder.mjs';
|
|
31
36
|
import { validateAll, indexSchema, validateMenuNames } from '../lib/validate.mjs';
|
|
32
37
|
import { cleanHtml, cssSummary, fetchPage, outline, outlineText } from '../lib/fetch.mjs';
|
|
33
38
|
|
|
@@ -184,9 +189,10 @@ async function pull({ dir, cfg }, collections = null, { overwrite = new Set(), m
|
|
|
184
189
|
await pullMenus({ dir, cfg });
|
|
185
190
|
return;
|
|
186
191
|
}
|
|
187
|
-
const [{ json: doc }, { json: schema }] = await Promise.all([
|
|
192
|
+
const [{ json: doc }, { json: schema }, { json: site }] = await Promise.all([
|
|
188
193
|
tool(cfg, 'pull_website', { site_id: cfg.site, ...(want ? { collections: want.join(',') } : {}) }),
|
|
189
|
-
tool(cfg, 'get_website_schema', { site_id: cfg.site })
|
|
194
|
+
tool(cfg, 'get_website_schema', { site_id: cfg.site }),
|
|
195
|
+
tool(cfg, 'get_website', { site_id: cfg.site })
|
|
190
196
|
]);
|
|
191
197
|
if (!doc?.content) fail('The pull came back without content.');
|
|
192
198
|
const pulled = new Set(doc.collections.map((c) => c.slug));
|
|
@@ -248,6 +254,10 @@ async function pull({ dir, cfg }, collections = null, { overwrite = new Set(), m
|
|
|
248
254
|
snap.settings = prev.settings;
|
|
249
255
|
snap.collections = [...new Set([...(prev.collections ?? []), ...snap.collections])];
|
|
250
256
|
}
|
|
257
|
+
// The website's own instructions: the words as AGENTS.md, their version in the snapshot for every change to carry.
|
|
258
|
+
const instructions = site?.website?.instructions ?? null;
|
|
259
|
+
snap.instructions_version = site?.website?.instructions_version ?? null;
|
|
260
|
+
const hadInstructions = writeInstructions(dir, instructions);
|
|
251
261
|
writeFileSync(join(dir, META, 'snapshot.json'), JSON.stringify(snap, null, '\t'));
|
|
252
262
|
writeFileSync(join(dir, META, 'schema.json'), JSON.stringify(schema, null, '\t'));
|
|
253
263
|
const n = doc.collections.reduce((a, c) => a + c.count, 0);
|
|
@@ -255,6 +265,7 @@ async function pull({ dir, cfg }, collections = null, { overwrite = new Set(), m
|
|
|
255
265
|
for (const c of doc.collections.filter((c) => c.count)) say(` ${c.slug.padEnd(20)} ${c.count}`);
|
|
256
266
|
if (snap.menus) say(` ${'menus'.padEnd(20)} ${Object.keys(snap.menus).length}`);
|
|
257
267
|
for (const k of kept) say(` kept your unpushed changes in ${k}`);
|
|
268
|
+
if (hadInstructions) say(` AGENTS.md: the website's own instructions${prev && prev.instructions_version !== snap.instructions_version ? ' (changed since the last pull)' : ''}; read them before changing anything`);
|
|
258
269
|
if (heldBack.length) say(` ${heldBack.length} entr${heldBack.length === 1 ? 'y' : 'ies'} you removed here stay removed (the website still has them until \`push --prune\`)`);
|
|
259
270
|
}
|
|
260
271
|
|
|
@@ -326,6 +337,7 @@ async function push(ctx) {
|
|
|
326
337
|
say('Nothing to push.');
|
|
327
338
|
return;
|
|
328
339
|
}
|
|
340
|
+
await requireCurrentInstructions(ctx);
|
|
329
341
|
const doc = pushDocument(s.local, s.snap, { keys, removeKeys });
|
|
330
342
|
if (flags.force) doc.force = true;
|
|
331
343
|
// A picture that exists only as a file here (an illustration drawn from the old page's inline SVG, a rasterised
|
|
@@ -346,7 +358,7 @@ async function push(ctx) {
|
|
|
346
358
|
const parts = splitDocument(doc);
|
|
347
359
|
if (parts.length > 1) say(`${parts.length} parts: the folder's pictures and videos weigh ${(documentWeight(doc) / 1048576).toFixed(0)} MB.`);
|
|
348
360
|
for (const [i, part] of parts.entries()) {
|
|
349
|
-
const { json } = await callTool(ctx.cfg, 'push_website', { site_id: ctx.cfg.site, ...part });
|
|
361
|
+
const { json } = await callTool(ctx.cfg, 'push_website', { site_id: ctx.cfg.site, ...stamp(ctx), ...part });
|
|
350
362
|
if (!json || typeof json !== 'object' || !json.content) throw new ApiError(`The website did not answer the push${parts.length > 1 ? ` (part ${i + 1} of ${parts.length})` : ''} in time or in a readable way`, { status: 504 });
|
|
351
363
|
r = r ? mergePushResults(r, json) : json;
|
|
352
364
|
}
|
|
@@ -376,13 +388,13 @@ async function push(ctx) {
|
|
|
376
388
|
}
|
|
377
389
|
try {
|
|
378
390
|
try {
|
|
379
|
-
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items } }, { throws: true });
|
|
391
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items }, ...stamp(ctx) }, { throws: true });
|
|
380
392
|
} catch (e) {
|
|
381
393
|
// A menu the website does not have yet (a phone drawer, a footer column) is created from the file, then filled.
|
|
382
394
|
if (!/not.?found/i.test(e.message ?? '')) throw e;
|
|
383
395
|
if (!/^[a-z][a-z0-9_]*$/.test(name)) throw new Error(`a new menu's name is lowercase letters, digits and underscores (${name} has something else)`);
|
|
384
|
-
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_create', arguments: { name, label: m.label || name } }, { throws: true });
|
|
385
|
-
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items } }, { throws: true });
|
|
396
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_create', arguments: { name, label: m.label || name }, ...stamp(ctx) }, { throws: true });
|
|
397
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items }, ...stamp(ctx) }, { throws: true });
|
|
386
398
|
say(`Menu ${name}: created.`);
|
|
387
399
|
}
|
|
388
400
|
say(`Menu ${name}: ${items.length} item${items.length === 1 ? '' : 's'} written.`);
|
|
@@ -533,7 +545,8 @@ async function redirect(ctx) {
|
|
|
533
545
|
if (sub === 'add') {
|
|
534
546
|
const [, from, to] = positional;
|
|
535
547
|
if (!from || !to) fail('Usage: tidysites redirect add <old path> <new path or url>');
|
|
536
|
-
|
|
548
|
+
await requireCurrentInstructions(ctx);
|
|
549
|
+
const { json } = await tool(ctx.cfg, 'add_website_redirect', { site_id: ctx.cfg.site, source: from, destination: to, ...stamp(ctx) });
|
|
537
550
|
say(json ? `${from} → ${to}` : 'Added.');
|
|
538
551
|
return;
|
|
539
552
|
}
|
|
@@ -544,7 +557,8 @@ async function redirect(ctx) {
|
|
|
544
557
|
const rows = list?.redirects ?? list?.items ?? [];
|
|
545
558
|
const hit = rows.find((r) => (r.source ?? r.from) === from || (r.source ?? r.from) === from.replace(/\/$/, '') || (r.source ?? r.from) === `${from}/`);
|
|
546
559
|
if (!hit) fail(`No redirect from ${from}.`);
|
|
547
|
-
await
|
|
560
|
+
await requireCurrentInstructions(ctx);
|
|
561
|
+
await tool(ctx.cfg, 'remove_website_redirect', { site_id: ctx.cfg.site, redirect_id: hit.id, ...stamp(ctx) });
|
|
548
562
|
say(`Removed ${from}.`);
|
|
549
563
|
return;
|
|
550
564
|
}
|
|
@@ -683,10 +697,42 @@ function readRemoved(dir) { return new Set(readJson(join(dir, META, REMOVED_FILE
|
|
|
683
697
|
function writeRemoved(dir, set) { writeFileSync(join(dir, META, REMOVED_FILE), JSON.stringify([...set].sort(), null, '\t')); }
|
|
684
698
|
function rememberRemoved(dir, key) { const s = readRemoved(dir); s.add(key); writeRemoved(dir, s); }
|
|
685
699
|
|
|
700
|
+
/**
|
|
701
|
+
* The website's own instructions as files. AGENTS.md is the file every assistant working in a folder opens
|
|
702
|
+
* first, and CLAUDE.md is the one Claude Code reads; a person may already keep either. So the words live in a
|
|
703
|
+
* marked block: the whole file when there was none, appended to theirs when there was, replaced in place on
|
|
704
|
+
* every pull, and taken out again (the file too, when nothing else is in it) once the website has none.
|
|
705
|
+
*/
|
|
706
|
+
function writeManaged(path, body) {
|
|
707
|
+
const existing = existsSync(path) ? readFileSync(path, 'utf8') : null;
|
|
708
|
+
const next = withBlock(existing, body);
|
|
709
|
+
if (next === null) { if (existing !== null) rmSync(path); return; }
|
|
710
|
+
if (next !== existing) writeFileSync(path, next);
|
|
711
|
+
}
|
|
712
|
+
function writeInstructions(dir, text) {
|
|
713
|
+
const has = Boolean(text && text.trim());
|
|
714
|
+
writeManaged(join(dir, 'AGENTS.md'), has ? text.replace(/\s+$/, '') : null);
|
|
715
|
+
writeManaged(join(dir, 'CLAUDE.md'), has ? CLAUDE_LINE : null);
|
|
716
|
+
return has;
|
|
717
|
+
}
|
|
718
|
+
/** The version of the instructions the folder last pulled, sent with every change as proof they were read. */
|
|
719
|
+
function stamp({ dir }) {
|
|
720
|
+
const v = readJson(join(dir, META, 'snapshot.json'))?.instructions_version;
|
|
721
|
+
return v ? { instructions_version: v } : {};
|
|
722
|
+
}
|
|
723
|
+
/** Before a change: the website's instructions must be the ones this folder pulled. */
|
|
724
|
+
async function requireCurrentInstructions(ctx) {
|
|
725
|
+
const { json } = await tool(ctx.cfg, 'get_website', { site_id: ctx.cfg.site });
|
|
726
|
+
const theirs = json?.website?.instructions_version ?? null;
|
|
727
|
+
const mine = readJson(join(ctx.dir, META, 'snapshot.json'))?.instructions_version ?? null;
|
|
728
|
+
if (theirs !== mine) fail("The website's instructions changed since the last pull. Run `tidysites pull`, read AGENTS.md, then try again.");
|
|
729
|
+
}
|
|
730
|
+
|
|
686
731
|
async function publish(ctx) {
|
|
687
732
|
if (!flags.yes) fail('Publishing makes the live site a copy of the preview site. Look at it first (`tidysites shot /`), then run `tidysites publish --yes`.');
|
|
688
733
|
// A website live on the client's own domain is never published from here: the website refuses (409 live_domain) and says who may.
|
|
689
|
-
|
|
734
|
+
await requireCurrentInstructions(ctx);
|
|
735
|
+
const { json, text } = await tool(ctx.cfg, 'publish_website', { site_id: ctx.cfg.site, ...stamp(ctx) });
|
|
690
736
|
say(json ? JSON.stringify(json, null, 2) : text);
|
|
691
737
|
}
|
|
692
738
|
|
|
@@ -722,6 +768,7 @@ async function main() {
|
|
|
722
768
|
writeFileSync(join(dir, META, 'key'), `${key}\n`, { mode: 0o600 });
|
|
723
769
|
writeFileSync(join(dir, META, '.gitignore'), 'key\nshots/\nsource/\npages/\n');
|
|
724
770
|
say(`Connected ${relative(process.cwd(), dir) || '.'} to ${site} on ${host}.`);
|
|
771
|
+
// The pull below writes AGENTS.md when the website carries its own instructions, and says so.
|
|
725
772
|
// A website that is still being set up answers 404 on its content model for a few minutes; the first pull waits for it.
|
|
726
773
|
for (let attempt = 1; ; attempt++) {
|
|
727
774
|
try { await pull(config()); break; }
|
package/lib/folder.mjs
CHANGED
|
@@ -264,3 +264,21 @@ export function splitDocument(doc) {
|
|
|
264
264
|
export function mergePushResults(a, b) {
|
|
265
265
|
return { ...a, ...b, content: { created: (a.content?.created ?? 0) + (b.content?.created ?? 0), updated: (a.content?.updated ?? 0) + (b.content?.updated ?? 0) }, images: (a.images ?? 0) + (b.images ?? 0), images_reused: (a.images_reused ?? 0) + (b.images_reused ?? 0), missing: [...(a.missing ?? []), ...(b.missing ?? [])] };
|
|
266
266
|
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The website's own instructions inside a file a person may already keep (AGENTS.md, CLAUDE.md): a marked
|
|
270
|
+
* block, the whole file when there was none, appended to theirs when there was, replaced in place on every
|
|
271
|
+
* pull. `body` null takes the block out; the result is null when nothing else was in the file.
|
|
272
|
+
*/
|
|
273
|
+
export const BLOCK_START = "<!-- tidysites:instructions (the website's own instructions; rewritten on every pull, edit them in the app) -->";
|
|
274
|
+
export const BLOCK_END = '<!-- /tidysites:instructions -->';
|
|
275
|
+
/** The one line Claude Code needs in CLAUDE.md to read AGENTS.md. */
|
|
276
|
+
export const CLAUDE_LINE = '@AGENTS.md';
|
|
277
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
278
|
+
const BLOCK_RE = new RegExp(`\\n*${escapeRe(BLOCK_START)}[\\s\\S]*?${escapeRe(BLOCK_END)}\\n*`);
|
|
279
|
+
export function withBlock(existing, body) {
|
|
280
|
+
const rest = (existing ?? '').replace(BLOCK_RE, '\n').trim();
|
|
281
|
+
if (body === null) return rest ? `${rest}\n` : null;
|
|
282
|
+
const block = `${BLOCK_START}\n${body.trim()}\n${BLOCK_END}`;
|
|
283
|
+
return rest ? `${rest}\n\n${block}\n` : `${block}\n`;
|
|
284
|
+
}
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -11,6 +11,10 @@ A Tidysite is a template (the data shape every site shares), a theme (the look),
|
|
|
11
11
|
|
|
12
12
|
Content work happens on the preview site. The live site changes only when `publish_website` runs or a person presses Publish now.
|
|
13
13
|
|
|
14
|
+
## The website's own instructions
|
|
15
|
+
|
|
16
|
+
A website can carry standing instructions from the partner: what never changes, how the copy reads, which pages are theirs to keep. They say how this site is done; this document says how Tidysites works. In a folder connected with the command line they are `AGENTS.md` (CLAUDE.md imports it), pulled with the content; read them before the first change. Every change the command line makes sends their version, and a push is refused when they changed since the last pull (pull again, read AGENTS.md). Through the connector, `get_website` returns them as `instructions` with an `instructions_version`, and every tool that changes the site takes that version back as `instructions_version`.
|
|
17
|
+
|
|
14
18
|
## The three layers
|
|
15
19
|
|
|
16
20
|
1. **Records.** The things with a page of their own or reused across pages: the Business record, Locations, Services and Service categories, Service areas, Audiences (who a service is for), People, Posts, Products, Case studies, Pages, Forms, Custom rows, Saved sections, and the FAQs and Reviews when they are shared. Logos, insurers, financing providers, technologies, conditions, policies, downloads, offers and badges are written in their section as items; a collection of them exists only for the shared case. Read and write them with `list_website_content`, `get_website_entry`, `create_website_entry`, `update_website_entry`, `edit_website_section` and `replace_website_text`.
|