ace-overseer 0.23.0 → 0.25.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.ace-defaults/overseer/config.yml +9 -0
  3. data/CHANGELOG.md +24 -804
  4. data/README.md +60 -42
  5. data/docs/getting-started.md +9 -4
  6. data/docs/handbook.md +1 -18
  7. data/docs/usage.md +297 -209
  8. data/handbook/workflow-instructions/overseer/queue.wf.md +210 -0
  9. data/handbook/workflow-instructions/overseer.wf.md +17 -32
  10. data/lib/ace/overseer/atoms/dependency_readiness.rb +48 -0
  11. data/lib/ace/overseer/atoms/handoff_readiness.rb +75 -0
  12. data/lib/ace/overseer/atoms/report_interpretation.rb +236 -0
  13. data/lib/ace/overseer/atoms/status_formatter.rb +0 -1
  14. data/lib/ace/overseer/cli/commands/handoff.rb +69 -0
  15. data/lib/ace/overseer/cli/commands/process_reports.rb +50 -0
  16. data/lib/ace/overseer/cli/commands/prune.rb +3 -50
  17. data/lib/ace/overseer/cli/commands/status.rb +8 -55
  18. data/lib/ace/overseer/cli/commands/work_on.rb +6 -50
  19. data/lib/ace/overseer/cli.rb +10 -14
  20. data/lib/ace/overseer/models/assignment_prune_candidate.rb +5 -5
  21. data/lib/ace/overseer/models/prune_candidate.rb +5 -5
  22. data/lib/ace/overseer/molecules/assignment_prune_safety_checker.rb +22 -84
  23. data/lib/ace/overseer/molecules/git_preservation_checker.rb +33 -21
  24. data/lib/ace/overseer/molecules/handoff_probe.rb +101 -0
  25. data/lib/ace/overseer/molecules/hitl_inbox.rb +43 -0
  26. data/lib/ace/overseer/molecules/prune_safety_checker.rb +43 -88
  27. data/lib/ace/overseer/molecules/worktree_context_collector.rb +4 -18
  28. data/lib/ace/overseer/organisms/handoff_orchestrator.rb +122 -0
  29. data/lib/ace/overseer/organisms/prune_orchestrator.rb +2 -2
  30. data/lib/ace/overseer/organisms/report_processor.rb +241 -0
  31. data/lib/ace/overseer/organisms/status_attention.rb +306 -0
  32. data/lib/ace/overseer/organisms/status_collector.rb +267 -3
  33. data/lib/ace/overseer/organisms/status_sources.rb +276 -0
  34. data/lib/ace/overseer/organisms/work_on_orchestrator.rb +49 -9
  35. data/lib/ace/overseer/version.rb +1 -1
  36. data/lib/ace/overseer.rb +12 -1
  37. metadata +46 -27
  38. data/handbook/skills/as-overseer-configure-project/SKILL.md +0 -32
  39. data/handbook/workflow-instructions/overseer/configure-project.wf.md +0 -238
  40. data/handbook/workflow-instructions/overseer/maintain-continuation.wf.md +0 -115
  41. data/handbook/workflow-instructions/roles/lab-coordinator.wf.md +0 -106
  42. data/handbook/workflow-instructions/roles/project-overseer.wf.md +0 -182
  43. data/handbook/workflow-instructions/roles/second-commander.wf.md +0 -95
  44. data/lib/ace/overseer/cli/commands/ordinary.rb +0 -37
  45. data/lib/ace/overseer/cli/commands/prompt.rb +0 -63
  46. data/lib/ace/overseer/cli/commands/review.rb +0 -44
  47. data/lib/ace/overseer/cli/commands/stop.rb +0 -33
  48. data/lib/ace/overseer/molecules/launch_request.rb +0 -216
  49. data/lib/ace/overseer/molecules/original_launch_child.rb +0 -165
  50. data/lib/ace/overseer/molecules/proposal_tick.rb +0 -56
  51. data/lib/ace/overseer/molecules/protected_selection.rb +0 -46
  52. data/lib/ace/overseer/organisms/launch_recovery.rb +0 -65
  53. data/lib/ace/overseer/organisms/ordinary_work_on.rb +0 -186
  54. data/lib/ace/overseer/organisms/protected_prune.rb +0 -116
  55. data/lib/ace/overseer/organisms/protected_review.rb +0 -167
  56. data/lib/ace/overseer/organisms/protected_status.rb +0 -157
  57. data/lib/ace/overseer/organisms/protected_steering.rb +0 -78
  58. data/lib/ace/overseer/organisms/protected_work_on.rb +0 -102
