@davesheffer/hunch 1.41.6 → 1.42.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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/index.js +402 -154
  3. package/dist/constitution/experiment.d.ts +3 -3
  4. package/dist/constitution/g3.d.ts +1 -1
  5. package/dist/core/footprint.d.ts +15 -0
  6. package/dist/core/footprint.js +167 -0
  7. package/dist/core/groundingLag.d.ts +15 -0
  8. package/dist/core/groundingLag.js +27 -0
  9. package/dist/core/hookText.d.ts +4 -0
  10. package/dist/core/hookText.js +8 -0
  11. package/dist/core/pipeline.d.ts +28 -0
  12. package/dist/core/pipeline.js +50 -0
  13. package/dist/core/shellwrites.d.ts +7 -0
  14. package/dist/core/shellwrites.js +131 -0
  15. package/dist/core/siblingfix.d.ts +124 -0
  16. package/dist/core/siblingfix.js +814 -0
  17. package/dist/core/taskReportHook.d.ts +1 -1
  18. package/dist/core/taskReportHook.js +19 -3
  19. package/dist/extractors/git.d.ts +31 -0
  20. package/dist/extractors/git.js +180 -1
  21. package/dist/extractors/nativeTreeSitter.d.ts +2 -1
  22. package/dist/extractors/nativeTreeSitter.js +128 -30
  23. package/dist/integrations/claudemd.d.ts +20 -2
  24. package/dist/integrations/claudemd.js +79 -53
  25. package/dist/integrations/providers.d.ts +9 -5
  26. package/dist/integrations/providers.js +34 -22
  27. package/dist/integrations/team.d.ts +24 -4
  28. package/dist/integrations/team.js +154 -16
  29. package/dist/integrations/worktree.d.ts +3 -2
  30. package/dist/integrations/worktree.js +7 -4
  31. package/dist/mcp/server.d.ts +489 -0
  32. package/dist/mcp/server.js +208 -62
  33. package/dist/mcp/taskReportTools.js +12 -9
  34. package/dist/mcp/toolset.d.ts +11 -1
  35. package/dist/mcp/toolset.js +28 -8
  36. package/dist/store/hunchStore.d.ts +25 -1
  37. package/dist/store/hunchStore.js +146 -21
  38. package/dist/store/jsonStore.js +25 -4
  39. package/package.json +1 -1
  40. package/server.json +2 -2
