Skip to content

feat(skill-memory): per-skill cross-session recall + historian auto-extraction - #181

Closed
iceteaSA wants to merge 27 commits into
cortexkit:masterfrom
iceteaSA:skill-memory-pr
Closed

feat(skill-memory): per-skill cross-session recall + historian auto-extraction#181
iceteaSA wants to merge 27 commits into
cortexkit:masterfrom
iceteaSA:skill-memory-pr

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds skill-memory — per-skill "motor memory" that gives a skill cross-session recall of its own hard-won lessons (gotchas, discoveries, fixes, workflow steps). When a skill's SKILL.md declares skill-memory: { enabled: true }, accumulated notes for that skill surface automatically in a <skill-memory> block appended to the skill tool's result on every load — and, with the historian extension, the historian writes those notes automatically during compaction (no agent action required).

It's fully opt-in per skill and cache-safe by construction: the block rides the tool-result tail (conversation), never the cached system/m[0] prefix, so it can't bust the prompt cache.

How it works

  • Transparent recall — three-hook augmentation: tool.definition advertises an intent param; tool.execute.before stashes the intent (bounded TTL); the after-hook parses the skill's Base directory, reads its SKILL.md frontmatter, and formats the recall block. Lands in the tool RESULT (cache-safe).
  • Write pathsctx_skill_note (agent-authored) and the historian (auto-extracted). Both dedup on a normalized hash.
  • Intent-scoped ranking — a recall cascade: model-matched embeddings → cosine blend over intent_embedding + delta_embedding (relevance/recency/hit weights tunable per skill via ranking_* frontmatter); FTS5 fallback over a content-linked skill_memory_fts vtable; flat recency×hit fallback.
  • Historian auto-extraction — the historian sees TC: skill(<name>) markers in its chunk and emits a <skill_observations> block; both the OpenCode and Pi runners promote those post-commit as global notes (project_identity='*', source_type='historian'), recallable from any project.

Review units (4 commits)

The branch is organized into four coherent, reviewable phases:

  1. P1 — transparent per-skill recall: skill_memory table migration, the three-hook augmentation, flat recall + storage, ctx_skill_note/ctx_skill_recall tools, opt-in distill-skill-memory dreamer task, TUI/ctx-status stats, docs.
  2. P2 — embeddings + intent-scoped recall: delta_embedding + recall_count columns + skill_memory_fts FTS5 vtable; embed-on-write; the cosine/FTS recall cascade; a programmatic (no-LLM) reembed pre-step.
  3. P3a — historian-extraction foundation: the TC: skill(<name>) marker keystone; origin_project + source_type columns; global-tier notes unified under project_identity='*' (collision-merge); partitionKey routing.
  4. P3b — historian auto-extraction pipeline: prompt emits <skill_observations>, parser, validated-result threading, both runners promote via the shared promoteSkillObservations helper, plus an initializeDatabase self-heal net (re-creates skill_memory + ensureColumn so an upgraded DB recovers even if a migration row is lost).

Schema / migrations

