OverviewFilesCommitsIssuesDocsReleasesPeers

knowledge-ratchet / pipeline.js

88 lines · javascript ref:
#!/usr/bin/env node

// Merged Pipeline — Single-Pass Analysis
// Knowledge Ratchet Phase 2
//
// Replaces running fuse-signals.js + analyze-transcripts.js separately.
// Reads all JSONL files once via scan-sessions.js, then runs both
// scoring systems on the shared data.
//
// Usage:
//   node pipeline.js                   # full pipeline (scan + fuse + sentiment)
//   node pipeline.js --recent=7        # only last 7 days
//   node pipeline.js --session=UUID    # single session
//
// This is the fast pipeline for end-of-session runs.
// Does NOT include: LLM analyzer, regex tuner, ratchet pipeline (those need batch mode).

const { execSync } = require('child_process')
const path = require('path')

const DIR = __dirname

function run (label, cmd) {
  const start = Date.now()
  try {
    execSync(cmd, { cwd: DIR, encoding: 'utf8', stdio: 'inherit', timeout: 300000 })
  } catch (e) {
    console.error(`  ${label} failed: ${e.message.slice(0, 200)}`)
  }
  return Date.now() - start
}

async function main () {
  const args = process.argv.slice(2).join(' ')
  const start = Date.now()

  console.log(`Knowledge Ratchet — Fast Pipeline`)
  console.log(`Started: ${new Date().toISOString()}`)

  // Step 1: Sensor fusion (includes single-pass JSONL scan)
  const t1 = run('Sensor Fusion', `node ${path.join(DIR, 'fuse-signals.js')} ${args}`)

  // Step 2: Meta-ratchet (reads fused-turns-detail.json, <0.1s)
  const t2 = run('Meta-Ratchet', `node ${path.join(DIR, 'meta-ratchet.js')}`)

  // Step 3: Coverage map (reads corrections.log, ~1s)
  const t3 = run('Coverage Map', `node ${path.join(DIR, 'coverage-map.js')} --summary`)

  // Step 4: Regression check (reads corrections.log + fused scores, <0.1s)
  const t4 = run('Regression', `node ${path.join(DIR, 'regress.js')}`)

  // Step 5: Loop detection (reads fused-turns-detail.json, <0.5s)
  const t5 = run('Loop Detector', `node ${path.join(DIR, 'loop-detector.js')}`)

  // Step 6: Rule extractor (auto-generates rules from resolved loops)
  run('Rule Extractor', `node ${path.join(DIR, 'rule-extractor.js')}`)

  // Step 7: Project mapper
  run('Project Mapper', `node ${path.join(DIR, 'project-mapper.js')}`)

  // Step 8: Benchmarks → history
  run('Benchmarks', `node ${path.join(DIR, 'benchmark-ratchet.js')}`)

  // Step 9: Dashboard
  run('Dashboard', `node ${path.join(DIR, 'dashboard.js')} --no-open`)

  // Step 10: AtomSpace ingest (optional — skips if CogServer not running)
  try {
    const { isCogServerUp } = require('./atomspace/cogserver')
    const up = await isCogServerUp()
    if (up) {
      run('AtomSpace Ingest', `node ${path.join(DIR, 'atomspace', 'ingest.js')}`)
    } else {
      console.log('  AtomSpace: CogServer not running, skipping ingest')
    }
  } catch {
    // atomspace module not available — skip silently
  }

  const total = Date.now() - start
  console.log(`\nFast pipeline: ${(total / 1000).toFixed(1)}s`)
}

main().catch(err => {
  console.error('Pipeline failed:', err.message)
  process.exit(1)
})