cngkit 1.1.20 → 1.1.22

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 (87) hide show
  1. package/LICENSE +198 -4
  2. package/README.md +8 -12
  3. package/dist/{chunk-NGEWD4BW.js → chunk-25Q463MH.js} +1 -2
  4. package/dist/{chunk-SMTQ3W3F.js → chunk-3BATDTKU.js} +131 -112
  5. package/dist/chunk-3BATDTKU.js.map +1 -0
  6. package/dist/chunk-AS7FIJWP.js +88 -0
  7. package/dist/chunk-AS7FIJWP.js.map +1 -0
  8. package/dist/chunk-BRFWVQI4.js +18 -0
  9. package/dist/chunk-BRFWVQI4.js.map +1 -0
  10. package/dist/{chunk-WDI43VPW.js → chunk-DCW4RKLC.js} +63 -234
  11. package/dist/chunk-DCW4RKLC.js.map +1 -0
  12. package/dist/{chunk-SKK2XLRZ.js → chunk-JNHW72SU.js} +21 -15
  13. package/dist/chunk-JNHW72SU.js.map +1 -0
  14. package/dist/{chunk-E2GLGGKO.js → chunk-KURN5BJ6.js} +300 -143
  15. package/dist/chunk-KURN5BJ6.js.map +1 -0
  16. package/dist/{chunk-CIZBVLN5.js → chunk-N255PYL7.js} +2 -2
  17. package/dist/chunk-N255PYL7.js.map +1 -0
  18. package/dist/chunk-NLAANOBW.js +67 -0
  19. package/dist/chunk-NLAANOBW.js.map +1 -0
  20. package/dist/chunk-TIY4RTXC.js +268 -0
  21. package/dist/chunk-TIY4RTXC.js.map +1 -0
  22. package/dist/chunk-VMTXY4KQ.js +111 -0
  23. package/dist/chunk-VMTXY4KQ.js.map +1 -0
  24. package/dist/chunk-YALWTRIP.js +102 -0
  25. package/dist/chunk-YALWTRIP.js.map +1 -0
  26. package/dist/cli.js +2 -2
  27. package/dist/cli.js.map +1 -1
  28. package/dist/commands/coderoom/index.js +4 -4
  29. package/dist/commands/coderoom/join.js +5 -5
  30. package/dist/commands/coderoom/share.js +8 -11
  31. package/dist/commands/coderoom/share.js.map +1 -1
  32. package/dist/commands/hookify/index.js +4 -4
  33. package/dist/commands/hookify/ingest.js +4 -4
  34. package/dist/commands/hooks/index.js +4 -4
  35. package/dist/commands/hooks/install.js +4 -4
  36. package/dist/commands/hooks/uninstall.js +4 -4
  37. package/dist/commands/index.js +3 -3
  38. package/dist/commands/knowledges/audiences.js +26 -8
  39. package/dist/commands/knowledges/audiences.js.map +1 -1
  40. package/dist/commands/knowledges/cat.js +26 -7
  41. package/dist/commands/knowledges/cat.js.map +1 -1
  42. package/dist/commands/knowledges/files.js +39 -8
  43. package/dist/commands/knowledges/files.js.map +1 -1
  44. package/dist/commands/knowledges/find.js +48 -8
  45. package/dist/commands/knowledges/find.js.map +1 -1
  46. package/dist/commands/knowledges/glob.js +41 -8
  47. package/dist/commands/knowledges/glob.js.map +1 -1
  48. package/dist/commands/knowledges/grep.js +73 -8
  49. package/dist/commands/knowledges/grep.js.map +1 -1
  50. package/dist/commands/knowledges/head.js +31 -8
  51. package/dist/commands/knowledges/head.js.map +1 -1
  52. package/dist/commands/knowledges/index.js +4 -4
  53. package/dist/commands/knowledges/list.js +39 -8
  54. package/dist/commands/knowledges/list.js.map +1 -1
  55. package/dist/commands/knowledges/ls.js +47 -8
  56. package/dist/commands/knowledges/ls.js.map +1 -1
  57. package/dist/commands/knowledges/read.js +46 -8
  58. package/dist/commands/knowledges/read.js.map +1 -1
  59. package/dist/commands/knowledges/realpath.js +23 -8
  60. package/dist/commands/knowledges/realpath.js.map +1 -1
  61. package/dist/commands/knowledges/search.js +34 -8
  62. package/dist/commands/knowledges/search.js.map +1 -1
  63. package/dist/commands/knowledges/stat.js +32 -8
  64. package/dist/commands/knowledges/stat.js.map +1 -1
  65. package/dist/commands/knowledges/status.js +26 -8
  66. package/dist/commands/knowledges/status.js.map +1 -1
  67. package/dist/commands/knowledges/tail.js +30 -8
  68. package/dist/commands/knowledges/tail.js.map +1 -1
  69. package/dist/commands/knowledges/tree.js +38 -8
  70. package/dist/commands/knowledges/tree.js.map +1 -1
  71. package/dist/commands/login.js +3 -3
  72. package/dist/commands/login.js.map +1 -1
  73. package/dist/commands/scrub.js +3 -3
  74. package/dist/commands/scrub.js.map +1 -1
  75. package/dist/commands/transcripts.js +137 -119
  76. package/dist/commands/transcripts.js.map +1 -1
  77. package/package.json +2 -2
  78. package/dist/chunk-CIZBVLN5.js.map +0 -1
  79. package/dist/chunk-E2GLGGKO.js.map +0 -1
  80. package/dist/chunk-MRXGD6TC.js +0 -42
  81. package/dist/chunk-MRXGD6TC.js.map +0 -1
  82. package/dist/chunk-NODJM6SH.js +0 -658
  83. package/dist/chunk-NODJM6SH.js.map +0 -1
  84. package/dist/chunk-SKK2XLRZ.js.map +0 -1
  85. package/dist/chunk-SMTQ3W3F.js.map +0 -1
  86. package/dist/chunk-WDI43VPW.js.map +0 -1
  87. /package/dist/{chunk-NGEWD4BW.js.map → chunk-25Q463MH.js.map} +0 -0
@@ -1,19 +1,34 @@
1
1
  import {
2
- runKnowRealpathCommand
3
- } from "../../chunk-NODJM6SH.js";
4
- import "../../chunk-XQGLUQFM.js";
5
- import "../../chunk-SKK2XLRZ.js";
6
- import "../../chunk-CIZBVLN5.js";
2
+ formatCatalogPathForDisplay,
3
+ normalizeFilesystemCatalogPath
4
+ } from "../../chunk-AS7FIJWP.js";
5
+ import {
6
+ formatJson,
7
+ shouldPrintJson
8
+ } from "../../chunk-XQGLUQFM.js";
7
9
  import {
8
10
  JsonOutputOptionsSchema,
9
11
  RequiredCatalogPathArgsSchema
10
- } from "../../chunk-NGEWD4BW.js";
12
+ } from "../../chunk-25Q463MH.js";
11
13
  import {
12
14
  CommandRunner
13
- } from "../../chunk-MRXGD6TC.js";
14
- import "../../chunk-WDI43VPW.js";
15
+ } from "../../chunk-TIY4RTXC.js";
16
+ import "../../chunk-DCW4RKLC.js";
15
17
  import "../../chunk-PZ5AY32C.js";
16
18
 
19
+ // src/features/knowledges/handlers/realpath.ts
20
+ async function runKnowRealpathCommand(path, options2, output) {
21
+ if (!path) {
22
+ throw new Error("Missing path. Usage: cngkit knowledges realpath <path>");
23
+ }
24
+ const resolvedPath = formatCatalogPathForDisplay(normalizeFilesystemCatalogPath(path));
25
+ if (shouldPrintJson(options2)) {
26
+ output.raw(formatJson({ path: resolvedPath }));
27
+ return;
28
+ }
29
+ output.raw(resolvedPath);
30
+ }
31
+
17
32
  // src/commands/knowledges/realpath.tsx
18
33
  import { jsx } from "react/jsx-runtime";
19
34
  var description = "Normalize a topics-root catalog path";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/knowledges/realpath.tsx"],"sourcesContent":["import { JsonOutputOptionsSchema, RequiredCatalogPathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowRealpathCommand, type KnowRealpathCommandOptions } from \"../../features/knowledges/run-knowledges-command.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Normalize a topics-root catalog path\";\nexport const args = RequiredCatalogPathArgsSchema;\nexport const options = JsonOutputOptionsSchema;\n\ntype RealpathCommandProps = {\n readonly args: [string];\n readonly options: KnowRealpathCommandOptions;\n};\n\nexport default function RealpathCommand({ args, options }: RealpathCommandProps) {\n return <CommandRunner run={(output) => runKnowRealpathCommand(args[0], options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAcS;AAVF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU;AAOR,SAAR,gBAAiC,EAAE,MAAAA,OAAM,SAAAC,SAAQ,GAAyB;AAC/E,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,uBAAuBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AAC3F;","names":["args","options"]}
1
+ {"version":3,"sources":["../../../src/features/knowledges/handlers/realpath.ts","../../../src/commands/knowledges/realpath.tsx"],"sourcesContent":["import { formatJson, shouldPrintJson } from \"../../../shared/command-utils.js\";\nimport type { CommandOutput } from \"../../../shared/output/types.js\";\nimport { formatCatalogPathForDisplay, normalizeFilesystemCatalogPath } from \"../knowledges-input.js\";\nimport type { KnowRealpathCommandOptions } from \"../knowledges-options.js\";\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 = formatCatalogPathForDisplay(normalizeFilesystemCatalogPath(path));\n if (shouldPrintJson(options)) {\n output.raw(formatJson({ path: resolvedPath }));\n return;\n }\n\n output.raw(resolvedPath);\n}\n","import { JsonOutputOptionsSchema, RequiredCatalogPathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowRealpathCommand } from \"../../features/knowledges/handlers/realpath.js\";\nimport type { KnowRealpathCommandOptions } from \"../../features/knowledges/knowledges-options.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Normalize a topics-root catalog path\";\nexport const args = RequiredCatalogPathArgsSchema;\nexport const options = JsonOutputOptionsSchema;\n\ntype RealpathCommandProps = {\n readonly args: [string];\n readonly options: KnowRealpathCommandOptions;\n};\n\nexport default function RealpathCommand({ args, options }: RealpathCommandProps) {\n return <CommandRunner run={(output) => runKnowRealpathCommand(args[0], options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,eAAsB,uBACpB,MACAA,UACA,QACe;AACf,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AAEA,QAAM,eAAe,4BAA4B,+BAA+B,IAAI,CAAC;AACrF,MAAI,gBAAgBA,QAAO,GAAG;AAC5B,WAAO,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC,CAAC;AAC7C;AAAA,EACF;AAEA,SAAO,IAAI,YAAY;AACzB;;;ACNS;AAVF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU;AAOR,SAAR,gBAAiC,EAAE,MAAAC,OAAM,SAAAC,SAAQ,GAAyB;AAC/E,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,uBAAuBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AAC3F;","names":["options","args","options"]}
@@ -1,19 +1,45 @@
1
1
  import {
2
- runKnowSearchCommand
3
- } from "../../chunk-NODJM6SH.js";
4
- import "../../chunk-XQGLUQFM.js";
5
- import "../../chunk-SKK2XLRZ.js";
6
- import "../../chunk-CIZBVLN5.js";
2
+ KnowSearchResults
3
+ } from "../../chunk-VMTXY4KQ.js";
4
+ import {
5
+ createKnowledgesApi
6
+ } from "../../chunk-NLAANOBW.js";
7
+ import "../../chunk-AS7FIJWP.js";
8
+ import "../../chunk-N255PYL7.js";
9
+ import {
10
+ coerceLimit,
11
+ formatJson,
12
+ shouldPrintJson
13
+ } from "../../chunk-XQGLUQFM.js";
7
14
  import {
8
15
  LimitOptionsSchema,
9
16
  RequiredQueryArgsSchema
10
- } from "../../chunk-NGEWD4BW.js";
17
+ } from "../../chunk-25Q463MH.js";
11
18
  import {
12
19
  CommandRunner
13
- } from "../../chunk-MRXGD6TC.js";
14
- import "../../chunk-WDI43VPW.js";
20
+ } from "../../chunk-TIY4RTXC.js";
21
+ import "../../chunk-DCW4RKLC.js";
15
22
  import "../../chunk-PZ5AY32C.js";
16
23
 
24
+ // src/features/knowledges/handlers/search.ts
25
+ import { createElement } from "react";
26
+ async function runKnowSearchCommand(query, options2, output, dependencies) {
27
+ if (!query) {
28
+ throw new Error("Missing search query. Usage: cngkit knowledges search <query>");
29
+ }
30
+ const api = dependencies?.api ?? createKnowledgesApi(options2);
31
+ const response = await api.search(query, coerceLimit(options2.limit, 5));
32
+ if (shouldPrintJson(options2)) {
33
+ output.raw(formatJson(response.data));
34
+ return;
35
+ }
36
+ if (response.data.results.length > 0) {
37
+ output.component(createElement(KnowSearchResults, { results: response.data.results }));
38
+ return;
39
+ }
40
+ output.warning(`No results for "${query}".`);
41
+ }
42
+
17
43
  // src/commands/knowledges/search.tsx
18
44
  import { jsx } from "react/jsx-runtime";
19
45
  var description = "Search over Postgres-backed knowledges records";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/knowledges/search.tsx"],"sourcesContent":["import { RequiredQueryArgsSchema, LimitOptionsSchema } from \"../../cli/options.js\";\nimport { runKnowSearchCommand, type KnowSearchCommandOptions } from \"../../features/knowledges/run-knowledges-command.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Search over Postgres-backed knowledges records\";\nexport const args = RequiredQueryArgsSchema;\nexport const options = LimitOptionsSchema;\n\ntype SearchCommandProps = {\n readonly args: string[];\n readonly options: KnowSearchCommandOptions;\n};\n\nexport default function SearchCommand({ args, options }: SearchCommandProps) {\n return <CommandRunner run={(output) => runKnowSearchCommand(args.join(\" \"), options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAcS;AAVF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU;AAOR,SAAR,cAA+B,EAAE,MAAAA,OAAM,SAAAC,SAAQ,GAAuB;AAC3E,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,qBAAqBD,MAAK,KAAK,GAAG,GAAGC,UAAS,MAAM,GAAG;AAChG;","names":["args","options"]}
1
+ {"version":3,"sources":["../../../src/features/knowledges/handlers/search.ts","../../../src/commands/knowledges/search.tsx"],"sourcesContent":["import { createElement } from \"react\";\n\nimport { coerceLimit, formatJson, shouldPrintJson } from \"../../../shared/command-utils.js\";\nimport type { CommandOutput } from \"../../../shared/output/types.js\";\nimport { createKnowledgesApi, type KnowCommandDependencies } from \"../knowledges-api.js\";\nimport { KnowSearchResults } from \"../knowledges-output.js\";\nimport type { KnowSearchCommandOptions } from \"../knowledges-options.js\";\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 if (response.data.results.length > 0) {\n output.component(createElement(KnowSearchResults, { results: response.data.results }));\n return;\n }\n\n output.warning(`No results for \"${query}\".`);\n}\n","import { RequiredQueryArgsSchema, LimitOptionsSchema } from \"../../cli/options.js\";\nimport { runKnowSearchCommand } from \"../../features/knowledges/handlers/search.js\";\nimport type { KnowSearchCommandOptions } from \"../../features/knowledges/knowledges-options.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Search over Postgres-backed knowledges records\";\nexport const args = RequiredQueryArgsSchema;\nexport const options = LimitOptionsSchema;\n\ntype SearchCommandProps = {\n readonly args: string[];\n readonly options: KnowSearchCommandOptions;\n};\n\nexport default function SearchCommand({ args, options }: SearchCommandProps) {\n return <CommandRunner run={(output) => runKnowSearchCommand(args.join(\" \"), options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAQ9B,eAAsB,qBACpB,OACAA,UACA,QACA,cACe;AACf,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AAEA,QAAM,MAAM,cAAc,OAAO,oBAAoBA,QAAO;AAC5D,QAAM,WAAW,MAAM,IAAI,OAAO,OAAO,YAAYA,SAAQ,OAAO,CAAC,CAAC;AAEtE,MAAI,gBAAgBA,QAAO,GAAG;AAC5B,WAAO,IAAI,WAAW,SAAS,IAAI,CAAC;AACpC;AAAA,EACF;AAEA,MAAI,SAAS,KAAK,QAAQ,SAAS,GAAG;AACpC,WAAO,UAAU,cAAc,mBAAmB,EAAE,SAAS,SAAS,KAAK,QAAQ,CAAC,CAAC;AACrF;AAAA,EACF;AAEA,SAAO,QAAQ,mBAAmB,KAAK,IAAI;AAC7C;;;ACjBS;AAVF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU;AAOR,SAAR,cAA+B,EAAE,MAAAC,OAAM,SAAAC,SAAQ,GAAuB;AAC3E,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,qBAAqBD,MAAK,KAAK,GAAG,GAAGC,UAAS,MAAM,GAAG;AAChG;","names":["options","args","options"]}
@@ -1,19 +1,43 @@
1
1
  import {
2
- runKnowStatCommand
3
- } from "../../chunk-NODJM6SH.js";
4
- import "../../chunk-XQGLUQFM.js";
5
- import "../../chunk-SKK2XLRZ.js";
6
- import "../../chunk-CIZBVLN5.js";
2
+ formatFilesystemStat
3
+ } from "../../chunk-YALWTRIP.js";
4
+ import {
5
+ createKnowledgesApi
6
+ } from "../../chunk-NLAANOBW.js";
7
+ import {
8
+ normalizeFilesystemCatalogPath
9
+ } from "../../chunk-AS7FIJWP.js";
10
+ import "../../chunk-N255PYL7.js";
11
+ import {
12
+ formatJson,
13
+ shouldPrintJson
14
+ } from "../../chunk-XQGLUQFM.js";
7
15
  import {
8
16
  JsonOutputOptionsSchema,
9
17
  RequiredCatalogPathArgsSchema
10
- } from "../../chunk-NGEWD4BW.js";
18
+ } from "../../chunk-25Q463MH.js";
11
19
  import {
12
20
  CommandRunner
13
- } from "../../chunk-MRXGD6TC.js";
14
- import "../../chunk-WDI43VPW.js";
21
+ } from "../../chunk-TIY4RTXC.js";
22
+ import "../../chunk-DCW4RKLC.js";
15
23
  import "../../chunk-PZ5AY32C.js";
16
24
 
25
+ // src/features/knowledges/handlers/stat.ts
26
+ async function runKnowStatCommand(path, options2, output, dependencies) {
27
+ if (!path) {
28
+ throw new Error("Missing path. Usage: cngkit knowledges stat <path>");
29
+ }
30
+ const api = dependencies?.api ?? createKnowledgesApi(options2);
31
+ const response = await api.statPath({
32
+ path: normalizeFilesystemCatalogPath(path)
33
+ });
34
+ if (shouldPrintJson(options2)) {
35
+ output.raw(formatJson(response.data));
36
+ return;
37
+ }
38
+ output.raw(formatFilesystemStat(response.data));
39
+ }
40
+
17
41
  // src/commands/knowledges/stat.tsx
18
42
  import { jsx } from "react/jsx-runtime";
19
43
  var description = "Print remote catalog path metadata";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/knowledges/stat.tsx"],"sourcesContent":["import { JsonOutputOptionsSchema, RequiredCatalogPathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowStatCommand, type KnowStatCommandOptions } from \"../../features/knowledges/run-knowledges-command.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print remote catalog path metadata\";\nexport const args = RequiredCatalogPathArgsSchema;\nexport const options = JsonOutputOptionsSchema;\n\ntype StatCommandProps = {\n readonly args: [string];\n readonly options: KnowStatCommandOptions;\n};\n\nexport default function StatCommand({ args, options }: StatCommandProps) {\n return <CommandRunner run={(output) => runKnowStatCommand(args[0], options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAcS;AAVF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU;AAOR,SAAR,YAA6B,EAAE,MAAAA,OAAM,SAAAC,SAAQ,GAAqB;AACvE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,mBAAmBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AACvF;","names":["args","options"]}
1
+ {"version":3,"sources":["../../../src/features/knowledges/handlers/stat.ts","../../../src/commands/knowledges/stat.tsx"],"sourcesContent":["import { formatJson, shouldPrintJson } from \"../../../shared/command-utils.js\";\nimport type { CommandOutput } from \"../../../shared/output/types.js\";\nimport { formatFilesystemStat } from \"../format/filesystem-format.js\";\nimport { createKnowledgesApi, type KnowCommandDependencies } from \"../knowledges-api.js\";\nimport { normalizeFilesystemCatalogPath } from \"../knowledges-input.js\";\nimport type { KnowStatCommandOptions } from \"../knowledges-options.js\";\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","import { JsonOutputOptionsSchema, RequiredCatalogPathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowStatCommand } from \"../../features/knowledges/handlers/stat.js\";\nimport type { KnowStatCommandOptions } from \"../../features/knowledges/knowledges-options.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print remote catalog path metadata\";\nexport const args = RequiredCatalogPathArgsSchema;\nexport const options = JsonOutputOptionsSchema;\n\ntype StatCommandProps = {\n readonly args: [string];\n readonly options: KnowStatCommandOptions;\n};\n\nexport default function StatCommand({ args, options }: StatCommandProps) {\n return <CommandRunner run={(output) => runKnowStatCommand(args[0], options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOA,eAAsB,mBACpB,MACAA,UACA,QACA,cACe;AACf,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AAEA,QAAM,MAAM,cAAc,OAAO,oBAAoBA,QAAO;AAC5D,QAAM,WAAW,MAAM,IAAI,SAAS;AAAA,IAClC,MAAM,+BAA+B,IAAI;AAAA,EAC3C,CAAC;AAED,MAAI,gBAAgBA,QAAO,GAAG;AAC5B,WAAO,IAAI,WAAW,SAAS,IAAI,CAAC;AACpC;AAAA,EACF;AAEA,SAAO,IAAI,qBAAqB,SAAS,IAAI,CAAC;AAChD;;;ACbS;AAVF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU;AAOR,SAAR,YAA6B,EAAE,MAAAC,OAAM,SAAAC,SAAQ,GAAqB;AACvE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,mBAAmBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AACvF;","names":["options","args","options"]}
@@ -1,18 +1,36 @@
1
1
  import {
2
- runKnowStatusCommand
3
- } from "../../chunk-NODJM6SH.js";
4
- import "../../chunk-XQGLUQFM.js";
5
- import "../../chunk-SKK2XLRZ.js";
6
- import "../../chunk-CIZBVLN5.js";
2
+ KnowCatalogSummary
3
+ } from "../../chunk-VMTXY4KQ.js";
4
+ import {
5
+ createKnowledgesApi
6
+ } from "../../chunk-NLAANOBW.js";
7
+ import "../../chunk-AS7FIJWP.js";
8
+ import "../../chunk-N255PYL7.js";
9
+ import {
10
+ formatJson,
11
+ shouldPrintJson
12
+ } from "../../chunk-XQGLUQFM.js";
7
13
  import {
8
14
  JsonOutputOptionsSchema
9
- } from "../../chunk-NGEWD4BW.js";
15
+ } from "../../chunk-25Q463MH.js";
10
16
  import {
11
17
  CommandRunner
12
- } from "../../chunk-MRXGD6TC.js";
13
- import "../../chunk-WDI43VPW.js";
18
+ } from "../../chunk-TIY4RTXC.js";
19
+ import "../../chunk-DCW4RKLC.js";
14
20
  import "../../chunk-PZ5AY32C.js";
15
21
 
22
+ // src/features/knowledges/handlers/status.ts
23
+ import { createElement } from "react";
24
+ async function runKnowStatusCommand(options2, output, dependencies) {
25
+ const api = dependencies?.api ?? createKnowledgesApi(options2);
26
+ const response = await api.getCatalog();
27
+ if (shouldPrintJson(options2)) {
28
+ output.raw(formatJson(response.data));
29
+ return;
30
+ }
31
+ output.component(createElement(KnowCatalogSummary, { catalog: response.data }));
32
+ }
33
+
16
34
  // src/commands/knowledges/status.tsx
17
35
  import { jsx } from "react/jsx-runtime";
18
36
  var description = "Print remote catalog state";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/knowledges/status.tsx"],"sourcesContent":["import { JsonOutputOptionsSchema } from \"../../cli/options.js\";\nimport { runKnowStatusCommand, type KnowStatusCommandOptions } from \"../../features/knowledges/run-knowledges-command.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print remote catalog state\";\nexport const options = JsonOutputOptionsSchema;\n\ntype StatusCommandProps = {\n readonly options: KnowStatusCommandOptions;\n};\n\nexport default function StatusCommand({ options }: StatusCommandProps) {\n return <CommandRunner run={(output) => runKnowStatusCommand(options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAYS;AARF,IAAM,cAAc;AACpB,IAAM,UAAU;AAMR,SAAR,cAA+B,EAAE,SAAAA,SAAQ,GAAuB;AACrE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,qBAAqBA,UAAS,MAAM,GAAG;AAChF;","names":["options"]}
1
+ {"version":3,"sources":["../../../src/features/knowledges/handlers/status.ts","../../../src/commands/knowledges/status.tsx"],"sourcesContent":["import { createElement } from \"react\";\n\nimport { formatJson, shouldPrintJson } from \"../../../shared/command-utils.js\";\nimport type { CommandOutput } from \"../../../shared/output/types.js\";\nimport { createKnowledgesApi, type KnowCommandDependencies } from \"../knowledges-api.js\";\nimport { KnowCatalogSummary } from \"../knowledges-output.js\";\nimport type { KnowStatusCommandOptions } from \"../knowledges-options.js\";\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 output.component(createElement(KnowCatalogSummary, { catalog: response.data }));\n}\n","import { JsonOutputOptionsSchema } from \"../../cli/options.js\";\nimport { runKnowStatusCommand } from \"../../features/knowledges/handlers/status.js\";\nimport type { KnowStatusCommandOptions } from \"../../features/knowledges/knowledges-options.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print remote catalog state\";\nexport const options = JsonOutputOptionsSchema;\n\ntype StatusCommandProps = {\n readonly options: KnowStatusCommandOptions;\n};\n\nexport default function StatusCommand({ options }: StatusCommandProps) {\n return <CommandRunner run={(output) => runKnowStatusCommand(options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAQ9B,eAAsB,qBACpBA,UACA,QACA,cACe;AACf,QAAM,MAAM,cAAc,OAAO,oBAAoBA,QAAO;AAC5D,QAAM,WAAW,MAAM,IAAI,WAAW;AAEtC,MAAI,gBAAgBA,QAAO,GAAG;AAC5B,WAAO,IAAI,WAAW,SAAS,IAAI,CAAC;AACpC;AAAA,EACF;AAEA,SAAO,UAAU,cAAc,oBAAoB,EAAE,SAAS,SAAS,KAAK,CAAC,CAAC;AAChF;;;ACTS;AARF,IAAM,cAAc;AACpB,IAAM,UAAU;AAMR,SAAR,cAA+B,EAAE,SAAAC,SAAQ,GAAuB;AACrE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,qBAAqBA,UAAS,MAAM,GAAG;AAChF;","names":["options","options"]}
@@ -1,22 +1,44 @@
1
1
  import {
2
- runKnowTailCommand
3
- } from "../../chunk-NODJM6SH.js";
4
- import "../../chunk-XQGLUQFM.js";
5
- import "../../chunk-SKK2XLRZ.js";
6
- import "../../chunk-CIZBVLN5.js";
2
+ outputRawContent
3
+ } from "../../chunk-BRFWVQI4.js";
4
+ import {
5
+ createKnowledgesApi
6
+ } from "../../chunk-NLAANOBW.js";
7
+ import {
8
+ normalizeCatalogPath
9
+ } from "../../chunk-AS7FIJWP.js";
10
+ import "../../chunk-N255PYL7.js";
11
+ import {
12
+ coerceLimit
13
+ } from "../../chunk-XQGLUQFM.js";
7
14
  import {
8
15
  JsonOutputOptionsSchema,
9
16
  RequiredFilePathArgsSchema
10
- } from "../../chunk-NGEWD4BW.js";
17
+ } from "../../chunk-25Q463MH.js";
11
18
  import {
12
19
  CommandRunner
13
- } from "../../chunk-MRXGD6TC.js";
14
- import "../../chunk-WDI43VPW.js";
20
+ } from "../../chunk-TIY4RTXC.js";
21
+ import "../../chunk-DCW4RKLC.js";
15
22
  import "../../chunk-PZ5AY32C.js";
16
23
 
17
24
  // src/commands/knowledges/tail.tsx
18
25
  import { option } from "pastel";
19
26
  import { z } from "zod";
27
+
28
+ // src/features/knowledges/handlers/tail.ts
29
+ async function runKnowTailCommand(filePath, options2, output, dependencies) {
30
+ if (!filePath) {
31
+ throw new Error("Missing file_path. Usage: cngkit knowledges tail <file_path> -n 10");
32
+ }
33
+ const api = dependencies?.api ?? createKnowledgesApi(options2);
34
+ const response = await api.tail({
35
+ filePath: normalizeCatalogPath(filePath),
36
+ lines: coerceLimit(options2.lines, 10, 2e3)
37
+ });
38
+ outputRawContent(response.data, options2, output);
39
+ }
40
+
41
+ // src/commands/knowledges/tail.tsx
20
42
  import { jsx } from "react/jsx-runtime";
21
43
  var description = "Print the last lines of a remote catalog file";
22
44
  var args = RequiredFilePathArgsSchema;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/knowledges/tail.tsx"],"sourcesContent":["import { option } from \"pastel\";\nimport { z } from \"zod\";\n\nimport { JsonOutputOptionsSchema, RequiredFilePathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowTailCommand, type KnowTailCommandOptions } from \"../../features/knowledges/run-knowledges-command.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print the last lines of a remote catalog file\";\nexport const args = RequiredFilePathArgsSchema;\nexport const options = JsonOutputOptionsSchema.extend({\n lines: z\n .number()\n .optional()\n .describe(\n option({\n alias: \"n\",\n description: \"Number of lines\",\n valueDescription: \"n\",\n })\n ),\n});\n\ntype TailCommandProps = {\n readonly args: [string];\n readonly options: KnowTailCommandOptions;\n};\n\nexport default function TailCommand({ args, options }: TailCommandProps) {\n return <CommandRunner run={(output) => runKnowTailCommand(args[0], options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,SAAS;AA2BT;AArBF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU,wBAAwB,OAAO;AAAA,EACpD,OAAO,EACJ,OAAO,EACP,SAAS,EACT;AAAA,IACC,OAAO;AAAA,MACL,OAAO;AAAA,MACP,aAAa;AAAA,MACb,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AACJ,CAAC;AAOc,SAAR,YAA6B,EAAE,MAAAA,OAAM,SAAAC,SAAQ,GAAqB;AACvE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,mBAAmBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AACvF;","names":["args","options"]}