@@ -3,38 +3,25 @@
3
3
  module Ace
4
4
  module Overseer
5
5
  module Molecules
6
- # Fail-closed safety classification for assignment cache pruning.
6
+ # Fail-closed safety classification for local assignment cache pruning.
7
7
  #
8
- # The cache directory of an assignment is disposable only when its
9
- # durable evidence survives outside the deletion target and every
10
- # attempt is provably terminal:
8
+ # The cache directory of an assignment is disposable only when the
9
+ # local assignment record is terminal:
11
10
  #
12
11
  # - the queue label must read completed (never proof by itself),
13
- # - recorded attempts must be terminal — active or uncertain attempts
14
- # block, and unreadable attempt state blocks,
15
- # - managed assignments must carry their durable evidence in
16
- # refs/ace/execution; a missing or unreadable evidence ref blocks,
17
- # and journal-derived active/uncertain attempts block even when the
18
- # local records were lost.
12
+ # - the local step summary must show no active or pending steps; an
13
+ # unreadable summary blocks.
19
14
  #
20
- # The journal checkout and the evidence ref are never deletion targets:
21
- # cleanup removes only the assignment cache directory.
15
+ # Assignment state lives in `.ace-local/assign/`; no journal, attempt or
16
+ # authority store participates in this decision.
22
17
  class AssignmentPruneSafetyChecker
23
- def initialize(assignment_discoverer_factory: nil, assignment_manager_factory: nil,
24
- journal_factory: nil)
18
+ def initialize(assignment_discoverer_factory: nil)
25
19
  @assignment_discoverer_factory = assignment_discoverer_factory || -> { Ace::Assign::Molecules::AssignmentDiscoverer.new }
26
- @assignment_manager_factory = assignment_manager_factory || -> { Ace::Assign::Molecules::AssignmentManager.new }
27
- @journal_factory = journal_factory || -> {
28
- Ace::Assign::Molecules::EvidenceJournal.new(
29
- repo_root: Ace::Support::Fs::Molecules::ProjectRootFinder.find_or_current
30
- )
31
- }
32
20
  end
33
21
 
34
22
  def check(assignment_id:)
35
23
  discoverer = @assignment_discoverer_factory.call
36
- all = discoverer.find_all(include_completed: true)
37
- info = all.find { |ai| ai.assignment.id == assignment_id }
24
+ info = discoverer.find_all(include_completed: true).find { |ai| ai.assignment.id == assignment_id }
38
25
 
39
26
  unless info
40
27
  return Models::AssignmentPruneCandidate.new(
@@ -42,7 +29,7 @@ module Ace
42
29
  assignment_name: "",
43
30
  assignment_state: "not_found",
44
31
  location_path: "",
45
- attempts_terminal: false,
32
+ work_terminal: false,
46
33
  reasons: ["assignment not found"]
47
34
  )
48
35
  end
@@ -51,83 +38,34 @@ module Ace
51
38
  reasons = []
52
39
  reasons << "assignment still #{state}" unless state == "completed"
53
40
 
54
- attempts_terminal, attempt_reasons = attempts_evidence(info.assignment, assignment_id)
55
- reasons.concat(attempt_reasons)
41
+ work_terminal, work_reasons = terminal_work(info)
42
+ reasons.concat(work_reasons)
56
43
 
57
44
  Models::AssignmentPruneCandidate.new(
58
45
  assignment_id: assignment_id,
59
46
  assignment_name: info.assignment.name,
60
47
  assignment_state: state,
61
48
  location_path: info.assignment.cache_dir,
62
- attempts_terminal: attempts_terminal,
49
+ work_terminal: work_terminal,
63
50
  reasons: reasons
64
51
  )
65
52
  end
66
53
 
67
54
  private
68
55
 
69
- def attempts_evidence(assignment, assignment_id)
70
- managed = begin
71
- assignment.managed?
72
- rescue => e
73
- return [false, ["assignment lifecycle state unreadable: #{e.message}"]]
74
- end
75
-
76
- reasons = []
77
- local_terminal, local_reasons = local_attempts(assignment_id)
78
- reasons.concat(local_reasons)
79
-
80
- if managed
81
- journal_terminal, journal_reasons = journal_evidence(assignment_id)
82
- reasons.concat(journal_reasons)
83
- [local_terminal && journal_terminal, reasons]
84
- else
85
- [local_terminal, reasons]
86
- end
87
- end
88
-
89
- def local_attempts(assignment_id)
90
- attempts = @assignment_manager_factory.call.attempts(assignment_id)
91
- terminal = true
92
- reasons = []
93
- attempts.each do |attempt|
94
- next unless attempt.active? || attempt.uncertain?
95
-
96
- terminal = false
97
- reasons << "attempt #{attempt.attempt_id} is #{attempt.state}"
56
+ def terminal_work(info)
57
+ summary = info.queue_state.summary
58
+ unless summary.is_a?(Hash)
59
+ return [false, ["assignment step state unreadable"]]
98
60
  end
