feat(session-start): make instinct injection count and confidence threshold configurable#2413
Conversation
…eshold configurable Expose ECC_MAX_INJECTED_INSTINCTS and ECC_INSTINCT_CONFIDENCE_THRESHOLD so operators can tune SessionStart instinct injection without editing source. Defaults are unchanged (6 instincts, 0.7 confidence floor). The two previously hardcoded constants become DEFAULT_-prefixed fallbacks, resolved through getMaxInjectedInstincts() and getInstinctConfidenceThreshold(), mirroring the existing getSessionRetentionDays() / getSessionStartMaxContextChars() env-override pattern already in this file. Invalid or out-of-range values fall back to the defaults. Adds subprocess coverage in tests/hooks/hooks.test.js and documents both variables in the README Hook Runtime Controls section. Implements part (a) of affaan-m#2371.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds environment-driven controls for instinct injection limits in ChangesConfigurable Instinct Injection
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant SessionStartHook
participant Resolvers
participant InstinctsList
SessionStartHook->>Resolvers: getInstinctConfidenceThreshold()
SessionStartHook->>Resolvers: getMaxInjectedInstincts()
Resolvers-->>SessionStartHook: confidenceThreshold, maxInjected
SessionStartHook->>InstinctsList: filter by confidenceThreshold
SessionStartHook->>InstinctsList: slice to maxInjected
InstinctsList-->>SessionStartHook: injected instincts
Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
|
| Filename | Overview |
|---|---|
| scripts/hooks/session-start.js | Adds validated env resolvers for the instinct threshold and injection cap, then applies them during SessionStart instinct selection. |
| tests/hooks/hooks.test.js | Adds subprocess tests for defaults, valid overrides, invalid strings, fractional counts, exponent counts, and hex thresholds. |
| README.md | Documents the new SessionStart hook runtime controls. |
Reviews (3): Last reviewed commit: "fix(session-start): validate decimal gra..." | Re-trigger Greptile
…knobs
Parse ECC_MAX_INJECTED_INSTINCTS and ECC_INSTINCT_CONFIDENCE_THRESHOLD with
Number() (after trim) instead of parseInt/parseFloat, so malformed values
like "3.9", "6abc", or "0.7x" fall back to the default rather than silently
accepting the numeric prefix (parseInt("3.9")=3, parseFloat("0.7x")=0.7).
Adds a regression assertion that a non-integer count falls back to 6.
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
…nv vars Number() still accepts non-decimal numeric syntax, so ECC_INSTINCT_CONFIDENCE_THRESHOLD=0x1 resolved to 1 and ECC_MAX_INJECTED_INSTINCTS=1e2 to 100. Gate each value on a strict format (/^\d+(\.\d+)?$/ for the 0-1 threshold, /^\d+$/ for the positive-integer count) before converting, so hex/exponent/partial values fall back to the default. Adds regression assertions for 1e2 and 0x1.
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
daltino
left a comment
There was a problem hiding this comment.
This PR introduces configurable parameters for the instinct injection count (ECC_MAX_INJECTED_INSTINCTS) and confidence threshold (ECC_INSTINCT_CONFIDENCE_THRESHOLD), which enhances flexibility for the SessionStart feature. The changes align with the contribution guidelines, as they add valuable configuration options to hooks, include documentation updates in README.md, and come with appropriate tests verifying the feature's behavior. The changes are well-documented and maintain backward compatibility with the default settings.
What Changed
Makes the two SessionStart instinct-injection knobs in
scripts/hooks/session-start.jsconfigurable via environment, keeping thecurrent values as defaults:
ECC_MAX_INJECTED_INSTINCTS— cap on how many learned instincts getinjected into context at SessionStart (default
6).ECC_INSTINCT_CONFIDENCE_THRESHOLD— minimum confidence, in[0, 1],an instinct needs to be injected (default
0.7).The two hardcoded constants (
MAX_INJECTED_INSTINCTS,INSTINCT_CONFIDENCE_THRESHOLD) becomeDEFAULT_-prefixed fallbacks and arenow resolved through
getMaxInjectedInstincts()/getInstinctConfidenceThreshold(), mirroring the file's existinggetSessionRetentionDays()/getSessionStartMaxContextChars()env-overridepattern. Invalid or out-of-range values fall back to the defaults.
This is part (a) of #2371 — the smaller, self-contained change the issue
author offered to land first ("Happy to scope it to just (a) first if you
prefer the smaller change"). Part (b) (confidence + stack/project relevance
ranking) is intentionally left for a separate PR to keep this one surgical.
Why This Change
Instinct selection is currently confidence-only with a hardcoded count and
threshold, so tuning injection behavior requires editing (and re-editing after
every update) source constants. Exposing them as env vars removes that friction
— e.g. lower
ECC_MAX_INJECTED_INSTINCTSfor low-context/local-model setups, orraise
ECC_INSTINCT_CONFIDENCE_THRESHOLDto inject only high-confidenceinstincts — with zero behavior change when the vars are unset.
Testing Done
node tests/run-all.js— 2939/2939 pass (clean env,CLAUDE_PLUGIN_ROOTunset)tests/hooks/hooks.test.jssubprocess coverage:ECC_MAX_INJECTED_INSTINCTS=3injects 3; garbage value falls back to 60.7threshold injects only above-floor instincts;0.95filters all out;0.5passes all (still capped at 6)npx eslint scripts/hooks/session-start.js tests/hooks/hooks.test.js— cleannpx markdownlint README.md— cleanscripts/ci/validate-no-personal-paths.js,check-unicode-safety.js,validate-hooks.js— all passType of Change
Security & Quality Checklist
Number.parseInt/Number.parseFloat+ range checks) with safe fallbackDocumentation
existing comment+export style.
Part of #2371 — implements part (a) (env-configurable knobs). Part (b)
(confidence + stack/project relevance ranking) is left as a follow-up; happy
to open that separately or fold it in if you'd prefer a single PR.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests