[Script library]

Save, load, import/export Pine scripts via local IndexedDB, cloud Worker, or git (GitHub/GitLab).

Script library

The script library is the operator-facing surface of storage plugins. The editor holds the working document; the library is durable, named documents with metadata.

Abstract

BackendIdMediumAuth
LocallocalIndexedDB (pynescript.axis.storage), LS fallbacknone
CloudcloudWorker /api/scripts (D1 or memory)Bearer Pro API key
GitgitGitHub/GitLab Contents APIPAT

Active backend: store.activePlugins.storage (Settings or library picker).

Conceptual model

Service layer (listScripts, readScript, writeScript, …) never talks to engines.

Interface surface

Manager → Script Library:

ControlBehavior
Backend selectsetActivePlugin('storage', id)
Refreshlist()
Name / descriptionMetadata for next write
SaveWrite current editor doc
Loadread → inject editor (loadLibraryDoc / setDoc)
Deleteremove
Export JSONFull library dump
Import JSONBulk write
Cloud endpoint + keySaved under pluginsConfig['storage:cloud']
Git fieldsprovider, token, owner, repo, branch, basePath, …

Status line: backend · remote · branch · connected · count.

Local backend

  • DB name pynescript.axis.storage v1 stores scripts + kv
  • Legacy SuperChart library keys migrate once
  • Drafts: optional saveDraft / loadDraft without polluting remote backends
  • Works fully offline

Invariant: browser profile wipe deletes local library—export JSON for backup.

Cloud backend

  • Authorization: Bearer <api_key>
  • Scripts partitioned by key hash on Worker
  • Concurrent updates may use If-Match / revision → HTTP 409 on conflict
  • Default endpoint falls back to store.endpoint or http://127.0.0.1:8787

Configure key in library panel or Settings-related config; keys stay in this browser’s localStorage state blob.

Git backend

InvariantDetail
Save commitsEach write/remove is a commit (+ push via API)
Drafts localNo remote commit for draft buffer
basePathDefault pine-library/
Providersgithub, gitlab (+ self-hosted apiBaseUrl)

Token scopes: GitHub contents:write; GitLab api or write_repository.

Worked examples

Solo offline library

  1. Storage = local
  2. Write indicator in editor
  3. Name sma-ribbon → Save
  4. Reload page → Library → Load

Team cloud

  1. Admin creates key on Worker
  2. Storage = cloud; paste endpoint + key
  3. Save shared strategies
  4. Second browser: same key → list

Research monorepo

  1. Storage = git; GitHub owner/repo; basePath research/pine
  2. Save → commit message from template
  3. PR review on GitHub UI

Internals

PathRole
frontend/src/ui/ScriptLibraryPanel.tsxUI
frontend/src/storage/service.tsFacade
frontend/src/storage/local.tsIDB
frontend/src/storage/cloud.tsWorker API
frontend/src/storage/git.tsGit plugin
frontend/src/storage/git-github.ts, git-gitlab.tsForges

Contract: Plugin types StoragePlugin.

Failure modes

SymptomCauseMitigation
Empty list after switchWrong backend / authCheck status line + key
401 cloudBad/missing keyRegenerate; re-save config
409 cloudRevision conflictRe-read then write
Git 404Wrong owner/repo/basePathFix config
Quota localHuge scripts in LS fallbackPrefer IDB; export prune

See also