@bendyline/gezel-mcp 1.0.3 → 1.0.4

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/server.d.ts CHANGED
@@ -15,6 +15,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
15
15
  * GEZEL_PROJECT_ID — the project context
16
16
  * GEZEL_SESSION_ID — the chat session this subprocess serves
17
17
  * GEZEL_HOME — path to ~/.gezel (for direct memory access)
18
+ * GEZEL_ROLE_BASED_NAME_ONLY_MODE — 1/0 naming presentation inherited by new tasks
18
19
  * GEZEL_CRAFTBOOK_ID — explicit craftbook-editor context (loads step surgery)
19
20
  * GEZEL_MCP_LEGACY_TOOLS=1 — expose compatibility aliases during migration
20
21
  */
package/dist/server.js CHANGED
@@ -46,6 +46,59 @@ function commandResultIsError(result) {
46
46
  return !result.ok && result.approvalPending !== true;
47
47
  }
48
48
 
49
+ // src/craftbook-invocation-idempotency.ts
50
+ import { createHash } from "crypto";
51
+ function rootTurnIdFromMessages(sessionId2, messages) {
52
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
53
+ const message = messages[index];
54
+ if (message?.role === "user") return `${sessionId2}:${index}:${message.at}`;
55
+ }
56
+ return null;
57
+ }
58
+ function canonicalize(value) {
59
+ if (Array.isArray(value)) return value.map(canonicalize);
60
+ if (value && typeof value === "object") {
61
+ return Object.fromEntries(
62
+ Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, canonicalize(entry)])
63
+ );
64
+ }
65
+ return value;
66
+ }
67
+ function invocationSignature(invocation) {
68
+ return JSON.stringify(canonicalize(invocation));
69
+ }
70
+ function rootTurnInvocationKey(rootTurnId, invocation) {
71
+ return `craftbook-root-v1:${createHash("sha256").update(rootTurnId).update("\n").update(invocationSignature(invocation)).digest("hex")}`;
72
+ }
73
+ var RootTurnInvocationCache = class {
74
+ constructor(maxEntries = 128) {
75
+ this.maxEntries = maxEntries;
76
+ }
77
+ maxEntries;
78
+ entries = /* @__PURE__ */ new Map();
79
+ async run(args) {
80
+ const key = `${args.rootTurnId}
81
+ ${invocationSignature(args.invocation)}`;
82
+ const existing = this.entries.get(key);
83
+ if (existing) return { value: await existing, reused: true };
84
+ const pending = args.execute();
85
+ this.entries.set(key, pending);
86
+ while (this.entries.size > this.maxEntries) {
87
+ const oldest = this.entries.keys().next().value;
88
+ if (oldest === void 0) break;
89
+ this.entries.delete(oldest);
90
+ }
91
+ try {
92
+ const value = await pending;
93
+ if (args.cacheResult && !args.cacheResult(value)) this.entries.delete(key);
94
+ return { value, reused: false };
95
+ } catch (error) {
96
+ this.entries.delete(key);
97
+ throw error;
98
+ }
99
+ }
100
+ };
101
+
49
102
  // src/craftbook-routing.ts
50
103
  import { z as z2 } from "zod";
51
104
 
@@ -1060,7 +1113,8 @@ var GitToolOutputSchema = ExecutionToolOutputSchema.extend({
1060
1113
  });
1061
1114
  var MemorySaveToolOutputSchema = ToolResultSummarySchema.extend({
1062
1115
  status: z3.enum(["saved", "duplicate"]),
1063
- scope: z3.enum(["gezel", "project"])
1116
+ scope: z3.enum(["gezel", "project"]),
1117
+ indexed: z3.boolean().optional()
1064
1118
  });
