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.
Files changed (88) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +155 -2
  3. package/desk-ui/app.css +73 -0
  4. package/desk-ui/app.js +182 -0
  5. package/desk-ui/fonts/bricolage-grotesque-800.woff2 +0 -0
  6. package/desk-ui/fonts/ibm-plex-mono-400.woff2 +0 -0
  7. package/desk-ui/fonts/ibm-plex-mono-600.woff2 +0 -0
  8. package/desk-ui/fonts/ibm-plex-sans-400.woff2 +0 -0
  9. package/desk-ui/fonts/silkscreen-400.woff2 +0 -0
  10. package/desk-ui/fonts.css +70 -0
  11. package/desk-ui/index.html +29 -0
  12. package/desk-ui/mascot.svg +1 -0
  13. package/dist/build.json +1 -0
  14. package/dist/cli/index.d.ts +2 -0
  15. package/dist/cli/index.js +640 -0
  16. package/dist/cli/ui.d.ts +18 -0
  17. package/dist/cli/ui.js +120 -0
  18. package/dist/core/checkup.d.ts +14 -0
  19. package/dist/core/checkup.js +69 -0
  20. package/dist/core/corrections.d.ts +54 -0
  21. package/dist/core/corrections.js +138 -0
  22. package/dist/core/digest.d.ts +36 -0
  23. package/dist/core/digest.js +91 -0
  24. package/dist/core/export.d.ts +8 -0
  25. package/dist/core/export.js +28 -0
  26. package/dist/core/external.d.ts +48 -0
  27. package/dist/core/external.js +127 -0
  28. package/dist/core/guard.d.ts +10 -0
  29. package/dist/core/guard.js +48 -0
  30. package/dist/core/mirror.d.ts +37 -0
  31. package/dist/core/mirror.js +148 -0
  32. package/dist/core/release.d.ts +69 -0
  33. package/dist/core/release.js +173 -0
  34. package/dist/core/report.d.ts +10 -0
  35. package/dist/core/report.js +65 -0
  36. package/dist/core/scrub.d.ts +20 -0
  37. package/dist/core/scrub.js +67 -0
  38. package/dist/core/sign.d.ts +25 -0
  39. package/dist/core/sign.js +86 -0
  40. package/dist/core/skill.d.ts +26 -0
  41. package/dist/core/skill.js +68 -0
  42. package/dist/core/starters.d.ts +54 -0
  43. package/dist/core/starters.js +184 -0
  44. package/dist/core/types.d.ts +187 -0
  45. package/dist/core/types.js +1 -0
  46. package/dist/core/version.d.ts +4 -0
  47. package/dist/core/version.js +17 -0
  48. package/dist/core/workspace.d.ts +23 -0
  49. package/dist/core/workspace.js +79 -0
  50. package/dist/desk/server.d.ts +10 -0
  51. package/dist/desk/server.js +140 -0
  52. package/dist/index.d.ts +11 -0
  53. package/dist/index.js +10 -0
  54. package/dist/mcp/server.d.ts +8 -0
  55. package/dist/mcp/server.js +112 -0
  56. package/dist/providers/index.d.ts +15 -0
  57. package/dist/providers/index.js +123 -0
  58. package/dist/slack/api.d.ts +6 -0
  59. package/dist/slack/api.js +18 -0
  60. package/dist/slack/app.d.ts +70 -0
  61. package/dist/slack/app.js +387 -0
  62. package/dist/slack/manifest.d.ts +50 -0
  63. package/dist/slack/manifest.js +71 -0
  64. package/dist/slack/messages.d.ts +414 -0
  65. package/dist/slack/messages.js +226 -0
  66. package/dist/slack/socket.d.ts +24 -0
  67. package/dist/slack/socket.js +84 -0
  68. package/dist/stores/airtable.d.ts +26 -0
  69. package/dist/stores/airtable.js +52 -0
  70. package/dist/stores/confluence-format.d.ts +34 -0
  71. package/dist/stores/confluence-format.js +458 -0
  72. package/dist/stores/confluence.d.ts +55 -0
  73. package/dist/stores/confluence.js +204 -0
  74. package/dist/stores/index.d.ts +30 -0
  75. package/dist/stores/index.js +53 -0
  76. package/dist/stores/notion.d.ts +43 -0
  77. package/dist/stores/notion.js +313 -0
  78. package/docs/SECURITY.md +45 -0
  79. package/docs/slack.md +78 -0
  80. package/package.json +48 -4
  81. package/starters/_core/SKILL.md +30 -0
  82. package/starters/customer-support-answers/starter.yaml +98 -0
  83. package/starters/data-warehouse-kb/starter.yaml +119 -0
  84. package/starters/engineering-house-rules/starter.yaml +106 -0
  85. package/starters/people-policies/starter.yaml +89 -0
  86. package/starters/pricing-and-packaging/starter.yaml +90 -0
  87. package/starters/product-analytics-kb/starter.yaml +109 -0
  88. package/starters/security-questionnaire-answers/starter.yaml +94 -0
