Skip to content

Commit

Permalink
"Archived automation and file_io modules, removed PersistableState an…
Browse files Browse the repository at this point in the history
…d related functions, refactored Session and GitTracker to use path instead of PersistableState"
  • Loading branch information
Cvikli committed Jan 14, 2025
1 parent 0f89574 commit 352c443
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 106 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions archived/file_io/Persistable.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

using JSON3
using JLD2

@kwdef mutable struct PersistableState
path::String
PersistableState(path::String) = (mkpath(path); new(expanduser(abspath(expanduser((path))))))
end



# persist!(conv::ConversationCTX) = save_message(conv)
# save_message(conv::ConversationCTX) = save_conversation_to_file(conv)
get_conversation_filename(p::PersistableState,conv_id::String) = (files = filter(f -> endswith(f, "_$(conv_id).log"), readdir(p.path)); isempty(files) ? nothing : joinpath(p.path, first(files)))

function generate_overview(conv::CONV, conv_id::String, p::PersistableState)
@assert false
sanitized_chars = strip(replace(replace(first(conv.messages[1].content, 32), r"[^\w\s-]" => "_"), r"\s+" => "_"), '_')
return joinpath(p.path, "$(date_format(conv.timestamp))_$(sanitized_chars)_$(conv_id).log")
end

(p::PersistableState)(conv::Session) = begin
println(conversaion_path(p, conv))
mkpath_if_missing(joinpath(p.path, conv.id))
mkpath_if_missing(conversaion_path(p, conv))
save_conversation(conversaion_file(p, conv), conv)
conv
end



export VirtualWorkspace, init_virtual_workspace_path

struct VirtualWorkspace
rel_path::String
end

function init_virtual_workspace_path(p::PersistableState, conv_ctx::Session)
vpath = joinpath(conv_ctx.id, "workspace")
rel_path = mkdir(expanduser(joinpath(p.path, vpath)))
VirtualWorkspace(rel_path)
end


File renamed without changes.
9 changes: 0 additions & 9 deletions src/EasyContext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ include("tools/formats/format.jl")
include("tools/tools.jl")
include("prompts/guides.jl")
include("ContextStructs.jl")
include("file_io/custom_format.jl")
include("file_io/Persistable.jl")
include("protocol/AbstractTypes.jl")
include("protocol/Message.jl")
# include("protocol/CodeBlock.jl")
include("protocol/Conversation.jl")
include("protocol/Session.jl")
include("file_io/Conversation_JSON.jl")
include("anthropic_extension.jl")
include("Rephrase.v1.jl")
include("chunkers/SourceChunks.jl")
Expand Down Expand Up @@ -56,12 +53,6 @@ include("contexts/Contexts.jl")



# Automation
include("automation/selector_llm.jl")
include("automation/condition_llm.jl")

include("model/persistence.jl")

include("precompile_scripts.jl")

end # module EasyContext
Expand Down
13 changes: 0 additions & 13 deletions src/file_io/Persistable.jl

This file was deleted.

1 change: 0 additions & 1 deletion src/loader/loaders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
include("token_counter.jl")
include("workspace_file_filters.jl")
include("workspace_loader.jl")
include("virtual_workspace.jl")

include("cached_loader.jl")
include("julia_loader.jl")
Expand Down
14 changes: 0 additions & 14 deletions src/loader/virtual_workspace.jl
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@

export VirtualWorkspace, init_virtual_workspace_path

struct VirtualWorkspace
rel_path::String
end

function init_virtual_workspace_path(p::PersistableState, conv_ctx::Session)
vpath = joinpath(conv_ctx.id, "workspace")
rel_path = mkdir(expanduser(joinpath(p.path, vpath)))
VirtualWorkspace(rel_path)
end


48 changes: 0 additions & 48 deletions src/model/persistence.jl

This file was deleted.

1 change: 0 additions & 1 deletion src/precompile_scripts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ using DataStructures: OrderedDict
# age_tracker = AgeTracker(max_history=14, cut_to=6)

