dwelldelta-mcp 0.12.0 → 0.14.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/LICENSE CHANGED
@@ -21,7 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
23
  The data files in vendor/ (rents-index.json, indicators.json, nsw-suburbs.json, vic-rents.json,
24
- nsw-rents.json, qld-rents.json, wa-rents.json, sa-rents.json, nsw-sales.json) are
24
+ nsw-rents.json, qld-rents.json, wa-rents.json, sa-rents.json, nsw-sales.json, nz-rents.json,
25
+ act-rents-interim.json, nt-rents-interim.json, tas-rents-interim.json) are
25
26
  not covered by this licence. Each figure keeps its source's own licence and
26
27
  attribution, which the data files and every answer state (for example, ABS data:
27
28
  CC BY 4.0, "Based on Australian Bureau of Statistics data"; the NSW suburb list:
@@ -34,4 +35,8 @@ SA rents: South Australian Housing Trust, Government of South Australia,
34
35
  Private Rent Report, whose own page states no licence - the national
35
36
  catalogues list CC BY 4.0 and CC BY 3.0 AU;
36
37
  NSW sale prices: CC BY 4.0, State of New South Wales (Department of
37
- Communities and Justice)).
38
+ Communities and Justice); New Zealand rents: CC BY 3.0 NZ, the Ministry of
39
+ Business, Innovation and Employment, Tenancy Services rental bond data; ACT,
40
+ Northern Territory and Tasmania interim rent cover: CC BY 4.0, Commonwealth of
41
+ Australia (Australian Bureau of Statistics), "Based on Australian Bureau of
42
+ Statistics data").
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # dwelldelta-mcp - is an Australian rent fair?
2
2
 
3
3
  An MCP server that lets an AI assistant check a weekly rent against the ABS rents index, look up median rents
