martty 0.2.39-beta.0 → 0.2.39

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/lib/acp-client.js CHANGED
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import spawn from 'cross-spawn'
11
+ import { harnessEnvironment } from './harness-environment.js'
11
12
  import { installAcpClientEvents } from './acp-client-events.js'
12
13
  import { installAcpSessionConfig } from './acp-session-config.js'
13
14
  import { installAcpSessionPlan } from './acp-session-plan.js'
@@ -115,7 +116,7 @@ export function apply(ctx, config = {}) {
115
116
  function spawnAgent(agent) {
116
117
  const child = spawn(agent.command, agent.args ?? [], {
117
118
  stdio: ['pipe', 'pipe', 'pipe'],
118
- env: { ...process.env, ...(agent.env ?? {}) },
119
+ env: harnessEnvironment(agent.env),
119
120
  })
120
121
  child.stdin.on('error', () => {})
121
122
  child.stdout.on('error', () => {})
@@ -252,6 +252,7 @@ export function installAcpSessionStatus(ctx, options = {}) {
252
252
  let facts = connections.get(owner.id)
253
253
  if (!facts) {
254
254
  facts = { connection: 'attached', server: owner.agentInfo?.name,
255
+ runtime: { command: owner.command, args: owner.args ?? [] },
255
256
  auth: { status: owner.authMethods?.length ? 'configured' : undefined, method: undefined } }
256
257
  connections.set(owner.id, facts)
257
258
  }
package/lib/boot.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { apply as applyHarnessBadge, inject as harnessBadgeInject } from './harness-badge.js'
1
2
  /**
2
3
  * Boot-time restore of a statically-registered gallery palette (ayu,
3
4
  * iceberg, …). `/theme` persistence writes `settings.theme`; dynamic
@@ -142,6 +143,7 @@ export async function bootClient(options = {}) {
142
143
  await ctx.plugin({ name: 'stats-view', inject: statsViewInject, apply: applyStatsView })
143
144
  await ctx.plugin({ name: 'acp-session-status', inject: sessionStatusInject, apply: applySessionStatus })
144
145
  await ctx.plugin({ name: 'status-view', inject: statusViewInject, apply: applyStatusView })
146
+ await ctx.plugin({ name: 'harness-badge', inject: harnessBadgeInject, apply: applyHarnessBadge }, harnessConfig)
145
147
  await ctx.plugin({ name: 'harness-view', inject: harnessViewInject, apply: applyHarnessView }, harnessConfig)
146
148
  await ctx.plugin({ name: 'deepseek-logo', inject: deepseekLogoInject, apply: applyDeepseekLogo })
147
149
  const localPlugins = installTuiLocalPlugins(ctx, {
@@ -203,6 +205,7 @@ export async function bootClient(options = {}) {
203
205
  applyStatsView(ctx)
204
206
  applySessionStatus(ctx)
205
207
  applyStatusView(ctx)
208
+ applyHarnessBadge(ctx, harnessConfig)
206
209
  applyHarnessView(ctx, harnessConfig)
207
210
  applyDeepseekLogo(ctx)
208
211
  const localPlugins = installTuiLocalPlugins(ctx, {
@@ -0,0 +1,137 @@
1
+ /** Registry-owned Harness marks. Only the Rust painter touches the terminal. */
2
+ import { createHash, randomUUID } from 'node:crypto'
3
+ import { promises as fs } from 'node:fs'
4
+ import path from 'node:path'
5
+ import { createRequire } from 'node:module'
6
+ import { readAcpRegistrySnapshot } from './harness-registry.js'
7
+ import { discoverHarnesses } from './harnesses.js'
8
+
9
+ export const name = 'harness-badge'
10
+ export const inject = ['acpSessionStatus', 'tuiSlots']
11
+ // ACP Registry does not list DeepSeek yet. Use Lobe's MIT-licensed mark,
12
+ // supplied by the installed SVG library. Registry always takes priority.
13
+ const deepseekBadge = {
14
+ label: 'DeepSeek',
15
+ icon: 'lobe:deepseek',
16
+ }
17
+ const require = createRequire(import.meta.url)
18
+ const MAX_BYTES = 512 * 1024
19
+ const png = bytes => bytes.length <= MAX_BYTES && bytes.subarray(0, 8).equals(Buffer.from([137,80,78,71,13,10,26,10]))
20
+
21
+ export function createIconCache(options = {}) {
22
+ const pending = new Map()
23
+ return function load(url) {
24
+ if (typeof url !== 'string' || (url !== 'lobe:deepseek' && !url.startsWith('https://'))) return Promise.resolve(undefined)
25
+ if (pending.has(url)) return pending.get(url)
26
+ const promise = (async () => {
27
+ const local = url === 'lobe:deepseek'
28
+ const version = local ? require('@lobehub/icons-static-svg/package.json').version : ''
29
+ const key = createHash('sha256').update(local ? `${url}@${version}` : url).digest('hex')
30
+ const file = options.settingsPath && path.join(path.dirname(options.settingsPath), 'cache', 'harness-icons', `${key}.png`)
31
+ if (file) {
32
+ try {
33
+ if ((await fs.stat(file)).size <= MAX_BYTES) {
34
+ const cached = await fs.readFile(file)
35
+ if (png(cached)) return cached.toString('base64')
36
+ }
37
+ } catch { /* Missing cache: fetch below. */ }
38
+ }
39
+ let source
40
+ if (local) {
41
+ source = await fs.readFile(require.resolve('@lobehub/icons-static-svg/icons/deepseek.svg'))
42
+ if (source.length > MAX_BYTES) throw new Error('Icon too large')
43
+ } else {
44
+ const response = await (options.fetchImpl ?? fetch)(url, { signal: AbortSignal.timeout(5000) })
45
+ if (!response.ok) throw new Error('Icon unavailable')
46
+ if (Number(response.headers.get('content-length')) > MAX_BYTES) throw new Error('Icon too large')
47
+ const chunks = []
48
+ let size = 0
49
+ for await (const chunk of response.body) {
50
+ size += chunk.length
51
+ if (size > MAX_BYTES) throw new Error('Icon too large')
52
+ chunks.push(chunk)
53
+ }
54
+ source = Buffer.concat(chunks)
55
+ }
56
+ // Lazy import: an unavailable optional native renderer still leaves the name usable.
57
+ const { Resvg } = await import('@resvg/resvg-js')
58
+ let bytes
59
+ if (png(source)) {
60
+ bytes = source
61
+ } else {
62
+ const renderer = new Resvg(source.toString('utf8').replaceAll('currentColor', '#a0a0a0'), {
63
+ fitTo: { mode: 'width', value: 64 }, font: { loadSystemFonts: false },
64
+ })
65
+ if (renderer.width <= 0 || renderer.height <= 0 || renderer.height / renderer.width > 4) throw new Error('Invalid icon dimensions')
66
+ bytes = renderer.render().asPng()
67
+ }
68
+ if (!png(bytes)) throw new Error('Invalid icon')
69
+ if (file) {
70
+ const temporary = `${file}.${randomUUID()}.tmp`
71
+ try {
72
+ await fs.mkdir(path.dirname(file), { recursive: true })
73
+ await fs.writeFile(temporary, bytes)
74
+ await fs.rename(temporary, file)
75
+ } catch { /* A read-only cache must not hide a downloaded icon. */ }
76
+ finally { await fs.rm(temporary, { force: true }).catch(() => {}) }
77
+ }
78
+ return bytes.toString('base64')
79
+ })().catch(() => undefined)
80
+ pending.set(url, promise)
81
+ return promise
82
+ }
83
+ }
84
+
85
+ function packageName(spec) {
86
+ if (typeof spec !== 'string') return undefined
87
+ return /^(?:(@[^/\s]+\/[^@/\s]+)|([^@/\s:]+))(?:@[^\s]+)?$/.exec(spec)?.slice(1).find(Boolean)
88
+ }
89
+
90
+ function runtimePackage(runtime) {
91
+ if (!runtime || !/(?:^|[/\\])npx(?:\.cmd|\.exe)?$/i.test(runtime.command ?? '')) return undefined
92
+ const args = runtime.args ?? []
93
+ const explicit = args.findIndex(arg => arg === '--package' || arg === '-p')
94
+ return packageName(explicit >= 0 ? args[explicit + 1] : args.find(arg => !arg.startsWith('-')))
95
+ }
96
+
97
+ export function apply(ctx, options = {}) {
98
+ const loadIcon = options.loadIcon ?? createIconCache(options)
99
+ let panel, disposed = false, generation = 0, lastKey
100
+ let nodes = []
101
+ const stopSlot = ctx.tuiSlots.inject('conversation.harness', () => {
102
+ panel = ctx.tuiSlots.register({ name: 'conversation.harness', id: 'harness' }, nodes)
103
+ return () => panel.dispose()
104
+ })
105
+ function update(status) {
106
+ const session = status.session?.bound ? status.session.sessionId : undefined
107
+ const key = JSON.stringify([session, status.server, status.runtime])
108
+ if (key === lastKey) return
109
+ lastKey = key
110
+ const token = ++generation
111
+ if (!session) { nodes = []; panel?.update(nodes); return }
112
+ const registry = options.registry ?? readAcpRegistrySnapshot(options)
113
+ const runtime = status.runtime
114
+ const entries = options.entries ?? discoverHarnesses(options.settingsPath, { ...options, registry, pathValue: '' })
115
+ const entry = runtime && entries.find(candidate => candidate.command === runtime.command
116
+ && JSON.stringify(candidate.args ?? []) === JSON.stringify(runtime.args ?? []))
117
+ const npmPackage = runtimePackage(runtime) ?? packageName(status.server)
118
+ const record = registry.find(candidate => candidate.id === entry?.id)
119
+ ?? registry.find(candidate => candidate.id === status.server || candidate.label === status.server)
120
+ ?? (npmPackage && registry.find(candidate => candidate.distributions?.some(distribution =>
121
+ distribution.type === 'npx' && packageName(distribution.args?.[0]) === npmPackage)))
122
+ ?? (['dsh-acp', '@deepseek-ai/dsh-acp', '@openma/deepseek-harness-acp'].includes(status.server)
123
+ || ['@deepseek-ai/dsh-acp', '@openma/deepseek-harness-acp'].includes(npmPackage)
124
+ ? deepseekBadge : undefined)
125
+ const label = (record?.label ?? entry?.label ?? status.server ?? runtime?.command)?.replace(/\s+harness$/i, '')
126
+ nodes = label ? [{ id: session, kind: 'image', name: label, mime: 'image/png' }] : []
127
+ panel?.update(nodes)
128
+ if (record?.icon && nodes.length) void loadIcon(record.icon).then(dataBase64 => {
129
+ if (disposed || token !== generation || !dataBase64) return
130
+ nodes = [{ ...nodes[0], dataBase64 }]
131
+ panel?.update(nodes)
132
+ })
133
+ }
134
+ update(ctx.acpSessionStatus.current())
135
+ const stopStatus = ctx.acpSessionStatus.subscribe(update)
136
+ return () => { disposed = true; ++generation; stopStatus?.(); stopSlot?.() }
137
+ }
@@ -0,0 +1,9 @@
1
+ /** npm exec exports its invocation selectors to children. They belong to Martty's
2
+ * launcher, not a nested Harness runner (npx otherwise treats a package as a bin).
3
+ * Keep registry/proxy/cache/auth settings and explicit Harness overrides intact.
4
+ */
5
+ export function harnessEnvironment(overrides = {}, inherited = process.env) {
6
+ const env = Object.fromEntries(Object.entries(inherited).filter(([key]) =>
7
+ !/^npm_config_(package|call|workspace|workspaces|include_workspace_root)$/i.test(key)))
8
+ return { ...env, ...overrides }
9
+ }
@@ -1,3 +1,4 @@
1
+ import { harnessEnvironment } from './harness-environment.js'
1
2
  import { StringDecoder } from 'node:string_decoder'
2
3
  import spawn from 'cross-spawn'
3
4
 
@@ -155,7 +156,7 @@ export async function prepareHarnessPackage(entry, options = {}) {
155
156
  try {
156
157
  child = (options.spawnImpl ?? spawn)(runner, args, {
157
158
  cwd: options.cwd,
158
- env: { ...process.env, ...distribution.env, ...entry.env, ...options.env },
159
+ env: harnessEnvironment({ ...distribution.env, ...entry.env, ...options.env }),
159
160
  stdio: ['ignore', 'pipe', 'pipe'],
160
161
  windowsHide: true,
161
162
  detached: process.platform !== 'win32',
@@ -128,6 +128,7 @@ export function normalizeAcpRegistry(value, options = {}) {
128
128
  return [{
129
129
  id: agent.id,
130
130
  label: agent.name,
131
+ ...(typeof agent.icon === 'string' ? { icon: agent.icon } : {}),
131
132
  version: agent.version,
132
133
  description: typeof agent.description === 'string' ? agent.description : '',
133
134
  distributions,
@@ -238,7 +238,8 @@ export function apply(ctx, options = {}) {
238
238
  notifyDownloads()
239
239
  }
240
240
  const newSession = () => ({ action: 'new-session' })
241
- if (openNow && !options.hostOwned) return newSession()
241
+ const emptySession = ctx.acpSessionStatus?.current()?.session?.started === false
242
+ if (!options.hostOwned && (openNow || emptySession)) return newSession()
242
243
  openView({ id: 'harness-saved', title: 'Default Harness saved', nodes: [{
243
244
  id: 'notice', kind: 'notice', level: 'info',
244
245
  text: options.hostOwned
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 LobeHub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/tui-slots.js CHANGED
@@ -16,9 +16,11 @@ export const SLOT_NAMES = Object.freeze([
16
16
  'conversation.input.dock',
17
17
  'conversation.navigation.dock',
18
18
  'conversation.composer.dock',
19
+ 'conversation.harness',
19
20
  ])
20
21
 
21
22
  const SLOT_DEFINITIONS = Object.freeze({
23
+ 'conversation.harness': Object.freeze({ kind: 'single', scope: 'session' }),
22
24
  'welcome.hero': Object.freeze({ kind: 'single', scope: 'root' }),
23
25
  'welcome.info': Object.freeze({ kind: 'single', scope: 'root' }),
24
26
  'chrome.right': Object.freeze({ kind: 'list', scope: 'root' }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "martty",
3
- "version": "0.2.39-beta.0",
3
+ "version": "0.2.39",
4
4
  "description": "Terminal-native ACP client UI; Cordis client tree, any ACP agent",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "test:harness-ui": "node --test ../scripts/harness-management-tui.test.mjs ../scripts/harness-session-tui.test.mjs",
18
18
  "pretest": "node --test ../scripts/workflow-release.test.mjs ../scripts/package-alias.test.mjs ../scripts/harness-removal.test.mjs",
19
- "test": "node --test ../scripts/download.test.mjs ../scripts/package-native.test.mjs ../scripts/check-release-tag.test.mjs ../scripts/check-static-elf.test.mjs ../scripts/smoke-old-linux.test.mjs ../scripts/cargo-guard.test.mjs ../scripts/build-npm.test.mjs ../scripts/client-profile.test.mjs ../scripts/plugin-runner.test.mjs ../scripts/profile-link-resolution.test.mjs ../scripts/packaged-acp-permission.test.mjs ../scripts/profile-smoke-tui.test.mjs ../scripts/release.test.mjs ../scripts/jsonrpc-line-transport.test.mjs ../scripts/tui-theme.test.mjs ../scripts/tui-presets.test.mjs ../scripts/tui-plugin-store.test.mjs ../scripts/tui-local-plugins.test.mjs ../scripts/tui-client-plugin-registry.test.mjs ../scripts/tui-slots.test.mjs ../scripts/tui-commands.test.mjs ../scripts/tui-overlay.test.mjs ../scripts/tui-agents.test.mjs ../scripts/tui-queue.test.mjs ../scripts/mux.test.mjs ../scripts/acp-client.test.mjs ../scripts/acp-agent-pool.test.mjs ../scripts/harnesses.test.mjs ../scripts/harness-discovery.test.mjs ../scripts/harness-discovery-scenario.test.mjs ../scripts/harness-view.test.mjs ../scripts/harness-onboarding.test.mjs ../scripts/harness-registry.test.mjs ../scripts/harness-package.test.mjs ../scripts/acp-client-events.test.mjs ../scripts/acp-session-config.test.mjs ../scripts/acp-session-plan.test.mjs ../scripts/acp-session-stats.test.mjs ../scripts/acp-session-status.test.mjs ../scripts/agents-view.test.mjs ../scripts/plan-view.test.mjs ../scripts/queue-view.test.mjs ../scripts/stats-view.test.mjs ../scripts/status-view.test.mjs ../scripts/deepseek-logo.test.mjs ../scripts/runner.test.mjs ../scripts/inspect.test.mjs ../scripts/creator-overlay.test.mjs ../scripts/real-agent-e2e.test.mjs",
19
+ "test": "node --test ../scripts/download.test.mjs ../scripts/package-native.test.mjs ../scripts/check-release-tag.test.mjs ../scripts/check-static-elf.test.mjs ../scripts/smoke-old-linux.test.mjs ../scripts/cargo-guard.test.mjs ../scripts/build-npm.test.mjs ../scripts/client-profile.test.mjs ../scripts/plugin-runner.test.mjs ../scripts/profile-link-resolution.test.mjs ../scripts/packaged-acp-permission.test.mjs ../scripts/profile-smoke-tui.test.mjs ../scripts/release.test.mjs ../scripts/jsonrpc-line-transport.test.mjs ../scripts/tui-theme.test.mjs ../scripts/tui-presets.test.mjs ../scripts/tui-plugin-store.test.mjs ../scripts/tui-local-plugins.test.mjs ../scripts/tui-client-plugin-registry.test.mjs ../scripts/tui-slots.test.mjs ../scripts/tui-commands.test.mjs ../scripts/tui-overlay.test.mjs ../scripts/tui-agents.test.mjs ../scripts/tui-queue.test.mjs ../scripts/mux.test.mjs ../scripts/acp-client.test.mjs ../scripts/acp-agent-pool.test.mjs ../scripts/harnesses.test.mjs ../scripts/harness-discovery.test.mjs ../scripts/harness-discovery-scenario.test.mjs ../scripts/harness-view.test.mjs ../scripts/harness-onboarding.test.mjs ../scripts/harness-registry.test.mjs ../scripts/harness-badge.test.mjs ../scripts/harness-package.test.mjs ../scripts/acp-client-events.test.mjs ../scripts/acp-session-config.test.mjs ../scripts/acp-session-plan.test.mjs ../scripts/acp-session-stats.test.mjs ../scripts/acp-session-status.test.mjs ../scripts/agents-view.test.mjs ../scripts/plan-view.test.mjs ../scripts/queue-view.test.mjs ../scripts/stats-view.test.mjs ../scripts/status-view.test.mjs ../scripts/deepseek-logo.test.mjs ../scripts/runner.test.mjs ../scripts/inspect.test.mjs ../scripts/creator-overlay.test.mjs ../scripts/real-agent-e2e.test.mjs",
20
20
  "test:profile-install-matrix": "node --test ../scripts/profile-install-matrix.test.mjs"
21
21
  },
22
22
  "publishConfig": {
@@ -76,7 +76,9 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "@deepseek-ai/cordis": "^4.0.1",
79
+ "@lobehub/icons-static-svg": "1.95.0",
79
80
  "@openma/deepseek-harness-acp": "0.4.31",
81
+ "@resvg/resvg-js": "2.6.2",
80
82
  "cross-spawn": "^7.0.6",
81
83
  "node-downloader-helper": "2.1.11"
82
84
  },
Binary file
Binary file
Binary file
Binary file
Binary file