# question_acc = QuestionCTX()
# persister = PersistableState(logdir)

# # Simulate usage of EasyContext functions
# # print_project_tree(workspace_context.workspace, show_tokens=show_tokens)
Expand Down
7 changes: 0 additions & 7 deletions src/protocol/Conversation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ update_last_user_message_meta(conv::CONV, itok::Int, otok::Int, cached::Int, cac
last_msg(conv::CONV) = conv.messages[end].content

get_message_separator(conv_id) = "===AISH_MSG_$(conv_id)==="
get_conversation_filename(p::PersistableState,conv_id::String) = (files = filter(f -> endswith(f, "_$(conv_id).log"), readdir(p.path)); isempty(files) ? nothing : joinpath(p.path, first(files)))

function parse_conversation_filename(filename)
m = match(CONVERSATION_FILE_REGEX, filename)
Expand All @@ -87,12 +86,6 @@ function parse_conversation_filename(filename)
end


function generate_overview(conv::CONV, conv_id::String, p::PersistableState)
@assert false
sanitized_chars = strip(replace(replace(first(conv.messages[1].content, 32), r"[^\w\s-]" => "_"), r"\s+" => "_"), '_')
return joinpath(p.path, "$(date_format(conv.timestamp))_$(sanitized_chars)_$(conv_id).log")
end

@kwdef mutable struct TODO <: CONV
overview::String # max 20 token thing
end
13 changes: 3 additions & 10 deletions src/protocol/Session.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,10 @@ end
conv
end

abs_conversaion_path(p,conv::Session) = joinpath(abspath(expanduser(p.path)), conv.id, "conversations")
conversaion_path(p,conv::Session) = joinpath(p.path, conv.id, "conversations")
conversaion_file(p,conv::Session) = joinpath(conversaion_path(p, conv), "conversation.json")
abs_conversaion_path(p,conv::Session) = joinpath(abspath(expanduser(path)), conv.id, "conversations")
conversaion_path(path,conv::Session) = joinpath(path, conv.id, "conversations")
conversaion_file(path,conv::Session) = joinpath(conversaion_path(path, conv), "conversation.json")

(p::PersistableState)(conv::Session) = begin
println(conversaion_path(p, conv))
mkpath_if_missing(joinpath(p.path, conv.id))
mkpath_if_missing(conversaion_path(p, conv))
save_conversation(conversaion_file(p, conv), conv)
conv
end
function to_PT_messages(session::Session)
return [
SystemMessage(session.system_message.content),
Expand Down
6 changes: 3 additions & 3 deletions src/stateful_transformation/GitTracker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
todo::String=""
end

GitTracker!(ws, p::PersistableState, conv) = begin
GitTracker!(ws, path::String, conv) = begin
# clean_unnamed()
# TODO if there is branch name collision then regerenrate extending the list what we 'don't want'
gits = WorkTree[]
Expand All @@ -32,15 +32,15 @@ GitTracker!(ws, p::PersistableState, conv) = begin

# proj_name = basename(normpath(project_path))
proj_name = get_project_name(expanded_project_path)
worktreepath = joinpath(p.path, conv.id, proj_name) # workpath cannot be ~ ... it MUST be expanded
worktreepath = joinpath(path, conv.id, proj_name) # workpath cannot be ~ ... it MUST be expanded
ws.project_paths[i] = worktreepath

create_worktree(expanded_project_path, worktreepath)
# @show worktreepath
push!(gits, WorkTree(LibGit2.GitRepo(worktreepath)))
end
ws.root_path, ws.rel_project_paths = resolve(ws.resolution_method, ws.project_paths)
conv_path = abs_conversaion_path(p, conv)
conv_path = abs_conversaion_path(path, conv)

init_git(conv_path)
conv_repo = LibGit2.GitRepo(conv_path)
Expand Down

0 comments on commit 352c443

Please sign in to comment.