akm-cli 0.1.3 → 0.2.1
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/dist/asset-registry.js +48 -0
- package/dist/asset-spec.js +11 -32
- package/dist/cli.js +173 -59
- package/dist/common.js +3 -0
- package/dist/completions.js +4 -2
- package/dist/config.js +35 -7
- package/dist/db.js +182 -22
- package/dist/embedder.js +140 -23
- package/dist/file-context.js +3 -0
- package/dist/indexer.js +198 -42
- package/dist/info.js +92 -0
- package/dist/local-search.js +190 -90
- package/dist/manifest.js +172 -0
- package/dist/metadata.js +165 -2
- package/dist/providers/skills-sh.js +21 -12
- package/dist/providers/static-index.js +3 -1
- package/dist/registry-build-index.js +12 -1
- package/dist/registry-resolve.js +10 -7
- package/dist/renderers.js +1 -1
- package/dist/search-fields.js +69 -0
- package/dist/search-source.js +42 -0
- package/dist/setup.js +151 -7
- package/dist/stash-clone.js +3 -1
- package/dist/stash-provider-factory.js +0 -2
- package/dist/stash-providers/filesystem.js +4 -5
- package/dist/stash-providers/git.js +140 -0
- package/dist/stash-providers/index.js +1 -1
- package/dist/stash-providers/openviking.js +36 -25
- package/dist/stash-providers/provider-utils.js +11 -0
- package/dist/stash-search.js +106 -90
- package/dist/stash-show.js +125 -9
- package/dist/usage-events.js +73 -0
- package/dist/version.js +20 -0
- package/dist/walker.js +1 -2
- package/package.json +4 -3
- package/dist/stash-providers/context-hub.js +0 -390
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central registry for asset type renderer and action builder maps.
|
|
3
|
+
*
|
|
4
|
+
* Previously these maps lived in `local-search.ts` and were wired into
|
|
5
|
+
* `asset-spec.ts` via a fragile `_setAssetTypeHooks` deferred callback
|
|
6
|
+
* pattern. If `local-search.ts` was imported after `registerAssetType()`
|
|
7
|
+
* calls, hooks would be silently dropped.
|
|
8
|
+
*
|
|
9
|
+
* This module is a simple singleton that both `asset-spec.ts` and
|
|
10
|
+
* `local-search.ts` import from, eliminating the import-order dependency
|
|
11
|
+
* entirely.
|
|
12
|
+
*/
|
|
13
|
+
/** Map asset types to their primary renderer names. */
|
|
14
|
+
export const TYPE_TO_RENDERER = {
|
|
15
|
+
script: "script-source",
|
|
16
|
+
skill: "skill-md",
|
|
17
|
+
command: "command-md",
|
|
18
|
+
agent: "agent-md",
|
|
19
|
+
knowledge: "knowledge-md",
|
|
20
|
+
memory: "memory-md",
|
|
21
|
+
};
|
|
22
|
+
/** Map asset types to action builder functions for search results. */
|
|
23
|
+
export const ACTION_BUILDERS = {
|
|
24
|
+
script: (ref) => `akm show ${ref} -> execute the run command`,
|
|
25
|
+
skill: (ref) => `akm show ${ref} -> follow the instructions`,
|
|
26
|
+
command: (ref) => `akm show ${ref} -> fill placeholders and dispatch`,
|
|
27
|
+
agent: (ref) => `akm show ${ref} -> dispatch with full prompt`,
|
|
28
|
+
knowledge: (ref) => `akm show ${ref} -> read reference material`,
|
|
29
|
+
memory: (ref) => `akm show ${ref} -> recall context`,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Register a type-to-renderer mapping.
|
|
33
|
+
*
|
|
34
|
+
* Called by `registerAssetType()` in `asset-spec.ts` when a spec includes
|
|
35
|
+
* `rendererName`, or directly by extension code.
|
|
36
|
+
*/
|
|
37
|
+
export function registerTypeRenderer(type, rendererName) {
|
|
38
|
+
TYPE_TO_RENDERER[type] = rendererName;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Register an action builder for an asset type.
|
|
42
|
+
*
|
|
43
|
+
* Called by `registerAssetType()` in `asset-spec.ts` when a spec includes
|
|
44
|
+
* `actionBuilder`, or directly by extension code.
|
|
45
|
+
*/
|
|
46
|
+
export function registerActionBuilder(type, builder) {
|
|
47
|
+
ACTION_BUILDERS[type] = builder;
|
|
48
|
+
}
|
package/dist/asset-spec.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { registerActionBuilder, registerTypeRenderer } from "./asset-registry";
|
|
2
3
|
import { toPosix } from "./common";
|
|
3
4
|
const markdownSpec = {
|
|
4
5
|
isRelevantFile: (fileName) => path.extname(fileName).toLowerCase() === ".md",
|
|
@@ -56,28 +57,6 @@ const ASSET_SPECS_INTERNAL = {
|
|
|
56
57
|
memory: { stashDir: "memories", ...markdownSpec },
|
|
57
58
|
};
|
|
58
59
|
export const ASSET_SPECS = ASSET_SPECS_INTERNAL;
|
|
59
|
-
/**
|
|
60
|
-
* Deferred hooks set by `local-search.ts` at module init time to avoid a
|
|
61
|
-
* circular dependency (asset-spec → local-search → asset-spec).
|
|
62
|
-
*
|
|
63
|
-
* When `registerAssetType` is called with a spec that includes `rendererName`
|
|
64
|
-
* or `actionBuilder`, these hooks are invoked automatically so callers only
|
|
65
|
-
* need a single `registerAssetType(type, spec)` call to fully register a new
|
|
66
|
-
* asset type — no separate `registerTypeRenderer`/`registerActionBuilder` calls
|
|
67
|
-
* are required.
|
|
68
|
-
*/
|
|
69
|
-
let _registerTypeRenderer;
|
|
70
|
-
let _registerActionBuilder;
|
|
71
|
-
/**
|
|
72
|
-
* Called once by `local-search.ts` during module initialization to wire in the
|
|
73
|
-
* renderer and action-builder registration hooks.
|
|
74
|
-
*
|
|
75
|
-
* @internal — not part of the public extension API; use `registerAssetType` instead.
|
|
76
|
-
*/
|
|
77
|
-
export function _setAssetTypeHooks(rendererHook, actionBuilderHook) {
|
|
78
|
-
_registerTypeRenderer = rendererHook;
|
|
79
|
-
_registerActionBuilder = actionBuilderHook;
|
|
80
|
-
}
|
|
81
60
|
/**
|
|
82
61
|
* Register a custom asset type with the akm asset system.
|
|
83
62
|
*
|
|
@@ -109,27 +88,27 @@ export function _setAssetTypeHooks(rendererHook, actionBuilderHook) {
|
|
|
109
88
|
* });
|
|
110
89
|
* ```
|
|
111
90
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* stored in the spec and will take effect once the hooks are set.
|
|
91
|
+
* Renderer and action builder registration is handled directly via the
|
|
92
|
+
* `asset-registry` singleton — no deferred hooks or import-order concerns.
|
|
115
93
|
*/
|
|
116
94
|
export function registerAssetType(type, spec) {
|
|
117
95
|
ASSET_SPECS_INTERNAL[type] = spec;
|
|
118
96
|
TYPE_DIRS[type] = spec.stashDir;
|
|
119
|
-
ASSET_TYPES =
|
|
97
|
+
ASSET_TYPES.length = 0;
|
|
98
|
+
ASSET_TYPES.push(...getAssetTypes());
|
|
120
99
|
// Auto-register renderer and action builder if provided in spec
|
|
121
|
-
if (spec.rendererName
|
|
122
|
-
|
|
100
|
+
if (spec.rendererName) {
|
|
101
|
+
registerTypeRenderer(type, spec.rendererName);
|
|
123
102
|
}
|
|
124
|
-
if (spec.actionBuilder
|
|
125
|
-
|
|
103
|
+
if (spec.actionBuilder) {
|
|
104
|
+
registerActionBuilder(type, spec.actionBuilder);
|
|
126
105
|
}
|
|
127
106
|
}
|
|
128
107
|
export function getAssetTypes() {
|
|
129
108
|
return Object.keys(ASSET_SPECS_INTERNAL);
|
|
130
109
|
}
|
|
131
|
-
/** Warning: mutable
|
|
132
|
-
export
|
|
110
|
+
/** Warning: mutable array — stale if captured before `registerAssetType()` calls. Prefer `getAssetTypes()`. */
|
|
111
|
+
export const ASSET_TYPES = getAssetTypes();
|
|
133
112
|
export const TYPE_DIRS = Object.fromEntries(Object.entries(ASSET_SPECS_INTERNAL).map(([type, spec]) => [type, spec.stashDir]));
|
|
134
113
|
export function isRelevantAssetFile(assetType, fileName) {
|
|
135
114
|
return ASSET_SPECS[assetType]?.isRelevantFile(fileName) ?? false;
|
package/dist/cli.js
CHANGED
|
@@ -6,8 +6,10 @@ import { resolveStashDir } from "./common";
|
|
|
6
6
|
import { generateBashCompletions, installBashCompletions } from "./completions";
|
|
7
7
|
import { DEFAULT_CONFIG, getConfigPath, loadConfig, saveConfig } from "./config";
|
|
8
8
|
import { getConfigValue, listConfig, setConfigValue, unsetConfigValue } from "./config-cli";
|
|
9
|
+
import { closeDatabase, openDatabase } from "./db";
|
|
9
10
|
import { ConfigError, NotFoundError, UsageError } from "./errors";
|
|
10
11
|
import { akmIndex } from "./indexer";
|
|
12
|
+
import { assembleInfo } from "./info";
|
|
11
13
|
import { akmInit } from "./init";
|
|
12
14
|
import { akmList, akmRemove, akmUpdate } from "./installed-kits";
|
|
13
15
|
import { getCacheDir, getDbPath, getDefaultStashDir } from "./paths";
|
|
@@ -19,42 +21,15 @@ import { akmClone } from "./stash-clone";
|
|
|
19
21
|
import { akmSearch, parseSearchSource } from "./stash-search";
|
|
20
22
|
import { akmShowUnified } from "./stash-show";
|
|
21
23
|
import { addStash, listStashes, removeStash } from "./stash-source-manage";
|
|
24
|
+
import { insertUsageEvent } from "./usage-events";
|
|
25
|
+
import { pkgVersion } from "./version";
|
|
22
26
|
import { setQuiet, warn } from "./warn";
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
// Injected at compile time via `bun build --define`
|
|
26
|
-
if (typeof AKM_VERSION !== "undefined")
|
|
27
|
-
return AKM_VERSION;
|
|
28
|
-
try {
|
|
29
|
-
const pkgPath = path.resolve(import.meta.dir ?? __dirname, "../package.json");
|
|
30
|
-
if (fs.existsSync(pkgPath)) {
|
|
31
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
32
|
-
if (typeof pkg.version === "string")
|
|
33
|
-
return pkg.version;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
// swallow — running as compiled binary without package.json
|
|
38
|
-
}
|
|
39
|
-
return "0.0.0-dev";
|
|
40
|
-
})();
|
|
41
|
-
const OUTPUT_FORMATS = ["json", "yaml", "text"];
|
|
42
|
-
const DETAIL_LEVELS = ["brief", "normal", "full"];
|
|
27
|
+
const OUTPUT_FORMATS = ["json", "yaml", "text", "jsonl"];
|
|
28
|
+
const DETAIL_LEVELS = ["brief", "normal", "full", "summary"];
|
|
43
29
|
const NORMAL_DESCRIPTION_LIMIT = 250;
|
|
44
30
|
const CONTEXT_HUB_ALIAS_REF = "context-hub";
|
|
45
31
|
const CONTEXT_HUB_ALIAS_URL = "https://github.com/andrewyng/context-hub";
|
|
46
|
-
|
|
47
|
-
// biome-ignore lint/suspicious/noExplicitAny: type guard for runtime feature detection
|
|
48
|
-
return typeof b.YAML?.stringify === "function";
|
|
49
|
-
}
|
|
50
|
-
/** Try Bun.YAML.stringify; fall back to JSON if the API is unavailable */
|
|
51
|
-
function yamlStringify(obj) {
|
|
52
|
-
if (hasBunYAML(Bun)) {
|
|
53
|
-
return Bun.YAML.stringify(obj);
|
|
54
|
-
}
|
|
55
|
-
warn("YAML output not available, using JSON");
|
|
56
|
-
return JSON.stringify(obj, null, 2);
|
|
57
|
-
}
|
|
32
|
+
import { stringify as yamlStringify } from "yaml";
|
|
58
33
|
function parseOutputFormat(value) {
|
|
59
34
|
if (!value)
|
|
60
35
|
return undefined;
|
|
@@ -79,15 +54,25 @@ function parseFlagValue(flag) {
|
|
|
79
54
|
}
|
|
80
55
|
return undefined;
|
|
81
56
|
}
|
|
57
|
+
// Uses process.argv directly because the global output() function (called by all
|
|
58
|
+
// commands) needs this flag but doesn't have access to citty's parsed args.
|
|
59
|
+
function hasBooleanFlag(flag) {
|
|
60
|
+
return process.argv.some((arg) => arg === flag || arg === `${flag}=true`);
|
|
61
|
+
}
|
|
82
62
|
function resolveOutputMode() {
|
|
83
63
|
const config = loadConfig();
|
|
84
64
|
const format = parseOutputFormat(parseFlagValue("--format")) ?? config.output?.format ?? "json";
|
|
85
65
|
const detail = parseDetailLevel(parseFlagValue("--detail")) ?? config.output?.detail ?? "brief";
|
|
86
|
-
|
|
66
|
+
const forAgent = hasBooleanFlag("--for-agent");
|
|
67
|
+
return { format, detail, forAgent };
|
|
87
68
|
}
|
|
88
69
|
function output(command, result) {
|
|
89
70
|
const mode = resolveOutputMode();
|
|
90
|
-
const shaped = shapeForCommand(command, result, mode.detail);
|
|
71
|
+
const shaped = shapeForCommand(command, result, mode.detail, mode.forAgent);
|
|
72
|
+
if (mode.format === "jsonl") {
|
|
73
|
+
outputJsonl(command, shaped);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
91
76
|
switch (mode.format) {
|
|
92
77
|
case "json":
|
|
93
78
|
console.log(JSON.stringify(shaped, null, 2));
|
|
@@ -102,27 +87,57 @@ function output(command, result) {
|
|
|
102
87
|
}
|
|
103
88
|
}
|
|
104
89
|
}
|
|
105
|
-
function
|
|
90
|
+
function outputJsonl(command, shaped) {
|
|
91
|
+
if (command === "search" || command === "registry-search") {
|
|
92
|
+
const r = shaped;
|
|
93
|
+
const hits = Array.isArray(r.hits) ? r.hits : [];
|
|
94
|
+
for (const hit of hits) {
|
|
95
|
+
console.log(JSON.stringify(hit));
|
|
96
|
+
}
|
|
97
|
+
const registryHits = Array.isArray(r.registryHits) ? r.registryHits : [];
|
|
98
|
+
for (const hit of registryHits) {
|
|
99
|
+
console.log(JSON.stringify(hit));
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// For non-search commands, output the whole object as a single JSONL line
|
|
104
|
+
console.log(JSON.stringify(shaped));
|
|
105
|
+
}
|
|
106
|
+
function shapeForCommand(command, result, detail, forAgent = false) {
|
|
106
107
|
switch (command) {
|
|
107
108
|
case "search":
|
|
108
|
-
return shapeSearchOutput(result, detail);
|
|
109
|
+
return shapeSearchOutput(result, detail, forAgent);
|
|
109
110
|
case "registry-search":
|
|
110
111
|
return shapeRegistrySearchOutput(result, detail);
|
|
111
112
|
case "show":
|
|
112
|
-
return shapeShowOutput(result, detail);
|
|
113
|
+
return shapeShowOutput(result, detail, forAgent);
|
|
113
114
|
default:
|
|
114
115
|
return result;
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
|
-
function shapeSearchOutput(result, detail) {
|
|
118
|
+
function shapeSearchOutput(result, detail, forAgent = false) {
|
|
118
119
|
const hits = Array.isArray(result.hits) ? result.hits : [];
|
|
119
|
-
const
|
|
120
|
+
const registryHits = Array.isArray(result.registryHits) ? result.registryHits : [];
|
|
121
|
+
const shapedHits = forAgent
|
|
122
|
+
? hits.map((hit) => shapeSearchHitForAgent(hit))
|
|
123
|
+
: hits.map((hit) => shapeSearchHit(hit, detail));
|
|
124
|
+
const shapedRegistryHits = forAgent
|
|
125
|
+
? registryHits.map((hit) => shapeSearchHitForAgent(hit))
|
|
126
|
+
: registryHits.map((hit) => shapeSearchHit(hit, detail));
|
|
127
|
+
if (forAgent) {
|
|
128
|
+
return {
|
|
129
|
+
hits: shapedHits,
|
|
130
|
+
...(shapedRegistryHits.length > 0 ? { registryHits: shapedRegistryHits } : {}),
|
|
131
|
+
...(result.tip ? { tip: result.tip } : {}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
120
134
|
if (detail === "full") {
|
|
121
135
|
return {
|
|
122
136
|
schemaVersion: result.schemaVersion,
|
|
123
137
|
stashDir: result.stashDir,
|
|
124
138
|
source: result.source,
|
|
125
139
|
hits: shapedHits,
|
|
140
|
+
...(shapedRegistryHits.length > 0 ? { registryHits: shapedRegistryHits } : {}),
|
|
126
141
|
...(result.tip ? { tip: result.tip } : {}),
|
|
127
142
|
...(result.warnings ? { warnings: result.warnings } : {}),
|
|
128
143
|
...(result.timing ? { timing: result.timing } : {}),
|
|
@@ -130,6 +145,7 @@ function shapeSearchOutput(result, detail) {
|
|
|
130
145
|
}
|
|
131
146
|
return {
|
|
132
147
|
hits: shapedHits,
|
|
148
|
+
...(shapedRegistryHits.length > 0 ? { registryHits: shapedRegistryHits } : {}),
|
|
133
149
|
...(result.tip ? { tip: result.tip } : {}),
|
|
134
150
|
...(Array.isArray(result.warnings) && result.warnings.length > 0 ? { warnings: result.warnings } : {}),
|
|
135
151
|
};
|
|
@@ -153,9 +169,9 @@ function shapeRegistrySearchOutput(result, detail) {
|
|
|
153
169
|
}
|
|
154
170
|
function shapeAssetHit(hit, detail) {
|
|
155
171
|
if (detail === "brief")
|
|
156
|
-
return pickFields(hit, ["assetName", "assetType", "action"]);
|
|
172
|
+
return pickFields(hit, ["assetName", "assetType", "action", "estimatedTokens"]);
|
|
157
173
|
if (detail === "normal") {
|
|
158
|
-
return capDescription(pickFields(hit, ["assetName", "assetType", "description", "kit", "action"]), NORMAL_DESCRIPTION_LIMIT);
|
|
174
|
+
return capDescription(pickFields(hit, ["assetName", "assetType", "description", "kit", "action", "estimatedTokens"]), NORMAL_DESCRIPTION_LIMIT);
|
|
159
175
|
}
|
|
160
176
|
return hit;
|
|
161
177
|
}
|
|
@@ -170,12 +186,17 @@ function shapeSearchHit(hit, detail) {
|
|
|
170
186
|
}
|
|
171
187
|
// Stash hit (local or remote)
|
|
172
188
|
if (detail === "brief")
|
|
173
|
-
return pickFields(hit, ["type", "name", "action"]);
|
|
189
|
+
return pickFields(hit, ["type", "name", "action", "estimatedTokens"]);
|
|
174
190
|
if (detail === "normal") {
|
|
175
|
-
return capDescription(pickFields(hit, ["type", "name", "description", "action", "score"]), NORMAL_DESCRIPTION_LIMIT);
|
|
191
|
+
return capDescription(pickFields(hit, ["type", "name", "description", "action", "score", "estimatedTokens"]), NORMAL_DESCRIPTION_LIMIT);
|
|
176
192
|
}
|
|
177
193
|
return hit;
|
|
178
194
|
}
|
|
195
|
+
/** Agent-optimized search hit: only fields an LLM agent needs to decide and act */
|
|
196
|
+
function shapeSearchHitForAgent(hit) {
|
|
197
|
+
const picked = pickFields(hit, ["name", "ref", "type", "description", "action", "score", "estimatedTokens"]);
|
|
198
|
+
return capDescription(picked, NORMAL_DESCRIPTION_LIMIT);
|
|
199
|
+
}
|
|
179
200
|
function capDescription(hit, limit) {
|
|
180
201
|
if (typeof hit.description !== "string")
|
|
181
202
|
return hit;
|
|
@@ -190,13 +211,35 @@ function truncateDescription(description, limit) {
|
|
|
190
211
|
const safe = lastSpace >= Math.floor(limit * 0.6) ? truncated.slice(0, lastSpace) : truncated;
|
|
191
212
|
return `${safe.trimEnd()}...`;
|
|
192
213
|
}
|
|
193
|
-
function shapeShowOutput(result, detail) {
|
|
214
|
+
function shapeShowOutput(result, detail, forAgent = false) {
|
|
215
|
+
if (forAgent) {
|
|
216
|
+
return pickFields(result, [
|
|
217
|
+
"type",
|
|
218
|
+
"name",
|
|
219
|
+
"description",
|
|
220
|
+
"action",
|
|
221
|
+
"content",
|
|
222
|
+
"template",
|
|
223
|
+
"prompt",
|
|
224
|
+
"run",
|
|
225
|
+
"setup",
|
|
226
|
+
"cwd",
|
|
227
|
+
"toolPolicy",
|
|
228
|
+
"modelHint",
|
|
229
|
+
"agent",
|
|
230
|
+
"parameters",
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
if (detail === "summary") {
|
|
234
|
+
return pickFields(result, ["type", "name", "description", "tags", "parameters", "action", "run", "origin"]);
|
|
235
|
+
}
|
|
194
236
|
const base = pickFields(result, [
|
|
195
237
|
"type",
|
|
196
238
|
"name",
|
|
197
239
|
"origin",
|
|
198
240
|
"action",
|
|
199
241
|
"description",
|
|
242
|
+
"tags",
|
|
200
243
|
"content",
|
|
201
244
|
"template",
|
|
202
245
|
"prompt",
|
|
@@ -240,7 +283,13 @@ function formatPlain(command, result, detail) {
|
|
|
240
283
|
return out;
|
|
241
284
|
}
|
|
242
285
|
case "index": {
|
|
243
|
-
|
|
286
|
+
const indexResult = result;
|
|
287
|
+
let out = `Indexed ${indexResult.totalEntries ?? 0} entries from ${indexResult.directoriesScanned ?? 0} directories (mode: ${indexResult.mode ?? "unknown"})`;
|
|
288
|
+
const verification = indexResult.verification;
|
|
289
|
+
if (verification?.ok === false && verification.message) {
|
|
290
|
+
out += `\nVerification: ${String(verification.message)}`;
|
|
291
|
+
}
|
|
292
|
+
return out;
|
|
244
293
|
}
|
|
245
294
|
case "show": {
|
|
246
295
|
const lines = [];
|
|
@@ -342,11 +391,13 @@ function formatPlain(command, result, detail) {
|
|
|
342
391
|
}
|
|
343
392
|
function formatSearchPlain(r, detail) {
|
|
344
393
|
const hits = r.hits ?? [];
|
|
345
|
-
|
|
394
|
+
const registryHits = r.registryHits ?? [];
|
|
395
|
+
const allHits = [...hits, ...registryHits];
|
|
396
|
+
if (allHits.length === 0) {
|
|
346
397
|
return r.tip ? String(r.tip) : "No results found.";
|
|
347
398
|
}
|
|
348
399
|
const lines = [];
|
|
349
|
-
for (const hit of
|
|
400
|
+
for (const hit of allHits) {
|
|
350
401
|
const type = hit.type ?? "unknown";
|
|
351
402
|
const name = hit.name ?? "unnamed";
|
|
352
403
|
const score = hit.score != null ? ` (score: ${hit.score})` : "";
|
|
@@ -436,14 +487,27 @@ const indexCommand = defineCommand({
|
|
|
436
487
|
meta: { name: "index", description: "Build search index (incremental by default; --full forces full reindex)" },
|
|
437
488
|
args: {
|
|
438
489
|
full: { type: "boolean", description: "Force full reindex", default: false },
|
|
490
|
+
verbose: { type: "boolean", description: "Print indexing summary and phase progress to stderr", default: false },
|
|
439
491
|
},
|
|
440
492
|
async run({ args }) {
|
|
441
493
|
await runWithJsonErrors(async () => {
|
|
442
|
-
const result = await akmIndex({
|
|
494
|
+
const result = await akmIndex({
|
|
495
|
+
full: args.full,
|
|
496
|
+
onProgress: args.verbose ? ({ message }) => console.error(`[index] ${message}`) : undefined,
|
|
497
|
+
});
|
|
443
498
|
output("index", result);
|
|
444
499
|
});
|
|
445
500
|
},
|
|
446
501
|
});
|
|
502
|
+
const infoCommand = defineCommand({
|
|
503
|
+
meta: { name: "info", description: "Show system capabilities, configuration, and index stats as JSON" },
|
|
504
|
+
run() {
|
|
505
|
+
return runWithJsonErrors(() => {
|
|
506
|
+
const result = assembleInfo();
|
|
507
|
+
output("info", result);
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
});
|
|
447
511
|
const searchCommand = defineCommand({
|
|
448
512
|
meta: { name: "search", description: "Search the stash" },
|
|
449
513
|
args: {
|
|
@@ -454,8 +518,8 @@ const searchCommand = defineCommand({
|
|
|
454
518
|
},
|
|
455
519
|
limit: { type: "string", description: "Maximum number of results" },
|
|
456
520
|
source: { type: "string", description: "Search source (stash|registry|both)", default: "stash" },
|
|
457
|
-
format: { type: "string", description: "Output format (json|text|yaml)" },
|
|
458
|
-
detail: { type: "string", description: "Detail level (brief|normal|full)" },
|
|
521
|
+
format: { type: "string", description: "Output format (json|jsonl|text|yaml)" },
|
|
522
|
+
detail: { type: "string", description: "Detail level (brief|normal|full|summary)" },
|
|
459
523
|
},
|
|
460
524
|
async run({ args }) {
|
|
461
525
|
await runWithJsonErrors(async () => {
|
|
@@ -586,8 +650,8 @@ const showCommand = defineCommand({
|
|
|
586
650
|
},
|
|
587
651
|
args: {
|
|
588
652
|
ref: { type: "positional", description: "Asset ref (type:name)", required: true },
|
|
589
|
-
format: { type: "string", description: "Output format (json|text|yaml)" },
|
|
590
|
-
detail: { type: "string", description: "Detail level (brief|normal|full)" },
|
|
653
|
+
format: { type: "string", description: "Output format (json|jsonl|text|yaml)" },
|
|
654
|
+
detail: { type: "string", description: "Detail level (brief|normal|full|summary)" },
|
|
591
655
|
akmView: { type: "string", description: "Internal positional knowledge view mode parser" },
|
|
592
656
|
akmHeading: { type: "string", description: "Internal positional section heading parser" },
|
|
593
657
|
akmStart: { type: "string", description: "Internal positional start-line parser" },
|
|
@@ -617,7 +681,10 @@ const showCommand = defineCommand({
|
|
|
617
681
|
throw new UsageError(`Unknown view mode: ${args.akmView}. Expected one of: full|toc|frontmatter|section|lines`);
|
|
618
682
|
}
|
|
619
683
|
}
|
|
620
|
-
|
|
684
|
+
// Map CLI detail level to ShowDetailLevel for the show function
|
|
685
|
+
const cliDetail = resolveOutputMode().detail;
|
|
686
|
+
const showDetail = cliDetail === "summary" ? "summary" : undefined;
|
|
687
|
+
const result = await akmShowUnified({ ref: args.ref, view, detail: showDetail });
|
|
621
688
|
output("show", result);
|
|
622
689
|
});
|
|
623
690
|
},
|
|
@@ -932,6 +999,47 @@ const stashCommand = defineCommand({
|
|
|
932
999
|
meta: { name: "stash", description: "Manage additional stashes (local directories and remote providers)" },
|
|
933
1000
|
subCommands: buildSourceSubCommands("stash"),
|
|
934
1001
|
});
|
|
1002
|
+
const feedbackCommand = defineCommand({
|
|
1003
|
+
meta: {
|
|
1004
|
+
name: "feedback",
|
|
1005
|
+
description: "Record positive or negative feedback for a stash asset",
|
|
1006
|
+
},
|
|
1007
|
+
args: {
|
|
1008
|
+
ref: { type: "positional", description: "Asset ref (type:name)", required: true },
|
|
1009
|
+
positive: { type: "boolean", description: "Record positive feedback", default: false },
|
|
1010
|
+
negative: { type: "boolean", description: "Record negative feedback", default: false },
|
|
1011
|
+
note: { type: "string", description: "Optional note to attach to the feedback" },
|
|
1012
|
+
},
|
|
1013
|
+
run({ args }) {
|
|
1014
|
+
return runWithJsonErrors(() => {
|
|
1015
|
+
const ref = args.ref.trim();
|
|
1016
|
+
if (!ref) {
|
|
1017
|
+
throw new UsageError("Asset ref is required. Usage: akm feedback <ref> --positive|--negative");
|
|
1018
|
+
}
|
|
1019
|
+
if (args.positive && args.negative) {
|
|
1020
|
+
throw new UsageError("Specify either --positive or --negative, not both.");
|
|
1021
|
+
}
|
|
1022
|
+
if (!args.positive && !args.negative) {
|
|
1023
|
+
throw new UsageError("Specify --positive or --negative.");
|
|
1024
|
+
}
|
|
1025
|
+
const signal = args.positive ? "positive" : "negative";
|
|
1026
|
+
const metadata = args.note ? JSON.stringify({ note: args.note }) : undefined;
|
|
1027
|
+
const db = openDatabase();
|
|
1028
|
+
try {
|
|
1029
|
+
insertUsageEvent(db, {
|
|
1030
|
+
event_type: "feedback",
|
|
1031
|
+
entry_ref: ref,
|
|
1032
|
+
signal,
|
|
1033
|
+
metadata,
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
finally {
|
|
1037
|
+
closeDatabase(db);
|
|
1038
|
+
}
|
|
1039
|
+
output("feedback", { ok: true, ref, signal, note: args.note ?? null });
|
|
1040
|
+
});
|
|
1041
|
+
},
|
|
1042
|
+
});
|
|
935
1043
|
const hintsCommand = defineCommand({
|
|
936
1044
|
meta: {
|
|
937
1045
|
name: "hints",
|
|
@@ -992,6 +1100,7 @@ const main = defineCommand({
|
|
|
992
1100
|
setup: setupCommand,
|
|
993
1101
|
init: initCommand,
|
|
994
1102
|
index: indexCommand,
|
|
1103
|
+
info: infoCommand,
|
|
995
1104
|
add: addCommand,
|
|
996
1105
|
list: listCommand,
|
|
997
1106
|
remove: removeCommand,
|
|
@@ -1004,6 +1113,7 @@ const main = defineCommand({
|
|
|
1004
1113
|
stash: stashCommand,
|
|
1005
1114
|
registry: registryCommand,
|
|
1006
1115
|
config: configCommand,
|
|
1116
|
+
feedback: feedbackCommand,
|
|
1007
1117
|
hints: hintsCommand,
|
|
1008
1118
|
completions: completionsCommand,
|
|
1009
1119
|
},
|
|
@@ -1057,9 +1167,9 @@ function buildHint(message) {
|
|
|
1057
1167
|
if (message.includes("Invalid value for --source"))
|
|
1058
1168
|
return "Pick one of: stash, registry, both.";
|
|
1059
1169
|
if (message.includes("Invalid value for --format"))
|
|
1060
|
-
return "Pick one of: json, text, yaml.";
|
|
1170
|
+
return "Pick one of: json, jsonl, text, yaml.";
|
|
1061
1171
|
if (message.includes("Invalid value for --detail"))
|
|
1062
|
-
return "Pick one of: brief, normal, full.";
|
|
1172
|
+
return "Pick one of: brief, normal, full, summary.";
|
|
1063
1173
|
if (message.includes("expected JSON object with endpoint and model")) {
|
|
1064
1174
|
return 'Quote JSON values in your shell, for example: akm config set embedding \'{"endpoint":"http://localhost:11434/v1/embeddings","model":"nomic-embed-text"}\'.';
|
|
1065
1175
|
}
|
|
@@ -1095,7 +1205,7 @@ function normalizeShowArgv(argv) {
|
|
|
1095
1205
|
const showArgs = [];
|
|
1096
1206
|
for (let i = 0; i < rest.length; i++) {
|
|
1097
1207
|
const arg = rest[i];
|
|
1098
|
-
if (arg === "--quiet" || arg === "-q") {
|
|
1208
|
+
if (arg === "--quiet" || arg === "-q" || arg === "--for-agent" || arg === "--for-agent=true") {
|
|
1099
1209
|
globalFlags.push(arg);
|
|
1100
1210
|
continue;
|
|
1101
1211
|
}
|
|
@@ -1204,8 +1314,9 @@ akm search "<query>" --detail full # Include scores, paths, timing
|
|
|
1204
1314
|
| \`--type\` | \`skill\`, \`command\`, \`agent\`, \`knowledge\`, \`script\`, \`memory\`, \`any\` | \`any\` |
|
|
1205
1315
|
| \`--source\` | \`stash\`, \`registry\`, \`both\` | \`stash\` |
|
|
1206
1316
|
| \`--limit\` | number | \`20\` |
|
|
1207
|
-
| \`--format\` | \`json\`, \`text\`, \`yaml\` | \`json\` |
|
|
1208
|
-
| \`--detail\` | \`brief\`, \`normal\`, \`full\` | \`brief\` |
|
|
1317
|
+
| \`--format\` | \`json\`, \`jsonl\`, \`text\`, \`yaml\` | \`json\` |
|
|
1318
|
+
| \`--detail\` | \`brief\`, \`normal\`, \`full\`, \`summary\` | \`brief\` |
|
|
1319
|
+
| \`--for-agent\` | boolean | \`false\` |
|
|
1209
1320
|
|
|
1210
1321
|
## Show
|
|
1211
1322
|
|
|
@@ -1219,7 +1330,7 @@ akm show agent:architect # Show agent (returns system promp
|
|
|
1219
1330
|
akm show knowledge:guide toc # Table of contents
|
|
1220
1331
|
akm show knowledge:guide section "Auth" # Specific section
|
|
1221
1332
|
akm show knowledge:guide lines 10 30 # Line range
|
|
1222
|
-
akm show
|
|
1333
|
+
akm show knowledge:my-doc # Show content (local or remote)
|
|
1223
1334
|
\`\`\`
|
|
1224
1335
|
|
|
1225
1336
|
| Type | Key fields returned |
|
|
@@ -1307,11 +1418,14 @@ akm completions --install # Install completions
|
|
|
1307
1418
|
All commands accept \`--format\` and \`--detail\` flags:
|
|
1308
1419
|
|
|
1309
1420
|
- \`--format json\` (default) — structured JSON
|
|
1421
|
+
- \`--format jsonl\` — one JSON object per line (streaming-friendly)
|
|
1310
1422
|
- \`--format text\` — human-readable plain text
|
|
1311
1423
|
- \`--format yaml\` — YAML output
|
|
1312
1424
|
- \`--detail brief\` (default) — compact output
|
|
1313
1425
|
- \`--detail normal\` — adds tags, refs, origins
|
|
1314
1426
|
- \`--detail full\` — includes scores, paths, timing, debug info
|
|
1427
|
+
- \`--detail summary\` — metadata only (no content/template/prompt), under 200 tokens
|
|
1428
|
+
- \`--for-agent\` — agent-optimized output: strips non-actionable fields (takes precedence over \`--detail\`)
|
|
1315
1429
|
|
|
1316
1430
|
Run \`akm -h\` or \`akm <command> -h\` for per-command help.
|
|
1317
1431
|
`;
|
package/dist/common.js
CHANGED
|
@@ -5,6 +5,9 @@ import { ConfigError } from "./errors";
|
|
|
5
5
|
import { getConfigPath, getDefaultStashDir } from "./paths";
|
|
6
6
|
// ── Constants ───────────────────────────────────────────────────────────────
|
|
7
7
|
export const IS_WINDOWS = process.platform === "win32";
|
|
8
|
+
export function isHttpUrl(value) {
|
|
9
|
+
return !!value && /^https?:\/\//.test(value);
|
|
10
|
+
}
|
|
8
11
|
// ── Validators ──────────────────────────────────────────────────────────────
|
|
9
12
|
export function isAssetType(type) {
|
|
10
13
|
return Object.hasOwn(TYPE_DIRS, type);
|
package/dist/completions.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { getAssetTypes } from "./asset-spec";
|
|
4
5
|
// ── Known flag values ────────────────────────────────────────────────────────
|
|
5
6
|
const FLAG_VALUES = {
|
|
6
7
|
"--format": ["json", "text", "yaml"],
|
|
7
8
|
"--detail": ["brief", "normal", "full"],
|
|
8
|
-
"--type":
|
|
9
|
+
"--type": () => [...getAssetTypes(), "any"],
|
|
9
10
|
"--source": ["stash", "registry", "both"],
|
|
10
11
|
"--shell": ["bash"],
|
|
11
12
|
};
|
|
@@ -57,7 +58,8 @@ export function generateBashCompletions(cmd) {
|
|
|
57
58
|
}
|
|
58
59
|
// Build flag-value completion cases
|
|
59
60
|
const valueCases = [];
|
|
60
|
-
for (const [flag,
|
|
61
|
+
for (const [flag, valuesOrFn] of Object.entries(FLAG_VALUES)) {
|
|
62
|
+
const values = typeof valuesOrFn === "function" ? valuesOrFn() : valuesOrFn;
|
|
61
63
|
valueCases.push(` ${flag})
|
|
62
64
|
COMPREPLY=( $(compgen -W "${values.join(" ")}" -- "\${cur}") )
|
|
63
65
|
return 0
|