Three migrations (numbered after the current master ceiling): skill_memory table, then delta_embedding/recall_count/FTS, then origin_project/source_type/* unification. LATEST_SUPPORTED_VERSION bumped in lockstep (the schema-version-fence test enforces it). Migration bodies are ensureColumn/IF NOT EXISTS idempotent.

Testing

Full plugin + Pi suites pass (one unrelated pre-existing full-suite ordering flake in tui-config.test.ts that passes in isolation), tsc clean both packages, lint clean, build produces all bundles. Dedicated coverage for the migrations (coexistence + fence), recall rungs, the tools, FTS triggers/backfill, the '*' collision-merge, and the historian promotion path on both runners. Verified working live: the historian auto-extraction writes genuine source_type='historian' notes, embeddings populate, and the read-side recall_count increments on surfacing.

Notes for reviewers

  • Migration version numbers are placeholders relative to this fork's base — happy to renumber to whatever slots are free at merge time.
  • The four commits are independently meaningful; if you'd prefer this as stacked PRs (P1 / P2 / historian), I can split it.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Adds per-skill cross-session recall and historian auto-extraction. Previously skills had no recall; now opted-in skills append a cache-safe <skill-memory> block on each load, and the historian writes global notes so skills remember gotchas, discoveries, fixes, and workflows without busting the prompt cache.

  • Transparent recall: the skill tool exposes an optional intent; hooks stash it and append a rendered recall block. Ranking cascades from cosine over on-the-fly intent + stored delta_embedding, to FTS5, then recency×hit. Reads union the skill’s project partition with the global '*' tier; reads increment recall_count. Token budgeting counts per-note framing; pinned budget clamps to min(max_pinned_tokens, max_tokens).
  • Write/recall tools: ctx_skill_note dedups by hash and cosine, embeds on write, and rejects writes when a skill hasn’t enabled memory. ctx_skill_recall renders notes on demand. Both are OpenCode-only; Pi does not register them.
  • Historian auto-extraction: the historian emits <skill_observations>; both OpenCode and Pi promote them as global '*' notes (source_type='historian') via a shared helper, gated to avoid double-emits.
  • Provenance and safety: accepts plain paths and file://; Windows path normalization; name-based fallback when the trailing provenance line is truncated. Intent stash is keyed by sessionId:callId with TTL and per-session pruning. The skill tool’s model schema advertises the intent param via jsonSchema. ctx_skill_note now fails early when a skill hasn’t opted in.
  • UX and surface: async executeStatus and the TUI show per-project skill-memory totals. The system prompt adds skill-memory guidance. The A1 golden and prompt-surface budget fixture were re-measured to include ctx_skill_note and ctx_skill_recall under the existing policy.
  • Dreamer: adds opt-in distill-skill-memory; a pre-step re-embeds NULL/stale vectors, then emits a read-only corpus health report.

Rollout

  • Fork-lane migrations v10000–v10002 add skill_memory, embeddings + FTS, and historian provenance/global '*' unification. initializeDatabase self-heals (creates table/columns, rebuilds FTS) and runForkMigrations runs on DB open.
  • Required action: enable per skill by adding skill-memory: { enabled: true } to SKILL.md. Optional: schedule the distill-skill-memory dreamer task.

Written for commit 5c5fb3b. Summary will update on new commits.

Review in cubic

Greptile Summary

This PR introduces skill-memory — per-skill cross-session recall that appends a <skill-memory> block to a skill's tool result when its SKILL.md declares skill-memory: { enabled: true }. The historian auto-extraction pipeline writes global notes under project_identity='*' so lessons accumulate across projects without busting the prompt cache.

  • Three fork-lane migrations (v10000–v10002) add skill_memory, embeddings+FTS, and historian provenance columns; initializeDatabase self-heals on a DB where migrations ran partially.
  • A four-rung recall cascade (cosine over intent+delta embeddings → FTS5 → flat recency×hit) is wired into tool.execute.before/after hooks; two new tools (ctx_skill_note, ctx_skill_recall) expose the write and explicit-read paths to the agent.
  • Both the OpenCode compartment runner and the Pi historian runner promote <skill_observations> blocks as global '*' notes; the recallPartitionPredicate union ensures project-local skills still surface those global historian rows on recall.

Confidence Score: 5/5

  • This PR is safe to merge. The core recall, storage, and historian promotion paths are well-implemented and previously flagged bugs have all been addressed.
  • The three bugs identified in the previous review round (session-bleed on intent stash, FTS rebuild gap in self-heal, orphaned historian notes for project-local skills) were all fixed. The remaining findings are a misleading parameter name on stashIntent and a redundant double-call inside searchSkillMemoryFts — neither affects correctness at runtime.
  • No files require special attention beyond the stashIntent parameter naming in hook-handlers.ts, which is a latent readability concern rather than an active defect.

Important Files Changed

Filename Overview
packages/plugin/src/hooks/magic-context/hook-handlers.ts Adds the intent stash map helpers (stashIntent, getAndDeleteIntent, pruneIntentsForSession, intentKey) and the three-hook plumbing (createToolExecuteBeforeHook, maybeInjectSkillMemory). The session-composite key pattern is implemented correctly in production, but stashIntent's callId parameter name is misleading — it must receive a pre-built intentKey() composite; calling it with a bare callId silently bypasses the session-prune mechanism.
packages/plugin/src/features/magic-context/skill-memory/storage.ts New storage layer for skill_memory. The recallPartitionPredicate helper correctly unions the skill's own partition with the global '*' partition so historian-promoted notes are surfaced regardless of skill tier. searchSkillMemoryFts calls recallPartitionPredicate twice with identical arguments; a single destructured call would be cleaner.
packages/plugin/src/features/magic-context/skill-memory/recall.ts Four-rung recall cascade (cosine → FTS5 → flat recency×hit) is well-structured. Token budgeting via budgetFill clamps the pinned sub-budget to min(max_pinned_tokens, max_tokens) correctly. sanitizeSkillIntentForFts properly quotes FTS5 tokens. Top-level catch now logs via log() rather than silently swallowing errors.
packages/plugin/src/features/magic-context/skill-memory/promote.ts Historian extraction promotion: always writes to tier='global', project_identity='*'. Hash dedup bumps hit_count instead of inserting duplicates. Per-observation error isolation ensures one bad observation never blocks the rest. Clean implementation.
packages/plugin/src/features/magic-context/skill-memory/frontmatter.ts Custom minimal YAML parser for the skill-memory: block. Correctly handles both inline flow-mapping and indented block forms, inline comments, BOM, and CRLF. Returns null (inert) for malformed or absent configs rather than throwing. No dependencies on a full YAML library.
packages/plugin/src/features/magic-context/skill-memory/provenance.ts Skill path/tier/source resolution. Accepts both file:// URLs (legacy opencode) and plain paths (current). The name-based fallback resolveSkillPathByName correctly skips project-tier candidates when projectDirectory is null to avoid poisoning the registry with wrong-dir guesses. Ancestor walk stops at .git boundary, $HOME, and filesystem root.
packages/plugin/src/features/magic-context/fork-migrations.ts Three fork-lane migrations (v10000–v10002) add skill_memory, embeddings+FTS, and historian provenance columns. Migration bodies use IF NOT EXISTS / ensureColumn for idempotency. Kept in a separate runForkMigrations() so upstream's migration fence and version tests are unaffected.
packages/plugin/src/features/magic-context/storage-db.ts Self-heal additions to initializeDatabase: creates skill_memory table, FTS virtual table, and three content-table triggers with IF NOT EXISTS. The guarded FTS rebuild (ftsCount === 0 && rowCount > 0) correctly backfills pre-existing rows without re-indexing on every boot. runForkMigrations is called from both openDatabase and openDatabaseAsync.
packages/plugin/src/hooks/magic-context/compartment-parser.ts Adds <skill_observations> block parsing. The SKILL_OBS_ITEM_REGEX correctly requires *-prefixed lines in `name
packages/plugin/src/tools/ctx-skill-note/tools.ts Note creation tool. Guards against disabled skill-memory before any DB work. Hash dedup first, then cosine dedup bounded to 200 candidates. Handles the concurrent-insert race (UNIQUE constraint) by bumping hit_count on null return from insertSkillMemoryNote. Correctly computes project identity from toolContext.directory.
packages/plugin/src/tools/ctx-skill-recall/tools.ts Explicit recall tool with registry-first then disk-fallback resolution. Guards against disabled frontmatter before recall. The test-injection path defaults tier to "global", which may miss project-tier edge cases in tests but doesn't affect production. Returns distinct messages for "skill not found", "memory disabled", and "no notes yet".

Sequence Diagram

sequenceDiagram
    participant Agent
    participant SkillTool as skill tool
    participant BeforeHook as tool.execute.before
    participant AfterHook as tool.execute.after
    participant Registry as SkillLoadRegistry
    participant DB as skill_memory DB
    participant Recall as recallSkillMemoryBlock

    Agent->>SkillTool: skill(name, intent)
    SkillTool->>BeforeHook: fires pre-validation
    BeforeHook->>BeforeHook: stashIntent(map, sessionId:callId, intent)

    SkillTool-->>AfterHook: output with "Base directory for this skill:"
    AfterHook->>AfterHook: parseSkillProvenance(output)
    AfterHook->>AfterHook: parseFrontmatterConfig(SKILL.md)
    AfterHook->>Registry: set(sessionId:skillId, provenance + frontmatterConfig)
    AfterHook->>AfterHook: getAndDeleteIntent(map, sessionId:callId)
    AfterHook->>Recall: "recallSkillMemoryBlock(db, {skill, intent, scope, projectIdentity})"

    alt has intent + embeddings
        Recall->>DB: getRankingCandidates (200)
        Recall->>Recall: rankRung1(cosine over intent+delta vectors)
        Recall->>DB: getPinnedNotes
        Recall->>Recall: unionPinnedFirst + budgetFill
    else FTS fallback
        Recall->>DB: searchSkillMemoryFts(sanitized intent)
    else flat fallback
        Recall->>DB: getSkillMemoryNotes(recency×hit)
    end

    Recall->>DB: bumpRecallCountByIds(surfaced note ids)
    Recall-->>AfterHook: "<skill-memory> XML block"
    AfterHook->>AfterHook: "output.output += block"
    AfterHook-->>Agent: augmented skill tool result

    Note over Agent,DB: Agent may call ctx_skill_note to write a note
    Agent->>DB: ctx_skill_note(skill, intent, kind, delta)
    DB-->>Agent: "Skill note saved (id=…)"

    Note over DB: Historian compaction (async)
    AfterHook->>DB: "promoteSkillObservations(global, '*', observations)"
Loading

Reviews (38): Last reviewed commit: "chore(skill-memory): rebase onto upstrea..." | Re-trigger Greptile

@iceteaSA
iceteaSA force-pushed the skill-memory-pr branch 4 times, most recently from dc83db6 to 4034019 Compare June 25, 2026 11:37
@iceteaSA
iceteaSA marked this pull request as ready for review June 25, 2026 13:18

@cubic-dev-ai cubic-dev-ai Bot 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.

11 issues found across 78 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/plugin/src/features/magic-context/dreamer/task-executor.ts">

<violation number="1" location="packages/plugin/src/features/magic-context/dreamer/task-executor.ts:419">
P2: Re-embed pre-step errors are suppressed, allowing successful task completion reporting despite a failed prerequisite data maintenance step.</violation>
</file>

Note: This PR contains a large number of files. cubic only reviews up to 40 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.

Re-trigger cubic

Comment thread CONFIGURATION.md Outdated
Comment thread packages/plugin/src/features/magic-context/skill-memory/promote.ts Outdated
Comment thread packages/plugin/src/index.ts Outdated
Comment thread packages/plugin/src/tools/ctx-skill-recall/types.ts
Comment thread packages/plugin/src/features/magic-context/dreamer/task-executor.ts
Comment thread packages/plugin/src/hooks/magic-context/read-session-formatting.ts Outdated
Comment thread packages/plugin/src/hooks/magic-context/read-session-formatting.ts
Comment thread packages/plugin/src/features/magic-context/skill-memory/frontmatter.ts Outdated
Comment thread packages/plugin/src/features/magic-context/skill-memory/frontmatter.ts Outdated
Comment thread packages/plugin/src/hooks/magic-context/hook.ts Outdated
Comment thread packages/plugin/src/hooks/magic-context/hook-handlers.ts
Comment thread packages/plugin/src/features/magic-context/storage-db.ts

@cubic-dev-ai cubic-dev-ai Bot 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.

4 issues found across 15 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/plugin/src/features/magic-context/dreamer/task-executor.ts">

<violation number="1" location="packages/plugin/src/features/magic-context/dreamer/task-executor.ts:419">
P2: Re-embed pre-step errors are suppressed, allowing successful task completion reporting despite a failed prerequisite data maintenance step.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/plugin/src/features/magic-context/dreamer/task-prompts.ts Outdated
Comment thread packages/plugin/src/features/magic-context/skill-memory/frontmatter.ts Outdated
Comment thread packages/plugin/src/hooks/magic-context/read-session-formatting.ts Outdated
Comment thread packages/plugin/src/features/magic-context/skill-memory/frontmatter.test.ts Outdated
Comment thread packages/plugin/src/features/magic-context/skill-memory/promote.ts
@iceteaSA
iceteaSA marked this pull request as draft June 25, 2026 14:55
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jun 25, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jun 25, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jun 25, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
@iceteaSA
iceteaSA marked this pull request as ready for review June 25, 2026 16:09

@cubic-dev-ai cubic-dev-ai Bot 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.

4 issues found across 78 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/plugin/src/features/magic-context/dreamer/task-executor.ts">

<violation number="1" location="packages/plugin/src/features/magic-context/dreamer/task-executor.ts:419">
P2: Re-embed pre-step errors are suppressed, allowing successful task completion reporting despite a failed prerequisite data maintenance step.</violation>
</file>

Note: This PR contains a large number of files. cubic only reviews up to 40 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.

Re-trigger cubic

Comment thread ARCHITECTURE.md Outdated
Comment thread ARCHITECTURE.md Outdated
Comment thread packages/plugin/src/hooks/magic-context/read-session-formatting.ts
Comment thread packages/plugin/src/features/magic-context/skill-memory/provenance.ts Outdated
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jun 25, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jun 26, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
@iceteaSA
iceteaSA force-pushed the skill-memory-pr branch 2 times, most recently from 9c62039 to 3e28417 Compare July 2, 2026 15:22
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jul 2, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
Comment thread packages/plugin/src/tools/ctx-skill-note/tools.ts
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jul 2, 2026
…d in frontmatter

Counterpart to ctx_skill_recall's enabled-guard (greptile review, PR cortexkit#181):
without it, notes for skills that never opted in inserted successfully but
were permanently orphaned — recallSkillMemoryBlock returns "" when
frontmatter is disabled, while the agent saw a convincing 'Skill note
saved' response. Now returns an actionable error before any insert.

Red-checked: new regression test fails without the guard (orphan row
inserted + 'saved' response), passes with it (no row, 'not enabled').
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jul 2, 2026
…d in frontmatter

Counterpart to ctx_skill_recall's enabled-guard (greptile review, PR cortexkit#181):
without it, notes for skills that never opted in inserted successfully but
were permanently orphaned — recallSkillMemoryBlock returns "" when
frontmatter is disabled, while the agent saw a convincing 'Skill note
saved' response. Now returns an actionable error before any insert.

Red-checked: new regression test fails without the guard (orphan row
inserted + 'saved' response), passes with it (no row, 'not enabled').

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jul 6, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Jul 6, 2026
…d in frontmatter

Counterpart to ctx_skill_recall's enabled-guard (greptile review, PR cortexkit#181):
without it, notes for skills that never opted in inserted successfully but
were permanently orphaned — recallSkillMemoryBlock returns "" when
frontmatter is disabled, while the agent saw a convincing 'Skill note
saved' response. Now returns an actionable error before any insert.

Red-checked: new regression test fails without the guard (orphan row
inserted + 'saved' response), passes with it (no row, 'not enabled').
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Aug 7, 2026
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
iceteaSA pushed a commit to iceteaSA/magic-context that referenced this pull request Aug 7, 2026
…d in frontmatter

Counterpart to ctx_skill_recall's enabled-guard (greptile review, PR cortexkit#181):
without it, notes for skills that never opted in inserted successfully but
were permanently orphaned — recallSkillMemoryBlock returns "" when
frontmatter is disabled, while the agent saw a convincing 'Skill note
saved' response. Now returns an actionable error before any insert.

Red-checked: new regression test fails without the guard (orphan row
inserted + 'saved' response), passes with it (no row, 'not enabled').
Tehan added 27 commits August 17, 2026 23:32
Per-skill "motor memory": when a skill's SKILL.md declares
`skill-memory: { enabled: true }`, accumulated gotchas/discoveries/fixes/
workflow-steps surface in a <skill-memory> block appended to the skill
tool's RESULT on every load (cache-safe — rides the tool-result tail).
Agents write back via ctx_skill_note; ctx_skill_recall is the explicit
companion to the transparent after-hook.

- migration: skill_memory table (per-skill; tier project/global; UNIQUE on
  skill_id/tier/project_identity/normalized_hash) + lookup indexes.
- three-hook augmentation: tool.definition advertises an `intent` param;
  tool.execute.before stashes intent (bounded TTL); after-hook parses the
  skill's Base directory, reads SKILL.md frontmatter, formats the block.
- flat recency×hit recall + storage layer; ctx_skill_note / ctx_skill_recall.
- opt-in distill-skill-memory dreamer task; agent-prompt guidance; TUI/ctx-status stats.
- docs: ARCHITECTURE / STRUCTURE / CONFIGURATION / README.
Upgrade recall from flat recency×hit to a multi-rung cascade: intent +
model-matched embeddings → cosine blend across intent_embedding +
delta_embedding (relevance/recency/hit weights tunable per skill via
ranking_* frontmatter); intent + no model match → FTS5 fallback over the
content-linked skill_memory_fts vtable; empty → flat fallback.

- migration: delta_embedding + recall_count columns + skill_memory_fts FTS5 vtable.
- embed-on-write in insertSkillMemoryNote; delta-only semantic dedup.
- programmatic, no-LLM reembed pre-step for the distill-skill-memory dreamer task.
- read-side recall_count (distinct from write-side hit_count).
- canonical vector serde + dedup/ranking/FTS query helpers.
…ication (P3a)

Foundation for the historian to auto-capture skill notes cross-project.

- surface the skill name in the historian chunk as a `TC: skill(<name>)`
  marker (the keystone — the tool input name was previously dropped).
- migration: origin_project + source_type columns; unify global-tier notes
  under project_identity='*' (collision-merge) so a global note is one row
  recallable from any repo.
- partitionKey helper routes global write/recall/reembed/stats through '*';
  recall reads global-tier from '*' (cross-project); reembed sweeps '*'.
Close the loop so the historian writes skill notes during compaction
without an agent volunteering ctx_skill_note.

- historian prompt emits a <skill_observations> block; parser extracts it;
  threaded through the validated historian result.
- both runners (OpenCode + Pi) promote skill observations post-commit via
  the shared promoteSkillObservations helper, gated by
  promotionActive && !discardedLast, writing global '*' notes with
  source_type='historian'.
- self-heal net: initializeDatabase re-creates skill_memory + ensureColumn
  so an upgraded DB recovers even if a migration row is lost.
- Remove committed <<<<<<< HEAD conflict marker in CONFIGURATION.md (P1)
- Move injectSkillIntentParam before the lastChatContext guard so the intent
  param is advertised even on tool.definition flights before first chat.message
- Key intentByCallId by sessionID:callID + prefix-prune on session delete so a
  concurrent session's delete can't evict another session's in-flight intents
- Log silent catch in promoteSkillObservations (observability for dropped writes)
- Anchor frontmatter regex to start-of-file (drop m flag) so a later --- rule
  can't be misparsed; strip inline # comments from unquoted YAML scalars + block header
- Scope distill report SQL to ('<identity>','*') instead of non-deterministic LIMIT 1
- Don't truncate skill name in TC: skill(<name>) marker (identity key); sanitize
  newlines/control chars
- Normalize backslash->slash after fileURLToPath for Windows provenance checks
- FTS self-heal rebuild in initializeDatabase when skill_memory_fts is empty but
  skill_memory has rows
- Move ctx_skill_recall _test* DI fields to a separate test-only deps type
- Hoist the shared registryKey dynamic import (one import, both blocks)

Pushback: reembed pre-step errors are already logged (task-executor.ts) — the
non-blocking try/catch is by design (failure leaves notes on the FTS rung).
…2/P3)

- P1: recall now unions the skill's own partition with the global '*' partition
  (recallPartitionPredicate helper) so a PROJECT-LOCAL skill surfaces
  historian-written global notes — previously orphaned (tier='project' query
  never matched tier='global'/'*'). Write/dedup paths stay exact-partition.
- Escape apostrophes in projectPath before SQL string interpolation in the
  distill prompt template.
- Frontmatter regex tolerates a leading UTF-8 BOM / whitespace (still start-anchored).
- TC: skill(<name>) marker emits the name VERBATIM when marker-safe, else drops
  it — never mutates the identity key (recall keys on raw input.name).
- Fix misleading frontmatter test: now actually exercises a '#' inside a quoted
  scalar (preserved) vs unquoted (comment-stripped).

Regression tests: project-local skill recalls a global historian note; agent
project note + historian global note both surface for the same skill.
…routing/parser gaps)

Council review (deepseek/sonnet/gpt-5.5) of PR cortexkit#181:

- Must (consensus rev-2+rev-3): the ctx_skill_note fail-loud guard threw during
  plugin init when the plugin is disabled (enabled:false OR conflict-disabled) —
  createSessionHooks returns {magicContext:null} by design, so the unconditional
  guard crashed the entry module on the disabled path. Gate it on
  pluginConfig.enabled; pass a throwaway Map to createToolRegistry (which
  early-returns {} when disabled and never reads it).
- Must (rev-3): singular ~/.config/opencode/skill/ global path was misclassified
  as project tier (opencode's pattern is {skill,skills}/**/SKILL.md) — fixed in
  deriveSkillTier/deriveSkillSource + the ctx_skill_recall cold-start search list.
- Must (rev-3): the frontmatter parser rejected the inline flow-mapping form
  'skill-memory: { enabled: true }' — the EXACT form the ctx_skill_recall
  remediation message and ARCHITECTURE/CONFIGURATION/README advertise. Added
  inline-mapping parsing so guidance and parser agree.
- Should (consensus rev-1+rev-3): recallSkillMemoryBlock swallowed all errors
  silently — added a log() so FTS/blob corruption is diagnosable (still no-throw).

Regression tests: inline frontmatter form (3 cases), singular skill/ global path
(2 cases).
- budgetFill now counts per-note XML framing (~20 tokens) so the rendered
  <skill-memory> block stays within max_tokens instead of ~13% overshoot (rev-1).
- clamp effective pinned budget to min(max_pinned_tokens, max_tokens) so the
  default 4000>1500 can't imply pinned gets more room than the whole block (rev-2).
- ctx_skill_recall: derive tier via dirname(resolvedPath) instead of a fragile
  .replace('/SKILL.md','') (rev-2).
Updated the budget-truncation test for the framing-inclusive math.
- provenance.ts: anchor the Base-directory regex to line-start (^…/gm) and take
  the LAST match — opencode appends the provenance line at the END of tool
  output, so a skill whose CONTENT echoes 'Base directory for this skill:' (e.g.
  a skill documenting skill-memory) would otherwise shadow the real line and
  misdirect recall to a bogus identity.
- read-session-formatting.ts: narrow the marker-safe exclusion to CR/LF/tab only
  — a ')' does not break the single-line TC: skill(<name>) marker and the
  historian reads it as natural language, so a ')'-containing name is preserved
  verbatim (identity key) instead of dropped.
- ARCHITECTURE.md: update the 'Skill-memory (motor memory)' Key Abstraction to
  the shipped reality (v50/51/52, multi-rung embedding+FTS recall, global-'*'
  union) — was stale (v37, 'P2 TODO'). Remove the PR-added duplicate
  'Tag Identity (v3.3.1+)' section (upstream owns the lean '## Tag identity';
  Tag Identity is unrelated to skill-memory — rebase scope-creep).

Regression tests: provenance last-match + mid-line rejection; ')' name preserved
+ CR/LF/tab still dropped.
…emory off

Rebase-onto-v0.29.0 resolution completion. Upstream ab4f01c added a
memory.enabled gate that drops ALL ctx_memory mentions from the system
prompt when memory is off (ctx_memory is then unregistered). The skill-memory
guidance carried a 'those belong in ctx_memory' cross-reference that violated
the new contract (buildMagicContextSection memory-gating tests). Parameterized
ctxSkillMemoryGuidance(memoryEnabled) so the cross-ref drops when memory is off;
skill-memory itself stays ungated (independent store).
…d in frontmatter

Counterpart to ctx_skill_recall's enabled-guard (greptile review, PR cortexkit#181):
without it, notes for skills that never opted in inserted successfully but
were permanently orphaned — recallSkillMemoryBlock returns "" when
frontmatter is disabled, while the agent saw a convincing 'Skill note
saved' response. Now returns an actionable error before any insert.

Red-checked: new regression test fails without the guard (orphan row
inserted + 'saved' response), passes with it (no row, 'not enabled').
…opencode #33580)

opencode's skill tool changed the 'Base directory for this skill:' line from a
file:// URL to a plain filesystem path (upstream #33580). Our parser hard-required
file:/// so parseSkillProvenance returned null on current opencode -> skill-load
registry never populated -> every agent ctx_skill_note failed with a provenance
parse error. Agent-written notes silently stopped 2026-07-02 (only historian-path
notes, which bypass this parser, continued).

Widen BASE_DIR_REGEX to capture the rest of the line and branch on the value:
file:// -> fileURLToPath (legacy/back-compat); otherwise treat as a plain path.
Keeps the line-anchor + last-match decoy-rejection invariant. +4 regression tests
(plain global, plain project, plain decoy last-match, plain mid-line-ignore); all
existing file:// tests unchanged.
… v50 collision

Upstream v0.31.0 added its own migration v50 (ctx-wrapup durable marker),
colliding with skill-memory's v50/51/52. Renumbered skill migrations to
v51 (skill_memory table) / v52 (embeddings+FTS) / v53 (historian extraction),
bumped LATEST_SUPPORTED_VERSION to 53, and rotated the migration test files
(v42/v51/v52 -> v51/v52/v53) with corrected internal version refs + fence
assertions.
…ath provenance case

