drop

package
v0.71.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 15 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 shell is a Chromium window, not a native terminal emulator, so a drop arrives through the page's DataTransfer — which carries the bytes and the metadata (name, size, mtime) but never the file's path: Chromium exposes neither `text/uri-list` nor `File.path` for a local drop. Two ways back to a path, in order:

  • Resolve: find the item by that metadata — under the session's directory first, then under home. The path is then the real one, so an edit lands on the user's file.
  • Upload: for anything neither tree holds, keep a copy under the config dir and paste the copy's path. Reading it works; editing it edits the copy — which is why Resolve is tried first, and why the copy's path never lands at a prompt without the line that says so (copyNotice).

A confined session takes the second way far more often, and has to: its home is an empty private one (internal/sandbox), so a path found under the real home is a path only lich can open. Resolve is told which sessions those are and does not search home for them at all — the copy is what reaches the session, because 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).

A dropped directory only ever takes the first path: the page can walk one, but copying a tree to paste a path to the copy is not what the drop meant.

The footer's attach button lands here too (Attach): a file chosen from the native picker already has its path, so there is nothing to look up — 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 struct {
	Path   string `json:"path"`
	Notice string `json:"notice"`
}

Attachment is what the picker produced: the path to write at the prompt, and the line that goes under it when that path is a copy's (copyNotice), empty when the session opens the file where it lies. Both empty for a cancelled dialog.

type Item

type Item struct {
	Name  string `json:"name"`
	Size  int64  `json:"size"`
	Mtime int64  `json:"mtime"`
	Dir   bool   `json:"dir"`
}

Item is one dropped entry as the page sees it — the whole of what Chromium hands over about a local file. Mtime is File.lastModified: milliseconds.

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

func (s *Service) Attach(sessionID, root string, confined bool) (Attachment, error)

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.

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) Resolve

func (s *Service) Resolve(root string, items []Item, confined bool) []string

Resolve maps each item to its absolute path, or "" when neither the session's tree nor the home directory holds a match for it.

The session's directory is searched first, then home — a drop is most often the session's own file, but it is just as often a screenshot or a directory from somewhere else entirely, and a directory has no copy to fall back to.

confined is the verdict recorded for the calling session (internal/sandbox): its home is an empty private one, so a match under the real home is a path the session cannot open, and answering with it hands the prompt a file that is not there. Those sessions search their checkout and nothing else, and everything outside it falls through to the copy — which the sandbox does bind. A machine with no sandbox backend confines nothing, so the flag alone is not enough to stop searching: Windows, which has no backend at all, keeps the unconfined behaviour whatever the row says.

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