@dzhechkov/keysarium 1.5.23 → 1.5.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dzhechkov/keysarium",
3
- "version": "1.5.23",
3
+ "version": "1.5.27",
4
4
  "description": "AI Case Research Toolkit for Claude Code — full 7-phase pipeline with feature-adr, dream cycles, background workers, multi-platform support, reward learning, and Cloud.ru AI Factory mapping (--ai-factory flag)",
5
5
  "main": "src/cli.js",
6
6
  "bin": {
@@ -375,6 +375,69 @@ Pre-flight, if Codex is `ready` (`codex-companion setup --json`), the orchestrat
375
375
  before launching; plain `/feature-adr` offers the same at the planning checkpoint. Omit the Codex knobs
376
376
  for today's all-Claude behavior. See `.claude/rules/feature-adr-ultracode.md`.
377
377
 
378
+ **Per-stage model routing — `args.models` (one dial, 11 stages).** `args.models` is an optional map that
379
+ routes each pipeline stage to an optimal model. Keys: `{router, requirements, research, adr, ideation,
380
+ ddd, architecture, plan, code, qe, fleet}`. Each value is a **spec**:
381
+
382
+ - **Claude** — `'fable' | 'opus' | 'sonnet' | 'haiku'` → adds `model` to that stage's `agent()` call
383
+ (any role `agentType` like `qe-code-reviewer` is PRESERVED).
384
+ - **Codex** — `'codex'` / `'codex:<id>'` / `'codex:<id>:<reasoning>'` (e.g. `'codex:gpt-5.6:xhigh'`;
385
+ `reasoning ∈ low|medium|high|xhigh`; ids incl. `gpt-5.5`, `gpt-5.6`) → routes the stage to the
386
+ `codex:codex-rescue` runtime with that `codexModel` + reasoning hint.
387
+
388
+ **Recommended DEFAULT TABLE** (applied only when you opt into routing — any one `args.models` key or any
389
+ Codex knob flips it on; otherwise every stage stays session-inherited, byte-identical to today):
390
+
391
+ | Stage | Default | | Stage | Default |
392
+ |---|---|---|---|---|
393
+ | router | `fable` | | architecture | `opus` |
394
+ | requirements | `sonnet` | | plan | `sonnet` |
395
+ | research | `sonnet` (folds into requirements) | | code | *the coder knob* (default Claude `opus`) |
396
+ | adr | `opus` | | qe | *CROSS-MODEL of the coder* (see below) |
397
+ | ideation | `sonnet` | | fleet | `sonnet` |
398
+ | ddd | `opus` (folds into architecture) | | | |
399
+
400
+ **Cross-model QE default (load-bearing).** When `args.models.qe` is UNSET, QE is auto-routed to the
401
+ **other model family than the coder** — a model that WRITES code must not also SELF-QE; independent
402
+ cross-model review catches what self-review misses. coder=Codex ⇒ QE=Claude (`opus`); coder=Claude ⇒
403
+ QE=Codex (`codex:<top>:high`), or a Claude reviewer if Codex is unavailable (**never blocks**).
404
+
405
+ **Precedence.** `args.models[stage]` is the general mechanism and WINS on conflict; the legacy
406
+ `planner`/`coder`/`qeReviewer`/`codexModel` knobs are shortcuts that fill a stage only when `args.models`
407
+ does not. `codexModel` sets the default id for a bare `'codex'` spec. Codex-fallback (Claude-first, then
408
+ Codex on limit-exhaustion) stays a knob-only behavior; a direct `models.code='codex'` means codex-first.
409
+
410
+ **gpt-5.6-ready** — a new Codex id is a DATA-ONLY addition to the `KNOWN_CODEX` allowlist (no control flow).
411
+ **Reporting** — the run result includes `modelsUsed` (the resolved per-stage model) so you see who did what.
412
+
413
+ *Example:* `Workflow({ scriptPath: '.claude/workflows/feature-adr.js', args: { slug, description, tier:
414
+ 'L', models: { code: 'opus', qe: 'codex:gpt-5.6:high', architecture: 'opus', router: 'fable' } } })` —
415
+ Claude writes the code, Codex independently QEs it.
416
+
417
+ **Usage-adaptive routing (pre-emptive Codex switch under limit pressure).** When routing is opted into,
418
+ the workflow probes Claude SESSION (active 5h-block) and WEEKLY (rolling 7d) usage at EACH phase boundary
419
+ via a minimal `dz usage --json` agent. When either metric is `>= usageThreshold` (default `70`) BEFORE a
420
+ phase launches — OR the probe output is missing (agent-null, which often MEANS the limit was hit) — ALL
421
+ remaining stages switch to `codex:<top>` (design/code/plan at `xhigh`, router/qe/fleet at `high`). When a
422
+ later probe reads BOTH metrics below the threshold (positive numbers, not nulls), the normal Claude+Codex
423
+ mix is RESTORED. Null percentages (unconfigured limits) change NOTHING in either direction. Switched
424
+ stages are tagged ` (usage-switched)` in `modelsUsed`, and every flip is recorded in the result's
425
+ `usageEvents` array (the audit trail — never trust promiseTags for this). Args:
426
+
427
+ | `args.*` | Default | Effect |
428
+ |---|---|---|
429
+ | `usageAdaptive` | `true` when routing is requested (any `args.models` key or Codex knob); `false` otherwise | `true` forces it on even without other routing; `false` disables all probes (byte-identical to today) |
430
+ | `usageThreshold` | `70` | the `>=` percent (either metric) that triggers the pre-emptive switch |
431
+ | `usageReasoning` | the `OVERRIDE_REASONING` map | per-stage reasoning under the override (merge over the default: design/code/plan → `xhigh`, router/qe/fleet → `high`) |
432
+
433
+ Configure the limits the probe measures against in `.dz/config.json` — `memory.usage.sessionTokenLimit`
434
+ and `memory.usage.weeklyTokenLimit` (OPTIONAL; absent ⇒ `pct` is `null` and no switch fires). The
435
+ percentages are **ESTIMATES** from local transcript aggregation (there is no official usage API);
436
+ **calibrate** by scaling a limit by `X/100` when a real limit-hit lands at an estimated `X%`.
437
+ **Honest caveat (the wrapper lesson):** at TRUE exhaustion even the Codex dispatch dies because
438
+ `codex:codex-rescue` is a Claude wrapper subagent — so the switch MUST happen BEFORE, which is why the
439
+ 70% pre-emptive probe (not just reactive null-detection) is the real defense.
440
+
378
441
  ### Pattern memory loop (self-learning — runs in ALL modes)
379
442
 
380
443
  **Self-learning is MANDATORY on EVERY `/feature-adr` run — including plain `/feature-adr` without any
@@ -408,6 +471,15 @@ non-blocking — an error or empty result never stalls the pipeline. This layer
408
471
  **distinct from the Keysarium reward layer** installed by `--with-learning`: it uses agentic-qe MCP
409
472
  memory + the dz store, is UNCONDITIONAL for the dz half (recall/teach/fa-record run in every mode) and Direct-mode-only for the aqe-MCP half, and never touches `.keysarium/memory/`.
410
473
 
474
+ **Canonical brain store — `args.brain` (never fragment the loop).** The dz durable loop only compounds if
475
+ Step-0 recall and Step-8 teach hit the SAME store. The workflow pins both to a canonical **brain** —
476
+ `args.brain`, default = the workspace root — via `cd <brain> && dz recall/teach … --project <brain>`, so a
477
+ Step-8 teach issued from a coder that `cd`'d into a target repo still lands in the brain, not that repo's
478
+ `.dz`. Omitting `args.brain` is behaviorally inert for a workspace-CWD run (`brain === repo`). **Share** a
479
+ brain: `dz recall --all --json > patterns.json` → `dz teach --from-json patterns.json --project <brain>`
480
+ (exact-text dedup, idempotent). **Recover** a fragmented store: `cd <stray-repo> && dz recall --all --json >
481
+ /tmp/stray.json` → `dz teach --from-json /tmp/stray.json --project <brain>` to merge it back into the brain.
482
+
411
483
  **Live learning panel (`dz statusline`).** The pipeline **drives** the panel: at each pattern-memory-loop
412
484
  step above it records its live state via `dz statusline --fa-record …`, so `dz statusline` can surface
413
485
  per-run learning (which feature, which step, how many patterns recalled vs. newly stored). Each of the