Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

- Add the settings-page entry for the PTC disclosure tier (#989): the row page carries one **PTC disclosure tier** card — *On-demand (default)* or *Full* — that unifies both PTC rows in one revision-checked save. An old profile shows the default rung and is never written unless the operator changes it; picking on-demand returns both rows to the absent key, so a profile saved through the card is letter-identical to one that never met it; disagreeing saved rows are named `mixed` and unified by the next choice; a cancelled edit writes nothing. The tier rides the merged row page as a volatile string beside `bashPath` (the legacy per-mode form stays YAML-only), survives unrelated saves, and applies to new sessions; while the dynamic-tools bundle switch is off the card names the suspension and keeps the saved choice. The full choice saved through the real writer boots a loader-less first round carrying exactly the permitted pool — the cap is never widened — and switching the tier between saves applies to the next session.
- 新增 PTC 披露档位的设置页入口(#989):行页面提供一张「PTC 披露档位」卡片——按需(默认)或全量——一次版本校验的保存同时统一两条 PTC 行。旧档案默认显示默认档且绝不被动写入;选回「按需」会把两行都还原为键缺失,经卡片保存过的档案与从未见过卡片的档案逐字一致;两行不一致时点名 `mixed`,由下一次选择统一;取消编辑不写入任何内容。档位以 volatile 字符串挂在合并行页面(与 `bashPath` 并列;旧的逐模式表单保持 YAML-only),无关保存不会丢,且只对新会话生效;动态工具总开关关闭期间卡片点名暂停并保留已存选择。经真实写入器保存的全量选择启动无 loader 的首轮,且恰好携带获准池——上限从不扩大——保存之间切换档位对下一个会话生效。
- Align custom PTC integrations with the publication plan (#988): the scoped diagnostic's expected first-round names now come from the same disclosure derivation (`src/ptc/disclosure.ts`) the publication uses, so a legal `profile: 'ptc'` row no longer reads degraded with a lone `PUBLICATION_UNAVAILABLE: ops_result` — `result` is selectable, not resident — while the explicit full tier's whole pool is expected when a row selects it and a genuinely missing first-round name still reports. Custom rows accept the same `disclosurePolicy` key the builtin rows parse (`'on-demand'` default, `'full'` explicit, Native-presentation rows reject it; nothing ever writes it for you). The custom path still rejects `alwaysLoaded` outside `allowedTools` where builtin rows accept it silently, with both sides now asserted; a native custom preset's visible tools are snapshotted, and the D1 truth-table pin that locked the misdiagnosis is flipped to `ready`. No publication behaviour changes on the on-demand tier.
- 对齐自定义 PTC 接入与发布计划(#988):作用域诊断的首轮期望名改由发布使用的同一份披露推导(`src/ptc/disclosure.ts`)生成——合法 `profile: 'ptc'` 行不再被误诊为仅剩 `PUBLICATION_UNAVAILABLE: ops_result` 的 degraded(`result` 是可选加载而非常驻);选择显式全量档的行其整池都在期望之内;真正缺失的首轮名仍会报告。自定义行接受与内置行相同的 `disclosurePolicy` 键(缺省 `'on-demand'`,显式 `'full'`,Native 展示行拒绝该键;任何升级或保存都不替你写入)。自定义路径对落在 `allowedTools` 之外的 `alwaysLoaded` 仍抛错而内置行静默接受,两侧均已断言;原生自定义 preset 的可见工具集已做快照;D1 锁定误报的真值表检查翻转为 `ready`。on-demand 档的发布行为不变。
- Publish the explicit full PTC disclosure tier (#987): with `disclosurePolicy: 'full'` the `ptc` and `ops-ptc` rows' first round now carries the whole permitted `allowedTools` pool plus `ops_result` (the D1 sign-off item 1 decision, taken conservatively per #979 §3 so refs spilled this step stay consumable — and forced by the unified rule, since on-demand can always load `result`) with no `ops_load_sdk`. The first program can call the permitted pool directly; read-only sessions still exclude every write API, an empty cap stays at resident + `result`, `residentTools:false` drops the resident surface but not the tier, duplicated names register once, `global.dynamicTools:false` keeps its veto (the row publishes its legacy surface letter for letter) and a row that also turns its loader off keeps the tier. `PtcConfig.disclosurePolicy` stays optional because custom integrations keep the legacy on-demand default until #988; the builtin plan carries the parsed value. On-demand (default) behaviour is letter-identical; the settings-page entry is #989.
Expand Down
18 changes: 18 additions & 0 deletions src/client/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ export const en = {
defaultPresetNoUpdate: 'Nothing to do: new sessions already start in OPS (PTC).',
defaultPresetUnavailable: 'The OPS (PTC) preset is not registered right now, so the default preset was not changed.',
defaultPresetFailed: 'The default preset was not changed:',
disclosureTitle: 'PTC disclosure tier',
disclosureHint: 'One choice for both PTC rows: when the full permitted tool declaration appears in a session. The distinction is the timing, never the permissions.',
disclosureOnDemand: 'On-demand (default)',
disclosureOnDemandHint: 'The first step publishes resident tools plus the loader; the full declaration appears after the loader call, two steps.',
disclosureFull: 'Full',
disclosureFullHint: 'The first step publishes the whole permitted tool pool with no loader. Choosing this never widens permissions.',
disclosureMixed: 'The saved PTC rows disagree about the tier. Choosing one below unifies them on save.',
disclosureSuspended: 'The dynamic-tools bundle switch is off, so the full tier is suspended and both rows run on-demand until it is back on; the saved choice is kept.',
disclosureAppliesOnSave: 'The choice applies to new sessions; running sessions keep their current surface.',
}
export const zh: Record<keyof typeof en, string> = {
ptcFilesRequired: '类型化 PTC 必须启用文件能力;用常驻开关控制启动 API。',
Expand Down Expand Up @@ -182,6 +191,15 @@ export const zh: Record<keyof typeof en, string> = {
defaultPresetNoUpdate: '无需更改:新会话本来就默认使用 OPS (PTC)。',
defaultPresetUnavailable: 'OPS (PTC) 预设当前未注册,默认预设没有改动。',
defaultPresetFailed: '默认预设没有改动:',
disclosureTitle: 'PTC 披露档位',
disclosureHint: '两条 PTC 行统一选择:完整获准工具声明在会话中出现的时机。区别只在时机,从不改变权限。',
disclosureOnDemand: '按需(默认)',
disclosureOnDemandHint: '首步只发布常驻工具与加载入口;完整声明在加载调用之后出现,分两步。',
disclosureFull: '全量',
disclosureFullHint: '首步直接发布整个获准工具池,且无加载入口。选择全量不会扩大任何权限。',
disclosureMixed: '已保存的两条 PTC 行档位不一致。在下面选定一个,保存后会统一。',
disclosureSuspended: '动态工具总开关已关闭,全量档暂不生效,两行按需运行;已保存的选择原样保留,开关回开后重新生效。',
disclosureAppliesOnSave: '选择对新会话生效;正在运行的会话保持当前工具面。',
}
declare module '@deepseek-ai/dsh-client-ui-slots' { interface LocaleNamespaceMap { dshOps: keyof typeof en } }
export type Translator = TranslateNS<'dshOps'>
Expand Down
47 changes: 42 additions & 5 deletions src/client/row-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { ReactElement } from 'react'
import type { RuntimeRemote, RuntimeSnapshot } from '../settings/runtime-contract.js'
import { FormActions, Unavailable, errorText, useEditor } from './forms.js'
import type { SettingsProps } from './forms.js'
import { groupsFor, bundleGates, changedFields, executorDiffers, executorOps, flatKey, readExecutor, readRowValues, type FieldSpec } from './row-schema.js'
import type { ExecutorChoice } from './row-schema.js'
import { groupsFor, bundleGates, changedFields, disclosureDiffers, disclosureOps, executorDiffers, executorOps, flatKey, readDisclosure, readExecutor, readRowValues, type FieldSpec } from './row-schema.js'
import type { DisclosureSelection, ExecutorChoice } from './row-schema.js'
import type { Translator } from './locales.js'

/** The subset of the native Switch this page binds. */
Expand All @@ -36,19 +36,24 @@ export function RowForm(props: SettingsProps & { Switch: SwitchBinding; pwsh7Ins
const editor = useEditor(form, read, t)
const [opened, setOpened] = useState<Record<string, boolean>>({})
const [choice, setChoice] = useState<ExecutorChoice>(() => readExecutor(form?.state.value ?? {}))
const [tier, setTier] = useState<DisclosureSelection>(() => readDisclosure(form?.state.value ?? {}))
const [check, setCheck] = useState<{ ok: boolean; text: string }>()
const [saving, setSaving] = useState(false)
// The saved row is the baseline: a Host reload while the page is dirty must not
// silently adopt somebody else's executor.
// silently adopt somebody else's executor or disclosure tier.
useEffect(() => {
if (editor.dirty) return
setChoice(readExecutor(editor.baseline))
setTier(readDisclosure(editor.baseline))
setCheck(undefined)
}, [editor.baseline, editor.dirty])
if (!editor.ready) return <Unavailable {...props} />
const draft = editor.draft, gates = bundleGates(draft)
const savedChoice = readExecutor(editor.baseline)
const executorDirty = executorDiffers(choice, editor.baseline)
const savedTier = readDisclosure(editor.baseline)
// `mixed` only describes saved state, so it is never a choice to write.
const tierDirty = tier !== 'mixed' && disclosureDiffers(tier, editor.baseline)
const candidates = executor.snapshot?.git ?? []

/** Ask the Host what a path resolves to; nothing is written by this call. */
Expand Down Expand Up @@ -83,6 +88,9 @@ export function RowForm(props: SettingsProps & { Switch: SwitchBinding; pwsh7Ins
} catch (error) { setCheck({ ok: false, text: errorText(error) }); return }
finally { setSaving(false) }
}
// The disclosure card writes exactly the reviewed tier, nothing else: an
// untouched old profile (key absent) produces no operation at all.
if (tierDirty) operations.push(...disclosureOps(editor.baseline, tier))
await editor.save(operations)
}
// The companion linkage locks every host-PowerShell hide switch to off.
Expand Down Expand Up @@ -178,8 +186,37 @@ export function RowForm(props: SettingsProps & { Switch: SwitchBinding; pwsh7Ins
<p className="ops-field-hint">{t('executorAppliesOnSave')}</p>
</div>
</section>
<FormActions busy={editor.busy || saving} dirty={editor.dirty || executorDirty} valid
reset={() => { editor.reset(); setChoice(savedChoice); setCheck(undefined) }} message={editor.message} t={t} />
<section className="ops-group ops-card" key="ptc-disclosure">
<div className="ops-group-head"><div className="ops-field-text">
<h4 className="ops-group-title">{t('disclosureTitle')}</h4>
<p className="ops-field-hint">{t('disclosureHint')}</p>
</div></div>
<div className="ops-card-body">
{savedTier === 'mixed' && <p className="ops-field-hint">{t('disclosureMixed')}</p>}
{/* The bundle switch keeps its veto (sign-off item 2): the hint names the
suspension instead of hiding the choice, which still applies on save. */}
{!gates.dynamicTools && <p className="ops-field-hint">{t('disclosureSuspended')}</p>}
<label className="ops-choice">
<input type="radio" name="ops-disclosure" checked={tier === 'on-demand'} disabled={editor.busy || saving}
onChange={() => { setTier('on-demand') }} />
<span className="ops-field-text">
<span className="ops-field-label">{t('disclosureOnDemand')}</span>
<span className="ops-field-hint">{t('disclosureOnDemandHint')}</span>
</span>
</label>
<label className="ops-choice">
<input type="radio" name="ops-disclosure" checked={tier === 'full'} disabled={editor.busy || saving}
onChange={() => { setTier('full') }} />
<span className="ops-field-text">
<span className="ops-field-label">{t('disclosureFull')}</span>
<span className="ops-field-hint">{t('disclosureFullHint')}</span>
</span>
</label>
<p className="ops-field-hint">{t('disclosureAppliesOnSave')}</p>
</div>
</section>
<FormActions busy={editor.busy || saving} dirty={editor.dirty || executorDirty || tierDirty} valid
reset={() => { editor.reset(); setChoice(savedChoice); setTier(savedTier); setCheck(undefined) }} message={editor.message} t={t} />
</form>
}

Expand Down
52 changes: 52 additions & 0 deletions src/client/row-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,58 @@ function savedBashPaths(raw: Record<string, unknown>): SavedBashPath[] {
return list
}

/** The mode sections that own a PTC publication surface and its disclosure tier. */
export const DISCLOSURE_SECTIONS = Object.freeze(['ptc', 'ops-ptc'] as const)

/** One disclosure tier as the page holds it, or \`mixed\` when the saved rows disagree. */
export type DisclosureSelection = 'on-demand' | 'full' | 'mixed'

/** The two tiers an operator can actually pick; \`mixed\` only describes saved state. */
export type DisclosureTier = Exclude<DisclosureSelection, 'mixed'>

/**
* Read the disclosure tier the saved rows stand for.
* @param raw - the saved row config.
* @returns the agreed tier, or \`mixed\` when the two PTC rows disagree.
*/
export function readDisclosure(raw: Record<string, unknown>): DisclosureSelection {
const tiers = new Set(DISCLOSURE_SECTIONS.map(section =>
objectAt(raw[section]).disclosurePolicy === 'full' ? 'full' : 'on-demand'))
return tiers.size === 1 ? [...tiers][0]! : 'mixed'
}

/**
* Whether the page's tier still differs from what is saved.
* @param selection - the operator's current choice.
* @param raw - the saved row config.
* @returns true when saving must write the tier.
*/
export function disclosureDiffers(selection: DisclosureSelection, raw: Record<string, unknown>): boolean {
return selection !== readDisclosure(raw)
}

/**
* The write operations that turn the saved rows into the reviewed tier.
*
* \`full\` pins both PTC rows; \`on-demand\` returns every row that carries the key
* to the absent default, so an old profile saved through the card is
* letter-identical to one that never met it.
* @param raw - the saved row config.
* @param tier - the operator's choice.
* @returns \`set\` operations for \`full\`, \`unset\` for the default rung.
*/
export function disclosureOps(raw: Record<string, unknown>, tier: DisclosureTier): SettingsPathOpView[] {
const operations: SettingsPathOpView[] = []
for (const section of DISCLOSURE_SECTIONS) {
const saved = objectAt(raw[section]).disclosurePolicy
if (tier === 'full' ? saved === 'full' : saved === undefined) continue
operations.push(tier === 'full'
? { op: 'set', path: [section, 'disclosurePolicy'], value: 'full' }
: { op: 'unset', path: [section, 'disclosurePolicy'] })
}
return operations
}

/** Whether a path names the Niubash executable rather than an MSYS bash. */
const niubashPath = (value: string): boolean => /(^|[\/])niu\.exe$/i.test(value)

Expand Down
6 changes: 6 additions & 0 deletions src/settings/merged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ const MODE_SWITCHES: Record<string, Field> = {
function modeSection(mode: ModeKey): Field {
return { type: 'object', dict: { enabled: boolean('Apply this mode to its sessions.'),
...(mode === 'minimal' ? {} : { residentTools: boolean('Publish baseline file tools independently of dynamic loading.') }),
// Only the PTC rows own a disclosure tier; the key is volatile because the
// row page's disclosure card writes it, exactly like the executor card
// writes bashPath. Absent stays the on-demand default (#989).
...(mode === 'ptc' || mode === 'ops-ptc'
? { disclosurePolicy: editable('string', 'Optional explicit first-round disclosure tier selected on the row page.') }
: {}),
bashPath: editable('string', 'Optional explicit Bash executable selected on the runtime page.'),
...MODE_SWITCHES } }
}
Expand Down
6 changes: 4 additions & 2 deletions test/ptc-disclosure-policy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ await test('input class 2 (legal value): on-demand and full parse and ride the s
assert.equal(resolveModeConfig({ disclosurePolicy: 'full' }, mode).disclosurePolicy, 'full', mode)
assert.equal(resolveModeConfig({ disclosurePolicy: 'on-demand' }, mode).disclosurePolicy, 'on-demand', mode)
}
// D2 adds no settings-page field: the key stays YAML-only (the entry is D5).
// D5 (#989) moved the key onto the merged row page as a volatile string the
// disclosure card owns; the legacy per-mode form keeps it YAML-only.
assert.equal('disclosurePolicy' in modeFields('ops-ptc'), false)
assert.equal('disclosurePolicy' in Config.dict['ops-ptc'].dict, false)
assert.equal('disclosurePolicy' in Config.dict['ops-ptc'].dict, true)
assert.equal(Config.dict['ops-ptc'].dict.disclosurePolicy.meta.volatile, true)
})

await test('input class 3 (misspelled value): the diagnostic names the key and the value', () => {
Expand Down
Loading
Loading