thumbgate 0.9.9
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/rlhf-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 +1483 -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 +286 -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 +1195 -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-314.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 +293 -0
- package/scripts/auto-wire-hooks.js +316 -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 +93 -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 +231 -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 +206 -0
- package/scripts/ensure-repo-bootstrap.js +129 -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 +344 -0
- package/scripts/export-kto-pairs.js +309 -0
- package/scripts/export-training.js +450 -0
- package/scripts/failure-diagnostics.js +558 -0
- package/scripts/feedback-attribution.js +313 -0
- package/scripts/feedback-fallback.js +110 -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 +164 -0
- package/scripts/filesystem-search.js +405 -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 +100 -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 +156 -0
- package/scripts/hybrid-feedback-context.js +675 -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 +310 -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 +384 -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 +190 -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 +713 -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 +459 -0
- package/scripts/rlaif-self-audit.js +129 -0
- package/scripts/rlhf_session_start.sh +32 -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 +282 -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/db/social-analytics.db +0 -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 +107 -0
- package/scripts/social-analytics/load-env.js +46 -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 +92 -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 +183 -0
- package/scripts/social-analytics/publish-instagram-thumbgate.js +98 -0
- package/scripts/social-analytics/publish-thumbgate-launch.js +316 -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 +378 -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 +447 -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 +933 -0
- package/scripts/user-profile.js +78 -0
- package/scripts/validate-feedback.js +581 -0
- package/scripts/validate-workflow-contract.js +287 -0
- package/scripts/vector-store.js +197 -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/rlhf-feedback/SKILL.md +49 -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/src/api/server.js +4206 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const crypto = require('crypto');
|
|
8
|
+
const { execFileSync } = require('child_process');
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
ensureContextFs,
|
|
12
|
+
constructContextPack,
|
|
13
|
+
recordProvenance,
|
|
14
|
+
} = require('./contextfs');
|
|
15
|
+
const { planIntent } = require('./intent-router');
|
|
16
|
+
const { formatCodeGraphRecallSection } = require('./codegraph-context');
|
|
17
|
+
|
|
18
|
+
const KNOWN_SOURCES = new Set(['github', 'slack', 'linear', 'api', 'cli']);
|
|
19
|
+
const DEFAULT_SOURCE = 'api';
|
|
20
|
+
const DEFAULT_SANDBOX_ROOT = path.join(os.tmpdir(), 'rlhf-internal-agent-sandboxes');
|
|
21
|
+
|
|
22
|
+
function normalizeText(value) {
|
|
23
|
+
if (value === undefined || value === null) return '';
|
|
24
|
+
return String(value).trim();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function slugify(value) {
|
|
28
|
+
return String(value || 'item')
|
|
29
|
+
.toLowerCase()
|
|
30
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
31
|
+
.replace(/^-+|-+$/g, '')
|
|
32
|
+
.slice(0, 96) || 'item';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function uniqueStrings(values = []) {
|
|
36
|
+
return Array.from(new Set(
|
|
37
|
+
values
|
|
38
|
+
.map((value) => normalizeText(value))
|
|
39
|
+
.filter(Boolean),
|
|
40
|
+
));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function hashFragment(values = []) {
|
|
44
|
+
return crypto
|
|
45
|
+
.createHash('sha1')
|
|
46
|
+
.update(values.filter(Boolean).join('|'))
|
|
47
|
+
.digest('hex')
|
|
48
|
+
.slice(0, 12);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function ensureGitRepo(repoPath) {
|
|
52
|
+
if (!repoPath) return null;
|
|
53
|
+
const resolved = path.resolve(repoPath);
|
|
54
|
+
const target = fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()
|
|
55
|
+
? resolved
|
|
56
|
+
: path.dirname(resolved);
|
|
57
|
+
try {
|
|
58
|
+
return execFileSync('git', ['-C', target, 'rev-parse', '--show-toplevel'], {
|
|
59
|
+
encoding: 'utf8',
|
|
60
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
61
|
+
}).trim();
|
|
62
|
+
} catch (err) {
|
|
63
|
+
throw new Error(`repoPath must point to a git repository: ${resolved}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function normalizeConversation(entries = []) {
|
|
68
|
+
if (!Array.isArray(entries)) return [];
|
|
69
|
+
return entries
|
|
70
|
+
.map((entry) => {
|
|
71
|
+
if (typeof entry === 'string') {
|
|
72
|
+
return {
|
|
73
|
+
author: null,
|
|
74
|
+
text: normalizeText(entry),
|
|
75
|
+
timestamp: null,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (!entry || typeof entry !== 'object') return null;
|
|
79
|
+
return {
|
|
80
|
+
author: normalizeText(entry.author || entry.user || entry.name) || null,
|
|
81
|
+
text: normalizeText(entry.text || entry.body || entry.message),
|
|
82
|
+
timestamp: normalizeText(entry.timestamp || entry.createdAt || entry.updatedAt) || null,
|
|
83
|
+
};
|
|
84
|
+
})
|
|
85
|
+
.filter((entry) => entry && entry.text);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function inferIntentId({ task, context }) {
|
|
89
|
+
const text = `${normalizeText(task.title)} ${normalizeText(task.body)} ${normalizeText(context)}`.toLowerCase();
|
|
90
|
+
if (/\b(incident|postmortem|outage|retro)\b/.test(text)) {
|
|
91
|
+
return 'incident_postmortem';
|
|
92
|
+
}
|
|
93
|
+
return 'improve_response_quality';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function normalizeSource(source) {
|
|
97
|
+
const normalized = normalizeText(source).toLowerCase();
|
|
98
|
+
return KNOWN_SOURCES.has(normalized) ? normalized : DEFAULT_SOURCE;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function deriveThreadId(invocation) {
|
|
102
|
+
const explicit = normalizeText(invocation.thread.id)
|
|
103
|
+
|| normalizeText(invocation.trigger.id)
|
|
104
|
+
|| normalizeText(invocation.task.number)
|
|
105
|
+
|| normalizeText(invocation.task.title);
|
|
106
|
+
|
|
107
|
+
if (explicit) {
|
|
108
|
+
return `${invocation.source}-${slugify(explicit)}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return `${invocation.source}-${hashFragment([
|
|
112
|
+
invocation.source,
|
|
113
|
+
invocation.trigger.type,
|
|
114
|
+
invocation.context,
|
|
115
|
+
invocation.task.title,
|
|
116
|
+
invocation.task.body,
|
|
117
|
+
])}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function normalizeInvocation(input = {}) {
|
|
121
|
+
const source = normalizeSource(input.source);
|
|
122
|
+
const trigger = {
|
|
123
|
+
type: normalizeText(input.trigger && input.trigger.type) || `${source}_event`,
|
|
124
|
+
id: normalizeText(input.trigger && input.trigger.id) || null,
|
|
125
|
+
url: normalizeText(input.trigger && input.trigger.url) || null,
|
|
126
|
+
actor: normalizeText(input.trigger && input.trigger.actor) || null,
|
|
127
|
+
};
|
|
128
|
+
const thread = {
|
|
129
|
+
id: normalizeText(input.thread && input.thread.id) || null,
|
|
130
|
+
title: normalizeText(input.thread && input.thread.title) || null,
|
|
131
|
+
url: normalizeText(input.thread && input.thread.url) || null,
|
|
132
|
+
};
|
|
133
|
+
const task = {
|
|
134
|
+
title: normalizeText(input.task && input.task.title) || thread.title || null,
|
|
135
|
+
body: normalizeText(input.task && input.task.body) || null,
|
|
136
|
+
number: normalizeText(input.task && input.task.number) || null,
|
|
137
|
+
labels: uniqueStrings(Array.isArray(input.task && input.task.labels) ? input.task.labels : []),
|
|
138
|
+
branch: normalizeText(input.task && input.task.branch) || null,
|
|
139
|
+
};
|
|
140
|
+
const context = normalizeText(input.context);
|
|
141
|
+
const repoPath = input.repoPath ? ensureGitRepo(input.repoPath) : null;
|
|
142
|
+
const threadId = deriveThreadId({ source, trigger, thread, task, context });
|
|
143
|
+
const intentId = normalizeText(input.intentId) || inferIntentId({ task, context });
|
|
144
|
+
const prepareSandbox = input.prepareSandbox !== false && Boolean(repoPath);
|
|
145
|
+
const sandboxRoot = path.resolve(input.sandboxRoot || process.env.THUMBGATE_AGENT_SANDBOX_ROOT || DEFAULT_SANDBOX_ROOT);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
source,
|
|
149
|
+
trigger,
|
|
150
|
+
thread: {
|
|
151
|
+
...thread,
|
|
152
|
+
id: thread.id || threadId,
|
|
153
|
+
},
|
|
154
|
+
threadId,
|
|
155
|
+
task,
|
|
156
|
+
comments: normalizeConversation(input.comments),
|
|
157
|
+
messages: normalizeConversation(input.messages),
|
|
158
|
+
context,
|
|
159
|
+
repoPath,
|
|
160
|
+
prepareSandbox,
|
|
161
|
+
sandboxRoot,
|
|
162
|
+
intentId,
|
|
163
|
+
mcpProfile: normalizeText(input.mcpProfile) || undefined,
|
|
164
|
+
partnerProfile: normalizeText(input.partnerProfile) || undefined,
|
|
165
|
+
delegationMode: normalizeText(input.delegationMode) || 'auto',
|
|
166
|
+
approved: input.approved === true,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function buildStartupContext(invocation) {
|
|
171
|
+
const sections = [];
|
|
172
|
+
|
|
173
|
+
sections.push({
|
|
174
|
+
title: 'Trigger',
|
|
175
|
+
lines: [
|
|
176
|
+
`Source: ${invocation.source}`,
|
|
177
|
+
`Trigger type: ${invocation.trigger.type}`,
|
|
178
|
+
`Thread ID: ${invocation.threadId}`,
|
|
179
|
+
invocation.trigger.actor ? `Actor: ${invocation.trigger.actor}` : null,
|
|
180
|
+
invocation.trigger.url ? `Trigger URL: ${invocation.trigger.url}` : null,
|
|
181
|
+
invocation.thread.url ? `Thread URL: ${invocation.thread.url}` : null,
|
|
182
|
+
].filter(Boolean),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
sections.push({
|
|
186
|
+
title: 'Task',
|
|
187
|
+
lines: [
|
|
188
|
+
invocation.task.title ? `Title: ${invocation.task.title}` : null,
|
|
189
|
+
invocation.task.number ? `Number: ${invocation.task.number}` : null,
|
|
190
|
+
invocation.task.labels.length > 0 ? `Labels: ${invocation.task.labels.join(', ')}` : null,
|
|
191
|
+
invocation.task.body ? `Body: ${invocation.task.body}` : null,
|
|
192
|
+
].filter(Boolean),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (invocation.comments.length > 0) {
|
|
196
|
+
sections.push({
|
|
197
|
+
title: 'Thread History',
|
|
198
|
+
lines: invocation.comments.map((entry) => {
|
|
199
|
+
const prefix = entry.author ? `${entry.author}: ` : '';
|
|
200
|
+
return `${prefix}${entry.text}`;
|
|
201
|
+
}),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (invocation.messages.length > 0) {
|
|
206
|
+
sections.push({
|
|
207
|
+
title: 'Conversation',
|
|
208
|
+
lines: invocation.messages.map((entry) => {
|
|
209
|
+
const prefix = entry.author ? `${entry.author}: ` : '';
|
|
210
|
+
return `${prefix}${entry.text}`;
|
|
211
|
+
}),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (invocation.context) {
|
|
216
|
+
sections.push({
|
|
217
|
+
title: 'Operator Context',
|
|
218
|
+
lines: [invocation.context],
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (invocation.repoPath) {
|
|
223
|
+
sections.push({
|
|
224
|
+
title: 'Workspace',
|
|
225
|
+
lines: [`Repository: ${invocation.repoPath}`],
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const text = sections
|
|
230
|
+
.filter((section) => section.lines.length > 0)
|
|
231
|
+
.map((section) => `## ${section.title}\n${section.lines.join('\n')}`)
|
|
232
|
+
.join('\n\n');
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
text,
|
|
236
|
+
sections,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function buildRecallQuery(invocation) {
|
|
241
|
+
return [
|
|
242
|
+
invocation.task.title,
|
|
243
|
+
invocation.task.body,
|
|
244
|
+
invocation.context,
|
|
245
|
+
...invocation.comments.slice(0, 3).map((entry) => entry.text),
|
|
246
|
+
...invocation.messages.slice(0, 3).map((entry) => entry.text),
|
|
247
|
+
]
|
|
248
|
+
.filter(Boolean)
|
|
249
|
+
.join(' ')
|
|
250
|
+
.slice(0, 600);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function ensureWorktreeSandbox({ repoPath, sandboxRoot, threadId }) {
|
|
254
|
+
if (!repoPath) {
|
|
255
|
+
return {
|
|
256
|
+
ready: false,
|
|
257
|
+
kind: 'none',
|
|
258
|
+
path: null,
|
|
259
|
+
reused: false,
|
|
260
|
+
baseRef: null,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const repoName = slugify(path.basename(repoPath));
|
|
265
|
+
const sandboxPath = path.join(path.resolve(sandboxRoot), repoName, slugify(threadId));
|
|
266
|
+
fs.mkdirSync(path.dirname(sandboxPath), { recursive: true });
|
|
267
|
+
|
|
268
|
+
if (fs.existsSync(path.join(sandboxPath, '.git'))) {
|
|
269
|
+
return {
|
|
270
|
+
ready: true,
|
|
271
|
+
kind: 'git_worktree',
|
|
272
|
+
path: sandboxPath,
|
|
273
|
+
reused: true,
|
|
274
|
+
baseRef: 'HEAD',
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (fs.existsSync(sandboxPath) && fs.readdirSync(sandboxPath).length > 0) {
|
|
279
|
+
throw new Error(`Sandbox path already exists and is not a ThumbGate worktree: ${sandboxPath}`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
execFileSync('git', ['-C', repoPath, 'worktree', 'add', '--detach', sandboxPath, 'HEAD'], {
|
|
283
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
ready: true,
|
|
288
|
+
kind: 'git_worktree',
|
|
289
|
+
path: sandboxPath,
|
|
290
|
+
reused: false,
|
|
291
|
+
baseRef: 'HEAD',
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function summarizePack(pack) {
|
|
296
|
+
return {
|
|
297
|
+
packId: pack.packId,
|
|
298
|
+
itemCount: Array.isArray(pack.items) ? pack.items.length : 0,
|
|
299
|
+
cache: pack.cache || { hit: false },
|
|
300
|
+
visibleTitles: pack.visibility && Array.isArray(pack.visibility.visibleTitles)
|
|
301
|
+
? pack.visibility.visibleTitles.slice()
|
|
302
|
+
: [],
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function buildReviewerLane(plan) {
|
|
307
|
+
if (!plan) {
|
|
308
|
+
return {
|
|
309
|
+
enabled: false,
|
|
310
|
+
delegateProfile: null,
|
|
311
|
+
executionMode: null,
|
|
312
|
+
verificationMode: null,
|
|
313
|
+
requiredChecks: [],
|
|
314
|
+
requiredEvidence: [],
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const requiredChecks = plan.handoffContract && Array.isArray(plan.handoffContract.requiredChecks)
|
|
319
|
+
? plan.handoffContract.requiredChecks.slice()
|
|
320
|
+
: (plan.partnerStrategy && Array.isArray(plan.partnerStrategy.recommendedChecks)
|
|
321
|
+
? plan.partnerStrategy.recommendedChecks.slice()
|
|
322
|
+
: []);
|
|
323
|
+
|
|
324
|
+
const requiredEvidence = plan.handoffContract && Array.isArray(plan.handoffContract.requiredEvidence)
|
|
325
|
+
? plan.handoffContract.requiredEvidence.slice()
|
|
326
|
+
: ['tests', 'proof', 'diff_review'];
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
enabled: plan.delegationEligible === true,
|
|
330
|
+
delegateProfile: plan.delegateProfile || null,
|
|
331
|
+
executionMode: plan.executionMode || null,
|
|
332
|
+
verificationMode: plan.partnerStrategy ? plan.partnerStrategy.verificationMode : null,
|
|
333
|
+
requiredChecks,
|
|
334
|
+
requiredEvidence,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function buildMiddlewarePlan({ sandbox, recallPack, plan, reviewerLane }) {
|
|
339
|
+
return [
|
|
340
|
+
{
|
|
341
|
+
step: 'trigger_normalization',
|
|
342
|
+
status: 'ready',
|
|
343
|
+
details: {},
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
step: 'startup_context_hydration',
|
|
347
|
+
status: 'ready',
|
|
348
|
+
details: {},
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
step: 'context_pack_construction',
|
|
352
|
+
status: 'ready',
|
|
353
|
+
details: summarizePack(recallPack),
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
step: 'sandbox_preparation',
|
|
357
|
+
status: sandbox.ready ? 'ready' : 'skipped',
|
|
358
|
+
details: {
|
|
359
|
+
kind: sandbox.kind,
|
|
360
|
+
path: sandbox.path,
|
|
361
|
+
reused: sandbox.reused,
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
step: 'intent_planning',
|
|
366
|
+
status: 'ready',
|
|
367
|
+
details: {
|
|
368
|
+
intentId: plan.intent.id,
|
|
369
|
+
status: plan.status,
|
|
370
|
+
executionMode: plan.executionMode,
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
step: 'reviewer_lane',
|
|
375
|
+
status: reviewerLane.enabled ? 'ready' : 'optional',
|
|
376
|
+
details: {
|
|
377
|
+
enabled: reviewerLane.enabled,
|
|
378
|
+
delegateProfile: reviewerLane.delegateProfile,
|
|
379
|
+
verificationMode: reviewerLane.verificationMode,
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
step: 'proof_gate',
|
|
384
|
+
status: 'ready',
|
|
385
|
+
details: {
|
|
386
|
+
requiredChecks: reviewerLane.requiredChecks,
|
|
387
|
+
requiredEvidence: reviewerLane.requiredEvidence,
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
step: 'feedback_capture',
|
|
392
|
+
status: 'ready',
|
|
393
|
+
details: {
|
|
394
|
+
tool: 'capture_feedback',
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function bootstrapInternalAgent(options = {}) {
|
|
401
|
+
const invocation = normalizeInvocation(options);
|
|
402
|
+
const startupContext = buildStartupContext(invocation);
|
|
403
|
+
|
|
404
|
+
ensureContextFs();
|
|
405
|
+
const recallPack = constructContextPack({
|
|
406
|
+
query: buildRecallQuery(invocation),
|
|
407
|
+
maxItems: 6,
|
|
408
|
+
maxChars: 5000,
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const sandbox = invocation.prepareSandbox
|
|
412
|
+
? ensureWorktreeSandbox({
|
|
413
|
+
repoPath: invocation.repoPath,
|
|
414
|
+
sandboxRoot: invocation.sandboxRoot,
|
|
415
|
+
threadId: invocation.threadId,
|
|
416
|
+
})
|
|
417
|
+
: {
|
|
418
|
+
ready: false,
|
|
419
|
+
kind: 'none',
|
|
420
|
+
path: null,
|
|
421
|
+
reused: false,
|
|
422
|
+
baseRef: null,
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const plan = planIntent({
|
|
426
|
+
intentId: invocation.intentId,
|
|
427
|
+
context: startupContext.text,
|
|
428
|
+
mcpProfile: invocation.mcpProfile,
|
|
429
|
+
partnerProfile: invocation.partnerProfile,
|
|
430
|
+
delegationMode: invocation.delegationMode,
|
|
431
|
+
approved: invocation.approved,
|
|
432
|
+
repoPath: sandbox.path || invocation.repoPath || undefined,
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const reviewerLane = buildReviewerLane(plan);
|
|
436
|
+
const codeGraphSection = formatCodeGraphRecallSection(plan.codegraphImpact);
|
|
437
|
+
const middlewarePlan = buildMiddlewarePlan({
|
|
438
|
+
sandbox,
|
|
439
|
+
recallPack,
|
|
440
|
+
plan,
|
|
441
|
+
reviewerLane,
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
const payload = {
|
|
445
|
+
generatedAt: new Date().toISOString(),
|
|
446
|
+
invocation: {
|
|
447
|
+
source: invocation.source,
|
|
448
|
+
trigger: invocation.trigger,
|
|
449
|
+
thread: invocation.thread,
|
|
450
|
+
threadId: invocation.threadId,
|
|
451
|
+
task: invocation.task,
|
|
452
|
+
repoPath: invocation.repoPath,
|
|
453
|
+
prepareSandbox: invocation.prepareSandbox,
|
|
454
|
+
intentId: invocation.intentId,
|
|
455
|
+
mcpProfile: invocation.mcpProfile || 'default',
|
|
456
|
+
delegationMode: invocation.delegationMode,
|
|
457
|
+
},
|
|
458
|
+
startupContext,
|
|
459
|
+
recallPack: summarizePack(recallPack),
|
|
460
|
+
sandbox,
|
|
461
|
+
intentPlan: plan,
|
|
462
|
+
reviewerLane,
|
|
463
|
+
middlewarePlan,
|
|
464
|
+
codeGraph: {
|
|
465
|
+
enabled: Boolean(codeGraphSection),
|
|
466
|
+
section: codeGraphSection,
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
recordProvenance({
|
|
471
|
+
type: 'internal_agent_bootstrap_created',
|
|
472
|
+
source: invocation.source,
|
|
473
|
+
threadId: invocation.threadId,
|
|
474
|
+
sandboxPath: sandbox.path,
|
|
475
|
+
intentId: plan.intent.id,
|
|
476
|
+
delegationEligible: plan.delegationEligible,
|
|
477
|
+
packId: recallPack.packId,
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
return payload;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
module.exports = {
|
|
484
|
+
DEFAULT_SANDBOX_ROOT,
|
|
485
|
+
normalizeInvocation,
|
|
486
|
+
buildStartupContext,
|
|
487
|
+
ensureWorktreeSandbox,
|
|
488
|
+
buildMiddlewarePlan,
|
|
489
|
+
bootstrapInternalAgent,
|
|
490
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* JSONL File Watcher
|
|
4
|
+
*
|
|
5
|
+
* Watches feedback-log.jsonl for new entries written by external sources
|
|
6
|
+
* (e.g., Amp plugin bridge) and routes them through captureFeedback()
|
|
7
|
+
* for full pipeline processing: memory promotion, vector indexing,
|
|
8
|
+
* sequence tracking, and DPO export eligibility.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node scripts/jsonl-watcher.js # watch mode
|
|
12
|
+
* node scripts/jsonl-watcher.js --once # process pending, exit
|
|
13
|
+
* node scripts/jsonl-watcher.js --source amp-plugin-bridge # filter by source
|
|
14
|
+
*
|
|
15
|
+
* The watcher tracks its position via .thumbgate/.watcher-offset to avoid
|
|
16
|
+
* reprocessing entries on restart.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const { captureFeedback, getFeedbackPaths } = require('./feedback-loop');
|
|
22
|
+
|
|
23
|
+
const POLL_INTERVAL_MS = 2000;
|
|
24
|
+
const WATCHER_SOURCE_TAG = 'watcher-ingested';
|
|
25
|
+
|
|
26
|
+
// Use stderr for logging so stdout stays clean for MCP JSON-RPC when co-hosted
|
|
27
|
+
const log = (...args) => process.stderr.write(`${args.join(' ')}\n`);
|
|
28
|
+
|
|
29
|
+
function getOffsetPath(feedbackDir) {
|
|
30
|
+
return path.join(feedbackDir, '.watcher-offset');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readOffset(feedbackDir) {
|
|
34
|
+
const offsetPath = getOffsetPath(feedbackDir);
|
|
35
|
+
try {
|
|
36
|
+
return parseInt(fs.readFileSync(offsetPath, 'utf-8').trim(), 10) || 0;
|
|
37
|
+
} catch {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function writeOffset(feedbackDir, offset) {
|
|
43
|
+
fs.writeFileSync(getOffsetPath(feedbackDir), String(offset) + '\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parseEntry(line) {
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(line);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function shouldIngest(entry, sourceFilter) {
|
|
55
|
+
// Only ingest entries from external sources (not from captureFeedback itself)
|
|
56
|
+
if (!entry || !entry.source) return false;
|
|
57
|
+
if (sourceFilter && entry.source !== sourceFilter) return false;
|
|
58
|
+
// Skip entries already ingested by the watcher
|
|
59
|
+
if (entry.tags && entry.tags.includes(WATCHER_SOURCE_TAG)) return false;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ingestEntry(entry) {
|
|
64
|
+
const signal = entry.signal === 'positive' ? 'up' : entry.signal === 'negative' ? 'down' : entry.signal;
|
|
65
|
+
|
|
66
|
+
const result = captureFeedback({
|
|
67
|
+
signal,
|
|
68
|
+
context: entry.context || '',
|
|
69
|
+
whatWentWrong: entry.whatWentWrong || undefined,
|
|
70
|
+
whatToChange: entry.whatToChange || undefined,
|
|
71
|
+
whatWorked: entry.whatWorked || undefined,
|
|
72
|
+
tags: [...(entry.tags || []), WATCHER_SOURCE_TAG, `bridged-from:${entry.source}`],
|
|
73
|
+
skill: entry.skill || undefined,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function processNewEntries(feedbackDir, feedbackLogPath, sourceFilter) {
|
|
80
|
+
if (!fs.existsSync(feedbackLogPath)) return { processed: 0, promoted: 0 };
|
|
81
|
+
|
|
82
|
+
const content = fs.readFileSync(feedbackLogPath, 'utf-8');
|
|
83
|
+
const lines = content.split('\n').filter(Boolean);
|
|
84
|
+
const offset = readOffset(feedbackDir);
|
|
85
|
+
|
|
86
|
+
if (offset >= lines.length) return { processed: 0, promoted: 0 };
|
|
87
|
+
|
|
88
|
+
const newLines = lines.slice(offset);
|
|
89
|
+
let processed = 0;
|
|
90
|
+
let promoted = 0;
|
|
91
|
+
|
|
92
|
+
for (const line of newLines) {
|
|
93
|
+
const entry = parseEntry(line);
|
|
94
|
+
if (shouldIngest(entry, sourceFilter)) {
|
|
95
|
+
const result = ingestEntry(entry);
|
|
96
|
+
processed++;
|
|
97
|
+
if (result && result.accepted) promoted++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
writeOffset(feedbackDir, lines.length);
|
|
102
|
+
return { processed, promoted };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function watch(sourceFilter) {
|
|
106
|
+
const { FEEDBACK_DIR, FEEDBACK_LOG_PATH } = getFeedbackPaths();
|
|
107
|
+
|
|
108
|
+
// Initialize offset to current end of file to avoid reprocessing history
|
|
109
|
+
if (!fs.existsSync(getOffsetPath(FEEDBACK_DIR))) {
|
|
110
|
+
if (fs.existsSync(FEEDBACK_LOG_PATH)) {
|
|
111
|
+
const lines = fs.readFileSync(FEEDBACK_LOG_PATH, 'utf-8').split('\n').filter(Boolean);
|
|
112
|
+
writeOffset(FEEDBACK_DIR, lines.length);
|
|
113
|
+
} else {
|
|
114
|
+
writeOffset(FEEDBACK_DIR, 0);
|
|
115
|
+
}
|
|
116
|
+
log(`[jsonl-watcher] Initialized offset at current end of file`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
log(`[jsonl-watcher] Watching ${FEEDBACK_LOG_PATH}`);
|
|
120
|
+
if (sourceFilter) log(`[jsonl-watcher] Filtering source: ${sourceFilter}`);
|
|
121
|
+
|
|
122
|
+
setInterval(() => {
|
|
123
|
+
try {
|
|
124
|
+
const result = processNewEntries(FEEDBACK_DIR, FEEDBACK_LOG_PATH, sourceFilter);
|
|
125
|
+
if (result.processed > 0) {
|
|
126
|
+
log(`[jsonl-watcher] Ingested ${result.processed} entries (${result.promoted} promoted)`);
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
log(`[jsonl-watcher] Poll error (non-fatal): ${err.message}`);
|
|
130
|
+
}
|
|
131
|
+
}, POLL_INTERVAL_MS);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function once(sourceFilter) {
|
|
135
|
+
const { FEEDBACK_DIR, FEEDBACK_LOG_PATH } = getFeedbackPaths();
|
|
136
|
+
const result = processNewEntries(FEEDBACK_DIR, FEEDBACK_LOG_PATH, sourceFilter);
|
|
137
|
+
log(`[jsonl-watcher] Processed ${result.processed} entries (${result.promoted} promoted)`);
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// CLI
|
|
142
|
+
if (require.main === module) {
|
|
143
|
+
const args = process.argv.slice(2);
|
|
144
|
+
const isOnce = args.includes('--once');
|
|
145
|
+
const sourceIdx = args.indexOf('--source');
|
|
146
|
+
const sourceFilter = sourceIdx >= 0 ? args[sourceIdx + 1] : undefined;
|
|
147
|
+
|
|
148
|
+
if (isOnce) {
|
|
149
|
+
once(sourceFilter);
|
|
150
|
+
} else {
|
|
151
|
+
watch(sourceFilter);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = { processNewEntries, ingestEntry, shouldIngest, watch, once };
|