shapewall 0.0.0-stage → 0.2.2
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 +139 -0
- package/Dockerfile.agent +45 -0
- package/LICENSE +202 -0
- package/NOTICE +12 -0
- package/README.md +651 -2
- package/THIRD_PARTY.md +165 -0
- package/bin/shapewall.js +29 -0
- package/dist/agent/package-lock.json +8384 -0
- package/dist/client/assets/BoardChat-D5SFd8HE.js +28 -0
- package/dist/client/assets/BuzzDialog-HWXBy52W.js +1 -0
- package/dist/client/assets/ChecksPanel-DTdImWoD.js +1 -0
- package/dist/client/assets/History-CEv6b-av.js +1 -0
- package/dist/client/assets/LocalSettings-C4vriEVQ.js +1 -0
- package/dist/client/assets/Management-DCfhcEUY.js +1 -0
- package/dist/client/assets/QuickConnect-DQGgUsl1.js +1 -0
- package/dist/client/assets/ShareDialog-C_plIto0.js +2 -0
- package/dist/client/assets/app-update-dialog-2hPz_N9G.js +1 -0
- package/dist/client/assets/circle-x-BZMPi8Zf.js +1 -0
- package/dist/client/assets/index-ByQRKVit.css +2 -0
- package/dist/client/assets/index-DweQ8Qtu.js +29 -0
- package/dist/client/assets/refresh-cw-CRow0Nbq.js +1 -0
- package/dist/client/assets/runtime-Bft6x_6E.js +4 -0
- package/dist/client/assets/square-A8EnIYLR.js +1 -0
- package/dist/client/assets/tts-dist-DYlBQmwG.js +18 -0
- package/dist/client/assets/tts-en-g2p-BPUtBFGG.js +1 -0
- package/dist/client/assets/tts-ort-wasm-simd-threaded-qh98TCA_.wasm +0 -0
- package/dist/client/assets/tts-ort.wasm.bundle.min-rEkcs_ow.js +12 -0
- package/dist/client/assets/tts-rolldown-runtime-D8NudN84.js +1 -0
- package/dist/client/assets/tts-spacy-en-tokenizer-6SNMl--A.json +1 -0
- package/dist/client/assets/tts-tts.worker-Bzm6aWbv.js +1 -0
- package/dist/client/assets/tts-us_gold-DcjeNMH1.json +92589 -0
- package/dist/client/assets/tts-us_silver-C964mEB5.json +93363 -0
- package/dist/client/assets/ui-CLbws0rx.js +41 -0
- package/dist/client/build-info.json +1 -0
- package/dist/client/favicon.svg +7 -0
- package/dist/client/icons/apple-touch-icon.png +0 -0
- package/dist/client/icons/icon-192.png +0 -0
- package/dist/client/icons/icon-512.png +0 -0
- package/dist/client/icons/maskable-512.png +0 -0
- package/dist/client/index.html +25 -0
- package/dist/client/manifest.webmanifest +15 -0
- package/dist/client/sw.js +53 -0
- package/dist/client/theme-boot.js +27 -0
- package/dist/console/assets/LocalAccountsApp-BQCcmj3x.js +1 -0
- package/dist/console/assets/LocalConsole-Bb2FUDs7.js +1 -0
- package/dist/console/assets/app-update-dialog-DIeYepLZ.js +1 -0
- package/dist/console/assets/console-C7uJLLOn.js +51 -0
- package/dist/console/assets/console-R8IBY3Am.css +2 -0
- package/dist/console/build-info.json +1 -0
- package/dist/console/console.html +21 -0
- package/dist/console/favicon.svg +7 -0
- package/dist/console/icons/apple-touch-icon.png +0 -0
- package/dist/console/icons/icon-192.png +0 -0
- package/dist/console/icons/icon-512.png +0 -0
- package/dist/console/icons/maskable-512.png +0 -0
- package/dist/console/manifest.webmanifest +15 -0
- package/dist/console/theme-boot.js +27 -0
- package/docs/agent-hardening.md +342 -0
- package/docs/agent-recipes.md +187 -0
- package/docs/agent-workflow.md +320 -0
- package/docs/agents.md +894 -0
- package/docs/architecture.md +242 -0
- package/docs/buzz.md +140 -0
- package/docs/capture-warnings.md +57 -0
- package/docs/config.md +489 -0
- package/docs/deployment.md +289 -0
- package/docs/design-system.md +162 -0
- package/docs/github.md +107 -0
- package/docs/hosted.md +764 -0
- package/docs/images/board-overview.png +0 -0
- package/docs/images/journeys.png +0 -0
- package/docs/images/live-comment.png +0 -0
- package/docs/images/phone-comment.png +0 -0
- package/docs/images/phone-overview.png +0 -0
- package/docs/images/variant.png +0 -0
- package/docs/interaction-audits.md +40 -0
- package/docs/journeys.md +137 -0
- package/docs/local-accounts.md +80 -0
- package/docs/notifications.md +237 -0
- package/docs/page-checks.md +69 -0
- package/docs/performance.md +174 -0
- package/docs/starter-agent.md +325 -0
- package/docs/updates.md +87 -0
- package/examples/audits/interaction.audit.json +17 -0
- package/package.json +132 -4
- package/src/accounts/avatar.js +121 -0
- package/src/accounts/local.js +464 -0
- package/src/agent/acp/command.js +204 -0
- package/src/agent/acp/detect.js +75 -0
- package/src/agent/acp/sandbox.js +160 -0
- package/src/agent/agent-health.js +75 -0
- package/src/agent/backends/acp.js +1297 -0
- package/src/agent/backends/index.js +61 -0
- package/src/agent/backends/openai.js +308 -0
- package/src/agent/composer.js +221 -0
- package/src/agent/config.js +338 -0
- package/src/agent/context.js +191 -0
- package/src/agent/control.js +122 -0
- package/src/agent/errors.js +17 -0
- package/src/agent/feedback-loop.js +137 -0
- package/src/agent/manage.js +94 -0
- package/src/agent/next-steps.js +51 -0
- package/src/agent/owner-mcp.js +38 -0
- package/src/agent/plain-text.js +52 -0
- package/src/agent/ratings-core.js +213 -0
- package/src/agent/ratings.js +100 -0
- package/src/agent/reply-text.js +67 -0
- package/src/agent/routes.js +1065 -0
- package/src/agent/run.js +326 -0
- package/src/agent/settings-routes.js +704 -0
- package/src/agent/showable.js +23 -0
- package/src/agent/starter/approvals.js +181 -0
- package/src/agent/starter/build-image.js +90 -0
- package/src/agent/starter/cli.js +163 -0
- package/src/agent/starter/disk.js +53 -0
- package/src/agent/starter/doctor.js +180 -0
- package/src/agent/starter/egress-proxy.js +351 -0
- package/src/agent/starter/gate.js +90 -0
- package/src/agent/starter/loop.js +114 -0
- package/src/agent/starter/model-relay.js +289 -0
- package/src/agent/starter/pause.js +14 -0
- package/src/agent/starter/probe.js +272 -0
- package/src/agent/starter/prompt.js +41 -0
- package/src/agent/starter/push-guard.js +146 -0
- package/src/agent/starter/rpc.js +164 -0
- package/src/agent/starter/runtime.js +287 -0
- package/src/agent/starter/sandbox-main.js +121 -0
- package/src/agent/starter/settings.js +290 -0
- package/src/agent/starter/source.js +69 -0
- package/src/agent/starter/supervisor.js +755 -0
- package/src/agent/starter/sweep.js +46 -0
- package/src/agent/starter/tools.js +524 -0
- package/src/agent/starter/watch.js +84 -0
- package/src/agent/starter/worktree.js +409 -0
- package/src/agent/text-diff.js +210 -0
- package/src/agent/thread-history.js +223 -0
- package/src/agent/threads.js +399 -0
- package/src/agent/tools.js +200 -0
- package/src/agent/turn-changes.js +424 -0
- package/src/agent/undo-state.js +26 -0
- package/src/agent/user-settings.js +308 -0
- package/src/auth/record.js +375 -0
- package/src/broken-links.js +164 -0
- package/src/buzz/client.js +75 -0
- package/src/buzz/config.js +151 -0
- package/src/buzz/environment.js +13 -0
- package/src/buzz/gateway.js +192 -0
- package/src/buzz/routes.js +61 -0
- package/src/buzz/signer-child.js +205 -0
- package/src/buzz/store.js +89 -0
- package/src/buzz/transport.js +60 -0
- package/src/buzz/verify.js +140 -0
- package/src/capture/actions.js +159 -0
- package/src/capture/capture.js +776 -0
- package/src/capture/dom-names.js +189 -0
- package/src/capture/element-map.js +509 -0
- package/src/capture/live.js +827 -0
- package/src/capture/media-scheme.js +317 -0
- package/src/capture/network-summary.js +86 -0
- package/src/capture/pacing.js +34 -0
- package/src/capture/requests.js +167 -0
- package/src/capture/sanitize.js +752 -0
- package/src/checks/accessibility.js +134 -0
- package/src/checks/budgets.js +58 -0
- package/src/checks/cli.js +55 -0
- package/src/checks/comparison.js +113 -0
- package/src/checks/environments.js +32 -0
- package/src/checks/flow-config.js +82 -0
- package/src/checks/flow-origin.js +53 -0
- package/src/checks/flows.js +398 -0
- package/src/checks/lighthouse-auth.js +145 -0
- package/src/checks/lighthouse-findings.js +130 -0
- package/src/checks/lighthouse.js +395 -0
- package/src/checks/robots.js +85 -0
- package/src/checks/routes.js +52 -0
- package/src/checks/run-control.js +259 -0
- package/src/checks/runner.js +724 -0
- package/src/checks/schema.js +133 -0
- package/src/checks/seo-analysis.js +443 -0
- package/src/checks/seo-probe.js +190 -0
- package/src/checks/seo-snapshot.js +99 -0
- package/src/checks/store.js +214 -0
- package/src/checks/transport.js +47 -0
- package/src/cli/args.js +319 -0
- package/src/cli/capture.js +79 -0
- package/src/cli/commands.js +92 -0
- package/src/cli/comments.js +84 -0
- package/src/cli/help.js +243 -0
- package/src/cli/init.js +214 -0
- package/src/cli/misc.js +64 -0
- package/src/cli/notify.js +87 -0
- package/src/cli/open.js +22 -0
- package/src/cli/serve.js +274 -0
- package/src/cli/variant.js +82 -0
- package/src/cli/watch.js +70 -0
- package/src/cli.js +130 -0
- package/src/comment-fields.js +76 -0
- package/src/comments-cli.js +208 -0
- package/src/config-reload.js +100 -0
- package/src/config.js +1061 -0
- package/src/devices-cli.js +21 -0
- package/src/diff.js +95 -0
- package/src/discover.js +284 -0
- package/src/doctor.js +295 -0
- package/src/event-log.js +268 -0
- package/src/events-cli.js +102 -0
- package/src/events.js +113 -0
- package/src/export.js +119 -0
- package/src/feedback.js +246 -0
- package/src/github.js +551 -0
- package/src/hosted/LICENSE.md +105 -0
- package/src/hosted/access-cli.js +78 -0
- package/src/hosted/admin.js +682 -0
- package/src/hosted/agent-approvals.js +163 -0
- package/src/hosted/agent-policy.js +189 -0
- package/src/hosted/app.js +510 -0
- package/src/hosted/auth-routes.js +540 -0
- package/src/hosted/auth.js +536 -0
- package/src/hosted/backup.js +483 -0
- package/src/hosted/board-context.js +35 -0
- package/src/hosted/board-routes.js +486 -0
- package/src/hosted/board-view.js +94 -0
- package/src/hosted/clean-worker.js +24 -0
- package/src/hosted/cleaner.js +89 -0
- package/src/hosted/comments.js +355 -0
- package/src/hosted/console-routes.js +401 -0
- package/src/hosted/cookies.js +18 -0
- package/src/hosted/crypto.js +80 -0
- package/src/hosted/db.js +496 -0
- package/src/hosted/device-routes.js +175 -0
- package/src/hosted/device.js +233 -0
- package/src/hosted/events.js +63 -0
- package/src/hosted/guards.js +172 -0
- package/src/hosted/guest-view.js +65 -0
- package/src/hosted/http.js +39 -0
- package/src/hosted/import.js +300 -0
- package/src/hosted/mail.js +73 -0
- package/src/hosted/mcp-http.js +71 -0
- package/src/hosted/membership.js +114 -0
- package/src/hosted/operator.js +478 -0
- package/src/hosted/ops-cli.js +345 -0
- package/src/hosted/pages.js +146 -0
- package/src/hosted/permissions.js +113 -0
- package/src/hosted/presence.js +372 -0
- package/src/hosted/projects.js +124 -0
- package/src/hosted/public.js +109 -0
- package/src/hosted/push.js +622 -0
- package/src/hosted/quotas.js +115 -0
- package/src/hosted/ratelimit.js +96 -0
- package/src/hosted/rebind.js +316 -0
- package/src/hosted/retention.js +128 -0
- package/src/hosted/server.js +260 -0
- package/src/hosted/setup-link.js +64 -0
- package/src/hosted/setup.js +323 -0
- package/src/hosted/shares.js +444 -0
- package/src/hosted/tailscale.js +204 -0
- package/src/hosted/tenancy.js +301 -0
- package/src/hosted/token-api.js +455 -0
- package/src/hosted/token-events.js +60 -0
- package/src/hosted/tokens.js +57 -0
- package/src/hosted/turnstile.js +49 -0
- package/src/hosted/usercontent.js +154 -0
- package/src/hosted/zip.js +155 -0
- package/src/invocation.js +58 -0
- package/src/journey-paths.js +282 -0
- package/src/journeys.js +189 -0
- package/src/links.js +106 -0
- package/src/local-projects.js +182 -0
- package/src/lock.js +193 -0
- package/src/mcp.js +417 -0
- package/src/mentions.js +151 -0
- package/src/net.js +15 -0
- package/src/notify/config.js +275 -0
- package/src/notify/index.js +301 -0
- package/src/notify/lease.js +73 -0
- package/src/notify/messages.js +212 -0
- package/src/notify/run.js +174 -0
- package/src/pixeldiff.js +49 -0
- package/src/png.js +143 -0
- package/src/reactions.js +111 -0
- package/src/remote/cli.js +133 -0
- package/src/remote/credentials.js +62 -0
- package/src/remote/ids.js +12 -0
- package/src/remote/login.js +155 -0
- package/src/remote/remote-mcp.js +237 -0
- package/src/remote/remote-watch.js +291 -0
- package/src/remote/remote.js +313 -0
- package/src/remote/share-state.js +78 -0
- package/src/remote/share.js +369 -0
- package/src/remote/terminal.js +13 -0
- package/src/serve-state.js +64 -0
- package/src/server/app.js +824 -0
- package/src/server/devices.js +186 -0
- package/src/server/local-console.js +28 -0
- package/src/server/local-user.js +59 -0
- package/src/server/pairing-routes.js +159 -0
- package/src/server/share-routes.js +89 -0
- package/src/server/tailscale.js +97 -0
- package/src/sitemap.js +431 -0
- package/src/store.js +983 -0
- package/src/tokens.js +11 -0
- package/src/update/routes.js +245 -0
- package/src/watch.js +403 -0
- package/src/which.js +58 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// What the starter agent runs with: the `starterAgent` config key, the
|
|
2
|
+
// flags and the environment.
|
|
3
|
+
//
|
|
4
|
+
// The config is usually committed, so it may choose only what stays inside
|
|
5
|
+
// the sandbox: who may dispatch work (per board), the test and setup
|
|
6
|
+
// commands (they run in the container), budgets, container limits, the
|
|
7
|
+
// branch prefix and the pull request base. What decides what leaves the
|
|
8
|
+
// sandbox comes only from the person running Shapewall: the image (the
|
|
9
|
+
// proxy runs from it), the runtime, the package registry and any extra
|
|
10
|
+
// egress host (flags or environment). The model endpoint and key follow the
|
|
11
|
+
// chat's rules (src/agent/config.js): a config cannot send your key to a
|
|
12
|
+
// host you did not confirm.
|
|
13
|
+
|
|
14
|
+
import { agentSettings } from '../config.js'
|
|
15
|
+
import { ACP_COMMAND_VAR } from '../acp/command.js'
|
|
16
|
+
import { splitCommand } from '../../watch.js'
|
|
17
|
+
import { ID_RE } from '../../config.js'
|
|
18
|
+
import { parseAllowEntry } from './egress-proxy.js'
|
|
19
|
+
import { DEFAULT_LIMITS, checkLimits } from './runtime.js'
|
|
20
|
+
import { sizeBytes } from './disk.js'
|
|
21
|
+
|
|
22
|
+
export const PROFILES = ['openai-compatible', 'claude-code', 'codex']
|
|
23
|
+
export const DEFAULT_BUDGET = { turns: 20, tokens: 200000, minutes: 15 }
|
|
24
|
+
export const BUDGET_MAX = { turns: 100, tokens: 2000000, minutes: 120 }
|
|
25
|
+
export const DEFAULT_REGISTRY = 'registry.npmjs.org:443'
|
|
26
|
+
export const REGISTRY_VAR = 'SHAPEWALL_AGENT_REGISTRY'
|
|
27
|
+
export const EGRESS_VAR = 'SHAPEWALL_AGENT_EGRESS'
|
|
28
|
+
export const DEFAULT_BRANCH_PREFIX = 'shapewall-agent/'
|
|
29
|
+
const TRUSTED_MAX = 200
|
|
30
|
+
const NAME_MAX = 80
|
|
31
|
+
const BRANCH_PREFIX_RE = /^[a-z0-9][a-z0-9._/-]{0,40}\/$/
|
|
32
|
+
const REMOTE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
|
|
33
|
+
const REF_RE = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,100}$/
|
|
34
|
+
// Keys refused in the config: each decides what leaves the sandbox or what runs on the host.
|
|
35
|
+
const REFUSED_KEYS = ['image', 'runtime', 'registry', 'egress', 'allowHosts', 'allowHost', 'network', 'apiKey', 'key', 'env', 'mounts']
|
|
36
|
+
|
|
37
|
+
const isObject = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
38
|
+
|
|
39
|
+
// How long a model call may take to start answering (headers), in seconds.
|
|
40
|
+
// Unset: 180 s until the model first answers in a run (a local model may
|
|
41
|
+
// still be loading), 60 s after that.
|
|
42
|
+
export const MODEL_TIMEOUT_MAX_S = 900
|
|
43
|
+
const modelTimeoutValid = (value) => Number.isInteger(value) && value >= 1 && value <= MODEL_TIMEOUT_MAX_S
|
|
44
|
+
|
|
45
|
+
// --model-timeout SECONDS, else the config's, else null (the defaults).
|
|
46
|
+
function modelTimeoutMs(base, flags) {
|
|
47
|
+
if (flags['model-timeout'] === undefined) return base.modelTimeoutSeconds ? base.modelTimeoutSeconds * 1000 : null
|
|
48
|
+
const raw = flags['model-timeout']
|
|
49
|
+
const value = typeof raw === 'number' ? raw : typeof raw === 'string' && /^\d+$/.test(raw.trim()) ? Number(raw) : NaN
|
|
50
|
+
if (!modelTimeoutValid(value)) throw new Error(`--model-timeout: 1 to ${MODEL_TIMEOUT_MAX_S} seconds`)
|
|
51
|
+
return value * 1000
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A trusted name as compared: hosted handles and local author names, case-folded.
|
|
55
|
+
export const trustName = (value) =>
|
|
56
|
+
String(value || '')
|
|
57
|
+
.replace(/^@/, '')
|
|
58
|
+
.replace(/\s+/g, ' ')
|
|
59
|
+
.trim()
|
|
60
|
+
.toLowerCase()
|
|
61
|
+
|
|
62
|
+
function cleanTrusted(raw, where, problems) {
|
|
63
|
+
if (raw === undefined) return null
|
|
64
|
+
if (
|
|
65
|
+
!Array.isArray(raw) ||
|
|
66
|
+
raw.length > TRUSTED_MAX ||
|
|
67
|
+
raw.some((item) => typeof item !== 'string' || !trustName(item) || item.length > NAME_MAX)
|
|
68
|
+
) {
|
|
69
|
+
problems.push(`${where}: a list of up to ${TRUSTED_MAX} member handles or names`)
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
return [...new Set(raw.map(trustName))]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function cleanCommand(raw, where, problems) {
|
|
76
|
+
if (raw === undefined || raw === null) return null
|
|
77
|
+
if (typeof raw !== 'string' || !raw.trim()) {
|
|
78
|
+
problems.push(`${where}: a command such as "npm test"`)
|
|
79
|
+
return null
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return splitCommand(raw, where)
|
|
83
|
+
} catch (error) {
|
|
84
|
+
problems.push(error.message)
|
|
85
|
+
return null
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Validates `starterAgent` in shapewall.config.json. Pushes one message per problem.
|
|
90
|
+
export function validateStarterAgent(raw, problems, { boardIds = [] } = {}) {
|
|
91
|
+
if (raw === undefined || raw === null) return null
|
|
92
|
+
if (!isObject(raw)) {
|
|
93
|
+
problems.push('starterAgent: an object such as { "trusted": ["robin"], "testCommand": "npm test" }')
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
// Where the agent's branch is pushed is the person's choice, per run.
|
|
97
|
+
for (const [key, flag] of [
|
|
98
|
+
['remote', '--git-remote'],
|
|
99
|
+
['forkRemote', '--fork-remote'],
|
|
100
|
+
]) {
|
|
101
|
+
if (raw[key] !== undefined) {
|
|
102
|
+
problems.push(
|
|
103
|
+
`starterAgent.${key}: not taken from the config (a repo must not decide where the agent's branch is pushed); pass ${flag} NAME to shapewall agent run instead (docs/starter-agent.md)`,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const key of REFUSED_KEYS) {
|
|
108
|
+
if (raw[key] !== undefined) {
|
|
109
|
+
problems.push(
|
|
110
|
+
`starterAgent.${key}: not taken from the config (a repo must not decide what leaves the sandbox); use the shapewall agent flags or environment (docs/starter-agent.md)`,
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const trusted = cleanTrusted(raw.trusted, 'starterAgent.trusted', problems) || []
|
|
115
|
+
const boards = {}
|
|
116
|
+
if (raw.boards !== undefined) {
|
|
117
|
+
if (!isObject(raw.boards)) problems.push('starterAgent.boards: { "<board id>": { "trusted": [...] } }')
|
|
118
|
+
else {
|
|
119
|
+
for (const [id, value] of Object.entries(raw.boards)) {
|
|
120
|
+
if (!ID_RE.test(id) || (boardIds.length && !boardIds.includes(id))) {
|
|
121
|
+
problems.push(`starterAgent.boards: no board "${id}"`)
|
|
122
|
+
continue
|
|
123
|
+
}
|
|
124
|
+
if (!isObject(value)) {
|
|
125
|
+
problems.push(`starterAgent.boards.${id}: { "trusted": [...] }`)
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
const list = cleanTrusted(value.trusted, `starterAgent.boards.${id}.trusted`, problems)
|
|
129
|
+
if (list) boards[id] = { trusted: list }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const budget = { ...DEFAULT_BUDGET }
|
|
134
|
+
if (raw.budget !== undefined) {
|
|
135
|
+
if (!isObject(raw.budget)) problems.push('starterAgent.budget: { "turns", "tokens", "minutes" }')
|
|
136
|
+
else {
|
|
137
|
+
for (const key of Object.keys(DEFAULT_BUDGET)) {
|
|
138
|
+
if (raw.budget[key] === undefined) continue
|
|
139
|
+
const value = raw.budget[key]
|
|
140
|
+
if (!Number.isInteger(value) || value < 1 || value > BUDGET_MAX[key])
|
|
141
|
+
problems.push(`starterAgent.budget.${key}: 1 to ${BUDGET_MAX[key]}`)
|
|
142
|
+
else budget[key] = value
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
let limits = { ...DEFAULT_LIMITS }
|
|
147
|
+
if (raw.limits !== undefined) {
|
|
148
|
+
if (!isObject(raw.limits)) problems.push('starterAgent.limits: { "memory": "4g", "cpus": 2, "pids": 512 }')
|
|
149
|
+
else {
|
|
150
|
+
try {
|
|
151
|
+
// Within what one review job should take on this machine.
|
|
152
|
+
// Compared in bytes: "999999m" is a size too, and must not get past the cap.
|
|
153
|
+
const asked = checkLimits({ ...DEFAULT_LIMITS, ...raw.limits })
|
|
154
|
+
if (sizeBytes(asked.memory) > sizeBytes('16g')) throw new Error('memory: at most 16g')
|
|
155
|
+
if (sizeBytes(asked.tmp) > sizeBytes('16g')) throw new Error('tmp: at most 16g')
|
|
156
|
+
if (Number(asked.cpus) > 8) throw new Error('cpus: at most 8')
|
|
157
|
+
if (sizeBytes(asked.disk) > sizeBytes('64g')) throw new Error('disk: at most 64g')
|
|
158
|
+
limits = asked
|
|
159
|
+
} catch (error) {
|
|
160
|
+
problems.push(`starterAgent.limits.${error.message}`)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const branchPrefix = raw.branchPrefix ?? DEFAULT_BRANCH_PREFIX
|
|
165
|
+
if (typeof branchPrefix !== 'string' || !BRANCH_PREFIX_RE.test(branchPrefix)) {
|
|
166
|
+
problems.push('starterAgent.branchPrefix: lowercase, ending in "/", such as "shapewall-agent/"')
|
|
167
|
+
}
|
|
168
|
+
if (raw.prBase !== undefined && (typeof raw.prBase !== 'string' || !REF_RE.test(raw.prBase)))
|
|
169
|
+
problems.push('starterAgent.prBase: a branch name')
|
|
170
|
+
const modelTimeout = raw.modelTimeoutSeconds
|
|
171
|
+
const timeoutOk = modelTimeout === undefined || modelTimeoutValid(modelTimeout)
|
|
172
|
+
if (!timeoutOk)
|
|
173
|
+
problems.push(`starterAgent.modelTimeoutSeconds: 1 to ${MODEL_TIMEOUT_MAX_S} (seconds to the first answer of a model call)`)
|
|
174
|
+
return {
|
|
175
|
+
modelTimeoutSeconds: timeoutOk && modelTimeout !== undefined ? modelTimeout : null,
|
|
176
|
+
trusted,
|
|
177
|
+
boards,
|
|
178
|
+
testCommand: cleanCommand(raw.testCommand, 'starterAgent.testCommand', problems),
|
|
179
|
+
setupCommand: cleanCommand(raw.setupCommand, 'starterAgent.setupCommand', problems),
|
|
180
|
+
budget,
|
|
181
|
+
limits,
|
|
182
|
+
branchPrefix: typeof branchPrefix === 'string' && BRANCH_PREFIX_RE.test(branchPrefix) ? branchPrefix : DEFAULT_BRANCH_PREFIX,
|
|
183
|
+
prBase: typeof raw.prBase === 'string' && REF_RE.test(raw.prBase) ? raw.prBase : null,
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// --max-disk SIZE: the disk cap on the mounted folder for this run.
|
|
188
|
+
function diskFlag(limits, value) {
|
|
189
|
+
if (value === undefined) return limits
|
|
190
|
+
if (typeof value !== 'string' || !/^[1-9]\d{0,5}[mg]$/.test(value) || sizeBytes(value) > sizeBytes('64g')) {
|
|
191
|
+
throw new Error('--max-disk: a size such as 2g or 500m, at most 64g')
|
|
192
|
+
}
|
|
193
|
+
return { ...limits, disk: value }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// A git remote name from a flag (never from the config), or the default.
|
|
197
|
+
function remoteFlag(flags, name, fallback) {
|
|
198
|
+
const value = flags[name]
|
|
199
|
+
if (value === undefined) return fallback
|
|
200
|
+
if (typeof value !== 'string' || !REMOTE_RE.test(value)) throw new Error(`--${name}: a git remote name`)
|
|
201
|
+
return value
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// "host" or "host:port" from a flag or the environment -> an allow entry the person chose.
|
|
205
|
+
export function personHost(value, where) {
|
|
206
|
+
const raw = String(value || '').trim()
|
|
207
|
+
const withPort = /:\d{1,5}$/.test(raw) && !/^\[[^\]]*$/.test(raw) ? raw : `${raw}:443`
|
|
208
|
+
try {
|
|
209
|
+
return { ...parseAllowEntry(withPort), private: true }
|
|
210
|
+
} catch {
|
|
211
|
+
throw new Error(`${where}: "${raw.slice(0, 80)}" is not a host or host:port`)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const list = (value) => (Array.isArray(value) ? value : String(value || '').split(',')).map((item) => String(item).trim()).filter(Boolean)
|
|
216
|
+
|
|
217
|
+
// Budget flags: --max-turns, --max-tokens, --max-minutes.
|
|
218
|
+
function budgetFrom(base, flags) {
|
|
219
|
+
const budget = { ...base }
|
|
220
|
+
for (const [flag, key] of [
|
|
221
|
+
['max-turns', 'turns'],
|
|
222
|
+
['max-tokens', 'tokens'],
|
|
223
|
+
['max-minutes', 'minutes'],
|
|
224
|
+
]) {
|
|
225
|
+
if (flags[flag] === undefined) continue
|
|
226
|
+
const value = Number(flags[flag])
|
|
227
|
+
if (!Number.isInteger(value) || value < 1 || value > BUDGET_MAX[key]) throw new Error(`--${flag}: 1 to ${BUDGET_MAX[key]}`)
|
|
228
|
+
budget[key] = value
|
|
229
|
+
}
|
|
230
|
+
return budget
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Everything a run needs to know, without secrets. Throws for bad flags.
|
|
234
|
+
export function starterSettings(config, { env = process.env, flags = {} } = {}) {
|
|
235
|
+
const base = config.starterAgent || validateStarterAgent({}, [])
|
|
236
|
+
const profile = flags.profile || 'openai-compatible'
|
|
237
|
+
if (!PROFILES.includes(profile)) throw new Error(`--profile: one of ${PROFILES.join(', ')}`)
|
|
238
|
+
// The chat's endpoint settings, never its ACP agent: the starter agent
|
|
239
|
+
// drives the model itself (from the sandbox, through the host relay).
|
|
240
|
+
const model = agentSettings(config, { ...env, [ACP_COMMAND_VAR]: '' })
|
|
241
|
+
let modelProblem = null
|
|
242
|
+
if (profile !== 'openai-compatible') {
|
|
243
|
+
modelProblem = `the ${profile} profile is not available yet; use --profile openai-compatible (docs/starter-agent.md)`
|
|
244
|
+
} else if (model.backend !== 'openai-compatible') {
|
|
245
|
+
modelProblem =
|
|
246
|
+
'the starter agent needs an OpenAI-compatible endpoint (agent.baseUrl and agent.model, or SHAPEWALL_AGENT_BASE_URL and SHAPEWALL_AGENT_MODEL); an ACP agent cannot run in the sandbox'
|
|
247
|
+
} else if (!model.configured) {
|
|
248
|
+
modelProblem = model.problem || 'no model endpoint: set agent.baseUrl and agent.model (docs/agents.md)'
|
|
249
|
+
}
|
|
250
|
+
const registryRaw = flags.registry ?? env[REGISTRY_VAR] ?? null
|
|
251
|
+
const registry =
|
|
252
|
+
registryRaw === 'none'
|
|
253
|
+
? null
|
|
254
|
+
: registryRaw
|
|
255
|
+
? personHost(registryRaw, `--registry / ${REGISTRY_VAR}`)
|
|
256
|
+
: { ...parseAllowEntry(DEFAULT_REGISTRY), private: false }
|
|
257
|
+
const extra = [...list(flags['allow-host']), ...list(env[EGRESS_VAR])].map((item) => personHost(item, `--allow-host / ${EGRESS_VAR}`))
|
|
258
|
+
const extraTrusted = list(flags.trusted).map(trustName).filter(Boolean)
|
|
259
|
+
return {
|
|
260
|
+
profile,
|
|
261
|
+
model: {
|
|
262
|
+
baseUrl: model.baseUrl,
|
|
263
|
+
model: model.model,
|
|
264
|
+
keyVar: model.keyVar,
|
|
265
|
+
hasKey: Boolean(model.hasKey),
|
|
266
|
+
host: model.host,
|
|
267
|
+
maxTokens: model.maxTokens,
|
|
268
|
+
temperature: model.temperature,
|
|
269
|
+
label: model.label,
|
|
270
|
+
},
|
|
271
|
+
problem: modelProblem,
|
|
272
|
+
// null: the defaults (model-relay.js).
|
|
273
|
+
modelTimeoutMs: modelTimeoutMs(base, flags),
|
|
274
|
+
budget: budgetFrom(base.budget, flags),
|
|
275
|
+
limits: diskFlag(base.limits, flags['max-disk']),
|
|
276
|
+
testCommand: base.testCommand,
|
|
277
|
+
setupCommand: base.setupCommand,
|
|
278
|
+
branchPrefix: base.branchPrefix,
|
|
279
|
+
remote: remoteFlag(flags, 'git-remote', 'origin'),
|
|
280
|
+
prBase: base.prBase,
|
|
281
|
+
forkRemote: remoteFlag(flags, 'fork-remote', null),
|
|
282
|
+
registry,
|
|
283
|
+
extraHosts: extra,
|
|
284
|
+
// Who may dispatch work on a board: its own list, or the default list, plus --trusted.
|
|
285
|
+
trustedFor(boardId) {
|
|
286
|
+
const own = base.boards?.[boardId]?.trusted
|
|
287
|
+
return new Set([...(own || base.trusted || []), ...extraTrusted])
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Where the starter agent's comments come from: this project's board
|
|
2
|
+
// (comments.json) or a hosted board (--remote, the token API). Both give
|
|
3
|
+
// comments in the feedback item shape (src/feedback.js) and take replies
|
|
4
|
+
// and agent status the same way.
|
|
5
|
+
|
|
6
|
+
import { getBoard } from '../../config.js'
|
|
7
|
+
import { feedbackContext, feedbackItem } from '../../feedback.js'
|
|
8
|
+
import { addReply, getComment, listComments, setAgentStatus } from '../../store.js'
|
|
9
|
+
|
|
10
|
+
export const AGENT_AUTHOR_NAME = 'agent'
|
|
11
|
+
|
|
12
|
+
export function localSource(config, boardId = null) {
|
|
13
|
+
const board = getBoard(config, boardId)
|
|
14
|
+
const item = (comment) => {
|
|
15
|
+
const value = feedbackItem(feedbackContext(config, board), comment)
|
|
16
|
+
delete value.files
|
|
17
|
+
return value
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
hosted: false,
|
|
21
|
+
config,
|
|
22
|
+
// baseUrl: what `shapewall capture` captures (is it reachable from the sandbox?).
|
|
23
|
+
board: { id: board.id, title: board.title, url: board.publicUrl || board.baseUrl, baseUrl: board.baseUrl || null },
|
|
24
|
+
list: async () => listComments(config, board.id, { status: 'open' }).map(item),
|
|
25
|
+
get: async (id) => item(getComment(config, board.id, id)),
|
|
26
|
+
claim: async (id, onlyFrom) => {
|
|
27
|
+
const { changed, comment } = await setAgentStatus(config, board.id, id, 'queued', { onlyFrom })
|
|
28
|
+
return { changed, comment: item(comment) }
|
|
29
|
+
},
|
|
30
|
+
setStatus: async (id, status) => setAgentStatus(config, board.id, id, status),
|
|
31
|
+
reply: async (id, body) => addReply(config, board.id, id, { author: AGENT_AUTHOR_NAME, body }),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function remoteSource(remote, boardId, boardInfo = {}) {
|
|
36
|
+
const strip = (value) => {
|
|
37
|
+
if (!value) return value
|
|
38
|
+
const copy = { ...value }
|
|
39
|
+
delete copy.files
|
|
40
|
+
return copy
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
hosted: true,
|
|
44
|
+
async approveCommand(id, { command, reason, signal, pollMs = 500 }) {
|
|
45
|
+
const { approval: record } = await remote.requestApproval(boardId, id, { command, reason })
|
|
46
|
+
for (;;) {
|
|
47
|
+
if (signal?.aborted || Date.now() >= Date.parse(record.expires_at)) return { approved: false, state: 'expired' }
|
|
48
|
+
const { approval: current } = await remote.approval(boardId, record.id)
|
|
49
|
+
if (current.state !== 'pending')
|
|
50
|
+
return {
|
|
51
|
+
approved: current.state === 'approved' && current.command_hash === record.command_hash && current.command === command,
|
|
52
|
+
state: current.state,
|
|
53
|
+
}
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve, pollMs))
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
config: null,
|
|
58
|
+
board: { id: boardId, title: boardInfo.title || boardId, url: boardInfo.baseUrl || null, baseUrl: boardInfo.baseUrl || null },
|
|
59
|
+
// Guests' comments are never asked for (the server hides them by default).
|
|
60
|
+
list: async () => (await remote.comments(boardId, { status: 'open' })).comments.filter((item) => !item.authorGuest).map(strip),
|
|
61
|
+
get: async (id) => strip((await remote.comment(boardId, id)).comment),
|
|
62
|
+
claim: async (id, onlyFrom) => {
|
|
63
|
+
const { changed, comment } = await remote.setAgentStatus(boardId, id, 'queued', { onlyFrom })
|
|
64
|
+
return { changed, comment: strip(comment) }
|
|
65
|
+
},
|
|
66
|
+
setStatus: async (id, status) => remote.setAgentStatus(boardId, id, status),
|
|
67
|
+
reply: async (id, body) => remote.reply(boardId, id, { body }),
|
|
68
|
+
}
|
|
69
|
+
}
|