cngkit 1.1.17 → 1.1.19

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 (76) hide show
  1. package/README.md +100 -7
  2. package/dist/chunk-3A6GRNEV.js +1590 -0
  3. package/dist/chunk-3A6GRNEV.js.map +1 -0
  4. package/dist/{chunk-HRFI2IEP.js → chunk-7SO75QXJ.js} +886 -68
  5. package/dist/chunk-7SO75QXJ.js.map +1 -0
  6. package/dist/chunk-DBA3BZXP.js +231 -0
  7. package/dist/chunk-DBA3BZXP.js.map +1 -0
  8. package/dist/{chunk-5ZNV3FDG.js → chunk-GBONV6XP.js} +16 -4
  9. package/dist/chunk-GBONV6XP.js.map +1 -0
  10. package/dist/chunk-L6ZVQRSY.js +569 -0
  11. package/dist/chunk-L6ZVQRSY.js.map +1 -0
  12. package/dist/{chunk-VCWNKNUE.js → chunk-NGEWD4BW.js} +10 -1
  13. package/dist/chunk-NGEWD4BW.js.map +1 -0
  14. package/dist/chunk-TYDIBWZV.js +35 -0
  15. package/dist/chunk-TYDIBWZV.js.map +1 -0
  16. package/dist/{chunk-GT2MTS6E.js → chunk-X4E7NAN4.js} +2 -2
  17. package/dist/cli.js +82 -16
  18. package/dist/cli.js.map +1 -1
  19. package/dist/commands/coderoom/index.js +6 -6
  20. package/dist/commands/coderoom/index.js.map +1 -1
  21. package/dist/commands/coderoom/join.js +5 -5
  22. package/dist/commands/coderoom/share.js +5 -5
  23. package/dist/commands/hookify/index.js +25 -0
  24. package/dist/commands/hookify/index.js.map +1 -0
  25. package/dist/commands/hookify/ingest.js +127 -0
  26. package/dist/commands/hookify/ingest.js.map +1 -0
  27. package/dist/commands/hooks/index.js +25 -0
  28. package/dist/commands/hooks/index.js.map +1 -0
  29. package/dist/commands/hooks/install.js +40 -0
  30. package/dist/commands/hooks/install.js.map +1 -0
  31. package/dist/commands/hooks/uninstall.js +40 -0
  32. package/dist/commands/hooks/uninstall.js.map +1 -0
  33. package/dist/commands/index.js +5 -5
  34. package/dist/commands/index.js.map +1 -1
  35. package/dist/commands/knowledges/audiences.js +6 -6
  36. package/dist/commands/knowledges/cat.js +31 -0
  37. package/dist/commands/knowledges/cat.js.map +1 -0
  38. package/dist/commands/knowledges/files.js +6 -6
  39. package/dist/commands/knowledges/find.js +66 -0
  40. package/dist/commands/knowledges/find.js.map +1 -0
  41. package/dist/commands/knowledges/glob.js +6 -6
  42. package/dist/commands/knowledges/grep.js +6 -6
  43. package/dist/commands/knowledges/head.js +41 -0
  44. package/dist/commands/knowledges/head.js.map +1 -0
  45. package/dist/commands/knowledges/index.js +6 -6
  46. package/dist/commands/knowledges/index.js.map +1 -1
  47. package/dist/commands/knowledges/list.js +7 -7
  48. package/dist/commands/knowledges/list.js.map +1 -1
  49. package/dist/commands/knowledges/ls.js +40 -0
  50. package/dist/commands/knowledges/ls.js.map +1 -0
  51. package/dist/commands/knowledges/read.js +6 -6
  52. package/dist/commands/knowledges/realpath.js +31 -0
  53. package/dist/commands/knowledges/realpath.js.map +1 -0
  54. package/dist/commands/knowledges/search.js +6 -6
  55. package/dist/commands/knowledges/stat.js +31 -0
  56. package/dist/commands/knowledges/stat.js.map +1 -0
  57. package/dist/commands/knowledges/status.js +6 -6
  58. package/dist/commands/knowledges/tail.js +41 -0
  59. package/dist/commands/knowledges/tail.js.map +1 -0
  60. package/dist/commands/knowledges/tree.js +46 -0
  61. package/dist/commands/knowledges/tree.js.map +1 -0
  62. package/dist/commands/login.js +3 -3
  63. package/dist/commands/scrub.js +3 -3
  64. package/dist/commands/transcripts.js +6 -6
  65. package/dist/commands/transcripts.js.map +1 -1
  66. package/package.json +2 -2
  67. package/dist/chunk-5ZNV3FDG.js.map +0 -1
  68. package/dist/chunk-BL3XMLIH.js +0 -573
  69. package/dist/chunk-BL3XMLIH.js.map +0 -1
  70. package/dist/chunk-HRFI2IEP.js.map +0 -1
  71. package/dist/chunk-K36DKQWH.js +0 -327
  72. package/dist/chunk-K36DKQWH.js.map +0 -1
  73. package/dist/chunk-VCWNKNUE.js.map +0 -1
  74. package/dist/chunk-WYJTGGMN.js +0 -222
  75. package/dist/chunk-WYJTGGMN.js.map +0 -1
  76. /package/dist/{chunk-GT2MTS6E.js.map → chunk-X4E7NAN4.js.map} +0 -0
