mdkg 0.1.0 → 0.1.2

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 (68) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +108 -15
  3. package/dist/cli.js +566 -15
  4. package/dist/commands/archive.js +474 -0
  5. package/dist/commands/bundle.js +743 -0
  6. package/dist/commands/bundle_import.js +243 -0
  7. package/dist/commands/capability.js +162 -0
  8. package/dist/commands/doctor.js +233 -2
  9. package/dist/commands/format.js +38 -9
  10. package/dist/commands/index.js +11 -0
  11. package/dist/commands/init.js +188 -63
  12. package/dist/commands/init_manifest.js +19 -6
  13. package/dist/commands/list.js +5 -2
  14. package/dist/commands/new.js +6 -0
  15. package/dist/commands/next.js +7 -0
  16. package/dist/commands/node_card.js +4 -1
  17. package/dist/commands/pack.js +62 -2
  18. package/dist/commands/query_output.js +1 -0
  19. package/dist/commands/search.js +5 -2
  20. package/dist/commands/show.js +7 -14
  21. package/dist/commands/skill_mirror.js +22 -0
  22. package/dist/commands/task.js +3 -0
  23. package/dist/commands/upgrade.js +151 -13
  24. package/dist/commands/validate.js +19 -2
  25. package/dist/commands/work.js +365 -0
  26. package/dist/commands/workspace.js +12 -2
  27. package/dist/core/config.js +100 -1
  28. package/dist/graph/agent_file_types.js +78 -5
  29. package/dist/graph/archive_file.js +125 -0
  30. package/dist/graph/archive_integrity.js +66 -0
  31. package/dist/graph/bundle_imports.js +418 -0
  32. package/dist/graph/capabilities_index_cache.js +103 -0
  33. package/dist/graph/capabilities_indexer.js +231 -0
  34. package/dist/graph/frontmatter.js +19 -0
  35. package/dist/graph/index_cache.js +21 -4
  36. package/dist/graph/indexer.js +4 -1
  37. package/dist/graph/node.js +23 -4
  38. package/dist/graph/node_body.js +37 -0
  39. package/dist/graph/skills_indexer.js +8 -3
  40. package/dist/graph/template_schema.js +33 -5
  41. package/dist/graph/validate_graph.js +83 -7
  42. package/dist/graph/visibility.js +214 -0
  43. package/dist/graph/workspace_files.js +22 -0
  44. package/dist/init/AGENT_START.md +21 -0
  45. package/dist/init/CLI_COMMAND_MATRIX.md +58 -3
  46. package/dist/init/README.md +60 -3
  47. package/dist/init/config.json +13 -1
  48. package/dist/init/core/guide.md +6 -2
  49. package/dist/init/core/rule-3-cli-contract.md +71 -4
  50. package/dist/init/core/rule-4-repo-safety-and-ignores.md +20 -0
  51. package/dist/init/core/rule-6-templates-and-schemas.md +10 -1
  52. package/dist/init/init-manifest.json +19 -14
  53. package/dist/init/skills/default/build-pack-and-execute-task/SKILL.md +2 -1
  54. package/dist/init/skills/default/verify-close-and-checkpoint/SKILL.md +26 -0
  55. package/dist/init/templates/default/archive.md +33 -0
  56. package/dist/init/templates/default/receipt.md +15 -1
  57. package/dist/init/templates/default/work.md +6 -1
  58. package/dist/init/templates/default/work_order.md +15 -1
  59. package/dist/pack/export_md.js +3 -0
  60. package/dist/pack/export_xml.js +3 -0
  61. package/dist/pack/order.js +1 -0
  62. package/dist/pack/pack.js +3 -13
  63. package/dist/templates/builtin.js +38 -0
  64. package/dist/templates/loader.js +9 -16
  65. package/dist/util/argparse.js +30 -0
  66. package/dist/util/refs.js +40 -0
  67. package/dist/util/zip.js +153 -0
  68. package/package.json +8 -2
