@profullstack/board-saas 0.0.0-stage → 0.1.1
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 +111 -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 +35 -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 +195 -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 +187 -0
package/src/validate.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
const balanced = balancedObject(s, start);
|
|
14
|
+
if (balanced) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(balanced);
|
|
17
|
+
} catch {
|
|
18
|
+
/* try the repair below */
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const end = s.lastIndexOf('}');
|
|
22
|
+
if (end <= start) throw new Error('the JSON object is not closed');
|
|
23
|
+
return JSON.parse(repairJson(s.slice(start, end + 1)));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function balancedObject(s, start) {
|
|
27
|
+
let depth = 0;
|
|
28
|
+
let inStr = false;
|
|
29
|
+
let esc = false;
|
|
30
|
+
for (let i = start; i < s.length; i++) {
|
|
31
|
+
const c = s[i];
|
|
32
|
+
if (inStr) {
|
|
33
|
+
if (esc) esc = false;
|
|
34
|
+
else if (c === '\\') esc = true;
|
|
35
|
+
else if (c === '"') inStr = false;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (c === '"') inStr = true;
|
|
39
|
+
else if (c === '{') depth++;
|
|
40
|
+
else if (c === '}') {
|
|
41
|
+
depth--;
|
|
42
|
+
if (depth === 0) return s.slice(start, i + 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Fix the mistakes small models make in JSON without changing what they said: a double
|
|
50
|
+
* quote inside a string value (escaped when the next non-space character could not follow
|
|
51
|
+
* a closing quote), raw newlines and tabs inside strings, and trailing commas.
|
|
52
|
+
*/
|
|
53
|
+
export function repairJson(s) {
|
|
54
|
+
let out = '';
|
|
55
|
+
let inStr = false;
|
|
56
|
+
let esc = false;
|
|
57
|
+
let strStart = 0;
|
|
58
|
+
const stack = [];
|
|
59
|
+
for (let i = 0; i < s.length; i++) {
|
|
60
|
+
const c = s[i];
|
|
61
|
+
if (!inStr) {
|
|
62
|
+
if (c === '"') {
|
|
63
|
+
inStr = true;
|
|
64
|
+
strStart = out.length;
|
|
65
|
+
} else if (c === '{' || c === '[') stack.push(c);
|
|
66
|
+
else if (c === '}' || c === ']') {
|
|
67
|
+
const want = c === '}' ? '{' : '[';
|
|
68
|
+
if (stack.at(-1) !== want) {
|
|
69
|
+
// "key": inside an array already closed it, or the model closed something never opened.
|
|
70
|
+
if (c === '}' && stack.at(-1) === '[') {
|
|
71
|
+
stack.pop();
|
|
72
|
+
out += ']';
|
|
73
|
+
} else continue;
|
|
74
|
+
}
|
|
75
|
+
stack.pop();
|
|
76
|
+
}
|
|
77
|
+
out += c;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (esc) {
|
|
81
|
+
esc = false;
|
|
82
|
+
out += c;
|
|
83
|
+
} else if (c === '\\') {
|
|
84
|
+
esc = true;
|
|
85
|
+
out += c;
|
|
86
|
+
} else if (c === '\n') out += '\\n';
|
|
87
|
+
else if (c === '\r') continue;
|
|
88
|
+
else if (c === '\t') out += '\\t';
|
|
89
|
+
else if (c === '"') {
|
|
90
|
+
let j = i + 1;
|
|
91
|
+
while (j < s.length && /\s/.test(s[j])) j++;
|
|
92
|
+
const next = s[j];
|
|
93
|
+
if (next === undefined || next === ',' || next === '}' || next === ']' || next === ':') {
|
|
94
|
+
inStr = false;
|
|
95
|
+
if (next === ':' && stack.at(-1) === '[') {
|
|
96
|
+
// A key inside an array: the model forgot to close the array before it.
|
|
97
|
+
const comma = out.lastIndexOf(',', strStart);
|
|
98
|
+
if (comma >= 0) {
|
|
99
|
+
out = `${out.slice(0, comma)}]${out.slice(comma)}`;
|
|
100
|
+
stack.pop();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
out += c;
|
|
104
|
+
} else out += '\\"';
|
|
105
|
+
} else out += c;
|
|
106
|
+
}
|
|
107
|
+
return out.replace(/,\s*([}\]])/g, '$1');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const str = (v) => (typeof v === 'string' ? v.trim() : typeof v === 'number' ? String(v) : '');
|
|
111
|
+
const strList = (v) => (Array.isArray(v) ? v.map(str).filter(Boolean) : typeof v === 'string' && v.trim() ? [v.trim()] : []);
|
|
112
|
+
|
|
113
|
+
/** Match "The CFO", "CFO", "founder_time" etc. to a board id. */
|
|
114
|
+
export function normalizeId(v) {
|
|
115
|
+
const s = str(v).toLowerCase().replace(/^the\s+/, '').replace(/[_\s]+/g, '-');
|
|
116
|
+
if (EXPERT_IDS.includes(s)) return s;
|
|
117
|
+
if (s.includes('cfo')) return 'cfo';
|
|
118
|
+
if (s.includes('growth')) return 'growth';
|
|
119
|
+
if (s.includes('operator') || s.includes('coo')) return 'operator';
|
|
120
|
+
if (s.includes('founder') || s.includes('time')) return 'founder-time';
|
|
121
|
+
if (s.includes('contrarian') || s.includes('investor')) return 'contrarian';
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const fail = (error) => ({ ok: false, error });
|
|
126
|
+
|
|
127
|
+
export function validateBriefCheck(o) {
|
|
128
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
129
|
+
const decision = str(o.decision);
|
|
130
|
+
const options = strList(o.options);
|
|
131
|
+
const constraints = strList(o.constraints);
|
|
132
|
+
const missing = strList(o.missing)
|
|
133
|
+
.map((m) => m.toLowerCase())
|
|
134
|
+
.filter((m) => ['decision', 'options', 'constraints'].includes(m));
|
|
135
|
+
if (!decision) missing.includes('decision') || missing.push('decision');
|
|
136
|
+
if (options.length < 2) missing.includes('options') || missing.push('options');
|
|
137
|
+
if (!constraints.length) missing.includes('constraints') || missing.push('constraints');
|
|
138
|
+
return { ok: true, value: { decision, options, constraints, missing: [...new Set(missing)] } };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function validateVerdict(o, expectedId) {
|
|
142
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
143
|
+
const call = str(o.call);
|
|
144
|
+
const reasons = strList(o.reasons);
|
|
145
|
+
const watch_out = str(o.watch_out ?? o.watchOut ?? o['watch-out']);
|
|
146
|
+
if (!call) return fail('"call" is missing or empty');
|
|
147
|
+
if (reasons.length < 2) return fail('"reasons" must be an array of 3 strings');
|
|
148
|
+
if (!watch_out) return fail('"watch_out" is missing or empty');
|
|
149
|
+
return { ok: true, value: { expert: expectedId, call, reasons: reasons.slice(0, 3), watch_out } };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function relList(v, self) {
|
|
153
|
+
if (!Array.isArray(v)) return [];
|
|
154
|
+
return v
|
|
155
|
+
.map((r) => ({ with: normalizeId(r?.with ?? r?.expert ?? r?.id), why: str(r?.why ?? r?.reason) }))
|
|
156
|
+
.filter((r) => r.with && r.with !== self && r.why);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function validateDebate(o, expectedId) {
|
|
160
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
161
|
+
const position = str(o.position);
|
|
162
|
+
const reply = str(o.reply);
|
|
163
|
+
if (!position) return fail('"position" is missing or empty');
|
|
164
|
+
if (!reply) return fail('"reply" is missing or empty');
|
|
165
|
+
const agrees = relList(o.agrees, expectedId);
|
|
166
|
+
const disagrees = relList(o.disagrees, expectedId);
|
|
167
|
+
const changed_mind = o.changed_mind === true || o.changed_mind === 'true';
|
|
168
|
+
return { ok: true, value: { expert: expectedId, agrees, disagrees, changed_mind, position, reply } };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function validateMinutes(o) {
|
|
172
|
+
if (!o || typeof o !== 'object') return fail('reply must be a JSON object');
|
|
173
|
+
const majority = str(o.majority);
|
|
174
|
+
const recommendation = str(o.recommendation);
|
|
175
|
+
const question = str(o.question);
|
|
176
|
+
const title = str(o.title);
|
|
177
|
+
const clashes = (Array.isArray(o.clashes) ? o.clashes : [])
|
|
178
|
+
.map((c) => ({ topic: str(c?.topic), sides: str(c?.sides), crux: str(c?.crux) }))
|
|
179
|
+
.filter((c) => c.topic && (c.sides || c.crux));
|
|
180
|
+
const dissent = { expert: normalizeId(o.dissent?.expert), argument: str(o.dissent?.argument) };
|
|
181
|
+
if (!majority) return fail('"majority" is missing or empty');
|
|
182
|
+
if (!recommendation) return fail('"recommendation" is missing or empty');
|
|
183
|
+
if (!question) return fail('"question" is missing or empty');
|
|
184
|
+
if (!clashes.length) return fail('"clashes" must list 2 to 4 objects with topic, sides and crux');
|
|
185
|
+
if (!dissent.expert || !dissent.argument) return fail('"dissent" must be {"expert":"<id>","argument":"..."}');
|
|
186
|
+
return { ok: true, value: { title, majority, clashes: clashes.slice(0, 4), dissent, recommendation, question } };
|
|
187
|
+
}
|