@pulse-editor/cli 0.1.1-beta.9 → 0.1.2

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 (57) hide show
  1. package/dist/app.js +3 -1
  2. package/dist/components/commands/build.js +18 -33
  3. package/dist/components/commands/create.js +38 -12
  4. package/dist/components/commands/dev.js +35 -8
  5. package/dist/components/commands/login.d.ts +2 -2
  6. package/dist/components/commands/login.js +110 -26
  7. package/dist/components/commands/preview.js +50 -11
  8. package/dist/components/commands/publish.js +23 -37
  9. package/dist/components/commands/{start copy.d.ts → skill.d.ts} +1 -1
  10. package/dist/components/commands/skill.js +230 -0
  11. package/dist/components/commands/{preview copy.d.ts → upgrade.d.ts} +1 -1
  12. package/dist/components/commands/upgrade.js +53 -0
  13. package/dist/lib/backend/publish-app.d.ts +1 -0
  14. package/dist/lib/backend/publish-app.js +26 -0
  15. package/dist/lib/backend-url.d.ts +1 -0
  16. package/dist/lib/backend-url.js +3 -0
  17. package/dist/lib/cli-flags.d.ts +18 -0
  18. package/dist/lib/cli-flags.js +18 -0
  19. package/dist/lib/manual.js +28 -0
  20. package/dist/lib/server/express.js +81 -41
  21. package/dist/lib/server/preview/backend/load-remote.cjs +28 -18
  22. package/dist/lib/server/utils.js +3 -3
  23. package/dist/lib/token.js +2 -3
  24. package/dist/lib/webpack/compile.d.ts +2 -0
  25. package/dist/lib/webpack/compile.js +30 -0
  26. package/dist/lib/webpack/configs/mf-client.d.ts +3 -0
  27. package/dist/lib/webpack/configs/mf-client.js +184 -0
  28. package/dist/lib/webpack/configs/mf-server.d.ts +2 -0
  29. package/dist/lib/webpack/configs/mf-server.js +463 -0
  30. package/dist/lib/webpack/configs/preview.d.ts +3 -0
  31. package/dist/lib/webpack/configs/preview.js +117 -0
  32. package/dist/lib/webpack/configs/utils.d.ts +10 -0
  33. package/dist/lib/webpack/configs/utils.js +172 -0
  34. package/dist/lib/webpack/dist/pregistered-actions.d.ts +2 -0
  35. package/dist/lib/webpack/dist/pulse.config.d.ts +7 -0
  36. package/dist/lib/webpack/dist/src/lib/agents/code-modifier-agent.d.ts +2 -0
  37. package/dist/lib/webpack/dist/src/lib/agents/vibe-coding-agent.d.ts +3 -0
  38. package/dist/lib/webpack/dist/src/lib/mcp/utils.d.ts +3 -0
  39. package/dist/lib/webpack/dist/src/lib/streaming/message-stream-controller.d.ts +10 -0
  40. package/dist/lib/webpack/dist/src/lib/types.d.ts +58 -0
  41. package/dist/lib/webpack/dist/src/server-function/generate-code/v1/generate.d.ts +5 -0
  42. package/dist/lib/webpack/dist/src/server-function/generate-code/v2/generate.d.ts +1 -0
  43. package/dist/lib/webpack/tsconfig.server.json +19 -0
  44. package/dist/lib/webpack/webpack-config.d.ts +1 -0
  45. package/dist/lib/webpack/webpack-config.js +24 -0
  46. package/dist/lib/webpack/webpack.config.d.ts +2 -0
  47. package/dist/lib/webpack/webpack.config.js +527 -0
  48. package/package.json +29 -20
  49. package/readme.md +7 -1
  50. package/dist/components/commands/preview copy.js +0 -14
  51. package/dist/components/commands/start copy.js +0 -14
  52. package/dist/lib/deps.d.ts +0 -1
  53. package/dist/lib/deps.js +0 -5
  54. package/dist/lib/node_module_bin.d.ts +0 -1
  55. package/dist/lib/node_module_bin.js +0 -7
  56. package/dist/lib/server/preview/backend/index.d.ts +0 -1
  57. package/dist/lib/server/preview/backend/index.js +0 -23
