@magic-markdown/cli 0.3.7 → 0.3.9

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.
Files changed (2) hide show
  1. package/dist/index.js +28 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1716,7 +1716,7 @@ async function readManifest(io) {
1716
1716
  return JSON.parse(raw);
1717
1717
  }
1718
1718
  async function writeManifest(io, manifest) {
1719
- await io.writeText(MANIFEST_PATH, `${JSON.stringify(manifest, null, 2)}
1719
+ await writeJsonText(io, MANIFEST_PATH, `${JSON.stringify(manifest, null, 2)}
1720
1720
  `);
1721
1721
  }
1722
1722
  async function readSidecar(io, docId) {
@@ -1724,9 +1724,16 @@ async function readSidecar(io, docId) {
1724
1724
  return JSON.parse(raw);
1725
1725
  }
1726
1726
  async function writeSidecar(io, sidecar) {
1727
- await io.writeText(sidecarPath(sidecar.docId), `${JSON.stringify(sidecar, null, 2)}
1727
+ await writeJsonText(io, sidecarPath(sidecar.docId), `${JSON.stringify(sidecar, null, 2)}
1728
1728
  `);
1729
1729
  }
1730
+ async function writeJsonText(io, path, content) {
1731
+ if (io.writeTextAtomic) {
1732
+ await io.writeTextAtomic(path, content);
1733
+ return;
1734
+ }
1735
+ await io.writeText(path, content);
1736
+ }
1730
1737
  function findDoc(manifest, pathOrDocId) {
1731
1738
  const entry = manifest.docs.find((doc) => doc.path === pathOrDocId || doc.docId === pathOrDocId);
1732
1739
  if (!entry) throw new Error(`Unknown document: ${pathOrDocId}`);
@@ -1739,7 +1746,7 @@ async function readManifestIfPresent(io) {
1739
1746
  async function ensureDocumentSidecar(io, entry, markdown) {
1740
1747
  const path = sidecarPath(entry.docId);
1741
1748
  if (await io.exists(path)) {
1742
- const sidecar = await readSidecar(io, entry.docId);
1749
+ const sidecar = await readSidecar(io, entry.docId).catch(() => createEmptySidecar(entry));
1743
1750
  await writeSidecar(io, {
1744
1751
  ...sidecar,
1745
1752
  path: entry.path,
@@ -10990,7 +10997,7 @@ var RemoteDocumentIO = class {
10990
10997
  };
10991
10998
 
10992
10999
  // src/agent.ts
10993
- var CLI_VERSION = "0.3.7";
11000
+ var CLI_VERSION = "0.3.9";
10994
11001
  var CLI_PACKAGE_NAME = "@magic-markdown/cli";
10995
11002
  var AGENT_COMMANDS = [
10996
11003
  {
@@ -11260,7 +11267,7 @@ var AGENT_COMMANDS = [
11260
11267
  {
11261
11268
  name: "bridge setup",
11262
11269
  summary: "Initialize, validate, request approval for, and start an agent filesystem bridge.",
11263
- usage: "mdocs bridge setup --workspace <id> --root <path> --root-id <id> --url <base-url> --actor-name <agent-name> --request-token",
11270
+ usage: "mdocs bridge setup --workspace <id> --root <path> --root-id <id> [--folder-id <id>] --url <base-url> --actor-name <agent-name> --request-token",
11264
11271
  output: "long-running",
11265
11272
  mutates: true,
11266
11273
  examples: [
@@ -13471,7 +13478,9 @@ async function runBridge(options) {
13471
13478
  });
13472
13479
  socket.addEventListener("message", (event) => {
13473
13480
  if (typeof event.data !== "string") return;
13474
- void handleIncoming(JSON.parse(event.data)).catch((error) => {
13481
+ const message = parseBridgeSyncMessage(event.data);
13482
+ if (!message) return;
13483
+ void handleIncoming(message).catch((error) => {
13475
13484
  process.stderr.write(`bridge incoming failed: ${error instanceof Error ? error.message : String(error)}
13476
13485
  `);
13477
13486
  });
@@ -13693,6 +13702,7 @@ async function requestBridgeToken(options, rootId) {
13693
13702
  rootId,
13694
13703
  actorId: options.actorId,
13695
13704
  actorName: options.actorName,
13705
+ folderId: options.folderId,
13696
13706
  sourceName: options.sourceName,
13697
13707
  role: "edit"
13698
13708
  })
@@ -13735,6 +13745,16 @@ async function requestBridgeToken(options, rootId) {
13735
13745
  }
13736
13746
  throw new Error("Bridge approval timed out before a token was issued.");
13737
13747
  }
13748
+ function parseBridgeSyncMessage(data) {
13749
+ if (!data.trim()) return void 0;
13750
+ try {
13751
+ return JSON.parse(data);
13752
+ } catch (error) {
13753
+ process.stderr.write(`bridge ignored malformed sync message: ${error instanceof Error ? error.message : String(error)}
13754
+ `);
13755
+ return void 0;
13756
+ }
13757
+ }
13738
13758
  function delay(ms) {
13739
13759
  return new Promise((resolve6) => setTimeout(resolve6, ms));
13740
13760
  }
@@ -14040,6 +14060,7 @@ async function main() {
14040
14060
  rootId: typeof parsed.flags["root-id"] === "string" ? parsed.flags["root-id"] : void 0,
14041
14061
  sourceId: typeof parsed.flags.source === "string" ? parsed.flags.source : void 0,
14042
14062
  sourceName: typeof parsed.flags["source-name"] === "string" ? parsed.flags["source-name"] : void 0,
14063
+ folderId: typeof parsed.flags["folder-id"] === "string" ? parsed.flags["folder-id"] : void 0,
14043
14064
  canonicalPrefix: typeof parsed.flags["canonical-prefix"] === "string" ? parsed.flags["canonical-prefix"] : void 0,
14044
14065
  replicaPrefix: typeof parsed.flags["replica-prefix"] === "string" ? parsed.flags["replica-prefix"] : void 0,
14045
14066
  claimToken: typeof parsed.flags.claim === "string" ? parsed.flags.claim : void 0,
@@ -14241,7 +14262,7 @@ Commands:
14241
14262
  remote events|history|restore Poll events, list commits, restore snapshots
14242
14263
  remote library|create-folder|update-folder|move-root|invite-folder
14243
14264
  Organize the joined project library
14244
- bridge setup --workspace <id> --root . --url <base-url> --request-token
14265
+ bridge setup --workspace <id> --root . --url <base-url> [--folder-id <id>] --request-token
14245
14266
  Initialize, validate, request approval,
14246
14267
  and start an agent filesystem bridge
14247
14268
  bridge --workspace <id> --root . --url <base-url> --request-token
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic-markdown/cli",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "Magic Markdown agent CLI (mdocs): read, review, comment on, suggest edits to, and sync clean Markdown workspaces.",
5
5
  "type": "module",
6
6
  "license": "MIT",