sneakoscope 6.1.0 → 6.2.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 (246) hide show
  1. package/README.md +35 -11
  2. package/crates/sks-core/Cargo.lock +1 -1
  3. package/crates/sks-core/Cargo.toml +1 -1
  4. package/dist/bin/fast-inline.js +18 -9
  5. package/dist/bin/sks-dispatch.js +2 -2
  6. package/dist/cli/args.js +2 -0
  7. package/dist/cli/command-manifest-lite.js +2 -3
  8. package/dist/cli/command-registry.js +3 -4
  9. package/dist/cli/help-fast.js +1 -1
  10. package/dist/cli/install-helpers.js +116 -306
  11. package/dist/cli/install-tool-helpers.js +287 -0
  12. package/dist/cli/router.js +40 -4
  13. package/dist/commands/codex-lb.js +51 -20
  14. package/dist/commands/codex.js +39 -1
  15. package/dist/commands/doctor.js +242 -20
  16. package/dist/commands/tmux.js +5 -1
  17. package/dist/commands/zellij-monitor-pane.js +2 -0
  18. package/dist/commands/zellij-viewport-pane.js +3 -1
  19. package/dist/commands/zellij.js +1 -1
  20. package/dist/config/skills-manifest.json +59 -59
  21. package/dist/core/agent-bridge/agent-manifest.js +48 -0
  22. package/dist/core/agents/agent-command-surface.js +2 -1
  23. package/dist/core/agents/agent-effort-policy.js +38 -35
  24. package/dist/core/agents/agent-plan.js +100 -21
  25. package/dist/core/agents/agent-role-config.js +43 -46
  26. package/dist/core/agents/agent-runner-codex-exec.js +16 -3
  27. package/dist/core/agents/agent-schema.js +3 -2
  28. package/dist/core/agents/native-cli-session-swarm.js +1 -1
  29. package/dist/core/agents/zellij-right-lane-cockpit.js +2 -2
  30. package/dist/core/codex/agent-config-file-repair.js +94 -193
  31. package/dist/core/codex/codex-cli-update.js +723 -0
  32. package/dist/core/codex/codex-config-guard.js +185 -9
  33. package/dist/core/codex/codex-config-readability.js +21 -8
  34. package/dist/core/codex/codex-config-toml.js +14 -11
  35. package/dist/core/codex/codex-project-config-policy.js +3 -6
  36. package/dist/core/codex/codex-startup-config-postcheck.js +52 -42
  37. package/dist/core/codex-adapter.js +35 -22
  38. package/dist/core/codex-app/codex-agent-role-sync.js +13 -54
  39. package/dist/core/codex-app/codex-app-launcher.js +48 -17
  40. package/dist/core/codex-app/codex-app-restart.js +23 -2
  41. package/dist/core/codex-app/mcp-manager.js +679 -0
  42. package/dist/core/codex-app/sks-menubar.js +533 -8
  43. package/dist/core/codex-control/codex-0139-image-path-real-probe.js +15 -4
  44. package/dist/core/codex-control/codex-0139-web-search-probe.js +17 -6
  45. package/dist/core/codex-control/codex-lb-launch-recovery.js +293 -0
  46. package/dist/core/codex-control/codex-reliability-shield.js +89 -29
  47. package/dist/core/codex-control/codex-sdk-adapter.js +44 -8
  48. package/dist/core/codex-control/codex-task-runner.js +62 -9
  49. package/dist/core/codex-control/python-codex-sdk-adapter.js +30 -3
  50. package/dist/core/codex-exec-output-schema.js +35 -6
  51. package/dist/core/codex-lb/codex-lb-env.js +1 -1
  52. package/dist/core/codex-lb/codex-lb-tool-output-recovery.js +291 -0
  53. package/dist/core/codex-native/codex-native-feature-broker.js +9 -16
  54. package/dist/core/codex-native/codex-native-repair-transaction.js +1 -1
  55. package/dist/core/codex-native/core-skill-manifest.js +8 -4
  56. package/dist/core/codex-runtime/codex-desktop-config-policy.js +2 -3
  57. package/dist/core/commands/agent-bridge-command.js +23 -2
  58. package/dist/core/commands/agent-command.js +19 -5
  59. package/dist/core/commands/basic-cli.js +47 -6
  60. package/dist/core/commands/command-utils.js +1 -1
  61. package/dist/core/commands/mad-sks-command.js +76 -10
  62. package/dist/core/commands/menubar-command.js +94 -0
  63. package/dist/core/commands/naruto-command.js +645 -1156
  64. package/dist/core/commands/research-command.js +293 -231
  65. package/dist/core/commands/run-command.js +100 -23
  66. package/dist/core/commands/team-command.js +2 -3
  67. package/dist/core/commands/team-legacy-observe-command.js +94 -359
  68. package/dist/core/commands/wiki-command.js +11 -5
  69. package/dist/core/db-safety.js +2 -2
  70. package/dist/core/decision-lattice.js +6 -6
  71. package/dist/core/doctor/codex-startup-config-repair.js +8 -3
  72. package/dist/core/doctor/doctor-codex-startup-repair.js +6 -141
  73. package/dist/core/feature-fixture-executor.js +71 -7
  74. package/dist/core/feature-fixture-runner.js +53 -12
  75. package/dist/core/feature-fixtures.js +47 -14
  76. package/dist/core/feature-registry.js +28 -27
  77. package/dist/core/fsx.js +1 -0
  78. package/dist/core/harness-conflicts.js +18 -9
  79. package/dist/core/hooks-runtime/code-pack-freshness-preflight.js +14 -8
  80. package/dist/core/hooks-runtime/hook-io.js +8 -4
  81. package/dist/core/hooks-runtime/light-turn.js +70 -0
  82. package/dist/core/hooks-runtime/naruto-decision-gate.js +184 -0
  83. package/dist/core/hooks-runtime/payload-signals.js +270 -0
  84. package/dist/core/hooks-runtime/stop-repeat-guard.js +89 -0
  85. package/dist/core/hooks-runtime/team-digest.js +0 -1
  86. package/dist/core/hooks-runtime/tool-output-quarantine.js +93 -0
  87. package/dist/core/hooks-runtime.js +438 -354
  88. package/dist/core/init/skills.js +16 -30
  89. package/dist/core/init.js +144 -36
  90. package/dist/core/managed-assets/managed-assets-manifest.js +566 -10
  91. package/dist/core/mission.js +24 -1
  92. package/dist/core/pipeline-internals/runtime-core.js +570 -177
  93. package/dist/core/pipeline-internals/runtime-gates.js +174 -48
  94. package/dist/core/preflight/parallel-preflight-engine.js +66 -4
  95. package/dist/core/proof/route-adapter.js +1 -1
  96. package/dist/core/proof/route-proof-gate.js +7 -2
  97. package/dist/core/proof/selftest-proof-fixtures.js +3 -5
  98. package/dist/core/proof-field.js +1 -1
  99. package/dist/core/provider/model-router.js +42 -31
  100. package/dist/core/recallpulse/policy.js +12 -28
  101. package/dist/core/recallpulse.js +11 -6
  102. package/dist/core/release/npm-pack-proof.js +247 -0
  103. package/dist/core/release/package-dist-snapshot.js +151 -0
  104. package/dist/core/release/package-size-budget.js +4 -1
  105. package/dist/core/release/release-authorization-snapshot.js +115 -0
  106. package/dist/core/release/release-gate-affected-selector.js +14 -2
  107. package/dist/core/release/release-gate-cache-v2.js +30 -0
  108. package/dist/core/release/release-gate-contract.js +161 -0
  109. package/dist/core/release/release-gate-dag.js +1 -0
  110. package/dist/core/release/release-real-contract.js +90 -10
  111. package/dist/core/release-parallel-full-coverage.js +31 -143
  112. package/dist/core/research/claim-evidence-matrix.js +41 -6
  113. package/dist/core/research/experiment-plan.js +14 -10
  114. package/dist/core/research/falsification.js +9 -2
  115. package/dist/core/research/implementation-blueprint-densifier.js +82 -60
  116. package/dist/core/research/implementation-blueprint.js +32 -26
  117. package/dist/core/research/mock-result.js +122 -11
  118. package/dist/core/research/replication-pack.js +15 -8
  119. package/dist/core/research/research-adversarial-review.js +1068 -0
  120. package/dist/core/research/research-claim-builder.js +69 -17
  121. package/dist/core/research/research-claim-synthesizer.js +343 -0
  122. package/dist/core/research/research-cycle-runner.js +53 -3
  123. package/dist/core/research/research-falsification-runner.js +176 -0
  124. package/dist/core/research/research-final-reviewer.js +44 -125
  125. package/dist/core/research/research-plan-markdown.js +123 -0
  126. package/dist/core/research/research-realistic-report.js +14 -6
  127. package/dist/core/research/research-review-artifact-digest.js +66 -0
  128. package/dist/core/research/research-source-evidence.js +144 -0
  129. package/dist/core/research/research-source-layer-catalog.js +68 -0
  130. package/dist/core/research/research-source-ledger-merge.js +250 -12
  131. package/dist/core/research/research-source-shards.js +26 -70
  132. package/dist/core/research/research-stage-runner.js +237 -247
  133. package/dist/core/research/research-super-search.js +188 -0
  134. package/dist/core/research/research-synthesis-prompt.js +20 -1
  135. package/dist/core/research/research-synthesis-writer.js +86 -5
  136. package/dist/core/research/research-work-graph.js +25 -18
  137. package/dist/core/research/source-quality-report.js +21 -0
  138. package/dist/core/research.js +424 -390
  139. package/dist/core/retention.js +70 -2
  140. package/dist/core/routes/constants.js +1 -1
  141. package/dist/core/routes/dollar-manifest-lite.js +11 -11
  142. package/dist/core/routes.js +149 -69
  143. package/dist/core/runtime/task-profile.js +66 -0
  144. package/dist/core/runtime/verification-budget.js +12 -0
  145. package/dist/core/security/high-risk-contracts.js +6 -6
  146. package/dist/core/stop-gate/stop-gate-check.js +49 -12
  147. package/dist/core/subagents/agent-catalog.js +287 -0
  148. package/dist/core/subagents/model-policy.js +259 -0
  149. package/dist/core/subagents/naruto-help-contract.js +47 -0
  150. package/dist/core/subagents/official-subagent-config.js +488 -0
  151. package/dist/core/subagents/official-subagent-preparation.js +297 -0
  152. package/dist/core/subagents/official-subagent-prompt.js +159 -0
  153. package/dist/core/subagents/official-subagent-runner.js +129 -0
  154. package/dist/core/subagents/subagent-evidence.js +663 -0
  155. package/dist/core/subagents/terminology.js +16 -0
  156. package/dist/core/subagents/thread-budget.js +21 -0
  157. package/dist/core/subagents/triwiki-attention.js +168 -0
  158. package/dist/core/super-search/runtime-helpers.js +173 -19
  159. package/dist/core/super-search/runtime.js +140 -15
  160. package/dist/core/super-search/source-records.js +49 -8
  161. package/dist/core/team-review-policy.js +15 -0
  162. package/dist/core/triwiki/code-pack-head-freshness.js +291 -0
  163. package/dist/core/triwiki/triwiki-module-card.js +1 -1
  164. package/dist/core/triwiki-wrongness/wrongness-ledger.js +9 -2
  165. package/dist/core/version-manager.js +51 -1
  166. package/dist/core/version.js +1 -1
  167. package/dist/core/work-order-ledger.js +40 -1
  168. package/dist/core/zellij/zellij-fake-adapter.js +3 -1
  169. package/dist/core/zellij/zellij-launcher.js +49 -10
  170. package/dist/core/zellij/zellij-layout-builder.js +14 -5
  171. package/dist/core/zellij/zellij-official-subagent-activity.js +477 -0
  172. package/dist/core/zellij/zellij-official-subagent-telemetry.js +264 -0
  173. package/dist/core/zellij/zellij-pane-proof.js +9 -1
  174. package/dist/core/zellij/zellij-slot-pane-renderer.js +17 -5
  175. package/dist/core/zellij/zellij-slot-telemetry.js +15 -3
  176. package/dist/core/zellij/zellij-ui-mode.js +1 -1
  177. package/dist/core/zellij/zellij-update.js +14 -1
  178. package/dist/core/zellij/zellij-viewport-binder.js +3 -0
  179. package/dist/scripts/agent-role-config-repair-check.js +14 -16
  180. package/dist/scripts/architecture-guard-check.js +8 -1
  181. package/dist/scripts/canonical-test-runner.js +7 -1
  182. package/dist/scripts/check-route-modularity.js +0 -1
  183. package/dist/scripts/check-ts-contracts.js +1 -1
  184. package/dist/scripts/codex-control-all-pipelines-check.js +7 -3
  185. package/dist/scripts/codex-control-tool-output-continuity-audit-check.js +27 -0
  186. package/dist/scripts/codex-lb-fast-mode-truth-check.js +11 -1
  187. package/dist/scripts/codex-lb-fast-ui-preservation-check.js +9 -2
  188. package/dist/scripts/codex-lb-gpt56-fast-profile-check.js +13 -2
  189. package/dist/scripts/codex-native-agent-role-content-check.js +27 -7
  190. package/dist/scripts/codex-native-repair-transaction-check.js +3 -1
  191. package/dist/scripts/codex-sdk-all-pipelines-check.js +7 -4
  192. package/dist/scripts/codex-sdk-backend-router-check.js +2 -0
  193. package/dist/scripts/codex-sdk-research-pipeline-check.js +30 -8
  194. package/dist/scripts/db-route-materialization-check.js +33 -0
  195. package/dist/scripts/docs-truthfulness-check.js +3 -1
  196. package/dist/scripts/doctor-codex-startup-repair-check.js +12 -15
  197. package/dist/scripts/doctor-fix-production-blackbox.js +12 -2
  198. package/dist/scripts/doctor-startup-config-repair-blackbox.js +8 -2
  199. package/dist/scripts/doctor-startup-config-repair-check.js +12 -2
  200. package/dist/scripts/install-update-preserves-config-check.js +6 -1
  201. package/dist/scripts/lib/codex-sdk-gate-lib.js +4 -0
  202. package/dist/scripts/mad-sks-app-ui-no-mutation-check.js +0 -1
  203. package/dist/scripts/managed-role-manifest-parity-check.js +5 -4
  204. package/dist/scripts/naruto-codex-e2e-check.js +14 -7
  205. package/dist/scripts/naruto-shadow-clone-swarm-check.js +4 -201
  206. package/dist/scripts/npm-publish-performance-check.js +20 -12
  207. package/dist/scripts/official-subagent-workflow-check.js +145 -0
  208. package/dist/scripts/package-published-contract-check.js +6 -29
  209. package/dist/scripts/packlist-performance-check.js +18 -21
  210. package/dist/scripts/parallel-verification-engine-check.js +2 -2
  211. package/dist/scripts/prepublish-release-check-or-fast.js +23 -86
  212. package/dist/scripts/python-codex-sdk-all-pipelines-check.js +8 -0
  213. package/dist/scripts/release-affected-selector-check.js +74 -1
  214. package/dist/scripts/release-check-stamp.js +153 -248
  215. package/dist/scripts/release-dag-full-coverage-check.js +7 -15
  216. package/dist/scripts/release-dynamic-presets-check.js +2 -1
  217. package/dist/scripts/release-gate-dag-runner-check.js +0 -1
  218. package/dist/scripts/release-gate-dag-runner.js +12 -1
  219. package/dist/scripts/release-gate-existence-audit.js +1 -2
  220. package/dist/scripts/release-parallel-full-coverage-check.js +12 -6
  221. package/dist/scripts/release-parallel-speed-budget-check.js +18 -2
  222. package/dist/scripts/release-real-check.js +26 -4
  223. package/dist/scripts/release-registry-check.js +61 -16
  224. package/dist/scripts/research-blueprint-densifier-check.js +2 -2
  225. package/dist/scripts/research-real-cycle-no-legacy-final-md-check.js +11 -7
  226. package/dist/scripts/sizecheck.js +2 -2
  227. package/dist/scripts/sks-3-1-4-directive-check-lib.js +8 -2
  228. package/dist/scripts/sks-3-1-5-directive-check-lib.js +3 -2
  229. package/dist/scripts/sks-3-1-6-directive-check-lib.js +5 -3
  230. package/dist/scripts/sks-menubar-install-check.js +14 -1
  231. package/dist/scripts/super-search-provider-interface-check.js +31 -18
  232. package/dist/scripts/trust-fixture-check.js +32 -10
  233. package/dist/scripts/wrongness-fixture-check.js +1 -1
  234. package/dist/scripts/zellij-layout-valid-check.js +5 -5
  235. package/dist/scripts/zellij-spawn-on-demand-layout-check.js +3 -3
  236. package/docs/demo.tape +1 -1
  237. package/infra-harness-gates.json +1486 -0
  238. package/package.json +15 -10
  239. package/release-gates.v2.json +4060 -0
  240. package/runtime-required-scripts.json +9 -0
  241. package/dist/commands/db.js +0 -6
  242. package/dist/core/commands/db-command.js +0 -146
  243. package/dist/core/research/prompt.js +0 -15
  244. package/dist/scripts/codex-0139-feature-probes-check.js +0 -30
  245. package/dist/scripts/codex-0139-marketplace-source-check.js +0 -13
  246. package/dist/scripts/codex-control-tool-call-sequence-repair-check.js +0 -14
