sneakoscope 5.7.0 → 5.9.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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/config/competitor-scorecard-baseline.json +97 -0
  3. package/config/perf-budgets.v1.json +10 -0
  4. package/crates/sks-core/Cargo.lock +1 -1
  5. package/crates/sks-core/Cargo.toml +1 -1
  6. package/crates/sks-core/src/main.rs +1 -1
  7. package/dist/bin/sks.js +61 -1
  8. package/dist/cli/command-registry.js +2 -3
  9. package/dist/cli/commands-fast.js +20 -0
  10. package/dist/cli/root-fast.js +48 -0
  11. package/dist/cli/router.js +3 -0
  12. package/dist/cli/super-search-command.js +221 -0
  13. package/dist/cli/xai-command.js +7 -7
  14. package/dist/commands/doctor.js +56 -24
  15. package/dist/config/skills-manifest.json +63 -70
  16. package/dist/core/agents/agent-codex-cockpit.js +3 -3
  17. package/dist/core/agents/agent-orchestrator.js +20 -2
  18. package/dist/core/agents/agent-wrongness.js +1 -1
  19. package/dist/core/agents/native-cli-session-swarm.js +14 -1
  20. package/dist/core/agents/parallel-runtime-proof.js +82 -8
  21. package/dist/core/agents/parallel-write-fixture.js +301 -0
  22. package/dist/core/commands/gc-command.js +12 -6
  23. package/dist/core/commands/run-command.js +20 -18
  24. package/dist/core/doctor/doctor-idempotence.js +93 -0
  25. package/dist/core/errors/blocker-humanizer.js +13 -0
  26. package/dist/core/errors/next-action-map.js +56 -0
  27. package/dist/core/feature-fixtures.js +15 -8
  28. package/dist/core/fsx.js +1 -1
  29. package/dist/core/init/skills.js +1 -2
  30. package/dist/core/install/installed-package-smoke.js +121 -0
  31. package/dist/core/mission.js +41 -15
  32. package/dist/core/naruto/naruto-active-pool.js +6 -2
  33. package/dist/core/perf/perf-budget.js +145 -0
  34. package/dist/core/quality/competitor-scorecard.js +116 -0
  35. package/dist/core/release/gate-timing.js +103 -0
  36. package/dist/core/release-parallel-full-coverage.js +1 -1
  37. package/dist/core/retention/retention-budget.js +62 -0
  38. package/dist/core/retention.js +1 -1
  39. package/dist/core/routes/constants.js +2 -2
  40. package/dist/core/routes.js +155 -53
  41. package/dist/core/source-intelligence/source-intelligence-policy.js +5 -5
  42. package/dist/core/source-intelligence/source-intelligence-proof.js +8 -8
  43. package/dist/core/source-intelligence/source-intelligence-runner.js +16 -16
  44. package/dist/core/strategy/strategy-gate.js +2 -1
  45. package/dist/core/super-search/doctor.js +63 -0
  46. package/dist/core/super-search/runtime-helpers.js +289 -0
  47. package/dist/core/super-search/runtime.js +270 -0
  48. package/dist/core/super-search/source-records.js +96 -0
  49. package/dist/core/super-search/types.js +3 -0
  50. package/dist/core/trust-kernel/trust-report.js +3 -3
  51. package/dist/core/verification/real-evidence-policy.js +55 -0
  52. package/dist/core/version.js +1 -1
  53. package/dist/scripts/agent-fast-mode-default-check.js +10 -1
  54. package/dist/scripts/agent-visual-consistency-check.js +1 -1
  55. package/dist/scripts/check-architecture.js +0 -1
  56. package/dist/scripts/competitor-scorecard-check.js +25 -0
  57. package/dist/scripts/doctor-idempotence-check.js +8 -0
  58. package/dist/scripts/gate-timing-check.js +8 -0
  59. package/dist/scripts/hook-latency-quantum-check.js +122 -0
  60. package/dist/scripts/installed-package-smoke-check.js +12 -0
  61. package/dist/scripts/lib/native-cli-session-swarm-check-lib.js +2 -0
  62. package/dist/scripts/mutation-callsite-coverage-check.js +7 -0
  63. package/dist/scripts/package-published-contract-check.js +7 -0
  64. package/dist/scripts/packlist-performance-check.js +31 -3
  65. package/dist/scripts/parallel-production-smoke-check.js +21 -0
  66. package/dist/scripts/perf-budget-check.js +14 -0
  67. package/dist/scripts/quantum-baseline-report.js +38 -0
  68. package/dist/scripts/release-check-stamp.js +117 -16
  69. package/dist/scripts/release-metadata-1-19-check.js +2 -2
  70. package/dist/scripts/release-parallel-check.js +2 -2
  71. package/dist/scripts/release-parallel-full-coverage-check.js +1 -1
  72. package/dist/scripts/retention-budget-check.js +8 -0
  73. package/dist/scripts/route-intent-regression-check.js +44 -0
  74. package/dist/scripts/sks-1-18-gate-lib.js +2 -2
  75. package/dist/scripts/source-intelligence-all-modes-check.js +2 -2
  76. package/dist/scripts/source-intelligence-policy-check.js +1 -1
  77. package/dist/scripts/super-search-live-smoke-check.js +70 -0
  78. package/dist/scripts/super-search-name-guard-check.js +98 -0
  79. package/dist/scripts/super-search-offline-contract-check.js +45 -0
  80. package/dist/scripts/{ultra-search-provider-interface-check.js → super-search-provider-interface-check.js} +9 -9
  81. package/dist/scripts/trust-fixture-check.js +19 -6
  82. package/package.json +26 -8
  83. package/schemas/agents/parallel-runtime-proof.schema.json +17 -1
  84. package/dist/cli/insane-search-command.js +0 -195
  85. package/dist/core/ultra-search/runtime.js +0 -502
  86. package/dist/core/ultra-search/types.js +0 -3
  87. package/dist/scripts/release-readiness-report.js +0 -1262
  88. /package/dist/core/{ultra-search → super-search}/index.js +0 -0
