@meshpoint/cli 1.4.1 → 1.4.2
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 +12 -3
- package/dist/import/run.js +110 -32
- package/package.json +1 -1
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>
|
|
@@ -75,14 +75,16 @@ const USAGE = `meshpoint <command>
|
|
|
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
77
|
import sessions [--since <days>] [--all-repos] [--with-turns] [--apply] [--yes]
|
|
78
|
-
[--runner claude|codex] [--model <m>] [--min-turns <n>]
|
|
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>.
|
|
86
88
|
tap claude-code | codex | cursor | antigravity [<event>] | openclaw
|
|
87
89
|
hook entry point; reads one hook payload on stdin
|
|
88
90
|
`;
|
|
@@ -273,6 +275,13 @@ async function main(argv) {
|
|
|
273
275
|
throw new Error("import supports: sessions");
|
|
274
276
|
const config = await requireConfig();
|
|
275
277
|
const repo = repoContext(process.cwd());
|
|
278
|
+
const from = flag(rest, "--from");
|
|
279
|
+
if (from !== undefined) {
|
|
280
|
+
if (!rest.includes("--apply"))
|
|
281
|
+
throw new Error("--from goes with --apply: it uploads a reviewed proposal file");
|
|
282
|
+
await withAuth(config, (c) => applyProposalFile({ config: c, file: from, current: repo ? { project: repo.project, root: repo.root } : null }));
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
276
285
|
const sinceDays = Number(flag(rest, "--since") ?? DEFAULT_SINCE_DAYS);
|
|
277
286
|
if (!Number.isInteger(sinceDays) || sinceDays < 1)
|
|
278
287
|
throw new Error("--since takes a whole number of days");
|
package/dist/import/run.js
CHANGED
|
@@ -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.
|
|
@@ -129,39 +130,22 @@ export async function importSessions(opts) {
|
|
|
129
130
|
result.branches.push(branchResult);
|
|
130
131
|
log(` ${branch}: ${kept.length} items proposed, ${dropped.length} dropped`);
|
|
131
132
|
}
|
|
133
|
+
// The saved proposal carries what --apply --from needs without the transcripts: the date of the
|
|
134
|
+
// newest source session and the harnesses it came from.
|
|
135
|
+
const endedAt = (ids) => Math.max(0, ...sessions.filter((s) => ids.includes(s.id)).map((s) => s.endedAt));
|
|
136
|
+
const harnessesOf = (ids) => [...new Set(sessions.filter((s) => ids.includes(s.id)).map((s) => s.harness))];
|
|
137
|
+
const saved = result.branches.map((b) => ({
|
|
138
|
+
branch: b.branch,
|
|
139
|
+
items: b.items.map((i) => ({ ...i, ...(endedAt(i.sessions) > 0 ? { created_at: endedAt(i.sessions) } : {}), harnesses: harnessesOf(i.sessions) })),
|
|
140
|
+
dropped: b.dropped,
|
|
141
|
+
}));
|
|
132
142
|
const file = path.join(outDir, `${safe(project)}.items.json`);
|
|
133
|
-
writeFileSync(file, `${JSON.stringify(
|
|
143
|
+
writeFileSync(file, `${JSON.stringify(saved, null, 2)}\n`, { mode: 0o600 });
|
|
134
144
|
itemsFiles.push(file);
|
|
135
145
|
if (opts.apply) {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
}
|
|
164
|
-
}
|
|
146
|
+
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 });
|
|
147
|
+
uploaded.items += out.items;
|
|
148
|
+
result.errors.push(...out.errors);
|
|
165
149
|
if (opts.withTurns) {
|
|
166
150
|
const cutoff = now() - TURNS_WINDOW_DAYS * 86_400_000;
|
|
167
151
|
for (const s of sessions.filter((x) => x.endedAt >= cutoff).slice(0, CAPTURE_SESSIONS_MAX)) {
|
|
@@ -182,6 +166,100 @@ export async function importSessions(opts) {
|
|
|
182
166
|
log("");
|
|
183
167
|
log(report);
|
|
184
168
|
log("");
|
|
185
|
-
log(opts.apply
|
|
169
|
+
log(opts.apply
|
|
170
|
+
? `uploaded ${uploaded.items} items${opts.withTurns ? ` and ${uploaded.turns} turns` : ""}; proposals saved in ${outDir}`
|
|
171
|
+
: `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 run again with --apply to distill afresh and upload.`);
|
|
186
172
|
return { results, unmapped, reportFile, itemsFiles, uploaded, cancelled: false };
|
|
187
173
|
}
|
|
174
|
+
// Writes a proposal's branches through items put semantics: refs re-read from the item text (the
|
|
175
|
+
// file may have been edited), HEAD as the commit, import provenance, dates from the sessions.
|
|
176
|
+
async function uploadProposal(u) {
|
|
177
|
+
const errors = [];
|
|
178
|
+
let count = 0;
|
|
179
|
+
const sha = u.root ? headSha(u.root) : "";
|
|
180
|
+
for (const b of u.branches) {
|
|
181
|
+
if (b.items.length === 0)
|
|
182
|
+
continue;
|
|
183
|
+
const { kept, dropped } = u.root ? prune(b.items, u.root, u.exists) : { kept: b.items.map((i) => ({ ...i, refs: i.refs ?? [] })), dropped: [] };
|
|
184
|
+
for (const d of dropped)
|
|
185
|
+
u.log(` ${b.branch}: skipped "${d.title}" (missing ${d.missing.join(", ")})`);
|
|
186
|
+
const inputs = kept.map((i) => {
|
|
187
|
+
const src = b.items.find((x) => x.title === i.title && x.body === i.body);
|
|
188
|
+
return {
|
|
189
|
+
id: randomUUID(),
|
|
190
|
+
kind: i.kind,
|
|
191
|
+
title: i.title,
|
|
192
|
+
body: i.body,
|
|
193
|
+
...(src?.created_at ? { created_at: src.created_at } : {}),
|
|
194
|
+
refs: i.refs,
|
|
195
|
+
paths: [],
|
|
196
|
+
...(sha ? { commit_sha: sha } : {}),
|
|
197
|
+
...(i.key ? { key: i.key } : {}),
|
|
198
|
+
...(i.supersedes && i.supersedes.length ? { supersedes: i.supersedes } : {}),
|
|
199
|
+
provenance: JSON.stringify({ agent: `import:${(src?.harnesses ?? []).join("+") || u.runnerName}`, user: u.config.user ?? "", sessions: (i.sessions ?? []).slice(0, 20) }),
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
if (inputs.length === 0)
|
|
203
|
+
continue;
|
|
204
|
+
try {
|
|
205
|
+
const client = new MeshpointClient({ baseUrl: u.config.baseUrl, token: u.config.token, project: u.project, branch: b.branch, ...(u.fetch ? { fetch: u.fetch } : {}) });
|
|
206
|
+
const out = await client.putItems(inputs);
|
|
207
|
+
count += out.count;
|
|
208
|
+
u.log(` ${b.branch}: uploaded ${out.count} items${out.superseded ? `, ${out.superseded} superseded` : ""}`);
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
errors.push(`${b.branch}: upload failed (${err instanceof Error ? err.message : String(err)})`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { items: count, errors };
|
|
215
|
+
}
|
|
216
|
+
function isRecord(v) {
|
|
217
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
218
|
+
}
|
|
219
|
+
// Reads a proposal file the user reviewed; anything malformed is an error, never a guess.
|
|
220
|
+
export function readProposal(file) {
|
|
221
|
+
let parsed;
|
|
222
|
+
try {
|
|
223
|
+
parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
throw new Error(`${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
227
|
+
}
|
|
228
|
+
if (!Array.isArray(parsed))
|
|
229
|
+
throw new Error(`${file}: expected an array of {branch, items}`);
|
|
230
|
+
return parsed.map((b, n) => {
|
|
231
|
+
if (!isRecord(b) || typeof b.branch !== "string" || !Array.isArray(b.items))
|
|
232
|
+
throw new Error(`${file}: entry ${n} needs branch and items`);
|
|
233
|
+
const items = b.items.map((i, m) => {
|
|
234
|
+
if (!isRecord(i) || typeof i.kind !== "string" || !KINDS.includes(i.kind) || i.kind === "status")
|
|
235
|
+
throw new Error(`${file}: ${b.branch} item ${m}: kind must be one of ${KINDS.filter((k) => k !== "status").join(", ")}`);
|
|
236
|
+
if (typeof i.title !== "string" || !i.title.trim() || typeof i.body !== "string" || !i.body.trim())
|
|
237
|
+
throw new Error(`${file}: ${b.branch} item ${m}: title and body required`);
|
|
238
|
+
return {
|
|
239
|
+
kind: i.kind,
|
|
240
|
+
title: i.title.trim(),
|
|
241
|
+
body: i.body.trim(),
|
|
242
|
+
sessions: Array.isArray(i.sessions) ? i.sessions.filter((x) => typeof x === "string") : [],
|
|
243
|
+
refs: Array.isArray(i.refs) ? i.refs.filter((x) => typeof x === "string") : [],
|
|
244
|
+
...(typeof i.key === "string" && i.key ? { key: i.key } : {}),
|
|
245
|
+
...(i.recurring === true ? { recurring: true } : {}),
|
|
246
|
+
...(Array.isArray(i.supersedes) ? { supersedes: i.supersedes.filter((x) => typeof x === "string") } : {}),
|
|
247
|
+
...(typeof i.created_at === "number" ? { created_at: i.created_at } : {}),
|
|
248
|
+
...(Array.isArray(i.harnesses) ? { harnesses: i.harnesses.filter((x) => typeof x === "string") } : {}),
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
return { branch: b.branch, items, dropped: [] };
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
// `--apply --from <file>`: upload a reviewed proposal for the current repository, exactly as edited.
|
|
255
|
+
export async function applyProposalFile(opts) {
|
|
256
|
+
if (!opts.current)
|
|
257
|
+
throw new Error("--from uploads into the current repository; run it inside the repo the proposal was made for");
|
|
258
|
+
const log = opts.log ?? ((l) => process.stderr.write(`${l}\n`));
|
|
259
|
+
const branches = readProposal(opts.file);
|
|
260
|
+
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 });
|
|
261
|
+
log(`uploaded ${out.items} items from ${opts.file}`);
|
|
262
|
+
for (const e of out.errors)
|
|
263
|
+
log(`! ${e}`);
|
|
264
|
+
return out;
|
|
265
|
+
}
|