@wrongstack/core 0.1.10 → 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 (54) hide show
  1. package/dist/{agent-bridge-6KPqsFx6.d.ts → agent-bridge-C3DUGjSb.d.ts} +1 -1
  2. package/dist/{compactor-B4mQZXf2.d.ts → compactor-BUU6Zm_3.d.ts} +1 -1
  3. package/dist/{config-BU9f_5yH.d.ts → config-CKLYPkCi.d.ts} +1 -1
  4. package/dist/{context-BmM2xGUZ.d.ts → context-IovtuTf8.d.ts} +10 -0
  5. package/dist/coordination/index.d.ts +211 -13
  6. package/dist/coordination/index.js +964 -67
  7. package/dist/coordination/index.js.map +1 -1
  8. package/dist/defaults/index.d.ts +33 -18
  9. package/dist/defaults/index.js +1273 -42
  10. package/dist/defaults/index.js.map +1 -1
  11. package/dist/{events-BMNaEFZl.d.ts → events-CNB9PALO.d.ts} +99 -1
  12. package/dist/execution/index.d.ts +12 -12
  13. package/dist/extension/index.d.ts +9 -0
  14. package/dist/extension/index.js +234 -0
  15. package/dist/extension/index.js.map +1 -0
  16. package/dist/index-BDb0cAMP.d.ts +806 -0
  17. package/dist/index.d.ts +112 -29
  18. package/dist/index.js +2036 -490
  19. package/dist/index.js.map +1 -1
  20. package/dist/infrastructure/index.d.ts +6 -6
  21. package/dist/kernel/index.d.ts +12 -9
  22. package/dist/kernel/index.js +73 -7
  23. package/dist/kernel/index.js.map +1 -1
  24. package/dist/{mcp-servers-Dzgg4x1w.d.ts → mcp-servers-DR35ojJZ.d.ts} +3 -3
  25. package/dist/models/index.d.ts +2 -2
  26. package/dist/models/index.js +24 -1
  27. package/dist/models/index.js.map +1 -1
  28. package/dist/{multi-agent-fmkRHtof.d.ts → multi-agent-B9a6sflH.d.ts} +71 -3
  29. package/dist/observability/index.d.ts +2 -2
  30. package/dist/{path-resolver-DBjaoXFq.d.ts → path-resolver-Cl_q0u-R.d.ts} +2 -2
  31. package/dist/provider-runner-BXuADQqQ.d.ts +36 -0
  32. package/dist/sdd/index.d.ts +3 -3
  33. package/dist/{secret-scrubber-CicHLN4G.d.ts → secret-scrubber-CgG2tV2B.d.ts} +1 -1
  34. package/dist/{secret-scrubber-DF88luOe.d.ts → secret-scrubber-Cuy5afaQ.d.ts} +1 -1
  35. package/dist/security/index.d.ts +20 -4
  36. package/dist/security/index.js +37 -2
  37. package/dist/security/index.js.map +1 -1
  38. package/dist/{selector-BbJqiEP4.d.ts → selector-wT2fv9Fg.d.ts} +1 -1
  39. package/dist/{session-reader-Drq8RvJu.d.ts → session-reader-CcPi4BQ8.d.ts} +1 -1
  40. package/dist/{skill-DhfSizKv.d.ts → skill-C_7znCIC.d.ts} +2 -2
  41. package/dist/storage/index.d.ts +164 -6
  42. package/dist/storage/index.js +297 -2
  43. package/dist/storage/index.js.map +1 -1
  44. package/dist/{renderer-rk_1Swwc.d.ts → system-prompt-Dk1qm8ey.d.ts} +30 -2
  45. package/dist/{tool-executor-CpuJPYm9.d.ts → tool-executor-DKu4A6nB.d.ts} +5 -5
  46. package/dist/types/index.d.ts +16 -16
  47. package/dist/types/index.js +24 -1
  48. package/dist/types/index.js.map +1 -1
  49. package/dist/utils/index.d.ts +1 -1
  50. package/dist/utils/index.js +24 -1
  51. package/dist/utils/index.js.map +1 -1
  52. package/package.json +5 -1
  53. package/dist/plugin-DJk6LL8B.d.ts +0 -434
  54. package/dist/system-prompt-BC_8ypCG.d.ts +0 -23
