包文件→ .shtukbase/packages/blueprint-software-factory/actions/setup.ts
actions/setup.ts
77 行, 4.2 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // `shtuk run blueprint-software-factory setup` (also on install): carries the answers of the start questions into
- // the project where a page mark cannot. The shtuk tool itself fills the language, branch and strictness in the head of
- // /base/software-factory.md and the harness in the agent pages ({{fact:…}}). This action writes the test command
- // (auto: by the language) to that head; the harness's model to the three agent pages; the strictness to the `mode` of the norms of the installed code-*
- // and std-* packages (observe: all but floor rules observe; enforce: MUST and SHOULD rules enforce, MAY left alone);
- // the kind Review to the placement map; the missing lines for secrets and runtime files to .gitignore.
- import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
- import { dirname, join } from 'node:path';
- import { readPage } from '../../collections/checks/lib/pages.ts';
- import { place } from '../../agents/lib/place.ts';
- import { update } from '../../agents/lib/write.ts';
- import { facts, str } from '../lib/facts.ts';
- import { PAGE } from '../lib/factory.ts';
- const root = process.cwd();
- const f = facts(dirname(import.meta.dir), 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);
- }
- // 1. the factory page
- const TESTS: Record<string, string> = {
- typescript: 'bun test', python: 'python3 -m unittest discover -q', rust: 'cargo test', go: 'go test ./...', other: 'make test',
- };
- const language = str(f['stack.language']) || 'typescript';
- const asked = str(f['factory.test']);
- const test = !asked || asked === 'auto' ? TESTS[language] ?? 'make test' : asked;
- const branch = str(f['factory.branch']) || 'main';
- const strict = str(f['factory.strictness']) === 'enforce' ? 'enforce' : 'observe';
- if (existsSync(at(PAGE))) set(at(PAGE), { test });
- say.push(`tests "${test}", branch ${branch}`);
- // 2. 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 ['sf-executor', 'sf-reviewer', 'sf-tester'])
- if (existsSync(at(`/agents/${a}.md`))) set(at(`/agents/${a}.md`), { model: MODELS[harness] ?? 'haiku' });
- say.push(`agents: ${harness}, ${MODELS[harness] ?? 'haiku'}`);
- // 3. strictness of code and standard norms
- let changed = 0;
- const rulesDir = at('/norms/rules');
- for (const pkg of existsSync(rulesDir) ? readdirSync(rulesDir) : []) {
- if (!/^(code|std)-/.test(pkg)) continue;
- for (const file of readdirSync(join(rulesDir, pkg)).filter((n) => n.endsWith('.md'))) {
- const path = join(rulesDir, pkg, file);
- const fm = readPage(path).fm;
- const level = str(fm.level);
- const want = strict === 'observe' ? (fm.floor === true ? null : 'observe') : level === 'MAY' ? null : 'enforce';
- if (want && str(fm.mode) !== want) {
- update(path, { mode: want });
- changed++;
- }
- }
- }
- say.push(`strictness ${strict}: the mode of code and standard norms changed in ${changed}`);
- // 4. the kind Review in the placement map
- place([{ itemType: 'Review', path: '/work/reviews', title: 'Reviews', pkg: 'blueprint-software-factory' }], root);
- // 5. .gitignore: secrets (SCR-R03) and the factory's runtime files; only the lines that are missing
- const IGNORE = ['.env', '.env.*', '!.env.example', '.shtukbase/state/', 'runs/logs/'];
- const gi = at('/.gitignore');
- const had = existsSync(gi) ? readFileSync(gi, 'utf8') : '';
- const lines = new Set(had.split('\n').map((l) => l.trim()));
- const add = IGNORE.filter((l) => !lines.has(l));
- if (add.length) {
- writeFileSync(gi, `${had}${had && !had.endsWith('\n') ? '\n' : ''}${had ? '\n' : ''}# shtukbase: software factory\n${add.join('\n')}\n`);
- say.push(`.gitignore: added ${add.join(' ')}`);
- }
- console.log(`software factory: ${say.join('; ')}`);