@profullstack/board-saas 0.1.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profullstack/board-saas",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Board as a Service: paste a decision brief, five AI advisors (CFO, Growth, Operator, Founder-Time, Contrarian) debate it in three rounds and a chair writes the minutes. Web, HTTP API, CLI, TUI and MCP. Runs on c0mpute.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/cli.js CHANGED
@@ -60,7 +60,7 @@ const err = (m) => process.stderr.write(`${m}\n`);
60
60
 
61
61
  export async function main(argv = process.argv.slice(2)) {
62
62
  const { args, flags } = parse(argv);
63
- const cmd = args.shift();
63
+ const cmd = args.shift() ?? (flags.version || flags.v ? 'version' : flags.help || flags.h ? 'help' : undefined);
64
64
  const cfg = loadConfig();
65
65
  if (flags.url) cfg.url = String(flags.url).replace(/\/+$/, '');
66
66
  if (flags.key) cfg.key = String(flags.key);
package/src/client.js CHANGED
@@ -89,8 +89,19 @@ export class BoardClient {
89
89
  /** Poll until the meeting leaves the running states. onUpdate(view) each poll. */
90
90
  async waitFor(id, { onUpdate = () => {}, intervalMs = 4000, timeoutMs = 20 * 60_000 } = {}) {
91
91
  const until = Date.now() + timeoutMs;
92
+ let misses = 0;
92
93
  for (;;) {
93
- const v = await this.getMeeting(id);
94
+ let v;
95
+ try {
96
+ v = await this.getMeeting(id);
97
+ misses = 0;
98
+ } catch (e) {
99
+ // A relay restart or a dropped connection must not lose a meeting that is still running.
100
+ const transient = !e.status || e.status >= 500;
101
+ if (!transient || ++misses > 15 || Date.now() > until) throw e;
102
+ await new Promise((r) => setTimeout(r, intervalMs * 2));
103
+ continue;
104
+ }
94
105
  onUpdate(v);
95
106
  if (!['queued', 'checking', 'running'].includes(v.status)) return v;
96
107
  if (Date.now() > until) return v;
package/src/experts.js CHANGED
@@ -22,7 +22,12 @@ const cache = new Map();
22
22
  export function persona(id) {
23
23
  if (!cache.has(id)) {
24
24
  const url = new URL(`./experts/${id}.md`, import.meta.url);
25
- cache.set(id, stripFrontmatter(readFileSync(url, 'utf8')));
25
+ let text = stripFrontmatter(readFileSync(url, 'utf8'));
26
+ // The chair skill ends with the plugin's meeting.json file format and how to render it.
27
+ // Here the service assembles meeting.json itself, and a small model shown that schema
28
+ // tries to write the whole file instead of the minutes, so the section is left out.
29
+ if (id === 'chair') text = text.replace(/\n## Report data[\s\S]*$/, '').trim();
30
+ cache.set(id, text);
26
31
  }
27
32
  return cache.get(id);
28
33
  }
package/src/meeting.js CHANGED
@@ -10,7 +10,8 @@ import { validateBriefCheck, validateDebate, validateMinutes, validateVerdict }
10
10
 
11
11
  export const MAX_BRIEF = 6000;
12
12
 
13
- const JSON_ONLY = 'Reply with ONLY one JSON object. No prose before or after it, no code fences, no thinking out loud.';
13
+ const JSON_ONLY =
14
+ 'Reply with ONLY one JSON object. No prose before or after it, no code fences, no thinking out loud. Inside the string values never use the double quote character; use single quotes for any quotation.';
14
15
 
15
16
  function briefBlock(b) {
16
17
  const lines = [`Decision: ${b.decision}`, 'Options:', ...b.options.map((o) => `- ${o}`), 'Constraints:', ...b.constraints.map((c) => `- ${c}`)];
package/src/service.js CHANGED
@@ -267,7 +267,7 @@ export function createService({ db, env = process.env, model, mailer, log = cons
267
267
  const cur = db.meeting(id);
268
268
  db.updateMeeting(id, { status: 'failed', error: msg, finished_at: Date.now() });
269
269
  if (cur.account_id && cur.paid_with && cur.paid_with !== 'admin') db.refund(cur.account_id, cur.paid_with === 'free' ? 'free' : 'credit');
270
- mlog(`failed: ${e?.message ?? e}${e?.raw ? ` raw=${JSON.stringify(e.raw.slice(0, 300))}` : ''}`);
270
+ mlog(`failed: ${e?.message ?? e}${e?.raw ? ` raw=${JSON.stringify(e.raw.slice(0, 1500))}` : ''}`);
271
271
  }
272
272
  }
273
273
 
package/src/validate.js CHANGED
@@ -10,6 +10,20 @@ export function extractJson(text) {
10
10
  if (fence) s = fence[1].trim();
11
11
  const start = s.indexOf('{');
12
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) {
13
27
  let depth = 0;
14
28
  let inStr = false;
15
29
  let esc = false;
@@ -25,10 +39,72 @@ export function extractJson(text) {
25
39
  else if (c === '{') depth++;
26
40
  else if (c === '}') {
27
41
  depth--;
28
- if (depth === 0) return JSON.parse(s.slice(start, i + 1));
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;
29
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;
30
106
  }
31
- throw new Error('the JSON object is not closed');
107
+ return out.replace(/,\s*([}\]])/g, '$1');
32
108
  }
33
109
 
34
110
  const str = (v) => (typeof v === 'string' ? v.trim() : typeof v === 'number' ? String(v) : '');