@@ -0,0 +1,289 @@
1
+ import path from 'node:path';
2
+ import { nowIso, sha256, writeTextAtomic } from '../fsx.js';
3
+ import { evaluateRealEvidencePolicy } from '../verification/real-evidence-policy.js';
4
+ import { classifyAuthority, isOfficialUrl, makeSource, sourceFromKnownUrl } from './source-records.js';
5
+ export function normalizeGenericSourceRows(raw, providerId, family, intent, tier) {
6
+ const rows = Array.isArray(raw) ? raw : Array.isArray(raw?.results) ? raw.results : raw ? [raw] : [];
7
+ return rows.map((row, index) => {
8
+ const url = typeof row.url === 'string' ? row.url : typeof row.link === 'string' ? row.link : null;
9
+ return makeSource({
10
+ providerId,
11
+ family,
12
+ type: intent === 'official_documentation' ? 'official_docs' : 'web_result',
13
+ title: String(row.title || row.name || `${providerId} result ${index + 1}`),
14
+ url,
15
+ snippet: String(row.snippet || row.summary || row.text || ''),
16
+ verdict: providerId === 'context7' ? 'verified_content' : 'weak_content',
17
+ authority: tier,
18
+ primary: providerId === 'context7',
19
+ path: [providerId]
20
+ });
21
+ });
22
+ }
23
+ export function sourceFromWebRow(row, index, intent) {
24
+ return makeSource({
25
+ providerId: 'codex_web',
26
+ family: intent === 'x_specific' ? 'social' : 'web',
27
+ type: 'web_result',
28
+ title: row.title || `Codex Web result ${index + 1}`,
29
+ url: row.url,
30
+ snippet: row.snippet,
31
+ verdict: row.url ? 'weak_content' : 'partial_content',
32
+ authority: classifyAuthority(row.url),
33
+ primary: isOfficialUrl(row.url),
34
+ path: ['codex_web_search']
35
+ });
36
+ }
37
+ export async function sourceFromUrlFetch(url, artifactDir, intent) {
38
+ const warnings = [];
39
+ const blockers = [];
40
+ const fetchFn = globalThis.fetch;
41
+ if (typeof fetchFn !== 'function') {
42
+ blockers.push('direct_url_fetch_adapter_unavailable');
43
+ return {
44
+ source: { ...sourceFromKnownUrl(url, intent), blockers, warnings: ['url_parse_only'] },
45
+ blockers,
46
+ warnings
47
+ };
48
+ }
49
+ const controller = new AbortController();
50
+ const timer = setTimeout(() => controller.abort(), 10000);
51
+ try {
52
+ const response = await fetchFn(url, {
53
+ redirect: 'follow',
54
+ signal: controller.signal,
55
+ headers: { 'user-agent': 'sneakoscope-super-search/5.8' }
56
+ });
57
+ const text = await response.text();
58
+ const capped = text.length > 512 * 1024 ? text.slice(0, 512 * 1024) : text;
59
+ if (text.length > capped.length)
60
+ warnings.push('url_content_truncated');
61
+ const normalizedUrl = response.url || url;
62
+ if (!response.ok)
63
+ blockers.push(`direct_url_fetch_http_${response.status}`);
64
+ if (!capped.trim())
65
+ blockers.push('direct_url_fetch_empty_content');
66
+ const contentSha = capped.trim() ? sha256(capped) : null;
67
+ const relArtifact = contentSha ? path.join('url-content', `${contentSha.slice(0, 16)}.txt`) : null;
68
+ if (relArtifact)
69
+ await writeTextAtomic(path.join(artifactDir, relArtifact), capped);
70
+ const source = makeSource({
71
+ providerId: 'direct_url',
72
+ family: intent === 'x_specific' ? 'social' : 'web',
73
+ type: 'known_url',
74
+ title: normalizedUrl,
75
+ url: normalizedUrl,
76
+ snippet: capped.replace(/\s+/g, ' ').trim().slice(0, 500),
77
+ verdict: response.ok && capped.trim() ? 'verified_content' : 'blocked',
78
+ authority: classifyAuthority(normalizedUrl),
79
+ primary: isOfficialUrl(normalizedUrl),
80
+ path: ['direct_url_fetch'],
81
+ warnings,
82
+ blockers,
83
+ contentArtifact: relArtifact,
84
+ contentSha256: contentSha,
85
+ contentLength: capped.length
86
+ });
87
+ return { source, blockers, warnings };
88
+ }
89
+ catch (error) {
90
+ const reason = error instanceof Error && error.name === 'AbortError' ? 'direct_url_fetch_timeout' : 'direct_url_fetch_failed';
91
+ blockers.push(reason);
92
+ warnings.push(error instanceof Error ? error.message : String(error));
93
+ return {
94
+ source: { ...sourceFromKnownUrl(url, intent), blockers, warnings: [...warnings, 'url_parse_only'] },
95
+ blockers,
96
+ warnings
97
+ };
98
+ }
99
+ finally {
100
+ clearTimeout(timer);
101
+ }
102
+ }
103
+ export function buildXDiscoverySources(queries, intent) {
104
+ return queries.filter((query) => query.startsWith('site:')).slice(0, 2).map((query, index) => makeSource({
105
+ providerId: 'x_public',
106
+ family: 'social',
107
+ type: 'x_discovery_query',
108
+ title: `X public discovery query ${index + 1}`,
109
+ url: null,
110
+ snippet: query,
111
+ verdict: 'partial_content',
112
+ authority: 'D',
113
+ primary: false,
114
+ path: ['web_index_discovery'],
115
+ warnings: ['discovery_only']
116
+ }));
117
+ }
118
+ export function dedupeSources(sources) {
119
+ const seen = new Map();
120
+ return sources.map((source) => {
121
+ const key = source.canonical_url || source.content_sha256 || source.source_id;
122
+ const cluster = seen.get(key);
123
+ if (cluster)
124
+ return { ...source, duplicate_cluster_id: cluster };
125
+ seen.set(key, source.source_id);
126
+ return { ...source, duplicate_cluster_id: source.source_id };
127
+ }).filter((source) => source.duplicate_cluster_id === source.source_id);
128
+ }
129
+ export function buildLeads(sources, mode) {
130
+ if (mode === 'fast')
131
+ return [];
132
+ return sources.filter((source) => source.acquisition_verdict !== 'verified_content').slice(0, 4).map((source, index) => ({
133
+ event_id: `lead-event-${index + 1}`,
134
+ parent_task_id: 'wave-001',
135
+ wave: 1,
136
+ lead_id: `lead-${sha256(source.source_id).slice(0, 10)}`,
137
+ kind: source.blockers.length ? 'dead_end' : 'source',
138
+ summary: `Hydrate or verify ${source.title}`,
139
+ why_it_matters: 'Weak or partial source cannot support final high-risk claims.',
140
+ suggested_query: source.canonical_url || source.title,
141
+ source_ids: [source.source_id],
142
+ priority: source.source_family === 'social' ? 'P1' : 'P0'
143
+ }));
144
+ }
145
+ export function buildClaims(query, sources, mode, intent) {
146
+ const verifiedSources = sources.filter((source) => source.acquisition_verdict === 'verified_content');
147
+ const primary = verifiedSources.filter((source) => source.primary_source);
148
+ const domains = [...new Set(verifiedSources.map((source) => source.domain).filter(Boolean))];
149
+ const highRisk = ['legal_or_policy', 'market_or_financial', 'news'].includes(intent);
150
+ const status = highRisk
151
+ ? (domains.length >= 2 && primary.length >= 1 ? 'supported' : 'unresolved')
152
+ : verifiedSources.length ? 'supported' : sources.length && mode !== 'x_search' ? 'unresolved' : 'unresolved';
153
+ const sourceIds = status === 'supported' ? verifiedSources.map((source) => source.source_id) : sources.map((source) => source.source_id);
154
+ return [{
155
+ claim_id: `claim-${sha256(query).slice(0, 12)}`,
156
+ text: `Evidence gathered for query: ${query}`,
157
+ claim_type: intent === 'code_implementation' ? 'code_behavior' : intent === 'x_specific' ? 'social_signal' : 'capability',
158
+ risk: highRisk ? 'high' : 'normal',
159
+ source_ids: sourceIds,
160
+ independent_domains: domains,
161
+ primary_source_ids: primary.map((source) => source.source_id),
162
+ counter_search_ids: [],
163
+ verification_artifacts: [],
164
+ status
165
+ }];
166
+ }
167
+ export function buildConvergence(mode, leads, blockers) {
168
+ const minimum = mode === 'deep' || mode === 'exhaustive' ? 2 : 1;
169
+ const waves = mode === 'deep' || mode === 'exhaustive' ? 2 : 1;
170
+ const open = leads.filter((lead) => lead.kind !== 'dead_end').length;
171
+ return {
172
+ schema: 'sks.super-search-convergence.v1',
173
+ waves_completed: waves,
174
+ minimum_waves_required: minimum,
175
+ new_leads_per_wave: waves === 2 ? [leads.length, 0] : [leads.length],
176
+ unchecked_leads: open,
177
+ consecutive_zero_lead_waves: waves === 2 ? 1 : 0,
178
+ max_depth: mode === 'exhaustive' ? 5 : 3,
179
+ status: blockers.length ? 'blocked_by_source_access' : open ? 'bounded_with_open_leads' : 'converged',
180
+ reason: blockers.length ? 'source_access_blocker_recorded' : open ? 'bounded_runtime_left_weak_sources_as_open_leads' : 'all_leads_closed'
181
+ };
182
+ }
183
+ export function buildProof(mode, intent, sources, claims, convergence, blockers, warnings) {
184
+ const unresolvedHighRisk = claims.filter((claim) => claim.risk === 'high' && claim.status === 'unresolved').length;
185
+ const weakContentFinalClaims = claims.filter((claim) => claim.status === 'supported' && claim.source_ids.some((id) => {
186
+ const source = sources.find((candidate) => candidate.source_id === id);
187
+ return source?.acquisition_verdict === 'weak_content' || source?.acquisition_verdict === 'partial_content';
188
+ })).length;
189
+ const proofBlockers = [...blockers];
190
+ if (unresolvedHighRisk)
191
+ proofBlockers.push('high_risk_claim_unresolved');
192
+ if (weakContentFinalClaims)
193
+ proofBlockers.push('weak_content_used_for_supported_claim');
194
+ if (mode === 'x_search' && sources.every((source) => source.acquisition_verdict !== 'verified_content')) {
195
+ proofBlockers.push('x_search_parity_not_proven');
196
+ }
197
+ const realEvidencePolicy = evaluateRealEvidencePolicy({
198
+ productionMode: true,
199
+ mode,
200
+ sources,
201
+ claims,
202
+ proof: {
203
+ verified_source_count: sources.filter((source) => source.acquisition_verdict === 'verified_content').length,
204
+ mock_only: false
205
+ }
206
+ });
207
+ proofBlockers.push(...realEvidencePolicy.blockers);
208
+ warnings.push(...realEvidencePolicy.warnings);
209
+ return {
210
+ schema: 'sks.super-search-proof.v1',
211
+ ok: proofBlockers.length === 0,
212
+ mode,
213
+ intent,
214
+ provider_independent: true,
215
+ xai_runtime_dependency: false,
216
+ snippet_only_final_claims: weakContentFinalClaims,
217
+ weak_content_final_claims: weakContentFinalClaims,
218
+ source_count: sources.length,
219
+ verified_source_count: sources.filter((source) => source.acquisition_verdict === 'verified_content').length,
220
+ claim_count: claims.length,
221
+ unresolved_high_risk_claims: unresolvedHighRisk,
222
+ convergence,
223
+ blockers: [...new Set(proofBlockers)],
224
+ warnings: [...new Set(warnings)]
225
+ };
226
+ }
227
+ export function renderSynthesis(query, sources, claims, proof) {
228
+ const usable = claims.filter((claim) => claim.status === 'verified' || (claim.status === 'supported' && claim.risk !== 'high'));
229
+ return [
230
+ '# Super-Search Synthesis',
231
+ '',
232
+ `Query: ${query}`,
233
+ `Status: ${proof.ok ? 'usable' : 'blocked_or_partial'}`,
234
+ '',
235
+ `Usable claims: ${usable.length}`,
236
+ `Sources: ${sources.length}`,
237
+ `Verified sources: ${proof.verified_source_count}`,
238
+ '',
239
+ proof.blockers.length ? `Blockers: ${proof.blockers.join(', ')}` : 'Blockers: none'
240
+ ].join('\n');
241
+ }
242
+ export function buildAttemptLedger(providerPlan, mode, blockers, warnings) {
243
+ const attempts = [];
244
+ const hasBlocker = (id) => blockers.includes(id);
245
+ const hasWarning = (id) => warnings.includes(id);
246
+ if (providerPlan.selected_providers.includes('context7')) {
247
+ attempts.push({ id: 'attempt-001', strategy: 'context7-official-docs', status: 'completed', reason: 'provider_bound', next_strategy: null });
248
+ }
249
+ else if (hasWarning('context7_docs_provider_not_bound') || hasWarning('context7_not_invoked_for_docs_query')) {
250
+ attempts.push({ id: 'attempt-001', strategy: 'context7-official-docs', status: 'skipped', reason: 'runtime_adapter_unavailable', next_strategy: 'codex-web-search' });
251
+ }
252
+ if (providerPlan.selected_providers.includes('codex_web')) {
253
+ attempts.push({ id: `attempt-${String(attempts.length + 1).padStart(3, '0')}`, strategy: 'codex-web-search', status: 'completed', reason: 'provider_bound', next_strategy: null });
254
+ }
255
+ else if (hasWarning('codex_web_search_not_bound_or_unverified') || hasBlocker('source_acquisition_unavailable')) {
256
+ attempts.push({ id: `attempt-${String(attempts.length + 1).padStart(3, '0')}`, strategy: 'codex-web-search', status: 'failed', reason: 'runtime_adapter_unavailable', next_strategy: mode === 'url_acquisition' ? 'direct-url-acquisition' : null });
257
+ }
258
+ if (mode === 'url_acquisition') {
259
+ attempts.push({
260
+ id: `attempt-${String(attempts.length + 1).padStart(3, '0')}`,
261
+ strategy: 'direct-url-acquisition',
262
+ status: hasBlocker('missing_url_for_super_search_fetch') ? 'blocked' : 'completed',
263
+ reason: hasBlocker('missing_url_for_super_search_fetch') ? 'missing_url_for_super_search_fetch' : 'url_present',
264
+ next_strategy: null
265
+ });
266
+ }
267
+ if (mode === 'x_search') {
268
+ attempts.push({
269
+ id: `attempt-${String(attempts.length + 1).padStart(3, '0')}`,
270
+ strategy: 'x-public-discovery',
271
+ status: hasBlocker('x_search_parity_not_proven') ? 'blocked' : 'completed',
272
+ reason: hasBlocker('x_search_parity_not_proven') ? 'discovery_only_without_verified_detail' : 'discovery_completed',
273
+ next_strategy: null
274
+ });
275
+ }
276
+ const failedByStrategy = attempts.reduce((map, attempt) => {
277
+ map.set(attempt.strategy, (map.get(attempt.strategy) || 0) + (attempt.status === 'failed' ? 1 : 0));
278
+ return map;
279
+ }, new Map());
280
+ return {
281
+ schema: 'sks.attempt-ledger.v1',
282
+ attempts,
283
+ repeated_failed_strategy_count: [...failedByStrategy.values()].filter((count) => count > 1).reduce((sum, count) => sum + count - 1, 0)
284
+ };
285
+ }
286
+ export function extractFirstUrl(text) {
287
+ return text.match(/https?:\/\/[^\s)"']+/i)?.[0] || null;
288
+ }
289
+ //# sourceMappingURL=runtime-helpers.js.map
@@ -0,0 +1,270 @@
1
+ import path from 'node:path';
2
+ import { ensureDir, nowIso, readJson, sha256, writeJsonAtomic, writeTextAtomic } from '../fsx.js';
3
+ import { runCodexWebSearch } from '../codex/codex-web-search-adapter.js';
4
+ import { humanizeBlockers } from '../errors/blocker-humanizer.js';
5
+ import { buildAttemptLedger, buildClaims, buildConvergence, buildLeads, buildProof, buildXDiscoverySources, dedupeSources, extractFirstUrl, normalizeGenericSourceRows, renderSynthesis, sourceFromUrlFetch, sourceFromWebRow } from './runtime-helpers.js';
6
+ export async function runSuperSearch(input) {
7
+ const root = path.resolve(input.root || process.cwd());
8
+ const missionDir = path.resolve(input.missionDir);
9
+ const missionId = input.missionId || path.basename(missionDir);
10
+ const artifactDir = path.join(missionDir, 'super-search');
11
+ await ensureDir(artifactDir);
12
+ const mode = resolveMode(input.query, input.mode, input.offline === true);
13
+ const intent = classifyIntent(input.query, mode);
14
+ const axes = buildAxes(input.query, mode, intent);
15
+ const queryVariants = buildQueryVariants(input.query, mode, intent);
16
+ const cache = await readCache(artifactDir, input.query, mode);
17
+ if (cache.hit && !cache.stale && cache.result) {
18
+ const cached = cache.result;
19
+ return {
20
+ ...cached,
21
+ generated_at: nowIso(),
22
+ cache: { ...cached.cache, hit: true, stale: false, age_ms: cache.age_ms }
23
+ };
24
+ }
25
+ const providerPlan = planProviders(intent, mode, input.offline === true, Boolean(input.context7), Boolean(input.codexWebSearch), input.env);
26
+ const sourceRows = [];
27
+ const warnings = [...providerPlan.warnings];
28
+ const blockers = [...providerPlan.blockers];
29
+ if (!providerPlan.selected_providers.length && mode !== 'url_acquisition')
30
+ blockers.push('source_acquisition_unavailable');
31
+ if (input.context7 && providerPlan.selected_providers.includes('context7')) {
32
+ const raw = await input.context7(queryVariants[0] || input.query);
33
+ sourceRows.push(...normalizeGenericSourceRows(raw, 'context7', 'official_docs', intent, 'A0'));
34
+ }
35
+ else if (intent === 'official_documentation' && !input.offline) {
36
+ warnings.push('context7_not_invoked_for_docs_query');
37
+ }
38
+ if (providerPlan.selected_providers.includes('codex_web')) {
39
+ const webEvidence = await runCodexWebSearch(queryVariants[0] || input.query, {
40
+ ...(input.codexWebSearch ? { search: input.codexWebSearch } : {}),
41
+ artifactDir,
42
+ ...(input.offline === undefined ? {} : { offline: input.offline }),
43
+ ...(input.env ? { env: input.env } : {})
44
+ });
45
+ if (webEvidence.blockers.length)
46
+ blockers.push(...webEvidence.blockers);
47
+ warnings.push(...webEvidence.warnings);
48
+ sourceRows.push(...webEvidence.normalized_results.map((row, index) => sourceFromWebRow(row, index, intent)));
49
+ }
50
+ if (mode === 'url_acquisition') {
51
+ const url = extractFirstUrl(input.query);
52
+ if (url) {
53
+ const fetched = await sourceFromUrlFetch(url, artifactDir, intent);
54
+ sourceRows.push(fetched.source);
55
+ blockers.push(...fetched.blockers);
56
+ warnings.push(...fetched.warnings);
57
+ }
58
+ else
59
+ blockers.push('missing_url_for_super_search_fetch');
60
+ }
61
+ if (mode === 'x_search') {
62
+ sourceRows.push(...buildXDiscoverySources(queryVariants, intent));
63
+ warnings.push('x_public_results_are_discovery_until_post_detail_or_authenticated_source_verifies_full_text');
64
+ }
65
+ const deduped = dedupeSources(sourceRows);
66
+ const leads = buildLeads(deduped, mode);
67
+ const claims = buildClaims(input.query, deduped, mode, intent);
68
+ const convergence = buildConvergence(mode, leads, blockers);
69
+ const proof = buildProof(mode, intent, deduped, claims, convergence, blockers, warnings);
70
+ const attemptLedger = buildAttemptLedger(providerPlan, mode, proof.blockers, proof.warnings);
71
+ const synthesis = renderSynthesis(input.query, deduped, claims, proof);
72
+ const result = {
73
+ schema: 'sks.super-search-result.v1',
74
+ generated_at: nowIso(),
75
+ ok: proof.ok,
76
+ mission_id: missionId,
77
+ artifact_dir: artifactDir,
78
+ query: input.query,
79
+ mode,
80
+ intent,
81
+ axes,
82
+ query_variants: queryVariants,
83
+ provider_plan: providerPlan,
84
+ sources: deduped,
85
+ leads,
86
+ claims,
87
+ convergence,
88
+ proof,
89
+ attempt_ledger: attemptLedger,
90
+ synthesis,
91
+ blockers: proof.blockers,
92
+ warnings: proof.warnings,
93
+ cache: {
94
+ key: cache.key,
95
+ hit: false,
96
+ stale: cache.stale,
97
+ ttl_ms: cache.ttl_ms,
98
+ age_ms: cache.age_ms,
99
+ artifact: cache.artifact
100
+ }
101
+ };
102
+ await writeArtifacts(artifactDir, result);
103
+ await writeJsonAtomic(cache.artifact, result);
104
+ return result;
105
+ }
106
+ export function resolveMode(query, explicit, offline = false) {
107
+ if (explicit)
108
+ return explicit;
109
+ if (offline)
110
+ return 'offline_cache';
111
+ if (extractFirstUrl(query))
112
+ return 'url_acquisition';
113
+ if (/\b(?:x\.com|twitter\.com|X\/Twitter|트위터|엑스|site:x\.com|site:twitter\.com)\b/i.test(query))
114
+ return 'x_search';
115
+ if (/(deep research|exhaustive|가능한 전부|누락 없이|완벽하게 조사|due diligence)/i.test(query))
116
+ return 'deep';
117
+ return 'balanced';
118
+ }
119
+ export function classifyIntent(query, mode) {
120
+ if (mode === 'x_search')
121
+ return 'x_specific';
122
+ if (mode === 'url_acquisition')
123
+ return 'known_url_fetch';
124
+ if (/\b(package|npm|SDK|API|MCP|framework|library|docs?|문서|React|Next\.js|Prisma|Tailwind)\b/i.test(query))
125
+ return 'official_documentation';
126
+ if (/\b(error|bug|stack trace|implementation|code|repo|GitHub|테스트|구현)\b/i.test(query))
127
+ return 'code_implementation';
128
+ if (/\b(news|today|latest|최근|오늘|발표)\b/i.test(query))
129
+ return 'news';
130
+ if (/\b(legal|law|policy|규정|법)\b/i.test(query))
131
+ return 'legal_or_policy';
132
+ return 'current_fact';
133
+ }
134
+ export function buildAxes(query, mode, intent) {
135
+ const base = [
136
+ {
137
+ axis_id: 'axis-primary',
138
+ question: `Primary or official evidence for: ${query}`,
139
+ territories: intent === 'official_documentation' ? ['official_docs', 'changelog'] : ['primary_source', 'official_statement'],
140
+ done_when: ['primary source found or explicit blocker recorded', 'date/version checked'],
141
+ priority: 'P0',
142
+ overlap_keys: []
143
+ },
144
+ {
145
+ axis_id: 'axis-current',
146
+ question: `Current indexed or live evidence for: ${query}`,
147
+ territories: ['web_search', 'freshness', 'source_date'],
148
+ done_when: ['fresh result checked', 'stale evidence warning recorded when needed'],
149
+ priority: 'P0',
150
+ overlap_keys: ['axis-primary']
151
+ },
152
+ {
153
+ axis_id: 'axis-counter',
154
+ question: `Counter evidence, limitations, or failures for: ${query}`,
155
+ territories: ['counter_search', 'contradictions', 'known_failures'],
156
+ done_when: ['counter query produced evidence or no-source gap recorded'],
157
+ priority: 'P1',
158
+ overlap_keys: []
159
+ }
160
+ ];
161
+ if (mode === 'deep' || mode === 'exhaustive') {
162
+ base.push({
163
+ axis_id: 'axis-community',
164
+ question: `Independent implementation or community evidence for: ${query}`,
165
+ territories: ['github', 'issues', 'forums', 'social_discourse'],
166
+ done_when: ['independent domains clustered', 'social-only evidence kept out of primary capability claims'],
167
+ priority: 'P1',
168
+ overlap_keys: ['axis-current']
169
+ });
170
+ }
171
+ if (mode === 'x_search') {
172
+ base.push({
173
+ axis_id: 'axis-x-detail',
174
+ question: `Public X post detail and freshness checks for: ${query}`,
175
+ territories: ['x_web_index', 'known_post_detail', 'profile_timeline', 'authenticated_readonly_optional'],
176
+ done_when: ['discovery-only items are not promoted to full evidence', 'auth-required gaps disclosed'],
177
+ priority: 'P0',
178
+ overlap_keys: []
179
+ });
180
+ }
181
+ return base;
182
+ }
183
+ export function buildQueryVariants(query, mode, intent) {
184
+ const clean = query.trim();
185
+ const variants = new Set([clean]);
186
+ if (intent === 'official_documentation')
187
+ variants.add(`${clean} official docs changelog`);
188
+ if (intent === 'code_implementation')
189
+ variants.add(`${clean} GitHub issue fix`);
190
+ variants.add(`${clean} limitations OR failure`);
191
+ if (mode === 'x_search') {
192
+ variants.add(`site:x.com "${clean.replace(/"/g, '')}"`);
193
+ variants.add(`site:twitter.com "${clean.replace(/"/g, '')}"`);
194
+ }
195
+ if (mode === 'deep' || mode === 'exhaustive')
196
+ variants.add(`${clean} counter evidence`);
197
+ return [...variants].slice(0, mode === 'fast' ? 4 : mode === 'exhaustive' ? 12 : 8);
198
+ }
199
+ function planProviders(intent, mode, offline, hasContext7, hasCodexWeb, env = process.env) {
200
+ const selected_capabilities = ['source_normalization', 'claim_ledger', 'citation_graph', 'cache_read_through'];
201
+ const selected_providers = [];
202
+ const blockers = [];
203
+ const warnings = [];
204
+ if (intent === 'official_documentation') {
205
+ selected_capabilities.push('official_docs');
206
+ if (hasContext7)
207
+ selected_providers.push('context7');
208
+ else
209
+ warnings.push('context7_docs_provider_not_bound');
210
+ }
211
+ if (!offline && (hasCodexWeb || env.SKS_CODEX_WEB_SEARCH_AVAILABLE === '1' || env.CODEX_WEB_SEARCH_AVAILABLE === '1')) {
212
+ selected_capabilities.push('web_search');
213
+ selected_providers.push('codex_web');
214
+ }
215
+ else if (!offline) {
216
+ warnings.push('codex_web_search_not_bound_or_unverified');
217
+ }
218
+ if (mode === 'x_search') {
219
+ selected_capabilities.push('social_recency', 'x_public_discovery');
220
+ selected_providers.push('x_public');
221
+ }
222
+ if (offline)
223
+ selected_providers.push('offline_cache');
224
+ return { selected_capabilities, selected_providers: [...new Set(selected_providers)], blockers, warnings };
225
+ }
226
+ async function writeArtifacts(artifactDir, result) {
227
+ await writeJsonAtomic(path.join(artifactDir, 'intent.json'), { schema: 'sks.super-search-intent.v1', intent: result.intent, mode: result.mode });
228
+ await writeJsonAtomic(path.join(artifactDir, 'axes.json'), { schema: 'sks.super-search-axes.v1', axes: result.axes });
229
+ await writeJsonAtomic(path.join(artifactDir, 'query-variants.json'), { schema: 'sks.super-search-query-variants.v1', query_variants: result.query_variants });
230
+ await writeJsonAtomic(path.join(artifactDir, 'provider-plan.json'), { schema: 'sks.super-search-provider-plan.v1', ...result.provider_plan });
231
+ await writeJsonAtomic(path.join(artifactDir, 'source-ledger.json'), { schema: 'sks.super-search-source-ledger.v1', sources: result.sources });
232
+ await writeJsonAtomic(path.join(artifactDir, 'lead-ledger.json'), { schema: 'sks.super-search-lead-ledger.v1', leads: result.leads });
233
+ await writeJsonAtomic(path.join(artifactDir, 'claim-ledger.json'), { schema: 'sks.super-search-claim-ledger.v1', claims: result.claims });
234
+ await writeJsonAtomic(path.join(artifactDir, 'attempt-ledger.json'), result.attempt_ledger);
235
+ await writeJsonAtomic(path.join(artifactDir, 'convergence.json'), result.convergence);
236
+ await writeJsonAtomic(path.join(artifactDir, 'super-search-proof.json'), result.proof);
237
+ const gateEvidencePaths = [
238
+ path.join(artifactDir, 'source-ledger.json'),
239
+ path.join(artifactDir, 'claim-ledger.json'),
240
+ path.join(artifactDir, 'super-search-proof.json'),
241
+ path.join(artifactDir, 'super-search-result.json')
242
+ ];
243
+ const blockerDiagnostics = humanizeBlockers(result.proof.blockers, gateEvidencePaths);
244
+ await writeJsonAtomic(path.join(artifactDir, 'super-search-gate.json'), {
245
+ schema: 'sks.super-search-gate.v1',
246
+ ok: result.proof.ok,
247
+ passed: result.proof.ok,
248
+ execution_class: 'production',
249
+ mock_only: false,
250
+ replacement_state: result.proof.ok ? 'usable_provider_independent_runtime' : 'replacement_incomplete',
251
+ blockers: result.proof.blockers,
252
+ human_summary: blockerDiagnostics.human_summary,
253
+ next_actions: blockerDiagnostics.next_actions,
254
+ evidence_paths: blockerDiagnostics.evidence_paths,
255
+ warnings: result.proof.warnings
256
+ });
257
+ await writeTextAtomic(path.join(artifactDir, 'synthesis.md'), result.synthesis);
258
+ await writeJsonAtomic(path.join(artifactDir, 'super-search-result.json'), result);
259
+ }
260
+ async function readCache(artifactDir, query, mode) {
261
+ const key = sha256(JSON.stringify({ query: query.trim().toLowerCase(), mode, adapter: 'super-search-runtime-v1' })).slice(0, 16);
262
+ const artifact = path.join(artifactDir, 'cache', `${key}.json`);
263
+ const ttl_ms = mode === 'x_search' ? 2 * 60 * 1000 : mode === 'offline_cache' ? 7 * 24 * 60 * 60 * 1000 : 10 * 60 * 1000;
264
+ const cached = await readJson(artifact, null);
265
+ if (!cached?.generated_at)
266
+ return { key, artifact, ttl_ms, hit: false, stale: false, age_ms: null, result: null };
267
+ const age_ms = Date.now() - Date.parse(cached.generated_at);
268
+ return { key, artifact, ttl_ms, hit: true, stale: age_ms > ttl_ms, age_ms, result: cached };
269
+ }
270
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,96 @@
1
+ import { nowIso, sha256 } from '../fsx.js';
2
+ export function sourceFromKnownUrl(url, intent) {
3
+ return makeSource({
4
+ providerId: 'direct_url',
5
+ family: intent === 'x_specific' ? 'social' : 'web',
6
+ type: 'known_url',
7
+ title: url,
8
+ url,
9
+ snippet: '',
10
+ verdict: 'weak_content',
11
+ authority: classifyAuthority(url),
12
+ primary: isOfficialUrl(url),
13
+ path: ['url_parse_only']
14
+ });
15
+ }
16
+ export function makeSource(opts) {
17
+ const now = nowIso();
18
+ const canonical = opts.url ? canonicalizeUrl(opts.url) : null;
19
+ const domain = canonical ? safeDomain(canonical) : null;
20
+ const content = `${opts.title}\n${opts.snippet}`;
21
+ const verified = opts.verdict === 'verified_content';
22
+ return {
23
+ source_id: `src-${sha256(`${opts.providerId}:${canonical || opts.title}:${opts.snippet}`).slice(0, 12)}`,
24
+ provider_id: opts.providerId,
25
+ source_family: opts.family,
26
+ source_type: opts.type,
27
+ title: opts.title,
28
+ canonical_url: canonical,
29
+ original_url: opts.url,
30
+ domain,
31
+ author: null,
32
+ published_at: null,
33
+ updated_at: null,
34
+ retrieved_at: now,
35
+ language: null,
36
+ snippet: opts.snippet,
37
+ content_artifact: opts.contentArtifact ?? null,
38
+ content_sha256: opts.contentSha256 ?? (content.trim() ? sha256(content) : null),
39
+ content_length: opts.contentLength ?? (content.trim().length || null),
40
+ acquisition_verdict: opts.verdict,
41
+ acquisition_path: opts.path,
42
+ authority_tier: opts.authority,
43
+ freshness_score: 0.5,
44
+ relevance_score: 0.6,
45
+ trust_score: verified ? 0.9 : opts.verdict === 'weak_content' ? 0.55 : 0.35,
46
+ primary_source: opts.primary,
47
+ authenticated_source: false,
48
+ local_only_raw: false,
49
+ duplicate_cluster_id: null,
50
+ independence_cluster_id: domain || opts.providerId,
51
+ warnings: opts.warnings || [],
52
+ blockers: opts.blockers || []
53
+ };
54
+ }
55
+ function canonicalizeUrl(raw) {
56
+ try {
57
+ const url = new URL(raw);
58
+ url.hash = '';
59
+ for (const key of [...url.searchParams.keys()]) {
60
+ if (/^(utm_|fbclid|gclid|mc_cid|mc_eid)/i.test(key))
61
+ url.searchParams.delete(key);
62
+ }
63
+ url.hostname = url.hostname.toLowerCase();
64
+ return url.toString();
65
+ }
66
+ catch {
67
+ return raw;
68
+ }
69
+ }
70
+ function safeDomain(raw) {
71
+ try {
72
+ return new URL(raw).hostname.toLowerCase();
73
+ }
74
+ catch {
75
+ return null;
76
+ }
77
+ }
78
+ export function isOfficialUrl(raw) {
79
+ if (!raw)
80
+ return false;
81
+ const domain = safeDomain(raw);
82
+ return Boolean(domain && /(docs\.|developer|github\.com|npmjs\.com|nodejs\.org|w3\.org|ietf\.org|gov$|\.gov$)/i.test(domain));
83
+ }
84
+ export function classifyAuthority(raw) {
85
+ if (!raw)
86
+ return 'E';
87
+ if (isOfficialUrl(raw))
88
+ return 'A0';
89
+ const domain = safeDomain(raw);
90
+ if (domain && /(github\.com|npmjs\.com|arxiv\.org|doi\.org)/i.test(domain))
91
+ return 'A1';
92
+ if (domain && /(x\.com|twitter\.com|reddit\.com|news\.ycombinator\.com)/i.test(domain))
93
+ return 'D';
94
+ return 'C';
95
+ }
96
+ //# sourceMappingURL=source-records.js.map
@@ -0,0 +1,3 @@
1
+ export const SUPER_SEARCH_PROOF_SCHEMA = 'sks.super-search-proof.v1';
2
+ export const SUPER_SEARCH_GATE_SCHEMA = 'sks.super-search-gate.v1';
3
+ //# sourceMappingURL=types.js.map