@the-vibe-company/armada 0.1.4 → 0.1.5

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 (2) hide show
  1. package/dist/armada.js +104 -53
  2. package/package.json +1 -1
package/dist/armada.js CHANGED
@@ -1548,13 +1548,18 @@ var LABEL_PHASES = [
1548
1548
  // ../core/src/linear.ts
1549
1549
  var LINEAR_ENDPOINT = "https://api.linear.app/graphql";
1550
1550
  var MAX_DEPTH = 8;
1551
- var MAX_PAGES = 20;
1552
1551
  var COMMENT_BATCH = 25;
1553
1552
  var MAX_COMMENTS = 100;
1553
+ var MORE_PAGE = 100;
1554
1554
  var REQUEST_TIMEOUT_MS = 30000;
1555
1555
 
1556
1556
  class LinearError extends Error {
1557
+ transport;
1557
1558
  name = "LinearError";
1559
+ constructor(message, transport = false) {
1560
+ super(message);
1561
+ this.transport = transport;
1562
+ }
1558
1563
  }
1559
1564
  var PHASES = [...LABEL_PHASES, "released", "merged"];
1560
1565
  var LEGACY = { "handed-back": "ready-to-merge", "ci-fixing": "shipping" };
@@ -1609,14 +1614,6 @@ function agentLabels(labels, groups) {
1609
1614
  }
1610
1615
  var sameName = (a, b) => a.toLowerCase().replace(/[^a-z0-9]/g, "") === b.toLowerCase().replace(/[^a-z0-9]/g, "");
1611
1616
  var phaseNamed = (name) => LABEL_PHASES.find((p) => sameName(p, name)) ?? null;
1612
- function truncationWarnings(raw) {
1613
- const cut = (c, what) => c.pageInfo?.hasNextPage ? [`${raw.identifier}: more ${what} than Armada reads; some are ignored`] : [];
1614
- return [
1615
- ...cut(raw.inverseRelations, "relations"),
1616
- ...cut(raw.labels, "labels"),
1617
- ...cut(raw.attachments, "attachments")
1618
- ];
1619
- }
1620
1617
  function normalizeIssue(raw, groups) {
1621
1618
  const blockers = new Map;
1622
1619
  for (const r of raw.inverseRelations.nodes)
@@ -1667,6 +1664,28 @@ function normalizeComment(raw, issueId) {
1667
1664
  claim: parseClaim(raw.body, raw.createdAt, author)
1668
1665
  };
1669
1666
  }
1667
+ var MORE = {
1668
+ inverseRelations: {
1669
+ field: "inverseRelations",
1670
+ nodes: "type issue { identifier state { type } }",
1671
+ operation: "MoreRelations",
1672
+ what: "relations"
1673
+ },
1674
+ labels: { field: "labels", nodes: "name parent { name }", operation: "MoreLabels", what: "labels" },
1675
+ attachments: { field: "attachments", nodes: "title url", operation: "MoreAttachments", what: "attachments" },
1676
+ comments: {
1677
+ field: "comments",
1678
+ nodes: "id createdAt body user { name }",
1679
+ operation: "MoreComments",
1680
+ what: "comments"
1681
+ }
1682
+ };
1683
+ var MORE_QUERY = (m) => `
1684
+ query ${m.operation}($id: String!, $after: String) {
1685
+ issue(id: $id) {
1686
+ ${m.field}(first: ${m.first ?? MORE_PAGE}, after: $after) { pageInfo { hasNextPage endCursor } nodes { ${m.nodes} } }
1687
+ }
1688
+ }`;
1670
1689
  var FIELDS = (delegate) => `
1671
1690
  fragment F on Issue {
1672
1691
  id identifier title url description createdAt updatedAt startedAt completedAt canceledAt
@@ -1674,9 +1693,9 @@ var FIELDS = (delegate) => `
1674
1693
  assignee { name }
1675
1694
  ${delegate ? "delegate { name }" : ""}
1676
1695
  parent { identifier }
1677
- labels(first: 25) { pageInfo { hasNextPage } nodes { name parent { name } } }
1678
- attachments(first: 25) { pageInfo { hasNextPage } nodes { title url } }
1679
- inverseRelations(first: 50) { pageInfo { hasNextPage } nodes { type issue { identifier state { type } } } }
1696
+ labels(first: 25) { pageInfo { hasNextPage endCursor } nodes { ${MORE.labels.nodes} } }
1697
+ attachments(first: 25) { pageInfo { hasNextPage endCursor } nodes { ${MORE.attachments.nodes} } }
1698
+ inverseRelations(first: 50) { pageInfo { hasNextPage endCursor } nodes { ${MORE.inverseRelations.nodes} } }
1680
1699
  }
