dsh-plugin-dev-kb 1.0.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 +21 -0
- package/README.md +56 -0
- package/cordis.patch.yml +12 -0
- package/kb/INDEX.md +210 -0
- package/kb/README.md +69 -0
- package/kb/extra/AGENTS.md +75 -0
- package/kb/extra/api-gateway.md +164 -0
- package/kb/extra/api-gateway.zh.md +164 -0
- package/kb/extra/cookbook/adding-a-vendored-package.md +59 -0
- package/kb/extra/cookbook/adding-a-vendored-package.zh.md +59 -0
- package/kb/extra/cookbook/maintaining-dsh-code-review.md +64 -0
- package/kb/extra/cookbook/maintaining-dsh-code-review.zh.md +64 -0
- package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.md +32 -0
- package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.zh.md +32 -0
- package/kb/extra/defensive-patterns.md +33 -0
- package/kb/extra/defensive-patterns.zh.md +33 -0
- package/kb/extra/development.md +171 -0
- package/kb/extra/development.zh.md +171 -0
- package/kb/extra/event-producer-consumer.md +76 -0
- package/kb/extra/event-producer-consumer.zh.md +78 -0
- package/kb/extra/glossary.md +45 -0
- package/kb/extra/glossary.zh.md +45 -0
- package/kb/extra/graph-atlas.md +24 -0
- package/kb/extra/graph-atlas.zh.md +26 -0
- package/kb/extra/i18n/README.md +60 -0
- package/kb/extra/i18n/README.zh.md +60 -0
- package/kb/extra/i18n/style-samples.md +87 -0
- package/kb/extra/i18n/terminology.md +214 -0
- package/kb/extra/i18n/translation-prompt.md +263 -0
- package/kb/extra/i18n/translation-rules.md +69 -0
- package/kb/extra/i18n/translation-rules.zh.md +69 -0
- package/kb/extra/module-graph.md +1641 -0
- package/kb/extra/module-graph.zh.md +1643 -0
- package/kb/extra/postmortem/0001-acp-default-export-drops-inject.md +113 -0
- package/kb/extra/postmortem/0001-acp-default-export-drops-inject.zh.md +113 -0
- package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.md +47 -0
- package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.zh.md +47 -0
- package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.md +53 -0
- package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.zh.md +53 -0
- package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.md +55 -0
- package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.zh.md +55 -0
- package/kb/extra/postmortem/README.md +18 -0
- package/kb/extra/postmortem/README.zh.md +18 -0
- package/kb/extra/rescope.md +53 -0
- package/kb/extra/rescope.zh.md +53 -0
- package/kb/extra/subsystems/attachment.md +125 -0
- package/kb/extra/subsystems/attachment.zh.md +125 -0
- package/kb/extra/subsystems/extensions.md +364 -0
- package/kb/extra/subsystems/extensions.zh.md +364 -0
- package/kb/extra/subsystems/feedback.md +266 -0
- package/kb/extra/subsystems/feedback.zh.md +266 -0
- package/kb/extra/testing.md +49 -0
- package/kb/extra/testing.zh.md +49 -0
- package/kb/extra/web-styling.md +25 -0
- package/kb/extra/web-styling.zh.md +25 -0
- package/kb/meta/search-index.json +1328 -0
- package/kb/meta/site-pages.txt +168 -0
- package/kb/meta/source.json +13 -0
- package/kb/meta/topics.md +75 -0
- package/kb/site/develop/basic/config.md +108 -0
- package/kb/site/develop/basic/index.md +146 -0
- package/kb/site/develop/basic/publish.md +185 -0
- package/kb/site/develop/basic/tool.md +54 -0
- package/kb/site/develop/cordis-tutorial/01-first-plugin.md +95 -0
- package/kb/site/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
- package/kb/site/develop/cordis-tutorial/03-services.md +98 -0
- package/kb/site/develop/cordis-tutorial/04-events.md +144 -0
- package/kb/site/develop/cordis-tutorial/05-config.md +84 -0
- package/kb/site/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
- package/kb/site/develop/cordis-tutorial/07-into-the-harness.md +107 -0
- package/kb/site/develop/cordis-tutorial/index.md +62 -0
- package/kb/site/develop/framework/events.md +145 -0
- package/kb/site/develop/framework/index.md +139 -0
- package/kb/site/develop/framework/service.md +152 -0
- package/kb/site/develop/practice/index.md +157 -0
- package/kb/site/develop/practice/llm-adapter.md +190 -0
- package/kb/site/en/develop/basic/config.md +108 -0
- package/kb/site/en/develop/basic/index.md +146 -0
- package/kb/site/en/develop/basic/publish.md +185 -0
- package/kb/site/en/develop/basic/tool.md +54 -0
- package/kb/site/en/develop/cordis-tutorial/01-first-plugin.md +95 -0
- package/kb/site/en/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
- package/kb/site/en/develop/cordis-tutorial/03-services.md +98 -0
- package/kb/site/en/develop/cordis-tutorial/04-events.md +144 -0
- package/kb/site/en/develop/cordis-tutorial/05-config.md +84 -0
- package/kb/site/en/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
- package/kb/site/en/develop/cordis-tutorial/07-into-the-harness.md +107 -0
- package/kb/site/en/develop/cordis-tutorial/index.md +60 -0
- package/kb/site/en/develop/framework/events.md +145 -0
- package/kb/site/en/develop/framework/index.md +139 -0
- package/kb/site/en/develop/framework/service.md +150 -0
- package/kb/site/en/develop/practice/index.md +157 -0
- package/kb/site/en/develop/practice/llm-adapter.md +190 -0
- package/kb/site/en/guide/providers-custom-form.png +0 -0
- package/kb/site/en/guide/providers-models-page.png +0 -0
- package/kb/site/en/guide/providers.md +100 -0
- package/kb/site/en/guide/python-sdk.md +106 -0
- package/kb/site/en/guide/quickstart.md +32 -0
- package/kb/site/en/index.md +8 -0
- package/kb/site/en/reference/agent-lifecycle.md +86 -0
- package/kb/site/en/reference/capability-seams.md +475 -0
- package/kb/site/en/reference/config-catalog.md +3155 -0
- package/kb/site/en/reference/cookbook/adding-a-conversation-node.md +235 -0
- package/kb/site/en/reference/cookbook/adding-a-package.md +120 -0
- package/kb/site/en/reference/cookbook/adding-a-settings-card.md +102 -0
- package/kb/site/en/reference/cookbook/adding-a-tool.md +96 -0
- package/kb/site/en/reference/cookbook/adding-an-llm-adapter.md +45 -0
- package/kb/site/en/reference/cookbook/extension-cookbook.md +131 -0
- package/kb/site/en/reference/cordis-api/context.md +368 -0
- package/kb/site/en/reference/cordis-api/events.md +211 -0
- package/kb/site/en/reference/cordis-api/fiber.md +379 -0
- package/kb/site/en/reference/cordis-api/inherited.md +43 -0
- package/kb/site/en/reference/cordis-api/registry.md +156 -0
- package/kb/site/en/reference/cordis-api/service.md +106 -0
- package/kb/site/en/reference/cordis-primer.md +46 -0
- package/kb/site/en/reference/index.md +131 -0
- package/kb/site/en/reference/persistence-catalog.md +949 -0
- package/kb/site/en/reference/subsystems/approval.md +173 -0
- package/kb/site/en/reference/subsystems/client-modules.md +121 -0
- package/kb/site/en/reference/subsystems/code-runtime.md +194 -0
- package/kb/site/en/reference/subsystems/commands.md +190 -0
- package/kb/site/en/reference/subsystems/compaction.md +241 -0
- package/kb/site/en/reference/subsystems/core.md +1073 -0
- package/kb/site/en/reference/subsystems/credentials.md +136 -0
- package/kb/site/en/reference/subsystems/filesystem.md +498 -0
- package/kb/site/en/reference/subsystems/goal.md +280 -0
- package/kb/site/en/reference/subsystems/index.md +58 -0
- package/kb/site/en/reference/subsystems/invariants.md +91 -0
- package/kb/site/en/reference/subsystems/jobs.md +293 -0
- package/kb/site/en/reference/subsystems/llm-streaming.md +920 -0
- package/kb/site/en/reference/subsystems/lsp.md +205 -0
- package/kb/site/en/reference/subsystems/permission-presets.md +134 -0
- package/kb/site/en/reference/subsystems/persistence.md +388 -0
- package/kb/site/en/reference/subsystems/plan.md +90 -0
- package/kb/site/en/reference/subsystems/sandbox.md +221 -0
- package/kb/site/en/reference/subsystems/schedule.md +189 -0
- package/kb/site/en/reference/subsystems/scope.md +62 -0
- package/kb/site/en/reference/subsystems/session-projection.md +265 -0
- package/kb/site/en/reference/subsystems/session-query.md +498 -0
- package/kb/site/en/reference/subsystems/session-reference.md +111 -0
- package/kb/site/en/reference/subsystems/session-telemetry.md +197 -0
- package/kb/site/en/reference/subsystems/session-title.md +207 -0
- package/kb/site/en/reference/subsystems/session.md +852 -0
- package/kb/site/en/reference/subsystems/settings.md +313 -0
- package/kb/site/en/reference/subsystems/shell.md +306 -0
- package/kb/site/en/reference/subsystems/skills.md +334 -0
- package/kb/site/en/reference/subsystems/spill.md +120 -0
- package/kb/site/en/reference/subsystems/storage.md +232 -0
- package/kb/site/en/reference/subsystems/subagent.md +737 -0
- package/kb/site/en/reference/subsystems/subprocess.md +327 -0
- package/kb/site/en/reference/subsystems/system-prompt.md +210 -0
- package/kb/site/en/reference/subsystems/terminal.md +187 -0
- package/kb/site/en/reference/subsystems/token-meter.md +93 -0
- package/kb/site/en/reference/subsystems/tools.md +723 -0
- package/kb/site/en/reference/subsystems/typert.md +339 -0
- package/kb/site/en/reference/subsystems/user-questions.md +181 -0
- package/kb/site/en/reference/subsystems/web-server.md +111 -0
- package/kb/site/en/reference/subsystems/web.md +202 -0
- package/kb/site/en/reference/subsystems/workflow.md +281 -0
- package/kb/site/en/reference/subsystems/workspace.md +231 -0
- package/kb/site/en/reference/tool-catalog.md +1877 -0
- package/kb/site/en/reference/tool-execution-pipeline.md +66 -0
- package/kb/site/guide/providers-custom-form.zh.png +0 -0
- package/kb/site/guide/providers-models-page.zh.png +0 -0
- package/kb/site/guide/providers.md +100 -0
- package/kb/site/guide/python-sdk.md +106 -0
- package/kb/site/guide/quickstart.md +32 -0
- package/kb/site/index.md +8 -0
- package/kb/site/reference/agent-lifecycle.md +86 -0
- package/kb/site/reference/capability-seams.md +475 -0
- package/kb/site/reference/config-catalog.md +3154 -0
- package/kb/site/reference/cookbook/adding-a-conversation-node.md +235 -0
- package/kb/site/reference/cookbook/adding-a-package.md +120 -0
- package/kb/site/reference/cookbook/adding-a-settings-card.md +102 -0
- package/kb/site/reference/cookbook/adding-a-tool.md +98 -0
- package/kb/site/reference/cookbook/adding-an-llm-adapter.md +45 -0
- package/kb/site/reference/cookbook/extension-cookbook.md +133 -0
- package/kb/site/reference/cordis-api/context.md +368 -0
- package/kb/site/reference/cordis-api/events.md +211 -0
- package/kb/site/reference/cordis-api/fiber.md +379 -0
- package/kb/site/reference/cordis-api/inherited.md +43 -0
- package/kb/site/reference/cordis-api/registry.md +156 -0
- package/kb/site/reference/cordis-api/service.md +106 -0
- package/kb/site/reference/cordis-primer.md +52 -0
- package/kb/site/reference/index.md +135 -0
- package/kb/site/reference/persistence-catalog.md +949 -0
- package/kb/site/reference/subsystems/approval.md +173 -0
- package/kb/site/reference/subsystems/client-modules.md +121 -0
- package/kb/site/reference/subsystems/code-runtime.md +194 -0
- package/kb/site/reference/subsystems/commands.md +190 -0
- package/kb/site/reference/subsystems/compaction.md +241 -0
- package/kb/site/reference/subsystems/core.md +1081 -0
- package/kb/site/reference/subsystems/credentials.md +136 -0
- package/kb/site/reference/subsystems/filesystem.md +498 -0
- package/kb/site/reference/subsystems/goal.md +280 -0
- package/kb/site/reference/subsystems/index.md +58 -0
- package/kb/site/reference/subsystems/invariants.md +91 -0
- package/kb/site/reference/subsystems/jobs.md +293 -0
- package/kb/site/reference/subsystems/llm-streaming.md +926 -0
- package/kb/site/reference/subsystems/lsp.md +205 -0
- package/kb/site/reference/subsystems/permission-presets.md +134 -0
- package/kb/site/reference/subsystems/persistence.md +388 -0
- package/kb/site/reference/subsystems/plan.md +90 -0
- package/kb/site/reference/subsystems/sandbox.md +221 -0
- package/kb/site/reference/subsystems/schedule.md +189 -0
- package/kb/site/reference/subsystems/scope.md +62 -0
- package/kb/site/reference/subsystems/session-projection.md +265 -0
- package/kb/site/reference/subsystems/session-query.md +498 -0
- package/kb/site/reference/subsystems/session-reference.md +111 -0
- package/kb/site/reference/subsystems/session-telemetry.md +197 -0
- package/kb/site/reference/subsystems/session-title.md +207 -0
- package/kb/site/reference/subsystems/session.md +854 -0
- package/kb/site/reference/subsystems/settings.md +313 -0
- package/kb/site/reference/subsystems/shell.md +306 -0
- package/kb/site/reference/subsystems/skills.md +334 -0
- package/kb/site/reference/subsystems/spill.md +120 -0
- package/kb/site/reference/subsystems/storage.md +232 -0
- package/kb/site/reference/subsystems/subagent.md +739 -0
- package/kb/site/reference/subsystems/subprocess.md +327 -0
- package/kb/site/reference/subsystems/system-prompt.md +210 -0
- package/kb/site/reference/subsystems/terminal.md +187 -0
- package/kb/site/reference/subsystems/token-meter.md +93 -0
- package/kb/site/reference/subsystems/tools.md +723 -0
- package/kb/site/reference/subsystems/typert.md +339 -0
- package/kb/site/reference/subsystems/user-questions.md +181 -0
- package/kb/site/reference/subsystems/web-server.md +111 -0
- package/kb/site/reference/subsystems/web.md +202 -0
- package/kb/site/reference/subsystems/workflow.md +281 -0
- package/kb/site/reference/subsystems/workspace.md +231 -0
- package/kb/site/reference/tool-catalog.md +1880 -0
- package/kb/site/reference/tool-execution-pipeline.md +66 -0
- package/package.json +40 -0
- package/scripts/rebuild-index.mjs +88 -0
- package/skills/dsh-plugin-dev-kb.md +66 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
editSource: "docs/subsystems/terminal.md"
|
|
3
|
+
outline: [2,3]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Persistent PTY Sessions
|
|
7
|
+
|
|
8
|
+
Types shared by PTY backends, `ctx.terminals`, and the model-facing consumer. The [persistent PTY Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/feature/2026-07-16-persistent-pty-sessions.md) owns the rationale; this page records the cross-package vocabulary from [`packages/terminal/terminal/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/terminal/terminal/src/types.ts).
|
|
9
|
+
|
|
10
|
+
## Identity and readiness
|
|
11
|
+
|
|
12
|
+
`TerminalSessionId` is a service-minted branded id. Optional names are owner-local display metadata; authorization compares the exact owning `Agent`, not a name or guessed id.
|
|
13
|
+
|
|
14
|
+
`TerminalWaitReason` says why one send returned. It is independent from `TerminalSessionStatus`: silence or timeout may return while the top-level shell remains alive, while `session_exit` means that shell exited rather than an arbitrary foreground child.
|
|
15
|
+
|
|
16
|
+
```ts type-equiv
|
|
17
|
+
/** Why one interactive send returned control to its caller. */
|
|
18
|
+
type TerminalWaitReason = 'stdin_read' | 'inferred_idle' | 'timeout' | 'session_exit'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts type-equiv
|
|
22
|
+
/** Top-level PTY process status, independent of a send's wait reason. */
|
|
23
|
+
type TerminalSessionStatus =
|
|
24
|
+
| { kind: 'running' }
|
|
25
|
+
| { kind: 'exited'; exitCode: number | null; signal: NodeJS.Signals | null }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Backend and live session
|
|
29
|
+
|
|
30
|
+
A backend owns how one registered type starts and detects readiness. `TerminalSessionService` publishes the returned session only after setup succeeds, then owns id authorization and cleanup. A backend that cannot clean partial startup resources rejects with `TerminalBackendCleanupError`, allowing disposal to retain the cleanup failure without replacing the caller's cancellation reason. A backend session owns terminal state and captured-resource quiescence.
|
|
31
|
+
|
|
32
|
+
```ts type-equiv
|
|
33
|
+
/** Replaceable provider for one PTY session type. */
|
|
34
|
+
interface TerminalBackend {
|
|
35
|
+
/** Stable type selected by {@link TerminalSpawnRequest.type}. */
|
|
36
|
+
readonly type: string
|
|
37
|
+
/** Create an unpublished session or reject after cleaning partial resources; cleanup failure uses {@link TerminalBackendCleanupError}. */
|
|
38
|
+
spawn(spec: TerminalBackendSpawnSpec): Promise<TerminalBackendSession>
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```ts type-equiv
|
|
43
|
+
/** Backend-owned live session retained by {@link TerminalSessionService}. */
|
|
44
|
+
interface TerminalBackendSession {
|
|
45
|
+
/** Initial bounded terminal output returned from `terminal_open`. */
|
|
46
|
+
readonly motd: string
|
|
47
|
+
/** Top-level process id when one exists. */
|
|
48
|
+
readonly pid?: number
|
|
49
|
+
/** Start one exclusive send operation. */
|
|
50
|
+
startSend(request: TerminalSendRequest): TerminalSendOperation
|
|
51
|
+
/** Read one bounded page from retained scrollback. */
|
|
52
|
+
read(request: TerminalReadRequest): TerminalReadResult
|
|
53
|
+
/** Signal the verified foreground process group. */
|
|
54
|
+
signal(signal: TerminalSignal): Promise<TerminalSignalResult>
|
|
55
|
+
/** Observe top-level process status. */
|
|
56
|
+
status(): TerminalSessionStatus
|
|
57
|
+
/** Idempotently close the captured owned process tree and await quiescence. */
|
|
58
|
+
close(reason: string): Promise<void>
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Send and retained output
|
|
63
|
+
|
|
64
|
+
One live session accepts one active send. Its operation exposes a consuming output cursor for generic background jobs and one terminal result for a foreground caller. `TerminalReadResult` separately pages the bounded session scrollback.
|
|
65
|
+
|
|
66
|
+
```ts type-equiv
|
|
67
|
+
/** Live backend-owned send; exactly one may be active per PTY session. */
|
|
68
|
+
interface TerminalSendOperation {
|
|
69
|
+
/** Resolves after readiness, timeout, cancellation, or top-level process exit. */
|
|
70
|
+
done: Promise<TerminalSendResult>
|
|
71
|
+
/** Consume output produced since the prior call. */
|
|
72
|
+
readOutput(): TerminalSendRead
|
|
73
|
+
/** Request `SIGINT`; returns false after the operation settled. */
|
|
74
|
+
cancel(): boolean
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```ts type-equiv
|
|
79
|
+
/** Settled result for one foreground or background send. */
|
|
80
|
+
interface TerminalSendResult {
|
|
81
|
+
/** Bounded rendered terminal delta remaining at settlement. */
|
|
82
|
+
viewport: string
|
|
83
|
+
/** Why the wait returned; this does not imply arbitrary child-process exit. */
|
|
84
|
+
waitReason: TerminalWaitReason
|
|
85
|
+
/** Top-level session status observed at settlement. */
|
|
86
|
+
sessionStatus: TerminalSessionStatus
|
|
87
|
+
/** Whether output was dropped from the operation or retained scrollback. */
|
|
88
|
+
truncated: boolean
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Ownership and durability
|
|
93
|
+
|
|
94
|
+
`TerminalSessionService` attaches one awaited cleanup to the exact owner scope, rejects foreign operations, and keeps sessions alive across backend or tool-plugin reload. PTY state and raw bytes remain process-local. Model input and bounded returned output are durable through the existing `tool/call`, `tool/result`, and task-result paths rather than duplicate PTY session events.
|
|
95
|
+
|
|
96
|
+
<!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
|
|
97
|
+
|
|
98
|
+
<a id="cordis-surface"></a>
|
|
99
|
+
|
|
100
|
+
## Cordis API
|
|
101
|
+
|
|
102
|
+
Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — this section is byte-identical in both language sides of the page. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
|
|
103
|
+
|
|
104
|
+
<a id="ctxterminals--terminalsessionservice"></a>
|
|
105
|
+
|
|
106
|
+
### `ctx.terminals` — `TerminalSessionService`
|
|
107
|
+
|
|
108
|
+
In-process registry for replaceable PTY backends and exact-Agent sessions.
|
|
109
|
+
|
|
110
|
+
```ts cordis-catalog
|
|
111
|
+
/**
|
|
112
|
+
* Register one backend type for this effect scope.
|
|
113
|
+
* @param backend - provider with a non-empty unique type.
|
|
114
|
+
* @returns disposer that removes exactly this contribution.
|
|
115
|
+
*/
|
|
116
|
+
registerBackend(backend: TerminalBackend): () => void
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* List registered backend types in registration order.
|
|
120
|
+
* @returns fresh backend type names.
|
|
121
|
+
*/
|
|
122
|
+
listBackends(): string[]
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Create and publish one owner-scoped session after backend setup succeeds.
|
|
126
|
+
* @param owner - exact registered Agent that owns access and cleanup.
|
|
127
|
+
* @param request - backend type plus optional owner-local name and cwd.
|
|
128
|
+
* @param signal - cancellation of unpublished setup.
|
|
129
|
+
* @returns published identity, metadata, status, and MOTD.
|
|
130
|
+
*/
|
|
131
|
+
async spawn(owner: Agent, request: TerminalSpawnRequest, signal?: AbortSignal): Promise<TerminalSpawnResult>
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Test whether an exact owner has a published session or unpublished spawn.
|
|
135
|
+
* @param owner - exact live owner to inspect.
|
|
136
|
+
* @returns true across the entire spawn-to-close interval, with no publication gap.
|
|
137
|
+
*/
|
|
138
|
+
hasOwnerActivity(owner: Agent): boolean
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Start one exclusive interactive send.
|
|
142
|
+
* @param owner - exact session owner.
|
|
143
|
+
* @param id - target PTY identity.
|
|
144
|
+
* @param request - explicit text, submit behavior, and cancellation.
|
|
145
|
+
* @returns live operation handle for foreground await or task registration.
|
|
146
|
+
*/
|
|
147
|
+
startSend(owner: Agent, id: TerminalSessionId, request: TerminalSendRequest): TerminalSendOperation
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Read one bounded scrollback page from an owned session.
|
|
151
|
+
* @param owner - exact session owner.
|
|
152
|
+
* @param id - target PTY identity.
|
|
153
|
+
* @param request - optional newest-relative offset and line count.
|
|
154
|
+
* @returns bounded retained text and pagination metadata.
|
|
155
|
+
*/
|
|
156
|
+
read(owner: Agent, id: TerminalSessionId, request: TerminalReadRequest = {}): TerminalReadResult
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Deliver an allowed signal through an owned backend session.
|
|
160
|
+
* @param owner - exact session owner.
|
|
161
|
+
* @param id - target PTY identity.
|
|
162
|
+
* @param signal - allowed POSIX signal name.
|
|
163
|
+
* @returns delivered foreground process-group identity.
|
|
164
|
+
*/
|
|
165
|
+
signal(owner: Agent, id: TerminalSessionId, signal: TerminalSignal): Promise<TerminalSignalResult>
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Close one owned session and remove it only after quiescent backend cleanup.
|
|
169
|
+
* @param owner - exact session owner.
|
|
170
|
+
* @param id - target PTY identity.
|
|
171
|
+
* @param reason - diagnostic cleanup reason.
|
|
172
|
+
* @returns true for a newly closed session, false when the same close is already in flight.
|
|
173
|
+
*/
|
|
174
|
+
async kill(owner: Agent, id: TerminalSessionId, reason: string = 'model request'): Promise<boolean>
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* List fresh snapshots for exactly one owner.
|
|
178
|
+
* @param owner - exact owner whose sessions are visible.
|
|
179
|
+
* @returns owner-visible snapshots in publication order.
|
|
180
|
+
*/
|
|
181
|
+
list(owner: Agent): TerminalSessionSnapshot[]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Types: [Agent](./core.md)
|
|
185
|
+
|
|
186
|
+
Source: [`packages/terminal/terminal/src/index.ts:105`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/terminal/terminal/src/index.ts)
|
|
187
|
+
<!-- END GENERATED cordis-surface -->
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
editSource: "docs/subsystems/token-meter.md"
|
|
3
|
+
outline: [2,3]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Token Meter
|
|
7
|
+
|
|
8
|
+
`@deepseek-ai/dsh-token-meter` exposes one detached replay snapshot for request pressure and positional surface pricing. `logRevision` is the number of durable events consumed for every field in the measurement.
|
|
9
|
+
|
|
10
|
+
Source: [`packages/llm/token-meter/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/llm/token-meter/src/types.ts)
|
|
11
|
+
|
|
12
|
+
## `TokenMeasurement`
|
|
13
|
+
|
|
14
|
+
```ts type-equiv
|
|
15
|
+
/** Detached immutable request-pressure and surface snapshot at one consumed log revision. */
|
|
16
|
+
interface TokenMeasurement {
|
|
17
|
+
/** Number of durable events consumed; equal to the next unread event seq. */
|
|
18
|
+
readonly logRevision: number
|
|
19
|
+
/** Provider or heuristic anchor used for this measurement. */
|
|
20
|
+
readonly baseline: TokenMeasurementBaseline
|
|
21
|
+
/** Signed repricing of current surface content relative to the baseline anchor. */
|
|
22
|
+
readonly surfaceDeltaTokens: number
|
|
23
|
+
/** Non-negative current request-and-response pressure. */
|
|
24
|
+
readonly totalTokens: number
|
|
25
|
+
/** Total heuristic tokens across the current surface. */
|
|
26
|
+
readonly surfaceTokens: number
|
|
27
|
+
/** Current surface nodes in positional head-to-tail order. */
|
|
28
|
+
readonly nodes: readonly TokenSurfaceNode[]
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`baseline.kind === 'usage'` means the latest successful provider call has the same canonical request envelope and its total is no lower than that call's full heuristic anchor. `estimated` means no reusable conservative usage anchor exists, so the service priced the complete envelope and surface with its fixed heuristic. A later successful request replaces the earlier anchor; signed `surfaceDeltaTokens` preserves growth and shrinkage relative to a matching anchor. `totalTokens` remains request-and-response pressure, while `surfaceTokens` is the surface-only heuristic total and equals the sum of the node prices.
|
|
33
|
+
|
|
34
|
+
## `TokenSurfaceNode`
|
|
35
|
+
|
|
36
|
+
```ts type-equiv
|
|
37
|
+
/** One token-priced node in the current ordered session surface. */
|
|
38
|
+
interface TokenSurfaceNode {
|
|
39
|
+
/** Durable sequence number of the surface event. */
|
|
40
|
+
readonly seq: number
|
|
41
|
+
/** Heuristic tokens for the exact message projected by this node. */
|
|
42
|
+
readonly tokens: number
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Surface order is authoritative; replacement nodes can have higher durable seqs than later positional nodes. The snapshot is immutable and does not grow when the underlying replay fold advances.
|
|
47
|
+
|
|
48
|
+
<!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
|
|
49
|
+
|
|
50
|
+
<a id="cordis-surface"></a>
|
|
51
|
+
|
|
52
|
+
## Cordis API
|
|
53
|
+
|
|
54
|
+
Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — this section is byte-identical in both language sides of the page. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
|
|
55
|
+
|
|
56
|
+
<a id="ctxtokenmeter--tokenmeter"></a>
|
|
57
|
+
|
|
58
|
+
### `ctx.tokenMeter` — `TokenMeter`
|
|
59
|
+
|
|
60
|
+
Replay owner for one service-wide estimator and isolated per-session folds.
|
|
61
|
+
|
|
62
|
+
```ts cordis-catalog
|
|
63
|
+
/**
|
|
64
|
+
* Measure current request pressure and surface through the durable tail.
|
|
65
|
+
*
|
|
66
|
+
* Provider usage is reused only when the latest successful call's canonical
|
|
67
|
+
* request envelope matches `requestHeader` and its total is no lower than
|
|
68
|
+
* that call's full heuristic anchor; otherwise the complete envelope and
|
|
69
|
+
* surface are heuristically repriced.
|
|
70
|
+
*
|
|
71
|
+
* `requestHeader` affects request pressure only; surface fields always
|
|
72
|
+
* describe the current session surface. Every call clones those positional
|
|
73
|
+
* nodes, so measurement is O(surface).
|
|
74
|
+
*
|
|
75
|
+
* @param session - session to replay through its current durable tail.
|
|
76
|
+
* @param requestHeader - optional effective request envelope replacing the latest logged header.
|
|
77
|
+
* @returns a detached deeply immutable pressure and surface measurement.
|
|
78
|
+
*/
|
|
79
|
+
measure(session: Session, requestHeader?: EpochHeader): TokenMeasurement
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Heuristically price one model-visible message (instance face of the pure
|
|
83
|
+
* `estimateMessage` export from `estimate.ts`).
|
|
84
|
+
* @param message - message to price without mutation.
|
|
85
|
+
* @returns content and role-framing tokens under the fixed service heuristic.
|
|
86
|
+
*/
|
|
87
|
+
estimateMessage(message: Message): number
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Types: [EpochHeader](./session.md) · [Message](./llm-streaming.md) · [Session](./session.md)
|
|
91
|
+
|
|
92
|
+
Source: [`packages/llm/token-meter/src/index.ts:74`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/llm/token-meter/src/index.ts)
|
|
93
|
+
<!-- END GENERATED cordis-surface -->
|