Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/agent/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ func runDaemon(root string) {

// Step 6: bind the Unix socket. The run directory (0700) is already
// ensured above; explicit socket chmod 0600 guards against any umask.
// The socket trusts callers running as this user: they can already read
// the user's files, so the daemon requires no separate connection token.
ln, err := net.Listen("unix", paths.Sock)
if err != nil {
agentLogger.Error("daemon listen failed", "path", paths.Sock, "err", err)
Expand Down Expand Up @@ -314,6 +316,7 @@ func runDaemon(root string) {
pty.Close() // hang up every terminal, as closing its tab does
chat.Close() // and end every Claude tab's program
lsp.Close()
fsys.DropUploads(nil)
if hooksrv != nil {
_ = hooksrv.Close()
}
Expand Down Expand Up @@ -391,6 +394,7 @@ func runDaemon(root string) {
var preempted atomic.Int32

host := stdioserver.New(d, conn, conn, agentLogger)
host.RegisterShutdownHook(func() { fsys.DropUploads(host.Context()) })

// Ready goes first: the client takes the first frame it gets for the
// handshake, and an event ahead of it reads as an agent without an
Expand Down
3 changes: 3 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ func newHookGetInfoHandler(hs hookInfoProvider) dispatch.Handler {
if err := hs.WaitReady(waitCtx); err != nil {
return nil, proto.NewError(proto.CodeUnavailable, "hookserver not ready: "+err.Error())
}
// The daemon's 0600 socket trusts this user, whose processes can
// already read the user's files. The master hook token can be returned
// over that connection without a separate connection token.
return map[string]any{
"socketPath": hs.SocketPath(),
"token": hs.Token(),
Expand Down
3 changes: 2 additions & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ nexus file push --device "Mac mini" --workspace site -r ./snapshot /Users/me/Dow
```

- `pull` 에서 로컬 대상을 생략하거나 기존 폴더를 지정하면 원래 이름으로 저장합니다. `push` 에서 원격 대상이 기존 폴더이면 그 안에 원래 이름으로 넣습니다. 여러 소스를 보내려면 대상이 기존 폴더여야 합니다. 각 파일의 부모 폴더가 있어야 하며, `-r` 은 복사할 폴더 트리를 만듭니다.
- 워크스페이스 안 읽기에는 파일 공유 권한이 필요합니다. 워크스페이스 안 쓰기에는 채팅 제어와 에이전트 요청을 허용해야 합니다. 워크스페이스 밖 절대 경로를 읽거나 쓰려면 대상 컴퓨터에서 터미널 제어와 에이전트 요청을 허용해야 합니다. 에이전트 설정이 ‘묻기’이면 쓰기와 워크스페이스 밖 읽기를 승인해야 합니다. 한 번 승인하면 같은 복사의 파일 조각과 승인된 폴더의 하위 경로에 적용됩니다. `push` 와 워크스페이스 밖 전송에는 대상 앱의 원격 프로토콜 0.14.0 이상과 로컬 워크스페이스가 필요합니다.
- 워크스페이스 안 읽기에는 파일 공유 권한이 필요합니다. 워크스페이스 안 쓰기에는 채팅 제어와 에이전트 요청을 허용해야 합니다. 워크스페이스 밖 절대 경로를 읽거나 쓰려면 대상 컴퓨터에서 터미널 제어와 에이전트 요청을 허용해야 합니다. 에이전트 설정이 ‘묻기’이면 쓰기와 워크스페이스 밖 읽기를 승인해야 합니다. 한 번 승인하면 같은 복사의 파일 조각과 승인된 폴더의 하위 경로에 적용됩니다. `push` 와 워크스페이스 밖 전송에는 대상 앱의 원격 프로토콜 0.14.0 이상이 필요합니다. SSH·WSL 워크스페이스로 보내려면 대상 파일 에이전트가 업로드를 지원해야 합니다. 워크스페이스 밖 절대 경로는 대상 앱의 로컬 워크스페이스에서 사용할 수 있습니다.
- 각 파일은 전송을 마친 뒤 대상에 배치되며 기존 파일을 덮어씁니다. `push` 는 파일 하나당 최대 20 GiB 를 보낼 수 있으며 기존 대상 파일의 권한 비트를 유지합니다. `-r` 은 심볼릭 링크를 건너뜁니다. `pull` 은 원격 폴더 목록이 잘렸으면 복사를 시작하기 전에 실패합니다.
- Windows에서 `push`로 파일을 덮어쓰면 기존 파일의 ACL과 읽기 전용·숨김 속성은 유지되지 않습니다.
- 출력에는 저장 경로, 바이트 수, SHA-256 이 들어갑니다. `--json` 은 기기와 두 컴퓨터의 경로도 출력합니다. `-r` 또는 여러 소스를 지정한 `push` 의 JSON 결과는 배열이며 건너뛴 링크에는 `"skipped": "symlink"` 가 붙습니다.

## 세션의 에이전트 따라가기
Expand Down
9 changes: 8 additions & 1 deletion internal/fs/preview_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ import (
// Open the resolved absolute path one component at a time. O_NOFOLLOW
// protects each component if it changes after the grant's symlink checks.
func openPreviewFile(real string) (*os.File, error) {
return openCanonicalPath(real, false)
}

func openCanonicalPath(real string, directory bool) (*os.File, error) {
const flags = unix.O_CLOEXEC | unix.O_NOFOLLOW
fd, err := unix.Open("/", flags|previewDirOpenFlags, 0)
if err != nil {
return nil, err
}
if real == "/" && directory {
return os.NewFile(uintptr(fd), real), nil
}
parts := strings.Split(strings.TrimPrefix(real, "/"), "/")
for i, part := range parts {
mode := flags | unix.O_RDONLY | unix.O_NONBLOCK
if i < len(parts)-1 {
if directory || i < len(parts)-1 {
mode = flags | previewDirOpenFlags
}
next, err := unix.Openat(fd, part, mode, 0)
Expand Down
15 changes: 14 additions & 1 deletion internal/fs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type EventSink func(event string, payload any) error
type Service struct {
root string

uploadMu sync.Mutex
uploads map[string]*fileUpload
uploadClosed bool

// watchMu serializes fs.watch, fs.unwatch and Close, so fsnotify Add and
// Remove run in call order without holding mu, which the event loop
// needs before it can take the next event from fsnotify.
Expand All @@ -63,6 +67,7 @@ func New(root string) (*Service, error) {
}
return &Service{
root: filepath.Clean(abs),
uploads: make(map[string]*fileUpload),
watches: make(map[string]*watchEntry),
buffers: make(map[string]filewatch.FsChangeKind),
}, nil
Expand All @@ -75,8 +80,9 @@ func (s *Service) SetEventSink(sink EventSink) {
s.sink = sink
}

// Close stops watcher goroutines and clears buffered fs events.
// Close discards uploads, stops watchers, and clears buffered fs events.
func (s *Service) Close() {
s.DropUploads(nil)
s.watchMu.Lock()
defer s.watchMu.Unlock()
s.mu.Lock()
Expand Down Expand Up @@ -108,6 +114,13 @@ func Register(d *dispatch.Dispatcher, fsys *Service) {
d.Register("fs.readAbsoluteRange", fsys.ReadAbsoluteRange)
d.Register("fs.readPreview", fsys.ReadPreview)
d.Register("fs.writeFile", fsys.WriteFile)
d.Register("fs.upload.resolve", bindUpload(fsys.resolveUpload))
d.Register("fs.upload.mkdir", bindUpload(fsys.mkdirUpload))
d.Register("fs.upload.begin", bindUpload(fsys.beginUpload))
d.Register("fs.upload.chunk", bindUpload(fsys.chunkUpload))
d.Register("fs.upload.verify", bindUpload(fsys.verifyUpload))
d.Register("fs.upload.commit", bindUpload(fsys.commitUpload))
d.Register("fs.upload.abort", bindUpload(fsys.abortUpload))
d.Register("fs.createFile", fsys.CreateFile)
d.Register("fs.mkdir", fsys.Mkdir)
d.Register("fs.unlink", fsys.Unlink)
Expand Down
Loading