@@ -6,26 +6,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadTemplate = loadTemplate;
7
7
  exports.renderTemplate = renderTemplate;
8
8
  const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
9
  const frontmatter_1 = require("../graph/frontmatter");
11
10
  const errors_1 = require("../util/errors");
12
- function templateNameForType(type) {
13
- const normalized = type.toLowerCase();
14
- if (normalized === "checkpoint") {
15
- return "chk";
16
- }
17
- return normalized;
18
- }
11
+ const builtin_1 = require("./builtin");
19
12
  function loadTemplate(root, config, type, templateSet) {
20
- const setName = (templateSet ?? config.templates.default_set).toLowerCase();
21
- const templateName = templateNameForType(type);
22
- const templatePath = path_1.default.resolve(root, config.templates.root_path, setName, `${templateName}.md`);
23
- if (!fs_1.default.existsSync(templatePath)) {
24
- throw new errors_1.NotFoundError(`template not found: ${setName}/${templateName}.md`);
13
+ const templatePath = (0, builtin_1.resolveLocalTemplatePath)(root, config, type, templateSet);
14
+ if (!fs_1.default.existsSync(templatePath) && templateSet !== undefined) {
15
+ throw new errors_1.NotFoundError(`template not found: ${templateSet.toLowerCase()}/${(0, builtin_1.templateNameForType)(type)}.md`);
25
16
  }
26
- const content = fs_1.default.readFileSync(templatePath, "utf8");
27
- const { frontmatter, body } = (0, frontmatter_1.parseFrontmatter)(content, templatePath);
28
- return { templatePath, frontmatter, body };
17
+ const source = fs_1.default.existsSync(templatePath) ? "local" : "bundled";
18
+ const resolvedPath = source === "local" ? templatePath : (0, builtin_1.requireBundledTemplatePath)(type);
19
+ const content = fs_1.default.readFileSync(resolvedPath, "utf8");
20
+ const { frontmatter, body } = (0, frontmatter_1.parseFrontmatter)(content, resolvedPath);
21
+ return { templatePath: resolvedPath, source, frontmatter, body };
29
22
  }
30
23
  function isTokenPlaceholder(value) {
31
24
  return typeof value === "string" && /^\{\{[a-z0-9_]+\}\}$/.test(value);
@@ -15,6 +15,7 @@ const VALUE_FLAGS = new Set([
15
15
  "--edges",
16
16
  "--format",
17
17
  "--out",
18
+ "--output",
18
19
  "--relates",
19
20
  "--scope",
20
21
  "--blocked-by",
@@ -51,10 +52,37 @@ const VALUE_FLAGS = new Set([
51
52
  "--add-blocked-by",
52
53
  "--checkpoint",
53
54
  "--kind",
55
+ "--title",
56
+ "--agent-id",
57
+ "--inputs",
58
+ "--outputs",
59
+ "--required-capabilities",
60
+ "--pricing-model",
61
+ "--work-id",
62
+ "--requester",
63
+ "--request-ref",
64
+ "--input-refs",
65
+ "--requested-outputs",
66
+ "--constraint-refs",
67
+ "--receipt-status",
68
+ "--work-order-id",
69
+ "--outcome",
70
+ "--cost-ref",
71
+ "--proof-refs",
72
+ "--attestation-refs",
73
+ "--input-hashes",
74
+ "--output-hashes",
75
+ "--add-input-refs",
76
+ "--add-proof-refs",
77
+ "--add-attestation-refs",
54
78
  "--notes",
55
79
  "--agent",
56
80
  "--skill",
57
81
  "--tool",
82
+ "--visibility",
83
+ "--source-path",
84
+ "--source-repo",
85
+ "--max-stale-seconds",
58
86
  ]);
59
87
  const BOOLEAN_FLAGS = new Set([
60
88
  "--tolerant",
@@ -87,10 +115,12 @@ const BOOLEAN_FLAGS = new Set([
87
115
  "--list-profiles",
88
116
  "--with-scripts",
89
117
  "--clear-blocked-by",
118
+ "--all",
90
119
  ]);
91
120
  const FLAG_ALIASES = {
92
121
  "--o": "--out",
93
122
  "-o": "--out",
123
+ "--output": "--out",
94
124
  "--profile": "--pack-profile",
95
125
  "--f": "--format",
96
126
  "-f": "--format",
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUriRef = isUriRef;
4
+ exports.archiveIdFromUri = archiveIdFromUri;
5
+ exports.isArchiveUri = isArchiveUri;
6
+ exports.isSha256Ref = isSha256Ref;
7
+ exports.isPortableOrUriRef = isPortableOrUriRef;
8
+ exports.validatePortableOrUriRef = validatePortableOrUriRef;
9
+ const id_1 = require("./id");
10
+ const URI_RE = /^[a-z][a-z0-9+.-]*:\/\/\S+$/i;
11
+ const ARCHIVE_URI_RE = /^archive:\/\/([a-z][a-z0-9_]*(?:[._-][a-z0-9_]+)*)$/;
12
+ const SHA256_RE = /^sha256:[a-f0-9]{64}$/;
13
+ function isUriRef(value) {
14
+ return URI_RE.test(value);
15
+ }
16
+ function archiveIdFromUri(value) {
17
+ const match = ARCHIVE_URI_RE.exec(value);
18
+ if (!match) {
19
+ return undefined;
20
+ }
21
+ return match[1];
22
+ }
23
+ function isArchiveUri(value) {
24
+ return archiveIdFromUri(value) !== undefined;
25
+ }
26
+ function isSha256Ref(value) {
27
+ return SHA256_RE.test(value);
28
+ }
29
+ function isPortableOrUriRef(value) {
30
+ return (0, id_1.isPortableId)(value.toLowerCase()) || isUriRef(value);
31
+ }
32
+ function validatePortableOrUriRef(value) {
33
+ if (isUriRef(value)) {
34
+ if (value.startsWith("archive://")) {
35
+ return archiveIdFromUri(value) !== undefined;
36
+ }
37
+ return true;
38
+ }
39
+ return value === value.toLowerCase() && (0, id_1.isPortableId)(value);
40
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createDeterministicZip = createDeterministicZip;
7
+ exports.createDeterministicZipFromEntries = createDeterministicZipFromEntries;
8
+ exports.readZipEntries = readZipEntries;
9
+ exports.readSingleFileZip = readSingleFileZip;
10
+ const zlib_1 = __importDefault(require("zlib"));
11
+ const CRC_TABLE = new Uint32Array(256);
12
+ for (let i = 0; i < 256; i += 1) {
13
+ let value = i;
14
+ for (let bit = 0; bit < 8; bit += 1) {
15
+ value = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
16
+ }
17
+ CRC_TABLE[i] = value >>> 0;
18
+ }
19
+ function crc32(data) {
20
+ let crc = 0xffffffff;
21
+ for (const byte of data) {
22
+ crc = CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);
23
+ }
24
+ return (crc ^ 0xffffffff) >>> 0;
25
+ }
26
+ function dosDate1980() {
27
+ return {
28
+ time: 0,
29
+ date: (0 << 9) | (1 << 5) | 1,
30
+ };
31
+ }
32
+ function headerBuffer(size) {
33
+ return Buffer.alloc(size);
34
+ }
35
+ function createDeterministicZip(entryName, data) {
36
+ return createDeterministicZipFromEntries([{ name: entryName, data }]);
37
+ }
38
+ function normalizeEntryName(entryName) {
39
+ const normalizedName = entryName.split(/[\\/]/).filter(Boolean).join("/");
40
+ if (!normalizedName || normalizedName.includes("..")) {
41
+ throw new Error("zip entry name must be a relative file name");
42
+ }
43
+ return normalizedName;
44
+ }
45
+ function createDeterministicZipFromEntries(entries) {
46
+ if (entries.length === 0) {
47
+ throw new Error("zip must contain at least one entry");
48
+ }
49
+ const normalizedEntries = entries
50
+ .map((entry) => ({ name: normalizeEntryName(entry.name), data: entry.data }))
51
+ .sort((a, b) => a.name.localeCompare(b.name));
52
+ const seen = new Set();
53
+ for (const entry of normalizedEntries) {
54
+ if (seen.has(entry.name)) {
55
+ throw new Error(`duplicate zip entry: ${entry.name}`);
56
+ }
57
+ seen.add(entry.name);
58
+ }
59
+ const localRecords = [];
60
+ const centralRecords = [];
61
+ let localOffset = 0;
62
+ const timestamp = dosDate1980();
63
+ for (const entry of normalizedEntries) {
64
+ const nameBuffer = Buffer.from(entry.name, "utf8");
65
+ const compressed = zlib_1.default.deflateRawSync(entry.data, { level: 9 });
66
+ const crc = crc32(entry.data);
67
+ const local = headerBuffer(30);
68
+ local.writeUInt32LE(0x04034b50, 0);
69
+ local.writeUInt16LE(20, 4);
70
+ local.writeUInt16LE(0, 6);
71
+ local.writeUInt16LE(8, 8);
72
+ local.writeUInt16LE(timestamp.time, 10);
73
+ local.writeUInt16LE(timestamp.date, 12);
74
+ local.writeUInt32LE(crc, 14);
75
+ local.writeUInt32LE(compressed.length, 18);
76
+ local.writeUInt32LE(entry.data.length, 22);
77
+ local.writeUInt16LE(nameBuffer.length, 26);
78
+ local.writeUInt16LE(0, 28);
79
+ const central = headerBuffer(46);
80
+ central.writeUInt32LE(0x02014b50, 0);
81
+ central.writeUInt16LE(20, 4);
82
+ central.writeUInt16LE(20, 6);
83
+ central.writeUInt16LE(0, 8);
84
+ central.writeUInt16LE(8, 10);
85
+ central.writeUInt16LE(timestamp.time, 12);
86
+ central.writeUInt16LE(timestamp.date, 14);
87
+ central.writeUInt32LE(crc, 16);
88
+ central.writeUInt32LE(compressed.length, 20);
89
+ central.writeUInt32LE(entry.data.length, 24);
90
+ central.writeUInt16LE(nameBuffer.length, 28);
91
+ central.writeUInt16LE(0, 30);
92
+ central.writeUInt16LE(0, 32);
93
+ central.writeUInt16LE(0, 34);
94
+ central.writeUInt16LE(0, 36);
95
+ central.writeUInt32LE(0, 38);
96
+ central.writeUInt32LE(localOffset, 42);
97
+ const localRecord = Buffer.concat([local, nameBuffer, compressed]);
98
+ localRecords.push(localRecord);
99
+ centralRecords.push(Buffer.concat([central, nameBuffer]));
100
+ localOffset += localRecord.length;
101
+ }
102
+ const localPayload = Buffer.concat(localRecords);
103
+ const centralPayload = Buffer.concat(centralRecords);
104
+ const end = headerBuffer(22);
105
+ end.writeUInt32LE(0x06054b50, 0);
106
+ end.writeUInt16LE(0, 4);
107
+ end.writeUInt16LE(0, 6);
108
+ end.writeUInt16LE(normalizedEntries.length, 8);
109
+ end.writeUInt16LE(normalizedEntries.length, 10);
110
+ end.writeUInt32LE(centralPayload.length, 12);
111
+ end.writeUInt32LE(localPayload.length, 16);
112
+ end.writeUInt16LE(0, 20);
113
+ return Buffer.concat([localPayload, centralPayload, end]);
114
+ }
115
+ function readZipEntries(zip) {
116
+ const entries = [];
117
+ let offset = 0;
118
+ while (offset + 4 <= zip.length) {
119
+ const signature = zip.readUInt32LE(offset);
120
+ if (signature === 0x02014b50 || signature === 0x06054b50) {
121
+ break;
122
+ }
123
+ if (signature !== 0x04034b50) {
124
+ throw new Error("zip local header missing");
125
+ }
126
+ const method = zip.readUInt16LE(offset + 8);
127
+ const compressedSize = zip.readUInt32LE(offset + 18);
128
+ const uncompressedSize = zip.readUInt32LE(offset + 22);
129
+ const nameLength = zip.readUInt16LE(offset + 26);
130
+ const extraLength = zip.readUInt16LE(offset + 28);
131
+ const nameStart = offset + 30;
132
+ const dataOffset = nameStart + nameLength + extraLength;
133
+ const entryName = zip.slice(nameStart, nameStart + nameLength).toString("utf8");
134
+ const compressed = zip.slice(dataOffset, dataOffset + compressedSize);
135
+ const data = method === 8 ? zlib_1.default.inflateRawSync(compressed) : method === 0 ? compressed : undefined;
136
+ if (!data) {
137
+ throw new Error(`unsupported zip compression method: ${method}`);
138
+ }
139
+ if (data.length !== uncompressedSize) {
140
+ throw new Error("zip uncompressed size mismatch");
141
+ }
142
+ entries.push({ name: entryName, data });
143
+ offset = dataOffset + compressedSize;
144
+ }
145
+ return entries;
146
+ }
147
+ function readSingleFileZip(zip) {
148
+ const entries = readZipEntries(zip);
149
+ if (entries.length !== 1) {
150
+ throw new Error("zip must contain exactly one file");
151
+ }
152
+ return { entryName: entries[0].name, data: entries[0].data };
153
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdkg",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Markdown Knowledge Graph",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -14,10 +14,16 @@
14
14
  "smoke:consumer": "npm run build && node scripts/smoke-consumer.js",
15
15
  "smoke:matrix": "npm run build && node scripts/smoke-command-matrix.js",
16
16
  "smoke:upgrade": "npm run build && node scripts/smoke-upgrade.js",
17
+ "smoke:init": "npm run build && node scripts/smoke-init.js",
18
+ "smoke:capabilities": "npm run build && node scripts/smoke-capabilities.js",
19
+ "smoke:archive-work": "npm run build && node scripts/smoke-archive-work.js",
20
+ "smoke:bundle": "npm run build && node scripts/smoke-bundle.js",
21
+ "smoke:bundle-import": "npm run build && node scripts/smoke-bundle-import.js",
22
+ "smoke:visibility": "npm run build && node scripts/smoke-visibility.js",
17
23
  "cli:snapshot": "npm run build && node scripts/cli_help_snapshot.js",
18
24
  "cli:check": "npm run build && node scripts/cli_help_snapshot.js --check",
19
25
  "prepack": "npm run build && node scripts/assert-publish-ready.js",
20
- "prepublishOnly": "npm run test && npm run cli:check && node dist/cli.js validate && npm run smoke:consumer && npm run smoke:matrix && npm run smoke:upgrade && node scripts/assert-publish-ready.js",
26
+ "prepublishOnly": "npm run test && npm run cli:check && node dist/cli.js validate && npm run smoke:consumer && npm run smoke:matrix && npm run smoke:upgrade && npm run smoke:init && npm run smoke:capabilities && npm run smoke:archive-work && npm run smoke:bundle && npm run smoke:bundle-import && npm run smoke:visibility && node scripts/assert-publish-ready.js",
21
27
  "postinstall": "node scripts/postinstall.js"
22
28
  },
23
29
  "devDependencies": {