1681
1700
  `;
1682
1701
  var ROOT_QUERY = (d) => `${FIELDS(d)} query Root($id: String!) { issue(id: $id) { ...F } }`;
@@ -1690,7 +1709,7 @@ var CHILDREN_QUERY = (d) => `${FIELDS(d)}
1690
1709
  var COMMENTS_QUERY = `
1691
1710
  query Comments($ids: [ID!]) {
1692
1711
  issues(first: 50, filter: { id: { in: $ids } }) {
1693
- nodes { identifier comments(first: ${MAX_COMMENTS}) { pageInfo { hasNextPage } nodes { id createdAt body user { name } } } }
1712
+ nodes { identifier comments(first: ${MAX_COMMENTS}) { pageInfo { hasNextPage endCursor } nodes { ${MORE.comments.nodes} } } }
1694
1713
  }
1695
1714
  }`;
1696
1715
  async function gql(opts, query, variables) {
@@ -1702,15 +1721,15 @@ async function gql(opts, query, variables) {
1702
1721
  body: JSON.stringify({ query, variables }),
1703
1722
  signal: AbortSignal.timeout(timeoutMs)
1704
1723
  }).catch((err) => {
1705
- throw new LinearError(`Linear API unreachable: ${networkReason(err, timeoutMs)}`);
1724
+ throw new LinearError(`Linear API unreachable: ${networkReason(err, timeoutMs)}`, true);
1706
1725
  });
1707
1726
  if (res.status === 401)
1708
- throw new LinearError("Linear rejected the API key (HTTP 401); check LINEAR_API_KEY");
1727
+ throw new LinearError("Linear rejected the API key (HTTP 401); check LINEAR_API_KEY", true);
1709
1728
  const json = await res.json().catch(() => ({}));
1710
1729
  if (json.errors?.length)
1711
1730
  throw new LinearError(`Linear API: ${json.errors.map((e) => e.message).join("; ")}`);
1712
1731
  if (!res.ok)
1713
- throw new LinearError(`Linear API HTTP ${res.status}`);
1732
+ throw new LinearError(`Linear API HTTP ${res.status}`, true);
1714
1733
  if (!json.data)
1715
1734
  throw new LinearError("Linear API: empty response");
1716
1735
  return json.data;
