@davesheffer/hunch 1.47.1 → 1.48.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.
package/LICENSE CHANGED
@@ -1,201 +1,105 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2026 Dave Sheffer
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Dave Sheffer
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/NOTICE CHANGED
@@ -1,6 +1,13 @@
1
1
  Hunch — Engineering Memory and Change Gate
2
2
  Copyright 2026 Dave Sheffer
3
3
 
4
- This product is licensed under the Apache License, Version 2.0.
5
- See the LICENSE file for the full license text, or
6
- http://www.apache.org/licenses/LICENSE-2.0
4
+ This product is licensed under the Functional Source License, Version 1.1,
5
+ ALv2 Future License (FSL-1.1-ALv2). See the LICENSE file for the full text,
6
+ or https://fsl.software. Each version becomes available under the Apache
7
+ License, Version 2.0 on the second anniversary of its release.
8
+
9
+ Versions released before the switch to FSL-1.1-ALv2 remain available under
10
+ the license they shipped with (Apache-2.0 from v0.15.2, MIT before that).
11
+
12
+ The Python client in clients/python is licensed separately under the Apache
13
+ License, Version 2.0; see clients/python/LICENSE.
package/README.md CHANGED
@@ -4,7 +4,13 @@
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@davesheffer/hunch?color=2742ff&label=npm)](https://www.npmjs.com/package/@davesheffer/hunch)
6
6
  [![GitHub stars](https://img.shields.io/github/stars/davesheffer/hunch?color=2742ff&label=%E2%98%85%20star)](https://github.com/davesheffer/hunch)
7
- [![license](https://img.shields.io/npm/l/@davesheffer/hunch?color=2742ff)](LICENSE)
7
+ [![license](https://img.shields.io/badge/license-FSL--1.1--ALv2-2742ff)](LICENSE)
8
+
9
+ [![Watch: Hunch Memory in 2 minutes](https://img.youtube.com/vi/m2PM6pV7D9Y/maxresdefault.jpg)](https://www.youtube.com/watch?v=m2PM6pV7D9Y)
10
+
11
+ ▶ **[Watch Hunch Memory in 2 minutes](https://www.youtube.com/watch?v=m2PM6pV7D9Y)**, then the [7-episode series](https://www.youtube.com/playlist?list=PLIXqtdE0LcNI) on setup, hooks, memory capture, delivery, rules, drift and teams.
12
+
13
+ ![Hunch refuses a staged change that imports lodash, citing the blocking rule it breaks](site/assets/hunch-blocks-it.gif)
8
14
 
9
15
  A new agent session should not mean explaining the project all over again. A second agent should be able to check a recorded decision, see the evidence behind completed work, and find an outstanding commitment.
10
16
 
@@ -12,10 +18,6 @@ Hunch keeps that record in Git and makes the relevant parts available to your ag
12
18
 
13
19
  The goal is simple: agents working from the same maintained record, with sources they can inspect. Hunch supplies memory and checks; the assistant still does the work.
14
20
 
15
- [![Watch: Hunch Memory in 2 minutes](https://img.youtube.com/vi/m2PM6pV7D9Y/maxresdefault.jpg)](https://www.youtube.com/watch?v=m2PM6pV7D9Y)
16
-
17
- ▶ **[Watch Hunch Memory in 2 minutes](https://www.youtube.com/watch?v=m2PM6pV7D9Y)**, then the [7-episode series](https://www.youtube.com/playlist?list=PLIXqtdE0LcNI) on setup, hooks, memory capture, delivery, rules, drift and teams.
18
-
19
21
  ## Start with your coding assistant
20
22
 
21
23
  Requires **Node 22.13+** and a Git repository.
@@ -196,4 +198,4 @@ Profiles retain their revision, sources, confidence, and freshness.
196
198
  - [VS Code extension](vscode-extension/README.md)
197
199
  - [Contributing](CONTRIBUTING.md)
198
200
 
199
- Apache-2.0
201
+ [FSL-1.1-ALv2](LICENSE) (Functional Source License). Use it, modify it, and run it for your own work, internal or commercial; you can't make it available to others in a commercial product or service that competes with Hunch or with services built on it (see Permitted Purpose in [LICENSE](LICENSE)). Each release converts to Apache-2.0 two years after it ships. Releases before this change keep the license they shipped with.
package/dist/cli/index.js CHANGED
@@ -23,7 +23,8 @@ import { Command } from "commander";
23
23
  import { hunchPaths, hunchPathsForDir, findRoot, toPosixTarget, isDir, realpathNorm, repoRelativeTarget } from "../core/paths.js";
24
24
  import { writeFileAtomic } from "../core/io.js";
25
25
  import { boundedSpawnSync } from "../core/boundedSpawn.js";
26
- import { looksLikeCorrection, CORRECTION_NUDGE } from "../core/correction.js";
26
+ import { looksLikeCorrection, CORRECTION_NUDGE, stripHostBlocks } from "../core/correction.js";
27
+ import { roleHasHunchTools } from "../core/subagentrole.js";
27
28
  import { HUNCH_VERSION } from "../core/version.js";
28
29
  import { registerIntegrationCommands } from "./integrations.js";
29
30
  import { registerTaskReportCommands } from "./taskReport.js";
@@ -856,7 +857,7 @@ program
856
857
  if (ctxWarning !== null)
857
858
  console.log(ctxWarning);
858
859
  }
859
- let written = 0, skipped = 0, llm = 0, heuristic = 0;
860
+ let written = 0, skipped = 0, llm = 0, heuristic = 0, fellBack = 0;
860
861
  const home = store.captureHome(false);
861
862
  // The per-commit cost is the Claude synthesis spawn; run several at once. Safe:
862
863
  // each commit drafts independently and writes its OWN decision file atomically,
@@ -868,11 +869,17 @@ program
868
869
  if (r.status === "written") {
869
870
  written++;
870
871
  // Any non-deterministic provider (claude/codex/cursor/ensemble) is an LLM draft.
871
- if (r.provider && r.provider !== "deterministic")
872
+ // A provider failure that fell back is counted apart from the commits the
873
+ // significance gate sent to the heuristic on purpose (issue #561).
874
+ if (r.fallbackReason)
875
+ fellBack++;
876
+ else if (r.provider && r.provider !== "deterministic")
872
877
  llm++;
873
878
  else
874
879
  heuristic++;
875
- process.stdout.write(` ✓ ${sha.slice(0, 8)} ${r.decision?.title.slice(0, 64) ?? ""}\n`);
880
+ process.stdout.write(` ${r.fallbackReason ? "⚠" : "✓"} ${sha.slice(0, 8)} ${r.decision?.title.slice(0, 64) ?? ""}\n`);
881
+ if (r.fallbackReason)
882
+ process.stdout.write(` heuristic draft instead: ${r.fallbackReason}\n`);
876
883
  }
877
884
  else
878
885
  skipped++;
@@ -884,7 +891,8 @@ program
884
891
  pumpMemoryHome(store, root, home, `hunch: backfill ${written} decision(s)`);
885
892
  // Honest tally of where the tokens went: trivial commits are seeded by the
886
893
  // free deterministic heuristic, only substantive ones spend the LLM.
887
- console.log(`Done: ${written} decision(s) seeded (${llm} via LLM, ${heuristic} heuristic), ${skipped} skipped (trivial/not substantive/already-captured).`);
894
+ const fellBackNote = fellBack ? `, ${fellBack} heuristic after the LLM failed` : "";
895
+ console.log(`Done: ${written} decision(s) seeded (${llm} via LLM, ${heuristic} heuristic${fellBackNote}), ${skipped} skipped (trivial/not substantive/already-captured).`);
888
896
  store.close();
889
897
  });
890
898
  // ---- sync (post-commit hook) ----------------------------------------------
@@ -947,6 +955,8 @@ program
947
955
  store.reindex();
948
956
  if (!opts.quiet)
949
957
  console.log(`✓ captured decision ${r.decision?.id} via ${r.provider}: "${r.decision?.title}"`);
958
+ if (!opts.quiet && r.fallbackReason)
959
+ console.log(` ⚠ heuristic draft instead: ${r.fallbackReason}`);
950
960
  }
951
961
  else if (!opts.quiet) {
952
962
  console.log(`· skipped: ${r.reason}`);
@@ -2083,7 +2093,7 @@ program
2083
2093
  else {
2084
2094
  console.log(`Top matches for "${q}"${how}:\n`);
2085
2095
  for (const h of hits)
2086
- console.log(formatSearchHit(h, isStateKind(h.kind) ? store.resolve(h.ref)?.record : undefined));
2096
+ console.log(formatSearchHit(h, isStateKind(h.kind) || h.kind === "decisions" ? store.resolve(h.ref)?.record : undefined));
2087
2097
  }
2088
2098
  store.close();
2089
2099
  });
@@ -5456,9 +5466,11 @@ program
5456
5466
  return flat.length > max ? `${flat.slice(0, max - 1).trimEnd()}…` : flat;
5457
5467
  };
5458
5468
  const type = (evt.agent_type ?? "").toLowerCase();
5469
+ // A role whose tool list leaves out Hunch's MCP tools is not told to call them.
5470
+ const tools = roleHasHunchTools(root, evt.agent_type ?? "");
5459
5471
  const L = [];
5460
5472
  const served = [];
5461
- const route = routedCwd
5473
+ const route = routedCwd && tools
5462
5474
  ? `Worktree routing: call hunch_context first with cwd: ${JSON.stringify(routedCwd)}, and pass the same cwd to hunch_task, hunch_report, and every Hunch capture/write call in this delegated task.`
5463
5475
  : null;
5464
5476
  const activeProvider = provider;
@@ -5478,8 +5490,9 @@ program
5478
5490
  served.push({ kind: "components", record_id: c.id, token_cost: Math.ceil([...line].length / 4) });
5479
5491
  }
5480
5492
  if (components.length > 12)
5481
- L.push(`…and ${components.length - 12} more — hunch_structure() for the full map.`);
5482
- L.push("Orient: hunch_structure(target) · hunch_why(target) · hunch_context(task).");
5493
+ L.push(`…and ${components.length - 12} more${tools ? " — hunch_structure() for the full map" : ""}.`);
5494
+ if (tools)
5495
+ L.push("Orient: hunch_structure(target) · hunch_why(target) · hunch_context(task).");
5483
5496
  }
5484
5497
  else if (/plan|architect|design/.test(type)) {
5485
5498
  // A plan drafted blind re-proposes what the graph already rejected.
@@ -5496,7 +5509,8 @@ program
5496
5509
  L.push(line);
5497
5510
  served.push({ kind: "decisions", record_id: d.id, token_cost: Math.ceil([...line].length / 4) });
5498
5511
  }
5499
- L.push("Before finalizing a plan: hunch_why(target) · hunch_current_decision(topic) · hunch_check_constraints(scope).");
5512
+ if (tools)
5513
+ L.push("Before finalizing a plan: hunch_why(target) · hunch_current_decision(topic) · hunch_check_constraints(scope).");
5500
5514
  }
5501
5515
  else {
5502
5516
  const sevRank = { blocking: 0, warning: 1, advisory: 2 };
@@ -5514,8 +5528,9 @@ program
5514
5528
  served.push({ kind: "constraints", record_id: c.id, token_cost: Math.ceil([...line].length / 4) });
5515
5529
  }
5516
5530
  if (constraints.length > 8)
5517
- L.push(`…and ${constraints.length - 8} more — hunch_check_constraints(scope) for your files.`);
5518
- L.push("Before editing: hunch_check_constraints(scope) · hunch_why(target). Orient: hunch_context(task).");
5531
+ L.push(`…and ${constraints.length - 8} more${tools ? " — hunch_check_constraints(scope) for your files" : "; the edit hook shows the ones your files touch"}.`);
5532
+ if (tools)
5533
+ L.push("Before editing: hunch_check_constraints(scope) · hunch_why(target). Orient: hunch_context(task).");
5519
5534
  }
5520
5535
  if (route)
5521
5536
  L.push(route);
@@ -7768,19 +7783,21 @@ function promptTaskSelection(root, store, provider, evt) {
7768
7783
  const taskId = hookReportTaskId(root, provider, evt);
7769
7784
  if (!taskId)
7770
7785
  return "";
7786
+ // Host-injected blocks (reminders, browser instructions) are not the task the human named.
7787
+ const humanText = stripHostBlocks(evt.prompt ?? "");
7771
7788
  const selection = selectForTask(liveSelectionRecords({
7772
7789
  decisions: store.recs("decisions"),
7773
7790
  bugs: store.recs("bugs"),
7774
7791
  constraints: store.recs("constraints"),
7775
7792
  findings: store.recs("findings"),
7776
- }), evt.prompt ?? "", { root, pathExists: (p) => existsSync(join(root, p)) });
7793
+ }), humanText, { root, pathExists: (p) => existsSync(join(root, p)) });
7777
7794
  // Same task id again (a notification alias) keeps its own earlier selection; a
7778
7795
  // new task that CONTINUES the session's previous one inherits that task's
7779
7796
  // selection only on a bare follow-up ("continue", "go on"), so it is not left
7780
7797
  // ungrounded. A substantive prompt names its own task: a same-session prompt
7781
7798
  // inside the continuation window must not hide memory behind an old selection.
7782
7799
  let previous = loadTaskSelection(taskId);
7783
- if (!previous && isBareFollowUp(evt.prompt ?? "")) {
7800
+ if (!previous && isBareFollowUp(humanText)) {
7784
7801
  try {
7785
7802
  const continues = readTaskReport(root, taskId).task.continues;
7786
7803
  previous = continues ? loadTaskSelection(continues) : null;
@@ -30,11 +30,12 @@ const CORRECTION_PATTERNS = [
30
30
  /\b(not like that|don'?t do (that|this)( again)?|stop doing (that|this))\b/i,
31
31
  ];
32
32
  /** Host-generated blocks a prompt can carry: a background task's completion
33
- * (`<task-notification>`, which also wraps a subagent's hand-back report) and
34
- * injected context (`<system-reminder>`, hook output). Their words are not the
33
+ * (`<task-notification>`, which also wraps a subagent's hand-back report),
34
+ * injected context (`<system-reminder>`, hook output) and the browser
35
+ * extension's standing instructions (`<browser_instruction>`). Their words are not the
35
36
  * human's, so "never use X" quoted from a constraint is not a correction. A tag
36
37
  * left unclosed drops only the rest of its own line, never the human's text below. */
37
- const HOST_TAGS = "task-notification|system-reminder|local-command-stdout|local-command-stderr|command-message|command-name|command-args";
38
+ const HOST_TAGS = "task-notification|system-reminder|local-command-stdout|local-command-stderr|command-message|command-name|command-args|browser_instruction";
38
39
  const HOST_BLOCK = new RegExp(`<(${HOST_TAGS})>[\\s\\S]*?<\\/\\1>`, "gi");
39
40
  const HOST_OPEN_LINE = new RegExp(`<(?:${HOST_TAGS})>[^\\n]*`, "gi");
40
41
  /** The prompt with host-generated blocks removed: what the human actually typed. */
@@ -7,7 +7,9 @@ export declare function formatContext(ctx: AssembledContext, options?: DeliveryO
7
7
  /** One search hit as `hunch query` / hunch_query print it (headline + indented detail line).
8
8
  * Graph records keep their `[kind] id — title` shape; a nuryel.state/1 hit renders through
9
9
  * renderStateLine (`[commitment/in_force] customer:Site:7 — "send report" due … (owner …)`)
10
- * with the record id on the detail line, so both readers say the same thing. */
10
+ * with the record id on the detail line, so both readers say the same thing. A decision that
11
+ * is no longer accepted says so in its tag (`[decisions · superseded → dec_new]`), so a
12
+ * reader never takes a history hit for the current rule. */
11
13
  export declare function formatSearchHit(hit: SearchHit, record: unknown): string;
12
14
  /** Render a StructureView as a compact orientation brief (hunch_structure). */
13
15
  export declare function formatStructure(v: StructureView): string;
@@ -6,12 +6,24 @@ export function formatContext(ctx, options = {}) {
6
6
  /** One search hit as `hunch query` / hunch_query print it (headline + indented detail line).
7
7
  * Graph records keep their `[kind] id — title` shape; a nuryel.state/1 hit renders through
8
8
  * renderStateLine (`[commitment/in_force] customer:Site:7 — "send report" due … (owner …)`)
9
- * with the record id on the detail line, so both readers say the same thing. */
9
+ * with the record id on the detail line, so both readers say the same thing. A decision that
10
+ * is no longer accepted says so in its tag (`[decisions · superseded → dec_new]`), so a
11
+ * reader never takes a history hit for the current rule. */
10
12
  export function formatSearchHit(hit, record) {
11
13
  if (isStateKind(hit.kind) && record) {
12
14
  return `• ${renderStateLine(hit.kind, record)}\n ${hit.ref}`;
13
15
  }
14
- return `• [${hit.kind}] ${hit.ref} — ${hit.title}\n ${hit.snippet}`;
16
+ return `• [${hit.kind}${decisionStatusTag(hit.kind, record)}] ${hit.ref} — ${hit.title}\n ${hit.snippet}`;
17
+ }
18
+ function decisionStatusTag(kind, record) {
19
+ if (kind !== "decisions" || !record)
20
+ return "";
21
+ const { status, superseded_by, valid_to } = record;
22
+ if (superseded_by)
23
+ return ` · superseded → ${superseded_by}`;
24
+ if (status && status !== "accepted")
25
+ return ` · ${status}`;
26
+ return valid_to ? ` · closed ${valid_to.slice(0, 10)}` : "";
15
27
  }
16
28
  /** Render a StructureView as a compact orientation brief (hunch_structure). */
17
29
  export function formatStructure(v) {
@@ -13,8 +13,8 @@ declare const commentSchema: z.ZodObject<{
13
13
  user: z.ZodObject<{
14
14
  login: z.ZodString;
15
15
  type: z.ZodEnum<{
16
- User: "User";
17
16
  Bot: "Bot";
17
+ User: "User";
18
18
  }>;
19
19
  }, z.core.$strip>;
20
20
  }, z.core.$strip>;
@@ -0,0 +1,6 @@
1
+ /** Whether a delegated agent can call Hunch's MCP tools. A named role defined in
2
+ * `.claude/agents/<type>.md` (project first, then user) with a `tools:` list that
3
+ * names no `mcp__hunch` tool and no wildcard cannot: telling it to call
4
+ * hunch_why only costs it a failed lookup. Built-in and unknown types inherit
5
+ * the parent's tools. */
6
+ export declare function roleHasHunchTools(root: string, agentType: string, home?: string): boolean;
@@ -0,0 +1,32 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ /** Whether a delegated agent can call Hunch's MCP tools. A named role defined in
5
+ * `.claude/agents/<type>.md` (project first, then user) with a `tools:` list that
6
+ * names no `mcp__hunch` tool and no wildcard cannot: telling it to call
7
+ * hunch_why only costs it a failed lookup. Built-in and unknown types inherit
8
+ * the parent's tools. */
9
+ export function roleHasHunchTools(root, agentType, home = homedir()) {
10
+ const type = agentType.trim();
11
+ if (!type || !/^[\w.-]+$/.test(type))
12
+ return true;
13
+ for (const dir of [join(root, ".claude", "agents"), join(home, ".claude", "agents")]) {
14
+ let text;
15
+ try {
16
+ text = readFileSync(join(dir, `${type}.md`), "utf8");
17
+ }
18
+ catch {
19
+ continue;
20
+ }
21
+ const front = /^?---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1];
22
+ if (!front)
23
+ return true;
24
+ // A block list continues on indented "- x" lines; a flow list runs to its "]".
25
+ const tools = /^tools:[ \t]*(\[[^\]]*\]?|.*(?:\r?\n[ \t]+-.*)*)/m.exec(front)?.[1];
26
+ if (tools === undefined || !tools.trim())
27
+ return true;
28
+ return /\*|mcp__hunch/.test(tools);
29
+ }
30
+ return true;
31
+ }
32
+ //# sourceMappingURL=subagentrole.js.map