1065
1119
  var MemoryListToolOutputSchema = ToolResultSummarySchema.extend({
1066
1120
  scope: z3.enum(["gezel", "project"]),
@@ -2697,6 +2751,8 @@ var gezelId = process.env.GEZEL_AGENT_ID ?? "";
2697
2751
  var projectId = process.env.GEZEL_PROJECT_ID ?? "default";
2698
2752
  var sessionId = process.env.GEZEL_SESSION_ID ?? "";
2699
2753
  var sessionStepId = process.env.GEZEL_STEP_ID ?? "";
2754
+ var sessionRoleBasedNameOnlyMode = process.env.GEZEL_ROLE_BASED_NAME_ONLY_MODE === "1" ? true : process.env.GEZEL_ROLE_BASED_NAME_ONLY_MODE === "0" ? false : void 0;
2755
+ var sessionTaskNamingMode = sessionRoleBasedNameOnlyMode === void 0 ? {} : { roleBasedNameOnlyMode: sessionRoleBasedNameOnlyMode };
2700
2756
  var sessionTaskRef = process.env.GEZEL_TASK_REF ?? "";
2701
2757
  var sessionCraftbookId = process.env.GEZEL_CRAFTBOOK_ID ?? "";
2702
2758
  var certPath = process.env.GEZEL_CERT_PATH;
@@ -2816,7 +2872,8 @@ server.tool(
2816
2872
  }
2817
2873
  const data = await res.json();
2818
2874
  const results = data.results ?? [];
2819
- const summary = results.length ? `Found ${results.length} relevant ${results.length === 1 ? "memory" : "memories"}.` : "No relevant memories found.";
2875
+ const resultSummary = results.length ? `Found ${results.length} relevant ${results.length === 1 ? "memory" : "memories"}.` : "No relevant memories found.";
2876
+ const summary = data.degraded?.message ? `${data.degraded.message} ${resultSummary}` : resultSummary;
2820
2877
  const formatted = results.map((r) => `[${r.scope}/${r.day} score=${r.score.toFixed(2)}] ${r.text}`).join("\n\n");
2821
2878
  return okResult(
2822
2879
  SearchToolOutputSchema,
@@ -2825,7 +2882,9 @@ server.tool(
2825
2882
  query,
2826
2883
  matches: results,
2827
2884
  count: results.length,
2828
- truncated: false
2885
+ truncated: false,
2886
+ ...data.mode ? { mode: data.degraded ? `${data.mode}-fallback` : data.mode } : {},
2887
+ engine: data.mode === "semantic" || data.mode === "hybrid" ? "sqlite-vec" : "markdown"
2829
2888
  },
2830
2889
  { text: formatted ? `${summary}
2831
2890
  ${formatted}` : summary }
@@ -2867,8 +2926,19 @@ server.tool(
2867
2926
  }
2868
2927
  const data = await res.json().catch(() => ({}));
2869
2928
  const status = data.status === "duplicate" ? "duplicate" : "saved";
2870
- const summary = status === "duplicate" ? `Memory already existed (${scope}); no duplicate was added.` : `Memory saved (${scope}).`;
2871
- return okResult(MemorySaveToolOutputSchema, { summary, status, scope }, { text: summary });
2929
+ const savedSummary = status === "duplicate" ? `Memory already existed (${scope}); no duplicate was added.` : `Memory saved (${scope}).`;
2930
+ const degradedMessage = data.degraded && typeof data.degraded.message === "string" ? data.degraded.message : void 0;
2931
+ const summary = degradedMessage ? `${savedSummary} ${degradedMessage}` : savedSummary;
2932
+ return okResult(
2933
+ MemorySaveToolOutputSchema,
2934
+ {
2935
+ summary,
2936
+ status,
2937
+ scope,
2938
+ ...typeof data.indexed === "boolean" ? { indexed: data.indexed } : {}
2939
+ },
2940
+ { text: summary }
2941
+ );
2872
2942
  } catch (err) {
2873
2943
  return errorResult(`save_memory failed: ${unwrapApiError(err)}`);
2874
2944
  }
@@ -4672,8 +4742,13 @@ async function responseErrorMessage(res) {
4672
4742
  if (body) {
4673
4743
  try {
4674
4744
  const parsed = JSON.parse(body);
4675
- if (typeof parsed.error === "string" && parsed.error) return parsed.error;
4676
- if (typeof parsed.message === "string" && parsed.message) return parsed.message;
4745
+ const requestSuffix = typeof parsed.requestId === "string" && parsed.requestId ? ` (request id: ${parsed.requestId})` : "";
4746
+ if (typeof parsed.error === "string" && parsed.error) {
4747
+ return `${parsed.error}${requestSuffix}`;
4748
+ }
4749
+ if (typeof parsed.message === "string" && parsed.message) {
4750
+ return `${parsed.message}${requestSuffix}`;
4751
+ }
4677
4752
  } catch {
4678
4753
  }
4679
4754
  return body.length > 1e3 ? `${body.slice(0, 1e3)}\u2026` : body;
@@ -5972,6 +6047,16 @@ async function requestCraftbookToolsetInstalls(project, craftbookId, requirement
5972
6047
  }
5973
6048
  return installed;
5974
6049
  }
6050
+ var invokeCraftbookRootTurnCache = new RootTurnInvocationCache();
6051
+ async function currentRootTurnId() {
6052
+ if (!sessionId) return null;
6053
+ try {
6054
+ const session = await api.getChatSession(sessionId);
6055
+ return rootTurnIdFromMessages(sessionId, session.messages);
6056
+ } catch {
6057
+ return null;
6058
+ }
6059
+ }
5975
6060
  async function launchCraftbookTask(args) {
5976
6061
  let projectCraftbooks = await api.listProjectCraftbooks(args.project);
5977
6062
  let missing = projectCraftbooks.missingToolsets[args.craftbookId] ?? [];
@@ -6004,12 +6089,14 @@ async function launchCraftbookTask(args) {
6004
6089
  }
6005
6090
  const craftbookName = projectCraftbooks.items.find((item) => item.manifest.id === args.craftbookId)?.manifest.name ?? args.craftbookId;
6006
6091
  const task = await api.createTask(args.project, {
6092
+ ...sessionTaskNamingMode,
6007
6093
  title: args.title ?? craftbookName,
6008
6094
  description: normalizedCraftbookTaskDescription(args.description, args.craftbookId),
6009
6095
  craftbookId: args.craftbookId,
6010
6096
  ...args.version ? { craftbookVersion: args.version } : {},
6011
6097
  ...args.params && Object.keys(args.params).length > 0 ? { craftbookParams: args.params } : {},
6012
6098
  ...args.assignee ? { assignee: assigneeFromArg(args.assignee) } : {},
6099
+ ...args.craftbookInvocationKey ? { craftbookInvocationKey: args.craftbookInvocationKey } : {},
6013
6100
  ...gezelId ? { createdBy: { kind: "gezel", gezelId } } : {},
6014
6101
  dispatchEntry: true
6015
6102
  });
@@ -6232,7 +6319,7 @@ server.tool(
6232
6319
  const resolvedProject = project ? await resolveProjectId(project) : projectId;
6233
6320
  try {
6234
6321
  const invocationParams = normalizeCraftbookInvocationParams(params, outputPath);
6235
- const launch = await launchCraftbookTask({
6322
+ const invocation = {
6236
6323
  craftbookId,
6237
6324
  project: resolvedProject,
6238
6325
  title,
@@ -6240,7 +6327,19 @@ server.tool(
6240
6327
  version,
6241
6328
  assignee,
6242
6329
  params: invocationParams
6243
- });
6330
+ };
6331
+ const rootTurnId = await currentRootTurnId();
6332
+ const launchInvocation = rootTurnId ? {
6333
+ ...invocation,
6334
+ craftbookInvocationKey: rootTurnInvocationKey(rootTurnId, invocation)
6335
+ } : invocation;
6336
+ const launched = rootTurnId ? await invokeCraftbookRootTurnCache.run({
6337
+ rootTurnId,
6338
+ invocation,
6339
+ execute: () => launchCraftbookTask(launchInvocation),
6340
+ cacheResult: (result) => result.kind !== "setup-required"
6341
+ }) : { value: await launchCraftbookTask(launchInvocation), reused: false };
6342
+ const launch = launched.value;
6244
6343
  if (launch.kind === "setup-required") {
6245
6344
  return {
6246
6345
  content: [
@@ -6255,11 +6354,12 @@ server.tool(
6255
6354
  const created = launch.task;
6256
6355
  const stepCount = created.craftbook.steps.length;
6257
6356
  const installedText = launch.installed.length > 0 ? ` Installed or upgraded project toolset${launch.installed.length === 1 ? "" : "s"}: ${launch.installed.join(", ")}.` : "";
6357
+ const idempotentText = launched.reused ? " This identical craftbook invocation already succeeded in the current root turn; reused its task instead of creating a duplicate." : "";
6258
6358
  return {
6259
6359
  content: [
6260
6360
  {
6261
6361
  type: "text",
6262
- text: `Invoked craftbook "${craftbookId}" \u2014 task ${created.ref} (${stepCount} step(s)). Active step ${created.activeStepId ?? "(none)"} was dispatched to the recipe-selected specialist.${installedText}`
6362
+ text: `Invoked craftbook "${craftbookId}" \u2014 task ${created.ref} (${stepCount} step(s)). Active step ${created.activeStepId ?? "(none)"} was dispatched to the recipe-selected specialist.${installedText}${idempotentText}`
6263
6363
  }
6264
6364
  ]
6265
6365
  };
@@ -7623,7 +7723,7 @@ function normalizeSpecialistRole(value) {
7623
7723
  }
7624
7724
  const resolved = resolveRoleId(lower) ?? resolveRoleId(normalized);
7625
7725
  if (resolved && resolved !== "meester" && resolved !== "voorman") return resolved;
7626
- return "developer";
7726
+ return "builder";
7627
7727
  }
7628
7728
  function repoFetchRedirectForMacro(input) {
7629
7729
  const text = `${input.name}
@@ -7919,6 +8019,7 @@ ${idempotent.resultText}`
7919
8019
  `${brief.name} ${brief.about ?? ""} ${brief.taskDescription ?? ""} ${effectiveTaskDescription}`
7920
8020
  ) : null;
7921
8021
  const task = crewLoop ? await api.createTask(project.id, {
8022
+ ...sessionTaskNamingMode,
7922
8023
  title: input.taskTitle ?? `Build ${brief.name}`,
7923
8024
  description: effectiveTaskDescription,
7924
8025
  assignee: { kind: "gezel", gezelId: voorman.id },
@@ -7926,6 +8027,7 @@ ${idempotent.resultText}`
7926
8027
  entryStepId: crewLoop.entryStepId,
7927
8028
  dispatchEntry: true
7928
8029
  }) : await api.createTask(project.id, {
8030
+ ...sessionTaskNamingMode,
7929
8031
  title: input.taskTitle ?? `Build ${brief.name}`,
7930
8032
  description: effectiveTaskDescription,
7931
8033
  assignee: { kind: "gezel", gezelId: voorman.id },
@@ -8043,6 +8145,7 @@ ${idempotent.resultText}`
8043
8145
  `${brief.name} ${brief.about} ${brief.taskDescription ?? ""} ${effectiveTaskDescription}`
8044
8146
  ) : null;
8045
8147
  const task = crewLoop ? await api.createTask(project.id, {
8148
+ ...sessionTaskNamingMode,
8046
8149
  title: taskTitle ?? `Build ${brief.name}`,
8047
8150
  description: effectiveTaskDescription,
8048
8151
  assignee: { kind: "gezel", gezelId: voorman.id },
@@ -8050,6 +8153,7 @@ ${idempotent.resultText}`
8050
8153
  entryStepId: crewLoop.entryStepId,
8051
8154
  dispatchEntry: true
8052
8155
  }) : await api.createTask(project.id, {
8156
+ ...sessionTaskNamingMode,
8053
8157
  title: taskTitle ?? `Build ${brief.name}`,
8054
8158
  description: effectiveTaskDescription,
8055
8159
  assignee: { kind: "gezel", gezelId: voorman.id },
@@ -8157,11 +8261,11 @@ ${idempotent.resultText}`
8157
8261
  mode: "solo"
8158
8262
  });
8159
8263
  const { name: gezelName, gender: gezelGender } = pickRandomNameWithGender();
8160
- const ambachtsman = await api.createGezelFromTemplate(effectiveSpecialistRole, {
8264
+ const builder = await api.createGezelFromTemplate(effectiveSpecialistRole, {
8161
8265
  name: gezelName,
8162
8266
  gender: gezelGender
8163
8267
  });
8164
- await api.updateProject(project.id, { voormanGezelId: ambachtsman.id });
8268
+ await api.updateProject(project.id, { voormanGezelId: builder.id });
8165
8269
  const effectiveTaskDescription = buildKickoffTaskDescription({
8166
8270
  ...brief,
8167
8271
  ...kickoffMessage ? { kickoffNote: kickoffMessage } : {}
@@ -8172,21 +8276,23 @@ ${idempotent.resultText}`
8172
8276
  });
8173
8277
  const craftbookPick = await pickCraftbookForBrief(project.id, brief);
8174
8278
  const soloLoop = craftbookPick ? await buildSoloLoopSteps(
8175
- ambachtsman.id,
8279
+ builder.id,
8176
8280
  sourceDeliverablePath ?? "index.html",
8177
8281
  `${brief.name} ${brief.about} ${brief.taskDescription ?? ""} ${effectiveTaskDescription}`
8178
8282
  ) : null;
8179
8283
  const task = soloLoop ? await api.createTask(project.id, {
8284
+ ...sessionTaskNamingMode,
8180
8285
  title: taskTitle ?? `Build ${brief.name}`,
8181
8286
  description: effectiveTaskDescription,
8182
- assignee: { kind: "gezel", gezelId: ambachtsman.id },
8287
+ assignee: { kind: "gezel", gezelId: builder.id },
8183
8288
  steps: soloLoop.steps,
8184
8289
  entryStepId: soloLoop.entryStepId,
8185
8290
  dispatchEntry: true
8186
8291
  }) : await api.createTask(project.id, {
8292
+ ...sessionTaskNamingMode,
8187
8293
  title: taskTitle ?? `Build ${brief.name}`,
8188
8294
  description: effectiveTaskDescription,
8189
- assignee: { kind: "gezel", gezelId: ambachtsman.id },
8295
+ assignee: { kind: "gezel", gezelId: builder.id },
8190
8296
  steps: [
8191
8297
  {
8192
8298
  name: "Plan and execute",
@@ -8196,7 +8302,7 @@ ${idempotent.resultText}`
8196
8302
  ],
8197
8303
  dispatchEntry: true
8198
8304
  });
8199
- const resultText = `Started project "${brief.name}" (${project.id}). Recruited ${ambachtsman.name} as lead (template: ${effectiveSpecialistRole}). Created task ${task.ref} ("${task.title}") and handed ${ambachtsman.name} its entry step \u2014 they are starting now in a task-scoped session. No reply lands in this thread; progress accrues on the task (notes, gates, status \u2014 get_task / read_task_notes when the user asks). Tell the user ${ambachtsman.name} is on it and they can watch the work in the ${brief.name} project.`;
8305
+ const resultText = `Started project "${brief.name}" (${project.id}). Recruited ${builder.name} as lead (template: ${effectiveSpecialistRole}). Created task ${task.ref} ("${task.title}") and handed ${builder.name} its entry step \u2014 they are starting now in a task-scoped session. No reply lands in this thread; progress accrues on the task (notes, gates, status \u2014 get_task / read_task_notes when the user asks). Tell the user ${builder.name} is on it and they can watch the work in the ${brief.name} project.`;
8200
8306
  recordMacroResult(cacheTool, brief.name, project.id, resultText);
8201
8307
  return {
8202
8308
  content: [
@@ -8663,6 +8769,7 @@ server.tool(
8663
8769
  try {
8664
8770
  const projectId2 = await resolveProjectId(project);
8665
8771
  const created = await api.createTask(projectId2, {
8772
+ ...sessionTaskNamingMode,
8666
8773
  title,
8667
8774
  description,
8668
8775
  ...plan ? { plan } : {},
@@ -8725,6 +8832,7 @@ server.tool(
8725
8832
  const resolvedProject = project ? await resolveProjectId(project) : projectId;
8726
8833
  const assignee = gezelId ? { kind: "gezel", gezelId } : { kind: "user" };
8727
8834
  const draft = await api.createTask(resolvedProject, {
8835
+ ...sessionTaskNamingMode,
8728
8836
  title: title ?? `Plan: ${goal.slice(0, 60)}`,
8729
8837
  description: `DRAFT PLAN (being authored). User goal: ${goal}`.padEnd(40, " "),
8730
8838
  status: "draft",
@@ -8737,6 +8845,7 @@ server.tool(
8737
8845
  ]
8738
8846
  });
8739
8847
  const authoring = await api.createTask(resolvedProject, {
8848
+ ...sessionTaskNamingMode,
8740
8849
  title: `Author plan for ${draft.ref}`,
8741
8850
  description: `Run the plan craftbook to author task ${draft.ref}. User goal: ${goal}`,
8742
8851
  craftbookId: "plan",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/gezel-mcp",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Gezel MCP server — gives agents access to memory, workspace, artifacts, and tools.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -55,8 +55,8 @@
55
55
  "!dist/**/*.map"
56
56
  ],
57
57
  "dependencies": {
58
- "@bendyline/gezel": "1.0.3",
59
- "@bendyline/gezel-client": "1.0.3",
58
+ "@bendyline/gezel": "1.0.4",
59
+ "@bendyline/gezel-client": "1.0.4",
60
60
  "@modelcontextprotocol/sdk": "^1.29.0",
61
61
  "typescript": "^6.0.3",
62
62
  "zod": "^4.4.3"