kward 0.75.0 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +8 -1
- data/CHANGELOG.md +48 -0
- data/Gemfile.lock +2 -2
- data/README.md +12 -4
- data/doc/agent-tools.md +0 -3
- data/doc/api.md +4 -0
- data/doc/composer.md +219 -0
- data/doc/configuration.md +87 -27
- data/doc/editor.md +18 -2
- data/doc/files.md +1 -1
- data/doc/getting-started.md +4 -0
- data/doc/git.md +2 -2
- data/doc/lifecycle-hooks.md +2 -14
- data/doc/pan.md +167 -0
- data/doc/plugins.md +1 -0
- data/doc/rpc.md +3 -22
- data/doc/security.md +180 -0
- data/doc/usage.md +15 -32
- data/lib/kward/agent.rb +5 -0
- data/lib/kward/ansi.rb +2 -2
- data/lib/kward/cancellation.rb +2 -2
- data/lib/kward/cli/commands.rb +1 -3
- data/lib/kward/cli/interactive_turn.rb +3 -17
- data/lib/kward/cli/plugins.rb +2 -7
- data/lib/kward/cli/prompt_interface.rb +10 -17
- data/lib/kward/cli/rendering.rb +7 -3
- data/lib/kward/cli/runtime_helpers.rb +0 -38
- data/lib/kward/cli/sessions.rb +14 -5
- data/lib/kward/cli/settings.rb +22 -0
- data/lib/kward/cli/slash_commands.rb +1 -561
- data/lib/kward/cli/tabs.rb +14 -2
- data/lib/kward/cli.rb +1 -17
- data/lib/kward/cli_transcript_formatter.rb +21 -11
- data/lib/kward/compactor.rb +3 -3
- data/lib/kward/config_files.rb +21 -0
- data/lib/kward/ekwsh.rb +0 -4
- data/lib/kward/events.rb +1 -0
- data/lib/kward/hooks/catalog.rb +0 -5
- data/lib/kward/image_attachments.rb +1 -1
- data/lib/kward/model/client.rb +12 -9
- data/lib/kward/model/model_info.rb +14 -5
- data/lib/kward/model/stream_parser.rb +12 -12
- data/lib/kward/pan/index.html.erb +460 -64
- data/lib/kward/pan/kward_logo.png +0 -0
- data/lib/kward/pan/server.rb +250 -23
- data/lib/kward/plugin_registry.rb +20 -0
- data/lib/kward/prompt_interface/editor/auto_indent.rb +31 -23
- data/lib/kward/prompt_interface/editor/modes/vibe.rb +72 -3
- data/lib/kward/prompt_interface/layout.rb +0 -4
- data/lib/kward/prompt_interface/project_browser.rb +40 -1
- data/lib/kward/prompt_interface/runtime_state.rb +4 -0
- data/lib/kward/prompt_interface/selection_prompt.rb +0 -1
- data/lib/kward/prompt_interface/transcript_renderer.rb +1 -13
- data/lib/kward/prompt_interface.rb +18 -1
- data/lib/kward/prompts/commands.rb +1 -3
- data/lib/kward/prompts.rb +20 -0
- data/lib/kward/rpc/server.rb +14 -42
- data/lib/kward/rpc/session_manager.rb +77 -25
- data/lib/kward/rpc/tool_event_normalizer.rb +2 -0
- data/lib/kward/rpc/tool_metadata.rb +23 -0
- data/lib/kward/rpc/transcript_normalizer.rb +14 -10
- data/lib/kward/session_store.rb +55 -16
- data/lib/kward/skills/registry.rb +21 -1
- data/lib/kward/tools/base.rb +14 -0
- data/lib/kward/tools/registry.rb +11 -16
- data/lib/kward/tools/search/code.rb +1 -1
- data/lib/kward/tools/search/web.rb +1 -1
- data/lib/kward/tools/tool_call.rb +0 -4
- data/lib/kward/transcript_export.rb +1 -1
- data/lib/kward/update_check.rb +12 -7
- data/lib/kward/version.rb +1 -1
- data/templates/default/kward_navigation.rb +5 -1
- data/templates/default/layout/html/layout.erb +0 -2
- metadata +5 -12
- data/lib/kward/workers/git_guard.rb +0 -93
- data/lib/kward/workers/job.rb +0 -99
- data/lib/kward/workers/live_view.rb +0 -49
- data/lib/kward/workers/manager.rb +0 -328
- data/lib/kward/workers/queue_runner.rb +0 -166
- data/lib/kward/workers/queue_store.rb +0 -112
- data/lib/kward/workers/store.rb +0 -72
- data/lib/kward/workers/tool_policy.rb +0 -23
- data/lib/kward/workers/worker.rb +0 -82
- data/lib/kward/workers/write_lock.rb +0 -38
- data/lib/kward/workers.rb +0 -10
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
require_relative "../agent"
|
|
2
|
-
require_relative "../config_files"
|
|
3
|
-
require_relative "../model/client"
|
|
4
|
-
require_relative "../tools/registry"
|
|
5
|
-
require_relative "../workspace"
|
|
6
|
-
require_relative "git_guard"
|
|
7
|
-
require_relative "tool_policy"
|
|
8
|
-
|
|
9
|
-
module Kward
|
|
10
|
-
module Workers
|
|
11
|
-
# Executes session-backed worker queue jobs one at a time.
|
|
12
|
-
class QueueRunner
|
|
13
|
-
CONTINUE_PROMPT = <<~PROMPT.freeze
|
|
14
|
-
Continue this session as an implementation worker.
|
|
15
|
-
Make the smallest correct change, preserve existing style, and run focused verification when practical.
|
|
16
|
-
Stop when the work is ready for human review.
|
|
17
|
-
PROMPT
|
|
18
|
-
|
|
19
|
-
def initialize(queue_store:, session_store:, client_factory: -> { Client.new }, prompt: nil, workspace_root: Dir.pwd, provider: nil, model: nil, reasoning_effort: nil, git_guard: nil, write_lock: nil)
|
|
20
|
-
@queue_store = queue_store
|
|
21
|
-
@session_store = session_store
|
|
22
|
-
@client_factory = client_factory
|
|
23
|
-
@prompt = prompt
|
|
24
|
-
@workspace_root = ConfigFiles.canonical_workspace_root(workspace_root)
|
|
25
|
-
@provider = provider
|
|
26
|
-
@model = model
|
|
27
|
-
@reasoning_effort = reasoning_effort
|
|
28
|
-
@git_guard = git_guard || GitGuard.new(root: @workspace_root)
|
|
29
|
-
@write_lock = write_lock
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def run_next
|
|
33
|
-
record = @queue_store.next_queued
|
|
34
|
-
return nil unless record
|
|
35
|
-
|
|
36
|
-
run_job(record)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def run_all
|
|
40
|
-
results = []
|
|
41
|
-
loop do
|
|
42
|
-
record = run_next
|
|
43
|
-
break unless record
|
|
44
|
-
|
|
45
|
-
results << record
|
|
46
|
-
break unless record["status"] == "ready_for_review"
|
|
47
|
-
end
|
|
48
|
-
results
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def suspend(id)
|
|
52
|
-
record = find_job(id)
|
|
53
|
-
raise ArgumentError, "Worker job #{id} is not running" unless record["status"] == "running"
|
|
54
|
-
|
|
55
|
-
stash_ref = stash_worker_changes(record)
|
|
56
|
-
@queue_store.update_status(record.fetch("id"), "suspended", stash_ref: stash_ref, error: "")
|
|
57
|
-
rescue StandardError => e
|
|
58
|
-
@queue_store.update_status(id, "blocked", error: e.message)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def resume(id)
|
|
62
|
-
record = find_job(id)
|
|
63
|
-
raise ArgumentError, "Worker job #{id} is not suspended" unless record["status"] == "suspended"
|
|
64
|
-
|
|
65
|
-
restore_worker_changes(record)
|
|
66
|
-
queued = @queue_store.update_status(record.fetch("id"), "queued", stash_ref: "", error: "")
|
|
67
|
-
run_job(queued, require_clean: false)
|
|
68
|
-
rescue DirtyWorkspaceError => e
|
|
69
|
-
@queue_store.update_status(id, "blocked", error: e.message)
|
|
70
|
-
rescue StandardError => e
|
|
71
|
-
@queue_store.update_status(id, "blocked", error: e.message)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
private
|
|
75
|
-
|
|
76
|
-
def run_job(record, require_clean: true)
|
|
77
|
-
id = record.fetch("id")
|
|
78
|
-
ensure_clean_workspace!(record) if require_clean
|
|
79
|
-
@queue_store.update_status(id, "running", error: "")
|
|
80
|
-
session, conversation = load_job_session(record)
|
|
81
|
-
agent = Agent.new(client: @client_factory.call, tool_registry: tool_registry(record, id), conversation: conversation)
|
|
82
|
-
report = agent.ask(CONTINUE_PROMPT)
|
|
83
|
-
commit = commit_if_needed(record)
|
|
84
|
-
session.append_message({ role: "assistant", content: completion_report(report, commit) }) if commit
|
|
85
|
-
@queue_store.update_status(id, "ready_for_review", commit_sha: commit, error: "")
|
|
86
|
-
rescue DirtyWorkspaceError => e
|
|
87
|
-
@queue_store.update_status(id, "blocked", error: e.message)
|
|
88
|
-
rescue StandardError => e
|
|
89
|
-
@queue_store.update_status(id, "failed", error: e.message)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def ensure_clean_workspace!(record)
|
|
93
|
-
return unless @git_guard.repository?
|
|
94
|
-
return if @git_guard.clean?
|
|
95
|
-
|
|
96
|
-
raise DirtyWorkspaceError, "Workspace is dirty; clean or stash changes before running worker #{record.fetch('id')}"
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def find_job(id)
|
|
100
|
-
@queue_store.find(id) || raise(ArgumentError, "Unknown worker job: #{id}")
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def stash_worker_changes(record)
|
|
104
|
-
return "" unless @git_guard.repository?
|
|
105
|
-
return "" if @git_guard.clean?
|
|
106
|
-
|
|
107
|
-
result = @git_guard.stash("Kward worker #{record.fetch('id')}: #{record.fetch('title')}")
|
|
108
|
-
raise "Worker changes could not be stashed: #{result.output}" unless result.success?
|
|
109
|
-
|
|
110
|
-
result.commit.to_s
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def restore_worker_changes(record)
|
|
114
|
-
ensure_clean_workspace!(record)
|
|
115
|
-
ref = record["stash_ref"].to_s
|
|
116
|
-
return if ref.empty?
|
|
117
|
-
|
|
118
|
-
apply = @git_guard.apply_stash(ref)
|
|
119
|
-
raise "Worker stash could not be restored: #{apply.output}" unless apply.success?
|
|
120
|
-
|
|
121
|
-
drop = @git_guard.drop_stash(ref)
|
|
122
|
-
raise "Worker stash could not be dropped: #{drop.output}" unless drop.success?
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def load_job_session(record)
|
|
126
|
-
@session_store.load(
|
|
127
|
-
record.fetch("session_path"),
|
|
128
|
-
workspace: Workspace.new(root: record["workspace_root"] || @workspace_root),
|
|
129
|
-
provider: @provider,
|
|
130
|
-
model: @model,
|
|
131
|
-
reasoning_effort: @reasoning_effort
|
|
132
|
-
)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def tool_registry(record, writer_id)
|
|
136
|
-
ToolRegistry.new(
|
|
137
|
-
workspace: Workspace.new(root: record["workspace_root"] || @workspace_root),
|
|
138
|
-
prompt: @prompt,
|
|
139
|
-
allowed_tool_names: ToolPolicy.allowed_tool_names("implementation"),
|
|
140
|
-
write_lock: @write_lock,
|
|
141
|
-
writer_id: writer_id
|
|
142
|
-
)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def commit_if_needed(record)
|
|
146
|
-
return nil unless @git_guard.repository?
|
|
147
|
-
return nil if @git_guard.clean?
|
|
148
|
-
|
|
149
|
-
result = @git_guard.commit_all(commit_message(record))
|
|
150
|
-
raise "Worker changed files but commit failed: #{result.output}" unless result.success?
|
|
151
|
-
|
|
152
|
-
result.commit
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def commit_message(record)
|
|
156
|
-
"Kward worker #{record.fetch('id')}: #{record.fetch('title')}"
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def completion_report(report, commit)
|
|
160
|
-
[report, "", "Committed workspace changes: #{commit}"].join("\n")
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
class DirtyWorkspaceError < StandardError; end
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
end
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
require "fileutils"
|
|
2
|
-
require "json"
|
|
3
|
-
require_relative "../config_files"
|
|
4
|
-
require_relative "job"
|
|
5
|
-
|
|
6
|
-
module Kward
|
|
7
|
-
module Workers
|
|
8
|
-
# JSON-backed queue store for session-backed worker jobs.
|
|
9
|
-
class QueueStore
|
|
10
|
-
def initialize(path: File.join(ConfigFiles.config_dir, "worker_queue.json"))
|
|
11
|
-
@path = path
|
|
12
|
-
@mutex = Mutex.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
attr_reader :path
|
|
16
|
-
|
|
17
|
-
def enqueue(title:, session_path:, workspace_root:, id: nil)
|
|
18
|
-
job = Job.new(
|
|
19
|
-
id: id || SecureRandom.hex(4),
|
|
20
|
-
title: title,
|
|
21
|
-
session_path: session_path,
|
|
22
|
-
workspace_root: workspace_root,
|
|
23
|
-
position: next_position
|
|
24
|
-
)
|
|
25
|
-
upsert(job)
|
|
26
|
-
job
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def upsert(job)
|
|
30
|
-
record = job.respond_to?(:to_h) ? job.to_h : job.to_h
|
|
31
|
-
update_records do |records|
|
|
32
|
-
index = records.index { |item| item["id"] == record["id"] }
|
|
33
|
-
index ? records[index] = record : records << record
|
|
34
|
-
normalize_positions(records)
|
|
35
|
-
end
|
|
36
|
-
record
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def list(include_archived: false)
|
|
40
|
-
records = read_records
|
|
41
|
-
records = records.reject { |record| record["status"] == "archived" } unless include_archived
|
|
42
|
-
sorted(records)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def find(id)
|
|
46
|
-
read_records.find { |record| record["id"] == id.to_s }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def update_status(id, status, **values)
|
|
50
|
-
record = nil
|
|
51
|
-
update_records do |records|
|
|
52
|
-
index = records.index { |item| item["id"] == id.to_s }
|
|
53
|
-
raise ArgumentError, "Unknown worker job: #{id}" unless index
|
|
54
|
-
|
|
55
|
-
job = Job.from_h(records[index])
|
|
56
|
-
job.update_status(status, **values)
|
|
57
|
-
record = job.to_h
|
|
58
|
-
records[index] = record
|
|
59
|
-
normalize_positions(records)
|
|
60
|
-
end
|
|
61
|
-
record
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def archive(id)
|
|
65
|
-
update_status(id, "archived")
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def next_queued
|
|
69
|
-
list.find { |record| record["status"] == "queued" }
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
private
|
|
73
|
-
|
|
74
|
-
def next_position
|
|
75
|
-
last = list(include_archived: true).map { |record| record["position"].to_i }.max
|
|
76
|
-
last ? last + 1 : 1
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def read_records
|
|
80
|
-
@mutex.synchronize { read_records_unlocked }
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def read_records_unlocked
|
|
84
|
-
return [] unless File.exist?(@path)
|
|
85
|
-
|
|
86
|
-
data = JSON.parse(File.read(@path))
|
|
87
|
-
data.is_a?(Array) ? data : []
|
|
88
|
-
rescue JSON::ParserError
|
|
89
|
-
raise "Invalid worker queue JSON: #{@path}"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def update_records
|
|
93
|
-
@mutex.synchronize do
|
|
94
|
-
records = read_records_unlocked
|
|
95
|
-
yield records
|
|
96
|
-
FileUtils.mkdir_p(File.dirname(@path))
|
|
97
|
-
File.write(@path, JSON.pretty_generate(sorted(records)) + "\n")
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def sorted(records)
|
|
102
|
-
records.sort_by { |record| [record["position"].to_i, record["enqueued_at"].to_s, record["id"].to_s] }
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def normalize_positions(records)
|
|
106
|
-
sorted(records).each_with_index do |record, index|
|
|
107
|
-
record["position"] = index + 1
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
data/lib/kward/workers/store.rb
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
require "fileutils"
|
|
2
|
-
require "json"
|
|
3
|
-
require_relative "../config_files"
|
|
4
|
-
|
|
5
|
-
module Kward
|
|
6
|
-
module Workers
|
|
7
|
-
# JSON-backed metadata store for worker records.
|
|
8
|
-
class Store
|
|
9
|
-
def initialize(path: File.join(ConfigFiles.config_dir, "workers.json"))
|
|
10
|
-
@path = path
|
|
11
|
-
@mutex = Mutex.new
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
attr_reader :path
|
|
15
|
-
|
|
16
|
-
def upsert(worker)
|
|
17
|
-
record = worker.respond_to?(:to_h) ? worker.to_h : worker.to_h
|
|
18
|
-
update_records do |records|
|
|
19
|
-
index = records.index { |item| item["id"] == record["id"] }
|
|
20
|
-
index ? records[index] = record : records << record
|
|
21
|
-
end
|
|
22
|
-
record
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def list(include_archived: false)
|
|
26
|
-
records = read_records
|
|
27
|
-
records = records.reject { |record| record["status"] == "archived" } unless include_archived
|
|
28
|
-
records.sort_by { |record| record["created_at"].to_s }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def find(id)
|
|
32
|
-
read_records.find { |record| record["id"] == id.to_s }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def archive(id)
|
|
36
|
-
record = nil
|
|
37
|
-
update_records do |records|
|
|
38
|
-
index = records.index { |item| item["id"] == id.to_s }
|
|
39
|
-
raise ArgumentError, "Unknown worker: #{id}" unless index
|
|
40
|
-
|
|
41
|
-
record = records[index].merge("status" => "archived")
|
|
42
|
-
records[index] = record
|
|
43
|
-
end
|
|
44
|
-
record
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
private
|
|
48
|
-
|
|
49
|
-
def read_records
|
|
50
|
-
@mutex.synchronize { read_records_unlocked }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def read_records_unlocked
|
|
54
|
-
return [] unless File.exist?(@path)
|
|
55
|
-
|
|
56
|
-
data = JSON.parse(File.read(@path))
|
|
57
|
-
data.is_a?(Array) ? data : []
|
|
58
|
-
rescue JSON::ParserError
|
|
59
|
-
raise "Invalid worker store JSON: #{@path}"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def update_records
|
|
63
|
-
@mutex.synchronize do
|
|
64
|
-
records = read_records_unlocked
|
|
65
|
-
yield records
|
|
66
|
-
FileUtils.mkdir_p(File.dirname(@path))
|
|
67
|
-
File.write(@path, JSON.pretty_generate(records) + "\n")
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module Kward
|
|
2
|
-
module Workers
|
|
3
|
-
# Tool allowlists for worker roles.
|
|
4
|
-
module ToolPolicy
|
|
5
|
-
READ_ONLY_TOOLS = %w[list_directory read_file code_search summarize_file_structure retrieve_tool_output web_search fetch_content fetch_raw read_skill].freeze
|
|
6
|
-
|
|
7
|
-
module_function
|
|
8
|
-
|
|
9
|
-
def allowed_tool_names(role)
|
|
10
|
-
case role.to_s
|
|
11
|
-
when "request", "read_only"
|
|
12
|
-
READ_ONLY_TOOLS
|
|
13
|
-
else
|
|
14
|
-
nil
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def write_capable?(role)
|
|
19
|
-
allowed_tool_names(role).nil?
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
data/lib/kward/workers/worker.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
require "securerandom"
|
|
2
|
-
require "time"
|
|
3
|
-
require_relative "../config_files"
|
|
4
|
-
require_relative "../cancellation"
|
|
5
|
-
|
|
6
|
-
module Kward
|
|
7
|
-
module Workers
|
|
8
|
-
# Runtime record for one independent unit of agent work.
|
|
9
|
-
class Worker
|
|
10
|
-
STATUSES = %w[idle queued running ready failed cancelled archived].freeze
|
|
11
|
-
|
|
12
|
-
def initialize(id: SecureRandom.hex(4), title:, role:, workspace_root: Dir.pwd, status: "idle", prompt: nil, conversation: nil, session: nil, cancellation: Cancellation.new, created_at: Time.now.utc)
|
|
13
|
-
@id = id
|
|
14
|
-
@title = title.to_s
|
|
15
|
-
@role = role.to_s
|
|
16
|
-
@workspace_root = ConfigFiles.canonical_workspace_root(workspace_root)
|
|
17
|
-
@status = status.to_s
|
|
18
|
-
@prompt = prompt.to_s
|
|
19
|
-
@conversation = conversation
|
|
20
|
-
@session = session
|
|
21
|
-
@cancellation = cancellation
|
|
22
|
-
@created_at = created_at
|
|
23
|
-
@updated_at = created_at
|
|
24
|
-
@started_at = nil
|
|
25
|
-
@finished_at = nil
|
|
26
|
-
@report = nil
|
|
27
|
-
@error = nil
|
|
28
|
-
@thread = nil
|
|
29
|
-
@event_history = []
|
|
30
|
-
@event_queue = Queue.new
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
attr_reader :id, :title, :role, :workspace_root, :prompt, :conversation, :session, :cancellation, :created_at, :updated_at, :started_at, :finished_at, :report, :error, :thread, :event_history, :event_queue
|
|
34
|
-
attr_writer :conversation, :session, :thread
|
|
35
|
-
|
|
36
|
-
def status
|
|
37
|
-
@status
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def update_status(status, error: nil, report: nil)
|
|
41
|
-
@status = status.to_s
|
|
42
|
-
@error = error unless error.nil?
|
|
43
|
-
@report = report unless report.nil?
|
|
44
|
-
now = Time.now.utc
|
|
45
|
-
@updated_at = now
|
|
46
|
-
@started_at ||= now if @status == "running"
|
|
47
|
-
@finished_at = now if %w[ready failed cancelled archived].include?(@status)
|
|
48
|
-
self
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def record_event(event)
|
|
52
|
-
@event_history << event
|
|
53
|
-
@event_queue << event
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def to_h
|
|
57
|
-
{
|
|
58
|
-
"id" => id,
|
|
59
|
-
"title" => title,
|
|
60
|
-
"role" => role,
|
|
61
|
-
"status" => status,
|
|
62
|
-
"prompt" => prompt,
|
|
63
|
-
"workspace_root" => workspace_root,
|
|
64
|
-
"session_id" => session&.id,
|
|
65
|
-
"session_path" => session&.path,
|
|
66
|
-
"created_at" => timestamp(created_at),
|
|
67
|
-
"updated_at" => timestamp(updated_at),
|
|
68
|
-
"started_at" => timestamp(started_at),
|
|
69
|
-
"finished_at" => timestamp(finished_at),
|
|
70
|
-
"report" => report,
|
|
71
|
-
"error" => error
|
|
72
|
-
}
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
private
|
|
76
|
-
|
|
77
|
-
def timestamp(value)
|
|
78
|
-
value&.utc&.iso8601(3)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require "thread"
|
|
2
|
-
|
|
3
|
-
module Kward
|
|
4
|
-
module Workers
|
|
5
|
-
# Cooperative ownership guard for workspace-mutating worker tools.
|
|
6
|
-
class WriteLock
|
|
7
|
-
def initialize
|
|
8
|
-
@owner_id = nil
|
|
9
|
-
@mutex = Mutex.new
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
attr_reader :owner_id
|
|
13
|
-
|
|
14
|
-
def acquire(owner_id)
|
|
15
|
-
owner = owner_id.to_s
|
|
16
|
-
return false if owner.empty?
|
|
17
|
-
|
|
18
|
-
@mutex.synchronize do
|
|
19
|
-
return true if @owner_id == owner
|
|
20
|
-
return false if @owner_id
|
|
21
|
-
|
|
22
|
-
@owner_id = owner
|
|
23
|
-
true
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def owned_by?(owner_id)
|
|
28
|
-
@mutex.synchronize { @owner_id == owner_id.to_s }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def release(owner_id)
|
|
32
|
-
@mutex.synchronize do
|
|
33
|
-
@owner_id = nil if @owner_id == owner_id.to_s
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
data/lib/kward/workers.rb
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
require_relative "workers/git_guard"
|
|
2
|
-
require_relative "workers/job"
|
|
3
|
-
require_relative "workers/live_view"
|
|
4
|
-
require_relative "workers/manager"
|
|
5
|
-
require_relative "workers/queue_runner"
|
|
6
|
-
require_relative "workers/queue_store"
|
|
7
|
-
require_relative "workers/store"
|
|
8
|
-
require_relative "workers/tool_policy"
|
|
9
|
-
require_relative "workers/write_lock"
|
|
10
|
-
require_relative "workers/worker"
|