@meshpoint/cli 1.9.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.
@@ -1,141 +1,15 @@
1
- import { KINDS, redact } from "@meshpoint/sdk";
1
+ import { consolidatePrompt, parseMerged, parseProposedWith, renderTranscript, sessionPrompt as sharedSessionPrompt } from "@meshpoint/sdk";
2
2
  import { extractRefs } from "../refs.js";
3
- import { jsonBlock } from "./runner.js";
4
- // Transcript text kept per call: the start sets the task, the end holds what was established.
5
- export const HEAD_CHARS = 20_000;
6
- export const TAIL_CHARS = 40_000;
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 [];
@@ -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
- const SYSTEM = "You are a careful assistant. Follow the instructions in the message exactly. No tools, no preamble, output only what is asked.";
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
- // The first JSON array or object in a model reply, code fences tolerated.
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.9.0",
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.3.0"
41
+ "@meshpoint/sdk": "^1.4.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.0.0",