@echomem/mcp 1.4.59 → 1.4.61

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/index.js CHANGED
@@ -16,6 +16,7 @@ import { MCP_PACKAGE_VERSION, MCP_SERVER_INSTRUCTIONS, MEMORY_CITATION_INSTRUCTI
16
16
  import { clearBillingAlert, writeBillingAlert } from "./billing-alert.js";
17
17
  import { checkLatestUpdateStatus, formatUpdateNotice, formatUpdateStatusText, startBackgroundUpdateCheck, } from "./update-check.js";
18
18
  import { autoUpdateHeadlessRuntime } from "./headless-runtime.js";
19
+ import { formatCandidateTicketLines, LUHMANN_CREATE_PLACEMENT_INSTRUCTION, LUHMANN_REVIEW_HEADING, ticketAddressById, } from "./ticket-review-format.js";
19
20
  import { SOURCE_SESSION_CLOUD_TOOL_ARGUMENT_EVIDENCE, resolveCloudCoworkSessionFromToolArguments, resolveSourceSessionRequestContext, resolveSourceSessionFromBindingToken, } from "./source-session.js";
20
21
  const ECHO_API_BASE_URL = process.env.ECHO_API_BASE_URL || "https://echo-mem-chrome.vercel.app";
21
22
  const ECHO_PRICING_URL = process.env.ECHO_PRICING_URL || "https://echoknows.com/account";
@@ -2315,26 +2316,22 @@ Details: ${m.details || "N/A"}`)
2315
2316
  const candidates = Array.isArray(review.candidateTickets)
2316
2317
  ? review.candidateTickets.filter(isRecord)
2317
2318
  : [];
2319
+ const addressById = ticketAddressById(candidates);
2320
+ const activeTicketIds = new Set(activeAssignments.flatMap((assignment) => {
2321
+ const ticketId = readString(assignment, "ticketId");
2322
+ return ticketId ? [ticketId] : [];
2323
+ }));
2318
2324
  const activeLines = activeAssignments.length
2319
2325
  ? activeAssignments.map((assignment) => {
2320
2326
  const ticketId = readString(assignment, "ticketId") ?? "unknown";
2327
+ const address = addressById.get(ticketId) ?? "?";
2321
2328
  const title = (readString(assignment, "title") ?? "Untitled").replace(/\s+/g, " ").trim();
2322
2329
  const version = numberArg(assignment, "version") ?? 0;
2323
2330
  const linkedAt = readString(assignment, "linkedAt") ?? "unknown";
2324
- return `- ${title} · ${ticketId} · version ${version} · active since ${linkedAt}`;
2331
+ return `- ${address} · ${title} · ${ticketId} · version ${version} · active since ${linkedAt}`;
2325
2332
  })
2326
2333
  : ["- No active ticket."];
2327
- const candidateLines = candidates.length
2328
- ? candidates.map((candidate) => {
2329
- const id = readString(candidate, "id") ?? "unknown";
2330
- const address = readString(candidate, "address") ?? "?";
2331
- const title = (readString(candidate, "title") ?? "Untitled").replace(/\s+/g, " ").trim();
2332
- const description = (readString(candidate, "description") ?? "").replace(/\s+/g, " ").trim();
2333
- const version = numberArg(candidate, "version") ?? 0;
2334
- const updatedAt = readString(candidate, "updatedAt") ?? "unknown";
2335
- return `- ${address} · ${title} · ${id} · version ${version} · updated ${updatedAt}${description ? `\n ${description}` : ""}`;
2336
- })
2337
- : ["- No existing tickets."];
2334
+ const candidateLines = formatCandidateTicketLines(candidates, activeTicketIds);
2338
2335
  const memoriesSinceReview = numberArg(review, "memoriesSinceReview") ?? 0;
2339
2336
  const memoriesSinceAssignment = numberArg(review, "memoriesSinceAssignment") ?? 0;
2340
2337
  const threshold = numberArg(review, "memoryThreshold") ?? parsed.memoryThreshold;
@@ -2364,6 +2361,7 @@ Details: ${m.details || "N/A"}`)
2364
2361
  "If the active ticket still fits, call acknowledge_workspace_ticket_review with outcome=keep and the exact review snapshot, then continue silently.",