99
- [terminal, reasons]
100
- rescue => e
101
- [false, ["attempt state unreadable: #{e.message}"]]
102
- end
103
61
 
104
- # The journal is the durable evidence outside the deletion target:
105
- # managed cleanup requires THIS assignment's journaled attempt
106
- # history to exist and to agree that no attempt is active or
107
- # uncertain (an empty journal carries no evidence at all).
108
- def journal_evidence(assignment_id)
109
- journal = @journal_factory.call
110
- ref_value = journal.ref_value
111
- if ref_value.nil?
112
- return [false, ["no durable evidence ref for managed assignment #{assignment_id}"]]
113
- end
62
+ active = summary[:active].to_i
63
+ pending = summary[:pending].to_i
64
+ return [true, []] if active.zero? && pending.zero?
114
65
 
115
- derived = journal.derived_attempts(assignment_id)
116
- if derived.empty?
117
- return [false, ["no durable attempt evidence for managed assignment #{assignment_id} in the journal"]]
118
- end
119
-
120
- terminal = true
121
- reasons = []
122
- derived.each do |attempt|
123
- next unless attempt.active? || attempt.uncertain?
124
-
125
- terminal = false
126
- reasons << "journaled attempt #{attempt.attempt_id} is #{attempt.state}"
127
- end
128
- [terminal, reasons]
66
+ [false, ["assignment has #{active} active and #{pending} pending step(s)"]]
129
67
  rescue => e
130
- [false, ["durable evidence unreadable: #{e.message}"]]
68
+ [false, ["assignment step state unreadable: #{e.message}"]]
131
69
  end
132
70
  end
133
71
  end
@@ -16,9 +16,11 @@ module Ace
16
16
  # whose content matches by full-tree equality or by an exact
17
17
  # path-by-path transition (modes, symlinks, binary content) between
18
18
  # separate source and destination bases. Patch-range proof requires
19
- # the independently recorded creation baseline (qjl base_head); a
20
- # missing or mismatching baseline disables it. The baseline itself
21
- # must be preserved on a surviving accepted ref.
19
+ # the declared source_base to equal the Git-derived fork point
20
+ # (merge-base of the candidate head and the accepted base tip): a
21
+ # declared base newer than the fork point could hide candidate work
22
+ # and blocks. The declared source_base must also be preserved on a
23
+ # surviving accepted ref.
22
24
  #
23
25
  # Everything else — missing, failed or ambiguous evidence — blocks.
24
26
  # All Git access is argv-based; no refs are fetched into any repo.
@@ -63,12 +65,10 @@ module Ace
63
65
  # @param accepted_base [Hash, nil] `{branch:, head:}` surviving base
64
66
  # @param manifest_record [PreservationManifest::Record, nil] Declared
65
67
  # destination (a claim; verified here)
66
- # @param recorded_base [String, nil] Independently recorded creation
67
- # baseline (attempt base_head), outside the manifest
68
68
  # @param candidate_branch [String, nil] The candidate's own branch,
69
69
  # scheduled for deletion with the worktree
70
70
  # @return [Models::PreservationProof]
71
- def proof(worktree_path:, accepted_base:, manifest_record: nil, recorded_base: nil, candidate_branch: nil)
71
+ def proof(worktree_path:, accepted_base:, manifest_record: nil, candidate_branch: nil)
72
72
  live_head = rev_parse(worktree_path, "--verify", "HEAD")
73
73
  return blocked("cannot resolve candidate HEAD") if live_head.nil?
74
74
 
@@ -82,7 +82,7 @@ module Ace
82
82
  return blocked("HEAD #{live_head[0, 12]} is not contained in accepted base " \
83
83
  "#{accepted_base[:branch]} (#{accepted_base[:head][0, 12]}) and no destination is declared") if manifest_record.nil?
84
84
 
85
- proof_via_destination(worktree_path, live_head, accepted_base, manifest_record, recorded_base, candidate_branch)
85
+ proof_via_destination(worktree_path, live_head, accepted_base, manifest_record, candidate_branch)
86
86
  end
87
87
 
88
88
  # Prove preservation for a static identity that has no local
@@ -108,7 +108,7 @@ module Ace
108
108
 
