dsh-aiterm 0.5.1 → 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 +202 -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/index.js +2 -2
- package/package.json +2 -2
- package/scripts/smoke-client.mjs +193 -6
package/lib/host/permission.js
CHANGED
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
* @property {boolean} humanWriteBlocked derived; the human's keystrokes are refused
|
|
33
33
|
* @property {boolean} aiWriteBlocked derived; the AI's writes are refused
|
|
34
34
|
* @property {number} updatedAt
|
|
35
|
+
* @property {number} revision monotonic change counter (internal)
|
|
36
|
+
* @property {number} readRevision read-authorization revision (internal)
|
|
35
37
|
*/
|
|
36
38
|
|
|
37
39
|
/**
|
|
@@ -66,6 +68,8 @@ export function createPermission(config) {
|
|
|
66
68
|
humanWriteBlocked: false,
|
|
67
69
|
aiWriteBlocked: false,
|
|
68
70
|
updatedAt: Date.now(),
|
|
71
|
+
revision: 0,
|
|
72
|
+
readRevision: 0,
|
|
69
73
|
}
|
|
70
74
|
return derive(state, config)
|
|
71
75
|
}
|
|
@@ -96,6 +100,7 @@ export function expireIfIdle(state, now, config) {
|
|
|
96
100
|
state.lockOwner = null
|
|
97
101
|
state.lockExpiresAt = null
|
|
98
102
|
state.updatedAt = now
|
|
103
|
+
state.revision = (state.revision ?? 0) + 1
|
|
99
104
|
derive(state, config)
|
|
100
105
|
return true
|
|
101
106
|
}
|
|
@@ -165,6 +170,7 @@ export function noteAiWrite(state, config, now = Date.now()) {
|
|
|
165
170
|
if (state.lockOwner === 'ai') {
|
|
166
171
|
state.lockOwner = null
|
|
167
172
|
state.lockExpiresAt = null
|
|
173
|
+
state.revision = (state.revision ?? 0) + 1
|
|
168
174
|
derive(state, config)
|
|
169
175
|
return true
|
|
170
176
|
}
|
|
@@ -172,6 +178,7 @@ export function noteAiWrite(state, config, now = Date.now()) {
|
|
|
172
178
|
}
|
|
173
179
|
state.lockOwner = 'ai'
|
|
174
180
|
state.lockExpiresAt = now + config.aiLockIdleMs
|
|
181
|
+
state.revision = (state.revision ?? 0) + 1
|
|
175
182
|
derive(state, config)
|
|
176
183
|
return true
|
|
177
184
|
}
|
|
@@ -188,6 +195,8 @@ export function takeOver(state, config, now = Date.now()) {
|
|
|
188
195
|
state.lockOwner = 'human'
|
|
189
196
|
state.lockExpiresAt = null
|
|
190
197
|
state.updatedAt = now
|
|
198
|
+
state.revision = (state.revision ?? 0) + 1
|
|
199
|
+
state.readRevision = (state.readRevision ?? 0) + 1
|
|
191
200
|
derive(state, config)
|
|
192
201
|
return true
|
|
193
202
|
}
|
|
@@ -204,6 +213,8 @@ export function releaseLock(state, config, now = Date.now()) {
|
|
|
204
213
|
state.lockOwner = null
|
|
205
214
|
state.lockExpiresAt = null
|
|
206
215
|
state.updatedAt = now
|
|
216
|
+
state.revision = (state.revision ?? 0) + 1
|
|
217
|
+
state.readRevision = (state.readRevision ?? 0) + 1
|
|
207
218
|
derive(state, config)
|
|
208
219
|
return true
|
|
209
220
|
}
|
|
@@ -220,6 +231,8 @@ export function setAiAccess(state, aiAccess, config, now = Date.now()) {
|
|
|
220
231
|
if (state.aiAccess === aiAccess) return false
|
|
221
232
|
state.aiAccess = aiAccess
|
|
222
233
|
state.updatedAt = now
|
|
234
|
+
state.revision = (state.revision ?? 0) + 1
|
|
235
|
+
state.readRevision = (state.readRevision ?? 0) + 1
|
|
223
236
|
derive(state, config)
|
|
224
237
|
return true
|
|
225
238
|
}
|
package/lib/host/prompt.js
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Registered once the `systemPrompt` service exists, at the terminal-tool order
|
|
5
5
|
* so it sits next to the other terminal guidance. Kept short: it ships with
|
|
6
|
-
* every request.
|
|
6
|
+
* every request. The text follows the configured disclosure mode: full keeps
|
|
7
|
+
* the historical guidance, progressive explains discovery and the next-step
|
|
8
|
+
* rule without naming any tool that another restriction may hide.
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
/** Stable prompt section name. */
|
|
10
12
|
export const PROMPT_SECTION_NAME = 'tool:aiterm'
|
|
11
13
|
|
|
12
|
-
/** Guidance text shown to the model. */
|
|
14
|
+
/** Guidance text shown to the model in `full` mode. */
|
|
13
15
|
export const PROMPT_TEXT = [
|
|
14
16
|
'SSH/Telnet sessions opened in the user\'s SSH/Telnet panel are shared with the user: `aiterm_list` shows them with their connection state and the AI permission the user granted.',
|
|
15
17
|
'Each session has its own AI permission: read-only (只读) lets you read output but never send input; write-only (只写) lets you send input but never read output; read-write (读写) allows both. Only the user can change it — a refusal is a policy decision, so report it instead of retrying or working around it.',
|
|
@@ -18,19 +20,37 @@ export const PROMPT_TEXT = [
|
|
|
18
20
|
'Prefer reading the screen before and after a command, send a newline with a trailing "\\r" (or enter:true), and never assume a command finished without checking its output.',
|
|
19
21
|
].join(' ')
|
|
20
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Guidance text shown to the model in `progressive` mode.
|
|
25
|
+
*
|
|
26
|
+
* Only the always-resident discovery entry is named: naming any other tool
|
|
27
|
+
* could disclose one that another restriction hides from this Agent.
|
|
28
|
+
*/
|
|
29
|
+
export const PROGRESSIVE_PROMPT_TEXT = [
|
|
30
|
+
'SSH/Telnet tools are disclosed progressively. Only the discovery entry `aiterm_discover` is available at first: call it with no arguments to list the available groups (session, history, automation, management), the tools this Agent may see, and the groups already expanded; call it again with one group to expand it.',
|
|
31
|
+
'Expansion affects the next model step only: a tool expanded during this step is not callable until the next step, so expand first and call the tool afterwards.',
|
|
32
|
+
'Expansion never grants permission. Each session keeps its own AI permission: read-only (只读) lets you read output but never send input; write-only (只写) lets you send input but never read output; read-write (读写) allows both. Only the user can change it — a refusal is a policy decision, so report it instead of retrying or working around it.',
|
|
33
|
+
'Start with the session group and list sessions: the other groups need an existing session id. While you send input, you hold control of the session and the user\'s typing is blocked until you go idle or use the release-control tool; call it as soon as you finish a multi-step operation so the user can type again.',
|
|
34
|
+
'If the user takes over control, your writes are refused until they release it. Use the status tool to see the current owner and the read/screen tools to inspect the screen before acting.',
|
|
35
|
+
'Prefer reading the screen before and after a command, send a newline with a trailing "\\r" (or enter:true), and never assume a command finished without checking its output.',
|
|
36
|
+
].join(' ')
|
|
37
|
+
|
|
21
38
|
/**
|
|
22
39
|
* Register the prompt section once the systemPrompt service exists.
|
|
23
40
|
* @param {any} ctx plugin context.
|
|
41
|
+
* @param {unknown} [toolDisclosure] configured `toolDisclosure` value; only the
|
|
42
|
+
* exact `progressive` string selects the progressive guidance.
|
|
24
43
|
* @returns {void}
|
|
25
44
|
*/
|
|
26
|
-
export function registerPrompt(ctx) {
|
|
45
|
+
export function registerPrompt(ctx, toolDisclosure) {
|
|
46
|
+
const text = toolDisclosure === 'progressive' ? PROGRESSIVE_PROMPT_TEXT : PROMPT_TEXT
|
|
27
47
|
ctx.inject(['systemPrompt'], (promptCtx) => {
|
|
28
48
|
promptCtx.effect(
|
|
29
49
|
() =>
|
|
30
50
|
promptCtx.systemPrompt.section({
|
|
31
51
|
name: PROMPT_SECTION_NAME,
|
|
32
52
|
order: promptCtx.systemPrompt.getSectionOrder('TOOL_PTY'),
|
|
33
|
-
text
|
|
53
|
+
text,
|
|
34
54
|
}),
|
|
35
55
|
'aiterm: prompt section',
|
|
36
56
|
)
|