@cyanheads/secedgar-mcp-server 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +23 -22
- package/CLAUDE.md +23 -22
- package/README.md +21 -9
- package/changelog/0.20.x/0.20.1.md +39 -0
- package/changelog/template.md +10 -8
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/company-search.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/company-search.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/compare-companies.tool.js +35 -21
- package/dist/mcp-server/tools/definitions/compare-companies.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/dataframe-query.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/dataframe-query.tool.js +28 -5
- package/dist/mcp-server/tools/definitions/dataframe-query.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-frames.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-frames.tool.js +4 -2
- package/dist/mcp-server/tools/definitions/fetch-frames.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/find-holders.tool.js +3 -3
- package/dist/mcp-server/tools/definitions/find-holders.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts +14 -2
- package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-filing.tool.js +220 -86
- package/dist/mcp-server/tools/definitions/get-filing.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-financials.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-financials.tool.js +82 -18
- package/dist/mcp-server/tools/definitions/get-financials.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js +3 -3
- package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts +18 -2
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js +299 -104
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js +5 -5
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-material-events.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/get-material-events.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.js +24 -22
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +17 -2
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-concepts.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-concepts.tool.js +16 -11
- package/dist/mcp-server/tools/definitions/search-concepts.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts +2 -0
- package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-filings.tool.js +88 -40
- package/dist/mcp-server/tools/definitions/search-filings.tool.js.map +1 -1
- package/dist/services/edgar/call-scope.d.ts +13 -1
- package/dist/services/edgar/call-scope.d.ts.map +1 -1
- package/dist/services/edgar/call-scope.js +4 -1
- package/dist/services/edgar/call-scope.js.map +1 -1
- package/dist/services/edgar/concept-map.d.ts.map +1 -1
- package/dist/services/edgar/concept-map.js +18 -2
- package/dist/services/edgar/concept-map.js.map +1 -1
- package/dist/services/edgar/concept-series.d.ts +32 -1
- package/dist/services/edgar/concept-series.d.ts.map +1 -1
- package/dist/services/edgar/concept-series.js +72 -1
- package/dist/services/edgar/concept-series.js.map +1 -1
- package/dist/services/edgar/edgar-api-service.d.ts +2 -12
- package/dist/services/edgar/edgar-api-service.d.ts.map +1 -1
- package/dist/services/edgar/edgar-api-service.js +18 -31
- package/dist/services/edgar/edgar-api-service.js.map +1 -1
- package/dist/services/edgar/filing-to-text.d.ts +20 -8
- package/dist/services/edgar/filing-to-text.d.ts.map +1 -1
- package/dist/services/edgar/filing-to-text.js +583 -51
- package/dist/services/edgar/filing-to-text.js.map +1 -1
- package/dist/services/edgar/fiscal-periods.d.ts +2 -0
- package/dist/services/edgar/fiscal-periods.d.ts.map +1 -1
- package/dist/services/edgar/fiscal-periods.js +1 -1
- package/dist/services/edgar/fiscal-periods.js.map +1 -1
- package/dist/services/edgar/types.d.ts +9 -6
- package/dist/services/edgar/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/server.json +3 -3
- package/skills/secedgar-guide/SKILL.md +16 -2
|
@@ -26,22 +26,31 @@ const SALE_CODES = new Set(['S']);
|
|
|
26
26
|
* When a canvas is available, scan at least this many recent Form 4 filings —
|
|
27
27
|
* as many as the submissions window offers (one rate-limited fetch each) — so
|
|
28
28
|
* the dataframe holds a useful aggregation window even when the inline `limit`
|
|
29
|
-
* is small (#63). Without a canvas, scanning stops
|
|
30
|
-
*
|
|
29
|
+
* is small (#63). Without a canvas, scanning stops at the end of the filing date
|
|
30
|
+
* on which the inline limit is met.
|
|
31
31
|
*/
|
|
32
32
|
const INSIDER_CANVAS_FILING_SCAN = 40;
|
|
33
33
|
/** Most Form 4 filings one call parses — one rate-limited document request each. */
|
|
34
34
|
const INSIDER_FILING_SCAN_CAP = 100;
|
|
35
|
+
/** Form 4 filings a call reaches for per transaction asked, for multi-transaction filings and filter losses. */
|
|
36
|
+
const FILINGS_PER_TRANSACTION = 5;
|
|
37
|
+
/** Transactions the inline list holds at most; `limit` clamps here (#197). */
|
|
38
|
+
const INLINE_TRANSACTION_CAP = 100;
|
|
35
39
|
/** Structured Form 4 XML became mandatory for filings on and after this date. */
|
|
36
40
|
const STRUCTURED_FORM4_START = '2003-06-30';
|
|
37
41
|
/**
|
|
38
|
-
* The Form 4 / 4-A rows of a submissions block filed inside the window
|
|
39
|
-
* (newest first). Only rows whose primary document is ownership XML —
|
|
40
|
-
* structured Form 4 began in mid-2003, and an earlier HTML or text filing has
|
|
41
|
-
* this tool can parse, so fetching it would spend a request on an empty result.
|
|
42
|
+
* The Form 4 / 4-A rows of a submissions block filed inside the window that `role` reads,
|
|
43
|
+
* in block order (newest first). Only rows whose primary document is ownership XML —
|
|
44
|
+
* EDGAR's structured Form 4 began in mid-2003, and an earlier HTML or text filing has
|
|
45
|
+
* nothing this tool can parse, so fetching it would spend a request on an empty result.
|
|
46
|
+
* Under `reporting_owner`, only rows the feed lists with a file number: EDGAR lists a
|
|
47
|
+
* Form 4 in each reporting owner's feed under the issuer's file number and in the
|
|
48
|
+
* issuer's own feed under none, so the rest name this filer as their issuer and are
|
|
49
|
+
* counted in `issuerRows` instead of read (#260).
|
|
42
50
|
*/
|
|
43
|
-
function windowForm4Rows(block, inWindow) {
|
|
51
|
+
function windowForm4Rows(block, inWindow, role) {
|
|
44
52
|
const rows = [];
|
|
53
|
+
let issuerRows = 0;
|
|
45
54
|
for (let i = 0; i < block.form.length; i++) {
|
|
46
55
|
const form = block.form[i];
|
|
47
56
|
const filingDate = block.filingDate[i] ?? '';
|
|
@@ -50,9 +59,97 @@ function windowForm4Rows(block, inWindow) {
|
|
|
50
59
|
continue;
|
|
51
60
|
if (!/\.xml$/i.test(primaryDocument))
|
|
52
61
|
continue;
|
|
62
|
+
if (role === 'reporting_owner' && !block.fileNumber?.[i]) {
|
|
63
|
+
issuerRows++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
53
66
|
rows.push({ accessionNumber: block.accessionNumber[i] ?? '', filingDate, primaryDocument });
|
|
54
67
|
}
|
|
55
|
-
return rows;
|
|
68
|
+
return { rows, issuerRows };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The filings a scan of at most `cap` reads from `batch` (newest first), ending on a whole
|
|
72
|
+
* filing date so a `filed_before` continuation neither skips nor repeats one (#261): the
|
|
73
|
+
* first `cap` rows, less the date the row after them continues. When that date opens the
|
|
74
|
+
* batch — more Form 4s filed on it than the cap — its first `cap` rows are read and it is
|
|
75
|
+
* returned as `overCapDate`.
|
|
76
|
+
*/
|
|
77
|
+
function capAtWholeDate(batch, cap) {
|
|
78
|
+
const rows = batch.slice(0, cap);
|
|
79
|
+
const next = batch[cap];
|
|
80
|
+
const start = next ? rows.findIndex((filing) => filing.filingDate === next.filingDate) : -1;
|
|
81
|
+
if (!next || start === -1)
|
|
82
|
+
return { rows };
|
|
83
|
+
return start === 0 ? { rows, overCapDate: next.filingDate } : { rows: rows.slice(0, start) };
|
|
84
|
+
}
|
|
85
|
+
/** A YYYY-MM-DD date one day earlier, in UTC. */
|
|
86
|
+
function dayBefore(date) {
|
|
87
|
+
const day = new Date(`${date}T00:00:00Z`);
|
|
88
|
+
day.setUTCDate(day.getUTCDate() - 1);
|
|
89
|
+
return day.toISOString().slice(0, 10);
|
|
90
|
+
}
|
|
91
|
+
/** The way past an archive walk the page cap ended: the date its oldest page starts on. */
|
|
92
|
+
function archiveCapNote(walk) {
|
|
93
|
+
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.`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The way on when `limit` cut `transactions[]` and no dataset holds the rows past the cut
|
|
97
|
+
* (#261): `filed_before` the filing date of the first row cut, where the rows shown from that
|
|
98
|
+
* date repeat and the next call's rows for it replace them — a dedupe on accession_number
|
|
99
|
+
* would drop the rest of a filing the cut split. When every row shown is from that date, the
|
|
100
|
+
* next call needs a larger `limit` to get past them, so one is named; a date holding more
|
|
101
|
+
* transactions than one call returns is read once at the inline cap, then stepped past, so
|
|
102
|
+
* no continuation repeats a call's rows.
|
|
103
|
+
*/
|
|
104
|
+
function cutContinuation(scan) {
|
|
105
|
+
const { dates, limit } = scan;
|
|
106
|
+
const cut = dates[limit];
|
|
107
|
+
const total = dates.filter((date) => date === cut).length;
|
|
108
|
+
const shown = dates.slice(0, limit).filter((date) => date === cut).length;
|
|
109
|
+
const repeat = shown === 0
|
|
110
|
+
? ''
|
|
111
|
+
: shown === 1
|
|
112
|
+
? ` The row shown from ${cut} repeats there; that call's rows for ${cut} replace it, since a filing's rows can straddle the cut.`
|
|
113
|
+
: ` 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.`;
|
|
114
|
+
if (shown < limit) {
|
|
115
|
+
return `The transactions past the ${limit} shown start on ${cut}; pass filed_before=${cut} to read on.${repeat}`;
|
|
116
|
+
}
|
|
117
|
+
if (total > INLINE_TRANSACTION_CAP && limit < INLINE_TRANSACTION_CAP) {
|
|
118
|
+
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}`;
|
|
119
|
+
}
|
|
120
|
+
if (total > INLINE_TRANSACTION_CAP) {
|
|
121
|
+
const older = scan.olderBefore(cut)
|
|
122
|
+
? `; pass filed_before=${dayBefore(cut)} to read the older ones`
|
|
123
|
+
: '';
|
|
124
|
+
return `${cut} holds more than ${INLINE_TRANSACTION_CAP} transactions, more than one call returns${older}.`;
|
|
125
|
+
}
|
|
126
|
+
if (scan.overCapScan !== undefined && scan.overCapScan < INSIDER_FILING_SCAN_CAP) {
|
|
127
|
+
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}`;
|
|
128
|
+
}
|
|
129
|
+
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}`;
|
|
130
|
+
}
|
|
131
|
+
/** Closes every notice that reports filings naming another issuer (#260). */
|
|
132
|
+
const ROLE_LEVER = 'Pass role: "reporting_owner" to read them as this filer\'s own trades.';
|
|
133
|
+
/** `<count> of <scanned> names a different issuer … and contributes none.`, closed by the role lever (#157). */
|
|
134
|
+
function otherIssuerSentence(count, scanned) {
|
|
135
|
+
const one = count === 1;
|
|
136
|
+
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}`;
|
|
137
|
+
}
|
|
138
|
+
/** The `<N> name it as the issuer` close of a `reporting_owner` miss, naming the default role as the way to them. */
|
|
139
|
+
function issuerFilingsNote(count) {
|
|
140
|
+
return `${count} ${count === 1 ? 'names' : 'name'} it as the issuer, which omitting role reads.`;
|
|
141
|
+
}
|
|
142
|
+
/** ` at Tesla, Inc. (TSLA, CIK 0001318605)` for a `reporting_owner` row; nothing for an issuer-role row. */
|
|
143
|
+
function issuerClause(tx) {
|
|
144
|
+
const ids = [
|
|
145
|
+
tx.issuer_ticker && escapeMarkdownInline(tx.issuer_ticker),
|
|
146
|
+
tx.issuer_cik && `CIK ${tx.issuer_cik}`,
|
|
147
|
+
]
|
|
148
|
+
.filter(Boolean)
|
|
149
|
+
.join(', ');
|
|
150
|
+
if (!tx.issuer_name)
|
|
151
|
+
return ids ? ` at ${ids}` : '';
|
|
152
|
+
return ` at ${escapeMarkdownInline(tx.issuer_name)}${ids ? ` (${ids})` : ''}`;
|
|
56
153
|
}
|
|
57
154
|
/** "between A and B" / "on or after A" / "on or before B" for notices. */
|
|
58
155
|
function describeWindow(filedAfter, filedBefore) {
|
|
@@ -83,8 +180,6 @@ function ownerRelationship(owner) {
|
|
|
83
180
|
parts.push('Other');
|
|
84
181
|
return parts.join(', ') || 'Unknown';
|
|
85
182
|
}
|
|
86
|
-
/** Transactions the inline list holds at most; `limit` clamps here (#197). */
|
|
87
|
-
const INLINE_TRANSACTION_CAP = 100;
|
|
88
183
|
/** `limit`: the inline list holds at most 100 transactions (#197). */
|
|
89
184
|
const transactionsLimit = limitClamp({
|
|
90
185
|
tool: 'secedgar_get_insider_transactions',
|
|
@@ -97,7 +192,7 @@ const transactionsLimit = limitClamp({
|
|
|
97
192
|
});
|
|
98
193
|
export const getInsiderTransactionsTool = tool('secedgar_get_insider_transactions', {
|
|
99
194
|
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.',
|
|
195
|
+
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). 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, 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.',
|
|
101
196
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
|
|
102
197
|
errors: [
|
|
103
198
|
{
|
|
@@ -115,7 +210,7 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
115
210
|
{
|
|
116
211
|
reason: 'no_filings_found',
|
|
117
212
|
code: JsonRpcErrorCode.NotFound,
|
|
118
|
-
when: 'A call without a date window finds no Form 4 filings in the recent submissions window',
|
|
213
|
+
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
214
|
recovery: 'Pass filed_after / filed_before to read an older period, or use secedgar_search_filings with forms=["4"] to find the filings.',
|
|
120
215
|
},
|
|
121
216
|
...SEC_UPSTREAM_ERRORS,
|
|
@@ -124,7 +219,11 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
124
219
|
company: z
|
|
125
220
|
.string()
|
|
126
221
|
.min(1)
|
|
127
|
-
.describe('The issuer whose Form 4 filings to read
|
|
222
|
+
.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.'),
|
|
223
|
+
role: z
|
|
224
|
+
.enum(['issuer', 'reporting_owner'])
|
|
225
|
+
.default('issuer')
|
|
226
|
+
.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
227
|
transaction_type: z
|
|
129
228
|
.enum(['purchase', 'sale', 'all'])
|
|
130
229
|
.default('all')
|
|
@@ -139,7 +238,7 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
139
238
|
.describe('YYYY-MM-DD'),
|
|
140
239
|
])
|
|
141
240
|
.optional()
|
|
142
|
-
.describe('Only read Form 4 filings filed on or after this date (YYYY-MM-DD). A date window
|
|
241
|
+
.describe('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.'),
|
|
143
242
|
filed_before: z
|
|
144
243
|
.union([
|
|
145
244
|
z.literal(''),
|
|
@@ -166,6 +265,10 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
166
265
|
issuer_name: z.string().describe('Issuer entity name (SEC-conformed).'),
|
|
167
266
|
issuer_cik: z.string().describe('Issuer CIK, zero-padded to 10 digits.'),
|
|
168
267
|
issuer_ticker: z.string().optional().describe('Issuer ticker symbol when available.'),
|
|
268
|
+
role: z
|
|
269
|
+
.literal('reporting_owner')
|
|
270
|
+
.optional()
|
|
271
|
+
.describe('Present only under role reporting_owner, where issuer_* name the filer.'),
|
|
169
272
|
transactions: z
|
|
170
273
|
.array(z
|
|
171
274
|
.object({
|
|
@@ -173,14 +276,26 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
173
276
|
period_of_report: z
|
|
174
277
|
.string()
|
|
175
278
|
.optional()
|
|
176
|
-
.describe('
|
|
279
|
+
.describe("The filing's period of report: its earliest transaction date (YYYY-MM-DD)."),
|
|
177
280
|
accession_number: z
|
|
178
281
|
.string()
|
|
179
|
-
.describe('Form 4 accession number
|
|
282
|
+
.describe('Form 4 accession number, for secedgar_get_filing.'),
|
|
180
283
|
reporting_person: z.string().describe('Name of the insider who filed the Form 4.'),
|
|
181
284
|
relationship: z
|
|
182
285
|
.string()
|
|
183
286
|
.describe('Relationship to issuer (e.g., "Director", "Officer (CEO)", "10% Owner").'),
|
|
287
|
+
issuer_cik: z
|
|
288
|
+
.string()
|
|
289
|
+
.optional()
|
|
290
|
+
.describe('Issuer CIK, zero-padded (role reporting_owner only).'),
|
|
291
|
+
issuer_name: z
|
|
292
|
+
.string()
|
|
293
|
+
.optional()
|
|
294
|
+
.describe('Issuer name as filed (role reporting_owner only).'),
|
|
295
|
+
issuer_ticker: z
|
|
296
|
+
.string()
|
|
297
|
+
.optional()
|
|
298
|
+
.describe('Issuer ticker as filed (role reporting_owner only).'),
|
|
184
299
|
security_title: z.string().describe('Security type (e.g., "Common Stock").'),
|
|
185
300
|
transaction_date: z
|
|
186
301
|
.string()
|
|
@@ -188,13 +303,13 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
188
303
|
.describe('Date the transaction occurred (YYYY-MM-DD). Absent on some filings.'),
|
|
189
304
|
transaction_code: z
|
|
190
305
|
.string()
|
|
191
|
-
.describe('SEC transaction code: P purchase, S sale, M exercise, A award, G gift, F tax withholding,
|
|
306
|
+
.describe('SEC transaction code: P purchase, S sale, M exercise, A award, G gift, F tax withholding, among others.'),
|
|
192
307
|
transaction_type: z
|
|
193
308
|
.string()
|
|
194
309
|
.describe('Plain-language name of the code (e.g., "purchase", "conversion_of_derivative").'),
|
|
195
310
|
is_derivative: z
|
|
196
311
|
.boolean()
|
|
197
|
-
.describe('True for derivative securities (options, RSUs, convertible notes)
|
|
312
|
+
.describe('True for derivative securities (options, RSUs, convertible notes).'),
|
|
198
313
|
shares_traded: z
|
|
199
314
|
.number()
|
|
200
315
|
.optional()
|
|
@@ -214,43 +329,40 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
214
329
|
ownership_type: z
|
|
215
330
|
.enum(['direct', 'indirect'])
|
|
216
331
|
.optional()
|
|
217
|
-
.describe('Direct, or indirect (
|
|
332
|
+
.describe('Direct, or indirect (trust, family member, etc.). Absent when not reported.'),
|
|
218
333
|
ownership_nature: z
|
|
219
334
|
.string()
|
|
220
335
|
.optional()
|
|
221
336
|
.describe('Nature of indirect ownership (e.g., "By Trust"). Present only when ownership_type is indirect.'),
|
|
222
337
|
})
|
|
223
338
|
.describe('One insider transaction parsed from a Form 4 filing.'))
|
|
224
|
-
.describe(
|
|
339
|
+
.describe("Insider transactions, newest filing first, capped at limit; dataset or the notice's next call reaches the rest."),
|
|
225
340
|
filings_scanned: z
|
|
226
341
|
.number()
|
|
227
342
|
.describe('Form 4 filings scanned, including those in filings_other_issuer.'),
|
|
228
343
|
filings_other_issuer: z
|
|
229
344
|
.number()
|
|
230
|
-
.describe(
|
|
345
|
+
.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
346
|
history_scanned_through: z
|
|
232
347
|
.string()
|
|
233
348
|
.optional()
|
|
234
|
-
.describe('Filing date of the oldest Form 4
|
|
349
|
+
.describe('Filing date of the oldest Form 4 the scan reached (YYYY-MM-DD); absent when it reached none.'),
|
|
235
350
|
dataset: datasetSchema
|
|
236
351
|
.extend({
|
|
237
352
|
truncated: z
|
|
238
353
|
.boolean()
|
|
239
|
-
.describe(
|
|
354
|
+
.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
355
|
})
|
|
241
356
|
.optional()
|
|
242
|
-
.describe('Dataframe of every parsed transaction
|
|
357
|
+
.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
358
|
}),
|
|
244
359
|
enrichment: {
|
|
245
360
|
notice: z
|
|
246
361
|
.string()
|
|
247
362
|
.optional()
|
|
248
|
-
.describe(
|
|
249
|
-
truncated: z
|
|
250
|
-
|
|
251
|
-
.optional()
|
|
252
|
-
.describe('True when the inline transactions[] was capped by limit.'),
|
|
253
|
-
shown: z.number().optional().describe('Number of transactions shown inline.'),
|
|
363
|
+
.describe("Why the result is empty, the dataframe pointer, and the next call's filed_before and limit."),
|
|
364
|
+
truncated: z.boolean().optional().describe('True when limit capped transactions[].'),
|
|
365
|
+
shown: z.number().optional().describe('Transactions shown inline.'),
|
|
254
366
|
cap: z.number().optional().describe('The limit cap applied.'),
|
|
255
367
|
resolvedAs: resolvedAsField,
|
|
256
368
|
},
|
|
@@ -282,21 +394,20 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
282
394
|
const filedBefore = input.filed_before || undefined;
|
|
283
395
|
const dateWindow = filedAfter || filedBefore ? { filedAfter, filedBefore } : undefined;
|
|
284
396
|
// With a canvas available, scan deeper than the inline `limit` so the dataframe
|
|
285
|
-
// holds a useful window for aggregation; without one, stop
|
|
286
|
-
// limit is met (
|
|
287
|
-
// the set, so with a canvas every filing inside it is parsed, up to the cap (#127).
|
|
397
|
+
// holds a useful window for aggregation; without one, stop at the end of the filing
|
|
398
|
+
// date on which the inline limit is met (the low-fetch path). A date window already
|
|
399
|
+
// bounds the set, so with a canvas every filing inside it is parsed, up to the cap (#127).
|
|
288
400
|
const bridge = getCanvasBridge();
|
|
289
401
|
const scanFloor = bridge
|
|
290
402
|
? dateWindow
|
|
291
403
|
? INSIDER_FILING_SCAN_CAP
|
|
292
404
|
: INSIDER_CANVAS_FILING_SCAN
|
|
293
405
|
: 0;
|
|
294
|
-
//
|
|
295
|
-
// filter losses; with a canvas, also
|
|
296
|
-
// `limit` doesn't under-scan the dataframe window (#63). Capped at 100; the
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
const scanCap = Math.min(bridge ? Math.max(limit * 5, scanFloor) : limit * 5, INSIDER_FILING_SCAN_CAP);
|
|
406
|
+
// Reach for 5x the filings `limit` asks for, to account for multi-transaction filings
|
|
407
|
+
// and filter losses; with a canvas, also for at least the scan floor so a small inline
|
|
408
|
+
// `limit` doesn't under-scan the dataframe window (#63). Capped at 100; the row past
|
|
409
|
+
// the cap, when the feed holds one, shows Form 4 filings beyond the scan window.
|
|
410
|
+
const scanCap = Math.min(Math.max(limit * FILINGS_PER_TRANSACTION, scanFloor), INSIDER_FILING_SCAN_CAP);
|
|
300
411
|
// Bare-CIK fallback: a numeric CIK absent from the ticker cache resolves to { cik }
|
|
301
412
|
// with no name/ticker. The submissions feed 404s for such a CIK — it's a
|
|
302
413
|
// filer/transmitter (e.g. an accession-number prefix), not a registrant. Convert
|
|
@@ -313,57 +424,67 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
313
424
|
err instanceof McpError &&
|
|
314
425
|
err.code === JsonRpcErrorCode.NotFound) {
|
|
315
426
|
ctx.log.debug('CIK has no submissions feed', { cik: match.cik });
|
|
316
|
-
throw ctx.fail('company_not_found', `No
|
|
427
|
+
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
428
|
}
|
|
318
429
|
throw err;
|
|
319
430
|
}
|
|
320
431
|
};
|
|
321
|
-
|
|
432
|
+
const ownerRole = input.role === 'reporting_owner';
|
|
433
|
+
// The Form 4 rows the role reads, newest first: the recent window, then in a date
|
|
434
|
+
// window the archive pages overlapping it, read until the scan budget plus one
|
|
435
|
+
// sentinel row is in hand or the shared page cap ends the walk.
|
|
436
|
+
const submissions = await readSubmissionsFeed(api.getSubmissions(match.cik, scope));
|
|
437
|
+
/** In-window Form 4 rows naming the company as their issuer, which `reporting_owner` leaves unread. */
|
|
438
|
+
let issuerRows = 0;
|
|
439
|
+
const inWindow = (date) => (!filedAfter || date >= filedAfter) && (!filedBefore || date <= filedBefore);
|
|
440
|
+
const select = (block) => {
|
|
441
|
+
const selected = windowForm4Rows(block, inWindow, input.role);
|
|
442
|
+
issuerRows += selected.issuerRows;
|
|
443
|
+
return selected.rows;
|
|
444
|
+
};
|
|
445
|
+
const filingBatch = select(submissions.filings.recent);
|
|
322
446
|
let walk;
|
|
323
447
|
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
448
|
walk = new SubmissionsArchiveWalk(api, submissions, { filedAfter, filedBefore, order: 'newest-first' }, scope);
|
|
331
449
|
if (filingBatch.length <= scanCap) {
|
|
332
450
|
for await (const { block } of walk) {
|
|
333
|
-
filingBatch.push(...
|
|
451
|
+
filingBatch.push(...select(block));
|
|
334
452
|
if (filingBatch.length > scanCap)
|
|
335
453
|
break;
|
|
336
454
|
}
|
|
337
455
|
}
|
|
338
456
|
}
|
|
339
|
-
|
|
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);
|
|
457
|
+
const { rows: filingsToScan, overCapDate } = capAtWholeDate(filingBatch, scanCap);
|
|
346
458
|
if (filingBatch.length === 0 && !dateWindow) {
|
|
347
|
-
throw ctx.fail('no_filings_found',
|
|
459
|
+
throw ctx.fail('no_filings_found', issuerRows > 0
|
|
460
|
+
? `No Form 4 in the recent filings of '${input.company}' names it as a reporting owner; ${issuerFilingsNote(issuerRows)}`
|
|
461
|
+
: `No Form 4 filings found for '${input.company}'.`);
|
|
348
462
|
}
|
|
463
|
+
// The ticker file names listed companies only; a person or an unlisted filer takes the
|
|
464
|
+
// name its submissions document carries, already read (#260).
|
|
465
|
+
const companyName = match.name ?? submissions.name;
|
|
349
466
|
const transactions = [];
|
|
350
467
|
let filingsScanned = 0;
|
|
351
468
|
let filingsOtherIssuer = 0;
|
|
352
|
-
/**
|
|
353
|
-
let
|
|
354
|
-
let
|
|
469
|
+
/** Filings the scan reached, and the filing date of the last — the oldest, since filings run newest first. */
|
|
470
|
+
let reached = 0;
|
|
471
|
+
let scannedThrough;
|
|
355
472
|
for (const filing of filingsToScan) {
|
|
356
|
-
|
|
357
|
-
|
|
473
|
+
// Whole filing dates only: once limit and the floor are in hand, stop where the
|
|
474
|
+
// next date begins, so filed_before the day before resumes without a gap (#261).
|
|
475
|
+
if (transactions.length >= limit &&
|
|
476
|
+
filingsScanned >= scanFloor &&
|
|
477
|
+
filing.filingDate !== scannedThrough) {
|
|
358
478
|
break;
|
|
359
479
|
}
|
|
480
|
+
reached++;
|
|
481
|
+
scannedThrough = filing.filingDate;
|
|
360
482
|
// primaryDocument may be prefixed with xslF345X06/ — strip to get the bare filename
|
|
361
483
|
const docName = filing.primaryDocument.replace(/^xsl[^/]+\//, '');
|
|
362
484
|
const xmlText = await api.tryGetFilingDocument(match.cik, filing.accessionNumber, docName, scope);
|
|
363
485
|
if (!xmlText)
|
|
364
486
|
continue;
|
|
365
487
|
filingsScanned++;
|
|
366
|
-
oldestParsed = filing.filingDate;
|
|
367
488
|
let parsed;
|
|
368
489
|
try {
|
|
369
490
|
parsed = parseForm4Xml(xmlText);
|
|
@@ -376,15 +497,32 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
376
497
|
continue;
|
|
377
498
|
}
|
|
378
499
|
// 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
|
-
|
|
500
|
+
// owner of another issuer — that issuer's insider activity, not this one's (#157),
|
|
501
|
+
// and under `reporting_owner` the very filings the call reads (#260).
|
|
502
|
+
if (!ownerRole && parsed.issuer_cik && !sameCik(parsed.issuer_cik, match.cik)) {
|
|
381
503
|
filingsOtherIssuer++;
|
|
382
504
|
continue;
|
|
383
505
|
}
|
|
384
|
-
//
|
|
385
|
-
|
|
506
|
+
// The row's person is the first reporting owner listed — under `reporting_owner`,
|
|
507
|
+
// the one carrying this filer's CIK, since a joint filing lists several (#260).
|
|
508
|
+
const primaryOwner = ownerRole
|
|
509
|
+
? parsed.reporting_owners.find((owner) => sameCik(owner.cik, match.cik))
|
|
510
|
+
: parsed.reporting_owners[0];
|
|
511
|
+
if (ownerRole && !primaryOwner) {
|
|
512
|
+
ctx.log.warning('Form 4 lists no reporting owner with the resolved CIK', {
|
|
513
|
+
accessionNumber: filing.accessionNumber,
|
|
514
|
+
});
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
386
517
|
const personName = primaryOwner?.name ?? 'Unknown';
|
|
387
518
|
const relationship = primaryOwner ? ownerRelationship(primaryOwner) : 'Unknown';
|
|
519
|
+
const rowIssuer = ownerRole
|
|
520
|
+
? {
|
|
521
|
+
...(parsed.issuer_cik && { issuer_cik: parsed.issuer_cik.padStart(10, '0') }),
|
|
522
|
+
...(parsed.issuer_name && { issuer_name: parsed.issuer_name }),
|
|
523
|
+
...(parsed.issuer_ticker && { issuer_ticker: parsed.issuer_ticker }),
|
|
524
|
+
}
|
|
525
|
+
: {};
|
|
388
526
|
// Collect every matching transaction — the full set backs the canvas; the
|
|
389
527
|
// inline response is sliced to `limit` after the scan completes.
|
|
390
528
|
for (const tx of parsed.transactions) {
|
|
@@ -400,6 +538,7 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
400
538
|
accession_number: filing.accessionNumber,
|
|
401
539
|
reporting_person: personName,
|
|
402
540
|
relationship,
|
|
541
|
+
...rowIssuer,
|
|
403
542
|
security_title: tx.security_title,
|
|
404
543
|
transaction_date: tx.transaction_date,
|
|
405
544
|
transaction_code: tx.transaction_code,
|
|
@@ -414,40 +553,68 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
414
553
|
});
|
|
415
554
|
}
|
|
416
555
|
}
|
|
556
|
+
// Form 4 filings past those read, and the filed_before that reaches them (#261). The
|
|
557
|
+
// scan read whole filing dates, so the day before the oldest one resumes it without a
|
|
558
|
+
// gap or a repeat; a date it could not finish, or an archive walk the page cap cut
|
|
559
|
+
// short, resumes on that date instead, and the rows read from it come back again.
|
|
560
|
+
let continuation;
|
|
561
|
+
if (scannedThrough) {
|
|
562
|
+
const through = scannedThrough;
|
|
563
|
+
if (overCapDate) {
|
|
564
|
+
continuation =
|
|
565
|
+
scanCap < INSIDER_FILING_SCAN_CAP
|
|
566
|
+
? `${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.`
|
|
567
|
+
: `${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.`;
|
|
568
|
+
}
|
|
569
|
+
else if (reached < filingBatch.length) {
|
|
570
|
+
continuation = dateWindow
|
|
571
|
+
? `More Form 4 filings in this window predate ${through}; narrow it with filed_before=${dayBefore(through)} to read them.`
|
|
572
|
+
: `Older Form 4 filings exist before ${through}; pass filed_before=${dayBefore(through)} to read them.`;
|
|
573
|
+
}
|
|
574
|
+
else if (walk?.truncated) {
|
|
575
|
+
continuation = `${archiveCapNote(walk)} Any rows already read from ${walk.scannedThrough} repeat, so dedupe on accession_number.`;
|
|
576
|
+
}
|
|
577
|
+
else if (!dateWindow && submissions.filings.files.length > 0) {
|
|
578
|
+
// Every recent Form 4 is read, and older ones can sit on the archive pages.
|
|
579
|
+
continuation = `Older Form 4 filings may exist before ${through}; pass filed_before=${dayBefore(through)} to read them.`;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
417
582
|
const windowText = dateWindow && describeWindow(filedAfter, filedBefore);
|
|
418
583
|
// The notices are authored Markdown, so the caller's company text is escaped.
|
|
419
584
|
const companyText = escapeMarkdownInline(input.company);
|
|
585
|
+
// `ctx.enrich.notice` is last-wins, so the continuation closes whichever notice is set.
|
|
586
|
+
const continuationTail = continuation ? ` ${continuation}` : '';
|
|
420
587
|
if (windowText && filingBatch.length === 0) {
|
|
421
588
|
// 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
|
-
: '';
|
|
589
|
+
const walkNote = walk?.truncated ? ` ${archiveCapNote(walk)}` : '';
|
|
425
590
|
const eraNote = filedBefore && filedBefore < STRUCTURED_FORM4_START
|
|
426
591
|
? ' Structured Form 4 filings begin in mid-2003, so an earlier window finds none.'
|
|
427
592
|
: '';
|
|
428
|
-
|
|
593
|
+
const lead = issuerRows > 0
|
|
594
|
+
? `No Form 4 of '${companyText}' filed ${windowText} names it as a reporting owner; ${issuerFilingsNote(issuerRows)}`
|
|
595
|
+
: `No Form 4 filings filed ${windowText} for '${companyText}'.`;
|
|
596
|
+
ctx.enrich.notice(`${lead}${walkNote}${eraNote}`);
|
|
429
597
|
}
|
|
430
598
|
else if (transactions.length === 0) {
|
|
431
599
|
const filterNote = input.transaction_type !== 'all'
|
|
432
600
|
? ` with transaction_type="${input.transaction_type}"`
|
|
433
601
|
: '';
|
|
434
602
|
const filings = `Form 4 filing${filingsScanned === 1 ? '' : 's'}`;
|
|
603
|
+
const ownerNote = ownerRole ? ' naming it as a reporting owner' : '';
|
|
435
604
|
const scope = windowText
|
|
436
|
-
? `the ${filingsScanned} ${filings} filed ${windowText}`
|
|
437
|
-
: `the ${filingsScanned} most recent ${filings}`;
|
|
605
|
+
? `the ${filingsScanned} ${filings} filed ${windowText}${ownerNote}`
|
|
606
|
+
: `the ${filingsScanned} most recent ${filings}${ownerNote}`;
|
|
438
607
|
const lead = `No insider transactions found for '${companyText}'${filterNote} in ${scope}`;
|
|
608
|
+
// Filings naming another issuer are this filer's own trades, which the other role reads (#260).
|
|
439
609
|
if (filingsOtherIssuer > 0 && filingsOtherIssuer === filingsScanned) {
|
|
440
610
|
// Every filing read is another issuer's insider activity, so no filter or
|
|
441
611
|
// broader form search surfaces this company's rows from them (#157).
|
|
442
612
|
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
|
|
613
|
+
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
614
|
}
|
|
445
615
|
else {
|
|
446
|
-
const otherIssuerNote = filingsOtherIssuer > 0
|
|
447
|
-
|
|
448
|
-
: '';
|
|
449
|
-
ctx.enrich.notice(`${lead}.${otherIssuerNote} ` +
|
|
450
|
-
`Try transaction_type="all" or use secedgar_search_filings with forms=["4"] for broader coverage.`);
|
|
616
|
+
const otherIssuerNote = filingsOtherIssuer > 0 ? ` ${otherIssuerSentence(filingsOtherIssuer, 'them')}` : '';
|
|
617
|
+
ctx.enrich.notice(`${lead}. Try transaction_type="all" or use secedgar_search_filings with forms=["4"] for broader coverage.${otherIssuerNote}${continuationTail}`);
|
|
451
618
|
}
|
|
452
619
|
}
|
|
453
620
|
// Use issuer data from the resolved entity (the submissions API may not always
|
|
@@ -455,17 +622,17 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
455
622
|
const issuerTicker = match.ticker ?? undefined;
|
|
456
623
|
// Register the full scanned transaction set to the canvas; the inline response
|
|
457
624
|
// 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
|
|
625
|
+
// dataframe is self-contained for SQL aggregation and cross-issuer joins: the
|
|
626
|
+
// resolved company, or under `reporting_owner` each filing's own issuer.
|
|
459
627
|
let dataset;
|
|
460
628
|
if (bridge && transactions.length > 0) {
|
|
461
|
-
//
|
|
462
|
-
|
|
463
|
-
// more filings than the scan cap (the +1 sentinel fetch above) (#63).
|
|
464
|
-
const truncated = !scannedWholeWindow || moreBeyondWindow;
|
|
629
|
+
// Truncated exactly when the continuation names Form 4 filings past those read (#63, #261).
|
|
630
|
+
const truncated = continuation !== undefined;
|
|
465
631
|
const registered = await bridge.registerDataframe(ctx, {
|
|
466
632
|
rows: transactions.map((t) => ({
|
|
467
|
-
issuer_cik: match.cik,
|
|
468
|
-
issuer_ticker: issuerTicker ?? null,
|
|
633
|
+
issuer_cik: ownerRole ? (t.issuer_cik ?? null) : match.cik,
|
|
634
|
+
issuer_ticker: ownerRole ? (t.issuer_ticker ?? null) : (issuerTicker ?? null),
|
|
635
|
+
issuer_name: ownerRole ? (t.issuer_name ?? null) : companyName,
|
|
469
636
|
reporting_person: t.reporting_person,
|
|
470
637
|
relationship: t.relationship,
|
|
471
638
|
security_title: t.security_title,
|
|
@@ -487,6 +654,7 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
487
654
|
queryParams: {
|
|
488
655
|
company: input.company,
|
|
489
656
|
cik: match.cik,
|
|
657
|
+
role: input.role,
|
|
490
658
|
transaction_type: input.transaction_type,
|
|
491
659
|
filed_after: filedAfter,
|
|
492
660
|
filed_before: filedBefore,
|
|
@@ -497,22 +665,47 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
497
665
|
dataset = { ...toDatasetField(registered), truncated };
|
|
498
666
|
}
|
|
499
667
|
const inlineTransactions = transactions.slice(0, limit);
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
668
|
+
// With no dataset to hold them, the rows `limit` cut are reached only by reading their
|
|
669
|
+
// filing date again, so the way on resumes there in place of the one past the scan (#261).
|
|
670
|
+
const wayOn = !dataset && transactions.length > limit
|
|
671
|
+
? cutContinuation({
|
|
672
|
+
dates: transactions.map((t) => t.filing_date),
|
|
673
|
+
limit,
|
|
674
|
+
overCapScan: overCapDate ? scanCap : undefined,
|
|
675
|
+
scanFillLimit: bridge ? 0 : INSIDER_FILING_SCAN_CAP / FILINGS_PER_TRANSACTION,
|
|
676
|
+
olderBefore: (date) => filingBatch.some((filing) => filing.filingDate < date) ||
|
|
677
|
+
Boolean(walk?.truncated) ||
|
|
678
|
+
(!dateWindow && submissions.filings.files.length > 0),
|
|
679
|
+
})
|
|
680
|
+
: continuation;
|
|
681
|
+
if (transactions.length > 0) {
|
|
682
|
+
// Filings naming another issuer are this filer's own trades, which the other role reads (#260).
|
|
683
|
+
const closing = [
|
|
684
|
+
filingsOtherIssuer > 0 &&
|
|
685
|
+
otherIssuerSentence(filingsOtherIssuer, `the ${filingsScanned} Form 4 filings scanned`),
|
|
686
|
+
wayOn,
|
|
687
|
+
];
|
|
688
|
+
const sentences = (...parts) => parts.filter(Boolean).join(' ');
|
|
689
|
+
if (transactions.length > limit) {
|
|
690
|
+
ctx.enrich.truncated({
|
|
691
|
+
shown: inlineTransactions.length,
|
|
692
|
+
cap: limit,
|
|
693
|
+
guidance: sentences(dataset
|
|
694
|
+
? dataframeGuidance(dataset)
|
|
695
|
+
: limit < INLINE_TRANSACTION_CAP
|
|
696
|
+
? `Raise limit (at most ${INLINE_TRANSACTION_CAP} inline), or narrow with filed_after, filed_before, or transaction_type.`
|
|
697
|
+
: 'Narrow with filed_after, filed_before, or transaction_type to reach the rest.', ...closing),
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
const notice = sentences(dataset && dataframeGuidance(dataset), ...closing);
|
|
702
|
+
if (notice)
|
|
703
|
+
ctx.enrich.notice(notice);
|
|
704
|
+
}
|
|
513
705
|
}
|
|
514
706
|
ctx.log.info('Insider transactions retrieved', {
|
|
515
707
|
cik: match.cik,
|
|
708
|
+
role: input.role,
|
|
516
709
|
filingsScanned,
|
|
517
710
|
filingsOtherIssuer,
|
|
518
711
|
transactionCount: transactions.length,
|
|
@@ -521,13 +714,14 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
521
714
|
datasetName: dataset?.name,
|
|
522
715
|
});
|
|
523
716
|
return {
|
|
524
|
-
issuer_name:
|
|
717
|
+
issuer_name: companyName,
|
|
525
718
|
issuer_cik: match.cik,
|
|
526
719
|
issuer_ticker: issuerTicker,
|
|
720
|
+
...(ownerRole && { role: 'reporting_owner' }),
|
|
527
721
|
transactions: inlineTransactions,
|
|
528
722
|
filings_scanned: filingsScanned,
|
|
529
723
|
filings_other_issuer: filingsOtherIssuer,
|
|
530
|
-
...(
|
|
724
|
+
...(scannedThrough && { history_scanned_through: scannedThrough }),
|
|
531
725
|
dataset,
|
|
532
726
|
};
|
|
533
727
|
},
|
|
@@ -536,10 +730,11 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
536
730
|
const otherIssuerNote = otherIssuer > 0
|
|
537
731
|
? `; ${otherIssuer} ${otherIssuer === 1 ? 'names another issuer and contributes' : 'name another issuer and contribute'} none`
|
|
538
732
|
: '';
|
|
733
|
+
const owner = result.role === 'reporting_owner';
|
|
539
734
|
// Names and titles are SEC or filer text, escaped to read back as written.
|
|
540
735
|
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}`,
|
|
736
|
+
`**Insider Transactions** — ${escapeMarkdownInline(result.issuer_name)} (CIK ${result.issuer_cik}${result.issuer_ticker ? `, ${result.issuer_ticker}` : ''})${owner ? ' as reporting owner' : ''}`,
|
|
737
|
+
`${result.transactions.length} transaction(s) from ${result.filings_scanned} Form 4 filing(s) scanned${otherIssuerNote}${owner ? ' (role: reporting_owner)' : ''}`,
|
|
543
738
|
];
|
|
544
739
|
// One legend rather than a per-row tag: every row spells the direction out
|
|
545
740
|
// as "shares acquired" / "shares disposed", and repeating the raw enum on
|
|
@@ -564,7 +759,7 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
564
759
|
: tx.ownership_type
|
|
565
760
|
? ` (${tx.ownership_type})`
|
|
566
761
|
: '';
|
|
567
|
-
lines.push(`**${escapeMarkdownInline(tx.reporting_person)}** (${escapeMarkdownInline(tx.relationship)}) — ${tx.transaction_type}${derivStr}`);
|
|
762
|
+
lines.push(`**${escapeMarkdownInline(tx.reporting_person)}** (${escapeMarkdownInline(tx.relationship)})${issuerClause(tx)} — ${tx.transaction_type}${derivStr}`);
|
|
568
763
|
const txDate = tx.transaction_date ?? tx.filing_date;
|
|
569
764
|
const periodStr = tx.period_of_report ? ` | report period: ${tx.period_of_report}` : '';
|
|
570
765
|
lines.push(`${txDate} | ${escapeMarkdownInline(tx.security_title)} | ${sharesStr} ${priceStr}${ownedStr}${ownershipStr}${periodStr}`);
|
|
@@ -575,7 +770,7 @@ export const getInsiderTransactionsTool = tool('secedgar_get_insider_transaction
|
|
|
575
770
|
}
|
|
576
771
|
if (result.dataset) {
|
|
577
772
|
const truncatedNote = result.dataset.truncated
|
|
578
|
-
? ' (truncated — more Form 4 filings exist beyond those scanned)'
|
|
773
|
+
? ' (truncated — more Form 4 filings may exist beyond those scanned)'
|
|
579
774
|
: '';
|
|
580
775
|
lines.push(`\nDataset: ${result.dataset.name} (${result.dataset.row_count} rows, expires ${result.dataset.expires_at})${truncatedNote} — query with secedgar_dataframe_query.`);
|
|
581
776
|
}
|