файл пакета→ .shtukbase/packages/blueprint-content-factory/actions/setup.ts
actions/setup.ts
98 строк, 6.1 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // `shtuk run blueprint-content-factory setup` (also on install): carries the answers of the start questions into the
- // project. The first topic and the platforms become records (an existing record is left alone), the language and
- // tone go to /content/voice.md, the harness's model to the two agent pages, the editor's schedule to its automation
- // (30 minutes after the author), and a first idea waits for a person's approval. The harness and the author's
- // schedule the shtuk tool puts into the pages itself ({{fact:factory.harness}}, {{fact:content.schedule}}).
- import { existsSync } from 'node:fs';
- import { dirname, join } from 'node:path';
- import { readPage } from '../../collections/checks/lib/pages.ts';
- import { create, slug, update } from '../../agents/lib/write.ts';
- import { facts, list, str } from '../lib/facts.ts';
- const root = process.cwd();
- const here = dirname(import.meta.dir);
- const f = facts(here, root);
- const at = (p: string) => join(root, p.replace(/^\/+/, ''));
- const say: string[] = [];
- /** Writes only the fields whose value differs, so a page the answers do not change stays as the tool laid it. */
- function set(path: string, fields: Record<string, unknown>): void {
- const fm = readPage(path).fm;
- const diff = Object.fromEntries(Object.entries(fields).filter(([k, v]) => JSON.stringify(fm[k]) !== JSON.stringify(v)));
- if (Object.keys(diff).length) update(path, diff as any);
- }
- /** Platform presets by name; anything else is a plain post up to 2000 characters. */
- const PRESETS: Record<string, { title: string; channel: string; format: string; minChars: number; maxChars: number; rules: string[] }> = {
- telegram: { title: 'Telegram', channel: 'Telegram channel', format: 'post', minChars: 300, maxChars: 2000,
- rules: ['The first line is the point, it is visible in the feed.', 'Paragraphs of 1-3 sentences.', 'At most one link, emoji only where they help.'] },
- blog: { title: 'Blog', channel: 'Blog on the site', format: 'article', minChars: 2000, maxChars: 12000,
- rules: ['A title and 3-6 subheadings.', 'The introduction says why to read, in two or three sentences.', 'A short conclusion at the end.'] },
- linkedin: { title: 'LinkedIn', channel: 'LinkedIn', format: 'post', minChars: 300, maxChars: 3000,
- rules: ['The first two lines hook: they are visible before "see more".', 'Experience and a conclusion, no advertising.', 'At most three hashtags, at the end.'] },
- x: { title: 'X', channel: 'X (Twitter)', format: 'post', minChars: 40, maxChars: 280,
- rules: ['One thought.', 'No hashtags in the middle.'] },
- newsletter: { title: 'Newsletter', channel: 'Letter to subscribers', format: 'newsletter', minChars: 1500, maxChars: 8000,
- rules: ['The subject of the letter is the title of the record.', 'Address one reader.', 'One main call to action.'] },
- };
- // 1. topic
- const topic = str(f['content.topic']);
- const topicPath = `/content/topics/${slug(topic)}.md`;
- if (topic && !existsSync(at(topicPath))) {
- create(root, '/content/topics', slug(topic), { type: 'Topic', title: topic, status: 'active' }, 'Who we write for and what about: complete this yourself.');
- say.push(`topic ${topicPath}`);
- }
- // 2. platforms
- const language = str(f['content.language']) || 'en';
- const tone = str(f['content.tone']);
- const platforms: string[] = [];
- for (const name of list(f['content.platforms'])) {
- const key = slug(name);
- const pre = PRESETS[key] ?? { title: name, channel: name, format: 'post', minChars: 0, maxChars: 2000, rules: ['The style rules of the platform: write them yourself.'] };
- const path = `/content/platforms/${key}.md`;
- platforms.push(path);
- if (existsSync(at(path))) continue;
- create(root, '/content/platforms', key, {
- type: 'Platform', title: pre.title, channel: pre.channel, format: pre.format, minChars: pre.minChars, maxChars: pre.maxChars,
- language, tone, status: 'active',
- }, `Style rules of the platform:\n\n${pre.rules.map((r) => `- ${r}`).join('\n')}`);
- say.push(`platform ${path}`);
- }
- // 3. voice
- if (existsSync(at('/content/voice.md'))) {
- set(at('/content/voice.md'), { language, ...(tone ? { tone } : {}) });
- say.push(`voice: ${language}${tone ? `, ${tone}` : ''}`);
- }
- // 4. the model of the agents (the harness itself is {{fact:factory.harness}} in their pages)
- const harness = str(f['factory.harness']) || 'claude';
- const MODELS: Record<string, string> = { claude: 'haiku', codex: 'gpt-6-luna', hermes: 'deepseek-v4.1-flash' };
- for (const a of ['/agents/content-author.md', '/agents/content-editor.md'])
- if (existsSync(at(a))) set(at(a), { model: MODELS[harness] ?? 'haiku' });
- say.push(`agents: ${harness}, ${MODELS[harness] ?? 'haiku'}`);
- // 5. schedule: the editor 30 minutes after the author when the minute is a plain number (the author's is {{fact:content.schedule}})
- const cron = str(f['content.schedule']) || '0 9 * * 1-5';
- const parts = cron.split(/\s+/);
- let editor = cron;
- if (parts.length === 5 && /^\d+$/.test(parts[0])) {
- const m = Number(parts[0]) + 30;
- if (m < 60) editor = [String(m), ...parts.slice(1)].join(' ');
- else if (/^\d+$/.test(parts[1])) editor = [String(m - 60), String((Number(parts[1]) + 1) % 24), ...parts.slice(2)].join(' ');
- }
- if (existsSync(at('/automations/content-editor.md'))) set(at('/automations/content-editor.md'), { trigger: { kind: 'schedule', cron: editor } });
- say.push(`schedule: author "${cron}", editor "${editor}"`);
- // 6. a first idea, waiting for a person
- if (!existsSync(at('/content/ideas')) || !(await Array.fromAsync(new Bun.Glob('*.md').scan(at('/content/ideas')))).length) {
- const p = create(root, '/content/ideas', 'first-idea', {
- type: 'Idea', title: `Why we write about "${topic || 'our work'}"`, status: 'new',
- ...(existsSync(at(topicPath)) ? { topic: topicPath.replace(/\.md$/, '') } : {}),
- ...(platforms[0] ? { platform: platforms[0].replace(/\.md$/, '') } : {}), proposedBy: 'blueprint-content-factory',
- }, 'The first text: who we are, what we will write about and why it is useful to the reader. Approve the idea (status: approved, approvedBy: your name) and the author agent will write a draft on its schedule.');
- say.push(`idea ${p} waits for approval`);
- }
- console.log(`content factory: ${say.join('; ')}`);