@oss-autopilot/core 3.42.5 → 3.44.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 (192) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +428 -27
  3. package/dist/cli.bundle.cjs +212 -156
  4. package/dist/commands/check-integration.js +5 -1
  5. package/dist/commands/cleanup.d.ts +80 -0
  6. package/dist/commands/cleanup.js +334 -0
  7. package/dist/commands/comments.d.ts +14 -1
  8. package/dist/commands/comments.js +17 -5
  9. package/dist/commands/config.d.ts +2 -0
  10. package/dist/commands/config.js +63 -6
  11. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  12. package/dist/commands/daily-dismiss-filter.js +17 -1
  13. package/dist/commands/daily-ledger.d.ts +150 -0
  14. package/dist/commands/daily-ledger.js +248 -0
  15. package/dist/commands/daily-recent-prs.d.ts +26 -0
  16. package/dist/commands/daily-recent-prs.js +55 -0
  17. package/dist/commands/daily-render.d.ts +2 -1
  18. package/dist/commands/daily-render.js +4 -1
  19. package/dist/commands/daily.d.ts +5 -1
  20. package/dist/commands/daily.js +83 -93
  21. package/dist/commands/dashboard-cache.d.ts +2 -0
  22. package/dist/commands/dashboard-cache.js +33 -8
  23. package/dist/commands/dashboard-data.js +113 -69
  24. package/dist/commands/dashboard-gist-sync.js +3 -1
  25. package/dist/commands/dashboard-lifecycle.d.ts +36 -8
  26. package/dist/commands/dashboard-lifecycle.js +132 -39
  27. package/dist/commands/dashboard-process.d.ts +49 -1
  28. package/dist/commands/dashboard-process.js +111 -12
  29. package/dist/commands/dashboard-server.js +89 -23
  30. package/dist/commands/detect-formatters.js +1 -0
  31. package/dist/commands/dismiss.js +11 -7
  32. package/dist/commands/doctor.d.ts +15 -1
  33. package/dist/commands/doctor.js +66 -5
  34. package/dist/commands/draft.d.ts +77 -0
  35. package/dist/commands/draft.js +218 -0
  36. package/dist/commands/eval.js +1 -0
  37. package/dist/commands/fork-prune.d.ts +58 -0
  38. package/dist/commands/fork-prune.js +247 -0
  39. package/dist/commands/guidelines.d.ts +69 -2
  40. package/dist/commands/guidelines.js +158 -14
  41. package/dist/commands/index.d.ts +29 -4
  42. package/dist/commands/index.js +20 -3
  43. package/dist/commands/issue-thread.d.ts +46 -0
  44. package/dist/commands/issue-thread.js +123 -0
  45. package/dist/commands/ledger-backfill.d.ts +9 -0
  46. package/dist/commands/ledger-backfill.js +44 -1
  47. package/dist/commands/list-mark-done.d.ts +2 -1
  48. package/dist/commands/list-mark-done.js +3 -1
  49. package/dist/commands/list-move-tier.d.ts +2 -1
  50. package/dist/commands/list-move-tier.js +3 -1
  51. package/dist/commands/local-repos.js +10 -5
  52. package/dist/commands/locate-issue-list.d.ts +40 -17
  53. package/dist/commands/locate-issue-list.js +148 -88
  54. package/dist/commands/move.js +7 -1
  55. package/dist/commands/overnight-handoff.d.ts +17 -7
  56. package/dist/commands/overnight-handoff.js +36 -14
  57. package/dist/commands/overnight-push-prep.d.ts +14 -8
  58. package/dist/commands/overnight-push-prep.js +107 -35
  59. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  60. package/dist/commands/overnight-tool-rules.js +217 -0
  61. package/dist/commands/overnight.d.ts +5 -6
  62. package/dist/commands/overnight.js +61 -140
  63. package/dist/commands/parse-list.js +7 -1
  64. package/dist/commands/policy.d.ts +90 -0
  65. package/dist/commands/policy.js +276 -0
  66. package/dist/commands/pr-create.d.ts +48 -0
  67. package/dist/commands/pr-create.js +200 -0
  68. package/dist/commands/pr-preflight.d.ts +69 -0
  69. package/dist/commands/pr-preflight.js +348 -0
  70. package/dist/commands/repo-vet.d.ts +9 -0
  71. package/dist/commands/repo-vet.js +36 -11
  72. package/dist/commands/scout-bridge.js +18 -8
  73. package/dist/commands/search.js +7 -0
  74. package/dist/commands/setup.d.ts +3 -3
  75. package/dist/commands/setup.js +160 -48
  76. package/dist/commands/skip-add.js +10 -1
  77. package/dist/commands/startup.d.ts +12 -3
  78. package/dist/commands/startup.js +82 -49
  79. package/dist/commands/state-cmd.d.ts +2 -0
  80. package/dist/commands/state-cmd.js +5 -1
  81. package/dist/commands/stats.js +1 -0
  82. package/dist/commands/status.js +6 -0
  83. package/dist/commands/strategy.js +1 -0
  84. package/dist/commands/validation.d.ts +5 -0
  85. package/dist/commands/validation.js +5 -0
  86. package/dist/commands/vet-list.d.ts +6 -0
  87. package/dist/commands/vet-list.js +26 -1
  88. package/dist/commands/vet.d.ts +20 -0
  89. package/dist/commands/vet.js +133 -2
  90. package/dist/commands/work.d.ts +4 -0
  91. package/dist/commands/work.js +34 -11
  92. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  93. package/dist/core/anti-llm-policy.d.ts +3 -0
  94. package/dist/core/anti-llm-policy.js +3 -0
  95. package/dist/core/auth.js +2 -0
  96. package/dist/core/ci-analysis.d.ts +7 -2
  97. package/dist/core/ci-analysis.js +76 -21
  98. package/dist/core/commit-date.d.ts +45 -0
  99. package/dist/core/commit-date.js +45 -0
  100. package/dist/core/compliance-score.d.ts +3 -0
  101. package/dist/core/compliance-score.js +13 -9
  102. package/dist/core/config-registry.d.ts +27 -2
  103. package/dist/core/config-registry.js +94 -7
  104. package/dist/core/contributing.d.ts +2 -3
  105. package/dist/core/contributing.js +2 -3
  106. package/dist/core/daily-logic.d.ts +30 -5
  107. package/dist/core/daily-logic.js +68 -19
  108. package/dist/core/errors.d.ts +37 -3
  109. package/dist/core/errors.js +54 -5
  110. package/dist/core/fork-prune.d.ts +149 -0
  111. package/dist/core/fork-prune.js +333 -0
  112. package/dist/core/gist-health.d.ts +15 -3
  113. package/dist/core/gist-health.js +8 -0
  114. package/dist/core/gist-state-store.d.ts +24 -4
  115. package/dist/core/gist-state-store.js +98 -51
  116. package/dist/core/github-stats.d.ts +110 -16
  117. package/dist/core/github-stats.js +295 -110
  118. package/dist/core/http-cache.d.ts +0 -10
  119. package/dist/core/http-cache.js +0 -19
  120. package/dist/core/index.d.ts +13 -6
  121. package/dist/core/index.js +16 -6
  122. package/dist/core/issue-conversation.d.ts +8 -2
  123. package/dist/core/issue-conversation.js +31 -12
  124. package/dist/core/local-config.d.ts +95 -0
  125. package/dist/core/local-config.js +270 -0
  126. package/dist/core/merged-pr-notes.d.ts +2 -2
  127. package/dist/core/pacing.d.ts +41 -0
  128. package/dist/core/pacing.js +115 -0
  129. package/dist/core/pagination.d.ts +55 -0
  130. package/dist/core/pagination.js +59 -0
  131. package/dist/core/paths.d.ts +7 -0
  132. package/dist/core/paths.js +9 -0
  133. package/dist/core/pr-assembly.d.ts +2 -0
  134. package/dist/core/pr-assembly.js +6 -2
  135. package/dist/core/pr-graphql.d.ts +53 -4
  136. package/dist/core/pr-graphql.js +87 -14
  137. package/dist/core/pr-monitor.d.ts +35 -12
  138. package/dist/core/pr-monitor.js +110 -26
  139. package/dist/core/pr-preflight.d.ts +154 -0
  140. package/dist/core/pr-preflight.js +753 -0
  141. package/dist/core/pr-quality-rubric.d.ts +0 -6
  142. package/dist/core/pr-quality-rubric.js +0 -8
  143. package/dist/core/pr-template.d.ts +2 -0
  144. package/dist/core/pr-template.js +5 -1
  145. package/dist/core/prose-script.d.ts +72 -0
  146. package/dist/core/prose-script.js +223 -0
  147. package/dist/core/repo-policy.d.ts +111 -0
  148. package/dist/core/repo-policy.js +428 -0
  149. package/dist/core/repo-score-manager.d.ts +66 -0
  150. package/dist/core/repo-score-manager.js +140 -1
  151. package/dist/core/review-analysis.d.ts +49 -21
  152. package/dist/core/review-analysis.js +89 -15
  153. package/dist/core/reviewed-prs-fetch.js +11 -29
  154. package/dist/core/reviewed-prs.js +8 -15
  155. package/dist/core/stale-data.d.ts +78 -0
  156. package/dist/core/stale-data.js +153 -0
  157. package/dist/core/state-persistence.d.ts +62 -27
  158. package/dist/core/state-persistence.js +338 -119
  159. package/dist/core/state-schema.d.ts +152 -210
  160. package/dist/core/state-schema.js +232 -80
  161. package/dist/core/state.d.ts +81 -8
  162. package/dist/core/state.js +239 -46
  163. package/dist/core/status-determination.js +32 -12
  164. package/dist/core/strategy.js +3 -1
  165. package/dist/core/types.d.ts +22 -1
  166. package/dist/core/types.js +1 -0
  167. package/dist/core/untrusted-content.d.ts +30 -11
  168. package/dist/core/untrusted-content.js +95 -42
  169. package/dist/core/urls.d.ts +33 -0
  170. package/dist/core/urls.js +94 -0
  171. package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
  172. package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
  173. package/dist/dashboard/index.html +1 -1
  174. package/dist/formatters/json.d.ts +432 -10
  175. package/dist/formatters/json.js +156 -1
  176. package/package.json +6 -6
  177. package/dist/core/ci-enforced-tools.d.ts +0 -35
  178. package/dist/core/ci-enforced-tools.js +0 -109
  179. package/dist/core/comment-decision.d.ts +0 -79
  180. package/dist/core/comment-decision.js +0 -82
  181. package/dist/core/extraction-categories.d.ts +0 -55
  182. package/dist/core/extraction-categories.js +0 -108
  183. package/dist/core/follow-up-history.d.ts +0 -40
  184. package/dist/core/follow-up-history.js +0 -71
  185. package/dist/core/issue-effort.d.ts +0 -29
  186. package/dist/core/issue-effort.js +0 -47
  187. package/dist/core/maintainer-hints.d.ts +0 -23
  188. package/dist/core/maintainer-hints.js +0 -36
  189. package/dist/core/workflow-state.d.ts +0 -56
  190. package/dist/core/workflow-state.js +0 -101
  191. package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
  192. package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
