daftari 3.2.0 → 3.4.0

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.
Files changed (137) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +18 -2
  3. package/dist/access/rbac.d.ts +1 -0
  4. package/dist/access/rbac.d.ts.map +1 -1
  5. package/dist/access/rbac.js +8 -0
  6. package/dist/access/rbac.js.map +1 -1
  7. package/dist/backfill/derive.d.ts.map +1 -1
  8. package/dist/backfill/derive.js +2 -0
  9. package/dist/backfill/derive.js.map +1 -1
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +18 -0
  12. package/dist/cli.js.map +1 -1
  13. package/dist/consolidate/call-budget.d.ts +2 -0
  14. package/dist/consolidate/call-budget.d.ts.map +1 -1
  15. package/dist/consolidate/call-budget.js +8 -1
  16. package/dist/consolidate/call-budget.js.map +1 -1
  17. package/dist/curation/lint-voice.d.ts.map +1 -1
  18. package/dist/curation/lint-voice.js +1 -0
  19. package/dist/curation/lint-voice.js.map +1 -1
  20. package/dist/curation/lint.d.ts +2 -1
  21. package/dist/curation/lint.d.ts.map +1 -1
  22. package/dist/curation/lint.js +42 -0
  23. package/dist/curation/lint.js.map +1 -1
  24. package/dist/distill/adapters/chat-transcript.d.ts +15 -0
  25. package/dist/distill/adapters/chat-transcript.d.ts.map +1 -0
  26. package/dist/distill/adapters/chat-transcript.js +182 -0
  27. package/dist/distill/adapters/chat-transcript.js.map +1 -0
  28. package/dist/distill/adapters/types.d.ts +39 -0
  29. package/dist/distill/adapters/types.d.ts.map +1 -0
  30. package/dist/distill/adapters/types.js +7 -0
  31. package/dist/distill/adapters/types.js.map +1 -0
  32. package/dist/distill/chunk.d.ts +34 -0
  33. package/dist/distill/chunk.d.ts.map +1 -0
  34. package/dist/distill/chunk.js +46 -0
  35. package/dist/distill/chunk.js.map +1 -0
  36. package/dist/distill/cli.d.ts +13 -0
  37. package/dist/distill/cli.d.ts.map +1 -0
  38. package/dist/distill/cli.js +568 -0
  39. package/dist/distill/cli.js.map +1 -0
  40. package/dist/distill/cost.d.ts +105 -0
  41. package/dist/distill/cost.d.ts.map +1 -0
  42. package/dist/distill/cost.js +168 -0
  43. package/dist/distill/cost.js.map +1 -0
  44. package/dist/distill/extract.d.ts +44 -0
  45. package/dist/distill/extract.d.ts.map +1 -0
  46. package/dist/distill/extract.js +153 -0
  47. package/dist/distill/extract.js.map +1 -0
  48. package/dist/distill/index.d.ts +73 -0
  49. package/dist/distill/index.d.ts.map +1 -0
  50. package/dist/distill/index.js +112 -0
  51. package/dist/distill/index.js.map +1 -0
  52. package/dist/distill/output-fence.d.ts +16 -0
  53. package/dist/distill/output-fence.d.ts.map +1 -0
  54. package/dist/distill/output-fence.js +38 -0
  55. package/dist/distill/output-fence.js.map +1 -0
  56. package/dist/distill/propose.d.ts +95 -0
  57. package/dist/distill/propose.d.ts.map +1 -0
  58. package/dist/distill/propose.js +237 -0
  59. package/dist/distill/propose.js.map +1 -0
  60. package/dist/distill/state.d.ts +92 -0
  61. package/dist/distill/state.d.ts.map +1 -0
  62. package/dist/distill/state.js +198 -0
  63. package/dist/distill/state.js.map +1 -0
  64. package/dist/frontmatter/schema.d.ts.map +1 -1
  65. package/dist/frontmatter/schema.js +1 -0
  66. package/dist/frontmatter/schema.js.map +1 -1
  67. package/dist/frontmatter/types.d.ts +2 -1
  68. package/dist/frontmatter/types.d.ts.map +1 -1
  69. package/dist/frontmatter/types.js +1 -0
  70. package/dist/frontmatter/types.js.map +1 -1
  71. package/dist/interview/transcript.d.ts.map +1 -1
  72. package/dist/interview/transcript.js +1 -0
  73. package/dist/interview/transcript.js.map +1 -1
  74. package/dist/okf/map.d.ts.map +1 -1
  75. package/dist/okf/map.js +1 -0
  76. package/dist/okf/map.js.map +1 -1
  77. package/dist/search/contested.d.ts +1 -1
  78. package/dist/search/contested.d.ts.map +1 -1
  79. package/dist/search/contested.js +4 -3
  80. package/dist/search/contested.js.map +1 -1
  81. package/dist/server.d.ts.map +1 -1
  82. package/dist/server.js +2 -0
  83. package/dist/server.js.map +1 -1
  84. package/dist/sleep/index.d.ts.map +1 -1
  85. package/dist/sleep/index.js +14 -0
  86. package/dist/sleep/index.js.map +1 -1
  87. package/dist/sleep/run-ledger.d.ts +17 -0
  88. package/dist/sleep/run-ledger.d.ts.map +1 -0
  89. package/dist/sleep/run-ledger.js +119 -0
  90. package/dist/sleep/run-ledger.js.map +1 -0
  91. package/dist/sleep/runs-cli.d.ts +2 -0
  92. package/dist/sleep/runs-cli.d.ts.map +1 -0
  93. package/dist/sleep/runs-cli.js +69 -0
  94. package/dist/sleep/runs-cli.js.map +1 -0
  95. package/dist/tools/backlinks.d.ts +34 -0
  96. package/dist/tools/backlinks.d.ts.map +1 -0
  97. package/dist/tools/backlinks.js +261 -0
  98. package/dist/tools/backlinks.js.map +1 -0
  99. package/dist/tools/erase.d.ts +15 -0
  100. package/dist/tools/erase.d.ts.map +1 -0
  101. package/dist/tools/erase.js +127 -0
  102. package/dist/tools/erase.js.map +1 -0
  103. package/dist/tools/read.d.ts.map +1 -1
  104. package/dist/tools/read.js +2 -0
  105. package/dist/tools/read.js.map +1 -1
  106. package/dist/tools/write.d.ts.map +1 -1
  107. package/dist/tools/write.js +1 -0
  108. package/dist/tools/write.js.map +1 -1
  109. package/dist/utils/config.d.ts +18 -0
  110. package/dist/utils/config.d.ts.map +1 -1
  111. package/dist/utils/config.js +71 -0
  112. package/dist/utils/config.js.map +1 -1
  113. package/dist/utils/git-erase.d.ts +35 -0
  114. package/dist/utils/git-erase.d.ts.map +1 -0
  115. package/dist/utils/git-erase.js +179 -0
  116. package/dist/utils/git-erase.js.map +1 -0
  117. package/dist/utils/vault-gitignore.d.ts +1 -1
  118. package/dist/utils/vault-gitignore.d.ts.map +1 -1
  119. package/dist/utils/vault-gitignore.js +5 -0
  120. package/dist/utils/vault-gitignore.js.map +1 -1
  121. package/dist/view/index.d.ts +3 -0
  122. package/dist/view/index.d.ts.map +1 -0
  123. package/dist/view/index.js +70 -0
  124. package/dist/view/index.js.map +1 -0
  125. package/dist/view/pages.d.ts +45 -0
  126. package/dist/view/pages.d.ts.map +1 -0
  127. package/dist/view/pages.js +126 -0
  128. package/dist/view/pages.js.map +1 -0
  129. package/dist/view/render.d.ts +4 -0
  130. package/dist/view/render.d.ts.map +1 -0
  131. package/dist/view/render.js +40 -0
  132. package/dist/view/render.js.map +1 -0
  133. package/dist/view/server.d.ts +15 -0
  134. package/dist/view/server.d.ts.map +1 -0
  135. package/dist/view/server.js +136 -0
  136. package/dist/view/server.js.map +1 -0
  137. package/package.json +10 -4
