shapewall 0.2.1 → 0.2.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 +22 -0
- package/README.md +4 -12
- package/dist/agent/package-lock.json +2 -2
- package/dist/client/assets/BoardChat-C88k4s-W.js +28 -0
- package/dist/client/assets/BuzzDialog-CZdwIQLF.js +1 -0
- package/dist/client/assets/ChecksPanel-B54chcLA.js +1 -0
- package/dist/client/assets/History-CVVuuxUK.js +1 -0
- package/dist/client/assets/LocalSettings-CvlVtNY_.js +1 -0
- package/dist/client/assets/Management-DOJkFY_o.js +1 -0
- package/dist/client/assets/QuickConnect-D40mj4Ry.js +1 -0
- package/dist/client/assets/ShareDialog-CdVAreaw.js +2 -0
- package/dist/client/assets/app-update-dialog-Dox9-LWv.js +1 -0
- package/dist/client/assets/circle-x-BmT6vHKl.js +1 -0
- package/dist/client/assets/index-CwvFfwU0.js +29 -0
- package/dist/client/assets/index-UIYSPHoh.css +2 -0
- package/dist/client/assets/refresh-cw-ugt3cWKH.js +1 -0
- package/dist/client/assets/square-_KG6tM5A.js +1 -0
- package/dist/client/assets/ui-BAGBTB_P.js +41 -0
- package/dist/client/build-info.json +1 -1
- package/dist/client/index.html +3 -2
- package/dist/client/sw.js +2 -2
- package/dist/console/assets/LocalAccountsApp-4MtW1QlZ.js +1 -0
- package/dist/console/assets/LocalConsole-CgKqYa8i.js +1 -0
- package/dist/console/assets/{app-update-dialog-C5JVG7ck.js → app-update-dialog-S2Yyc7Pw.js} +1 -1
- package/dist/console/assets/console-BPmBRIoz.js +51 -0
- package/dist/console/assets/console-DgVrGRMD.css +2 -0
- package/dist/console/build-info.json +1 -1
- package/dist/console/console.html +2 -2
- package/docs/agents.md +105 -43
- package/docs/deployment.md +1 -2
- package/docs/design-system.md +31 -7
- package/docs/hosted.md +2 -4
- package/package.json +1 -1
- package/src/agent/agent-health.js +75 -0
- package/src/agent/backends/acp.js +217 -41
- package/src/agent/config.js +9 -1
- package/src/agent/options-cache.js +52 -0
- package/src/agent/routes.js +140 -7
- package/src/agent/run.js +20 -1
- package/src/agent/settings-routes.js +75 -8
- package/src/agent/user-settings.js +12 -0
- package/src/server/app.js +1 -0
- package/dist/client/assets/AgentSettings-CEOkftKf.js +0 -1
- package/dist/client/assets/BoardChat-DyD_rQlA.js +0 -30
- package/dist/client/assets/BuzzDialog-DAdMz66r.js +0 -1
- package/dist/client/assets/ChecksPanel-Due6G_M8.js +0 -1
- package/dist/client/assets/History-DxCP1-IS.js +0 -1
- package/dist/client/assets/LocalSettings-BVVleHqg.js +0 -1
- package/dist/client/assets/Management-BkQimoMa.js +0 -1
- package/dist/client/assets/ShareDialog-D9mIRVJ4.js +0 -2
- package/dist/client/assets/app-update-dialog-BNJaXH1v.js +0 -1
- package/dist/client/assets/circle-x-B5smn8Mj.js +0 -1
- package/dist/client/assets/index-BHbxSLS4.js +0 -65
- package/dist/client/assets/index-DqWPr45k.css +0 -2
- package/dist/client/assets/refresh-cw-SqPU2sKl.js +0 -1
- package/dist/client/assets/square-hda22GRT.js +0 -1
- package/dist/console/assets/LocalAccountsApp-Dea93fL3.js +0 -1
- package/dist/console/assets/LocalConsole-D-TJ53EA.js +0 -1
- package/dist/console/assets/console-DybJNLin.css +0 -2
- package/dist/console/assets/console-lpozP2ju.js +0 -51
package/docs/design-system.md
CHANGED
|
@@ -85,7 +85,7 @@ colours meet WCAG AA on `surface` and `surface-2` (7:1 for High contrast), in li
|
|
|
85
85
|
|
|
86
86
|
| Component | Notes |
|
|
87
87
|
| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
-
| `Button` | `variant`: default, secondary, ghost, danger, link, inverse (on a filled chip). `size`: xs, sm, md, touch, icon-xs, icon-sm, icon. `asChild` for links.
|
|
88
|
+
| `Button` | `variant`: default, soft (the primary action at rest: accent text on a light tint, same box as default), secondary, ghost, danger, link, inverse (on a filled chip). `size`: xs, sm, md, touch, icon-xs, icon-sm, icon. `asChild` for links. |
|
|
89
89
|
| `IconButton` | Icon-only `Button` with `label` (its `aria-label`) shown as a tooltip; `tooltip` overrides the tip text. |
|
|
90
90
|
| `Tooltip`, `TooltipProvider` | `<Tooltip content="...">` around any kit control. One provider at the app root. Mouse and keyboard only. |
|
|
91
91
|
| `Select` (+ Trigger, Value, Content, Item, Group, Label, Separator) | A popover list on every screen, never the OS picker. Items cannot be `""`: use `placeholder` with `value=""`, or a sentinel. `SelectTrigger` takes `size` (xs, sm, touch) and `tone` (default, active). |
|
|
@@ -96,7 +96,7 @@ colours meet WCAG AA on `surface` and `surface-2` (7:1 for High contrast), in li
|
|
|
96
96
|
| `Dialog` | `open`, `onClose`, `title`, `description` (one line; `wrapDescription` for a full sentence), `footer`, `size` (sm, md, lg). A bottom sheet on phones, centered from `sm` up. Focuses the first field, or the element marked `data-autofocus`. |
|
|
97
97
|
| `Tabs` (+ List, Trigger, Content) | A choice that swaps the panel below (before/after on phones). `TabsList variant`: segmented (default) or underline (text-width tabs on a hairline, the active one underlined, the row scrolls sideways when it does not fit; every choice inside Checks uses it). |
|
|
98
98
|
| `ToggleGroup` | One value out of a few (`options: [{ id, label, count? }]`); replaces the old `Segmented`. `variant`: segmented (default) or underline, the same two looks as `Tabs`. |
|
|
99
|
-
| `Toggle` | An on/off chip (`pressed`, `onPressedChange`); `variant` outline or
|
|
99
|
+
| `Toggle` | An on/off chip (`pressed`, `onPressedChange`); `variant` outline, pill or flat (a borderless toolbar button, pressed = the selected chip). |
|
|
100
100
|
| `Input`, `Textarea` | `size` xs, sm, touch (16 px text on touch, so iOS does not zoom). `Input` takes an `icon`. |
|
|
101
101
|
| `Badge`, `CommentDot` | Chips and counters: `tone` neutral, accent, ok, warn, bad, solid; `shape` chip, count, tag. |
|
|
102
102
|
| `Kbd`, `Separator`, `Spinner` | Small pieces. |
|
|
@@ -105,18 +105,42 @@ colours meet WCAG AA on `surface` and `surface-2` (7:1 for High contrast), in li
|
|
|
105
105
|
| `Skeleton` | A loading placeholder shaped like what is coming (`className` sets the size). `aria-hidden`; give the screen one `role="status"` label. |
|
|
106
106
|
|
|
107
107
|
Local installations offer **Workspace Console** from the board profile menu, including when no agent is connected or the agent owner key is absent.
|
|
108
|
-
The local Console uses the hosted Console's header, sidebar and card layout with real boards from this installation. Its **
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
The local Console uses the hosted Console's header, sidebar and card layout with real boards from this installation. Its **Agents** section
|
|
109
|
+
holds everything about agents (the Agents card, the connection details and the endpoint form); its **Settings** section covers this
|
|
110
|
+
browser's appearance, installation details and updates. Agent configuration keeps its existing owner permissions; opening Console,
|
|
111
|
+
Agents or General settings does not unlock it. Hosted boards also label their workspace-management link **Workspace Console**. Local Console does
|
|
112
|
+
not create hosted accounts, workspaces or memberships. Inside Console, Projects, Agents and Settings stay in the sidebar; the profile menu
|
|
112
113
|
contains identity and appearance rather than duplicate workspace navigation. The earlier `?settings=general` board link remains supported.
|
|
113
114
|
|
|
115
|
+
The app sidebar (`AppRail`, `components/app-rail.jsx`) is a labelled menu when expanded and a rail of icons when collapsed. Collapsed,
|
|
116
|
+
an icon with more behind it (the board's pages tree, the sections of the workspace or account you are in) opens a flyout beside the
|
|
117
|
+
rail instead of expanding the sidebar: on hover after 150 ms, closing 250 ms after the pointer leaves both the icon and the panel, so
|
|
118
|
+
you can move into it; a click, tap, Enter, Space or ArrowRight opens it pinned and moves focus in. A choice in it, Escape (focus back on
|
|
119
|
+
the icon), a click outside or Tab past its end closes it. It is a non-modal `role="dialog"` named after its icon, the expanded
|
|
120
|
+
sidebar's width, on the Chrome layer (above the canvas and the comment thread, below dialogs and menus). Icons with nothing behind them
|
|
121
|
+
keep their tooltip. Only the panel button and Ctrl/Cmd+B expand the sidebar. The hover timing and height rules are in
|
|
122
|
+
`components/rail-flyout.js`.
|
|
123
|
+
|
|
114
124
|
App-level pieces outside the kit, in `client/src/components/`: `ProfileMenu` (the avatar menu: account items, the console's workspace
|
|
115
125
|
switcher, View as in the demo, Appearance, and About Shapewall and updates) and `DemoBanner` (the demo's "viewing as" strip with Reset; in the console header a chip whose Reset is desktop only, on phones Reset the demo is in the profile menu).
|
|
116
126
|
|
|
117
127
|
Not included on purpose: `Checkbox` and `Switch` (the board has no checkboxes; on/off options are `Toggle`s) and `ScrollArea` (native
|
|
118
128
|
scrolling keeps momentum and `scrollIntoView` on phones).
|
|
119
129
|
|
|
130
|
+
## The board toolbar
|
|
131
|
+
|
|
132
|
+
On desktop the toolbar has three zones, the way canvas tools lay it out. Left, where you are and how you look at it: the board
|
|
133
|
+
switcher, the screen-size toggle, View options and, on a local board, Capture with its status (otherwise the status dot sits by the
|
|
134
|
+
name). Centre, find: the "Go to page or journey" box, centred on the toolbar itself, 240 to 320 px wide. Right, act and open panels:
|
|
135
|
+
the viewer note, Comment (the primary action: `soft` while comment mode is off, filled `default` with `aria-pressed="true"`
|
|
136
|
+
while it is on, agreeing with the comment-mode banner), the Comments, Agent and Checks toggles as one tight group (`Toggle variant="flat"`:
|
|
137
|
+
the open panel's toggle takes the selected chip look, none while the panel is closed), then Agent settings. Zones
|
|
138
|
+
are 20 px apart, controls inside a zone 6 px, with no dividers. When it gets narrow, `client/src/board/toolbarFit.js` drops words in a
|
|
139
|
+
fixed order (search to an icon, the panel toggles, View, then the screen-size toggle to icons with tooltips) and the board name
|
|
140
|
+
truncates a little at each step, never below about 8 characters. Accessible names, shortcuts and tooltips never change.
|
|
141
|
+
`test/toolbar-fit.test.js` checks the order and that nothing overlaps from a 1024 px window with the widest sidebar up. The phone
|
|
142
|
+
toolbar is a separate compact bar. `ToggleGroup` options take a `tooltip` for icon-only labels.
|
|
143
|
+
|
|
120
144
|
## The website
|
|
121
145
|
|
|
122
146
|
`website/` is a separate package and does not import the board's kit. Its `src/components/ui.jsx` uses the same component names and
|
|
@@ -131,7 +155,7 @@ One scale for `z-index`, lowest first. Pick the row that says what the thing is;
|
|
|
131
155
|
| Canvas | `z-10`/`z-20` | Pins, card headers and bars, resize handles, presence cursors. |
|
|
132
156
|
| On canvas | `z-30` | Things that belong to the canvas but float over cards: the comment thread and new-comment box, |
|
|
133
157
|
| | | the journey bar, canvas notes, Try this. |
|
|
134
|
-
| Chrome | `z-40` | Sticky app headers.
|
|
158
|
+
| Chrome | `z-40` | Sticky app headers and the collapsed sidebar's flyouts. |
|
|
135
159
|
| Modal | `z-50` | Dialogs, sheets, the command palette and their dimmed overlay. A modal covers everything below. |
|
|
136
160
|
| Menu | `z-[60]` | Dropdown menus, selects and small popovers, so they work inside a dialog. |
|
|
137
161
|
| Hover | `z-[65]`/`z-[70]` | Hover cards and tooltips. |
|
package/docs/hosted.md
CHANGED
|
@@ -8,9 +8,7 @@ License: the server (`src/hosted`) is under the [Functional Source License 1.1,
|
|
|
8
8
|
You can run it for yourself or your company; you can't offer it as a competing hosted service. Each release becomes Apache 2.0
|
|
9
9
|
two years later. The clients (`push` and the `--remote` commands, in `src/remote`) are Apache 2.0 like the rest of Shapewall.
|
|
10
10
|
|
|
11
|
-
**Status: beta.**
|
|
12
|
-
team on it or real phone passkeys verified, so run it for people you trust and keep backups. A Shapewall-operated service on
|
|
13
|
-
shapewall.com comes later. Start with one
|
|
11
|
+
**Status: beta.** Start with one
|
|
14
12
|
invite-only server that the team reaches over Tailscale. Each teammate signs in with their own Shapewall passkey and joins a workspace.
|
|
15
13
|
Walk through the [checklist before you invite the team](#before-you-invite-the-team) on your own devices and network first.
|
|
16
14
|
|
|
@@ -554,7 +552,7 @@ from the private Compose network. Review network access and secrets before produ
|
|
|
554
552
|
Dockerfile, client and lockfile; a packed npm installation must pass `--source` pointing to one.
|
|
555
553
|
|
|
556
554
|
Use a separate registrable domain for live HTML, not another subdomain of the app's domain. The usercontent Caddy site forwards
|
|
557
|
-
only `/uc/*`, discards incoming Cookie/Authorization and strips Set-Cookie.
|
|
555
|
+
only `/uc/*`, discards incoming Cookie/Authorization and strips Set-Cookie. `--usercontent-origin` /
|
|
558
556
|
`SHAPEWALL_USERCONTENT_ORIGIN` support is required to issue URLs for that site; the template alone does not isolate same-origin HTML.
|
|
559
557
|
Staging stays gated and noindex; the commented Caddy gate example leaves guest routes outside the console gate intentionally.
|
|
560
558
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shapewall",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Every page of your site on one zoomable wall: desktop and phone captures, sandboxed live HTML, and element-anchored comments your coding agent can read.",
|
|
5
5
|
"license": "Apache-2.0 AND FSL-1.1-ALv2",
|
|
6
6
|
"author": "Dan Baruch",
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// How each connected agent is doing, in plain words, for the agent picker
|
|
2
|
+
// and Settings: derived only from what this server already saw (the last
|
|
3
|
+
// turn or connection test, and agent processes starting right now). Nothing
|
|
4
|
+
// polls an agent to find out.
|
|
5
|
+
//
|
|
6
|
+
// ready connected, and the last turn or test went fine (or none yet)
|
|
7
|
+
// login the last turn or test said it is not logged in (agent_auth)
|
|
8
|
+
// starting an agent process for it is starting now
|
|
9
|
+
// not-responding the last turn or test: it did not start, did not answer
|
|
10
|
+
// in time, or stopped
|
|
11
|
+
// unavailable not set up (no command, a removed profile)
|
|
12
|
+
//
|
|
13
|
+
// Kept in memory per server process; a restart starts from "ready".
|
|
14
|
+
|
|
15
|
+
import { loginHint } from './acp/command.js'
|
|
16
|
+
|
|
17
|
+
export const AGENT_STATES = ['ready', 'login', 'starting', 'not-responding', 'unavailable']
|
|
18
|
+
|
|
19
|
+
// One key per thing that runs: the default connection and the profile that
|
|
20
|
+
// runs the same command share what was learned about it.
|
|
21
|
+
export function healthKey(settings) {
|
|
22
|
+
if (!settings) return null
|
|
23
|
+
if (settings.backend === 'acp') return settings.acp?.argv ? `acp:${settings.acp.argv.join('\u0000')}` : null
|
|
24
|
+
return settings.baseUrl ? `api:${settings.baseUrl}|${settings.model || ''}` : null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// What one turn (a stored reply: { status, error }) or connection test
|
|
28
|
+
// ({ ok, code, message }) says: 'ok', 'login', 'not-responding', or null
|
|
29
|
+
// when it says nothing about the agent (stopped by the person, a tool error,
|
|
30
|
+
// a long answer cut at the time limit).
|
|
31
|
+
export function outcomeOf(result) {
|
|
32
|
+
if (!result) return null
|
|
33
|
+
if (result.ok === true) return 'ok'
|
|
34
|
+
const code = result.ok === false ? result.code : result.error?.code
|
|
35
|
+
if (code === 'agent_auth') return 'login'
|
|
36
|
+
if (result.ok === false) return /not (logged|signed) in/i.test(result.message || '') ? 'login' : 'not-responding'
|
|
37
|
+
if (['agent_start', 'agent_exited'].includes(code)) return 'not-responding'
|
|
38
|
+
if (result.status === 'done' && !result.error) return 'ok'
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The state of one agent. `outcome`: the last outcomeOf; `starting`: an
|
|
43
|
+
// agent process for it is starting now.
|
|
44
|
+
export function agentState({ configured, outcome = null, starting = false }) {
|
|
45
|
+
if (!configured) return 'unavailable'
|
|
46
|
+
if (starting) return 'starting'
|
|
47
|
+
if (outcome === 'login') return 'login'
|
|
48
|
+
if (outcome === 'not-responding') return 'not-responding'
|
|
49
|
+
return 'ready'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The store: record(settings, result) after a turn or test, and
|
|
53
|
+
// status(settings, pool) for the fields the board gets:
|
|
54
|
+
// { state, loginHint } (loginHint only for a native agent).
|
|
55
|
+
export function createAgentHealth() {
|
|
56
|
+
const last = new Map()
|
|
57
|
+
return {
|
|
58
|
+
record(settings, result) {
|
|
59
|
+
const key = healthKey(settings)
|
|
60
|
+
const outcome = outcomeOf(result)
|
|
61
|
+
if (key && outcome) last.set(key, outcome)
|
|
62
|
+
},
|
|
63
|
+
outcome(settings) {
|
|
64
|
+
return last.get(healthKey(settings)) || null
|
|
65
|
+
},
|
|
66
|
+
status(settings, processPool = null) {
|
|
67
|
+
const argv = settings?.acp?.argv ? settings.acp.argv.join('\u0000') : null
|
|
68
|
+
const starting = Boolean(
|
|
69
|
+
argv && [...(processPool?.agents || [])].some((agent) => agent.state === 'starting' && (agent.argv || []).join('\u0000') === argv),
|
|
70
|
+
)
|
|
71
|
+
const state = agentState({ configured: Boolean(settings?.configured), outcome: last.get(healthKey(settings)) || null, starting })
|
|
72
|
+
return { state, ...(settings?.backend === 'acp' && settings.acp?.argv ? { loginHint: loginHint(settings.acp.argv) } : {}) }
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -24,7 +24,7 @@ import { randomBytes } from 'node:crypto'
|
|
|
24
24
|
import { spawn } from 'node:child_process'
|
|
25
25
|
import { Readable, Writable } from 'node:stream'
|
|
26
26
|
import { PROTOCOL_VERSION, RequestError, client, ndJsonStream } from '@agentclientprotocol/sdk'
|
|
27
|
-
import { TERMINAL_ENV_ALLOWED, agentEnv, formatCommand, loginHint, terminalEnvRefused } from '../acp/command.js'
|
|
27
|
+
import { TERMINAL_ENV_ALLOWED, acpAgentKind, agentEnv, formatCommand, loginHint, terminalEnvRefused } from '../acp/command.js'
|
|
28
28
|
import { createSandbox, SandboxError } from '../acp/sandbox.js'
|
|
29
29
|
import { ACP_PREAMBLE, NEXT_STEPS_PROMPT, NO_IMAGES_NOTE, quoteData } from '../context.js'
|
|
30
30
|
import { AgentError } from '../errors.js'
|
|
@@ -67,38 +67,115 @@ export function sessionChoices(session) {
|
|
|
67
67
|
return `${name}: ${showable(String(selected?.name || option.currentValue)).slice(0, 120)}`
|
|
68
68
|
})
|
|
69
69
|
}
|
|
70
|
-
// The
|
|
71
|
-
// the agent lists them,
|
|
70
|
+
// The composer's option menus: the session's own select config options as
|
|
71
|
+
// the agent lists them (model, thinking level, mode, then any other), with
|
|
72
|
+
// display text made showable and bounded. Never a credential, path, command
|
|
73
|
+
// or permission setting, and never a mode or value that lets the agent act
|
|
74
|
+
// without asking (bypass, yolo, accept edits, full access, ...): the panel
|
|
75
|
+
// promises that the agent asks before it changes files or runs commands.
|
|
76
|
+
// An agent that reports its modes the older way (session/new `modes`, set
|
|
77
|
+
// with session/set_mode) gets the same "mode" option, id MODE_OPTION_ID.
|
|
72
78
|
const OPTION_VALUES_MAX = 60
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
const OPTIONS_MAX = 5
|
|
80
|
+
export const MODE_OPTION_ID = 'shapewall:mode'
|
|
81
|
+
const CATEGORY_ORDER = ['model', 'thought_level', 'mode']
|
|
82
|
+
const UNSAFE_VALUE_RE =
|
|
83
|
+
/bypass|yolo|danger|full[\s_-]?access|accept[\s_-]?(all|edits?)|\bauto\b|never[\s_-]?ask|no[\s_-]?ask|skip[\s_-]?(perm|approv)|don'?t[\s_-]?ask|trust/i
|
|
84
|
+
const SENSITIVE_OPTION_RE =
|
|
85
|
+
/perm|approv|sandbox|trust|auth|login|key|token|secret|credential|password|env|path|dir|folder|command|shell|mcp|url|host|endpoint|proxy|network/i
|
|
86
|
+
|
|
87
|
+
const optionValues = (list) =>
|
|
88
|
+
(Array.isArray(list) ? list : [])
|
|
89
|
+
.flatMap((item) => (Array.isArray(item?.options) ? item.options : [item]))
|
|
90
|
+
.filter((item) => typeof item?.value === 'string')
|
|
91
|
+
.slice(0, OPTION_VALUES_MAX)
|
|
92
|
+
.map((item) => ({
|
|
93
|
+
value: item.value.slice(0, 200),
|
|
94
|
+
name: showable(String(item.name || item.value)).slice(0, 80),
|
|
95
|
+
...(item.description ? { description: showable(String(item.description)).slice(0, 160) } : {}),
|
|
96
|
+
}))
|
|
97
|
+
|
|
98
|
+
// Only the current value and safe ones of a mode or an uncategorised option.
|
|
99
|
+
const safeValues = (category, values, current) =>
|
|
100
|
+
['model', 'thought_level'].includes(category)
|
|
101
|
+
? values
|
|
102
|
+
: values.filter((item) => item.value === current || !UNSAFE_VALUE_RE.test(`${item.value} ${item.name}`))
|
|
103
|
+
|
|
104
|
+
export function sessionOptions(configOptions, modes = null) {
|
|
105
|
+
const out = (Array.isArray(configOptions) ? configOptions : [])
|
|
75
106
|
.filter(
|
|
76
107
|
(option) =>
|
|
77
|
-
|
|
78
|
-
(option.type === undefined || option.type === 'select') &&
|
|
108
|
+
(option?.type === undefined || option.type === 'select') &&
|
|
79
109
|
typeof option.id === 'string' &&
|
|
80
|
-
typeof option.currentValue === 'string'
|
|
110
|
+
typeof option.currentValue === 'string' &&
|
|
111
|
+
(CATEGORY_ORDER.includes(option.category) || !SENSITIVE_OPTION_RE.test(`${option.id} ${option.name || ''}`)),
|
|
81
112
|
)
|
|
82
|
-
.slice(0, 2)
|
|
83
113
|
.map((option) => {
|
|
84
|
-
const
|
|
85
|
-
.flatMap((item) => (Array.isArray(item?.options) ? item.options : [item]))
|
|
86
|
-
.filter((item) => typeof item?.value === 'string')
|
|
87
|
-
.slice(0, OPTION_VALUES_MAX)
|
|
88
|
-
.map((item) => ({
|
|
89
|
-
value: item.value.slice(0, 200),
|
|
90
|
-
name: showable(String(item.name || item.value)).slice(0, 80),
|
|
91
|
-
...(item.description ? { description: showable(String(item.description)).slice(0, 160) } : {}),
|
|
92
|
-
}))
|
|
114
|
+
const category = CATEGORY_ORDER.includes(option.category) ? option.category : 'other'
|
|
93
115
|
return {
|
|
94
116
|
id: option.id.slice(0, 100),
|
|
95
|
-
category
|
|
96
|
-
name: showable(String(option.name || option.category)).slice(0, 60),
|
|
117
|
+
category,
|
|
118
|
+
name: showable(String(option.name || option.category || option.id)).slice(0, 60),
|
|
119
|
+
...(option.description ? { description: showable(String(option.description)).slice(0, 160) } : {}),
|
|
97
120
|
currentValue: option.currentValue,
|
|
98
|
-
values,
|
|
121
|
+
values: safeValues(category, optionValues(option.options), option.currentValue),
|
|
99
122
|
}
|
|
100
123
|
})
|
|
124
|
+
const available = Array.isArray(modes?.availableModes) ? modes.availableModes : []
|
|
125
|
+
if (!out.some((option) => option.category === 'mode') && typeof modes?.currentModeId === 'string' && available.length) {
|
|
126
|
+
out.push({
|
|
127
|
+
id: MODE_OPTION_ID,
|
|
128
|
+
category: 'mode',
|
|
129
|
+
name: 'Mode',
|
|
130
|
+
currentValue: modes.currentModeId,
|
|
131
|
+
values: safeValues(
|
|
132
|
+
'mode',
|
|
133
|
+
optionValues(available.map((item) => ({ value: item?.id, name: item?.name, description: item?.description }))),
|
|
134
|
+
modes.currentModeId,
|
|
135
|
+
),
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
// One of each of the known kinds (the first the agent lists), in that order, then the rest.
|
|
139
|
+
const rank = (option) => (CATEGORY_ORDER.includes(option.category) ? CATEGORY_ORDER.indexOf(option.category) : CATEGORY_ORDER.length)
|
|
140
|
+
const seen = new Set()
|
|
141
|
+
return out
|
|
101
142
|
.filter((option) => option.values.length > 1)
|
|
143
|
+
.filter((option) => {
|
|
144
|
+
if (option.category === 'other') return true
|
|
145
|
+
if (seen.has(option.category)) return false
|
|
146
|
+
seen.add(option.category)
|
|
147
|
+
return true
|
|
148
|
+
})
|
|
149
|
+
.sort((a, b) => rank(a) - rank(b))
|
|
150
|
+
.slice(0, OPTIONS_MAX)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// What a turn ran with, for the answer's meta line: the model and the
|
|
154
|
+
// thinking level, by their display names.
|
|
155
|
+
export function usedOptions(options) {
|
|
156
|
+
return (options || [])
|
|
157
|
+
.filter((option) => ['model', 'thought_level'].includes(option.category))
|
|
158
|
+
.map((option) => {
|
|
159
|
+
const item = option.values.find((value) => value.value === option.currentValue)
|
|
160
|
+
return {
|
|
161
|
+
category: option.category,
|
|
162
|
+
name: option.name,
|
|
163
|
+
value: item?.name || showable(option.currentValue).slice(0, 80),
|
|
164
|
+
// "Default" models often say which model that is now (the meta line names it).
|
|
165
|
+
...(item?.description && /^default\b/i.test(item.name) ? { description: item.description } : {}),
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// A composer's choices ({ configId: value }) as sent to the server: a few
|
|
171
|
+
// string pairs, bounded; anything else is dropped.
|
|
172
|
+
export function cleanChoices(value) {
|
|
173
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return {}
|
|
174
|
+
const out = {}
|
|
175
|
+
for (const [key, item] of Object.entries(value).slice(0, 8)) {
|
|
176
|
+
if (typeof key === 'string' && key.length <= 100 && typeof item === 'string' && item.length <= 200) out[key] = item
|
|
177
|
+
}
|
|
178
|
+
return out
|
|
102
179
|
}
|
|
103
180
|
const KILL_GRACE_MS = 2000
|
|
104
181
|
const POSIX = process.platform !== 'win32'
|
|
@@ -193,9 +270,13 @@ function stopTree(child) {
|
|
|
193
270
|
return child.treeStopping
|
|
194
271
|
}
|
|
195
272
|
|
|
196
|
-
|
|
273
|
+
// `evict: false` (a session started only to read its options): a full pool
|
|
274
|
+
// is busy, never a reason to stop another thread's session.
|
|
275
|
+
async function reserveProcessSlot(processPool, agent, signal, { evict = true } = {}) {
|
|
197
276
|
if (!processPool) return
|
|
198
277
|
const epoch = processPool.epoch
|
|
278
|
+
if (processPool.agents.size >= processPool.max && !evict)
|
|
279
|
+
throw new AgentError('agent_busy', 'Native agents are busy in other threads. Try again in a moment.', 429)
|
|
199
280
|
if (processPool.agents.size >= processPool.max) {
|
|
200
281
|
const idle = [...processPool.agents].filter((item) => !item.turn && item.state === 'ready').sort((a, b) => a.usedAt - b.usedAt)
|
|
201
282
|
if (![...processPool.agents].some((item) => item.killedFor && item.stoppingPromise)) idle[0]?.kill('evicted')
|
|
@@ -328,11 +409,17 @@ export function modelFailureAnswer(text) {
|
|
|
328
409
|
|
|
329
410
|
// The chat error for an agent that is not logged in, with how to fix it for
|
|
330
411
|
// that agent (from the command: src/agent/acp/command.js loginHint).
|
|
412
|
+
// `login`: the one command that signs that agent in, for the chat's card
|
|
413
|
+
// (copyable), when there is one.
|
|
414
|
+
const LOGIN_COMMANDS = { claude: 'claude auth login', codex: 'codex login', goose: 'goose configure', gemini: 'gemini' }
|
|
331
415
|
export function authError(label, argv) {
|
|
332
|
-
|
|
416
|
+
const error = new AgentError(
|
|
333
417
|
'agent_auth',
|
|
334
418
|
`${label} is not logged in (or not set up) on this machine. To fix it, ${loginHint(argv)}; then send again.`,
|
|
335
419
|
)
|
|
420
|
+
error.login = LOGIN_COMMANDS[acpAgentKind(argv)] || null
|
|
421
|
+
error.label = label
|
|
422
|
+
return error
|
|
336
423
|
}
|
|
337
424
|
|
|
338
425
|
// What the person's turn looks like to the agent: on a new session, the
|
|
@@ -490,6 +577,9 @@ class AcpProcess {
|
|
|
490
577
|
this.sessionId = session.sessionId
|
|
491
578
|
this.choices = sessionChoices(session)
|
|
492
579
|
this.configOptions = Array.isArray(session.configOptions) ? session.configOptions : []
|
|
580
|
+
this.modes = session.modes && typeof session.modes === 'object' ? session.modes : null
|
|
581
|
+
// As the session started, before any chat's choices: what a new chat starts from.
|
|
582
|
+
this.startOptions = sessionOptions(this.configOptions, this.modes)
|
|
493
583
|
this.state = 'ready'
|
|
494
584
|
} catch (error) {
|
|
495
585
|
throw this.startError(error)
|
|
@@ -674,24 +764,61 @@ class AcpProcess {
|
|
|
674
764
|
turn.killTimer.unref?.()
|
|
675
765
|
}
|
|
676
766
|
|
|
677
|
-
// The composer's
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
767
|
+
// The composer's option menus, as sessionOptions lists them.
|
|
768
|
+
options() {
|
|
769
|
+
return sessionOptions(this.configOptions, this.modes)
|
|
770
|
+
}
|
|
771
|
+
// The same menus with the values the session started with (the agent's
|
|
772
|
+
// defaults): what the options cache keeps for the next new chat.
|
|
773
|
+
defaults() {
|
|
774
|
+
const now = this.options()
|
|
775
|
+
const start = new Map((this.startOptions || []).map((option) => [option.id, option.currentValue]))
|
|
776
|
+
return now.map((option) =>
|
|
777
|
+
start.has(option.id) && option.values.some((item) => item.value === start.get(option.id))
|
|
778
|
+
? { ...option, currentValue: start.get(option.id) }
|
|
779
|
+
: option,
|
|
780
|
+
)
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// One of those options to one of the values it lists: a config option
|
|
784
|
+
// through session/set_config_option, the older modes through
|
|
785
|
+
// session/set_mode. Never while a turn runs; never a value sessionOptions
|
|
786
|
+
// leaves out (one that would let the agent act without asking).
|
|
681
787
|
async setOption(configId, value) {
|
|
682
788
|
if (this.state !== 'ready' || this.turn) throw new AgentError('agent_running', 'Wait for the answer to finish before switching.', 409)
|
|
683
|
-
const option =
|
|
789
|
+
const option = this.options().find((item) => item.id === configId)
|
|
684
790
|
if (!option || !option.values.some((item) => item.value === value))
|
|
685
791
|
throw new AgentError('bad_option', 'The agent does not offer that choice.', 400)
|
|
792
|
+
if (option.currentValue === value) return this.options()
|
|
686
793
|
let result
|
|
687
794
|
try {
|
|
688
|
-
result =
|
|
795
|
+
result =
|
|
796
|
+
configId === MODE_OPTION_ID
|
|
797
|
+
? await this.connection.agent.request('session/set_mode', { sessionId: this.sessionId, modeId: value })
|
|
798
|
+
: await this.connection.agent.request('session/set_config_option', { sessionId: this.sessionId, configId, value })
|
|
689
799
|
} catch (error) {
|
|
690
800
|
throw new AgentError('agent_upstream', `${this.label} did not switch (${cut(errorText(error) || 'no answer', 200)}).`, 502)
|
|
691
801
|
}
|
|
692
|
-
if (
|
|
802
|
+
if (configId === MODE_OPTION_ID) this.modes = { ...this.modes, currentModeId: value }
|
|
803
|
+
else if (Array.isArray(result?.configOptions)) this.configOptions = result.configOptions
|
|
693
804
|
else this.configOptions = this.configOptions.map((item) => (item.id === configId ? { ...item, currentValue: value } : item))
|
|
694
|
-
return
|
|
805
|
+
return this.options()
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// The composer's choices for this chat ({ configId: value }), before a
|
|
809
|
+
// turn: each one the session still offers and does not have yet. A choice
|
|
810
|
+
// the agent refuses keeps its own value (logged, never fatal).
|
|
811
|
+
async applyChoices(choices) {
|
|
812
|
+
for (const [configId, value] of Object.entries(choices || {})) {
|
|
813
|
+
if (this.state !== 'ready' || this.turn) return
|
|
814
|
+
const option = this.options().find((item) => item.id === configId)
|
|
815
|
+
if (!option || option.currentValue === value || !option.values.some((item) => item.value === value)) continue
|
|
816
|
+
try {
|
|
817
|
+
await this.setOption(configId, value)
|
|
818
|
+
} catch (error) {
|
|
819
|
+
this.log(`acp: ${this.label} kept its ${option.category} (${error.message})`)
|
|
820
|
+
}
|
|
821
|
+
}
|
|
695
822
|
}
|
|
696
823
|
|
|
697
824
|
// ---- What the agent sends ---------------------------------------------------
|
|
@@ -706,6 +833,11 @@ class AcpProcess {
|
|
|
706
833
|
if (Array.isArray(params.update.configOptions)) this.configOptions = params.update.configOptions
|
|
707
834
|
return
|
|
708
835
|
}
|
|
836
|
+
if (params?.sessionId === this.sessionId && params.update?.sessionUpdate === 'current_mode_update') {
|
|
837
|
+
if (this.modes && typeof params.update.currentModeId === 'string')
|
|
838
|
+
this.modes = { ...this.modes, currentModeId: params.update.currentModeId }
|
|
839
|
+
return
|
|
840
|
+
}
|
|
709
841
|
const turn = this.turn
|
|
710
842
|
if (!turn || turn.cancelled || params?.sessionId !== this.sessionId) return
|
|
711
843
|
const update = params.update || {}
|
|
@@ -1141,15 +1273,21 @@ export function createAcpBackend(
|
|
|
1141
1273
|
const starting = new Set()
|
|
1142
1274
|
let closed = false
|
|
1143
1275
|
|
|
1144
|
-
|
|
1276
|
+
// Sessions started for their options only, while they start: a turn (or
|
|
1277
|
+
// another look) for the same thread waits for that one instead of starting
|
|
1278
|
+
// a second process.
|
|
1279
|
+
const preparing = new Map()
|
|
1280
|
+
|
|
1281
|
+
const evictFor = (evict) => {
|
|
1145
1282
|
if (processes.size + starting.size < limit.processesMax) return
|
|
1146
1283
|
const idle = [...processes.values()].filter((item) => !item.turn && item.state === 'ready').sort((a, b) => a.usedAt - b.usedAt)
|
|
1147
|
-
if (!idle.length
|
|
1284
|
+
if (!idle.length || !evict)
|
|
1285
|
+
throw new AgentError('agent_busy', `${settings.label} is busy in other threads. Try again in a moment.`, 429)
|
|
1148
1286
|
idle[0].kill('evicted')
|
|
1149
1287
|
}
|
|
1150
1288
|
|
|
1151
|
-
const start = async (thread, signal) => {
|
|
1152
|
-
evictFor()
|
|
1289
|
+
const start = async (thread, signal, { evict = true } = {}) => {
|
|
1290
|
+
evictFor(evict)
|
|
1153
1291
|
const agent = new AcpProcess({
|
|
1154
1292
|
argv: settings.acp.argv,
|
|
1155
1293
|
label: settings.label,
|
|
@@ -1165,7 +1303,7 @@ export function createAcpBackend(
|
|
|
1165
1303
|
},
|
|
1166
1304
|
})
|
|
1167
1305
|
if (closed) throw new AgentError('agent_start', 'The server is stopping.')
|
|
1168
|
-
if (processPool) await reserveProcessSlot(processPool, agent, signal)
|
|
1306
|
+
if (processPool) await reserveProcessSlot(processPool, agent, signal, { evict })
|
|
1169
1307
|
if (closed) {
|
|
1170
1308
|
agent.kill('shutdown')
|
|
1171
1309
|
await agent.stoppingPromise
|
|
@@ -1201,27 +1339,38 @@ export function createAcpBackend(
|
|
|
1201
1339
|
vision: settings.vision !== false,
|
|
1202
1340
|
label: settings.label,
|
|
1203
1341
|
runMsMax: limit.runMs,
|
|
1204
|
-
|
|
1342
|
+
// `choices`: the composer's options for this chat ({ configId: value },
|
|
1343
|
+
// owner turns only), applied before the prompt. The turn then reports
|
|
1344
|
+
// the model and thinking level it runs with (the answer's meta line).
|
|
1345
|
+
async *stream({ messages, signal, thread = 'default', choices = null }) {
|
|
1205
1346
|
if (signal?.aborted) return
|
|
1347
|
+
await preparing.get(thread)?.catch(() => {})
|
|
1206
1348
|
let agent = processes.get(thread)
|
|
1207
1349
|
if (agent?.turn) await agent.settled()
|
|
1208
1350
|
agent = processes.get(thread)
|
|
1209
1351
|
if (!agent || agent.state !== 'ready') {
|
|
1210
1352
|
yield { type: 'status', text: `Starting ${settings.label}` }
|
|
1211
1353
|
agent = await start(thread, signal)
|
|
1212
|
-
for (const text of agent.choices) yield { type: 'notice', text }
|
|
1213
1354
|
}
|
|
1214
1355
|
if (signal?.aborted) {
|
|
1215
1356
|
agent.kill('aborted')
|
|
1216
1357
|
await agent.settled()
|
|
1217
1358
|
return
|
|
1218
1359
|
}
|
|
1360
|
+
await agent.applyChoices(choices)
|
|
1361
|
+
const used = usedOptions(agent.options())
|
|
1362
|
+
if (used.length) yield { type: 'options', used }
|
|
1219
1363
|
yield { type: 'status', text: `${settings.label} is working` }
|
|
1220
1364
|
const image = agent.image && settings.vision !== false
|
|
1221
1365
|
if (!image && messages.at(-1)?.content?.some((part) => part.type === 'image')) yield { type: 'notice', text: NO_IMAGES_NOTE }
|
|
1222
1366
|
const turn = agent.prompt(promptBlocks({ messages, fresh: agent.fresh, image, thread }), signal)
|
|
1223
1367
|
try {
|
|
1224
1368
|
for await (const event of turn.events) yield event
|
|
1369
|
+
} catch (error) {
|
|
1370
|
+
// Not signed in: this session stops, so Check again (or the next
|
|
1371
|
+
// message) starts the agent afresh with the new login.
|
|
1372
|
+
if (error?.code === 'agent_auth') agent.kill('signed_out')
|
|
1373
|
+
throw error
|
|
1225
1374
|
} finally {
|
|
1226
1375
|
turn.finish()
|
|
1227
1376
|
await agent.settled()
|
|
@@ -1238,11 +1387,38 @@ export function createAcpBackend(
|
|
|
1238
1387
|
answerPermission(thread, id, optionId, answeredBy = null) {
|
|
1239
1388
|
return processes.get(thread)?.answer(id, optionId, answeredBy) ?? null
|
|
1240
1389
|
},
|
|
1241
|
-
// The composer's
|
|
1242
|
-
//
|
|
1390
|
+
// The composer's option menus, for a thread whose session is running
|
|
1391
|
+
// (they come from session/new). Null without a session.
|
|
1243
1392
|
sessionOptions(thread) {
|
|
1244
1393
|
const agent = processes.get(thread)
|
|
1245
|
-
return agent && agent.state === 'ready' ?
|
|
1394
|
+
return agent && agent.state === 'ready' ? agent.options() : null
|
|
1395
|
+
},
|
|
1396
|
+
// The same, with the values the session started with.
|
|
1397
|
+
sessionDefaults(thread) {
|
|
1398
|
+
const agent = processes.get(thread)
|
|
1399
|
+
return agent && agent.state === 'ready' ? agent.defaults() : null
|
|
1400
|
+
},
|
|
1401
|
+
// The options before the first message: the thread's session, started
|
|
1402
|
+
// the way its first turn would start it (and then reused by that turn),
|
|
1403
|
+
// or the one already running. Never evicts another thread's session; an
|
|
1404
|
+
// unused one stops after `idleMs` like any idle session. `choices` are
|
|
1405
|
+
// applied to it as they would be before a turn.
|
|
1406
|
+
async prepare(thread, { choices = null, signal = null } = {}) {
|
|
1407
|
+
if (closed) throw new AgentError('agent_start', 'The server is stopping.')
|
|
1408
|
+
await preparing.get(thread)?.catch(() => {})
|
|
1409
|
+
let agent = processes.get(thread)
|
|
1410
|
+
if (!agent || agent.state !== 'ready') {
|
|
1411
|
+
const pending = start(thread, signal, { evict: false })
|
|
1412
|
+
preparing.set(thread, pending)
|
|
1413
|
+
try {
|
|
1414
|
+
agent = await pending
|
|
1415
|
+
} finally {
|
|
1416
|
+
if (preparing.get(thread) === pending) preparing.delete(thread)
|
|
1417
|
+
}
|
|
1418
|
+
if (!agent.turn) agent.idle()
|
|
1419
|
+
}
|
|
1420
|
+
if (!agent.turn) await agent.applyChoices(choices)
|
|
1421
|
+
return agent.options()
|
|
1246
1422
|
},
|
|
1247
1423
|
async setSessionOption(thread, configId, value) {
|
|
1248
1424
|
const agent = processes.get(thread)
|
package/src/agent/config.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// thread or an API response.
|
|
11
11
|
|
|
12
12
|
import { ACP_COMMAND_VAR, ACP_FLAG, SETTINGS_SOURCE, acpCommand, extraVarNames } from './acp/command.js'
|
|
13
|
-
import { userAgentEntry } from './user-settings.js'
|
|
13
|
+
import { implicitDefault, userAgentEntry } from './user-settings.js'
|
|
14
14
|
|
|
15
15
|
export const AGENT_BACKENDS = ['openai-compatible', 'acp']
|
|
16
16
|
// A config is usually committed. A command in it would run on the machine of
|
|
@@ -187,6 +187,14 @@ export function agentSettings(config, env = process.env, { acp = null, profileId
|
|
|
187
187
|
saved.problem,
|
|
188
188
|
)
|
|
189
189
|
}
|
|
190
|
+
// Profiles saved without a default connection: the first one is the
|
|
191
|
+
// default, unless the config's own endpoint or an operator command is in effect.
|
|
192
|
+
const first = !acp && !env.SHAPEWALL_AGENT_ACP && !env.SHAPEWALL_AGENT_BASE_URL ? implicitDefault(user) : null
|
|
193
|
+
if (first && !(repo.backend !== 'acp' && repo.baseUrl && repo.model)) {
|
|
194
|
+
const fromProfile = { ...agentSettings(config, env, { acp, profileId: first.id }) }
|
|
195
|
+
delete fromProfile.profileId
|
|
196
|
+
return { ...fromProfile, defaultProfile: first.id, settingsProblem: saved.problem, keyHosts: user.keyHosts || [] }
|
|
197
|
+
}
|
|
190
198
|
const base = { ...repo }
|
|
191
199
|
for (const key of SAVED_KEYS) if (user[key] !== undefined) base[key] = user[key]
|
|
192
200
|
const from = (key, envVar) =>
|