@kioju/dsh-cognitive-findings 0.0.0-stage → 0.4.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kiojuvr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,158 @@
1
- # Temporary Holding Version
1
+ # dsh-cognitive-findings
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A deferral queue for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) agents.
4
+
5
+ While working on one task you notice a problem that belongs to another. The two
6
+ obvious responses are both bad: detour and fix it now (the original task drifts),
7
+ or ignore it (the discovery is lost). This plugin adds the third option —
8
+ record it in one call, keep working, and pick it up later.
9
+
10
+ It is **not** a task list. A todo says "I decided to do this". A finding says
11
+ "I did not plan this, but it exists". The plugin is built so the agent never has
12
+ to decide whether it is drifting: recording *is* the deferral.
13
+
14
+ ## What it contributes
15
+
16
+ | Contribution | Effect |
17
+ |---|---|
18
+ | `finding_add` | Record a problem noticed during other work. One call, then continue. |
19
+ | `finding_list` | Read the backlog, highest priority first, with age and staleness. |
20
+ | `finding_update` | Change status or priority. Closing records a decision. |
21
+ | `finding_resolve` | Close it with a note saying how; the note becomes a decision record. |
22
+ | A short instruction section | Tells the model to record instead of detouring. |
23
+ | A passive recall context | Open findings appear in context without being asked for; stale rows are marked. |
24
+ | `/cognitive-findings` | Human command: list, `all`, `stale [days]`, `show <id>`, `resolve <id> <note>`. |
25
+ | UI cards | One `tool.call.toolview` card per tool, driven by persisted `presentationMeta`. |
26
+
27
+ Nothing here blocks work. There is no gate, no required resolution, and no
28
+ approval step.
29
+
30
+ ## Decision records
31
+
32
+ Closing a finding is a decision, so it is recorded as one. `finding_resolve` and
33
+ a closing `finding_update` append an immutable decision record to the same
34
+ document and link it from `Finding.decisionId`:
35
+
36
+ ```json
37
+ {
38
+ "id": "dec_...",
39
+ "findingId": "fnd_...",
40
+ "action": "resolved",
41
+ "summary": "installed rustup and rebuilt",
42
+ "evidence": [],
43
+ "at": "2026-11-14T05:00:00.000Z",
44
+ "sessionId": "session-..."
45
+ }
46
+ ```
47
+
48
+ The old `resolution` field is still written so v0.1 readers keep working.
49
+ Reopening a finding keeps its last decision; a second closure appends a second
50
+ decision.
51
+
52
+ ## Staleness
53
+
54
+ `open` and `triaged` findings that are older than `staleAfterDays` (default 14)
55
+ are marked stale in recall, in `/cognitive-findings`, and on the UI card. `in_progress` is
56
+ never stale — someone is already working on it, which is what staleness is
57
+ asking for.
58
+
59
+ Tune the plugin through the bundle row's `config`:
60
+
61
+ ```yaml
62
+ - id: cognitive-findings
63
+ name: '@kioju/dsh-cognitive-findings'
64
+ config:
65
+ staleAfterDays: 14
66
+ recallLimit: 10
67
+ ```
68
+
69
+ `recallLimit` caps how many active findings the passive context shows.
70
+
71
+ ## Install
72
+
73
+ In DSH, open **Plugins**, choose **Add plugin**, and enter
74
+ `@kioju/dsh-cognitive-findings`. From a shell the same install is
75
+ `dsh plugin add @kioju/dsh-cognitive-findings`. The plugin is enabled when it is added;
76
+ switch it on in **Plugins** if it is not.
77
+
78
+ The package is its own bundle (`dsh.bundle.patch`), and the shared library
79
+ `@kioju/dsh-cognitive-core` arrives as an ordinary dependency — no checkout, no build
80
+ step, nothing to place beside it. The browser half (`dsh.client`) ships with the
81
+ package; reload the page after an update.
82
+
83
+ The other cognitive plugins install the same way: `@kioju/dsh-cognitive-model` (the
84
+ graph and the recall block a session starts from) and `@kioju/dsh-cognitive-dashboard`
85
+ (the **Cognition** tab, which draws on both). Each is independent; this one needs
86
+ neither.
87
+
88
+ ## Storage
89
+
90
+ Findings live beside the workspace, not in the DSH home:
91
+
92
+ ```
93
+ <projectRoot>/.dsh/cognitive-findings/findings.json
94
+ ```
95
+
96
+ `<projectRoot>` is the nearest ancestor containing `.git`, or the session's
97
+ working directory when there is none. This is the same rule DSH uses for
98
+ `<projectRoot>/.dsh/skills`, so findings sit next to the project-local directory
99
+ the rest of the harness already respects.
100
+
101
+ The document is plain JSON (`schemaVersion: 2`): `findings` plus `decisions`.
102
+ Read it, edit it, or commit it. A v0.1 document (no `decisions`, no
103
+ `transitions`) is read as-is and upgraded on the next write.
104
+
105
+ ## Reset
106
+
107
+ ```sh
108
+ rm -rf <projectRoot>/.dsh/cognitive-findings
109
+ ```
110
+
111
+ That is the whole deletion story. There is no delete tool, no soft-delete flag,
112
+ and no retention policy — by design. A ledger that needs a maintenance mechanism
113
+ has already outgrown itself.
114
+
115
+ ## Design notes
116
+
117
+ - **No gate.** `priority` is a hint, never an enforcement. Nothing refuses to
118
+ proceed because a `P0` is open.
119
+ - **No self-assessment.** The agent is never asked "is this out of scope?" —
120
+ only "what did you notice?". The finding records which session it came from
121
+ (`discoveredDuring`), and that is enough to know it was a deferral.
122
+ - **Duplicates are reported, not added.** Recording the same active title and
123
+ kind twice returns the original, which is also the signal that recall did not
124
+ work.
125
+ - **Corrupt files read as empty.** A hand-edited or truncated document never
126
+ takes the plugin down.
127
+ - **No auto-capture.** Observing tool failures and inventing findings was
128
+ deliberately left out of v0.2: false positives would poison the ledger before
129
+ recall has proven itself.
130
+
131
+ ## Compatibility
132
+
133
+ Built against DSH `0.2.2-rc.3` (`engines.dsh: >=0.2.2-rc.3 <0.3.0`).
134
+
135
+ The plugin imports nothing from `@deepseek-ai/*`; it declares the small slice of
136
+ the host surface it uses structurally in `src/cordis.ts`. Re-verify that slice
137
+ against the installed release before upgrading DSH.
138
+
139
+ ## Development
140
+
141
+ ```sh
142
+ npm install
143
+ npm run build
144
+ npm test # node --test (spawns one process per test file)
145
+ npm run test:sandbox # in-process runner for environments that deny child spawn
146
+ ```
147
+
148
+ `npm test` needs to spawn test processes. Inside the DSH sandbox that spawn can
149
+ be denied, so `npm run test:sandbox` imports the same test files into one
150
+ process instead. Both run the same cases; use the sandbox variant only where the
151
+ runner itself is blocked.
152
+
153
+ Tests use the built-in Node test runner and a stand-in host, so they run without
154
+ a DSH installation.
155
+
156
+ ## License
157
+
158
+ MIT
package/client.js ADDED
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Browser half of dsh-cognitive-findings.
3
+ *
4
+ * Registers one keyed `tool.call.toolview` card per finding tool. The card reads
5
+ * the persisted `presentationMeta` projection (`block.meta`) rather than
6
+ * parsing model-facing text, so it replays identically from the session log.
7
+ *
8
+ * This file is the built client artifact the `dsh.client` scan serves; it is
9
+ * plain JS on purpose and needs no bundler. React comes from the browser module
10
+ * table. All copy goes through the Client locale service.
11
+ */
12
+ window.__ModuleLoader__.load({
13
+ id: '@kioju/dsh-cognitive-findings',
14
+ factory(require) {
15
+ const React = require('react')
16
+ const h = React.createElement
17
+
18
+ const NS = 'cognitive-findings'
19
+
20
+ const en = {
21
+ 'title.add': 'Finding recorded',
22
+ 'title.addDuplicate': 'Finding already recorded',
23
+ 'title.update': 'Finding updated',
24
+ 'title.resolve': 'Finding resolved',
25
+ 'title.list': 'Findings',
26
+ 'title.running': 'Findings',
27
+ 'state.running': 'Working…',
28
+ 'state.failed': 'The finding tool failed',
29
+ 'label.stale': 'stale',
30
+ 'label.more': 'more',
31
+ 'label.none': 'No findings',
32
+ 'label.decision': 'decision',
33
+ 'label.days': 'd',
34
+ 'status.open': 'open',
35
+ 'status.triaged': 'triaged',
36
+ 'status.in_progress': 'in progress',
37
+ 'status.resolved': 'resolved',
38
+ 'status.wontfix': 'wontfix',
39
+ 'status.duplicate': 'duplicate',
40
+ }
41
+
42
+ const zh = {
43
+ 'title.add': '已记录 finding',
44
+ 'title.addDuplicate': '该 finding 已记录',
45
+ 'title.update': '已更新 finding',
46
+ 'title.resolve': '已解决 finding',
47
+ 'title.list': 'Findings',
48
+ 'title.running': 'Findings',
49
+ 'state.running': '处理中…',
50
+ 'state.failed': 'finding 工具执行失败',
51
+ 'label.stale': '滞留',
52
+ 'label.more': '条更多',
53
+ 'label.none': '没有 finding',
54
+ 'label.decision': '决定',
55
+ 'label.days': '天',
56
+ 'status.open': '待处理',
57
+ 'status.triaged': '已分类',
58
+ 'status.in_progress': '进行中',
59
+ 'status.resolved': '已解决',
60
+ 'status.wontfix': '不修复',
61
+ 'status.duplicate': '重复',
62
+ }
63
+
64
+ const ja = {
65
+ 'title.add': 'Finding を記録しました',
66
+ 'title.addDuplicate': 'Finding は記録済みです',
67
+ 'title.update': 'Finding を更新しました',
68
+ 'title.resolve': 'Finding を解決しました',
69
+ 'title.list': 'Findings',
70
+ 'title.running': 'Findings',
71
+ 'state.running': '処理中…',
72
+ 'state.failed': 'Finding ツールが失敗しました',
73
+ 'label.stale': '滞留',
74
+ 'label.more': '件',
75
+ 'label.none': 'Finding はありません',
76
+ 'label.decision': '決定',
77
+ 'label.days': '日',
78
+ 'status.open': '未対応',
79
+ 'status.triaged': 'トリアージ済み',
80
+ 'status.in_progress': '対応中',
81
+ 'status.resolved': '解決済み',
82
+ 'status.wontfix': '対応しない',
83
+ 'status.duplicate': '重複',
84
+ }
85
+
86
+ const PRIORITY_COLOR = {
87
+ P0: 'var(--dsw-alias-state-error-primary)',
88
+ P1: 'var(--dsw-alias-state-warn-primary)',
89
+ P2: 'var(--dsw-alias-label-secondary)',
90
+ P3: 'var(--dsw-alias-label-tertiary)',
91
+ }
92
+
93
+ const MAX_CARD_ROWS = 8
94
+
95
+ const styles = {
96
+ card: {
97
+ display: 'flex',
98
+ flexDirection: 'column',
99
+ gap: '6px',
100
+ padding: '8px 10px',
101
+ border: '1px solid var(--dsw-alias-border-l2)',
102
+ borderRadius: '10px',
103
+ background: 'var(--dsw-alias-card-fill)',
104
+ color: 'var(--dsw-alias-label-primary)',
105
+ fontSize: '13px',
106
+ lineHeight: 1.45,
107
+ },
108
+ header: {
109
+ display: 'flex',
110
+ alignItems: 'center',
111
+ gap: '6px',
112
+ color: 'var(--dsw-alias-label-secondary)',
113
+ fontSize: '12px',
114
+ },
115
+ icon: { flex: 'none', opacity: 0.85 },
116
+ stale: {
117
+ marginLeft: 'auto',
118
+ color: 'var(--dsw-alias-state-warn-primary)',
119
+ fontSize: '11px',
120
+ },
121
+ row: {
122
+ display: 'flex',
123
+ alignItems: 'baseline',
124
+ gap: '8px',
125
+ minWidth: 0,
126
+ },
127
+ priority: {
128
+ flex: 'none',
129
+ fontWeight: 600,
130
+ fontSize: '11px',
131
+ fontVariantNumeric: 'tabular-nums',
132
+ },
133
+ title: {
134
+ flex: 1,
135
+ minWidth: 0,
136
+ overflow: 'hidden',
137
+ textOverflow: 'ellipsis',
138
+ whiteSpace: 'nowrap',
139
+ },
140
+ meta: {
141
+ flex: 'none',
142
+ color: 'var(--dsw-alias-label-tertiary)',
143
+ fontSize: '11px',
144
+ fontVariantNumeric: 'tabular-nums',
145
+ },
146
+ summary: {
147
+ color: 'var(--dsw-alias-label-secondary)',
148
+ overflowWrap: 'anywhere',
149
+ },
150
+ error: { color: 'var(--dsw-alias-state-error-primary)' },
151
+ body: { display: 'flex', flexDirection: 'column', gap: '4px' },
152
+ more: { color: 'var(--dsw-alias-label-tertiary)', fontSize: '11px' },
153
+ empty: { color: 'var(--dsw-alias-label-tertiary)' },
154
+ }
155
+
156
+ function icon() {
157
+ return h(
158
+ 'svg',
159
+ {
160
+ width: 14,
161
+ height: 14,
162
+ viewBox: '0 0 16 16',
163
+ fill: 'none',
164
+ 'aria-hidden': true,
165
+ style: styles.icon,
166
+ },
167
+ h('rect', { x: 2.5, y: 2.5, width: 11, height: 11, rx: 2.5, stroke: 'currentColor', strokeWidth: 1.4 }),
168
+ h('path', { d: 'M5 6.5h6M5 9.5h4', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }),
169
+ h('circle', { cx: 11.6, cy: 11.6, r: 1.8, fill: 'var(--dsw-alias-brand-primary)' }),
170
+ )
171
+ }
172
+
173
+ function priorityChip(priority) {
174
+ return h(
175
+ 'span',
176
+ { style: { ...styles.priority, color: PRIORITY_COLOR[priority] ?? PRIORITY_COLOR.P2 } },
177
+ priority,
178
+ )
179
+ }
180
+
181
+ function ageText(finding, t) {
182
+ const days = typeof finding.ageDays === 'number' ? finding.ageDays : undefined
183
+ if (days === undefined) return ''
184
+ return `${days}${t('label.days')}`
185
+ }
186
+
187
+ function findingRow(finding, t) {
188
+ const statusKey = `status.${finding.status}`
189
+ const status = t(statusKey)
190
+ const statusLabel = status === statusKey ? finding.status : status
191
+ const meta = [statusLabel, ageText(finding, t)].filter((part) => part !== '').join(' · ')
192
+ return h(
193
+ 'div',
194
+ { style: styles.row, key: finding.id },
195
+ priorityChip(finding.priority),
196
+ h('span', { style: styles.title, title: finding.title }, finding.title),
197
+ h('span', { style: styles.meta }, meta),
198
+ finding.stale ? h('span', { style: styles.stale }, t('label.stale')) : null,
199
+ )
200
+ }
201
+
202
+ function card(title, children, extra) {
203
+ return h(
204
+ 'div',
205
+ { style: styles.card, 'data-tool': 'cognitive-findings' },
206
+ h('div', { style: styles.header }, icon(), h('span', null, title), extra ?? null),
207
+ ...children,
208
+ )
209
+ }
210
+
211
+ function runningCard(t) {
212
+ return card(t('title.running'), [h('span', { style: styles.empty }, t('state.running'))])
213
+ }
214
+
215
+ function resultText(block) {
216
+ if (block === undefined || block === null || block.kind !== 'tool-result') return ''
217
+ const parts = []
218
+ for (const item of block.content ?? []) {
219
+ if (item !== null && typeof item === 'object' && item.type === 'text' && typeof item.text === 'string') {
220
+ parts.push(item.text)
221
+ }
222
+ }
223
+ return parts.join('\n')
224
+ }
225
+
226
+ function argsOf(block) {
227
+ if (block === undefined || block === null) return undefined
228
+ const raw = typeof block.argsRaw === 'string'
229
+ ? block.argsRaw
230
+ : block.call !== null && block.call !== undefined && typeof block.call.argsRaw === 'string'
231
+ ? block.call.argsRaw
232
+ : ''
233
+ if (raw === '') return undefined
234
+ try {
235
+ const parsed = JSON.parse(raw)
236
+ return parsed !== null && typeof parsed === 'object' ? parsed : undefined
237
+ } catch {
238
+ return undefined
239
+ }
240
+ }
241
+
242
+ function metaOf(block) {
243
+ if (block === undefined || block === null || block.kind !== 'tool-result') return undefined
244
+ const meta = block.meta
245
+ if (meta === null || typeof meta !== 'object') return undefined
246
+ return meta.v === 1 ? meta : undefined
247
+ }
248
+
249
+ function titleFor(meta, t) {
250
+ if (meta === undefined) return t('title.running')
251
+ if (meta.ok === false) return t('state.failed')
252
+ switch (meta.action) {
253
+ case 'add': return meta.duplicate === true ? t('title.addDuplicate') : t('title.add')
254
+ case 'update': return t('title.update')
255
+ case 'resolve': return t('title.resolve')
256
+ case 'list': return t('title.list')
257
+ default: return t('title.running')
258
+ }
259
+ }
260
+
261
+ function singleCard(meta, t) {
262
+ if (meta.ok === false) {
263
+ return card(titleFor(meta, t), [h('span', { style: styles.error }, String(meta.error ?? ''))])
264
+ }
265
+ const finding = meta.finding
266
+ if (finding === undefined || finding === null) {
267
+ return card(titleFor(meta, t), [])
268
+ }
269
+ const children = [findingRow(finding, t)]
270
+ if (meta.decision !== undefined && meta.decision !== null) {
271
+ children.push(
272
+ h(
273
+ 'div',
274
+ { style: styles.summary },
275
+ `${t('label.decision')} ${meta.decision.id}: ${meta.decision.summary}`,
276
+ ),
277
+ )
278
+ }
279
+ return card(titleFor(meta, t), children)
280
+ }
281
+
282
+ function listCard(meta, t) {
283
+ const findings = Array.isArray(meta.findings) ? meta.findings : []
284
+ const staleCount = typeof meta.staleCount === 'number' ? meta.staleCount : 0
285
+ const extra = staleCount > 0
286
+ ? h('span', { style: styles.stale }, `${staleCount} ${t('label.stale')}`)
287
+ : null
288
+ const shown = findings.slice(0, MAX_CARD_ROWS)
289
+ const children = shown.map((finding) => findingRow(finding, t))
290
+ if (children.length === 0) {
291
+ children.push(h('span', { style: styles.empty }, t('label.none')))
292
+ }
293
+ const more = (typeof meta.more === 'number' ? meta.more : 0) + (findings.length - shown.length)
294
+ if (more > 0) {
295
+ children.push(h('span', { style: styles.more }, `+${more} ${t('label.more')}`))
296
+ }
297
+ return card(titleFor(meta, t), children, extra)
298
+ }
299
+
300
+ function fallbackCard(block, t) {
301
+ const args = argsOf(block)
302
+ const text = resultText(block).split('\n').filter((line) => line !== '').slice(0, 4)
303
+ const children = []
304
+ if (args !== undefined && typeof args.title === 'string') {
305
+ children.push(h('span', { style: styles.title, title: args.title }, args.title))
306
+ }
307
+ if (text.length > 0) {
308
+ children.push(h('div', { style: styles.summary, key: 'text' }, text.join('\n')))
309
+ }
310
+ return card(t('title.list'), children)
311
+ }
312
+
313
+ function FindingCard(props) {
314
+ const t = props.t
315
+ if (props.phase === 'preparing') return runningCard(t)
316
+ const meta = metaOf(props.block)
317
+ if (meta === undefined) {
318
+ if (props.phase === 'start') return runningCard(t)
319
+ return fallbackCard(props.block, t)
320
+ }
321
+ if (meta.action === 'list') return listCard(meta, t)
322
+ return singleCard(meta, t)
323
+ }
324
+
325
+ return {
326
+ inject: ['slots', 'locale'],
327
+ apply(ctx) {
328
+ ctx.effect(() => ctx.locale.register(NS, { zh, en, ja }), 'cognitive-findings: dictionaries')
329
+ for (const key of ['finding_add', 'finding_list', 'finding_update', 'finding_resolve']) {
330
+ ctx.slots.inject('tool.call.toolview', () => ctx.slots.register(
331
+ { name: 'tool.call.toolview', key, locale: NS },
332
+ FindingCard,
333
+ ))
334
+ }
335
+ },
336
+ }
337
+ },
338
+ })
@@ -0,0 +1,21 @@
1
+ # dsh-cognitive-findings — DSH bundle patch layer
2
+ #
3
+ # Registers the findings ledger plugin. It contributes four model tools
4
+ # (finding_add / finding_list / finding_update / finding_resolve), a passive
5
+ # recall context, a short instruction, the `/cognitive-findings` human command,
6
+ # and one UI card per tool.
7
+ #
8
+ # Storage lives beside the workspace, not in the DSH home:
9
+ # <projectRoot>/.dsh/cognitive-findings/findings.json
10
+ #
11
+ # Reset is physical deletion of that directory. There is no delete tool.
12
+
13
+ - insert:
14
+ - id: cognitive-findings
15
+ name: '@kioju/dsh-cognitive-findings'
16
+ config:
17
+ # Active findings at least this old are marked stale in recall,
18
+ # /cognitive-findings, and the UI card.
19
+ staleAfterDays: 14
20
+ # How many active findings the passive recall prompt shows.
21
+ recallLimit: 10
package/icon.svg ADDED
@@ -0,0 +1,5 @@
1
+ <svg width="36" height="36" viewBox="0 0 36 36" xmlns="http://www.w3.org/2000/svg">
2
+ <rect x="8" y="7" width="20" height="22" rx="4" fill="none" stroke="#4D6BFE" stroke-width="2"/>
3
+ <path d="M13 13.5h10M13 18h7" stroke="#4D6BFE" stroke-width="2" stroke-linecap="round"/>
4
+ <circle cx="24.5" cy="23" r="3" fill="#E0A34A"/>
5
+ </svg>
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Structural declarations for the host surface this plugin uses.
3
+ *
4
+ * The plugin imports nothing from `@deepseek-ai/*`: the host supplies `ctx`,
5
+ * and structural typing keeps this package installable without pinning a
6
+ * specific DSH release's type packages.
7
+ *
8
+ * Verified against DSH 0.2.2-rc.3:
9
+ * - `ctx.tools.register(definition)` (`@deepseek-ai/dsh-tools`, ToolsService)
10
+ * - `ctx.systemPrompt.section(section)` (`@deepseek-ai/dsh-system-prompt`)
11
+ * - `ctx.systemPrompt.context(context)` (`@deepseek-ai/dsh-system-prompt`)
12
+ * - `ctx.commands.register(definition)` (`@deepseek-ai/dsh-commands`, CommandRuntime)
13
+ * - `ctx.inject(deps, callback)` (Cordis registry; optional services)
14
+ * - `exec.agent.sessionId`, `exec.agent.session.header.cwd`
15
+ * (`@deepseek-ai/dsh-agent`, `@deepseek-ai/dsh-session`)
16
+ */
17
+ /** Raw JSON Schema as accepted by `ctx.tools.register`. */
18
+ export type JsonSchema = Record<string, unknown>;
19
+ export interface ContentBlock {
20
+ readonly type: 'text';
21
+ readonly text: string;
22
+ }
23
+ export interface ToolOutputDefinition {
24
+ readonly schema: JsonSchema;
25
+ render(args: unknown, value: unknown): ContentBlock[];
26
+ /**
27
+ * Pure, replayable UI projection persisted on `tool/result` (`result.meta`).
28
+ * Client cards read it instead of parsing the model-facing text.
29
+ */
30
+ presentationMeta?(args: unknown, value: unknown): unknown;
31
+ }
32
+ export interface ToolDefinition {
33
+ readonly name: string;
34
+ readonly description: string;
35
+ readonly parameters: JsonSchema;
36
+ readonly output: ToolOutputDefinition;
37
+ execute(args: unknown, exec: ToolRunContext): Promise<unknown>;
38
+ }
39
+ /** The slice of a DSH Agent this plugin reads. */
40
+ export interface AgentLike {
41
+ /** Present on an AgentHandle; the tool context usually receives the Agent. */
42
+ readonly sessionId?: string;
43
+ readonly session?: {
44
+ /** `SessionHeader.id` mirrors the Session's own id. */
45
+ readonly header?: {
46
+ readonly id?: string;
47
+ readonly cwd?: string;
48
+ };
49
+ };
50
+ }
51
+ export interface ToolRunContext {
52
+ readonly signal?: AbortSignal;
53
+ readonly agent?: AgentLike;
54
+ readonly callId?: string;
55
+ }
56
+ export interface PromptSection {
57
+ readonly name: string;
58
+ readonly order: number;
59
+ readonly text: string | ((context: unknown) => string);
60
+ readonly interpolate?: boolean;
61
+ }
62
+ export interface PromptContext {
63
+ readonly name: string;
64
+ readonly order: number;
65
+ readonly text: string | ((context: unknown) => string);
66
+ readonly interpolate?: boolean;
67
+ readonly required?: boolean;
68
+ }
69
+ /** The assembly context handed to prompt contributors. */
70
+ export interface AssembleContextLike {
71
+ readonly scope?: unknown;
72
+ readonly signal?: AbortSignal;
73
+ /**
74
+ * The agent whose prompt is being assembled. `@deepseek-ai/dsh-system-prompt`
75
+ * declares only `scope`/`signal`; other packages merge this field in, and the
76
+ * host populates it (see `dsh-working-directory`, which reads
77
+ * `context.agent.session`).
78
+ */
79
+ readonly agent?: AgentLike;
80
+ }
81
+ /** One command line invocation, as `@deepseek-ai/dsh-commands` defines it. */
82
+ export interface CommandInvocation {
83
+ readonly commandId: string;
84
+ readonly agent: AgentLike;
85
+ /** Exact text following the command name, including separator whitespace. */
86
+ readonly rawInput: string;
87
+ readonly signal?: AbortSignal;
88
+ }
89
+ export type CommandResult = {
90
+ readonly kind: 'success';
91
+ readonly text?: string;
92
+ } | {
93
+ readonly kind: 'error';
94
+ readonly text: string;
95
+ };
96
+ /** Plugin-owned human command registration. */
97
+ export interface CommandDefinition {
98
+ /** Lowercase command name without the leading slash. */
99
+ readonly name: string;
100
+ readonly description: string;
101
+ readonly input?: {
102
+ readonly hint: string;
103
+ readonly attachments?: boolean;
104
+ };
105
+ readonly handler: (invocation: CommandInvocation) => CommandResult | Promise<CommandResult>;
106
+ }
107
+ export interface CommandsService {
108
+ register(definition: CommandDefinition): () => void;
109
+ }
110
+ export interface Context {
111
+ readonly tools: {
112
+ register(definition: ToolDefinition): () => void;
113
+ };
114
+ readonly systemPrompt: {
115
+ section(section: PromptSection): () => void;
116
+ context(context: PromptContext): () => void;
117
+ };
118
+ /** Present only where an interactive command adapter is composed. */
119
+ readonly commands?: CommandsService;
120
+ /**
121
+ * Start a child plugin once these services exist. Used for optional
122
+ * capabilities (`commands`) so the plugin still works without them.
123
+ */
124
+ inject?(deps: string[], callback: (ctx: Context) => void): unknown;
125
+ /** Cordis event subscription; `prepend` places a waterfall listener first. */
126
+ on(event: string, listener: (...args: any[]) => unknown, options?: {
127
+ prepend?: boolean;
128
+ }): () => void;
129
+ /** Cordis service lookup; used only for optional, defensive access. */
130
+ get?(name: string): unknown;
131
+ }