@@ -0,0 +1,21 @@
1
+ export const DEFAULT_NARUTO_MAX_THREADS = 12;
2
+ export const HARD_NARUTO_MAX_THREADS = 32;
3
+ export const DEFAULT_NARUTO_REQUESTED_SUBAGENTS = 2;
4
+ export function resolveSubagentThreadBudget(input = {}) {
5
+ const requested = clamp(input.requested ?? input.independentSliceCount ?? DEFAULT_NARUTO_REQUESTED_SUBAGENTS, 1, HARD_NARUTO_MAX_THREADS);
6
+ const configured = clamp(input.configuredMaxThreads ?? DEFAULT_NARUTO_MAX_THREADS, 1, HARD_NARUTO_MAX_THREADS);
7
+ return {
8
+ requestedSubagents: requested,
9
+ maxThreads: configured,
10
+ firstWave: Math.min(requested, configured),
11
+ waveCount: Math.ceil(requested / configured),
12
+ maxDepth: 1
13
+ };
14
+ }
15
+ function clamp(value, minimum, maximum) {
16
+ const parsed = Number(value);
17
+ if (!Number.isFinite(parsed))
18
+ return minimum;
19
+ return Math.max(minimum, Math.min(maximum, Math.floor(parsed)));
20
+ }
21
+ //# sourceMappingURL=thread-budget.js.map
@@ -0,0 +1,168 @@
1
+ import path from 'node:path';
2
+ import { readJson } from '../fsx.js';
3
+ export const BOUNDED_TRIWIKI_ATTENTION_SCHEMA = 'sks.subagent-triwiki-attention.v1';
4
+ export const DEFAULT_TRIWIKI_ATTENTION_ANCHOR_LIMIT = 8;
5
+ export async function readBoundedTriwikiAttention(root, limit = DEFAULT_TRIWIKI_ATTENTION_ANCHOR_LIMIT, query = '') {
6
+ const pack = await readJson(path.join(root, '.sneakoscope', 'wiki', 'context-pack.json'), null);
7
+ return extractBoundedTriwikiAttention(pack, limit, query);
8
+ }
9
+ export function extractBoundedTriwikiAttention(value, limit = DEFAULT_TRIWIKI_ATTENTION_ANCHOR_LIMIT, query = '') {
10
+ const pack = asRecord(value);
11
+ const attention = asRecord(pack.attention);
12
+ const anchorLimit = normalizeLimit(limit);
13
+ const hydrateHints = new Map();
14
+ const hydrateOrder = new Map();
15
+ for (const [index, row] of (Array.isArray(attention.hydrate_first) ? attention.hydrate_first : []).entries()) {
16
+ if (!Array.isArray(row))
17
+ continue;
18
+ const id = text(row[0]);
19
+ const hint = text(row[1]);
20
+ if (id && hint) {
21
+ hydrateHints.set(id, hint.slice(0, 240));
22
+ hydrateOrder.set(id, index);
23
+ }
24
+ }
25
+ const useFirst = [];
26
+ for (const [index, row] of (Array.isArray(attention.use_first) ? attention.use_first : []).entries()) {
27
+ if (!Array.isArray(row))
28
+ continue;
29
+ const id = text(row[0]);
30
+ if (!id || useFirst.some((anchor) => anchor.id === id))
31
+ continue;
32
+ useFirst.push({
33
+ id,
34
+ claim_hash: text(row[1]) || null,
35
+ source_hash: text(row[2]) || null,
36
+ hydrate_hint: hydrateHints.get(id) || null,
37
+ order: index
38
+ });
39
+ }
40
+ const anchors = selectAnchors(useFirst, hydrateHints, hydrateOrder, anchorLimit, query);
41
+ return {
42
+ schema: BOUNDED_TRIWIKI_ATTENTION_SCHEMA,
43
+ source: '.sneakoscope/wiki/context-pack.json',
44
+ available: anchors.length > 0,
45
+ attention_mode: text(attention.mode) || null,
46
+ anchor_limit: anchorLimit,
47
+ anchors,
48
+ hydration_policy: 'on_demand_only',
49
+ full_pack_injected: false
50
+ };
51
+ }
52
+ function selectAnchors(useFirst, hydrateHints, hydrateOrder, limit, query) {
53
+ const tokens = attentionQueryTokens(query);
54
+ if (!tokens.length)
55
+ return useFirst.slice(0, limit).map(stripOrder);
56
+ const selected = [];
57
+ const seen = new Set();
58
+ // Keep the leading high-trust policy anchors, then spend the remaining
59
+ // budget on query-relevant use_first or hydrate-first candidates. Hydrate-
60
+ // only rows stay hints: workers must open the cited source before relying on
61
+ // them, so relevance improves without treating lower-trust summaries as fact.
62
+ for (const anchor of useFirst.slice(0, Math.min(3, limit))) {
63
+ selected.push(stripOrder(anchor));
64
+ seen.add(anchor.id);
65
+ }
66
+ const candidates = [];
67
+ for (const anchor of useFirst) {
68
+ if (seen.has(anchor.id))
69
+ continue;
70
+ candidates.push({
71
+ ...stripOrder(anchor),
72
+ score: attentionRelevance(anchor.id, anchor.hydrate_hint, tokens),
73
+ order: anchor.order,
74
+ priority: 0
75
+ });
76
+ }
77
+ for (const [id, hint] of hydrateHints.entries()) {
78
+ if (seen.has(id) || useFirst.some((anchor) => anchor.id === id))
79
+ continue;
80
+ const score = attentionRelevance(id, hint, tokens);
81
+ if (score <= 0)
82
+ continue;
83
+ candidates.push({
84
+ id,
85
+ claim_hash: null,
86
+ source_hash: null,
87
+ hydrate_hint: hint,
88
+ score,
89
+ order: hydrateOrder.get(id) ?? Number.MAX_SAFE_INTEGER,
90
+ priority: 1
91
+ });
92
+ }
93
+ candidates.sort((left, right) => right.score - left.score || left.priority - right.priority || left.order - right.order);
94
+ for (const candidate of candidates) {
95
+ if (selected.length >= limit)
96
+ break;
97
+ if (candidate.score <= 0 || seen.has(candidate.id))
98
+ continue;
99
+ selected.push(stripRank(candidate));
100
+ seen.add(candidate.id);
101
+ }
102
+ for (const anchor of useFirst) {
103
+ if (selected.length >= limit)
104
+ break;
105
+ if (seen.has(anchor.id))
106
+ continue;
107
+ selected.push(stripOrder(anchor));
108
+ seen.add(anchor.id);
109
+ }
110
+ return selected;
111
+ }
112
+ function attentionQueryTokens(value) {
113
+ const stop = new Set([
114
+ 'and', 'the', 'for', 'with', 'from', 'into', 'this', 'that', 'sks', 'src', 'core',
115
+ '작업', '구현', '개선', '추가', '변경', '기능', '모든', '최대한'
116
+ ]);
117
+ return [...new Set(String(value || '')
118
+ .normalize('NFKC')
119
+ .toLowerCase()
120
+ .replace(/[^\p{L}\p{N}]+/gu, ' ')
121
+ .split(/\s+/)
122
+ .map((token) => token.trim())
123
+ .filter((token) => token.length >= 2 && !stop.has(token)))]
124
+ .slice(0, 64);
125
+ }
126
+ function attentionRelevance(id, hint, tokens) {
127
+ const haystack = `${id} ${hint || ''}`
128
+ .normalize('NFKC')
129
+ .toLowerCase()
130
+ .replace(/[^\p{L}\p{N}]+/gu, ' ');
131
+ const compact = haystack.replace(/\s+/g, '');
132
+ return tokens.reduce((score, token) => {
133
+ if (haystack.includes(token))
134
+ return score + (token.length >= 5 ? 4 : 3);
135
+ return compact.includes(token) ? score + 2 : score;
136
+ }, 0);
137
+ }
138
+ function stripOrder(anchor) {
139
+ return {
140
+ id: anchor.id,
141
+ claim_hash: anchor.claim_hash,
142
+ source_hash: anchor.source_hash,
143
+ hydrate_hint: anchor.hydrate_hint
144
+ };
145
+ }
146
+ function stripRank(anchor) {
147
+ return {
148
+ id: anchor.id,
149
+ claim_hash: anchor.claim_hash,
150
+ source_hash: anchor.source_hash,
151
+ hydrate_hint: anchor.hydrate_hint
152
+ };
153
+ }
154
+ function normalizeLimit(value) {
155
+ const parsed = Number(value);
156
+ if (!Number.isFinite(parsed))
157
+ return DEFAULT_TRIWIKI_ATTENTION_ANCHOR_LIMIT;
158
+ return Math.max(1, Math.min(16, Math.floor(parsed)));
159
+ }
160
+ function asRecord(value) {
161
+ return value && typeof value === 'object' && !Array.isArray(value)
162
+ ? value
163
+ : {};
164
+ }
165
+ function text(value) {
166
+ return typeof value === 'string' ? value.trim() : '';
167
+ }
168
+ //# sourceMappingURL=triwiki-attention.js.map
@@ -3,7 +3,7 @@ import dns from 'node:dns/promises';
3
3
  import net from 'node:net';
