share

package
v0.16.521 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 41 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package share is the owner's conversation snapshots and the read-only links published from them: a redacted draft of a conversation's transcript, its page and Markdown, the links' store and the page a colleague opens through the platform's share route.

Index

Constants

View Source
const (
	ModePreview = "preview" // the owner checks the draft: a banner says so
	ModeExport  = "export"  // a downloaded file
	ModeShared  = "shared"  // a colleague opened a published link
)

Render modes.

View Source
const PageCSP = "default-src 'none'; style-src 'unsafe-inline'; img-src 'none'; form-action 'none'; base-uri 'none'"

PageCSP allows no scripts, forms, images or frames; styles only from the inline sheet.

Variables

View Source
var ShareIDRe = regexp.MustCompile(`^[A-Za-z0-9_-]{43}$`)

ShareIDRe is a draft's or a link's id: 32 random bytes in base64url.

Functions

func Capture

func Capture(in CaptureInput) (snapshot, report *jsvalue.Object, ok bool)

Capture is projection → redaction → the per-entry limit (after redaction, so a cut never splits a secret) → the 5 MB check. It returns the snapshot and its report, or false when the snapshot is too large.

func CleanTitle

func CleanTitle(title string) string

CleanTitle is cleanConversationTitle: transport wrappers stripped, whitespace collapsed.

func DraftView

func DraftView(d *jsvalue.Object) *jsvalue.Object

DraftView is what the owner's page gets of a draft.

func EnvSecrets

func EnvSecrets(environ []string, authVar string) []string

EnvSecrets are the exact secret values in an environment: values of eight or more characters, without whitespace and not a path, of variables whose names look secret (or the named auth variable).

func HTMLHeaders

func HTMLHeaders() [][2]string

HTMLHeaders are the headers of every snapshot page.

func IsExpiryDays

func IsExpiryDays(v any) bool

IsExpiryDays: 7, 30 or 90, as a number.

func ParseShareBase

func ParseShareBase(v string) string