109
109
  private
110
110
 
111
- def proof_via_destination(worktree_path, live_head, accepted_base, record, recorded_base, candidate_branch)
111
+ def proof_via_destination(worktree_path, live_head, accepted_base, record, candidate_branch)
112
112
  identity_failure = verify_source_identity(worktree_path, live_head, record)
113
113
  return identity_failure if identity_failure
114
114
 
@@ -121,19 +121,12 @@ module Ace
121
121
  tree_proof = tree_equality_proof(record)
122
122
  return tree_proof if tree_proof&.preserved?
123
123
 
124
- unless patch_proof_allowed?(record, recorded_base)
125
- if recorded_base.nil?
126
- return blocked("patch-range proof is disabled: no independently recorded creation baseline " \
127
- "(attempt base_head) is available to authorize the declared source range")
128
- end
129
-
130
- return blocked("declared source_base does not match the recorded creation baseline " \
131
- "#{recorded_base[0, 12]}")
132
- end
133
-
134
124
  range_failure = verify_range(record)
135
125
  return range_failure if range_failure
136
126
 
127
+ fork_failure = verify_fork_point(record, accepted_base)
128
+ return fork_failure if fork_failure
129
+
137
130
  unless ancestry?(record.source_repo, record.resolved_source_base, accepted_base[:head])
138
131
  return blocked("declared source baseline #{record.source_base[0, 12]} itself is not preserved on " \
139
132
  "accepted base #{accepted_base[:branch]}; patch-range proof cannot discard it")
@@ -171,10 +164,24 @@ module Ace
171
164
  end
172
165
  end
173
166
 
174
- def patch_proof_allowed?(record, recorded_base)
175
- return false if recorded_base.nil?
167
+ # The Git-derived creation baseline: the fork point of the candidate
168
+ # head and the surviving accepted base tip. A manifest may declare a
169
+ # patch range only from that exact commit; a newer declared base could
170
+ # exclude candidate commits from the range and hide unpreserved work.
171
+ def verify_fork_point(record, accepted_base)
172
+ fork_point = merge_base(record.source_repo, record.resolved_source_head, accepted_base[:head])
173
+ if fork_point.nil? || fork_point.empty?
174
+ return blocked("cannot resolve the Git fork point between candidate head " \
175
+ "#{record.resolved_source_head[0, 12]} and accepted base #{accepted_base[:branch]} " \
176
+ "(#{accepted_base[:head][0, 12]}); patch-range proof requires a Git-derived creation baseline")
177
+ end
176
178
 
177
- recorded_base == record.resolved_source_base
179
+ return nil if record.resolved_source_base == fork_point
180
+
181
+ blocked("declared source_base #{record.source_base[0, 12]} is not the Git-derived fork point " \
182
+ "#{fork_point[0, 12]} of candidate head #{record.resolved_source_head[0, 12]} and accepted base " \
183
+ "#{accepted_base[:branch]}; a declared base newer than the fork point could hide candidate work, " \
184
+ "so patch-range proof is blocked (use full-tree equality or declare the true fork point)")
178
185
  end
179
186
 
180
187
  # A destination that IS the candidate's own branch ref is scheduled
@@ -289,6 +296,11 @@ module Ace
289
296
  status.success? ? stdout.to_s.strip.to_i : nil
290
297
  end
291
298
 
299
+ def merge_base(repo, left, right)
300
+ stdout, _stderr, status = git_runner.call(repo, "merge-base", left, right)
301
+ status.success? ? stdout.to_s.strip : nil
302
+ end
303
+
292
304
  def ancestry?(repo, revision, base)
293
305
  _stdout, _stderr, status = git_runner.call(repo, "merge-base", "--is-ancestor", revision, base)