@@ -0,0 +1,569 @@
1
+ import {
2
+ coerceLimit,
3
+ coerceOptionalNumber,
4
+ formatJson,
5
+ shouldPrintJson,
6
+ singleLine
7
+ } from "./chunk-XQGLUQFM.js";
8
+ import {
9
+ createCngApiClient
10
+ } from "./chunk-TYDIBWZV.js";
11
+ import {
12
+ resolveOutputFormat
13
+ } from "./chunk-7SO75QXJ.js";
14
+
15
+ // src/features/knowledges/knowledges-api.ts
16
+ function createKnowledgesApi(options) {
17
+ const client = createCngApiClient(options);
18
+ return {
19
+ getCatalog: () => client.harnessKnowledges.getHarnessKnowledgesCatalog(),
20
+ listAudiences: () => client.harnessKnowledges.listHarnessKnowledgesAudiences(),
21
+ search: (query, limit) => client.harnessKnowledges.searchHarnessKnowledges({
22
+ q: query,
23
+ limit
24
+ }),
25
+ listTopics: () => client.harnessKnowledges.listHarnessKnowledgesTopics(),
26
+ listFiles: ({ query, audience, limit }) => client.harnessKnowledges.listHarnessTopicAssets({
27
+ ...query ? { q: query } : {},
28
+ ...audience ? { audience } : {},
29
+ limit
30
+ }),
31
+ read: ({ filePath, offset, limit }) => client.harnessFilesystem.getHarnessFilesystemRead({
32
+ file_path: filePath,
33
+ offset,
34
+ limit
35
+ }),
36
+ grep: ({ pattern, path, include, mode, context, ignoreCase }) => client.harnessFilesystem.getHarnessFilesystemGrep({
37
+ pattern,
38
+ path,
39
+ include,
40
+ output_mode: mode,
41
+ context,
42
+ case_insensitive: ignoreCase ? "true" : void 0
43
+ }),
44
+ glob: ({ pattern, path }) => client.harnessFilesystem.getHarnessFilesystemGlob({
45
+ pattern,
46
+ path
47
+ }),
48
+ listDirectory: ({ path, limit }) => client.harnessFilesystem.getHarnessFilesystemLs({
49
+ path,
50
+ limit
51
+ }),
52
+ tree: ({ path, depth, limit }) => client.harnessFilesystem.getHarnessFilesystemTree({
53
+ path,
54
+ depth,
55
+ limit
56
+ }),
57
+ find: ({ path, name, type, maxDepth, limit }) => client.harnessFilesystem.getHarnessFilesystemFind({
58
+ path,
59
+ ...name ? { name } : {},
60
+ ...type ? { type } : {},
61
+ ...maxDepth !== void 0 ? { max_depth: maxDepth } : {},
62
+ limit
63
+ }),
64
+ tail: ({ filePath, lines }) => client.harnessFilesystem.getHarnessFilesystemTail({
65
+ file_path: filePath,
66
+ lines
67
+ }),
68
+ statPath: ({ path }) => client.harnessFilesystem.getHarnessFilesystemStat({
69
+ path
70
+ })
71
+ };
72
+ }
73
+
74
+ // src/features/knowledges/knowledges-input.ts
75
+ function normalizeAudienceId(value) {
76
+ if (value === void 0) {
77
+ return void 0;
78
+ }
79
+ switch (value) {
80
+ case "all":
81
+ case "operators":
82
+ case "builders":
83
+ case "researchers":
84
+ case "agent-makers":
85
+ return value;
86
+ default:
87
+ throw new Error(
88
+ `Unknown audience "${value}". Run cngkit knowledges audiences to see supported values.`
89
+ );
90
+ }
91
+ }
92
+ function normalizeCatalogPath(value) {
93
+ const trimmed = value.trim();
94
+ if (trimmed === "/" || trimmed === "") {
95
+ return "skills";
96
+ }
97
+ const relativePath = trimmed.replace(/^\/+/, "");
98
+ if (relativePath.startsWith("skills/knowledges/")) {
99
+ return relativePath;
100
+ }
101
+ const [firstSegment, ...restSegments] = relativePath.split("/");
102
+ if (!firstSegment) {
103
+ return relativePath;
104
+ }
105
+ switch (firstSegment) {
106
+ case "concepts":
107
+ case "domains":
108
+ case "formats":
109
+ case "languages":
110
+ case "libraries":
111
+ case "patterns":
112
+ case "platforms":
113
+ case "procedures":
114
+ case "protocols":
115
+ case "tools":
116
+ return `skills/knowledges/topics/${firstSegment}${restSegments.length > 0 ? `/${restSegments.join("/")}` : ""}`;
117
+ default:
118
+ return relativePath;
119
+ }
120
+ }
121
+ function normalizeFilesystemCatalogPath(value) {
122
+ const trimmed = value.trim();
123
+ if (trimmed === "/" || trimmed === "") {
124
+ return "skills/knowledges/topics";
125
+ }
126
+ return normalizeCatalogPath(trimmed);
127
+ }
128
+ function normalizeGrepMode(value) {
129
+ if (value === void 0) {
130
+ return "content";
131
+ }
132
+ switch (value) {
133
+ case "content":
134
+ case "files_with_matches":
135
+ case "count":
136
+ return value;
137
+ default:
138
+ throw new Error("Unknown grep mode. Use one of: content, files_with_matches, count.");
139
+ }
140
+ }
141
+
142
+ // src/features/knowledges/run-knowledges-command.ts
143
+ async function runKnowStatusCommand(options, output, dependencies) {
144
+ const api = dependencies?.api ?? createKnowledgesApi(options);
145
+ const response = await api.getCatalog();
146
+ if (shouldPrintJson(options)) {
147
+ output.raw(formatJson(response.data));
148
+ return;
149
+ }
150
+ const lines = [
151
+ `Catalog: ${response.data.name}`,
152
+ `Files: ${response.data.files}`,
153
+ `Blobs: ${response.data.blobs}`,
154
+ `Database: ${response.data.database.engine} (${response.data.database.binding})`
155
+ ];
156
+ output.info(lines.join("\n"));
157
+ }
158
+ async function runKnowAudiencesCommand(options, output, dependencies) {
159
+ const api = dependencies?.api ?? createKnowledgesApi(options);
160
+ const response = await api.listAudiences();
161
+ if (shouldPrintJson(options)) {
162
+ output.raw(formatJson(response.data));
163
+ return;
164
+ }
165
+ const lines = response.data.audiences.flatMap((audience) => [
166
+ `${audience.id} - ${audience.label}`,
167
+ ` ${singleLine(audience.help)}`
168
+ ]);
169
+ output.info(lines.length > 0 ? lines.join("\n") : "No audiences available.");
170
+ }
171
+ async function runKnowSearchCommand(query, options, output, dependencies) {
172
+ if (!query) {
173
+ throw new Error("Missing search query. Usage: cngkit knowledges search <query>");
174
+ }
175
+ const api = dependencies?.api ?? createKnowledgesApi(options);
176
+ const response = await api.search(query, coerceLimit(options.limit, 5));
177
+ if (shouldPrintJson(options)) {
178
+ output.raw(formatJson(response.data));
179
+ return;
180
+ }
181
+ const lines = response.data.results.flatMap((result, index) => [
182
+ `${index + 1}. ${result.title} (${result.topicName})`,
183
+ ` score ${result.score.toFixed(3)} | ${result.path}`,
184
+ ` ${singleLine(result.description || result.contentPreview)}`
185
+ ]);
186
+ if (lines.length > 0) {
187
+ output.info(lines.join("\n"));
188
+ return;
189
+ }
190
+ output.warning(`No results for "${query}".`);
191
+ }
192
+ async function runKnowListCommand(query, options, output, dependencies) {
193
+ const api = dependencies?.api ?? createKnowledgesApi(options);
194
+ const response = await api.listTopics();
195
+ const limit = coerceLimit(options.limit, 25);
196
+ const normalizedQuery = query?.toLowerCase();
197
+ const topics = response.data.topics.filter((topic) => {
198
+ if (!normalizedQuery) {
199
+ return true;
200
+ }
201
+ return [topic.name, topic.title, topic.description, topic.type].join(" ").toLowerCase().includes(normalizedQuery);
202
+ }).slice(0, limit);
203
+ if (shouldPrintJson(options)) {
204
+ output.raw(formatJson({ topics, total: topics.length }));
205
+ return;
206
+ }
207
+ const lines = topics.flatMap((topic) => [
208
+ `${topic.name} [${topic.type}]`,
209
+ ` ${topic.title} | files ${topic.fileCount} | rating ${topic.rating}`,
210
+ ` ${singleLine(topic.description)}`
211
+ ]);
212
+ if (lines.length > 0) {
213
+ output.info(lines.join("\n"));
214
+ return;
215
+ }
216
+ output.warning("No matching topics.");
217
+ }
218
+ async function runKnowFilesCommand(query, options, output, dependencies) {
219
+ const api = dependencies?.api ?? createKnowledgesApi(options);
220
+ const response = await api.listFiles({
221
+ query,
222
+ audience: normalizeAudienceId(options.audience),
223
+ limit: coerceLimit(options.limit, 25)
224
+ });
225
+ if (shouldPrintJson(options)) {
226
+ output.raw(formatJson(response.data));
227
+ return;
228
+ }
229
+ const lines = response.data.files.map((file) => {
230
+ const title = file.display_title ?? file.title ?? file.topic_name ?? "Untitled";
231
+ return `${file.path}
232
+ ${title}`;
233
+ });
234
+ if (lines.length > 0) {
235
+ output.info(lines.join("\n"));
236
+ return;
237
+ }
238
+ output.warning("No matching files.");
239
+ }
240
+ async function runKnowReadCommand(filePath, options, output, dependencies) {
241
+ if (!filePath) {
242
+ throw new Error("Missing file_path. Usage: cngkit knowledges read <file_path>");
243
+ }
244
+ const api = dependencies?.api ?? createKnowledgesApi(options);
245
+ const response = await api.read({
246
+ filePath: normalizeCatalogPath(filePath),
247
+ offset: coerceOptionalNumber(options.offset),
248
+ limit: coerceLimit(options.limit, 200, 2e3)
249
+ });
250
+ if (shouldPrintJson(options)) {
251
+ output.raw(formatJson(response.data));
252
+ return;
253
+ }
254
+ if (resolveOutputFormat() === "markdown" || !response.data.file_path.endsWith(".md")) {
255
+ output.raw(response.data.content);
256
+ } else {
257
+ output.markdown(response.data.content);
258
+ }
259
+ if (response.data.truncated) {
260
+ output.warning(
261
+ `[truncated: showing ${response.data.limit} lines from offset ${response.data.offset} of ${response.data.total_lines}]`
262
+ );
263
+ }
264
+ }
265
+ async function runKnowCatCommand(filePath, options, output, dependencies) {
266
+ if (!filePath) {
267
+ throw new Error("Missing file_path. Usage: cngkit knowledges cat <file_path>");
268
+ }
269
+ const api = dependencies?.api ?? createKnowledgesApi(options);
270
+ const response = await api.read({
271
+ filePath: normalizeCatalogPath(filePath),
272
+ offset: 0,
273
+ limit: 2e3
274
+ });
275
+ outputRawContent(response.data, options, output);
276
+ }
277
+ async function runKnowHeadCommand(filePath, options, output, dependencies) {
278
+ if (!filePath) {
279
+ throw new Error("Missing file_path. Usage: cngkit knowledges head <file_path> -n 10");
280
+ }
281
+ const api = dependencies?.api ?? createKnowledgesApi(options);
282
+ const response = await api.read({
283
+ filePath: normalizeCatalogPath(filePath),
284
+ offset: 0,
285
+ limit: coerceLimit(options.lines, 10, 2e3)
286
+ });
287
+ outputRawContent(response.data, options, output);
288
+ }
289
+ async function runKnowTailCommand(filePath, options, output, dependencies) {
290
+ if (!filePath) {
291
+ throw new Error("Missing file_path. Usage: cngkit knowledges tail <file_path> -n 10");
292
+ }
293
+ const api = dependencies?.api ?? createKnowledgesApi(options);
294
+ const response = await api.tail({
295
+ filePath: normalizeCatalogPath(filePath),
296
+ lines: coerceLimit(options.lines, 10, 2e3)
297
+ });
298
+ outputRawContent(response.data, options, output);
299
+ }
300
+ async function runKnowGrepCommand(pattern, options, output, dependencies) {
301
+ if (!pattern) {
302
+ throw new Error("Missing pattern. Usage: cngkit knowledges grep <pattern>");
303
+ }
304
+ const api = dependencies?.api ?? createKnowledgesApi(options);
305
+ const limit = options.limit !== void 0 ? coerceOptionalNumber(options.limit) : void 0;
306
+ const response = await api.grep({
307
+ pattern,
308
+ path: normalizeCatalogPath(options.path ?? "/"),
309
+ include: options.include ?? "*",
310
+ mode: normalizeGrepMode(options.outputMode),
311
+ context: coerceLimit(options.context, 0, 20),
312
+ ignoreCase: options.caseInsensitive === true
313
+ });
314
+ if (shouldPrintJson(options)) {
315
+ output.raw(formatJson(response.data));
316
+ return;
317
+ }
318
+ if (response.data.mode === "files_with_matches") {
319
+ const files = limit ? response.data.files.slice(0, limit) : response.data.files;
320
+ if (files.length > 0) {
321
+ output.raw(files.join("\n"));
322
+ return;
323
+ }
324
+ output.warning(`No files matched "${pattern}".`);
325
+ return;
326
+ }
327
+ if (response.data.mode === "count") {
328
+ const counts = limit ? response.data.counts.slice(0, limit) : response.data.counts;
329
+ const lines2 = counts.map((count) => `${count.file_path}: ${count.match_count}`);
330
+ if (lines2.length > 0) {
331
+ output.raw(lines2.join("\n"));
332
+ return;
333
+ }
334
+ output.warning(`No matches for "${pattern}".`);
335
+ return;
336
+ }
337
+ const matches = limit ? response.data.matches.slice(0, limit) : response.data.matches;
338
+ const lines = matches.flatMap((match) => [
339
+ `${match.file_path}:${match.line_number}`,
340
+ ...match.context_before.map((line) => ` ${line}`),
341
+ `> ${match.line}`,
342
+ ...match.context_after.map((line) => ` ${line}`)
343
+ ]);
344
+ if (lines.length > 0) {
345
+ output.raw(lines.join("\n"));
346
+ return;
347
+ }
348
+ output.warning(`No matches for "${pattern}".`);
349
+ }
350
+ async function runKnowGlobCommand(pattern, options, output, dependencies) {
351
+ const api = dependencies?.api ?? createKnowledgesApi(options);
352
+ const limit = options.limit !== void 0 ? coerceOptionalNumber(options.limit) : void 0;
353
+ const response = await api.glob({
354
+ pattern: pattern ?? "**/*.md",
355
+ path: normalizeCatalogPath(options.path ?? "/")
356
+ });
357
+ if (shouldPrintJson(options)) {
358
+ output.raw(formatJson(response.data));
359
+ return;
360
+ }
361
+ const files = limit ? response.data.files.slice(0, limit) : response.data.files;
362
+ const wasClientTruncated = limit ? response.data.files.length > limit : false;
363
+ if (files.length > 0) {
364
+ output.raw(files.join("\n"));
365
+ } else {
366
+ output.warning("No matching files.");
367
+ }
368
+ if (response.data.truncated || wasClientTruncated) {
369
+ output.warning(`[truncated: ${response.data.total_files} total files]`);
370
+ }
371
+ }
372
+ async function runKnowLsCommand(path, options, output, dependencies) {
373
+ const api = dependencies?.api ?? createKnowledgesApi(options);
374
+ const response = await api.listDirectory({
375
+ path: normalizeFilesystemCatalogPath(path ?? "/"),
376
+ limit: coerceLimit(options.limit, 100, 1e3)
377
+ });
378
+ if (shouldPrintJson(options)) {
379
+ output.raw(formatJson(response.data));
380
+ return;
381
+ }
382
+ const entries = [...response.data.entries].sort(compareFilesystemEntries);
383
+ const lines = entries.map(
384
+ (entry) => options.long === true ? formatLongFilesystemEntryLine(entry) : formatShellFilesystemEntryName(entry)
385
+ );
386
+ if (lines.length > 0) {
387
+ output.raw(lines.join("\n"));
388
+ } else {
389
+ output.warning(`No entries under ${response.data.path}.`);
390
+ }
391
+ if (response.data.truncated) {
392
+ output.warning(`[truncated: ${response.data.total_entries} total entries]`);
393
+ }
394
+ }
395
+ async function runKnowTreeCommand(path, options, output, dependencies) {
396
+ const api = dependencies?.api ?? createKnowledgesApi(options);
397
+ const response = await api.tree({
398
+ path: normalizeFilesystemCatalogPath(path ?? "/"),
399
+ depth: coerceLimit(options.depth, 3, 8),
400
+ limit: coerceLimit(options.limit, 500, 2e3)
401
+ });
402
+ if (shouldPrintJson(options)) {
403
+ output.raw(formatJson(response.data));
404
+ return;
405
+ }
406
+ const lines = formatFilesystemTree(response.data.path, response.data.entries);
407
+ output.raw(lines.join("\n"));
408
+ if (response.data.truncated) {
409
+ output.warning(`[truncated: ${response.data.total_entries} total entries]`);
410
+ }
411
+ }
412
+ async function runKnowFindCommand(path, options, output, dependencies) {
413
+ const api = dependencies?.api ?? createKnowledgesApi(options);
414
+ const response = await api.find({
415
+ path: normalizeFilesystemCatalogPath(path ?? "/"),
416
+ name: options.name,
417
+ type: options.type,
418
+ maxDepth: coerceOptionalFiniteNumber(options.maxDepth),
419
+ limit: coerceLimit(options.limit, 500, 2e3)
420
+ });
421
+ if (shouldPrintJson(options)) {
422
+ output.raw(formatJson(response.data));
423
+ return;
424
+ }
425
+ const entries = [...response.data.entries].sort(compareFilesystemEntries);
426
+ const lines = entries.map(formatFilesystemEntryPath);
427
+ if (lines.length > 0) {
428
+ output.raw(lines.join("\n"));
429
+ } else {
430
+ output.warning(`No entries found under ${response.data.path}.`);
431
+ }
432
+ if (response.data.truncated) {
433
+ output.warning(`[truncated: ${response.data.total_entries} total entries]`);
434
+ }
435
+ }
436
+ async function runKnowStatCommand(path, options, output, dependencies) {
437
+ if (!path) {
438
+ throw new Error("Missing path. Usage: cngkit knowledges stat <path>");
439
+ }
440
+ const api = dependencies?.api ?? createKnowledgesApi(options);
441
+ const response = await api.statPath({
442
+ path: normalizeFilesystemCatalogPath(path)
443
+ });
444
+ if (shouldPrintJson(options)) {
445
+ output.raw(formatJson(response.data));
446
+ return;
447
+ }
448
+ output.raw(formatFilesystemStat(response.data));
449
+ }
450
+ async function runKnowRealpathCommand(path, options, output) {
451
+ if (!path) {
452
+ throw new Error("Missing path. Usage: cngkit knowledges realpath <path>");
453
+ }
454
+ const resolvedPath = normalizeFilesystemCatalogPath(path);
455
+ if (shouldPrintJson(options)) {
456
+ output.raw(formatJson({ path: resolvedPath }));
457
+ return;
458
+ }
459
+ output.raw(resolvedPath);
460
+ }
461
+ function compareFilesystemEntries(left, right) {
462
+ if (left.type !== right.type) {
463
+ return left.type === "directory" ? -1 : 1;
464
+ }
465
+ return left.path.localeCompare(right.path);
466
+ }
467
+ function outputRawContent(data, options, output) {
468
+ if (shouldPrintJson(options)) {
469
+ output.raw(formatJson(data));
470
+ return;
471
+ }
472
+ output.raw(data.content);
473
+ }
474
+ function formatFilesystemTree(rootPath, entries) {
475
+ const normalizedRootPath = rootPath.replace(/\/+$/, "");
476
+ const rootLine = formatTreeDirectoryName(rootPath);
477
+ const entryLines = [...entries].sort(compareFilesystemEntries).map((entry) => {
478
+ const relativePath = stripRootPath(entry.path, normalizedRootPath);
479
+ const segmentCount = relativePath.split("/").filter(Boolean).length;
480
+ const indent = " ".repeat(Math.max(segmentCount - 1, 0));
481
+ return `${indent}${formatShellFilesystemEntryName(entry)}`;
482
+ });
483
+ return [rootLine, ...entryLines];
484
+ }
485
+ function stripRootPath(path, rootPath) {
486
+ if (path === rootPath) {
487
+ return "";
488
+ }
489
+ if (rootPath && path.startsWith(`${rootPath}/`)) {
490
+ return path.slice(rootPath.length + 1);
491
+ }
492
+ return path;
493
+ }
494
+ function formatTreeDirectoryName(path) {
495
+ const normalizedPath = path.replace(/\/+$/, "");
496
+ return normalizedPath ? `${normalizedPath}/` : "/";
497
+ }
498
+ function formatShellFilesystemEntryName(entry) {
499
+ return entry.type === "directory" ? `${entry.name}/` : entry.name;
500
+ }
501
+ function formatFilesystemEntryPath(entry) {
502
+ return entry.type === "directory" ? `${entry.path}/` : entry.path;
503
+ }
504
+ function formatLongFilesystemEntryLine(entry) {
505
+ const fields = [
506
+ entry.type,
507
+ entry.path,
508
+ ...formatOptionalEntryFields([
509
+ ["size", entry.size],
510
+ ["files", entry.file_count],
511
+ ["children", entry.child_count],
512
+ ["total_size", entry.total_size],
513
+ ["sha256", entry.sha256],
514
+ ["asset_kind", entry.asset_kind],
515
+ ["topic", entry.topic_name]
516
+ ])
517
+ ];
518
+ return fields.join(" ");
519
+ }
520
+ function coerceOptionalFiniteNumber(value) {
521
+ const normalizedValue = coerceOptionalNumber(value);
522
+ return normalizedValue === void 0 || Number.isNaN(normalizedValue) ? void 0 : Math.max(1, Math.trunc(normalizedValue));
523
+ }
524
+ function formatFilesystemStat(entry) {
525
+ const fields = [
526
+ ["path", entry.path],
527
+ ["type", entry.type],
528
+ ["name", entry.name],
529
+ ["depth", entry.depth],
530
+ ["size", entry.size],
531
+ ["files", entry.file_count],
532
+ ["children", entry.child_count],
533
+ ["total_size", entry.total_size],
534
+ ["sha256", entry.sha256],
535
+ ["asset_kind", entry.asset_kind],
536
+ ["title", entry.title],
537
+ ["topic", entry.topic_name],
538
+ ["updated_at", entry.updated_at]
539
+ ];
540
+ return formatOptionalEntryFields(fields).join("\n");
541
+ }
542
+ function formatOptionalEntryFields(fields) {
543
+ return fields.flatMap(([key, value]) => {
544
+ if (value === null || value === "") {
545
+ return [];
546
+ }
547
+ return [`${key}=${value}`];
548
+ });
549
+ }
550
+
551
+ export {
552
+ runKnowStatusCommand,
553
+ runKnowAudiencesCommand,
554
+ runKnowSearchCommand,
555
+ runKnowListCommand,
556
+ runKnowFilesCommand,
557
+ runKnowReadCommand,
558
+ runKnowCatCommand,
559
+ runKnowHeadCommand,
560
+ runKnowTailCommand,
561
+ runKnowGrepCommand,
562
+ runKnowGlobCommand,
563
+ runKnowLsCommand,
564
+ runKnowTreeCommand,
565
+ runKnowFindCommand,
566
+ runKnowStatCommand,
567
+ runKnowRealpathCommand
568
+ };
569
+ //# sourceMappingURL=chunk-L6ZVQRSY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/features/knowledges/knowledges-api.ts","../src/features/knowledges/knowledges-input.ts","../src/features/knowledges/run-knowledges-command.ts"],"sourcesContent":["import type { CngApi } from \"@cng/client\";\n\nimport { createCngApiClient } from \"../../shared/api-client.js\";\nimport type { GlobalCommandOptions } from \"../../shared/config.js\";\n\nexport type KnowCommandDependencies = {\n api?: KnowledgesApi;\n};\n\nexport type KnowledgesApi = {\n getCatalog(): Promise<CngApi.HarnessCatalogSummaryApiResponse>;\n listAudiences(): Promise<CngApi.HarnessAudiencesApiResponse>;\n search(query: string, limit: number): Promise<CngApi.HarnessSemanticSearchApiResponse>;\n listTopics(): Promise<CngApi.HarnessTopicsApiResponse>;\n listFiles(options: {\n query?: string;\n audience?: CngApi.HarnessAudienceId;\n limit: number;\n }): Promise<CngApi.HarnessTopicAssetsApiResponse>;\n read(options: {\n filePath: string;\n offset?: number;\n limit: number;\n }): Promise<CngApi.HarnessReadApiResponse>;\n grep(options: {\n pattern: string;\n path: string;\n include: string;\n mode: CngApi.HarnessGrepOutputMode;\n context: number;\n ignoreCase: boolean;\n }): Promise<CngApi.HarnessGrepApiResponse>;\n glob(options: { pattern: string; path: string }): Promise<CngApi.HarnessGlobApiResponse>;\n listDirectory(options: {\n path: string;\n limit: number;\n }): Promise<CngApi.HarnessFilesystemLsApiResponse>;\n tree(options: {\n path: string;\n depth: number;\n limit: number;\n }): Promise<CngApi.HarnessFilesystemTreeApiResponse>;\n find(options: {\n path: string;\n name?: string;\n type?: CngApi.HarnessFilesystemFindType;\n maxDepth?: number;\n limit: number;\n }): Promise<CngApi.HarnessFilesystemFindApiResponse>;\n tail(options: {\n filePath: string;\n lines: number;\n }): Promise<CngApi.HarnessFilesystemTailApiResponse>;\n statPath(options: { path: string }): Promise<CngApi.HarnessFilesystemStatApiResponse>;\n};\n\nexport function createKnowledgesApi(options: GlobalCommandOptions): KnowledgesApi {\n const client = createCngApiClient(options);\n\n return {\n getCatalog: () => client.harnessKnowledges.getHarnessKnowledgesCatalog(),\n listAudiences: () => client.harnessKnowledges.listHarnessKnowledgesAudiences(),\n search: (query, limit) =>\n client.harnessKnowledges.searchHarnessKnowledges({\n q: query,\n limit,\n }),\n listTopics: () => client.harnessKnowledges.listHarnessKnowledgesTopics(),\n listFiles: ({ query, audience, limit }) =>\n client.harnessKnowledges.listHarnessTopicAssets({\n ...(query ? { q: query } : {}),\n ...(audience ? { audience } : {}),\n limit,\n }),\n read: ({ filePath, offset, limit }) =>\n client.harnessFilesystem.getHarnessFilesystemRead({\n file_path: filePath,\n offset,\n limit,\n }),\n grep: ({ pattern, path, include, mode, context, ignoreCase }) =>\n client.harnessFilesystem.getHarnessFilesystemGrep({\n pattern,\n path,\n include,\n output_mode: mode,\n context,\n case_insensitive: ignoreCase ? \"true\" : undefined,\n }),\n glob: ({ pattern, path }) =>\n client.harnessFilesystem.getHarnessFilesystemGlob({\n pattern,\n path,\n }),\n listDirectory: ({ path, limit }) =>\n client.harnessFilesystem.getHarnessFilesystemLs({\n path,\n limit,\n }),\n tree: ({ path, depth, limit }) =>\n client.harnessFilesystem.getHarnessFilesystemTree({\n path,\n depth,\n limit,\n }),\n find: ({ path, name, type, maxDepth, limit }) =>\n client.harnessFilesystem.getHarnessFilesystemFind({\n path,\n ...(name ? { name } : {}),\n ...(type ? { type } : {}),\n ...(maxDepth !== undefined ? { max_depth: maxDepth } : {}),\n limit,\n }),\n tail: ({ filePath, lines }) =>\n client.harnessFilesystem.getHarnessFilesystemTail({\n file_path: filePath,\n lines,\n }),\n statPath: ({ path }) =>\n client.harnessFilesystem.getHarnessFilesystemStat({\n path,\n }),\n };\n}\n","import type { CngApi } from \"@cng/client\";\n\nexport function normalizeAudienceId(value: string | undefined): CngApi.HarnessAudienceId | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n switch (value) {\n case \"all\":\n case \"operators\":\n case \"builders\":\n case \"researchers\":\n case \"agent-makers\":\n return value;\n default:\n throw new Error(\n `Unknown audience \"${value}\". Run cngkit knowledges audiences to see supported values.`\n );\n }\n}\n\nexport function normalizeCatalogPath(value: string): string {\n const trimmed = value.trim();\n if (trimmed === \"/\" || trimmed === \"\") {\n return \"skills\";\n }\n\n const relativePath = trimmed.replace(/^\\/+/, \"\");\n if (relativePath.startsWith(\"skills/knowledges/\")) {\n return relativePath;\n }\n\n const [firstSegment, ...restSegments] = relativePath.split(\"/\");\n if (!firstSegment) {\n return relativePath;\n }\n\n switch (firstSegment) {\n case \"concepts\":\n case \"domains\":\n case \"formats\":\n case \"languages\":\n case \"libraries\":\n case \"patterns\":\n case \"platforms\":\n case \"procedures\":\n case \"protocols\":\n case \"tools\":\n return `skills/knowledges/topics/${firstSegment}${restSegments.length > 0 ? `/${restSegments.join(\"/\")}` : \"\"}`;\n default:\n return relativePath;\n }\n}\n\nexport function normalizeFilesystemCatalogPath(value: string): string {\n const trimmed = value.trim();\n if (trimmed === \"/\" || trimmed === \"\") {\n return \"skills/knowledges/topics\";\n }\n\n return normalizeCatalogPath(trimmed);\n}\n\nexport function normalizeGrepMode(value: string | undefined): CngApi.HarnessGrepOutputMode {\n if (value === undefined) {\n return \"content\";\n }\n\n switch (value) {\n case \"content\":\n case \"files_with_matches\":\n case \"count\":\n return value;\n default:\n throw new Error(\"Unknown grep mode. Use one of: content, files_with_matches, count.\");\n }\n}\n","import { renderKnowledgesHelp } from \"../../cli/help-specs.js\";\nimport type { CngApi } from \"@cng/client\";\nimport {\n coerceLimit,\n coerceOptionalNumber,\n formatJson,\n optionalJoinedArgument,\n shouldPrintJson,\n singleLine,\n type JsonOutputOptions,\n type NumberOption,\n} from \"../../shared/command-utils.js\";\nimport { resolveOutputFormat } from \"../../shared/config.js\";\nimport type { GlobalCommandOptions } from \"../../shared/config.js\";\nimport type { CommandOutput } from \"../../shared/output.js\";\nimport { createKnowledgesApi, type KnowCommandDependencies } from \"./knowledges-api.js\";\nimport {\n normalizeAudienceId,\n normalizeCatalogPath,\n normalizeFilesystemCatalogPath,\n normalizeGrepMode,\n} from \"./knowledges-input.js\";\n\nexport type KnowStatusCommandOptions = GlobalCommandOptions & JsonOutputOptions;\n\nexport type KnowAudiencesCommandOptions = GlobalCommandOptions & JsonOutputOptions;\n\nexport type KnowSearchCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n limit?: NumberOption;\n };\n\nexport type KnowListCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n limit?: NumberOption;\n };\n\nexport type KnowFilesCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n audience?: string;\n limit?: NumberOption;\n };\n\nexport type KnowReadCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n offset?: NumberOption;\n limit?: NumberOption;\n };\n\nexport type KnowCatCommandOptions = GlobalCommandOptions & JsonOutputOptions;\n\nexport type KnowHeadCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n lines?: NumberOption;\n };\n\nexport type KnowTailCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n lines?: NumberOption;\n };\n\nexport type KnowGrepCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n path?: string;\n include?: string;\n outputMode?: string;\n context?: NumberOption;\n caseInsensitive?: boolean;\n limit?: NumberOption;\n };\n\nexport type KnowGlobCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n path?: string;\n limit?: NumberOption;\n };\n\nexport type KnowLsCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n limit?: NumberOption;\n long?: boolean;\n };\n\nexport type KnowTreeCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n depth?: NumberOption;\n limit?: NumberOption;\n };\n\nexport type KnowFindCommandOptions = GlobalCommandOptions &\n JsonOutputOptions & {\n name?: string;\n type?: \"file\" | \"directory\";\n maxDepth?: NumberOption;\n limit?: NumberOption;\n };\n\nexport type KnowStatCommandOptions = GlobalCommandOptions & JsonOutputOptions;\n\nexport type KnowRealpathCommandOptions = GlobalCommandOptions & JsonOutputOptions;\n\nexport type KnowledgesCliOptions = KnowFilesCommandOptions &\n KnowGlobCommandOptions &\n KnowGrepCommandOptions &\n KnowCatCommandOptions &\n KnowHeadCommandOptions &\n KnowTailCommandOptions &\n KnowReadCommandOptions &\n KnowSearchCommandOptions &\n KnowLsCommandOptions &\n KnowTreeCommandOptions &\n KnowFindCommandOptions;\n\nexport async function runKnowledgesCommand(\n args: string[] | undefined,\n options: KnowledgesCliOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const [subcommand, ...subcommandArgs] = args ?? [];\n\n if (subcommand === undefined || subcommand === \"help\") {\n output.component(renderKnowledgesHelp(subcommandArgs[0]));\n return;\n }\n\n switch (subcommand) {\n case \"status\":\n return runKnowStatusCommand(options, output, dependencies);\n case \"audiences\":\n return runKnowAudiencesCommand(options, output, dependencies);\n case \"search\":\n return runKnowSearchCommand(\n optionalJoinedArgument(subcommandArgs),\n options,\n output,\n dependencies\n );\n case \"list\":\n return runKnowListCommand(\n optionalJoinedArgument(subcommandArgs),\n options,\n output,\n dependencies\n );\n case \"files\":\n return runKnowFilesCommand(\n optionalJoinedArgument(subcommandArgs),\n options,\n output,\n dependencies\n );\n case \"read\":\n return runKnowReadCommand(subcommandArgs[0], options, output, dependencies);\n case \"cat\":\n return runKnowCatCommand(subcommandArgs[0], options, output, dependencies);\n case \"head\":\n return runKnowHeadCommand(subcommandArgs[0], options, output, dependencies);\n case \"tail\":\n return runKnowTailCommand(subcommandArgs[0], options, output, dependencies);\n case \"grep\":\n return runKnowGrepCommand(\n optionalJoinedArgument(subcommandArgs),\n options,\n output,\n dependencies\n );\n case \"glob\":\n return runKnowGlobCommand(\n optionalJoinedArgument(subcommandArgs),\n options,\n output,\n dependencies\n );\n case \"ls\":\n return runKnowLsCommand(subcommandArgs[0], options, output, dependencies);\n case \"tree\":\n return runKnowTreeCommand(subcommandArgs[0], options, output, dependencies);\n case \"find\":\n return runKnowFindCommand(subcommandArgs[0], options, output, dependencies);\n case \"stat\":\n return runKnowStatCommand(subcommandArgs[0], options, output, dependencies);\n case \"realpath\":\n return runKnowRealpathCommand(subcommandArgs[0], options, output);\n default:\n throw new Error(\n \"Missing knowledges command. Usage: cngkit knowledges <status|audiences|search|list|files|read|cat|head|tail|grep|glob|ls|tree|find|stat|realpath>\"\n );\n }\n}\n\nexport async function runKnowStatusCommand(\n options: KnowStatusCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.getCatalog();\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const lines = [\n `Catalog: ${response.data.name}`,\n `Files: ${response.data.files}`,\n `Blobs: ${response.data.blobs}`,\n `Database: ${response.data.database.engine} (${response.data.database.binding})`,\n ];\n\n output.info(lines.join(\"\\n\"));\n}\n\nexport async function runKnowAudiencesCommand(\n options: KnowAudiencesCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.listAudiences();\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const lines = response.data.audiences.flatMap((audience) => [\n `${audience.id} - ${audience.label}`,\n ` ${singleLine(audience.help)}`,\n ]);\n\n output.info(lines.length > 0 ? lines.join(\"\\n\") : \"No audiences available.\");\n}\n\nexport async function runKnowSearchCommand(\n query: string | undefined,\n options: KnowSearchCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n if (!query) {\n throw new Error(\"Missing search query. Usage: cngkit knowledges search <query>\");\n }\n\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.search(query, coerceLimit(options.limit, 5));\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const lines = response.data.results.flatMap((result, index) => [\n `${index + 1}. ${result.title} (${result.topicName})`,\n ` score ${result.score.toFixed(3)} | ${result.path}`,\n ` ${singleLine(result.description || result.contentPreview)}`,\n ]);\n\n if (lines.length > 0) {\n output.info(lines.join(\"\\n\"));\n return;\n }\n\n output.warning(`No results for \"${query}\".`);\n}\n\nexport async function runKnowListCommand(\n query: string | undefined,\n options: KnowListCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.listTopics();\n const limit = coerceLimit(options.limit, 25);\n const normalizedQuery = query?.toLowerCase();\n const topics = response.data.topics\n .filter((topic) => {\n if (!normalizedQuery) {\n return true;\n }\n return [topic.name, topic.title, topic.description, topic.type]\n .join(\" \")\n .toLowerCase()\n .includes(normalizedQuery);\n })\n .slice(0, limit);\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson({ topics, total: topics.length }));\n return;\n }\n\n const lines = topics.flatMap((topic) => [\n `${topic.name} [${topic.type}]`,\n ` ${topic.title} | files ${topic.fileCount} | rating ${topic.rating}`,\n ` ${singleLine(topic.description)}`,\n ]);\n\n if (lines.length > 0) {\n output.info(lines.join(\"\\n\"));\n return;\n }\n\n output.warning(\"No matching topics.\");\n}\n\nexport async function runKnowFilesCommand(\n query: string | undefined,\n options: KnowFilesCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.listFiles({\n query,\n audience: normalizeAudienceId(options.audience),\n limit: coerceLimit(options.limit, 25),\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const lines = response.data.files.map((file) => {\n const title = file.display_title ?? file.title ?? file.topic_name ?? \"Untitled\";\n return `${file.path}\\n ${title}`;\n });\n\n if (lines.length > 0) {\n output.info(lines.join(\"\\n\"));\n return;\n }\n\n output.warning(\"No matching files.\");\n}\n\nexport async function runKnowReadCommand(\n filePath: string | undefined,\n options: KnowReadCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n if (!filePath) {\n throw new Error(\"Missing file_path. Usage: cngkit knowledges read <file_path>\");\n }\n\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.read({\n filePath: normalizeCatalogPath(filePath),\n offset: coerceOptionalNumber(options.offset),\n limit: coerceLimit(options.limit, 200, 2000),\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n if (resolveOutputFormat() === \"markdown\" || !response.data.file_path.endsWith(\".md\")) {\n output.raw(response.data.content);\n } else {\n output.markdown(response.data.content);\n }\n\n if (response.data.truncated) {\n output.warning(\n `[truncated: showing ${response.data.limit} lines from offset ${response.data.offset} of ${response.data.total_lines}]`\n );\n }\n}\n\nexport async function runKnowCatCommand(\n filePath: string | undefined,\n options: KnowCatCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n if (!filePath) {\n throw new Error(\"Missing file_path. Usage: cngkit knowledges cat <file_path>\");\n }\n\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.read({\n filePath: normalizeCatalogPath(filePath),\n offset: 0,\n limit: 2000,\n });\n\n outputRawContent(response.data, options, output);\n}\n\nexport async function runKnowHeadCommand(\n filePath: string | undefined,\n options: KnowHeadCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n if (!filePath) {\n throw new Error(\"Missing file_path. Usage: cngkit knowledges head <file_path> -n 10\");\n }\n\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.read({\n filePath: normalizeCatalogPath(filePath),\n offset: 0,\n limit: coerceLimit(options.lines, 10, 2000),\n });\n\n outputRawContent(response.data, options, output);\n}\n\nexport async function runKnowTailCommand(\n filePath: string | undefined,\n options: KnowTailCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n if (!filePath) {\n throw new Error(\"Missing file_path. Usage: cngkit knowledges tail <file_path> -n 10\");\n }\n\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.tail({\n filePath: normalizeCatalogPath(filePath),\n lines: coerceLimit(options.lines, 10, 2000),\n });\n\n outputRawContent(response.data, options, output);\n}\n\nexport async function runKnowGrepCommand(\n pattern: string | undefined,\n options: KnowGrepCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n if (!pattern) {\n throw new Error(\"Missing pattern. Usage: cngkit knowledges grep <pattern>\");\n }\n\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const limit = options.limit !== undefined ? coerceOptionalNumber(options.limit) : undefined;\n const response = await api.grep({\n pattern,\n path: normalizeCatalogPath(options.path ?? \"/\"),\n include: options.include ?? \"*\",\n mode: normalizeGrepMode(options.outputMode),\n context: coerceLimit(options.context, 0, 20),\n ignoreCase: options.caseInsensitive === true,\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n if (response.data.mode === \"files_with_matches\") {\n const files = limit ? response.data.files.slice(0, limit) : response.data.files;\n if (files.length > 0) {\n output.raw(files.join(\"\\n\"));\n return;\n }\n\n output.warning(`No files matched \"${pattern}\".`);\n return;\n }\n\n if (response.data.mode === \"count\") {\n const counts = limit ? response.data.counts.slice(0, limit) : response.data.counts;\n const lines = counts.map((count) => `${count.file_path}: ${count.match_count}`);\n if (lines.length > 0) {\n output.raw(lines.join(\"\\n\"));\n return;\n }\n\n output.warning(`No matches for \"${pattern}\".`);\n return;\n }\n\n const matches = limit ? response.data.matches.slice(0, limit) : response.data.matches;\n const lines = matches.flatMap((match) => [\n `${match.file_path}:${match.line_number}`,\n ...match.context_before.map((line) => ` ${line}`),\n `> ${match.line}`,\n ...match.context_after.map((line) => ` ${line}`),\n ]);\n\n if (lines.length > 0) {\n output.raw(lines.join(\"\\n\"));\n return;\n }\n\n output.warning(`No matches for \"${pattern}\".`);\n}\n\nexport async function runKnowGlobCommand(\n pattern: string | undefined,\n options: KnowGlobCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const limit = options.limit !== undefined ? coerceOptionalNumber(options.limit) : undefined;\n const response = await api.glob({\n pattern: pattern ?? \"**/*.md\",\n path: normalizeCatalogPath(options.path ?? \"/\"),\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const files = limit ? response.data.files.slice(0, limit) : response.data.files;\n const wasClientTruncated = limit ? response.data.files.length > limit : false;\n\n if (files.length > 0) {\n output.raw(files.join(\"\\n\"));\n } else {\n output.warning(\"No matching files.\");\n }\n if (response.data.truncated || wasClientTruncated) {\n output.warning(`[truncated: ${response.data.total_files} total files]`);\n }\n}\n\nexport async function runKnowLsCommand(\n path: string | undefined,\n options: KnowLsCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.listDirectory({\n path: normalizeFilesystemCatalogPath(path ?? \"/\"),\n limit: coerceLimit(options.limit, 100, 1000),\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const entries = [...response.data.entries].sort(compareFilesystemEntries);\n const lines = entries.map((entry) =>\n options.long === true\n ? formatLongFilesystemEntryLine(entry)\n : formatShellFilesystemEntryName(entry)\n );\n\n if (lines.length > 0) {\n output.raw(lines.join(\"\\n\"));\n } else {\n output.warning(`No entries under ${response.data.path}.`);\n }\n\n if (response.data.truncated) {\n output.warning(`[truncated: ${response.data.total_entries} total entries]`);\n }\n}\n\nexport async function runKnowTreeCommand(\n path: string | undefined,\n options: KnowTreeCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.tree({\n path: normalizeFilesystemCatalogPath(path ?? \"/\"),\n depth: coerceLimit(options.depth, 3, 8),\n limit: coerceLimit(options.limit, 500, 2000),\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const lines = formatFilesystemTree(response.data.path, response.data.entries);\n output.raw(lines.join(\"\\n\"));\n\n if (response.data.truncated) {\n output.warning(`[truncated: ${response.data.total_entries} total entries]`);\n }\n}\n\nexport async function runKnowFindCommand(\n path: string | undefined,\n options: KnowFindCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.find({\n path: normalizeFilesystemCatalogPath(path ?? \"/\"),\n name: options.name,\n type: options.type,\n maxDepth: coerceOptionalFiniteNumber(options.maxDepth),\n limit: coerceLimit(options.limit, 500, 2000),\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n const entries = [...response.data.entries].sort(compareFilesystemEntries);\n const lines = entries.map(formatFilesystemEntryPath);\n\n if (lines.length > 0) {\n output.raw(lines.join(\"\\n\"));\n } else {\n output.warning(`No entries found under ${response.data.path}.`);\n }\n\n if (response.data.truncated) {\n output.warning(`[truncated: ${response.data.total_entries} total entries]`);\n }\n}\n\nexport async function runKnowStatCommand(\n path: string | undefined,\n options: KnowStatCommandOptions,\n output: CommandOutput,\n dependencies?: KnowCommandDependencies\n): Promise<void> {\n if (!path) {\n throw new Error(\"Missing path. Usage: cngkit knowledges stat <path>\");\n }\n\n const api = dependencies?.api ?? createKnowledgesApi(options);\n const response = await api.statPath({\n path: normalizeFilesystemCatalogPath(path),\n });\n\n if (shouldPrintJson(options)) {\n output.raw(formatJson(response.data));\n return;\n }\n\n output.raw(formatFilesystemStat(response.data));\n}\n\nexport async function runKnowRealpathCommand(\n path: string | undefined,\n options: KnowRealpathCommandOptions,\n output: CommandOutput\n): Promise<void> {\n if (!path) {\n throw new Error(\"Missing path. Usage: cngkit knowledges realpath <path>\");\n }\n\n const resolvedPath = normalizeFilesystemCatalogPath(path);\n if (shouldPrintJson(options)) {\n output.raw(formatJson({ path: resolvedPath }));\n return;\n }\n\n output.raw(resolvedPath);\n}\n\nfunction compareFilesystemEntries(\n left: CngApi.HarnessFilesystemEntry,\n right: CngApi.HarnessFilesystemEntry\n): number {\n if (left.type !== right.type) {\n return left.type === \"directory\" ? -1 : 1;\n }\n\n return left.path.localeCompare(right.path);\n}\n\nfunction outputRawContent(\n data: CngApi.HarnessReadResponse,\n options: JsonOutputOptions,\n output: CommandOutput\n): void {\n if (shouldPrintJson(options)) {\n output.raw(formatJson(data));\n return;\n }\n\n output.raw(data.content);\n}\n\nfunction formatFilesystemTree(\n rootPath: string,\n entries: CngApi.HarnessFilesystemEntry[]\n): string[] {\n const normalizedRootPath = rootPath.replace(/\\/+$/, \"\");\n const rootLine = formatTreeDirectoryName(rootPath);\n const entryLines = [...entries].sort(compareFilesystemEntries).map((entry) => {\n const relativePath = stripRootPath(entry.path, normalizedRootPath);\n const segmentCount = relativePath.split(\"/\").filter(Boolean).length;\n const indent = \" \".repeat(Math.max(segmentCount - 1, 0));\n return `${indent}${formatShellFilesystemEntryName(entry)}`;\n });\n\n return [rootLine, ...entryLines];\n}\n\nfunction stripRootPath(path: string, rootPath: string): string {\n if (path === rootPath) {\n return \"\";\n }\n\n if (rootPath && path.startsWith(`${rootPath}/`)) {\n return path.slice(rootPath.length + 1);\n }\n\n return path;\n}\n\nfunction formatTreeDirectoryName(path: string): string {\n const normalizedPath = path.replace(/\\/+$/, \"\");\n return normalizedPath ? `${normalizedPath}/` : \"/\";\n}\n\nfunction formatShellFilesystemEntryName(entry: CngApi.HarnessFilesystemEntry): string {\n return entry.type === \"directory\" ? `${entry.name}/` : entry.name;\n}\n\nfunction formatFilesystemEntryPath(entry: CngApi.HarnessFilesystemEntry): string {\n return entry.type === \"directory\" ? `${entry.path}/` : entry.path;\n}\n\nfunction formatLongFilesystemEntryLine(entry: CngApi.HarnessFilesystemEntry): string {\n const fields = [\n entry.type,\n entry.path,\n ...formatOptionalEntryFields([\n [\"size\", entry.size],\n [\"files\", entry.file_count],\n [\"children\", entry.child_count],\n [\"total_size\", entry.total_size],\n [\"sha256\", entry.sha256],\n [\"asset_kind\", entry.asset_kind],\n [\"topic\", entry.topic_name],\n ]),\n ];\n\n return fields.join(\"\\t\");\n}\n\nfunction coerceOptionalFiniteNumber(value: NumberOption | undefined): number | undefined {\n const normalizedValue = coerceOptionalNumber(value);\n return normalizedValue === undefined || Number.isNaN(normalizedValue)\n ? undefined\n : Math.max(1, Math.trunc(normalizedValue));\n}\n\nfunction formatFilesystemStat(entry: CngApi.HarnessFilesystemStatResponse): string {\n const fields: Array<[string, string | number | null]> = [\n [\"path\", entry.path],\n [\"type\", entry.type],\n [\"name\", entry.name],\n [\"depth\", entry.depth],\n [\"size\", entry.size],\n [\"files\", entry.file_count],\n [\"children\", entry.child_count],\n [\"total_size\", entry.total_size],\n [\"sha256\", entry.sha256],\n [\"asset_kind\", entry.asset_kind],\n [\"title\", entry.title],\n [\"topic\", entry.topic_name],\n [\"updated_at\", entry.updated_at],\n ];\n\n return formatOptionalEntryFields(fields).join(\"\\n\");\n}\n\nfunction formatOptionalEntryFields(fields: Array<[string, string | number | null]>): string[] {\n return fields.flatMap(([key, value]) => {\n if (value === null || value === \"\") {\n return [];\n }\n\n return [`${key}=${value}`];\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwDO,SAAS,oBAAoB,SAA8C;AAChF,QAAM,SAAS,mBAAmB,OAAO;AAEzC,SAAO;AAAA,IACL,YAAY,MAAM,OAAO,kBAAkB,4BAA4B;AAAA,IACvE,eAAe,MAAM,OAAO,kBAAkB,+BAA+B;AAAA,IAC7E,QAAQ,CAAC,OAAO,UACd,OAAO,kBAAkB,wBAAwB;AAAA,MAC/C,GAAG;AAAA,MACH;AAAA,IACF,CAAC;AAAA,IACH,YAAY,MAAM,OAAO,kBAAkB,4BAA4B;AAAA,IACvE,WAAW,CAAC,EAAE,OAAO,UAAU,MAAM,MACnC,OAAO,kBAAkB,uBAAuB;AAAA,MAC9C,GAAI,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC;AAAA,MAC5B,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;AAAA,MAC/B;AAAA,IACF,CAAC;AAAA,IACH,MAAM,CAAC,EAAE,UAAU,QAAQ,MAAM,MAC/B,OAAO,kBAAkB,yBAAyB;AAAA,MAChD,WAAW;AAAA,MACX;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,MAAM,CAAC,EAAE,SAAS,MAAM,SAAS,MAAM,SAAS,WAAW,MACzD,OAAO,kBAAkB,yBAAyB;AAAA,MAChD;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb;AAAA,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