ParseShareBase is the link prefix the platform sent ("https://<share host>/share/<route key>/", or a hub's own); "" when sharing is not set up (no header, or a malformed one).

func Project

func Project(timeline []*jsvalue.Object, o Options) []*jsvalue.Object

Project turns timeline entries into snapshot entries. Pure; redaction and limits come after.

func RedactSnapshot

func RedactSnapshot(s *jsvalue.Object, r *Redactor) *jsvalue.Object

RedactSnapshot passes every string a viewer can see through the redactor: title, model, entries, diffs.

func ShareView

func ShareView(r *jsvalue.Object, now float64) *jsvalue.Object

ShareView is what the owner's page gets of a link.

func TranscriptEconomics

func TranscriptEconomics(content, provider string) (*jsvalue.Object, bool)

TranscriptEconomics is tokens and time straight from the raw transcript. Claude writes one line per content block with the same message id and usage, so usage counts once per id; a Codex token_count is cumulative, the last wins. false where the previous runtime threw (a line that is JSON null).

Types

type CaptureInput

type CaptureInput struct {
	Timeline  []*jsvalue.Object
	Provider  string
	Title     string
	OwnerSub  any // string or nil
	Options   Options
	Economics *jsvalue.Object // nil for none
	Redactor  *Redactor
	Now       float64
}

CaptureInput is what a snapshot is made of.

type Kind

type Kind int

Kind is which of the routes a request is for.

const (
	NotShare Kind = iota
	Snapshots
	Download
	Preview
	Shares
	ShareOne
	ShareRead
)

The routes.

func Match

func Match(r *http.Request, platformAPI string) (Kind, string)

Match says which route a request is for and the id in its path, as the previous runtime's router split and decoded the path; platformAPI is the platform's prefix ("/api/<platform>").

type Mutation

type Mutation struct {
	Share  *jsvalue.Object
	Status int
	Error  string
}

Mutation is a change to a link: the link's view, or a refusal's status and message.

type Options

type Options struct {
	Tools                      string // "summary" or "none"
	Thinking, Diffs, Economics bool
}

Options are what the owner chose to include.

func ParseOptions

func ParseOptions(v any) (Options, bool)

ParseOptions is parseShareOptions: false for anything but {tools: summary|none, thinking, diffs, economics: bool}.

type Page

type Page struct {
	Brand string
	// DropHostSuffix and DropPathPrefix: an absolute link to a host ending so, under that path, is dropped.
	DropHostSuffix, DropPathPrefix string
}

Page is what the page names: the platform's brand, and the links it must not carry (into the agent workspace).

func (Page) RenderHTML

func (p Page) RenderHTML(source *jsvalue.Object, r *Redactor, o RenderOptions) string

RenderHTML is the snapshot page.

func (Page) RenderMarkdown

func (p Page) RenderMarkdown(source *jsvalue.Object, r *Redactor) string

RenderMarkdown is the snapshot as Markdown, for the .md download; redacted again like the page.

type Redactor

type Redactor struct {
	// contains filtered or unexported fields
}

Redactor hides the secrets and shortens the paths of the strings of one snapshot, counting what it did.

func NewRedactor

func NewRedactor(c RedactorConfig) *Redactor

NewRedactor is a redactor with fresh counters.

func (*Redactor) Redact

func (r *Redactor) Redact(text string) string

Redact is one string with its secrets hidden and its paths shortened.

func (*Redactor) Report

func (r *Redactor) Report() *jsvalue.Object

Report is {pathsShortened, redactions} so far.

type RedactorConfig

type RedactorConfig struct {
	// KnownSecrets are exact secret values (the pair's secret, the cli-token, secret-looking environment values).
	KnownSecrets []string
	// HomeDirs are shortened to "~"; /home/<user> and /root always are.
	HomeDirs []string
	// WorkspaceDir is dropped from the front of paths ("" for none).
	WorkspaceDir string
	// ProfileHomes is the folder of per-person profiles whose <name>/home is a home too ("" for none).
	ProfileHomes string
}

RedactorConfig is what a redactor knows of this runtime.

type RenderOptions

type RenderOptions struct {
	Mode string
	// Viewer is who opened a published link ("" for none).
	Viewer string
	// ExpiresAt is when a published link stops working (0 for none).
	ExpiresAt float64
}

RenderOptions are a render's mode and what a published link adds.

type Route

type Route struct {
	Store *Store
	Page  Page
	Token TokenConfig
	// Secret is the pair's secret: share-read tokens are checked with a key derived from it, and it is a known secret.
	Secret []byte
	// Home and EnvHome are shortened to "~" (the user's home, and $HOME when it differs).
	Home, EnvHome string
	// WorkspaceDir is dropped from the front of paths ("" for none); ProfileHomes is the per-person profiles folder.
	WorkspaceDir, ProfileHomes string
	// Environ is the process environment whose secret-looking values are redacted (nil: none).
	Environ func() []string
	// ShareBaseHeader carries the link prefix the platform gives this runtime; ShareTokenHeader the share-read token.
	ShareBaseHeader, ShareTokenHeader string
	// FilePrefix starts a downloaded file's name.
	FilePrefix string
	// SessionOK is a page session; APIRefusal the old API's refusal of a caller with neither session nor cli-token;
	// Claims the session token's claims (nil without one).
	SessionOK  func(*http.Request) bool
	APIRefusal func(*http.Request) (int, any, http.Header, bool)
	Claims     func(*http.Request) map[string]any
	// FindTab is a tab of this runtime's layouts by id, as stored.
	FindTab func(tabID string) (*jsvalue.Object, bool)
	// Headlines reads a Claude transcript's AI title.
	Headlines *launch.Headlines
	// Now is the clock (tests freeze it); nil is the real one.
	Now func() time.Time
}

Route answers the snapshot and link routes under the platform API, as the previous runtime's dispatcher and handlers did: the dispatcher's refusal and body parsing first, then the handler's own checks.

func (*Route) Download

func (rt *Route) Download(r *http.Request, id string) (int, any, http.Header)

Download is GET ?format=html|md: the draft as a file. The HTML is the preview page without the banner.

func (*Route) Preview

func (rt *Route) Preview(r *http.Request, id string) (int, any, http.Header)

Preview is GET: the draft exactly as a colleague will see it, under a banner.

func (*Route) Share

func (rt *Route) Share(r *http.Request, id string) (int, any, http.Header)

Share is PATCH {expiresInDays} → {share} (a new date from now, never past 90 days after publication) and DELETE → 204 (revoked: content removed at once, the record stays as a tombstone).

func (*Route) ShareRead

func (rt *Route) ShareRead(r *http.Request, id string) (int, any, http.Header)

ShareRead is GET: a published snapshot for the platform's share route only. No session is looked at, only the short-lived share-read token signed for exactly this id: 200 HTML (redacted again), 401 no or bad token, 403 a token for another id, 404 unknown, 410 revoked or expired.

func (*Route) Shares

func (rt *Route) Shares(r *http.Request) (int, any, http.Header)

Shares is GET ?tabId= → {enabled, shares} and POST {draftId, expiresInDays, replaceId?} → 201 {share}.

func (*Route) Snapshots

func (rt *Route) Snapshots(r *http.Request) (int, any, http.Header)

Snapshots is POST {tabId, options} → 201 {draft}: a redacted snapshot draft of the conversation.

type Store

type Store struct {
	DataDir string
	// Now is the clock (tests freeze it); nil is the real one.
	Now func() time.Time
	// NewID makes the id of a draft or a link (tests count); nil is 32 random bytes.
	NewID func() string
	// contains filtered or unexported fields
}

Store is the drafts and the links of this runtime.

func (*Store) Extend

func (s *Store) Extend(id string, days float64) (Mutation, error)

Extend sets a new expiry counted from now, capped at 90 days after the first publication.

func (*Store) List

func (s *Store) List(tabID *string) ([]any, error)

List is the owner's links, the latest change first; with a tab id only that conversation's.

func (*Store) Publish

func (s *Store) Publish(draft *jsvalue.Object, routeBase string, days float64, replaceID string) (Mutation, error)

Publish turns a draft into a frozen link, or with replaceID puts it behind an existing live link (same URL, version + 1). The draft's snapshot is stored as it is: it was redacted at capture and is redacted again on every read.

func (*Store) ReadDraft

func (s *Store) ReadDraft(id string) (*jsvalue.Object, error)

ReadDraft is a live draft; nil when the id is malformed, unknown or expired (an expired file is removed on the spot). An error is a draft file that is not JSON (the previous runtime failed the request).

func (*Store) ReadShared

func (s *Store) ReadShared(id, viewer string) (int, *jsvalue.Object, *jsvalue.Object, error)

ReadShared is what a viewer gets: the snapshot of a live link (and its record), or 410 for a revoked or expired one, 404 for anything else. It counts the view.

func (*Store) RemoveDraft

func (s *Store) RemoveDraft(id string)

RemoveDraft drops a published draft: its snapshot now lives in the store.

func (*Store) Revoke

func (s *Store) Revoke(id string) (Mutation, error)

Revoke removes a link's content at once; the next read answers 410. Revoking twice is fine.

func (*Store) SaveDraft

func (s *Store) SaveDraft(tabID string, snapshot, report *jsvalue.Object) (*jsvalue.Object, error)

SaveDraft writes a new draft of a snapshot and returns it.

func (*Store) SweepDrafts

func (s *Store) SweepDrafts()

SweepDrafts removes the drafts written more than an hour ago.

type TokenConfig

type TokenConfig struct {
	Salt, Audience string
}

TokenConfig names the token: the HKDF salt and the audience the share route signs with.

func (TokenConfig) VerifyToken

func (c TokenConfig) VerifyToken(token, id string, secret []byte, now time.Time) (string, int)

VerifyToken checks a share-read token for one link: the viewer it names, or 401 (no, forged, expired or overlong token) or 403 (a valid token for another link). It checks what jose's jwtVerify checked for the previous runtime: HS256, the audience, iat/exp/sid/viewer present, issued at most two minutes ago and not in the future.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL