cngkit 1.1.18 → 1.1.20

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 (80) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +94 -19
  3. package/dist/chunk-CIZBVLN5.js +35 -0
  4. package/dist/chunk-CIZBVLN5.js.map +1 -0
  5. package/dist/{chunk-IB5B3BLY.js → chunk-E2GLGGKO.js} +16 -4
  6. package/dist/chunk-E2GLGGKO.js.map +1 -0
  7. package/dist/chunk-MRXGD6TC.js +42 -0
  8. package/dist/chunk-MRXGD6TC.js.map +1 -0
  9. package/dist/{chunk-ZA4YOWPB.js → chunk-NGEWD4BW.js} +2 -1
  10. package/dist/chunk-NODJM6SH.js +658 -0
  11. package/dist/chunk-NODJM6SH.js.map +1 -0
  12. package/dist/chunk-SKK2XLRZ.js +1590 -0
  13. package/dist/chunk-SKK2XLRZ.js.map +1 -0
  14. package/dist/chunk-SMTQ3W3F.js +271 -0
  15. package/dist/chunk-SMTQ3W3F.js.map +1 -0
  16. package/dist/{chunk-FJ34NVQ4.js → chunk-WDI43VPW.js} +578 -88
  17. package/dist/chunk-WDI43VPW.js.map +1 -0
  18. package/dist/cli.js +107 -27
  19. package/dist/cli.js.map +1 -1
  20. package/dist/commands/coderoom/index.js +6 -6
  21. package/dist/commands/coderoom/index.js.map +1 -1
  22. package/dist/commands/coderoom/join.js +5 -5
  23. package/dist/commands/coderoom/share.js +5 -5
  24. package/dist/commands/hookify/index.js +6 -6
  25. package/dist/commands/hookify/index.js.map +1 -1
  26. package/dist/commands/hookify/ingest.js +52 -13
  27. package/dist/commands/hookify/ingest.js.map +1 -1
  28. package/dist/commands/hooks/index.js +25 -0
  29. package/dist/commands/hooks/index.js.map +1 -0
  30. package/dist/commands/hooks/install.js +40 -0
  31. package/dist/commands/hooks/install.js.map +1 -0
  32. package/dist/commands/hooks/uninstall.js +40 -0
  33. package/dist/commands/hooks/uninstall.js.map +1 -0
  34. package/dist/commands/index.js +5 -5
  35. package/dist/commands/index.js.map +1 -1
  36. package/dist/commands/knowledges/audiences.js +6 -6
  37. package/dist/commands/knowledges/cat.js +31 -0
  38. package/dist/commands/knowledges/cat.js.map +1 -0
  39. package/dist/commands/knowledges/files.js +6 -6
  40. package/dist/commands/knowledges/find.js +66 -0
  41. package/dist/commands/knowledges/find.js.map +1 -0
  42. package/dist/commands/knowledges/glob.js +6 -6
  43. package/dist/commands/knowledges/grep.js +6 -6
  44. package/dist/commands/knowledges/head.js +41 -0
  45. package/dist/commands/knowledges/head.js.map +1 -0
  46. package/dist/commands/knowledges/index.js +6 -6
  47. package/dist/commands/knowledges/index.js.map +1 -1
  48. package/dist/commands/knowledges/list.js +7 -7
  49. package/dist/commands/knowledges/list.js.map +1 -1
  50. package/dist/commands/knowledges/ls.js +16 -7
  51. package/dist/commands/knowledges/ls.js.map +1 -1
  52. package/dist/commands/knowledges/read.js +6 -6
  53. package/dist/commands/knowledges/realpath.js +31 -0
  54. package/dist/commands/knowledges/realpath.js.map +1 -0
  55. package/dist/commands/knowledges/search.js +6 -6
  56. package/dist/commands/knowledges/stat.js +31 -0
  57. package/dist/commands/knowledges/stat.js.map +1 -0
  58. package/dist/commands/knowledges/status.js +6 -6
  59. package/dist/commands/knowledges/tail.js +41 -0
  60. package/dist/commands/knowledges/tail.js.map +1 -0
  61. package/dist/commands/knowledges/tree.js +46 -0
  62. package/dist/commands/knowledges/tree.js.map +1 -0
  63. package/dist/commands/login.js +4 -4
  64. package/dist/commands/login.js.map +1 -1
  65. package/dist/commands/scrub.js +38 -15
  66. package/dist/commands/scrub.js.map +1 -1
  67. package/dist/commands/transcripts.js +44 -24
  68. package/dist/commands/transcripts.js.map +1 -1
  69. package/package.json +3 -4
  70. package/dist/chunk-C7HFDK4S.js +0 -393
  71. package/dist/chunk-C7HFDK4S.js.map +0 -1
  72. package/dist/chunk-CBIVTEZP.js +0 -222
  73. package/dist/chunk-CBIVTEZP.js.map +0 -1
  74. package/dist/chunk-FJ34NVQ4.js.map +0 -1
  75. package/dist/chunk-IB5B3BLY.js.map +0 -1
  76. package/dist/chunk-KSW6QT5Q.js +0 -628
  77. package/dist/chunk-KSW6QT5Q.js.map +0 -1
  78. package/dist/chunk-TWQDLZ6F.js +0 -26
  79. package/dist/chunk-TWQDLZ6F.js.map +0 -1
  80. /package/dist/{chunk-ZA4YOWPB.js.map → chunk-NGEWD4BW.js.map} +0 -0
