@cyanheads/secedgar-mcp-server 0.20.0 → 0.21.0

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 (128) hide show
  1. package/AGENTS.md +41 -33
  2. package/CLAUDE.md +41 -33
  3. package/README.md +37 -16
  4. package/changelog/0.20.x/0.20.1.md +39 -0
  5. package/changelog/0.21.x/0.21.0.md +35 -0
  6. package/changelog/template.md +10 -8
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp-server/prompts/definitions/company-analysis.prompt.js +3 -3
  10. package/dist/mcp-server/prompts/definitions/company-analysis.prompt.js.map +1 -1
  11. package/dist/mcp-server/tools/annual-report-reads.d.ts +50 -0
  12. package/dist/mcp-server/tools/annual-report-reads.d.ts.map +1 -0
  13. package/dist/mcp-server/tools/annual-report-reads.js +141 -0
  14. package/dist/mcp-server/tools/annual-report-reads.js.map +1 -0
  15. package/dist/mcp-server/tools/calendar-quarter.d.ts +22 -0
  16. package/dist/mcp-server/tools/calendar-quarter.d.ts.map +1 -0
  17. package/dist/mcp-server/tools/calendar-quarter.js +34 -0
  18. package/dist/mcp-server/tools/calendar-quarter.js.map +1 -0
  19. package/dist/mcp-server/tools/definitions/company-search.tool.d.ts.map +1 -1
  20. package/dist/mcp-server/tools/definitions/company-search.tool.js +11 -22
  21. package/dist/mcp-server/tools/definitions/company-search.tool.js.map +1 -1
  22. package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts +12 -2
  23. package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts.map +1 -1
  24. package/dist/mcp-server/tools/definitions/compare-companies.tool.js +153 -48
  25. package/dist/mcp-server/tools/definitions/compare-companies.tool.js.map +1 -1
  26. package/dist/mcp-server/tools/definitions/dataframe-query.tool.d.ts.map +1 -1
  27. package/dist/mcp-server/tools/definitions/dataframe-query.tool.js +28 -5
  28. package/dist/mcp-server/tools/definitions/dataframe-query.tool.js.map +1 -1
  29. package/dist/mcp-server/tools/definitions/fetch-frames.tool.d.ts.map +1 -1
  30. package/dist/mcp-server/tools/definitions/fetch-frames.tool.js +4 -2
  31. package/dist/mcp-server/tools/definitions/fetch-frames.tool.js.map +1 -1
  32. package/dist/mcp-server/tools/definitions/find-holders.tool.d.ts.map +1 -1
  33. package/dist/mcp-server/tools/definitions/find-holders.tool.js +12 -19
  34. package/dist/mcp-server/tools/definitions/find-holders.tool.js.map +1 -1
  35. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.d.ts +24 -9
  36. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.d.ts.map +1 -1
  37. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js +126 -47
  38. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js.map +1 -1
  39. package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts +24 -2
  40. package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts.map +1 -1
  41. package/dist/mcp-server/tools/definitions/get-filing.tool.js +370 -92
  42. package/dist/mcp-server/tools/definitions/get-filing.tool.js.map +1 -1
  43. package/dist/mcp-server/tools/definitions/get-financials.tool.d.ts.map +1 -1
  44. package/dist/mcp-server/tools/definitions/get-financials.tool.js +127 -44
  45. package/dist/mcp-server/tools/definitions/get-financials.tool.js.map +1 -1
  46. package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.d.ts.map +1 -1
  47. package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js +5 -6
  48. package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js.map +1 -1
  49. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts +42 -2
  50. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts.map +1 -1
  51. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js +525 -134
  52. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js.map +1 -1
  53. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.d.ts +12 -0
  54. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.d.ts.map +1 -1
  55. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js +21 -36
  56. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js.map +1 -1
  57. package/dist/mcp-server/tools/definitions/get-material-events.tool.d.ts +15 -0
  58. package/dist/mcp-server/tools/definitions/get-material-events.tool.d.ts.map +1 -1
  59. package/dist/mcp-server/tools/definitions/get-material-events.tool.js +108 -55
  60. package/dist/mcp-server/tools/definitions/get-material-events.tool.js.map +1 -1
  61. package/dist/mcp-server/tools/definitions/get-snapshot.tool.d.ts +5 -0
  62. package/dist/mcp-server/tools/definitions/get-snapshot.tool.d.ts.map +1 -1
  63. package/dist/mcp-server/tools/definitions/get-snapshot.tool.js +70 -37
  64. package/dist/mcp-server/tools/definitions/get-snapshot.tool.js.map +1 -1
  65. package/dist/mcp-server/tools/definitions/index.d.ts +282 -219
  66. package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
  67. package/dist/mcp-server/tools/definitions/search-concepts.tool.d.ts.map +1 -1
  68. package/dist/mcp-server/tools/definitions/search-concepts.tool.js +16 -11
  69. package/dist/mcp-server/tools/definitions/search-concepts.tool.js.map +1 -1
  70. package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts +18 -0
  71. package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts.map +1 -1
  72. package/dist/mcp-server/tools/definitions/search-filings.tool.js +130 -68
  73. package/dist/mcp-server/tools/definitions/search-filings.tool.js.map +1 -1
  74. package/dist/mcp-server/tools/filing-dates.d.ts +46 -0
  75. package/dist/mcp-server/tools/filing-dates.d.ts.map +1 -0
  76. package/dist/mcp-server/tools/filing-dates.js +93 -0
  77. package/dist/mcp-server/tools/filing-dates.js.map +1 -0
  78. package/dist/mcp-server/tools/limit-clamp.d.ts.map +1 -1
  79. package/dist/mcp-server/tools/limit-clamp.js +6 -2
  80. package/dist/mcp-server/tools/limit-clamp.js.map +1 -1
  81. package/dist/services/edgar/body-text-decoder.d.ts +33 -0
  82. package/dist/services/edgar/body-text-decoder.d.ts.map +1 -0
  83. package/dist/services/edgar/body-text-decoder.js +103 -0
  84. package/dist/services/edgar/body-text-decoder.js.map +1 -0
  85. package/dist/services/edgar/call-scope.d.ts +13 -1
  86. package/dist/services/edgar/call-scope.d.ts.map +1 -1
  87. package/dist/services/edgar/call-scope.js +4 -1
  88. package/dist/services/edgar/call-scope.js.map +1 -1
  89. package/dist/services/edgar/concept-map.d.ts.map +1 -1
  90. package/dist/services/edgar/concept-map.js +88 -14
  91. package/dist/services/edgar/concept-map.js.map +1 -1
  92. package/dist/services/edgar/concept-series.d.ts +111 -1
  93. package/dist/services/edgar/concept-series.d.ts.map +1 -1
  94. package/dist/services/edgar/concept-series.js +196 -1
  95. package/dist/services/edgar/concept-series.js.map +1 -1
  96. package/dist/services/edgar/edgar-api-service.d.ts +2 -12
  97. package/dist/services/edgar/edgar-api-service.d.ts.map +1 -1
  98. package/dist/services/edgar/edgar-api-service.js +30 -39
  99. package/dist/services/edgar/edgar-api-service.js.map +1 -1
  100. package/dist/services/edgar/eight-k-items.d.ts +19 -1
  101. package/dist/services/edgar/eight-k-items.d.ts.map +1 -1
  102. package/dist/services/edgar/eight-k-items.js +24 -1
  103. package/dist/services/edgar/eight-k-items.js.map +1 -1
  104. package/dist/services/edgar/filing-to-text.d.ts +29 -10
  105. package/dist/services/edgar/filing-to-text.d.ts.map +1 -1
  106. package/dist/services/edgar/filing-to-text.js +605 -53
  107. package/dist/services/edgar/filing-to-text.js.map +1 -1
  108. package/dist/services/edgar/fiscal-periods.d.ts +2 -0
  109. package/dist/services/edgar/fiscal-periods.d.ts.map +1 -1
  110. package/dist/services/edgar/fiscal-periods.js +1 -1
  111. package/dist/services/edgar/fiscal-periods.js.map +1 -1
  112. package/dist/services/edgar/form4-amendments.d.ts +63 -0
  113. package/dist/services/edgar/form4-amendments.d.ts.map +1 -0
  114. package/dist/services/edgar/form4-amendments.js +99 -0
  115. package/dist/services/edgar/form4-amendments.js.map +1 -0
  116. package/dist/services/edgar/mirror/companyfacts-sync.d.ts +6 -1
  117. package/dist/services/edgar/mirror/companyfacts-sync.d.ts.map +1 -1
  118. package/dist/services/edgar/mirror/companyfacts-sync.js +29 -6
  119. package/dist/services/edgar/mirror/companyfacts-sync.js.map +1 -1
  120. package/dist/services/edgar/ownership-parser.d.ts +5 -0
  121. package/dist/services/edgar/ownership-parser.d.ts.map +1 -1
  122. package/dist/services/edgar/ownership-parser.js +3 -0
  123. package/dist/services/edgar/ownership-parser.js.map +1 -1
  124. package/dist/services/edgar/types.d.ts +12 -7
  125. package/dist/services/edgar/types.d.ts.map +1 -1
  126. package/package.json +8 -8
  127. package/server.json +3 -3
  128. package/skills/secedgar-guide/SKILL.md +22 -5
