drop

package
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: AGPL-3.0 Imports: 16 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 drop turns a file dropped on the terminal into a path the session can paste.

The window hands over the dropped files' own paths, and an unconfined session takes them as they are. A confined session's home is an empty private one (internal/sandbox), so a file outside its checkout is a path only lich can open: for those the window uploads the bytes (Upload), lich keeps a copy under the config dir, and the copy's path is pasted. Reading it works; editing it edits the copy, which is why the copy's path never lands at a prompt without the line that says so (copyNotice). The sandbox binds the copies directory and nothing else of the home.

The copies are kept one directory per session, and that is the unit they are deleted in: a confined session sees its own directory mounted and not the one beside it, and every copy a session was dropped goes when its row does (Purge): a copy lives exactly as long as the session it was dropped into, and the clock only ever collects the orphans (Prune).

The footer's attach button lands here too (Attach): a file chosen from the native picker already has its path, but a confined session cannot open one outside its checkout either, and the same copy is the answer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(configDir string) string

Dir is where a lich with this config directory keeps the copies. It is the directory the sandbox binds into a confined session, so it is named here rather than spelled out at the two callers (main.go wires it through to internal/terminal).

Types

type Attachment

type Attachment = api.DropAttachment

type Service

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

func New

func New(configDir string, live func(sessionID string) bool) *Service

New keeps uploaded copies under Dir(configDir), and creates that directory now rather than on the first drop. A confined session binds its own copies directory when its PTY spawns (internal/terminal/sandbox.go), and a bind whose source is not there yet is skipped: the first file dropped into a session that opened before the directory existed would land where that session cannot read it.

live answers whether a session's row still exists, open or parked (store.SessionExists): it is what keeps the age rule off the copies of a session that is still around. A nil one makes every copy an orphan, which is what the tests want and never what a running lich does.

func (*Service) Attach

Attach opens the file chooser and answers with a path the session can actually open: the file's own where the session reaches it, a copy's inside the session's dropped-files directory otherwise. It is the footer's attach button, and the counterpart of a drop — the same problem arrives through a dialog instead of a drag.

The picker runs here rather than in the caller, and that is the security property of this method: every session carries LICH_TOKEN (see internal/terminal), so a confined agent can call any RPC on the loopback listener. A method that copied a *path it was handed* would let that agent name ~/.ssh/id_rsa and read the copy from inside the sandbox — the sandbox undone by its own harness. Here the path can only come from a dialog a human answers on screen.

opts.Root is the session's checkout, the one tree a confined session sees; a file under it keeps its own path. Anything else is copied, including files under directories the sandbox happens to bind (a toolchain, ~/.config): copying one of those costs a few bytes, and deciding it does not need copying means reproducing the mount list here, where it would go stale in silence.

func (*Service) Prune

func (s *Service) Prune()

Prune deletes the copies of sessions that are gone and older than keepDropped. Called after each new copy, the only thing that grows the directory, so a lich left running for weeks still clears what earlier drops left behind.

Age is the backstop, not the rule: a session that ends takes its copies with it (Purge), and what this catches is the session lich never saw end — a crash, a kill, a machine that went down.

A failure here is never the caller's problem — the copy it just wrote is good, and the stale ones get another chance on the next drop.

func (*Service) PruneStale

func (s *Service) PruneStale()

PruneStale is Prune plus the session directories left with nothing in them. Startup only, and that is the whole reason it is a second method: a confined session binds its own copies directory when it spawns, and removing that directory under a live mount leaves every later copy of that session invisible inside it — the mount would still point at the deleted one. At startup no session has spawned yet, so there is no mount to strand.

func (*Service) Purge

func (s *Service) Purge(sessionID string)

Purge deletes every copy dropped into one session. It is what makes a copy die with the session it was dropped into rather than with the clock: the paths pasted from it only ever meant anything inside that conversation, and the session's own row is gone by the time this runs (store.SetSessionGone).

Best effort, like Prune: a failure leaves copies that the age rule still clears.

func (*Service) Save

func (s *Service) Save(sessionID, name string, body io.Reader) (string, error)

Save writes one dropped file under the session's own copies directory, without ever overwriting an earlier drop — its path may still be sitting in a prompt. sessionID must already be one path element (element).

func (*Service) SetPicker

func (s *Service) SetPicker(pick func(title string) (string, error))

SetPicker wires the host's file picker (internal/project), which is what the footer's attach button reaches through Attach. Startup wiring, called before anything serves.

func (*Service) SetPromptLanguage

func (s *Service) SetPromptLanguage(lang func() prompt.Lang)

SetPromptLanguage wires where the copy notice reads its language. It is read again for every notice, so a change in Settings reaches the next drop; without it the notice is English, the default. Startup wiring, called before anything serves.

func (*Service) Upload

func (s *Service) Upload(w http.ResponseWriter, r *http.Request)

Upload stores one dropped file's bytes and answers with the path it landed at. The name and the session ride the query because the body is the file itself.

Jump to

Keyboard shortcuts

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