294
306
  status.success?
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Ace
6
+ module Overseer
7
+ module Molecules
8
+ # Read-only probe of a task worktree's handoff truth (L6.4): the
9
+ # ordered role-sequence legs for the task (ace-assign's own
10
+ # assignment files, ordered by creation — the order the planner
11
+ # composed them in), each leg's real assignment state, the role of
12
+ # each leg (from the per-role start configs ace-coworker prepare
13
+ # wrote), and the worktree's executor truth (commissioned config +
14
+ # assignment inventory) via the SAME coworker probe/ rule prepare
15
+ # uses — one active-executor concept, no second copy. Writes
16
+ # nothing; owns no state (ADR-034).
17
+ class HandoffProbe
18
+ ASSIGN_DIR = File.join(".ace-local", "assign")
19
+ # Reuse the coworker-owned location constant: one definition of
20
+ # where prepare writes per-role start configs.
21
+ PREPARE_DIR = Ace::Coworker::Organisms::StartConfigWriter::PREPARE_DIR
22
+
23
+ # @param executor_probe [#probe] WorktreeExecutorProbe-compatible
24
+ # seam (defaults to the coworker probe anchored at the probed
25
+ # worktree)
26
+ def initialize(executor_probe: nil)
27
+ @executor_probe = executor_probe
28
+ end
29
+
30
+ # @param worktree_path [String] the task worktree
31
+ # @param task_id [String] canonical task id
32
+ # @return [Hash] {legs: Array<{"role" => String|nil,
33
+ # "assignment" => String, "name" => String, "state" => String}>,
34
+ # executor: {config:, assignments:}} in sequence order
35
+ # @raise [Error] when the assignment inventory cannot be read
36
+ def probe(worktree_path, task_id:)
37
+ executor = executor_probe(worktree_path).probe(worktree_path)
38
+ states = executor[:assignments].to_h { |a| [a["id"].to_s, a["state"].to_s] }
39
+ roles = prepare_roles(worktree_path)
40
+
41
+ legs = sequence_assignments(worktree_path, task_id).map do |record|
42
+ mapping = roles[record["id"]] || {}
43
+ {
44
+ "role" => mapping["role"],
45
+ "start_config" => mapping["start_config"],
46
+ "assignment" => record["id"],
47
+ "name" => record["name"],
48
+ "state" => states.fetch(record["id"], "")
49
+ }
50
+ end
51
+ {legs: legs, executor: executor}
52
+ end
53
+
54
+ private
55
+
56
+ def executor_probe(worktree_path)
57
+ @executor_probe || Ace::Coworker::Molecules::WorktreeExecutorProbe.new(project_root: worktree_path)
58
+ end
59
+
60
+ # The task's role-sequence assignments from ace-assign's own
61
+ # files ("<task>-<role>" with task_id), in composition order
62
+ # (created_at, then id as a stable tie-breaker).
63
+ def sequence_assignments(worktree_path, task_id)
64
+ Dir.glob(File.join(worktree_path, ASSIGN_DIR, "*", "assignment.yaml")).filter_map do |path|
65
+ data = YAML.safe_load_file(path, permitted_classes: [Time, Date], aliases: true) || {}
66
+ next unless data.is_a?(Hash) && data["task_id"].to_s == task_id
67
+
68
+ {"id" => File.basename(File.dirname(path)), "name" => data["name"].to_s,
69
+ "created_at" => data["created_at"]}
70
+ end.sort_by { |record| [record["created_at"].to_s, record["id"]] }
71
+ end
72
+
73
+ # assignment id -> {"role" =>, "start_config" => relative path},
74
+ # from the per-leg start configs
75
+ # (.ace-local/coworker/prepare/<role>.yml). An unreadable config,
76
+ # or one without BOTH a non-empty assignment id and a non-empty
77
+ # role, contributes nothing: its leg keeps role nil and the
78
+ # handoff gate refuses to start it instead of guessing. The
79
+ # carried start_config is the actually-globbed file path, so a
80
+ # ready verdict can never point at a nonexistent config.
81
+ def prepare_roles(worktree_path)
82
+ Dir.glob(File.join(worktree_path, PREPARE_DIR, "*.yml")).filter_map do |path|
83
+ data = begin
84
+ YAML.safe_load_file(path, permitted_classes: [Date], aliases: true)
85
+ rescue StandardError
86
+ next
87
+ end
88
+ next unless data.is_a?(Hash)
89
+
90
+ assignment = data["assignment"].to_s
91
+ role = data["role"].to_s
92
+ next if assignment.empty? || role.strip.empty?
93
+
94
+ [assignment, {"role" => role,
95
+ "start_config" => File.join(PREPARE_DIR, File.basename(path))}]
96
+ end.to_h
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ace
4
+ module Overseer
5
+ module Molecules
6
+ # Read-only gateway to the overseer's incoming ace-hitl events
7
+ # (L6.5). ace-hitl owns its files; this molecule only lists events
8
+ # and normalizes them into plain hashes for the interpretation
9
+ # atom. Reports carry status "recorded", questions stay "pending"
10
+ # until answered — both are the overseer's inbox.
11
+ class HitlInbox
12
+ # @param manager [Ace::Hitl::Organisms::HitlManager, nil]
13
+ def initialize(manager: nil)
14
+ @manager = manager || Ace::Hitl::Organisms::HitlManager.new
15
+ end
16
+
17
+ # @return [Array<Hash>] {"id","type","result","task","assignment",
18
+ # "title"} sorted oldest-first. Only the keys the interpretation
19
+ # atom matches on are carried: assignment, then the managing
20
+ # task's project_task.
21
+ def incoming_events
22
+ reports = @manager.list(in_folder: "next", type: "report")
23
+ questions = @manager.list(in_folder: "next", type: "question", status: "pending")
24
+
25
+ (reports + questions).sort_by { |event| event.created_at || Time.now }.map { |event| normalize(event) }
26
+ end
27
+
28
+ private
29
+
30
+ def normalize(event)
31
+ {
32
+ "id" => event.id,
33
+ "type" => event.type,
34
+ "result" => event.result,
35
+ "task" => event.metadata["task"],
36
+ "assignment" => event.metadata["assignment"],
37
+ "title" => event.title
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -8,26 +8,24 @@ module Ace
8
8
  # Classifies one worktree candidate for prune, fail-closed.
9
9
  #
10
10
  # A candidate is safe only when ALL of the following hold:
11
- # - the assignment queue label is completed,
11
+ # - every local assignment is completed,
12
12
  # - the task is done (a missing task record alone proves nothing but
13
13
  # never authorizes removal by itself),
14
14
  # - the checkout is clean including untracked files (dirty tracked AND
15
15
  # untracked files are work; --force never overrides this),
16
- # - required ignored artifacts are preserved: a local evidence journal
17
- # checkout must already be contained in refs/ace/execution,
18
- # - all recorded attempts are terminal (active or uncertain attempts
19
- # and unreadable attempt state block),
16
+ # - no local assignment step is active or pending (unreadable local
17
+ # work state blocks),
20
18
  # - an executed preservation proof passes (accepted ancestry or a
21
19
  # verified declared destination).
20
+ #
21
+ # Local state only: assignment records under `.ace-local/assign/`, task
22
+ # records under `.ace-tasks/`, and Git. No journal, attempt or authority
23
+ # store participates in this classification.
22
24
  class PruneSafetyChecker
23
- def initialize(context_collector: nil, task_loader_factory: nil, preservation_checker: nil,
24
- attempt_store_factory: nil)
25
+ def initialize(context_collector: nil, task_loader_factory: nil, preservation_checker: nil)
25
26
  @context_collector = context_collector || WorktreeContextCollector.new
26
27
  @task_loader_factory = task_loader_factory || -> { Ace::Task::Organisms::TaskManager.new }
27
28
  @preservation_checker = preservation_checker || GitPreservationChecker.new
28
- @attempt_store_factory = attempt_store_factory || ->(cache_base) {
29
- Ace::Assign::Molecules::AttemptStore.new(cache_base: cache_base)
30
- }
31
29
  end
32
30
 
33
31
  attr_reader :preservation_checker
@@ -41,11 +39,10 @@ module Ace
41
39
  def check(worktree_path:, task_ref:, manifest_record: nil, accepted_base: nil)
42
40
  context = @context_collector.collect(worktree_path)
43
41
 
44
- assignment_complete = assignment_complete?(context.assignment_status)
42
+ assignment_complete = assignment_complete?(context.assignments)
43
+ work_terminal, work_reasons = work_terminal?(context.assignments)
45
44
  task_done = task_done?(worktree_path, task_ref)
46
45
  git_clean = git_clean_for_prune?(worktree_path)
47
- artifacts_safe, artifact_reasons = required_ignored_artifacts_safe?(worktree_path)
48
- attempts_terminal, attempt_reasons, recorded_base = attempts_evidence(worktree_path, context)
49
46
  # One branch identity for the whole check: read before the proof,
50
47
  # handed to the proof as the candidate's own branch, and verified
51
48
  # downstream. A later read could name a switched-to destination.
@@ -54,7 +51,6 @@ module Ace
54
51
  worktree_path: worktree_path,
55
52
  accepted_base: accepted_base,
56
53
  manifest_record: manifest_record,
57
- recorded_base: recorded_base,
58
54
  candidate_branch: branch_at_check
59
55
  )
