shapewall 0.3.1 → 0.3.3
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/CHANGELOG.md +142 -0
- package/NOTICE +7 -0
- package/README.md +4 -2
- package/THIRD_PARTY.md +39 -0
- package/dist/agent/package-lock.json +2 -2
- package/dist/client/assets/BoardChat-DxehB761.js +27 -0
- package/dist/client/assets/BuzzDialog-Ix9qJvim.js +1 -0
- package/dist/client/assets/ChecksPanel-pA_ueIaJ.js +1 -0
- package/dist/client/assets/History-C9N32kCv.js +1 -0
- package/dist/client/assets/LocalSettings-DawtKnvi.js +1 -0
- package/dist/client/assets/{Management-BFcKFdbp.js → Management-NVFDtSZB.js} +1 -1
- package/dist/client/assets/QuickConnect-DO1TjS1t.js +1 -0
- package/dist/client/assets/ShareDialog-By0ETg6n.js +2 -0
- package/dist/client/assets/app-update-dialog-RGIw24iZ.js +1 -0
- package/dist/client/assets/{circle-x-PRxj7kPi.js → circle-x-B6KfScOE.js} +1 -1
- package/dist/client/assets/index-CsqLdqGx.css +2 -0
- package/dist/client/assets/index-DnZarJ3U.js +37 -0
- package/dist/client/assets/{refresh-cw-aeOBDuGQ.js → refresh-cw-vkgvCCfR.js} +1 -1
- package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/client/assets/{shield-check-DuPBJ6H_.js → shield-check-QzwGhz0t.js} +1 -1
- package/dist/client/assets/ui-DI-FGWWK.js +41 -0
- package/dist/client/build-info.json +1 -1
- package/dist/client/index.html +4 -3
- package/dist/client/sw.js +2 -2
- package/dist/console/assets/{LocalAccountsApp-lJjkhUcH.js → LocalAccountsApp-VOCZg8dg.js} +1 -1
- package/dist/console/assets/{LocalConsole-BZHqYKnt.js → LocalConsole-CMwAW-mF.js} +1 -1
- package/dist/console/assets/{app-update-dialog-DCM9sYE3.js → app-update-dialog-Cw6UDqNP.js} +1 -1
- package/dist/console/assets/console-DgfWmUEx.js +55 -0
- package/dist/console/assets/console-Lis0vvdL.css +2 -0
- package/dist/console/build-info.json +1 -1
- package/dist/console/console.html +2 -2
- package/docs/agent-workflow.md +19 -3
- package/docs/agents.md +62 -2
- package/docs/config.md +3 -3
- package/docs/deployment.md +2 -0
- package/docs/design-system.md +20 -15
- package/docs/hosted.md +19 -0
- package/docs/pull-requests.md +4 -1
- package/docs/where-to-run.md +88 -0
- package/package.json +2 -1
- package/src/agent/agent-logos.js +81 -0
- package/src/agent/composer.js +9 -5
- package/src/agent/config.js +27 -2
- package/src/agent/context.js +3 -1
- package/src/agent/icon-store.js +100 -0
- package/src/agent/identity.js +77 -0
- package/src/agent/owner-mcp.js +19 -3
- package/src/agent/routes.js +82 -21
- package/src/agent/run.js +3 -1
- package/src/agent/settings-routes.js +233 -14
- package/src/agent/test-timing.js +14 -0
- package/src/agent/tools.js +6 -3
- package/src/agent/user-settings.js +51 -3
- package/src/capture/capture.js +3 -1
- package/src/capture/element-map.js +73 -11
- package/src/ci/settings.js +3 -3
- package/src/ci/start.js +16 -0
- package/src/ci/summary.js +8 -1
- package/src/cli/args.js +1 -0
- package/src/cli/ci.js +2 -2
- package/src/cli/comments.js +5 -4
- package/src/cli/help.js +3 -1
- package/src/cli/init.js +2 -2
- package/src/comment-fields.js +45 -0
- package/src/comments-cli.js +100 -21
- package/src/discover.js +34 -1
- package/src/doctor.js +26 -1
- package/src/event-log.js +5 -2
- package/src/feedback.js +5 -2
- package/src/github.js +4 -2
- package/src/hosted/agent-presence.js +40 -0
- package/src/hosted/app.js +6 -0
- package/src/hosted/board-routes.js +9 -1
- package/src/hosted/comments.js +11 -11
- package/src/hosted/console-routes.js +47 -1
- package/src/hosted/events.js +6 -4
- package/src/hosted/import.js +7 -4
- package/src/hosted/presence.js +1 -1
- package/src/hosted/projects.js +32 -1
- package/src/hosted/token-api.js +5 -1
- package/src/hosted/token-events.js +5 -2
- package/src/hosted/tokens.js +3 -2
- package/src/mcp.js +10 -2
- package/src/notify/messages.js +6 -4
- package/src/store.js +19 -11
- package/dist/client/assets/BoardChat-V1BCXdDB.js +0 -27
- package/dist/client/assets/BuzzDialog-Ds7Thpfe.js +0 -1
- package/dist/client/assets/ChecksPanel-Cm22bCdQ.js +0 -1
- package/dist/client/assets/History-U0bD1BjA.js +0 -1
- package/dist/client/assets/LocalSettings-DOSuW7VC.js +0 -1
- package/dist/client/assets/QuickConnect-DyfPSWbV.js +0 -1
- package/dist/client/assets/ShareDialog-BouvNraR.js +0 -2
- package/dist/client/assets/app-update-dialog-DH2Mgby8.js +0 -1
- package/dist/client/assets/index-C9S7HL_o.js +0 -37
- package/dist/client/assets/index-CXtuJi1K.css +0 -2
- package/dist/client/assets/ui-Cg4TTrec.js +0 -41
- package/dist/console/assets/console-C2LsvEco.js +0 -55
- package/dist/console/assets/console-Fp4k9iyx.css +0 -2
package/src/agent/routes.js
CHANGED
|
@@ -73,6 +73,8 @@ import { createAgentHealth } from './agent-health.js'
|
|
|
73
73
|
import { beginAgentOperation } from './control.js'
|
|
74
74
|
import { validateFiles, validateMentions } from './composer.js'
|
|
75
75
|
import { profileForDefault, userAgentEntry, userSettingsFile } from './user-settings.js'
|
|
76
|
+
import { uploadHashes } from './identity.js'
|
|
77
|
+
import { readIcon } from './icon-store.js'
|
|
76
78
|
import { finishFix, projectChanged, projectSnapshot, stopReason } from './feedback-loop.js'
|
|
77
79
|
import { ownerMcpServers } from './owner-mcp.js'
|
|
78
80
|
import { RUN_MS_MAX, commentIdOf, runTurn } from './run.js'
|
|
@@ -104,11 +106,14 @@ import {
|
|
|
104
106
|
versionsOf,
|
|
105
107
|
visibleTo,
|
|
106
108
|
} from './threads.js'
|
|
109
|
+
import { commentText } from '../comment-fields.js'
|
|
107
110
|
|
|
108
111
|
// Four 5 MB images in base64, and the text. Only POST .../messages reads a
|
|
109
112
|
// body this big, and only once the message is allowed to run.
|
|
110
113
|
export const BODY_LIMIT = '28mb'
|
|
111
114
|
const SMALL_BODY_LIMIT = '4kb'
|
|
115
|
+
// An uploaded agent icon: 512 KiB of PNG at most (src/accounts/avatar.js), in base64.
|
|
116
|
+
const ICON_BODY_LIMIT = '700kb'
|
|
112
117
|
// Open GET /events streams at once; a new one ends the oldest.
|
|
113
118
|
export const EVENT_STREAMS_MAX = 32
|
|
114
119
|
|
|
@@ -241,7 +246,19 @@ export function agentRouter({
|
|
|
241
246
|
}
|
|
242
247
|
// How each agent is doing (agent-health.js): from the last turn or test.
|
|
243
248
|
const health = createAgentHealth()
|
|
244
|
-
|
|
249
|
+
// While an agent's connection test runs (settings-routes.js) its state is
|
|
250
|
+
// "testing": the chat header says so instead of "Ready".
|
|
251
|
+
const testedNow = (current) => {
|
|
252
|
+
const test = connectionTest()
|
|
253
|
+
if (!test) return false
|
|
254
|
+
if (current.profileId) return test.id === current.profileId
|
|
255
|
+
const runs = current.defaultProfile || profileForDefault(userAgentEntry(config.dir, env).entry)?.id || 'default'
|
|
256
|
+
return test.id === 'default' || test.id === runs
|
|
257
|
+
}
|
|
258
|
+
const agentStatus = (current) => {
|
|
259
|
+
const status = health.status(current, processPool)
|
|
260
|
+
return testedNow(current) ? { ...status, state: 'testing' } : status
|
|
261
|
+
}
|
|
245
262
|
router.health = health
|
|
246
263
|
const profiles = () => {
|
|
247
264
|
const saved = userAgentEntry(config.dir, env)
|
|
@@ -283,9 +300,13 @@ export function agentRouter({
|
|
|
283
300
|
'control_needs_owner',
|
|
284
301
|
'This agent can run commands on this computer, so only its owner can use it. Open the private owner link from the terminal (or run shapewall serve --open), or use a paired device.',
|
|
285
302
|
)
|
|
303
|
+
// What makes a backend the same one: everything but the agent's name,
|
|
304
|
+
// icon and tint (identity.js), which are display only. Renaming an agent
|
|
305
|
+
// must not stop its processes.
|
|
306
|
+
const fingerprintOf = (current) => JSON.stringify({ ...current, label: null, icon: null, tint: null })
|
|
286
307
|
const backendFor = (current, ownerWrites = false) => {
|
|
287
308
|
const key = JSON.stringify({ profileId: current.profileId || 'default', ownerWrites })
|
|
288
|
-
const fingerprint =
|
|
309
|
+
const fingerprint = fingerprintOf(current)
|
|
289
310
|
if (backends.has(key) && backends.get(key).fingerprint !== fingerprint) {
|
|
290
311
|
backends.get(key).backend?.close?.()
|
|
291
312
|
backends.delete(key)
|
|
@@ -293,32 +314,44 @@ export function agentRouter({
|
|
|
293
314
|
if (!backends.has(key)) {
|
|
294
315
|
// usage: an endpoint is asked for token counts (the composer's usage
|
|
295
316
|
// ring); one that refuses stream_options is asked again without.
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
317
|
+
const live = { ...current, usage: current.usage ?? true }
|
|
318
|
+
const backend = createBackend(live, {
|
|
319
|
+
env,
|
|
320
|
+
fetchImpl,
|
|
321
|
+
processPool,
|
|
322
|
+
root: config.dir,
|
|
323
|
+
protect: [config.outputDir],
|
|
324
|
+
// Files capture runs or logs in with: a write needs an approval card.
|
|
325
|
+
sensitivePaths: () => authFiles(config),
|
|
326
|
+
mcpServersFor: ownerWrites
|
|
327
|
+
? (thread) =>
|
|
328
|
+
ownerMcpServers(config, thread.split('/')[0], {
|
|
329
|
+
allowCapture,
|
|
330
|
+
env,
|
|
331
|
+
// Whose replies these are, so they are signed with its name.
|
|
332
|
+
agent: {
|
|
333
|
+
which: live.profileId || (['flag', 'env'].includes(live.sources?.acpCommand) ? 'fixed' : 'default'),
|
|
334
|
+
name: live.label,
|
|
335
|
+
},
|
|
336
|
+
})
|
|
337
|
+
: null,
|
|
338
|
+
// One agent process per thread, no more than answers at once.
|
|
339
|
+
limits: { processesMax: limit.runsMax, ...limit.acp },
|
|
340
|
+
log,
|
|
341
|
+
})
|
|
342
|
+
backends.set(key, { key, fingerprint, backend, live })
|
|
313
343
|
}
|
|
314
344
|
cached = backends.get(key)
|
|
345
|
+
// A rename since the backend was made: what it says next ("Starting
|
|
346
|
+
// Harry") uses the new name. Nothing is restarted for it.
|
|
347
|
+
Object.assign(cached.live, { label: current.label, icon: current.icon, tint: current.tint })
|
|
315
348
|
return cached.backend
|
|
316
349
|
}
|
|
317
350
|
// The owner backend already running for these settings, never a new one
|
|
318
351
|
// (the composer's pickers read a live session's choices).
|
|
319
352
|
const liveOwnerBackend = (current) => {
|
|
320
353
|
const entry = backends.get(JSON.stringify({ profileId: current.profileId || 'default', ownerWrites: true }))
|
|
321
|
-
return entry && entry.fingerprint ===
|
|
354
|
+
return entry && entry.fingerprint === fingerprintOf(current) ? entry.backend : null
|
|
322
355
|
}
|
|
323
356
|
// Server shutdown: stop agent processes (src/server/app.js stopChildren).
|
|
324
357
|
router.close = () => {
|
|
@@ -395,6 +428,8 @@ export function agentRouter({
|
|
|
395
428
|
const runs = new Map()
|
|
396
429
|
const selecting = new Set()
|
|
397
430
|
let connectionTesting = () => false
|
|
431
|
+
// { id } while a connection test runs, else null (settings-routes.js).
|
|
432
|
+
let connectionTest = () => null
|
|
398
433
|
// Keep controls privileged for the lifetime of an owner thread/session,
|
|
399
434
|
// including an idle ACP process. A tokenless turn cannot reset its memory.
|
|
400
435
|
const ownerThreads = new Set()
|
|
@@ -493,7 +528,7 @@ export function agentRouter({
|
|
|
493
528
|
.find(Boolean)
|
|
494
529
|
?.slice(0, 72) || ''
|
|
495
530
|
const message = comment
|
|
496
|
-
? `Fix comment #${commentId}: ${firstLine(comment
|
|
531
|
+
? `Fix comment #${commentId}: ${firstLine(commentText(comment)) || 'agent change'}\n\n${commentLink(config, boardUrlFor(config, { env }), board.id, comment)}\n\nshapewall:${board.id}/${commentId}\n`
|
|
497
532
|
: `Agent change from chat: ${firstLine(userText) || threadId}\n\nshapewall:${board.id}/${threadId}\n`
|
|
498
533
|
let commit = null
|
|
499
534
|
try {
|
|
@@ -862,6 +897,7 @@ export function agentRouter({
|
|
|
862
897
|
requestedPages,
|
|
863
898
|
// Branch mode: the agent's cwd, file sandbox and commands are the worktree.
|
|
864
899
|
workdir: work ? worktreeWorkdir(work) : null,
|
|
900
|
+
agentName: current.label || null,
|
|
865
901
|
})
|
|
866
902
|
health.record(current, reply)
|
|
867
903
|
// What the profile offers, as this turn's session saw it; a turn that
|
|
@@ -1194,8 +1230,32 @@ export function agentRouter({
|
|
|
1194
1230
|
|
|
1195
1231
|
// ---- Everything else: small bodies only ------------------------------------
|
|
1196
1232
|
|
|
1233
|
+
// An uploaded agent icon (settings-routes.js POST /identity/icon) is a
|
|
1234
|
+
// 256 by 256 PNG in base64: larger than the small bodies below. Only a
|
|
1235
|
+
// request with the owner's settings token gets the larger parser.
|
|
1236
|
+
router.post('/settings/identity/icon', (req, res, next) =>
|
|
1237
|
+
settingsTokenOk(req, settingsToken) ? express.json({ limit: ICON_BODY_LIMIT })(req, res, next) : next(),
|
|
1238
|
+
)
|
|
1197
1239
|
router.use(express.json({ limit: SMALL_BODY_LIMIT }))
|
|
1198
1240
|
|
|
1241
|
+
// An icon the owner uploaded for one of this project's agents
|
|
1242
|
+
// (icon-store.js), for everyone who can see the board: the agent info they
|
|
1243
|
+
// get names it by its content hash ("upload:<hash>"). Always a PNG this
|
|
1244
|
+
// server encoded itself, served as nothing but an image. A hash no agent
|
|
1245
|
+
// of this project uses is a 404, so the folder cannot be browsed.
|
|
1246
|
+
router.get('/icons/:hash', (req, res) => {
|
|
1247
|
+
const hash = String(req.params.hash)
|
|
1248
|
+
const used = uploadHashes(userAgentEntry(config.dir, env).entry)
|
|
1249
|
+
const png = used.has(hash) ? readIcon(hash, env) : null
|
|
1250
|
+
if (!png) return res.status(404).json({ error: { code: 'unknown_icon', message: 'No such agent icon.' } })
|
|
1251
|
+
// The name is the hash of the bytes: it never changes under one URL.
|
|
1252
|
+
res.setHeader('Cache-Control', 'private, max-age=31536000, immutable')
|
|
1253
|
+
res.setHeader('Content-Security-Policy', "default-src 'none'; sandbox")
|
|
1254
|
+
res.setHeader('Cross-Origin-Resource-Policy', 'same-origin')
|
|
1255
|
+
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
1256
|
+
res.type('png').send(png)
|
|
1257
|
+
})
|
|
1258
|
+
|
|
1199
1259
|
// The agent settings changed (here, in another tab, or in the file): a
|
|
1200
1260
|
// nudge only, no settings in it; each view refetches what it shows.
|
|
1201
1261
|
// The owner only (the settings token in its header, a paired device or the
|
|
@@ -1275,6 +1335,7 @@ export function agentRouter({
|
|
|
1275
1335
|
},
|
|
1276
1336
|
})
|
|
1277
1337
|
connectionTesting = settingsApi.isTesting
|
|
1338
|
+
connectionTest = settingsApi.testing
|
|
1278
1339
|
router.use('/settings', settingsApi)
|
|
1279
1340
|
router.get(
|
|
1280
1341
|
'/boards/:id/threads',
|
package/src/agent/run.js
CHANGED
|
@@ -117,6 +117,8 @@ export async function runTurn({
|
|
|
117
117
|
choices = null,
|
|
118
118
|
// Agent branch mode: the folder this turn's agent works in (acp.js stream).
|
|
119
119
|
workdir = null,
|
|
120
|
+
// What the owner called this agent (identity.js): the author of its replies.
|
|
121
|
+
agentName = null,
|
|
120
122
|
}) {
|
|
121
123
|
const thread = `${board.id}/${threadId}`
|
|
122
124
|
const runMs = backend.runMsMax || RUN_MS_MAX
|
|
@@ -279,7 +281,7 @@ export async function runTurn({
|
|
|
279
281
|
for (const call of calls) {
|
|
280
282
|
const id = call.id || newId('call')
|
|
281
283
|
card({ id, kind: 'tool', name: call.name, label: call.name, state: 'running', detail: null })
|
|
282
|
-
const result = await runTool({ config, board, ownerWrites, allowCapture, capture, requestedPages }, call)
|
|
284
|
+
const result = await runTool({ config, board, ownerWrites, allowCapture, capture, requestedPages, agentName }, call)
|
|
283
285
|
card({ id, label: result.label, state: result.ok ? 'done' : 'error', detail: result.detail })
|
|
284
286
|
if (result.ok) noteRefs(call.args)
|
|
285
287
|
conversation.push({ role: 'tool', toolCallId: id, content: [{ type: 'text', text: result.text }] })
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
// POST /api/agent/settings/profiles/:id/default make a connected agent (or "endpoint": the saved
|
|
13
13
|
// OpenAI-compatible endpoint) the one new chats and fixes use
|
|
14
14
|
// DELETE /api/agent/settings/profiles/:id remove a connected agent
|
|
15
|
+
// POST /api/agent/settings/identity { id, name?, icon?, tint? } what an agent is called and how
|
|
16
|
+
// it looks (identity.js). `id`: a connected agent, "endpoint", or
|
|
17
|
+
// "default" (the agent a flag or the environment fixes). Display only:
|
|
18
|
+
// no confirmation, no restart, no test, also while it answers
|
|
19
|
+
// POST /api/agent/settings/identity/icon { id, png } an uploaded icon (icon-store.js)
|
|
15
20
|
//
|
|
16
21
|
// These are the server owner's settings: which agent runs on their machine
|
|
17
22
|
// and where their API key goes. Looking local is not enough (a proxy or TCP
|
|
@@ -50,9 +55,12 @@ import { legacyProfile, profileForDefault, projectKey, saveUserAgentEntry, userA
|
|
|
50
55
|
import { DEFAULT_BRANCH_PREFIX, branchModeSettings, cleanBranchPrefix, repoFilters } from './branch-mode.js'
|
|
51
56
|
import { batchFixSettings, cleanBatchFixes } from './batch-fixes.js'
|
|
52
57
|
import { tokenEquals } from '../tokens.js'
|
|
58
|
+
import { cleanAgentName, identityOf, isAgentIcon, isAgentTint, isBuiltInIcon } from './identity.js'
|
|
59
|
+
import { IconError, pruneIcons, saveIcon } from './icon-store.js'
|
|
60
|
+
import { logoForAgent } from './agent-logos.js'
|
|
61
|
+
import { ACP_TEST_TIMEOUT_MS } from './test-timing.js'
|
|
53
62
|
|
|
54
63
|
const TEST_TIMEOUT_MS = 15000
|
|
55
|
-
const ACP_TEST_TIMEOUT_MS = 30000
|
|
56
64
|
const VISION_PROBE_MS = 3000
|
|
57
65
|
const LOOPBACK_NAMES = new Set(['127.0.0.1', 'localhost', '[::1]', '::1'])
|
|
58
66
|
// Any of these means a proxy or tunnel stands between the person and us.
|
|
@@ -356,6 +364,9 @@ export function settingsRoutes({
|
|
|
356
364
|
})
|
|
357
365
|
const repo = () => config.agent || {}
|
|
358
366
|
let testing = false
|
|
367
|
+
// Which agent the running test is of: a profile id, or "default" (the
|
|
368
|
+
// default connection). Shown as that agent's state ("Testing the connection").
|
|
369
|
+
let testingId = null
|
|
359
370
|
let closing = false
|
|
360
371
|
const pending = new Set()
|
|
361
372
|
router.close = async () => {
|
|
@@ -364,6 +375,15 @@ export function settingsRoutes({
|
|
|
364
375
|
}
|
|
365
376
|
// Shared admission lock: a handshake must not overlap live turns or profile changes.
|
|
366
377
|
router.isTesting = () => testing
|
|
378
|
+
// { id } while a test runs, else null (routes.js: the agent's state).
|
|
379
|
+
router.testing = () => (testing ? { id: testingId } : null)
|
|
380
|
+
// A test started or ended: every open view hears it, also the ones that
|
|
381
|
+
// did not start it (a reloaded page, another tab).
|
|
382
|
+
const setTesting = (on, id = null) => {
|
|
383
|
+
testing = on
|
|
384
|
+
testingId = on ? id || 'default' : null
|
|
385
|
+
events?.changed('state')
|
|
386
|
+
}
|
|
367
387
|
|
|
368
388
|
const guard = (req, res, next) => {
|
|
369
389
|
if (closing) return fail(res, 503, 'settings_stopping', 'Agent settings are stopping.')
|
|
@@ -378,6 +398,145 @@ export function settingsRoutes({
|
|
|
378
398
|
next()
|
|
379
399
|
}
|
|
380
400
|
|
|
401
|
+
// ---- What an agent is called and how it looks (identity.js) ----------------
|
|
402
|
+
//
|
|
403
|
+
// Registered before the admission step below on purpose: a name, an icon
|
|
404
|
+
// and a tint change nothing an agent runs with, so saving them never waits
|
|
405
|
+
// for a turn to end, never stops an agent process and never runs a test.
|
|
406
|
+
// A flag or environment command does not block them either: it fixes the
|
|
407
|
+
// command, not what the board calls it.
|
|
408
|
+
|
|
409
|
+
// The saved place `id` names: { entry, target, known } with `target` the
|
|
410
|
+
// object inside `entry` that holds its label, icon and tint, and `known`
|
|
411
|
+
// the built-in name an empty name falls back to (null: the name is needed).
|
|
412
|
+
const identityTarget = (id, current) => {
|
|
413
|
+
const entry = { ...current, profiles: (current.profiles || []).map((item) => ({ ...item })) }
|
|
414
|
+
const source = settings().sources?.acpCommand
|
|
415
|
+
const fixed = source === 'flag' || source === 'env'
|
|
416
|
+
const legacy = legacyProfile(current, KNOWN_AGENTS)
|
|
417
|
+
const builtIn = (profileId) => KNOWN_AGENTS.find((item) => item.id === profileId)?.label || null
|
|
418
|
+
if (id === 'default') {
|
|
419
|
+
if (fixed) {
|
|
420
|
+
entry.fixedAgent = { ...(current.fixedAgent || {}) }
|
|
421
|
+
return { entry, target: entry.fixedAgent, known: true }
|
|
422
|
+
}
|
|
423
|
+
const running = profileForDefault(current) || legacy
|
|
424
|
+
if (running) return identityTarget(running.id, current)
|
|
425
|
+
return endpointOf(current) ? identityTarget('endpoint', current) : null
|
|
426
|
+
}
|
|
427
|
+
if (id === 'endpoint') return endpointOf(current) ? { entry, target: entry, known: true } : null
|
|
428
|
+
// A default command saved before profiles becomes a profile, as on Connect.
|
|
429
|
+
if (legacy?.id === id) entry.profiles = [{ ...legacy }, ...entry.profiles]
|
|
430
|
+
const profile = entry.profiles.find((item) => item.id === id)
|
|
431
|
+
return profile ? { entry, target: profile, known: builtIn(id) } : null
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// `current` with { name, icon, tint } (only the keys given) applied to the
|
|
435
|
+
// agent `id`: { entry }, or { status, code, message } when it is refused.
|
|
436
|
+
const withIdentity = (current, id, change) => {
|
|
437
|
+
const found = identityTarget(id, current)
|
|
438
|
+
if (!found) return { status: 404, code: 'unknown_profile', message: 'That agent is not connected.' }
|
|
439
|
+
const { entry, target } = found
|
|
440
|
+
if (Object.hasOwn(change, 'name')) {
|
|
441
|
+
const { name, problem } = cleanAgentName(change.name)
|
|
442
|
+
if (problem) return { status: 400, code: 'invalid_name', message: problem }
|
|
443
|
+
if (name) target.label = name
|
|
444
|
+
else if (found.known === true) delete target.label
|
|
445
|
+
else if (found.known) target.label = found.known
|
|
446
|
+
else return { status: 400, code: 'invalid_name', message: 'name: 1 to 40 characters' }
|
|
447
|
+
}
|
|
448
|
+
if (Object.hasOwn(change, 'icon')) {
|
|
449
|
+
if (change.icon === null || change.icon === '') delete target.icon
|
|
450
|
+
else if (isAgentIcon(change.icon)) target.icon = change.icon
|
|
451
|
+
else return { status: 400, code: 'invalid_icon', message: 'icon: one of the built-in icons, or null for none.' }
|
|
452
|
+
}
|
|
453
|
+
if (Object.hasOwn(change, 'tint')) {
|
|
454
|
+
if (change.tint === null || change.tint === '') delete target.tint
|
|
455
|
+
else if (isAgentTint(change.tint)) target.tint = change.tint
|
|
456
|
+
else return { status: 400, code: 'invalid_tint', message: 'tint: one of the accent colours, or null for none.' }
|
|
457
|
+
}
|
|
458
|
+
if (entry.fixedAgent && !Object.keys(entry.fixedAgent).length) delete entry.fixedAgent
|
|
459
|
+
if (!entry.profiles.length) delete entry.profiles
|
|
460
|
+
delete entry.updatedAt
|
|
461
|
+
return { entry }
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// A one-click Connect saves the agent and then tests it, which with a real
|
|
465
|
+
// agent takes seconds, and puts the old settings back when the test fails.
|
|
466
|
+
// A name or an icon saved in that window must not be lost or refused:
|
|
467
|
+
// - for the agent being connected, the save waits for the test (the person
|
|
468
|
+
// sees "Saving when the connection test finishes..."), then is applied to
|
|
469
|
+
// the connected agent, or answers that it did not connect;
|
|
470
|
+
// - for any other agent it is saved at once, and remembered (`renamed`) so
|
|
471
|
+
// that a failed test, which writes the old settings back, applies it again.
|
|
472
|
+
// `connecting`: { id, done, renamed } while such a test runs, else null.
|
|
473
|
+
let connecting = null
|
|
474
|
+
const underTest = (id) => {
|
|
475
|
+
if (!connecting || typeof id !== 'string') return false
|
|
476
|
+
const found = identityTarget(id, userAgentEntry(config.dir, env).entry || {})
|
|
477
|
+
return found?.target?.id === connecting.id
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Saves the change for `id`. Returns true when saved; otherwise it answered.
|
|
481
|
+
const saveIdentity = async (req, res, id, change) => {
|
|
482
|
+
if (typeof id !== 'string' || !id) return fail(res, 400, 'invalid_identity', 'id: a connected agent, "endpoint" or "default".')
|
|
483
|
+
const waited = underTest(id) ? connecting : null
|
|
484
|
+
if (waited) await waited.done
|
|
485
|
+
const saved = userAgentEntry(config.dir, env)
|
|
486
|
+
if (saved.problem) return fail(res, 409, 'settings_file_invalid', saved.problem)
|
|
487
|
+
const next = withIdentity(saved.entry || {}, id, change)
|
|
488
|
+
if (!next.entry) {
|
|
489
|
+
// The agent it was for did not connect: said in those words.
|
|
490
|
+
if (waited && next.status === 404)
|
|
491
|
+
return fail(res, 409, 'agent_not_connected', `${waited.label} did not connect, so there is nothing to rename. Nothing was changed.`)
|
|
492
|
+
return fail(res, next.status, next.code, next.message)
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
// No reload(): the agents keep running; the name is read fresh wherever it is shown.
|
|
496
|
+
saveUserAgentEntry(config.dir, next.entry, env)
|
|
497
|
+
if (connecting) connecting.renamed.push({ id, change })
|
|
498
|
+
pruneIcons(env)
|
|
499
|
+
} catch (error) {
|
|
500
|
+
return fail(res, 500, 'settings_not_saved', `The settings were not saved: ${error.message}`)
|
|
501
|
+
}
|
|
502
|
+
return true
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
router.post('/identity', guard, async (req, res) => {
|
|
506
|
+
const body = req.body && typeof req.body === 'object' && !Array.isArray(req.body) ? req.body : {}
|
|
507
|
+
const change = Object.fromEntries(['name', 'icon', 'tint'].filter((key) => Object.hasOwn(body, key)).map((key) => [key, body[key]]))
|
|
508
|
+
// An uploaded icon is set by the upload itself, never named from outside.
|
|
509
|
+
if (typeof change.icon === 'string' && !isBuiltInIcon(change.icon))
|
|
510
|
+
return fail(res, 400, 'invalid_icon', 'icon: one of the built-in icons, or null for none.')
|
|
511
|
+
if ((await saveIdentity(req, res, body.id, change)) === true) res.json(view())
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
router.post('/identity/icon', guard, async (req, res) => {
|
|
515
|
+
const body = req.body && typeof req.body === 'object' && !Array.isArray(req.body) ? req.body : {}
|
|
516
|
+
// The agent is being connected: wait here, before the picture is stored
|
|
517
|
+
// (a file no agent uses yet would be cleaned up by another save).
|
|
518
|
+
const waited = underTest(body.id) ? connecting : null
|
|
519
|
+
if (waited) await waited.done
|
|
520
|
+
// Is the agent there? Before anything is stored.
|
|
521
|
+
const saved = userAgentEntry(config.dir, env)
|
|
522
|
+
if (saved.problem) return fail(res, 409, 'settings_file_invalid', saved.problem)
|
|
523
|
+
if (typeof body.id !== 'string' || !identityTarget(body.id, saved.entry || {})) {
|
|
524
|
+
if (waited)
|
|
525
|
+
return fail(res, 409, 'agent_not_connected', `${waited.label} did not connect, so its icon was not saved. Nothing was changed.`)
|
|
526
|
+
return fail(res, 404, 'unknown_profile', 'That agent is not connected.')
|
|
527
|
+
}
|
|
528
|
+
let hash
|
|
529
|
+
try {
|
|
530
|
+
hash = saveIcon(body.png, env)
|
|
531
|
+
} catch (error) {
|
|
532
|
+
if (error instanceof IconError) return fail(res, error.status, error.code, error.message)
|
|
533
|
+
return fail(res, 500, 'settings_not_saved', `The icon was not saved: ${error.message}`)
|
|
534
|
+
}
|
|
535
|
+
if ((await saveIdentity(req, res, body.id, { icon: `upload:${hash}` })) === true) res.json(view())
|
|
536
|
+
// Not saved after all: the file just written is not left behind.
|
|
537
|
+
else pruneIcons(env)
|
|
538
|
+
})
|
|
539
|
+
|
|
381
540
|
router.use(async (req, res, next) => {
|
|
382
541
|
if (['GET', 'HEAD', 'OPTIONS'].includes(req.method)) return next()
|
|
383
542
|
// Authorize before taking admission so an outsider cannot block turns.
|
|
@@ -433,7 +592,12 @@ export function settingsRoutes({
|
|
|
433
592
|
})
|
|
434
593
|
|
|
435
594
|
// How an agent is doing (agent-health.js): { state, loginHint }.
|
|
436
|
-
|
|
595
|
+
// While its connection test runs an agent's state is "testing", not what
|
|
596
|
+
// the last turn left ("Ready"): the page must not look finished.
|
|
597
|
+
const statusOf = (profileId) => {
|
|
598
|
+
const status = health ? health.status(settings(profileId), processPool) : {}
|
|
599
|
+
return testing && testingId === (profileId || 'default') ? { ...status, state: 'testing' } : status
|
|
600
|
+
}
|
|
437
601
|
const profileList = (entry) => {
|
|
438
602
|
const legacy = legacyProfile(entry, KNOWN_AGENTS)
|
|
439
603
|
// Profiles saved without a default connection: the first one (config.js agentSettings).
|
|
@@ -442,6 +606,8 @@ export function settingsRoutes({
|
|
|
442
606
|
...profile,
|
|
443
607
|
command: acpCommand,
|
|
444
608
|
default: (entry?.backend === 'acp' && entry.acpCommand === acpCommand) || profile.id === fallback,
|
|
609
|
+
// Its default icon: a known agent's product mark (agent-logos.js), or null.
|
|
610
|
+
logo: settings(profile.legacy ? null : profile.id).logo || null,
|
|
445
611
|
// A legacy command runs as the default connection.
|
|
446
612
|
...statusOf(profile.legacy ? null : profile.id),
|
|
447
613
|
}))
|
|
@@ -455,6 +621,7 @@ export function settingsRoutes({
|
|
|
455
621
|
const isDefault = backend === 'openai-compatible' && !settings().defaultProfile
|
|
456
622
|
return {
|
|
457
623
|
label: entry.label || repo().label || model,
|
|
624
|
+
...identityOf(entry),
|
|
458
625
|
model,
|
|
459
626
|
host: hostOf(baseUrl),
|
|
460
627
|
default: isDefault,
|
|
@@ -482,6 +649,10 @@ export function settingsRoutes({
|
|
|
482
649
|
configured: current.configured,
|
|
483
650
|
problem: current.problem,
|
|
484
651
|
label: current.label,
|
|
652
|
+
icon: current.icon || null,
|
|
653
|
+
tint: current.tint || null,
|
|
654
|
+
logo: current.logo || null,
|
|
655
|
+
builtInLabel: current.builtInLabel || null,
|
|
485
656
|
baseUrl: current.baseUrl,
|
|
486
657
|
model: current.model,
|
|
487
658
|
host: current.host,
|
|
@@ -504,7 +675,12 @@ export function settingsRoutes({
|
|
|
504
675
|
// one-click Connect in an unconnected chat panel.
|
|
505
676
|
detected: detectAgents(env),
|
|
506
677
|
// Every agent Shapewall knows how to run, found or not (the console's Agents page).
|
|
507
|
-
known: KNOWN_AGENTS.map(({ id, label, adapter, cli, install }) => ({ id, label, adapter, cli, install })),
|
|
678
|
+
known: KNOWN_AGENTS.map(({ id, label, adapter, cli, install }) => ({ id, label, adapter, cli, install, logo: logoForAgent(id) })),
|
|
679
|
+
// Icons can be uploaded here (the demo has only the built-in ones).
|
|
680
|
+
iconUpload: true,
|
|
681
|
+
// { id } while a connection test runs (a Connect, or Test connection):
|
|
682
|
+
// the other changes of this page wait for it.
|
|
683
|
+
testing: testing ? { id: testingId } : null,
|
|
508
684
|
knownKeyHosts: [...KNOWN_KEY_HOSTS],
|
|
509
685
|
defaultKeyVar: DEFAULT_KEY_VAR,
|
|
510
686
|
keyVarsSet: keyVarsSet(env),
|
|
@@ -571,16 +747,27 @@ export function settingsRoutes({
|
|
|
571
747
|
return fail(res, 400, 'invalid_settings', 'The settings must be an object.')
|
|
572
748
|
// Old clients save only the default connection. Keep their saved profiles.
|
|
573
749
|
const preserved = input && !Object.hasOwn(input, 'profiles') ? userAgentEntry(config.dir, env).entry?.profiles : undefined
|
|
574
|
-
// Branch mode
|
|
575
|
-
// /batch-fixes): a save of the connection keeps them.
|
|
750
|
+
// Branch mode, batch fixes and the icons have their own routes
|
|
751
|
+
// (/branch-mode, /batch-fixes, /identity): a save of the connection keeps them.
|
|
576
752
|
const savedEntry = userAgentEntry(config.dir, env).entry || {}
|
|
577
753
|
const branch = Object.fromEntries(
|
|
578
|
-
['branchMode', 'branchPrefix', 'batchFixes']
|
|
754
|
+
['branchMode', 'branchPrefix', 'batchFixes', 'icon', 'tint', 'fixedAgent']
|
|
579
755
|
.filter((key) => !Object.hasOwn(input, key) && savedEntry[key] !== undefined)
|
|
580
756
|
.map((key) => [key, savedEntry[key]]),
|
|
581
757
|
)
|
|
582
758
|
const { entry, problems } = validateUserEntry({ ...input, ...(preserved ? { profiles: preserved } : {}), ...branch })
|
|
583
759
|
if (!entry) return fail(res, 400, 'invalid_settings', problems.join('; '))
|
|
760
|
+
// The form's name field names the agent it saves. When that is a
|
|
761
|
+
// connected agent (the default command is one of the profiles), the name
|
|
762
|
+
// belongs to that agent, the same one the Agents page's Edit changes.
|
|
763
|
+
const named = Object.hasOwn(input, 'label') ? profileForDefault(entry) : null
|
|
764
|
+
if (named) {
|
|
765
|
+
const { name, problem } = cleanAgentName(input.label)
|
|
766
|
+
if (problem) return fail(res, 400, 'invalid_settings', problem.replace(/^name/, 'label'))
|
|
767
|
+
const builtIn = KNOWN_AGENTS.find((item) => item.id === named.id)?.label
|
|
768
|
+
entry.profiles = entry.profiles.map((item) => (item.id === named.id ? { ...item, label: name || builtIn || item.label } : item))
|
|
769
|
+
delete entry.label
|
|
770
|
+
}
|
|
584
771
|
// A Connect is testing what it saved and may put the old settings back:
|
|
585
772
|
// a save now would be lost.
|
|
586
773
|
if (testing) return fail(res, 409, 'test_running', 'A connection test is running. Wait for it, then save.')
|
|
@@ -612,6 +799,21 @@ export function settingsRoutes({
|
|
|
612
799
|
`The agent command comes from ${source === 'flag' ? '--agent-acp' : 'SHAPEWALL_AGENT_ACP'}, which wins over the board. Change it there, or restart shapewall serve without it.`,
|
|
613
800
|
)
|
|
614
801
|
}
|
|
802
|
+
// What the owner calls it, from the confirmation's Name field (empty:
|
|
803
|
+
// its built-in name), and optionally a built-in icon and a tint. An
|
|
804
|
+
// uploaded icon comes after the agent is connected (POST /identity/icon).
|
|
805
|
+
const { name, problem } = cleanAgentName(req.body?.name)
|
|
806
|
+
if (problem) return fail(res, 400, 'invalid_name', problem)
|
|
807
|
+
const look = {}
|
|
808
|
+
if (req.body?.icon) {
|
|
809
|
+
if (!isBuiltInIcon(req.body.icon)) return fail(res, 400, 'invalid_icon', 'icon: one of the built-in icons.')
|
|
810
|
+
look.icon = req.body.icon
|
|
811
|
+
}
|
|
812
|
+
if (req.body?.tint) {
|
|
813
|
+
if (!isAgentTint(req.body.tint)) return fail(res, 400, 'invalid_tint', 'tint: one of the accent colours.')
|
|
814
|
+
look.tint = req.body.tint
|
|
815
|
+
}
|
|
816
|
+
const called = (profileConnect && name) || agent.label
|
|
615
817
|
const before = userAgentEntry(config.dir, env)
|
|
616
818
|
// The label and the image toggle belong to the agent connected before.
|
|
617
819
|
const entry = { ...(before.entry || {}) }
|
|
@@ -622,7 +824,7 @@ export function settingsRoutes({
|
|
|
622
824
|
entry.profiles = [
|
|
623
825
|
...(legacy && legacy.id !== agent.id ? [legacy] : []),
|
|
624
826
|
...(entry.profiles || []).filter((item) => item.id !== agent.id),
|
|
625
|
-
{ id: agent.id, label:
|
|
827
|
+
{ id: agent.id, label: called, acpCommand: agent.command, ...look },
|
|
626
828
|
]
|
|
627
829
|
}
|
|
628
830
|
if (!profileConnect || !settings().configured) {
|
|
@@ -632,21 +834,38 @@ export function settingsRoutes({
|
|
|
632
834
|
delete entry.vision
|
|
633
835
|
}
|
|
634
836
|
if (!saveEntry(req, res, entry)) return
|
|
635
|
-
|
|
837
|
+
let ended
|
|
838
|
+
const job = { id: agent.id, label: called, renamed: [], done: new Promise((resolve) => (ended = resolve)) }
|
|
839
|
+
// Back to what was there: the panel must not claim an agent that does not
|
|
840
|
+
// start. Names and icons other agents were given meanwhile are kept; one
|
|
841
|
+
// for an agent that is not there any more (this one) is dropped.
|
|
636
842
|
const restore = () => {
|
|
637
843
|
try {
|
|
638
|
-
|
|
844
|
+
let entry = before.entry || {}
|
|
845
|
+
for (const { id, change } of job.renamed) entry = withIdentity(entry, id, change).entry || entry
|
|
846
|
+
saveUserAgentEntry(config.dir, entry, env)
|
|
847
|
+
pruneIcons(env)
|
|
639
848
|
} finally {
|
|
640
849
|
reload()
|
|
641
850
|
}
|
|
642
851
|
}
|
|
643
|
-
|
|
852
|
+
connecting = job
|
|
853
|
+
setTesting(true, profileConnect ? agent.id : 'default')
|
|
854
|
+
// The test is over (after any restore): the saves that waited for it go
|
|
855
|
+
// on, and the answer below already shows the agent as it is, not "testing".
|
|
856
|
+
const over = () => {
|
|
857
|
+
if (connecting !== job) return
|
|
858
|
+
connecting = null
|
|
859
|
+
setTesting(false)
|
|
860
|
+
ended()
|
|
861
|
+
}
|
|
644
862
|
try {
|
|
645
863
|
const tested = settings(profileConnect ? agent.id : null)
|
|
646
864
|
const result = await testConnection(tested, { env, fetchImpl, root: config.dir, processPool })
|
|
647
865
|
health?.record(tested, result)
|
|
648
866
|
if (!result.ok) restore()
|
|
649
|
-
|
|
867
|
+
over()
|
|
868
|
+
res.json({ connected: result.ok, result: { ...result, label: called }, ...view() })
|
|
650
869
|
} catch (error) {
|
|
651
870
|
try {
|
|
652
871
|
restore()
|
|
@@ -655,7 +874,7 @@ export function settingsRoutes({
|
|
|
655
874
|
}
|
|
656
875
|
fail(res, 500, 'test_failed', `The test did not finish: ${redact(error.message)}`)
|
|
657
876
|
} finally {
|
|
658
|
-
|
|
877
|
+
over()
|
|
659
878
|
await res.locals.releaseSettingsOperation?.()
|
|
660
879
|
}
|
|
661
880
|
})
|
|
@@ -776,7 +995,7 @@ export function settingsRoutes({
|
|
|
776
995
|
const profileId = req.body?.profileId ?? null
|
|
777
996
|
if (profileId !== null && !(userAgentEntry(config.dir, env).entry?.profiles || []).some((item) => item.id === profileId))
|
|
778
997
|
return fail(res, 400, 'unknown_profile', 'profileId: one of the connected agents.')
|
|
779
|
-
|
|
998
|
+
setTesting(true, profileId)
|
|
780
999
|
try {
|
|
781
1000
|
const tested = settings(profileId)
|
|
782
1001
|
const result = await testConnection(tested, { env, fetchImpl, root: config.dir, processPool })
|
|
@@ -785,7 +1004,7 @@ export function settingsRoutes({
|
|
|
785
1004
|
} catch (error) {
|
|
786
1005
|
fail(res, 500, 'test_failed', `The test did not finish: ${redact(error.message)}`)
|
|
787
1006
|
} finally {
|
|
788
|
-
|
|
1007
|
+
setTesting(false)
|
|
789
1008
|
await res.locals.releaseSettingsOperation?.()
|
|
790
1009
|
}
|
|
791
1010
|
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// How long a connection test may take, in one place for the server that
|
|
2
|
+
// runs it and the board that waits for it.
|
|
3
|
+
//
|
|
4
|
+
// A one-click Connect (and Test connection) starts the agent and waits for
|
|
5
|
+
// its ACP handshake. The stub used in tests answers at once; a real agent
|
|
6
|
+
// takes several seconds, and up to ACP_TEST_TIMEOUT_MS before the server
|
|
7
|
+
// gives up. While it runs the server takes no chat message and no other
|
|
8
|
+
// settings change, so the board waits rather than showing an error: for a
|
|
9
|
+
// little longer than the test can last (TEST_WAIT_MS).
|
|
10
|
+
//
|
|
11
|
+
// No Node imports: the board imports this file too.
|
|
12
|
+
|
|
13
|
+
export const ACP_TEST_TIMEOUT_MS = 30000
|
|
14
|
+
export const TEST_WAIT_MS = ACP_TEST_TIMEOUT_MS + 15000
|
package/src/agent/tools.js
CHANGED
|
@@ -6,6 +6,7 @@ import fs from 'node:fs'
|
|
|
6
6
|
import { feedbackContext, feedbackItem } from '../feedback.js'
|
|
7
7
|
import { addReply, captureFiles, commentCounts, getComment, listComments, setAgentStatus, updateComment } from '../store.js'
|
|
8
8
|
import { quoteData } from './context.js'
|
|
9
|
+
import { commentText } from '../comment-fields.js'
|
|
9
10
|
|
|
10
11
|
const LIST_MAX = 100
|
|
11
12
|
|
|
@@ -112,7 +113,7 @@ export const BOARD_TOOLS = [
|
|
|
112
113
|
pageId: comment.pageId,
|
|
113
114
|
viewport: comment.viewport,
|
|
114
115
|
status: comment.status,
|
|
115
|
-
body: comment
|
|
116
|
+
body: commentText(comment),
|
|
116
117
|
author: comment.author || null,
|
|
117
118
|
element: comment.anchor?.text || null,
|
|
118
119
|
agentStatus: comment.agentStatus || null,
|
|
@@ -148,8 +149,10 @@ export const OWNER_TOOLS = [
|
|
|
148
149
|
required: ['id', 'body'],
|
|
149
150
|
additionalProperties: false,
|
|
150
151
|
},
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
// Signed with the name the owner gave the agent, and marked as an agent's.
|
|
153
|
+
async run({ config, board, agentName }, args) {
|
|
154
|
+
const signed = agentName ? { author: agentName, agent: true } : { author: 'agent' }
|
|
155
|
+
return (await addReply(config, board.id, args.id, { body: args.body, ...signed })).comment
|
|
153
156
|
},
|
|
154
157
|
},
|
|
155
158
|
{
|