beam-shared 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Beam Non-Commercial License
2
+
3
+ Copyright (c) 2026 Suman Biswas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to use,
7
+ copy, modify, and distribute the Software for personal, educational, internal,
8
+ and other non-commercial purposes, subject to the following conditions:
9
+
10
+ 1. The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ 2. The Software may not be sold, sublicensed for a fee, or used for any
14
+ commercial purpose.
15
+
16
+ 3. Commercial purpose includes any use primarily intended for or directed
17
+ toward commercial advantage or monetary compensation, including paid products,
18
+ paid services, consulting deliverables, or resale.
19
+
20
+ 4. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ export declare const EMPTY_STATE_MESSAGES: readonly [{
2
+ readonly lead: "Ask a question, open a command, or drop in a file to begin.";
3
+ readonly tip: "Beam can also help with searches, edits, and project awareness.";
4
+ }, {
5
+ readonly lead: "Start local with Ollama, or switch to OpenAI when you need it.";
6
+ readonly tip: "Type / to open Beam actions and keep the flow moving.";
7
+ }, {
8
+ readonly lead: "Point Beam at a file or path, and it can pick up the context.";
9
+ readonly tip: "Use action log if you want to follow each step Beam takes.";
10
+ }, {
11
+ readonly lead: "Keep it simple: one prompt, one file, or one quick command.";
12
+ readonly tip: "Beam is built to handle edits, searches, and project awareness.";
13
+ }];
14
+ export type EmptyStateMessage = (typeof EMPTY_STATE_MESSAGES)[number];
15
+ //# sourceMappingURL=app-copy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-copy.d.ts","sourceRoot":"","sources":["../src/app-copy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;EAiBvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ export const EMPTY_STATE_MESSAGES = [
2
+ {
3
+ lead: "Ask a question, open a command, or drop in a file to begin.",
4
+ tip: "Beam can also help with searches, edits, and project awareness.",
5
+ },
6
+ {
7
+ lead: "Start local with Ollama, or switch to OpenAI when you need it.",
8
+ tip: "Type / to open Beam actions and keep the flow moving.",
9
+ },
10
+ {
11
+ lead: "Point Beam at a file or path, and it can pick up the context.",
12
+ tip: "Use action log if you want to follow each step Beam takes.",
13
+ },
14
+ {
15
+ lead: "Keep it simple: one prompt, one file, or one quick command.",
16
+ tip: "Beam is built to handle edits, searches, and project awareness.",
17
+ },
18
+ ];
@@ -0,0 +1,4 @@
1
+ export * from "./models.js";
2
+ export * from "./app-copy.js";
3
+ export * from "./system-prompt.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./models.js";
2
+ export * from "./app-copy.js";
3
+ export * from "./system-prompt.js";
@@ -0,0 +1,15 @@
1
+ export interface ModelConfig {
2
+ id: string;
3
+ provider: "ollama" | "openai" | "nvidia";
4
+ tag: string;
5
+ description: string;
6
+ installCommand?: string;
7
+ needsApiKey?: boolean;
8
+ url?: string;
9
+ free?: boolean;
10
+ }
11
+ export declare const MODEL_CONFIGS: ModelConfig[];
12
+ export declare const MODELS: string[];
13
+ export type Model = typeof MODELS[number];
14
+ export declare function getModelConfig(modelId: string): ModelConfig | undefined;
15
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,aAAa,EAAE,WAAW,EAiDtC,CAAC;AAEF,eAAO,MAAM,MAAM,UAAyC,CAAC;AAC7D,MAAM,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AAE1C,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAEvE"}
package/dist/models.js ADDED
@@ -0,0 +1,53 @@
1
+ export const MODEL_CONFIGS = [
2
+ {
3
+ id: "qwen2.5:7b",
4
+ provider: "ollama",
5
+ tag: "Qwen 2.5",
6
+ description: "Fast and efficient 7B parameter model",
7
+ installCommand: "ollama pull qwen2.5:7b",
8
+ needsApiKey: false,
9
+ free: true,
10
+ url: "https://ollama.com/library/qwen2.5:7b",
11
+ },
12
+ {
13
+ id: "qwen3.5:9b",
14
+ provider: "ollama",
15
+ tag: "Qwen 3.5",
16
+ description: "Specialized for code generation and understanding",
17
+ installCommand: "ollama pull qwen3.5:9b",
18
+ needsApiKey: false,
19
+ free: true,
20
+ url: "https://ollama.com/library/qwen3.5:9b",
21
+ },
22
+ {
23
+ id: "gpt-4.1-mini",
24
+ provider: "openai",
25
+ tag: "ChatGPT 4.1 Mini",
26
+ description: "Fast OpenAI model for everyday coding help",
27
+ needsApiKey: true,
28
+ free: false,
29
+ url: "https://platform.openai.com/docs/models/gpt-4-1-mini",
30
+ },
31
+ {
32
+ id: "gpt-4.1",
33
+ provider: "openai",
34
+ tag: "ChatGPT 4.1",
35
+ description: "Higher-quality OpenAI model for complex tasks",
36
+ needsApiKey: true,
37
+ free: false,
38
+ url: "https://platform.openai.com/docs/models/gpt-4-1",
39
+ },
40
+ {
41
+ id: "google/gemma-4-31b-it",
42
+ provider: "nvidia",
43
+ tag: "NVIDIA Hosted",
44
+ description: "NVIDIA-hosted model with strong reasoning and long outputs",
45
+ needsApiKey: true,
46
+ free: true,
47
+ url: "https://build.nvidia.com/models",
48
+ },
49
+ ];
50
+ export const MODELS = MODEL_CONFIGS.map((model) => model.id);
51
+ export function getModelConfig(modelId) {
52
+ return MODEL_CONFIGS.find((model) => model.id === modelId);
53
+ }
@@ -0,0 +1,8 @@
1
+ export declare const QUICK_ACTIONS: QuickAction[];
2
+ export interface QuickAction {
3
+ title: string;
4
+ description: string;
5
+ shortcut: string;
6
+ userPrompt: string;
7
+ }
8
+ //# sourceMappingURL=quick-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quick-actions.d.ts","sourceRoot":"","sources":["../src/quick-actions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,EAAE,WAAW,EA8BtC,CAAC;AAEF,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACtB"}
@@ -0,0 +1,31 @@
1
+ export const QUICK_ACTIONS = [
2
+ {
3
+ title: "/commit",
4
+ description: "Generate a commit message based on the diff",
5
+ shortcut: "Ctrl+G",
6
+ userPrompt: "Generate a concise, descriptive git commit message based on the diff or context provided.",
7
+ },
8
+ {
9
+ title: "/test",
10
+ description: "Generate test cases for the selected code",
11
+ shortcut: "Ctrl+T",
12
+ userPrompt: "Generate comprehensive test cases for the selected code or file.",
13
+ },
14
+ // {
15
+ // title: "/doc",
16
+ // description: "Generate documentation for the code",
17
+ // shortcut: "Ctrl+D",
18
+ // },
19
+ {
20
+ title: "/fix",
21
+ description: "Fix issues in the selected code",
22
+ shortcut: "Ctrl+F",
23
+ userPrompt: "Identify and fix any issues in the selected code or file.",
24
+ },
25
+ {
26
+ title: "/explain",
27
+ description: "Explain what the selected code snippet or file does",
28
+ shortcut: "Ctrl+E",
29
+ userPrompt: "You're given a file or a selected line snippet as context. Explain the given code clearly and concisely. Optionaly you can read other files if those are relevant. Describe what it does, how it works, and any important patterns or concepts.",
30
+ },
31
+ ];
@@ -0,0 +1,7 @@
1
+ export declare function getSystemPrompt(hasProjectFiles?: boolean): string;
2
+ /**
3
+ * Get system prompt tailored to a specific quick action.
4
+ * Each action has different capabilities and constraints.
5
+ */
6
+ export declare function getSystemPromptForAction(action: string | undefined, hasProjectFiles?: boolean): string;
7
+ //# sourceMappingURL=system-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../src/system-prompt.ts"],"names":[],"mappings":"AA2HA,wBAAgB,eAAe,CAAC,eAAe,GAAE,OAAe,GAAG,MAAM,CAKxE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,eAAe,GAAE,OAAe,GAC/B,MAAM,CAoBR"}
@@ -0,0 +1,134 @@
1
+ const BASE_PROMPT = `
2
+ You are an AI assistant called beam with START, PLAN, ACTION, OBSERVATION and OUTPUT state.
3
+ Wait for the user prompt and first PLAN using available tools.
4
+ After planning, take the ACTION with appropriate tools and wait for OBSERVATION.
5
+ Once you get the OBSERVATION, return the AI response based on the START prompt and observations.
6
+
7
+ Strictly follow the JSON output format as given in the examples.
8
+
9
+ For simple conversational messages, greetings, small talk, or non-technical messages like generating a commit message, skip to output directly:
10
+ {"type": "output", "output": "Hey! What can I help you with?"}
11
+
12
+ Available tools:`;
13
+ const PROJECT_CONTEXT_TOOL = `
14
+ - Project structure is provided as context above.
15
+ Use the provided project-files.json to understand the project layout instead of calling getProjectAwareness.`;
16
+ const PROJECT_AWARENESS_TOOL = `
17
+ - function getProjectAwareness(rootDir: string): string[]
18
+ Scans the workspace, creates or refreshes .beam/project-files.json, and returns the discovered project file paths.
19
+ Use this first when you need project context.`;
20
+ const READ_ONLY_TOOLS = `
21
+
22
+ - function readPath(path: string): object
23
+ Reads a file or lists a directory inside the workspace.
24
+ Use this first when you need the contents of a file or a quick directory view.
25
+
26
+ - function glob(pattern: string): object
27
+ Finds files in the workspace that match a glob pattern like "**/*.ts".
28
+ Use this for fast file pattern matching.
29
+
30
+ - function grep(pattern: string, flags?: string): object
31
+ Searches file contents with a regular expression and returns matching lines.
32
+ Use this when you need powerful content search with regex support.
33
+
34
+ - function webSearch(query: string, limit?: number): object
35
+ Searches the web for current information and returns a small set of result links and snippets.
36
+ Use this when the answer may have changed recently or needs fresh external context.
37
+
38
+ - function webFetch(url: string): object
39
+ Fetches a URL and extracts readable text for analysis.
40
+ Use this after webSearch, or when the user gives you a URL to inspect.`;
41
+ const WRITE_TOOLS = `
42
+ - function writePath(path: string, content: string): object
43
+ Writes or creates a file. Parent directories are created automatically.
44
+
45
+ - function editPath(path: string, searchValue: string, replaceValue: string): object
46
+ Replaces literal text in a file and writes the result back.
47
+
48
+ - function deletePath(path: string): object
49
+ Deletes a file or directory inside the workspace.
50
+ Beam will ask the user for confirmation before deletion.
51
+
52
+ - function runCommand(command: string): object
53
+ Runs a shell command inside the open workspace folder.
54
+ Use this for build, test, lint, install, git status, and other CLI-based tasks.
55
+
56
+ Rules:
57
+ - Do not use interactive commands.
58
+ - Do not use destructive commands like rm -rf, sudo, git reset --hard, shutdown, or reboot.`;
59
+ const STRICT_RULES_READ_ONLY = `
60
+ STRICT RULES:
61
+ - Only ONE plan per response cycle. After planning, ALWAYS follow with an action.
62
+ - Never plan twice in a row. Never repeat the same action twice.
63
+ - Once you have enough information from observations, go straight to output.
64
+ - For code/technical output: use markdown with triple backticks and a language tag.
65
+ - For conversational output: plain text only, no markdown.
66
+ - Escape newlines as \\n inside JSON string values.
67
+ - DO NOT modify or write any files. You can only read files, search, or fetch web content.`;
68
+ const STRICT_RULES_WRITE = `
69
+ STRICT RULES:
70
+ - Only ONE plan per response cycle. After planning, ALWAYS follow with an action.
71
+ - Never plan twice in a row. Never repeat the same action twice.
72
+ - Once you have enough information from observations, go straight to output.
73
+ - For code/technical output: use markdown with triple backticks and a language tag.
74
+ - For conversational output: plain text only, no markdown.
75
+ - Escape newlines as \\n inside JSON string values.`;
76
+ const OUTPUT_FORMAT = `
77
+ Output Format Examples:
78
+
79
+ // Conversational:
80
+ {"type": "output", "output": "Hey! What can I help you with?"}
81
+
82
+ // Single tool task:
83
+ {"type": "plan", "plan": "I will inspect the file structure"}
84
+ {"type": "action", "action": "getProjectAwareness", "parameters": {"rootDir": "./"}}
85
+ // (observation is injected by the system, not by you — wait for it, then continue)
86
+ {"type": "action", "action": "readPath", "parameters": {"path": "src/index.ts"}}
87
+ {"type": "output", "output": "Your app is running on port 3000."}
88
+
89
+ // Multi-step task:
90
+ {"type": "plan", "plan": "I will inspect the code then write a summary"}
91
+ {"type": "action", "action": "grep", "parameters": {"pattern": "writePath"}}
92
+ // (wait for observation)
93
+ {"type": "action", "action": "writePath", "parameters": {"path": "doc.md", "content": "# Project\\n..."}}
94
+ {"type": "output", "output": "I've written doc.md with a summary of your project."}
95
+
96
+ IMPORTANT: You NEVER emit {"type": "observation", ...}. Observations are injected by the system after each action. Just wait and then respond with the next action or output.
97
+ `;
98
+ function buildPrompt(toolsSection, includeWriteTools, includeProjectAwarenessTool) {
99
+ return (BASE_PROMPT +
100
+ toolsSection +
101
+ (includeProjectAwarenessTool ? PROJECT_AWARENESS_TOOL : "") +
102
+ READ_ONLY_TOOLS +
103
+ (includeWriteTools ? `\n\n${WRITE_TOOLS}` : "") +
104
+ `\n\n` +
105
+ (includeWriteTools ? STRICT_RULES_WRITE : STRICT_RULES_READ_ONLY) +
106
+ `\n\n` +
107
+ OUTPUT_FORMAT);
108
+ }
109
+ export function getSystemPrompt(hasProjectFiles = false) {
110
+ const toolsSection = hasProjectFiles ? PROJECT_CONTEXT_TOOL : `
111
+ - If the project-files cache is not already provided, use getProjectAwareness to build it.`;
112
+ return buildPrompt(toolsSection, true, !hasProjectFiles);
113
+ }
114
+ /**
115
+ * Get system prompt tailored to a specific quick action.
116
+ * Each action has different capabilities and constraints.
117
+ */
118
+ export function getSystemPromptForAction(action, hasProjectFiles = false) {
119
+ if (!action) {
120
+ return getSystemPrompt(hasProjectFiles);
121
+ }
122
+ const toolsSection = hasProjectFiles ? PROJECT_CONTEXT_TOOL : `
123
+ - If the project-files cache is not already provided, use getProjectAwareness to build it.`;
124
+ switch (action) {
125
+ case "/explain":
126
+ case "/commit":
127
+ return buildPrompt(toolsSection, false, !hasProjectFiles);
128
+ case "/test":
129
+ case "/fix":
130
+ return buildPrompt(toolsSection, true, !hasProjectFiles);
131
+ default:
132
+ return getSystemPrompt(hasProjectFiles);
133
+ }
134
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "beam-shared",
3
+ "version": "0.1.0",
4
+ "description": "Shared utilities and types for Beam",
5
+ "keywords": ["beam", "shared", "utilities"],
6
+ "author": "Suman Biswas <textsumanb@gmail.com>",
7
+ "license": "SEE LICENSE IN LICENSE",
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "homepage": "https://github.com/sumanbiswas7/beam#readme",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/sumanbiswas7/beam.git",
15
+ "directory": "packages/shared"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "LICENSE"
20
+ ],
21
+ "exports": {
22
+ ".": "./dist/index.js",
23
+ "./models": "./dist/models.js",
24
+ "./app-copy": "./dist/app-copy.js"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p ./tsconfig.json",
28
+ "dev": "tsc -w -p ./tsconfig.json"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^5.9.3"
32
+ }
33
+ }