archidocs 1.3.1 → 1.3.3-beta.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.
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
  import type { Snapshot, Source } from "./source.ts";
4
4
  import { type Past } from "./history.ts";
5
5
  import type { ErrorCode } from "./errors.ts";
6
+ import { type Log } from "./announce.ts";
6
7
  export interface ServerOptions {
7
8
  source: Source;
8
9
  /** Base URL of a published viewer; when set, results carry `viewerUrl` links. */
@@ -13,6 +14,11 @@ export interface ServerOptions {
13
14
  * source that takes them: a Bundle never does.
14
15
  */
15
16
  allowWrites?: boolean;
17
+ /** The archidocs version, reported to clients. */
18
+ version?: string;
19
+ /** Where to log tool calls: every write call, and read calls too with `logReads`. */
20
+ log?: Log;
21
+ logReads?: boolean;
16
22
  }
17
23
  export type ToolOutcome = {
18
24
  ok: true;
@@ -12,6 +12,7 @@ import { BundleAdr, BundleDeployment, BundleElement, BundleLens, BundleRelations
12
12
  import { POINT_GRAMMAR, touching } from "../revisions/index.js";
13
13
  import { pastOf } from "./history.js";
14
14
  import { registerWriteTools } from "./writes.js";
15
+ import { callLine } from "./announce.js";
15
16
  import { authoringGuide, topics } from "../guide/index.js";
16
17
  const ok = (data, text) => ({ ok: true, data, text });
17
18
  const fail = (code, message, suggestions) => ({ ok: false, code, message, ...(suggestions ? { suggestions } : {}) });
@@ -25,12 +26,19 @@ const fail = (code, message, suggestions) => ({ ok: false, code, message, ...(su
25
26
  */
26
27
  export function createServer(options) {
27
28
  const { source } = options;
28
- const server = new McpServer({ name: "archidocs", version: "0.0.0" }, { capabilities: { tools: {} } });
29
+ const server = new McpServer({ name: "archidocs", version: options.version ?? "0.0.0" }, { capabilities: { tools: {} } });
29
30
  const writesAllowed = source.writesAllowed && options.allowWrites !== false;
30
31
  const readOnlyReason = source.kind === "bundle"
31
32
  ? `This server reads a published Bundle (${source.location}); write tools need a checkout.`
32
33
  : "Write tools are off over HTTP; restart the server with --allow-writes to allow them.";
33
34
  const past = pastOf(source);
35
+ /** Wraps a tool handler so its call is logged: always for a write, for a read only with `logReads`. */
36
+ const logged = (name, write, handle) => async (raw) => {
37
+ const result = await handle(raw);
38
+ if (options.log && (write || options.logReads))
39
+ options.log(callLine(name, raw, result));
40
+ return result;
41
+ };
34
42
  /**
35
43
  * Registers a tool. A read tool also takes `at` (a ref or a date) and runs
36
44
  * over the Bundle there; a write tool refuses `at`.
@@ -43,7 +51,7 @@ export function createServer(options) {
43
51
  inputSchema: advertise(input),
44
52
  outputSchema: config.output,
45
53
  annotations: { readOnlyHint: !config.write, openWorldHint: false },
46
- }, async (raw) => {
54
+ }, logged(name, config.write === true, async (raw) => {
47
55
  if (config.write && !writesAllowed)
48
56
  return toResult(fail("read_only", readOnlyReason));
49
57
  if (config.write && takesAt(raw))
@@ -67,7 +75,7 @@ export function createServer(options) {
67
75
  snapshot = then.snapshot;
68
76
  }
69
77
  return toResult(await run(rest, snapshot, { past, at, current }));
70
- });
78
+ }));
71
79
  };
72
80
  tool("get_workspace_info", {
73
81
  title: "Workspace info",
@@ -647,7 +655,7 @@ export function createServer(options) {
647
655
  return toResult(fail("not_found", guide.message, guide.suggestion ? [guide.suggestion] : undefined));
648
656
  return toResult(ok({ topic: guide.topic, topics: topics.map((t) => ({ ...t })), text: guide.text }, guide.text));
649
657
  });
650
- registerWriteTools(server, source, writesAllowed ? undefined : readOnlyReason);
658
+ registerWriteTools(server, source, writesAllowed ? undefined : readOnlyReason, logged);
651
659
  return server;
652
660
  }
653
661
  const Point = z.string().min(1);
@@ -1,4 +1,4 @@
1
- import type { McpServer } from "@modelcontextprotocol/server";
1
+ import type { CallToolResult, McpServer } from "@modelcontextprotocol/server";
2
2
  import type { Source } from "./source.ts";
3
3
  /**
4
4
  * The Model write tools: thin adapters over the YAML writer. Each edits the
@@ -7,4 +7,4 @@ import type { Source } from "./source.ts";
7
7
  * They never touch git. With `readOnly` set (a Bundle source, or HTTP
8
8
  * without --allow-writes) each returns `read_only` with that reason.
9
9
  */
10
- export declare function registerWriteTools(server: McpServer, source: Source, readOnly: string | undefined): void;
10
+ export declare function registerWriteTools(server: McpServer, source: Source, readOnly: string | undefined, logged: (name: string, write: boolean, handle: (raw: unknown) => Promise<CallToolResult>) => (raw: unknown) => Promise<CallToolResult>): void;
@@ -30,7 +30,7 @@ const WriteOutput = z.object({
30
30
  * They never touch git. With `readOnly` set (a Bundle source, or HTTP
31
31
  * without --allow-writes) each returns `read_only` with that reason.
32
32
  */
33
- export function registerWriteTools(server, source, readOnly) {
33
+ export function registerWriteTools(server, source, readOnly, logged) {
34
34
  const fs = nodeFileSystem();
35
35
  const writeTool = (name, config, toRequest) => {
36
36
  server.registerTool(name, {
@@ -39,7 +39,7 @@ export function registerWriteTools(server, source, readOnly) {
39
39
  inputSchema: advertise(config.input),
40
40
  outputSchema: WriteOutput,
41
41
  annotations: { readOnlyHint: false, destructiveHint: config.destructive ?? false, idempotentHint: config.idempotent ?? true, openWorldHint: false },
42
- }, async (raw) => {
42
+ }, logged(name, true, async (raw) => {
43
43
  if (readOnly !== undefined || source.kind !== "checkout")
44
44
  return toResult({ ok: false, code: "read_only", message: readOnly ?? "Write tools need a checkout." });
45
45
  if (takesAt(raw))
@@ -56,7 +56,7 @@ export function registerWriteTools(server, source, readOnly) {
56
56
  return toResult({ ok: false, code: "source_unavailable", message: `Could not write the Workspace at ${source.root}: ${error instanceof Error ? error.message : String(error)}` });
57
57
  }
58
58
  return toResult(outcome(result));
59
- });
59
+ }));
60
60
  };
61
61
  writeTool("upsert_element", {
62
62
  title: "Add or update an Element",
@@ -39,10 +39,13 @@ export declare const SEQUENCE: {
39
39
  readonly nameSize: 13;
40
40
  readonly labelSize: 12;
41
41
  readonly subSize: 11;
42
- /** Room in a header beside its name: the Team stripe, code and padding. */
43
- readonly headerPad: 64;
42
+ /**
43
+ * Room in a header beside its name: the border, padding, the gaps either
44
+ * side of the name, and the widest Team code tile (three capitals). Headers
45
+ * have no maximum width, so a name is never cut.
46
+ */
47
+ readonly headerPad: 88;
44
48
  readonly minColumn: 116;
45
- readonly maxColumn: 200;
46
49
  readonly margin: 24;
47
50
  };
48
51
  export interface SequenceColumn {
@@ -17,10 +17,13 @@ export const SEQUENCE = {
17
17
  nameSize: 13,
18
18
  labelSize: 12,
19
19
  subSize: 11,
20
- /** Room in a header beside its name: the Team stripe, code and padding. */
21
- headerPad: 64,
20
+ /**
21
+ * Room in a header beside its name: the border, padding, the gaps either
22
+ * side of the name, and the widest Team code tile (three capitals). Headers
23
+ * have no maximum width, so a name is never cut.
24
+ */
25
+ headerPad: 88,
22
26
  minColumn: 116,
23
- maxColumn: 200,
24
27
  margin: 24,
25
28
  };
26
29
  /**
@@ -72,7 +75,7 @@ export function layoutSequence(view, options) {
72
75
  const messages = sequenceMessages(view, options);
73
76
  const ids = sequenceParticipants(view, options);
74
77
  const index = new Map(ids.map((id, i) => [id, i]));
75
- const widths = ids.map((id) => Math.min(S.maxColumn, Math.max(S.minColumn, textWidth(options.name(id), S.nameSize, 700) + S.headerPad)));
78
+ const widths = ids.map((id) => Math.max(S.minColumn, textWidth(options.name(id), S.nameSize, 700) + S.headerPad));
76
79
  const labelWidths = messages.map((m) => {
77
80
  const via = viaLine(m, options.name);
78
81
  return Math.max(textWidth(m.label, S.labelSize), via ? textWidth(via, S.subSize) : 0, m.note ? textWidth(m.note, S.subSize) : 0);