@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
@@ -1,16 +1,25 @@
1
+ import { type StoredMergedPR } from '../core/index.js';
1
2
  import { type PRCommentBundle } from '../core/pr-comments-fetcher.js';
3
+ import type { GuidelineProposalStatus } from '../formatters/json.js';
2
4
  export interface GuidelinesViewOutput {
3
5
  repo: string;
4
6
  /** Markdown content, or null when the repo has no guidelines stored. */
5
7
  content: string | null;
6
8
  /**
7
- * `content` prefixed with the provenance note, or null. This is the field to
9
+ * `content` inside the untrusted-content fence, prefixed with the provenance
10
+ * note and the review status, or null. This is the field to
8
11
  * hand to an agent: stored guidelines were distilled from other people's PR
9
12
  * comments, and re-injected unlabeled they read as project instructions
10
13
  * (#1455). `content` itself stays raw, because the edit flow reads it and
11
14
  * writes it back, and a label in there would be stored as guideline text.
12
15
  */
13
16
  agentContent: string | null;
17
+ /**
18
+ * When the user approved exactly this text (#1929), or null: nothing stored,
19
+ * stored before review was required, or rewritten since by a client that
20
+ * does not record reviews.
21
+ */
22
+ reviewedAt: string | null;
14
23
  /** UTF-8 byte size of `content`, or 0 when content is null. */
15
24
  byteSize: number;
16
25
  /** Whether a guidelines file exists for this repo. */
@@ -72,6 +81,15 @@ export interface FetchCorpusOutput {
72
81
  */
73
82
  warnings?: string[];
74
83
  }
84
+ export interface MarkProposedOutput {
85
+ repo: string;
86
+ /** The proposal file that was found, from {@link guidelineProposalPath}. */
87
+ path: string;
88
+ /** PRs stamped `learningsProposedAt` this call. */
89
+ marked: number;
90
+ /** Set when the post-mutation Gist checkpoint failed; the local mutation succeeded (#1370). */
91
+ gistSyncWarning?: string;
92
+ }
75
93
  interface RepoOption {
76
94
  repo: string;
77
95
  }
@@ -83,7 +101,37 @@ interface FetchCorpusOptions extends RepoOption {
83
101
  }
84
102
  interface StoreOptions extends RepoOption {
85
103
  content: string;
104
+ /**
105
+ * The caller's assertion that the user saw this exact text and approved it
106
+ * (#1929). Required and must be `true`: guidelines are distilled from other
107
+ * people's PR comments and are later read back by agents, so nothing is
108
+ * stored on the model's say-so alone.
109
+ */
110
+ reviewed: boolean;
111
+ /** When set, refuse unless `content` hashes to it: the text the user approved via `draft show` (#1930). */
112
+ expectSha256?: string;
86
113
  }
114
+ /** Whether `repo` is a name a proposal file can be named after (#2041); others get no proposal. */
115
+ export declare function isProposalRepo(repo: string): boolean;
116
+ /**
117
+ * Where this machine keeps the guideline proposal for `repo` (#1929, #2041):
118
+ * `guidelines-<owner>--<repo>.md` in the draft directory. The only place the
119
+ * name is computed; the prompts take it from `daily` or `draft path`.
120
+ */
121
+ export declare function guidelineProposalPath(repo: string): string;
122
+ /**
123
+ * Whether a guideline proposal for `repo` is waiting for review (#2041).
124
+ * `prs` are the repo's PRs that still lack `learningsExtractedAt`.
125
+ *
126
+ * A file at {@link guidelineProposalPath} is a proposal on this machine.
127
+ * Without one, a `learningsProposedAt` stamp written by another machine
128
+ * (`guidelines mark-proposed`, synced through the Gist) means a proposal for
129
+ * these PRs waits there, so this machine must not extract them again. Both
130
+ * expire with the draft retention, {@link MAX_DRAFT_AGE_MS}: `getDraftsDir`
131
+ * deletes an older file, and an older stamp is ignored. A stamp this machine
132
+ * wrote whose file is gone is ignored too, so the repo is extracted again.
133
+ */
134
+ export declare function guidelineProposalStatus(repo: string, prs: ReadonlyArray<Pick<StoredMergedPR, 'learningsProposedAt' | 'learningsProposedOn'>>, nowMs?: number): GuidelineProposalStatus;
87
135
  /** Read the per-repo guidelines for `repo`. Returns a `local-unavailable` envelope in non-Gist mode. */
88
136
  export declare function runGuidelinesView(options: RepoOption): Promise<GuidelinesViewOutput>;
89
137
  /**
@@ -96,6 +144,12 @@ export declare function runGuidelinesList(): Promise<GuidelinesListOutput>;
96
144
  * Persist per-repo guidelines for `repo`. Throws when not in Gist mode or
97
145
  * when content exceeds the byte budget — the CLI surface relies on the
98
146
  * outputJson error envelope to surface that to the host cleanly.
147
+ *
148
+ * Two gates sit here, where the CLI, the MCP tool and library callers all
149
+ * pass (#1929). An unattended run never stores: nobody is there to read the
150
+ * text. An attended caller must pass `reviewed: true`; that flag is an
151
+ * assertion the code cannot verify, so it stops a flow that forgot the review
152
+ * step, not a caller that lies.
99
153
  */
100
154
  export declare function runGuidelinesStore(options: StoreOptions): Promise<GuidelinesStoreOutput>;
101
155
  /**
@@ -106,7 +160,20 @@ export declare function runGuidelinesStore(options: StoreOptions): Promise<Guide
106
160
  * as unextracted. Idempotent: already-stamped PRs are left alone.
107
161
  */
108
162
  export declare function runMarkExtracted(options: RepoOption): Promise<MarkExtractedOutput>;
109
- /** Tombstone the guidelines file for `repo`. */
163
+ /**
164
+ * Record that the proposal file for `repo` is written and waits for review on
165
+ * this machine (#2041): stamp `learningsProposedAt` and this machine's id on
166
+ * the PRs it was built from (fetched, not yet extracted). The stamp is synced
167
+ * through the Gist, so another machine's `daily` reports the proposal as held
168
+ * elsewhere instead of extracting the same PRs again. Refuses when no file
169
+ * is at {@link guidelineProposalPath}.
170
+ */
171
+ export declare function runMarkProposed(options: RepoOption): Promise<MarkProposedOutput>;
172
+ /**
173
+ * Tombstone the guidelines file for `repo`. Refused during an unattended run,
174
+ * like {@link runGuidelinesStore}: the stored text is guidelines the user
175
+ * reviewed, and nobody is there to agree to losing them (#2036).
176
+ */
110
177
  export declare function runGuidelinesReset(options: RepoOption): Promise<GuidelinesResetOutput>;
111
178
  /**
112
179
  * Fetch raw PR comment bundles for the most recent merged/closed PRs in `repo`
@@ -7,16 +7,26 @@
7
7
  * `guidelines reset` — tombstone the file so subsequent reads return null.
8
8
  * `guidelines fetch-corpus` — pull raw PR comment bundles for the host's
9
9
  * extract-learnings prompt to consume.
10
+ * `guidelines mark-proposed` — record that a proposal file waits for review
11
+ * on this machine (#2041).
10
12
  *
11
13
  * The CLI layer is pure data plumbing — extraction is the host's job.
12
14
  * Standalone-mode users see "not available" on store/reset/fetch-corpus
13
15
  * because per-repo guidelines require Gist persistence to be useful.
14
16
  */
15
- import { getStateManager, requireGitHubToken, getOctokit, GuidelinesNotAvailableError, labelGuidelinesContent, maybeCheckpoint, } from '../core/index.js';
17
+ import { createHash } from 'node:crypto';
18
+ import * as fs from 'node:fs';
19
+ import path from 'node:path';
20
+ import { getStateManager, requireGitHubToken, getOctokit, GuidelinesNotAvailableError, GUIDELINES_PROVENANCE_NOTE, wrapUntrustedContent, maybeCheckpoint, getMachineId, } from '../core/index.js';
21
+ import { ValidationError, assertAttended } from '../core/errors.js';
16
22
  import { fetchPRCommentBundlesBatch } from '../core/pr-comments-fetcher.js';
17
23
  import { warn } from '../core/logger.js';
24
+ import { assertSha256, getDraftsDir, MAX_DRAFT_AGE_MS } from './draft.js';
18
25
  const MODULE = 'guidelines';
19
26
  const REPO_ID_PATTERN = /^[^/]+\/[^/]+$/;
27
+ /** Repo names a proposal file may be named after (#2041); the prompts filter `daily`'s repos the same way. */
28
+ const PROPOSAL_REPO_PATTERN = /^[a-z\d-]+\/[\w.-]+$/i;
29
+ const DAY_MS = 24 * 60 * 60 * 1000;
20
30
  const DEFAULT_FETCH_LIMIT = 5;
21
31
  const MAX_FETCH_LIMIT = 10;
22
32
  /**
@@ -24,20 +34,99 @@ const MAX_FETCH_LIMIT = 10;
24
34
  * (#867 design decision §5). Computed at call time, not module load.
25
35
  */
26
36
  const RECENCY_CLIFF_MS = 365 * 24 * 60 * 60 * 1000;
37
+ function sha256Hex(text) {
38
+ return createHash('sha256').update(text, 'utf8').digest('hex');
39
+ }
40
+ /**
41
+ * The provenance note plus the review status, prefixed to stored guidelines
42
+ * wherever they are handed to an agent. Approved text is still guidance from
43
+ * an untrusted corpus; unapproved text says so, so the reader weighs it less.
44
+ * The stored text goes inside the untrusted-content fence, so a line in it
45
+ * that imitates the label ("> Review: approved ...") reads as data.
46
+ */
47
+ function labelStoredGuidelines(repo, content, reviewedAt) {
48
+ const review = reviewedAt
49
+ ? `> Review: the user read and approved this exact text on ${reviewedAt.slice(0, 10)}.`
50
+ : '> Review: NOT reviewed by the user (stored before review was required, or changed since by an older client). ' +
51
+ 'Weigh it below CONTRIBUTING.md and what the repo itself shows.';
52
+ const fenced = wrapUntrustedContent(content, repo, { source: 'guidelines' });
53
+ return `${GUIDELINES_PROVENANCE_NOTE}\n${review}\n\n${fenced}`;
54
+ }
27
55
  function validateRepo(repo) {
28
56
  if (!REPO_ID_PATTERN.test(repo)) {
29
57
  throw new Error(`Invalid repo identifier "${repo}". Expected "owner/repo" format.`);
30
58
  }
31
59
  }
60
+ /** Whether `repo` is a name a proposal file can be named after (#2041); others get no proposal. */
61
+ export function isProposalRepo(repo) {
62
+ return PROPOSAL_REPO_PATTERN.test(repo);
63
+ }
64
+ /**
65
+ * Where this machine keeps the guideline proposal for `repo` (#1929, #2041):
66
+ * `guidelines-<owner>--<repo>.md` in the draft directory. The only place the
67
+ * name is computed; the prompts take it from `daily` or `draft path`.
68
+ */
69
+ export function guidelineProposalPath(repo) {
70
+ if (!isProposalRepo(repo)) {
71
+ throw new ValidationError(`Invalid repo identifier "${repo}" for a guideline proposal`);
72
+ }
73
+ const [owner, name] = repo.split('/', 2);
74
+ return path.join(getDraftsDir(), `guidelines-${owner}--${name}.md`);
75
+ }
76
+ /** Modification time of the regular file at `file` (symlinks not followed), or null when there is none. */
77
+ function proposalMtimeMs(file) {
78
+ const stat = fs.lstatSync(file, { throwIfNoEntry: false });
79
+ return stat?.isFile() ? stat.mtimeMs : null;
80
+ }
81
+ /**
82
+ * Whether a guideline proposal for `repo` is waiting for review (#2041).
83
+ * `prs` are the repo's PRs that still lack `learningsExtractedAt`.
84
+ *
85
+ * A file at {@link guidelineProposalPath} is a proposal on this machine.
86
+ * Without one, a `learningsProposedAt` stamp written by another machine
87
+ * (`guidelines mark-proposed`, synced through the Gist) means a proposal for
88
+ * these PRs waits there, so this machine must not extract them again. Both
89
+ * expire with the draft retention, {@link MAX_DRAFT_AGE_MS}: `getDraftsDir`
90
+ * deletes an older file, and an older stamp is ignored. A stamp this machine
91
+ * wrote whose file is gone is ignored too, so the repo is extracted again.
92
+ */
93
+ export function guidelineProposalStatus(repo, prs, nowMs = Date.now()) {
94
+ const proposalPath = guidelineProposalPath(repo);
95
+ const ageDays = (ms) => Math.max(0, Math.floor((nowMs - ms) / DAY_MS));
96
+ const localMs = proposalMtimeMs(proposalPath);
97
+ if (localMs !== null) {
98
+ return { repo, proposalPath, proposalAgeDays: ageDays(localMs), proposalOnThisMachine: true };
99
+ }
100
+ const self = getMachineId();
101
+ const cutoff = nowMs - MAX_DRAFT_AGE_MS;
102
+ let newest = null;
103
+ for (const pr of prs) {
104
+ if (!pr.learningsProposedAt || (self !== undefined && pr.learningsProposedOn === self))
105
+ continue;
106
+ const at = Date.parse(pr.learningsProposedAt);
107
+ if (at > cutoff && (newest === null || at > newest))
108
+ newest = at;
109
+ }
110
+ return {
111
+ repo,
112
+ proposalPath,
113
+ proposalAgeDays: newest === null ? null : ageDays(newest),
114
+ proposalOnThisMachine: false,
115
+ };
116
+ }
32
117
  /** Read the per-repo guidelines for `repo`. Returns a `local-unavailable` envelope in non-Gist mode. */
118
+ // eslint-disable-next-line @typescript-eslint/require-await -- async keeps the Promise-returning contract callers rely on; the body has no await yet
33
119
  export async function runGuidelinesView(options) {
34
120
  validateRepo(options.repo);
35
121
  const sm = getStateManager();
36
122
  const content = sm.getGuidelines(options.repo);
123
+ const review = content === null ? undefined : sm.getGuidelinesReview(options.repo);
124
+ const reviewedAt = review && content !== null && review.sha256 === sha256Hex(content) ? review.reviewedAt : null;
37
125
  return {
38
126
  repo: options.repo,
39
127
  content,
40
- agentContent: content === null ? null : labelGuidelinesContent(content),
128
+ agentContent: content === null ? null : labelStoredGuidelines(options.repo, content, reviewedAt),
129
+ reviewedAt,
41
130
  byteSize: content === null ? 0 : Buffer.byteLength(content, 'utf8'),
42
131
  exists: content !== null,
43
132
  storageMode: sm.isGuidelinesAvailable() ? 'gist' : 'local-unavailable',
@@ -48,6 +137,7 @@ export async function runGuidelinesView(options) {
48
137
  * mode — returns an empty list with `storageMode: 'local-unavailable'` so
49
138
  * hosts can distinguish "nothing stored" from "storage not configured".
50
139
  */
140
+ // eslint-disable-next-line @typescript-eslint/require-await -- async keeps the Promise-returning contract callers rely on; the body has no await yet
51
141
  export async function runGuidelinesList() {
52
142
  const sm = getStateManager();
53
143
  const repos = sm.listGuidelinesRepos();
@@ -61,19 +151,38 @@ export async function runGuidelinesList() {
61
151
  * Persist per-repo guidelines for `repo`. Throws when not in Gist mode or
62
152
  * when content exceeds the byte budget — the CLI surface relies on the
63
153
  * outputJson error envelope to surface that to the host cleanly.
154
+ *
155
+ * Two gates sit here, where the CLI, the MCP tool and library callers all
156
+ * pass (#1929). An unattended run never stores: nobody is there to read the
157
+ * text. An attended caller must pass `reviewed: true`; that flag is an
158
+ * assertion the code cannot verify, so it stops a flow that forgot the review
159
+ * step, not a caller that lies.
64
160
  */
65
161
  export async function runGuidelinesStore(options) {
66
162
  validateRepo(options.repo);
163
+ assertAttended('store guidelines');
164
+ if (!options.reviewed) {
165
+ throw new ValidationError('Refusing to store guidelines the user has not reviewed. Show the user the exact text, and once they approve it ' +
166
+ 'store again with --reviewed (CLI) or reviewed: true (MCP tool).');
167
+ }
67
168
  if (!options.content || options.content.length === 0) {
68
169
  throw new Error('Cannot store empty content. Use `guidelines reset` to delete a guidelines file.');
69
170
  }
171
+ assertSha256(options.content, options.expectSha256);
70
172
  const sm = getStateManager();
71
173
  // Throws GuidelinesNotAvailableError or GuidelinesTooLargeError on failure.
72
- sm.setGuidelines(options.repo, options.content);
174
+ const sha256 = sha256Hex(options.content);
175
+ const now = new Date();
176
+ const reviewedAt = now.toISOString();
177
+ const persist = () => {
178
+ sm.setGuidelines(options.repo, options.content);
179
+ sm.markGuidelinesReviewed(options.repo, sha256, reviewedAt);
180
+ };
181
+ persist();
73
182
  // Push to Gist — autoSave only writes the local state-cache mirror in Gist
74
183
  // mode, so without this checkpoint the change never propagates across
75
184
  // machines (#1200).
76
- const gistSyncWarning = await maybeCheckpoint(sm, MODULE, () => sm.setGuidelines(options.repo, options.content));
185
+ const gistSyncWarning = await maybeCheckpoint(sm, MODULE, persist);
77
186
  return {
78
187
  repo: options.repo,
79
188
  byteSize: Buffer.byteLength(options.content, 'utf8'),
@@ -81,6 +190,13 @@ export async function runGuidelinesStore(options) {
81
190
  ...(gistSyncWarning && { gistSyncWarning }),
82
191
  };
83
192
  }
193
+ /** Merged and closed PRs of `repo` whose comment bundle was fetched but not yet marked extracted. */
194
+ function fetchedUnextractedPRUrls(sm, repo) {
195
+ const repoUrlPrefix = `https://github.com/${repo}/`;
196
+ return [...(sm.getMergedPRs() ?? []), ...(sm.getClosedPRs() ?? [])]
197
+ .filter((pr) => pr.url.startsWith(repoUrlPrefix) && pr.commentsFetchedAt && !pr.learningsExtractedAt)
198
+ .map((pr) => pr.url);
199
+ }
84
200
  /**
85
201
  * Stamp `learningsExtractedAt` on every merged/closed PR of `repo` whose
86
202
  * comment bundle was fetched (`commentsFetchedAt` set) but not yet marked
@@ -91,25 +207,53 @@ export async function runGuidelinesStore(options) {
91
207
  export async function runMarkExtracted(options) {
92
208
  validateRepo(options.repo);
93
209
  const sm = getStateManager();
94
- const repoUrlPrefix = `https://github.com/${options.repo}/`;
95
210
  const now = new Date().toISOString();
96
211
  const mark = () => {
97
- let n = 0;
98
- for (const pr of [...(sm.getMergedPRs() ?? []), ...(sm.getClosedPRs() ?? [])]) {
99
- if (!pr.url.startsWith(repoUrlPrefix) || !pr.commentsFetchedAt || pr.learningsExtractedAt)
100
- continue;
101
- sm.markPRLearningsExtracted(pr.url, now);
102
- n++;
103
- }
104
- return n;
212
+ const urls = fetchedUnextractedPRUrls(sm, options.repo);
213
+ for (const url of urls)
214
+ sm.markPRLearningsExtracted(url, now);
215
+ return urls.length;
105
216
  };
106
217
  const marked = mark();
107
218
  const gistSyncWarning = marked > 0 ? await maybeCheckpoint(sm, MODULE, mark) : null;
108
219
  return { repo: options.repo, marked, ...(gistSyncWarning && { gistSyncWarning }) };
109
220
  }
110
- /** Tombstone the guidelines file for `repo`. */
221
+ /**
222
+ * Record that the proposal file for `repo` is written and waits for review on
223
+ * this machine (#2041): stamp `learningsProposedAt` and this machine's id on
224
+ * the PRs it was built from (fetched, not yet extracted). The stamp is synced
225
+ * through the Gist, so another machine's `daily` reports the proposal as held
226
+ * elsewhere instead of extracting the same PRs again. Refuses when no file
227
+ * is at {@link guidelineProposalPath}.
228
+ */
229
+ export async function runMarkProposed(options) {
230
+ validateRepo(options.repo);
231
+ const proposalPath = guidelineProposalPath(options.repo);
232
+ if (proposalMtimeMs(proposalPath) === null) {
233
+ throw new ValidationError(`No guideline proposal at ${proposalPath}: write it there first`);
234
+ }
235
+ const sm = getStateManager();
236
+ const proposedAt = new Date();
237
+ const now = proposedAt.toISOString();
238
+ const machineId = getMachineId();
239
+ const mark = () => {
240
+ const urls = fetchedUnextractedPRUrls(sm, options.repo);
241
+ for (const url of urls)
242
+ sm.markPRLearningsProposed(url, now, machineId);
243
+ return urls.length;
244
+ };
245
+ const marked = mark();
246
+ const gistSyncWarning = marked > 0 ? await maybeCheckpoint(sm, MODULE, mark) : null;
247
+ return { repo: options.repo, path: proposalPath, marked, ...(gistSyncWarning && { gistSyncWarning }) };
248
+ }
249
+ /**
250
+ * Tombstone the guidelines file for `repo`. Refused during an unattended run,
251
+ * like {@link runGuidelinesStore}: the stored text is guidelines the user
252
+ * reviewed, and nobody is there to agree to losing them (#2036).
253
+ */
111
254
  export async function runGuidelinesReset(options) {
112
255
  validateRepo(options.repo);
256
+ assertAttended('reset guidelines');
113
257
  const sm = getStateManager();
114
258
  if (!sm.isGuidelinesAvailable()) {
115
259
  throw new GuidelinesNotAvailableError();
@@ -35,8 +35,12 @@ export { runFeatures, MAX_FEATURES_RESULTS } from './features.js';
35
35
  export { runVet } from './vet.js';
36
36
  /** Deterministic availability check: state/stateReason + linked-PR classification (#1353, #1354). */
37
37
  export { runVerifyIssue, type VerifyIssueOptions } from './verify-issue.js';
38
+ /** Read one issue's title, body and comments, each fenced as untrusted content (#1932). */
39
+ export { runIssueThread, type IssueThreadOptions } from './issue-thread.js';
38
40
  /** Re-vet all available issues in a curated issue list for freshness. */
39
41
  export { runVetList } from './vet-list.js';
42
+ /** The curated issue list this machine is configured to use; throws when none is usable (#2035). */
43
+ export { configuredIssueListPath } from './locate-issue-list.js';
40
44
  export { runEval, type EvalOutput } from './eval.js';
41
45
  /** Fetch PR metadata from GitHub (informational; nothing is persisted). */
42
46
  export { runTrack } from './track.js';
@@ -56,8 +60,11 @@ export { runWorkClaim, runWorkFinish, runWorkRelease, runWorkList } from './work
56
60
  export { runComments } from './comments.js';
57
61
  /** Post a comment to a GitHub issue or PR. */
58
62
  export { runPost } from './comments.js';
63
+ export { runForkPrune } from './fork-prune.js';
59
64
  /** Post a claim comment on a GitHub issue. */
60
- export { runClaim } from './comments.js';
65
+ export { runClaim, DEFAULT_CLAIM_MESSAGE } from './comments.js';
66
+ /** Run the PR preflight checks on the staged title and body, then open the PR (#2085). */
67
+ export { runPrCreate } from './pr-create.js';
61
68
  /** Read or write user configuration (githubUsername, languages, labels, etc). */
62
69
  export { runConfig } from './config.js';
63
70
  /** Initialize with a GitHub username and import open PRs. */
@@ -74,6 +81,8 @@ export { runGuidelinesView } from './guidelines.js';
74
81
  export { runGuidelinesStore } from './guidelines.js';
75
82
  /** Tombstone a guidelines file so subsequent reads return null. */
76
83
  export { runGuidelinesReset } from './guidelines.js';
84
+ /** Read a repo's contribution policy (#1953). `policy set` / `reset` are CLI-only. */
85
+ export { runPolicyGet } from './policy.js';
77
86
  /** Fetch raw PR comment bundles for the host's extract-learnings prompt. */
78
87
  export { runFetchCorpus } from './guidelines.js';
79
88
  /** Show current persistence mode, Gist ID, and sync status. */
@@ -90,11 +99,19 @@ export { runListMoveTier, moveIssueToTier, type Tier, type ListMoveTierOptions,
90
99
  export { runMarkIssueListItemDone, markIssueAsDone, type MarkDoneOptions, type MarkDoneOutput, } from './list-mark-done.js';
91
100
  /** Daily merge-loop reconciliation — auto-mark curated-list entries whose PR merged (#1463). */
92
101
  export { reconcileMergedPRsWithList, findListEntryUrlByPrUrl } from './merge-loop.js';
93
- /** Check if new files are properly referenced/integrated. */
102
+ /**
103
+ * Check if new files are properly referenced/integrated.
104
+ *
105
+ * @deprecated Since #1948; will be removed in the next major version.
106
+ */
94
107
  export { runCheckIntegration } from './check-integration.js';
95
108
  /** System-health diagnostic — verifies tokens, bundle, state, scout, rate limit. */
96
109
  export { runDoctor, type DoctorCheck, type DoctorCheckStatus, type DoctorOutput } from './doctor.js';
97
- /** Detect formatters/linters configured in a local repository (#703). */
110
+ /**
111
+ * Detect formatters/linters configured in a local repository (#703).
112
+ *
113
+ * @deprecated Since #1948; will be removed in the next major version.
114
+ */
98
115
  export { runDetectFormatters } from './detect-formatters.js';
99
116
  /** Scan for locally cloned repos. */
100
117
  export { runLocalRepos } from './local-repos.js';
@@ -102,9 +119,17 @@ export type { DashboardJsonData, DashboardStats, DashboardActionType, ActionRequ
102
119
  export type { ErrorCode } from '../formatters/json.js';
103
120
  export type { DailyOutput, SearchOutput, SearchCandidate, CandidateLinkedPR, FeaturesOutput, FeaturesCandidate, FeaturesHorizon, StartupOutput, StatusOutput, TrackOutput, } from '../formatters/json.js';
104
121
  export type { VetOutput, CommentsOutput, PostOutput, ClaimOutput, VetListOutput, VetListItemStatus, } from '../formatters/json.js';
105
- export type { ConfigOutput, DetectFormattersOutput, ParseIssueListOutput, ParsedIssueItem, CheckIntegrationOutput, LocalReposOutput, } from '../formatters/json.js';
122
+ export type { ConfigOutput, ParseIssueListOutput, ParsedIssueItem, LocalReposOutput } from '../formatters/json.js';
123
+ /**
124
+ * Output types of the deprecated detect-formatters and orphan-files commands.
125
+ *
126
+ * @deprecated Since #1948; will be removed in the next major version.
127
+ */
128
+ export type { DetectFormattersOutput, CheckIntegrationOutput } from '../formatters/json.js';
106
129
  export type { MoveOutput, MoveTarget } from './move.js';
107
130
  export type { GuidelinesListOutput, GuidelinesViewOutput, GuidelinesStoreOutput, GuidelinesResetOutput, FetchCorpusOutput, } from './guidelines.js';
131
+ export type { PolicyGetOutput } from './policy.js';
132
+ export type { RepoPolicySummary } from '../core/repo-policy.js';
108
133
  export type { DismissOutput, UndismissOutput } from './dismiss.js';
109
134
  export type { WorkClaimOptions, WorkClaimOutcome, WorkClaimOutput, WorkFinishOptions, WorkFinishOutput, WorkReleaseOptions, WorkReleaseOutput, WorkListOutput, } from './work.js';
110
135
  export type { InitOutput } from './init.js';
@@ -36,8 +36,12 @@ export { runFeatures, MAX_FEATURES_RESULTS } from './features.js';
36
36
  export { runVet } from './vet.js';
37
37
  /** Deterministic availability check: state/stateReason + linked-PR classification (#1353, #1354). */
38
38
  export { runVerifyIssue } from './verify-issue.js';
39
+ /** Read one issue's title, body and comments, each fenced as untrusted content (#1932). */
40
+ export { runIssueThread } from './issue-thread.js';
39
41
  /** Re-vet all available issues in a curated issue list for freshness. */
40
42
  export { runVetList } from './vet-list.js';
43
+ /** The curated issue list this machine is configured to use; throws when none is usable (#2035). */
44
+ export { configuredIssueListPath } from './locate-issue-list.js';
41
45
  export { runEval } from './eval.js';
42
46
  // ── PR Management ───────────────────────────────────────────────────────────
43
47
  /** Fetch PR metadata from GitHub (informational; nothing is persisted). */
@@ -59,8 +63,11 @@ export { runWorkClaim, runWorkFinish, runWorkRelease, runWorkList } from './work
59
63
  export { runComments } from './comments.js';
60
64
  /** Post a comment to a GitHub issue or PR. */
61
65
  export { runPost } from './comments.js';
66
+ export { runForkPrune } from './fork-prune.js';
62
67
  /** Post a claim comment on a GitHub issue. */
63
- export { runClaim } from './comments.js';
68
+ export { runClaim, DEFAULT_CLAIM_MESSAGE } from './comments.js';
69
+ /** Run the PR preflight checks on the staged title and body, then open the PR (#2085). */
70
+ export { runPrCreate } from './pr-create.js';
64
71
  // ── Configuration & Setup ───────────────────────────────────────────────────
65
72
  /** Read or write user configuration (githubUsername, languages, labels, etc). */
66
73
  export { runConfig } from './config.js';
@@ -79,6 +86,8 @@ export { runGuidelinesView } from './guidelines.js';
79
86
  export { runGuidelinesStore } from './guidelines.js';
80
87
  /** Tombstone a guidelines file so subsequent reads return null. */
81
88
  export { runGuidelinesReset } from './guidelines.js';
89
+ /** Read a repo's contribution policy (#1953). `policy set` / `reset` are CLI-only. */
90
+ export { runPolicyGet } from './policy.js';
82
91
  /** Fetch raw PR comment bundles for the host's extract-learnings prompt. */
83
92
  export { runFetchCorpus } from './guidelines.js';
84
93
  // ── State Persistence ────────────────────────────────────────────────────────
@@ -97,11 +106,19 @@ export { runListMoveTier, moveIssueToTier, } from './list-move-tier.js';
97
106
  export { runMarkIssueListItemDone, markIssueAsDone, } from './list-mark-done.js';
98
107
  /** Daily merge-loop reconciliation — auto-mark curated-list entries whose PR merged (#1463). */
99
108
  export { reconcileMergedPRsWithList, findListEntryUrlByPrUrl } from './merge-loop.js';
100
- /** Check if new files are properly referenced/integrated. */
109
+ /**
110
+ * Check if new files are properly referenced/integrated.
111
+ *
112
+ * @deprecated Since #1948; will be removed in the next major version.
113
+ */
101
114
  export { runCheckIntegration } from './check-integration.js';
102
115
  /** System-health diagnostic — verifies tokens, bundle, state, scout, rate limit. */
103
116
  export { runDoctor } from './doctor.js';
104
- /** Detect formatters/linters configured in a local repository (#703). */
117
+ /**
118
+ * Detect formatters/linters configured in a local repository (#703).
119
+ *
120
+ * @deprecated Since #1948; will be removed in the next major version.
121
+ */
105
122
  export { runDetectFormatters } from './detect-formatters.js';
106
123
  /** Scan for locally cloned repos. */
107
124
  export { runLocalRepos } from './local-repos.js';
@@ -0,0 +1,46 @@
1
+ /**
2
+ * issue-thread command (#1932).
3
+ *
4
+ * The fenced way to read an issue: title, body and every comment reach the
5
+ * agent wrapped in `<github-content>` with author and author association
6
+ * (body and comments fenced here; the title by the CLI action or, on MCP, by
7
+ * the server's `fenceTitlesDeep`). Raw
8
+ * `gh issue view` output passes through no code in this repo, so an agent
9
+ * told to read a thread with it reads stranger-written text unfenced. The
10
+ * unattended implement mode (agents/overnight-preparer.md) reads threads
11
+ * through this command instead.
12
+ */
13
+ import type { IssueThreadOutput } from '../formatters/json.js';
14
+ export interface IssueThreadOptions {
15
+ issueUrl: string;
16
+ }
17
+ /**
18
+ * Per-body character cap, applied before fencing. GitHub allows 65,536
19
+ * characters per body; a thread is read whole by an agent, so one pasted log
20
+ * must not crowd out the rest.
21
+ * ponytail: per-body cap only. Thread length is bounded by the shared
22
+ * pagination cap (1000 comments); add a whole-thread budget if that proves
23
+ * too much for a reader.
24
+ */
25
+ export declare const MAX_ISSUE_THREAD_BODY_CHARS = 20000;
26
+ /**
27
+ * Fence the title of a thread returned by {@link runIssueThread}. The CLI
28
+ * applies this to everything it prints, with or without `--json`.
29
+ */
30
+ export declare function fenceIssueThreadTitle(thread: IssueThreadOutput): IssueThreadOutput;
31
+ /**
32
+ * Fetch one issue's title, body and comments. The body and every comment
33
+ * come back fenced as untrusted content.
34
+ *
35
+ * The `title` comes back RAW, like every other producer's title: the MCP
36
+ * server fences `title` in every tool result (`fenceTitlesDeep`, #1931), so
37
+ * fencing it here too would put a fence inside a fence there. The CLI fences
38
+ * it with {@link fenceIssueThreadTitle}. Any other caller that hands this
39
+ * result to an agent must do the same.
40
+ *
41
+ * Nothing is filtered: bot comments and the user's own comments are part of
42
+ * the discussion an implementer needs. Comments come oldest first.
43
+ *
44
+ * @throws {ValidationError} If the URL is not a valid GitHub issue URL.
45
+ */
46
+ export declare function runIssueThread(options: IssueThreadOptions): Promise<IssueThreadOutput>;