@profullstack/board-saas 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 +21 -0
- package/README.md +93 -2
- package/bin/board-saas.js +10 -0
- package/package.json +52 -4
- package/public/app.js +95 -0
- package/public/index.html +103 -0
- package/public/style.css +46 -0
- package/src/cli.js +203 -0
- package/src/client.js +100 -0
- package/src/db.js +176 -0
- package/src/experts/cfo.md +27 -0
- package/src/experts/chair.md +55 -0
- package/src/experts/contrarian.md +26 -0
- package/src/experts/founder-time.md +27 -0
- package/src/experts/growth.md +26 -0
- package/src/experts/operator.md +28 -0
- package/src/experts.js +30 -0
- package/src/footers.js +52 -0
- package/src/llm.js +94 -0
- package/src/mail.js +58 -0
- package/src/mcp-stdio.js +24 -0
- package/src/mcp.js +113 -0
- package/src/meeting.js +194 -0
- package/src/pages.js +94 -0
- package/src/render-report.js +160 -0
- package/src/server.js +258 -0
- package/src/service.js +281 -0
- package/src/tui.js +119 -0
- package/src/validate.js +111 -0
package/src/validate.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Every model answer is JSON, validated per round. Validators return { ok, value, error }:
|
|
2
|
+
// value is the cleaned object (trimmed strings, ids normalized), error says what is wrong
|
|
3
|
+
// in words the model can act on when it is asked to try again.
|
|
4
|
+
import { EXPERT_IDS } from './experts.js';
|
|
5
|
+
|
|
6
|
+
/** Pull the first JSON object out of a model reply (fences, prose and <think> blocks around it). */
|
|
7
|
+
export function extractJson(text) {
|
|
8
|
+
let s = String(text ?? '').replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
|
|
9
|
+
const fence = s.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
10
|
+
if (fence) s = fence[1].trim();
|
|
11
|
+
const start = s.indexOf('{');
|
|
12
|
+
if (start < 0) throw new Error('no JSON object in the reply');
|
|
13
|
+
let depth = 0;
|
|
14
|
+
let inStr = false;
|
|
15
|
+
let esc = false;
|
|
16
|
+
for (let i = start; i < s.length; i++) {
|
|
17
|
+
const c = s[i];
|
|
18
|
+
if (inStr) {
|
|
19
|
+
if (esc) esc = false;
|
|
20
|
+
else if (c === '\\') esc = true;
|
|
21
|
+
else if (c === '"') inStr = false;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (c === '"') inStr = true;
|
|
25
|
+
else if (c === '{') depth++;
|
|
26
|
+
else if (c === '}') {
|
|
27
|
+
depth--;
|
|
28
|
+
if (depth === 0) return JSON.parse(s.slice(start, i + 1));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
throw new Error('the JSON object is not closed');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const str = (v) => (typeof v === 'string' ? v.trim() : typeof v === 'number' ? String(v) : '');
|
|
35
|
+
const strList = (v) => (Array.isArray(v) ? v.map(str).filter(Boolean) : typeof v === 'string' && v.trim() ? [v.trim()] : []);
|
|
36
|
+
|
|
37
|
+
/** Match "The CFO", "CFO", "founder_time" etc. to a board id. */
|
|
38
|
+
export function normalizeId(v) {
|
|
39
|
+
const s = str(v).toLowerCase().replace(/^the\s+/, '').replace(/[_\s]+/g, '-');
|
|
40
|
+
if (EXPERT_IDS.includes(s)) return s;
|
|
41
|
+
if (s.includes('cfo')) return 'cfo';
|
|
42
|
+
if (s.includes('growth')) return 'growth';
|
|
43
|
+
if (s.includes('operator') || s.includes('coo')) return 'operator';
|
|
44
|
+
if (s.includes('founder') || s.includes('time')) return 'founder-time';
|
|
45
|
+
if (s.includes('contrarian') || s.includes('investor')) return 'contrarian';
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const fail = (error) => ({ ok: false, error });
|
|
50
|
+
|
|
51
|
+
export function validateBriefCheck(o) {
|
|
52
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
53
|
+
const decision = str(o.decision);
|
|
54
|
+
const options = strList(o.options);
|
|
55
|
+
const constraints = strList(o.constraints);
|
|
56
|
+
const missing = strList(o.missing)
|
|
57
|
+
.map((m) => m.toLowerCase())
|
|
58
|
+
.filter((m) => ['decision', 'options', 'constraints'].includes(m));
|
|
59
|
+
if (!decision) missing.includes('decision') || missing.push('decision');
|
|
60
|
+
if (options.length < 2) missing.includes('options') || missing.push('options');
|
|
61
|
+
if (!constraints.length) missing.includes('constraints') || missing.push('constraints');
|
|
62
|
+
return { ok: true, value: { decision, options, constraints, missing: [...new Set(missing)] } };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function validateVerdict(o, expectedId) {
|
|
66
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
67
|
+
const call = str(o.call);
|
|
68
|
+
const reasons = strList(o.reasons);
|
|
69
|
+
const watch_out = str(o.watch_out ?? o.watchOut ?? o['watch-out']);
|
|
70
|
+
if (!call) return fail('"call" is missing or empty');
|
|
71
|
+
if (reasons.length < 2) return fail('"reasons" must be an array of 3 strings');
|
|
72
|
+
if (!watch_out) return fail('"watch_out" is missing or empty');
|
|
73
|
+
return { ok: true, value: { expert: expectedId, call, reasons: reasons.slice(0, 3), watch_out } };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function relList(v, self) {
|
|
77
|
+
if (!Array.isArray(v)) return [];
|
|
78
|
+
return v
|
|
79
|
+
.map((r) => ({ with: normalizeId(r?.with ?? r?.expert ?? r?.id), why: str(r?.why ?? r?.reason) }))
|
|
80
|
+
.filter((r) => r.with && r.with !== self && r.why);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function validateDebate(o, expectedId) {
|
|
84
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
85
|
+
const position = str(o.position);
|
|
86
|
+
const reply = str(o.reply);
|
|
87
|
+
if (!position) return fail('"position" is missing or empty');
|
|
88
|
+
if (!reply) return fail('"reply" is missing or empty');
|
|
89
|
+
const agrees = relList(o.agrees, expectedId);
|
|
90
|
+
const disagrees = relList(o.disagrees, expectedId);
|
|
91
|
+
const changed_mind = o.changed_mind === true || o.changed_mind === 'true';
|
|
92
|
+
return { ok: true, value: { expert: expectedId, agrees, disagrees, changed_mind, position, reply } };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function validateMinutes(o) {
|
|
96
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
97
|
+
const majority = str(o.majority);
|
|
98
|
+
const recommendation = str(o.recommendation);
|
|
99
|
+
const question = str(o.question);
|
|
100
|
+
const title = str(o.title);
|
|
101
|
+
const clashes = (Array.isArray(o.clashes) ? o.clashes : [])
|
|
102
|
+
.map((c) => ({ topic: str(c?.topic), sides: str(c?.sides), crux: str(c?.crux) }))
|
|
103
|
+
.filter((c) => c.topic && (c.sides || c.crux));
|
|
104
|
+
const dissent = { expert: normalizeId(o.dissent?.expert), argument: str(o.dissent?.argument) };
|
|
105
|
+
if (!majority) return fail('"majority" is missing or empty');
|
|
106
|
+
if (!recommendation) return fail('"recommendation" is missing or empty');
|
|
107
|
+
if (!question) return fail('"question" is missing or empty');
|
|
108
|
+
if (!clashes.length) return fail('"clashes" must list 2 to 4 objects with topic, sides and crux');
|
|
109
|
+
if (!dissent.expert || !dissent.argument) return fail('"dissent" must be {"expert":"<id>","argument":"..."}');
|
|
110
|
+
return { ok: true, value: { title, majority, clashes: clashes.slice(0, 4), dissent, recommendation, question } };
|
|
111
|
+
}
|