Skip to content

feat(session-start): make instinct injection count and confidence threshold configurable#2413

Open
gaurav0107 wants to merge 3 commits into
affaan-m:mainfrom
gaurav0107:fix/2371-feat-rank-sessionstart-injected-instinct
Open

feat(session-start): make instinct injection count and confidence threshold configurable#2413
gaurav0107 wants to merge 3 commits into
affaan-m:mainfrom
gaurav0107:fix/2371-feat-rank-sessionstart-injected-instinct

Conversation

@gaurav0107

@gaurav0107 gaurav0107 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What Changed

Makes the two SessionStart instinct-injection knobs in
scripts/hooks/session-start.js configurable via environment, keeping the
current values as defaults:

  • ECC_MAX_INJECTED_INSTINCTS — cap on how many learned instincts get
    injected 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) become DEFAULT_-prefixed fallbacks and are
now resolved through getMaxInjectedInstincts() /
getInstinctConfidenceThreshold(), mirroring the file's existing
getSessionRetentionDays() / getSessionStartMaxContextChars() env-override
pattern. 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_INSTINCTS for low-context/local-model setups, or
raise ECC_INSTINCT_CONFIDENCE_THRESHOLD to inject only high-confidence
instincts — with zero behavior change when the vars are unset.

Testing Done

  • node tests/run-all.js2939/2939 pass (clean env, CLAUDE_PLUGIN_ROOT unset)
  • Added tests/hooks/hooks.test.js subprocess coverage:
    • default cap injects 6; ECC_MAX_INJECTED_INSTINCTS=3 injects 3; garbage value falls back to 6
    • default 0.7 threshold injects only above-floor instincts; 0.95 filters all out; 0.5 passes all (still capped at 6)
  • npx eslint scripts/hooks/session-start.js tests/hooks/hooks.test.js — clean
  • npx markdownlint README.md — clean
  • scripts/ci/validate-no-personal-paths.js, check-unicode-safety.js, validate-hooks.js — all pass

Type of Change

  • New feature (non-breaking; env-gated, defaults preserved)

Security & Quality Checklist

  • No new dependencies
  • No secrets, no network calls, no personal absolute paths
  • Env values validated (Number.parseInt / Number.parseFloat + range checks) with safe fallback
  • Surgical scope — one concern, single production file + its test + a doc note
  • Behavior unchanged when the new env vars are unset

Documentation

  • README "Hook Runtime Controls" section documents both new variables in the
    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

    • Added environment-based controls for learned instinct injection at session start, including a configurable maximum count and confidence threshold.
  • Bug Fixes

    • More reliable handling of invalid environment values by falling back to safe defaults.
    • Injection behavior now consistently applies both the confidence threshold and the maximum injection cap.
  • Documentation

    • Updated README with the new environment variables and their default values.
  • Tests

    • Added edge-case tests covering defaulting, invalid overrides, threshold filtering, and max-limit enforcement.

…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.
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f846fad5-f9bb-40c3-8c23-29d646958d71

📥 Commits

Reviewing files that changed from the base of the PR and between 297eb29 and 1b79e77.

📒 Files selected for processing (2)
  • scripts/hooks/session-start.js
  • tests/hooks/hooks.test.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/hooks/session-start.js
  • tests/hooks/hooks.test.js

📝 Walkthrough

Walkthrough

Adds environment-driven controls for instinct injection limits in session-start.js, with validation, runtime filtering updates, and README documentation for the new variables.

Changes

Configurable Instinct Injection

Layer / File(s) Summary
Resolver functions and defaults
scripts/hooks/session-start.js
Replaces fixed threshold/cap constants with DEFAULT_INSTINCT_CONFIDENCE_THRESHOLD and DEFAULT_MAX_INJECTED_INSTINCTS, and adds getInstinctConfidenceThreshold()/getMaxInjectedInstincts() to parse and validate ECC_INSTINCT_CONFIDENCE_THRESHOLD and ECC_MAX_INJECTED_INSTINCTS, falling back to defaults on invalid input.
Injection logic wiring
scripts/hooks/session-start.js
summarizeActiveInstincts computes confidenceThreshold and maxInjected from the resolvers and uses them in the filtering condition and final slicing of ranked instincts.
Documentation update
README.md
Documents ECC_MAX_INJECTED_INSTINCTS and ECC_INSTINCT_CONFIDENCE_THRESHOLD with their default values.

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
Loading

Possibly related issues

Suggested reviewers: affaan-m, daltino

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: configurable instinct injection count and confidence threshold for session-start.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ecc-tools

ecc-tools Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@gaurav0107 gaurav0107 marked this pull request as ready for review July 1, 2026 12:34
@gaurav0107 gaurav0107 requested a review from affaan-m as a code owner July 1, 2026 12:34
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes SessionStart instinct injection configurable through environment variables. The main changes are:

  • Adds env-backed controls for instinct count and confidence threshold.
  • Keeps the existing default injection behavior when env vars are unset or invalid.
  • Documents the new hook runtime controls in the README.
  • Adds subprocess tests for valid overrides and invalid numeric formats.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

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

Comment thread scripts/hooks/session-start.js
…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-tools

ecc-tools Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

Comment thread scripts/hooks/session-start.js
…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-tools

ecc-tools Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@daltino daltino left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants