domain-hound 0.1.7 → 0.1.8

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.
@@ -0,0 +1,332 @@
1
+ // Transfer a domain the person owns elsewhere into their own Spaceship account. The live quote is bound to the account, the
2
+ // domain, its current registrar and expiry, the transfer term, amount, regular price, renewal and currency. The default ends
3
+ // at Spaceship's own transfer checkout, where the person enters the auth code; Domain Hound never sees it there. Direct
4
+ // transfers through the REST API are the person's opt-in (DOMAIN_HOUND_DIRECT_PURCHASE=1) and take the auth code only for
5
+ // the one request: it is never printed, stored or echoed, also not from Spaceship's error text.
6
+ import { spaceshipTransferPage, transferBlockers, transferRegistryRecord, transferRules } from '../portfolio/move.mjs';
7
+ import { capCents, directPurchaseEnabled, ownerContact } from './buy.mjs';
8
+ import { cents, minimumYears, quoteLifetimeMs, usd } from './quote.mjs';
9
+ import { digest } from './store.mjs';
10
+
11
+ // Spaceship's MCP tool reference lists registration and read tools; it has no incoming-transfer tool. domain_register
12
+ // registers new names only and must never be used to move a domain. Set tool when Spaceship documents one with a
13
+ // preview and a confirmation step.
14
+ export const spaceshipMcpTransfer = Object.freeze({ tool: null, reference: 'https://www.spaceship.com/knowledgebase/spaceship-mcp/',
15
+ checked: '2026-11-25' });
16
+
17
+ const plainWord = value => typeof value === 'string' && /^[A-Za-z][A-Za-z _-]{0,39}$/.test(value) ? value : null;
18
+ const isoDate = value => typeof value === 'string' && Number.isFinite(Date.parse(value)) ? new Date(value).toISOString() : null;
19
+
20
+ // Every term in years with its final and regular price, in whole cents.
21
+ function termRows(rows) {
22
+ return (Array.isArray(rows) ? rows : []).flatMap(row => {
23
+ const years = row?.period?.unit === 'y' && Number.isSafeInteger(row.period.value) && row.period.value > 0 ? row.period.value : null;
24
+ const price = row?.priceInDefaultCurrency;
25
+ const amount = cents(price?.finalPrice?.amount);
26
+ const regular = cents(price?.regularPrice?.amount);
27
+ const currency = price?.finalPrice?.currency;
28
+ return years && amount !== null && regular !== null && typeof currency === 'string' && price.regularPrice.currency === currency
29
+ ? [{ years, amount, regular, currency }] : [];
30
+ }).sort((a, b) => a.years - b.years);
31
+ }
32
+
33
+ // Spaceship's pricing answer read as one transfer offer. Spaceship omits the transfer price when the ending cannot be
34
+ // transferred in or transfers are paused. The transfer term is Spaceship's own (a transfer request has no years field).
35
+ export function readTransferPrice(domain, pricing) {
36
+ if (typeof pricing?.domain !== 'string' || pricing.domain.toLowerCase() !== domain || !['standard', 'premium'].includes(pricing.priceClass)) {
37
+ return { status: 'unpriced', reason: 'Spaceship gave no price for it.' };
38
+ }
39
+ const [term] = termRows(pricing.prices?.transfer);
40
+ if (!term) return { status: 'unpriced', reason: 'Spaceship lists no transfer price for it (transfers may not be offered for this ending now).' };
41
+ const renewal = termRows(pricing.prices?.renew).find(row => row.years >= minimumYears(domain));
42
+ if (!renewal) return { status: 'unpriced', reason: 'Spaceship lists no renewal price for it.' };
43
+ if (term.currency !== 'USD' || renewal.currency !== 'USD') {
44
+ return { status: 'unpriced', reason: 'Spaceship priced it in ' + term.currency + ', not USD.' };
45
+ }
46
+ return { status: 'priced', priceClass: pricing.priceClass, premium: pricing.priceClass === 'premium', years: term.years,
47
+ amount: term.amount, regular: term.regular, currency: 'USD', promo: term.amount < term.regular || renewal.amount < renewal.regular,
48
+ renewal: { years: renewal.years, amount: renewal.amount, regular: renewal.regular, currency: 'USD' } };
49
+ }
50
+
51
+ // One live check: Spaceship's transfer price, whether the account already holds the domain, and the registry's facts.
52
+ export async function liveTransferOffer(domain, { client, facts, record, now = new Date() }) {
53
+ const [pricing, info, registry] = await Promise.all([client.pricing(domain),
54
+ client.info(domain).catch(problem => problem?.status === 404 ? false : null),
55
+ record ?? transferRegistryRecord(domain, { facts, now })]);
56
+ const { blockers, locked } = transferBlockers(registry, transferRules(domain), now);
57
+ const base = { domain, checkedAt: now.toISOString(), registrar: registry.registrar ?? null, expires: registry.expires ?? null,
58
+ locked, blockers, inAccount: info === false ? false : info?.name === domain ? true : null,
59
+ statusKnown: Boolean(registry.status?.length), created: registry.created };
60
+ if (/\bspaceship\b/i.test(base.registrar ?? '')) base.blockers.unshift('it is already registered at Spaceship');
61
+ if (base.inAccount) base.blockers.unshift('it is already in this Spaceship account');
62
+ if (base.inAccount === null) base.blockers.push('Spaceship did not say whether this account already holds it');
63
+ if (!base.registrar) base.blockers.push('the registry did not name the current registrar');
64
+ if (!base.expires) base.blockers.push('the registry did not confirm the expiry date');
65
+ return { ...base, ...readTransferPrice(domain, pricing) };
66
+ }
67
+
68
+ // The fields a transfer quote binds. Any change between quote and transfer refuses it.
69
+ export const boundTransferFields = offer => ({ domain: offer.domain, registrar: offer.registrar, expires: offer.expires,
70
+ years: offer.years, amount: offer.amount, regular: offer.regular, currency: offer.currency, renewal: offer.renewal,
71
+ priceClass: offer.priceClass, premium: offer.premium });
72
+
73
+ export function transferChanges(quote, fresh) {
74
+ const found = [];
75
+ if (fresh.status !== 'priced') return [fresh.reason ?? 'Spaceship no longer prices the transfer'];
76
+ if (fresh.registrar !== quote.registrar) found.push('the registrar changed from ' + quote.registrar + ' to ' + (fresh.registrar ?? 'unknown'));
77
+ if (fresh.expires !== quote.expires) found.push('the expiry changed from ' + String(quote.expires).slice(0, 10) + ' to ' + String(fresh.expires).slice(0, 10));
78
+ if (fresh.priceClass !== quote.priceClass) found.push('price class changed from ' + quote.priceClass + ' to ' + fresh.priceClass);
79
+ if (fresh.years !== quote.years) found.push('the transfer term changed from ' + quote.years + ' to ' + fresh.years + ' years');
80
+ if (fresh.amount !== quote.amount || fresh.currency !== quote.currency) found.push('price changed from ' + usd(quote.amount) + ' to ' + usd(fresh.amount));
81
+ if (fresh.regular !== quote.regular) found.push('regular price changed from ' + usd(quote.regular) + ' to ' + usd(fresh.regular));
82
+ const was = quote.renewal;
83
+ const now = fresh.renewal;
84
+ if (now.amount !== was.amount || now.regular !== was.regular || now.years !== was.years) {
85
+ found.push('renewal changed from ' + usd(was.amount) + ' to ' + usd(now.amount) + ' per ' + per(now.years));
86
+ }
87
+ return found;
88
+ }
89
+
90
+ const term = years => years + (years === 1 ? ' year' : ' years');
91
+ const per = years => years === 1 ? 'year' : years + ' years';
92
+ const clock = iso => iso.slice(11, 16) + ' UTC';
93
+
94
+ export const transferOfferLine = offer => offer.domain + ': transfer to Spaceship ' + usd(offer.amount) + ', adds ' + term(offer.years)
95
+ + ', then ' + usd(offer.renewal.amount) + ' per ' + per(offer.renewal.years) + '.'
96
+ + (offer.promo ? ' Promotion: the regular price is ' + usd(offer.regular) + ' for the transfer and ' + usd(offer.renewal.regular)
97
+ + ' for the renewal.' : '') + (offer.premium ? ' Premium price.' : '');
98
+
99
+ // Issue a transfer quote: one live check, bound and valid for ten minutes. No quote while anything blocks the move.
100
+ export async function issueTransferQuote(domain, { client, store, facts, record, now = new Date() }) {
101
+ const offer = await liveTransferOffer(domain, { client, facts, record, now });
102
+ if (offer.status !== 'priced' || offer.blockers.length) return { offer, quote: null };
103
+ const expiresAt = new Date(now.getTime() + quoteLifetimeMs).toISOString();
104
+ const { accountBinding, ...quote } = await store.saveBound('transfer-quotes', 'dht-', { ...boundTransferFields(offer), promo: offer.promo,
105
+ checkedAt: offer.checkedAt, expiresAt, accountBinding: client.accountBinding });
106
+ return { offer, quote };
107
+ }
108
+
109
+ export const transferClaimKey = domain => 'trn-' + digest('transfer ' + domain).slice(0, 20);
110
+
111
+ const readableExpiry = quote => typeof quote.expiresAt === 'string' && Number.isFinite(Date.parse(quote.expiresAt));
112
+ const expired = (quote, at) => !readableExpiry(quote) || at.getTime() >= Date.parse(quote.expiresAt);
113
+
114
+ const refusal = (text, fields = {}) => ({ ok: false, transferred: false, say: text, ...fields });
115
+ const checkAccount = 'Do not retry here or at checkout. Check transfers in your Spaceship account first.';
116
+ const alreadySent = (domain, prior) => refusal('A transfer of ' + domain + ' was already sent'
117
+ + (prior?.status ? ' (' + prior.status + (prior.operationId ? ', operation ' + prior.operationId : '') + ')' : '')
118
+ + '. Domain Hound never sends a second one. Follow it with move_domain and status: true. ' + checkAccount,
119
+ { alreadySent: true, ...(prior?.operationId && { operationId: prior.operationId }) });
120
+ const inProgress = (domain, store, path) => refusal('Not sent: another transfer of ' + domain + ' is in progress. Its claim ' + path
121
+ + ' says "checking": it is running its last price check and has sent nothing. Wait a minute and ask again. If no transfer is '
122
+ + 'running, stop every Domain Hound instance that uses ' + store.directory + ', check that the status is exactly "checking", move '
123
+ + 'the file out of that folder, then get a fresh quote.', { inProgress: true, claimPath: path });
124
+
125
+ async function blockedBy(domain, store) {
126
+ const key = transferClaimKey(domain);
127
+ const prior = await store.readClaim(key);
128
+ if (!prior) return null;
129
+ return prior.status === 'checking' ? inProgress(domain, store, store.claimPath(key)) : alreadySent(domain, prior);
130
+ }
131
+
132
+ // The default handoff: Spaceship's transfer checkout, where the person enters the auth code. Never through domain_register.
133
+ export function checkoutHandoff(quote, { max, cap }) {
134
+ const limits = 'exactly ' + quote.domain + ', the transfer adds ' + term(quote.years) + ', at most ' + usd(quote.amount)
135
+ + ' upfront (this quote; your max ' + usd(max) + ', cap ' + usd(cap) + '), renewal at most ' + usd(quote.renewal.amount) + ' per '
136
+ + per(quote.renewal.years) + ', WHOIS privacy on, auto-renew on';
137
+ return [
138
+ 'Spaceship’s MCP has no incoming-transfer tool (tool reference checked ' + spaceshipMcpTransfer.checked + '). Do not use '
139
+ + 'domain_register: it registers new names and cannot move this one.',
140
+ 'Transfer it yourself at Spaceship: [Transfer ' + quote.domain + ' at Spaceship](' + spaceshipTransferPage + '). Enter the auth '
141
+ + 'code there, never in this chat.',
142
+ 'Before starting, check Transfer Manager for any existing transfer. Before paying, check: ' + limits + '. Stop if anything differs' + (quote.promo ? ', or if checkout shows the regular price '
143
+ + usd(quote.regular) + ' (the promotion ended)' : '') + '.',
144
+ 'If your Spaceship MCP lists an incoming-transfer tool with a preview and a confirmation step, you may use it instead with the same '
145
+ + 'limits: preview, check, show the person, accept only after their yes.',
146
+ 'Afterwards, follow it with move_domain and status: true (no code needed).',
147
+ ].join('\n');
148
+ }
149
+
150
+ // transferRequest body: auto renew, high privacy, the account owner for every contact role and the auth code. No years field.
151
+ export const transferBody = (owner, authCode) => ({ autoRenew: true, privacyProtection: { level: 'high', userConsent: true },
152
+ contacts: { registrant: owner, admin: owner, tech: owner, billing: owner }, authCode });
153
+
154
+ // An auth code as Spaceship accepts it: 1 to 50 characters on one line. Checked without echoing it.
155
+ export const validAuthCode = value => typeof value === 'string' && value.length >= 1 && value.length <= 50 && !/\p{Cc}/u.test(value)
156
+ && value.trim() === value;
157
+
158
+ // Guardrails in order: no earlier transfer, valid unexpired quote, explicit max, cap, same account, strict re-check and no
159
+ // blockers. Without direct mode: the checkout handoff. With it: owner contact, standard price, unlocked, dry run or transfer.
160
+ export async function transferDomain(input, { client, accountBinding, store, facts, env = process.env, now = () => new Date(),
161
+ sleep = ms => new Promise(resolve => setTimeout(resolve, ms)), polls = 3, pollMs = 3000 }) {
162
+ const { domain, quote_id: quoteId, max_usd: maxUsd, confirm = false, authCode } = input;
163
+ const blocked = await blockedBy(domain, store);
164
+ if (blocked) return blocked;
165
+ const cap = capCents(env);
166
+ const stored = await store.readBound('transfer-quotes', 'dht-', quoteId);
167
+ if (!stored) return refusal('No valid transfer quote with that ID. Call move_domain with the domain, show the person the quote, then use its ID.');
168
+ const { accountBinding: quotedAccount, ...quote } = stored;
169
+ if (quote.domain !== domain) return refusal('That quote is for ' + quote.domain + ', not ' + domain + '. Nothing sent.');
170
+ if (expired(quote, now())) return refusal('Quote ' + quoteId + ' has expired. Get a fresh plan. Nothing sent.', { expired: true });
171
+ const max = cents(String(maxUsd));
172
+ if (max === null || max <= 0) return refusal('Give max_usd as a positive USD amount in whole cents.');
173
+ if (quote.amount > max) return refusal('The quote is ' + usd(quote.amount) + ', over the max of ' + usd(max) + '. Nothing sent.', { overMax: true });
174
+ if (quote.amount > cap) {
175
+ return refusal('The quote is ' + usd(quote.amount) + ', over the cap of ' + usd(cap) + ' set by DOMAIN_HOUND_MAX_USD. Only the person '
176
+ + 'can raise it in the MCP server settings. Nothing sent.', { overCap: true });
177
+ }
178
+ if (quotedAccount !== await accountBinding()) return refusal('The Spaceship key changed since the quote. Get a fresh plan.');
179
+ const fresh = await liveTransferOffer(domain, { client, facts, now: now() });
180
+ if (expired(quote, now())) return refusal('The quote expired during the price check. Get a fresh plan.');
181
+ const changed = transferChanges(quote, fresh);
182
+ if (changed.length) return refusal('Not sent: ' + changed.join('; ') + '. Get a fresh plan and show the person the new quote.', { changed });
183
+ if (fresh.blockers.length) return refusal('Not sent: ' + fresh.blockers.join('; ') + '.', { blockers: fresh.blockers });
184
+ const claimed = await blockedBy(domain, store);
185
+ if (claimed) return claimed;
186
+ const summary = transferOfferLine(quote) + ' Re-checked ' + clock(fresh.checkedAt) + ', unchanged, within the max of ' + usd(max)
187
+ + ' and the cap of ' + usd(cap) + '.';
188
+ const handoff = () => checkoutHandoff(quote, { max, cap });
189
+ if (!directPurchaseEnabled(env)) {
190
+ return { ok: true, transferred: false, handoff: 'spaceship-checkout', quote, ceilings: { quote: quote.amount, max, cap },
191
+ say: [summary, fresh.locked ? 'First unlock it at ' + quote.registrar + ' (the registry still shows a transfer lock).' : null, handoff()]
192
+ .filter(Boolean).join('\n') };
193
+ }
194
+ // Spaceship's REST endpoint accepts no price ceiling. A promotion can lapse between the re-check and the charge.
195
+ if (quote.regular > Math.min(max, cap)) {
196
+ return refusal('The regular transfer price of ' + usd(quote.regular) + ' exceeds the approved max or server cap. Nothing sent.',
197
+ { overMax: quote.regular > max, overCap: quote.regular > cap });
198
+ }
199
+ const { id: owner, problem } = ownerContact(env);
200
+ const rules = transferRules(domain);
201
+ const direct = problem ?? (quote.premium ? 'direct transfers never move a premium-priced domain'
202
+ : quote.years !== rules.yearsAdded ? 'the transfer term does not match the verified rule for this ending' : null);
203
+ if (direct) return refusal('Not sent: ' + direct + '. Nothing was sent.\n' + summary + '\n' + handoff(), { handoff: 'spaceship-checkout' });
204
+ if (fresh.locked) {
205
+ return refusal('Not sent: the registry still shows a transfer lock. Unlock it at ' + quote.registrar + ', then ask again. Nothing was sent.',
206
+ { locked: true });
207
+ }
208
+ const eligibility = directRegistryIssue(fresh, rules);
209
+ if (eligibility) return refusal('Not sent: ' + eligibility + '. Nothing was sent.');
210
+ if (confirm !== true) {
211
+ return { ok: true, transferred: false, dryRun: true, quote, say: ['Dry run. Nothing sent.', summary,
212
+ 'Direct transfer is on. Spaceship sets the actual charge. Show the person this exact quote. After they approve, call move_domain '
213
+ + 'with confirm: true and the code from their private tool input. Keep the code out of chat and results.'].join('\n') };
214
+ }
215
+ if (!validAuthCode(authCode)) return refusal('Give the auth code from the current registrar (1 to 50 characters). Nothing was sent.');
216
+ return placeTransfer(quote, { client, store, facts, owner, authCode, now, sleep, polls, pollMs });
217
+ }
218
+
219
+ function directRegistryIssue(offer, rules) {
220
+ if (!offer.statusKnown) return 'the registry did not publish the transfer status';
221
+ if (rules.lockDays && !offer.created) return 'the registry did not confirm the registration date';
222
+ return null;
223
+ }
224
+
225
+ async function placeTransfer(quote, { client, store, facts, owner, authCode, now, sleep, polls, pollMs }) {
226
+ const { domain } = quote;
227
+ const key = transferClaimKey(domain);
228
+ let record = await store.claim(key, { domain, kind: 'transfer', quoteId: quote.id, quotedAmount: quote.amount, years: quote.years,
229
+ status: 'checking', at: now().toISOString() });
230
+ if (!record) {
231
+ return await blockedBy(domain, store) ?? refusal('Not sent: another transfer of this domain has just ended. Get a fresh plan.');
232
+ }
233
+ let last, existing;
234
+ try {
235
+ [last, existing] = await Promise.all([
236
+ liveTransferOffer(domain, { client, facts, now: now() }),
237
+ client.transferInfo(domain).catch(error => {
238
+ if (error?.status === 404) return false;
239
+ throw error;
240
+ }),
241
+ ]);
242
+ } catch {
243
+ await store.release(key);
244
+ return refusal('The final Spaceship price or transfer status check failed. Nothing was sent. Check the key scopes and get a fresh plan.');
245
+ }
246
+ const changed = transferChanges(quote, last);
247
+ if (last.status === 'priced') changed.push(...last.blockers);
248
+ if (last.locked) changed.push('the registry shows a transfer lock again');
249
+ const eligibility = directRegistryIssue(last, transferRules(domain));
250
+ if (eligibility) changed.push(eligibility);
251
+ if (existing !== false && !['completed', 'cancelled'].includes(existing?.status)) {
252
+ changed.push('Spaceship already has an ongoing or unconfirmed transfer for this domain');
253
+ }
254
+ if (expired(quote, now())) changed.push('the quote expired');
255
+ if (changed.length) {
256
+ await store.release(key);
257
+ return refusal('Not sent: ' + changed.join('; ') + '. Nothing was sent. Get a fresh plan.', { changed });
258
+ }
259
+ record = { ...record, status: 'sending' };
260
+ try {
261
+ await store.updateClaim(key, record);
262
+ } catch {
263
+ await store.release(key);
264
+ return refusal('Domain Hound could not record the transfer on disk. Nothing was sent.');
265
+ }
266
+ const mark = async fields => {
267
+ record = { ...record, ...fields };
268
+ try { await store.updateClaim(key, record); } catch { /* the claim on disk still blocks a second transfer */ }
269
+ };
270
+ let operationId;
271
+ try {
272
+ ({ operationId } = await client.startTransfer(domain, transferBody(owner, authCode)));
273
+ } catch (problem) {
274
+ if (problem.notSent === true) {
275
+ await store.release(key);
276
+ return refusal(problem.refused ? 'Spaceship refused the transfer (HTTP ' + problem.status + '). Get a fresh plan after resolving it.'
277
+ : 'Nothing was sent.', { refused: problem.refused === true });
278
+ }
279
+ await mark({ status: 'uncertain' });
280
+ return refusal('The transfer result for ' + domain + ' is unclear. Domain Hound will not send it '
281
+ + 'again. ' + checkAccount, { ambiguous: true });
282
+ }
283
+ await mark({ status: 'sent', operationId });
284
+ let operation = null;
285
+ for (let attempt = 0; attempt < polls; attempt++) {
286
+ operation = await client.operation(operationId).catch(() => null);
287
+ if (operation?.status === 'success' || operation?.status === 'failed') break;
288
+ if (attempt < polls - 1) await sleep(pollMs);
289
+ }
290
+ if (operation?.status === 'failed') {
291
+ await mark({ outcome: 'failed' });
292
+ return refusal('Spaceship reports the transfer of ' + domain + ' failed (operation ' + operationId + '). Domain Hound will not send '
293
+ + 'it again. ' + checkAccount, { failed: true, operationId });
294
+ }
295
+ if (operation?.status === 'success') await mark({ outcome: 'success' });
296
+ return { ok: true, transferred: false, requested: true, operationId, say: [
297
+ 'Transfer requested: Spaceship accepted the transfer of ' + domain + ' (operation ' + operationId + ').',
298
+ 'Quoted ' + usd(quote.amount) + ' for ' + term(quote.years) + '; Spaceship sets the actual charge and your account shows it.',
299
+ 'It completes when ' + quote.registrar + ' releases the domain; approve any email from them to speed it up. Follow it with '
300
+ + 'move_domain and status: true (no code needed).'].join('\n') };
301
+ }
302
+
303
+ // Status of a transfer into this account: Spaceship's transfer record and, when Domain Hound sent it, the async operation.
304
+ // Never sends anything and needs no auth code.
305
+ export async function transferStatus(domain, { client, store }) {
306
+ const key = transferClaimKey(domain);
307
+ const claim = await store.readClaim(key);
308
+ const [info, operation] = await Promise.all([
309
+ client.transferInfo(domain).catch(problem => problem?.status === 404 ? null : undefined),
310
+ claim?.operationId ? client.operation(claim.operationId).catch(() => null) : null]);
311
+ const status = ['pending', 'completed', 'cancelled'].includes(info?.status) ? info.status : null;
312
+ const direction = info?.direction === 'in' ? 'in' : null;
313
+ const opStatus = ['pending', 'success', 'failed'].includes(operation?.status) ? operation.status : null;
314
+ if (claim && opStatus && ['success', 'failed'].includes(opStatus) && claim.outcome !== opStatus) {
315
+ try { await store.updateClaim(key, { ...claim, outcome: opStatus }); } catch { /* the claim still blocks a second transfer */ }
316
+ }
317
+ const lines = [];
318
+ if (info === undefined) lines.push('Spaceship did not answer for this transfer. The key needs domains:transfer. Try again later.');
319
+ else if (!info) lines.push('Spaceship has no transfer record for ' + domain + ' in this account.');
320
+ else {
321
+ lines.push(domain + ': incoming transfer, status ' + (status ?? 'unknown')
322
+ + (isoDate(info.startedAt) ? ', started ' + isoDate(info.startedAt).slice(0, 16).replace('T', ' ') + ' UTC' : '')
323
+ + (isoDate(info.finishedAt) ? ', finished ' + isoDate(info.finishedAt).slice(0, 16).replace('T', ' ') + ' UTC' : '') + '.');
324
+ }
325
+ if (claim) {
326
+ lines.push('Domain Hound sent it' + (claim.operationId ? ' (operation ' + claim.operationId + (opStatus ? ', ' + opStatus : '') + ')' : '')
327
+ + '; claim status "' + (plainWord(claim.status) ?? 'unresolved') + '". It will not send another.');
328
+ }
329
+ if (status === 'pending' || opStatus === 'pending') lines.push('Still waiting for the current registrar to release it. Ask again later.');
330
+ return { domain, transfer: info ? { status, direction, startedAt: isoDate(info.startedAt),
331
+ finishedAt: isoDate(info.finishedAt) } : null, operation: opStatus, claim: claim ? plainWord(claim.status) : null, say: lines.join('\n') };
332
+ }
package/display.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { shopSearchUrl, shops } from './clis/domain-check/prices.mjs';
1
+ import { dnsNeed, shopSearchUrl, shops } from './clis/domain-check/prices.mjs';
2
2
  import { isSearchLink, nameCheckLines } from './clis/domain-check/google-search.mjs';
