@orbit-build/cli 3.1.0 → 3.2.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Orbit for Safari",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "description": "Share a page or selection with Orbit, or review and fill a form in Safari.",
6
6
  "permissions": ["activeTab", "scripting", "storage"],
7
7
  "action": { "default_popup": "popup.html", "default_title": "Orbit" }
@@ -9,6 +9,12 @@
9
9
  && location.pathname === "/" && document.querySelector("#connectionState.is-connected")
10
10
  && document.querySelector("textarea#prompt");
11
11
 
12
+ function destination(input) {
13
+ if (!input || input.getAttribute("aria-busy") === "true") throw Error("chatChanged");
14
+ return input.dataset.orbitDraftTarget
15
+ || document.querySelector(".recent-session[aria-current=page]")?.dataset.sessionId;
16
+ }
17
+
12
18
  function labelOf(el) {
13
19
  let label = el.labels?.[0]?.innerText?.trim() || el.getAttribute("aria-label")?.trim();
14
20
  if (!label) {
@@ -142,16 +148,25 @@
142
148
  if (sender.id !== browser.runtime.id || !msg || msg.channel !== "orbit-safari") return;
143
149
  return Promise.resolve().then(() => {
144
150
  if (msg.action === "identify") {
145
- const connected = !!workspace();
151
+ const input = workspace();
152
+ const connected = !!input;
146
153
  return {
147
154
  documentId,
148
155
  workspace: connected,
156
+ draftTarget: input ? destination(input) : undefined,
157
+ chatName: input
158
+ ? document.getElementById("workspaceName")?.textContent.trim().slice(0, 120)
159
+ : undefined,
149
160
  workspaceName: connected
150
161
  ? document.getElementById("sidebarWorkspace")?.textContent.trim().slice(0, 120)
151
162
  : undefined,
152
163
  };
153
164
  }
154
165
  if (msg.documentId !== documentId) throw Error("stale");
166
+ if (msg.action === "draftQuestion" || msg.action === "prepare") {
167
+ const target = destination(workspace());
168
+ if (msg.draftTarget !== undefined && target !== msg.draftTarget) throw Error("chatChanged");
169
+ }
155
170
  switch (msg.action) {
156
171
  case "pageExcerpt": {
157
172
  if (workspace() || !/^https?:$/.test(location.protocol)) throw Error("page");
@@ -53,6 +53,11 @@ const reasons = {
53
53
  "标签页或表单已变化,请重新交给 Orbit。",
54
54
  "分頁或表單已變更,請重新交給 Orbit。",
55
55
  ),
56
+ chatChanged: t(
57
+ "The Orbit chat changed. Reopen Orbit here to choose the current draft.",
58
+ "Orbit 对话已切换。请重新打开此扩展,核对草稿去向。",
59
+ "Orbit 對話已切換。請重新開啟延伸功能,核對草稿去向。",
60
+ ),
56
61
  access: t(
57
62
  "Safari could not access this tab. Check the extension permission and reopen it.",
58
63
  "Safari 无法访问此标签页。请检查扩展权限并重新打开。",
@@ -113,16 +118,16 @@ async function main() {
113
118
  const here = { tabId: tab.id, documentId: info.documentId };
114
119
  const route = document.querySelector("#route");
115
120
  const { workspace, task } = await store.get(["workspace", "task"]);
116
- let workspaceName = workspace?.name;
117
- if (!info.workspace && workspace && !workspaceName) {
118
- const saved = await message(workspace, "identify");
119
- if (!saved.workspace || saved.documentId !== workspace.documentId) throw Error("stale");
120
- workspaceName = saved.workspaceName;
121
+ let target = info;
122
+ if (!info.workspace && workspace) {
123
+ target = await message(workspace, "identify");
124
+ if (!target.workspace || target.documentId !== workspace.documentId) throw Error("stale");
121
125
  }
122
- const targetName = (info.workspace ? info.workspaceName : workspaceName)
126
+ const targetName = target.workspaceName || workspace?.name
123
127
  || t("Orbit workspace", "Orbit 工作区", "Orbit 工作區");
128
+ const destination = [targetName, target.chatName].filter(Boolean).join(" / ");
124
129
  route.hidden = !info.workspace && !workspace;
125
- route.textContent = info.workspace ? targetName : url.host + " → " + targetName;
130
+ route.textContent = info.workspace ? destination : url.host + " → " + destination;
126
131
  const live = task && Date.now() < task.expires;
127
132
  if (task && !live) await store.remove("task");
128
133
  if (info.workspace) {
@@ -174,7 +179,7 @@ async function main() {
174
179
  async () => {
175
180
  const excerpt = await message(here, "pageExcerpt");
176
181
  try {
177
- await message(workspace, "draftQuestion", { excerpt });
182
+ await message(workspace, "draftQuestion", { excerpt, draftTarget: target.draftTarget });
178
183
  } catch (error) {
179
184
  if (error.message !== "draft") throw error;
180
185
  actions.replaceChildren();
@@ -184,7 +189,11 @@ async function main() {
184
189
  "Orbit 裡已有草稿。要把網頁內容附加到結尾嗎?",
185
190
  );
186
191
  button(t("Add to existing draft", "追加到现有草稿", "附加至現有草稿"), async () => {
187
- await message(workspace, "draftQuestion", { excerpt, append: true });
192
+ await message(workspace, "draftQuestion", {
193
+ excerpt,
194
+ append: true,
195
+ draftTarget: target.draftTarget,
196
+ });
188
197
  await openPreparedDraft();
189
198
  });
190
199
  button(t("Cancel", "取消"), main);
@@ -256,7 +265,7 @@ async function main() {
256
265
  button(t("Hand to Orbit", "交给 Orbit", "交給 Orbit"), async () => {
257
266
  const key = crypto.randomUUID();
258
267
  const { site, labels } = await message(here, "start", { key });
259
- await message(workspace, "prepare", { key, site, labels });
268
+ await message(workspace, "prepare", { key, site, labels, draftTarget: target.draftTarget });
260
269
  await store.set({ task: { source: here, labels, key, expires: Date.now() + 10 * 60_000 } });
261
270
  await focusTab(workspace.tabId);
262
271
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbit-build/cli",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Local-first AI coding agent CLI, TUI, Web UI, diagnostics, and LSP runtime",
6
6
  "keywords": [