@vidge/dsh-agent-hub 0.1.0-rc1

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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -0
  3. package/README.zh.md +115 -0
  4. package/cordis.patch.yml +22 -0
  5. package/lib/client.js +1494 -0
  6. package/lib/index.js +5045 -0
  7. package/lib/invariant.js +96 -0
  8. package/lib/types/client/LoopEngineComposerSelect.d.ts +73 -0
  9. package/lib/types/client/LoopEngineSection.d.ts +43 -0
  10. package/lib/types/client/engine-rpc.d.ts +74 -0
  11. package/lib/types/client/index.d.ts +28 -0
  12. package/lib/types/client/locales.d.ts +44 -0
  13. package/lib/types/client/session-location.d.ts +63 -0
  14. package/lib/types/client/store.d.ts +58 -0
  15. package/lib/types/commands.d.ts +69 -0
  16. package/lib/types/driver-core/context-files.d.ts +62 -0
  17. package/lib/types/driver-core/ownership.d.ts +40 -0
  18. package/lib/types/driver-core/permission-knobs.d.ts +26 -0
  19. package/lib/types/driver-core/prompt.d.ts +23 -0
  20. package/lib/types/driver-core/skill-inject.d.ts +59 -0
  21. package/lib/types/engine-claude/agent.d.ts +116 -0
  22. package/lib/types/engine-claude/loop.d.ts +99 -0
  23. package/lib/types/engine-claude/mapping.d.ts +84 -0
  24. package/lib/types/engine-claude/permission.d.ts +41 -0
  25. package/lib/types/engine-claude/process.d.ts +59 -0
  26. package/lib/types/engine-claude/provider-env.d.ts +50 -0
  27. package/lib/types/engine-claude/sdk.d.ts +101 -0
  28. package/lib/types/engine-claude/types.d.ts +28 -0
  29. package/lib/types/engine-codex/agent.d.ts +109 -0
  30. package/lib/types/engine-codex/appserver/client.d.ts +49 -0
  31. package/lib/types/engine-codex/appserver/mapping.d.ts +67 -0
  32. package/lib/types/engine-codex/appserver/thread.d.ts +66 -0
  33. package/lib/types/engine-codex/appserver/types.d.ts +215 -0
  34. package/lib/types/engine-codex/loop.d.ts +92 -0
  35. package/lib/types/engine-codex/permission.d.ts +32 -0
  36. package/lib/types/engine-codex/skills.d.ts +29 -0
  37. package/lib/types/engine-codex/types.d.ts +19 -0
  38. package/lib/types/engine-pi/agent.d.ts +125 -0
  39. package/lib/types/engine-pi/loop.d.ts +96 -0
  40. package/lib/types/engine-pi/permission.d.ts +43 -0
  41. package/lib/types/engine-pi/rpc/client.d.ts +105 -0
  42. package/lib/types/engine-pi/rpc/mapping.d.ts +37 -0
  43. package/lib/types/engine-pi/rpc/types.d.ts +235 -0
  44. package/lib/types/engine-pi/skills.d.ts +55 -0
  45. package/lib/types/engine-pi/types.d.ts +27 -0
  46. package/lib/types/engine-record.d.ts +124 -0
  47. package/lib/types/index.d.ts +138 -0
  48. package/lib/types/invariant.d.ts +23 -0
  49. package/lib/types/llm-compat.d.ts +32 -0
  50. package/lib/types/namespace.d.ts +19 -0
  51. package/lib/types/patch-manager.d.ts +78 -0
  52. package/lib/types/router.d.ts +189 -0
  53. package/lib/types/rpc.d.ts +113 -0
  54. package/lib/types/settings.d.ts +29 -0
  55. package/lib/types/skills.d.ts +93 -0
  56. package/package.json +107 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Codex skill provider: exposes the codex CLI's instruction files as DSH