@@ -0,0 +1,658 @@
1
+ import {
2
+ coerceLimit,
3
+ coerceOptionalNumber,
4
+ formatJson,
5
+ shouldPrintJson,
6
+ singleLine
7
+ } from "./chunk-XQGLUQFM.js";
8
+ import {
9
+ createCngApiClient
10
+ } from "./chunk-CIZBVLN5.js";
11
+ import {
12
+ resolveOutputFormat
13
+ } from "./chunk-WDI43VPW.js";
14
+
15
+ // src/features/knowledges/run-knowledges-command.ts
16
+ import { createElement } from "react";
17
+
18
+ // src/features/knowledges/knowledges-api.ts
19
+ function createKnowledgesApi(options) {
20
+ const client = createCngApiClient(options);
21
+ return {
22
+ getCatalog: () => client.harnessKnowledges.getHarnessKnowledgesCatalog(),
23
+ listAudiences: () => client.harnessKnowledges.listHarnessKnowledgesAudiences(),
24
+ search: (query, limit) => client.harnessKnowledges.searchHarnessKnowledges({
25
+ q: query,
26
+ limit
27
+ }),
28
+ listTopics: () => client.harnessKnowledges.listHarnessKnowledgesTopics(),
29
+ listFiles: ({ query, audience, limit }) => client.harnessKnowledges.listHarnessTopicAssets({
30
+ ...query ? { q: query } : {},
31
+ ...audience ? { audience } : {},
32
+ limit
33
+ }),
34
+ read: ({ filePath, offset, limit }) => client.harnessFilesystem.getHarnessFilesystemRead({
35
+ file_path: filePath,
36
+ offset,
37
+ limit
38
+ }),
39
+ grep: ({ pattern, path, include, mode, context, ignoreCase }) => client.harnessFilesystem.getHarnessFilesystemGrep({
40
+ pattern,
41
+ path,
42
+ include,
43
+ output_mode: mode,
44
+ context,
45
+ case_insensitive: ignoreCase ? "true" : void 0
46
+ }),
47
+ glob: ({ pattern, path }) => client.harnessFilesystem.getHarnessFilesystemGlob({
48
+ pattern,
49
+ path
50
+ }),
51
+ listDirectory: ({ path, limit }) => client.harnessFilesystem.getHarnessFilesystemLs({
52
+ path,
53
+ limit
54
+ }),
55
+ tree: ({ path, depth, limit }) => client.harnessFilesystem.getHarnessFilesystemTree({
56
+ path,
57
+ depth,
58
+ limit
59
+ }),
60
+ find: ({ path, name, type, maxDepth, limit }) => client.harnessFilesystem.getHarnessFilesystemFind({
61
+ path,
62
+ ...name ? { name } : {},
63
+ ...type ? { type } : {},
64
+ ...maxDepth !== void 0 ? { max_depth: maxDepth } : {},
65
+ limit
66
+ }),
67
+ tail: ({ filePath, lines }) => client.harnessFilesystem.getHarnessFilesystemTail({
68
+ file_path: filePath,
69
+ lines
70
+ }),
71
+ statPath: ({ path }) => client.harnessFilesystem.getHarnessFilesystemStat({
72
+ path
73
+ })
74
+ };
75
+ }
76
+
77
+ // src/features/knowledges/knowledges-input.ts
78
+ var storedTopicsRoot = "skills/knowledges/topics";
79
+ function normalizeAudienceId(value) {
80
+ if (value === void 0) {
81
+ return void 0;
82
+ }
83
+ switch (value) {
84
+ case "all":
85
+ case "operators":
86
+ case "builders":
87
+ case "researchers":
88
+ case "agent-makers":
89
+ return value;
90
+ default:
91
+ throw new Error(
92
+ `Unknown audience "${value}". Run cngkit knowledges audiences to see supported values.`
93
+ );
94
+ }
95
+ }
96
+ function normalizeCatalogPath(value) {
97
+ const trimmed = value.trim();
98
+ if (trimmed === "/" || trimmed === "") {
99
+ return storedTopicsRoot;
100
+ }
101
+ const relativePath = trimmed.replace(/^\/+/, "");
102
+ if (relativePath === storedTopicsRoot || relativePath.startsWith(`${storedTopicsRoot}/`)) {
103
+ return relativePath;
104
+ }
105
+ const topicRelativePath = relativePath.startsWith("topics/") ? relativePath.slice("topics/".length) : relativePath;
106
+ const [firstSegment, ...restSegments] = relativePath.split("/");
107
+ if (!firstSegment) {
108
+ return relativePath;
109
+ }
110
+ switch (firstSegment) {
111
+ case "concepts":
112
+ case "domains":
113
+ case "formats":
114
+ case "languages":
115
+ case "libraries":
116
+ case "patterns":
117
+ case "platforms":
118
+ case "procedures":
119
+ case "protocols":
120
+ case "tools":
121
+ return `${storedTopicsRoot}/${firstSegment}${restSegments.length > 0 ? `/${restSegments.join("/")}` : ""}`;
122
+ default:
123
+ return `${storedTopicsRoot}/${topicRelativePath}`;
124
+ }
125
+ }
126
+ function normalizeFilesystemCatalogPath(value) {
127
+ const trimmed = value.trim();
128
+ if (trimmed === "/" || trimmed === "") {
129
+ return storedTopicsRoot;
130
+ }
131
+ return normalizeCatalogPath(trimmed);
132
+ }
133
+ function formatCatalogPathForDisplay(value) {
134
+ const normalized = value.replace(/\/+$/, "");
135
+ if (normalized === storedTopicsRoot) {
136
+ return "/";
137
+ }
138
+ if (normalized.startsWith(`${storedTopicsRoot}/`)) {
139
+ return `/${normalized.slice(storedTopicsRoot.length + 1)}`;
140
+ }
141
+ return value;
142
+ }
143
+ function normalizeGrepMode(value) {
144
+ if (value === void 0) {
145
+ return "content";
146
+ }
147
+ switch (value) {
148
+ case "content":
149
+ case "files_with_matches":
150
+ case "count":
151
+ return value;
152
+ default:
153
+ throw new Error("Unknown grep mode. Use one of: content, files_with_matches, count.");
154
+ }
155
+ }
156
+
157
+ // src/features/knowledges/knowledges-output.tsx
158
+ import { Box, Text } from "ink";
159
+ import { jsx, jsxs } from "react/jsx-runtime";
160
+ function KnowCatalogSummary({ catalog }) {
161
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
162
+ /* @__PURE__ */ jsxs(Text, { children: [
163
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "Catalog: " }),
164
+ catalog.name
165
+ ] }),
166
+ /* @__PURE__ */ jsxs(Text, { children: [
167
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "Files: " }),
168
+ catalog.files
169
+ ] }),
170
+ /* @__PURE__ */ jsxs(Text, { children: [
171
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "Blobs: " }),
172
+ catalog.blobs
173
+ ] }),
174
+ /* @__PURE__ */ jsxs(Text, { children: [
175
+ /* @__PURE__ */ jsx(Text, { bold: true, children: "Database: " }),
176
+ catalog.database.engine,
177
+ " (",
178
+ catalog.database.binding,
179
+ ")"
180
+ ] })
181
+ ] });
182
+ }
183
+ function KnowAudienceList({ audiences }) {
184
+ if (audiences.length === 0) {
185
+ return /* @__PURE__ */ jsx(Text, { color: "yellow", children: "No audiences available." });
186
+ }
187
+ return /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: audiences.map((audience) => /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [
188
+ /* @__PURE__ */ jsxs(Text, { children: [
189
+ /* @__PURE__ */ jsx(Text, { color: "cyan", children: audience.id }),
190
+ /* @__PURE__ */ jsxs(Text, { children: [
191
+ " - ",
192
+ audience.label
193
+ ] })
194
+ ] }),
195
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: singleLine(audience.help) })
196
+ ] }, audience.id)) });
197
+ }
198
+ function KnowSearchResults({
199
+ results
200
+ }) {
201
+ return /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: results.map((result, index) => /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [
202
+ /* @__PURE__ */ jsxs(Text, { children: [
203
+ /* @__PURE__ */ jsxs(Text, { color: "cyan", children: [
204
+ index + 1,
205
+ ". "
206
+ ] }),
207
+ /* @__PURE__ */ jsx(Text, { bold: true, children: result.title }),
208
+ /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
209
+ " (",
210
+ result.topicName,
211
+ ")"
212
+ ] })
213
+ ] }),
214
+ /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
215
+ "score ",
216
+ result.score.toFixed(3),
217
+ " | ",
218
+ formatCatalogPathForDisplay(result.path)
219
+ ] }),
220
+ /* @__PURE__ */ jsx(Text, { children: singleLine(result.description || result.contentPreview) })
221
+ ] }, result.id)) });
222
+ }
223
+ function KnowTopicList({ topics }) {
224
+ return /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: topics.map((topic) => /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [
225
+ /* @__PURE__ */ jsxs(Text, { children: [
226
+ /* @__PURE__ */ jsx(Text, { color: "cyan", children: topic.name }),
227
+ /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
228
+ " [",
229
+ topic.type,
230
+ "]"
231
+ ] })
232
+ ] }),
233
+ /* @__PURE__ */ jsxs(Text, { children: [
234
+ topic.title,
235
+ " | files ",
236
+ topic.fileCount,
237
+ " | rating ",
238
+ topic.rating
239
+ ] }),
240
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: singleLine(topic.description) })
241
+ ] }, topic.id)) });
242
+ }
243
+ function KnowTopicFileList({ files }) {
244
+ return /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: files.map((file) => {
245
+ const title = file.display_title ?? file.title ?? file.topic_name ?? "Untitled";
246
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [
247
+ /* @__PURE__ */ jsx(Text, { color: "cyan", children: formatCatalogPathForDisplay(file.path) }),
248
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: title })
249
+ ] }, `${file.path}-${file.sha256}`);
250
+ }) });
251
+ }
252
+
253
+ // src/features/knowledges/run-knowledges-command.ts
254
+ async function runKnowStatusCommand(options, output, dependencies) {
255
+ const api = dependencies?.api ?? createKnowledgesApi(options);
256
+ const response = await api.getCatalog();
257
+ if (shouldPrintJson(options)) {
258
+ output.raw(formatJson(response.data));
259
+ return;
260
+ }
261
+ output.component(createElement(KnowCatalogSummary, { catalog: response.data }));
262
+ }
263
+ async function runKnowAudiencesCommand(options, output, dependencies) {
264
+ const api = dependencies?.api ?? createKnowledgesApi(options);
265
+ const response = await api.listAudiences();
266
+ if (shouldPrintJson(options)) {
267
+ output.raw(formatJson(response.data));
268
+ return;
269
+ }
270
+ output.component(createElement(KnowAudienceList, { audiences: response.data.audiences }));
271
+ }
272
+ async function runKnowSearchCommand(query, options, output, dependencies) {
273
+ if (!query) {
274
+ throw new Error("Missing search query. Usage: cngkit knowledges search <query>");
275
+ }
276
+ const api = dependencies?.api ?? createKnowledgesApi(options);
277
+ const response = await api.search(query, coerceLimit(options.limit, 5));
278
+ if (shouldPrintJson(options)) {
279
+ output.raw(formatJson(response.data));
280
+ return;
281
+ }
282
+ if (response.data.results.length > 0) {
283
+ output.component(createElement(KnowSearchResults, { results: response.data.results }));
284
+ return;
285
+ }
286
+ output.warning(`No results for "${query}".`);
287
+ }
288
+ async function runKnowListCommand(query, options, output, dependencies) {
289
+ const api = dependencies?.api ?? createKnowledgesApi(options);
290
+ const response = await api.listTopics();
291
+ const limit = coerceLimit(options.limit, 25);
292
+ const normalizedQuery = query?.toLowerCase();
293
+ const topics = response.data.topics.filter((topic) => {
294
+ if (!normalizedQuery) {
295
+ return true;
296
+ }
297
+ return [topic.name, topic.title, topic.description, topic.type].join(" ").toLowerCase().includes(normalizedQuery);
298
+ }).slice(0, limit);
299
+ if (shouldPrintJson(options)) {
300
+ output.raw(formatJson({ topics, total: topics.length }));
301
+ return;
302
+ }
303
+ if (topics.length > 0) {
304
+ output.component(createElement(KnowTopicList, { topics }));
305
+ return;
306
+ }
307
+ output.warning("No matching topics.");
308
+ }
309
+ async function runKnowFilesCommand(query, options, output, dependencies) {
310
+ const api = dependencies?.api ?? createKnowledgesApi(options);
311
+ const response = await api.listFiles({
312
+ query,
313
+ audience: normalizeAudienceId(options.audience),
314
+ limit: coerceLimit(options.limit, 25)
315
+ });
316
+ if (shouldPrintJson(options)) {
317
+ output.raw(formatJson(response.data));
318
+ return;
319
+ }
320
+ if (response.data.files.length > 0) {
321
+ output.component(createElement(KnowTopicFileList, { files: response.data.files }));
322
+ return;
323
+ }
324
+ output.warning("No matching files.");
325
+ }
326
+ async function runKnowReadCommand(filePath, options, output, dependencies) {
327
+ if (!filePath) {
328
+ throw new Error("Missing file_path. Usage: cngkit knowledges read <file_path>");
329
+ }
330
+ const api = dependencies?.api ?? createKnowledgesApi(options);
331
+ const response = await api.read({
332
+ filePath: normalizeCatalogPath(filePath),
333
+ offset: coerceOptionalNumber(options.offset),
334
+ limit: coerceLimit(options.limit, 200, 2e3)
335
+ });
336
+ if (shouldPrintJson(options)) {
337
+ output.raw(formatJson(response.data));
338
+ return;
339
+ }
340
+ if (resolveOutputFormat() === "markdown" || !response.data.file_path.endsWith(".md")) {
341
+ output.raw(response.data.content);
342
+ } else {
343
+ output.markdown(response.data.content);
344
+ }
345
+ if (response.data.truncated) {
346
+ output.warning(
347
+ `[truncated: showing ${response.data.limit} lines from offset ${response.data.offset} of ${response.data.total_lines}]`
348
+ );
349
+ }
350
+ }
351
+ async function runKnowCatCommand(filePath, options, output, dependencies) {
352
+ if (!filePath) {
353
+ throw new Error("Missing file_path. Usage: cngkit knowledges cat <file_path>");
354
+ }
355
+ const api = dependencies?.api ?? createKnowledgesApi(options);
356
+ const response = await api.read({
357
+ filePath: normalizeCatalogPath(filePath),
358
+ offset: 0,
359
+ limit: 2e3
360
+ });
361
+ outputRawContent(response.data, options, output);
362
+ }
363
+ async function runKnowHeadCommand(filePath, options, output, dependencies) {
364
+ if (!filePath) {
365
+ throw new Error("Missing file_path. Usage: cngkit knowledges head <file_path> -n 10");
366
+ }
367
+ const api = dependencies?.api ?? createKnowledgesApi(options);
368
+ const response = await api.read({
369
+ filePath: normalizeCatalogPath(filePath),
370
+ offset: 0,
371
+ limit: coerceLimit(options.lines, 10, 2e3)
372
+ });
373
+ outputRawContent(response.data, options, output);
374
+ }
375
+ async function runKnowTailCommand(filePath, options, output, dependencies) {
376
+ if (!filePath) {
377
+ throw new Error("Missing file_path. Usage: cngkit knowledges tail <file_path> -n 10");
378
+ }
379
+ const api = dependencies?.api ?? createKnowledgesApi(options);
380
+ const response = await api.tail({
381
+ filePath: normalizeCatalogPath(filePath),
382
+ lines: coerceLimit(options.lines, 10, 2e3)
383
+ });
384
+ outputRawContent(response.data, options, output);
385
+ }
386
+ async function runKnowGrepCommand(pattern, options, output, dependencies) {
387
+ if (!pattern) {
388
+ throw new Error("Missing pattern. Usage: cngkit knowledges grep <pattern>");
389
+ }
390
+ const api = dependencies?.api ?? createKnowledgesApi(options);
391
+ const limit = options.limit !== void 0 ? coerceOptionalNumber(options.limit) : void 0;
392
+ const response = await api.grep({
393
+ pattern,
394
+ path: normalizeCatalogPath(options.path ?? "/"),
395
+ include: options.include ?? "*",
396
+ mode: normalizeGrepMode(options.outputMode),
397
+ context: coerceLimit(options.context, 0, 20),
398
+ ignoreCase: options.caseInsensitive === true
399
+ });
400
+ if (shouldPrintJson(options)) {
401
+ output.raw(formatJson(response.data));
402
+ return;
403
+ }
404
+ if (response.data.mode === "files_with_matches") {
405
+ const files = limit ? response.data.files.slice(0, limit) : response.data.files;
406
+ if (files.length > 0) {
407
+ output.raw(files.map(formatCatalogPathForDisplay).join("\n"));
408
+ return;
409
+ }
410
+ output.warning(`No files matched "${pattern}".`);
411
+ return;
412
+ }
413
+ if (response.data.mode === "count") {
414
+ const counts = limit ? response.data.counts.slice(0, limit) : response.data.counts;
415
+ const lines2 = counts.map(
416
+ (count) => `${formatCatalogPathForDisplay(count.file_path)}: ${count.match_count}`
417
+ );
418
+ if (lines2.length > 0) {
419
+ output.raw(lines2.join("\n"));
420
+ return;
421
+ }
422
+ output.warning(`No matches for "${pattern}".`);
423
+ return;
424
+ }
425
+ const matches = limit ? response.data.matches.slice(0, limit) : response.data.matches;
426
+ const lines = matches.flatMap((match) => [
427
+ `${formatCatalogPathForDisplay(match.file_path)}:${match.line_number}`,
428
+ ...match.context_before.map((line) => ` ${line}`),
429
+ `> ${match.line}`,
430
+ ...match.context_after.map((line) => ` ${line}`)
431
+ ]);
432
+ if (lines.length > 0) {
433
+ output.raw(lines.join("\n"));
434
+ return;
435
+ }
436
+ output.warning(`No matches for "${pattern}".`);
437
+ }
438
+ async function runKnowGlobCommand(pattern, options, output, dependencies) {
439
+ const api = dependencies?.api ?? createKnowledgesApi(options);
440
+ const limit = options.limit !== void 0 ? coerceOptionalNumber(options.limit) : void 0;
441
+ const response = await api.glob({
442
+ pattern: pattern ?? "**/*.md",
443
+ path: normalizeCatalogPath(options.path ?? "/")
444
+ });
445
+ if (shouldPrintJson(options)) {
446
+ output.raw(formatJson(response.data));
447
+ return;
448
+ }
449
+ const files = limit ? response.data.files.slice(0, limit) : response.data.files;
450
+ const wasClientTruncated = limit ? response.data.files.length > limit : false;
451
+ if (files.length > 0) {
452
+ output.raw(files.map(formatCatalogPathForDisplay).join("\n"));
453
+ } else {
454
+ output.warning("No matching files.");
455
+ }
456
+ if (response.data.truncated || wasClientTruncated) {
457
+ output.warning(`[truncated: ${response.data.total_files} total files]`);
458
+ }
459
+ }
460
+ async function runKnowLsCommand(path, options, output, dependencies) {
461
+ const api = dependencies?.api ?? createKnowledgesApi(options);
462
+ const response = await api.listDirectory({
463
+ path: normalizeFilesystemCatalogPath(path ?? "/"),
464
+ limit: coerceLimit(options.limit, 100, 1e3)
465
+ });
466
+ if (shouldPrintJson(options)) {
467
+ output.raw(formatJson(response.data));
468
+ return;
469
+ }
470
+ const entries = [...response.data.entries].sort(compareFilesystemEntries);
471
+ const lines = entries.map(
472
+ (entry) => options.long === true ? formatLongFilesystemEntryLine(entry) : formatShellFilesystemEntryName(entry)
473
+ );
474
+ if (lines.length > 0) {
475
+ output.raw(lines.join("\n"));
476
+ } else {
477
+ output.warning(`No entries under ${formatCatalogPathForDisplay(response.data.path)}.`);
478
+ }
479
+ if (response.data.truncated) {
480
+ output.warning(`[truncated: ${response.data.total_entries} total entries]`);
481
+ }
482
+ }
483
+ async function runKnowTreeCommand(path, options, output, dependencies) {
484
+ const api = dependencies?.api ?? createKnowledgesApi(options);
485
+ const response = await api.tree({
486
+ path: normalizeFilesystemCatalogPath(path ?? "/"),
487
+ depth: coerceLimit(options.depth, 3, 8),
488
+ limit: coerceLimit(options.limit, 500, 2e3)
489
+ });
490
+ if (shouldPrintJson(options)) {
491
+ output.raw(formatJson(response.data));
492
+ return;
493
+ }
494
+ const lines = formatFilesystemTree(response.data.path, response.data.entries);
495
+ output.raw(lines.join("\n"));
496
+ if (response.data.truncated) {
497
+ output.warning(`[truncated: ${response.data.total_entries} total entries]`);
498
+ }
499
+ }
500
+ async function runKnowFindCommand(path, options, output, dependencies) {
501
+ const api = dependencies?.api ?? createKnowledgesApi(options);
502
+ const response = await api.find({
503
+ path: normalizeFilesystemCatalogPath(path ?? "/"),
504
+ name: options.name,
505
+ type: options.type,
506
+ maxDepth: coerceOptionalFiniteNumber(options.maxDepth),
507
+ limit: coerceLimit(options.limit, 500, 2e3)
508
+ });
509
+ if (shouldPrintJson(options)) {
510
+ output.raw(formatJson(response.data));
511
+ return;
512
+ }
513
+ const entries = [...response.data.entries].sort(compareFilesystemEntries);
514
+ const lines = entries.map(formatFilesystemEntryPath);
515
+ if (lines.length > 0) {
516
+ output.raw(lines.join("\n"));
517
+ } else {
518
+ output.warning(`No entries found under ${formatCatalogPathForDisplay(response.data.path)}.`);
519
+ }
520
+ if (response.data.truncated) {
521
+ output.warning(`[truncated: ${response.data.total_entries} total entries]`);
522
+ }
523
+ }
524
+ async function runKnowStatCommand(path, options, output, dependencies) {
525
+ if (!path) {
526
+ throw new Error("Missing path. Usage: cngkit knowledges stat <path>");
527
+ }
528
+ const api = dependencies?.api ?? createKnowledgesApi(options);
529
+ const response = await api.statPath({
530
+ path: normalizeFilesystemCatalogPath(path)
531
+ });
532
+ if (shouldPrintJson(options)) {
533
+ output.raw(formatJson(response.data));
534
+ return;
535
+ }
536
+ output.raw(formatFilesystemStat(response.data));
537
+ }
538
+ async function runKnowRealpathCommand(path, options, output) {
539
+ if (!path) {
540
+ throw new Error("Missing path. Usage: cngkit knowledges realpath <path>");
541
+ }
542
+ const resolvedPath = formatCatalogPathForDisplay(normalizeFilesystemCatalogPath(path));
543
+ if (shouldPrintJson(options)) {
544
+ output.raw(formatJson({ path: resolvedPath }));
545
+ return;
546
+ }
547
+ output.raw(resolvedPath);
548
+ }
549
+ function compareFilesystemEntries(left, right) {
550
+ if (left.type !== right.type) {
551
+ return left.type === "directory" ? -1 : 1;
552
+ }
553
+ return left.path.localeCompare(right.path);
554
+ }
555
+ function outputRawContent(data, options, output) {
556
+ if (shouldPrintJson(options)) {
557
+ output.raw(formatJson(data));
558
+ return;
559
+ }
560
+ output.raw(data.content);
561
+ }
562
+ function formatFilesystemTree(rootPath, entries) {
563
+ const normalizedRootPath = rootPath.replace(/\/+$/, "");
564
+ const rootLine = formatTreeDirectoryName(rootPath);
565
+ const entryLines = [...entries].sort(compareFilesystemEntries).map((entry) => {
566
+ const relativePath = stripRootPath(entry.path, normalizedRootPath);
567
+ const segmentCount = relativePath.split("/").filter(Boolean).length;
568
+ const indent = " ".repeat(Math.max(segmentCount - 1, 0));
569
+ return `${indent}${formatShellFilesystemEntryName(entry)}`;
570
+ });
571
+ return [rootLine, ...entryLines];
572
+ }
573
+ function stripRootPath(path, rootPath) {
574
+ if (path === rootPath) {
575
+ return "";
576
+ }
577
+ if (rootPath && path.startsWith(`${rootPath}/`)) {
578
+ return path.slice(rootPath.length + 1);
579
+ }
580
+ return path;
581
+ }
582
+ function formatTreeDirectoryName(path) {
583
+ const normalizedPath = formatCatalogPathForDisplay(path).replace(/\/+$/, "");
584
+ return normalizedPath ? `${normalizedPath}/` : "/";
585
+ }
586
+ function formatShellFilesystemEntryName(entry) {
587
+ return entry.type === "directory" ? `${entry.name}/` : entry.name;
588
+ }
589
+ function formatFilesystemEntryPath(entry) {
590
+ const displayPath = formatCatalogPathForDisplay(entry.path);
591
+ return entry.type === "directory" ? `${displayPath}/` : displayPath;
592
+ }
593
+ function formatLongFilesystemEntryLine(entry) {
594
+ const fields = [
595
+ entry.type,
596
+ formatCatalogPathForDisplay(entry.path),
597
+ ...formatOptionalEntryFields([
598
+ ["size", entry.size],
599
+ ["files", entry.file_count],
600
+ ["children", entry.child_count],
601
+ ["total_size", entry.total_size],
602
+ ["sha256", entry.sha256],
603
+ ["asset_kind", entry.asset_kind],
604
+ ["topic", entry.topic_name]
605
+ ])
606
+ ];
607
+ return fields.join(" ");
608
+ }
609
+ function coerceOptionalFiniteNumber(value) {
610
+ const normalizedValue = coerceOptionalNumber(value);
611
+ return normalizedValue === void 0 || Number.isNaN(normalizedValue) ? void 0 : Math.max(1, Math.trunc(normalizedValue));
612
+ }
613
+ function formatFilesystemStat(entry) {
614
+ const fields = [
615
+ ["path", formatCatalogPathForDisplay(entry.path)],
616
+ ["type", entry.type],
617
+ ["name", entry.name],
618
+ ["depth", entry.depth],
619
+ ["size", entry.size],
620
+ ["files", entry.file_count],
621
+ ["children", entry.child_count],
622
+ ["total_size", entry.total_size],
623
+ ["sha256", entry.sha256],
624
+ ["asset_kind", entry.asset_kind],
625
+ ["title", entry.title],
626
+ ["topic", entry.topic_name],
627
+ ["updated_at", entry.updated_at]
628
+ ];
629
+ return formatOptionalEntryFields(fields).join("\n");
630
+ }
631
+ function formatOptionalEntryFields(fields) {
632
+ return fields.flatMap(([key, value]) => {
633
+ if (value === null || value === "") {
634
+ return [];
635
+ }
636
+ return [`${key}=${value}`];
637
+ });
638
+ }
639
+
640
+ export {
641
+ runKnowStatusCommand,
642
+ runKnowAudiencesCommand,
643
+ runKnowSearchCommand,
644
+ runKnowListCommand,
645
+ runKnowFilesCommand,
646
+ runKnowReadCommand,
647
+ runKnowCatCommand,
648
+ runKnowHeadCommand,
649
+ runKnowTailCommand,
650
+ runKnowGrepCommand,
651
+ runKnowGlobCommand,
652
+ runKnowLsCommand,
653
+ runKnowTreeCommand,
654
+ runKnowFindCommand,
655
+ runKnowStatCommand,
656
+ runKnowRealpathCommand
657
+ };
658
+ //# sourceMappingURL=chunk-NODJM6SH.js.map