3
- import { canRecommend, eligibilityNeed, endingTier, normalizeName, premiumRisk, unicodeName } from './clis/domain-check/name-search.mjs';
3
+ import { canRecommend, choosePick, comparePicks, eligibilityNeed, lowestTotal, lowestUpfront, normalizeName, premiumRisk, qualityRank,
4
+ unicodeName } from './clis/domain-check/name-search.mjs';
4
5
  import { purchaseLine } from './clis/domain-check/naming-method.mjs';
5
6
 
6
7
  export { purchaseLine, showAsIs } from './clis/domain-check/naming-method.mjs';
@@ -260,7 +261,8 @@ function freeLines(row, listPrices, level, eligible) {
260
261
  const quote = own ? option : listPrices[option.d];
261
262
  const listed = jumpRatio(quote) ? ' (list price)' : ' list price';
262
263
  const tag = option.s === 'ok' ? ' ✓ ' + priceLabel(option, option.shop) : level >= 1 || quote?.now == null ? '' : listed;
263
- return '- ' + domain + ' ' + (quote?.now == null ? 'price at shop' : priceText(quote)) + tag;
264
+ const dns = quote?.now != null && dnsNeed(quote.shop) ? ' (' + dnsNeed(quote.shop).toLowerCase() + ')' : '';
265
+ return '- ' + domain + ' ' + (quote?.now == null ? 'price at shop' : priceText(quote)) + tag + dns;
264
266
  });
