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
- Variables
- func Capture(in CaptureInput) (snapshot, report *jsvalue.Object, ok bool)
- func CleanTitle(title string) string
- func DraftView(d *jsvalue.Object) *jsvalue.Object
- func EnvSecrets(environ []string, authVar string) []string
- func HTMLHeaders() [][2]string
- func IsExpiryDays(v any) bool
- func ParseShareBase(v string) string
- func Project(timeline []*jsvalue.Object, o Options) []*jsvalue.Object
- func RedactSnapshot(s *jsvalue.Object, r *Redactor) *jsvalue.Object
- func ShareView(r *jsvalue.Object, now float64) *jsvalue.Object
- func TranscriptEconomics(content, provider string) (*jsvalue.Object, bool)
- type CaptureInput
- type Kind
- type Mutation
- type Options
- type Page
- type Redactor
- type RedactorConfig
- type RenderOptions
- type Route
- func (rt *Route) Download(r *http.Request, id string) (int, any, http.Header)
- func (rt *Route) Preview(r *http.Request, id string) (int, any, http.Header)
- func (rt *Route) Share(r *http.Request, id string) (int, any, http.Header)
- func (rt *Route) ShareRead(r *http.Request, id string) (int, any, http.Header)
- func (rt *Route) Shares(r *http.Request) (int, any, http.Header)
- func (rt *Route) Snapshots(r *http.Request) (int, any, http.Header)
- type Store
- func (s *Store) Extend(id string, days float64) (Mutation, error)
- func (s *Store) List(tabID *string) ([]any, error)
- func (s *Store) Publish(draft *jsvalue.Object, routeBase string, days float64, replaceID string) (Mutation, error)
- func (s *Store) ReadDraft(id string) (*jsvalue.Object, error)
- func (s *Store) ReadShared(id, viewer string) (int, *jsvalue.Object, *jsvalue.Object, error)
- func (s *Store) RemoveDraft(id string)
- func (s *Store) Revoke(id string) (Mutation, error)
- func (s *Store) SaveDraft(tabID string, snapshot, report *jsvalue.Object) (*jsvalue.Object, error)
- func (s *Store) SweepDrafts()
- type TokenConfig
Constants ¶
const ( ModePreview = "preview" // the owner checks the draft: a banner says so ModeExport = "export" // a downloaded file )
Render modes.
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 ¶
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 ¶
CleanTitle is cleanConversationTitle: transport wrappers stripped, whitespace collapsed.
func EnvSecrets ¶
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 ParseShareBase ¶
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 ¶
Project turns timeline entries into snapshot entries. Pure; redaction and limits come after.
func RedactSnapshot ¶
RedactSnapshot passes every string a viewer can see through the redactor: title, model, entries, diffs.
func TranscriptEconomics ¶
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 ( Snapshots Download Preview )
The routes.
type Options ¶
Options are what the owner chose to include.
func ParseOptions ¶
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 ¶
RenderHTML is the snapshot 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.
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
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 ¶
Download is GET ?format=html|md: the draft as a file. The HTML is the preview page without the banner.
func (*Route) Preview ¶
Preview is GET: the draft exactly as a colleague will see it, under a banner.
func (*Route) Share ¶
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 ¶
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.
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 ¶
Extend sets a new expiry counted from now, capped at 90 days after the first publication.
func (*Store) List ¶
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 ¶
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 ¶
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 ¶
RemoveDraft drops a published draft: its snapshot now lives in the store.
func (*Store) Revoke ¶
Revoke removes a link's content at once; the next read answers 410. Revoking twice is fine.
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 ¶
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.