mdkg 0.1.3 → 0.1.5

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 (49) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/README.md +34 -10
  3. package/dist/cli.js +354 -87
  4. package/dist/commands/bundle.js +7 -7
  5. package/dist/commands/capability.js +118 -4
  6. package/dist/commands/doctor.js +15 -15
  7. package/dist/commands/goal.js +548 -0
  8. package/dist/commands/index.js +1 -1
  9. package/dist/commands/init.js +1 -0
  10. package/dist/commands/list.js +1 -1
  11. package/dist/commands/new.js +7 -1
  12. package/dist/commands/next.js +1 -1
  13. package/dist/commands/node_card.js +1 -1
  14. package/dist/commands/pack.js +1 -1
  15. package/dist/commands/search.js +1 -1
  16. package/dist/commands/show.js +1 -1
  17. package/dist/commands/subgraph.js +312 -0
  18. package/dist/commands/task.js +1 -1
  19. package/dist/commands/upgrade.js +54 -7
  20. package/dist/commands/validate.js +39 -7
  21. package/dist/commands/work.js +1 -1
  22. package/dist/core/config.js +95 -39
  23. package/dist/graph/frontmatter.js +8 -0
  24. package/dist/graph/goal_scope.js +127 -0
  25. package/dist/graph/index_cache.js +12 -12
  26. package/dist/graph/indexer.js +1 -1
  27. package/dist/graph/node.js +80 -1
  28. package/dist/graph/reindex.js +6 -6
  29. package/dist/graph/sqlite_index.js +6 -6
  30. package/dist/graph/{bundle_imports.js → subgraphs.js} +214 -140
  31. package/dist/graph/validate_graph.js +41 -0
  32. package/dist/graph/visibility.js +3 -3
  33. package/dist/init/AGENT_START.md +17 -1
  34. package/dist/init/CLI_COMMAND_MATRIX.md +43 -7
  35. package/dist/init/README.md +9 -8
  36. package/dist/init/config.json +1 -1
  37. package/dist/init/core/rule-3-cli-contract.md +56 -23
  38. package/dist/init/core/rule-4-repo-safety-and-ignores.md +7 -2
  39. package/dist/init/core/rule-6-templates-and-schemas.md +10 -1
  40. package/dist/init/init-manifest.json +20 -10
  41. package/dist/init/skills/default/pursue-mdkg-goal/SKILL.md +68 -0
  42. package/dist/init/skills/default/select-work-and-ground-context/SKILL.md +9 -7
  43. package/dist/init/skills/default/verify-close-and-checkpoint/SKILL.md +11 -10
  44. package/dist/init/templates/default/goal.md +91 -0
  45. package/dist/pack/order.js +2 -1
  46. package/dist/pack/pack.js +17 -0
  47. package/dist/util/argparse.js +2 -0
  48. package/package.json +8 -6
  49. package/dist/commands/bundle_import.js +0 -255
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCapabilityListCommand = runCapabilityListCommand;
4
4
  exports.runCapabilitySearchCommand = runCapabilitySearchCommand;
5
5
  exports.runCapabilityShowCommand = runCapabilityShowCommand;
6
+ exports.runCapabilityResolveCommand = runCapabilityResolveCommand;
6
7
  const config_1 = require("../core/config");
7
8
  const capabilities_indexer_1 = require("../graph/capabilities_indexer");
8
9
  const capabilities_index_cache_1 = require("../graph/capabilities_index_cache");
9
- const bundle_imports_1 = require("../graph/bundle_imports");
10
+ const subgraphs_1 = require("../graph/subgraphs");
10
11
  const errors_1 = require("../util/errors");
