@shrkcrft/cli 0.1.0-alpha.11 → 0.1.0-alpha.13

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 (81) hide show
  1. package/dist/audit/knowledge-audit-llm.d.ts +19 -0
  2. package/dist/audit/knowledge-audit-llm.d.ts.map +1 -0
  3. package/dist/audit/knowledge-audit-llm.js +164 -0
  4. package/dist/audit/knowledge-audit.d.ts +61 -0
  5. package/dist/audit/knowledge-audit.d.ts.map +1 -0
  6. package/dist/audit/knowledge-audit.js +203 -0
  7. package/dist/audit/knowledge-fix-plan-llm.d.ts +11 -0
  8. package/dist/audit/knowledge-fix-plan-llm.d.ts.map +1 -0
  9. package/dist/audit/knowledge-fix-plan-llm.js +141 -0
  10. package/dist/audit/knowledge-fix-plan.d.ts +41 -0
  11. package/dist/audit/knowledge-fix-plan.d.ts.map +1 -0
  12. package/dist/audit/knowledge-fix-plan.js +125 -0
  13. package/dist/audit/pipeline-audit-llm.d.ts +11 -0
  14. package/dist/audit/pipeline-audit-llm.d.ts.map +1 -0
  15. package/dist/audit/pipeline-audit-llm.js +134 -0
  16. package/dist/audit/pipeline-audit.d.ts +69 -0
  17. package/dist/audit/pipeline-audit.d.ts.map +1 -0
  18. package/dist/audit/pipeline-audit.js +166 -0
  19. package/dist/audit/templates-audit-llm.d.ts +19 -0
  20. package/dist/audit/templates-audit-llm.d.ts.map +1 -0
  21. package/dist/audit/templates-audit-llm.js +207 -0
  22. package/dist/audit/templates-audit.d.ts +63 -0
  23. package/dist/audit/templates-audit.d.ts.map +1 -0
  24. package/dist/audit/templates-audit.js +171 -0
  25. package/dist/audit/templates-fix-plan-llm.d.ts +19 -0
  26. package/dist/audit/templates-fix-plan-llm.d.ts.map +1 -0
  27. package/dist/audit/templates-fix-plan-llm.js +162 -0
  28. package/dist/audit/templates-fix-plan.d.ts +37 -0
  29. package/dist/audit/templates-fix-plan.d.ts.map +1 -0
  30. package/dist/audit/templates-fix-plan.js +174 -0
  31. package/dist/commands/ai-status.command.d.ts +19 -0
  32. package/dist/commands/ai-status.command.d.ts.map +1 -0
  33. package/dist/commands/ai-status.command.js +94 -0
  34. package/dist/commands/ask.command.d.ts.map +1 -1
  35. package/dist/commands/ask.command.js +10 -9
  36. package/dist/commands/command-catalog.d.ts.map +1 -1
  37. package/dist/commands/command-catalog.js +110 -1
  38. package/dist/commands/deps-audit.command.d.ts +23 -0
  39. package/dist/commands/deps-audit.command.d.ts.map +1 -0
  40. package/dist/commands/deps-audit.command.js +266 -0
  41. package/dist/commands/doctor.command.d.ts.map +1 -1
  42. package/dist/commands/doctor.command.js +100 -3
  43. package/dist/commands/graph-code-subverbs.d.ts.map +1 -1
  44. package/dist/commands/graph-code-subverbs.js +144 -26
  45. package/dist/commands/graph.command.d.ts.map +1 -1
  46. package/dist/commands/graph.command.js +3 -2
  47. package/dist/commands/help.command.d.ts.map +1 -1
  48. package/dist/commands/help.command.js +22 -1
  49. package/dist/commands/impact.command.d.ts.map +1 -1
  50. package/dist/commands/impact.command.js +3 -2
  51. package/dist/commands/move-plan.command.d.ts +23 -0
  52. package/dist/commands/move-plan.command.d.ts.map +1 -0
  53. package/dist/commands/move-plan.command.js +360 -0
  54. package/dist/commands/scaffold-validate.command.d.ts +22 -0
  55. package/dist/commands/scaffold-validate.command.d.ts.map +1 -0
  56. package/dist/commands/scaffold-validate.command.js +215 -0
  57. package/dist/commands/smart-context.command.d.ts +58 -0
  58. package/dist/commands/smart-context.command.d.ts.map +1 -0
  59. package/dist/commands/smart-context.command.js +4524 -0
  60. package/dist/commands/spike.command.d.ts +22 -0
  61. package/dist/commands/spike.command.d.ts.map +1 -0
  62. package/dist/commands/spike.command.js +235 -0
  63. package/dist/commands/surface.command.d.ts +1 -0
  64. package/dist/commands/surface.command.d.ts.map +1 -1
  65. package/dist/commands/surface.command.js +10 -3
  66. package/dist/commands/template-quality.command.d.ts.map +1 -1
  67. package/dist/commands/template-quality.command.js +39 -3
  68. package/dist/commands/templates.command.d.ts.map +1 -1
  69. package/dist/commands/templates.command.js +37 -2
  70. package/dist/commands/watch.command.d.ts +26 -0
  71. package/dist/commands/watch.command.d.ts.map +1 -0
  72. package/dist/commands/watch.command.js +456 -0
  73. package/dist/env/load-dotenv.d.ts +15 -0
  74. package/dist/env/load-dotenv.d.ts.map +1 -0
  75. package/dist/env/load-dotenv.js +70 -0
  76. package/dist/main.d.ts.map +1 -1
  77. package/dist/main.js +105 -2
  78. package/dist/schemas/json-schemas.d.ts +384 -36
  79. package/dist/schemas/json-schemas.d.ts.map +1 -1
  80. package/dist/schemas/json-schemas.js +247 -36
  81. package/package.json +33 -31