4
4
  import { nowIso, sha256, writeTextAtomic } from '../fsx.js';
5
5
  import { evaluateRealEvidencePolicy } from '../verification/real-evidence-policy.js';
6
- import { classifyAuthority, isOfficialUrl, makeSource, sourceFromKnownUrl } from './source-records.js';
6
+ import { classifyAuthority, independenceClusterForDomain, isOfficialUrl, makeSource, sourceFromKnownUrl } from './source-records.js';
7
7
  const DEFAULT_FETCH = globalThis.fetch;
8
8
  export function normalizeGenericSourceRows(raw, providerId, family, intent, tier) {
9
9
  const rows = Array.isArray(raw) ? raw : Array.isArray(raw?.results) ? raw.results : raw ? [raw] : [];
@@ -16,13 +16,45 @@ export function normalizeGenericSourceRows(raw, providerId, family, intent, tier
16
16
  title: String(row.title || row.name || `${providerId} result ${index + 1}`),
17
17
  url,
18
18
  snippet: String(row.snippet || row.summary || row.text || ''),
19
- verdict: providerId === 'context7' ? 'verified_content' : 'weak_content',
19
+ verdict: 'weak_content',
20
20
  authority: tier,
21
21
  primary: providerId === 'context7',
22
22
  path: [providerId]
23
23
  });
