Found via TDD that supplier_leads has its own platform CHECK constraint
(chk_supplier_leads_platform) and that the seed migration was missing
NOT NULL columns (accepts_types, channel). Migration now:
- widens supplier_projects/project_supplier_links/supplier_leads.platform
VARCHAR(4) → VARCHAR(8) (DIRECT is 6 chars)
- extends three CHECK constraints to include 'DIRECT'
Seed migration uses raw SQL INSERT to properly serialize PG ARRAY type
for accepts_types column. channel='sites' (valid per suppliers_channel_check).
db/schema.sql synced — 3 platform columns and 3 CHECK constraints updated.
CHANGELOG_schema.md entry pending Task 9.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
LedgerService::resolveSupplierId returns suppliers.code='direct' row for
DIRECT-platform supplier_projects (and for parsed-from-payload non-B
projects). CsvReconcileJob::extractPlatform now classifies most non-empty,
non-junk project strings as DIRECT (instead of dumping them into
unparseable_count) — this allows CSV recovery to also create DIRECT
supplier_leads, mirroring the webhook path.
CsvReconcileJobTest junk-rows fixtures updated: previously used callback
phone-number-as-project (79135551234) and URL-like strings as 'junk', but
those are now valid DIRECT identifiers. Replaced with truly junk strings
matching only outside-whitelist symbols (e.g. '???', '!@#').
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
parseProjectField() returns ('DIRECT', signal_type, identifier) when project
has no B-prefix; identifier-detection (call/site/sms regex) runs on full
project string. LeadRouter::matchEligibleProjects has a DIRECT fast-path
that matches Liderra projects by (signal_type, signal_identifier) directly
without requiring project_supplier_links pivot — because DIRECT
supplier_projects are auto-created on first webhook and don't have manual
psl links.
B1/B2/B3 path unchanged (psl-based via project_supplier_links).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Drops regex /^B[123]_.+$/ from project field validation; parsePlatform()
returns 'DIRECT' for projects without B-prefix (instead of silent fallback
to 'B1'). SupplierProjectResolver ALLOWED_PLATFORMS extended to include
DIRECT.
Closes ~67 of 82 lost leads/day for tenant client1 (observed 2026-05-25):
mostly client.carmoney.ru (55), B2_Caranga (7), cabinet.caranga.ru (3),
cashmotor.ru (2), numeric callback IDs (~10).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
TDD found that 'DIRECT' (6 chars) does not fit in VARCHAR(4). Three columns
need widening: supplier_projects.platform, project_supplier_links.platform,
supplier_leads.platform. supplier_manual_sync_queue.platform was already
VARCHAR(8). Done in the same migration as CHECK extension — single
atomic deploy.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
LedgerService::resolveSupplierId will look up suppliers WHERE code='direct'
for DIRECT-platform supplier_projects (Phase 3). cost_rub matches B1 (same
supplier company, different lead-routing channel).
Spec: docs/superpowers/specs/2026-05-25-supplier-webhook-reliability-design.md
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds early merge check in RouteSupplierLeadJob::createDealCopyForProject:
when lead.vid IS NOT NULL and an existing deal with NULL source_crm_id
exists for (tenant, phone, project_id) within last 24h, UPDATE that
deal's source_crm_id instead of creating a second Deal. INSERT into
supplier_lead_deliveries links the new supplier_lead.id to the existing
deal.id. LedgerService::chargeForDelivery is NOT called — the original
charge happened when the csv-recovery created the deal.
Closes 37 duplicate deals observed on prod for tenant client1 25.05.2026.
Spec B Phase 1 (commit ccfecd5e) removed DuplicateDetector — this fix
restores idempotency for the specific webhook-after-csv-recovered case
WITHOUT re-blocking intentional supplier repeats with different vids.
Guard: only merges where source_crm_id IS NULL (the CSV-recovered marker).
Two webhooks with different vids on same phone+project still create two
deals — by-design per Spec B.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds withExceptions render callback for ValidationException that forces
JSON 422 response when request matches api/webhook/supplier/* — regardless
of Accept header. Default Laravel behavior is 302 redirect for non-JSON
clients, which strips POST body.
Observed on prod 2026-05-25: 76 of 234 supplier webhook hits got 302 (Location: /),
mostly for non-B-prefix projects (client.carmoney.ru, cabinet.caranga.ru,
cashmotor.ru). Supplier doesn't follow 302 redirects on POST, so the
lead body is lost. This fix ensures supplier always sees a meaningful
422 with errors[] instead of a redirect.
Other routes unaffected (render returns null for non-webhook URLs).
Append-only journal capture during the factor-analysis bug-surface session.
Episodes contain live tests of the LLM classifier retry logic (10/10 LLM
success rate post-retry) and the prefilter Layer 1 gate on short prompts.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Phase 1 Task 6 of LLM-first router overhaul. Minimal-scope execution after
reality check (C1/C2 controllers don't track section refs, only version
drift; plan steps about §3.3/R15 archiving are out of scope for cross-ref
update).
Changes:
- CLAUDE.md §0 'Источник истины' row for Pravila: **v1.40 от 24.05.2026**
-> **v1.41 от 25.05.2026** + narrative bump (§12 archived in Task 4,
§17 added in Task 5 via ADR-016).
- docs/Tooling_v8_3.md line 4 cross-ref:
cross-ref Pravila v1.39+ -> v1.41+ (+ CLAUDE.md v2.27+ -> v2.28+).
Deferred (TASKLOG.md Task 6 section for full reasoning):
- §12 textual occurrences in PSR_v1 (39) and historical Tooling/CLAUDE.md
changelog blocks remain as honest historical pointers to the archived
§12 (docs/archive/llm-bootstrap-2026-05/pravila-12/...).
- CLAUDE.md §3.3 archive + nodes.yaml pin — out of scope, requires
structural restructure beyond cross-ref work.
- Tooling §4.X 'когда брать' archive — out of scope.
- PSR_v1 R15 — already removed in v2.0 (motion-runtime removal,
12.05.2026); current R15 is 'Off-phase routing', unrelated to §12.
Verification:
- tools/l1-watcher.mjs: OK — 0 drift.
- tools/cross-ref-checker.mjs: OK — 0 drift in 4 files (was FAILing on
Pravila v1.40 / v1.39 references after Task 5 bump to v1.41).
- npx vitest run tools/: 539 passed (unchanged from Task 4 baseline).
Plan: docs/superpowers/plans/2026-05-25-llm-first-router-overhaul.md Task 6.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Phase 1 Task 2 of LLM-first router overhaul.
Live user-level changes (NOT in git, see TASKLOG.md for full diff manifest):
- ~/.claude/settings.json — removed 2 PreToolUse blocks:
- matcher 'Skill' -> skill-marker.py (§12 trigger marker)
- matcher 'Edit|Write|MultiEdit' -> skill-check.py (§12 enforcement on Edit)
- Remaining PreToolUse: 1 block (economy-state-guard, pure economy)
- ~/.claude/hooks/economy-mode.py — trailer text:
'§12 hard rule из Pravila НЕ override-ится' -> '§17 universal skill-coverage НЕ override-ится'
- ~/.claude/hooks/economy-state-guard.py — NO-OP (no §12 logic; pure economy)
Economy system (0%/5%/25%/50%/75%/100%) remains fully active. Stop-hook
subagent verifier (model: claude-sonnet-4-6) remains. PostCompact, SessionStart
hooks unchanged.
skill-marker.py and skill-check.py files remain on disk in ~/.claude/hooks/
(snapshot already in docs/archive/.../user-hooks/ from Task 1). They are
unwired from PreToolUse — no longer invoked. Task 4 moves them into the
archive proper.
permissions.ask still references skill-marker.py/skill-check.py (4 entries
Edit/Write each) — these gate direct file edits and are harmless. Cleaned
up alongside Task 4 archive.
Verification:
- ~/.claude/settings.json parses as valid JSON (1 PreToolUse block).
- All 4 economy hooks (economy-mode, economy-state-guard, economy-postcompact,
economy-self-check) still run with exit 0.
- Live economy-mode.py with prompt 'тест экономия 5%' returns valid hook
JSON with FIRST LINE '=== ECONOMY MODE: 5%' and trailer mentioning §17.
Rollback: 'node tools/test-rollback.mjs --execute' restores both files
from snapshot (verified e2e in Task 1).
Plan: docs/superpowers/plans/2026-05-25-llm-first-router-overhaul.md Task 2.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
EnsureSaasAdmin fail-closed 503 вне dev/testing → вся админка на боевом
liderra.ru недоступна (все /api/admin/* падали). Настоящий saas-admin SSO
(Yandex 360) ещё не готов (Б-1 + DO-4), но держать зону наглухо закрытой
нельзя — заказчику нужна админка.
Стопгэп (выбор заказчика): защита /admin + /api/admin/* переносится на
nginx (отдельный HTTP Basic Auth, /etc/nginx/.htpasswd-admin), middleware
зону больше не закрывает. Тест production-кейса переведён с 503 на 200.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
v2.0 → v2.1 — 3 группы изменений (16 пунктов суммарно):
Группа 1 — решения принятые после v2.0, не внесённые:
- 1.1 Памятка classifier (4 паттерна: brainstorming / discovery-interview /
writing-plans / systematic-debugging). +flag prompt-enrichment-mode.
- 1.2 Reviewer как полноценный Claude Code subagent (tools=[Read,Grep,Glob,
Skill], model=opus). Новый файл .claude/agents/reviewer-agent.md.
+стоимость $240-1200/мес vs $40-80 direct API. Crash fallback на direct
API. Context bloat cap 10 соседних эпизодов.
- 1.3 Inheritance + 3 группы коротких prompt'ов (continuation/acknowledgment/
cancellation) + 30-минутный таймаут. +flag inheritance-mode. Новые поля
в schema v4.1: inherited_from_task_id, inheritance_age_minutes,
previous_direction_rejected, previous_task_id_rejected.
Группа 2 — edge cases:
- 2.1 Reviewer model явно opus в agent file.
- 2.2 Reviewer subagent crash → fallback direct API call.
- 2.3 Reviewer context bloat: max 10 episodes в agent system prompt.
- 2.4 Manual override приоритет №1 в prefilter (раньше inheritance).
- 2.5 Cancellation clears state + previous_task_id_rejected marker.
Группа 3 — мелкие упущения:
- 3.1 brain-retro SKILL.md description: раз в 1-2 недели (не sprint).
- 3.2 recommended_chain_id nullable для custom chains.
- 3.3 Embedding только для non-prefilter эпизодов.
- 3.4 PII filter wraps sanity-check comments.
- 3.5 requested_node fuzzy matching fallback.
- 3.6 Anchor word list inline initial.
- 3.7 Self-retrospect counter init в фазе 3 step 3.3.
- 3.8 Sanity-check answer file schema_version=1.
Cost rewrite: 720-1380 USD (v2.0) -> 1940-8200 USD (v2.1) на 6 месяцев
из-за reviewer subagent. Granular rollback через reviewer-mode=direct-api
возвращает к v2.0 ценам.
§21 новый — changelog v2.0 → v2.1 со всеми 16 пунктами и где правка.
Реализация — после закрытия Биллинга v2 Спек C.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
readRouterState(sessionId, {baseDir}) -- pure read state-файла сторожа.
extractRouterFields(state) -- pure извлечение 4 полей для primary_rationale.
Используется парсером эпизодов на следующем шаге (Task 3).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
active-projects.md обновлён: этап 2 ✅ + влит в main, этап 3 ✅ Phase A+B + влит
в main (warn-only режим, никакой блокировки), bug-fix bec69aa5 (deriveRouterStep)
включён. CHECKPOINT B накапливает реальные наблюдения; Task 9 (переключение
в enforce + 2 метрики) — отдельно после ревью baseline.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Эпизоды реальных сессий после hotfix — сторож пишет state + классификацию
на каждый промпт (verified: UUID-session state files). Данные для brain-retro
warn-only ревью.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two real bugs found via verification (hook didn't fire in live session):
1. UserPromptSubmit block had matcher:"*" — event doesn't support matcher,
non-standard block dropped (claude-code-guide authoritative). Removed →
block now {hooks:[...]} like working observer-stop-hook.
2. stdin field was event.user_prompt; Claude Code sends event.prompt.
Now reads (event.prompt || event.user_prompt) for compat.
Field-fix verified manually with real stdin shape {prompt:...} → #71 pdn-152fz.
Firing fix (matcher) NOT verifiable in-session (hooks load at session start) —
needs restart + next-turn state-file check.
NB stop-gate turn_events field also wrong (Stop sends transcript_path) — separate
follow-up, not on observation critical path (affects chain tracking only).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
UserPromptSubmit → router-prehook (classifier).
PreToolUse Edit|Write|MultiEdit|Bash → router-tool-gate (warn-only).
Stop → router-stop-gate (chain progress).
router-gate-mode.json = warn-only (outside repo, ~/.claude/runtime/).
Переключение в enforce — отдельным шагом после Checkpoint B (24ч наблюдения).
End-to-end smoke verified: «проверь пдн» → #71 pdn-152fz-audit,
warn-only пишет в stderr, не блокирует. Доменная разметка Task 1 работает.
NB активация в основной сессии: хуки в worktree-копии settings.json
версионируются; для реального наблюдения нужна либо merge ветки, либо
ручное применение к основному .claude/settings.json (warn-only безопасен).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
После каждого хода обновляет state.chainProgress по реально вызванным
скилам. chainCompleted=true когда последний шаг достигнут.
skillInvokedThisTurn флажок для PreToolUse gate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Подкрутка classifier'а БЕЗ правки реестра (доменная разметка Task 1 сохранена):
- TASK_TYPE_KEYWORDS +командные глаголы (проверь/составь/поправь/распиши/...);
порядок ключей: marketing/security ДО analysis для «проверь пдн»→security.
- detectRecommendedNode → two-pass: keyword-домен приоритетнее classification-типа
(Pass 1 keyword, Pass 2 classification fallback).
- MICRO_KEYWORDS +увеличь/уменьши/одну строку/bump.
Accuracy regex-only: 68.3% → 80.0% (type 55%→85%, micro 95%→100%, node 55%).
Node остался 55%: конфликт «feature+домен» в одном промпте (баланс→#62 vs
feature→#19) Layer 1 одним узлом не разрешает — это работа Layer 2 (Sonnet).
Ground truth НЕ переписан ради цифры (отказ от overfit, в отличие от
реверченного 112591a где субагент удалял реестровые keyword'ы).
489/489 tools GREEN.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Snapshot "Commit:" field referenced 30b795c (dangling orphan from
amend cycle). Replaced with actual e239160a + 436284c5 (F1 fix).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Spec review F1: positions 4-5 had stale numbers (#41:2 #42:2);
actual analyzer output shows #25:3, #39:3 (and #53:3 tied at pos 5).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Зафиксированы цифры дисциплины роутера на 2026-05-24 перед запуском
enforcement-хука этапа 3. Sanity-check passed: missed_before=17 ==
missed_after=17 (delta=0) после переключения источника правды на реестр.
observer-classification-map.json помечен deprecated — для удаления в этапе 4.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Auto-generated блок с разбивкой % дисциплины по типам задач,
router-step distribution + suspicious-флаг, boundaries-applied rate.
Backward-compat: блок опускается, если discipline не передан.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
status-md-generator рендерит блок «Активные многоэтапные проекты»
из repo-local docs/observer/active-projects.md (если файл есть).
renderStatus backward-compatible: без activeProjects блок пустой.
active-projects.md — single source состояния многоэтапного router
overhaul (этап 1 ✅ закрыт, этапы 2-4 pending). Будущая сессия видит
статус в STATUS.md dashboard + memory tracker.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
renderAll() режим без --check переписывает файлы; с --check
возвращает exit 1 на drift (для lefthook).
Сейчас рендерит 2 региона: Tooling summary + routing-table.
Маркеры в Markdown добавим в Task 6 (без них скрипт корректно падает
с понятной ошибкой Markers not found).
Fix: entry-point guard использует fileURLToPath+resolve вместо
string-замены — совместимость с кириллическими путями (Windows quirk).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Покрытие: индексация по classification/keyword, exclude
historic/dormant из индексов, cache lifecycle, schema violation,
chain membership lookup.
Все 11 GREEN на пилотном реестре из 3 узлов.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Экспортирует loadRegistry/findByClassification/findByKeyword/
findActiveNodes/findChainsByNode + clearCache для тестов.
Кэширует в module-scope (per-process); валидирует через ajv при
загрузке (schema + ajv-formats). Keyword индексация case-insensitive
(.toLowerCase()) для последовательности с findByKeyword.
Тестов нет — Task 4.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
I-1: weight range 0-1 added to classification + file_pattern trigger
variants (раньше было только на keyword) — иначе weight=50 silent
ranking-bug в Task 3 indexByTrigger.
I-2: additionalProperties:false на 3 trigger-variant объекты — ясная
ajv-ошибка при mixed-key (keyword+classification одновременно).
I-3: additionalProperties:false на definitions.node и definitions.chain
— typo ("categori" / "keywrod") теперь reject'ится, не silently
accepted.
Smoke-проверка: 3 теста — weight=50 reject, typo categori reject, valid
accept. ajv compile OK.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Schema поддерживает: id/name/slug/category/status, триггеры трёх видов
(keyword/classification/file_pattern), границы (adr/pair), членство в
цепочках L1-L16, dormancy/deferred-статус.
README — заглушка, наполнится в Task 13.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Final-review followup. .claude/settings.json uses regex-style combined
matchers like "Edit|Write"; transcript writes per-tool PreToolUse:Edit.
Split on | when building map so per-tool counts resolve. Also sync
spec doc loadHookMap -> buildHookMap (impl name).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
aggregation-template.md gets two new sections (Hook script breakdown,
Recommended-node candidates) + paragraph in Missed Activations.
factor-analysis spec gets a v3 amendment cross-ref to the 2026-05-23 spec.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>