265
267
  }
266
268
 
@@ -276,8 +278,8 @@ function groupRows(rows, linesFor) {
276
278
  return [...groups.values()];
277
279
  }
278
280
 
279
- // For one bare name: the cheapest first payment and the best three-year value among the endings this buyer can register,
280
- // both within the most attractive tier that has a free ending (fallback endings only when nothing else is free).
281
+ // For one bare name, the shared pick rule: the pick, then the cheapest first payment and the best three-year value
282
+ // among the endings this buyer can register, each only when it is not the pick.
281
283
  function choiceLines(row, listPrices, eligible, preferred = []) {
282
284
  const free = (row.free ?? []).flatMap(option => {
283
285
  const domain = option.d.includes('.') ? option.d : row.name + '.' + option.d;
@@ -285,15 +287,18 @@ function choiceLines(row, listPrices, eligible, preferred = []) {
285
287
  if (option.s === 'prem' || option.prem || premiumRisk(domain) || ineligible(ending, eligible)
286
288
  || (preferred.length && !preferred.includes(ending))) return [];
287
289
  const price = option.now != null ? option : listPrices[option.d];
288
- return [{ domain, price, value: threeYears(price)?.total ?? Infinity, tier: endingTier(domain, preferred, eligible) }];
290
+ return [{ domain, price, now: price?.now ?? null, total: threeYears(price)?.total ?? null }];
289
291
  });
290
- const tier = Math.min(...free.map(option => option.tier));
291
- const options = free.filter(option => option.tier === tier && option.price?.now != null);
292
- if (!options.length) return [];
293
- const cheapest = options.reduce((best, row) => row.price.now < best.price.now ? row : best);
294
- const value = options.reduce((best, row) => row.value < best.value
295
- || (row.value === best.value && row.price.now < best.price.now) ? row : best);
296
- return ['Cheapest now: ' + shown(cheapest.domain), ...(value.value < Infinity ? [bestValueLine(value.domain, value.price)] : [])];
292
+ const rank = option => qualityRank(option.domain, preferred, eligible);
293
+ const pick = choosePick(free, { requested: preferred, eligible });
294
+ const cheapest = lowestUpfront(free, rank);
295
+ const value = lowestTotal(free, rank);
296
+ // Each price and renewal jump appears once, on its free line; these lines only name the domains and the 3-year total.
297
+ return [
298
+ ...(pick ? ['Pick: ' + shown(pick.domain)] : []),
299
+ ...(cheapest && cheapest !== pick ? ['Cheapest now: ' + shown(cheapest.domain)] : []),
300
+ ...(value && value !== pick ? [bestValueLine(value.domain, value.price)] : []),
301
+ ];
297
302
  }
298
303
 
299
304
  export function checkDisplay(result, level = 0, purchase = false, preferred = []) {
@@ -364,12 +369,12 @@ export function checkDisplay(result, level = 0, purchase = false, preferred = []
364
369
  if (!canRecommend(ending, eligible) || (preferred.length && !preferred.includes(ending))) return [];
365
370
  const price = option.prem || option.s === 'prem' ? option : { ...listPrices[option.d], ...option };
366
371
  const link = templateLink(result.buyUrlTemplate, price.shop, domain);
367
- // An exact domain the person typed is requested, so it is never demoted to the fallback tier.
368
- const tier = endingTier(domain, row.name.includes('.') ? [...preferred, domain] : preferred, eligible);
369
- return link ? [{ link, price: price.now ?? Infinity, tier }] : [];
372
+ // An exact domain the person typed is requested, so it ranks first.
373
+ const requested = row.name.includes('.') ? [...preferred, domain] : preferred;
374
+ return link ? [{ link, domain, now: price.now ?? null, total: threeYears(price)?.total ?? null, requested }] : [];
370
375
  }));