1
+ {"version":3,"sources":["../../../src/commands/knowledges/tail.tsx","../../../src/features/knowledges/handlers/tail.ts"],"sourcesContent":["import { option } from \"pastel\";\nimport { z } from \"zod\";\n\nimport { JsonOutputOptionsSchema, RequiredFilePathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowTailCommand } from \"../../features/knowledges/handlers/tail.js\";\nimport type { KnowTailCommandOptions } from \"../../features/knowledges/knowledges-options.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print the last lines of a remote catalog file\";\nexport const args = RequiredFilePathArgsSchema;\nexport const options = JsonOutputOptionsSchema.extend({\n lines: z\n .number()\n .optional()\n .describe(\n option({\n alias: \"n\",\n description: \"Number of lines\",\n valueDescription: \"n\",\n })\n ),\n});\n\ntype TailCommandProps = {\n readonly args: [string];\n readonly options: KnowTailCommandOptions;\n};\n\nexport default function TailCommand({ args, options }: TailCommandProps) {\n return <CommandRunner run={(output) => runKnowTailCommand(args[0], options, output)} />;\n}\n","import { coerceLimit } from \"../../../shared/command-utils.js\";\nimport type { CommandOutput } from \"../../../shared/output/types.js\";\nimport { createKnowledgesApi, type KnowCommandDependencies } from \"../knowledges-api.js\";\nimport { normalizeCatalogPath } from \"../knowledges-input.js\";\nimport type { KnowTailCommandOptions } from \"../knowledges-options.js\";\nimport { outputRawContent } from \"../format/content-format.js\";\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,SAAS;;;ACMlB,eAAsB,mBACpB,UACAA,UACA,QACA,cACe;AACf,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,oEAAoE;AAAA,EACtF;AAEA,QAAM,MAAM,cAAc,OAAO,oBAAoBA,QAAO;AAC5D,QAAM,WAAW,MAAM,IAAI,KAAK;AAAA,IAC9B,UAAU,qBAAqB,QAAQ;AAAA,IACvC,OAAO,YAAYA,SAAQ,OAAO,IAAI,GAAI;AAAA,EAC5C,CAAC;AAED,mBAAiB,SAAS,MAAMA,UAAS,MAAM;AACjD;;;ADKS;AArBF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU,wBAAwB,OAAO;AAAA,EACpD,OAAO,EACJ,OAAO,EACP,SAAS,EACT;AAAA,IACC,OAAO;AAAA,MACL,OAAO;AAAA,MACP,aAAa;AAAA,MACb,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AACJ,CAAC;AAOc,SAAR,YAA6B,EAAE,MAAAC,OAAM,SAAAC,SAAQ,GAAqB;AACvE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,mBAAmBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AACvF;","names":["options","args","options"]}
@@ -1,22 +1,52 @@
1
1
  import {
2
- runKnowTreeCommand
3
- } from "../../chunk-NODJM6SH.js";
4
- import "../../chunk-XQGLUQFM.js";
5
- import "../../chunk-SKK2XLRZ.js";
6
- import "../../chunk-CIZBVLN5.js";
2
+ formatFilesystemTree
3
+ } from "../../chunk-YALWTRIP.js";
4
+ import {
5
+ createKnowledgesApi
6
+ } from "../../chunk-NLAANOBW.js";
7
+ import {
8
+ normalizeFilesystemCatalogPath
9
+ } from "../../chunk-AS7FIJWP.js";
10
+ import "../../chunk-N255PYL7.js";
11
+ import {
12
+ coerceLimit,
13
+ formatJson,
14
+ shouldPrintJson
15
+ } from "../../chunk-XQGLUQFM.js";
7
16
  import {
8
17
  JsonOutputOptionsSchema,
9
18
  OptionalPathArgsSchema
10
- } from "../../chunk-NGEWD4BW.js";
19
+ } from "../../chunk-25Q463MH.js";
11
20
  import {
12
21
  CommandRunner
13
- } from "../../chunk-MRXGD6TC.js";
14
- import "../../chunk-WDI43VPW.js";
22
+ } from "../../chunk-TIY4RTXC.js";
23
+ import "../../chunk-DCW4RKLC.js";
15
24
  import "../../chunk-PZ5AY32C.js";
16
25
 
17
26
  // src/commands/knowledges/tree.tsx
18
27
  import { option } from "pastel";
19
28
  import { z } from "zod";
29
+
30
+ // src/features/knowledges/handlers/tree.ts
31
+ async function runKnowTreeCommand(path, options2, output, dependencies) {
32
+ const api = dependencies?.api ?? createKnowledgesApi(options2);
33
+ const response = await api.tree({
34
+ path: normalizeFilesystemCatalogPath(path ?? "/"),
35
+ depth: coerceLimit(options2.depth, 3, 8),
36
+ limit: coerceLimit(options2.limit, 500, 2e3)
37
+ });
38
+ if (shouldPrintJson(options2)) {
39
+ output.raw(formatJson(response.data));
40
+ return;
41
+ }
42
+ const lines = formatFilesystemTree(response.data.path, response.data.entries);
43
+ output.raw(lines.join("\n"));
44
+ if (response.data.truncated) {
45
+ output.warning(`[truncated: ${response.data.total_entries} total entries]`);
46
+ }
47
+ }
48
+
49
+ // src/commands/knowledges/tree.tsx
20
50
  import { jsx } from "react/jsx-runtime";
21
51
  var description = "Print a remote catalog directory tree";
22
52
  var args = OptionalPathArgsSchema;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/knowledges/tree.tsx"],"sourcesContent":["import { option } from \"pastel\";\nimport { z } from \"zod\";\n\nimport { JsonOutputOptionsSchema, OptionalPathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowTreeCommand, type KnowTreeCommandOptions } from \"../../features/knowledges/run-knowledges-command.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print a remote catalog directory tree\";\nexport const args = OptionalPathArgsSchema;\nexport const options = JsonOutputOptionsSchema.extend({\n depth: z\n .number()\n .optional()\n .describe(\n option({\n description: \"Maximum tree depth\",\n valueDescription: \"n\",\n })\n ),\n limit: z\n .number()\n .optional()\n .describe(\n option({\n description: \"Maximum entries\",\n valueDescription: \"n\",\n })\n ),\n});\n\ntype TreeCommandProps = {\n readonly args: [string?];\n readonly options: KnowTreeCommandOptions;\n};\n\nexport default function TreeCommand({ args, options }: TreeCommandProps) {\n return <CommandRunner run={(output) => runKnowTreeCommand(args[0], options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,SAAS;AAmCT;AA7BF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU,wBAAwB,OAAO;AAAA,EACpD,OAAO,EACJ,OAAO,EACP,SAAS,EACT;AAAA,IACC,OAAO;AAAA,MACL,aAAa;AAAA,MACb,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AAAA,EACF,OAAO,EACJ,OAAO,EACP,SAAS,EACT;AAAA,IACC,OAAO;AAAA,MACL,aAAa;AAAA,MACb,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AACJ,CAAC;AAOc,SAAR,YAA6B,EAAE,MAAAA,OAAM,SAAAC,SAAQ,GAAqB;AACvE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,mBAAmBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AACvF;","names":["args","options"]}
1
+ {"version":3,"sources":["../../../src/commands/knowledges/tree.tsx","../../../src/features/knowledges/handlers/tree.ts"],"sourcesContent":["import { option } from \"pastel\";\nimport { z } from \"zod\";\n\nimport { JsonOutputOptionsSchema, OptionalPathArgsSchema } from \"../../cli/options.js\";\nimport { runKnowTreeCommand } from \"../../features/knowledges/handlers/tree.js\";\nimport type { KnowTreeCommandOptions } from \"../../features/knowledges/knowledges-options.js\";\nimport { CommandRunner } from \"../../cli/command-runner.js\";\n\nexport const description = \"Print a remote catalog directory tree\";\nexport const args = OptionalPathArgsSchema;\nexport const options = JsonOutputOptionsSchema.extend({\n depth: z\n .number()\n .optional()\n .describe(\n option({\n description: \"Maximum tree depth\",\n valueDescription: \"n\",\n })\n ),\n limit: z\n .number()\n .optional()\n .describe(\n option({\n description: \"Maximum entries\",\n valueDescription: \"n\",\n })\n ),\n});\n\ntype TreeCommandProps = {\n readonly args: [string?];\n readonly options: KnowTreeCommandOptions;\n};\n\nexport default function TreeCommand({ args, options }: TreeCommandProps) {\n return <CommandRunner run={(output) => runKnowTreeCommand(args[0], options, output)} />;\n}\n","import { coerceLimit, formatJson, shouldPrintJson } from \"../../../shared/command-utils.js\";\nimport type { CommandOutput } from \"../../../shared/output/types.js\";\nimport { formatFilesystemTree } from \"../format/filesystem-format.js\";\nimport { createKnowledgesApi, type KnowCommandDependencies } from \"../knowledges-api.js\";\nimport { normalizeFilesystemCatalogPath } from \"../knowledges-input.js\";\nimport type { KnowTreeCommandOptions } from \"../knowledges-options.js\";\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,SAAS;;;ACMlB,eAAsB,mBACpB,MACAA,UACA,QACA,cACe;AACf,QAAM,MAAM,cAAc,OAAO,oBAAoBA,QAAO;AAC5D,QAAM,WAAW,MAAM,IAAI,KAAK;AAAA,IAC9B,MAAM,+BAA+B,QAAQ,GAAG;AAAA,IAChD,OAAO,YAAYA,SAAQ,OAAO,GAAG,CAAC;AAAA,IACtC,OAAO,YAAYA,SAAQ,OAAO,KAAK,GAAI;AAAA,EAC7C,CAAC;AAED,MAAI,gBAAgBA,QAAO,GAAG;AAC5B,WAAO,IAAI,WAAW,SAAS,IAAI,CAAC;AACpC;AAAA,EACF;AAEA,QAAM,QAAQ,qBAAqB,SAAS,KAAK,MAAM,SAAS,KAAK,OAAO;AAC5E,SAAO,IAAI,MAAM,KAAK,IAAI,CAAC;AAE3B,MAAI,SAAS,KAAK,WAAW;AAC3B,WAAO,QAAQ,eAAe,SAAS,KAAK,aAAa,iBAAiB;AAAA,EAC5E;AACF;;;ADMS;AA7BF,IAAM,cAAc;AACpB,IAAM,OAAO;AACb,IAAM,UAAU,wBAAwB,OAAO;AAAA,EACpD,OAAO,EACJ,OAAO,EACP,SAAS,EACT;AAAA,IACC,OAAO;AAAA,MACL,aAAa;AAAA,MACb,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AAAA,EACF,OAAO,EACJ,OAAO,EACP,SAAS,EACT;AAAA,IACC,OAAO;AAAA,MACL,aAAa;AAAA,MACb,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AACJ,CAAC;AAOc,SAAR,YAA6B,EAAE,MAAAC,OAAM,SAAAC,SAAQ,GAAqB;AACvE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,mBAAmBD,MAAK,CAAC,GAAGC,UAAS,MAAM,GAAG;AACvF;","names":["options","args","options"]}
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  GlobalOptionsSchema
3
- } from "../chunk-NGEWD4BW.js";
3
+ } from "../chunk-25Q463MH.js";
4
4
  import {
5
5
  CommandRunner
6
- } from "../chunk-MRXGD6TC.js";
6
+ } from "../chunk-TIY4RTXC.js";
7
7
  import {
8
8
  resolveApiBaseUrl
9
- } from "../chunk-WDI43VPW.js";
9
+ } from "../chunk-DCW4RKLC.js";
10
10
  import "../chunk-PZ5AY32C.js";