@@ -34,7 +34,7 @@ async function atomicWrite(targetPath, content, opts = {}) {
34
34
  if (mode !== void 0) {
35
35
  await fsp.chmod(tmp, mode);
36
36
  }
37
- await fsp.rename(tmp, targetPath);
37
+ await renameWithRetry(tmp, targetPath);
38
38
  } catch (err) {
39
39
  try {
40
40
  await fsp.unlink(tmp);
@@ -46,6 +46,29 @@ async function atomicWrite(targetPath, content, opts = {}) {
46
46
  async function ensureDir(dir) {
47
47
  await fsp.mkdir(dir, { recursive: true });
48
48
  }
49
+ var TRANSIENT_RENAME_CODES = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "EACCES", "ENOTEMPTY"]);
50
+ async function renameWithRetry(from, to) {
51
+ if (process.platform !== "win32") {
52
+ await fsp.rename(from, to);
53
+ return;
54
+ }
55
+ const delays = [10, 25, 60, 120, 250];
56
+ let lastErr;
57
+ for (let i = 0; i <= delays.length; i++) {
58
+ try {
59
+ await fsp.rename(from, to);
60
+ return;
61
+ } catch (err) {
62
+ lastErr = err;
63
+ const code = err?.code;
64
+ if (!code || !TRANSIENT_RENAME_CODES.has(code) || i === delays.length) {
65
+ throw err;
66
+ }
67
+ await new Promise((resolve) => setTimeout(resolve, delays[i]));
68
+ }
69
+ }
70
+ throw lastErr;
71
+ }
49
72
 
50
73
  // src/storage/session-store.ts
51
74
  var DefaultSessionStore = class {
@@ -284,6 +307,12 @@ var FileSessionWriter = class {
284
307
  tokenIn = 0;
285
308
  tokenOut = 0;
286
309
  filePath;
310
+ /** Public accessor for the JSONL path — required by SessionWriter so
311
+ * observability surfaces (`/fleet log`, FleetPanel) can locate the
312
+ * transcript without recomputing the path from session metadata. */
313
+ get transcriptPath() {
314
+ return this.filePath || void 0;
315
+ }
287
316
  initDone = false;
288
317
  resumed;
289
318
  appendFailCount = 0;
@@ -1524,7 +1553,273 @@ var SessionAnalyzer = class {
1524
1553
  return last - first;
1525
1554
  }
1526
1555
  };
1556
+ async function loadTodosCheckpoint(filePath) {
1557
+ let raw;
1558
+ try {
1559
+ raw = await fsp.readFile(filePath, "utf8");
1560
+ } catch {
1561
+ return null;
1562
+ }
1563
+ try {
1564
+ const parsed = JSON.parse(raw);
1565
+ if (parsed?.version !== 1 || !Array.isArray(parsed.todos)) return null;
1566
+ return parsed.todos.filter(
1567
+ (t) => !!t && typeof t.id === "string" && typeof t.content === "string" && typeof t.status === "string"
1568
+ );
1569
+ } catch {
1570
+ return null;
1571
+ }
1572
+ }
1573
+ async function saveTodosCheckpoint(filePath, sessionId, todos) {
1574
+ const payload = {
1575
+ version: 1,
1576
+ sessionId,
1577
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1578
+ todos: [...todos]
1579
+ };
1580
+ try {
1581
+ await atomicWrite(filePath, JSON.stringify(payload, null, 2), { mode: 384 });
1582
+ } catch (err) {
1583
+ console.warn(
1584
+ "[todos-checkpoint] save failed:",
1585
+ err instanceof Error ? err.message : String(err)
1586
+ );
1587
+ }
1588
+ }
1589
+ function attachTodosCheckpoint(state, filePath, sessionId) {
1590
+ let timer = null;
1591
+ let pending = null;
1592
+ const flush = () => {
1593
+ timer = null;
1594
+ if (pending) {
1595
+ void saveTodosCheckpoint(filePath, sessionId, pending);
1596
+ pending = null;
1597
+ }
1598
+ };
1599
+ const unsubscribe = state.onChange((change) => {
1600
+ if (change.kind !== "todos_replaced") return;
1601
+ pending = change.todos;
1602
+ if (timer) clearTimeout(timer);
1603
+ timer = setTimeout(flush, 150);
1604
+ });
1605
+ return () => {
1606
+ unsubscribe();
1607
+ if (timer) {
1608
+ clearTimeout(timer);
1609
+ flush();
1610
+ }
1611
+ };
1612
+ }
1613
+ async function loadPlan(filePath) {
1614
+ let raw;
1615
+ try {
1616
+ raw = await fsp.readFile(filePath, "utf8");
1617
+ } catch {
1618
+ return null;
1619
+ }
1620
+ try {
1621
+ const parsed = JSON.parse(raw);
1622
+ if (parsed?.version !== 1 || !Array.isArray(parsed.items)) return null;
1623
+ return parsed;
1624
+ } catch {
1625
+ return null;
1626
+ }
1627
+ }
1628
+ async function savePlan(filePath, plan) {
1629
+ try {
1630
+ await atomicWrite(filePath, JSON.stringify(plan, null, 2), { mode: 384 });
1631
+ } catch (err) {
1632
+ console.warn(
1633
+ "[plan-store] save failed:",
1634
+ err instanceof Error ? err.message : String(err)
1635
+ );
1636
+ }
1637
+ }
1638
+ function emptyPlan(sessionId, title) {
1639
+ return {
1640
+ version: 1,
1641
+ sessionId,
1642
+ title,
1643
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1644
+ items: []
1645
+ };
1646
+ }
1647
+ function addPlanItem(plan, title, details) {
1648
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1649
+ const item = {
1650
+ id: `plan_${Date.now()}_${randomUUID().slice(0, 6)}`,
1651
+ title,
1652
+ details,
1653
+ status: "open",
1654
+ createdAt: now,
1655
+ updatedAt: now
1656
+ };
1657
+ return {
1658
+ plan: { ...plan, items: [...plan.items, item], updatedAt: now },
1659
+ item
1660
+ };
1661
+ }
1662
+ function removePlanItem(plan, idOrIndex) {
1663
+ const idx = matchIndex(plan, idOrIndex);
1664
+ if (idx === -1) return plan;
1665
+ return {
1666
+ ...plan,
1667
+ items: plan.items.filter((_, i) => i !== idx),
1668
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1669
+ };
1670
+ }
1671
+ function setPlanItemStatus(plan, idOrIndex, status) {
1672
+ const idx = matchIndex(plan, idOrIndex);
1673
+ if (idx === -1) return plan;
1674
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1675
+ const items = plan.items.map(
1676
+ (it, i) => i === idx ? { ...it, status, updatedAt: now } : it
1677
+ );
1678
+ return { ...plan, items, updatedAt: now };
1679
+ }
1680
+ function clearPlan(plan) {
1681
+ return { ...plan, items: [], updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
1682
+ }
1683
+ function formatPlan(plan) {
1684
+ if (plan.items.length === 0) return "Plan is empty.";
1685
+ const lines = [];
1686
+ if (plan.title) lines.push(`# ${plan.title}`);
1687
+ plan.items.forEach((it, i) => {
1688
+ const mark = it.status === "done" ? "[x]" : it.status === "in_progress" ? "[~]" : "[ ]";
1689
+ lines.push(`${i + 1}. ${mark} ${it.title}`);
1690
+ if (it.details) {
1691
+ for (const line of it.details.split("\n")) lines.push(` ${line}`);
1692
+ }
1693
+ });
1694
+ return lines.join("\n");
1695
+ }
1696
+ function matchIndex(plan, idOrIndex) {
1697
+ const asNum = Number.parseInt(idOrIndex, 10);
1698
+ if (!Number.isNaN(asNum) && asNum >= 1 && asNum <= plan.items.length) return asNum - 1;
1699
+ const byId = plan.items.findIndex((it) => it.id === idOrIndex);
1700
+ if (byId !== -1) return byId;
1701
+ const lower = idOrIndex.toLowerCase();
1702
+ return plan.items.findIndex((it) => it.title.toLowerCase().includes(lower));
1703
+ }
1704
+ function attachPlanCheckpoint(_state, _filePath, _sessionId) {
1705
+ return () => void 0;
1706
+ }
1707
+ async function loadDirectorState(filePath) {
1708
+ let raw;
1709
+ try {
1710
+ raw = await fsp.readFile(filePath, "utf8");
1711
+ } catch {
1712
+ return null;
1713
+ }
1714
+ try {
1715
+ const parsed = JSON.parse(raw);
1716
+ if (parsed?.version !== 1) return null;
1717
+ return parsed;
1718
+ } catch {
1719
+ return null;
1720
+ }
1721
+ }
1722
+ var DirectorStateCheckpoint = class {
1723
+ snapshot;
1724
+ filePath;
1725
+ timer = null;
1726
+ debounceMs;
1727
+ writing = false;
1728
+ rewriteRequested = false;
1729
+ constructor(filePath, init, debounceMs = 250) {
1730
+ this.filePath = filePath;
1731
+ this.debounceMs = debounceMs;
1732
+ this.snapshot = {
1733
+ version: 1,
1734
+ directorRunId: init.directorRunId,
1735
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1736
+ spawnCount: 0,
1737
+ maxSpawns: init.maxSpawns,
1738
+ spawnDepth: init.spawnDepth,
1739
+ maxSpawnDepth: init.maxSpawnDepth,
1740
+ subagents: [],
1741
+ tasks: []
1742
+ };
1743
+ }
1744
+ current() {
1745
+ return this.snapshot;
1746
+ }
1747
+ recordSpawn(sub, spawnCount) {
1748
+ this.snapshot = {
1749
+ ...this.snapshot,
1750
+ spawnCount,
1751
+ subagents: [...this.snapshot.subagents.filter((s) => s.id !== sub.id), sub]
1752
+ };
1753
+ this.bumpUpdatedAt();
1754
+ this.schedule();
1755
+ }
1756
+ recordTaskAssigned(task) {
1757
+ const exists = this.snapshot.tasks.some((t) => t.taskId === task.taskId);
1758
+ this.snapshot = {
1759
+ ...this.snapshot,
1760
+ tasks: exists ? this.snapshot.tasks.map((t) => t.taskId === task.taskId ? { ...t, ...task } : t) : [...this.snapshot.tasks, task]
1761
+ };
1762
+ this.bumpUpdatedAt();
1763
+ this.schedule();
1764
+ }
1765
+ recordTaskStatus(taskId, patch) {
1766
+ this.snapshot = {
1767
+ ...this.snapshot,
1768
+ tasks: this.snapshot.tasks.map(
1769
+ (t) => t.taskId === taskId ? { ...t, ...patch } : t
1770
+ )
1771
+ };
1772
+ this.bumpUpdatedAt();
1773
+ this.schedule();
1774
+ }
1775
+ setUsage(usage) {
1776
+ this.snapshot = { ...this.snapshot, usage };
1777
+ this.bumpUpdatedAt();
1778
+ this.schedule();
1779
+ }
1780
+ /** Force a synchronous flush — used by Director.shutdown(). */
1781
+ async flush() {
1782
+ if (this.timer) {
1783
+ clearTimeout(this.timer);
1784
+ this.timer = null;
1785
+ }
1786
+ await this.persist();
1787
+ }
1788
+ bumpUpdatedAt() {
1789
+ this.snapshot = { ...this.snapshot, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
1790
+ }
1791
+ schedule() {
1792
+ if (this.timer) return;
1793
+ this.timer = setTimeout(() => {
1794
+ this.timer = null;
1795
+ void this.persist();
1796
+ }, this.debounceMs);
1797
+ }
1798
+ async persist() {
1799
+ if (this.writing) {
1800
+ this.rewriteRequested = true;
1801
+ return;
1802
+ }
1803
+ this.writing = true;
1804
+ try {
1805
+ await atomicWrite(this.filePath, JSON.stringify(this.snapshot, null, 2), {
1806
+ mode: 384
1807
+ });
1808
+ } catch (err) {
1809
+ console.warn(
1810
+ "[director-state] checkpoint write failed:",
1811
+ err instanceof Error ? err.message : String(err)
1812
+ );
1813
+ } finally {
1814
+ this.writing = false;
1815
+ if (this.rewriteRequested) {
1816
+ this.rewriteRequested = false;
1817
+ this.schedule();
1818
+ }
1819
+ }
1820
+ }
1821
+ };
1527
1822
 
1528
- export { ConfigMigrationError, DEFAULT_CONFIG_MIGRATIONS, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultMemoryStore, DefaultSessionReader, DefaultSessionStore, QueueStore, RecoveryLock, SessionAnalyzer, runConfigMigrations };
1823
+ export { ConfigMigrationError, DEFAULT_CONFIG_MIGRATIONS, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultMemoryStore, DefaultSessionReader, DefaultSessionStore, DirectorStateCheckpoint, QueueStore, RecoveryLock, SessionAnalyzer, addPlanItem, attachPlanCheckpoint, attachTodosCheckpoint, clearPlan, emptyPlan, formatPlan, loadDirectorState, loadPlan, loadTodosCheckpoint, removePlanItem, runConfigMigrations, savePlan, saveTodosCheckpoint, setPlanItemStatus };
1529
1824
  //# sourceMappingURL=index.js.map
1530
1825
  //# sourceMappingURL=index.js.map