ai-advisory-board 0.7.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # CHANGELOG — AI Advisory Board CLI
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4300231: Bug-audit fixes across the discussion engine, web server, and storage layer (full audit log in `docs/development/BUG_AUDIT_2026-06-09.md`):
8
+
9
+ - **Round 1 no longer dies on one flaky member.** `startDiscussion` now tolerates per-member failures like `continueDiscussion` always has — the discussion proceeds with the members that answered, and only fails if _all_ of them do.
10
+ - **Follow-up questions always run a round.** A user follow-up is an explicit, relevant-by-intent question, so `aab discuss follow-up` deliberately ignores a pre-round `conclude` decision and runs the round anyway (resource limits are still enforced by `maxTurns`). The pre-round gate's `request_user_input` clarification path is unchanged.
11
+ - **Web UI double-submits can't corrupt a discussion.** `/api/discussions/:id/{continue,respond,follow-up}` now reject a second request with 409 while a round is in flight, instead of racing two rounds against the same record (last-writer-wins data loss).
12
+ - **HITL replies are recorded against the round they drive**, not the previous round's number.
13
+ - **Business-context writes get rollback snapshots** in `.snapshots/`, like every other persistent entity.
14
+ - **Hand-edited agent files are safer:** a momentarily unreadable `.claude/agents/<slug>.md` is now treated as protected rather than overwritable by `sync-agents`.
15
+ - Correct `✗`-formatted user errors (instead of bare stack-trace errors) for no-active-members, all-members-failed, duplicate member ids, and board validation; `aab doctor` prints the agents path with the platform's separators; start-discussion failure events on the WebSocket are tagged `context: 'start_discussion'`.
16
+
3
17
  ## 0.7.0
4
18
 
5
19
  ### Minor Changes
package/dist/bin/aab.js CHANGED
@@ -1,8 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
+ var __esm = (fn, res, err) => function __init() {
5
+ if (err) throw err[0];
6
+ try {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ } catch (e) {
9
+ throw err = [e], e;
10
+ }
6
11
  };
