Skip to content

feat(team): harden share pipeline — Ollama client, helper extraction, segmented sync#49

Merged
ashu17706 merged 1 commit intodevfrom
feat/smriti-share-v2
Mar 9, 2026
Merged

feat(team): harden share pipeline — Ollama client, helper extraction, segmented sync#49
ashu17706 merged 1 commit intodevfrom
feat/smriti-share-v2

Conversation

@ashu17706
Copy link
Contributor

Summary

  • src/team/ollama.ts (new) — Centralized Ollama HTTP client extracted from both segment.ts and document.ts. Adds 120s timeout, 2-retry exponential backoff, and proper error classification (no retry on 4xx, retry on 5xx and network failures).
  • src/team/utils.ts (new) — Shared slugify() and datePrefix() utilities, extracted from document.ts.
  • Share pipeline refactoredshare.ts extracts resolveOutputDir(), querySessions(), getSessionMessages(), and writeManifest() as named helpers. Both the segmented and legacy pipelines now share these instead of duplicating 100+ lines each.
  • Segmented sync fixsync.ts now detects docs from the segmented pipeline (via meta.pipeline === "segmented") and treats the full body as a single assistant message instead of trying to parse **user**/**assistant** chat patterns that don't exist in generated docs.
  • Category dir bug fixreplaceAll("/", "-") instead of replace("/", "-"), so nested categories like decision/technical produce decision-technical/ not decision/technical/.
  • Dedup simplified — Unit-level dedup now checks content hash only, not (content_hash, unit_id), avoiding false negatives on re-runs.
  • Stage 2 prompts — All templates now receive {{title}} and emit a # Heading using it. Stage 1 category list locked down with "Use ONLY categories listed above."
  • Duration fix — Session duration in segment.ts now calculated from actual message timestamps instead of messages.length / 2.

Test plan

  • bun test test/team.test.ts — legacy share pipeline
  • bun test test/team-segmented.test.ts — segmented pipeline
  • smriti share --project <id> --segmented — verify generated docs have # Heading
  • smriti sync after share — verify segmented docs import without being skipped
  • Verify nested category (decision/technical) creates decision-technical/ dir correctly

Priority 1 - Fix broken things:
- Rewrite test/team.test.ts with bun:test (was using console.assert, wrong imports)
- Fix unit-level dedup in share.ts (was matching on random UUID, now content_hash only)
- Fix duration calculation in segment.ts (use actual timestamps, not messageCount/2)
- Fix replace() → replaceAll() for nested category paths in share.ts

Priority 2 - Code quality:
- Extract shared callOllama() to src/team/ollama.ts with timeout + retry
- Extract shared slugify/datePrefix to src/team/utils.ts
- DRY up share.ts: extract resolveOutputDir, querySessions, writeManifest helpers
- Use isValidCategory from categorize/schema.ts instead of duplicate in segment.ts
- Remove unused SMRITI_DIR import from document.ts

Priority 3 - Test coverage:
- Replace misleading tests in team-segmented.test.ts with mocked Ollama tests
- Add generateDocument, generateDocumentsSequential, and fallback path tests
- Add real DB validation tests using isValidCategory

Priority 4 - Sync integration:
- Fix sync.ts to handle Stage 2 structured output (pipeline: segmented flag)
- Segmented knowledge docs are no longer write-only

Priority 5 - Prompt improvements:
- Constrain Stage 1 to use only listed categories (remove "other valid" text)
- Add {{title}} placeholder and heading instruction to all Stage 2 templates
- Remove hallucination-prone "Links to further reading" from topic template

Also adds docs/demo-script.md showing the full smriti workflow story.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ashu17706 ashu17706 force-pushed the feat/smriti-share-v2 branch from b24a0e1 to 891fb05 Compare March 9, 2026 06:08
@ashu17706 ashu17706 merged commit 6eb6031 into dev Mar 9, 2026
9 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Benchmark Scorecard (ci-small)

Bench Scorecard (ci-small)

threshold: 20.00%

metric baseline current (median) delta status
ingest_throughput_msgs_per_sec 1735.800 609.390 -64.89% WARN
ingest_p95_ms_per_session 6.960 18.071 +159.64% WARN
fts_p95_ms 0.410 0.740 +80.49% WARN
recall_p95_ms 0.436 0.847 +94.27% WARN

Summary: WARN (4 metrics)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant