mdedit-cli 0.2.2 → 0.3.0
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 +26 -0
- package/dist/index.js +200 -7
- package/dist/index.js.map +1 -1
- package/openclaw.json +36 -1
- package/package.json +3 -3
- package/skill.md +8 -0
package/README.md
CHANGED
|
@@ -55,6 +55,32 @@ quote, heading, section, or range anchors. The command exits `2` when an anchor
|
|
|
55
55
|
`3` when an anchor is ambiguous, and `4` when an edit conflict is reported. In JSON mode,
|
|
56
56
|
the result or typed error is the only value written to stdout.
|
|
57
57
|
|
|
58
|
+
## Public links
|
|
59
|
+
|
|
60
|
+
Use a key with `publishing:write` to publish or update a public snapshot. Publishing is
|
|
61
|
+
explicit: later edits stay private until the command is run again.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
mdedit article publish <articleId> --yes
|
|
65
|
+
mdedit article publish <articleId> --slug my-document --yes
|
|
66
|
+
mdedit article publish-status <articleId> --format json
|
|
67
|
+
mdedit article unpublish <articleId> --yes
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Create a document from Markdown and publish it in one command:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
mdedit article create \
|
|
74
|
+
--file document.md \
|
|
75
|
+
--publish \
|
|
76
|
+
--yes
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Without `--title`, the CLI uses the first Markdown H1 or the filename.
|
|
80
|
+
The JSON result includes `publication.shortUrl`, such as
|
|
81
|
+
`https://mded.it/my-document`. If article creation succeeds but publishing fails, the
|
|
82
|
+
article is kept private and the command reports its article ID.
|
|
83
|
+
|
|
58
84
|
## Review commands
|
|
59
85
|
|
|
60
86
|
Review agents can comment and suggest with `articles:read,reviews:write`; accepting a
|
package/dist/index.js
CHANGED
|
@@ -349,6 +349,18 @@ var normalizeTimestampMs = (value) => {
|
|
|
349
349
|
if (!Number.isFinite(n)) return Date.now();
|
|
350
350
|
return n < 1e12 ? n * 1e3 : n;
|
|
351
351
|
};
|
|
352
|
+
var readFolderErrorMessage = async (response, fallback) => {
|
|
353
|
+
const errorText = await response.text();
|
|
354
|
+
try {
|
|
355
|
+
const body = JSON.parse(errorText);
|
|
356
|
+
const message = body?.error?.message ?? body?.message;
|
|
357
|
+
if (typeof message === "string" && message.trim()) {
|
|
358
|
+
return message;
|
|
359
|
+
}
|
|
360
|
+
} catch {
|
|
361
|
+
}
|
|
362
|
+
return errorText.trim() || fallback;
|
|
363
|
+
};
|
|
352
364
|
var normalizeFolder = (raw) => {
|
|
353
365
|
const id = raw?.id ?? raw?.folderId;
|
|
354
366
|
const parentId = raw?.parentId ?? raw?.parentFolderId ?? null;
|
|
@@ -389,8 +401,10 @@ var createFolder = async (workspaceId, folderRequest, fetchers) => {
|
|
|
389
401
|
})
|
|
390
402
|
});
|
|
391
403
|
if (!response.ok) {
|
|
392
|
-
|
|
393
|
-
|
|
404
|
+
throw new errors_default(
|
|
405
|
+
await readFolderErrorMessage(response, "Error creating folder"),
|
|
406
|
+
response.status
|
|
407
|
+
);
|
|
394
408
|
}
|
|
395
409
|
return normalizeFolder(await response.json());
|
|
396
410
|
};
|
|
@@ -404,8 +418,10 @@ var updateFolder = async (workspaceId, folderId, folderRequest, fetchers) => {
|
|
|
404
418
|
})
|
|
405
419
|
});
|
|
406
420
|
if (!response.ok) {
|
|
407
|
-
|
|
408
|
-
|
|
421
|
+
throw new errors_default(
|
|
422
|
+
await readFolderErrorMessage(response, "Error updating folder"),
|
|
423
|
+
response.status
|
|
424
|
+
);
|
|
409
425
|
}
|
|
410
426
|
const result = await response.json();
|
|
411
427
|
try {
|
|
@@ -527,6 +543,68 @@ var checkpointCollaboration = async (workspaceId, articleId, fetchers) => {
|
|
|
527
543
|
}
|
|
528
544
|
return response.json();
|
|
529
545
|
};
|
|
546
|
+
var publishArticle = async (workspaceId, articleId, body, fetchers) => {
|
|
547
|
+
const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
|
|
548
|
+
const response = await fetchV2(
|
|
549
|
+
`/workspaces/${workspaceId}/articles/${articleId}/publish`,
|
|
550
|
+
{
|
|
551
|
+
method: "POST",
|
|
552
|
+
body: JSON.stringify(body)
|
|
553
|
+
}
|
|
554
|
+
);
|
|
555
|
+
if (!response.ok) {
|
|
556
|
+
throw new errors_default(
|
|
557
|
+
`Error publishing article: ${await response.text()}`,
|
|
558
|
+
response.status
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
return response.json();
|
|
562
|
+
};
|
|
563
|
+
var unpublishArticle = async (workspaceId, articleId, fetchers) => {
|
|
564
|
+
const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
|
|
565
|
+
const response = await fetchV2(
|
|
566
|
+
`/workspaces/${workspaceId}/articles/${articleId}/publish`,
|
|
567
|
+
{ method: "DELETE" }
|
|
568
|
+
);
|
|
569
|
+
if (!response.ok) {
|
|
570
|
+
throw new errors_default(
|
|
571
|
+
`Error unpublishing article: ${await response.text()}`,
|
|
572
|
+
response.status
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
return response.json();
|
|
576
|
+
};
|
|
577
|
+
var getPublishStatus = async (workspaceId, articleId, fetchers) => {
|
|
578
|
+
const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
|
|
579
|
+
const response = await fetchV2(
|
|
580
|
+
`/workspaces/${workspaceId}/articles/${articleId}/publish`,
|
|
581
|
+
{ method: "GET" }
|
|
582
|
+
);
|
|
583
|
+
if (!response.ok) {
|
|
584
|
+
throw new errors_default(
|
|
585
|
+
`Error fetching publish status: ${await response.text()}`,
|
|
586
|
+
response.status
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
return response.json();
|
|
590
|
+
};
|
|
591
|
+
var updatePublishedArticle = async (workspaceId, articleId, body, fetchers) => {
|
|
592
|
+
const fetchV2 = fetchers?.customFetchV2 ?? customFetchV2;
|
|
593
|
+
const response = await fetchV2(
|
|
594
|
+
`/workspaces/${workspaceId}/articles/${articleId}/publish`,
|
|
595
|
+
{
|
|
596
|
+
method: "PUT",
|
|
597
|
+
body: JSON.stringify(body)
|
|
598
|
+
}
|
|
599
|
+
);
|
|
600
|
+
if (!response.ok) {
|
|
601
|
+
throw new errors_default(
|
|
602
|
+
`Error updating published article: ${await response.text()}`,
|
|
603
|
+
response.status
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
return response.json();
|
|
607
|
+
};
|
|
530
608
|
var FetchError2 = class extends Error {
|
|
531
609
|
status;
|
|
532
610
|
data;
|
|
@@ -590,6 +668,12 @@ function createSdkClient(config) {
|
|
|
590
668
|
},
|
|
591
669
|
collaboration: {
|
|
592
670
|
checkpoint: (workspaceId, articleId) => withFetchError(() => checkpointCollaboration(workspaceId, articleId, fetchers))
|
|
671
|
+
},
|
|
672
|
+
publish: {
|
|
673
|
+
publish: (workspaceId, articleId, request = {}) => withFetchError(() => publishArticle(workspaceId, articleId, request, fetchers)),
|
|
674
|
+
status: (workspaceId, articleId) => withFetchError(() => getPublishStatus(workspaceId, articleId, fetchers)),
|
|
675
|
+
update: (workspaceId, articleId, request = {}) => withFetchError(() => updatePublishedArticle(workspaceId, articleId, request, fetchers)),
|
|
676
|
+
unpublish: (workspaceId, articleId) => withFetchError(() => unpublishArticle(workspaceId, articleId, fetchers))
|
|
593
677
|
}
|
|
594
678
|
};
|
|
595
679
|
}
|
|
@@ -603,6 +687,7 @@ import inquirer from "inquirer";
|
|
|
603
687
|
import { v4 as uuidv4 } from "uuid";
|
|
604
688
|
import { readFile, writeFile } from "fs/promises";
|
|
605
689
|
import { createHash } from "crypto";
|
|
690
|
+
import { basename, extname } from "path";
|
|
606
691
|
import {
|
|
607
692
|
openArticleSession
|
|
608
693
|
} from "@mdedit/agent-client";
|
|
@@ -1073,6 +1158,36 @@ async function writeBlobToFile(blob, filePath) {
|
|
|
1073
1158
|
function sha256Hex(content) {
|
|
1074
1159
|
return createHash("sha256").update(content).digest("hex");
|
|
1075
1160
|
}
|
|
1161
|
+
function inferFileTitle(filePath, content) {
|
|
1162
|
+
const firstHeading = content?.match(/^\s*#\s+(.+?)\s*$/m)?.[1]?.trim();
|
|
1163
|
+
if (firstHeading) return firstHeading;
|
|
1164
|
+
if (filePath === "-") return void 0;
|
|
1165
|
+
const fileName = basename(filePath);
|
|
1166
|
+
const extension = extname(fileName);
|
|
1167
|
+
const stem = (extension ? fileName.slice(0, -extension.length) : fileName).trim();
|
|
1168
|
+
return stem || void 0;
|
|
1169
|
+
}
|
|
1170
|
+
function publishRequest(options) {
|
|
1171
|
+
const seoMetadata = {
|
|
1172
|
+
...options.seoTitle ? { title: options.seoTitle } : {},
|
|
1173
|
+
...options.seoDescription ? { description: options.seoDescription } : {}
|
|
1174
|
+
};
|
|
1175
|
+
return {
|
|
1176
|
+
...options.slug ? { customSlug: options.slug } : {},
|
|
1177
|
+
...Object.keys(seoMetadata).length > 0 ? { seoMetadata } : {}
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
async function confirmPublicPublish(articleId) {
|
|
1181
|
+
const { confirm } = await inquirer.prompt([
|
|
1182
|
+
{
|
|
1183
|
+
type: "confirm",
|
|
1184
|
+
name: "confirm",
|
|
1185
|
+
message: `Publish article ${articleId} publicly? Anyone with the link will be able to view it.`,
|
|
1186
|
+
default: false
|
|
1187
|
+
}
|
|
1188
|
+
]);
|
|
1189
|
+
return Boolean(confirm);
|
|
1190
|
+
}
|
|
1076
1191
|
async function readEditOperations(filePath) {
|
|
1077
1192
|
const raw = await readFile(filePath, "utf-8");
|
|
1078
1193
|
const parsed = JSON.parse(raw);
|
|
@@ -1141,17 +1256,23 @@ function createArticleCommands() {
|
|
|
1141
1256
|
output.output(presentArticleDetails(result));
|
|
1142
1257
|
output.info("Hint: use `mdedit article get <articleId> --content-only` to print markdown, or `--include-content` to include it in the output.");
|
|
1143
1258
|
});
|
|
1144
|
-
article.command("create").description("Create a new article").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("-i, --id <articleId>", "Article ID (defaults to a UUID)").option("-t, --title <title>", "Article title").option("-f, --folder <folderId>", "Folder ID").option("-c, --collaborative", "Enable collaborative editing").option("--file <path>", "Read initial article content from a file (use - for stdin)").option("--content <text>", "Set initial article content as an inline string").action(async (options) => {
|
|
1259
|
+
article.command("create").description("Create a new article").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("-i, --id <articleId>", "Article ID (defaults to a UUID)").option("-t, --title <title>", "Article title").option("-f, --folder <folderId>", "Folder ID").option("-c, --collaborative", "Enable collaborative editing").option("--file <path>", "Read initial article content from a file (use - for stdin)").option("--content <text>", "Set initial article content as an inline string").option("--publish", "Publish the created article to a public mded.it link").option("--slug <slug>", "Custom public-link slug (requires --publish)").option("--seo-title <title>", "SEO/social title for the public page (requires --publish)").option("--seo-description <description>", "SEO/social description for the public page (requires --publish)").option("-y, --yes", "Skip public-publishing confirmation").action(async (options) => {
|
|
1145
1260
|
const apiKey = requireApiKey();
|
|
1146
1261
|
const client = getApiClient();
|
|
1147
1262
|
const workspaceId = requireWorkspaceId(options.workspace);
|
|
1148
1263
|
if (options.content !== void 0 && options.file !== void 0) {
|
|
1149
1264
|
throw new Error("--content and --file are mutually exclusive. Provide only one.");
|
|
1150
1265
|
}
|
|
1266
|
+
if (!options.publish && (options.slug || options.seoTitle || options.seoDescription)) {
|
|
1267
|
+
throw new Error("--slug, --seo-title, and --seo-description require --publish.");
|
|
1268
|
+
}
|
|
1151
1269
|
let contentText = null;
|
|
1152
1270
|
if (options.content !== void 0) contentText = options.content;
|
|
1153
1271
|
else if (options.file) contentText = await readContentFromFile(options.file);
|
|
1154
1272
|
let title = options.title;
|
|
1273
|
+
if (!title && options.file) {
|
|
1274
|
+
title = inferFileTitle(options.file, contentText);
|
|
1275
|
+
}
|
|
1155
1276
|
if (!title) {
|
|
1156
1277
|
const answers = await inquirer.prompt([
|
|
1157
1278
|
{
|
|
@@ -1164,6 +1285,10 @@ function createArticleCommands() {
|
|
|
1164
1285
|
title = String(answers.title);
|
|
1165
1286
|
}
|
|
1166
1287
|
const articleId = options.id || uuidv4();
|
|
1288
|
+
if (options.publish && !options.yes && !await confirmPublicPublish(articleId)) {
|
|
1289
|
+
output.info("Article creation cancelled; nothing was published.");
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1167
1292
|
const created = await client.article.create(workspaceId, {
|
|
1168
1293
|
articleId,
|
|
1169
1294
|
title: String(title),
|
|
@@ -1235,7 +1360,27 @@ function createArticleCommands() {
|
|
|
1235
1360
|
}
|
|
1236
1361
|
output.success("Article created successfully");
|
|
1237
1362
|
if (contentText !== null) output.success("Article content uploaded");
|
|
1238
|
-
|
|
1363
|
+
if (!options.publish) {
|
|
1364
|
+
output.output(created);
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
try {
|
|
1368
|
+
const publication = await client.publish.publish(
|
|
1369
|
+
workspaceId,
|
|
1370
|
+
articleId,
|
|
1371
|
+
publishRequest(options)
|
|
1372
|
+
);
|
|
1373
|
+
output.success("Article published publicly");
|
|
1374
|
+
output.output({
|
|
1375
|
+
...created ?? { articleId, workspaceId },
|
|
1376
|
+
publication
|
|
1377
|
+
});
|
|
1378
|
+
} catch (error) {
|
|
1379
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1380
|
+
throw new Error(
|
|
1381
|
+
`Article ${articleId} was created and kept, but publishing failed: ${message}`
|
|
1382
|
+
);
|
|
1383
|
+
}
|
|
1239
1384
|
});
|
|
1240
1385
|
article.command("update <articleId>").description("Update an article").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("-t, --title <title>", "New title").option("--archive", "Archive the article").option("--pin", "Pin the article").option("--file <path>", "Update article content from a file (use - for stdin)").option("--content <text>", "Update article content as an inline string").action(async (articleId, options) => {
|
|
1241
1386
|
requireApiKey();
|
|
@@ -1274,6 +1419,50 @@ function createArticleCommands() {
|
|
|
1274
1419
|
output.warning("No changes provided. Use --title, --archive, --pin, --file, or --content.");
|
|
1275
1420
|
}
|
|
1276
1421
|
});
|
|
1422
|
+
article.command("publish <articleId>").description("Publish or update an article at a public mded.it link").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("--slug <slug>", "Custom public-link slug").option("--seo-title <title>", "SEO/social title for the public page").option("--seo-description <description>", "SEO/social description for the public page").option("-y, --yes", "Skip public-publishing confirmation").action(async (articleId, options) => {
|
|
1423
|
+
requireApiKey();
|
|
1424
|
+
const client = getApiClient();
|
|
1425
|
+
const workspaceId = requireWorkspaceId(options.workspace);
|
|
1426
|
+
if (!options.yes && !await confirmPublicPublish(articleId)) {
|
|
1427
|
+
output.info("Publish cancelled.");
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
const result = await client.publish.publish(
|
|
1431
|
+
workspaceId,
|
|
1432
|
+
articleId,
|
|
1433
|
+
publishRequest(options)
|
|
1434
|
+
);
|
|
1435
|
+
output.success("Article published publicly");
|
|
1436
|
+
output.output(result);
|
|
1437
|
+
});
|
|
1438
|
+
article.command("publish-status <articleId>").description("Show public publishing status for an article").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").action(async (articleId, options) => {
|
|
1439
|
+
requireApiKey();
|
|
1440
|
+
const client = getApiClient();
|
|
1441
|
+
const workspaceId = requireWorkspaceId(options.workspace);
|
|
1442
|
+
output.output(await client.publish.status(workspaceId, articleId));
|
|
1443
|
+
});
|
|
1444
|
+
article.command("unpublish <articleId>").description("Disable an article public link").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("-y, --yes", "Skip confirmation").action(async (articleId, options) => {
|
|
1445
|
+
requireApiKey();
|
|
1446
|
+
const client = getApiClient();
|
|
1447
|
+
const workspaceId = requireWorkspaceId(options.workspace);
|
|
1448
|
+
if (!options.yes) {
|
|
1449
|
+
const { confirm } = await inquirer.prompt([
|
|
1450
|
+
{
|
|
1451
|
+
type: "confirm",
|
|
1452
|
+
name: "confirm",
|
|
1453
|
+
message: `Unpublish article ${articleId}? Its public link will stop working.`,
|
|
1454
|
+
default: false
|
|
1455
|
+
}
|
|
1456
|
+
]);
|
|
1457
|
+
if (!confirm) {
|
|
1458
|
+
output.info("Unpublish cancelled.");
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const result = await client.publish.unpublish(workspaceId, articleId);
|
|
1463
|
+
output.success("Article unpublished");
|
|
1464
|
+
output.output(result);
|
|
1465
|
+
});
|
|
1277
1466
|
article.command("watch <articleId>").description("Stream article and review changes as newline-delimited JSON").option("-w, --workspace <workspaceId>", "Workspace ID (or set default via config)").option("--agent <name>", "Agent presence name", "mdedit-cli").option("--poll-interval <milliseconds>", "REST fallback polling interval", "2000").action(async (articleId, options) => {
|
|
1278
1467
|
const apiKey = requireApiKey();
|
|
1279
1468
|
const workspaceId = requireWorkspaceId(options.workspace);
|
|
@@ -2162,7 +2351,11 @@ async function main() {
|
|
|
2162
2351
|
if (err.status === 401) {
|
|
2163
2352
|
output.info("Hint: set an API key via `mdedit config set apiKey <key>` or pass `--api-key <key>`.");
|
|
2164
2353
|
} else if (err.status === 403) {
|
|
2165
|
-
|
|
2354
|
+
if (err.message.includes("publishing:write")) {
|
|
2355
|
+
output.info("Hint: publishing requires an API key with publishing:write scope.");
|
|
2356
|
+
} else {
|
|
2357
|
+
output.info("Hint: check that the API key has the required scope and permission for this workspace/resource.");
|
|
2358
|
+
}
|
|
2166
2359
|
} else if (err.status === 404) {
|
|
2167
2360
|
output.info("Hint: verify your `apiUrl` and that the API build matches the CLI routes.");
|
|
2168
2361
|
}
|