npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cosca-semantic-tags

v1.1.0

Published

Infrastructure semantic tagging engine for purpose-driven code analysis

Downloads

7

Readme

@cosca/semantic-tags

🏗️ Semantic code analysis for infrastructure patterns and purpose-driven metadata

npm version License: MIT

A TypeScript/JavaScript library for analyzing code and detecting infrastructure patterns, purpose-driven metadata, and semantic tags. Built by COSCA for purpose-driven infrastructure analysis.

🚀 Installation

npm install @cosca/semantic-tags

📖 Usage

Basic Analysis

import { analyzeCode, SemanticAnalysisResult } from '@cosca/semantic-tags';

const terraformCode = `
resource "aws_s3_bucket" "data_lake" {
  bucket = "company-data-lake"
  
  tags = {
    purpose = "analytics_storage"
    expiry = "2_years"
    owner = "data_team"
  }
}
`;

const result: SemanticAnalysisResult = analyzeCode(terraformCode, 'terraform');

console.log('COSCA Readiness Score:', result.coscaReadinessScore);
console.log('Infrastructure Tags:', result.infraTagCount);
console.log('Has Purpose Metadata:', result.hasPurposeMetadata);

File Analysis

import { analyzeFile } from '@cosca/semantic-tags';
import fs from 'fs';

const content = fs.readFileSync('infrastructure.tf', 'utf8');
const result = analyzeFile('infrastructure.tf', content);

console.log('Analysis Results:', {
  totalTags: result.totalTags,
  topPatterns: result.insights.topPatterns,
  isInfrastructure: result.isInfraFile
});

Advanced Usage with Custom Analyzer

import { SemanticAnalyzer } from '@cosca/semantic-tags';

const analyzer = new SemanticAnalyzer();
const result = analyzer.analyze(codeContent);

// Access detailed tag information
result.tags.forEach(tag => {
  console.log(`${tag.label} found at line ${tag.line + 1}: "${tag.match}"`);
});

🏷️ Detected Patterns

Infrastructure Patterns

  • Infrastructure as Code: terraform, pulumi, cloudformation
  • Cloud Services: s3, ec2, lambda, rds, dynamodb
  • Containers: docker, kubernetes, k8s, pod, deployment
  • Compute: cpu, memory, gpu, instance, cluster
  • Storage: bucket, volume, disk, backup
  • Observability: metrics, logs, prometheus, grafana

Purpose-Driven Metadata (COSCA-specific)

  • Purpose: purpose = "web_server"
  • Expiry: expiry = "30_days"
  • Owner: owner = "platform_team"

General Code Patterns

  • Network: fetch, axios, http.get
  • Debug: console.log, print, debugger
  • TODOs: TODO, FIXME, HACK
  • Database: SELECT, query, findOne
  • Auth: login, token, jwt

📊 Analysis Results

The SemanticAnalysisResult interface provides:

interface SemanticAnalysisResult {
  totalTags: number;                    // Total semantic tags found
  tags: SemanticTag[];                  // Detailed tag information
  tagCounts: Record<string, number>;    // Count by tag type
  infraTagCount: number;                // Infrastructure-specific tags
  isInfraFile: boolean;                 // Contains infrastructure patterns
  hasPurposeMetadata: boolean;          // Contains COSCA metadata
  coscaReadinessScore: number;          // 0-100 readiness score
  insights: {
    topPatterns: [string, number][];    // Most common patterns
    purposeTags: number;                // Purpose metadata count
    expiryTags: number;                 // Expiry metadata count
    ownerTags: number;                  // Owner metadata count
  };
}

🎯 COSCA Readiness Score

The library calculates a "COSCA Readiness Score" (0-100) based on:

  • Infrastructure pattern density
  • Purpose-driven metadata presence
  • Resource lifecycle awareness

Score = (Infrastructure Tags + Purpose Metadata) / Total Tags × 100

🔧 Supported File Types

  • Terraform: .tf files
  • Kubernetes: .yaml, .yml manifests
  • Docker: docker-compose.yml, Dockerfile
  • JavaScript/TypeScript: .js, .ts
  • Python: .py
  • Go: .go
  • JSON: .json

📈 Use Cases

DevOps & Infrastructure

// Analyze Terraform files for infrastructure patterns
const infraAnalysis = analyzeFile('main.tf', terraformContent);
if (infraAnalysis.coscaReadinessScore < 50) {
  console.warn('Low COSCA readiness - consider adding purpose metadata');
}

Code Quality Analysis

// Check for debug statements in production code
const codeAnalysis = analyzeCode(sourceCode, 'javascript');
const debugTags = codeAnalysis.tagCounts['debug'] || 0;
if (debugTags > 0) {
  console.warn(`Found ${debugTags} debug statements`);
}

CI/CD Integration

// Validate infrastructure files in CI pipeline
import glob from 'glob';

const infraFiles = glob.sync('**/*.tf');
let totalReadinessScore = 0;

infraFiles.forEach(file => {
  const content = fs.readFileSync(file, 'utf8');
  const analysis = analyzeFile(file, content);
  totalReadinessScore += analysis.coscaReadinessScore;
  
  if (!analysis.hasPurposeMetadata) {
    console.error(`${file}: Missing purpose metadata`);
  }
});

const avgReadiness = totalReadinessScore / infraFiles.length;
console.log(`Average COSCA Readiness: ${avgReadiness}%`);

🤝 Contributing

This library is part of the COSCA ecosystem. Contributions welcome!

git clone https://github.com/coscatech/semantic-tags-plugin.git
cd semantic-tags-plugin/lib
npm install
npm run build
npm test

📄 License

MIT License - see LICENSE file for details.

🔗 Related Projects


Built with ❤️ by the COSCA team

Making infrastructure smarter, one semantic tag at a time.