package/dist/main.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { loadDotenv } from "./env/load-dotenv.js";
2
3
  import { CommandRegistry, extractGlobalCwd, parseArgs, } from "./command-registry.js";
3
4
  import { initCommand } from "./commands/init.command.js";
4
5
  import { inspectCommand } from "./commands/inspect.command.js";
@@ -55,6 +56,13 @@ import { dashboardCommand } from "./commands/dashboard.command.js";
55
56
  import { dashboardDiffCommand, dashboardExportCommand, } from "./commands/dashboard-export.command.js";
56
57
  import { importCommand } from "./commands/import.command.js";
57
58
  import { askCommand } from "./commands/ask.command.js";
59
+ import { aiStatusCommand } from "./commands/ai-status.command.js";
60
+ import { smartContextAuditKnowledgeCommand, smartContextAuditPipelinesCommand, smartContextAuditTemplatesCommand, smartContextCommand, smartContextEmbeddingsBuildCommand, smartContextEmbeddingsStatusCommand, smartContextListCommand, smartContextPlanAheadCommand, smartContextShowCommand, } from "./commands/smart-context.command.js";
61
+ import { spikeCommand } from "./commands/spike.command.js";
62
+ import { depsAuditCommand } from "./commands/deps-audit.command.js";
63
+ import { scaffoldValidateCommand } from "./commands/scaffold-validate.command.js";
64
+ import { movePlanCommand } from "./commands/move-plan.command.js";
65
+ import { watchCommand, watchListCommand, watchPruneCommand, watchStopCommand } from "./commands/watch.command.js";
58
66
  import { mcpCommand } from "./commands/mcp.command.js";
59
67
  import { versionCommand } from "./commands/version.command.js";
60
68
  import { makeHelpCommand } from "./commands/help.command.js";
