domain-hound 0.1.7 → 0.1.9

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.
Files changed (45) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +2 -2
  4. package/README.md +89 -24
  5. package/clis/domain-check/company-search.mjs +1 -0
  6. package/clis/domain-check/dossier.mjs +16 -13
  7. package/clis/domain-check/google-play.mjs +11 -48
  8. package/clis/domain-check/google-search.mjs +3 -2
  9. package/clis/domain-check/handles.mjs +235 -106
  10. package/clis/domain-check/index.mjs +49 -28
  11. package/clis/domain-check/name-score.mjs +348 -0
  12. package/clis/domain-check/name-search.mjs +70 -18
  13. package/clis/domain-check/naming-method.mjs +37 -8
  14. package/clis/domain-check/price-catalog.mjs +33 -14
  15. package/clis/domain-check/price-snapshot.json +91 -0
  16. package/clis/domain-check/prices.mjs +5 -0
  17. package/clis/domain-check/public-name-checks.mjs +275 -0
  18. package/clis/domain-check/score-log.mjs +54 -0
  19. package/clis/domain-check/triage-sources.mjs +4 -1
  20. package/clis/domain-check/triage.mjs +131 -83
  21. package/clis/domain-check/youtube-handle.mjs +18 -0
  22. package/clis/portfolio/checks.mjs +456 -0
  23. package/clis/portfolio/discover.mjs +175 -0
  24. package/clis/portfolio/move.mjs +297 -0
  25. package/clis/portfolio/page.mjs +140 -0
  26. package/clis/portfolio/portfolio.mjs +212 -0
  27. package/clis/portfolio/store.mjs +62 -0
  28. package/clis/portfolio/transfer-prices.mjs +41 -0
  29. package/clis/spaceship/client.mjs +35 -19
  30. package/clis/spaceship/tools.mjs +105 -17
  31. package/clis/spaceship/transfer.mjs +332 -0
  32. package/display.mjs +62 -61
  33. package/dossier.mjs +8 -5
  34. package/hosted-results.mjs +157 -0
  35. package/hosted.mjs +164 -0
  36. package/package.json +21 -3
  37. package/plugin.json +8 -8
  38. package/results-style.mjs +3 -0
  39. package/results.mjs +149 -94
  40. package/server.json +4 -4
  41. package/server.mjs +216 -28
  42. package/share.mjs +18 -6
  43. package/site/r/share-format.mjs +23 -8
  44. package/skills/naming/SKILL.md +76 -0
  45. package/watch.mjs +3 -3
