@productbrain/cli 0.1.0-beta.17088 → 0.1.0-beta.17102

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.
@@ -0,0 +1,32 @@
1
+ import type { ACCEPT_REFUSAL_HEADLINE, SAVE_REFUSAL_HEADLINE } from './checklist.js';
2
+ /** DEC-2195: a workspace's daily AI allowance in credits, counted since 00:00 UTC. Not enforced; the block stays the only stop. */
3
+ export declare const AI_ALLOWANCE_CREDITS = 600000;
4
+ /** DEC-2196: the one word for the allowance on every surface (RULE-664). */
5
+ export declare const AI_ALLOWANCE_WORD = "AI allowance";
6
+ /** Each door's own short lead-in; the budget facts after it are the same string. */
7
+ export type DailyLimitDoor = 'Chat is paused' | typeof ACCEPT_REFUSAL_HEADLINE | typeof SAVE_REFUSAL_HEADLINE;
8
+ /** 5000000 as "5,000,000": digits and commas only, so the Convex runtime and every surface print the same figure. */
9
+ export declare function formatCredits(credits: number): string;
10
+ /**
11
+ * RULE-662: two sentences of at most 12 words. The limit the block holds over its rolling 24 hours (the limit, never the
12
+ * spend: the sum can pass it); when it
13
+ * frees up, or that it won't by itself (`freesAt` null: no expiry brings the sum back under it); and that Product
14
+ * Brain raises it, since no product door writes llmDailyBudgetCredits (DEC-2062).
15
+ */
16
+ export declare function dailyLimitSpentMessage(door: DailyLimitDoor, budgetCredits: number, freesAt: number | null): string;
17
+ /** 00:00 UTC of the day `now` falls in: the allowance counts from here, so its sum only rises within a UTC day. */
18
+ export declare function utcDayStart(now: number): number;
19
+ /** The UTC day as YYYY-MM-DD, the `day` the crossing event carries (INS-2825). */
20
+ export declare function utcDay(now: number): string;
21
+ /**
22
+ * Percent of the allowance left after `usedToday` credits: floor((600,000 - used) / 600,000 x 100), but never under 1 while
23
+ * any is left, so the line never reads 0% beside a workspace that has not crossed yet; 0 from the crossing on.
24
+ */
25
+ export declare function allowanceLeft(usedToday: number): number;
26
+ /** True only for the insert that takes today's sum from under the allowance to at or over it (DEC-2195: crossings recorded). */
27
+ export declare function crossesAllowance(usedBefore: number, costCredits: number): boolean;
28
+ /** The one allowance line Settings, pb session start and the MCP session tool print (RULE-662, DEC-2195). */
29
+ export declare function allowanceLine(usedToday: number): string;
30
+ /** The figure under the Settings line: credits used since 00:00 UTC against the allowance. */
31
+ export declare function allowanceCreditsLine(usedToday: number): string;
32
+ //# sourceMappingURL=dailyLimit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dailyLimit.d.ts","sourceRoot":"","sources":["../../src/lib/dailyLimit.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAIrF,mIAAmI;AACnI,eAAO,MAAM,oBAAoB,SAAU,CAAC;AAE5C,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,oFAAoF;AACpF,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,OAAO,uBAAuB,GAAG,OAAO,qBAAqB,CAAC;AAE9G,qHAAqH;AACrH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAYD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGlH;AAED,mHAAmH;AACnH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED,kFAAkF;AAClF,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED,gIAAgI;AAChI,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAEjF;AAED,6GAA6G;AAC7G,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED,8FAA8F;AAC9F,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE9D"}
@@ -0,0 +1,64 @@
1
+ // GENERATED by scripts/generate-mcp-embedded-copies.mjs from kernel/llm/dailyLimit.ts.
2
+ // DO NOT EDIT. Run `npm run mcp:embedded-copies` to regenerate.
3
+ // Local runtime copy for the isolated connector build.
4
+ const MINUTE_MS = 60_000;
5
+ /** DEC-2195: a workspace's daily AI allowance in credits, counted since 00:00 UTC. Not enforced; the block stays the only stop. */
6
+ export const AI_ALLOWANCE_CREDITS = 600_000;
7
+ /** DEC-2196: the one word for the allowance on every surface (RULE-664). */
8
+ export const AI_ALLOWANCE_WORD = 'AI allowance';
9
+ /** 5000000 as "5,000,000": digits and commas only, so the Convex runtime and every surface print the same figure. */
10
+ export function formatCredits(credits) {
11
+ return String(Math.max(0, Math.round(credits))).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
12
+ }
13
+ /**
14
+ * `freesAt` (epoch ms) as "2026-10-12 14:05 UTC": the first whole minute AFTER it, so a retry at that time is never
15
+ * early. Strictly after: the budget window counts a row while its time is >= now - 24h, so at exactly `freesAt` the
16
+ * row still counts (PR #1721 review).
17
+ */
18
+ function formatFreesAt(freesAt) {
19
+ const rounded = Math.floor(freesAt / MINUTE_MS) * MINUTE_MS + MINUTE_MS;
20
+ return `${new Date(rounded).toISOString().slice(0, 16).replace('T', ' ')} UTC`;
21
+ }
22
+ /**
23
+ * RULE-662: two sentences of at most 12 words. The limit the block holds over its rolling 24 hours (the limit, never the
24
+ * spend: the sum can pass it); when it
25
+ * frees up, or that it won't by itself (`freesAt` null: no expiry brings the sum back under it); and that Product
26
+ * Brain raises it, since no product door writes llmDailyBudgetCredits (DEC-2062).
27
+ */
28
+ export function dailyLimitSpentMessage(door, budgetCredits, freesAt) {
29
+ const when = freesAt === null ? "It won't free up by itself" : `It frees up at ${formatFreesAt(freesAt)}`;
30
+ return `${door}: this workspace reached its ${formatCredits(budgetCredits)}-credit limit for 24 hours. ${when}; contact Product Brain for more.`;
31
+ }
32
+ /** 00:00 UTC of the day `now` falls in: the allowance counts from here, so its sum only rises within a UTC day. */
33
+ export function utcDayStart(now) {
34
+ const d = new Date(now);
35
+ return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
36
+ }
37
+ /** The UTC day as YYYY-MM-DD, the `day` the crossing event carries (INS-2825). */
38
+ export function utcDay(now) {
39
+ return new Date(now).toISOString().slice(0, 10);
40
+ }
41
+ /**
42
+ * Percent of the allowance left after `usedToday` credits: floor((600,000 - used) / 600,000 x 100), but never under 1 while
43
+ * any is left, so the line never reads 0% beside a workspace that has not crossed yet; 0 from the crossing on.
44
+ */
45
+ export function allowanceLeft(usedToday) {
46
+ if (usedToday >= AI_ALLOWANCE_CREDITS)
47
+ return 0;
48
+ return Math.max(1, Math.floor(((AI_ALLOWANCE_CREDITS - usedToday) * 100) / AI_ALLOWANCE_CREDITS)); // x100 first: no float drift
49
+ }
50
+ /** True only for the insert that takes today's sum from under the allowance to at or over it (DEC-2195: crossings recorded). */
51
+ export function crossesAllowance(usedBefore, costCredits) {
52
+ return usedBefore < AI_ALLOWANCE_CREDITS && usedBefore + costCredits >= AI_ALLOWANCE_CREDITS;
53
+ }
54
+ /** The one allowance line Settings, pb session start and the MCP session tool print (RULE-662, DEC-2195). */
55
+ export function allowanceLine(usedToday) {
56
+ return usedToday < AI_ALLOWANCE_CREDITS
57
+ ? `${AI_ALLOWANCE_WORD} today: ${allowanceLeft(usedToday)}% left.`
58
+ : `This workspace passed today's ${AI_ALLOWANCE_WORD}; keep working. We'll contact your lead about a bigger plan.`;
59
+ }
60
+ /** The figure under the Settings line: credits used since 00:00 UTC against the allowance. */
61
+ export function allowanceCreditsLine(usedToday) {
62
+ return `${formatCredits(usedToday)} of ${formatCredits(AI_ALLOWANCE_CREDITS)} credits used since 00:00 UTC.`;
63
+ }
64
+ //# sour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of days as words, "last day" for one; pb usage's lines that name their period in words read it too (DEC-2999 point 13). */
2
+ export declare const lastDays: (days: number) => string;
3
+ export declare const USAGE_SECTION_TITLES: {
4
+ readonly outcomes: (days: number) => string;
5
+ readonly qualityCoaching: (days: number) => string;
6
+ };
7
+ /**
8
+ * The names of the AI features the Settings > Usage page and pb usage's By feature rows show, keyed by an llmUsage
9
+ * row's `feature` (TASK-2345; moved from the web usage page). Names for the other keys are TASK-2351.
10
+ */
11
+ export declare const USAGE_FEATURE_NAMES: Readonly<Record<string, string>>;
12
+ /** A feature's name, or its key while it has none (TASK-2351). Both surfaces read this one fallback. */
13
+ export declare function usageFeatureName(feature: string): string;
14
+ //# sourceMappingURL=usageWords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usageWords.d.ts","sourceRoot":"","sources":["../../src/lib/usageWords.ts"],"names":[],"mappings":"AAWA,uIAAuI;AACvI,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,WAAoD,CAAC;AAE1F,eAAO,MAAM,oBAAoB;8BACf,MAAM;qCACC,MAAM;CACrB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMhE,CAAC;AAEF,wGAAwG;AACxG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD"}
@@ -0,0 +1,31 @@
1
+ // GENERATED by scripts/generate-mcp-embedded-copies.mjs from kernel/usageWords.ts.
2
+ // DO NOT EDIT. Run `npm run mcp:embedded-copies` to regenerate.
3
+ // Local runtime copy for the isolated connector build.
4
+ /**
5
+ * The Settings > Usage section titles that name the window their numbers cover, declared once (RULE-664, RULE-17; TASK-2306).
6
+ * `days` is the period the section's read served (its periodDays), never a number typed beside the title. Read by
7
+ * src/routes/(app)/w/[slug]/settings/usage/+page.svelte.
8
+ */
9
+ import { CHAT_WORDS } from './chatWords.js';
10
+ /** A window of days as words, "last day" for one; pb usage's lines that name their period in words read it too (DEC-2999 point 13). */
11
+ export const lastDays = (days) => (days === 1 ? 'last day' : `last ${days} days`);
12
+ export const USAGE_SECTION_TITLES = {
13
+ outcomes: (days) => `Outcomes · ${lastDays(days)}`,
14
+ qualityCoaching: (days) => `Quality coaching · ${lastDays(days)}`,
15
+ };
16
+ /**
17
+ * The names of the AI features the Settings > Usage page and pb usage's By feature rows show, keyed by an llmUsage
18
+ * row's `feature` (TASK-2345; moved from the web usage page). Names for the other keys are TASK-2351.
19
+ */
20
+ export const USAGE_FEATURE_NAMES = {
21
+ quality_coaching: 'Quality Coaching',
22
+ brain_chat: CHAT_WORDS.pageName, // TASK-831 (RULE-664): the chat page's one name
23
+ chainwork: 'ChainWork',
24
+ strategy_synthesis: 'Strategy Synthesis',
25
+ format_content: 'Format Content',
26
+ };
27
+ /** A feature's name, or its key while it has none (TASK-2351). Both surfaces read this one fallback. */
28
+ export function usageFeatureName(feature) {
29
+ return Object.hasOwn(USAGE_FEATURE_NAMES, feature) ? USAGE_FEATURE_NAMES[feature] : feature;
30
+ }
31
+ //# sourceMappingURL=usageWords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usageWords.js","sourceRoot":"","sources":["../../src/lib/usageWords.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,gEAAgE;AAChE,uDAAuD;AAEvD;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,uIAAuI;AACvI,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,CAAC;AAE1F,MAAM,CAAC,MAAM,oBAAoB,GAAG;IACnC,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,cAAc,QAAQ,CAAC,IAAI,CAAC,EAAE;IAC1D,eAAe,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,sBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE;CAChE,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqC;IACpE,gBAAgB,EAAE,kBAAkB;IACpC,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE,gDAAgD;IACjF,SAAS,EAAE,WAAW;IACtB,kBAAkB,EAAE,oBAAoB;IACxC,cAAc,EAAE,gBAAgB;CAChC,CAAC;AAEF,wGAAwG;AACxG,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAC7F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@productbrain/cli",
3
- "version": "0.1.0-beta.17088",
3
+ "version": "0.1.0-beta.17102",
4
4
  "description": "Product Brain — Chain knowledge and write-back CLI",
5
5
  "type": "module",
6
6
  "bin": {