371
- const cheapest = available.sort((a, b) => a.tier - b.tier || a.price - b.price)[0];
372
- if (cheapest) lines.push('Check at shop: ' + cheapest.link);
376
+ const pick = choosePick(available, { requested: [...new Set(available.flatMap(option => option.requested))], eligible });
377
+ if (pick) lines.push('Check at shop: ' + pick.link);
373
378
  }
374
379
  return lines.join('\n').trim();
375
380
  }
@@ -393,48 +398,40 @@ export function checkLines(row, short = false) {
393
398
 
394
399
  const verdictRank = { 'No conflict found': 0, 'Check first': 1, Avoid: 2 };
395
400
 
396
- // The cheapest free ending this buyer can register, at the name's own price or the standard list price, within the
397
- // most attractive tier that has a free eligible ending. tier is not part of the pick it returns.
398
- function cheapestEligible(row, prices, eligible, preferred = []) {
401
+ // A name's pick under the shared pick rule, among the free endings this buyer can register, at the name's own price or
402
+ // the standard list price. fit, rank and total are for ranking names and are not part of the pick it returns.
403
+ function eligiblePick(row, prices, eligible, preferred = []) {
399
404
  const free = (Array.isArray(row?.free) ? row.free : []).filter(ending => canRecommend(ending, eligible)
400
405
  && (!preferred.length || preferred.includes(ending)));
401
- const tier = ending => endingTier('.' + ending, preferred, eligible);
402
- const top = Math.min(...free.map(tier));
403
- let best = null;
404
- for (const ending of free) {
406
+ const options = free.flatMap(ending => {
405
407
  const quote = row.own?.[ending] ?? prices?.[ending];
406
- if (tier(ending) !== top || quote?.now == null) continue;
407
- if (!best || quote.now < best.now) best = { ending, now: quote.now, renew: quote.renew ?? null, term: quote.term ?? null };
408
- }
409
- return best && { ...best, tier: top };
408
+ if (quote?.now == null) return [];
409
+ return [{ ending, domain: 'x.' + ending, now: quote.now, renew: quote.renew ?? null, term: quote.term ?? null,
410
+ total: threeYears(quote)?.total ?? null }];
411
+ });
412
+ return choosePick(options, { requested: preferred, eligible });
410
413
  }
411
414
 
412
415
  // Three ranked picks once three or more names are screened: the screen's own ranking first, then the other
413
- // names by verdict and cheapest eligible price. Each pick carries its cheapest eligible domain and price.
416
+ // names by verdict and their pick (within the cap first, then the quality order). Each pick carries its domain and price.
414
417
  export function topPicks(result, preferred = []) {
415
418
  const rows = (result.names ?? []).filter(Boolean);
416
419
  const prices = result.prices ?? {};
417
- const eligibleCheapest = row => {
418
- const found = cheapestEligible(row, prices, result.eligible, preferred);
419
- if (!found) return null;
420
- const { tier, ...pick } = found;
421
- return pick;
422
- };
420
+ const pickFields = found => found && { ending: found.ending, now: found.now, renew: found.renew, term: found.term };
423
421
  const picks = (Array.isArray(result.top) ? result.top : []).filter(Boolean).slice(0, 3).map(pick => {
424
422
  if (pick.ending || pick.domain) return pick;
425
- const cheapest = eligibleCheapest(rows.find(row => row.name === pick.name));
426
- return cheapest ? { ...pick, ...cheapest } : pick;
423
+ const found = pickFields(eligiblePick(rows.find(row => row.name === pick.name), prices, result.eligible, preferred));
424
+ return found ? { ...pick, ...found } : pick;
427
425
  });
428
426
  if (rows.length < 3) return picks;
429
- const rest = rows.map((row, index) => ({ row, index, cheapest: cheapestEligible(row, prices, result.eligible, preferred) }))
427
+ const context = { requested: preferred, eligible: result.eligible ?? [] };
428
+ const rest = rows.map((row, index) => ({ row, index, pick: eligiblePick(row, prices, result.eligible, preferred) }))
430
429
  .filter(({ row }) => !picks.some(pick => pick.name === row.name))
431
430
  .sort((a, b) => (verdictRank[a.row.verdict] ?? 3) - (verdictRank[b.row.verdict] ?? 3)
432
- || (a.cheapest?.tier ?? Infinity) - (b.cheapest?.tier ?? Infinity)
433
- || (a.cheapest?.now ?? Infinity) - (b.cheapest?.now ?? Infinity) || a.index - b.index);
434
- for (const { row, cheapest } of rest.slice(0, 3 - picks.length)) {
435
- const { tier, ...pick } = cheapest ?? {};
431
+ || Number(!a.pick) - Number(!b.pick) || (a.pick && b.pick ? comparePicks(a.pick, b.pick, context) : 0) || a.index - b.index);
432
+ for (const { row, pick } of rest.slice(0, 3 - picks.length)) {
436
433
  picks.push({ name: row.name, verdict: row.verdict, reason: row.reason,
437
- ...(cheapest && { ...pick, domain: fullDomain(label(row.name), cheapest.ending) }) });
434
+ ...(pick && { ...pickFields(pick), domain: fullDomain(label(row.name), pick.ending) }) });
438
435
  }
439
436
  return picks;
440
437
  }