11
11
 
12
12
  // src/shared/browser.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/shared/browser.ts","../../src/features/login/run-login-command.ts","../../src/commands/login.tsx"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport process from \"node:process\";\n\nexport async function openBrowserUrl(url: string): Promise<boolean> {\n const command = browserOpenCommand(url);\n\n return await new Promise<boolean>((resolve, reject) => {\n const childProcess = spawn(command.command, command.args, {\n detached: true,\n stdio: \"ignore\",\n });\n\n childProcess.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") {\n resolve(false);\n return;\n }\n\n reject(error);\n });\n childProcess.on(\"spawn\", () => {\n childProcess.unref();\n resolve(true);\n });\n });\n}\n\nfunction browserOpenCommand(url: string): { command: string; args: string[] } {\n if (process.platform === \"darwin\") {\n return { command: \"open\", args: [url] };\n }\n\n if (process.platform === \"win32\") {\n return { command: \"cmd\", args: [\"/c\", \"start\", \"\", url] };\n }\n\n return { command: \"xdg-open\", args: [url] };\n}\n","import { openBrowserUrl } from \"../../shared/browser.js\";\nimport { resolveApiBaseUrl, type GlobalCommandOptions } from \"../../shared/config.js\";\nimport type { CommandOutput } from \"../../shared/output.js\";\n\nexport type LoginCommandOptions = GlobalCommandOptions;\n\nexport async function runLoginCommand(\n options: LoginCommandOptions,\n output: CommandOutput\n): Promise<void> {\n const loginUrl = new URL(\"/login\", resolveApiBaseUrl(options));\n const loginUrlString = loginUrl.toString();\n output.success(`Opening ${loginUrlString}`);\n\n const didOpenBrowser = await openBrowserUrl(loginUrlString);\n if (!didOpenBrowser) {\n output.warning(`No browser opener found. Open this URL manually: ${loginUrlString}`);\n }\n}\n","import { GlobalOptionsSchema } from \"../cli/options.js\";\nimport { runLoginCommand, type LoginCommandOptions } from \"../features/login/run-login-command.js\";\nimport { CommandRunner } from \"../cli/command-runner.js\";\n\nexport const description = \"Open browser login\";\nexport const options = GlobalOptionsSchema;\n\ntype LoginCommandProps = {\n readonly options: LoginCommandOptions;\n};\n\nexport default function LoginCommand({ options }: LoginCommandProps) {\n return <CommandRunner run={(output) => runLoginCommand(options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,OAAO,aAAa;AAEpB,eAAsB,eAAe,KAA+B;AAClE,QAAM,UAAU,mBAAmB,GAAG;AAEtC,SAAO,MAAM,IAAI,QAAiB,CAAC,SAAS,WAAW;AACrD,UAAM,eAAe,MAAM,QAAQ,SAAS,QAAQ,MAAM;AAAA,MACxD,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAED,iBAAa,GAAG,SAAS,CAAC,UAAiC;AACzD,UAAI,MAAM,SAAS,UAAU;AAC3B,gBAAQ,KAAK;AACb;AAAA,MACF;AAEA,aAAO,KAAK;AAAA,IACd,CAAC;AACD,iBAAa,GAAG,SAAS,MAAM;AAC7B,mBAAa,MAAM;AACnB,cAAQ,IAAI;AAAA,IACd,CAAC;AAAA,EACH,CAAC;AACH;AAEA,SAAS,mBAAmB,KAAkD;AAC5E,MAAI,QAAQ,aAAa,UAAU;AACjC,WAAO,EAAE,SAAS,QAAQ,MAAM,CAAC,GAAG,EAAE;AAAA,EACxC;AAEA,MAAI,QAAQ,aAAa,SAAS;AAChC,WAAO,EAAE,SAAS,OAAO,MAAM,CAAC,MAAM,SAAS,IAAI,GAAG,EAAE;AAAA,EAC1D;AAEA,SAAO,EAAE,SAAS,YAAY,MAAM,CAAC,GAAG,EAAE;AAC5C;;;AC/BA,eAAsB,gBACpBA,UACA,QACe;AACf,QAAM,WAAW,IAAI,IAAI,UAAU,kBAAkBA,QAAO,CAAC;AAC7D,QAAM,iBAAiB,SAAS,SAAS;AACzC,SAAO,QAAQ,WAAW,cAAc,EAAE;AAE1C,QAAM,iBAAiB,MAAM,eAAe,cAAc;AAC1D,MAAI,CAAC,gBAAgB;AACnB,WAAO,QAAQ,oDAAoD,cAAc,EAAE;AAAA,EACrF;AACF;;;ACNS;AARF,IAAM,cAAc;AACpB,IAAM,UAAU;AAMR,SAAR,aAA8B,EAAE,SAAAC,SAAQ,GAAsB;AACnE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,gBAAgBA,UAAS,MAAM,GAAG;AAC3E;","names":["options","options"]}
1
+ {"version":3,"sources":["../../src/shared/browser.ts","../../src/features/login/run-login-command.ts","../../src/commands/login.tsx"],"sourcesContent":["import { spawn } from \"node:child_process\";\nimport process from \"node:process\";\n\nexport async function openBrowserUrl(url: string): Promise<boolean> {\n const command = browserOpenCommand(url);\n\n return await new Promise<boolean>((resolve, reject) => {\n const childProcess = spawn(command.command, command.args, {\n detached: true,\n stdio: \"ignore\",\n });\n\n childProcess.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") {\n resolve(false);\n return;\n }\n\n reject(error);\n });\n childProcess.on(\"spawn\", () => {\n childProcess.unref();\n resolve(true);\n });\n });\n}\n\nfunction browserOpenCommand(url: string): { command: string; args: string[] } {\n if (process.platform === \"darwin\") {\n return { command: \"open\", args: [url] };\n }\n\n if (process.platform === \"win32\") {\n return { command: \"cmd\", args: [\"/c\", \"start\", \"\", url] };\n }\n\n return { command: \"xdg-open\", args: [url] };\n}\n","import { openBrowserUrl } from \"../../shared/browser.js\";\nimport { resolveApiBaseUrl, type GlobalCommandOptions } from \"../../shared/config.js\";\nimport type { CommandOutput } from \"../../shared/output/types.js\";\n\nexport type LoginCommandOptions = GlobalCommandOptions;\n\nexport async function runLoginCommand(\n options: LoginCommandOptions,\n output: CommandOutput\n): Promise<void> {\n const loginUrl = new URL(\"/login\", resolveApiBaseUrl(options));\n const loginUrlString = loginUrl.toString();\n output.success(`Opening ${loginUrlString}`);\n\n const didOpenBrowser = await openBrowserUrl(loginUrlString);\n if (!didOpenBrowser) {\n output.warning(`No browser opener found. Open this URL manually: ${loginUrlString}`);\n }\n}\n","import { GlobalOptionsSchema } from \"../cli/options.js\";\nimport { runLoginCommand, type LoginCommandOptions } from \"../features/login/run-login-command.js\";\nimport { CommandRunner } from \"../cli/command-runner.js\";\n\nexport const description = \"Open browser login\";\nexport const options = GlobalOptionsSchema;\n\ntype LoginCommandProps = {\n readonly options: LoginCommandOptions;\n};\n\nexport default function LoginCommand({ options }: LoginCommandProps) {\n return <CommandRunner run={(output) => runLoginCommand(options, output)} />;\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,OAAO,aAAa;AAEpB,eAAsB,eAAe,KAA+B;AAClE,QAAM,UAAU,mBAAmB,GAAG;AAEtC,SAAO,MAAM,IAAI,QAAiB,CAAC,SAAS,WAAW;AACrD,UAAM,eAAe,MAAM,QAAQ,SAAS,QAAQ,MAAM;AAAA,MACxD,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAED,iBAAa,GAAG,SAAS,CAAC,UAAiC;AACzD,UAAI,MAAM,SAAS,UAAU;AAC3B,gBAAQ,KAAK;AACb;AAAA,MACF;AAEA,aAAO,KAAK;AAAA,IACd,CAAC;AACD,iBAAa,GAAG,SAAS,MAAM;AAC7B,mBAAa,MAAM;AACnB,cAAQ,IAAI;AAAA,IACd,CAAC;AAAA,EACH,CAAC;AACH;AAEA,SAAS,mBAAmB,KAAkD;AAC5E,MAAI,QAAQ,aAAa,UAAU;AACjC,WAAO,EAAE,SAAS,QAAQ,MAAM,CAAC,GAAG,EAAE;AAAA,EACxC;AAEA,MAAI,QAAQ,aAAa,SAAS;AAChC,WAAO,EAAE,SAAS,OAAO,MAAM,CAAC,MAAM,SAAS,IAAI,GAAG,EAAE;AAAA,EAC1D;AAEA,SAAO,EAAE,SAAS,YAAY,MAAM,CAAC,GAAG,EAAE;AAC5C;;;AC/BA,eAAsB,gBACpBA,UACA,QACe;AACf,QAAM,WAAW,IAAI,IAAI,UAAU,kBAAkBA,QAAO,CAAC;AAC7D,QAAM,iBAAiB,SAAS,SAAS;AACzC,SAAO,QAAQ,WAAW,cAAc,EAAE;AAE1C,QAAM,iBAAiB,MAAM,eAAe,cAAc;AAC1D,MAAI,CAAC,gBAAgB;AACnB,WAAO,QAAQ,oDAAoD,cAAc,EAAE;AAAA,EACrF;AACF;;;ACNS;AARF,IAAM,cAAc;AACpB,IAAM,UAAU;AAMR,SAAR,aAA8B,EAAE,SAAAC,SAAQ,GAAsB;AACnE,SAAO,oBAAC,iBAAc,KAAK,CAAC,WAAW,gBAAgBA,UAAS,MAAM,GAAG;AAC3E;","names":["options","options"]}
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  GlobalOptionsSchema,
3
3
  OptionalPathArgsSchema
