hive-am 1.12.0 → 1.13.0
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 +27 -1
- package/README.md +7 -3
- package/package.json +1 -1
- package/server/dist/api.js +1 -0
- package/server/dist/http/routes/agent-colonies.js +11 -0
- package/server/dist/instructions.js +9 -2
- package/server/dist/providers/claude.js +3 -3
- package/server/dist/services/colony-admin.js +402 -0
- package/server/dist/skills/defaults.js +95 -0
- package/server/mcp/dispatch.mjs +79 -0
- package/web/.next/BUILD_ID +1 -1
- package/web/.next/app-build-manifest.json +43 -43
- package/web/.next/app-path-routes-manifest.json +8 -8
- package/web/.next/build-manifest.json +2 -2
- package/web/.next/prerender-manifest.json +47 -47
- package/web/.next/required-server-files.json +1 -1
- package/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/_not-found.html +1 -1
- package/web/.next/server/app/_not-found.rsc +4 -4
- package/web/.next/server/app/agents/[id]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/agents/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/agents.html +1 -1
- package/web/.next/server/app/agents.rsc +4 -4
- package/web/.next/server/app/apple-icon.png/route.js +1 -1
- package/web/.next/server/app/apple-icon.png.body +0 -0
- package/web/.next/server/app/chat/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/chat.html +1 -1
- package/web/.next/server/app/chat.rsc +4 -4
- package/web/.next/server/app/colony/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/colony.html +1 -1
- package/web/.next/server/app/colony.rsc +4 -4
- package/web/.next/server/app/connections/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/connections.html +1 -1
- package/web/.next/server/app/connections.rsc +4 -4
- package/web/.next/server/app/favicon.ico/route.js +1 -1
- package/web/.next/server/app/favicon.ico.body +0 -0
- package/web/.next/server/app/icon.png/route.js +1 -1
- package/web/.next/server/app/icon.png.body +0 -0
- package/web/.next/server/app/index.html +1 -1
- package/web/.next/server/app/index.rsc +4 -4
- package/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/relations/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/relations.html +1 -1
- package/web/.next/server/app/relations.rsc +4 -4
- package/web/.next/server/app/resources/[id]/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/resources/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/resources.html +1 -1
- package/web/.next/server/app/resources.rsc +4 -4
- package/web/.next/server/app/schedules/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/schedules.html +1 -1
- package/web/.next/server/app/schedules.rsc +4 -4
- package/web/.next/server/app/sessions/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/sessions.html +1 -1
- package/web/.next/server/app/sessions.rsc +4 -4
- package/web/.next/server/app/skills/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/skills.html +1 -1
- package/web/.next/server/app/skills.rsc +4 -4
- package/web/.next/server/app/types/page_client-reference-manifest.js +1 -1
- package/web/.next/server/app/types.html +1 -1
- package/web/.next/server/app/types.rsc +4 -4
- package/web/.next/server/app-paths-manifest.json +8 -8
- package/web/.next/server/chunks/953.js +1 -1
- package/web/.next/server/pages/404.html +1 -1
- package/web/.next/server/pages/500.html +1 -1
- package/web/.next/server/server-reference-manifest.json +1 -1
- package/web/.next/static/chunks/app/{layout-114e3639e77db079.js → layout-e3a3b8673994fb7f.js} +1 -1
- package/web/.next/static/css/{c484c502b2d13072.css → e6062c3ccbd917a3.css} +1 -1
- package/web/.next/trace +31 -31
- package/web/public/logo-completo.png +0 -0
- package/web/public/logo.png +0 -0
- /package/web/.next/static/{GT9TTAUuwG8duMIDd7bTf → GAg13pXdw3yQNnw4lpxay}/_buildManifest.js +0 -0
- /package/web/.next/static/{GT9TTAUuwG8duMIDd7bTf → GAg13pXdw3yQNnw4lpxay}/_ssgManifest.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,30 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.13.0] - 2026-10-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Agents can build and manage colonies.** The new default skill **Colony builder** (`default-colonies`, loaded on demand) gives an agent eighteen `colony_*` MCP tools to create, read, change and delete colonies, agents and resources of any colony, with the same checks as the web app (unique names, existing folders, providers, effort levels, Plan mode and chat connections). Arguments use names, and the skill teaches the recipe: ask first, a colony prompt and one prompt per role, skills per role, `Role - Name - ACRONYM` names, linking workers, resources, changing only what was asked and checking the result. The server enforces the limits (an agent in Plan mode on OpenCode, Kiro or Cursor can use all of them too, and can give Full access, so the skill tells it to ask the person first; Claude Code blocks every hive tool in Plan mode); no password, secret variable or `env` value is shown, and no password or secret can be written from a chat (a saved secret HTTP variable is kept on update and cannot be removed or made plain from there); Telegram and Slack connections are out of reach; an agent cannot delete itself, its orchestrator, an agent it has a task open with or its own colony, and a change that would take away its own access is rolled back whole; deleting needs `confirm` with the exact name, and without it the answer only says what would go. API: `POST /api/agent-colonies/:op`, local app only like the writes of resources; tested in `test-colony-tools.ts` (no model). It gives full control: assign it only to an agent you trust with everything (manual, Permissions and security).
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **Claude no longer receives the instructions twice in a new session.** A new Claude Code conversation (and every delegated task, which always starts one) got the instructions as its system prompt and again as an `<instructions>` block in front of the first message, one extra copy that stayed in the context for the whole session. Now a new session gets them only as the system prompt; a resumed one still gets the `update` block when they changed, since Claude ignores the system prompt on `--resume`. OpenCode, Kiro and Cursor are unchanged. Claude's arguments and stdin are tested in the new `test-claude-args.ts` (no model).
|
|
18
|
+
|
|
19
|
+
## [1.12.1] - 2026-10-24
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **Diagrams of how hive-am works inside.** `docs/diagrams/`, in English and Spanish, has ten pages that each follow a real path through the code: a chat message, a turn, the effective prompt, a delegation, wake-ups and schedules, processes and ports, a source map of `server/src`, the data model, the life cycle of an agent and the providers. Each has a Mermaid diagram, a table that maps every step to a file, a function and a line, the test scripts that cover it and its edge cases. The README and the reference index link to them.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- **New hive-am logos.** The README uses the full logo (isotype plus wordmark), and the app logo, favicon and icons use the new isotype. The editable sources and exports are in `docs/brand/`.
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- **Cards no longer touch in a resource's Settings.** In the two-column Settings form, a full-width card (such as **Volumes**) sat 2 px under the last card of a column instead of the usual 14 px, so the two looked glued together. The gap is now the same everywhere.
|
|
32
|
+
|
|
9
33
|
## [1.12.0] - 2026-10-23
|
|
10
34
|
|
|
11
35
|
### Added
|
|
@@ -327,7 +351,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
|
327
351
|
- Complete documentation in English and Spanish.
|
|
328
352
|
- npm package with the `hive-am` command.
|
|
329
353
|
|
|
330
|
-
[Unreleased]: https://github.com/hughcbscrt/hive-am/compare/v1.
|
|
354
|
+
[Unreleased]: https://github.com/hughcbscrt/hive-am/compare/v1.13.0...HEAD
|
|
355
|
+
[1.13.0]: https://github.com/hughcbscrt/hive-am/compare/v1.12.1...v1.13.0
|
|
356
|
+
[1.12.1]: https://github.com/hughcbscrt/hive-am/compare/v1.12.0...v1.12.1
|
|
331
357
|
[1.12.0]: https://github.com/hughcbscrt/hive-am/compare/v1.11.0...v1.12.0
|
|
332
358
|
[1.11.0]: https://github.com/hughcbscrt/hive-am/compare/v1.10.1...v1.11.0
|
|
333
359
|
[1.10.1]: https://github.com/hughcbscrt/hive-am/compare/v1.10.0...v1.10.1
|
package/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="web/public/logo.png" alt="hive-am" width="
|
|
2
|
+
<img src="web/public/logo-completo.png" alt="hive-am" width="100%" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
<h1 align="center">hive-am</h1>
|
|
6
|
-
|
|
7
5
|
<p align="center">
|
|
8
6
|
<strong>A colony of coding agents on your machine.</strong><br />
|
|
9
7
|
Orchestrators and subagents over <b>Claude Code</b>, <b>OpenCode</b>, <b>Kiro</b> and <b>Cursor</b>, with the real sessions of each CLI, a browser UI and Telegram.
|
|
@@ -146,6 +144,8 @@ A step by step guide with screenshots, from installing hive-am to running resour
|
|
|
146
144
|
|
|
147
145
|
Full documentation in English and Spanish: **[English](docs/reference/en/README.md)** · **[Español](docs/reference/es/README.md)**.
|
|
148
146
|
|
|
147
|
+
Diagrams of how it works inside, with the file, function and line behind each step: **[English](docs/diagrams/en/README.md)** · **[Español](docs/diagrams/es/README.md)**.
|
|
148
|
+
|
|
149
149
|
| Topic | Where |
|
|
150
150
|
|---|---|
|
|
151
151
|
| Overview and architecture | [docs/01](docs/reference/en/01-overview.md) |
|
|
@@ -166,3 +166,7 @@ Full documentation in English and Spanish: **[English](docs/reference/en/README.
|
|
|
166
166
|
- A turn in flight during a crash is lost; the session is intact and the agent is idle on restart.
|
|
167
167
|
- Instructions are advice to the model; what the server enforces is who an agent can delegate to, who a connection answers, which files can be sent, and the permission level.
|
|
168
168
|
- There is no automated test suite. Features are checked with simulations against real agents (`server/scripts/sim-*.ts`).
|
|
169
|
+
|
|
170
|
+
<p align="center">
|
|
171
|
+
<img src="web/public/logo.png" alt="hive-am" width="84" />
|
|
172
|
+
</p>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-am",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "A colony of coding agents: orchestrators and subagents over Claude Code, OpenCode, Kiro and Cursor, with real session resume, a browser UI and Telegram.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
package/server/dist/api.js
CHANGED
|
@@ -9,6 +9,7 @@ import './http/routes/terminals.js';
|
|
|
9
9
|
import './http/routes/skills.js';
|
|
10
10
|
import './http/routes/types.js';
|
|
11
11
|
import './http/routes/colonies.js';
|
|
12
|
+
import './http/routes/agent-colonies.js';
|
|
12
13
|
import './http/routes/connections.js';
|
|
13
14
|
import './http/routes/orchestration.js';
|
|
14
15
|
import './http/routes/notebook.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { agentColonies } from '../../services/colony-admin.js';
|
|
2
|
+
import { body } from '../body.js';
|
|
3
|
+
import { requireLocal } from '../guards.js';
|
|
4
|
+
import { route } from '../router.js';
|
|
5
|
+
// The tools `colony_*` of the "Colony builder" skill: one route, the operation in the path; `from` is the agent, and the skill, the
|
|
6
|
+
// secrets and the guards that keep it from cutting off its own access are checked in services/colony-admin.ts. They create
|
|
7
|
+
// servers with their commands and agents with Full access, so, like the writes of resources, a page of another origin is refused (the MCP sends none).
|
|
8
|
+
route('POST', '/api/agent-colonies/:op', async ({ req, params }) => {
|
|
9
|
+
requireLocal(req, 'Colonies can only be changed from the local app');
|
|
10
|
+
return agentColonies(params[0], await body(req));
|
|
11
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { agents, colonies, skills } from './db.js';
|
|
2
2
|
import { connections } from './connections/store.js';
|
|
3
3
|
import { platformName } from './connections/prompt.js';
|
|
4
|
-
import { DATABASES_SKILL_ID, NOTEBOOK_SKILL_ID, OBJECTS_SKILL_ID, WAKEUPS_SKILL_ID } from './skills/defaults.js';
|
|
4
|
+
import { COLONIES_SKILL_ID, DATABASES_SKILL_ID, NOTEBOOK_SKILL_ID, OBJECTS_SKILL_ID, WAKEUPS_SKILL_ID } from './skills/defaults.js';
|
|
5
5
|
import { NOTEBOOK_MAX, notebooks } from './skills/notebook.js';
|
|
6
6
|
/**
|
|
7
7
|
* What an agent is told and which hive tools it gets: its identity, prompt, skills, team, channels and notebook, and the
|
|
@@ -16,7 +16,7 @@ export function lazySkills(a) {
|
|
|
16
16
|
return [];
|
|
17
17
|
return a.skill_ids.map((id) => skills.get(id)).filter((s) => !!s && a.skill_loads[s.id] === 'on_demand' && !!s.content.trim());
|
|
18
18
|
}
|
|
19
|
-
/** Which hive tools an agent gets: `dispatch` (orchestrator with a team)
|
|
19
|
+
/** Which hive tools an agent gets: `dispatch` (orchestrator with a team), `channel` (linked to an external connection) and one group per skill that comes with tools. */
|
|
20
20
|
export function mcpCaps(a) {
|
|
21
21
|
const caps = [];
|
|
22
22
|
if (a.role === 'orchestrator' && a.worker_ids.length > 0)
|
|
@@ -31,6 +31,8 @@ export function mcpCaps(a) {
|
|
|
31
31
|
caps.push('objects');
|
|
32
32
|
if (a.skill_ids.includes(DATABASES_SKILL_ID))
|
|
33
33
|
caps.push('databases');
|
|
34
|
+
if (a.skill_ids.includes(COLONIES_SKILL_ID))
|
|
35
|
+
caps.push('colonies');
|
|
34
36
|
if (lazySkills(a).length > 0)
|
|
35
37
|
caps.push('skills');
|
|
36
38
|
return caps;
|
|
@@ -106,6 +108,11 @@ You look after the servers and containers of your colony. Tools: \`object_list\`
|
|
|
106
108
|
const t = (tool) => `\`${tool}\` (${toolName(a.provider, tool)})`;
|
|
107
109
|
parts.push(`## Database management
|
|
108
110
|
You look after the database resources of your colony. Look: ${t('object_db_list')}, ${t('object_db_schema')}, ${t('object_db_columns')}, ${t('object_db_describe')}, ${t('object_db_search')}, ${t('object_db_ddl')}, ${t('object_db_sample')}, ${t('object_db_explain')}. Run SQL: ${t('object_db_query')} (one statement) and ${t('object_db_exec')} (several, in one transaction)${a.permission === 'plan' ? ' (read-only: you can only read)' : ''}; ${t('object_db_export')} writes a result to a file in your folder. Keep: ${t('object_db_saved')}, ${t('object_db_history')}, ${t('object_db_sessions')}. The resource itself: ${t('object_db_config')}, ${t('object_db_test')}, and with Full access ${t('object_db_config_set')}, ${t('object_db_create')}, ${t('object_db_delete')}, ${t('object_db_kill')}. Follow the "Database management" skill: writes are real, DROP and TRUNCATE need Full access, and you never write or repeat a password.`);
|
|
111
|
+
}
|
|
112
|
+
if (a.skill_ids.includes(COLONIES_SKILL_ID)) {
|
|
113
|
+
const t = (tool) => `\`${tool}\` (${toolName(a.provider, tool)})`;
|
|
114
|
+
parts.push(`## Colony builder
|
|
115
|
+
You can create, change and delete the colonies, agents and resources of ANY colony, with any permission: full control, so go slowly. Look: ${t('colony_options')}, ${t('colony_list')}, ${t('colony_get')}, ${t('colony_agent_list')}, ${t('colony_agent_get')}, ${t('colony_skill_list')}, ${t('colony_resource_list')}, ${t('colony_resource_get')}. Change: ${t('colony_create')}, ${t('colony_update')}, ${t('colony_delete')}, ${t('colony_agent_create')}, ${t('colony_agent_update')}, ${t('colony_agent_delete')}, ${t('colony_resource_create')}, ${t('colony_resource_update')}, ${t('colony_resource_delete')}, ${t('colony_resource_manager')}. Follow the "Colony builder" skill: ask before you build, change only what was asked, and delete only after the person's explicit yes (the delete tools need \`confirm\` with the exact name). Secrets and chat connections are set by the person in the web app.`);
|
|
109
116
|
}
|
|
110
117
|
if (a.skill_ids.includes(NOTEBOOK_SKILL_ID)) {
|
|
111
118
|
const nb = { read: toolName(a.provider, 'notebook_read'), add: toolName(a.provider, 'notebook_add'), rewrite: toolName(a.provider, 'notebook_rewrite') };
|
|
@@ -24,11 +24,11 @@ export async function* runClaude(o) {
|
|
|
24
24
|
// Files people sent through a connection live outside the working folder; let the agent read them.
|
|
25
25
|
if (existsSync(inboxDir(agent.id)))
|
|
26
26
|
args.push('--add-dir', inboxDir(agent.id));
|
|
27
|
-
// The system prompt of a session is fixed when it starts: `--append-system-prompt` is ignored on `--resume`.
|
|
28
|
-
// resumed conversation whose instructions changed (skills, team, notebook…) gets them as an update inside the message.
|
|
27
|
+
// The system prompt of a session is fixed when it starts: `--append-system-prompt` is ignored on `--resume`. A new session gets the
|
|
28
|
+
// instructions only as the system prompt; a resumed conversation whose instructions changed (skills, team, notebook…) gets them as an update inside the message.
|
|
29
29
|
if (o.instructions)
|
|
30
30
|
args.push('--append-system-prompt', o.instructions);
|
|
31
|
-
const prompt = withInstructions(o.prompt, o.instructions,
|
|
31
|
+
const prompt = agent.session_id ? withInstructions(o.prompt, o.instructions, true, o.refreshInstructions) : o.prompt;
|
|
32
32
|
// Agents with the Browser switch on drive the person's Chrome through its extension; `-p` has nobody to approve each call, so the tools are allowed up front.
|
|
33
33
|
const allowed = [];
|
|
34
34
|
if (agent.browser && agent.permission !== 'plan') {
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { agents, colonies, db, resolved, skills } from '../db.js';
|
|
2
|
+
import { connections } from '../connections/store.js';
|
|
3
|
+
import { effortOptions } from '../efforts.js';
|
|
4
|
+
import { mcpCaps } from '../instructions.js';
|
|
5
|
+
import { listModels } from '../models.js';
|
|
6
|
+
import { listObjects, createObject, removeObject, setObjectManager, updateObject } from '../objects/index.js';
|
|
7
|
+
import { isKind, kindOf } from '../objects/model.js';
|
|
8
|
+
import { maskConfig, objectsStore } from '../objects/store.js';
|
|
9
|
+
import { notebooks } from '../skills/notebook.js';
|
|
10
|
+
import { notifyAgentsChanged } from '../runtime.js';
|
|
11
|
+
import { createAgent, removeAgent, updateAgent } from './agents.js';
|
|
12
|
+
import { createColony, removeColony, updateColony } from './colonies.js';
|
|
13
|
+
import { PROVIDERS, isProvider, providerStatus } from './providers.js';
|
|
14
|
+
import { bad } from '../http/errors.js';
|
|
15
|
+
import { isRecord, text, trimmed, validateAgentInput, validateColony } from '../http/validate.js';
|
|
16
|
+
const NO_SKILL = 'You do not have the "Colony builder" skill.';
|
|
17
|
+
const SELF_LOCKOUT = 'That change would take away your own Colony builder access. Ask the person to do it from the web app.';
|
|
18
|
+
const NO_SECRETS = 'Set secrets in the web app (Resources); never put them in a chat.';
|
|
19
|
+
const PERMISSIONS = ['plan', 'acceptEdits', 'bypassPermissions'];
|
|
20
|
+
const FIELDS = ['cwd', 'permission', 'skills', 'prompt'];
|
|
21
|
+
const MASK = '***';
|
|
22
|
+
function whoAsks(from) {
|
|
23
|
+
const a = typeof from === 'string' ? agents.get(from) : undefined;
|
|
24
|
+
if (!a || !mcpCaps(resolved(a)).includes('colonies'))
|
|
25
|
+
throw bad(NO_SKILL);
|
|
26
|
+
return a;
|
|
27
|
+
}
|
|
28
|
+
/** Keeps the caller able to use these tools: the change runs in a transaction that is rolled back if it would not be. */
|
|
29
|
+
function keepingAccess(a, change) {
|
|
30
|
+
return db.transaction(() => {
|
|
31
|
+
const out = change();
|
|
32
|
+
const me = agents.get(a.id);
|
|
33
|
+
if (!me || !mcpCaps(resolved(me)).includes('colonies'))
|
|
34
|
+
throw bad(SELF_LOCKOUT);
|
|
35
|
+
return out;
|
|
36
|
+
})();
|
|
37
|
+
}
|
|
38
|
+
// ---- names to records -----------------------------------------------------------------------------------------------------------------
|
|
39
|
+
const same = (a, b) => a.toLowerCase() === trimmed(b).toLowerCase();
|
|
40
|
+
const names = (xs) => xs.map((x) => x.name).join(', ') || '(none)';
|
|
41
|
+
const isNone = (v) => v === null || ['', 'none', 'null'].includes(trimmed(v).toLowerCase());
|
|
42
|
+
function colonyNamed(name) {
|
|
43
|
+
const all = colonies.list(), c = all.find((x) => same(x.name, name));
|
|
44
|
+
if (!c)
|
|
45
|
+
throw bad(`There is no colony named "${text(name)}". Colonies: ${names(all)}.`);
|
|
46
|
+
return c;
|
|
47
|
+
}
|
|
48
|
+
function agentNamed(name) {
|
|
49
|
+
const a = agents.byName(trimmed(name));
|
|
50
|
+
if (!a)
|
|
51
|
+
throw bad(`There is no agent named "${text(name)}". Agents: ${names(agents.list())}.`);
|
|
52
|
+
return a;
|
|
53
|
+
}
|
|
54
|
+
function resourceNamed(name) {
|
|
55
|
+
const all = listObjects(), o = all.find((x) => same(x.name, name));
|
|
56
|
+
if (!o)
|
|
57
|
+
throw bad(`There is no resource named "${text(name)}". Resources: ${names(all)}.`);
|
|
58
|
+
return o;
|
|
59
|
+
}
|
|
60
|
+
/** `null`, '' or "none" is no colony; anything else must be the name of one. */
|
|
61
|
+
const colonyArg = (v) => (isNone(v) ? null : colonyNamed(v).id);
|
|
62
|
+
const colonyName = (id) => (id ? colonies.get(id)?.name ?? null : null);
|
|
63
|
+
const agentName = (id) => agents.get(id)?.name ?? id;
|
|
64
|
+
/** `[{ name, load }]` (or plain names) to the ids and loads the repositories take. */
|
|
65
|
+
function skillsArg(v) {
|
|
66
|
+
if (!Array.isArray(v))
|
|
67
|
+
throw bad('skills must be a list of { name, load }');
|
|
68
|
+
const all = skills.list(), skill_ids = [], skill_loads = {};
|
|
69
|
+
for (const item of v) {
|
|
70
|
+
const r = isRecord(item) ? item : { name: item };
|
|
71
|
+
const s = all.find((x) => same(x.name, r.name));
|
|
72
|
+
if (!s)
|
|
73
|
+
throw bad(`There is no skill named "${text(r.name)}". Call colony_skill_list for the names.`);
|
|
74
|
+
if (r.load !== undefined && r.load !== 'always' && r.load !== 'on_demand')
|
|
75
|
+
throw bad('A skill load must be always or on_demand');
|
|
76
|
+
skill_ids.push(s.id);
|
|
77
|
+
skill_loads[s.id] = r.load ?? s.load;
|
|
78
|
+
}
|
|
79
|
+
return { skill_ids, skill_loads };
|
|
80
|
+
}
|
|
81
|
+
const skillsOut = (ids, loads) => ids.map((id) => skills.get(id)).filter((s) => !!s).map((s) => ({ name: s.name, load: loads[s.id] ?? s.load }));
|
|
82
|
+
const permissionArg = (v) => { if (!PERMISSIONS.includes(v))
|
|
83
|
+
throw bad(`permission must be ${PERMISSIONS.join(', ')}`); return v; };
|
|
84
|
+
// ---- what is shown (never a secret, a session or a token) -----------------------------------------------------------------------------
|
|
85
|
+
const colonyOut = (c) => ({
|
|
86
|
+
name: c.name, color: c.color, cwd: c.cwd, permission: c.permission, system_prompt: c.system_prompt, inherit: c.inherit,
|
|
87
|
+
skills: skillsOut(c.skill_ids, c.skill_loads), agents: c.agent_ids.map(agentName),
|
|
88
|
+
});
|
|
89
|
+
const colonyLine = (c) => ({ name: c.name, cwd: c.cwd, permission: c.permission, agents: c.agent_ids.map(agentName), skills: skillsOut(c.skill_ids, c.skill_loads).map((s) => s.name) });
|
|
90
|
+
const linkedTo = (id) => connections.list().filter((c) => c.agent_id === id);
|
|
91
|
+
const bossesOf = (id) => agents.list().filter((o) => o.role === 'orchestrator' && o.worker_ids.includes(id));
|
|
92
|
+
function agentOut(a) {
|
|
93
|
+
return {
|
|
94
|
+
name: a.name, description: a.description, role: a.role, provider: a.provider, model: a.model, effort: a.effort, permission: a.permission, cwd: a.cwd,
|
|
95
|
+
colony: colonyName(a.colony_id), browser: a.browser, overrides: a.overrides, inherited: a.effective.inherited, system_prompt: a.system_prompt,
|
|
96
|
+
skills: skillsOut(a.skill_ids, a.skill_loads), workers: a.worker_ids.map(agentName), orchestrators: bossesOf(a.id).map((o) => o.name),
|
|
97
|
+
effective: { cwd: a.effective.cwd, permission: a.effective.permission, skills: skillsOut(a.effective.skill_ids, a.effective.skill_loads), system_prompt: a.effective.system_prompt },
|
|
98
|
+
chat_connections: linkedTo(a.id).length, status: a.status,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const agentLine = (a) => ({ name: a.name, role: a.role, provider: a.provider, model: a.model, permission: a.effective.permission, colony: colonyName(a.colony_id), description: a.description, status: a.status });
|
|
102
|
+
/** `env` of servers and containers keeps its names and hides its values (maskConfig already empties passwords and secret HTTP variables). */
|
|
103
|
+
function configOut(o) {
|
|
104
|
+
const c = { ...o.config };
|
|
105
|
+
if (isRecord(c.env))
|
|
106
|
+
c.env = Object.fromEntries(Object.keys(c.env).map((k) => [k, MASK]));
|
|
107
|
+
if (o.kind === 'cluster' && Array.isArray(c.members))
|
|
108
|
+
c.members = c.members.map((id) => objectsStore.get(String(id))?.name ?? id);
|
|
109
|
+
return c;
|
|
110
|
+
}
|
|
111
|
+
const resourceLine = (o) => ({ name: o.name, kind: o.kind, colony: colonyName(o.colony_id), status: o.state.status, detail: o.state.detail ?? null, manager: o.manager_id ? agentName(o.manager_id) : null });
|
|
112
|
+
// ---- input ----------------------------------------------------------------------------------------------------------------------------
|
|
113
|
+
function colonyInput(args, partial) {
|
|
114
|
+
const p = {};
|
|
115
|
+
for (const k of ['name', 'color', 'cwd', 'system_prompt'])
|
|
116
|
+
if (args[k] !== undefined)
|
|
117
|
+
p[k] = text(args[k]);
|
|
118
|
+
if (args.permission !== undefined)
|
|
119
|
+
p.permission = permissionArg(args.permission);
|
|
120
|
+
if (args.inherit !== undefined) {
|
|
121
|
+
if (!isRecord(args.inherit) || Object.entries(args.inherit).some(([k, v]) => !FIELDS.includes(k) || typeof v !== 'boolean'))
|
|
122
|
+
throw bad(`inherit takes true or false for ${FIELDS.join(', ')}`);
|
|
123
|
+
p.inherit = args.inherit;
|
|
124
|
+
}
|
|
125
|
+
if (args.skills !== undefined)
|
|
126
|
+
Object.assign(p, skillsArg(args.skills));
|
|
127
|
+
if (args.agents !== undefined) {
|
|
128
|
+
if (!partial)
|
|
129
|
+
throw bad('Create the colony first, then add agents with colony_update (or set their colony)');
|
|
130
|
+
if (!Array.isArray(args.agents))
|
|
131
|
+
throw bad('agents must be a list of agent names');
|
|
132
|
+
p.agent_ids = args.agents.map((n) => agentNamed(n).id);
|
|
133
|
+
}
|
|
134
|
+
return validateColony(p, partial);
|
|
135
|
+
}
|
|
136
|
+
function agentInput(args, cur) {
|
|
137
|
+
const p = {};
|
|
138
|
+
for (const k of ['name', 'description', 'role', 'provider', 'model', 'effort', 'cwd', 'system_prompt'])
|
|
139
|
+
if (args[k] !== undefined)
|
|
140
|
+
p[k] = args[k] === null ? '' : text(args[k]);
|
|
141
|
+
if (!cur) {
|
|
142
|
+
p.role ??= 'worker';
|
|
143
|
+
if (p.provider === undefined)
|
|
144
|
+
throw bad(`Choose the provider: ${Object.keys(PROVIDERS).join(', ')} (colony_options says which are installed)`);
|
|
145
|
+
}
|
|
146
|
+
if (args.permission !== undefined)
|
|
147
|
+
p.permission = permissionArg(args.permission);
|
|
148
|
+
if (args.browser !== undefined)
|
|
149
|
+
p.browser = args.browser;
|
|
150
|
+
if (args.colony !== undefined)
|
|
151
|
+
p.colony_id = colonyArg(args.colony);
|
|
152
|
+
if (args.overrides !== undefined) {
|
|
153
|
+
if (!Array.isArray(args.overrides) || args.overrides.some((f) => !FIELDS.includes(f)))
|
|
154
|
+
throw bad(`overrides must be a list of ${FIELDS.join(', ')}`);
|
|
155
|
+
p.overrides = [...new Set(args.overrides)];
|
|
156
|
+
}
|
|
157
|
+
if (args.skills !== undefined)
|
|
158
|
+
Object.assign(p, skillsArg(args.skills));
|
|
159
|
+
if (args.workers !== undefined) {
|
|
160
|
+
if ((p.role ?? cur?.role) !== 'orchestrator')
|
|
161
|
+
throw bad('Only an orchestrator has workers');
|
|
162
|
+
if (!Array.isArray(args.workers))
|
|
163
|
+
throw bad('workers must be a list of agent names');
|
|
164
|
+
p.worker_ids = args.workers.map((n) => agentNamed(n).id);
|
|
165
|
+
if (cur && p.worker_ids.includes(cur.id))
|
|
166
|
+
throw bad('An orchestrator cannot be its own worker');
|
|
167
|
+
}
|
|
168
|
+
return validateAgentInput(p, !!cur);
|
|
169
|
+
}
|
|
170
|
+
/** Names that reach Object.prototype when used as a key: refused for the environments, variables and env keys an agent sends. */
|
|
171
|
+
const RESERVED = ['__proto__', 'constructor', 'prototype'];
|
|
172
|
+
const plainName = (what, k) => { if (RESERVED.includes(k))
|
|
173
|
+
throw bad(`${what} cannot be named ${k}`); };
|
|
174
|
+
/** A secret written here would stay in the conversation: database passwords and the values of secret HTTP variables come from the web app. */
|
|
175
|
+
function refuseSecrets(kind, config) {
|
|
176
|
+
if (!isRecord(config))
|
|
177
|
+
return;
|
|
178
|
+
if (kind === 'database' && typeof config.password === 'string' && config.password !== '')
|
|
179
|
+
throw bad(NO_SECRETS);
|
|
180
|
+
if (kind === 'http' && isRecord(config.variables)) {
|
|
181
|
+
for (const vars of Object.values(config.variables))
|
|
182
|
+
if (isRecord(vars))
|
|
183
|
+
for (const v of Object.values(vars))
|
|
184
|
+
if (isRecord(v) && v.secret && typeof v.value === 'string' && v.value !== '')
|
|
185
|
+
throw bad(NO_SECRETS);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* `variables` of an HTTP resource, merged by environment and by name with the saved ones (masked: a secret comes empty and the store keeps
|
|
190
|
+
* its value). A variable that is not sent stays; a plain one is removed by sending it (or its whole environment) as null. A saved secret
|
|
191
|
+
* cannot be removed, emptied or made plain from here: the person does that in the web app.
|
|
192
|
+
*/
|
|
193
|
+
function mergeVariables(saved, incoming) {
|
|
194
|
+
if (incoming === null)
|
|
195
|
+
incoming = Object.fromEntries(Object.keys(isRecord(saved) ? saved : {}).map((env) => [env, null]));
|
|
196
|
+
if (!isRecord(incoming))
|
|
197
|
+
throw bad('variables must be an object: { environment: { NAME: { value, secret } } }');
|
|
198
|
+
// Without a prototype, a name sent by the client (`__proto__`, `constructor`) can only be an own key, never Object.prototype.
|
|
199
|
+
const out = Object.create(null);
|
|
200
|
+
for (const [env, vars] of Object.entries(isRecord(saved) ? saved : {}))
|
|
201
|
+
out[env] = Object.assign(Object.create(null), vars);
|
|
202
|
+
const secretOf = (env, k) => { const v = Object.hasOwn(out, env) ? out[env][k] : undefined; return isRecord(v) && !!v.secret; };
|
|
203
|
+
const refuse = (env, k) => bad(`${env}.${k} is a secret saved in the web app: it cannot be removed, emptied or made plain from here. Ask the person to do it in the web app.`);
|
|
204
|
+
for (const [env, vars] of Object.entries(incoming)) {
|
|
205
|
+
plainName('An environment', env);
|
|
206
|
+
if (vars === null) {
|
|
207
|
+
const secret = Object.keys(out[env] ?? {}).find((k) => secretOf(env, k));
|
|
208
|
+
if (secret)
|
|
209
|
+
throw refuse(env, secret);
|
|
210
|
+
delete out[env];
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (!isRecord(vars))
|
|
214
|
+
throw bad(`variables.${env} must be an object of NAME: { value, secret } (or null to remove it)`);
|
|
215
|
+
const cur = out[env] ?? Object.create(null);
|
|
216
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
217
|
+
plainName('A variable', k);
|
|
218
|
+
if (v !== null && !isRecord(v))
|
|
219
|
+
throw bad(`variables.${env}.${k} must be { value, secret } (or null to remove it)`);
|
|
220
|
+
if (secretOf(env, k)) {
|
|
221
|
+
if (!v || !v.secret)
|
|
222
|
+
throw refuse(env, k);
|
|
223
|
+
cur[k] = { value: '', secret: true };
|
|
224
|
+
}
|
|
225
|
+
else if (v === null)
|
|
226
|
+
delete cur[k];
|
|
227
|
+
else
|
|
228
|
+
cur[k] = v;
|
|
229
|
+
}
|
|
230
|
+
out[env] = cur;
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
/** Cluster members by name (ids still work). */
|
|
235
|
+
function membersById(config) {
|
|
236
|
+
if (!isRecord(config) || !Array.isArray(config.members))
|
|
237
|
+
return config;
|
|
238
|
+
return { ...config, members: config.members.map((m) => objectsStore.get(String(m))?.id ?? objectsStore.byName(trimmed(m))?.id ?? m) };
|
|
239
|
+
}
|
|
240
|
+
// ---- deleting -------------------------------------------------------------------------------------------------------------------------
|
|
241
|
+
const confirmed = (name, confirm) => confirm !== undefined && confirm !== null && same(name, confirm);
|
|
242
|
+
const notYet = (name, what) => ({ deleted: false, name, would_delete: what });
|
|
243
|
+
const count = (sql, id) => db.prepare(sql).get(id).n;
|
|
244
|
+
const plural = (n, one) => `${n} ${one}${n === 1 ? '' : 's'}`;
|
|
245
|
+
function deleteColony(a, args) {
|
|
246
|
+
const c = colonyNamed(args.name);
|
|
247
|
+
if (a.colony_id === c.id)
|
|
248
|
+
throw bad(`"${c.name}" is your own colony: deleting it would take away your folder, permission, skills and prompt. Ask the person to do it from the web app.`);
|
|
249
|
+
const members = c.agent_ids.map((id) => agents.get(id)).filter(Boolean);
|
|
250
|
+
const stranded = members.filter((m) => !m.cwd.trim()).map((m) => m.name);
|
|
251
|
+
if (!confirmed(c.name, args.confirm)) {
|
|
252
|
+
return notYet(c.name, `the colony "${c.name}". Its agents are NOT deleted: ${members.length ? `${members.map((m) => m.name).join(', ')} would be left without a colony` : 'it has none'}${stranded.length ? `, and ${stranded.join(', ')} would have no working folder (they could not run until they get one)` : ''}. Its own skill assignments and prompt go with it; its resources stay, without a colony.`);
|
|
253
|
+
}
|
|
254
|
+
removeColony(c.id);
|
|
255
|
+
return { deleted: true, name: c.name, left_without_colony: members.map((m) => m.name), without_folder: members.filter((m) => !agents.get(m.id)?.effective.cwd).map((m) => m.name) };
|
|
256
|
+
}
|
|
257
|
+
function deleteAgent(a, args) {
|
|
258
|
+
const t = agentNamed(args.name);
|
|
259
|
+
if (t.id === a.id)
|
|
260
|
+
throw bad('You cannot delete yourself: ask the person to do it from the web app.');
|
|
261
|
+
if (t.worker_ids.includes(a.id))
|
|
262
|
+
throw bad(`"${t.name}" is your orchestrator: deleting it would cancel the task you are working on. Ask the person to do it from the web app.`);
|
|
263
|
+
const open = db.prepare("SELECT from_id, to_id, task FROM dispatches WHERE status IN ('queued','running') AND ((from_id=? AND to_id=?) OR (from_id=? AND to_id=?))").get(a.id, t.id, t.id, a.id);
|
|
264
|
+
if (open)
|
|
265
|
+
throw bad(`"${t.name}" has a task open with you (${agentName(open.from_id)} to ${agentName(open.to_id)}: "${open.task.replace(/\s+/g, ' ').slice(0, 80)}"). Wait until it ends or cancel it first.`);
|
|
266
|
+
const links = linkedTo(t.id);
|
|
267
|
+
if (links.length)
|
|
268
|
+
throw bad(`"${t.name}" is linked to a chat connection (${links.map((c) => c.name).join(', ')}): deleting it would switch off that channel. Ask the person to do it from the web app.`);
|
|
269
|
+
if (!confirmed(t.name, args.confirm)) {
|
|
270
|
+
const sessions = agents.sessions(t.id).length, notes = notebooks.get(t.id).content.trim().length;
|
|
271
|
+
const schedules = count('SELECT COUNT(*) n FROM agent_schedules WHERE agent_id=?', t.id), wakeups = count('SELECT COUNT(*) n FROM agent_wakeups WHERE agent_id=?', t.id);
|
|
272
|
+
const managed = listObjects().filter((o) => o.manager_id === t.id).map((o) => o.name), bosses = bossesOf(t.id).map((o) => o.name);
|
|
273
|
+
return notYet(t.name, `the agent "${t.name}" (${t.role}, ${t.provider}): its record of ${plural(sessions, 'conversation')} (the CLI's own files stay), ${notes ? 'its notebook' : 'its empty notebook'}, ${plural(schedules, 'schedule')} and ${plural(wakeups, 'pending wake-up')}${bosses.length ? `; it stops being a worker of ${bosses.join(', ')}` : ''}${t.worker_ids.length ? `; its team (${t.worker_ids.map(agentName).join(', ')}) is unlinked, not deleted` : ''}${managed.length ? `; ${managed.join(', ')} go back to their colony's agents` : ''}. A turn it is running is stopped.`);
|
|
274
|
+
}
|
|
275
|
+
removeAgent(t.id);
|
|
276
|
+
return { deleted: true, name: t.name };
|
|
277
|
+
}
|
|
278
|
+
async function deleteResource(args) {
|
|
279
|
+
const o = resourceNamed(args.name);
|
|
280
|
+
if (!confirmed(o.name, args.confirm)) {
|
|
281
|
+
return notYet(o.name, `the ${o.kind} resource "${o.name}"${o.kind === 'server' ? ': it is stopped first' : o.kind === 'docker' ? ': its container is stopped, and removed if hive-am created it' : o.kind === 'database' ? ': the database itself is not touched, only hive-am forgets the connection, its saved queries and history' : ''}.`);
|
|
282
|
+
}
|
|
283
|
+
await removeObject(o.id);
|
|
284
|
+
return { deleted: true, name: o.name };
|
|
285
|
+
}
|
|
286
|
+
// ---- the operations -------------------------------------------------------------------------------------------------------------------
|
|
287
|
+
async function options(args) {
|
|
288
|
+
const status = await providerStatus();
|
|
289
|
+
const wanted = args.provider !== undefined ? (isProvider(args.provider) ? [args.provider] : (() => { throw bad(`Unknown provider "${text(args.provider)}"`); })()) : status.filter((p) => p.installed).map((p) => p.id);
|
|
290
|
+
const providers = await Promise.all(status.map(async (p) => {
|
|
291
|
+
if (!wanted.includes(p.id))
|
|
292
|
+
return { id: p.id, installed: p.installed, version: p.version };
|
|
293
|
+
const model = args.provider === p.id ? text(args.model) : '';
|
|
294
|
+
const efforts = effortOptions(p.id, model);
|
|
295
|
+
return { id: p.id, installed: p.installed, version: p.version, models: (await listModels(p.id)).map((m) => m.id), efforts: efforts.options.map((v) => v.id), efforts_known: efforts.known };
|
|
296
|
+
}));
|
|
297
|
+
return {
|
|
298
|
+
providers, roles: ['orchestrator', 'worker'], permissions: { plan: 'Read-only (Plan mode)', acceptEdits: 'Edit files', bypassPermissions: 'Full access' },
|
|
299
|
+
inherit_fields: FIELDS, skill_loads: ['always', 'on_demand'], resource_kinds: ['server', 'docker', 'http', 'database', 'cluster'],
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
export async function agentColonies(op, body) {
|
|
303
|
+
const a = whoAsks(body.from);
|
|
304
|
+
const args = { ...body };
|
|
305
|
+
delete args.from;
|
|
306
|
+
switch (String(op ?? '')) {
|
|
307
|
+
case 'options': return options(args);
|
|
308
|
+
case 'list': return { colonies: colonies.list().map(colonyLine) };
|
|
309
|
+
case 'get': return colonyOut(colonyNamed(args.name));
|
|
310
|
+
case 'create': return { created: true, colony: colonyOut(createColony(colonyInput(args, false))) };
|
|
311
|
+
case 'update': {
|
|
312
|
+
const c = colonyNamed(args.name), p = { ...args };
|
|
313
|
+
delete p.name;
|
|
314
|
+
if (args.new_name !== undefined) {
|
|
315
|
+
p.name = args.new_name;
|
|
316
|
+
delete p.new_name;
|
|
317
|
+
}
|
|
318
|
+
return { updated: true, colony: colonyOut(keepingAccess(a, () => updateColony(c.id, colonyInput(p, true)))) };
|
|
319
|
+
}
|
|
320
|
+
case 'delete': return deleteColony(a, args);
|
|
321
|
+
case 'agent_list': {
|
|
322
|
+
const col = args.colony === undefined ? undefined : colonyArg(args.colony);
|
|
323
|
+
return { agents: agents.list().filter((x) => col === undefined || (x.colony_id ?? null) === col).map(agentLine) };
|
|
324
|
+
}
|
|
325
|
+
case 'agent_get': return agentOut(agentNamed(args.name));
|
|
326
|
+
case 'agent_create': return { created: true, agent: agentOut(createAgent(agentInput(args))) };
|
|
327
|
+
case 'agent_update': {
|
|
328
|
+
const t = agentNamed(args.name), p = { ...args };
|
|
329
|
+
delete p.name;
|
|
330
|
+
if (args.new_name !== undefined) {
|
|
331
|
+
p.name = args.new_name;
|
|
332
|
+
delete p.new_name;
|
|
333
|
+
}
|
|
334
|
+
const input = agentInput(p, t);
|
|
335
|
+
return { updated: true, agent: agentOut(keepingAccess(a, () => updateAgent(t.id, input))) };
|
|
336
|
+
}
|
|
337
|
+
case 'agent_delete': return deleteAgent(a, args);
|
|
338
|
+
case 'skill_list': {
|
|
339
|
+
const usage = skills.usage();
|
|
340
|
+
return { skills: skills.list().map((s) => ({ name: s.name, description: s.description, load: s.load, agents: usage[s.id]?.agents ?? 0, types: usage[s.id]?.types ?? 0 })) };
|
|
341
|
+
}
|
|
342
|
+
case 'resource_list': {
|
|
343
|
+
const col = args.colony === undefined ? undefined : colonyArg(args.colony);
|
|
344
|
+
return { resources: listObjects().filter((o) => col === undefined || (o.colony_id ?? null) === col).map(resourceLine) };
|
|
345
|
+
}
|
|
346
|
+
case 'resource_get': {
|
|
347
|
+
const o = resourceNamed(args.name);
|
|
348
|
+
return { ...resourceLine(o), config: configOut(o) };
|
|
349
|
+
}
|
|
350
|
+
case 'resource_create': {
|
|
351
|
+
const kind = kindOf(args.kind);
|
|
352
|
+
if (!isKind(kind))
|
|
353
|
+
throw bad('kind must be server, docker, http, database or cluster');
|
|
354
|
+
refuseSecrets(kind, args.config);
|
|
355
|
+
const made = createObject({ name: args.name, kind, colony_id: args.colony === undefined ? null : colonyArg(args.colony), config: membersById(args.config) });
|
|
356
|
+
return { created: true, resource: { ...resourceLine(made), config: configOut(made) } };
|
|
357
|
+
}
|
|
358
|
+
case 'resource_update': {
|
|
359
|
+
const o = resourceNamed(args.name);
|
|
360
|
+
if (args.config !== undefined && !isRecord(args.config))
|
|
361
|
+
throw bad('config must be an object with the fields to change');
|
|
362
|
+
refuseSecrets(o.kind, args.config);
|
|
363
|
+
const p = {};
|
|
364
|
+
if (args.new_name !== undefined)
|
|
365
|
+
p.name = args.new_name;
|
|
366
|
+
if (args.colony !== undefined)
|
|
367
|
+
p.colony_id = colonyArg(args.colony);
|
|
368
|
+
if (args.config !== undefined) {
|
|
369
|
+
// Only the keys sent change. It starts from the masked config, so an empty password or secret is kept by the store as it does for the web
|
|
370
|
+
// app; HTTP `variables` are merged by environment and name.
|
|
371
|
+
const stored = objectsStore.get(o.id), base = { ...maskConfig(stored).config };
|
|
372
|
+
delete base.passwordSet;
|
|
373
|
+
const next = { ...base, ...membersById(args.config) };
|
|
374
|
+
if (o.kind === 'http' && args.config.variables !== undefined)
|
|
375
|
+
next.variables = mergeVariables(base.variables, args.config.variables);
|
|
376
|
+
// `env` is replaced whole (its values are not shown): the keys to keep are sent as ***, which only stands for a key already saved.
|
|
377
|
+
const savedEnv = stored.config.env ?? {};
|
|
378
|
+
if (isRecord(next.env))
|
|
379
|
+
next.env = Object.fromEntries(Object.entries(next.env).map(([k, v]) => {
|
|
380
|
+
plainName('An env variable', k);
|
|
381
|
+
if (v !== MASK)
|
|
382
|
+
return [k, v];
|
|
383
|
+
if (!Object.hasOwn(savedEnv, k))
|
|
384
|
+
throw bad(`env ${k} is not saved, so *** has nothing to keep: give it a value (or leave it out)`);
|
|
385
|
+
return [k, savedEnv[k]];
|
|
386
|
+
}));
|
|
387
|
+
p.config = next;
|
|
388
|
+
}
|
|
389
|
+
const v = updateObject(o.id, p);
|
|
390
|
+
return { updated: true, resource: { ...resourceLine(v), config: configOut(v) } };
|
|
391
|
+
}
|
|
392
|
+
case 'resource_delete': return deleteResource(args);
|
|
393
|
+
case 'resource_manager': {
|
|
394
|
+
const o = resourceNamed(args.name);
|
|
395
|
+
const r = setObjectManager(o.id, isNone(args.agent) ? null : agentNamed(args.agent).id);
|
|
396
|
+
if (r.skillAdded)
|
|
397
|
+
notifyAgentsChanged();
|
|
398
|
+
return { name: o.name, manager: r.object.manager_id ? agentName(r.object.manager_id) : null, skill_added: r.skillAdded };
|
|
399
|
+
}
|
|
400
|
+
default: throw bad(`Unknown operation "${text(op)}"`);
|
|
401
|
+
}
|
|
402
|
+
}
|