3
+ * skills.
4
+ *
5
+ * Codex has no per-skill catalog like the agents-skill standard; its
6
+ * instructions are `AGENTS.md` files read from the session cwd up to the git
7
+ * root, plus the global `~/.codex/AGENTS.md`. Each file set is surfaced as one
8
+ * user-invocable `agents-md` skill whose body is the concatenated file
9
+ * contents, so the dsh skill-injection seam (`/name` gestures) can carry it
10
+ * into the prompt.
11
+ *
12
+ * @module dsh-agent-hub/engine-codex/skills
13
+ */
14
+ import type { SkillCandidate, SkillDefinition, SkillLookupOptions, SkillProvider, SkillProviderControl } from '../skills.ts';
15
+ /**
16
+ * Skill provider that discovers `AGENTS.md` from every directory between the
17
+ * project cwd and the git root, plus the user home `~/.codex/AGENTS.md`.
18
+ */
19
+ export declare class CodexSkillProvider implements SkillProvider {
20
+ private readonly control;
21
+ readonly name = "codex";
22
+ constructor(control: SkillProviderControl);
23
+ list(options: SkillLookupOptions): Promise<readonly SkillCandidate[]>;
24
+ get(candidate: SkillCandidate, _options: SkillLookupOptions): Promise<SkillDefinition | undefined>;
25
+ /** One merged `agents-md` candidate for a ranked file set. */
26
+ private agentsCandidate;
27
+ }
28
+ export default CodexSkillProvider;
29
+ //# sourceMappingURL=skills.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Public types of the Codex loop driver. Types only — no runtime code.
3
+ *
4
+ * @module dsh-agent-hub/engine-codex/types
5
+ */
6
+ /** Codex CLI sandbox modes, as spoken by the app-server `sandbox` field. */
7
+ export type CodexSandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access';
8
+ /** Codex CLI approval policies, as spoken by the app-server `approvalPolicy` field. */
9
+ export type CodexApprovalPolicy = 'never' | 'on-request' | 'on-failure' | 'untrusted';
10
+ /** Driver configuration after defaults and load-time validation. */
11
+ export interface ResolvedConfig {
12
+ /** Pinned sandbox mode; `undefined` follows the session's dsh permission knobs per query. */
13
+ readonly sandboxMode: CodexSandboxMode | undefined;
14
+ /** Pinned approval policy; `undefined` follows the session's dsh permission knobs per query. */
15
+ readonly approvalPolicy: CodexApprovalPolicy | undefined;
16
+ readonly env: Record<string, string>;
17
+ readonly model: string | undefined;
18
+ }
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Pi loop Agent: drives one session through turn and step boundaries by
3
+ * spawning a `pi --mode rpc` child process and speaking strict-LF JSONL over
4
+ * stdio. The dsh session log is the sole source of truth and each step runs one
5
+ * stateless Pi session (a fresh `new_session` + a single `prompt`), so the
6
+ * prompt is a pure serialization of the durable history plus the assembled dsh
7
+ * system prompt. Pi owns its tools natively but has no permission system, so
8
+ * the whole child is sandboxed by the dsh subprocess seam and its `--tools`
9
+ * are pruned to the resolved stance.
10
+ *
11
+ * @module dsh-agent-hub/engine-pi/agent
12
+ */
13
+ import type { Agent, AgentCancelCause, AgentOptions, AgentStatus, CancelOptions, InboxTarget } from '@deepseek-ai/dsh-agent';
14
+ import { Inbox } from '@deepseek-ai/dsh-agent';
15
+ import type { Scope } from '@deepseek-ai/dsh-scope';
16
+ import type { Session, SessionId, UserMessage } from '@deepseek-ai/dsh-session';
17
+ import type { Context } from '@deepseek-ai/cordis';
18
+ import type { ResolvedConfig } from './types.ts';
19
+ import { type PiSpawnCapability } from './rpc/client.ts';
20
+ /** Drives one session through turn and step boundaries on Pi. */
21
+ export declare class PiAgent implements Agent {
22
+ private loopCtx;
23
+ readonly id: SessionId;
24
+ readonly options: AgentOptions;
25
+ readonly session: Session;
26
+ private readonly config;
27
+ private readonly spawn;
28
+ private readonly bin;
29
+ readonly inbox: Inbox;
30
+ private phase;
31
+ private activityDone;
32
+ /** The agent-scoped registration boundary; the lifecycle owner unwinds it after the driver exits. */
33
+ readonly scope: Scope;
34
+ readonly ctx: Context;
35
+ /** Fused dispatcher, built once in the constructor so hot-path dispatches never allocate. */
36
+ private readonly dispatch;
37
+ /** Whether this loop instance has appended its initial/resume request anchor. */
38
+ private requestHeaderLogged;
39
+ /** Lazily created RPC client, reused across steps and released on scope teardown. */
40
+ private rpc;
41
+ /** The spawn spec the cached client was built from; a change forces a respawn. */
42
+ private lastSpec;
43
+ constructor(loopCtx: Context, id: SessionId, options: AgentOptions, session: Session, config: ResolvedConfig, spawn: PiSpawnCapability, bin: string);
44
+ /** Return the cached RPC client, respawning when the spec or process changed. */
45
+ private rpcClient;
46
+ get status(): AgentStatus;
47
+ /** Commit a phase and publish its externally visible status transition. */
48
+ private setPhase;
49
+ send(message: UserMessage, target: InboxTarget, wakeup: boolean): void;
50
+ /**
51
+ * Queue a message for the next turn and wake the driver.
52
+ * @param input - the user message to deliver.
53
+ */
54
+ followup(input: UserMessage): void;
55
+ /**
56
+ * Queue a message for the running step and wake the driver.
57
+ * @param input - the user message to deliver.
58
+ */
59
+ steer(input: UserMessage): void;
60
+ /**
61
+ * Queue a message for the running step without waking the driver.
62
+ * @param input - the user message to deliver.
63
+ */
64
+ inject(input: UserMessage): void;
65
+ cancel(cause: AgentCancelCause, options?: CancelOptions): void;
66
+ /**
67
+ * Run a maintenance job while the agent is idle.
68
+ * @param job - the maintenance operation, receiving the phase abort signal.
69
+ * @returns the maintenance result.
70
+ */
71
+ runMaintenance<T>(job: (signal: AbortSignal) => Promise<T>): Promise<T>;
72
+ /**
73
+ * Start one driver, or latch its wake behind maintenance or an aborted
74
+ * activity. A wake sent while idle always opens its turn boundary, even
75
+ * when its message was cleared; only a latched replay is suppressed when
76
+ * the queue no longer holds the wake.
77
+ * @param wakeAfterAbort - the {@link send} classification, captured before
78
+ * the inbox insertion so a reentrant cancel cannot reclassify it.
79
+ */
80
+ private wakeDriver;
81
+ whenIdle(): Promise<void>;
82
+ /** Report one failure at its live boundary, then preserve it for driver containment. */
83
+ private throwError;
84
+ private kick;
85
+ private preStep;
86
+ /**
87
+ * Scan the step's user messages for `/name` skill gestures, load each
88
+ * matching skill, and inject the rendered skill content into the message
89
+ * batch. This mirrors what dsh-tool-skill does for the in-process engine.
90
+ * @param messages - the current step's message batch.
91
+ * @param signal - cancellation signal (aborted loads are silently dropped).
92
+ * @returns the original batch when no skill was invoked, or an extended
93
+ * batch with injected skill-content messages appended.
94
+ */
95
+ private injectSkills;
96
+ /**
97
+ * Resolve the runtime permission stance for one query. Deployment-pinned
98
+ * fields win; anything unpinned follows the session's durable dsh permission
99
+ * knobs, re-folded per query so mid-session preset switches take effect on the
100
+ * next step.
101
+ * @returns the permission fields of the query spec.
102
+ */
103
+ private queryPermission;
104
+ /** Open one turn before claiming its first proposed step. */
105
+ private turn;
106
+ /** Model label recorded in the request header for one lifecycle. */
107
+ private modelLabel;
108
+ /** Append the request header snapshot once per loop instance. */
109
+ private assertRequestHeader;
110
+ /** Build the `pi --mode rpc` argv/cwd/env for one step's child process. */
111
+ private spawnSpec;
112
+ /**
113
+ * Run one Pi RPC query for the current step and map its event stream into the
114
+ * session log. The step opens a fresh Pi session (`new_session`) and sends the
115
+ * serialized session history as one prompt, then consumes events until the
116
+ * agent settles. Like the Codex/Claude drivers, Pi owns its own system prompt
117
+ * natively, so the dsh system-prompt assembly (which pulls dsh tool schemas
118
+ * and `agent.ctx.tools`) is deliberately not run — the durable session log is
119
+ * the sole source of model context.
120
+ */
121
+ private step;
122
+ /** Append one Pi tool result to the durable log as a `tool/result` message. */
123
+ private appendToolResult;
124
+ }
125
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Pi loop engine module: hosts the AgentFactory that drives every session
3
+ * through the Pi CLI (`@earendil-works/pi-coding-agent`) over its JSONL RPC
4
+ * mode, one stateless session per dsh step, with the durable session log as the
5
+ * sole source of model context. dsh-agent-hub constructs this factory when
6
+ * the Pi engine is selected; this module is a library, not a Cordis plugin
7
+ * entry. Pi has no permission system, so the entire `pi --mode rpc` child is
8
+ * spawned through the dsh subprocess seam — the only available privilege
9
+ * boundary — and its `--tools` are pruned to the resolved sandbox stance.
10
+ *
11
+ * @module dsh-agent-hub/engine-pi
12
+ */
13
+ import { Service } from '@deepseek-ai/cordis';
14
+ import type { Context } from '@deepseek-ai/cordis';
15
+ import z from '@deepseek-ai/schemastery';
16
+ import type { AgentFactory, AgentHandle, CreateAgentOptions, ResumeAgentOptions } from '@deepseek-ai/dsh-agent';
17
+ import type { PiProcess, PiSpawnSpec } from './rpc/client.ts';
18
+ import type { PiSandboxMode, ResolvedConfig } from './types.ts';
19
+ /** Pi CLI sandbox modes a deployment may pin. */
20
+ export declare const PI_SANDBOX_MODES: readonly PiSandboxMode[];
21
+ /** Grace in milliseconds for Pi process-tree termination. */
22
+ export declare const PI_DISPOSE_GRACE_MS = 3000;
23
+ /** Deployment-owned configuration for the Pi loop plugin. */
24
+ export interface Config {
25
+ /**
26
+ * Pinned sandbox stance for every RPC child. When omitted, each query follows
27
+ * the session's dsh permission knobs (`sandbox/mode` and `approval/policy`):
28
+ * full access runs native, `workspace-write` wraps the child in the dsh
29
+ * sandbox with a write-capable tool set, an `ask` policy degrades to a
30
+ * read-only denial, and anything else fails closed with `read-only`.
31
+ */
32
+ sandboxMode?: PiSandboxMode;
33
+ /** LLM provider for the `pi` child (`--provider`), when the deployment pins one. */
34
+ provider?: string;
35
+ /** Model pattern for the `pi` child (`--model`); Pi native settings own the model when omitted. */
36
+ model?: string;
37
+ /** Thinking/reasoning level, appended to the `--model` pattern when pinned. */
38
+ thinkingLevel?: string;
39
+ /** Explicit environment entries passed to the `pi` child. */
40
+ env?: Record<string, string>;
41
+ }
42
+ /** Schema of the Pi loop plugin configuration. */
43
+ export declare const Config: z<Config>;
44
+ /** Host-face ctx key for the Pi loop service. */
45
+ declare module '@deepseek-ai/cordis' {
46
+ interface Context {
47
+ agentLoopPi: PiLoop;
48
+ }
49
+ }
50
+ /**
51
+ * Concrete AgentFactory and driver service of the Pi loop. Creation and resume
52
+ * follow the registry factory contract and the shared publication transaction:
53
+ * prepare, run setup, then publish through both registries, announce, and emit
54
+ * `agent/session-start`.
55
+ */
56
+ export declare class PiLoop extends Service implements AgentFactory {
57
+ /** Services the loop resolves through its own fiber; blessed identically to the package-level entry inject. */
58
+ static inject: string[];
59
+ /** Validated configuration owned by the loop plugin. */
60
+ readonly config: ResolvedConfig;
61
+ private readonly ownership;
62
+ /** Plain holder prevents Cordis from re-tracing the factory's dependency context through a caller shadow. */
63
+ private readonly runtime;
64
+ /** Process-tree spawn capability handed to every agent, sandboxed by the subprocess seam. */
65
+ readonly spawn: (spec: PiSpawnSpec) => PiProcess;
66
+ /** Resolved Pi CLI entrypoint; `argv[0]` of every Pi RPC child. */
67
+ readonly bin: string;
68
+ constructor(ctx: Context, config: Config);
69
+ /**
70
+ * Construct the driver, scope, and one memoized reverse teardown for a new
71
+ * agent. The teardown is registered with the factory and the owner fiber
72
+ * BEFORE publication, so a mid-setup unload rolls everything back; `signal`
73
+ * fuses caller cancellation with lifecycle teardown for setup awaits.
74
+ */
75
+ private prepare;
76
+ /** Prepare one Agent around an acquired Session, run setup, and publish it. */
77
+ private setupAndPublish;
78
+ /**
79
+ * Create an agent and session under one caller-supplied identity, owned by
80
+ * the accessing fiber.
81
+ * @param ownerCtx - caller context that structurally owns the lifecycle.
82
+ * @param options - identities, session seed/metadata, loop options, setup, and cancellation.
83
+ * @returns the published handle.
84
+ */
85
+ createAgent(ownerCtx: Context, options: CreateAgentOptions): Promise<AgentHandle>;
86
+ /**
87
+ * Resume an owned agent from the configured persistence service.
88
+ * @param ownerCtx - caller context that owns load, setup, and the live lifecycle.
89
+ * @param options - persisted identity, loop options, setup, and cancellation.
90
+ * @returns the published handle.
91
+ */
92
+ resume(ownerCtx: Context, options: ResumeAgentOptions): Promise<AgentHandle>;
93
+ /** Resume through an explicit persistence handle. */
94
+ private resumeWith;
95
+ }
96
+ //# sourceMappingURL=loop.d.ts.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Mapping from the dsh session's durable permission knobs to one Pi RPC
3
+ * process's runtime stance. Pi carries no native permission system — "runs
4
+ * with the permissions of the user" — so the driver cannot ask it to sandbox or
5
+ * approve. The only available boundary is the process environment: the driver
6
+ * either wraps the whole `pi --mode rpc` child in the dsh subprocess sandbox
7
+ * and prunes its `--tools`, or (full access) lets it run under the dsh user.
8
+ * The fold mirrors the codex bridge, mapping the session's `sandbox/mode` and
9
+ * `approval/policy` events directly:
10
+ * - full access → `danger-full-access`, no tool pruning (native tools);
11
+ * - `workspace-write` → sandbox wrap with a write-capable tool set;
12
+ * - an `ask` policy → degraded to a read-only denial (Pi has no request
13
+ * callback, so interactive approval can only become a rejection);
14
+ * - anything else fails closed → `read-only`.
15
+ *
16
+ * @module dsh-agent-hub/engine-pi/permission
17
+ */
18
+ import type { PermissionEvent } from '../driver-core/permission-knobs.ts';
19
+ import type { PiSandboxMode } from './types.ts';
20
+ /** The runtime stance one Pi RPC process should run under. */
21
+ export interface PiPermission {
22
+ /** Sandbox mode driving whether the child is wrapped in the dsh sandbox. */
23
+ readonly sandboxMode: PiSandboxMode;
24
+ /** The `--tools` allowlist; empty means "use Pi's native tools" (no pruning). */
25
+ readonly tools: readonly string[];
26
+ }
27
+ /** Conservative unattended default: read-only sandbox, no write/exec tools. */
28
+ export declare const DEFAULT_PI_PERMISSION: PiPermission;
29
+ /**
30
+ * Derive the `--tools` allowlist for a given sandbox stance. Full access prunes
31
+ * nothing; `workspace-write` allows a write-capable set; `read-only` allows read
32
+ * and search only.
33
+ * @param mode - the resolved sandbox stance.
34
+ * @returns the tool set to pass as `--tools`.
35
+ */
36
+ export declare function toolsForSandbox(mode: PiSandboxMode): readonly string[];
37
+ /**
38
+ * Resolve the session's effective Pi runtime stance.
39
+ * @param events - the durable session log.
40
+ * @returns the stance one Pi RPC process should run under.
41
+ */
42
+ export declare function resolveSessionPermission(events: readonly PermissionEvent[]): PiPermission;
43
+ //# sourceMappingURL=permission.d.ts.map
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Strict-LF JSONL client for the Pi RPC subprocess (`pi --mode rpc`).
3
+ *
4
+ * The driver hands the client a process handle carrying its stdin/stdout/stderr
5
+ * (projected from the dsh subprocess seam, so the whole `pi` child is sandboxed
6
+ * by the harness). The client frames records on a bare `\n` only — not on
7
+ * Unicode separators — using a byte decoder, tolerates a trailing `\r`, and
8
+ * correlates command responses by the optional `id` field while dispatching
9
+ * every non-response line to a buffered event stream.
10
+ *
11
+ * @module dsh-agent-hub/engine-pi/rpc/client
12
+ */
13
+ import type { ChildProcess } from 'node:child_process';
14
+ import type { Readable, Writable } from 'node:stream';
15
+ import type { PiCommand, PiEvent, PiResponse } from './types.ts';
16
+ /** A spawned Pi RPC process as the protocol transport needs it. */
17
+ export interface PiProcess {
18
+ /** Child stdin (command JSON lines). */
19
+ readonly stdin: Writable;
20
+ /** Child stdout (response + event JSON lines). */
21
+ readonly stdout: Readable;
22
+ /** Child stderr (diagnostics; buffered and dropped). */
23
+ readonly stderr: Readable;
24
+ /** Register a single human-readable termination callback. */
25
+ onExit(handler: () => void): void;
26
+ /** Request process-tree termination. */
27
+ terminate(): void;
28
+ }
29
+ /** The exact argv/cwd/env the driver requests for one `pi --mode rpc` child. */
30
+ export interface PiSpawnSpec {
31
+ /** The program plus its flags; `argv[0]` is the Pi CLI entrypoint. */
32
+ readonly argv: readonly string[];
33
+ readonly cwd: string;
34
+ readonly env: Record<string, string>;
35
+ }
36
+ /** Spawns one Pi RPC process over the given spec (the driver's spawn capability). */
37
+ export type PiSpawnCapability = (spec: PiSpawnSpec) => PiProcess;
38
+ /** Callback receiving every non-response event line. */
39
+ export type PiEventHandler = (event: PiEvent) => void;
40
+ /** Options for one `prompt` command. */
41
+ export interface PiPromptOptions {
42
+ readonly streamingBehavior?: 'steer' | 'followUp';
43
+ }
44
+ /** Project a `node:child_process` child onto the Pi protocol transport. */
45
+ export declare function fromChildProcess(child: ChildProcess): PiProcess;
46
+ /** Prompt the agent and stream its events. */
47
+ export declare class PiRpcClient {
48
+ private readonly process;
49
+ private reqId;
50
+ private pending;
51
+ private readonly eventBuffer;
52
+ private eventWake;
53
+ private eventHandler;
54
+ private disposed;
55
+ private readonly decoder;
56
+ private buffer;
57
+ private readonly onStderr;
58
+ /** Whether this client was disposed or its process exited. */
59
+ get closed(): boolean;
60
+ /** Mount a client over an already-spawned Pi RPC process. */
61
+ constructor(process: PiProcess);
62
+ /**
63
+ * Create a client, spawning the Pi RPC child through the supplied capability
64
+ * (or the default node-runtime spawn when none is given).
65
+ * @param spec - the Pi CLI argv/cwd/env the child should run with.
66
+ * @param spawn - optional process-spawn capability (the subprocess seam);
67
+ * absent falls back to the plain node child spawn.
68
+ * @returns the connected client.
69
+ */
70
+ static create(spec: PiSpawnSpec, spawn?: PiSpawnCapability): PiRpcClient;
71
+ /** Register the event dispatch handler. */
72
+ onEvent(handler: PiEventHandler): void;
73
+ /** Drop any events still buffered from a previous step (stateless per-step sessions). */
74
+ clearEvents(): void;
75
+ /** Start a fresh Pi session. */
76
+ newSession(): Promise<PiResponse>;
77
+ /** Prompt the agent and await the acceptance response. */
78
+ prompt(message: string, options?: PiPromptOptions): Promise<PiResponse>;
79
+ /** Abort the current agent operation. */
80
+ abort(): Promise<PiResponse>;
81
+ /** Query session stats. */
82
+ getSessionStats(): Promise<PiResponse>;
83
+ /** Send a command without awaiting its response (fire-and-forget). */
84
+ send(command: PiCommand): void;
85
+ /**
86
+ * Send a command and await the correlated response. Assigns a fresh `id`
87
+ * when the command carries none, so responses always round-trip.
88
+ */
89
+ request(command: PiCommand): Promise<PiResponse>;
90
+ /**
91
+ * Consume every buffered event as an async generator, waking as fresh lines
92
+ * arrive. The caller bounds the iteration by a terminal event; unmatched
93
+ * lines stay buffered for a later iteration.
94
+ */
95
+ events(): AsyncGenerator<PiEvent, void, void>;
96
+ /** Dispose the client and request child termination. */
97
+ dispose(): void;
98
+ /** Feed one chunk of stdout into the framing state machine. */
99
+ private feed;
100
+ /** Dispatch one parsed line to the pending map or the event queue. */
101
+ private dispatch;
102
+ /** Drain decoded stderr bytes (no-op consumer keeps the pipe flowing). */
103
+ private consumeStderr;
104
+ }
105
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Maps Pi RPC messages and end-of-execution events to dsh session-log events.
3
+ * Token-level streaming deltas are folded inline by the driver's step loop
4
+ * (they carry live progress); this module projects the end-state items — a
5
+ * completed tool call, a completed tool execution, and a finished turn's usage
6
+ * — into the durable `tool/call`, `tool/result`, and usage events.
7
+ *
8
+ * @module dsh-agent-hub/engine-pi/rpc/mapping
9
+ */
10
+ import type { TokenUsage, ToolResultMessage } from '@deepseek-ai/dsh-llm';
11
+ import type { PiUsage } from './types.ts';
12
+ /** Map one Pi usage snapshot to dsh TokenUsage. */
13
+ export declare function mapUsage(usage: PiUsage): TokenUsage;
14
+ /**
15
+ * Derive the compact transcript text of a Pi content block, joining nested
16
+ * text segments so the durable tool-result block carries the read model text.
17
+ * @param content - the result payload (e.g. `{ content: [{ type, text }, ...] }`).
18
+ * @returns the joined text.
19
+ */
20
+ export declare function resultText(content: unknown): string;
21
+ /** Map a completed Pi tool-execution end event to the durable tool/result message. */
22
+ export declare function mapToolResult(ev: {
23
+ toolCallId: string;
24
+ result: unknown;
25
+ isError: boolean;
26
+ }): ToolResultMessage;
27
+ /** Map the identity of a Pi message tool call or execution start to a durable tool/call. */
28
+ export declare function mapToolCall(ev: {
29
+ callId: string;
30
+ name: string;
31
+ arguments: unknown;
32
+ }): {
33
+ callId: string;
34
+ name: string;
35
+ arguments: string;
36
+ };
37
+ //# sourceMappingURL=mapping.d.ts.map