akm-cli 0.7.5 → 0.8.0-rc.3
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/.github/CHANGELOG.md +1 -1
- package/dist/cli/parse-args.js +86 -0
- package/dist/cli.js +1023 -521
- package/dist/commands/agent-dispatch.js +107 -0
- package/dist/commands/agent-support.js +62 -0
- package/dist/commands/config-cli.js +68 -84
- package/dist/commands/consolidate.js +812 -0
- package/dist/commands/distill-promotion-policy.js +658 -0
- package/dist/commands/distill.js +218 -43
- package/dist/commands/eval-cases.js +40 -0
- package/dist/commands/events.js +2 -23
- package/dist/commands/graph.js +222 -0
- package/dist/commands/health.js +376 -0
- package/dist/commands/help/help-accept.md +9 -0
- package/dist/commands/help/help-improve.md +53 -0
- package/dist/commands/help/help-proposals.md +15 -0
- package/dist/commands/help/help-propose.md +17 -0
- package/dist/commands/help/help-reject.md +8 -0
- package/dist/commands/history.js +3 -30
- package/dist/commands/improve.js +1161 -0
- package/dist/commands/info.js +2 -2
- package/dist/commands/init.js +2 -2
- package/dist/commands/install-audit.js +5 -1
- package/dist/commands/installed-stashes.js +118 -138
- package/dist/commands/knowledge.js +133 -0
- package/dist/commands/lint/agent-linter.js +46 -0
- package/dist/commands/lint/base-linter.js +291 -0
- package/dist/commands/lint/command-linter.js +46 -0
- package/dist/commands/lint/default-linter.js +13 -0
- package/dist/commands/lint/index.js +145 -0
- package/dist/commands/lint/knowledge-linter.js +13 -0
- package/dist/commands/lint/memory-linter.js +58 -0
- package/dist/commands/lint/registry.js +33 -0
- package/dist/commands/lint/skill-linter.js +42 -0
- package/dist/commands/lint/task-linter.js +47 -0
- package/dist/commands/lint/types.js +1 -0
- package/dist/commands/lint/vault-key-rules.js +67 -0
- package/dist/commands/lint/workflow-linter.js +53 -0
- package/dist/commands/lint.js +1 -0
- package/dist/commands/proposal.js +8 -7
- package/dist/commands/propose.js +71 -28
- package/dist/commands/reflect.js +135 -35
- package/dist/commands/registry-search.js +2 -2
- package/dist/commands/remember.js +54 -0
- package/dist/commands/schema-repair.js +130 -0
- package/dist/commands/search.js +21 -5
- package/dist/commands/show.js +125 -20
- package/dist/commands/source-add.js +10 -10
- package/dist/commands/source-manage.js +11 -19
- package/dist/commands/tasks.js +385 -0
- package/dist/commands/url-checker.js +39 -0
- package/dist/commands/vault.js +168 -77
- package/dist/core/action-contributors.js +25 -0
- package/dist/core/asset-ref.js +4 -0
- package/dist/core/asset-registry.js +4 -16
- package/dist/core/asset-spec.js +10 -0
- package/dist/core/common.js +100 -0
- package/dist/core/concurrent.js +22 -0
- package/dist/core/config.js +233 -133
- package/dist/core/events.js +73 -126
- package/dist/core/frontmatter.js +0 -6
- package/dist/core/markdown.js +17 -0
- package/dist/core/memory-improve.js +678 -0
- package/dist/core/parse.js +155 -0
- package/dist/core/paths.js +101 -3
- package/dist/core/proposal-validators.js +61 -0
- package/dist/core/proposals.js +49 -38
- package/dist/core/state-db.js +731 -0
- package/dist/core/time.js +51 -0
- package/dist/core/warn.js +59 -1
- package/dist/indexer/db-search.js +52 -238
- package/dist/indexer/db.js +403 -54
- package/dist/indexer/ensure-index.js +61 -0
- package/dist/indexer/graph-boost.js +247 -94
- package/dist/indexer/graph-db.js +201 -0
- package/dist/indexer/graph-dedup.js +99 -0
- package/dist/indexer/graph-extraction.js +409 -76
- package/dist/indexer/index-context.js +10 -0
- package/dist/indexer/indexer.js +456 -290
- package/dist/indexer/llm-cache.js +47 -0
- package/dist/indexer/matchers.js +124 -160
- package/dist/indexer/memory-inference.js +63 -29
- package/dist/indexer/metadata-contributors.js +26 -0
- package/dist/indexer/metadata.js +196 -197
- package/dist/indexer/path-resolver.js +89 -0
- package/dist/indexer/ranking-contributors.js +204 -0
- package/dist/indexer/ranking.js +74 -0
- package/dist/indexer/search-hit-enrichers.js +22 -0
- package/dist/indexer/search-source.js +24 -9
- package/dist/indexer/semantic-status.js +2 -16
- package/dist/indexer/walker.js +25 -0
- package/dist/integrations/agent/builders.js +109 -0
- package/dist/integrations/agent/config.js +203 -3
- package/dist/integrations/agent/index.js +5 -2
- package/dist/integrations/agent/model-aliases.js +63 -0
- package/dist/integrations/agent/profiles.js +67 -5
- package/dist/integrations/agent/prompts.js +77 -72
- package/dist/integrations/agent/sdk-runner.js +120 -0
- package/dist/integrations/agent/spawn.js +93 -22
- package/dist/integrations/lockfile.js +10 -18
- package/dist/integrations/session-logs/index.js +65 -0
- package/dist/integrations/session-logs/providers/claude-code.js +56 -0
- package/dist/integrations/session-logs/providers/opencode.js +52 -0
- package/dist/integrations/session-logs/types.js +1 -0
- package/dist/llm/call-ai.js +74 -0
- package/dist/llm/client.js +61 -122
- package/dist/llm/feature-gate.js +27 -16
- package/dist/llm/graph-extract.js +297 -62
- package/dist/llm/memory-infer.js +49 -71
- package/dist/llm/metadata-enhance.js +39 -22
- package/dist/llm/prompts/graph-extract-user-prompt.md +12 -0
- package/dist/output/cli-hints-full.md +277 -0
- package/dist/output/cli-hints-short.md +65 -0
- package/dist/output/cli-hints.js +2 -318
- package/dist/output/renderers.js +220 -256
- package/dist/output/shapes.js +101 -93
- package/dist/output/text.js +256 -17
- package/dist/registry/providers/skills-sh.js +61 -49
- package/dist/registry/providers/static-index.js +44 -48
- package/dist/registry/resolve.js +8 -16
- package/dist/setup/setup.js +510 -11
- package/dist/sources/provider-factory.js +2 -1
- package/dist/sources/providers/filesystem.js +16 -23
- package/dist/sources/providers/git.js +4 -5
- package/dist/sources/providers/website.js +15 -22
- package/dist/sources/website-ingest.js +4 -0
- package/dist/tasks/backends/cron.js +200 -0
- package/dist/tasks/backends/exec-utils.js +25 -0
- package/dist/tasks/backends/index.js +32 -0
- package/dist/tasks/backends/launchd-template.xml +19 -0
- package/dist/tasks/backends/launchd.js +184 -0
- package/dist/tasks/backends/schtasks-template.xml +29 -0
- package/dist/tasks/backends/schtasks.js +212 -0
- package/dist/tasks/parser.js +198 -0
- package/dist/tasks/resolveAkmBin.js +84 -0
- package/dist/tasks/runner.js +432 -0
- package/dist/tasks/schedule.js +208 -0
- package/dist/tasks/schema.js +13 -0
- package/dist/tasks/validator.js +59 -0
- package/dist/wiki/index-template.md +12 -0
- package/dist/wiki/ingest-workflow-template.md +54 -0
- package/dist/wiki/log-template.md +8 -0
- package/dist/wiki/schema-template.md +61 -0
- package/dist/wiki/wiki-templates.js +12 -0
- package/dist/wiki/wiki.js +10 -61
- package/dist/workflows/authoring.js +5 -25
- package/dist/workflows/renderer.js +8 -3
- package/dist/workflows/runs.js +59 -91
- package/dist/workflows/validator.js +1 -1
- package/dist/workflows/workflow-template.md +24 -0
- package/docs/README.md +5 -2
- package/docs/migration/release-notes/0.7.0.md +1 -1
- package/docs/migration/release-notes/0.8.0.md +43 -0
- package/package.json +3 -2
- package/dist/templates/wiki-templates.js +0 -100
package/dist/output/renderers.js
CHANGED
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
import fs from "node:fs";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import { listKeys as listVaultKeys } from "../commands/vault";
|
|
12
|
-
import { hasErrnoCode } from "../core/common";
|
|
13
|
-
import { parseFrontmatter
|
|
12
|
+
import { asNonEmptyString, hasErrnoCode } from "../core/common";
|
|
13
|
+
import { parseFrontmatter } from "../core/frontmatter";
|
|
14
14
|
import { extractFrontmatterOnly, extractLineRange, extractSection, formatToc, parseMarkdownToc, } from "../core/markdown";
|
|
15
15
|
import { registerRenderer } from "../indexer/file-context";
|
|
16
16
|
import { extractCommentMetadata, extractDescriptionFromComments } from "../indexer/metadata";
|
|
17
|
+
import { registerMetadataContributor } from "../indexer/metadata-contributors";
|
|
17
18
|
import { buildWorkflowAction, workflowMdRenderer } from "../workflows/renderer";
|
|
18
19
|
// ── Interpreter auto-detection map ───────────────────────────────────────────
|
|
19
20
|
const INTERPRETER_MAP = {
|
|
@@ -165,7 +166,7 @@ const skillMdRenderer = {
|
|
|
165
166
|
name,
|
|
166
167
|
path: ctx.absPath,
|
|
167
168
|
action: "Read and follow the instructions below",
|
|
168
|
-
description:
|
|
169
|
+
description: asNonEmptyString(parsed.data.description),
|
|
169
170
|
...(tags ? { tags } : {}),
|
|
170
171
|
content: parsed.content,
|
|
171
172
|
};
|
|
@@ -184,11 +185,11 @@ const commandMdRenderer = {
|
|
|
184
185
|
name,
|
|
185
186
|
path: ctx.absPath,
|
|
186
187
|
action: "Fill $ARGUMENTS placeholders in the template, then dispatch",
|
|
187
|
-
description:
|
|
188
|
+
description: asNonEmptyString(parsedMd.data.description),
|
|
188
189
|
...(tags ? { tags } : {}),
|
|
189
190
|
template,
|
|
190
191
|
modelHint: typeof parsedMd.data.model === "string" ? parsedMd.data.model : undefined,
|
|
191
|
-
agent:
|
|
192
|
+
agent: asNonEmptyString(parsedMd.data.agent),
|
|
192
193
|
parameters: extractParameters(template),
|
|
193
194
|
};
|
|
194
195
|
},
|
|
@@ -204,168 +205,67 @@ const agentMdRenderer = {
|
|
|
204
205
|
name,
|
|
205
206
|
path: ctx.absPath,
|
|
206
207
|
action: "Dispatch using the prompt below verbatim. Use modelHint and toolPolicy if present.",
|
|
207
|
-
description:
|
|
208
|
+
description: asNonEmptyString(parsedMd.data.description),
|
|
208
209
|
prompt: parsedMd.content,
|
|
209
210
|
toolPolicy: parsedMd.data.tools,
|
|
210
211
|
modelHint: typeof parsedMd.data.model === "string" ? parsedMd.data.model : undefined,
|
|
211
212
|
};
|
|
212
213
|
},
|
|
213
214
|
};
|
|
214
|
-
// ── 4. knowledge-md
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return {
|
|
246
|
-
type: "knowledge",
|
|
247
|
-
name,
|
|
248
|
-
path: ctx.absPath,
|
|
249
|
-
action: "Reference material - read the content below. Use 'toc' view for large documents.",
|
|
250
|
-
content: `Section "${v.heading}" not found in ${name}. Try \`akm show <ref> toc\` to discover available headings.`,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
type: "knowledge",
|
|
255
|
-
name,
|
|
256
|
-
path: ctx.absPath,
|
|
257
|
-
action: "Reference material - read the content below. Use 'toc' view for large documents.",
|
|
258
|
-
content: section.content,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
case "lines": {
|
|
262
|
-
return {
|
|
263
|
-
type: "knowledge",
|
|
264
|
-
name,
|
|
265
|
-
path: ctx.absPath,
|
|
266
|
-
action: "Reference material - read the content below. Use 'toc' view for large documents.",
|
|
267
|
-
content: extractLineRange(content, v.start, v.end),
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
default: {
|
|
271
|
-
return {
|
|
272
|
-
type: "knowledge",
|
|
273
|
-
name,
|
|
274
|
-
path: ctx.absPath,
|
|
275
|
-
action: "Reference material - read the content below. Use 'toc' view for large documents.",
|
|
276
|
-
content,
|
|
277
|
-
};
|
|
215
|
+
// ── 4. knowledge-md / wiki-md shared helper ───────────────────────────────────
|
|
216
|
+
const KNOWLEDGE_ACTION = "Reference material - read the content below. Use 'toc' view for large documents.";
|
|
217
|
+
const WIKI_PAGE_ACTION = "Wiki page — read below. Use 'toc' to scan, 'section <heading>' for depth.";
|
|
218
|
+
/**
|
|
219
|
+
* Shared implementation for knowledge-md and wiki-md `buildShowResponse`.
|
|
220
|
+
*
|
|
221
|
+
* Both renderers handle the same set of view modes (toc, frontmatter, section,
|
|
222
|
+
* lines, full). The only differences are the `type` discriminant and the
|
|
223
|
+
* section-not-found message. Extracting this helper eliminates ~90 lines of
|
|
224
|
+
* byte-for-byte duplication.
|
|
225
|
+
*/
|
|
226
|
+
function buildMarkdownViewResponse(ctx, type, action) {
|
|
227
|
+
const name = deriveName(ctx);
|
|
228
|
+
const v = ctx.matchResult.meta?.view ?? { mode: "full" };
|
|
229
|
+
const content = ctx.content();
|
|
230
|
+
switch (v.mode) {
|
|
231
|
+
case "toc": {
|
|
232
|
+
const toc = parseMarkdownToc(content);
|
|
233
|
+
return { type, name, path: ctx.absPath, action, content: formatToc(toc) };
|
|
234
|
+
}
|
|
235
|
+
case "frontmatter": {
|
|
236
|
+
const fm = extractFrontmatterOnly(content);
|
|
237
|
+
return { type, name, path: ctx.absPath, action, content: fm ?? "(no frontmatter)" };
|
|
238
|
+
}
|
|
239
|
+
case "section": {
|
|
240
|
+
const section = extractSection(content, v.heading);
|
|
241
|
+
if (!section) {
|
|
242
|
+
const notFoundMsg = type === "wiki"
|
|
243
|
+
? `Section "${v.heading}" not found in ${name}. Try \`akm show wiki:${name} toc\` to discover available headings.`
|
|
244
|
+
: `Section "${v.heading}" not found in ${name}. Try \`akm show <ref> toc\` to discover available headings.`;
|
|
245
|
+
return { type, name, path: ctx.absPath, action, content: notFoundMsg };
|
|
278
246
|
}
|
|
247
|
+
return { type, name, path: ctx.absPath, action, content: section.content };
|
|
279
248
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
try {
|
|
283
|
-
const toc = parseMarkdownToc(ctx.content());
|
|
284
|
-
if (toc.headings.length > 0)
|
|
285
|
-
entry.toc = toc.headings;
|
|
249
|
+
case "lines": {
|
|
250
|
+
return { type, name, path: ctx.absPath, action, content: extractLineRange(content, v.start, v.end) };
|
|
286
251
|
}
|
|
287
|
-
|
|
288
|
-
|
|
252
|
+
default: {
|
|
253
|
+
return { type, name, path: ctx.absPath, action, content };
|
|
289
254
|
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// ── 4. knowledge-md ──────────────────────────────────────────────────────────
|
|
258
|
+
const knowledgeMdRenderer = {
|
|
259
|
+
name: "knowledge-md",
|
|
260
|
+
buildShowResponse(ctx) {
|
|
261
|
+
return buildMarkdownViewResponse(ctx, "knowledge", KNOWLEDGE_ACTION);
|
|
290
262
|
},
|
|
291
263
|
};
|
|
292
264
|
// ── 4b. wiki-md ──────────────────────────────────────────────────────────────
|
|
293
|
-
const WIKI_PAGE_ACTION = "Wiki page — read below. Use 'toc' to scan, 'section <heading>' for depth.";
|
|
294
265
|
const wikiMdRenderer = {
|
|
295
266
|
name: "wiki-md",
|
|
296
267
|
buildShowResponse(ctx) {
|
|
297
|
-
|
|
298
|
-
const v = ctx.matchResult.meta?.view ?? { mode: "full" };
|
|
299
|
-
const content = ctx.content();
|
|
300
|
-
switch (v.mode) {
|
|
301
|
-
case "toc": {
|
|
302
|
-
const toc = parseMarkdownToc(content);
|
|
303
|
-
return {
|
|
304
|
-
type: "wiki",
|
|
305
|
-
name,
|
|
306
|
-
path: ctx.absPath,
|
|
307
|
-
action: WIKI_PAGE_ACTION,
|
|
308
|
-
content: formatToc(toc),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
case "frontmatter": {
|
|
312
|
-
const fm = extractFrontmatterOnly(content);
|
|
313
|
-
return {
|
|
314
|
-
type: "wiki",
|
|
315
|
-
name,
|
|
316
|
-
path: ctx.absPath,
|
|
317
|
-
action: WIKI_PAGE_ACTION,
|
|
318
|
-
content: fm ?? "(no frontmatter)",
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
case "section": {
|
|
322
|
-
const section = extractSection(content, v.heading);
|
|
323
|
-
if (!section) {
|
|
324
|
-
return {
|
|
325
|
-
type: "wiki",
|
|
326
|
-
name,
|
|
327
|
-
path: ctx.absPath,
|
|
328
|
-
action: WIKI_PAGE_ACTION,
|
|
329
|
-
content: `Section "${v.heading}" not found in ${name}. Try \`akm show wiki:${name} toc\` to discover available headings.`,
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
type: "wiki",
|
|
334
|
-
name,
|
|
335
|
-
path: ctx.absPath,
|
|
336
|
-
action: WIKI_PAGE_ACTION,
|
|
337
|
-
content: section.content,
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
case "lines": {
|
|
341
|
-
return {
|
|
342
|
-
type: "wiki",
|
|
343
|
-
name,
|
|
344
|
-
path: ctx.absPath,
|
|
345
|
-
action: WIKI_PAGE_ACTION,
|
|
346
|
-
content: extractLineRange(content, v.start, v.end),
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
default: {
|
|
350
|
-
return {
|
|
351
|
-
type: "wiki",
|
|
352
|
-
name,
|
|
353
|
-
path: ctx.absPath,
|
|
354
|
-
action: WIKI_PAGE_ACTION,
|
|
355
|
-
content,
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
extractMetadata(entry, ctx) {
|
|
361
|
-
try {
|
|
362
|
-
const toc = parseMarkdownToc(ctx.content());
|
|
363
|
-
if (toc.headings.length > 0)
|
|
364
|
-
entry.toc = toc.headings;
|
|
365
|
-
}
|
|
366
|
-
catch {
|
|
367
|
-
// Non-fatal: skip TOC if file can't be read
|
|
368
|
-
}
|
|
268
|
+
return buildMarkdownViewResponse(ctx, "wiki", WIKI_PAGE_ACTION);
|
|
369
269
|
},
|
|
370
270
|
};
|
|
371
271
|
// ── 4c. lesson-md ────────────────────────────────────────────────────────────
|
|
@@ -384,8 +284,8 @@ const lessonMdRenderer = {
|
|
|
384
284
|
buildShowResponse(ctx) {
|
|
385
285
|
const name = deriveName(ctx);
|
|
386
286
|
const parsed = parseFrontmatter(ctx.content());
|
|
387
|
-
const description =
|
|
388
|
-
const whenToUse =
|
|
287
|
+
const description = asNonEmptyString(parsed.data.description);
|
|
288
|
+
const whenToUse = asNonEmptyString(parsed.data.when_to_use);
|
|
389
289
|
const action = whenToUse
|
|
390
290
|
? `Apply this lesson when: ${whenToUse}`
|
|
391
291
|
: "Apply this lesson when its `when_to_use` trigger matches the current task.";
|
|
@@ -398,33 +298,6 @@ const lessonMdRenderer = {
|
|
|
398
298
|
content: parsed.content,
|
|
399
299
|
};
|
|
400
300
|
},
|
|
401
|
-
extractMetadata(entry, ctx) {
|
|
402
|
-
try {
|
|
403
|
-
const parsed = parseFrontmatter(ctx.content());
|
|
404
|
-
const fm = parsed.data;
|
|
405
|
-
const desc = toStringOrUndefined(fm.description);
|
|
406
|
-
if (desc && !entry.description) {
|
|
407
|
-
entry.description = desc;
|
|
408
|
-
entry.source = "frontmatter";
|
|
409
|
-
entry.confidence = 0.9;
|
|
410
|
-
}
|
|
411
|
-
const whenToUse = toStringOrUndefined(fm.when_to_use);
|
|
412
|
-
if (whenToUse) {
|
|
413
|
-
const hints = new Set(entry.searchHints ?? []);
|
|
414
|
-
hints.add(`when_to_use:${whenToUse}`);
|
|
415
|
-
entry.searchHints = Array.from(hints).filter(Boolean);
|
|
416
|
-
}
|
|
417
|
-
if (Array.isArray(fm.tags) && fm.tags.length > 0) {
|
|
418
|
-
const fmTags = fm.tags.filter((t) => typeof t === "string" && t.trim().length > 0);
|
|
419
|
-
if (fmTags.length > 0) {
|
|
420
|
-
entry.tags = Array.from(new Set([...(entry.tags ?? []), ...fmTags]));
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
catch {
|
|
425
|
-
// Non-fatal: skip metadata extraction on parse error
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
301
|
};
|
|
429
302
|
// ── 5. memory-md ─────────────────────────────────────────────────────────────
|
|
430
303
|
const memoryMdRenderer = {
|
|
@@ -439,58 +312,6 @@ const memoryMdRenderer = {
|
|
|
439
312
|
content: ctx.content(),
|
|
440
313
|
};
|
|
441
314
|
},
|
|
442
|
-
extractMetadata(entry, ctx) {
|
|
443
|
-
try {
|
|
444
|
-
const parsed = parseFrontmatter(ctx.content());
|
|
445
|
-
const fm = parsed.data;
|
|
446
|
-
// Description from frontmatter
|
|
447
|
-
const desc = toStringOrUndefined(fm.description);
|
|
448
|
-
if (desc && !entry.description) {
|
|
449
|
-
entry.description = desc;
|
|
450
|
-
entry.source = "frontmatter";
|
|
451
|
-
entry.confidence = 0.9;
|
|
452
|
-
}
|
|
453
|
-
// Tags from frontmatter
|
|
454
|
-
if (Array.isArray(fm.tags) && fm.tags.length > 0) {
|
|
455
|
-
const fmTags = fm.tags.filter((t) => typeof t === "string" && t.trim().length > 0);
|
|
456
|
-
if (fmTags.length > 0) {
|
|
457
|
-
entry.tags = Array.from(new Set([...(entry.tags ?? []), ...fmTags]));
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
// Build searchHints from structured memory metadata fields
|
|
461
|
-
const hints = new Set(entry.searchHints ?? []);
|
|
462
|
-
const source = toStringOrUndefined(fm.source);
|
|
463
|
-
if (source)
|
|
464
|
-
hints.add(source);
|
|
465
|
-
// observed_at: prefer frontmatter value, fall back to file mtime
|
|
466
|
-
const fmObservedAt = toStringOrUndefined(fm.observed_at);
|
|
467
|
-
if (fmObservedAt) {
|
|
468
|
-
hints.add(`observed_at:${fmObservedAt}`);
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
// mtime fallback: format as ISO date (YYYY-MM-DD)
|
|
472
|
-
try {
|
|
473
|
-
const mtime = ctx.stat().mtime;
|
|
474
|
-
const isoDate = mtime.toISOString().slice(0, 10);
|
|
475
|
-
hints.add(`observed_at:${isoDate}`);
|
|
476
|
-
}
|
|
477
|
-
catch {
|
|
478
|
-
// Non-fatal: skip mtime fallback on stat error
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
const expires = toStringOrUndefined(fm.expires);
|
|
482
|
-
if (expires)
|
|
483
|
-
hints.add(`expires:${expires}`);
|
|
484
|
-
if (fm.subjective === true)
|
|
485
|
-
hints.add("subjective");
|
|
486
|
-
if (hints.size > 0) {
|
|
487
|
-
entry.searchHints = Array.from(hints).filter(Boolean);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
catch {
|
|
491
|
-
// Non-fatal: skip metadata extraction on error
|
|
492
|
-
}
|
|
493
|
-
},
|
|
494
315
|
};
|
|
495
316
|
// ── 6. workflow-md ───────────────────────────────────────────────────────────
|
|
496
317
|
// Defined in src/workflows/renderer.ts and imported above.
|
|
@@ -537,16 +358,6 @@ const scriptSourceRenderer = {
|
|
|
537
358
|
throw error;
|
|
538
359
|
}
|
|
539
360
|
},
|
|
540
|
-
extractMetadata(entry, ctx) {
|
|
541
|
-
if (ctx.ext !== ".md") {
|
|
542
|
-
const commentDesc = extractDescriptionFromComments(ctx.absPath);
|
|
543
|
-
if (commentDesc && !entry.description) {
|
|
544
|
-
entry.description = commentDesc;
|
|
545
|
-
entry.source = "comments";
|
|
546
|
-
entry.confidence = 0.7;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
361
|
};
|
|
551
362
|
// ── 8. vault-env ─────────────────────────────────────────────────────────────
|
|
552
363
|
/**
|
|
@@ -574,22 +385,174 @@ const vaultEnvRenderer = {
|
|
|
574
385
|
if (keys.length > 0)
|
|
575
386
|
hit.keys = keys;
|
|
576
387
|
},
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
388
|
+
};
|
|
389
|
+
// ── 7. task-md ───────────────────────────────────────────────────────────────
|
|
390
|
+
const TASK_PAGE_ACTION = "Scheduled task — `akm tasks show <id>` for parsed details, `akm tasks run <id>` to invoke now.";
|
|
391
|
+
const taskMdRenderer = {
|
|
392
|
+
name: "task-md",
|
|
393
|
+
buildShowResponse(ctx) {
|
|
394
|
+
const name = deriveName(ctx);
|
|
395
|
+
return {
|
|
396
|
+
type: "task",
|
|
397
|
+
name,
|
|
398
|
+
path: ctx.absPath,
|
|
399
|
+
action: TASK_PAGE_ACTION,
|
|
400
|
+
content: ctx.content(),
|
|
401
|
+
};
|
|
591
402
|
},
|
|
592
403
|
};
|
|
404
|
+
function applyTocMetadata(entry, ctx) {
|
|
405
|
+
try {
|
|
406
|
+
const toc = parseMarkdownToc(ctx.content());
|
|
407
|
+
if (toc.headings.length > 0)
|
|
408
|
+
entry.toc = toc.headings;
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
// Non-fatal: skip TOC if file can't be read
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Parse frontmatter, apply description (if not already set) and merge tags
|
|
416
|
+
* into `entry`. Returns the raw frontmatter data object so callers can access
|
|
417
|
+
* type-specific fields without re-parsing.
|
|
418
|
+
*/
|
|
419
|
+
function applyFrontmatterDescriptionAndTags(entry, ctx) {
|
|
420
|
+
const parsed = parseFrontmatter(ctx.content());
|
|
421
|
+
const fm = parsed.data;
|
|
422
|
+
const desc = asNonEmptyString(fm.description);
|
|
423
|
+
if (desc && !entry.description) {
|
|
424
|
+
entry.description = desc;
|
|
425
|
+
entry.source = "frontmatter";
|
|
426
|
+
entry.confidence = 0.9;
|
|
427
|
+
}
|
|
428
|
+
if (Array.isArray(fm.tags) && fm.tags.length > 0) {
|
|
429
|
+
const fmTags = fm.tags.filter((t) => typeof t === "string" && t.trim().length > 0);
|
|
430
|
+
if (fmTags.length > 0) {
|
|
431
|
+
entry.tags = Array.from(new Set([...(entry.tags ?? []), ...fmTags]));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return fm;
|
|
435
|
+
}
|
|
436
|
+
function applyLessonMetadata(entry, ctx) {
|
|
437
|
+
try {
|
|
438
|
+
const fm = applyFrontmatterDescriptionAndTags(entry, ctx);
|
|
439
|
+
const whenToUse = asNonEmptyString(fm.when_to_use);
|
|
440
|
+
if (whenToUse) {
|
|
441
|
+
const hints = new Set(entry.searchHints ?? []);
|
|
442
|
+
hints.add(`when_to_use:${whenToUse}`);
|
|
443
|
+
entry.searchHints = Array.from(hints).filter(Boolean);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
// Non-fatal: skip metadata extraction on parse error
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function applyMemoryMetadata(entry, ctx) {
|
|
451
|
+
try {
|
|
452
|
+
const fm = applyFrontmatterDescriptionAndTags(entry, ctx);
|
|
453
|
+
const hints = new Set(entry.searchHints ?? []);
|
|
454
|
+
const source = asNonEmptyString(fm.source);
|
|
455
|
+
if (source)
|
|
456
|
+
hints.add(source);
|
|
457
|
+
const fmObservedAt = asNonEmptyString(fm.observed_at);
|
|
458
|
+
if (fmObservedAt) {
|
|
459
|
+
hints.add(`observed_at:${fmObservedAt}`);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
try {
|
|
463
|
+
const isoDate = ctx.stat().mtime.toISOString().slice(0, 10);
|
|
464
|
+
hints.add(`observed_at:${isoDate}`);
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
// Non-fatal: skip mtime fallback on stat error
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const expires = asNonEmptyString(fm.expires);
|
|
471
|
+
if (expires)
|
|
472
|
+
hints.add(`expires:${expires}`);
|
|
473
|
+
if (fm.subjective === true)
|
|
474
|
+
hints.add("subjective");
|
|
475
|
+
if (hints.size > 0) {
|
|
476
|
+
entry.searchHints = Array.from(hints).filter(Boolean);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
// Non-fatal: skip metadata extraction on error
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function applyScriptMetadata(entry, ctx) {
|
|
484
|
+
if (ctx.ext === ".md")
|
|
485
|
+
return;
|
|
486
|
+
const commentDesc = extractDescriptionFromComments(ctx.absPath);
|
|
487
|
+
if (commentDesc && !entry.description) {
|
|
488
|
+
entry.description = commentDesc;
|
|
489
|
+
entry.source = "comments";
|
|
490
|
+
entry.confidence = 0.7;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
function applyVaultMetadata(entry, ctx) {
|
|
494
|
+
const { keys, comments } = listVaultKeys(ctx.absPath);
|
|
495
|
+
if (comments.length > 0 && !entry.description) {
|
|
496
|
+
entry.description = comments.join(" ").slice(0, 500);
|
|
497
|
+
entry.source = "comments";
|
|
498
|
+
entry.confidence = 0.7;
|
|
499
|
+
}
|
|
500
|
+
if (keys.length > 0) {
|
|
501
|
+
entry.searchHints = keys;
|
|
502
|
+
}
|
|
503
|
+
entry.tags = Array.from(new Set([...(entry.tags ?? []), "vault", "secrets"]));
|
|
504
|
+
}
|
|
505
|
+
function applyTaskMetadata(entry, ctx) {
|
|
506
|
+
try {
|
|
507
|
+
const fm = applyFrontmatterDescriptionAndTags(entry, ctx);
|
|
508
|
+
entry.tags = Array.from(new Set([...(entry.tags ?? []), "task", "scheduled"]));
|
|
509
|
+
const hints = new Set(entry.searchHints ?? []);
|
|
510
|
+
const schedule = asNonEmptyString(fm.schedule);
|
|
511
|
+
if (schedule)
|
|
512
|
+
hints.add(`schedule:${schedule}`);
|
|
513
|
+
const workflow = asNonEmptyString(fm.workflow);
|
|
514
|
+
if (workflow)
|
|
515
|
+
hints.add(`workflow:${workflow}`);
|
|
516
|
+
const prompt = asNonEmptyString(fm.prompt);
|
|
517
|
+
if (prompt)
|
|
518
|
+
hints.add(`prompt:${prompt}`);
|
|
519
|
+
if (hints.size > 0)
|
|
520
|
+
entry.searchHints = Array.from(hints).filter(Boolean);
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
// Non-fatal: skip metadata extraction on error
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
registerMetadataContributor({
|
|
527
|
+
name: "toc-metadata",
|
|
528
|
+
appliesTo: ({ rendererName }) => rendererName === "knowledge-md" || rendererName === "wiki-md",
|
|
529
|
+
contribute: (entry, ctx) => applyTocMetadata(entry, ctx.renderContext),
|
|
530
|
+
});
|
|
531
|
+
registerMetadataContributor({
|
|
532
|
+
name: "lesson-frontmatter-metadata",
|
|
533
|
+
appliesTo: ({ rendererName }) => rendererName === "lesson-md",
|
|
534
|
+
contribute: (entry, ctx) => applyLessonMetadata(entry, ctx.renderContext),
|
|
535
|
+
});
|
|
536
|
+
registerMetadataContributor({
|
|
537
|
+
name: "memory-frontmatter-metadata",
|
|
538
|
+
appliesTo: ({ rendererName }) => rendererName === "memory-md",
|
|
539
|
+
contribute: (entry, ctx) => applyMemoryMetadata(entry, ctx.renderContext),
|
|
540
|
+
});
|
|
541
|
+
registerMetadataContributor({
|
|
542
|
+
name: "script-comment-metadata",
|
|
543
|
+
appliesTo: ({ rendererName }) => rendererName === "script-source",
|
|
544
|
+
contribute: (entry, ctx) => applyScriptMetadata(entry, ctx.renderContext),
|
|
545
|
+
});
|
|
546
|
+
registerMetadataContributor({
|
|
547
|
+
name: "vault-secret-metadata",
|
|
548
|
+
appliesTo: ({ rendererName }) => rendererName === "vault-env",
|
|
549
|
+
contribute: (entry, ctx) => applyVaultMetadata(entry, ctx.renderContext),
|
|
550
|
+
});
|
|
551
|
+
registerMetadataContributor({
|
|
552
|
+
name: "task-frontmatter-metadata",
|
|
553
|
+
appliesTo: ({ rendererName }) => rendererName === "task-md",
|
|
554
|
+
contribute: (entry, ctx) => applyTaskMetadata(entry, ctx.renderContext),
|
|
555
|
+
});
|
|
593
556
|
// ── Registration ─────────────────────────────────────────────────────────────
|
|
594
557
|
/** All built-in renderers. */
|
|
595
558
|
const builtinRenderers = [
|
|
@@ -603,6 +566,7 @@ const builtinRenderers = [
|
|
|
603
566
|
workflowMdRenderer,
|
|
604
567
|
scriptSourceRenderer,
|
|
605
568
|
vaultEnvRenderer,
|
|
569
|
+
taskMdRenderer,
|
|
606
570
|
];
|
|
607
571
|
/**
|
|
608
572
|
* Register all built-in renderers with the file-context registry.
|