@remnic/core 9.26.0 → 9.28.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/dist/access-admin-ops-surface.d.ts +13 -10
- package/dist/access-admin-ops-surface.js +43 -38
- package/dist/access-audit.js +2 -2
- package/dist/access-authorization-probe.d.ts +13 -10
- package/dist/access-authorization-probe.js +44 -39
- package/dist/access-boundary.d.ts +13 -10
- package/dist/access-boundary.js +43 -38
- package/dist/access-cli.js +100 -94
- package/dist/access-cli.js.map +1 -1
- package/dist/access-health-types.d.ts +10 -1
- package/dist/access-http-lcm-compaction.d.ts +13 -10
- package/dist/access-http.d.ts +13 -10
- package/dist/access-http.js +53 -48
- package/dist/access-identity-continuity-surface.d.ts +9 -8
- package/dist/access-identity-continuity-surface.js +43 -38
- package/dist/access-lcm-surface.d.ts +13 -10
- package/dist/access-lcm-surface.js +43 -38
- package/dist/access-mcp.d.ts +13 -10
- package/dist/access-mcp.js +48 -43
- package/dist/access-memory-search-fanout.d.ts +2 -2
- package/dist/{access-namespace-preflight-wRSZEO5V.d.ts → access-namespace-preflight-BiQ_-iUJ.d.ts} +1 -1
- package/dist/access-namespace-preflight.d.ts +3 -3
- package/dist/access-namespace-preflight.js +43 -38
- package/dist/access-observe-write-surface.d.ts +13 -10
- package/dist/access-observe-write-surface.js +43 -38
- package/dist/access-operations-batch.js +45 -40
- package/dist/access-operations.d.ts +16 -13
- package/dist/access-operations.js +47 -42
- package/dist/access-recall-concurrency.d.ts +13 -10
- package/dist/access-recall-concurrency.js +43 -38
- package/dist/access-recall-response.d.ts +13 -10
- package/dist/access-recall-response.js +43 -38
- package/dist/access-recall-surface.d.ts +13 -10
- package/dist/access-recall-surface.js +43 -38
- package/dist/access-schema.d.ts +80 -80
- package/dist/access-schema.js +4 -4
- package/dist/{access-service-DL8FJnTj.d.ts → access-service-CXkIgcGh.d.ts} +12 -8
- package/dist/access-service.d.ts +13 -10
- package/dist/access-service.js +43 -38
- package/dist/access-surface-catalog.d.ts +13 -10
- package/dist/access-wearables-meetings-surface.d.ts +4 -3
- package/dist/action-confidence.d.ts +1 -1
- package/dist/active-memory-bridge.d.ts +1 -1
- package/dist/active-recall.d.ts +1 -1
- package/dist/active-recall.js +4 -2
- package/dist/active-recall.js.map +1 -1
- package/dist/adapters/index.js +7 -7
- package/dist/adapters/registry.js +3 -3
- package/dist/behavior-learner.d.ts +1 -1
- package/dist/behavior-signals.d.ts +1 -1
- package/dist/bootstrap.d.ts +9 -8
- package/dist/briefing.d.ts +3 -2
- package/dist/briefing.js +12 -10
- package/dist/buffer-surprise-report.d.ts +1 -1
- package/dist/buffer.d.ts +3 -2
- package/dist/bulk-import/index.d.ts +3 -3
- package/dist/calibration.d.ts +1 -1
- package/dist/capabilities.d.ts +1 -1
- package/dist/{capsule-crypto-YO5QJ6L3.js → capsule-crypto-7FJQINUR.js} +2 -2
- package/dist/{catalog-BLLxZ5L5.d.ts → catalog-Bouj8Gfg.d.ts} +1 -1
- package/dist/causal-behavior.d.ts +1 -1
- package/dist/causal-consolidation.d.ts +1 -1
- package/dist/causal-consolidation.js +13 -11
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/causal-trajectory-graph.d.ts +1 -1
- package/dist/{chunk-7RZJWZ46.js → chunk-227UFSEQ.js} +5 -5
- package/dist/{chunk-VGEH3STZ.js → chunk-2BEJ4XCF.js} +2 -2
- package/dist/{chunk-LIIQPDFN.js → chunk-2FYNLDKJ.js} +24 -3
- package/dist/chunk-2FYNLDKJ.js.map +1 -0
- package/dist/{chunk-BXLOS5AJ.js → chunk-2NLLXCJG.js} +2 -2
- package/dist/{chunk-6NNNURLK.js → chunk-2PHX3I5C.js} +8 -8
- package/dist/{chunk-YN4AUGNF.js → chunk-2TQ2UFKH.js} +65 -60
- package/dist/chunk-2TQ2UFKH.js.map +1 -0
- package/dist/{chunk-XAAIUXJO.js → chunk-3BSJBIZ3.js} +2 -2
- package/dist/{chunk-JCVQV6QX.js → chunk-3UOSVTFR.js} +11 -11
- package/dist/{chunk-AJ7QCSIS.js → chunk-7CPOZH6Y.js} +2 -2
- package/dist/{chunk-EXM2Q555.js → chunk-AHFZXUZM.js} +7 -5
- package/dist/chunk-AHFZXUZM.js.map +1 -0
- package/dist/{chunk-M2KGXXTL.js → chunk-ALTP3MFS.js} +2 -2
- package/dist/{chunk-77CNV7DY.js → chunk-BLAKS3CP.js} +4 -4
- package/dist/{chunk-FE5FKTCI.js → chunk-BR4UFMLO.js} +2 -2
- package/dist/chunk-CVILPI77.js +432 -0
- package/dist/chunk-CVILPI77.js.map +1 -0
- package/dist/{chunk-H2PBM562.js → chunk-DKQM5Q6Q.js} +2 -2
- package/dist/{chunk-CSXHRAJJ.js → chunk-EG64LXKL.js} +3 -3
- package/dist/{chunk-PTN6UAUA.js → chunk-ES36HTSC.js} +4 -4
- package/dist/{chunk-WMDRLTNA.js → chunk-EZWWCN7I.js} +2 -2
- package/dist/{chunk-XKGPIWGI.js → chunk-FBZTWUK5.js} +5 -5
- package/dist/{chunk-GJJBPI6I.js → chunk-FOCEI3TN.js} +6 -3
- package/dist/chunk-FOCEI3TN.js.map +1 -0
- package/dist/{chunk-Y6E37WRG.js → chunk-GJPCP5CA.js} +2 -2
- package/dist/{chunk-IHMXPG4P.js → chunk-GQSMYXKL.js} +6 -4
- package/dist/{chunk-IHMXPG4P.js.map → chunk-GQSMYXKL.js.map} +1 -1
- package/dist/{chunk-TGQ2NTWH.js → chunk-IJ6WHMFB.js} +16 -2
- package/dist/{chunk-TGQ2NTWH.js.map → chunk-IJ6WHMFB.js.map} +1 -1
- package/dist/{chunk-VDX2J7OX.js → chunk-IPLYGWQF.js} +6 -6
- package/dist/{chunk-XNUBF6RF.js → chunk-IYT632D5.js} +3 -3
- package/dist/{chunk-2QSZNTDO.js → chunk-JBPKEARU.js} +7 -7
- package/dist/{chunk-67DSDRUB.js → chunk-JIF3VRKQ.js} +8 -8
- package/dist/{chunk-V25OWXAC.js → chunk-JQ7T5VDC.js} +1 -1
- package/dist/chunk-JQ7T5VDC.js.map +1 -0
- package/dist/{chunk-MIFF37NN.js → chunk-KKBTBUVT.js} +2 -2
- package/dist/{chunk-ZHP4SUPB.js → chunk-LIHC3T43.js} +2 -2
- package/dist/{chunk-PX7VDW7R.js → chunk-MJPV4LBH.js} +79 -79
- package/dist/{chunk-PX7VDW7R.js.map → chunk-MJPV4LBH.js.map} +1 -1
- package/dist/{chunk-UGH6VPPO.js → chunk-MWTMTW2T.js} +2 -2
- package/dist/{chunk-F6LSNPPB.js → chunk-MXJ3VP6S.js} +6 -6
- package/dist/{chunk-KPWLZBXZ.js → chunk-NBNDVNJ2.js} +186 -25
- package/dist/chunk-NBNDVNJ2.js.map +1 -0
- package/dist/{chunk-M5EPMNS4.js → chunk-P2CLYN6H.js} +2 -2
- package/dist/{chunk-7XXCIO6X.js → chunk-PXQM2HOG.js} +13 -6
- package/dist/{chunk-7XXCIO6X.js.map → chunk-PXQM2HOG.js.map} +1 -1
- package/dist/{chunk-UZK7VVPD.js → chunk-Q5VJUNXA.js} +1858 -272
- package/dist/chunk-Q5VJUNXA.js.map +1 -0
- package/dist/{chunk-KGTD2KZJ.js → chunk-Q6YJW6KE.js} +2 -2
- package/dist/{chunk-X3SQYAPP.js → chunk-R372P2EH.js} +2 -2
- package/dist/{chunk-HBVOJNV4.js → chunk-RKXZ7P4V.js} +3 -3
- package/dist/chunk-RMMVQQA6.js +70 -0
- package/dist/chunk-RMMVQQA6.js.map +1 -0
- package/dist/{chunk-E6EAB4J6.js → chunk-S24E4MBQ.js} +14 -14
- package/dist/chunk-S24E4MBQ.js.map +1 -0
- package/dist/{chunk-RYHWZ52A.js → chunk-S2BBISHU.js} +4 -4
- package/dist/{chunk-LLISELSY.js → chunk-TBMRQZDY.js} +2 -2
- package/dist/{chunk-FMLKOL2Z.js → chunk-TC3VNKGX.js} +4 -4
- package/dist/{chunk-7K5Q6COX.js → chunk-TVVEYCNW.js} +4 -4
- package/dist/{chunk-2XP3PWL3.js → chunk-UR5SIN7H.js} +53 -35
- package/dist/chunk-UR5SIN7H.js.map +1 -0
- package/dist/{chunk-NKDVXEFU.js → chunk-VFNI3RPT.js} +2 -2
- package/dist/chunk-VNA7W7QF.js +134 -0
- package/dist/chunk-VNA7W7QF.js.map +1 -0
- package/dist/{chunk-PQPSZICJ.js → chunk-VYYNBJXH.js} +5 -5
- package/dist/chunk-WNIUPHWV.js +152 -0
- package/dist/chunk-WNIUPHWV.js.map +1 -0
- package/dist/chunk-WRJVB3C2.js +118 -0
- package/dist/chunk-WRJVB3C2.js.map +1 -0
- package/dist/{chunk-SN3ZESWQ.js → chunk-WVVK2RFM.js} +6 -6
- package/dist/{chunk-DQEMWVMT.js → chunk-X7Y7WX73.js} +1 -1
- package/dist/{chunk-4KKV7W62.js → chunk-YOBNCD3Z.js} +6 -6
- package/dist/chunk-YXZG5TVN.js +40 -0
- package/dist/chunk-YXZG5TVN.js.map +1 -0
- package/dist/{chunk-4DJQYKMN.js → chunk-ZIKENA2C.js} +2 -2
- package/dist/chunk-ZIKENA2C.js.map +1 -0
- package/dist/{chunk-SK3EYPKC.js → chunk-ZN4UZWMT.js} +2 -2
- package/dist/{cli-BoouX6LX.d.ts → cli-DJbkaZBU.d.ts} +5 -5
- package/dist/cli.d.ts +14 -12
- package/dist/cli.js +79 -74
- package/dist/compounding/engine.d.ts +3 -2
- package/dist/compounding/engine.js +12 -10
- package/dist/compounding/preference-consolidator.d.ts +1 -1
- package/dist/compression-optimizer.d.ts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +4 -2
- package/dist/connectors/codex-materialize-runner.d.ts +1 -1
- package/dist/connectors/codex-materialize-runner.js +12 -10
- package/dist/connectors/codex-materialize.d.ts +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.js +12 -10
- package/dist/consolidation-provenance-check.d.ts +3 -2
- package/dist/consolidation-undo.d.ts +3 -2
- package/dist/contradiction/index.d.ts +3 -2
- package/dist/conversation-index/backend.d.ts +1 -1
- package/dist/conversation-index/backend.js +2 -2
- package/dist/conversation-index/chunker.d.ts +1 -1
- package/dist/conversation-index/faiss-adapter.d.ts +1 -1
- package/dist/conversation-index/indexer.d.ts +1 -1
- package/dist/conversation-index/search.d.ts +1 -1
- package/dist/corpus-watermark.d.ts +15 -2
- package/dist/corpus-watermark.js +25 -21
- package/dist/day-summary.d.ts +1 -1
- package/dist/delinearize.d.ts +1 -1
- package/dist/direct-answer-wiring.d.ts +1 -1
- package/dist/direct-answer.d.ts +1 -1
- package/dist/embedding-fallback.d.ts +1 -1
- package/dist/enrichment/index.d.ts +1 -1
- package/dist/entity-id-normalization.d.ts +4 -0
- package/dist/entity-id-normalization.js +10 -0
- package/dist/entity-id-normalization.js.map +1 -0
- package/dist/entity-retrieval-boundaries.d.ts +3 -0
- package/dist/entity-retrieval-boundaries.js +8 -0
- package/dist/entity-retrieval-boundaries.js.map +1 -0
- package/dist/entity-retrieval.d.ts +3 -2
- package/dist/entity-retrieval.js +13 -10
- package/dist/entity-schema.d.ts +1 -1
- package/dist/entity-schema.js +1 -1
- package/dist/explicit-capture.d.ts +9 -8
- package/dist/extraction-error-classification.d.ts +1 -1
- package/dist/extraction-faithfulness.d.ts +1 -1
- package/dist/extraction-judge-telemetry.d.ts +1 -1
- package/dist/extraction-judge-training.d.ts +1 -1
- package/dist/extraction-judge.d.ts +1 -1
- package/dist/extraction-liveness.d.ts +1 -1
- package/dist/extraction.d.ts +1 -1
- package/dist/fallback-llm.d.ts +1 -1
- package/dist/{first-start-migration-LEXL3XYL.js → first-start-migration-BKNGOFED.js} +4 -4
- package/dist/graph-dashboard-diff.d.ts +1 -1
- package/dist/graph-dashboard-key.d.ts +1 -1
- package/dist/graph-dashboard-parser.d.ts +1 -1
- package/dist/graph-edge-reinforcement.d.ts +1 -1
- package/dist/graph-snapshot.d.ts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/importance.d.ts +1 -1
- package/dist/importers/index.d.ts +1 -1
- package/dist/in-flight-reads.d.ts +1 -1
- package/dist/index.d.ts +409 -407
- package/dist/index.js +147 -141
- package/dist/intent.d.ts +1 -1
- package/dist/lcm/engine.d.ts +1 -1
- package/dist/lcm/engine.js +3 -3
- package/dist/lcm/index.d.ts +1 -1
- package/dist/lcm/index.js +9 -9
- package/dist/lcm/tools.d.ts +1 -1
- package/dist/lifecycle.d.ts +1 -1
- package/dist/live-connectors-runner.d.ts +1 -1
- package/dist/local-llm.d.ts +1 -1
- package/dist/local-model-endpoint.d.ts +1 -1
- package/dist/maintenance/memory-governance.d.ts +1 -1
- package/dist/maintenance/memory-governance.js +12 -10
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +3 -2
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +12 -10
- package/dist/maintenance/rebuild-memory-projection.d.ts +3 -2
- package/dist/maintenance/rebuild-memory-projection.js +13 -11
- package/dist/{maintenance-DD22oIx9.d.ts → maintenance-DveW6azo.d.ts} +3 -3
- package/dist/mcp-memory-inspector-app.d.ts +13 -10
- package/dist/memory-action-policy.d.ts +1 -1
- package/dist/memory-cache.d.ts +1 -1
- package/dist/memory-lifecycle-ledger-utils.d.ts +1 -1
- package/dist/memory-projection-mutations.d.ts +4 -0
- package/dist/memory-projection-mutations.js +15 -0
- package/dist/memory-projection-mutations.js.map +1 -0
- package/dist/memory-projection-store.d.ts +1 -1
- package/dist/memory-provenance.d.ts +1 -1
- package/dist/memory-worth-outcomes.d.ts +3 -2
- package/dist/models-json.d.ts +1 -1
- package/dist/namespaces/migrate.d.ts +4 -3
- package/dist/namespaces/migrate.js +22 -20
- package/dist/namespaces/principal.d.ts +1 -1
- package/dist/namespaces/search.d.ts +1 -1
- package/dist/namespaces/search.js +9 -9
- package/dist/namespaces/storage.d.ts +4 -3
- package/dist/namespaces/storage.js +12 -10
- package/dist/native-knowledge.d.ts +1 -1
- package/dist/offline-sync-impression-drain.d.ts +1 -1
- package/dist/offline-sync-impression-drain.js +3 -3
- package/dist/operator-doctor-corpus.d.ts +22 -3
- package/dist/operator-doctor-corpus.js +32 -22
- package/dist/operator-doctor-replica.d.ts +52 -0
- package/dist/operator-doctor-replica.js +15 -0
- package/dist/operator-doctor-replica.js.map +1 -0
- package/dist/operator-toolkit.d.ts +7 -3
- package/dist/operator-toolkit.js +33 -27
- package/dist/orchestration/compression-guideline-coordinator.d.ts +3 -2
- package/dist/orchestration/maintenance.d.ts +5 -4
- package/dist/orchestration/maintenance.js +17 -15
- package/dist/{orchestrator-CFJ_TG6D.d.ts → orchestrator-Cvlgpe6I.d.ts} +7 -7
- package/dist/orchestrator.d.ts +9 -8
- package/dist/orchestrator.js +99 -93
- package/dist/patterns-cli.d.ts +1 -1
- package/dist/{pipeline-Bq5zU6Bp.d.ts → pipeline-BveYVaz7.d.ts} +1 -1
- package/dist/policy-runtime.d.ts +1 -1
- package/dist/proactive-contention.d.ts +1 -1
- package/dist/provenance.d.ts +1 -1
- package/dist/{qmd-3ILJkC70.d.ts → qmd-CLWDsbYR.d.ts} +1 -1
- package/dist/qmd-preflight.d.ts +2 -2
- package/dist/qmd-recall-cache.d.ts +1 -1
- package/dist/qmd.d.ts +2 -2
- package/dist/recall-concurrency-config.d.ts +1 -1
- package/dist/recall-disclosure-escalation.d.ts +1 -1
- package/dist/recall-explain-renderer.d.ts +1 -1
- package/dist/recall-explain-renderer.js +3 -3
- package/dist/recall-memory-map.d.ts +1 -1
- package/dist/recall-planner-llm.d.ts +1 -1
- package/dist/recall-state.d.ts +1 -1
- package/dist/recall-state.js +2 -2
- package/dist/recall-tag-filter.d.ts +1 -1
- package/dist/recall-timings.d.ts +1 -1
- package/dist/recall-xray-cli.d.ts +1 -1
- package/dist/recall-xray-cli.js +4 -4
- package/dist/recall-xray-renderer.d.ts +1 -1
- package/dist/recall-xray-renderer.js +3 -3
- package/dist/recall-xray.d.ts +1 -1
- package/dist/recall-xray.js +2 -2
- package/dist/replay/normalizers/chatgpt.d.ts +1 -1
- package/dist/replay/normalizers/claude.d.ts +1 -1
- package/dist/replay/normalizers/openclaw.d.ts +1 -1
- package/dist/replay/normalizers/shared.d.ts +1 -1
- package/dist/replay/runner.d.ts +1 -1
- package/dist/replay/types.d.ts +1 -1
- package/dist/replica-divergence.d.ts +279 -0
- package/dist/replica-divergence.js +28 -0
- package/dist/replica-divergence.js.map +1 -0
- package/dist/replica-peers-config.d.ts +5 -0
- package/dist/replica-peers-config.js +13 -0
- package/dist/replica-peers-config.js.map +1 -0
- package/dist/resolve-auth-token.d.ts +21 -2
- package/dist/resolve-auth-token.js +5 -1
- package/dist/resume-bundles.js +5 -3
- package/dist/retrieval-agents.d.ts +2 -2
- package/dist/retrieval-tiers.d.ts +1 -1
- package/dist/routing/engine.d.ts +1 -1
- package/dist/routing/store.d.ts +1 -1
- package/dist/salvage-envelope.d.ts +1 -1
- package/dist/schemas.d.ts +76 -76
- package/dist/{scope-profiles-D0-ff4xT.d.ts → scope-profiles-BVf3DZ7z.d.ts} +1 -1
- package/dist/search/embed-helper.d.ts +1 -1
- package/dist/search/factory.d.ts +1 -1
- package/dist/search/factory.js +8 -8
- package/dist/search/index.d.ts +1 -1
- package/dist/search/index.js +13 -13
- package/dist/search/lancedb-backend.d.ts +1 -1
- package/dist/search/lancedb-backend.js +2 -2
- package/dist/search/meilisearch-backend.d.ts +1 -1
- package/dist/search/meilisearch-backend.js +2 -2
- package/dist/search/noop-backend.d.ts +1 -1
- package/dist/search/orama-backend.d.ts +1 -1
- package/dist/search/orama-backend.js +2 -2
- package/dist/search/port.d.ts +1 -1
- package/dist/search/remote-backend.d.ts +1 -1
- package/dist/{semantic-consolidation-4Tfh7c1g.d.ts → semantic-consolidation-DXLV47y2.d.ts} +1 -1
- package/dist/semantic-consolidation.d.ts +2 -2
- package/dist/semantic-consolidation.js +13 -11
- package/dist/semantic-rule-promotion.js +12 -10
- package/dist/semantic-rule-verifier.d.ts +1 -1
- package/dist/semantic-rule-verifier.js +12 -10
- package/dist/{service-Z8uzoAST.d.ts → service-DbgPTeMJ.d.ts} +2 -2
- package/dist/session-observer-bands.d.ts +1 -1
- package/dist/session-observer-state.d.ts +1 -1
- package/dist/shared-context/manager.d.ts +9 -9
- package/dist/signal.d.ts +1 -1
- package/dist/{storage-BZVMn8yJ.d.ts → storage-DOzTm8wG.d.ts} +13 -22
- package/dist/storage.d.ts +3 -2
- package/dist/storage.js +13 -10
- package/dist/summarizer.d.ts +1 -1
- package/dist/summary-snapshot.d.ts +1 -1
- package/dist/temporal-supersession.d.ts +3 -2
- package/dist/temporal-timeline-recall.d.ts +1 -1
- package/dist/temporal-validity.d.ts +1 -1
- package/dist/threading.d.ts +1 -1
- package/dist/tier-migration.d.ts +3 -2
- package/dist/tier-routing.d.ts +1 -1
- package/dist/topics.d.ts +1 -1
- package/dist/transcript.d.ts +1 -1
- package/dist/transfer/autodetect.js +1 -1
- package/dist/transfer/backup.js +2 -2
- package/dist/transfer/capsule-export.js +3 -3
- package/dist/transfer/capsule-import.js +2 -2
- package/dist/transfer/types.d.ts +66 -66
- package/dist/trust-score-stage.d.ts +1 -1
- package/dist/trust-score.d.ts +1 -1
- package/dist/{types-DHBxIF0s.d.ts → types-BA7W-_xy.d.ts} +53 -4
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/utility-runtime.d.ts +1 -1
- package/dist/verified-recall.js +12 -10
- package/dist/write-envelope.d.ts +1 -1
- package/package.json +2 -2
- package/src/access-health-types.ts +8 -0
- package/src/access-http.test.ts +4 -0
- package/src/access-service-health.test.ts +23 -0
- package/src/access-service.ts +27 -4
- package/src/cli.ts +9 -7
- package/src/config.ts +2 -1
- package/src/corpus-watermark.test.ts +21 -0
- package/src/corpus-watermark.ts +25 -3
- package/src/entity-id-normalization.ts +55 -0
- package/src/entity-retrieval-boundaries.ts +134 -0
- package/src/entity-retrieval.ts +253 -27
- package/src/entity-schema.ts +2 -1
- package/src/memory-projection-mutations.ts +132 -0
- package/src/namespaces/storage.ts +5 -3
- package/src/operator-doctor-corpus.ts +41 -0
- package/src/operator-doctor-replica.test.ts +261 -0
- package/src/operator-doctor-replica.ts +129 -0
- package/src/operator-toolkit.ts +5 -4
- package/src/orchestration/orchestrator-init.ts +2 -2
- package/src/replica-divergence.test.ts +1475 -0
- package/src/replica-divergence.ts +910 -0
- package/src/replica-peers-config.ts +250 -0
- package/src/resolve-auth-token.ts +38 -0
- package/src/storage/entity-canonical-id-migration-adapter.ts +72 -0
- package/src/storage/entity-canonical-id-migration-runner.ts +68 -0
- package/src/storage/entity-canonical-id-migration.ts +904 -0
- package/src/storage/entity-store.ts +44 -0
- package/src/storage/memory-frontmatter-metadata.ts +17 -0
- package/src/storage/memory-migration-serialization.ts +37 -0
- package/src/storage/memory-read-store.ts +3 -2
- package/src/storage/profile-header.ts +898 -0
- package/src/storage-profile-timestamp.test.ts +3358 -0
- package/src/storage.ts +73 -77
- package/src/testing/subjects/profile-header-write.test.ts +71 -0
- package/src/types.ts +3 -3
- package/dist/chunk-2XP3PWL3.js.map +0 -1
- package/dist/chunk-4DJQYKMN.js.map +0 -1
- package/dist/chunk-E6EAB4J6.js.map +0 -1
- package/dist/chunk-EXM2Q555.js.map +0 -1
- package/dist/chunk-GJJBPI6I.js.map +0 -1
- package/dist/chunk-KPWLZBXZ.js.map +0 -1
- package/dist/chunk-LIIQPDFN.js.map +0 -1
- package/dist/chunk-UZK7VVPD.js.map +0 -1
- package/dist/chunk-V25OWXAC.js.map +0 -1
- package/dist/chunk-YN4AUGNF.js.map +0 -1
- /package/dist/{capsule-crypto-YO5QJ6L3.js.map → capsule-crypto-7FJQINUR.js.map} +0 -0
- /package/dist/{chunk-7RZJWZ46.js.map → chunk-227UFSEQ.js.map} +0 -0
- /package/dist/{chunk-VGEH3STZ.js.map → chunk-2BEJ4XCF.js.map} +0 -0
- /package/dist/{chunk-BXLOS5AJ.js.map → chunk-2NLLXCJG.js.map} +0 -0
- /package/dist/{chunk-6NNNURLK.js.map → chunk-2PHX3I5C.js.map} +0 -0
- /package/dist/{chunk-XAAIUXJO.js.map → chunk-3BSJBIZ3.js.map} +0 -0
- /package/dist/{chunk-JCVQV6QX.js.map → chunk-3UOSVTFR.js.map} +0 -0
- /package/dist/{chunk-AJ7QCSIS.js.map → chunk-7CPOZH6Y.js.map} +0 -0
- /package/dist/{chunk-M2KGXXTL.js.map → chunk-ALTP3MFS.js.map} +0 -0
- /package/dist/{chunk-77CNV7DY.js.map → chunk-BLAKS3CP.js.map} +0 -0
- /package/dist/{chunk-FE5FKTCI.js.map → chunk-BR4UFMLO.js.map} +0 -0
- /package/dist/{chunk-H2PBM562.js.map → chunk-DKQM5Q6Q.js.map} +0 -0
- /package/dist/{chunk-CSXHRAJJ.js.map → chunk-EG64LXKL.js.map} +0 -0
- /package/dist/{chunk-PTN6UAUA.js.map → chunk-ES36HTSC.js.map} +0 -0
- /package/dist/{chunk-WMDRLTNA.js.map → chunk-EZWWCN7I.js.map} +0 -0
- /package/dist/{chunk-XKGPIWGI.js.map → chunk-FBZTWUK5.js.map} +0 -0
- /package/dist/{chunk-Y6E37WRG.js.map → chunk-GJPCP5CA.js.map} +0 -0
- /package/dist/{chunk-VDX2J7OX.js.map → chunk-IPLYGWQF.js.map} +0 -0
- /package/dist/{chunk-XNUBF6RF.js.map → chunk-IYT632D5.js.map} +0 -0
- /package/dist/{chunk-2QSZNTDO.js.map → chunk-JBPKEARU.js.map} +0 -0
- /package/dist/{chunk-67DSDRUB.js.map → chunk-JIF3VRKQ.js.map} +0 -0
- /package/dist/{chunk-MIFF37NN.js.map → chunk-KKBTBUVT.js.map} +0 -0
- /package/dist/{chunk-ZHP4SUPB.js.map → chunk-LIHC3T43.js.map} +0 -0
- /package/dist/{chunk-UGH6VPPO.js.map → chunk-MWTMTW2T.js.map} +0 -0
- /package/dist/{chunk-F6LSNPPB.js.map → chunk-MXJ3VP6S.js.map} +0 -0
- /package/dist/{chunk-M5EPMNS4.js.map → chunk-P2CLYN6H.js.map} +0 -0
- /package/dist/{chunk-KGTD2KZJ.js.map → chunk-Q6YJW6KE.js.map} +0 -0
- /package/dist/{chunk-X3SQYAPP.js.map → chunk-R372P2EH.js.map} +0 -0
- /package/dist/{chunk-HBVOJNV4.js.map → chunk-RKXZ7P4V.js.map} +0 -0
- /package/dist/{chunk-RYHWZ52A.js.map → chunk-S2BBISHU.js.map} +0 -0
- /package/dist/{chunk-LLISELSY.js.map → chunk-TBMRQZDY.js.map} +0 -0
- /package/dist/{chunk-FMLKOL2Z.js.map → chunk-TC3VNKGX.js.map} +0 -0
- /package/dist/{chunk-7K5Q6COX.js.map → chunk-TVVEYCNW.js.map} +0 -0
- /package/dist/{chunk-NKDVXEFU.js.map → chunk-VFNI3RPT.js.map} +0 -0
- /package/dist/{chunk-PQPSZICJ.js.map → chunk-VYYNBJXH.js.map} +0 -0
- /package/dist/{chunk-SN3ZESWQ.js.map → chunk-WVVK2RFM.js.map} +0 -0
- /package/dist/{chunk-DQEMWVMT.js.map → chunk-X7Y7WX73.js.map} +0 -0
- /package/dist/{chunk-4KKV7W62.js.map → chunk-YOBNCD3Z.js.map} +0 -0
- /package/dist/{chunk-SK3EYPKC.js.map → chunk-ZN4UZWMT.js.map} +0 -0
- /package/dist/{first-start-migration-LEXL3XYL.js.map → first-start-migration-BKNGOFED.js.map} +0 -0
|
@@ -0,0 +1,898 @@
|
|
|
1
|
+
const LAST_UPDATED_HEADER = /^\*Last updated:[^*]*\*$/;
|
|
2
|
+
const PROFILE_TITLE = /^ {0,3}#(?:[ \t]+|$)/;
|
|
3
|
+
const MARKDOWN_HEADING = /^ {0,3}#{1,6}(?:[ \t]+|$)/;
|
|
4
|
+
const MARKDOWN_LIST_ITEM = /^(?:[-+*]|\d{1,9}[.)])[ \t]+/;
|
|
5
|
+
const MARKDOWN_LIST_ITEM_CAN_INTERRUPT = /^(?:[-+*]|1[.)])[ \t]+/;
|
|
6
|
+
const MARKDOWN_THEMATIC_BREAK = /^(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
7
|
+
const MARKDOWN_SETEXT_UNDERLINE = /^(?:=+|-+)$/;
|
|
8
|
+
const MARKDOWN_BLOCK_QUOTE = /^>/;
|
|
9
|
+
const MARKDOWN_LINK_REFERENCE =
|
|
10
|
+
/^\[(?:\\.|[^\\\[\]])+\]:[ \t]*(?:<[^>\n]*>|([^\s]+))(?:[ \t]+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?$/;
|
|
11
|
+
const MARKDOWN_LINK_REFERENCE_LABEL = /^\[(?:\\.|[^\\\[\]])+\]:[ \t]*$/;
|
|
12
|
+
const MARKDOWN_LINK_REFERENCE_CONTINUATION =
|
|
13
|
+
/^ {1,3}(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\))$/;
|
|
14
|
+
const MARKDOWN_LINK_REFERENCE_DESTINATION_CONTINUATION =
|
|
15
|
+
/^ {1,3}(?:<[^>\n]*>|(?!["'(])[^\s]+(?:[ \t]+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?)$/;
|
|
16
|
+
const UTF8_BOM = "\uFEFF";
|
|
17
|
+
|
|
18
|
+
type FenceMarker = {
|
|
19
|
+
indentation: number;
|
|
20
|
+
character: string;
|
|
21
|
+
length: number;
|
|
22
|
+
trailing: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function isLastUpdatedHeader(line: string): boolean {
|
|
26
|
+
const withoutBom = line.startsWith(UTF8_BOM) ? line.slice(1) : line;
|
|
27
|
+
if (isIndentedCodeLine(withoutBom)) return false;
|
|
28
|
+
return LAST_UPDATED_HEADER.test(withoutBom.trim());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isIndentedCodeLine(line: string): boolean {
|
|
32
|
+
let indentation = 0;
|
|
33
|
+
while (line[indentation] === " ") indentation += 1;
|
|
34
|
+
return indentation >= 4 || line[indentation] === "\t";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getFenceMarker(line: string): FenceMarker | null {
|
|
38
|
+
let indentation = 0;
|
|
39
|
+
while (line[indentation] === " ") indentation += 1;
|
|
40
|
+
if (indentation > 3 || line[indentation] === "\t") return null;
|
|
41
|
+
const trimmed = line.slice(indentation);
|
|
42
|
+
const character = trimmed[0];
|
|
43
|
+
if (character !== "`" && character !== "~") return null;
|
|
44
|
+
let length = 0;
|
|
45
|
+
while (trimmed[length] === character) length += 1;
|
|
46
|
+
if (length < 3) return null;
|
|
47
|
+
const trailing = trimmed.slice(length);
|
|
48
|
+
if (character === "`" && trailing.includes("`")) return null;
|
|
49
|
+
return { indentation, character, length, trailing };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isClosingFence(fence: FenceMarker, openFence: FenceMarker): boolean {
|
|
53
|
+
return (
|
|
54
|
+
fence.character === openFence.character &&
|
|
55
|
+
fence.length >= openFence.length &&
|
|
56
|
+
fence.trailing.trim() === ""
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const RAW_HTML_BLOCK_TAGS = ["pre", "textarea", "script", "style"] as const;
|
|
61
|
+
const HTML_BLOCK_TAGS = [
|
|
62
|
+
"address",
|
|
63
|
+
"article",
|
|
64
|
+
"aside",
|
|
65
|
+
"base",
|
|
66
|
+
"basefont",
|
|
67
|
+
"blockquote",
|
|
68
|
+
"body",
|
|
69
|
+
"caption",
|
|
70
|
+
"center",
|
|
71
|
+
"col",
|
|
72
|
+
"colgroup",
|
|
73
|
+
"dd",
|
|
74
|
+
"details",
|
|
75
|
+
"dialog",
|
|
76
|
+
"dir",
|
|
77
|
+
"div",
|
|
78
|
+
"dl",
|
|
79
|
+
"dt",
|
|
80
|
+
"fieldset",
|
|
81
|
+
"figcaption",
|
|
82
|
+
"figure",
|
|
83
|
+
"footer",
|
|
84
|
+
"form",
|
|
85
|
+
"frame",
|
|
86
|
+
"frameset",
|
|
87
|
+
"h1",
|
|
88
|
+
"h2",
|
|
89
|
+
"h3",
|
|
90
|
+
"h4",
|
|
91
|
+
"h5",
|
|
92
|
+
"h6",
|
|
93
|
+
"head",
|
|
94
|
+
"header",
|
|
95
|
+
"hgroup",
|
|
96
|
+
"hr",
|
|
97
|
+
"html",
|
|
98
|
+
"iframe",
|
|
99
|
+
"legend",
|
|
100
|
+
"li",
|
|
101
|
+
"link",
|
|
102
|
+
"main",
|
|
103
|
+
"menu",
|
|
104
|
+
"menuitem",
|
|
105
|
+
"nav",
|
|
106
|
+
"noframes",
|
|
107
|
+
"ol",
|
|
108
|
+
"optgroup",
|
|
109
|
+
"option",
|
|
110
|
+
"p",
|
|
111
|
+
"param",
|
|
112
|
+
"search",
|
|
113
|
+
"section",
|
|
114
|
+
"summary",
|
|
115
|
+
"table",
|
|
116
|
+
"tbody",
|
|
117
|
+
"td",
|
|
118
|
+
"tfoot",
|
|
119
|
+
"th",
|
|
120
|
+
"thead",
|
|
121
|
+
"title",
|
|
122
|
+
"tr",
|
|
123
|
+
"track",
|
|
124
|
+
"ul",
|
|
125
|
+
] as const;
|
|
126
|
+
|
|
127
|
+
type HtmlBlock = {
|
|
128
|
+
endMarker: string | null;
|
|
129
|
+
endsAtBlankLine: boolean;
|
|
130
|
+
tagName: string | null;
|
|
131
|
+
depth: number;
|
|
132
|
+
};
|
|
133
|
+
type OpenHtmlBlock = HtmlBlock & {
|
|
134
|
+
listIndentation: number | null;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
function findHtmlBlockTag(line: string, tags: readonly string[]): string | null {
|
|
138
|
+
const isClosing = line.startsWith("</");
|
|
139
|
+
const nameStart = isClosing ? 2 : 1;
|
|
140
|
+
for (const tag of tags) {
|
|
141
|
+
const nextCharacter = line[nameStart + tag.length];
|
|
142
|
+
const isSelfClosingSlash =
|
|
143
|
+
!isClosing && nextCharacter === "/" && line[nameStart + tag.length + 1] === ">";
|
|
144
|
+
if (
|
|
145
|
+
line.startsWith(`${isClosing ? "</" : "<"}${tag}`) &&
|
|
146
|
+
(nextCharacter === undefined ||
|
|
147
|
+
nextCharacter === ">" ||
|
|
148
|
+
isSelfClosingSlash ||
|
|
149
|
+
nextCharacter === " " ||
|
|
150
|
+
nextCharacter === "\t")
|
|
151
|
+
) {
|
|
152
|
+
return tag;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type HtmlTag = {
|
|
159
|
+
name: string;
|
|
160
|
+
isClosing: boolean;
|
|
161
|
+
isSelfClosing: boolean;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
function isAsciiLetter(character: string): boolean {
|
|
165
|
+
return (
|
|
166
|
+
(character >= "a" && character <= "z") ||
|
|
167
|
+
(character >= "A" && character <= "Z")
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isHtmlTagNameCharacter(character: string): boolean {
|
|
172
|
+
return (
|
|
173
|
+
isAsciiLetter(character) ||
|
|
174
|
+
(character >= "0" && character <= "9") ||
|
|
175
|
+
character === "-"
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const HTML_ATTRIBUTES =
|
|
179
|
+
/^(?:[A-Za-z_:][A-Za-z0-9_.:-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)(?:\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*$/;
|
|
180
|
+
|
|
181
|
+
function hasValidHtmlTagAttributes(attributeText: string, isClosing: boolean): boolean {
|
|
182
|
+
const trimmed = attributeText.trim();
|
|
183
|
+
if (isClosing || trimmed === "") return trimmed === "";
|
|
184
|
+
const withoutSelfClosingSlash = trimmed.endsWith("/")
|
|
185
|
+
? trimmed.slice(0, -1).trimEnd()
|
|
186
|
+
: trimmed;
|
|
187
|
+
return withoutSelfClosingSlash === "" || HTML_ATTRIBUTES.test(withoutSelfClosingSlash);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function findCompleteHtmlTag(line: string): HtmlTag | null {
|
|
191
|
+
let index = 1;
|
|
192
|
+
const isClosing = line[index] === "/";
|
|
193
|
+
if (isClosing) index += 1;
|
|
194
|
+
const nameStart = index;
|
|
195
|
+
if (!isAsciiLetter(line[index] ?? "")) return null;
|
|
196
|
+
while (isHtmlTagNameCharacter(line[index] ?? "")) index += 1;
|
|
197
|
+
const nextCharacter = line[index] ?? "";
|
|
198
|
+
if (
|
|
199
|
+
nextCharacter !== ">" &&
|
|
200
|
+
nextCharacter !== "/" &&
|
|
201
|
+
nextCharacter !== " " &&
|
|
202
|
+
nextCharacter !== "\t"
|
|
203
|
+
) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const name = line.slice(nameStart, index).toLowerCase();
|
|
207
|
+
let quote: string | null = null;
|
|
208
|
+
for (; index < line.length; index += 1) {
|
|
209
|
+
const character = line[index]!;
|
|
210
|
+
if (quote) {
|
|
211
|
+
if (character === quote) quote = null;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (character === "\"" || character === "'") {
|
|
215
|
+
quote = character;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (character === ">" && line.slice(index + 1).trim() === "") {
|
|
219
|
+
const tagBody = line.slice(nameStart, index).trimEnd();
|
|
220
|
+
if (!hasValidHtmlTagAttributes(tagBody.slice(name.length), isClosing)) return null;
|
|
221
|
+
return {
|
|
222
|
+
name,
|
|
223
|
+
isClosing,
|
|
224
|
+
isSelfClosing: !isClosing && tagBody.endsWith("/"),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
function findHtmlTagPrefix(line: string): HtmlTag | null {
|
|
231
|
+
let quote: string | null = null;
|
|
232
|
+
for (let index = 1; index < line.length; index += 1) {
|
|
233
|
+
const character = line[index]!;
|
|
234
|
+
if (quote) {
|
|
235
|
+
if (character === quote) quote = null;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (character === "\"" || character === "'") {
|
|
239
|
+
quote = character;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (character !== ">") continue;
|
|
243
|
+
return findCompleteHtmlTag(line.slice(0, index + 1));
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isRawHtmlBlockTerminator(line: string): boolean {
|
|
249
|
+
const normalizedLine = line.toLowerCase();
|
|
250
|
+
return RAW_HTML_BLOCK_TAGS.some((name) =>
|
|
251
|
+
hasRawHtmlBlockEndMarker(normalizedLine, `</${name}>`),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function findHtmlTags(line: string): HtmlTag[] {
|
|
256
|
+
const tags: HtmlTag[] = [];
|
|
257
|
+
let index = 0;
|
|
258
|
+
while (index < line.length) {
|
|
259
|
+
if (line[index] !== "<") {
|
|
260
|
+
index += 1;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
let cursor = index + 1;
|
|
265
|
+
const isClosing = line[cursor] === "/";
|
|
266
|
+
if (isClosing) cursor += 1;
|
|
267
|
+
const nameStart = cursor;
|
|
268
|
+
if (!isAsciiLetter(line[cursor] ?? "")) {
|
|
269
|
+
index += 1;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
while (isHtmlTagNameCharacter(line[cursor] ?? "")) cursor += 1;
|
|
273
|
+
const name = line.slice(nameStart, cursor).toLowerCase();
|
|
274
|
+
let quote: string | null = null;
|
|
275
|
+
for (; cursor < line.length; cursor += 1) {
|
|
276
|
+
const character = line[cursor] ?? "";
|
|
277
|
+
if (quote) {
|
|
278
|
+
if (character === quote) quote = null;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (character === "\"" || character === "'") {
|
|
282
|
+
quote = character;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (character !== ">") continue;
|
|
286
|
+
const tagBody = line.slice(nameStart, cursor).trimEnd();
|
|
287
|
+
tags.push({
|
|
288
|
+
name,
|
|
289
|
+
isClosing,
|
|
290
|
+
isSelfClosing: !isClosing && tagBody.endsWith("/"),
|
|
291
|
+
});
|
|
292
|
+
index = cursor + 1;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
if (cursor >= line.length) break;
|
|
296
|
+
}
|
|
297
|
+
return tags;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function updateHtmlBlockDepth(
|
|
301
|
+
htmlBlock: OpenHtmlBlock,
|
|
302
|
+
line: string,
|
|
303
|
+
skipFirstOpening: boolean,
|
|
304
|
+
): OpenHtmlBlock | null {
|
|
305
|
+
if (!htmlBlock.tagName) return htmlBlock;
|
|
306
|
+
let depth = htmlBlock.depth;
|
|
307
|
+
let skippedFirstOpening = !skipFirstOpening;
|
|
308
|
+
for (const tag of findHtmlTags(line)) {
|
|
309
|
+
if (tag.name !== htmlBlock.tagName) continue;
|
|
310
|
+
if (tag.isClosing) {
|
|
311
|
+
depth -= 1;
|
|
312
|
+
} else if (!tag.isSelfClosing) {
|
|
313
|
+
if (!skippedFirstOpening) {
|
|
314
|
+
skippedFirstOpening = true;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
depth += 1;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (depth > 0) return { ...htmlBlock, depth };
|
|
321
|
+
return htmlBlock.endsAtBlankLine
|
|
322
|
+
? { ...htmlBlock, endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 }
|
|
323
|
+
: null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function hasSpacedSelfClosingSlash(line: string): boolean {
|
|
327
|
+
return /\s\/\s*>/.test(line);
|
|
328
|
+
}
|
|
329
|
+
function findHtmlBlockStart(
|
|
330
|
+
normalizedLine: string,
|
|
331
|
+
trimmedLine: string,
|
|
332
|
+
allowGenericHtmlBlock: boolean,
|
|
333
|
+
): HtmlBlock | null {
|
|
334
|
+
const rawTag = findHtmlBlockTag(normalizedLine, RAW_HTML_BLOCK_TAGS);
|
|
335
|
+
if (rawTag) {
|
|
336
|
+
const completeTag =
|
|
337
|
+
findCompleteHtmlTag(trimmedLine) ?? findHtmlTagPrefix(trimmedLine);
|
|
338
|
+
if (!completeTag && normalizedLine.startsWith("</")) return null;
|
|
339
|
+
if (completeTag?.isSelfClosing && !hasSpacedSelfClosingSlash(trimmedLine)) return null;
|
|
340
|
+
const endMarker = `</${rawTag}>`;
|
|
341
|
+
if (hasHtmlBlockEndMarker(normalizedLine, endMarker)) {
|
|
342
|
+
if (!completeTag || completeTag.isClosing) return null;
|
|
343
|
+
return { endMarker, endsAtBlankLine: false, tagName: null, depth: 0 };
|
|
344
|
+
}
|
|
345
|
+
return { endMarker, endsAtBlankLine: false, tagName: null, depth: 0 };
|
|
346
|
+
}
|
|
347
|
+
if (normalizedLine.startsWith("<!--")) {
|
|
348
|
+
return { endMarker: "-->", endsAtBlankLine: false, tagName: null, depth: 0 };
|
|
349
|
+
}
|
|
350
|
+
if (normalizedLine.startsWith("<?")) {
|
|
351
|
+
return { endMarker: "?>", endsAtBlankLine: false, tagName: null, depth: 0 };
|
|
352
|
+
}
|
|
353
|
+
if (trimmedLine.startsWith("<![CDATA[")) {
|
|
354
|
+
return { endMarker: "]]>", endsAtBlankLine: false, tagName: null, depth: 0 };
|
|
355
|
+
}
|
|
356
|
+
const declarationFirst = trimmedLine[2];
|
|
357
|
+
if (
|
|
358
|
+
trimmedLine.startsWith("<!") &&
|
|
359
|
+
declarationFirst &&
|
|
360
|
+
declarationFirst >= "A" &&
|
|
361
|
+
declarationFirst <= "Z"
|
|
362
|
+
) {
|
|
363
|
+
return { endMarker: ">", endsAtBlankLine: false, tagName: null, depth: 0 };
|
|
364
|
+
}
|
|
365
|
+
const blockTag = findHtmlBlockTag(normalizedLine, HTML_BLOCK_TAGS);
|
|
366
|
+
if (blockTag) {
|
|
367
|
+
const completeTag =
|
|
368
|
+
findCompleteHtmlTag(trimmedLine) ?? findHtmlTagPrefix(trimmedLine);
|
|
369
|
+
if (!completeTag) {
|
|
370
|
+
return { endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 };
|
|
371
|
+
}
|
|
372
|
+
if (completeTag.isSelfClosing) {
|
|
373
|
+
return { endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 };
|
|
374
|
+
}
|
|
375
|
+
return { endMarker: `</${blockTag}>`, endsAtBlankLine: true, tagName: blockTag, depth: 1 };
|
|
376
|
+
}
|
|
377
|
+
if (!allowGenericHtmlBlock) return null;
|
|
378
|
+
const genericTag = findCompleteHtmlTag(trimmedLine);
|
|
379
|
+
if (!genericTag) return null;
|
|
380
|
+
if (genericTag.isClosing || genericTag.isSelfClosing) {
|
|
381
|
+
return { endMarker: null, endsAtBlankLine: true, tagName: null, depth: 0 };
|
|
382
|
+
}
|
|
383
|
+
return { endMarker: `</${genericTag.name}>`, endsAtBlankLine: true, tagName: genericTag.name, depth: 1 };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
type ProfileLine = {
|
|
388
|
+
content: string;
|
|
389
|
+
ending: string;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
function parseProfileLines(content: string): ProfileLine[] {
|
|
393
|
+
const segments = content.split(/(\r\n|\n|\r)/);
|
|
394
|
+
const lines: ProfileLine[] = [];
|
|
395
|
+
for (let index = 0; index < segments.length; index += 2) {
|
|
396
|
+
lines.push({
|
|
397
|
+
content: segments[index] ?? "",
|
|
398
|
+
ending: segments[index + 1] ?? "",
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return lines;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function renderProfileLines(lines: ProfileLine[]): string {
|
|
405
|
+
let rendered = "";
|
|
406
|
+
for (const line of lines) {
|
|
407
|
+
rendered += line.content + line.ending;
|
|
408
|
+
}
|
|
409
|
+
return rendered;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function findFrontmatterEnd(lines: ProfileLine[]): number {
|
|
413
|
+
const firstLine = lines[0]?.content.startsWith(UTF8_BOM) ? lines[0].content.slice(1) : lines[0]?.content;
|
|
414
|
+
if (firstLine !== "---") return -1;
|
|
415
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
416
|
+
const line = lines[index]?.content.trimEnd();
|
|
417
|
+
if (line === "---" || line === "...") return index;
|
|
418
|
+
}
|
|
419
|
+
return -1;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function hasHtmlBlockEndMarker(line: string, endMarker: string): boolean {
|
|
423
|
+
return line.includes(endMarker);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function shouldCloseHtmlBlock(line: string, endMarker: string): boolean {
|
|
427
|
+
const normalizedLine = line.trimStart().toLowerCase();
|
|
428
|
+
return normalizedLine.includes(endMarker.toLowerCase());
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
function hasRawHtmlBlockEndMarker(line: string, endMarker: string): boolean {
|
|
433
|
+
return line.includes(endMarker);
|
|
434
|
+
}
|
|
435
|
+
function canStartGenericHtmlBlock(
|
|
436
|
+
lines: ProfileLine[],
|
|
437
|
+
index: number,
|
|
438
|
+
previousHtmlTerminator: boolean,
|
|
439
|
+
): boolean {
|
|
440
|
+
const previousLine = lines[index - 1]?.content.trim() ?? "";
|
|
441
|
+
if (previousLine === "") return true;
|
|
442
|
+
return (
|
|
443
|
+
isCompletedIndentedCodeBlock(lines, index) ||
|
|
444
|
+
(isMetadataBoundary(previousLine, previousHtmlTerminator) &&
|
|
445
|
+
!isLastUpdatedHeader(previousLine) &&
|
|
446
|
+
!MARKDOWN_LIST_ITEM.test(previousLine) &&
|
|
447
|
+
!MARKDOWN_BLOCK_QUOTE.test(previousLine))
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function isHtmlBlockBoundary(
|
|
452
|
+
lines: ProfileLine[],
|
|
453
|
+
index: number,
|
|
454
|
+
htmlTerminatorIndexes: ReadonlySet<number>,
|
|
455
|
+
): boolean {
|
|
456
|
+
if (htmlTerminatorIndexes.has(index)) return true;
|
|
457
|
+
const line = lines[index]?.content ?? "";
|
|
458
|
+
const parserLine = index === 0 && line.startsWith(UTF8_BOM) ? line.slice(1) : line;
|
|
459
|
+
if (isIndentedCodeLine(parserLine) || getFenceMarker(parserLine)) return false;
|
|
460
|
+
const trimmedLine = parserLine.trimStart();
|
|
461
|
+
return (
|
|
462
|
+
findHtmlBlockStart(
|
|
463
|
+
trimmedLine.toLowerCase(),
|
|
464
|
+
trimmedLine,
|
|
465
|
+
canStartGenericHtmlBlock(lines, index, htmlTerminatorIndexes.has(index - 1)),
|
|
466
|
+
) !== null
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function visitProfileMetadataLines(
|
|
471
|
+
lines: ProfileLine[],
|
|
472
|
+
visit: (line: string, index: number) => void,
|
|
473
|
+
onHtmlBlockTerminator?: (index: number) => void,
|
|
474
|
+
onFenceBlockTerminator?: (index: number) => void,
|
|
475
|
+
): void {
|
|
476
|
+
const frontmatterEnd = findFrontmatterEnd(lines);
|
|
477
|
+
const htmlTerminatorIndexes = new Set<number>();
|
|
478
|
+
const markHtmlTerminator = (index: number): void => {
|
|
479
|
+
htmlTerminatorIndexes.add(index);
|
|
480
|
+
onHtmlBlockTerminator?.(index);
|
|
481
|
+
};
|
|
482
|
+
let openFence: (FenceMarker & { listIndentation: number | null }) | null = null;
|
|
483
|
+
let openHtmlBlock: OpenHtmlBlock | null = null;
|
|
484
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
485
|
+
const line = lines[index]?.content ?? "";
|
|
486
|
+
const parserLine = index === 0 && line.startsWith(UTF8_BOM) ? line.slice(1) : line;
|
|
487
|
+
if (index <= frontmatterEnd) continue;
|
|
488
|
+
const fence = getFenceMarker(parserLine);
|
|
489
|
+
if (openFence) {
|
|
490
|
+
const indentation = parserLine.length - parserLine.trimStart().length;
|
|
491
|
+
const leavesListContainer =
|
|
492
|
+
openFence.listIndentation !== null &&
|
|
493
|
+
parserLine.trim() !== "" &&
|
|
494
|
+
indentation < openFence.listIndentation;
|
|
495
|
+
if (!leavesListContainer) {
|
|
496
|
+
if (fence && isClosingFence(fence, openFence)) openFence = null;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
openFence = null;
|
|
500
|
+
if (index > 0) onFenceBlockTerminator?.(index - 1);
|
|
501
|
+
}
|
|
502
|
+
const trimmedLine = parserLine.trimStart();
|
|
503
|
+
const normalizedLine = trimmedLine.toLowerCase();
|
|
504
|
+
if (openHtmlBlock) {
|
|
505
|
+
const indentation = parserLine.length - parserLine.trimStart().length;
|
|
506
|
+
const leavesListContainer =
|
|
507
|
+
openHtmlBlock.listIndentation !== null &&
|
|
508
|
+
parserLine.trim() !== "" &&
|
|
509
|
+
indentation < openHtmlBlock.listIndentation;
|
|
510
|
+
if (!leavesListContainer) {
|
|
511
|
+
if (openHtmlBlock.endsAtBlankLine && normalizedLine === "") {
|
|
512
|
+
openHtmlBlock = null;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (openHtmlBlock.tagName) {
|
|
516
|
+
const nextHtmlBlock = updateHtmlBlockDepth(openHtmlBlock, normalizedLine, false);
|
|
517
|
+
if (!nextHtmlBlock) markHtmlTerminator(index);
|
|
518
|
+
openHtmlBlock = nextHtmlBlock;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (openHtmlBlock.endMarker && shouldCloseHtmlBlock(normalizedLine, openHtmlBlock.endMarker)) {
|
|
522
|
+
openHtmlBlock = null;
|
|
523
|
+
markHtmlTerminator(index);
|
|
524
|
+
}
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
openHtmlBlock = null;
|
|
528
|
+
if (index > 0) markHtmlTerminator(index - 1);
|
|
529
|
+
}
|
|
530
|
+
if (isIndentedCodeLine(parserLine)) continue;
|
|
531
|
+
if (fence) {
|
|
532
|
+
openFence = {
|
|
533
|
+
...fence,
|
|
534
|
+
listIndentation: isNestedListContent(lines, index, fence.indentation)
|
|
535
|
+
? fence.indentation
|
|
536
|
+
: null,
|
|
537
|
+
};
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
const htmlBlock = findHtmlBlockStart(
|
|
541
|
+
normalizedLine,
|
|
542
|
+
trimmedLine,
|
|
543
|
+
canStartGenericHtmlBlock(lines, index, htmlTerminatorIndexes.has(index - 1)),
|
|
544
|
+
);
|
|
545
|
+
if (htmlBlock) {
|
|
546
|
+
markHtmlTerminator(index);
|
|
547
|
+
const indentation = parserLine.length - parserLine.trimStart().length;
|
|
548
|
+
const htmlBlockWithContainer = {
|
|
549
|
+
...htmlBlock,
|
|
550
|
+
listIndentation: isNestedListContent(lines, index, indentation) ? indentation : null,
|
|
551
|
+
};
|
|
552
|
+
if (htmlBlock.tagName) {
|
|
553
|
+
openHtmlBlock = updateHtmlBlockDepth(htmlBlockWithContainer, normalizedLine, true);
|
|
554
|
+
if (!openHtmlBlock) markHtmlTerminator(index);
|
|
555
|
+
} else if (htmlBlock.endMarker && shouldCloseHtmlBlock(normalizedLine, htmlBlock.endMarker)) {
|
|
556
|
+
openHtmlBlock = null;
|
|
557
|
+
markHtmlTerminator(index);
|
|
558
|
+
} else {
|
|
559
|
+
openHtmlBlock = htmlBlockWithContainer;
|
|
560
|
+
}
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
visit(line, index);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function isCompletedIndentedCodeBlock(lines: ProfileLine[], index: number): boolean {
|
|
568
|
+
if (!isIndentedCodeLine(lines[index - 1]?.content ?? "")) return false;
|
|
569
|
+
let sawBlank = false;
|
|
570
|
+
for (let previousIndex = index - 2; previousIndex >= 0; previousIndex -= 1) {
|
|
571
|
+
const previousLine = lines[previousIndex]?.content ?? "";
|
|
572
|
+
if (previousLine.trim() === "") {
|
|
573
|
+
sawBlank = true;
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
if (isIndentedCodeLine(previousLine)) continue;
|
|
577
|
+
return sawBlank;
|
|
578
|
+
}
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function isListContinuation(lines: ProfileLine[], index: number, indentation: number): boolean {
|
|
583
|
+
for (let previousIndex = index - 1; previousIndex >= 0; previousIndex -= 1) {
|
|
584
|
+
const previousLine = lines[previousIndex]?.content ?? "";
|
|
585
|
+
if (previousLine.trim() === "") return false;
|
|
586
|
+
const previousIndentation = previousLine.length - previousLine.trimStart().length;
|
|
587
|
+
if (previousIndentation > indentation) continue;
|
|
588
|
+
const previousBoundaryLine = previousLine.trimStart();
|
|
589
|
+
if (MARKDOWN_LIST_ITEM.test(previousBoundaryLine)) return true;
|
|
590
|
+
if (
|
|
591
|
+
MARKDOWN_HEADING.test(previousBoundaryLine) ||
|
|
592
|
+
MARKDOWN_THEMATIC_BREAK.test(previousBoundaryLine) ||
|
|
593
|
+
MARKDOWN_BLOCK_QUOTE.test(previousBoundaryLine) ||
|
|
594
|
+
getFenceMarker(previousLine) !== null
|
|
595
|
+
) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function isNestedListContent(lines: ProfileLine[], index: number, indentation: number): boolean {
|
|
603
|
+
for (let previousIndex = index - 1; previousIndex >= 0; previousIndex -= 1) {
|
|
604
|
+
const previousLine = lines[previousIndex]?.content ?? "";
|
|
605
|
+
if (previousLine.trim() === "") continue;
|
|
606
|
+
const previousIndentation = previousLine.length - previousLine.trimStart().length;
|
|
607
|
+
if (previousIndentation >= indentation) continue;
|
|
608
|
+
if (
|
|
609
|
+
MARKDOWN_LIST_ITEM.test(previousLine.trimStart()) ||
|
|
610
|
+
isListContinuation(lines, previousIndex, indentation)
|
|
611
|
+
) {
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function isValidBareLinkDestination(destination: string): boolean {
|
|
620
|
+
let parentheses = 0;
|
|
621
|
+
for (let index = 0; index < destination.length; index += 1) {
|
|
622
|
+
const character = destination[index];
|
|
623
|
+
if (character === "\\") {
|
|
624
|
+
if (index + 1 >= destination.length) return false;
|
|
625
|
+
index += 1;
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
if (character === "<" || character === ">") return false;
|
|
629
|
+
if (character === "(") {
|
|
630
|
+
parentheses += 1;
|
|
631
|
+
} else if (character === ")") {
|
|
632
|
+
if (parentheses === 0) return false;
|
|
633
|
+
parentheses -= 1;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return parentheses === 0;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function isMarkdownLinkReferenceDefinition(line: string): boolean {
|
|
640
|
+
const match = MARKDOWN_LINK_REFERENCE.exec(line);
|
|
641
|
+
return match !== null && (match[1] === undefined || isValidBareLinkDestination(match[1]));
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function isMarkdownLinkReferenceDefinitionEnd(lines: ProfileLine[], index: number): boolean {
|
|
645
|
+
const line = lines[index]?.content ?? "";
|
|
646
|
+
const boundaryLine = /^ {0,3}(?=\S)/.test(line) ? line.trimStart() : line;
|
|
647
|
+
if (isMarkdownLinkReferenceDefinition(boundaryLine)) return true;
|
|
648
|
+
if (MARKDOWN_LINK_REFERENCE_CONTINUATION.test(line)) {
|
|
649
|
+
const previousLine = lines[index - 1]?.content ?? "";
|
|
650
|
+
const previousBoundaryLine =
|
|
651
|
+
/^ {0,3}(?=\S)/.test(previousLine) ? previousLine.trimStart() : previousLine;
|
|
652
|
+
if (isMarkdownLinkReferenceDefinition(previousBoundaryLine)) return true;
|
|
653
|
+
const destinationLine = lines[index - 1]?.content ?? "";
|
|
654
|
+
if (!MARKDOWN_LINK_REFERENCE_DESTINATION_CONTINUATION.test(destinationLine)) return false;
|
|
655
|
+
const labelLine = lines[index - 2]?.content ?? "";
|
|
656
|
+
const labelBoundaryLine =
|
|
657
|
+
/^ {0,3}(?=\S)/.test(labelLine) ? labelLine.trimStart() : labelLine;
|
|
658
|
+
return MARKDOWN_LINK_REFERENCE_LABEL.test(labelBoundaryLine);
|
|
659
|
+
}
|
|
660
|
+
if (!MARKDOWN_LINK_REFERENCE_DESTINATION_CONTINUATION.test(line)) return false;
|
|
661
|
+
const previousLine = lines[index - 1]?.content ?? "";
|
|
662
|
+
const previousBoundaryLine =
|
|
663
|
+
/^ {0,3}(?=\S)/.test(previousLine) ? previousLine.trimStart() : previousLine;
|
|
664
|
+
return MARKDOWN_LINK_REFERENCE_LABEL.test(previousBoundaryLine);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function isProfileTitleLine(lines: ProfileLine[], index: number, line: string): boolean {
|
|
668
|
+
const titleLine = index === 0 && line.startsWith(UTF8_BOM) ? line.slice(1) : line;
|
|
669
|
+
if (!PROFILE_TITLE.test(titleLine)) return false;
|
|
670
|
+
const indentation = titleLine.length - titleLine.trimStart().length;
|
|
671
|
+
if (indentation === 0 || index === 0) return true;
|
|
672
|
+
const previousLine = lines[index - 1]?.content.trim() ?? "";
|
|
673
|
+
return previousLine === ""
|
|
674
|
+
? !isNestedListContent(lines, index, indentation)
|
|
675
|
+
: previousLine === "---" || previousLine === "...";
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function findProfileTitleIndex(lines: ProfileLine[]): number {
|
|
679
|
+
let titleIndex = -1;
|
|
680
|
+
visitProfileMetadataLines(lines, (line, index) => {
|
|
681
|
+
if (titleIndex >= 0) return;
|
|
682
|
+
if (isProfileTitleLine(lines, index, line)) titleIndex = index;
|
|
683
|
+
});
|
|
684
|
+
return titleIndex;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function isSetextHeadingText(line: string): boolean {
|
|
688
|
+
const withoutBom = line.startsWith(UTF8_BOM) ? line.slice(1) : line;
|
|
689
|
+
const boundaryLine = withoutBom.trim();
|
|
690
|
+
return (
|
|
691
|
+
boundaryLine !== "" &&
|
|
692
|
+
!MARKDOWN_HEADING.test(boundaryLine) &&
|
|
693
|
+
!MARKDOWN_LIST_ITEM.test(boundaryLine) &&
|
|
694
|
+
!MARKDOWN_BLOCK_QUOTE.test(boundaryLine) &&
|
|
695
|
+
!MARKDOWN_THEMATIC_BREAK.test(boundaryLine) &&
|
|
696
|
+
!isMarkdownLinkReferenceDefinition(boundaryLine) &&
|
|
697
|
+
getFenceMarker(withoutBom) === null
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function isMetadataBoundary(
|
|
702
|
+
line: string,
|
|
703
|
+
htmlTerminator = false,
|
|
704
|
+
allowSetext = true,
|
|
705
|
+
allowParagraphListInterrupt = false,
|
|
706
|
+
setextPreviousLine = "",
|
|
707
|
+
): boolean {
|
|
708
|
+
const listPattern = allowParagraphListInterrupt
|
|
709
|
+
? MARKDOWN_LIST_ITEM_CAN_INTERRUPT
|
|
710
|
+
: MARKDOWN_LIST_ITEM;
|
|
711
|
+
const boundaryLine = /^ {0,3}(?=\S)/.test(line) ? line.trimStart() : line;
|
|
712
|
+
const isSetextUnderline =
|
|
713
|
+
!allowSetext &&
|
|
714
|
+
MARKDOWN_SETEXT_UNDERLINE.test(boundaryLine) &&
|
|
715
|
+
isSetextHeadingText(setextPreviousLine);
|
|
716
|
+
return (
|
|
717
|
+
line.trim() === "" ||
|
|
718
|
+
MARKDOWN_HEADING.test(boundaryLine) ||
|
|
719
|
+
listPattern.test(boundaryLine) ||
|
|
720
|
+
(allowSetext && MARKDOWN_SETEXT_UNDERLINE.test(boundaryLine)) ||
|
|
721
|
+
(MARKDOWN_THEMATIC_BREAK.test(boundaryLine) && !isSetextUnderline) ||
|
|
722
|
+
MARKDOWN_BLOCK_QUOTE.test(boundaryLine) ||
|
|
723
|
+
isMarkdownLinkReferenceDefinition(boundaryLine) ||
|
|
724
|
+
isLastUpdatedHeader(line) ||
|
|
725
|
+
getFenceMarker(line) !== null ||
|
|
726
|
+
htmlTerminator
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function isStandaloneMetadataLine(
|
|
731
|
+
lines: ProfileLine[],
|
|
732
|
+
index: number,
|
|
733
|
+
frontmatterEnd: number,
|
|
734
|
+
htmlTerminatorIndexes: ReadonlySet<number>,
|
|
735
|
+
fenceTerminatorIndexes: ReadonlySet<number>,
|
|
736
|
+
standaloneHeaderIndexes: ReadonlySet<number>,
|
|
737
|
+
): boolean {
|
|
738
|
+
const currentLine = lines[index]?.content ?? "";
|
|
739
|
+
const currentWithoutBom = currentLine.startsWith(UTF8_BOM)
|
|
740
|
+
? currentLine.slice(1)
|
|
741
|
+
: currentLine;
|
|
742
|
+
const indentation = currentWithoutBom.length - currentWithoutBom.trimStart().length;
|
|
743
|
+
const previousLine = lines[index - 1]?.content.trimEnd() ?? "";
|
|
744
|
+
const nextLine = lines[index + 1]?.content.trimEnd() ?? "";
|
|
745
|
+
const previousWithoutBom = previousLine.startsWith(UTF8_BOM)
|
|
746
|
+
? previousLine.slice(1)
|
|
747
|
+
: previousLine;
|
|
748
|
+
const nextWithoutBom = nextLine.startsWith(UTF8_BOM) ? nextLine.slice(1) : nextLine;
|
|
749
|
+
const previousLinkReferenceBoundary = isMarkdownLinkReferenceDefinitionEnd(lines, index - 1);
|
|
750
|
+
const previousMetadataBoundary =
|
|
751
|
+
isCompletedIndentedCodeBlock(lines, index) ||
|
|
752
|
+
previousLinkReferenceBoundary ||
|
|
753
|
+
fenceTerminatorIndexes.has(index - 1) ||
|
|
754
|
+
(isMetadataBoundary(
|
|
755
|
+
previousWithoutBom,
|
|
756
|
+
htmlTerminatorIndexes.has(index - 1),
|
|
757
|
+
) &&
|
|
758
|
+
(!isLastUpdatedHeader(previousWithoutBom) || standaloneHeaderIndexes.has(index - 1)));
|
|
759
|
+
const nextHtmlBlockBoundary = isHtmlBlockBoundary(
|
|
760
|
+
lines,
|
|
761
|
+
index + 1,
|
|
762
|
+
htmlTerminatorIndexes,
|
|
763
|
+
);
|
|
764
|
+
const nextMetadataBoundary =
|
|
765
|
+
nextHtmlBlockBoundary ||
|
|
766
|
+
isMetadataBoundary(
|
|
767
|
+
nextWithoutBom,
|
|
768
|
+
htmlTerminatorIndexes.has(index + 1),
|
|
769
|
+
false,
|
|
770
|
+
true,
|
|
771
|
+
currentWithoutBom,
|
|
772
|
+
);
|
|
773
|
+
const previousContainerMarker =
|
|
774
|
+
!MARKDOWN_THEMATIC_BREAK.test(previousWithoutBom) &&
|
|
775
|
+
(MARKDOWN_LIST_ITEM.test(previousWithoutBom) || MARKDOWN_BLOCK_QUOTE.test(previousWithoutBom));
|
|
776
|
+
const nestedListContent =
|
|
777
|
+
indentation > 0 && isNestedListContent(lines, index, indentation);
|
|
778
|
+
const startsBlock =
|
|
779
|
+
(index === 0 || index === frontmatterEnd + 1 || previousMetadataBoundary) &&
|
|
780
|
+
!previousContainerMarker &&
|
|
781
|
+
!nestedListContent;
|
|
782
|
+
const endsBlock = index === lines.length - 1 || nextMetadataBoundary;
|
|
783
|
+
const compactHeaderAfterTitle = isProfileTitleLine(lines, index - 1, previousWithoutBom);
|
|
784
|
+
const compactHeaderAfterHeader =
|
|
785
|
+
isLastUpdatedHeader(previousWithoutBom) && standaloneHeaderIndexes.has(index - 1);
|
|
786
|
+
return startsBlock && (endsBlock || compactHeaderAfterTitle || compactHeaderAfterHeader);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function findProfileHeaderIndexes(lines: ProfileLine[]): number[] {
|
|
790
|
+
const indexes: number[] = [];
|
|
791
|
+
const frontmatterEnd = findFrontmatterEnd(lines);
|
|
792
|
+
const htmlTerminatorIndexes = new Set<number>();
|
|
793
|
+
const fenceTerminatorIndexes = new Set<number>();
|
|
794
|
+
const standaloneHeaderIndexes = new Set<number>();
|
|
795
|
+
visitProfileMetadataLines(
|
|
796
|
+
lines,
|
|
797
|
+
(line, index) => {
|
|
798
|
+
if (
|
|
799
|
+
isLastUpdatedHeader(line) &&
|
|
800
|
+
isStandaloneMetadataLine(
|
|
801
|
+
lines,
|
|
802
|
+
index,
|
|
803
|
+
frontmatterEnd,
|
|
804
|
+
htmlTerminatorIndexes,
|
|
805
|
+
fenceTerminatorIndexes,
|
|
806
|
+
standaloneHeaderIndexes,
|
|
807
|
+
)
|
|
808
|
+
) {
|
|
809
|
+
indexes.push(index);
|
|
810
|
+
standaloneHeaderIndexes.add(index);
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
(index) => htmlTerminatorIndexes.add(index),
|
|
814
|
+
(index) => fenceTerminatorIndexes.add(index),
|
|
815
|
+
);
|
|
816
|
+
return indexes;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function insertHeaderAfter(lines: ProfileLine[], index: number, header: string): void {
|
|
820
|
+
const insertAt = index + 1;
|
|
821
|
+
const ending = lines[index]?.ending || lines[insertAt]?.ending || "\n";
|
|
822
|
+
if (lines[insertAt]?.content.trim() === "") {
|
|
823
|
+
lines.splice(
|
|
824
|
+
insertAt + 1,
|
|
825
|
+
0,
|
|
826
|
+
{ content: header, ending },
|
|
827
|
+
{ content: "", ending },
|
|
828
|
+
);
|
|
829
|
+
} else {
|
|
830
|
+
lines.splice(
|
|
831
|
+
insertAt,
|
|
832
|
+
0,
|
|
833
|
+
{ content: "", ending },
|
|
834
|
+
{ content: header, ending },
|
|
835
|
+
{ content: "", ending },
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function prependHeader(lines: ProfileLine[], header: string): string {
|
|
841
|
+
const frontmatterEnd = findFrontmatterEnd(lines);
|
|
842
|
+
if (frontmatterEnd >= 0) {
|
|
843
|
+
insertHeaderAfter(lines, frontmatterEnd, header);
|
|
844
|
+
return renderProfileLines(lines);
|
|
845
|
+
}
|
|
846
|
+
const ending = lines[0]?.ending || "\n";
|
|
847
|
+
if (lines[0]?.content.startsWith(UTF8_BOM)) {
|
|
848
|
+
lines[0].content = lines[0].content.slice(1);
|
|
849
|
+
lines.unshift(
|
|
850
|
+
{ content: `${UTF8_BOM}${header}`, ending },
|
|
851
|
+
{ content: "", ending },
|
|
852
|
+
);
|
|
853
|
+
return renderProfileLines(lines);
|
|
854
|
+
}
|
|
855
|
+
lines.unshift(
|
|
856
|
+
{ content: header, ending },
|
|
857
|
+
{ content: "", ending },
|
|
858
|
+
);
|
|
859
|
+
return renderProfileLines(lines);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
export function renderProfileWithLastUpdated(content: string, updatedAt: string): string {
|
|
863
|
+
const lines = parseProfileLines(content);
|
|
864
|
+
const header = `*Last updated: ${updatedAt}*`;
|
|
865
|
+
const titleIndex = findProfileTitleIndex(lines);
|
|
866
|
+
const headerIndexes = findProfileHeaderIndexes(lines);
|
|
867
|
+
|
|
868
|
+
if (headerIndexes.length > 0) {
|
|
869
|
+
const firstHeaderIndex = headerIndexes[0];
|
|
870
|
+
if (firstHeaderIndex === undefined) return renderProfileLines(lines);
|
|
871
|
+
const canonicalIndex =
|
|
872
|
+
titleIndex >= 0
|
|
873
|
+
? headerIndexes.find((index) => index > titleIndex) ?? firstHeaderIndex
|
|
874
|
+
: firstHeaderIndex;
|
|
875
|
+
const preserveBomAtFileStart = headerIndexes.some((index) =>
|
|
876
|
+
lines[index].content.startsWith(UTF8_BOM),
|
|
877
|
+
);
|
|
878
|
+
const bomPrefix =
|
|
879
|
+
canonicalIndex === 0 && lines[canonicalIndex].content.startsWith(UTF8_BOM)
|
|
880
|
+
? UTF8_BOM
|
|
881
|
+
: "";
|
|
882
|
+
lines[canonicalIndex].content = `${bomPrefix}${header}`;
|
|
883
|
+
for (let index = headerIndexes.length - 1; index >= 0; index -= 1) {
|
|
884
|
+
const headerIndex = headerIndexes[index];
|
|
885
|
+
if (headerIndex === undefined || headerIndex === canonicalIndex) continue;
|
|
886
|
+
lines.splice(headerIndex, 1);
|
|
887
|
+
}
|
|
888
|
+
if (preserveBomAtFileStart && !lines[0].content.startsWith(UTF8_BOM)) {
|
|
889
|
+
lines[0].content = `${UTF8_BOM}${lines[0].content}`;
|
|
890
|
+
}
|
|
891
|
+
return renderProfileLines(lines);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
if (titleIndex < 0) return prependHeader(lines, header);
|
|
895
|
+
|
|
896
|
+
insertHeaderAfter(lines, titleIndex, header);
|
|
897
|
+
return renderProfileLines(lines);
|
|
898
|
+
}
|