60
56
  # The HEAD and branch whose preservation was actually proven:
@@ -69,8 +65,7 @@ module Ace
69
65
  reasons << "assignment not complete" unless assignment_complete
70
66
  reasons << "task not done" unless task_done
71
67
  reasons << "git not clean" unless git_clean
72
- reasons.concat(artifact_reasons)
73
- reasons.concat(attempt_reasons)
68
+ reasons.concat(work_reasons)
74
69
  reasons << "preservation not proven: #{proof.reason}" unless proof.preserved?
75
70
 
76
71
  Models::PruneCandidate.new(
@@ -79,7 +74,7 @@ module Ace
79
74
  assignment_complete: assignment_complete,
80
75
  task_done: task_done,
81
76
  git_clean: git_clean,
82
- attempts_terminal: attempts_terminal && artifacts_safe,
77
+ work_terminal: work_terminal,
83
78
  preserved: proof.preserved?,
84
79
  verified_head: verified_head,
85
80
  verified_branch: verified_branch,
@@ -89,10 +84,35 @@ module Ace
89
84
 
90
85
  private
91
86
 
92
- def assignment_complete?(assignment_status)
93
- return false unless assignment_status.is_a?(Hash)
87
+ # Every local assignment must be completed. A missing or unreadable
88
+ # assignment record never proves terminality.
89
+ def assignment_complete?(assignments)
90
+ entries = Array(assignments)
91
+ return false if entries.empty?
92
+
93
+ entries.all? { |entry| entry.dig("assignment", "state") == "completed" }
94
+ end
95
+
96
+ # No local step may be active or pending. A summary that exists but
97
+ # is unreadable blocks.
98
+ def work_terminal?(assignments)
99
+ reasons = []
100
+ entries = Array(assignments)
101
+ entries.each do |entry|
102
+ summary = entry["step_summary"]
103
+ next if summary.nil?
104
+
105
+ unless summary.is_a?(Hash)
106
+ reasons << "assignment step state unreadable"
107
+ next
108
+ end
109
+ active = summary["active"].to_i
110
+ pending = summary["pending"].to_i
111
+ next if active.zero? && pending.zero?
94
112
 
95
- assignment_status.dig("assignment", "state") == "completed"
113
+ reasons << "assignment #{entry.dig("assignment", "id")} has #{active} active and #{pending} pending step(s)"
114
+ end
115
+ [reasons.empty?, reasons]
96
116
  end
97
117
 
98
118
  def task_done?(worktree_path, task_ref)
@@ -101,7 +121,8 @@ module Ace
101
121
  end
102
122
 
103
123
  # Full cleanliness: untracked files are work too. Ignored files are
104
- # not dirt, but required ignored artifacts are checked separately.
124
+ # not dirt; local assignment state is not a deletion precondition
125
+ # beyond the assignment-completion check above.
105
126
  def git_clean_for_prune?(worktree_path)
106
127
  stdout, status = Open3.capture2(
107
128
  "git", "-C", worktree_path, "status", "--porcelain"
@@ -113,75 +134,13 @@ module Ace
113
134
  false
114
135
  end
115
136
 
116
- # A journal checkout inside the worktree is a required ignored
117
- # artifact unless every journaled commit already lives in the
118
- # authoritative evidence ref.
119
- def required_ignored_artifacts_safe?(worktree_path)
120
- checkout = File.join(worktree_path, assign_cache_relative, "evidence-checkout", "journal")
121
- return [true, []] unless File.directory?(checkout)
122
-
123
- head, status = Open3.capture2("git", "-C", checkout, "rev-parse", "HEAD")
124
- checkout_head = head.to_s.strip
125
- if !status.success? || checkout_head.empty?
126
- return [false, ["evidence journal checkout unreadable: #{checkout}"]]
127
- end
128
-
129
- common_dir = project_git_common_dir(worktree_path)
130
- if common_dir.nil?
131
- return [false, ["cannot resolve common git dir to verify evidence journal"]]
132
- end
133
-
134
- _out, evidence_status = Open3.capture2(
135
- "git", "-C", common_dir, "merge-base", "--is-ancestor", checkout_head, "refs/ace/execution"
136
- )
137
- if evidence_status.success?
138
- [true, []]
139
- else
140
- [false, ["evidence journal checkout has commits not in refs/ace/execution"]]
141
- end
142
- end
143
-
144
- # Attempt evidence from the worktree's own assignment cache: any
145
- # active or uncertain attempt blocks; an unreadable store blocks.
146
- # Returns the independently recorded creation baseline (base_head)
147
- # for patch-range preservation proofs.
148
- def attempts_evidence(worktree_path, context)
149
- ids = Array(context.assignments).filter_map { |entry| entry.dig("assignment", "id") }
150
- return [true, [], nil] if ids.empty?
151
-
152
- cache_base = File.join(worktree_path, assign_cache_relative)
153
- begin
154
- store = @attempt_store_factory.call(cache_base)
155
- rescue => e
156
- return [false, ["attempt state unreadable: #{e.message}"], nil]
157
- end
158
- reasons = []
159
- recorded_base = nil
160
- terminal = true
161
- ids.each do |assignment_id|
162
- attempts = store.list(assignment_id)
163
- attempts.each do |attempt|
164
- recorded_base ||= attempt.binding.base_head
165
- next unless attempt.active? || attempt.uncertain?
166
-
167
- terminal = false
168
- reasons << "attempt #{attempt.attempt_id} on assignment #{assignment_id} is #{attempt.state}"
169
- end
170
- rescue => e
171
- terminal = false
172
- reasons << "attempt state for assignment #{assignment_id} unreadable: #{e.message}"
173
- end
174
- [terminal, reasons, recorded_base]
175
- end
176
-
177
- def preservation_proof(worktree_path:, accepted_base:, manifest_record:, recorded_base:, candidate_branch: nil)
137
+ def preservation_proof(worktree_path:, accepted_base:, manifest_record:, candidate_branch: nil)
178
138
  return Models::PreservationProof.blocked("no surviving accepted base could be resolved") if accepted_base.nil?
179
139
 
180
140
  @preservation_checker.proof(
181
141
  worktree_path: worktree_path,
182
142
  accepted_base: accepted_base,
183
143
  manifest_record: manifest_record,
184
- recorded_base: recorded_base,
185
144
  candidate_branch: candidate_branch
186
145
  )
187
146
  rescue => e
@@ -202,10 +161,6 @@ module Ace
202
161
  nil
203
162
  end
204
163
 
205
- def assign_cache_relative
206
- Ace::Assign.config["cache_dir"] || ".ace-local/assign"
207
- end
208
-
209
164
  def task_done_in_context?(path, task_ref)
210
165
  Dir.chdir(path) do
211
166
  manager = @task_loader_factory.call
@@ -4,12 +4,11 @@ module Ace
4
4
  module Overseer
5
5
  module Molecules
6
6
  class WorktreeContextCollector
7
- def initialize(repo_status_loader: nil, assignment_discoverer_factory: nil, recovery_factory: nil)
7
+ def initialize(repo_status_loader: nil, assignment_discoverer_factory: nil)
8
8
  @repo_status_loader = repo_status_loader || -> {
9
9
  Ace::Git::Organisms::RepoStatusLoader.load(include_pr_activity: false, include_commits: false)
10
10
  }
11
11
  @assignment_discoverer_factory = assignment_discoverer_factory || -> { Ace::Assign::Molecules::AssignmentDiscoverer.new }
12
- @recovery_factory = recovery_factory || -> { Ace::Assign::Organisms::AttemptCoordinator.new }
13
12
  end
14
13
 
15
14
  def collect(worktree_path, location_type: :worktree)
@@ -50,9 +49,8 @@ module Ace
50
49
  def load_all_assignments
51
50
  infos = @assignment_discoverer_factory.call.find_all(include_completed: true)
52
51
  infos.map { |info| assignment_info_to_h(info) }
53
- rescue StandardError => e
54
- [{"assignment" => {"id" => "unknown", "name" => "unreadable assignment state", "state" => "unknown"},
55
- "recovery" => unavailable_recovery("unknown", e)}]
52
+ rescue StandardError
53
+ [{"assignment" => {"id" => "unknown", "name" => "unreadable assignment state", "state" => "unknown"}}]
56
54
  end
57
55
 
58
56
  def assignment_info_to_h(info)
@@ -72,22 +70,10 @@ module Ace
72
70
  "pending" => info.queue_state.summary[:pending]
73
71
  },
74
72
  "active_steps" => active_steps.map(&:name),
75
- "next_step" => next_step&.name,
76
- "recovery" => recovery_for(info.id)
73
+ "next_step" => next_step&.name
77
74
  }
78
75
  end
79
76
 
80
- def recovery_for(id)
81
- @recovery_factory.call.recovery_snapshot(id)
82
- rescue StandardError => e
83
- unavailable_recovery(id, e)
84
- end
85
-
86
- def unavailable_recovery(id, error)
87
- {"assignment_id" => id, "liveness" => "unknown", "last_verified_observation" => nil,
88
- "decision" => "reconcile-required", "recovery_reason" => "recovery evidence unavailable (#{error.class})"}
89
- end
90
-
91
77
  def extract_task_id(worktree_path, branch)
92
78
  # Match "task.NNN"/"t.NNN" or "ace-task.xxx"/"ace-t.xxx" in path (numeric or B36TS naming)
93
79
  from_path = worktree_path.to_s[/^(?:.*\/)?(?:ace-)?(?:task|t)\.([0-9a-z]+(?:\.[0-9a-z]+)?)\/?$/, 1]