@lincyaw/dsh 0.2.0-rc.107 → 0.2.0-rc.108

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/cordis.patch.yml CHANGED
@@ -1,4 +1,23 @@
1
+ # DeltaBox owns execution inside Presmium's per-session candidate. Publication and
2
+ # author review remain one Presmium transaction, with source guards and validation.
3
+ - id: deltabox-runtime
4
+ disabled: true
5
+ - id: deltabox-review-policy
6
+ disabled: true
7
+ - id: ptc-runtime
8
+ disabled: true
9
+ - id: workflow-ptc
10
+ disabled: true
11
+ - id: tool-workflow
12
+ disabled: true
13
+
1
14
  - insert:
15
+ - id: presmium-deltabox-runtime
16
+ name: '@lincyaw/dsh/deltabox-runtime'
17
+ config:
18
+ binary: !!js process.env.DELTABOX_BINARY ?? 'deltabox'
19
+ fsMode: cbcow-private
20
+ projectSessionReuse: false
2
21
  - id: presmium-service
3
22
  name: '@lincyaw/dsh/service'
4
23
  config:
@@ -0,0 +1,3 @@
1
+ import { load } from './load.mjs'
2
+
3
+ export default (await load('deltabox-runtime.ts')).default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/dsh",
3
- "version": "0.2.0-rc.107",
3
+ "version": "0.2.0-rc.108",
4
4
  "description": "Presmium's bundle for DeepSeek Harness: the workbench of presmium studio, its host side (Presmium's tools, approvals, document context, skills and routes) and its client side (the root layout and the workbench's panels, precompiled) (experimental)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -35,6 +35,7 @@
35
35
  "./skills": "./entries/skills.mjs",
36
36
  "./routes": "./entries/routes.mjs",
37
37
  "./turns": "./entries/turns.mjs",
38
+ "./deltabox-runtime": "./entries/deltabox-runtime.mjs",
38
39
  "./telemetry": "./entries/telemetry.mjs",
39
40
  "./events": {
40
41
  "types": "./src/node/workspace-events.ts",
@@ -81,15 +82,16 @@
81
82
  ]
82
83
  },
83
84
  "dependencies": {
85
+ "dsh-deltabox": "0.1.8",
84
86
  "eventsource": "3.0.7",
85
87
  "jiti": "^2.7.0",
86
88
  "node-addon-require-builtin": "0.1.9",
87
89
  "ws": "8.22.0",
88
90
  "zod": "4.4.3",
89
- "@lincyaw/cli": "1.0.0-rc.108",
90
- "@lincyaw/kernel": "1.0.0-rc.108",
91
- "@lincyaw/mcp": "1.0.0-rc.108",
92
- "@lincyaw/skills": "1.0.0-rc.108"
91
+ "@lincyaw/cli": "1.0.0-rc.109",
92
+ "@lincyaw/kernel": "1.0.0-rc.109",
93
+ "@lincyaw/mcp": "1.0.0-rc.109",
94
+ "@lincyaw/skills": "1.0.0-rc.109"
93
95
  },
94
96
  "peerDependencies": {
95
97
  "@deepseek-ai/dsh": "0.2.1-alpha.4"
@@ -105,8 +107,8 @@
105
107
  "react": "18.3.1",
106
108
  "react-dom": "18.3.1",
107
109
  "react-resizable-panels": "^4.14.5",
108
- "@lincyaw/design": "1.0.0-rc.108",
109
- "@lincyaw/workbench": "0.2.0-rc.109"
110
+ "@lincyaw/design": "1.0.0-rc.109",
111
+ "@lincyaw/workbench": "0.2.0-rc.110"
110
112
  },
111
113
  "scripts": {}
112
114
  }
@@ -10,6 +10,7 @@ import { SERVER_ROUTES } from './server-routes.ts'
10
10
  import type { WorkspaceServerClient } from './service.ts'
11
11
  import { WorkspaceServerClient as CandidateServer } from './service.ts'
12
12
  import { WORKSPACE_ROUTES } from './server-routes.ts'
13
+ import { deltaboxOf, runtimeAgent } from './deltabox-runtime.ts'
13
14
 
14
15
  /** Fixed inputs owned by one pending invocation, including native resources that need retirement. */
15
16
  export interface PreparedBindingCall { signature: string, arguments: Record<string, unknown>, native?: PreparedMcpCall }