@@ -0,0 +1,187 @@
1
+ export type StoreConfig = {
2
+ type: 'git';
3
+ } | {
4
+ type: 'folder';
5
+ path: string;
6
+ } | {
7
+ type: 'notion';
8
+ root_page: string;
9
+ token_env?: string;
10
+ } | {
11
+ type: 'airtable';
12
+ base: string;
13
+ table: string;
14
+ token_env?: string;
15
+ } | {
16
+ type: 'confluence';
17
+ site: string;
18
+ space: string;
19
+ parent_page?: string;
20
+ token_env?: string;
21
+ email_env?: string;
22
+ };
23
+ export interface ModelConfig {
24
+ /** Display name used in works-on tables, e.g. "Claude". */
25
+ name: string;
26
+ provider: 'anthropic' | 'openai' | 'gemini' | 'openai-compatible' | 'command' | 'answers' | 'offline';
27
+ /** Vendor model id, e.g. the one your company approved. */
28
+ model: string;
29
+ /** Environment variable that holds the key. Keys are never written to disk. */
30
+ key_env?: string;
31
+ /** For openai-compatible endpoints (Llama, Azure, local gateways). */
32
+ base_url?: string;
33
+ /**
34
+ * For provider "command": a program that reads the prompt on stdin and prints the answer,
35
+ * e.g. ["claude", "-p", "--system-prompt-file", "{system_file}"]. "{system_file}" is replaced
36
+ * with a temporary file holding the system prompt; without it, the system prompt is sent
37
+ * on stdin ahead of the question. Lets guard tests run on a login you already have.
38
+ */
39
+ command?: string[];
40
+ /** provider "answers": answers come from a file (test --emit-prompts, then --answers). Nothing is called. */
41
+ /** Seconds before a command answer times out. Default 180. */
42
+ timeout?: number;
43
+ }
44
+ export interface WorkspaceConfig {
45
+ org: string;
46
+ rung: 0 | 1 | 2 | 3;
47
+ curator: string;
48
+ store: StoreConfig;
49
+ models: ModelConfig[];
50
+ /** Optional head count per model, used only to word receipts ("live for 38 people"). */
51
+ audience?: Record<string, number>;
52
+ sharing: {
53
+ monthly_count: boolean;
54
+ share_invitations: boolean;
55
+ };
56
+ scrub: {
57
+ names: string[];
58
+ extra_patterns?: string[];
59
+ };
60
+ /** Folder for the private signing key, if not ~/.config/skill-monster/keys. "~" is allowed. */
61
+ keys_dir?: string;
62
+ /** Serve a version to a model that was never tested on it. Default false. */
63
+ allow_untested?: boolean;
64
+ /** The self-hosted Slack app (rung 2). Tokens come from SLACK_BOT_TOKEN and SLACK_APP_TOKEN, never this file. */
65
+ slack?: SlackConfig;
66
+ }
67
+ export interface SlackConfig {
68
+ /** Slack user id → the name that signs releases. Only these people can approve or decline from Slack. Empty: nobody can. */
69
+ curators?: Record<string, string>;
70
+ /** Channel id for the Monday digest. Omit to DM each curator instead. */
71
+ digest_channel?: string;
72
+ /** Channel id a curator can post release notes to, after choosing to. */
73
+ release_channel?: string;
74
+ /** When the digest goes out, in the server's time zone. Default "mon 09:00". "off" turns it off. */
75
+ digest_at?: string;
76
+ /** Where people in Slack can open the Desk, e.g. your internal URL. Default http://localhost:4747. */
77
+ desk_url?: string;
78
+ /** Your install page (in your repo or wiki), linked from release notes. */
79
+ install_url?: string;
80
+ /** The "set up your own" page. Only a source tag such as from=receipt is added, never a name or id. */
81
+ setup_url?: string;
82
+ /** Answer only this Slack workspace (team id). */
83
+ team_id?: string;
84
+ }
85
+ export interface SkillMeta {
86
+ name: string;
87
+ title: string;
88
+ version: string;
89
+ owner: string;
90
+ description: string;
91
+ starter?: string;
92
+ sections: string[];
93
+ /** Teams that use this skill, for receipts and the install note. */
94
+ teams?: string[];
95
+ }
96
+ export interface GuardTest {
97
+ id: string;
98
+ question: string;
99
+ expect: {
100
+ /** Every group must match: each group is a list of acceptable phrasings (any one counts). */
101
+ include?: string[][];
102
+ /** None of these may appear in the answer. */
103
+ exclude?: string[];
104
+ /** Optional plain-language rubric checked by the same model as a judge. */
105
+ rubric?: string;
106
+ };
107
+ added_from?: string;
108
+ /** The test checks that this topic is still a visible blank. Check-up warns once the content defines it. */
109
+ blank?: string;
110
+ verified_on?: string;
111
+ seeded?: boolean;
112
+ }
113
+ export interface TestOutcome {
114
+ id: string;
115
+ pass: boolean;
116
+ reason: string;
117
+ answer?: string;
118
+ }
119
+ export interface ModelResult {
120
+ model: string;
121
+ provider: string;
122
+ pass: number;
123
+ total: number;
124
+ failed: string[];
125
+ outcomes: TestOutcome[];
126
+ skipped?: string;
127
+ note?: string;
128
+ }
129
+ export type CorrectionStatus = 'open' | 'approved' | 'declined' | 'snoozed';
130
+ export interface Correction {
131
+ id: string;
132
+ skill: string;
133
+ version: string;
134
+ question: string;
135
+ answer_excerpt: string;
136
+ what_was_wrong: string;
137
+ suggested_rule: string;
138
+ reporter_role: string;
139
+ /** Opaque token the reporter's assistant keeps, to collect the receipt later. No name. */
140
+ receipt_token: string;
141
+ created_at: string;
142
+ status: CorrectionStatus;
143
+ removed: string[];
144
+ votes: {
145
+ role: string;
146
+ vote: 1 | -1;
147
+ note?: string;
148
+ }[];
149
+ resolution?: {
150
+ version?: string;
151
+ note?: string;
152
+ decided_at: string;
153
+ decided_by: string;
154
+ };
155
+ }
156
+ export interface ReleaseRecord {
157
+ skill: string;
158
+ version: string;
159
+ previous?: string;
160
+ changelog: string;
161
+ corrections: string[];
162
+ files: Record<string, string>;
163
+ works_on: Record<string, {
164
+ pass: number;
165
+ total: number;
166
+ failed: string[];
167
+ tested: boolean;
168
+ }>;
169
+ store: string;
170
+ signed_by: string;
171
+ signed_at: string;
172
+ key_id: string;
173
+ signature?: string;
174
+ }
175
+ export interface Receipt {
176
+ correction: string;
177
+ receipt_token: string;
178
+ skill: string;
179
+ version: string;
180
+ message: string;
181
+ works_on: string[];
182
+ held: string[];
183
+ live_for?: number;
184
+ waiting?: number;
185
+ created_at: string;
186
+ delivered?: boolean;
187
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /** The package version, e.g. "0.1.0". */
2
+ export declare const VERSION: string;
3
+ /** Version plus build stamp (commit and date, written by scripts/stamp.mjs at build), so two builds of one version can be told apart. */
4
+ export declare function versionLine(): string;
@@ -0,0 +1,17 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ const here = path.dirname(fileURLToPath(import.meta.url));
5
+ const read = (f) => { try {
6
+ return JSON.parse(fs.readFileSync(path.resolve(here, f), 'utf8'));
7
+ }
8
+ catch {
9
+ return undefined;
10
+ } };
11
+ /** The package version, e.g. "0.1.0". */
12
+ export const VERSION = read('../../package.json')?.version ?? '0.0.0';
13
+ /** Version plus build stamp (commit and date, written by scripts/stamp.mjs at build), so two builds of one version can be told apart. */
14
+ export function versionLine() {
15
+ const b = read('../build.json');
16
+ return b ? `${VERSION} (build ${[b.commit, b.built_at?.slice(0, 16).replace('T', ' ')].filter(Boolean).join(', ')})` : VERSION;
17
+ }
@@ -0,0 +1,23 @@
1
+ import type { WorkspaceConfig } from './types.js';
2
+ export declare const CONFIG_FILE = "skill-monster.yaml";
3
+ export declare const RECORDS_DIR = ".skill-monster";
4
+ export declare class Workspace {
5
+ root: string;
6
+ config: WorkspaceConfig;
7
+ constructor(root: string, config: WorkspaceConfig);
8
+ static find(start?: string): Workspace;
9
+ static exists(dir: string): boolean;
10
+ p(...parts: string[]): string;
11
+ records(...parts: string[]): string;
12
+ skillDir(name: string): string;
13
+ saveConfig(): void;
14
+ listSkills(): string[];
15
+ }
16
+ export declare const configHeader = "# Skill Monster settings. Lives in your repo or folder. Nothing here is sent anywhere.\n# Model keys are read from environment variables at run time and never written to disk.\n";
17
+ export declare function defaultConfig(org?: string, curator?: string): WorkspaceConfig;
18
+ export declare function normalizeConfig(raw: any): WorkspaceConfig;
19
+ export declare function readYaml<T>(file: string): T;
20
+ export declare function writeYaml(file: string, data: unknown): void;
21
+ export declare function writeJson(file: string, data: unknown): void;
22
+ export declare function readJson<T>(file: string): T;
23
+ export declare const nowIso: () => string;
@@ -0,0 +1,79 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import YAML from 'yaml';
4
+ export const CONFIG_FILE = 'skill-monster.yaml';
5
+ export const RECORDS_DIR = '.skill-monster';
6
+ export class Workspace {
7
+ root;
8
+ config;
9
+ constructor(root, config) {
10
+ this.root = root;
11
+ this.config = config;
12
+ }
13
+ static find(start = process.cwd()) {
14
+ let dir = path.resolve(start);
15
+ for (;;) {
16
+ const f = path.join(dir, CONFIG_FILE);
17
+ if (fs.existsSync(f))
18
+ return new Workspace(dir, normalizeConfig(YAML.parse(fs.readFileSync(f, 'utf8'))));
19
+ const up = path.dirname(dir);
20
+ if (up === dir)
21
+ throw new Error(`No ${CONFIG_FILE} found. Run "skill-monster init" in your folder first.`);
22
+ dir = up;
23
+ }
24
+ }
25
+ static exists(dir) { return fs.existsSync(path.join(dir, CONFIG_FILE)); }
26
+ p(...parts) { return path.join(this.root, ...parts); }
27
+ records(...parts) { return path.join(this.root, RECORDS_DIR, ...parts); }
28
+ skillDir(name) { return this.p('skills', name); }
29
+ saveConfig() {
30
+ fs.writeFileSync(this.p(CONFIG_FILE), configHeader + YAML.stringify(this.config));
31
+ }
32
+ listSkills() {
33
+ const d = this.p('skills');
34
+ if (!fs.existsSync(d))
35
+ return [];
36
+ return fs.readdirSync(d).filter(n => fs.existsSync(path.join(d, n, 'skill.yaml'))).sort();
37
+ }
38
+ }
39
+ export const configHeader = `# Skill Monster settings. Lives in your repo or folder. Nothing here is sent anywhere.
40
+ # Model keys are read from environment variables at run time and never written to disk.
41
+ `;
42
+ export function defaultConfig(org = 'My company', curator = 'Curator') {
43
+ return {
44
+ org,
45
+ rung: 0,
46
+ curator,
47
+ store: { type: 'git' },
48
+ models: [
49
+ { name: 'Claude', provider: 'anthropic', model: 'claude-sonnet-5-5', key_env: 'ANTHROPIC_API_KEY' },
50
+ { name: 'GPT', provider: 'openai', model: 'gpt-5-mini', key_env: 'OPENAI_API_KEY' },
51
+ { name: 'Gemini', provider: 'gemini', model: 'gemini-2.5-flash', key_env: 'GEMINI_API_KEY' },
52
+ ],
53
+ sharing: { monthly_count: false, share_invitations: true },
54
+ scrub: { names: [] },
55
+ allow_untested: false,
56
+ };
57
+ }
58
+ export function normalizeConfig(raw) {
59
+ const d = defaultConfig();
60
+ return {
61
+ ...d,
62
+ ...raw,
63
+ store: raw?.store ?? d.store,
64
+ models: Array.isArray(raw?.models) ? raw.models : d.models,
65
+ sharing: { ...d.sharing, ...(raw?.sharing ?? {}) },
66
+ scrub: { ...d.scrub, ...(raw?.scrub ?? {}) },
67
+ };
68
+ }
69
+ export function readYaml(file) { return YAML.parse(fs.readFileSync(file, 'utf8')); }
70
+ export function writeYaml(file, data) {
71
+ fs.mkdirSync(path.dirname(file), { recursive: true });
72
+ fs.writeFileSync(file, YAML.stringify(data, { lineWidth: 0 }));
73
+ }
74
+ export function writeJson(file, data) {
75
+ fs.mkdirSync(path.dirname(file), { recursive: true });
76
+ fs.writeFileSync(file, JSON.stringify(data, null, 2) + '\n');
77
+ }
78
+ export function readJson(file) { return JSON.parse(fs.readFileSync(file, 'utf8')); }
79
+ export const nowIso = () => new Date().toISOString();
@@ -0,0 +1,10 @@
1
+ import http from 'node:http';
2
+ import type { Workspace } from '../core/workspace.js';
3
+ /**
4
+ * The Desk: the curator's home. A small web app served from this machine (rung 0) or a
5
+ * company server behind company sign-in (rung 2). It reads and writes the workspace only.
6
+ */
7
+ export declare function deskHandler(ws: Workspace, opts?: {
8
+ user?: (req: http.IncomingMessage) => string | undefined;
9
+ }): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
10
+ export declare function startDesk(ws: Workspace, port?: number, host?: string): Promise<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>>;
@@ -0,0 +1,140 @@
1
+ import fs from 'node:fs';
2
+ import http from 'node:http';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { findBlanks, loadSkill, loadTests } from '../core/skill.js';
6
+ import { listReleases, release, verifyRelease, BlockedError } from '../core/release.js';
7
+ import { approve, clusters, decline, getCorrection, listCorrections, saveCorrection, vote } from '../core/corrections.js';
8
+ import { checkSkill } from '../core/checkup.js';
9
+ import { buildDigest } from '../core/digest.js';
10
+ import { openStore } from '../stores/index.js';
11
+ const MIME = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml', '.woff2': 'font/woff2' };
12
+ function uiDir() {
13
+ const here = path.dirname(fileURLToPath(import.meta.url));
14
+ for (const c of [path.resolve(here, '../../desk-ui'), path.resolve(here, '../../../desk-ui')])
15
+ if (fs.existsSync(c))
16
+ return c;
17
+ throw new Error('desk-ui folder not found');
18
+ }
19
+ /**
20
+ * The Desk: the curator's home. A small web app served from this machine (rung 0) or a
21
+ * company server behind company sign-in (rung 2). It reads and writes the workspace only.
22
+ */
23
+ export function deskHandler(ws, opts = {}) {
24
+ const ui = uiDir();
25
+ const who = (req) => opts.user?.(req) ?? req.headers['x-forwarded-user'] ?? ws.config.curator;
26
+ const routes = [
27
+ ['GET', /^\/api\/state$/, async (_m, _b, req) => {
28
+ const skills = [];
29
+ for (const n of ws.listSkills()) {
30
+ const meta = loadSkill(ws, n);
31
+ const rel = listReleases(ws, n)[0];
32
+ let blanks = null, filled = null;
33
+ try {
34
+ const b = findBlanks(await openStore(ws).readSections(meta));
35
+ blanks = b.length;
36
+ filled = meta.sections.length - new Set(b.map(x => x.section)).size;
37
+ }
38
+ catch { /* store unreachable */ }
39
+ skills.push({ name: n, title: meta.title, owner: meta.owner, version: meta.version, released: rel?.version ?? null, works_on: rel?.works_on ?? {}, starter: meta.starter ?? null, sections: meta.sections.length, blanks, filled, tests: loadTests(ws, n).length });
40
+ }
41
+ const open = listCorrections(ws, 'open');
42
+ const releases = ws.listSkills().reduce((n, s) => n + listReleases(ws, s).length, 0);
43
+ return { org: ws.config.org, rung: ws.config.rung, curator: ws.config.curator, user: who(req), store: openStore(ws).describe(), models: ws.config.models.map(m => ({ name: m.name, provider: m.provider, model: m.model, key_set: m.provider === 'offline' || !!(m.key_env && process.env[m.key_env]) })), audience: ws.config.audience ?? {}, sharing: ws.config.sharing, skills, open: open.length, releases };
44
+ }],
45
+ ['GET', /^\/api\/inbox$/, () => {
46
+ const groups = clusters(listCorrections(ws, 'open'));
47
+ return { groups, resolved: listCorrections(ws).filter(c => c.status === 'approved' || c.status === 'declined').slice(0, 50), snoozed: listCorrections(ws, 'snoozed') };
48
+ }],
49
+ ['GET', /^\/api\/corrections\/(COR-\d+)$/, async (m) => {
50
+ const c = getCorrection(ws, m[1]);
51
+ const meta = loadSkill(ws, c.skill);
52
+ const sections = await openStore(ws).readSections(meta);
53
+ const similar = clusters(listCorrections(ws, 'open')).find(g => g.some(x => x.id === c.id)) ?? [c];
54
+ return { correction: c, similar, skill: meta, sections, tests: loadTests(ws, c.skill) };
55
+ }],
56
+ ['GET', /^\/api\/skills\/([\w-]+)$/, async (m) => {
57
+ const meta = loadSkill(ws, m[1]);
58
+ const sections = await openStore(ws).readSections(meta);
59
+ const rels = listReleases(ws, m[1]).map(r => ({ ...r, verified: verifyRelease(ws, r.skill, r.version) }));
60
+ return { meta, sections, blanks: findBlanks(sections), tests: loadTests(ws, m[1]), releases: rels, checkup: await checkSkill(ws, m[1]) };
61
+ }],
62
+ ['POST', /^\/api\/approve$/, async (_m, b, req) => {
63
+ const out = await approve(ws, { ids: b.ids, section: b.section, old_text: b.old_text, new_text: b.new_text, test: b.test, curator: who(req), offline: !!b.offline });
64
+ return { record: out.record, results: out.results.map(r => ({ ...r, outcomes: r.outcomes.map(o => ({ id: o.id, pass: o.pass, reason: o.reason })) })), receipts: out.receipts };
65
+ }],
66
+ ['POST', /^\/api\/release$/, async (_m, b, req) => {
67
+ const out = await release(ws, b.skill, { version: b.version, signedBy: who(req), offline: !!b.offline, changelog: b.changelog });
68
+ return { record: out.record, results: out.results };
69
+ }],
70
+ ['POST', /^\/api\/decline$/, (_m, b, req) => decline(ws, b.id, who(req), b.note || 'Declined')],
71
+ ['POST', /^\/api\/snooze$/, (_m, b) => { const c = getCorrection(ws, b.id); c.status = b.undo ? 'open' : 'snoozed'; saveCorrection(ws, c); return c; }],
72
+ ['POST', /^\/api\/vote$/, (_m, b) => vote(ws, b.id, b.role, b.vote, b.note)],
73
+ ['POST', /^\/api\/settings$/, (_m, b) => {
74
+ if (b.sharing)
75
+ ws.config.sharing = { ...ws.config.sharing, ...pick(b.sharing, ['monthly_count', 'share_invitations']) };
76
+ ws.saveConfig();
77
+ return { sharing: ws.config.sharing };
78
+ }],
79
+ ['GET', /^\/api\/digest$/, () => buildDigest(ws)],
80
+ ];
81
+ return async (req, res) => {
82
+ const url = new URL(req.url ?? '/', 'http://desk');
83
+ // Block DNS-rebinding: on a laptop, only answer to localhost names.
84
+ const host = String(req.headers.host ?? '').replace(/:\d+$/, '');
85
+ if (!process.env.SKILL_MONSTER_DESK_HOST && !['localhost', '127.0.0.1', '[::1]'].includes(host))
86
+ return send(res, 421, { error: 'Unknown host' });
87
+ try {
88
+ if (url.pathname.startsWith('/api/')) {
89
+ if (req.method === 'POST') {
90
+ // Same-origin only: a page on another site can't approve releases through your browser.
91
+ if (req.headers['x-skill-monster'] !== '1')
92
+ return send(res, 403, { error: 'Missing header' });
93
+ const origin = req.headers.origin;
94
+ if (origin && new URL(origin).host !== req.headers.host)
95
+ return send(res, 403, { error: 'Cross-site request refused' });
96
+ }
97
+ for (const [method, re, fn] of routes) {
98
+ const m = url.pathname.match(re);
99
+ if (m && req.method === method) {
100
+ const body = method === 'POST' ? await readBody(req) : undefined;
101
+ return send(res, 200, await fn(m, body, req));
102
+ }
103
+ }
104
+ return send(res, 404, { error: 'Not found' });
105
+ }
106
+ const rel = url.pathname === '/' ? 'index.html' : url.pathname.slice(1);
107
+ const f = path.join(ui, path.normalize(rel).replace(/^(\.\.[/\\])+/, ''));
108
+ if (!f.startsWith(ui + path.sep) || !fs.existsSync(f) || fs.statSync(f).isDirectory())
109
+ return sendFile(res, path.join(ui, 'index.html'));
110
+ return sendFile(res, f);
111
+ }
112
+ catch (e) {
113
+ if (e instanceof BlockedError)
114
+ return send(res, 422, { error: 'Blocked by check-up', findings: e.findings });
115
+ return send(res, 400, { error: e.message });
116
+ }
117
+ };
118
+ }
119
+ export function startDesk(ws, port = 4747, host = process.env.SKILL_MONSTER_DESK_HOST ?? '127.0.0.1') {
120
+ const server = http.createServer(deskHandler(ws));
121
+ return new Promise((resolve, reject) => { server.once('error', reject); server.listen(port, host, () => resolve(server)); });
122
+ }
123
+ const pick = (o, keys) => Object.fromEntries(keys.filter(k => k in o).map(k => [k, !!o[k]]));
124
+ function send(res, code, data) {
125
+ res.writeHead(code, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' });
126
+ res.end(JSON.stringify(data));
127
+ }
128
+ function sendFile(res, f) {
129
+ res.writeHead(200, { 'Content-Type': MIME[path.extname(f)] ?? 'application/octet-stream', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'" });
130
+ fs.createReadStream(f).pipe(res);
131
+ }
132
+ async function readBody(req) {
133
+ let s = '';
134
+ for await (const ch of req) {
135
+ s += ch;
136
+ if (s.length > 1_000_000)
137
+ throw new Error('Request too large');
138
+ }
139
+ return s ? JSON.parse(s) : {};
140
+ }
@@ -0,0 +1,11 @@
1
+ /** Skill Monster library entry. The CLI, MCP connector and Desk are built on these. */
2
+ export { Workspace, defaultConfig } from './core/workspace.js';
3
+ export { hatch, listStarters, loadStarter } from './core/starters.js';
4
+ export { release, verifyRelease, servedVersion, listReleases, testSkill, BlockedError } from './core/release.js';
5
+ export { previewCorrection, fileCorrection, listCorrections, approve, decline, receiptsFor } from './core/corrections.js';
6
+ export { checkSkill, scanFolder } from './core/checkup.js';
7
+ export { scrub } from './core/scrub.js';
8
+ export { openStore } from './stores/index.js';
9
+ export { buildServer } from './mcp/server.js';
10
+ export { startDesk } from './desk/server.js';
11
+ export type * from './core/types.js';
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /** Skill Monster library entry. The CLI, MCP connector and Desk are built on these. */
2
+ export { Workspace, defaultConfig } from './core/workspace.js';
3
+ export { hatch, listStarters, loadStarter } from './core/starters.js';
4
+ export { release, verifyRelease, servedVersion, listReleases, testSkill, BlockedError } from './core/release.js';
5
+ export { previewCorrection, fileCorrection, listCorrections, approve, decline, receiptsFor } from './core/corrections.js';
6
+ export { checkSkill, scanFolder } from './core/checkup.js';
7
+ export { scrub } from './core/scrub.js';
8
+ export { openStore } from './stores/index.js';
9
+ export { buildServer } from './mcp/server.js';
10
+ export { startDesk } from './desk/server.js';
@@ -0,0 +1,8 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { Workspace } from '../core/workspace.js';
3
+ /**
4
+ * The assistant connector. Runs inside the company (stdio, launched by the assistant app),
5
+ * reads the team's repo or folder, and never calls a model or a Skill Monster service.
6
+ */
7
+ export declare function buildServer(ws: Workspace): McpServer;
8
+ export declare function runMcp(ws?: Workspace): Promise<void>;
@@ -0,0 +1,112 @@
1
+ import path from 'node:path';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { z } from 'zod';
5
+ import { Workspace } from '../core/workspace.js';
6
+ import { loadSkill, trustFooterInstruction } from '../core/skill.js';
7
+ import { readReleasedBundle, servedVersion, listReleases } from '../core/release.js';
8
+ import { fileCorrection, previewCorrection, receiptsFor } from '../core/corrections.js';
9
+ import { hatch, listStarters, loadStarter } from '../core/starters.js';
10
+ import { scanFolder } from '../core/checkup.js';
11
+ const text = (t) => ({ content: [{ type: 'text', text: t }] });
12
+ /**
13
+ * The assistant connector. Runs inside the company (stdio, launched by the assistant app),
14
+ * reads the team's repo or folder, and never calls a model or a Skill Monster service.
15
+ */
16
+ export function buildServer(ws) {
17
+ const server = new McpServer({ name: 'skill-monster', version: '0.1.0' }, {
18
+ instructions: 'Skill Monster serves your team\'s curated skills and carries corrections to their owners. ' +
19
+ 'Before answering a question a skill covers, call get_skill and follow it. ' +
20
+ 'When the user says an answer from a skill was wrong, call preview_correction, show the user exactly what will be sent, ' +
21
+ 'and only after they agree call send_correction. Keep the receipt_token it returns; later call my_receipts with it and tell the user when their fix is live.',
22
+ });
23
+ server.registerTool('list_skills', {
24
+ description: 'List the team skills available here, with their owner and released version.',
25
+ inputSchema: {},
26
+ }, async () => {
27
+ const rows = ws.listSkills().map(n => {
28
+ const m = loadSkill(ws, n);
29
+ const r = listReleases(ws, n)[0];
30
+ return `- ${n} ${r?.version ?? '(unreleased)'}: ${m.description} Owner: ${m.owner}.`;
31
+ });
32
+ return text(rows.length ? rows.join('\n') : 'No skills yet. Ask me to set one up from a starter.');
33
+ });
34
+ server.registerTool('get_skill', {
35
+ description: 'Get the signed, released content of a skill to answer from. Pass the model family you are (Claude, GPT, Gemini…) so you get the newest version that passed its guard tests on your model.',
36
+ inputSchema: { name: z.string(), model: z.string().optional() },
37
+ }, async ({ name, model }) => {
38
+ const rec = servedVersion(ws, name, model) ?? (model ? undefined : listReleases(ws, name)[0]);
39
+ if (!rec)
40
+ return text(`No released version of ${name} has passed its guard tests${model ? ` on ${model}` : ''} yet. Answer without it and say so.`);
41
+ const { text: bundle } = readReleasedBundle(ws, rec);
42
+ return text(`${trustFooterInstruction({ name, version: rec.version })}\n\nSigned by ${rec.signed_by} on ${rec.signed_at.slice(0, 10)}.\n\n${bundle}`);
43
+ });
44
+ const corrInput = {
45
+ skill: z.string().describe('Skill that answered'),
46
+ version: z.string().optional().describe('Version that answered, from the trust footer'),
47
+ question: z.string().describe("The user's question"),
48
+ answer: z.string().optional().describe('The wrong answer, or the relevant part'),
49
+ what_was_wrong: z.string().describe("What the user says is wrong, in the user's words"),
50
+ suggested_rule: z.string().optional().describe('What the rule should say instead'),
51
+ reporter_role: z.string().optional().describe('The reporter\'s team or role, e.g. "Growth". Never a name.'),
52
+ };
53
+ server.registerTool('preview_correction', {
54
+ description: 'Show exactly what a correction will look like after names, customer data, amounts and secrets are removed. Writes nothing. Show this to the user and ask before sending.',
55
+ inputSchema: corrInput,
56
+ }, async (input) => {
57
+ const p = previewCorrection(ws, input);
58
+ const owner = loadSkill(ws, input.skill).owner;
59
+ return text(`Send this correction to ${owner} (owner of ${p.skill})?\n\n` +
60
+ `Skill: ${p.skill} ${p.version}\nWhat was wrong: ${p.what_was_wrong}\nSuggested rule: ${p.suggested_rule || '(none)'}\nQuestion: ${p.question}\nReporter: ${p.reporter_role}\n` +
61
+ `Removed: ${p.removed.length ? p.removed.join(', ') : 'nothing needed removing'}.\n\nNothing leaves the company: it is written to ${path.basename(ws.root)}.`);
62
+ });
63
+ server.registerTool('send_correction', {
64
+ description: 'File the correction after the user agreed to the preview. Returns the correction number and a receipt_token to keep for my_receipts.',
65
+ inputSchema: corrInput,
66
+ }, async (input) => {
67
+ const c = fileCorrection(ws, input);
68
+ const owner = loadSkill(ws, input.skill).owner;
69
+ return text(`Correction ${c.id} filed. Fed to ${owner}'s review queue.\nreceipt_token: ${c.receipt_token}\nTell the user they will get a receipt here when the fix is released.`);
70
+ });
71
+ server.registerTool('my_receipts', {
72
+ description: 'Check whether corrections this user sent are now live. Pass the receipt_token values you kept.',
73
+ inputSchema: { receipt_tokens: z.array(z.string()) },
74
+ }, async ({ receipt_tokens }) => {
75
+ const rs = receiptsFor(ws, receipt_tokens);
76
+ if (!rs.length)
77
+ return text('No receipts yet. The owner has not released these fixes.');
78
+ const invite = ws.config.sharing.share_invitations
79
+ ? '\n\nOffer once: "Want this for your own team\'s playbook? About 15 minutes, no sign-up, nothing leaves the company."' : '';
80
+ return text(rs.map(r => `${r.correction} · ${r.skill} ${r.version}: ${r.message}`).join('\n') + invite);
81
+ });
82
+ server.registerTool('list_starters', {
83
+ description: 'List starter skills a team can set up in about 15 minutes.',
84
+ inputSchema: {},
85
+ }, async () => text(listStarters().map(s => `- ${s.id}: ${s.title}. ${s.tagline} For: ${s.for}.`).join('\n')));
86
+ server.registerTool('starter_interview', {
87
+ description: 'Get the setup interview questions for a starter. Ask the user these one by one; any can be skipped.',
88
+ inputSchema: { starter: z.string() },
89
+ }, async ({ starter }) => {
90
+ const s = loadStarter(starter);
91
+ return text(`${s.title}: ask these, any can be skipped. Unanswered ones become visible blanks, never invented.\n` + s.interview.map((q, i) => `${i + 1}. [${q.key}] ${q.question}${q.hint ? ` (${q.hint})` : ''}`).join('\n'));
92
+ });
93
+ server.registerTool('hatch_starter', {
94
+ description: 'Create a skill from a starter with the interview answers (keys from starter_interview). Unanswered questions stay visible blanks. The curator then releases it from the Desk or CLI.',
95
+ inputSchema: { starter: z.string(), answers: z.record(z.string(), z.string()), name: z.string().optional() },
96
+ }, async ({ starter, answers, name }) => {
97
+ const r = await hatch(ws, starter, answers, { name });
98
+ return text(`${r.meta.name} created: ${r.meta.sections.length} sections, ${r.filled} filled, ${r.blanks} blanks marked, ${r.tests} guard tests seeded.\nNext: the owner runs "skill-monster release ${r.meta.name}" or opens the Desk to release 0.1.0.`);
99
+ });
100
+ server.registerTool('checkup_folder', {
101
+ description: 'Free check-up of a docs folder before it becomes a skill: finds passwords, keys and personal data. Reads locally only.',
102
+ inputSchema: { folder: z.string() },
103
+ }, async ({ folder }) => {
104
+ const r = scanFolder(path.resolve(ws.root, folder));
105
+ return text(`Checked ${r.files.length} files.\n` + (r.findings.length ? r.findings.map(f => `- ${f.message}`).join('\n') : 'Nothing sensitive found.'));
106
+ });
107
+ return server;
108
+ }
109
+ export async function runMcp(ws) {
110
+ const server = buildServer(ws ?? Workspace.find(process.env.SKILL_MONSTER_ROOT));
111
+ await server.connect(new StdioServerTransport());
112
+ }
@@ -0,0 +1,15 @@
1
+ import type { ModelConfig } from '../core/types.js';
2
+ /**
3
+ * Calls the company's own model accounts with the company's own keys.
4
+ * Skill Monster has no model and no proxy of its own.
5
+ */
6
+ export interface Chat {
7
+ system: string;
8
+ user: string;
9
+ maxTokens?: number;
10
+ }
11
+ export declare class MissingKeyError extends Error {
12
+ }
13
+ export declare function ask(m: ModelConfig, chat: Chat): Promise<string>;
14
+ /** Runs a local program (for example Claude Code in print mode) with the prompt on stdin. */
15
+ export declare function runCommand(m: ModelConfig, chat: Chat): Promise<string>;