返回 last30days-skill
json-export.md
根目录 / docs / reference / json-export.md
1 # Agent JSON export
2
3 The agent JSON profile is the stable machine-readable research contract for downstream agents, scripts, dashboards, and workflow tools. Ask the slash command for machine-readable JSON:
4
5 ```text
6 /last30days AI coding agents — return the versioned agent JSON export
7 ```
8
9 For direct engine use in scripts, cron jobs, or development, use:
10
11 ```bash
12 python3 skills/last30days/scripts/last30days.py "AI coding agents" --emit=json
13 python3 skills/last30days/scripts/last30days.py "AI coding agents" --emit=json --output results.json
14 ```
15
16 `--emit=json` defaults to `--json-profile=agent`. The full internal report remains available for debugging and power users:
17
18 ```bash
19 python3 skills/last30days/scripts/last30days.py "AI coding agents" --emit=json --json-profile=raw
20 ```
21
22 The raw profile is intentionally unversioned and may change when pipeline internals change. It preserves the JSON serialization used before the agent profile was introduced.
23
24 ### Local corpus privacy
25
26 Evidence from `--corpus` / `LAST30DAYS_CORPUS_DIRS` is excluded from the versioned agent profile by default. The exclusion removes corpus results, corpus-only clusters, corpus source outcomes, freshness verdicts, and titles derived from a corpus representative. Set `LAST30DAYS_CORPUS_IN_EXPORT=1` only for a run whose JSON is intentionally allowed to contain local file contents. This opt-in does not change the schema shape or version; it permits `source: "corpus"` entries in the existing result fields. The unversioned `raw` profile is a complete local debug dump and may contain corpus paths and text.
27
28 ## Discovery export
29
30 Discovery mode has a separate versioned contract so its topic results do not change the normal research export:
31
32 ```bash
33 python3 skills/last30days/scripts/last30days.py --discover "AI agents" --emit=json
34 ```
35
36 Its top level contains `schema_version` (`1.1`), `kind` (`"discovery"`), `domain` (`""` for a global no-domain trending run), `generated_at`, `window_days`, `source_status`, `feeds`, `results`, `warnings`, `outcome` (`"ok"`, or `"nothing-solid"` when no topic cleared the confidence floor), and `weak_signal` (the closest sub-floor topic name on a nothing-solid run, else `null`). Each ranked result contains `rank`, `topic`, `why_spiking`, `momentum` (`new-this-week` or `building`), `velocity_score`, `sources`, per-source native `engagement`, a ready-to-run `command`, `evidence_urls`, `top_comment` (the strongest verbatim community comment from the topic's research pass, with attribution; `null` on shallow runs), `corroboration_count` (distinct confirming sources), `podcast_angle` (engine-generated podcast content hook; `null` when no reasoning provider produced one), `x_article_angle` (engine-generated X-article content hook; `null` when no reasoning provider produced one), `previously_surfaced_count` (topic-queue annotation: how many earlier sweeps surfaced this topic; `0` when the queue is off), `last_surfaced` (topic-queue annotation: date the topic last surfaced; `null` when the queue is off), and `covered` (topic-queue annotation: whether the topic was already covered; `false` when the queue is off). The discovery contract follows the same versioning policy below but evolves independently of the normal agent export. `--json-profile=raw` returns the unversioned internal `DiscoveryReport` dataclass instead.
37
38 When `LAST30DAYS_API_KEY` and `LAST30DAYS_API_BASE` route a run through a configured remote API, the server does not return the local `Report` needed to build this profile. In that mode, `--json-profile=agent` exits with status 2 instead of emitting a misleading shape; use `--json-profile=raw` to retain the remote backend's existing server-response JSON contract.
39
40 ## Top-level fields
41
42 | Field | Type | Meaning |
43 | --- | --- | --- |
44 | `schema_version` | string | Agent export contract version. The current version is `1.4`. |
45 | `query` | string | The research topic supplied to the engine. |
46 | `generated_at` | string | UTC generation timestamp in RFC 3339 format. |
47 | `window_days` | integer | Number of days between the report's start and end dates. |
48 | `source_status` | object | Map of source name to the outcome observed during this run. |
49 | `freshness_verdicts` | array | Per-claim act-time verdicts produced by `--verify-freshness`; empty when verification was not requested or no conservative claims were extractable. |
50 | `clusters` | array | Ranked groups of related results. |
51 | `results` | array | Ranked, flat evidence results for downstream processing. |
52 | `usage` | object or null | Provider-reported token usage for planner and rerank calls across the run. Added in `1.4`; see below. |
53
54 All top-level fields are always present. Empty runs contain empty `clusters` and `results` arrays. Sources appear in `source_status` when the run recorded an outcome for them.
55
56 ## `usage`
57
58 When every reasoning request reports valid token counts, `usage` contains four non-negative integer fields:
59
60 | Field | Meaning |
61 | --- | --- |
62 | `calls` | Number of successful provider responses included in the total. |
63 | `promptTokens` | Sum of reported input tokens. |
64 | `completionTokens` | Sum of output tokens, including reported reasoning tokens when a provider's total exceeds input plus visible output. |
65 | `totalTokens` | Sum of `promptTokens` and `completionTokens`. |
66
67 `usage` is `null` when no reasoning provider was called, a response omits or invalidates token counts, or a request fails or retries after a transport attempt whose token cost is unknown. The engine does not publish a partial total as zero or as the full run total. These counts come from provider responses and do not represent a monetary charge.
68
69 ## `freshness_verdicts`
70
71 Each entry identifies the grounded claim and candidate, its primary source item, the typed `verdict` (`current`, `stale`, `contradicted`, or `unsupported`), the original and re-derived values when applicable, and source/evidence URLs and timestamps. `stale` means a successful point re-fetch returned a moved value; `contradicted` means a newer item in the report window explicitly disagrees; `unsupported` means the datum could not be re-checked, including degraded `source_status` outcomes. Consumers can gate actions on `verdict == "current"` without treating an unreachable source as evidence that a claim moved.
72
73 ## `source_status`
74
75 Each value distinguishes a clean empty result from incomplete coverage:
76
77 | State | Meaning |
78 | --- | --- |
79 | `ok` | The source completed and returned one or more items. |
80 | `no-results` | The source completed successfully but found no matching items. |
81 | `partial` | The source returned some items before a later failure. |
82 | `rate-limited` | Retrieval was stopped by a provider rate limit. |
83 | `auth-failed` | Credentials were missing, rejected, or expired during retrieval. |
84 | `payment-required` | The provider rejected the request because the account's credits are exhausted (HTTP 402 or an explicit credit-exhaustion message). Fix is to top up, not to re-authenticate. Added in `1.3`. |
85 | `unreachable` | The source or network endpoint could not be reached. |
86 | `timeout` | Retrieval exceeded its time limit. |
87 | `schema-drift` | The provider response no longer matched the expected shape. |
88 | `skipped-unconfigured` | The source was intentionally skipped because required configuration was absent. |
89 | `error` | Retrieval failed for another reason. |
90
91 Consumers must not interpret failure states as evidence that a source had no discussion. Only `no-results` means the source completed cleanly with zero matches.
92
93 ## Cluster fields
94
95 | Field | Type | Meaning |
96 | --- | --- | --- |
97 | `title` | string | Cluster headline. |
98 | `summary` | string | Summary from the cluster's representative ranked result. |
99 | `sources` | array of strings | Sources represented by the cluster. |
100 | `engagement_total` | number | Sum of one headline native engagement counter per result. Known sources use their primary count (for example, Digg uses `postCount`); otherwise the largest counter-like field is used. Ranking, ratio, rating, and computed-score metadata are excluded. |
101
102 Cluster array order is ranking order. A result's `cluster` value is the zero-based index into this array.
103
104 ## Result fields
105
106 | Field | Type | Meaning |
107 | --- | --- | --- |
108 | `candidate_id` | string | Stable identifier joining this result to `freshness_verdicts[].candidate_id`. Added in `1.2`. |
109 | `title` | string | Result title. |
110 | `source` | string | Primary source name, such as `reddit`, `x`, `youtube`, or `grounding`. |
111 | `url` | string | Canonical result URL. It may be empty when the provider supplies no link. |
112 | `published_at` | string | Primary source item's publication date or timestamp. Omitted when unknown. |
113 | `summary` | string | Normalized snippet, with the relevance explanation or body used as fallback. |
114 | `engagement` | object | Native engagement counters from the primary source item, such as Reddit `score` and `num_comments` or X `likes` and `reposts`. |
115 | `relevance_score` | number | Engine final score normalized to the inclusive `0.0`–`1.0` range. |
116 | `cluster` | integer | Zero-based index into `clusters`. Omitted when the result is not assigned to a cluster. |
117
118 Fields whose value is unknown are omitted rather than emitted as JSON `null`. Strings and collection fields otherwise remain present, including empty strings, objects, or arrays.
119
120 ## Comparison runs
121
122 Comparison queries use an envelope so each entity keeps its own contract:
123
124 ```json
125 {
126 "schema_version": "1.4",
127 "comparison": true,
128 "entities": ["OpenAI", "Anthropic"],
129 "reports": [
130 {"entity": "OpenAI", "report": {"schema_version": "1.4", "query": "OpenAI"}},
131 {"entity": "Anthropic", "report": {"schema_version": "1.4", "query": "Anthropic"}}
132 ]
133 }
134 ```
135
136 The abbreviated reports above only illustrate the envelope; real reports contain every documented top-level field.
137
138 ## Versioning policy
139
140 - `schema_version` uses `major.minor` numbering.
141 - Any breaking field removal, rename, type change, semantic change, or envelope change requires a major-version bump.
142 - Backward-compatible field additions may use a minor-version bump. Consumers should ignore fields they do not recognize.
143 - The checked-in golden snapshot test locks the complete current shape. Contract changes must update the version and snapshot deliberately.
144 - `1.4` added `usage` to the top level. It is `null` unless all reasoning requests have complete provider-reported token counts.
145 - `1.3` added the `payment-required` value to `source_status` for credit exhaustion (HTTP 402). Backward-compatible minor bump: consumers that switch on state names should treat it like `auth-failed` (a failure state, not evidence of silence) until they add a branch for it. Messages that previously classified as `auth-failed` or `error` because of a 402 or an "insufficient credits" body now carry this state on every source.
146 - `1.2` added `candidate_id` to each `results` entry so verdicts can be joined to the result they annotate.
147 - Discovery `1.1` added `podcast_angle`, `x_article_angle`, `previously_surfaced_count`, `last_surfaced`, and `covered` to each discovery `results` entry — a backward-compatible minor bump; the fields carry their defaults (`null`/`null`/`0`/`null`/`false`) until an angle generator or the topic queue populates them.
148 - `--json-profile=raw` is outside this compatibility policy because it mirrors internal pipeline dataclasses.
149
150 `--preflight --emit=json` is a different machine contract for permission and configuration inspection. `--json-profile` does not alter preflight output.
151
151 lines MARKDOWN