@banbolee/dsh-fish-shell 0.7.0 → 0.8.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +318 -13
  3. package/README.zh.md +101 -4
  4. package/THIRD-PARTY-NOTICES.md +91 -0
  5. package/cordis.patch.yml +56 -0
  6. package/node_modules/@deepseek-ai/cosmokit/LICENSE +21 -0
  7. package/node_modules/@deepseek-ai/cosmokit/README.md +30 -0
  8. package/node_modules/@deepseek-ai/cosmokit/lib/index.js +418 -0
  9. package/node_modules/@deepseek-ai/cosmokit/lib/types/array.d.ts +15 -0
  10. package/node_modules/@deepseek-ai/cosmokit/lib/types/array.d.ts.map +1 -0
  11. package/node_modules/@deepseek-ai/cosmokit/lib/types/index.d.ts +13 -0
  12. package/node_modules/@deepseek-ai/cosmokit/lib/types/index.d.ts.map +1 -0
  13. package/node_modules/@deepseek-ai/cosmokit/lib/types/misc.d.ts +41 -0
  14. package/node_modules/@deepseek-ai/cosmokit/lib/types/misc.d.ts.map +1 -0
  15. package/node_modules/@deepseek-ai/cosmokit/lib/types/string.d.ts +89 -0
  16. package/node_modules/@deepseek-ai/cosmokit/lib/types/string.d.ts.map +1 -0
  17. package/node_modules/@deepseek-ai/cosmokit/lib/types/time.d.ts +19 -0
  18. package/node_modules/@deepseek-ai/cosmokit/lib/types/time.d.ts.map +1 -0
  19. package/node_modules/@deepseek-ai/cosmokit/lib/types/types.d.ts +42 -0
  20. package/node_modules/@deepseek-ai/cosmokit/lib/types/types.d.ts.map +1 -0
  21. package/node_modules/@deepseek-ai/cosmokit/lib/types/volatile.d.ts +40 -0
  22. package/node_modules/@deepseek-ai/cosmokit/lib/types/volatile.d.ts.map +1 -0
  23. package/node_modules/@deepseek-ai/cosmokit/package.json +32 -0
  24. package/node_modules/@deepseek-ai/cosmokit/src/array.ts +42 -0
  25. package/node_modules/@deepseek-ai/cosmokit/src/index.ts +12 -0
  26. package/node_modules/@deepseek-ai/cosmokit/src/misc.ts +78 -0
  27. package/node_modules/@deepseek-ai/cosmokit/src/string.ts +113 -0
  28. package/node_modules/@deepseek-ai/cosmokit/src/time.ts +92 -0
  29. package/node_modules/@deepseek-ai/cosmokit/src/types.ts +168 -0
  30. package/node_modules/@deepseek-ai/cosmokit/src/volatile.ts +86 -0
  31. package/node_modules/@deepseek-ai/dsh-tool-terminal/LICENSE +21 -0
  32. package/node_modules/@deepseek-ai/dsh-tool-terminal/README.i18n.yaml +100 -0
  33. package/node_modules/@deepseek-ai/dsh-tool-terminal/README.md +186 -0
  34. package/node_modules/@deepseek-ai/dsh-tool-terminal/README.zh.md +186 -0
  35. package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/index.js +646 -0
  36. package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/types/background.d.ts +20 -0
  37. package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/types/index.d.ts +32 -0
  38. package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/types/render.d.ts +81 -0
  39. package/node_modules/@deepseek-ai/dsh-tool-terminal/package.json +63 -0
  40. package/node_modules/@deepseek-ai/schemastery/LICENSE +21 -0
  41. package/node_modules/@deepseek-ai/schemastery/README.md +393 -0
  42. package/node_modules/@deepseek-ai/schemastery/lib/index.cjs +635 -0
  43. package/node_modules/@deepseek-ai/schemastery/lib/index.mjs +635 -0
  44. package/node_modules/@deepseek-ai/schemastery/lib/types/index.d.ts +211 -0
  45. package/node_modules/@deepseek-ai/schemastery/lib/types/index.d.ts.map +1 -0
  46. package/node_modules/@deepseek-ai/schemastery/package.json +39 -0
  47. package/node_modules/@deepseek-ai/schemastery/src/index.ts +962 -0
  48. package/node_modules/@standard-schema/spec/LICENSE +21 -0
  49. package/node_modules/@standard-schema/spec/README.md +198 -0
  50. package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
  51. package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
  52. package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
  53. package/node_modules/@standard-schema/spec/dist/index.js +0 -0
  54. package/node_modules/@standard-schema/spec/package.json +52 -0
  55. package/package.json +56 -42
  56. package/terminal-tools.js +259 -0
  57. package/terminal.js +297 -0
  58. package/tool.js +1 -1