cubic P2 (PR cortexkit#181): the 'PLAIN filesystem path for a PROJECT skill' test
asserted tier/skillSource but not resolvedPath — the only plain-path
project-skill test, so a path-join regression (missing /SKILL.md suffix,
bad concat) would go undetected. Added the resolvedPath assertion to match
the coverage pattern of every sibling test.
…(use provider-factory seam)

Bun mock.module is process-global and mock.restore() cannot undo it
cross-file in Bun 1.3.14. The skill-memory test files (reembed, recall,
ctx-skill-note) and promotion.test.ts each globally mocked the embedding
barrel, which bled into ctx-memory's provider-coordination tests (5s
timeouts) and into each other under CI worker sharding.

Converted all four files to the non-global seam that ctx-memory's own
tests use: _setTestProviderFactoryForProject + registerProjectEmbedding
with mandatory afterEach reset. Zero mock.module calls for any embedding
barrel remain in the test suite.
…runcated

Large skills (e.g. delegating at ~53KB) exceed opencode's MAX_BYTES=51200
tool-output truncation. The 'Base directory for this skill:' provenance line
sits after the full SKILL.md content, so it lands in the dropped tail →
parseSkillProvenance returns null → skillLoadRegistry never populates →
ctx_skill_note hard-fails and the transparent <skill-memory> injection no-ops.

Add resolveSkillPathByName (shared disk-walk in provenance.ts), wired into the
after-hook as a fallback when the primary parse returns null. The skill name is
always in the tool args (never truncated), so the fallback never depends on
parsing truncatable output. ctx_skill_recall's cold-start walk refactored to
reuse the same helper (removes duplication).

Cross-family reviewed (M3): APPROVE must=0.
- Fallback only resolves project-tier candidates when the session directory
  is authoritative (sessionDirectoryBySession hit); a launch-dir guess must
  not register a wrong same-named project skill (cubic P1). Global tier
  resolves from HOME regardless.
- Ancestor walk for project-tier candidates (nearest-first, bounded at 20
  levels, stops at $HOME/root) — sessions rooted in a worktree subdir now
  find repo-root project skills, matching opencode's discoverSkills walk-up.
- DB cleanup (try/finally closeQuietly) in the truncation tests.
- Drop redundant test-provider reset in reembed.test.ts.
The fallback's global-dir walk reads $HOME at call time; a developer
machine with a same-named global skill would flip the negative-registry
assertions. Override HOME to an empty tmpdir for the describe block.
Upstream v0.33.0 added migrations v54-v69 (authority identity, mirror
cursors, live-memory resnapshots, mural, message-FTS convergence),
colliding with the skill-memory slots. Renumbered skill P1/P2/P3a to
v70/71/72; LATEST_SUPPORTED_VERSION 69 -> 72.

