@dsh-cc/serena-first 0.5.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/LICENSE +201 -0
- package/README.md +25 -0
- package/README.zh.md +22 -0
- package/lib/index.d.ts +53 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +113 -0
- package/lib/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @dsh-cc/serena-first
|
|
2
|
+
|
|
3
|
+
Serena-first prompt steering for the CC preset (`packages/preset/cc`).
|
|
4
|
+
|
|
5
|
+
When a serena MCP server is connected (repo `.serena/project.yml`, user-scoped
|
|
6
|
+
`~/.claude.json` entry — see `docs/code-intelligence-health.md`), the session
|
|
7
|
+
carries ~30 `mcp__serena__*` symbol tools that answer code questions without
|
|
8
|
+
loading whole files. This plugin makes the system prompt say so:
|
|
9
|
+
|
|
10
|
+
- **Contribution A** — a registered section `serena-first` (order 105) with a
|
|
11
|
+
dynamic provider that renders the policy paragraph while serena is ready and
|
|
12
|
+
an empty string (dropped at render) otherwise.
|
|
13
|
+
- **Contribution B** — a `system-prompt/assemble` waterfall listener
|
|
14
|
+
(`{ prepend: true }`, outermost, so its return value is authoritative) that
|
|
15
|
+
replace-not-mutate appends one sentence each to the upstream
|
|
16
|
+
`tool:read` and `tool:grep` sections while serena is ready.
|
|
17
|
+
|
|
18
|
+
Detection is registry-only and live: a duck-typed `mcpConnections` entry
|
|
19
|
+
(`state: 'ready'` with `toolCount > 0`), re-evaluated on every assembly, so a
|
|
20
|
+
mid-session disconnect stops the steering on the next turn. Scope-less
|
|
21
|
+
assemblies pass through (mirrors `tool-append-order`); `tool:write`,
|
|
22
|
+
`tool:edit`, and `tool:glob` are never rewritten.
|
|
23
|
+
|
|
24
|
+
Config: `enabled` (default `true`), `serverName` (default `'serena'`) — the
|
|
25
|
+
latter drives both detection and every emitted `mcp__<serverName>__*` name.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @dsh-cc/serena-first
|
|
2
|
+
|
|
3
|
+
CC 预设的 serena 优先提示词引导(参见 `README.md`)。
|
|
4
|
+
|
|
5
|
+
当 serena MCP 服务器已连接(仓库 `.serena/project.yml`,用户级
|
|
6
|
+
`~/.claude.json` 条目——见 `docs/code-intelligence-health.md`)时,会话中
|
|
7
|
+
存在约 30 个 `mcp__serena__*` 符号工具,可以在不整读文件的情况下回答代码
|
|
8
|
+
问题。本插件让系统提示词说明这一点:
|
|
9
|
+
|
|
10
|
+
- **贡献 A** —— 注册 `serena-first` 段落(order 105),动态 provider 在
|
|
11
|
+
serena 就绪时渲染策略段落,否则渲染空字符串(渲染时被丢弃)。
|
|
12
|
+
- **贡献 B** —— `system-prompt/assemble` 瀑布监听器(`{ prepend: true }`,
|
|
13
|
+
最外层,返回值权威),在 serena 就绪时以 replace-not-mutate 方式为上游
|
|
14
|
+
`tool:read` 与 `tool:grep` 段落各追加一句。
|
|
15
|
+
|
|
16
|
+
检测仅依赖注册表且实时求值:对 `mcpConnections` 做鸭子类型读取
|
|
17
|
+
(`state: 'ready'` 且 `toolCount > 0`),每次组装时重新求值,因此会话中途
|
|
18
|
+
断开会在下一轮停止引导。无作用域的组装直接放行(与 `tool-append-order`
|
|
19
|
+
一致);`tool:write`、`tool:edit`、`tool:glob` 永不改写。
|
|
20
|
+
|
|
21
|
+
配置:`enabled`(默认 `true`)、`serverName`(默认 `'serena'`)——后者同时
|
|
22
|
+
决定探测与所有 `mcp__<serverName>__*` 工具名。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serena-first prompt steering for the CC preset.
|
|
3
|
+
*
|
|
4
|
+
* When a serena MCP server is connected, the session carries ~30
|
|
5
|
+
* `mcp__serena__*` symbol tools that answer code questions without loading
|
|
6
|
+
* whole files; the upstream `tool:read` / `tool:grep` guidance sections say
|
|
7
|
+
* nothing about them. This plugin contributes two disjoint pieces:
|
|
8
|
+
*
|
|
9
|
+
* - A registered section `serena-first` (order 105, just after the upstream
|
|
10
|
+
* tool guidance band at 100–104) whose dynamic provider renders the policy
|
|
11
|
+
* paragraph while serena is ready and `''` otherwise (empty renders are
|
|
12
|
+
* dropped at render time). It is *registered*, never inserted at assemble
|
|
13
|
+
* time — nothing in the repo inserts a brand-new section into
|
|
14
|
+
* `assembly.sections` on the waterfall.
|
|
15
|
+
* - A `system-prompt/assemble` waterfall listener registered with
|
|
16
|
+
* `{ prepend: true }` (cordis composes outermost-first and the outermost
|
|
17
|
+
* return value is authoritative) that replace-not-mutate appends one
|
|
18
|
+
* sentence each to the existing `tool:read` and `tool:grep` sections while
|
|
19
|
+
* serena is ready. `tool:write` / `tool:edit` / `tool:glob` are never
|
|
20
|
+
* rewritten: serena has no path-discovery equivalent, and edits keep the
|
|
21
|
+
* fs-observation-policy read-before-write gating.
|
|
22
|
+
*
|
|
23
|
+
* Detection is registry-only and live: a duck-typed `mcpConnections` entry
|
|
24
|
+
* (the service mcp-client always provides; the same seam `command-doctor`
|
|
25
|
+
* duck-types) with `state: 'ready'` and `toolCount > 0`, re-evaluated on
|
|
26
|
+
* every assembly, so a mid-session disconnect stops the steering on the next
|
|
27
|
+
* turn. Scope-less assemblies pass through — there is no per-scope keying
|
|
28
|
+
* possible (mirrors `tool-append-order`).
|
|
29
|
+
* @module @dsh-cc/serena-first
|
|
30
|
+
*/
|
|
31
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
32
|
+
import z from '@deepseek-ai/schemastery';
|
|
33
|
+
export declare const name = "serena-first";
|
|
34
|
+
export declare const inject: readonly ["systemPrompt"];
|
|
35
|
+
/** Plugin config. */
|
|
36
|
+
export interface Config {
|
|
37
|
+
/** Master switch; `false` renders nothing (default true). */
|
|
38
|
+
enabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* MCP server name; drives both detection and every emitted
|
|
41
|
+
* `mcp__<serverName>__*` tool name (default 'serena').
|
|
42
|
+
*/
|
|
43
|
+
serverName?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const Config: z<Config>;
|
|
46
|
+
/**
|
|
47
|
+
* Register the serena-first section and the assemble waterfall listener.
|
|
48
|
+
* @param ctx - context exposing the systemPrompt service (and, in real
|
|
49
|
+
* deployments, the `mcpConnections` registry).
|
|
50
|
+
* @param config - `enabled` (default true) and `serverName` (default 'serena').
|
|
51
|
+
*/
|
|
52
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAIxC,eAAO,MAAM,IAAI,iBAAiB,CAAA;AAClC,eAAO,MAAM,MAAM,2BAA4B,CAAA;AAE/C,qBAAqB;AACrB,MAAM,WAAW,MAAM;IACrB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAG3B,CAAA;AA8CF;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CA8BxD"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serena-first prompt steering for the CC preset.
|
|
3
|
+
*
|
|
4
|
+
* When a serena MCP server is connected, the session carries ~30
|
|
5
|
+
* `mcp__serena__*` symbol tools that answer code questions without loading
|
|
6
|
+
* whole files; the upstream `tool:read` / `tool:grep` guidance sections say
|
|
7
|
+
* nothing about them. This plugin contributes two disjoint pieces:
|
|
8
|
+
*
|
|
9
|
+
* - A registered section `serena-first` (order 105, just after the upstream
|
|
10
|
+
* tool guidance band at 100–104) whose dynamic provider renders the policy
|
|
11
|
+
* paragraph while serena is ready and `''` otherwise (empty renders are
|
|
12
|
+
* dropped at render time). It is *registered*, never inserted at assemble
|
|
13
|
+
* time — nothing in the repo inserts a brand-new section into
|
|
14
|
+
* `assembly.sections` on the waterfall.
|
|
15
|
+
* - A `system-prompt/assemble` waterfall listener registered with
|
|
16
|
+
* `{ prepend: true }` (cordis composes outermost-first and the outermost
|
|
17
|
+
* return value is authoritative) that replace-not-mutate appends one
|
|
18
|
+
* sentence each to the existing `tool:read` and `tool:grep` sections while
|
|
19
|
+
* serena is ready. `tool:write` / `tool:edit` / `tool:glob` are never
|
|
20
|
+
* rewritten: serena has no path-discovery equivalent, and edits keep the
|
|
21
|
+
* fs-observation-policy read-before-write gating.
|
|
22
|
+
*
|
|
23
|
+
* Detection is registry-only and live: a duck-typed `mcpConnections` entry
|
|
24
|
+
* (the service mcp-client always provides; the same seam `command-doctor`
|
|
25
|
+
* duck-types) with `state: 'ready'` and `toolCount > 0`, re-evaluated on
|
|
26
|
+
* every assembly, so a mid-session disconnect stops the steering on the next
|
|
27
|
+
* turn. Scope-less assemblies pass through — there is no per-scope keying
|
|
28
|
+
* possible (mirrors `tool-append-order`).
|
|
29
|
+
* @module @dsh-cc/serena-first
|
|
30
|
+
*/
|
|
31
|
+
import z from '@deepseek-ai/schemastery';
|
|
32
|
+
export const name = 'serena-first';
|
|
33
|
+
export const inject = ['systemPrompt'];
|
|
34
|
+
export const Config = z.object({
|
|
35
|
+
enabled: z.boolean().default(true),
|
|
36
|
+
serverName: z.string().default('serena'),
|
|
37
|
+
});
|
|
38
|
+
/** The sentence appended to the upstream `tool:read` section while active (leading space is deliberate). */
|
|
39
|
+
const READ_APPEND = {
|
|
40
|
+
'tool:read': ' When serena tools are available, prefer {prefix}find_symbol and {prefix}get_symbols_overview for code questions — they navigate by symbol instead of loading whole files; use read when you need exact line-numbered content (verifying an edit site, non-code files, paths outside the serena project root).',
|
|
41
|
+
'tool:grep': ' For identifier lookups, {prefix}find_referencing_symbols is usually sharper than grepping raw text.',
|
|
42
|
+
};
|
|
43
|
+
/** The registered policy section text while active. */
|
|
44
|
+
function policyText(serverName) {
|
|
45
|
+
const prefix = `mcp__${serverName}__`;
|
|
46
|
+
return [
|
|
47
|
+
`A serena MCP server is connected. Prefer its symbol tools for code questions:`,
|
|
48
|
+
`\`${prefix}find_symbol\` to locate symbols,`,
|
|
49
|
+
`\`${prefix}find_referencing_symbols\` for reference lists,`,
|
|
50
|
+
`\`${prefix}get_symbols_overview\` for a file's outline, and`,
|
|
51
|
+
`\`${prefix}search_for_pattern\` for pattern search with symbol context.`,
|
|
52
|
+
'These tools may be deferred: if they are not in your tool set yet, call `tool_search` first (for example with the query `serena find_symbol`) to activate them.',
|
|
53
|
+
'An empty serena result is not proof of absence — confirm with one cheap grep or read before concluding.',
|
|
54
|
+
'After two serena tool errors in this session, stop retrying serena and use the built-in read/grep/edit tools.',
|
|
55
|
+
'Serena only reaches files under its project root (the session launch directory); use the built-in tools for anything outside it.',
|
|
56
|
+
].join(' ');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether serena steering is active right now: enabled, and the configured
|
|
60
|
+
* registry entry is ready with at least one tool. Registry-only: when
|
|
61
|
+
* mcp-client is not mounted there are no `mcp__*` tools at all.
|
|
62
|
+
*/
|
|
63
|
+
function isActive(ctx, config) {
|
|
64
|
+
if (config.enabled !== true)
|
|
65
|
+
return false;
|
|
66
|
+
const serverName = config.serverName ?? 'serena';
|
|
67
|
+
const connections = ctx.get('mcpConnections');
|
|
68
|
+
if (connections?.entries === undefined)
|
|
69
|
+
return false;
|
|
70
|
+
const entry = connections.entries().find(candidate => candidate.name === serverName);
|
|
71
|
+
if (entry === undefined)
|
|
72
|
+
return false;
|
|
73
|
+
return entry.state === 'ready' && (entry.toolCount ?? 0) > 0;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Register the serena-first section and the assemble waterfall listener.
|
|
77
|
+
* @param ctx - context exposing the systemPrompt service (and, in real
|
|
78
|
+
* deployments, the `mcpConnections` registry).
|
|
79
|
+
* @param config - `enabled` (default true) and `serverName` (default 'serena').
|
|
80
|
+
*/
|
|
81
|
+
export function apply(ctx, config) {
|
|
82
|
+
const enabled = config.enabled ?? true;
|
|
83
|
+
const serverName = config.serverName ?? 'serena';
|
|
84
|
+
const resolved = { enabled, serverName };
|
|
85
|
+
const prefix = `mcp__${serverName}__`;
|
|
86
|
+
// Contribution A: registered policy section, empty render while inactive.
|
|
87
|
+
ctx.systemPrompt.section({
|
|
88
|
+
name: 'serena-first',
|
|
89
|
+
order: 105,
|
|
90
|
+
text: () => (isActive(ctx, resolved) ? policyText(serverName) : ''),
|
|
91
|
+
});
|
|
92
|
+
// Contribution B: rewrite the texts of existing fs sections, replace-not-mutate.
|
|
93
|
+
ctx.on('system-prompt/assemble', async (_assembly, context, next) => {
|
|
94
|
+
const result = await next();
|
|
95
|
+
// Scope-less assemblies pass through: no per-scope keying is possible
|
|
96
|
+
// (mirrors tool-append-order).
|
|
97
|
+
if (context.scope === undefined)
|
|
98
|
+
return result;
|
|
99
|
+
if (!isActive(ctx, resolved))
|
|
100
|
+
return result;
|
|
101
|
+
let changed = false;
|
|
102
|
+
const sections = result.sections.map((section) => {
|
|
103
|
+
const append = READ_APPEND[section.name];
|
|
104
|
+
if (append === undefined)
|
|
105
|
+
return section;
|
|
106
|
+
changed = true;
|
|
107
|
+
return { ...section, text: section.text + append.replaceAll('{prefix}', prefix) };
|
|
108
|
+
});
|
|
109
|
+
// Missing target sections (deployments without the fs tools) skip silently.
|
|
110
|
+
return changed ? { ...result, sections } : result;
|
|
111
|
+
}, { prepend: true });
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-cc/serena-first",
|
|
3
|
+
"description": "Serena-first prompt steering on the CC preset: a registered policy section plus replace-not-mutate appends to the upstream tool:read / tool:grep sections while a serena MCP server is ready",
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
8
|
+
"directory": "packages/compat/cc-serena-first"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@deepseek-ai/cordis": ">=0.1.1-rc.2",
|
|
25
|
+
"@deepseek-ai/schemastery": ">=0.1.1-rc.2",
|
|
26
|
+
"@deepseek-ai/dsh-system-prompt": ">=0.1.1-rc.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
30
|
+
"@deepseek-ai/dsh-agent": "link:../../../../deepseek-harness/packages/agent/agent",
|
|
31
|
+
"@deepseek-ai/dsh-scope": "link:../../../../deepseek-harness/packages/core/scope",
|
|
32
|
+
"@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
|
|
33
|
+
"@deepseek-ai/dsh-system-prompt": "link:../../../../deepseek-harness/packages/core/system-prompt",
|
|
34
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|