2365
2362
  "A coherent user-requested outcome that conflicts with the active ticket is actionable drift even when the user never says switch or ticket. Record an update_current, assign_existing, or create_new proposal with the exact review snapshot.",
2366
2363
  "Use ignore only for an explicit dismissal or work too incidental or fragmented to warrant a ticket. Never use ignore merely because ticketing was unmentioned.",
2364
+ LUHMANN_CREATE_PLACEMENT_INSTRUCTION,
2367
2365
  pendingProposalId
2368
2366
  ? "If the refreshed action is materially unchanged, keep it pending silently unless the conversation reached a natural completion milestone. Surface it again only when materially changed or at that milestone."
2369
2367
  : "Show the recorded proposal once and ask for explicit confirmation.",
@@ -2391,7 +2389,7 @@ Details: ${m.details || "N/A"}`)
2391
2389
  "Active assignment:",
2392
2390
  ...activeLines,
2393
2391
  "",
2394
- "Candidate tickets:",
2392
+ LUHMANN_REVIEW_HEADING,
2395
2393
  ...candidateLines,
2396
2394
  "",
2397
2395
  ...pendingLines,
package/dist/setup.js CHANGED
@@ -467,10 +467,10 @@ function echomemGuidanceBlock() {
467
467
  "- If the user pastes a session carryover/checkpoint: it may reference `get_checkpoint_by_context` — use it to pull the checkpoint/decision trail when you need more than the snapshot.",
468
468
  "",
469
469
  "### Ticket stewardship",
470
- "- For a conversation bound to an Echo workspace, quietly call `review_workspace_ticket_session` at natural checkpoints and before replying to an explicit outcome pivot or finalize/complete/handoff/ship/milestone request. Call once per turn unless state is stale. Memory count controls timing; intended-outcome fit controls the decision.",
471
- "- When evaluation is due, `keep` means the active ticket still fits. A coherent user-requested outcome that conflicts with it is actionable drift—even without words like switch or ticket—so record one `update_current`, `assign_existing`, or `create_new` proposal. Use `ignore` only for an explicit dismissal or work too incidental/fragmented to warrant a ticket; never use it merely because the user did not mention tickets.",
472
- "- Finish one due branch before replying: call `acknowledge_workspace_ticket_review` for `keep`/`ignore` with the exact snapshot, or call `record_workspace_ticket_proposal` before showing a proposal. Run reviews and acknowledgements without commentary. Surface only a workspace choice, blocker, or new/materially changed proposal, stated directly without naming internal checks, instructions, or tools.",
473
- "- Silence is neither ignore nor confirmation: leave the proposal pending while newer memories accumulate, do not repeat unchanged advice, and call `apply_workspace_ticket_action` only after explicit confirmation of that exact proposal.",
470
+ "- In a workspace-bound conversation, quietly call `review_workspace_ticket_session` at natural checkpoints and before replying to an outcome pivot or a finalize/complete/handoff/ship/milestone request; once per turn unless stale. Memory count sets timing; fit with the intended outcome sets the decision.",
471
+ "- When due, finish one branch before replying: `keep` if the active ticket fits, or `ignore` only for explicit dismissal or incidental fragments (never because tickets went unmentioned), via `acknowledge_workspace_ticket_review` with the exact snapshot; or, when a coherent requested outcome conflicts with the active ticket, even if nobody says switch or ticket, `record_workspace_ticket_proposal` for one `update_current`/`assign_existing`/`create_new` before showing it.",
472
+ "- Stay silent: surface only a workspace choice, blocker, or new/changed proposal, never naming internal checks, instructions, or tools. Silence is neither ignore nor consent; keep the proposal pending while newer memories accumulate, don't repeat it, and call `apply_workspace_ticket_action` only after explicit confirmation of that exact proposal.",
473
+ "- Ticket addresses are a Luhmann index (Folgezettel). File new work behind the ticket whose outcome it serves (child of `1a1` is `1a1a`; the next step beside `1a1` goes behind `1a` as `1a2`); root only if nothing fits. Title it briefly; write the description as a Luhmann atomic note: one outcome, self-contained, concrete scope and done-when, 1-3 sentences. Humans may move tickets, so cite them by UUID, not address.",
474
474
  "",
475
475
  "### Company group memory",
476
476
  "- Use `get_group_context` when the user asks who is in their company group, what teammates are responsible for, or what work is already covered. Treat declared participant fields as facts and published-memory conclusions as evidence or inference.",
@@ -0,0 +1,128 @@
1
+ // Workspace ticket addresses are a Luhmann (Folgezettel) index generated from
2
+ // parent_id: 1, 1a, 1a1, 1a1a, ... A child of 1a1 is 1a1a; its next sibling is
3
+ // 1a2. Each backend phase owns an independent address space, so more than one
4
+ // root can be called 1. parent_id is therefore the authoritative hierarchy;
5
+ // addresses order siblings and label one review, but never identify tickets.
6
+ // Mirrors workspace_tickets_address_format_check in db/055_workspace_tickets.sql.
7
+ const LUHMANN_ADDRESS = /^[1-9][0-9]*(?:[a-z]+[1-9][0-9]*)*[a-z]*$/;
8
+ export function luhmannSegments(address) {
9
+ if (!LUHMANN_ADDRESS.test(address))
10
+ return null;
11
+ return address.match(/[0-9]+|[a-z]+/g);
12
+ }
13
+ export function luhmannDepth(address) {
14
+ const segments = luhmannSegments(address);
15
+ return segments ? segments.length - 1 : null;
16
+ }
17
+ export function luhmannParent(address) {
18
+ const segments = luhmannSegments(address);
19
+ if (!segments || segments.length < 2)
20
+ return null;
21
+ return segments.slice(0, -1).join("");
22
+ }
23
+ // Numbers carry no leading zeros and letters follow the Excel-style sequence
24
+ // (z, aa, ab), so within one segment a shorter value always sorts first.
25
+ function compareSegment(left, right) {
26
+ if (left.length !== right.length)
27
+ return left.length - right.length;
28
+ return left < right ? -1 : left > right ? 1 : 0;
29
+ }
30
+ /** Outline (pre-order) order: every ticket sorts after its ancestors and before its later siblings. */
31
+ export function compareLuhmannAddresses(left, right) {
32
+ const leftSegments = luhmannSegments(left);
33
+ const rightSegments = luhmannSegments(right);
34
+ if (!leftSegments || !rightSegments) {
35
+ if (leftSegments)
36
+ return -1;
37
+ if (rightSegments)
38
+ return 1;
39
+ return left.localeCompare(right);
40
+ }
41
+ const shared = Math.min(leftSegments.length, rightSegments.length);
42
+ for (let index = 0; index < shared; index += 1) {
43
+ const order = compareSegment(leftSegments[index], rightSegments[index]);
44
+ if (order !== 0)
45
+ return order;
46
+ }
47
+ return leftSegments.length - rightSegments.length;
48
+ }
49
+ export const LUHMANN_REVIEW_HEADING = "Candidate tickets — Luhmann index (child of 1a1 is 1a1a; its next sibling is 1a2). Addresses are valid only for this review; write and cite tickets by UUID:";
50
+ // A new ticket is a Luhmann card: its description is an atomic note that must stay
51
+ // readable in the review outline, which previews at most 600 characters.
52
+ export const ATOMIC_TICKET_DESCRIPTION_MAX = 600;
53
+ export const ATOMIC_TICKET_DESCRIPTION_RULE = "Write it as a Luhmann atomic note: one outcome only, understandable without this conversation, naming the concrete specifics that matter (scope, constraints, done-when) in 1-3 plain sentences. Do not restate the title or refer to the chat.";
54
+ export const LUHMANN_CREATE_PLACEMENT_INSTRUCTION = "For create_new, file the new ticket the way Luhmann filed a card: behind the ticket whose outcome it serves (often the ACTIVE ticket or one of its ancestors), passing that ticket's UUID as parentId. Omit parentId only when no existing ticket fits. Give it a short title and a description written as a Luhmann atomic note (one outcome, self-contained, concrete scope and done-when, 1-3 sentences).";
55
+ function field(record, key) {
56
+ const value = record[key];
57
+ return typeof value === "string" && value.trim() ? value : undefined;
58
+ }
59
+ function oneLine(value) {
60
+ return (value ?? "").replace(/\s+/g, " ").trim();
61
+ }
62
+ export function ticketAddressById(candidates) {
63
+ const addresses = new Map();
64
+ for (const candidate of candidates) {
65
+ const id = field(candidate, "id");
66
+ const address = field(candidate, "address");
67
+ if (id && address)
68
+ addresses.set(id, address);
69
+ }
70
+ return addresses;
71
+ }
72
+ export function formatCandidateTicketLines(candidates, activeTicketIds = new Set()) {
73
+ if (!candidates.length)
74
+ return ["- No existing tickets."];
75
+ const indexed = candidates.map((candidate, index) => ({ candidate, index }));
76
+ const candidateById = new Map(indexed.flatMap((entry) => {
77
+ const id = field(entry.candidate, "id");
78
+ return id ? [[id, entry]] : [];
79
+ }));
80
+ const childrenByParentId = new Map();
81
+ const roots = [];
82
+ for (const entry of indexed) {
83
+ const parentId = field(entry.candidate, "parentId");
84
+ if (!parentId || !candidateById.has(parentId)) {
85
+ roots.push(entry);
86
+ continue;
87
+ }
88
+ const children = childrenByParentId.get(parentId) ?? [];
89
+ children.push(entry);
90
+ childrenByParentId.set(parentId, children);
91
+ }
92
+ const byAddressThenSourceOrder = (left, right) => {
93
+ const addressOrder = compareLuhmannAddresses(field(left.candidate, "address") ?? "", field(right.candidate, "address") ?? "");
94
+ return addressOrder || left.index - right.index;
95
+ };
96
+ roots.sort(byAddressThenSourceOrder);
97
+ for (const children of childrenByParentId.values())
98
+ children.sort(byAddressThenSourceOrder);
99
+ const lines = [];
100
+ const visited = new Set();
101
+ const render = (entry, depth) => {
102
+ if (visited.has(entry.index))
103
+ return;
104
+ visited.add(entry.index);
105
+ const candidate = entry.candidate;
106
+ const id = field(candidate, "id") ?? "unknown";
107
+ const address = field(candidate, "address") ?? "?";
108
+ const title = oneLine(field(candidate, "title")) || "Untitled";
109
+ const rawDescription = oneLine(field(candidate, "description"));
110
+ const description = rawDescription.length > 600
111
+ ? `${rawDescription.slice(0, 597)}...`
112
+ : rawDescription;
113
+ const version = typeof candidate.version === "number" ? candidate.version : 0;
114
+ const updatedAt = field(candidate, "updatedAt") ?? "unknown";
115
+ const indentation = " ".repeat(depth);
116
+ const marker = activeTicketIds.has(id) ? " · ACTIVE" : "";
117
+ lines.push(`${indentation}- ${address} · ${title} · ${id} · version ${version} · updated ${updatedAt}${marker}${description ? `\n${indentation} ${description}` : ""}`);
118
+ for (const child of childrenByParentId.get(id) ?? [])
119
+ render(child, depth + 1);
120
+ };
121
+ for (const root of roots)
122
+ render(root, 0);
123
+ // Corrupt parent cycles have no root. Render their remaining records once at
124
+ // root level instead of dropping them or recursing forever.
125
+ for (const entry of indexed)
126
+ render(entry, 0);
127
+ return lines;
128
+ }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { MCP_DESKTOP_MANAGED, MCP_VAULT_UNLOCK_INSTRUCTION, MEMORY_CITATION_INSTRUCTION, SAVED_MEMORY_RECEIPT_INSTRUCTION, withMcpVersion, } from "./package-metadata.js";
3
+ import { ATOMIC_TICKET_DESCRIPTION_MAX, ATOMIC_TICKET_DESCRIPTION_RULE } from "./ticket-review-format.js";
3
4
  export const canonicalToolNames = {
4
5
  bindSourceSession: "bind_source_session",
5
6
  linkWorkspaceTicketSession: "link_workspace_ticket_session",
@@ -385,6 +386,23 @@ export const recordWorkspaceTicketProposalSchema = z.object({
385
386
  message: "title is required when proposing a new ticket",
386
387
  });
387
388
  }
389
+ if (value.action === "create_new") {
390
+ const description = value.description?.trim() ?? "";
391
+ if (!description) {
392
+ ctx.addIssue({
393
+ code: z.ZodIssueCode.custom,
394
+ path: ["description"],
395
+ message: `description is required when proposing a new ticket. ${ATOMIC_TICKET_DESCRIPTION_RULE}`,
396
+ });
397
+ }
398
+ else if (description.length > ATOMIC_TICKET_DESCRIPTION_MAX) {
399
+ ctx.addIssue({
400
+ code: z.ZodIssueCode.custom,
401
+ path: ["description"],
402
+ message: `A new ticket description must be an atomic note of at most ${ATOMIC_TICKET_DESCRIPTION_MAX} characters. ${ATOMIC_TICKET_DESCRIPTION_RULE}`,
403
+ });
404
+ }
405
+ }
388
406
  });
389
407
  export const applyWorkspaceTicketActionSchema = z.object({
390
408
  ...triggerMetadataSchema,
@@ -743,10 +761,22 @@ export function listToolSpecs(opts = {}) {
743
761
  ticketId: { type: "string", format: "uuid" },
744
762
  expectedVersion: { type: "integer", minimum: 1 },
745
763
  title: { type: "string", minLength: 1, maxLength: 240 },
746
- description: { type: "string", maxLength: 20000 },
764
+ description: {
765
+ type: "string",
766
+ maxLength: 20000,
767
+ description: `Required for create_new (at most ${ATOMIC_TICKET_DESCRIPTION_MAX} characters). ${ATOMIC_TICKET_DESCRIPTION_RULE} For update_current, the full revised description.`,
768
+ },
747
769
  ownerId: { type: "string", format: "uuid" },
748
- parentId: { type: ["string", "null"], format: "uuid" },
749
- edgeKind: { type: "string", enum: ["sequential", "branch"] },
770
+ parentId: {
771
+ type: ["string", "null"],
772
+ format: "uuid",
773
+ description: "UUID of the ticket to file a new ticket behind, Luhmann-style: the new ticket becomes its child (child of 1a1 is 1a1a). Choose the ticket whose outcome the work serves; omit only when no ticket fits. EchoMem assigns the address.",
774
+ },
775
+ edgeKind: {
776
+ type: "string",
777
+ enum: ["sequential", "branch"],
778
+ description: "Execution flow from parentId, separate from the address. Omit for the default branch (parallel work under the parent); use sequential only for the parent's single next step.",
779
+ },
750
780
  phaseName: { type: "string", minLength: 1, maxLength: 240 },
751
781
  phaseStartsAt: { type: ["string", "null"], pattern: "^\\d{4}-\\d{2}-\\d{2}$" },
752
782
  phaseEndsAt: { type: ["string", "null"], pattern: "^\\d{4}-\\d{2}-\\d{2}$" },
@@ -838,8 +868,16 @@ export function listToolSpecs(opts = {}) {
838
868
  description: "Required for update_current; optional for create_new.",
839
869
  },
840
870
  ownerId: { type: "string", format: "uuid" },
841
- parentId: { type: ["string", "null"], format: "uuid" },
842
- edgeKind: { type: "string", enum: ["sequential", "branch"] },
871
+ parentId: {
872
+ type: ["string", "null"],
873
+ format: "uuid",
874
+ description: "Copy exactly from the pending proposal; do not re-choose the parent at apply time.",
875
+ },
876
+ edgeKind: {
877
+ type: "string",
878
+ enum: ["sequential", "branch"],
879
+ description: "Copy exactly from the pending proposal.",
880
+ },
843
881
  phaseName: { type: "string", minLength: 1, maxLength: 240 },
844
882
  phaseStartsAt: { type: ["string", "null"], pattern: "^\\d{4}-\\d{2}-\\d{2}$" },
845
883
  phaseEndsAt: { type: ["string", "null"], pattern: "^\\d{4}-\\d{2}-\\d{2}$" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@echomem/mcp",
3
- "version": "1.4.59",
3
+ "version": "1.4.61",
4
4
  "description": "EchoMem MCP bridge for cross-agent memory, local history import, and recall",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  "test:config-safety": "npm run build && node test/config-safety.test.mjs",
37
37
  "test:billing-ui": "npm run build && node test/setup-ui.test.mjs billing",
38
38
  "test:mcp-control": "npm run build && node test/mcp-control.test.mjs",
39
- "test": "npm run build && node test/source-session.test.mjs && node test/cowork-ticket-session.test.mjs && node test/source-session-hook.test.mjs && node test/local-data-paths.test.mjs && node test/crypto.test.mjs && node test/integration.test.mjs && node test/onboarding-resilience.test.mjs && node test/local-auth.test.mjs && node test/retrieval-only.test.mjs && node test/no-restart.test.mjs && node test/canonical-golden.test.mjs && node test/tools.test.mjs && node test/workspace-selector.test.mjs && node test/group-map.test.mjs && node test/update-check.test.mjs && node test/headless-runtime.test.mjs && node test/claude-code-config.test.mjs && node test/config-safety.test.mjs && node test/mcp-control.test.mjs && node test/delete.test.mjs && node test/low-touch-tools.test.mjs && node test/migrate.test.mjs && node test/restart-recovery.test.mjs && node test/save-checkpoint-hook.test.mjs && node test/durable-entry.test.mjs && node test/durable-reexec.test.mjs && node test/doctor.test.mjs && node test/environment-matrix.test.mjs",
39
+ "test": "npm run build && node test/source-session.test.mjs && node test/cowork-ticket-session.test.mjs && node test/ticket-review-format.test.mjs && node test/source-session-hook.test.mjs && node test/local-data-paths.test.mjs && node test/crypto.test.mjs && node test/integration.test.mjs && node test/onboarding-resilience.test.mjs && node test/local-auth.test.mjs && node test/retrieval-only.test.mjs && node test/no-restart.test.mjs && node test/canonical-golden.test.mjs && node test/tools.test.mjs && node test/workspace-selector.test.mjs && node test/group-map.test.mjs && node test/update-check.test.mjs && node test/headless-runtime.test.mjs && node test/claude-code-config.test.mjs && node test/config-safety.test.mjs && node test/mcp-control.test.mjs && node test/delete.test.mjs && node test/low-touch-tools.test.mjs && node test/migrate.test.mjs && node test/restart-recovery.test.mjs && node test/save-checkpoint-hook.test.mjs && node test/durable-entry.test.mjs && node test/durable-reexec.test.mjs && node test/doctor.test.mjs && node test/environment-matrix.test.mjs",
40
40
  "prepack": "npm run build"
41
41
  },
42
42
  "dependencies": {