@@ -1741,34 +1760,35 @@ async function fetchTree(opts, delegate) {
1741
1760
  for (let depth = 0;depth < MAX_DEPTH && parents.length; depth++) {
1742
1761
  const next = [];
1743
1762
  let after = null;
1744
- for (let page = 0;; page++) {
1745
- if (page === MAX_PAGES) {
1746
- warnings.push(`more than ${MAX_PAGES * 50} issues at depth ${depth + 1}; the rest are ignored`);
1747
- break;
1748
- }
1763
+ for (;; ) {
1749
1764
  const data = await gql(opts, CHILDREN_QUERY(delegate), { parents, after });
1750
1765
  all.push(...data.issues.nodes);
1751
1766
  next.push(...data.issues.nodes.map((n) => n.id));
1752
- if (!data.issues.pageInfo.hasNextPage)
1767
+ const { hasNextPage, endCursor } = data.issues.pageInfo;
1768
+ if (!hasNextPage)
1769
+ break;
1770
+ if (!endCursor || endCursor === after) {
1771
+ warnings.push(`issues at depth ${depth + 1}: Linear did not advance to the next page; the rest are ignored`);
1753
1772
  break;
1754
- after = data.issues.pageInfo.endCursor;
1773
+ }
1774
+ after = endCursor;
1755
1775
  }
1756
1776
  parents = next;
1757
1777
  }
1758
1778
  if (parents.length)
1759
1779
  warnings.push(`the program is deeper than ${MAX_DEPTH} levels; deeper issues are ignored`);
1760
1780
  for (const r of all)
1761
- warnings.push(...truncationWarnings(r));
1781
+ for (const field of ["inverseRelations", "labels", "attachments"])
1782
+ await readRest(opts, r.identifier, MORE[field], r[field], warnings);
1762
1783
  const issues = all.map((r) => normalizeIssue(r, opts.labels));
1763
1784
  const candidates = issues.filter((i) => i.id !== root.identifier && !CLOSED2.has(i.statusType) && (i.agentPhase || i.statusType === "started"));
1764
1785
  const comments = [];
1765
1786
  for (const batch of chunks(candidates.map((i) => i.uuid), COMMENT_BATCH)) {
1766
1787
  const data = await gql(opts, COMMENTS_QUERY, { ids: batch });
1767
1788
  for (const n of data.issues.nodes) {
1789
+ await readRest(opts, n.identifier, MORE.comments, n.comments, warnings);
1768
1790
  for (const c of n.comments.nodes)
1769
1791
  comments.push(normalizeComment(c, n.identifier));
1770
- if (n.comments.pageInfo?.hasNextPage)
1771
- warnings.push(`${n.identifier}: more than ${MAX_COMMENTS} comments; its phase and claim may be out of date`);
1772
1792
  }
1773
1793
  }
1774
1794
  return {
@@ -1779,13 +1799,40 @@ async function fetchTree(opts, delegate) {
1779
1799
  warnings
1780
1800
  };
1781
1801
  }
1802
+ async function readRest(opts, identifier, more, conn, warnings) {
1803
+ while (conn.pageInfo?.hasNextPage) {
1804
+ const after = conn.pageInfo.endCursor;
1805
+ try {
1806
+ if (!after)
1807
+ throw new LinearError("Linear gave no cursor for the next page");
1808
+ const data = await gql(opts, MORE_QUERY(more), {
1809
+ id: identifier,
1810
+ after
1811
+ });
1812
+ const page = data.issue?.[more.field];
1813
+ if (!page)
1814
+ throw new LinearError(`Linear: issue ${identifier} not found`);
1815
+ conn.nodes.push(...page.nodes);
1816
+ conn.pageInfo = page.pageInfo;
1817
+ if (page.pageInfo?.hasNextPage && page.pageInfo.endCursor === after)
1818
+ throw new LinearError("Linear did not advance to a next page");
1819
+ } catch (err) {
1820
+ if (!(err instanceof LinearError) || err.transport)
1821
+ throw err;
1822
+ warnings.push(`${identifier}: could not read all its ${more.what} (${err.message}); some may be missing`);
1823
+ return;
1824
+ }
1825
+ }
1826
+ }
1782
1827
 
1783
1828
  // ../core/src/brief.ts
1784
1829
  var ARMADA_PACKAGE = "@the-vibe-company/armada";
1785
1830
  var WORKER_SKILL_PATH = ".agents/skills/armada-worker/SKILL.md";
1786
1831
  var CONDUCTOR_HANDLE = '"$CONDUCTOR_WORKSPACE_ID/$CONDUCTOR_SESSION_ID"';
1787
1832
  var MAX_NOTES = 10;
1788
- var NOTES = "pageInfo { hasNextPage } nodes { id createdAt body user { name } }";
1833
+ var NOTE = "id createdAt body user { name }";
1834
+ var NOTES = `pageInfo { hasNextPage endCursor } nodes { ${NOTE} }`;
1835
+ var RELATION = `type issue { identifier title url state { name type } comments(first: 50) { ${NOTES} } }`;
1789
1836
  var BRIEF_QUERY = `
1790
1837
  query Brief($id: String!) {
1791
1838
  issue(id: $id) {
@@ -1793,33 +1840,28 @@ var BRIEF_QUERY = `
1793
1840
  state { name type }
1794
1841
  parent { identifier title url }
1795
1842
  comments(first: 50) { ${NOTES} }
1796
- inverseRelations(first: 25) {
1797
- pageInfo { hasNextPage }
1798
- nodes { type issue { identifier title url state { name type } comments(first: 50) { ${NOTES} } } }
1799
- }
1843
+ inverseRelations(first: 25) { pageInfo { hasNextPage endCursor } nodes { ${RELATION} } }
1800
1844
  }
1801
1845
  }`;
1846
+ var MORE_NOTES = { field: "comments", nodes: NOTE, operation: "MoreBriefComments", what: "comments" };
1847
+ var MORE_RELATIONS = {
1848
+ field: "inverseRelations",
1849
+ nodes: RELATION,
1850
+ operation: "MoreBriefRelations",
1851
+ what: "relations",
1852
+ first: 25
1853
+ };
1802
1854
  var noteUrl = (issueUrl, id) => `${issueUrl}#comment-${id.slice(0, 8)}`;
