@networkbase/cli 2.2.1 → 2.2.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.
@@ -60,20 +60,35 @@ export async function changeStatus(ctx) {
60
60
  const { root } = ctx.requireRoot();
61
61
  const id = ctx.positionals[0] ? await fullId(ctx, ctx.positionals[0]) : currentChange(root);
62
62
  if (!id) {
63
- ctx.out.result("nb.change.status/1", { changeSet: null }, () => ["No open change set in this folder.", ctx.out.c.muted(" nb change start \"what you're doing\" opens one; nb change list shows the workspace's.")]);
63
+ // Nothing open: the last applied ones, so "undo what you applied" is one step (found in the D22 agent run).
64
+ const recent = /** @type {any} */ (await ctx.api.get(`/api/v1/workspaces/${enc(ctx.requireWorkspace())}/change-sets`, { query: { status: "applied", limit: 3 } }).catch(() => ({ changeSets: [] })));
65
+ const applied = (recent.changeSets ?? []).slice(0, 3).map((/** @type {any} */ s) => ({ id: s.id, title: s.title, appliedAt: s.appliedAt ?? s.updatedAt, files: s.filesAdded + s.filesChanged + s.filesDeleted + s.filesRenamed }));
66
+ ctx.out.result("nb.change.status/1", { changeSet: null, recentlyApplied: applied }, (d) => [
67
+ "No open change set in this folder.",
68
+ ...d.recentlyApplied.map((/** @type {any} */ a) => ` applied ${ctx.out.c.muted(a.id.slice(0, 8))} ${safe(a.title)} ${ctx.out.c.muted(`· ${plural(a.files, "file")} · undo: nb change undo ${a.id.slice(0, 8)}`)}`),
69
+ ctx.out.c.muted(" nb change start \"what you're doing\" opens one; nb change list shows the workspace's."),
70
+ ]);
64
71
  return EXIT.ok;
65
72
  }
66
- const capture = ctx.flags["no-send"] ? null : await captureNow(ctx, id);
73
+ // Sending the latest saves is best effort: a failed upload (storage down, signed out) still shows the set, with
74
+ // what's waiting (found in the D22 agent run, where a storage error made status itself fail).
75
+ /** @type {Awaited<ReturnType<typeof captureNow>> | null} */
76
+ let capture = null;
77
+ let sendError = null;
78
+ if (!ctx.flags["no-send"]) {
79
+ try { capture = await captureNow(ctx, id); } catch (error) { sendError = error instanceof Error ? error.message : String(error); }
80
+ }
67
81
  const view = /** @type {any} */ (await ctx.api.get(`/api/v1/change-sets/${enc(id)}`));
68
82
  const set = view.changeSet;
69
83
  const conflicts = view.items.filter((/** @type {any} */ i) => i.state === "conflict");
70
84
  const pending = readJournal(root, id).missing.length;
71
85
  const held = Object.values(readJournal(root, id).held ?? {});
72
86
  const comments = (view.comments ?? []).filter((/** @type {any} */ c) => !c.resolvedAt);
73
- ctx.out.result("nb.change.status/1", { changeSet: set, items: view.items, uploadsPending: pending, held, conflicts, comments, skipped: capture?.skipped ?? [] }, (d) => [
87
+ ctx.out.result("nb.change.status/1", { changeSet: set, items: view.items, uploadsPending: pending, held, conflicts, comments, skipped: capture?.skipped ?? [], ...(sendError ? { sendError } : {}) }, (d) => [
74
88
  `${ctx.out.c.bold(safe(d.changeSet.title))} ${ctx.out.c.muted(`${d.changeSet.id.slice(0, 8)} · ${d.changeSet.status}`)}`,
75
89
  ` ${counts(d.changeSet)}${d.changeSet.linesAdded || d.changeSet.linesRemoved ? ctx.out.c.muted(`, +${d.changeSet.linesAdded} −${d.changeSet.linesRemoved}`) : ""}`,
76
90
  ...(d.held.length ? [ctx.out.c.warning(` Not sent, ${d.held.length === 1 ? "it looks" : "they look"} like ${d.held.length === 1 ? "it holds" : "they hold"} a key: ${d.held.map((/** @type {string} */ p) => safe(p)).join(", ")}`), ctx.out.c.muted(" Remove the key, or nb change finish --confirm-secrets if it's safe to share")] : []),
91
+ ...(d.sendError ? [ctx.out.c.warning(` Your latest saves weren't sent: ${safe(d.sendError)}. They stay here; nb change status tries again`)] : []),
77
92
  ...(d.uploadsPending > d.held.length ? [ctx.out.c.warning(` ${plural(d.uploadsPending - d.held.length, "file")} still to upload: run nb change status again`)] : []),
78
93
  ...d.conflicts.map((/** @type {any} */ c) => ctx.out.c.warning(` ${ctx.out.sym.warn} ${safe(c.path)} changed since you started (${c.conflict?.kind ?? "edit"})`)),
79
94
  ...d.skipped.map((/** @type {any} */ s) => ctx.out.c.muted(` skipped ${safe(s.path)}: ${s.reason}`)),
@@ -122,6 +137,18 @@ async function finishSet(ctx, id) {
122
137
 
123
138
  /** @param {Context} ctx */
124
139
  export async function changeFinish(ctx) {
140
+ // Saves not captured into a change set yet (an agent finishing before its first save was picked up): one opens now,
141
+ // named like the one nb mcp opens, then finishes (found in the D22 agent run).
142
+ const { root, project } = ctx.requireRoot();
143
+ if (!ctx.positionals[0] && !currentChange(root)) {
144
+ const { items } = await draftItems(root, project);
145
+ if (!items.length) throw new CliError("NOT_FOUND", "Nothing to finish: no saved changes and no open change set here", { hint: "nb change status" });
146
+ const task = project.startedTask;
147
+ const title = String(ctx.flags.message ?? "").split("\n")[0]?.trim() || (task?.number ? `Work on #${task.number}${task.title ? `: ${task.title}` : ""}` : `Changes by ${ctx.env.NB_AGENT_NAME ?? "the terminal"}`);
148
+ const started = /** @type {any} */ (await ctx.api.post(`/api/v1/workspaces/${enc(project.workspaceId)}/change-sets`, { title: title.slice(0, 120) }));
149
+ setCurrentChange(root, started.changeSet.id);
150
+ writeJournal(root, { id: started.changeSet.id, title: started.changeSet.title, sent: {}, missing: [] });
151
+ }
125
152
  const id = pick(ctx);
126
153
  const res = await finishSet(ctx, id);
127
154
  ctx.out.result("nb.change.finish/1", res, (d) => [
@@ -298,7 +325,9 @@ export async function changeResolve(ctx) {
298
325
  const state = readState(root, project.workspaceId);
299
326
  const meta = /** @type {any} */ (await ctx.api.get("/api/v1/extension/file", { query: { projectId: project.workspaceId, path: remote, transfer: "metadata" } }).catch(() => null));
300
327
  const rel = toRelative(project.remoteRoot, remote);
301
- const abs = rel ? path.join(root, rel) : null;
328
+ // Inside this folder and never in .git (the same guard as nb pull): an agent's path can't write elsewhere.
329
+ const { safeJoin } = await import("../sync/transfer.mjs");
330
+ const abs = rel ? safeJoin(root, rel) : null;
302
331
  if (choice === "theirs" && meta && abs) {
303
332
  const { downloadTo } = await import("../sync/transfer.mjs");
304
333
  const got = await downloadTo(ctx.api, project.workspaceId, remote, abs, meta.contentHash ?? null);
@@ -309,7 +338,7 @@ export async function changeResolve(ctx) {
309
338
  state.files[remote] = { ...(state.files[remote] ?? { size: 0 }), nodeId: meta.nodeId ?? meta.id, baseVersion: meta.currentVersion ?? meta.version, baseHash: String(meta.contentHash ?? ""), mtimeMs: 0 };
310
339
  }
311
340
  const copy = state.conflicts[remote]?.copy;
312
- if (copy) fs.rmSync(path.join(root, copy), { force: true });
341
+ if (copy) fs.rmSync((await import("../sync/transfer.mjs")).safeJoin(root, copy.split(path.sep).join("/")), { force: true });
313
342
  delete state.conflicts[remote];
314
343
  writeState(root, state);
315
344
  if (id) {
package/lib/mcp/tools.mjs CHANGED
@@ -207,7 +207,7 @@ export const TOOLS = [
207
207
 
208
208
  // Change sets (report G7, G8): where they're on, the agent's saved files go into one change set as it works.
209
209
  { name: "networkbase_change_status", title: "The change set", tier: "read", pack: "changes", props: {},
210
- description: "Where change sets are on, your saved files go into one change set as you work (no push needed). Shows its files, uploads, review comments to address, and anything a teammate changed since.",
210
+ description: "Where change sets are on, your saved files go into one change set as you work (no push needed). Shows its files, uploads, review comments to address, and anything a teammate changed since; with none open, the recently applied ones and their ids (for networkbase_change_undo).",
211
211
  run: (nb) => nb("change status") },
212
212
  { name: "networkbase_change_start", title: "Start a change set", tier: "small", pack: "changes", props: { title: { type: "string", description: "The job, like \"Redesign the sign-in page\"" }, task: { type: "string" } }, required: ["title"],
213
213
  description: "Name the work before you start; otherwise your first save opens one named after the task. If it answers CHANGE_SETS_OFF, push with networkbase_file_push instead.",
@@ -218,6 +218,12 @@ export const TOOLS = [
218
218
  { name: "networkbase_change_apply", title: "Apply the change set", tier: "small", pack: "changes", props: { id: { type: "string", description: "Default: this folder's" } },
219
219
  description: "Apply every file of the finished change set at once, or none. Big ones (over 20 files, deletes, final files, docs) answer needs_confirmation. Undo: networkbase_change_undo.",
220
220
  run: (nb, a) => nb("change apply", a.id ? [String(a.id)] : []) },
221
+ { name: "networkbase_change_update", title: "Bring in teammates' changes", tier: "small", pack: "changes", props: {},
222
+ description: "When a teammate changed files you're also changing: merges their newer versions into your files here. Different lines merge; the same lines get a conflict copy next to the file, settled with networkbase_change_resolve.",
223
+ run: (nb) => nb("change update") },
224
+ { name: "networkbase_change_resolve", title: "Settle a conflicted file", tier: "small", pack: "changes", props: { path: { type: "string" }, keep: { type: "string", enum: ["mine", "theirs"] } }, required: ["path", "keep"],
225
+ description: "For a file changed on both sides: keep yours (it goes over theirs) or theirs (yours leaves the change set). To combine both, edit the file yourself and keep mine.",
226
+ run: (nb, a) => nb("change resolve", [String(a.path)], a.keep === "theirs" ? { theirs: true } : { mine: true }) },
221
227
  { name: "networkbase_change_undo", title: "Undo a change set", tier: "small", pack: "changes", props: { id: { type: "string" }, partial: { type: "boolean", description: "Undo the files nobody changed since" } }, required: ["id"],
222
228
  description: "Put every file of an applied change set back. Refused, naming the files, if someone changed them since; partial undoes the rest.",
223
229
  run: (nb, a) => nb("change undo", [String(a.id)], a.partial ? { partial: true } : {}) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@networkbase/cli",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "NetworkBase in your terminal: sync files, work on tasks, edit docs",
5
5
  "type": "module",
6
6
  "homepage": "https://networkbase.in",