@marvalt/digivalt-mcp 0.0.0-stage → 0.4.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +674 -0
  3. package/README.md +66 -3
  4. package/dist/audit.d.ts +24 -0
  5. package/dist/audit.js +34 -0
  6. package/dist/audit.js.map +1 -0
  7. package/dist/blocks/serialize.d.ts +15 -0
  8. package/dist/blocks/serialize.js +231 -0
  9. package/dist/blocks/serialize.js.map +1 -0
  10. package/dist/catalogue/blocks.d.ts +17 -0
  11. package/dist/catalogue/blocks.js +37 -0
  12. package/dist/catalogue/blocks.js.map +1 -0
  13. package/dist/catalogue/shortcodes.d.ts +49 -0
  14. package/dist/catalogue/shortcodes.js +384 -0
  15. package/dist/catalogue/shortcodes.js.map +1 -0
  16. package/dist/cli.d.ts +2 -0
  17. package/dist/cli.js +57 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/config.d.ts +43 -0
  20. package/dist/config.js +131 -0
  21. package/dist/config.js.map +1 -0
  22. package/dist/index.d.ts +9 -0
  23. package/dist/index.js +8 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/media.d.ts +26 -0
  26. package/dist/media.js +118 -0
  27. package/dist/media.js.map +1 -0
  28. package/dist/publish.d.ts +32 -0
  29. package/dist/publish.js +74 -0
  30. package/dist/publish.js.map +1 -0
  31. package/dist/refresh.d.ts +30 -0
  32. package/dist/refresh.js +93 -0
  33. package/dist/refresh.js.map +1 -0
  34. package/dist/resources/guides.d.ts +2 -0
  35. package/dist/resources/guides.js +51 -0
  36. package/dist/resources/guides.js.map +1 -0
  37. package/dist/server.d.ts +19 -0
  38. package/dist/server.js +522 -0
  39. package/dist/server.js.map +1 -0
  40. package/dist/validate/local.d.ts +17 -0
  41. package/dist/validate/local.js +75 -0
  42. package/dist/validate/local.js.map +1 -0
  43. package/dist/version.d.ts +3 -0
  44. package/dist/version.js +4 -0
  45. package/dist/version.js.map +1 -0
  46. package/dist/wp-client.d.ts +31 -0
  47. package/dist/wp-client.js +94 -0
  48. package/dist/wp-client.js.map +1 -0
  49. package/docs/README.md +98 -0
  50. package/docs/SECURITY.md +40 -0
  51. package/package.json +48 -4
