@davesheffer/hunch 1.45.2 → 1.47.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 (91) hide show
  1. package/dist/cli/index.js +290 -353
  2. package/dist/cli/invocation.d.ts +22 -13
  3. package/dist/cli/invocation.js +49 -29
  4. package/dist/cli/verify.d.ts +28 -0
  5. package/dist/cli/verify.js +265 -0
  6. package/dist/constitution/delta.js +2 -2
  7. package/dist/constitution/experiment.d.ts +1 -1
  8. package/dist/constitution/sourceMutation.js +28 -18
  9. package/dist/core/agenthook.js +26 -6
  10. package/dist/core/boundedSpawn.d.ts +57 -0
  11. package/dist/core/boundedSpawn.js +321 -0
  12. package/dist/core/commitrepair.d.ts +43 -138
  13. package/dist/core/commitrepair.js +76 -167
  14. package/dist/core/config.d.ts +6 -0
  15. package/dist/core/config.js +1 -0
  16. package/dist/core/correction.js +9 -9
  17. package/dist/core/delivery.d.ts +6 -1
  18. package/dist/core/delivery.js +71 -5
  19. package/dist/core/docanchors.js +9 -9
  20. package/dist/core/drift.js +22 -27
  21. package/dist/core/escalations.d.ts +16 -58
  22. package/dist/core/escalations.js +39 -121
  23. package/dist/core/glob.d.ts +7 -7
  24. package/dist/core/glob.js +12 -11
  25. package/dist/core/groundingLag.d.ts +2 -9
  26. package/dist/core/groundingLag.js +5 -11
  27. package/dist/core/groundingMerge.d.ts +2 -7
  28. package/dist/core/groundingMerge.js +35 -54
  29. package/dist/core/migrate.d.ts +10 -1
  30. package/dist/core/migrate.js +17 -6
  31. package/dist/core/paths.d.ts +17 -24
  32. package/dist/core/paths.js +37 -43
  33. package/dist/core/projectDna.js +11 -1
  34. package/dist/core/refrepair.d.ts +2 -1
  35. package/dist/core/refrepair.js +4 -4
  36. package/dist/core/relativeImports.js +6 -2
  37. package/dist/core/repairqueue.d.ts +17 -34
  38. package/dist/core/repairqueue.js +48 -98
  39. package/dist/core/taskSelection.js +48 -6
  40. package/dist/core/testSelection.d.ts +122 -0
  41. package/dist/core/testSelection.js +588 -0
  42. package/dist/core/types.d.ts +3 -3
  43. package/dist/core/types.js +1 -1
  44. package/dist/extractors/diff.d.ts +4 -4
  45. package/dist/extractors/diff.js +25 -29
  46. package/dist/extractors/git.d.ts +8 -23
  47. package/dist/extractors/git.js +77 -95
  48. package/dist/extractors/helm.d.ts +10 -0
  49. package/dist/extractors/helm.js +43 -59
  50. package/dist/extractors/indexer.d.ts +6 -0
  51. package/dist/extractors/indexer.js +168 -184
  52. package/dist/extractors/k8sManifest.d.ts +23 -80
  53. package/dist/extractors/k8sManifest.js +319 -690
  54. package/dist/extractors/languages.d.ts +37 -37
  55. package/dist/extractors/languages.js +83 -54
  56. package/dist/extractors/nativeTreeSitter.d.ts +4 -4
  57. package/dist/extractors/nativeTreeSitter.js +17 -14
  58. package/dist/extractors/parse.d.ts +27 -13
  59. package/dist/extractors/parse.js +120 -56
  60. package/dist/extractors/workspaces.js +3 -1
  61. package/dist/integrations/claudemd.js +1 -0
  62. package/dist/integrations/gitignore.js +3 -5
  63. package/dist/integrations/health.d.ts +6 -0
  64. package/dist/integrations/health.js +33 -12
  65. package/dist/integrations/hooks.d.ts +13 -16
  66. package/dist/integrations/hooks.js +31 -30
  67. package/dist/integrations/mergeDriver.js +18 -17
  68. package/dist/integrations/optout.d.ts +3 -0
  69. package/dist/integrations/optout.js +17 -0
  70. package/dist/integrations/providers.d.ts +6 -2
  71. package/dist/integrations/providers.js +19 -2
  72. package/dist/integrations/team.js +4 -2
  73. package/dist/integrations/uninstall.d.ts +10 -4
  74. package/dist/integrations/uninstall.js +22 -18
  75. package/dist/mcp/server.d.ts +4 -5
  76. package/dist/mcp/server.js +107 -81
  77. package/dist/serve/app.js +9 -1
  78. package/dist/serve/config.js +5 -0
  79. package/dist/serve/writelock.d.ts +3 -1
  80. package/dist/serve/writelock.js +17 -3
  81. package/dist/store/hunchStore.d.ts +2 -1
  82. package/dist/store/hunchStore.js +20 -23
  83. package/dist/store/jsonStore.d.ts +13 -3
  84. package/dist/store/jsonStore.js +37 -13
  85. package/dist/store/stateBinding.js +17 -4
  86. package/dist/synthesis/provider.d.ts +19 -21
  87. package/dist/synthesis/provider.js +93 -154
  88. package/dist/synthesis/synthesize.d.ts +8 -8
  89. package/dist/synthesis/synthesize.js +33 -50
  90. package/package.json +3 -3
  91. package/server.json +2 -2
