dsh-builtin-browser 1.0.3 → 1.1.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/CHANGELOG.md +16 -1
- package/README.en.md +89 -0
- package/browser-extension/constants.mjs +20 -0
- package/browser-extension/controller.mjs +293 -0
- package/browser-extension/locales.mjs +15 -0
- package/browser-extension/manifest.json +12 -0
- package/browser-extension/options.html +14 -0
- package/browser-extension/options.mjs +9 -0
- package/browser-extension/permission-guard.mjs +13 -0
- package/browser-extension/worker.mjs +74 -0
- package/desktop-bridge/desktop-identity.json +10 -2
- package/desktop-bridge/install.mjs +28 -2
- package/docs/issue-replies-2026-11-28.md +141 -0
- package/dsh-host-patch/apply.mjs +1 -1
- package/dsh-host-patch/rc3.json +4 -4
- package/dsh-host-patch/rc5.json +4 -4
- package/dsh-host-patch/v023-alpha2.json +2 -2
- package/lib/browser-electron/bridge-status.js +24 -1
- package/lib/browser-electron/desktop-identity.js +47 -8
- package/lib/client.js +2 -1
- package/native-host/install.mjs +5 -0
- package/package.json +20 -2
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +69 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +40 -0
- package/scripts/install-electron.mjs +101 -0
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +58 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +98 -0
- package/skills/dsh-builtin-browser/references/batch.md +68 -0
- package/skills/dsh-builtin-browser/references/deliver.md +31 -0
- package/skills/dsh-builtin-browser/references/locate.md +11 -0
- package/skills/dsh-builtin-browser/references/recover.md +11 -0
- package/skills/dsh-builtin-browser/references/verify.md +13 -0
- package/skills/dsh-debug-host/SKILL.md +56 -0
- package/skills/dsh-debug-self/SKILL.md +50 -0
- package/src/bridge-compatibility.ts +39 -0
- package/src/browser/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +578 -0
- package/src/browser/takeover-target.ts +45 -0
- package/src/browser/types.ts +870 -0
- package/src/browser-electron/authenticated-route.ts +109 -0
- package/src/browser-electron/automatic-maintenance.ts +736 -0
- package/src/browser-electron/bridge-auto.ts +159 -0
- package/src/browser-electron/bridge-connection.ts +386 -0
- package/src/browser-electron/bridge-endpoint.ts +129 -0
- package/src/browser-electron/bridge-install.ts +290 -0
- package/src/browser-electron/bridge-maintenance.ts +189 -0
- package/src/browser-electron/bridge-status.ts +412 -0
- package/src/browser-electron/desktop-bridge-host.ts +253 -0
- package/src/browser-electron/desktop-identity.ts +400 -0
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +347 -0
- package/src/browser-electron/entry.ts +1378 -0
- package/src/browser-electron/ephemeral-profile.ts +189 -0
- package/src/browser-electron/extension-browser.ts +230 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/file-write.ts +31 -0
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +177 -0
- package/src/browser-electron/guest-cookie-store.ts +59 -0
- package/src/browser-electron/guest-css-runtime.ts +76 -0
- package/src/browser-electron/guest-css.ts +68 -0
- package/src/browser-electron/guest-route.ts +716 -0
- package/src/browser-electron/guest-runtime.ts +408 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +120 -0
- package/src/browser-electron/history-store.ts +224 -0
- package/src/browser-electron/host-main.ts +1385 -0
- package/src/browser-electron/host-patch-maintenance.ts +121 -0
- package/src/browser-electron/http-body.ts +65 -0
- package/src/browser-electron/json-reply.ts +47 -0
- package/src/browser-electron/maintenance-broker.ts +166 -0
- package/src/browser-electron/maintenance-lifecycle.ts +91 -0
- package/src/browser-electron/maintenance-route.ts +68 -0
- package/src/browser-electron/missing-system-browser.ts +114 -0
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +25 -0
- package/src/browser-electron/preferred-browser.ts +130 -0
- package/src/browser-electron/preview-route.ts +215 -0
- package/src/browser-electron/process-ownership.ts +174 -0
- package/src/browser-electron/process.ts +23 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +47 -0
- package/src/browser-electron/profile-extension.ts +129 -0
- package/src/browser-electron/profile-lease.ts +211 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider-core.ts +1107 -0
- package/src/browser-electron/provider-interaction.ts +1034 -0
- package/src/browser-electron/provider-media.ts +589 -0
- package/src/browser-electron/provider-navigation.ts +323 -0
- package/src/browser-electron/provider-observation.ts +664 -0
- package/src/browser-electron/provider-tabs.ts +372 -0
- package/src/browser-electron/provider.ts +666 -0
- package/src/browser-electron/reference-route.ts +598 -0
- package/src/browser-electron/remote-host.ts +1538 -0
- package/src/browser-electron/rpc-input.ts +13 -0
- package/src/browser-electron/rpc-ops.ts +41 -0
- package/src/browser-electron/runtime-diagnostics.ts +38 -0
- package/src/browser-electron/runtime-route.ts +105 -0
- package/src/browser-electron/runtime-status.ts +309 -0
- package/src/browser-electron/settings-route.ts +64 -0
- package/src/browser-electron/settings-store.ts +593 -0
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +300 -0
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +1850 -0
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/timing.ts +16 -0
- package/src/browser-electron/virtual-cursor.ts +162 -0
- package/src/browser-electron/windows-system.ts +24 -0
- package/src/browser-reference/delivery.ts +384 -0
- package/src/browser-reference/entry.ts +631 -0
- package/src/browser-reference/export.ts +339 -0
- package/src/browser-reference/import.ts +303 -0
- package/src/browser-reference/page-script.ts +1537 -0
- package/src/browser-reference/service.ts +1346 -0
- package/src/browser-reference/store.ts +172 -0
- package/src/browser-reference/text-quote.ts +219 -0
- package/src/browser-reference/types.ts +195 -0
- package/src/browser-reference/visible.ts +367 -0
- package/src/browser-reference/web-sources.ts +106 -0
- package/src/client/apply-guard.ts +22 -0
- package/src/client/browser/BrowserController.ts +693 -0
- package/src/client/browser/BrowserFrame.ts +78 -0
- package/src/client/browser/BrowserNavigation.ts +169 -0
- package/src/client/browser/BrowserPage.ts +23 -0
- package/src/client/browser/BrowserPersistence.ts +44 -0
- package/src/client/browser/IframeImpl.ts +182 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -0
- package/src/client/browser/iframe-reference.ts +67 -0
- package/src/client/browser/initialization.ts +262 -0
- package/src/client/browser/omnibox.ts +243 -0
- package/src/client/browser/store.ts +38 -0
- package/src/client/browser/takeover-channel.ts +72 -0
- package/src/client/browser/url.ts +46 -0
- package/src/client/browser/web-reference-source.ts +56 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +36 -0
- package/src/client/electron/ElectronWebViewImpl.ts +371 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
- package/src/client/electron/NativeChildPresentation.ts +53 -0
- package/src/client/electron/NativeViewPage.ts +265 -0
- package/src/client/electron/pages.ts +23 -0
- package/src/client/electron/reference-overlay.ts +53 -0
- package/src/client/electron/workspace.ts +33 -0
- package/src/client/index.ts +333 -0
- package/src/client/locales.ts +860 -0
- package/src/client/pages.ts +28 -0
- package/src/client/reference/client/BrowserRefLink.tsx +142 -0
- package/src/client/reference/client/draft-reference.ts +167 -0
- package/src/client/reference/client/index.ts +7 -0
- package/src/client/reference/client/ordered-submission.ts +108 -0
- package/src/client/reference/client/pending-delivery.ts +216 -0
- package/src/client/reference/client/plugin.ts +208 -0
- package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
- package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
- package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
- package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
- package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
- package/src/client/reference/client/production/ReferenceText.tsx +36 -0
- package/src/client/reference/client/production/assembly.ts +447 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +72 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +512 -0
- package/src/client/reference/client/production/http-transport.ts +212 -0
- package/src/client/reference/client/production/production-submission.ts +70 -0
- package/src/client/reference/client/production/protocol.ts +234 -0
- package/src/client/reference/client/production/reference-card.ts +240 -0
- package/src/client/reference/client/production/reference-labels.ts +29 -0
- package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
- package/src/client/reference/client/production/reveal.ts +215 -0
- package/src/client/reference/client/production/runtime.ts +1056 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +99 -0
- package/src/client/reference/client/production/source-opener.ts +55 -0
- package/src/client/reference/client/production/styles.ts +104 -0
- package/src/client/reference/client/production/user-text-rule.ts +67 -0
- package/src/client/reference/client/reveal.ts +109 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/session-schedule.ts +36 -0
- package/src/client/reference/client/types.ts +168 -0
- package/src/client/reference/css-modules.d.ts +4 -0
- package/src/client/reference/index.ts +11 -0
- package/src/client/reference-capture-owner.ts +162 -0
- package/src/client/reference-intents.ts +36 -0
- package/src/client/settings/index.ts +42 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +2773 -0
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +300 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +315 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +365 -0
- package/src/client/view/StartPage.tsx +598 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/compat/host-features.ts +92 -0
- package/src/index.ts +110 -0
- package/src/reference-owner.ts +5 -0
- package/src/reference-page.ts +9 -0
- package/src/reference-source.ts +3 -0
- package/src/reference-text.ts +219 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +28 -0
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +555 -0
- package/src/tool-browser/code-worker.ts +725 -0
- package/src/tool-browser/element-fields.ts +167 -0
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +265 -0
- package/src/tool-browser/page-probe.ts +675 -0
- package/src/tool-browser/panel-page.ts +126 -0
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +199 -0
- package/src/tool-browser/tools-debug.ts +806 -0
- package/src/tool-browser/tools-interaction.ts +956 -0
- package/src/tool-browser/tools-navigation.ts +786 -0
- package/src/tool-browser/tools-observation.ts +474 -0
- package/src/tool-browser/tools-reference.ts +294 -0
- package/src/types/electron-shim.d.ts +144 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +35 -0
- package/tools/accept-desktop.mjs +148 -0
- package/dist/client.d.cts +0 -516
- package/dist/client.d.mts +0 -516
- package/dist/index.cjs +0 -92
- package/dist/index.d.mts +0 -2960
- package/dist/index.mjs +0 -24
- package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -0
- package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +0 -218
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +0 -260
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
|
|
2
|
+
/**
|
|
3
|
+
* Persistent browsing history: which pages the shared browser actually visited,
|
|
4
|
+
* kept independently from any session's operation log (`dsh_browser_history`) and
|
|
5
|
+
* from the browser process's lifetime.
|
|
6
|
+
*
|
|
7
|
+
* It lives beside the browser profile (`$DSH_HOME/dsh-builtin-browser-host/
|
|
8
|
+
* history.jsonl`), so it follows the same persistence rules as the login state:
|
|
9
|
+
* closing the interface releases the process, never the record.
|
|
10
|
+
*
|
|
11
|
+
* Format: one JSON object per line, append-only. Appending stays cheap for a
|
|
12
|
+
* long session, and a half-written tail (crash, power loss) is dropped on read
|
|
13
|
+
* instead of poisoning the whole file.
|
|
14
|
+
* @module dsh-browser/browser-electron/history-store
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
18
|
+
import { dirname, join } from 'node:path'
|
|
19
|
+
import { dshHome } from './paths.ts'
|
|
20
|
+
import type { VisitedPage } from '../browser/types.ts'
|
|
21
|
+
import { writeFileAtomic } from './settings-store.ts'
|
|
22
|
+
|
|
23
|
+
export type { VisitedPage }
|
|
24
|
+
|
|
25
|
+
/** Retention limits; whichever is hit first starts trimming. */
|
|
26
|
+
export interface HistoryLimits {
|
|
27
|
+
/** Maximum retained entries. Default 5000. */
|
|
28
|
+
readonly maxEntries?: number
|
|
29
|
+
/** Maximum age in days. Default 90. */
|
|
30
|
+
readonly maxAgeDays?: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Default entry cap — mirrors the documented retention rule. */
|
|
34
|
+
const DEFAULT_MAX_ENTRIES = 5_000
|
|
35
|
+
/** Default age cap in days. */
|
|
36
|
+
const DEFAULT_MAX_AGE_DAYS = 90
|
|
37
|
+
/** Rewrite the file only once it has grown this far past the cap. */
|
|
38
|
+
const PRUNE_SLACK = 500
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Absolute path of the browsing-history file, beside the browser profile so the
|
|
42
|
+
* record shares the login state's persistence rules.
|
|
43
|
+
* @returns the history file path.
|
|
44
|
+
*/
|
|
45
|
+
export function visitedHistoryPath(): string {
|
|
46
|
+
const home = dshHome()
|
|
47
|
+
return join(home, BROWSER_PROFILE_DIR, 'history.jsonl')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Append-only browsing history with bounded retention. Every method tolerates a
|
|
52
|
+
* missing or damaged file: recording a visit must never fail a navigation, and
|
|
53
|
+
* a corrupted line must never hide the rest of the history.
|
|
54
|
+
*/
|
|
55
|
+
export class HistoryStore {
|
|
56
|
+
/** Entry count at which another batched rewrite is due. */
|
|
57
|
+
private pruneThreshold: number
|
|
58
|
+
/** Number of entries at the last full read, unknown until the first prune. */
|
|
59
|
+
private knownEntries: number | undefined
|
|
60
|
+
/** Successful appends since the last full read. */
|
|
61
|
+
private appendedSincePrune = 0
|
|
62
|
+
/** Earliest retained visit's expiry; time can require a prune without any new visit. */
|
|
63
|
+
private nextExpiryAt = Infinity
|
|
64
|
+
/** Changing retention invalidates both the count and the age calculation. */
|
|
65
|
+
private limitsChanged = false
|
|
66
|
+
private maxEntries: number
|
|
67
|
+
private maxAgeMs: number
|
|
68
|
+
private readonly file: string
|
|
69
|
+
constructor(
|
|
70
|
+
file: string = visitedHistoryPath(),
|
|
71
|
+
limits: HistoryLimits = {},
|
|
72
|
+
) {
|
|
73
|
+
this.file = file
|
|
74
|
+
this.maxEntries = limits.maxEntries ?? DEFAULT_MAX_ENTRIES
|
|
75
|
+
this.maxAgeMs = (limits.maxAgeDays ?? DEFAULT_MAX_AGE_DAYS) * 24 * 60 * 60 * 1000
|
|
76
|
+
// The first rewrite is due once the file has grown the slack past the cap.
|
|
77
|
+
this.pruneThreshold = this.maxEntries + this.slack()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Re-read the retention limits.
|
|
82
|
+
*
|
|
83
|
+
* They are settings, and settings change while the plugin runs — a panel that let the
|
|
84
|
+
* operator edit them while nothing read the new values made the control a lie. Entry count
|
|
85
|
+
* and age are the pair the interface presents, so they are updated together.
|
|
86
|
+
* @param limits - the current retention overrides.
|
|
87
|
+
*/
|
|
88
|
+
updateLimits(limits: HistoryLimits): void {
|
|
89
|
+
const maxEntries = limits.maxEntries ?? DEFAULT_MAX_ENTRIES
|
|
90
|
+
const maxAgeMs = (limits.maxAgeDays ?? DEFAULT_MAX_AGE_DAYS) * 24 * 60 * 60 * 1000
|
|
91
|
+
if (maxEntries === this.maxEntries && maxAgeMs === this.maxAgeMs) return
|
|
92
|
+
this.maxEntries = maxEntries
|
|
93
|
+
this.maxAgeMs = maxAgeMs
|
|
94
|
+
this.pruneThreshold = this.maxEntries + this.slack()
|
|
95
|
+
this.limitsChanged = true
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Whether the history file exists yet (diagnostics and tests). */
|
|
99
|
+
exists(): boolean {
|
|
100
|
+
return existsSync(this.file)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Record one visit. Failures are swallowed by design: history is a
|
|
105
|
+
* convenience, and losing an entry must never break the tool call that
|
|
106
|
+
* produced it.
|
|
107
|
+
* @param page - the visited page.
|
|
108
|
+
*/
|
|
109
|
+
append(page: VisitedPage): void {
|
|
110
|
+
try {
|
|
111
|
+
mkdirSync(dirname(this.file), { recursive: true })
|
|
112
|
+
appendFileSync(this.file, `${JSON.stringify(page)}\n`)
|
|
113
|
+
this.appendedSincePrune++
|
|
114
|
+
this.nextExpiryAt = Math.min(this.nextExpiryAt, page.at + this.maxAgeMs + 1)
|
|
115
|
+
} catch {
|
|
116
|
+
// Best-effort: history is not worth failing a navigation over.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Read visits, newest first. Unparseable lines are skipped; entries older
|
|
122
|
+
* than the age limit are filtered out but left on disk until the next prune.
|
|
123
|
+
* @param options - optional result cap plus three filters: `domain` (hostname),
|
|
124
|
+
* `query` (substring of the URL or title) and `session` (the task that visited
|
|
125
|
+
* it). Filters compose, so "the pages THIS task opened on that host" is one call.
|
|
126
|
+
* @returns the matching visits, newest first.
|
|
127
|
+
*/
|
|
128
|
+
list(options: { readonly limit?: number; readonly domain?: string; readonly query?: string; readonly session?: string } = {}): VisitedPage[] {
|
|
129
|
+
// The on-disk count may include the small batch slack; that is a write optimization,
|
|
130
|
+
// not permission to expose visits beyond the operator's retained-entry limit.
|
|
131
|
+
const cutoff = Date.now() - this.maxAgeMs
|
|
132
|
+
const fresh = this.readAll().filter(page => page.at >= cutoff)
|
|
133
|
+
const all = fresh.length > this.maxEntries ? fresh.slice(-this.maxEntries) : fresh
|
|
134
|
+
const domain = options.domain?.toLowerCase()
|
|
135
|
+
const query = options.query?.toLowerCase()
|
|
136
|
+
const session = options.session
|
|
137
|
+
const matches = all.filter(page => {
|
|
138
|
+
if (session !== undefined && page.session !== session) return false
|
|
139
|
+
if (query !== undefined) {
|
|
140
|
+
const haystack = `${page.url}\n${page.title ?? ''}`.toLowerCase()
|
|
141
|
+
if (!haystack.includes(query)) return false
|
|
142
|
+
}
|
|
143
|
+
if (domain === undefined) return true
|
|
144
|
+
try {
|
|
145
|
+
return new URL(page.url).hostname.toLowerCase().includes(domain)
|
|
146
|
+
} catch {
|
|
147
|
+
return page.url.toLowerCase().includes(domain)
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
matches.reverse()
|
|
151
|
+
return options.limit === undefined ? matches : matches.slice(0, Math.max(0, options.limit))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* How far past the cap the file may grow before it is rewritten.
|
|
156
|
+
*
|
|
157
|
+
* Scaled to the cap rather than fixed: a fixed 500 was meaningless when the cap is
|
|
158
|
+
* small (a caller asking for three entries would never reach 503), and the slack is
|
|
159
|
+
* there to batch rewrites, not to overrule the caller's bound.
|
|
160
|
+
* @returns the number of extra entries tolerated before a rewrite.
|
|
161
|
+
*/
|
|
162
|
+
private slack(): number {
|
|
163
|
+
return Math.min(PRUNE_SLACK, Math.max(1, Math.floor(this.maxEntries / 2)))
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
prune(): void {
|
|
167
|
+
// Ordinary navigations compare counters and a timestamp only. Read once on startup,
|
|
168
|
+
// when a batch fills, when limits change, or when an existing visit actually expires.
|
|
169
|
+
const now = Date.now()
|
|
170
|
+
if (this.knownEntries !== undefined && !this.limitsChanged
|
|
171
|
+
&& this.knownEntries + this.appendedSincePrune < this.pruneThreshold
|
|
172
|
+
&& now < this.nextExpiryAt) return
|
|
173
|
+
const all = this.readAll()
|
|
174
|
+
const cutoff = now - this.maxAgeMs
|
|
175
|
+
const fresh = all.filter(page => page.at >= cutoff)
|
|
176
|
+
const kept = fresh.length > this.maxEntries ? fresh.slice(fresh.length - this.maxEntries) : fresh
|
|
177
|
+
try {
|
|
178
|
+
if (kept.length !== all.length) {
|
|
179
|
+
writeFileAtomic(this.file, kept.map(page => `${JSON.stringify(page)}\n`).join(''))
|
|
180
|
+
}
|
|
181
|
+
this.knownEntries = kept.length
|
|
182
|
+
this.appendedSincePrune = 0
|
|
183
|
+
this.limitsChanged = false
|
|
184
|
+
this.nextExpiryAt = kept.reduce((earliest, page) => Math.min(earliest, page.at + this.maxAgeMs + 1), Infinity)
|
|
185
|
+
} catch {
|
|
186
|
+
// Best-effort: an unpruned file still reads correctly, and the atomic write leaves the
|
|
187
|
+
// previous one in place when it fails. Keep the next prune eligible to retry.
|
|
188
|
+
this.limitsChanged = true
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Parse the whole file, skipping blank and damaged lines. */
|
|
193
|
+
private readAll(): VisitedPage[] {
|
|
194
|
+
let raw: string
|
|
195
|
+
try {
|
|
196
|
+
raw = readFileSync(this.file, 'utf8')
|
|
197
|
+
} catch {
|
|
198
|
+
return []
|
|
199
|
+
}
|
|
200
|
+
const pages: VisitedPage[] = []
|
|
201
|
+
// Strip a BOM first: trim() does not remove U+FEFF (it is not whitespace in
|
|
202
|
+
// ECMAScript), so a file written by Notepad or PowerShell made the first line fail to
|
|
203
|
+
// parse and be discarded as corrupt — silently losing one visit, or the whole file when
|
|
204
|
+
// it holds one. settings-store strips one for the same reason.
|
|
205
|
+
for (const line of raw.replace(/^\uFEFF/, '').split('\n')) {
|
|
206
|
+
const trimmed = line.trim()
|
|
207
|
+
if (trimmed === '') continue
|
|
208
|
+
try {
|
|
209
|
+
const parsed = JSON.parse(trimmed) as Partial<VisitedPage>
|
|
210
|
+
if (typeof parsed.at !== 'number' || typeof parsed.url !== 'string') continue
|
|
211
|
+
pages.push({
|
|
212
|
+
at: parsed.at,
|
|
213
|
+
url: parsed.url,
|
|
214
|
+
...typeof parsed.title === 'string' && parsed.title !== '' ? { title: parsed.title } : {},
|
|
215
|
+
...typeof parsed.session === 'string' && parsed.session !== '' ? { session: parsed.session } : {},
|
|
216
|
+
})
|
|
217
|
+
} catch {
|
|
218
|
+
// A damaged line (typically a truncated tail) must not hide the rest.
|
|
219
|
+
continue
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return pages
|
|
223
|
+
}
|
|
224
|
+
}
|