~kris/9p

llm9p

ref: ed43a61bf88f3238d4844391e1f7926d8490ae50 llm9p/internal/llmfs/new.go -rw-r--r-- 1.5 KiB
ed43a61b — pdfinn feat(llm9p): Add per-fid session isolation and prefill support 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package llmfs

import (
	"github.com/NERVsystems/llm9p/internal/llm"
	"github.com/NERVsystems/llm9p/internal/protocol"
)

// NewFile is a write-only file that resets the conversation when written to.
// It implements FidAwareFile to reset only the session for the writing fid.
type NewFile struct {
	*protocol.BaseFile
	sm *llm.SessionManager
}

// NewNewFile creates the new file
func NewNewFile(sm *llm.SessionManager) *NewFile {
	return &NewFile{
		BaseFile: protocol.NewBaseFile("new", 0222),
		sm:       sm,
	}
}

// Read implements File.Read
func (f *NewFile) Read(p []byte, offset int64) (int, error) {
	return 0, protocol.ErrPermission
}

// Write implements File.Write (fallback for non-fid-aware access)
func (f *NewFile) Write(p []byte, offset int64) (int, error) {
	// Without fid context, we can't reset a specific session
	return 0, protocol.ErrPermission
}

// ReadFid implements FidAwareFile.ReadFid
func (f *NewFile) ReadFid(fid uint32, p []byte, offset int64) (int, error) {
	return 0, protocol.ErrPermission
}

// WriteFid implements FidAwareFile.WriteFid
func (f *NewFile) WriteFid(fid uint32, p []byte, offset int64) (int, error) {
	// Reset only the session for this fid
	f.sm.Reset(fid)
	return len(p), nil
}

// CloseFid implements FidAwareFile.CloseFid
func (f *NewFile) CloseFid(fid uint32) error {
	// No per-fid state to clean up for this file
	return nil
}

// Stat returns the file's metadata
func (f *NewFile) Stat() protocol.Stat {
	s := f.BaseFile.Stat()
	s.Length = 0
	return s
}