@@ -135,6 +143,7 @@ export function buildRegistry() {
135
143
  registry.register(initCommand);
136
144
  registry.register(inspectCommand);
137
145
  registry.register(doctorCommand);
146
+ registry.register(aiStatusCommand);
138
147
  registry.registerSubcommand('doctor', doctorSuppressCommand);
139
148
  registry.registerSubcommand('doctor', doctorSuppressionsCommand);
140
149
  // Acknowledgements with required reason + expiry.
@@ -204,6 +213,23 @@ export function buildRegistry() {
204
213
  registry.register(planParentCommand);
205
214
  registry.register(devCommand);
206
215
  registry.register(askCommand);
216
+ registry.register(smartContextCommand);
217
+ registry.registerSubcommand('smart-context', smartContextPlanAheadCommand);
218
+ registry.registerSubcommand('smart-context', smartContextListCommand);
219
+ registry.registerSubcommand('smart-context', smartContextShowCommand);
220
+ registry.registerSubcommand('smart-context', smartContextEmbeddingsBuildCommand);
221
+ registry.registerSubcommand('smart-context', smartContextEmbeddingsStatusCommand);
222
+ registry.registerSubcommand('smart-context', smartContextAuditTemplatesCommand);
223
+ registry.registerSubcommand('smart-context', smartContextAuditKnowledgeCommand);
224
+ registry.registerSubcommand('smart-context', smartContextAuditPipelinesCommand);
225
+ registry.register(spikeCommand);
226
+ registry.register(depsAuditCommand);
227
+ registry.register(scaffoldValidateCommand);
228
+ registry.register(movePlanCommand);
229
+ registry.register(watchCommand);
230
+ registry.registerSubcommand('watch', watchListCommand);
231
+ registry.registerSubcommand('watch', watchStopCommand);
232
+ registry.registerSubcommand('watch', watchPruneCommand);
207
233
  registry.register(mcpCommand);
208
234
  registry.register(versionCommand);
209
235
  registry.register(qualityCommand);
@@ -804,9 +830,86 @@ if (isMain ||
804
830
  entryPath.endsWith('shrk') ||
805
831
  entryPath.endsWith('shrk.js') ||
806
832
  entryPath.endsWith('shrk.cmd')) {
833
+ loadDotenv(process.cwd());
807
834
  const argv = process.argv.slice(2);
808
- runCli(argv).then((code) => process.exit(code), (err) => {
835
+ const cleanShutdown = async (code) => {
836
+ // Best-effort teardown of shared native runtimes. Without this,
837
+ // commands that loaded native libs (ONNX via embeddings; Metal
838
+ // via node-llama-cpp) abort during `process.exit` AFTER the
839
+ // work completed — the user sees their result then `zsh: abort`.
840
+ // Dynamic imports keep these off the hot path for commands that
841
+ // never touched them.
842
+ try {
843
+ const mod = (await import('@shrkcrft/embeddings'));
844
+ if (typeof mod.disposeSemanticIndexPipeline === 'function') {
845
+ await mod.disposeSemanticIndexPipeline();
846
+ }
847
+ }
848
+ catch {
849
+ // Best-effort; never block the exit on teardown failure.
850
+ }
851
+ try {
852
+ const mod = (await import('@shrkcrft/ai'));
853
+ if (typeof mod.disposeLlamaCppRuntime === 'function') {
854
+ await mod.disposeLlamaCppRuntime();
855
+ }
856
+ }
857
+ catch {
858
+ // Best-effort.
859
+ }
860
+ // Flush stdio synchronously before bypassing C++ destructors.
861
+ // `_exit` skips all libc finalizers, which is exactly what we
862
+ // need (see below), but it also doesn't wait for buffered
863
+ // writes to drain. Two synchronous write callbacks force the
864
+ // current buffers through.
865
+ try {
866
+ await new Promise((resolve) => process.stdout.write('', () => resolve()));
867
+ await new Promise((resolve) => process.stderr.write('', () => resolve()));
868
+ }
869
+ catch {
870
+ // ignore flush failures
871
+ }
872
+ // Prefer a low-level exit over `process.exit` on Node. Without
873
+ // this, libc++ static destructors run during `process.exit`, and
874
+ // native bindings still resident in memory abort with libc++abi
875
+ // errors AFTER the user's result has already printed:
876
+ // - node-llama-cpp's libggml-metal hits `GGML_ASSERT([rsets->data
877
+ // count] == 0)` in `ggml_metal_device_free` → `zsh: abort`.
878
+ // - onnxruntime-node's worker pool aborts with
879
+ // `libc++abi: mutex lock failed: Invalid argument` after a
880
+ // successful `shrk smart-context embeddings-build`. NOTE:
881
+ // `pipeline.dispose()` returns cleanly, but ONNX worker threads
882
+ // are not actually joined — they continue running briefly and
883
+ // hit the pthread mutex teardown race. There is no JS-layer
884
+ // fix for this; upstream onnxruntime-node 1.21 has the bug.
885
+ // The low-level exit at least suppresses the destructor pass
886
+ // so the failure mode is "noisy stderr, exit code preserved"
887
+ // rather than "destructor cascade".
888
+ //
889
+ // Node exposes the low-level exit under two names depending on the
890
+ // version:
891
+ // - `process._exit` — public alias (older Node; removed from
892
+ // the public surface on Node 22+).
893
+ // - `process.reallyExit` — Node-internal name; still present on
894
+ // Node 22 even when `_exit` is undefined.
895
+ // Try both in order. Bun's process object doesn't expose either,
896
+ // but Bun also doesn't drive shutdown through libuv + libc++ static
897
+ // destructors the same way Node does, so the crash doesn't
898
+ // reproduce there. Fall back to `process.exit` when no low-level
899
+ // hook is available.
900
+ const proc = process;
901
+ const lowLevelExit = typeof proc._exit === 'function'
902
+ ? proc._exit
903
+ : typeof proc.reallyExit === 'function'
904
+ ? proc.reallyExit
905
+ : null;
906
+ if (lowLevelExit !== null) {
907
+ lowLevelExit(code);
908
+ }
909
+ process.exit(code);
910
+ };
911
+ runCli(argv).then((code) => cleanShutdown(code), (err) => {
809
912
  process.stderr.write(`Fatal: ${err instanceof Error ? err.message : String(err)}\n`);
810
- process.exit(1);
913
+ return cleanShutdown(1);
811
914
  });
812
915
  }