@@ -448,7 +445,7 @@ function nameLabel(name) {
448
445
  function topLines(result, showReason, showValue = true, preferred = []) {
449
446
  return ['**Top picks**', ...topPicks(result, preferred).map(row => {
450
447
  const ending = row.domain ? shown(row.domain) : row.ending && '.' + row.ending;
451
- const domain = ending ? ', cheapest now ' + priced(ending, row) : ', no eligible free ending';
448
+ const domain = ending ? ', pick ' + priced(ending, row) : ', no eligible free ending';
452
449
  const value = !showValue ? '' : typeof row.bestValue === 'string'
453
450
  ? rowBestValue(result.names.find(candidate => candidate.name === row.name), result.prices)
454
451
  : row.bestValue && bestValueLine(row.bestValue.domain, row.bestValue);
package/dossier.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import { buildDossier, dossierDomain, formatMoney } from './clis/domain-check/dossier.mjs';
2
2
  import { attributed, md } from './display.mjs';
3
+ import { dnsNeed } from './clis/domain-check/prices.mjs';
3
4
 
4
5
  export const dossierTool = {
5
6
  name: 'taken_domain_dossier',
6
- description: 'Investigate a taken domain. Get registry, site and public listing evidence, likely owner type, and a price range when supported. '
7
- + 'See up to three free alternatives with upfront, renewal and three-year prices, plus a quick trademark, app and rival screen. '
8
- + 'Relay the display and sources. Keep maxBudget private, send no drafts, and start a watch only on request. Share follow-up drafts only on request.',
7
+ description: 'Investigate a taken domain: registry, site and public listing evidence, likely owner type, and a price range when supported, '
8
+ + 'plus up to three free alternatives with upfront, renewal and three-year prices and a quick trademark, app and rival screen. '
9
+ + 'Relay the display and sources. Keep maxBudget private and send no drafts. Share follow-up drafts and start a watch only on request.',
9
10
  annotations: { title: 'Taken domain dossier', readOnlyHint: true, destructiveHint: false, openWorldHint: true },
10
11
  inputSchema: {
11
12
  type: 'object',
@@ -97,7 +98,8 @@ function trackLine(data) {
97
98
  return 'Next: if you want to inquire, review the draft and use a public contact route.';
98
99
  }
99
100
 
100
- const roleText = { 'best-value': 'best 3-year value for the exact name', variant: '.com variant', 'exact-com': 'exact .com',
101
+ const roleText = { pick: 'pick for the exact name',
102
+ variant: '.com variant', 'exact-com': 'exact .com',
101
103
  'exact-ending': 'same name, other ending' };
102
104
 
103
105
  // First payment, renewal with the jump flag, minimum term and the three-year total, all list prices.
@@ -108,7 +110,8 @@ function costText(row) {
108
110
  : money(row.price) + ' first year';
109
111
  const renewal = row.renewal != null ? ', renews at ' + money(row.renewal) + '/year' + (row.renewalJump ? ' (renewal jump)' : '') : '';
110
112
  const total = row.threeYear != null ? ', ' + money(row.threeYear) + ' over 3 years' : '';
111
- return first + renewal + total;
113
+ const dns = dnsNeed(row.shop);
114
+ return first + renewal + total + (dns ? ' (' + dns.toLowerCase() + ')' : '');
112
115
  }
113
116
 
114
117
  function screenText(screen, isBase = false) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "domain-hound",
3
- "version": "0.1.7",
4
- "description": "Find a startup name and domain you can actually buy: availability, prices, app names, trademarks. MCP for Claude Code and Codex.",
3
+ "version": "0.1.8",
4
+ "description": "Domains for agents. One MCP for everything domains: find, check, buy, set up, watch, move, renew, keep track.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
@@ -23,6 +23,9 @@
23
23
  "codex",
24
24
  "domain",
25
25
  "domain-availability",
26
+ "domains-for-agents",
27
+ "domain-portfolio",
28
+ "domain-transfer",
26
29
  "domain-name",
27
30
  "startup-name",
28
31
  "naming",
@@ -79,6 +82,14 @@
79
82
  "clis/spaceship/setup.mjs",
80
83
  "clis/spaceship/store.mjs",
81
84
  "clis/spaceship/tools.mjs",
85
+ "clis/spaceship/transfer.mjs",
86
+ "clis/portfolio/checks.mjs",
87
+ "clis/portfolio/discover.mjs",
88
+ "clis/portfolio/move.mjs",
89
+ "clis/portfolio/page.mjs",
90
+ "clis/portfolio/portfolio.mjs",
91
+ "clis/portfolio/store.mjs",
92
+ "clis/portfolio/transfer-prices.mjs",
82
93
  "assets/",
83
94
  ".claude-plugin/plugin.json",
84
95
  ".claude-plugin/marketplace.json",
@@ -88,7 +99,7 @@
88
99
  "server.json"
89
100
  ],
90
101
  "scripts": {
91
- "test": "node --test server.test.mjs results.test.mjs share.test.mjs dossier.test.mjs clis/domain-check/*.test.mjs clis/domain-check/test.mjs clis/spaceship/*.test.mjs",
102
+ "test": "node --test server.test.mjs results.test.mjs share.test.mjs dossier.test.mjs clis/domain-check/*.test.mjs clis/domain-check/test.mjs clis/spaceship/*.test.mjs clis/portfolio/*.test.mjs",
92
103
  "smoke": "node scripts/smoke.mjs",
93
104
  "snapshot-prices": "node scripts/snapshot-prices.mjs",
94
105
  "build-mcpb": "node scripts/build-mcpb.mjs"
package/plugin.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "domain-hound",
4
- "version": "0.1.7",
5
- "description": "Check domain availability and prices, and screen product names, from your AI assistant.",
4
+ "version": "0.1.8",
5
+ "description": "Domains for agents. One MCP for everything domains: find, check, buy, set up, watch, move, renew, keep track.",
6
6
  "author": {
7
7
  "name": "Lars Hvinden"
8
8
  },
@@ -12,15 +12,15 @@
12
12
  "com.openai": {
13
13
  "interface": {
14
14
  "displayName": "Domain Hound",
15
- "shortDescription": "Domain prices and name checks",
16
- "longDescription": "Domain Hound checks registry availability, compares upfront and renewal prices, and screens product names for trademarks, app store clashes and web traction. It can investigate taken domains and watch them for release. Connect your own Spaceship account to get a live quote and set up website or mail DNS. You buy through Spaceship’s own MCP, after you approve Spaceship’s confirmation with the price and payment method. Direct purchase is an opt-in in the server settings, and Spaceship checkout is the fallback. Domain Hound runs on your machine and is open source under the MIT license.",
15
+ "shortDescription": "Domains for agents",
16
+ "longDescription": "Domains for agents. One MCP for everything domains: find, check, buy, set up, watch, move, renew, keep track. Domain Hound finds names and checks registry availability, compares upfront and renewal prices, and screens names for trademarks, app store clashes and web traction. Connect your own Spaceship account to get a live quote, buy with your approval and set up website or mail DNS. You buy through Spaceship’s own MCP, after you approve Spaceship’s confirmation with the price and payment method. Direct purchase is an opt-in in the server settings, and Spaceship checkout is the fallback. It investigates and watches taken domains, plans moves to a cheaper registrar, and keeps track of every domain you own: expiry, DNS, site, email setup and renewal prices. Domain Hound runs on your machine and is open source under the MIT license.",
17
17
  "developerName": "Lars Hvinden",
18
18
  "category": "Developer Tools",
19
19
  "capabilities": [
20
- "Check domain availability",
21
- "Compare registrar prices",
22
- "Screen product names",
23
- "Set up DNS at Spaceship"
20
+ "Find names and check domains",
21
+ "Compare upfront and renewal prices",
22
+ "Buy and set up DNS at Spaceship",
23
+ "Watch, move and track your domains"
24
24
  ],
25
25
  "websiteURL": "https://domainhound.dev",
26
26
  "privacyPolicyURL": "https://domainhound.dev/privacy/",