11
12
  function normalizeKind(value) {
12
13
  if (value === undefined) {
@@ -39,11 +40,11 @@ function loadRecords(options) {
39
40
  if (stale && !rebuilt && !options.noCache) {
40
41
  console.error("warning: capabilities index is stale; run mdkg index to refresh");
41
42
  }
42
- const imported = (0, bundle_imports_1.buildImportedCapabilityRecords)(options.root, config);
43
- for (const warning of imported.warnings) {
43
+ const subgraph = (0, subgraphs_1.buildSubgraphCapabilityRecords)(options.root, config);
44
+ for (const warning of subgraph.warnings) {
44
45
  console.error(`warning: ${warning}`);
45
46
  }
46
- return [...index.records, ...imported.records];
47
+ return [...index.records, ...subgraph.records];
47
48
  }
48
49
  function applyFilters(records, options) {
49
50
  const kind = normalizeKind(options.kind);
@@ -95,6 +96,89 @@ function matchesQuery(record, query) {
95
96
  const text = capabilitySearchText(record);
96
97
  return terms.every((term) => text.includes(term));
97
98
  }
99
+ function recordSource(record) {
100
+ const source = record.source;
101
+ return source ?? {};
102
+ }
103
+ function isStale(record) {
104
+ return recordSource(record).stale === true;
105
+ }
106
+ function hasReadPermission(record) {
107
+ const permissions = recordSource(record).permissions;
108
+ return !Array.isArray(permissions) || permissions.includes("read");
109
+ }
110
+ function requirementMatch(record, required) {
111
+ if (!required) {
112
+ return 0;
113
+ }
114
+ const normalized = required.toLowerCase();
115
+ const haystack = [
116
+ ...record.refs,
117
+ ...record.tags,
118
+ JSON.stringify(record.spec ?? {}),
119
+ JSON.stringify(record.work ?? {}),
120
+ JSON.stringify(record.skill ?? {}),
121
+ ]
122
+ .join(" ")
123
+ .toLowerCase();
124
+ return haystack.includes(normalized) ? 1 : 0;
125
+ }
126
+ function linkageScore(record) {
127
+ let score = 0;
128
+ if (record.kind === "work") {
129
+ score += 2;
130
+ }
131
+ if (record.kind === "spec") {
132
+ score += 1;
133
+ }
134
+ if (record.work || record.spec) {
135
+ score += 1;
136
+ }
137
+ return score;
138
+ }
139
+ function resolveScore(record, options) {
140
+ let score = 0;
141
+ if (record.workspace === "root") {
142
+ score += 1000;
143
+ }
144
+ if (!isStale(record)) {
145
+ score += 500;
146
+ }
147
+ if (hasReadPermission(record)) {
148
+ score += 100;
149
+ }
150
+ if (options.query && matchesQuery(record, options.query)) {
151
+ score += 50;
152
+ }
153
+ score += requirementMatch(record, options.requires) * 25;
154
+ score += linkageScore(record);
155
+ return score;
156
+ }
157
+ function resolveCapabilities(records, options) {
158
+ const filtered = records.filter((record) => {
159
+ if (options.freshOnly && isStale(record)) {
160
+ return false;
161
+ }
162
+ if (options.query && !matchesQuery(record, options.query)) {
163
+ return false;
164
+ }
165
+ if (options.requires && requirementMatch(record, options.requires) === 0) {
166
+ return false;
167
+ }
168
+ return true;
169
+ });
170
+ return filtered.sort((a, b) => {
171
+ const scoreDelta = resolveScore(b, options) - resolveScore(a, options);
172
+ if (scoreDelta !== 0) {
173
+ return scoreDelta;
174
+ }
175
+ const qidDelta = a.qid.localeCompare(b.qid);
176
+ if (qidDelta !== 0) {
177
+ return qidDelta;
178
+ }
179
+ return a.path.localeCompare(b.path);
180
+ });
181
+ }
98
182
  function printCapabilityList(records, json, query) {
99
183
  if (json) {
100
184
  console.log(JSON.stringify({
@@ -160,3 +244,33 @@ function runCapabilityShowCommand(options) {
160
244
  const records = loadRecords(options);
161
245
  printCapability(resolveCapability(records, options.id), options.json);
162
246
  }
247
+ function runCapabilityResolveCommand(options) {
248
+ const records = applyFilters(loadRecords(options), options);
249
+ const items = resolveCapabilities(records, options).map((record, rank) => ({
250
+ rank: rank + 1,
251
+ score: resolveScore(record, options),
252
+ stale: isStale(record),
253
+ item: record,
254
+ }));
255
+ if (options.json) {
256
+ console.log(JSON.stringify({
257
+ kind: "capability.resolve",
258
+ query: options.query,
259
+ requires: options.requires,
260
+ fresh_only: options.freshOnly === true,
261
+ count: items.length,
262
+ items,
263
+ }, null, 2));
264
+ return;
265
+ }
266
+ if (items.length === 0) {
267
+ console.log("no capabilities resolved");
268
+ return;
269
+ }
270
+ console.log(`resolved capabilities: ${items.length}`);
271
+ for (const result of items) {
272
+ const record = result.item;
273
+ const stale = result.stale ? " stale" : "";
274
+ console.log(`${result.rank}. ${record.qid} | score ${result.score}${stale} | ${record.kind} | ${record.title}`);
275
+ }
276
+ }
@@ -9,7 +9,7 @@ const path_1 = __importDefault(require("path"));
9
9
  const config_1 = require("../core/config");
10
10
  const index_cache_1 = require("../graph/index_cache");
11
11
  const capabilities_index_cache_1 = require("../graph/capabilities_index_cache");
12
- const bundle_imports_1 = require("../graph/bundle_imports");
12
+ const subgraphs_1 = require("../graph/subgraphs");
13
13
  const node_1 = require("../graph/node");
14
14
  const template_schema_1 = require("../graph/template_schema");
15
15
  const visibility_1 = require("../graph/visibility");
@@ -186,45 +186,45 @@ function runBundleStorageCheck(root, outputDir) {
186
186
  detail: `${bundles.length} bundle(s) found; run \`mdkg bundle verify <path>\` to check freshness before handoff`,
187
187
  };
188
188
  }
189
- function runBundleImportChecks(root, config) {
190
- const projection = (0, bundle_imports_1.buildBundleImportsIndex)(root, config);
191
- if (projection.index.imports.length === 0) {
189
+ function runSubgraphChecks(root, config) {
190
+ const projection = (0, subgraphs_1.buildSubgraphsIndex)(root, config);
191
+ if (projection.index.subgraphs.length === 0) {
192
192
  return [
193
193
  {
194
- name: "bundle-imports",
194
+ name: "subgraphs",
195
195
  ok: true,
196
- detail: "no bundle imports configured",
196
+ detail: "no subgraphs configured",
197
197
  },
198
198
  ];
199
199
  }
200
- return projection.index.imports.map((item) => {
200
+ return projection.index.subgraphs.map((item) => {
201
201
  if (!item.enabled) {
202
202
  return {
203
- name: `bundle-import:${item.alias}`,
203
+ name: `subgraph:${item.alias}`,
204
204
  ok: true,
205
205
  level: "warn",
206
- detail: `disabled import at ${item.path}`,
206
+ detail: "disabled subgraph",
207
207
  };
208
208
  }
209
209
  if (item.error_count > 0) {
210
210
  return {
211
- name: `bundle-import:${item.alias}`,
211
+ name: `subgraph:${item.alias}`,
212
212
  ok: false,
213
213
  detail: item.errors.join("; "),
214
214
  };
215
215
  }
216
216
  if (item.stale || item.warning_count > 0) {
217
217
  return {
218
- name: `bundle-import:${item.alias}`,
218
+ name: `subgraph:${item.alias}`,
219
219
  ok: true,
220
220
  level: "warn",
221
- detail: `import is stale or has warnings; run \`mdkg bundle import verify ${item.alias}\` (${item.warnings.join("; ")})`,
221
+ detail: `subgraph is stale or has warnings; run \`mdkg subgraph verify ${item.alias}\` (${item.warnings.join("; ")})`,
222
222
  };
223
223
  }
224
224
  return {
225
- name: `bundle-import:${item.alias}`,
225
+ name: `subgraph:${item.alias}`,
226
226
  ok: true,
227
- detail: `import loaded from ${item.path}`,
227
+ detail: `subgraph loaded from ${item.sources.map((source) => source.path).join(", ")}`,
228
228
  };
229
229
  });
230
230
  }
@@ -299,7 +299,7 @@ function runDoctorCommand(options) {
299
299
  results.push(runArchiveLargeCacheCheck(options.root, config.archive.large_cache_warning_bytes));
300
300
  results.push(runBundleStorageCheck(options.root, config.bundles.output_dir));
301
301
  results.push(runSqliteCheck(options.root, config));
302
- results.push(...runBundleImportChecks(options.root, config));
302
+ results.push(...runSubgraphChecks(options.root, config));
303
303
  results.push(runVisibilityPolicyCheck(options.root, config, options));
304
304
  try {
305
305
  const templateSchemaInfo = (0, template_schema_1.loadTemplateSchemasWithInfo)(options.root, config, node_1.ALLOWED_TYPES);