aipeek 0.2.4 → 0.2.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.
@@ -830,61 +830,29 @@ JS in the page and returns the result \u2014 for anything the typed endpoints ca
830
830
  aipeek auto-detects errors after HMR and prints them to the terminal \u2014 watch for \`[aipeek]\` messages.
831
831
  `;
832
832
  }
833
- function norm(line) {
834
- const t = line.trim();
835
- const i = t.indexOf("localhost:");
836
- if (i === -1)
837
- return t;
838
- let j = i + "localhost:".length;
839
- while (j < t.length && t[j] >= "0" && t[j] <= "9") j++;
840
- return `${t.slice(0, i)}localhost:PORT${t.slice(j)}`;
841
- }
842
- function stripBlocks(content, snippet) {
843
- const known = new Set(snippet.split("\n").map(norm).filter((l) => l.length > 3));
844
- const lines = content.split("\n");
845
- const keep = [];
846
- let inside = false;
847
- let buf = [];
848
- let hits = 0;
849
- const flush = () => {
850
- if (buf.length && hits / buf.length <= 0.5)
851
- keep.push(...buf);
852
- buf = [];
853
- hits = 0;
854
- inside = false;
855
- };
856
- for (const line of lines) {
857
- const isKnown = known.has(norm(line));
858
- if (!inside) {
859
- if (isKnown) {
860
- inside = true;
861
- buf = [line];
862
- hits = 1;
863
- } else {
864
- keep.push(line);
865
- }
866
- continue;
867
- }
868
- buf.push(line);
869
- if (isKnown)
870
- hits++;
871
- else if (buf.slice(-3).every((l) => !known.has(norm(l))))
872
- flush();
873
- }
874
- flush();
875
- return keep.join("\n");
876
- }
833
+ var START_TAG = "<!-- AIPEEK:START -->";
834
+ var END_TAG = "<!-- AIPEEK:END -->";
877
835
  function injectClaudeMd(root, port) {
878
836
  const path = _path.resolve.call(void 0, root, "CLAUDE.md");
879
- const snippet = aipeekSnippet(port);
837
+ const block = `${START_TAG}
838
+ ${aipeekSnippet(port).trim()}
839
+ ${END_TAG}
840
+ `;
880
841
  try {
881
842
  if (!_fs.existsSync.call(void 0, path)) {
882
- _fs.writeFileSync.call(void 0, path, snippet.trimStart());
843
+ _fs.writeFileSync.call(void 0, path, block);
844
+ return;
845
+ }
846
+ const content = _fs.readFileSync.call(void 0, path, "utf-8");
847
+ const si = content.indexOf(START_TAG);
848
+ const ei = content.indexOf(END_TAG);
849
+ if (si !== -1 && ei !== -1) {
850
+ _fs.writeFileSync.call(void 0, path, content.slice(0, si) + block.trimEnd() + content.slice(ei + END_TAG.length));
883
851
  return;
884
852
  }
885
- const stripped = stripBlocks(_fs.readFileSync.call(void 0, path, "utf-8"), snippet).trimEnd();
886
- _fs.writeFileSync.call(void 0, path, `${stripped}
887
- ${snippet}`);
853
+ const sep = content.endsWith("\n") ? "" : "\n";
854
+ _fs.writeFileSync.call(void 0, path, `${content}${sep}
855
+ ${block}`);
888
856
  } catch (e6) {
889
857
  }
890
858
  }
@@ -1201,4 +1169,7 @@ ${result.ui}` : head);
1201
1169
 
1202
1170
 
1203
1171
 
1204
- exports.check = check; exports.diffState = diffState; exports.emitSummary = emitSummary; exports.emitCheck = emitCheck; exports.emitDiff = emitDiff; exports.aipeekPlugin = aipeekPlugin;
1172
+
1173
+
1174
+
1175
+ exports.check = check; exports.diffState = diffState; exports.emitSummary = emitSummary; exports.emitCheck = emitCheck; exports.emitDiff = emitDiff; exports.START_TAG = START_TAG; exports.END_TAG = END_TAG; exports.injectClaudeMd = injectClaudeMd; exports.aipeekPlugin = aipeekPlugin;
@@ -826,61 +826,29 @@ JS in the page and returns the result \u2014 for anything the typed endpoints ca
826
826
  aipeek auto-detects errors after HMR and prints them to the terminal \u2014 watch for \`[aipeek]\` messages.
827
827
  `;
828
828
  }