@@ -18,6 +18,7 @@ export const INITIAL_STATE = AgentStateSchema.parse({ version: 4 });
18
18
  export const PROJECT_CATEGORIES = ProjectCategorySchema.options;
19
19
  export const ISSUE_SCOPES = IssueScopeSchema.options;
20
20
  export const DIFF_TOOLS = DiffToolSchema.options;
21
+ /** @deprecated Since #1948; nothing reads it. Will be removed in the next major version. */
21
22
  export const SCOPE_LABELS = {
22
23
  beginner: ['good first issue', 'help wanted', 'easy', 'up-for-grabs', 'first-timers-only', 'beginner'],
23
24
  intermediate: ['enhancement', 'feature', 'feature-request', 'contributions welcome'],
@@ -7,9 +7,11 @@
7
7
  * and the prompt-injection corpus:
8
8
  *
9
9
  * 1. Output starts with the open tag and ends with the close tag.
10
- * 2. The close-tag literal NEVER appears inside the wrapped body — any
11
- * occurrence in the input is escaped to a sentinel so an attacker
12
- * cannot close the fence early and inject instructions after it.
10
+ * 2. No `<` appears inside the wrapped body: every one is escaped to
11
+ * `&lt;` (#1931), so no tag of any spelling (letter case, inner
12
+ * whitespace, attributes, zero-width or lookalike letters) can exist
13
+ * there and an attacker cannot close the fence early and inject
14
+ * instructions after it.
13
15
  * 3. `extractFromFence(wrapUntrustedContent(x, label))` returns `x`
14
16
  * unchanged for any input — the wrapping is lossless.
15
17
  *
@@ -29,6 +31,8 @@
29
31
  * CLI text renderers consume the same objects.
30
32
  * - MCP-only surfaces (#1455): PR titles and branch-ref names via
31
33
  * {@link fenceFetchedPRTitles} (mcp-server resources.ts / prompts.ts),
34
+ * every title and branch-ref string in MCP tool results via
35
+ * {@link fenceTitlesDeep} (mcp-server tools.ts `wrapTool`, #1931),
32
36
  * and stored guidelines provenance via {@link labelGuidelinesContent}.
33
37
  * These do NOT apply on the CLI envelope — see the helpers' docs.
34
38
  *
@@ -54,14 +58,15 @@ export interface UntrustedContentMeta {
54
58
  }
55
59
  /**
56
60
  * Wrap `text` in a `<github-content>` fence labeled with `label` and the
57
- * optional metadata. Any occurrence of the close-tag literal inside `text`
58
- * is replaced with a zero-width-joined sentinel that round-trips losslessly
59
- * via {@link extractFromFence}.
61
+ * optional metadata. Every `&` and `<` inside `text` is entity-escaped,
62
+ * which round-trips losslessly via {@link extractFromFence}. Wrapping
63
+ * already-fenced text escapes the inner fence's tags like any other.
64
+ * Fullwidth `<` (U+FF1C) is not ASCII `<` and stays as is.
60
65
  */
61
66
  export declare function wrapUntrustedContent(text: string, label: string, meta?: UntrustedContentMeta): string;
62
67
  /**
63
68
  * Reverse of {@link wrapUntrustedContent}. Extracts the original body text
64
- * (un-escaping any sentinel-encoded close tags). Throws if the input is not
69
+ * (un-escaping `&lt;` and `&amp;`). Throws if the input is not
65
70
  * a single well-formed fence — callers shouldn't be parsing arbitrary
66
71
  * markdown with this; it's for tests + symmetric reasoning only.
67
72
  */
@@ -98,12 +103,26 @@ export declare function fenceFetchedPR<T extends FenceablePR>(pr: T): T;
98
103
  *
99
104
  * Composes safely with {@link fenceFetchedPR} (disjoint fields), and is
100
105
  * applied to already-body-fenced digest PRs without double-wrapping.
101
- * `VerifiedLinkedPR.title` (verify-issue) stays raw: the same producer
102
- * feeds the CLI `--json` contract (pinned by verify-issue contract
103
- * snapshots) and the consuming issue-scout agent carries the awareness
104
- * block. Returns a copy; never mutates.
106
+ * `VerifiedLinkedPR.title` (verify-issue) stays raw at the producer and on
107
+ * the CLI: the same producer feeds the CLI `--json` contract (pinned by
108
+ * verify-issue contract snapshots) and the consuming issue-scout agent
109
+ * carries the awareness block. On the MCP `verify-issue` tool result it is
110
+ * fenced by {@link fenceTitlesDeep} like every other title (#1931).
111
+ * Returns a copy; never mutates.
105
112
  */
106
113
  export declare function fenceFetchedPRTitles<T extends FenceableTitledPR>(pr: T): T;
114
+ /**
115
+ * Fence every non-empty PR/issue title and branch-ref string anywhere in an
116
+ * MCP tool result (#1931), and each label of an issue or PR row (#2046).
117
+ * Tool results reach an arbitrary MCP host LLM that never sees the "Prompt
118
+ * Injection Awareness" block, the same reason {@link fenceFetchedPRTitles} exists for resources and prompts, but tool
119
+ * payloads have no single shape, so this walks the whole value and matches
120
+ * by key. Field names and types are unchanged; only the string values gain
121
+ * the fence. Never skips a value that already looks fenced: an attacker can
122
+ * write a title that looks pre-fenced. Returns a copy; never mutates.
123
+ * MCP-only: the CLI `--json` envelope keeps these raw.
124
+ */
125
+ export declare function fenceTitlesDeep<T>(value: T): T;
107
126
  /**
108
127
  * Provenance preamble for stored per-repo guidelines (#1455). Guidelines are
109
128
  * LLM-distilled from a corpus of public PR comments — an untrusted source —
@@ -7,9 +7,11 @@
7
7
  * and the prompt-injection corpus:
8
8
  *
9
9
  * 1. Output starts with the open tag and ends with the close tag.
10
- * 2. The close-tag literal NEVER appears inside the wrapped body — any
11
- * occurrence in the input is escaped to a sentinel so an attacker
12
- * cannot close the fence early and inject instructions after it.
10
+ * 2. No `<` appears inside the wrapped body: every one is escaped to
11
+ * `&lt;` (#1931), so no tag of any spelling (letter case, inner
12
+ * whitespace, attributes, zero-width or lookalike letters) can exist
13
+ * there and an attacker cannot close the fence early and inject
14
+ * instructions after it.
13
15
  * 3. `extractFromFence(wrapUntrustedContent(x, label))` returns `x`
14
16
  * unchanged for any input — the wrapping is lossless.
15
17
  *
@@ -29,6 +31,8 @@
29
31
  * CLI text renderers consume the same objects.
30
32
  * - MCP-only surfaces (#1455): PR titles and branch-ref names via
31
33
  * {@link fenceFetchedPRTitles} (mcp-server resources.ts / prompts.ts),
34
+ * every title and branch-ref string in MCP tool results via
35
+ * {@link fenceTitlesDeep} (mcp-server tools.ts `wrapTool`, #1931),
32
36
  * and stored guidelines provenance via {@link labelGuidelinesContent}.
33
37
  * These do NOT apply on the CLI envelope — see the helpers' docs.
34
38
  *
@@ -44,18 +48,6 @@
44
48
  */
45
49
  export const UNTRUSTED_OPEN_TAG_NAME = 'github-content';
46
50
  export const UNTRUSTED_CLOSE_TAG = `</${UNTRUSTED_OPEN_TAG_NAME}>`;
47
- /**
48
- * Sentinels used to neutralize any literal open- or close-tag substring
49
- * inside the wrapped body. We use HTML entity escapes (`&lt;` / `&gt;`) so
50
- * the result is pure ASCII, lints cleanly, and round-trips losslessly. The
51
- * `&` itself is escaped first so an input containing the literal text
52
- * `&lt;/github-content&gt;` survives the wrap/unwrap round-trip without
53
- * collision.
54
- */
55
- const AMP_ESCAPE = '&amp;';
56
- const CLOSE_TAG_ESCAPE = `&lt;/${UNTRUSTED_OPEN_TAG_NAME}&gt;`;
57
- const OPEN_TAG_PATTERN = new RegExp(String.raw `<${UNTRUSTED_OPEN_TAG_NAME}\b`, 'g');
58
- const OPEN_TAG_ESCAPE = `&lt;${UNTRUSTED_OPEN_TAG_NAME}`;
59
51
  function escapeAttr(value) {
60
52
  // Newlines/carriage returns can't break out of a quoted attribute (no `"`)
61
53
  // but they visually fragment the open tag in the prompt text the LLM
@@ -70,23 +62,18 @@ function escapeAttr(value) {
70
62
  }
71
63
  /**
72
64
  * Wrap `text` in a `<github-content>` fence labeled with `label` and the
73
- * optional metadata. Any occurrence of the close-tag literal inside `text`
74
- * is replaced with a zero-width-joined sentinel that round-trips losslessly
75
- * via {@link extractFromFence}.
65
+ * optional metadata. Every `&` and `<` inside `text` is entity-escaped,
66
+ * which round-trips losslessly via {@link extractFromFence}. Wrapping
67
+ * already-fenced text escapes the inner fence's tags like any other.
68
+ * Fullwidth `<` (U+FF1C) is not ASCII `<` and stays as is.
76
69
  */
77
70
  export function wrapUntrustedContent(text, label, meta = {}) {
78
71
  // Escape order matters for round-trip correctness:
79
72
  // 1. `&` first — so any pre-existing entity in the input gets a literal
80
73
  // `&amp;` that survives the unwrap pass below.
81
- // 2. Close-tag literals — replaced with the entity-escaped form.
82
- // 3. Open-tag literals (matched only at boundaries via OPEN_TAG_PATTERN
83
- // so we don't accidentally rewrite the close-tag's `</github-content`).
84
- const escapedBody = text
85
- .split('&')
86
- .join(AMP_ESCAPE)
87
- .split(UNTRUSTED_CLOSE_TAG)
88
- .join(CLOSE_TAG_ESCAPE)
89
- .replaceAll(OPEN_TAG_PATTERN, OPEN_TAG_ESCAPE);
74
+ // 2. Every `<`. After pass 1 every `&lt;` in the body is one written
75
+ // here, so an input holding the literal text `&lt;` does not collide.
76
+ const escapedBody = text.replaceAll('&', '&amp;').replaceAll('<', '&lt;');
90
77
  const attrs = [`label="${escapeAttr(label)}"`];
91
78
  if (meta.author !== undefined)
92
79
  attrs.push(`author="${escapeAttr(meta.author)}"`);
@@ -98,7 +85,7 @@ export function wrapUntrustedContent(text, label, meta = {}) {
98
85
  }
99
86
  /**
100
87
  * Reverse of {@link wrapUntrustedContent}. Extracts the original body text
101
- * (un-escaping any sentinel-encoded close tags). Throws if the input is not
88
+ * (un-escaping `&lt;` and `&amp;`). Throws if the input is not
102
89
  * a single well-formed fence — callers shouldn't be parsing arbitrary
103
90
  * markdown with this; it's for tests + symmetric reasoning only.
104
91
  */
@@ -111,18 +98,13 @@ export function extractFromFence(fenced) {
111
98
  throw new Error('extractFromFence: input does not end with </github-content>');
112
99
  }
113
100
  const inner = fenced.slice(openMatch[0].length, fenced.length - UNTRUSTED_CLOSE_TAG.length);
114
- if (inner.includes(UNTRUSTED_CLOSE_TAG)) {
115
- throw new Error('extractFromFence: nested </github-content> found in body — fence escaping is broken');
101
+ // wrapUntrustedContent never leaves a raw `<` in the body.
102
+ if (inner.includes('<')) {
103
+ throw new Error('extractFromFence: raw < found in body (nested tag?) — fence escaping is broken');
116
104
  }
117
- // Reverse the escapes in opposite order: tag entities first (so an
105
+ // Reverse the escapes in opposite order: `&lt;` first (so an
118
106
  // already-`&amp;`-prefixed entity survives), then unescape `&amp;`.
119
- return inner
120
- .split(CLOSE_TAG_ESCAPE)
121
- .join(UNTRUSTED_CLOSE_TAG)
122
- .split(OPEN_TAG_ESCAPE)
123
- .join(`<${UNTRUSTED_OPEN_TAG_NAME}`)
124
- .split(AMP_ESCAPE)
125
- .join('&');
107
+ return inner.replaceAll('&lt;', '<').replaceAll('&amp;', '&');
126
108
  }
127
109
  /**
128
110
  * Tolerant unwrap for human-facing display paths (CLI text mode). Returns
@@ -176,10 +158,12 @@ export function fenceFetchedPR(pr) {
176
158
  *
177
159
  * Composes safely with {@link fenceFetchedPR} (disjoint fields), and is
178
160
  * applied to already-body-fenced digest PRs without double-wrapping.
179
- * `VerifiedLinkedPR.title` (verify-issue) stays raw: the same producer
180
- * feeds the CLI `--json` contract (pinned by verify-issue contract
181
- * snapshots) and the consuming issue-scout agent carries the awareness
182
- * block. Returns a copy; never mutates.
161
+ * `VerifiedLinkedPR.title` (verify-issue) stays raw at the producer and on
162
+ * the CLI: the same producer feeds the CLI `--json` contract (pinned by
163
+ * verify-issue contract snapshots) and the consuming issue-scout agent
164
+ * carries the awareness block. On the MCP `verify-issue` tool result it is
165
+ * fenced by {@link fenceTitlesDeep} like every other title (#1931).
166
+ * Returns a copy; never mutates.
183
167
  */
184
168
  export function fenceFetchedPRTitles(pr) {
185
169
  const label = `${pr.repo}#${pr.number}`;
@@ -195,6 +179,75 @@ export function fenceFetchedPRTitles(pr) {
195
179
  }
196
180
  return fenced;
197
181
  }
182
+ /** Result keys {@link fenceTitlesDeep} fences, mapped to the fence `source`. */
183
+ const TITLE_KEY_SOURCES = new Map([
184
+ ['title', 'title'],
185
+ ['prTitle', 'pr-title'],
186
+ ['headRefName', 'pr-head-ref'],
187
+ ['baseRefName', 'pr-base-ref'],
188
+ ]);
189
+ /** Best provenance label available on an arbitrary result object. */
190
+ function titleLabel(obj) {
191
+ if (typeof obj.repo === 'string' && typeof obj.number === 'number')
192
+ return `${obj.repo}#${obj.number}`;
193
+ for (const key of ['url', 'prUrl', 'repo']) {
194
+ const value = obj[key];
195
+ if (typeof value === 'string' && value !== '')
196
+ return value;
197
+ }
198
+ return 'github';
199
+ }
200
+ /**
201
+ * The `labels` of an issue or PR row (an object with a numeric `number` and a
202
+ * string `url`): set by the repo's maintainers, so fenced like titles (#2046).
203
+ * Rows without both keys are left alone, so the user's own configured
204
+ * `labels` (config, setup) stay raw.
205
+ */
206
+ function fenceRowLabels(obj, labels, label) {
207
+ if (typeof obj.number !== 'number' || typeof obj.url !== 'string')
208
+ return labels.map((l) => fenceTitlesDeep(l));
209
+ return labels.map((name) => typeof name === 'string' && name !== ''
210
+ ? wrapUntrustedContent(name, label, { source: 'issue-label' })
211
+ : fenceTitlesDeep(name));
212
+ }
213
+ /**
214
+ * Fence every non-empty PR/issue title and branch-ref string anywhere in an
215
+ * MCP tool result (#1931), and each label of an issue or PR row (#2046).
216
+ * Tool results reach an arbitrary MCP host LLM that never sees the "Prompt
217
+ * Injection Awareness" block, the same reason {@link fenceFetchedPRTitles} exists for resources and prompts, but tool
218
+ * payloads have no single shape, so this walks the whole value and matches
219
+ * by key. Field names and types are unchanged; only the string values gain
220
+ * the fence. Never skips a value that already looks fenced: an attacker can
221
+ * write a title that looks pre-fenced. Returns a copy; never mutates.
222
+ * MCP-only: the CLI `--json` envelope keeps these raw.
223
+ */
224
+ export function fenceTitlesDeep(value) {
225
+ if (Array.isArray(value))
226
+ return value.map((item) => fenceTitlesDeep(item));
227
+ if (value === null || typeof value !== 'object')
228
+ return value;
229
+ // Plain objects only: a Date or a class with toJSON must reach
230
+ // JSON.stringify intact, not as a copy of its own enumerable fields.
231
+ const proto = Object.getPrototypeOf(value);
232
+ if (proto !== null && proto !== Object.prototype)
233
+ return value;
234
+ const obj = value;
235
+ const label = titleLabel(obj);
236
+ const out = {};
237
+ for (const [key, field] of Object.entries(obj)) {
238
+ out[key] = fenceEntry(obj, key, field, label);
239
+ }
240
+ return out;
241
+ }
242
+ /** One entry of a result object `obj`, fenced by {@link fenceTitlesDeep}'s rules. */
243
+ function fenceEntry(obj, key, field, label) {
244
+ if (key === 'labels' && Array.isArray(field))
245
+ return fenceRowLabels(obj, field, label);
246
+ const source = TITLE_KEY_SOURCES.get(key);
247
+ return source !== undefined && typeof field === 'string' && field !== ''
248
+ ? wrapUntrustedContent(field, label, { source })
249
+ : fenceTitlesDeep(field);
250
+ }
198
251
  /**
199
252
  * Provenance preamble for stored per-repo guidelines (#1455). Guidelines are
200
253
  * LLM-distilled from a corpus of public PR comments — an untrusted source —
@@ -46,6 +46,15 @@ export declare function parseGitHubUrl(url: string): ParsedGitHubUrl | null;
46
46
  * // "org/repo#5"
47
47
  */
48
48
  export declare function issueRefKey(url: string): string | null;
49
+ /**
50
+ * The key of a URL-keyed state map (`dismissedIssues`, `dismissedPRHeads`,
51
+ * `statusOverrides`) that names the same issue or PR as `url` (#2001): `url`
52
+ * itself when present, else the key with the same {@link issueRefKey}, so a
53
+ * mixed-case owner/repo or the `/issues/N` form of a PR still finds the entry.
54
+ * Keys stay URLs because older clients sharing the Gist look them up by exact
55
+ * URL. undefined when there is no such key.
56
+ */
57
+ export declare function findRefKey(map: Readonly<Record<string, unknown>> | undefined, url: string): string | undefined;
49
58
  /**
50
59
  * Extracts the owner and repo from a GitHub web URL
51
60
  * (e.g. `https://github.com/owner/repo/pull/42`, `https://github.com/owner/repo/`).
@@ -76,3 +85,27 @@ export declare function splitRepo(repoFullName: string): {
76
85
  export declare function isOwnRepo(owner: string, username: string): boolean;
77
86
  /** True when `owner` is listed in `config.untrackedOrgs` (case-insensitive). */
78
87
  export declare function isUntrackedOrg(owner: string, untrackedOrgs?: readonly string[]): boolean;
88
+ /** GitHub's PR body limit. */
89
+ export declare const MAX_BODY_CHARS = 65536;
90
+ /**
91
+ * Markdown with its HTML comments and code (fenced and inline) blanked out:
92
+ * the text GitHub links refs in, and where PR templates keep example
93
+ * `Fixes #123` lines. Each match of
94
+ * `/<!--[\s\S]*?-->|```[\s\S]*?```|(`+)[^`]*\1/g` becomes one space, but in
95
+ * linear time: that regex rescans to the end from every unclosed opener.
96
+ */
97
+ export declare function stripNonProse(markdown: string): string;
98
+ /** One closing reference: `repo` is the `owner/repo` the text names, null for a bare `#N`. */
99
+ export interface ClosingRef {
100
+ repo: string | null;
101
+ number: number;
102
+ }
103
+ /**
104
+ * Issues `text` closes with a GitHub closing keyword (#2048), in order of
105
+ * appearance. With `markdown` (a PR body), HTML comments and code are
106
+ * skipped and only the first {@link MAX_BODY_CHARS} characters are read, as
107
+ * GitHub links nothing there; without it (a commit message) every line counts.
108
+ */
109
+ export declare function findClosingRefs(text: string, options?: {
110
+ markdown?: boolean;
111
+ }): ClosingRef[];
package/dist/core/urls.js CHANGED
@@ -74,6 +74,24 @@ export function issueRefKey(url) {
74
74
  const parsed = parseGitHubUrl(url);
75
75
  return parsed ? `${parsed.owner.toLowerCase()}/${parsed.repo.toLowerCase()}#${parsed.number}` : null;
76
76
  }
77
+ /**
78
+ * The key of a URL-keyed state map (`dismissedIssues`, `dismissedPRHeads`,
79
+ * `statusOverrides`) that names the same issue or PR as `url` (#2001): `url`
80
+ * itself when present, else the key with the same {@link issueRefKey}, so a
81
+ * mixed-case owner/repo or the `/issues/N` form of a PR still finds the entry.
82
+ * Keys stay URLs because older clients sharing the Gist look them up by exact
83
+ * URL. undefined when there is no such key.
84
+ */
85
+ export function findRefKey(map, url) {
86
+ if (!map)
87
+ return undefined;
88
+ if (Object.hasOwn(map, url))
89
+ return url;
90
+ const key = issueRefKey(url);
91
+ // ponytail: linear scan per miss, and these maps are never pruned, so cost grows with every
92
+ // dismiss/override ever made. Upgrade: build a ref -> key index once per daily/dashboard pass.
93
+ return key === null ? undefined : Object.keys(map).find((k) => issueRefKey(k) === key);
94
+ }
77
95
  /**
78
96
  * Extracts the owner and repo from a GitHub web URL
79
97
  * (e.g. `https://github.com/owner/repo/pull/42`, `https://github.com/owner/repo/`).
@@ -120,3 +138,79 @@ export function isUntrackedOrg(owner, untrackedOrgs = []) {
120
138
  const ownerLower = owner.toLowerCase();
121
139
  return untrackedOrgs.some((org) => org.toLowerCase() === ownerLower);
122
140
  }
141
+ /** GitHub's PR body limit. */
142
+ export const MAX_BODY_CHARS = 65_536;
143
+ function commentEnd(text, i, closers) {
144
+ if (!closers.comment || !text.startsWith('<!--', i))
145
+ return -1;
146
+ const close = text.indexOf('-->', i + 4);
147
+ if (close === -1)
148
+ closers.comment = false;
149
+ return close === -1 ? -1 : close + 3;
150
+ }
151
+ function fenceEnd(text, i, closers) {
152
+ if (!closers.fence || !text.startsWith('```', i))
153
+ return -1;
154
+ const close = text.indexOf('```', i + 3);
155
+ if (close === -1)
156
+ closers.fence = false;
157
+ return close === -1 ? -1 : close + 3;
158
+ }
159
+ /** A run of N backticks closed by the next N; failing that, half the run closes the other half. */
160
+ function codeSpanEnd(text, i) {
161
+ let run = 0;
162
+ while (text[i + run] === '`')
163
+ run++;
164
+ if (run === 0)
165
+ return -1;
166
+ const close = text.indexOf('`', i + run);
167
+ if (close !== -1 && text.startsWith('`'.repeat(run), close))
168
+ return close + run;
169
+ return run >= 2 ? i + 2 * Math.floor(run / 2) : -1;
170
+ }
171
+ /**
172
+ * Markdown with its HTML comments and code (fenced and inline) blanked out:
173
+ * the text GitHub links refs in, and where PR templates keep example
174
+ * `Fixes #123` lines. Each match of
175
+ * `/<!--[\s\S]*?-->|```[\s\S]*?```|(`+)[^`]*\1/g` becomes one space, but in
176
+ * linear time: that regex rescans to the end from every unclosed opener.
177
+ */
178
+ export function stripNonProse(markdown) {
179
+ const closers = { comment: true, fence: true };
180
+ let out = '';
181
+ let prose = 0;
182
+ let i = 0;
183
+ while (i < markdown.length) {
184
+ const end = Math.max(commentEnd(markdown, i, closers), fenceEnd(markdown, i, closers));
185
+ const span = end === -1 ? codeSpanEnd(markdown, i) : end;
186
+ if (span === -1) {
187
+ i++;
188
+ }
189
+ else {
190
+ out += `${markdown.slice(prose, i)} `;
191
+ prose = span;
192
+ i = span;
193
+ }
194
+ }
195
+ return out + markdown.slice(prose);
196
+ }
197
+ /**
198
+ * GitHub's closing keyword (close, closes, closed, fix, fixes, fixed, resolve,
199
+ * resolves, resolved; any case), an optional colon, then one ref: `#12`,
200
+ * `owner/repo#12` or an issue URL. Each ref needs its own keyword, as on
201
+ * GitHub, so `Fixes #1, #2` closes only #1.
202
+ */
203
+ const CLOSING_REF_RE = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)(?::\s*|\s+)(?:https?:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/issues\/(\d+)|([\w.-]+\/[\w.-]+)?#(\d+))\b/gi;
204
+ /**
205
+ * Issues `text` closes with a GitHub closing keyword (#2048), in order of
206
+ * appearance. With `markdown` (a PR body), HTML comments and code are
207
+ * skipped and only the first {@link MAX_BODY_CHARS} characters are read, as
208
+ * GitHub links nothing there; without it (a commit message) every line counts.
209
+ */
210
+ export function findClosingRefs(text, options = {}) {
211
+ const scanned = options.markdown ? stripNonProse(text.slice(0, MAX_BODY_CHARS)) : text;
212
+ return Array.from(scanned.matchAll(CLOSING_REF_RE), (m) => ({
213
+ repo: m[1] ?? m[3] ?? null,
214
+ number: Number(m[2] ?? m[4]),
215
+ }));
216
+ }