4
- } from "../chunk-NGEWD4BW.js";
4
+ } from "../chunk-25Q463MH.js";
5
5
  import {
6
6
  CommandRunner
7
- } from "../chunk-MRXGD6TC.js";
8
- import "../chunk-WDI43VPW.js";
7
+ } from "../chunk-TIY4RTXC.js";
8
+ import "../chunk-DCW4RKLC.js";
9
9
  import "../chunk-PZ5AY32C.js";
10
10
 
11
11
  // src/commands/scrub.tsx
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/scrub.tsx","../../src/features/scrub/run-scrub-command.ts","../../src/features/scrub/masker.ts","../../src/features/scrub/scrub-output.tsx","../../src/features/scrub/trufflehog.ts","../../src/features/scrub/findings.ts"],"sourcesContent":["import { option } from \"pastel\";\nimport { z } from \"zod\";\n\nimport { GlobalOptionsSchema, OptionalPathArgsSchema } from \"../cli/options.js\";\nimport { runScrubCommand, type ScrubCommandOptions } from \"../features/scrub/run-scrub-command.js\";\nimport { CommandRunner } from \"../cli/command-runner.js\";\n\nexport const description = \"Scan for secrets with TruffleHog and optionally mask them inline\";\nexport const args = OptionalPathArgsSchema;\nexport const options = GlobalOptionsSchema.extend({\n mask: z\n .boolean()\n .optional()\n .describe(\n option({\n description: \"Compatibility alias for inline scrubbing; --yes is still required\",\n })\n ),\n yes: z\n .boolean()\n .optional()\n .describe(\n option({\n description: \"Confirm and run inline scrubbing\",\n })\n ),\n});\n\ntype ScrubCommandProps = {\n readonly args: z.infer<typeof args>;\n readonly options: ScrubCommandOptions;\n};\n\nexport default function ScrubCommand({ args, options }: ScrubCommandProps) {\n return <CommandRunner run={(output) => runScrubCommand(args[0], options, output)} />;\n}\n","import process from \"node:process\";\nimport { createElement } from \"react\";\n\nimport type { GlobalCommandOptions } from \"../../shared/config.js\";\nimport type { CommandOutput } from \"../../shared/output.js\";\nimport type { ScrubFinding } from \"./findings.js\";\nimport { scrubFindingsInline } from \"./masker.js\";\nimport { ScrubFindingsReport } from \"./scrub-output.js\";\nimport { scanFilesystemWithTruffleHog } from \"./trufflehog.js\";\n\nexport type ScrubCommandOptions = GlobalCommandOptions & {\n mask?: boolean;\n yes?: boolean;\n};\n\nexport type ScrubCommandDependencies = {\n scanFilesystem(targetPath: string): Promise<ScrubFinding[]>;\n};\n\nexport async function runScrubCommand(\n targetPath: string | undefined,\n options: ScrubCommandOptions,\n output: CommandOutput,\n dependencies?: ScrubCommandDependencies\n): Promise<void> {\n const scrubTargetPath = targetPath ?? \".\";\n const scanFilesystem =\n dependencies?.scanFilesystem ??\n ((scanTargetPath: string) =>\n scanFilesystemWithTruffleHog(scanTargetPath, {\n cwd: process.cwd(),\n }));\n const findings = await scanFilesystem(scrubTargetPath);\n\n if (findings.length === 0) {\n output.success(\"No secrets found.\");\n return;\n }\n\n output.component(createElement(ScrubFindingsReport, { findings }));\n\n if (!options.yes) {\n if (options.mask) {\n throw new Error(\"Inline scrubbing rewrites files. Re-run with --yes to continue.\");\n }\n\n output.warning(\"Report only. Re-run with --yes to scrub files inline.\");\n return;\n }\n\n const result = await scrubFindingsInline(scrubTargetPath, findings);\n output.success(\n `Masked ${result.replacements} secret${result.replacements === 1 ? \"\" : \"s\"} in ${\n result.filesChanged\n } file${result.filesChanged === 1 ? \"\" : \"s\"}.`\n );\n\n if (result.skippedFindings > 0) {\n output.warning(`Skipped ${result.skippedFindings} finding(s) outside the scrub root.`);\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport type { ScrubFinding } from \"./findings.js\";\n\nexport type InlineScrubResult = {\n filesChanged: number;\n replacements: number;\n skippedFindings: number;\n};\n\nexport async function scrubFindingsInline(\n targetPath: string,\n findings: ScrubFinding[]\n): Promise<InlineScrubResult> {\n const target = await resolveScrubTarget(targetPath);\n const findingsByFile = groupFindingsBySafePath(target, findings);\n let filesChanged = 0;\n let replacements = 0;\n\n for (const [absolutePath, fileFindings] of findingsByFile.safeFindingsByPath) {\n const originalContent = await fs.readFile(absolutePath, \"utf8\");\n let scrubbedContent = originalContent;\n let fileReplacements = 0;\n\n for (const finding of fileFindings) {\n const placeholder = formatSecretPlaceholder(finding);\n const nextContent = scrubbedContent.split(finding.rawSecret).join(placeholder);\n if (nextContent !== scrubbedContent) {\n fileReplacements += countOccurrences(scrubbedContent, finding.rawSecret);\n scrubbedContent = nextContent;\n }\n }\n\n if (scrubbedContent !== originalContent) {\n await fs.writeFile(absolutePath, scrubbedContent);\n filesChanged += 1;\n replacements += fileReplacements;\n }\n }\n\n return {\n filesChanged,\n replacements,\n skippedFindings: findingsByFile.skippedFindings,\n };\n}\n\nexport function formatSecretPlaceholder(finding: ScrubFinding): string {\n return `[CNGKIT_SECRET:${sanitizePlaceholderPart(finding.detectorName)}:${\n finding.verified ? \"verified\" : \"unverified\"\n }]`;\n}\n\nfunction groupFindingsBySafePath(\n target: ScrubTarget,\n findings: ScrubFinding[]\n): {\n safeFindingsByPath: Map<string, ScrubFinding[]>;\n skippedFindings: number;\n} {\n const safeFindingsByPath = new Map<string, ScrubFinding[]>();\n let skippedFindings = 0;\n\n for (const finding of findings) {\n const absolutePath = resolveSafeFindingPath(target, finding.filePath);\n if (!absolutePath) {\n skippedFindings += 1;\n continue;\n }\n\n const fileFindings = safeFindingsByPath.get(absolutePath) ?? [];\n fileFindings.push(finding);\n safeFindingsByPath.set(absolutePath, fileFindings);\n }\n\n return { safeFindingsByPath, skippedFindings };\n}\n\ntype ScrubTarget = {\n rootDir: string;\n allowedFilePath?: string;\n};\n\nasync function resolveScrubTarget(targetPath: string): Promise<ScrubTarget> {\n const absoluteTargetPath = path.resolve(targetPath);\n const stat = await fs.stat(absoluteTargetPath);\n\n if (stat.isFile()) {\n return {\n rootDir: path.dirname(absoluteTargetPath),\n allowedFilePath: absoluteTargetPath,\n };\n }\n\n return {\n rootDir: absoluteTargetPath,\n };\n}\n\nfunction resolveSafeFindingPath(\n target: ScrubTarget,\n findingFilePath: string\n): string | undefined {\n const absolutePath = path.isAbsolute(findingFilePath)\n ? path.resolve(findingFilePath)\n : path.resolve(target.rootDir, findingFilePath);\n\n if (target.allowedFilePath) {\n return absolutePath === target.allowedFilePath ? absolutePath : undefined;\n }\n\n const normalizedRoot = `${path.resolve(target.rootDir)}${path.sep}`;\n\n if (absolutePath === path.resolve(target.rootDir) || absolutePath.startsWith(normalizedRoot)) {\n return absolutePath;\n }\n\n return undefined;\n}\n\nfunction countOccurrences(value: string, search: string): number {\n if (!search) {\n return 0;\n }\n\n return value.split(search).length - 1;\n}\n\nfunction sanitizePlaceholderPart(value: string): string {\n return value.replace(/[^A-Za-z0-9_-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"Unknown\";\n}\n","import { Box, Text } from \"ink\";\n\nimport type { ScrubFinding } from \"./findings.js\";\n\nexport function ScrubFindingsReport({ findings }: { readonly findings: readonly ScrubFinding[] }) {\n return (\n <Box flexDirection=\"column\">\n <Text color=\"yellow\" bold>\n Found {findings.length} possible secret{findings.length === 1 ? \"\" : \"s\"}:\n </Text>\n {findings.map((finding, index) => {\n const location = finding.line ? `${finding.filePath}:${finding.line}` : finding.filePath;\n const status = finding.verified ? \"verified\" : \"unverified\";\n\n return (\n <Text key={`${finding.filePath}-${finding.line ?? 0}-${finding.detectorName}-${index}`}>\n <Text color=\"cyan\">- </Text>\n <Text>{location}</Text>\n <Text dimColor> {finding.detectorName}</Text>\n <Text color={finding.verified ? \"green\" : \"yellow\"}> {status}</Text>\n </Text>\n );\n })}\n </Box>\n );\n}\n","import { spawn } from \"node:child_process\";\nimport path from \"node:path\";\n\nimport { parseTruffleHogJsonLines, type ScrubFinding } from \"./findings.js\";\n\nexport type TruffleHogScanOptions = {\n cwd: string;\n};\n\nexport async function scanFilesystemWithTruffleHog(\n targetPath: string,\n options: TruffleHogScanOptions\n): Promise<ScrubFinding[]> {\n const absoluteTargetPath = path.resolve(options.cwd, targetPath);\n const { stdout } = await runTruffleHog([\n \"filesystem\",\n absoluteTargetPath,\n \"--json\",\n \"--no-update\",\n \"--force-skip-binaries\",\n \"--force-skip-archives\",\n ]);\n\n return parseTruffleHogJsonLines(stdout);\n}\n\nfunction runTruffleHog(args: string[]): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const child = spawn(\"trufflehog\", args, {\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n const stdoutChunks: Buffer[] = [];\n const stderrChunks: Buffer[] = [];\n\n child.stdout.on(\"data\", (chunk: Buffer) => {\n stdoutChunks.push(chunk);\n });\n child.stderr.on(\"data\", (chunk: Buffer) => {\n stderrChunks.push(chunk);\n });\n child.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") {\n reject(\n new Error(\n \"TruffleHog is not installed. Install it with `brew install trufflehog` or see https://github.com/trufflesecurity/trufflehog.\"\n )\n );\n return;\n }\n\n reject(error);\n });\n child.on(\"close\", (exitCode) => {\n const stdout = Buffer.concat(stdoutChunks).toString(\"utf8\");\n const stderr = Buffer.concat(stderrChunks).toString(\"utf8\");\n\n if (exitCode && exitCode !== 0) {\n reject(new Error(`TruffleHog scan failed with exit code ${exitCode}: ${stderr.trim()}`));\n return;\n }\n\n resolve({ stdout, stderr });\n });\n });\n}\n","export type ScrubFinding = {\n detectorName: string;\n filePath: string;\n line?: number;\n rawSecret: string;\n redactedSecret: string;\n verified: boolean;\n};\n\ntype JsonRecord = Record<string, unknown>;\n\nexport function parseTruffleHogJsonLines(output: string): ScrubFinding[] {\n const findings: ScrubFinding[] = [];\n\n for (const line of output.split(/\\r?\\n/)) {\n const trimmedLine = line.trim();\n if (!trimmedLine.startsWith(\"{\")) {\n continue;\n }\n\n const parsedLine = parseJsonRecord(trimmedLine);\n if (!parsedLine) {\n continue;\n }\n\n const finding = parseTruffleHogFinding(parsedLine);\n if (finding) {\n findings.push(finding);\n }\n }\n\n return findings;\n}\n\nfunction parseTruffleHogFinding(finding: JsonRecord): ScrubFinding | undefined {\n const rawSecret = readString(finding.Raw) || readString(finding.RawV2);\n const filePath = readFilesystemFilePath(finding);\n\n if (!rawSecret || !filePath) {\n return undefined;\n }\n\n return {\n detectorName: readString(finding.DetectorName) || \"Unknown\",\n filePath,\n line: readFilesystemLine(finding),\n rawSecret,\n redactedSecret: readString(finding.Redacted) || \"\",\n verified: finding.Verified === true,\n };\n}\n\nfunction readFilesystemFilePath(finding: JsonRecord): string | undefined {\n const filesystem = readFilesystemMetadata(finding);\n if (!filesystem) {\n return undefined;\n }\n\n return readString(filesystem.file) || readString(filesystem.path);\n}\n\nfunction readFilesystemLine(finding: JsonRecord): number | undefined {\n const filesystem = readFilesystemMetadata(finding);\n if (!filesystem) {\n return undefined;\n }\n\n return typeof filesystem.line === \"number\" ? filesystem.line : undefined;\n}\n\nfunction readFilesystemMetadata(finding: JsonRecord): JsonRecord | undefined {\n const sourceMetadata = readRecord(finding.SourceMetadata);\n const data = readRecord(sourceMetadata?.Data);\n return readRecord(data?.Filesystem);\n}\n\nfunction parseJsonRecord(line: string): JsonRecord | undefined {\n try {\n return readRecord(JSON.parse(line));\n } catch {\n return undefined;\n }\n}\n\nfunction isJsonRecord(value: unknown): value is JsonRecord {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction readRecord(value: unknown): JsonRecord | undefined {\n return isJsonRecord(value) ? value : undefined;\n}\n\nfunction readString(value: unknown): string | undefined {\n return typeof value === \"string\" && value.length > 0 ? value : undefined;\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,SAAS;;;ACDlB,OAAO,aAAa;AACpB,SAAS,qBAAqB;;;ACD9B,OAAO,QAAQ;AACf,OAAO,UAAU;AAUjB,eAAsB,oBACpB,YACA,UAC4B;AAC5B,QAAM,SAAS,MAAM,mBAAmB,UAAU;AAClD,QAAM,iBAAiB,wBAAwB,QAAQ,QAAQ;AAC/D,MAAI,eAAe;AACnB,MAAI,eAAe;AAEnB,aAAW,CAAC,cAAc,YAAY,KAAK,eAAe,oBAAoB;AAC5E,UAAM,kBAAkB,MAAM,GAAG,SAAS,cAAc,MAAM;AAC9D,QAAI,kBAAkB;AACtB,QAAI,mBAAmB;AAEvB,eAAW,WAAW,cAAc;AAClC,YAAM,cAAc,wBAAwB,OAAO;AACnD,YAAM,cAAc,gBAAgB,MAAM,QAAQ,SAAS,EAAE,KAAK,WAAW;AAC7E,UAAI,gBAAgB,iBAAiB;AACnC,4BAAoB,iBAAiB,iBAAiB,QAAQ,SAAS;AACvE,0BAAkB;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,oBAAoB,iBAAiB;AACvC,YAAM,GAAG,UAAU,cAAc,eAAe;AAChD,sBAAgB;AAChB,sBAAgB;AAAA,IAClB;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,iBAAiB,eAAe;AAAA,EAClC;AACF;AAEO,SAAS,wBAAwB,SAA+B;AACrE,SAAO,kBAAkB,wBAAwB,QAAQ,YAAY,CAAC,IACpE,QAAQ,WAAW,aAAa,YAClC;AACF;AAEA,SAAS,wBACP,QACA,UAIA;AACA,QAAM,qBAAqB,oBAAI,IAA4B;AAC3D,MAAI,kBAAkB;AAEtB,aAAW,WAAW,UAAU;AAC9B,UAAM,eAAe,uBAAuB,QAAQ,QAAQ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","names":["path","options","path","args","options","jsx","args","options"]}
1
+ {"version":3,"sources":["../../src/commands/scrub.tsx","../../src/features/scrub/run-scrub-command.ts","../../src/features/scrub/masker.ts","../../src/features/scrub/scrub-output.tsx","../../src/features/scrub/trufflehog.ts","../../src/features/scrub/findings.ts"],"sourcesContent":["import { option } from \"pastel\";\nimport { z } from \"zod\";\n\nimport { GlobalOptionsSchema, OptionalPathArgsSchema } from \"../cli/options.js\";\nimport { runScrubCommand, type ScrubCommandOptions } from \"../features/scrub/run-scrub-command.js\";\nimport { CommandRunner } from \"../cli/command-runner.js\";\n\nexport const description = \"Scan for secrets with TruffleHog and optionally mask them inline\";\nexport const args = OptionalPathArgsSchema;\nexport const options = GlobalOptionsSchema.extend({\n mask: z\n .boolean()\n .optional()\n .describe(\n option({\n description: \"Compatibility alias for inline scrubbing; --yes is still required\",\n })\n ),\n yes: z\n .boolean()\n .optional()\n .describe(\n option({\n description: \"Confirm and run inline scrubbing\",\n })\n ),\n});\n\ntype ScrubCommandProps = {\n readonly args: z.infer<typeof args>;\n readonly options: ScrubCommandOptions;\n};\n\nexport default function ScrubCommand({ args, options }: ScrubCommandProps) {\n return <CommandRunner run={(output) => runScrubCommand(args[0], options, output)} />;\n}\n","import process from \"node:process\";\nimport { createElement } from \"react\";\n\nimport type { GlobalCommandOptions } from \"../../shared/config.js\";\nimport type { CommandOutput } from \"../../shared/output/types.js\";\nimport type { ScrubFinding } from \"./findings.js\";\nimport { scrubFindingsInline } from \"./masker.js\";\nimport { ScrubFindingsReport } from \"./scrub-output.js\";\nimport { scanFilesystemWithTruffleHog } from \"./trufflehog.js\";\n\nexport type ScrubCommandOptions = GlobalCommandOptions & {\n mask?: boolean;\n yes?: boolean;\n};\n\nexport type ScrubCommandDependencies = {\n scanFilesystem(targetPath: string): Promise<ScrubFinding[]>;\n};\n\nexport async function runScrubCommand(\n targetPath: string | undefined,\n options: ScrubCommandOptions,\n output: CommandOutput,\n dependencies?: ScrubCommandDependencies\n): Promise<void> {\n const scrubTargetPath = targetPath ?? \".\";\n const scanFilesystem =\n dependencies?.scanFilesystem ??\n ((scanTargetPath: string) =>\n scanFilesystemWithTruffleHog(scanTargetPath, {\n cwd: process.cwd(),\n }));\n const findings = await scanFilesystem(scrubTargetPath);\n\n if (findings.length === 0) {\n output.success(\"No secrets found.\");\n return;\n }\n\n output.component(createElement(ScrubFindingsReport, { findings }));\n\n if (!options.yes) {\n if (options.mask) {\n throw new Error(\"Inline scrubbing rewrites files. Re-run with --yes to continue.\");\n }\n\n output.warning(\"Report only. Re-run with --yes to scrub files inline.\");\n return;\n }\n\n const result = await scrubFindingsInline(scrubTargetPath, findings);\n output.success(\n `Masked ${result.replacements} secret${result.replacements === 1 ? \"\" : \"s\"} in ${\n result.filesChanged\n } file${result.filesChanged === 1 ? \"\" : \"s\"}.`\n );\n\n if (result.skippedFindings > 0) {\n output.warning(`Skipped ${result.skippedFindings} finding(s) outside the scrub root.`);\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport type { ScrubFinding } from \"./findings.js\";\n\nexport type InlineScrubResult = {\n filesChanged: number;\n replacements: number;\n skippedFindings: number;\n};\n\nexport async function scrubFindingsInline(\n targetPath: string,\n findings: ScrubFinding[]\n): Promise<InlineScrubResult> {\n const target = await resolveScrubTarget(targetPath);\n const findingsByFile = groupFindingsBySafePath(target, findings);\n let filesChanged = 0;\n let replacements = 0;\n\n for (const [absolutePath, fileFindings] of findingsByFile.safeFindingsByPath) {\n const originalContent = await fs.readFile(absolutePath, \"utf8\");\n let scrubbedContent = originalContent;\n let fileReplacements = 0;\n\n for (const finding of fileFindings) {\n const placeholder = formatSecretPlaceholder(finding);\n const nextContent = scrubbedContent.split(finding.rawSecret).join(placeholder);\n if (nextContent !== scrubbedContent) {\n fileReplacements += countOccurrences(scrubbedContent, finding.rawSecret);\n scrubbedContent = nextContent;\n }\n }\n\n if (scrubbedContent !== originalContent) {\n await fs.writeFile(absolutePath, scrubbedContent);\n filesChanged += 1;\n replacements += fileReplacements;\n }\n }\n\n return {\n filesChanged,\n replacements,\n skippedFindings: findingsByFile.skippedFindings,\n };\n}\n\nexport function formatSecretPlaceholder(finding: ScrubFinding): string {\n return `[CNGKIT_SECRET:${sanitizePlaceholderPart(finding.detectorName)}:${\n finding.verified ? \"verified\" : \"unverified\"\n }]`;\n}\n\nfunction groupFindingsBySafePath(\n target: ScrubTarget,\n findings: ScrubFinding[]\n): {\n safeFindingsByPath: Map<string, ScrubFinding[]>;\n skippedFindings: number;\n} {\n const safeFindingsByPath = new Map<string, ScrubFinding[]>();\n let skippedFindings = 0;\n\n for (const finding of findings) {\n const absolutePath = resolveSafeFindingPath(target, finding.filePath);\n if (!absolutePath) {\n skippedFindings += 1;\n continue;\n }\n\n const fileFindings = safeFindingsByPath.get(absolutePath) ?? [];\n fileFindings.push(finding);\n safeFindingsByPath.set(absolutePath, fileFindings);\n }\n\n return { safeFindingsByPath, skippedFindings };\n}\n\ntype ScrubTarget = {\n rootDir: string;\n allowedFilePath?: string;\n};\n\nasync function resolveScrubTarget(targetPath: string): Promise<ScrubTarget> {\n const absoluteTargetPath = path.resolve(targetPath);\n const stat = await fs.stat(absoluteTargetPath);\n\n if (stat.isFile()) {\n return {\n rootDir: path.dirname(absoluteTargetPath),\n allowedFilePath: absoluteTargetPath,\n };\n }\n\n return {\n rootDir: absoluteTargetPath,\n };\n}\n\nfunction resolveSafeFindingPath(\n target: ScrubTarget,\n findingFilePath: string\n): string | undefined {\n const absolutePath = path.isAbsolute(findingFilePath)\n ? path.resolve(findingFilePath)\n : path.resolve(target.rootDir, findingFilePath);\n\n if (target.allowedFilePath) {\n return absolutePath === target.allowedFilePath ? absolutePath : undefined;\n }\n\n const normalizedRoot = `${path.resolve(target.rootDir)}${path.sep}`;\n\n if (absolutePath === path.resolve(target.rootDir) || absolutePath.startsWith(normalizedRoot)) {\n return absolutePath;\n }\n\n return undefined;\n}\n\nfunction countOccurrences(value: string, search: string): number {\n if (!search) {\n return 0;\n }\n\n return value.split(search).length - 1;\n}\n\nfunction sanitizePlaceholderPart(value: string): string {\n return value.replace(/[^A-Za-z0-9_-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"Unknown\";\n}\n","import { Box, Text } from \"ink\";\n\nimport type { ScrubFinding } from \"./findings.js\";\n\nexport function ScrubFindingsReport({ findings }: { readonly findings: readonly ScrubFinding[] }) {\n return (\n <Box flexDirection=\"column\">\n <Text color=\"yellow\" bold>\n Found {findings.length} possible secret{findings.length === 1 ? \"\" : \"s\"}:\n </Text>\n {findings.map((finding, index) => {\n const location = finding.line ? `${finding.filePath}:${finding.line}` : finding.filePath;\n const status = finding.verified ? \"verified\" : \"unverified\";\n\n return (\n <Text key={`${finding.filePath}-${finding.line ?? 0}-${finding.detectorName}-${index}`}>\n <Text color=\"cyan\">- </Text>\n <Text>{location}</Text>\n <Text dimColor> {finding.detectorName}</Text>\n <Text color={finding.verified ? \"green\" : \"yellow\"}> {status}</Text>\n </Text>\n );\n })}\n </Box>\n );\n}\n","import { spawn } from \"node:child_process\";\nimport path from \"node:path\";\n\nimport { parseTruffleHogJsonLines, type ScrubFinding } from \"./findings.js\";\n\nexport type TruffleHogScanOptions = {\n cwd: string;\n};\n\nexport async function scanFilesystemWithTruffleHog(\n targetPath: string,\n options: TruffleHogScanOptions\n): Promise<ScrubFinding[]> {\n const absoluteTargetPath = path.resolve(options.cwd, targetPath);\n const { stdout } = await runTruffleHog([\n \"filesystem\",\n absoluteTargetPath,\n \"--json\",\n \"--no-update\",\n \"--force-skip-binaries\",\n \"--force-skip-archives\",\n ]);\n\n return parseTruffleHogJsonLines(stdout);\n}\n\nfunction runTruffleHog(args: string[]): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const child = spawn(\"trufflehog\", args, {\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n const stdoutChunks: Buffer[] = [];\n const stderrChunks: Buffer[] = [];\n\n child.stdout.on(\"data\", (chunk: Buffer) => {\n stdoutChunks.push(chunk);\n });\n child.stderr.on(\"data\", (chunk: Buffer) => {\n stderrChunks.push(chunk);\n });\n child.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (error.code === \"ENOENT\") {\n reject(\n new Error(\n \"TruffleHog is not installed. Install it with `brew install trufflehog` or see https://github.com/trufflesecurity/trufflehog.\"\n )\n );\n return;\n }\n\n reject(error);\n });\n child.on(\"close\", (exitCode) => {\n const stdout = Buffer.concat(stdoutChunks).toString(\"utf8\");\n const stderr = Buffer.concat(stderrChunks).toString(\"utf8\");\n\n if (exitCode && exitCode !== 0) {\n reject(new Error(`TruffleHog scan failed with exit code ${exitCode}: ${stderr.trim()}`));\n return;\n }\n\n resolve({ stdout, stderr });\n });\n });\n}\n","export type ScrubFinding = {\n detectorName: string;\n filePath: string;\n line?: number;\n rawSecret: string;\n redactedSecret: string;\n verified: boolean;\n};\n\ntype JsonRecord = Record<string, unknown>;\n\nexport function parseTruffleHogJsonLines(output: string): ScrubFinding[] {\n const findings: ScrubFinding[] = [];\n\n for (const line of output.split(/\\r?\\n/)) {\n const trimmedLine = line.trim();\n if (!trimmedLine.startsWith(\"{\")) {\n continue;\n }\n\n const parsedLine = parseJsonRecord(trimmedLine);\n if (!parsedLine) {\n continue;\n }\n\n const finding = parseTruffleHogFinding(parsedLine);\n if (finding) {\n findings.push(finding);\n }\n }\n\n return findings;\n}\n\nfunction parseTruffleHogFinding(finding: JsonRecord): ScrubFinding | undefined {\n const rawSecret = readString(finding.Raw) || readString(finding.RawV2);\n const filePath = readFilesystemFilePath(finding);\n\n if (!rawSecret || !filePath) {\n return undefined;\n }\n\n return {\n detectorName: readString(finding.DetectorName) || \"Unknown\",\n filePath,\n line: readFilesystemLine(finding),\n rawSecret,\n redactedSecret: readString(finding.Redacted) || \"\",\n verified: finding.Verified === true,\n };\n}\n\nfunction readFilesystemFilePath(finding: JsonRecord): string | undefined {\n const filesystem = readFilesystemMetadata(finding);\n if (!filesystem) {\n return undefined;\n }\n\n return readString(filesystem.file) || readString(filesystem.path);\n}\n\nfunction readFilesystemLine(finding: JsonRecord): number | undefined {\n const filesystem = readFilesystemMetadata(finding);\n if (!filesystem) {\n return undefined;\n }\n\n return typeof filesystem.line === \"number\" ? filesystem.line : undefined;\n}\n\nfunction readFilesystemMetadata(finding: JsonRecord): JsonRecord | undefined {\n const sourceMetadata = readRecord(finding.SourceMetadata);\n const data = readRecord(sourceMetadata?.Data);\n return readRecord(data?.Filesystem);\n}\n\nfunction parseJsonRecord(line: string): JsonRecord | undefined {\n try {\n return readRecord(JSON.parse(line));\n } catch {\n return undefined;\n }\n}\n\nfunction isJsonRecord(value: unknown): value is JsonRecord {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction readRecord(value: unknown): JsonRecord | undefined {\n return isJsonRecord(value) ? value : undefined;\n}\n\nfunction readString(value: unknown): string | undefined {\n return typeof value === \"string\" && value.length > 0 ? value : undefined;\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,SAAS;;;ACDlB,OAAO,aAAa;AACpB,SAAS,qBAAqB;;;ACD9B,OAAO,QAAQ;AACf,OAAO,UAAU;AAUjB,eAAsB,oBACpB,YACA,UAC4B;AAC5B,QAAM,SAAS,MAAM,mBAAmB,UAAU;AAClD,QAAM,iBAAiB,wBAAwB,QAAQ,QAAQ;AAC/D,MAAI,eAAe;AACnB,MAAI,eAAe;AAEnB,aAAW,CAAC,cAAc,YAAY,KAAK,eAAe,oBAAoB;AAC5E,UAAM,kBAAkB,MAAM,GAAG,SAAS,cAAc,MAAM;AAC9D,QAAI,kBAAkB;AACtB,QAAI,mBAAmB;AAEvB,eAAW,WAAW,cAAc;AAClC,YAAM,cAAc,wBAAwB,OAAO;AACnD,YAAM,cAAc,gBAAgB,MAAM,QAAQ,SAAS,EAAE,KAAK,WAAW;AAC7E,UAAI,gBAAgB,iBAAiB;AACnC,4BAAo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