builder.io 1.6.98 → 1.6.99

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.
@@ -1,6 +1,6 @@
1
1
  import type { DevToolsSys } from "../types";
2
2
  import { type Credentials } from "./credentials";
3
- import type { CodegenFeedback, CodegenTurn, CommitMode, CustomInstruction, GenerateCompletionState, GenerateCompletionStep, GenerateCompletionStepGit, GenerateUserMessage, UserContext, WorkspaceConfiguration, WorkspaceFolder } from "$/ai-utils";
3
+ import type { CodegenFeedback, CodegenTurn, CommitMode, CustomInstruction, GenerateCompletionState, GenerateCompletionStep, GenerateCompletionStepGit, GenerateUserMessage, UserContext, WorkspaceConfiguration, WorkspaceFolder, LoadWholeSessionOptions, LoadWholeSessionResult, LoadHistoryResult } from "$/ai-utils";
4
4
  import prettier from "prettier";
5
5
  import { type FusionContext } from "./code-tools";
6
6
  import EventEmitter from "node:events";
@@ -46,18 +46,8 @@ export declare class CodeGenSession {
46
46
  constructor(options: CodeGenSessionOptions);
47
47
  get workingDirectory(): string;
48
48
  initializeSession(): Promise<void>;
49
- loadWholeSession(opts?: {
50
- linear?: boolean;
51
- getAll?: boolean;
52
- }): Promise<{
53
- sessionId: string;
54
- title: string | undefined;
55
- beforeCommit: string | undefined;
56
- createdUnixTime: number;
57
- updatedUnixTime: number;
58
- addedTurns: number;
59
- turns: CodegenTurn[];
60
- }>;
49
+ loadHistory(): Promise<LoadHistoryResult>;
50
+ loadWholeSession(opts?: LoadWholeSessionOptions): Promise<LoadWholeSessionResult>;
61
51
  loadMoreTurns(): Promise<CodegenTurn[]>;
62
52
  setRepoUrl(repoUrl: string): void;
63
53
  getRepoUrl(): string | undefined;
@@ -160,9 +150,19 @@ export declare class CodeGenSession {
160
150
  * @param dryRun If true, only simulate the restoration without making changes
161
151
  * @returns Array of file paths that were changed
162
152
  */
163
- restore(location: "before" | "after", predicate: (turn: CodegenTurn | null, index: number) => boolean, dryRun?: boolean): Promise<string[] | null>;
153
+ restore({ location, predicate, dryRun, forceReplay, }: {
154
+ location: "before" | "after";
155
+ predicate: (turn: CodegenTurn | null, index: number) => boolean;
156
+ dryRun?: boolean;
157
+ forceReplay?: boolean;
158
+ }): Promise<string[] | null>;
164
159
  restoreHEAD(): Promise<string[] | null>;
165
160
  restoreAll(): Promise<string[] | null>;
161
+ restoreFromCompletionId({ location, completionId, forceReplay, }: {
162
+ location: "before" | "after";
163
+ completionId: string;
164
+ forceReplay?: boolean;
165
+ }): Promise<string[] | null>;
166
166
  restoreBeforeCompletionId(completionId: string): Promise<string[] | null>;
167
167
  /**
168
168
  * Undo all changes back to the last user message
@@ -1,108 +1,64 @@
1
1
  import type { DevToolsSys } from "@builder.io/dev-tools/core";
2
- import { EventEmitter } from "events";
3
- import type { FusionConfig } from "$/ai-utils";
4
- export declare enum InitState {
5
- IDLE = "IDLE",
6
- CHECKING_DIRECTORIES = "CHECKING_DIRECTORIES",
7
- CONFIGURING_GIT_REPO = "CONFIGURING_GIT_REPO",
8
- CONFIGURING_GIT_USER = "CONFIGURING_GIT_USER",
9
- INSTALLING_DEPENDENCIES = "INSTALLING_DEPENDENCIES",
10
- STASHING_CHANGES = "STASHING_CHANGES",
11
- COMPLETED = "COMPLETED",
12
- FAILED = "FAILED",
13
- CANCELLED = "CANCELLED"
14
- }
2
+ import type { FusionConfig, WorkspaceFolder } from "$/ai-utils";
15
3
  export interface InitConfig {
16
4
  fusionConfig: FusionConfig;
17
- retryDelayMs?: number;
18
- maxRetryDelayMs?: number;
19
5
  sys: DevToolsSys;
20
6
  debug?: boolean;
21
7
  runSetupCommand: boolean;
22
8
  }
23
- export declare enum InitErrorType {
24
- FATAL = "fatal",
25
- SOFT_ERROR = "soft-error",
26
- HARD_ERROR = "hard-error"
27
- }
28
- export interface InitError {
29
- userMessage: string;
30
- contextForLLMs?: string;
31
- type: InitErrorType;
32
- }
33
- export interface InitExecutionResult {
34
- success: boolean;
35
- errors: InitError[];
36
- }
37
9
  export interface InitStatus {
38
- state: InitState;
39
- progress: number;
40
10
  message: string;
41
11
  error?: string;
42
- metadata?: Record<string, any>;
43
12
  }
44
- export interface OperationLogEntry {
45
- id: string;
46
- operation: string;
47
- state: InitState;
48
- startTime: number;
49
- endTime?: number;
50
- duration?: number;
51
- status: "started" | "completed" | "failed" | "aborted";
52
- error?: string;
53
- metadata?: Record<string, any>;
54
- }
55
- export interface InitStateMachineEvents {
56
- status: (status: InitStatus) => void;
57
- operation: (entry: OperationLogEntry) => void;
58
- error: (error: string, state: InitState) => void;
59
- complete: (success: boolean, finalState: InitState) => void;
60
- abort: (state: InitState) => void;
13
+ declare enum InitStateStep {
14
+ Init = "init",
15
+ Validation = "validation",
16
+ CheckDirectories = "check-directories",
17
+ CreateDirectories = "create-directories",
18
+ ConfigureGitRepos = "configure-git-repos",
19
+ CheckExistingGit = "check-existing-git",
20
+ UpdateRemoteUrl = "update-remote-url",
21
+ CloneRepo = "clone-repo",
22
+ ConfigureGitUser = "configure-git-user",
23
+ InstallDependencies = "install-dependencies",
24
+ StashChanges = "stash-changes",
25
+ InitSuccess = "init-success",
26
+ InitFailed = "init-failed"
61
27
  }
62
- export interface TypedEventEmitter {
63
- on<K extends keyof InitStateMachineEvents>(event: K, listener: InitStateMachineEvents[K]): this;
64
- off<K extends keyof InitStateMachineEvents>(event: K, listener: InitStateMachineEvents[K]): this;
65
- emit<K extends keyof InitStateMachineEvents>(event: K, ...args: Parameters<InitStateMachineEvents[K]>): boolean;
28
+ export interface InitStatusLog {
29
+ id: number;
30
+ timestamp: string;
31
+ type: "status" | "log" | "error" | "complete";
32
+ message: string;
33
+ step?: InitStateStep;
34
+ error?: string;
35
+ success?: boolean;
66
36
  }
67
- export declare class InitStateMachine extends EventEmitter implements TypedEventEmitter {
68
- private currentState;
69
- private config;
70
- private retryCount;
71
- private metadata;
72
- private abortController;
73
- private activeChildProcesses;
74
- private readonly baseRetryDelay;
75
- private readonly maxRetryDelay;
76
- private readonly execAsync;
77
- private operationLog;
78
- private operationCounter;
79
- private readonly repositories;
80
- private allInitErrors;
81
- constructor(config: InitConfig);
82
- private updateStatus;
83
- private sanitizeError;
84
- private delay;
85
- private calculateRetryDelay;
86
- private executeWithRetry;
87
- private getProgress;
88
- private checkAborted;
89
- private checkDirectories;
37
+ export declare class InitStateMachine {
38
+ logIdCounter: number;
39
+ initStatusLogs: InitStatusLog[];
40
+ initState: {
41
+ isRunning: boolean;
42
+ isComplete: boolean;
43
+ success: boolean;
44
+ currentStep: string;
45
+ error: string | undefined;
46
+ };
47
+ init(config: InitConfig, signal?: AbortSignal): Promise<boolean>;
48
+ addInitLog(type: "status" | "log" | "error" | "complete", message: string, options?: {
49
+ step?: InitStateStep;
50
+ error?: string;
51
+ success?: boolean;
52
+ }): void;
53
+ clearInitLogs(): void;
54
+ step1CheckDirectories(config: InitConfig, repositories: Required<WorkspaceFolder>[], signal?: AbortSignal): Promise<void>;
55
+ step2ConfigureGitRepositories(config: InitConfig, repositories: Required<WorkspaceFolder>[], signal?: AbortSignal): Promise<void>;
56
+ step3ConfigureGitUser(config: InitConfig, repositories: Required<WorkspaceFolder>[], signal?: AbortSignal): Promise<void>;
57
+ step4InstallDependencies(config: InitConfig, signal?: AbortSignal): Promise<void>;
58
+ step5StashChanges(config: InitConfig, repositories: Required<WorkspaceFolder>[], signal?: AbortSignal): Promise<void>;
90
59
  private isGitConfigured;
91
60
  private getGitRemoteUrl;
92
61
  private sanitizeGitRemoteUrl;
93
- private cloneRepository;
94
- private configureGitRepos;
95
- private configureGitUser;
96
- private installDependencies;
97
- private stashChanges;
98
- execute(signal?: AbortSignal): Promise<InitExecutionResult>;
99
- getCurrentState(): InitState;
100
- getMetadata(): Record<string, any>;
101
- getOperationLog(): OperationLogEntry[];
102
- cleanup(): Promise<void>;
103
- private startOperation;
104
- private completeOperation;
105
- private failOperation;
106
- private abortOperation;
107
- private getPerformanceStats;
62
+ cloneRepository(repo: Required<WorkspaceFolder>, repoPath: string, debug?: boolean, signal?: AbortSignal): Promise<boolean>;
108
63
  }
64
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { type Express } from "express";
2
+ import type { InitStateMachine } from "./InitStateMachine";
2
3
  export declare const BUILDER_ENDPOINT_PREFIX = "/_builder.io";
3
4
  export declare const BUILDER_API_ENDPOINT_PREFIX: string;
4
5
  /**
@@ -7,10 +8,12 @@ export declare const BUILDER_API_ENDPOINT_PREFIX: string;
7
8
  export declare const NON_AUTHENTICATED_ENDPOINTS: {
8
9
  readonly STATUS: "/status";
9
10
  readonly PROXY_STATUS: "/proxy-status";
11
+ readonly STATUS_V2: "/status-v2";
10
12
  };
11
- export declare const configureServer: ({ app, validBuilderPrivateKey, authenticateProxy, isLocal, }: {
13
+ export declare const configureServer: ({ app, validBuilderPrivateKey, authenticateProxy, isLocal, initStateMachine, }: {
12
14
  app: Express;
13
15
  validBuilderPrivateKey: string | undefined;
14
16
  authenticateProxy: boolean;
15
17
  isLocal: boolean;
18
+ initStateMachine?: InitStateMachine;
16
19
  }) => void;
@@ -1 +1 @@
1
- export declare const REPO_INDEXING_GROUP_PROMPT = "# Component Repository Analysis and Grouping\n\n## Objective\nAnalyze the repository to identify and categorize components based on **mandatory architectural interdependency**, creating groups ONLY when components literally cannot function independently and MUST be used together.\n\n## Component Grouping Philosophy - STRICT CRITERIA\n\n### ONLY Group Components That Meet ALL These Requirements:\n\n1. **Mandatory Compositional Architecture**\n - Components that literally cannot render or function without their counterparts\n - Parent components that are meaningless without specific child components\n - Child components that will throw errors or fail without their required parent\n - Example: `Table` requires `TableHeader`, `TableBody`, `TableRow`, `TableCell` to be functional\n\n2. **Exclusive Required Context Dependencies**\n - Components that share context where the context is NOT optional\n - Child components that will fail without the parent's required context\n - Components with hard-coded provider-consumer relationships that cannot be bypassed\n - Example: `FormField` + `FormLabel` + `FormControl` sharing required form context\n\n3. **Critical Runtime Dependencies**\n - Components that reference each other's internal APIs or state directly\n - Components that communicate through required internal protocols\n - Components where removing one breaks the others at runtime\n\n### What MUST REMAIN SEPARATE - Even If They Share Code\n\n**Shared Infrastructure \u2260 Interdependency**\n- AreaChart, BarChart, LineChart are SEPARATE even if they use shared cartesian infrastructure\n- Each chart can render independently without the others\n- Shared internal components are implementation details, not architectural coupling\n\n**Thematic Similarity \u2260 Coupling** \n- Button, IconButton, ToggleButton stay separate (each works alone)\n- Input, Select, TextArea stay separate (independent form controls)\n- Card, Panel, Modal stay separate (independent containers)\n\n**Optional Composition \u2260 Required Composition**\n- Components that CAN work together but don't HAVE to\n- Components where composition is for convenience, not necessity\n\n## Strict Validation Test\nBefore grouping ANY components, ask these questions. ALL must be \"YES\":\n\n1. **Removal Test**: If I remove one component from this group, do the others become non-functional or throw errors?\n2. **Independence Test**: Can ANY component in this group render successfully in complete isolation?\n3. **Context Test**: Do these components share context that is absolutely required (not optional)?\n4. **API Test**: Do these components directly call each other's methods or access each other's internal state?\n\nIf ANY answer is \"NO\" \u2192 DO NOT GROUP\n\n## Examples of CORRECT Grouping\n\n** Table Group** (Critical Coupling)\n```json\n{\n \"name\": \"Table\",\n \"components\": [\"Table\", \"TableHeader\", \"TableBody\", \"TableRow\", \"TableCell\"],\n}\n```\nWhy: Table component cannot render without TableHeader, TableBody, etc. Each piece is meaningless alone.\n\n**Form Field Group** (Strong Coupling) \n```json\n{\n \"name\": \"FormField\", \n \"components\": [\"FormField\", \"FormLabel\", \"FormControl\", \"FormMessage\"]\n}\n```\nWhy: These share required form context and cannot function independently.\n\n## Examples of INCORRECT Grouping\n\n** Charts Group** (Shared Infrastructure \u2260 Coupling)\n```json\n// WRONG - Don't do this\n{\n \"name\": \"Charts\",\n \"components\": [\"AreaChart\", \"BarChart\", \"LineChart\", \"PieChart\"]\n}\n```\nWhy: Each chart renders independently. Shared infrastructure is an implementation detail.\n\n** Button Group** (Thematic Similarity \u2260 Coupling)\n```json\n// WRONG - Don't do this \n{\n \"name\": \"Buttons\",\n \"components\": [\"Button\", \"IconButton\", \"ToggleButton\"]\n}\n```\nWhy: Each button type works completely independently.\n\n## Default Assumption: KEEP SEPARATE\n- When in doubt, create separate groups for each component\n- Err on the side of independence rather than grouping\n- Most components should end up in individual groups\n\n## Instructions\n\n### 1. Component Discovery\n{{component-discovery}}\n\n### 2. Interdependency Analysis\nFor each component, analyze:\n- **Required Dependencies**: What other components MUST be present for this to work?\n- **Context Requirements**: Does this component require specific context providers?\n- **Compositional Rules**: Are there mandatory parent-child relationships?\n- **Shared State**: Do components communicate through shared internal state?\n\n### 3. Coupling Strength Assessment\nEvaluate coupling strength:\n- **Critical Coupling**: Components cannot function without each other\n- **Strong Coupling**: Components are designed to work together with shared context\n- **Moderate Coupling**: Components enhance each other but can work independently\n- **Weak Coupling**: Components are thematically related but functionally independent\n\n### 4. Group Formation Rules\n- **Group together**: Components with Critical or Strong coupling\n- **Consider grouping**: Components with Moderate coupling (case-by-case basis)\n- **Keep separate**: Components with Weak coupling or functional independence\n\n### 5. Relevant Files Collection\nFor each group, include:\n- Primary component files (.tsx, .ts)\n- Context providers or shared state files\n- Type definition files specific to the group\n- Hook files that bind the components together\n- Test files that test the group as a unit\n- Documentation files specific to the group\n- Example files showing the components working together\n\n## Required Output Format\n\nGenerate a component-groups.json file with this structure:\n\n```json\n{{output-format}}\n```\n\n### Coupling Strength Definitions:\n- **\"critical\"**: Components cannot function without each other (Table group)\n- **\"strong\"**: Components share exclusive context/state (Form group) \n- **\"moderate\"**: Components enhance each other but can work alone (ButtonGroup + Button)\n- **\"none\"**: Component is functionally independent (standalone Button)\n\n## Quality Requirements\n\n**Be Conservative:**\n- Prefer individual component groups over multi-component groups\n- Only group when there's undeniable architectural interdependency\n- Most components should be individual groups\n\n**Component Coverage:**\n{{component-coverage}}\n- Every component must appear in exactly one group\n- Prefer smaller, focused groups over large, loosely-coupled groups\n- Create individual groups for truly independent components\n\n**Grouping Validation:**\nFor each proposed group, ask:\n1. Would removing any component make the others useless or broken?\n2. Is there a required parent-child rendering relationship?\n3. Do they share mandatory (not optional) context or state?\n\nIf you can't answer \"YES\" confidently to at least one of these, keep components separate.\n\n**File Selection:**\n- Include files that are essential to understanding the group's architecture\n- Focus on files that show interdependencies between components\n- Include context providers, shared hooks, and type definitions\n- Exclude generic utility files unless they're group-specific\n\n## Anti-Patterns to Avoid\n\n**Don't group by theme alone**\n- Wrong: Group Button, IconButton, ToggleButton because they're all \"buttons\"\n- Right: Keep them separate because each works independently\n\n**Don't create mega-groups** \n- Wrong: Group all form-related components together\n- Right: Group only those that share context (FormField + FormLabel + FormControl)\n\n**Don't group by visual similarity**\n- Wrong: Group Card, Panel, Container because they're all \"containers\" \n- Right: Keep separate because they serve different architectural purposes\n\n**Don't group by shared infrastructure**\n- Wrong: Group AreaChart, BarChart, LineChart because they use shared cartesian components\n- Right: Keep separate because each chart works independently\n\n## Output Requirements\n- Return ONLY the JSON array\n- No additional commentary or explanation\n- Ensure valid JSON format\n- Include all required fields for each group\n- Validate that every component appears exactly once\n- Most groups should contain only one component";
1
+ export declare const REPO_INDEXING_GROUP_PROMPT: string;