@meshpoint/cli 1.4.1 → 1.5.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/bin.js CHANGED
@@ -24,7 +24,7 @@ import { api, ApiError, canOpenBrowser, deviceLogin, freshConfig, login } from "
24
24
  import { detectHarnesses, renderDetected } from "./detect.js";
25
25
  import { renderDoctor, runDoctor } from "./doctor.js";
26
26
  import { confirmItems, parseItemArgs, parseItems, putItems, retractItems } from "./items.js";
27
- import { DEFAULT_SINCE_DAYS, importSessions } from "./import/run.js";
27
+ import { applyProposalFile, DEFAULT_SINCE_DAYS, importSessions } from "./import/run.js";
28
28
  import { detectRunner } from "./import/runner.js";
29
29
  import { Spool } from "./spool.js";
30
30
  const USAGE = `meshpoint <command>
@@ -74,15 +74,18 @@ const USAGE = `meshpoint <command>
74
74
  stdin form takes a JSON array of {kind, title, body}
75
75
  items retract <id>... retract items on the current branch; an id may be a prefix
76
76
  items confirm <id>... confirm items on the current branch (counts toward their rank)
77
- import sessions [--since <days>] [--all-repos] [--with-turns] [--apply] [--yes]
78
- [--runner claude|codex] [--model <m>] [--min-turns <n>]
77
+ import sessions [--since <days>] [--all-repos] [--with-turns] [--apply | --propose] [--yes]
78
+ [--runner claude|codex] [--model <m>] [--min-turns <n>] [--from <items.json>]
79
79
  read this machine's harness transcripts (Claude Code, Codex, pi,
80
80
  opencode, Antigravity, Cursor) for the current repo and the last
81
81
  90 days, distill them into items with your own agent CLI, and
82
82
  write a proposal + report under ~/.local/state/meshpoint/import/.
83
83
  Nothing is uploaded without --apply; older than 90 days or
84
84
  --all-repos asks first (--yes skips). --with-turns also uploads
85
- the last 30 days of turns as sessions.
85
+ the last 30 days of turns as sessions. Review the saved
86
+ items.json, delete or edit entries, then upload exactly that
87
+ file with --apply --from <items.json>; or --propose sends the
88
+ proposal to the console, where it is reviewed and applied.
86
89
  tap claude-code | codex | cursor | antigravity [<event>] | openclaw
87
90
  hook entry point; reads one hook payload on stdin