@@ -0,0 +1,122 @@
1
+ /** One test's coverage record. `complete` = the test file passed (ran to the
2
+ * end, so its coverage is whole); `closureHash` = the entry-closure hash at
3
+ * refresh time; `commit` = HEAD when this entry was recorded. */
4
+ export interface ImpactEntry {
5
+ files: string[];
6
+ complete: boolean;
7
+ commit: string;
8
+ closureHash: string;
9
+ }
10
+ export interface ImpactMap {
11
+ version: number;
12
+ commit: string;
13
+ generatedAt?: string;
14
+ closureHash?: string;
15
+ /** test file → coverage entry (repo-relative posix). */
16
+ map: Record<string, ImpactEntry>;
17
+ }
18
+ export interface SelectionInput {
19
+ changedFiles: string[];
20
+ allTests: string[];
21
+ impactMap?: ImpactMap;
22
+ /** Static dependencies of a test: transitive imports plus the closures of
23
+ * repo paths its text names (see `testDependencyModel`). */
24
+ importGraph: (testFile: string) => Set<string>;
25
+ fullTriggers?: string[];
26
+ /** Extra per-test globs: a changed file matching one selects that test. */
27
+ gateMaps?: Record<string, string[]>;
28
+ /** Source text of a test (and its non-src helpers), for path/basename mentions. */
29
+ testText?: (testFile: string) => string;
30
+ /** Does the test start a child process (directly or through a helper)? */
31
+ spawning?: (testFile: string) => boolean;
32
+ /** Every file a spawned child could execute (all src/ plus tooling closures). */
33
+ wholeProgram?: Iterable<string>;
34
+ /** Entry-closure hash computed now; a map entry is trusted only if it matches. */
35
+ closureHash?: string;
36
+ /** src/ and tooling/ files whose text names a test file by repo path. */
37
+ testNamers?: (testFile: string) => string[];
38
+ }
39
+ export interface Selection {
40
+ mode: "selected" | "full" | "none";
41
+ tests: string[];
42
+ reasons: Record<string, string[]>;
43
+ fullReason?: string;
44
+ unattributed: string[];
45
+ /** Tests whose impact-map entry attributed a change or narrowed a spawning test. */
46
+ mapUsed: string[];
47
+ }
48
+ export declare const DEFAULT_FULL_TRIGGERS: readonly string[];
49
+ /** Repo-root markdown (README.md, CHANGELOG.md, ...) is the only non-code change
50
+ * that can skip the full suite: it selects tests that mention it, else nothing. */
51
+ export declare function isDocsOnly(file: string): boolean;
52
+ /** Selected tests above this share of the suite run the full suite instead. */
53
+ export declare const MAX_SELECTED_SHARE = 0.6;
54
+ export declare const isMetaTest: (text: string) => boolean;
55
+ /** A map entry may narrow a spawning test only when it is complete and was
56
+ * recorded against the same entry closure as now. */
57
+ export declare function entryTrusted(entry: ImpactEntry | undefined, closureHash: string | undefined): boolean;
58
+ export declare function selectTests(input: SelectionInput): Selection;
59
+ /** Tracked + untracked (non-ignored) repo files, repo-relative posix, sorted. */
60
+ export declare function listRepoFiles(root: string): string[];
61
+ export declare function discoverTests(files: string[], glob?: string): string[];
62
+ /** Static imports, re-exports, `import()`/`require()` with literal specifiers. */
63
+ export declare function importSpecifiers(source: string): string[];
64
+ /** Transitive relative-import closure per file, memoized for this call. An
65
+ * unresolvable relative specifier (e.g. a deleted file) records every
66
+ * candidate path, so the deletion stays attributable to its importers. */
67
+ export declare function buildImportGraph(root: string, files?: string[]): (file: string) => Set<string>;
68
+ /** Entries whose import closure (edges included) keys map-entry trust. */
69
+ export declare const CLOSURE_ROOTS: readonly string[];
70
+ /** String-literal arguments of each `join(`/`resolve(` call, found with a
71
+ * balanced-paren scan so nested calls (`join(process.cwd(), "src")`) parse. */
72
+ export declare function joinSegmentRuns(text: string): string[][];
73
+ /** Repo files a test's text names: path-like tokens anywhere (string literals,
74
+ * `--eval` import specifiers, template strings) and `join(…, "src", "x.ts")`
75
+ * segment runs, resolved against the REPO ROOT (and the test's own dir for
76
+ * `./`/`../` tokens), with `.js`→`.ts` mapping. */
77
+ export declare function literalRepoPaths(text: string, fromFile: string, available: Set<string>): string[];
78
+ /** Arguments of each `join(`/`resolve(` call: a plain string literal's value, or
79
+ * `null` for anything computed (identifiers, calls, `${}` templates). */
80
+ export declare function joinCallArgs(text: string): (string | null)[][];
81
+ /** Top-level repo dirs a text reaches through a COMPUTED path: `` `../src/${p}` ``,
82
+ * `"src/" + p`, `join(root, "src", p)`, or a later use of an alias like
83
+ * `const SRC = join(ROOT, "src")`. A test doing that may read any file under
84
+ * the dir, so it depends on all of them. A computed segment right after the
85
+ * root (`` `../${dir}/x` ``, `"../" + dir`, `resolve(__dirname, "..", dir)`,
86
+ * `` `${ROOT}/${dir}` ``) may be ANY top-level dir (fail closed). */
87
+ export declare function templatedRepoDirs(text: string, topDirs: Set<string>): string[];
88
+ export interface TestDependencyModel {
89
+ /** Static imports ∪ closures of repo paths named in the test or its helpers. */
90
+ dependencies: (testFile: string) => Set<string>;
91
+ spawning: (testFile: string) => boolean;
92
+ /** Text of the test plus its non-src static closure (helpers). */
93
+ testText: (testFile: string) => string;
94
+ /** All src/ files plus the closures of every tooling/*.mjs. */
95
+ wholeProgram: Set<string>;
96
+ /** Hash of the import closures (edges) of CLOSURE_ROOTS and tooling/*.mjs. */
97
+ closureHash: string;
98
+ /** src/ and tooling/ code files whose text names a test file by repo path. */
99
+ testNamers: (testFile: string) => string[];
100
+ }
101
+ export declare function testDependencyModel(root: string, files: string[], graph?: (file: string) => Set<string>): TestDependencyModel;
102
+ /** Structural hash of the entry closures: every reachable file and its direct
103
+ * edges. Content edits don't change it; a new import or file in the closure does. */
104
+ export declare function closureHash(root: string, files: string[], graph?: (file: string) => Set<string>): string;
105
+ /** Repo files with any executed range in V8 coverage reports
106
+ * (`NODE_V8_COVERAGE` JSON: `{ result: [{ url, functions: [{ ranges }] }] }`). */
107
+ export declare function coverageFiles(reports: unknown[], root: string, repoFiles: Set<string>): string[];
108
+ export type ChangeMode = {
109
+ kind: "worktree";
110
+ } | {
111
+ kind: "staged";
112
+ } | {
113
+ kind: "base";
114
+ ref: string;
115
+ };
116
+ /** Changed files for a verify run. `worktree` (default): staged + unstaged +
117
+ * untracked; `staged`: the index only; `base`: merge-base(ref, HEAD)..HEAD
118
+ * plus the working tree. */
119
+ export declare function changedFiles(root: string, mode?: ChangeMode): string[];
120
+ /** Load an impact map; a missing file is `null`, a malformed one throws. A
121
+ * legacy `test: string[]` entry loads as incomplete (never trusted). */
122
+ export declare function loadImpactMap(path: string): ImpactMap | null;