24
24
  });
25
25
  }
26
+ export async function materializeContext7SourceRows(raw, artifactDir, intent) {
27
+ const rows = Array.isArray(raw) ? raw : Array.isArray(raw?.results) ? raw.results : raw ? [raw] : [];
28
+ const out = [];
29
+ for (let index = 0; index < rows.length; index += 1) {
30
+ const row = rows[index];
31
+ const url = typeof row?.url === 'string' ? row.url : typeof row?.link === 'string' ? row.link : null;
32
+ const content = String(row?.content || row?.full_text || row?.document || row?.markdown || row?.text || row?.snippet || '');
33
+ const visible = visibleEvidenceText(content);
34
+ const meaningful = visible.length >= 80 && (visible.match(/[\p{L}\p{N}]{2,}/gu) || []).length >= 8;
35
+ const contentSha = meaningful ? sha256(content) : null;
36
+ const contentArtifact = contentSha ? path.join('context7-content', `${contentSha.slice(0, 16)}.txt`) : null;
37
+ if (contentArtifact)
38
+ await writeTextAtomic(path.join(artifactDir, contentArtifact), content);
39
+ out.push(makeSource({
40
+ providerId: 'context7',
41
+ family: 'official_docs',
42
+ type: 'official_docs',
43
+ title: String(row?.title || row?.name || `context7 result ${index + 1}`),
44
+ url,
45
+ snippet: String(row?.snippet || row?.summary || visible.slice(0, 500)),
46
+ verdict: meaningful ? 'verified_content' : 'weak_content',
47
+ authority: 'A0',
48
+ primary: true,
49
+ path: ['context7', ...(contentArtifact ? ['materialized_content'] : ['snippet_only'])],
50
+ blockers: contentArtifact ? [] : ['context7_content_artifact_missing'],
51
+ contentArtifact,
52
+ contentSha256: contentSha,
53
+ contentLength: meaningful ? content.length : null
54
+ }));
55
+ }
56
+ return out;
57
+ }
26
58
  export function sourceFromWebRow(row, index, intent) {
27
59
  return makeSource({
28
60
  providerId: 'codex_web',
@@ -49,7 +81,19 @@ export async function sourceFromUrlFetch(url, artifactDir, intent, opts = {}) {
49
81
  warnings
50
82
  };
51
83
  }
52
- const policyOpts = { ...opts, networkLookupRequired: fetchFn === DEFAULT_FETCH };
84
+ const fetchTimeoutMs = boundedOperationTimeout(10_000, opts.hardTimeoutMs, opts.deadlineEpochMs);
85
+ if (fetchTimeoutMs <= 0) {
86
+ blockers.push('direct_url_fetch_deadline_exceeded');
87
+ return {
88
+ source: { ...sourceFromKnownUrl(url, intent), blockers, warnings: ['url_parse_only'] },
89
+ blockers,
90
+ warnings
91
+ };
92
+ }
93
+ const policyOpts = {
94
+ ...(opts.allowLocal === undefined ? {} : { allowLocal: opts.allowLocal }),
95
+ networkLookupRequired: fetchFn === DEFAULT_FETCH
96
+ };
53
97
  const initialPolicy = await evaluateUrlFetchPolicy(url, policyOpts);
54
98
  if (!initialPolicy.ok) {
55
99
  blockers.push(...initialPolicy.blockers);
@@ -62,7 +106,7 @@ export async function sourceFromUrlFetch(url, artifactDir, intent, opts = {}) {
62
106
  }
63
107
  warnings.push(...initialPolicy.warnings);
64
108
  const controller = new AbortController();
65
- const timer = setTimeout(() => controller.abort(), 10000);
109
+ const timer = setTimeout(() => controller.abort(), fetchTimeoutMs);
66
110
  try {
67
111
  let currentUrl = url;
68
112
  let response = null;
@@ -112,9 +156,11 @@ export async function sourceFromUrlFetch(url, artifactDir, intent, opts = {}) {
112
156
  warnings.push(...finalPolicy.warnings);
113
157
  if (!response.ok)
114
158
  blockers.push(`direct_url_fetch_http_${response.status}`);
115
- if (!capped.trim())
116
- blockers.push('direct_url_fetch_empty_content');
117
- const contentSha = capped.trim() ? sha256(capped) : null;
159
+ const contentInspection = inspectHydratedContent(capped, response.headers.get('content-type'));
160
+ blockers.push(...contentInspection.blockers);
161
+ warnings.push(...contentInspection.warnings);
162
+ const verifiedContent = response.ok && contentInspection.ok;
163
+ const contentSha = verifiedContent ? sha256(capped) : null;
118
164
  const relArtifact = contentSha ? path.join('url-content', `${contentSha.slice(0, 16)}.txt`) : null;
119
165
  if (relArtifact)
120
166
  await writeTextAtomic(path.join(artifactDir, relArtifact), capped);
@@ -124,8 +170,8 @@ export async function sourceFromUrlFetch(url, artifactDir, intent, opts = {}) {
124
170
  type: 'known_url',
125
171
  title: normalizedUrl,
126
172
  url: normalizedUrl,
127
- snippet: capped.replace(/\s+/g, ' ').trim().slice(0, 500),
128
- verdict: response.ok && capped.trim() ? 'verified_content' : 'blocked',
173
+ snippet: contentInspection.visible_text.slice(0, 500),
174
+ verdict: verifiedContent ? 'verified_content' : 'blocked',
129
175
  authority: classifyAuthority(normalizedUrl),
130
176
  primary: isOfficialUrl(normalizedUrl),
131
177
  path: opts.allowLocal ? ['direct_url_fetch', 'allow_local'] : ['direct_url_fetch'],
@@ -133,7 +179,7 @@ export async function sourceFromUrlFetch(url, artifactDir, intent, opts = {}) {
133
179
  blockers,
134
180
  contentArtifact: relArtifact,
135
181
  contentSha256: contentSha,
136
- contentLength: capped.length
182
+ contentLength: verifiedContent ? capped.length : null
137
183
  });
138
184
  return { source, blockers, warnings };
139
185
  }
@@ -151,6 +197,75 @@ export async function sourceFromUrlFetch(url, artifactDir, intent, opts = {}) {
151
197
  clearTimeout(timer);
152
198
  }
153
199
  }
200
+ function boundedOperationTimeout(fallbackMs, hardTimeoutMs, deadlineEpochMs) {
201
+ const hard = Number(hardTimeoutMs);
202
+ const deadline = Number(deadlineEpochMs);
203
+ const remaining = Number.isFinite(deadline) && deadline > 0 ? Math.floor(deadline - Date.now()) : Number.POSITIVE_INFINITY;
204
+ if (remaining <= 0)
205
+ return 0;
206
+ return Math.max(1, Math.floor(Math.min(fallbackMs, Number.isFinite(hard) && hard > 0 ? hard : Number.POSITIVE_INFINITY, remaining)));
207
+ }
208
+ export function inspectHydratedContent(raw, contentTypeValue) {
209
+ const body = String(raw || '');
210
+ const contentType = String(contentTypeValue || '').split(';')[0].trim().toLowerCase();
211
+ const blockers = [];
212
+ const warnings = [];
213
+ if (contentType && !isTextualEvidenceContentType(contentType)) {
214
+ blockers.push(`direct_url_fetch_unsupported_content_type:${contentType}`);
215
+ }
216
+ const visibleText = visibleEvidenceText(body);
217
+ if (!body.trim())
218
+ blockers.push('direct_url_fetch_empty_content');
219
+ if (looksLikeAuthenticationOrChallenge(body, visibleText))
220
+ blockers.push('direct_url_fetch_auth_or_challenge_content');
221
+ if (looksLikeSoftError(body, visibleText))
222
+ blockers.push('direct_url_fetch_error_or_soft_404_content');
223
+ const tokens = visibleText.match(/[\p{L}\p{N}]{2,}/gu) || [];
224
+ if (visibleText.length < 80 || tokens.length < 8)
225
+ blockers.push('direct_url_fetch_non_meaningful_content');
226
+ if (!contentType)
227
+ blockers.push('direct_url_fetch_content_type_missing');
228
+ return {
229
+ ok: blockers.length === 0,
230
+ visible_text: visibleText,
231
+ blockers: [...new Set(blockers)],
232
+ warnings: [...new Set(warnings)]
233
+ };
234
+ }
235
+ function isTextualEvidenceContentType(contentType) {
236
+ return contentType.startsWith('text/')
237
+ || contentType === 'application/json'
238
+ || contentType === 'application/ld+json'
239
+ || contentType === 'application/xml'
240
+ || contentType === 'application/xhtml+xml'
241
+ || contentType.endsWith('+json')
242
+ || contentType.endsWith('+xml');
243
+ }
244
+ function visibleEvidenceText(body) {
245
+ return body
246
+ .replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, ' ')
247
+ .replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, ' ')
248
+ .replace(/<noscript\b[^>]*>[\s\S]*?<\/noscript>/gi, ' ')
249
+ .replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gi, ' ')
250
+ .replace(/<[^>]+>/g, ' ')
251
+ .replace(/&(?:nbsp|amp|quot|apos|lt|gt);/gi, ' ')
252
+ .replace(/\s+/g, ' ')
253
+ .trim();
254
+ }
255
+ function looksLikeAuthenticationOrChallenge(body, visibleText) {
256
+ const prefix = `${body.slice(0, 12000)}\n${visibleText.slice(0, 2000)}`;
257
+ const structuralLogin = /<form\b[^>]*(?:login|signin|sign-in)|<input\b[^>]*type\s*=\s*["']?password/i.test(prefix);
258
+ const challenge = /\b(?:verify (?:that )?you are human|checking your browser|attention required|captcha|cloudflare ray id|bot (?:check|challenge|detection)|enable javascript and cookies to continue)\b/i.test(prefix);
259
+ const shortAuthenticationShell = visibleText.length < 1200
260
+ && /\b(?:sign in|log in|login required|authentication required|access denied|unauthorized)\b/i.test(prefix);
261
+ return structuralLogin || challenge || shortAuthenticationShell;
262
+ }
263
+ function looksLikeSoftError(body, visibleText) {
264
+ const prefix = `${body.slice(0, 8000)}\n${visibleText.slice(0, 1600)}`;
265
+ return /<title[^>]*>\s*(?:404|not found|page not found|error|service unavailable|internal server error|bad gateway)\b/i.test(prefix)
266
+ || /\b(?:404\s+(?:error|not found)|page not found|the page you (?:requested|are looking for) (?:was not found|does not exist)|this page (?:does not|doesn't) exist|soft 404|service unavailable|internal server error|bad gateway)\b/i.test(prefix)
267
+ || /(?:페이지를\s*찾을\s*수\s*없|요청한\s*페이지가\s*없|서비스를\s*사용할\s*수\s*없|내부\s*서버\s*오류)/i.test(prefix);
268
+ }
154
269
  async function evaluateUrlFetchPolicy(rawUrl, opts) {
155
270
  if (opts.allowLocal === true)
156
271
  return { ok: true, blockers: [], warnings: ['local_fetch_explicitly_allowed'] };
@@ -228,15 +343,36 @@ export function buildXDiscoverySources(queries, intent) {
228
343
  }));
229
344
  }
230
345
  export function dedupeSources(sources) {
231
- const seen = new Map();
232
- return sources.map((source) => {
346
+ const clusters = new Map();
347
+ for (const source of sources) {
233
348
  const key = source.canonical_url || source.content_sha256 || source.source_id;
234
- const cluster = seen.get(key);
235
- if (cluster)
236
- return { ...source, duplicate_cluster_id: cluster };
237
- seen.set(key, source.source_id);
238
- return { ...source, duplicate_cluster_id: source.source_id };
239
- }).filter((source) => source.duplicate_cluster_id === source.source_id);
349
+ const rows = clusters.get(key) || [];
350
+ rows.push(source);
351
+ clusters.set(key, rows);
352
+ }
353
+ return [...clusters.values()].map((rows) => {
354
+ const ranked = [...rows].sort((a, b) => sourceRank(b) - sourceRank(a));
355
+ const selected = ranked[0];
356
+ return {
357
+ ...selected,
358
+ duplicate_cluster_id: selected.source_id,
359
+ acquisition_path: [...new Set(rows.flatMap((row) => row.acquisition_path || []))],
360
+ warnings: [...new Set(rows.flatMap((row) => row.warnings || []))],
361
+ blockers: selected.acquisition_verdict === 'verified_content'
362
+ ? []
363
+ : [...new Set(rows.flatMap((row) => row.blockers || []))]
364
+ };
365
+ });
366
+ }
367
+ function sourceRank(source) {
368
+ const verdict = source.acquisition_verdict === 'verified_content'
369
+ ? 5
370
+ : source.acquisition_verdict === 'partial_content'
371
+ ? 3
372
+ : source.acquisition_verdict === 'weak_content'
373
+ ? 2
374
+ : 0;
375
+ return verdict * 100 + source.trust_score * 10 + source.relevance_score;
240
376
  }
241
377
  export function buildLeads(sources, mode) {
242
378
  if (mode === 'fast')
@@ -318,12 +454,30 @@ export function buildProof(mode, intent, sources, claims, convergence, blockers,
318
454
  });
319
455
  proofBlockers.push(...realEvidencePolicy.blockers);
320
456
  warnings.push(...realEvidencePolicy.warnings);
457
+ const verifiedSources = sources.filter((source) => source.acquisition_verdict === 'verified_content');
458
+ const verifiedProviderIds = [...new Set(verifiedSources
459
+ .map((source) => String(source.provider_id || '').trim())
460
+ .filter(Boolean))];
461
+ const verifiedProviderFamilies = [...new Set(verifiedSources
462
+ .map((source) => String(source.source_family || '').trim().toLowerCase())
463
+ .filter(Boolean))];
464
+ const verifiedIndependenceClusters = [...new Set(verifiedSources
465
+ .map((source) => String(source.independence_cluster_id || independenceClusterForDomain(source.domain) || '').trim().toLowerCase())
466
+ .filter(Boolean))];
467
+ const providerIndependent = verifiedProviderFamilies.length >= 2 && verifiedIndependenceClusters.length >= 2;
321
468
  return {
322
469
  schema: 'sks.super-search-proof.v1',
323
470
  ok: proofBlockers.length === 0,
324
471
  mode,
325
472
  intent,
326
- provider_independent: true,
473
+ provider_independent: providerIndependent,
474
+ provider_independence_basis: 'distinct_verified_provider_families_and_independence_clusters',
475
+ verified_provider_count: verifiedProviderIds.length,
476
+ verified_provider_ids: verifiedProviderIds,
477
+ verified_provider_family_count: verifiedProviderFamilies.length,
478
+ verified_provider_families: verifiedProviderFamilies,
479
+ verified_independence_cluster_count: verifiedIndependenceClusters.length,
480
+ verified_independence_clusters: verifiedIndependenceClusters,
327
481
  xai_runtime_dependency: false,
328
482
  snippet_only_final_claims: weakContentFinalClaims,
329
483
  weak_content_final_claims: weakContentFinalClaims,