negotium 0.2.33 → 0.3.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.
Files changed (66) hide show
  1. package/dist/agent-helpers.js +57 -5
  2. package/dist/agent-helpers.js.map +12 -12
  3. package/dist/background-bash.js +3 -2
  4. package/dist/background-bash.js.map +4 -4
  5. package/dist/browser-runtime.js +3 -2
  6. package/dist/browser-runtime.js.map +4 -4
  7. package/dist/chunk-s2gez3wg.js.map +1 -1
  8. package/dist/{chunk-1y2xw0xe.js → chunk-vvfwqxnh.js} +33 -3
  9. package/dist/{chunk-1y2xw0xe.js.map → chunk-vvfwqxnh.js.map} +8 -8
  10. package/dist/hosted-agent.js +34 -4
  11. package/dist/hosted-agent.js.map +8 -8
  12. package/dist/main.js +1135 -370
  13. package/dist/main.js.map +27 -24
  14. package/dist/mcp-catalog.js +2 -1
  15. package/dist/mcp-catalog.js.map +3 -3
  16. package/dist/mcp-factories.js +585 -255
  17. package/dist/mcp-factories.js.map +16 -14
  18. package/dist/mcp-servers.js +3 -1
  19. package/dist/mcp-servers.js.map +3 -3
  20. package/dist/prompts.js +8 -2
  21. package/dist/prompts.js.map +5 -5
  22. package/dist/query-runtime.js +3 -2
  23. package/dist/query-runtime.js.map +4 -4
  24. package/dist/registry.js +3 -3
  25. package/dist/registry.js.map +2 -2
  26. package/dist/rollout.js +1 -1
  27. package/dist/runtime/cron/mcp-server.ts +2 -2
  28. package/dist/runtime/src/mcp/canonical-bridge-config.ts +1 -1
  29. package/dist/runtime/src/mcp/canonical-proxy-server.ts +74 -1
  30. package/dist/runtime/src/mcp/decision-server.ts +21 -0
  31. package/dist/runtime/src/mcp/factories/decision.ts +178 -0
  32. package/dist/runtime/src/mcp/factories/index.ts +6 -0
  33. package/dist/runtime/src/mcp/runtime-spec.ts +1 -0
  34. package/dist/runtime/src/mcp/session-comm/topic-config.ts +7 -1
  35. package/dist/runtime/src/node-host.ts +1 -0
  36. package/dist/runtime/src/platform/config.ts +2 -1
  37. package/dist/runtime/src/platform/mcp-catalog-policy.ts +1 -0
  38. package/dist/runtime/src/platform/mcp-config.ts +31 -1
  39. package/dist/runtime/src/prompts/builders.ts +5 -0
  40. package/dist/runtime/src/runtime/inbox.ts +6 -4
  41. package/dist/runtime/src/runtime/visual-html.ts +18 -1
  42. package/dist/runtime/src/storage/api-topics.ts +30 -2
  43. package/dist/runtime/src/storage/decisions.ts +231 -0
  44. package/dist/runtime/src/storage/storage-public.ts +2 -0
  45. package/dist/runtime/src/types.ts +13 -0
  46. package/dist/runtime/src/version.ts +1 -1
  47. package/dist/runtime-helpers.js +21 -3
  48. package/dist/runtime-helpers.js.map +5 -5
  49. package/dist/storage.js +263 -57
  50. package/dist/storage.js.map +6 -5
  51. package/dist/types/apps/negotium/src/mcp-servers.d.ts +1 -1
  52. package/dist/types/packages/core/src/mcp/canonical-bridge-config.d.ts +1 -1
  53. package/dist/types/packages/core/src/mcp/factories/decision.d.ts +16 -0
  54. package/dist/types/packages/core/src/mcp/factories/index.d.ts +1 -0
  55. package/dist/types/packages/core/src/mcp/runtime-spec.d.ts +1 -1
  56. package/dist/types/packages/core/src/platform/config.d.ts +2 -1
  57. package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +4 -0
  58. package/dist/types/packages/core/src/storage/api-topics.d.ts +29 -4
  59. package/dist/types/packages/core/src/storage/decisions.d.ts +45 -0
  60. package/dist/types/packages/core/src/storage/storage-public.d.ts +2 -0
  61. package/dist/types/packages/core/src/types.d.ts +12 -0
  62. package/dist/types/packages/core/src/version.d.ts +1 -1
  63. package/dist/vault.js +3 -2
  64. package/dist/vault.js.map +4 -4
  65. package/install-browser-rs.mjs +3 -3
  66. package/package.json +2 -2
package/dist/storage.js CHANGED
@@ -1901,7 +1901,8 @@ function setTopicSurfaces(topicIds, surface) {
1901
1901
  })();
1902
1902
  return changed;
1903
1903
  }
