@lasso-ai/cli 1.1.4 → 1.1.5

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 (2) hide show
  1. package/dist/cli/agent.js +33 -5
  2. package/package.json +1 -1
package/dist/cli/agent.js CHANGED
@@ -80,6 +80,11 @@ async function contextFor(cwd, element) {
80
80
  const needle = element.label.replace(/^[^.#]+[.#]?/, "");
81
81
  const hintedPath = element.sourceHint?.split(":")[0];
82
82
  const sourceFile = hintedPath ? node_path_1.default.basename(hintedPath) : "";
83
+ // Extract unique class names and attributes from the element for better matching
84
+ const classMatches = element.html?.match(/class="([^"]+)"/);
85
+ const classNames = classMatches ? classMatches[1].split(/\s+/).filter((c) => c.length > 3) : [];
86
+ const hrefMatch = element.html?.match(/href="([^"]+)"/);
87
+ const href = hrefMatch ? hrefMatch[1] : "";
83
88
  if (hintedPath) {
84
89
  const candidates = [
85
90
  node_path_1.default.isAbsolute(hintedPath) ? hintedPath : node_path_1.default.resolve(cwd, hintedPath),
@@ -101,11 +106,31 @@ async function contextFor(cwd, element) {
101
106
  }
102
107
  const files = await sourceFiles(cwd);
103
108
  const snippets = [];
109
+ const scoredFiles = [];
104
110
  const results = await Promise.all(files.map(async (file) => {
105
111
  try {
106
112
  const content = await promises_1.default.readFile(file, "utf8");
107
- if (!needle || (sourceFile && file.endsWith(sourceFile)) || content.includes(needle) || content.includes(element.label)) {
108
- return `FILE: ${node_path_1.default.relative(cwd, file)}\n${content.slice(0, 6000)}`;
113
+ let score = 0;
114
+ // Score files based on relevance
115
+ if (sourceFile && file.endsWith(sourceFile))
116
+ score += 10;
117
+ if (content.includes(needle))
118
+ score += 5;
119
+ if (content.includes(element.label))
120
+ score += 5;
121
+ if (href && content.includes(href))
122
+ score += 8;
123
+ // Check for class name matches
124
+ for (const className of classNames) {
125
+ if (content.includes(className))
126
+ score += 3;
127
+ }
128
+ // Boost score for component files
129
+ if (file.includes("component") || file.includes("nav") || file.includes("header") || file.includes("layout")) {
130
+ score += 2;
131
+ }
132
+ if (score > 0) {
133
+ return { file, score, content };
109
134
  }
110
135
  }
111
136
  catch {
@@ -113,9 +138,12 @@ async function contextFor(cwd, element) {
113
138
  }
114
139
  return null;
115
140
  }));
116
- for (const result of results) {
117
- if (result && snippets.length < 4)
118
- snippets.push(result);
141
+ // Sort by score and take top files
142
+ const sortedResults = results.filter((r) => r !== null).sort((a, b) => b.score - a.score);
143
+ for (const result of sortedResults) {
144
+ if (snippets.length < 8) {
145
+ snippets.push(`FILE: ${node_path_1.default.relative(cwd, result.file)}\n${result.content.slice(0, 6000)}`);
146
+ }
119
147
  }
120
148
  return snippets.join("\n\n---\n\n");
121
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lasso-ai/cli",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Select any part of your running app, describe a change, and let AI edit the real source code.",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cli/index.js",