dsh-aiterm 0.5.0 → 0.5.12
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/CONTRACTS.md +104 -22
- package/README.md +208 -26
- package/client/HistoryPanel.jsx +342 -29
- package/client/api.js +44 -3
- package/client/locale.js +40 -2
- package/cordis.patch.yml +1 -0
- package/lib/client.js +30 -30
- package/lib/host/autolog.js +107 -4
- package/lib/host/config.js +14 -0
- package/lib/host/disclosure.js +357 -0
- package/lib/host/exporter.js +447 -159
- package/lib/host/history-store.js +1735 -295
- package/lib/host/permission.js +13 -0
- package/lib/host/prompt.js +24 -4
- package/lib/host/registry.js +858 -76
- package/lib/host/routes.js +45 -2
- package/lib/host/tools.js +280 -22
- package/lib/host/transports/ssh.js +1 -1
- package/lib/index.js +2 -2
- package/package.json +8 -6
- package/scripts/build-vendor.mjs +37 -0
- package/scripts/smoke-client.mjs +193 -6
- package/vendor/README.md +31 -0
- package/vendor/ssh2.LICENSE +19 -0
- package/vendor/ssh2.cjs +20124 -0
package/lib/host/routes.js
CHANGED
|
@@ -242,6 +242,7 @@ async function invoke(plugin, name, params) {
|
|
|
242
242
|
case 'audit.list':
|
|
243
243
|
return {
|
|
244
244
|
entries: registry.audit({
|
|
245
|
+
actor: 'human',
|
|
245
246
|
sessionId: typeof params.id === 'string' ? params.id : undefined,
|
|
246
247
|
limit: params.limit,
|
|
247
248
|
}),
|
|
@@ -260,12 +261,22 @@ async function invoke(plugin, name, params) {
|
|
|
260
261
|
changedOnly: params.changedOnly === true,
|
|
261
262
|
maxLines: params.maxLines,
|
|
262
263
|
})
|
|
263
|
-
case 'history.sessions':
|
|
264
|
-
|
|
264
|
+
case 'history.sessions': {
|
|
265
|
+
const page = await registry.historySessionsPage({
|
|
266
|
+
actor: 'human',
|
|
267
|
+
limit: params.limit,
|
|
268
|
+
offset: params.offset,
|
|
269
|
+
snapshot: params.snapshot,
|
|
270
|
+
since: params.since,
|
|
271
|
+
until: params.until,
|
|
272
|
+
})
|
|
273
|
+
return page
|
|
274
|
+
}
|
|
265
275
|
case 'history.query':
|
|
266
276
|
return registry.historyQuery({
|
|
267
277
|
actor: 'human',
|
|
268
278
|
sessionId: typeof params.sessionId === 'string' ? params.sessionId : undefined,
|
|
279
|
+
historyId: typeof params.historyId === 'string' ? params.historyId : undefined,
|
|
269
280
|
since: params.since,
|
|
270
281
|
until: params.until,
|
|
271
282
|
search: params.search,
|
|
@@ -274,9 +285,40 @@ async function invoke(plugin, name, params) {
|
|
|
274
285
|
maxBytes: params.maxBytes,
|
|
275
286
|
limit: params.limit,
|
|
276
287
|
})
|
|
288
|
+
case 'history.legacy.sessions': {
|
|
289
|
+
const page = await registry.legacyHistorySessionsPage({
|
|
290
|
+
actor: 'human',
|
|
291
|
+
limit: params.limit,
|
|
292
|
+
offset: params.offset,
|
|
293
|
+
snapshot: params.snapshot,
|
|
294
|
+
since: params.since,
|
|
295
|
+
until: params.until,
|
|
296
|
+
})
|
|
297
|
+
return page
|
|
298
|
+
}
|
|
299
|
+
case 'history.legacy.query':
|
|
300
|
+
return registry.legacyHistoryQuery({
|
|
301
|
+
actor: 'human',
|
|
302
|
+
sessionId: typeof params.sessionId === 'string' ? params.sessionId : undefined,
|
|
303
|
+
since: params.since,
|
|
304
|
+
until: params.until,
|
|
305
|
+
search: params.search,
|
|
306
|
+
context: params.context,
|
|
307
|
+
maxMatches: params.maxMatches,
|
|
308
|
+
maxBytes: params.maxBytes,
|
|
309
|
+
})
|
|
310
|
+
case 'history.legacy.export':
|
|
311
|
+
return registry.legacyHistoryExport({
|
|
312
|
+
actor: 'human',
|
|
313
|
+
sessionId: typeof params.sessionId === 'string' ? params.sessionId : undefined,
|
|
314
|
+
since: params.since,
|
|
315
|
+
until: params.until,
|
|
316
|
+
})
|
|
277
317
|
case 'history.export':
|
|
278
318
|
return registry.exportHistory({
|
|
319
|
+
actor: 'human',
|
|
279
320
|
sessionId: typeof params.sessionId === 'string' ? params.sessionId : undefined,
|
|
321
|
+
historyId: typeof params.historyId === 'string' ? params.historyId : undefined,
|
|
280
322
|
all: params.all === true,
|
|
281
323
|
since: params.since,
|
|
282
324
|
until: params.until,
|
|
@@ -287,6 +329,7 @@ async function invoke(plugin, name, params) {
|
|
|
287
329
|
return autoLog(registry).set({
|
|
288
330
|
enabled: typeof params.enabled === 'boolean' ? params.enabled : undefined,
|
|
289
331
|
dir: params.dir,
|
|
332
|
+
confirmLegacy: params.confirmLegacy === true,
|
|
290
333
|
})
|
|
291
334
|
case 'scripts.list':
|
|
292
335
|
return { scripts: await requireScripts(plugin).list() }
|
package/lib/host/tools.js
CHANGED
|
@@ -15,6 +15,7 @@ import { AsyncLocalStorage } from 'node:async_hooks'
|
|
|
15
15
|
|
|
16
16
|
import { coded, jsonSafe } from './util.js'
|
|
17
17
|
import { normalizeSteps, runBatch } from './batch.js'
|
|
18
|
+
import { createDisclosure, DISCLOSURE_GROUPS } from './disclosure.js'
|
|
18
19
|
import { normalizeOwner, ownerScopedRegistry } from './registry.js'
|
|
19
20
|
import { runScript } from './script-lang.js'
|
|
20
21
|
|
|
@@ -150,6 +151,87 @@ const AUDIT_ENTRY_SCHEMA = {
|
|
|
150
151
|
required: ['at', 'sessionId', 'source', 'action', 'detail'],
|
|
151
152
|
}
|
|
152
153
|
|
|
154
|
+
/** Name of the always-resident progressive-mode discovery entry. */
|
|
155
|
+
export const DISCOVER_TOOL_NAME = 'aiterm_discover'
|
|
156
|
+
|
|
157
|
+
/** Group names accepted by the discovery entry. */
|
|
158
|
+
const DISCLOSURE_GROUP_NAMES = Object.freeze(Object.keys(DISCLOSURE_GROUPS))
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Wire shape of a discovery/expansion result.
|
|
162
|
+
*
|
|
163
|
+
* It accepts both the success payload and every fail-closed refusal produced by
|
|
164
|
+
* the Task 1 controller; `additionalProperties: false` keeps hostile or
|
|
165
|
+
* accidental extras from ever reaching the model.
|
|
166
|
+
*/
|
|
167
|
+
const DISCOVERY_OUTPUT_SCHEMA = {
|
|
168
|
+
type: 'object',
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
properties: {
|
|
171
|
+
ok: { type: 'boolean' },
|
|
172
|
+
mode: { type: 'string', enum: ['full', 'progressive'] },
|
|
173
|
+
groups: {
|
|
174
|
+
type: 'array',
|
|
175
|
+
items: {
|
|
176
|
+
type: 'object',
|
|
177
|
+
additionalProperties: false,
|
|
178
|
+
properties: {
|
|
179
|
+
group: { type: 'string' },
|
|
180
|
+
tools: { type: 'array', items: { type: 'string' } },
|
|
181
|
+
},
|
|
182
|
+
required: ['group', 'tools'],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
expanded: { type: 'array', items: { type: 'string' } },
|
|
186
|
+
visible: { type: 'array', items: { type: 'string' } },
|
|
187
|
+
dependencies: {
|
|
188
|
+
type: 'array',
|
|
189
|
+
items: {
|
|
190
|
+
type: 'object',
|
|
191
|
+
additionalProperties: false,
|
|
192
|
+
properties: {
|
|
193
|
+
group: { type: 'string' },
|
|
194
|
+
requires: { type: 'array', items: { type: 'string' } },
|
|
195
|
+
hint: { type: 'string' },
|
|
196
|
+
},
|
|
197
|
+
required: ['group', 'requires', 'hint'],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
hints: { type: 'array', items: { type: 'string' } },
|
|
201
|
+
nextStep: { type: 'string' },
|
|
202
|
+
error: { type: 'string' },
|
|
203
|
+
group: { type: 'string' },
|
|
204
|
+
},
|
|
205
|
+
required: ['ok', 'mode', 'groups', 'expanded', 'visible', 'dependencies', 'hints', 'nextStep'],
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Render a discovery or expansion result as compact text.
|
|
210
|
+
* @param {Record<string, any>} value JSON-safe result from the controller.
|
|
211
|
+
* @returns {string} model-facing text.
|
|
212
|
+
*/
|
|
213
|
+
function renderDiscovery(value) {
|
|
214
|
+
const lines = []
|
|
215
|
+
if (value.ok === false) {
|
|
216
|
+
lines.push(`Tool discovery refused (${String(value.error)}).`)
|
|
217
|
+
} else {
|
|
218
|
+
lines.push(`Tool disclosure mode: ${String(value.mode)}.`)
|
|
219
|
+
for (const { group, tools: members } of value.groups) {
|
|
220
|
+
const state = value.expanded.includes(group) ? ' [expanded]' : ''
|
|
221
|
+
lines.push(`${group}${state}${members.length === 0 ? ' — no tools are available to this Agent' : ''}`)
|
|
222
|
+
for (const name of members) lines.push(` ${name}`)
|
|
223
|
+
}
|
|
224
|
+
if (typeof value.group === 'string') {
|
|
225
|
+
lines.push('', value.mode === 'progressive'
|
|
226
|
+
? `Expanded "${value.group}"; its tools become callable on the next model step.`
|
|
227
|
+
: `Full mode already exposes every tool; "${value.group}" needs no expansion.`)
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (typeof value.nextStep === 'string' && value.nextStep.length > 0) lines.push('', value.nextStep)
|
|
231
|
+
for (const hint of value.hints ?? []) lines.push(`- ${hint}`)
|
|
232
|
+
return lines.join('\n')
|
|
233
|
+
}
|
|
234
|
+
|
|
153
235
|
/**
|
|
154
236
|
* One text content block.
|
|
155
237
|
* @param {string} text content.
|
|
@@ -245,12 +327,38 @@ function sleep(ms) {
|
|
|
245
327
|
* @returns {void}
|
|
246
328
|
*/
|
|
247
329
|
export function registerTools(ctx, plugin) {
|
|
330
|
+
// `resolveConfig` guarantees only the exact `progressive` value enables the
|
|
331
|
+
// new behaviour; everything else (including a direct caller's `{}`) keeps the
|
|
332
|
+
// historical unconditional registration untouched, including its lifecycle.
|
|
333
|
+
const progressive = plugin?.config?.toolDisclosure === 'progressive'
|
|
334
|
+
const disclosure = progressive ? createDisclosure({ mode: 'progressive', tools: ctx.tools }) : undefined
|
|
335
|
+
|
|
336
|
+
if (disclosure !== undefined) {
|
|
337
|
+
// Agent disposal is the only reliable end-of-life signal for the per-Agent
|
|
338
|
+
// expansion state. `ctx.on` is owned by this plugin's fiber, so unloading
|
|
339
|
+
// the plugin also removes the listener; the effect below additionally
|
|
340
|
+
// clears the controller so late conditions fail closed during teardown.
|
|
341
|
+
if (typeof ctx.on === 'function') {
|
|
342
|
+
ctx.on('agent/disposed', ({ agent }) => {
|
|
343
|
+
disclosure.forget(agent)
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
ctx.effect(() => () => disclosure.dispose(), 'aiterm: tool disclosure')
|
|
347
|
+
}
|
|
348
|
+
|
|
248
349
|
/**
|
|
249
|
-
* Register one tool.
|
|
350
|
+
* Register one original business tool.
|
|
250
351
|
*
|
|
251
352
|
* Tool results are validated as lossless JSON before they reach the model, so
|
|
252
353
|
* every payload is normalized (absent optional fields dropped, non-finite
|
|
253
354
|
* numbers nulled) on the way out.
|
|
355
|
+
*
|
|
356
|
+
* In progressive mode only, the original registration gains a step-time
|
|
357
|
+
* condition reading the invoking Agent from the `ToolActivationContext`. The
|
|
358
|
+
* condition is side-effect free, synchronous, and catches every failure
|
|
359
|
+
* (including a hostile `agent.id` getter) so a bad caller cannot fail step
|
|
360
|
+
* preparation or widen visibility. No scoped tool is registered, so existing
|
|
361
|
+
* restrictions and scope-local definitions keep their exact behaviour.
|
|
254
362
|
* @param {Record<string, any>} definition tool definition.
|
|
255
363
|
*/
|
|
256
364
|
const register = (definition) => {
|
|
@@ -265,6 +373,17 @@ export function registerTools(ctx, plugin) {
|
|
|
265
373
|
return safe === undefined ? null : safe
|
|
266
374
|
},
|
|
267
375
|
}
|
|
376
|
+
if (progressive) {
|
|
377
|
+
const when = (context) => {
|
|
378
|
+
try {
|
|
379
|
+
return disclosure.isVisible(context?.agent, definition.name)
|
|
380
|
+
} catch {
|
|
381
|
+
return false
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
ctx.effect(() => ctx.tools.register(guarded, { when }), `aiterm: tool ${definition.name}`)
|
|
385
|
+
return
|
|
386
|
+
}
|
|
268
387
|
ctx.effect(() => ctx.tools.register(guarded), `aiterm: tool ${definition.name}`)
|
|
269
388
|
}
|
|
270
389
|
|
|
@@ -296,17 +415,17 @@ export function registerTools(ctx, plugin) {
|
|
|
296
415
|
register({
|
|
297
416
|
name: 'aiterm_connect',
|
|
298
417
|
description:
|
|
299
|
-
'Open a new SSH or Telnet session in the visible SSH/Telnet panel. Prefer connecting through a saved profile (profileId) — saved passwords and private keys are read by the Host and never exposed to you. Ad-hoc connections may only use agent/none authentication; do not ask the user for a password. The session starts with the deployment default AI permission and the user can change it at any time.',
|
|
418
|
+
'Open a new SSH or Telnet session in the visible SSH/Telnet panel. Prefer connecting through a saved profile (profileId) — saved passwords and private keys are read by the Host and never exposed to you. With profileId, pass ONLY profileId (plus title/cols/rows): transport/host/port/username/authType overrides are rejected so saved credentials cannot be redirected. Ad-hoc connections may only use agent/none authentication; do not ask the user for a password. The session starts with the deployment default AI permission and the user can change it at any time.',
|
|
300
419
|
parameters: {
|
|
301
420
|
type: 'object',
|
|
302
421
|
additionalProperties: false,
|
|
303
422
|
properties: {
|
|
304
423
|
profileId: { type: 'string', description: 'Saved profile id from the panel (recommended).' },
|
|
305
|
-
transport: { type: 'string', enum: ['ssh', 'telnet'], description: 'Ad-hoc connection transport
|
|
306
|
-
host: { type: 'string', description: 'Ad-hoc host name or IP
|
|
307
|
-
port: { type: 'integer', description: 'Ad-hoc port (default 22 for SSH, 23 for Telnet).' },
|
|
308
|
-
username: { type: 'string', description: 'Ad-hoc SSH username.' },
|
|
309
|
-
authType: { type: 'string', enum: ['agent', 'none'], description: 'Ad-hoc SSH auth;
|
|
424
|
+
transport: { type: 'string', enum: ['ssh', 'telnet'], description: 'Ad-hoc connection transport; cannot be combined with profileId (AI calls are rejected).' },
|
|
425
|
+
host: { type: 'string', description: 'Ad-hoc host name or IP; cannot be combined with profileId (AI calls are rejected).' },
|
|
426
|
+
port: { type: 'integer', description: 'Ad-hoc port (default 22 for SSH, 23 for Telnet); cannot be combined with profileId.' },
|
|
427
|
+
username: { type: 'string', description: 'Ad-hoc SSH username; cannot be combined with profileId.' },
|
|
428
|
+
authType: { type: 'string', enum: ['agent', 'none'], description: 'Ad-hoc SSH auth; cannot be combined with profileId. Password/key connections must use a saved profile.' },
|
|
310
429
|
title: { type: 'string', description: 'Optional display title.' },
|
|
311
430
|
cols: { type: 'integer', description: 'Terminal columns (default 100).' },
|
|
312
431
|
rows: { type: 'integer', description: 'Terminal rows (default 30).' },
|
|
@@ -591,12 +710,16 @@ export function registerTools(ctx, plugin) {
|
|
|
591
710
|
register({
|
|
592
711
|
name: 'aiterm_history',
|
|
593
712
|
description:
|
|
594
|
-
'Search or read a session\'s output history with timestamps, including sessions that already closed (history is kept on disk for the configured retention window). Omit sessionId to list recent sessions (live and past) with sizes and time ranges. With sessionId: pass search (regex or text) to get matching lines with timestamps and context, or since/until alone to read that time window. Time values accept epoch milliseconds, ISO timestamps, or relative amounts like "10m", "2h", "90s". Cheapest way to answer "what happened at 16:02" without re-reading screens.',
|
|
713
|
+
'Search or read a session\'s output history with timestamps, including sessions that already closed (history is kept on disk for the configured retention window). Omit sessionId to list recent sessions (live and past) with sizes and time ranges; page with limit/offset and pass the returned snapshot back. If history changed between pages (including a live close), stale:true is returned instead of silently skipping rows. With sessionId: pass search (regex or text) to get matching lines with timestamps and context, or since/until alone to read that time window. Time values accept epoch milliseconds, ISO timestamps, or relative amounts like "10m", "2h", "90s". Cheapest way to answer "what happened at 16:02" without re-reading screens.',
|
|
595
714
|
parameters: {
|
|
596
715
|
type: 'object',
|
|
597
716
|
additionalProperties: false,
|
|
598
717
|
properties: {
|
|
599
718
|
sessionId: { type: 'string', description: 'Session id; omit to list sessions instead.' },
|
|
719
|
+
historyId: {
|
|
720
|
+
type: 'string',
|
|
721
|
+
description: 'Optional exact incarnation address from the session list. Use it when several incarnations share one logical session id; required to address an older one.',
|
|
722
|
+
},
|
|
600
723
|
since: { type: 'string', description: 'Start time (ISO, epoch ms, or relative like "10m").' },
|
|
601
724
|
until: { type: 'string', description: 'End time.' },
|
|
602
725
|
search: { type: 'string', description: 'Regular expression or plain text to find (case-insensitive).' },
|
|
@@ -604,6 +727,8 @@ export function registerTools(ctx, plugin) {
|
|
|
604
727
|
maxMatches: { type: 'integer', description: 'Maximum matches (default 20).' },
|
|
605
728
|
maxBytes: { type: 'integer', description: 'Byte cap for a plain time-window read.' },
|
|
606
729
|
limit: { type: 'integer', description: 'Maximum sessions to list when sessionId is omitted.' },
|
|
730
|
+
offset: { type: 'integer', description: 'Offset for the session list (paging); truncated/total are returned.' },
|
|
731
|
+
snapshot: { type: 'string', description: 'Snapshot token from the previous list page. If history changed, stale:true is returned instead of silently skipping rows.' },
|
|
607
732
|
},
|
|
608
733
|
},
|
|
609
734
|
output: {
|
|
@@ -628,6 +753,7 @@ export function registerTools(ctx, plugin) {
|
|
|
628
753
|
bytes: { type: 'number' },
|
|
629
754
|
lastTs: { type: 'number' },
|
|
630
755
|
live: { type: 'boolean' },
|
|
756
|
+
historyId: { type: 'string' },
|
|
631
757
|
},
|
|
632
758
|
required: ['id', 'title', 'transport', 'host'],
|
|
633
759
|
},
|
|
@@ -649,6 +775,10 @@ export function registerTools(ctx, plugin) {
|
|
|
649
775
|
},
|
|
650
776
|
text: { type: 'string' },
|
|
651
777
|
truncated: { type: 'boolean' },
|
|
778
|
+
total: { type: 'integer' },
|
|
779
|
+
snapshot: { type: 'string' },
|
|
780
|
+
stale: { type: 'boolean' },
|
|
781
|
+
limitReached: { type: 'boolean' },
|
|
652
782
|
scannedBytes: { type: 'number' },
|
|
653
783
|
since: { type: 'number' },
|
|
654
784
|
complete: { type: 'boolean' },
|
|
@@ -667,6 +797,7 @@ export function registerTools(ctx, plugin) {
|
|
|
667
797
|
bytes: { type: 'number' },
|
|
668
798
|
lastTs: { type: 'number' },
|
|
669
799
|
live: { type: 'boolean' },
|
|
800
|
+
historyId: { type: 'string' },
|
|
670
801
|
},
|
|
671
802
|
required: ['id', 'title', 'transport', 'host'],
|
|
672
803
|
},
|
|
@@ -675,13 +806,34 @@ export function registerTools(ctx, plugin) {
|
|
|
675
806
|
},
|
|
676
807
|
render: (args, value) => {
|
|
677
808
|
if (Array.isArray(value.sessions)) {
|
|
678
|
-
|
|
809
|
+
const snapshot = typeof value.snapshot === 'string' && value.snapshot.length > 0
|
|
810
|
+
? `\nsnapshot: ${value.snapshot}`
|
|
811
|
+
: ''
|
|
812
|
+
const offset = Number.isInteger(args.offset) ? args.offset : 0
|
|
813
|
+
if (value.stale === true) {
|
|
814
|
+
return textContent(`History changed while paging; restart from the first page (call again with offset 0 and no snapshot) or narrow the time window.${snapshot}`)
|
|
815
|
+
}
|
|
816
|
+
if (value.sessions.length === 0) {
|
|
817
|
+
return textContent(value.limitReached === true
|
|
818
|
+
? `No more rows can be paged at this server source limit; total may be overestimated for legacy sources; narrow the time window.${snapshot}`
|
|
819
|
+
: `No session history is available yet.${snapshot}`)
|
|
820
|
+
}
|
|
679
821
|
const lines = value.sessions.map((entry) => {
|
|
680
822
|
const when = new Date(entry.createdAt).toISOString().slice(11, 19)
|
|
681
823
|
const end = entry.closedAt === undefined ? 'live' : new Date(entry.closedAt).toISOString().slice(11, 19)
|
|
682
|
-
|
|
824
|
+
const address = typeof entry.historyId === 'string' && entry.historyId.length > 0 ? ` historyId=${entry.historyId}` : ''
|
|
825
|
+
return `${entry.id}${address} ${entry.title} [${entry.transport} ${entry.host}:${entry.port}] ${when}→${end} ${entry.bytes}B`
|
|
683
826
|
})
|
|
684
|
-
|
|
827
|
+
const total = Number.isInteger(value.total) ? value.total : value.sessions.length
|
|
828
|
+
const footer = value.limitReached === true
|
|
829
|
+
? `\n\n[showing ${value.sessions.length} of ${total} — server source limit reached; total may be overestimated for legacy sources; narrow the time window]`
|
|
830
|
+
: (value.truncated === true
|
|
831
|
+
? `\n\n[showing ${value.sessions.length} of ${total} — more history exists; raise limit, use offset, or narrow the window]`
|
|
832
|
+
: '')
|
|
833
|
+
const next = value.limitReached === true || value.truncated !== true
|
|
834
|
+
? ''
|
|
835
|
+
: `\nTo page, call aiterm_history again with offset=${offset + value.sessions.length}${snapshot.length > 0 ? ' and the snapshot above' : ''}.`
|
|
836
|
+
return textContent(`${lines.join('\n')}${footer}${snapshot}${next}`)
|
|
685
837
|
}
|
|
686
838
|
if (Array.isArray(value.matches)) {
|
|
687
839
|
if (value.matches.length === 0) return textContent(`No match (scanned ${value.scannedBytes} bytes).`)
|
|
@@ -704,6 +856,7 @@ export function registerTools(ctx, plugin) {
|
|
|
704
856
|
const registry = requireRegistry(plugin)
|
|
705
857
|
return registry.historyQuery({
|
|
706
858
|
sessionId: args.sessionId,
|
|
859
|
+
historyId: args.historyId,
|
|
707
860
|
since: args.since,
|
|
708
861
|
until: args.until,
|
|
709
862
|
search: args.search,
|
|
@@ -711,6 +864,8 @@ export function registerTools(ctx, plugin) {
|
|
|
711
864
|
maxMatches: args.maxMatches,
|
|
712
865
|
maxBytes: args.maxBytes,
|
|
713
866
|
limit: args.limit,
|
|
867
|
+
offset: args.offset,
|
|
868
|
+
snapshot: args.snapshot,
|
|
714
869
|
})
|
|
715
870
|
},
|
|
716
871
|
})
|
|
@@ -1172,13 +1327,17 @@ export function registerTools(ctx, plugin) {
|
|
|
1172
1327
|
register({
|
|
1173
1328
|
name: 'aiterm_export',
|
|
1174
1329
|
description:
|
|
1175
|
-
'Export
|
|
1330
|
+
'Export stored output history for sessions owned by the current conversation (live or already closed) as human-readable text log files on the Host. all:true exports every readable incarnation — including several incarnations that share one logical session id — and returns a skipped list for unreadable/missing sources; a write-only closed incarnation is reported as skipped rather than leaked. Pass historyId to export one exact incarnation. Each line is "<ISO timestamp> <output line>", after a header with transport/host/port/username/title/start. Returns absolute paths with byte and line counts. Time values accept epoch milliseconds, ISO timestamps, or relative amounts like "10m".',
|
|
1176
1331
|
parameters: {
|
|
1177
1332
|
type: 'object',
|
|
1178
1333
|
additionalProperties: false,
|
|
1179
1334
|
properties: {
|
|
1180
1335
|
sessionId: { type: 'string', description: 'Session to export; omit to use the only session.' },
|
|
1181
|
-
|
|
1336
|
+
historyId: {
|
|
1337
|
+
type: 'string',
|
|
1338
|
+
description: 'Optional exact incarnation address. Use it to export an older incarnation that shares a logical session id.',
|
|
1339
|
+
},
|
|
1340
|
+
all: { type: 'boolean', description: 'Export every session owned by this conversation, including already closed ones.' },
|
|
1182
1341
|
since: { type: 'string', description: 'Start time (ISO, epoch ms, or relative like "10m").' },
|
|
1183
1342
|
until: { type: 'string', description: 'End time (ISO, epoch ms, or relative like "2h").' },
|
|
1184
1343
|
},
|
|
@@ -1196,6 +1355,7 @@ export function registerTools(ctx, plugin) {
|
|
|
1196
1355
|
additionalProperties: false,
|
|
1197
1356
|
properties: {
|
|
1198
1357
|
sessionId: { type: 'string' },
|
|
1358
|
+
historyId: { type: 'string' },
|
|
1199
1359
|
path: { type: 'string' },
|
|
1200
1360
|
bytes: { type: 'integer' },
|
|
1201
1361
|
lines: { type: 'integer' },
|
|
@@ -1203,21 +1363,58 @@ export function registerTools(ctx, plugin) {
|
|
|
1203
1363
|
required: ['sessionId', 'path', 'bytes', 'lines'],
|
|
1204
1364
|
},
|
|
1205
1365
|
},
|
|
1366
|
+
skipped: {
|
|
1367
|
+
type: 'array',
|
|
1368
|
+
items: {
|
|
1369
|
+
type: 'object',
|
|
1370
|
+
additionalProperties: false,
|
|
1371
|
+
properties: {
|
|
1372
|
+
sessionId: { type: 'string' },
|
|
1373
|
+
historyId: { type: 'string' },
|
|
1374
|
+
code: { type: 'string' },
|
|
1375
|
+
message: { type: 'string' },
|
|
1376
|
+
count: { type: 'integer' },
|
|
1377
|
+
},
|
|
1378
|
+
required: ['sessionId', 'code', 'message'],
|
|
1379
|
+
},
|
|
1380
|
+
},
|
|
1381
|
+
omitted: {
|
|
1382
|
+
type: 'object',
|
|
1383
|
+
additionalProperties: false,
|
|
1384
|
+
properties: {
|
|
1385
|
+
count: { type: 'integer' },
|
|
1386
|
+
limit: { type: 'integer' },
|
|
1387
|
+
reason: { type: 'string' },
|
|
1388
|
+
},
|
|
1389
|
+
required: ['count', 'limit', 'reason'],
|
|
1390
|
+
},
|
|
1391
|
+
skippedTotal: { type: 'integer' },
|
|
1206
1392
|
},
|
|
1207
|
-
required: ['dir', 'files'],
|
|
1393
|
+
required: ['dir', 'files', 'skipped'],
|
|
1208
1394
|
},
|
|
1209
1395
|
render: (args, value) => {
|
|
1210
|
-
|
|
1396
|
+
const files = Array.isArray(value.files) ? value.files : []
|
|
1397
|
+
const skipped = Array.isArray(value.skipped) ? value.skipped : []
|
|
1398
|
+
if (files.length === 0 && skipped.length === 0) {
|
|
1211
1399
|
return textContent(`No history to export (checked ${value.dir}).`)
|
|
1212
1400
|
}
|
|
1213
|
-
const lines =
|
|
1214
|
-
|
|
1401
|
+
const lines = files.map((file) => `${file.sessionId}${file.historyId ? ` (${file.historyId})` : ''} ${file.bytes}B ${file.lines} lines ${file.path}`)
|
|
1402
|
+
if (files.length === 0) {
|
|
1403
|
+
const skippedTotal = Number.isInteger(value.skippedTotal) ? value.skippedTotal : skipped.length
|
|
1404
|
+
const omitted = value.omitted ? `, ${value.omitted.count} incarnation(s) not attempted (${value.omitted.reason})` : ''
|
|
1405
|
+
return textContent(`No history file could be exported (checked ${value.dir}); ${skippedTotal} source(s) skipped${omitted}.`)
|
|
1406
|
+
}
|
|
1407
|
+
const skippedTotal = Number.isInteger(value.skippedTotal) ? value.skippedTotal : skipped.length
|
|
1408
|
+
const suffix = skippedTotal > 0 ? `\nSkipped ${skippedTotal} entry/entries (details: ${skipped.length}).` : ''
|
|
1409
|
+
const omitted = value.omitted ? `\n${value.omitted.count} incarnation(s) were not attempted (${value.omitted.reason}, limit ${value.omitted.limit}).` : ''
|
|
1410
|
+
return textContent(`Exported ${files.length} log file(s) to ${value.dir}:\n${lines.join('\n')}${suffix}${omitted}`)
|
|
1215
1411
|
},
|
|
1216
1412
|
},
|
|
1217
1413
|
async execute(args) {
|
|
1218
1414
|
const registry = requireRegistry(plugin)
|
|
1219
1415
|
return registry.exportHistory({
|
|
1220
1416
|
sessionId: args.sessionId,
|
|
1417
|
+
historyId: args.historyId,
|
|
1221
1418
|
all: args.all === true,
|
|
1222
1419
|
since: args.since,
|
|
1223
1420
|
until: args.until,
|
|
@@ -1228,7 +1425,7 @@ export function registerTools(ctx, plugin) {
|
|
|
1228
1425
|
register({
|
|
1229
1426
|
name: 'aiterm_autolog',
|
|
1230
1427
|
description:
|
|
1231
|
-
'Query
|
|
1428
|
+
'Query automatic log-file writing. With no arguments it reports the current switch and directory. This is a host-wide privacy setting: only the human can change it from the history panel, so the AI can read the state but any attempt to enable/disable it or choose a directory is refused. Off by default; when enabled, every session appends its live output to <dir>/<sessionId>.log with a header containing only transport/host/port/username/title (never credentials). The setting and directory persist across Host restarts.',
|
|
1232
1429
|
parameters: {
|
|
1233
1430
|
type: 'object',
|
|
1234
1431
|
additionalProperties: false,
|
|
@@ -1244,20 +1441,81 @@ export function registerTools(ctx, plugin) {
|
|
|
1244
1441
|
properties: {
|
|
1245
1442
|
enabled: { type: 'boolean' },
|
|
1246
1443
|
dir: { type: 'string' },
|
|
1444
|
+
needsReview: { type: 'boolean' },
|
|
1247
1445
|
},
|
|
1248
1446
|
required: ['enabled', 'dir'],
|
|
1249
1447
|
},
|
|
1250
|
-
render: (args, value) =>
|
|
1251
|
-
|
|
1448
|
+
render: (args, value) => {
|
|
1449
|
+
const review = value.needsReview === true
|
|
1450
|
+
? '\nThis switch was enabled by an older version and is paused: only the human can confirm it in the history panel.'
|
|
1451
|
+
: ''
|
|
1452
|
+
return textContent(`Automatic log files: ${value.enabled ? 'enabled' : 'disabled'}\nDirectory: ${value.dir}${review}`)
|
|
1453
|
+
},
|
|
1252
1454
|
},
|
|
1253
1455
|
async execute(args) {
|
|
1254
1456
|
const registry = requireRegistry(plugin)
|
|
1255
1457
|
const autolog = registry.autolog
|
|
1256
1458
|
if (autolog === undefined || autolog === null) throw new Error('automatic log files are not available in this build')
|
|
1257
|
-
|
|
1258
|
-
|
|
1459
|
+
// The switch and directory are host-wide: enabling them makes every
|
|
1460
|
+
// session, including other owners' terminals, write plaintext output to a
|
|
1461
|
+
// path the AI chooses. That is a cross-owner disclosure primitive, so the
|
|
1462
|
+
// AI may read the state but only the human panel may change it.
|
|
1463
|
+
if (args.enabled !== undefined || args.dir !== undefined) {
|
|
1464
|
+
throw coded(
|
|
1465
|
+
'HUMAN_ONLY',
|
|
1466
|
+
'automatic log files are a host-wide privacy setting; only the human can change it from the history panel',
|
|
1467
|
+
403,
|
|
1468
|
+
)
|
|
1469
|
+
}
|
|
1470
|
+
return autolog.get()
|
|
1259
1471
|
},
|
|
1260
1472
|
})
|
|
1473
|
+
|
|
1474
|
+
// The discovery entry is deliberately not part of any business group: it
|
|
1475
|
+
// never touches a terminal, is registered without a condition so it stays
|
|
1476
|
+
// resident in progressive mode, and exists only there (full mode keeps the
|
|
1477
|
+
// historical 21-tool surface).
|
|
1478
|
+
if (progressive) {
|
|
1479
|
+
const discoveryDefinition = {
|
|
1480
|
+
name: DISCOVER_TOOL_NAME,
|
|
1481
|
+
description:
|
|
1482
|
+
'Discover the SSH/Telnet toolset. Call with no arguments to list the available groups, the tools this Agent may see, and the groups already expanded; call again with one group (session, history, automation, management) to expand it. Expansion only reveals schemas: it takes effect on the next model step, never grants permission, and existing read-only/write-only AI modes and human control still refuse calls. Begin with the session group.',
|
|
1483
|
+
parameters: {
|
|
1484
|
+
type: 'object',
|
|
1485
|
+
additionalProperties: false,
|
|
1486
|
+
properties: {
|
|
1487
|
+
group: {
|
|
1488
|
+
type: 'string',
|
|
1489
|
+
enum: DISCLOSURE_GROUP_NAMES,
|
|
1490
|
+
description: 'Group to expand; omit to only inspect the current disclosure state.',
|
|
1491
|
+
},
|
|
1492
|
+
},
|
|
1493
|
+
},
|
|
1494
|
+
output: {
|
|
1495
|
+
schema: DISCOVERY_OUTPUT_SCHEMA,
|
|
1496
|
+
render: (args, value) => textContent(renderDiscovery(value)),
|
|
1497
|
+
},
|
|
1498
|
+
async execute(args, exec) {
|
|
1499
|
+
const agent = exec?.agent
|
|
1500
|
+
if (args !== null && typeof args === 'object' && args.group !== undefined) {
|
|
1501
|
+
return disclosure.expand(agent, args.group)
|
|
1502
|
+
}
|
|
1503
|
+
return disclosure.discover(agent)
|
|
1504
|
+
},
|
|
1505
|
+
}
|
|
1506
|
+
const discoveryExecute = discoveryDefinition.execute
|
|
1507
|
+
const guardedDiscovery = {
|
|
1508
|
+
...discoveryDefinition,
|
|
1509
|
+
async execute(args, exec) {
|
|
1510
|
+
// No terminal-owner binding: discovery never touches the session
|
|
1511
|
+
// registry, so it must work before any terminal exists.
|
|
1512
|
+
const value = await discoveryExecute(args, exec)
|
|
1513
|
+
const safe = jsonSafe(value)
|
|
1514
|
+
return safe === undefined ? null : safe
|
|
1515
|
+
},
|
|
1516
|
+
}
|
|
1517
|
+
ctx.effect(() => ctx.tools.register(guardedDiscovery), `aiterm: tool ${DISCOVER_TOOL_NAME}`)
|
|
1518
|
+
}
|
|
1261
1519
|
}
|
|
1262
1520
|
|
|
1263
1521
|
/** Wire shape of one batch run. */
|
package/lib/index.js
CHANGED
|
@@ -115,8 +115,8 @@ export function apply(ctx, config) {
|
|
|
115
115
|
// 1) Model-facing tools (`tools` is guaranteed by `inject`).
|
|
116
116
|
registerTools(ctx, plugin)
|
|
117
117
|
|
|
118
|
-
// 2) System-prompt guidance.
|
|
119
|
-
registerPrompt(ctx)
|
|
118
|
+
// 2) System-prompt guidance (mode-specific: full keeps the historical text).
|
|
119
|
+
registerPrompt(ctx, resolved.toolDisclosure)
|
|
120
120
|
|
|
121
121
|
// 3) HTTP RPC + SSE, only when the Web composition provides both services.
|
|
122
122
|
// `ctx.inject` never fires in a headless composition, which is exactly the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-aiterm",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.12",
|
|
4
4
|
"description": "SSH and Telnet terminals for DeepSeek Harness: one real terminal shared by you and the AI, with per-session AI permissions and token-cheap delta reads.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,22 +42,24 @@
|
|
|
42
42
|
"icon.svg",
|
|
43
43
|
"README.md",
|
|
44
44
|
"LICENSE",
|
|
45
|
-
"CONTRACTS.md"
|
|
45
|
+
"CONTRACTS.md",
|
|
46
|
+
"vendor"
|
|
46
47
|
],
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "node scripts/build-client.mjs",
|
|
49
50
|
"lint": "node --check lib/index.js && for f in lib/host/*.js lib/host/transports/*.js; do node --check \"$f\" || exit 1; done",
|
|
50
|
-
"test": "node scripts/smoke-client.mjs"
|
|
51
|
+
"test": "node --test test/*.test.mjs && node scripts/smoke-client.mjs",
|
|
52
|
+
"build:vendor": "node scripts/build-vendor.mjs"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
55
|
"@xterm/addon-serialize": "^0.14.0",
|
|
54
|
-
"@xterm/headless": "^6.0.0"
|
|
55
|
-
"ssh2": "^1.17.0"
|
|
56
|
+
"@xterm/headless": "^6.0.0"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@xterm/addon-fit": "^0.11.0",
|
|
59
60
|
"@xterm/xterm": "^6.0.0",
|
|
60
|
-
"esbuild": "^0.28.2"
|
|
61
|
+
"esbuild": "^0.28.2",
|
|
62
|
+
"ssh2": "1.17.0"
|
|
61
63
|
},
|
|
62
64
|
"dsh": {
|
|
63
65
|
"bundle": {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build `vendor/ssh2.cjs` — the pure-JS `ssh2` bundle shipped inside this package.
|
|
3
|
+
*
|
|
4
|
+
* Why: `ssh2` is already pure JS, but it carries two *optional* native extras
|
|
5
|
+
* (`cpu-features` and its own `sshcrypto` node-gyp binding). Both are loaded
|
|
6
|
+
* inside `try/catch` with a pure-JS fallback, yet their `install` / `rebuild`
|
|
7
|
+
* scripts make pnpm 10+ stop and ask for build approval — which rolls back the
|
|
8
|
+
* whole DSH profile install. Vendoring removes them from the dependency graph.
|
|
9
|
+
*
|
|
10
|
+
* Usage: `npm install && npm run build:vendor`
|
|
11
|
+
*/
|
|
12
|
+
import { execFileSync } from 'node:child_process'
|
|
13
|
+
import { createRequire } from 'node:module'
|
|
14
|
+
import { dirname, resolve } from 'node:path'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
|
|
17
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
18
|
+
const require = createRequire(import.meta.url)
|
|
19
|
+
const entry = require.resolve('ssh2')
|
|
20
|
+
const esbuild = resolve(root, 'node_modules', '.bin', 'esbuild')
|
|
21
|
+
const outfile = resolve(root, 'vendor', 'ssh2.cjs')
|
|
22
|
+
|
|
23
|
+
execFileSync(esbuild, [
|
|
24
|
+
entry,
|
|
25
|
+
'--bundle',
|
|
26
|
+
'--platform=node',
|
|
27
|
+
'--format=cjs',
|
|
28
|
+
'--target=node20',
|
|
29
|
+
`--outfile=${outfile}`,
|
|
30
|
+
'--external:cpu-features',
|
|
31
|
+
'--external:nan',
|
|
32
|
+
'--external:./crypto/build/Release/sshcrypto.node',
|
|
33
|
+
'--log-level=warning',
|
|
34
|
+
], { stdio: 'inherit' })
|
|
35
|
+
|
|
36
|
+
const { statSync } = await import('node:fs')
|
|
37
|
+
console.log(`build-vendor: wrote ${outfile} (${Math.round(statSync(outfile).size / 1024)} KiB)`)
|