@@ -0,0 +1,105 @@
1
+ import type { DistillConfig } from "../utils/config.js";
2
+ import type { Chunk } from "./chunk.js";
3
+ import type { ExtractOutcome } from "./extract.js";
4
+ /**
5
+ * Pre-flight estimate returned by `planDistill`. No LLM calls made.
6
+ * All cost figures are labeled estimates; see the token heuristic note above.
7
+ */
8
+ export interface DistillPlan {
9
+ /** Number of chunks the source was split into. */
10
+ chunkCount: number;
11
+ /**
12
+ * Estimated LLM calls: min(chunkCount, config.maxLlmCalls).
13
+ * The actual call count may be lower if maxClaims is hit first.
14
+ */
15
+ estimatedLlmCalls: number;
16
+ /**
17
+ * Estimated USD spend, derived from the token heuristic.
18
+ * Falls back to Haiku pricing for unknown models (same as estimateCostUSD).
19
+ */
20
+ estimatedCostUSD: number;
21
+ /** Model id from config — the same model every extraction call will use. */
22
+ model: string;
23
+ /**
24
+ * True when the model has its own pricing row in CONSOLIDATE_PRICING_PER_MTOKEN.
25
+ * False means the estimate uses Haiku fallback pricing — treat with extra caution.
26
+ */
27
+ priced: boolean;
28
+ }
29
+ /** Input options for `buildReceipt`. */
30
+ export interface BuildReceiptOpts {
31
+ /** The outcome from a completed extractClaims run. */
32
+ outcome: ExtractOutcome;
33
+ /** The distill config that governed this run. */
34
+ config: DistillConfig;
35
+ /**
36
+ * Transport that made the LLM calls: "anthropic" | "openrouter".
37
+ * Passed explicitly by the CLI (U7) from resolveDistillClient's transport.
38
+ */
39
+ provider: "anthropic" | "openrouter";
40
+ /**
41
+ * Zero-data-retention flag. Must be supplied explicitly by the caller —
42
+ * never inferred from provider. See ZDR design note at the top of this file.
43
+ * Default: false.
44
+ */
45
+ zdr: boolean;
46
+ /** Optional source identifier (file path, channel id, etc.). */
47
+ sourceId?: string;
48
+ }
49
+ /**
50
+ * Per-run receipt recording actuals after a `--propose` run.
51
+ * Persisted by the CLI (U7) so cost and provenance survive across sessions.
52
+ */
53
+ export interface DistillReceipt {
54
+ /** Unique identifier for this run (random UUID). */
55
+ runId: string;
56
+ /** Optional source that was distilled. */
57
+ sourceId?: string;
58
+ /** Model id used for every extraction call. */
59
+ model: string;
60
+ /** LLM transport used. */
61
+ provider: "anthropic" | "openrouter";
62
+ /**
63
+ * Whether this run was made under a zero-data-retention arrangement.
64
+ * This is caller-asserted, not verified by daftari. Default: false.
65
+ */
66
+ zdr: boolean;
67
+ /** Total LLM calls attempted (from ExtractOutcome.llmCalls). */
68
+ llmCalls: number;
69
+ /** Number of claims produced (claims.length from ExtractOutcome). */
70
+ claimsProduced: number;
71
+ /**
72
+ * True when the run was cut short — either:
73
+ * - claimsProduced >= config.maxClaims (maxClaims wall hit), OR
74
+ * - budget_exhausted (withCallBudget cut the run).
75
+ * Both cases mean downstream vault writes are a partial import.
76
+ */
77
+ truncated: boolean;
78
+ /**
79
+ * Approximate USD cost. Uses the same per-call token heuristic as the
80
+ * pre-flight estimate, scaled by actual llmCalls. The value is an estimate,
81
+ * not a measured count — see ACTUAL COST NOTE.
82
+ */
83
+ approxCostUSD: number;
84
+ /** ISO 8601 timestamp when buildReceipt was called. */
85
+ completedAt: string;
86
+ }
87
+ /**
88
+ * Compute a pre-flight estimate for a distill run.
89
+ *
90
+ * This function is pure (no async, no network, no LLM calls). The zero-spend
91
+ * guarantee is structural: no LlmClient is received, so none can be called.
92
+ *
93
+ * @param chunks - Pre-computed chunks from chunkMessages().
94
+ * @param config - DistillConfig for this vault.
95
+ */
96
+ export declare function planDistill(chunks: Chunk[], config: DistillConfig): DistillPlan;
97
+ /**
98
+ * Build a `DistillReceipt` from the outcome of a completed extractClaims run.
99
+ *
100
+ * Call this after `extractClaims` returns, passing the full ExtractOutcome
101
+ * and the runtime context (provider, zdr, config). The CLI (U7) persists the
102
+ * receipt; this function only constructs it.
103
+ */
104
+ export declare function buildReceipt(opts: BuildReceiptOpts): DistillReceipt;
105
+ //# sourceMappingURL=cost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/distill/cost.ts"],"names":[],"mappings":"AAkDA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA6BnD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,OAAO,EAAE,cAAc,CAAC;IACxB,iDAAiD;IACjD,MAAM,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,QAAQ,EAAE,WAAW,GAAG,YAAY,CAAC;IACrC;;;;OAIG;IACH,GAAG,EAAE,OAAO,CAAC;IACb,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,QAAQ,EAAE,WAAW,GAAG,YAAY,CAAC;IACrC;;;OAGG;IACH,GAAG,EAAE,OAAO,CAAC;IACb,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;CACrB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,aAAa,GAAG,WAAW,CA4C/E;AAMD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,cAAc,CAyBnE"}
@@ -0,0 +1,168 @@
1
+ // src/distill/cost.ts
2
+ //
3
+ // Pre-flight cost estimation (--plan) and per-run receipt recording (--propose)
4
+ // for the distill pipeline. No LLM calls are made here — estimation is purely
5
+ // arithmetic over chunk metadata and config values.
6
+ //
7
+ // Design decisions recorded here (referenced in U6 task report):
8
+ //
9
+ // TOKEN HEURISTIC (pre-flight only):
10
+ // Input tokens per call ≈ min(chunkTextChars, inCallInputCap) / CHARS_PER_TOKEN
11
+ // Output tokens per call ≈ CLAIMS_PER_CHUNK_ESTIMATE * OUTPUT_TOKENS_PER_CLAIM
12
+ // CHARS_PER_TOKEN = 4 (conservative; English prose is ~4 chars/token).
13
+ // CLAIMS_PER_CHUNK_ESTIMATE = 5 (a mid-range guess for a 30-message window).
14
+ // OUTPUT_TOKENS_PER_CLAIM = 30 (a single-sentence claim, ~20-40 tokens).
15
+ // These are documented estimates, not calibrated values. Label: [HYPOTHESIS].
16
+ // The actual token counts are not collected here (the LLM client returns them
17
+ // in CompleteResult, but U3's extractClaims doesn't surface them through
18
+ // ExtractOutcome). The receipt therefore uses the same heuristic for
19
+ // approxCostUSD — see ACTUAL COST NOTE below.
20
+ //
21
+ // ZDR (zero-data-retention) FLAG:
22
+ // Recorded as an explicit caller-supplied boolean, default false.
23
+ // ZDR eligibility is account- and endpoint-specific, not transport-specific.
24
+ // An `anthropic` transport does NOT automatically mean ZDR — it depends on
25
+ // whether the caller's Anthropic account has ZDR enabled. Making it inferred
26
+ // would silently overstate a privacy guarantee. The CLI (U7) passes it
27
+ // explicitly; the receipt preserves whatever the caller asserts.
28
+ //
29
+ // TRUNCATION SIGNAL:
30
+ // `truncated` is true when claimsProduced >= maxClaims OR budget_exhausted.
31
+ // ExtractOutcome.budget_exhausted is a first-class signal from withCallBudget.
32
+ // claimsProduced >= maxClaims covers the maxClaims-wall case (extract stops
33
+ // at the cap; the LLM budget may not be spent). Both cases mean the run did
34
+ // not see all chunks, so the downstream vault write is a partial import.
35
+ //
36
+ // ACTUAL COST NOTE:
37
+ // ExtractOutcome does not carry per-call token counts (they are consumed
38
+ // inside extractClaims but not threaded out). approxCostUSD therefore uses
39
+ // the same per-call heuristic as the pre-flight estimate, scaled by the
40
+ // actual llmCalls count. This is consistent with the estimate and is clearly
41
+ // labeled an approximation. A future slice could add token tracking to
42
+ // ExtractOutcome and replace the heuristic with real numbers.
43
+ //
44
+ // BUDGET ENFORCEMENT:
45
+ // Hard caps (maxLlmCalls via withCallBudget, maxClaims inside extractClaims)
46
+ // are enforced by U2/U3. This module RECORDS the actuals from ExtractOutcome
47
+ // and ESTIMATES for pre-flight; it does not duplicate the cap logic.
48
+ import { randomUUID } from "node:crypto";
49
+ import { estimateCostUSD, isModelPriced } from "../consolidate/constants.js";
50
+ // ---------------------------------------------------------------------------
51
+ // Token estimation constants (pre-flight heuristic)
52
+ // ---------------------------------------------------------------------------
53
+ /**
54
+ * Conservative chars-per-token ratio for English prose.
55
+ * 4 chars/token is the standard rule of thumb; actual ratio for chat
56
+ * transcripts is typically 3.5–4.5. Using 4 avoids underestimating cost.
57
+ */
58
+ const CHARS_PER_TOKEN = 4;
59
+ /**
60
+ * Estimated claims extracted per 30-message chunk — mid-range guess.
61
+ * Used only for output-token estimation in the pre-flight plan.
62
+ */
63
+ const CLAIMS_PER_CHUNK_ESTIMATE = 5;
64
+ /**
65
+ * Estimated output tokens per extracted claim (a short self-contained sentence
66
+ * serialized as JSON). 30 tokens ≈ a 20–40 token range midpoint.
67
+ */
68
+ const OUTPUT_TOKENS_PER_CLAIM = 30;
69
+ // ---------------------------------------------------------------------------
70
+ // planDistill — pre-flight estimate, zero LLM spend
71
+ // ---------------------------------------------------------------------------
72
+ /**
73
+ * Compute a pre-flight estimate for a distill run.
74
+ *
75
+ * This function is pure (no async, no network, no LLM calls). The zero-spend
76
+ * guarantee is structural: no LlmClient is received, so none can be called.
77
+ *
78
+ * @param chunks - Pre-computed chunks from chunkMessages().
79
+ * @param config - DistillConfig for this vault.
80
+ */
81
+ export function planDistill(chunks, config) {
82
+ const chunkCount = chunks.length;
83
+ if (chunkCount === 0) {
84
+ return {
85
+ chunkCount: 0,
86
+ estimatedLlmCalls: 0,
87
+ estimatedCostUSD: 0,
88
+ model: config.model,
89
+ priced: isModelPriced(config.model),
90
+ };
91
+ }
92
+ const estimatedLlmCalls = Math.min(chunkCount, config.maxLlmCalls);
93
+ // Per-call input token estimate: chars of transcript fed to the LLM, capped
94
+ // by inCallInputCap, then divided by CHARS_PER_TOKEN. We use the average
95
+ // chunk text length, bounded by the cap.
96
+ const totalChunkChars = chunks.reduce((sum, c) => sum + c.text.length, 0);
97
+ const avgChunkChars = totalChunkChars / chunkCount;
98
+ const inputCharsPerCall = Math.min(avgChunkChars, config.inCallInputCap);
99
+ const inputTokensPerCall = Math.ceil(inputCharsPerCall / CHARS_PER_TOKEN);
100
+ // Per-call output token estimate: a fixed guess at claims per chunk * tokens
101
+ // per claim, bounded by the total maxClaims cap spread over the estimated
102
+ // number of calls.
103
+ const maxClaimsPerCall = Math.ceil(config.maxClaims / estimatedLlmCalls);
104
+ const outputTokensPerCall = Math.min(CLAIMS_PER_CHUNK_ESTIMATE * OUTPUT_TOKENS_PER_CLAIM, maxClaimsPerCall * OUTPUT_TOKENS_PER_CLAIM);
105
+ const totalInputTokens = inputTokensPerCall * estimatedLlmCalls;
106
+ const totalOutputTokens = outputTokensPerCall * estimatedLlmCalls;
107
+ const estimatedCostUSD = estimateCostUSD(config.model, totalInputTokens, totalOutputTokens);
108
+ return {
109
+ chunkCount,
110
+ estimatedLlmCalls,
111
+ estimatedCostUSD,
112
+ model: config.model,
113
+ priced: isModelPriced(config.model),
114
+ };
115
+ }
116
+ // ---------------------------------------------------------------------------
117
+ // buildReceipt — record actuals after a --propose run
118
+ // ---------------------------------------------------------------------------
119
+ /**
120
+ * Build a `DistillReceipt` from the outcome of a completed extractClaims run.
121
+ *
122
+ * Call this after `extractClaims` returns, passing the full ExtractOutcome
123
+ * and the runtime context (provider, zdr, config). The CLI (U7) persists the
124
+ * receipt; this function only constructs it.
125
+ */
126
+ export function buildReceipt(opts) {
127
+ const { outcome, config, provider, zdr, sourceId } = opts;
128
+ const claimsProduced = outcome.claims.length;
129
+ // Truncation: the run was partial if the claim cap was hit OR the LLM call
130
+ // budget was exhausted. See TRUNCATION SIGNAL design note.
131
+ const truncated = outcome.budget_exhausted || claimsProduced >= config.maxClaims;
132
+ // Approximate cost: token heuristic applied to the real llmCalls count.
133
+ // We don't have real token counts from ExtractOutcome (see ACTUAL COST NOTE).
134
+ const approxCostUSD = costFromLlmCalls(outcome.llmCalls, config);
135
+ return {
136
+ runId: randomUUID(),
137
+ ...(sourceId !== undefined ? { sourceId } : {}),
138
+ model: config.model,
139
+ provider,
140
+ zdr,
141
+ llmCalls: outcome.llmCalls,
142
+ claimsProduced,
143
+ truncated,
144
+ approxCostUSD,
145
+ completedAt: new Date().toISOString(),
146
+ };
147
+ }
148
+ // ---------------------------------------------------------------------------
149
+ // Internal helpers
150
+ // ---------------------------------------------------------------------------
151
+ /**
152
+ * Estimate the cost of `n` actual LLM calls using the same per-call heuristic
153
+ * as planDistill, but with the inCallInputCap as the assumed input size (a
154
+ * conservative upper bound — actual inputs may be shorter).
155
+ *
156
+ * This is intentionally the same formula as planDistill so the estimate and
157
+ * the receipt are directly comparable. When token counts become available from
158
+ * ExtractOutcome, replace `inputTokensPerCall` with the real value.
159
+ */
160
+ function costFromLlmCalls(llmCalls, config) {
161
+ if (llmCalls === 0)
162
+ return 0;
163
+ // Conservative: assume every call hit the full inCallInputCap.
164
+ const inputTokensPerCall = Math.ceil(config.inCallInputCap / CHARS_PER_TOKEN);
165
+ const outputTokensPerCall = CLAIMS_PER_CHUNK_ESTIMATE * OUTPUT_TOKENS_PER_CLAIM;
166
+ return estimateCostUSD(config.model, inputTokensPerCall * llmCalls, outputTokensPerCall * llmCalls);
167
+ }
168
+ //# sourceMappingURL=cost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost.js","sourceRoot":"","sources":["../../src/distill/cost.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,oDAAoD;AACpD,EAAE;AACF,iEAAiE;AACjE,EAAE;AACF,qCAAqC;AACrC,mFAAmF;AACnF,iFAAiF;AACjF,yEAAyE;AACzE,+EAA+E;AAC/E,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,2EAA2E;AAC3E,uEAAuE;AACvE,gDAAgD;AAChD,EAAE;AACF,kCAAkC;AAClC,oEAAoE;AACpE,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,yEAAyE;AACzE,mEAAmE;AACnE,EAAE;AACF,qBAAqB;AACrB,8EAA8E;AAC9E,iFAAiF;AACjF,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,EAAE;AACF,oBAAoB;AACpB,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,+EAA+E;AAC/E,yEAAyE;AACzE,gEAAgE;AAChE,EAAE;AACF,sB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,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ;QACR,GAAG;QACH,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,cAAc;QACd,SAAS;QACT,aAAa;QACb,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACtC,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,QAAgB,EAAE,MAAqB;IAC/D,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAE7B,+DAA+D;IAC/D,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,eAAe,CAAC,CAAC;IAC9E,MAAM,mBAAmB,GAAG,yBAAyB,GAAG,uBAAuB,CAAC;IAEhF,OAAO,eAAe,CACpB,MAAM,CAAC,KAAK,EACZ,kBAAkB,GAAG,QAAQ,EAC7B,mBAAmB,GAAG,QAAQ,CAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { LlmClient } from "../eval/llm.js";
2
+ import type { Chunk } from "./chunk.js";
3
+ /** One extracted claim, keyed for idempotent upsert (U5). */
4
+ export interface ExtractedClaim {
5
+ /** Stable within-source key: `<chunk anchor>:<statement slug>-<hash8>`. */
6
+ claim_key: string;
7
+ /** The claim itself, as a self-contained sentence. */
8
+ statement: string;
9
+ /**
10
+ * Minimal frontmatter seed; the proposal stage (U4) completes it. Only a
11
+ * title here by design — do not grow this into the full staged-action.
12
+ */
13
+ proposed_frontmatter: {
14
+ title: string;
15
+ };
16
+ }
17
+ export interface ExtractOutcome {
18
+ claims: ExtractedClaim[];
19
+ /** True when withCallBudget cut the run short — claims are partial. */
20
+ budget_exhausted: boolean;
21
+ /** LLM calls attempted (including the one refused by the budget). */
22
+ llmCalls: number;
23
+ /** Per-chunk non-budget failures (LLM error or unusable response shape). */
24
+ chunkErrors: Array<{
25
+ anchor: string;
26
+ error: string;
27
+ }>;
28
+ }
29
+ export interface ExtractOpts {
30
+ /** Model id for every extraction call. */
31
+ model: string;
32
+ /** Hard cap on total claims this run may produce (truncate + stop). */
33
+ maxClaims: number;
34
+ /** Max characters of rendered transcript per call (bounds token spend). */
35
+ inCallInputCap: number;
36
+ }
37
+ /**
38
+ * Extract claims from `chunks` — one LLM call per chunk, stopping early when
39
+ * `maxClaims` is reached or the call budget is exhausted. `llm` should be the
40
+ * resolveDistillClient client wrapped in `withCallBudget(client, maxLlmCalls)`.
41
+ * Never throws; per-chunk failures land in `chunkErrors`.
42
+ */
43
+ export declare function extractClaims(chunks: Chunk[], llm: LlmClient, opts: ExtractOpts): Promise<ExtractOutcome>;
44
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/distill/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAIxC,6DAA6D;AAC7D,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,oBAAoB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,uEAAuE;IACvE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,WAAW,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,WAAW;IAC1B,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,cAAc,EAAE,MAAM,CAAC;CACxB;AAwFD;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,KAAK,EAAE,EACf,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,cAAc,CAAC,CAqDzB"}
@@ -0,0 +1,153 @@
1
+ // src/distill/extract.ts
2
+ //
3
+ // Claim extraction (U3, distill stage 3). For each chunk, one budgeted
4
+ // `completeJson` call asks the internal LLM for discrete claims (decisions,
5
+ // facts, commitments). The caller supplies the client already wrapped in
6
+ // `withCallBudget` (see src/consolidate/call-budget.ts); when the budget is
7
+ // exhausted mid-run this stage returns the partial claim set with a
8
+ // `budget_exhausted: true` marker — it never throws.
9
+ //
10
+ // claim_key contract (load-bearing for U5's idempotent upsert): derived
11
+ // deterministically from the chunk's stable content anchor + a slug + short
12
+ // hash of the claim statement. Same source + same LLM output ⇒ same keys on
13
+ // a re-run. Never an ordinal, array index, or random value.
14
+ import { isBudgetExhaustedError } from "../consolidate/call-budget.js";
15
+ import { sha256Hex } from "../utils/hash.js";
16
+ // --- prompt ------------------------------------------------------------------
17
+ const EXTRACT_SYSTEM = `You extract discrete claims from a chat transcript window.
18
+
19
+ A claim is a decision, commitment, factual statement, or stated preference that
20
+ would be worth remembering after the conversation ends. Each claim must be a
21
+ single self-contained sentence, understandable without the transcript. Ground
22
+ every claim in what participants actually said — do not speculate, do not merge
23
+ unrelated points, and return an empty list when the window contains nothing
24
+ worth keeping (greetings, logistics chatter, media placeholders).
25
+
26
+ Paraphrase in your own words by default: a claim is a compiled belief, not a
27
+ transcript excerpt. Do not copy long verbatim spans from the window. If a short
28
+ exact quote is genuinely necessary, keep it brief and enclose only the quoted
29
+ words in double quotes.`;
30
+ const EXTRACT_SCHEMA = {
31
+ type: "object",
32
+ properties: {
33
+ claims: {
34
+ type: "array",
35
+ items: {
36
+ type: "object",
37
+ properties: {
38
+ statement: { type: "string", description: "One self-contained claim sentence." },
39
+ },
40
+ required: ["statement"],
41
+ },
42
+ },
43
+ },
44
+ required: ["claims"],
45
+ };
46
+ function extractUserBody(chunk, inputCap) {
47
+ const transcript = chunk.text.length <= inputCap ? chunk.text : chunk.text.slice(0, inputCap);
48
+ return `Transcript window (starts ${chunk.firstTs}):\n\n${transcript}`;
49
+ }
50
+ // --- claim_key derivation ----------------------------------------------------
51
+ // Lowercased, hyphen-separated slug of the statement, capped so keys stay
52
+ // short. Truncation collisions are disambiguated by the hash suffix below.
53
+ const SLUG_MAX = 48;
54
+ function slugify(statement) {
55
+ const slug = statement
56
+ .toLowerCase()
57
+ .replace(/[^a-z0-9]+/g, "-")
58
+ .replace(/^-+|-+$/g, "")
59
+ .slice(0, SLUG_MAX)
60
+ .replace(/-+$/, "");
61
+ return slug.length > 0 ? slug : "claim";
62
+ }
63
+ function claimKey(anchor, statement) {
64
+ return `${anchor}:${slugify(statement)}-${sha256Hex(statement).slice(0, 8)}`;
65
+ }
66
+ // --- response parsing --------------------------------------------------------
67
+ // Pull usable statements out of the parsed LLM response. Malformed entries
68
+ // (non-object, missing/empty statement) are skipped, mirroring the adapter
69
+ // posture: never throw on bad model output. A response whose top-level shape
70
+ // is unusable returns err so the chunk is recorded as failed.
71
+ function parseStatements(parsed) {
72
+ if (typeof parsed !== "object" || parsed === null)
73
+ return null;
74
+ const claims = parsed.claims;
75
+ if (!Array.isArray(claims))
76
+ return null;
77
+ const out = [];
78
+ for (const entry of claims) {
79
+ if (typeof entry !== "object" || entry === null)
80
+ continue;
81
+ const statement = entry.statement;
82
+ if (typeof statement !== "string")
83
+ continue;
84
+ const trimmed = statement.trim();
85
+ if (trimmed.length === 0)
86
+ continue;
87
+ out.push(trimmed);
88
+ }
89
+ return out;
90
+ }
91
+ const TITLE_MAX = 80;
92
+ function titleOf(statement) {
93
+ return statement.length <= TITLE_MAX ? statement : `${statement.slice(0, TITLE_MAX - 1)}…`;
94
+ }
95
+ // --- extraction pass ---------------------------------------------------------
96
+ /**
97
+ * Extract claims from `chunks` — one LLM call per chunk, stopping early when
98
+ * `maxClaims` is reached or the call budget is exhausted. `llm` should be the
99
+ * resolveDistillClient client wrapped in `withCallBudget(client, maxLlmCalls)`.
100
+ * Never throws; per-chunk failures land in `chunkErrors`.
101
+ */
102
+ export async function extractClaims(chunks, llm, opts) {
103
+ const claims = [];
104
+ const seenKeys = new Set();
105
+ const chunkErrors = [];
106
+ let budgetExhausted = false;
107
+ let llmCalls = 0;
108
+ for (const chunk of chunks) {
109
+ if (claims.length >= opts.maxClaims)
110
+ break;
111
+ const res = await llm.completeJson({
112
+ model: opts.model,
113
+ system: EXTRACT_SYSTEM,
114
+ user: extractUserBody(chunk, opts.inCallInputCap),
115
+ schema: EXTRACT_SCHEMA,
116
+ temperature: 0,
117
+ });
118
+ llmCalls++;
119
+ if (!res.ok) {
120
+ if (isBudgetExhaustedError(res.error)) {
121
+ // Budget spent: stop cleanly with whatever we have. withCallBudget
122
+ // already guarantees no network call happened for this chunk.
123
+ budgetExhausted = true;
124
+ break;
125
+ }
126
+ chunkErrors.push({ anchor: chunk.anchor, error: res.error.message });
127
+ continue;
128
+ }
129
+ const statements = parseStatements(res.value.parsed);
130
+ if (statements === null) {
131
+ chunkErrors.push({
132
+ anchor: chunk.anchor,
133
+ error: `unusable response shape: ${res.value.text.slice(0, 120)}`,
134
+ });
135
+ continue;
136
+ }
137
+ for (const statement of statements) {
138
+ if (claims.length >= opts.maxClaims)
139
+ break;
140
+ const key = claimKey(chunk.anchor, statement);
141
+ if (seenKeys.has(key))
142
+ continue; // same statement twice in one run
143
+ seenKeys.add(key);
144
+ claims.push({
145
+ claim_key: key,
146
+ statement,
147
+ proposed_frontmatter: { title: titleOf(statement) },
148
+ });
149
+ }
150
+ }
151
+ return { claims, budget_exhausted: budgetExhausted, llmCalls, chunkErrors };
152
+ }
153
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/distill/extract.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,EAAE;AACF,uEAAuE;AACvE,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,oEAAoE;AACpE,qDAAqD;AACrD,EAAE;AACF,wEAAwE;AACxE,4EAA4E;AAC5E,4EAA4E;AAC5E,4DAA4D;AAE5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAqC7C,gFAAgF;AAEhF,MAAM,cAAc,GAAG;;;;;;;;;;;;wBAYC,CAAC;AAEzB,MAAM,cAAc,GAAG;IACrB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,MAAM,EAAE;YACN,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,oCAAoC,EAAE;iBACjF;gBACD,QAAQ,EAAE,CAAC,WAAW,CAAC;aACxB;SACF;KACF;IACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;CACZ,CAAC;AAEX,SAAS,eAAe,CAAC,KAAY,EAAE,QAAgB;IACrD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC9F,OAAO,6BAA6B,KAAK,CAAC,OAAO,SAAS,UAAU,EAAE,CAAC;AACzE,CAAC;AAED,gFAAgF;AAEhF,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apters/chat-transcript.js";
3
+ export type { MessageType, NormalizedMessage, SourceAdapter } from "./adapters/types.js";
4
+ export { CHUNK_WINDOW, type Chunk, chunkMessages } from "./chunk.js";
5
+ export { type ExtractedClaim, type ExtractOpts, type ExtractOutcome, extractClaims, } from "./extract.js";
6
+ import { type LlmClient } from "../eval/llm.js";
7
+ import { type LlmTransport } from "../eval/llm-openrouter.js";
8
+ import { type Result } from "../frontmatter/types.js";
9
+ import { type DistillConfig } from "../utils/config.js";
10
+ import type { SourceAdapter } from "./adapters/types.js";
11
+ import { type Chunk } from "./chunk.js";
12
+ import type { ExtractedClaim } from "./extract.js";
13
+ /** Built-in adapter registry, keyed by sourceId(). */
14
+ export declare const ADAPTER_REGISTRY: Record<string, SourceAdapter>;
15
+ /**
16
+ * Resolved distill client and config, returned by `resolveDistillClient`.
17
+ * Later units receive this via dependency injection so they never re-load
18
+ * config or re-construct the client.
19
+ */
20
+ export interface ResolvedDistill {
21
+ client: LlmClient;
22
+ config: DistillConfig;
23
+ /** The transport that was actually resolved and used to build `client`. */
24
+ transport: LlmTransport;
25
+ }
26
+ export declare const DISTILL_NOT_CONFIGURED_MSG: string;
27
+ /**
28
+ * Resolves the distill config from `vaultRoot` and constructs an LLM client.
29
+ *
30
+ * Refuses to run (returns `err`) when:
31
+ * - The config cannot be loaded (malformed yaml, I/O error).
32
+ * - The `distill:` block is absent — no silent default spend.
33
+ * - The resolved transport's API key is missing — fail-fast before any
34
+ * network call (mirrors the consolidate/sleep posture).
35
+ *
36
+ * Transport defaults to `anthropic`; the caller may override via the
37
+ * `DAFTARI_LLM_TRANSPORT` env var or by passing an explicit value.
38
+ *
39
+ * @param vaultRoot - Absolute path to the vault root.
40
+ * @param transport - Optional explicit transport override (CLI flag value).
41
+ */
42
+ export declare function resolveDistillClient(vaultRoot: string, transport?: string): Result<ResolvedDistill, Error>;
43
+ /** Extracted claims are the distill pipeline's "raw claim" (U3). */
44
+ export type RawClaim = ExtractedClaim;
45
+ /** Placeholder — U4 will replace with a real VaultProposal definition. */
46
+ export interface VaultProposal {
47
+ }
48
+ export interface DistillResult {
49
+ /** Parsed messages from the adapter (U1). */
50
+ messages: ReturnType<SourceAdapter["parse"]>;
51
+ /** Chunked message windows (U3). */
52
+ chunks: Chunk[];
53
+ /**
54
+ * Extracted raw claims. The extract stage (extractClaims, U3) needs an LLM
55
+ * client + budget, which only the CLI orchestration (U7) has — so this
56
+ * synchronous entry point keeps the stub and the CLI wires extraction.
57
+ */
58
+ claims: RawClaim[];
59
+ /** Vault write proposals (U4 — stub, always []). */
60
+ proposals: VaultProposal[];
61
+ }
62
+ /**
63
+ * Entry point for the distill pipeline.
64
+ *
65
+ * Currently implements only the parse stage (U1). Chunk, extract, and propose
66
+ * stages are stubs that return empty arrays — later units will replace them
67
+ * in-place without changing this function's signature.
68
+ *
69
+ * @param raw - Raw content of the source file (e.g. a chat export .txt).
70
+ * @param adapter - SourceAdapter instance to use for parsing.
71
+ */
72
+ export declare function distill(raw: string, adapter: SourceAdapter): DistillResult;
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/distill/index.ts"],"names":[],"mappings":"AAoBA,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,KAAK,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,aAAa,GACd,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,2BAA2B,CAAC;AACnC,OAA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