skill-monster 0.0.0-stage → 0.1.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.
- package/LICENSE +202 -0
- package/README.md +155 -2
- package/desk-ui/app.css +73 -0
- package/desk-ui/app.js +182 -0
- package/desk-ui/fonts/bricolage-grotesque-800.woff2 +0 -0
- package/desk-ui/fonts/ibm-plex-mono-400.woff2 +0 -0
- package/desk-ui/fonts/ibm-plex-mono-600.woff2 +0 -0
- package/desk-ui/fonts/ibm-plex-sans-400.woff2 +0 -0
- package/desk-ui/fonts/silkscreen-400.woff2 +0 -0
- package/desk-ui/fonts.css +70 -0
- package/desk-ui/index.html +29 -0
- package/desk-ui/mascot.svg +1 -0
- package/dist/build.json +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +640 -0
- package/dist/cli/ui.d.ts +18 -0
- package/dist/cli/ui.js +120 -0
- package/dist/core/checkup.d.ts +14 -0
- package/dist/core/checkup.js +69 -0
- package/dist/core/corrections.d.ts +54 -0
- package/dist/core/corrections.js +138 -0
- package/dist/core/digest.d.ts +36 -0
- package/dist/core/digest.js +91 -0
- package/dist/core/export.d.ts +8 -0
- package/dist/core/export.js +28 -0
- package/dist/core/external.d.ts +48 -0
- package/dist/core/external.js +127 -0
- package/dist/core/guard.d.ts +10 -0
- package/dist/core/guard.js +48 -0
- package/dist/core/mirror.d.ts +37 -0
- package/dist/core/mirror.js +148 -0
- package/dist/core/release.d.ts +69 -0
- package/dist/core/release.js +173 -0
- package/dist/core/report.d.ts +10 -0
- package/dist/core/report.js +65 -0
- package/dist/core/scrub.d.ts +20 -0
- package/dist/core/scrub.js +67 -0
- package/dist/core/sign.d.ts +25 -0
- package/dist/core/sign.js +86 -0
- package/dist/core/skill.d.ts +26 -0
- package/dist/core/skill.js +68 -0
- package/dist/core/starters.d.ts +54 -0
- package/dist/core/starters.js +184 -0
- package/dist/core/types.d.ts +187 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +4 -0
- package/dist/core/version.js +17 -0
- package/dist/core/workspace.d.ts +23 -0
- package/dist/core/workspace.js +79 -0
- package/dist/desk/server.d.ts +10 -0
- package/dist/desk/server.js +140 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +112 -0
- package/dist/providers/index.d.ts +15 -0
- package/dist/providers/index.js +123 -0
- package/dist/slack/api.d.ts +6 -0
- package/dist/slack/api.js +18 -0
- package/dist/slack/app.d.ts +70 -0
- package/dist/slack/app.js +387 -0
- package/dist/slack/manifest.d.ts +50 -0
- package/dist/slack/manifest.js +71 -0
- package/dist/slack/messages.d.ts +414 -0
- package/dist/slack/messages.js +226 -0
- package/dist/slack/socket.d.ts +24 -0
- package/dist/slack/socket.js +84 -0
- package/dist/stores/airtable.d.ts +26 -0
- package/dist/stores/airtable.js +52 -0
- package/dist/stores/confluence-format.d.ts +34 -0
- package/dist/stores/confluence-format.js +458 -0
- package/dist/stores/confluence.d.ts +55 -0
- package/dist/stores/confluence.js +204 -0
- package/dist/stores/index.d.ts +30 -0
- package/dist/stores/index.js +53 -0
- package/dist/stores/notion.d.ts +43 -0
- package/dist/stores/notion.js +313 -0
- package/docs/SECURITY.md +45 -0
- package/docs/slack.md +78 -0
- package/package.json +48 -4
- package/starters/_core/SKILL.md +30 -0
- package/starters/customer-support-answers/starter.yaml +98 -0
- package/starters/data-warehouse-kb/starter.yaml +119 -0
- package/starters/engineering-house-rules/starter.yaml +106 -0
- package/starters/people-policies/starter.yaml +89 -0
- package/starters/pricing-and-packaging/starter.yaml +90 -0
- package/starters/product-analytics-kb/starter.yaml +109 -0
- package/starters/security-questionnaire-answers/starter.yaml +94 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import readline from 'node:readline/promises';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
import { c, ok, warn, bad, fail, banner, table, chew, mascot } from './ui.js';
|
|
8
|
+
import { Workspace, defaultConfig, readYaml, writeYaml, RECORDS_DIR } from '../core/workspace.js';
|
|
9
|
+
import { ensureKey, keyHome, keyDirWarnings } from '../core/sign.js';
|
|
10
|
+
import { checkSkill, scanFolder } from '../core/checkup.js';
|
|
11
|
+
import { hatch, listStarters, loadStarter, normalizeAnswers, shapeStarter } from '../core/starters.js';
|
|
12
|
+
import { release, listReleases, verifyRelease, testSkill, BlockedError } from '../core/release.js';
|
|
13
|
+
import { loadSkill, saveSkill, bumpVersion, findBlanks } from '../core/skill.js';
|
|
14
|
+
import { fileCorrection, listCorrections, clusters, approve, decline, getCorrection } from '../core/corrections.js';
|
|
15
|
+
import { buildDigest, postDigest } from '../core/digest.js';
|
|
16
|
+
import { exportSkill } from '../core/export.js';
|
|
17
|
+
import { openStore } from '../stores/index.js';
|
|
18
|
+
import { parseConfluenceLink } from '../stores/confluence.js';
|
|
19
|
+
import { VERSION, versionLine } from '../core/version.js';
|
|
20
|
+
const argv = process.argv.slice(2);
|
|
21
|
+
const cmd = argv[0];
|
|
22
|
+
const { values: o, positionals: pos } = parseArgs({
|
|
23
|
+
args: argv.slice(1), allowPositionals: true, strict: false,
|
|
24
|
+
options: {
|
|
25
|
+
org: { type: 'string' }, curator: { type: 'string' }, name: { type: 'string' }, owner: { type: 'string' },
|
|
26
|
+
store: { type: 'string' }, answers: { type: 'string' }, yes: { type: 'boolean', short: 'y' },
|
|
27
|
+
offline: { type: 'boolean' }, version: { type: 'string' }, bump: { type: 'string' }, model: { type: 'string' },
|
|
28
|
+
question: { type: 'string' }, pasted: { type: 'string' }, page: { type: 'string' }, answer: { type: 'string' }, wrong: { type: 'string' }, rule: { type: 'string' }, role: { type: 'string' },
|
|
29
|
+
section: { type: 'string' }, old: { type: 'string' }, new: { type: 'string' }, test: { type: 'string' }, expect: { type: 'string' }, exclude: { type: 'string' },
|
|
30
|
+
reason: { type: 'string' }, post: { type: 'boolean' }, format: { type: 'string' }, out: { type: 'string' }, port: { type: 'string' },
|
|
31
|
+
'no-release': { type: 'boolean' }, file: { type: 'string' }, dir: { type: 'string' }, 'keys-dir': { type: 'string' }, 'emit-prompts': { type: 'string' }, 'no-git': { type: 'boolean' }, 'dry-run': { type: 'boolean' }, wiki: { type: 'string' }, names: { type: 'boolean' }, json: { type: 'boolean' }, help: { type: 'boolean', short: 'h' },
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const str = (k) => (typeof o[k] === 'string' ? o[k] : undefined);
|
|
35
|
+
function worksOnTable(results, version) {
|
|
36
|
+
const rows = (Array.isArray(results) ? results.map(r => [r.model, { pass: r.pass, total: r.total, failed: r.failed, tested: !r.skipped, note: r.skipped }])
|
|
37
|
+
: Object.entries(results).map(([m, w]) => [m, { ...w, note: undefined }]));
|
|
38
|
+
return table(rows.map(([m, w]) => {
|
|
39
|
+
if (!w.tested)
|
|
40
|
+
return [m, c.dim('– NOT RUN'), c.dim(`– / ${w.total}`), c.dim(w.note?.replace(/^skipped: /, '') ?? 'not tested')];
|
|
41
|
+
const good = w.failed.length === 0;
|
|
42
|
+
return [m, good ? c.monster('✓ GUARDING') : c.bite('✗ SICK'), `${w.pass} / ${w.total}`, good ? version : c.bite(`held · ${w.failed[0]}`)];
|
|
43
|
+
}), ['MODEL', 'STATUS', 'TESTS', 'RELEASE']);
|
|
44
|
+
}
|
|
45
|
+
async function prompt(q, hint) {
|
|
46
|
+
if (!process.stdin.isTTY || o.yes)
|
|
47
|
+
return '';
|
|
48
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
49
|
+
const a = await rl.question(`${q}${hint ? c.dim(` (${hint})`) : ''}\n ${c.monster('→')} `);
|
|
50
|
+
rl.close();
|
|
51
|
+
return a.trim();
|
|
52
|
+
}
|
|
53
|
+
function printFindings(fs_) {
|
|
54
|
+
for (const f of fs_)
|
|
55
|
+
console.log(f.level === 'block' ? bad(f.message) : f.level === 'warn' ? warn(f.message) : ok(f.message));
|
|
56
|
+
}
|
|
57
|
+
async function doRelease(ws, name, version) {
|
|
58
|
+
const stop = chew(`Testing ${name} on ${ws.config.models.map(m => m.name).join(', ')}`);
|
|
59
|
+
try {
|
|
60
|
+
const { record, results, git } = await release(ws, name, { version, offline: !!o.offline, answersFile: cmd === 'release' ? str('answers') : undefined, git: !o['no-git'] });
|
|
61
|
+
stop();
|
|
62
|
+
for (const r of results.filter(r => r.note))
|
|
63
|
+
console.log(c.dim(` ${r.model}: ${r.note}`));
|
|
64
|
+
console.log(`\n${c.hi('Works-on check')} ${c.dim(`(${results[0]?.total ?? 0} guard tests)`)}:`);
|
|
65
|
+
console.log(worksOnTable(results, record.version));
|
|
66
|
+
for (const r of results.filter(r => !r.skipped && r.failed.length))
|
|
67
|
+
console.log(bad(`${r.model} users don't get ${record.version} until ${r.failed.join(', ')} pass${r.failed.length > 1 ? '' : 'es'}.`));
|
|
68
|
+
const tested = results.filter(r => !r.skipped), live = tested.filter(r => !r.failed.length);
|
|
69
|
+
const head = !tested.length ? `${name} ${record.version} signed. Not tested on any model yet, so nobody gets it until it passes.`
|
|
70
|
+
: !live.length ? `${name} ${record.version} signed, but held on every model until the guard tests pass.`
|
|
71
|
+
: `${name} ${record.version} signed and released for ${live.map(r => r.model).join(', ')}`;
|
|
72
|
+
const m = mascot(live.length ? 'full' : 'sick');
|
|
73
|
+
console.log(`\n ${m[2]} ${live.length ? ok(c.hi(head)) : warn(c.hi(head))}\n ${m[3]} ${c.dim(`Key ${record.key_id} · ${Object.keys(record.files).length} files${git.done ? ` · committed and tagged ${name}-v${record.version}` : ''} · nothing was sent anywhere.`)}\n`);
|
|
74
|
+
if (git.note && !o['no-git'])
|
|
75
|
+
console.log(warn(git.note));
|
|
76
|
+
return record;
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
stop();
|
|
80
|
+
if (e instanceof BlockedError) {
|
|
81
|
+
console.log(c.hi('\nCheck-up:'));
|
|
82
|
+
printFindings(e.findings);
|
|
83
|
+
console.log(c.bite('\nRelease blocked. Fix the items above, then run release again.'));
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const HELP = `${banner(VERSION)}
|
|
91
|
+
${c.hi('Start')}
|
|
92
|
+
init [folder] Set up Skill Monster in a folder (check-up, signing key, settings)
|
|
93
|
+
[--store folder:kb|notion:<link>|confluence:<page link>] [--keys-dir ../.skill-monster-keys]
|
|
94
|
+
starters List the starter skills
|
|
95
|
+
new <starter> Hatch a starter: short interview, visible blanks, seeded guard tests, signed 0.1.0
|
|
96
|
+
${c.hi('Every day')}
|
|
97
|
+
check [skill] Free check-up: passwords, personal data, versions, owner
|
|
98
|
+
test [skill] [--out f.md] Run guard tests on every configured model (your keys)
|
|
99
|
+
test <skill> --emit-prompts f.yaml Write the questions for answering elsewhere (no keys)
|
|
100
|
+
test <skill> --emit-prompts dir/ The same, one file per test (answers saved as test-NN.answer.md)
|
|
101
|
+
test <skill> --answers f.yaml|dir/ Grade those answers, rubric verdicts included
|
|
102
|
+
release <skill> [--answers f.yaml] [--bump patch|minor] [--no-git]
|
|
103
|
+
Check, test, sign and release the next version (commits and tags in a git repo)
|
|
104
|
+
verify <skill> [ver] Check a release's signature and files
|
|
105
|
+
status Skills, versions, open corrections, blanks
|
|
106
|
+
read <skill> [--section id] [--dir d] [--wiki confluence] Print sections, or write one .md per section to a folder
|
|
107
|
+
(--wiki confluence: page titles unique in a space, plus storage-format copies)
|
|
108
|
+
mirror <skill> --dir d [--pasted ids|all] [--page link] Which wiki pages need pasting again; record a paste
|
|
109
|
+
write <skill> --dir d [--dry-run] Take edited sections back from that folder (e.g. after a Notion or Confluence round trip);
|
|
110
|
+
--dry-run only lists the sections that differ (mirror status)
|
|
111
|
+
write <skill> --section id --file f.md Replace one section
|
|
112
|
+
report [--out f.md] [--names] Counts-only run report, safe to share outside the company (skills shown as skill 1, 2…)
|
|
113
|
+
${c.hi('Corrections')}
|
|
114
|
+
correct <skill> --question "…" --wrong "…" [--rule "…"] [--role Growth]
|
|
115
|
+
inbox Open corrections, grouped when they look like the same problem
|
|
116
|
+
approve <COR…> --section <id> [--old "…"] --new "…" --test "question" --expect "a|b;c"
|
|
117
|
+
decline <COR> --reason "…"
|
|
118
|
+
digest [--post] Monday digest (posts to SKILL_MONSTER_CHAT_WEBHOOK with --post)
|
|
119
|
+
${c.hi('Slack')} ${c.dim('(your own app, on your own server; nothing is sent to Skill Monster)')}
|
|
120
|
+
slack manifest [--out d] The app manifest your org registers, plus the monster icon
|
|
121
|
+
slack check Check tokens and slack: settings
|
|
122
|
+
slack run [--offline] Run the app (Socket Mode): flag wrong answers, receipts, digest, approvals
|
|
123
|
+
slack note <skill> [--post] Draft the release note; --post sends it to slack.release_channel or the webhook
|
|
124
|
+
${c.hi('Surfaces')}
|
|
125
|
+
desk [--port 4747] Open the Desk in your browser (runs on this machine)
|
|
126
|
+
mcp Run the assistant connector (MCP, stdio)
|
|
127
|
+
export <skill> --format agent-skill|agents-md|instructions --out <dir> [--model Claude]
|
|
128
|
+
|
|
129
|
+
Flags: --offline skips model calls · --yes accepts defaults · NO_COLOR=1 for plain output`;
|
|
130
|
+
async function main() {
|
|
131
|
+
if (!cmd || cmd === 'help' || o.help || cmd === '--help' || cmd === '-h') {
|
|
132
|
+
console.log(HELP);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (cmd === '--version' || cmd === '-v') {
|
|
136
|
+
console.log(versionLine());
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (cmd === 'init') {
|
|
140
|
+
const dir = path.resolve(pos[0] ?? '.');
|
|
141
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
142
|
+
console.log(banner(VERSION));
|
|
143
|
+
if (Workspace.exists(dir)) {
|
|
144
|
+
console.log(ok(`Already set up in ${dir}.`));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const scan = scanFolder(dir);
|
|
148
|
+
const mdDocs = scan.files.filter(f => /\.mdx?$/i.test(f));
|
|
149
|
+
const cfg = defaultConfig(str('org') ?? path.basename(path.dirname(dir)), str('curator') ?? process.env.USER ?? 'Curator');
|
|
150
|
+
if (str('store'))
|
|
151
|
+
cfg.store = parseStore(str('store'));
|
|
152
|
+
if (str('keys-dir'))
|
|
153
|
+
cfg.keys_dir = str('keys-dir');
|
|
154
|
+
writeYaml(path.join(dir, 'skill-monster.yaml'), cfg);
|
|
155
|
+
const ws = Workspace.find(dir);
|
|
156
|
+
fs.mkdirSync(ws.records('corrections'), { recursive: true });
|
|
157
|
+
const key = ensureKey(ws);
|
|
158
|
+
console.log(ok(`Scanning ${path.basename(dir)} ... found ${scan.files.length} files${mdDocs.length ? `, ${mdDocs.length} docs` : ''}`));
|
|
159
|
+
console.log(ok(`Initialised skill-monster.yaml (rung 0: local, store: ${cfg.store.type})`));
|
|
160
|
+
const home = path.resolve(keyHome(ws));
|
|
161
|
+
console.log(ok(`Signing key ${key.keyId} ${key.created ? 'created' : 'found'}. Private half stays in ${home.startsWith(os.homedir() + path.sep) ? '~' + home.slice(os.homedir().length) : home}.`));
|
|
162
|
+
for (const w of keyDirWarnings(ws))
|
|
163
|
+
console.log(warn(w));
|
|
164
|
+
if (scan.findings.length) {
|
|
165
|
+
console.log(c.hi('\nCheck-up:'));
|
|
166
|
+
printFindings(scan.findings);
|
|
167
|
+
}
|
|
168
|
+
if (mdDocs.length && !o['no-release']) {
|
|
169
|
+
const name = str('name') ?? `${path.basename(dir).replace(/[^a-z0-9]+/gi, '-').toLowerCase().replace(/-docs?$/, '')}-playbook`;
|
|
170
|
+
const meta = { name, title: name, version: '0.1.0', owner: cfg.curator, description: `Team playbook from ${path.basename(dir)}.`, sections: [] };
|
|
171
|
+
fs.mkdirSync(ws.skillDir(name), { recursive: true });
|
|
172
|
+
for (const f of mdDocs.slice(0, 50)) {
|
|
173
|
+
const id = path.relative(dir, f).replace(/\.mdx?$/i, '').replace(/[^a-z0-9]+/gi, '-').toLowerCase();
|
|
174
|
+
meta.sections.push(id);
|
|
175
|
+
fs.mkdirSync(path.join(ws.skillDir(name), 'sections'), { recursive: true });
|
|
176
|
+
fs.copyFileSync(f, path.join(ws.skillDir(name), 'sections', `${id}.md`));
|
|
177
|
+
}
|
|
178
|
+
fs.writeFileSync(path.join(ws.skillDir(name), 'SKILL.md'), `---\nname: ${name}\ndescription: Team playbook from ${path.basename(dir)}.\n---\n# ${name}\n\nAnswer from the sections below. If something is not written here, say you don't know and name ${cfg.curator}. End with "Answered from ${name} <version>".\n`);
|
|
179
|
+
saveSkill(ws, meta);
|
|
180
|
+
const findings = await checkSkill(ws, name);
|
|
181
|
+
if (findings.some(f => f.level === 'block')) {
|
|
182
|
+
console.log(c.hi(`\nSkill ${name} created from ${mdDocs.length} docs, not released yet:`));
|
|
183
|
+
printFindings(findings.filter(f => f.level === 'block'));
|
|
184
|
+
console.log(c.dim(`\nFix those, then run: skill-monster release ${name}`));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const yes = o.yes || !process.stdin.isTTY ? true : /^(y|yes|)$/i.test(await prompt(`Sign and release ${name} 1.0.0? (Y/n)`));
|
|
188
|
+
if (yes)
|
|
189
|
+
await doRelease(ws, name, '1.0.0');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
console.log(`${c.dim('Next:')} ${c.monster('skill-monster starters')} ${c.dim('then')} ${c.monster('skill-monster new <starter>')} ${c.dim('or')} ${c.monster('skill-monster desk')} ${c.dim('to open the Desk at')} ${c.hi('http://localhost:4747')}`);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (cmd === 'starters') {
|
|
196
|
+
console.log(`\n${c.inv('EGGS')} ${c.hi('Starter skills')} ${c.dim('· one engine, seven content packs')}\n`);
|
|
197
|
+
console.log(table(listStarters().map((s, i) => [c.monster(s.id), s.title + (i === 0 ? c.dim(' (featured)') : ''), c.dim(s.for)])));
|
|
198
|
+
console.log(c.dim(`\nHatch one: skill-monster new <starter>`));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const ws = Workspace.find();
|
|
202
|
+
if (cmd === 'new') {
|
|
203
|
+
const id = pos[0];
|
|
204
|
+
if (!id) {
|
|
205
|
+
console.log(bad('Which starter? Run "skill-monster starters" to see them.'));
|
|
206
|
+
process.exitCode = 1;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const raw = (str('answers') ? readYaml(str('answers')) : null) ?? {};
|
|
210
|
+
// Count the sections that will really be made: extra_sections added, drop_sections left out.
|
|
211
|
+
const st = shapeStarter(loadStarter(id), raw);
|
|
212
|
+
const name = str('name') ?? st.default_skill;
|
|
213
|
+
console.log(`\n${c.inv('EGGS')} ${c.hi(st.id)} ${c.dim(`· ${st.sections.length} sections · seeded guard tests`)}\n`);
|
|
214
|
+
const { section_titles, drop_sections, extra_sections, ...plain } = raw;
|
|
215
|
+
let answers = normalizeAnswers(plain);
|
|
216
|
+
const asked = st.interview.filter(q => answers[q.key] === undefined);
|
|
217
|
+
for (const [i, q] of asked.entries()) {
|
|
218
|
+
const a = await prompt(`${c.dim(`[${i + 1}/${asked.length}]`)} ${q.question}`, q.hint ?? 'Enter to skip; it stays a visible blank');
|
|
219
|
+
if (a)
|
|
220
|
+
answers[q.key] = a;
|
|
221
|
+
}
|
|
222
|
+
const stop = chew('Chewing through your answers');
|
|
223
|
+
const res = await hatch(ws, id, { ...answers, section_titles, drop_sections, extra_sections }, { name, owner: str('owner') });
|
|
224
|
+
stop(ok(c.hi(`${res.meta.sections.length} sections, ${res.filled} filled, ${res.blanks} blanks marked. ${res.tests} guard tests seeded.`)));
|
|
225
|
+
console.log(c.dim(' Blanks are snacks for week one.'));
|
|
226
|
+
if (!o['no-release'])
|
|
227
|
+
await doRelease(ws, name, '0.1.0');
|
|
228
|
+
console.log(c.dim(`Run skill-monster desk to fill blanks · nothing was sent anywhere.`));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (cmd === 'check') {
|
|
232
|
+
const names = pos[0] ? [pos[0]] : ws.listSkills();
|
|
233
|
+
let blocked = false;
|
|
234
|
+
for (const w of keyDirWarnings(ws))
|
|
235
|
+
console.log(warn(w));
|
|
236
|
+
for (const n of names) {
|
|
237
|
+
console.log(c.hi(`\n${n}`));
|
|
238
|
+
const f = await checkSkill(ws, n);
|
|
239
|
+
printFindings(f);
|
|
240
|
+
blocked ||= f.some(x => x.level === 'block');
|
|
241
|
+
}
|
|
242
|
+
if (blocked)
|
|
243
|
+
process.exitCode = 1;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (cmd === 'test' && str('emit-prompts')) {
|
|
247
|
+
const n = pos[0] ?? (ws.listSkills().length === 1 ? ws.listSkills()[0] : undefined);
|
|
248
|
+
if (!n)
|
|
249
|
+
throw new Error('Which skill? skill-monster test <skill> --emit-prompts <file>');
|
|
250
|
+
const { emitPrompts, writePromptFile, writePromptDir, isPromptDir } = await import('../core/external.js');
|
|
251
|
+
const p = await emitPrompts(ws, loadSkill(ws, n), str('model') ?? 'Claude');
|
|
252
|
+
const target = str('emit-prompts');
|
|
253
|
+
const dir = isPromptDir(target);
|
|
254
|
+
if (dir)
|
|
255
|
+
writePromptDir(target, p);
|
|
256
|
+
else
|
|
257
|
+
writePromptFile(target, p);
|
|
258
|
+
console.log(ok(`${p.tests.length} guard-test questions for ${n} written to ${target}${dir ? ', one file per test' : ''}.`) + c.dim(` ${p.tests.filter(t => t.rubric).length} also need a verdict.`));
|
|
259
|
+
console.log(c.dim(` Answer each in a fresh context (see ${dir ? 'HOW_TO.md in the folder' : 'how_to in the file'}), then: skill-monster test ${n} --answers ${target}`));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (cmd === 'test') {
|
|
263
|
+
const md = ['### 👾 Skill Monster works-on check', '', '| Skill | Model | Status | Tests | Failing |', '|---|---|---|---|---|'];
|
|
264
|
+
for (const n of pos[0] ? [pos[0]] : ws.listSkills()) {
|
|
265
|
+
const meta = loadSkill(ws, n);
|
|
266
|
+
const stop = chew(`Testing ${n}`);
|
|
267
|
+
const { results } = await testSkill(ws, meta, { offline: !!o.offline, answersFile: str('answers'), models: str('model') ? [str('model')] : undefined });
|
|
268
|
+
stop();
|
|
269
|
+
console.log(`\n${c.hi(n)} ${c.dim(meta.version)}`);
|
|
270
|
+
console.log(worksOnTable(results, meta.version));
|
|
271
|
+
for (const r of results)
|
|
272
|
+
for (const x of r.outcomes.filter(x => !x.pass))
|
|
273
|
+
console.log(fail(`${r.model} ${x.id}: ${x.reason}`));
|
|
274
|
+
for (const r of results.filter(r => r.note))
|
|
275
|
+
console.log(c.dim(` ${r.model}: ${r.note}`));
|
|
276
|
+
if (results.some(r => r.failed.length))
|
|
277
|
+
process.exitCode = 1;
|
|
278
|
+
for (const r of results)
|
|
279
|
+
md.push(`| ${n} ${meta.version} | ${r.model} | ${r.skipped ? 'not run' : r.failed.length ? '✗ sick' : '✓ guarding'} | ${r.skipped ? '–' : `${r.pass} / ${r.total}`} | ${r.skipped ? r.skipped.replace(/^skipped: /, '') : r.failed.join(', ') || '–'} |`);
|
|
280
|
+
}
|
|
281
|
+
if (str('out')) {
|
|
282
|
+
md.push('', '_A model that fails stays on its last passing version. Nothing was sent anywhere except to your own model providers._');
|
|
283
|
+
fs.writeFileSync(str('out'), md.join('\n') + '\n');
|
|
284
|
+
}
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (cmd === 'release') {
|
|
288
|
+
const n = pos[0] ?? (ws.listSkills().length === 1 ? ws.listSkills()[0] : undefined);
|
|
289
|
+
if (!n)
|
|
290
|
+
throw new Error('Which skill? skill-monster release <skill>');
|
|
291
|
+
const meta = loadSkill(ws, n);
|
|
292
|
+
const prev = listReleases(ws, n)[0];
|
|
293
|
+
let v = str('version') ?? meta.version;
|
|
294
|
+
if (!str('version') && prev && prev.version === meta.version)
|
|
295
|
+
v = bumpVersion(meta.version, str('bump') ?? 'patch');
|
|
296
|
+
await doRelease(ws, n, v);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (cmd === 'verify') {
|
|
300
|
+
const n = pos[0];
|
|
301
|
+
if (!n)
|
|
302
|
+
throw new Error('skill-monster verify <skill> [version]');
|
|
303
|
+
const vs = pos[1] ? [pos[1]] : listReleases(ws, n).map(r => r.version);
|
|
304
|
+
for (const v of vs) {
|
|
305
|
+
const r = verifyRelease(ws, n, v);
|
|
306
|
+
console.log(r.ok ? ok(`${n} ${v}: ${r.reason}`) : bad(`${n} ${v}: ${r.reason}`));
|
|
307
|
+
if (!r.ok)
|
|
308
|
+
process.exitCode = 1;
|
|
309
|
+
}
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (cmd === 'status') {
|
|
313
|
+
const open = listCorrections(ws, 'open');
|
|
314
|
+
console.log(banner(VERSION, [c.dim(`${ws.config.org} · rung ${ws.config.rung} · store: ${openStore(ws).describe()}`)]));
|
|
315
|
+
const rows = [];
|
|
316
|
+
for (const n of ws.listSkills()) {
|
|
317
|
+
const m = loadSkill(ws, n);
|
|
318
|
+
const rel = listReleases(ws, n)[0];
|
|
319
|
+
let blanks = '–';
|
|
320
|
+
try {
|
|
321
|
+
blanks = String(findBlanks(await openStore(ws).readSections(m)).length);
|
|
322
|
+
}
|
|
323
|
+
catch { /* store offline */ }
|
|
324
|
+
rows.push([c.monster(n), rel?.version ?? c.dim('unreleased'), m.owner, String(open.filter(x => x.skill === n).length), blanks]);
|
|
325
|
+
}
|
|
326
|
+
console.log(rows.length ? table(rows, ['SKILL', 'RELEASED', 'OWNER', 'OPEN', 'BLANKS']) : c.dim('No skills yet. Run skill-monster starters, then skill-monster new <starter>.'));
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (cmd === 'read') {
|
|
330
|
+
const n = pos[0];
|
|
331
|
+
if (!n)
|
|
332
|
+
throw new Error('skill-monster read <skill> [--section <id>] [--dir <folder>]');
|
|
333
|
+
const meta = loadSkill(ws, n);
|
|
334
|
+
const sections = await openStore(ws).readSections(meta);
|
|
335
|
+
if (str('dir')) {
|
|
336
|
+
const { writeMirror } = await import('../core/mirror.js');
|
|
337
|
+
const wiki = str('wiki');
|
|
338
|
+
if (wiki && wiki !== 'confluence' && wiki !== 'notion')
|
|
339
|
+
throw new Error('--wiki takes notion or confluence.');
|
|
340
|
+
const files = writeMirror(meta, sections, path.resolve(str('dir')), wiki);
|
|
341
|
+
console.log(ok(`${files.length} sections of ${n} written to ${str('dir')}, one Markdown file each, plus MIRROR.md.`));
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const ids = str('section') ? [str('section')] : meta.sections;
|
|
345
|
+
for (const id of ids) {
|
|
346
|
+
if (!(id in sections))
|
|
347
|
+
throw new Error(`No section "${id}". Sections: ${meta.sections.join(', ')}`);
|
|
348
|
+
console.log(`<!-- section: ${id} -->\n${sections[id].trim()}\n`);
|
|
349
|
+
}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (cmd === 'write') {
|
|
353
|
+
const n = pos[0], id = str('section'), file = str('file');
|
|
354
|
+
if (n && str('dir')) {
|
|
355
|
+
const { readMirror, mirrorChanges } = await import('../core/mirror.js');
|
|
356
|
+
const meta = loadSkill(ws, n);
|
|
357
|
+
const store = openStore(ws);
|
|
358
|
+
const current = await store.readSections(meta);
|
|
359
|
+
const incoming = readMirror(meta, path.resolve(str('dir')));
|
|
360
|
+
const diff = mirrorChanges(incoming, current);
|
|
361
|
+
const changed = Object.keys(diff);
|
|
362
|
+
const dry = !!o['dry-run'];
|
|
363
|
+
if (!dry)
|
|
364
|
+
for (const k of changed)
|
|
365
|
+
await store.writeSection(meta, k, diff[k]);
|
|
366
|
+
const missing = meta.sections.filter(k => !(k in incoming));
|
|
367
|
+
const s_ = changed.length > 1 ? 's' : '';
|
|
368
|
+
console.log(ok(!changed.length ? `No changes: every section in ${str('dir')} matches the store.`
|
|
369
|
+
: dry ? `${changed.length} section${s_} of ${n} differ from the store: ${changed.join(', ')}. Nothing was written.`
|
|
370
|
+
: `Updated ${changed.length} section${s_} of ${n}: ${changed.join(', ')}.`)
|
|
371
|
+
+ (missing.length ? c.dim(` Not in the folder, left as they were: ${missing.join(', ')}.`) : ''));
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (!n || !id || !file)
|
|
375
|
+
throw new Error('skill-monster write <skill> --section <id> --file <markdown file>, or write <skill> --dir <folder>');
|
|
376
|
+
const meta = loadSkill(ws, n);
|
|
377
|
+
if (!meta.sections.includes(id))
|
|
378
|
+
throw new Error(`No section "${id}". Sections: ${meta.sections.join(', ')}`);
|
|
379
|
+
await openStore(ws).writeSection(meta, id, fs.readFileSync(file, 'utf8'));
|
|
380
|
+
console.log(ok(`Section ${id} of ${n} replaced in ${openStore(ws).describe()}.`) + c.dim(' Run skill-monster check, then release.'));
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (cmd === 'mirror') {
|
|
384
|
+
const n = pos[0], d = str('dir');
|
|
385
|
+
if (!n || !d)
|
|
386
|
+
throw new Error('skill-monster mirror <skill> --dir <folder> [--pasted <section,…|all> [--page <link>]]');
|
|
387
|
+
const { mirrorStatus, markPasted } = await import('../core/mirror.js');
|
|
388
|
+
const meta = loadSkill(ws, n), dir = path.resolve(d);
|
|
389
|
+
if (str('pasted')) {
|
|
390
|
+
const done = markPasted(meta, dir, str('pasted').split(',').map(x => x.trim()).filter(Boolean), str('page'));
|
|
391
|
+
console.log(ok(`Recorded ${done.length} section${done.length > 1 ? 's' : ''} as pasted: ${done.join(', ')}.`));
|
|
392
|
+
}
|
|
393
|
+
const rows = mirrorStatus(meta, dir);
|
|
394
|
+
console.log(table(rows.map(r => [r.id, r.page ?? c.dim('–'), r.status === 'up to date' ? c.monster(r.status) : c.warn(r.status)]), ['SECTION', 'PAGE', 'STATUS']));
|
|
395
|
+
const todo = rows.filter(r => r.status === 'paste again' || r.status === 'new page');
|
|
396
|
+
if (todo.length)
|
|
397
|
+
console.log(c.dim(` ${todo.length} to paste: ${todo.map(r => r.id).join(', ')}. After pasting: skill-monster mirror ${n} --dir ${d} --pasted <ids>`));
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (cmd === 'report') {
|
|
401
|
+
const { buildReport } = await import('../core/report.js');
|
|
402
|
+
const r = await buildReport(ws, versionLine(), { names: !!o.names });
|
|
403
|
+
if (str('out')) {
|
|
404
|
+
fs.writeFileSync(str('out'), r);
|
|
405
|
+
console.log(ok(`Report written to ${str('out')}. It holds counts only; read it before you share it.`));
|
|
406
|
+
}
|
|
407
|
+
else
|
|
408
|
+
console.log(r);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (cmd === 'correct') {
|
|
412
|
+
const n = pos[0];
|
|
413
|
+
if (!n || !str('question') || !str('wrong'))
|
|
414
|
+
throw new Error('skill-monster correct <skill> --question "…" --wrong "…" [--rule "…"] [--role Growth]');
|
|
415
|
+
const cor = fileCorrection(ws, { skill: n, question: str('question'), answer: str('answer'), what_was_wrong: str('wrong'), suggested_rule: str('rule'), reporter_role: str('role') });
|
|
416
|
+
console.log(ok(`Correction ${c.hi(cor.id)} filed for ${loadSkill(ws, n).owner}.`) + (cor.removed.length ? c.dim(` Removed: ${cor.removed.join(', ')}.`) : ''));
|
|
417
|
+
console.log(c.dim(` Receipt token: ${cor.receipt_token}`));
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (cmd === 'inbox') {
|
|
421
|
+
const open = listCorrections(ws, 'open');
|
|
422
|
+
if (!open.length) {
|
|
423
|
+
const m = mascot('full');
|
|
424
|
+
console.log(`\n ${m[2]} ${c.hi('Inbox zero. The monster is full.')}\n ${m[3]}\n`);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const groups = clusters(open);
|
|
428
|
+
const same = groups.filter(g => g.length > 1).reduce((n, g) => n + g.length, 0);
|
|
429
|
+
console.log(`\n${c.hi(`${open.length} open`)}${same ? c.dim(` · ${same} look like the same problem`) : ''}\n`);
|
|
430
|
+
for (const g of groups) {
|
|
431
|
+
console.log(`${c.monster(g.map(x => x.id).join(' + '))} ${c.dim(`${g[0].skill} ${g[0].version} · ${[...new Set(g.map(x => x.reporter_role))].join(', ')}`)}${g.length > 1 ? ' ' + c.inv(`${g.length} SIMILAR`) : ''}`);
|
|
432
|
+
console.log(` ${g[0].what_was_wrong}${g[0].suggested_rule ? c.dim(`\n Suggested: ${g[0].suggested_rule}`) : ''}\n`);
|
|
433
|
+
}
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (cmd === 'approve') {
|
|
437
|
+
if (!pos.length || !str('section') || !str('new') || !str('test') || !str('expect'))
|
|
438
|
+
throw new Error('skill-monster approve <COR…> --section <id> [--old "…"] --new "…" --test "question" --expect "a|b;c" [--exclude "x;y"]');
|
|
439
|
+
const include = str('expect').split(';').map(g => g.split('|').map(s => s.trim()).filter(Boolean)).filter(g => g.length);
|
|
440
|
+
const stop = chew('Changing the rule, adding the guard test, testing on every model');
|
|
441
|
+
const out = await approve(ws, { ids: pos, section: str('section'), old_text: str('old'), new_text: str('new'), test: { question: str('test'), include, exclude: str('exclude')?.split(';').map(s => s.trim()) }, curator: str('curator') ?? ws.config.curator, offline: !!o.offline });
|
|
442
|
+
stop();
|
|
443
|
+
console.log(worksOnTable(out.results, out.record.version));
|
|
444
|
+
console.log(ok(c.hi(`${out.record.skill} ${out.record.version} signed and released.`)) + c.dim(' The monster ate the old rule.'));
|
|
445
|
+
for (const r of out.receipts)
|
|
446
|
+
console.log(c.dim(` Receipt for ${r.correction}: ${r.message}`));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (cmd === 'decline') {
|
|
450
|
+
const cor = decline(ws, pos[0], str('curator') ?? ws.config.curator, str('reason') ?? 'Declined');
|
|
451
|
+
console.log(ok(`${cor.id} declined. The reporter will see: "${cor.resolution?.note}"`));
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (cmd === 'digest') {
|
|
455
|
+
const d = await buildDigest(ws);
|
|
456
|
+
console.log(d.text);
|
|
457
|
+
if (o.post) {
|
|
458
|
+
const hook = process.env.SKILL_MONSTER_CHAT_WEBHOOK;
|
|
459
|
+
if (!hook)
|
|
460
|
+
throw new Error('Set SKILL_MONSTER_CHAT_WEBHOOK to your team chat incoming webhook to post the digest.');
|
|
461
|
+
await postDigest(hook, d);
|
|
462
|
+
console.log(ok('Posted to team chat.'));
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
if (cmd === 'export') {
|
|
467
|
+
const n = pos[0];
|
|
468
|
+
if (!n)
|
|
469
|
+
throw new Error('skill-monster export <skill> --format agent-skill|agents-md|instructions --out <dir>');
|
|
470
|
+
const out = exportSkill(ws, n, str('format') ?? 'agent-skill', path.resolve(str('out') ?? 'export'), str('model'));
|
|
471
|
+
console.log(ok(`Exported to ${out}`));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (cmd === 'slack') {
|
|
475
|
+
await slackCommand(ws);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (cmd === 'desk') {
|
|
479
|
+
const { startDesk } = await import('../desk/server.js');
|
|
480
|
+
const port = Number(str('port') ?? 4747);
|
|
481
|
+
await startDesk(ws, port);
|
|
482
|
+
console.log(banner(VERSION, [`${c.hi('The Desk')} is open at ${c.monster(`http://localhost:${port}`)}`, c.dim('Runs on this machine. Nothing leaves it. Ctrl+C to stop.')]));
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (cmd === 'mcp') {
|
|
486
|
+
const { runMcp } = await import('../mcp/server.js');
|
|
487
|
+
await runMcp(ws);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
console.log(bad(`Unknown command "${cmd}".`) + c.dim(' Run skill-monster help.'));
|
|
491
|
+
process.exitCode = 1;
|
|
492
|
+
}
|
|
493
|
+
async function slackCommand(ws) {
|
|
494
|
+
const sub = pos[0];
|
|
495
|
+
const { slackManifest, monsterIcon } = await import('../slack/manifest.js');
|
|
496
|
+
const { SlackApp, parseDigestAt, storeLabel } = await import('../slack/app.js');
|
|
497
|
+
const { slackApi } = await import('../slack/api.js');
|
|
498
|
+
const { releaseNote } = await import('../slack/messages.js');
|
|
499
|
+
const bot = process.env.SLACK_BOT_TOKEN, appToken = process.env.SLACK_APP_TOKEN;
|
|
500
|
+
if (sub === 'manifest') {
|
|
501
|
+
const m = JSON.stringify(slackManifest(ws.config.org), null, 2);
|
|
502
|
+
if (!str('out')) {
|
|
503
|
+
console.log(m);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const dir = path.resolve(str('out'));
|
|
507
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
508
|
+
fs.writeFileSync(path.join(dir, 'slack-manifest.json'), m + '\n');
|
|
509
|
+
fs.writeFileSync(path.join(dir, 'skill-monster-icon.png'), monsterIcon());
|
|
510
|
+
console.log(ok(`Wrote slack-manifest.json and skill-monster-icon.png to ${dir}`));
|
|
511
|
+
console.log(c.dim(' Create the app at api.slack.com/apps → From an app manifest, upload the icon, turn on an app-level token (connections:write),\n install it to your workspace, then set SLACK_BOT_TOKEN and SLACK_APP_TOKEN where the app runs.'));
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (sub === 'check') {
|
|
515
|
+
const s = ws.config.slack ?? {};
|
|
516
|
+
let good = true;
|
|
517
|
+
const say = (pass, msg) => { console.log(pass ? ok(msg) : bad(msg)); if (!pass)
|
|
518
|
+
good = false; };
|
|
519
|
+
if (bot) {
|
|
520
|
+
try {
|
|
521
|
+
const a = await slackApi(bot)('auth.test');
|
|
522
|
+
say(true, `Bot token works: ${a.team} as @${a.user}.`);
|
|
523
|
+
if (s.team_id && a.team_id !== s.team_id)
|
|
524
|
+
say(false, `slack.team_id is ${s.team_id} but the token is for ${a.team_id}.`);
|
|
525
|
+
}
|
|
526
|
+
catch (e) {
|
|
527
|
+
say(false, `SLACK_BOT_TOKEN: ${e.message}`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
else
|
|
531
|
+
say(false, 'SLACK_BOT_TOKEN is not set (xoxb-…).');
|
|
532
|
+
if (appToken) {
|
|
533
|
+
const { openConnection } = await import('../slack/socket.js');
|
|
534
|
+
try {
|
|
535
|
+
await openConnection(appToken);
|
|
536
|
+
say(true, 'App token works (Socket Mode).');
|
|
537
|
+
}
|
|
538
|
+
catch (e) {
|
|
539
|
+
say(false, e.message);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
else
|
|
543
|
+
say(false, 'SLACK_APP_TOKEN is not set (xapp-…, with connections:write).');
|
|
544
|
+
const n = Object.keys(s.curators ?? {}).length;
|
|
545
|
+
if (n)
|
|
546
|
+
console.log(ok(`${n} curator${n === 1 ? '' : 's'} can approve from Slack.`));
|
|
547
|
+
else
|
|
548
|
+
console.log(warn('No slack.curators yet, so nobody can approve or decline from Slack. Flagging and receipts still work.'));
|
|
549
|
+
try {
|
|
550
|
+
const d = parseDigestAt(s.digest_at);
|
|
551
|
+
console.log(ok(d ? `Digest goes ${s.digest_at ?? 'mon 09:00'} (server time) to ${s.digest_channel ? `channel ${s.digest_channel}` : 'each curator by DM'}.` : 'Scheduled digest is off.'));
|
|
552
|
+
}
|
|
553
|
+
catch (e) {
|
|
554
|
+
say(false, e.message);
|
|
555
|
+
}
|
|
556
|
+
console.log(s.release_channel ? ok(`Release notes can go to channel ${s.release_channel}.`) : c.dim(' No slack.release_channel: release notes are drafts to paste.'));
|
|
557
|
+
if (!s.desk_url)
|
|
558
|
+
console.log(warn('No slack.desk_url: Review buttons point at http://localhost:4747, which only works on the curator\'s own machine.'));
|
|
559
|
+
if (!good)
|
|
560
|
+
process.exitCode = 1;
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (sub === 'note') {
|
|
564
|
+
const name = pos[1];
|
|
565
|
+
if (!name)
|
|
566
|
+
throw new Error('skill-monster slack note <skill> [--post]');
|
|
567
|
+
const rec = listReleases(ws, name)[0];
|
|
568
|
+
if (!rec)
|
|
569
|
+
throw new Error(`${name} has no release yet. Release it first.`);
|
|
570
|
+
const note = releaseNote(ws.config, loadSkill(ws, name), rec, storeLabel(ws.config.store));
|
|
571
|
+
console.log(note.text);
|
|
572
|
+
if (!o.post) {
|
|
573
|
+
console.log(c.dim('\n Draft only. Add --post to send it, or paste it yourself.'));
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const ch = ws.config.slack?.release_channel, hook = process.env.SKILL_MONSTER_CHAT_WEBHOOK;
|
|
577
|
+
if (bot && ch) {
|
|
578
|
+
await slackApi(bot)('chat.postMessage', { channel: ch, text: note.text, blocks: note.blocks, unfurl_links: false });
|
|
579
|
+
console.log(ok(`Posted to channel ${ch}.`));
|
|
580
|
+
}
|
|
581
|
+
else if (hook) {
|
|
582
|
+
await postDigest(hook, note);
|
|
583
|
+
console.log(ok('Posted to team chat.'));
|
|
584
|
+
}
|
|
585
|
+
else
|
|
586
|
+
throw new Error('To post, set SLACK_BOT_TOKEN and slack.release_channel, or SKILL_MONSTER_CHAT_WEBHOOK.');
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
if (sub === 'run') {
|
|
590
|
+
if (!bot || !appToken)
|
|
591
|
+
throw new Error('Set SLACK_BOT_TOKEN (xoxb-…) and SLACK_APP_TOKEN (xapp-…). Run "skill-monster slack manifest" to create the app first.');
|
|
592
|
+
const { runSocketMode } = await import('../slack/socket.js');
|
|
593
|
+
const log = (m) => console.log(`${c.dim(new Date().toISOString().slice(11, 19))} ${m}`);
|
|
594
|
+
const call = slackApi(bot);
|
|
595
|
+
const app = new SlackApp(ws, {
|
|
596
|
+
call, log, offline: !!o.offline,
|
|
597
|
+
respond: async (url, body) => {
|
|
598
|
+
if (!/^https:\/\/hooks\.slack\.com\//.test(url))
|
|
599
|
+
throw new Error('Refused a response URL outside hooks.slack.com.');
|
|
600
|
+
await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
601
|
+
},
|
|
602
|
+
});
|
|
603
|
+
parseDigestAt(ws.config.slack?.digest_at);
|
|
604
|
+
if (!Object.keys(ws.config.slack?.curators ?? {}).length)
|
|
605
|
+
console.log(warn('No slack.curators: nobody can approve from Slack yet.'));
|
|
606
|
+
console.log(banner(VERSION, [`${c.hi('Slack app')} running for ${ws.config.org} (Socket Mode)`, c.dim('Talks only to slack.com with your tokens. Nothing is sent to Skill Monster. Ctrl+C to stop.')]));
|
|
607
|
+
const timer = setInterval(() => { void app.tick(); }, 60_000);
|
|
608
|
+
void app.tick();
|
|
609
|
+
try {
|
|
610
|
+
await runSocketMode({ appToken, handle: (t, p) => app.handle(t, p), log });
|
|
611
|
+
}
|
|
612
|
+
finally {
|
|
613
|
+
clearInterval(timer);
|
|
614
|
+
}
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
throw new Error('skill-monster slack manifest|check|run|note. See skill-monster help.');
|
|
618
|
+
}
|
|
619
|
+
function parseStore(s) {
|
|
620
|
+
const [type, a, b] = s.split(':');
|
|
621
|
+
if (type === 'notion')
|
|
622
|
+
return { type: 'notion', root_page: s.slice('notion:'.length) };
|
|
623
|
+
if (type === 'confluence') {
|
|
624
|
+
// confluence:<page or space link>, or confluence:<site>/<SPACE>[/<parent page id>]
|
|
625
|
+
const rest = s.slice('confluence:'.length);
|
|
626
|
+
const short = rest.match(/^([^/]+\.[^/]+)\/([^/]+)(?:\/(\d+))?$/);
|
|
627
|
+
const p = short ? { site: short[1], space: short[2], page: short[3] } : parseConfluenceLink(rest);
|
|
628
|
+
if (!p.space)
|
|
629
|
+
throw new Error('Give the space too: --store confluence:<link to the parent page>, or confluence:acme.atlassian.net/KB');
|
|
630
|
+
return { type: 'confluence', site: parseConfluenceLink(p.site).site, space: p.space, ...(p.page ? { parent_page: p.page } : {}) };
|
|
631
|
+
}
|
|
632
|
+
if (type === 'airtable')
|
|
633
|
+
return { type: 'airtable', base: a, table: b ?? 'Knowledge' };
|
|
634
|
+
if (type === 'folder')
|
|
635
|
+
return { type: 'folder', path: a };
|
|
636
|
+
return { type: 'git' };
|
|
637
|
+
}
|
|
638
|
+
main().catch(e => { console.error(bad(e.message ?? String(e))); process.exitCode = 1; });
|
|
639
|
+
void getCorrection;
|
|
640
|
+
void RECORDS_DIR;
|
package/dist/cli/ui.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const c: {
|
|
2
|
+
monster: (s: string) => string;
|
|
3
|
+
bite: (s: string) => string;
|
|
4
|
+
warn: (s: string) => string;
|
|
5
|
+
dim: (s: string) => string;
|
|
6
|
+
hi: (s: string) => string;
|
|
7
|
+
inv: (s: string) => string;
|
|
8
|
+
};
|
|
9
|
+
export declare const ok: (s: string) => string;
|
|
10
|
+
export declare const warn: (s: string) => string;
|
|
11
|
+
export declare const bad: (s: string) => string;
|
|
12
|
+
export declare const fail: (s: string) => string;
|
|
13
|
+
export declare function grid(mood: 'hungry' | 'full' | 'chewing' | 'sick'): any[][];
|
|
14
|
+
/** Renders the mascot with half blocks: 12x12 pixels in 12 columns x 6 rows. */
|
|
15
|
+
export declare function mascot(mood?: 'hungry' | 'full' | 'chewing' | 'sick'): string[];
|
|
16
|
+
export declare function banner(version: string, lines?: string[], mood?: Parameters<typeof mascot>[0]): string;
|
|
17
|
+
export declare function table(rows: string[][], head?: string[]): string;
|
|
18
|
+
export declare function chew(label: string): (done?: string) => void;
|