@@ -0,0 +1,124 @@
1
+ export interface SiblingCommit {
2
+ sha: string;
3
+ subject: string;
4
+ fix: boolean;
5
+ /** The commit's changed lines inside the sibling, in hunk order, `+`/`-` prefixed. */
6
+ change: string[];
7
+ /** Test files the same commit changed: the proof that came with the fix. */
8
+ tests?: string[];
9
+ }
10
+ export interface SiblingLesson {
11
+ symbol: string;
12
+ file: string;
13
+ line: number;
14
+ sibling: string;
15
+ siblingFile: string;
16
+ siblingStart: number;
17
+ siblingEnd: number;
18
+ similarity: number;
19
+ commits: SiblingCommit[];
20
+ }
21
+ export interface SiblingOptions {
22
+ /** Candidate pairs whose history is inspected (best similarity first). */
23
+ maxPairs?: number;
24
+ /** Lessons returned. */
25
+ maxLessons?: number;
26
+ /** Per git call; each call is also capped by what is left of `budgetMs`. */
27
+ timeoutMs?: number;
28
+ /** Wall-clock budget for the whole computation; past it the result is incomplete. */
29
+ budgetMs?: number;
30
+ /** Cap on the no-index inventory scan (tests force truncation with it). */
31
+ inventoryBudgetMs?: number;
32
+ /** Set false to bypass the .hunch-cache read/write (tests). */
33
+ cache?: boolean;
34
+ /** Clock for the incomplete-run retry window (tests). */
35
+ now?: number;
36
+ }
37
+ interface IndexedSymbol {
38
+ file: string;
39
+ name: string;
40
+ kind: string;
41
+ }
42
+ /** `isHunchProviderHook` → {is, hunch, provider, hook}. */
43
+ export declare function nameTokens(name: string): Set<string>;
44
+ /** Identifier-ish tokens of a body's CODE, including those inside regex/string
45
+ * literals. Comment lines are dropped: a fix usually adds an explanation, and
46
+ * its prose would otherwise swamp the shared shape. */
47
+ export declare function codeTokens(text: string): Set<string>;
48
+ /** Overlap coefficient: shared / smaller set. A hardened copy grows, so
49
+ * containment — not Jaccard — is what "same shape" means for bodies. */
50
+ export declare function overlap(a: ReadonlySet<string>, b: ReadonlySet<string>): number;
51
+ export declare function jaccard(a: ReadonlySet<string>, b: ReadonlySet<string>): number;
52
+ export declare function isFixSubject(subject: string): boolean;
53
+ export interface LineLogCommit {
54
+ sha: string;
55
+ subject: string;
56
+ added: string[];
57
+ removed: string[];
58
+ /** Added and removed lines in hunk order, `+`/`-` prefixed. */
59
+ diff: string[];
60
+ /** Largest old/new line span of any hunk — how far git's range reached. */
61
+ span: number;
62
+ /** Every hunk starts from nothing (`@@ -0,0 …`): the function was created here. */
63
+ created: boolean;
64
+ }
65
+ /** Parse `git log -L … --format=%x1eC %H%x1f%s` output. */
66
+ export declare function parseLineLog(output: string): LineLogCommit[];
67
+ /** A commit whose removed and added lines differ only in whitespace/line
68
+ * endings (a reformat, a CRLF→LF sweep, a re-indent) changed nothing. */
69
+ export declare function isSubstantive(commit: LineLogCommit): boolean;
70
+ /** git follows a line range backwards only while it can map it. A whole-file
71
+ * rewrite (a line-ending sweep, a reformat) breaks the mapping: from that
72
+ * commit on, every hunk spans the whole file and nothing in it is attributable
73
+ * to the function. Keep the history before that commit and report where the
74
+ * mapping was lost. */
75
+ export declare function attributable(commits: readonly LineLogCommit[], fnLines: number): {
76
+ kept: LineLogCommit[];
77
+ lostAt: string | null;
78
+ };
79
+ /** Candidate scans run (tests: a cache hit must not run one). */
80
+ export declare const siblingCounters: {
81
+ candidateScans: number;
82
+ lessonComputes: number;
83
+ };
84
+ /** Sibling-fix lessons for one repo-relative file. */
85
+ export declare function siblingLessonsFor(root: string, file: string, symbols: readonly IndexedSymbol[], options?: SiblingOptions): SiblingLesson[];
86
+ /** Stable identity for hook dedupe: which fixes were surfaced, not the wording. */
87
+ export declare function siblingLessonsIdentity(lessons: readonly SiblingLesson[]): string;
88
+ /** A commit's diff inside the function, blank-only lines dropped, capped
89
+ * (a fix commit gets the larger cap). */
90
+ export declare function changeLines(diff: readonly string[], fix?: boolean): string[];
91
+ export declare const SIBLING_HEADING = "## \u26A0 Fix not carried to this function";
92
+ /** Callers of each lesson's function, by lesson symbol: names of functions in
93
+ * the same working-tree file whose body calls it. */
94
+ export type SiblingCallers = ReadonlyMap<string, readonly string[]>;
95
+ /** Written to be acted on, not skimmed: an agent reads "possible, heuristic,
96
+ * elsewhere" as out of scope and moves on (trap-310: three deliveries, zero
97
+ * follow-ups). So the lesson says what this copy lacks, which code here runs
98
+ * through it, and asks for an explicit outcome. It stays advisory: "does not
99
+ * apply, because …" is always an accepted answer. */
100
+ /** A blocking invariant whose scope covers the lesson's file. */
101
+ export interface SiblingInvariant {
102
+ id: string;
103
+ statement: string;
104
+ }
105
+ /** "Pre-existing" and "outside this task" are how an agent that agrees with the
106
+ * lesson still leaves it (trap-310 v4: gap confirmed, reported, not fixed).
107
+ * The change in hand runs through the copy, so only "cannot reach it" or
108
+ * "already handled" count as not applying. */
109
+ export declare const NOT_A_REASON = "\"Pre-existing\" or \"outside this task\" does not count: the change you are making runs through this copy, so leaving it ships the gap again inside your change.";
110
+ export declare function renderSiblingLessons(lessons: readonly SiblingLesson[], callers?: SiblingCallers, invariants?: readonly SiblingInvariant[]): string;
111
+ /** Hash of the function's current body, or null when it cannot be found. A
112
+ * changed hash means the agent touched the function after the lesson. */
113
+ export declare function functionBodyHash(root: string, file: string, symbol: string): string | null;
114
+ export interface SiblingGrounding {
115
+ text: string;
116
+ identity: string;
117
+ lessons: SiblingLesson[];
118
+ callers: SiblingCallers;
119
+ }
120
+ /** Grounding-path entry: the rendered block plus its dedupe identity for one
121
+ * repo-relative file. Never throws — a parser load failure or a git error
122
+ * means no sibling lessons, not a failed edit hook. */
123
+ export declare function siblingGrounding(root: string, file: string, symbols: readonly IndexedSymbol[], invariants?: readonly SiblingInvariant[]): SiblingGrounding;
124
+ export {};