[PR #7908] [MERGED] feat(mari): prof Mari improvements, built-in skills, better toolcall errors, qol #8002

Closed
opened 2026-10-24 04:09:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7908
Author: @ylli-selmani
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/mari-builtin-skills


📝 Commits (10+)

  • d2d9f01 feat(mari): built-in handbook skills, and tool errors a weak model can act on
  • ea8484d fix(mari): keep a leading sentinel and the NOT SAVED line around argument notes
  • f8c41b2 fix(mari): accepted calls skip the handbook gate, and six review findings
  • cc424ba test(mari): share the handbook setup and drop checks that pinned prose
  • d056a7c fix(mari): Dottore's review, and a 12b's list sent as JSON text
  • 5dcee21 Merge remote-tracking branch 'origin/staging' into feat/mari-builtin-skills
  • fe17cb3 test(mari): pin the dry-run sentinel where it now lives
  • d719348 feat(mari): link a character and a lorebook through app_data
  • 0270ce9 fix(mari): keep the clamp note on calls app_data does not wrap
  • ad5ab17 fix(mari): Dottore's third pass, and offer to link a made-for book

📊 Changes

67 files changed (+5253 additions, -508 deletions)

View changed files

📝 docs/home/professor-mari.md (+9 -0)
📝 docs/settings/settings-overview.md (+1 -1)
📝 packages/client/src/components/chat/HomeProfessorMariChat.tsx (+2 -2)
📝 packages/client/src/components/chat/MariSkillsMenu.tsx (+158 -104)
📝 packages/client/src/components/chat/mari/MariWindowHeader.tsx (+2 -9)
📝 packages/client/src/components/chat/mari/MariWorkTimeline.tsx (+31 -14)
📝 packages/client/src/components/chat/mari/mari-tool-presentation.ts (+11 -3)
📝 packages/client/src/components/chat/mari/use-mari-skill-memory-actions.ts (+5 -2)
📝 packages/client/src/components/layout/omnibar/OmnibarSettingsMenu.tsx (+44 -0)
📝 packages/client/src/localization/locales/en.json (+6 -0)
📝 packages/client/src/styles/mari.css (+17 -6)
➕ packages/server/src/assets/mari-skills/characters.md (+87 -0)
➕ packages/server/src/assets/mari-skills/decisions.md (+126 -0)
➕ packages/server/src/assets/mari-skills/extensions.md (+86 -0)
➕ packages/server/src/assets/mari-skills/home-widgets.md (+86 -0)
➕ packages/server/src/assets/mari-skills/lorebook.md (+118 -0)
➕ packages/server/src/assets/mari-skills/onboarding.md (+170 -0)
➕ packages/server/src/assets/mari-skills/presets.md (+84 -0)
➕ packages/server/src/assets/mari-skills/repair.md (+79 -0)
➕ packages/server/src/assets/mari-skills/themes.md (+99 -0)

...and 47 more files

📄 Description

Linked issue

Closes #7827
Closes #7907
Closes #7949
Closes #7995
Closes #7999

#7827 proposed shipping this in slices, one PR per handbook. At Ylli's direction the whole set ships in
one PR: the nine handbooks share one router block and one prompt ratchet, and split PRs would leave the
prompt in a half-migrated state between them. #7907 is the one piece of engine behaviour the onboarding
handbook needs (a card's lorebooks readable through character.get), so it lands here rather than as a
separate patch.

Why this change

Professor Mari's authoring knowledge lived in her permanent prompt: every procedure for every surface,
paid for on every turn. Measured on staging (51e6cace8), MARI_SYSTEM_PROMPT plus
workspaceCommandKnowledgePrompt() came to about 60k chars (~15k tokens) before any history, and
roughly 23k of that was procedure: lorebook authoring, onboarding, decisions, presets, themes,
extensions, Home widgets, reply repair.

That had two costs. Every guide was billed on turns that touch none of them, and a permanent guide has
to be a dense paragraph: no worked example, no error→fix table, no read-back check. The result was
visible in live runs, and it was not only about length. The tool surface was part of the problem:

  • a 12b model guessed instead of fetching (four chats, one skill.get), and called skill.get with
    the id nested under data, which the engine refused;
  • refusals named a value but not where it goes (character name is required: pass it as "name"), so
    the model retried the same shape, and character.update silently ignored a lorebooks field it
    does not own;
  • character.search missed a card whose name contains quotes, because it compared raw JSON (escaped
    \") as one substring, and a missed row turned into a hallucinated id;
  • an unclosed {{ was saved as literal text, and the model then "explained" a broken preview;
  • an update sent without apply was a dry run that reported success, so a 12b "finished" five edits
    that never saved (found in tool-call testing, see below);
  • an apply the tool could not read (0, "dry-run") wrote on every create, and a limit of "ten"
    or 5000 quietly became the default or the maximum page (#7999).

So this PR is three connected things:

  1. Shipped, read-only handbooks. Nine builtin-* skills carry the procedures. The prompt keeps one
    router line each, plus a gate that makes the first write on a covered surface start with its handbook.
  2. A tool surface the model can repair from. Every refusal names the action, what arrived and where
    the value goes. Unknown actions echo themselves and list what is valid. Not-found says what an id
    looks like and which lookup returns it. Search matches the name a person types. A macro linter
    refuses unbalanced braces and macros in fields that never resolve them. A write that did not save
    can no longer read as one that did.
  3. Quality-of-life fixes found while testing: a link-character refusal instead of a silent drop,
    the work line wraps instead of clipping, the skills panel tells the two kinds of skills apart, and
    a dry-run step is labelled "Previewed · not saved".

The goal is concrete: a 12b-class model should be able to author on any covered surface without the
prompt carrying every procedure. When it gets a call wrong, the error should be enough to fix it.

What changed

Before After
Knowledge block workspaceCommandKnowledgePrompt 29,217 chars 14,338
Shipped handbooks 0 9 (10.6–16.9k chars, indexed, never inlined)
Handbook regressions 0 8
Prompt ratchet 15,700 14,600

Shipped handbooks: packages/server/src/assets/mari-skills/ holds onboarding.md, lorebook.md,
presets.md, repair.md, extensions.md, decisions.md, characters.md, themes.md and
home-widgets.md. Each has the field and argument shapes the caller cannot guess, its traps, a worked
example, and checkable completion criteria. They are protocol-neutral (action, never a classic
say/stop envelope), so the same text works under pi's native and textual modes and under classic.

Prompt: in packages/server/src/services/professor-mari/workspace-agent.service.ts the knowledge
block is now the nine router lines plus policy (voice, read-only intent, the approval / apply /
change-card contract, delete safety, the command catalog, memory policy, the bare-create question
bound). Each router line names its skill id and that surface's one silent-failure trap. The duplicate
Personal Extensions block and the old MARI_DECISION_AUTHORING_PROMPT are gone; their facts live in
extensions.md and decisions.md now. piRuntimePrompt() interpolates the same shared block.

Protocol and fetchability fixes (2026-10-21). Four prompt defects surfaced in live 12b/31b runs,
all fixed here.

  1. The policy block told her "your voice belongs in say", a classic-only field. A model without
    reasoning turns that into a literal <say>/<suggestions> tag, which then renders raw and gets
    replayed by the continuity block. It now says "the visible reply", and pi's mapping adds an explicit
    "plain text, no tags" rule.
  2. skill.get was named without its argument shape, so a weak model passed the id inside data and
    never opened a handbook. Reads now say the id is top-level.
  3. The skills index said "before you act", which models read as "after thinking". It now says fetch in
    the first tool round, and that anything created, edited or activated on a built-in surface starts
    with its handbook.
  4. A failed structured call now carries a hint naming that surface's skill, so the repair round starts
    from the handbook instead of a second guess.

Skills mechanism: built-ins are a shipped source merged into the existing index. Their ids are
builtin-*. They are always on and read-only (no edit, delete, toggle or PUT/DELETE), they can never
be shadowed by a user file (a collision is reported as a diagnostic), and an app update replaces their
text cleanly because skills.json is never touched. The index is listed, never inlined; bodies are read
only on skill.get.

Client: the Skills panel separates shipped skills from the user's own (they are not part of the
"active / total" count), marks them read-only, and shows a "no custom skills yet" empty state for a
user who has not authored one. Search and Professor Mari settings gains Read the handbook before
the first write
(on by default, see below).

Mari DB read (#7907): character.get returns lorebooks: [{ id, name, description, attached: "linked" | "owned" }], which is the books linked to the card plus the one it owns, sorted by name, with
descriptions truncated. It is read-only and additive. onboarding.md uses it to skim a card's lore
before writing persona questions.

Tool error messages (#7949): a failed structured call now says what was wrong, what arrived and where
the value goes (character.create needs a non-empty "name" (none was sent) — pass it top-level, or inside "data"). An unknown action echoes itself, suggests the nearest valid name and lists that namespace's
actions. A lookup miss on every get says No character has the id "…". Character ids are generated, never a name or slug; find the record with character.search (or character.list) and send the "id" it returns. Before, character.get with a name printed null. It is one mari-db/tool-error.ts helper,
text-only, with no dispatch, validation or sandbox change. It is here because a small model's only repair
loop is reading the error.

Tool-call testing (runs 1–3, gemma-4 31b and 12b on pi)

Eight asks (folder move, memory, an AND lorebook entry, a lorebook link, a one-number description edit,
macros in a name, a quoted-name search, a two-step theme) were run against both models, three rounds,
each round's findings fixed before the next. Each fix below has a regression.

Round What a model did Fix
1 Resent the same preview for 164 s: the dry-run result said "proceed per your Permissions Mode", which Auto never explains The dry-run result says an update, delete or move saves only with top-level "apply": true
1 Read "run … in bash" in the link refusal as an instruction for the user It says she runs it with her bash tool
1 Saved an "only when both words" entry with both words as primary keys, or with selective and no secondaryKeys, then claimed AND A validation notice says the entry fires on any one key, and how to fix it
1 Wrote --mari-window-* or invented tokens for an app accent themes.md says which tokens repaint what, and that unknown names do nothing
2 Ended on dry runs and called them done; one 16.7k-char preview hid the "not saved" line mid-card A dry run opens and ends with a NOT SAVED line, and a preview keeps only the changed fields
2 "I've verified the records … now correctly reflects 1745" passed the word-based claim check The claim audit refuses a final reply when every write in scope was a dry run, unless it asks a question or says nothing was saved
2 Wrote lorebook entries without opening the handbook, since a success never triggered the failure hint The first write or preview on a handbook surface in a chat is refused once until its skill is read
2 Handed the user a mari command she could run herself The bash tool description and the link refusal say a lone mari command skips the sandbox
2 Sent entry keys as objects, saved as [object Object] List fields such as keys refuse object items
3 Sent character.update without apply five times; each was a successful dry run with a green "Updated" An update, delete or move with no top-level apply is refused and saves nothing. apply: false still previews; creates still write by default. The CLI's --apply is unchanged
3 A dry-run step read as a saved change in the work list It reads "Previewed … · not saved", with an amber neutral mark instead of the green check
3 The handbook gate's refusal hid the call's own error (a bogus linked_characters field) The gate dry-runs the call and appends its error; a failed mari result prints its error, not only the output
3 character.get with the name "Aldric" printed null The missing-id message above, on character.get, lorebook.get and the CLI lorebooks get / chats get

The handbook-first setting. The gate from round 2 costs a strong model one round it would have spent
reading the skill anyway. It is now a setting, Read the handbook before the first write, on by
default so a small or local model gets it without the user knowing it exists. It is read fresh per call
from app_settings (mari-skill-gate; only "false" turns it off) and is behind the mari-db floor, so
Mari cannot switch it off herself.

One run-3 failure is not rule-fixable: a 12b read the lorebook handbook, then saved both words as primary
keys anyway. The entry is valid, so no notice fires. #8035 proposes an optional checker that asks a
second model whether a write fulfilled the request.

Unreadable arguments (#7999)

An argument the tool could not read used to be replaced without a word. Now:

  • app_data refuses an apply that is not a boolean or one of the strings it already reads
    (true/false/yes/no/1/0/on/off/enabled/disabled), before any action runs: "apply" must be true or false (got 0), so nothing was saved. Before, that value wrote on all 14 create sites and previewed on
    every update. Leaving apply out keeps its documented meaning.
  • limit and offset that are not numbers are refused, naming the key. One that had to be moved into
    range is still answered, with a note before the result: "limit" 5000 is above this read's maximum, so 1000 was used: this may not be everything. The same rule covers the workspace tools (read, ls,
    find, grep, docs_*, bash timeout) through numberArg.
  • The notes are collected per tool call (collectArgumentNotes in mari-db/tool-error.ts, an
    AsyncLocalStorage) and printed first, so output compaction cannot cut them off.

Pinned by mari/unreadable-arguments.regression.ts.

Macro linter (#7995)

Models writing card text or lorebook entries drop braces, and an unclosed {{ used to reach the
prompt as literal text. The model then explains the broken preview instead of fixing it. The linter
is deliberately narrow: it refuses only text whose braces cannot balance at all (an unclosed {{, or
a stray }}), because {{ always opens a macro in Marinara; unknown macro names and literal pairs
still pass. It is wired into character.create|update, character.onboarding.update and the three
lorebook entry writes. The refusal names the field and the character offset, and says what to do. It is
a refusal, not a warning, because a broken brace in a saved card is already wrong. Slice 2 covers the
other half of the issue: a macro in a field that never interpolates (name, tags, entry keys) is
refused too, because it would be stored and shown literally forever.

Where the 4.6k lines go

The diff reads as 65 files, +4,641/−487. The testing rounds, #7999 and their regressions added about
1,100 lines; a later trim of the regressions took about 220 back. Most of it is text a
reviewer can skim:

Group Files + − What it is
Nine handbooks (packages/server/src/assets/mari-skills/*.md) 9 931 0 New files only. Procedures, worked examples and exact error text for characters, lorebooks, presets, themes, extensions, decisions, home widgets, reply repair, onboarding.
Regressions (scripts/regressions/) 30 2,044 90 16 new harnesses (handbooks, the macro linter, #7907, the testing-round fixes in app-data-envelope-errors, #7999 in unreadable-arguments), the shared mari/_handbook.ts setup, plus prompt and ratchet assertions. None of it ships.
mari-db/ 4 750 105 tool-error.ts, macro-lint.ts, the precise refusals (unknown actions, missing fields, not-found, quote-safe search), the macro gate, the selective-keys notice, the setting's floor rule, and the #7999 argument checks and notes, and table-keyed not-found lookups.
professor-mari/ services and route 9 654 162 Skill loading and index, router lines, the two protocol prompts, the gate and its setting, the dry-run sentinel and claim audit, the omitted-apply refusal, numberArg and the per-call notes, the GET/PUT /skill-gate route, and accepted held calls skipping the gate. Most of the −158 is the constants the handbooks replaced.
Client 9 239 129 Read-only Skills panel rows, empty states, the built-in group, work-line wrapping, the settings row and the amber "Previewed · not saved" step.
Shared 2 13 0 The setting's key, the dry-run prefix the work list reads, and one type field.
Docs 2 10 1 docs/home/professor-mari.md and docs/settings/settings-overview.md.
Total 65 4,641 487 30 of the 65 are new files: 9 handbooks, 16 regressions and their shared setup, 4 server modules.

Shipped product code is about 1,660 additions across 24 files. The rest is procedures, proof and docs.

Deferred, not in this PR

  • #8035: the optional "was the request fulfilled" checker for valid-but-wrong writes (run 3, T3).
  • A link app_data action. Attaching a lorebook to a card still goes through the CLI
    (mari lorebooks link-character). A structured action is a follow-up PR.
  • Two extension defects found while writing extensions.md: source is not adopted on update, and
    full_page_access is stored where the mapper strips it. They need their own change and tests.
  • App polish observed while testing: a stale "That attempt failed" banner under a later successful
    change card; the timeline labels decision.record as "Read"; an applied widget receipt reads "New app
    setting" / "Changed value".
  • scripts/dev.mjs never loads .env, so pnpm dev on a non-default port health-checks the daily
    install. Separate launcher branch.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Run by the agent on cc424ba52 (the boxes above are Ylli's to tick). The branch's 48 working commits are
squashed into d2d9f01ed, with the same tree as before; ea8484d82 holds the CodeRabbit fixes, f8c41b20e
the independent-review fixes and cc424ba52 the regression trim.

  • pnpm check: exit 0 (TypeScript in all four projects, ESLint, localization, format, client build).
  • Regressions for the touched areas: --filter mari 74/74, professor-mari 22/22, skill 4/4,
    workspace 3/3, lorebook 25/26. The one lorebook failure is lorebook-images ("symlinks do not expose
    other files"), which this branch does not touch and which needs symlink rights on Windows. The full suite
    (about half an hour locally) is left to the GitHub complete-node-regressions job.
  • Two local CodeRabbit passes (coderabbit review --committed --base origin/staging --agent --fresh). The last,
    on d2d9f01ed, found 9; six are fixed in ea8484d82: argument notes no longer push a leading sentinel off
    line 1, the closing NOT SAVED line survives truncation, the lorebook handbook's lorebook.get miss is
    corrected, and three regressions are tightened. Three declined, with reasons in the commit message: letting a
    stray }} through (#7995 refuses it on purpose) and two wording changes to text Ylli reviewed by hand.
  • Four independent agent reviews, two of the regressions and two of the source. Fixed in f8c41b20e, each with a
    regression: Accept replayed held calls through the handbook gate (half-applied changes); an argument note pushed
    bash's Command: header off line 1; the gate matched the raw action spelling (lorebooks.create,
    home-widget.create); macro lint refused nested CSS in Creator Notes; character.update refused the unchanged
    lorebooks list and link-character inserted duplicate links; two not-found errors named actions that do not
    exist. cc424ba52 moves the handbook setup into mari/_handbook.ts and drops checks that only pinned prose
    (about 330 test lines), keeping every example run, quoted error and behaviour claim.

Tool-call testing so far (raw results kept privately): round 1 on 31b and 12b, rounds 2 and 3 on 12b
for the asks that failed. The 12b re-test after round 3: T5 passed, recovering from the handbook gate and
the missing-apply refusal and then reading the card back. T3 still writes AND-logic entries as a plain
trigger, which looks like the limit of a 12b model. T4 refused the CLI link command the refusal handed it, which
is the case for the app_data link action listed under Deferred.

Still to do by Ylli, in the app:

  • Skills panel: with no custom skills, the "no custom skills yet" note appears above the shipped group;
    shipped rows cannot be edited, toggled or deleted.
  • Settings: Read the handbook before the first write is on by default; turned off, a fresh chat's
    first lorebook write is not refused.
  • A dry run (ask for a preview of a card edit) shows "Previewed … · not saved" in the work list.
  • Ask "write onboarding for Edric": expect a skill.get chip for builtin-onboarding, the card
    patched in the same pass, and {{bond}} resolving.
  • Ask "make me a grumpy lighthouse keeper": one full create, then 2–4 follow-up chips.
  • Ask "make me a dusk theme with warm accents": created and activated, with a read-back.
  • A Home-widget create: held behind the Accept action, applied only after accepting.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

docs/home/professor-mari.md gains a Built-in skills subsection (what the shipped skills are, that
they are read-only, the new setting) and a line on the "Previewed · not saved" step.
docs/settings/settings-overview.md lists the setting. The translated pages on docs-i18n need the
same additions; that is tracked in #8058. The handbooks themselves are agent procedure, not user documentation, so they are not
translated.

UI evidence (if applicable)

Screenshots of the live runs (skills panel, a fetched handbook, the onboarding/character/theme/widget
flows, the testing rounds) are kept privately and will be attached before this is marked ready.

Pinned, not in this PR

  • Reported from a live 12b run and fixed on this branch: character.search refused a query
    nested under data even though the refusal promised "top-level, or inside data"; reads now
    fall back to data. The live step line clipped long labels ("Checking Characters and
    personas ag…"); it wraps to a second line now.
  • Model-side, not reproducible as a defect: a theme create read its skill and then exhausted
    its output tokens mid-write; a character create lost its final message to a thought loop. The
    reads and tool calls succeeded in both; the failure is model budget/looping, not the prompt.
  • Composer @ / / is #7913 (its own change): letting a user hand Mari a character directly.
    Once it lands, the app_data data description should be reworded to match.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7908 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/mari-builtin-skills` --- ### 📝 Commits (10+) - [`d2d9f01`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d2d9f01ede60b20d3fc143401c33f80ad8ad0b2e) feat(mari): built-in handbook skills, and tool errors a weak model can act on - [`ea8484d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ea8484d820ab801eb3f6d23cc15160c331633b8e) fix(mari): keep a leading sentinel and the NOT SAVED line around argument notes - [`f8c41b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f8c41b20ee9986a8a09d70a1e426f984e052dcd7) fix(mari): accepted calls skip the handbook gate, and six review findings - [`cc424ba`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cc424ba52c00bc38414f29a0b87bf1914a9b7df3) test(mari): share the handbook setup and drop checks that pinned prose - [`d056a7c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d056a7c2bdd969cbc93ffbc3a287981ea68450c6) fix(mari): Dottore's review, and a 12b's list sent as JSON text - [`5dcee21`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5dcee21bfb4c2cee70d5bd2a41b45a0257007351) Merge remote-tracking branch 'origin/staging' into feat/mari-builtin-skills - [`fe17cb3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe17cb3e64d507be87067e1410edff0a171f7a76) test(mari): pin the dry-run sentinel where it now lives - [`d719348`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d71934895b14107f61a26bc49437ab88a15e7225) feat(mari): link a character and a lorebook through app_data - [`0270ce9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0270ce980c8c1bc81bb04db2f5d16d9f732b6eed) fix(mari): keep the clamp note on calls app_data does not wrap - [`ad5ab17`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ad5ab171fc6b0ab6f372425d65734d6c780c18d3) fix(mari): Dottore's third pass, and offer to link a made-for book ### 📊 Changes **67 files changed** (+5253 additions, -508 deletions) <details> <summary>View changed files</summary> 📝 `docs/home/professor-mari.md` (+9 -0) 📝 `docs/settings/settings-overview.md` (+1 -1) 📝 `packages/client/src/components/chat/HomeProfessorMariChat.tsx` (+2 -2) 📝 `packages/client/src/components/chat/MariSkillsMenu.tsx` (+158 -104) 📝 `packages/client/src/components/chat/mari/MariWindowHeader.tsx` (+2 -9) 📝 `packages/client/src/components/chat/mari/MariWorkTimeline.tsx` (+31 -14) 📝 `packages/client/src/components/chat/mari/mari-tool-presentation.ts` (+11 -3) 📝 `packages/client/src/components/chat/mari/use-mari-skill-memory-actions.ts` (+5 -2) 📝 `packages/client/src/components/layout/omnibar/OmnibarSettingsMenu.tsx` (+44 -0) 📝 `packages/client/src/localization/locales/en.json` (+6 -0) 📝 `packages/client/src/styles/mari.css` (+17 -6) ➕ `packages/server/src/assets/mari-skills/characters.md` (+87 -0) ➕ `packages/server/src/assets/mari-skills/decisions.md` (+126 -0) ➕ `packages/server/src/assets/mari-skills/extensions.md` (+86 -0) ➕ `packages/server/src/assets/mari-skills/home-widgets.md` (+86 -0) ➕ `packages/server/src/assets/mari-skills/lorebook.md` (+118 -0) ➕ `packages/server/src/assets/mari-skills/onboarding.md` (+170 -0) ➕ `packages/server/src/assets/mari-skills/presets.md` (+84 -0) ➕ `packages/server/src/assets/mari-skills/repair.md` (+79 -0) ➕ `packages/server/src/assets/mari-skills/themes.md` (+99 -0) _...and 47 more files_ </details> ### 📄 Description ## Linked issue Closes #7827 Closes #7907 Closes #7949 Closes #7995 Closes #7999 #7827 proposed shipping this in slices, one PR per handbook. At Ylli's direction the whole set ships in one PR: the nine handbooks share one router block and one prompt ratchet, and split PRs would leave the prompt in a half-migrated state between them. #7907 is the one piece of engine behaviour the onboarding handbook needs (a card's lorebooks readable through `character.get`), so it lands here rather than as a separate patch. ## Why this change Professor Mari's authoring knowledge lived in her permanent prompt: every procedure for every surface, paid for on every turn. Measured on `staging` (`51e6cace8`), `MARI_SYSTEM_PROMPT` plus `workspaceCommandKnowledgePrompt()` came to about **60k chars (~15k tokens)** before any history, and roughly 23k of that was procedure: lorebook authoring, onboarding, decisions, presets, themes, extensions, Home widgets, reply repair. That had two costs. Every guide was billed on turns that touch none of them, and a permanent guide has to be a dense paragraph: no worked example, no error→fix table, no read-back check. The result was visible in live runs, and it was not only about length. The *tool surface* was part of the problem: - a 12b model guessed instead of fetching (four chats, one `skill.get`), and called `skill.get` with the id nested under `data`, which the engine refused; - refusals named a value but not where it goes (`character name is required: pass it as "name"`), so the model retried the same shape, and `character.update` silently *ignored* a `lorebooks` field it does not own; - `character.search` missed a card whose name contains quotes, because it compared raw JSON (escaped `\"`) as one substring, and a missed row turned into a hallucinated id; - an unclosed `{{` was saved as literal text, and the model then "explained" a broken preview; - an update sent without `apply` was a dry run that reported success, so a 12b "finished" five edits that never saved (found in tool-call testing, see below); - an `apply` the tool could not read (`0`, `"dry-run"`) wrote on every create, and a `limit` of `"ten"` or `5000` quietly became the default or the maximum page (#7999). So this PR is three connected things: 1. **Shipped, read-only handbooks.** Nine `builtin-*` skills carry the procedures. The prompt keeps one router line each, plus a gate that makes the first write on a covered surface start with its handbook. 2. **A tool surface the model can repair from.** Every refusal names the action, what arrived and where the value goes. Unknown actions echo themselves and list what is valid. Not-found says what an id looks like and which lookup returns it. Search matches the name a person types. A macro linter refuses unbalanced braces and macros in fields that never resolve them. A write that did not save can no longer read as one that did. 3. **Quality-of-life fixes found while testing**: a link-character refusal instead of a silent drop, the work line wraps instead of clipping, the skills panel tells the two kinds of skills apart, and a dry-run step is labelled "Previewed · not saved". The goal is concrete: a 12b-class model should be able to author on any covered surface without the prompt carrying every procedure. When it gets a call wrong, the error should be enough to fix it. ## What changed | | Before | After | | --- | --- | --- | | Knowledge block `workspaceCommandKnowledgePrompt` | 29,217 chars | **14,338** | | Shipped handbooks | 0 | **9** (10.6–16.9k chars, indexed, never inlined) | | Handbook regressions | 0 | **8** | | Prompt ratchet | 15,700 | **14,600** | **Shipped handbooks**: `packages/server/src/assets/mari-skills/` holds `onboarding.md`, `lorebook.md`, `presets.md`, `repair.md`, `extensions.md`, `decisions.md`, `characters.md`, `themes.md` and `home-widgets.md`. Each has the field and argument shapes the caller cannot guess, its traps, a worked example, and checkable completion criteria. They are protocol-neutral (`action`, never a classic `say`/`stop` envelope), so the same text works under pi's native and textual modes and under classic. **Prompt**: in `packages/server/src/services/professor-mari/workspace-agent.service.ts` the knowledge block is now the nine router lines plus policy (voice, read-only intent, the approval / `apply` / change-card contract, delete safety, the command catalog, memory policy, the bare-create question bound). Each router line names its skill id and that surface's one silent-failure trap. The duplicate Personal Extensions block and the old `MARI_DECISION_AUTHORING_PROMPT` are gone; their facts live in `extensions.md` and `decisions.md` now. `piRuntimePrompt()` interpolates the same shared block. **Protocol and fetchability fixes (2026-10-21).** Four prompt defects surfaced in live 12b/31b runs, all fixed here. 1. The policy block told her *"your voice belongs in `say`"*, a classic-only field. A model without reasoning turns that into a literal `<say>`/`<suggestions>` tag, which then renders raw and gets replayed by the continuity block. It now says "the visible reply", and pi's mapping adds an explicit "plain text, no tags" rule. 2. `skill.get` was named without its argument shape, so a weak model passed the id inside `data` and never opened a handbook. Reads now say the id is top-level. 3. The skills index said "before you act", which models read as "after thinking". It now says fetch in the first tool round, and that anything created, edited or activated on a built-in surface starts with its handbook. 4. A failed structured call now carries a hint naming that surface's skill, so the repair round starts from the handbook instead of a second guess. **Skills mechanism**: built-ins are a shipped source merged into the existing index. Their ids are `builtin-*`. They are always on and read-only (no edit, delete, toggle or `PUT`/`DELETE`), they can never be shadowed by a user file (a collision is reported as a diagnostic), and an app update replaces their text cleanly because `skills.json` is never touched. The index is listed, never inlined; bodies are read only on `skill.get`. **Client**: the Skills panel separates shipped skills from the user's own (they are not part of the "active / total" count), marks them read-only, and shows a "no custom skills yet" empty state for a user who has not authored one. **Search and Professor Mari settings** gains **Read the handbook before the first write** (on by default, see below). **Mari DB read (#7907)**: `character.get` returns `lorebooks: [{ id, name, description, attached: "linked" | "owned" }]`, which is the books linked to the card plus the one it owns, sorted by name, with descriptions truncated. It is read-only and additive. `onboarding.md` uses it to skim a card's lore before writing persona questions. **Tool error messages (#7949)**: a failed structured call now says what was wrong, what arrived and where the value goes (`character.create needs a non-empty "name" (none was sent) — pass it top-level, or inside "data"`). An unknown action echoes itself, suggests the nearest valid name and lists that namespace's actions. A lookup miss on every `get` says `No character has the id "…". Character ids are generated, never a name or slug; find the record with character.search (or character.list) and send the "id" it returns.` Before, `character.get` with a name printed `null`. It is one `mari-db/tool-error.ts` helper, text-only, with no dispatch, validation or sandbox change. It is here because a small model's only repair loop is reading the error. ### Tool-call testing (runs 1–3, gemma-4 31b and 12b on pi) Eight asks (folder move, memory, an AND lorebook entry, a lorebook link, a one-number description edit, macros in a name, a quoted-name search, a two-step theme) were run against both models, three rounds, each round's findings fixed before the next. Each fix below has a regression. | Round | What a model did | Fix | | --- | --- | --- | | 1 | Resent the same preview for 164 s: the dry-run result said "proceed per your Permissions Mode", which Auto never explains | The dry-run result says an update, delete or move saves only with top-level `"apply": true` | | 1 | Read "run … in bash" in the link refusal as an instruction for the user | It says she runs it with her bash tool | | 1 | Saved an "only when both words" entry with both words as primary keys, or with `selective` and no `secondaryKeys`, then claimed AND | A validation notice says the entry fires on any one key, and how to fix it | | 1 | Wrote `--mari-window-*` or invented tokens for an app accent | `themes.md` says which tokens repaint what, and that unknown names do nothing | | 2 | Ended on dry runs and called them done; one 16.7k-char preview hid the "not saved" line mid-card | A dry run opens and ends with a `NOT SAVED` line, and a preview keeps only the changed fields | | 2 | "I've verified the records … now correctly reflects 1745" passed the word-based claim check | The claim audit refuses a final reply when every write in scope was a dry run, unless it asks a question or says nothing was saved | | 2 | Wrote lorebook entries without opening the handbook, since a success never triggered the failure hint | The first write or preview on a handbook surface in a chat is refused once until its skill is read | | 2 | Handed the user a `mari` command she could run herself | The bash tool description and the link refusal say a lone `mari` command skips the sandbox | | 2 | Sent entry keys as objects, saved as `[object Object]` | List fields such as `keys` refuse object items | | 3 | Sent `character.update` without `apply` five times; each was a successful dry run with a green "Updated" | An update, delete or move with no top-level `apply` is refused and saves nothing. `apply: false` still previews; creates still write by default. The CLI's `--apply` is unchanged | | 3 | A dry-run step read as a saved change in the work list | It reads "Previewed … · not saved", with an amber neutral mark instead of the green check | | 3 | The handbook gate's refusal hid the call's own error (a bogus `linked_characters` field) | The gate dry-runs the call and appends its error; a failed `mari` result prints its error, not only the output | | 3 | `character.get` with the name "Aldric" printed `null` | The missing-id message above, on `character.get`, `lorebook.get` and the CLI `lorebooks get` / `chats get` | **The handbook-first setting.** The gate from round 2 costs a strong model one round it would have spent reading the skill anyway. It is now a setting, **Read the handbook before the first write**, on by default so a small or local model gets it without the user knowing it exists. It is read fresh per call from `app_settings` (`mari-skill-gate`; only `"false"` turns it off) and is behind the mari-db floor, so Mari cannot switch it off herself. One run-3 failure is not rule-fixable: a 12b read the lorebook handbook, then saved both words as primary keys anyway. The entry is valid, so no notice fires. #8035 proposes an optional checker that asks a second model whether a write fulfilled the request. ### Unreadable arguments (#7999) An argument the tool could not read used to be replaced without a word. Now: - `app_data` refuses an `apply` that is not a boolean or one of the strings it already reads (`true/false/yes/no/1/0/on/off/enabled/disabled`), before any action runs: `"apply" must be true or false (got 0), so nothing was saved.` Before, that value wrote on all 14 create sites and previewed on every update. Leaving `apply` out keeps its documented meaning. - `limit` and `offset` that are not numbers are refused, naming the key. One that had to be moved into range is still answered, with a note before the result: `"limit" 5000 is above this read's maximum, so 1000 was used: this may not be everything.` The same rule covers the workspace tools (`read`, `ls`, `find`, `grep`, `docs_*`, `bash` timeout) through `numberArg`. - The notes are collected per tool call (`collectArgumentNotes` in `mari-db/tool-error.ts`, an `AsyncLocalStorage`) and printed first, so output compaction cannot cut them off. Pinned by `mari/unreadable-arguments.regression.ts`. ### Macro linter (#7995) Models writing card text or lorebook entries drop braces, and an unclosed `{{` used to reach the prompt as literal text. The model then explains the broken preview instead of fixing it. The linter is deliberately narrow: it refuses only text whose braces cannot balance at all (an unclosed `{{`, or a stray `}}`), because `{{` always opens a macro in Marinara; unknown macro names and literal pairs still pass. It is wired into `character.create|update`, `character.onboarding.update` and the three lorebook entry writes. The refusal names the field and the character offset, and says what to do. It is a refusal, not a warning, because a broken brace in a saved card is already wrong. Slice 2 covers the other half of the issue: a macro in a field that never interpolates (`name`, `tags`, entry `keys`) is refused too, because it would be stored and shown literally forever. ### Where the 4.6k lines go The diff reads as 65 files, +4,641/−487. The testing rounds, #7999 and their regressions added about 1,100 lines; a later trim of the regressions took about 220 back. Most of it is text a reviewer can skim: | Group | Files | + | − | What it is | |---|---|---|---|---| | Nine handbooks (`packages/server/src/assets/mari-skills/*.md`) | 9 | 931 | 0 | New files only. Procedures, worked examples and exact error text for characters, lorebooks, presets, themes, extensions, decisions, home widgets, reply repair, onboarding. | | Regressions (`scripts/regressions/`) | 30 | 2,044 | 90 | 16 new harnesses (handbooks, the macro linter, #7907, the testing-round fixes in `app-data-envelope-errors`, #7999 in `unreadable-arguments`), the shared `mari/_handbook.ts` setup, plus prompt and ratchet assertions. None of it ships. | | `mari-db/` | 4 | 750 | 105 | `tool-error.ts`, `macro-lint.ts`, the precise refusals (unknown actions, missing fields, not-found, quote-safe search), the macro gate, the selective-keys notice, the setting's floor rule, and the #7999 argument checks and notes, and table-keyed not-found lookups. | | `professor-mari/` services and route | 9 | 654 | 162 | Skill loading and index, router lines, the two protocol prompts, the gate and its setting, the dry-run sentinel and claim audit, the omitted-`apply` refusal, `numberArg` and the per-call notes, the `GET`/`PUT /skill-gate` route, and accepted held calls skipping the gate. Most of the −158 is the constants the handbooks replaced. | | Client | 9 | 239 | 129 | Read-only Skills panel rows, empty states, the built-in group, work-line wrapping, the settings row and the amber "Previewed · not saved" step. | | Shared | 2 | 13 | 0 | The setting's key, the dry-run prefix the work list reads, and one type field. | | Docs | 2 | 10 | 1 | `docs/home/professor-mari.md` and `docs/settings/settings-overview.md`. | | **Total** | **65** | **4,641** | **487** | 30 of the 65 are new files: 9 handbooks, 16 regressions and their shared setup, 4 server modules. | Shipped product code is about 1,660 additions across 24 files. The rest is procedures, proof and docs. ### Deferred, not in this PR - **#8035**: the optional "was the request fulfilled" checker for valid-but-wrong writes (run 3, T3). - **A `link` app_data action.** Attaching a lorebook to a card still goes through the CLI (`mari lorebooks link-character`). A structured action is a follow-up PR. - Two extension defects found while writing `extensions.md`: `source` is not adopted on `update`, and `full_page_access` is stored where the mapper strips it. They need their own change and tests. - App polish observed while testing: a stale "That attempt failed" banner under a later successful change card; the timeline labels `decision.record` as "Read"; an applied widget receipt reads "New app setting" / "Changed value". - `scripts/dev.mjs` never loads `.env`, so `pnpm dev` on a non-default port health-checks the daily install. Separate launcher branch. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Run by the agent on `cc424ba52` (the boxes above are Ylli's to tick). The branch's 48 working commits are squashed into `d2d9f01ed`, with the same tree as before; `ea8484d82` holds the CodeRabbit fixes, `f8c41b20e` the independent-review fixes and `cc424ba52` the regression trim. - `pnpm check`: exit 0 (TypeScript in all four projects, ESLint, localization, format, client build). - Regressions for the touched areas: `--filter mari` 74/74, `professor-mari` 22/22, `skill` 4/4, `workspace` 3/3, `lorebook` 25/26. The one `lorebook` failure is `lorebook-images` ("symlinks do not expose other files"), which this branch does not touch and which needs symlink rights on Windows. The full suite (about half an hour locally) is left to the GitHub `complete-node-regressions` job. - Two local CodeRabbit passes (`coderabbit review --committed --base origin/staging --agent --fresh`). The last, on `d2d9f01ed`, found 9; six are fixed in `ea8484d82`: argument notes no longer push a leading sentinel off line 1, the closing NOT SAVED line survives truncation, the lorebook handbook's `lorebook.get` miss is corrected, and three regressions are tightened. Three declined, with reasons in the commit message: letting a stray `}}` through (#7995 refuses it on purpose) and two wording changes to text Ylli reviewed by hand. - Four independent agent reviews, two of the regressions and two of the source. Fixed in `f8c41b20e`, each with a regression: Accept replayed held calls through the handbook gate (half-applied changes); an argument note pushed bash's `Command: ` header off line 1; the gate matched the raw action spelling (`lorebooks.create`, `home-widget.create`); macro lint refused nested CSS in Creator Notes; `character.update` refused the unchanged `lorebooks` list and `link-character` inserted duplicate links; two not-found errors named actions that do not exist. `cc424ba52` moves the handbook setup into `mari/_handbook.ts` and drops checks that only pinned prose (about 330 test lines), keeping every example run, quoted error and behaviour claim. Tool-call testing so far (raw results kept privately): round 1 on 31b and 12b, rounds 2 and 3 on 12b for the asks that failed. The 12b re-test after round 3: T5 passed, recovering from the handbook gate and the missing-`apply` refusal and then reading the card back. T3 still writes AND-logic entries as a plain trigger, which looks like the limit of a 12b model. T4 refused the CLI link command the refusal handed it, which is the case for the `app_data` link action listed under Deferred. Still to do by Ylli, in the app: - Skills panel: with no custom skills, the "no custom skills yet" note appears above the shipped group; shipped rows cannot be edited, toggled or deleted. - Settings: **Read the handbook before the first write** is on by default; turned off, a fresh chat's first lorebook write is not refused. - A dry run (ask for a preview of a card edit) shows "Previewed … · not saved" in the work list. - Ask "write onboarding for Edric": expect a `skill.get` chip for `builtin-onboarding`, the card patched in the same pass, and `{{bond}}` resolving. - Ask "make me a grumpy lighthouse keeper": one full create, then 2–4 follow-up chips. - Ask "make me a dusk theme with warm accents": created and activated, with a read-back. - A Home-widget create: held behind the Accept action, applied only after accepting. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `docs/home/professor-mari.md` gains a **Built-in skills** subsection (what the shipped skills are, that they are read-only, the new setting) and a line on the "Previewed · not saved" step. `docs/settings/settings-overview.md` lists the setting. The translated pages on `docs-i18n` need the same additions; that is tracked in #8058. The handbooks themselves are agent procedure, not user documentation, so they are not translated. ## UI evidence (if applicable) Screenshots of the live runs (skills panel, a fetched handbook, the onboarding/character/theme/widget flows, the testing rounds) are kept privately and will be attached before this is marked ready. ## Pinned, not in this PR - **Reported from a live 12b run and fixed on this branch:** `character.search` refused a query nested under `data` even though the refusal promised "top-level, or inside data"; reads now fall back to `data`. The live step line clipped long labels ("Checking Characters and personas ag…"); it wraps to a second line now. - **Model-side, not reproducible as a defect:** a theme create read its skill and then exhausted its output tokens mid-write; a character create lost its final message to a thought loop. The reads and tool calls succeeded in both; the failure is model budget/looping, not the prompt. - **Composer `@` / `/`** is #7913 (its own change): letting a user hand Mari a character directly. Once it lands, the `app_data` `data` description should be reworded to match. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:34 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8002
No description provided.