@meshpoint/cli 1.8.0 → 1.10.0
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/dist/agents-md.js +19 -4
- package/dist/bin.js +21 -1
- package/dist/import/distill.js +6 -132
- package/dist/import/runner.js +2 -12
- package/package.json +2 -2
package/dist/agents-md.js
CHANGED
|
@@ -8,6 +8,9 @@ import { isExpired } from "@meshpoint/sdk";
|
|
|
8
8
|
export const AGENTS_FILE = "AGENTS.md";
|
|
9
9
|
export const BLOCK_START = "<!-- meshpoint:conventions start -->";
|
|
10
10
|
export const BLOCK_END = "<!-- meshpoint:conventions end -->";
|
|
11
|
+
// The session-start context for a job that has no hook (CI, cloud agents): written per checkout, not committed.
|
|
12
|
+
export const CONTEXT_START = "<!-- meshpoint:context start -->";
|
|
13
|
+
export const CONTEXT_END = "<!-- meshpoint:context end -->";
|
|
11
14
|
const ID_TAG = /<!--\s*mp:([A-Za-z0-9_-]{8,})\s*-->/g;
|
|
12
15
|
const CLAUDE_IMPORT = /^@(?:\.\/)?AGENTS\.md\s*$/m;
|
|
13
16
|
// Harnesses that read AGENTS.md at the repository root on their own. Claude Code reads CLAUDE.md
|
|
@@ -35,13 +38,13 @@ export function renderBlock(items) {
|
|
|
35
38
|
return lines.join("\n");
|
|
36
39
|
}
|
|
37
40
|
// Replaces the block in place, appends it to a file without one, or starts a new file.
|
|
38
|
-
export function applyBlock(existing, block) {
|
|
41
|
+
export function applyBlock(existing, block, markers = [BLOCK_START, BLOCK_END]) {
|
|
39
42
|
if (existing === null)
|
|
40
43
|
return `# Agent instructions\n\n${block}\n`;
|
|
41
|
-
const start = existing.indexOf(
|
|
42
|
-
const end = existing.indexOf(
|
|
44
|
+
const start = existing.indexOf(markers[0]);
|
|
45
|
+
const end = existing.indexOf(markers[1], start);
|
|
43
46
|
if (start >= 0 && end > start)
|
|
44
|
-
return `${existing.slice(0, start)}${block}${existing.slice(end +
|
|
47
|
+
return `${existing.slice(0, start)}${block}${existing.slice(end + markers[1].length)}`;
|
|
45
48
|
const head = existing.replace(/\s+$/, "");
|
|
46
49
|
return `${head ? `${head}\n\n` : ""}${block}\n`;
|
|
47
50
|
}
|
|
@@ -59,6 +62,18 @@ export function exportConventions(items, root, opts = {}) {
|
|
|
59
62
|
writeFileSync(abs, next);
|
|
60
63
|
return { file: rel, created: existing === null, changed, count: conventions.length };
|
|
61
64
|
}
|
|
65
|
+
// The inject text as a block for a checkout without hooks. Replaces an earlier block, leaves the
|
|
66
|
+
// conventions block alone, and answers whether the file changed.
|
|
67
|
+
export function writeContext(text, root, file = AGENTS_FILE) {
|
|
68
|
+
const abs = path.join(root, file);
|
|
69
|
+
const existing = read(abs);
|
|
70
|
+
const body = text.trim() || "No team knowledge for this branch yet.";
|
|
71
|
+
const next = applyBlock(existing, `${CONTEXT_START}\n${body}\n${CONTEXT_END}`, [CONTEXT_START, CONTEXT_END]);
|
|
72
|
+
const changed = next !== existing;
|
|
73
|
+
if (changed)
|
|
74
|
+
writeFileSync(abs, next);
|
|
75
|
+
return { file, created: existing === null, changed };
|
|
76
|
+
}
|
|
62
77
|
export function hasBlock(root, file = AGENTS_FILE) {
|
|
63
78
|
const text = read(path.join(root, file));
|
|
64
79
|
return text !== null && text.includes(BLOCK_START) && text.includes(BLOCK_END);
|
package/dist/bin.js
CHANGED
|
@@ -27,7 +27,7 @@ import { renderDoctor, runDoctor } from "./doctor.js";
|
|
|
27
27
|
import { branchItems, confirmItems, parseItemArgs, parseItems, putItems, retractItems } from "./items.js";
|
|
28
28
|
import { importOffer } from "./import/offer.js";
|
|
29
29
|
import { applyProposalFile, DEFAULT_SINCE_DAYS, importSessions } from "./import/run.js";
|
|
30
|
-
import { AGENTS_FILE, exportConventions, hasBlock } from "./agents-md.js";
|
|
30
|
+
import { AGENTS_FILE, exportConventions, hasBlock, writeContext } from "./agents-md.js";
|
|
31
31
|
import { connectMcp } from "./mcp/connect.js";
|
|
32
32
|
import { McpServer } from "./mcp/server.js";
|
|
33
33
|
import { MCP_INSTRUCTIONS, MCP_SERVER_NAME, meshpointTools } from "./mcp/tools.js";
|
|
@@ -104,6 +104,9 @@ const USAGE = `meshpoint <command>
|
|
|
104
104
|
stdin form takes a JSON array of {kind, title, body}
|
|
105
105
|
items retract <id>... retract items on the current branch; an id may be a prefix
|
|
106
106
|
items confirm <id>... confirm items on the current branch (counts toward their rank)
|
|
107
|
+
context write [--file <path>] write the session-start context (team knowledge, verification
|
|
108
|
+
marks, teammates) as a marked block in AGENTS.md for a checkout
|
|
109
|
+
without hooks: CI jobs and cloud agents. Not for committing
|
|
107
110
|
export agents [--file <path>] [--check] write the branch's conventions as a marked block in AGENTS.md
|
|
108
111
|
(or --file, repo-relative) for agents that read that file
|
|
109
112
|
without a hook; the block is the only part touched, rerun to
|
|
@@ -340,6 +343,23 @@ async function main(argv) {
|
|
|
340
343
|
await server.serve(process.stdin, process.stdout);
|
|
341
344
|
return 0;
|
|
342
345
|
}
|
|
346
|
+
case "context": {
|
|
347
|
+
if (rest[0] !== "write")
|
|
348
|
+
throw new Error("context supports: write");
|
|
349
|
+
const config = await requireConfig();
|
|
350
|
+
const repo = repoContext(process.cwd());
|
|
351
|
+
if (!repo)
|
|
352
|
+
throw new Error("not inside a git repo with an origin remote");
|
|
353
|
+
const file = flag(rest, "--file");
|
|
354
|
+
if (file !== undefined && (path.isAbsolute(file) || file.split(/[\\/]/).includes("..")))
|
|
355
|
+
throw new Error("--file is a path inside the repository");
|
|
356
|
+
const tap = new Tap({ config, repo, session: `context-${randomUUID()}`, spool: new Spool(spoolDir()), checkpoints: new Checkpoints(stateDir()), local: localChecks(repo.root), refresh: () => freshConfig(config, { force: true }).catch(() => null) });
|
|
357
|
+
const text = await tap.start();
|
|
358
|
+
const out = writeContext(text, repo.root, file);
|
|
359
|
+
const items = (text.match(/^- /gm) ?? []).length;
|
|
360
|
+
console.log(`${out.created ? "created" : out.changed ? "updated" : "unchanged"} ${out.file}: context for ${repo.project} @ ${repo.branch}, ${items} line${items === 1 ? "" : "s"}. Not for committing.`);
|
|
361
|
+
return 0;
|
|
362
|
+
}
|
|
343
363
|
case "export": {
|
|
344
364
|
if (rest[0] !== "agents")
|
|
345
365
|
throw new Error("export supports: agents");
|
package/dist/import/distill.js
CHANGED
|
@@ -1,141 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { consolidatePrompt, parseMerged, parseProposedWith, renderTranscript, sessionPrompt as sharedSessionPrompt } from "@meshpoint/sdk";
|
|
2
2
|
import { extractRefs } from "../refs.js";
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export const SESSION_ITEMS_MAX = 20;
|
|
8
|
-
export const BRANCH_ITEMS_MAX = 60;
|
|
9
|
-
export const EVIDENCE_CHARS = 200;
|
|
10
|
-
const KEY_RE = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
11
|
-
const RULES = `Write what a teammate's agent would need to resume work in this repository correctly, as items.
|
|
12
|
-
Each item is {"kind", "title", "body", "evidence"}. kind is one of: decision (a choice made and why), gotcha (something that bit or will bite), convention (how things are done here), fact (a stable truth about the code or environment), status (where the work stands), todo (an agreed next step).
|
|
13
|
-
title is one line. body is one to three sentences, concrete: file names by repo-relative path, commands, values, reasons.
|
|
14
|
-
evidence is a quote of at most ${EVIDENCE_CHARS} characters copied verbatim from the transcript that supports the item; an item without a real quote is discarded.
|
|
15
|
-
Rules: only what this session established, never invent; prefer durable knowledge over moment-to-moment detail; at most one status; no secrets, tokens or credentials; skip chit-chat and anything true of every project.`;
|
|
16
|
-
export function renderTranscript(entries) {
|
|
17
|
-
const lines = entries.map((e) => `[${e.role}] ${e.text}${e.paths.length ? `\n(files: ${e.paths.slice(0, 8).join(", ")})` : ""}`);
|
|
18
|
-
const text = lines.join("\n\n");
|
|
19
|
-
if (text.length <= HEAD_CHARS + TAIL_CHARS)
|
|
20
|
-
return text;
|
|
21
|
-
return `${text.slice(0, HEAD_CHARS)}\n\n[... ${text.length - HEAD_CHARS - TAIL_CHARS} characters omitted ...]\n\n${text.slice(-TAIL_CHARS)}`;
|
|
22
|
-
}
|
|
3
|
+
// Turning transcripts into items with the user's own model: one call per session with the
|
|
4
|
+
// checkpoint skill's rules, then one call per branch that merges what the sessions proposed.
|
|
5
|
+
// The prompts and parsers live in @meshpoint/sdk, shared with the platform's Distill action.
|
|
6
|
+
export { BRANCH_ITEMS_MAX, consolidatePrompt, EVIDENCE_CHARS, HEAD_CHARS, parseMerged, parseProposed, parseProposedWith, renderTranscript, SESSION_ITEMS_MAX, TAIL_CHARS } from "@meshpoint/sdk";
|
|
23
7
|
export function sessionPrompt(s) {
|
|
24
|
-
return
|
|
25
|
-
RULES,
|
|
26
|
-
"",
|
|
27
|
-
`Harness: ${s.harness}. Repository directory: ${s.cwd ?? "unknown"}. Branch: ${s.branch ?? "unknown"}. Session started ${new Date(s.startedAt).toISOString()}.`,
|
|
28
|
-
"",
|
|
29
|
-
`Output only a JSON array of at most ${SESSION_ITEMS_MAX} items. Output [] if the session established nothing worth keeping.`,
|
|
30
|
-
"",
|
|
31
|
-
"Transcript:",
|
|
32
|
-
renderTranscript(s.entries),
|
|
33
|
-
].join("\n");
|
|
34
|
-
}
|
|
35
|
-
function isRecord(v) {
|
|
36
|
-
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
37
|
-
}
|
|
38
|
-
const squash = (s) => s.replace(/\s+/g, " ").trim();
|
|
39
|
-
// Items whose quote is not in the transcript are unsupported and left out.
|
|
40
|
-
export function parseProposedWith(raw, session, transcript) {
|
|
41
|
-
let parsed;
|
|
42
|
-
try {
|
|
43
|
-
parsed = jsonBlock(raw);
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return { items: [], unsupported: 0 };
|
|
47
|
-
}
|
|
48
|
-
if (!Array.isArray(parsed))
|
|
49
|
-
return { items: [], unsupported: 0 };
|
|
50
|
-
const haystack = transcript === undefined ? null : squash(transcript);
|
|
51
|
-
const items = [];
|
|
52
|
-
let unsupported = 0;
|
|
53
|
-
for (const v of parsed) {
|
|
54
|
-
if (!isRecord(v) || typeof v.kind !== "string" || !KINDS.includes(v.kind))
|
|
55
|
-
continue;
|
|
56
|
-
if (typeof v.title !== "string" || !v.title.trim() || typeof v.body !== "string" || !v.body.trim())
|
|
57
|
-
continue;
|
|
58
|
-
const quote = typeof v.evidence === "string" ? squash(v.evidence).slice(0, EVIDENCE_CHARS) : "";
|
|
59
|
-
if (haystack !== null && (!quote || !haystack.includes(quote))) {
|
|
60
|
-
unsupported++;
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const item = { kind: v.kind, title: redact(v.title.trim().slice(0, 200)), body: redact(v.body.trim().slice(0, 2000)), sessions: [session] };
|
|
64
|
-
if (typeof v.key === "string" && KEY_RE.test(v.key))
|
|
65
|
-
item.key = v.key;
|
|
66
|
-
if (v.recurring === true)
|
|
67
|
-
item.recurring = true;
|
|
68
|
-
if (quote)
|
|
69
|
-
item.evidence = redact(quote);
|
|
70
|
-
items.push(item);
|
|
71
|
-
if (items.length >= SESSION_ITEMS_MAX)
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
return { items, unsupported };
|
|
75
|
-
}
|
|
76
|
-
export function parseProposed(raw, session, transcript) {
|
|
77
|
-
return parseProposedWith(raw, session, transcript).items;
|
|
8
|
+
return sharedSessionPrompt({ harness: s.harness, cwd: s.cwd, branch: s.branch, startedAt: s.startedAt }, renderTranscript(s.entries));
|
|
78
9
|
}
|
|
79
10
|
export async function distillSession(runner, s) {
|
|
80
11
|
return parseProposedWith(await runner.run(sessionPrompt(s)), s.id, renderTranscript(s.entries));
|
|
81
12
|
}
|
|
82
|
-
export function consolidatePrompt(items, live) {
|
|
83
|
-
return [
|
|
84
|
-
"You merge knowledge items proposed from several coding sessions on one repository branch into one list.",
|
|
85
|
-
"Input items carry the ids of the sessions that produced them. Rules:",
|
|
86
|
-
"- Merge duplicates and near-duplicates into one item; keep every session id in \"sessions\".",
|
|
87
|
-
"- When a fact or decision changed across sessions, keep only the newest statement (later session ids are newer in the list).",
|
|
88
|
-
"- Give conventions a short stable \"key\" (letters, digits, . _ : / -) such as test-runner or deploy-target.",
|
|
89
|
-
"- Mark a gotcha \"recurring\": true when the same problem appears in two or more sessions.",
|
|
90
|
-
"- Drop every status item (they describe a past moment) and todos that read as finished.",
|
|
91
|
-
"- Keep \"evidence\" (a verbatim transcript quote) from the newest source item that was merged; never write new evidence.",
|
|
92
|
-
"- Items already live on the branch are listed; do not repeat them, and when a proposed item supersedes a live one, add \"supersedes\": [\"<live id>\"].",
|
|
93
|
-
`- Output only a JSON array of at most ${BRANCH_ITEMS_MAX} items: {"kind","title","body","evidence"?,"key"?,"recurring"?,"supersedes"?,"sessions"}.`,
|
|
94
|
-
"",
|
|
95
|
-
`Live items on the branch:\n${JSON.stringify(live.map((i) => ({ id: i.id, kind: i.kind, title: i.title, body: i.body })))}`,
|
|
96
|
-
"",
|
|
97
|
-
`Proposed items:\n${JSON.stringify(items)}`,
|
|
98
|
-
].join("\n");
|
|
99
|
-
}
|
|
100
|
-
// A status describes a past moment; an import never writes one, since a new status supersedes the
|
|
101
|
-
// branch's current one on write.
|
|
102
|
-
const IMPORT_KINDS = KINDS.filter((k) => k !== "status");
|
|
103
|
-
export function parseMerged(raw, fallback) {
|
|
104
|
-
let parsed;
|
|
105
|
-
try {
|
|
106
|
-
parsed = jsonBlock(raw);
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
return fallback.filter((i) => i.kind !== "status");
|
|
110
|
-
}
|
|
111
|
-
if (!Array.isArray(parsed))
|
|
112
|
-
return fallback.filter((i) => i.kind !== "status");
|
|
113
|
-
const out = [];
|
|
114
|
-
for (const v of parsed) {
|
|
115
|
-
if (!isRecord(v) || typeof v.kind !== "string" || !IMPORT_KINDS.includes(v.kind))
|
|
116
|
-
continue;
|
|
117
|
-
if (typeof v.title !== "string" || !v.title.trim() || typeof v.body !== "string" || !v.body.trim())
|
|
118
|
-
continue;
|
|
119
|
-
const item = {
|
|
120
|
-
kind: v.kind,
|
|
121
|
-
title: redact(v.title.trim().slice(0, 200)),
|
|
122
|
-
body: redact(v.body.trim().slice(0, 2000)),
|
|
123
|
-
sessions: Array.isArray(v.sessions) ? v.sessions.filter((x) => typeof x === "string").slice(0, 50) : [],
|
|
124
|
-
};
|
|
125
|
-
if (typeof v.key === "string" && KEY_RE.test(v.key))
|
|
126
|
-
item.key = v.key;
|
|
127
|
-
if (v.recurring === true)
|
|
128
|
-
item.recurring = true;
|
|
129
|
-
if (typeof v.evidence === "string" && v.evidence.trim())
|
|
130
|
-
item.evidence = redact(squash(v.evidence).slice(0, EVIDENCE_CHARS));
|
|
131
|
-
if (Array.isArray(v.supersedes))
|
|
132
|
-
item.supersedes = v.supersedes.filter((x) => typeof x === "string").slice(0, 20);
|
|
133
|
-
out.push(item);
|
|
134
|
-
if (out.length >= BRANCH_ITEMS_MAX)
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
return out;
|
|
138
|
-
}
|
|
139
13
|
export async function consolidate(runner, items, live) {
|
|
140
14
|
if (items.length === 0)
|
|
141
15
|
return [];
|
package/dist/import/runner.js
CHANGED
|
@@ -2,7 +2,7 @@ import { execFileSync, spawnSync } from "node:child_process";
|
|
|
2
2
|
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
|
|
5
|
+
import { DISTILL_SYSTEM as SYSTEM } from "@meshpoint/sdk";
|
|
6
6
|
const TIMEOUT_MS = 10 * 60_000;
|
|
7
7
|
function onPath(bin, env) {
|
|
8
8
|
for (const dir of (env.PATH ?? "").split(path.delimiter)) {
|
|
@@ -77,14 +77,4 @@ export function detectRunner(env, prefer, model) {
|
|
|
77
77
|
}
|
|
78
78
|
return null;
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
export function jsonBlock(text) {
|
|
82
|
-
let s = text.trim();
|
|
83
|
-
if (s.startsWith("```")) {
|
|
84
|
-
s = s.includes("\n") ? s.slice(s.indexOf("\n") + 1) : s.slice(3);
|
|
85
|
-
s = s.lastIndexOf("```") >= 0 ? s.slice(0, s.lastIndexOf("```")) : s;
|
|
86
|
-
}
|
|
87
|
-
const starts = [s.indexOf("["), s.indexOf("{")].filter((i) => i >= 0);
|
|
88
|
-
const start = starts.length ? Math.min(...starts) : 0;
|
|
89
|
-
return JSON.parse(s.slice(start));
|
|
90
|
-
}
|
|
80
|
+
export { jsonBlock } from "@meshpoint/sdk";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshpoint/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Meshpoint CLI and harness adapters: shared agent memory for developer teams",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"meshpoint",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"prepublishOnly": "npm run check && npm run build"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@meshpoint/sdk": "^1.
|
|
41
|
+
"@meshpoint/sdk": "^1.4.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^22.0.0",
|