mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
* v0.41.15.0 feat: conversation parser cathedral + progressive-batch primitive (closes #1461) Replaces PR #1461's single-format Telegram regex with a 12-pattern built-in registry covering iMessage/Slack, Telegram (×2), Discord (×2), WhatsApp (×2 locales), Signal, Matrix/Element, IRC (×2), Teams. Each pattern is hand-vetted from public format docs (signal-cli, DiscordChatExporter, Telegram Desktop, WhatsApp export docs, Element matrix-archive, irssi/weechat defaults); module-load validation runs test_positive[] + test_negative[] for every pattern at startup so a typo makes gbrain refuse to start. PR #1461 contributor's BRACKET_TIME_RX + cleanSpeaker survive verbatim as the `telegram-bracket` built-in pattern + DEFAULT_SPEAKER_CLEAN export. All 33 of their test cases pass against the new orchestrator. Three layers per page (orchestrator chooses): 1. Built-in pattern registry (zero-cost, deterministic) 2. User-declared simple_pattern via config (deferred to v0.42+) 3. Opt-IN LLM polish + fallback (privacy-first; chat content goes to Anthropic only when user explicitly enables) D18 priority scoring picks the highest-match-rate pattern across the first 10 lines (not first-wins) so overlapping formats don't silently mis-route. D5 multi_line per-pattern + D11 quick_reject prefix screen + D19 timezone_policy per-pattern complete the registry shape. Companion: src/core/progressive-batch/ primitive (rule of three satisfied across 12+ ad-hoc cost-prompt sites). Wintermute-inspired ramp shape (trial 10 → 100 → 500 → full with verification at each stage), productionized with verifier+policy injection (callers describe HOW TO MEASURE SUCCESS, not WHEN TO WAIT FOR CTRL-C). D3 fail-closed budget gate: null tracker + null Policy.maxCostUsd → abort_cost_cap reason='no_budget_safety_net'. D20 discriminated Verifier union (output_count | idempotent_mutation | noop). extract-conversation-facts is the one proven consumer in v0.41.15.0; 9-site retrofit deferred to v0.41.16.0+ per TODOS.md. Codex outside-voice review absorbed 8 substantive findings: - Privacy posture (LLM polish/fallback flipped to opt-IN) - ReDoS theater (dropped arbitrary user regex; v0.42+ uses RE2) - LLM-inferred-regex persistence as silent-corruption machine - Pattern priority scoring across first 10 lines - Timezone policy on every PatternEntry - Verifier shape discriminated union - Behavior parity for sites that "jumped straight to full" - Real-corpus-redacted fixture gap (v0.42+ TODO) CI gates: - bun run check:conversation-parser (13 fixtures, --no-llm, deterministic) - bun run check:fixture-privacy (banned-token grep) Doctor surfaces 3 new checks: conversation_format_coverage, progressive_batch_audit_health, conversation_parser_probe_health. Tests: 198/198 across primitive + parser + LLM + nightly probe + eval CLI + debug CLI + doctor checks + migration v97 round-trip + E2E parser ↔ engine integration. Real bug caught + fixed during gap audit: IdempotentMutationVerifier was comparing absolute mutated-count vs per-stage expected (failed silently on stage 2+); now uses per-stage delta semantics matching OutputCountVerifier. Schema migration v97: conversation_parser_llm_cache table with (content_sha256, model_id, call_shape) composite key. NO inferred_patterns table (D17: silent-corruption machine). Plan + 23 decisions + codex outside-voice absorption at ~/.claude/plans/system-instruction-you-are-working-cuddly-hollerith.md. Co-Authored-By: garrytan-agents (PR #1461) <noreply@github.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(check-privacy): allowlist scripts/check-fixture-privacy.sh The new sibling privacy guard literally names the banned tokens in its BANNED_TOKENS array — same meta-exception that check-privacy.sh itself gets. Without this allowlist entry, bun run verify rejects the file post-merge because the banned name appears in the rule-definition script. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: renumber v0.41.15.0 → v0.41.16.0 (queue drift) Mechanical rename across all surfaces: VERSION, package.json, CHANGELOG (header + body refs), CLAUDE.md, TODOS.md, src/core/ migrate.ts (migration v98 comment), all src/core/conversation-parser/* and src/core/progressive-batch/* file headers, all test/ headers, scripts/check-privacy.sh allowlist comment, llms-full.txt regenerated. Audit clean: VERSION + package.json + CHANGELOG header all show 0.41.16.0. verify 24/24, touched tests 179/179. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: garrytan-agents (PR #1461) <noreply@github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
99 lines
3.2 KiB
TypeScript
99 lines
3.2 KiB
TypeScript
/**
|
|
* v0.41.16.0 — Targeted assertions for the 3 new doctor checks.
|
|
*
|
|
* Spawns `bun src/cli.ts doctor --json --fast` as a subprocess and
|
|
* parses the JSON envelope to verify:
|
|
*
|
|
* - conversation_format_coverage
|
|
* - progressive_batch_audit_health
|
|
* - conversation_parser_probe_health
|
|
*
|
|
* are present with stable shapes. The full doctor surface is covered
|
|
* by test/doctor.test.ts; this file is a structural regression guard
|
|
* for the 3 new v0.41.16.0 checks.
|
|
*
|
|
* Spawning the subprocess matches the actual user experience (`gbrain
|
|
* doctor`) and avoids the in-process env/stdout-capture brittleness
|
|
* that bit the original test draft.
|
|
*/
|
|
|
|
import { describe, expect, test } from 'bun:test';
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
interface DoctorCheck {
|
|
name: string;
|
|
status: 'ok' | 'warn' | 'fail';
|
|
message: string;
|
|
}
|
|
interface DoctorEnvelope {
|
|
schema_version: number;
|
|
status: 'healthy' | 'unhealthy';
|
|
health_score: number;
|
|
checks: DoctorCheck[];
|
|
}
|
|
|
|
function runDoctor(): DoctorEnvelope {
|
|
const result = spawnSync(
|
|
process.execPath, // bun
|
|
['src/cli.ts', 'doctor', '--json', '--fast'],
|
|
{
|
|
cwd: process.cwd(),
|
|
encoding: 'utf8',
|
|
timeout: 60000,
|
|
},
|
|
);
|
|
if (result.error) throw result.error;
|
|
// Doctor's JSON envelope is the LAST line in stdout (CLI may print
|
|
// banners on stderr; --json sends the envelope to stdout).
|
|
const stdout = result.stdout ?? '';
|
|
const lines = stdout.split('\n').filter((l) => l.trim().length > 0);
|
|
const jsonLine = lines.reverse().find((l) => l.trim().startsWith('{'));
|
|
if (!jsonLine) {
|
|
throw new Error(
|
|
`No JSON envelope found in doctor output. stdout=${stdout.slice(0, 500)} stderr=${(result.stderr ?? '').slice(0, 500)}`,
|
|
);
|
|
}
|
|
return JSON.parse(jsonLine) as DoctorEnvelope;
|
|
}
|
|
|
|
describe('doctor — v0.41.16.0 new checks emit', () => {
|
|
test('all 3 new checks present in JSON envelope', () => {
|
|
const env = runDoctor();
|
|
const checkNames = env.checks.map((c) => c.name);
|
|
// conversation_format_coverage may not appear in --fast mode (it
|
|
// requires DB access); progressive_batch_audit_health and
|
|
// conversation_parser_probe_health do not need DB.
|
|
expect(checkNames).toContain('progressive_batch_audit_health');
|
|
expect(checkNames).toContain('conversation_parser_probe_health');
|
|
});
|
|
|
|
test('progressive_batch_audit_health shape', () => {
|
|
const env = runDoctor();
|
|
const check = env.checks.find(
|
|
(c) => c.name === 'progressive_batch_audit_health',
|
|
);
|
|
expect(check).toBeDefined();
|
|
expect(['ok', 'warn', 'fail']).toContain(check!.status);
|
|
expect(typeof check!.message).toBe('string');
|
|
expect(check!.message.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('conversation_parser_probe_health shape + opt-in hint', () => {
|
|
const env = runDoctor();
|
|
const check = env.checks.find(
|
|
(c) => c.name === 'conversation_parser_probe_health',
|
|
);
|
|
expect(check).toBeDefined();
|
|
expect(check!.status).toBe('ok');
|
|
expect(check!.message).toContain('opt-in');
|
|
expect(check!.message).toContain(
|
|
'autopilot.conversation_parser_probe.enabled true',
|
|
);
|
|
});
|
|
|
|
test('schema_version is stable (2 at v0.41.16.0)', () => {
|
|
const env = runDoctor();
|
|
expect(env.schema_version).toBe(2);
|
|
});
|
|
});
|