@orbit-build/cli 3.0.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.1.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) {
@@ -141,8 +147,26 @@
141
147
  browser.runtime.onMessage.addListener((msg, sender) => {
142
148
  if (sender.id !== browser.runtime.id || !msg || msg.channel !== "orbit-safari") return;
143
149
  return Promise.resolve().then(() => {
144
- if (msg.action === "identify") return { documentId, workspace: !!workspace() };
150
+ if (msg.action === "identify") {
151
+ const input = workspace();
152
+ const connected = !!input;
153
+ return {
154
+ documentId,
155
+ workspace: connected,
156
+ draftTarget: input ? destination(input) : undefined,
157
+ chatName: input
158
+ ? document.getElementById("workspaceName")?.textContent.trim().slice(0, 120)
159
+ : undefined,
160
+ workspaceName: connected
161
+ ? document.getElementById("sidebarWorkspace")?.textContent.trim().slice(0, 120)
162
+ : undefined,
163
+ };
164
+ }
145
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
+ }
146
170
  switch (msg.action) {
147
171
  case "pageExcerpt": {
148
172
  if (workspace() || !/^https?:$/.test(location.protocol)) throw Error("page");
@@ -7,3 +7,6 @@ button, textarea { font: inherit; }
7
7
  button { padding: 5px 9px; }
8
8
  textarea { resize: vertical; }
9
9
  p, label { overflow-wrap: anywhere; }
10
+
11
+ #route { overflow-wrap: anywhere; padding-block: 5px; border-bottom: 1px solid GrayText; }
12
+ button:focus-visible, textarea:focus-visible { outline: 2px solid AccentColor; outline-offset: 2px; }
@@ -7,6 +7,7 @@
7
7
  </head>
8
8
  <body>
9
9
  <strong>Orbit</strong>
10
+ <p id="route" hidden></p>
10
11
  <p id="status" role="status" aria-live="polite"></p>
11
12
  <section id="fields"></section>
12
13
  <section id="actions"></section>
@@ -1,6 +1,8 @@
1
- const zh = navigator.language.toLowerCase().startsWith("zh");
2
- const t = (en, cn) => zh ? cn : en;
3
- document.documentElement.lang = zh ? "zh-CN" : "en";
1
+ const locale = navigator.language.toLowerCase();
2
+ const chinese = locale.startsWith("zh");
3
+ const traditional = chinese && /(?:hant|tw|hk|mo)(?:-|$)/.test(locale);
4
+ const t = (en, cn, tw = cn) => traditional ? tw : chinese ? cn : en;
5
+ document.documentElement.lang = traditional ? "zh-TW" : chinese ? "zh-CN" : "en";
4
6
  const status = document.querySelector("#status");
5
7
  const fields = document.querySelector("#fields");
6
8
  const actions = document.querySelector("#actions");
@@ -9,33 +11,57 @@ const reasons = {
9
11
  chooseForm: t(
10
12
  "Click a text field in the form you want, then reopen Orbit.",
11
13
  "请点一下目标表单里的文本框,再打开 Orbit。",
14
+ "請先點選目標表單的文字欄位,再開啟 Orbit。",
15
+ ),
16
+ emptyDraft: t(
17
+ "Enter at least one value in the draft.",
18
+ "请至少填写一项草稿内容。",
19
+ "請至少填寫一項草稿內容。",
12
20
  ),
13
- emptyDraft: t("Enter at least one value in the draft.", "请至少填写一项草稿内容。"),
14
21
  invalidValue: t(
15
22
  "Check field length limits and remove line breaks from single-line fields.",
16
23
  "请检查字段长度,并去掉单行文本框里的换行,再试一次。",
24
+ "請檢查欄位長度並移除單行欄位的換行,再試一次。",
17
25
  ),
18
26
  draft: t(
19
27
  "Your Orbit draft has text. Send or save it first.",
20
28
  "Orbit 输入框里有草稿。请先发送或保存。",
29
+ "Orbit 輸入框裡有草稿。請先傳送或儲存。",
30
+ ),
31
+ empty: t(
32
+ "No empty, visible text fields are available.",
33
+ "没有可填写的可见空文本框。",
34
+ "沒有可填寫的可見空白文字欄位。",
35
+ ),
36
+ page: t(
37
+ "Choose a normal HTTPS page or a local test page.",
38
+ "请选择 HTTPS 网页或本地测试页。",
39
+ "請選擇 HTTPS 網頁或本機測試頁。",
21
40
  ),
22
- empty: t("No empty, visible text fields are available.", "没有可填写的可见空文本框。"),
23
- page: t("Choose a normal HTTPS page or a local test page.", "请选择 HTTPS 网页或本地测试页。"),
24
41
  workspace: t(
25
42
  "Connect your signed-in Orbit workspace first.",
26
43
  "请先在已连接的 Orbit 工作区打开扩展并连接。",
44
+ "請先在 Orbit 工作區開啟延伸功能並連線。",
27
45
  ),
28
46
  reply: t(
29
47
  "Send the request in Orbit and wait for its completed JSON reply.",
30
48
  "请在 Orbit 发送请求,等它回复完整的 JSON 草稿。",
49
+ "請在 Orbit 傳送請求,等待完整的 JSON 草稿。",
31
50
  ),
32
51
  stale: t(
33
52
  "The tab or form changed. Start a new handoff.",
34
53
  "标签页或表单已变化,请重新交给 Orbit。",
54
+ "分頁或表單已變更,請重新交給 Orbit。",
55
+ ),
56
+ chatChanged: t(
57
+ "The Orbit chat changed. Reopen Orbit here to choose the current draft.",
58
+ "Orbit 对话已切换。请重新打开此扩展,核对草稿去向。",
59
+ "Orbit 對話已切換。請重新開啟延伸功能,核對草稿去向。",
35
60
  ),
36
61
  access: t(
37
62
  "Safari could not access this tab. Check the extension permission and reopen it.",
38
63
  "Safari 无法访问此标签页。请检查扩展权限并重新打开。",
64
+ "Safari 無法存取此分頁。請檢查延伸功能權限並重新開啟。",
39
65
  ),
40
66
  };
41
67
 
@@ -90,27 +116,41 @@ async function main() {
90
116
  await browser.scripting.executeScript({ target: { tabId: tab.id }, files: ["page.js"] });
91
117
  const info = await message({ tabId: tab.id }, "identify");
92
118
  const here = { tabId: tab.id, documentId: info.documentId };
119
+ const route = document.querySelector("#route");
93
120
  const { workspace, task } = await store.get(["workspace", "task"]);
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");
125
+ }
126
+ const targetName = target.workspaceName || workspace?.name
127
+ || t("Orbit workspace", "Orbit 工作区", "Orbit 工作區");
128
+ const destination = [targetName, target.chatName].filter(Boolean).join(" / ");
129
+ route.hidden = !info.workspace && !workspace;
130
+ route.textContent = info.workspace ? destination : url.host + " → " + destination;
94
131
  const live = task && Date.now() < task.expires;
95
132
  if (task && !live) await store.remove("task");
96
133
  if (info.workspace) {
97
134
  if (workspace?.documentId !== here.documentId || workspace.tabId !== tab.id) {
98
135
  status.textContent = t(
99
136
  "Use this Orbit workspace for Safari drafts?",
100
- "用这个 Orbit 工作区起草 Safari 表单?",
137
+ "将 Safari 选文和表单草稿送到这个工作区?",
138
+ "將 Safari 選文和表單草稿送到這個工作區?",
101
139
  );
102
- button(t("Connect this workspace", "连接这个工作区"), async () => {
140
+ button(t("Connect this workspace", "连接这个工作区", "連線至這個工作區"), async () => {
103
141
  await store.remove("task");
104
- await store.set({ workspace: here });
142
+ await store.set({ workspace: { ...here, name: targetName } });
105
143
  await main();
106
144
  });
107
145
  } else {
108
146
  status.textContent = t(
109
147
  "Connected. Open Orbit in the Safari toolbar on the website you want to share.",
110
148
  "已连接。在要分享的网页上点 Safari 工具栏里的 Orbit。",
149
+ "已連線。在要分享的網頁上點選 Safari 工具列裡的 Orbit。",
111
150
  );
112
- if (live) button(t("Return to the form", "返回表单"), () => focusTab(task.source.tabId));
113
- button(t("Disconnect", "断开连接"), async () => {
151
+ if (live)
152
+ button(t("Return to the form", "返回表单", "返回表單"), () => focusTab(task.source.tabId));
153
+ button(t("Disconnect", "断开连接", "中斷連線"), async () => {
114
154
  await store.remove(["workspace", "task"]);
115
155
  await main();
116
156
  });
@@ -122,37 +162,54 @@ async function main() {
122
162
  // A Safari window can disappear between preparing a draft and activating its tab.
123
163
  // Offer navigation again without appending the same excerpt a second time.
124
164
  actions.replaceChildren();
125
- status.textContent = t("Draft ready in Orbit.", "草稿已在 Orbit 中准备好。");
165
+ status.textContent = t(
166
+ "Draft ready in Orbit.",
167
+ "草稿已在 Orbit 中准备好。",
168
+ "草稿已在 Orbit 中準備好。",
169
+ );
126
170
  button(t("Return to Orbit", "返回 Orbit"), () => focusTab(workspace.tabId));
127
171
  await focusTab(workspace.tabId);
128
172
  }
129
- button(t("Ask about this page or selection", "把网页或选中文字交给 Orbit"), async () => {
130
- const excerpt = await message(here, "pageExcerpt");
131
- try {
132
- await message(workspace, "draftQuestion", { excerpt });
133
- } catch (error) {
134
- if (error.message !== "draft") throw error;
135
- actions.replaceChildren();
136
- status.textContent = t(
137
- "There is already a draft in Orbit. Add this page at the end?",
138
- "Orbit 里已有草稿。要把网页内容追加到末尾吗?",
139
- );
140
- button(t("Add to existing draft", "追加到现有草稿"), async () => {
141
- await message(workspace, "draftQuestion", { excerpt, append: true });
142
- await openPreparedDraft();
143
- });
144
- button(t("Cancel", "取消"), main);
145
- actions.querySelector("button").focus();
146
- return;
147
- }
148
- await openPreparedDraft();
149
- });
173
+ button(
174
+ t(
175
+ "Ask about this page or selection",
176
+ "把网页或选中文字交给 Orbit",
177
+ "將網頁或選取文字交給 Orbit",
178
+ ),
179
+ async () => {
180
+ const excerpt = await message(here, "pageExcerpt");
181
+ try {
182
+ await message(workspace, "draftQuestion", { excerpt, draftTarget: target.draftTarget });
183
+ } catch (error) {
184
+ if (error.message !== "draft") throw error;
185
+ actions.replaceChildren();
186
+ status.textContent = t(
187
+ "There is already a draft in Orbit. Add this page at the end?",
188
+ "Orbit 里已有草稿。要把网页内容追加到末尾吗?",
189
+ "Orbit 裡已有草稿。要把網頁內容附加到結尾嗎?",
190
+ );
191
+ button(t("Add to existing draft", "追加到现有草稿", "附加至現有草稿"), async () => {
192
+ await message(workspace, "draftQuestion", {
193
+ excerpt,
194
+ append: true,
195
+ draftTarget: target.draftTarget,
196
+ });
197
+ await openPreparedDraft();
198
+ });
199
+ button(t("Cancel", "取消"), main);
200
+ actions.querySelector("button").focus();
201
+ return;
202
+ }
203
+ await openPreparedDraft();
204
+ },
205
+ );
150
206
  if (live && task.source.tabId === here.tabId && task.source.documentId === here.documentId) {
151
207
  status.textContent = t(
152
208
  "Review each suggestion here. You submit the form on the website.",
153
209
  "在这里核对建议值。最后由你在网页上提交。",
210
+ "在這裡核對建議值,最後由你在網頁上送出。",
154
211
  );
155
- button(t("Review Orbit’s draft", "查看 Orbit 草稿"), async () => {
212
+ button(t("Review Orbit’s draft", "查看 Orbit 草稿", "檢視 Orbit 草稿"), async () => {
156
213
  const values = await message(workspace, "proposal", {
157
214
  key: task.key,
158
215
  length: task.labels.length,
@@ -169,7 +226,7 @@ async function main() {
169
226
  fields.append(label);
170
227
  return input;
171
228
  });
172
- button(t("Fill reviewed values", "填入已核对的内容"), async () => {
229
+ button(t("Fill reviewed values", "填入已核对的内容", "填入已核對的內容"), async () => {
173
230
  const current = (await store.get("task")).task;
174
231
  if (current?.key !== task.key) throw Error("stale");
175
232
  const result = await message(here, "apply", {
@@ -182,12 +239,13 @@ async function main() {
182
239
  status.textContent = t(
183
240
  `Filled ${result.count} of ${result.total}. Review the page before submitting.`,
184
241
  `已填入 ${result.count}/${result.total} 项,请在网页上核对并提交。`,
242
+ `已填入 ${result.count}/${result.total} 項,請在網頁上核對並送出。`,
185
243
  );
186
244
  });
187
245
  button(t("Cancel", "取消"), main);
188
246
  });
189
247
  button(t("Return to Orbit", "返回 Orbit"), () => focusTab(workspace.tabId));
190
- button(t("End this handoff", "结束这次协作"), async () => {
248
+ button(t("End this handoff", "结束这次协作", "結束這次交接"), async () => {
191
249
  await store.remove("task");
192
250
  await main();
193
251
  });
@@ -196,16 +254,18 @@ async function main() {
196
254
  status.textContent = t(
197
255
  "Share this page and any selected text, or prepare a form. Review the draft in Orbit before sending.",
198
256
  "分享当前网页和选中文字,或起草表单。在 Orbit 里核对草稿后再发送。",
257
+ "分享目前網頁與選取文字,或起草表單。在 Orbit 核對草稿後再傳送。",
199
258
  );
200
259
  if (live)
201
260
  status.textContent += t(
202
261
  " Starting another form replaces the previous form handoff.",
203
262
  " 开始新表单会替换上一次表单协作。",
263
+ " 開始新表單會取代上一次表單交接。",
204
264
  );
205
- button(t("Hand to Orbit", "交给 Orbit"), async () => {
265
+ button(t("Hand to Orbit", "交给 Orbit", "交給 Orbit"), async () => {
206
266
  const key = crypto.randomUUID();
207
267
  const { site, labels } = await message(here, "start", { key });
208
- await message(workspace, "prepare", { key, site, labels });
268
+ await message(workspace, "prepare", { key, site, labels, draftTarget: target.draftTarget });
209
269
  await store.set({ task: { source: here, labels, key, expires: Date.now() + 10 * 60_000 } });
210
270
  await focusTab(workspace.tabId);
211
271
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbit-build/cli",
3
- "version": "3.0.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": [