@@ -0,0 +1,86 @@
1
+ /** Shared config references used by schema validators and plugin runtimes. */
2
+
3
+ const write = Symbol.for('cosmokit.volatile.write')
4
+
5
+ /** Recursively readonly data returned by a volatile config reference. */
6
+ export type VolatileSnapshot<T> = T extends object ? { readonly [K in keyof T]: VolatileSnapshot<T[K]> } : T
7
+
8
+ /** A stable reference; keep the reference, or capture its value for one operation only. */
9
+ export interface Volatile<T> {
10
+ /** @returns the current immutable snapshot, including undefined for an absent value. */
11
+ get(): VolatileSnapshot<T>
12
+ }
13
+
14
+ interface WritableVolatile extends Volatile<unknown> {
15
+ [write](value: unknown): void
16
+ }
17
+
18
+ function snapshot(value: unknown, ancestors = new Set<object>()): unknown {
19
+ if (typeof value === 'function') throw new TypeError('volatile config cannot contain functions')
20
+ if (value === null || typeof value !== 'object') return value
21
+ if (ancestors.has(value)) throw new TypeError('volatile config cannot contain cycles')
22
+ ancestors.add(value)
23
+ try {
24
+ if (Array.isArray(value)) return Object.freeze(value.map(item => snapshot(item, ancestors)))
25
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
26
+ throw new TypeError('volatile config objects must be plain objects or arrays')
27
+ }
28
+ return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])))
29
+ } finally {
30
+ ancestors.delete(value)
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Create a detached reference containing an immutable copy of the supplied data.
36
+ * @param value - validated config data; class instances and functions are unsupported.
37
+ * @returns a reference whose value is updated only by its owning runtime.
38
+ */
39
+ export function createVolatile<T>(value: T): Volatile<T> {
40
+ let current = snapshot(value)
41
+ return Object.freeze({
42
+ get: () => current,
43
+ [write]: (value: unknown) => { current = value },
44
+ }) as Volatile<T>
45
+ }
46
+
47
+ /**
48
+ * Identify references across ESM/CJS copies of the shared library.
49
+ * @param value - a parsed config value.
50
+ * @returns whether the value implements the shared reference protocol.
51
+ */
52
+ export function isVolatile(value: unknown): value is Volatile<unknown> {
53
+ return typeof value === 'object' && value !== null && write in value
54
+ }
55
+
56
+ /**
57
+ * Collect config references without descending into their snapshots or opaque objects.
58
+ * @internal
59
+ * @param value - parsed config; cyclic ordinary fields are visited once per path.
60
+ * @returns references and their object-key paths, including an empty path for a root reference.
61
+ */
62
+ export function volatileEntries(value: unknown): { path: string[]; ref: Volatile<unknown> }[] {
63
+ const ancestors = new Set<object>()
64
+ function visit(value: unknown, path: string[]): { path: string[]; ref: Volatile<unknown> }[] {
65
+ if (isVolatile(value)) return [{ path, ref: value }]
66
+ if (!value || typeof value !== 'object' || ancestors.has(value)) return []
67
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return []
68
+ ancestors.add(value)
69
+ try {
70
+ return Object.entries(value).flatMap(([key, child]) => visit(child, [...path, key]))
71
+ } finally {
72
+ ancestors.delete(value)
73
+ }
74
+ }
75
+ return visit(value, [])
76
+ }
77
+
78
+ /**
79
+ * Commit an already validated immutable snapshot from another reference.
80
+ * @internal
81
+ * @param target - the owning plugin's stable reference.
82
+ * @param source - a newly parsed candidate reference.
83
+ */
84
+ export function updateVolatile(target: Volatile<unknown>, source: Volatile<unknown>): void {
85
+ ;(target as WritableVolatile)[write](source.get())
86
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
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.
@@ -0,0 +1,100 @@
1
+ # Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
2
+ # section, a hash of its English and Chinese blocks outside code blocks and generated regions.
3
+ # After editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/terminal/tool-terminal/README.md
5
+ /:
6
+ en: fc74eecdf1f2ad5b
7
+ zh: dc9c2a28ce96ce67
8
+ /deepseek-ai-dsh-tool-terminal:
9
+ en: 47fa84b67ff171b9
10
+ zh: bbd625bbf85694e1
11
+ /deepseek-ai-dsh-tool-terminal/summary:
12
+ en: c0e810d4279333a5
13
+ zh: 7e79b6a63fa10029
14
+ /deepseek-ai-dsh-tool-terminal/table-of-contents:
15
+ en: d152484eb41ac6b4
16
+ zh: 09388d293f9be9cb
17
+ /deepseek-ai-dsh-tool-terminal/use-this-package:
18
+ en: dcc6b2ac23494026
19
+ zh: f5b755ec75994458
20
+ /deepseek-ai-dsh-tool-terminal/use-this-package/the-six-tools:
21
+ en: 3e9b6211dd72ec64
22
+ zh: aa4cd15195cb43d6
23
+ /deepseek-ai-dsh-tool-terminal/use-this-package/composition:
24
+ en: 4ce2a232b60ff77d
25
+ zh: 3a8a0f13371ca6b9
26
+ /deepseek-ai-dsh-tool-terminal/use-this-package/configuration:
27
+ en: 0af09df923fcb322
28
+ zh: 6d9d766c24c530bc
29
+ /deepseek-ai-dsh-tool-terminal/use-this-package/background-sends:
30
+ en: 2ad49d4f69deb06d
31
+ zh: 5f29972b5feec7e3
32
+ /deepseek-ai-dsh-tool-terminal/use-this-package/observable-outcomes-and-failures:
33
+ en: 321a982fdbbf4ada
34
+ zh: 8c2636e5379815e1
35
+ /deepseek-ai-dsh-tool-terminal/understand-the-implementation:
36
+ en: 6302fca8fef89136
37
+ zh: 6327d56edb798ab2
38
+ /deepseek-ai-dsh-tool-terminal/understand-the-implementation/design-concept:
39
+ en: dc500eeff749a06f
40
+ zh: 9402f5005d7ca338
41
+ /deepseek-ai-dsh-tool-terminal/understand-the-implementation/source-map:
42
+ en: a59f4e76dc926bed
43
+ zh: 24813cb1bd8fbf32
44
+ /deepseek-ai-dsh-tool-terminal/understand-the-implementation/result-bounding:
45
+ en: c1953779a1617d09
46
+ zh: cc6a4a6e76fa021c
47
+ /deepseek-ai-dsh-tool-terminal/understand-the-implementation/ui-render-intents:
48
+ en: 03e5bb37f0c3aada
49
+ zh: 8d51eeb758eabe9c
50
+ /deepseek-ai-dsh-tool-terminal/further-exploration:
51
+ en: 45a0c33ed8104fb1
52
+ zh: ae50c9e583ef4867
53
+ /deepseek-ai-dsh-tool-terminal/model-experience:
54
+ en: 215e7ba838619b7b
55
+ zh: a311da3843709f90
56
+ /deepseek-ai-dsh-tool-terminal/model-experience/system-prompt:
57
+ en: cf78b9dd5596495f
58
+ zh: bd44560f8c2435e8
59
+ /deepseek-ai-dsh-tool-terminal/model-experience/system-prompt/what-the-model-sees:
60
+ en: 99887ae1de81aaeb
61
+ zh: 4846a1d3ea8a3dc3
62
+ /deepseek-ai-dsh-tool-terminal/model-experience/system-prompt/what-the-model-sees/terminal-guidance:
63
+ en: 3ab4211f41e40211
64
+ zh: b730cc3f278be17c
65
+ /deepseek-ai-dsh-tool-terminal/model-experience/system-prompt/token-effect:
66
+ en: c9d6d1a8238b74ab
67
+ zh: 7f4b12d6180b9bac
68
+ /deepseek-ai-dsh-tool-terminal/model-experience/system-prompt/kv-cache-effect:
69
+ en: 7fdc10b826aeeb51
70
+ zh: 998c86c09efe43bd
71
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-schemas:
72
+ en: 3039bc5e7a796b21
73
+ zh: 6b7a9eaf69c9ea53
74
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-schemas/what-the-model-sees:
75
+ en: 32127d768242d8c4
76
+ zh: 3095d987d6011f44
77
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-schemas/token-effect:
78
+ en: 824644a1f5fe76df
79
+ zh: b34c7dd78c5ce3cd
80
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-schemas/kv-cache-effect:
81
+ en: c8cbbef533bdb90f
82
+ zh: c0b00813b8419f46
83
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-results-and-task-context:
84
+ en: 54e0c8a019f02479
85
+ zh: 7331b10d1a455d59
86
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-results-and-task-context/what-the-model-sees:
87
+ en: cc1e88a508d0679e
88
+ zh: a219be277705c0ab
89
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-results-and-task-context/token-effect:
90
+ en: e4746b7b386944df
91
+ zh: be52cd2fd38276b5
92
+ /deepseek-ai-dsh-tool-terminal/model-experience/tool-results-and-task-context/kv-cache-effect:
93
+ en: ac583ab16185a93c
94
+ zh: 78df55a519b2ec1f
95
+ /deepseek-ai-dsh-tool-terminal/known-limitations-and-deferred-work:
96
+ en: ba974b703d6ed0bc
97
+ zh: 655810d5d338343c
98
+ /deepseek-ai-dsh-tool-terminal/known-limitations-and-deferred-work/dev-note:
99
+ en: a4c4901129addb49
100
+ zh: 78f339ece6da423b
@@ -0,0 +1,186 @@
1
+ ---
2
+ description: "Six model-facing persistent terminal tools with owner isolation, bounded results, and optional background sends for agents that need cross-call terminal state."
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-tool-terminal
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ Use `dsh-tool-terminal` when an agent needs persistent terminal state or interactive input across calls. It can open, send to, read, signal, close, and list terminal sessions while preventing one agent from operating another agent's sessions. Sends may wait for bounded foreground output or return a background job id for later collection or interruption. `maxResultBytes` caps each result, which remains in session history until compaction. The model is guided to prefer one-shot tools for bounded work.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Use this package](#use-this-package)
17
+ - [Understand the implementation](#understand-the-implementation)
18
+ - [Further Exploration](#further-exploration)
19
+ - [Model Experience](#model-experience)
20
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
21
+ - [Dev Note](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## Use this package
27
+
28
+ Enable these tools when the composition mounts a terminal backend and the model should be able to use terminal state across calls — stepping a debugger, exploring in a REPL, or returning to a shell after interrupting a foreground command. The guidance section steers the model toward the one-shot bash, read, write, and edit tools for bounded operations.
29
+
30
+ ### The six tools
31
+
32
+ | Tool | What it does | Result |
33
+ |---|---|---|
34
+ | `terminal_open` | Creates an owner-scoped session from a backend type | Session id, name, type, pid, status, and bounded startup output |
35
+ | `terminal_send` | Writes text, optionally submitting Enter, and waits for readiness — or starts a background job | Bounded output plus wait and session status, or a job id |
36
+ | `terminal_read` | Reads a bounded page of retained output without sending input | Text with line pagination metadata |
37
+ | `terminal_signal` | Delivers one allowed signal to the foreground process group | `delivered` plus the target process group id |
38
+ | `terminal_close` | Closes a session and waits for its process tree to end | Closed or already-closing outcome |
39
+ | `terminal_list` | Lists the caller's live sessions | Owner-scoped session summaries |
40
+
41
+ ### Composition
42
+
43
+ ```yaml
44
+ - name: '@deepseek-ai/dsh-terminal'
45
+ - name: '@deepseek-ai/dsh-terminal-bash'
46
+ - name: '@deepseek-ai/dsh-tool-terminal'
47
+ ```
48
+
49
+ The tools need `ctx.terminals` — a backend must be mounted — and the system-prompt service for the guidance section. Background sends additionally require the jobs service and its model-facing controller (`@deepseek-ai/dsh-tool-jobs`).
50
+
51
+ ### Configuration
52
+
53
+ | Field | Default | Meaning |
54
+ |---|---|---|
55
+ | `enableRunInBackground` | `true` | Expose and accept `run_in_background`; `false` removes the schema field and rejects the argument |
56
+ | `maxResultBytes` | `262144` | UTF-8 cap (minimum `64`) for each complete terminal result after wait, session, pagination, truncation, and job-status metadata |
57
+
58
+ The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-tool-terminal) and [tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-tool-terminal) are the exhaustive sources for config fields and schemas.
59
+
60
+ ### Background sends
61
+
62
+ `terminal_send(run_in_background: true)` returns a job id immediately instead of waiting. The job is collected with `job_output`, which waits and reads incremental output, and stopped with `job_kill`, which delivers a real `SIGINT` to the foreground process group. Background mode fails before writing input when the jobs surface is absent.
63
+
64
+ ### Observable outcomes and failures
65
+
66
+ A foreground send returns the terminal's new output plus `wait: <reason>` and the session status; `session_exit` means the top-level shell exited, while `inferred_idle` or `timeout` never proves the foreground command exited. Opening a session with an unregistered backend type fails. Results larger than `maxResultBytes` are truncated at a UTF-8 boundary with a marker.
67
+
68
+ -----
69
+
70
+ <a id="understand-the-implementation"></a>
71
+ ## Understand the implementation
72
+
73
+ <details>
74
+ <summary>Implementation internals — click to expand</summary>
75
+
76
+ This section explains the design behind the tools and points at the code that realizes it; the observable behavior is covered in [Use this package](#use-this-package).
77
+
78
+ ### Design concept
79
+
80
+ The package is a thin adapter: the six tools forward to `ctx.terminals` with the executing agent as the owner, and the presentation layer renders bounded results. Background sends register the in-flight operation on `ctx.jobs` so the generic job surface owns waiting, incremental reads, and `SIGINT` delivery.
81
+
82
+ ### Source map
83
+
84
+ | File | Role |
85
+ |---|---|
86
+ | [`src/index.ts`](src/index.ts) | Six tool definitions, schemas, guidance section, background-job integration |
87
+ | [`src/render.ts`](src/render.ts) | Result rendering and the complete-result UTF-8 cap |
88
+
89
+ ### Result bounding
90
+
91
+ Every terminal-owned single-text result is capped by `maxResultBytes` after normalized tool or pipeline errors, policy denials and short-circuits, replacements and blocks, and generic job-status text; cuts preserve UTF-8 boundaries and reserve room for a truncation marker. Structured multi-block policy results retain their shape. The minimum cap of 64 bytes keeps every registry-issued session or job id visible in its creation acknowledgement.
92
+
93
+ ### UI render intents
94
+
95
+ Foreground sends use terminal call and result cards; background sends and the other five tools use generic `execute`, `read`, or `delete` cards. None of the tools emits source locations.
96
+
97
+ </details>
98
+
99
+ -----
100
+
101
+ <a id="further-exploration"></a>
102
+ ## Further Exploration
103
+
104
+ Read these pages when the package-level contract is not enough. They move from the generated schemas to the service contract, the backend, and the background-job surface.
105
+
106
+ - [Tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-tool-terminal) — the six generated schemas and result shapes.
107
+ - [Terminal subsystem reference](../../../docs/subsystems/terminal.md) — the service contract and shared types behind the tools.
108
+ - [terminal service](../terminal/README.md) — session operations, owner fencing, and cleanup semantics.
109
+ - [terminal-bash backend](../terminal-bash/README.md) — the shipped shell backend that provides sessions.
110
+ - [jobs package map](../../jobs/README.md) — the background-job surface that collects and kills background sends.
111
+ - [Persistent PTY Agent Note](../../../.agents/notes/implemented/feature/2026-07-16-persistent-pty-sessions.md) — the capability design and deferred boundaries.
112
+
113
+ -----
114
+
115
+ <a id="model-experience"></a>
116
+ ## Model Experience
117
+
118
+ ### System prompt
119
+
120
+ #### What the model sees
121
+
122
+ The plugin contributes this fixed guidance section:
123
+
124
+ ##### Terminal guidance
125
+
126
+ ```markdown
127
+ Use a terminal session only when work needs persistent terminal state or interactive stdin; prefer shell/read/write/edit for bounded one-shot operations. Track every terminal session id and close sessions that no longer matter. An inferred_idle or timeout result does not prove the foreground command exited.
128
+ ```
129
+
130
+ #### Token effect
131
+
132
+ Small fixed input cost on every request while the plugin is active.
133
+
134
+ #### KV Cache effect
135
+
136
+ Prefix-stable while the registration scope and guidance text are unchanged.
137
+
138
+ ### Tool schemas
139
+
140
+ #### What the model sees
141
+
142
+ The six generated schemas are listed in the [`dsh-tool-terminal` catalog section](../../../docs/tool-catalog.md#deepseek-aidsh-tool-terminal). Their fixed schema tokens are present whenever this plugin is active; agent-scoped tool filtering may hide them.
143
+
144
+ #### Token effect
145
+
146
+ Fixed schema cost on requests where the tools are visible.
147
+
148
+ #### KV Cache effect
149
+
150
+ Prefix-stable while tool visibility and definitions are unchanged.
151
+
152
+ ### Tool results and task context
153
+
154
+ #### What the model sees
155
+
156
+ Spawn returns the id and bounded startup output. Send and read return bounded terminal text plus readiness and history markers. Background mode returns a generic job id. Every terminal-owned single-text result is capped by `maxResultBytes`; results remain in session history until compaction, and incremental task reads do not repeat consumed output.
157
+
158
+ #### Token effect
159
+
160
+ Terminal-owned results are data-dependent and bounded by `maxResultBytes`; each returned result stays in history until compaction.
161
+
162
+ #### KV Cache effect
163
+
164
+ Append-only; new results follow the reusable request prefix.
165
+
166
+ ## Known Limitations and Deferred Work
167
+
168
+ <a id="known-limitations-and-deferred-work"></a>
169
+
170
+
171
+ These limits define the model-facing surface that is absent. They are current package constraints, not a task backlog.
172
+
173
+ - **No TUI or key-sequence surface** — named key sequences, full-screen TUI interaction, BEL, resize, and auto-start are not exposed in any schema.
174
+ - **Background mode requires the jobs surface** — `run_in_background` needs both `@deepseek-ai/dsh-jobs` and its model-facing controller (`@deepseek-ai/dsh-tool-jobs`); without them the argument is rejected.
175
+
176
+ <a id="dev-note"></a>
177
+ ### Dev Note
178
+
179
+ <details>
180
+ <summary>Working context for maintainers — click to expand</summary>
181
+
182
+ None.
183
+
184
+ </details>
185
+
186
+ **Runtime invariant:** No companion is published. This stateless adapter contributes tools and prompt guidance, while PTY lifecycle and background-job relationships remain owned by the services it composes.
@@ -0,0 +1,186 @@
1
+ ---
2
+ description: "面向需要跨调用终端状态的 agent(智能体)的 6 个持久终端工具,带所有者隔离、有界结果与可选后台发送。"
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-tool-terminal
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ 当 agent 需要跨调用保留终端状态或提供交互式输入时,使用 `dsh-tool-terminal`。它可以打开、发送、读取、传递信号、关闭和列出终端会话,同时防止一个 agent 操作其他 agent 的会话。发送可以等待有界的前台输出,也可以返回供后续收集或中断的后台任务 job id。`maxResultBytes` 限制每个结果的大小,而结果会保留在会话历史中直到压缩(compaction)。指引会让模型对有界工作优先使用单次工具。
13
+
14
+ ## 目录
15
+
16
+ - [使用本包](#use-this-package)
17
+ - [理解实现](#understand-the-implementation)
18
+ - [进一步探索](#further-exploration)
19
+ - [模型体验](#model-experience)
20
+ - [已知限制与延期工作](#known-limitations-and-deferred-work)
21
+ - [开发备注](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## 使用本包
27
+
28
+ 当组合挂载了终端后端、且模型应当能跨调用使用终端状态时启用这些工具——使用调试器单步调试、在 REPL 中探索,或中断前台命令后回到 shell。指引章节会引导模型对有界操作使用单次 bash、read、write 与 edit 工具。
29
+
30
+ ### 六个工具
31
+
32
+ | 工具 | 作用 | 结果 |
33
+ |---|---|---|
34
+ | `terminal_open` | 按后端类型创建限定所有者范围的会话 | 会话 id、名称、类型、pid、状态与有界启动输出 |
35
+ | `terminal_send` | 写入文本,可选地提交 Enter,并等待就绪——或启动后台任务 | 有界输出加等待与会话状态,或一个 job id |
36
+ | `terminal_read` | 不发送输入,读取一页有界保留输出 | 带行分页元数据的文本 |
37
+ | `terminal_signal` | 向前台进程组投递一个允许的信号 | `delivered` 加目标进程组 id |
38
+ | `terminal_close` | 关闭会话并等待其进程树结束 | 已关闭或正在关闭的结果 |
39
+ | `terminal_list` | 列出调用方的活跃会话 | 限定所有者范围的会话摘要 |
40
+
41
+ ### 组合方式
42
+
43
+ ```yaml
44
+ - name: '@deepseek-ai/dsh-terminal'
45
+ - name: '@deepseek-ai/dsh-terminal-bash'
46
+ - name: '@deepseek-ai/dsh-tool-terminal'
47
+ ```
48
+
49
+ 工具需要 `ctx.terminals`——必须挂载一个后端——以及用于指引章节的系统提示词服务。后台发送还额外要求任务服务及其面向模型的控制器(`@deepseek-ai/dsh-tool-jobs`)。
50
+
51
+ ### 配置
52
+
53
+ | 字段 | 默认值 | 含义 |
54
+ |---|---|---|
55
+ | `enableRunInBackground` | `true` | 公开并接受 `run_in_background`;设为 `false` 时移除 schema 字段并拒绝该参数 |
56
+ | `maxResultBytes` | `262144` | 每个完整终端结果的 UTF-8 上限(最小值 `64`);在等待、会话、分页、截断与任务状态元数据全部加入后计算 |
57
+
58
+ 生成的[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-tool-terminal)与[工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-terminal)是配置字段与 schema 的穷尽式真源。
59
+
60
+ ### 后台发送
61
+
62
+ `terminal_send(run_in_background: true)` 立即返回 job id,而不是等待。任务用 `job_output` 收集——它会等待并读取增量输出——用 `job_kill` 停止,后者向前台进程组投递真正的 `SIGINT`。缺少任务接口面时,后台模式会在写入输入之前失败。
63
+
64
+ ### 可观察结果与失败
65
+
66
+ 前台发送返回终端的新输出以及 `wait: <原因>` 与会话状态;`session_exit` 表示顶层 shell 已退出,而 `inferred_idle` 或 `timeout` 绝不证明前台命令已退出。用未注册的后端类型打开会话会失败。大于 `maxResultBytes` 的结果会在 UTF-8 边界处截断并附标记。
67
+
68
+ -----
69
+
70
+ <a id="understand-the-implementation"></a>
71
+ ## 理解实现
72
+
73
+ <details>
74
+ <summary>实现细节——点击展开</summary>
75
+
76
+ 本节解释工具背后的设计并指出实现它们的代码位置;可观察行为已在[使用本包](#use-this-package)中说明。
77
+
78
+ ### 设计理念
79
+
80
+ 本包是薄适配器:6 个工具以执行 agent 作为所有者转发到 `ctx.terminals`,呈现层渲染有界结果。后台发送把在途操作注册到 `ctx.jobs`,由通用任务接口面负责等待、增量读取与 `SIGINT` 投递。
81
+
82
+ ### 源码地图
83
+
84
+ | 文件 | 职责 |
85
+ |---|---|
86
+ | [`src/index.ts`](src/index.ts) | 6 个工具定义、schema、指引章节、后台任务集成 |
87
+ | [`src/render.ts`](src/render.ts) | 结果渲染与完整结果的 UTF-8 上限 |
88
+
89
+ ### 结果上限
90
+
91
+ 每个终端自身的单文本结果都会在规范化后的工具或流水线错误、策略拒绝与短路、替换与阻止、以及通用任务状态文本之后,受 `maxResultBytes` 限制;截断保留 UTF-8 边界并为截断标记预留空间。结构化的多块策略结果保留其结构。64 字节的最小上限保证注册表签发的每个会话或 job id 都出现在创建确认中。
92
+
93
+ ### UI 呈现意图
94
+
95
+ 前台发送使用终端调用与结果卡片;后台发送与其他 5 个工具使用通用 `execute`、`read` 或 `delete` 卡片。所有工具都不输出源位置。
96
+
97
+ </details>
98
+
99
+ -----
100
+
101
+ <a id="further-exploration"></a>
102
+ ## 进一步探索
103
+
104
+ 当包级约定不够用时阅读以下页面。它们从生成的 schema 进入服务约定、后端与后台任务接口面。
105
+
106
+ - [工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-terminal)——6 个生成的 schema 与结果形态。
107
+ - [终端子系统参考](../../../docs/subsystems/terminal.zh.md)——工具背后的服务约定与共享类型。
108
+ - [terminal 服务](../terminal/README.zh.md)——会话操作、所有者限制与清理语义。
109
+ - [terminal-bash 后端](../terminal-bash/README.zh.md)——提供会话的随附 shell 后端。
110
+ - [jobs 包映射](../../jobs/README.zh.md)——收集与停止后台发送的后台任务接口面。
111
+ - [持久 PTY Agent Note](../../../.agents/notes/implemented/feature/2026-07-16-persistent-pty-sessions.zh.md)——能力设计与暂缓边界。
112
+
113
+ -----
114
+
115
+ <a id="model-experience"></a>
116
+ ## 模型体验
117
+
118
+ ### 系统提示词
119
+
120
+ #### 模型看到什么
121
+
122
+ 该插件贡献以下固定指引章节:
123
+
124
+ ##### 终端指引
125
+
126
+ ```markdown
127
+ Use a terminal session only when work needs persistent terminal state or interactive stdin; prefer shell/read/write/edit for bounded one-shot operations. Track every terminal session id and close sessions that no longer matter. An inferred_idle or timeout result does not prove the foreground command exited.
128
+ ```
129
+
130
+ #### Token 影响
131
+
132
+ 插件活跃期间,每次请求都会产生少量固定输入成本。
133
+
134
+ #### KV Cache 影响
135
+
136
+ 注册范围与指引文本不变时,前缀保持稳定。
137
+
138
+ ### 工具 schema
139
+
140
+ #### 模型看到什么
141
+
142
+ 6 个生成的 schema 列在 [`dsh-tool-terminal` 目录章节](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-terminal)中。此插件活跃时,请求中会包含它们的固定 schema token;按 agent 范围过滤工具时可能隐藏这些 schema。
143
+
144
+ #### Token 影响
145
+
146
+ 工具可见的请求会产生固定的 schema 成本。
147
+
148
+ #### KV Cache 影响
149
+
150
+ 工具可见性与定义不变时,前缀保持稳定。
151
+
152
+ ### 工具结果与任务上下文
153
+
154
+ #### 模型看到什么
155
+
156
+ spawn 返回 id 与有界启动输出。发送与读取返回有界终端文本以及就绪与历史标记。后台模式返回通用 job id。每个终端自身的单文本结果都受 `maxResultBytes` 限制;结果保留在会话历史中直到压缩,增量任务读取不会重复已经消费的输出。
157
+
158
+ #### Token 影响
159
+
160
+ 终端自身的结果随数据变化,并受 `maxResultBytes` 限制;每个返回结果都保留在历史中直到压缩。
161
+
162
+ #### KV Cache 影响
163
+
164
+ 仅追加;新结果位于可复用请求前缀之后。
165
+
166
+ ## 已知限制与延期工作
167
+
168
+ <a id="known-limitations-and-deferred-work"></a>
169
+
170
+
171
+ 这些限制说明缺失的面向模型接口面。它们是当前包约束,不是任务积压。
172
+
173
+ - **没有 TUI 或按键序列接口面**——具名按键序列、全屏 TUI 交互、BEL、调整大小与自动启动均未出现在任何 schema 中。
174
+ - **后台模式要求任务接口面**——`run_in_background` 同时需要 `@deepseek-ai/dsh-jobs` 及其面向模型的控制器(`@deepseek-ai/dsh-tool-jobs`);缺少时会拒绝该参数。
175
+
176
+ <a id="dev-note"></a>
177
+ ### 开发备注
178
+
179
+ <details>
180
+ <summary>维护者的工作上下文——点击展开</summary>
181
+
182
+ 无。
183
+
184
+ </details>
185
+
186
+ **运行时不变式:** 不发布伴生入口。这个无状态适配器只贡献工具与提示词指引;PTY 生命周期与后台任务关系仍由其组合的服务持有。