829
- function norm(line) {
830
- const t = line.trim();
831
- const i = t.indexOf("localhost:");
832
- if (i === -1)
833
- return t;
834
- let j = i + "localhost:".length;
835
- while (j < t.length && t[j] >= "0" && t[j] <= "9") j++;
836
- return `${t.slice(0, i)}localhost:PORT${t.slice(j)}`;
837
- }
838
- function stripBlocks(content, snippet) {
839
- const known = new Set(snippet.split("\n").map(norm).filter((l) => l.length > 3));
840
- const lines = content.split("\n");
841
- const keep = [];
842
- let inside = false;
843
- let buf = [];
844
- let hits = 0;
845
- const flush = () => {
846
- if (buf.length && hits / buf.length <= 0.5)
847
- keep.push(...buf);
848
- buf = [];
849
- hits = 0;
850
- inside = false;
851
- };
852
- for (const line of lines) {
853
- const isKnown = known.has(norm(line));
854
- if (!inside) {
855
- if (isKnown) {
856
- inside = true;
857
- buf = [line];
858
- hits = 1;
859
- } else {
860
- keep.push(line);
861
- }
862
- continue;
863
- }
864
- buf.push(line);
865
- if (isKnown)
866
- hits++;
867
- else if (buf.slice(-3).every((l) => !known.has(norm(l))))
868
- flush();
869
- }
870
- flush();
871
- return keep.join("\n");
872
- }
829
+ var START_TAG = "<!-- AIPEEK:START -->";
830
+ var END_TAG = "<!-- AIPEEK:END -->";
873
831
  function injectClaudeMd(root, port) {
874
832
  const path = resolve(root, "CLAUDE.md");
875
- const snippet = aipeekSnippet(port);
833
+ const block = `${START_TAG}
834
+ ${aipeekSnippet(port).trim()}
835
+ ${END_TAG}
836
+ `;
876
837
  try {
877
838
  if (!existsSync(path)) {
878
- writeFileSync(path, snippet.trimStart());
839
+ writeFileSync(path, block);
840
+ return;
841
+ }
842
+ const content = readFileSync(path, "utf-8");
843
+ const si = content.indexOf(START_TAG);
844
+ const ei = content.indexOf(END_TAG);
845
+ if (si !== -1 && ei !== -1) {
846
+ writeFileSync(path, content.slice(0, si) + block.trimEnd() + content.slice(ei + END_TAG.length));
879
847
  return;
880
848
  }
881
- const stripped = stripBlocks(readFileSync(path, "utf-8"), snippet).trimEnd();
882
- writeFileSync(path, `${stripped}
883
- ${snippet}`);
849
+ const sep = content.endsWith("\n") ? "" : "\n";
850
+ writeFileSync(path, `${content}${sep}
851
+ ${block}`);
884
852
  } catch {
885
853
  }
886
854
  }
@@ -1196,5 +1164,8 @@ export {
1196
1164
  emitSummary,
1197
1165
  emitCheck,
1198
1166
  emitDiff,
1167
+ START_TAG,
1168
+ END_TAG,
1169
+ injectClaudeMd,
1199
1170
  aipeekPlugin
1200
1171
  };
package/dist/index.cjs CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunk3NVB3GGEcjs = require('./chunk-3NVB3GGE.cjs');
8
+ var _chunk6EZKMGRDcjs = require('./chunk-6EZKMGRD.cjs');
9
9
  require('./chunk-Z2Y65YOY.cjs');
10
10
 
11
11
 
@@ -14,4 +14,4 @@ require('./chunk-Z2Y65YOY.cjs');
14
14
 
15
15
 
16
16
 
17
- exports.aipeekPlugin = _chunk3NVB3GGEcjs.aipeekPlugin; exports.check = _chunk3NVB3GGEcjs.check; exports.diffState = _chunk3NVB3GGEcjs.diffState; exports.emitCheck = _chunk3NVB3GGEcjs.emitCheck; exports.emitDiff = _chunk3NVB3GGEcjs.emitDiff; exports.emitSummary = _chunk3NVB3GGEcjs.emitSummary;
17
+ exports.aipeekPlugin = _chunk6EZKMGRDcjs.aipeekPlugin; exports.check = _chunk6EZKMGRDcjs.check; exports.diffState = _chunk6EZKMGRDcjs.diffState; exports.emitCheck = _chunk6EZKMGRDcjs.emitCheck; exports.emitDiff = _chunk6EZKMGRDcjs.emitDiff; exports.emitSummary = _chunk6EZKMGRDcjs.emitSummary;
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  emitCheck,
6
6
  emitDiff,
7
7
  emitSummary
