@user-mrz/dsh-system-prompt-studio 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -46,7 +46,15 @@ window.__ModuleLoader__.load({
46
46
  subtitle: '按对话覆盖模型实际收到的系统提示词',
47
47
  close: '关闭',
48
48
  scopeSession: '本对话',
49
+ scopeWorkspace: '本工作区',
49
50
  scopeGlobal: '全局默认',
51
+ scopeWorkspaceHint: '这个工作区下所有对话都套用(含子代理);按侧边栏里的工作区归属算。',
52
+ scopeWorkspaceNoDir: '这个对话没有可用的工作区,无法按工作区保存。',
53
+ scopeWorkspacePath: '工作区:',
54
+ workspaceEmpty: '这个工作区还没有规则',
55
+ workspaceSaved: '已保存为这个工作区的规则,它下面的对话下一次请求生效。',
56
+ workspaceCleared: '已清除这个工作区的规则。',
57
+ workspaceFrom: '当前规则来自这个工作区:',
50
58
  scopeGlobalHint: '所有没有自身覆盖的顶层对话都套用(不含子代理)。',
51
59
  modeAppend: '追加到末尾',
52
60
  modeAppendHint: '保留第一方全部提示词,只在末尾追加你的段落。',
@@ -67,6 +75,8 @@ window.__ModuleLoader__.load({
67
75
  bodyHint: '{{…}} 会原样保留,不会被当作变量插值。',
68
76
  chars: '字符',
69
77
  enable: '在本对话启用覆盖',
78
+ enableWorkspace: '在本工作区启用覆盖',
79
+ enableGlobal: '在全局默认启用覆盖',
70
80
  save: '保存',
71
81
  clear: '清除覆盖',
72
82
  saving: '保存中…',
@@ -113,7 +123,15 @@ window.__ModuleLoader__.load({
113
123
  subtitle: 'Override the system prompt this conversation actually sends',
114
124
  close: 'Close',
115
125
  scopeSession: 'This conversation',
126
+ scopeWorkspace: 'This workspace',
116
127
  scopeGlobal: 'Global default',
128
+ scopeWorkspaceHint: 'Applied to every conversation in this workspace (subagents included); keyed on the workspace the sidebar shows.',
129
+ scopeWorkspaceNoDir: 'This conversation has no usable workspace, so a workspace override cannot be saved.',
130
+ scopeWorkspacePath: 'Workspace: ',
131
+ workspaceEmpty: 'no rules for this workspace yet',
132
+ workspaceSaved: 'Saved as this workspace\'s rules; applies to its conversations on their next request.',
133
+ workspaceCleared: 'Cleared this workspace\'s rules.',
134
+ workspaceFrom: 'Current rules come from this workspace: ',
117
135
  scopeGlobalHint: 'Applied to every top-level conversation without an override of its own (not subagents).',
118
136
  modeAppend: 'Append',
119
137
  modeAppendHint: 'Keep every first-party section and add yours at the end.',
@@ -134,6 +152,8 @@ window.__ModuleLoader__.load({
134
152
  bodyHint: '{{…}} is kept literally and is not interpolated.',
135
153
  chars: 'chars',
136
154
  enable: 'Enable override for this conversation',
155
+ enableWorkspace: 'Enable override for this workspace',
156
+ enableGlobal: 'Enable override in the global default',
137
157
  save: 'Save',
138
158
  clear: 'Clear override',
139
159
  saving: 'Saving…',
@@ -452,7 +472,8 @@ window.__ModuleLoader__.load({
452
472
  const backdropRef = React.useRef(null)
453
473
 
454
474
  const captureBaseline = React.useCallback((payload, which) => {
455
- const entry = which === 'global' ? payload?.global : payload?.session
475
+ const entry =
476
+ which === 'global' ? payload?.global : which === 'workspace' ? payload?.workspace?.entry : payload?.session
456
477
  return {
457
478
  mode: entry !== null && entry !== undefined && typeof entry.mode === 'string' ? entry.mode : 'append',
458
479
  text: entry !== null && entry !== undefined && typeof entry.text === 'string' ? entry.text : '',
@@ -586,7 +607,24 @@ window.__ModuleLoader__.load({
586
607
  const maxChars = typeof payload?.limits?.maxChars === 'number' ? payload.limits.maxChars : 200000
587
608
  const current = payload?.current ?? null
588
609
  const ownEntry = payload?.session ?? null
610
+ /**
611
+ * 工作区这一档在当前对话上是否可用。
612
+ *
613
+ * `workspace.key` 为空表示 host 算不出这个对话的目录(服务缺失、或会话
614
+ * 记录里没有 cwd)。这时必须把「本工作区」这个 tab 显式标成不可用,
615
+ * 而不是让它看起来能点、点下去再报错——那会让用户以为是自己填错了。
616
+ */
617
+ const workspaceKey = typeof payload?.workspace?.key === 'string' ? payload.workspace.key : ''
618
+ const workspacePath =
619
+ typeof payload?.workspace?.path === 'string' && payload.workspace.path !== ''
620
+ ? payload.workspace.path
621
+ : workspaceKey
622
+ const workspaceEntry = payload?.workspace?.entry ?? null
623
+ const workspaceAvailable = workspaceKey !== ''
589
624
  const inheritFrom = scope === 'session' ? payload?.effective?.inheritedFrom ?? '' : ''
625
+ // 只在「本对话」这一档提示工作区来源:站在工作区 tab 上说「规则来自工作区」
626
+ // 是废话,用户此刻正在编辑的就是那条规则。
627
+ const workspaceFrom = scope === 'session' ? payload?.effective?.workspaceKey ?? '' : ''
590
628
  const disabled = blocked.off || blocked.noService || blocked.noAgents || busy
591
629
  const completeOk = !blocked.complete && (mode !== 'complete' || ack)
592
630
 
@@ -609,13 +647,55 @@ window.__ModuleLoader__.load({
609
647
  const dropped = sections.filter((row) => !own.has(row.name))
610
648
  const chars = dropped.reduce((sum, row) => sum + (typeof row.chars === 'number' ? row.chars : 0), 0)
611
649
  /**
612
- * 第三方插件注册的段。第一方段的命名是 `harness:` / `tool:` / `deployment:` /
613
- * `app:` / `context:` / `plan:` / `ui:` / `mcp-` 这些前缀;插件习惯用
614
- * `plugin:` 前缀,或 `<包名>:<段名>` 的形状。按前缀判定是启发式,但足够
615
- * 把「你自己的插件会哑掉」这件事点到名,判错也不会误导成相反的方向。
650
+ * 第三方插件注册的段。
651
+ *
652
+ * 用**前缀白名单**而不是「非第一方即插件」的反向判定:反向判定会把所有
653
+ * 没见过的名字都算成插件,而第一方段的命名空间并不是全封闭的 ——
654
+ * 0.2.2-rc.2 的 dsh-cua 就注册了一个 `computer-use:dsh-cua`,它不是
655
+ * `tool:` 前缀却属于第一方随包发布的插件。反过来,`tool:` 前缀也不保证
656
+ * 第一方:dsh-m 就把自己的段注册成 `tool:dshm`。
657
+ *
658
+ * 所以这里只认「确实是第一方内置包注册的段名」这份白名单,其余一律
659
+ * 计入插件侧 —— 宁可多报一个(提示用户去看清单),也不要漏报一个让
660
+ * 插件静默失效。
616
661
  */
617
- const FIRST_PARTY = /^(harness:|tool:|deployment:|app:|context:|plan:|ui:|mcp-)/
618
- const plugins = dropped.filter((row) => !FIRST_PARTY.test(String(row.name ?? '')))
662
+ const FIRST_PARTY = new Set([
663
+ 'harness:identity',
664
+ 'harness:source',
665
+ 'deployment:persona-prefix',
666
+ 'deployment:persona-suffix',
667
+ 'plan:policy',
668
+ 'team:policy',
669
+ 'ptc:only',
670
+ 'context:file-reference',
671
+ 'tool:bash',
672
+ 'tool:pwsh',
673
+ 'tool:read',
674
+ 'tool:write',
675
+ 'tool:edit',
676
+ 'tool:apply_patch',
677
+ 'tool:glob',
678
+ 'tool:grep',
679
+ 'tool:jobs',
680
+ 'tool:pty',
681
+ 'tool:web_search',
682
+ 'tool:web_fetch',
683
+ 'tool:lsp',
684
+ 'tool:session_query',
685
+ 'tool:goal',
686
+ 'tool:schedule',
687
+ 'tool:workflow',
688
+ 'tool:ralph',
689
+ 'tool:subagent',
690
+ 'tool:subagent_fork',
691
+ 'tool:report',
692
+ 'mcp-resource-servers',
693
+ 'tools:sdk',
694
+ 'ui:deliverable-file-references',
695
+ 'structured-output',
696
+ 'app:web-surface',
697
+ ])
698
+ const plugins = dropped.filter((row) => !FIRST_PARTY.has(String(row.name ?? '')))
619
699
  return { dropped, chars, plugins, kept }
620
700
  })()
621
701
 
@@ -629,13 +709,17 @@ window.__ModuleLoader__.load({
629
709
  return
630
710
  }
631
711
  if (mode === 'complete' && !ack) return
712
+ if (scope === 'workspace' && !workspaceAvailable) {
713
+ setNotice({ kind: 'error', text: t('scopeWorkspaceNoDir') })
714
+ return
715
+ }
632
716
  setBusy(true)
633
717
  setNotice({ kind: '', text: '' })
634
718
  try {
635
719
  const body = {
636
720
  action: 'set',
637
721
  scope,
638
- sessionId: scope === 'session' ? sessionId : '',
722
+ sessionId: sessionId,
639
723
  patch: { enabled, mode, text, target: mode === 'replace' ? target.trim() : '' },
640
724
  }
641
725
  const result = await api.save(body)
@@ -644,7 +728,12 @@ window.__ModuleLoader__.load({
644
728
  setBaseline({ mode, text, target, enabled })
645
729
  setNotice({
646
730
  kind: result?.persisted === false ? 'error' : 'ok',
647
- text: result?.persisted === false ? t('savedLocal') : t('saved'),
731
+ text:
732
+ result?.persisted === false
733
+ ? t('savedLocal')
734
+ : scope === 'workspace'
735
+ ? t('workspaceSaved')
736
+ : t('saved'),
648
737
  })
649
738
  } catch (error) {
650
739
  setNotice({ kind: 'error', text: `${t('saveFailed')}${String(error?.message ?? error)}` })
@@ -654,14 +743,18 @@ window.__ModuleLoader__.load({
654
743
  }
655
744
 
656
745
  const onClear = async () => {
746
+ if (scope === 'workspace' && !workspaceAvailable) {
747
+ setNotice({ kind: 'error', text: t('scopeWorkspaceNoDir') })
748
+ return
749
+ }
657
750
  setBusy(true)
658
751
  setNotice({ kind: '', text: '' })
659
752
  try {
660
- const body = { action: 'clear', scope, sessionId: scope === 'session' ? sessionId : '' }
753
+ const body = { action: 'clear', scope, sessionId }
661
754
  const result = await api.save(body)
662
755
  setStatus({ phase: 'ready', payload: result, error: '' })
663
756
  applyPayload(result, scope)
664
- setNotice({ kind: 'ok', text: t('cleared') })
757
+ setNotice({ kind: 'ok', text: scope === 'workspace' ? t('workspaceCleared') : t('cleared') })
665
758
  } catch (error) {
666
759
  setNotice({ kind: 'error', text: `${t('saveFailed')}${String(error?.message ?? error)}` })
667
760
  } finally {
@@ -771,7 +864,24 @@ window.__ModuleLoader__.load({
771
864
  ? h('div', { key: 'inherit-none', 'data-sps': 'muted' }, t('inheritedNone'))
772
865
  : null,
773
866
 
774
- // 作用域
867
+ /**
868
+ * 工作区来源提示。
869
+ *
870
+ * 只在「本对话没有自身条目、且当前生效的规则来自工作区」时显示:
871
+ * 用户打开一个对话,发现提示词变了,而他自己没在这个对话里设过任何
872
+ * 东西——必须能一眼看出是「这个目录的规矩」在起作用,而不是以为
873
+ * 插件抽风或上一个对话的规则漏过来了。
874
+ */
875
+ workspaceFrom !== '' && ownEntry === null && inheritFrom === ''
876
+ ? h(
877
+ 'div',
878
+ { key: 'wsfrom', 'data-sps': 'warn', style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
879
+ h('span', { style: { flex: 1, minWidth: 200 } }, `${t('workspaceFrom')}${workspaceFrom}`),
880
+ )
881
+ : null,
882
+
883
+ // 作用域:三档,从具体到宽泛排列(本对话 → 本目录 → 全局默认)。
884
+ // 顺序刻意按「影响范围递增」排,用户从左往右点就是在逐级放宽。
775
885
  h(
776
886
  'div',
777
887
  { key: 'scope', 'data-sps': 'row' },
@@ -791,6 +901,23 @@ window.__ModuleLoader__.load({
791
901
  },
792
902
  t('scopeSession'),
793
903
  ),
904
+ h(
905
+ 'button',
906
+ {
907
+ type: 'button',
908
+ 'data-sps': 'tab',
909
+ 'data-on': scope === 'workspace' ? 'true' : 'false',
910
+ // 没有可用目录时禁用而不是隐藏:隐藏会让用户以为插件不支持
911
+ // 工作区,禁用加下面的说明才告诉他「为什么这里不行」。
912
+ disabled: !workspaceAvailable,
913
+ title: workspaceAvailable ? workspacePath : t('scopeWorkspaceNoDir'),
914
+ onClick: () => {
915
+ setScope('workspace')
916
+ applyPayload(status.payload, 'workspace')
917
+ },
918
+ },
919
+ t('scopeWorkspace'),
920
+ ),
794
921
  h(
795
922
  'button',
796
923
  {
@@ -806,8 +933,36 @@ window.__ModuleLoader__.load({
806
933
  ),
807
934
  ),
808
935
  scope === 'global' ? h('span', { 'data-sps': 'muted' }, t('scopeGlobalHint')) : null,
936
+ scope === 'workspace'
937
+ ? h(
938
+ 'span',
939
+ { 'data-sps': 'muted' },
940
+ workspaceAvailable ? t('scopeWorkspaceHint') : t('scopeWorkspaceNoDir'),
941
+ )
942
+ : null,
809
943
  ),
810
944
 
945
+ // 工作区路径:必须显示,否则用户无法核对「我改的是不是这个项目」。
946
+ scope === 'workspace' && workspaceAvailable
947
+ ? h(
948
+ 'div',
949
+ { key: 'wspath', 'data-sps': 'row' },
950
+ h('span', { 'data-sps': 'label' }, t('scopeWorkspacePath')),
951
+ h(
952
+ 'code',
953
+ {
954
+ 'data-sps': 'wspath',
955
+ title: workspacePath,
956
+ style: { fontSize: 12, wordBreak: 'break-all', flex: 1, minWidth: 200 },
957
+ },
958
+ workspacePath,
959
+ ),
960
+ workspaceEntry === null
961
+ ? h('span', { 'data-sps': 'muted' }, `· ${t('workspaceEmpty')}`)
962
+ : null,
963
+ )
964
+ : null,
965
+
811
966
  // 模式
812
967
  h(
813
968
  'div',
@@ -945,7 +1100,11 @@ window.__ModuleLoader__.load({
945
1100
  'label',
946
1101
  { key: 'enable', 'data-sps': 'row', style: { gap: 8 } },
947
1102
  h('input', { type: 'checkbox', checked: enabled, onChange: (event) => setEnabled(event.target.checked) }),
948
- h('span', { 'data-sps': 'muted' }, t('enable')),
1103
+ h(
1104
+ 'span',
1105
+ { 'data-sps': 'muted' },
1106
+ t(scope === 'global' ? 'enableGlobal' : scope === 'workspace' ? 'enableWorkspace' : 'enable'),
1107
+ ),
949
1108
  ),
950
1109
 
951
1110
  // 影响说明