@vite-plugin-opencode-assistant/opencode 1.0.17 → 1.0.19

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.
@@ -6,7 +6,7 @@ var E = Object.defineProperty, w = Object.defineProperties, b = Object.getOwnPro
6
6
  for (var e of y(t))
7
7
  C.call(t, e) && _(r, e, t[e]);
8
8
  return r;
9
- }, u = (r, t) => w(r, b(t)), O = (r, t, e) => _(r, typeof t != "symbol" ? t + "" : t, e);
9
+ }, p = (r, t) => w(r, b(t)), O = (r, t, e) => _(r, typeof t != "symbol" ? t + "" : t, e);
10
10
  const s = {
11
11
  reset: "\x1B[0m",
12
12
  dim: "\x1B[2m",
@@ -37,7 +37,7 @@ function x() {
37
37
  const r = /* @__PURE__ */ new Date(), t = String(r.getHours()).padStart(2, "0"), e = String(r.getMinutes()).padStart(2, "0"), n = String(r.getSeconds()).padStart(2, "0"), o = String(r.getMilliseconds()).padStart(3, "0");
38
38
  return `${t}:${e}:${n}.${o}`;
39
39
  }
40
- function I(r = 3) {
40
+ function R(r = 3) {
41
41
  const t = new Error().stack;
42
42
  if (!t) return "";
43
43
  const n = t.split(`
@@ -48,7 +48,7 @@ function I(r = 3) {
48
48
  const [, a, m, l] = o;
49
49
  return `${m.split("/").pop() || m}:${l} ${a || "<anonymous>"}`;
50
50
  }
51
- function f(r, t = 0) {
51
+ function u(r, t = 0) {
52
52
  if (t > 3) return "...";
53
53
  if (r === null) return "null";
54
54
  if (r === void 0) return "undefined";
@@ -58,14 +58,14 @@ function f(r, t = 0) {
58
58
  return `${r.name}: ${r.message}${r.stack ? `
59
59
  ${r.stack}` : ""}`;
60
60
  if (Array.isArray(r))
61
- return r.length === 0 ? "[]" : r.length > 5 ? `[${r.slice(0, 3).map((o) => f(o, t + 1)).join(", ")}, ... ${r.length - 3} more items]` : `[${r.map((n) => f(n, t + 1)).join(", ")}]`;
61
+ return r.length === 0 ? "[]" : r.length > 5 ? `[${r.slice(0, 3).map((o) => u(o, t + 1)).join(", ")}, ... ${r.length - 3} more items]` : `[${r.map((n) => u(n, t + 1)).join(", ")}]`;
62
62
  if (typeof r == "object") {
63
63
  const e = Object.entries(r);
64
- return e.length === 0 ? "{}" : e.length > 5 ? `{${e.slice(0, 3).map(([a, m]) => `${a}: ${f(m, t + 1)}`).join(", ")}, ... ${e.length - 3} more keys}` : `{${e.map(([o, a]) => `${o}: ${f(a, t + 1)}`).join(", ")}}`;
64
+ return e.length === 0 ? "{}" : e.length > 5 ? `{${e.slice(0, 3).map(([a, m]) => `${a}: ${u(m, t + 1)}`).join(", ")}, ... ${e.length - 3} more keys}` : `{${e.map(([o, a]) => `${o}: ${u(a, t + 1)}`).join(", ")}}`;
65
65
  }
66
66
  return String(r);
67
67
  }
68
- function R(r) {
68
+ function I(r) {
69
69
  if (!r || Object.keys(r).length === 0) return "";
70
70
  const t = [];
71
71
  r.module && t.push(`[${r.module}]`), r.operation && t.push(`(${r.operation})`), r.traceId && t.push(`trace:${r.traceId}`), r.duration !== void 0 && t.push(`${r.duration}ms`);
@@ -74,7 +74,7 @@ function R(r) {
74
74
  );
75
75
  if (e.length > 0) {
76
76
  const n = {};
77
- e.forEach((o) => n[o] = r[o]), t.push(f(n));
77
+ e.forEach((o) => n[o] = r[o]), t.push(u(n));
78
78
  }
79
79
  return t.join(" ");
80
80
  }
@@ -84,20 +84,20 @@ function $(r, t, e, ...n) {
84
84
  o.push(`${s.dim}[${process.pid}]${s.reset}`), o.push(`${s.dim}${x()}${s.reset}`);
85
85
  const a = j[r], m = L[r].padEnd(5);
86
86
  o.push(`${a}${m}${s.reset}`), o.push(`${s.bright}${P}${s.reset}`);
87
- const l = R(e);
87
+ const l = I(e);
88
88
  if (l && o.push(`${s.magenta}${l}${s.reset}`), o.push(t), r >= 2) {
89
- const i = I(4);
89
+ const i = R(4);
90
90
  i && o.push(`${s.dim}(${i})${s.reset}`);
91
91
  }
92
- const h = n.map((i) => f(i)).join(" ");
92
+ const h = n.map((i) => u(i)).join(" ");
93
93
  if (h && o.push(h), e != null && e.error) {
94
94
  const i = e.error;
95
- i instanceof Error ? o.push(`${s.red}Error: ${i.message}${s.reset}`) : o.push(`${s.red}Error: ${f(i)}${s.reset}`);
95
+ i instanceof Error ? o.push(`${s.red}Error: ${i.message}${s.reset}`) : o.push(`${s.red}Error: ${u(i)}${s.reset}`);
96
96
  }
97
97
  const d = o.join(" ");
98
98
  r >= 3 ? console.error(d) : r === 2 ? console.warn(d) : console.log(d);
99
99
  }
100
- const p = {
100
+ const f = {
101
101
  debug(r, t, ...e) {
102
102
  $(0, r, t, ...e);
103
103
  },
@@ -115,39 +115,39 @@ const p = {
115
115
  groupEnd() {
116
116
  }
117
117
  };
118
- class A {
118
+ class T {
119
119
  constructor(t, e) {
120
- O(this, "startTime"), O(this, "context"), O(this, "operation"), this.operation = t, this.context = e || {}, this.startTime = performance.now(), p.debug(`⏱️ Starting: ${t}`, this.context);
120
+ O(this, "startTime"), O(this, "context"), O(this, "operation"), this.operation = t, this.context = e || {}, this.startTime = performance.now(), f.debug(`⏱️ Starting: ${t}`, this.context);
121
121
  }
122
122
  end(t) {
123
123
  const e = Math.round(performance.now() - this.startTime), n = t || `✓ Completed: ${this.operation}`;
124
- return p.debug(n, u(c({}, this.context), { duration: e })), e;
124
+ return f.debug(n, p(c({}, this.context), { duration: e })), e;
125
125
  }
126
126
  checkpoint(t) {
127
127
  const e = Math.round(performance.now() - this.startTime);
128
- return p.debug(` ↳ ${t}`, u(c({}, this.context), { duration: e })), e;
128
+ return f.debug(` ↳ ${t}`, p(c({}, this.context), { duration: e })), e;
129
129
  }
130
130
  }
131
131
  function B(r) {
132
132
  return {
133
133
  debug(t, e, ...n) {
134
- p.debug(t, u(c({}, e), { module: r }), ...n);
134
+ f.debug(t, p(c({}, e), { module: r }), ...n);
135
135
  },
136
136
  info(t, e, ...n) {
137
- p.info(t, u(c({}, e), { module: r }), ...n);
137
+ f.info(t, p(c({}, e), { module: r }), ...n);
138
138
  },
139
139
  warn(t, e, ...n) {
140
- p.warn(t, u(c({}, e), { module: r }), ...n);
140
+ f.warn(t, p(c({}, e), { module: r }), ...n);
141
141
  },
142
142
  error(t, e, ...n) {
143
- p.error(t, u(c({}, e), { module: r }), ...n);
143
+ f.error(t, p(c({}, e), { module: r }), ...n);
144
144
  },
145
145
  timer(t, e) {
146
- return new A(t, u(c({}, e), { module: r }));
146
+ return new T(t, p(c({}, e), { module: r }));
147
147
  }
148
148
  };
149
149
  }
150
- const g = B("OpenCodePluginPageContext"), T = async () => {
150
+ const g = B("OpenCodePluginPageContext"), A = async () => {
151
151
  g.info("PageContextPlugin loading...");
152
152
  const r = process.env.OPENCODE_CONTEXT_API_URL;
153
153
  return g.debug("Context API URL:", { contextApiUrl: r }), r ? (g.info("Plugin initialized successfully"), {
@@ -176,18 +176,6 @@ const g = B("OpenCodePluginPageContext"), T = async () => {
176
176
  └─────────────────────────────────────────────────────────────┘
177
177
  \`\`\`
178
178
 
179
- ### 上下文感知机制
180
-
181
- 当用户与你对话时,系统会自动收集并注入以下页面上下文信息:
182
-
183
- **选中元素**:用户在页面上选中的 DOM 元素信息,包括:
184
- - 元素的预览页面 URL 和标题
185
- - 元素的选择器
186
- - 元素的文本内容
187
- - 源码文件路径
188
-
189
- 这些信息由 Vite 插件通过内部 API 收集,并在用户发送消息时自动附加到消息前缀中。
190
-
191
179
  请遵循以下规则:
192
180
 
193
181
  1. **前置要求:定位节点位置**(强制)
@@ -196,6 +184,8 @@ const g = B("OpenCodePluginPageContext"), T = async () => {
196
184
  - 通过文件搜索、DOM 分析等方式定位到具体代码位置
197
185
  - 明确知道节点在哪里被定义/使用后,再处理用户请求
198
186
 
187
+ 2. 如有需要,使用 Chrome DevTools Mcp 来获取用户当前正在浏览的页面 URL,而不是直接从上下文中提取。
188
+
199
189
  2. **理解上下文**:将页面 URL、标题和选中节点信息作为用户请求的背景,帮助理解用户的真实意图。
200
190
 
201
191
  3. **直接行动**:在明确节点位置后,针对用户的实际请求给出清晰、可执行的方案。
@@ -205,6 +195,6 @@ const g = B("OpenCodePluginPageContext"), T = async () => {
205
195
  }) : (g.warn("OPENCODE_CONTEXT_API_URL is not set, page context plugin will not work"), {});
206
196
  };
207
197
  export {
208
- T as PageContextPlugin,
209
- T as default
198
+ A as PageContextPlugin,
199
+ A as default
210
200
  };
@@ -78,18 +78,6 @@ const PageContextPlugin = () => __async(null, null, function* () {
78
78
  \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
79
79
  \`\`\`
80
80
 
81
- ### \u4E0A\u4E0B\u6587\u611F\u77E5\u673A\u5236
82
-
83
- \u5F53\u7528\u6237\u4E0E\u4F60\u5BF9\u8BDD\u65F6\uFF0C\u7CFB\u7EDF\u4F1A\u81EA\u52A8\u6536\u96C6\u5E76\u6CE8\u5165\u4EE5\u4E0B\u9875\u9762\u4E0A\u4E0B\u6587\u4FE1\u606F\uFF1A
84
-
85
- **\u9009\u4E2D\u5143\u7D20**\uFF1A\u7528\u6237\u5728\u9875\u9762\u4E0A\u9009\u4E2D\u7684 DOM \u5143\u7D20\u4FE1\u606F\uFF0C\u5305\u62EC\uFF1A
86
- - \u5143\u7D20\u7684\u9884\u89C8\u9875\u9762 URL \u548C\u6807\u9898
87
- - \u5143\u7D20\u7684\u9009\u62E9\u5668
88
- - \u5143\u7D20\u7684\u6587\u672C\u5185\u5BB9
89
- - \u6E90\u7801\u6587\u4EF6\u8DEF\u5F84
90
-
91
- \u8FD9\u4E9B\u4FE1\u606F\u7531 Vite \u63D2\u4EF6\u901A\u8FC7\u5185\u90E8 API \u6536\u96C6\uFF0C\u5E76\u5728\u7528\u6237\u53D1\u9001\u6D88\u606F\u65F6\u81EA\u52A8\u9644\u52A0\u5230\u6D88\u606F\u524D\u7F00\u4E2D\u3002
92
-
93
81
  \u8BF7\u9075\u5FAA\u4EE5\u4E0B\u89C4\u5219\uFF1A
94
82
 
95
83
  1. **\u524D\u7F6E\u8981\u6C42\uFF1A\u5B9A\u4F4D\u8282\u70B9\u4F4D\u7F6E**\uFF08\u5F3A\u5236\uFF09
@@ -98,6 +86,8 @@ const PageContextPlugin = () => __async(null, null, function* () {
98
86
  - \u901A\u8FC7\u6587\u4EF6\u641C\u7D22\u3001DOM \u5206\u6790\u7B49\u65B9\u5F0F\u5B9A\u4F4D\u5230\u5177\u4F53\u4EE3\u7801\u4F4D\u7F6E
99
87
  - \u660E\u786E\u77E5\u9053\u8282\u70B9\u5728\u54EA\u91CC\u88AB\u5B9A\u4E49/\u4F7F\u7528\u540E\uFF0C\u518D\u5904\u7406\u7528\u6237\u8BF7\u6C42
100
88
 
89
+ 2. \u5982\u6709\u9700\u8981\uFF0C\u4F7F\u7528 Chrome DevTools Mcp \u6765\u83B7\u53D6\u7528\u6237\u5F53\u524D\u6B63\u5728\u6D4F\u89C8\u7684\u9875\u9762 URL\uFF0C\u800C\u4E0D\u662F\u76F4\u63A5\u4ECE\u4E0A\u4E0B\u6587\u4E2D\u63D0\u53D6\u3002
90
+
101
91
  2. **\u7406\u89E3\u4E0A\u4E0B\u6587**\uFF1A\u5C06\u9875\u9762 URL\u3001\u6807\u9898\u548C\u9009\u4E2D\u8282\u70B9\u4FE1\u606F\u4F5C\u4E3A\u7528\u6237\u8BF7\u6C42\u7684\u80CC\u666F\uFF0C\u5E2E\u52A9\u7406\u89E3\u7528\u6237\u7684\u771F\u5B9E\u610F\u56FE\u3002
102
92
 
103
93
  3. **\u76F4\u63A5\u884C\u52A8**\uFF1A\u5728\u660E\u786E\u8282\u70B9\u4F4D\u7F6E\u540E\uFF0C\u9488\u5BF9\u7528\u6237\u7684\u5B9E\u9645\u8BF7\u6C42\u7ED9\u51FA\u6E05\u6670\u3001\u53EF\u6267\u884C\u7684\u65B9\u6848\u3002
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-plugin-opencode-assistant/opencode",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "execa": "^9.6.1",
25
- "@vite-plugin-opencode-assistant/shared": "1.0.17"
25
+ "@vite-plugin-opencode-assistant/shared": "1.0.19"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@opencode-ai/plugin": "^1.3.15",