88
91
  `;
@@ -273,6 +276,13 @@ async function main(argv) {
273
276
  throw new Error("import supports: sessions");
274
277
  const config = await requireConfig();
275
278
  const repo = repoContext(process.cwd());
279
+ const from = flag(rest, "--from");
280
+ if (from !== undefined) {
281
+ if (!rest.includes("--apply"))
282
+ throw new Error("--from goes with --apply: it uploads a reviewed proposal file");
283
+ await withAuth(config, (c) => applyProposalFile({ config: c, file: from, current: repo ? { project: repo.project, root: repo.root } : null }));
284
+ return 0;
285
+ }
276
286
  const sinceDays = Number(flag(rest, "--since") ?? DEFAULT_SINCE_DAYS);
277
287
  if (!Number.isInteger(sinceDays) || sinceDays < 1)
278
288
  throw new Error("--since takes a whole number of days");
@@ -292,6 +302,7 @@ async function main(argv) {
292
302
  allRepos: rest.includes("--all-repos"),
293
303
  withTurns: rest.includes("--with-turns"),
294
304
  apply: rest.includes("--apply"),
305
+ propose: rest.includes("--propose"),
295
306
  yes: rest.includes("--yes"),
296
307
  minTurns,
297
308
  runner,
@@ -1,11 +1,12 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { createInterface } from "node:readline";
5
5
  import { MeshpointClient } from "@meshpoint/sdk";
6
6
  import { headSha } from "../refs.js";
7
7
  import { discoverSessions } from "./discover.js";
8
8
  import { consolidate, distillSession, prune } from "./distill.js";
9
+ import { KINDS } from "@meshpoint/sdk";
9
10
  import { renderReport } from "./report.js";
10
11
  // `meshpoint import sessions`: the whole flow, dry run by default. Nothing leaves the machine
11
12
  // without --apply; anything older than the default window or outside the current repo asks first.
@@ -51,7 +52,7 @@ export async function importSessions(opts) {
51
52
  throw new Error("not inside a git repo with an origin remote; pass --all-repos to import every repository");
52
53
  selected = selected.filter((s) => s.project === opts.current.project);
53
54
  }
54
- const empty = { results: [], unmapped, reportFile: "", itemsFiles: [], uploaded: { items: 0, turns: 0 }, cancelled: false };
55
+ const empty = { results: [], unmapped, reportFile: "", itemsFiles: [], uploaded: { items: 0, turns: 0 }, proposals: [], cancelled: false };
55
56
  if (selected.length === 0) {
56
57
  log(`no sessions found${opts.allRepos ? "" : ` for ${opts.current?.project}`} in the last ${opts.sinceDays} days (${inWindow.length} in the window, ${unmapped.length} unmapped)`);
57
58
  return empty;
@@ -76,6 +77,7 @@ export async function importSessions(opts) {
76
77
  const results = [];
77
78
  const itemsFiles = [];
78
79
  const uploaded = { items: 0, turns: 0 };
80
+ const sent = [];
79
81
  const outDir = path.join(opts.stateDir, "import");
80
82
  mkdirSync(outDir, { recursive: true, mode: 0o700 });
81
83
  for (const [project, sessions] of byProject) {
@@ -129,39 +131,39 @@ export async function importSessions(opts) {
129
131
  result.branches.push(branchResult);
130
132
  log(` ${branch}: ${kept.length} items proposed, ${dropped.length} dropped`);
131
133
  }
134
+ // The saved proposal carries what --apply --from needs without the transcripts: the date of the
135
+ // newest source session and the harnesses it came from.
136
+ const endedAt = (ids) => Math.max(0, ...sessions.filter((s) => ids.includes(s.id)).map((s) => s.endedAt));
137
+ const harnessesOf = (ids) => [...new Set(sessions.filter((s) => ids.includes(s.id)).map((s) => s.harness))];
138
+ const saved = result.branches.map((b) => ({
139
+ branch: b.branch,
140
+ items: b.items.map((i) => ({ ...i, ...(endedAt(i.sessions) > 0 ? { created_at: endedAt(i.sessions) } : {}), harnesses: harnessesOf(i.sessions) })),
141
+ dropped: b.dropped,
142
+ }));
132
143
  const file = path.join(outDir, `${safe(project)}.items.json`);
133
- writeFileSync(file, `${JSON.stringify(result.branches.map((b) => ({ branch: b.branch, items: b.items, dropped: b.dropped })), null, 2)}\n`, { mode: 0o600 });
144
+ writeFileSync(file, `${JSON.stringify(saved, null, 2)}\n`, { mode: 0o600 });
134
145
  itemsFiles.push(file);
135
- if (opts.apply) {
136
- const sha = root ? headSha(root) : "";
137
- for (const b of result.branches) {
138
- if (b.items.length === 0)
139
- continue;
140
- // Items are dated by the newest session that produced them, so ranking and decay see the
141
- // real age rather than the import time.
142
- const endedAt = (ids) => Math.max(0, ...sessions.filter((s) => ids.includes(s.id)).map((s) => s.endedAt));
143
- const inputs = b.items.map((i) => ({
144
- id: randomUUID(),
145
- kind: i.kind,
146
- title: i.title,
147
- body: i.body,
148
- ...(endedAt(i.sessions) > 0 ? { created_at: endedAt(i.sessions) } : {}),
149
- refs: i.refs,
150
- paths: [],
151
- ...(sha ? { commit_sha: sha } : {}),
152
- ...(i.key ? { key: i.key } : {}),
153
- ...(i.supersedes && i.supersedes.length ? { supersedes: i.supersedes } : {}),
154
- provenance: JSON.stringify({ agent: `import:${[...new Set(sessions.filter((s) => i.sessions.includes(s.id)).map((s) => s.harness))].join("+") || opts.runner.name}`, user: opts.config.user ?? "", sessions: i.sessions.slice(0, 20) }),
155
- }));
156
- try {
157
- const out = await client(b.branch).putItems(inputs);
158
- uploaded.items += out.count;
159
- log(` ${b.branch}: uploaded ${out.count} items${out.superseded ? `, ${out.superseded} superseded` : ""}`);
160
- }
161
- catch (err) {
162
- result.errors.push(`${b.branch}: upload failed (${err instanceof Error ? err.message : String(err)})`);
163
- }
146
+ if (opts.propose) {
147
+ try {
148
+ const res = await (opts.fetch ?? fetch)(`${opts.config.baseUrl.replace(/\/+$/, "")}/v1/imports`, {
149
+ method: "POST",
150
+ headers: { authorization: `Bearer ${opts.config.token}`, "content-type": "application/json" },
151
+ body: JSON.stringify({ project, branches: saved, report: renderReport([result], [], {}).slice(0, 60_000), commit_sha: root ? headSha(root) : "" }),
152
+ });
153
+ const data = (await res.json());
154
+ if (!res.ok || !data.id)
155
+ throw new Error(data.error ?? `HTTP ${res.status}`);
156
+ sent.push({ project, id: data.id, url: data.url ?? "" });
157
+ log(` proposal ${data.id} sent for review${data.url ? `: ${data.url}` : ""}`);
158
+ }
159
+ catch (err) {
160
+ result.errors.push(`proposal upload failed (${err instanceof Error ? err.message : String(err)})`);
164
161
  }
162
+ }
163
+ if (opts.apply) {
164
+ const out = await uploadProposal({ project, root, branches: saved, config: opts.config, runnerName: opts.runner.name, ...(opts.fetch ? { fetch: opts.fetch } : {}), ...(opts.exists ? { exists: opts.exists } : {}), log });
165
+ uploaded.items += out.items;
166
+ result.errors.push(...out.errors);
165
167
  if (opts.withTurns) {
166
168
  const cutoff = now() - TURNS_WINDOW_DAYS * 86_400_000;
167
169
  for (const s of sessions.filter((x) => x.endedAt >= cutoff).slice(0, CAPTURE_SESSIONS_MAX)) {
@@ -182,6 +184,103 @@ export async function importSessions(opts) {
182
184
  log("");
183
185
  log(report);
184
186
  log("");
185
- log(opts.apply ? `uploaded ${uploaded.items} items${opts.withTurns ? ` and ${uploaded.turns} turns` : ""}; proposals saved in ${outDir}` : `dry run: proposals saved in ${outDir}; run again with --apply to upload`);
186
- return { results, unmapped, reportFile, itemsFiles, uploaded, cancelled: false };
187
+ if (opts.apply)
188
+ log(`uploaded ${uploaded.items} items${opts.withTurns ? ` and ${uploaded.turns} turns` : ""}; proposals saved in ${outDir}`);
189
+ else if (opts.propose)
190
+ log(`sent for review in the console${sent.length ? `: ${sent.map((p) => p.url || p.id).join(", ")}` : ""}. Nothing is written until someone applies it there.`);
191
+ else
192
+ log(`dry run, nothing uploaded. Review the proposal: ${itemsFiles.join(", ")}\nDelete or edit entries there, then upload exactly that file with: meshpoint import sessions --apply --from <file>\nOr send it to the console for review with --propose, or run again with --apply to distill afresh and upload.`);
193
+ return { results, unmapped, reportFile, itemsFiles, uploaded, proposals: sent, cancelled: false };
194
+ }
195
+ // Writes a proposal's branches through items put semantics: refs re-read from the item text (the
196
+ // file may have been edited), HEAD as the commit, import provenance, dates from the sessions.
197
+ async function uploadProposal(u) {
198
+ const errors = [];
199
+ let count = 0;
200
+ const sha = u.root ? headSha(u.root) : "";
201
+ for (const b of u.branches) {
202
+ if (b.items.length === 0)
203
+ continue;
204
+ const { kept, dropped } = u.root ? prune(b.items, u.root, u.exists) : { kept: b.items.map((i) => ({ ...i, refs: i.refs ?? [] })), dropped: [] };
205
+ for (const d of dropped)
206
+ u.log(` ${b.branch}: skipped "${d.title}" (missing ${d.missing.join(", ")})`);
207
+ const inputs = kept.map((i) => {
208
+ const src = b.items.find((x) => x.title === i.title && x.body === i.body);
209
+ return {
210
+ id: randomUUID(),
211
+ kind: i.kind,
212
+ title: i.title,
213
+ body: i.body,
214
+ ...(src?.created_at ? { created_at: src.created_at } : {}),
215
+ refs: i.refs,
216
+ paths: [],
217
+ ...(sha ? { commit_sha: sha } : {}),
218
+ ...(i.key ? { key: i.key } : {}),
219
+ ...(i.supersedes && i.supersedes.length ? { supersedes: i.supersedes } : {}),
220
+ provenance: JSON.stringify({ agent: `import:${(src?.harnesses ?? []).join("+") || u.runnerName}`, user: u.config.user ?? "", sessions: (i.sessions ?? []).slice(0, 20) }),
221
+ };
222
+ });
223
+ if (inputs.length === 0)
224
+ continue;
225
+ try {
226
+ const client = new MeshpointClient({ baseUrl: u.config.baseUrl, token: u.config.token, project: u.project, branch: b.branch, ...(u.fetch ? { fetch: u.fetch } : {}) });
227
+ const out = await client.putItems(inputs);
228
+ count += out.count;
229
+ u.log(` ${b.branch}: uploaded ${out.count} items${out.superseded ? `, ${out.superseded} superseded` : ""}`);
230
+ }
231
+ catch (err) {
232
+ errors.push(`${b.branch}: upload failed (${err instanceof Error ? err.message : String(err)})`);
233
+ }
234
+ }
235
+ return { items: count, errors };
236
+ }
237
+ function isRecord(v) {
238
+ return typeof v === "object" && v !== null && !Array.isArray(v);
239
+ }
240
+ // Reads a proposal file the user reviewed; anything malformed is an error, never a guess.
241
+ export function readProposal(file) {
242
+ let parsed;
243
+ try {
244
+ parsed = JSON.parse(readFileSync(file, "utf8"));
245
+ }
246
+ catch (err) {
247
+ throw new Error(`${file}: ${err instanceof Error ? err.message : String(err)}`);
248
+ }
249
+ if (!Array.isArray(parsed))
250
+ throw new Error(`${file}: expected an array of {branch, items}`);
251
+ return parsed.map((b, n) => {
252
+ if (!isRecord(b) || typeof b.branch !== "string" || !Array.isArray(b.items))
253
+ throw new Error(`${file}: entry ${n} needs branch and items`);
254
+ const items = b.items.map((i, m) => {
255
+ if (!isRecord(i) || typeof i.kind !== "string" || !KINDS.includes(i.kind) || i.kind === "status")
256
+ throw new Error(`${file}: ${b.branch} item ${m}: kind must be one of ${KINDS.filter((k) => k !== "status").join(", ")}`);
257
+ if (typeof i.title !== "string" || !i.title.trim() || typeof i.body !== "string" || !i.body.trim())
258
+ throw new Error(`${file}: ${b.branch} item ${m}: title and body required`);
259
+ return {
260
+ kind: i.kind,
261
+ title: i.title.trim(),
262
+ body: i.body.trim(),
263
+ sessions: Array.isArray(i.sessions) ? i.sessions.filter((x) => typeof x === "string") : [],
264
+ refs: Array.isArray(i.refs) ? i.refs.filter((x) => typeof x === "string") : [],
265
+ ...(typeof i.key === "string" && i.key ? { key: i.key } : {}),
266
+ ...(i.recurring === true ? { recurring: true } : {}),
267
+ ...(Array.isArray(i.supersedes) ? { supersedes: i.supersedes.filter((x) => typeof x === "string") } : {}),
268
+ ...(typeof i.created_at === "number" ? { created_at: i.created_at } : {}),
269
+ ...(Array.isArray(i.harnesses) ? { harnesses: i.harnesses.filter((x) => typeof x === "string") } : {}),
270
+ };
271
+ });
272
+ return { branch: b.branch, items, dropped: [] };
273
+ });
274
+ }
275
+ // `--apply --from <file>`: upload a reviewed proposal for the current repository, exactly as edited.
276
+ export async function applyProposalFile(opts) {
277
+ if (!opts.current)
278
+ throw new Error("--from uploads into the current repository; run it inside the repo the proposal was made for");
279
+ const log = opts.log ?? ((l) => process.stderr.write(`${l}\n`));
280
+ const branches = readProposal(opts.file);
281
+ const out = await uploadProposal({ project: opts.current.project, root: opts.current.root, branches, config: opts.config, runnerName: "file", ...(opts.fetch ? { fetch: opts.fetch } : {}), ...(opts.exists ? { exists: opts.exists } : {}), log });
282
+ log(`uploaded ${out.items} items from ${opts.file}`);
283
+ for (const e of out.errors)
284
+ log(`! ${e}`);
285
+ return out;
187
286
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshpoint/cli",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Meshpoint CLI and harness adapters: shared agent memory for developer teams",
5
5
  "keywords": [
6
6
  "meshpoint",