@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.
- package/AGENTS.md +41 -33
- package/CLAUDE.md +41 -33
- package/README.md +37 -16
- package/changelog/0.20.x/0.20.1.md +39 -0
- package/changelog/0.21.x/0.21.0.md +35 -0
- package/changelog/template.md +10 -8
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/prompts/definitions/company-analysis.prompt.js +3 -3
- package/dist/mcp-server/prompts/definitions/company-analysis.prompt.js.map +1 -1
- package/dist/mcp-server/tools/annual-report-reads.d.ts +50 -0
- package/dist/mcp-server/tools/annual-report-reads.d.ts.map +1 -0
- package/dist/mcp-server/tools/annual-report-reads.js +141 -0
- package/dist/mcp-server/tools/annual-report-reads.js.map +1 -0
- package/dist/mcp-server/tools/calendar-quarter.d.ts +22 -0
- package/dist/mcp-server/tools/calendar-quarter.d.ts.map +1 -0
- package/dist/mcp-server/tools/calendar-quarter.js +34 -0
- package/dist/mcp-server/tools/calendar-quarter.js.map +1 -0
- package/dist/mcp-server/tools/definitions/company-search.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/company-search.tool.js +11 -22
- package/dist/mcp-server/tools/definitions/company-search.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts +12 -2
- package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/compare-companies.tool.js +153 -48
- 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.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/find-holders.tool.js +12 -19
- package/dist/mcp-server/tools/definitions/find-holders.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.d.ts +24 -9
- package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js +126 -47
- 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 +24 -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 +370 -92
- 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 +127 -44
- package/dist/mcp-server/tools/definitions/get-financials.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js +5 -6
- 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 +42 -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 +525 -134
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.d.ts +12 -0
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js +21 -36
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-material-events.tool.d.ts +15 -0
- package/dist/mcp-server/tools/definitions/get-material-events.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-material-events.tool.js +108 -55
- 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 +5 -0
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.js +70 -37
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +282 -219
- 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 +18 -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 +130 -68
- package/dist/mcp-server/tools/definitions/search-filings.tool.js.map +1 -1
- package/dist/mcp-server/tools/filing-dates.d.ts +46 -0
- package/dist/mcp-server/tools/filing-dates.d.ts.map +1 -0
- package/dist/mcp-server/tools/filing-dates.js +93 -0
- package/dist/mcp-server/tools/filing-dates.js.map +1 -0
- package/dist/mcp-server/tools/limit-clamp.d.ts.map +1 -1
- package/dist/mcp-server/tools/limit-clamp.js +6 -2
- package/dist/mcp-server/tools/limit-clamp.js.map +1 -1
- package/dist/services/edgar/body-text-decoder.d.ts +33 -0
- package/dist/services/edgar/body-text-decoder.d.ts.map +1 -0
- package/dist/services/edgar/body-text-decoder.js +103 -0
- package/dist/services/edgar/body-text-decoder.js.map +1 -0
- 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 +88 -14
- package/dist/services/edgar/concept-map.js.map +1 -1
- package/dist/services/edgar/concept-series.d.ts +111 -1
- package/dist/services/edgar/concept-series.d.ts.map +1 -1
- package/dist/services/edgar/concept-series.js +196 -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 +30 -39
- package/dist/services/edgar/edgar-api-service.js.map +1 -1
- package/dist/services/edgar/eight-k-items.d.ts +19 -1
- package/dist/services/edgar/eight-k-items.d.ts.map +1 -1
- package/dist/services/edgar/eight-k-items.js +24 -1
- package/dist/services/edgar/eight-k-items.js.map +1 -1
- package/dist/services/edgar/filing-to-text.d.ts +29 -10
- package/dist/services/edgar/filing-to-text.d.ts.map +1 -1
- package/dist/services/edgar/filing-to-text.js +605 -53
- 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/form4-amendments.d.ts +63 -0
- package/dist/services/edgar/form4-amendments.d.ts.map +1 -0
- package/dist/services/edgar/form4-amendments.js +99 -0
- package/dist/services/edgar/form4-amendments.js.map +1 -0
- package/dist/services/edgar/mirror/companyfacts-sync.d.ts +6 -1
- package/dist/services/edgar/mirror/companyfacts-sync.d.ts.map +1 -1
- package/dist/services/edgar/mirror/companyfacts-sync.js +29 -6
- package/dist/services/edgar/mirror/companyfacts-sync.js.map +1 -1
- package/dist/services/edgar/ownership-parser.d.ts +5 -0
- package/dist/services/edgar/ownership-parser.d.ts.map +1 -1
- package/dist/services/edgar/ownership-parser.js +3 -0
- package/dist/services/edgar/ownership-parser.js.map +1 -1
- package/dist/services/edgar/types.d.ts +12 -7
- 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 +22 -5
|
@@ -9,7 +9,7 @@ import { limitClamp, withLimitClamps, } from '../limit-clamp.js';
|
|
|
9
9
|
import { SEC_UPSTREAM_ERRORS } from '../sec-upstream-errors.js';
|
|
10
10
|
import { CallScope } from '../../../services/edgar/call-scope.js';
|
|
11
11
|
import { filingArchiveUrl, getEdgarApiService } from '../../../services/edgar/edgar-api-service.js';
|
|
12
|
-
import { detectHeadings, filingToExtract, findPhrase, foldForHeadingMatch, getExtractCache, headingKey, isTocHeading, linkedSectionStart, MARKER_TITLE_RE, matchSectionLine, setExtractCache, spaceRunInMarker, windowText, withoutSubItemLabel, } from '../../../services/edgar/filing-to-text.js';
|
|
12
|
+
import { deleteExtractCache, detectHeadings, filingToExtract, findPhrase, foldForHeadingMatch, getExtractCache, headingKey, isTocHeading, linkedSectionStart, MARKER_TITLE_RE, matchSectionLine, setExtractCache, spaceRunInMarker, windowText, withoutSubItemLabel, } from '../../../services/edgar/filing-to-text.js';
|
|
13
13
|
const MAX_DOCUMENTS_IN_FORMAT = 10;
|
|
14
14
|
/**
|
|
15
15
|
* Per-category cap on the catalog rendered into an error message. Distinct from
|
|
@@ -67,7 +67,7 @@ const contentLimit = limitClamp({
|
|
|
67
67
|
cap: 200_000,
|
|
68
68
|
bound: 1_000_000,
|
|
69
69
|
shape: (n) => n.default(50000),
|
|
70
|
-
description: '
|
|
70
|
+
description: 'Characters of document text per page. Default 50,000 (about 12,000 words); 200,000 fits full financial statements, and a 10-K can pass 500,000. Page on with offset; section and find open a page at a heading or a phrase.',
|
|
71
71
|
});
|
|
72
72
|
export const getFilingTool = tool('secedgar_get_filing', {
|
|
73
73
|
description: "Fetch a specific filing's metadata and document content by accession number. Returns the primary document as readable text. Use offset/next_offset for multi-page access to large filings (10-K, S-1 can exceed 1M chars): pass the next_offset from a truncated response as offset, without section or find, to read the next page. Use section to jump directly to a heading (e.g. 'risk factors', 'item 7') without needing an offset, or find to open the page at a phrase in the text (e.g. 'net revenue retention') and list where it occurs.",
|
|
@@ -79,7 +79,7 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
79
79
|
notice: z
|
|
80
80
|
.string()
|
|
81
81
|
.optional()
|
|
82
|
-
.describe('
|
|
82
|
+
.describe('Later filings amending this one; how to read the next page or list more occurrences of find; which file was read when the archive lacks the indexed primary; a section landing on a document line; the detected-heading count when the outline lists fewer.'),
|
|
83
83
|
truncated: z
|
|
84
84
|
.boolean()
|
|
85
85
|
.optional()
|
|
@@ -109,9 +109,16 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
109
109
|
{
|
|
110
110
|
reason: 'filing_not_found',
|
|
111
111
|
code: JsonRpcErrorCode.NotFound,
|
|
112
|
-
when: 'No
|
|
112
|
+
when: 'No EDGAR source lists the accession number — no directory tried holds it, full-text search has no record of it, and SEC serves no index page for it — or the lookups that could show it were unavailable',
|
|
113
113
|
recovery: 'Verify the accession number and pass the company CIK explicitly.',
|
|
114
114
|
},
|
|
115
|
+
{
|
|
116
|
+
reason: 'filing_not_served',
|
|
117
|
+
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
118
|
+
when: 'EDGAR shows the filing exists — full-text search lists it, SEC serves its index page, or this server read it earlier — but the SEC archive answered 404 for its directory listing under every CIK tried, an answer SEC caches for several minutes',
|
|
119
|
+
recovery: 'Retry the same call in a few minutes — the SEC archive is not serving this existing filing right now, and nothing in the request needs to change.',
|
|
120
|
+
retryable: true,
|
|
121
|
+
},
|
|
115
122
|
{
|
|
116
123
|
reason: 'offset_out_of_range',
|
|
117
124
|
code: JsonRpcErrorCode.ValidationError,
|
|
@@ -141,7 +148,7 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
141
148
|
.string()
|
|
142
149
|
.regex(/^\d{1,10}$/, 'Expected a CIK of 1-10 digits')
|
|
143
150
|
.optional()
|
|
144
|
-
.describe("Filer CIK, digits only (
|
|
151
|
+
.describe("Filer CIK, digits only (from secedgar_company_search). Optional but faster. Omitted, the filer is found from the accession number through full-text search (2001 on) and its prefix, often a filing agent's CIK, then through the filers its index page names."),
|
|
145
152
|
content_limit: contentLimit.schema(true),
|
|
146
153
|
document: z
|
|
147
154
|
.string()
|
|
@@ -150,7 +157,7 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
150
157
|
include_xbrl: z
|
|
151
158
|
.boolean()
|
|
152
159
|
.default(false)
|
|
153
|
-
.describe('
|
|
160
|
+
.describe('List XBRL viewer artifacts and taxonomy files (R*.htm, linkbase and instance .xml, .xsd, MetaLinks.json, FilingSummary.xml, Show.js, report.css, *-xbrl.zip, Financial_Report.xlsx, EX-101.* exhibits) under documents.xbrl. Off by default: about 100 entries on a typical 10-K, rarely needed to read it.'),
|
|
154
161
|
offset: z
|
|
155
162
|
.number()
|
|
156
163
|
.int()
|
|
@@ -161,12 +168,12 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
161
168
|
.string()
|
|
162
169
|
.min(1)
|
|
163
170
|
.optional()
|
|
164
|
-
.describe("Jump to a
|
|
171
|
+
.describe("Jump to a heading or document line (e.g. 'risk factors', 'item 7'), ignoring case, whitespace, and quote style; 'item 1' never reaches Item 10. For a phrase that is not a heading, use find. Outranks find and offset, so leave it out when paging with next_offset."),
|
|
165
172
|
find: z
|
|
166
173
|
.string()
|
|
167
174
|
.max(MAX_FIND_CHARS)
|
|
168
175
|
.optional()
|
|
169
|
-
.describe("Open the page at a phrase
|
|
176
|
+
.describe("Open the page at a phrase (e.g. 'net revenue retention') and list up to 20 occurrences from there. A substring match ignoring case, whitespace runs, and quote style; no patterns. The search starts at offset, so leave find out when paging with next_offset; section outranks it. Blank is omitted."),
|
|
170
177
|
}),
|
|
171
178
|
output: z.object({
|
|
172
179
|
accession_number: z.string().describe('Filing accession number, normalized to dash format.'),
|
|
@@ -177,7 +184,7 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
177
184
|
filing_date: z
|
|
178
185
|
.string()
|
|
179
186
|
.optional()
|
|
180
|
-
.describe('
|
|
187
|
+
.describe('Filing date (YYYY-MM-DD). Absent under the same conditions as form.'),
|
|
181
188
|
company_name: z
|
|
182
189
|
.string()
|
|
183
190
|
.optional()
|
|
@@ -187,6 +194,16 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
187
194
|
.string()
|
|
188
195
|
.optional()
|
|
189
196
|
.describe('Period of report (YYYY-MM-DD), from the same source as form. Absent for forms without one (S-8, Form 4, proxy statements) or when neither source has it.'),
|
|
197
|
+
later_filings: z
|
|
198
|
+
.array(z
|
|
199
|
+
.object({
|
|
200
|
+
accession_number: z.string().describe('Pass as accession_number to read it.'),
|
|
201
|
+
form: z.string().describe('"10-K/A", "RW", …'),
|
|
202
|
+
filing_date: z.string().describe('YYYY-MM-DD.'),
|
|
203
|
+
})
|
|
204
|
+
.describe('One later filing.'))
|
|
205
|
+
.optional()
|
|
206
|
+
.describe('Later amendments or withdrawals, oldest first: /A of a 10-K, 10-KT, 10-Q, 10-QT, 20-F, or 40-F period; /A or RW of an S-1, S-3, S-4, S-11, F-1, F-3, F-4, F-6, F-10, SF-1, or SF-3. Absent when none was found; see the notice.'),
|
|
190
207
|
primary_document: z
|
|
191
208
|
.string()
|
|
192
209
|
.describe("Primary document as read: an XML form's SEC rendering (xsl…/form4.xml) up to 600 KB raw; a 2000–2001 name SEC does not serve, as <accession>-<name>, else the full submission <accession>.txt."),
|
|
@@ -273,7 +290,8 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
273
290
|
const resolved = await resolveFilingArchive(api, scope, accn, input.cik, document);
|
|
274
291
|
if (!resolved.ok) {
|
|
275
292
|
// Each miss below comes after every directory the filer lookups found was
|
|
276
|
-
// tried, so the filer's own CIK is the way out an archive miss offers (#203)
|
|
293
|
+
// tried, so the filer's own CIK is the way out an archive miss offers (#203) —
|
|
294
|
+
// except a filing EDGAR shows exists, which only a retry reaches (#256).
|
|
277
295
|
const lookupNote = resolved.kind !== 'binary_document' && resolved.filerLookupFailed
|
|
278
296
|
? `${FILER_LOOKUP_UNAVAILABLE} `
|
|
279
297
|
: '';
|
|
@@ -345,11 +363,30 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
345
363
|
},
|
|
346
364
|
});
|
|
347
365
|
}
|
|
366
|
+
if (resolved.kind === 'filing_not_served') {
|
|
367
|
+
const source = resolved.evidence === 'full_text_search'
|
|
368
|
+
? 'EDGAR full-text search lists it'
|
|
369
|
+
: 'SEC serves its index page';
|
|
370
|
+
const { ciksTried } = resolved;
|
|
371
|
+
throw ctx.fail('filing_not_served', `Filing '${accn}' exists — ${source} — but the SEC archive answered 404 for its directory listing under ${ciksTried.length === 1 ? 'CIK' : 'CIKs'} ${ciksTried.join(', ')}.`, {
|
|
372
|
+
accession_number: accn,
|
|
373
|
+
ciks_tried: ciksTried,
|
|
374
|
+
...(resolved.filerLookupFailed && {
|
|
375
|
+
recovery: {
|
|
376
|
+
hint: `${lookupNote}${ctx.recoveryFor('filing_not_served').recovery.hint}`,
|
|
377
|
+
},
|
|
378
|
+
}),
|
|
379
|
+
});
|
|
380
|
+
}
|
|
348
381
|
const cikSuffix = resolved.providedCik
|
|
349
382
|
? ` (CIK ${resolved.providedCik.padStart(10, '0')})`
|
|
350
383
|
: '';
|
|
384
|
+
// A lookup that could have shown the filing exists was unavailable, so a retry
|
|
385
|
+
// can reach what this call could not (#215, #256).
|
|
351
386
|
const recoveryHint = resolved.providedCik
|
|
352
|
-
?
|
|
387
|
+
? resolved.filerLookupFailed
|
|
388
|
+
? `${lookupNote}Verify the accession number and CIK are correct, or retry in a minute.`
|
|
389
|
+
: 'Verify the accession number and CIK are correct.'
|
|
353
390
|
: resolved.filerLookupFailed
|
|
354
391
|
? `${lookupNote}Pass ${FILER_CIK}, or retry in a minute.`
|
|
355
392
|
: 'Verify the accession number and pass the company CIK explicitly.';
|
|
@@ -378,14 +415,15 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
378
415
|
else {
|
|
379
416
|
// Cache hit — still need metadata. Re-resolve the index under the CIK whose
|
|
380
417
|
// archive served the cached text (no candidate search, no document body fetch).
|
|
381
|
-
//
|
|
382
|
-
//
|
|
418
|
+
// The cached text shows the filing exists, so an archive that no longer serves
|
|
419
|
+
// its listing there is SEC's to clear, not a missing filing (#256): fail as
|
|
420
|
+
// such rather than fabricating placeholder metadata. The entry goes, so the
|
|
421
|
+
// next call resolves the filing in full and answers what SEC shows then —
|
|
422
|
+
// a filing SEC has since removed fails filing_not_found there.
|
|
383
423
|
const metaResolved = await resolveFilingMeta(api, scope, accn, cached.cik, document);
|
|
384
424
|
if (!metaResolved.ok) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
cik: input.cik,
|
|
388
|
-
});
|
|
425
|
+
deleteExtractCache(cacheKey);
|
|
426
|
+
throw ctx.fail('filing_not_served', `Filing '${accn}' exists — this server read it earlier under CIK ${cached.cik} — but the SEC archive is not serving it there now.`, { accession_number: accn, ciks_tried: [cached.cik] });
|
|
389
427
|
}
|
|
390
428
|
resolvedCik = cached.cik;
|
|
391
429
|
index = metaResolved.index;
|
|
@@ -416,6 +454,11 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
416
454
|
const form = idx >= 0 ? recent.form[idx] : header?.form;
|
|
417
455
|
const filingDate = idx >= 0 ? recent.filingDate[idx] : header?.filingDate;
|
|
418
456
|
const periodEnding = idx >= 0 ? recent.reportDate[idx] : header?.periodOfReport;
|
|
457
|
+
// The same feed names the filings that amend or withdraw this one; no request.
|
|
458
|
+
// A filing the feed omits is placed among its rows by its own filing date (#268).
|
|
459
|
+
const laterCheck = checkLaterFilings(recent, idx, form, periodEnding, filingDate);
|
|
460
|
+
const laterNotice = laterCheck && laterFilingsNotice(laterCheck);
|
|
461
|
+
const laterFilings = laterCheck?.kind === 'checked' && laterCheck.filings.length ? laterCheck.filings : undefined;
|
|
419
462
|
// Where the page starts: section, else find, else offset. Under find, offset
|
|
420
463
|
// is where the search starts (#238).
|
|
421
464
|
let effectiveOffset = input.offset ?? 0;
|
|
@@ -441,6 +484,9 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
441
484
|
else if (landing?.source === 'line-over-heading') {
|
|
442
485
|
lineNotice = `No detected heading equals section '${sectionText}', so this page starts at the first document line that does, ahead of headings that only contain it.`;
|
|
443
486
|
}
|
|
487
|
+
else if (landing?.source === 'line-over-toc') {
|
|
488
|
+
lineNotice = `No detected heading outside the table of contents matches section '${sectionText}', so this page starts at the first document line that does.`;
|
|
489
|
+
}
|
|
444
490
|
if (landing === undefined) {
|
|
445
491
|
// Render the outline into the message itself — clients reliably see only
|
|
446
492
|
// message + recovery hint, not error data (#70).
|
|
@@ -534,13 +580,13 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
534
580
|
ctx.enrich.truncated({
|
|
535
581
|
shown: text.length,
|
|
536
582
|
cap: pageLimit,
|
|
537
|
-
guidance: [fallbackNotice, lineNotice, findNotice, paging, outlineCut]
|
|
583
|
+
guidance: [laterNotice, fallbackNotice, lineNotice, findNotice, paging, outlineCut]
|
|
538
584
|
.filter(Boolean)
|
|
539
585
|
.join(' '),
|
|
540
586
|
});
|
|
541
587
|
}
|
|
542
|
-
else if (fallbackNotice || lineNotice || findNotice) {
|
|
543
|
-
ctx.enrich.notice([fallbackNotice, lineNotice, findNotice].filter(Boolean).join(' '));
|
|
588
|
+
else if (laterNotice || fallbackNotice || lineNotice || findNotice) {
|
|
589
|
+
ctx.enrich.notice([laterNotice, fallbackNotice, lineNotice, findNotice].filter(Boolean).join(' '));
|
|
544
590
|
}
|
|
545
591
|
// Headers give canonical document types; without them categorization falls
|
|
546
592
|
// back to name-pattern inference.
|
|
@@ -570,6 +616,7 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
570
616
|
company_name: submissions.name || undefined,
|
|
571
617
|
cik: resolvedCik,
|
|
572
618
|
period_ending: periodEnding || undefined,
|
|
619
|
+
later_filings: laterFilings,
|
|
573
620
|
primary_document: primaryDocument,
|
|
574
621
|
requested_document: requestedDocument,
|
|
575
622
|
documents,
|
|
@@ -598,6 +645,12 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
598
645
|
const filedPart = result.filing_date ? `Filed: ${result.filing_date}` : 'Filed: Unknown';
|
|
599
646
|
const periodPart = result.period_ending ? ` | Period: ${result.period_ending}` : '';
|
|
600
647
|
const dateLine = `${filedPart}${periodPart}`;
|
|
648
|
+
// Forms and accessions here come from a fixed vocabulary and digits, so they render raw as the form label does.
|
|
649
|
+
const laterLine = result.later_filings
|
|
650
|
+
? `\nLater filings: ${result.later_filings
|
|
651
|
+
.map((f) => `${f.form} ${f.accession_number} (filed ${f.filing_date})`)
|
|
652
|
+
.join(', ')}`
|
|
653
|
+
: '';
|
|
601
654
|
const docLabel = result.requested_document
|
|
602
655
|
? `Primary: ${result.primary_document} | Requested: ${result.requested_document}`
|
|
603
656
|
: `Primary: ${result.primary_document}`;
|
|
@@ -623,7 +676,7 @@ export const getFilingTool = tool('secedgar_get_filing', {
|
|
|
623
676
|
return [
|
|
624
677
|
{
|
|
625
678
|
type: 'text',
|
|
626
|
-
text: `${header}\n${dateLine}\n${meta}${docs}${outlineText}${occurrencesText}${url}\n\n${FILING_CONTENT_BEGIN}\n${body}\n${FILING_CONTENT_END}`,
|
|
679
|
+
text: `${header}\n${dateLine}${laterLine}\n${meta}${docs}${outlineText}${occurrencesText}${url}\n\n${FILING_CONTENT_BEGIN}\n${body}\n${FILING_CONTENT_END}`,
|
|
627
680
|
},
|
|
628
681
|
];
|
|
629
682
|
},
|
|
@@ -633,7 +686,7 @@ export function createGetFilingTool(options) {
|
|
|
633
686
|
return withLimitClamps(getFilingTool, [contentLimit], options);
|
|
634
687
|
}
|
|
635
688
|
/**
|
|
636
|
-
* A heading or `section` value folded for {@link
|
|
689
|
+
* A heading or `section` value folded for {@link sectionMatchRank}: Unicode
|
|
637
690
|
* whitespace runs and typographic quotes folded on both operands, so a heading
|
|
638
691
|
* re-sent from a rendered outline still matches the bytes it came from (#106),
|
|
639
692
|
* with a space read in where a marker runs straight into its title
|
|
@@ -644,41 +697,61 @@ function foldForSectionMatch(value) {
|
|
|
644
697
|
return foldForHeadingMatch(spaceRunInMarker(value));
|
|
645
698
|
}
|
|
646
699
|
/**
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* `
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
700
|
+
* How a folded `section` needle matches a folded heading: 0 for a substring
|
|
701
|
+
* match, 1 for a match only where a needle ending in a digit runs on into a
|
|
702
|
+
* letter, undefined for none. Rank 0 is falsy, so a caller tests for undefined.
|
|
703
|
+
*
|
|
704
|
+
* A needle ending in a number never continues into a longer one. A trailing
|
|
705
|
+
* digit never runs on into another digit — `item 1` matches `Item 1.` and `Item
|
|
706
|
+
* 1A`, never `Item 12`. Plain-text outlines keep their TOC rows (they are worded
|
|
707
|
+
* differently from the body heading, so dedup leaves them), and a TOC row for
|
|
708
|
+
* Item 10–16 precedes the body Item 1, so a bare substring test landed `item 1`
|
|
709
|
+
* on the wrong Item (#136). A trailing roman numeral (`part i`, a word of `i`,
|
|
710
|
+
* `v`, and `x`) ends at a space, punctuation, or the heading's end, so `part i`
|
|
711
|
+
* never matches `PART II`, `PART III`, or `PART IV` — a 10-Q printing Part I only
|
|
712
|
+
* in its table of contents otherwise landed `part i` on its body `PART II -
|
|
713
|
+
* OTHER INFORMATION`.
|
|
714
|
+
*
|
|
715
|
+
* A digit running on into a letter ranks 1, after every match where the number
|
|
716
|
+
* ends: `item 9` takes Item 9 ahead of Items 9A–9C, and `item 7` Item 7 ahead of
|
|
717
|
+
* Item 7A. Intel's 10-K (0000050863-26-000011) prints Item 9 only on a
|
|
718
|
+
* cross-reference index row, and `item 9` landed on its Item 9C row (#257).
|
|
719
|
+
*
|
|
720
|
+
* Every occurrence is checked and the best kept, not just the first ("ITEM 1A
|
|
721
|
+
* AND ITEM 1" ranks 0 for `item 1`). Both operands arrive folded with a run-in
|
|
722
|
+
* marker spaced ({@link foldForSectionMatch}), so the numeral of "Part
|
|
723
|
+
* IFinancial Information" ends where heading detection ends it (#180).
|
|
661
724
|
*/
|
|
662
|
-
function
|
|
663
|
-
const
|
|
664
|
-
?
|
|
725
|
+
function sectionMatchRank(heading, needle) {
|
|
726
|
+
const end = /\d$/.test(needle)
|
|
727
|
+
? 'digit'
|
|
665
728
|
: /(?:^|\s)[ivx]{1,4}$/.test(needle)
|
|
666
|
-
?
|
|
729
|
+
? 'roman'
|
|
667
730
|
: undefined;
|
|
668
731
|
const at = heading.indexOf(needle);
|
|
669
732
|
if (at === -1)
|
|
670
|
-
return
|
|
671
|
-
if (
|
|
672
|
-
return
|
|
673
|
-
|
|
674
|
-
return
|
|
733
|
+
return;
|
|
734
|
+
if (end === undefined)
|
|
735
|
+
return 0;
|
|
736
|
+
const first = occurrenceRank(heading.charAt(at + needle.length), end);
|
|
737
|
+
return first === 0 ? 0 : bestOccurrenceRank(heading, needle, at + 1, end, first);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* The rank of one occurrence of a needle ending in `end`, from the character
|
|
741
|
+
* after it (`next`, empty at the heading's end): 0 where no letter or digit
|
|
742
|
+
* follows, 1 where a digit runs on into a letter, else undefined.
|
|
743
|
+
*/
|
|
744
|
+
function occurrenceRank(next, end) {
|
|
745
|
+
if (!/[\p{L}\p{N}]/u.test(next))
|
|
746
|
+
return 0;
|
|
747
|
+
return end === 'digit' && !/\d/.test(next) ? 1 : undefined;
|
|
675
748
|
}
|
|
676
749
|
/**
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
* Reached only after a first occurrence that runs on.
|
|
750
|
+
* The best rank of `needle` in `heading` over `best` and every occurrence at or
|
|
751
|
+
* after `from`, in one Knuth–Morris–Pratt pass that stops at the first rank-0
|
|
752
|
+
* occurrence. Reached only after a first occurrence that runs on.
|
|
680
753
|
*/
|
|
681
|
-
function
|
|
754
|
+
function bestOccurrenceRank(heading, needle, from, end, best) {
|
|
682
755
|
const fallback = new Int32Array(needle.length);
|
|
683
756
|
for (let i = 1, k = 0; i < needle.length; i++) {
|
|
684
757
|
while (k > 0 && needle[i] !== needle[k])
|
|
@@ -687,18 +760,32 @@ function occursBeforeBoundary(heading, needle, from, continuation) {
|
|
|
687
760
|
k++;
|
|
688
761
|
fallback[i] = k;
|
|
689
762
|
}
|
|
763
|
+
let rank = best;
|
|
690
764
|
for (let i = from, k = 0; i < heading.length; i++) {
|
|
691
765
|
while (k > 0 && heading[i] !== needle[k])
|
|
692
766
|
k = fallback[k - 1] ?? 0;
|
|
693
767
|
if (heading[i] === needle[k])
|
|
694
768
|
k++;
|
|
695
769
|
if (k === needle.length) {
|
|
696
|
-
|
|
697
|
-
|
|
770
|
+
const found = occurrenceRank(heading.charAt(i + 1), end);
|
|
771
|
+
if (found === 0)
|
|
772
|
+
return 0;
|
|
773
|
+
rank ??= found;
|
|
698
774
|
k = fallback[k - 1] ?? 0;
|
|
699
775
|
}
|
|
700
776
|
}
|
|
701
|
-
return
|
|
777
|
+
return rank;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Whether an Item or Part heading's title — the text after its marker — opens on
|
|
781
|
+
* the keyed value `key`, which ends where no letter or digit follows: "Item 15.
|
|
782
|
+
* Exhibits and Financial Statement Schedules" opens on `exhibits`; "Item 16. Form
|
|
783
|
+
* 10-K Summary" does not open on `summary`, and no title opens on a marker value
|
|
784
|
+
* (`item 6`).
|
|
785
|
+
*/
|
|
786
|
+
function titleOpensOn(heading, key) {
|
|
787
|
+
const title = MARKER_TITLE_RE.exec(headingKey(heading.heading))?.[2];
|
|
788
|
+
return title?.startsWith(key) === true && !/[\p{L}\p{N}]/u.test(title.charAt(key.length));
|
|
702
789
|
}
|
|
703
790
|
/**
|
|
704
791
|
* Where `section` lands, over every detected heading (#169) and the document's
|
|
@@ -711,18 +798,26 @@ function occursBeforeBoundary(heading, needle, from, continuation) {
|
|
|
711
798
|
* II") has no title and is never a candidate here. This tier keeps "risk
|
|
712
799
|
* factors" on "Item 1A. Risk Factors." when an earlier all-caps heading
|
|
713
800
|
* merely contains the words.
|
|
714
|
-
* 2. The first Item or Part heading that
|
|
715
|
-
* an Item title names that Item
|
|
716
|
-
* Compensation"), where a line equal to
|
|
801
|
+
* 2. The first Item or Part heading that contains the value
|
|
802
|
+
* ({@link sectionMatchRank}): a value inside an Item title names that Item
|
|
803
|
+
* ("compensation" → "Item 11. Executive Compensation"), where a line equal to
|
|
804
|
+
* it is often a table-row label. A TOC row here whose title opens on the
|
|
805
|
+
* value ({@link titleOpensOn}) points at a section printed under a line, so
|
|
806
|
+
* it gives way to tiers 3–5 and lands only when no line matches the value
|
|
807
|
+
* (#257): Intel's 10-K (0000050863-26-000011) prints its Items only on a
|
|
808
|
+
* cross-reference index, and its "Item 15. Exhibits and Financial Statement
|
|
809
|
+
* Schedules" row took `exhibits` from the body's "Exhibits" line. A marker
|
|
810
|
+
* value (`item 6`) opens no title, so a TOC row still takes it (#174).
|
|
717
811
|
* 3. A document line equal to the value ({@link matchSectionLine}) that labels
|
|
718
812
|
* no table row.
|
|
719
|
-
* 4. The first other heading that
|
|
720
|
-
*
|
|
721
|
-
*
|
|
813
|
+
* 4. The first other heading that contains the value. One that merely holds the
|
|
814
|
+
* word ("NOTE 3. BUSINESS COMBINATIONS" for "business", "COST OF REVENUES"
|
|
815
|
+
* for "revenue") ranks after a line printing the value alone.
|
|
722
816
|
* 5. A document line equal to the value that labels a table row, else one
|
|
723
|
-
* starting with the value
|
|
724
|
-
*
|
|
725
|
-
*
|
|
817
|
+
* starting with the value, else a table's column-header row whose first cell
|
|
818
|
+
* equals it (#257). A row label ranks after every heading containing the
|
|
819
|
+
* value (#184): every line equal to `revenue` in Microsoft's 2004 10-K labels
|
|
820
|
+
* a row, and in tier 3 one took the value from its MD&A heading.
|
|
726
821
|
*
|
|
727
822
|
* Inside each heading tier, a heading on a table-of-contents row
|
|
728
823
|
* ({@link isTocHeading}) ranks after every body heading of the tier, and lands
|
|
@@ -734,9 +829,12 @@ function occursBeforeBoundary(heading, needle, from, continuation) {
|
|
|
734
829
|
* line. They are not pushed behind the line tiers: a body heading over a page
|
|
735
830
|
* number reads as a TOC row too, and behind the line tiers CCC's `item 6` left
|
|
736
831
|
* its body "Item 6. Reserved." for a bare TOC marker line. The line tiers skip
|
|
737
|
-
* TOC rows already.
|
|
832
|
+
* TOC rows already. In tiers 2 and 4 the match rank goes first: a value's number
|
|
833
|
+
* ending (`item 9` in "Item 9.") ahead of one running on into a letter ("Item
|
|
834
|
+
* 9A"), so the order is exact body, exact TOC, letter body, letter TOC.
|
|
738
835
|
*
|
|
739
|
-
* The line tiers share one pass over the text, run only when tiers 1 and 2 miss
|
|
836
|
+
* The line tiers share one pass over the text, run only when tiers 1 and 2 miss
|
|
837
|
+
* or tier 2's match is a TOC row that gives way.
|
|
740
838
|
*
|
|
741
839
|
* A proxy statement (`proxy`) keeps tier 1, then every heading containing the
|
|
742
840
|
* value, then the line tiers: its ITEM headings are ballot proposals, not the
|
|
@@ -747,25 +845,25 @@ function occursBeforeBoundary(heading, needle, from, continuation) {
|
|
|
747
845
|
*/
|
|
748
846
|
function resolveSection(text, headings, section, proxy) {
|
|
749
847
|
/**
|
|
750
|
-
* The earliest heading
|
|
751
|
-
* no match),
|
|
848
|
+
* The earliest heading in the lowest slot: `rank` gives each heading's match
|
|
849
|
+
* rank (0, then 1; undefined is no match), and `slot` places a match by its
|
|
850
|
+
* rank and whether it sits on a TOC row — read for matches only.
|
|
752
851
|
*/
|
|
753
|
-
const best = (rank) => {
|
|
852
|
+
const best = (rank, slot) => {
|
|
754
853
|
const earliest = [];
|
|
755
854
|
for (const h of headings) {
|
|
756
855
|
const r = rank(h);
|
|
757
856
|
if (r === undefined)
|
|
758
857
|
continue;
|
|
759
|
-
const
|
|
760
|
-
if (
|
|
858
|
+
const s = slot(r, isTocHeading(text, h) ? 1 : 0);
|
|
859
|
+
if (s === 0)
|
|
761
860
|
return h;
|
|
762
|
-
earliest[
|
|
861
|
+
earliest[s] ??= h;
|
|
763
862
|
}
|
|
764
863
|
return earliest.find((h) => h !== undefined);
|
|
765
864
|
};
|
|
766
|
-
/** The first heading `matches` accepts, a body heading ahead of every TOC row. */
|
|
767
|
-
const first = (matches) => best((h) => (matches(h) ? 0 : undefined));
|
|
768
865
|
const exactNeedle = headingKey(section);
|
|
866
|
+
// Tier 1: every body heading ahead of every TOC row, then the equal ahead of the labelled.
|
|
769
867
|
const exact = best((h) => {
|
|
770
868
|
const key = headingKey(h.heading);
|
|
771
869
|
const title = MARKER_TITLE_RE.exec(key)?.[2];
|
|
@@ -775,7 +873,7 @@ function resolveSection(text, headings, section, proxy) {
|
|
|
775
873
|
return 0;
|
|
776
874
|
const labelled = [key, title].some((k) => k !== undefined && withoutSubItemLabel(k) === exactNeedle);
|
|
777
875
|
return labelled ? 1 : undefined;
|
|
778
|
-
});
|
|
876
|
+
}, (r, toc) => r + 2 * toc);
|
|
779
877
|
const onHeading = (heading) => ({
|
|
780
878
|
heading,
|
|
781
879
|
offset: heading.offset,
|
|
@@ -784,26 +882,32 @@ function resolveSection(text, headings, section, proxy) {
|
|
|
784
882
|
if (exact)
|
|
785
883
|
return onHeading(exact);
|
|
786
884
|
const needle = foldForSectionMatch(section);
|
|
787
|
-
|
|
885
|
+
/** The first heading `keep` accepts that contains the value, ranked as tiers 2 and 4 rank. */
|
|
886
|
+
const firstContaining = (keep) => best((h) => (keep(h) ? sectionMatchRank(foldForSectionMatch(h.heading), needle) : undefined), (r, toc) => 2 * r + toc);
|
|
788
887
|
if (proxy) {
|
|
789
|
-
const heading =
|
|
888
|
+
const heading = firstContaining(() => true);
|
|
790
889
|
if (heading)
|
|
791
890
|
return onHeading(heading);
|
|
792
891
|
const line = matchSectionLine(text, section);
|
|
793
892
|
return line ? { offset: line.offset, source: 'line' } : undefined;
|
|
794
893
|
}
|
|
795
|
-
const itemOrPart =
|
|
796
|
-
|
|
894
|
+
const itemOrPart = firstContaining(isStructuralHeading);
|
|
895
|
+
const pointer = itemOrPart !== undefined &&
|
|
896
|
+
titleOpensOn(itemOrPart, exactNeedle) &&
|
|
897
|
+
isTocHeading(text, itemOrPart);
|
|
898
|
+
if (itemOrPart && !pointer)
|
|
797
899
|
return onHeading(itemOrPart);
|
|
798
900
|
const line = matchSectionLine(text, section);
|
|
799
|
-
|
|
800
|
-
|
|
901
|
+
if (itemOrPart && !line)
|
|
902
|
+
return onHeading(itemOrPart);
|
|
903
|
+
const other = firstContaining((h) => !isStructuralHeading(h));
|
|
904
|
+
const lineSource = itemOrPart ? 'line-over-toc' : 'line';
|
|
801
905
|
if (line?.equal)
|
|
802
|
-
return { offset: line.offset, source: other ? 'line-over-heading' :
|
|
906
|
+
return { offset: line.offset, source: other ? 'line-over-heading' : lineSource };
|
|
803
907
|
if (other)
|
|
804
908
|
return onHeading(other);
|
|
805
909
|
if (line)
|
|
806
|
-
return { offset: line.offset, source:
|
|
910
|
+
return { offset: line.offset, source: lineSource };
|
|
807
911
|
return;
|
|
808
912
|
}
|
|
809
913
|
/** Whether the character at `at` is whitespace as `\s` reads it; false past either end. */
|
|
@@ -1000,17 +1104,18 @@ function normalizeAccessionNumber(input) {
|
|
|
1000
1104
|
return `${input.slice(0, 10)}-${input.slice(10, 12)}-${input.slice(12)}`;
|
|
1001
1105
|
}
|
|
1002
1106
|
/**
|
|
1003
|
-
* At most this many
|
|
1004
|
-
*
|
|
1005
|
-
*
|
|
1107
|
+
* At most this many filers are tried past the candidate CIKs: the parties the
|
|
1108
|
+
* filing's index page names (#203), or, with `cik`, the filers full-text search
|
|
1109
|
+
* records (#256). A filing lives under every party's directory, so the first
|
|
1110
|
+
* untried one almost always serves it; a group filing can name dozens.
|
|
1006
1111
|
*/
|
|
1007
|
-
const
|
|
1112
|
+
const FALLBACK_FILER_CAP = 3;
|
|
1008
1113
|
/**
|
|
1009
1114
|
* Resolve filing archive: fetch index + primary document HTML.
|
|
1010
1115
|
* Used on cache misses to get both the document content and index metadata.
|
|
1011
1116
|
*
|
|
1012
1117
|
* When no candidate directory serves the filing, the filing's index page names its
|
|
1013
|
-
* parties, and up to {@link
|
|
1118
|
+
* parties, and up to {@link FALLBACK_FILER_CAP} of them not yet tried are
|
|
1014
1119
|
* searched the same way (#203). A pre-2001 accession filed through an agent needs
|
|
1015
1120
|
* it: full-text search has no record before 2001, and the agent's directory, the
|
|
1016
1121
|
* only other candidate, holds no copy the archive serves. The page costs one
|
|
@@ -1018,10 +1123,21 @@ const INDEX_PAGE_PARTY_CAP = 3;
|
|
|
1018
1123
|
* listing named the target but the archive did not serve it, or no directory
|
|
1019
1124
|
* answered at all — a document no listing names is missing from every party's
|
|
1020
1125
|
* directory alike.
|
|
1126
|
+
*
|
|
1127
|
+
* SEC's archive also answers 404 for an existing filing's listing at times, and
|
|
1128
|
+
* caches that answer for minutes, longer than the call's failure budget, so a
|
|
1129
|
+
* filing no directory serves is told apart from one that does not exist by what
|
|
1130
|
+
* shows EDGAR holds it (#256): the full-text search hit already in hand, or the
|
|
1131
|
+
* index page answering.
|
|
1132
|
+
* With `cik`, which skips the search, one full-text search is sent when neither the
|
|
1133
|
+
* directories nor the page answered, and the filers it names are tried like the
|
|
1134
|
+
* page's parties. A filing shown to exist fails `filing_not_served`; the success
|
|
1135
|
+
* path sends no request for any of this.
|
|
1021
1136
|
*/
|
|
1022
1137
|
async function resolveFilingArchive(api, scope, accessionNumber, providedCik, requestedDocument) {
|
|
1023
1138
|
const candidates = await resolveCandidateCiks(api, scope, accessionNumber, providedCik);
|
|
1024
1139
|
let filerLookupFailed = candidates.filerLookupFailed;
|
|
1140
|
+
let evidence = candidates.listed ? 'full_text_search' : undefined;
|
|
1025
1141
|
const search = {
|
|
1026
1142
|
tried: new Set(),
|
|
1027
1143
|
requestedNotServed: false,
|
|
@@ -1033,9 +1149,18 @@ async function resolveFilingArchive(api, scope, accessionNumber, providedCik, re
|
|
|
1033
1149
|
if (!search.lastIndexed?.items.length || search.requestedNotServed || search.primaryNotServed) {
|
|
1034
1150
|
const parties = await readFilingParties(api, scope, accessionNumber);
|
|
1035
1151
|
filerLookupFailed ||= parties === undefined;
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1152
|
+
// The page answering at all shows the filing exists, whatever parties it names.
|
|
1153
|
+
if (parties)
|
|
1154
|
+
evidence ??= 'index_page';
|
|
1155
|
+
let others = parties ?? [];
|
|
1156
|
+
if (providedCik && !parties && !search.lastIndexed) {
|
|
1157
|
+
const listed = await lookUpFilingCiks(api, scope, accessionNumber);
|
|
1158
|
+
filerLookupFailed ||= listed === undefined;
|
|
1159
|
+
if (listed?.length)
|
|
1160
|
+
evidence ??= 'full_text_search';
|
|
1161
|
+
others = listed ?? [];
|
|
1162
|
+
}
|
|
1163
|
+
const untried = others.filter((cik) => !search.tried.has(cik)).slice(0, FALLBACK_FILER_CAP);
|
|
1039
1164
|
if (untried.length > 0) {
|
|
1040
1165
|
const refound = await searchArchive(api, scope, accessionNumber, untried, requestedDocument, search);
|
|
1041
1166
|
if (refound)
|
|
@@ -1044,6 +1169,16 @@ async function resolveFilingArchive(api, scope, accessionNumber, providedCik, re
|
|
|
1044
1169
|
}
|
|
1045
1170
|
const { lastIndexed } = search;
|
|
1046
1171
|
if (!lastIndexed?.items.length) {
|
|
1172
|
+
// Every directory tried answered 404 for the listing, while a source shows the filing.
|
|
1173
|
+
if (evidence && !lastIndexed) {
|
|
1174
|
+
return {
|
|
1175
|
+
ok: false,
|
|
1176
|
+
kind: 'filing_not_served',
|
|
1177
|
+
ciksTried: [...search.tried],
|
|
1178
|
+
evidence,
|
|
1179
|
+
filerLookupFailed,
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1047
1182
|
return { ok: false, kind: 'filing_not_found', providedCik, filerLookupFailed };
|
|
1048
1183
|
}
|
|
1049
1184
|
// Categorize as the success path does: the same primary, the header page's types.
|
|
@@ -1197,23 +1332,166 @@ async function readFilingRecords(api, scope, cik, accessionNumber) {
|
|
|
1197
1332
|
]);
|
|
1198
1333
|
return { headers, submissions };
|
|
1199
1334
|
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Periodic reports whose amendment (`<form>/A`) carries the original's period of
|
|
1337
|
+
* report as its feed `reportDate` (#268): checked on GoPro's and Tesla's 10-K/A,
|
|
1338
|
+
* GoPro's 10-Q/A, KalVista's 10-KT/A, Shorepower's 10-QT/A, Cosan's 20-F/A, and
|
|
1339
|
+
* Americas Gold & Silver's two 40-F/As. Their Exchange Act file number is shared
|
|
1340
|
+
* by every 10-K, 10-Q, and 8-K, so it identifies nothing.
|
|
1341
|
+
*/
|
|
1342
|
+
const PERIODIC_FORMS = new Set(['10-K', '10-KT', '10-Q', '10-QT', '20-F', '40-F']);
|
|
1343
|
+
/**
|
|
1344
|
+
* Securities Act registration statements whose amendments (`<form>/A`) and
|
|
1345
|
+
* withdrawal (`RW`) carry their `333-` file number (#268). Other rows under that
|
|
1346
|
+
* number — EFFECT, 424B prospectuses, POS AM — are not amendments of it. An N-2/A
|
|
1347
|
+
* as often carries only an `811-` number, so N-2 is left out.
|
|
1348
|
+
*/
|
|
1349
|
+
const REGISTRATION_FORMS = new Set([
|
|
1350
|
+
'S-1',
|
|
1351
|
+
'S-3',
|
|
1352
|
+
'S-4',
|
|
1353
|
+
'S-11',
|
|
1354
|
+
'F-1',
|
|
1355
|
+
'F-3',
|
|
1356
|
+
'F-4',
|
|
1357
|
+
'F-6',
|
|
1358
|
+
'F-10',
|
|
1359
|
+
'SF-1',
|
|
1360
|
+
'SF-3',
|
|
1361
|
+
]);
|
|
1362
|
+
/**
|
|
1363
|
+
* The filings in `recent` after the filing at row `idx` that amend or withdraw
|
|
1364
|
+
* it, oldest first; undefined for a form the check does not cover. At -1 the
|
|
1365
|
+
* window omits the filing, whose `form`, `period`, and `filingDate` then come
|
|
1366
|
+
* from its own header. Unchecked when the match key is not in reach: a periodic
|
|
1367
|
+
* report with no period of report, or a registration statement with no `333-`
|
|
1368
|
+
* file number — always so outside the window, since only its own feed row
|
|
1369
|
+
* carries that number. An amendment is read by its base form, so a later
|
|
1370
|
+
* amendment of an amendment is named. `recent` lists filings newest first —
|
|
1371
|
+
* filing date descending, then acceptance time within a day, across ten feeds
|
|
1372
|
+
* sampled — so the rows above a listed filing's are those filed after it. Reads
|
|
1373
|
+
* only arrays in hand.
|
|
1374
|
+
*/
|
|
1375
|
+
function checkLaterFilings(recent, idx, form, period, filingDate) {
|
|
1376
|
+
const base = form?.replace(/\/A$/, '');
|
|
1377
|
+
if (!base)
|
|
1378
|
+
return;
|
|
1379
|
+
const periodic = PERIODIC_FORMS.has(base);
|
|
1380
|
+
if (!periodic && !REGISTRATION_FORMS.has(base))
|
|
1381
|
+
return;
|
|
1382
|
+
const keys = periodic ? recent.reportDate : (recent.fileNumber ?? []);
|
|
1383
|
+
const key = periodic ? period : idx >= 0 ? keys[idx] : undefined;
|
|
1384
|
+
if (!key || (!periodic && !key.startsWith('333-'))) {
|
|
1385
|
+
return { kind: 'unchecked', missing: periodic ? 'period' : 'file_number' };
|
|
1386
|
+
}
|
|
1387
|
+
let reach = { from: 'row' };
|
|
1388
|
+
if (idx < 0) {
|
|
1389
|
+
if (!filingDate)
|
|
1390
|
+
return { kind: 'unchecked', missing: 'filing_date' };
|
|
1391
|
+
const first = recent.filingDate.at(-1);
|
|
1392
|
+
reach =
|
|
1393
|
+
first !== undefined && filingDate < first
|
|
1394
|
+
? { from: 'window', date: first }
|
|
1395
|
+
: { from: 'date', date: filingDate, past: recent.filingDate.some((d) => d > filingDate) };
|
|
1396
|
+
}
|
|
1397
|
+
const amendment = `${base}/A`;
|
|
1398
|
+
const filings = [];
|
|
1399
|
+
const sameDay = [];
|
|
1400
|
+
for (let i = (idx >= 0 ? idx : recent.accessionNumber.length) - 1; i >= 0; i--) {
|
|
1401
|
+
const rowForm = recent.form[i];
|
|
1402
|
+
const accession = recent.accessionNumber[i];
|
|
1403
|
+
const rowDate = recent.filingDate[i];
|
|
1404
|
+
if (keys[i] !== key || accession === undefined || rowDate === undefined)
|
|
1405
|
+
continue;
|
|
1406
|
+
if (rowForm !== amendment && (periodic || rowForm !== 'RW'))
|
|
1407
|
+
continue;
|
|
1408
|
+
const row = { accession_number: accession, form: rowForm, filing_date: rowDate };
|
|
1409
|
+
if (reach.from !== 'date' || rowDate > reach.date)
|
|
1410
|
+
filings.push(row);
|
|
1411
|
+
else if (rowDate === reach.date)
|
|
1412
|
+
sameDay.push(row);
|
|
1413
|
+
}
|
|
1414
|
+
return { kind: 'checked', filings, sameDay, reach };
|
|
1415
|
+
}
|
|
1416
|
+
/**
|
|
1417
|
+
* The notice naming the later filings and saying what was not looked for:
|
|
1418
|
+
* nothing when the check could not run, everything filed before the window for a
|
|
1419
|
+
* filing older than it, every later filing for one dated after every row; and
|
|
1420
|
+
* naming an omitted filing's same-day amendments as of unknown order. Undefined
|
|
1421
|
+
* only when the window holds every filing after this one and none amends it.
|
|
1422
|
+
*/
|
|
1423
|
+
function laterFilingsNotice(check) {
|
|
1424
|
+
if (check.kind === 'unchecked') {
|
|
1425
|
+
switch (check.missing) {
|
|
1426
|
+
case 'period':
|
|
1427
|
+
return 'Amendments of it were not looked for, since its period of report could not be read.';
|
|
1428
|
+
case 'file_number':
|
|
1429
|
+
return 'Amendments and withdrawals of it were not looked for, since its 333- file number could not be read.';
|
|
1430
|
+
case 'filing_date':
|
|
1431
|
+
return 'Amendments of it were not looked for, since its filing date could not be read.';
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
const { filings, sameDay, reach } = check;
|
|
1435
|
+
const sentences = [];
|
|
1436
|
+
if (filings.length > 0) {
|
|
1437
|
+
sentences.push(`Later filings amend or withdraw this one: ${filings
|
|
1438
|
+
.map((f) => `${f.form} ${f.accession_number} (filed ${f.filing_date})`)
|
|
1439
|
+
.join(', ')}. Read one by passing its accession_number to secedgar_get_filing.`);
|
|
1440
|
+
}
|
|
1441
|
+
else if (reach.from === 'window') {
|
|
1442
|
+
sentences.push(`No amendment of it was filed from ${reach.date} on.`);
|
|
1443
|
+
}
|
|
1444
|
+
else if (reach.from === 'date') {
|
|
1445
|
+
sentences.push(reach.past
|
|
1446
|
+
? `No amendment of it was filed after ${reach.date}.`
|
|
1447
|
+
: `The filer's submissions feed lists neither this filing nor any filed after ${reach.date}, so later amendments of it were not looked for.`);
|
|
1448
|
+
}
|
|
1449
|
+
if (reach.from === 'window') {
|
|
1450
|
+
sentences.push(`Amendments filed before ${reach.date} were not looked for.`);
|
|
1451
|
+
}
|
|
1452
|
+
if (sameDay.length > 0 && reach.from === 'date') {
|
|
1453
|
+
sentences.push(`${sameDay.map((f) => `${f.form} ${f.accession_number}`).join(', ')} ${sameDay.length === 1 ? 'was' : 'were'} filed the same day (${reach.date}); the feed does not show whether before or after this one.`);
|
|
1454
|
+
}
|
|
1455
|
+
return sentences.length > 0 ? sentences.join(' ') : undefined;
|
|
1456
|
+
}
|
|
1200
1457
|
/**
|
|
1201
1458
|
* The CIKs whose archive directories are searched first, in order: the caller's
|
|
1202
1459
|
* `cik` alone, or the filers EDGAR full-text search records for the accession, then
|
|
1203
1460
|
* the CIK the accession number opens with — the filer's own, or a filing agent's.
|
|
1204
1461
|
* When SEC cannot answer the search (#215), the prefix alone is searched and
|
|
1205
1462
|
* `filerLookupFailed` says so; the caller's cancellation and a rate-limit refusal
|
|
1206
|
-
* still end the call.
|
|
1463
|
+
* still end the call. `listed` says the search found the accession, which shows
|
|
1464
|
+
* EDGAR holds the filing (#256).
|
|
1207
1465
|
*/
|
|
1208
1466
|
async function resolveCandidateCiks(api, scope, accessionNumber, providedCik) {
|
|
1209
|
-
if (providedCik)
|
|
1210
|
-
return { ciks: [providedCik.padStart(10, '0')], filerLookupFailed: false };
|
|
1211
|
-
|
|
1467
|
+
if (providedCik) {
|
|
1468
|
+
return { ciks: [providedCik.padStart(10, '0')], filerLookupFailed: false, listed: false };
|
|
1469
|
+
}
|
|
1470
|
+
const searched = await lookUpFilingCiks(api, scope, accessionNumber);
|
|
1212
1471
|
return {
|
|
1213
1472
|
ciks: [...new Set([...(searched ?? []), accessionPrefixCik(accessionNumber)])],
|
|
1214
1473
|
filerLookupFailed: searched === undefined,
|
|
1474
|
+
listed: Boolean(searched?.length),
|
|
1215
1475
|
};
|
|
1216
1476
|
}
|
|
1477
|
+
/**
|
|
1478
|
+
* The filers EDGAR full-text search records for the accession, in SEC's order, or
|
|
1479
|
+
* `undefined` when SEC could not answer the search: unavailable as
|
|
1480
|
+
* {@link unlessSecUnavailable} reads it, or the search endpoint answering 404, which
|
|
1481
|
+
* it never does for a search it ran — one matching nothing answers 200 (#256).
|
|
1482
|
+
*/
|
|
1483
|
+
function lookUpFilingCiks(api, scope, accessionNumber) {
|
|
1484
|
+
return unlessSecUnavailable(scope, async () => {
|
|
1485
|
+
try {
|
|
1486
|
+
return await api.findFilingCiks(accessionNumber, scope);
|
|
1487
|
+
}
|
|
1488
|
+
catch (error) {
|
|
1489
|
+
if (error instanceof McpError && error.code === JsonRpcErrorCode.NotFound)
|
|
1490
|
+
return;
|
|
1491
|
+
throw error;
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1217
1495
|
/**
|
|
1218
1496
|
* The parties the filing's index page names, read under the accession number's
|
|
1219
1497
|
* own prefix CIK: SEC serves the page there for any filing that exists, a filing
|