@magic-markdown/cli 0.3.6 → 0.3.8
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 +8 -6
- package/dist/index.js +90 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,19 +22,21 @@ The package is a single self-contained bundle with no runtime dependencies. It r
|
|
|
22
22
|
## Quick start for agents
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs version --json
|
|
26
|
+
|
|
25
27
|
# Join a shared document and announce presence
|
|
26
|
-
mdocs join <share-url> --doc <docId> --name "Claude Code" --json
|
|
28
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs join <share-url> --doc <docId> --name "Claude Code" --json
|
|
27
29
|
|
|
28
30
|
# Orient without dumping the whole document
|
|
29
|
-
mdocs remote context --summary --json
|
|
31
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs remote context --summary --json
|
|
30
32
|
|
|
31
33
|
# Page document text separately from review state
|
|
32
|
-
mdocs remote context --start-line 1 --end-line 120 --no-review --json
|
|
33
|
-
mdocs remote review --json
|
|
34
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs remote context --start-line 1 --end-line 120 --no-review --json
|
|
35
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs remote review --json
|
|
34
36
|
|
|
35
37
|
# Leave a comment or propose an edit (ranges are 1-based, inclusive)
|
|
36
|
-
mdocs remote comment --range 12:14 --body "Tighten this paragraph." --json
|
|
37
|
-
mdocs remote suggest --range 12:14 --with-file replacement.md --message "Clearer phrasing" --json
|
|
38
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs remote comment --range 12:14 --body "Tighten this paragraph." --json
|
|
39
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs remote suggest --range 12:14 --with-file replacement.md --message "Clearer phrasing" --json
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
Run `mdocs agent guide` for the full agent workflow, `mdocs help <command>` for any command, or `mdocs agent commands --json` for the machine-readable command contract.
|
package/dist/index.js
CHANGED
|
@@ -10990,7 +10990,7 @@ var RemoteDocumentIO = class {
|
|
|
10990
10990
|
};
|
|
10991
10991
|
|
|
10992
10992
|
// src/agent.ts
|
|
10993
|
-
var CLI_VERSION = "0.3.
|
|
10993
|
+
var CLI_VERSION = "0.3.8";
|
|
10994
10994
|
var CLI_PACKAGE_NAME = "@magic-markdown/cli";
|
|
10995
10995
|
var AGENT_COMMANDS = [
|
|
10996
10996
|
{
|
|
@@ -11009,6 +11009,14 @@ var AGENT_COMMANDS = [
|
|
|
11009
11009
|
mutates: false,
|
|
11010
11010
|
examples: ["mdocs agent commands --json"]
|
|
11011
11011
|
},
|
|
11012
|
+
{
|
|
11013
|
+
name: "agent-guide",
|
|
11014
|
+
summary: "Alias for mdocs agent guide.",
|
|
11015
|
+
usage: "mdocs agent-guide [--json]",
|
|
11016
|
+
output: "text",
|
|
11017
|
+
mutates: false,
|
|
11018
|
+
examples: ["mdocs agent-guide", "mdocs agent-guide --json"]
|
|
11019
|
+
},
|
|
11012
11020
|
{
|
|
11013
11021
|
name: "init",
|
|
11014
11022
|
summary: "Create .mdocs metadata and index Markdown documents.",
|
|
@@ -11249,6 +11257,21 @@ var AGENT_COMMANDS = [
|
|
|
11249
11257
|
"mdocs checkpoint restore checkpoint_abc123 --json"
|
|
11250
11258
|
]
|
|
11251
11259
|
},
|
|
11260
|
+
{
|
|
11261
|
+
name: "bridge setup",
|
|
11262
|
+
summary: "Initialize, validate, request approval for, and start an agent filesystem bridge.",
|
|
11263
|
+
usage: "mdocs bridge setup --workspace <id> --root <path> --root-id <id> [--folder-id <id>] --url <base-url> --actor-name <agent-name> --request-token",
|
|
11264
|
+
output: "long-running",
|
|
11265
|
+
mutates: true,
|
|
11266
|
+
examples: [
|
|
11267
|
+
"mdocs bridge setup --workspace workspace_abc --root . --root-id agentfs-hermes --url https://magic.example.com --actor-name Hermes --request-token"
|
|
11268
|
+
],
|
|
11269
|
+
notes: [
|
|
11270
|
+
"Runs init and doctor before starting the bridge.",
|
|
11271
|
+
"--request-token opens a human approval URL and avoids pasting bridge secrets into an agent session.",
|
|
11272
|
+
"--token (or MDOCS_BRIDGE_TOKEN) still works when a scoped bridge token is already available."
|
|
11273
|
+
]
|
|
11274
|
+
},
|
|
11252
11275
|
{
|
|
11253
11276
|
name: "bridge",
|
|
11254
11277
|
summary: "Sync a local Markdown root with a Magic workspace over WebSocket (long-running).",
|
|
@@ -11300,14 +11323,10 @@ Magic Markdown keeps Markdown files clean and stores collaboration metadata in .
|
|
|
11300
11323
|
|
|
11301
11324
|
## Install / Bootstrap
|
|
11302
11325
|
|
|
11303
|
-
The only official package is \`@magic-markdown/cli\` (bins \`mdocs\` and \`magic-markdown\`). A different, unrelated package is published as \`@mdocs/cli\` \u2014 do not install it.
|
|
11326
|
+
The only official package is \`@magic-markdown/cli\` (bins \`mdocs\` and \`magic-markdown\`). A different, unrelated package is published as \`@mdocs/cli\` \u2014 do not install it. Agent sessions should bootstrap through the latest official package so they do not reuse a stale global \`mdocs\`:
|
|
11304
11327
|
|
|
11305
11328
|
\`\`\`bash
|
|
11306
|
-
|
|
11307
|
-
if ! command -v mdocs >/dev/null 2>&1 || ! mdocs version --json 2>/dev/null | grep -qF '"name": "@magic-markdown/cli"'; then
|
|
11308
|
-
MDOCS="npx --yes --package=@magic-markdown/cli@latest mdocs"
|
|
11309
|
-
fi
|
|
11310
|
-
$MDOCS version --json
|
|
11329
|
+
npx --yes --package=@magic-markdown/cli@latest mdocs version --json
|
|
11311
11330
|
\`\`\`
|
|
11312
11331
|
|
|
11313
11332
|
Run \`mdocs help <command>\` (or \`mdocs <command> --help\`) for usage, examples, and notes on any command, or \`mdocs agent commands --json\` for the full machine-readable contract.
|
|
@@ -13367,6 +13386,33 @@ function optionalFolderTarget(value) {
|
|
|
13367
13386
|
// src/bridge.ts
|
|
13368
13387
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
13369
13388
|
import { basename as basename2, resolve as resolve4 } from "node:path";
|
|
13389
|
+
function bridgeSetupIdentity(input) {
|
|
13390
|
+
const actorName = input.actorName?.trim() || "Agent";
|
|
13391
|
+
return {
|
|
13392
|
+
actorId: input.actorId?.trim() || `agent:${agentSlug(actorName)}`,
|
|
13393
|
+
actorName,
|
|
13394
|
+
sourceName: input.sourceName?.trim() || agentFilesystemDisplayName(actorName)
|
|
13395
|
+
};
|
|
13396
|
+
}
|
|
13397
|
+
async function runBridgeSetup(options) {
|
|
13398
|
+
const root = resolve4(options.root);
|
|
13399
|
+
const identity = bridgeSetupIdentity(options);
|
|
13400
|
+
const io = new NodeWorkspaceIO(root);
|
|
13401
|
+
const manifest = await indexWorkspace(io);
|
|
13402
|
+
process.stdout.write(`mdocs bridge setup indexed ${manifest.docs.length} Markdown document${manifest.docs.length === 1 ? "" : "s"} in ${root}
|
|
13403
|
+
`);
|
|
13404
|
+
const doctor = await runDoctor(io, root);
|
|
13405
|
+
process.stdout.write(`mdocs doctor ${doctor.ok ? "ok" : "has warnings"}: ${doctor.checks.map((check) => check.details).join(" ")}
|
|
13406
|
+
`);
|
|
13407
|
+
await runBridge({
|
|
13408
|
+
...options,
|
|
13409
|
+
root,
|
|
13410
|
+
actorId: identity.actorId,
|
|
13411
|
+
actorName: identity.actorName,
|
|
13412
|
+
sourceName: identity.sourceName,
|
|
13413
|
+
requestToken: options.requestToken || !options.token
|
|
13414
|
+
});
|
|
13415
|
+
}
|
|
13370
13416
|
async function runBridge(options) {
|
|
13371
13417
|
const root = resolve4(options.root);
|
|
13372
13418
|
const localManifestSource = await readLocalSource(root);
|
|
@@ -13425,7 +13471,9 @@ async function runBridge(options) {
|
|
|
13425
13471
|
});
|
|
13426
13472
|
socket.addEventListener("message", (event) => {
|
|
13427
13473
|
if (typeof event.data !== "string") return;
|
|
13428
|
-
|
|
13474
|
+
const message = parseBridgeSyncMessage(event.data);
|
|
13475
|
+
if (!message) return;
|
|
13476
|
+
void handleIncoming(message).catch((error) => {
|
|
13429
13477
|
process.stderr.write(`bridge incoming failed: ${error instanceof Error ? error.message : String(error)}
|
|
13430
13478
|
`);
|
|
13431
13479
|
});
|
|
@@ -13647,6 +13695,7 @@ async function requestBridgeToken(options, rootId) {
|
|
|
13647
13695
|
rootId,
|
|
13648
13696
|
actorId: options.actorId,
|
|
13649
13697
|
actorName: options.actorName,
|
|
13698
|
+
folderId: options.folderId,
|
|
13650
13699
|
sourceName: options.sourceName,
|
|
13651
13700
|
role: "edit"
|
|
13652
13701
|
})
|
|
@@ -13689,6 +13738,16 @@ async function requestBridgeToken(options, rootId) {
|
|
|
13689
13738
|
}
|
|
13690
13739
|
throw new Error("Bridge approval timed out before a token was issued.");
|
|
13691
13740
|
}
|
|
13741
|
+
function parseBridgeSyncMessage(data) {
|
|
13742
|
+
if (!data.trim()) return void 0;
|
|
13743
|
+
try {
|
|
13744
|
+
return JSON.parse(data);
|
|
13745
|
+
} catch (error) {
|
|
13746
|
+
process.stderr.write(`bridge ignored malformed sync message: ${error instanceof Error ? error.message : String(error)}
|
|
13747
|
+
`);
|
|
13748
|
+
return void 0;
|
|
13749
|
+
}
|
|
13750
|
+
}
|
|
13692
13751
|
function delay(ms) {
|
|
13693
13752
|
return new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
13694
13753
|
}
|
|
@@ -13776,6 +13835,15 @@ function agentNameFromActorId(actorId, rootName) {
|
|
|
13776
13835
|
if (nameFromId) return nameFromId;
|
|
13777
13836
|
return "Agent";
|
|
13778
13837
|
}
|
|
13838
|
+
function agentFilesystemDisplayName(agentName) {
|
|
13839
|
+
const trimmed = agentName.trim();
|
|
13840
|
+
if (!trimmed) return "Agent Filesystem";
|
|
13841
|
+
return /\bagent$/i.test(trimmed) ? `${trimmed} Filesystem` : `${trimmed} Agent Filesystem`;
|
|
13842
|
+
}
|
|
13843
|
+
function agentSlug(agentName) {
|
|
13844
|
+
const slug = agentName.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
13845
|
+
return slug || "agent";
|
|
13846
|
+
}
|
|
13779
13847
|
function mergePermissions(permissions, permission) {
|
|
13780
13848
|
return [...permissions.filter((candidate) => candidate.actorId !== permission.actorId), permission];
|
|
13781
13849
|
}
|
|
@@ -13974,24 +14042,31 @@ async function main() {
|
|
|
13974
14042
|
await runAgentCommand(io, cwd, subcommand, parsed);
|
|
13975
14043
|
return;
|
|
13976
14044
|
}
|
|
14045
|
+
case "agent-guide": {
|
|
14046
|
+
print(parsed.flags.json ? getAgentGuidePayload() : getAgentSkillMarkdown(), parsed.flags);
|
|
14047
|
+
return;
|
|
14048
|
+
}
|
|
13977
14049
|
case "bridge": {
|
|
13978
|
-
|
|
14050
|
+
const options = {
|
|
13979
14051
|
root: resolve5(String(parsed.flags.root ?? cwd)),
|
|
13980
14052
|
workspaceId: String(parsed.flags.workspace ?? "workspace_demo"),
|
|
13981
14053
|
rootId: typeof parsed.flags["root-id"] === "string" ? parsed.flags["root-id"] : void 0,
|
|
13982
14054
|
sourceId: typeof parsed.flags.source === "string" ? parsed.flags.source : void 0,
|
|
13983
14055
|
sourceName: typeof parsed.flags["source-name"] === "string" ? parsed.flags["source-name"] : void 0,
|
|
14056
|
+
folderId: typeof parsed.flags["folder-id"] === "string" ? parsed.flags["folder-id"] : void 0,
|
|
13984
14057
|
canonicalPrefix: typeof parsed.flags["canonical-prefix"] === "string" ? parsed.flags["canonical-prefix"] : void 0,
|
|
13985
14058
|
replicaPrefix: typeof parsed.flags["replica-prefix"] === "string" ? parsed.flags["replica-prefix"] : void 0,
|
|
13986
14059
|
claimToken: typeof parsed.flags.claim === "string" ? parsed.flags.claim : void 0,
|
|
13987
|
-
actorId:
|
|
14060
|
+
actorId: typeof parsed.flags.actor === "string" ? parsed.flags.actor : void 0,
|
|
13988
14061
|
actorName: typeof parsed.flags["actor-name"] === "string" ? parsed.flags["actor-name"] : void 0,
|
|
13989
14062
|
baseUrl: bridgeBaseUrl(parsed.flags),
|
|
13990
14063
|
intervalMs: Number(parsed.flags.interval ?? 1e3),
|
|
13991
14064
|
token: typeof parsed.flags.token === "string" ? parsed.flags.token : process.env.MDOCS_BRIDGE_TOKEN || void 0,
|
|
13992
14065
|
requestToken: Boolean(parsed.flags["request-token"] || parsed.flags.pair),
|
|
13993
14066
|
pairingTimeoutMs: typeof parsed.flags["pairing-timeout-ms"] === "string" ? Number(parsed.flags["pairing-timeout-ms"]) : void 0
|
|
13994
|
-
}
|
|
14067
|
+
};
|
|
14068
|
+
if (subcommand === "setup") await runBridgeSetup(options);
|
|
14069
|
+
else await runBridge({ ...options, actorId: options.actorId ?? "actor_local" });
|
|
13995
14070
|
return;
|
|
13996
14071
|
}
|
|
13997
14072
|
case "doctor": {
|
|
@@ -14147,6 +14222,7 @@ function help() {
|
|
|
14147
14222
|
|
|
14148
14223
|
Commands:
|
|
14149
14224
|
agent guide Print agent SKILL.md workflow guidance
|
|
14225
|
+
agent-guide Alias for agent guide
|
|
14150
14226
|
agent commands --json Print machine-readable command metadata
|
|
14151
14227
|
init [path] Initialize .mdocs and index Markdown files
|
|
14152
14228
|
map --json Print workspace map
|
|
@@ -14179,6 +14255,9 @@ Commands:
|
|
|
14179
14255
|
remote events|history|restore Poll events, list commits, restore snapshots
|
|
14180
14256
|
remote library|create-folder|update-folder|move-root|invite-folder
|
|
14181
14257
|
Organize the joined project library
|
|
14258
|
+
bridge setup --workspace <id> --root . --url <base-url> [--folder-id <id>] --request-token
|
|
14259
|
+
Initialize, validate, request approval,
|
|
14260
|
+
and start an agent filesystem bridge
|
|
14182
14261
|
bridge --workspace <id> --root . --url <base-url> --request-token
|
|
14183
14262
|
Request human approval, then sync an
|
|
14184
14263
|
approved local root with the workspace
|
package/package.json
CHANGED