@chrryai/waffles 2.4.42 → 2.4.46

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/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _playwright_test from '@playwright/test';
2
2
  import { Page } from '@playwright/test';
3
+ import { Effect } from 'effect';
3
4
 
4
5
  declare class APIClient {
5
6
  private context;
@@ -55,6 +56,58 @@ declare const scheduledJobFactory: {
55
56
  buildMany(count: number, overrides?: Partial<TribeScheduleInput>): TribeScheduleInput[];
56
57
  };
57
58
 
59
+ /**
60
+ * Branch-Based AI Agent Context System
61
+ *
62
+ * Every git branch becomes an isolated agent workspace.
63
+ * Branch switch = agent context switch (spatial Z-axis navigation).
64
+ */
65
+
66
+ interface BranchAgentWorkspace {
67
+ id: string;
68
+ namespace: string;
69
+ branchName: string;
70
+ fullBranchName: string;
71
+ agentId: string;
72
+ systemPrompt?: string;
73
+ instructions: any[];
74
+ memories: any[];
75
+ characterProfile?: any;
76
+ evolutionScore: number;
77
+ lastCommitSha?: string;
78
+ metadata: Record<string, any>;
79
+ createdOn: string;
80
+ updatedOn: string;
81
+ }
82
+ interface BranchContext {
83
+ currentBranch: string;
84
+ namespace: string;
85
+ branchName: string;
86
+ workspace?: BranchAgentWorkspace;
87
+ previousBranch?: string;
88
+ }
89
+ declare function getCurrentBranch(): string | undefined;
90
+ declare function parseBranchName(fullBranch: string): {
91
+ namespace: string;
92
+ branchName: string;
93
+ };
94
+ declare function generateAgentId(namespace: string, branchName: string): string;
95
+ declare function createBranchWorkspace(fullBranchName: string, overrides?: Partial<BranchAgentWorkspace>): BranchAgentWorkspace;
96
+ declare function loadBranchWorkspace(fullBranchName: string): BranchAgentWorkspace | undefined;
97
+ declare function saveBranchWorkspace(workspace: BranchAgentWorkspace): BranchAgentWorkspace;
98
+ declare function getOrCreateBranchWorkspace(fullBranchName: string): BranchAgentWorkspace;
99
+ declare function switchBranchContext(newBranch: string, previousBranch?: string): BranchContext;
100
+ declare function autoDetectAndSwitch(previousBranch?: string): BranchContext | undefined;
101
+ declare function deleteBranchWorkspace(fullBranchName: string): boolean;
102
+ declare function recordMutation(fullBranchName: string, mutation: {
103
+ type: string;
104
+ description: string;
105
+ success?: boolean;
106
+ }): BranchAgentWorkspace | undefined;
107
+ declare function getCurrentBranchSafe(): Effect.Effect<string | undefined, never, never>;
108
+ declare function switchBranchContextSafe(newBranch: string, previousBranch?: string): Effect.Effect<BranchContext, string, never>;
109
+ declare function autoDetectAndSwitchSafe(previousBranch?: string): Effect.Effect<BranchContext | undefined, string, never>;
110
+
58
111
  /**
59
112
  * ChopStick Expert - Payload Optimizer
60
113
  *
@@ -366,6 +419,52 @@ declare function buildRamenPayload(base: Omit<Ramen, "join" | "depth">, ctx: Cho
366
419
  };
367
420
  };
368
421
 
422
+ /**
423
+ * Golden Ratio Adaptive Trigger System (φ-Engine)
424
+ *
425
+ * Progressive feature unlock mechanism based on Fibonacci thresholds.
426
+ * AI capabilities awaken dynamically as users create threads and accumulate messages.
427
+ */
428
+ declare const FIBONACCI: number[];
429
+ type GoldenFeature = "memory" | "kanban" | "characterProfile" | "instructions" | "placeholders" | "vectorEmbed";
430
+ interface GoldenTrigger {
431
+ feature: GoldenFeature;
432
+ homeApp: "hippo" | "focus" | "sushi" | "grape";
433
+ threadThreshold: number;
434
+ messageThreshold: number;
435
+ }
436
+ interface GoldenTriggerConfig {
437
+ threadThreshold: number;
438
+ messageThreshold: number;
439
+ enabled: boolean;
440
+ }
441
+ type GoldenRatioConfig = Partial<Record<GoldenFeature, GoldenTriggerConfig>>;
442
+ declare const DEFAULT_TRIGGERS: GoldenTrigger[];
443
+ declare function getDefaultTriggers(): GoldenTrigger[];
444
+ declare function getUserGoldenRatioConfig(userConfig?: GoldenRatioConfig | null): Record<GoldenFeature, GoldenTriggerConfig>;
445
+ interface GoldenRatioEvaluation {
446
+ feature: GoldenFeature;
447
+ homeApp: GoldenTrigger["homeApp"];
448
+ triggered: boolean;
449
+ alreadyTriggered: boolean;
450
+ threadThreshold: number;
451
+ messageThreshold: number;
452
+ userThreadCount: number;
453
+ threadMessageCount: number;
454
+ }
455
+ declare function evaluateGoldenRatio(userThreadCount: number, threadMessageCount: number, lastTriggeredFeatures: GoldenFeature[], userConfig?: GoldenRatioConfig | null): GoldenRatioEvaluation[];
456
+ declare function getNewlyTriggeredFeatures(userThreadCount: number, threadMessageCount: number, lastTriggeredFeatures: GoldenFeature[], userConfig?: GoldenRatioConfig | null): GoldenRatioEvaluation[];
457
+ declare function getNextFibonacciThreshold(value: number): number;
458
+ declare function formatFibonacciPreview(userThreadCount: number, threadMessageCount: number, userConfig?: GoldenRatioConfig | null): {
459
+ feature: GoldenFeature;
460
+ homeApp: string;
461
+ progressThread: number;
462
+ progressMessage: number;
463
+ ready: boolean;
464
+ nextThresholdThread: number;
465
+ nextThresholdMessage: number;
466
+ }[];
467
+
369
468
  type modelName = "chatGPT" | "claude" | "gemini" | "sushi" | "perplexity";
370
469
  declare const TEST_GUEST_FINGERPRINTS: string[];
371
470
  declare const TEST_MEMBER_FINGERPRINTS: string[];
@@ -405,4 +504,4 @@ declare const log: ({ page }: {
405
504
  page: Page;
406
505
  }) => void;
407
506
 
408
- export { APIClient, type ChopStickContext, type ChopStickDecision, type JoinWeights, type ModelInfo, type PresetName, type ScheduledJob, type StoreAppKnowledge, type StoreKnowledgeBase, TEST_GUEST_FINGERPRINTS, TEST_MEMBER_EMAILS, TEST_MEMBER_FINGERPRINTS, TEST_URL, VEX_LIVE_FINGERPRINT, VEX_LIVE_FINGERPRINTS, VEX_LIVE_FINGERPRINT_2, VEX_LIVE_FINGERPRINT_3, VEX_TEST_EMAIL, VEX_TEST_EMAIL_2, VEX_TEST_EMAIL_3, VEX_TEST_EMAIL_4, VEX_TEST_FINGERPRINT, VEX_TEST_FINGERPRINT_2, VEX_TEST_FINGERPRINT_3, VEX_TEST_FINGERPRINT_4, VEX_TEST_PASSWORD, VEX_TEST_PASSWORD_2, VEX_TEST_PASSWORD_3, VEX_TEST_PASSWORD_4, buildRamenPayload, buildStoreKnowledgeBase, capitalizeFirstLetter, getJoinWeights, getModelCredits, getPreset, getURL, isCI, log, type modelName, modelPricing, optimizeChopStick, presets, scheduledJobFactory, simulateInputPaste, simulatePaste, storeApps, wait };
507
+ export { APIClient, type BranchAgentWorkspace, type BranchContext, type ChopStickContext, type ChopStickDecision, DEFAULT_TRIGGERS, FIBONACCI, type GoldenFeature, type GoldenRatioConfig, type GoldenTrigger, type GoldenTriggerConfig, type JoinWeights, type ModelInfo, type PresetName, type ScheduledJob, type StoreAppKnowledge, type StoreKnowledgeBase, TEST_GUEST_FINGERPRINTS, TEST_MEMBER_EMAILS, TEST_MEMBER_FINGERPRINTS, TEST_URL, VEX_LIVE_FINGERPRINT, VEX_LIVE_FINGERPRINTS, VEX_LIVE_FINGERPRINT_2, VEX_LIVE_FINGERPRINT_3, VEX_TEST_EMAIL, VEX_TEST_EMAIL_2, VEX_TEST_EMAIL_3, VEX_TEST_EMAIL_4, VEX_TEST_FINGERPRINT, VEX_TEST_FINGERPRINT_2, VEX_TEST_FINGERPRINT_3, VEX_TEST_FINGERPRINT_4, VEX_TEST_PASSWORD, VEX_TEST_PASSWORD_2, VEX_TEST_PASSWORD_3, VEX_TEST_PASSWORD_4, autoDetectAndSwitch, autoDetectAndSwitchSafe, buildRamenPayload, buildStoreKnowledgeBase, capitalizeFirstLetter, createBranchWorkspace, deleteBranchWorkspace, evaluateGoldenRatio, formatFibonacciPreview, generateAgentId, getCurrentBranch, getCurrentBranchSafe, getDefaultTriggers, getJoinWeights, getModelCredits, getNewlyTriggeredFeatures, getNextFibonacciThreshold, getOrCreateBranchWorkspace, getPreset, getURL, getUserGoldenRatioConfig, isCI, loadBranchWorkspace, log, type modelName, modelPricing, optimizeChopStick, parseBranchName, presets, recordMutation, saveBranchWorkspace, scheduledJobFactory, simulateInputPaste, simulatePaste, storeApps, switchBranchContext, switchBranchContextSafe, wait };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _playwright_test from '@playwright/test';
2
2
  import { Page } from '@playwright/test';
3
+ import { Effect } from 'effect';
3
4
 
4
5
  declare class APIClient {
5
6
  private context;
@@ -55,6 +56,58 @@ declare const scheduledJobFactory: {
55
56
  buildMany(count: number, overrides?: Partial<TribeScheduleInput>): TribeScheduleInput[];
56
57
  };
57
58
 
59
+ /**
60
+ * Branch-Based AI Agent Context System
61
+ *
62
+ * Every git branch becomes an isolated agent workspace.
63
+ * Branch switch = agent context switch (spatial Z-axis navigation).
64
+ */
65
+
66
+ interface BranchAgentWorkspace {
67
+ id: string;
68
+ namespace: string;
69
+ branchName: string;
70
+ fullBranchName: string;
71
+ agentId: string;
72
+ systemPrompt?: string;
73
+ instructions: any[];
74
+ memories: any[];
75
+ characterProfile?: any;
76
+ evolutionScore: number;
77
+ lastCommitSha?: string;
78
+ metadata: Record<string, any>;
79
+ createdOn: string;
80
+ updatedOn: string;
81
+ }
82
+ interface BranchContext {
83
+ currentBranch: string;
84
+ namespace: string;
85
+ branchName: string;
86
+ workspace?: BranchAgentWorkspace;
87
+ previousBranch?: string;
88
+ }
89
+ declare function getCurrentBranch(): string | undefined;
90
+ declare function parseBranchName(fullBranch: string): {
91
+ namespace: string;
92
+ branchName: string;
93
+ };
94
+ declare function generateAgentId(namespace: string, branchName: string): string;
95
+ declare function createBranchWorkspace(fullBranchName: string, overrides?: Partial<BranchAgentWorkspace>): BranchAgentWorkspace;
96
+ declare function loadBranchWorkspace(fullBranchName: string): BranchAgentWorkspace | undefined;
97
+ declare function saveBranchWorkspace(workspace: BranchAgentWorkspace): BranchAgentWorkspace;
98
+ declare function getOrCreateBranchWorkspace(fullBranchName: string): BranchAgentWorkspace;
99
+ declare function switchBranchContext(newBranch: string, previousBranch?: string): BranchContext;
100
+ declare function autoDetectAndSwitch(previousBranch?: string): BranchContext | undefined;
101
+ declare function deleteBranchWorkspace(fullBranchName: string): boolean;
102
+ declare function recordMutation(fullBranchName: string, mutation: {
103
+ type: string;
104
+ description: string;
105
+ success?: boolean;
106
+ }): BranchAgentWorkspace | undefined;
107
+ declare function getCurrentBranchSafe(): Effect.Effect<string | undefined, never, never>;
108
+ declare function switchBranchContextSafe(newBranch: string, previousBranch?: string): Effect.Effect<BranchContext, string, never>;
109
+ declare function autoDetectAndSwitchSafe(previousBranch?: string): Effect.Effect<BranchContext | undefined, string, never>;
110
+
58
111
  /**
59
112
  * ChopStick Expert - Payload Optimizer
60
113
  *
@@ -366,6 +419,52 @@ declare function buildRamenPayload(base: Omit<Ramen, "join" | "depth">, ctx: Cho
366
419
  };
367
420
  };
368
421
 
422
+ /**
423
+ * Golden Ratio Adaptive Trigger System (φ-Engine)
424
+ *
425
+ * Progressive feature unlock mechanism based on Fibonacci thresholds.
426
+ * AI capabilities awaken dynamically as users create threads and accumulate messages.
427
+ */
428
+ declare const FIBONACCI: number[];
429
+ type GoldenFeature = "memory" | "kanban" | "characterProfile" | "instructions" | "placeholders" | "vectorEmbed";
430
+ interface GoldenTrigger {
431
+ feature: GoldenFeature;
432
+ homeApp: "hippo" | "focus" | "sushi" | "grape";
433
+ threadThreshold: number;
434
+ messageThreshold: number;
435
+ }
436
+ interface GoldenTriggerConfig {
437
+ threadThreshold: number;
438
+ messageThreshold: number;
439
+ enabled: boolean;
440
+ }
441
+ type GoldenRatioConfig = Partial<Record<GoldenFeature, GoldenTriggerConfig>>;
442
+ declare const DEFAULT_TRIGGERS: GoldenTrigger[];
443
+ declare function getDefaultTriggers(): GoldenTrigger[];
444
+ declare function getUserGoldenRatioConfig(userConfig?: GoldenRatioConfig | null): Record<GoldenFeature, GoldenTriggerConfig>;
445
+ interface GoldenRatioEvaluation {
446
+ feature: GoldenFeature;
447
+ homeApp: GoldenTrigger["homeApp"];
448
+ triggered: boolean;
449
+ alreadyTriggered: boolean;
450
+ threadThreshold: number;
451
+ messageThreshold: number;
452
+ userThreadCount: number;
453
+ threadMessageCount: number;
454
+ }
455
+ declare function evaluateGoldenRatio(userThreadCount: number, threadMessageCount: number, lastTriggeredFeatures: GoldenFeature[], userConfig?: GoldenRatioConfig | null): GoldenRatioEvaluation[];
456
+ declare function getNewlyTriggeredFeatures(userThreadCount: number, threadMessageCount: number, lastTriggeredFeatures: GoldenFeature[], userConfig?: GoldenRatioConfig | null): GoldenRatioEvaluation[];
457
+ declare function getNextFibonacciThreshold(value: number): number;
458
+ declare function formatFibonacciPreview(userThreadCount: number, threadMessageCount: number, userConfig?: GoldenRatioConfig | null): {
459
+ feature: GoldenFeature;
460
+ homeApp: string;
461
+ progressThread: number;
462
+ progressMessage: number;
463
+ ready: boolean;
464
+ nextThresholdThread: number;
465
+ nextThresholdMessage: number;
466
+ }[];
467
+
369
468
  type modelName = "chatGPT" | "claude" | "gemini" | "sushi" | "perplexity";
370
469
  declare const TEST_GUEST_FINGERPRINTS: string[];
371
470
  declare const TEST_MEMBER_FINGERPRINTS: string[];
@@ -405,4 +504,4 @@ declare const log: ({ page }: {
405
504
  page: Page;
406
505
  }) => void;
407
506
 
408
- export { APIClient, type ChopStickContext, type ChopStickDecision, type JoinWeights, type ModelInfo, type PresetName, type ScheduledJob, type StoreAppKnowledge, type StoreKnowledgeBase, TEST_GUEST_FINGERPRINTS, TEST_MEMBER_EMAILS, TEST_MEMBER_FINGERPRINTS, TEST_URL, VEX_LIVE_FINGERPRINT, VEX_LIVE_FINGERPRINTS, VEX_LIVE_FINGERPRINT_2, VEX_LIVE_FINGERPRINT_3, VEX_TEST_EMAIL, VEX_TEST_EMAIL_2, VEX_TEST_EMAIL_3, VEX_TEST_EMAIL_4, VEX_TEST_FINGERPRINT, VEX_TEST_FINGERPRINT_2, VEX_TEST_FINGERPRINT_3, VEX_TEST_FINGERPRINT_4, VEX_TEST_PASSWORD, VEX_TEST_PASSWORD_2, VEX_TEST_PASSWORD_3, VEX_TEST_PASSWORD_4, buildRamenPayload, buildStoreKnowledgeBase, capitalizeFirstLetter, getJoinWeights, getModelCredits, getPreset, getURL, isCI, log, type modelName, modelPricing, optimizeChopStick, presets, scheduledJobFactory, simulateInputPaste, simulatePaste, storeApps, wait };
507
+ export { APIClient, type BranchAgentWorkspace, type BranchContext, type ChopStickContext, type ChopStickDecision, DEFAULT_TRIGGERS, FIBONACCI, type GoldenFeature, type GoldenRatioConfig, type GoldenTrigger, type GoldenTriggerConfig, type JoinWeights, type ModelInfo, type PresetName, type ScheduledJob, type StoreAppKnowledge, type StoreKnowledgeBase, TEST_GUEST_FINGERPRINTS, TEST_MEMBER_EMAILS, TEST_MEMBER_FINGERPRINTS, TEST_URL, VEX_LIVE_FINGERPRINT, VEX_LIVE_FINGERPRINTS, VEX_LIVE_FINGERPRINT_2, VEX_LIVE_FINGERPRINT_3, VEX_TEST_EMAIL, VEX_TEST_EMAIL_2, VEX_TEST_EMAIL_3, VEX_TEST_EMAIL_4, VEX_TEST_FINGERPRINT, VEX_TEST_FINGERPRINT_2, VEX_TEST_FINGERPRINT_3, VEX_TEST_FINGERPRINT_4, VEX_TEST_PASSWORD, VEX_TEST_PASSWORD_2, VEX_TEST_PASSWORD_3, VEX_TEST_PASSWORD_4, autoDetectAndSwitch, autoDetectAndSwitchSafe, buildRamenPayload, buildStoreKnowledgeBase, capitalizeFirstLetter, createBranchWorkspace, deleteBranchWorkspace, evaluateGoldenRatio, formatFibonacciPreview, generateAgentId, getCurrentBranch, getCurrentBranchSafe, getDefaultTriggers, getJoinWeights, getModelCredits, getNewlyTriggeredFeatures, getNextFibonacciThreshold, getOrCreateBranchWorkspace, getPreset, getURL, getUserGoldenRatioConfig, isCI, loadBranchWorkspace, log, type modelName, modelPricing, optimizeChopStick, parseBranchName, presets, recordMutation, saveBranchWorkspace, scheduledJobFactory, simulateInputPaste, simulatePaste, storeApps, switchBranchContext, switchBranchContextSafe, wait };
package/dist/index.js CHANGED
@@ -3,6 +3,9 @@
3
3
  var dotenv = require('dotenv');
4
4
  var test = require('@playwright/test');
5
5
  var faker = require('@faker-js/faker');
6
+ var child_process = require('child_process');
7
+ var crypto = require('crypto');
8
+ var effect = require('effect');
6
9
 
7
10
  function _interopNamespace(e) {
8
11
  if (e && e.__esModule) return e;
@@ -24,7 +27,12 @@ function _interopNamespace(e) {
24
27
 
25
28
  var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
26
29
 
27
- // src/index.ts
30
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
31
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
32
+ }) : x)(function(x) {
33
+ if (typeof require !== "undefined") return require.apply(this, arguments);
34
+ throw Error('Dynamic require of "' + x + '" is not supported');
35
+ });
28
36
  var APIClient = class {
29
37
  context = null;
30
38
  baseURL;
@@ -140,6 +148,211 @@ var scheduledJobFactory = {
140
148
  return Array.from({ length: count }, () => this.build(overrides));
141
149
  }
142
150
  };
151
+ var BRANCH_STORAGE_KEY = "chrry-branch-agents";
152
+ function getStorage() {
153
+ if (typeof globalThis === "undefined") return {};
154
+ try {
155
+ const raw = globalThis[BRANCH_STORAGE_KEY];
156
+ if (raw) return JSON.parse(raw);
157
+ } catch {
158
+ }
159
+ return {};
160
+ }
161
+ function setStorage(data) {
162
+ if (typeof globalThis !== "undefined") {
163
+ globalThis[BRANCH_STORAGE_KEY] = JSON.stringify(data);
164
+ }
165
+ }
166
+ function fileStoragePath() {
167
+ try {
168
+ const cwd = process.cwd();
169
+ return `${cwd}/.chrry/branch-agents.json`;
170
+ } catch {
171
+ return void 0;
172
+ }
173
+ }
174
+ function loadFileStorage() {
175
+ const path = fileStoragePath();
176
+ if (!path) return {};
177
+ try {
178
+ const fs = __require("fs");
179
+ if (fs.existsSync(path)) {
180
+ return JSON.parse(fs.readFileSync(path, "utf-8"));
181
+ }
182
+ } catch {
183
+ }
184
+ return {};
185
+ }
186
+ function saveFileStorage(data) {
187
+ const path = fileStoragePath();
188
+ if (!path) return;
189
+ try {
190
+ const fs = __require("fs");
191
+ const dir = path.replace("/branch-agents.json", "");
192
+ if (!fs.existsSync(dir)) {
193
+ fs.mkdirSync(dir, { recursive: true });
194
+ }
195
+ fs.writeFileSync(path, JSON.stringify(data, null, 2));
196
+ } catch {
197
+ }
198
+ }
199
+ function getAllWorkspaces() {
200
+ const mem = getStorage();
201
+ const file = loadFileStorage();
202
+ return { ...file, ...mem };
203
+ }
204
+ function setAllWorkspaces(data) {
205
+ setStorage(data);
206
+ saveFileStorage(data);
207
+ }
208
+ function getCurrentBranch() {
209
+ const envBranch = process.env.CHRRY_BRANCH || process.env.GIT_BRANCH || process.env.GITHUB_HEAD_REF || process.env.CF_PAGES_BRANCH;
210
+ if (envBranch) return envBranch;
211
+ try {
212
+ const branch = child_process.execSync("git branch --show-current", {
213
+ encoding: "utf-8",
214
+ stdio: ["pipe", "pipe", "ignore"]
215
+ }).trim();
216
+ if (branch) return branch;
217
+ } catch {
218
+ }
219
+ try {
220
+ const desc = child_process.execSync("git describe --all --contains HEAD", {
221
+ encoding: "utf-8",
222
+ stdio: ["pipe", "pipe", "ignore"]
223
+ }).trim();
224
+ if (desc) return desc.replace(/^heads\//, "");
225
+ } catch {
226
+ }
227
+ return void 0;
228
+ }
229
+ function parseBranchName(fullBranch) {
230
+ const parts = fullBranch.split("/");
231
+ if (parts.length >= 2) {
232
+ return {
233
+ namespace: parts.slice(0, -1).join("/"),
234
+ branchName: parts[parts.length - 1]
235
+ };
236
+ }
237
+ return {
238
+ namespace: "default",
239
+ branchName: fullBranch
240
+ };
241
+ }
242
+ function generateAgentId(namespace, branchName) {
243
+ return `agent-${namespace}-${branchName}-${crypto.randomUUID().slice(0, 8)}`;
244
+ }
245
+ function createBranchWorkspace(fullBranchName, overrides) {
246
+ const { namespace, branchName } = parseBranchName(fullBranchName);
247
+ const now = (/* @__PURE__ */ new Date()).toISOString();
248
+ return {
249
+ id: crypto.randomUUID(),
250
+ namespace,
251
+ branchName,
252
+ fullBranchName,
253
+ agentId: overrides?.agentId || generateAgentId(namespace, branchName),
254
+ systemPrompt: overrides?.systemPrompt || defaultSystemPrompt(namespace, branchName),
255
+ instructions: overrides?.instructions || [],
256
+ memories: overrides?.memories || [],
257
+ characterProfile: overrides?.characterProfile,
258
+ evolutionScore: overrides?.evolutionScore ?? 0,
259
+ lastCommitSha: overrides?.lastCommitSha,
260
+ metadata: overrides?.metadata || {
261
+ createdBy: "branch-agent-system",
262
+ version: "1.0"
263
+ },
264
+ createdOn: overrides?.createdOn || now,
265
+ updatedOn: now
266
+ };
267
+ }
268
+ function defaultSystemPrompt(namespace, branchName) {
269
+ return `You are the AI agent for the branch "${namespace}/${branchName}".
270
+ Your knowledge, memories, and behavior are isolated to this branch.
271
+ When switching branches, save your current context and load the new one.
272
+ Collaborate with other branch agents via @namespace/branch mentions.`;
273
+ }
274
+ function loadBranchWorkspace(fullBranchName) {
275
+ const workspaces = getAllWorkspaces();
276
+ return workspaces[fullBranchName];
277
+ }
278
+ function saveBranchWorkspace(workspace) {
279
+ const workspaces = getAllWorkspaces();
280
+ workspace.updatedOn = (/* @__PURE__ */ new Date()).toISOString();
281
+ workspaces[workspace.fullBranchName] = workspace;
282
+ setAllWorkspaces(workspaces);
283
+ return workspace;
284
+ }
285
+ function getOrCreateBranchWorkspace(fullBranchName) {
286
+ const existing = loadBranchWorkspace(fullBranchName);
287
+ if (existing) return existing;
288
+ const created = createBranchWorkspace(fullBranchName);
289
+ return saveBranchWorkspace(created);
290
+ }
291
+ function switchBranchContext(newBranch, previousBranch) {
292
+ const { namespace, branchName } = parseBranchName(newBranch);
293
+ if (previousBranch) {
294
+ const prevWorkspace = loadBranchWorkspace(previousBranch);
295
+ if (prevWorkspace) {
296
+ saveBranchWorkspace(prevWorkspace);
297
+ }
298
+ }
299
+ const workspace = getOrCreateBranchWorkspace(newBranch);
300
+ return {
301
+ currentBranch: newBranch,
302
+ namespace,
303
+ branchName,
304
+ workspace,
305
+ previousBranch
306
+ };
307
+ }
308
+ function autoDetectAndSwitch(previousBranch) {
309
+ const current = getCurrentBranch();
310
+ if (!current) return void 0;
311
+ if (current === previousBranch) {
312
+ return {
313
+ currentBranch: current,
314
+ ...parseBranchName(current),
315
+ workspace: loadBranchWorkspace(current),
316
+ previousBranch
317
+ };
318
+ }
319
+ return switchBranchContext(current, previousBranch);
320
+ }
321
+ function deleteBranchWorkspace(fullBranchName) {
322
+ const workspaces = getAllWorkspaces();
323
+ if (!workspaces[fullBranchName]) return false;
324
+ delete workspaces[fullBranchName];
325
+ setAllWorkspaces(workspaces);
326
+ return true;
327
+ }
328
+ function recordMutation(fullBranchName, mutation) {
329
+ const workspace = loadBranchWorkspace(fullBranchName);
330
+ if (!workspace) return void 0;
331
+ const mutations = workspace.metadata.mutations || [];
332
+ mutations.push({
333
+ ...mutation,
334
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
335
+ });
336
+ const successCount = mutations.filter((m) => m.success).length;
337
+ workspace.evolutionScore = mutations.length > 0 ? successCount / mutations.length : 0;
338
+ workspace.metadata.mutations = mutations.slice(-100);
339
+ return saveBranchWorkspace(workspace);
340
+ }
341
+ function getCurrentBranchSafe() {
342
+ return effect.Effect.sync(() => getCurrentBranch()).pipe(
343
+ effect.Effect.catchAll((e) => effect.Effect.succeed(void 0))
344
+ );
345
+ }
346
+ function switchBranchContextSafe(newBranch, previousBranch) {
347
+ return effect.Effect.sync(() => switchBranchContext(newBranch, previousBranch)).pipe(
348
+ effect.Effect.catchAll((e) => effect.Effect.fail(String(e)))
349
+ );
350
+ }
351
+ function autoDetectAndSwitchSafe(previousBranch) {
352
+ return effect.Effect.sync(() => autoDetectAndSwitch(previousBranch)).pipe(
353
+ effect.Effect.catchAll((e) => effect.Effect.fail(String(e)))
354
+ );
355
+ }
143
356
 
144
357
  // src/agent/chopstickExpert.ts
145
358
  var modelPricing = {
@@ -375,21 +588,8 @@ var presets = {
375
588
  reasoning: ["Free preset"]
376
589
  }
377
590
  };
378
- var sushiSwaps = {
379
- "deepseek/deepseek-v3.2": "nvidia/nemotron-3-super-120b-a12b:free",
380
- "deepseek/deepseek-r1": "qwen/qwen3.6-plus",
381
- "minimax/minimax-m2.5": "qwen/qwen3.6-plus",
382
- "minimax/minimax-m2.7": "qwen/qwen3.6-plus"
383
- };
384
591
  function swapModel(modelId, preferFree) {
385
- if (preferFree) {
386
- return {
387
- modelId: "nvidia/nemotron-3-super-120b-a12b:free",
388
- swapped: modelId !== "nvidia/nemotron-3-super-120b-a12b:free"
389
- };
390
- }
391
- const swapped = sushiSwaps[modelId];
392
- return swapped ? { modelId: swapped, swapped: true } : { modelId, swapped: false };
592
+ return { modelId, swapped: false };
393
593
  }
394
594
  function optimizeChopStick(ctx) {
395
595
  const reasoning = [];
@@ -435,14 +635,10 @@ function optimizeChopStick(ctx) {
435
635
  reasoning.push("Analysis requirement");
436
636
  }
437
637
  if (ctx.allowsModelSwap) {
438
- const swap = swapModel(
638
+ swapModel(
439
639
  modelId,
440
640
  ctx.preferFree || (ctx.creditsLeft ?? 10) < 5
441
641
  );
442
- if (swap.swapped) {
443
- modelId = swap.modelId;
444
- reasoning.push(`Sushi swap`);
445
- }
446
642
  }
447
643
  const pricing = modelPricing[modelId];
448
644
  return {
@@ -537,6 +733,119 @@ function buildRamenPayload(base, ctx) {
537
733
  };
538
734
  }
539
735
 
736
+ // src/agent/goldenRatio.ts
737
+ var FIBONACCI = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144];
738
+ var DEFAULT_TRIGGERS = [
739
+ {
740
+ feature: "memory",
741
+ homeApp: "hippo",
742
+ threadThreshold: 3,
743
+ messageThreshold: 2
744
+ },
745
+ {
746
+ feature: "kanban",
747
+ homeApp: "focus",
748
+ threadThreshold: 5,
749
+ messageThreshold: 3
750
+ },
751
+ {
752
+ feature: "characterProfile",
753
+ homeApp: "hippo",
754
+ threadThreshold: 5,
755
+ messageThreshold: 5
756
+ },
757
+ {
758
+ feature: "placeholders",
759
+ homeApp: "hippo",
760
+ threadThreshold: 8,
761
+ messageThreshold: 5
762
+ },
763
+ {
764
+ feature: "instructions",
765
+ homeApp: "sushi",
766
+ threadThreshold: 8,
767
+ messageThreshold: 8
768
+ },
769
+ {
770
+ feature: "vectorEmbed",
771
+ homeApp: "grape",
772
+ threadThreshold: 13,
773
+ messageThreshold: 8
774
+ }
775
+ ];
776
+ function getDefaultTriggers() {
777
+ return DEFAULT_TRIGGERS.map((t) => ({ ...t }));
778
+ }
779
+ function getUserGoldenRatioConfig(userConfig) {
780
+ const defaults = Object.fromEntries(
781
+ DEFAULT_TRIGGERS.map((t) => [
782
+ t.feature,
783
+ {
784
+ threadThreshold: t.threadThreshold,
785
+ messageThreshold: t.messageThreshold,
786
+ enabled: true
787
+ }
788
+ ])
789
+ );
790
+ if (!userConfig) return defaults;
791
+ for (const key of Object.keys(userConfig)) {
792
+ const cfg = userConfig[key];
793
+ if (!cfg) continue;
794
+ defaults[key] = {
795
+ threadThreshold: cfg.threadThreshold ?? defaults[key].threadThreshold,
796
+ messageThreshold: cfg.messageThreshold ?? defaults[key].messageThreshold,
797
+ enabled: cfg.enabled ?? true
798
+ };
799
+ }
800
+ return defaults;
801
+ }
802
+ function evaluateGoldenRatio(userThreadCount, threadMessageCount, lastTriggeredFeatures, userConfig) {
803
+ const config2 = getUserGoldenRatioConfig(userConfig);
804
+ const triggeredSet = new Set(lastTriggeredFeatures);
805
+ return DEFAULT_TRIGGERS.map((trigger) => {
806
+ const cfg = config2[trigger.feature];
807
+ const isTriggered = cfg.enabled && userThreadCount >= cfg.threadThreshold && threadMessageCount >= cfg.messageThreshold;
808
+ return {
809
+ feature: trigger.feature,
810
+ homeApp: trigger.homeApp,
811
+ triggered: isTriggered,
812
+ alreadyTriggered: triggeredSet.has(trigger.feature),
813
+ threadThreshold: cfg.threadThreshold,
814
+ messageThreshold: cfg.messageThreshold,
815
+ userThreadCount,
816
+ threadMessageCount
817
+ };
818
+ });
819
+ }
820
+ function getNewlyTriggeredFeatures(userThreadCount, threadMessageCount, lastTriggeredFeatures, userConfig) {
821
+ return evaluateGoldenRatio(
822
+ userThreadCount,
823
+ threadMessageCount,
824
+ lastTriggeredFeatures,
825
+ userConfig
826
+ ).filter((e) => e.triggered && !e.alreadyTriggered);
827
+ }
828
+ function getNextFibonacciThreshold(value) {
829
+ const next = FIBONACCI.find((f) => f > value);
830
+ return next ?? FIBONACCI[FIBONACCI.length - 1];
831
+ }
832
+ function formatFibonacciPreview(userThreadCount, threadMessageCount, userConfig) {
833
+ const config2 = getUserGoldenRatioConfig(userConfig);
834
+ return DEFAULT_TRIGGERS.map((trigger) => {
835
+ const cfg = config2[trigger.feature];
836
+ const ready = cfg.enabled && userThreadCount >= cfg.threadThreshold && threadMessageCount >= cfg.messageThreshold;
837
+ return {
838
+ feature: trigger.feature,
839
+ homeApp: trigger.homeApp,
840
+ progressThread: Math.min(1, userThreadCount / cfg.threadThreshold),
841
+ progressMessage: Math.min(1, threadMessageCount / cfg.messageThreshold),
842
+ ready,
843
+ nextThresholdThread: cfg.threadThreshold,
844
+ nextThresholdMessage: cfg.messageThreshold
845
+ };
846
+ });
847
+ }
848
+
540
849
  // src/index.ts
541
850
  dotenv__namespace.config();
542
851
  var TEST_GUEST_FINGERPRINTS = (process.env.TEST_GUEST_FINGERPRINTS?.split(",") || []).filter((fp) => fp);
@@ -649,6 +958,8 @@ var log = ({ page }) => {
649
958
  };
650
959
 
651
960
  exports.APIClient = APIClient;
961
+ exports.DEFAULT_TRIGGERS = DEFAULT_TRIGGERS;
962
+ exports.FIBONACCI = FIBONACCI;
652
963
  exports.TEST_GUEST_FINGERPRINTS = TEST_GUEST_FINGERPRINTS;
653
964
  exports.TEST_MEMBER_EMAILS = TEST_MEMBER_EMAILS;
654
965
  exports.TEST_MEMBER_FINGERPRINTS = TEST_MEMBER_FINGERPRINTS;
@@ -669,22 +980,42 @@ exports.VEX_TEST_PASSWORD = VEX_TEST_PASSWORD;
669
980
  exports.VEX_TEST_PASSWORD_2 = VEX_TEST_PASSWORD_2;
670
981
  exports.VEX_TEST_PASSWORD_3 = VEX_TEST_PASSWORD_3;
671
982
  exports.VEX_TEST_PASSWORD_4 = VEX_TEST_PASSWORD_4;
983
+ exports.autoDetectAndSwitch = autoDetectAndSwitch;
984
+ exports.autoDetectAndSwitchSafe = autoDetectAndSwitchSafe;
672
985
  exports.buildRamenPayload = buildRamenPayload;
673
986
  exports.buildStoreKnowledgeBase = buildStoreKnowledgeBase;
674
987
  exports.capitalizeFirstLetter = capitalizeFirstLetter;
988
+ exports.createBranchWorkspace = createBranchWorkspace;
989
+ exports.deleteBranchWorkspace = deleteBranchWorkspace;
990
+ exports.evaluateGoldenRatio = evaluateGoldenRatio;
991
+ exports.formatFibonacciPreview = formatFibonacciPreview;
992
+ exports.generateAgentId = generateAgentId;
993
+ exports.getCurrentBranch = getCurrentBranch;
994
+ exports.getCurrentBranchSafe = getCurrentBranchSafe;
995
+ exports.getDefaultTriggers = getDefaultTriggers;
675
996
  exports.getJoinWeights = getJoinWeights;
676
997
  exports.getModelCredits = getModelCredits;
998
+ exports.getNewlyTriggeredFeatures = getNewlyTriggeredFeatures;
999
+ exports.getNextFibonacciThreshold = getNextFibonacciThreshold;
1000
+ exports.getOrCreateBranchWorkspace = getOrCreateBranchWorkspace;
677
1001
  exports.getPreset = getPreset;
678
1002
  exports.getURL = getURL;
1003
+ exports.getUserGoldenRatioConfig = getUserGoldenRatioConfig;
679
1004
  exports.isCI = isCI;
1005
+ exports.loadBranchWorkspace = loadBranchWorkspace;
680
1006
  exports.log = log;
681
1007
  exports.modelPricing = modelPricing;
682
1008
  exports.optimizeChopStick = optimizeChopStick;
1009
+ exports.parseBranchName = parseBranchName;
683
1010
  exports.presets = presets;
1011
+ exports.recordMutation = recordMutation;
1012
+ exports.saveBranchWorkspace = saveBranchWorkspace;
684
1013
  exports.scheduledJobFactory = scheduledJobFactory;
685
1014
  exports.simulateInputPaste = simulateInputPaste;
686
1015
  exports.simulatePaste = simulatePaste;
687
1016
  exports.storeApps = storeApps;
1017
+ exports.switchBranchContext = switchBranchContext;
1018
+ exports.switchBranchContextSafe = switchBranchContextSafe;
688
1019
  exports.wait = wait;
689
1020
  //# sourceMappingURL=index.js.map
690
1021
  //# sourceMappingURL=index.js.map