@nanonets/graft 0.22.0 → 0.23.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 (140) hide show
  1. package/README.md +11 -10
  2. package/dist/app/checkout.d.ts +0 -32
  3. package/dist/app/checkout.d.ts.map +1 -1
  4. package/dist/app/checkout.js +0 -45
  5. package/dist/app/checkout.js.map +1 -1
  6. package/dist/app/identity.d.ts +0 -56
  7. package/dist/app/identity.d.ts.map +1 -1
  8. package/dist/app/identity.js +0 -119
  9. package/dist/app/identity.js.map +1 -1
  10. package/dist/app/main.js +0 -8
  11. package/dist/app/main.js.map +1 -1
  12. package/dist/app/server.d.ts +0 -20
  13. package/dist/app/server.d.ts.map +1 -1
  14. package/dist/app/server.js +0 -121
  15. package/dist/app/server.js.map +1 -1
  16. package/dist/ask/ask.d.ts +0 -3
  17. package/dist/ask/ask.d.ts.map +1 -1
  18. package/dist/ask/ask.js +1 -3
  19. package/dist/ask/ask.js.map +1 -1
  20. package/dist/brand.d.ts.map +1 -1
  21. package/dist/brand.js +4 -1
  22. package/dist/brand.js.map +1 -1
  23. package/dist/check/learning-edits.d.ts +9 -0
  24. package/dist/check/learning-edits.d.ts.map +1 -0
  25. package/dist/check/learning-edits.js +62 -0
  26. package/dist/check/learning-edits.js.map +1 -0
  27. package/dist/claude/format.d.ts +1 -9
  28. package/dist/claude/format.d.ts.map +1 -1
  29. package/dist/claude/format.js +6 -21
  30. package/dist/claude/format.js.map +1 -1
  31. package/dist/claude/hook-layers.d.ts.map +1 -1
  32. package/dist/claude/hook-layers.js +5 -3
  33. package/dist/claude/hook-layers.js.map +1 -1
  34. package/dist/claude/hooks.d.ts +6 -0
  35. package/dist/claude/hooks.d.ts.map +1 -1
  36. package/dist/claude/hooks.js +101 -14
  37. package/dist/claude/hooks.js.map +1 -1
  38. package/dist/claude/init.d.ts +38 -7
  39. package/dist/claude/init.d.ts.map +1 -1
  40. package/dist/claude/init.js +172 -33
  41. package/dist/claude/init.js.map +1 -1
  42. package/dist/claude/settings-merge.d.ts +23 -0
  43. package/dist/claude/settings-merge.d.ts.map +1 -1
  44. package/dist/claude/settings-merge.js +103 -7
  45. package/dist/claude/settings-merge.js.map +1 -1
  46. package/dist/claude/shim-template.d.ts.map +1 -1
  47. package/dist/claude/shim-template.js +39 -3
  48. package/dist/claude/shim-template.js.map +1 -1
  49. package/dist/claude/skill-template.d.ts +4 -3
  50. package/dist/claude/skill-template.d.ts.map +1 -1
  51. package/dist/claude/skill-template.js +25 -10
  52. package/dist/claude/skill-template.js.map +1 -1
  53. package/dist/claude/state.d.ts +1 -1
  54. package/dist/claude/state.d.ts.map +1 -1
  55. package/dist/cli-picker.d.ts +15 -0
  56. package/dist/cli-picker.d.ts.map +1 -1
  57. package/dist/cli-picker.js +33 -3
  58. package/dist/cli-picker.js.map +1 -1
  59. package/dist/cli.js +141 -60
  60. package/dist/cli.js.map +1 -1
  61. package/dist/cloud/diff.d.ts +2 -0
  62. package/dist/cloud/diff.d.ts.map +1 -1
  63. package/dist/cloud/diff.js +1 -0
  64. package/dist/cloud/diff.js.map +1 -1
  65. package/dist/context/map-dir.d.ts +13 -0
  66. package/dist/context/map-dir.d.ts.map +1 -0
  67. package/dist/context/map-dir.js +67 -0
  68. package/dist/context/map-dir.js.map +1 -0
  69. package/dist/context/node-file.d.ts +4 -3
  70. package/dist/context/node-file.d.ts.map +1 -1
  71. package/dist/context/node-file.js +18 -4
  72. package/dist/context/node-file.js.map +1 -1
  73. package/dist/hosts/claude-global.d.ts.map +1 -1
  74. package/dist/hosts/claude-global.js +31 -11
  75. package/dist/hosts/claude-global.js.map +1 -1
  76. package/dist/hosts/config-write.js +1 -1
  77. package/dist/hosts/config-write.js.map +1 -1
  78. package/dist/hosts/retract.d.ts.map +1 -1
  79. package/dist/hosts/retract.js +15 -6
  80. package/dist/hosts/retract.js.map +1 -1
  81. package/dist/notes/branches.d.ts +18 -1
  82. package/dist/notes/branches.d.ts.map +1 -1
  83. package/dist/notes/branches.js +73 -7
  84. package/dist/notes/branches.js.map +1 -1
  85. package/dist/notes/cold-start.d.ts +54 -4
  86. package/dist/notes/cold-start.d.ts.map +1 -1
  87. package/dist/notes/cold-start.js +97 -36
  88. package/dist/notes/cold-start.js.map +1 -1
  89. package/dist/notes/edit-overlap.d.ts +62 -0
  90. package/dist/notes/edit-overlap.d.ts.map +1 -0
  91. package/dist/notes/edit-overlap.js +202 -0
  92. package/dist/notes/edit-overlap.js.map +1 -0
  93. package/dist/notes/notes.d.ts +25 -4
  94. package/dist/notes/notes.d.ts.map +1 -1
  95. package/dist/notes/notes.js +65 -15
  96. package/dist/notes/notes.js.map +1 -1
  97. package/dist/notes/pr-reviews.d.ts +108 -0
  98. package/dist/notes/pr-reviews.d.ts.map +1 -0
  99. package/dist/notes/pr-reviews.js +325 -0
  100. package/dist/notes/pr-reviews.js.map +1 -0
  101. package/dist/notes/repo-trail.d.ts +3 -1
  102. package/dist/notes/repo-trail.d.ts.map +1 -1
  103. package/dist/notes/repo-trail.js +40 -3
  104. package/dist/notes/repo-trail.js.map +1 -1
  105. package/dist/notes/session-cost.d.ts +16 -4
  106. package/dist/notes/session-cost.d.ts.map +1 -1
  107. package/dist/notes/session-cost.js +120 -11
  108. package/dist/notes/session-cost.js.map +1 -1
  109. package/dist/telemetry/contract.d.ts.map +1 -1
  110. package/dist/telemetry/contract.js +6 -5
  111. package/dist/telemetry/contract.js.map +1 -1
  112. package/dist/upkeep-run.d.ts.map +1 -1
  113. package/dist/upkeep-run.js +4 -2
  114. package/dist/upkeep-run.js.map +1 -1
  115. package/dist/upkeep.js +2 -2
  116. package/dist/upkeep.js.map +1 -1
  117. package/dist/util/state.d.ts.map +1 -1
  118. package/dist/util/state.js +2 -1
  119. package/dist/util/state.js.map +1 -1
  120. package/package.json +1 -1
  121. package/dist/app/brain-build-process.d.ts +0 -22
  122. package/dist/app/brain-build-process.d.ts.map +0 -1
  123. package/dist/app/brain-build-process.js +0 -129
  124. package/dist/app/brain-build-process.js.map +0 -1
  125. package/dist/app/brain-build-worker.d.ts +0 -35
  126. package/dist/app/brain-build-worker.d.ts.map +0 -1
  127. package/dist/app/brain-build-worker.js +0 -56
  128. package/dist/app/brain-build-worker.js.map +0 -1
  129. package/dist/app/brain-build.d.ts +0 -160
  130. package/dist/app/brain-build.d.ts.map +0 -1
  131. package/dist/app/brain-build.js +0 -278
  132. package/dist/app/brain-build.js.map +0 -1
  133. package/dist/app/history.d.ts +0 -163
  134. package/dist/app/history.d.ts.map +0 -1
  135. package/dist/app/history.js +0 -319
  136. package/dist/app/history.js.map +0 -1
  137. package/dist/app/sources.d.ts +0 -81
  138. package/dist/app/sources.d.ts.map +0 -1
  139. package/dist/app/sources.js +0 -470
  140. package/dist/app/sources.js.map +0 -1
@@ -1,163 +0,0 @@
1
- import type { GraphV1 } from "../graph/types.js";
2
- import { type Fetch } from "./identity.js";
3
- import type { HistorySource } from "./sources.js";
4
- /** One commit's rule-bearing content. */
5
- export interface HistoryCommit {
6
- sha: string;
7
- subject: string;
8
- body: string;
9
- files: string[];
10
- }
11
- /** One pull request's discussion. */
12
- export interface HistoryThread {
13
- number: number;
14
- title: string;
15
- body: string;
16
- mergeSha: string;
17
- comments: Array<{
18
- body: string;
19
- path?: string;
20
- }>;
21
- }
22
- /** One symbol, as the brain needs it to anchor a rule. */
23
- export interface HistorySymbol {
24
- id: string;
25
- path: string;
26
- name: string;
27
- kind: string;
28
- signature: string;
29
- fingerprint: string;
30
- }
31
- /** The whole payload posted to the brain. */
32
- export interface RepoDigest {
33
- provider: "github";
34
- owner: string;
35
- name: string;
36
- head_sha: string;
37
- default_branch: string;
38
- is_private: boolean;
39
- commits: Array<{
40
- sha: string;
41
- subject: string;
42
- body: string;
43
- files: string[];
44
- symbols: string[];
45
- }>;
46
- threads: Array<{
47
- number: number;
48
- title: string;
49
- body: string;
50
- merge_sha: string;
51
- comments: Array<{
52
- body: string;
53
- path?: string;
54
- }>;
55
- }>;
56
- symbols: HistorySymbol[];
57
- /** Everything in the repo that is already a rule, or nearly one: instruction
58
- * files, decision records, config, ownership, reverts, test names. One array
59
- * rather than a field per kind, so adding a source is adding an entry. */
60
- sources: HistorySource[];
61
- auto_approve: boolean;
62
- /** The agents `graft init` wired this repo for (claude, cursor, agents, …).
63
- * Trail shows only the context files those agents read. Absent or empty
64
- * means "not known", and Trail then shows every kind. */
65
- agents?: string[];
66
- }
67
- /**
68
- * Commit subjects, bodies and touched files, oldest first.
69
- *
70
- * `--no-merges`: a merge commit's message is "Merge pull request #N from …",
71
- * which establishes nothing — the decision is in the commits it brings in, and
72
- * in the thread. `--reverse` so a later reversal reads as a reversal downstream;
73
- * the extraction prompt relies on that ordering.
74
- */
75
- export declare function readCommits(root: string, max?: number): HistoryCommit[];
76
- /** How many threads' comments are fetched at once. Two requests per pull
77
- * request, so this is the real cost of a repository read. A pool of 24 (so at
78
- * most 48 requests in flight) stays well under GitHub's secondary limit on
79
- * concurrent requests, and a slow thread no longer holds up the seven that
80
- * happened to share its batch. */
81
- export declare const THREAD_FETCH_CONCURRENCY = 24;
82
- /**
83
- * What one push has already asked GitHub, shared between its reads.
84
- *
85
- * The early upload reads the newest pull requests and the full read reads them
86
- * again as part of the 200. Promises rather than results, so a full read that
87
- * starts while the early one is still in flight waits on the same request
88
- * instead of sending a second — and threads with no discussion are remembered
89
- * too, which a map of finished threads could not say.
90
- */
91
- export interface ThreadReadCache {
92
- /** Pages of the closed-pull-request list, by page number. */
93
- pages: Map<number, Promise<PullListItem[] | null>>;
94
- /** One pull request's discussion, by number; null when it had none. */
95
- threads: Map<number, Promise<HistoryThread | null>>;
96
- }
97
- export declare function newThreadReadCache(): ThreadReadCache;
98
- /** Run `fn` over `items` with at most `limit` in flight, results in input order. */
99
- export declare function mapPool<T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]>;
100
- export interface PullListItem {
101
- number?: number;
102
- title?: string;
103
- body?: string | null;
104
- merge_commit_sha?: string | null;
105
- }
106
- /**
107
- * Closed pull requests and their discussion, most-discussed first.
108
- *
109
- * Closed only: an open PR's discussion has not concluded, so mining a rule out
110
- * of it would record a proposal as a decision.
111
- *
112
- * Comment counts have to be discovered by fetching, not by reading the list.
113
- * GitHub's `GET /pulls` list response carries NO `comments` or
114
- * `review_comments` field — those exist only on the single-PR GET — so an
115
- * earlier version that pre-filtered on them read `undefined` for every pull
116
- * request, scored them all zero and skipped the lot. The failure was silent and
117
- * total: every repository came back with no discussion at all. So the comments
118
- * are fetched for the most recently updated closed pull requests, and the
119
- * ranking happens afterwards, on counts that are real.
120
- *
121
- * Bot comments are dropped. A CI bot posting a coverage table is the single
122
- * largest source of text in a busy repo's threads and it establishes nothing.
123
- */
124
- export declare function readThreads(owner: string, repo: string, token: string, fetchImpl: Fetch, api?: string, max?: number, known?: ReadonlyMap<number, HistoryThread>, cache?: ThreadReadCache): Promise<HistoryThread[]>;
125
- /**
126
- * Exported symbols from the graph, with the body hash that makes an anchored
127
- * rule self-invalidating.
128
- *
129
- * Exported only, and biggest first: an internal helper is not what a team's
130
- * rules are about, and the budget is better spent on the surface a rule is
131
- * likely to govern.
132
- */
133
- export declare function readSymbols(graph: GraphV1 | null, max?: number): HistorySymbol[];
134
- /**
135
- * Assemble the digest.
136
- *
137
- * Each commit carries the symbol ids its files touched, so a rule mined from a
138
- * commit message can be anchored even when the message names no symbol — which
139
- * is most of the time.
140
- */
141
- export declare function buildDigest(input: {
142
- owner: string;
143
- name: string;
144
- headSha: string;
145
- defaultBranch: string;
146
- isPrivate: boolean;
147
- commits: HistoryCommit[];
148
- threads: HistoryThread[];
149
- symbols: HistorySymbol[];
150
- sources: HistorySource[];
151
- autoApprove: boolean;
152
- agents?: string[];
153
- }): RepoDigest;
154
- /**
155
- * Post the digest to a brain.
156
- *
157
- * Returns the job id so the caller can hand it back to whoever asked for the
158
- * build, which is what the onboarding screen polls.
159
- */
160
- export declare function postDigest(baseUrl: string, brainId: string, brainToken: string, digest: RepoDigest, fetchImpl: Fetch): Promise<{
161
- jobId: string;
162
- }>;
163
- //# sourceMappingURL=history.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/app/history.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAED,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,KAAK,CAAC;QAAE,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BAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,KAAK,GACf,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB5B"}
@@ -1,319 +0,0 @@
1
- /**
2
- * Reading a repository's history into a rule-bearing digest.
3
- *
4
- * What a code graph cannot tell you is why the code is the way it is. That
5
- * lives in two places: commit messages, and the discussion under pull requests.
6
- * This module reads both, plus the symbol ids from the graph so a rule mined
7
- * out of them can be anchored to the code it governs.
8
- *
9
- * It deliberately sends NO source code onward. The digest is messages, titles,
10
- * comments, symbol ids and hashes — nothing a reader could reconstruct a private
11
- * codebase from.
12
- */
13
- import { spawnSync } from "node:child_process";
14
- import { ghHeaders } from "./identity.js";
15
- /** Field separators inside one `git log` record. Chosen for being bytes no
16
- * commit message contains, the same trick blast/owners.ts uses. */
17
- const REC = "\x01";
18
- const FIELD = "\x02";
19
- /** Most commits read out of one repository. Above the brain's own per-ingest
20
- * cap, so the trim happens here where the ordering is known. */
21
- const MAX_COMMITS = 1_000;
22
- /** Run git in `root`, or null when git fails. */
23
- function git(root, args) {
24
- const res = spawnSync("git", ["-c", "core.quotePath=false", ...args], {
25
- cwd: root,
26
- encoding: "utf8",
27
- stdio: ["ignore", "pipe", "pipe"],
28
- maxBuffer: 64 * 1024 * 1024,
29
- });
30
- if (res.error || res.status !== 0 || typeof res.stdout !== "string")
31
- return null;
32
- return res.stdout;
33
- }
34
- /**
35
- * Commit subjects, bodies and touched files, oldest first.
36
- *
37
- * `--no-merges`: a merge commit's message is "Merge pull request #N from …",
38
- * which establishes nothing — the decision is in the commits it brings in, and
39
- * in the thread. `--reverse` so a later reversal reads as a reversal downstream;
40
- * the extraction prompt relies on that ordering.
41
- */
42
- export function readCommits(root, max = MAX_COMMITS) {
43
- const fmt = `${REC}%H${FIELD}%s${FIELD}%b${FIELD}`;
44
- const out = git(root, [
45
- "log",
46
- "--no-merges",
47
- "--reverse",
48
- `-n`,
49
- String(max),
50
- `--format=${fmt}`,
51
- "--name-only",
52
- ]);
53
- if (!out)
54
- return [];
55
- const commits = [];
56
- for (const record of out.split(REC)) {
57
- if (!record.trim())
58
- continue;
59
- const [sha = "", subject = "", body = "", rest = ""] = record.split(FIELD);
60
- const files = rest
61
- .split("\n")
62
- .map((l) => l.trim())
63
- .filter((l) => l !== "");
64
- // A commit with no subject is a broken record, not a commit worth mining.
65
- if (!sha.trim() || !subject.trim())
66
- continue;
67
- commits.push({ sha: sha.trim(), subject: subject.trim(), body: body.trim(), files });
68
- }
69
- return commits;
70
- }
71
- /** How many pull requests to read, and how many comment pages per thread. */
72
- const MAX_THREADS = 200;
73
- const MAX_COMMENT_PAGES = 3;
74
- /** How many threads' comments are fetched at once. Two requests per pull
75
- * request, so this is the real cost of a repository read. A pool of 24 (so at
76
- * most 48 requests in flight) stays well under GitHub's secondary limit on
77
- * concurrent requests, and a slow thread no longer holds up the seven that
78
- * happened to share its batch. */
79
- export const THREAD_FETCH_CONCURRENCY = 24;
80
- export function newThreadReadCache() {
81
- return { pages: new Map(), threads: new Map() };
82
- }
83
- /** Run `fn` over `items` with at most `limit` in flight, results in input order. */
84
- export async function mapPool(items, limit, fn) {
85
- const out = new Array(items.length);
86
- let next = 0;
87
- const worker = async () => {
88
- for (;;) {
89
- const i = next++;
90
- if (i >= items.length)
91
- return;
92
- out[i] = await fn(items[i], i);
93
- }
94
- };
95
- await Promise.all(Array.from({ length: Math.min(Math.max(1, limit), items.length) }, worker));
96
- return out;
97
- }
98
- /**
99
- * Closed pull requests and their discussion, most-discussed first.
100
- *
101
- * Closed only: an open PR's discussion has not concluded, so mining a rule out
102
- * of it would record a proposal as a decision.
103
- *
104
- * Comment counts have to be discovered by fetching, not by reading the list.
105
- * GitHub's `GET /pulls` list response carries NO `comments` or
106
- * `review_comments` field — those exist only on the single-PR GET — so an
107
- * earlier version that pre-filtered on them read `undefined` for every pull
108
- * request, scored them all zero and skipped the lot. The failure was silent and
109
- * total: every repository came back with no discussion at all. So the comments
110
- * are fetched for the most recently updated closed pull requests, and the
111
- * ranking happens afterwards, on counts that are real.
112
- *
113
- * Bot comments are dropped. A CI bot posting a coverage table is the single
114
- * largest source of text in a busy repo's threads and it establishes nothing.
115
- */
116
- export async function readThreads(owner, repo, token, fetchImpl, api = "https://api.github.com", max = MAX_THREADS,
117
- // Threads already read (the early upload's newest ones), reused rather than
118
- // fetched a second time.
119
- known = new Map(),
120
- // Everything this push has already asked GitHub, in flight or finished. See
121
- // ThreadReadCache; a fresh one when the caller has nothing to share.
122
- cache = newThreadReadCache()) {
123
- const headers = ghHeaders(token);
124
- const readPage = (page) => {
125
- const cached = cache.pages.get(page);
126
- if (cached)
127
- return cached;
128
- const pending = (async () => {
129
- const res = await fetchImpl(`${api}/repos/${owner}/${repo}/pulls?state=closed&sort=updated&direction=desc&per_page=100&page=${page}`, { headers });
130
- if (!res.ok)
131
- return null;
132
- const batch = JSON.parse(await res.text());
133
- return Array.isArray(batch) ? batch : null;
134
- })();
135
- // A failed page is forgotten, so the next read asks again rather than
136
- // inheriting one blip for the rest of the push.
137
- pending.catch(() => cache.pages.delete(page));
138
- cache.pages.set(page, pending);
139
- return pending;
140
- };
141
- const pulls = [];
142
- // 100 per page, up to the cap. Sorted by GitHub as most-recently-updated,
143
- // which is the right window: rules decided two years ago that still hold get
144
- // restated in newer threads, and ones that do not are usually superseded.
145
- for (let page = 1; pulls.length < max && page <= Math.ceil(max / 100); page++) {
146
- const batch = await readPage(page);
147
- if (!batch || batch.length === 0)
148
- break;
149
- pulls.push(...batch);
150
- }
151
- // Deduplicated: a pull request updated between two page reads moves up the
152
- // list and would otherwise be read, and sent, twice.
153
- const seenNumbers = new Set();
154
- const candidates = pulls
155
- .filter((p) => typeof p.number === "number")
156
- .filter((p) => !seenNumbers.has(p.number) && (seenNumbers.add(p.number), true))
157
- .slice(0, max);
158
- const readThread = (p) => {
159
- const seen = known.get(p.number);
160
- if (seen)
161
- return Promise.resolve(seen);
162
- const cached = cache.threads.get(p.number);
163
- if (cached)
164
- return cached;
165
- const pending = (async () => {
166
- const [issueComments, reviewComments] = await Promise.all([
167
- readComments(`${api}/repos/${owner}/${repo}/issues/${p.number}/comments`, headers, fetchImpl),
168
- readComments(`${api}/repos/${owner}/${repo}/pulls/${p.number}/comments`, headers, fetchImpl),
169
- ]);
170
- const comments = [...issueComments, ...reviewComments];
171
- if (comments.length === 0)
172
- return null;
173
- return {
174
- number: p.number,
175
- title: (p.title ?? "").trim(),
176
- body: (p.body ?? "").trim(),
177
- mergeSha: (p.merge_commit_sha ?? "").trim(),
178
- comments,
179
- };
180
- })();
181
- pending.catch(() => cache.threads.delete(p.number));
182
- cache.threads.set(p.number, pending);
183
- return pending;
184
- };
185
- // A pool rather than one at a time: two requests per pull request over 200
186
- // of them is 400 sequential round trips, which is minutes of a person
187
- // waiting on a progress screen.
188
- const fetched = await mapPool(candidates, THREAD_FETCH_CONCURRENCY, readThread);
189
- const threads = fetched.filter((t) => t !== null);
190
- // Most-discussed first, because the digest renderer spends its budget in this
191
- // order and a twenty-comment thread contains an argument while a one-comment
192
- // thread contains a rubber stamp.
193
- threads.sort((a, b) => b.comments.length - a.comments.length);
194
- return threads;
195
- }
196
- /** One comment endpoint, paginated, bots removed. */
197
- async function readComments(url, headers, fetchImpl) {
198
- const out = [];
199
- for (let page = 1; page <= MAX_COMMENT_PAGES; page++) {
200
- const res = await fetchImpl(`${url}?per_page=100&page=${page}`, { headers });
201
- if (!res.ok)
202
- break;
203
- let batch;
204
- try {
205
- batch = JSON.parse(await res.text());
206
- }
207
- catch {
208
- break;
209
- }
210
- if (!Array.isArray(batch) || batch.length === 0)
211
- break;
212
- for (const c of batch) {
213
- const body = (c.body ?? "").trim();
214
- if (!body)
215
- continue;
216
- if (c.user?.type === "Bot")
217
- continue;
218
- out.push(c.path ? { body, path: c.path } : { body });
219
- }
220
- if (batch.length < 100)
221
- break;
222
- }
223
- return out;
224
- }
225
- /** Most symbols to send. The brain only needs enough to anchor rules against. */
226
- const MAX_SYMBOLS = 4_000;
227
- /**
228
- * Exported symbols from the graph, with the body hash that makes an anchored
229
- * rule self-invalidating.
230
- *
231
- * Exported only, and biggest first: an internal helper is not what a team's
232
- * rules are about, and the budget is better spent on the surface a rule is
233
- * likely to govern.
234
- */
235
- export function readSymbols(graph, max = MAX_SYMBOLS) {
236
- if (!graph)
237
- return [];
238
- return graph.nodes
239
- .filter((n) => n.exported && n.kind !== "file")
240
- .sort((a, b) => (b.chars ?? 0) - (a.chars ?? 0))
241
- .slice(0, max)
242
- .map((n) => ({
243
- id: n.id,
244
- path: n.path,
245
- name: n.name,
246
- kind: n.kind,
247
- signature: n.signature ?? "",
248
- fingerprint: n.body_hash,
249
- }));
250
- }
251
- /**
252
- * Assemble the digest.
253
- *
254
- * Each commit carries the symbol ids its files touched, so a rule mined from a
255
- * commit message can be anchored even when the message names no symbol — which
256
- * is most of the time.
257
- */
258
- export function buildDigest(input) {
259
- const byPath = new Map();
260
- for (const s of input.symbols) {
261
- const bucket = byPath.get(s.path);
262
- if (bucket)
263
- bucket.push(s.id);
264
- else
265
- byPath.set(s.path, [s.id]);
266
- }
267
- return {
268
- provider: "github",
269
- owner: input.owner,
270
- name: input.name,
271
- head_sha: input.headSha,
272
- default_branch: input.defaultBranch,
273
- is_private: input.isPrivate,
274
- commits: input.commits.map((c) => ({
275
- sha: c.sha,
276
- subject: c.subject,
277
- body: c.body,
278
- files: c.files,
279
- // Capped per commit: a sweeping refactor touches hundreds of files, and
280
- // listing every symbol in all of them would drown the message it belongs to.
281
- symbols: c.files.flatMap((f) => byPath.get(f) ?? []).slice(0, 20),
282
- })),
283
- threads: input.threads.map((t) => ({
284
- number: t.number,
285
- title: t.title,
286
- body: t.body,
287
- merge_sha: t.mergeSha,
288
- comments: t.comments,
289
- })),
290
- symbols: input.symbols,
291
- sources: input.sources,
292
- auto_approve: input.autoApprove,
293
- ...(input.agents?.length ? { agents: input.agents } : {}),
294
- };
295
- }
296
- /**
297
- * Post the digest to a brain.
298
- *
299
- * Returns the job id so the caller can hand it back to whoever asked for the
300
- * build, which is what the onboarding screen polls.
301
- */
302
- export async function postDigest(baseUrl, brainId, brainToken, digest, fetchImpl) {
303
- const res = await fetchImpl(`${baseUrl.replace(/\/+$/, "")}/api/brains/${encodeURIComponent(brainId)}/repo`, {
304
- method: "POST",
305
- headers: {
306
- authorization: `Bearer ${brainToken}`,
307
- "content-type": "application/json",
308
- accept: "application/json",
309
- },
310
- body: JSON.stringify(digest),
311
- });
312
- const text = await res.text();
313
- if (!res.ok) {
314
- throw new Error(`brain ingest failed: ${res.status} ${text.slice(0, 300)}`);
315
- }
316
- const parsed = JSON.parse(text);
317
- return { jobId: String(parsed.job_id ?? "") };
318
- }
319
- //# sourceMappingURL=history.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/app/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAc,MAAM,eAAe,CAAC;AA0DtD;mEACmE;AACnE,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,MAAM,KAAK,GAAG,MAAM,CAAC;AAErB;gEACgE;AAChE,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,iDAAiD;AACjD,SAAS,GAAG,CAAC,IAAY,EAAE,IAAc;IACvC,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC,EAAE;QACpE,GAAG,EAAE,IAAI;QACT,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;QACjC,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;KAC5B,CAAC,CAAC;IACH,IAAI,GAAG,CAA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,81 +0,0 @@
1
- import { type Fetch } from "./identity.js";
2
- /** What kind of thing a source is, so extraction can weigh it. */
3
- export type SourceKind = "agent_instructions" | "decision_doc" | "lint_config" | "ci_config" | "codeowners" | "branch_protection" | "revert" | "test_name" | "declined_issue";
4
- /** One rule-bearing artefact. */
5
- export interface HistorySource {
6
- kind: SourceKind;
7
- /** Repo-relative path, or an API-ish label like "branch protection: main". */
8
- path: string;
9
- text: string;
10
- /** Deep link, where one exists (an issue, a reverted commit). */
11
- url?: string;
12
- }
13
- /**
14
- * Instruction files the team already wrote for coding agents.
15
- *
16
- * The single highest-precision source in a repository: someone sat down and
17
- * wrote imperative rules for a machine to follow. Nothing has to be inferred.
18
- *
19
- * Graft's own managed blocks are stripped first. Without that the brain reads
20
- * back graft's instructions about using graft, and then graft carries them into
21
- * the same file — a loop that fills the rulebook with itself.
22
- */
23
- export declare function readAgentInstructions(root: string): HistorySource[];
24
- /** Most folder instruction files, and most skills, carried per push. */
25
- export declare const MAX_FOLDER_FILES = 30;
26
- export declare const MAX_SKILL_FILES = 30;
27
- /**
28
- * `**\/CLAUDE.md` and `**\/AGENTS.md` below the root, shallowest first.
29
- *
30
- * Asked of git first, because git already knows what the repository ignores:
31
- * a CLAUDE.md inside an ignored folder is someone's scratch, not the team's.
32
- * The walk is the fallback for a checkout git cannot answer for.
33
- */
34
- export declare function folderInstructionFiles(root: string, max?: number): string[];
35
- /** `.claude/skills/<name>/SKILL.md`, graft's own skill excluded. */
36
- export declare function skillFiles(root: string, max?: number): string[];
37
- /** Architecture decision records and the docs that read like them. */
38
- export declare function readDecisionDocs(root: string): HistorySource[];
39
- /**
40
- * Rules the team already encoded for a machine: linters, formatters, and the
41
- * checks CI insists on. Nothing to infer — extraction only has to phrase them.
42
- */
43
- export declare function readCodifiedRules(root: string): HistorySource[];
44
- /** Who must approve what. A hard constraint, stated as a file. */
45
- export declare function readCodeowners(root: string): HistorySource[];
46
- /**
47
- * Commits that undid another commit.
48
- *
49
- * "We tried this and took it back" is a rule available from nowhere else, and
50
- * it is the one kind of history that says what NOT to do. The body of a revert
51
- * usually names the commit it undoes and, when the author bothered, why.
52
- */
53
- export declare function readReverts(root: string, max?: number): HistorySource[];
54
- /**
55
- * Test names, which are invariants someone wrote deliberately.
56
- *
57
- * `never retries on a card decline` is a rule stated as an assertion. Read from
58
- * the graph's own symbols rather than by re-parsing, so this costs nothing:
59
- * a test function is already a node.
60
- *
61
- * Only names that read like a sentence are kept. `TestFoo` is a label;
62
- * `rejects an expired token` is a claim about how the system must behave.
63
- */
64
- export declare function readTestNames(symbolNames: Array<{
65
- name: string;
66
- path: string;
67
- }>, max?: number): HistorySource[];
68
- /**
69
- * Issues closed as not planned.
70
- *
71
- * A decision NOT to build something, which is half of what a codebase's rules
72
- * are and is invisible everywhere else — nothing was committed, so no commit
73
- * message records it.
74
- */
75
- export declare function readDeclinedIssues(owner: string, repo: string, token: string, fetchImpl: Fetch, api?: string, max?: number): Promise<HistorySource[]>;
76
- /** Required checks and reviewers on the default branch. */
77
- export declare function readBranchProtection(owner: string, repo: string, branch: string, token: string, fetchImpl: Fetch, api?: string): Promise<HistorySource[]>;
78
- export declare function budgetSources(sources: HistorySource[], maxChars?: number, maxCount?: number): HistorySource[];
79
- /** Repo-relative path, for readers handed an absolute one. */
80
- export declare function relPath(root: string, abs: string): string;
81
- //# sourceMappingURL=sources.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../src/app/sources.ts"],"names":[],"mappings":"AAeA,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtD,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAClB,oBAAoB,GACpB,cAAc,GACd,aAAa,GACb,WAAW,GACX,YAAY,GACZ,mBAAmB,GACnB,QAAQ,GACR,WAAW,GACX,gBAAgB,CAAC;AAErB,iCAAiC;AACjC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,8EAA8E;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