4
- by area in five states and NSW median sale prices, and quote sourced Australian property and lending indicators. From
4
+ by area in five states and New Zealand (with interim ABS cover for the ACT, the Northern Territory and Tasmania) and
5
+ NSW median sale prices, and quote sourced Australian property and lending indicators. From
5
6
  [DwellDelta](https://dwelldelta.com.au/), a service of Xcelerent Pty Ltd, built on public data.
6
7
 
7
8
  Seven read-only tools, and one that adds the user's own rent when they ask:
@@ -9,7 +10,7 @@ Seven read-only tools, and one that adds the user's own rent when they ask:
9
10
  | Tool | What it answers |
10
11
  |---|---|
11
12
  | `rent_check` | a weekly rent, and any proposed new rent, against the ABS rents index for the capital city since the lease began (the same arithmetic as the rent check at tools.dwelldelta.com.au); or, given a `place` instead of a lease start, against that place's median of new bonds or leases, and its quartiles where published (from 0.12.0) |
12
- | `property_rents` | the rents of a place asked with no state - a suburb, locality or postcode - answered from the state that holds it (NSW, Victoria, Queensland, WA or SA); an NSW suburb is answered for its postcode, and a name held in more than one state is listed, not chosen (from 0.12.0) |
13
+ | `property_rents` | the rents of a place asked with no state - a suburb, locality or postcode - answered from the state that holds it (NSW, Victoria, Queensland, WA or SA); an NSW suburb is answered for its postcode, and a name held in more than one state is listed, not chosen (from 0.12.0). From 0.14.0 also a New Zealand council or region (MBIE's bonds for one month, in NZ$, provisional) and an ACT, NT or Tasmanian postcode (interim ABS cover: the rent paid at the 2021 Census, the capital's rents index, sale prices - not new-bond medians) |
13
14
  | `market_indicators` | the latest RBA cash rate, unemployment, wage growth, rents for all eight capitals, NSW lending, lending standards and arrears, approvals and completions - each with period, source, licence and limits; filter by `geography` |
14
15
  | `vic_rents` | Victorian rents by suburb group from Homes Victoria's Rental Report: the median weekly rent of new leases, the lease count and the change on a year before, for 146 suburb groups and 13 regions; filter by `suburb_group` or `region` (from 0.5.0) |
15
16
  | `area_rents` | median weekly rent of new bonds, all dwellings together, with the bond count and the change on a year before, for one state per call: NSW by postcode or council (NSW Department of Communities and Justice), Queensland by suburb or council (Residential Tenancies Authority), WA by locality (calculated by DwellDelta from the Government of Western Australia's bond records), SA by suburb (SA Housing Trust, Private Rent Report; its publisher's page states no licence, and the national catalogues list CC BY); each file states CC BY 4.0 (from 0.6.0; SA from 0.11.0) |
@@ -19,9 +20,9 @@ Seven read-only tools, and one that adds the user's own rent when they ask:
19
20
 
20
21
  It runs on your own machine over stdio. It records nothing and sends nothing about you unless you choose to add
21
22
  your rent. At start it fetches DwellDelta's published files from tools.dwelldelta.com.au - the week's indicators,
22
- the rents and sale prices it answers from, and (from 0.9.0) the ABS rents index behind `rent_check`, nine public
23
- files in all, the same for everyone; nothing about you or your questions is sent - and otherwise uses the copies it
24
- ships with. Set `DWELLDELTA_OFFLINE=1` and none of those nine files is fetched; adding a rent with `contribute_rent` still sends it, as you asked. Nothing it says is a
23
+ the rents and sale prices it answers from, and (from 0.9.0) the ABS rents index behind `rent_check`, fourteen public
24
+ files in all from 0.14.0, the same for everyone; nothing about you or your questions is sent - and otherwise uses the
25
+ copies it ships with (all but the two rents by dwelling type files). Set `DWELLDELTA_OFFLINE=1` and none of those files is fetched; adding a rent with `contribute_rent` still sends it, as you asked. Nothing it says is a
25
26
  forecast, a valuation or advice.
26
27
 
27
28
  ## Adding a rent (from 0.5.0)
@@ -110,6 +111,28 @@ by-type question fails with the next step, and every other answer is unaffected.
110
111
 
111
112
  It is listed in the MCP registry as `au.com.dwelldelta/dwelldelta`.
112
113
 
114
+ ## New Zealand, and the ACT, the Northern Territory and Tasmania (from 0.14.0)
115
+
116
+ `property_rents` answers these too, each in fields of its own - never `area_rents`, whose fields mean a median of new
117
+ bonds lodged in an Australian quarter, in Australian dollars. Nothing is compared across states or countries.
118
+
119
+ - **New Zealand**, by council (territorial authority) or region, as MBIE names them ("Wellington City", "Auckland",
120
+ "Canterbury Region"; "Wellington, NZ" lists the city and the region): MBIE Tenancy Services' median weekly rent of
121
+ the bonds for private tenancies that began in the latest month, with its geometric mean, quartiles and bond count,
122
+ CC BY 3.0 NZ. Every amount is in New Zealand dollars, written NZ$, in fields ending `_nzd`; MBIE calls the data
123
+ provisional, so no change on a year is given. A figure on fewer than 30 bonds is a small sample; MBIE gives none
124
+ below 5. The answer carries `country: "NZ"`, `currency: "NZD"`, `provisional: true`, `nz_place`, and the place's
125
+ page at tools.dwelldelta.com.au/area/nz/.
126
+ - **The ACT, the Northern Territory and Tasmania**, by postcode, or the state or its capital alone: interim ABS cover,
127
+ CC BY 4.0 - the median weekly rent paid in the postal area on Census night, 10 August 2021 (leases new and old,
128
+ every landlord), the capital's CPI rents index and ABS median sale prices, each with its period. None is a median
129
+ of new bonds or today's rent. A postal area under half privately rented carries "Mostly not private rentals: do not
130
+ quote as a market rent."; a small Census sample is marked; where fewer than 10 households stated their rent there is
131
+ no dollar median, only "Too few households for a median (N)". The answer carries `interim: true`, `census_period`,
132
+ `postal_area`, `cpi_rents` and `dwelling_prices`, and the state's page (/area/act/, /area/nt/, /area/tas/).
133
+ - `rent_check` places no rent against either: not an Australian-dollar rent against NZ$ figures, and not against a
134
+ 2021 Census median.
135
+
113
136
  ## What an agent gets back
114
137
 
115
138
  Every call returns text to quote and a structured result: the figures, plus `sources` (each with its licence and
@@ -134,6 +157,37 @@ copy city by city (each city's series starts no later and ends no earlier than i
134
157
  later than the current one; otherwise, or with `DWELLDELTA_OFFLINE=1`, the bundled copy answers.
135
158
  `data_as_of` and the `Cite:` line's period say which month the answer runs to.
136
159
 
160
+ ### rent_check reads common input shapes (from 0.13.0)
161
+
162
+ - `city` is read in any case ("sydney"), as "Greater Sydney", or as "Sydney, NSW" (the state must be the city's
163
+ own). A state or territory alone ("NSW", "Victoria") is refused, never read as its capital: the ABS rents index
164
+ exists only for capitals, so a regional tenant's "NSW" is not Sydney's index. The refusal names the capital, and
165
+ where local rents are held, says to give `place` for the local rent check.
166
+ - `current_rent` and `proposed_rent` are read from text as well as numbers: "550", "$550", "A$550", "550.00",
167
+ "$1,250", "550 pw", "550 per week". A range ("550-600"), a rent per month, fortnight or year, a decimal comma and
168
+ anything else are refused.
169
+ - `lease_start` is read as "2024-03", "2024-03-01" (a real date; its month is used) or "March 2024" / "Mar 2024".
170
+ - Each refusal names the field and every form that is read. The handler receives the same canonical values as
171
+ before, and tools/list declares the same JSON Schema, byte for byte: 31,159 characters over stdio, 28,451 hosted.
172
+
173
+ ### A name in several NSW postcodes, and a registry icon (from 0.13.0)
174
+
175
+ - `area_rents` (state NSW), `property_rents` and `rent_check`'s local mode refuse an NSW name the NSW suburb list
176
+ places in more than one postcode as a name held in more than one state is refused, all three in the same words:
177
+ `"Alison" is held in more than one postcode: 2259, 2420`, every postcode listed and none chosen. The next step's
178
+ example is one postcode alone, offered only where DCJ's file publishes a median for it, so each of the three answers
179
+ it with a figure: of those, the one with the most new bonds (a banded count by its lower end; a tie by the list's
180
+ order). A postcode with no median or no row is listed and said to have no figure; where none has a median, none is
181
+ offered and the next step says so. Until 0.13.0 the refusal said `No New South Wales postcode matches "Alison"` and
182
+ named the postcodes only in its next step. Refusals are text; no field and no tool description changes, so
183
+ tools/list is as in 0.12.0.
184
+ - The registry entry (`server.json`) lists an icon: https://tools.dwelldelta.com.au/mcp/icon-256.png, the DwellDelta
185
+ mark, 256x256 PNG.
186
+ - The hosted server answers a POST whose Accept allows JSON (`application/json`, `application/*` or `*/*`) but does
187
+ not list `text/event-stream`, in JSON as always; it was refused 406. An Accept that does not allow JSON is still 406.
188
+ - The hosted server's log lines name four more MCP methods (`server/discover`, `resources/read`, `prompts/get`,
189
+ `subscriptions/listen`) where they said "other". No field is added; the line holds what the privacy notice says.
190
+
137
191
  ### Answers on the first call, pages and citations (from 0.12.0)
138
192
 
139
193
  - A NSW suburb's name is answered on the first call where the NSW suburb list (NSW Spatial Services, CC BY 3.0 AU)
@@ -195,6 +195,56 @@ export function nswResolve(wanted, suburbs, feed) {
195
195
  `postcode, not ${suburb} alone.` };
196
196
  }
197
197
 
198
+ /** A name and its "Mt"/"Mount" twin: the files spell it one way ("Mount Victoria"), an asker often the other. */
199
+ export const spellings = (name) => {
200
+ const n = norm(name);
201
+ return new Set([n, n.replace(/\bmt\.?\s/g, "mount "), n.replace(/\bmount\s/g, "mt ")]);
202
+ };
203
+
204
+ /**
205
+ * An NSW name the suburb list places in more than one postcode ("Alison": 2259 and 2420), as a ToolError that says so
206
+ * and lists every one, none chosen - or null for a name in one postcode or none (0.13.0). Until then area_rents said
207
+ * "No New South Wales postcode matches "Alison"" and named the postcodes only in its next step. One check for the
208
+ * three tools that take an NSW name: area_rents here, and property_rents and rent_check's local mode through
209
+ * resolvePlace (place-tool.mjs), so all three refuse in the same words.
210
+ *
211
+ * The next step's example is one postcode alone, and only one whose row in DCJ's file has a published median, so
212
+ * that each of the three tools answers it with a figure (the cold review of #80: offering the first postcode with a
213
+ * row sent rent_check to a postcode with no median for 9 of 79 names). Of those, the RULE is: the most new bonds; a
214
+ * count DCJ gives only as a band ("10 to 30") ranks by its lower end; a tie goes to the list's order. A postcode with
215
+ * a row but no median, or with no row, is listed and said to have no figure, and never offered; where no postcode has
216
+ * a median, none is offered and the next step says so.
217
+ */
218
+ export const medianOf = (r) => (isRecord(r) && typeof r.median_weekly_rent_aud === "number" &&
219
+ Number.isFinite(r.median_weekly_rent_aud) && r.median_weekly_rent_aud > 0 ? r.median_weekly_rent_aud : null);
220
+ const bondsOf = (r) => (typeof r.new_bonds === "number" && Number.isFinite(r.new_bonds) ? r.new_bonds
221
+ : Number(/^\d+/.exec(String(r.new_bonds_band ?? r.new_bonds_range ?? ""))?.[0] ?? 0));
222
+ const postcodes = (list) => `${list.length > 1 ? "postcodes" : "postcode"} ${list.join(", ")}`;
223
+
224
+ export function nswSeveralPostcodes(name, suburbs, feed) {
225
+ const want = spellings(name);
226
+ const exact = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(String(s))).filter((m) => m && want.has(norm(m[1])));
227
+ const codes = [...new Set(exact.map((m) => m[2]))];
228
+ if (codes.length < 2) return null;
229
+ const rows = new Map((feed?.areas ?? []).filter(isRecord).map((r) => [String(r.area), r]));
230
+ const priced = codes.filter((p) => medianOf(rows.get(p)) != null);
231
+ const unpriced = codes.filter((p) => rows.has(p) && medianOf(rows.get(p)) == null);
232
+ const rowless = codes.filter((p) => !rows.has(p));
233
+ const offer = priced.reduce((best, p) => (bondsOf(rows.get(p)) > bondsOf(rows.get(best)) ? p : best), priced[0]);
234
+ const next = offer
235
+ ? `Ask again with one postcode, e.g. ${JSON.stringify(offer)} (of those with a published median, the one with the ` +
236
+ "most new bonds), or ask which one is meant. No one of them is chosen here; a postcode's figure is for the whole " +
237
+ `postcode, not ${exact[0][1]} alone.` +
238
+ (unpriced.length ? ` DCJ's file publishes no median for ${postcodes(unpriced)}, so ` +
239
+ `${unpriced.length > 1 ? "they have" : "it has"} no figure here.` : "") +
240
+ (rowless.length ? ` DCJ's rents file has no row for ${postcodes(rowless)}, so ` +
241
+ `${rowless.length > 1 ? "they have" : "it has"} no figure here.` : "")
242
+ : "No one of them is chosen here, and none is offered: DCJ's file publishes no median for any of them, so none " +
243
+ "has a figure here.";
244
+ return new ToolError(`${JSON.stringify(String(name).trim())} is held in more than one postcode: ${codes.join(", ")} ` +
245
+ `(${SUBURB_LIST_CREDIT}).`, next);
246
+ }
247
+
198
248
  /** The note when a resolved suburb's name is also a council's: the council's figure is a call of its own. */
