-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
1435 lines (1297 loc) · 54.3 KB
/
Copy pathindex.js
File metadata and controls
1435 lines (1297 loc) · 54.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (c) 2024-2026 Chris Arsenault / 1450 Enterprises LLC
import { config } from './config.js';
import { db } from './db/client.js';
import {
listOperationLogs,
summarizeOperationLogs,
listHarvestRuns,
listFailureInbox,
listSourceHealth,
logOperationSafely,
} from './db/operation-log-store.js';
import { createSystemRunSafely, updateSystemRunSafely, listSystemRuns } from './db/system-run-store.js';
import { listClaims, listClaimQueue, summarizeClaims, updateClaim } from './db/claim-store.js';
import { listSourceRecords, summarizeSourceRecords } from './db/source-record-store.js';
import { migrate } from './db/migrate.js';
import { logger } from './utils/logger.js';
import { N8nCommunityHarvester } from './harvesters/n8n-community.js';
import { GitHubHarvester } from './harvesters/github.js';
import { RedditHarvester } from './harvesters/reddit.js';
import { GitHubAgentsHarvester } from './harvesters/github-agents.js';
import { GitHubZapierMakeHarvester } from './harvesters/github-zapier-make.js';
import { ActivepiecesHarvester } from './harvesters/activepieces.js';
import { WindmillHarvester } from './harvesters/windmill.js';
import { TemporalHarvester } from './harvesters/temporal.js';
import { AirflowHarvester } from './harvesters/airflow.js';
import { NodeRedHarvester } from './harvesters/node-red.js';
import { PrefectHarvester } from './harvesters/prefect.js';
import { DagsterHarvester } from './harvesters/dagster.js';
import { LangGraphHarvester } from './harvesters/langgraph.js';
import { ComfyUIHarvester } from './harvesters/comfyui.js';
import { DifyHarvester } from './harvesters/dify.js';
import { FlowiseHarvester } from './harvesters/flowise.js';
import { PipedreamHarvester } from './harvesters/pipedream.js';
import { ArgoHarvester } from './harvesters/argo.js';
import { LuigiHarvester } from './harvesters/luigi.js';
import { TektonHarvester } from './harvesters/tekton.js';
import { GitHubActionsHarvester } from './harvesters/github-actions.js';
import { HomeAssistantHarvester } from './harvesters/home-assistant.js';
import { MLflowHarvester } from './harvesters/mlflow.js';
import { DbtHarvester } from './harvesters/dbt.js';
import { CamundaHarvester } from './harvesters/camunda.js';
import { KafkaConnectHarvester } from './harvesters/kafka-connect.js';
import { CamelHarvester } from './harvesters/camel.js';
import { classifyWorkflows } from './processing/classifier.js';
import { scoreWorkflows } from './processing/scorer.js';
import { embedWorkflows } from './processing/embedder.js';
import { packageWorkflows } from './processing/packager.js';
import { generateGuides } from './processing/guide-generator.js';
import { analyzeMigrations } from './processing/migration-analyzer.js';
import { analyzeComplexity } from './processing/complexity-analyzer.js';
import { generateCompositions } from './processing/composition-engine.js';
import { refreshFacets } from './processing/faceted-search.js';
import { embedArtifacts } from './processing/artifact-embedder.js';
import { monetizeArtifacts } from './processing/monetizer.js';
import { generateBundles } from './processing/bundler.js';
import { registerWorkflowStrategies } from './processing/strategies/workflow/index.js';
import { registerInfraConfigStrategies } from './processing/strategies/infra-config/index.js';
import { registerCodePatternStrategies } from './processing/strategies/code-pattern/index.js';
import { registerAiMlAssetStrategies } from './processing/strategies/ai-ml-asset/index.js';
import { registerApiSpecStrategies } from './processing/strategies/api-spec/index.js';
import { registerDataAssetStrategies } from './processing/strategies/data-asset/index.js';
import { registerDocumentationStrategies } from './processing/strategies/documentation/index.js';
import { ARTIFACT_TYPES, listStrategies } from './processing/registry.js';
import { TerraformHarvester } from './harvesters/terraform.js';
import { HelmHarvester } from './harvesters/helm.js';
import { DockerComposeHarvester } from './harvesters/docker-compose-harvester.js';
import { K8sManifestsHarvester } from './harvesters/k8s-manifests.js';
import { AnsibleHarvester } from './harvesters/ansible.js';
import { createYamlHarvesters } from './harvesters/yaml-harvester.js';
// ── Wave 3: Quality Improvements ──
import { detectLicenseBatch } from './processing/license-detector.js';
import { validateArtifactsBatch } from './processing/validator.js';
import { detectTestsBatch } from './processing/test-detector.js';
import { scoreFreshnessBatch } from './processing/freshness-scorer.js';
// ── Wave 3: Search & Discovery ──
import { buildRelations } from './processing/relation-builder.js';
import { generateRecommendations } from './processing/recommender.js';
import { enrichWithTrends } from './processing/trend-enricher.js';
// ── F3: Semantic Dedup ──
import { runSemanticDedup } from './processing/semantic-dedup.js';
// ── F1: Predictive Quality Decay ──
import { scoreBatchDecay } from './processing/decay-predictor.js';
// ── F5: Multi-Language Understanding ──
import { batchExtractUnderstanding } from './processing/understanding-extractor.js';
import { batchExtractClaims } from './processing/claim-extractor.js';
// ── F11: Intelligence Graph ──
import { materializeGraph } from './db/graph-store.js';
// ── Autonomy Expansion ──
import { getEventBus } from './processing/event-bus.js';
import { getScheduler } from './processing/scheduler.js';
import { createSnapshot, listSnapshots, compareSnapshots } from './processing/snapshots.js';
import { discoverRelated, discoverClusters, discoverBridges } from './processing/graph-discovery.js';
import { analyzeCoverage, identifyGaps, getCoverageReport } from './processing/coverage-analyzer.js';
import { thisVsLast, velocityReport } from './processing/time-compare.js';
import { refreshBatch } from './processing/auto-refresh.js';
import { syncFromTrendscope } from './integrations/trendscope-sync.js';
// ── Wave 3: More Harvesters ──
import { CIConfigsHarvester } from './harvesters/ci-configs.js';
import { DockerfileHarvester } from './harvesters/dockerfile.js';
import { JupyterHarvester } from './harvesters/jupyter.js';
import { ShellScriptsHarvester } from './harvesters/shell-scripts.js';
import { MakefileHarvester } from './harvesters/makefile.js';
import { CompetitiveIntelHarvester } from './harvesters/competitive-intel.js';
// ─── CLI Command Definitions ───
const COMMANDS = {
harvest: runHarvest,
classify: runClassify,
score: runScore,
embed: runEmbed,
package: runPackage,
guide: runGuide,
migrate: runMigrate,
migrations: runMigrationAnalysis,
complexity: runComplexity,
compose: runCompositions,
facets: runFacets,
monetize: runMonetize,
bundle: runBundles,
pipeline: runFullPipeline,
stats: runStats,
// ── Wave 3: Quality Improvements ──
license: runLicenseDetection,
validate: runValidation,
'test-detect': runTestDetection,
freshness: runFreshnessScoring,
// ── Wave 3: Search & Discovery ──
relations: runRelations,
recommend: runRecommendations,
// ── Trendscope Integration ──
'enrich-trends': runTrendEnrichment,
// ── F3: Semantic Dedup ──
'dedup-semantic': dedupSemantic,
// ── F1: Predictive Quality Decay ──
decay: decayPredict,
// ── F5: Multi-Language Understanding ──
understand: runUnderstanding,
claims: runClaims,
'claim-queue': runClaimQueue,
'claim-review': runClaimReview,
'claims-extract': runClaimExtraction,
// ── F11: Intelligence Graph ──
'graph-materialize': graphMaterialize,
// ── Autonomy Expansion ──
schedule: runScheduleCmd,
snapshot: runSnapshotCmd,
discover: runDiscoverCmd,
coverage: runCoverageCmd,
compare: runCompareCmd,
'auto-refresh': runAutoRefresh,
'sync-trends': runSyncTrends,
pulse: runPulse,
errors: runErrors,
runs: runRuns,
inbox: runInbox,
'source-health': runSourceHealth,
'source-records': runSourceRecords,
'system-runs': runSystemRuns,
};
const USAGE = `
Knowledge Harvester — Multi-Tool Automation & Asset Library Builder
Usage: node src/index.js <command> [options]
Commands:
harvest --source <source|all> Harvest workflows from a specific source or all
classify [--limit N] Classify unclassified workflows via Ollama
score [--limit N] Score unscored workflows
embed [--limit N] Generate vector embeddings for semantic search
package [--limit N] [--id ID] Generate deployment packages for workflows
guide [--limit N] Generate setup guides for packaged workflows
migrate Run database migrations
migrations [--limit N] Analyze cross-tool migration suggestions
complexity [--limit N] Run multi-dimensional complexity analysis
compose [--limit N] Generate workflow composition suggestions
facets Refresh and display search facets
monetize [--limit N] Assign price tiers and marketplace metadata
bundle Generate curated artifact bundles
license [--limit N] Detect licenses for artifacts
validate [--limit N] Run per-type validation on artifacts
test-detect [--limit N] Detect test coverage signals
freshness [--limit N] Score artifact freshness via GitHub API
relations [--limit N] Build artifact relation graph
recommend [--limit N] Generate artifact recommendations
enrich-trends [--limit N] Enrich artifacts with Trendscope signals
dedup-semantic [--limit N] [--threshold F] Detect semantic duplicates and select canonicals
decay [--limit N] Score predictive quality decay for artifacts
understand [--limit N] Extract LLM-driven understanding metadata via Ollama
claims [--limit N] [--status S] [--claim-type T] Review extracted claims
claim-queue [--limit N] [--status S] [--search Q] Show evidence-aware claim review queue
claim-review --id ID [--status S] [--confidence F] Update claim adjudication fields
claims-extract [--limit N] Extract candidate claims from accepted source records
graph-materialize Materialize intelligence graph from artifacts & relations
schedule <list|run|enable|disable> [--name N] Manage scheduled automations
snapshot <create|list|compare> [--label L] [--a ID --b ID] Manage snapshots
discover <related|clusters|bridges> [--id ID] Graph-powered discovery
coverage Category coverage analysis
compare [--period week|month|day] Time-window comparison
auto-refresh [--threshold F] [--limit N] Auto-refresh stale artifacts
sync-trends Sync intelligence with Trendscope
pulse Autonomy system pulse dashboard
errors [--limit N] [--since-hours H] [--run-id ID] [--system-run-id ID] Show recent operational warnings and errors
runs [--limit N] [--status S] Show recent harvest runs with warning/error counts
inbox [--limit N] [--since-hours H] Show grouped actionable failures
source-health [--limit N] Show source reliability and recent failure status
source-records [--limit N] [--decision D] [--source S] Show accepted/discarded source appendix records
system-runs [--limit N] [--status S] Show recent command and pipeline runs
pipeline Run full 23-step pipeline
stats Show database statistics
Sources (37+ built-in, 27 workflow + 10 infra/code + YAML-defined):
n8n-community n8n official template library (~7,888 templates)
github n8n workflows on GitHub (code search)
reddit r/n8n community posts
github-agents AI agent frameworks (LangChain, CrewAI, AutoGen)
github-zapier-make Zapier, Make.com, IFTTT configs on GitHub
activepieces Activepieces template gallery
windmill Windmill OpenFlow definitions on GitHub
temporal Temporal workflow code (Python, TS, Go, Java)
airflow Apache Airflow DAGs on GitHub
node-red Node-RED flow library (flows.nodered.org)
prefect Prefect flow/task definitions on GitHub
dagster Dagster asset/op/job definitions on GitHub
langgraph LangGraph agent graphs on GitHub (Python, TS)
comfyui ComfyUI image/video generation workflows
dify Dify AI application workflows
flowise Flowise chatflow and agentflow definitions
pipedream Pipedream event-driven workflows
argo Argo Workflows Kubernetes-native DAGs
luigi Luigi batch processing pipeline definitions
tekton Tekton Pipelines on Kubernetes
github-actions GitHub Actions CI/CD workflows
home-assistant Home Assistant automations and blueprints
mlflow MLflow experiment tracking and model pipelines
dbt dbt data transformation models
camunda Camunda BPMN process definitions
kafka-connect Kafka Connect connector configurations
camel Apache Camel integration routes
Infrastructure Configs (→ artifacts table):
terraform Terraform modules and configs (HCL)
helm Helm chart definitions (Chart.yaml, values, templates)
docker-compose Docker Compose service definitions
k8s-manifests Kubernetes manifest YAML files
ansible Ansible playbooks and roles
ci-configs CI/CD configs (GitHub Actions, GitLab CI, Jenkins)
dockerfile Dockerfile patterns (multi-stage, non-root, healthcheck)
jupyter Jupyter notebooks (PyTorch, TensorFlow, scikit-learn)
shell-scripts Shell scripts (deploy, setup, install, entrypoint)
makefile Makefiles (build automation patterns)
Programmable (YAML-defined, drop files in src/definitions/):
fastapi-patterns FastAPI middleware and router patterns
pytorch-training PyTorch model training scripts and configs
react-patterns React component and hook patterns
openapi-specs OpenAPI/Swagger API specifications
asyncapi-specs AsyncAPI event-driven API specifications
grpc-protos gRPC protobuf service definitions
graphql-schemas GraphQL schema definitions
sql-schemas SQL database schema definitions
adrs Architecture Decision Records
runbooks Operational runbooks and procedures
security-policies Security and governance policy documents
compliance-controls Compliance control matrices and evidence docs
support-playbooks Support troubleshooting and escalation playbooks
product-requirements Product requirement docs and specs
release-checklists Release, cutover, and go-live checklists
vendor-assessments Vendor risk and due diligence assessments
legal-contracts Contracts, agreements, and legal operating docs
finance-controls Finance controls, budgeting, and close procedures
employee-handbooks Employee handbooks and people-ops guides
privacy-governance Privacy and data handling governance docs
board-governance Board and committee governance records
sales-playbooks Sales and revenue-ops playbooks
sales-enablement Sales enablement, battlecards, and training docs
customer-onboarding Customer onboarding guides and checklists
customer-success-playbooks Customer success and renewal playbooks
hr-onboarding Employee onboarding guides and checklists
incident-postmortems Incident postmortems and outage retrospectives
mcp-servers Model Context Protocol servers and tools
open-policy-agent Rego policy-as-code rules
aws-step-functions AWS Step Functions state machines
google-workflows Google Cloud Workflows definitions
kestra-flows Kestra orchestration flows and tasks
flyte-workflows Flyte workflow and task definitions
pulumi-programs Pulumi infrastructure programs
cloudformation-templates AWS CloudFormation and SAM templates
(add your own .yaml files to extend!)
Artifact Types: workflow, code_pattern, infra_config, ai_ml_asset,
api_spec, data_asset, documentation
Examples:
node src/index.js pipeline
node src/index.js harvest --source n8n-community
node src/index.js harvest --source terraform
node src/index.js harvest --source fastapi-patterns
node src/index.js classify --limit 100
`;
// ─── Main Entry Point ───
async function main() {
// Initialize strategy registry
registerWorkflowStrategies();
registerInfraConfigStrategies();
registerCodePatternStrategies();
registerAiMlAssetStrategies();
registerApiSpecStrategies();
registerDataAssetStrategies();
registerDocumentationStrategies();
const command = process.argv[2] || 'pipeline';
const handler = COMMANDS[command];
if (!handler) {
console.log(USAGE);
process.exit(1);
}
// Track active harvesters for graceful shutdown
const activeHarvesters = [];
const systemRun = await createSystemRunSafely({
runType: command === 'pipeline' ? 'pipeline' : 'command',
command,
trigger: 'cli',
status: 'running',
metadata: {
argv: process.argv.slice(2),
},
});
await logOperationSafely({
level: 'info',
category: command === 'pipeline' ? 'pipeline' : 'command',
eventType: `${command === 'pipeline' ? 'pipeline' : 'command'}.started`,
message: `Command "${command}" started`,
command,
systemRunId: systemRun.id,
metadata: {
argv: process.argv.slice(2),
trigger: 'cli',
},
});
// Graceful shutdown handler
const shutdown = async (signal) => {
logger.info(`Received ${signal}, shutting down gracefully...`);
activeHarvesters.forEach(h => h.abort());
await updateSystemRunSafely(systemRun.id, {
status: 'aborted',
errorMessage: `Interrupted by ${signal}`,
completedAt: 'now',
});
await logOperationSafely({
level: 'warn',
category: command === 'pipeline' ? 'pipeline' : 'command',
eventType: `${command === 'pipeline' ? 'pipeline' : 'command'}.aborted`,
message: `Command "${command}" interrupted by ${signal}`,
command,
systemRunId: systemRun.id,
metadata: { signal },
});
// Force exit after 5 seconds if cleanup hangs
setTimeout(() => {
logger.warn('Forced exit after timeout');
process.exit(1);
}, 5000);
};
process.on('SIGINT', () => shutdown('SIGINT'));
process.on('SIGTERM', () => shutdown('SIGTERM'));
try {
await handler(activeHarvesters, systemRun.id);
await updateSystemRunSafely(systemRun.id, {
status: 'completed',
completedAt: 'now',
});
await logOperationSafely({
level: 'info',
category: command === 'pipeline' ? 'pipeline' : 'command',
eventType: `${command === 'pipeline' ? 'pipeline' : 'command'}.completed`,
message: `Command "${command}" completed`,
command,
systemRunId: systemRun.id,
});
} catch (err) {
logger.error('Command failed', { command, error: err.message, stack: err.stack });
await logOperationSafely({
level: 'error',
category: 'command',
eventType: 'command.failed',
message: `Command "${command}" failed`,
command,
systemRunId: systemRun.id,
error: err,
});
await updateSystemRunSafely(systemRun.id, {
status: 'failed',
errorMessage: err.message,
completedAt: 'now',
});
process.exit(1);
} finally {
await db.end();
}
}
// ─── Command Handlers ───
async function runHarvest(activeHarvesters) {
const sourceArg = getArg('--source') || 'all';
const harvesterMap = {
'n8n-community': () => new N8nCommunityHarvester(),
'github': () => new GitHubHarvester(),
'reddit': () => new RedditHarvester(),
'github-agents': () => new GitHubAgentsHarvester(),
'github-zapier-make': () => new GitHubZapierMakeHarvester(),
'activepieces': () => new ActivepiecesHarvester(),
'windmill': () => new WindmillHarvester(),
'temporal': () => new TemporalHarvester(),
'airflow': () => new AirflowHarvester(),
'node-red': () => new NodeRedHarvester(),
'prefect': () => new PrefectHarvester(),
'dagster': () => new DagsterHarvester(),
'langgraph': () => new LangGraphHarvester(),
'comfyui': () => new ComfyUIHarvester(),
'dify': () => new DifyHarvester(),
'flowise': () => new FlowiseHarvester(),
'pipedream': () => new PipedreamHarvester(),
'argo': () => new ArgoHarvester(),
'luigi': () => new LuigiHarvester(),
'tekton': () => new TektonHarvester(),
'github-actions': () => new GitHubActionsHarvester(),
'home-assistant': () => new HomeAssistantHarvester(),
'mlflow': () => new MLflowHarvester(),
'dbt': () => new DbtHarvester(),
'camunda': () => new CamundaHarvester(),
'kafka-connect': () => new KafkaConnectHarvester(),
'camel': () => new CamelHarvester(),
// ── Infra Config Harvesters (artifact table) ──
'terraform': () => new TerraformHarvester(),
'helm': () => new HelmHarvester(),
'docker-compose': () => new DockerComposeHarvester(),
'k8s-manifests': () => new K8sManifestsHarvester(),
'ansible': () => new AnsibleHarvester(),
// ── Wave 3 Harvesters ──
'ci-configs': () => new CIConfigsHarvester(),
'dockerfile': () => new DockerfileHarvester(),
'jupyter': () => new JupyterHarvester(),
'shell-scripts': () => new ShellScriptsHarvester(),
'makefile': () => new MakefileHarvester(),
'competitive-intel': () => new CompetitiveIntelHarvester(),
};
// Add YAML-defined harvesters dynamically
const yamlHarvesters = createYamlHarvesters();
for (const yh of yamlHarvesters) {
if (!harvesterMap[yh.source]) {
harvesterMap[yh.source] = () => yh;
}
}
const sources = sourceArg === 'all'
? Object.keys(harvesterMap)
: [sourceArg];
for (const source of sources) {
const factory = harvesterMap[source];
if (!factory) {
logger.error(`Unknown source: ${source}`);
continue;
}
logger.info(`Starting harvest: ${source}`);
const harvester = factory();
activeHarvesters.push(harvester);
const stats = await harvester.run();
logger.info(`${source} harvest results`, stats);
}
}
async function runClassify() {
const limit = parseInt(getArg('--limit') || '50', 10);
await classifyWorkflows(limit);
}
async function runScore() {
const limit = parseInt(getArg('--limit') || '100', 10);
await scoreWorkflows(limit);
}
async function runEmbed() {
const limit = parseInt(getArg('--limit') || '100', 10);
await embedWorkflows(limit);
}
async function runPackage() {
const limit = parseInt(getArg('--limit') || '50', 10);
const id = getArg('--id');
if (id) {
// Package a single workflow by ID
await packageWorkflows(1);
} else {
await packageWorkflows(limit);
}
}
async function runGuide() {
const limit = parseInt(getArg('--limit') || '20', 10);
await generateGuides(limit);
}
async function runMigrate() {
await migrate();
}
async function runMigrationAnalysis() {
const limit = parseInt(getArg('--limit') || '50', 10);
await analyzeMigrations(limit);
}
async function runComplexity() {
const limit = parseInt(getArg('--limit') || '100', 10);
await analyzeComplexity(limit);
}
async function runCompositions() {
const limit = parseInt(getArg('--limit') || '50', 10);
await generateCompositions(limit);
}
async function runFacets() {
const facets = await refreshFacets();
console.log('\n═══ Search Facets ═══\n');
console.table(facets);
}
async function runMonetize() {
const limit = parseInt(getArg('--limit') || '200', 10);
const result = await monetizeArtifacts(limit);
console.log('\n═══ Monetization Results ═══\n');
console.log(`Monetized: ${result.monetized}`);
if (result.byTier) {
console.log('By tier:', result.byTier);
}
}
// ── Wave 3: Quality Improvement Commands ──
async function runLicenseDetection() {
const limit = parseInt(getArg('--limit') || '200', 10);
const result = await detectLicenseBatch(db, limit);
console.log('\n═══ License Detection Results ═══\n');
console.log(`Processed: ${result.processed}, Licensed: ${result.licensed}, Unknown: ${result.unknown}`);
}
async function runValidation() {
const limit = parseInt(getArg('--limit') || '200', 10);
const result = await validateArtifactsBatch(db, limit);
console.log('\n═══ Validation Results ═══\n');
console.log(`Processed: ${result.processed}, Valid: ${result.valid}, Invalid: ${result.invalid}`);
}
async function runTestDetection() {
const limit = parseInt(getArg('--limit') || '200', 10);
const result = await detectTestsBatch(db, limit);
console.log('\n═══ Test Detection Results ═══\n');
console.log(`Processed: ${result.processed}, With tests: ${result.with_tests}, Without: ${result.without_tests}`);
}
async function runFreshnessScoring() {
const limit = parseInt(getArg('--limit') || '100', 10);
const result = await scoreFreshnessBatch(db, limit);
console.log('\n═══ Freshness Scoring Results ═══\n');
console.log(`Processed: ${result.processed}, Scored: ${result.scored}, Errors: ${result.errors}`);
}
// ── Wave 3: Search & Discovery Commands ──
async function runRelations() {
const limit = parseInt(getArg('--limit') || '200', 10);
const result = await buildRelations(db, limit);
console.log('\n═══ Relation Building Results ═══\n');
console.log(`Processed: ${result.processed}, Relations created: ${result.relations_created}`);
}
async function runRecommendations() {
const limit = parseInt(getArg('--limit') || '200', 10);
const result = await generateRecommendations(db, limit);
console.log('\n═══ Recommendation Results ═══\n');
console.log(`Processed: ${result.processed}, Recommendations: ${result.recommendations_generated}`);
}
// ── Trendscope Integration Command ──
async function runTrendEnrichment() {
const limit = parseInt(getArg('--limit') || '200', 10);
const result = await enrichWithTrends(db, limit);
console.log('\n═══ Trend Enrichment Results ═══\n');
console.log(`Processed: ${result.processed}, Enriched: ${result.enriched}, No match: ${result.no_match}`);
}
// ── F3: Semantic Dedup Command ──
async function dedupSemantic(args = {}) {
const limit = parseInt(args.limit || getArg('--limit') || '100', 10);
const threshold = parseFloat(args.threshold || getArg('--threshold') || '0.92');
const result = await runSemanticDedup(db, limit, threshold);
console.log('\n═══ Semantic Dedup Results ═══\n');
console.log(`Groups found: ${result.groups_found}, Canonical selected: ${result.canonical_selected}, Links created: ${result.links_created}`);
}
// ── F1: Predictive Quality Decay Command ──
async function decayPredict(args = {}) {
const limit = parseInt(args.limit || getArg('--limit') || '100', 10);
console.log(`Scoring decay risk for up to ${limit} artifacts...`);
const result = await scoreBatchDecay(db, limit);
console.log(`Decay prediction complete: ${result.processed} processed, ${result.at_risk} at risk`);
}
// ── F5: Multi-Language Understanding Command ──
async function runUnderstanding(args = {}) {
const limit = parseInt(args.limit || getArg('--limit') || '50', 10);
console.log(`Extracting understanding for up to ${limit} artifacts...`);
const result = await batchExtractUnderstanding(db, limit);
console.log(`Understanding extraction: ${result.succeeded}/${result.processed} succeeded, ${result.failed} failed`);
}
async function runClaimExtraction(args = {}) {
const limit = parseInt(args.limit || getArg('--limit') || '100', 10);
console.log(`Extracting claims from up to ${limit} accepted source records...`);
const result = await batchExtractClaims(db, limit);
console.log(
`Claim extraction: ${result.created}/${result.processed} claims created, ` +
`${result.evidence_created} evidence records, ${result.skipped} skipped, ${result.failed} failed`,
);
}
async function runClaims() {
const limit = parseInt(getArg('--limit') || '20', 10);
const status = getArg('--status');
const claimType = getArg('--claim-type');
const subjectType = getArg('--subject-type');
const sourceRecordId = getArg('--source-record-id');
const search = getArg('--search');
const filters = {
limit,
status,
claimType,
subjectType,
sourceRecordId,
search,
};
const summary = await summarizeClaims(db, filters);
const result = await listClaims(db, filters);
console.log('\n=== Claims ===\n');
console.log(`Total claims: ${summary.total}`);
if (summary.by_status.length > 0) {
console.log('\nBy status:');
console.table(summary.by_status);
}
if (summary.by_type.length > 0) {
console.log('\nBy type:');
console.table(summary.by_type);
}
if (result.claims.length === 0) {
console.log('\nNo matching claims found.');
return;
}
console.table(result.claims.map((claim) => ({
id: claim.id,
status: claim.status,
claim_type: claim.claim_type,
subject_type: claim.subject_type || '-',
source_record_id: claim.source_record_id || '-',
confidence: claim.confidence,
summary: claim.summary || claim.claim_text,
})));
}
async function runClaimReview() {
const id = getArg('--id');
if (!id) {
throw new Error('--id is required');
}
const status = getArg('--status');
const confidenceArg = getArg('--confidence');
const summary = getArg('--summary');
const note = getArg('--note');
const updates = {};
if (status) updates.status = status;
if (confidenceArg !== null) updates.confidence = confidenceArg;
if (summary !== null) updates.summary = summary;
if (note) {
updates.metadata = {
review_note: note,
reviewed_at: new Date().toISOString(),
reviewer: 'cli',
};
}
const claim = await updateClaim(db, id, updates);
if (!claim) {
throw new Error('Claim not found');
}
console.log('\n=== Claim Updated ===\n');
console.table([{
id: claim.id,
status: claim.status,
claim_type: claim.claim_type,
confidence: claim.confidence,
summary: claim.summary || claim.claim_text,
}]);
}
async function runClaimQueue() {
const limit = parseInt(getArg('--limit') || '20', 10);
const status = getArg('--status');
const claimType = getArg('--claim-type');
const subjectType = getArg('--subject-type');
const sourceRecordId = getArg('--source-record-id');
const search = getArg('--search');
const filters = {
limit,
status,
claimType,
subjectType,
sourceRecordId,
search,
};
const summary = await summarizeClaims(db, filters);
const queue = await listClaimQueue(db, filters);
console.log('\n=== Claim Review Queue ===\n');
console.log(`Needs review: ${summary.review_queue.needs_review}`);
console.log(`Disputed: ${summary.review_queue.disputed}`);
console.log(`Accepted without support: ${summary.review_queue.accepted_without_support}`);
console.log(`With contradictions: ${summary.review_queue.contradicted}`);
if (queue.claims.length === 0) {
console.log('\nNo queued claims found.');
return;
}
console.table(queue.claims.map((claim) => ({
id: claim.id,
priority: claim.review_priority,
status: claim.status,
claim_type: claim.claim_type,
confidence: claim.confidence,
supports: claim.supports_count,
contradicts: claim.contradicts_count,
context: claim.context_count,
summary: claim.summary || claim.claim_text,
})));
}
// ── F11: Intelligence Graph Command ──
async function graphMaterialize(args = {}) {
console.log('Materializing intelligence graph...');
const result = await materializeGraph(db);
console.log(`Graph materialized: ${result.nodes_created} nodes, ${result.edges_created} edges`);
}
// ── Autonomy Expansion Command Handlers ──
async function runScheduleCmd() {
const sub = process.argv[3] || 'list';
const name = getArg('--name');
const scheduler = getScheduler(db);
if (sub === 'list') {
const schedules = await scheduler.listSchedules();
console.log('\n═══ Schedules ═══\n');
if (schedules.length === 0) {
console.log('No schedules registered.');
} else {
console.table(schedules);
}
} else if (sub === 'run' && name) {
const result = await scheduler.runNow(name);
console.log(`Schedule "${name}": ${JSON.stringify(result)}`);
} else if (sub === 'enable' && name) {
await scheduler.enable(name);
console.log(`Schedule "${name}" enabled.`);
} else if (sub === 'disable' && name) {
await scheduler.disable(name);
console.log(`Schedule "${name}" disabled.`);
} else {
console.log('Usage: schedule <list|run|enable|disable> [--name NAME]');
}
}
async function runSnapshotCmd() {
const sub = process.argv[3] || 'list';
if (sub === 'create') {
const label = getArg('--label') || `snapshot-${new Date().toISOString().slice(0, 10)}`;
const snap = await createSnapshot(db, label);
console.log(`Snapshot created: ${snap.id} (${snap.label})`);
} else if (sub === 'list') {
const snaps = await listSnapshots(db);
console.log('\n═══ Snapshots ═══\n');
if (snaps.length === 0) {
console.log('No snapshots found.');
} else {
console.table(snaps.map(s => ({ id: s.id, label: s.label, created_at: s.created_at })));
}
} else if (sub === 'compare') {
const a = getArg('--a');
const b = getArg('--b');
if (!a || !b) {
console.log('Usage: snapshot compare --a <ID> --b <ID>');
return;
}
const diff = await compareSnapshots(db, a, b);
console.log('\n═══ Snapshot Comparison ═══\n');
console.log(JSON.stringify(diff, null, 2));
} else {
console.log('Usage: snapshot <create|list|compare> [--label L] [--a ID --b ID]');
}
}
async function runDiscoverCmd() {
const sub = process.argv[3] || 'clusters';
if (sub === 'related') {
const id = getArg('--id');
if (!id) {
console.log('Usage: discover related --id <ARTIFACT_ID>');
return;
}
const results = await discoverRelated(db, id);
console.log('\n═══ Related Artifacts ═══\n');
console.log(JSON.stringify(results, null, 2));
} else if (sub === 'clusters') {
const results = await discoverClusters(db);
console.log('\n═══ Clusters ═══\n');
console.log(`Found ${results.length} clusters`);
console.log(JSON.stringify(results, null, 2));
} else if (sub === 'bridges') {
const results = await discoverBridges(db);
console.log('\n═══ Bridge Nodes ═══\n');
console.log(JSON.stringify(results, null, 2));
} else {
console.log('Usage: discover <related|clusters|bridges> [--id ID]');
}
}
async function runCoverageCmd() {
const report = await getCoverageReport(db);
console.log('\n═══ Coverage Report ═══\n');
console.log(`Categories: ${report.summary.total_categories}, Types: ${report.summary.total_types}`);
console.log(`Coverage score: ${report.summary.avg_coverage}`);
if (report.gaps.length > 0) {
console.log(`\nGaps (${report.gaps.length}):`);
console.table(report.gaps);
}
}
async function runCompareCmd() {
const period = getArg('--period') || 'week';
const sub = process.argv[3] || 'this-vs-last';
if (sub === 'velocity') {
const report = await velocityReport(db, period);
console.log('\n═══ Velocity Report ═══\n');
console.log(JSON.stringify(report, null, 2));
} else {
const report = await thisVsLast(db, period);
console.log(`\n═══ This vs Last ${period} ═══\n`);
console.log(JSON.stringify(report, null, 2));
}
}
async function runAutoRefresh() {
const threshold = parseFloat(getArg('--threshold') || '0.6');
const limit = parseInt(getArg('--limit') || '50', 10);
console.log(`Auto-refreshing stale artifacts (threshold=${threshold}, limit=${limit})...`);
const result = await refreshBatch(db, { threshold, limit });
console.log(`Auto-refresh complete: ${result.refreshed}/${result.scanned} refreshed, ${result.errors} errors`);
}
async function runSyncTrends() {
console.log('Syncing intelligence with Trendscope...');
const result = await syncFromTrendscope(db);
console.log(`Sync complete: ${JSON.stringify(result)}`);
}
async function runPulse() {
const { handleAutonomyPulse } = await import('./api/autonomy-routes.js');
// Direct DB query for CLI pulse
const schedules = await db.query('SELECT name, enabled, last_status, last_run, run_count FROM schedules ORDER BY name');
const staleCount = await db.query(
`SELECT COUNT(*) as count FROM artifacts
WHERE type_metadata IS NOT NULL
AND type_metadata::jsonb -> 'decay_prediction' ->> 'decay_risk' IS NOT NULL
AND (type_metadata::jsonb -> 'decay_prediction' ->> 'decay_risk')::float >= 0.6`
);
console.log('\n═══ Autonomy System Pulse ═══\n');
console.log(`Stale artifacts: ${staleCount.rows[0]?.count || 0}`);
if (schedules.rows.length > 0) {
console.log('\nSchedules:');
console.table(schedules.rows);
}
}
async function runErrors() {
const limit = parseInt(getArg('--limit') || '20', 10);
const level = getArg('--level') || 'error,warn';
const category = getArg('--category');
const source = getArg('--source');
const command = getArg('--command');
const runId = getArg('--run-id');
const systemRunId = getArg('--system-run-id');
const requestPath = getArg('--request-path');
const search = getArg('--search');
const sinceHours = parseInt(getArg('--since-hours') || '24', 10);
const filters = {
limit,
level,
category,
source,
command,
runId,
systemRunId,
requestPath,
search,
sinceHours,
};
const summary = await summarizeOperationLogs(db, filters);
const result = await listOperationLogs(db, {
...filters,
});
console.log('\n=== Operational Errors ===\n');
console.log(`Window: last ${summary.window_hours}h`);
console.log(`Total logs: ${summary.total}`);
if (summary.by_level.length > 0) {
console.log('\nBy level:');
console.table(summary.by_level);
}
if (summary.by_category.length > 0) {
console.log('\nBy category:');
console.table(summary.by_category);
}
if (result.logs.length > 0) {
console.log('\nRecent entries:');
console.table(result.logs.map(log => ({
created_at: log.created_at?.toISOString?.() ? log.created_at.toISOString() : log.created_at,
level: log.level,
category: log.category,
event_type: log.event_type,
source: log.source || log.command || log.request_path || '-',
run_id: log.run_id || '-',
system_run_id: log.system_run_id || '-',
message: log.message,
})));
} else {
console.log('\nNo matching logs found.');
}
}
async function runRuns() {
const limit = parseInt(getArg('--limit') || '20', 10);
const status = getArg('--status');
const source = getArg('--source');
const result = await listHarvestRuns(db, { limit, status, source });
console.log('\n=== Harvest Runs ===\n');
console.log(`Total matching runs: ${result.total}`);
if (result.runs.length === 0) {
console.log('No harvest runs found.');
return;
}
console.table(result.runs.map(run => ({
id: run.id,
source: run.source,
status: run.status,
discovered: run.items_discovered,
new: run.items_new,
duplicate: run.items_duplicate,
invalid: run.items_invalid,
warnings: run.warning_events,
errors: run.error_events,
started_at: run.started_at?.toISOString?.() ? run.started_at.toISOString() : run.started_at,