@chatcode/cco-better-sidebar 0.18.0-alpha.3 → 0.18.0-rc.11
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/README.md +24 -5
- package/README_EN.md +24 -5
- package/cordis.patch.yml +6 -5
- package/lib/client-editor.js +10919 -362
- package/lib/client-mermaid.js +10810 -275
- package/lib/client-registry.js +3760 -2145
- package/lib/client-terminal.js +402 -261
- package/lib/client.js +3758 -2143
- package/lib/index.js +264 -46
- package/lib/types/client/LogoutConfirmDialog.d.ts +5 -0
- package/lib/types/client/PluginMarketSettingsSection.d.ts +7 -0
- package/lib/types/client/PluginMarketView.d.ts +7 -0
- package/lib/types/client/PluginProjectPicker.d.ts +13 -0
- package/lib/types/client/api.d.ts +17 -0
- package/lib/types/client/builtins/tabs.d.ts +13 -1
- package/lib/types/client/icons.d.ts +26 -8
- package/lib/types/client/locales.d.ts +39 -0
- package/lib/types/client/plugin-market-catalog.d.ts +25 -0
- package/lib/types/client/service.d.ts +1 -1
- package/lib/types/client/ui-tweaks/archive.d.ts +3 -7
- package/lib/types/client/ui-tweaks/branding.d.ts +1 -1
- package/lib/types/client/ui-tweaks/index.d.ts +3 -3
- package/lib/types/client/ui-tweaks/sidebar-header.d.ts +6 -0
- package/lib/types/client/ui-tweaks/typography.d.ts +9 -0
- package/lib/types/config.d.ts +4 -3
- package/lib/types/context-types.d.ts +12 -14
- package/lib/types/login-page-script.d.ts +2 -0
- package/lib/types/login-route.d.ts +2 -0
- package/lib/types/plugin-market-api.d.ts +5 -0
- package/lib/types/plugin-market-shared.d.ts +59 -0
- package/lib/types/prefs-shared.d.ts +1 -1
- package/lib/types/pty-deps.d.ts +1 -1
- package/lib/types/ui-tweaks/config.d.ts +6 -7
- package/lib/types/ui-tweaks/index.d.ts +2 -3
- package/package.json +4 -3
- package/src/client/AccountMenu.tsx +12 -2
- package/src/client/BrowserView.tsx +1 -1
- package/src/client/DiffTab.tsx +1 -1
- package/src/client/EditorHost.tsx +1 -1
- package/src/client/FileTree.tsx +10 -5
- package/src/client/FreeWindow.tsx +2 -1
- package/src/client/GitView.tsx +7 -3
- package/src/client/LogoutConfirmDialog.tsx +39 -0
- package/src/client/PluginMarketSettingsSection.tsx +55 -0
- package/src/client/PluginMarketView.module.css +50 -0
- package/src/client/PluginMarketView.tsx +243 -0
- package/src/client/PluginProjectPicker.tsx +73 -0
- package/src/client/SideCardSection.tsx +2 -23
- package/src/client/Sidebar.tsx +2 -2
- package/src/client/TabBar.tsx +2 -4
- package/src/client/TextEditor.tsx +2 -1
- package/src/client/TreePanel.tsx +1 -2
- package/src/client/UsageHeatmapSection.tsx +1 -1
- package/src/client/api.ts +9 -0
- package/src/client/builtins/tabs.tsx +25 -5
- package/src/client/builtins/viewers.tsx +2 -1
- package/src/client/icons.tsx +57 -4
- package/src/client/index.tsx +10 -1
- package/src/client/intercept.tsx +1 -1
- package/src/client/locales-ja.ts +39 -0
- package/src/client/locales.ts +118 -1
- package/src/client/md-toc.tsx +1 -1
- package/src/client/mermaid.tsx +2 -1
- package/src/client/open-with-settings.tsx +1 -1
- package/src/client/plugin-market-catalog.ts +90 -0
- package/src/client/service.ts +1 -1
- package/src/client/sidebar.module.css +81 -19
- package/src/client/ui-tweaks/archive.tsx +6 -56
- package/src/client/ui-tweaks/branding.tsx +80 -28
- package/src/client/ui-tweaks/index.tsx +45 -108
- package/src/client/ui-tweaks/sidebar-header.ts +73 -0
- package/src/client/ui-tweaks/typography.ts +38 -0
- package/src/config.ts +22 -2
- package/src/context-types.ts +5 -15
- package/src/index.ts +24 -20
- package/src/login-page-script.ts +107 -0
- package/src/login-route.ts +7 -4
- package/src/plugin-market-api.ts +88 -0
- package/src/plugin-market-shared.ts +30 -0
- package/src/prefs-shared.ts +1 -1
- package/src/pty-deps.ts +2 -2
- package/src/ui-tweaks/config.ts +12 -12
- package/src/ui-tweaks/index.ts +7 -13
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Compact sidebar chrome; the host retains every button, shortcut and drag surface. */
|
|
2
|
+
export const SIDEBAR_HEADER_CSS = `
|
|
3
|
+
.dut-sidebar-header{height:44px !important;padding:0 4px !important;margin-bottom:8px !important;gap:8px !important}
|
|
4
|
+
.dut-sidebar-brand{min-width:0 !important;background:transparent !important;box-shadow:none !important}
|
|
5
|
+
.dut-sidebar-identity{height:24px !important;gap:8px !important}
|
|
6
|
+
.dut-sidebar-wordmark{font:var(--dsw-font-s-strong-14) !important;letter-spacing:-.01em !important;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
7
|
+
.dut-sidebar-toggle{width:28px !important;height:28px !important;border-radius:8px !important;color:var(--dsw-alias-label-secondary) !important}
|
|
8
|
+
.dut-sidebar-toggle:hover{background:var(--dsw-alias-interactive-bg-hover) !important}
|
|
9
|
+
/* Reuse the original ChatCode primary-action red, scoped to this marked CTA. */
|
|
10
|
+
.dut-sidebar-new-session{height:40px !important;justify-content:flex-start !important;gap:8px !important;margin:0 0 10px !important;padding:8px 10px !important;border:1px solid #9B0B09 !important;border-radius:10px !important;background:linear-gradient(135deg,#9B0B09,#b71916) !important;color:#fff !important;font:var(--dsw-font-s-strong-14) !important;font-weight:600 !important;box-shadow:none !important;transform:none !important}
|
|
11
|
+
.dut-sidebar-new-session:hover{background:linear-gradient(135deg,#b71916,#cf302c) !important}
|
|
12
|
+
.dut-sidebar-new-session:active{background:#9B0B09 !important}
|
|
13
|
+
.dut-sidebar-new-session:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
|
|
14
|
+
.dut-sidebar-new-session > span:first-child{flex:1;min-width:0;overflow:hidden;mask-image:none !important}
|
|
15
|
+
.dut-sidebar-new-session > span:first-child > span{width:auto !important;justify-content:flex-start !important;gap:8px !important;min-width:0}
|
|
16
|
+
.dut-sidebar-new-session > span:first-child > span > svg{width:16px;height:16px;flex:none;color:inherit}
|
|
17
|
+
.dut-sidebar-new-session > span:first-child > span > span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
18
|
+
.dut-sidebar-new-session > span + span{opacity:1 !important;flex:none;color:color-mix(in srgb,currentColor 75%,transparent);font:var(--dsw-font-xxs-12)}
|
|
19
|
+
/* Temporary navigation-only hide. Remove this block to restore Plugins;
|
|
20
|
+
registrations, settings, installed plugins and other panel entries stay intact. */
|
|
21
|
+
nav:is([aria-label="全局面板"],[aria-label="Global panels"]) > button:is([aria-label="插件"],[aria-label="Plugins"]),
|
|
22
|
+
nav:is([aria-label="全局面板"],[aria-label="Global panels"]):has(> button:is([aria-label="插件"],[aria-label="Plugins"]):only-child){display:none !important}
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
const HEADER_CLASSES = [
|
|
26
|
+
'dut-sidebar-header', 'dut-sidebar-brand', 'dut-sidebar-identity',
|
|
27
|
+
'dut-sidebar-wordmark', 'dut-sidebar-toggle', 'dut-sidebar-new-session',
|
|
28
|
+
] as const
|
|
29
|
+
type HeaderClass = typeof HEADER_CLASSES[number]
|
|
30
|
+
|
|
31
|
+
/** Mark only the expanded brand row and its adjacent native New Session button. */
|
|
32
|
+
export function syncSidebarHeader(): void {
|
|
33
|
+
const desired = new Map<HTMLElement, Set<HeaderClass>>()
|
|
34
|
+
const mark = (element: Element | null | undefined, className: HeaderClass): void => {
|
|
35
|
+
if (!(element instanceof HTMLElement)) return
|
|
36
|
+
const classes = desired.get(element) ?? new Set<HeaderClass>()
|
|
37
|
+
classes.add(className)
|
|
38
|
+
desired.set(element, classes)
|
|
39
|
+
}
|
|
40
|
+
for (const name of document.querySelectorAll<HTMLElement>('.dut-sidebar-brand-name,.dut-brand-title')) {
|
|
41
|
+
const row = name.closest<HTMLElement>('[data-window-drag]')
|
|
42
|
+
const logo = row?.querySelector('.dut-sidebar-logo,.dut-left-logo')
|
|
43
|
+
if (!row || !logo) continue
|
|
44
|
+
const brand = [...row.children].find(child => child.contains(name) && child.contains(logo))
|
|
45
|
+
if (!brand) continue
|
|
46
|
+
mark(row, 'dut-sidebar-header')
|
|
47
|
+
mark(brand, 'dut-sidebar-brand')
|
|
48
|
+
mark(logo.closest('[class*="brandIdentity"]'), 'dut-sidebar-identity')
|
|
49
|
+
mark(name, 'dut-sidebar-wordmark')
|
|
50
|
+
for (const button of row.querySelectorAll('button')) {
|
|
51
|
+
if (!brand.contains(button) && button !== brand) mark(button, 'dut-sidebar-toggle')
|
|
52
|
+
}
|
|
53
|
+
// The host renders this native action directly after the drag row. Do
|
|
54
|
+
// not infer a new action from arbitrary text in another panel or dialog.
|
|
55
|
+
const next = row.nextElementSibling
|
|
56
|
+
if (next instanceof HTMLButtonElement) mark(next, 'dut-sidebar-new-session')
|
|
57
|
+
}
|
|
58
|
+
// A collapsed rail no longer has a wordmark. Remove expanded-only styling
|
|
59
|
+
// without changing the host's rail geometry or its logo/expand interaction.
|
|
60
|
+
for (const className of HEADER_CLASSES) {
|
|
61
|
+
for (const element of document.querySelectorAll<HTMLElement>(`.${className}`)) {
|
|
62
|
+
if (!desired.get(element)?.has(className)) element.classList.remove(className)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const [element, classes] of desired) element.classList.add(...classes)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Restore native header styling when the branding effect is disposed. */
|
|
69
|
+
export function clearSidebarHeader(): void {
|
|
70
|
+
for (const className of HEADER_CLASSES) {
|
|
71
|
+
for (const element of document.querySelectorAll(`.${className}`)) element.classList.remove(className)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Font overrides for the conversation, preserving the live theme families. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Apply the UI Tweaks size and spacing preferences to the host's prose tokens.
|
|
5
|
+
* @param fontSize - Selected body size in pixels.
|
|
6
|
+
* @param lineHeight - Vertical-spacing unit; 16 retains the normal rhythm.
|
|
7
|
+
* @param codeFontSize - Selected code-block size in pixels.
|
|
8
|
+
* @returns Theme-token overrides for a runtime stylesheet.
|
|
9
|
+
*/
|
|
10
|
+
export function buildFontCss(fontSize: number, lineHeight: number, codeFontSize: number): string {
|
|
11
|
+
const parts: string[] = []
|
|
12
|
+
const base = 'var(--dsw-font-markdown-base-font-family, var(--dsw-font-family))'
|
|
13
|
+
const code = 'var(--dsw-font-markdown-code-block-font-family, var(--ds-font-family-code))'
|
|
14
|
+
const token = (name: string, size: number, leading: number, family: string, weight = 400, style = 'normal'): void => {
|
|
15
|
+
const line = Math.max(12, Math.round(leading * (lineHeight / 16)))
|
|
16
|
+
parts.push(`--${name}:${style} ${weight} ${size}px/${line}px ${family}`)
|
|
17
|
+
parts.push(`--${name}-font-size:${size}px`)
|
|
18
|
+
parts.push(`--${name}-line-height:${line}px`)
|
|
19
|
+
parts.push(`--${name}-font-weight:${weight}`)
|
|
20
|
+
parts.push(`--${name}-font-style:${style}`)
|
|
21
|
+
}
|
|
22
|
+
const bodyLine = fontSize + 10
|
|
23
|
+
token('dsw-font-markdown-base', fontSize, bodyLine, base)
|
|
24
|
+
token('dsw-font-markdown-base-strong', fontSize, bodyLine, base, 600)
|
|
25
|
+
token('dsw-font-markdown-base-italic', fontSize, bodyLine, base, 400, 'italic')
|
|
26
|
+
token('dsw-font-markdown-base-strong-italic', fontSize, bodyLine, base, 600, 'italic')
|
|
27
|
+
token('dsw-font-markdown-h1', fontSize + 4, bodyLine + 4, base, 600)
|
|
28
|
+
token('dsw-font-markdown-h2', fontSize + 2, bodyLine + 2, base, 600)
|
|
29
|
+
token('dsw-font-markdown-h3', fontSize + 1, bodyLine + 1, base, 600)
|
|
30
|
+
token('dsw-font-markdown-h4', fontSize, bodyLine, base, 600)
|
|
31
|
+
token('dsw-font-markdown-table', fontSize, bodyLine, base)
|
|
32
|
+
token('dsw-font-markdown-table-head', fontSize, bodyLine, base, 500)
|
|
33
|
+
token('dsw-font-markdown-code', codeFontSize, codeFontSize + 7,
|
|
34
|
+
'var(--dsw-font-markdown-code-font-family, var(--ds-font-family-code))')
|
|
35
|
+
token('dsw-font-markdown-code-block', codeFontSize, codeFontSize + 7, code)
|
|
36
|
+
token('dsw-font-markdown-code-block-small', Math.max(8, codeFontSize - 2), codeFontSize + 3, code)
|
|
37
|
+
return `body{${parts.join(';')}}`
|
|
38
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import z from 'schemastery'
|
|
9
|
+
import { Config as UITweaksSchema, type UITweaksConfig } from './ui-tweaks/config.ts'
|
|
9
10
|
import {
|
|
10
11
|
SIDEBAR_PREFS_DEFAULTS,
|
|
11
12
|
SIDEBAR_PREFS_NS,
|
|
@@ -37,7 +38,7 @@ export {
|
|
|
37
38
|
} from './prefs-shared.ts'
|
|
38
39
|
|
|
39
40
|
/** Tunable sidebar host limits (every field optional; defaults fill in). */
|
|
40
|
-
export interface SidebarConfig {
|
|
41
|
+
export interface SidebarConfig extends Partial<SidebarPrefs>, UITweaksConfig {
|
|
41
42
|
/** Read cap of one text file (bytes); larger files return truncated. */
|
|
42
43
|
readLimit?: number
|
|
43
44
|
/** Media route cap (bytes); larger binaries are refused. */
|
|
@@ -88,7 +89,7 @@ export interface CodingPlanConfig {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/** Schemastery schema for the plugin configuration. */
|
|
91
|
-
|
|
92
|
+
const HostConfig = z.object({
|
|
92
93
|
readLimit: z.number().step(1).min(1).default(512 * 1024),
|
|
93
94
|
mediaLimit: z.number().step(1).min(1).default(20 * 1024 * 1024),
|
|
94
95
|
uploadLimit: z.number().step(1).min(1).default(128 * 1024 * 1024),
|
|
@@ -205,3 +206,22 @@ export const PrefsSchema: z<SidebarPrefs> = z.object({
|
|
|
205
206
|
// keys as unknown schema fields.
|
|
206
207
|
pluginSettings: z.dict(z.dict(z.any())).default({}),
|
|
207
208
|
})
|
|
209
|
+
|
|
210
|
+
function live<T>(schema: z<T>): z<T> {
|
|
211
|
+
Reflect.set(schema.meta, 'volatile', true)
|
|
212
|
+
return schema
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function liveFields(schema: z): Record<string, z> {
|
|
216
|
+
if (schema.type !== 'object' || schema.dict === undefined) {
|
|
217
|
+
throw new TypeError('Live settings schema must be an object')
|
|
218
|
+
}
|
|
219
|
+
return Object.fromEntries(Object.entries(schema.dict).map(([key, field]) => [key, live(field)]))
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** One entry schema: deployment fields stay fixed while sidebar and UI preferences are live-editable. */
|
|
223
|
+
export const Config = z.object({
|
|
224
|
+
...HostConfig.dict,
|
|
225
|
+
...liveFields(PrefsSchema),
|
|
226
|
+
...liveFields(UITweaksSchema),
|
|
227
|
+
}) as z<SidebarConfig>
|
package/src/context-types.ts
CHANGED
|
@@ -446,22 +446,10 @@ export interface SidebarInvariantsService {
|
|
|
446
446
|
): () => void
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
-
/** The settings service face (mirror of @deepseek-ai/dsh-settings'
|
|
449
|
+
/** The settings service face (mirror of @deepseek-ai/dsh-settings' SettingsForms). */
|
|
450
450
|
export interface SidebarSettingsService {
|
|
451
|
-
/**
|
|
452
|
-
|
|
453
|
-
* then the composition base, then the user document).
|
|
454
|
-
*/
|
|
455
|
-
register<T>(
|
|
456
|
-
ns: string,
|
|
457
|
-
schema: unknown,
|
|
458
|
-
options?: { base?: Partial<T>; applies?: 'live' | 'restart' },
|
|
459
|
-
): {
|
|
460
|
-
get(): T
|
|
461
|
-
watch(callback: (next: T, prev: T) => void | Promise<void>): () => void
|
|
462
|
-
update(patch: object): Promise<void>
|
|
463
|
-
replace(section: object): Promise<void>
|
|
464
|
-
}
|
|
451
|
+
/** Whether the active profile accepts form edits. */
|
|
452
|
+
readonly writable: boolean
|
|
465
453
|
/** Redacted descriptors of every registered namespace (secrets stripped). */
|
|
466
454
|
describe(options?: { redactSecrets?: boolean }): Array<{
|
|
467
455
|
ns: string
|
|
@@ -473,6 +461,8 @@ export interface SidebarSettingsService {
|
|
|
473
461
|
}>
|
|
474
462
|
/** Service-level merge write with the revision guard (a stale writer is refused). */
|
|
475
463
|
update(ns: string, patch: object, expectedRevision?: number): Promise<void>
|
|
464
|
+
/** Apply path edits without restating fields hidden from the caller. */
|
|
465
|
+
mutate(ns: string, ops: readonly ({ op: 'set'; path: readonly string[]; value: unknown } | { op: 'unset'; path: readonly string[] })[], expectedRevision?: number): Promise<void>
|
|
476
466
|
}
|
|
477
467
|
|
|
478
468
|
/**
|
package/src/index.ts
CHANGED
|
@@ -21,7 +21,6 @@ import { WebSocket, WebSocketServer } from 'ws'
|
|
|
21
21
|
import type { Context, SidebarHttpRequest } from './context-types.ts'
|
|
22
22
|
import {
|
|
23
23
|
Config,
|
|
24
|
-
PrefsSchema,
|
|
25
24
|
resolveSidebarConfig,
|
|
26
25
|
SIDEBAR_PREFS_DEFAULTS,
|
|
27
26
|
SIDEBAR_PREFS_NS,
|
|
@@ -55,6 +54,7 @@ import { CodingPlanCatalogue } from './codingplan.ts'
|
|
|
55
54
|
import { checkOneUpdate, CHATCODE_UPDATE_PACKAGES, performAllUpdates } from './chatcode-update.ts'
|
|
56
55
|
import { readJsonBody, requireString, SidebarError, writeError, writeJson, writeOk } from './wire.ts'
|
|
57
56
|
import { apply as applyUiTweaksHost } from './ui-tweaks/index.ts'
|
|
57
|
+
import { buildPluginMarketApi } from './plugin-market-api.ts'
|
|
58
58
|
|
|
59
59
|
export { Config }
|
|
60
60
|
export type { SidebarConfig, ResolvedSidebarConfig }
|
|
@@ -492,6 +492,7 @@ function buildApi(
|
|
|
492
492
|
const { sessionId, cwd } = await cwdOf(payload)
|
|
493
493
|
return { sessionId, cwd, root: rootLabel(cwd), parent: parentOf(cwd) ?? null }
|
|
494
494
|
},
|
|
495
|
+
...buildPluginMarketApi(ctx, cwdOf),
|
|
495
496
|
'fs.tree': async (payload) => {
|
|
496
497
|
const { cwd } = await cwdOf(payload)
|
|
497
498
|
const record = payload as { path?: unknown }
|
|
@@ -829,9 +830,8 @@ function buildApi(
|
|
|
829
830
|
* {@link resolveSidebarConfig}.
|
|
830
831
|
*/
|
|
831
832
|
export function apply(ctx: Context, config?: SidebarConfig): void {
|
|
832
|
-
// dsh-ui-tweaks is embedded as an intact feature module. Its
|
|
833
|
-
//
|
|
834
|
-
// settings.yaml values and browser behavior carry over without migration.
|
|
833
|
+
// dsh-ui-tweaks is embedded as an intact feature module. Its routes stay
|
|
834
|
+
// unchanged while its live fields share this entry's generated settings form.
|
|
835
835
|
// Cordis honours the root `inject` list in production. Keeping this guard
|
|
836
836
|
// lets lightweight embedders that call apply() directly retain the sidebar
|
|
837
837
|
// subset when they intentionally omit the settings service.
|
|
@@ -886,8 +886,8 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
|
|
|
886
886
|
void codingPlanCatalogue.refresh().catch(() => { /* catalogue returns a safe unavailable snapshot */ })
|
|
887
887
|
|
|
888
888
|
// ── User-facing "Side card" preferences ──────────────────────────────────
|
|
889
|
-
//
|
|
890
|
-
//
|
|
889
|
+
// The Settings page (client half) renders and persists the
|
|
890
|
+
// new-conversation defaults from this entry's volatile Config fields. The
|
|
891
891
|
// DSH settings RPC domain (api-proxy) only serves allowlisted namespaces to
|
|
892
892
|
// configuration clients, so the client reaches this namespace through the
|
|
893
893
|
// plugin's own fenced routes below ('settings.get'/'settings.update'),
|
|
@@ -921,17 +921,7 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
|
|
|
921
921
|
}
|
|
922
922
|
}
|
|
923
923
|
ctx.inject(['settings'], (sctx) => {
|
|
924
|
-
// DSH 0.1.2-alpha.2 validates namespaces at compile time
|
|
925
|
-
// (SettingsNamespaceInput); the 'dsh-better-sidebar' literal passes, so the
|
|
926
|
-
// runtime helper this used to call (settingsNamespace) is gone upstream.
|
|
927
924
|
const ns = SIDEBAR_PREFS_NS
|
|
928
|
-
// The structural settings mirror types `schema` as unknown, so the
|
|
929
|
-
// generic is not inferred here; the real service resolves it from the
|
|
930
|
-
// schemastery schema (PrefsSchema) — narrow the owner scope explicitly.
|
|
931
|
-
const scope = sctx.settings.register(ns, PrefsSchema) as {
|
|
932
|
-
get(): SidebarPrefs
|
|
933
|
-
watch(callback: (next: SidebarPrefs, prev: SidebarPrefs) => void): () => void
|
|
934
|
-
}
|
|
935
925
|
const viewOf = (): { value?: unknown; revision?: number } => {
|
|
936
926
|
const descriptor = sctx.settings.describe({ redactSecrets: true }).find(candidate => candidate.ns === ns)
|
|
937
927
|
return descriptor === undefined
|
|
@@ -957,6 +947,15 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
|
|
|
957
947
|
return viewOf()
|
|
958
948
|
},
|
|
959
949
|
}
|
|
950
|
+
const scope = {
|
|
951
|
+
get: (): SidebarPrefs => {
|
|
952
|
+
const value = viewOf().value
|
|
953
|
+
return {
|
|
954
|
+
...SIDEBAR_PREFS_DEFAULTS,
|
|
955
|
+
...(typeof value === 'object' && value !== null ? value : {}),
|
|
956
|
+
} as SidebarPrefs
|
|
957
|
+
},
|
|
958
|
+
}
|
|
960
959
|
// Register (or unregister) the terminal tools from the current setting,
|
|
961
960
|
// and keep them in sync with every settings commit.
|
|
962
961
|
syncToolsGate(scope)
|
|
@@ -988,10 +987,15 @@ export function apply(ctx: Context, config?: SidebarConfig): void {
|
|
|
988
987
|
}
|
|
989
988
|
}
|
|
990
989
|
syncOpenToolsGate()
|
|
991
|
-
//
|
|
992
|
-
//
|
|
993
|
-
|
|
994
|
-
|
|
990
|
+
// Volatile Config writes preserve the plugin fiber. Re-read the projected
|
|
991
|
+
// form after each Loader update so both gates track the committed values.
|
|
992
|
+
const updates = sctx as unknown as {
|
|
993
|
+
on(event: 'loader/volatile-update', listener: () => void): () => void
|
|
994
|
+
}
|
|
995
|
+
updates.on('loader/volatile-update', () => {
|
|
996
|
+
syncToolsGate(scope)
|
|
997
|
+
syncOpenToolsGate()
|
|
998
|
+
})
|
|
995
999
|
})
|
|
996
1000
|
|
|
997
1001
|
// ── JSON API ────────────────────────────────────────────────────────────
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** Standalone sign-in recovery; each document starts once and always keeps a usable reopen action. */
|
|
2
|
+
export const CHATCODE_LOGIN_PAGE_SCRIPT = String.raw`
|
|
3
|
+
(() => {
|
|
4
|
+
const message = document.getElementById('message');
|
|
5
|
+
const button = document.getElementById('login');
|
|
6
|
+
const fallback = document.getElementById('login-fallback');
|
|
7
|
+
const link = document.getElementById('login-link');
|
|
8
|
+
const current = new URL(location.href);
|
|
9
|
+
const returnTo = (() => {
|
|
10
|
+
const value = current.searchParams.get('return');
|
|
11
|
+
if (!value || !value.startsWith('/') || value.startsWith('//')) return '/';
|
|
12
|
+
const target = new URL(value, location.origin);
|
|
13
|
+
return target.origin === location.origin ? target.pathname + target.search + target.hash : '/';
|
|
14
|
+
})();
|
|
15
|
+
let busy = false, checking = false, attempted = false, recheck = false, attempt, popup;
|
|
16
|
+
const call = async name => {
|
|
17
|
+
const response = await fetch('/sidebar/api/' + name, {
|
|
18
|
+
method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}',
|
|
19
|
+
});
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
if (!response.ok || !data.ok) throw new Error('操作失败');
|
|
22
|
+
return data.value;
|
|
23
|
+
};
|
|
24
|
+
const showMessage = (text, error = false) => {
|
|
25
|
+
message.textContent = text;
|
|
26
|
+
message.classList.toggle('error', error);
|
|
27
|
+
};
|
|
28
|
+
async function login() {
|
|
29
|
+
if (busy) return;
|
|
30
|
+
attempted = true;
|
|
31
|
+
busy = true;
|
|
32
|
+
button.disabled = true;
|
|
33
|
+
button.textContent = '正在打开登录页…';
|
|
34
|
+
let tab = null;
|
|
35
|
+
try { tab = window.open('', '_blank'); if (tab) tab.opener = null; } catch {}
|
|
36
|
+
try {
|
|
37
|
+
if (!attempt) {
|
|
38
|
+
const started = await call('chatcode.start');
|
|
39
|
+
const url = new URL(started.url);
|
|
40
|
+
if (!['http:', 'https:'].includes(url.protocol) || typeof started.sessionId !== 'string') throw new Error('登录地址无效');
|
|
41
|
+
attempt = { sessionId: started.sessionId, url: url.href };
|
|
42
|
+
}
|
|
43
|
+
link.href = attempt.url;
|
|
44
|
+
link.textContent = attempt.url;
|
|
45
|
+
fallback.hidden = false;
|
|
46
|
+
if (tab && !tab.closed) {
|
|
47
|
+
try { tab.location.href = attempt.url; popup = tab; } catch { try { tab.close(); } catch {} }
|
|
48
|
+
}
|
|
49
|
+
showMessage('请在登录页完成登录;若网页已关闭,可随时重新打开。');
|
|
50
|
+
} catch {
|
|
51
|
+
try { if (tab) tab.close(); } catch {}
|
|
52
|
+
showMessage('登录页打开失败,请重试。', true);
|
|
53
|
+
} finally {
|
|
54
|
+
busy = false;
|
|
55
|
+
button.disabled = false;
|
|
56
|
+
button.textContent = attempt ? '重新打开登录页' : '去登录';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function status() {
|
|
60
|
+
if (checking || busy) return;
|
|
61
|
+
checking = true;
|
|
62
|
+
const observedAttempt = attempt, observedStarted = attempted;
|
|
63
|
+
try {
|
|
64
|
+
const state = await call('chatcode.status');
|
|
65
|
+
if (busy || attempt !== observedAttempt || attempted !== observedStarted) return;
|
|
66
|
+
if (state.available && state.validation === 'valid' && !state.expired) {
|
|
67
|
+
try { if (popup) popup.close(); window.focus(); } catch {}
|
|
68
|
+
location.replace(returnTo);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!state.available) {
|
|
72
|
+
recheck = true;
|
|
73
|
+
button.textContent = '重新检测';
|
|
74
|
+
showMessage('登录服务暂不可用,请稍后重试。', true);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (state.configured && state.validation === 'unavailable') {
|
|
78
|
+
recheck = true;
|
|
79
|
+
button.textContent = '重新检测';
|
|
80
|
+
showMessage('暂时无法验证已有账号,请检查网络后重新检测。', true);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
recheck = false;
|
|
84
|
+
button.textContent = attempt ? '重新打开登录页' : '去登录';
|
|
85
|
+
if (attempt && (state.login?.sessionId !== attempt.sessionId || state.login.state !== 'pending')) {
|
|
86
|
+
attempt = undefined;
|
|
87
|
+
fallback.hidden = true;
|
|
88
|
+
link.removeAttribute('href');
|
|
89
|
+
link.textContent = '';
|
|
90
|
+
button.textContent = '去登录';
|
|
91
|
+
showMessage('登录请求已失效,请重新登录。');
|
|
92
|
+
}
|
|
93
|
+
if (!attempted) await login();
|
|
94
|
+
} catch {
|
|
95
|
+
recheck = true;
|
|
96
|
+
button.textContent = '重新检测';
|
|
97
|
+
showMessage('无法读取登录状态,请稍后重试。', true);
|
|
98
|
+
} finally {
|
|
99
|
+
checking = false;
|
|
100
|
+
if (!busy) button.disabled = false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
button.addEventListener('click', () => { void (recheck ? status() : login()); });
|
|
104
|
+
void status();
|
|
105
|
+
setInterval(() => { void status(); }, 2000);
|
|
106
|
+
})();
|
|
107
|
+
`
|
package/src/login-route.ts
CHANGED
|
@@ -2,14 +2,17 @@ import { readFile } from 'node:fs/promises'
|
|
|
2
2
|
import { dirname, join } from 'node:path'
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
4
|
import type { Context, SidebarHttpRequest, SidebarHttpResponse } from './context-types.ts'
|
|
5
|
+
import { CHATCODE_LOGIN_PAGE_SCRIPT } from './login-page-script.ts'
|
|
5
6
|
|
|
6
7
|
const assetPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'assets', 'logo.svg')
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
/** Render the standalone login gate with one automatic attempt and persistent manual recovery. */
|
|
10
|
+
export function renderChatcodeLoginPage(logo: string): string {
|
|
9
11
|
return `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>请登录 ChatCode</title><style>
|
|
10
12
|
*{box-sizing:border-box}body{margin:0;min-width:320px;min-height:100vh;display:grid;place-items:center;font-family:Inter,"Microsoft YaHei",system-ui,sans-serif;color:#172b4d;background:radial-gradient(circle at 18% 18%,#e5edff 0,transparent 30rem),linear-gradient(135deg,#edf2fb,#dfe8f7)}.card{width:min(490px,calc(100vw - 40px));padding:34px 44px 36px;border:1px solid #dce4ef;border-radius:18px;background:#fff;box-shadow:0 20px 48px rgba(36,62,103,.18),0 2px 8px rgba(36,62,103,.06)}.brand{display:flex;align-items:center;justify-content:center;gap:12px;padding-bottom:27px;border-bottom:1px solid #edf0f5}.brand img{width:34px;height:34px}.brand strong{font-size:22px;letter-spacing:-.02em}.content{padding-top:40px;text-align:center}.content h1{margin:0;font-size:28px;line-height:1.3;font-weight:650}.content p{min-height:24px;margin:12px 0 30px;color:#71809a;font-size:14px;line-height:1.7}.action{width:100%;min-height:46px;border:0;border-radius:8px;background:#9B0B09;color:#fff;font:600 15px/1 Inter,"Microsoft YaHei",sans-serif;cursor:pointer;box-shadow:0 8px 18px rgba(155,11,9,.25);transition:transform .18s ease,box-shadow .18s ease,background .18s ease}.action:hover:not(:disabled){transform:translateY(-2px);background:#b20d0a;box-shadow:0 12px 24px rgba(155,11,9,.38)}.action:focus-visible{outline:3px solid #f0b7b5;outline-offset:3px}.action:disabled{cursor:default;opacity:.7}.error{color:#b42318}@media(max-width:480px){.card{padding:30px 26px}.content{padding-top:32px}}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
.login-fallback{margin:18px 0 0;color:#71809a;font-size:12px;line-height:1.7;overflow-wrap:anywhere}.login-fallback a{display:block;margin-top:4px;color:#315da8;text-underline-offset:3px}
|
|
14
|
+
</style></head><body><main class="card"><div class="brand"><img src="data:image/svg+xml;base64,${logo}" alt=""><strong>ChatCode</strong></div><section class="content"><h1>请登录 ChatCode</h1><p id="message" aria-live="polite">正在检查登录状态…</p><button id="login" class="action" type="button" disabled>正在检查登录状态…</button><div id="login-fallback" class="login-fallback" hidden>若登录网页已关闭或未弹出,可再次访问:<a id="login-link" target="_blank" rel="noopener noreferrer"></a></div></section></main><script>
|
|
15
|
+
${CHATCODE_LOGIN_PAGE_SCRIPT}
|
|
13
16
|
</script></body></html>`
|
|
14
17
|
}
|
|
15
18
|
|
|
@@ -20,7 +23,7 @@ export function registerLoginRoute(ctx: Context, fence: (req: SidebarHttpRequest
|
|
|
20
23
|
try {
|
|
21
24
|
const logo = (await readFile(assetPath)).toString('base64')
|
|
22
25
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'content-security-policy': "default-src 'self'; img-src 'self' data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'" })
|
|
23
|
-
res.end(req.method === 'HEAD' ? undefined :
|
|
26
|
+
res.end(req.method === 'HEAD' ? undefined : renderChatcodeLoginPage(logo))
|
|
24
27
|
} catch { res.writeHead(500); res.end('login page unavailable') }
|
|
25
28
|
} })
|
|
26
29
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Shared config plugin routes inside the sidebar's existing trust fence. */
|
|
2
|
+
import type { Context } from './context-types.ts'
|
|
3
|
+
import { realpath, stat } from 'node:fs/promises'
|
|
4
|
+
import { isAbsolute } from 'node:path'
|
|
5
|
+
import type { PluginMarketService, PluginMarketScope, PluginProjectDirectories } from './plugin-market-shared.ts'
|
|
6
|
+
import { requireString, SidebarError } from './wire.ts'
|
|
7
|
+
|
|
8
|
+
interface DirectoryPicker {
|
|
9
|
+
capability(): { kind: 'native'; pick(signal: AbortSignal): Promise<string | null> }
|
|
10
|
+
| { kind: 'browse'; list(path?: string, signal?: AbortSignal): Promise<PluginProjectDirectories> }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function buildPluginMarketApi(ctx: Pick<Context, 'get'>, cwdOf: (payload: unknown) => Promise<{ cwd: string }>): Record<string, (payload: unknown) => Promise<unknown>> {
|
|
14
|
+
const service = (): PluginMarketService => {
|
|
15
|
+
const value = ctx.get('chatcodePluginMarket', false) as PluginMarketService | undefined
|
|
16
|
+
if (!value) throw new SidebarError('chatcode-unavailable', '插件市场服务未挂载,请更新并启用 ChatCode config 插件。', 503)
|
|
17
|
+
return value
|
|
18
|
+
}
|
|
19
|
+
const scopeOf = (payload: unknown): PluginMarketScope => {
|
|
20
|
+
const scope = requireString(payload, 'scope')
|
|
21
|
+
if (scope !== 'project' && scope !== 'user') throw new SidebarError('bad-request', 'scope must be project or user')
|
|
22
|
+
return scope
|
|
23
|
+
}
|
|
24
|
+
const selectedProject = async (payload: unknown): Promise<string> => {
|
|
25
|
+
if (typeof (payload as { projectPath?: unknown } | null)?.projectPath !== 'string') throw new SidebarError('bad-request', '请先选择目标项目目录。')
|
|
26
|
+
const path = requireString(payload, 'projectPath')
|
|
27
|
+
const qualified = process.platform !== 'win32' || /^(?:[A-Za-z]:[\\/]|[\\/]{2}[^\\/]+[\\/][^\\/]+)/.test(path)
|
|
28
|
+
if (!isAbsolute(path) || !qualified || path.includes('\0')) throw new SidebarError('bad-request', '请选择有效的项目目录。')
|
|
29
|
+
const canonical = await realpath(path)
|
|
30
|
+
if (!(await stat(canonical)).isDirectory()) throw new SidebarError('bad-request', '请选择项目文件夹。')
|
|
31
|
+
return canonical
|
|
32
|
+
}
|
|
33
|
+
const picker = () => {
|
|
34
|
+
const value = ctx.get('directoryPicker', false) as DirectoryPicker | undefined
|
|
35
|
+
if (!value) throw new SidebarError('method-error', '目录选择器未挂载,请启用宿主目录选择插件。', 503)
|
|
36
|
+
return value.capability()
|
|
37
|
+
}
|
|
38
|
+
// A sessionless settings page has no implicit project. Only user-scoped
|
|
39
|
+
// operations may use the launch cwd internally, which never becomes a target.
|
|
40
|
+
const contextOf = async (payload: unknown): Promise<{ sessionId: string; cwd?: string }> => {
|
|
41
|
+
const sessionId = (payload as { sessionId?: unknown } | null)?.sessionId
|
|
42
|
+
if (sessionId === undefined || sessionId === '') return { sessionId: '' }
|
|
43
|
+
requireString(payload, 'sessionId')
|
|
44
|
+
return { sessionId: sessionId as string, cwd: (await cwdOf(payload)).cwd }
|
|
45
|
+
}
|
|
46
|
+
const projectOf = async (payload: unknown): Promise<string | undefined> => {
|
|
47
|
+
if ((payload as { projectPath?: unknown } | null)?.projectPath !== undefined) return selectedProject(payload)
|
|
48
|
+
return (await contextOf(payload)).cwd
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
'plugins.context': contextOf,
|
|
52
|
+
'plugins.project.pick': async () => {
|
|
53
|
+
const capability = picker()
|
|
54
|
+
if (capability.kind === 'browse') return { kind: 'browse' }
|
|
55
|
+
const path = await capability.pick(AbortSignal.timeout(120_000))
|
|
56
|
+
return { kind: 'native', path: path === null ? null : await selectedProject({ projectPath: path }) }
|
|
57
|
+
},
|
|
58
|
+
'plugins.project.directories': async payload => {
|
|
59
|
+
const capability = picker()
|
|
60
|
+
if (capability.kind !== 'browse') throw new SidebarError('method-error', '当前宿主使用系统文件夹选择窗口。')
|
|
61
|
+
const path = (payload as { path?: unknown } | null)?.path
|
|
62
|
+
return capability.list(path === undefined ? undefined : requireString(payload, 'path'), AbortSignal.timeout(15_000))
|
|
63
|
+
},
|
|
64
|
+
'plugins.marketplaces': () => service().marketplaces(),
|
|
65
|
+
'plugins.catalog': async payload => {
|
|
66
|
+
const market = service()
|
|
67
|
+
const id = requireString(payload, 'marketplaceId')
|
|
68
|
+
if ((payload as { includeMetadata?: unknown }).includeMetadata !== true) return market.plugins(id)
|
|
69
|
+
return market.catalog ? market.catalog(id) : { plugins: await market.plugins(id), warning: '' }
|
|
70
|
+
},
|
|
71
|
+
'plugins.installed': async payload => {
|
|
72
|
+
const project = await projectOf(payload)
|
|
73
|
+
const records = await service().installed(project ?? process.cwd())
|
|
74
|
+
return project ? records : records.filter(record => record.scope === 'user')
|
|
75
|
+
},
|
|
76
|
+
'plugins.install': async payload => {
|
|
77
|
+
const scope = scopeOf(payload)
|
|
78
|
+
const project = scope === 'project' ? await selectedProject(payload) : await projectOf(payload)
|
|
79
|
+
return service().install(project ?? process.cwd(), requireString(payload, 'pluginId'), scope)
|
|
80
|
+
},
|
|
81
|
+
'plugins.uninstall': async payload => {
|
|
82
|
+
const scope = scopeOf(payload)
|
|
83
|
+
const project = scope === 'project' ? await selectedProject(payload) : await projectOf(payload)
|
|
84
|
+
await service().uninstall(project ?? process.cwd(), requireString(payload, 'pluginId'), scope)
|
|
85
|
+
return { ok: true }
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Credential-free structural contract of the config plugin's host service. */
|
|
2
|
+
export type PluginMarketScope = 'project' | 'user'
|
|
3
|
+
export interface PluginMarketplace { id: string; name: string; description: string; official: boolean }
|
|
4
|
+
export interface MarketplacePlugin { id: string; marketplaceId: string; name: string; description: string }
|
|
5
|
+
export interface InstalledMarketplacePlugin extends MarketplacePlugin {
|
|
6
|
+
scope: PluginMarketScope
|
|
7
|
+
projectPath: string
|
|
8
|
+
installPath: string
|
|
9
|
+
version: string
|
|
10
|
+
installedAt: string
|
|
11
|
+
}
|
|
12
|
+
export interface MarketplaceCatalog { marketplaces: PluginMarketplace[]; warning: string }
|
|
13
|
+
export interface PluginCatalog { plugins: MarketplacePlugin[]; warning: string }
|
|
14
|
+
/** Host-owned paths for the remote Web directory browser. */
|
|
15
|
+
export interface PluginProjectDirectories {
|
|
16
|
+
path: string
|
|
17
|
+
home: string
|
|
18
|
+
crumbs: Array<{ name: string; path: string; hidden: boolean }>
|
|
19
|
+
entries: Array<{ name: string; path: string; hidden: boolean }>
|
|
20
|
+
truncated: boolean
|
|
21
|
+
}
|
|
22
|
+
export type PluginProjectPick = { kind: 'native'; path: string | null } | { kind: 'browse' }
|
|
23
|
+
export interface PluginMarketService {
|
|
24
|
+
marketplaces(): Promise<MarketplaceCatalog>
|
|
25
|
+
plugins(marketplaceId: string): Promise<MarketplacePlugin[]>
|
|
26
|
+
catalog?(marketplaceId: string): Promise<PluginCatalog>
|
|
27
|
+
installed(cwd: string): Promise<InstalledMarketplacePlugin[]>
|
|
28
|
+
install(cwd: string, pluginId: string, scope: PluginMarketScope): Promise<InstalledMarketplacePlugin>
|
|
29
|
+
uninstall(cwd: string, pluginId: string, scope: PluginMarketScope): Promise<void>
|
|
30
|
+
}
|
package/src/prefs-shared.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/** The user-settings namespace holding the side card preferences. */
|
|
10
|
-
export const SIDEBAR_PREFS_NS = '
|
|
10
|
+
export const SIDEBAR_PREFS_NS = 'better-sidebar'
|
|
11
11
|
|
|
12
12
|
/** User-facing side card preferences (new-conversation defaults). */
|
|
13
13
|
export interface SidebarPrefs {
|
package/src/pty-deps.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* agent terminal tools are simply not registered.
|
|
18
18
|
*
|
|
19
19
|
* Version contract: the plugin must stay in sync with DSH core —
|
|
20
|
-
* `@deepseek-ai/dsh-subprocess-local` declares `"node-pty": "
|
|
20
|
+
* `@deepseek-ai/dsh-subprocess-local` declares `"node-pty": "1.2.0-beta.15"` in
|
|
21
21
|
* its `dependencies`. Both sides then resolve the SAME pnpm store entry
|
|
22
22
|
* (same range, same integrity → one native binding, no drift). Do NOT
|
|
23
23
|
* switch to a fork (e.g. @lydell/node-pty) or a different range without
|
|
@@ -39,7 +39,7 @@ export type NodePtyModule = typeof nodePtyNs
|
|
|
39
39
|
* range DSH core declares (`@deepseek-ai/dsh-subprocess-local`): the same
|
|
40
40
|
* range keeps pnpm resolving both to one physical package.
|
|
41
41
|
*/
|
|
42
|
-
export const DSH_NODE_PTY_RANGE = '
|
|
42
|
+
export const DSH_NODE_PTY_RANGE = '1.2.0-beta.15'
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* The WebSocket close-code-1011 reason the host sends when node-pty is
|