7
12
  var __export = (target, all) => {
8
13
  for (var name in all)
@@ -1973,6 +1978,7 @@ function readJsonlAll(path) {
1973
1978
  }
1974
1979
 
1975
1980
  // src/storage/fs-storage-service.ts
1981
+ init_errors();
1976
1982
  var FsStorageService = class {
1977
1983
  workspace;
1978
1984
  p;
@@ -2009,7 +2015,7 @@ var FsStorageService = class {
2009
2015
  async saveBoardMember(member) {
2010
2016
  const all = await this.loadBoardMembers();
2011
2017
  if (all.some((m) => m.id === member.id)) {
2012
- throw new Error(`Member with id ${member.id} already exists`);
2018
+ throw new UserError(`Member with id ${member.id} already exists`);
2013
2019
  }
2014
2020
  all.push(member);
2015
2021
  writeJsonAtomic(this.p.members, all, { snapshotDir: this.p.snapshots });
@@ -2063,24 +2069,24 @@ var FsStorageService = class {
2063
2069
  */
2064
2070
  async validateBoardForPersist(board, all, isUpdate) {
2065
2071
  const name = board.name?.trim() ?? "";
2066
- if (name.length < 1) throw new Error("Board name is required.");
2067
- if (name.length > 100) throw new Error("Board name must be \u2264 100 characters.");
2072
+ if (name.length < 1) throw new UserError("Board name is required.");
2073
+ if (name.length > 100) throw new UserError("Board name must be \u2264 100 characters.");
2068
2074
  if (board.description && board.description.length > 500) {
2069
- throw new Error("Board description must be \u2264 500 characters.");
2075
+ throw new UserError("Board description must be \u2264 500 characters.");
2070
2076
  }
2071
2077
  if (!board.slug || !/^[a-z0-9-]+$/.test(board.slug)) {
2072
- throw new Error(`Board slug "${board.slug}" is invalid (expected kebab-case).`);
2078
+ throw new UserError(`Board slug "${board.slug}" is invalid (expected kebab-case).`);
2073
2079
  }
2074
2080
  const slugClash = all.some((b) => b.id !== board.id && b.slug === board.slug);
2075
- if (slugClash) throw new Error(`Board slug "${board.slug}" is already in use.`);
2081
+ if (slugClash) throw new UserError(`Board slug "${board.slug}" is already in use.`);
2076
2082
  const nameClash = all.some(
2077
2083
  (b) => b.id !== board.id && b.name.trim().toLowerCase() === name.toLowerCase()
2078
2084
  );
2079
- if (nameClash) throw new Error(`A board named "${name}" already exists.`);
2085
+ if (nameClash) throw new UserError(`A board named "${name}" already exists.`);
2080
2086
  const members = await this.loadBoardMembers();
2081
2087
  const known = new Set(members.map((m) => m.id));
2082
2088
  const missing = [...new Set(board.memberIds)].filter((id) => !known.has(id));
2083
- if (missing.length > 0) throw new Error(`Board references unknown member id(s): ${missing.join(", ")}`);
2089
+ if (missing.length > 0) throw new UserError(`Board references unknown member id(s): ${missing.join(", ")}`);
2084
2090
  void isUpdate;
2085
2091
  }
2086
2092
  // ============================================================
@@ -2202,18 +2208,18 @@ var FsStorageService = class {
2202
2208
  async saveBusinessContext(context) {
2203
2209
  const all = await this.loadBusinessContext();
2204
2210
  all.push(context);
2205
- writeJsonAtomic(this.p.businessContext, all);
2211
+ writeJsonAtomic(this.p.businessContext, all, { snapshotDir: this.p.snapshots });
2206
2212
  }
2207
2213
  async updateBusinessContext(context) {
2208
2214
  const all = await this.loadBusinessContext();
2209
2215
  const idx = all.findIndex((c2) => c2.id === context.id);
2210
2216
  if (idx === -1) all.push({ ...context, updatedAt: nowIso() });
2211
2217
  else all[idx] = { ...context, updatedAt: nowIso() };
2212
- writeJsonAtomic(this.p.businessContext, all);
2218
+ writeJsonAtomic(this.p.businessContext, all, { snapshotDir: this.p.snapshots });
2213
2219
  }
2214
2220
  async deleteBusinessContext(id) {
2215
2221
  const all = await this.loadBusinessContext();
2216
- writeJsonAtomic(this.p.businessContext, all.filter((c2) => c2.id !== id));
2222
+ writeJsonAtomic(this.p.businessContext, all.filter((c2) => c2.id !== id), { snapshotDir: this.p.snapshots });
2217
2223
  }
2218
2224
  async loadBusinessProfile() {
2219
2225
  if (!existsSync5(this.p.businessProfile)) return null;
@@ -2594,7 +2600,7 @@ function isAabGenerated(path) {
2594
2600
  const raw = readFileSync6(path, "utf8");
2595
2601
  return raw.includes(GENERATED_MARKER);
2596
2602
  } catch {
2597
- return true;
2603
+ return false;
2598
2604
  }
2599
2605
  }
2600
2606
  var KNOWN_COLORS = /* @__PURE__ */ new Set([
@@ -4696,7 +4702,7 @@ function registerDoctorCommand(program) {
4696
4702
  checks.push({
4697
4703
  label: ".claude/agents/<member>.md",
4698
4704
  ok: activeMembers.length === 0 || missing.length === 0,
4699
- detail: activeMembers.length === 0 ? "no active members" : missing.length === 0 ? `${activeMembers.length} agent file(s) at ${projectRoot}\\.claude\\agents\\` : `missing: ${missing.join(", ")} \u2014 run \`aab members sync-agents\``
4705
+ detail: activeMembers.length === 0 ? "no active members" : missing.length === 0 ? `${activeMembers.length} agent file(s) at ${join13(projectRoot, ".claude", "agents")}` : `missing: ${missing.join(", ")} \u2014 run \`aab members sync-agents\``
4700
4706
  });
4701
4707
  checks.push({
4702
4708
  label: "Workspace lock",
@@ -6447,7 +6453,7 @@ async function startDiscussion(opts) {
6447
6453
  opts.onProgress?.({ stage: "initializing" });
6448
6454
  const activeMembers = opts.members.filter((m) => m.isActive);
6449
6455
  if (activeMembers.length === 0) {
6450
- throw new Error("No active board members. Add or activate at least one with `aab members add`.");
6456
+ throw new UserError("No active board members. Add or activate at least one with `aab members add`.");
6451
6457
  }
6452
6458
  const discussionId = generateUUID();
6453
6459
  const now = nowIso();
@@ -6501,36 +6507,40 @@ async function startDiscussion(opts) {
6501
6507
  for (let i = 0; i < activeMembers.length; i++) {
6502
6508
  const member = activeMembers[i];
6503
6509
  opts.onProgress?.({ stage: "generating", memberName: member.name, index: i + 1, total: activeMembers.length });
6504
- const result = await runMember({
6505
- question: opts.question,
6506
- member,
6507
- roundNumber: 1,
6508
- previousResponsesInRound: round1.responses,
6509
- conversationHistory: [],
6510
- businessContext,
6511
- settings: opts.settings,
6512
- storage: opts.storage,
6513
- discussionId,
6514
- projectRoot: opts.projectRoot,
6515
- workspaceRoot: opts.storage.getWorkspaceRoot(),
6516
- signal: opts.signal,
6517
- onActivity: (a) => opts.onProgress?.({ stage: "member_activity", memberName: member.name, ...a })
6518
- });
6519
- round1.responses.push(result.response);
6520
- discussion.responses.push(result.response);
6521
- discussion.totalTurns++;
6522
- totalCostUsd += result.costUsd;
6523
- opts.onProgress?.({
6524
- stage: "member_done",
6525
- memberName: member.name,
6526
- durationMs: result.durationMs,
6527
- costUsd: result.costUsd,
6528
- response: result.response,
6529
- roundNumber: 1
6530
- });
6510
+ try {
6511
+ const result = await runMember({
6512
+ question: opts.question,
6513
+ member,
6514
+ roundNumber: 1,
6515
+ previousResponsesInRound: round1.responses,
6516
+ conversationHistory: [],
6517
+ businessContext,
6518
+ settings: opts.settings,
6519
+ storage: opts.storage,
6520
+ discussionId,
6521
+ projectRoot: opts.projectRoot,
6522
+ workspaceRoot: opts.storage.getWorkspaceRoot(),
6523
+ signal: opts.signal,
6524
+ onActivity: (a) => opts.onProgress?.({ stage: "member_activity", memberName: member.name, ...a })
6525
+ });
6526
+ round1.responses.push(result.response);
6527
+ discussion.responses.push(result.response);
6528
+ discussion.totalTurns++;
6529
+ totalCostUsd += result.costUsd;
6530
+ opts.onProgress?.({
6531
+ stage: "member_done",
6532
+ memberName: member.name,
6533
+ durationMs: result.durationMs,
6534
+ costUsd: result.costUsd,
6535
+ response: result.response,
6536
+ roundNumber: 1
6537
+ });
6538
+ } catch (error) {
6539
+ logger.warn(`[startDiscussion] ${member.name} failed (continuing with other members):`, error);
6540
+ }
6531
6541
  }
6532
6542
  if (round1.responses.length === 0) {
6533
- throw new Error("All board members failed to respond. Check `aab doctor` and try again.");
6543
+ throw new UserError("All board members failed to respond. Check `aab doctor` and try again.");
6534
6544
  }
6535
6545
  round1.completedAt = nowIso();
6536
6546
  opts.onProgress?.({ stage: "orchestrating" });
@@ -6711,7 +6721,7 @@ async function continueDiscussion(opts) {
6711
6721
  };
6712
6722
  if (opts.userFollowUp) {
6713
6723
  const lastResponse = discussion.userResponses[discussion.userResponses.length - 1];
6714
- round.userResponse = lastResponse;
6724
+ round.userResponse = lastResponse ? { ...lastResponse, roundNumber: nextRoundNumber } : lastResponse;
6715
6725
  }
6716
6726
  const conversationHistory = discussion.responses;
6717
6727
  const businessContext = await loadBusinessContextSafe(opts.storage);
@@ -13995,6 +14005,7 @@ async function startUiServer(opts) {
13995
14005
  if (matches.length === 1) return matches[0];
13996
14006
  return null;
13997
14007
  };
14008
+ const runningDiscussions = /* @__PURE__ */ new Set();
13998
14009
  app.post("/api/discussions", async (req, res) => {
13999
14010
  try {
14000
14011
  const { question, memberIds, boardId } = req.body;
@@ -14044,7 +14055,11 @@ async function startUiServer(opts) {
14044
14055
  });
14045
14056
  }).catch((error) => {
14046
14057
  logger.warn("[ui] discussion failed:", error);
14047
- broadcast({ type: "error", message: error instanceof Error ? error.message : String(error) });
14058
+ broadcast({
14059
+ type: "error",
14060
+ context: "start_discussion",
14061
+ message: error instanceof Error ? error.message : String(error)
14062
+ });
14048
14063
  });
14049
14064
  } catch (error) {
14050
14065
  sendError(res, 500, error);
@@ -14082,6 +14097,11 @@ async function startUiServer(opts) {
14082
14097
  });
14083
14098
  return;
14084
14099
  }
14100
+ if (runningDiscussions.has(discussion.id)) {
14101
+ res.status(409).json({ error: "A round is already running for this discussion." });
14102
+ return;
14103
+ }
14104
+ runningDiscussions.add(discussion.id);
14085
14105
  res.status(202).json({ accepted: true });
14086
14106
  const fromRoundNumber = (discussion.rounds[discussion.rounds.length - 1]?.roundNumber ?? 0) + 1;
14087
14107
  logger.info(`[ui] continuing discussion ${discussion.id.slice(0, 8)} \u2192 round ${fromRoundNumber}`);
@@ -14106,7 +14126,7 @@ async function startUiServer(opts) {
14106
14126
  discussionId: discussion.id,
14107
14127
  message: error instanceof Error ? error.message : String(error)
14108
14128
  });
14109
- });
14129
+ }).finally(() => runningDiscussions.delete(discussion.id));
14110
14130
  } catch (error) {
14111
14131
  sendError(res, 500, error);
14112
14132
  }
@@ -14142,6 +14162,11 @@ async function startUiServer(opts) {
14142
14162
  });
14143
14163
  return;
14144
14164
  }
14165
+ if (runningDiscussions.has(discussion.id)) {
14166
+ res.status(409).json({ error: "A round is already running for this discussion." });
14167
+ return;
14168
+ }
14169
+ runningDiscussions.add(discussion.id);
14145
14170
  res.status(202).json({ accepted: true });
14146
14171
  const fromRoundNumber = (discussion.rounds[discussion.rounds.length - 1]?.roundNumber ?? 0) + 1;
14147
14172
  logger.info(`[ui] responding to discussion ${discussion.id.slice(0, 8)}`);
@@ -14168,7 +14193,7 @@ async function startUiServer(opts) {
14168
14193
  discussionId: discussion.id,
14169
14194
  message: error instanceof Error ? error.message : String(error)
14170
14195
  });
14171
- });
14196
+ }).finally(() => runningDiscussions.delete(discussion.id));
14172
14197
  } catch (error) {
14173
14198
  sendError(res, 500, error);
14174
14199
  }
@@ -14260,6 +14285,11 @@ async function startUiServer(opts) {
14260
14285
  });
14261
14286
  return;
14262
14287
  }
14288
+ if (runningDiscussions.has(discussion.id)) {
14289
+ res.status(409).json({ error: "A round is already running for this discussion." });
14290
+ return;
14291
+ }
14292
+ runningDiscussions.add(discussion.id);
14263
14293
  res.status(202).json({ accepted: true });
14264
14294
  const fromRoundNumber = (discussion.rounds[discussion.rounds.length - 1]?.roundNumber ?? 0) + 1;
14265
14295
  logger.info(
@@ -14304,7 +14334,7 @@ async function startUiServer(opts) {
14304
14334
  discussionId: discussion.id,
14305
14335
  message: error instanceof Error ? error.message : String(error)
14306
14336
  });
14307
- });
14337
+ }).finally(() => runningDiscussions.delete(discussion.id));
14308
14338
  } catch (error) {
14309
14339
  sendError(res, 500, error);
14310
14340
  }