-
Notifications
You must be signed in to change notification settings - Fork 0
[T619] Render grounded path-existence answers #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/dev/talos/runtime/outcome/PathExistenceAnswerRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package dev.talos.runtime.outcome; | ||
|
|
||
| import dev.talos.runtime.policy.EvidenceObligation; | ||
| import dev.talos.runtime.policy.EvidenceObligationVerifier; | ||
| import dev.talos.runtime.task.TaskContract; | ||
| import dev.talos.runtime.toolcall.ToolCallSupport; | ||
| import dev.talos.runtime.turn.CurrentTurnPlan; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Set; | ||
|
|
||
| /** Renders deterministic file-existence facts once path-existence evidence is satisfied. */ | ||
| public final class PathExistenceAnswerRenderer { | ||
| private static final String PREFIX = "[Path existence verified]"; | ||
|
|
||
| private PathExistenceAnswerRenderer() {} | ||
|
|
||
| public static String prependVerifiedStatusIfNeeded( | ||
| String answer, | ||
| CurrentTurnPlan plan, | ||
| EvidenceObligation obligation, | ||
| EvidenceObligationVerifier.Result evidenceResult, | ||
| Path workspace | ||
| ) { | ||
| String current = answer == null ? "" : answer; | ||
| if (current.startsWith(PREFIX)) return current; | ||
| if (obligation != EvidenceObligation.PATH_EXISTENCE_EVIDENCE_REQUIRED) return current; | ||
| if (evidenceResult == null || evidenceResult.status() != EvidenceObligationVerifier.Status.SATISFIED) { | ||
| return current; | ||
| } | ||
| if (workspace == null) return current; | ||
|
|
||
| List<String> targets = sortedTargets(plan == null ? null : plan.taskContract()); | ||
| if (targets.isEmpty()) return current; | ||
|
|
||
| Path root; | ||
| try { | ||
| root = workspace.toAbsolutePath().normalize(); | ||
| } catch (RuntimeException e) { | ||
| return current; | ||
| } | ||
|
|
||
| List<String> lines = new ArrayList<>(); | ||
| for (String target : targets) { | ||
| String status = status(root, target); | ||
| if (status.isBlank()) continue; | ||
| lines.add(target + ": " + status); | ||
| } | ||
| if (lines.isEmpty()) return current; | ||
|
|
||
| String summary = PREFIX + "\n- " + String.join("\n- ", lines); | ||
| return current.isBlank() ? summary : summary + "\n\n" + current; | ||
| } | ||
|
|
||
| private static List<String> sortedTargets(TaskContract contract) { | ||
| if (contract == null) return List.of(); | ||
| Set<String> targets = contract.sourceEvidenceTargets().isEmpty() | ||
| ? contract.expectedTargets() | ||
| : contract.sourceEvidenceTargets(); | ||
| if (targets == null || targets.isEmpty()) return List.of(); | ||
| return targets.stream() | ||
| .map(ToolCallSupport::normalizePath) | ||
| .map(String::strip) | ||
| .filter(target -> !target.isBlank()) | ||
| .distinct() | ||
| .sorted(Comparator.comparing((String target) -> target.toLowerCase(Locale.ROOT)) | ||
| .thenComparing(Comparator.naturalOrder())) | ||
| .toList(); | ||
| } | ||
|
|
||
| private static String status(Path root, String target) { | ||
| Path resolved = resolve(root, target); | ||
| if (resolved == null) return "outside workspace"; | ||
| return Files.exists(resolved) ? "exists" : "not found"; | ||
| } | ||
|
|
||
| private static Path resolve(Path root, String target) { | ||
| if (root == null || target == null || target.isBlank()) return null; | ||
| try { | ||
| Path candidate = Path.of(target); | ||
| Path resolved = candidate.isAbsolute() ? candidate : root.resolve(candidate); | ||
| resolved = resolved.toAbsolutePath().normalize(); | ||
| return resolved.startsWith(root) ? resolved : null; | ||
| } catch (RuntimeException e) { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In workspaces containing a broken symlink, this reports
<link>: not foundeven though the path entry itself exists andtalos.list_direvidence would show it.Files.exists(resolved)follows the symlink target by default, so a broken link is treated the same as an absent path; path-existence answers should check the directory entry itself, e.g. withLinkOption.NOFOLLOW_LINKSor an explicit symbolic-link check.Useful? React with 👍 / 👎.