@4fu/dsh-arbor-host 0.0.0-stage → 2026.1110.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/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@4fu/dsh-arbor-host",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2026.1110.0",
4
+ "type": "module",
5
+ "description": "The one Arbor host a DSH process runs: the durable SQLite journal and note store under DSH_HOME/arbor, the settings and the window lifecycle",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "dependencies": {
14
+ "@4fu/arbor-core": "2026.1109.1",
15
+ "@4fu/arbor-environment-dir": "2026.1109.1",
16
+ "@4fu/arbor-interfaces": "2026.1109.1",
17
+ "@4fu/arbor-journal-sqlite": "2026.1109.1",
18
+ "@4fu/arbor-notes-sqlite": "2026.1109.1",
19
+ "@4fu/arbor-prompt": "2026.1109.1",
20
+ "@4fu/arbor-workspace-dir": "2026.1109.1",
21
+ "@4fu/dsh-arbor-env": "2026.1110.0",
22
+ "@4fu/dsh-arbor-llm": "2026.1110.0",
23
+ "@4fu/dsh-arbor-prompt": "2026.1110.0",
24
+ "@4fu/dsh-arbor-workspace": "2026.1110.0",
25
+ "@deepseek-ai/cordis": "4.1.0",
26
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
27
+ "@deepseek-ai/dsh-home-paths": "0.2.2-rc.1",
28
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
29
+ "@deepseek-ai/dsh-plan-mode": "0.2.2-rc.1",
30
+ "@deepseek-ai/dsh-session": "0.2.2-rc.1",
31
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
32
+ "@deepseek-ai/dsh-skill": "0.2.2-rc.1",
33
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
34
+ "@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
35
+ "@deepseek-ai/dsh-working-directory": "0.2.2-rc.1",
36
+ "@deepseek-ai/dsh-workspace": "0.2.2-rc.1",
37
+ "@deepseek-ai/schemastery": "~3.19.0"
38
+ },
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/4fuu/dsh-arbor.git",
43
+ "directory": "packages/arbor-host"
44
+ },
45
+ "engines": {
46
+ "node": ">=24.9.0",
47
+ "dsh": "0.2.2-rc.1"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "files": [
53
+ "index.d.ts",
54
+ "index.js",
55
+ "send.d.ts",
56
+ "send.js"
57
+ ],
58
+ "types": "./index.d.ts",
59
+ "main": "./index.js"
60
+ }
package/send.d.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The `send` executor: what a window sends reaches the DSH user.
3
+ *
4
+ * Arbor's `send` records an effect and hands it to the queue, which carries it
5
+ * out only when an executor owns it. Nothing in arbor's core knows about DSH,
6
+ * so without this module every send a window makes stays queued forever and the
7
+ * window's own result line — `已记录 r4,效果已入队。` — is the last anyone hears
8
+ * of it. That is the honest answer for a target nobody owns, and the wrong one
9
+ * for the target this deployment exists to serve: the DSH user, who sees only
10
+ * what `send` writes.
11
+ *
12
+ * So this executor owns the DSH targets and lands their content on the session
13
+ * log as an assistant message, which is the surface DSH's client renders — the
14
+ * same one the official agent loop writes the model's reply to. The markdown
15
+ * link syntax `<harness>` states (`![说明](<绝对路径>)`, `[文件名](<路径#L24>)`)
16
+ * is DSH's own `ui:deliverable-file-references` wording, so a link written that
17
+ * way renders the way DSH renders any assistant message.
18
+ *
19
+ * Two target forms are owned:
20
+ *
21
+ * - `dsh:user` — the user of the session that sent it. The session is read back
22
+ * from the journal, the same way the workspace reads it, so a send made
23
+ * after its turn ended still lands on the right session's log.
24
+ * - `dsh:session:<id>` — one named session's user, for a window that addresses
25
+ * another session directly.
26
+ *
27
+ * Every other target stays unowned, which is arbor's own answer for a channel
28
+ * nobody plugged in: the effect is recorded, the queue waits, and the window is
29
+ * told the effect is queued rather than delivered.
30
+ */
31
+ import type { AgentRegistry } from '@deepseek-ai/dsh-agent';
32
+ import type { Effect, EffectExecutor, EffectResult, Journal } from '@4fu/arbor-interfaces';
33
+ /** The target prefix every DSH target carries. */
34
+ export declare const DSH_TARGET_PREFIX = "dsh:";
35
+ /** The target that names the DSH user of the session that sent. */
36
+ export declare const DSH_USER_TARGET = "dsh:user";
37
+ /** Inputs for {@link DshSendExecutor}. */
38
+ export interface DshSendExecutorOptions {
39
+ /** The journal, to read which DSH session one window belongs to. */
40
+ readonly journal: Journal;
41
+ /** DSH's agent registry, to reach a session's log by its id. */
42
+ readonly agents: AgentRegistry;
43
+ }
44
+ /**
45
+ * Carries a window's `send` out onto the DSH session log.
46
+ *
47
+ * The append happens while the turn that made the send is still in flight —
48
+ * `EffectQueue.submit` starts the drain before it returns — so the message the
49
+ * user reads appears beside the tool call that produced it rather than after
50
+ * the turn. The turn and step are read off the log rather than passed in, so a
51
+ * send made outside any turn (a restart's replay, a scheduled task) still lands
52
+ * at a position the log accepts.
53
+ */
54
+ export declare class DshSendExecutor implements EffectExecutor {
55
+ readonly id = "dsh-send";
56
+ private readonly journal;
57
+ private readonly agents;
58
+ /** Messages waiting for the tool result that must precede them on the log. */
59
+ private readonly pending;
60
+ constructor(options: DshSendExecutorOptions);
61
+ can(effect: Effect): boolean;
62
+ run(effect: Effect): Promise<EffectResult>;
63
+ /**
64
+ * Write every delivered send after the tool results that precede it.
65
+ *
66
+ * The driver calls this once per step, after all of the step's tool calls
67
+ * have their results on the log. A message whose step has already closed is
68
+ * dropped rather than allowed to make the stored log invalid.
69
+ */
70
+ flush(): void;
71
+ /**
72
+ * The DSH agent one effect addresses.
73
+ *
74
+ * A `dsh:session:<id>` target names it directly. `dsh:user` asks which
75
+ * session the sending window belongs to, which the journal records on the
76
+ * window's own `window_start` event — the same record the workspace reads for
77
+ * a window's root, so the two answers cannot disagree.
78
+ */
79
+ private agentOf;
80
+ /** The DSH session one window belongs to, from the journal's own record. */
81
+ private windowSession;
82
+ }
package/send.js ADDED
@@ -0,0 +1,206 @@
1
+ /**
2
+ * The `send` executor: what a window sends reaches the DSH user.
3
+ *
4
+ * Arbor's `send` records an effect and hands it to the queue, which carries it
5
+ * out only when an executor owns it. Nothing in arbor's core knows about DSH,
6
+ * so without this module every send a window makes stays queued forever and the
7
+ * window's own result line — `已记录 r4,效果已入队。` — is the last anyone hears
8
+ * of it. That is the honest answer for a target nobody owns, and the wrong one
9
+ * for the target this deployment exists to serve: the DSH user, who sees only
10
+ * what `send` writes.
11
+ *
12
+ * So this executor owns the DSH targets and lands their content on the session
13
+ * log as an assistant message, which is the surface DSH's client renders — the
14
+ * same one the official agent loop writes the model's reply to. The markdown
15
+ * link syntax `<harness>` states (`![说明](<绝对路径>)`, `[文件名](<路径#L24>)`)
16
+ * is DSH's own `ui:deliverable-file-references` wording, so a link written that
17
+ * way renders the way DSH renders any assistant message.
18
+ *
19
+ * Two target forms are owned:
20
+ *
21
+ * - `dsh:user` — the user of the session that sent it. The session is read back
22
+ * from the journal, the same way the workspace reads it, so a send made
23
+ * after its turn ended still lands on the right session's log.
24
+ * - `dsh:session:<id>` — one named session's user, for a window that addresses
25
+ * another session directly.
26
+ *
27
+ * Every other target stays unowned, which is arbor's own answer for a channel
28
+ * nobody plugged in: the effect is recorded, the queue waits, and the window is
29
+ * told the effect is queued rather than delivered.
30
+ */
31
+ import { createAssistantMessage } from '@deepseek-ai/dsh-llm';
32
+ import { MAX_PAGE_LIMIT } from '@4fu/arbor-interfaces';
33
+ import { SESSION_TARGET_PREFIX } from "./index.js";
34
+ /** The target prefix every DSH target carries. */
35
+ export const DSH_TARGET_PREFIX = 'dsh:';
36
+ /** The target that names the DSH user of the session that sent. */
37
+ export const DSH_USER_TARGET = 'dsh:user';
38
+ /**
39
+ * Carries a window's `send` out onto the DSH session log.
40
+ *
41
+ * The append happens while the turn that made the send is still in flight —
42
+ * `EffectQueue.submit` starts the drain before it returns — so the message the
43
+ * user reads appears beside the tool call that produced it rather than after
44
+ * the turn. The turn and step are read off the log rather than passed in, so a
45
+ * send made outside any turn (a restart's replay, a scheduled task) still lands
46
+ * at a position the log accepts.
47
+ */
48
+ export class DshSendExecutor {
49
+ id = 'dsh-send';
50
+ journal;
51
+ agents;
52
+ /** Messages waiting for the tool result that must precede them on the log. */
53
+ pending = [];
54
+ constructor(options) {
55
+ this.journal = options.journal;
56
+ this.agents = options.agents;
57
+ }
58
+ can(effect) {
59
+ return effect.kind === 'send' && effect.target.startsWith(DSH_TARGET_PREFIX);
60
+ }
61
+ async run(effect) {
62
+ const text = sendText(effect);
63
+ if (text === '') {
64
+ return {
65
+ ok: false,
66
+ error: {
67
+ code: 'invalid_input',
68
+ rule: 'send.content.empty',
69
+ message: 'dsh-arbor: a send carried no text',
70
+ nextAction: '补上要发送的内容,然后重发。',
71
+ },
72
+ };
73
+ }
74
+ const agent = await this.agentOf(effect);
75
+ if (agent === undefined) {
76
+ return {
77
+ ok: false,
78
+ error: {
79
+ code: 'unavailable',
80
+ rule: 'send.session.absent',
81
+ message: `dsh-arbor: no DSH session owns the window that sent to ${effect.target}`,
82
+ nextAction: '确认这个窗口还属于一个存活的 DSH 会话,然后重发。',
83
+ },
84
+ };
85
+ }
86
+ // The send runs inside the window's tool call, before the driver has
87
+ // appended the call's `tool/result`. DSH requires the result immediately
88
+ // after the call, so the assistant message waits in this queue until the
89
+ // driver has appended every result of the step; it then lands before the
90
+ // step closes. Delaying with a timer is not enough: the message must belong
91
+ // to an open turn and step, and a timer can fire after the turn ended and
92
+ // corrupts the stored log.
93
+ const session = agent.session;
94
+ const position = positionOf(session);
95
+ const message = createAssistantMessage({
96
+ content: [{ type: 'text', text }],
97
+ source: attributionOf(agent),
98
+ });
99
+ this.pending.push(() => {
100
+ session.append('assistant/message', { ...position, message, stream: [] }, { surfaceOp: 'append' });
101
+ });
102
+ return { ok: true };
103
+ }
104
+ /**
105
+ * Write every delivered send after the tool results that precede it.
106
+ *
107
+ * The driver calls this once per step, after all of the step's tool calls
108
+ * have their results on the log. A message whose step has already closed is
109
+ * dropped rather than allowed to make the stored log invalid.
110
+ */
111
+ flush() {
112
+ for (const append of this.pending.splice(0)) {
113
+ try {
114
+ append();
115
+ }
116
+ catch {
117
+ // The turn closed before the driver flushed; the effect result already
118
+ // records the delivery and the log must stay valid.
119
+ }
120
+ }
121
+ }
122
+ /**
123
+ * The DSH agent one effect addresses.
124
+ *
125
+ * A `dsh:session:<id>` target names it directly. `dsh:user` asks which
126
+ * session the sending window belongs to, which the journal records on the
127
+ * window's own `window_start` event — the same record the workspace reads for
128
+ * a window's root, so the two answers cannot disagree.
129
+ */
130
+ async agentOf(effect) {
131
+ if (effect.target !== DSH_USER_TARGET && effect.target.startsWith(SESSION_TARGET_PREFIX)) {
132
+ const named = effect.target.slice(SESSION_TARGET_PREFIX.length);
133
+ return this.agents.get(named);
134
+ }
135
+ const window = await this.windowSession(effect.madeBy);
136
+ return window === undefined ? undefined : this.agents.get(window);
137
+ }
138
+ /** The DSH session one window belongs to, from the journal's own record. */
139
+ async windowSession(window) {
140
+ for (let offset = 0;; offset += MAX_PAGE_LIMIT) {
141
+ const page = await this.journal.list({ window, kinds: ['window_start'], limit: MAX_PAGE_LIMIT, offset });
142
+ for (const event of page.items) {
143
+ // The label is the deployment's own attachment - the DSH session id -
144
+ // carried by arbor onto the window's start. A journal written before
145
+ // labels carries the session as a target instead.
146
+ if (event.body !== null) {
147
+ try {
148
+ const parsed = JSON.parse(event.body);
149
+ const label = parsed?.label;
150
+ if (typeof label === 'string' && label !== '')
151
+ return label;
152
+ }
153
+ catch {
154
+ // A body that is not JSON names no label.
155
+ }
156
+ }
157
+ const target = event.targets.find(one => one.startsWith(SESSION_TARGET_PREFIX));
158
+ if (target !== undefined)
159
+ return target.slice(SESSION_TARGET_PREFIX.length);
160
+ }
161
+ if (page.items.length < MAX_PAGE_LIMIT)
162
+ return undefined;
163
+ }
164
+ }
165
+ }
166
+ /**
167
+ * The text one `send` effect carries.
168
+ *
169
+ * The host wraps a send's content in a `data` block whose `content` field is
170
+ * the string the model wrote, so the text is that field rather than the block's
171
+ * rendered form.
172
+ */
173
+ function sendText(effect) {
174
+ const value = effect.content[0]?.fields['content'];
175
+ return typeof value === 'string' ? value : '';
176
+ }
177
+ /**
178
+ * The turn and step a send lands at.
179
+ *
180
+ * The newest `step/start` on the log, so the message joins the step that asked
181
+ * for it. A log with no step yet — a send made before any turn — lands at 0:0,
182
+ * which is where the loop puts the session's first system prompt.
183
+ */
184
+ function positionOf(session) {
185
+ for (let seq = session.seq - 1; seq >= 0; seq -= 1) {
186
+ const event = session.eventAt(seq);
187
+ if (event?.type === 'step/start')
188
+ return { turn: event.data.turn, step: event.data.step };
189
+ }
190
+ return { turn: 0, step: 0 };
191
+ }
192
+ /**
193
+ * Who the sent message is attributed to.
194
+ *
195
+ * The session agent's own model selection, so the message reads as this
196
+ * session's model having said it — the same attribution the official loop
197
+ * writes. An agent with no selection yet (a send before the first model call)
198
+ * is attributed to arbor, which is the driver that produced it.
199
+ */
200
+ function attributionOf(agent) {
201
+ const selection = agent.model.current();
202
+ return {
203
+ provider: selection?.provider ?? 'arbor',
204
+ model: selection?.model ?? 'arbor',
205
+ };
206
+ }