fairwire-dns-records 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (unreleased)
4
+
5
+ - First version (Fairwire ver 1).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kurt Francisco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,206 @@
1
- # Temporary Holding Version
1
+ # Fairwire DNS Records
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DNS zone hygiene from a zone export: names pointing at cloud services that may no longer exist (takeover risk), public names pointing at private addresses, duplicate and conflicting records, very short or very long TTLs, wildcards and records pointing at addresses you no longer own. Drafts a change request; never edits DNS.
4
+
5
+ Part of **Fairwire**, the IT and network family of [Mythos Machines](https://fair-agents.com) agents. The software is free (MIT); you pay a fixed price for the setup on your files. It reads files your IT team exports, on your own computer, and drafts notes. Every change to a live device, firewall, DNS zone, directory or cloud account stays one named person's click.
6
+
7
+ ## What it checks
8
+
9
+ | Finding | What it means |
10
+ |---|---|
11
+ | `dangling_cname` | A name pointing (CNAME) at a cloud service host name that may no longer exist: whoever creates that cloud resource next can serve content on your name (subdomain takeover). |
12
+ | `cname_conflict` | A name with a CNAME and other records at the same time, which DNS does not allow and resolvers handle unpredictably. |
13
+ | `private_ip_in_public_zone` | A public zone record pointing at a private address (it leaks your internal layout and never works from outside). |
14
+ | `ip_not_owned` | A record pointing at a public address outside the ranges you own (it may now belong to someone else). |
15
+ | `duplicate_record` | The same record listed twice. |
16
+ | `ttl_out_of_range` | A time-to-live shorter or longer than your limits. |
17
+ | `wildcard_record` | A wildcard record, which answers for every name under it, including typos and names an attacker chooses. |
18
+
19
+ Findings come back worst first (high, medium, low). A finding a named person has reviewed can be accepted as known, with a reason and a date to look again; it then moves to "Accepted as known" instead of counting as open.
20
+
21
+ ## Settings
22
+
23
+ Pass a settings file with `settings`. Every setting is optional; a misspelt setting is refused by name.
24
+
25
+ | Setting | What it does |
26
+ |---|---|
27
+ | `public_zones` | Zones published on the internet (default: every zone in the file) |
28
+ | `owned_cidrs` | Public address ranges you own or rent (no ownership check when empty) |
29
+ | `active_cloud_hosts` | Cloud host names that still exist in your accounts; a CNAME to a cloud host not on this list is high (medium when the list is empty) |
30
+ | `cloud_suffixes` | Extra cloud service host suffixes to treat as takeover-prone |
31
+ | `ttl_min` | Shortest acceptable TTL in seconds (default 60) |
32
+ | `ttl_max` | Longest acceptable TTL in seconds (default 604800, one week) |
33
+
34
+ ## What it never does
35
+
36
+ - `dns_update_record` is refused: Fairwire DNS Records never creates, changes or deletes a DNS record.
37
+ - `dns_live_lookup` is refused: Fairwire DNS Records never queries live DNS or cloud APIs; it reads the export you give it.
38
+ - `dns_records_request_submit` waits for one named person's click, even in Auto (`production_deploy`).
39
+ - `dns_records_accept_learning` waits for one named person's click, even in Auto (`accept_learning`).
40
+ - `dns_records_retire_memory` waits for one named person's click, even in Auto (`accept_learning`).
41
+ - `dns_update_record` waits for one named person's click, even in Auto (`production_deploy`).
42
+ - `dns_live_lookup` waits for one named person's click, even in Auto (`production_deploy`).
43
+
44
+ <!-- generated:start -->
45
+
46
+ ## A demo run
47
+
48
+ `npx -y fairwire-dns-records demo` runs the agent on the fictional files in [`fixtures/`](fixtures) in a temporary folder. Captured output:
49
+
50
+ ```text
51
+ Fairwire DNS Records demo (fictional data) in a temporary folder, Auto on for the draft only
52
+
53
+ ▶ Check the exported files
54
+ status: executed decision: allow
55
+ 14 record(s) for 12 name(s) in 2 zone(s), 5 CNAME(s): 8 open finding(s), 2 high.
56
+ high cname_conflict example.com
57
+ high dangling_cname example.com
58
+ medium ip_not_owned example.com
59
+ medium private_ip_in_public_zone example.com
60
+ low duplicate_record example.com
61
+ low ttl_out_of_range example.com
62
+ low ttl_out_of_range example.com
63
+ low wildcard_record example.com
64
+
65
+ ▶ Explain one finding
66
+ status: executed decision: allow
67
+ high cname_conflict: status.example.com has a CNAME and also TXT records. Fix: Keep either the CNAME or the other records, not both.
68
+ low ttl_out_of_range: CNAME record status.example.com has a TTL of 30 seconds. Fix: Raise it unless you are about to move the record; very short TTLs add load and cost.
69
+
70
+ ▶ Write the worklist
71
+ status: executed decision: allow
72
+ DNS zone hygiene written: 14 record(s) for 12 name(s) in 2 zone(s), 5 CNAME(s): 8 open finding(s), 2 high.
73
+
74
+ ▶ Draft the note for a person
75
+ status: executed decision: allow (auto)
76
+ change request 2026-11-18 drafted with 1 open marker(s) ([TO CONFIRM DNS and network change board]). Nothing was sent.
77
+
78
+ ▶ Auto: approving it still waits for one named person
79
+ status: needs_approval decision: ask
80
+ reason: production_deploy stays one-click, even in Auto
81
+
82
+ ▶ The agent tries to change the live system itself
83
+ status: blocked decision: block
84
+ reason: Fairwire DNS Records never creates, changes or deletes a DNS record.
85
+ ```
86
+
87
+ ## Tools
88
+
89
+ | Tool | What it does | Policy |
90
+ |---|---|---|
91
+ | `dns_records_check` | Review the zone export and list takeover-prone CNAMEs, CNAME conflicts, private or foreign addresses, duplicates, TTL problems and wildcards. | runs |
92
+ | `dns_records_explain` | Every finding for one record name or zone. | runs |
93
+ | `dns_records_write_report` | Write dns-records.csv (one row per finding, with blank owner and decision columns) and dns-records.html into out_dir (default fairwire-out/dns_records). | runs |
94
+ | `dns_records_draft_change_request` | Write drafts/change_request-<date>.md: the open findings at or above min_severity (default medium), each with what to do, addressed to DNS and network change board. | asks first (Auto can be opted in) |
95
+ | `dns_records_request_submit` | After one named human click (even in Auto), record that the reviewed change request draft is approved in change_request-requests.csv. | one named click, even in Auto (`production_deploy`) |
96
+ | `dns_records_recall` | Search this agent's own memory of the customer's setup: accepted facts (in use) and facts waiting for a person. | runs |
97
+ | `dns_records_learn` | Propose one fact about the customer's setup for this agent to remember. | runs |
98
+ | `dns_records_accept_learning` | A named person accepts or rejects a fact waiting in this agent's memory. | one named click, even in Auto (`accept_learning`) |
99
+ | `dns_records_retire_memory` | A named person stops an accepted fact from applying. | one named click, even in Auto (`accept_learning`) |
100
+ | `dns_update_record` | Fairwire DNS Records never creates, changes or deletes a DNS record. | refused |
101
+ | `dns_live_lookup` | Fairwire DNS Records never queries live DNS or cloud APIs; it reads the export you give it. | refused |
102
+
103
+ Any tool name not in this table is blocked, including names a model invents. `refused` tools are listed so a model can see they exist and are refused.
104
+
105
+ ## Columns it reads
106
+
107
+ Table inputs can be CSV, TSV, semicolon- or pipe-separated text, Excel `.xlsx`, JSON or JSONL. Columns are matched by the agent's own name, then by the English names below, then by their names in German, French, Spanish, Portuguese, Italian, Japanese, Chinese and Korean. Dates become `YYYY-MM-DD`; amounts and counts are read with either decimal mark. Every result lists under `sources` how each file was read.
108
+
109
+ ### DNS records (`records`)
110
+
111
+ | Column | Type | Also read as | For example, in other languages |
112
+ |---|---|---|---|
113
+ | `zone` | text | Zone, Zone Name, Domain, Hosted Zone | Zone, Zone, ゾーン, 区域 |
114
+ | `name` (required) | text | Name, Record Name, Host, Hostname, FQDN | Name, Nom, 名前, 名称 |
115
+ | `type` (required) | text | Type, Record Type, RR Type | Typ, Type, 種類, 类型 |
116
+ | `value` (required) | text | Value, Data, Target, Points To, Content, Record Data | - |
117
+ | `ttl` | number | TTL, Time To Live, TTL (s) | TTL, TTL, TTL, TTL |
118
+
119
+ ### Files from other countries
120
+
121
+ A German export in Windows-1252 with semicolons, `1.234,56` and `03.11.2026`, or a Japanese one in Shift_JIS with `2026/11/03`, is read the same way as the English file. [`fixtures/intl/`](fixtures/intl) has both versions of the demo data, and the eval cases `intl-de-*` and `intl-ja-*` require the same results as the English case. Columns named differently? Run `npx fairwire-dns-records inspect <file>` (names and shapes only, never values) and name them in `fairwire-sources.json`:
122
+
123
+ ```json
124
+ { "files": { "exports/devices.csv": { "columns": { "host": "Gerätename" }, "date_order": "dmy" } } }
125
+ ```
126
+
127
+ ## Memory
128
+
129
+ fairwire-dns-records can remember facts about your setup so the next run does not have to be told again. `dns_records_learn` only proposes a fact; it changes nothing until a named person accepts it with `dns_records_accept_learning`, which is one click even in Auto. Facts live in one hash-chained file per agent under `.fairwire/memory/`; if the chain does not verify, no fact is used. Credentials, personal identifiers and text that reads like instructions to an AI are refused. Run without memory with `--no-memory`.
130
+
131
+ | Kind | What an accepted fact changes |
132
+ |---|---|
133
+ | `known_exception` | that finding is listed under "Accepted as known" instead of as open, until review_by (when given) has passed. |
134
+ | `note` | nothing (shown by recall only) |
135
+
136
+ ```bash
137
+ fairwire-dns-records memory list
138
+ fairwire-dns-records memory accept MEM-1a2b3c4d5e6f --as "Your Name"
139
+ fairwire-dns-records memory retire MEM-1a2b3c4d5e6f --as "Your Name" --reason "rule removed"
140
+ ```
141
+
142
+ ## Install
143
+
144
+ Node 20 or newer. No other dependencies.
145
+
146
+ ```bash
147
+ npx -y fairwire-dns-records demo
148
+ npx -y fairwire-dns-records mcp --root /path/to/your/files
149
+ ```
150
+
151
+ Claude Desktop, Cursor and other MCP hosts:
152
+
153
+ ```json
154
+ {
155
+ "mcpServers": {
156
+ "fairwire-dns-records": {
157
+ "command": "npx",
158
+ "args": [
159
+ "-y",
160
+ "fairwire-dns-records",
161
+ "mcp",
162
+ "--root",
163
+ "/path/to/your/files"
164
+ ]
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ Claude Code: `claude mcp add fairwire-dns-records -- npx -y fairwire-dns-records mcp --root .`, or install the `fairwire-dns-records` plugin from this repository's marketplace.
171
+
172
+ ## Modes and approvals
173
+
174
+ - **Review** (`--mode review`): reads and reports only.
175
+ - **Assist** (default): the policy above. A tool that asks returns an `approval_id`; a person approves it once with `fairwire-dns-records approve <id> --as "Your Name"` (or on the local approvals page, `fairwire-dns-records approvals`), and the same call is repeated.
176
+ - **Auto** (`--mode auto --auto <tool,...>`): opt-in per tool, with step caps and a kill switch (`fairwire-dns-records kill`). Paying, sending, posting to a ledger or a live system and accepting a learned fact stay **one named click even in Auto**; an approval is tied to the sha256 of the reviewed draft, so a changed draft needs a new click.
177
+
178
+ ## CLI
179
+
180
+ ```bash
181
+ fairwire-dns-records tools # every tool, its policy and arguments
182
+ fairwire-dns-records sources # the columns each input is read from
183
+ fairwire-dns-records inspect <file> # how a file would be read (names and shapes, never values)
184
+ fairwire-dns-records call dns_records_check '{"records":"<records>"}'
185
+ fairwire-dns-records eval # the private eval cases on the fictional fixtures
186
+ fairwire-dns-records demo
187
+ ```
188
+
189
+ ## Audit log and data
190
+
191
+ Every call is written to `.fairwire/audit.jsonl` under the root: hash-chained JSON lines, with arguments stored as a hash, signed with an Ed25519 key when you configure one. Everything runs on your machine on files you choose. No network calls, no telemetry, no credentials. The bundled fixtures are fictional.
192
+
193
+ <!-- generated:end -->
194
+
195
+ ## Limits
196
+
197
+ - Reads only the files you export and give it. It does not log in to a firewall, switch, controller, cloud console, identity provider or any other live system.
198
+ - Works offline from the export: it does not resolve names or ask cloud providers whether a resource exists. List the cloud host names that still exist in active_cloud_hosts to sharpen the takeover check.
199
+ - Mail records (SPF, DKIM, DMARC, MX) and certificates are covered by the Fairbooks mail authentication and certificate agents, not here.
200
+ - Thresholds are working defaults in a settings file you control; they are not a vendor rule, a requirement of any standard or a security guarantee.
201
+ - It changes nothing on a live device, firewall, DNS zone, directory or cloud account. Every change it suggests is a draft that one named person applies.
202
+ - Export layouts were written from knowledge of common exports and have not been tested on live customer accounts. Run `inspect` on a new export and name columns in `fairwire-sources.json` when they differ.
203
+
204
+ ## Licence
205
+
206
+ MIT. Fictional data only in `fixtures/`.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from 'node:url';
3
+ import { main } from 'fairwire-core';
4
+ import { manifest } from '../src/manifest.js';
5
+ import { demo } from '../src/demo.js';
6
+
7
+ main(manifest, { bin: 'fairwire-dns-records', demo, evalFile: fileURLToPath(new URL('../evals/cases.json', import.meta.url)) });
@@ -0,0 +1,358 @@
1
+ {
2
+ "suite": "fairwire-dns-records",
3
+ "root": "..",
4
+ "data_note": "Fictional DNS records in ../fixtures. No model is called and no name is resolved.",
5
+ "cases": [
6
+ {
7
+ "id": "check-totals",
8
+ "tool": "dns_records_check",
9
+ "args": {
10
+ "records": "fixtures/records.csv",
11
+ "settings": "fixtures/settings.json"
12
+ },
13
+ "expect": {
14
+ "equals": {
15
+ "result.records": 14,
16
+ "result.zones": 2,
17
+ "result.names": 12,
18
+ "result.cnames": 5,
19
+ "result.open": 8,
20
+ "result.high": 2
21
+ }
22
+ }
23
+ },
24
+ {
25
+ "id": "zone-file",
26
+ "tool": "dns_records_check",
27
+ "args": {
28
+ "records": "fixtures/exports/example-com.zone",
29
+ "settings": "fixtures/settings.json"
30
+ },
31
+ "expect": {
32
+ "equals": {
33
+ "result.format": "zone file",
34
+ "result.records": 17,
35
+ "result.open": 8,
36
+ "result.high": 2
37
+ },
38
+ "contains": [
39
+ "dangling_cname",
40
+ "private_ip_in_public_zone",
41
+ "cname_conflict"
42
+ ],
43
+ "not_contains": [
44
+ "www.example.com has a CNAME"
45
+ ]
46
+ },
47
+ "note": "A master file with the same planted problems as records.csv; the RRSIG beside the www CNAME is DNSSEC, not a conflict."
48
+ },
49
+ {
50
+ "id": "every-planted-issue",
51
+ "tool": "dns_records_check",
52
+ "args": {
53
+ "records": "fixtures/records.csv",
54
+ "settings": "fixtures/settings.json"
55
+ },
56
+ "expect": {
57
+ "contains": [
58
+ "dangling_cname",
59
+ "promo2024.example.com",
60
+ "cname_conflict",
61
+ "status.example.com",
62
+ "private_ip_in_public_zone",
63
+ "10.20.0.15",
64
+ "ip_not_owned",
65
+ "198.51.100.77",
66
+ "duplicate_record",
67
+ "ttl_out_of_range",
68
+ "1209600",
69
+ "wildcard_record"
70
+ ],
71
+ "not_contains": [
72
+ "fileserver",
73
+ "example-shop",
74
+ "example-docs"
75
+ ]
76
+ }
77
+ },
78
+ {
79
+ "id": "without-settings-all-cloud-names-to-confirm",
80
+ "tool": "dns_records_check",
81
+ "args": {
82
+ "records": "fixtures/records.csv"
83
+ },
84
+ "expect": {
85
+ "equals": {
86
+ "result.high": 1
87
+ },
88
+ "contains": [
89
+ "confirm that cloud resource still exists"
90
+ ],
91
+ "not_contains": [
92
+ "ip_not_owned"
93
+ ]
94
+ }
95
+ },
96
+ {
97
+ "id": "code-filter-dangling",
98
+ "tool": "dns_records_check",
99
+ "args": {
100
+ "records": "fixtures/records.csv",
101
+ "code": "dangling_cname"
102
+ },
103
+ "expect": {
104
+ "equals": {
105
+ "result.findings": 3
106
+ }
107
+ }
108
+ },
109
+ {
110
+ "id": "explain-status",
111
+ "tool": "dns_records_explain",
112
+ "args": {
113
+ "records": "fixtures/records.csv",
114
+ "settings": "fixtures/settings.json",
115
+ "name": "status.example.com"
116
+ },
117
+ "expect": {
118
+ "contains": [
119
+ "cname_conflict",
120
+ "ttl_out_of_range"
121
+ ],
122
+ "equals": {
123
+ "result.findings": 2
124
+ }
125
+ }
126
+ },
127
+ {
128
+ "id": "draft-after-approval",
129
+ "tool": "dns_records_draft_change_request",
130
+ "approve": "Pat Example",
131
+ "args": {
132
+ "records": "fixtures/records.csv",
133
+ "settings": "fixtures/settings.json"
134
+ },
135
+ "expect": {
136
+ "status": "executed",
137
+ "contains": [
138
+ "Nothing was sent"
139
+ ],
140
+ "equals": {
141
+ "result.items": 4,
142
+ "result.open_markers": 1
143
+ }
144
+ }
145
+ },
146
+ {
147
+ "id": "review-mode-still-reads",
148
+ "tool": "dns_records_check",
149
+ "mode": "review",
150
+ "args": {
151
+ "records": "fixtures/records.csv",
152
+ "settings": "fixtures/settings.json"
153
+ },
154
+ "expect": {
155
+ "status": "executed",
156
+ "equals": {
157
+ "result.records": 14,
158
+ "result.zones": 2,
159
+ "result.names": 12,
160
+ "result.cnames": 5,
161
+ "result.open": 8,
162
+ "result.high": 2
163
+ }
164
+ },
165
+ "generated": true
166
+ },
167
+ {
168
+ "id": "severity-filter",
169
+ "tool": "dns_records_check",
170
+ "args": {
171
+ "records": "fixtures/records.csv",
172
+ "settings": "fixtures/settings.json",
173
+ "severity": "high"
174
+ },
175
+ "expect": {
176
+ "status": "executed",
177
+ "equals": {
178
+ "result.findings": 2
179
+ }
180
+ },
181
+ "generated": true
182
+ },
183
+ {
184
+ "id": "missing-argument-named",
185
+ "tool": "dns_records_check",
186
+ "args": {},
187
+ "expect": {
188
+ "status": "error",
189
+ "contains": [
190
+ "records"
191
+ ]
192
+ },
193
+ "generated": true
194
+ },
195
+ {
196
+ "id": "file-outside-root-refused",
197
+ "tool": "dns_records_check",
198
+ "args": {
199
+ "records": "../../../outside.csv",
200
+ "settings": "fixtures/settings.json"
201
+ },
202
+ "expect": {
203
+ "status": "error",
204
+ "contains": [
205
+ "outside"
206
+ ]
207
+ },
208
+ "generated": true
209
+ },
210
+ {
211
+ "id": "invented-tool-name-refused",
212
+ "tool": "dns_records_apply_every_fix_now",
213
+ "args": {},
214
+ "expect": {
215
+ "status": "blocked"
216
+ },
217
+ "generated": true
218
+ },
219
+ {
220
+ "id": "write-report-writes-files",
221
+ "tool": "dns_records_write_report",
222
+ "args": {
223
+ "records": "fixtures/records.csv",
224
+ "settings": "fixtures/settings.json"
225
+ },
226
+ "expect": {
227
+ "status": "executed",
228
+ "contains": [
229
+ "dns-records.csv",
230
+ "dns-records.html"
231
+ ]
232
+ },
233
+ "generated": true
234
+ },
235
+ {
236
+ "id": "recall-memory-starts-empty",
237
+ "tool": "dns_records_recall",
238
+ "args": {},
239
+ "expect": {
240
+ "status": "executed",
241
+ "contains": [
242
+ "memory is empty"
243
+ ]
244
+ },
245
+ "generated": true
246
+ },
247
+ {
248
+ "id": "accept-learning-stays-one-click",
249
+ "tool": "dns_records_accept_learning",
250
+ "mode": "auto",
251
+ "args": {
252
+ "id": "MEM-000000000000",
253
+ "decision": "accept"
254
+ },
255
+ "expect": {
256
+ "status": "needs_approval"
257
+ },
258
+ "generated": true
259
+ },
260
+ {
261
+ "id": "never-dns-update-record",
262
+ "tool": "dns_update_record",
263
+ "mode": "auto",
264
+ "args": {},
265
+ "expect": {
266
+ "status": "blocked"
267
+ },
268
+ "generated": true
269
+ },
270
+ {
271
+ "id": "never-dns-live-lookup",
272
+ "tool": "dns_live_lookup",
273
+ "mode": "auto",
274
+ "args": {},
275
+ "expect": {
276
+ "status": "blocked"
277
+ },
278
+ "generated": true
279
+ },
280
+ {
281
+ "id": "draft-waits-for-a-person",
282
+ "tool": "dns_records_draft_change_request",
283
+ "args": {
284
+ "records": "fixtures/records.csv",
285
+ "settings": "fixtures/settings.json"
286
+ },
287
+ "expect": {
288
+ "status": "needs_approval",
289
+ "decision": "ask"
290
+ },
291
+ "generated": true
292
+ },
293
+ {
294
+ "id": "review-mode-drafts-nothing",
295
+ "tool": "dns_records_draft_change_request",
296
+ "mode": "review",
297
+ "args": {
298
+ "records": "fixtures/records.csv",
299
+ "settings": "fixtures/settings.json"
300
+ },
301
+ "expect": {
302
+ "status": "blocked"
303
+ },
304
+ "generated": true
305
+ },
306
+ {
307
+ "id": "request-stays-one-click",
308
+ "tool": "dns_records_request_submit",
309
+ "mode": "auto",
310
+ "args": {
311
+ "draft": "fixtures/README.md",
312
+ "draft_sha256": "0000000000000000000000000000000000000000000000000000000000000000"
313
+ },
314
+ "expect": {
315
+ "status": "needs_approval"
316
+ },
317
+ "generated": true
318
+ },
319
+ {
320
+ "id": "intl-de-check-totals",
321
+ "tool": "dns_records_check",
322
+ "args": {
323
+ "records": "fixtures/intl/de/records.csv",
324
+ "settings": "fixtures/settings.json"
325
+ },
326
+ "expect": {
327
+ "equals": {
328
+ "result.records": 14,
329
+ "result.zones": 2,
330
+ "result.names": 12,
331
+ "result.cnames": 5,
332
+ "result.open": 8,
333
+ "result.high": 2
334
+ }
335
+ },
336
+ "note": "German export of the same data (fixtures/intl/de); must match the English case \"check-totals\"."
337
+ },
338
+ {
339
+ "id": "intl-ja-check-totals",
340
+ "tool": "dns_records_check",
341
+ "args": {
342
+ "records": "fixtures/intl/ja/records.csv",
343
+ "settings": "fixtures/settings.json"
344
+ },
345
+ "expect": {
346
+ "equals": {
347
+ "result.records": 14,
348
+ "result.zones": 2,
349
+ "result.names": 12,
350
+ "result.cnames": 5,
351
+ "result.open": 8,
352
+ "result.high": 2
353
+ }
354
+ },
355
+ "note": "Japanese export of the same data (fixtures/intl/ja); must match the English case \"check-totals\"."
356
+ }
357
+ ]
358
+ }
@@ -0,0 +1,6 @@
1
+ # Fairwire DNS Records fixtures
2
+
3
+ Fictional records for example.com (reserved for documentation) and an internal corp zone.
4
+
5
+ - `records.csv`: 14 records. promo2024 points at an S3 website that is not in the list of resources that still exist; intranet in the public zone points at a private address; legacy points at an address outside the owned range; mail is listed twice; status has a CNAME and a TXT record (and a 30-second TTL); a wildcard under preview; api has a two-week TTL. The internal zone is not public, so its private address is fine.
6
+ - `settings.json`: the public zone, the owned range 203.0.113.0/24 and the cloud host names that still exist.
@@ -0,0 +1,23 @@
1
+ ; Fictional zone for example.com in master-file format (as BIND, Windows DNS or a zone transfer writes it).
2
+ ; Same planted problems as records.csv, plus a DNSSEC signature next to a CNAME, which is not a conflict.
3
+ $ORIGIN example.com.
4
+ $TTL 3600
5
+ @ IN SOA ns1.example.com. hostmaster.example.com. (
6
+ 2026111801 ; serial
7
+ 7200 3600 1209600 3600 )
8
+ @ IN NS ns1.example.com.
9
+ @ IN A 203.0.113.10
10
+ www IN CNAME @
11
+ www IN RRSIG CNAME 13 3 3600 20261201000000 20261118000000 12345 example.com. c2lnbmF0dXJl
12
+ shop IN CNAME example-shop.azurewebsites.net.
13
+ docs IN CNAME example-docs.github.io.
14
+ promo2024 IN CNAME promo2024-example.s3-website-us-east-1.amazonaws.com.
15
+ intranet IN A 10.20.0.15
16
+ legacy IN A 198.51.100.77
17
+ mail IN A 203.0.113.25
18
+ mail IN A 203.0.113.25
19
+ status 30 IN CNAME status-page.example.net.
20
+ status IN TXT "verification=abc123; kept in quotes"
21
+ *.preview IN A 203.0.113.40
22
+ api 1209600 IN A 203.0.113.30
23
+ ns1 IN A 203.0.113.53
@@ -0,0 +1,12 @@
1
+ # Fixtures from other countries
2
+
3
+ Generated by `node scripts/make-intl-fixtures.mjs` from the English fixtures one
4
+ folder up. The same fictional data, written the way a local export writes it:
5
+
6
+ - `de/`: German column names, Windows-1252 text, semicolons, comma decimals
7
+ (1.234,56), day-first dotted dates (03.11.2026), kilograms and kilometres.
8
+ - `ja/`: Japanese column names, Shift_JIS text, year-first dates (2026/11/03),
9
+ kilograms and kilometres.
10
+
11
+ Values (names, codes, charge wording) stay in English. The eval cases
12
+ `intl-de-*` and `intl-ja-*` expect exactly the same results as the English case.
@@ -0,0 +1,15 @@
1
+ Tarifzone;Vollst�ndiger Name;Typ;value;G�ltigkeitsdauer
2
+ example.com;@;A;203.0.113.10;3.600
3
+ example.com;www;CNAME;example.com.;3.600
4
+ example.com;shop;CNAME;example-shop.azurewebsites.net.;3.600
5
+ example.com;docs;CNAME;example-docs.github.io.;3.600
6
+ example.com;promo2024;CNAME;promo2024-example.s3-website-us-east-1.amazonaws.com.;3.600
7
+ example.com;intranet;A;10.20.0.15;3.600
8
+ example.com;legacy;A;198.51.100.77;3.600
9
+ example.com;mail;A;203.0.113.25;3.600
10
+ example.com;mail;A;203.0.113.25;3.600
11
+ example.com;status;CNAME;status-page.example.net.;30
12
+ example.com;status;TXT;verification=abc123;3.600
13
+ example.com;*.preview;A;203.0.113.40;3.600
14
+ example.com;api;A;203.0.113.30;1.209.600
15
+ corp.example.com;fileserver;A;10.20.0.40;3.600
@@ -0,0 +1,15 @@
1
+ �]�[��,���O,���,value,ttl
2
+ example.com,@,A,203.0.113.10,"3,600"
3
+ example.com,www,CNAME,example.com.,"3,600"
4
+ example.com,shop,CNAME,example-shop.azurewebsites.net.,"3,600"
5
+ example.com,docs,CNAME,example-docs.github.io.,"3,600"
6
+ example.com,promo2024,CNAME,promo2024-example.s3-website-us-east-1.amazonaws.com.,"3,600"
7
+ example.com,intranet,A,10.20.0.15,"3,600"
8
+ example.com,legacy,A,198.51.100.77,"3,600"
9
+ example.com,mail,A,203.0.113.25,"3,600"
10
+ example.com,mail,A,203.0.113.25,"3,600"
11
+ example.com,status,CNAME,status-page.example.net.,30
12
+ example.com,status,TXT,verification=abc123,"3,600"
13
+ example.com,*.preview,A,203.0.113.40,"3,600"
14
+ example.com,api,A,203.0.113.30,"1,209,600"
15
+ corp.example.com,fileserver,A,10.20.0.40,"3,600"
@@ -0,0 +1,15 @@
1
+ zone,name,type,value,ttl
2
+ example.com,@,A,203.0.113.10,3600
3
+ example.com,www,CNAME,example.com.,3600
4
+ example.com,shop,CNAME,example-shop.azurewebsites.net.,3600
5
+ example.com,docs,CNAME,example-docs.github.io.,3600
6
+ example.com,promo2024,CNAME,promo2024-example.s3-website-us-east-1.amazonaws.com.,3600
7
+ example.com,intranet,A,10.20.0.15,3600
8
+ example.com,legacy,A,198.51.100.77,3600
9
+ example.com,mail,A,203.0.113.25,3600
10
+ example.com,mail,A,203.0.113.25,3600
11
+ example.com,status,CNAME,status-page.example.net.,30
12
+ example.com,status,TXT,"verification=abc123",3600
13
+ example.com,*.preview,A,203.0.113.40,3600
14
+ example.com,api,A,203.0.113.30,1209600
15
+ corp.example.com,fileserver,A,10.20.0.40,3600
@@ -0,0 +1,5 @@
1
+ {
2
+ "public_zones": ["example.com"],
3
+ "owned_cidrs": ["203.0.113.0/24"],
4
+ "active_cloud_hosts": ["example-shop.azurewebsites.net", "example-docs.github.io"]
5
+ }
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "fairwire-dns-records",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "mcpName": "io.github.fpavia111-creator/fairwire-dns-records",
5
+ "description": "Fairwire DNS Records: DNS zone hygiene from a zone export: names pointing at cloud services that may no longer exist (takeover risk), public names pointing at private addresses, duplicate and conflicting records, very short or very long TTLs, wildcards and records pointing at addresses you no longer own. Drafts a change request; never edits DNS.",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "author": "Kurt Francisco",
9
+ "engines": {
10
+ "node": ">=20"
11
+ },
12
+ "main": "src/index.js",
13
+ "exports": {
14
+ ".": "./src/index.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "bin": {
18
+ "fairwire-dns-records": "bin/fairwire-dns-records.js"
19
+ },
20
+ "files": [
21
+ "src",
22
+ "bin",
23
+ "fixtures",
24
+ "evals",
25
+ "README.md",
26
+ "CHANGELOG.md",
27
+ "LICENSE",
28
+ "server.json"
29
+ ],
30
+ "scripts": {
31
+ "test": "node scripts/run-tests.cjs",
32
+ "demo": "node bin/fairwire-dns-records.js demo",
33
+ "eval": "node bin/fairwire-dns-records.js eval"
34
+ },
35
+ "dependencies": {
36
+ "fairwire-core": "^0.1.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/fpavia111-creator/fairwire-agents.git",
41
+ "directory": "packages/fairwire-dns-records"
42
+ },
43
+ "homepage": "https://github.com/fpavia111-creator/fairwire-agents/tree/master/packages/fairwire-dns-records#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/fpavia111-creator/fairwire-agents/issues"
46
+ },
47
+ "keywords": [
48
+ "mcp",
49
+ "mcp-server",
50
+ "it-operations",
51
+ "network",
52
+ "fairwire",
53
+ "dns",
54
+ "zone-file",
55
+ "subdomain-takeover",
56
+ "dangling-cname",
57
+ "dns-hygiene"
58
+ ]
59
+ }
package/server.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.fpavia111-creator/fairwire-dns-records",
4
+ "title": "Fairwire DNS Records",
5
+ "description": "Fairwire DNS Records: DNS zone hygiene from a zone export: names pointing at cloud services that…",
6
+ "version": "0.1.0",
7
+ "repository": {
8
+ "url": "https://github.com/fpavia111-creator/fairwire-agents",
9
+ "source": "github",
10
+ "subfolder": "packages/fairwire-dns-records"
11
+ },
12
+ "websiteUrl": "https://fair-agents.com/fairwire.html",
13
+ "packages": [
14
+ {
15
+ "registryType": "npm",
16
+ "identifier": "fairwire-dns-records",
17
+ "version": "0.1.0",
18
+ "transport": {
19
+ "type": "stdio"
20
+ },
21
+ "packageArguments": [
22
+ {
23
+ "type": "positional",
24
+ "value": "mcp"
25
+ },
26
+ {
27
+ "type": "named",
28
+ "name": "--root",
29
+ "description": "Folder holding the exports this agent may read and write (it cannot reach outside it)",
30
+ "isRequired": true,
31
+ "format": "filepath",
32
+ "valueHint": "exports_folder"
33
+ }
34
+ ]
35
+ }
36
+ ]
37
+ }
package/src/demo.js ADDED
@@ -0,0 +1,19 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { readFileSync } from 'node:fs';
3
+ import { standardDemo } from 'fairwire-core';
4
+
5
+ // The demo runs the eval case "check-totals" and the agent's draft on the fictional fixtures.
6
+ const cases = JSON.parse(readFileSync(new URL('../evals/cases.json', import.meta.url), 'utf8')).cases;
7
+ const base = cases.find((c) => c.id === 'check-totals');
8
+ const explain = cases.find((c) => /_explain$/.test(c.tool) && !c.expect.status);
9
+ const draft = cases.find((c) => /_draft_/.test(c.tool) && c.approve);
10
+
11
+ export async function demo(manifest) {
12
+ const refused = manifest.tools.filter((t) => (manifest.policy.rules.find((r) => r.tool === t.name) || {}).decision === 'block')[0];
13
+ await standardDemo(manifest, fileURLToPath(new URL('../fixtures', import.meta.url)), {
14
+ title: 'Fairwire DNS Records demo', args: base.args,
15
+ explain: explain ? { label: 'Explain one finding', args: explain.args } : null,
16
+ draft: draft ? { label: 'Draft the note for a person', args: draft.args } : null,
17
+ refused: refused ? refused.name : null,
18
+ });
19
+ }
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { manifest } from './manifest.js';
2
+ export * from './logic.js';
3
+ export { parseZoneFile, looksLikeZoneFile } from './zonefile.js';
package/src/logic.js ADDED
@@ -0,0 +1,63 @@
1
+ // Fairwire DNS Records: DNS zone hygiene from a zone export. Pure functions.
2
+ import { num, str, low, isIpv4, isPrivateIp, inAnyCidr, finding } from 'fairwire-core';
3
+
4
+ export const CHECKS = Object.freeze({
5
+ dangling_cname: 'A name pointing (CNAME) at a cloud service host name that may no longer exist: whoever creates that cloud resource next can serve content on your name (subdomain takeover).',
6
+ cname_conflict: 'A name with a CNAME and other records at the same time, which DNS does not allow and resolvers handle unpredictably.',
7
+ private_ip_in_public_zone: 'A public zone record pointing at a private address (it leaks your internal layout and never works from outside).',
8
+ ip_not_owned: 'A record pointing at a public address outside the ranges you own (it may now belong to someone else).',
9
+ duplicate_record: 'The same record listed twice.',
10
+ ttl_out_of_range: 'A time-to-live shorter or longer than your limits.',
11
+ wildcard_record: 'A wildcard record, which answers for every name under it, including typos and names an attacker chooses.',
12
+ });
13
+
14
+ export const RECORD_FIELDS = Object.freeze({
15
+ zone: { aliases: ['Zone', 'Zone Name', 'Domain', 'Hosted Zone'] },
16
+ name: { aliases: ['Name', 'Record Name', 'Host', 'Hostname', 'FQDN'], required: true },
17
+ type: { aliases: ['Type', 'Record Type', 'RR Type'], required: true },
18
+ value: { aliases: ['Value', 'Data', 'Target', 'Points To', 'Content', 'Record Data'], required: true },
19
+ ttl: { type: 'number', aliases: ['TTL', 'Time To Live', 'TTL (s)'] },
20
+ });
21
+
22
+ const CLOUD = ['azurewebsites.net', 'cloudapp.net', 'cloudapp.azure.com', 'trafficmanager.net', 'blob.core.windows.net', 'azureedge.net', 'azurefd.net', 's3.amazonaws.com', 's3-website', 'elasticbeanstalk.com', 'cloudfront.net', 'herokuapp.com', 'herokudns.com', 'github.io', 'netlify.app', 'vercel.app', 'pages.dev', 'fastly.net', 'ghost.io', 'myshopify.com', 'wpengine.com', 'zendesk.com', 'readthedocs.io'];
23
+ export const SETTINGS_SCHEMA = { type: 'object', additionalProperties: false, properties: {
24
+ public_zones: { type: 'array', items: { type: 'string' }, maxItems: 500, description: 'Zones published on the internet (default: every zone in the file)' },
25
+ owned_cidrs: { type: 'array', items: { type: 'string' }, maxItems: 500, description: 'Public address ranges you own or rent (no ownership check when empty)' },
26
+ active_cloud_hosts: { type: 'array', items: { type: 'string' }, maxItems: 5000, description: 'Cloud host names that still exist in your accounts; a CNAME to a cloud host not on this list is high (medium when the list is empty)' },
27
+ cloud_suffixes: { type: 'array', items: { type: 'string' }, maxItems: 200, description: 'Extra cloud service host suffixes to treat as takeover-prone' },
28
+ ttl_min: { type: 'integer', minimum: 0, description: 'Shortest acceptable TTL in seconds (default 60)' },
29
+ ttl_max: { type: 'integer', minimum: 1, description: 'Longest acceptable TTL in seconds (default 604800, one week)' },
30
+ } };
31
+ export const DEFAULTS = Object.freeze({ public_zones: [], owned_cidrs: [], active_cloud_hosts: [], cloud_suffixes: [], ttl_min: 60, ttl_max: 604800 });
32
+
33
+ const DNSSEC = new Set(['RRSIG', 'NSEC', 'NSEC3', 'SIG', 'KEY']);
34
+ const fqdn = (name, zone) => { const n = low(name).replace(/\.$/, ''); const z = low(zone).replace(/\.$/, ''); if (!n || n === '@') return z; return z && !n.endsWith(z) ? `${n}.${z}` : n; };
35
+
36
+ /** Count items per key in one pass (a filter per group is quadratic). */
37
+ const countBy = (list, key) => { const m = new Map(); for (const x of list) { const k = key(x); m.set(k, (m.get(k) || 0) + 1); } return m; };
38
+
39
+ export function reviewZones(rows, settings = {}) {
40
+ const s = { ...DEFAULTS, ...settings };
41
+ const rs = rows.filter((r) => str(r.name) && str(r.type) && str(r.value)).map((r) => { const zone = low(r.zone).replace(/\.$/, ''); return { zone, name: fqdn(r.name, zone), type: str(r.type).toUpperCase(), value: low(r.value).replace(/\.$/, ''), ttl: num(r.ttl) }; });
42
+ const items = []; const pub = s.public_zones.map(low); const active = new Set(s.active_cloud_hosts.map((h) => low(h).replace(/\.$/, '')));
43
+ const cloud = [...CLOUD, ...s.cloud_suffixes.map(low)];
44
+ const byName = new Map(); for (const r of rs) { const l = byName.get(r.name); if (l) l.push(r); else byName.set(r.name, [r]); }
45
+ const seen = new Set();
46
+ for (const r of rs) {
47
+ const sig = `${r.name}|${r.type}|${r.value}`;
48
+ if (seen.has(sig)) { items.push(finding('duplicate_record', 'low', sig, `${r.type} record ${r.name} -> ${r.value} is listed twice.`, 'Remove the copy.', { subject: r.zone })); continue; }
49
+ seen.add(sig);
50
+ const isPublic = !pub.length || pub.includes(r.zone);
51
+ if (r.type === 'CNAME' && cloud.some((c) => r.value.endsWith(c) || r.value.includes(`.${c}`))) {
52
+ if (!active.has(r.value)) items.push(finding('dangling_cname', active.size ? 'high' : 'medium', r.name, `${r.name} points at ${r.value}${active.size ? ', which is not in your list of cloud resources that still exist' : '; confirm that cloud resource still exists'}.`, 'If the resource is gone, delete the record today; if it exists, add it to active_cloud_hosts.', { subject: r.zone }));
53
+ }
54
+ if ((r.type === 'A') && isPublic && isIpv4(r.value) && isPrivateIp(r.value)) items.push(finding('private_ip_in_public_zone', 'medium', `${r.name}|${r.value}`, `Public record ${r.name} points at private address ${r.value}.`, 'Move it to the internal zone (split DNS) or remove it.', { subject: r.zone }));
55
+ if (r.type === 'A' && isPublic && s.owned_cidrs.length && isIpv4(r.value) && !isPrivateIp(r.value) && !inAnyCidr(r.value, s.owned_cidrs)) items.push(finding('ip_not_owned', 'medium', `${r.name}|${r.value}`, `${r.name} points at ${r.value}, which is outside the address ranges you own.`, 'Check the address still belongs to your provider or service; remove the record if not.', { subject: r.zone }));
56
+ if (r.ttl !== null && (r.ttl < s.ttl_min || r.ttl > s.ttl_max)) items.push(finding('ttl_out_of_range', 'low', sig, `${r.type} record ${r.name} has a TTL of ${r.ttl} seconds.`, r.ttl < s.ttl_min ? 'Raise it unless you are about to move the record; very short TTLs add load and cost.' : 'Lower it so a change takes effect within a day or so.', { subject: r.zone }));
57
+ if (r.name.startsWith('*.')) items.push(finding('wildcard_record', 'low', sig, `${r.name} is a wildcard ${r.type} record pointing at ${r.value}.`, 'Replace it with the names you actually use, unless a service needs it.', { subject: r.zone }));
58
+ }
59
+ // DNSSEC records (RRSIG, NSEC, NSEC3) sit beside a CNAME by design (RFC 4035) and are not a conflict.
60
+ for (const [name, list] of byName) { const types = new Set(list.map((r) => r.type).filter((t) => !DNSSEC.has(t))); if (types.has('CNAME') && types.size > 1) items.push(finding('cname_conflict', 'high', name, `${name} has a CNAME and also ${[...types].filter((t) => t !== 'CNAME').sort().join(', ')} records.`, 'Keep either the CNAME or the other records, not both.', { subject: list[0].zone })); }
61
+ const zones = [...new Set(rs.map((r) => r.zone))].sort();
62
+ return { records: rs.length, zones: zones.length, names: byName.size, cnames: rs.filter((r) => r.type === 'CNAME').length, by_zone: ((nr, nf) => zones.map((zone) => ({ zone, records: nr.get(zone) || 0, findings: nf.get(zone) || 0 })))(countBy(rs, (r) => r.zone), countBy(items, (i) => i.subject)), items };
63
+ }
@@ -0,0 +1,41 @@
1
+ import { readFileSync, statSync } from 'node:fs';
2
+ import { wireAgent, fileArg, SETTINGS_ARG, settingsFrom, LIMITS } from 'fairwire-core';
3
+ import { RECORD_FIELDS, SETTINGS_SCHEMA, DEFAULTS, reviewZones } from './logic.js';
4
+ import { looksLikeZoneFile, parseZoneFile } from './zonefile.js';
5
+
6
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
7
+ const args = {
8
+ records: fileArg('DNS zone export under --root: a zone (master) file as BIND, Windows DNS, Cloudflare or a zone transfer writes it, or a CSV, Excel or JSON list (Route 53, Azure DNS) with zone, name, type, value and TTL'),
9
+ settings: SETTINGS_ARG('public_zones, owned_cidrs, active_cloud_hosts, cloud_suffixes, ttl_min, ttl_max'),
10
+ };
11
+
12
+ export const manifest = wireAgent({
13
+ pkg, prefix: 'dns_records', title: 'Fairwire DNS Records',
14
+ description: 'Reviews DNS zone exports: names pointing at cloud services that may no longer exist (subdomain takeover risk), CNAMEs next to other records, public names pointing at private addresses, addresses outside the ranges you own, duplicates, TTLs outside your limits and wildcards. Offline; drafts a change request and never edits DNS.',
15
+ args, required: ['records'],
16
+ sources: { records: { label: 'DNS records', args: ['records'], fields: RECORD_FIELDS } },
17
+ configSchemas: { dns_records_settings: SETTINGS_SCHEMA },
18
+ run: (a, ctx) => {
19
+ const settings = settingsFrom(a, ctx, 'dns_records_settings', DEFAULTS);
20
+ // A zone (master) file is read here; anything else goes through the usual table reader.
21
+ if (statSync(ctx.path(a.records)).size <= 200 * 1024 * 1024) {
22
+ const text = ctx.readText(a.records);
23
+ if (looksLikeZoneFile(text)) { const z = parseZoneFile(text); return { ...reviewZones(z.rows, settings), format: 'zone file', ...(z.includes || z.skipped ? { zone_file: { includes_not_followed: z.includes, lines_not_read: z.skipped } } : {}) }; }
24
+ }
25
+ return reviewZones(ctx.records(a.records, 'records'), settings);
26
+ },
27
+ summary: (o) => `${o.records} record(s) for ${o.names} name(s) in ${o.zones} zone(s), ${o.cnames} CNAME(s): ${o.open} open finding(s), ${o.high} high.`,
28
+ check: { title: 'Review DNS zones', description: 'Review the zone export and list takeover-prone CNAMEs, CNAME conflicts, private or foreign addresses, duplicates, TTL problems and wildcards.' },
29
+ explain: { arg: 'name', argSchema: { type: 'string', maxLength: 300, description: 'Record name or zone from dns_records_check' }, title: 'Explain one name or zone', description: 'Every finding for one record name or zone.', match: (i, v) => i.key === v || String(i.key).split('|')[0] === String(v).toLowerCase() || i.subject === String(v).toLowerCase() },
30
+ report: {
31
+ title: 'DNS zone hygiene', base: 'dns-records',
32
+ sections: (o) => [{ title: 'By zone', rows: o.by_zone, columns: ['zone', 'records', 'findings'] }],
33
+ limits: [LIMITS.files, 'Works offline from the export: it does not resolve names or ask cloud providers whether a resource exists. List the cloud host names that still exist in active_cloud_hosts to sharpen the takeover check.', 'Mail records (SPF, DKIM, DMARC, MX) and certificates are covered by the Fairbooks mail authentication and certificate agents, not here.', LIMITS.defaults, LIMITS.live],
34
+ },
35
+ note: { noun: 'change_request', verb: 'submit', category: 'production_deploy', actor: 'the DNS owner', to: 'DNS and network change board', subject: 'DNS records to change or remove', ask: 'Please remove dangling records today; check each other change with the service owner first.' },
36
+ refused: [
37
+ { name: 'dns_update_record', category: 'production_deploy', description: 'Fairwire DNS Records never creates, changes or deletes a DNS record.' },
38
+ { name: 'dns_live_lookup', category: 'production_deploy', description: 'Fairwire DNS Records never queries live DNS or cloud APIs; it reads the export you give it.' },
39
+ ],
40
+ prompt: { title: 'Review DNS zones', description: 'Walks the host model through a zone review with Fairwire DNS Records.', text: 'You are helping a DNS owner review zone exports with fairwire-dns-records. Fairwire DNS Records works offline. 1. Call dns_records_check; lead with dangling CNAMEs and CNAME conflicts. 2. Use dns_records_explain for one name. 3. Call dns_records_write_report. 4. Offer dns_records_draft_change_request; dns_records_request_submit waits for one named click and the DNS owner makes the change.' },
41
+ });
@@ -0,0 +1,71 @@
1
+ // DNS master files (RFC 1035 section 5): what BIND, Windows DNS, Cloudflare, Route 53 (via cli53) and a zone
2
+ // transfer (dig AXFR) write. Read into the same rows as a spreadsheet export: zone, name, type, value, ttl.
3
+ // Pure functions. Added in the final pass to read the public IANA root zone as published.
4
+ //
5
+ // Handled: comments, $ORIGIN, $TTL, $INCLUDE (not followed; counted), "@", relative and absolute names,
6
+ // a blank owner (the previous one), TTL and class in either order, records split over lines with
7
+ // parentheses, and quoted text with semicolons inside.
8
+
9
+ const TYPES = new Set(['A', 'AAAA', 'AFSDB', 'APL', 'CAA', 'CDNSKEY', 'CDS', 'CERT', 'CNAME', 'CSYNC', 'DHCID', 'DLV', 'DNAME', 'DNSKEY', 'DS', 'EUI48', 'EUI64', 'HINFO', 'HIP', 'HTTPS', 'IPSECKEY', 'KEY', 'KX', 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', 'NSEC3', 'NSEC3PARAM', 'OPENPGPKEY', 'PTR', 'RP', 'RRSIG', 'SIG', 'SMIMEA', 'SOA', 'SPF', 'SRV', 'SSHFP', 'SVCB', 'TA', 'TLSA', 'TXT', 'URI', 'ZONEMD']);
10
+ const CLASSES = new Set(['IN', 'CH', 'HS', 'CS']);
11
+ const isType = (t) => TYPES.has(t.toUpperCase()) || /^TYPE\d+$/i.test(t);
12
+ /** Record types whose whole value is one domain name, resolved against $ORIGIN when relative. */
13
+ const NAME_VALUE = new Set(['CNAME', 'DNAME', 'NS', 'PTR']);
14
+
15
+ /** Strip a comment that is not inside quotes. */
16
+ function stripComment(line) {
17
+ let q = false;
18
+ for (let i = 0; i < line.length; i++) {
19
+ const ch = line[i];
20
+ if (ch === '\\') { i++; continue; }
21
+ if (ch === '"') q = !q; else if (ch === ';' && !q) return line.slice(0, i);
22
+ }
23
+ return line;
24
+ }
25
+ /** Split on whitespace, keeping quoted strings whole. */
26
+ function tokens(s) { return s.match(/"(?:[^"\\]|\\.)*"|[^\s()]+/g) || []; }
27
+
28
+ /** True when the text looks like a master file rather than a CSV or JSON export. */
29
+ export function looksLikeZoneFile(text) {
30
+ const lines = String(text).split(/\r?\n/).map((l) => stripComment(l).trim()).filter(Boolean).slice(0, 40);
31
+ if (!lines.length) return false;
32
+ if (lines.some((l) => /^\$(ORIGIN|TTL)\b/i.test(l))) return true;
33
+ const data = lines.filter((l) => !/^[,;]/.test(l));
34
+ const rr = data.filter((l) => { const t = tokens(l); return t.slice(0, 4).some((x, k) => k > 0 && isType(x)) && !/,/.test(l.split(/\s+/)[0]); });
35
+ return rr.length >= Math.min(3, data.length) && !data[0].includes(',');
36
+ }
37
+
38
+ export function parseZoneFile(text, { origin = '' } = {}) {
39
+ let org = origin ? (origin.endsWith('.') ? origin : `${origin}.`) : '';
40
+ let ttl = null; let last = null; const rows = []; let includes = 0; let skipped = 0; let zone = org;
41
+ const abs = (n) => { if (n === '@') return org || '.'; if (n.endsWith('.')) return n; return org && org !== '.' ? `${n}.${org}` : `${n}.`; };
42
+ const src = String(text).replace(/^/, '').split(/\r?\n/);
43
+ for (let i = 0; i < src.length; i++) {
44
+ let raw = stripComment(src[i]);
45
+ // A record split over lines with parentheses (SOA, DNSKEY, RRSIG).
46
+ let depth = (raw.match(/\(/g) || []).length - (raw.match(/\)/g) || []).length;
47
+ while (depth > 0 && i + 1 < src.length) { const next = stripComment(src[++i]); raw += ` ${next}`; depth += (next.match(/\(/g) || []).length - (next.match(/\)/g) || []).length; }
48
+ if (!raw.trim()) continue;
49
+ const blankOwner = /^\s/.test(raw);
50
+ const t = tokens(raw);
51
+ if (!t.length) continue;
52
+ const d = t[0].toUpperCase();
53
+ if (d === '$ORIGIN') { org = t[1] ? (t[1].endsWith('.') ? t[1] : `${t[1]}.${org}`) : org; if (!zone) zone = org; continue; }
54
+ if (d === '$TTL') { ttl = Number(t[1]) || ttl; continue; }
55
+ if (d === '$INCLUDE') { includes++; continue; }
56
+ let k = 0; let owner;
57
+ if (blankOwner) owner = last; else { owner = abs(t[0]); k = 1; }
58
+ let rttl = null;
59
+ for (let n = 0; n < 2 && k < t.length; n++) {
60
+ if (/^\d+$/.test(t[k])) { rttl = Number(t[k]); k++; } else if (CLASSES.has(t[k].toUpperCase())) k++;
61
+ }
62
+ const type = t[k] ? t[k].toUpperCase() : '';
63
+ if (!owner || !isType(type)) { skipped++; continue; }
64
+ let value = t.slice(k + 1).join(' ');
65
+ if (NAME_VALUE.has(type) && t[k + 1]) value = abs(t[k + 1]);
66
+ if (type === 'SOA' && !zone) zone = owner;
67
+ last = owner;
68
+ rows.push({ zone: zone || org || owner, name: owner, type, value, ttl: rttl ?? ttl ?? '' });
69
+ }
70
+ return { rows, includes, skipped };
71
+ }