mdkg 0.0.7 → 0.0.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.
- package/CHANGELOG.md +56 -0
- package/CONTRIBUTING.md +124 -0
- package/README.md +33 -10
- package/dist/cli.js +80 -32
- package/dist/commands/checkpoint.js +19 -2
- package/dist/commands/event.js +12 -0
- package/dist/commands/new.js +50 -4
- package/dist/commands/pack.js +14 -0
- package/dist/commands/query_output.js +2 -0
- package/dist/commands/search.js +8 -0
- package/dist/commands/show.js +7 -0
- package/dist/commands/skill.js +80 -12
- package/dist/commands/task.js +41 -4
- package/dist/commands/validate.js +31 -3
- package/dist/commands/workspace.js +105 -13
- package/dist/core/config.js +217 -22
- package/dist/core/migrate.js +39 -5
- package/dist/core/workspace_path.js +41 -0
- package/dist/graph/agent_file_types.js +392 -0
- package/dist/graph/edges.js +13 -10
- package/dist/graph/frontmatter.js +33 -0
- package/dist/graph/indexer.js +1 -0
- package/dist/graph/node.js +21 -5
- package/dist/graph/skills_indexer.js +14 -1
- package/dist/graph/validate_graph.js +302 -2
- package/dist/init/AGENT_START.md +13 -0
- package/dist/init/CLI_COMMAND_MATRIX.md +43 -1
- package/dist/init/README.md +7 -0
- package/dist/init/skills/default/verify-close-and-checkpoint/SKILL.md +1 -1
- package/dist/init/templates/default/dispute.md +31 -0
- package/dist/init/templates/default/feedback.md +27 -0
- package/dist/init/templates/default/proposal.md +35 -0
- package/dist/init/templates/default/receipt.md +31 -0
- package/dist/init/templates/default/spec.md +43 -0
- package/dist/init/templates/default/work.md +44 -0
- package/dist/init/templates/default/work_order.md +32 -0
- package/dist/pack/export_json.js +3 -0
- package/dist/pack/export_md.js +9 -0
- package/dist/pack/export_xml.js +9 -0
- package/dist/pack/order.js +7 -0
- package/dist/pack/pack.js +1 -0
- package/dist/util/argparse.js +1 -0
- package/dist/util/id.js +19 -0
- package/package.json +9 -2
- package/scripts/postinstall.js +89 -0
package/dist/pack/export_json.js
CHANGED
|
@@ -15,6 +15,9 @@ function buildFrontmatter(node) {
|
|
|
15
15
|
if (node.aliases.length > 0) {
|
|
16
16
|
frontmatter.aliases = node.aliases;
|
|
17
17
|
}
|
|
18
|
+
for (const [key, value] of Object.entries(node.attributes ?? {})) {
|
|
19
|
+
frontmatter[key] = value;
|
|
20
|
+
}
|
|
18
21
|
return frontmatter;
|
|
19
22
|
}
|
|
20
23
|
function exportJson(pack) {
|
package/dist/pack/export_md.js
CHANGED
|
@@ -7,6 +7,12 @@ function formatList(label, values) {
|
|
|
7
7
|
}
|
|
8
8
|
return `${label}: ${values.join(", ")}`;
|
|
9
9
|
}
|
|
10
|
+
function formatAttribute(label, value) {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return formatList(label, value);
|
|
13
|
+
}
|
|
14
|
+
return `${label}: ${String(value)}`;
|
|
15
|
+
}
|
|
10
16
|
function renderHeader(meta, nodes) {
|
|
11
17
|
const lines = [];
|
|
12
18
|
lines.push("# mdkg pack");
|
|
@@ -56,6 +62,9 @@ function renderNode(node) {
|
|
|
56
62
|
if (node.refs.length > 0) {
|
|
57
63
|
lines.push(formatList("refs", node.refs));
|
|
58
64
|
}
|
|
65
|
+
for (const [key, value] of Object.entries(node.attributes ?? {})) {
|
|
66
|
+
lines.push(formatAttribute(key, value));
|
|
67
|
+
}
|
|
59
68
|
if (node.body.trim().length > 0) {
|
|
60
69
|
lines.push("");
|
|
61
70
|
lines.push(node.body);
|
package/dist/pack/export_xml.js
CHANGED
|
@@ -21,6 +21,12 @@ function listItems(tag, itemTag, items, indent) {
|
|
|
21
21
|
lines.push(`${indent}</${tag}>`);
|
|
22
22
|
return lines;
|
|
23
23
|
}
|
|
24
|
+
function attributeLines(key, value, indent) {
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
return listItems(key, "item", value, indent);
|
|
27
|
+
}
|
|
28
|
+
return [`${indent}<${key}>${escapeXml(String(value))}</${key}>`];
|
|
29
|
+
}
|
|
24
30
|
function exportXml(pack) {
|
|
25
31
|
const lines = [];
|
|
26
32
|
lines.push("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
@@ -78,6 +84,9 @@ function exportXml(pack) {
|
|
|
78
84
|
lines.push(...listItems("artifacts", "artifact", node.artifacts, " "));
|
|
79
85
|
lines.push(...listItems("refs", "ref", node.refs, " "));
|
|
80
86
|
lines.push(...listItems("aliases", "alias", node.aliases, " "));
|
|
87
|
+
for (const [key, value] of Object.entries(node.attributes ?? {})) {
|
|
88
|
+
lines.push(...attributeLines(key, value, " "));
|
|
89
|
+
}
|
|
81
90
|
lines.push(" </frontmatter>");
|
|
82
91
|
lines.push(` <body>${escapeXml(node.body)}</body>`);
|
|
83
92
|
lines.push(" </node>");
|
package/dist/pack/order.js
CHANGED
package/dist/pack/pack.js
CHANGED
package/dist/util/argparse.js
CHANGED
package/dist/util/id.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isCanonicalId = isCanonicalId;
|
|
4
|
+
exports.isPortableId = isPortableId;
|
|
4
5
|
exports.isCanonicalIdRef = isCanonicalIdRef;
|
|
6
|
+
exports.isPortableIdRef = isPortableIdRef;
|
|
5
7
|
const NUMERIC_ID_RE = /^[a-z]+-[0-9]+$/;
|
|
6
8
|
const WORKSPACE_RE = /^[a-z][a-z0-9_]*$/;
|
|
9
|
+
const PORTABLE_ID_RE = /^[a-z][a-z0-9_]*(?:[._-][a-z0-9_]+)*$/;
|
|
7
10
|
const SPECIAL_IDS = new Set(["rule-guide", "rule-soul", "rule-human"]);
|
|
8
11
|
function isCanonicalId(value) {
|
|
9
12
|
return NUMERIC_ID_RE.test(value) || SPECIAL_IDS.has(value);
|
|
10
13
|
}
|
|
14
|
+
function isPortableId(value) {
|
|
15
|
+
return isCanonicalId(value) || PORTABLE_ID_RE.test(value);
|
|
16
|
+
}
|
|
11
17
|
function isCanonicalIdRef(value) {
|
|
12
18
|
const normalized = value.toLowerCase();
|
|
13
19
|
const parts = normalized.split(":");
|
|
@@ -21,3 +27,16 @@ function isCanonicalIdRef(value) {
|
|
|
21
27
|
const id = parts[1] ?? "";
|
|
22
28
|
return WORKSPACE_RE.test(workspace) && isCanonicalId(id);
|
|
23
29
|
}
|
|
30
|
+
function isPortableIdRef(value) {
|
|
31
|
+
const normalized = value.toLowerCase();
|
|
32
|
+
const parts = normalized.split(":");
|
|
33
|
+
if (parts.length === 1) {
|
|
34
|
+
return isPortableId(parts[0] ?? "");
|
|
35
|
+
}
|
|
36
|
+
if (parts.length !== 2) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const workspace = parts[0] ?? "";
|
|
40
|
+
const id = parts[1] ?? "";
|
|
41
|
+
return WORKSPACE_RE.test(workspace) && isPortableId(id);
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdkg",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Markdown Knowledge Graph",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -12,8 +12,12 @@
|
|
|
12
12
|
"test": "npm run build && npm run build:test && node --test dist/tests/**/*.test.js",
|
|
13
13
|
"test:coverage": "npm run build && npm run build:test && node --test --experimental-test-coverage dist/tests/**/*.test.js",
|
|
14
14
|
"smoke:consumer": "npm run build && node scripts/smoke-consumer.js",
|
|
15
|
+
"smoke:matrix": "npm run build && node scripts/smoke-command-matrix.js",
|
|
15
16
|
"cli:snapshot": "npm run build && node scripts/cli_help_snapshot.js",
|
|
16
|
-
"cli:check": "npm run build && node scripts/cli_help_snapshot.js --check"
|
|
17
|
+
"cli:check": "npm run build && node scripts/cli_help_snapshot.js --check",
|
|
18
|
+
"prepack": "npm run build && node scripts/assert-publish-ready.js",
|
|
19
|
+
"prepublishOnly": "npm run test && npm run cli:check && node dist/cli.js validate && npm run smoke:consumer && npm run smoke:matrix && node scripts/assert-publish-ready.js",
|
|
20
|
+
"postinstall": "node scripts/postinstall.js"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
"@types/node": "^18.19.0",
|
|
@@ -28,7 +32,10 @@
|
|
|
28
32
|
"dist/pack/",
|
|
29
33
|
"dist/templates/",
|
|
30
34
|
"dist/util/",
|
|
35
|
+
"scripts/postinstall.js",
|
|
31
36
|
"README.md",
|
|
37
|
+
"CHANGELOG.md",
|
|
38
|
+
"CONTRIBUTING.md",
|
|
32
39
|
"LICENSE"
|
|
33
40
|
],
|
|
34
41
|
"engines": {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const { spawnSync } = require("node:child_process");
|
|
6
|
+
|
|
7
|
+
function readPackageVersion() {
|
|
8
|
+
try {
|
|
9
|
+
const pkgPath = path.resolve(__dirname, "..", "package.json");
|
|
10
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
11
|
+
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
12
|
+
} catch {
|
|
13
|
+
return "unknown";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function npmCommand(platform = process.platform) {
|
|
18
|
+
return platform === "win32" ? "npm.cmd" : "npm";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function npmPrefixGlobal(env = process.env, platform = process.platform, spawn = spawnSync) {
|
|
22
|
+
if (env.npm_config_prefix) {
|
|
23
|
+
return env.npm_config_prefix;
|
|
24
|
+
}
|
|
25
|
+
const result = spawn(npmCommand(platform), ["prefix", "-g"], {
|
|
26
|
+
encoding: "utf8",
|
|
27
|
+
stdio: "pipe",
|
|
28
|
+
});
|
|
29
|
+
if (result.status !== 0) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const prefix = String(result.stdout || "").trim();
|
|
33
|
+
return prefix || undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function globalBinFromPrefix(prefix, platform = process.platform) {
|
|
37
|
+
if (!prefix) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return platform === "win32" ? prefix : path.join(prefix, "bin");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function pathIncludesDir(dir, env = process.env, platform = process.platform) {
|
|
44
|
+
if (!dir) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const currentPath = env.PATH || "";
|
|
48
|
+
return currentPath
|
|
49
|
+
.split(path.delimiter)
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.some((entry) => path.resolve(entry) === path.resolve(dir));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function buildPostinstallMessage(env = process.env, platform = process.platform, spawn = spawnSync) {
|
|
55
|
+
const version = readPackageVersion();
|
|
56
|
+
const lines = [
|
|
57
|
+
`mdkg ${version} installed.`,
|
|
58
|
+
"",
|
|
59
|
+
"Start here:",
|
|
60
|
+
" mdkg --help",
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const prefix = npmPrefixGlobal(env, platform, spawn);
|
|
64
|
+
const globalBin = globalBinFromPrefix(prefix, platform);
|
|
65
|
+
if (platform !== "win32" && globalBin && !pathIncludesDir(globalBin, env, platform)) {
|
|
66
|
+
lines.push(
|
|
67
|
+
"",
|
|
68
|
+
"If your shell cannot find mdkg, add npm's global bin directory to PATH:",
|
|
69
|
+
"",
|
|
70
|
+
"# zsh",
|
|
71
|
+
`echo 'export PATH="${globalBin}:$PATH"' >> ~/.zshrc`,
|
|
72
|
+
"",
|
|
73
|
+
"# bash",
|
|
74
|
+
`echo 'export PATH="${globalBin}:$PATH"' >> ~/.bashrc`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return lines.join("\n");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (require.main === module) {
|
|
82
|
+
console.log(buildPostinstallMessage());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = {
|
|
86
|
+
buildPostinstallMessage,
|
|
87
|
+
globalBinFromPrefix,
|
|
88
|
+
pathIncludesDir,
|
|
89
|
+
};
|