@lincyaw/dsh 0.2.0-rc.26 → 0.2.0-rc.28
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/build/dist/client.js +205 -205
- package/build/dist/client.json +5 -2
- package/package.json +7 -7
- package/src/client/messages.ts +2 -2
- package/src/node/bindings.ts +88 -6
- package/src/node/context.ts +4 -3
- package/src/node/policy.ts +5 -0
- package/src/node/routes.ts +1 -1
- package/src/node/service.ts +3 -0
- package/src/node/tools.ts +9 -1
- package/src/node/turns.ts +11 -8
package/build/dist/client.json
CHANGED
|
@@ -46,6 +46,9 @@
|
|
|
46
46
|
"../kernel/src/contracts/document-image.ts",
|
|
47
47
|
"../kernel/src/contracts.ts",
|
|
48
48
|
"../kernel/src/random-uuid.ts",
|
|
49
|
+
"../kernel/src/access.ts",
|
|
50
|
+
"../kernel/src/document-places.ts",
|
|
51
|
+
"../kernel/src/document-comments.ts",
|
|
49
52
|
"../kernel/src/document-operations.ts",
|
|
50
53
|
"../kernel/src/document-schema.ts",
|
|
51
54
|
"../kernel/src/authoring.ts",
|
|
@@ -54,8 +57,6 @@
|
|
|
54
57
|
"../kernel/src/document-reads.ts",
|
|
55
58
|
"../kernel/src/document-voices.ts",
|
|
56
59
|
"../kernel/src/document-colors.ts",
|
|
57
|
-
"../kernel/src/access.ts",
|
|
58
|
-
"../kernel/src/document-comments.ts",
|
|
59
60
|
"../kernel/src/document-caption-timings.ts",
|
|
60
61
|
"../kernel/src/parameters.ts",
|
|
61
62
|
"../kernel/src/document.ts",
|
|
@@ -176,6 +177,7 @@
|
|
|
176
177
|
"../workbench/src/document-editor/inline.ts",
|
|
177
178
|
"../workbench/src/document-editor/rich-text.ts",
|
|
178
179
|
"../workbench/src/document-editor/comments.ts",
|
|
180
|
+
"../workbench/src/document-editor/component-label.ts",
|
|
179
181
|
"../workbench/src/document-editor/DocumentComments.tsx",
|
|
180
182
|
"../workbench/src/document-editor/NewCommentDrafts.tsx",
|
|
181
183
|
"../workbench/src/document-editor/BlockNoteSurface.tsx",
|
|
@@ -223,6 +225,7 @@
|
|
|
223
225
|
"../workbench/src/component-property-messages.ts",
|
|
224
226
|
"../workbench/src/document-editor/ComponentMaterials.tsx",
|
|
225
227
|
"../workbench/src/document-editor/ComponentPropertiesDialog.tsx",
|
|
228
|
+
"../workbench/src/document-editor/PlaceComment.tsx",
|
|
226
229
|
"../workbench/src/document-editor/DocumentBlockPreview.tsx",
|
|
227
230
|
"../workbench/src/panels/SourceDocumentPanel.tsx",
|
|
228
231
|
"../workbench/src/panels/DocumentNarrationPanel.tsx",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/dsh",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.28",
|
|
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": {
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
"jiti": "^2.7.0",
|
|
85
85
|
"ws": "8.22.0",
|
|
86
86
|
"zod": "4.4.3",
|
|
87
|
-
"@lincyaw/cli": "1.0.0-rc.
|
|
88
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
89
|
-
"@lincyaw/
|
|
90
|
-
"@lincyaw/
|
|
87
|
+
"@lincyaw/cli": "1.0.0-rc.29",
|
|
88
|
+
"@lincyaw/kernel": "1.0.0-rc.29",
|
|
89
|
+
"@lincyaw/mcp": "1.0.0-rc.29",
|
|
90
|
+
"@lincyaw/skills": "1.0.0-rc.29"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"@deepseek-ai/dsh": "0.2.1-alpha.4"
|
|
@@ -103,8 +103,8 @@
|
|
|
103
103
|
"react": "18.3.1",
|
|
104
104
|
"react-dom": "18.3.1",
|
|
105
105
|
"react-resizable-panels": "^4.14.5",
|
|
106
|
-
"@lincyaw/design": "1.0.0-rc.
|
|
107
|
-
"@lincyaw/workbench": "0.2.0-rc.
|
|
106
|
+
"@lincyaw/design": "1.0.0-rc.29",
|
|
107
|
+
"@lincyaw/workbench": "0.2.0-rc.28"
|
|
108
108
|
},
|
|
109
109
|
"scripts": {}
|
|
110
110
|
}
|
package/src/client/messages.ts
CHANGED
|
@@ -37,7 +37,7 @@ const zh = {
|
|
|
37
37
|
models: '设置模型',
|
|
38
38
|
helpItems: [
|
|
39
39
|
'直接在文稿中输入即可修改。修改自动保存,文稿上方显示“已保存”。',
|
|
40
|
-
'
|
|
40
|
+
'选中文字会出现格式工具栏:段落样式、加粗、对齐、颜色、“插入链接”与“新建批注”。“新建批注”在选中的文字上留下批注,“批注”窗格列出全部批注。动画、图表的预览工具栏里有“本步批注”,可以对整个内容块或其中一步批注。',
|
|
41
41
|
'鼠标移到一段内容上,旁边的“插入内容块”可插入标题、列表、表格、图片等内容,“打开内容块菜单”可删除这一段或修改它的颜色。',
|
|
42
42
|
'“导航窗格”列出全部页面:“新建页面”添加一页,页面旁的“更多”可以重命名、复制、上移、下移或删除这一页。',
|
|
43
43
|
'“撤消”({undo})与“恢复”({redo})逐步撤消或恢复修改。“版本历史”列出保存过的每次修改,“撤消此更改”单独撤消其中一次。',
|
|
@@ -109,7 +109,7 @@ const en: ClientMessages = {
|
|
|
109
109
|
models: 'Set Up a Model',
|
|
110
110
|
helpItems: [
|
|
111
111
|
'Type directly in the document to change it. Changes save automatically, and the top of the document shows Saved.',
|
|
112
|
-
'Select text to show the formatting toolbar: paragraph style, Bold, alignment, Colors, Insert Link, and New Comment. New Comment leaves a comment on the selected text; the Comments pane lists them all.',
|
|
112
|
+
'Select text to show the formatting toolbar: paragraph style, Bold, alignment, Colors, Insert Link, and New Comment. New Comment leaves a comment on the selected text; the Comments pane lists them all. An animation or chart preview also has Comment on step, for the whole content block or one step.',
|
|
113
113
|
'Point at a paragraph: Insert Block, beside it, inserts a heading, list, table, picture, and more; Open Block Menu deletes the paragraph or changes its colors.',
|
|
114
114
|
'The Navigation Pane lists the pages: New Page adds one, and More beside a page renames, duplicates, moves, or deletes it.',
|
|
115
115
|
'Undo ({undo}) and Redo ({redo}) step back and forth through your changes. Version History lists every saved change; Undo This Change reverses one of them.',
|
package/src/node/bindings.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { realpathSync } from 'node:fs'
|
|
2
2
|
import { relative, resolve, sep } from 'node:path'
|
|
3
|
+
import { isInside } from '@lincyaw/kernel/node'
|
|
3
4
|
import { connectPresmiumMcp } from '@lincyaw/mcp/client'
|
|
4
5
|
import { errorMessage, isRecord } from '@lincyaw/kernel'
|
|
5
6
|
import type { DiagnosticSnapshot, DocumentSummary } from '@lincyaw/kernel'
|
|
@@ -7,6 +8,8 @@ import type { ListedTool, PresmiumMcpClient } from '@lincyaw/mcp/client'
|
|
|
7
8
|
import type { DshAgent, DshContext, DshLogger } from './dsh-types.ts'
|
|
8
9
|
import { SERVER_ROUTES } from './server-routes.ts'
|
|
9
10
|
import type { WorkspaceServerClient } from './service.ts'
|
|
11
|
+
import { WorkspaceServerClient as CandidateServer } from './service.ts'
|
|
12
|
+
import { WORKSPACE_ROUTES } from './server-routes.ts'
|
|
10
13
|
|
|
11
14
|
/** The document an agent session works on: an MCP client with a session token for it, its tools and its diagnostics. */
|
|
12
15
|
export interface DocumentBinding {
|
|
@@ -14,6 +17,8 @@ export interface DocumentBinding {
|
|
|
14
17
|
document: DocumentSummary
|
|
15
18
|
dir: string
|
|
16
19
|
client: PresmiumMcpClient
|
|
20
|
+
authorClient: PresmiumMcpClient
|
|
21
|
+
workspaceRoot: string
|
|
17
22
|
readonly tools: ListedTool[]
|
|
18
23
|
toolChanges: BindingTools
|
|
19
24
|
diagnostics: BindingDiagnostics
|
|
@@ -154,7 +159,7 @@ async function closeBinding(binding: DocumentBinding): Promise<void> {
|
|
|
154
159
|
try {
|
|
155
160
|
await Promise.all([binding.diagnostics.close(), binding.toolChanges.close()])
|
|
156
161
|
} finally {
|
|
157
|
-
await binding.client.close()
|
|
162
|
+
await Promise.all([binding.client.close(), binding.authorClient.close()])
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
|
|
@@ -189,6 +194,54 @@ export class DocumentBindings {
|
|
|
189
194
|
readonly #selectionListeners = new Map<string, SelectionListener>()
|
|
190
195
|
readonly #selected = new Map<string, string | null>()
|
|
191
196
|
#closed = false
|
|
197
|
+
readonly #candidates = new Map<string, Promise<WorkspaceServerClient>>()
|
|
198
|
+
readonly #parents = new Map<string, string>()
|
|
199
|
+
readonly #candidateRoots = new Map<string, string>()
|
|
200
|
+
readonly #candidateOwners = new Map<string, Set<string>>()
|
|
201
|
+
|
|
202
|
+
rootSessionOf(agent: DshAgent): string {
|
|
203
|
+
const header = agent.session.header as { origin?: string, parentSession?: string } | undefined
|
|
204
|
+
if (header?.origin === 'subagent' && header.parentSession) this.#parents.set(agent.session.id, header.parentSession)
|
|
205
|
+
let id = agent.session.id
|
|
206
|
+
for (let depth = 0; depth < 32 && this.#parents.has(id); depth++) id = this.#parents.get(id)!
|
|
207
|
+
return id
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async candidateOf(agent: DshAgent): Promise<WorkspaceServerClient> {
|
|
211
|
+
const id = this.rootSessionOf(agent)
|
|
212
|
+
let owners = this.#candidateOwners.get(id)
|
|
213
|
+
if (!owners) this.#candidateOwners.set(id, owners = new Set())
|
|
214
|
+
owners.add(agent.session.id)
|
|
215
|
+
let pending = this.#candidates.get(id)
|
|
216
|
+
if (!pending) {
|
|
217
|
+
pending = (async () => {
|
|
218
|
+
const { root } = await this.#server.requestJson<{ root: string }>(`${WORKSPACE_ROUTES}review/workspace`, { body: { session: id } })
|
|
219
|
+
const candidate = new CandidateServer({ root, candidate: true }, this.#log)
|
|
220
|
+
await candidate.ready
|
|
221
|
+
return candidate
|
|
222
|
+
})()
|
|
223
|
+
this.#candidates.set(id, pending)
|
|
224
|
+
void pending.catch(() => { if (this.#candidates.get(id) === pending) this.#candidates.delete(id) })
|
|
225
|
+
}
|
|
226
|
+
const candidate = await pending
|
|
227
|
+
const directory = await candidate.ready
|
|
228
|
+
this.#candidateRoots.set(id, directory.root)
|
|
229
|
+
const workingDirectory = this.#ctx.get('workingDirectory') as { set(agent: DshAgent, path: string): Promise<string> } | undefined
|
|
230
|
+
if (!workingDirectory) throw new Error('Presmium needs the workingDirectory service for concurrent authoring')
|
|
231
|
+
if (!isInside(this.workingDirectoryOf(agent), directory.root)) await workingDirectory.set(agent, directory.root)
|
|
232
|
+
return candidate
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
candidateRootOf(agent: DshAgent | undefined): string | undefined {
|
|
236
|
+
return agent ? this.#candidateRoots.get(this.rootSessionOf(agent)) : undefined
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async refreshCandidate(agent: DshAgent): Promise<void> {
|
|
240
|
+
const { root } = await this.#server.ready
|
|
241
|
+
if (!isInside(this.workingDirectoryOf(agent), root)) return
|
|
242
|
+
await this.candidateOf(agent)
|
|
243
|
+
await this.#server.requestJson(`${WORKSPACE_ROUTES}review/workspace`, { body: { session: this.rootSessionOf(agent), refresh: true } })
|
|
244
|
+
}
|
|
192
245
|
|
|
193
246
|
constructor(ctx: DshContext, server: WorkspaceServerClient, log: DshLogger) {
|
|
194
247
|
this.#ctx = ctx
|
|
@@ -228,18 +281,26 @@ export class DocumentBindings {
|
|
|
228
281
|
const id = agent.session.id
|
|
229
282
|
const documents = await this.#server.readDocuments()
|
|
230
283
|
const selected = this.#selected.get(id)
|
|
231
|
-
const
|
|
284
|
+
const cwd = this.workingDirectoryOf(agent)
|
|
285
|
+
if (!isInside(cwd, root)) return undefined
|
|
286
|
+
const document = selected === undefined ? documentAt(root, agent.session.header?.cwd ?? root, documents) ?? (documents.length === 1 ? documents[0] : undefined) : documents.find(doc => doc.dir === selected)
|
|
232
287
|
if (!current()) return undefined
|
|
233
288
|
if (!document) {
|
|
234
289
|
this.#failures.delete(id)
|
|
235
290
|
return undefined
|
|
236
291
|
}
|
|
237
|
-
const
|
|
292
|
+
const candidate = await this.candidateOf(agent)
|
|
293
|
+
const [grant, authorGrant] = await Promise.all([
|
|
294
|
+
candidate.requestJson<{ url: string, token: string }>(`${SERVER_ROUTES}tokens`, { body: { document: document.dir, session: id } }),
|
|
295
|
+
this.#server.requestJson<{ url: string, token: string }>(`${SERVER_ROUTES}tokens`, { body: { document: document.dir, session: id } }),
|
|
296
|
+
])
|
|
238
297
|
const client = await connectPresmiumMcp(grant.url, grant.token)
|
|
239
|
-
const
|
|
298
|
+
const authorClient = await connectPresmiumMcp(authorGrant.url, authorGrant.token)
|
|
299
|
+
const diagnostics = new BindingDiagnostics(authorClient, document.dir)
|
|
240
300
|
const toolChanges = new BindingTools(client, this.#log)
|
|
241
301
|
try {
|
|
242
|
-
const
|
|
302
|
+
const workspaceRoot = (await candidate.ready).root
|
|
303
|
+
const binding: DocumentBinding = { agentSessionId: id, document, dir: resolve(workspaceRoot, document.dir), workspaceRoot, client, authorClient, get tools() { return toolChanges.snapshot }, toolChanges, diagnostics }
|
|
243
304
|
await toolChanges.start()
|
|
244
305
|
await diagnostics.start()
|
|
245
306
|
if (current()) {
|
|
@@ -250,9 +311,10 @@ export class DocumentBindings {
|
|
|
250
311
|
} catch (error) {
|
|
251
312
|
await Promise.all([diagnostics.close(), toolChanges.close()]).catch(() => undefined)
|
|
252
313
|
await client.close().catch(() => undefined)
|
|
314
|
+
await authorClient.close().catch(() => undefined)
|
|
253
315
|
throw error
|
|
254
316
|
}
|
|
255
|
-
await Promise.all([diagnostics.close(), toolChanges.close()]).finally(() => client.close())
|
|
317
|
+
await Promise.all([diagnostics.close(), toolChanges.close()]).finally(() => Promise.all([client.close(), authorClient.close()]))
|
|
256
318
|
return undefined
|
|
257
319
|
}
|
|
258
320
|
|
|
@@ -315,6 +377,8 @@ export class DocumentBindings {
|
|
|
315
377
|
|
|
316
378
|
/** Closes the session's binding and revokes its session token; `forget` drops its selection too. */
|
|
317
379
|
async unbind(agentSessionId: string, forget = true): Promise<void> {
|
|
380
|
+
let ownerId = agentSessionId
|
|
381
|
+
for (let depth = 0; depth < 32 && this.#parents.has(ownerId); depth++) ownerId = this.#parents.get(ownerId)!
|
|
318
382
|
if (forget) {
|
|
319
383
|
this.#selectionVersions.delete(agentSessionId)
|
|
320
384
|
this.#selected.delete(agentSessionId)
|
|
@@ -327,6 +391,19 @@ export class DocumentBindings {
|
|
|
327
391
|
this.#failures.delete(agentSessionId)
|
|
328
392
|
if (binding) await closeBinding(binding).catch(error => this.#log.warn(`presmium-service: closing session ${agentSessionId}: ${errorMessage(error)}`))
|
|
329
393
|
else await request
|
|
394
|
+
if (forget) {
|
|
395
|
+
this.#parents.delete(agentSessionId)
|
|
396
|
+
const owners = this.#candidateOwners.get(ownerId)
|
|
397
|
+
owners?.delete(agentSessionId)
|
|
398
|
+
if (owners?.size === 0) {
|
|
399
|
+
this.#candidateOwners.delete(ownerId)
|
|
400
|
+
this.#candidateRoots.delete(ownerId)
|
|
401
|
+
const candidate = this.#candidates.get(ownerId)
|
|
402
|
+
this.#candidates.delete(ownerId)
|
|
403
|
+
if (candidate) await (await candidate).close()
|
|
404
|
+
await this.#server.requestJson(`${WORKSPACE_ROUTES}review/workspace`, { body: { session: ownerId, close: true } })
|
|
405
|
+
}
|
|
406
|
+
}
|
|
330
407
|
if (!binding && !request) return
|
|
331
408
|
await this.#server.request(`${SERVER_ROUTES}tokens`, { method: 'DELETE', body: { session: agentSessionId } }).then(r => r.body?.cancel(), () => undefined)
|
|
332
409
|
}
|
|
@@ -341,5 +418,10 @@ export class DocumentBindings {
|
|
|
341
418
|
this.#selected.clear()
|
|
342
419
|
this.#selectionVersions.clear()
|
|
343
420
|
this.#selectionListeners.clear()
|
|
421
|
+
await Promise.all([...this.#candidates.values()].map(async candidate => (await candidate).close()))
|
|
422
|
+
this.#candidates.clear()
|
|
423
|
+
this.#candidateRoots.clear()
|
|
424
|
+
this.#candidateOwners.clear()
|
|
425
|
+
this.#parents.clear()
|
|
344
426
|
}
|
|
345
427
|
}
|
package/src/node/context.ts
CHANGED
|
@@ -18,7 +18,7 @@ export const GUIDE = [
|
|
|
18
18
|
'',
|
|
19
19
|
'What you answer for:',
|
|
20
20
|
'- Do what the author asks, and no more. A question is answered, with no change to files. A change is made where it is asked for, and the rest is kept. When a request is unclear, or would change more than it names, ask first.',
|
|
21
|
-
'- Your file
|
|
21
|
+
'- Your file tools and source-changing Presmium tools use a private candidate workspace. The author keeps editing the original while you work. Completed writing tools publish their changes with original-file version checks, or keep them for required review. A conflict means the author changed the source: read the refreshed files and retry your intended change. Never overwrite the author workspace through an old absolute path. Do not commit your files.',
|
|
22
22
|
'',
|
|
23
23
|
'What tells you what:',
|
|
24
24
|
'- A valid document save is acknowledged by its document version independently of snapshot compilation. Read back the canonical JSON to confirm authoring changes and preserve input on conflicts. Diagnostics and presmium__get_section or presmium__get_step describe compiled output; an older snapshot is not confirmation of a newer edit. Preview compilation can fail while the saved document remains valid.',
|
|
@@ -36,7 +36,8 @@ const NOT_SOURCES = new Set(['dist', '.presmium', 'node_modules', '.git'])
|
|
|
36
36
|
const FILES_SHOWN = 60
|
|
37
37
|
|
|
38
38
|
async function callJsonTool(binding: DocumentBinding, tool: string): Promise<any> {
|
|
39
|
-
const
|
|
39
|
+
const client = ['get_position', 'get_focus', 'get_runtime'].includes(tool) ? binding.authorClient : binding.client
|
|
40
|
+
const result = await client.call(tool, {}).catch(() => undefined)
|
|
40
41
|
if (!result || result.isError) return undefined
|
|
41
42
|
try {
|
|
42
43
|
return JSON.parse(result.text)
|
|
@@ -141,7 +142,7 @@ export function apply(ctx: DshContext): void {
|
|
|
141
142
|
document = failure ? `<presmium-document>Presmium document context and diagnostics are unavailable: ${JSON.stringify(failure)}. This does not establish that the document is healthy.</presmium-document>`
|
|
142
143
|
: '<presmium-document>No document selected. Document diagnostics are not observed. Work from the workspace root.</presmium-document>'
|
|
143
144
|
}
|
|
144
|
-
latest.set(id, `Workspace root: ${JSON.stringify((await server.ready).root)}.\n${document}`)
|
|
145
|
+
latest.set(id, `Workspace root: ${JSON.stringify(bindings.candidateRootOf(agent) ?? (await server.ready).root)}.\n${document}`)
|
|
145
146
|
} catch (error) {
|
|
146
147
|
latest.set(id, `<presmium-document>Presmium document context and diagnostics are unavailable: ${JSON.stringify(errorMessage(error))}. This does not establish that the document is healthy.</presmium-document>`)
|
|
147
148
|
}
|
package/src/node/policy.ts
CHANGED
|
@@ -24,6 +24,8 @@ const displayText = (text: string, lang?: string) => ({ en: text, ...lang ? { [l
|
|
|
24
24
|
|
|
25
25
|
export function apply(ctx: DshContext): void {
|
|
26
26
|
const operatorDir = operatorRoot()
|
|
27
|
+
let authorRoot: string | undefined
|
|
28
|
+
void ctx.presmium.server.ready.then(endpoint => { authorRoot = endpoint.root })
|
|
27
29
|
|
|
28
30
|
ctx.on('tools/pre-execute', async (exec: DshToolExecution, next: () => Promise<DshPreDecision>): Promise<DshPreDecision> => {
|
|
29
31
|
const { bindings } = ctx.presmium
|
|
@@ -48,8 +50,11 @@ export function apply(ctx: DshContext): void {
|
|
|
48
50
|
ctx.tools.guard((exec) => {
|
|
49
51
|
const file = FILE_WRITE_TOOLS.has(exec.name) ? fileOf(exec) : undefined
|
|
50
52
|
const dir = exec.agent ? ctx.presmium.bindings.workingDirectoryOf(exec.agent) : process.cwd()
|
|
53
|
+
const candidate = ctx.presmium.bindings.candidateRootOf(exec.agent)
|
|
54
|
+
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.'
|
|
51
55
|
if (file && isInside(resolve(dir, file), operatorDir)) return `Presmium: the operator directory (${operatorDir}) is not the agent's to write`
|
|
52
56
|
const command = exec.name === 'bash' ? (exec.arguments as { command?: unknown } | undefined)?.command : undefined
|
|
57
|
+
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.'
|
|
53
58
|
if (typeof command === 'string' && command.includes(operatorDir)) return `Presmium: the operator directory (${operatorDir}) is not the agent's to touch`
|
|
54
59
|
return undefined
|
|
55
60
|
})
|
package/src/node/routes.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const ROUTES: Record<string, string> = Object.fromEntries([
|
|
|
10
10
|
'document/media-clip/validate', 'document/transcription/capabilities', 'document/transcription', 'document/transcription/result', 'document/transcription/cancel',
|
|
11
11
|
'document/transcription/adoption/plan', 'document/transcription/adoption/apply',
|
|
12
12
|
'ir', 'ir/events', 'preview', 'build', 'check', 'jobs', 'jobs/cancel', 'jobs/events', 'voice-catalog', 'voice-capabilities',
|
|
13
|
-
'review', 'review/open', 'review/step', 'review/accept', 'review/reject', 'review/restore'].map(path => [path, `${WORKSPACE_ROUTES}${path}`]),
|
|
13
|
+
'review', 'review/workspace', 'review/open', 'review/step', 'review/accept', 'review/reject', 'review/restore'].map(path => [path, `${WORKSPACE_ROUTES}${path}`]),
|
|
14
14
|
['focus', `${SERVER_ROUTES}focus`],
|
|
15
15
|
['control', `${SERVER_ROUTES}control`],
|
|
16
16
|
['diagnostics', `${SERVER_ROUTES}diagnostics`],
|
package/src/node/service.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface Config {
|
|
|
15
15
|
url?: string
|
|
16
16
|
token?: string
|
|
17
17
|
root?: string
|
|
18
|
+
candidate?: boolean
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export interface Endpoint {
|
|
@@ -54,6 +55,7 @@ export class WorkspaceServerClient {
|
|
|
54
55
|
presmium: cliBin(),
|
|
55
56
|
dir: root,
|
|
56
57
|
serviceToken,
|
|
58
|
+
env: { ...process.env, ...config.candidate ? { PRESMIUM_AGENT_CANDIDATE: '1' } : {} },
|
|
57
59
|
onOutput: (text) => {
|
|
58
60
|
for (const line of text.split('\n').filter(Boolean)) log.debug(`presmium serve: ${line}`)
|
|
59
61
|
},
|
|
@@ -104,6 +106,7 @@ export class WorkspaceServerClient {
|
|
|
104
106
|
this.#closed = true
|
|
105
107
|
if (this.#launched) {
|
|
106
108
|
this.#launched.child.kill('SIGTERM')
|
|
109
|
+
await this.#launched.exited
|
|
107
110
|
return
|
|
108
111
|
}
|
|
109
112
|
await this.request(`${SERVER_ROUTES}tokens`, { method: 'DELETE', body: {} }).then(r => r.body?.cancel(), () => undefined)
|
package/src/node/tools.ts
CHANGED
|
@@ -7,6 +7,13 @@ export const name = 'presmium-tools'
|
|
|
7
7
|
export const inject = ['presmium', 'tools']
|
|
8
8
|
|
|
9
9
|
export const PREFIX = 'presmium__'
|
|
10
|
+
export const CANDIDATE_TOOLS = new Set([
|
|
11
|
+
'get_authoring_capabilities', 'get_document', 'get_document_outline', 'read_document_part',
|
|
12
|
+
'plan_document_change', 'apply_document_change', 'plan_page_change', 'apply_page_change',
|
|
13
|
+
'plan_page_duplication', 'apply_page_duplication', 'plan_authoring_action', 'apply_authoring_action', 'read_authoring_action_impact',
|
|
14
|
+
'check_document', 'get_section', 'get_step', 'list_sections', 'deck_info', 'list_documents',
|
|
15
|
+
'run_code', 'capture_slides', 'capture_reading', 'capture_overview',
|
|
16
|
+
])
|
|
10
17
|
|
|
11
18
|
const IMAGE_TYPES = new Set<string>(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])
|
|
12
19
|
|
|
@@ -41,7 +48,7 @@ function definition(ctx: DshContext, binding: DocumentBinding, tool: ListedTool)
|
|
|
41
48
|
parameters: tool.inputSchema,
|
|
42
49
|
output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] },
|
|
43
50
|
async execute(args, exec) {
|
|
44
|
-
const result = await binding.client.call(tool.name, (args ?? {}) as Record<string, unknown>, exec.signal)
|
|
51
|
+
const result = await (CANDIDATE_TOOLS.has(tool.name) ? binding.client : binding.authorClient).call(tool.name, (args ?? {}) as Record<string, unknown>, exec.signal)
|
|
45
52
|
if (result.isError) throw new Error(result.text)
|
|
46
53
|
if (result.images.length > 0) prepared.set(exec.token, [...result.text ? [{ type: 'text' as const, text: result.text }] : [], ...await imageBlocks(ctx, tool.name, result.images, exec)])
|
|
47
54
|
return result.text
|
|
@@ -90,6 +97,7 @@ export function apply(ctx: DshContext): void {
|
|
|
90
97
|
for (const dispose of previous?.dispose ?? []) dispose()
|
|
91
98
|
})
|
|
92
99
|
ctx.on('agent/pre-step', async ({ agent }: { agent: DshAgent }, next: () => Promise<unknown>) => {
|
|
100
|
+
await ctx.presmium.bindings.refreshCandidate(agent)
|
|
93
101
|
await sync(agent)
|
|
94
102
|
return next()
|
|
95
103
|
})
|
package/src/node/turns.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { errorMessage } from '@lincyaw/kernel'
|
|
|
3
3
|
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
|
+
import { CANDIDATE_TOOLS, PREFIX } from './tools.ts'
|
|
6
7
|
|
|
7
8
|
// What a writing tool answers when the change cannot be recorded. The AI reads it and tells the author in their own
|
|
8
9
|
// language, so it names what the author sees (Version History) and none of the internals behind it.
|
|
@@ -83,7 +84,8 @@ export function apply(ctx: DshContext): void {
|
|
|
83
84
|
if (path === 'open' && response.status === 404) throw new Error(NOT_RECORDED)
|
|
84
85
|
let reason = text
|
|
85
86
|
try {
|
|
86
|
-
|
|
87
|
+
const failure = JSON.parse(text) as { error?: string, next?: string, paths?: string[] }
|
|
88
|
+
reason = [failure.error, failure.paths?.join(', '), failure.next].filter(Boolean).join(' ') || reason
|
|
87
89
|
} catch {
|
|
88
90
|
}
|
|
89
91
|
throw new Error(reason || `the review answered ${response.status}`)
|
|
@@ -100,9 +102,13 @@ export function apply(ctx: DshContext): void {
|
|
|
100
102
|
})
|
|
101
103
|
|
|
102
104
|
ctx.on('tools/execute', async (exec: DshToolExecution, next: () => Promise<unknown>) => {
|
|
103
|
-
if (!
|
|
105
|
+
if (!exec.agent) return next()
|
|
104
106
|
const { root } = await ctx.presmium.server.ready
|
|
105
107
|
if (!isInside(ctx.presmium.bindings.workingDirectoryOf(exec.agent), root)) return next()
|
|
108
|
+
await ctx.presmium.bindings.candidateOf(exec.agent)
|
|
109
|
+
const binding = ctx.presmium.bindings.bindingOf(exec.agent)
|
|
110
|
+
const tool = exec.name.startsWith(PREFIX) ? binding?.tools.find(tool => `${PREFIX}${tool.name}` === exec.name) : undefined
|
|
111
|
+
if (!WRITING_TOOLS.has(exec.name) && (!tool || tool.kind === 'read' || !CANDIDATE_TOOLS.has(tool.name))) return next()
|
|
106
112
|
const document = ctx.presmium.bindings.bindingOf(exec.agent)?.document.dir ?? ''
|
|
107
113
|
const agentSessionId = rootAgentSessionOf(exec.agent.session.id)
|
|
108
114
|
const state = turnStateOf(agentSessionId)
|
|
@@ -113,12 +119,9 @@ export function apply(ctx: DshContext): void {
|
|
|
113
119
|
}
|
|
114
120
|
state.document = document
|
|
115
121
|
state.wrote = true
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
await postReview(document, agentSessionId, 'step', { ...state.turn !== undefined ? { turn: state.turn } : {}, label: labelOf(exec), tool: exec.name })
|
|
120
|
-
.catch((error: unknown) => log.warn(`presmium-turns: no checkpoint after ${exec.name} in ${agentSessionId}: ${errorMessage(error)}`))
|
|
121
|
-
}
|
|
122
|
+
const result = await next()
|
|
123
|
+
await postReview(document, agentSessionId, 'step', { ...state.turn !== undefined ? { turn: state.turn } : {}, label: labelOf(exec), tool: exec.name })
|
|
124
|
+
return result
|
|
122
125
|
})
|
|
123
126
|
|
|
124
127
|
ctx.on('agent/created', ({ agent }: { agent: LiveAgent }) => {
|