thumbgate 0.9.10
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.
- package/.claude-plugin/README.md +134 -0
- package/.claude-plugin/bundle/icon.png +0 -0
- package/.claude-plugin/bundle/icon.svg +18 -0
- package/.claude-plugin/bundle/server/index.js +24 -0
- package/.claude-plugin/marketplace.json +36 -0
- package/.claude-plugin/plugin.json +21 -0
- package/.well-known/mcp/server-card.json +231 -0
- package/LICENSE +21 -0
- package/README.md +375 -0
- package/adapters/README.md +9 -0
- package/adapters/amp/skills/thumbgate-feedback/SKILL.md +22 -0
- package/adapters/chatgpt/INSTALL.md +83 -0
- package/adapters/chatgpt/openapi.yaml +1281 -0
- package/adapters/claude/.mcp.json +14 -0
- package/adapters/codex/config.toml +9 -0
- package/adapters/gemini/function-declarations.json +224 -0
- package/adapters/mcp/server-stdio.js +788 -0
- package/adapters/opencode/opencode.json +15 -0
- package/bin/cli.js +1484 -0
- package/bin/memory.sh +64 -0
- package/bin/obsidian-sync.sh +20 -0
- package/bin/postinstall.js +37 -0
- package/config/build-metadata.json +4 -0
- package/config/e2e-critical-flows.json +45 -0
- package/config/gate-templates.json +77 -0
- package/config/gates/claim-verification.json +29 -0
- package/config/gates/computer-use.json +39 -0
- package/config/gates/default.json +117 -0
- package/config/github-about.json +25 -0
- package/config/mcp-allowlists.json +135 -0
- package/config/model-tiers.json +33 -0
- package/config/partner-routing.json +132 -0
- package/config/policy-bundles/constrained-v1.json +64 -0
- package/config/policy-bundles/default-v1.json +91 -0
- package/config/rubrics/default-v1.json +52 -0
- package/config/skill-packs/react-testing.json +23 -0
- package/config/skill-packs/stripe-integration/references/api-spec.json +1 -0
- package/config/skill-packs/stripe-integration/references/webhook-guide.md +3 -0
- package/config/skill-specs/pr-reviewer.json +9 -0
- package/config/skill-specs/release-status.json +9 -0
- package/config/skill-specs/ticket-triage.json +9 -0
- package/config/subagent-profiles.json +32 -0
- package/config/tessl-tiles.json +29 -0
- package/config/thumbgate-settings.managed.json +12 -0
- package/openapi/openapi.yaml +1281 -0
- package/package.json +283 -0
- package/plugins/amp-skill/INSTALL.md +52 -0
- package/plugins/amp-skill/SKILL.md +64 -0
- package/plugins/claude-codex-bridge/.claude-plugin/plugin.json +22 -0
- package/plugins/claude-codex-bridge/.mcp.json +12 -0
- package/plugins/claude-codex-bridge/INSTALL.md +43 -0
- package/plugins/claude-codex-bridge/README.md +46 -0
- package/plugins/claude-codex-bridge/scripts/codex-bridge.js +288 -0
- package/plugins/claude-codex-bridge/skills/adversarial-review/SKILL.md +24 -0
- package/plugins/claude-codex-bridge/skills/result/SKILL.md +22 -0
- package/plugins/claude-codex-bridge/skills/review/SKILL.md +28 -0
- package/plugins/claude-codex-bridge/skills/second-pass/SKILL.md +27 -0
- package/plugins/claude-codex-bridge/skills/setup/SKILL.md +21 -0
- package/plugins/claude-codex-bridge/skills/status/SKILL.md +19 -0
- package/plugins/claude-skill/INSTALL.md +55 -0
- package/plugins/claude-skill/SKILL.md +46 -0
- package/plugins/codex-profile/.codex-plugin/plugin.json +43 -0
- package/plugins/codex-profile/.mcp.json +12 -0
- package/plugins/codex-profile/AGENTS.md +20 -0
- package/plugins/codex-profile/INSTALL.md +66 -0
- package/plugins/codex-profile/README.md +37 -0
- package/plugins/cursor-marketplace/.cursor-plugin/plugin.json +23 -0
- package/plugins/cursor-marketplace/CHANGELOG.md +30 -0
- package/plugins/cursor-marketplace/LICENSE +21 -0
- package/plugins/cursor-marketplace/README.md +124 -0
- package/plugins/cursor-marketplace/agents/reliability-reviewer.md +31 -0
- package/plugins/cursor-marketplace/assets/logo-400x400.png +0 -0
- package/plugins/cursor-marketplace/commands/capture-feedback.md +33 -0
- package/plugins/cursor-marketplace/commands/check-gates.md +25 -0
- package/plugins/cursor-marketplace/commands/show-lessons.md +27 -0
- package/plugins/cursor-marketplace/hooks/hooks.json +10 -0
- package/plugins/cursor-marketplace/mcp.json +12 -0
- package/plugins/cursor-marketplace/rules/feedback-capture.mdc +34 -0
- package/plugins/cursor-marketplace/rules/pre-action-gates.mdc +30 -0
- package/plugins/cursor-marketplace/rules/session-continuity.mdc +28 -0
- package/plugins/cursor-marketplace/scripts/gate-check.sh +11 -0
- package/plugins/cursor-marketplace/skills/capture-feedback/SKILL.md +47 -0
- package/plugins/cursor-marketplace/skills/prevention-rules/SKILL.md +31 -0
- package/plugins/cursor-marketplace/skills/recall-context/SKILL.md +30 -0
- package/plugins/cursor-marketplace/skills/search-lessons/SKILL.md +33 -0
- package/plugins/gemini-extension/INSTALL.md +92 -0
- package/plugins/gemini-extension/gemini_prompt.txt +14 -0
- package/plugins/gemini-extension/tool_contract.json +45 -0
- package/plugins/opencode-profile/INSTALL.md +57 -0
- package/public/assets/instagram-card.png +0 -0
- package/public/assets/tiktok-agent-memory.mp4 +0 -0
- package/public/blog.html +400 -0
- package/public/dashboard.html +1093 -0
- package/public/guide.html +317 -0
- package/public/index.html +1014 -0
- package/public/learn/agent-harness-pattern.html +180 -0
- package/public/learn/ai-agent-persistent-memory.html +202 -0
- package/public/learn/learn.css +45 -0
- package/public/learn/mcp-pre-action-gates-explained.html +172 -0
- package/public/learn/stop-ai-agent-force-push.html +134 -0
- package/public/learn/vibe-coding-safety-net.html +142 -0
- package/public/learn.html +213 -0
- package/public/lessons.html +650 -0
- package/public/vercel.json +8 -0
- package/scripts/__pycache__/train_from_feedback.cpython-312.pyc +0 -0
- package/scripts/a2ui-engine.js +73 -0
- package/scripts/access-anomaly-detector.js +12 -0
- package/scripts/adk-consolidator.js +266 -0
- package/scripts/agent-readiness.js +220 -0
- package/scripts/agent-security-hardening.js +227 -0
- package/scripts/agentic-data-pipeline.js +847 -0
- package/scripts/analytics-report.js +328 -0
- package/scripts/analytics-window.js +158 -0
- package/scripts/async-job-runner.js +1001 -0
- package/scripts/audit-trail.js +398 -0
- package/scripts/auto-promote-gates.js +299 -0
- package/scripts/auto-wire-hooks.js +312 -0
- package/scripts/autonomous-sales-agent.js +39 -0
- package/scripts/autoresearch-runner.js +216 -0
- package/scripts/background-agent-governance.js +237 -0
- package/scripts/behavioral-extraction.js +97 -0
- package/scripts/belief-update.js +84 -0
- package/scripts/billing.js +2438 -0
- package/scripts/bot-detector.js +50 -0
- package/scripts/budget-guard.js +173 -0
- package/scripts/build-claude-mcpb.js +189 -0
- package/scripts/build-metadata.js +97 -0
- package/scripts/check-congruence.js +322 -0
- package/scripts/cli-feedback.js +135 -0
- package/scripts/cli-telemetry.js +87 -0
- package/scripts/cloudflare-dynamic-sandbox.js +315 -0
- package/scripts/code-reasoning.js +350 -0
- package/scripts/codegraph-context.js +466 -0
- package/scripts/commercial-offer.js +56 -0
- package/scripts/computer-use-firewall.js +250 -0
- package/scripts/context-engine.js +694 -0
- package/scripts/contextfs.js +1287 -0
- package/scripts/conversation-context.js +119 -0
- package/scripts/creator-campaigns.js +239 -0
- package/scripts/daemon-manager.js +108 -0
- package/scripts/daily-digest.js +11 -0
- package/scripts/dashboard-render-spec.js +395 -0
- package/scripts/dashboard.js +1058 -0
- package/scripts/data-governance.js +173 -0
- package/scripts/delegation-runtime.js +900 -0
- package/scripts/deploy-gcp.sh +44 -0
- package/scripts/deploy-policy.js +263 -0
- package/scripts/disagreement-mining.js +315 -0
- package/scripts/dispatch-brief.js +159 -0
- package/scripts/distribution-surfaces.js +44 -0
- package/scripts/dpo-optimizer.js +209 -0
- package/scripts/ephemeral-agent-store.js +219 -0
- package/scripts/eval-harness.js +56 -0
- package/scripts/evolution-state.js +241 -0
- package/scripts/experiment-tracker.js +267 -0
- package/scripts/export-databricks-bundle.js +242 -0
- package/scripts/export-dpo-pairs.js +345 -0
- package/scripts/export-kto-pairs.js +310 -0
- package/scripts/export-training.js +448 -0
- package/scripts/failure-diagnostics.js +558 -0
- package/scripts/feedback-attribution.js +313 -0
- package/scripts/feedback-fallback.js +111 -0
- package/scripts/feedback-history-distiller.js +391 -0
- package/scripts/feedback-inbox-read.js +162 -0
- package/scripts/feedback-loop.js +1887 -0
- package/scripts/feedback-paths.js +145 -0
- package/scripts/feedback-quality.js +139 -0
- package/scripts/feedback-root-consolidator.js +238 -0
- package/scripts/feedback-schema.js +426 -0
- package/scripts/feedback-session.js +286 -0
- package/scripts/feedback-to-memory.js +185 -0
- package/scripts/feedback-to-rules.js +163 -0
- package/scripts/filesystem-search.js +404 -0
- package/scripts/funnel-analytics.js +35 -0
- package/scripts/gate-satisfy.js +42 -0
- package/scripts/gate-stats.js +116 -0
- package/scripts/gate-templates.js +70 -0
- package/scripts/gates-engine.js +816 -0
- package/scripts/generate-paperbanana-diagrams.sh +99 -0
- package/scripts/generate-pretool-hook.sh +40 -0
- package/scripts/github-about.js +350 -0
- package/scripts/github-outreach.js +65 -0
- package/scripts/gtm-revenue-loop.js +520 -0
- package/scripts/hallucination-detector.js +226 -0
- package/scripts/hf-papers.js +317 -0
- package/scripts/history-distiller.js +200 -0
- package/scripts/hook-auto-capture.sh +95 -0
- package/scripts/hook-stop-pr-thread-check.sh +68 -0
- package/scripts/hook-stop-self-score.sh +51 -0
- package/scripts/hook-stop-verify-deploy.sh +31 -0
- package/scripts/hook-thumbgate-cache-updater.js +48 -0
- package/scripts/hook-verify-before-done.sh +20 -0
- package/scripts/hosted-config.js +170 -0
- package/scripts/hybrid-feedback-context.js +676 -0
- package/scripts/install-mcp.js +159 -0
- package/scripts/intent-router.js +392 -0
- package/scripts/internal-agent-bootstrap.js +490 -0
- package/scripts/jsonl-watcher.js +155 -0
- package/scripts/lesson-db.js +613 -0
- package/scripts/lesson-inference.js +315 -0
- package/scripts/lesson-retrieval.js +95 -0
- package/scripts/lesson-rotation.js +137 -0
- package/scripts/lesson-search.js +644 -0
- package/scripts/lesson-synthesis.js +196 -0
- package/scripts/license.js +50 -0
- package/scripts/local-model-profile.js +383 -0
- package/scripts/markdown-escape.js +12 -0
- package/scripts/marketing-experiment.js +671 -0
- package/scripts/mcp-config.js +149 -0
- package/scripts/mcp-policy.js +99 -0
- package/scripts/memalign-recall.js +111 -0
- package/scripts/memory-firewall.js +222 -0
- package/scripts/memory-migration.js +296 -0
- package/scripts/meta-policy.js +194 -0
- package/scripts/metered-billing.js +16 -0
- package/scripts/model-tier-router.js +301 -0
- package/scripts/money-watcher.js +71 -0
- package/scripts/multi-hop-recall.js +240 -0
- package/scripts/natural-language-harness.js +330 -0
- package/scripts/obsidian-export.js +712 -0
- package/scripts/operational-dashboard.js +103 -0
- package/scripts/operational-summary.js +93 -0
- package/scripts/optimize-context.js +17 -0
- package/scripts/org-dashboard.js +201 -0
- package/scripts/partner-orchestration.js +146 -0
- package/scripts/per-step-scoring.js +165 -0
- package/scripts/perplexity-marketing.js +466 -0
- package/scripts/pii-scanner.js +153 -0
- package/scripts/plan-gate.js +154 -0
- package/scripts/post-everywhere.js +308 -0
- package/scripts/post-to-x-retry.sh +22 -0
- package/scripts/post-to-x.js +369 -0
- package/scripts/pr-manager.js +236 -0
- package/scripts/predictive-insights.js +356 -0
- package/scripts/principle-extractor.js +162 -0
- package/scripts/pro-features.js +40 -0
- package/scripts/pro-local-dashboard.js +174 -0
- package/scripts/problem-detail.js +53 -0
- package/scripts/product-feedback.js +134 -0
- package/scripts/profile-router.js +245 -0
- package/scripts/prompt-dlp.js +221 -0
- package/scripts/prompt-guard.js +83 -0
- package/scripts/prove-adapters.js +863 -0
- package/scripts/prove-attribution.js +365 -0
- package/scripts/prove-automation.js +653 -0
- package/scripts/prove-autoresearch.js +304 -0
- package/scripts/prove-claim-verification.js +277 -0
- package/scripts/prove-cloudflare-sandbox.js +163 -0
- package/scripts/prove-data-pipeline.js +410 -0
- package/scripts/prove-data-quality.js +227 -0
- package/scripts/prove-evolution.js +352 -0
- package/scripts/prove-harnesses.js +287 -0
- package/scripts/prove-intelligence.js +259 -0
- package/scripts/prove-lancedb.js +371 -0
- package/scripts/prove-local-intelligence.js +342 -0
- package/scripts/prove-loop-closure.js +263 -0
- package/scripts/prove-predictive-insights.js +357 -0
- package/scripts/prove-runtime.js +350 -0
- package/scripts/prove-seo-gsd.js +234 -0
- package/scripts/prove-settings.js +279 -0
- package/scripts/prove-subway-upgrades.js +277 -0
- package/scripts/prove-tessl.js +229 -0
- package/scripts/prove-training-export.js +327 -0
- package/scripts/prove-workflow-contract.js +116 -0
- package/scripts/prove-xmemory.js +332 -0
- package/scripts/publish-decision.js +133 -0
- package/scripts/pulse.js +80 -0
- package/scripts/rate-limiter.js +125 -0
- package/scripts/reddit-dm-outreach.js +182 -0
- package/scripts/reddit-monitor-cron.sh +26 -0
- package/scripts/reflector-agent.js +221 -0
- package/scripts/reminder-engine.js +132 -0
- package/scripts/revenue-status.js +472 -0
- package/scripts/risk-scorer.js +458 -0
- package/scripts/rlaif-self-audit.js +129 -0
- package/scripts/rubric-engine.js +230 -0
- package/scripts/schedule-manager.js +251 -0
- package/scripts/secret-scanner.js +414 -0
- package/scripts/self-heal.js +147 -0
- package/scripts/self-healing-check.js +188 -0
- package/scripts/semantic-layer.js +98 -0
- package/scripts/seo-gsd.js +1153 -0
- package/scripts/settings-hierarchy.js +214 -0
- package/scripts/shieldcortex-memory-firewall-runner.mjs +53 -0
- package/scripts/skill-exporter.js +262 -0
- package/scripts/skill-generator.js +446 -0
- package/scripts/skill-materializer.js +134 -0
- package/scripts/skill-packs.js +136 -0
- package/scripts/skill-proposer.js +99 -0
- package/scripts/skill-quality-tracker.js +284 -0
- package/scripts/slo-alert-engine.js +14 -0
- package/scripts/slow-loop.js +72 -0
- package/scripts/social-analytics/db/schema.sql +32 -0
- package/scripts/social-analytics/digest.js +256 -0
- package/scripts/social-analytics/generate-instagram-card.js +97 -0
- package/scripts/social-analytics/instagram-thumbgate-post.js +73 -0
- package/scripts/social-analytics/mcp-server.js +289 -0
- package/scripts/social-analytics/normalizer.js +580 -0
- package/scripts/social-analytics/notify.js +162 -0
- package/scripts/social-analytics/poll-all.js +107 -0
- package/scripts/social-analytics/pollers/github.js +195 -0
- package/scripts/social-analytics/pollers/instagram.js +253 -0
- package/scripts/social-analytics/pollers/linkedin.js +330 -0
- package/scripts/social-analytics/pollers/plausible.js +247 -0
- package/scripts/social-analytics/pollers/reddit.js +306 -0
- package/scripts/social-analytics/pollers/threads.js +233 -0
- package/scripts/social-analytics/pollers/tiktok.js +203 -0
- package/scripts/social-analytics/pollers/x.js +227 -0
- package/scripts/social-analytics/pollers/youtube.js +304 -0
- package/scripts/social-analytics/pollers/zernio.js +180 -0
- package/scripts/social-analytics/publish-instagram-thumbgate.js +85 -0
- package/scripts/social-analytics/publishers/devto.js +122 -0
- package/scripts/social-analytics/publishers/instagram.js +317 -0
- package/scripts/social-analytics/publishers/linkedin.js +294 -0
- package/scripts/social-analytics/publishers/reddit.js +390 -0
- package/scripts/social-analytics/publishers/threads.js +275 -0
- package/scripts/social-analytics/publishers/tiktok.js +217 -0
- package/scripts/social-analytics/publishers/x.js +259 -0
- package/scripts/social-analytics/publishers/youtube.js +223 -0
- package/scripts/social-analytics/publishers/zernio.js +209 -0
- package/scripts/social-analytics/run-digest.js +34 -0
- package/scripts/social-analytics/store.js +257 -0
- package/scripts/social-analytics/utm.js +143 -0
- package/scripts/social-pipeline.js +2628 -0
- package/scripts/social-quality-gate.js +18 -0
- package/scripts/social-reply-monitor.js +445 -0
- package/scripts/status-dashboard.js +155 -0
- package/scripts/statusline-lesson.js +16 -0
- package/scripts/statusline-tower.js +8 -0
- package/scripts/statusline.sh +116 -0
- package/scripts/stripe-live-status.js +115 -0
- package/scripts/subagent-profiles.js +79 -0
- package/scripts/sync-gh-secrets-from-env.sh +70 -0
- package/scripts/sync-github-about.js +52 -0
- package/scripts/sync-version.js +451 -0
- package/scripts/synthetic-dpo.js +234 -0
- package/scripts/telemetry-analytics.js +821 -0
- package/scripts/tessl-export.js +371 -0
- package/scripts/test-coverage.js +120 -0
- package/scripts/thompson-sampling.js +417 -0
- package/scripts/thumbgate-search.js +189 -0
- package/scripts/tool-kpi-tracker.js +12 -0
- package/scripts/tool-registry.js +811 -0
- package/scripts/train_from_feedback.py +910 -0
- package/scripts/user-profile.js +78 -0
- package/scripts/validate-feedback.js +580 -0
- package/scripts/validate-workflow-contract.js +287 -0
- package/scripts/vector-store.js +198 -0
- package/scripts/verification-loop.js +291 -0
- package/scripts/verify-obsidian-setup.sh +269 -0
- package/scripts/verify-run.js +269 -0
- package/scripts/webhook-delivery.js +62 -0
- package/scripts/weekly-auto-post.js +124 -0
- package/scripts/workflow-runs.js +154 -0
- package/scripts/workflow-sprint-intake.js +475 -0
- package/scripts/workspace-evolver.js +374 -0
- package/scripts/x-autonomous-marketing.js +139 -0
- package/scripts/xmemory-lite.js +405 -0
- package/skills/agent-memory/SKILL.md +97 -0
- package/skills/solve-architecture-autonomy/SKILL.md +17 -0
- package/skills/solve-architecture-autonomy/tool.js +33 -0
- package/skills/thumbgate/SKILL.md +114 -0
- package/skills/thumbgate-feedback/SKILL.md +49 -0
- package/src/api/server.js +4208 -0
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Helpers
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
function ensureDir(dirPath) {
|
|
11
|
+
if (!fs.existsSync(dirPath)) {
|
|
12
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readJSONL(filePath) {
|
|
17
|
+
if (!fs.existsSync(filePath)) return [];
|
|
18
|
+
const raw = fs.readFileSync(filePath, 'utf-8').trim();
|
|
19
|
+
if (!raw) return [];
|
|
20
|
+
return raw
|
|
21
|
+
.split('\n')
|
|
22
|
+
.map((line) => {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(line);
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.filter(Boolean);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function slugify(text, maxLen) {
|
|
33
|
+
maxLen = maxLen || 80;
|
|
34
|
+
return String(text || '')
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
37
|
+
.replace(/^-+|-+$/g, '')
|
|
38
|
+
.slice(0, maxLen);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function extractDate(entry) {
|
|
42
|
+
const ts = entry.timestamp || entry.date || entry.createdAt || entry.promotedAt || '';
|
|
43
|
+
if (!ts) return 'unknown';
|
|
44
|
+
const d = new Date(ts);
|
|
45
|
+
if (!Number.isFinite(d.getTime())) return 'unknown';
|
|
46
|
+
return d.toISOString().slice(0, 10);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Escape a YAML value — wrap in quotes if it contains colons, special chars,
|
|
51
|
+
* or starts with a YAML-special character.
|
|
52
|
+
*/
|
|
53
|
+
function yamlEscape(value) {
|
|
54
|
+
if (value === null || value === undefined) return '""';
|
|
55
|
+
const s = String(value);
|
|
56
|
+
if (s === '') return '""';
|
|
57
|
+
// Wrap in double quotes if it contains colons, #, [], {}, `, or starts with special chars
|
|
58
|
+
if (/[:\#\[\]\{\}`|>]/.test(s) || /^[&*!%@]/.test(s) || /^['"]/.test(s) || s.includes('\n')) {
|
|
59
|
+
return '"' + s.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
|
|
60
|
+
}
|
|
61
|
+
return s;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function yamlArray(arr) {
|
|
65
|
+
if (!arr || arr.length === 0) return '[]';
|
|
66
|
+
return '\n' + arr.map((item) => ' - ' + yamlEscape(item)).join('\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function buildFrontmatter(fields) {
|
|
70
|
+
const lines = ['---'];
|
|
71
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
lines.push(key + ': ' + yamlArray(value));
|
|
74
|
+
} else {
|
|
75
|
+
lines.push(key + ': ' + yamlEscape(value));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
lines.push('---');
|
|
79
|
+
return lines.join('\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function wikiLink(name) {
|
|
83
|
+
return '[[' + String(name || '') + ']]';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function tagWikiLinks(tags) {
|
|
87
|
+
if (!tags || !Array.isArray(tags) || tags.length === 0) return '';
|
|
88
|
+
return tags.map((t) => wikiLink(t)).join(', ');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function writeNote(filePath, frontmatter, body) {
|
|
92
|
+
ensureDir(path.dirname(filePath));
|
|
93
|
+
fs.writeFileSync(filePath, frontmatter + '\n\n' + body.trim() + '\n', 'utf-8');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// Export: Feedback Log
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
function exportFeedbackLog(feedbackDir, outputDir) {
|
|
101
|
+
const errors = [];
|
|
102
|
+
let exported = 0;
|
|
103
|
+
const logPath = path.join(feedbackDir, 'feedback-log.jsonl');
|
|
104
|
+
const entries = readJSONL(logPath);
|
|
105
|
+
const outDir = path.join(outputDir, 'Feedback');
|
|
106
|
+
ensureDir(outDir);
|
|
107
|
+
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
try {
|
|
110
|
+
if (!entry || !entry.id) {
|
|
111
|
+
errors.push('Skipped feedback entry with missing id');
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const date = extractDate(entry);
|
|
115
|
+
const slug = slugify(entry.context || entry.whatWentWrong || entry.whatWorked || entry.id);
|
|
116
|
+
const fileName = date + '-' + slug + '.md';
|
|
117
|
+
|
|
118
|
+
const signal = entry.signal === 'positive' || entry.signal === 'up' ? 'up' : 'down';
|
|
119
|
+
const tags = Array.isArray(entry.tags) ? entry.tags : [];
|
|
120
|
+
const category = entry.category || (tags[0] || 'uncategorized');
|
|
121
|
+
const actionType = entry.actionType || entry.action || 'feedback';
|
|
122
|
+
|
|
123
|
+
const fm = buildFrontmatter({
|
|
124
|
+
title: entry.context || entry.whatWentWrong || entry.whatWorked || entry.id,
|
|
125
|
+
date: date,
|
|
126
|
+
signal: signal,
|
|
127
|
+
category: category,
|
|
128
|
+
tags: tags,
|
|
129
|
+
actionType: actionType,
|
|
130
|
+
sourceFeedbackId: entry.id,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const bodyParts = ['# ' + (entry.context || entry.id)];
|
|
134
|
+
if (entry.whatWentWrong) {
|
|
135
|
+
bodyParts.push('\n## Context\n\n' + entry.whatWentWrong);
|
|
136
|
+
}
|
|
137
|
+
if (entry.whatWorked) {
|
|
138
|
+
bodyParts.push('\n## What Worked\n\n' + entry.whatWorked);
|
|
139
|
+
}
|
|
140
|
+
if (entry.correctiveAction || entry.whatToChange) {
|
|
141
|
+
bodyParts.push('\n## Corrective Action\n\n' + (entry.correctiveAction || entry.whatToChange));
|
|
142
|
+
}
|
|
143
|
+
if (tags.length > 0) {
|
|
144
|
+
bodyParts.push('\n## Tags\n\n' + tagWikiLinks(tags));
|
|
145
|
+
}
|
|
146
|
+
if (entry.toolName) {
|
|
147
|
+
bodyParts.push('\n## Tool\n\n`' + entry.toolName + '`');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
writeNote(path.join(outDir, fileName), fm, bodyParts.join('\n'));
|
|
151
|
+
exported++;
|
|
152
|
+
} catch (err) {
|
|
153
|
+
errors.push('Feedback entry error: ' + (err.message || String(err)));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return { exported, errors };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// Export: Memory Log
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
|
|
164
|
+
function exportMemoryLog(feedbackDir, outputDir) {
|
|
165
|
+
const errors = [];
|
|
166
|
+
let exported = 0;
|
|
167
|
+
const logPath = path.join(feedbackDir, 'memory-log.jsonl');
|
|
168
|
+
const entries = readJSONL(logPath);
|
|
169
|
+
const outDir = path.join(outputDir, 'Memories');
|
|
170
|
+
ensureDir(outDir);
|
|
171
|
+
|
|
172
|
+
for (const entry of entries) {
|
|
173
|
+
try {
|
|
174
|
+
if (!entry || !entry.id) {
|
|
175
|
+
errors.push('Skipped memory entry with missing id');
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const date = extractDate(entry);
|
|
179
|
+
const slug = slugify(entry.title || entry.content || entry.id);
|
|
180
|
+
const fileName = date + '-' + slug + '.md';
|
|
181
|
+
|
|
182
|
+
const tags = Array.isArray(entry.tags) ? entry.tags : [];
|
|
183
|
+
const category = entry.category || 'uncategorized';
|
|
184
|
+
const signal = entry.signal || (category === 'error' ? 'down' : 'up');
|
|
185
|
+
|
|
186
|
+
const fm = buildFrontmatter({
|
|
187
|
+
title: entry.title || entry.id,
|
|
188
|
+
date: date,
|
|
189
|
+
category: category,
|
|
190
|
+
tags: tags,
|
|
191
|
+
signal: signal,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const bodyParts = ['# ' + (entry.title || entry.id)];
|
|
195
|
+
if (entry.content) {
|
|
196
|
+
bodyParts.push('\n' + entry.content);
|
|
197
|
+
}
|
|
198
|
+
if (tags.length > 0) {
|
|
199
|
+
bodyParts.push('\n## Tags\n\n' + tagWikiLinks(tags));
|
|
200
|
+
}
|
|
201
|
+
if (entry.sourceFeedbackId) {
|
|
202
|
+
bodyParts.push('\n## Source\n\nBacklink: ' + wikiLink('Feedback/' + entry.sourceFeedbackId));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
writeNote(path.join(outDir, fileName), fm, bodyParts.join('\n'));
|
|
206
|
+
exported++;
|
|
207
|
+
} catch (err) {
|
|
208
|
+
errors.push('Memory entry error: ' + (err.message || String(err)));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return { exported, errors };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// Export: Prevention Rules
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
|
|
219
|
+
function deriveSeverity(text) {
|
|
220
|
+
const s = String(text || '').toLowerCase();
|
|
221
|
+
if (/\bcritical\b|\bblock\b|\bblocked\b|\bnever\b|\bforce push\b/.test(s)) return 'critical';
|
|
222
|
+
if (/\bhigh\b|\bwarn\b|\bdanger\b/.test(s)) return 'high';
|
|
223
|
+
if (/\blow\b|\bminor\b/.test(s)) return 'low';
|
|
224
|
+
return 'medium';
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function parsePreventionRulesMarkdown(content) {
|
|
228
|
+
const rules = [];
|
|
229
|
+
if (!content) return rules;
|
|
230
|
+
|
|
231
|
+
const lines = content.split('\n');
|
|
232
|
+
let current = null;
|
|
233
|
+
|
|
234
|
+
for (const line of lines) {
|
|
235
|
+
// Match rule headers like "## Rule: ...", "### ...", "## 1. ..." (skip top-level # headers)
|
|
236
|
+
const headerMatch = line.match(/^#{2,3}\s+(?:Rule:\s*)?(?:\d+\.\s*)?(.+)/);
|
|
237
|
+
if (headerMatch) {
|
|
238
|
+
if (current && current.title) {
|
|
239
|
+
// Derive severity from title + body before pushing
|
|
240
|
+
current.severity = deriveSeverity(current.title + ' ' + current.body);
|
|
241
|
+
rules.push(current);
|
|
242
|
+
}
|
|
243
|
+
current = {
|
|
244
|
+
title: headerMatch[1].trim(),
|
|
245
|
+
severity: 'medium',
|
|
246
|
+
source: 'prevention-rules.md',
|
|
247
|
+
body: '',
|
|
248
|
+
};
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (current) {
|
|
252
|
+
current.body += line + '\n';
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (current && current.title) {
|
|
256
|
+
current.severity = deriveSeverity(current.title + ' ' + current.body);
|
|
257
|
+
rules.push(current);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return rules;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function exportPreventionRules(feedbackDir, outputDir) {
|
|
264
|
+
const errors = [];
|
|
265
|
+
let exported = 0;
|
|
266
|
+
const rulesPath = path.join(feedbackDir, 'prevention-rules.md');
|
|
267
|
+
const outDir = path.join(outputDir, 'Rules');
|
|
268
|
+
ensureDir(outDir);
|
|
269
|
+
|
|
270
|
+
if (!fs.existsSync(rulesPath)) {
|
|
271
|
+
return { exported: 0, errors: [] };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let content;
|
|
275
|
+
try {
|
|
276
|
+
content = fs.readFileSync(rulesPath, 'utf-8');
|
|
277
|
+
} catch (err) {
|
|
278
|
+
return { exported: 0, errors: ['Failed to read prevention-rules.md: ' + err.message] };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const rules = parsePreventionRulesMarkdown(content);
|
|
282
|
+
const indexLinks = [];
|
|
283
|
+
|
|
284
|
+
for (const rule of rules) {
|
|
285
|
+
try {
|
|
286
|
+
const slug = slugify(rule.title);
|
|
287
|
+
if (!slug) {
|
|
288
|
+
errors.push('Skipped rule with empty title');
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const fileName = slug + '.md';
|
|
292
|
+
|
|
293
|
+
const fm = buildFrontmatter({
|
|
294
|
+
title: rule.title,
|
|
295
|
+
type: 'prevention-rule',
|
|
296
|
+
severity: rule.severity,
|
|
297
|
+
source: rule.source,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const body = '# ' + rule.title + '\n\n' + (rule.body || '').trim();
|
|
301
|
+
writeNote(path.join(outDir, fileName), fm, body);
|
|
302
|
+
indexLinks.push('- ' + wikiLink('Rules/' + slug));
|
|
303
|
+
exported++;
|
|
304
|
+
} catch (err) {
|
|
305
|
+
errors.push('Rule export error: ' + (err.message || String(err)));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Write index
|
|
310
|
+
if (indexLinks.length > 0) {
|
|
311
|
+
const indexFm = buildFrontmatter({
|
|
312
|
+
title: 'Prevention Rules Index',
|
|
313
|
+
type: 'index',
|
|
314
|
+
});
|
|
315
|
+
const indexBody = '# Prevention Rules Index\n\n' + indexLinks.join('\n');
|
|
316
|
+
writeNote(path.join(outDir, 'Prevention Rules Index.md'), indexFm, indexBody);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return { exported, errors };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ---------------------------------------------------------------------------
|
|
323
|
+
// Export: Gates
|
|
324
|
+
// ---------------------------------------------------------------------------
|
|
325
|
+
|
|
326
|
+
function exportGates(configPath, outputDir) {
|
|
327
|
+
const errors = [];
|
|
328
|
+
let exported = 0;
|
|
329
|
+
const outDir = path.join(outputDir, 'Gates');
|
|
330
|
+
ensureDir(outDir);
|
|
331
|
+
|
|
332
|
+
let gates = [];
|
|
333
|
+
|
|
334
|
+
// Read default gates config
|
|
335
|
+
if (fs.existsSync(configPath)) {
|
|
336
|
+
try {
|
|
337
|
+
const raw = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
338
|
+
if (Array.isArray(raw.gates)) {
|
|
339
|
+
gates = gates.concat(raw.gates);
|
|
340
|
+
}
|
|
341
|
+
} catch (err) {
|
|
342
|
+
errors.push('Failed to read gates config: ' + err.message);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Read auto-promoted gates if present (check common locations)
|
|
347
|
+
const autoGatePaths = [
|
|
348
|
+
path.join(path.dirname(configPath), '..', '.thumbgate', 'auto-promoted-gates.json'),
|
|
349
|
+
path.join(path.dirname(configPath), '..', '.claude', 'memory', 'feedback', 'auto-promoted-gates.json'),
|
|
350
|
+
];
|
|
351
|
+
for (const agPath of autoGatePaths) {
|
|
352
|
+
if (fs.existsSync(agPath)) {
|
|
353
|
+
try {
|
|
354
|
+
const raw = JSON.parse(fs.readFileSync(agPath, 'utf-8'));
|
|
355
|
+
if (Array.isArray(raw.gates)) {
|
|
356
|
+
gates = gates.concat(raw.gates);
|
|
357
|
+
}
|
|
358
|
+
} catch (err) {
|
|
359
|
+
errors.push('Failed to read auto-promoted gates: ' + err.message);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const indexLinks = [];
|
|
365
|
+
|
|
366
|
+
for (const gate of gates) {
|
|
367
|
+
try {
|
|
368
|
+
if (!gate || !gate.id) {
|
|
369
|
+
errors.push('Skipped gate with missing id');
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
const fileName = gate.id + '.md';
|
|
373
|
+
const action = gate.action || 'warn';
|
|
374
|
+
const tool = gate.trigger || gate.tool || 'any';
|
|
375
|
+
const pattern = gate.pattern || '';
|
|
376
|
+
|
|
377
|
+
const fm = buildFrontmatter({
|
|
378
|
+
title: gate.id,
|
|
379
|
+
type: 'gate',
|
|
380
|
+
action: action,
|
|
381
|
+
tool: tool,
|
|
382
|
+
pattern: pattern,
|
|
383
|
+
severity: gate.severity || 'medium',
|
|
384
|
+
layer: gate.layer || 'unknown',
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const bodyParts = ['# Gate: ' + gate.id];
|
|
388
|
+
if (gate.message) {
|
|
389
|
+
bodyParts.push('\n## Description\n\n' + gate.message);
|
|
390
|
+
}
|
|
391
|
+
bodyParts.push('\n## Match Conditions\n');
|
|
392
|
+
bodyParts.push('- **Pattern**: `' + pattern + '`');
|
|
393
|
+
bodyParts.push('- **Layer**: ' + (gate.layer || 'unknown'));
|
|
394
|
+
if (gate.unless) {
|
|
395
|
+
bodyParts.push('- **Unless**: `' + gate.unless + '`');
|
|
396
|
+
}
|
|
397
|
+
bodyParts.push('\n## Enforcement\n');
|
|
398
|
+
bodyParts.push('- **Action**: ' + action);
|
|
399
|
+
bodyParts.push('- **Severity**: ' + (gate.severity || 'medium'));
|
|
400
|
+
|
|
401
|
+
writeNote(path.join(outDir, fileName), fm, bodyParts.join('\n'));
|
|
402
|
+
indexLinks.push('- ' + wikiLink('Gates/' + gate.id));
|
|
403
|
+
exported++;
|
|
404
|
+
} catch (err) {
|
|
405
|
+
errors.push('Gate export error: ' + (err.message || String(err)));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Write index
|
|
410
|
+
if (indexLinks.length > 0) {
|
|
411
|
+
const indexFm = buildFrontmatter({
|
|
412
|
+
title: 'Gates Index',
|
|
413
|
+
type: 'index',
|
|
414
|
+
});
|
|
415
|
+
const indexBody = '# Gates Index\n\n' + indexLinks.join('\n');
|
|
416
|
+
writeNote(path.join(outDir, 'Gates Index.md'), indexFm, indexBody);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return { exported, errors };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// ---------------------------------------------------------------------------
|
|
423
|
+
// Export: ContextFS Packs
|
|
424
|
+
// ---------------------------------------------------------------------------
|
|
425
|
+
|
|
426
|
+
function exportContextFsPacks(feedbackDir, outputDir) {
|
|
427
|
+
const errors = [];
|
|
428
|
+
let exported = 0;
|
|
429
|
+
const provDir = path.join(feedbackDir, 'contextfs', 'provenance');
|
|
430
|
+
const outDir = path.join(outputDir, 'Context Packs');
|
|
431
|
+
ensureDir(outDir);
|
|
432
|
+
|
|
433
|
+
if (!fs.existsSync(provDir)) {
|
|
434
|
+
return { exported: 0, errors: [] };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Read packs.jsonl
|
|
438
|
+
const packsPath = path.join(provDir, 'packs.jsonl');
|
|
439
|
+
const packs = readJSONL(packsPath);
|
|
440
|
+
|
|
441
|
+
// Also try reading individual JSON files in provenance
|
|
442
|
+
let provFiles = [];
|
|
443
|
+
try {
|
|
444
|
+
provFiles = fs.readdirSync(provDir).filter((f) => f.endsWith('.json'));
|
|
445
|
+
} catch (_) { /* ignore */ }
|
|
446
|
+
|
|
447
|
+
for (const file of provFiles) {
|
|
448
|
+
try {
|
|
449
|
+
const raw = JSON.parse(fs.readFileSync(path.join(provDir, file), 'utf-8'));
|
|
450
|
+
if (raw && raw.packId && !packs.find((p) => p.packId === raw.packId)) {
|
|
451
|
+
packs.push(raw);
|
|
452
|
+
}
|
|
453
|
+
} catch (_) { /* skip malformed */ }
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
for (const pack of packs) {
|
|
457
|
+
try {
|
|
458
|
+
if (!pack || !pack.packId) {
|
|
459
|
+
errors.push('Skipped pack with missing packId');
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
const date = extractDate(pack);
|
|
463
|
+
const fileName = pack.packId + '.md';
|
|
464
|
+
|
|
465
|
+
const fm = buildFrontmatter({
|
|
466
|
+
packId: pack.packId,
|
|
467
|
+
date: date,
|
|
468
|
+
template: pack.template || 'unknown',
|
|
469
|
+
itemCount: pack.itemCount || (Array.isArray(pack.items) ? pack.items.length : 0),
|
|
470
|
+
usedChars: pack.usedChars || pack.charCount || 0,
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const bodyParts = ['# Context Pack: ' + pack.packId];
|
|
474
|
+
if (pack.template) {
|
|
475
|
+
bodyParts.push('\n**Template**: ' + pack.template);
|
|
476
|
+
}
|
|
477
|
+
if (Array.isArray(pack.items) && pack.items.length > 0) {
|
|
478
|
+
bodyParts.push('\n## Items\n');
|
|
479
|
+
for (const item of pack.items) {
|
|
480
|
+
if (typeof item === 'string') {
|
|
481
|
+
bodyParts.push('- ' + item);
|
|
482
|
+
} else if (item && item.id) {
|
|
483
|
+
bodyParts.push('- ' + wikiLink(item.namespace ? item.namespace + '/' + item.id : item.id));
|
|
484
|
+
} else if (item && item.content) {
|
|
485
|
+
bodyParts.push('- ' + String(item.content).slice(0, 100));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (pack.outcome) {
|
|
490
|
+
bodyParts.push('\n## Outcome\n\n' + String(pack.outcome));
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
writeNote(path.join(outDir, fileName), fm, bodyParts.join('\n'));
|
|
494
|
+
exported++;
|
|
495
|
+
} catch (err) {
|
|
496
|
+
errors.push('ContextFS pack error: ' + (err.message || String(err)));
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return { exported, errors };
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ---------------------------------------------------------------------------
|
|
504
|
+
// Export: Promoted Lessons
|
|
505
|
+
// ---------------------------------------------------------------------------
|
|
506
|
+
|
|
507
|
+
function exportLessons(feedbackDir, outputDir) {
|
|
508
|
+
const errors = [];
|
|
509
|
+
let exported = 0;
|
|
510
|
+
const outDir = path.join(outputDir, 'Lessons');
|
|
511
|
+
ensureDir(outDir);
|
|
512
|
+
|
|
513
|
+
// Lessons come from feedback entries that were promoted (generated rules or have promoted flag)
|
|
514
|
+
const feedbackPath = path.join(feedbackDir, 'feedback-log.jsonl');
|
|
515
|
+
const memoryPath = path.join(feedbackDir, 'memory-log.jsonl');
|
|
516
|
+
|
|
517
|
+
const feedbackEntries = readJSONL(feedbackPath);
|
|
518
|
+
const memoryEntries = readJSONL(memoryPath);
|
|
519
|
+
|
|
520
|
+
// Promoted lessons: memories with category 'learning' or 'error' that have content,
|
|
521
|
+
// or feedback entries with promoted flag
|
|
522
|
+
const lessons = [];
|
|
523
|
+
|
|
524
|
+
for (const mem of memoryEntries) {
|
|
525
|
+
if (!mem || !mem.id) continue;
|
|
526
|
+
const isPromoted = mem.promoted === true ||
|
|
527
|
+
mem.category === 'learning' ||
|
|
528
|
+
(mem.category === 'error' && mem.content);
|
|
529
|
+
if (isPromoted) {
|
|
530
|
+
lessons.push(mem);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// Also check feedback for explicitly promoted entries
|
|
535
|
+
for (const fb of feedbackEntries) {
|
|
536
|
+
if (!fb || !fb.id) continue;
|
|
537
|
+
if (fb.promoted === true && !lessons.find((l) => l.sourceFeedbackId === fb.id || l.id === fb.id)) {
|
|
538
|
+
lessons.push({
|
|
539
|
+
id: fb.id,
|
|
540
|
+
title: fb.context || fb.whatWentWrong || fb.whatWorked || fb.id,
|
|
541
|
+
date: fb.timestamp,
|
|
542
|
+
timestamp: fb.timestamp,
|
|
543
|
+
category: fb.category || 'learning',
|
|
544
|
+
tags: fb.tags,
|
|
545
|
+
content: fb.correctiveAction || fb.whatToChange || fb.whatWorked || '',
|
|
546
|
+
promoted: true,
|
|
547
|
+
sourceFeedbackId: fb.id,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const indexLinks = [];
|
|
553
|
+
|
|
554
|
+
for (const lesson of lessons) {
|
|
555
|
+
try {
|
|
556
|
+
const date = extractDate(lesson);
|
|
557
|
+
const slug = slugify(lesson.title || lesson.content || lesson.id);
|
|
558
|
+
if (!slug) {
|
|
559
|
+
errors.push('Skipped lesson with empty slug');
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
const fileName = date + '-' + slug + '.md';
|
|
563
|
+
|
|
564
|
+
const tags = Array.isArray(lesson.tags) ? lesson.tags : [];
|
|
565
|
+
const linkedRules = Array.isArray(lesson.linkedRules) ? lesson.linkedRules : [];
|
|
566
|
+
const linkedGates = Array.isArray(lesson.linkedGates) ? lesson.linkedGates : [];
|
|
567
|
+
|
|
568
|
+
const fm = buildFrontmatter({
|
|
569
|
+
title: lesson.title || lesson.id,
|
|
570
|
+
date: date,
|
|
571
|
+
category: lesson.category || 'learning',
|
|
572
|
+
promoted: true,
|
|
573
|
+
linkedRules: linkedRules,
|
|
574
|
+
linkedGates: linkedGates,
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
const bodyParts = ['# ' + (lesson.title || lesson.id)];
|
|
578
|
+
if (lesson.content) {
|
|
579
|
+
bodyParts.push('\n## Corrective Action\n\n' + lesson.content);
|
|
580
|
+
}
|
|
581
|
+
if (lesson.lifecycleState || lesson.state) {
|
|
582
|
+
bodyParts.push('\n## Lifecycle State\n\n' + (lesson.lifecycleState || lesson.state));
|
|
583
|
+
}
|
|
584
|
+
if (linkedRules.length > 0) {
|
|
585
|
+
bodyParts.push('\n## Linked Rules\n\n' + linkedRules.map((r) => wikiLink('Rules/' + slugify(r))).join(', '));
|
|
586
|
+
}
|
|
587
|
+
if (linkedGates.length > 0) {
|
|
588
|
+
bodyParts.push('\n## Linked Gates\n\n' + linkedGates.map((g) => wikiLink('Gates/' + g)).join(', '));
|
|
589
|
+
}
|
|
590
|
+
if (tags.length > 0) {
|
|
591
|
+
bodyParts.push('\n## Tags\n\n' + tagWikiLinks(tags));
|
|
592
|
+
}
|
|
593
|
+
if (lesson.sourceFeedbackId) {
|
|
594
|
+
bodyParts.push('\n## Source\n\nBacklink: ' + wikiLink('Feedback/' + lesson.sourceFeedbackId));
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
writeNote(path.join(outDir, fileName), fm, bodyParts.join('\n'));
|
|
598
|
+
indexLinks.push('- ' + wikiLink('Lessons/' + date + '-' + slug));
|
|
599
|
+
exported++;
|
|
600
|
+
} catch (err) {
|
|
601
|
+
errors.push('Lesson export error: ' + (err.message || String(err)));
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// Write index
|
|
606
|
+
if (indexLinks.length > 0) {
|
|
607
|
+
const indexFm = buildFrontmatter({
|
|
608
|
+
title: 'Lessons Index',
|
|
609
|
+
type: 'index',
|
|
610
|
+
});
|
|
611
|
+
const indexBody = '# Lessons Index\n\n' + indexLinks.join('\n');
|
|
612
|
+
writeNote(path.join(outDir, 'Lessons Index.md'), indexFm, indexBody);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return { exported, errors };
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// ---------------------------------------------------------------------------
|
|
619
|
+
// Export All
|
|
620
|
+
// ---------------------------------------------------------------------------
|
|
621
|
+
|
|
622
|
+
function exportAll(options) {
|
|
623
|
+
const feedbackDir = options.feedbackDir;
|
|
624
|
+
const outputDir = options.outputDir;
|
|
625
|
+
const gatesConfigPath = options.gatesConfigPath || path.join(__dirname, '..', 'config', 'gates', 'default.json');
|
|
626
|
+
const includeIndex = options.includeIndex !== false;
|
|
627
|
+
|
|
628
|
+
ensureDir(outputDir);
|
|
629
|
+
|
|
630
|
+
const feedback = exportFeedbackLog(feedbackDir, outputDir);
|
|
631
|
+
const memories = exportMemoryLog(feedbackDir, outputDir);
|
|
632
|
+
const rules = exportPreventionRules(feedbackDir, outputDir);
|
|
633
|
+
const gates = exportGates(gatesConfigPath, outputDir);
|
|
634
|
+
const packs = exportContextFsPacks(feedbackDir, outputDir);
|
|
635
|
+
const lessons = exportLessons(feedbackDir, outputDir);
|
|
636
|
+
|
|
637
|
+
const allErrors = [].concat(
|
|
638
|
+
feedback.errors,
|
|
639
|
+
memories.errors,
|
|
640
|
+
rules.errors,
|
|
641
|
+
gates.errors,
|
|
642
|
+
packs.errors,
|
|
643
|
+
lessons.errors
|
|
644
|
+
);
|
|
645
|
+
|
|
646
|
+
const stats = {
|
|
647
|
+
feedback: feedback.exported,
|
|
648
|
+
memories: memories.exported,
|
|
649
|
+
rules: rules.exported,
|
|
650
|
+
gates: gates.exported,
|
|
651
|
+
packs: packs.exported,
|
|
652
|
+
lessons: lessons.exported,
|
|
653
|
+
errors: allErrors,
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
if (includeIndex) {
|
|
657
|
+
const indexFm = buildFrontmatter({
|
|
658
|
+
title: 'ThumbGate',
|
|
659
|
+
type: 'master-index',
|
|
660
|
+
exported: new Date().toISOString(),
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
const indexBody = [
|
|
664
|
+
'# ThumbGate',
|
|
665
|
+
'',
|
|
666
|
+
'## Export Summary',
|
|
667
|
+
'',
|
|
668
|
+
'| Type | Count |',
|
|
669
|
+
'|------|-------|',
|
|
670
|
+
'| Feedback | ' + stats.feedback + ' |',
|
|
671
|
+
'| Memories | ' + stats.memories + ' |',
|
|
672
|
+
'| Prevention Rules | ' + stats.rules + ' |',
|
|
673
|
+
'| Gates | ' + stats.gates + ' |',
|
|
674
|
+
'| Context Packs | ' + stats.packs + ' |',
|
|
675
|
+
'| Lessons | ' + stats.lessons + ' |',
|
|
676
|
+
'',
|
|
677
|
+
'## Indexes',
|
|
678
|
+
'',
|
|
679
|
+
'- ' + wikiLink('Rules/Prevention Rules Index'),
|
|
680
|
+
'- ' + wikiLink('Gates/Gates Index'),
|
|
681
|
+
'- ' + wikiLink('Lessons/Lessons Index'),
|
|
682
|
+
'',
|
|
683
|
+
'## Last Export',
|
|
684
|
+
'',
|
|
685
|
+
new Date().toISOString(),
|
|
686
|
+
].join('\n');
|
|
687
|
+
|
|
688
|
+
writeNote(path.join(outputDir, 'ThumbGate.md'), indexFm, indexBody);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return stats;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// ---------------------------------------------------------------------------
|
|
695
|
+
// Module exports
|
|
696
|
+
// ---------------------------------------------------------------------------
|
|
697
|
+
|
|
698
|
+
module.exports = {
|
|
699
|
+
exportFeedbackLog,
|
|
700
|
+
exportMemoryLog,
|
|
701
|
+
exportPreventionRules,
|
|
702
|
+
exportGates,
|
|
703
|
+
exportContextFsPacks,
|
|
704
|
+
exportLessons,
|
|
705
|
+
exportAll,
|
|
706
|
+
// Internals exposed for testing
|
|
707
|
+
slugify,
|
|
708
|
+
yamlEscape,
|
|
709
|
+
buildFrontmatter,
|
|
710
|
+
wikiLink,
|
|
711
|
+
parsePreventionRulesMarkdown,
|
|
712
|
+
};
|