feat(laws): add always-injected one-liner tier for permanent instincts#9
Open
NestorPVsf wants to merge 1 commit into
Open
feat(laws): add always-injected one-liner tier for permanent instincts#9NestorPVsf wants to merge 1 commit into
NestorPVsf wants to merge 1 commit into
Conversation
Introduces a Laws tier: always-injected one-liner projections of permanent instincts (or fs-cortex stand-alone seeds), injected at SessionStart with rotation by last_injected ASC, cap 10 laws / ~300 tokens per session. - core/_laws-injector.sh (70 LOC): SessionStart hook with YAML-frontmatter parser, MAX_LAWS=10 and TOKEN_BUDGET=300 caps, atomic tmp+rename write for last_injected update. - seeds/laws/: 5 seeds ported from fermontero/fs-cortex (MIT): read-first, grep-read-verify, git-triple-check, never-hardcode-secrets, three-layer-security. - core/settings.template.json: adds SessionStart hook block (hooks total 6 to 7). - install.sh: copies injector + seed laws into ~/.claude/skills/_laws/ (idempotent, preserves existing last_injected on upgrade). - commands/promote.md: new Step 4 distills a Law when an instinct is promoted to permanent. - tests/test-laws.sh: 10 TDD tests, 10/10 GREEN. Suite 116 to 126. - docs/FEATURES.md: Laws tier section. Credit: Fernando Montero (github.com/fermonterom/fs-cortex, MIT).
NestorPVsf
pushed a commit
to NestorPVsf/sinapsis
that referenced
this pull request
Apr 18, 2026
Addresses 3 bugs flagged by Codex CLI during PR Luispitik#9 review. All 3 are pre-existing in the feat(seeds) commit of PR Luispitik#8. P1: install.sh hardcoded `python` instead of `$PYTHON_CMD` detected in Step 1. On systems with only python3 in PATH, seed import failed and was silently swallowed by `|| true`. Uses `$PYTHON_CMD` now with a warning fallback when Python is unavailable. P2: parse_yaml_simple stripped quotes but did not decode backslash escapes. Seeds with `"spec\.ts"` were stored with literal backslashes, producing invalid regex. Added _decode_yaml_double_quoted (handles \ \" \n \t \r) and _decode_yaml_single_quoted (`''` → `'`). Fixes 3 broken seeds: e2e-playwright-selectors, security-headers-vercel, supabase-rls-auth-uid. P2: _instinct-activator.sh pre-filters by ALWAYS_DOMAINS + stack-detected domains when context.md exists. Seed domains workflow-general, testing, web-development, saas-development are outside both sets so those seeds never reached regex evaluation. Added DOMAIN_MAP in importer: workflow-general → operations, testing → quality, web-development → frontend, saas-development → stripe. original_domain preserved for traceability. Tests: 3 new in test-seeds.sh (9-11). Suite 8/8 → 11/11 GREEN. Credit: bugs identified by Codex CLI (cross-model review).
This was referenced Apr 18, 2026
Luispitik
requested changes
Jun 10, 2026
Luispitik
left a comment
Owner
There was a problem hiding this comment.
The idea fits the scope (laws as a projection of permanent instincts — the activate layer of the observe→learn→index→activate pipeline), and the base code is solid: node is already a hard prerequisite, no eval, quoted paths, per-file try/catch, sandboxed tests. So this is not a close — but it can't merge as-is:
- Doesn't apply on v4.6.1 —
git apply --checkfails on 4 of the 6 modified files (CHANGELOG.md,core/settings.template.json,docs/FEATURES.md,install.sh). The branch predates v4.5; please rebase. - Version collision: v4.5.0 was released in main (Opus 4.7 + PreCompact hook). Renumber to the next free version, and after the rebase
settings.template.jsonmust declare_hooks_total: 8with PreCompact included — your diff proposes 6→7 omitting PreCompact, which a careless conflict resolution would drop from everyone's settings. install.batparity is missing — it copies each hook explicitly (lines 147-153) and would receive neither_laws-injector.shnor the seeds nor the SessionStart block. Windows users would get a SessionStart hook pointing at a script that doesn't exist (silent no-op): the population that already reports the most bugs would be the one silently excluded from the feature.
Injector tweaks for the new revision:
- Pass the laws dir from bash into node via env (
LAWS_DIR="$LAWS_DIR" node -e '…'readingprocess.env.LAWS_DIR) instead of reconstructing it fromprocess.env.HOME— MSYS path conversion makes the reconstructed path a silent-no-op risk on Git Bash. - The trailing
2>/dev/nullon the node block defeatsSINAPSIS_DEBUG'sexec 2>>— make the redirect conditional onSINAPSIS_DEBUG != 1. - Use
continue, notbreak, when a law exceeds the token budget — as written, one long law at the head of the rotation starves all the short ones behind it. - Reconsider shipping
three-layer-securityas a default seed — "middleware → API validation → Supabase RLS" is stack-specific and doesn't generalize in a public MIT repo. Make seeds opt-in (e.g.--with-seed-laws) or keep only the generic four. /promote --lawis mentioned in the body/CHANGELOG butcommands/promote.mddoesn't define that flag — align the docs with the interactive Step 4 you actually implemented.- After the rebase: re-run the full suite and refresh the test badge (main has grown since your base), add an assertion to
tests/test-install-upgrade.shthat both installers leave_laws/populated and that a re-install preserveslast_injected, and add a note to FEATURES.md recording the (accepted) tension betweenlast_injectedrotation and the v4.5 byte-stable-ordering philosophy — one injection per session makes it fine, but it should be a documented decision, not an accident.
The unconditional context cost (~128-300 tokens per session for every user, with seeds not opt-in) is the part I most want to see addressed in the next revision. Looking forward to the rebase.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a Laws tier: always-injected one-liner projections of permanent instincts (or fs-cortex stand-alone seeds), injected at
SessionStartwith rotation bylast_injectedASC. Cap: 10 laws / ~300 tokens per session. Purely additive — no existing command or schema changes.Model
source_instinct: nullmeans the law is a stand-alone seed (e.g. fs-cortex import). When/promote --lawdistills a permanent instinct,source_instinctpoints to that instinct id.Changes
core/_laws-injector.sh(new, 70 LOC): SessionStart hook with YAML-frontmatter parser,MAX_LAWS=10/TOKEN_BUDGET=300caps, atomictmp → renamewrite forlast_injectedupdate (survives concurrent sessions).seeds/laws/*.txt(5 new): ported fromfermontero/fs-cortex(MIT © Fernando Montero):read-first,grep-read-verify,git-triple-check,never-hardcode-secrets,three-layer-security.core/settings.template.json: addsSessionStartblock (_hooks_total: 6 → 7,_hooks_breakdown:SessionStart(1) + PreToolUse(4) + PostToolUse(1) + Stop(1)).install.sh: copies injector + seed laws into~/.claude/skills/_laws/. Idempotent — existing files preserve theirlast_injectedon upgrade.commands/promote.md: new Step 4 offers Law distillation when an instinct is promoted topermanent.tests/test-laws.sh(new, 10 TDD tests): presence, seed count, empty-dir silent exit, emission format,MAX_LAWScap,last_injectedatomic update, rotation ordering, malformed-file resilience, whitespace normalization. 10/10 GREEN. Suite: 116 → 126.docs/FEATURES.md: Laws tier section.CHANGELOG.md: v4.5.0 entry with rationale.Rationale
Sinapsis already projected patterns as instincts (regex-gated, per-tool-use injection). What was missing: a thin tier of always-on crystallized wisdom — the 5-10 principles the user never wants to risk forgetting, no matter the context. Matches fs-cortex's `laws` concept without replacing instincts: laws are a projection of permanents, not a parallel registry.
Test plan
Independence
Branches from `main` (45949ed `chore: bump version to v4.4.1 (#5)`). No dependency on PR #8 (seeds/instincts) or PR #7 (dashboard fix). Can merge in any order.
Credit
`seeds/laws/*.txt` — MIT © 2026 Fernando Montero, ported from fermontero/fs-cortex. Attribution preserved in each file's frontmatter.