Also adapts our tests to two upstream contract changes:
- executeStatus is async on this branch; upstream's new cortexkit#241 clamp tests
  needed await (they were added against the sync signature).
- the historian output contract now requires the tiered paraphrase
  structure, so the skill_observations fixtures emit <p1> instead of a
  flat compartment body (same update upstream made to its e2e fixtures).
- promotion.test.ts: upstream's two new embedding tests used the global
  mock.module('./embedding') this branch removed (CI mock bleed); they
  now use the non-global provider-factory seam.
resolveSkillPathByName's project-tier ancestor walk diverged from
opencode's real discovery (skill/index.ts calls fsys.up({ start:
directory, stop: worktree }), and that helper has no depth cap and
breaks AFTER checking the stop level):

- the 20-ancestor cap let a deeply nested session dir stop early, miss
  the project skill, and fall through to a same-named GLOBAL skill —
  registering the wrong tier and path;
- without a worktree boundary the walk kept climbing toward $HOME, so a
  skill in a repo ABOVE the worktree could resolve as this project's.

Both corrupt the registry silently rather than failing loudly.

Stop at the worktree root, checked AFTER the pattern checks so the root
level stays inclusive (matching up()'s semantics). Detect it with
existsSync(<dir>/.git) — true for a normal clone's directory and a linked
worktree's file alike. Drop the depth cap; the walk is already bounded by
stripping one segment per step. $HOME/root backstops stay for sessions
outside any repo.

Regression tests red-verified against the old code: deep-nesting returned
null, and the boundary case leaked a parent-repo skill.
Upstream v0.34.0 claimed v73 (todowrite permission verdict) and v74
(detected context-limit provenance), so the three skill-memory migrations
renumber v73/74/75 -> v75/76/77 and LATEST_SUPPORTED_VERSION follows to 77.
Their test files move with them; upstream's own migrations-v73/74.test.ts
are taken as-is.

Adapts to four upstream changes:

- executeStatus grew a `dreamer` parameter. Ours added `directory` for the
  skill-memory section; both are kept, dreamer first (upstream's position),
  directory appended.
- The tool.execute.after hook now awaits flushIgnoredMessages and reads
  `agent` off the input; the skill-memory branch and the callID field are
  additive alongside it.
- getDreamTaskBacklog's switch is exhaustive over DreamTaskName, so
  distill-skill-memory needed an arm. Returns 0/0 to match its
  always-eligible gate — the distill pass is whole-corpus maintenance with
  no per-item queue, and reaching into skill_memory internals would couple
  the scheduler to a table it does not otherwise touch.
- promotion.test.ts: upstream fixed the mock.module bleed itself (7eb943e,
  our issue cortexkit#279) using the same provider-factory seam, so upstream's file
  is taken verbatim and our now-redundant version dropped. The three
  skill-memory test files keep their seam conversions.

Two fence assertions relaxed from equality to a floor: migrations-v72 and
-v74 asserted LATEST_SUPPORTED_VERSION was exactly their own version, which
cannot hold once any migration is appended above them. The lockstep
assertion (LATEST_SUPPORTED_VERSION === LATEST_MIGRATION_VERSION) is the
invariant that matters and is kept in both.
…fork lane

Upstream v0.34.2 claimed v75 ("persist mural cue validation rejection latches"),
colliding with skill-memory P1 within hours of the last renumber. That is the
seventh renumber for this feature (v38 -> v39 -> v42 -> v54 -> v70 -> v73 -> v75)
and the collision class has twice made the runner skip a real migration body,
needing live-DB surgery to repair.

Upstream shipped the fix in v0.34.1 (docs/migration-version-lanes.md): versions
>= 10000 are reserved for downstream forks sharing context.db, and fork rows are
invisible to the upstream watermark and schema fence. This moves skill-memory
there:

  fork 10000  P1  skill_memory table
  fork 10001  P2  delta_embedding + recall_count + skill_memory_fts
  fork 10002  P3a origin_project + source_type + global '*' unification

Fork migrations live in a new fork-migrations.ts rather than in MIGRATIONS, so
runMigrations() and the fence constant derived from MIGRATIONS stay byte-identical
to upstream; runForkMigrations() runs as a second pass from storage-db.ts's open
path. Selection is by per-row presence, not by the upstream watermark -- that is
what makes the lane immune to the collision-skip. Rationale in the module header.

LATEST_SUPPORTED_VERSION returns to 75, byte-identical to upstream. Divergence in
upstream-owned files is now:
  schema-version-fence.test.ts  0 lines (byte-identical)
  migrations.ts                 +7/-2 (two export keywords + comments)

migrations-v10000/1/2.test.ts (renamed from v75/76/77): the co-located
"LATEST_SUPPORTED_VERSION === newest migration" mirrors asserted an UPSTREAM-lane
contract a fork migration does not participate in. Replaced with the contract
that does hold: the migration is present in FORK_MIGRATIONS and the fence stays
below the floor.

storage-db.test.ts: upstream's downstream-rows test hand-seeds floor+0/+1, which
this branch now genuinely owns (P1/P2). Moved the seed to floor+9000/+9001 so the
test still measures what it means -- that hand-inserted downstream rows survive
and stay fence-invisible.

fork-migrations.test.ts covers lane placement, cross-lane uniqueness, idempotent
re-run, the ordering contract, and that fork rows never advance the upstream
watermark. The load-bearing test drives the real openDatabase() path and asserts
the DDL landed, not just the bookkeeping rows -- red-checked by removing both
runForkMigrations calls, which leaves every other test green (a dead-on-arrival
seam) and fails only that one.

Gates: plugin 3728/0, pi 734/0, cli 296 (2 skip), typecheck 0 x3, lint clean,
tui-compiled reproducible, marker sweep clean.
…egime

v0.35.0 introduced prompt-surface budget governance (A1 golden + budget fixture +
checklist) that pins the agent-facing surface at five tools. Skill-memory adds
ctx_skill_note and ctx_skill_recall, so every surface keyed to that list needed
them:

- ACTIVE_TOOL_IDS and the measurement catalog (buildToolDefinitions)
- PROMPT_SURFACE_TOOL_IDS + LIGHT_TOOL_DESCRIPTIONS. This was a real gap, not
  just bookkeeping: descriptionFor() early-returns the full description for any
  id outside PROMPT_SURFACE_TOOL_ID_SET, so the light preset was silently
  serving full-length skill-tool descriptions.
- Two authored light descriptions (light-descriptions.ts)
- The A1 golden, regenerated -> 7 tools

export-agent-surface.ts also never emitted section 3 (the system-prompt hash
baseline), so that table was hand-maintained and regenerating the golden dropped
it. Verified the hash is just MD5 of the guidance bytes -- reproduces all four
committed upstream values byte-for-byte -- and taught the generator to emit it.

BUDGET FIXTURE: re-measured, NOT relaxed.

  mutableProseBaseline    3650 -> 4087
  integerLightCeiling     1825 -> 2043   (still floor(0.50 * baseline))
  builtInProviderVisible  4560 -> 5260

Same tokenizer identity, same policy expression, same primary variant, same
inclusion/exclusion lists; only the measurements moved, because the surface is
genuinely larger. The fixture carries a downstreamNote recording upstream's
numbers and stating plainly that this is a downstream measurement requiring
upstream ratification, not a self-granted budget increase. Note the light surface
now measures 1969 tokens, which would have BREACHED the old 1825 ceiling -- the
increase is load-bearing, not cosmetic.

Pi: skill-memory is OpenCode-only (it hangs off OpenCode's `skill` tool hook
trio; Pi has no `skill` tool), so the shared golden lists seven tools while Pi
registers five. Pi's parity tests subtract the pair via an explicit
OPENCODE_ONLY_GOLDEN_TOOLS set rather than a prefix filter, so a genuinely-shared
tool Pi failed to register still fails the test; the set is validated against the
golden at read time so it cannot rot. Documented as PARITY.md 8b.

Gates: plugin 3777/2, pi 741/0, cli 296 (2 skip), typecheck 0 x3, lint clean,
check-prompt-surface --budget green. The 2 plugin failures are upstream's own
@OpenTui TDZ errors -- verified identical on a clean upstream/master worktree.
Upstream claimed migration slots 76 and 77. The fork lane absorbed that with no
renumbering — skill rows stay at 10000-10002 in fork-migrations.ts, and
migrations.ts takes upstream's side verbatim. First upstream LATEST bump since
the lane moved, and it cost nothing; the renumber cascade used to be the
expensive part of every one of these.

storage-db.ts: LATEST_SUPPORTED_VERSION 75 -> 77. Taking upstream's migrations.ts
during conflict resolution left the fence at our side's 75 while the array had
grown to 77 — stale by two, which the migration tests would not have caught since
they assert >= their own version.

Prompt-surface budget (cortexkit#294's canonical-list restructure):

Our two tools now enter through upstream's single ACTIVE_TOOL_IDS, and the
`satisfies Readonly<Record<PromptSurfaceToolId, string>>` clause makes a missing
light description a compile error rather than a silent omission.

v0.36 also hardened the budget gate from a derived ceiling into pinned ratified
literals (3650/1825). This fork cannot satisfy those: the 7-tool surface measures
4087, and the gap is structural — 146 tokens of tool descriptions plus 291 of
skill-memory guidance. Fitting under 3650 would mean shipping the feature with no
prompt surface at all.

So the literals are re-derived here with upstream's UNCHANGED policy,
floor(0.50 * measured baseline) -> 2043. Policy, tokenizer, primary variant, and
the inclusion/exclusion lists are untouched; only the measurement moved. The gate
test now derives its assertions from the constants instead of hardcoding the
numbers, so it tracks whichever ceiling is in force. Upstream's own baseline is
recorded in budget-fixture.json's downstreamNote — ratifying a larger surface is
upstream's call if these tools ever land there.

fork-migrations.ts: drop an ensureColumn import left dead by the conflict
resolution.

Plugin 3926/0, pi-plugin 0 fail, cli 0 fail, typecheck 0 across three packages,
budget gate green, tui-compiled regenerated.
@alfonso-magic-context

Copy link
Copy Markdown
Collaborator

Thank you for the sustained work on this and for keeping it rebased — the persistence deserves a straight answer rather than another quiet month, so here it is: we're not taking a skill-memory subsystem into Magic Context. Cross-session skill recall is being solved in our stack by a different mechanism (retrieval-on-demand skill documents with their own authoring pipeline, outside the plugin's memory system), and the historian auto-extraction lane here would overlap it while adding a second promotion pipeline to a memory system we're actively simplifying — see the design discussion in #335 for the direction. Closing as not planned. That's a verdict on fit, not on the work: the implementation quality across your PRs has been consistently high, and the extractions we've merged from them are credited in the history.

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