8
- } from "./chunk-72ZKZ42D.js";
8
+ } from "./chunk-X3HAXWFJ.js";
9
9
  export {
10
10
  aipeekPlugin,
11
11
  check,
package/dist/plugin.cjs CHANGED
@@ -1,7 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk3NVB3GGEcjs = require('./chunk-3NVB3GGE.cjs');
3
+
4
+
5
+
6
+ var _chunk6EZKMGRDcjs = require('./chunk-6EZKMGRD.cjs');
4
7
  require('./chunk-Z2Y65YOY.cjs');
5
8
 
6
9
 
7
- exports.aipeekPlugin = _chunk3NVB3GGEcjs.aipeekPlugin;
10
+
11
+
12
+
13
+ exports.END_TAG = _chunk6EZKMGRDcjs.END_TAG; exports.START_TAG = _chunk6EZKMGRDcjs.START_TAG; exports.aipeekPlugin = _chunk6EZKMGRDcjs.aipeekPlugin; exports.injectClaudeMd = _chunk6EZKMGRDcjs.injectClaudeMd;
package/dist/plugin.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import {
2
- aipeekPlugin
3
- } from "./chunk-72ZKZ42D.js";
2
+ END_TAG,
3
+ START_TAG,
4
+ aipeekPlugin,
5
+ injectClaudeMd
6
+ } from "./chunk-X3HAXWFJ.js";
4
7
  export {
5
- aipeekPlugin
8
+ END_TAG,
9
+ START_TAG,
10
+ aipeekPlugin,
11
+ injectClaudeMd
6
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aipeek",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Gives AI a peek into your running browser app — UI tree, console, network, errors, state",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -107,73 +107,30 @@ aipeek auto-detects errors after HMR and prints them to the terminal — watch f
107
107
  `
108
108
  }
109
109
 
110
- // normalize a line so cosmetic diffs (indent, port number) don't break matching
111
- function norm(line: string): string {
112
- const t = line.trim()
113
- const i = t.indexOf('localhost:')
114
- if (i === -1)
115
- return t
116
- let j = i + 'localhost:'.length
117
- while (j < t.length && t[j] >= '0' && t[j] <= '9') j++
118
- return `${t.slice(0, i)}localhost:PORT${t.slice(j)}`
119
- }
120
-
121
- // strip every existing aipeek block by simulating a human reading line-by-line:
122
- // scan downward; once enough recent lines belong to the snippet we're INSIDE a
123
- // block; once they stop belonging we're OUTSIDE again. A run whose lines are
124
- // >50% snippet-content is dropped. Content-fuzzy — survives wording/port edits.
125
- function stripBlocks(content: string, snippet: string): string {
126
- const known = new Set(snippet.split('\n').map(norm).filter(l => l.length > 3))
127
- const lines = content.split('\n')
128
- const keep: string[] = []
129
- let inside = false
130
- let buf: string[] = []
131
- let hits = 0
132
-
133
- const flush = () => {
134
- // settle the buffered run: drop it if it reads as snippet, else keep it
135
- if (buf.length && hits / buf.length <= 0.5)
136
- keep.push(...buf)
137
- buf = []
138
- hits = 0
139
- inside = false
140
- }
141
-
142
- for (const line of lines) {
143
- const isKnown = known.has(norm(line))
144
- if (!inside) {
145
- if (isKnown) {
146
- inside = true
147
- buf = [line]
148
- hits = 1
149
- }
150
- else {
151
- keep.push(line)
152
- }
153
- continue
154
- }
155
- // INSIDE: keep accumulating until we drift away from the snippet
156
- buf.push(line)
157
- if (isKnown)
158
- hits++
159
- // a run of unknown lines means the block ended — settle it
160
- else if (buf.slice(-3).every(l => !known.has(norm(l))))
161
- flush()
162
- }
163
- flush()
164
- return keep.join('\n')
165
- }
166
-
167
- function injectClaudeMd(root: string, port: number) {
110
+ export const START_TAG = '<!-- AIPEEK:START -->'
111
+ export const END_TAG = '<!-- AIPEEK:END -->'
112
+
113
+ // Marker-based injection — the block lives between START_TAG and END_TAG, so
114
+ // re-injection is a deterministic splice (find markers, replace between) rather
115
+ // than fuzzy line matching. New file → write markers + snippet. Existing markers
116
+ // replace their contents. No markers yet → append a fresh marked block.
117
+ export function injectClaudeMd(root: string, port: number) {
168
118
  const path = resolve(root, 'CLAUDE.md')
169
- const snippet = aipeekSnippet(port)
119
+ const block = `${START_TAG}\n${aipeekSnippet(port).trim()}\n${END_TAG}\n`
170
120
  try {
171
121
  if (!existsSync(path)) {
172
- writeFileSync(path, snippet.trimStart())
122
+ writeFileSync(path, block)
123
+ return
124
+ }
125
+ const content = readFileSync(path, 'utf-8')
126
+ const si = content.indexOf(START_TAG)
127
+ const ei = content.indexOf(END_TAG)
128
+ if (si !== -1 && ei !== -1) {
129
+ writeFileSync(path, content.slice(0, si) + block.trimEnd() + content.slice(ei + END_TAG.length))
173
130
  return
174
131
  }
175
- const stripped = stripBlocks(readFileSync(path, 'utf-8'), snippet).trimEnd()
176
- writeFileSync(path, `${stripped}\n${snippet}`)
132
+ const sep = content.endsWith('\n') ? '' : '\n'
133
+ writeFileSync(path, `${content}${sep}\n${block}`)
177
134
  }
178
135
  catch {}
179
136
  }