audit-tools 0.32.20 → 0.32.22

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 (195) hide show
  1. package/dist/audit/clarification/blastRadius.d.ts +23 -0
  2. package/dist/audit/clarification/blastRadius.d.ts.map +1 -0
  3. package/dist/audit/clarification/blastRadius.js +65 -0
  4. package/dist/audit/clarification/blastRadius.js.map +1 -0
  5. package/dist/audit/clarification/dials.d.ts +28 -0
  6. package/dist/audit/clarification/dials.d.ts.map +1 -0
  7. package/dist/audit/clarification/dials.js +37 -0
  8. package/dist/audit/clarification/dials.js.map +1 -0
  9. package/dist/audit/clarification/partition.d.ts +25 -0
  10. package/dist/audit/clarification/partition.d.ts.map +1 -0
  11. package/dist/audit/clarification/partition.js +77 -0
  12. package/dist/audit/clarification/partition.js.map +1 -0
  13. package/dist/audit/clarification/riskGate.d.ts +24 -0
  14. package/dist/audit/clarification/riskGate.d.ts.map +1 -0
  15. package/dist/audit/clarification/riskGate.js +38 -0
  16. package/dist/audit/clarification/riskGate.js.map +1 -0
  17. package/dist/audit/clarification/voiQueue.d.ts +17 -0
  18. package/dist/audit/clarification/voiQueue.d.ts.map +1 -0
  19. package/dist/audit/clarification/voiQueue.js +37 -0
  20. package/dist/audit/clarification/voiQueue.js.map +1 -0
  21. package/dist/audit/cli/auditStep.d.ts +2 -0
  22. package/dist/audit/cli/auditStep.d.ts.map +1 -1
  23. package/dist/audit/cli/auditStep.js +9 -1
  24. package/dist/audit/cli/auditStep.js.map +1 -1
  25. package/dist/audit/cli/charterClarificationPrompt.d.ts +19 -0
  26. package/dist/audit/cli/charterClarificationPrompt.d.ts.map +1 -0
  27. package/dist/audit/cli/charterClarificationPrompt.js +60 -0
  28. package/dist/audit/cli/charterClarificationPrompt.js.map +1 -0
  29. package/dist/audit/cli/nextStepCommand.d.ts.map +1 -1
  30. package/dist/audit/cli/nextStepCommand.js +74 -0
  31. package/dist/audit/cli/nextStepCommand.js.map +1 -1
  32. package/dist/audit/cli/nextStepHelpers.d.ts +62 -0
  33. package/dist/audit/cli/nextStepHelpers.d.ts.map +1 -1
  34. package/dist/audit/cli/nextStepHelpers.js +129 -0
  35. package/dist/audit/cli/nextStepHelpers.js.map +1 -1
  36. package/dist/audit/cli/steps.d.ts +4 -4
  37. package/dist/audit/cli/steps.d.ts.map +1 -1
  38. package/dist/audit/cli/steps.js +2 -0
  39. package/dist/audit/cli/steps.js.map +1 -1
  40. package/dist/audit/io/artifacts.d.ts +6 -0
  41. package/dist/audit/io/artifacts.d.ts.map +1 -1
  42. package/dist/audit/io/artifacts.js +2 -0
  43. package/dist/audit/io/artifacts.js.map +1 -1
  44. package/dist/audit/orchestrator/advance.d.ts +23 -0
  45. package/dist/audit/orchestrator/advance.d.ts.map +1 -1
  46. package/dist/audit/orchestrator/advance.js +122 -4
  47. package/dist/audit/orchestrator/advance.js.map +1 -1
  48. package/dist/audit/orchestrator/advanceTypes.d.ts +22 -1
  49. package/dist/audit/orchestrator/advanceTypes.d.ts.map +1 -1
  50. package/dist/audit/orchestrator/charterClarificationExecutor.d.ts +28 -0
  51. package/dist/audit/orchestrator/charterClarificationExecutor.d.ts.map +1 -0
  52. package/dist/audit/orchestrator/charterClarificationExecutor.js +130 -0
  53. package/dist/audit/orchestrator/charterClarificationExecutor.js.map +1 -0
  54. package/dist/audit/orchestrator/dependencyMap.d.ts +2 -0
  55. package/dist/audit/orchestrator/dependencyMap.d.ts.map +1 -1
  56. package/dist/audit/orchestrator/dependencyMap.js +24 -0
  57. package/dist/audit/orchestrator/dependencyMap.js.map +1 -1
  58. package/dist/audit/orchestrator/designReviewPrompt.d.ts +17 -0
  59. package/dist/audit/orchestrator/designReviewPrompt.d.ts.map +1 -1
  60. package/dist/audit/orchestrator/designReviewPrompt.js +50 -0
  61. package/dist/audit/orchestrator/designReviewPrompt.js.map +1 -1
  62. package/dist/audit/orchestrator/executorRunners.d.ts.map +1 -1
  63. package/dist/audit/orchestrator/executorRunners.js +4 -0
  64. package/dist/audit/orchestrator/executorRunners.js.map +1 -1
  65. package/dist/audit/orchestrator/executors.d.ts.map +1 -1
  66. package/dist/audit/orchestrator/executors.js +20 -0
  67. package/dist/audit/orchestrator/executors.js.map +1 -1
  68. package/dist/audit/orchestrator/nextStep.d.ts +11 -1
  69. package/dist/audit/orchestrator/nextStep.d.ts.map +1 -1
  70. package/dist/audit/orchestrator/nextStep.js +6 -2
  71. package/dist/audit/orchestrator/nextStep.js.map +1 -1
  72. package/dist/audit/orchestrator/staleness.d.ts +27 -1
  73. package/dist/audit/orchestrator/staleness.d.ts.map +1 -1
  74. package/dist/audit/orchestrator/staleness.js +33 -16
  75. package/dist/audit/orchestrator/staleness.js.map +1 -1
  76. package/dist/audit/orchestrator/state.d.ts +12 -1
  77. package/dist/audit/orchestrator/state.d.ts.map +1 -1
  78. package/dist/audit/orchestrator/state.js +41 -2
  79. package/dist/audit/orchestrator/state.js.map +1 -1
  80. package/dist/audit/orchestrator/synthesisExecutors.d.ts.map +1 -1
  81. package/dist/audit/orchestrator/synthesisExecutors.js +1 -0
  82. package/dist/audit/orchestrator/synthesisExecutors.js.map +1 -1
  83. package/dist/audit/orchestrator/systemicChallengeExecutor.d.ts +25 -0
  84. package/dist/audit/orchestrator/systemicChallengeExecutor.d.ts.map +1 -0
  85. package/dist/audit/orchestrator/systemicChallengeExecutor.js +107 -0
  86. package/dist/audit/orchestrator/systemicChallengeExecutor.js.map +1 -0
  87. package/dist/audit/reporting/mergeFindings.d.ts +2 -1
  88. package/dist/audit/reporting/mergeFindings.d.ts.map +1 -1
  89. package/dist/audit/reporting/mergeFindings.js +6 -1
  90. package/dist/audit/reporting/mergeFindings.js.map +1 -1
  91. package/dist/audit/reporting/synthesis.d.ts +2 -0
  92. package/dist/audit/reporting/synthesis.d.ts.map +1 -1
  93. package/dist/audit/reporting/synthesis.js +1 -1
  94. package/dist/audit/reporting/synthesis.js.map +1 -1
  95. package/dist/audit/systemic/aggregateMetricsDigest.d.ts +11 -0
  96. package/dist/audit/systemic/aggregateMetricsDigest.d.ts.map +1 -0
  97. package/dist/audit/systemic/aggregateMetricsDigest.js +84 -0
  98. package/dist/audit/systemic/aggregateMetricsDigest.js.map +1 -0
  99. package/dist/audit/systemic/metricsDigestTypes.d.ts +35 -0
  100. package/dist/audit/systemic/metricsDigestTypes.d.ts.map +1 -0
  101. package/dist/audit/systemic/metricsDigestTypes.js +10 -0
  102. package/dist/audit/systemic/metricsDigestTypes.js.map +1 -0
  103. package/dist/audit/systemic/secondOrderAdversaryPrompt.d.ts +16 -0
  104. package/dist/audit/systemic/secondOrderAdversaryPrompt.d.ts.map +1 -0
  105. package/dist/audit/systemic/secondOrderAdversaryPrompt.js +85 -0
  106. package/dist/audit/systemic/secondOrderAdversaryPrompt.js.map +1 -0
  107. package/dist/audit/systemic/systemicChallengeLoop.d.ts +48 -0
  108. package/dist/audit/systemic/systemicChallengeLoop.d.ts.map +1 -0
  109. package/dist/audit/systemic/systemicChallengeLoop.js +107 -0
  110. package/dist/audit/systemic/systemicChallengeLoop.js.map +1 -0
  111. package/dist/audit/types/charterClarification.d.ts +52 -0
  112. package/dist/audit/types/charterClarification.d.ts.map +1 -0
  113. package/dist/audit/types/charterClarification.js +2 -0
  114. package/dist/audit/types/charterClarification.js.map +1 -0
  115. package/dist/audit/types/systemicChallenge.d.ts +69 -0
  116. package/dist/audit/types/systemicChallenge.d.ts.map +1 -0
  117. package/dist/audit/types/systemicChallenge.js +2 -0
  118. package/dist/audit/types/systemicChallenge.js.map +1 -0
  119. package/dist/remediate/steps/dispatch/acceptNode.d.ts +178 -0
  120. package/dist/remediate/steps/dispatch/acceptNode.d.ts.map +1 -0
  121. package/dist/remediate/steps/dispatch/acceptNode.js +351 -0
  122. package/dist/remediate/steps/dispatch/acceptNode.js.map +1 -0
  123. package/dist/remediate/steps/dispatch/common.d.ts +123 -0
  124. package/dist/remediate/steps/dispatch/common.d.ts.map +1 -0
  125. package/dist/remediate/steps/dispatch/common.js +236 -0
  126. package/dist/remediate/steps/dispatch/common.js.map +1 -0
  127. package/dist/remediate/steps/dispatch/dagNodeFields.d.ts +37 -0
  128. package/dist/remediate/steps/dispatch/dagNodeFields.d.ts.map +1 -0
  129. package/dist/remediate/steps/dispatch/dagNodeFields.js +19 -0
  130. package/dist/remediate/steps/dispatch/dagNodeFields.js.map +1 -0
  131. package/dist/remediate/steps/dispatch/implementPrompt.d.ts +70 -0
  132. package/dist/remediate/steps/dispatch/implementPrompt.d.ts.map +1 -0
  133. package/dist/remediate/steps/dispatch/implementPrompt.js +577 -0
  134. package/dist/remediate/steps/dispatch/implementPrompt.js.map +1 -0
  135. package/dist/remediate/steps/dispatch/marshal.d.ts +32 -0
  136. package/dist/remediate/steps/dispatch/marshal.d.ts.map +1 -0
  137. package/dist/remediate/steps/dispatch/marshal.js +935 -0
  138. package/dist/remediate/steps/dispatch/marshal.js.map +1 -0
  139. package/dist/remediate/steps/dispatch/verifyCommands.d.ts +97 -0
  140. package/dist/remediate/steps/dispatch/verifyCommands.d.ts.map +1 -0
  141. package/dist/remediate/steps/dispatch/verifyCommands.js +204 -0
  142. package/dist/remediate/steps/dispatch/verifyCommands.js.map +1 -0
  143. package/dist/remediate/steps/dispatch/waveScheduling.d.ts +90 -0
  144. package/dist/remediate/steps/dispatch/waveScheduling.d.ts.map +1 -0
  145. package/dist/remediate/steps/dispatch/waveScheduling.js +352 -0
  146. package/dist/remediate/steps/dispatch/waveScheduling.js.map +1 -0
  147. package/dist/remediate/steps/dispatch/worktreeLifecycle.d.ts +189 -0
  148. package/dist/remediate/steps/dispatch/worktreeLifecycle.d.ts.map +1 -0
  149. package/dist/remediate/steps/dispatch/worktreeLifecycle.js +643 -0
  150. package/dist/remediate/steps/dispatch/worktreeLifecycle.js.map +1 -0
  151. package/dist/remediate/steps/dispatch/writeScope.d.ts +151 -0
  152. package/dist/remediate/steps/dispatch/writeScope.d.ts.map +1 -0
  153. package/dist/remediate/steps/dispatch/writeScope.js +376 -0
  154. package/dist/remediate/steps/dispatch/writeScope.js.map +1 -0
  155. package/dist/remediate/steps/dispatch.d.ts +16 -871
  156. package/dist/remediate/steps/dispatch.d.ts.map +1 -1
  157. package/dist/remediate/steps/dispatch.js +18 -3623
  158. package/dist/remediate/steps/dispatch.js.map +1 -1
  159. package/dist/shared/decompose/charterClarification.d.ts +80 -0
  160. package/dist/shared/decompose/charterClarification.d.ts.map +1 -0
  161. package/dist/shared/decompose/charterClarification.js +105 -0
  162. package/dist/shared/decompose/charterClarification.js.map +1 -0
  163. package/dist/shared/decompose/systemicChallenge.d.ts +326 -0
  164. package/dist/shared/decompose/systemicChallenge.d.ts.map +1 -0
  165. package/dist/shared/decompose/systemicChallenge.js +30 -0
  166. package/dist/shared/decompose/systemicChallenge.js.map +1 -0
  167. package/dist/shared/index.d.ts +10 -5
  168. package/dist/shared/index.d.ts.map +1 -1
  169. package/dist/shared/index.js +6 -4
  170. package/dist/shared/index.js.map +1 -1
  171. package/dist/shared/opencodePermissions.d.ts +73 -0
  172. package/dist/shared/opencodePermissions.d.ts.map +1 -1
  173. package/dist/shared/opencodePermissions.js +172 -0
  174. package/dist/shared/opencodePermissions.js.map +1 -1
  175. package/dist/shared/tooling/exec.d.ts +10 -1
  176. package/dist/shared/tooling/exec.d.ts.map +1 -1
  177. package/dist/shared/tooling/exec.js +13 -1
  178. package/dist/shared/tooling/exec.js.map +1 -1
  179. package/dist/shared/types/charter.d.ts +89 -0
  180. package/dist/shared/types/charter.d.ts.map +1 -1
  181. package/dist/shared/types/charter.js +68 -0
  182. package/dist/shared/types/charter.js.map +1 -1
  183. package/dist/shared/types/intentCheckpoint.d.ts +15 -0
  184. package/dist/shared/types/intentCheckpoint.d.ts.map +1 -1
  185. package/dist/shared/types/intentCheckpoint.js +11 -0
  186. package/dist/shared/types/intentCheckpoint.js.map +1 -1
  187. package/dist/shared/validation/charterGate.d.ts +20 -1
  188. package/dist/shared/validation/charterGate.d.ts.map +1 -1
  189. package/dist/shared/validation/charterGate.js +23 -0
  190. package/dist/shared/validation/charterGate.js.map +1 -1
  191. package/opencode.json +36 -20
  192. package/package.json +1 -1
  193. package/scripts/postinstall.mjs +2 -1
  194. package/wrapper/audit-code-wrapper-opencode.mjs +38 -12
  195. package/wrapper/remediate-code-wrapper-opencode.mjs +38 -12
