@pcircle/memesh 4.0.3 → 4.1.1
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/README.de.md +227 -53
- package/README.es.md +230 -56
- package/README.fr.md +230 -56
- package/README.ja.md +229 -55
- package/README.ko.md +230 -56
- package/README.md +54 -3
- package/README.pt.md +230 -56
- package/README.th.md +230 -56
- package/README.vi.md +228 -54
- package/README.zh-CN.md +230 -56
- package/README.zh-TW.md +228 -54
- package/dashboard/dist/index.html +3 -3
- package/dist/core/analytics.d.ts +53 -0
- package/dist/core/analytics.d.ts.map +1 -0
- package/dist/core/analytics.js +127 -0
- package/dist/core/analytics.js.map +1 -0
- package/dist/core/auto-tagger.d.ts.map +1 -1
- package/dist/core/auto-tagger.js +14 -54
- package/dist/core/auto-tagger.js.map +1 -1
- package/dist/core/config.d.ts +1 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +6 -10
- package/dist/core/config.js.map +1 -1
- package/dist/core/consolidator.d.ts.map +1 -1
- package/dist/core/consolidator.js +11 -61
- package/dist/core/consolidator.js.map +1 -1
- package/dist/core/doctor.d.ts +40 -0
- package/dist/core/doctor.d.ts.map +1 -0
- package/dist/core/doctor.js +264 -0
- package/dist/core/doctor.js.map +1 -0
- package/dist/core/embedder.js.map +1 -1
- package/dist/core/failure-analyzer.d.ts +2 -1
- package/dist/core/failure-analyzer.d.ts.map +1 -1
- package/dist/core/failure-analyzer.js +14 -47
- package/dist/core/failure-analyzer.js.map +1 -1
- package/dist/core/graph.d.ts +13 -0
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/core/graph.js +13 -0
- package/dist/core/graph.js.map +1 -0
- package/dist/core/lesson-engine.d.ts +2 -1
- package/dist/core/lesson-engine.d.ts.map +1 -1
- package/dist/core/lesson-engine.js +2 -0
- package/dist/core/lesson-engine.js.map +1 -1
- package/dist/core/lifecycle.d.ts.map +1 -1
- package/dist/core/lifecycle.js +2 -1
- package/dist/core/lifecycle.js.map +1 -1
- package/dist/core/llm-client.d.ts +6 -0
- package/dist/core/llm-client.d.ts.map +1 -0
- package/dist/core/llm-client.js +64 -0
- package/dist/core/llm-client.js.map +1 -0
- package/dist/core/operations.d.ts +0 -1
- package/dist/core/operations.d.ts.map +1 -1
- package/dist/core/operations.js +40 -61
- package/dist/core/operations.js.map +1 -1
- package/dist/core/prompt-safety.d.ts +3 -0
- package/dist/core/prompt-safety.d.ts.map +1 -0
- package/dist/core/prompt-safety.js +13 -0
- package/dist/core/prompt-safety.js.map +1 -0
- package/dist/core/query-expander.d.ts.map +1 -1
- package/dist/core/query-expander.js +11 -72
- package/dist/core/query-expander.js.map +1 -1
- package/dist/core/schema-export.d.ts.map +1 -1
- package/dist/core/schema-export.js +72 -0
- package/dist/core/schema-export.js.map +1 -1
- package/dist/core/skill-usage-log.d.ts +11 -0
- package/dist/core/skill-usage-log.d.ts.map +1 -0
- package/dist/core/skill-usage-log.js +125 -0
- package/dist/core/skill-usage-log.js.map +1 -0
- package/dist/core/stats.d.ts +12 -0
- package/dist/core/stats.d.ts.map +1 -0
- package/dist/core/stats.js +19 -0
- package/dist/core/stats.js.map +1 -0
- package/dist/core/types.d.ts +9 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/verifier.d.ts +37 -0
- package/dist/core/verifier.d.ts.map +1 -0
- package/dist/core/verifier.js +195 -0
- package/dist/core/verifier.js.map +1 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +14 -0
- package/dist/db.js.map +1 -1
- package/dist/knowledge-graph.d.ts.map +1 -1
- package/dist/knowledge-graph.js +8 -43
- package/dist/knowledge-graph.js.map +1 -1
- package/dist/skills-manifest.json +71 -0
- package/dist/storage/conflicts.d.ts +4 -0
- package/dist/storage/conflicts.d.ts.map +1 -0
- package/dist/storage/conflicts.js +32 -0
- package/dist/storage/conflicts.js.map +1 -0
- package/dist/storage/fts-index.d.ts +4 -0
- package/dist/storage/fts-index.d.ts.map +1 -0
- package/dist/storage/fts-index.js +18 -0
- package/dist/storage/fts-index.js.map +1 -0
- package/dist/transports/cli/cli.js +203 -69
- package/dist/transports/cli/cli.js.map +1 -1
- package/dist/transports/http/server.d.ts +1 -0
- package/dist/transports/http/server.d.ts.map +1 -1
- package/dist/transports/http/server.js +138 -231
- package/dist/transports/http/server.js.map +1 -1
- package/dist/transports/mcp/handlers.d.ts +93 -0
- package/dist/transports/mcp/handlers.d.ts.map +1 -1
- package/dist/transports/mcp/handlers.js +51 -1
- package/dist/transports/mcp/handlers.js.map +1 -1
- package/dist/transports/schemas.d.ts +28 -0
- package/dist/transports/schemas.d.ts.map +1 -1
- package/dist/transports/schemas.js +25 -0
- package/dist/transports/schemas.js.map +1 -1
- package/hooks/hooks.json +10 -0
- package/package.json +5 -3
- package/plugin.json +1 -1
- package/scripts/hooks/_shared.js +207 -1
- package/scripts/hooks/post-commit.js +5 -76
- package/scripts/hooks/pre-bash-orchestration-nudge.js +150 -0
- package/scripts/hooks/pre-compact.js +8 -76
- package/scripts/hooks/pre-edit-recall.js +0 -0
- package/scripts/hooks/session-start.js +69 -8
- package/scripts/hooks/session-summary.js +12 -81
- package/skills/agentic-orchestration/SKILL.md +399 -0
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
|
+
import { createHash } from 'crypto';
|
|
4
5
|
import { homedir } from 'os';
|
|
5
|
-
import {
|
|
6
|
-
import { existsSync, unlinkSync } from 'fs';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
6
|
+
import { join, basename } from 'path';
|
|
7
|
+
import { existsSync, unlinkSync, rmSync, appendFileSync, chmodSync } from 'fs';
|
|
8
8
|
import {
|
|
9
9
|
buildReferenceContext,
|
|
10
10
|
ensurePrivateDir,
|
|
11
11
|
getMemeshDir,
|
|
12
|
+
isAgenticOrchestrationEnabled,
|
|
12
13
|
isTrustedForAutoContext,
|
|
14
|
+
resolvePluginRoot,
|
|
15
|
+
resolveSessionLimit,
|
|
13
16
|
writePrivateJson,
|
|
14
17
|
} from './_shared.js';
|
|
15
18
|
|
|
@@ -18,6 +21,7 @@ const require = createRequire(import.meta.url);
|
|
|
18
21
|
const dbPath = process.env.MEMESH_DB_PATH || join(homedir(), '.memesh', 'knowledge-graph.db');
|
|
19
22
|
const memeshDir = getMemeshDir(process.env);
|
|
20
23
|
const throttlePath = join(memeshDir, 'session-recalled-files.json');
|
|
24
|
+
const nudgeFlagsDir = join(memeshDir, 'agent-nudge-flags');
|
|
21
25
|
|
|
22
26
|
let input = '';
|
|
23
27
|
process.stdin.setEncoding('utf8');
|
|
@@ -27,7 +31,7 @@ process.stdin.on('end', async () => {
|
|
|
27
31
|
const data = JSON.parse(input);
|
|
28
32
|
const projectName = basename(data.cwd || process.cwd());
|
|
29
33
|
|
|
30
|
-
// Clear
|
|
34
|
+
// Clear per-session throttle files from previous session
|
|
31
35
|
try {
|
|
32
36
|
if (existsSync(throttlePath)) {
|
|
33
37
|
unlinkSync(throttlePath);
|
|
@@ -35,6 +39,13 @@ process.stdin.on('end', async () => {
|
|
|
35
39
|
} catch {
|
|
36
40
|
// Non-critical
|
|
37
41
|
}
|
|
42
|
+
try {
|
|
43
|
+
if (existsSync(nudgeFlagsDir)) {
|
|
44
|
+
rmSync(nudgeFlagsDir, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// Non-critical
|
|
48
|
+
}
|
|
38
49
|
|
|
39
50
|
if (!existsSync(dbPath)) {
|
|
40
51
|
output('MeMesh: No database found. Memories will be created as you work.');
|
|
@@ -65,8 +76,9 @@ process.stdin.on('end', async () => {
|
|
|
65
76
|
const statusFilter = hasStatus ? "AND e.status = 'active'" : '';
|
|
66
77
|
const recentStatusFilter = hasStatus ? "WHERE status = 'active'" : '';
|
|
67
78
|
|
|
68
|
-
// Configurable limit: how many top-N entities to load per section
|
|
69
|
-
|
|
79
|
+
// Configurable limit: how many top-N entities to load per section.
|
|
80
|
+
// Env > config.sessionLimit > default 10.
|
|
81
|
+
const sessionLimit = resolveSessionLimit(process.env);
|
|
70
82
|
|
|
71
83
|
// Build scoring ORDER BY clause (or fallback to insertion order)
|
|
72
84
|
const scoringOrderBy = hasScoringCols
|
|
@@ -188,6 +200,54 @@ process.stdin.on('end', async () => {
|
|
|
188
200
|
// Lesson query failed — don't break session start
|
|
189
201
|
}
|
|
190
202
|
|
|
203
|
+
// --- Agentic-orchestration mode banner (experimental protocol, opt-in) ---
|
|
204
|
+
// memesh ships an experimental working-model protocol alongside its
|
|
205
|
+
// memory layer. The banner reminds Claude at session start that the
|
|
206
|
+
// suggested default for verifiable work (build/test/lint/migrate/
|
|
207
|
+
// refactor/benchmark) is to dispatch a background agent rather than
|
|
208
|
+
// block the conversation; strategic work stays foreground.
|
|
209
|
+
//
|
|
210
|
+
// OPT-IN ONLY: enabled via MEMESH_ENABLE_AGENTIC_ORCHESTRATION=1.
|
|
211
|
+
// The default is OFF — main wedge of memesh is local memory; the
|
|
212
|
+
// working-model protocol is a separable experiment, and its banner
|
|
213
|
+
// would otherwise dominate every session for users who never asked
|
|
214
|
+
// for it. Setting the flag also enables local skill-usage telemetry
|
|
215
|
+
// (~/.memesh/skill-usage.jsonl) so the protocol can later be
|
|
216
|
+
// validated with real usage data.
|
|
217
|
+
if (isAgenticOrchestrationEnabled(process.env)) {
|
|
218
|
+
try {
|
|
219
|
+
memorySummary +=
|
|
220
|
+
'\n\n[Experimental working model — protocol; effectiveness still being validated] ' +
|
|
221
|
+
'User=CTO · Claude=Orchestrator · Agents=Engineering team\n' +
|
|
222
|
+
'Verifiable work (build/test/lint/refactor/benchmark) → dispatch as background agent (Task with run_in_background:true).\n' +
|
|
223
|
+
'Strategic work → stay foreground. Skill: agentic-orchestration.';
|
|
224
|
+
|
|
225
|
+
// Local-only telemetry — never networked. Hook writes the JSONL
|
|
226
|
+
// line directly to keep itself self-contained (no dynamic import
|
|
227
|
+
// of compiled TS). Only fires when the user has opted in above.
|
|
228
|
+
try {
|
|
229
|
+
const usagePath = join(homedir(), '.memesh', 'skill-usage.jsonl');
|
|
230
|
+
// Hash the cwd so distinct-project counting still works without
|
|
231
|
+
// persisting any path fragment. SHA-256 → first 16 hex chars =
|
|
232
|
+
// 64 bits, plenty to distinguish projects on one machine.
|
|
233
|
+
const cwd = String(data?.cwd || process.cwd());
|
|
234
|
+
const cwdHashed = createHash('sha256').update(cwd).digest('hex').slice(0, 16);
|
|
235
|
+
const line = JSON.stringify({
|
|
236
|
+
ts: new Date().toISOString(),
|
|
237
|
+
event: 'agentic_orchestration_banner_injected',
|
|
238
|
+
payload: { cwd_hashed: cwdHashed },
|
|
239
|
+
}) + '\n';
|
|
240
|
+
appendFileSync(usagePath, line);
|
|
241
|
+
// Tighten mode — telemetry includes timestamps + per-project
|
|
242
|
+
// hashed cwd which can profile user activity. Other local
|
|
243
|
+
// users on a shared system should not be able to read it.
|
|
244
|
+
try { chmodSync(usagePath, 0o600); } catch { /* non-POSIX */ }
|
|
245
|
+
} catch { /* swallow — telemetry must not break session-start */ }
|
|
246
|
+
} catch {
|
|
247
|
+
// Banner failed — non-critical, continue
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
191
251
|
// --- Record injected entity IDs for recall effectiveness tracking ---
|
|
192
252
|
try {
|
|
193
253
|
// CRITICAL: Deduplicate by entity ID (entity may appear in both project and recent lists)
|
|
@@ -249,8 +309,9 @@ process.stdin.on('end', async () => {
|
|
|
249
309
|
// Opens a separate read-write connection via the core module.
|
|
250
310
|
// Throttled to once per 24h inside compressWeeklyNoise().
|
|
251
311
|
try {
|
|
252
|
-
|
|
253
|
-
|
|
312
|
+
// F5: derive pluginRoot strictly from this file's location.
|
|
313
|
+
// See `resolvePluginRoot` for the full reasoning.
|
|
314
|
+
const pluginRoot = resolvePluginRoot(import.meta.url);
|
|
254
315
|
const dbMod = await import(join(pluginRoot, 'dist/db.js'));
|
|
255
316
|
const lifecycleMod = await import(join(pluginRoot, 'dist/core/lifecycle.js'));
|
|
256
317
|
dbMod.openDatabase();
|
|
@@ -5,64 +5,12 @@
|
|
|
5
5
|
// and stores as session-insight entities in MeMesh.
|
|
6
6
|
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
|
-
import { getMemeshDir } from './_shared.js';
|
|
8
|
+
import { join, basename } from 'path';
|
|
9
|
+
import { existsSync, readFileSync } from 'fs';
|
|
10
|
+
import { getMemeshDir, isAutoCaptureEnabled, openHookDb, resolvePluginRoot } from './_shared.js';
|
|
13
11
|
|
|
14
12
|
const require = createRequire(import.meta.url);
|
|
15
13
|
|
|
16
|
-
const SCHEMA_SQL = `
|
|
17
|
-
CREATE TABLE IF NOT EXISTS entities (
|
|
18
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
19
|
-
name TEXT NOT NULL UNIQUE,
|
|
20
|
-
type TEXT NOT NULL,
|
|
21
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
22
|
-
metadata JSON
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
CREATE TABLE IF NOT EXISTS observations (
|
|
26
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
27
|
-
entity_id INTEGER NOT NULL,
|
|
28
|
-
content TEXT NOT NULL,
|
|
29
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
30
|
-
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
CREATE TABLE IF NOT EXISTS relations (
|
|
34
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
35
|
-
from_entity_id INTEGER NOT NULL,
|
|
36
|
-
to_entity_id INTEGER NOT NULL,
|
|
37
|
-
relation_type TEXT NOT NULL,
|
|
38
|
-
metadata JSON,
|
|
39
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
40
|
-
FOREIGN KEY (from_entity_id) REFERENCES entities(id) ON DELETE CASCADE,
|
|
41
|
-
FOREIGN KEY (to_entity_id) REFERENCES entities(id) ON DELETE CASCADE,
|
|
42
|
-
UNIQUE(from_entity_id, to_entity_id, relation_type)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
CREATE TABLE IF NOT EXISTS tags (
|
|
46
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
47
|
-
entity_id INTEGER NOT NULL,
|
|
48
|
-
tag TEXT NOT NULL,
|
|
49
|
-
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
CREATE INDEX IF NOT EXISTS idx_tags_entity ON tags(entity_id);
|
|
53
|
-
CREATE INDEX IF NOT EXISTS idx_tags_tag ON tags(tag);
|
|
54
|
-
DELETE FROM tags
|
|
55
|
-
WHERE id NOT IN (
|
|
56
|
-
SELECT MIN(id)
|
|
57
|
-
FROM tags
|
|
58
|
-
GROUP BY entity_id, tag
|
|
59
|
-
);
|
|
60
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_tags_entity_tag_unique ON tags(entity_id, tag);
|
|
61
|
-
CREATE INDEX IF NOT EXISTS idx_observations_entity ON observations(entity_id);
|
|
62
|
-
CREATE INDEX IF NOT EXISTS idx_relations_from ON relations(from_entity_id);
|
|
63
|
-
CREATE INDEX IF NOT EXISTS idx_relations_to ON relations(to_entity_id);
|
|
64
|
-
`;
|
|
65
|
-
|
|
66
14
|
// Parse a JSONL transcript file.
|
|
67
15
|
// Mirrors logic in src/core/extractor.ts parseTranscript().
|
|
68
16
|
// Defensive: never throws — malformed lines are silently skipped.
|
|
@@ -124,8 +72,8 @@ process.stdin.on('end', async () => {
|
|
|
124
72
|
try {
|
|
125
73
|
if (!input.trim()) return exit0();
|
|
126
74
|
|
|
127
|
-
// Opt-out check
|
|
128
|
-
if (process.env
|
|
75
|
+
// Opt-out check (env > config > default-on)
|
|
76
|
+
if (!isAutoCaptureEnabled(process.env)) return exit0();
|
|
129
77
|
|
|
130
78
|
let inputData;
|
|
131
79
|
try {
|
|
@@ -151,30 +99,12 @@ process.stdin.on('end', async () => {
|
|
|
151
99
|
// Skip sessions with too little activity
|
|
152
100
|
if (toolCallCount < 3) return exit0();
|
|
153
101
|
|
|
154
|
-
// Open DB
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (!existsSync(dbDir)) mkdirSync(dbDir, { recursive: true });
|
|
158
|
-
|
|
159
|
-
const Database = require('better-sqlite3');
|
|
102
|
+
// Open DB via shared helper — applies SCHEMA_SQL + status migration.
|
|
103
|
+
// sqlite-vec is loaded separately because only this hook needs it
|
|
104
|
+
// (for embedding-aware recall-effectiveness tracking).
|
|
160
105
|
const sqliteVec = require('sqlite-vec');
|
|
161
|
-
|
|
162
|
-
const db = new Database(dbPath);
|
|
106
|
+
const { db } = openHookDb(process.env);
|
|
163
107
|
try {
|
|
164
|
-
db.pragma('journal_mode = WAL');
|
|
165
|
-
db.pragma('foreign_keys = ON');
|
|
166
|
-
|
|
167
|
-
// Ensure schema exists (tables may already exist from MeMesh server)
|
|
168
|
-
db.exec(SCHEMA_SQL);
|
|
169
|
-
|
|
170
|
-
// Migrate: add status column if missing (v2.11 -> v2.12)
|
|
171
|
-
const cols = db.prepare("PRAGMA table_info(entities)").all();
|
|
172
|
-
if (!cols.some(c => c.name === 'status')) {
|
|
173
|
-
db.exec("ALTER TABLE entities ADD COLUMN status TEXT NOT NULL DEFAULT 'active'");
|
|
174
|
-
db.exec("CREATE INDEX IF NOT EXISTS idx_entities_status ON entities(status)");
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Load sqlite-vec extension
|
|
178
108
|
sqliteVec.load(db);
|
|
179
109
|
|
|
180
110
|
// Duplicate detection: if we already captured this session, bail
|
|
@@ -326,8 +256,9 @@ process.stdin.on('end', async () => {
|
|
|
326
256
|
// Wrapped in its own try/catch — never blocks rule-based extraction.
|
|
327
257
|
if (errorsEncountered.length > 0 && filesEdited.length > 0) {
|
|
328
258
|
try {
|
|
329
|
-
|
|
330
|
-
|
|
259
|
+
// F5: derive pluginRoot strictly from this file's location.
|
|
260
|
+
// See `resolvePluginRoot` for the full reasoning.
|
|
261
|
+
const pluginRoot = resolvePluginRoot(import.meta.url);
|
|
331
262
|
const configMod = await import(join(pluginRoot, 'dist/core/config.js'));
|
|
332
263
|
const config = configMod.readConfig();
|
|
333
264
|
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: agentic-orchestration
|
|
3
|
+
description: Experimental working-model protocol shipped with memesh v4.1. Status — protocol present + instrumented; effectiveness in real usage is being collected (see `memesh patterns`), not yet proven. Suggests a user-as-CTO / Claude-as-orchestrator / background-agents-as-engineers split. Claude routes work by verifiability, dispatches parallel background agents for high-verifiability technical work, and stays foreground only for strategic/understanding work that the user must own. Use as a default for non-trivial software tasks; report back when it helps or doesn't.
|
|
4
|
+
user-invocable: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Agentic Orchestration (Experimental Working-Model Protocol)
|
|
8
|
+
|
|
9
|
+
> **Status — experimental, instrumented, validation in progress.** This
|
|
10
|
+
> skill is shipped to begin collecting evidence about whether a structured
|
|
11
|
+
> verifiability-router protocol changes Claude's behavior in ways that
|
|
12
|
+
> measurably help users. `memesh patterns` exposes a local counter so you
|
|
13
|
+
> can see how often the banner is injected and how often
|
|
14
|
+
> `verify_agent_work` is invoked in your real usage. None of that data
|
|
15
|
+
> ever leaves your machine.
|
|
16
|
+
|
|
17
|
+
> **The roles, suggested:**
|
|
18
|
+
> - **User = CTO / PM.** Owns understanding, strategy, product taste, "what is worth building."
|
|
19
|
+
> - **Claude = Orchestrator / engineering manager.** Routes work, dispatches agents, reviews diffs, surfaces decisions, never the bottleneck.
|
|
20
|
+
> - **Background agents = engineering interns.** Execute high-verifiability technical work in parallel.
|
|
21
|
+
|
|
22
|
+
The hypothesis behind this skill: Claude as a single-threaded synchronous
|
|
23
|
+
coding partner spends a meaningful portion of the user's time on work
|
|
24
|
+
that could run in the background. If that hypothesis holds, this skill
|
|
25
|
+
should noticeably reduce wall-clock time on multi-step technical tasks.
|
|
26
|
+
We do not yet have field data either way.
|
|
27
|
+
|
|
28
|
+
**Announce at start:** "Using agentic-orchestration (experimental protocol) to route this work."
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Why this ships with memesh
|
|
33
|
+
|
|
34
|
+
memesh is a local memory layer **and** a working-model activator. Three
|
|
35
|
+
parts compose:
|
|
36
|
+
|
|
37
|
+
1. **This skill** — the protocol document. Loaded by Claude Code's skill
|
|
38
|
+
system when memesh is installed. Discoverable on its own.
|
|
39
|
+
2. **The SessionStart banner hook** — injects the working model into
|
|
40
|
+
Claude's context at session start so it sticks. **Opt-in: set
|
|
41
|
+
`MEMESH_ENABLE_AGENTIC_ORCHESTRATION=1`.**
|
|
42
|
+
3. **The PreToolUse Bash nudge hook** — advisory reminder when Claude is
|
|
43
|
+
about to run a high-verifiability bash command synchronously,
|
|
44
|
+
suggesting `run_in_background: true` instead. **Opt-in: same flag.**
|
|
45
|
+
|
|
46
|
+
Default is OFF for parts 2 and 3 — the core memory features (parts that
|
|
47
|
+
are not "the protocol") work without setting any flag. Opt in to the
|
|
48
|
+
flag if you want to participate in the experiment; doing so also enables
|
|
49
|
+
local-only telemetry (`memesh patterns`) so the protocol's effectiveness
|
|
50
|
+
can later be validated with real usage data.
|
|
51
|
+
|
|
52
|
+
Plus: memesh's self-improving lessons + the `agent_pattern` entity type
|
|
53
|
+
(record what dispatch patterns worked) close the loop — the longer you
|
|
54
|
+
use memesh, the better Claude gets at orchestrating *your* team's
|
|
55
|
+
specific kinds of work.
|
|
56
|
+
|
|
57
|
+
Memory is the substrate. Operating model is what makes Claude Code feel
|
|
58
|
+
different on day one.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## The Verifiability Router
|
|
63
|
+
|
|
64
|
+
Before doing any task, classify it. This decides whether Claude does it
|
|
65
|
+
foreground or dispatches it as a background agent.
|
|
66
|
+
|
|
67
|
+
```dot
|
|
68
|
+
digraph router {
|
|
69
|
+
"New task arrives" [shape=doublecircle];
|
|
70
|
+
"Outcome is checkable by code?" [shape=diamond];
|
|
71
|
+
"Multiple independent subtasks?" [shape=diamond];
|
|
72
|
+
"User must own the decision?" [shape=diamond];
|
|
73
|
+
"Foreground sync (Claude does it now)" [shape=box, style=filled];
|
|
74
|
+
"Single background agent (run_in_background:true)" [shape=box, style=filled];
|
|
75
|
+
"Parallel background agents (one per subtask)" [shape=box, style=filled];
|
|
76
|
+
|
|
77
|
+
"New task arrives" -> "User must own the decision?";
|
|
78
|
+
"User must own the decision?" -> "Foreground sync (Claude does it now)" [label="yes"];
|
|
79
|
+
"User must own the decision?" -> "Outcome is checkable by code?" [label="no"];
|
|
80
|
+
"Outcome is checkable by code?" -> "Foreground sync (Claude does it now)" [label="no"];
|
|
81
|
+
"Outcome is checkable by code?" -> "Multiple independent subtasks?" [label="yes"];
|
|
82
|
+
"Multiple independent subtasks?" -> "Single background agent (run_in_background:true)" [label="no"];
|
|
83
|
+
"Multiple independent subtasks?" -> "Parallel background agents (one per subtask)" [label="yes"];
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Three Tiers — be explicit about which one applies
|
|
88
|
+
|
|
89
|
+
| Tier | What it is | Verification cost | Dispatch verdict |
|
|
90
|
+
|---|---|---|---|
|
|
91
|
+
| **Tier 1 — Machine-verifiable** | tsc, vitest, lint, build, migrate, benchmark, gh run watch | seconds, deterministic | **Background, parallel OK** |
|
|
92
|
+
| **Tier 2 — Review-verifiable** | API shape, schema, public types, generated docs, code review against checklist | minutes, semi-automated | **Background OK + auto-trigger code-review after** |
|
|
93
|
+
| **Tier 3 — Judgment-required** | UX, naming, architecture, strategy, public-facing copy | hours, human only | **Foreground only — do not dispatch** |
|
|
94
|
+
|
|
95
|
+
Operating principle: **anything Tier 1 or Tier 2 should be agentic; verifying it is the bottleneck, not doing it.** If verification of an agent's claim takes longer than the work itself, the dispatch is a net negative — design verification first, then dispatch.
|
|
96
|
+
|
|
97
|
+
### High verifiability (→ background agent)
|
|
98
|
+
|
|
99
|
+
The agent can self-verify because the goal is mechanically checkable.
|
|
100
|
+
|
|
101
|
+
- Build / typecheck / lint passes
|
|
102
|
+
- Test suite passes (unit, integration, e2e)
|
|
103
|
+
- Migration applies cleanly to fresh DB
|
|
104
|
+
- Benchmark reaches a threshold
|
|
105
|
+
- Refactor preserves behaviour (regression tests)
|
|
106
|
+
- Code review of a diff against a checklist
|
|
107
|
+
- Documentation generated from code matches actual signatures
|
|
108
|
+
- Deploy succeeds and a smoke test passes
|
|
109
|
+
- Schema diff between two states is empty
|
|
110
|
+
- "Make CI green" — the agent can loop until green
|
|
111
|
+
|
|
112
|
+
### Low verifiability (→ foreground, user owns)
|
|
113
|
+
|
|
114
|
+
No mechanical check exists. The user's *understanding* is the
|
|
115
|
+
verification.
|
|
116
|
+
|
|
117
|
+
- Strategy, positioning, pricing, audience choice
|
|
118
|
+
- Product feature/scope decisions
|
|
119
|
+
- Naming, taglines, copywriting that represents the brand
|
|
120
|
+
- Whether a result is "publishable" for marketing
|
|
121
|
+
- Whether a proposed direction matches the user's long-term plan
|
|
122
|
+
- Trade-off calls (do A and lose B)
|
|
123
|
+
- Reviewing the *first* surface a user touches
|
|
124
|
+
- Anything that, if Claude got wrong, would damage reputation
|
|
125
|
+
irrecoverably
|
|
126
|
+
|
|
127
|
+
If unsure: **default to foreground**. The cost of a wrong delegation on
|
|
128
|
+
strategic work is much higher than the cost of one extra synchronous
|
|
129
|
+
turn.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Dispatch Patterns
|
|
134
|
+
|
|
135
|
+
### Pattern A — Single background agent (most common)
|
|
136
|
+
|
|
137
|
+
For one self-contained verifiable task that takes ≥10 minutes.
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
Task tool:
|
|
141
|
+
subagent_type: general-purpose (or domain-specific)
|
|
142
|
+
description: 3-5 word summary
|
|
143
|
+
prompt: Self-contained brief. Include: goal, context the agent needs,
|
|
144
|
+
what to produce, what NOT to do (e.g. "do not push to remote",
|
|
145
|
+
"do not modify production code"), how to verify success.
|
|
146
|
+
isolation: "worktree" ← if it touches files
|
|
147
|
+
mode: "acceptEdits" ← so the agent can edit existing files
|
|
148
|
+
without permission prompts
|
|
149
|
+
run_in_background: true ← always for ≥10min work
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
After dispatch:
|
|
153
|
+
1. Tell user one sentence: "Dispatched [agent name] in background, will report back."
|
|
154
|
+
2. **Continue with other work** — do NOT poll, do NOT sleep.
|
|
155
|
+
3. When the system delivers a completion notification, surface results.
|
|
156
|
+
4. Trust but verify: read the agent's actual diff, do not just trust its summary.
|
|
157
|
+
|
|
158
|
+
### Pattern B — Parallel background agents
|
|
159
|
+
|
|
160
|
+
For 2+ independent verifiable subtasks. Send all of them in **one
|
|
161
|
+
message with multiple Task tool calls**, not sequentially. Then continue
|
|
162
|
+
with foreground work (e.g. discussing strategy with the user) while
|
|
163
|
+
they run.
|
|
164
|
+
|
|
165
|
+
### Pattern C — Foreground iteration
|
|
166
|
+
|
|
167
|
+
For low-verifiability work where the user must stay in the loop. Stop
|
|
168
|
+
generating long monologues. Send shorter messages. Ask one focused
|
|
169
|
+
question at a time when blocked. Do not make strategic decisions that
|
|
170
|
+
the user did not authorize.
|
|
171
|
+
|
|
172
|
+
### Pattern D — Hybrid (recommended for big tasks)
|
|
173
|
+
|
|
174
|
+
Most real work is mixed. Run them in the right shape:
|
|
175
|
+
- Foreground: "what is the goal, what is in scope, what does success look like"
|
|
176
|
+
- Branch off: dispatch background agents for each verifiable subgoal
|
|
177
|
+
- Foreground: review their outputs, decide what to keep, iterate
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## The Verification Gate (mandatory post-agent procedure)
|
|
182
|
+
|
|
183
|
+
**An agent's summary is not evidence. The diff is. Tests passing locally are.**
|
|
184
|
+
|
|
185
|
+
Before reporting any agent's work as "done" — to the user, to memory, in a commit message, anywhere — the orchestrator MUST run the verification gate. No exceptions for "this agent is reliable" or "I read the prompt carefully." The discipline is mechanical because human trust scales worse than agents do.
|
|
186
|
+
|
|
187
|
+
### Gate sequence (run in order, stop on first failure)
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
1. Reality check — did the claimed changes actually happen?
|
|
191
|
+
git -C <agent_workdir> diff --stat <base>..HEAD
|
|
192
|
+
→ compare against agent's claim of "files changed"
|
|
193
|
+
→ if mismatch: agent fabricated. Discard, do not commit.
|
|
194
|
+
|
|
195
|
+
2. Hard verification — do the deterministic checks pass?
|
|
196
|
+
npm run typecheck # tsc --noEmit
|
|
197
|
+
npm test -- --run # full suite, not "the new tests"
|
|
198
|
+
npm run lint (if exists)
|
|
199
|
+
npm run build (if changes touch build output)
|
|
200
|
+
→ if any fail: agent's work is incomplete. Fix-then-dispatch
|
|
201
|
+
a follow-up, or take over foreground. Do NOT commit broken state.
|
|
202
|
+
|
|
203
|
+
3. Cross-check — do the numbers in the agent's summary match reality?
|
|
204
|
+
"added 5 tests" → grep -c "^\s*it\(" <new test files>
|
|
205
|
+
"77/77 pass" → re-run test count, verify
|
|
206
|
+
"R@5 = 95.40%" → spot-check one or two of the result rows
|
|
207
|
+
→ numbers that match by accident are still verified;
|
|
208
|
+
numbers that the agent calculated must be re-derived independently.
|
|
209
|
+
|
|
210
|
+
4. Independent review (Tier 2 only) — does an outside reviewer see issues?
|
|
211
|
+
Spawn a fresh-context code-review subagent with no memory of the
|
|
212
|
+
original work. Have it review only the diff against the project's
|
|
213
|
+
standards. Surface any non-overlapping findings.
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### What the gate is NOT
|
|
217
|
+
|
|
218
|
+
- Not a replacement for tests written by the agent — it CHECKS that they pass
|
|
219
|
+
- Not "vibes-based" review — every step is a command with deterministic output
|
|
220
|
+
- Not skippable when "I'm in a hurry" — speed comes from parallel dispatch, not from skipping verification
|
|
221
|
+
|
|
222
|
+
### Recursive trust problem (do not fall in)
|
|
223
|
+
|
|
224
|
+
The verification gate's steps must be **deterministic commands**, not LLM judgment. An "LLM that verifies an LLM" is the same risk class as no verification — both can fabricate. The only safe verifiers are:
|
|
225
|
+
|
|
226
|
+
- Compilers and linters
|
|
227
|
+
- Test runners with assertions
|
|
228
|
+
- Diff tools and `git status`
|
|
229
|
+
- File existence + content hash checks
|
|
230
|
+
- HTTP probes that assert response codes/shapes
|
|
231
|
+
- Schema validators (Zod, JSON Schema, Prisma)
|
|
232
|
+
|
|
233
|
+
LLM-as-reviewer is useful for **opinion** ("does this look idiomatic?"), useless for **fact** ("did the test actually run?"). Use it as Tier 2 augmentation, never as Tier 1 substitute.
|
|
234
|
+
|
|
235
|
+
### When verification reveals the agent fabricated
|
|
236
|
+
|
|
237
|
+
Treat as a debugging signal, not a personal failure. Record it:
|
|
238
|
+
1. Stash the agent's diff (don't lose it, in case there is salvage)
|
|
239
|
+
2. Note what it claimed vs what the gate found
|
|
240
|
+
3. Save to memesh as a `lesson_learned`: "When dispatching <pattern>, verification at step <N> caught <fabrication-type>"
|
|
241
|
+
4. Decide: re-dispatch with sharper prompt, or take over foreground
|
|
242
|
+
|
|
243
|
+
This is how the orchestrator learns which dispatch shapes are reliable for the user's stack.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Known limitation — file creation in worktree-isolated agents
|
|
248
|
+
|
|
249
|
+
In current Claude Code (as of memesh 4.1), background agents launched
|
|
250
|
+
with `isolation: "worktree"` can **edit existing files freely** but
|
|
251
|
+
sometimes **cannot create new files** even with `mode: "acceptEdits"`.
|
|
252
|
+
The user's permission system blocks fresh `Write` calls inside the
|
|
253
|
+
isolated worktree.
|
|
254
|
+
|
|
255
|
+
Implication: if a task requires creating multiple new source files
|
|
256
|
+
(e.g., a new module with new tests), foreground that work or use
|
|
257
|
+
`isolation` other than `"worktree"`. For pure-edit tasks (refactors,
|
|
258
|
+
fixes, doc updates) and for benchmark/test tasks that only touch
|
|
259
|
+
existing files plus a `results/` directory, background dispatch works.
|
|
260
|
+
|
|
261
|
+
When in doubt: dispatch one tiny "smoke test" agent that just creates a
|
|
262
|
+
new empty file. If that succeeds, the larger task is safe to dispatch.
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## The Orchestrator's Discipline
|
|
267
|
+
|
|
268
|
+
1. **Surface results, not progress.** When an agent finishes, report
|
|
269
|
+
numbers and decisions, not "I'm running step 12 of 17". The user
|
|
270
|
+
does not need a progress bar.
|
|
271
|
+
|
|
272
|
+
2. **Review every agent's actual diff before reporting "done".** Agents
|
|
273
|
+
summarise what they intended; only the diff shows what they did. This
|
|
274
|
+
is the orchestrator's last line of defence against fabricated
|
|
275
|
+
progress.
|
|
276
|
+
|
|
277
|
+
3. **Keep agent prompts self-contained.** Brief them like a smart
|
|
278
|
+
colleague who just walked into the room. Include goal, constraints,
|
|
279
|
+
success criteria, and explicit "do NOT" lines.
|
|
280
|
+
|
|
281
|
+
4. **Do not be afraid of `isolation: "worktree"`.** Agent work in an
|
|
282
|
+
isolated copy is automatically discarded if it produces no useful
|
|
283
|
+
change, and merge-able if it does. There is no downside.
|
|
284
|
+
|
|
285
|
+
5. **Spike → land or drop, same day.** Per CONTRIBUTING.md branch
|
|
286
|
+
lifecycle discipline: a spike that lives past its verdict becomes
|
|
287
|
+
technical debt. Dispatch, review, decide, close.
|
|
288
|
+
|
|
289
|
+
6. **Bias toward delete.** A discarded agent worktree is reflog-recoverable.
|
|
290
|
+
An undeleted speculation accumulates and blocks attention.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## What This Replaces
|
|
295
|
+
|
|
296
|
+
| Old habit (single-thread Claude) | New habit (orchestrator Claude) |
|
|
297
|
+
|---|---|
|
|
298
|
+
| Read 8 files sequentially in foreground | Dispatch one agent: "read these 8 files and summarise X" |
|
|
299
|
+
| Write a migration in foreground, watch user wait | Dispatch background agent with verification criteria |
|
|
300
|
+
| Run lint/typecheck/tests one at a time | Dispatch one agent with a self-loop until all green |
|
|
301
|
+
| Wait for CI, polling every 30s | `gh run watch` once OR launch a background watcher agent |
|
|
302
|
+
| Sequential PR cleanups, one at a time | Parallel agents, one per PR, dispatched together |
|
|
303
|
+
| Long synchronous "let me read all of memesh-cloud" tour | One Explore agent with focused questions |
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Things That Are NOT Background Agent Work
|
|
308
|
+
|
|
309
|
+
Background agents are not a panacea. The following must stay foreground:
|
|
310
|
+
|
|
311
|
+
- **First-time user-facing changes** (a real human will see this; the
|
|
312
|
+
user must approve before deploy)
|
|
313
|
+
- **Anything visible on the public website** (positioning, copy, prices,
|
|
314
|
+
legal text)
|
|
315
|
+
- **Destructive ops without rollback** (rm, drop database, force-push,
|
|
316
|
+
delete remote branch — these need the user to say yes per action)
|
|
317
|
+
- **Decisions about *what* to build** (only *how* to build can be
|
|
318
|
+
delegated)
|
|
319
|
+
- **Reading the user's emotional state** — if the user is frustrated, an
|
|
320
|
+
agent will not notice; Claude must
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## The Daily Question
|
|
325
|
+
|
|
326
|
+
Every time Claude is about to do a 10+ minute task in foreground, it
|
|
327
|
+
must ask:
|
|
328
|
+
|
|
329
|
+
> "Is this task verifiable? If yes, why am I doing it synchronously
|
|
330
|
+
> instead of dispatching an agent and freeing the user?"
|
|
331
|
+
|
|
332
|
+
If the honest answer is "no good reason — habit / fear of dispatch
|
|
333
|
+
failure / wanting to look responsive" → **dispatch the agent**. The
|
|
334
|
+
user gets their time back.
|
|
335
|
+
|
|
336
|
+
The user's time is the bottleneck. Claude's time is not. Optimise for
|
|
337
|
+
the user's time.
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Checklist Before Starting Any Multi-Step Task
|
|
342
|
+
|
|
343
|
+
- [ ] Have I classified each subtask as Tier 1 / 2 / 3?
|
|
344
|
+
- [ ] For Tier 1 / 2 subtasks, have I dispatched them as background
|
|
345
|
+
agents (parallel where independent)?
|
|
346
|
+
- [ ] Did I include `mode: "acceptEdits"` so the agent can act without
|
|
347
|
+
permission prompts?
|
|
348
|
+
- [ ] For Tier 3 subtasks, am I keeping the user in the loop with
|
|
349
|
+
short, focused exchanges?
|
|
350
|
+
- [ ] Am I writing self-contained prompts that the agent can act on
|
|
351
|
+
without further clarification?
|
|
352
|
+
- [ ] Do my prompts include the agent's **own self-verification step**
|
|
353
|
+
("after writing the code, run `npm test -- --run` and report the
|
|
354
|
+
result")?
|
|
355
|
+
- [ ] Do my prompts include explicit "do NOT" boundaries (no push to
|
|
356
|
+
remote, no production-touching changes, no public-surface edits
|
|
357
|
+
without approval)?
|
|
358
|
+
- [ ] Have I told the user, in one sentence, what is running in the
|
|
359
|
+
background and what is foreground?
|
|
360
|
+
|
|
361
|
+
## Checklist Before Reporting Any Agent's Work As "Done"
|
|
362
|
+
|
|
363
|
+
- [ ] Did I run the **Verification Gate** (the four steps above), not
|
|
364
|
+
just read the agent's summary?
|
|
365
|
+
- [ ] Does `git diff --stat` actually show the changes the agent
|
|
366
|
+
claimed?
|
|
367
|
+
- [ ] Did `npm run typecheck && npm test -- --run` pass on my machine,
|
|
368
|
+
not just inside the agent's worktree?
|
|
369
|
+
- [ ] If the agent reported numbers (test count, benchmark score),
|
|
370
|
+
did I re-derive at least one of them independently?
|
|
371
|
+
- [ ] For Tier 2 work, did I run a fresh-context code-review pass
|
|
372
|
+
against the diff?
|
|
373
|
+
- [ ] If the gate failed: did I record the failure mode to memesh as
|
|
374
|
+
a lesson_learned so the next dispatch is sharper?
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## When This Skill Is Wrong For The Moment
|
|
379
|
+
|
|
380
|
+
- **Trivial single-step tasks** (read one file, answer one question, run
|
|
381
|
+
one command). Just do it.
|
|
382
|
+
- **The user is teaching/exploring with you** and explicitly wants to
|
|
383
|
+
see the work happen step by step.
|
|
384
|
+
- **The user has said "do this yourself, don't dispatch."**
|
|
385
|
+
- **High-stakes irreversible operations** where every step needs user
|
|
386
|
+
confirmation.
|
|
387
|
+
|
|
388
|
+
In these cases, announce that you are not using agent dispatch and why.
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## See Also
|
|
393
|
+
|
|
394
|
+
- The `memesh` skill (sibling) — manages the memory layer that records
|
|
395
|
+
agent_patterns, lesson_learned, and project decisions over time. Use
|
|
396
|
+
it together with this one.
|
|
397
|
+
- `CONTRIBUTING.md` Branch Lifecycle Discipline — the three-rule policy
|
|
398
|
+
on dev checkpoints, pivots, and spikes that keeps git tidy as a
|
|
399
|
+
side-effect of agentic orchestration.
|