@@ -0,0 +1,9 @@
1
+ export { createServer } from './server.js';
2
+ export { readConfig, loadEnvFiles, normalizeWpUrl } from './config.js';
3
+ export type { Config } from './config.js';
4
+ export { WpClient, WpError } from './wp-client.js';
5
+ export { validateLocal } from './validate/local.js';
6
+ export type { LocalIssue, LocalResult } from './validate/local.js';
7
+ export { BLOCKS, UNRENDERED_HINTS } from './catalogue/blocks.js';
8
+ export { SHORTCODES, findShortcodes, checkShortcode } from './catalogue/shortcodes.js';
9
+ export { VERSION, PACKAGE_NAME } from './version.js';
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { createServer } from './server.js';
2
+ export { readConfig, loadEnvFiles, normalizeWpUrl } from './config.js';
3
+ export { WpClient, WpError } from './wp-client.js';
4
+ export { validateLocal } from './validate/local.js';
5
+ export { BLOCKS, UNRENDERED_HINTS } from './catalogue/blocks.js';
6
+ export { SHORTCODES, findShortcodes, checkShortcode } from './catalogue/shortcodes.js';
7
+ export { VERSION, PACKAGE_NAME } from './version.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,26 @@
1
+ export interface MediaLimits {
2
+ maxBytes: number;
3
+ maxWidth: number;
4
+ maxHeight: number;
5
+ }
6
+ export declare const DEFAULT_LIMITS: MediaLimits;
7
+ export interface ImageInfo {
8
+ mime: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp' | 'image/avif';
9
+ width: number;
10
+ height: number;
11
+ }
12
+ export declare class MediaError extends Error {
13
+ readonly code: string;
14
+ constructor(code: string, message: string);
15
+ }
16
+ /** Identify an image from its bytes (never from the file name) and read its pixel size. */
17
+ export declare function inspectImage(b: Buffer): ImageInfo;
18
+ export interface PreparedUpload {
19
+ filename: string;
20
+ base64: string;
21
+ sha256: string;
22
+ bytes: number;
23
+ info: ImageInfo;
24
+ }
25
+ /** Read a local file and check type, size and dimensions before anything is sent. */
26
+ export declare function prepareUpload(path: string, alt: string, limits?: MediaLimits): Promise<PreparedUpload>;
package/dist/media.js ADDED
@@ -0,0 +1,118 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFile, stat } from 'node:fs/promises';
3
+ import { basename, extname } from 'node:path';
4
+ export const DEFAULT_LIMITS = { maxBytes: 12 * 1024 * 1024, maxWidth: 3840, maxHeight: 2160 };
5
+ export class MediaError extends Error {
6
+ code;
7
+ constructor(code, message) {
8
+ super(message);
9
+ this.code = code;
10
+ this.name = 'MediaError';
11
+ }
12
+ }
13
+ function jpegSize(b) {
14
+ let i = 2;
15
+ while (i + 9 < b.length) {
16
+ if (b[i] !== 0xff) {
17
+ i += 1;
18
+ continue;
19
+ }
20
+ const marker = b[i + 1];
21
+ if (marker === 0xff) {
22
+ i += 1;
23
+ continue;
24
+ }
25
+ if (marker >= 0xc0 && marker <= 0xcf && ![0xc4, 0xc8, 0xcc].includes(marker)) {
26
+ return { height: b.readUInt16BE(i + 5), width: b.readUInt16BE(i + 7) };
27
+ }
28
+ if (marker === 0xd8 || (marker >= 0xd0 && marker <= 0xd7) || marker === 0x01) {
29
+ i += 2;
30
+ continue;
31
+ }
32
+ i += 2 + b.readUInt16BE(i + 2);
33
+ }
34
+ return null;
35
+ }
36
+ function webpSize(b) {
37
+ const kind = b.toString('ascii', 12, 16);
38
+ if (kind === 'VP8X')
39
+ return { width: 1 + b.readUIntLE(24, 3), height: 1 + b.readUIntLE(27, 3) };
40
+ if (kind === 'VP8L') {
41
+ const bits = b.readUInt32LE(21);
42
+ return { width: 1 + (bits & 0x3fff), height: 1 + ((bits >> 14) & 0x3fff) };
43
+ }
44
+ if (kind === 'VP8 ')
45
+ return { width: b.readUInt16LE(26) & 0x3fff, height: b.readUInt16LE(28) & 0x3fff };
46
+ return null;
47
+ }
48
+ function avifSize(b) {
49
+ const at = b.indexOf('ispe', 0, 'ascii');
50
+ if (at < 0 || at + 16 > b.length)
51
+ return null;
52
+ return { width: b.readUInt32BE(at + 8), height: b.readUInt32BE(at + 12) };
53
+ }
54
+ /** Identify an image from its bytes (never from the file name) and read its pixel size. */
55
+ export function inspectImage(b) {
56
+ let mime = null;
57
+ let size = null;
58
+ if (b.length > 24 && b[0] === 0x89 && b.toString('ascii', 1, 4) === 'PNG') {
59
+ mime = 'image/png';
60
+ size = { width: b.readUInt32BE(16), height: b.readUInt32BE(20) };
61
+ }
62
+ else if (b.length > 4 && b[0] === 0xff && b[1] === 0xd8) {
63
+ mime = 'image/jpeg';
64
+ size = jpegSize(b);
65
+ }
66
+ else if (b.length > 10 && b.toString('ascii', 0, 3) === 'GIF') {
67
+ mime = 'image/gif';
68
+ size = { width: b.readUInt16LE(6), height: b.readUInt16LE(8) };
69
+ }
70
+ else if (b.length > 30 && b.toString('ascii', 0, 4) === 'RIFF' && b.toString('ascii', 8, 12) === 'WEBP') {
71
+ mime = 'image/webp';
72
+ size = webpSize(b);
73
+ }
74
+ else if (b.length > 16 && b.toString('ascii', 4, 8) === 'ftyp' && /avif|avis/.test(b.toString('ascii', 8, 32))) {
75
+ mime = 'image/avif';
76
+ size = avifSize(b);
77
+ }
78
+ else if (/^\s*(<\?xml|<svg)/i.test(b.toString('utf8', 0, 200))) {
79
+ throw new MediaError('MEDIA_TYPE', 'SVG uploads are not allowed. Use PNG, JPEG, GIF, WebP or AVIF.');
80
+ }
81
+ if (!mime)
82
+ throw new MediaError('MEDIA_TYPE', 'Unsupported file. Use PNG, JPEG, GIF, WebP or AVIF.');
83
+ if (!size || !size.width || !size.height)
84
+ throw new MediaError('MEDIA_CORRUPT', 'Could not read the image dimensions; the file may be corrupt.');
85
+ return { mime, ...size };
86
+ }
87
+ /** Read a local file and check type, size and dimensions before anything is sent. */
88
+ export async function prepareUpload(path, alt, limits = DEFAULT_LIMITS) {
89
+ if (!alt || !alt.trim())
90
+ throw new MediaError('MEDIA_ALT', 'alt text is required.');
91
+ let st;
92
+ try {
93
+ st = await stat(path);
94
+ }
95
+ catch {
96
+ throw new MediaError('MEDIA_NOT_FOUND', `File not found: ${path}`);
97
+ }
98
+ if (!st.isFile())
99
+ throw new MediaError('MEDIA_NOT_FOUND', `Not a file: ${path}`);
100
+ if (st.size > limits.maxBytes) {
101
+ throw new MediaError('MEDIA_TOO_LARGE', `File is ${(st.size / 1048576).toFixed(1)} MB; the limit is ${(limits.maxBytes / 1048576).toFixed(0)} MB.`);
102
+ }
103
+ const bytes = await readFile(path);
104
+ const info = inspectImage(bytes);
105
+ if (info.width > limits.maxWidth || info.height > limits.maxHeight) {
106
+ throw new MediaError('MEDIA_DIMENSIONS', `Image is ${info.width}x${info.height}; the limit is ${limits.maxWidth}x${limits.maxHeight}. Resize it first.`);
107
+ }
108
+ const ext = extname(path).toLowerCase() || `.${info.mime.split('/')[1].replace('jpeg', 'jpg')}`;
109
+ const stem = basename(path, extname(path)).replace(/[^\w.-]+/g, '-').replace(/^-+|-+$/g, '') || 'image';
110
+ return {
111
+ filename: `${stem}${ext}`,
112
+ base64: bytes.toString('base64'),
113
+ sha256: createHash('sha256').update(bytes).digest('hex'),
114
+ bytes: bytes.length,
115
+ info,
116
+ };
117
+ }
118
+ //# sourceMappingURL=media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQ9C,MAAM,CAAC,MAAM,cAAc,GAAgB,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAQ3G,MAAM,OAAO,UAAW,SAAQ,KAAK;IAEjB,IAAI;IADtB,YACkB,IAAY,EAC5B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;oBAHC,IAAI;QAIpB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,CAAS;IACzB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAClB,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACxB,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,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,MAAM,CAAC,SAAS,EAAE,CAAC;QACnE,MAAM,IAAI,UAAU,CAClB,kBAAkB,EAClB,YAAY,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,kBAAkB,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS,oBAAoB,CAC/G,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IAChG,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC;IACxG,OAAO;QACL,QAAQ,EAAE,GAAG,IAAI,GAAG,GAAG,EAAE;QACzB,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAChC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACxD,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,IAAI;KACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,32 @@
1
+ /** Sliding-window budget for write-type calls. Reads are not counted. */
2
+ export declare class WriteBudget {
3
+ private readonly max;
4
+ private readonly windowMs;
5
+ private readonly now;
6
+ private stamps;
7
+ constructor(max: number, windowMs: number, now?: () => number);
8
+ take(): void;
9
+ }
10
+ export declare const MAX_CONTENT_BYTES = 500000;
11
+ export declare const MAX_BLOCK_DEPTH = 12;
12
+ /** Local size and nesting caps, applied before any request. */
13
+ export declare function checkContentLimits(markup: string): void;
14
+ export interface Plan {
15
+ action: 'promote' | 'publish' | 'rollback';
16
+ post_id: number;
17
+ /** Everything the person is asked to approve. Hashed to bind an approval to exactly this plan. */
18
+ summary: unknown;
19
+ options: Record<string, unknown>;
20
+ }
21
+ export declare function planHash(plan: Plan): string;
22
+ /** Single-use approval codes, bound to one plan and short-lived. */
23
+ export declare class ApprovalCodes {
24
+ private readonly ttlMs;
25
+ private readonly now;
26
+ private pending;
27
+ constructor(ttlMs?: number, now?: () => number);
28
+ issue(hash: string): string;
29
+ /** Consumes the code whether or not it matches, so a code cannot be guessed repeatedly. */
30
+ redeem(code: string, hash: string): boolean;
31
+ }
32
+ export declare function describePlan(plan: Plan): string;
@@ -0,0 +1,74 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { parse } from '@wordpress/block-serialization-default-parser';
3
+ import { hashContent } from './audit.js';
4
+ import { WpError } from './wp-client.js';
5
+ /** Sliding-window budget for write-type calls. Reads are not counted. */
6
+ export class WriteBudget {
7
+ max;
8
+ windowMs;
9
+ now;
10
+ stamps = [];
11
+ constructor(max, windowMs, now = Date.now) {
12
+ this.max = max;
13
+ this.windowMs = windowMs;
14
+ this.now = now;
15
+ }
16
+ take() {
17
+ const t = this.now();
18
+ this.stamps = this.stamps.filter((s) => t - s < this.windowMs);
19
+ if (this.stamps.length >= this.max) {
20
+ const wait = Math.ceil((this.stamps[0] + this.windowMs - t) / 1000);
21
+ throw new WpError(429, 'RATE_LIMITED', `Write budget used up (${this.max} per ${Math.round(this.windowMs / 60000)} minutes). Retry in about ${wait}s.`);
22
+ }
23
+ this.stamps.push(t);
24
+ }
25
+ }
26
+ export const MAX_CONTENT_BYTES = 500_000;
27
+ export const MAX_BLOCK_DEPTH = 12;
28
+ function depth(blocks) {
29
+ let max = 0;
30
+ for (const b of blocks)
31
+ max = Math.max(max, 1 + depth(b.innerBlocks ?? []));
32
+ return max;
33
+ }
34
+ /** Local size and nesting caps, applied before any request. */
35
+ export function checkContentLimits(markup) {
36
+ if (Buffer.byteLength(markup) > MAX_CONTENT_BYTES) {
37
+ throw new WpError(400, 'CONTENT_TOO_LARGE', `Content is over ${MAX_CONTENT_BYTES / 1000} KB. Split it across pages or trim it.`);
38
+ }
39
+ if (depth(parse(markup)) > MAX_BLOCK_DEPTH) {
40
+ throw new WpError(400, 'CONTENT_TOO_DEEP', `Blocks are nested more than ${MAX_BLOCK_DEPTH} levels deep. Flatten the structure.`);
41
+ }
42
+ }
43
+ export function planHash(plan) {
44
+ return hashContent(JSON.stringify(plan));
45
+ }
46
+ /** Single-use approval codes, bound to one plan and short-lived. */
47
+ export class ApprovalCodes {
48
+ ttlMs;
49
+ now;
50
+ pending = new Map();
51
+ constructor(ttlMs = 5 * 60_000, now = Date.now) {
52
+ this.ttlMs = ttlMs;
53
+ this.now = now;
54
+ }
55
+ issue(hash) {
56
+ const code = randomBytes(4).toString('hex');
57
+ this.pending.set(code, { hash, expires: this.now() + this.ttlMs });
58
+ return code;
59
+ }
60
+ /** Consumes the code whether or not it matches, so a code cannot be guessed repeatedly. */
61
+ redeem(code, hash) {
62
+ const p = this.pending.get(code);
63
+ this.pending.delete(code);
64
+ return Boolean(p && p.hash === hash && p.expires > this.now());
65
+ }
66
+ }
67
+ export function describePlan(plan) {
68
+ const lines = [`Action: ${plan.action} post ${plan.post_id}`, JSON.stringify(plan.summary, null, 2)];
69
+ const flags = Object.entries(plan.options).filter(([, v]) => v !== undefined && v !== false);
70
+ if (flags.length)
71
+ lines.push(`Options: ${flags.map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(', ')}`);
72
+ return lines.join('\n');
73
+ }
74
+ //# sourceMappingURL=publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,+CAA+C,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,M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AY;QAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACjE,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,IAAU;IACrC,MAAM,KAAK,GAAG,CAAC,WAAW,IAAI,CAAC,MAAM,SAAS,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACrG,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;IAC7F,IAAI,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1G,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { Config } from './config.js';
2
+ export interface RunResult {
3
+ code: number | null;
4
+ output: string;
5
+ timedOut: boolean;
6
+ }
7
+ export type Runner = (cwd: string, env: NodeJS.ProcessEnv, timeoutMs: number) => Promise<RunResult>;
8
+ /** Runs `npm run generate` in the app directory. */
9
+ export declare const npmGenerate: Runner;
10
+ export interface RefreshResult {
11
+ ok: boolean;
12
+ exit_code: number | null;
13
+ timed_out: boolean;
14
+ duration_ms: number;
15
+ generated_at: string | null;
16
+ preview_drafts: {
17
+ frontend?: string;
18
+ count?: number;
19
+ ids?: number[];
20
+ } | null;
21
+ output_tail: string;
22
+ }
23
+ /**
24
+ * Regenerate the app's static data with preview drafts overlaid, so the local dev server or a local build shows
25
+ * the agent's drafts. Developer tool: it runs the app's own `generate` script.
26
+ */
27
+ export declare function refreshStaticData(dir: string, config: Config, opts?: {
28
+ runner?: Runner;
29
+ timeoutMs?: number;
30
+ }): Promise<RefreshResult>;
@@ -0,0 +1,93 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { WpError } from './wp-client.js';
5
+ const TAIL_CHARS = 4000;
6
+ /** Runs `npm run generate` in the app directory. */
7
+ export const npmGenerate = (cwd, env, timeoutMs) => new Promise((resolve) => {
8
+ const child = spawn('npm run generate', { cwd, env, shell: true, windowsHide: true });
9
+ let output = '';
10
+ let timedOut = false;
11
+ let finished = false;
12
+ const finish = (code) => {
13
+ if (finished)
14
+ return;
15
+ finished = true;
16
+ clearTimeout(timer);
17
+ resolve({ code, output, timedOut });
18
+ };
19
+ const append = (chunk) => {
20
+ output = (output + chunk.toString()).slice(-TAIL_CHARS * 4);
21
+ };
22
+ child.stdout.on('data', append);
23
+ child.stderr.on('data', append);
24
+ const timer = setTimeout(() => {
25
+ timedOut = true;
26
+ // On Windows the shell wrapper hides the real process; kill the whole tree.
27
+ if (process.platform === 'win32' && child.pid)
28
+ spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true });
29
+ else
30
+ child.kill();
31
+ // Do not wait for stdio of orphaned grandchildren.
32
+ setTimeout(() => finish(null), 2000);
33
+ }, timeoutMs);
34
+ child.on('error', (e) => {
35
+ output += `
36
+ ${e.message}`;
37
+ finish(null);
38
+ });
39
+ child.on('close', (code) => finish(code));
40
+ });
41
+ function redact(text, config) {
42
+ let out = text;
43
+ for (const secret of [config.wpPassword, config.cfClientSecret, config.cfClientId]) {
44
+ if (secret && secret.length >= 4)
45
+ out = out.split(secret).join('***');
46
+ }
47
+ return out;
48
+ }
49
+ /**
50
+ * Regenerate the app's static data with preview drafts overlaid, so the local dev server or a local build shows
51
+ * the agent's drafts. Developer tool: it runs the app's own `generate` script.
52
+ */
53
+ export async function refreshStaticData(dir, config, opts = {}) {
54
+ let pkg;
55
+ try {
56
+ pkg = JSON.parse(await readFile(join(dir, 'package.json'), 'utf8'));
57
+ }
58
+ catch {
59
+ throw new WpError(400, 'NO_APP', `No package.json in ${dir}. Start the MCP from the app repository (or pass --cwd).`);
60
+ }
61
+ if (!pkg.scripts?.generate) {
62
+ throw new WpError(400, 'NO_GENERATE_SCRIPT', 'The app has no "generate" script in package.json, so there is nothing to refresh.');
63
+ }
64
+ if (!config.stagingFrontend) {
65
+ throw new WpError(400, 'STAGING_NOT_SET', 'Set VITE_STAGING_FRONTEND first.');
66
+ }
67
+ if (config.frontendId !== config.stagingFrontend) {
68
+ throw new WpError(400, 'FRONTEND_MISMATCH', `Refusing to build previews: VITE_FRONTEND_ID is "${config.frontendId ?? ''}" but the staging frontend is "${config.stagingFrontend}". Set VITE_FRONTEND_ID to the staging frontend in .env.local for local previews.`);
69
+ }
70
+ const started = Date.now();
71
+ const run = opts.runner ?? npmGenerate;
72
+ const res = await run(dir, { ...process.env, VITE_PREVIEW_DRAFTS: 'true' }, opts.timeoutMs ?? 180_000);
73
+ let generatedAt = null;
74
+ let previewDrafts = null;
75
+ try {
76
+ const data = JSON.parse(await readFile(join(dir, 'public', 'wordpress-data.json'), 'utf8'));
77
+ generatedAt = data.generated_at ?? null;
78
+ previewDrafts = data.preview_drafts ?? null;
79
+ }
80
+ catch {
81
+ // data file missing or unreadable: reported through ok/output
82
+ }
83
+ return {
84
+ ok: res.code === 0 && !res.timedOut,
85
+ exit_code: res.code,
86
+ timed_out: res.timedOut,
87
+ duration_ms: Date.now() - started,
88
+ generated_at: generatedAt,
89
+ preview_drafts: previewDrafts,
90
+ output_tail: redact(res.output.slice(-TAIL_CHARS), config),
91
+ };
92
+ }
93
+ //# sourceMappingURL=refresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh.js","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAUzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,oDAAoD;AACpD,MAAM,CAAC,MAAM,WAAW,GAAW,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CACzD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,MAAM,KAAK,GAAG,KAAK,CAAC,kBAAkB,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IACtF,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,MAAM,MAAM,GAAG,CAAC,IAAmB,EAAE,EAAE;QACrC,IAAI,QAAQ;YAAE,OAAO;QACrB,QAAQ,GAAG,IAAI,CAAC;QAChB,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IACtC,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE;QAC/B,MAAM,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,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AM,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,mBAAmB,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,CAAC;IAEvG,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI,aAAa,GAAoC,IAAI,CAAC;IAC1D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,qBAAqB,CAAC,EAAE,MAAM,CAAC,CAGzF,CAAC;QACF,WAAW,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC;QACxC,aAAa,GAAG,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,8DAA8D;IAChE,CAAC;IAED,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ;QACnC,SAAS,EAAE,GAAG,CAAC,IAAI;QACnB,SAAS,EAAE,GAAG,CAAC,QAAQ;QACvB,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;QACjC,YAAY,EAAE,WAAW;QACzB,cAAc,EAAE,aAAa;QAC7B,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;KAC3D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const WORKFLOW_GUIDE = "# DigiValt page workflow\n\nYou build and edit WordPress pages that a DigiValt React frontend renders. Follow this order.\n\n1. Call site_info first. It shows the connected site, your permissions, the enabled post types and the staging frontend.\n2. Read before you write: list_pages, then get_page. Never guess ids.\n3. Draft content using only supported blocks and shortcodes (list_blocks, list_shortcodes). Read digivalt://guide/layout.\n4. Prefer the \"blocks\" tree (see the tool description) over hand-written markup: it is serialized into valid blocks for you. Use \"content\" only to keep markup you read from an existing page.\n5. Upload images first with upload_media (local file, alt text required), then reference the returned id and url in image or cover blocks.\n6. Call validate_page, or just write: create_page and update_page validate first and write nothing if there are errors. Fix every error. Review the warnings.\n7. Everything you create is a draft pinned to the staging frontend. Nothing you do goes live.\n8. Published pages are never edited in place. update_page on a published page writes to a shadow draft; diff_page shows the change; discard_draft removes it. Only a person promotes it (promote_page, when the site owner enabled publishing).\n9. Set SEO fields with set_seo (title, description, canonical, og image, FAQ).\n10. To preview locally, call refresh_static_data (developers only: it runs the app's generate with drafts overlaid), then reload the dev server. The staging site shows drafts after its own build.\n11. Ask the user to preview and approve before anything is promoted or published. promote_page, publish_page and rollback_page exist only when a publisher credential is configured (check site_info.can_publish). Each needs the person's approval: they are prompted, or you get a plan and an approval_code to use after they say yes in chat. Never approve for them.\n\nRules\n- Do not publish, promote or delete unless the user explicitly asks.\n- Do not put secrets, scripts or tracking code in content.\n- Use images from the media library, with alt text.\n- If a tool reports ACCESS_BLOCKED, 401 or 403, stop and tell the user what the message says. Do not retry in a loop.\n";
2
+ export declare const LAYOUT_GUIDE = "# Layout rules for DigiValt pages\n\nStructure\n- A page is a flat list of top-level core/group blocks. One group per section (hero, features, testimonials, call to action).\n- Inside a section use core/heading, core/paragraph, core/columns > core/column, core/image, core/buttons > core/button, core/list.\n- Use core/cover for a hero with a background image.\n- Use core/html only as an escape hatch (for example a video iframe). No scripts.\n\nHeadings\n- Exactly one H1 per page, in the first section. Do not skip levels (H2 then H3).\n\nShortcodes\n- Put each shortcode alone in its own core/paragraph block: <!-- wp:paragraph --><p>[gf_embed id=\"3\"]</p><!-- /wp:paragraph -->\n- Shortcodes only render inside core/paragraph. Not in core/html, core/group text or core/shortcode.\n- Forms: [gf_embed id=\"N\"] for Gravity Forms, [mautic_form id=\"N\"] for Mautic. Never the Gravity Forms PHP shortcode.\n- Check attributes with list_shortcodes. Names that are wp-only do not render on the frontend.\n\nStyling\n- Keep className values consistent across sections. Reuse classes you find in existing pages (get_page) instead of inventing new ones.\n- Do not use inline styles for layout. The frontend's Tailwind theme controls spacing and colour.\n\nMedia\n- Images must come from the WordPress media library. Do not hot-link external images.\n- Every image needs alt text.\n\nBlock comments\n- Always write full block markup with comment delimiters. Plain HTML outside blocks is not rendered reliably.\n";
@@ -0,0 +1,51 @@
1
+ export const WORKFLOW_GUIDE = `# DigiValt page workflow
2
+
3
+ You build and edit WordPress pages that a DigiValt React frontend renders. Follow this order.
4
+
5
+ 1. Call site_info first. It shows the connected site, your permissions, the enabled post types and the staging frontend.
6
+ 2. Read before you write: list_pages, then get_page. Never guess ids.
7
+ 3. Draft content using only supported blocks and shortcodes (list_blocks, list_shortcodes). Read digivalt://guide/layout.
8
+ 4. Prefer the "blocks" tree (see the tool description) over hand-written markup: it is serialized into valid blocks for you. Use "content" only to keep markup you read from an existing page.
9
+ 5. Upload images first with upload_media (local file, alt text required), then reference the returned id and url in image or cover blocks.
10
+ 6. Call validate_page, or just write: create_page and update_page validate first and write nothing if there are errors. Fix every error. Review the warnings.
11
+ 7. Everything you create is a draft pinned to the staging frontend. Nothing you do goes live.
12
+ 8. Published pages are never edited in place. update_page on a published page writes to a shadow draft; diff_page shows the change; discard_draft removes it. Only a person promotes it (promote_page, when the site owner enabled publishing).
13
+ 9. Set SEO fields with set_seo (title, description, canonical, og image, FAQ).
14
+ 10. To preview locally, call refresh_static_data (developers only: it runs the app's generate with drafts overlaid), then reload the dev server. The staging site shows drafts after its own build.
15
+ 11. Ask the user to preview and approve before anything is promoted or published. promote_page, publish_page and rollback_page exist only when a publisher credential is configured (check site_info.can_publish). Each needs the person's approval: they are prompted, or you get a plan and an approval_code to use after they say yes in chat. Never approve for them.
16
+
17
+ Rules
18
+ - Do not publish, promote or delete unless the user explicitly asks.
19
+ - Do not put secrets, scripts or tracking code in content.
20
+ - Use images from the media library, with alt text.
21
+ - If a tool reports ACCESS_BLOCKED, 401 or 403, stop and tell the user what the message says. Do not retry in a loop.
22
+ `;
23
+ export const LAYOUT_GUIDE = `# Layout rules for DigiValt pages
24
+
25
+ Structure
26
+ - A page is a flat list of top-level core/group blocks. One group per section (hero, features, testimonials, call to action).
27
+ - Inside a section use core/heading, core/paragraph, core/columns > core/column, core/image, core/buttons > core/button, core/list.
28
+ - Use core/cover for a hero with a background image.
29
+ - Use core/html only as an escape hatch (for example a video iframe). No scripts.
30
+
31
+ Headings
32
+ - Exactly one H1 per page, in the first section. Do not skip levels (H2 then H3).
33
+
34
+ Shortcodes
35
+ - Put each shortcode alone in its own core/paragraph block: <!-- wp:paragraph --><p>[gf_embed id="3"]</p><!-- /wp:paragraph -->
36
+ - Shortcodes only render inside core/paragraph. Not in core/html, core/group text or core/shortcode.
37
+ - Forms: [gf_embed id="N"] for Gravity Forms, [mautic_form id="N"] for Mautic. Never the Gravity Forms PHP shortcode.
38
+ - Check attributes with list_shortcodes. Names that are wp-only do not render on the frontend.
39
+
40
+ Styling
41
+ - Keep className values consistent across sections. Reuse classes you find in existing pages (get_page) instead of inventing new ones.
42
+ - Do not use inline styles for layout. The frontend's Tailwind theme controls spacing and colour.
43
+
44
+ Media
45
+ - Images must come from the WordPress media library. Do not hot-link external images.
46
+ - Every image needs alt text.
47
+
48
+ Block comments
49
+ - Always write full block markup with comment delimiters. Plain HTML outside blocks is not rendered reliably.
50
+ `;
51
+ //# sourceMappingURL=guides.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guides.js","sourceRoot":"","sources":["../../src/resources/guides.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;CAqB7B,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B3B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { AuditLog } from './audit.js';
3
+ import { type Runner } from './refresh.js';
4
+ import type { Config } from './config.js';
5
+ import { WpClient } from './wp-client.js';
6
+ export interface ServerOptions {
7
+ /** Where writes are recorded. Defaults to no logging. */
8
+ audit?: AuditLog;
9
+ /** App repository directory. Enables refresh_static_data. */
10
+ appDir?: string;
11
+ /** Test hooks for refresh_static_data. */
12
+ runner?: Runner;
13
+ refreshTimeoutMs?: number;
14
+ /** Client for the publisher credential. Defaults to one built from the config. */
15
+ publishClient?: WpClient;
16
+ /** Clock for the write budget and approval codes (tests). */
17
+ now?: () => number;
18
+ }
19
+ export declare function createServer(config: Config, client?: WpClient, opts?: ServerOptions): McpServer;