@zilliz/memsearch-opencode 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
You are distilling reusable skills from {{AGENT_NAME}}'s recent memory journals.
|
|
2
|
+
|
|
3
|
+
Project directory: {{PROJECT_DIR}}
|
|
4
|
+
Input memory directory: {{INPUT_DIR}}
|
|
5
|
+
|
|
6
|
+
A "skill" is procedural memory: a reusable, multi-step procedure for getting a
|
|
7
|
+
recurring task done (how to run the app, how to deploy, how to debug a class of
|
|
8
|
+
error). It is NOT a fact, a decision, or a preference — those belong in
|
|
9
|
+
PROJECT.md and USER.md.
|
|
10
|
+
|
|
11
|
+
You will receive recent memory journal entries and a list of existing skills
|
|
12
|
+
(which you MAY revise). Propose or revise skills only when they clearly earn it.
|
|
13
|
+
|
|
14
|
+
Be conservative. Quality over quantity. Most runs should return an empty list.
|
|
15
|
+
|
|
16
|
+
A NEW workflow qualifies as a candidate ONLY when ALL of these hold:
|
|
17
|
+
- It is a repeatable multi-step procedure, not a one-off action or a fact.
|
|
18
|
+
- It recurs across at least {{MIN_OCCURRENCES}} distinct sessions or days in the
|
|
19
|
+
journals below.
|
|
20
|
+
- It generalizes into a reusable capability. If it is tightly coupled to one
|
|
21
|
+
specific ticket, one specific value, or a one-time condition, do NOT propose it.
|
|
22
|
+
- The recent runs were not immediately corrected, abandoned, or undone (a
|
|
23
|
+
workflow the user kept fighting is not a good skill).
|
|
24
|
+
- It is not already covered by an existing skill.
|
|
25
|
+
|
|
26
|
+
You may also REVISE an existing skill (re-emit it with the SAME name and a
|
|
27
|
+
corrected body) when the recent journals show that procedure has genuinely
|
|
28
|
+
changed — a tool, command, flag, or step is now done differently. Only revise when
|
|
29
|
+
there is clear evidence of change; do not rewrite for style.
|
|
30
|
+
|
|
31
|
+
Rules:
|
|
32
|
+
- Return only a JSON object, with no prose outside JSON.
|
|
33
|
+
- Use {"skills": []} when nothing in the journals qualifies. This is the common case.
|
|
34
|
+
- For each candidate, write a clean, portable SKILL.md body in "body": step-by-step
|
|
35
|
+
instructions an agent can follow. Do not include YAML frontmatter — only the
|
|
36
|
+
markdown body. Keep it concise and concrete.
|
|
37
|
+
- "name" must be a short lowercase slug (letters, digits, dashes), e.g. "run-tests".
|
|
38
|
+
It becomes the skill's command name. Do not reuse an existing skill name.
|
|
39
|
+
- "description" is one line: what the skill does AND when it should trigger.
|
|
40
|
+
Lead with the verbs a user would actually type ("run", "deploy", "debug").
|
|
41
|
+
- "occurrences" is how many distinct sessions/days you saw this workflow.
|
|
42
|
+
- "sources" lists the journal file names the workflow was observed in.
|
|
43
|
+
- Do not copy raw journal text wholesale into the body; abstract it into a procedure.
|
|
44
|
+
|
|
45
|
+
How to write a good skill body (this is what makes the skill usable):
|
|
46
|
+
- Write imperative, numbered steps an agent can follow top to bottom.
|
|
47
|
+
- Be concrete: real commands, file paths, and flags — not vague prose.
|
|
48
|
+
- Keep it focused and short. A skill loads only when triggered, so include just
|
|
49
|
+
what is needed to do this one task well, and push rare detail to the end.
|
|
50
|
+
- State any preconditions, and where useful, when NOT to use the skill.
|
|
51
|
+
- Never bake in secrets, tokens, or one-off values; describe them as placeholders.
|
|
52
|
+
- Make it self-contained: an agent on a clean checkout should be able to follow it.
|
|
53
|
+
- The "description" is the trigger signal — if it does not name the situation and
|
|
54
|
+
the verbs a user would type, the skill will never fire. Spend care on it.
|
|
55
|
+
|
|
56
|
+
Accuracy — confirm from the original, do not hallucinate:
|
|
57
|
+
- The journal entries are LOSSY SUMMARIES; they drop the exact commands, flags,
|
|
58
|
+
and paths. Do not reconstruct those from the summary alone.
|
|
59
|
+
- Before writing a step's exact command, confirm it from the original transcript.
|
|
60
|
+
Each journal entry has an anchor comment naming the original conversation; the
|
|
61
|
+
key differs by agent — `transcript:<file>` (Claude Code), `rollout:<file>`
|
|
62
|
+
(Codex), or `db:`/a `session:` id (OpenCode). For a file-based transcript, run
|
|
63
|
+
`memsearch transcript <file>` (optionally `--turn <id>`) to read the original
|
|
64
|
+
turns WITH their tool calls — that is where the real commands and output live.
|
|
65
|
+
For a session/db anchor (OpenCode), use that platform's transcript script.
|
|
66
|
+
- If you cannot read the transcript or confirm a detail, capture only what the
|
|
67
|
+
summary clearly states; keep the step general or omit it — a plausible-but-wrong
|
|
68
|
+
command is worse than none. Never invent specifics.
|
|
69
|
+
- Prefer fewer, verified steps over a complete-looking but partly-guessed procedure.
|
|
70
|
+
|
|
71
|
+
JSON examples:
|
|
72
|
+
{"skills":[]}
|
|
73
|
+
|
|
74
|
+
{"skills":[{"name":"run-tests","description":"Run the project's test suite and report failures. Use when asked to run tests, check tests, or verify a change.","body":"## Run the tests\n\n1. ...\n2. ...","occurrences":4,"sources":["2026-06-12.md","2026-06-14.md"],"reason":"Test run procedure recurred across 4 sessions."}]}
|
|
@@ -363,7 +363,7 @@ def ensure_memsearch_importable() -> None:
|
|
|
363
363
|
def apply_plugin_prompt_defaults(cfg) -> None:
|
|
364
364
|
plugin_dir = Path(__file__).resolve().parent.parent
|
|
365
365
|
prompts_dir = plugin_dir / "prompts"
|
|
366
|
-
for task in ("project_review", "user_profile"):
|
|
366
|
+
for task in ("project_review", "user_profile", "memory_to_skill"):
|
|
367
367
|
if getattr(cfg.prompts, task, ""):
|
|
368
368
|
continue
|
|
369
369
|
prompt_file = prompts_dir / f"{task}.txt"
|
|
@@ -376,7 +376,14 @@ def run_native_provider(ctx, prompt: str) -> str:
|
|
|
376
376
|
env = {**os.environ, "MEMSEARCH_NO_WATCH": "1"}
|
|
377
377
|
|
|
378
378
|
if ctx.platform == "claude-code":
|
|
379
|
-
cmd = ["claude", "-p", "--strict-mcp-config", "--
|
|
379
|
+
cmd = ["claude", "-p", "--strict-mcp-config", "--no-session-persistence", "--no-chrome"]
|
|
380
|
+
# Skill distillation needs to read original transcripts for exact commands.
|
|
381
|
+
# Open a narrow hole — Bash limited to the two read-only memsearch drill
|
|
382
|
+
# commands — only for that task; other maintenance keeps all tools off.
|
|
383
|
+
if getattr(ctx, "task", "") == "memory_to_skill":
|
|
384
|
+
cmd += ["--tools", "Bash", "--allowed-tools", "Bash(memsearch transcript:*) Bash(memsearch expand:*)"]
|
|
385
|
+
else:
|
|
386
|
+
cmd += ["--tools", ""]
|
|
380
387
|
if model:
|
|
381
388
|
cmd += ["--model", model]
|
|
382
389
|
cmd += [
|
|
@@ -388,7 +395,9 @@ def run_native_provider(ctx, prompt: str) -> str:
|
|
|
388
395
|
return run_command(cmd, env=env, cwd=ctx.project_dir, timeout=120)
|
|
389
396
|
|
|
390
397
|
if ctx.platform == "codex":
|
|
391
|
-
with tempfile.NamedTemporaryFile(
|
|
398
|
+
with tempfile.NamedTemporaryFile(
|
|
399
|
+
prefix="memsearch-codex-maintenance-", suffix=".txt", delete=False
|
|
400
|
+
) as output_file:
|
|
392
401
|
output_path = Path(output_file.name)
|
|
393
402
|
cmd = [
|
|
394
403
|
"codex",
|
|
@@ -476,6 +485,20 @@ def main() -> int:
|
|
|
476
485
|
force=args.force,
|
|
477
486
|
llm_runner=llm_runner,
|
|
478
487
|
)
|
|
488
|
+
|
|
489
|
+
# Distill recurring workflows into candidate skills (procedural memory).
|
|
490
|
+
# Same session-end trigger, due-state, and llm_runner as the tasks above;
|
|
491
|
+
# this only ever touches the candidate store, never an agent's skills dir.
|
|
492
|
+
from memsearch.skills import distill as distill_skills
|
|
493
|
+
|
|
494
|
+
skill_result = distill_skills(
|
|
495
|
+
platform=args.platform,
|
|
496
|
+
project_dir=project_dir,
|
|
497
|
+
memsearch_dir=args.memsearch_dir,
|
|
498
|
+
cfg=cfg,
|
|
499
|
+
force=args.force,
|
|
500
|
+
llm_runner=llm_runner,
|
|
501
|
+
)
|
|
479
502
|
except (KeyError, RuntimeError, ValueError, subprocess.SubprocessError) as exc:
|
|
480
503
|
sys.stderr.write(f"Maintenance error: {exc}\n")
|
|
481
504
|
return 1
|
|
@@ -484,12 +507,15 @@ def main() -> int:
|
|
|
484
507
|
os.chdir(old_cwd)
|
|
485
508
|
|
|
486
509
|
payload = [result.__dict__ for result in results]
|
|
510
|
+
payload.append({"task": "memory_to_skill", **skill_result.__dict__})
|
|
487
511
|
if args.json_output:
|
|
488
512
|
sys.stdout.write(json.dumps(payload, indent=2, ensure_ascii=False) + "\n")
|
|
489
513
|
else:
|
|
490
514
|
for result in results:
|
|
491
515
|
detail = f": {result.reason}" if result.reason else ""
|
|
492
516
|
sys.stdout.write(f"{result.task}: {result.action}{detail}\n")
|
|
517
|
+
skill_detail = f": {skill_result.reason}" if skill_result.reason else ""
|
|
518
|
+
sys.stdout.write(f"memory_to_skill: {skill_result.action}{skill_detail}\n")
|
|
493
519
|
return 0
|
|
494
520
|
|
|
495
521
|
|
|
@@ -19,6 +19,7 @@ When this skill is triggered, inspect the user's request text. If there is no co
|
|
|
19
19
|
- "Not capturing/search empty/no memory": troubleshoot files, config, and index health.
|
|
20
20
|
- "Use OpenAI/Gemini/Anthropic/native/model": configure provider routing.
|
|
21
21
|
- "PROJECT.md/USER.md/profile/review": configure advanced maintenance.
|
|
22
|
+
- "skill/distill/extract a skill/memory-to-skill": procedural-memory distillation — enable or tune it here, or use the dedicated `/memory-to-skill` skill to review and install candidates.
|
|
22
23
|
- "Prompt": explain or configure prompt overrides.
|
|
23
24
|
|
|
24
25
|
Ask the user before enabling external or paid providers, changing output paths, re-indexing, deleting state, or broadening what gets indexed.
|
|
@@ -145,6 +146,11 @@ model = ""
|
|
|
145
146
|
min_interval_hours = 24
|
|
146
147
|
input_dir = ".memsearch/memory"
|
|
147
148
|
output_file = ".memsearch/USER.md"
|
|
149
|
+
|
|
150
|
+
[plugins.opencode.memory_to_skill]
|
|
151
|
+
enabled = false
|
|
152
|
+
min_occurrences = 3 # how many times a workflow must recur before it is distilled
|
|
153
|
+
paths = [] # where installed skills are copied; empty = ask the user
|
|
148
154
|
```
|
|
149
155
|
|
|
150
156
|
Provider rules:
|
|
@@ -192,6 +198,7 @@ Prompt overrides:
|
|
|
192
198
|
summarize = ""
|
|
193
199
|
project_review = ""
|
|
194
200
|
user_profile = ""
|
|
201
|
+
memory_to_skill = ""
|
|
195
202
|
```
|
|
196
203
|
|
|
197
204
|
Empty prompt paths mean use the built-in MemSearch prompts. Custom prompt files may use `{{AGENT_NAME}}`, `{{TASK_NAME}}`, `{{PROJECT_DIR}}`, `{{INPUT_DIR}}`, and `{{OUTPUT_FILE}}`; the runner appends existing output, recent journals, and digest automatically.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memory-to-skill
|
|
3
|
+
description: "Turn workflows from your MemSearch memory into reusable skills. Use when the user asks to make/create/extract/distill a skill from what they just did or from past work, review skill candidates, install a distilled skill, or 'turn this into a skill'. Manages MemSearch procedural-memory candidates under .memsearch/skill-candidates/, not OpenCode's own skills system."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
You manage MemSearch's **procedural memory**: skills distilled from the work you
|
|
7
|
+
repeat — a third layer beside the daily journals (episodic) and PROJECT.md /
|
|
8
|
+
USER.md (semantic). State once that this is MemSearch skill distillation, not
|
|
9
|
+
OpenCode's built-in skills system.
|
|
10
|
+
|
|
11
|
+
Stages: **0** memory journals → **1** candidate (`.memsearch/skill-candidates/`,
|
|
12
|
+
a git-tracked store that keeps evolving) → **2** installed (an agent skill dir).
|
|
13
|
+
Candidates are never installed automatically; installing is always a human step.
|
|
14
|
+
|
|
15
|
+
## Intent routing
|
|
16
|
+
|
|
17
|
+
- "make/turn this into a skill", "from what we just did" → **A. Capture now**.
|
|
18
|
+
- "what skills / review candidates / install X" → **B. Review & install**.
|
|
19
|
+
- "mine my history / find recurring workflows" → **C. Distill from history**.
|
|
20
|
+
- "enable / configure / how eager" → **D. Configure**.
|
|
21
|
+
- Unclear or empty → run **B**'s `list`; if empty, offer A or C.
|
|
22
|
+
|
|
23
|
+
## A. Capture what you just did (0→1→2)
|
|
24
|
+
|
|
25
|
+
You already have the context, so **draft the skill yourself** — do not call the
|
|
26
|
+
background distiller for this. Write a SKILL.md **body** (markdown, no
|
|
27
|
+
frontmatter): imperative numbered steps for the recurring task, concrete commands
|
|
28
|
+
and paths, no secrets, self-contained.
|
|
29
|
+
|
|
30
|
+
**Be exact — do not guess.** You have the live session for what you just did, so use the real commands, paths, and output, not approximations. If a detail is uncertain, verify it (re-read the relevant files or the transcript) or keep that step general — a wrong command is worse than a vague one. Then persist it as a candidate:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
printf '%s' "## <title>\n\n1. ...\n2. ..." | memsearch skills add \
|
|
34
|
+
--name "<short-slug>" \
|
|
35
|
+
--description "<what it does AND when it should trigger — lead with the verbs a user types>" \
|
|
36
|
+
--body-file -
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`add` handles slugging, standard frontmatter, meta.json, and the git commit — no
|
|
40
|
+
LLM is involved. Then show it to the user and install it (see **B**). Finally,
|
|
41
|
+
check whether background distillation is on; if not, offer to enable it (so
|
|
42
|
+
recurring workflows get captured automatically going forward) — do not force it.
|
|
43
|
+
|
|
44
|
+
## B. Review & install candidates (1→2)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
memsearch skills list # add -j for sources / installed paths
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Before recommending or installing, skim the candidate's body: if a step looks uncertain or loosely summarized, re-check it against the source (open the transcript if needed) or flag it to the user and let them decide — installing copies the candidate as-is, so this is the last chance to catch a wrong step.
|
|
51
|
+
|
|
52
|
+
Pick one, resolve where to install (ask if unset), then install:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
memsearch config get plugins.opencode.memory_to_skill.paths 2>/dev/null || echo "[]"
|
|
56
|
+
memsearch skills install <name> --path .agents/skills
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If the list is **empty**, background distillation is likely off or has not run.
|
|
60
|
+
Offer the user a choice: capture from recent work now (**A**), distill from
|
|
61
|
+
history (**C**), or enable the background pass (**D**).
|
|
62
|
+
|
|
63
|
+
## C. Mine history for recurring workflows (0→1)
|
|
64
|
+
|
|
65
|
+
To pull skills out of past work (not just the current session), read the recent
|
|
66
|
+
journals yourself — they live in `.memsearch/memory/*.md` — and look for
|
|
67
|
+
multi-step procedures that recur across several sessions. Draft each genuinely
|
|
68
|
+
reusable one and persist it with `memsearch skills add` (one call per skill), the
|
|
69
|
+
same way as **A**. Use your own judgment: only propose procedures that recur and
|
|
70
|
+
generalize, not one-offs from a single day.
|
|
71
|
+
|
|
72
|
+
**Drill into the original before drafting.** The journal bullets are a lossy summary; the exact commands, flags, and paths live in the original conversation. OpenCode stores transcripts in its session database (not a file), and the journal anchor carries a `session:` id (and `turn:` when present). Run `python3 __INSTALL_DIR__/scripts/parse-transcript.py <session_id>` (add `--turn <id>` when the anchor has one) to read the original turns with their tool calls — that is where the executed commands and output live. Write the skill from that. If the shown excerpt feels incomplete, skim nearby turns in the same original source before committing to exact commands or paths. If you cannot read it or confirm a detail, keep the step general or omit it — never fabricate.
|
|
73
|
+
|
|
74
|
+
The background pass mines automatically when enabled, but it can only see the summaries; doing it here on demand lets you read the original transcripts, so the result is more accurate.
|
|
75
|
+
|
|
76
|
+
## D. Configure
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
memsearch config get plugins.opencode.memory_to_skill.enabled 2>/dev/null || echo "false"
|
|
80
|
+
# enable the background pass (do not enable silently)
|
|
81
|
+
memsearch config set plugins.opencode.memory_to_skill.enabled true --project
|
|
82
|
+
# how eagerly history-mining distils (default 3; lower = more eager)
|
|
83
|
+
memsearch config set plugins.opencode.memory_to_skill.min_occurrences 3 --project
|
|
84
|
+
# pre-set install targets (otherwise you are asked at install time)
|
|
85
|
+
memsearch config set plugins.opencode.memory_to_skill.paths '[".agents/skills"]' --project
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Note: `enabled` only gates the **background** (session-end) pass. The explicit
|
|
89
|
+
commands above (`skills add`, `skills install`) always work, and you can mine history (C) directly.
|
|
90
|
+
|
|
91
|
+
## Install paths
|
|
92
|
+
|
|
93
|
+
- `.agents/skills` — **project-local (recommended)**: a skill from this project's
|
|
94
|
+
memory is usually most relevant here.
|
|
95
|
+
- `~/.agents/skills` — global: available across all your projects.
|
|
96
|
+
- a custom path, or several (one skill can be installed to multiple dirs).
|
|
97
|
+
|
|
98
|
+
Each agent reads skills from its own directory: Claude Code `.claude/skills/`;
|
|
99
|
+
Codex and OpenCode `.agents/skills/` (the shared standard, also read by Cursor
|
|
100
|
+
etc.); OpenClaw `.openclaw/skills/`. Claude Code does **not** read `.agents/skills/`.
|
|
101
|
+
Install to multiple paths to cover several agents.
|
|
102
|
+
|
|
103
|
+
## Guardrails
|
|
104
|
+
|
|
105
|
+
- Never enable the feature, change install paths, or install a candidate without
|
|
106
|
+
the user's go-ahead.
|
|
107
|
+
- Do not hand-edit the store; create candidates with `memsearch skills add` and let
|
|
108
|
+
the git-tracked store at `.memsearch/skill-candidates/` keep history.
|