@@ -207,7 +208,9 @@ export class DocumentBindings {
207
208
  readonly #candidates = new Map<string, Promise<WorkspaceServerClient>>()
208
209
  readonly #parents = new Map<string, string>()
209
210
  readonly #candidateRoots = new Map<string, string>()
211
+ readonly #candidateViews = new Map<string, string>()
210
212
  readonly #candidateOwners = new Map<string, Set<string>>()
213
+ readonly #renewCandidates = new Set<string>()
211
214
 
212
215
  rootSessionOf(agent: DshAgent): string {
213
216
  const header = agent.session.header as { origin?: string, parentSession?: string } | undefined
@@ -226,7 +229,16 @@ export class DocumentBindings {
226
229
  if (!pending) {
227
230
  pending = (async () => {
228
231
  const { root } = await this.#server.requestJson<{ root: string }>(`${WORKSPACE_ROUTES}review/workspace`, { body: { session: id } })
229
- const candidate = new CandidateServer({ root, candidate: true, presmium: this.#server.presmium }, this.#log)
232
+ this.#candidateRoots.set(id, root)
233
+ const runtime = deltaboxOf(this.#ctx)
234
+ const previous = runtime?.existingSession(runtimeAgent(agent))
235
+ if (previous && previous.projectRoot !== root) await previous.close()
236
+ const session = await runtime?.acquireFor(runtimeAgent(agent))
237
+ if (session?.recoveredFrom && session.reviewActive) await session.reviewCommit()
238
+ if (session) await this.#server.requestJson(`${WORKSPACE_ROUTES}review/workspace`, { body: { session: id, resumed: true } })
239
+ const view = session ? (await session.target()).mountpoint : root
240
+ this.#candidateViews.set(id, view)
241
+ const candidate = new CandidateServer({ root: view, candidate: true, presmium: this.#server.presmium }, this.#log)
230
242
  await candidate.ready
231
243
  return candidate
232
244
  })()
@@ -235,7 +247,6 @@ export class DocumentBindings {
235
247
  }
236
248
  const candidate = await pending
237
249
  const directory = await candidate.ready
238
- this.#candidateRoots.set(id, directory.root)
239
250
  const workingDirectory = this.#ctx.get('workingDirectory') as { set(agent: DshAgent, path: string): Promise<string> } | undefined
240
251
  if (!workingDirectory) throw new Error('Presmium needs the workingDirectory service for concurrent authoring')
241
252
  if (!isInside(this.workingDirectoryOf(agent), directory.root)) await workingDirectory.set(agent, directory.root)
@@ -246,11 +257,34 @@ export class DocumentBindings {
246
257
  return agent ? this.#candidateRoots.get(this.rootSessionOf(agent)) : undefined
247
258
  }
248
259
 
260
+ candidateViewOf(agent: DshAgent | undefined): string | undefined {
261
+ return agent ? this.#candidateViews.get(this.rootSessionOf(agent)) : undefined
262
+ }
263
+
249
264
  async refreshCandidate(agent: DshAgent): Promise<void> {
250
265
  const { root } = await this.#server.ready
251
- if (!isInside(this.workingDirectoryOf(agent), root)) return
266
+ if (!this.candidateRootOf(agent) && !isInside(this.workingDirectoryOf(agent), root)) return
252
267
  await this.candidateOf(agent)
253
- await this.#server.requestJson(`${WORKSPACE_ROUTES}review/workspace`, { body: { session: this.rootSessionOf(agent), refresh: true } })
268
+ const id = this.rootSessionOf(agent)
269
+ const { changed } = await this.#server.requestJson<{ changed: boolean }>(`${WORKSPACE_ROUTES}review/workspace`, { body: { session: id, refresh: true } })
270
+ if (deltaboxOf(this.#ctx) && (changed || this.#renewCandidates.has(id))) {
271
+ await this.retireCandidate(agent)
272
+ await this.candidateOf(agent)
273
+ }
274
+ }
275
+
276
+ candidateChanged(agent: DshAgent): void { this.#renewCandidates.add(this.rootSessionOf(agent)) }
277
+
278
+ /** Retire the private view only at a tool/step boundary, before its next binding is installed. */
279
+ async retireCandidate(agent: DshAgent): Promise<void> {
280
+ const id = this.rootSessionOf(agent)
281
+ await this.unbind(agent.session.id, false)
282
+ const candidate = this.#candidates.get(id)
283
+ this.#candidates.delete(id)
284
+ if (candidate) await (await candidate).close()
285
+ this.#candidateViews.delete(id)
286
+ await deltaboxOf(this.#ctx)?.existingSession(runtimeAgent(agent))?.close()
287
+ this.#renewCandidates.delete(id)
254
288
  }
255
289
 
256
290
  constructor(ctx: DshContext, server: WorkspaceServerClient, log: DshLogger) {
@@ -292,7 +326,7 @@ export class DocumentBindings {
292
326
  const documents = await this.#server.readDocuments()
293
327
  const selected = this.#selected.get(id)
294
328
  const cwd = this.workingDirectoryOf(agent)
295
- if (!isInside(cwd, root)) return undefined
329
+ if (!this.candidateRootOf(agent) && !isInside(cwd, root)) return undefined
296
330
  const document = selected === undefined ? documentAt(root, agent.session.header?.cwd ?? root, documents) ?? (documents.length === 1 ? documents[0] : undefined) : documents.find(doc => doc.dir === selected)
297
331
  if (!current()) return undefined
298
332
  if (!document) {
@@ -408,6 +442,7 @@ export class DocumentBindings {
408
442
  if (owners?.size === 0) {
409
443
  this.#candidateOwners.delete(ownerId)
410
444
  this.#candidateRoots.delete(ownerId)
445
+ this.#candidateViews.delete(ownerId)
411
446
  const candidate = this.#candidates.get(ownerId)
412
447
  this.#candidates.delete(ownerId)
413
448
  if (candidate) await (await candidate).close()
@@ -431,6 +466,7 @@ export class DocumentBindings {
431
466
  await Promise.all([...this.#candidates.values()].map(async candidate => (await candidate).close()))
432
467
  this.#candidates.clear()
433
468
  this.#candidateRoots.clear()
469
+ this.#candidateViews.clear()
434
470
  this.#candidateOwners.clear()
435
471
  this.#parents.clear()
436
472
  }
@@ -0,0 +1,19 @@
1
+ import DeltaboxRuntime from 'dsh-deltabox/runtime'
2
+ import { realpathSync } from 'node:fs'
3
+ import type { DshAgent, DshContext } from './dsh-types.ts'
4
+ import type { Presmium } from './service.ts'
5
+
6
+ type RuntimeAgent = Parameters<DeltaboxRuntime['sessionFor']>[0]
7
+
8
+ /** The public runtime seam keeps DeltaBox inside the session's private Presmium candidate. */
9
+ export default class PresmiumDeltabox extends DeltaboxRuntime {
10
+ static inject = [...DeltaboxRuntime.inject, 'presmium']
11
+
12
+ projectRootFor(agent: RuntimeAgent): string {
13
+ const presmium = this.ctx.get('presmium') as Presmium | undefined
14
+ return realpathSync(presmium?.bindings.candidateRootOf(agent as unknown as DshAgent) ?? super.projectRootFor(agent))
15
+ }
16
+ }
17
+
18
+ export const deltaboxOf = (ctx: DshContext): DeltaboxRuntime | undefined => ctx.get('deltabox') as DeltaboxRuntime | undefined
19
+ export const runtimeAgent = (agent: DshAgent): RuntimeAgent => agent as unknown as RuntimeAgent
@@ -172,7 +172,7 @@ export function writeProfile(dshHome: string, name: string, carrier: Carrier, bu
172
172
  const manifestFile = join(dir, 'package.json')
173
173
  const saved = existsSync(manifestFile) ? JSON.parse(readFileSync(manifestFile, 'utf8')) : {}
174
174
  if (!saved || typeof saved !== 'object' || Array.isArray(saved)) throw new TypeError('Invalid profile package manifest')
175
- const required = ['@deepseek-ai/dsh-base', CARRIERS[carrier], PACKAGE_NAME]
175
+ const required = ['@deepseek-ai/dsh-base', CARRIERS[carrier], 'dsh-deltabox', PACKAGE_NAME]
176
176
  const extra = Array.isArray(saved.dsh?.profile?.bundles) ? saved.dsh.profile.bundles.filter((bundle: unknown) => typeof bundle === 'string' && !required.includes(bundle) && !Object.values(CARRIERS).includes(bundle as string)) : []
177
177
  writeChanged(manifestFile, `${JSON.stringify({
178
178
  ...saved,
@@ -193,5 +193,13 @@ export function writeProfile(dshHome: string, name: string, carrier: Carrier, bu
193
193
  rmSync(link, { force: true, recursive: true })
194
194
  symlinkSync(target, link, 'junction')
195
195
  }
196
+ const deltabox = join(dir, 'node_modules', 'dsh-deltabox')
197
+ const deltaboxTarget = dirname(createRequire(join(bundle, 'package.json')).resolve('dsh-deltabox/package.json'))
198
+ let currentDeltabox: string | undefined
199
+ try { currentDeltabox = realpathSync(deltabox) } catch {}
200
+ if (currentDeltabox !== deltaboxTarget) {
201
+ rmSync(deltabox, { force: true, recursive: true })
202
+ symlinkSync(deltaboxTarget, deltabox, 'junction')
203
+ }
196
204
  return dir
197
205
  }
@@ -56,10 +56,11 @@ export function apply(ctx: DshContext): void {
56
56
  const file = FILE_WRITE_TOOLS.has(exec.name) ? fileOf(exec) : undefined
57
57
  const dir = exec.agent ? ctx.presmium.bindings.workingDirectoryOf(exec.agent) : process.cwd()
58
58
  const candidate = ctx.presmium.bindings.candidateRootOf(exec.agent)
59
- if (candidate && authorRoot && file && isInside(resolve(dir, file), authorRoot) && !isInside(resolve(dir, file), candidate)) return 'Presmium: write in your current candidate workspace using relative paths. The author workspace changed independently; read the current candidate file and retry.'
59
+ const view = ctx.presmium.bindings.candidateViewOf(exec.agent)
60
+ if (candidate && authorRoot && file && isInside(resolve(dir, file), authorRoot) && !isInside(resolve(dir, file), candidate) && !(view && isInside(resolve(dir, file), view))) return 'Presmium: write in your current candidate workspace using relative paths. The author workspace changed independently; read the current candidate file and retry.'
60
61
  if (file && isInside(resolve(dir, file), operatorDir)) return `Presmium: the operator directory (${operatorDir}) is not the agent's to write`
61
62
  const command = exec.name === 'bash' ? (exec.arguments as { command?: unknown } | undefined)?.command : undefined
62
- if (candidate && authorRoot && typeof command === 'string' && command.replaceAll(candidate, '').includes(authorRoot)) return 'Presmium: use your current candidate workspace instead of the author workspace absolute path. Read the file there and retry.'
63
+ if (candidate && authorRoot && typeof command === 'string' && command.replaceAll(candidate, '').replaceAll(view ?? candidate, '').includes(authorRoot)) return 'Presmium: use your current candidate workspace instead of the author workspace absolute path. Read the file there and retry.'
63
64
  if (typeof command === 'string' && command.includes(operatorDir)) return `Presmium: the operator directory (${operatorDir}) is not the agent's to touch`
64
65
  return undefined
65
66
  })
package/src/node/tools.ts CHANGED
@@ -5,7 +5,7 @@ import type { DshAgent, DshAttachments, DshContentBlock, DshContext, DshImageMed
5
5
  import type { DocumentBinding, PreparedBindingCall } from './bindings.ts'
6
6
 
7
7
  export const name = 'presmium-tools'
8
- export const inject = ['presmium', 'tools']
8
+ export const inject = ['presmium', 'tools', 'deltabox']
9
9
 
10
10
  export const PREFIX = 'presmium__'
11
11
  export const CANDIDATE_TOOLS = new Set([
@@ -159,13 +159,14 @@ export function apply(ctx: DshContext): void {
159
159
  if (!live.has(agent)) return
160
160
  selections.set(agent, ctx.presmium.bindings.watchSelection(agent.session.id, { before: () => agent.whenIdle(), after: () => sync(agent) }))
161
161
  })
162
- ctx.on('agent/disposed', ({ agent }: { agent: DshAgent }) => {
162
+ ctx.on('agent/disposed', async ({ agent }: { agent: DshAgent }) => {
163
163
  live.delete(agent)
164
164
  selections.get(agent)?.(); selections.delete(agent)
165
165
  const previous = registered.get(agent)
166
166
  registered.delete(agent)
167
167
  previous?.stop?.()
168
168
  for (const dispose of previous?.dispose ?? []) dispose()
169
+ await ctx.presmium.bindings.retireCandidate(agent)
169
170
  })
170
171
  ctx.on('agent/pre-step', async ({ agent }: { agent: DshAgent }, next: () => Promise<unknown>) => {
171
172
  await ctx.presmium.bindings.refreshCandidate(agent)
package/src/node/turns.ts CHANGED
@@ -4,6 +4,7 @@ import { isInside } from '@lincyaw/kernel/node'
4
4
  import type { DshAgent, DshContext, DshToolExecution } from './dsh-types.ts'
5
5
  import { WORKSPACE_ROUTES } from './server-routes.ts'
6
6
  import { isCandidateTool, PREFIX, resolvePresmiumCall } from './tools.ts'
7
+ import { deltaboxOf, runtimeAgent } from './deltabox-runtime.ts'
7
8
 
8
9
  // What a writing tool answers when the change cannot be recorded. The AI reads it and tells the author in their own
9
10
  // language, so it names what the author sees (Version History) and none of the internals behind it.
@@ -104,7 +105,7 @@ export function apply(ctx: DshContext): void {
104
105
  ctx.on('tools/execute', async (exec: DshToolExecution, next: () => Promise<unknown>) => {
105
106
  if (!exec.agent) return next()
106
107
  const { root } = await ctx.presmium.server.ready
107
- if (!isInside(ctx.presmium.bindings.workingDirectoryOf(exec.agent), root)) return next()
108
+ if (!ctx.presmium.bindings.candidateRootOf(exec.agent) && !isInside(ctx.presmium.bindings.workingDirectoryOf(exec.agent), root)) return next()
108
109
  await ctx.presmium.bindings.candidateOf(exec.agent)
109
110
  const binding = ctx.presmium.bindings.bindingOf(exec.agent)
110
111
  const target = exec.name.startsWith(PREFIX) ? await resolvePresmiumCall(binding, exec) : undefined
@@ -114,13 +115,23 @@ export function apply(ctx: DshContext): void {
114
115
  const agentSessionId = rootAgentSessionOf(exec.agent.session.id)
115
116
  const state = turnStateOf(agentSessionId)
116
117
  try {
117
- await postReview(document, agentSessionId, 'open', state.turn !== undefined ? { turn: state.turn } : {})
118
+ await postReview(document, agentSessionId, 'open', { ...state.turn !== undefined ? { turn: state.turn } : {}, ...deltaboxOf(ctx) ? { backend: 'deltabox' } : {} })
118
119
  } catch (error) {
119
120
  throw new Error(`${errorMessage(error)} ${NOTHING_CHANGED}`)
120
121
  }
121
122
  state.document = document
122
123
  state.wrote = true
123
- const result = await next()
124
+ const session = await deltaboxOf(ctx)?.acquireFor(runtimeAgent(exec.agent))
125
+ let result
126
+ try {
127
+ result = session && target ? await session.runMutable(() => next()) : await next()
128
+ if (session?.reviewActive) await session.reviewCommit()
129
+ } catch (error) {
130
+ if (session?.reviewActive) await session.reviewAbort()
131
+ ctx.presmium.bindings.candidateChanged(exec.agent)
132
+ throw error
133
+ }
134
+ ctx.presmium.bindings.candidateChanged(exec.agent)
124
135
  await postReview(document, agentSessionId, 'step', { ...state.turn !== undefined ? { turn: state.turn } : {}, label: labelOf(target ? { ...exec, name: PREFIX + target.tool.name, arguments: target.arguments } : exec), tool: target ? PREFIX + target.tool.name : exec.name })
125
136
  return result
126
137
  })
package/web.patch.yml CHANGED
@@ -10,6 +10,20 @@
10
10
 
11
11
  - id: harness-dev-context
12
12
  disabled: true
13
+ - id: agent-preset-registry
14
+ disabled: false
15
+ - id: open-in-app
16
+ disabled: true
17
+ - id: job-controller
18
+ disabled: true
19
+ - id: terminal-controller
20
+ disabled: true
21
+ - id: ui-sidebar-terminal
22
+ disabled: true
23
+ - id: ui-jobs
24
+ disabled: true
25
+ - id: workspace-changes
26
+ disabled: true
13
27
 
14
28
  - insert:
15
29
  - id: presmium-workbench
@@ -79,18 +93,16 @@
79
93
  name: '@deepseek-ai/dsh-time-context'
80
94
  - id: tool-bash
81
95
  name: '@deepseek-ai/dsh-tool-bash'
96
+ config:
97
+ enableRunInBackground: false
82
98
  disabled: !!js process.platform === 'win32'
83
99
  - id: tool-pwsh
84
100
  name: '@deepseek-ai/dsh-tool-pwsh'
101
+ config:
102
+ enableRunInBackground: false
85
103
  disabled: !!js process.platform !== 'win32'
86
104
  - id: tool-fs
87
105
  name: '@deepseek-ai/dsh-tool-fs'
88
- - id: tool-fs-search
89
- name: '@deepseek-ai/dsh-tool-fs-search'
90
- config:
91
- sampleOverCapGlobResults: false
92
- - id: tool-jobs
93
- name: '@deepseek-ai/dsh-tool-jobs'
94
106
  - id: skill-filesystem
95
107
  name: '@deepseek-ai/dsh-skill-filesystem'
96
108
  - id: tool-skill