199
249
  export function councilToo(wanted, councils) {
200
250
  const c = (councils ?? []).filter(isRecord).find((r) => norm(r.council) === norm(wanted));
@@ -234,6 +284,9 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
234
284
  areas = match(feed.areas, "area", resolved.postcode);
235
285
  resolved.note += council == null || !String(council).trim() ? councilToo(area, feed.councils) : "";
236
286
  }
287
+ // A name in several postcodes is refused as such, never as a name with no match (0.13.0).
288
+ const several = resolved ? null : nswSeveralPostcodes(area, nswSuburbs, feed);
289
+ if (several) throw several;
237
290
  }
238
291
  if (!areas.length) {
239
292
  const named = state === "NSW" ? nswPostcodes(area, nswSuburbs, feed) : [];
package/cover-tool.mjs ADDED
@@ -0,0 +1,357 @@
1
+ /**
2
+ * New Zealand, and the ACT, the Northern Territory and Tasmania (0.14.0; owner, 2026-11-03: "make the MCP tools serve
3
+ * NZ or ACT/NT/TAS as well"). Answered through property_rents (place-tool.mjs), never area_rents: area_rents' state
4
+ * enum, its median_weekly_rent_aud, new_bonds and quarter fields and its words all mean a median of new bonds lodged in
5
+ * an Australian quarter, in Australian dollars, and a released field keeps its meaning. These answers carry fields of
6
+ * their own instead.
7
+ *
8
+ * - New Zealand: market/nz-rents.json, MBIE Tenancy Services' bonds for the tenancies that began in one month, by
9
+ * territorial authority (council) and region, CC BY 3.0 NZ. Every amount is New Zealand dollars - fields ending
10
+ * _nzd, written NZ$ - never AUD; MBIE calls the data provisional, so no change on a year is given (the file nulls
11
+ * it); and nothing is set beside an Australian figure.
12
+ * - The ACT, the NT and Tasmania: market/{act,nt,tas}-rents-interim.json, interim ABS cover, CC BY 4.0: the median
13
+ * weekly rent PAID in each postal area on Census night 2021, the capital's CPI rents index and ABS median sale
14
+ * prices. None of it is a median of new bonds, and no answer calls it one; every figure carries its period; the
15
+ * file's flags are said in its words (tools/render-area-pages.mjs INTERIM_FLAGS, held to these by
16
+ * tests/mcp-pages.test.mjs); a postal area where fewer than 10 households stated their rent gets no dollar
17
+ * median, only "Too few households for a median (N)", as the site's page.
18
+ *
19
+ * Loaded like the state rents feeds: DWELLDELTA_STATE_RENTS_DIR where it holds the file, else the owner's live store,
20
+ * else the published file (fetched once at start; nothing about the user or the question is sent) where well formed
21
+ * and not older than the bundled copy, else the copy bundled at pack time. DWELLDELTA_OFFLINE=1 never fetches.
22
+ */
23
+ import { existsSync } from "node:fs";
24
+ import { fileURLToPath } from "node:url";
25
+ import { dirname, join } from "node:path";
26
+ import { envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS, feedSource, citeLine, isRecord, passes, readChecked, quiet,
27
+ warnPublished, fromCopy } from "./tools.mjs";
28
+ import { SITE, slug } from "./pages.mjs";
29
+
30
+ const HERE = dirname(fileURLToPath(import.meta.url));
31
+ const LIVE_DIR = join(HERE, "..", "..", "dwelldelta-data", "market");
32
+ const BUNDLED_DIR = join(HERE, "vendor");
33
+ const PUBLISHED_BASE = "https://tools.dwelldelta.com.au/market/";
34
+ export const NZ_FILE = "nz-rents.json";
35
+ export const INTERIM = {
36
+ ACT: { file: "act-rents-interim.json", name: "the Australian Capital Territory", page: "act" },
37
+ NT: { file: "nt-rents-interim.json", name: "the Northern Territory", page: "nt" },
38
+ TAS: { file: "tas-rents-interim.json", name: "Tasmania", page: "tas" },
39
+ };
40
+ /** The site's own rules (tools/render-area-pages.mjs NZ_MIN_BONDS, NZ_SMALL, INTERIM_FEW, INTERIM_FLAGS). */
41
+ export const NZ_MIN_BONDS = 5;
42
+ export const NZ_SMALL = 30;
43
+ export const INTERIM_FEW = 10;
44
+ export const INTERIM_FLAGS = { mostly: "Mostly not private rentals: do not quote as a market rent.",
45
+ small: "Small Census sample (under 30 households): do not quote as typical of the area." };
46
+ /** Keys a state rents feed gives a meaning of its own (render-area-pages.mjs BOND_FIELDS): no interim answer has one. */
47
+ export const BOND_FIELDS = ["median_weekly_rent_aud", "first_quartile_aud", "third_quartile_aud", "new_bonds", "new_bonds_band",
48
+ "new_bonds_range", "change_pct", "year_ago_median_aud", "small_sample", "withheld", "quarter", "compared_with",
49
+ "state_total", "areas", "councils", "regions", "area_kind"];
50
+
51
+ const ym = (v) => /^\d{4}-\d{2}$/.test(v ?? "");
52
+ const hasAud = (f) => /"[a-z_]*_aud"\s*:/.test(JSON.stringify(f));
53
+ /** A New Zealand file this code may answer from: NZD, provisional with no change given, and no field in AUD. */
54
+ export const nzWellFormed = (f) => isRecord(f) && f.country === "NZ" && f.currency === "NZD" && ym(f.month)
55
+ && typeof f.month_words === "string" && Array.isArray(f.areas) && f.areas.length > 0 && Array.isArray(f.regions)
56
+ && Array.isArray(f.limits) && f.licence === "CC BY 3.0 NZ" && Boolean(f.attribution) && f.provisional === true
57
+ && f.compared_with == null && !hasAud(f)
58
+ && [...f.areas, ...f.regions].every((r) => !isRecord(r) || (r.change_pct == null && r.year_ago_median_nzd == null));
59
+ /** An interim file this code may answer from: its own state, interim, and no field a rents feed gives a bond meaning. */
60
+ const bondKeys = (n) => (Array.isArray(n) ? n.flatMap(bondKeys) : isRecord(n)
61
+ ? Object.entries(n).flatMap(([k, v]) => [...(BOND_FIELDS.includes(k) ? [k] : []), ...bondKeys(v)]) : []);
62
+ export const interimWellFormed = (f, state) => isRecord(f) && f.state === state && f.interim === true
63
+ && f.measure === "interim_rent_cover" && Array.isArray(f.limits) && Boolean(f.attribution) && f.licence === "CC BY 4.0"
64
+ && isRecord(f.census_2021) && /^\d{4}-\d{2}-\d{2}$/.test(f.census_2021.census_date ?? "")
65
+ && Array.isArray(f.census_2021.postcodes) && f.census_2021.postcodes.length > 0
66
+ && isRecord(f.cpi_rents) && ym(f.cpi_rents.latest_month) && isRecord(f.dwelling_prices)
67
+ && Array.isArray(f.dwelling_prices.places) && bondKeys(f).length === 0;
68
+ /** Which of two copies is newer: the month (NZ) or the day it was built (interim). */
69
+ const age = (f) => String(f?.month ?? f?.built ?? "");
70
+
71
+ async function loadCover(file, check, what, { env = process.env, fetchImpl = globalThis.fetch, liveDir = LIVE_DIR,
72
+ bundledDir = BUNDLED_DIR, warn = quiet } = {}) {
73
+ const read = (path, variable) => readChecked(path, check, what, variable, warn);
74
+ // A folder named by the variable that lacks this file (one made before 0.14.0) falls through to the others.
75
+ if (env.DWELLDELTA_STATE_RENTS_DIR && existsSync(join(env.DWELLDELTA_STATE_RENTS_DIR, file))) {
76
+ return fromCopy(await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file), "DWELLDELTA_STATE_RENTS_DIR"), "feed", "env");
77
+ }
78
+ if (existsSync(join(liveDir, file))) return fromCopy(await read(join(liveDir, file)), "feed", "live");
79
+ const shipped = (await read(join(bundledDir, file))).copy;
80
+ if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
81
+ try {
82
+ const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
83
+ const got = res.ok ? await res.json() : null;
84
+ if (got != null && !passes(check, got)) warnPublished(warn, what, PUBLISHED_BASE + file, shipped);
85
+ if (passes(check, got) && (!shipped || age(got) >= age(shipped))) return { feed: got, origin: "published" };
86
+ } catch {
87
+ // Offline, blocked or slow: the bundled copy answers, and its period says how current it is.
88
+ }
89
+ }
90
+ return { feed: shipped, origin: shipped ? "bundled" : null };
91
+ }
92
+
93
+ /**
94
+ * { nz, interim: { ACT, NT, TAS }, refused }: each a feed with its origin, or null; refused names, by key (NZ, ACT, NT,
95
+ * TAS), a copy that failed its check, so a tool can say so rather than that there is none. The four are asked for
96
+ * together (Promise.all), so the stdio server's start waits for one fetch timeout at most, not four (the cold review).
97
+ */
98
+ export async function loadCoverFeeds(opts = {}) {
99
+ const withOrigin = (l) => (l.feed ? { ...l.feed, origin: l.origin } : null);
100
+ const states = Object.keys(INTERIM);
101
+ const [nz, ...each] = await Promise.all([
102
+ loadCover(NZ_FILE, nzWellFormed, "the New Zealand rents feed", opts),
103
+ ...states.map((state) => loadCover(INTERIM[state].file, (f) => interimWellFormed(f, state),
104
+ `the ${state} interim rent cover file`, opts)),
105
+ ]);
106
+ const refused = Object.fromEntries([["NZ", nz], ...states.map((s, i) => [s, each[i]])]
107
+ .filter(([, l]) => l.refused).map(([k, l]) => [k, l.refused]));
108
+ return { nz: withOrigin(nz), interim: Object.fromEntries(states.map((s, i) => [s, withOrigin(each[i])])), refused };
109
+ }
110
+
111
+ // --- New Zealand -----------------------------------------------------------------------------------------------------
112
+
113
+ const fold = (s) => String(s ?? "").normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/[’']/g, "'")
114
+ .trim().replace(/\s+/g, " ").toLowerCase();
115
+ const shortName = (n) => n.replace(/ (city|district|region)$/i, "");
116
+
117
+ /** Every New Zealand place row: { kind: "council" | "region", name, row }. */
118
+ export function nzPlaces(feed) {
119
+ if (!feed) return [];
120
+ return [...feed.areas.filter(isRecord).map((r) => ({ kind: "council", name: String(r.area), row: r })),
121
+ ...feed.regions.filter(isRecord).map((r) => ({ kind: "region", name: String(r.region), row: r }))];
122
+ }
123
+ /**
124
+ * The New Zealand places a name is: by its full name as MBIE gives it ("Wellington City", "Auckland"), always; by its
125
+ * name without "City", "District" or "Region" ("Wellington") only where the asker said New Zealand, and then only if
126
+ * no full name matched - "Wellington" alone is the NSW postcode it has always been.
127
+ */
128
+ export function nzMatches(name, feed, saidNz = false) {
129
+ const want = fold(name);
130
+ if (!want) return [];
131
+ const places = nzPlaces(feed);
132
+ const exact = places.filter((p) => fold(p.name) === want);
133
+ if (exact.length || !saidNz) return exact;
134
+ return places.filter((p) => fold(shortName(p.name)) === want);
135
+ }
136
+
137
+ /** The site's addresses for New Zealand (render-area-pages.mjs nzPlaces): given across every row, by name alone. */
138
+ const nzMemo = new WeakMap();
139
+ function nzAddresses(feed) {
140
+ if (nzMemo.has(feed)) return nzMemo.get(feed);
141
+ const rows = nzPlaces(feed).map((p) => ({ ...p, slug: slug(p.name) }));
142
+ const seen = new Set(), out = new Map();
143
+ for (const p of [...rows].sort((a, b) => (a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
144
+ if (!p.slug) continue;
145
+ let s = p.slug;
146
+ for (let n = 2; seen.has(s); n++) s = `${p.slug}-${n}`;
147
+ seen.add(s);
148
+ out.set(`${p.kind}:${p.name}`, s);
149
+ }
150
+ nzMemo.set(feed, out);
151
+ return out;
152
+ }
153
+ const NZ_FIGURES = ["median_weekly_rent_nzd", "geometric_mean_weekly_rent_nzd", "lower_quartile_weekly_rent_nzd",
154
+ "upper_quartile_weekly_rent_nzd", "new_bonds", "active_bonds"];
155
+ export const nzShown = (r) => isRecord(r) && Number.isFinite(r.median_weekly_rent_nzd) && Number.isFinite(r.new_bonds)
156
+ && r.new_bonds >= NZ_MIN_BONDS;
157
+ export const nzSmall = (r) => r.small_sample === true || !(r.new_bonds >= NZ_SMALL);
158
+ /**
159
+ * A place's page, or null where the site builds none: a place with a figure it may show. A region whose every figure is
160
+ * a council's, and whose name the council's begins with (Auckland), has the council's page, which stands for both.
161
+ */
162
+ export function nzPage(feed, place) {
163
+ if (!nzShown(place.row)) return null;
164
+ if (place.kind === "region") {
165
+ const base = place.name.replace(/ Region$/, "");
166
+ const twin = nzPlaces(feed).filter((p) => p.kind === "council" && nzShown(p.row))
167
+ .sort((a, b) => a.name.localeCompare(b.name, "en-NZ"))
168
+ .find((c) => c.name.startsWith(base) && NZ_FIGURES.every((k) => c.row[k] === place.row[k]));
169
+ if (twin) return nzPage(feed, twin);
170
+ }
171
+ const s = nzAddresses(feed).get(`${place.kind}:${place.name}`);
172
+ return s ? `${SITE}/area/nz/${s}/` : null;
173
+ }
174
+
175
+ /** New Zealand dollars, always marked: NZ$650; NZ$472.50. Never a bare $. */
176
+ export const nzd = (v) => {
177
+ const n = Number(v);
178
+ return `NZ$${n.toLocaleString("en-NZ", Number.isInteger(n) ? {} : { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
179
+ };
180
+ /** The file's own words, with any amount marked as New Zealand dollars. */
181
+ const nzWords = (s) => String(s).replace(/(^|[^A-Za-z])\$(?=\d)/g, (m, before) => `${before}NZ$`);
182
+ const MBIE_PAGE = (f) => f.source_notice ?? null;
183
+
184
+ /** One New Zealand place's answer: MBIE's month, in NZ$, provisional, with no change on a year. */
185
+ export function nzResult(place, feed, now = new Date()) {
186
+ const r = place.row;
187
+ const kind = place.kind === "region" ? "region" : "territorial authority";
188
+ const src = feedSource(feed, PUBLISHED_BASE + NZ_FILE, feed.month, { noticeIsData: true });
189
+ const env = envelope({ sources: [src], dataAsOf: feed.month, origin: feed.origin ?? null }, now);
190
+ const shown = nzShown(r);
191
+ const small = shown && nzSmall(r);
192
+ const url = nzPage(feed, place);
193
+ const cite = shown ? `Median weekly rent of new bonds, ${place.name} (${kind}), New Zealand, ${feed.month_words} ` +
194
+ `(provisional). Source: ${feed.rights_holder}, ${feed.licence}. Via DwellDelta: ${url ?? `${SITE}/area/nz/`}` : null;
195
+ const money = (k) => (Number.isFinite(r[k]) ? nzd(r[k]) : null);
196
+ const figure = shown
197
+ ? `${place.name} (${kind}), tenancies begun in ${feed.month_words}: median ${nzd(r.median_weekly_rent_nzd)} a week, ` +
198
+ `from ${Number(r.new_bonds).toLocaleString("en-NZ")} new bonds` +
199
+ (money("geometric_mean_weekly_rent_nzd") ? `; geometric mean ${money("geometric_mean_weekly_rent_nzd")}` : "") +
200
+ (money("lower_quartile_weekly_rent_nzd") && money("upper_quartile_weekly_rent_nzd")
201
+ ? `; MBIE's lower and upper quartile rents ${money("lower_quartile_weekly_rent_nzd")} and ` +
202
+ `${money("upper_quartile_weekly_rent_nzd")}` : "") +
203
+ `.${small ? ` Small sample (under ${NZ_SMALL} new bonds): treat with caution.` : ""}`
204
+ : `${place.name} (${kind}), ${feed.month_words}: no figure. MBIE publishes none where fewer than ${NZ_MIN_BONDS} ` +
205
+ "bonds were lodged.";
206
+ const text = [
207
+ `New Zealand rents, in New Zealand dollars (NZ$), not Australian dollars: MBIE's median weekly rent of the bonds ` +
208
+ // What the code knows (the re-review of #91): a bundled or offline copy can be older than MBIE's latest month.
209
+ `for private tenancies that began in ${feed.month_words}. It is the latest month in DwellDelta's copy of MBIE's ` +
210
+ "data, which MBIE can revise as bonds lodged late are recorded. " +
211
+ `Provisional: ${nzWords(feed.change_withheld ?? "no change on a year is given")}.`,
212
+ "",
213
+ figure,
214
+ "These are rents of new bonds lodged with Tenancy Services, not advertised rents and not what sitting tenants " +
215
+ "pay. Nothing here is set beside an Australian figure.",
216
+ "",
217
+ "Limits:",
218
+ ...feed.limits.map((l) => "- " + nzWords(l)),
219
+ "",
220
+ ...(url ? [`Page: ${url}`] : []),
221
+ ...(cite ? [`Cite as: ${cite}`] : []),
222
+ /^Source:/.test(feed.attribution) ? feed.attribution : `Source: ${feed.attribution}`,
223
+ citeLine({ source: feed.source, period: `${feed.month_words} (provisional)`, licence: feed.licence,
224
+ n: shown ? `${r.new_bonds} new bonds` : `fewer than ${NZ_MIN_BONDS} new bonds (withheld)`,
225
+ url: env.sources[0].source_url ?? MBIE_PAGE(feed), feedUrl: PUBLISHED_BASE + NZ_FILE, stale: false }),
226
+ FOOTER,
227
+ ].join("\n");
228
+ const row = Object.fromEntries(Object.entries(r).filter(([k]) => k !== "area" && k !== "region"));
229
+ return {
230
+ text,
231
+ structured: { ...env, country: "NZ", currency: "NZD", unit: feed.unit ?? "NZD per week", provisional: true,
232
+ month: feed.month, month_words: feed.month_words, change_withheld: feed.change_withheld ?? null,
233
+ nz_place: { name: place.name, kind: place.kind === "region" ? "region" : "territorial_authority", ...row,
234
+ shown, small_sample: small },
235
+ limits: feed.limits.filter((l) => typeof l === "string"), page_url: url, cite_as: cite },
236
+ };
237
+ }
238
+
239
+ // --- The ACT, the Northern Territory and Tasmania: interim ABS cover ----------------------------------------------------
240
+
241
+ const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October",
242
+ "November", "December"];
243
+ const longDate = (iso) => `${Number(iso.slice(8, 10))} ${MONTHS[Number(iso.slice(5, 7)) - 1]} ${iso.slice(0, 4)}`;
244
+ const longMonth = (ym) => `${MONTHS[Number(String(ym).slice(5, 7)) - 1]} ${String(ym).slice(0, 4)}`;
245
+ const aud = (v) => `$${Number(v).toLocaleString("en-AU")}`;
246
+ const signed = (v) => `${v >= 0 ? "+" : ""}${v}%`;
247
+ export const interimPage = (state) => `${SITE}/area/${INTERIM[state].page}/`;
248
+ /** "Census night, 10 August 2021": the period every Census figure carries. */
249
+ export const censusPeriod = (feed) => `Census night, ${longDate(feed.census_2021.census_date)}`;
250
+
251
+ /** The flags a postal area carries, in the site's words. */
252
+ export function interimFlags(r) {
253
+ const out = [];
254
+ if (r.mostly_not_private_rentals === true) out.push(INTERIM_FLAGS.mostly);
255
+ if (r.small_census_sample) out.push(INTERIM_FLAGS.small);
256
+ if (r.census_2021_median_weekly_rent_aud == null) {
257
+ const why = r.census_2021_no_median ?? "the ABS publishes no median rent for this postal area";
258
+ out.push(`${why[0].toUpperCase()}${why.slice(1)}.`);
259
+ } else if (Number.isFinite(r.census_2021_renting_households_rent_stated) && r.census_2021_renting_households_rent_stated < INTERIM_FEW) {
260
+ out.push(`Too few households for a median (${r.census_2021_renting_households_rent_stated}).`);
261
+ }
262
+ if (r.crosses_border) out.push(`Crosses a border: ${r.crosses_border}.`);
263
+ return out;
264
+ }
265
+ const interimShown = (r) => r.census_2021_median_weekly_rent_aud != null
266
+ && !(Number.isFinite(r.census_2021_renting_households_rent_stated) && r.census_2021_renting_households_rent_stated < INTERIM_FEW);
267
+
268
+ /**
269
+ * One interim answer: a postal area's 2021 Census rent (postcode given), or none (the state or its capital asked), with
270
+ * the capital's rents index and the sale medians, each with its period. Never a bond median, never another state.
271
+ */
272
+ export function interimResult(state, feed, postcode = null, now = new Date()) {
273
+ const info = INTERIM[state];
274
+ const c = feed.census_2021, cpi = feed.cpi_rents, px = feed.dwelling_prices;
275
+ const census = censusPeriod(feed);
276
+ const row = postcode ? c.postcodes.filter(isRecord).find((r) => r.postcode === postcode) : null;
277
+ if (postcode && !row) {
278
+ throw new ToolError(`Postcode ${postcode} is in ${info.name}, but the ABS's 2021 Census has no postal area ${postcode} ` +
279
+ "in DwellDelta's interim file (a PO Box or other non-residential postcode has none).",
280
+ `Give a residential postcode, or ${JSON.stringify(state)} alone for ${cpi.city}'s rents index and the sale prices. ` +
281
+ `Every postal area held is listed at ${interimPage(state)}`);
282
+ }
283
+ const src = (source, period) => ({ ...feedSource(feed, PUBLISHED_BASE + info.file, period), source });
284
+ // "Rest of NT" as a sentence says it: "the rest of the Northern Territory" (capitalised to open a line).
285
+ const regionWords = (region, opening = true) => (/^Rest of /.test(region)
286
+ ? `${opening ? "The" : "the"} rest of ${info.name}` : region);
287
+ const env = envelope({ sources: [src(c.source, census), src(cpi.source, cpi.period), src(px.source, px.period)],
288
+ dataAsOf: cpi.latest_month, origin: feed.origin ?? null }, now);
289
+ const flags = row ? interimFlags(row) : [];
290
+ const shown = row ? interimShown(row) : false;
291
+ const n = (v) => Number(v).toLocaleString("en-AU");
292
+ const censusLine = !row
293
+ ? `2021 Census rents are by postal area (${c.postcodes.length} in this file): give a postcode for one.`
294
+ : row.census_2021_median_weekly_rent_aud == null
295
+ ? `Postal area ${postcode}, ${census}: no median.`
296
+ : !shown
297
+ ? `Postal area ${postcode}, ${census}: Too few households for a median (${row.census_2021_renting_households_rent_stated}).`
298
+ : `Postal area ${postcode}, ${census}: median weekly rent paid ${aud(row.census_2021_median_weekly_rent_aud)}` +
299
+ `${row.mostly_not_private_rentals === true ? " (not a market rent)" : ""}, by the ` +
300
+ // The share's base is the households whose landlord type was stated (dwelldelta-local
301
+ // build_interim_rents_feeds.py: the sum of G40's five landlord-type cells), not those who stated their rent.
302
+ `${n(row.census_2021_renting_households_rent_stated)} renting households who stated their rent, on leases new ` +
303
+ "and old, every landlord type, social housing included" + (Number.isFinite(row.census_2021_private_landlord_share_pct)
304
+ ? `; ${row.census_2021_private_landlord_share_pct}% of those whose landlord type was stated rented from an ` +
305
+ "agent or a private landlord." : ".");
306
+ const only = px.places.length > 1 ? ` It is for ${cpi.city} only.` : "";
307
+ const prices = px.places.filter(isRecord).map((p) => {
308
+ const l = p.latest ?? {};
309
+ const part = (what, price, count) => (Number.isFinite(l[price]) ? `${what} ${aud(l[price])}` +
310
+ (Number.isFinite(l[count]) ? ` (${n(l[count])} transfers)` : "") : `${what}: none published`);
311
+ return `- ${regionWords(p.region)}: ${part("established houses", "median_price_established_houses_aud", "established_house_transfers")}; ` +
312
+ `${part("attached dwellings", "median_price_attached_dwellings_aud", "attached_dwelling_transfers")}.`;
313
+ });
314
+ const placeNames = px.places.filter(isRecord).map((p) => regionWords(p.region, false));
315
+ const priceHeading = `Median sale prices for ${placeNames.join(" and ")} as a whole (ABS; sales, not rents; not for ` +
316
+ `${postcode ? `postal area ${postcode}` : "any suburb or postcode"}), ${px.period}; the ABS revises the latest ` +
317
+ "quarter:";
318
+ const cite = `Interim rent cover, ${info.name.replace(/^the /, "")}: 2021 Census median weekly rents by postal area ` +
319
+ `(${census}), the ABS rents index for ${cpi.city} (${cpi.year_change_period}) and ABS median sale prices ` +
320
+ `(${px.period}). Source: ${feed.rights_holder}, ${feed.licence}. Via DwellDelta: ${interimPage(state)}`;
321
+ const text = [
322
+ `Interim cover for ${info.name}, from ABS data. DwellDelta holds no rents from new bonds for ${info.name}: none ` +
323
+ "of these figures is a median of new bonds, and none is today's rent. Do not carry the 2021 rent forward with " +
324
+ // The ABS index is far older than this file's monthly series; the site's renderer says the same (re-review of #91).
325
+ `the rents index (the monthly series in this file starts in ${longMonth(cpi.first_month)}, is for ${cpi.city} as a ` +
326
+ "whole, and covers all " +
327
+ "tenancies), and do not divide a rent by a sale price: no current rent and no rental yield can be read from these " +
328
+ "figures.",
329
+ "",
330
+ censusLine,
331
+ ...flags.filter((f) => !/^Too few households/.test(f)).map((f) => ` ${f}`),
332
+ `${cpi.city}'s rents index (ABS CPI: the change in rents paid for the same homes, on new and continuing leases, ` +
333
+ "private and public housing, net of Rent Assistance; not a rent): " +
334
+ `${signed(cpi.year_change_pct)} from ${cpi.year_change_period}, ${signed(cpi.change_since_first_month_pct)} from ` +
335
+ `${cpi.change_since_first_month_period}.${only}`,
336
+ priceHeading,
337
+ ...prices,
338
+ "Nothing here is set beside another state's figures or New Zealand's.",
339
+ "",
340
+ "Limits:",
341
+ ...feed.limits.map((l) => "- " + l),
342
+ "",
343
+ `Page: ${interimPage(state)}`,
344
+ `Cite as: ${cite}`,
345
+ `Source: ${feed.attribution}`,
346
+ FOOTER,
347
+ ].join("\n");
348
+ const pa = row ? { ...row, census_2021_median_weekly_rent_aud: shown ? row.census_2021_median_weekly_rent_aud : null,
349
+ median_shown: shown, flags } : null;
350
+ return {
351
+ text,
352
+ structured: { ...env, interim: true, measure: "interim_rent_cover", state_name: info.name.replace(/^the /, ""),
353
+ periods: feed.periods ?? null, census_period: census, postal_area: pa,
354
+ cpi_rents: cpi, dwelling_prices: px, limits: feed.limits.filter((l) => typeof l === "string"),
355
+ page_url: interimPage(state), cite_as: cite },
356
+ };
357
+ }
@@ -275,7 +275,14 @@ export const OUTPUT_SCHEMAS = {
275
275
 
276
276
  // property_rents (0.12.0, place-tool.mjs): the answer of area_rents or vic_rents for the state that holds the
277
277
  // place, as that tool gives it (allowed as every unnamed key is), and resolved_state and resolved_place: the state
278
- // and the place in words the question was read as.
278
+ // and the place in words the question was read as. From 0.14.0 (cover-tool.mjs), two more kinds of answer, in keys
279
+ // of their own, allowed as every unnamed key is: New Zealand (resolved_state "NZ"; country "NZ", currency "NZD",
280
+ // provisional true, month, nz_place with MBIE's fields ending _nzd), and interim ABS cover (resolved_state ACT, NT
281
+ // or TAS; interim true, census_period, postal_area with the file's census_2021_* fields and its flags, cpi_rents,
282
+ // dwelling_prices). At the top level neither carries a key the new-bond answers give a meaning (median_weekly_rent_aud,
283
+ // new_bonds, quarter...); nz_place nests MBIE's own row, whose new_bonds, change_pct and small_sample are MBIE's (in
284
+ // NZ$, change_pct null while provisional), and the interim answer carries none of them anywhere. No released field
285
+ // changes meaning: the new answers are told apart by resolved_state and by country or interim.
279
286
  property_rents: obj({ ...envelope, resolved_state: str, resolved_place: str }),
280
287
 
281
288
  // Two answers: the consent text and token (stored: false), or the deletion code once the rent is added (stored:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dwelldelta-mcp",
3
- "version": "0.12.0",
4
- "description": "Australian rents by area for five states, asked by place with no state, a rent placed against its local median, NSW median sale prices, an ABS rents index check, and sourced property and lending indicators, for AI agents.",
3
+ "version": "0.14.0",
4
+ "description": "Australian rents by area for five states, New Zealand rents by council and region and interim ABS cover for the ACT, NT and Tasmania, asked by place with no state, a rent placed against its local median, NSW median sale prices, an ABS rents index check, and sourced property and lending indicators, for AI agents.",
5
5
  "mcpName": "au.com.dwelldelta/dwelldelta",
6
6
  "license": "MIT",
7
7
  "homepage": "https://dwelldelta.com.au/",
@@ -29,6 +29,7 @@
29
29
  "sale-prices-tool.mjs",
30
30
  "pages.mjs",
31
31
  "place-tool.mjs",
32
+ "cover-tool.mjs",
32
33
  "vendor/",
33
34
  "LICENSE",
34
35
  "README.md"