sneakoscope 7.3.0 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -10
- package/crates/sks-core/Cargo.lock +1 -1
- package/crates/sks-core/Cargo.toml +1 -1
- package/dist/cli/codex-app-command.js +1 -1
- package/dist/cli/command-manifest-lite.js +4 -1
- package/dist/cli/command-registry.js +2 -0
- package/dist/cli/install-helpers-codex-lb-chain.js +42 -0
- package/dist/cli/install-helpers-codex-lb-config.js +114 -9
- package/dist/cli/install-helpers-install-support.js +6 -16
- package/dist/cli/install-helpers.js +788 -600
- package/dist/cli/router.js +30 -2
- package/dist/commands/codex-app.js +37 -1
- package/dist/commands/codex-lb.js +491 -300
- package/dist/config/skills-manifest.json +57 -71
- package/dist/core/align/align-route.js +127 -0
- package/dist/core/codex-app/codex-app-fast-ui-repair.js +8 -4
- package/dist/core/codex-app/codex-app-restart.js +83 -0
- package/dist/core/codex-app/codex-app-ui-state-snapshot.js +8 -4
- package/dist/core/codex-app/desktop-routing-snapshot.js +1 -1
- package/dist/core/codex-app/menubar/constants.js +5 -0
- package/dist/core/codex-app/menubar/generation-transaction-journal.js +1 -3
- package/dist/core/codex-app/menubar/installer.js +18 -0
- package/dist/core/codex-app/multi-provider-router.js +22 -10
- package/dist/core/codex-app/openrouter-activate.js +26 -1
- package/dist/core/codex-app.js +118 -26
- package/dist/core/codex-control/codex-app-server-runtime-env.js +86 -0
- package/dist/core/codex-control/codex-app-server-v2-client.js +78 -8
- package/dist/core/codex-control/codex-task-runner.js +2 -2
- package/dist/core/codex-lb/capability-runner.js +204 -0
- package/dist/core/codex-lb/capability-types.js +1 -0
- package/dist/core/codex-lb/codex-lb-env.js +9 -13
- package/dist/core/codex-lb/codex-lb-setup.js +45 -8
- package/dist/core/codex-lb/codex-lb-tool-catalog.js +52 -74
- package/dist/core/codex-lb/codex-lb-tool-output-recovery.js +1 -1
- package/dist/core/codex-lb/desktop-auth-invariant.js +185 -0
- package/dist/core/codex-lb/desktop-bridge/client.js +34 -0
- package/dist/core/codex-lb/desktop-bridge/header-policy.js +106 -0
- package/dist/core/codex-lb/desktop-bridge/http-forward.js +101 -0
- package/dist/core/codex-lb/desktop-bridge/index.js +10 -0
- package/dist/core/codex-lb/desktop-bridge/launchd.js +81 -0
- package/dist/core/codex-lb/desktop-bridge/location-rewrite.js +27 -0
- package/dist/core/codex-lb/desktop-bridge/security.js +274 -0
- package/dist/core/codex-lb/desktop-bridge/server.js +179 -0
- package/dist/core/codex-lb/desktop-bridge/state.js +119 -0
- package/dist/core/codex-lb/desktop-bridge/types.js +16 -0
- package/dist/core/codex-lb/desktop-bridge/websocket-forward.js +151 -0
- package/dist/core/codex-lb/desktop-center-credentials.js +189 -0
- package/dist/core/codex-lb/desktop-controller.js +1410 -0
- package/dist/core/codex-lb/desktop-mode.js +32 -0
- package/dist/core/codex-lb/desktop-real-evidence.js +168 -0
- package/dist/core/codex-lb/desktop-service.js +613 -0
- package/dist/core/codex-lb/legacy-migration.js +575 -0
- package/dist/core/codex-lb/migration-receipt.js +246 -0
- package/dist/core/codex-lb/probes/auxiliary-surfaces-probe.js +60 -0
- package/dist/core/codex-lb/probes/bridge-probe.js +75 -0
- package/dist/core/codex-lb/probes/catalog-probe.js +128 -0
- package/dist/core/codex-lb/probes/computer-use-probe.js +50 -0
- package/dist/core/codex-lb/probes/image-generation-probe.js +47 -0
- package/dist/core/codex-lb/probes/probe-evidence.js +39 -0
- package/dist/core/codex-lb/probes/voice-realtime-probe.js +44 -0
- package/dist/core/codex-lb/trusted-deep-evidence.js +403 -0
- package/dist/core/codex-native/core-skill-manifest.js +22 -6
- package/dist/core/codex-runtime/codex-desktop-config-policy.js +2 -1
- package/dist/core/commands/align-command.js +220 -0
- package/dist/core/commands/image-ux-review-command.js +280 -68
- package/dist/core/commands/naruto-command.js +257 -8
- package/dist/core/commands/ppt-command.js +2 -2
- package/dist/core/commands/telegram-command.js +402 -34
- package/dist/core/commands/triwiki-command.js +11 -1
- package/dist/core/commands/triwiki-graph-command.js +160 -0
- package/dist/core/commands/wiki-command.js +100 -20
- package/dist/core/doctor/skill-legacy-surface.js +1 -3
- package/dist/core/errors/message.js +3 -0
- package/dist/core/evidence/evidence-freshness.js +14 -0
- package/dist/core/feature-fixtures.js +9 -1
- package/dist/core/feature-registry.js +5 -3
- package/dist/core/fsx.js +7 -3
- package/dist/core/hooks-runtime/codex-commit-hooks-selftest.js +82 -0
- package/dist/core/hooks-runtime/context-graph-freshness-preflight.js +113 -0
- package/dist/core/hooks-runtime/hook-context.js +15 -2
- package/dist/core/hooks-runtime/managed-skill-generation-heal.js +46 -0
- package/dist/core/hooks-runtime/naruto-terminal-finalization.js +1 -0
- package/dist/core/hooks-runtime/official-subagent-lifecycle.js +1 -1
- package/dist/core/hooks-runtime/tool-output-quarantine.js +1 -1
- package/dist/core/hooks-runtime.js +33 -89
- package/dist/core/image-ux-review/callout-extraction.js +6 -0
- package/dist/core/image-ux-review/imagegen-adapter.js +64 -23
- package/dist/core/image-ux-review/real-callout-extractor.js +1 -0
- package/dist/core/image-ux-review.js +230 -12
- package/dist/core/imagegen/codex-lb-imagegen-target.js +21 -7
- package/dist/core/imagegen/imagegen-capability.js +10 -4
- package/dist/core/imagegen/require-imagegen.js +29 -5
- package/dist/core/init/skills.js +25 -13
- package/dist/core/init.js +1 -1
- package/dist/core/install/installed-package-smoke.js +157 -4
- package/dist/core/managed-assets/managed-assets-manifest.js +2 -1
- package/dist/core/managed-path-safety.js +8 -10
- package/dist/core/mcp-config/backup.js +2 -4
- package/dist/core/mcp-config/config-reader.js +2 -4
- package/dist/core/mcp-config/scope.js +3 -5
- package/dist/core/naruto/context-graph-advisor-scope.js +242 -0
- package/dist/core/naruto/context-graph-advisor.js +0 -0
- package/dist/core/perf/release-latency-slo.js +12 -6
- package/dist/core/pipeline-internals/runtime-core.js +78 -0
- package/dist/core/pipeline-internals/runtime-gates.js +5 -2
- package/dist/core/policy/latest-version-guidance.js +113 -0
- package/dist/core/ppt.js +8 -8
- package/dist/core/preflight/parallel-preflight-engine.js +1 -1
- package/dist/core/proof/auto-finalize.js +98 -6
- package/dist/core/proof/route-proof-gate.js +12 -1
- package/dist/core/proof/route-proof-policy.js +8 -8
- package/dist/core/release/gate-manifest.js +32 -1
- package/dist/core/release/npm-stage-contract.js +21 -0
- package/dist/core/release/package-size-budget.js +2 -2
- package/dist/core/release/release-gate-contract.js +5 -0
- package/dist/core/release/release-proof-io.js +1 -3
- package/dist/core/release/release-real-contract.js +5 -4
- package/dist/core/release/release-stamp-proof.js +1 -3
- package/dist/core/release/stage-publish.js +27 -0
- package/dist/core/remote/audit-idempotency.js +50 -18
- package/dist/core/remote/codex-public-activity.js +283 -0
- package/dist/core/remote/index.js +1 -0
- package/dist/core/remote/ssh-worker-client.js +4 -1
- package/dist/core/remote/worker.js +206 -27
- package/dist/core/research/research-adversarial-review.js +1 -3
- package/dist/core/research/research-claim-synthesizer.js +1 -3
- package/dist/core/research/research-falsification-runner.js +1 -3
- package/dist/core/research/research-source-evidence.js +1 -3
- package/dist/core/responses-stream.js +65 -19
- package/dist/core/routes/constants.js +1 -1
- package/dist/core/routes/design-policy.js +7 -2
- package/dist/core/routes/dollar-manifest-lite.js +2 -4
- package/dist/core/routes/evidence.js +1 -1
- package/dist/core/routes.js +30 -10
- package/dist/core/safety/command-contract/contracts.js +2 -0
- package/dist/core/safety/command-contract/types.js +1 -1
- package/dist/core/search/context-graph-seeds.js +205 -0
- package/dist/core/search/context.js +0 -0
- package/dist/core/search/provider.js +2 -2
- package/dist/core/secret-redaction.js +6 -0
- package/dist/core/subagents/naruto-help-contract.js +2 -1
- package/dist/core/subagents/naruto-host-credentials.js +161 -0
- package/dist/core/subagents/official-subagent-preparation.js +4 -1
- package/dist/core/subagents/official-subagent-prompt.js +44 -2
- package/dist/core/subagents/official-subagent-runner.js +26 -8
- package/dist/core/subagents/triwiki-attention.js +135 -123
- package/dist/core/telegram/bot-api.js +85 -10
- package/dist/core/telegram/center-snapshot.js +718 -0
- package/dist/core/telegram/config.js +158 -31
- package/dist/core/telegram/hub.js +288 -33
- package/dist/core/telegram/index.js +2 -0
- package/dist/core/telegram/ingress-spool.js +419 -0
- package/dist/core/telegram/ledgers.js +188 -29
- package/dist/core/telegram/messages.js +26 -6
- package/dist/core/telegram/owner-lock.js +10 -7
- package/dist/core/telegram/runtime-projection.js +38 -3
- package/dist/core/telegram/runtime.js +298 -63
- package/dist/core/telegram/service.js +137 -8
- package/dist/core/telegram/setup.js +291 -73
- package/dist/core/text/strings.js +3 -0
- package/dist/core/triwiki/code-pack.js +12 -120
- package/dist/core/triwiki/context-graph/compiler/cache-key.js +277 -0
- package/dist/core/triwiki/context-graph/compiler/extract.js +104 -0
- package/dist/core/triwiki/context-graph/compiler/freshness.js +108 -0
- package/dist/core/triwiki/context-graph/compiler/index.js +237 -0
- package/dist/core/triwiki/context-graph/compiler/merge.js +0 -0
- package/dist/core/triwiki/context-graph/compiler/serialize.js +115 -0
- package/dist/core/triwiki/context-graph/contracts.js +236 -0
- package/dist/core/triwiki/context-graph/extractors/code/builders.js +150 -0
- package/dist/core/triwiki/context-graph/extractors/code/declarations.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/index.js +265 -0
- package/dist/core/triwiki/context-graph/extractors/code/inventory.js +237 -0
- package/dist/core/triwiki/context-graph/extractors/code/module-graph.js +252 -0
- package/dist/core/triwiki/context-graph/extractors/code/modules.js +79 -0
- package/dist/core/triwiki/context-graph/extractors/code/references.js +184 -0
- package/dist/core/triwiki/context-graph/extractors/code/selection.js +100 -0
- package/dist/core/triwiki/context-graph/extractors/code/ts-config.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/types.js +18 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/claims.js +289 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/index.js +54 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proof-index.js +213 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proofs.js +266 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/redaction.js +177 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/shared.js +0 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/sources.js +154 -0
- package/dist/core/triwiki/context-graph/extractors/index.js +7 -0
- package/dist/core/triwiki/context-graph/extractors/topology/commands.js +207 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gate-edges.js +201 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gates.js +182 -0
- package/dist/core/triwiki/context-graph/extractors/topology/globs.js +124 -0
- package/dist/core/triwiki/context-graph/extractors/topology/index.js +92 -0
- package/dist/core/triwiki/context-graph/extractors/topology/routes.js +135 -0
- package/dist/core/triwiki/context-graph/extractors/topology/shared.js +215 -0
- package/dist/core/triwiki/context-graph/graph-index.js +143 -0
- package/dist/core/triwiki/context-graph/ids.js +0 -0
- package/dist/core/triwiki/context-graph/lint/index.js +0 -0
- package/dist/core/triwiki/context-graph/lint/rules.js +232 -0
- package/dist/core/triwiki/context-graph/lint/warnings.js +93 -0
- package/dist/core/triwiki/context-graph/paths.js +116 -0
- package/dist/core/triwiki/context-graph/profiles.js +78 -0
- package/dist/core/triwiki/context-graph/projections/anchors.js +91 -0
- package/dist/core/triwiki/context-graph/projections/attention.js +58 -0
- package/dist/core/triwiki/context-graph/projections/code-pack-workspace.js +62 -0
- package/dist/core/triwiki/context-graph/projections/code-pack.js +144 -0
- package/dist/core/triwiki/context-graph/projections/index.js +7 -0
- package/dist/core/triwiki/context-graph/projections/module-view.js +140 -0
- package/dist/core/triwiki/context-graph/projections/node-summary.js +118 -0
- package/dist/core/triwiki/context-graph/projections/pack-contract.js +6 -0
- package/dist/core/triwiki/context-graph/query/explain.js +0 -0
- package/dist/core/triwiki/context-graph/query/index.js +178 -0
- package/dist/core/triwiki/context-graph/query/load.js +116 -0
- package/dist/core/triwiki/context-graph/query/pack.js +117 -0
- package/dist/core/triwiki/context-graph/query/rank.js +142 -0
- package/dist/core/triwiki/context-graph/query/ranking-config.js +64 -0
- package/dist/core/triwiki/context-graph/query/seeds.js +241 -0
- package/dist/core/triwiki/context-graph/query/snapshot-cache.js +72 -0
- package/dist/core/triwiki/context-graph/query/traverse.js +154 -0
- package/dist/core/triwiki/context-graph/query-types.js +29 -0
- package/dist/core/triwiki/context-graph/store/compile-lock.js +21 -0
- package/dist/core/triwiki/context-graph/store/event-log.js +48 -0
- package/dist/core/triwiki/context-graph/store/fragment-cache.js +85 -0
- package/dist/core/triwiki/context-graph/store/graph-status.js +85 -0
- package/dist/core/triwiki/context-graph/store/snapshot-store.js +155 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-repair.js +115 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-store.js +290 -0
- package/dist/core/triwiki/triwiki-proof-bank-index.js +126 -0
- package/dist/core/triwiki/triwiki-proof-bank.js +7 -1
- package/dist/core/verification/context-graph-affected.js +271 -0
- package/dist/core/version.js +1 -1
- package/dist/native/sks-menubar/Sources/AlertFactory.swift +11 -3
- package/dist/native/sks-menubar/Sources/AppDelegate.swift +9 -0
- package/dist/native/sks-menubar/Sources/ControlCenterWindowController.swift +25 -3
- package/dist/native/sks-menubar/Sources/ControlKit.swift +19 -8
- package/dist/native/sks-menubar/Sources/DiagnosticsViewController.swift +1 -2
- package/dist/native/sks-menubar/Sources/MCPServersViewController.swift +45 -17
- package/dist/native/sks-menubar/Sources/OverviewSummary.swift +162 -0
- package/dist/native/sks-menubar/Sources/OverviewViewController.swift +136 -190
- package/dist/native/sks-menubar/Sources/ProcessClient.swift +107 -11
- package/dist/native/sks-menubar/Sources/ProvidersMultiProvider.swift +5 -1
- package/dist/native/sks-menubar/Sources/ProvidersOpenRouter.swift +16 -4
- package/dist/native/sks-menubar/Sources/ProvidersRoleModels.swift +4 -1
- package/dist/native/sks-menubar/Sources/ProvidersRoutingTruth.swift +131 -0
- package/dist/native/sks-menubar/Sources/ProvidersViewController.swift +288 -341
- package/dist/native/sks-menubar/Sources/RemoteTelegramCenterState.swift +447 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramRendering.swift +484 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramViewController.swift +364 -115
- package/dist/native/sks-menubar/Sources/SettingsViewController.swift +73 -12
- package/dist/native/sks-menubar/Sources/SidebarItem.swift +3 -3
- package/dist/native/sks-menubar/Sources/StatusItemController.swift +13 -13
- package/dist/native/sks-menubar/Sources/TelegramHubSupervisor.swift +469 -0
- package/dist/native/sks-menubar/Sources/UpdatesViewController.swift +1 -6
- package/dist/native/sks-menubar/Tests/AppRuntimeTestSupport.swift +12 -0
- package/dist/native/sks-menubar/Tests/NativeTelegramRegressionRunner.swift +55 -0
- package/dist/native/sks-menubar/Tests/ProcessClientTests.swift +33 -0
- package/dist/native/sks-menubar/Tests/ProvidersViewControllerTests.swift +142 -0
- package/dist/native/sks-menubar/Tests/RemoteTelegramCenterStateTests.swift +56 -0
- package/dist/native/sks-menubar/Tests/TelegramHubSupervisorTests.swift +55 -0
- package/dist/scripts/codex-lb-catalog-passthrough-check.js +120 -0
- package/dist/scripts/codex-lb-desktop-auth-invariant-check.js +169 -0
- package/dist/scripts/codex-lb-desktop-bridge-check.js +394 -0
- package/dist/scripts/codex-lb-desktop-bridge-latency-check.js +196 -0
- package/dist/scripts/codex-lb-desktop-capabilities-check.js +287 -0
- package/dist/scripts/codex-lb-desktop-real-evidence-check.js +123 -0
- package/dist/scripts/codex-lb-fast-mode-truth-check.js +10 -3
- package/dist/scripts/codex-lb-fast-ui-preservation-check.js +81 -40
- package/dist/scripts/codex-lb-gpt56-fast-profile-check.js +99 -37
- package/dist/scripts/context-graph-check.js +191 -0
- package/dist/scripts/doctor-fixes-codex-app-fast-ui-check.js +1 -1
- package/dist/scripts/gate-policy-audit-check.js +1 -1
- package/dist/scripts/helper-dedup-check.js +0 -2
- package/dist/scripts/installed-package-smoke-check.js +4 -1
- package/dist/scripts/latest-version-guidance-check.js +74 -0
- package/dist/scripts/release-metadata-check.js +21 -4
- package/dist/scripts/release-real-check.js +7 -0
- package/dist/scripts/ux-review-imagegen-blackbox-check.js +25 -1
- package/dist/scripts/ux-review-run-wires-imagegen-check.js +9 -1
- package/package.json +8 -3
- package/release-gates.v2.json +176 -1
- package/runtime-required-scripts.json +30 -0
- package/schemas/triwiki/context-graph.schema.json +119 -0
- package/dist/cli/install-helpers-codex-lb-selftest-chain.js +0 -112
- package/dist/cli/install-helpers-codex-lb-selftest.js +0 -481
- package/dist/core/triwiki/code-index-scanner.js +0 -309
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { sha256 } from '../../../../fsx.js';
|
|
2
|
+
import { lintWarning } from '../../contracts.js';
|
|
3
|
+
import { contextGraphNodeId, shortDigest } from '../../ids.js';
|
|
4
|
+
import { tryNormalizeGraphPath } from '../../paths.js';
|
|
5
|
+
import { boundedText, safeText } from './redaction.js';
|
|
6
|
+
import { EvidenceSourceGraph, hasManifestPrefix, manifestHashes } from './sources.js';
|
|
7
|
+
import { CONTEXT_PACK_REL, EvidenceFragmentBuilder, RiskDomainRegistry, asArray, asFiniteNumber, asRecord, asString, asStringList, graphRiskFromBand, isRemoteCitation, readWorkspaceFile, statWorkspaceEntry, tokenEstimate } from './shared.js';
|
|
8
|
+
const MAX_CLAIMS = 512;
|
|
9
|
+
const MAX_CITATIONS_PER_CLAIM = 16;
|
|
10
|
+
const MAX_FRESHNESS_WARNINGS = 24;
|
|
11
|
+
const DECLARED_RELATION_TYPES = new Set(['supports', 'contradicts', 'supersedes']);
|
|
12
|
+
const STATUS_TRUST = {
|
|
13
|
+
supported: 0.8,
|
|
14
|
+
weak: 0.5,
|
|
15
|
+
stale: 0.3,
|
|
16
|
+
unknown: 0.35,
|
|
17
|
+
unsupported: 0.1,
|
|
18
|
+
conflicted: 0.05
|
|
19
|
+
};
|
|
20
|
+
export function extractContextPackEvidence(builder, ctx, risks) {
|
|
21
|
+
const read = readWorkspaceFile(ctx.root, CONTEXT_PACK_REL, ctx.limits.maxFileBytes);
|
|
22
|
+
if (!read.ok) {
|
|
23
|
+
builder.addSkip(read.skip);
|
|
24
|
+
builder.addIssue(lintWarning('extractor_skipped_input', 'TriWiki context pack is absent or unreadable; no claim evidence was extracted', {
|
|
25
|
+
path: CONTEXT_PACK_REL,
|
|
26
|
+
extractor: builder.fragment.extractor
|
|
27
|
+
}));
|
|
28
|
+
return { packPresent: false, packHash: null, claimCount: 0 };
|
|
29
|
+
}
|
|
30
|
+
builder.addInputHash(CONTEXT_PACK_REL, read.value.hash);
|
|
31
|
+
let parsed = null;
|
|
32
|
+
try {
|
|
33
|
+
parsed = JSON.parse(read.value.bytes.toString('utf8'));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
parsed = null;
|
|
37
|
+
}
|
|
38
|
+
const pack = asRecord(parsed);
|
|
39
|
+
if (!pack) {
|
|
40
|
+
builder.addSkip({ path: CONTEXT_PACK_REL, reason: 'unreadable', detail: 'context_pack_corrupt' });
|
|
41
|
+
builder.addIssue(lintWarning('extractor_skipped_input', 'TriWiki context pack is not decodable JSON; no claim evidence was extracted', {
|
|
42
|
+
path: CONTEXT_PACK_REL,
|
|
43
|
+
extractor: builder.fragment.extractor
|
|
44
|
+
}));
|
|
45
|
+
return { packPresent: false, packHash: read.value.hash, claimCount: 0 };
|
|
46
|
+
}
|
|
47
|
+
const packHash = read.value.hash;
|
|
48
|
+
const manifest = manifestHashes(pack);
|
|
49
|
+
const anchors = anchorHydrationPaths(pack);
|
|
50
|
+
const rows = claimRows(pack, anchors);
|
|
51
|
+
const sources = new EvidenceSourceGraph(builder, ctx, manifest, packHash);
|
|
52
|
+
const knownClaims = new Map();
|
|
53
|
+
let freshnessWarnings = 0;
|
|
54
|
+
for (const row of rows)
|
|
55
|
+
knownClaims.set(row.claimId, row.nodeId);
|
|
56
|
+
for (const row of rows) {
|
|
57
|
+
const citations = resolveCitations(ctx, row, manifest);
|
|
58
|
+
const localStates = [];
|
|
59
|
+
for (const rel of citations.local) {
|
|
60
|
+
const state = sources.ensure(rel);
|
|
61
|
+
localStates.push(state);
|
|
62
|
+
builder.addEdge({
|
|
63
|
+
from: row.nodeId,
|
|
64
|
+
to: state.id,
|
|
65
|
+
type: 'cites',
|
|
66
|
+
confidence: 'manifest',
|
|
67
|
+
provenancePath: CONTEXT_PACK_REL,
|
|
68
|
+
provenanceHash: packHash
|
|
69
|
+
});
|
|
70
|
+
if (state.freshness === 'unknown' && freshnessWarnings < MAX_FRESHNESS_WARNINGS) {
|
|
71
|
+
freshnessWarnings += 1;
|
|
72
|
+
builder.addIssue(lintWarning('unknown_freshness', 'cited source has no comparable hash in the pack source manifest', {
|
|
73
|
+
nodeId: state.id,
|
|
74
|
+
path: rel,
|
|
75
|
+
extractor: builder.fragment.extractor
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
addClaimNode(builder, risks, row, localStates, citations, packHash);
|
|
80
|
+
}
|
|
81
|
+
addDeclaredRelations(builder, pack, rows, knownClaims, packHash);
|
|
82
|
+
return { packPresent: true, packHash, claimCount: rows.length };
|
|
83
|
+
}
|
|
84
|
+
function anchorHydrationPaths(pack) {
|
|
85
|
+
const out = new Map();
|
|
86
|
+
const wiki = asRecord(pack.wiki);
|
|
87
|
+
if (!wiki)
|
|
88
|
+
return out;
|
|
89
|
+
for (const entry of asArray(wiki.anchors)) {
|
|
90
|
+
const anchor = asRecord(entry);
|
|
91
|
+
const id = anchor ? asString(anchor.id) : null;
|
|
92
|
+
const hydrate = anchor ? asString(anchor.p) : null;
|
|
93
|
+
if (id && hydrate)
|
|
94
|
+
out.set(id, hydrate);
|
|
95
|
+
}
|
|
96
|
+
for (const entry of asArray(wiki.a)) {
|
|
97
|
+
const row = asArray(entry);
|
|
98
|
+
const id = asString(row[0]);
|
|
99
|
+
const hydrate = asString(row[8]);
|
|
100
|
+
if (id && hydrate && !out.has(id))
|
|
101
|
+
out.set(id, hydrate);
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function claimRows(pack, anchors) {
|
|
106
|
+
const rows = [];
|
|
107
|
+
const seen = new Set();
|
|
108
|
+
for (const entry of asArray(pack.claims)) {
|
|
109
|
+
if (rows.length >= MAX_CLAIMS)
|
|
110
|
+
break;
|
|
111
|
+
const claim = asRecord(entry);
|
|
112
|
+
const claimId = claim ? asString(claim.id) : null;
|
|
113
|
+
if (!claim || !claimId || seen.has(claimId))
|
|
114
|
+
continue;
|
|
115
|
+
seen.add(claimId);
|
|
116
|
+
const text = asString(claim.text) ?? '';
|
|
117
|
+
const declaredHash = asString(claim.h);
|
|
118
|
+
const claimHash = declaredHash && /^[0-9a-f]{8,64}$/i.test(declaredHash)
|
|
119
|
+
? declaredHash.toLowerCase()
|
|
120
|
+
: shortDigest(`${claimId}\n${text}`);
|
|
121
|
+
rows.push({
|
|
122
|
+
claimId,
|
|
123
|
+
nodeId: contextGraphNodeId({ kind: 'wiki_claim', claimHash }),
|
|
124
|
+
text,
|
|
125
|
+
status: asString(claim.status) ?? 'unknown',
|
|
126
|
+
riskBand: asString(claim.risk) ?? 'medium',
|
|
127
|
+
authority: asString(claim.authority) ?? asString(claim.source) ?? 'unknown',
|
|
128
|
+
declaredTrust: asFiniteNumber(claim.trust_score ?? claim.trust),
|
|
129
|
+
declaredFreshness: asString(claim.freshness),
|
|
130
|
+
evidenceCount: asFiniteNumber(claim.evidence_count) ?? 0,
|
|
131
|
+
hydrationPath: anchors.get(claimId) ?? null,
|
|
132
|
+
raw: claim
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return rows.sort((left, right) => (left.nodeId < right.nodeId ? -1 : left.nodeId > right.nodeId ? 1 : 0));
|
|
136
|
+
}
|
|
137
|
+
function resolveCitations(ctx, row, manifest) {
|
|
138
|
+
const candidates = [
|
|
139
|
+
...asStringList(row.raw.source_paths),
|
|
140
|
+
...asStringList(row.raw.file),
|
|
141
|
+
...asStringList(row.raw.source),
|
|
142
|
+
...asStringList(row.raw.hydrate),
|
|
143
|
+
...asStringList(row.raw.evidence_path),
|
|
144
|
+
...(row.hydrationPath ? [row.hydrationPath] : [])
|
|
145
|
+
];
|
|
146
|
+
const local = new Set();
|
|
147
|
+
let remote = 0;
|
|
148
|
+
let unresolved = 0;
|
|
149
|
+
for (const candidate of candidates) {
|
|
150
|
+
if (local.size >= MAX_CITATIONS_PER_CLAIM)
|
|
151
|
+
break;
|
|
152
|
+
if (isRemoteCitation(candidate)) {
|
|
153
|
+
remote += 1;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const rel = tryNormalizeGraphPath(ctx.root, candidate);
|
|
157
|
+
if (!rel) {
|
|
158
|
+
unresolved += 1;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (!manifest.has(rel) && !hasManifestPrefix(manifest, rel) && !statWorkspaceEntry(ctx.root, rel)) {
|
|
162
|
+
unresolved += 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
local.add(rel);
|
|
166
|
+
}
|
|
167
|
+
return { local: [...local].sort(), remote, unresolved };
|
|
168
|
+
}
|
|
169
|
+
function addClaimNode(builder, risks, row, localStates, citations, packHash) {
|
|
170
|
+
const staleSources = localStates.filter((state) => state.freshness === 'stale').length;
|
|
171
|
+
const freshSources = localStates.filter((state) => state.freshness === 'fresh').length;
|
|
172
|
+
const freshness = staleSources > 0 || row.declaredFreshness === 'stale'
|
|
173
|
+
? 'stale'
|
|
174
|
+
: localStates.length > 0 && freshSources === localStates.length
|
|
175
|
+
? 'fresh'
|
|
176
|
+
: 'unknown';
|
|
177
|
+
let trust = row.declaredTrust !== null && row.declaredTrust >= 0 && row.declaredTrust <= 1
|
|
178
|
+
? row.declaredTrust
|
|
179
|
+
: STATUS_TRUST[row.status] ?? 0.35;
|
|
180
|
+
let basis = row.declaredTrust !== null ? 'declared' : 'status';
|
|
181
|
+
if (freshness === 'stale') {
|
|
182
|
+
trust = Math.min(trust, 0.35);
|
|
183
|
+
basis = 'stale_capped';
|
|
184
|
+
}
|
|
185
|
+
if (localStates.length === 0) {
|
|
186
|
+
trust = Math.min(trust, 0.2);
|
|
187
|
+
basis = 'orphan_capped';
|
|
188
|
+
builder.addIssue(lintWarning('orphan_wiki_claim', 'wiki claim carries no resolvable local citation; trust is capped', {
|
|
189
|
+
nodeId: row.nodeId,
|
|
190
|
+
path: CONTEXT_PACK_REL,
|
|
191
|
+
extractor: builder.fragment.extractor
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
else if (localStates.length === 1) {
|
|
195
|
+
trust = Math.min(trust, 0.6);
|
|
196
|
+
if (basis !== 'stale_capped')
|
|
197
|
+
basis = 'single_source_capped';
|
|
198
|
+
builder.addIssue(lintWarning('single_source_low_trust_synthesis', 'wiki claim rests on a single cited source; trust is capped', {
|
|
199
|
+
nodeId: row.nodeId,
|
|
200
|
+
path: CONTEXT_PACK_REL,
|
|
201
|
+
extractor: builder.fragment.extractor
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
const metadata = {
|
|
205
|
+
claim_id: boundedText(row.claimId, 120),
|
|
206
|
+
text_hash: shortDigest(row.text),
|
|
207
|
+
text_length: row.text.length,
|
|
208
|
+
status: boundedText(row.status, 40),
|
|
209
|
+
risk_band: boundedText(row.riskBand, 40),
|
|
210
|
+
authority: boundedText(row.authority, 60),
|
|
211
|
+
citation_count: localStates.length,
|
|
212
|
+
remote_citation_count: citations.remote,
|
|
213
|
+
unresolved_citation_count: citations.unresolved,
|
|
214
|
+
stale_source_count: staleSources,
|
|
215
|
+
evidence_count: row.evidenceCount,
|
|
216
|
+
trust_basis: basis
|
|
217
|
+
};
|
|
218
|
+
builder.addNode({
|
|
219
|
+
id: row.nodeId,
|
|
220
|
+
kind: 'wiki_claim',
|
|
221
|
+
label: safeText(row.claimId, 120) || row.nodeId,
|
|
222
|
+
path: CONTEXT_PACK_REL,
|
|
223
|
+
contentHash: sha256(`${row.claimId}\n${row.text}`),
|
|
224
|
+
trust,
|
|
225
|
+
freshness,
|
|
226
|
+
risk: graphRiskFromBand(row.riskBand),
|
|
227
|
+
tokenCost: tokenEstimate(row.text.length || row.claimId.length),
|
|
228
|
+
metadata
|
|
229
|
+
}, CONTEXT_PACK_REL);
|
|
230
|
+
const declaredDomain = asString(row.raw.risk_domain) ?? asString(row.raw.domain);
|
|
231
|
+
const domain = declaredDomain
|
|
232
|
+
? `wiki-domain/${declaredDomain}`
|
|
233
|
+
: ['high', 'critical'].includes(row.riskBand.toLowerCase())
|
|
234
|
+
? `wiki-risk/${row.riskBand.toLowerCase()}`
|
|
235
|
+
: null;
|
|
236
|
+
if (!domain)
|
|
237
|
+
return;
|
|
238
|
+
const domainId = risks.note(domain, graphRiskFromBand(row.riskBand));
|
|
239
|
+
if (!domainId)
|
|
240
|
+
return;
|
|
241
|
+
builder.addEdge({
|
|
242
|
+
from: row.nodeId,
|
|
243
|
+
to: domainId,
|
|
244
|
+
type: 'affected_by',
|
|
245
|
+
confidence: 'manifest',
|
|
246
|
+
provenancePath: CONTEXT_PACK_REL,
|
|
247
|
+
provenanceHash: packHash
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function addDeclaredRelations(builder, pack, rows, knownClaims, packHash) {
|
|
251
|
+
const declared = [];
|
|
252
|
+
const push = (fromClaim, toClaim, type) => {
|
|
253
|
+
if (!fromClaim || !toClaim || !type || !DECLARED_RELATION_TYPES.has(type))
|
|
254
|
+
return;
|
|
255
|
+
const from = knownClaims.get(fromClaim);
|
|
256
|
+
const to = knownClaims.get(toClaim);
|
|
257
|
+
if (!from || !to || from === to)
|
|
258
|
+
return;
|
|
259
|
+
declared.push({ from, to, type: type });
|
|
260
|
+
};
|
|
261
|
+
for (const entry of [...asArray(pack.claim_relations), ...asArray(pack.claim_edges)]) {
|
|
262
|
+
const relation = asRecord(entry);
|
|
263
|
+
if (!relation)
|
|
264
|
+
continue;
|
|
265
|
+
push(asString(relation.from) ?? asString(relation.source) ?? asString(relation.claim), asString(relation.to) ?? asString(relation.target), (asString(relation.type) ?? asString(relation.relation))?.toLowerCase() ?? null);
|
|
266
|
+
}
|
|
267
|
+
for (const row of rows) {
|
|
268
|
+
for (const type of DECLARED_RELATION_TYPES) {
|
|
269
|
+
for (const target of asStringList(row.raw[type]))
|
|
270
|
+
push(row.claimId, target, type);
|
|
271
|
+
}
|
|
272
|
+
for (const entry of asArray(row.raw.relations)) {
|
|
273
|
+
const relation = asRecord(entry);
|
|
274
|
+
if (!relation)
|
|
275
|
+
continue;
|
|
276
|
+
push(row.claimId, asString(relation.to) ?? asString(relation.target), (asString(relation.type) ?? asString(relation.relation))?.toLowerCase() ?? null);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for (const relation of declared) {
|
|
280
|
+
builder.addEdge({
|
|
281
|
+
from: relation.from,
|
|
282
|
+
to: relation.to,
|
|
283
|
+
type: relation.type,
|
|
284
|
+
confidence: 'manifest',
|
|
285
|
+
provenancePath: CONTEXT_PACK_REL,
|
|
286
|
+
provenanceHash: packHash
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { lintWarning } from '../../contracts.js';
|
|
2
|
+
import { extractContextPackEvidence } from './claims.js';
|
|
3
|
+
import { extractProofEvidence } from './proofs.js';
|
|
4
|
+
import { sanitizeEvidenceFragment } from './redaction.js';
|
|
5
|
+
import { CONTEXT_PACK_REL, EVIDENCE_EXTRACTOR_ID, EVIDENCE_EXTRACTOR_REVISION, EvidenceFragmentBuilder, PROOF_BANK_REL, RiskDomainRegistry, evidenceContext, finalizeEvidenceFragment } from './shared.js';
|
|
6
|
+
export { CONTEXT_PACK_REL, EVIDENCE_EXTRACTOR_ID, EVIDENCE_EXTRACTOR_REVISION, PROOF_BANK_REL, PROOF_INDEX_REL } from './shared.js';
|
|
7
|
+
export { TRIWIKI_PROOF_INDEX_SCHEMA } from './proof-index.js';
|
|
8
|
+
const MIN_FAN_IN_FOR_VERIFICATION_WARNING = 3;
|
|
9
|
+
export class EvidenceGraphExtractor {
|
|
10
|
+
id = EVIDENCE_EXTRACTOR_ID;
|
|
11
|
+
revision = EVIDENCE_EXTRACTOR_REVISION;
|
|
12
|
+
async extract(input) {
|
|
13
|
+
const ctx = evidenceContext({ root: input.root, observedAt: input.observedAt, limits: input.limits });
|
|
14
|
+
const builder = new EvidenceFragmentBuilder(input.limits, input.observedAt);
|
|
15
|
+
const risks = new RiskDomainRegistry();
|
|
16
|
+
const pack = extractContextPackEvidence(builder, ctx, risks);
|
|
17
|
+
const proofs = extractProofEvidence(builder, ctx, risks);
|
|
18
|
+
risks.flush(builder, pack.packPresent ? CONTEXT_PACK_REL : PROOF_BANK_REL);
|
|
19
|
+
noteUnverifiedFanIn(builder);
|
|
20
|
+
if (!pack.packPresent && proofs.proofCount === 0) {
|
|
21
|
+
builder.addIssue(lintWarning('extractor_skipped_input', 'no TriWiki evidence artifacts were present; the evidence fragment is empty by observation, not by failure', {
|
|
22
|
+
path: CONTEXT_PACK_REL,
|
|
23
|
+
extractor: EVIDENCE_EXTRACTOR_ID
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
return finalizeEvidenceFragment(sanitizeEvidenceFragment(builder.fragment));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function createEvidenceGraphExtractor() {
|
|
30
|
+
return new EvidenceGraphExtractor();
|
|
31
|
+
}
|
|
32
|
+
function noteUnverifiedFanIn(builder) {
|
|
33
|
+
const incoming = new Map();
|
|
34
|
+
for (const edge of builder.fragment.edges) {
|
|
35
|
+
if (edge.type !== 'verified_by' && edge.type !== 'invalidates')
|
|
36
|
+
continue;
|
|
37
|
+
const bucket = incoming.get(edge.to) ?? { total: 0, verified: 0 };
|
|
38
|
+
bucket.total += 1;
|
|
39
|
+
if (edge.type === 'verified_by')
|
|
40
|
+
bucket.verified += 1;
|
|
41
|
+
incoming.set(edge.to, bucket);
|
|
42
|
+
}
|
|
43
|
+
for (const nodeId of [...incoming.keys()].sort()) {
|
|
44
|
+
const bucket = incoming.get(nodeId);
|
|
45
|
+
if (!bucket)
|
|
46
|
+
continue;
|
|
47
|
+
if (bucket.verified > 0 || bucket.total < MIN_FAN_IN_FOR_VERIFICATION_WARNING)
|
|
48
|
+
continue;
|
|
49
|
+
builder.addIssue(lintWarning('high_fan_in_without_verification', 'subject is referenced only by invalidated proofs and has no standing verification', {
|
|
50
|
+
nodeId,
|
|
51
|
+
extractor: EVIDENCE_EXTRACTOR_ID
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { sha256 } from '../../../../fsx.js';
|
|
3
|
+
import { resolveInsideWorkspace, tryNormalizeGraphPath } from '../../paths.js';
|
|
4
|
+
import { PROOF_BANK_REL, PROOF_INDEX_REL, asArray, asRecord, asString, asStringList, readWorkspaceFile, statWorkspaceEntry } from './shared.js';
|
|
5
|
+
export const TRIWIKI_PROOF_INDEX_SCHEMA = 'sks.triwiki-proof-index.v1';
|
|
6
|
+
const MAX_PROOF_RECORDS = 512;
|
|
7
|
+
const MAX_SCAN_DEPTH = 4;
|
|
8
|
+
const SCAN_EXCLUDED_DIRS = new Set(['.locks', 'node_modules', '.git']);
|
|
9
|
+
export function discoverProofRecords(ctx) {
|
|
10
|
+
const indexed = readProofIndex(ctx);
|
|
11
|
+
if (indexed.ok)
|
|
12
|
+
return indexed.discovery;
|
|
13
|
+
const scanned = scanProofBank(ctx);
|
|
14
|
+
return { ...scanned, skipped: [...indexed.skipped, ...scanned.skipped] };
|
|
15
|
+
}
|
|
16
|
+
function insideProofBank(rel) {
|
|
17
|
+
return rel === PROOF_BANK_REL || rel.startsWith(`${PROOF_BANK_REL}/`);
|
|
18
|
+
}
|
|
19
|
+
function readProofIndex(ctx) {
|
|
20
|
+
const read = readWorkspaceFile(ctx.root, PROOF_INDEX_REL, ctx.limits.maxFileBytes);
|
|
21
|
+
if (!read.ok)
|
|
22
|
+
return { ok: false, skipped: [] };
|
|
23
|
+
let parsed = null;
|
|
24
|
+
try {
|
|
25
|
+
parsed = JSON.parse(read.value.bytes.toString('utf8'));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
parsed = null;
|
|
29
|
+
}
|
|
30
|
+
const file = asRecord(parsed);
|
|
31
|
+
if (!file || file.schema !== TRIWIKI_PROOF_INDEX_SCHEMA) {
|
|
32
|
+
return { ok: false, skipped: [{ path: PROOF_INDEX_REL, reason: 'unreadable', detail: 'proof_index_schema_mismatch' }] };
|
|
33
|
+
}
|
|
34
|
+
const records = [];
|
|
35
|
+
const skipped = [];
|
|
36
|
+
let truncated = false;
|
|
37
|
+
const limit = Math.min(MAX_PROOF_RECORDS, Math.max(0, ctx.limits.maxFiles));
|
|
38
|
+
for (const entry of asArray(file.proofs)) {
|
|
39
|
+
if (records.length >= limit) {
|
|
40
|
+
truncated = true;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
const row = asRecord(entry);
|
|
44
|
+
if (!row)
|
|
45
|
+
continue;
|
|
46
|
+
const proofId = asString(row.proof_id);
|
|
47
|
+
const subjectId = asString(row.subject_id);
|
|
48
|
+
const declaredPath = asString(row.path);
|
|
49
|
+
const hash = asString(row.hash);
|
|
50
|
+
if (!proofId || !subjectId || !declaredPath || !hash)
|
|
51
|
+
continue;
|
|
52
|
+
const rel = tryNormalizeGraphPath(ctx.root, declaredPath);
|
|
53
|
+
if (!rel || !insideProofBank(rel)) {
|
|
54
|
+
skipped.push({ path: PROOF_INDEX_REL, reason: 'excluded', detail: `proof_path_outside_proof_bank:${proofId}` });
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
records.push({
|
|
58
|
+
proofId,
|
|
59
|
+
subjectType: asString(row.subject_type) ?? 'unknown',
|
|
60
|
+
subjectId,
|
|
61
|
+
rel,
|
|
62
|
+
hash,
|
|
63
|
+
cacheKey: asString(row.cache_key),
|
|
64
|
+
reusable: typeof row.reusable === 'boolean' ? row.reusable : null,
|
|
65
|
+
expiresAt: asString(row.expires_at),
|
|
66
|
+
invalidationReasons: asStringList(row.invalidation_reasons),
|
|
67
|
+
cardPresent: statWorkspaceEntry(ctx.root, rel) !== null,
|
|
68
|
+
corrupt: false,
|
|
69
|
+
card: null
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (truncated)
|
|
73
|
+
skipped.push({ path: PROOF_INDEX_REL, reason: 'cap_reached', detail: 'proof_index_entry_cap' });
|
|
74
|
+
return {
|
|
75
|
+
ok: true,
|
|
76
|
+
discovery: {
|
|
77
|
+
mode: 'index',
|
|
78
|
+
records: sortRecords(records),
|
|
79
|
+
skipped,
|
|
80
|
+
inputHashes: { [PROOF_INDEX_REL]: read.value.hash },
|
|
81
|
+
truncated
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function scanProofBank(ctx) {
|
|
86
|
+
const bankStat = statWorkspaceEntry(ctx.root, PROOF_BANK_REL);
|
|
87
|
+
if (!bankStat || !bankStat.isDirectory()) {
|
|
88
|
+
return {
|
|
89
|
+
mode: 'absent',
|
|
90
|
+
records: [],
|
|
91
|
+
skipped: [{ path: PROOF_BANK_REL, reason: 'unreadable', detail: 'proof_bank_missing' }],
|
|
92
|
+
inputHashes: {},
|
|
93
|
+
truncated: false
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const skipped = [];
|
|
97
|
+
const files = listProofFiles(ctx, skipped);
|
|
98
|
+
const records = [];
|
|
99
|
+
const inputHashes = {};
|
|
100
|
+
for (const rel of files.paths) {
|
|
101
|
+
const read = readWorkspaceFile(ctx.root, rel, ctx.limits.maxFileBytes);
|
|
102
|
+
if (!read.ok) {
|
|
103
|
+
skipped.push(read.skip);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
inputHashes[rel] = read.value.hash;
|
|
107
|
+
const record = decodeProofCard(rel, read.value.bytes, read.value.hash);
|
|
108
|
+
if (record)
|
|
109
|
+
records.push(record);
|
|
110
|
+
}
|
|
111
|
+
return { mode: 'scan', records: sortRecords(records), skipped, inputHashes, truncated: files.truncated };
|
|
112
|
+
}
|
|
113
|
+
function decodeProofCard(rel, bytes, hash) {
|
|
114
|
+
let parsed = null;
|
|
115
|
+
try {
|
|
116
|
+
parsed = JSON.parse(bytes.toString('utf8'));
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
parsed = null;
|
|
120
|
+
}
|
|
121
|
+
const card = asRecord(parsed);
|
|
122
|
+
const proofId = card ? asString(card.proof_id) : null;
|
|
123
|
+
if (!card || !proofId) {
|
|
124
|
+
return {
|
|
125
|
+
proofId: `corrupt-${sha256(rel).slice(0, 16)}`,
|
|
126
|
+
subjectType: 'unknown',
|
|
127
|
+
subjectId: 'unknown',
|
|
128
|
+
rel,
|
|
129
|
+
hash,
|
|
130
|
+
cacheKey: null,
|
|
131
|
+
reusable: false,
|
|
132
|
+
expiresAt: null,
|
|
133
|
+
invalidationReasons: ['corrupt_proof_card'],
|
|
134
|
+
cardPresent: true,
|
|
135
|
+
corrupt: true,
|
|
136
|
+
card: null
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
proofId,
|
|
141
|
+
subjectType: asString(card.subject_type) ?? 'unknown',
|
|
142
|
+
subjectId: asString(card.subject_id) ?? 'unknown',
|
|
143
|
+
rel,
|
|
144
|
+
hash,
|
|
145
|
+
cacheKey: asString(card.cache_key),
|
|
146
|
+
reusable: typeof card.reusable === 'boolean' ? card.reusable : null,
|
|
147
|
+
expiresAt: asString(card.expires_at),
|
|
148
|
+
invalidationReasons: asStringList(card.invalidation_reasons),
|
|
149
|
+
cardPresent: true,
|
|
150
|
+
corrupt: false,
|
|
151
|
+
card: card
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function listProofFiles(ctx, skipped) {
|
|
155
|
+
const limit = Math.min(MAX_PROOF_RECORDS, Math.max(0, ctx.limits.maxFiles));
|
|
156
|
+
const out = [];
|
|
157
|
+
let truncated = false;
|
|
158
|
+
const queue = [{ rel: PROOF_BANK_REL, depth: 0 }];
|
|
159
|
+
while (queue.length) {
|
|
160
|
+
const current = queue.shift();
|
|
161
|
+
if (!current)
|
|
162
|
+
break;
|
|
163
|
+
if (current.depth > MAX_SCAN_DEPTH) {
|
|
164
|
+
truncated = true;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
let entries;
|
|
168
|
+
try {
|
|
169
|
+
const absolute = resolveInsideWorkspace(ctx.root, current.rel);
|
|
170
|
+
if (!absolute)
|
|
171
|
+
continue;
|
|
172
|
+
entries = fs.readdirSync(absolute, { withFileTypes: true });
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
skipped.push({ path: current.rel, reason: 'unreadable', detail: 'proof_dir_unreadable' });
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
for (const entry of [...entries].sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0))) {
|
|
179
|
+
const rel = `${current.rel}/${entry.name}`;
|
|
180
|
+
if (entry.isDirectory()) {
|
|
181
|
+
if (SCAN_EXCLUDED_DIRS.has(entry.name))
|
|
182
|
+
continue;
|
|
183
|
+
queue.push({ rel, depth: current.depth + 1 });
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (!entry.isFile())
|
|
187
|
+
continue;
|
|
188
|
+
if (!entry.name.endsWith('.json'))
|
|
189
|
+
continue;
|
|
190
|
+
if (entry.name.includes('.corrupt-'))
|
|
191
|
+
continue;
|
|
192
|
+
if (rel === PROOF_INDEX_REL)
|
|
193
|
+
continue;
|
|
194
|
+
if (out.length >= limit) {
|
|
195
|
+
truncated = true;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
out.push(rel);
|
|
199
|
+
}
|
|
200
|
+
if (truncated)
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
if (truncated)
|
|
204
|
+
skipped.push({ path: PROOF_BANK_REL, reason: 'cap_reached', detail: 'proof_scan_cap' });
|
|
205
|
+
return { paths: out.sort(), truncated };
|
|
206
|
+
}
|
|
207
|
+
function sortRecords(records) {
|
|
208
|
+
return [...records].sort((left, right) => {
|
|
209
|
+
if (left.rel !== right.rel)
|
|
210
|
+
return left.rel < right.rel ? -1 : 1;
|
|
211
|
+
return left.proofId < right.proofId ? -1 : left.proofId > right.proofId ? 1 : 0;
|
|
212
|
+
});
|
|
213
|
+
}
|