@@ -0,0 +1,172 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { existsSync, writeFileSync } from "fs";
3
+ import fs from "fs/promises";
4
+ import { globSync } from "glob";
5
+ import { networkInterfaces } from "os";
6
+ import path from "path";
7
+ import { Project, SyntaxKind } from "ts-morph";
8
+ import ts from "typescript";
9
+ import { pathToFileURL } from "url";
10
+ export async function loadPulseConfig() {
11
+ const projectDirName = process.cwd();
12
+ // compile to js file and import
13
+ const program = ts.createProgram({
14
+ rootNames: [path.join(projectDirName, "pulse.config.ts")],
15
+ options: {
16
+ module: ts.ModuleKind.ESNext,
17
+ target: ts.ScriptTarget.ES2020,
18
+ outDir: path.join(projectDirName, "node_modules/.pulse/config"),
19
+ esModuleInterop: true,
20
+ skipLibCheck: true,
21
+ forceConsistentCasingInFileNames: true,
22
+ },
23
+ });
24
+ program.emit();
25
+ // Fix imports in the generated js file for all files in node_modules/.pulse/config
26
+ globSync("node_modules/.pulse/config/**/*.js", {
27
+ cwd: projectDirName,
28
+ absolute: true,
29
+ }).forEach(async (jsFile) => {
30
+ let content = await fs.readFile(jsFile, "utf-8");
31
+ content = content.replace(/(from\s+["']\.\/[^\s"']+)(["'])/g, (match, p1, p2) => {
32
+ // No change if the import already has any extension
33
+ if (p1.match(/\.(js|cjs|mjs|ts|tsx|json)$/)) {
34
+ return match; // No change needed
35
+ }
36
+ return `${p1}.js${p2}`;
37
+ });
38
+ await fs.writeFile(jsFile, content);
39
+ });
40
+ // Copy package.json if exists
41
+ const pkgPath = path.join(projectDirName, "package.json");
42
+ if (existsSync(pkgPath)) {
43
+ const destPath = path.join(projectDirName, "node_modules/.pulse/config/package.json");
44
+ await fs.copyFile(pkgPath, destPath);
45
+ }
46
+ const compiledConfig = path.join(projectDirName, "node_modules/.pulse/config/pulse.config.js");
47
+ const mod = await import(pathToFileURL(compiledConfig).href);
48
+ // delete the compiled config after importing
49
+ await fs.rm(path.join(projectDirName, "node_modules/.pulse/config"), {
50
+ recursive: true,
51
+ force: true,
52
+ });
53
+ return mod.default;
54
+ }
55
+ export function getLocalNetworkIP() {
56
+ const interfaces = networkInterfaces();
57
+ for (const iface of Object.values(interfaces)) {
58
+ if (!iface)
59
+ continue;
60
+ for (const config of iface) {
61
+ if (config.family === "IPv4" && !config.internal) {
62
+ return config.address; // Returns the first non-internal IPv4 address
63
+ }
64
+ }
65
+ }
66
+ return "localhost"; // Fallback
67
+ }
68
+ export async function readConfigFile() {
69
+ // Read pulse.config.json from dist/client
70
+ // Wait until dist/pulse.config.json exists
71
+ while (true) {
72
+ try {
73
+ await fs.access("dist/pulse.config.json");
74
+ break;
75
+ }
76
+ catch (err) {
77
+ // Wait for 100ms before trying again
78
+ await new Promise((resolve) => setTimeout(resolve, 100));
79
+ }
80
+ }
81
+ const data = await fs.readFile("dist/pulse.config.json", "utf-8");
82
+ return JSON.parse(data);
83
+ }
84
+ export function discoverServerFunctions() {
85
+ // Get all .ts files under src/server-function and read use default exports as entry points
86
+ const files = globSync("./src/server-function/**/*.ts");
87
+ const entryPoints = files
88
+ .map((file) => file.replaceAll("\\", "/"))
89
+ .map((file) => {
90
+ return {
91
+ ["./" + file.replace("src/server-function/", "").replace(/\.ts$/, "")]: "./" + file,
92
+ };
93
+ })
94
+ .reduce((acc, curr) => {
95
+ return { ...acc, ...curr };
96
+ }, {});
97
+ return entryPoints;
98
+ }
99
+ export function discoverAppSkillActions() {
100
+ // Get all .ts files under src/skill and read use default exports as entry points
101
+ const files = globSync("./src/skill/*/action.ts");
102
+ const entryPoints = files
103
+ .map((file) => file.replaceAll("\\", "/"))
104
+ .map((file) => {
105
+ // Read default export info in the file using ts-morph to get the function name, and use the function name as the entry point key instead of the file name
106
+ const project = new Project({
107
+ tsConfigFilePath: path.join(process.cwd(), "node_modules/.pulse/tsconfig.server.json"),
108
+ });
109
+ const sourceFile = project.addSourceFileAtPath(file);
110
+ const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
111
+ if (!defaultExportSymbol) {
112
+ console.warn(`No default export found in action file ${file}. Skipping...`);
113
+ return null;
114
+ }
115
+ const defaultExportDeclarations = defaultExportSymbol.getDeclarations();
116
+ if (defaultExportDeclarations.length === 0) {
117
+ console.warn(`No declarations found for default export in action file ${file}. Skipping...`);
118
+ return null;
119
+ }
120
+ const funcDecl = defaultExportDeclarations[0]?.asKind(SyntaxKind.FunctionDeclaration);
121
+ if (!funcDecl) {
122
+ console.warn(`Default export in action file ${file} is not a function declaration. Skipping...`);
123
+ return null;
124
+ }
125
+ // Match `*/src/skill/{actionName}/action.ts` and extract {actionName}
126
+ const pattern = /src\/skill\/([^\/]+)\/action\.ts$/;
127
+ const match = file.replaceAll("\\", "/").match(pattern);
128
+ if (!match) {
129
+ console.warn(`File path ${file} does not match pattern ${pattern}. Skipping...`);
130
+ return null;
131
+ }
132
+ const actionName = match[1];
133
+ if (!actionName) {
134
+ console.warn(`Could not extract action name from file path ${file}. Skipping...`);
135
+ return null;
136
+ }
137
+ return {
138
+ ["./skill/" + actionName]: "./" + file,
139
+ };
140
+ })
141
+ .reduce((acc, curr) => {
142
+ return { ...acc, ...curr };
143
+ }, {});
144
+ return entryPoints;
145
+ }
146
+ // Generate tsconfig for server functions
147
+ export function generateTempTsConfig() {
148
+ const tempTsConfigPath = path.join(process.cwd(), "node_modules/.pulse/tsconfig.server.json");
149
+ if (existsSync(tempTsConfigPath)) {
150
+ return;
151
+ }
152
+ const tsConfig = {
153
+ compilerOptions: {
154
+ target: "ES2020",
155
+ module: "esnext",
156
+ moduleResolution: "bundler",
157
+ strict: true,
158
+ declaration: true,
159
+ outDir: path.join(process.cwd(), "dist"),
160
+ },
161
+ include: [
162
+ path.join(process.cwd(), "src/server-function/**/*"),
163
+ path.join(process.cwd(), "pulse.config.ts"),
164
+ path.join(process.cwd(), "global.d.ts"),
165
+ ],
166
+ exclude: [
167
+ path.join(process.cwd(), "node_modules"),
168
+ path.join(process.cwd(), "dist"),
169
+ ],
170
+ };
171
+ writeFileSync(tempTsConfigPath, JSON.stringify(tsConfig, null, 2));
172
+ }
@@ -0,0 +1,2 @@
1
+ import { Action } from "@pulse-editor/shared-utils";
2
+ export declare const preRegisteredActions: Record<string, Action>;
@@ -0,0 +1,7 @@
1
+ import { AppConfig } from "@pulse-editor/shared-utils";
2
+ /**
3
+ * Pulse Editor Extension Config
4
+ *
5
+ */
6
+ declare const config: AppConfig;
7
+ export default config;
@@ -0,0 +1,2 @@
1
+ import { ChatPromptTemplate } from "@langchain/core/prompts";
2
+ export declare const codeModifierAgentPrompt: ChatPromptTemplate<any, any>;
@@ -0,0 +1,3 @@
1
+ import { MultiServerMCPClient } from "@langchain/mcp-adapters";
2
+ import { MessageStreamController } from "../streaming/message-stream-controller";
3
+ export declare function runVibeCoding(mcpClient: MultiServerMCPClient, userPrompt: string, controller: MessageStreamController): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { MultiServerMCPClient } from "@langchain/mcp-adapters";
2
+ export declare function writeFileToFS(mcpClient: MultiServerMCPClient, uri: string, content: string): Promise<string>;
3
+ export declare function callTerminal(mcpClient: MultiServerMCPClient, command: string): Promise<string>;
@@ -0,0 +1,10 @@
1
+ import { AgentTaskMessageData } from "../types";
2
+ export declare class MessageStreamController {
3
+ private controller;
4
+ private msgCounter;
5
+ private messages;
6
+ private timeCountMap;
7
+ constructor(controller: ReadableStreamDefaultController);
8
+ enqueueNew(data: AgentTaskMessageData, isFinal: boolean): number;
9
+ enqueueUpdate(data: AgentTaskMessageData, isFinal: boolean): void;
10
+ }
@@ -0,0 +1,58 @@
1
+ export type VibeDevFlowNode = {
2
+ id: string;
3
+ children: VibeDevFlowNode[];
4
+ };
5
+ export declare enum AgentTaskMessageType {
6
+ Creation = "creation",
7
+ Update = "update"
8
+ }
9
+ export declare enum AgentTaskMessageDataType {
10
+ Notification = "notification",
11
+ ToolCall = "toolCall",
12
+ ArtifactOutput = "artifactOutput"
13
+ }
14
+ /**
15
+ * Data associated with an AgentTaskItem.
16
+ * The fields included depend on the type of the task item.
17
+ *
18
+ * @property type - The type of the task item, defined by the AgentTaskItemType enum.
19
+ * @property title - (Optional) A brief title or summary of the task item.
20
+ * @property description - (Optional) A detailed description of the task item.
21
+ * @property toolName - (Optional) The name of the tool being called (if applicable).
22
+ * @property parameters - (Optional) A record of parameters associated with the tool call (if applicable).
23
+ * @property error - (Optional) An error message if the task item represents an error.
24
+ * @property result - (Optional) The result or output of the task item (if applicable).
25
+ */
26
+ export type AgentTaskMessageData = {
27
+ type?: AgentTaskMessageDataType;
28
+ title?: string;
29
+ description?: string;
30
+ toolName?: string;
31
+ parameters?: Record<string, unknown>;
32
+ error?: string;
33
+ result?: string;
34
+ };
35
+ /**
36
+ * Represents a single task item generated by the agent.
37
+ * Each task item can be of different types such as tool calls, notifications, or errors.
38
+ *
39
+ * @property type - The type of the task item, defined by the AgentTaskItemType enum.
40
+ * @property messageId - The unique identifier for the task item.
41
+ * This is an incremental number representing the n-th task item.
42
+ * @property data - The data associated with the task item, which varies based on the type.
43
+ * @property isFinal - (Optional) Indicates if the task item is final and no further updates are expected.
44
+ */
45
+ export type AgentTaskMessage = {
46
+ type: AgentTaskMessageType;
47
+ messageId: number;
48
+ data: AgentTaskMessageData;
49
+ isFinal?: boolean;
50
+ };
51
+ export type AgentTaskMessageUpdate = {
52
+ type: AgentTaskMessageType;
53
+ messageId: number;
54
+ updateType: "append";
55
+ delta: AgentTaskMessageData;
56
+ isFinal?: boolean;
57
+ timeUsedSec?: string;
58
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * An example function to echo the body of a POST request.
3
+ * This route is accessible at /server-function/echo
4
+ */
5
+ export default function generate(req: Request): Promise<Response>;
@@ -0,0 +1 @@
1
+ export default function handler(req: Request): Promise<Response>;
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "esnext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "declaration": true,
8
+ "outDir": "dist",
9
+ },
10
+ "include": [
11
+ "../../../../../../src/server-function/**/*",
12
+ "../../../../../../pulse.config.ts",
13
+ "../../../../../../global.d.ts",
14
+ ],
15
+ "exclude": [
16
+ "../../../../../../node_modules",
17
+ "../../../../../../dist",
18
+ ]
19
+ }
@@ -0,0 +1 @@
1
+ export declare function createWebpackConfig(isPreview: boolean, buildTarget: "client" | "server" | "both", mode: "development" | "production"): Promise<import("webpack").Configuration[]>;
@@ -0,0 +1,24 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { makeMFClientConfig } from "./configs/mf-client.js";
3
+ import { makeMFServerConfig } from "./configs/mf-server.js";
4
+ import { makePreviewClientConfig } from "./configs/preview.js";
5
+ export async function createWebpackConfig(isPreview, buildTarget, mode) {
6
+ if (isPreview) {
7
+ const previewClientConfig = await makePreviewClientConfig("development");
8
+ const mfServerConfig = await makeMFServerConfig("development");
9
+ return [previewClientConfig, mfServerConfig];
10
+ }
11
+ else if (buildTarget === "server") {
12
+ const mfServerConfig = await makeMFServerConfig(mode);
13
+ return [mfServerConfig];
14
+ }
15
+ else if (buildTarget === "client") {
16
+ const mfClientConfig = await makeMFClientConfig(mode);
17
+ return [mfClientConfig];
18
+ }
19
+ else {
20
+ const mfClientConfig = await makeMFClientConfig(mode);
21
+ const mfServerConfig = await makeMFServerConfig(mode);
22
+ return [mfClientConfig, mfServerConfig];
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ import wp from 'webpack';
2
+ export declare function createWebpackConfig(isPreview: boolean, buildTarget: 'client' | 'server' | 'both', mode: 'development' | 'production'): Promise<wp.Configuration[]>;