@@ -8,6 +8,7 @@ import { JsonRpcErrorCode, McpError } from '@cyanheads/mcp-ts-core/errors';
8
8
  import { escapeMarkdownInline } from '@cyanheads/mcp-ts-core/utils';
9
9
  import { ambiguousMatches } from '../ambiguous-matches.js';
10
10
  import { datasetSchema } from '../dataset-schema.js';
11
+ import { checkFilingDates, filingDateField } from '../filing-dates.js';
11
12
  import { fixedPoint } from '../fixed-point.js';
12
13
  import { limitClamp, withLimitClamps, } from '../limit-clamp.js';
13
14
  import { resolvedAsField } from '../resolved-as.js';
@@ -15,6 +16,7 @@ import { SEC_UPSTREAM_ERRORS } from '../sec-upstream-errors.js';
15
16
  import { dataframeGuidance, getCanvasBridge, toDatasetField, } from '../../../services/canvas-bridge/canvas-bridge.js';
16
17
  import { CallScope } from '../../../services/edgar/call-scope.js';
17
18
  import { getEdgarApiService } from '../../../services/edgar/edgar-api-service.js';
19
+ import { pairAmendments, rowKey, } from '../../../services/edgar/form4-amendments.js';
18
20
  import { nonUsListingNote } from '../../../services/edgar/listing-codes.js';
19
21
  import { parseForm4Xml, } from '../../../services/edgar/ownership-parser.js';
20
22
  import { sameCik } from '../../../services/edgar/same-cik.js';
@@ -26,33 +28,223 @@ const SALE_CODES = new Set(['S']);
26
28
  * When a canvas is available, scan at least this many recent Form 4 filings —
27
29
  * as many as the submissions window offers (one rate-limited fetch each) — so
28
30
  * the dataframe holds a useful aggregation window even when the inline `limit`
29
- * is small (#63). Without a canvas, scanning stops as soon as the inline limit
30
- * is met — no extra latency.
31
+ * is small (#63). Without a canvas, scanning stops at the end of the filing date
32
+ * on which the inline limit is met.
31
33
  */
32
34
  const INSIDER_CANVAS_FILING_SCAN = 40;
33
35
  /** Most Form 4 filings one call parses — one rate-limited document request each. */
34
36
  const INSIDER_FILING_SCAN_CAP = 100;
37
+ /** Form 4 filings a call reaches for per transaction asked, for multi-transaction filings and filter losses. */
38
+ const FILINGS_PER_TRANSACTION = 5;
39
+ /** Transactions the inline list holds at most; `limit` clamps here (#197). */
40
+ const INLINE_TRANSACTION_CAP = 100;
35
41
  /** Structured Form 4 XML became mandatory for filings on and after this date. */
36
42
  const STRUCTURED_FORM4_START = '2003-06-30';
43
+ /** Ownership forms, whose rows in a reporting owner's feed carry the issuer's file number. */
44
+ const OWNERSHIP_FORMS = new Set(['3', '3/A', '4', '4/A', '5', '5/A']);
37
45
  /**
38
46
  * The Form 4 / 4-A rows of a submissions block filed inside the window, in block order
39
- * (newest first). Only rows whose primary document is ownership XML — EDGAR's
40
- * structured Form 4 began in mid-2003, and an earlier HTML or text filing has nothing
41
- * this tool can parse, so fetching it would spend a request on an empty result.
47
+ * (newest first), and the file numbers the block shows to be the filer's own. Only rows
48
+ * whose primary document is ownership XML — EDGAR's structured Form 4 began in mid-2003,
49
+ * and an earlier HTML or text filing has nothing this tool can parse, so fetching it
50
+ * would spend a request on an empty result.
51
+ *
52
+ * EDGAR lists a Form 4 in each reporting owner's feed under the issuer's file number. In
53
+ * the issuer's own feed it lists one under none, unless the issuer is also a reporting
54
+ * owner of it — CTT Pharmaceutical is on its CEO's Form 4s — and then under the issuer's
55
+ * own number. The filer's own numbers are those on its rows of every other form, whatever
56
+ * their date, so a row under any other number is a Form 4 it filed as another issuer's
57
+ * owner (#260, #265).
42
58
  */
43
59
  function windowForm4Rows(block, inWindow) {
44
60
  const rows = [];
61
+ const ownFileNumbers = [];
45
62
  for (let i = 0; i < block.form.length; i++) {
46
- const form = block.form[i];
63
+ const form = block.form[i] ?? '';
64
+ const fileNumber = block.fileNumber?.[i] ?? '';
65
+ if (!OWNERSHIP_FORMS.has(form)) {
66
+ if (fileNumber)
67
+ ownFileNumbers.push(fileNumber);
68
+ continue;
69
+ }
47
70
  const filingDate = block.filingDate[i] ?? '';
48
71
  const primaryDocument = block.primaryDocument[i] ?? '';
49
72
  if ((form !== '4' && form !== '4/A') || !inWindow(filingDate))
50
73
  continue;
51
74
  if (!/\.xml$/i.test(primaryDocument))
52
75
  continue;
53
- rows.push({ accessionNumber: block.accessionNumber[i] ?? '', filingDate, primaryDocument });
76
+ rows.push({
77
+ accessionNumber: block.accessionNumber[i] ?? '',
78
+ fileNumber,
79
+ filingDate,
80
+ form,
81
+ primaryDocument,
82
+ });
83
+ }
84
+ return { rows, ownFileNumbers };
85
+ }
86
+ /**
87
+ * The filings a scan of at most `cap` reads from `batch` (newest first), ending on a whole
88
+ * filing date so a `filed_before` continuation neither skips nor repeats one (#261): the
89
+ * first `cap` rows, less the date the row after them continues. When that date opens the
90
+ * batch — more Form 4s filed on it than the cap — its first `cap` rows are read and it is
91
+ * returned as `overCapDate`.
92
+ */
93
+ function capAtWholeDate(batch, cap) {
94
+ const rows = batch.slice(0, cap);
95
+ const next = batch[cap];
96
+ const start = next ? rows.findIndex((filing) => filing.filingDate === next.filingDate) : -1;
97
+ if (!next || start === -1)
98
+ return { rows };
99
+ return start === 0 ? { rows, overCapDate: next.filingDate } : { rows: rows.slice(0, start) };
100
+ }
101
+ /** A YYYY-MM-DD date one day earlier, in UTC. */
102
+ function dayBefore(date) {
103
+ const day = new Date(`${date}T00:00:00Z`);
104
+ day.setUTCDate(day.getUTCDate() - 1);
105
+ return day.toISOString().slice(0, 10);
106
+ }
107
+ /** The way past an archive walk the page cap ended: the date its oldest page starts on. */
108
+ function archiveCapNote(walk) {
109
+ return `The archive scan stopped after ${walk.pagesRead} pages, at filings from ${walk.scannedThrough}; narrow the window with filed_before=${walk.scannedThrough} to reach older ones.`;
110
+ }
111
+ /**
112
+ * The way on when `limit` cut `transactions[]` and no dataset holds the rows past the cut
113
+ * (#261): `filed_before` the filing date of the first row cut, where the rows shown from that
114
+ * date repeat and the next call's rows for it replace them — a dedupe on accession_number
115
+ * would drop the rest of a filing the cut split. When every row shown is from that date, the
116
+ * next call needs a larger `limit` to get past them, so one is named; a date holding more
117
+ * transactions than one call returns is read once at the inline cap, then stepped past, so
118
+ * no continuation repeats a call's rows.
119
+ */
120
+ function cutContinuation(scan) {
121
+ const { dates, limit } = scan;
122
+ const cut = dates[limit];
123
+ const total = dates.filter((date) => date === cut).length;
124
+ const shown = dates.slice(0, limit).filter((date) => date === cut).length;
125
+ const repeat = shown === 0
126
+ ? ''
127
+ : shown === 1
128
+ ? ` The row shown from ${cut} repeats there; that call's rows for ${cut} replace it, since a filing's rows can straddle the cut.`
129
+ : ` The ${shown} rows shown from ${cut} repeat there; that call's rows for ${cut} replace them, since a filing's rows can straddle the cut.`;
130
+ if (shown < limit) {
131
+ return `The transactions past the ${limit} shown start on ${cut}; pass filed_before=${cut} to read on.${repeat}`;
132
+ }
133
+ if (total > INLINE_TRANSACTION_CAP && limit < INLINE_TRANSACTION_CAP) {
134
+ return `${cut} holds more than ${INLINE_TRANSACTION_CAP} transactions, more than one call returns; pass filed_before=${cut} with limit=${INLINE_TRANSACTION_CAP} to read ${INLINE_TRANSACTION_CAP} of them.${repeat}`;
135
+ }
136
+ if (total > INLINE_TRANSACTION_CAP) {
137
+ const older = scan.olderBefore(cut)
138
+ ? `; pass filed_before=${dayBefore(cut)} to read the older ones`
139
+ : '';
140
+ return `${cut} holds more than ${INLINE_TRANSACTION_CAP} transactions, more than one call returns${older}.`;
141
+ }
142
+ if (scan.overCapScan !== undefined && scan.overCapScan < INSIDER_FILING_SCAN_CAP) {
143
+ return `${cut} holds more Form 4 filings than the ${scan.overCapScan} this call read; pass filed_before=${cut} with limit=${Math.max(total, scan.scanFillLimit)} to read up to ${INSIDER_FILING_SCAN_CAP} of them.${repeat}`;
54
144
  }
55
- return rows;
145
+ return `This call read ${total} transactions filed on ${cut} and shows ${limit} of them; pass filed_before=${cut} with limit=${total} to read them all.${repeat}`;
146
+ }
147
+ /** Closes every notice that reports filings naming another issuer (#260). */
148
+ const ROLE_LEVER = 'Pass role: "reporting_owner" to read them as this filer\'s own trades.';
149
+ /** `<count> of <scanned> names a different issuer … and contributes none.`, closed by the role lever (#157). */
150
+ function otherIssuerSentence(count, scanned) {
151
+ const one = count === 1;
152
+ return `${count} of ${scanned} ${one ? 'names' : 'name'} a different issuer — a Form 4 this company filed as a reporting owner of another company — and ${one ? 'contributes' : 'contribute'} none. ${ROLE_LEVER}`;
153
+ }
154
+ /** The `<N> name it as the issuer` close of a `reporting_owner` miss, naming the default role as the way to them. */
155
+ function issuerFilingsNote(count) {
156
+ return `${count} ${count === 1 ? 'names' : 'name'} it as the issuer, which omitting role reads.`;
157
+ }
158
+ /** ` at Tesla, Inc. (TSLA, CIK 0001318605)` for a `reporting_owner` row; nothing for an issuer-role row. */
159
+ function issuerClause(tx) {
160
+ const ids = [
161
+ tx.issuer_ticker && escapeMarkdownInline(tx.issuer_ticker),
162
+ tx.issuer_cik && `CIK ${tx.issuer_cik}`,
163
+ ]
164
+ .filter(Boolean)
165
+ .join(', ');
166
+ if (!tx.issuer_name)
167
+ return ids ? ` at ${ids}` : '';
168
+ return ` at ${escapeMarkdownInline(tx.issuer_name)}${ids ? ` (${ids})` : ''}`;
169
+ }
170
+ /** `a`, `a and b`, `a, b, and c`. */
171
+ function listed(items) {
172
+ return items.length <= 2
173
+ ? items.join(' and ')
174
+ : `${items.slice(0, -1).join(', ')}, and ${items.at(-1)}`;
175
+ }
176
+ /**
177
+ * The notice sentences on the scan's Form 4/A amendments whose filings put a row in the
178
+ * result (#267): each pair, each case no rule settled, and for a 4/A whose Form 4 predates
179
+ * the filings read, the window holding both.
180
+ */
181
+ function amendmentSentences(amendments, inResult, scan) {
182
+ const sentences = [];
183
+ const pairs = amendments.pairs.filter((pair) => inResult.has(pair.amendment) || inResult.has(pair.original));
184
+ if (pairs.length > 0) {
185
+ sentences.push(`Form 4/A amendments in this scan: ${pairs.map((pair) => `${pair.amendment} amends ${pair.original}`).join('; ')}. Rows a 4/A restates carry amended_by; leave them out of net activity (WHERE amended_by IS NULL).`);
186
+ }
187
+ // Each kind of flag is one sentence however many pairs raise it; the pair list maps each 4/A to its Form 4.
188
+ const flagged = (kind) => pairs.filter((pair) => pair[kind]);
189
+ const [shared, unmatched] = [flagged('sharedKey'), flagged('unmatched')];
190
+ const [oneShared] = shared;
191
+ if (oneShared) {
192
+ sentences.push(shared.length === 1
193
+ ? `${oneShared.amendment} restates a security, date, and code that several rows of ${oneShared.original} share, so those rows carry no amended_by; check them against it.`
194
+ : `${listed(shared.map((pair) => pair.amendment))} each restate a security, date, and code that several rows of the Form 4 it amends share, so those rows carry no amended_by; check them against the 4/A.`);
195
+ }
196
+ const [oneUnmatched] = unmatched;
197
+ if (oneUnmatched) {
198
+ sentences.push(unmatched.length === 1
199
+ ? `${oneUnmatched.amendment} holds a row matching no row of ${oneUnmatched.original} by security, date, and code — a corrected date or code — so any row it replaces carries no amended_by; check them against it.`
200
+ : `${listed(unmatched.map((pair) => pair.amendment))} each hold a row matching no row of the Form 4 it amends by security, date, and code — a corrected date or code — so any row it replaces carries no amended_by; check them against the 4/A.`);
201
+ }
202
+ for (const { original, amendments: several } of amendments.contested) {
203
+ if (!inResult.has(original) && !several.some((accession) => inResult.has(accession)))
204
+ continue;
205
+ const two = several.length === 2;
206
+ sentences.push(`${listed(several)} ${two ? 'both' : 'all'} amend ${original}, so none of its rows carries amended_by; check them against ${two ? 'both' : 'each'}.`);
207
+ }
208
+ // 4/As whose Form 4 predates the oldest date read, grouped by the date they amend. Filings
209
+ // run newest first, so the first 4/A a group meets is its newest.
210
+ const unreached = new Map();
211
+ for (const unpaired of amendments.unpaired) {
212
+ if (!inResult.has(unpaired.amendment))
213
+ continue;
214
+ if (unpaired.reason === 'no_date') {
215
+ sentences.push(`${unpaired.amendment} states no original filing date, so it pairs with no Form 4.`);
216
+ }
217
+ else if (unpaired.reason === 'several') {
218
+ sentences.push(`${unpaired.amendment} matches several Form 4s filed ${unpaired.amendsDate} by the same reporting owners, and neither period nor a shared row singles one out, so it pairs with none.`);
219
+ }
220
+ else if (unpaired.amendsDate < scan.scannedThrough) {
221
+ const group = unreached.get(unpaired.amendsDate);
222
+ if (group)
223
+ group.amendments.push(unpaired.amendment);
224
+ else {
225
+ unreached.set(unpaired.amendsDate, {
226
+ amendments: [unpaired.amendment],
227
+ newest: unpaired.filingDate,
228
+ });
229
+ }
230
+ }
231
+ else {
232
+ sentences.push(`${unpaired.amendment} amends a Form 4 filed ${unpaired.amendsDate}, but no Form 4 this call read from that date has its issuer and reporting owners.`);
233
+ }
234
+ }
235
+ for (const [amendsDate, { amendments: group, newest }] of unreached) {
236
+ // The window from the amended date to the newest 4/A holds both; name the bounds it changes.
237
+ const levers = [
238
+ scan.filedAfter !== amendsDate && `filed_after=${amendsDate}`,
239
+ scan.filedBefore !== newest && `filed_before=${newest}`,
240
+ ].filter(Boolean);
241
+ const one = group.length === 1;
242
+ const lead = `${listed(group)} ${one ? 'amends a Form 4' : 'amend Form 4s'} filed ${amendsDate}`;
243
+ sentences.push(levers.length > 0
244
+ ? `${lead}, before the filings this call read; pass ${levers.join(' and ')} to read ${one ? 'it with the Form 4 it amends' : 'them with the Form 4s they amend'}.`
245
+ : `${lead}, which this call did not reach.`);
246
+ }
247
+ return sentences;
56
248
  }
57
249
  /** "between A and B" / "on or after A" / "on or before B" for notices. */
58
250
  function describeWindow(filedAfter, filedBefore) {
@@ -83,8 +275,18 @@ function ownerRelationship(owner) {
83
275
  parts.push('Other');
84
276
  return parts.join(', ') || 'Unknown';
85
277
  }
86
- /** Transactions the inline list holds at most; `limit` clamps here (#197). */
87
- const INLINE_TRANSACTION_CAP = 100;
278
+ /** A CIK zero-padded to 10 digits; nothing when the filing gives none, rather than an all-zero one. */
279
+ function paddedCik(cik) {
280
+ return cik ? cik.padStart(10, '0') : undefined;
281
+ }
282
+ /** `(CIK 0000019617, 10% Owner)`, the CIK left out when the filing gives none; `escapeText` for Markdown. */
283
+ function ownerDetail(owner, escapeText = (text) => text) {
284
+ return `(${owner.cik ? `CIK ${owner.cik}, ` : ''}${escapeText(owner.relationship)})`;
285
+ }
286
+ /** `DNT Asset Trust (CIK 0002005954, 10% Owner)` — one joint filer, as the dataframe and content[] list it. */
287
+ function jointFilerLabel(owner, escapeText = (text) => text) {
288
+ return `${escapeText(owner.name)} ${ownerDetail(owner, escapeText)}`;
289
+ }
88
290
  /** `limit`: the inline list holds at most 100 transactions (#197). */
89
291
  const transactionsLimit = limitClamp({
90
292
  tool: 'secedgar_get_insider_transactions',
@@ -97,7 +299,7 @@ const transactionsLimit = limitClamp({
97
299
  });
98
300
  export const getInsiderTransactionsTool = tool('secedgar_get_insider_transactions', {
99
301
  title: 'Get Insider Transactions',
100
- description: 'Fetch Form 4 insider transactions (purchases, sales, grants, exercises) for a company by parsing SEC EDGAR ownership XML. Returns the reporting person, their relationship to the issuer, transaction date, type, shares traded (absolute magnitude), direction (acquire/dispose), price per share, and shares owned after the transaction. Covers nonDerivative transactions (open-market buys/sells, gifts) and derivative transactions (option exercises, RSU vests). Without a date window it reads the newest Form 4 filings; filed_after / filed_before read any period since mid-2003, reaching past the recent submissions window into the archive (e.g. insider trades in the quarter before an earnings miss). When a canvas is available, the full set of transactions parsed from the scanned filings is materialized as df_<id> (the inline list is a preview capped at limit) — inspect it with secedgar_dataframe_describe, then query it with secedgar_dataframe_query to aggregate net buy/sell by insider: SUM(CASE WHEN direction=\'dispose\' THEN -shares_traded ELSE shares_traded END). Use secedgar_search_filings with forms=["4"] to search Form 4 filings across all companies.',
302
+ description: 'Fetch Form 4 and 4/A insider transactions (purchases, sales, grants, exercises) for a company by parsing SEC EDGAR ownership XML: nonDerivative transactions (open-market buys/sells, gifts) and derivative ones (option exercises, RSU vests). With role "reporting_owner", company is instead the insider who filed (a person by CIK, or a fund or company holding 10%), and the result is that filer\'s own trades across every issuer, each transaction naming its issuer. Without a date window it reads the newest Form 4 filings; filed_after / filed_before read any period since mid-2003, past the recent submissions window into the archive. When a canvas is available, every transaction parsed from the scanned filings is materialized as df_<id> (the inline list is a preview capped at limit) — inspect it with secedgar_dataframe_describe, then aggregate net buy/sell by insider with secedgar_dataframe_query: SUM(CASE WHEN direction=\'dispose\' THEN -shares_traded ELSE shares_traded END) ... WHERE amended_by IS NULL, leaving out rows a 4/A in the scan restates. Use secedgar_search_filings with forms=["4"] to search Form 4 filings across all companies.',
101
303
  annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
102
304
  errors: [
103
305
  {
@@ -115,42 +317,30 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
115
317
  {
116
318
  reason: 'no_filings_found',
117
319
  code: JsonRpcErrorCode.NotFound,
118
- when: 'A call without a date window finds no Form 4 filings in the recent submissions window',
320
+ when: 'A call without a date window finds no Form 4 filings in the recent submissions window, or under role reporting_owner none listing the company as a reporting owner',
119
321
  recovery: 'Pass filed_after / filed_before to read an older period, or use secedgar_search_filings with forms=["4"] to find the filings.',
120
322
  },
121
323
  ...SEC_UPSTREAM_ERRORS,
122
324
  ],
123
- input: z.object({
325
+ input: z
326
+ .object({
124
327
  company: z
125
328
  .string()
126
329
  .min(1)
127
- .describe('The issuer whose Form 4 filings to read — the company, not the reporting person. A ticker symbol (e.g., "AAPL"), a CIK with or without zero-padding (e.g., "320193" or "0000320193"), or a company name (current or former). A name matching several companies fails and lists them, so retry with one\'s ticker or CIK.'),
330
+ .describe('The issuer whose Form 4 filings to read, or under role reporting_owner the insider who filed them. A ticker (e.g., "AAPL"), a CIK with or without zero-padding (e.g., "320193"), or a current or former company name; a person only by CIK. A name matching several companies fails and lists them.'),
331
+ role: z
332
+ .enum(['issuer', 'reporting_owner'])
333
+ .default('issuer')
334
+ .describe('Whose Form 4s to read. "issuer" (default): those of the company\'s insiders. "reporting_owner": those the company filed as an insider itself (a person, or a 10% holder), across every issuer, each transaction naming its issuer.'),
128
335
  transaction_type: z
129
336
  .enum(['purchase', 'sale', 'all'])
130
337
  .default('all')
131
338
  .describe('Filter by direction. "purchase" = open-market buys (code P). "sale" = open-market sells (code S). "all" includes grants, awards, exercises, gifts, and other coded transaction types as well.'),
132
339
  limit: transactionsLimit.schema(true),
133
- filed_after: z
134
- .union([
135
- z.literal(''),
136
- z
137
- .string()
138
- .regex(/^\d{4}-\d{2}-\d{2}$/, 'Expected YYYY-MM-DD')
139
- .describe('YYYY-MM-DD'),
140
- ])
141
- .optional()
142
- .describe('Only read Form 4 filings filed on or after this date (YYYY-MM-DD). A date window reaches filings older than the recent submissions window by paging into the archive, and with a canvas every Form 4 filed inside it is parsed, up to 100. Structured Form 4 XML begins in mid-2003, so an earlier window finds nothing.'),
143
- filed_before: z
144
- .union([
145
- z.literal(''),
146
- z
147
- .string()
148
- .regex(/^\d{4}-\d{2}-\d{2}$/, 'Expected YYYY-MM-DD')
149
- .describe('YYYY-MM-DD'),
150
- ])
151
- .optional()
152
- .describe('Only read Form 4 filings filed on or before this date (YYYY-MM-DD). Use alone or with filed_after. Without either bound the tool reads the newest Form 4 filings.'),
153
- }),
340
+ filed_after: filingDateField('Only read Form 4 filings filed on or after this date (YYYY-MM-DD). A date window pages into the archive past the recent submissions window, and with a canvas every Form 4 filed inside it is parsed, up to 100. Structured Form 4 XML begins in mid-2003, so an earlier window finds nothing.'),
341
+ filed_before: filingDateField('Only read Form 4 filings filed on or before this date (YYYY-MM-DD). Use alone or with filed_after. Without either bound the tool reads the newest Form 4 filings.'),
342
+ })
343
+ .superRefine(checkFilingDates),
154
344
  // Other tools' spellings of the company and filing-date parameters, and this tool's
155
345
  // former company name (#115).
156
346
  inputAliases: {
@@ -166,6 +356,10 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
166
356
  issuer_name: z.string().describe('Issuer entity name (SEC-conformed).'),
167
357
  issuer_cik: z.string().describe('Issuer CIK, zero-padded to 10 digits.'),
168
358
  issuer_ticker: z.string().optional().describe('Issuer ticker symbol when available.'),
359
+ role: z
360
+ .literal('reporting_owner')
361
+ .optional()
362
+ .describe('Present only under role reporting_owner, where issuer_* name the filer.'),
169
363
  transactions: z
170
364
  .array(z
171
365
  .object({
@@ -173,14 +367,51 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
173
367
  period_of_report: z
174
368
  .string()
175
369
  .optional()
176
- .describe('Transaction date per the filing period (YYYY-MM-DD).'),
370
+ .describe("The filing's period of report: its earliest transaction date (YYYY-MM-DD)."),
177
371
  accession_number: z
178
372
  .string()
179
- .describe('Form 4 accession number — pass to secedgar_get_filing for the raw XML.'),
180
- reporting_person: z.string().describe('Name of the insider who filed the Form 4.'),
373
+ .describe('Form 4 accession number, for secedgar_get_filing.'),
374
+ form: z.enum(['4', '4/A']).describe('"4", or "4/A" for an amendment.'),
375
+ amends_filing_date: z
376
+ .string()
377
+ .optional()
378
+ .describe('4/A rows: filing date of the Form 4 it amends (YYYY-MM-DD).'),
379
+ amended_by: z
380
+ .string()
381
+ .optional()
382
+ .describe('Accession of the 4/A in this scan that restates and so supersedes this row; net activity omits it.'),
383
+ reporting_person: z
384
+ .string()
385
+ .describe('First reporting owner listed; under role reporting_owner, the one with that CIK.'),
386
+ reporting_person_cik: z
387
+ .string()
388
+ .optional()
389
+ .describe('CIK of reporting_person, zero-padded.'),
181
390
  relationship: z
182
391
  .string()
183
392
  .describe('Relationship to issuer (e.g., "Director", "Officer (CEO)", "10% Owner").'),
393
+ joint_filers: z
394
+ .array(z
395
+ .object({
396
+ name: z.string().describe('Name as filed.'),
397
+ cik: z.string().optional().describe('CIK, zero-padded.'),
398
+ relationship: z.string().describe('Relationship to issuer.'),
399
+ })
400
+ .describe('A joint filer.'))
401
+ .optional()
402
+ .describe('Other owners of a joint filing, in filing order; the trade is reported once for all.'),
403
+ issuer_cik: z
404
+ .string()
405
+ .optional()
406
+ .describe('Issuer CIK, zero-padded (role reporting_owner only).'),
407
+ issuer_name: z
408
+ .string()
409
+ .optional()
410
+ .describe('Issuer name as filed (role reporting_owner only).'),
411
+ issuer_ticker: z
412
+ .string()
413
+ .optional()
414
+ .describe('Issuer ticker as filed (role reporting_owner only).'),
184
415
  security_title: z.string().describe('Security type (e.g., "Common Stock").'),
185
416
  transaction_date: z
186
417
  .string()
@@ -188,13 +419,13 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
188
419
  .describe('Date the transaction occurred (YYYY-MM-DD). Absent on some filings.'),
189
420
  transaction_code: z
190
421
  .string()
191
- .describe('SEC transaction code: P purchase, S sale, M exercise, A award, G gift, F tax withholding, C conversion, among others.'),
422
+ .describe('SEC transaction code: P purchase, S sale, M exercise, A award, G gift, F tax withholding, among others.'),
192
423
  transaction_type: z
193
424
  .string()
194
425
  .describe('Plain-language name of the code (e.g., "purchase", "conversion_of_derivative").'),
195
426
  is_derivative: z
196
427
  .boolean()
197
- .describe('True for derivative securities (options, RSUs, convertible notes); false for direct equity.'),
428
+ .describe('True for derivative securities (options, RSUs, convertible notes).'),
198
429
  shares_traded: z
199
430
  .number()
200
431
  .optional()
@@ -214,43 +445,40 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
214
445
  ownership_type: z
215
446
  .enum(['direct', 'indirect'])
216
447
  .optional()
217
- .describe('Direct, or indirect (through a trust, family member, etc.). Absent when not reported.'),
448
+ .describe('Direct, or indirect (trust, family member, etc.). Absent when not reported.'),
218
449
  ownership_nature: z
219
450
  .string()
220
451
  .optional()
221
452
  .describe('Nature of indirect ownership (e.g., "By Trust"). Present only when ownership_type is indirect.'),
222
453
  })
223
454
  .describe('One insider transaction parsed from a Form 4 filing.'))
224
- .describe('Insider transactions, newest filing first, capped at limit; the dataframe holds the full parsed set.'),
455
+ .describe("Insider transactions, newest filing first, capped at limit; dataset or the notice's next call reaches the rest."),
225
456
  filings_scanned: z
226
457
  .number()
227
458
  .describe('Form 4 filings scanned, including those in filings_other_issuer.'),
228
459
  filings_other_issuer: z
229
460
  .number()
230
- .describe("Scanned Form 4 filings naming a different issuer, filed by this company as that issuer's reporting owner (e.g., a 10% holder of a fund); they add no transactions here or to the dataframe."),
461
+ .describe('Scanned Form 4s naming another issuer, filed by this company as its reporting owner; they add no transactions. Role reporting_owner reads them.'),
231
462
  history_scanned_through: z
232
463
  .string()
233
464
  .optional()
234
- .describe('Filing date of the oldest Form 4 parsed (YYYY-MM-DD). Present only with a date window that held a Form 4.'),
465
+ .describe('Filing date of the oldest Form 4 the scan reached (YYYY-MM-DD); absent when it reached none.'),
235
466
  dataset: datasetSchema
236
467
  .extend({
237
468
  truncated: z
238
469
  .boolean()
239
- .describe("True when Form 4 filings exist past those parsed (the newest-filings sample, or a window's 100-filing or 10-page cap); narrow the window to reach them."),
470
+ .describe('True when Form 4 filings exist, or may exist on archive pages, past those read; the notice names the filed_before reaching them.'),
240
471
  })
241
472
  .optional()
242
- .describe('Dataframe of every parsed transaction, issuer keys on each row, for net buy/sell by insider and cross-issuer joins. Absent when canvas is unavailable or nothing parsed.'),
473
+ .describe('Dataframe of every parsed transaction with issuer keys, for net buy/sell by insider and cross-issuer joins; absent without a canvas or rows.'),
243
474
  }),
244
475
  enrichment: {
245
476
  notice: z
246
477
  .string()
247
478
  .optional()
248
- .describe('Why the result is empty (the filter, or every scanned filing naming another issuer), and the dataframe pointer when staged.'),
249
- truncated: z
250
- .boolean()
251
- .optional()
252
- .describe('True when the inline transactions[] was capped by limit.'),
253
- shown: z.number().optional().describe('Number of transactions shown inline.'),
479
+ .describe("Why the result is empty, the dataframe pointer, 4/A pairings, and the next call's date bounds and limit."),
480
+ truncated: z.boolean().optional().describe('True when limit capped transactions[].'),
481
+ shown: z.number().optional().describe('Transactions shown inline.'),
254
482
  cap: z.number().optional().describe('The limit cap applied.'),
255
483
  resolvedAs: resolvedAsField,
256
484
  },
@@ -282,21 +510,20 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
282
510
  const filedBefore = input.filed_before || undefined;
283
511
  const dateWindow = filedAfter || filedBefore ? { filedAfter, filedBefore } : undefined;
284
512
  // With a canvas available, scan deeper than the inline `limit` so the dataframe
285
- // holds a useful window for aggregation; without one, stop as soon as the inline
286
- // limit is met (preserves the fast, low-fetch path). A date window already bounds
287
- // the set, so with a canvas every filing inside it is parsed, up to the cap (#127).
513
+ // holds a useful window for aggregation; without one, stop at the end of the filing
514
+ // date on which the inline limit is met (the low-fetch path). A date window already
515
+ // bounds the set, so with a canvas every filing inside it is parsed, up to the cap (#127).
288
516
  const bridge = getCanvasBridge();
289
517
  const scanFloor = bridge
290
518
  ? dateWindow
291
519
  ? INSIDER_FILING_SCAN_CAP
292
520
  : INSIDER_CANVAS_FILING_SCAN
293
521
  : 0;
294
- // Over-fetch Form 4 metadata by 5x to account for multi-transaction filings and
295
- // filter losses; with a canvas, also fetch at least the scan floor so a small inline
296
- // `limit` doesn't under-scan the dataframe window (#63). Capped at 100; the +1
297
- // sentinel row (metadata only) detects Form 4 filings beyond the scan window so
298
- // `dataset.truncated` is truthful.
299
- const scanCap = Math.min(bridge ? Math.max(limit * 5, scanFloor) : limit * 5, INSIDER_FILING_SCAN_CAP);
522
+ // Reach for 5x the filings `limit` asks for, to account for multi-transaction filings
523
+ // and filter losses; with a canvas, also for at least the scan floor so a small inline
524
+ // `limit` doesn't under-scan the dataframe window (#63). Capped at 100; the row past
525
+ // the cap, when the feed holds one, shows Form 4 filings beyond the scan window.
526
+ const scanCap = Math.min(Math.max(limit * FILINGS_PER_TRANSACTION, scanFloor), INSIDER_FILING_SCAN_CAP);
300
527
  // Bare-CIK fallback: a numeric CIK absent from the ticker cache resolves to { cik }
301
528
  // with no name/ticker. The submissions feed 404s for such a CIK — it's a
302
529
  // filer/transmitter (e.g. an accession-number prefix), not a registrant. Convert
@@ -313,57 +540,91 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
313
540
  err instanceof McpError &&
314
541
  err.code === JsonRpcErrorCode.NotFound) {
315
542
  ctx.log.debug('CIK has no submissions feed', { cik: match.cik });
316
- throw ctx.fail('company_not_found', `No issuer found for CIK ${match.cik}. If this looks like an accession-number prefix, it's the filing agent, not the issuer — use secedgar_company_search to find the company.`, { ...ctx.recoveryFor('company_not_found') });
543
+ throw ctx.fail('company_not_found', `No EDGAR filer found for CIK ${match.cik}. If this looks like an accession-number prefix, it's the filing agent, not the issuer — use secedgar_company_search to find the company.`, { ...ctx.recoveryFor('company_not_found') });
317
544
  }
318
545
  throw err;
319
546
  }
320
547
  };
321
- let filingBatch;
548
+ const ownerRole = input.role === 'reporting_owner';
549
+ // The in-window Form 4 rows, newest first: the recent window, then in a date window
550
+ // the archive pages overlapping it, read until the scan budget plus one sentinel row
551
+ // the role reads is in hand or the shared page cap ends the walk.
552
+ const submissions = await readSubmissionsFeed(api.getSubmissions(match.cik, scope));
553
+ const inWindow = (date) => (!filedAfter || date >= filedAfter) && (!filedBefore || date <= filedBefore);
554
+ const form4Rows = [];
555
+ /** The company's own file numbers, from every block read (#265). */
556
+ const ownFileNumbers = new Set();
557
+ const take = (block) => {
558
+ const selected = windowForm4Rows(block, inWindow);
559
+ form4Rows.push(...selected.rows);
560
+ for (const fileNumber of selected.ownFileNumbers)
561
+ ownFileNumbers.add(fileNumber);
562
+ };
563
+ /**
564
+ * Whether the scan reads a row. Under `reporting_owner`, a row listed under a file number,
565
+ * the company's as an owner; the rest name it as their issuer (#260). Otherwise a row
566
+ * listed under none or the company's own; any other number marks a Form 4 it filed as
567
+ * another issuer's owner, skipped unread (#265). Own numbers only accrue as pages are
568
+ * read, so a row skipped early can turn out to be read, never the reverse.
569
+ */
570
+ const reads = (row) => ownerRole ? row.fileNumber !== '' : !row.fileNumber || ownFileNumbers.has(row.fileNumber);
571
+ const rowsRead = () => form4Rows.filter(reads).length;
572
+ take(submissions.filings.recent);
322
573
  let walk;
323
574
  if (dateWindow) {
324
- // In-window Form 4 rows, newest first: the recent window, then the archive pages
325
- // overlapping the window, read until the scan budget plus one sentinel row is in
326
- // hand or the shared page cap ends the walk.
327
- const submissions = await readSubmissionsFeed(api.getSubmissions(match.cik, scope));
328
- const inWindow = (date) => (!filedAfter || date >= filedAfter) && (!filedBefore || date <= filedBefore);
329
- filingBatch = windowForm4Rows(submissions.filings.recent, inWindow);
330
575
  walk = new SubmissionsArchiveWalk(api, submissions, { filedAfter, filedBefore, order: 'newest-first' }, scope);
331
- if (filingBatch.length <= scanCap) {
576
+ if (rowsRead() <= scanCap) {
332
577
  for await (const { block } of walk) {
333
- filingBatch.push(...windowForm4Rows(block, inWindow));
334
- if (filingBatch.length > scanCap)
578
+ take(block);
579
+ if (rowsRead() > scanCap)
335
580
  break;
336
581
  }
337
582
  }
338
583
  }
339
- else {
340
- filingBatch = await readSubmissionsFeed(api.getRecentFilingsByForm(match.cik, ['4', '4/A'], scanCap + 1, scope));
341
- }
342
- // Form 4 filings exist past the scan: the sentinel row turned up, or — in a date
343
- // window — archive pages overlapping it went unread.
344
- const moreBeyondWindow = filingBatch.length > scanCap || Boolean(walk?.truncated);
345
- const filingsToScan = filingBatch.slice(0, scanCap);
346
- if (filingBatch.length === 0 && !dateWindow) {
347
- throw ctx.fail('no_filings_found', `No Form 4 filings found for '${input.company}'.`);
584
+ const filingBatch = form4Rows.filter(reads);
585
+ /**
586
+ * The in-window rows the role leaves unread: under `reporting_owner` those naming the
587
+ * company as issuer, otherwise those it filed as another issuer's owner.
588
+ */
589
+ const unread = form4Rows.filter((row) => !reads(row));
590
+ const issuerRows = ownerRole ? unread.length : 0;
591
+ const otherIssuerRows = ownerRole ? [] : unread;
592
+ const { rows: filingsToScan, overCapDate } = capAtWholeDate(filingBatch, scanCap);
593
+ // A window holding only Form 4s filed as another issuer's owner is a success that says
594
+ // so, not a miss (#157, #265).
595
+ if (filingBatch.length === 0 && otherIssuerRows.length === 0 && !dateWindow) {
596
+ throw ctx.fail('no_filings_found', issuerRows > 0
597
+ ? `No Form 4 in the recent filings of '${input.company}' names it as a reporting owner; ${issuerFilingsNote(issuerRows)}`
598
+ : `No Form 4 filings found for '${input.company}'.`);
348
599
  }
600
+ // The ticker file names listed companies only; a person or an unlisted filer takes the
601
+ // name its submissions document carries, already read (#260).
602
+ const companyName = match.name ?? submissions.name;
349
603
  const transactions = [];
350
- let filingsScanned = 0;
604
+ /** The filings whose rows this call reads, for pairing each 4/A with its Form 4 (#267). */
605
+ const scanned = [];
606
+ /** Form 4 documents read, the canvas floor's measure; `filings_scanned` adds the rows skipped unread. */
607
+ let filingsRead = 0;
351
608
  let filingsOtherIssuer = 0;
352
- /** Filing date of the last filing parsed — the oldest, since filings run newest first. */
353
- let oldestParsed;
354
- let scannedWholeWindow = true;
609
+ /** Filings the scan reached, and the filing date of the last — the oldest, since filings run newest first. */
610
+ let reached = 0;
611
+ let scannedThrough;
355
612
  for (const filing of filingsToScan) {
356
- if (transactions.length >= limit && filingsScanned >= scanFloor) {
357
- scannedWholeWindow = false;
613
+ // Whole filing dates only: once limit and the floor are in hand, stop where the
614
+ // next date begins, so filed_before the day before resumes without a gap (#261).
615
+ if (transactions.length >= limit &&
616
+ filingsRead >= scanFloor &&
617
+ filing.filingDate !== scannedThrough) {
358
618
  break;
359
619
  }
620
+ reached++;
621
+ scannedThrough = filing.filingDate;
360
622
  // primaryDocument may be prefixed with xslF345X06/ — strip to get the bare filename
361
623
  const docName = filing.primaryDocument.replace(/^xsl[^/]+\//, '');
362
624
  const xmlText = await api.tryGetFilingDocument(match.cik, filing.accessionNumber, docName, scope);
363
625
  if (!xmlText)
364
626
  continue;
365
- filingsScanned++;
366
- oldestParsed = filing.filingDate;
627
+ filingsRead++;
367
628
  let parsed;
368
629
  try {
369
630
  parsed = parseForm4Xml(xmlText);
@@ -375,16 +636,50 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
375
636
  });
376
637
  continue;
377
638
  }
378
- // The submissions feed also lists Form 4s this company filed as a reporting
379
- // owner of another issuer — that issuer's insider activity, not this one's (#157).
380
- if (parsed.issuer_cik && !sameCik(parsed.issuer_cik, match.cik)) {
639
+ // A Form 4 this company filed as a reporting owner of another issuer is that issuer's
640
+ // insider activity, not this one's (#157), and under `reporting_owner` the very filing
641
+ // the call reads (#260). The feed's file number skipped most unread; this drops one it
642
+ // lists under none or the company's own (#265).
643
+ if (!ownerRole && parsed.issuer_cik && !sameCik(parsed.issuer_cik, match.cik)) {
381
644
  filingsOtherIssuer++;
382
645
  continue;
383
646
  }
384
- // Build a single primary owner label from the first reporting owner
385
- const primaryOwner = parsed.reporting_owners[0];
647
+ // The row's person is the first reporting owner listed — under `reporting_owner`,
648
+ // the one carrying this filer's CIK, since a joint filing lists several (#260). The
649
+ // others ride on every row as joint filers: the XML ties no transaction to one owner,
650
+ // so a row per owner would multiply each trade by the owner count (#264).
651
+ const primaryOwner = ownerRole
652
+ ? parsed.reporting_owners.find((owner) => sameCik(owner.cik, match.cik))
653
+ : parsed.reporting_owners[0];
654
+ if (ownerRole && !primaryOwner) {
655
+ ctx.log.warning('Form 4 lists no reporting owner with the resolved CIK', {
656
+ accessionNumber: filing.accessionNumber,
657
+ });
658
+ continue;
659
+ }
386
660
  const personName = primaryOwner?.name ?? 'Unknown';
661
+ const personCik = primaryOwner && paddedCik(primaryOwner.cik);
387
662
  const relationship = primaryOwner ? ownerRelationship(primaryOwner) : 'Unknown';
663
+ const jointFilers = parsed.reporting_owners
664
+ .filter((owner) => owner !== primaryOwner)
665
+ .map((owner) => {
666
+ const cik = paddedCik(owner.cik);
667
+ return { name: owner.name, ...(cik && { cik }), relationship: ownerRelationship(owner) };
668
+ });
669
+ const rowIssuer = ownerRole
670
+ ? {
671
+ ...(parsed.issuer_cik && { issuer_cik: parsed.issuer_cik.padStart(10, '0') }),
672
+ ...(parsed.issuer_name && { issuer_name: parsed.issuer_name }),
673
+ ...(parsed.issuer_ticker && { issuer_ticker: parsed.issuer_ticker }),
674
+ }
675
+ : {};
676
+ scanned.push({
677
+ accession: filing.accessionNumber,
678
+ filingDate: filing.filingDate,
679
+ form: filing.form,
680
+ parsed,
681
+ });
682
+ const amendsDate = filing.form === '4/A' ? parsed.date_of_original_submission : undefined;
388
683
  // Collect every matching transaction — the full set backs the canvas; the
389
684
  // inline response is sliced to `limit` after the scan completes.
390
685
  for (const tx of parsed.transactions) {
@@ -398,8 +693,13 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
398
693
  filing_date: filing.filingDate,
399
694
  period_of_report: parsed.period_of_report,
400
695
  accession_number: filing.accessionNumber,
696
+ form: filing.form,
697
+ ...(amendsDate && { amends_filing_date: amendsDate }),
401
698
  reporting_person: personName,
699
+ ...(personCik && { reporting_person_cik: personCik }),
402
700
  relationship,
701
+ ...(jointFilers.length > 0 && { joint_filers: jointFilers }),
702
+ ...rowIssuer,
403
703
  security_title: tx.security_title,
404
704
  transaction_date: tx.transaction_date,
405
705
  transaction_code: tx.transaction_code,
@@ -414,40 +714,88 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
414
714
  });
415
715
  }
416
716
  }
717
+ // A row a 4/A in the scan restates is superseded: it names that 4/A, so a net-activity
718
+ // sum can leave it out and count the trade once, as corrected (#267).
719
+ const amendments = pairAmendments(scanned);
720
+ const pairOf = new Map(amendments.pairs.map((pair) => [pair.original, pair]));
721
+ for (const row of transactions) {
722
+ const pair = pairOf.get(row.accession_number);
723
+ if (pair?.restated.has(rowKey(row)))
724
+ row.amended_by = pair.amendment;
725
+ }
726
+ // The rows skipped as another issuer's that the scan passed count as scanned and as
727
+ // naming another issuer (#265): those filed on or after the oldest filing read, or every
728
+ // one when the scan read all of the company's own.
729
+ const stoppedAt = reached < filingBatch.length ? scannedThrough : undefined;
730
+ const passed = stoppedAt
731
+ ? otherIssuerRows.filter((row) => row.filingDate >= stoppedAt)
732
+ : otherIssuerRows;
733
+ const filingsScanned = filingsRead + passed.length;
734
+ filingsOtherIssuer += passed.length;
735
+ /** The oldest Form 4 the scan reached, read or passed. */
736
+ const historyThrough = passed.reduce((oldest, row) => (oldest && oldest <= row.filingDate ? oldest : row.filingDate), scannedThrough);
737
+ // Form 4 filings past those read, and the filed_before that reaches them (#261). The
738
+ // scan read whole filing dates, so the day before the oldest one resumes it without a
739
+ // gap or a repeat; a date it could not finish, or an archive walk the page cap cut
740
+ // short, resumes on that date instead, and the rows read from it come back again.
741
+ let continuation;
742
+ if (historyThrough) {
743
+ const through = historyThrough;
744
+ if (overCapDate) {
745
+ continuation =
746
+ scanCap < INSIDER_FILING_SCAN_CAP
747
+ ? `${through} holds more Form 4 filings than the ${scanCap} this call read; pass filed_before=${through}${bridge ? '' : ` with limit=${INSIDER_FILING_SCAN_CAP / FILINGS_PER_TRANSACTION}`} to read up to ${INSIDER_FILING_SCAN_CAP} of them. The rows already read from ${through} repeat, so dedupe on accession_number.`
748
+ : `${through} holds more than ${INSIDER_FILING_SCAN_CAP} Form 4 filings, more than one call reads; pass filed_before=${dayBefore(through)} to read the older ones.`;
749
+ }
750
+ else if (reached < filingBatch.length) {
751
+ continuation = dateWindow
752
+ ? `More Form 4 filings in this window predate ${through}; narrow it with filed_before=${dayBefore(through)} to read them.`
753
+ : `Older Form 4 filings exist before ${through}; pass filed_before=${dayBefore(through)} to read them.`;
754
+ }
755
+ else if (walk?.truncated) {
756
+ continuation = `${archiveCapNote(walk)} Any rows already read from ${walk.scannedThrough} repeat, so dedupe on accession_number.`;
757
+ }
758
+ else if (!dateWindow && submissions.filings.files.length > 0) {
759
+ // Every recent Form 4 is read, and older ones can sit on the archive pages.
760
+ continuation = `Older Form 4 filings may exist before ${through}; pass filed_before=${dayBefore(through)} to read them.`;
761
+ }
762
+ }
417
763
  const windowText = dateWindow && describeWindow(filedAfter, filedBefore);
418
764
  // The notices are authored Markdown, so the caller's company text is escaped.
419
765
  const companyText = escapeMarkdownInline(input.company);
420
- if (windowText && filingBatch.length === 0) {
766
+ // `ctx.enrich.notice` is last-wins, so the continuation closes whichever notice is set.
767
+ const continuationTail = continuation ? ` ${continuation}` : '';
768
+ if (windowText && filingBatch.length === 0 && otherIssuerRows.length === 0) {
421
769
  // The walk runs newest first, so only an earlier upper bound reaches older filings.
422
- const walkNote = walk?.truncated
423
- ? ` The archive scan stopped after ${walk.pagesRead} pages, at filings from ${walk.scannedThrough}; narrow the window with filed_before=${walk.scannedThrough} to reach older ones.`
424
- : '';
770
+ const walkNote = walk?.truncated ? ` ${archiveCapNote(walk)}` : '';
425
771
  const eraNote = filedBefore && filedBefore < STRUCTURED_FORM4_START
426
772
  ? ' Structured Form 4 filings begin in mid-2003, so an earlier window finds none.'
427
773
  : '';
428
- ctx.enrich.notice(`No Form 4 filings filed ${windowText} for '${companyText}'.${walkNote}${eraNote}`);
774
+ const lead = issuerRows > 0
775
+ ? `No Form 4 of '${companyText}' filed ${windowText} names it as a reporting owner; ${issuerFilingsNote(issuerRows)}`
776
+ : `No Form 4 filings filed ${windowText} for '${companyText}'.`;
777
+ ctx.enrich.notice(`${lead}${walkNote}${eraNote}`);
429
778
  }
430
779
  else if (transactions.length === 0) {
431
780
  const filterNote = input.transaction_type !== 'all'
432
781
  ? ` with transaction_type="${input.transaction_type}"`
433
782
  : '';
434
783
  const filings = `Form 4 filing${filingsScanned === 1 ? '' : 's'}`;
784
+ const ownerNote = ownerRole ? ' naming it as a reporting owner' : '';
435
785
  const scope = windowText
436
- ? `the ${filingsScanned} ${filings} filed ${windowText}`
437
- : `the ${filingsScanned} most recent ${filings}`;
786
+ ? `the ${filingsScanned} ${filings} filed ${windowText}${ownerNote}`
787
+ : `the ${filingsScanned} most recent ${filings}${ownerNote}`;
438
788
  const lead = `No insider transactions found for '${companyText}'${filterNote} in ${scope}`;
789
+ // Filings naming another issuer are this filer's own trades, which the other role reads (#260).
439
790
  if (filingsOtherIssuer > 0 && filingsOtherIssuer === filingsScanned) {
440
791
  // Every filing read is another issuer's insider activity, so no filter or
441
792
  // broader form search surfaces this company's rows from them (#157).
442
793
  const single = filingsScanned === 1;
443
- ctx.enrich.notice(`${lead}: ${single ? 'it names' : 'each names'} a different issuer — a Form 4 this company filed as a reporting owner of another company — so ${single ? "it reports that company's" : "they report those companies'"} insider activity, not this one's.`);
794
+ ctx.enrich.notice(`${lead}: ${single ? 'it names' : 'each names'} a different issuer — a Form 4 this company filed as a reporting owner of another company — so ${single ? "it reports that company's" : "they report those companies'"} insider activity, not this one's. ${ROLE_LEVER}${continuationTail}`);
444
795
  }
445
796
  else {
446
- const otherIssuerNote = filingsOtherIssuer > 0
447
- ? ` ${filingsOtherIssuer} of them ${filingsOtherIssuer === 1 ? 'names' : 'name'} a different issuer — a Form 4 this company filed as a reporting owner of another company — and ${filingsOtherIssuer === 1 ? 'contributes' : 'contribute'} none.`
448
- : '';
449
- ctx.enrich.notice(`${lead}.${otherIssuerNote} ` +
450
- `Try transaction_type="all" or use secedgar_search_filings with forms=["4"] for broader coverage.`);
797
+ const otherIssuerNote = filingsOtherIssuer > 0 ? ` ${otherIssuerSentence(filingsOtherIssuer, 'them')}` : '';
798
+ ctx.enrich.notice(`${lead}. Try transaction_type="all" or use secedgar_search_filings with forms=["4"] for broader coverage.${otherIssuerNote}${continuationTail}`);
451
799
  }
452
800
  }
453
801
  // Use issuer data from the resolved entity (the submissions API may not always
@@ -455,19 +803,21 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
455
803
  const issuerTicker = match.ticker ?? undefined;
456
804
  // Register the full scanned transaction set to the canvas; the inline response
457
805
  // is a preview sliced to `limit`. Denormalize the issuer onto every row so the
458
- // dataframe is self-contained for SQL aggregation and cross-issuer joins.
806
+ // dataframe is self-contained for SQL aggregation and cross-issuer joins: the
807
+ // resolved company, or under `reporting_owner` each filing's own issuer.
459
808
  let dataset;
460
809
  if (bridge && transactions.length > 0) {
461
- // The scanned window is a recent sample — more Form 4 filings exist when the
462
- // scan broke before exhausting its window, or the submissions window held
463
- // more filings than the scan cap (the +1 sentinel fetch above) (#63).
464
- const truncated = !scannedWholeWindow || moreBeyondWindow;
810
+ // Truncated exactly when the continuation names Form 4 filings past those read (#63, #261).
811
+ const truncated = continuation !== undefined;
465
812
  const registered = await bridge.registerDataframe(ctx, {
466
813
  rows: transactions.map((t) => ({
467
- issuer_cik: match.cik,
468
- issuer_ticker: issuerTicker ?? null,
814
+ issuer_cik: ownerRole ? (t.issuer_cik ?? null) : match.cik,
815
+ issuer_ticker: ownerRole ? (t.issuer_ticker ?? null) : (issuerTicker ?? null),
816
+ issuer_name: ownerRole ? (t.issuer_name ?? null) : companyName,
469
817
  reporting_person: t.reporting_person,
818
+ reporting_person_cik: t.reporting_person_cik ?? null,
470
819
  relationship: t.relationship,
820
+ joint_filers: t.joint_filers?.map((owner) => jointFilerLabel(owner)).join('; ') ?? null,
471
821
  security_title: t.security_title,
472
822
  transaction_date: t.transaction_date ?? null,
473
823
  filing_date: t.filing_date,
@@ -482,11 +832,15 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
482
832
  ownership_type: t.ownership_type ?? null,
483
833
  ownership_nature: t.ownership_nature ?? null,
484
834
  accession_number: t.accession_number,
835
+ form: t.form,
836
+ amends_filing_date: t.amends_filing_date ?? null,
837
+ amended_by: t.amended_by ?? null,
485
838
  })),
486
839
  sourceTool: 'secedgar_get_insider_transactions',
487
840
  queryParams: {
488
841
  company: input.company,
489
842
  cik: match.cik,
843
+ role: input.role,
490
844
  transaction_type: input.transaction_type,
491
845
  filed_after: filedAfter,
492
846
  filed_before: filedBefore,
@@ -497,23 +851,50 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
497
851
  dataset = { ...toDatasetField(registered), truncated };
498
852
  }
499
853
  const inlineTransactions = transactions.slice(0, limit);
500
- if (transactions.length > limit) {
501
- ctx.enrich.truncated({
502
- shown: inlineTransactions.length,
503
- cap: limit,
504
- guidance: dataset
505
- ? dataframeGuidance(dataset)
506
- : limit < INLINE_TRANSACTION_CAP
507
- ? `Raise limit (at most ${INLINE_TRANSACTION_CAP} inline), or narrow with filed_after, filed_before, or transaction_type.`
508
- : 'Narrow with filed_after, filed_before, or transaction_type to reach the rest.',
509
- });
510
- }
511
- else if (dataset) {
512
- ctx.enrich.notice(dataframeGuidance(dataset));
854
+ // With no dataset to hold them, the rows `limit` cut are reached only by reading their
855
+ // filing date again, so the way on resumes there in place of the one past the scan (#261).
856
+ const wayOn = !dataset && transactions.length > limit
857
+ ? cutContinuation({
858
+ dates: transactions.map((t) => t.filing_date),
859
+ limit,
860
+ overCapScan: overCapDate ? scanCap : undefined,
861
+ scanFillLimit: bridge ? 0 : INSIDER_FILING_SCAN_CAP / FILINGS_PER_TRANSACTION,
862
+ olderBefore: (date) => filingBatch.some((filing) => filing.filingDate < date) ||
863
+ Boolean(walk?.truncated) ||
864
+ (!dateWindow && submissions.filings.files.length > 0),
865
+ })
866
+ : continuation;
867
+ if (transactions.length > 0 && scannedThrough) {
868
+ // Filings naming another issuer are this filer's own trades, which the other role reads (#260).
869
+ const closing = [
870
+ filingsOtherIssuer > 0 &&
871
+ otherIssuerSentence(filingsOtherIssuer, `the ${filingsScanned} Form 4 filings scanned`),
872
+ ...amendmentSentences(amendments, new Set(transactions.map((row) => row.accession_number)), { scannedThrough, filedAfter, filedBefore }),
873
+ wayOn,
874
+ ];
875
+ const sentences = (...parts) => parts.filter(Boolean).join(' ');
876
+ if (transactions.length > limit) {
877
+ ctx.enrich.truncated({
878
+ shown: inlineTransactions.length,
879
+ cap: limit,
880
+ guidance: sentences(dataset
881
+ ? dataframeGuidance(dataset)
882
+ : limit < INLINE_TRANSACTION_CAP
883
+ ? `Raise limit (at most ${INLINE_TRANSACTION_CAP} inline), or narrow with filed_after, filed_before, or transaction_type.`
884
+ : 'Narrow with filed_after, filed_before, or transaction_type to reach the rest.', ...closing),
885
+ });
886
+ }
887
+ else {
888
+ const notice = sentences(dataset && dataframeGuidance(dataset), ...closing);
889
+ if (notice)
890
+ ctx.enrich.notice(notice);
891
+ }
513
892
  }
514
893
  ctx.log.info('Insider transactions retrieved', {
515
894
  cik: match.cik,
895
+ role: input.role,
516
896
  filingsScanned,
897
+ filingsRead,
517
898
  filingsOtherIssuer,
518
899
  transactionCount: transactions.length,
519
900
  returned: inlineTransactions.length,
@@ -521,13 +902,14 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
521
902
  datasetName: dataset?.name,
522
903
  });
523
904
  return {
524
- issuer_name: match.name ?? input.company,
905
+ issuer_name: companyName,
525
906
  issuer_cik: match.cik,
526
907
  issuer_ticker: issuerTicker,
908
+ ...(ownerRole && { role: 'reporting_owner' }),
527
909
  transactions: inlineTransactions,
528
910
  filings_scanned: filingsScanned,
529
911
  filings_other_issuer: filingsOtherIssuer,
530
- ...(dateWindow && { history_scanned_through: oldestParsed }),
912
+ ...(historyThrough && { history_scanned_through: historyThrough }),
531
913
  dataset,
532
914
  };
533
915
  },
@@ -536,10 +918,11 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
536
918
  const otherIssuerNote = otherIssuer > 0
537
919
  ? `; ${otherIssuer} ${otherIssuer === 1 ? 'names another issuer and contributes' : 'name another issuer and contribute'} none`
538
920
  : '';
921
+ const owner = result.role === 'reporting_owner';
539
922
  // Names and titles are SEC or filer text, escaped to read back as written.
540
923
  const lines = [
541
- `**Insider Transactions** — ${escapeMarkdownInline(result.issuer_name)} (CIK ${result.issuer_cik}${result.issuer_ticker ? `, ${result.issuer_ticker}` : ''})`,
542
- `${result.transactions.length} transaction(s) from ${result.filings_scanned} Form 4 filing(s) scanned${otherIssuerNote}`,
924
+ `**Insider Transactions** — ${escapeMarkdownInline(result.issuer_name)} (CIK ${result.issuer_cik}${result.issuer_ticker ? `, ${result.issuer_ticker}` : ''})${owner ? ' as reporting owner' : ''}`,
925
+ `${result.transactions.length} transaction(s) from ${result.filings_scanned} Form 4 filing(s) scanned${otherIssuerNote}${owner ? ' (role: reporting_owner)' : ''}`,
543
926
  ];
544
927
  // One legend rather than a per-row tag: every row spells the direction out
545
928
  // as "shares acquired" / "shares disposed", and repeating the raw enum on
@@ -564,18 +947,26 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
564
947
  : tx.ownership_type
565
948
  ? ` (${tx.ownership_type})`
566
949
  : '';
567
- lines.push(`**${escapeMarkdownInline(tx.reporting_person)}** (${escapeMarkdownInline(tx.relationship)}) — ${tx.transaction_type}${derivStr}`);
950
+ const person = { cik: tx.reporting_person_cik, relationship: tx.relationship };
951
+ lines.push(`**${escapeMarkdownInline(tx.reporting_person)}** ${ownerDetail(person, escapeMarkdownInline)}${issuerClause(tx)} — ${tx.transaction_type}${derivStr}`);
952
+ if (tx.joint_filers) {
953
+ lines.push(`Joint filers: ${tx.joint_filers.map((owner) => jointFilerLabel(owner, escapeMarkdownInline)).join('; ')}`);
954
+ }
568
955
  const txDate = tx.transaction_date ?? tx.filing_date;
569
956
  const periodStr = tx.period_of_report ? ` | report period: ${tx.period_of_report}` : '';
570
957
  lines.push(`${txDate} | ${escapeMarkdownInline(tx.security_title)} | ${sharesStr} ${priceStr}${ownedStr}${ownershipStr}${periodStr}`);
571
- lines.push(`Code: ${tx.transaction_code} | Filed: ${tx.filing_date} [${tx.accession_number}]`);
958
+ const amendsStr = tx.amends_filing_date
959
+ ? ` | Amends: Form 4 filed ${tx.amends_filing_date}`
960
+ : '';
961
+ const amendedStr = tx.amended_by ? ` | Amended by: ${tx.amended_by}` : '';
962
+ lines.push(`Code: ${tx.transaction_code} | Form ${tx.form} | Filed: ${tx.filing_date} [${tx.accession_number}]${amendsStr}${amendedStr}`);
572
963
  }
573
964
  if (result.history_scanned_through) {
574
965
  lines.push(`\nHistory scanned through: ${result.history_scanned_through}`);
575
966
  }
576
967
  if (result.dataset) {
577
968
  const truncatedNote = result.dataset.truncated
578
- ? ' (truncated — more Form 4 filings exist beyond those scanned)'
969
+ ? ' (truncated — more Form 4 filings may exist beyond those scanned)'
579
970
  : '';
580
971
  lines.push(`\nDataset: ${result.dataset.name} (${result.dataset.row_count} rows, expires ${result.dataset.expires_at})${truncatedNote} — query with secedgar_dataframe_query.`);
581
972
  }