@@ -0,0 +1,123 @@
1
+ export interface DispatchOptions {
2
+ root: string;
3
+ artifactsDir: string;
4
+ }
5
+ /** Normalize a declared path (absolute, repo-relative, or back-slashed) to a repo-relative forward-slash string. */
6
+ export declare function toRepoRelative(p: string, root: string): string;
7
+ export declare function uniquePaths(paths: string[]): string[];
8
+ export declare function runDir(artifactsDir: string, runId: string, phase: string): string;
9
+ export declare function dispatchPlanPath(artifactsDir: string, runId: string, phase: string): string;
10
+ /**
11
+ * Canonical comparison key for a filesystem path. `realpathSync` resolves
12
+ * symlinks and platform short-names so it matches git's `--show-toplevel`
13
+ * output (macOS TMPDIR `/var`→`/private/var`, Windows 8.3 names); falls back to
14
+ * `resolve` for paths that don't exist on disk (e.g. mocked unit tests).
15
+ */
16
+ export declare function canonicalPathKey(p: string): string;
17
+ /**
18
+ * Deterministic name of the dedicated remediation branch for a run. Derived from
19
+ * the stable run id (= the plan id, constant for the whole remediation) so every
20
+ * wave and the final report resolve the SAME branch without persisting it. Ref-safe:
21
+ * any character outside [A-Za-z0-9._-] collapses to '-'. Distinct from the per-node
22
+ * worktree branches (`remediate-<blockId>-<runId>`) — this uses a `remediation/` ref
23
+ * namespace so the two never collide.
24
+ */
25
+ export declare function refSafeSegment(s: string, fallback: string): string;
26
+ /**
27
+ * The git top-level directory containing `cwd`, or `null` when `cwd` is not
28
+ * inside a git working tree (or git is unavailable). `git rev-parse
29
+ * --show-toplevel` emits a forward-slash absolute path on every platform.
30
+ */
31
+ export declare function gitTopLevel(cwd: string): string | null;
32
+ /** True when `root` is inside a git work tree (the git tool is present and it's a repo). */
33
+ export declare function isGitWorkTree(root: string): boolean;
34
+ /** True when `branch` resolves to a commit in the repo at `root`. */
35
+ export declare function gitBranchExists(root: string, branch: string): boolean;
36
+ /** Branch name a block's isolated worktree is created on (mirrors `worktreePath`). */
37
+ export declare function worktreeBranchForBlock(blockId: string, runId: string): string;
38
+ /** Outcome of resolving the worker's ACTUAL edited files from git. */
39
+ export type GitEditedFiles = {
40
+ available: true;
41
+ files: Set<string>;
42
+ }
43
+ /** git is present but a probe failed against a real repo → fail closed. */
44
+ | {
45
+ available: false;
46
+ reason: "probe_failed";
47
+ error: string;
48
+ }
49
+ /** root is not under version control at all → no ground truth, gate is skipped. */
50
+ | {
51
+ available: false;
52
+ reason: "not_a_repo";
53
+ error: string;
54
+ };
55
+ /**
56
+ * The files a worker's worktree branch changed relative to HEAD — the ground
57
+ * truth for write-scope enforcement. Diffs `HEAD...<branch>` (the branch's own
58
+ * commits). Fail-closed / not-a-repo semantics mirror `gitEditedFiles`.
59
+ */
60
+ export declare function gitEditedFilesForBranch(root: string, branch: string): GitEditedFiles;
61
+ /** A single edited hunk on the NEW side of a branch diff (repo-relative path). */
62
+ export interface GitBranchHunk {
63
+ /** Repo-relative forward-slash path the hunk belongs to. */
64
+ file: string;
65
+ /** 1-based first line of the hunk on the new side. */
66
+ startLine: number;
67
+ /** Number of new-side lines the hunk spans (a pure deletion has 0). */
68
+ lineCount: number;
69
+ }
70
+ /**
71
+ * Outcome of resolving a branch's ACTUAL edited HUNKS from git. Fail-closed like
72
+ * {@link gitEditedFilesForBranch}: on a non-repo, a failed probe, or a diff we
73
+ * cannot parse, `available` is false and callers MUST treat hunk info as absent
74
+ * (conservatively assume same-file blocks overlap — never silently drop a
75
+ * collision).
76
+ */
77
+ export type GitBranchHunks = {
78
+ available: true;
79
+ hunks: GitBranchHunk[];
80
+ } | {
81
+ available: false;
82
+ reason: "not_a_repo";
83
+ error: string;
84
+ } | {
85
+ available: false;
86
+ reason: "probe_failed";
87
+ error: string;
88
+ };
89
+ /**
90
+ * Parse `git diff HEAD...<branch>` into per-hunk NEW-side line ranges — the
91
+ * ground truth for whether two same-file edits actually touch disjoint regions.
92
+ * Mirrors {@link gitEditedFilesForBranch}'s fail-closed / not-a-repo semantics:
93
+ * never throws; on a non-repo / failed probe / malformed diff returns a
94
+ * discriminated result marking hunks unavailable so the caller can fail closed.
95
+ *
96
+ * Paths are normalised to repo-relative forward-slash (the same scheme
97
+ * {@link gitEditedFilesForBranch} emits) so hunk files compare like-for-like
98
+ * with the file set.
99
+ */
100
+ export declare function gitHunksForBranch(root: string, branch: string): GitBranchHunks;
101
+ /**
102
+ * Parse a unified-diff body into NEW-side hunk ranges. Extracted for testability
103
+ * (no git spawn). Recognises `+++ b/<path>` file headers and
104
+ * `@@ -a,b +c,d @@` hunk headers; a header we cannot parse fails the whole probe
105
+ * closed (returns `probe_failed`) rather than silently producing partial hunks
106
+ * that would let a real overlap slip through.
107
+ */
108
+ export declare function parseUnifiedDiffHunks(diffText: string): GitBranchHunks;
109
+ /**
110
+ * Files the worker edited (from git) that fall OUTSIDE the block's declared
111
+ * write scope. Result-file artifacts and the agent-feedback file are excluded
112
+ * (they are sanctioned side outputs, never source edits). Returns the offending
113
+ * repo-relative paths (empty when the edits are fully within scope).
114
+ */
115
+ export declare function writeScopeViolations(declaredWritePaths: string[], editedFiles: Set<string>, root: string): string[];
116
+ /** Fixed prompt overhead per dispatch slot (prompt instructions, JSON schema, etc.). */
117
+ export declare const PROMPT_OVERHEAD_TOKENS = 2000;
118
+ /** Estimate slot tokens for an implement dispatch slot from readFiles byte sizes. */
119
+ export declare function estimateImplementSlotTokens(readFiles: string[], root: string): number;
120
+ /** Module-level cache: repo root → formatted conventions string. */
121
+ export declare const detectRepoConventionsCache: Map<string, string>;
122
+ export declare function getCachedConventions(root: string): string;
123
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/remediate/steps/dispatch/common.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,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AE,MAAM,GAAG,MAAM,CAMrF;AAMD,oEAAoE;AACpE,eAAO,MAAM,0BAA0B,qBAA4B,CAAC;AAEpE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOzD"}
@@ -0,0 +1,236 @@
1
+ import { statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { realpathSync } from "node:fs";
4
+ import { resolve } from "node:path";
5
+ import { spawnSyncHidden } from "audit-tools/shared";
6
+ import { AGENT_FEEDBACK_FILENAME, detectRepoConventions, formatRepoConventions, estimateTokensFromBytes, normalizeRepoPath, } from "audit-tools/shared";
7
+ // ---------------------------------------------------------------------------
8
+ // Path + set primitives
9
+ // ---------------------------------------------------------------------------
10
+ /** Normalize a declared path (absolute, repo-relative, or back-slashed) to a repo-relative forward-slash string. */
11
+ export function toRepoRelative(p, root) {
12
+ const normalizedRoot = root.replace(/\\/g, "/").replace(/\/$/, "");
13
+ let s = p.replace(/\\/g, "/");
14
+ if (s.startsWith(normalizedRoot + "/")) {
15
+ s = s.slice(normalizedRoot.length + 1);
16
+ }
17
+ return s;
18
+ }
19
+ export function uniquePaths(paths) {
20
+ return [...new Set(paths)];
21
+ }
22
+ export function runDir(artifactsDir, runId, phase) {
23
+ return join(artifactsDir, "runs", runId, phase);
24
+ }
25
+ export function dispatchPlanPath(artifactsDir, runId, phase) {
26
+ return join(runDir(artifactsDir, runId, phase), "dispatch-plan.json");
27
+ }
28
+ /**
29
+ * Canonical comparison key for a filesystem path. `realpathSync` resolves
30
+ * symlinks and platform short-names so it matches git's `--show-toplevel`
31
+ * output (macOS TMPDIR `/var`→`/private/var`, Windows 8.3 names); falls back to
32
+ * `resolve` for paths that don't exist on disk (e.g. mocked unit tests).
33
+ */
34
+ export function canonicalPathKey(p) {
35
+ try {
36
+ return normalizeRepoPath(realpathSync(p));
37
+ }
38
+ catch {
39
+ return normalizeRepoPath(resolve(p));
40
+ }
41
+ }
42
+ /**
43
+ * Deterministic name of the dedicated remediation branch for a run. Derived from
44
+ * the stable run id (= the plan id, constant for the whole remediation) so every
45
+ * wave and the final report resolve the SAME branch without persisting it. Ref-safe:
46
+ * any character outside [A-Za-z0-9._-] collapses to '-'. Distinct from the per-node
47
+ * worktree branches (`remediate-<blockId>-<runId>`) — this uses a `remediation/` ref
48
+ * namespace so the two never collide.
49
+ */
50
+ export function refSafeSegment(s, fallback) {
51
+ return (s
52
+ .replace(/[^A-Za-z0-9._-]+/g, "-")
53
+ .replace(/\.{2,}/g, ".") // ".." is invalid in a git ref name
54
+ .replace(/^[-.]+|[-.]+$/g, "") || fallback);
55
+ }
56
+ // ---------------------------------------------------------------------------
57
+ // Git primitives
58
+ // ---------------------------------------------------------------------------
59
+ /**
60
+ * The git top-level directory containing `cwd`, or `null` when `cwd` is not
61
+ * inside a git working tree (or git is unavailable). `git rev-parse
62
+ * --show-toplevel` emits a forward-slash absolute path on every platform.
63
+ */
64
+ export function gitTopLevel(cwd) {
65
+ const result = spawnSyncHidden("git", ["rev-parse", "--show-toplevel"], {
66
+ cwd,
67
+ encoding: "utf8",
68
+ shell: false,
69
+ });
70
+ if (result.status !== 0)
71
+ return null;
72
+ const top = (result.stdout ?? "").trim();
73
+ return top.length > 0 ? top : null;
74
+ }
75
+ /** True when `root` is inside a git work tree (the git tool is present and it's a repo). */
76
+ export function isGitWorkTree(root) {
77
+ const probe = spawnSyncHidden("git", ["rev-parse", "--is-inside-work-tree"], { cwd: root, encoding: "utf8", shell: false });
78
+ return !probe.error && probe.status === 0 && /true/.test(probe.stdout ?? "");
79
+ }
80
+ /** True when `branch` resolves to a commit in the repo at `root`. */
81
+ export function gitBranchExists(root, branch) {
82
+ const probe = spawnSyncHidden("git", ["rev-parse", "--verify", "--quiet", `${branch}^{commit}`], { cwd: root, encoding: "utf8", shell: false });
83
+ return !probe.error && probe.status === 0;
84
+ }
85
+ /** Branch name a block's isolated worktree is created on (mirrors `worktreePath`). */
86
+ export function worktreeBranchForBlock(blockId, runId) {
87
+ return `remediate-${blockId}-${runId}`;
88
+ }
89
+ /**
90
+ * The files a worker's worktree branch changed relative to HEAD — the ground
91
+ * truth for write-scope enforcement. Diffs `HEAD...<branch>` (the branch's own
92
+ * commits). Fail-closed / not-a-repo semantics mirror `gitEditedFiles`.
93
+ */
94
+ export function gitEditedFilesForBranch(root, branch) {
95
+ if (!isGitWorkTree(root)) {
96
+ return { available: false, reason: "not_a_repo", error: "root is not a git work tree" };
97
+ }
98
+ const diff = spawnSyncHidden("git", ["diff", "--name-only", `HEAD...${branch}`], { cwd: root, encoding: "utf8", shell: false });
99
+ if (diff.error || typeof diff.status !== "number" || diff.status !== 0) {
100
+ const detail = (diff.stderr ?? diff.error?.message ?? "git diff failed").toString().trim();
101
+ return { available: false, reason: "probe_failed", error: detail };
102
+ }
103
+ const files = new Set();
104
+ for (const line of (diff.stdout ?? "").split(/\r?\n/)) {
105
+ const p = line.trim();
106
+ if (p.length > 0)
107
+ files.add(p.replace(/\\/g, "/"));
108
+ }
109
+ return { available: true, files };
110
+ }
111
+ /**
112
+ * Parse `git diff HEAD...<branch>` into per-hunk NEW-side line ranges — the
113
+ * ground truth for whether two same-file edits actually touch disjoint regions.
114
+ * Mirrors {@link gitEditedFilesForBranch}'s fail-closed / not-a-repo semantics:
115
+ * never throws; on a non-repo / failed probe / malformed diff returns a
116
+ * discriminated result marking hunks unavailable so the caller can fail closed.
117
+ *
118
+ * Paths are normalised to repo-relative forward-slash (the same scheme
119
+ * {@link gitEditedFilesForBranch} emits) so hunk files compare like-for-like
120
+ * with the file set.
121
+ */
122
+ export function gitHunksForBranch(root, branch) {
123
+ if (!isGitWorkTree(root)) {
124
+ return { available: false, reason: "not_a_repo", error: "root is not a git work tree" };
125
+ }
126
+ const diff = spawnSyncHidden("git",
127
+ // No rename detection / context noise beyond what we parse; a plain unified
128
+ // diff carries the `+++ b/<path>` and `@@ … +start,count @@` headers we need.
129
+ ["diff", `HEAD...${branch}`], { cwd: root, encoding: "utf8", shell: false });
130
+ if (diff.error || typeof diff.status !== "number" || diff.status !== 0) {
131
+ const detail = (diff.stderr ?? diff.error?.message ?? "git diff failed").toString().trim();
132
+ return { available: false, reason: "probe_failed", error: detail };
133
+ }
134
+ return parseUnifiedDiffHunks(diff.stdout ?? "");
135
+ }
136
+ /**
137
+ * Parse a unified-diff body into NEW-side hunk ranges. Extracted for testability
138
+ * (no git spawn). Recognises `+++ b/<path>` file headers and
139
+ * `@@ -a,b +c,d @@` hunk headers; a header we cannot parse fails the whole probe
140
+ * closed (returns `probe_failed`) rather than silently producing partial hunks
141
+ * that would let a real overlap slip through.
142
+ */
143
+ export function parseUnifiedDiffHunks(diffText) {
144
+ const hunks = [];
145
+ let currentFile = null;
146
+ for (const rawLine of diffText.split(/\r?\n/)) {
147
+ if (rawLine.startsWith("+++ ")) {
148
+ // `+++ b/path` — or `+++ /dev/null` for a pure deletion (no new side).
149
+ const target = rawLine.slice(4).trim();
150
+ if (target === "/dev/null") {
151
+ currentFile = null;
152
+ continue;
153
+ }
154
+ // Strip the conventional `b/` prefix; leave already-bare paths intact.
155
+ const bare = target.startsWith("b/") ? target.slice(2) : target;
156
+ currentFile = bare.replace(/\\/g, "/");
157
+ continue;
158
+ }
159
+ if (rawLine.startsWith("@@")) {
160
+ const match = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/.exec(rawLine);
161
+ if (!match) {
162
+ return {
163
+ available: false,
164
+ reason: "probe_failed",
165
+ error: `unparseable hunk header: ${rawLine}`,
166
+ };
167
+ }
168
+ if (currentFile === null)
169
+ continue; // deletion-only target: no new-side hunk.
170
+ const startLine = Number(match[1]);
171
+ const lineCount = match[2] === undefined ? 1 : Number(match[2]);
172
+ hunks.push({ file: currentFile, startLine, lineCount });
173
+ }
174
+ }
175
+ return { available: true, hunks };
176
+ }
177
+ /**
178
+ * Files the worker edited (from git) that fall OUTSIDE the block's declared
179
+ * write scope. Result-file artifacts and the agent-feedback file are excluded
180
+ * (they are sanctioned side outputs, never source edits). Returns the offending
181
+ * repo-relative paths (empty when the edits are fully within scope).
182
+ */
183
+ export function writeScopeViolations(declaredWritePaths, editedFiles, root) {
184
+ const declared = new Set(declaredWritePaths.map((p) => toRepoRelative(p, root)));
185
+ const violations = [];
186
+ for (const edited of editedFiles) {
187
+ const rel = toRepoRelative(edited, root);
188
+ if (declared.has(rel))
189
+ continue;
190
+ // Sanctioned non-source outputs: result JSON files and the reflection file.
191
+ if (rel.endsWith(".result.json"))
192
+ continue;
193
+ if (rel.endsWith(AGENT_FEEDBACK_FILENAME))
194
+ continue;
195
+ violations.push(rel);
196
+ }
197
+ return violations;
198
+ }
199
+ // ---------------------------------------------------------------------------
200
+ // Byte-based token estimation helpers
201
+ // ---------------------------------------------------------------------------
202
+ /** Fixed prompt overhead per dispatch slot (prompt instructions, JSON schema, etc.). */
203
+ export const PROMPT_OVERHEAD_TOKENS = 2000;
204
+ /** Sum the byte sizes of a list of absolute or repo-relative file paths. */
205
+ function sumFileSizes(filePaths) {
206
+ let total = 0;
207
+ for (const p of filePaths) {
208
+ try {
209
+ total += statSync(p).size;
210
+ }
211
+ catch {
212
+ // Missing file → 0 bytes; not an error for estimation purposes.
213
+ }
214
+ }
215
+ return total;
216
+ }
217
+ /** Estimate slot tokens for an implement dispatch slot from readFiles byte sizes. */
218
+ export function estimateImplementSlotTokens(readFiles, root) {
219
+ const absPaths = readFiles.map((f) => f.startsWith("/") || /^[A-Za-z]:[/\\]/.test(f) ? f : join(root, f));
220
+ const bytes = sumFileSizes(absPaths);
221
+ return estimateTokensFromBytes(bytes) + PROMPT_OVERHEAD_TOKENS;
222
+ }
223
+ // ---------------------------------------------------------------------------
224
+ // detectRepoConventions cache (one call per repo root per process)
225
+ // ---------------------------------------------------------------------------
226
+ /** Module-level cache: repo root → formatted conventions string. */
227
+ export const detectRepoConventionsCache = new Map();
228
+ export function getCachedConventions(root) {
229
+ if (detectRepoConventionsCache.has(root)) {
230
+ return detectRepoConventionsCache.get(root);
231
+ }
232
+ const result = formatRepoConventions(detectRepoConventions(root));
233
+ detectRepoConventionsCache.set(root, result);
234
+ return result;
235
+ }
236
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/remediate/steps/dispatch/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAO5B,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E,oHAAoH;AACpH,MAAM,UAAU,cAAc,CAAC,CAAS,EAAE,IAAY;IACpD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnE,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,CAAC,UAAU,CAAC,cAAc,GAAG,GAAG,CAAC,EAAE,CAAC;QACvC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAe;IACzC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,YAAoB,EAAE,KAAa,EAAE,KAAa;IACvE,OAAO,IAAI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E,8EAA8E;AAE9E,oEAAoE;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEpE,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,IAAI,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,OAAO,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IAC/C,CAAC;IACD,MAAM,MAAM,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;IAClE,0BAA0B,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { Finding } from "../../state/types.js";
2
+ /**
3
+ * The implementation-DAG node fields `promoteImplementationDagToExtractedPlan`
4
+ * writes onto each Finding (one node ↔ one finding ↔ one block in the contract
5
+ * pipeline). The shared `Finding` type does not declare these overlay fields, so
6
+ * they are read through this structural view rather than added to the shared
7
+ * contract. Every field is optional: a finding sourced from a plain
8
+ * `audit-findings.json` (not the contract pipeline) carries none of them and the
9
+ * seam degrades to the block-level behavior.
10
+ */
11
+ export interface DagNodeFields {
12
+ /** Relative model rank for the node (small | standard | deep). Never a model name. */
13
+ model_tier?: "small" | "standard" | "deep";
14
+ /** Upstream contracts' declared outputs this node builds on. */
15
+ preconditions?: string[];
16
+ /** Human-readable description of the concrete changes the node is expected to produce. */
17
+ expected_changes?: string;
18
+ /** Human-readable verification checks beyond `targeted_commands`. */
19
+ verification?: string[];
20
+ /**
21
+ * Reconciliation expectations carried from seam reconciliation: what an
22
+ * upstream/neighbor contract agreed to provide this node, expressed either as
23
+ * a list of strings or, when richer, as the precondition list. Read tolerantly
24
+ * because the promotion shape can vary across pipeline versions.
25
+ */
26
+ reconciliation_expectations?: string[];
27
+ }
28
+ /** Read the promoted DAG-node overlay fields off a Finding (all optional). */
29
+ export declare function nodeFieldsOf(finding: Finding): DagNodeFields;
30
+ /**
31
+ * The reconciliation expectations a node must honor (INV-DS-12): the explicit
32
+ * `reconciliation_expectations` when present, else the node's `preconditions`
33
+ * (upstream contracts' declared outputs). Returned as a deduped string list so
34
+ * the renderer can thread them and the disposition can record them.
35
+ */
36
+ export declare function reconciliationExpectationsOf(finding: Finding): string[];
37
+ //# sourceMappingURL=dagNodeFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dagNodeFields.d.ts","sourceRoot":"","sources":["../../../../src/remediate/steps/dispatch/dagNodeFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAMpD;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,sFAAsF;IACtF,UAAU,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;IAC3C,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0FAA0F;IAC1F,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;;;OAKG;IACH,2BAA2B,CAAC,EAAE,MAAM,EAAE,CAAC;CACxC;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CASvE"}
@@ -0,0 +1,19 @@
1
+ /** Read the promoted DAG-node overlay fields off a Finding (all optional). */
2
+ export function nodeFieldsOf(finding) {
3
+ return finding;
4
+ }
5
+ /**
6
+ * The reconciliation expectations a node must honor (INV-DS-12): the explicit
7
+ * `reconciliation_expectations` when present, else the node's `preconditions`
8
+ * (upstream contracts' declared outputs). Returned as a deduped string list so
9
+ * the renderer can thread them and the disposition can record them.
10
+ */
11
+ export function reconciliationExpectationsOf(finding) {
12
+ const node = nodeFieldsOf(finding);
13
+ const explicit = Array.isArray(node.reconciliation_expectations)
14
+ ? node.reconciliation_expectations
15
+ : [];
16
+ const preconditions = Array.isArray(node.preconditions) ? node.preconditions : [];
17
+ return [...new Set([...explicit, ...preconditions])].filter((s) => typeof s === "string" && s.trim().length > 0);
18
+ }
19
+ //# sourceMappingURL=dagNodeFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dagNodeFields.js","sourceRoot":"","sources":["../../../../src/remediate/steps/dispatch/dagNodeFields.ts"],"names":[],"mappings":"AAiCA,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,OAAO,OAAkC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,OAAgB;IAC3D,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC;QAC9D,CAAC,CAAC,IAAI,CAAC,2BAA2B;QAClC,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IAClF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CACzD,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CACpD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type { RemediationState } from "../../state/store.js";
2
+ import type { RemediationBlock } from "../../state/types.js";
3
+ import { type DispatchModelHint, type DispatchPlanItem } from "../types.js";
4
+ /**
5
+ * Best-effort: repo-relative test files that reference any of `sourceFiles` (by
6
+ * module basename). Pulling them into a block's access lets the worker that
7
+ * changes or removes a symbol also fix the tests that assert it, instead of
8
+ * leaving orphaned test breakage for a separate central mop-up. Matching is
9
+ * deliberately loose (a false positive only grants slightly broader, harmless
10
+ * write access; a false negative is the failure mode we want to avoid).
11
+ */
12
+ export interface TestFileEntry {
13
+ rel: string;
14
+ content: string;
15
+ }
16
+ /**
17
+ * Walk the repo ONCE and read every test file's content (bounded). Built once per
18
+ * dispatch and shared across all blocks so the filesystem walk + reads are not
19
+ * repeated per block.
20
+ */
21
+ export declare function buildTestFileIndex(root: string): TestFileEntry[];
22
+ /**
23
+ * Collect test files from `index` that reference any of `sourceFiles` by
24
+ * module basename. When `packageRoot` is supplied (repo-relative prefix, e.g.
25
+ * `packages/foo`), only test files under that package are considered —
26
+ * otherwise all test files in the index are matched (existing behavior).
27
+ */
28
+ export declare function collectReferencingTests(index: TestFileEntry[], sourceFiles: string[], packageRoot?: string): string[];
29
+ /**
30
+ * Detect the nearest ancestor directory containing a `package.json` for the
31
+ * first source file in `sourceFiles` (walk up, stop at `root`). Returns the
32
+ * repo-relative path prefix (e.g. `packages/foo`) or undefined if none found.
33
+ */
34
+ declare function detectPackageRoot(sourceFiles: string[], root: string): string | undefined;
35
+ export { detectPackageRoot };
36
+ /**
37
+ * Repo-relative paths every finding in a block needs for context, deduped.
38
+ */
39
+ export declare function blockReadFiles(block: RemediationBlock, state: RemediationState): string[];
40
+ /**
41
+ * Repo-relative paths every finding in a block may write, deduped. This is kept
42
+ * narrower than read context so a broad affected hub file does not serialize
43
+ * blocks whose documented write sets are actually disjoint.
44
+ */
45
+ export declare function blockWriteFiles(block: RemediationBlock, state: RemediationState): string[];
46
+ /**
47
+ * Construct the DispatchPlanItem for an implement task. Single source of truth
48
+ * so prepareImplementDispatch and mergeImplementResults stay in lockstep on item
49
+ * shape.
50
+ */
51
+ export declare function buildImplementDispatchItem(block: RemediationBlock, state: RemediationState, dir: string): DispatchPlanItem;
52
+ /**
53
+ * Absolute path to a block's implement worker result file for a run. Single
54
+ * source (same convention as {@link buildImplementDispatchItem}'s `result_path`)
55
+ * shared with triage's already-satisfied reconciliation guard: a passing tree
56
+ * verify only proves a node's work was DONE if a worker actually ran and left a
57
+ * result — no result file ⇒ "no worker ran", not "verified satisfied".
58
+ */
59
+ export declare function implementResultPath(artifactsDir: string, runId: string, blockId: string): string;
60
+ export declare function buildImplementModelHint(block: RemediationBlock, state: RemediationState): DispatchModelHint;
61
+ /**
62
+ * Returns true when any path in `writePaths` is one of the live infra modules.
63
+ * Paths are normalised to forward-slash form (win32 backslash → `/`) and matched
64
+ * by trailing repo-relative segment so absolute/worktree/relative spellings all
65
+ * resolve identically. Used to gate the live-surface verification section in the
66
+ * implement prompt.
67
+ */
68
+ export declare function isInfraModifyingBlock(writePaths: string[]): boolean;
69
+ export declare function implementPrompt(block: RemediationBlock, state: RemediationState, resultPath: string, conventions: string, repoRoot: string, feedbackDisplay: string, worktreeRoot?: string): string;
70
+ //# sourceMappingURL=implementPrompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"implementPrompt.d.ts","sourceRoot":"","sources":["../../../../src/remediate/steps/dispatch/implementPrompt.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAqB,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AAwCrB;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYhE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,aAAa,EAAE,EACtB,W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