vine-context 0.1.0 → 0.1.1

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/cli.js CHANGED
@@ -131,7 +131,7 @@ function generatedName(publicKey) {
131
131
  function resolveName(dataDir, probes = systemProbes) {
132
132
  if (process.env.VINE_USER) return { name: process.env.VINE_USER, source: "VINE_USER" };
133
133
  const stored = storedName(dataDir);
134
- if (stored) return { name: stored, source: "set_my_name" };
134
+ if (stored) return { name: stored, source: "chosen" };
135
135
  for (const source of ["git", "os", "login"]) {
136
136
  const name = usable(probes[source]());
137
137
  if (name) return { name, source };
@@ -692,32 +692,18 @@ var init_pack = __esm({
692
692
  SERVER_PARAMS = ["now", "by", "key", "role"];
693
693
  RESERVED_TOOL_NAMES = [
694
694
  "context_info",
695
- "context_activity",
695
+ "find_context",
696
696
  "model_guide",
697
- "describe_context",
698
- "set_my_name",
697
+ "update_context",
699
698
  "share_context",
700
- "stop_sharing",
701
- "start_sharing",
702
- "sharing_status",
703
- "revoke_invite",
704
- "set_peer_role",
705
- "remove_peer",
699
+ "sharing",
700
+ "manage_member",
706
701
  "join_context",
707
702
  "use_context",
708
- "add_context",
709
- "remove_context",
710
- "context_details",
711
703
  "delete_context",
712
- "rename_context",
713
- "set_turn_server",
714
- "remove_turn_server",
704
+ "turn_server",
715
705
  "link_folder",
716
- "take_back",
717
- "open_console",
718
- "open_contexts",
719
- "explore_context",
720
- "browser_view"
706
+ "open_view"
721
707
  ];
722
708
  ToolsFileSchema = z.object({
723
709
  fragments: z.record(identifier, z.string()).default({}),
@@ -812,6 +798,8 @@ __export(graph_exports, {
812
798
  ToolError: () => ToolError,
813
799
  defaultDataDir: () => defaultDataDir,
814
800
  inputShape: () => inputShape,
801
+ isoDay: () => isoDay,
802
+ isoMoment: () => isoMoment,
815
803
  newId: () => newId
816
804
  });
817
805
  import { mkdirSync as mkdirSync2 } from "fs";
@@ -820,12 +808,12 @@ import { z as z2 } from "zod";
820
808
  function newId(prefix) {
821
809
  return `${prefix}_${uuidv7()}`;
822
810
  }
823
- function scalar(type, spec) {
811
+ function scalar(type, spec, listing = false) {
824
812
  switch (type) {
825
813
  case "string":
826
814
  return z2.string().max(spec.max_length ?? 2e4);
827
815
  case "id":
828
- return z2.string().min(1).max(64);
816
+ return listing ? z2.string() : z2.string().min(1).max(64);
829
817
  case "integer": {
830
818
  let s = z2.number().int();
831
819
  if (spec.min !== void 0) s = s.min(spec.min);
@@ -841,17 +829,17 @@ function scalar(type, spec) {
841
829
  case "boolean":
842
830
  return z2.boolean();
843
831
  case "date":
844
- return z2.iso.date();
832
+ return listing ? z2.string().meta({ format: "date" }) : isoDay();
845
833
  case "datetime":
846
- return z2.iso.datetime({ offset: true });
834
+ return listing ? z2.string().meta({ format: "date-time" }) : isoMoment();
847
835
  default:
848
836
  throw new Error(`unknown type ${type}`);
849
837
  }
850
838
  }
851
- function inputShape(input) {
839
+ function inputShape(input, listing = false) {
852
840
  const shape = {};
853
841
  for (const [name, spec] of Object.entries(input)) {
854
- let s = spec.type === "enum" ? z2.enum(spec.values) : spec.type === "array" ? z2.array(scalar(spec.items, spec)).max(100) : scalar(spec.type, spec);
842
+ let s = spec.type === "enum" ? z2.enum(spec.values) : spec.type === "array" ? z2.array(scalar(spec.items, spec, listing)).max(100) : scalar(spec.type, spec, listing);
855
843
  s = s.describe(spec.description);
856
844
  if (spec.default !== void 0) s = s.default(spec.default);
857
845
  else if (!spec.required) s = s.optional();
@@ -863,7 +851,7 @@ function recordedOf(n, time) {
863
851
  const v = time ? n.props[time.recorded] : void 0;
864
852
  return typeof v === "string" ? Date.parse(v) : 0;
865
853
  }
866
- var ToolError, QueryError, openStores, CLAIM_RELS, REL_TYPES, isArray, str, day, Graph;
854
+ var ToolError, QueryError, isoDay, isoMoment, openStores, CLAIM_RELS, REL_TYPES, isArray, str, day, Graph;
867
855
  var init_graph = __esm({
868
856
  "src/core/graph.ts"() {
869
857
  "use strict";
@@ -879,6 +867,8 @@ var init_graph = __esm({
879
867
  };
880
868
  QueryError = class extends ToolError {
881
869
  };
870
+ isoDay = () => z2.iso.date({ error: "must be a real calendar date as YYYY-MM-DD, for example 2026-03-01" });
871
+ isoMoment = () => z2.iso.datetime({ offset: true, error: "must be an ISO 8601 date-time with a time zone, for example 2026-03-01T09:00:00Z" });
882
872
  openStores = /* @__PURE__ */ new Map();
883
873
  CLAIM_RELS = /* @__PURE__ */ new Set(["SUPPORTS", "CONTRADICTS", "REPLACES"]);
884
874
  REL_TYPES = /* @__PURE__ */ new Set(["SUPPORTS", "CONTRADICTS", "REPLACES", "ANSWERS", "ABOUT", "REPLIES_TO"]);
@@ -3406,7 +3396,7 @@ async function digest(changes, ctx) {
3406
3396
  const head = others.length >= 3 ? [`Caught up ${others.length} changes from ${authors.join(", ")}.`] : [];
3407
3397
  const shown2 = [...head, ...lines].slice(0, MAX_LINES);
3408
3398
  const more = head.length + lines.length - shown2.length;
3409
- return more > 0 ? [...shown2, `\u2026and ${more} more (context_activity lists them).`] : shown2;
3399
+ return more > 0 ? [...shown2, `\u2026and ${more} more (recent with activity lists them).`] : shown2;
3410
3400
  }
3411
3401
  async function briefing(g, reader) {
3412
3402
  const read = async (tool, args = {}) => {
@@ -3874,9 +3864,15 @@ var init_host = __esm({
3874
3864
  });
3875
3865
  }
3876
3866
  /** Undo, while a write is still held: it is removed and never leaves this machine. */
3877
- takeBack(changeId) {
3867
+ takeBack(changeId, newOnly = false) {
3878
3868
  return this.serial(async () => {
3879
- const held = this.log.heldChanges().find((h) => h.change.id === changeId || h.change.body.node === changeId);
3869
+ const held = this.log.heldChanges().find((h) => h.change.id === changeId || h.change.body.node === changeId && !(newOnly && h.change.kind === "withdraw"));
3870
+ if (newOnly && held && held.change.id !== changeId) {
3871
+ const node = held.change.body.node;
3872
+ const points = (c) => c.id !== held.change.id && c.body.node !== node && [c.body.supports, c.body.contradicts, c.body.replaces, c.body.answers, c.body.about, c.body.question, c.body.from, c.body.to].flat().includes(node);
3873
+ if (this.log.heldChanges().some((h) => points(h.change)) || this.log.all().some(points))
3874
+ throw new ToolError("Other items already link to it, so it can't be undone without trace. Withdraw it instead (it stays in the history).");
3875
+ }
3880
3876
  if (!held) {
3881
3877
  if (this.log.get(changeId) || this.log.all().some((c) => c.body.node === changeId))
3882
3878
  throw new ToolError("It has already been shared with the other members, so it can't be taken back without trace. Withdraw it instead (it stays in the history).");
@@ -4026,7 +4022,7 @@ var init_host = __esm({
4026
4022
  return { deny: "You are already in this graph, and this code is for someone else. It hasn't been used up: they can still join with it." };
4027
4023
  if (!existing || existing.removed_at) {
4028
4024
  const taken = this.members.current().some((m) => m.name === n.name);
4029
- if (taken) return { deny: `The name '${n.name}' is taken in this graph. Set another name (set_my_name) and use the code again.` };
4025
+ if (taken) return { deny: `The name '${n.name}' is taken in this graph. Set another name (update_context with my_name) and use the code again.` };
4030
4026
  await this.member("add_member", {
4031
4027
  key: n.key,
4032
4028
  name: n.name,
@@ -4176,7 +4172,7 @@ var init_host = __esm({
4176
4172
  return this.graph.call(p.tool, p.args, this.readCaller());
4177
4173
  }
4178
4174
  case "take_back":
4179
- return this.takeBack(String(p.id ?? ""));
4175
+ return this.takeBack(String(p.id ?? ""), Boolean(p.new_only));
4180
4176
  case "info":
4181
4177
  return this.info();
4182
4178
  case "snapshot":
@@ -4507,6 +4503,7 @@ var init_apps = __esm({
4507
4503
  init_package_root();
4508
4504
  APP_MIME = "text/html;profile=mcp-app";
4509
4505
  VIEWS = {
4506
+ view: "Views: the contexts panel, the sharing console or the graph explorer, whichever open_view was asked for",
4510
4507
  contexts: "Contexts panel: what needs you in this chat's context, its questions, claims and people, and the chat's contexts",
4511
4508
  console: "Sharing console: join codes, everyone in the graph, who is online, and their roles",
4512
4509
  explorer: "Graph explorer: the graph as it stood at any moment, with search",
@@ -4789,7 +4786,7 @@ function openInBrowser(url) {
4789
4786
  return false;
4790
4787
  }
4791
4788
  }
4792
- var text, failure2, OS, GRAPH_RE, contextArg, Session;
4789
+ var text, failure2, OPEN_VIEWS, OS, GRAPH_RE, contextArg, Session;
4793
4790
  var init_server = __esm({
4794
4791
  "src/mcp/server.ts"() {
4795
4792
  "use strict";
@@ -4812,6 +4809,7 @@ var init_server = __esm({
4812
4809
  content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value, null, 1) }]
4813
4810
  });
4814
4811
  failure2 = (message) => ({ ...text(message), isError: true });
4812
+ OPEN_VIEWS = ["contexts", "console", "explorer"];
4815
4813
  OS = { darwin: "macOS", win32: "Windows", linux: "Linux" };
4816
4814
  GRAPH_RE = /^[a-z0-9][a-z0-9-]{0,62}$/;
4817
4815
  contextArg = z3.string().regex(GRAPH_RE).optional();
@@ -4823,7 +4821,7 @@ var init_server = __esm({
4823
4821
  {
4824
4822
  capabilities: { tools: { listChanged: true }, resources: {}, prompts: {} },
4825
4823
  // Some agents read only the start of this (Codex: the first 512 characters), so that much stands alone.
4826
- instructions: "Vine Context holds shared contexts: what a group knows, as dated claims and open questions, synced peer to peer between its members' agents. Use it during ordinary work, not only when asked: when this chat reaches a decision, establishes a fact or leaves a question open that fits its context's purpose, record it (add_claim, ask_question; search first), and look there (search, open_questions) before answering what the group may already know. context_info says which context this chat uses and what it is for. Every member keeps a full copy, so it works offline. A chat usually uses one context; use_context switches it, add_context adds another, remove_context drops one, and the chat keeps them when reopened. find_context searches this machine's contexts by what they are for: use it to pick one, and before starting a new one. Call model_guide once before you first write, and follow it. To invite someone, use share_context: it makes a join code for one person. To join someone else's context, call join_context with the vine1_ code they sent."
4824
+ instructions: "Vine Context holds shared contexts: what a group knows, as dated claims and open questions, synced peer to peer between its members' agents. Use it during ordinary work, not only when asked: when this chat reaches a decision, establishes a fact or leaves a question open that fits its context's purpose, record it (add_claim, ask_question; search first), and look there (search, open_questions) before answering what the group may already know. context_info says which context this chat uses and what it is for. Every member keeps a full copy, so it works offline. A chat usually uses one context; use_context switches it (or, with `mode`, adds or drops one), and the chat keeps them when reopened. find_context searches this machine's contexts by what they are for: use it to pick one, and before starting a new one. Call model_guide once before you first write, and follow it. To invite someone, use share_context: it makes a join code for one person. To join someone else's context, call join_context with the vine1_ code they sent."
4827
4825
  }
4828
4826
  );
4829
4827
  registerViews(this.server);
@@ -4981,7 +4979,7 @@ Call join_context with the code exactly as given. When I'm in, tell me whose con
4981
4979
  async target(name) {
4982
4980
  const c = name ? this.contexts.get(name) : this.writeTo ? this.contexts.get(this.writeTo) : void 0;
4983
4981
  if (name && !c)
4984
- throw new Error(`This chat doesn't use '${name}': it uses ${[...this.contexts.keys()].map((n) => `'${n}'`).join(", ") || "no context"}. add_context adds one.`);
4982
+ throw new Error(`This chat doesn't use '${name}': it uses ${[...this.contexts.keys()].map((n) => `'${n}'`).join(", ") || "no context"}. use_context with mode 'add' adds one.`);
4985
4983
  if (!c) throw new Error(this.noContext());
4986
4984
  if (!c.host.closed) return c;
4987
4985
  if (!this.localNames().includes(c.name) && c.d.graph_id) {
@@ -5037,6 +5035,71 @@ Call join_context with the code exactly as given. When I'm in, tell me whose con
5037
5035
  const parts = [...this.contexts.values()].map((c) => `'${c.name}'${c.name === this.writeTo ? " (writes go here by default)" : ""}: ${c.d.description ?? "no description yet"}`);
5038
5036
  return ` This chat's contexts: ${parts.join("; ")}.`;
5039
5037
  }
5038
+ /**
5039
+ * What this server adds to two of the model's tools. `recent` can also give
5040
+ * the context's activity (what the panels poll), and `withdraw` first undoes
5041
+ * a write that is still only on this machine.
5042
+ */
5043
+ modelTool(tool) {
5044
+ const shape = inputShape(tool.input, true);
5045
+ if (tool.name === "recent")
5046
+ return {
5047
+ description: tool.description + " With `activity`, one context's latest activity instead (no `since` needed): who wrote what, what others' changes meant for you, joins and role changes, who is online.",
5048
+ shape: {
5049
+ ...shape,
5050
+ since: z3.string().meta({ format: "date-time" }).optional().describe("Changes after this time (ISO 8601). Required unless activity."),
5051
+ activity: z3.boolean().optional(),
5052
+ snapshot: z3.boolean().optional().describe("With activity: also its items and links"),
5053
+ context: contextArg
5054
+ }
5055
+ };
5056
+ if (tool.name === "withdraw")
5057
+ return {
5058
+ description: tool.description + " A write still only on this machine (for a few seconds after it is made) is undone without trace instead and never reaches anyone: the result then says taken_back.",
5059
+ shape: {
5060
+ ...shape,
5061
+ id: z3.string().describe("The claim, question or reply; or, to undo a write just made, its `change` id"),
5062
+ undo_only: z3.boolean().optional().describe("Fail if it was already shared, rather than withdraw")
5063
+ }
5064
+ };
5065
+ return { description: tool.description, shape };
5066
+ }
5067
+ /** The `activity` form of `recent`. It never takes the agent's notices: the panels poll it. */
5068
+ async activityCall(a) {
5069
+ try {
5070
+ if (!this.contexts.size) {
5071
+ const none = { using: "no context", context: null, contexts: [], your_contexts: this.localNames(), next: this.noContext() };
5072
+ return { ...text(none), structuredContent: none };
5073
+ }
5074
+ const out = await this.activity(a);
5075
+ return { ...text(out), structuredContent: out };
5076
+ } catch (e) {
5077
+ return failure2(e.message);
5078
+ }
5079
+ }
5080
+ /**
5081
+ * Undoes a write that is still only on this machine: it is removed and never
5082
+ * reaches anyone. Null when there is nothing to undo (it was shared already),
5083
+ * unless `must`, which fails instead. Without `must`, an item's own id only
5084
+ * undoes the write that made it (so withdrawing twice doesn't undo the
5085
+ * withdrawal), and only while nothing else links to it; a change id undoes
5086
+ * that change, whatever it was.
5087
+ */
5088
+ async takeBack(id, context, must) {
5089
+ const names2 = context || !this.many ? [context] : [...this.contexts.keys()];
5090
+ let last;
5091
+ for (const n of names2) {
5092
+ try {
5093
+ const r = await this.request("take_back", { id, new_only: !must }, n);
5094
+ return { ...this.many ? { context: n ?? this.writeTo } : {}, ...r, note: "Undone before it was shared: it never left this machine and leaves no trace." };
5095
+ } catch (e) {
5096
+ last = e;
5097
+ if (/already been shared/.test(last.message)) break;
5098
+ }
5099
+ }
5100
+ if (must) throw last ?? new Error(`No write ${id} from this machine.`);
5101
+ return null;
5102
+ }
5040
5103
  /** Registers the model's tools for the chat's contexts, as far as this machine's roles allow. */
5041
5104
  offer() {
5042
5105
  for (const t of this.modelTools.values()) t.remove();
@@ -5044,15 +5107,16 @@ Call join_context with the code exactly as given. When I'm in, tell me whose con
5044
5107
  const all = [...this.contexts.values()];
5045
5108
  if (!all.length) {
5046
5109
  for (const tool of claimsPack().tools) {
5110
+ const { description, shape } = this.modelTool(tool);
5047
5111
  const registered = this.server.registerTool(
5048
5112
  tool.name,
5049
5113
  {
5050
5114
  title: tool.title,
5051
- description: `${tool.description} This chat has no context yet: this tells you how to choose one.`,
5052
- inputSchema: inputShape(tool.input),
5115
+ description: `${description} This chat has no context yet: this tells you how to choose one.`,
5116
+ inputSchema: shape,
5053
5117
  annotations: { readOnlyHint: tool.kind === "read", destructiveHint: false, idempotentHint: tool.kind === "read", openWorldHint: false }
5054
5118
  },
5055
- async () => this.withNews(failure2(this.noContext()))
5119
+ async (raw) => tool.name === "recent" && raw?.activity ? this.activityCall({}) : this.withNews(failure2(this.noContext()))
5056
5120
  );
5057
5121
  this.modelTools.set(tool.name, registered);
5058
5122
  }
@@ -5064,13 +5128,14 @@ Call join_context with the code exactly as given. When I'm in, tell me whose con
5064
5128
  const allowed = all.filter((c) => RANK[this.roleIn(c)] >= RANK[tool.role] && !(tool.kind === "write" && c.d.member === false));
5065
5129
  if (!allowed.length) continue;
5066
5130
  const routing = !many ? "" : tool.kind === "write" ? ` Goes to the context named in \`context\`, else '${this.writeTo}'. Pick the context whose description fits; if none clearly does, ask the person.${this.contextsLine()}` : ` Without \`context\`, it runs on each of this chat's contexts and every result says which one it came from.${this.contextsLine()}`;
5131
+ const { description, shape } = this.modelTool(tool);
5067
5132
  const registered = this.server.registerTool(
5068
5133
  tool.name,
5069
5134
  {
5070
5135
  title: tool.title,
5071
- description: tool.description + routing,
5136
+ description: description + routing,
5072
5137
  inputSchema: {
5073
- ...inputShape(tool.input),
5138
+ ...shape,
5074
5139
  ...many ? { context: contextArg.describe(tool.kind === "write" ? "The context to write to (default: the write context)" : "Only this context (default: all of this chat's)") } : {}
5075
5140
  },
5076
5141
  annotations: { readOnlyHint: tool.kind === "read", destructiveHint: false, idempotentHint: tool.kind === "read", openWorldHint: false },
@@ -5078,14 +5143,27 @@ Call join_context with the code exactly as given. When I'm in, tell me whose con
5078
5143
  },
5079
5144
  async (raw) => {
5080
5145
  const { context, ...args } = raw;
5146
+ if (tool.name === "recent") {
5147
+ const { activity, snapshot } = args;
5148
+ if (activity) return this.activityCall({ limit: args.limit, snapshot, context });
5149
+ delete args.activity;
5150
+ delete args.snapshot;
5151
+ }
5081
5152
  try {
5082
5153
  await this.followRenames();
5154
+ if (tool.name === "recent" && !args.since) throw new Error("Give `since` (ISO 8601, for example 2026-03-01T09:00:00Z), or set `activity` for the context's latest activity.");
5155
+ if (tool.name === "withdraw") {
5156
+ const must = Boolean(args.undo_only);
5157
+ delete args.undo_only;
5158
+ const undone = await this.takeBack(String(args.id), context, must);
5159
+ if (undone) return this.withNews(text(undone));
5160
+ }
5083
5161
  if (tool.kind === "read" && !context && this.many) return this.withNews(await this.readAll(tool.name, args));
5084
5162
  const c = await this.target(context);
5085
5163
  let result = await this.request("call", { tool: tool.name, args }, c.name);
5086
5164
  if (Array.isArray(result) && this.many) result = result.map((row) => ({ context: c.name, ...row }));
5087
5165
  const out = text(result);
5088
- const held = tool.kind === "write" && result && typeof result === "object" && result.shared_at ? ` It stays on this machine until ${result.shared_at}; until then take_back removes it without trace.` : "";
5166
+ const held = tool.kind === "write" && result && typeof result === "object" && result.shared_at ? tool.name === "withdraw" ? ` Withdrawn: it stays in the history. The withdrawal itself stays on this machine until ${result.shared_at}; until then withdraw with its \`change\` id undoes it.` : ` It stays on this machine until ${result.shared_at}; until then withdraw removes it without trace.` : "";
5089
5167
  out.content.push({ type: "text", text: `(${tool.kind === "write" ? "in" : "from"} ${this.where(c.name)})${held}` });
5090
5168
  if (tool.view)
5091
5169
  out.structuredContent = {
@@ -5095,7 +5173,7 @@ Call join_context with the code exactly as given. When I'm in, tell me whose con
5095
5173
  input: args,
5096
5174
  result,
5097
5175
  context: c.name,
5098
- undo: tool.kind === "write" ? { take_back: true, withdraw: RANK[this.roleIn(c)] >= RANK.contributor } : null,
5176
+ undo: tool.kind === "write" ? { held: true, withdraw: RANK[this.roleIn(c)] >= RANK.contributor } : null,
5099
5177
  where: this.where(c.name)
5100
5178
  };
5101
5179
  return this.withNews(out);
@@ -5350,40 +5428,55 @@ Tell the person this, briefly.` });
5350
5428
  return this.withNews(failure2(e.message));
5351
5429
  }
5352
5430
  };
5353
- const which = contextArg.describe("Which of this chat's contexts (default: the one writes go to)");
5354
- const anyHere = contextArg.describe("Which context: one of this chat's (default: the one writes go to), or any other on this machine by name");
5431
+ const which = contextArg.describe("One of this chat's contexts (default: where writes go)");
5432
+ const anyHere = contextArg.describe("Any context on this machine (default: where the chat's writes go)");
5355
5433
  this.server.registerTool(
5356
5434
  "context_info",
5357
5435
  {
5358
5436
  title: "Context info",
5359
- description: "This chat's context: what it's for, your role, how much it holds, everyone in it and who is online, and the sharing state. Also the other contexts on this machine (your_contexts). If the chat uses several, `contexts` lists them and `context` picks which one to detail.",
5360
- inputSchema: { context: which },
5437
+ description: "This chat's context: what it's for, your role, how much it holds, who is in it and online, and the sharing state; also the other contexts on this machine (your_contexts). With `details`, a summary of any one context on this machine instead: id, who made it, members, items, whether it's syncing, where it's stored.",
5438
+ inputSchema: {
5439
+ context: contextArg.describe("One of this chat's contexts (default: where writes go); with details, any on this machine"),
5440
+ details: z3.boolean().optional()
5441
+ },
5361
5442
  annotations: ro
5362
5443
  },
5363
- wrap(async ({ context }) => {
5364
- if (!this.contexts.size) return { using: "no context", context: null, contexts: [], your_contexts: this.localNames(), next: this.noContext() };
5365
- const c = await this.target(context);
5366
- return {
5367
- using: this.where(c.name),
5368
- context: c.name,
5369
- id: c.d.graph_id ?? null,
5370
- description: c.d.description ?? null,
5371
- role: c.d.member === false ? null : c.d.you.role,
5372
- ...await this.request("info", void 0, c.name),
5373
- contexts: this.list(),
5374
- write_to: this.writeTo,
5375
- your_contexts: this.localNames(),
5376
- folder: this.folderState(),
5377
- started_from: this.origin,
5378
- next: this.many ? "Reads search every context in this chat; put each write in the one whose description fits (the `context` argument), else it goes to write_to." : "use_context switches this chat to another context; add_context adds one alongside (the chat keeps them when reopened)."
5379
- };
5380
- })
5444
+ async ({ context, details }) => {
5445
+ if (details || context && !this.contexts.has(context) && this.localNames().includes(context)) {
5446
+ try {
5447
+ const name = context ?? this.writeTo;
5448
+ if (!name) throw new Error(this.noContext());
5449
+ const out = await this.details(name);
5450
+ return { ...text(out), structuredContent: out };
5451
+ } catch (e) {
5452
+ return failure2(e.message);
5453
+ }
5454
+ }
5455
+ return wrap(async () => {
5456
+ if (!this.contexts.size) return { using: "no context", context: null, contexts: [], your_contexts: this.localNames(), next: this.noContext() };
5457
+ const c = await this.target(context);
5458
+ return {
5459
+ using: this.where(c.name),
5460
+ context: c.name,
5461
+ id: c.d.graph_id ?? null,
5462
+ description: c.d.description ?? null,
5463
+ role: c.d.member === false ? null : c.d.you.role,
5464
+ ...await this.request("info", void 0, c.name),
5465
+ contexts: this.list(),
5466
+ write_to: this.writeTo,
5467
+ your_contexts: this.localNames(),
5468
+ folder: this.folderState(),
5469
+ started_from: this.origin,
5470
+ next: this.many ? "Reads search every context in this chat; put each write in the one whose description fits (the `context` argument), else it goes to write_to." : "use_context switches this chat to another context, or with mode 'add' adds one alongside (the chat keeps them when reopened)."
5471
+ };
5472
+ })({});
5473
+ }
5381
5474
  );
5382
5475
  this.server.registerTool(
5383
5476
  "find_context",
5384
5477
  {
5385
5478
  title: "Find a context",
5386
- description: "Search the contexts on this machine (yours and ones you joined, whether or not this chat uses them) by name and what they are for, ranked by hybrid search (meaning plus keywords). Use it to find the context a topic belongs in, and before starting a new one, so it isn't a duplicate. It searches contexts, not what's in them: for claims and questions, use search.",
5479
+ description: "Search the contexts on this machine (whether or not this chat uses them) by name and what they are for. Use it to find the context a topic belongs in, and before starting a new one. It searches contexts, not their contents: for claims and questions, use search.",
5387
5480
  inputSchema: {
5388
5481
  query: z3.string().min(1).max(500).describe("What the context would be about"),
5389
5482
  limit: z3.number().int().min(1).max(50).default(10).describe("How many contexts")
@@ -5399,35 +5492,10 @@ Tell the person this, briefly.` });
5399
5492
  return {
5400
5493
  found,
5401
5494
  searched: names2.length,
5402
- next: found.length ? "Scores rank, they don't judge: read the descriptions. use_context switches this chat to one, add_context adds it alongside; if none fits, ask the person before starting a new one." : "No context here matches. If the person wants one for this, ask what it's for and start it with use_context or add_context and a description."
5495
+ next: found.length ? "Scores rank, they don't judge: read the descriptions. use_context switches this chat to one, or with mode 'add' adds it alongside; if none fits, ask the person before starting a new one." : "No context here matches. If the person wants one for this, ask what it's for and start it with use_context and a description."
5403
5496
  };
5404
5497
  })
5405
5498
  );
5406
- this.server.registerTool(
5407
- "context_activity",
5408
- {
5409
- title: "Context activity",
5410
- description: "What happened lately in one of this chat's contexts (default: the write context), newest first: who wrote what (yours and synced from others), what others' changes meant for you (the sync digest), joins and role changes, who is online, and (for an admin) the open join codes. With snapshot, also its items and links. Read-only; it never uses up the notices meant for you (it's what the Claude Code mod's band and panel poll).",
5411
- inputSchema: {
5412
- limit: z3.number().int().min(1).max(200).optional().describe("How many recent changes (default 30)"),
5413
- snapshot: z3.boolean().optional().describe("Also return the context as it stands now (items and links)"),
5414
- context: which
5415
- },
5416
- annotations: ro
5417
- },
5418
- async (a) => {
5419
- try {
5420
- if (!this.contexts.size) {
5421
- const none = { using: "no context", context: null, contexts: [], your_contexts: this.localNames(), next: this.noContext() };
5422
- return { ...text(none), structuredContent: none };
5423
- }
5424
- const out = await this.activity(a);
5425
- return { ...text(out), structuredContent: out };
5426
- } catch (e) {
5427
- return failure2(e.message);
5428
- }
5429
- }
5430
- );
5431
5499
  this.server.registerTool(
5432
5500
  "model_guide",
5433
5501
  {
@@ -5446,59 +5514,69 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5446
5514
  })
5447
5515
  );
5448
5516
  this.server.registerTool(
5449
- "describe_context",
5517
+ "update_context",
5450
5518
  {
5451
- title: "Describe a context",
5452
- description: "Set what a context is for, in a sentence or two (you must be an admin): what goes in it and what doesn't. Every member's agent sees it. Ask the person for it; don't invent it.",
5453
- inputSchema: { description: z3.string().min(1).max(500).describe("What the context is for"), context: anyHere },
5519
+ title: "Change a context's purpose or name, or your name",
5520
+ description: "Change what a context is for (`purpose`; admins only; every member's agent sees it), this machine's own name for it (`rename_to`; other members keep theirs), or the name others see for you in every context on this machine (`my_name`). Ask the person for each; don't invent them.",
5521
+ inputSchema: {
5522
+ purpose: z3.string().min(1).max(500).optional().describe("A sentence or two: what goes in it and what doesn't"),
5523
+ rename_to: contextArg.describe("Lower-case letters, digits and dashes"),
5524
+ my_name: z3.string().min(1).max(40).optional().describe("Letters, digits, spaces, dots, dashes or underscores"),
5525
+ context: anyHere
5526
+ },
5454
5527
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5455
5528
  },
5456
5529
  wrap(async (a) => {
5457
- if (a.context && !this.contexts.has(a.context)) return this.onContext(a.context, (h) => h.request("describe_context", { description: a.description }));
5458
- const c = await this.target(a.context);
5459
- const r = await this.request("describe_context", { description: a.description }, c.name);
5460
- await this.refresh(c.name);
5461
- return r;
5462
- })
5463
- );
5464
- this.server.registerTool(
5465
- "set_my_name",
5466
- {
5467
- title: "Set your name",
5468
- description: "Set the name other people see for you in every context on this machine (for example 'Craig Deverall'). Ask the person what they want to be called; don't invent it. You are your machine's key; the name is a label you can change. What you recorded before shows the new name too.",
5469
- inputSchema: { name: z3.string().min(1).max(40).describe("1\u201340 letters, digits, spaces, dots, dashes or underscores") },
5470
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5471
- },
5472
- wrap(async ({ name }) => {
5473
- if (process.env.VINE_USER) throw new Error(`Your name is set by VINE_USER ('${process.env.VINE_USER}') in this agent's configuration; change it there.`);
5474
- const n = setName(this.dataDir, name);
5475
- for (const c of this.contexts.values()) await this.request("rename", { name: n }, c.name);
5476
- return { name: n, fingerprint: fingerprint(this.o.identity().publicKey), note: "This chat's contexts have it now; your other contexts take it when their hosts next start." };
5530
+ if (!a.purpose && !a.rename_to && !a.my_name) throw new Error("Nothing to change: give `purpose`, `rename_to` or `my_name`.");
5531
+ if (a.my_name && process.env.VINE_USER) throw new Error(`Your name is set by VINE_USER ('${process.env.VINE_USER}') in this agent's configuration; change it there.`);
5532
+ const out = {};
5533
+ if (a.my_name) {
5534
+ const n = setName(this.dataDir, a.my_name);
5535
+ for (const c of this.contexts.values()) await this.request("rename", { name: n }, c.name);
5536
+ out.my_name = { name: n, fingerprint: fingerprint(this.o.identity().publicKey), note: "This chat's contexts have it now; your other contexts take it when their hosts next start." };
5537
+ }
5538
+ if (a.purpose) {
5539
+ if (a.context && !this.contexts.has(a.context)) out.purpose = await this.onContext(a.context, (h) => h.request("describe_context", { description: a.purpose }));
5540
+ else {
5541
+ const c = await this.target(a.context);
5542
+ out.purpose = await this.request("describe_context", { description: a.purpose }, c.name);
5543
+ await this.refresh(c.name);
5544
+ }
5545
+ }
5546
+ if (a.rename_to) {
5547
+ const from = a.context ?? this.writeTo;
5548
+ if (!from) throw new Error(this.noContext());
5549
+ out.renamed = { ...await this.renameLocal(from, a.rename_to), note: "Renamed on this machine. Other members keep their own name for it." };
5550
+ }
5551
+ return out;
5477
5552
  })
5478
5553
  );
5479
5554
  this.server.registerTool(
5480
- "set_turn_server",
5555
+ "turn_server",
5481
5556
  {
5482
- title: "Set a TURN server",
5483
- description: "Set the TURN server this machine's connections go through when two members' networks block a direct connection (a join that fails with 'could not connect', or members who never link). Most people don't need one, and there is none by default. The person must have a server and a username on it: ask for them, never invent them. Never ask for the server's password, and never accept one in the chat: this tool takes none. It saves the server and username only, and the password is read from the VINE_TURN_PASSWORD environment variable where vine runs. To have vine keep the password instead (in a file only the person can read, or the OS keychain), the person runs the `terminal_command` from the result in their own terminal: it asks for the password there, unseen. It applies to every context on this machine, from the next connection on, with nothing to restart. One of two members having a server is enough for that pair. The result says whether the server answered.",
5557
+ title: "Set or forget the TURN server",
5558
+ description: "Set (`set`) or forget (`clear`) the TURN server this machine's connections use when two members' networks block a direct connection (a join that fails with 'could not connect', or members who never link). Most people need none. For `set`, ask the person for the server and their username on it; never invent them. Never ask for the server's password or accept one in the chat: this tool takes none. It is read from VINE_TURN_PASSWORD where vine runs, or the person runs the result's `terminal_command` in their own terminal so vine keeps it.",
5484
5559
  inputSchema: {
5485
- host: z3.string().min(1).max(255).describe("The server's host name or address, e.g. turn.example.org"),
5560
+ action: z3.enum(["set", "clear"]),
5561
+ host: z3.string().min(1).max(255).optional().describe("For set, e.g. turn.example.org"),
5486
5562
  port: z3.number().int().min(1).max(65535).optional().describe("Default 3478 (5349 for tls)"),
5487
- username: z3.string().min(1).max(255),
5488
- transport: z3.enum(["udp", "tcp", "tls"]).optional().describe("How to reach the server (default udp)")
5563
+ username: z3.string().min(1).max(255).optional().describe("For set"),
5564
+ transport: z3.enum(["udp", "tcp", "tls"]).optional().describe("Default udp")
5489
5565
  },
5490
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
5566
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true }
5491
5567
  },
5492
5568
  wrap(async (a) => {
5569
+ if (a.action === "clear") return { removed: clearTurn(this.dataDir), note: "Members whose networks block direct connections can no longer reach this machine directly. Links already open stay as they are." };
5570
+ if (!a.host || !a.username) throw new Error("To set a TURN server, give its `host` and the person's `username` on it.");
5493
5571
  if (process.env.VINE_ICE !== void 0) throw new Error("VINE_ICE is set in this agent's configuration and replaces this setting; change it there, or remove it first.");
5494
5572
  if (readCloudflare(this.dataDir))
5495
5573
  throw new Error(
5496
- "Cloudflare TURN is set up on this machine, and this tool would replace it. To change it, the person runs `vine turn set` in a terminal; or remove it first with remove_turn_server."
5574
+ "Cloudflare TURN is set up on this machine, and this tool would replace it. To change it, the person runs `vine turn set` in a terminal; or remove it first with turn_server and the action 'clear'."
5497
5575
  );
5498
5576
  const kept = readTurn(this.dataDir);
5499
5577
  if (kept && kept.store !== "env")
5500
5578
  throw new Error(
5501
- `A TURN server is already set (${kept.host}:${kept.port}, user ${kept.username}) with its password kept by vine, and this tool can't replace it without losing that password. To change it, the person runs \`vine turn set\` in a terminal; or remove it first with remove_turn_server.`
5579
+ `A TURN server is already set (${kept.host}:${kept.port}, user ${kept.username}) with its password kept by vine, and this tool can't replace it without losing that password. To change it, the person runs \`vine turn set\` in a terminal; or remove it first with turn_server and the action 'clear'.`
5502
5580
  );
5503
5581
  const t = saveTurn(this.dataDir, { host: a.host, port: a.port, username: a.username, transport: a.transport, store: "env" });
5504
5582
  const check = await checkStoredTurn(this.dataDir);
@@ -5514,25 +5592,15 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5514
5592
  };
5515
5593
  })
5516
5594
  );
5517
- this.server.registerTool(
5518
- "remove_turn_server",
5519
- {
5520
- title: "Remove the TURN server",
5521
- description: "Forget this machine's TURN server and its password. New connections are direct only; links already open stay as they are.",
5522
- inputSchema: {},
5523
- annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
5524
- },
5525
- wrap(async () => ({ removed: clearTurn(this.dataDir), note: "Members whose networks block direct connections can no longer reach this machine directly." }))
5526
- );
5527
5595
  this.server.registerTool(
5528
5596
  "share_context",
5529
5597
  {
5530
5598
  title: "Invite someone",
5531
- description: "Invite one person to a context (you must be an admin of it; default: the chat's context): makes a new join code (vine1_\u2026) for that person. Your machine answers the code, so it must be online when they use it. The first person to use it is let straight in with the code's role and gets a full copy; anyone else using it is turned away. Everyone in the context is told when someone joins, with their name, key fingerprint and agent. remove_peer takes anyone out. An unused code expires (default 24 hours). Call it once per person, and only when the person asks to invite someone. Unless they already said, ask first what the person may do: read and add (contributor), only read (reader), or read, add and invite (admin). sharing_status lists invites; revoke_invite cancels one.",
5599
+ description: "Invite one person to a context (admins only; default: the chat's context): makes a join code (vine1_\u2026) that lets the first person to use it in, with the code's role and a full copy. Your machine answers the code, so it must be online when they use it. Call it once per person, and only when the person asks to invite someone. Unless they already said, ask first what the invitee may do: read and add (contributor), only read (reader), or read, add and invite (admin).",
5532
5600
  inputSchema: {
5533
- label: z3.string().max(60).optional().describe("Who it's for, e.g. 'for Sam': shown in sharing_status and in the join notice"),
5534
- role: z3.enum(["reader", "contributor", "admin"]).optional().describe("The role they get when they join: the person's choice (default contributor)"),
5535
- expires_hours: z3.number().positive().max(720).optional().describe("Hours until an unused code stops working (default 24)"),
5601
+ label: z3.string().max(60).optional().describe("Who it's for, e.g. 'for Sam'"),
5602
+ role: z3.enum(["reader", "contributor", "admin"]).optional().describe("Default contributor"),
5603
+ expires_hours: z3.number().positive().max(720).optional().describe("How long an unused code works (default 24)"),
5536
5604
  context: anyHere
5537
5605
  },
5538
5606
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
@@ -5544,78 +5612,54 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5544
5612
  })
5545
5613
  );
5546
5614
  this.server.registerTool(
5547
- "revoke_invite",
5548
- {
5549
- title: "Cancel an invite",
5550
- description: "Cancel a join code you made: it stops working. Use the invite id from sharing_status. To take someone out of a context, use remove_peer.",
5551
- inputSchema: { id: z3.string().describe("The invite id (inv_\u2026), as sharing_status shows it"), context: which },
5552
- annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
5553
- },
5554
- wrap(({ context, ...a }) => this.request("revoke_invite", a, context))
5555
- );
5556
- this.server.registerTool(
5557
- "stop_sharing",
5615
+ "sharing",
5558
5616
  {
5559
- title: "Go offline",
5560
- description: "Stop syncing a context with the other members, and stop answering your join codes for it, until you share again (start_sharing, or the console). Your copy keeps working; what you write is sent when you're back. Sharing is on by default.",
5561
- inputSchema: { context: anyHere },
5617
+ title: "Sharing: status, go offline, go online",
5618
+ description: "`status`: whether a context is syncing, its invites (who each is for; open, used or expired), its members (name, key fingerprint, role, agent, online) and the links to them. `off`: stop syncing it and answering its join codes until `on`; your copy keeps working and what you write is sent when you're back. Sharing is on by default.",
5619
+ inputSchema: { action: z3.enum(["status", "on", "off"]), context: anyHere },
5562
5620
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5563
5621
  },
5564
- wrap(({ context }) => this.onContext(context, (h) => h.request("unshare")))
5565
- );
5566
- this.server.registerTool(
5567
- "start_sharing",
5568
- {
5569
- title: "Go online",
5570
- description: "Start syncing a context with the other members again after stop_sharing, and answer your join codes for it. It makes no new join code (share_context does). Sharing is on by default, so this is only needed after going offline.",
5571
- inputSchema: { context: anyHere },
5572
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5573
- },
5574
- wrap(({ context }) => this.onContext(context, (h) => h.request("start_sharing")))
5575
- );
5576
- this.server.registerTool(
5577
- "sharing_status",
5578
- {
5579
- title: "Sharing status",
5580
- description: "Whether a context is syncing, its invites (who each is for, open, used or expired), everyone in it (name, key fingerprint, role, agent, operating system, online), the links to other members, and the signalling relays' state.",
5581
- inputSchema: { context: which },
5582
- annotations: ro
5583
- },
5584
- wrap(({ context }) => this.request("status", void 0, context))
5585
- );
5586
- const roleSchema = z3.enum(["reader", "contributor", "admin"]);
5587
- this.server.registerTool(
5588
- "set_peer_role",
5589
- {
5590
- title: "Change someone's role",
5591
- description: "Change a member's role in a context (you must be an admin): reader, contributor or admin. Every member's machine applies it.",
5592
- inputSchema: { name: z3.string().describe("Their name"), role: roleSchema.describe("Their new role"), context: which },
5593
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5594
- },
5595
- wrap(({ context, ...a }) => this.request("set_role", a, context))
5622
+ wrap(
5623
+ ({ action, context }) => this.onContext(context, (h) => h.request(action === "status" ? "status" : action === "on" ? "start_sharing" : "unshare"))
5624
+ )
5596
5625
  );
5597
5626
  this.server.registerTool(
5598
- "remove_peer",
5627
+ "manage_member",
5599
5628
  {
5600
- title: "Remove someone",
5601
- description: "Take a member out of a context (you must be an admin). Every member's machine stops syncing with them and refuses their later changes. Their past contributions stay. They keep the copy they already had: removal can't take back what they received.",
5602
- inputSchema: { name: z3.string().describe("Their name"), context: which },
5629
+ title: "Change a role, remove someone, cancel an invite",
5630
+ description: "For an admin of a context. `set_role`: change a member's role. `remove`: take a member out; every machine stops syncing with them and refuses their later changes, but they keep the copy they already had. `revoke_invite`: cancel a join code.",
5631
+ inputSchema: {
5632
+ action: z3.enum(["set_role", "remove", "revoke_invite"]),
5633
+ name: z3.string().optional().describe("The member (set_role, remove)"),
5634
+ role: z3.enum(["reader", "contributor", "admin"]).optional(),
5635
+ invite: z3.string().optional().describe("Invite id (inv_\u2026) from sharing status"),
5636
+ context: which
5637
+ },
5603
5638
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
5604
5639
  },
5605
- wrap(({ context, ...a }) => this.request("remove", a, context))
5640
+ wrap(({ action, name, role, invite, context }) => {
5641
+ if (action === "revoke_invite") {
5642
+ if (!invite) throw new Error("To cancel an invite, give its id as `invite` (inv_\u2026, from sharing with the action 'status').");
5643
+ return this.request("revoke_invite", { id: invite }, context);
5644
+ }
5645
+ if (!name) throw new Error("Give the member's `name`.");
5646
+ if (action === "remove") return this.request("remove", { name }, context);
5647
+ if (!role) throw new Error("Give their new `role`: reader, contributor or admin.");
5648
+ return this.request("set_role", { name, role }, context);
5649
+ })
5606
5650
  );
5607
5651
  this.server.registerTool(
5608
5652
  "join_context",
5609
5653
  {
5610
5654
  title: "Join a shared context",
5611
- description: "Join someone else's context with the join code they sent (vine1_\u2026; it can be inside other text). Use it when the person pastes such a code. The machine that made the code must be online. You are let in at once and get your own full copy, kept in step with the others; everyone is told you joined (your name, key fingerprint and agent). It's added to this chat and writes go to it; the result includes a briefing (open questions, conflicts, latest). Other chats don't need the code: use_context with its name.",
5655
+ description: "Join someone else's context with the join code they sent (vine1_\u2026; it can be inside other text). Use it when the person pastes such a code. The machine that made the code must be online. You get your own full copy, kept in step with the others, and everyone is told you joined. It's added to this chat and writes go to it; the result includes a briefing. Other chats don't need the code: use_context with its name.",
5612
5656
  inputSchema: { code: z3.string().describe("The vine1_\u2026 join code, exactly as sent") },
5613
5657
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
5614
5658
  },
5615
5659
  wrap(async ({ code }) => this.join(code))
5616
5660
  );
5617
- const nameArg = z3.string().regex(GRAPH_RE).describe("Context name: lower-case letters, digits and dashes");
5618
- const descriptionArg = z3.string().max(500).optional().describe("For a new context: what it's for (what goes in it), in a sentence or two");
5661
+ const nameArg = z3.string().regex(GRAPH_RE).describe("Lower-case letters, digits and dashes");
5662
+ const descriptionArg = z3.string().max(500).optional().describe("For a new context: what goes in it, in a sentence or two");
5619
5663
  const created = async (name, isNew, description) => {
5620
5664
  const c = this.contexts.get(name);
5621
5665
  if (isNew && description) {
@@ -5627,20 +5671,41 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5627
5671
  if (autoShare()) await this.request("start_sharing", void 0, name);
5628
5672
  return {
5629
5673
  created: this.where(name),
5630
- next: (c.d.description ? "" : "Ask the person what this context is for and set it with describe_context. ") + "No one is invited yet and there is no join code. When the person wants someone in, ask who and what they may do (read and add, only read, or also invite), then call share_context for that one person. Call model_guide before writing."
5674
+ next: (c.d.description ? "" : "Ask the person what this context is for and set it with update_context (`purpose`). ") + "No one is invited yet and there is no join code. When the person wants someone in, ask who and what they may do (read and add, only read, or also invite), then call share_context for that one person. Call model_guide before writing."
5631
5675
  };
5632
5676
  };
5633
5677
  this.server.registerTool(
5634
5678
  "use_context",
5635
5679
  {
5636
- title: "Use a context in this chat",
5637
- description: "Make a context this chat's context, replacing the ones it had: one on this machine (yours, or one you joined; context_info lists your_contexts). The chat keeps it when reopened. A name that isn't here yet starts a new context of your own: ask the person what it's for and give that as its description. To use another alongside, add_context.",
5638
- inputSchema: { name: nameArg, description: descriptionArg },
5680
+ title: "Choose this chat's contexts",
5681
+ description: "Make a context on this machine (context_info lists your_contexts) this chat's context, replacing the ones it had; the chat keeps it when reopened. A name that isn't here yet starts a new context of your own: ask the person what it's for and pass that as `description`. Mode `add` uses it alongside the chat's others (most chats need one). Mode `remove` takes it out of the chat (without a name, all of them); nothing is deleted.",
5682
+ inputSchema: {
5683
+ name: contextArg.describe("Lower-case letters, digits and dashes"),
5684
+ mode: z3.enum(["replace", "add", "remove"]).default("replace"),
5685
+ description: descriptionArg,
5686
+ write_here: z3.boolean().optional().describe("With add: writes go to it by default")
5687
+ },
5639
5688
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5640
5689
  },
5641
- wrap(async ({ name, description }) => {
5690
+ wrap(async ({ name, mode, description, write_here }) => {
5691
+ if (mode === "remove") {
5692
+ for (const n of name ? [name] : [...this.contexts.keys()]) this.detach(n);
5693
+ return { contexts: this.list(), write_to: this.writeTo ?? null, ...this.contexts.size ? {} : { next: this.noContext() } };
5694
+ }
5695
+ if (!name) throw new Error("Give the context's `name`.");
5642
5696
  const isNew = !this.localNames().includes(name);
5643
5697
  await this.attach(name, false);
5698
+ if (mode === "add") {
5699
+ if (write_here) this.writeTo = name;
5700
+ this.remember();
5701
+ this.offer();
5702
+ return {
5703
+ contexts: this.list(),
5704
+ write_to: this.writeTo,
5705
+ next: this.many ? "Call model_guide again: it says how to pick a context for each write." : "Call model_guide before writing.",
5706
+ ...await created(name, isNew, description)
5707
+ };
5708
+ }
5644
5709
  for (const other of [...this.contexts.keys()]) if (other !== name) this.contexts.get(other).host.close(), this.contexts.delete(other);
5645
5710
  this.writeTo = name;
5646
5711
  this.origin = "chosen";
@@ -5650,73 +5715,11 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5650
5715
  return { using: this.where(name), description: c.d.description ?? null, next: "Call model_guide before writing to it.", ...await created(name, isNew, description) };
5651
5716
  })
5652
5717
  );
5653
- this.server.registerTool(
5654
- "add_context",
5655
- {
5656
- title: "Also use a context",
5657
- description: "Add another context to this chat, alongside the ones it uses (most chats need one). Reads then search it too, and writes go to whichever context fits. A new name starts a new context of your own: ask what it's for. With write_here, writes go to it unless a call names another.",
5658
- inputSchema: { name: nameArg, description: descriptionArg, write_here: z3.boolean().optional().describe("Make it where writes go by default") },
5659
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5660
- },
5661
- wrap(async ({ name, description, write_here }) => {
5662
- const isNew = !this.localNames().includes(name);
5663
- await this.attach(name, false);
5664
- if (write_here) this.writeTo = name;
5665
- this.remember();
5666
- this.offer();
5667
- return {
5668
- contexts: this.list(),
5669
- write_to: this.writeTo,
5670
- next: this.many ? "Call model_guide again: it says how to pick a context for each write." : "Call model_guide before writing.",
5671
- ...await created(name, isNew, description)
5672
- };
5673
- })
5674
- );
5675
- this.server.registerTool(
5676
- "remove_context",
5677
- {
5678
- title: "Stop using a context",
5679
- description: "Take a context out of this chat (nothing is deleted: it stays on this machine and keeps syncing). Without `name`, takes them all out, leaving the chat with no context.",
5680
- inputSchema: { name: z3.string().regex(GRAPH_RE).optional().describe("The context to take out (default: all of them)") },
5681
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5682
- },
5683
- wrap(async ({ name }) => {
5684
- for (const n of name ? [name] : [...this.contexts.keys()]) this.detach(n);
5685
- return { contexts: this.list(), write_to: this.writeTo ?? null, ...this.contexts.size ? {} : { next: this.noContext() } };
5686
- })
5687
- );
5688
- this.server.registerTool(
5689
- "context_details",
5690
- {
5691
- title: "A context's details",
5692
- description: "Everything about one context on this machine, whether or not this chat uses it: what it's for, its id, your role, who made it, how many members and items it has, whether it's syncing, and where it's stored. Read-only.",
5693
- inputSchema: { name: nameArg },
5694
- annotations: ro
5695
- },
5696
- async ({ name }) => {
5697
- try {
5698
- const out = await this.details(name);
5699
- return { ...text(out), structuredContent: out };
5700
- } catch (e) {
5701
- return failure2(e.message);
5702
- }
5703
- }
5704
- );
5705
- this.server.registerTool(
5706
- "rename_context",
5707
- {
5708
- title: "Rename a context on this machine",
5709
- description: "Give a context on this machine (whether or not this chat uses it) a new name. The name is this machine's own label for it: other members keep theirs, and the context's id doesn't change. Every chat and folder that uses it follows it to the new name. Only when the person asks: they choose the name.",
5710
- inputSchema: { name: nameArg, to: z3.string().regex(GRAPH_RE).describe("The new name: lower-case letters, digits and dashes") },
5711
- annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5712
- },
5713
- wrap(async ({ name, to }) => ({ ...await this.renameLocal(name, to), note: "Renamed on this machine. Other members keep their own name for it." }))
5714
- );
5715
5718
  this.server.registerTool(
5716
5719
  "delete_context",
5717
5720
  {
5718
5721
  title: "Delete a context from this machine",
5719
- description: "Permanently delete this machine's copy of a context: its claims, questions and replies, its change log, the join codes made here, and every chat's and folder's link to it. It can't be undone. Other members keep their own copies; with no other member, it is gone for good. Getting it back means joining again with a new code from an admin. Only when the person asked to delete it: first tell them what it removes and ask them to confirm by name, then pass that name as `confirm`. To only stop using it in this chat, use remove_context.",
5722
+ description: "Permanently delete this machine's copy of a context: its claims, questions and replies, its change log, its join codes, and every chat's and folder's link to it. It can't be undone. Other members keep their copies; with none, it is gone for good. Only when the person asked to delete it: first tell them what it removes and ask them to confirm by name, then pass that name as `confirm`. To only stop using it in this chat, use_context with mode `remove`.",
5720
5723
  inputSchema: { name: nameArg, confirm: z3.string().describe("The context's name again, as the person confirmed it") },
5721
5724
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
5722
5725
  },
@@ -5730,10 +5733,10 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5730
5733
  "link_folder",
5731
5734
  {
5732
5735
  title: "Start this folder's chats here",
5733
- description: "Make new chats started in this chat's folder (or below it) start with this chat's contexts, or with `off`, stop that. With `name`, pin just that one context to the folder (any on this machine), or with `off` too, unpin it, leaving the folder's others as they are. It's kept on this machine (nothing is written into the folder). Ask the person first.",
5736
+ description: "Make new chats started in this chat's folder (or below it) start with this chat's contexts; with `off`, stop that. With `name`, pin (or with `off`, unpin) just that context, leaving the folder's others as they are. Kept on this machine, not in the folder. Ask the person first.",
5734
5737
  inputSchema: {
5735
- off: z3.boolean().optional().describe("Stop linking the folder (or, with name, unpin that context)"),
5736
- name: z3.string().regex(GRAPH_RE).optional().describe("Pin or unpin only this context")
5738
+ off: z3.boolean().optional(),
5739
+ name: contextArg
5737
5740
  },
5738
5741
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
5739
5742
  },
@@ -5764,28 +5767,6 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5764
5767
  return { folder: this.o.cwd, linked: [...this.contexts.keys()], note: "New chats started in this folder, or below it, start with these contexts." };
5765
5768
  })
5766
5769
  );
5767
- this.server.registerTool(
5768
- "take_back",
5769
- {
5770
- title: "Take back a write",
5771
- description: "Undo something you just wrote, while it is still only on this machine (for a few seconds after writing): it is removed and never reaches anyone. Use it when something was recorded by mistake, such as personal details in the wrong chat. After that, use withdraw (which keeps it in the history).",
5772
- inputSchema: { id: z3.string().describe("The change id (change) or the item's id from the write's result"), context: contextArg.describe("The context it was written to (default: each of this chat's, in turn)") },
5773
- annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
5774
- },
5775
- wrap(async ({ id, context }) => {
5776
- if (context || !this.many) return this.request("take_back", { id }, context);
5777
- let last;
5778
- for (const c of this.contexts.values()) {
5779
- try {
5780
- return { context: c.name, ...await this.request("take_back", { id }, c.name) };
5781
- } catch (e) {
5782
- last = e;
5783
- if (/already been shared/.test(e.message)) throw e;
5784
- }
5785
- }
5786
- throw last instanceof Error ? last : new Error(`No write ${id} from this machine.`);
5787
- })
5788
- );
5789
5770
  }
5790
5771
  /** What the console shows. */
5791
5772
  async consoleState(context) {
@@ -5808,102 +5789,81 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5808
5789
  }
5809
5790
  };
5810
5791
  const both = (summary2, structured) => ({ ...text(summary2), structuredContent: structured });
5811
- const which = contextArg.describe("Which of this chat's contexts (default: the one writes go to)");
5792
+ const which = contextArg.describe("One of this chat's contexts (default: where writes go)");
5812
5793
  this.server.registerTool(
5813
- "open_contexts",
5794
+ "open_view",
5814
5795
  {
5815
- title: "Open the contexts panel",
5816
- description: "Show the person this chat's context in a panel: what needs them, its questions with their threads, its claims (with conflicts and history), its people and join codes, and the chat's contexts to turn on and off. For the person to look at and steer from; to read the context yourself, use context_info and the model's search and read tools.",
5817
- inputSchema: {},
5818
- annotations: ro,
5819
- _meta: uiMeta("contexts", { beside: true })
5820
- },
5821
- run4(async () => {
5822
- if (!this.contexts.size) {
5823
- const none = { using: "no context", context: null, contexts: [], your_contexts: this.localNames(), next: this.noContext() };
5824
- return both(none, none);
5825
- }
5826
- const state = await this.activity({ limit: 40, snapshot: true });
5827
- const snap = state.snapshot;
5828
- return both({ showing: state.using, context: state.context, items: snap.nodes.length, note: "The person is looking at the contexts panel." }, state);
5829
- })
5830
- );
5831
- this.server.registerTool(
5832
- "open_console",
5833
- {
5834
- title: "Open the sharing console",
5835
- description: "Show the sharing console for a context: everyone in it (with key fingerprints, agents, roles and who is online), your join codes, and whether it is syncing. An admin can make codes, change roles and remove people there.",
5836
- inputSchema: { context: which },
5837
- annotations: ro,
5838
- _meta: uiMeta("console")
5839
- },
5840
- run4(async (a) => {
5841
- const state = await this.consoleState(a.context);
5842
- return both(state, state);
5843
- })
5844
- );
5845
- this.server.registerTool(
5846
- "explore_context",
5847
- {
5848
- title: "Explore a context",
5849
- description: "Show a context as an interactive picture: its items and the links between them, as it stood at a moment (default now). For the person to look at; to answer a question yourself, use the model's search and read tools.",
5796
+ title: "Show a view of a context",
5797
+ description: "Show the person a view of this chat's context: `contexts` (the panel: what needs them, questions and threads, claims, people and join codes, and the chat's contexts), `console` (sharing: members, key fingerprints, roles, who is online, join codes) or `explorer` (a picture of its items and links, as it stood `at` a moment). For the person to look at and steer from; to read the context yourself, use search and the other read tools." + (this.o.browserView ? " If this agent can't show views, pass `browser` for a link to them in a browser tab." : ""),
5850
5798
  inputSchema: {
5851
- at: z3.iso.datetime({ offset: true }).optional().describe("Show it as it stood at this time (ISO 8601). Default now."),
5852
- limit: z3.number().int().min(1).max(1e3).default(200).describe("Most recent items to show"),
5799
+ view: z3.enum(OPEN_VIEWS).default("contexts"),
5800
+ at: z3.string().meta({ format: "date-time" }).optional().describe("Explorer: ISO 8601, default now"),
5801
+ limit: z3.number().int().min(1).max(1e3).optional().describe("Explorer: most recent items (default 200)"),
5802
+ ...this.o.browserView ? { browser: z3.boolean().optional() } : {},
5853
5803
  context: which
5854
5804
  },
5855
5805
  annotations: ro,
5856
- _meta: uiMeta("explorer")
5806
+ _meta: uiMeta("view", { beside: true })
5857
5807
  },
5858
- run4(async ({ context, ...a }) => {
5859
- const c = await this.target(context);
5860
- const snap = await this.request("snapshot", a, c.name);
5861
- const counts = {};
5862
- for (const n of snap.nodes) counts[n.label] = (counts[n.label] ?? 0) + 1;
5863
- return both(
5864
- {
5865
- showing: this.where(c.name),
5866
- at: snap.at,
5867
- nodes: counts,
5868
- links: snap.edges.length,
5869
- truncated: snap.truncated,
5870
- note: "The explorer shows the picture to the person; this summary is all you get here."
5871
- },
5872
- { ...snap, where: this.where(c.name) }
5873
- );
5874
- })
5875
- );
5876
- if (this.o.browserView)
5877
- this.server.registerTool(
5878
- "browser_view",
5879
- {
5880
- title: "Open the views in a browser",
5881
- description: "Get a link to the console and explorer in a browser tab on this machine, for when this agent can't show MCP App views itself. Give the person the link to open; it works only on this machine and while this session runs.",
5882
- annotations: ro
5883
- },
5884
- run4(async () => {
5808
+ run4(async ({ view = "contexts", at, limit, browser, context }) => {
5809
+ if (browser && this.o.browserView) {
5885
5810
  const url = await this.o.browserView();
5886
5811
  const opened = openInBrowser(url);
5887
- return text({
5812
+ const out = {
5888
5813
  url,
5889
5814
  opened,
5890
- note: opened ? "Opened in the default browser. If no tab appeared, open the link on this machine. Don't share it: it acts as you." : "Open it in a browser on this machine. Don't share it: it acts as you."
5891
- });
5892
- })
5893
- );
5815
+ note: opened ? "Opened in the default browser. If no tab appeared, open the link on this machine. Don't share it: it acts as you. It works only on this machine and while this session runs." : "Open it in a browser on this machine. Don't share it: it acts as you. It works only on this machine and while this session runs."
5816
+ };
5817
+ return both(out, { view: "browser", ...out });
5818
+ }
5819
+ if (view === "console") {
5820
+ const state2 = await this.consoleState(context);
5821
+ return both(state2, { view, ...state2 });
5822
+ }
5823
+ if (view === "explorer") {
5824
+ if (at !== void 0) {
5825
+ const ok = isoMoment().safeParse(at);
5826
+ if (!ok.success) throw new Error(`Invalid input:
5827
+ - at: ${ok.error.issues[0]?.message}`);
5828
+ }
5829
+ const c = await this.target(context);
5830
+ const snap2 = await this.request("snapshot", { ...at ? { at } : {}, limit: limit ?? 200 }, c.name);
5831
+ const counts = {};
5832
+ for (const n of snap2.nodes) counts[n.label] = (counts[n.label] ?? 0) + 1;
5833
+ return both(
5834
+ {
5835
+ showing: this.where(c.name),
5836
+ at: snap2.at,
5837
+ nodes: counts,
5838
+ links: snap2.edges.length,
5839
+ truncated: snap2.truncated,
5840
+ note: "The explorer shows the picture to the person; this summary is all you get here."
5841
+ },
5842
+ { view, ...snap2, where: this.where(c.name) }
5843
+ );
5844
+ }
5845
+ if (!this.contexts.size) {
5846
+ const none = { using: "no context", context: null, contexts: [], your_contexts: this.localNames(), next: this.noContext() };
5847
+ return both(none, { view, ...none });
5848
+ }
5849
+ const state = await this.activity({ limit: 40, snapshot: true, context });
5850
+ const snap = state.snapshot;
5851
+ return both({ showing: state.using, context: state.context, items: snap.nodes.length, note: "The person is looking at the contexts panel." }, { view, ...state });
5852
+ })
5853
+ );
5894
5854
  }
5895
5855
  /** What share_context says about a new invite. */
5896
5856
  /** What to tell the person about the name others see, when they didn't choose it themselves. */
5897
5857
  nameNote() {
5898
5858
  const source = nameSource(this.dataDir);
5899
5859
  const { name } = this.o.identity();
5900
- if (source === "VINE_USER" || source === "set_my_name") return {};
5860
+ if (source === "VINE_USER" || source === "chosen") return {};
5901
5861
  if (isGuessedName(source))
5902
5862
  return {
5903
- your_name: `Others see this person as '${name}', which is ${source === "login" ? "only their login name" : "a made-up name"}. If this chat hasn't asked yet, ask what name they want and save it with set_my_name; if they'd rather not say, '${name}' stays.`
5863
+ your_name: `Others see this person as '${name}', which is ${source === "login" ? "only their login name" : "a made-up name"}. If this chat hasn't asked yet, ask what name they want and save it with update_context (my_name); if they'd rather not say, '${name}' stays.`
5904
5864
  };
5905
5865
  return {
5906
- your_name: `Others see this person as '${name}' (${source === "git" ? "from git's user.name" : "the full name on their computer account"}). If this chat hasn't told them yet, do, and offer set_my_name if they want another.`
5866
+ your_name: `Others see this person as '${name}' (${source === "git" ? "from git's user.name" : "the full name on their computer account"}). If this chat hasn't told them yet, do, and offer update_context (my_name) if they want another.`
5907
5867
  };
5908
5868
  }
5909
5869
  invited(r, context) {
@@ -5915,7 +5875,7 @@ This chat uses ${this.contexts.size} contexts.${this.contextsLine()} Reads searc
5915
5875
  invite: { id: r.id, label: r.label, role: r.role, expires_at: r.expires_at },
5916
5876
  shared_as: { name: identity.name, fingerprint: fingerprint(identity.publicKey) },
5917
5877
  ...this.nameNote(),
5918
- next: "Give the person the 'send' line to pass on privately (not in a public channel). Agents without the plugin command can be told: join the context with this code. This machine answers the code, so it must be online when they use it. Whoever uses it first is let in at once and gets a full copy, and everyone in the context is told who joined (name, key fingerprint, agent). Each code is for one person: call share_context again for the next. remove_peer takes anyone out."
5878
+ next: "Give the person the 'send' line to pass on privately (not in a public channel). Agents without the plugin command can be told: join the context with this code. This machine answers the code, so it must be online when they use it. Whoever uses it first is let in at once and gets a full copy, and everyone in the context is told who joined (name, key fingerprint, agent). Each code is for one person: call share_context again for the next. manage_member takes anyone out."
5919
5879
  };
5920
5880
  }
5921
5881
  /** Joins a context with a code: gets its whole log from the machine that made the code, keeps a copy here, adds it to this chat (writes go to it) and briefs the agent. */
@@ -6936,11 +6896,11 @@ ${plan.map((p) => ` ${p}`).join("\n")}`);
6936
6896
  const cur = d.name.current();
6937
6897
  if (cur.source === "VINE_USER") record({ step: "name", status: "ok", detail: `${cur.name} (from VINE_USER)` });
6938
6898
  else {
6939
- const from = { set_my_name: "set before", git: "from git", os: "from your computer account", login: "your login name", generated: "made up" }[cur.source] ?? cur.source;
6899
+ const from = { chosen: "set before", git: "from git", os: "from your computer account", login: "your login name", generated: "made up" }[cur.source] ?? cur.source;
6940
6900
  const guessed = cur.source === "login" || cur.source === "generated";
6941
6901
  const question = guessed ? ` Your name, as others will see it (Enter keeps ${cur.name}, ${from})` : ` The name others see you as (${from})`;
6942
6902
  const name = (await d.prompt.ask(question, cur.name)).trim().slice(0, 60);
6943
- if (cur.source === "set_my_name" && name === cur.name) record({ step: "name", status: "ok", detail: `${name}` });
6903
+ if (cur.source === "chosen" && name === cur.name) record({ step: "name", status: "ok", detail: `${name}` });
6944
6904
  else if (!name) record({ step: "name", status: "skipped", detail: `kept ${cur.name}` });
6945
6905
  else if (guessed && name === cur.name) record({ step: "name", status: "skipped", detail: `using ${cur.name} for now (${from}); set your own with \`vine setup\`` });
6946
6906
  else {
@@ -7244,7 +7204,7 @@ function briefing2(dataDir, names2, writeTo) {
7244
7204
  const s = summary(dataDir, name);
7245
7205
  const who = s.members > 1 ? `shared with ${plural(s.members - 1, "other member")}` : "only this machine's person so far";
7246
7206
  lines.push(`Vine Context: this chat uses the shared context "${name}" (${who}).`);
7247
- lines.push(s.description ? `What it is for: ${s.description}` : "It has no description yet (describe_context sets one).");
7207
+ lines.push(s.description ? `What it is for: ${s.description}` : "It has no description yet (update_context sets one).");
7248
7208
  lines.push(`${plural(s.claims, "claim")} and ${plural(s.questions, "question")} have been recorded in it.`);
7249
7209
  }
7250
7210
  if (names2.length > 1 && writeTo) lines.push(`Writes from this chat go to "${writeTo}" unless a call names another.`);
@@ -7374,7 +7334,7 @@ Commands:
7374
7334
  --version Print the version
7375
7335
 
7376
7336
  Environment:
7377
- VINE_USER Your name in contexts (default: the name you set with set_my_name, else git's user.name, else your computer account's full name, else your login name, else a made-up one)
7337
+ VINE_USER Your name in contexts (default: the name you set (update_context, or vine setup), else git's user.name, else your computer account's full name, else your login name, else a made-up one)
7378
7338
  VINE_CONTEXT The context a new chat starts with when its folder has none linked (default: none; the agent asks)
7379
7339
  VINE_CHAT The chat's id, to remember its context (default: Claude Code's session id)
7380
7340
  VINE_DATA_DIR Where contexts live (default: ~/.local/share/vine-context)