cortico-world-workbuddy 0.1.6 → 0.3.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.
package/dist/webui.js CHANGED
@@ -36,19 +36,12 @@ var TEXT = {
36
36
  currentModel: "\u5F53\u524D\u6A21\u578B",
37
37
  priorityTitle: "\u4E2D\u8F6C\u7AD9\u4F18\u5148",
38
38
  priorityLabel: "\u662F\u5426\u542F\u7528Workbuddy",
39
- priorityDesc: "\u4E0E\u300C\u5F00\u59CB\u300D\u9875\u7684\u300C\u4E2D\u8F6C\u7AD9\u4F18\u5148\u300D\u6309\u94AE\u662F\u540C\u4E00\u4EFD\u72B6\u6001\uFF1A\u6253\u5F00\u540E\u684C\u5BA0\u6BCF\u8F6E\u5BF9\u8BDD\u4F18\u5148\u8C03\u7528 WorkBuddy \u7684\u6A21\u578B\uFF0C\u5173\u95ED\u5219\u5B8C\u5168\u8DF3\u8FC7 WorkBuddy\u3002\u9700\u8981 WorkBuddy \u684C\u9762\u7AEF\u4E3B\u8FDB\u7A0B\u5728\u8FD0\u884C\u3002",
39
+ priorityDesc: "\u6253\u5F00\u540E\u684C\u5BA0\u6BCF\u8F6E\u5BF9\u8BDD\u4F18\u5148\u8C03\u7528 WorkBuddy \u7684\u6A21\u578B\uFF0C\u5173\u95ED\u5219\u5B8C\u5168\u8DF3\u8FC7 WorkBuddy\u3002\u9700\u8981 WorkBuddy \u684C\u9762\u7AEF\u4E3B\u8FDB\u7A0B\u5728\u8FD0\u884C\u3002",
40
40
  procRunning: "WorkBuddy \u4E3B\u8FDB\u7A0B\uFF1A\u8FD0\u884C\u4E2D",
41
41
  procStopped: "WorkBuddy \u4E3B\u8FDB\u7A0B\uFF1A\u672A\u68C0\u6D4B\u5230",
42
42
  noProcess: "\u672A\u68C0\u6D4B\u5230Workbuddy",
43
43
  enabledOn: "\u5DF2\u5F00\u542F\uFF1A\u684C\u5BA0\u4F18\u5148\u8D70 WorkBuddy \u6A21\u578B",
44
44
  enabledOff: "\u5DF2\u5173\u95ED\uFF1A\u684C\u5BA0\u8DF3\u8FC7 WorkBuddy",
45
- hostOk: "\u5F00\u59CB\u9875\u6309\u94AE\uFF1A\u5DF2\u6CE8\u5165",
46
- hostBroken: "\u5F00\u59CB\u9875\u6309\u94AE\uFF1A\u672A\u6CE8\u5165\uFF08\u5BBF\u4E3B\u5347\u7EA7\u53EF\u80FD\u8986\u76D6\u4E86\u63A7\u5236\u53F0\u6587\u4EF6\uFF09",
47
- hostUnknown: "\u5F00\u59CB\u9875\u6309\u94AE\uFF1A\u72B6\u6001\u672A\u77E5",
48
- repair: "\u91CD\u65B0\u6CE8\u5165\u5F00\u59CB\u9875\u6309\u94AE",
49
- repairing: "\u6B63\u5728\u91CD\u65B0\u6CE8\u5165\u2026",
50
- repaired: "\u5DF2\u4FEE\u590D\uFF0C\u91CD\u65B0\u6253\u5F00\u63A7\u5236\u53F0\u5373\u53EF\u770B\u5230\u6309\u94AE",
51
- repairFail: "\u4FEE\u590D\u5931\u8D25",
52
45
  usageTitle: "\u7528\u91CF",
53
46
  usageDesc: "\u672C\u673A\u8BB0\u8D26\u7684\u8C03\u7528\u7528\u91CF\u4E0E WorkBuddy \u79EF\u5206\u5305\u4F59\u989D\u3002\u79EF\u5206\u53D6\u4E0A\u6E38\u6BCF\u6B21\u8C03\u7528\u56DE\u4F20\u7684\u771F\u5B9E\u6263\u8D39\uFF08\u53EF\u80FD\u4E3A 0\uFF09\uFF0C\u500D\u7387\u6309\u76EE\u5F55 + \u9650\u65F6\u4F18\u60E0\u5B9E\u65F6\u8BA1\u7B97\u3002",
54
47
  usageRefresh: "\u5237\u65B0\u4F59\u989D",
@@ -77,7 +70,14 @@ var TEXT = {
77
70
  noData: "\u6682\u65E0\u6570\u636E",
78
71
  totalCredit: "\u5408\u8BA1\u79EF\u5206",
79
72
  todayCredit: "\u4ECA\u65E5\u79EF\u5206",
80
- todayTokens: "\u4ECA\u65E5 token"
73
+ todayTokens: "\u4ECA\u65E5 token",
74
+ colSafety: "\u5408\u89C4",
75
+ safetySafe: "\u5B89\u5168\u6E05\u5355",
76
+ safetyCaution: "\u5B89\u5168\u6E05\u5355\xB7\u8C28\u614E",
77
+ showAllModels: "\u663E\u793A\u5168\u90E8\u6A21\u578B\uFF08\u542B\u4E0D\u5EFA\u8BAE\u9879\uFF09",
78
+ unsafePick: "\u8BE5\u6A21\u578B\u4E0D\u5728\u5B89\u5168\u6E05\u5355\u5185\uFF0C\u5DF2\u62D2\u7EDD\u9009\u62E9",
79
+ safeOnlyOn: "\u4EC5\u8C03\u7528\u5B89\u5168\u6E05\u5355\u6A21\u578B",
80
+ safeOnlyOff: "safeOnly \u5DF2\u5173\u95ED\uFF1A\u5168\u90E8\u6A21\u578B\u53EF\u8C03\u7528\uFF08\u542B WorkBuddy \u4E0D\u5EFA\u8BAE\u5916\u90E8\u8C03\u7528\u7684\u9879\uFF09"
81
81
  },
82
82
  en: {
83
83
  refresh: "Refresh from WorkBuddy",
@@ -121,13 +121,6 @@ var TEXT = {
121
121
  noProcess: "Workbuddy not detected",
122
122
  enabledOn: "On: the pet asks WorkBuddy first",
123
123
  enabledOff: "Off: the pet skips WorkBuddy",
124
- hostOk: "Home button: injected",
125
- hostBroken: "Home button: not injected (a host update may have replaced the console files)",
126
- hostUnknown: "Home button: unknown",
127
- repair: "Re-inject the home button",
128
- repairing: "Re-injecting\u2026",
129
- repaired: "Fixed. Reopen the console to see the button",
130
- repairFail: "Repair failed",
131
124
  usageTitle: "Usage",
132
125
  usageDesc: "Locally recorded call usage plus the WorkBuddy credit balance. Credits come from the per-call figure the upstream returns (may be 0); multipliers combine the catalog with time-limited offers in real time.",
133
126
  usageRefresh: "Refresh balance",
@@ -156,7 +149,14 @@ var TEXT = {
156
149
  noData: "No data",
157
150
  totalCredit: "Total credits",
158
151
  todayCredit: "Credits today",
159
- todayTokens: "Tokens today"
152
+ todayTokens: "Tokens today",
153
+ colSafety: "Policy",
154
+ safetySafe: "Safe list",
155
+ safetyCaution: "Safe list \xB7 caution",
156
+ showAllModels: "Show all models (including discouraged ones)",
157
+ unsafePick: "This model is outside the safe list and cannot be selected",
158
+ safeOnlyOn: "Safe-list only",
159
+ safeOnlyOff: "safeOnly is off: every model is callable (including ones WorkBuddy discourages)"
160
160
  }
161
161
  };
162
162
  function strings(ctx) {
@@ -190,33 +190,42 @@ function mountModels(ctx) {
190
190
  const { ui } = ctx;
191
191
  const sheet = ui.sheet({
192
192
  title: s.colModel === "\u6A21\u578B" ? "WorkBuddy \u6A21\u578B\u76EE\u5F55" : "WorkBuddy model catalog",
193
- desc: s.empty
193
+ desc: s.colModel === "\u6A21\u578B" ? "\u9ED8\u8BA4\u53EA\u5217 WorkBuddy \u516C\u5F00\u5BF9\u8BDD\u6A21\u578B\uFF08\u5B89\u5168\u6E05\u5355\uFF09\uFF1B\u52FE\u9009\u300C\u663E\u793A\u5168\u90E8\u6A21\u578B\u300D\u53EF\u67E5\u770B\u88AB\u6392\u9664\u9879\u53CA\u5176\u7406\u7531\u3002" : 'Only WorkBuddy public chat models are listed by default; tick "Show all models" to see excluded ones and why.'
194
194
  });
195
195
  ctx.root.append(sheet.el);
196
196
  const head = ui.rowbar();
197
197
  const refreshBtn = ui.button(s.refresh, { variant: "primary" });
198
198
  const stateChip = ui.chip("", "plain");
199
199
  const currentChip = ui.chip("", "accent");
200
- head.append(refreshBtn, stateChip, currentChip);
200
+ const allBox = ui.checkbox(s.showAllModels, { checked: false });
201
+ head.append(refreshBtn, stateChip, currentChip, allBox.el);
201
202
  sheet.body.append(head);
202
203
  const errLine = ui.msgline();
203
204
  sheet.body.append(errLine);
204
205
  const table = ui.table({
205
- head: [s.colModel, s.colMultiplier, s.colContext, s.colReasoning, s.colAction],
206
+ head: [s.colModel, s.colSafety, s.colMultiplier, s.colContext, s.colReasoning, s.colAction],
206
207
  maxHeight: "calc(100vh - 320px)"
207
208
  });
208
209
  sheet.body.append(table.el);
209
210
  let state = null;
210
211
  function renderChips() {
211
- stateChip.textContent = `${s.lastRefresh}: ${fmtTs(state?.catalogAt, s)} \xB7 ${state?.models?.length ?? 0} ${s.models}`;
212
+ const models = state?.models ?? [];
213
+ const safeCount = models.filter((m) => m.safety?.allow).length;
214
+ stateChip.textContent = `${s.lastRefresh}: ${fmtTs(state?.catalogAt, s)} \xB7 ${safeCount}/${models.length} ${s.models} \xB7 ${state?.safeOnly === false ? s.safeOnlyOff : s.safeOnlyOn}`;
212
215
  currentChip.textContent = `${s.currentModel}: ${state?.model || "\u2014"}`;
213
216
  }
217
+ function pickable(m) {
218
+ if (state?.safeOnly === false) return true;
219
+ return m.safety?.allow !== false;
220
+ }
214
221
  function renderTable() {
215
- const models = state?.models ?? [];
222
+ const all = state?.models ?? [];
223
+ const models = allBox.checked ? all : all.filter((m) => m.safety?.allow);
216
224
  table.clear(models.length ? void 0 : s.empty);
217
225
  for (const m of models) {
218
226
  const mul = fmtMultiplier(m, s);
219
227
  const isCurrent = state.model === m.id;
228
+ const safety = m.safety ?? {};
220
229
  const nameCell = ui.h("div");
221
230
  nameCell.append(ui.h("div", null, m.name || m.id));
222
231
  const sub = ui.h("div", "dim", m.id);
@@ -224,12 +233,26 @@ function mountModels(ctx) {
224
233
  sub.style.opacity = "0.65";
225
234
  nameCell.append(sub);
226
235
  if (m.description) nameCell.title = m.description;
236
+ const safePill = ui.pill(
237
+ safety.label ?? "\u2014",
238
+ safety.allow ? safety.caution ? "plain" : "on" : "plain"
239
+ );
240
+ if (safety.reason) safePill.title = safety.reason;
241
+ if (!safety.allow) {
242
+ safePill.style.opacity = "0.6";
243
+ nameCell.style.opacity = "0.6";
244
+ }
227
245
  const mulPill = ui.pill(mul.text, mul.free ? "on" : "plain");
228
246
  if (mul.promo) mulPill.title = mul.promo;
247
+ const allowed = pickable(m);
229
248
  const btn = ui.button(isCurrent ? s.selected : s.select, {
230
249
  size: "sm",
231
250
  variant: isCurrent ? "plain" : "primary",
232
251
  onClick: async () => {
252
+ if (!allowed) {
253
+ ui.toast(`${s.unsafePick}${safety.reason ? `\uFF1A${safety.reason}` : ""}`, "bad");
254
+ return;
255
+ }
233
256
  const off = ui.disable(btn);
234
257
  try {
235
258
  const r = await ctx.invoke("select", [m.id]);
@@ -249,8 +272,13 @@ function mountModels(ctx) {
249
272
  }
250
273
  });
251
274
  if (isCurrent) btn.disabled = true;
275
+ if (!allowed) {
276
+ btn.disabled = true;
277
+ btn.title = safety.reason ?? "";
278
+ }
252
279
  table.addRow([
253
280
  nameCell,
281
+ safePill,
254
282
  mulPill,
255
283
  m.contextWindow ? String(m.contextWindow) : "\u2014",
256
284
  m.reasoning?.supportedEfforts?.join(" / ") ?? "\u2014",
@@ -258,6 +286,10 @@ function mountModels(ctx) {
258
286
  ]);
259
287
  }
260
288
  }
289
+ allBox.input.addEventListener("change", () => {
290
+ renderChips();
291
+ renderTable();
292
+ });
261
293
  async function load() {
262
294
  state = await ctx.invoke("state");
263
295
  renderChips();
@@ -389,40 +421,10 @@ function mountPriority(ctx) {
389
421
  const sheet = ui.sheet({ title: s.priorityTitle, desc: s.priorityDesc });
390
422
  ctx.root.append(sheet.el);
391
423
  const statusLine = ui.msgline();
392
- const hostLine = ui.msgline();
393
- const hostBar = ui.actions();
394
- const repairBtn = ui.button(s.repair, {
395
- size: "sm",
396
- variant: "plain",
397
- onClick: async () => {
398
- repairBtn.disabled = true;
399
- hostLine.textContent = s.repairing;
400
- try {
401
- const r = await ctx.invoke("repair");
402
- hostLine.textContent = r?.ok ? s.repaired : `${s.repairFail}\uFF1A${r?.error ?? r?.hostUi?.reason ?? ""}`;
403
- ui.toast(r?.ok ? s.repaired : s.repairFail, r?.ok ? "ok" : "bad");
404
- await load();
405
- } catch (err) {
406
- hostLine.textContent = `${s.repairFail}\uFF1A${String(err?.message ?? err)}`;
407
- ui.toast(s.repairFail, "bad");
408
- } finally {
409
- repairBtn.disabled = false;
410
- }
411
- }
412
- });
413
- hostBar.append(repairBtn);
414
424
  function apply(r) {
415
425
  if (!r) return;
416
426
  box.setChecked(r.prefer === true);
417
427
  statusLine.textContent = r.running ? s.procRunning : s.procStopped;
418
- const host = r.hostUi;
419
- if (!host) {
420
- hostLine.textContent = s.hostUnknown;
421
- hostBar.style.display = "none";
422
- return;
423
- }
424
- hostLine.textContent = host.ok ? s.hostOk : `${s.hostBroken}\uFF08${host.label ?? host.reason}\uFF09`;
425
- hostBar.style.display = host.ok ? "none" : "";
426
428
  }
427
429
  const box = ui.checkbox(s.priorityLabel, {
428
430
  checked: false,
@@ -444,7 +446,7 @@ function mountPriority(ctx) {
444
446
  }
445
447
  }
446
448
  });
447
- sheet.body.append(box.el, statusLine, hostLine, hostBar);
449
+ sheet.body.append(box.el, statusLine);
448
450
  async function load() {
449
451
  apply(await ctx.invoke("state"));
450
452
  }
@@ -566,7 +568,9 @@ function mountUsage(ctx) {
566
568
  recentTable.addRow([
567
569
  when,
568
570
  r.model ?? "\u2014",
569
- fmtNum(r.totalTokens ?? (r.promptTokens ?? 0) + (r.completionTokens ?? 0)),
571
+ // 账本里的字段名就是 total/prompt/completion(不是 totalTokens),
572
+ // 以前这里恒读出 0,最近调用表的 token 列一直是 0。
573
+ fmtNum(r.total ?? (r.prompt ?? 0) + (r.completion ?? 0)),
570
574
  r.ok === false ? "\u2014" : fmtNum(r.credit),
571
575
  typeof r.durationMs === "number" ? `${r.durationMs} ms` : "\u2014"
572
576
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-workbuddy",
3
- "version": "0.1.6",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "把 Windows 端已登录的 WorkBuddy 客户端模型桥接进 Coopanion:读取本机登录态,列出模型目录与默认积分倍率,供 Coo 调用。",
6
6
  "license": "MIT",
@@ -49,16 +49,17 @@
49
49
  "CHANGELOG.md",
50
50
  "describe.json",
51
51
  "scripts",
52
+ "!scripts/visual",
52
53
  "LICENSE",
53
- "SECURITY.md",
54
- "ENV_PROMPT.md"
54
+ "SECURITY.md"
55
55
  ],
56
56
  "scripts": {
57
- "build:web": "esbuild src/webui/client.js --bundle --format=esm --outfile=dist/webui.js",
57
+ "build:web": "node scripts/build-web.mjs",
58
58
  "selfcheck": "node scripts/selfcheck.mjs",
59
- "host-inject": "node scripts/host-inject.mjs",
60
59
  "verify": "node scripts/verify-ui.mjs --runs 3",
61
- "prepack": "npm run build:web"
60
+ "prepack": "node scripts/build-web.mjs --strict",
61
+ "gen:describe": "node scripts/gen-describe.mjs",
62
+ "contract": "node scripts/contract.mjs"
62
63
  },
63
64
  "author": {
64
65
  "name": "大肥鱼 (aechoa215)",
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 重建 `dist/webui.js`(面板产物)。
4
+ *
5
+ * 为什么不用 `esbuild` 直接当 script:`prepack` 会在别人机器上跑,
6
+ * 那里可能没有 `npm install` 过(没有 node_modules/esbuild),直接调 `esbuild` 会
7
+ * `'esbuild' is not recognized`,整条 `npm pack` 就失败了。
8
+ *
9
+ * 解析顺序:
10
+ * 1. 本包的 devDependency(`node_modules/esbuild`,版本由 lock 固定,CI 用这个);
11
+ * 2. 宿主 Coopanion 自带的那份(`--config.strict-dep-builds` 之外的本机兜底);
12
+ * 3. 都没有:`dist/webui.js` 已存在就警告并退出 0(产物已随包提交),否则报错。
13
+ *
14
+ * `--strict`:找不到 esbuild 时**不允许**沿用旧产物(返回 1)。
15
+ * `prepack` 走 strict —— 否则没装依赖的机器会静默把过期 dist 发布出去(审查报告第 6 条)。
16
+ *
17
+ * 用法:node scripts/build-web.mjs [--verbose] [--strict]
18
+ */
19
+
20
+ import { existsSync, mkdirSync, readFileSync as readTextSync, statSync } from 'node:fs';
21
+ import { spawnSync } from 'node:child_process';
22
+ import { createRequire } from 'node:module';
23
+ import { dirname, join } from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
+
26
+ const pkgDir = fileURLToPath(new URL('..', import.meta.url));
27
+ const verbose = process.argv.includes('--verbose');
28
+ const strict = process.argv.includes('--strict');
29
+ const entry = join(pkgDir, 'src', 'webui', 'client.js');
30
+ const outfile = join(pkgDir, 'dist', 'webui.js');
31
+ const args = [entry, '--bundle', '--format=esm', `--outfile=${outfile}`, '--log-level=warning'];
32
+
33
+ /**
34
+ * 宿主 Coopanion 的 app 目录(只用来兜底取它自带的 esbuild)。
35
+ * 按「存在 build/console/index.html」判定,探测失败返回空串。
36
+ */
37
+ function hostAppRoot() {
38
+ const local = process.env.LOCALAPPDATA || '';
39
+ const candidates = [
40
+ local && join(local, 'Programs', 'Coopanion', 'resources', 'app'),
41
+ process.env.ProgramFiles && join(process.env.ProgramFiles, 'Coopanion', 'resources', 'app'),
42
+ process.env['ProgramFiles(x86)'] && join(process.env['ProgramFiles(x86)'], 'Coopanion', 'resources', 'app'),
43
+ ].filter(Boolean);
44
+ return candidates.find((dir) => existsSync(join(dir, 'build', 'console', 'index.html'))) ?? '';
45
+ }
46
+
47
+ /** 找到可用的 esbuild 启动脚本(bin/esbuild 是 JS 包装,用 node 跑)。 */
48
+ function resolveEsbuild() {
49
+ const require = createRequire(import.meta.url);
50
+ const candidates = [];
51
+ try {
52
+ candidates.push(require.resolve('esbuild/bin/esbuild'));
53
+ } catch {
54
+ /* 本地没装 devDependencies,走宿主兜底 */
55
+ }
56
+ const appRoot = process.env.COOPANION_APP_ROOT || hostAppRoot();
57
+ if (appRoot) candidates.push(join(appRoot, 'node_modules', 'esbuild', 'bin', 'esbuild'));
58
+
59
+ for (const bin of candidates) {
60
+ if (!existsSync(bin)) continue;
61
+ // 版本号在同一目录的 package.json 里
62
+ let version = 'unknown';
63
+ try {
64
+ version = JSON.parse(readTextSync(join(dirname(bin), '..', 'package.json'), 'utf8')).version;
65
+ } catch {
66
+ /* 版本读不到不影响构建 */
67
+ }
68
+ return { bin, version };
69
+ }
70
+ return null;
71
+ }
72
+
73
+ const found = resolveEsbuild();
74
+ if (!found) {
75
+ console.error('✗ 找不到 esbuild(本地 devDependencies 与宿主都没装)。');
76
+ console.error(' 先跑一次 `npm ci`(有 lockfile,锁的是 devDependency 的 esbuild)再重试。');
77
+ if (!existsSync(outfile)) process.exit(1);
78
+ if (strict) {
79
+ console.error('✗ --strict:拒绝沿用已有的 dist/webui.js(可能是过期产物)。');
80
+ process.exit(1);
81
+ }
82
+ console.warn('! 非 strict 模式:沿用已有的 dist/webui.js(本地开发可以,发布不行)。');
83
+ process.exit(0);
84
+ }
85
+
86
+ if (verbose) console.log(`· esbuild ${found.version}:${found.bin}`);
87
+ mkdirSync(join(pkgDir, 'dist'), { recursive: true });
88
+ const result = spawnSync(process.execPath, [found.bin, ...args], { cwd: pkgDir, encoding: 'utf8' });
89
+ if (result.stdout) process.stdout.write(result.stdout);
90
+ if (result.stderr) process.stderr.write(result.stderr);
91
+ if (result.status !== 0) {
92
+ console.error(`✗ esbuild 失败(退出码 ${result.status})`);
93
+ process.exit(1);
94
+ }
95
+
96
+ const size = statSync(outfile).size;
97
+ console.log(`✓ dist/webui.js 已重建(esbuild ${found.version},${size} 字节)`);