sideby 0.31.2 → 0.31.3

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.
@@ -68,11 +68,16 @@ export interface ReadyFile {
68
68
  sessionId?: string;
69
69
  transcriptPath?: string;
70
70
  }
71
- /** The parent kept a session that hit its limit, to wait for the reset at `until` (ADR-0018). */
71
+ /**
72
+ * The parent kept a session that waits for a reset at `until` (ADR-0018): it decided to wait, or the Host stopped at
73
+ * its limit with no account to take over. `trigger` is what made the session ready; a `limit` one is cleared by the
74
+ * hook at the next finished turn, since the Host has continued by then.
75
+ */
72
76
  export interface WaitingFile {
73
77
  runId: string;
74
78
  until: string;
75
79
  at: string;
80
+ trigger?: HandoffTrigger;
76
81
  }
77
82
  export interface ChainHop {
78
83
  ref: string;
@@ -110,8 +115,9 @@ export declare function writeJsonFile(path: string, value: unknown): Promise<voi
110
115
  /**
111
116
  * `sideby handoff ready` (spec §3.17): asks the parent to hand over after this turn. Works only inside a run sideby
112
117
  * started with Auto Handoff; `briefFile`, when given, is copied into the chain directory (mode 600); `to` is the
113
- * Account ref to hand over to. While the session waits for a reset (`waiting.json`, typed as `! sideby handoff ready`),
114
- * no turn will end to pick up a request, so it writes `ready.json` at once (`now`).
118
+ * Account ref to hand over to. While the session waits for a reset (`waiting.json`: the parent chose to wait, or the
119
+ * Host stopped at its limit with no account to take over; typed as `! sideby handoff ready`), no turn will end to pick
120
+ * up a request, so it writes `ready.json` at once (`now`).
115
121
  * Returns the request, or null outside such a run.
116
122
  */
117
123
  export declare function requestHandoff(env: Readonly<Record<string, string | undefined>>, briefFile?: string, to?: string, now?: Date): Promise<(ReadyFile & {
@@ -57,8 +57,9 @@ export async function writeJsonFile(path, value) {
57
57
  /**
58
58
  * `sideby handoff ready` (spec §3.17): asks the parent to hand over after this turn. Works only inside a run sideby
59
59
  * started with Auto Handoff; `briefFile`, when given, is copied into the chain directory (mode 600); `to` is the
60
- * Account ref to hand over to. While the session waits for a reset (`waiting.json`, typed as `! sideby handoff ready`),
61
- * no turn will end to pick up a request, so it writes `ready.json` at once (`now`).
60
+ * Account ref to hand over to. While the session waits for a reset (`waiting.json`: the parent chose to wait, or the
61
+ * Host stopped at its limit with no account to take over; typed as `! sideby handoff ready`), no turn will end to pick
62
+ * up a request, so it writes `ready.json` at once (`now`).
62
63
  * Returns the request, or null outside such a run.
63
64
  */
64
65
  export async function requestHandoff(env, briefFile, to, now = new Date()) {
@@ -135,6 +135,18 @@ export function hookEntryWorks(env) {
135
135
  execFile('sideby', ['handoff-hook', '--check'], { env: env, timeout: 5000 }, (err, out) => resolve(!err && String(out).trim() === 'ok'));
136
136
  });
137
137
  }
138
+ /** How long a Host stopped at its limit waits when its window's reset is unknown: the shortest Quota window. */
139
+ const LIMIT_WAIT_FALLBACK_MS = 5 * 60 * 60_000;
140
+ /**
141
+ * When a Host stopped at its limit continues by itself: the reset of the window that stopped it, or, without a future
142
+ * one, `LIMIT_WAIT_FALLBACK_MS` from now (the hook also clears the file at the next finished turn).
143
+ */
144
+ function limitUntil(ready, now = new Date()) {
145
+ const at = ready.window ? Date.parse(ready.window.resetsAt) : Number.NaN;
146
+ return Number.isFinite(at) && at > now.getTime()
147
+ ? new Date(at).toISOString()
148
+ : new Date(now.getTime() + LIMIT_WAIT_FALLBACK_MS).toISOString();
149
+ }
138
150
  /** The decision, or `none` with the reason when sideby cannot tell (an account removed mid-chain, say). */
139
151
  async function decide(rt, account, used, to, manual = false) {
140
152
  try {
@@ -284,11 +296,16 @@ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
284
296
  break;
285
297
  }
286
298
  await rm(join(dir, FILES.ready), { force: true });
287
- if (d.kind === 'wait')
299
+ // A session kept at its limit (or kept to wait) ends no turn until it continues, so a request would never be
300
+ // picked up: `waiting.json` lets `handoff ready` hand over at once (ADR-0018). A `threshold` none is still in
301
+ // its turns and gets none.
302
+ const until = d.kind === 'wait' ? d.until : got.ready.trigger === 'limit' ? limitUntil(got.ready) : undefined;
303
+ if (until)
288
304
  await writeJsonFile(join(dir, FILES.waiting), {
289
305
  runId,
290
- until: d.until,
306
+ until,
291
307
  at: new Date().toISOString(),
308
+ trigger: got.ready.trigger,
292
309
  });
293
310
  kept = d;
294
311
  }
@@ -49,12 +49,19 @@ export type UsedAccount = string | {
49
49
  resetsAt: string;
50
50
  };
51
51
  };
52
+ /** What an automatic handoff does with the Accounts this chain already used (spec §3.17 "选号" 3, ADR-0060). */
53
+ export interface UsedRule {
54
+ /** Left out: the origin, a bare ref, and an Account whose latest hop handed over for a window that has not reset. */
55
+ out: Set<string>;
56
+ /** Back only when its own Quota data shows it ready: its latest hop recorded no window (a manual handoff, an older chain). */
57
+ ifReady: Set<string>;
58
+ }
52
59
  /**
53
- * The Accounts an automatic handoff leaves out (spec §3.17 "选号" 3): the origin, and every Account the chain used
54
- * unless its latest hop handed over for a Quota window that has reset by `now` (ADR-0060). A bare ref, or a hop with no
55
- * window (a manual handoff, an older chain), stays out.
60
+ * Sorts the Accounts this chain used by their latest hop: one that handed over for a Quota window that has reset by
61
+ * `now` may take over again like any other, one with no recorded window only when it is `ready`, the rest stay out.
62
+ * A bare ref stays out, and so does the origin.
56
63
  */
57
- export declare function stillUsed(origin: string, used: readonly UsedAccount[], now: Date): Set<string>;
64
+ export declare function stillUsed(origin: string, used: readonly UsedAccount[], now: Date): UsedRule;
58
65
  /** Organizations when both have one, else email domains when both have one, else the same. */
59
66
  export declare function sameOrganization(a?: AccountIdentity, b?: AccountIdentity): boolean;
60
67
  export declare function selectNext(input: {
@@ -63,7 +70,10 @@ export declare function selectNext(input: {
63
70
  settings: HandoffSettings;
64
71
  /** Short command → Account ref, so lists may name either. */
65
72
  aliases: Readonly<Record<string, string>>;
66
- /** Accounts this chain already used, the origin included; one whose window has reset since may come back. */
73
+ /**
74
+ * Accounts this chain already used, the origin included; one whose window has reset since may come back, and one
75
+ * whose hop recorded no window when its Quota shows it ready.
76
+ */
67
77
  used: readonly UsedAccount[];
68
78
  now: Date;
69
79
  /** Decide now what happens when the origin's fullest window reaches the threshold (see `waitUntil`). */
@@ -1,21 +1,23 @@
1
1
  import { planHandoff } from './handoff.js';
2
2
  import { takeoverLimit, windowReset } from './quota-levels.js';
3
3
  /**
4
- * The Accounts an automatic handoff leaves out (spec §3.17 "选号" 3): the origin, and every Account the chain used
5
- * unless its latest hop handed over for a Quota window that has reset by `now` (ADR-0060). A bare ref, or a hop with no
6
- * window (a manual handoff, an older chain), stays out.
4
+ * Sorts the Accounts this chain used by their latest hop: one that handed over for a Quota window that has reset by
5
+ * `now` may take over again like any other, one with no recorded window only when it is `ready`, the rest stay out.
6
+ * A bare ref stays out, and so does the origin.
7
7
  */
8
8
  export function stillUsed(origin, used, now) {
9
- const back = new Map();
9
+ const latest = new Map();
10
10
  for (const u of used) {
11
11
  if (typeof u === 'string')
12
- back.set(u, false);
12
+ latest.set(u, 'out');
13
+ else if (u.window === undefined)
14
+ latest.set(u.ref, 'ifReady');
13
15
  else
14
- back.set(u.ref, u.window !== undefined && windowReset(u.window.resetsAt, now));
16
+ latest.set(u.ref, windowReset(u.window.resetsAt, now) ? 'back' : 'out');
15
17
  }
16
- const out = new Set([...back].flatMap(([ref, b]) => (b ? [] : [ref])));
17
- out.add(origin);
18
- return out;
18
+ latest.set(origin, 'out');
19
+ const refs = (k) => new Set([...latest].flatMap(([ref, v]) => (v === k ? [ref] : [])));
20
+ return { out: refs('out'), ifReady: refs('ifReady') };
19
21
  }
20
22
  const domain = (email) => email.slice(email.lastIndexOf('@') + 1).toLowerCase();
21
23
  /** Organizations when both have one, else email domains when both have one, else the same. */
@@ -101,14 +103,24 @@ export function selectNext(input) {
101
103
  const skipped = list
102
104
  .filter((c) => sameLogin.has(c.ref))
103
105
  .map((c) => ({ ref: c.ref, reason: `same login as ${origin.ref}, so it shares the same quota` }));
104
- const withSkipped = skipped.length ? { skipped } : {};
106
+ // A used Account with no recorded window comes back only on Quota data that shows it ready: not on a guess
107
+ // (`unknown`, an API account). It is still counted while full, so its reset can be named.
108
+ const unsure = (c) => used.ifReady.has(c.ref) && !['ready', 'full', 'logged-out'].includes(stateOf(c, s, now).state);
105
109
  // Could take over if the settings allowed it: another login, its Host installed and able to receive.
106
- const couldTake = (c) => !sameLogin.has(c.ref) && !used.has(c.ref) && c.installed && c.receive;
107
- const eligible = list.filter((c) => couldTake(c) &&
108
- // An API account pays per request, so it gets past no vendor's limit: sameFamily does not apply to it, but it
109
- // takes over only when the user allowed paying for it (`api`, ADR-0046).
110
- (c.kind === 'api' ? s.api : s.sameFamily || c.family !== origin.family) &&
111
- (allowed.has(c.ref) || sameOrganization(origin.identity, c.identity)));
110
+ const couldTake = (c) => !sameLogin.has(c.ref) && !used.out.has(c.ref) && !unsure(c) && c.installed && c.receive;
111
+ const allows = (c) =>
112
+ // An API account pays per request, so it gets past no vendor's limit: sameFamily does not apply to it, but it
113
+ // takes over only when the user allowed paying for it (`api`, ADR-0046).
114
+ (c.kind === 'api' ? s.api : s.sameFamily || c.family !== origin.family) &&
115
+ (allowed.has(c.ref) || sameOrganization(origin.identity, c.identity));
116
+ const eligible = list.filter((c) => couldTake(c) && allows(c));
117
+ for (const c of list)
118
+ if (unsure(c) && !sameLogin.has(c.ref) && c.installed && c.receive && allows(c))
119
+ skipped.push({
120
+ ref: c.ref,
121
+ reason: 'this chain already used it and its quota is not known, so it is not picked again',
122
+ });
123
+ const withSkipped = skipped.length ? { skipped } : {};
112
124
  const states = eligible.map((c) => ({ c, e: stateOf(c, s, now) }));
113
125
  const first = states.find(({ e }) => e.state === 'ready' || e.state === 'unknown') ??
114
126
  states.find(({ e }) => e.state === 'api');
@@ -312,6 +312,26 @@ const ENTRIES = [
312
312
  target: { action: 'ask', write: true },
313
313
  cliCommand: 'sideby ask',
314
314
  },
315
+ {
316
+ id: 'action.commands',
317
+ kind: 'action',
318
+ title: { en: 'Commands', zh: '命令' },
319
+ synonyms: [
320
+ 'command list',
321
+ 'commands',
322
+ 'cli',
323
+ 'terminal',
324
+ 'help',
325
+ 'shortcuts',
326
+ '命令列表',
327
+ '指令',
328
+ '终端命令',
329
+ '帮助',
330
+ ],
331
+ panel: at(HEADER, { en: 'Commands', zh: '命令' }),
332
+ target: { action: 'commands', write: false },
333
+ cliCommand: 'sideby commands',
334
+ },
315
335
  {
316
336
  id: 'action.health-check',
317
337
  kind: 'action',
@@ -121,6 +121,11 @@ export async function decide(opts) {
121
121
  const reason = field(input, 'reason');
122
122
  if (reason && reason !== 'end_turn')
123
123
  return {};
124
+ // A finished turn means a Host kept at its limit has continued: a later `handoff ready` waits for the turn again.
125
+ const waitingFile = join(dir, FILES.waiting);
126
+ const held = await readJsonFile(waitingFile);
127
+ if (held && held.runId === runId && held.trigger === 'limit')
128
+ await rm(waitingFile, { force: true });
124
129
  const request = await readJsonFile(join(dir, FILES.request));
125
130
  if (request && request.runId === runId) {
126
131
  await ready({ ...request, trigger: 'manual' });
@@ -458,6 +458,7 @@ declare const en: {
458
458
  'ai.ask.api': string;
459
459
  'ai.ask.tool': string;
460
460
  'ai.ask.find': string;
461
+ 'ai.ask.commands': string;
461
462
  'pal.button': string;
462
463
  'pal.title': string;
463
464
  'pal.placeholder': string;
@@ -477,6 +478,19 @@ declare const en: {
477
478
  'pal.readOnly': string;
478
479
  'pal.also': string;
479
480
  'pal.keys': string;
481
+ 'cmds.button': string;
482
+ 'cmds.title': string;
483
+ 'cmds.intro': string;
484
+ 'cmds.placeholder': string;
485
+ 'cmds.common': string;
486
+ 'cmds.none': string;
487
+ 'cmds.feature': string;
488
+ 'cmds.example': string;
489
+ 'cmds.copy': string;
490
+ 'cmds.copied': string;
491
+ 'cmds.open': string;
492
+ 'cmds.openLabel': string;
493
+ 'cmds.foot': string;
480
494
  'ask.button': string;
481
495
  'ask.title': string;
482
496
  'ask.title.fix': string;
@@ -460,6 +460,7 @@ const en = {
460
460
  'ai.ask.api': 'Add a DeepSeek API account for me.',
461
461
  'ai.ask.tool': 'Help sideby support a new tool.',
462
462
  'ai.ask.find': 'Where do I change the language of the Panel?',
463
+ 'ai.ask.commands': 'Which sideby commands are there for quota?',
463
464
  'pal.button': 'Search',
464
465
  'pal.title': 'Search sideby',
465
466
  'pal.placeholder': 'Find a page, setting or action…',
@@ -479,6 +480,19 @@ const en = {
479
480
  'pal.readOnly': 'Not in a read-only Panel',
480
481
  'pal.also': 'matches “{w}”',
481
482
  'pal.keys': '↑ ↓ to move · Enter to open · Esc to close',
483
+ 'cmds.button': 'Commands',
484
+ 'cmds.title': 'Commands',
485
+ 'cmds.intro': 'Everything the Panel does, you can also type in a terminal. Copy a command and paste it there.',
486
+ 'cmds.placeholder': 'Filter commands, in English or Chinese…',
487
+ 'cmds.common': 'Common',
488
+ 'cmds.none': 'No command matches “{q}”.',
489
+ 'cmds.feature': 'Search Panel features for “{q}”',
490
+ 'cmds.example': 'Example',
491
+ 'cmds.copy': 'Copy {text}',
492
+ 'cmds.copied': 'Copied',
493
+ 'cmds.open': 'Open in Panel',
494
+ 'cmds.openLabel': 'Open {what} in the Panel',
495
+ 'cmds.foot': 'Press ? anywhere to open this list · sideby commands in a terminal · Esc to close',
482
496
  'ask.button': 'Let AI do it',
483
497
  'ask.title': 'Let AI do it',
484
498
  'ask.title.fix': 'Let AI fix it',
@@ -2035,6 +2049,7 @@ const zh = {
2035
2049
  'ai.ask.api': '帮我加一个 DeepSeek API 账号。',
2036
2050
  'ai.ask.tool': '帮 sideby 支持一个新工具。',
2037
2051
  'ai.ask.find': '面板的语言在哪里改?',
2052
+ 'ai.ask.commands': 'sideby 有哪些和额度有关的命令?',
2038
2053
  'pal.button': '搜索',
2039
2054
  'pal.title': '搜索 sideby',
2040
2055
  'pal.placeholder': '查找页面、设置或操作…',
@@ -2054,6 +2069,19 @@ const zh = {
2054
2069
  'pal.readOnly': '只读面板里不能用',
2055
2070
  'pal.also': '匹配“{w}”',
2056
2071
  'pal.keys': '↑ ↓ 选择 · Enter 打开 · Esc 关闭',
2072
+ 'cmds.button': '命令',
2073
+ 'cmds.title': '命令',
2074
+ 'cmds.intro': '面板能做的事,在终端里也能敲命令完成。复制一条命令,粘贴到终端里运行。',
2075
+ 'cmds.placeholder': '筛选命令,中英文都行…',
2076
+ 'cmds.common': '常用',
2077
+ 'cmds.none': '没有匹配“{q}”的命令。',
2078
+ 'cmds.feature': '在面板功能里搜索“{q}”',
2079
+ 'cmds.example': '示例',
2080
+ 'cmds.copy': '复制 {text}',
2081
+ 'cmds.copied': '已复制',
2082
+ 'cmds.open': '在面板中打开',
2083
+ 'cmds.openLabel': '在面板中打开{what}',
2084
+ 'cmds.foot': '在任意位置按 ? 打开这个列表 · 终端里用 sideby commands · Esc 关闭',
2057
2085
  'ask.button': '让 AI 帮我',
2058
2086
  'ask.title': '让 AI 帮我',
2059
2087
  'ask.title.fix': '让 AI 修复',
@@ -1,5 +1,6 @@
1
1
  // The Panel page's inline script. Plain browser JavaScript in a string (no template literals inside, so String.raw
2
2
  // keeps it verbatim); the pure helpers from page-logic.ts are prepended so the tested code is the code that runs.
3
+ import { filterCommands } from '../core/cli-commands.js';
3
4
  import { groupsToAccept } from '../core/inbound.js';
4
5
  import { quotaIsStale } from '../core/quota-levels.js';
5
6
  import { remoteControlTodo } from '../core/remote-control.js';
@@ -10,6 +11,7 @@ const LOGIC = [
10
11
  catalogNorm,
11
12
  catalogMatchLevel,
12
13
  searchCatalog,
14
+ filterCommands,
13
15
  aiTaskAccounts,
14
16
  askBridge,
15
17
  askBridged,
@@ -1167,6 +1169,7 @@ const MAIN = String.raw `
1167
1169
  $('ask-ai').setAttribute('aria-label', t('ask.button'))
1168
1170
  $('search-btn').setAttribute('aria-label', t('pal.button') + ' (' + palKey() + ')')
1169
1171
  $('search-kbd').textContent = palKey()
1172
+ $('cmds-btn').setAttribute('aria-label', t('cmds.button') + ' (?)')
1170
1173
  const repo = $('repo')
1171
1174
  for (const k of ['aria-label', 'title']) repo.setAttribute(k, t('top.repo'))
1172
1175
  if (/^https:\/\/github\.com\//.test(BOOT.repoUrl || '')) { repo.href = BOOT.repoUrl; repo.hidden = false }
@@ -2856,8 +2859,9 @@ const MAIN = String.raw `
2856
2859
  // A wide dialog is wide before it opens, so it does not open narrow and then stretch.
2857
2860
  el.classList.toggle('dialog-wide', kind === 'settings' ? el.classList.contains('dialog-wide') : kind === 'history')
2858
2861
  // A dialog that grows as the user adds to it (screenshots, its result) keeps its top edge and grows downward.
2859
- el.classList.toggle('dialog-top', kind === 'send' || kind === 'palette')
2862
+ el.classList.toggle('dialog-top', kind === 'send' || kind === 'palette' || kind === 'commands')
2860
2863
  el.classList.toggle('dialog-pal', kind === 'palette')
2864
+ el.classList.toggle('dialog-cmds', kind === 'commands')
2861
2865
  if (!el.open) { el.showModal(); raiseToasts() }
2862
2866
  }
2863
2867
 
@@ -6551,6 +6555,7 @@ const MAIN = String.raw `
6551
6555
  'handoff-on': { run: () => setPage('handoff'), ok: () => Boolean(ahState()), nav: true },
6552
6556
  network: { run: openNet, ok: () => Boolean(netState()) },
6553
6557
  themes: { run: openThemes, ok: () => true },
6558
+ commands: { run: () => openCommands(), ok: () => true },
6554
6559
  update: { run: openUpdate, ok: () => Boolean(BOOT.updates) },
6555
6560
  ask: { run: () => openAsk(), ok: () => !askBridged(BOOT, window) },
6556
6561
  health: { run: palHealth, ok: () => Boolean(S.state && S.state.accounts.length), nav: true },
@@ -6594,15 +6599,18 @@ const MAIN = String.raw `
6594
6599
  return Boolean(a && a.ok())
6595
6600
  }
6596
6601
  function palWhyOff(e) { return e.target.action && e.target.write && BOOT.readOnly ? t('pal.readOnly') : '' }
6597
- function openPalette() {
6598
- if (dlg.el && dlg.el.open) return
6602
+ function openPalette(q) {
6603
+ // The Commands dialog hands its dialog over (its "Search Panel features" row); any other open dialog stays.
6604
+ if (dlg.el && dlg.el.open && dlg.kind !== 'commands') return
6599
6605
  closeMenu()
6600
- pal.q = ''
6606
+ cmd.els = null
6607
+ pal.q = typeof q === 'string' ? q : ''
6601
6608
  pal.sel = 0
6602
6609
  pal.all = false
6603
6610
  pal.found = palFindable()
6604
6611
  showDialog('palette')
6605
6612
  const input = h('input', { type: 'search', class: 'pal-input', role: 'combobox', 'aria-expanded': 'true', 'aria-controls': 'pal-list', 'aria-autocomplete': 'list', autocomplete: 'off', spellcheck: 'false', placeholder: t('pal.placeholder'), 'aria-label': t('pal.title') })
6613
+ input.value = pal.q
6606
6614
  input.addEventListener('input', () => { pal.q = input.value; pal.sel = 0; pal.all = false; drawPalette() })
6607
6615
  input.addEventListener('keydown', palKeys)
6608
6616
  const list = h('div', { id: 'pal-list', class: 'pal-list', role: 'listbox', 'aria-label': t('pal.title') })
@@ -6703,7 +6711,8 @@ const MAIN = String.raw `
6703
6711
  if (pal.q) { e.preventDefault(); pal.els.input.value = ''; pal.q = ''; pal.sel = 0; drawPalette() }
6704
6712
  }
6705
6713
  }
6706
- function palClose() { pal.els = null; if (dlg.kind === 'palette') dlg.el.close() }
6714
+ // Closes the palette, or the Commands dialog when its "Open in Panel" goes somewhere (both use palGo).
6715
+ function palClose() { pal.els = null; if (dlg.kind === 'palette' || dlg.kind === 'commands') dlg.el.close() }
6707
6716
  // Lights a row up once it is in view, so the eye finds it; none under reduced motion.
6708
6717
  function palFlash(el) {
6709
6718
  if (REDUCED || !el) return
@@ -6722,6 +6731,7 @@ const MAIN = String.raw `
6722
6731
  }
6723
6732
  function palGo(e) {
6724
6733
  palRemember(e.id)
6734
+ const from = dlg.kind
6725
6735
  const g = e.target
6726
6736
  pal.els = null
6727
6737
  if (g.page) { palClose(); setPage(g.page); window.scrollTo({ top: 0, behavior: REDUCED ? 'auto' : 'smooth' }); return }
@@ -6745,8 +6755,9 @@ const MAIN = String.raw `
6745
6755
  const a = PALETTE_ACTIONS[g.action]
6746
6756
  if (a.nav) palClose()
6747
6757
  a.run()
6748
- // An action that opened nothing (such as a task handed to the Portal) leaves no palette behind.
6749
- if (dlg.kind === 'palette') palClose()
6758
+ // An action that opened nothing (such as a task handed to the Portal) leaves no palette or Commands dialog behind;
6759
+ // one that opened its own dialog in their place (the palette's Commands action too) keeps it.
6760
+ if (dlg.kind === from && (from === 'palette' || from === 'commands')) palClose()
6750
6761
  }
6751
6762
  // The words go to Session History's search box, which reads them as it does typed ones.
6752
6763
  function palHistory(q) {
@@ -6760,6 +6771,92 @@ const MAIN = String.raw `
6760
6771
  setPage('sessions')
6761
6772
  }
6762
6773
 
6774
+ // ---------- Command List (spec §3.38, ADR-0061) ----------
6775
+ // The Commands button, ? and the palette open every sideby command by task, from the Command List that
6776
+ // sideby --help and sideby commands print too. Each row copies its command (the example when there is one, so it runs
6777
+ // as it is); a command with a place in the Panel also goes there, through the palette's own navigation.
6778
+ const CMDS = JSON.parse(document.getElementById('sideby-commands').textContent)
6779
+ const cmd = { q: '', els: null, found: null }
6780
+ function openCommands() {
6781
+ // The palette hands its dialog over (its Commands action); any other open dialog stays.
6782
+ if (dlg.el && dlg.el.open && dlg.kind !== 'palette') return
6783
+ closeMenu()
6784
+ pal.els = null
6785
+ cmd.q = ''
6786
+ cmd.found = palFindable()
6787
+ showDialog('commands')
6788
+ const input = h('input', { type: 'search', class: 'pal-input', autocomplete: 'off', spellcheck: 'false', placeholder: t('cmds.placeholder'), 'aria-label': t('cmds.placeholder'), 'aria-controls': 'cmd-list' })
6789
+ input.addEventListener('input', () => { cmd.q = input.value; drawCommands() })
6790
+ input.addEventListener('keydown', (e) => {
6791
+ // Escape first empties the box, as in the palette; a second one closes.
6792
+ if (e.key === 'Escape' && cmd.q) { e.preventDefault(); input.value = ''; cmd.q = ''; drawCommands() }
6793
+ else if (e.key === 'ArrowDown') {
6794
+ const b = cmd.els && cmd.els.list.querySelector('button')
6795
+ if (b) { e.preventDefault(); b.focus() }
6796
+ }
6797
+ })
6798
+ const list = h('div', { id: 'cmd-list', class: 'cmd-list' })
6799
+ cmd.els = { input, list }
6800
+ setKids(dlg.el, [
6801
+ h('h2', { id: 'dlg-title', class: 'sr-only' }, t('cmds.title')),
6802
+ h('div', { class: 'pal-head' }, icon('terminal', 'pal-ic'), input, h('kbd', { class: 'kbd-inline', 'aria-hidden': 'true' }, 'Esc')),
6803
+ list,
6804
+ h('div', { class: 'pal-foot muted small', 'aria-hidden': 'true' }, t('cmds.foot')),
6805
+ ])
6806
+ drawCommands()
6807
+ input.focus()
6808
+ }
6809
+ function drawCommands() {
6810
+ if (!cmd.els) return
6811
+ const q = cmd.q.trim()
6812
+ const kids = []
6813
+ if (!q) {
6814
+ kids.push(h('p', { class: 'cmd-intro muted small' }, t('cmds.intro')))
6815
+ kids.push(cmdGroup(t('cmds.common'), CMDS.commands.filter((c) => c.common).sort((a, b) => a.common - b.common)))
6816
+ }
6817
+ const hits = filterCommands(q, CMDS.commands, CMDS.groups)
6818
+ for (const g of CMDS.groups) {
6819
+ const list = hits.filter((c) => c.group === g.id)
6820
+ if (list.length) kids.push(cmdGroup(g.title[lang] || g.title.en, list))
6821
+ }
6822
+ if (q && !hits.length)
6823
+ kids.push(h('div', { class: 'cmd-none' }, h('p', { class: 'muted' }, t('cmds.none', { q })),
6824
+ h('button', { class: 'link-btn', type: 'button', onclick: () => openPalette(q) }, icon('search'), ' ', t('cmds.feature', { q }))))
6825
+ cmd.els.list.replaceChildren(...kids)
6826
+ cmd.els.list.scrollTop = 0
6827
+ }
6828
+ function cmdGroup(title, list) {
6829
+ return h('section', { class: 'cmd-group', 'aria-label': title },
6830
+ h('h3', { class: 'pal-group' }, title),
6831
+ h('ul', { class: 'cmd-rows' }, list.map(cmdRow)))
6832
+ }
6833
+ // The copy button sits next to what it copies: the example when there is one, else the command itself.
6834
+ function cmdCopyBtn(text) {
6835
+ const b = h('button', { class: 'icon-btn cmd-copy', type: 'button', 'aria-label': t('cmds.copy', { text }), 'data-tip': t('btn.copy') })
6836
+ b.append(icon('copy'))
6837
+ b.addEventListener('click', async () => {
6838
+ await copyText(text)
6839
+ b.replaceChildren(icon('tick'))
6840
+ b.classList.add('is-done')
6841
+ b.setAttribute('data-tip', t('cmds.copied'))
6842
+ setTimeout(() => { b.replaceChildren(icon('copy')); b.classList.remove('is-done'); b.setAttribute('data-tip', t('btn.copy')) }, 1400)
6843
+ })
6844
+ return b
6845
+ }
6846
+ function cmdRow(c) {
6847
+ const e = c.feature ? CATALOG.entries.find((x) => x.id === c.feature) : null
6848
+ // "Open in Panel" only where this Panel has the place now, never for this list itself.
6849
+ const go = e && !(e.target.action === 'commands') && palAvailable(e, cmd.found) && !palWhyOff(e) ? e : null
6850
+ const what = go ? go.title[lang] || go.title.en : ''
6851
+ return h('li', { class: 'cmd-row' },
6852
+ h('div', { class: 'cmd-line' },
6853
+ h('code', { class: 'cmd-usage' }, c.usage),
6854
+ go ? h('button', { class: 'link-btn cmd-open', type: 'button', 'aria-label': t('cmds.openLabel', { what }), onclick: () => palGo(go) }, t('cmds.open')) : null,
6855
+ c.example ? null : cmdCopyBtn(c.usage)),
6856
+ h('div', { class: 'cmd-desc' }, c.summary[lang] || c.summary.en),
6857
+ c.example ? h('div', { class: 'cmd-ex' }, h('span', { class: 'cmd-ex-label' }, t('cmds.example')), h('code', null, c.example), cmdCopyBtn(c.example)) : null)
6858
+ }
6859
+
6763
6860
  // ---------- start at login (spec §3.29, ADR-0029) and the Menu Bar Item (spec §3.31, ADR-0034) ----------
6764
6861
  // Each switch reads its state when the settings open; moving it shows the file and what will run, and only the
6765
6862
  // confirmation writes. A read-only Panel shows the state only. mb.* words override as.* for the menu bar.
@@ -7084,7 +7181,7 @@ const MAIN = String.raw `
7084
7181
  return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
7085
7182
  }
7086
7183
  // Example phrases: a click puts one in the Let AI do it box (spec §3.28).
7087
- const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.tool']
7184
+ const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.commands', 'ai.ask.tool']
7088
7185
  // Network Guard (spec §3.35): one dialog with the switch, the allowed countries and the newest result per address.
7089
7186
  // Countries are never ticked for the user, the current one included: a wrong network would allow itself.
7090
7187
  const NET_COMMON = ['US', 'JP', 'SG', 'GB', 'DE', 'FR', 'NL', 'CA', 'AU', 'KR', 'TW', 'HK']
@@ -8638,6 +8735,7 @@ const MAIN = String.raw `
8638
8735
  $('refresh').addEventListener('click', refreshAll)
8639
8736
  $('ask-ai').addEventListener('click', () => openAsk())
8640
8737
  $('search-btn').addEventListener('click', () => openPalette())
8738
+ $('cmds-btn').addEventListener('click', () => openCommands())
8641
8739
  // Cmd/Ctrl+K opens the Command Palette from anywhere and closes it again; / and Cmd/Ctrl+F stay on the account search.
8642
8740
  document.addEventListener('keydown', (e) => {
8643
8741
  if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey || (e.key !== 'k' && e.key !== 'K')) return
@@ -8645,6 +8743,17 @@ const MAIN = String.raw `
8645
8743
  e.preventDefault()
8646
8744
  openPalette()
8647
8745
  })
8746
+ // ? opens the Command List (as GitHub and Linear open their shortcut lists), and closes it again; typing a ? in a
8747
+ // field stays typing.
8748
+ document.addEventListener('keydown', (e) => {
8749
+ if (e.key !== '?' || e.metaKey || e.ctrlKey || e.altKey || e.defaultPrevented) return
8750
+ const el = e.target
8751
+ if (el && (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT' || el.isContentEditable)) return
8752
+ if (dlg.el && dlg.el.open) { if (dlg.kind === 'commands') { e.preventDefault(); dlg.el.close() } return }
8753
+ if (menu.el) return
8754
+ e.preventDefault()
8755
+ openCommands()
8756
+ })
8648
8757
  // In a Portal that offers AI Tasks itself the Portal has the button; opened on its own, the Panel keeps it.
8649
8758
  $('ask-ai').hidden = askBridged(BOOT, window)
8650
8759
  $('accounts').addEventListener('dragover', onDragOver)
@@ -1387,6 +1387,24 @@ input.ua-time::placeholder { color: var(--faint); }
1387
1387
  .pal-none { padding: 14px 10px 4px; margin: 0; }
1388
1388
  .pal-foot { padding: 8px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
1389
1389
  [data-width=narrow] .pal-where, [data-width=narrow] .pal-foot { display: none; }
1390
+ .dialog.dialog-cmds { width: min(760px, calc(100vw - 24px)); flex-direction: column; }
1391
+ .cmd-list { overflow-y: auto; overscroll-behavior: contain; padding: 4px 6px 10px; height: min(62vh, 560px); }
1392
+ .cmd-intro { margin: 8px 10px 2px; }
1393
+ .cmd-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
1394
+ .cmd-row { display: flex; flex-direction: column; gap: 2px; padding: 7px 10px; border-top: 1px solid var(--border); }
1395
+ .cmd-row:first-child { border-top: 0; }
1396
+ .cmd-line, .cmd-ex { display: flex; align-items: center; gap: 8px; min-width: 0; }
1397
+ .cmd-usage { flex: 1; min-width: 0; color: var(--text); font-weight: var(--strong-weight); overflow-wrap: anywhere; }
1398
+ .cmd-desc { color: var(--muted); font-size: var(--small); }
1399
+ .cmd-ex { font-size: 12px; color: var(--muted); }
1400
+ .cmd-ex code { min-width: 0; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; overflow-wrap: anywhere; }
1401
+ .cmd-ex-label { flex: none; }
1402
+ .cmd-open { flex: none; font-size: var(--small); }
1403
+ .cmd-copy { flex: none; }
1404
+ .cmd-copy.is-done { color: var(--ok); }
1405
+ .cmd-none { padding: 14px 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
1406
+ .cmd-none p { margin: 0; }
1407
+ .cmd-none .link-btn { display: inline-flex; align-items: center; gap: 4px; }
1390
1408
  .find-flash { animation: find-flash 1.2s ease-out; border-radius: var(--ctl-radius); }
1391
1409
  @keyframes find-flash { 0%, 35% { box-shadow: 0 0 0 6px var(--accent-soft); background: var(--accent-soft); } to { box-shadow: 0 0 0 6px transparent; background: transparent; } }
1392
1410
  @media (prefers-reduced-motion: reduce) { .find-flash { animation: none; } .pal-opt { transition: none; } }
@@ -3,6 +3,7 @@
3
3
  // i18n.ts (English and Chinese text); this module assembles them under the CSP nonce.
4
4
  import { createHash } from 'node:crypto';
5
5
  import { FAVICON_SVG, MARK_SVG } from '../core/brand-mark.js';
6
+ import { commandListForPage } from '../core/cli-commands.js';
6
7
  import { ALIAS_NAME, RESERVED_ALIASES } from '../core/config.js';
7
8
  import { QUOTA_FAIL_PERCENT, QUOTA_WARN_PERCENT, USAGE_DAYS } from '../core/quota-levels.js';
8
9
  import { COMMON_ENTRIES, SEARCH_CATALOG } from '../core/search-catalog.js';
@@ -93,6 +94,7 @@ export function renderPage(opts) {
93
94
  <button id="ua-badge" class="btn ua-badge" type="button" hidden></button>
94
95
  <button id="update" class="btn update-btn" type="button" hidden></button>
95
96
  <button id="search-btn" class="btn" type="button" aria-haspopup="dialog" aria-label="Search"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4.2-4.2"/></svg><span class="hide-sm" data-i18n="pal.button">Search</span><kbd id="search-kbd" class="kbd-inline hide-sm" aria-hidden="true"></kbd></button>
97
+ <button id="cmds-btn" class="btn" type="button" aria-haspopup="dialog" aria-label="Commands (?)"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 17l6-5-6-5M12 19h8"/></svg><span class="hide-sm" data-i18n="cmds.button">Commands</span><kbd class="kbd-inline hide-sm" aria-hidden="true">?</kbd></button>
96
98
  <button id="ask-ai" class="btn" type="button" aria-haspopup="dialog" aria-label="Let AI do it"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9h12a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2zM12 5v4M9.5 13.5v1M14.5 13.5v1"/></svg><span class="hide-sm" data-i18n="ask.button">Let AI do it</span></button>
97
99
  <a id="repo" class="icon-btn repo-link" target="_blank" rel="noopener noreferrer" aria-label="sideby on GitHub" title="sideby on GitHub" hidden><svg viewBox="0 0 24 24" aria-hidden="true"><path d="${GITHUB_MARK}"/></svg></a>
98
100
  <button id="settings" class="btn" type="button" aria-haspopup="dialog" aria-expanded="false"${lang === 'auto' ? '' : ' hidden'}><span data-i18n="set.button">Settings</span></button>
@@ -123,6 +125,7 @@ export function renderPage(opts) {
123
125
  <div id="toasts" class="toasts" aria-live="polite" popover="manual"></div>
124
126
  <script type="application/json" id="sideby-boot">${boot}</script>
125
127
  <script type="application/json" id="sideby-catalog">${jsonForScript({ entries: SEARCH_CATALOG, common: COMMON_ENTRIES })}</script>
128
+ <script type="application/json" id="sideby-commands">${jsonForScript(commandListForPage())}</script>
126
129
  <script type="application/json" id="sideby-i18n">${jsonForScript(MESSAGES)}</script>
127
130
  <script${nonce}>${PAGE_SCRIPT}</script>
128
131
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sideby",
3
- "version": "0.31.2",
3
+ "version": "0.31.3",
4
4
  "description": "Run work, personal and API-key accounts at the same time, without their configs drifting apart.",
5
5
  "license": "MIT",
6
6
  "author": "Adonis0123 (https://github.com/Adonis0123)",