1904
- function getTopicByNameForUser(title, userId, opts = {}) {
1904
+ function getTopicByNameForUser(title, userId, lookupScope) {
1905
+ const opts = "scope" in lookupScope ? {} : lookupScope;
1905
1906
  const trimmed = title.trim();
1906
1907
  const qualified = /^(agent|channel|manager):(.+)$/i.exec(trimmed);
1907
1908
  const requestedKind = qualified ? normalizeTopicKind(qualified[1]?.toLowerCase()) : null;
@@ -2423,6 +2424,198 @@ function findLastSessionIdForAgent(entries, agent) {
2423
2424
  }
2424
2425
  return null;
2425
2426
  }
2427
+ // ../../packages/core/src/storage/decisions.ts
2428
+ var exports_decisions = {};
2429
+ __export(exports_decisions, {
2430
+ writeDecisions: () => writeDecisions,
2431
+ writeDecisionGraphSvg: () => writeDecisionGraphSvg,
2432
+ validateDecisionGraph: () => validateDecisionGraph,
2433
+ updateDecisions: () => updateDecisions,
2434
+ renderDecisionList: () => renderDecisionList,
2435
+ readDecisions: () => readDecisions,
2436
+ getDecisionGraphSvgPath: () => getDecisionGraphSvgPath,
2437
+ getDecisionFilePath: () => getDecisionFilePath,
2438
+ deleteDecisions: () => deleteDecisions,
2439
+ decisionScopeKey: () => decisionScopeKey,
2440
+ createDecisions: () => createDecisions,
2441
+ DECISION_STATUS_VALUES: () => DECISION_STATUS_VALUES
2442
+ });
2443
+ import { existsSync as existsSync4, mkdirSync as mkdirSync6, readFileSync as readFileSync4, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "fs";
2444
+ import { dirname as dirname5, join as join5 } from "path";
2445
+ var DECISION_STATUS_VALUES = [
2446
+ "proposed",
2447
+ "accepted",
2448
+ "executed",
2449
+ "rejected",
2450
+ "superseded"
2451
+ ];
2452
+ function safeDecisionScopeKey(scopeKey) {
2453
+ const safe = sanitizeFileName(scopeKey);
2454
+ if (!safe || safe === "." || safe === "..") {
2455
+ throw new Error(`decisions: refusing unsafe scope key: ${scopeKey}`);
2456
+ }
2457
+ return safe;
2458
+ }
2459
+ function decisionScopeKey(opts) {
2460
+ return opts.topicId?.trim() || opts.session || "default";
2461
+ }
2462
+ function getDecisionFilePath(userId, scopeKey) {
2463
+ return join5(resolveStorageDataDir(), "decisions", `${safeDecisionScopeKey(scopeKey)}.json`);
2464
+ }
2465
+ function getDecisionGraphSvgPath(userId, scopeKey) {
2466
+ return join5(resolveStorageDataDir(), "decision-renders", safeDecisionScopeKey(scopeKey), "latest.svg");
2467
+ }
2468
+ function writeDecisionGraphSvg(userId, scopeKey, svg) {
2469
+ const path = getDecisionGraphSvgPath(userId, scopeKey);
2470
+ mkdirSync6(dirname5(path), { recursive: true });
2471
+ const tmp = `${path}.${process.pid}.tmp`;
2472
+ writeFileSync5(tmp, svg, "utf-8");
2473
+ renameSync4(tmp, path);
2474
+ return path;
2475
+ }
2476
+ function readDecisions(userId, scopeKey) {
2477
+ const path = getDecisionFilePath(userId, scopeKey);
2478
+ if (!existsSync4(path))
2479
+ return [];
2480
+ try {
2481
+ const parsed = JSON.parse(readFileSync4(path, "utf-8"));
2482
+ return Array.isArray(parsed?.decisions) ? parsed.decisions : [];
2483
+ } catch (error) {
2484
+ logger.warn({ err: error, path }, "decisions: failed to read decision store");
2485
+ return [];
2486
+ }
2487
+ }
2488
+ function writeDecisions(userId, scopeKey, decisions) {
2489
+ const path = getDecisionFilePath(userId, scopeKey);
2490
+ mkdirSync6(dirname5(path), { recursive: true });
2491
+ const payload = { version: 1, decisions };
2492
+ const tmp = `${path}.${process.pid}.tmp`;
2493
+ writeFileSync5(tmp, JSON.stringify(payload, null, 2), "utf-8");
2494
+ renameSync4(tmp, path);
2495
+ }
2496
+ function nextDecisionId(decisions) {
2497
+ let max = 0;
2498
+ for (const decision of decisions) {
2499
+ const id = Number(decision.id);
2500
+ if (Number.isInteger(id) && id > max)
2501
+ max = id;
2502
+ }
2503
+ return max + 1;
2504
+ }
2505
+ function normalizedIds(ids) {
2506
+ if (!ids)
2507
+ return;
2508
+ const unique = [...new Set(ids.map((id) => id.trim()).filter(Boolean))];
2509
+ return unique.length > 0 ? unique : undefined;
2510
+ }
2511
+ function validateDecisionGraph(decisions) {
2512
+ const ids = new Set(decisions.map((decision) => decision.id));
2513
+ for (const decision of decisions) {
2514
+ for (const upstream of decision.causedBy ?? []) {
2515
+ if (!ids.has(upstream)) {
2516
+ throw new Error(`Decision #${decision.id} references missing decision #${upstream}.`);
2517
+ }
2518
+ if (upstream === decision.id) {
2519
+ throw new Error(`Decision #${decision.id} cannot cause itself.`);
2520
+ }
2521
+ }
2522
+ }
2523
+ const visiting = new Set;
2524
+ const visited = new Set;
2525
+ const byId = new Map(decisions.map((decision) => [decision.id, decision]));
2526
+ const visit = (id) => {
2527
+ if (visited.has(id))
2528
+ return;
2529
+ if (visiting.has(id))
2530
+ throw new Error(`Decision graph contains a cycle at #${id}.`);
2531
+ visiting.add(id);
2532
+ for (const upstream of byId.get(id)?.causedBy ?? [])
2533
+ visit(upstream);
2534
+ visiting.delete(id);
2535
+ visited.add(id);
2536
+ };
2537
+ for (const id of ids)
2538
+ visit(id);
2539
+ }
2540
+ function createDecisions(decisions, inputs) {
2541
+ const out = [...decisions];
2542
+ const created = [];
2543
+ let id = nextDecisionId(out);
2544
+ for (const input of inputs) {
2545
+ const decision = {
2546
+ id: String(id++),
2547
+ action: input.action.trim(),
2548
+ reasoning: input.reasoning.trim(),
2549
+ agent: input.agent,
2550
+ status: input.status ?? "accepted",
2551
+ timestamp: input.timestamp ?? Date.now(),
2552
+ ...input.model ? { model: input.model } : {},
2553
+ ...normalizedIds(input.causedBy) ? { causedBy: normalizedIds(input.causedBy) } : {}
2554
+ };
2555
+ out.push(decision);
2556
+ created.push(decision);
2557
+ }
2558
+ validateDecisionGraph(out);
2559
+ return { decisions: out, created };
2560
+ }
2561
+ function updateDecisions(decisions, updates) {
2562
+ const out = decisions.map((decision) => ({
2563
+ ...decision,
2564
+ ...decision.causedBy ? { causedBy: [...decision.causedBy] } : {}
2565
+ }));
2566
+ const byId = new Map(out.map((decision) => [decision.id, decision]));
2567
+ const missing = [];
2568
+ for (const update of updates) {
2569
+ const decision = byId.get(update.id);
2570
+ if (!decision) {
2571
+ missing.push(update.id);
2572
+ continue;
2573
+ }
2574
+ if (update.action !== undefined)
2575
+ decision.action = update.action.trim();
2576
+ if (update.reasoning !== undefined)
2577
+ decision.reasoning = update.reasoning.trim();
2578
+ if (update.status !== undefined)
2579
+ decision.status = update.status;
2580
+ if (update.causedBy !== undefined) {
2581
+ const ids = normalizedIds(update.causedBy);
2582
+ if (ids)
2583
+ decision.causedBy = ids;
2584
+ else
2585
+ delete decision.causedBy;
2586
+ }
2587
+ }
2588
+ validateDecisionGraph(out);
2589
+ return { decisions: out, missing };
2590
+ }
2591
+ function deleteDecisions(decisions, opts) {
2592
+ if (opts.all)
2593
+ return { decisions: [], removed: decisions.length };
2594
+ const ids = new Set(opts.ids ?? []);
2595
+ const kept = decisions.filter((decision) => !ids.has(decision.id)).map((decision) => {
2596
+ const causedBy = decision.causedBy?.filter((id) => !ids.has(id));
2597
+ const next = { ...decision };
2598
+ if (causedBy && causedBy.length > 0)
2599
+ next.causedBy = causedBy;
2600
+ else
2601
+ delete next.causedBy;
2602
+ return next;
2603
+ });
2604
+ return { decisions: kept, removed: decisions.length - kept.length };
2605
+ }
2606
+ function renderDecisionList(decisions) {
2607
+ if (decisions.length === 0)
2608
+ return "Decisions (0 recorded)";
2609
+ return [
2610
+ `Decisions (${decisions.length} recorded)`,
2611
+ ...decisions.map((decision) => {
2612
+ const causes = decision.causedBy?.length ? ` <- ${decision.causedBy.map((id) => `#${id}`).join(", ")}` : "";
2613
+ return `[${decision.status}] #${decision.id} ${decision.action}${causes}
2614
+ ${decision.reasoning}`;
2615
+ })
2616
+ ].join(`
2617
+ `);
2618
+ }
2426
2619
  // ../../packages/core/src/storage/forum/index.ts
2427
2620
  var exports_forum = {};
2428
2621
  __export(exports_forum, {
@@ -3054,20 +3247,20 @@ __export(exports_session_asks, {
3054
3247
  import { createHash } from "crypto";
3055
3248
  import {
3056
3249
  closeSync as closeSync2,
3057
- mkdirSync as mkdirSync6,
3250
+ mkdirSync as mkdirSync7,
3058
3251
  openSync as openSync2,
3059
3252
  readdirSync as readdirSync2,
3060
- readFileSync as readFileSync4,
3253
+ readFileSync as readFileSync5,
3061
3254
  statSync as statSync3,
3062
3255
  unlinkSync as unlinkSync5,
3063
- writeFileSync as writeFileSync5
3256
+ writeFileSync as writeFileSync6
3064
3257
  } from "fs";
3065
- import { dirname as dirname5, join as join5 } from "path";
3258
+ import { dirname as dirname6, join as join6 } from "path";
3066
3259
  var PENDING_ASK_TTL_MS = 15 * 60 * 1000;
3067
3260
  function pendingAskDir(userId) {
3068
3261
  const rawUserId = String(userId);
3069
3262
  const safeUserId = /^[A-Za-z0-9][A-Za-z0-9_.@-]{0,255}$/.test(rawUserId) && !rawUserId.includes("..") ? rawUserId : `sha256-${createHash("sha256").update(rawUserId).digest("hex")}`;
3070
- return join5(resolveStorageSessionAsksDir(), safeUserId);
3263
+ return join6(resolveStorageSessionAsksDir(), safeUserId);
3071
3264
  }
3072
3265
  var ASK_FILENAME_PREFIX = "v3-";
3073
3266
  var V2_ASK_FILENAME_PREFIX = "v2-";
@@ -3076,19 +3269,19 @@ function encodeAskKey(key) {
3076
3269
  }
3077
3270
  function pendingAskPath(key) {
3078
3271
  const digest = createHash("sha256").update(encodeAskKey(key)).digest("hex");
3079
- return join5(pendingAskDir(key.userId), `${ASK_FILENAME_PREFIX}${digest}.pending`);
3272
+ return join6(pendingAskDir(key.userId), `${ASK_FILENAME_PREFIX}${digest}.pending`);
3080
3273
  }
3081
3274
  function v2PendingAskPath(key) {
3082
3275
  const encoded = Buffer.from(encodeAskKey(key), "utf8").toString("base64url");
3083
- return join5(pendingAskDir(key.userId), `${V2_ASK_FILENAME_PREFIX}${encoded}.pending`);
3276
+ return join6(pendingAskDir(key.userId), `${V2_ASK_FILENAME_PREFIX}${encoded}.pending`);
3084
3277
  }
3085
3278
  function legacyPendingAskPath(key) {
3086
3279
  if (key.from.includes("/") || key.from.includes("\\") || key.to.includes("/") || key.to.includes("\\") || key.from.includes("\x00") || key.to.includes("\x00")) {
3087
3280
  return null;
3088
3281
  }
3089
3282
  const dir = pendingAskDir(key.userId);
3090
- const candidate = join5(dir, `${key.from}___${key.to}.pending`);
3091
- return dirname5(candidate) === dir ? candidate : null;
3283
+ const candidate = join6(dir, `${key.from}___${key.to}.pending`);
3284
+ return dirname6(candidate) === dir ? candidate : null;
3092
3285
  }
3093
3286
  function parsePendingAskFilename(fileName) {
3094
3287
  if (!fileName.endsWith(".pending"))
@@ -3109,7 +3302,7 @@ function parsePendingAskFilename(fileName) {
3109
3302
  }
3110
3303
  function readPendingAskFile(path, fallback) {
3111
3304
  try {
3112
- const raw = readFileSync4(path, "utf8").trim();
3305
+ const raw = readFileSync5(path, "utf8").trim();
3113
3306
  if (!raw)
3114
3307
  return null;
3115
3308
  if (!raw.startsWith("{")) {
@@ -3160,17 +3353,17 @@ function isStale(record, path) {
3160
3353
  }
3161
3354
  function writePendingAsk(record) {
3162
3355
  const path = pendingAskPath(record);
3163
- mkdirSync6(pendingAskDir(record.userId), { recursive: true });
3164
- writeFileSync5(path, `${JSON.stringify(record)}
3356
+ mkdirSync7(pendingAskDir(record.userId), { recursive: true });
3357
+ writeFileSync6(path, `${JSON.stringify(record)}
3165
3358
  `);
3166
3359
  }
3167
3360
  function writePendingAskIfAbsent(record) {
3168
3361
  const path = pendingAskPath(record);
3169
- mkdirSync6(pendingAskDir(record.userId), { recursive: true });
3362
+ mkdirSync7(pendingAskDir(record.userId), { recursive: true });
3170
3363
  let fd = null;
3171
3364
  try {
3172
3365
  fd = openSync2(path, "wx");
3173
- writeFileSync5(fd, `${JSON.stringify(record)}
3366
+ writeFileSync6(fd, `${JSON.stringify(record)}
3174
3367
  `);
3175
3368
  return true;
3176
3369
  } catch (error) {
@@ -3230,12 +3423,12 @@ function createPendingAsk(args) {
3230
3423
  createdAt: now,
3231
3424
  updatedAt: now
3232
3425
  };
3233
- mkdirSync6(pendingAskDir(args.userId), { recursive: true });
3426
+ mkdirSync7(pendingAskDir(args.userId), { recursive: true });
3234
3427
  for (let attempt = 0;attempt < 2; attempt++) {
3235
3428
  let fd = null;
3236
3429
  try {
3237
3430
  fd = openSync2(path, "wx");
3238
- writeFileSync5(fd, `${JSON.stringify(record)}
3431
+ writeFileSync6(fd, `${JSON.stringify(record)}
3239
3432
  `);
3240
3433
  return { ok: true, record };
3241
3434
  } catch (err) {
@@ -3328,7 +3521,7 @@ function listPendingAsksForCaller(args) {
3328
3521
  const parsed = isV3 ? { from: args.from, to: "" } : parsePendingAskFilename(fileName);
3329
3522
  if (!parsed)
3330
3523
  continue;
3331
- const path = join5(dir, fileName);
3524
+ const path = join6(dir, fileName);
3332
3525
  const record = readPendingAskFile(path, {
3333
3526
  userId: args.userId,
3334
3527
  from: parsed.from,
@@ -3370,7 +3563,7 @@ function deletePendingAsksForTopic(args) {
3370
3563
  }
3371
3564
  let deleted = 0;
3372
3565
  for (const fileName of files) {
3373
- const path = join5(dir, fileName);
3566
+ const path = join6(dir, fileName);
3374
3567
  const parsed = parsePendingAskFilename(fileName);
3375
3568
  const record = readPendingAskFile(path, {
3376
3569
  userId: args.userId,
@@ -3418,8 +3611,8 @@ __export(exports_tasks, {
3418
3611
  createTasks: () => createTasks,
3419
3612
  TASK_STATUS_VALUES: () => TASK_STATUS_VALUES
3420
3613
  });
3421
- import { existsSync as existsSync4, mkdirSync as mkdirSync7, readFileSync as readFileSync5, renameSync as renameSync4, statSync as statSync4, writeFileSync as writeFileSync6 } from "fs";
3422
- import { dirname as dirname6, join as join6 } from "path";
3614
+ import { existsSync as existsSync5, mkdirSync as mkdirSync8, readFileSync as readFileSync6, renameSync as renameSync5, statSync as statSync4, writeFileSync as writeFileSync7 } from "fs";
3615
+ import { dirname as dirname7, join as join7 } from "path";
3423
3616
  var TASK_STATUS_VALUES = ["pending", "in_progress", "completed"];
3424
3617
  function safeTaskScopeKey(scopeKey) {
3425
3618
  const safe = sanitizeFileName(scopeKey);
@@ -3432,14 +3625,14 @@ function taskScopeKey(opts) {
3432
3625
  return opts.topicId?.trim() || opts.session || "default";
3433
3626
  }
3434
3627
  function getTaskFilePath(userId, scopeKey) {
3435
- return join6(resolveStorageDataDir(), "tasks", `${safeTaskScopeKey(scopeKey)}.json`);
3628
+ return join7(resolveStorageDataDir(), "tasks", `${safeTaskScopeKey(scopeKey)}.json`);
3436
3629
  }
3437
3630
  function readTasks(userId, scopeKey) {
3438
3631
  const path = getTaskFilePath(userId, scopeKey);
3439
- if (!existsSync4(path))
3632
+ if (!existsSync5(path))
3440
3633
  return [];
3441
3634
  try {
3442
- const parsed = JSON.parse(readFileSync5(path, "utf-8"));
3635
+ const parsed = JSON.parse(readFileSync6(path, "utf-8"));
3443
3636
  return Array.isArray(parsed?.tasks) ? parsed.tasks : [];
3444
3637
  } catch (e) {
3445
3638
  logger.warn({ err: e, path }, "tasks: failed to read task store");
@@ -3448,11 +3641,11 @@ function readTasks(userId, scopeKey) {
3448
3641
  }
3449
3642
  function writeTasks(userId, scopeKey, tasks) {
3450
3643
  const path = getTaskFilePath(userId, scopeKey);
3451
- mkdirSync7(dirname6(path), { recursive: true });
3644
+ mkdirSync8(dirname7(path), { recursive: true });
3452
3645
  const payload = { version: 1, tasks };
3453
3646
  const tmp = `${path}.${process.pid}.tmp`;
3454
- writeFileSync6(tmp, JSON.stringify(payload, null, 2), "utf-8");
3455
- renameSync4(tmp, path);
3647
+ writeFileSync7(tmp, JSON.stringify(payload, null, 2), "utf-8");
3648
+ renameSync5(tmp, path);
3456
3649
  }
3457
3650
  function taskFileMtimeNs(userId, scopeKey) {
3458
3651
  try {
@@ -3554,8 +3747,8 @@ __export(exports_token_stats, {
3554
3747
  calcCost: () => calcCost
3555
3748
  });
3556
3749
  import { createHash as createHash2 } from "crypto";
3557
- import { mkdirSync as mkdirSync8, writeFileSync as writeFileSync7 } from "fs";
3558
- import { join as join7 } from "path";
3750
+ import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync8 } from "fs";
3751
+ import { join as join8 } from "path";
3559
3752
  function emptyBucket() {
3560
3753
  return {
3561
3754
  inputTokens: 0,
@@ -3573,8 +3766,8 @@ function tokenStatsFileId(userId) {
3573
3766
  function queriesPath(userId) {
3574
3767
  const fileId = tokenStatsFileId(userId);
3575
3768
  const logDir = resolveStorageLogDir();
3576
- mkdirSync8(logDir, { recursive: true });
3577
- return join7(logDir, `token-queries-${fileId}.jsonl`);
3769
+ mkdirSync9(logDir, { recursive: true });
3770
+ return join8(logDir, `token-queries-${fileId}.jsonl`);
3578
3771
  }
3579
3772
  function loadRecords(userId) {
3580
3773
  try {
@@ -3655,7 +3848,7 @@ function deleteTopicStats(userId, topicId) {
3655
3848
  return true;
3656
3849
  }
3657
3850
  });
3658
- writeFileSync7(path, kept.length > 0 ? `${kept.join(`
3851
+ writeFileSync8(path, kept.length > 0 ? `${kept.join(`
3659
3852
  `)}
3660
3853
  ` : "", "utf-8");
3661
3854
  } catch (e) {
@@ -3761,8 +3954,8 @@ __export(exports_topic_archive, {
3761
3954
  archiveTopicMessages: () => archiveTopicMessages,
3762
3955
  archiveConversationEvents: () => archiveConversationEvents
3763
3956
  });
3764
- import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync8 } from "fs";
3765
- import { join as join9 } from "path";
3957
+ import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync9 } from "fs";
3958
+ import { join as join10 } from "path";
3766
3959
 
3767
3960
  // ../../packages/core/src/agents/memory-archive-policy.ts
3768
3961
  function countMemoryArchiveExchanges(rows) {
@@ -3850,50 +4043,50 @@ __export(exports_wiki, {
3850
4043
  getTopicMemoryFilePaths: () => getTopicMemoryFilePaths,
3851
4044
  getSharedWikiDir: () => getSharedWikiDir
3852
4045
  });
3853
- import { existsSync as existsSync5, readdirSync as readdirSync3, statSync as statSync5 } from "fs";
3854
- import { basename as basename2, dirname as dirname7, join as join8 } from "path";
4046
+ import { existsSync as existsSync6, readdirSync as readdirSync3, statSync as statSync5 } from "fs";
4047
+ import { basename as basename2, dirname as dirname8, join as join9 } from "path";
3855
4048
  function getWikiDir(_userId, workspaceDir = resolveStorageWorkspaceDir()) {
3856
- return join8(workspaceDir, "wiki");
4049
+ return join9(workspaceDir, "wiki");
3857
4050
  }
3858
4051
  function getSharedWikiDir(workspaceDir = resolveStorageWorkspaceDir()) {
3859
- return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() : join8(workspaceDir, "wiki");
4052
+ return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() : join9(workspaceDir, "wiki");
3860
4053
  }
3861
4054
  function findLatestSummaryFile(wikiDir, safeTopic) {
3862
- const summariesDir = join8(wikiDir, "summaries");
3863
- if (!existsSync5(summariesDir))
4055
+ const summariesDir = join9(wikiDir, "summaries");
4056
+ if (!existsSync6(summariesDir))
3864
4057
  return null;
3865
4058
  const files = readdirSync3(summariesDir).filter((f) => f.endsWith(".md") && f.match(new RegExp(`^\\d{4}-\\d{2}-\\d{2}-${safeTopic}(\\.md|~\\d+\\.md)$`)) && !f.endsWith("-sent-files.md")).sort((left, right) => {
3866
- const mtimeDelta = statSync5(join8(summariesDir, right)).mtimeMs - statSync5(join8(summariesDir, left)).mtimeMs;
4059
+ const mtimeDelta = statSync5(join9(summariesDir, right)).mtimeMs - statSync5(join9(summariesDir, left)).mtimeMs;
3867
4060
  return mtimeDelta || right.localeCompare(left, undefined, { numeric: true });
3868
4061
  });
3869
- return files.length > 0 ? join8(summariesDir, files[0]) : null;
4062
+ return files.length > 0 ? join9(summariesDir, files[0]) : null;
3870
4063
  }
3871
4064
  function getTopicMemoryFilePaths(_userId, topicName, forkOrigin, workspaceDir = resolveStorageWorkspaceDir()) {
3872
4065
  const wikiDir = getSharedWikiDir(workspaceDir);
3873
4066
  const resolveBrief = (name) => {
3874
4067
  const safe = sanitizeTopicName(name, true);
3875
- const brief = join8(wikiDir, "topic", `${safe}.md`);
4068
+ const brief = join9(wikiDir, "topic", `${safe}.md`);
3876
4069
  const latestSummary = findLatestSummaryFile(wikiDir, safe);
3877
4070
  return { brief, latestSummary };
3878
4071
  };
3879
- const archiveDir = join8(wikiDir, "archive");
4072
+ const archiveDir = join9(wikiDir, "archive");
3880
4073
  const archiveExistsFor = (name) => {
3881
4074
  const safe = sanitizeTopicName(name);
3882
- return existsSync5(archiveDir) && readdirSync3(archiveDir).some((f) => f.endsWith(".jsonl") && f.startsWith(`${safe}_`));
4075
+ return existsSync6(archiveDir) && readdirSync3(archiveDir).some((f) => f.endsWith(".jsonl") && f.startsWith(`${safe}_`));
3883
4076
  };
3884
4077
  const sourceTopic = forkOrigin ?? topicName;
3885
4078
  const hasArchive = archiveExistsFor(sourceTopic) || (forkOrigin ? archiveExistsFor(topicName) : false);
3886
4079
  const target = resolveBrief(sourceTopic);
3887
- if (existsSync5(target.brief)) {
4080
+ if (existsSync6(target.brief)) {
3888
4081
  return {
3889
- memoryDir: dirname7(target.brief),
4082
+ memoryDir: dirname8(target.brief),
3890
4083
  memoryFiles: [basename2(target.brief)],
3891
4084
  ...target.latestSummary ? { latestSummaryFile: target.latestSummary } : {},
3892
4085
  ...hasArchive ? { hasArchive: true } : {}
3893
4086
  };
3894
4087
  }
3895
4088
  return {
3896
- memoryDir: join8(wikiDir, "topic"),
4089
+ memoryDir: join9(wikiDir, "topic"),
3897
4090
  memoryFiles: [],
3898
4091
  ...target.latestSummary ? { latestSummaryFile: target.latestSummary } : {},
3899
4092
  ...hasArchive ? { hasArchive: true } : {}
@@ -3906,8 +4099,8 @@ function archiveTopicMessages(topicId, topicTitle, options = {}) {
3906
4099
  if (rows.length === 0)
3907
4100
  return null;
3908
4101
  const safeTopic = sanitizeTopicName(topicTitle, true);
3909
- const archiveDir = join9(getSharedWikiDir(), "archive");
3910
- mkdirSync9(archiveDir, { recursive: true });
4102
+ const archiveDir = join10(getSharedWikiDir(), "archive");
4103
+ mkdirSync10(archiveDir, { recursive: true });
3911
4104
  const date = new Date().toISOString().slice(0, 10);
3912
4105
  const reasonSuffix = options.reason && options.reason !== "delete" ? `_${options.reason}` : "";
3913
4106
  let filename;
@@ -3919,9 +4112,9 @@ function archiveTopicMessages(topicId, topicTitle, options = {}) {
3919
4112
  let path;
3920
4113
  while (true) {
3921
4114
  filename = `${safeTopic}_${date}${reasonSuffix}${counter === 1 ? "" : `_${counter}`}.jsonl`;
3922
- path = join9(archiveDir, filename);
4115
+ path = join10(archiveDir, filename);
3923
4116
  try {
3924
- writeFileSync8(path, body, { flag: "wx" });
4117
+ writeFileSync9(path, body, { flag: "wx" });
3925
4118
  break;
3926
4119
  } catch (err) {
3927
4120
  if (err.code !== "EEXIST")
@@ -3964,8 +4157,8 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
3964
4157
  const entries = readRawConversation(userId, topicTitle);
3965
4158
  if (entries.length === 0)
3966
4159
  return null;
3967
- const archiveDir = join9(getSharedWikiDir(), "archive");
3968
- mkdirSync9(archiveDir, { recursive: true });
4160
+ const archiveDir = join10(getSharedWikiDir(), "archive");
4161
+ mkdirSync10(archiveDir, { recursive: true });
3969
4162
  const safeTopic = sanitizeTopicName(topicTitle, true);
3970
4163
  const date = new Date().toISOString().slice(0, 10);
3971
4164
  const reasonSuffix = options.reason && options.reason !== "delete" ? `_${options.reason}` : "";
@@ -3992,9 +4185,9 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
3992
4185
  let counter = 1;
3993
4186
  while (true) {
3994
4187
  const suffix = counter === 1 ? "" : `_${counter}`;
3995
- const path = join9(archiveDir, `${safeTopic}_${date}${reasonSuffix}_events${suffix}.jsonl`);
4188
+ const path = join10(archiveDir, `${safeTopic}_${date}${reasonSuffix}_events${suffix}.jsonl`);
3996
4189
  try {
3997
- writeFileSync8(path, body, { flag: "wx" });
4190
+ writeFileSync9(path, body, { flag: "wx" });
3998
4191
  logger.info({ topicId, topicTitle, archive: path, eventCount: entries.length }, "archiveConversationEvents: archived raw conversation events");
3999
4192
  return { path, eventCount: entries.length };
4000
4193
  } catch (error) {
@@ -4181,6 +4374,8 @@ export {
4181
4374
  writeTasks,
4182
4375
  writeSentFileLog,
4183
4376
  writeLog,
4377
+ writeDecisions,
4378
+ writeDecisionGraphSvg,
4184
4379
  wikiSummaryStorageSlug,
4185
4380
  wikiSummarySlug,
4186
4381
  exports_wiki_summary_names as wikiSummaryNames,
@@ -4189,9 +4384,11 @@ export {
4189
4384
  exports_wiki as wiki,
4190
4385
  waitForRuntimeProcessLease,
4191
4386
  waitForRequiredRuntimeProcessLease,
4387
+ validateDecisionGraph,
4192
4388
  upsertTopic,
4193
4389
  updateTopicThreadId,
4194
4390
  updateTasks,
4391
+ updateDecisions,
4195
4392
  updateApiMessageUsage,
4196
4393
  updateApiMessageText,
4197
4394
  updateApiMessageSubagentCard,
@@ -4240,6 +4437,7 @@ export {
4240
4437
  replaceConversationStrict,
4241
4438
  reparentTopicChildren,
4242
4439
  renderTaskList,
4440
+ renderDecisionList,
4243
4441
  renameTopic,
4244
4442
  removeTopic,
4245
4443
  removeSentFilesForTopic,
@@ -4251,6 +4449,7 @@ export {
4251
4449
  readTasks,
4252
4450
  readSentFilesForTopic,
4253
4451
  readRawConversation,
4452
+ readDecisions,
4254
4453
  readConversation,
4255
4454
  quarantineForeignAskUserGates,
4256
4455
  quarantineAskUserGate,
@@ -4312,6 +4511,8 @@ export {
4312
4511
  getGlobalAiName,
4313
4512
  getTopicByName2 as getForumTopicByName,
4314
4513
  getDmSessionId,
4514
+ getDecisionGraphSvgPath,
4515
+ getDecisionFilePath,
4315
4516
  getConversationPath,
4316
4517
  getCommunicateThreadId,
4317
4518
  getApiTopicConfig,
@@ -4335,12 +4536,16 @@ export {
4335
4536
  deleteTasks,
4336
4537
  deletePendingAsksForTopic,
4337
4538
  deleteMessagesForTopic,
4539
+ deleteDecisions,
4338
4540
  deleteApiTopicConfig,
4339
4541
  defaultTopicSurface,
4340
4542
  defaultSurfaceScope,
4543
+ exports_decisions as decisions,
4544
+ decisionScopeKey,
4341
4545
  db2 as db,
4342
4546
  createTasks,
4343
4547
  createPendingAsk,
4548
+ createDecisions,
4344
4549
  copyMessagesForTopic,
4345
4550
  copyMessageSnapshotToTopic,
4346
4551
  exports_conversations as conversations,
@@ -4379,7 +4584,8 @@ export {
4379
4584
  PROCESS_LEASE_HEARTBEAT_MS,
4380
4585
  PENDING_ASK_TTL_MS,
4381
4586
  DEFAULT_AI_NAME,
4587
+ DECISION_STATUS_VALUES,
4382
4588
  ConversationLogDivergedError
4383
4589
  };
4384
4590
 
4385
- //# debugId=6AE30BDF1C411C3464756E2164756E21
4591
+ //# debugId=89A366518555705864756E2164756E21