1803
1855
  var toNotes = (issueUrl, raw) => raw.nodes.map((c) => ({ url: noteUrl(issueUrl, c.id), author: c.user?.name ?? null, createdAt: c.createdAt, body: c.body })).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
1804
- function normalizeBriefTicket(raw) {
1805
- const warnings = [];
1806
- const cut = (c, what) => {
1807
- if (c.pageInfo?.hasNextPage)
1808
- warnings.push(`${what}; the brief may miss the newest ones`);
1809
- };
1810
- cut(raw.comments, `${raw.identifier} has more comments than Armada reads`);
1811
- cut(raw.inverseRelations, `${raw.identifier} has more relations than Armada reads`);
1812
- const blockers = raw.inverseRelations.nodes.filter((r) => r.type === "blocks").map(({ issue: b }) => {
1813
- cut(b.comments, `blocker ${b.identifier} has more comments than Armada reads`);
1814
- return {
1815
- id: b.identifier,
1816
- title: b.title,
1817
- url: b.url,
1818
- status: b.state.name,
1819
- statusType: b.state.type,
1820
- notes: toNotes(b.url, b.comments)
1821
- };
1822
- }).sort((a, b) => a.id.localeCompare(b.id, "en", { numeric: true }));
1856
+ function normalizeBriefTicket(raw, warnings = []) {
1857
+ const blockers = raw.inverseRelations.nodes.filter((r) => r.type === "blocks").map(({ issue: b }) => ({
1858
+ id: b.identifier,
1859
+ title: b.title,
1860
+ url: b.url,
1861
+ status: b.state.name,
1862
+ statusType: b.state.type,
1863
+ notes: toNotes(b.url, b.comments)
1864
+ })).sort((a, b) => a.id.localeCompare(b.id, "en", { numeric: true }));
1823
1865
  return {
1824
1866
  id: raw.identifier,
1825
1867
  title: raw.title,
@@ -1840,7 +1882,16 @@ async function fetchBriefTicket(opts, id) {
1840
1882
  return { issue: null };
1841
1883
  throw err;
1842
1884
  });
1843
- return data.issue ? normalizeBriefTicket(data.issue) : null;
1885
+ const raw = data.issue;
1886
+ if (!raw)
1887
+ return null;
1888
+ const warnings = [];
1889
+ await readRest(opts, raw.identifier, MORE_NOTES, raw.comments, warnings);
1890
+ await readRest(opts, raw.identifier, MORE_RELATIONS, raw.inverseRelations, warnings);
1891
+ for (const r of raw.inverseRelations.nodes)
1892
+ if (r.type === "blocks")
1893
+ await readRest(opts, r.issue.identifier, MORE_NOTES, r.issue.comments, warnings);
1894
+ return normalizeBriefTicket(raw, warnings);
1844
1895
  }
1845
1896
  function handBackNote(notes) {
1846
1897
  const withStatus = notes.filter((n) => parseStatusLine(n.body));
@@ -1857,7 +1908,7 @@ class BriefError extends Error {
1857
1908
  }
1858
1909
  function buildBrief(input) {
1859
1910
  const { config, ticket, program } = input;
1860
- const warnings = [...ticket.warnings, ...program.warnings];
1911
+ const warnings = [...new Set([...ticket.warnings, ...program.warnings])];
1861
1912
  const choice = resolveProfile(config, input.profile);
1862
1913
  if (!choice.profile && choice.problem)
1863
1914
  throw new BriefError(choice.problem);
@@ -4293,7 +4344,7 @@ async function loadStatus(config, opts) {
4293
4344
  });
4294
4345
  }
4295
4346
  // package.json
4296
- var version = "0.1.4";
4347
+ var version = "0.1.5";
4297
4348
 
4298
4349
  // src/io.ts
4299
4350
  class UsageError extends Error {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-vibe-company/armada",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "Run a fleet of coding agents on one project: the armada command line.",
6
6
  "license": "MIT",