archidocs 1.3.1 → 1.3.3
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/README.md +10 -16
- package/dist/cli/commands.d.ts +11 -3
- package/dist/cli/commands.js +5 -3
- package/dist/cli/dev.d.ts +7 -0
- package/dist/cli/dev.js +23 -5
- package/dist/cli/init.d.ts +11 -1
- package/dist/cli/init.js +121 -10
- package/dist/cli/run.js +36 -7
- package/dist/guide/index.d.ts +5 -4
- package/dist/guide/index.js +6 -5
- package/dist/mcp/announce.d.ts +25 -0
- package/dist/mcp/announce.js +54 -0
- package/dist/mcp/check.d.ts +17 -0
- package/dist/mcp/check.js +52 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/server.d.ts +6 -0
- package/dist/mcp/server.js +12 -4
- package/dist/mcp/writes.d.ts +2 -2
- package/dist/mcp/writes.js +3 -3
- package/dist/viewer/assets/index-BhiW2o_9.js +138 -0
- package/dist/viewer/assets/{png-DMwnpRCt.js → png-CJovcggr.js} +1 -1
- package/dist/viewer/assets/{svg-DN6lMeZo.js → svg-Cg6M1xWg.js} +1 -1
- package/dist/viewer/index.html +1 -1
- package/guide/SKILL.md +2 -0
- package/package.json +10 -1
- package/dist/viewer/assets/index-C0lIIm8V.js +0 -138
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ServerOptions } from "./server.ts";
|
|
2
|
+
export interface CheckResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
/** What the check found, to print on stdout. */
|
|
5
|
+
lines: string[];
|
|
6
|
+
/** Why it failed, when it did. */
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `archidocs mcp --check`: runs the server these options would start behind
|
|
11
|
+
* an in-process client, as an agent would, and reports what it serves. It
|
|
12
|
+
* does `initialize`, `tools/list` and one read (`list_teams`), so it fails
|
|
13
|
+
* when the server can't start or can't read its source.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkServer(options: ServerOptions & {
|
|
16
|
+
version: string;
|
|
17
|
+
}): Promise<CheckResult>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { InMemoryTransport, LATEST_PROTOCOL_VERSION } from "@modelcontextprotocol/server";
|
|
2
|
+
import { startupLine } from "./announce.js";
|
|
3
|
+
import { createServer } from "./server.js";
|
|
4
|
+
const TIMEOUT_MS = 30_000;
|
|
5
|
+
/**
|
|
6
|
+
* `archidocs mcp --check`: runs the server these options would start behind
|
|
7
|
+
* an in-process client, as an agent would, and reports what it serves. It
|
|
8
|
+
* does `initialize`, `tools/list` and one read (`list_teams`), so it fails
|
|
9
|
+
* when the server can't start or can't read its source.
|
|
10
|
+
*/
|
|
11
|
+
export async function checkServer(options) {
|
|
12
|
+
const lines = [await startupLine({ version: options.version, transport: "check", source: options.source, writesAllowed: options.source.writesAllowed })];
|
|
13
|
+
const server = createServer(options);
|
|
14
|
+
const [client, end] = InMemoryTransport.createLinkedPair();
|
|
15
|
+
const pending = new Map();
|
|
16
|
+
client.onmessage = (message) => {
|
|
17
|
+
const id = message.id;
|
|
18
|
+
if (id !== undefined)
|
|
19
|
+
pending.get(id)?.(message);
|
|
20
|
+
};
|
|
21
|
+
let next = 0;
|
|
22
|
+
const request = async (method, params) => {
|
|
23
|
+
const id = ++next;
|
|
24
|
+
const reply = new Promise((resolve, reject) => {
|
|
25
|
+
pending.set(id, resolve);
|
|
26
|
+
setTimeout(() => reject(new Error(`${method} got no answer in ${TIMEOUT_MS / 1000} s`)), TIMEOUT_MS).unref();
|
|
27
|
+
});
|
|
28
|
+
await client.send({ jsonrpc: "2.0", id, method, params });
|
|
29
|
+
const message = (await reply);
|
|
30
|
+
if (message.error)
|
|
31
|
+
throw new Error(`${method} failed: ${message.error.message}`);
|
|
32
|
+
return message.result;
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
await server.connect(end);
|
|
36
|
+
await client.start();
|
|
37
|
+
await request("initialize", { protocolVersion: LATEST_PROTOCOL_VERSION, capabilities: {}, clientInfo: { name: "archidocs-check", version: options.version } });
|
|
38
|
+
await client.send({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
39
|
+
const { tools } = (await request("tools/list", {}));
|
|
40
|
+
const teams = (await request("tools/call", { name: "list_teams", arguments: {} }));
|
|
41
|
+
if (teams.isError)
|
|
42
|
+
throw new Error(`list_teams failed: ${teams.structuredContent?.code}: ${teams.structuredContent?.message}`);
|
|
43
|
+
lines.push(`ok: ${tools.length} tools; list_teams answered`);
|
|
44
|
+
return { ok: true, lines };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return { ok: false, lines, error: error instanceof Error ? error.message : String(error) };
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await server.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { createServer, type ServerOptions } from "./server.ts";
|
|
2
2
|
export { ERROR_CODES, type ErrorCode } from "./errors.ts";
|
|
3
3
|
export { bundleSource, checkoutSource, type BundleSource, type CheckoutSource, type Source, type Snapshot } from "./source.ts";
|
|
4
|
+
export { checkServer, type CheckResult } from "./check.ts";
|
|
5
|
+
export { startupLine, callLine, describeSource, type Log } from "./announce.ts";
|
|
4
6
|
export { serveHttp, DEFAULT_PORT, type HttpServer, type ServeHttpOptions } from "./http.ts";
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { createServer } from "./server.js";
|
|
2
2
|
export { ERROR_CODES } from "./errors.js";
|
|
3
3
|
export { bundleSource, checkoutSource } from "./source.js";
|
|
4
|
+
export { checkServer } from "./check.js";
|
|
5
|
+
export { startupLine, callLine, describeSource } from "./announce.js";
|
|
4
6
|
export { serveHttp, DEFAULT_PORT } from "./http.js";
|
package/dist/mcp/server.d.ts
CHANGED
|
@@ -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;
|
package/dist/mcp/server.js
CHANGED
|
@@ -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);
|
package/dist/mcp/writes.d.ts
CHANGED
|
@@ -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;
|
package/dist/mcp/writes.js
CHANGED
|
@@ -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",
|