@@ -0,0 +1,275 @@
1
+ import { parse, parseFragment } from 'parse5';
2
+
3
+ export const publicCheckTiming = Object.freeze({ budgetMs: 3000, timeoutMs: 1400, archiveTimeoutMs: 900, pageTimeoutMs: 2400, ttlMs: 3_600_000 });
4
+ export const publicHtmlLimit = 4_000_000;
5
+ export const archiveKinds = Object.freeze(['linkedin', 'reddit']);
6
+ export const publicPageKinds = Object.freeze(['youtube', 'threads', 'twitch', 'googlePlay']);
7
+ export const publicProfileKinds = Object.freeze(['youtube', 'instagram', 'x', 'tiktok', 'threads', 'facebook', 'twitch', ...archiveKinds]);
8
+ export const embedKinds = Object.freeze([...publicProfileKinds.filter(kind => kind !== 'youtube'), 'googlePlay']);
9
+
10
+ // Expire decisions made by the old Threads and Google Play classifiers.
11
+ export const publicCacheKind = kind => ['threads', 'googlePlay'].includes(kind) ? kind + '-v2' : kind;
12
+ const archiveProfile = (kind, handle) => (kind === 'linkedin' ? 'linkedin.com/company/' : 'reddit.com/user/') + handle;
13
+ export const archiveLabel = year => `Found · seen ${year}`;
14
+ export const threadsFromInstagram = (threads, instagram) => instagram?.state === 'not-found'
15
+ ? { state: 'not-found', why: 'no Instagram account', checkedAt: instagram.checkedAt } : threads;
16
+
17
+ const embedUrl = (endpoint, profile) => endpoint + '?' + new URLSearchParams({ url: profile });
18
+ export const playSearchLink = name => 'https://play.google.com/store/search?' +
19
+ new URLSearchParams({ q: name, c: 'apps', hl: 'en', gl: 'US' });
20
+ export const validPlayName = name => typeof name === 'string' && name.length > 0 && name.length <= 100 &&
21
+ /[\p{L}\p{N}]/u.test(name) && !/[\p{Cc}\p{Cf}]/u.test(name);
22
+ export const playCacheName = name => name.trim().replace(/\s+/gu, ' ').toLowerCase();
23
+ export function playTitleMatches(name, title) {
24
+ const query = playCacheName(name);
25
+ const candidate = playCacheName(title);
26
+ return candidate.replaceAll(' ', '') === query.replaceAll(' ', '') ||
27
+ (candidate.startsWith(query) && /^[^\p{L}]/u.test(candidate.slice(query.length)));
28
+ }
29
+
30
+ export const publicUrls = Object.freeze({
31
+ tiktok: handle => embedUrl('https://www.tiktok.com/oembed', 'https://www.tiktok.com/@' + handle),
32
+ instagram: handle => embedUrl('https://graph.facebook.com/v22.0/instagram_oembed', 'https://www.instagram.com/' + handle + '/'),
33
+ x: handle => embedUrl('https://publish.twitter.com/oembed', 'https://x.com/' + handle),
34
+ youtube: handle => 'https://www.youtube.com/@' + handle,
35
+ threads: handle => 'https://www.threads.net/@' + handle,
36
+ facebook: handle => 'https://graph.facebook.com/' + handle + '/picture?redirect=false',
37
+ twitch: handle => 'https://www.twitch.tv/' + handle,
38
+ googlePlay: playSearchLink,
39
+ });
40
+
41
+ const jsonType = /^application\/(?:[\w.+-]+\+)?json\b/i;
42
+ const htmlType = /^text\/html\b/i;
43
+ const readsJson = (kind, type) => jsonType.test(type) ||
44
+ (['instagram', 'facebook'].includes(kind) && /^text\/javascript\b/i.test(type));
45
+ export const readsPublicBody = (kind, status, type) => readsJson(kind, type) ||
46
+ (!['tiktok', 'instagram'].includes(kind) && (status === 200 || status === 404) && htmlType.test(type));
47
+
48
+ // Stop reading once a successful page has supplied the evidence it needs.
49
+ export function publicBodyComplete(kind, status, type, body, name) {
50
+ if (status !== 200 || !htmlType.test(type)) return false;
51
+ if (kind === 'threads') return body.includes('</title>');
52
+ if (kind === 'twitch') return body.includes('</head>');
53
+ return kind === 'youtube' && body.includes('<meta property="og:type" content="profile">') &&
54
+ classifyPublicCheck(kind, { status, contentType: type, body }, name) === 'taken';
55
+ }
56
+ const text = node => node.nodeName === '#text' ? node.value : (node.childNodes ?? []).map(text).join('');
57
+ const attr = (node, name) => node.attrs?.find(entry => entry.name === name)?.value;
58
+ const hasClass = (node, value) => (attr(node, 'class') ?? '').split(/\s+/).includes(value);
59
+
60
+ function* elements(node) {
61
+ for (const child of node.childNodes ?? []) {
62
+ if (!child.tagName || ['script', 'style', 'template', 'svg'].includes(child.tagName)) continue;
63
+ yield child;
64
+ yield* elements(child);
65
+ }
66
+ }
67
+
68
+ function playCards(document, query) {
69
+ const cards = [];
70
+ let empty = false;
71
+ let incomplete = false;
72
+ const emptyMessage = 'no results for ' + playCacheName(query);
73
+ for (const node of elements(document)) {
74
+ if (['h1', 'h2', 'h3', 'span', 'p'].includes(node.tagName) && !empty && playCacheName(text(node)) === emptyMessage) {
75
+ empty = true;
76
+ }
77
+ const href = node.tagName === 'a' ? attr(node, 'href') : null;
78
+ if (!href?.startsWith('/store/apps/details?id=')) continue;
79
+ const featured = hasClass(node, 'Qfxief');
80
+ const find = (root, className) => {
81
+ for (const child of elements(root)) if (hasClass(child, className)) return text(child);
82
+ return '';
83
+ };
84
+ const id = new URL(href, 'https://play.google.com').searchParams.get('id');
85
+ const name = featured ? attr(node, 'aria-label') : find(node, 'DdYX5');
86
+ const seller = featured ? find(node.parentNode, 'LbQbAe') : find(node, 'wMUdtb');
87
+ if (name?.trim() && id) cards.push({ name, seller, id });
88
+ else incomplete = true;
89
+ }
90
+ return { cards, empty, incomplete };
91
+ }
92
+
93
+ export function parsePlayCards(document, query) {
94
+ const { cards, empty } = playCards(document, query);
95
+ const detailed = cards.filter(card => card.seller);
96
+ return empty ? [] : detailed.length ? detailed : null;
97
+ }
98
+
99
+ function classifyPlay(html, query) {
100
+ const document = parse(html);
101
+ const head = document.childNodes.find(node => node.tagName === 'html')?.childNodes.find(node => node.tagName === 'head');
102
+ const title = head?.childNodes.find(node => node.tagName === 'title');
103
+ if (!title || playCacheName(text(title)) !== playCacheName(query + ' - Android Apps on Google Play')) return 'unknown';
104
+ const { cards, empty, incomplete } = playCards(document, query);
105
+ if (empty) return 'not-found';
106
+ if (cards.some(card => playTitleMatches(query, card.name))) return 'taken';
107
+ return cards.length && !incomplete ? 'not-found' : 'unknown';
108
+ }
109
+
110
+ function titleOf(html) {
111
+ const raw = html.match(/<title\b[^>]*>([^<]{1,400})<\/title>/i)?.[1];
112
+ // The title is RCDATA, so decoding entities must not interpret its contents as markup.
113
+ return raw ? text(parseFragment('<title>' + raw + '</title>')).trim() : '';
114
+ }
115
+
116
+ function twitchProfile(html, name) {
117
+ const head = parse(html).childNodes.find(node => node.tagName === 'html')?.childNodes.find(node => node.tagName === 'head');
118
+ const meta = new Map(head?.childNodes.filter(node => node.tagName === 'meta')
119
+ .map(node => [attr(node, 'property'), attr(node, 'content')]));
120
+ const title = meta.get('og:title');
121
+ const username = meta.get('og:profile:username');
122
+ if (title && /^.+ - Twitch$/.test(title) && (!username || username.toLowerCase() === name)) return 'taken';
123
+ const pageTitle = head?.childNodes.find(node => node.tagName === 'title');
124
+ // Twitch also serves a generic homepage shell for existing channels. Require metadata for the requested URL.
125
+ if (!username && (!title || title === 'Twitch') && meta.get('og:site_name') === 'Twitch' &&
126
+ pageTitle && text(pageTitle).trim() === 'Twitch' &&
127
+ profileUrlMatches(meta.get('og:url'), ['www.twitch.tv'], '/' + name)) return 'not-found';
128
+ return 'unknown';
129
+ }
130
+
131
+ function profileUrlMatches(value, hosts, path) {
132
+ try {
133
+ const url = new URL(value);
134
+ return url.protocol === 'https:' && !url.port && !url.username && !url.password &&
135
+ hosts.includes(url.hostname) && url.pathname.replace(/\/$/, '').toLowerCase() === path;
136
+ } catch {
137
+ return false;
138
+ }
139
+ }
140
+
141
+ // Allow only the observed cross-host redirects. No credentials, query changes or redirects to login pages.
142
+ export async function fetchPublicCheck(fetcher, url, init) {
143
+ const response = await fetcher(url, { ...init, redirect: 'manual' });
144
+ if (![301, 302, 303, 307, 308].includes(response.status)) return response;
145
+ const original = new URL(url);
146
+ const host = { 'publish.twitter.com': 'publish.x.com', 'www.threads.net': 'www.threads.com' }[original.hostname];
147
+ let next;
148
+ try { next = new URL(response.headers.get('location') ?? '', original); } catch { return response; }
149
+ if (!host || next.origin !== 'https://' + host || next.username || next.password || next.hash ||
150
+ next.pathname !== original.pathname || next.search !== original.search) return response;
151
+ void response.body?.cancel().catch(() => {});
152
+ return fetcher(next.href, { ...init, redirect: 'manual' });
153
+ }
154
+
155
+ export function classifyPublicCheck(kind, { status, contentType, body }, name) {
156
+ const json = readsJson(kind, contentType);
157
+ const html = htmlType.test(contentType) && typeof body === 'string' ? body : '';
158
+ let data;
159
+ if (json && [200, 400].includes(status)) {
160
+ try { data = JSON.parse(body); } catch { return 'unknown'; }
161
+ }
162
+ switch (kind) {
163
+ case 'tiktok':
164
+ if (status === 200 && data?.provider_name === 'TikTok' && data.type === 'rich' && data.embed_type === 'profile' &&
165
+ typeof data.embed_product_id === 'string' && data.embed_product_id.toLowerCase() === name && typeof data.html === 'string' &&
166
+ profileUrlMatches(data.author_url, ['www.tiktok.com'], '/@' + name)) return 'taken';
167
+ if (status === 400 && data?.code === 400 && data.message === 'Something went wrong') return 'not-found';
168
+ break;
169
+ case 'instagram': {
170
+ const permalink = typeof data?.html === 'string' && data.html.match(/\bdata-instgrm-permalink="([^"]+)"/i)?.[1];
171
+ if (status === 200 && data?.provider_name === 'Instagram' && data.type === 'rich' &&
172
+ profileUrlMatches(permalink, ['www.instagram.com'], '/' + name)) return 'taken';
173
+ if (status === 400 && data?.error?.type === 'OAuthException' && data.error.code === 24 &&
174
+ data.error.error_subcode === 2207045 && data.error.is_transient === false &&
175
+ data.error.message === 'The requested resource does not exist') return 'not-found';
176
+ break;
177
+ }
178
+ case 'x':
179
+ if (status === 200 && ['X', 'Twitter'].includes(data?.provider_name) && data.type === 'rich' &&
180
+ typeof data.html === 'string' && /\bclass="twitter-timeline"/.test(data.html) &&
181
+ profileUrlMatches(data.url, ['x.com', 'twitter.com'], '/' + name)) return 'taken';
182
+ if (status === 404 && html && ['X / ?', 'Twitter / ?'].includes(titleOf(html)) &&
183
+ /<h1 id="header">Nothing to see here<\/h1>/i.test(html)) return 'not-found';
184
+ break;
185
+ case 'youtube':
186
+ if (status === 200 && html && /<link rel="canonical" href="https:\/\/www\.youtube\.com\/channel\/UC[\w-]{22}">/.test(html) &&
187
+ /<meta property="og:type" content="profile">/.test(html) &&
188
+ ['www', 'm'].some(host => html.toLowerCase().includes('href="https://' + host + '.youtube.com/@' + name + '"'))) return 'taken';
189
+ if (status === 404 && html && titleOf(html) === '404 Not Found' &&
190
+ /<iframe\b[^>]*\bsrc="\/error\?src=404&amp;ifr=1&amp;error="/i.test(html)) return 'not-found';
191
+ break;
192
+ case 'threads':
193
+ if (status === 200 && html) {
194
+ const title = titleOf(html);
195
+ const marker = ' (@' + name + ') • Threads';
196
+ const at = title.toLowerCase().indexOf(marker.toLowerCase());
197
+ if (at > 0 && /^[,\s]?$/.test(title.charAt(at + marker.length))) return 'taken';
198
+ }
199
+ break;
200
+ case 'facebook':
201
+ if (status === 200 && typeof data?.data?.url === 'string' && typeof data.data.is_silhouette === 'boolean') return 'taken';
202
+ if (status === 400 && data?.error?.type === 'GraphMethodException' && data.error.code === 100 &&
203
+ data.error.error_subcode === 33 && typeof data.error.message === 'string' &&
204
+ data.error.message.startsWith(`Unsupported get request. Object with ID '${name}' does not exist`)) {
205
+ return 'not-found';
206
+ }
207
+ break;
208
+ case 'twitch':
209
+ if (status === 200 && html) return twitchProfile(html, name);
210
+ break;
211
+ case 'googlePlay':
212
+ if (status === 200 && html) return classifyPlay(html, name);
213
+ break;
214
+ }
215
+ return 'unknown';
216
+ }
217
+
218
+ export const publicHeaders = Object.freeze({ 'accept-language': 'en-US,en;q=0.9', 'accept-encoding': 'gzip' });
219
+
220
+ const commonCrawlCollections = 'https://index.commoncrawl.org/collinfo.json';
221
+ const archiveJson = /^(?:application\/(?:[\w.+-]+\+)?json|(?:application|text)\/x-ndjson)\b/i;
222
+ const plainText = /^text\/plain\b/i;
223
+ export const readsArchiveBody = (status, type) => [200, 404].includes(status) && (archiveJson.test(type) || plainText.test(type));
224
+ const captureYear = timestamp => typeof timestamp === 'string' && /^(?:19|20)\d{12}$/.test(timestamp) ? Number(timestamp.slice(0, 4)) : null;
225
+ const archiveUnknown = response => ({ state: 'unknown', why: response.skipped ?? (response.error === 'timeout' ? 'timeout'
226
+ : response.status === 429 ? 'rate-limited' : 'archive lookup failed') });
227
+
228
+ function readArchive(response, provider, profile) {
229
+ const { status, contentType, body } = response;
230
+ if (response.skipped || response.error || typeof body !== 'string') return archiveUnknown(response);
231
+ const value = body.trim();
232
+ if (provider === 'wayback' && status === 200 && plainText.test(contentType)) {
233
+ if (!value) return { state: 'not-seen' };
234
+ const year = captureYear(value.match(/^(\d{14})\s+200$/)?.[1]);
235
+ if (year) return { state: 'taken', seenYear: year };
236
+ }
237
+ if (provider === 'commonCrawl' && archiveJson.test(contentType)) {
238
+ if (status === 200 && !value) return { state: 'not-seen' };
239
+ try {
240
+ const row = JSON.parse(value);
241
+ if (status === 404 && row?.message === `No Captures found for: ${profile}`) return { state: 'not-seen' };
242
+ const year = captureYear(row?.timestamp);
243
+ const url = new URL(row?.url);
244
+ const archived = url.hostname.replace(/^www\./, '') + url.pathname.replace(/\/$/, '');
245
+ if (status === 200 && String(row.status) === '200' && year && ['https:', 'http:'].includes(url.protocol) &&
246
+ !url.username && !url.password && !url.port && !url.search && archived.toLowerCase() === profile) return { state: 'taken', seenYear: year };
247
+ } catch { /* A malformed capture is not evidence. */ }
248
+ }
249
+ return archiveUnknown(response);
250
+ }
251
+
252
+ export async function findCommonCrawlIndex(request) {
253
+ const response = await request(commonCrawlCollections);
254
+ if (response.status === 200 && archiveJson.test(response.contentType) && !response.error) {
255
+ try {
256
+ const index = JSON.parse(response.body)?.[0]?.['cdx-api'];
257
+ if (/^https:\/\/index\.commoncrawl\.org\/CC-MAIN-\d{4}-\d{2}-index$/.test(index)) return { index };
258
+ } catch { /* Ignore unrecognized collections. */ }
259
+ }
260
+ return archiveUnknown(response);
261
+ }
262
+
263
+ export async function checkPublicArchives(kind, handle, request, getCommonIndex) {
264
+ const profile = archiveProfile(kind, handle);
265
+ const wayback = await request('https://web.archive.org/cdx/search/cdx?' + new URLSearchParams({
266
+ url: profile, limit: '1', fl: 'timestamp,statuscode', filter: 'statuscode:200',
267
+ })).then(response => readArchive(response, 'wayback', profile));
268
+ if (wayback.state !== 'unknown') return wayback;
269
+ const { index } = await getCommonIndex();
270
+ if (!index) return wayback;
271
+ const common = await request(index + '?' + new URLSearchParams({
272
+ url: profile, output: 'json', limit: '1', filter: '=status:200',
273
+ })).then(response => readArchive(response, 'commonCrawl', profile));
274
+ return common.state === 'unknown' ? wayback : common;
275
+ }
@@ -0,0 +1,54 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { appendFile, chmod, mkdir } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { dirname, join } from 'node:path';
5
+ import { scoreVersion } from './name-score.mjs';
6
+
7
+ // Local Name score calibration log, off by default. With DOMAIN_HOUND_SCORE_LOG=1 each shown, scored name appends one
8
+ // line to ~/.domain-hound/score-log.jsonl: component points, weights version, rank, band, which checks were not done,
9
+ // and later whether it was picked. Nothing leaves the machine. The name is written only with
10
+ // DOMAIN_HOUND_SCORE_LOG_NAMES=1; the brief, domains, reasons and evidence never are.
11
+ export function scoreLogger({ env = process.env, file = join(homedir(), '.domain-hound', 'score-log.jsonl'), now = () => new Date() } = {}) {
12
+ const enabled = env.DOMAIN_HOUND_SCORE_LOG === '1';
13
+ const withNames = env.DOMAIN_HOUND_SCORE_LOG_NAMES === '1';
14
+ // DNS label -> log id, for this server session only, so a later pick can point back without the name.
15
+ const shown = new Map();
16
+ const picked = new Set();
17
+ let writes = Promise.resolve();
18
+ const write = entries => {
19
+ if (!entries.length) return writes;
20
+ const text = entries.map(entry => JSON.stringify(entry) + '\n').join('');
21
+ writes = writes.then(async () => {
22
+ await mkdir(dirname(file), { recursive: true, mode: 0o700 });
23
+ await appendFile(file, text, { mode: 0o600 });
24
+ await chmod(file, 0o600).catch(() => {});
25
+ }).catch(() => {});
26
+ return writes;
27
+ };
28
+ return {
29
+ enabled,
30
+ // rows: [{ label, name, score }] in rank order, scored and not filtered.
31
+ shown(rows) {
32
+ if (!enabled) return Promise.resolve();
33
+ const at = now().toISOString();
34
+ return write(rows.flatMap((row, rank) => {
35
+ const score = row.score;
36
+ if (!Number.isInteger(score?.value) || !score.components) return [];
37
+ const id = randomUUID();
38
+ if (row.label) shown.set(row.label, id);
39
+ return [{ event: 'shown', at, id, weights: score.version ?? scoreVersion, rank: rank + 1, value: score.value, band: score.band,
40
+ components: score.components, unknown: score.unknown ?? [], notChecked: (score.notChecked ?? []).length,
41
+ ...(score.recipe && { recipe: score.recipe }), ...(withNames && typeof row.name === 'string' && { name: row.name }) }];
42
+ }));
43
+ },
44
+ // The person explicitly chose a domain whose label was shown in this session.
45
+ picked(domain, via) {
46
+ if (!enabled || typeof domain !== 'string') return Promise.resolve();
47
+ const id = shown.get(domain.toLowerCase().split('.')[0]);
48
+ if (!id || picked.has(id + via)) return Promise.resolve();
49
+ picked.add(id + via);
50
+ return write([{ event: 'picked', at: now().toISOString(), id, weights: scoreVersion, via }]);
51
+ },
52
+ flush: () => writes,
53
+ };
54
+ }
@@ -297,7 +297,10 @@ export async function checkHandles(name, options = {}) {
297
297
  };
298
298
  const social = options.social ? await options.social
299
299
  : (await checkSocialHandles([{ name, platforms: ['GitHub', 'npm'], links: false }], options)).get(name);
300
- const state = platform => social?.find(entry => entry.platform === platform)?.state ?? 'check';
300
+ const state = platform => {
301
+ const answer = social?.find(entry => entry.platform === platform)?.state;
302
+ return answer === 'taken' || answer === 'not-found' ? answer : 'check';
303
+ };
301
304
  const getGitHub = async () => {
302
305
  const status = state('GitHub');
303
306
  if (fresh(saved.githubSearch) && saved.githubSearch.result?.count !== undefined) {