@fish-under-sea/dsh-agent-teams-fish 1.0.2 → 2.0.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/NOTICE.md +13 -7
- package/README.en.md +20 -12
- package/README.md +20 -12
- package/compatibility.json +82 -46
- package/icon.png +0 -0
- package/lib/artifacts.js +148 -25
- package/lib/client/ActivityPanel.js +26 -5
- package/lib/client/WorkspaceActivity.js +6 -4
- package/lib/client/activity-monitor.js +113 -41
- package/lib/client/locales.js +14 -0
- package/lib/client.js +433 -199
- package/lib/client.js.map +1 -1
- package/lib/command.js +7 -4
- package/lib/git-artifact-stamp.json +2 -2
- package/lib/harness-compat.js +120 -62
- package/lib/index.js +7 -10
- package/lib/mailbox.js +15 -5
- package/lib/members.js +221 -154
- package/lib/snapshot.js +15 -10
- package/lib/state.js +41 -8
- package/lib/tools.js +123 -64
- package/lib/types/artifacts.d.ts +6 -3
- package/lib/types/client/activity-monitor.d.ts +13 -4
- package/lib/types/client/locales.d.ts +14 -0
- package/lib/types/harness-compat.d.ts +63 -16
- package/lib/types/mailbox.d.ts +2 -0
- package/lib/types/members.d.ts +5 -17
- package/lib/types/snapshot.d.ts +12 -7
- package/lib/types/state.d.ts +10 -3
- package/lib/types/types.d.ts +5 -0
- package/lib/types/web-routes.d.ts +2 -0
- package/lib/types/workspace-audit-service.d.ts +35 -0
- package/lib/types/workspace-audit-worker.d.ts +1 -0
- package/lib/web-routes.js +31 -0
- package/lib/workspace-audit-service.js +165 -0
- package/lib/workspace-audit-worker.js +11 -0
- package/lib/workspace-audit.js +6 -5
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +69 -64
- package/pnpm-workspace.yaml +306 -273
- package/release-notes/v0.1.25.md +16 -0
- package/release-notes/v0.1.26.md +19 -0
- package/release-notes/v0.1.27.md +42 -0
- package/release-notes/v0.1.28.md +45 -0
- package/release-notes/v0.1.29.md +23 -0
- package/release-notes/v1.1.0.md +42 -0
- package/release-notes/v2.0.0.md +17 -0
- package/scripts/artwork-role-match.test.mjs +517 -0
- package/scripts/capabilities.test.mjs +301 -0
- package/scripts/check-install-channel.mjs +55 -0
- package/scripts/check-install-channel.test.mjs +39 -0
- package/scripts/clean-build.mjs +14 -0
- package/scripts/client-harness-migration.test.mjs +46 -0
- package/scripts/compatibility.mjs +20 -0
- package/scripts/compatibility.test.mjs +187 -0
- package/scripts/corrupt-teamjson.test.mjs +180 -0
- package/scripts/custom-artwork.test.mjs +273 -0
- package/scripts/fallback-tdd.mjs +61 -0
- package/scripts/fixtures/harness-benchmark-scope.mjs +16 -0
- package/scripts/fixtures/harness-benchmark-scope.test.mjs +18 -0
- package/scripts/fixtures/harness-complex-case.mjs +201 -0
- package/scripts/fixtures/harness-complex-case.test.mjs +21 -0
- package/scripts/fixtures/harness-complex-oracle.mjs +63 -0
- package/scripts/fixtures/harness-issue-case.mjs +51 -0
- package/scripts/fixtures/harness-issue159-case.mjs +28 -0
- package/scripts/fixtures/harness-model-case.mjs +127 -0
- package/scripts/fixtures/harness-model-case.test.mjs +37 -0
- package/scripts/fixtures/harness-model-driver.mjs +100 -0
- package/scripts/fixtures/harness-runtime-credentials.mjs +23 -0
- package/scripts/fixtures/harness-runtime-entry.mjs +171 -0
- package/scripts/fixtures/harness-runtime-idle.mjs +42 -0
- package/scripts/fixtures/harness-runtime-llm.mjs +193 -0
- package/scripts/fixtures/harness-runtime-protocol.mjs +187 -0
- package/scripts/fixtures/harness-runtime-resume.mjs +24 -0
- package/scripts/fixtures/harness-runtime-stability.mjs +282 -0
- package/scripts/fixtures/harness-runtime-tools.mjs +13 -0
- package/scripts/fixtures/harness-runtime-web-approval.mjs +341 -0
- package/scripts/fixtures/issue-336-audit-worker.mjs +18 -0
- package/scripts/git-artifacts.mjs +64 -0
- package/scripts/git-artifacts.test.mjs +32 -0
- package/scripts/harness-compat-tdd.mjs +492 -0
- package/scripts/harness-issue-verify.mjs +26 -0
- package/scripts/harness-model-benchmark.mjs +163 -0
- package/scripts/harness-runtime-platform.test.mjs +31 -0
- package/scripts/harness-runtime-scenarios.mjs +297 -0
- package/scripts/harness-runtime-verify.mjs +169 -0
- package/scripts/harness-source-verify.mjs +211 -0
- package/scripts/harness-source-verify.test.mjs +97 -0
- package/scripts/harness-validation.mjs +68 -0
- package/scripts/harness-validation.test.mjs +95 -0
- package/scripts/http-body.test.mjs +72 -0
- package/scripts/import-vendor-artwork.mjs +78 -0
- package/scripts/inline-plan-blank-optional-tdd.mjs +121 -0
- package/scripts/issue-159.test.mjs +78 -0
- package/scripts/issue-188.test.mjs +148 -0
- package/scripts/issue-189.test.mjs +100 -0
- package/scripts/issue-203-card.test.mjs +181 -0
- package/scripts/issue-205.test.mjs +163 -0
- package/scripts/issue-234.test.mjs +424 -0
- package/scripts/issue-236-stale-module.test.mjs +63 -0
- package/scripts/issue-236.test.mjs +59 -0
- package/scripts/issue-262.test.mjs +98 -0
- package/scripts/issue-336.test.mjs +404 -0
- package/scripts/legacy-session-source-repair.test.mjs +201 -0
- package/scripts/lifecycle-verify.mjs +1573 -0
- package/scripts/lineage-identity.test.mjs +77 -0
- package/scripts/member-failure-tdd.mjs +451 -0
- package/scripts/member-spawn-recovery.test.mjs +92 -0
- package/scripts/quality-gates-amend.test.mjs +161 -0
- package/scripts/quality-gates-content-bound.test.mjs +572 -0
- package/scripts/quality-gates-cross-binding.test.mjs +184 -0
- package/scripts/quality-gates-excluded-scope.test.mjs +163 -0
- package/scripts/quality-gates-repair-scope.test.mjs +143 -0
- package/scripts/quality-gates-repair-wiring.test.mjs +189 -0
- package/scripts/quality-gates-tdd.mjs +1238 -0
- package/scripts/quality-gates-work-order.test.mjs +494 -0
- package/scripts/readme-version.mjs +89 -0
- package/scripts/readme-version.test.mjs +77 -0
- package/scripts/release-metadata.mjs +45 -0
- package/scripts/release-metadata.test.mjs +66 -0
- package/scripts/scoped-release.test.mjs +52 -0
- package/scripts/stability-tdd.mjs +144 -0
- package/scripts/stress-verify.mjs +548 -0
- package/scripts/symlink-support.mjs +46 -0
- package/scripts/sync-skill.mjs +103 -0
- package/scripts/tool-policies.test.mjs +280 -0
- package/scripts/update-skills.mjs +105 -0
- package/scripts/update-skills.test.mjs +79 -0
- package/scripts/upgrade-status.mjs +66 -0
- package/scripts/upgrade-status.test.mjs +83 -0
- package/scripts/verify-package.mjs +73 -0
- package/scripts/verify.mjs +2199 -0
- package/scripts/web-routes-verify.mjs +142 -0
- package/scripts/workspace-activity.test.mjs +346 -0
- package/scripts/workspace-summary.test.mjs +49 -0
- package/src/artifacts.ts +487 -0
- package/src/artwork-source.ts +262 -0
- package/src/capabilities.ts +113 -0
- package/src/client/ActivityPanel.module.css +2390 -0
- package/src/client/ActivityPanel.tsx +1507 -0
- package/src/client/AgentTeamsCard.module.css +148 -0
- package/src/client/AgentTeamsCard.tsx +155 -0
- package/src/client/StagingPlanEditor.tsx +829 -0
- package/src/client/TeamChatEntry.tsx +27 -0
- package/src/client/WorkspaceActivity.module.css +41 -0
- package/src/client/WorkspaceActivity.tsx +137 -0
- package/src/client/activity-model.ts +372 -0
- package/src/client/activity-monitor.ts +440 -0
- package/src/client/agent-teams-card-definition.ts +250 -0
- package/src/client/artwork.ts +374 -0
- package/src/client/icons.tsx +17 -0
- package/src/client/index.tsx +140 -0
- package/src/client/locales.ts +481 -0
- package/src/client/panel-geometry.ts +194 -0
- package/src/client/session-navigation.ts +73 -0
- package/src/client/workspace-state.ts +52 -0
- package/src/command.ts +145 -0
- package/src/css-modules.d.ts +4 -0
- package/src/event-types.ts +177 -0
- package/src/events.ts +78 -0
- package/src/harness-compat.ts +570 -0
- package/src/index.ts +599 -0
- package/src/lineage.ts +248 -0
- package/src/mailbox.ts +185 -0
- package/src/members.ts +1230 -0
- package/src/profiles.ts +765 -0
- package/src/quality-gates.ts +2124 -0
- package/src/scheduler.ts +554 -0
- package/src/snapshot.ts +333 -0
- package/src/state.ts +1317 -0
- package/src/tool-names.ts +14 -0
- package/src/tool-policies.ts +219 -0
- package/src/tools.ts +2939 -0
- package/src/types.ts +414 -0
- package/src/web-routes.ts +128 -0
- package/src/workspace-audit-service.ts +182 -0
- package/src/workspace-audit-worker.ts +12 -0
- package/src/workspace-audit.ts +57 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentTeams for DeepSeek Harness.
|
|
3
|
+
*
|
|
4
|
+
* A host-plane plugin that registers the `agent_teams_*` tools and one usage
|
|
5
|
+
* agent-scoped usage section. Each session keeps a stable tool set and core
|
|
6
|
+
* instructions. Existing business tools cover the complete team lifecycle.
|
|
7
|
+
* After installation any session can
|
|
8
|
+
* run multi-agent teamwork through natural language (e.g. "use AgentTeams to research X"):
|
|
9
|
+
* the model creates a team (it becomes the captain), spawns members as
|
|
10
|
+
* durable continuable subagents, breaks the goal into tasks with
|
|
11
|
+
* dependencies, wakes members with messages, relays reports, and collects
|
|
12
|
+
* results.
|
|
13
|
+
*
|
|
14
|
+
* Installation (bundle): `dsh plugin --profile <name> add dsh-agent-teams-fish`
|
|
15
|
+
* (or a local path). The bundle patch mounts this plugin row into the host
|
|
16
|
+
* composition; the tools register into the shared `tools` registry and the
|
|
17
|
+
* usage section into the global system prompt, so the plugin needs no realm.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-agent-teams
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
23
|
+
import z from '@deepseek-ai/schemastery'
|
|
24
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
25
|
+
// Declaration merges make ctx.subagents and ctx.systemPrompt visible.
|
|
26
|
+
import type {} from '@deepseek-ai/dsh-subagent'
|
|
27
|
+
import type {} from '@deepseek-ai/dsh-system-prompt'
|
|
28
|
+
import type { WorkspaceRegistry } from '@deepseek-ai/dsh-workspace'
|
|
29
|
+
import {
|
|
30
|
+
haltTeamWork,
|
|
31
|
+
stagedPlanApprovedContext,
|
|
32
|
+
registerAgentTeamsTools,
|
|
33
|
+
type StagedPlanMutation,
|
|
34
|
+
type ToolsConfig,
|
|
35
|
+
} from './tools.ts'
|
|
36
|
+
import { installAgentTeamsGestureBoundary, registerAgentTeamsCommand } from './command.ts'
|
|
37
|
+
import { join, resolve } from 'node:path'
|
|
38
|
+
import { fileURLToPath } from 'node:url'
|
|
39
|
+
import { collectArchivedTeamsActivity, collectTeamsActivity } from './snapshot.ts'
|
|
40
|
+
import { findTeamByCaptain } from './state.ts'
|
|
41
|
+
import { leadIdentityOfAsync } from './lineage.ts'
|
|
42
|
+
import { formatProfilesForPrompt, type TeamProfileConfig } from './profiles.ts'
|
|
43
|
+
import { parseToolPolicies, type MemberToolPolicy } from './tool-policies.ts'
|
|
44
|
+
import { installTeamCapabilities } from './capabilities.ts'
|
|
45
|
+
import { agentTeamsSource, observedSessionFormatVersion } from './harness-compat.ts'
|
|
46
|
+
import { TEAM_TOOL_NAMES } from './tool-names.ts'
|
|
47
|
+
import { artworkCandidates, findCustomArtwork, findPackagedArtwork } from './artwork-source.ts'
|
|
48
|
+
|
|
49
|
+
import { authenticatedWebRoutes, readJsonRequest, RequestBodyError, writeJsonWithEtag, type BrowserRequestGate, type WebRouteHost } from './web-routes.ts'
|
|
50
|
+
|
|
51
|
+
/** Web-server service key candidates, newest first. */
|
|
52
|
+
const WEB_SERVER_KEYS = ['webServer', 'httpServer'] as const
|
|
53
|
+
/** Workspace registry service key candidates, newest first. */
|
|
54
|
+
const WORKSPACE_KEYS = ['workspaceRegistry', 'workspace'] as const
|
|
55
|
+
|
|
56
|
+
export const name = 'agent-teams'
|
|
57
|
+
export const inject = ['tools', 'llm', 'subagents', 'systemPrompt', 'agents']
|
|
58
|
+
|
|
59
|
+
/** Plugin configuration. */
|
|
60
|
+
export interface Config {
|
|
61
|
+
/**
|
|
62
|
+
* State directory name under the captain's workspace; team state lives at
|
|
63
|
+
* `<workspace>/<stateDir>/<teamId>/` (default `.agent-teams`).
|
|
64
|
+
*/
|
|
65
|
+
stateDir?: string
|
|
66
|
+
/** `ctx.subagents` provider used to spawn members; must support continuable children and personas (default `spawn`). */
|
|
67
|
+
memberProvider?: string
|
|
68
|
+
/**
|
|
69
|
+
* Optional model override applied to every member. The id is used verbatim.
|
|
70
|
+
* When the captain's provider does not advertise it, the provider that does
|
|
71
|
+
* is resolved from the live catalogs (only if exactly one advertises it);
|
|
72
|
+
* set `memberLlmProvider` to name the owner explicitly instead.
|
|
73
|
+
*/
|
|
74
|
+
memberModel?: string
|
|
75
|
+
/**
|
|
76
|
+
* LLM provider route that owns `memberModel`. Set this when the member model
|
|
77
|
+
* is served by a different provider than the captain's session; without it
|
|
78
|
+
* the captain's provider is only used if it actually advertises the model,
|
|
79
|
+
* and an ambiguous or unowned model fails with the provider catalogs instead
|
|
80
|
+
* of being silently paired with the captain's route (issue #189).
|
|
81
|
+
* Distinct from `memberProvider`, which is the subagent runtime backend.
|
|
82
|
+
*/
|
|
83
|
+
memberLlmProvider?: string
|
|
84
|
+
/** Prompt injected into member personas and automatic task assignments. */
|
|
85
|
+
executionPrompt?: string
|
|
86
|
+
/** Plugin-wide fallback route for unavailable member models. */
|
|
87
|
+
fallback?: import('./profiles.ts').TeamModelFallbackConfig
|
|
88
|
+
/** Member delegation depth cap (default `0`; `0` forbids delegation entirely). */
|
|
89
|
+
memberMaxDepth?: number
|
|
90
|
+
/** Team size cap in members (default `8`). */
|
|
91
|
+
maxMembers?: number
|
|
92
|
+
/** Named multi-role team profiles. */
|
|
93
|
+
profiles?: Record<string, TeamProfileConfig>
|
|
94
|
+
/**
|
|
95
|
+
* Reusable per-member tool policies declared by the deployment owner (#59),
|
|
96
|
+
* keyed by policy id. A member selects one by id (`tool_policy` on
|
|
97
|
+
* `agent_teams_add_member`, a plan member, or a profile member row); the
|
|
98
|
+
* Captain model can select an existing policy but never submit raw lists.
|
|
99
|
+
* `allow` keeps only the named global tools (the four coordination tools are
|
|
100
|
+
* always added); `deny` removes the named global tools. Captain-only tools
|
|
101
|
+
* stay denied either way.
|
|
102
|
+
*/
|
|
103
|
+
toolPolicies?: Record<string, MemberToolPolicy>
|
|
104
|
+
/** Prompt-section order for the usage policy (default `117`, after delegation policy). */
|
|
105
|
+
promptSectionOrder?: number
|
|
106
|
+
/**
|
|
107
|
+
* Register the deterministic `/agent-teams` activation surfaces (the
|
|
108
|
+
* closed-namespace slash command and the plain-text gesture boundary).
|
|
109
|
+
* Disable to keep the natural-language trigger as the only entry point.
|
|
110
|
+
*/
|
|
111
|
+
slashCommand?: boolean
|
|
112
|
+
/**
|
|
113
|
+
* Directory of custom mascot artwork that replaces the packaged whale
|
|
114
|
+
* images slug by slug (`team-lead-v2.png`, `member-<role>-v2.png`,
|
|
115
|
+
* `action-<state>-v2.png`). The `-v2` suffix is optional, and `.png`,
|
|
116
|
+
* `.webp`, `.jpg`, `.jpeg`, `.gif` and `.svg` are accepted. Relative paths
|
|
117
|
+
* resolve against the host process working directory; a slug without a
|
|
118
|
+
* matching file keeps the packaged artwork.
|
|
119
|
+
*/
|
|
120
|
+
artworkDir?: string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// `z.object()` has an implicit `{}` default in Schemastery. Fallback routes
|
|
124
|
+
// are optional, so model absence explicitly; otherwise a missing route is
|
|
125
|
+
// validated as an empty object and fails on the required provider/model keys.
|
|
126
|
+
const fallbackRouteConfig = z.union([
|
|
127
|
+
z.object({ provider: z.string().required(), model: z.string().required() }),
|
|
128
|
+
z.const(undefined),
|
|
129
|
+
])
|
|
130
|
+
|
|
131
|
+
// Same Schemastery defaulting trap for a tool policy: an `allow`-only policy
|
|
132
|
+
// would materialize `deny: []` and fail a `.min(1)` on an absent list. Model
|
|
133
|
+
// each accepted combination explicitly, so a policy that declares only one
|
|
134
|
+
// side stays valid while an empty side is still rejected.
|
|
135
|
+
const toolPolicyConfig = z.union([
|
|
136
|
+
z.object({ allow: z.array(z.string()).min(1).required(), deny: z.const(undefined) }),
|
|
137
|
+
z.object({ allow: z.const(undefined), deny: z.array(z.string()).min(1).required() }),
|
|
138
|
+
z.object({ allow: z.array(z.string()).min(1).required(), deny: z.array(z.string()).min(1).required() }),
|
|
139
|
+
])
|
|
140
|
+
|
|
141
|
+
export const Config: z<Config> = z.object({
|
|
142
|
+
stateDir: z.string().default('.agent-teams'),
|
|
143
|
+
memberProvider: z.string().default('spawn'),
|
|
144
|
+
memberModel: z.string(),
|
|
145
|
+
memberLlmProvider: z.string(),
|
|
146
|
+
executionPrompt: z.string(),
|
|
147
|
+
fallback: fallbackRouteConfig,
|
|
148
|
+
profiles: z.dict(z.object({
|
|
149
|
+
description: z.string(),
|
|
150
|
+
protocol: z.string(),
|
|
151
|
+
executionPrompt: z.string(),
|
|
152
|
+
fallback: fallbackRouteConfig,
|
|
153
|
+
members: z.array(z.object({
|
|
154
|
+
name: z.string().required(),
|
|
155
|
+
role: z.string(),
|
|
156
|
+
provider: z.string(),
|
|
157
|
+
model: z.string(),
|
|
158
|
+
reasoning_effort: z.string(),
|
|
159
|
+
executionPrompt: z.string(),
|
|
160
|
+
fallback: fallbackRouteConfig,
|
|
161
|
+
// Owner-declared tool-policy id this profile member selects (#59).
|
|
162
|
+
tool_policy: z.string(),
|
|
163
|
+
})).min(1).required(),
|
|
164
|
+
taskPlanning: z.union([z.const('captain'), z.const('seed')]),
|
|
165
|
+
reviewPolicy: z.object({
|
|
166
|
+
requirementsMinRounds: z.natural().min(1),
|
|
167
|
+
requirementsMaxRounds: z.natural().min(1),
|
|
168
|
+
codeMaxRounds: z.natural().min(1),
|
|
169
|
+
maxRepairAttempts: z.natural().min(1),
|
|
170
|
+
requiredReviewers: z.array(z.string()),
|
|
171
|
+
}),
|
|
172
|
+
tasks: z.array(z.object({
|
|
173
|
+
id: z.string().required(),
|
|
174
|
+
subject: z.string().required(),
|
|
175
|
+
description: z.string(),
|
|
176
|
+
assignee: z.string(),
|
|
177
|
+
dependencies: z.array(z.string()),
|
|
178
|
+
})),
|
|
179
|
+
})).default({}),
|
|
180
|
+
toolPolicies: z.dict(toolPolicyConfig).default({}),
|
|
181
|
+
memberMaxDepth: z.natural().default(0),
|
|
182
|
+
maxMembers: z.natural().min(1).default(8),
|
|
183
|
+
promptSectionOrder: z.natural().default(117),
|
|
184
|
+
slashCommand: z.boolean().default(true),
|
|
185
|
+
artworkDir: z.string(),
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
/** The model-facing usage policy: when and how to drive AgentTeams. */
|
|
189
|
+
export function usageSectionText(toolNames: string, profilesText = ''): string {
|
|
190
|
+
return `AgentTeams captain protocol:
|
|
191
|
+
1. Inspect current team state when needed, using agent_teams_status. Continue existing work without duplicating its roster/tasks. Create only when no current team exists, with the user's goal as description and approval="required"; automatic approval requires an explicit request to run immediately. Staged plans never spawn or schedule work.
|
|
192
|
+
2. Add each needed role once; members inherit your model route unless another is requested/needed. A requested profile goes to create({profile}); it supplies its roster. Seed profiles also supply tasks; captain-planning profiles require your DAG. Do not duplicate either. A member may also select one owner-declared tool policy by id (tool_policy on add_member, a plan member, or a profile member): it is the only way to change which global tools that member sees and may invoke, and you can never pass raw allow/deny lists.
|
|
193
|
+
3. Build the complete smallest useful DAG while staged. For an ordinary research/audit plan, pass the roster and dependency graph together in create({plan:{members,tasks}}) to avoid repeated setup rounds. Every task needs a subject; pass kind and assignee explicitly when the plan specifies them. Titles, descriptions and member roles do not set these fields. Dependencies represent prerequisites. Give every required contributor a task or explicit message. Present the plan and end your turn for review; never approve in that planning turn. Approve only after a later explicit user approval or the Web action.
|
|
194
|
+
4. Respect Web approve/return/discard control messages. On return, ask what to change before editing; after the answer, use one atomic agent_teams_edit_plan batch (edit downstream references before removals), summarize and await review again. Never inspect or edit .agent-teams state files or plugin source code to revise plans. Discard does not authorize a replacement.
|
|
195
|
+
5. The scheduler dispatches ready tasks after approval. Delegate; do not duplicate slow work or send messages merely to start a stage. Handle reports/user work, then yield when waiting is all that remains: reports wake you automatically. Use status after a delivery or user request, never busy-poll or wait for unassigned members.
|
|
196
|
+
6. Tasks carry attempt_id capabilities. Use the current attempt_id; stale means ownership changed. Pause members only on explicit request; later guidance via send_message continues that same attempt. Retry, transfer or take over through reassign_task first; it revokes the old attempt and waits for quiescence. Prefer a member. Captain implementation/review takeover requires a user request. Every takeover is one ready task at a time, finished in this turn; never yield with captain-owned work open.
|
|
197
|
+
7. In a running team, correct never-started pending tasks with edit_plan update_task; preserve dependency and ownership contracts instead of cancelling and recreating the graph. A captain can cancel a never-started pending task directly. Active attempts still require reassign_task. Quality kinds (requirements, implementation, verification, review, repair, integration) require objective + acceptance; implementation/repair also require inScope + verify. Derive paths/commands from the workspace/profile, never assume src/ or pnpm test. Review/requirements complete only with verdict=pass; needs_revision/reject fail with findings. Never approve your own implementation or ask for a deliberate failure. When a quality contract itself is wrong (a verify command that cannot pass, an inScope that forbids the file the objective requires), fix it with agent_teams_amend_task — captain-only, non-terminal tasks only, frozen after a passing review, and every amendment is recorded in the task's revisions ledger — instead of letting the worker dead-lock or game the gate.
|
|
198
|
+
8. When full quality mode is requested: requirements → implementation → verification → review → integration. Plan the entire DAG while staged, including implementation before requirements finishes and integration depending on review round 1. Failed review automatically adds repair + next review and rewires pending downstream gates. Do not recreate this loop, omit integration or depend on a failed task. Review acceptance judges the latest implementation. Do not put smoke-test scripts into task instructions.
|
|
199
|
+
9. Halted means the user stopped work (including the captain turn). Resume only on a later explicit user request with a reason, via agent_teams_resume or create_task({resume:true,resumeReason}); creating tasks alone never resumes. Escalated means the review loop hit its limit, not a halt. Deployment requires explicit user confirmation.
|
|
200
|
+
10. Wait for all required tasks to be terminal and members idle/ready, present results, then delete/archive unless the user wants to continue. Never discard unfinished work without authorization.
|
|
201
|
+
Tools: ${toolNames}${profilesText === '' ? '' : `\n\n${profilesText}`}`
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** One resolved artwork response: the bytes, their media type, and the cache policy. */
|
|
205
|
+
export interface ResolvedArtwork {
|
|
206
|
+
data: Buffer
|
|
207
|
+
contentType: string
|
|
208
|
+
cacheControl: string
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Resolve one artwork request into the bytes and media type to serve.
|
|
213
|
+
*
|
|
214
|
+
* Extracted from the HTTP handler so the degradation chain, the media type and
|
|
215
|
+
* the cache policy stay assertable without a live web server.
|
|
216
|
+
* @param name - requested artwork slug; foreign or unknown names resolve to undefined.
|
|
217
|
+
* @param options - the bundled artwork directory plus the optional custom override.
|
|
218
|
+
* @returns the response to serve, or undefined when nothing matched.
|
|
219
|
+
*/
|
|
220
|
+
export async function resolveArtwork(
|
|
221
|
+
name: string,
|
|
222
|
+
options: { artDir: string; customArtDir?: string },
|
|
223
|
+
): Promise<ResolvedArtwork | undefined> {
|
|
224
|
+
const candidates = artworkCandidates(name)
|
|
225
|
+
if (candidates.length === 0) return undefined
|
|
226
|
+
let data: Buffer | undefined
|
|
227
|
+
let contentType: string | undefined
|
|
228
|
+
let fromCustom = false
|
|
229
|
+
if (options.customArtDir !== undefined) {
|
|
230
|
+
for (const candidate of candidates) {
|
|
231
|
+
const hit = await findCustomArtwork(options.customArtDir, candidate)
|
|
232
|
+
if (hit !== undefined) {
|
|
233
|
+
data = hit.data
|
|
234
|
+
contentType = hit.contentType
|
|
235
|
+
fromCustom = true
|
|
236
|
+
break
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (data === undefined) {
|
|
241
|
+
for (const candidate of candidates) {
|
|
242
|
+
// The bundle may ship a member/leader candidate under another accepted
|
|
243
|
+
// extension (the `-full` preview family is WebP); probe like the custom
|
|
244
|
+
// directory does so one request answers every encoding of the same stem.
|
|
245
|
+
const hit = await findPackagedArtwork(options.artDir, candidate)
|
|
246
|
+
if (hit !== undefined) {
|
|
247
|
+
data = hit.data
|
|
248
|
+
contentType = hit.contentType
|
|
249
|
+
break
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (data === undefined) return undefined
|
|
254
|
+
return {
|
|
255
|
+
data,
|
|
256
|
+
contentType: contentType ?? 'application/octet-stream',
|
|
257
|
+
// A custom artwork directory can change any slug at any time — even slugs
|
|
258
|
+
// that also ship packaged, such as the captain avatar — so nothing may sit
|
|
259
|
+
// in the browser cache while one is configured, nor for bytes that came
|
|
260
|
+
// from it. Otherwise packaged bytes cached before a file was dropped in
|
|
261
|
+
// would keep winning for 24h, which looks exactly like a broken override.
|
|
262
|
+
cacheControl: fromCustom || options.customArtDir !== undefined ? 'no-store' : 'public, max-age=86400',
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function apply(ctx: Context, config: Config): void {
|
|
267
|
+
const resolved: ToolsConfig = {
|
|
268
|
+
stateDir: config.stateDir ?? '.agent-teams',
|
|
269
|
+
memberProvider: config.memberProvider ?? 'spawn',
|
|
270
|
+
memberModel: config.memberModel,
|
|
271
|
+
memberLlmProvider: config.memberLlmProvider,
|
|
272
|
+
executionPrompt: config.executionPrompt,
|
|
273
|
+
fallback: config.fallback,
|
|
274
|
+
memberMaxDepth: config.memberMaxDepth ?? 0,
|
|
275
|
+
maxMembers: config.maxMembers ?? 8,
|
|
276
|
+
profiles: config.profiles ?? {},
|
|
277
|
+
// Owner configuration is validated once, at mount: an empty or malformed
|
|
278
|
+
// policy must never reach a member creation path.
|
|
279
|
+
toolPolicies: parseToolPolicies(config.toolPolicies),
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Custom mascot artwork is optional: every slug the directory does not
|
|
283
|
+
// provide keeps the packaged whale image.
|
|
284
|
+
const customArtDir = config.artworkDir === undefined ? undefined : resolve(config.artworkDir)
|
|
285
|
+
if (customArtDir !== undefined) ctx.logger.info(`agent-teams: custom artwork directory ${customArtDir}`)
|
|
286
|
+
|
|
287
|
+
// Provider registration is a sibling plugin's effect (`subagent-spawn` /
|
|
288
|
+
// `subagent-fork` rows), which can land after this mount under the Loader's
|
|
289
|
+
// concurrent activation — so capability validation happens at the first
|
|
290
|
+
// member spawn (`spawnMember`), the earliest point the provider list is
|
|
291
|
+
// settled, rather than here.
|
|
292
|
+
|
|
293
|
+
const agentTeamsRuntime = registerAgentTeamsTools(ctx, resolved)
|
|
294
|
+
installTeamCapabilities(ctx, {
|
|
295
|
+
stateDir: resolved.stateDir,
|
|
296
|
+
isPendingMember: agentTeamsRuntime.isPendingMember,
|
|
297
|
+
order: config.promptSectionOrder,
|
|
298
|
+
// Keep the bounded profile directory available without extra tool calls.
|
|
299
|
+
// installTeamCapabilities snapshots this once; no business state rewrites it.
|
|
300
|
+
captainPrompt: () => usageSectionText(TEAM_TOOL_NAMES.join(', '), formatProfilesForPrompt(config.profiles)),
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
// Deterministic activation surfaces: the closed-namespace `/agent-teams`
|
|
304
|
+
// host command (surfaces in the Web GUI slash menu via the Harness
|
|
305
|
+
// ui-commands client) and the plain-text gesture boundary for surfaces
|
|
306
|
+
// without command adjudication (headless CLI). Both default on; a profile
|
|
307
|
+
// can disable them to keep the natural-language trigger exclusive.
|
|
308
|
+
//
|
|
309
|
+
// `commands` is registered lazily (not a required inject): it ships in the
|
|
310
|
+
// base bundle of every standard profile, but a minimal composition that
|
|
311
|
+
// omits the command registry keeps the plugin fully functional — the fiber
|
|
312
|
+
// never pends on it and simply never gains the slash command.
|
|
313
|
+
if (config.slashCommand ?? true) {
|
|
314
|
+
ctx.inject(['commands'], (commandCtx) => {
|
|
315
|
+
registerAgentTeamsCommand(commandCtx, () => config.profiles ?? {})
|
|
316
|
+
})
|
|
317
|
+
installAgentTeamsGestureBoundary(ctx, () => config.profiles ?? {})
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// The activity panel data/artwork routes need the Web server and the
|
|
321
|
+
// workspace registry, which headless profiles do not mount; under
|
|
322
|
+
// concurrent activation they may also bind after this plugin. Register the
|
|
323
|
+
// routes lazily: try now, then on each service binding event. In a webless
|
|
324
|
+
// profile the plugin stays tool-only and never blocks boot.
|
|
325
|
+
let webRegistered = false
|
|
326
|
+
const registerWebSurface = (): void => {
|
|
327
|
+
if (webRegistered) return
|
|
328
|
+
const rawWebServer = (ctx.get(WEB_SERVER_KEYS[0]) ?? ctx.get(WEB_SERVER_KEYS[1])) as WebRouteHost | undefined
|
|
329
|
+
const workspaceRegistry = (ctx.get(WORKSPACE_KEYS[0]) ?? ctx.get(WORKSPACE_KEYS[1])) as WorkspaceRegistry | undefined
|
|
330
|
+
if (rawWebServer === undefined || workspaceRegistry === undefined) return
|
|
331
|
+
const webServer = authenticatedWebRoutes(rawWebServer, () => ctx.get('connection') as BrowserRequestGate | undefined)
|
|
332
|
+
webRegistered = true
|
|
333
|
+
|
|
334
|
+
// Activity panel data route: the browser floater polls this for team
|
|
335
|
+
// snapshots (disk truth + live subagent activity). Mirrors the Claude
|
|
336
|
+
// Code desktop watcher's server-side snapshot pattern.
|
|
337
|
+
ctx.effect(() => webServer.register({
|
|
338
|
+
kind: 'exact',
|
|
339
|
+
path: '/plugins/dsh-agent-teams/state',
|
|
340
|
+
handler: async (req, res) => {
|
|
341
|
+
const url = new URL(req.url ?? '/', 'http://x')
|
|
342
|
+
const captainSessionId = url.searchParams.get('session')?.trim() || undefined
|
|
343
|
+
const roots = workspaceRegistry.list().map((workspace) => ({
|
|
344
|
+
workspace: workspace.title,
|
|
345
|
+
// The panel audits the same current bytes as agent_teams_status, so it
|
|
346
|
+
// cannot advertise a passing gate over a changed revision (#161).
|
|
347
|
+
workspacePath: workspace.path,
|
|
348
|
+
stateRoot: join(workspace.path, resolved.stateDir),
|
|
349
|
+
}))
|
|
350
|
+
// ?archived=1 serves teams moved to archive/ (post-delete review).
|
|
351
|
+
const snapshots = url.searchParams.get('archived') === '1'
|
|
352
|
+
? await collectArchivedTeamsActivity(ctx, roots, captainSessionId)
|
|
353
|
+
: await collectTeamsActivity(ctx, roots, captainSessionId, url.searchParams.get('summary') === '1')
|
|
354
|
+
writeJsonWithEtag(req, res, JSON.stringify({ teams: snapshots }))
|
|
355
|
+
},
|
|
356
|
+
}), 'agent-teams: activity route')
|
|
357
|
+
|
|
358
|
+
ctx.effect(() => webServer.register({
|
|
359
|
+
kind: 'exact',
|
|
360
|
+
path: '/plugins/dsh-agent-teams/halt',
|
|
361
|
+
handler: async (req, res) => {
|
|
362
|
+
if (req.method !== 'POST') {
|
|
363
|
+
res.writeHead(405, { allow: 'POST', 'cache-control': 'no-store' })
|
|
364
|
+
res.end()
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
let payload: Record<string, unknown>
|
|
368
|
+
try {
|
|
369
|
+
payload = await readJsonRequest(req)
|
|
370
|
+
} catch (error: unknown) {
|
|
371
|
+
res.writeHead(error instanceof RequestBodyError ? error.status : 400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
372
|
+
res.end(JSON.stringify({ error: error instanceof Error ? error.message : 'invalid request body' }))
|
|
373
|
+
return
|
|
374
|
+
}
|
|
375
|
+
const sessionId = typeof payload.sessionId === 'string' ? payload.sessionId.trim() : ''
|
|
376
|
+
const teamId = typeof payload.teamId === 'string' ? payload.teamId.trim() : ''
|
|
377
|
+
if (sessionId === '' || teamId === '') {
|
|
378
|
+
res.writeHead(400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
379
|
+
res.end(JSON.stringify({ error: 'sessionId and teamId are required' }))
|
|
380
|
+
return
|
|
381
|
+
}
|
|
382
|
+
const captain = ctx.agents.get(sessionId as import('@deepseek-ai/dsh-session').SessionId)
|
|
383
|
+
if (captain === undefined) {
|
|
384
|
+
res.writeHead(409, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
385
|
+
res.end(JSON.stringify({ error: 'captain session is not attached' }))
|
|
386
|
+
return
|
|
387
|
+
}
|
|
388
|
+
const workspace = captain.session.header.cwd ?? process.cwd()
|
|
389
|
+
const stateRoot = join(workspace, resolved.stateDir)
|
|
390
|
+
const team = await findTeamByCaptain(stateRoot, captain.id, await leadIdentityOfAsync(ctx, captain.session))
|
|
391
|
+
if (team === undefined || team.id !== teamId) {
|
|
392
|
+
res.writeHead(404, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
393
|
+
res.end(JSON.stringify({ error: 'team not found for this captain' }))
|
|
394
|
+
return
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
const result = await haltTeamWork({
|
|
398
|
+
ctx,
|
|
399
|
+
stateRoot,
|
|
400
|
+
teamId,
|
|
401
|
+
captain,
|
|
402
|
+
})
|
|
403
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
404
|
+
res.end(JSON.stringify(result))
|
|
405
|
+
} catch (error: unknown) {
|
|
406
|
+
ctx.logger.warn(`agent-teams: halt failed for ${teamId}: ${String(error)}`)
|
|
407
|
+
res.writeHead(500, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
408
|
+
res.end(JSON.stringify({ error: 'failed to stop the team' }))
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
}), 'agent-teams: halt route')
|
|
412
|
+
|
|
413
|
+
ctx.effect(() => webServer.register({
|
|
414
|
+
kind: 'exact',
|
|
415
|
+
path: '/plugins/dsh-agent-teams/plan',
|
|
416
|
+
handler: async (req, res) => {
|
|
417
|
+
if (req.method !== 'POST') {
|
|
418
|
+
res.writeHead(405, { allow: 'POST', 'cache-control': 'no-store' })
|
|
419
|
+
res.end()
|
|
420
|
+
return
|
|
421
|
+
}
|
|
422
|
+
let payload: Record<string, unknown>
|
|
423
|
+
try {
|
|
424
|
+
payload = await readJsonRequest(req)
|
|
425
|
+
} catch (error: unknown) {
|
|
426
|
+
res.writeHead(error instanceof RequestBodyError ? error.status : 400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
427
|
+
res.end(JSON.stringify({ error: error instanceof Error ? error.message : 'invalid request body' }))
|
|
428
|
+
return
|
|
429
|
+
}
|
|
430
|
+
const sessionId = typeof payload['sessionId'] === 'string' ? payload['sessionId'].trim() : ''
|
|
431
|
+
const teamId = typeof payload['teamId'] === 'string' ? payload['teamId'].trim() : ''
|
|
432
|
+
const action = typeof payload['action'] === 'string' ? payload['action'] : ''
|
|
433
|
+
if (sessionId === '' || teamId === '' || action === '') {
|
|
434
|
+
res.writeHead(400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
435
|
+
res.end(JSON.stringify({ error: 'sessionId, teamId, and action are required' }))
|
|
436
|
+
return
|
|
437
|
+
}
|
|
438
|
+
const captain = ctx.agents.get(sessionId as import('@deepseek-ai/dsh-session').SessionId)
|
|
439
|
+
if (captain === undefined) {
|
|
440
|
+
res.writeHead(409, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
441
|
+
res.end(JSON.stringify({ error: 'captain session is not attached' }))
|
|
442
|
+
return
|
|
443
|
+
}
|
|
444
|
+
const workspace = captain.session.header.cwd ?? process.cwd()
|
|
445
|
+
const stateRoot = join(workspace, resolved.stateDir)
|
|
446
|
+
const team = await findTeamByCaptain(stateRoot, captain.id, await leadIdentityOfAsync(ctx, captain.session))
|
|
447
|
+
if (team === undefined || team.id !== teamId) {
|
|
448
|
+
res.writeHead(404, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
449
|
+
res.end(JSON.stringify({ error: 'team not found for this captain' }))
|
|
450
|
+
return
|
|
451
|
+
}
|
|
452
|
+
try {
|
|
453
|
+
if (action === 'approve') {
|
|
454
|
+
const approved = await agentTeamsRuntime.approveStagedTeam(captain, teamId)
|
|
455
|
+
// The browser receives the HTTP result, so the model needs its own
|
|
456
|
+
// control message. steer wakes an idle captain or joins its next
|
|
457
|
+
// step; the tool approve path already returns to the model itself.
|
|
458
|
+
try {
|
|
459
|
+
captain.steer(createUserMessage({
|
|
460
|
+
content: [{ type: 'text', text: stagedPlanApprovedContext(team.name) }],
|
|
461
|
+
source: agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(captain)),
|
|
462
|
+
}))
|
|
463
|
+
} catch (error) {
|
|
464
|
+
// Approval is already committed. Do not report a failed approval
|
|
465
|
+
// and invite a retry that could duplicate the user's action.
|
|
466
|
+
ctx.logger.warn(`agent-teams: approval notification failed for ${teamId}: ${String(error)}`)
|
|
467
|
+
}
|
|
468
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
469
|
+
res.end(JSON.stringify({ ok: true, phase: 'running', ...approved }))
|
|
470
|
+
return
|
|
471
|
+
}
|
|
472
|
+
if (action === 'continue') {
|
|
473
|
+
const continued = await agentTeamsRuntime.continueStagedPlanning(captain, teamId)
|
|
474
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
475
|
+
res.end(JSON.stringify({ ok: true, phase: 'staged', review: 'awaiting_feedback', ...continued }))
|
|
476
|
+
return
|
|
477
|
+
}
|
|
478
|
+
if (action === 'discard') {
|
|
479
|
+
const discarded = await agentTeamsRuntime.discardStagedTeam(captain, teamId)
|
|
480
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
481
|
+
res.end(JSON.stringify({ ok: true, phase: 'archived', ...discarded }))
|
|
482
|
+
return
|
|
483
|
+
}
|
|
484
|
+
const dependencies = Array.isArray(payload['dependencies'])
|
|
485
|
+
? payload['dependencies'].filter((item): item is string => typeof item === 'string')
|
|
486
|
+
: []
|
|
487
|
+
let mutation: StagedPlanMutation
|
|
488
|
+
if (action === 'update_member') {
|
|
489
|
+
if (typeof payload['memberName'] !== 'string'
|
|
490
|
+
|| typeof payload['provider'] !== 'string'
|
|
491
|
+
|| typeof payload['model'] !== 'string') throw new Error('memberName, provider, and model are required')
|
|
492
|
+
mutation = {
|
|
493
|
+
action,
|
|
494
|
+
memberName: payload['memberName'],
|
|
495
|
+
provider: payload['provider'],
|
|
496
|
+
model: payload['model'],
|
|
497
|
+
...typeof payload['role'] === 'string' || payload['role'] === null ? { role: payload['role'] as string | null } : {},
|
|
498
|
+
...typeof payload['reasoningEffort'] === 'string' || payload['reasoningEffort'] === null
|
|
499
|
+
? { reasoningEffort: payload['reasoningEffort'] as string | null }
|
|
500
|
+
: {},
|
|
501
|
+
...typeof payload['executionPrompt'] === 'string' || payload['executionPrompt'] === null
|
|
502
|
+
? { executionPrompt: payload['executionPrompt'] as string | null }
|
|
503
|
+
: {},
|
|
504
|
+
...typeof payload['tool_policy'] === 'string' ? { toolPolicy: payload['tool_policy'] } : {},
|
|
505
|
+
}
|
|
506
|
+
} else if (action === 'update_task') {
|
|
507
|
+
if (typeof payload['taskId'] !== 'string' || typeof payload['subject'] !== 'string') {
|
|
508
|
+
throw new Error('taskId and subject are required')
|
|
509
|
+
}
|
|
510
|
+
mutation = {
|
|
511
|
+
action,
|
|
512
|
+
taskId: payload['taskId'],
|
|
513
|
+
subject: payload['subject'],
|
|
514
|
+
dependencies,
|
|
515
|
+
...typeof payload['description'] === 'string' || payload['description'] === null
|
|
516
|
+
? { description: payload['description'] as string | null }
|
|
517
|
+
: {},
|
|
518
|
+
...typeof payload['assignee'] === 'string' || payload['assignee'] === null
|
|
519
|
+
? { assignee: payload['assignee'] as string | null }
|
|
520
|
+
: {},
|
|
521
|
+
}
|
|
522
|
+
} else if (action === 'add_task') {
|
|
523
|
+
if (typeof payload['subject'] !== 'string') throw new Error('subject is required')
|
|
524
|
+
mutation = {
|
|
525
|
+
action,
|
|
526
|
+
subject: payload['subject'],
|
|
527
|
+
dependencies,
|
|
528
|
+
...typeof payload['description'] === 'string' || payload['description'] === null
|
|
529
|
+
? { description: payload['description'] as string | null }
|
|
530
|
+
: {},
|
|
531
|
+
...typeof payload['assignee'] === 'string' || payload['assignee'] === null
|
|
532
|
+
? { assignee: payload['assignee'] as string | null }
|
|
533
|
+
: {},
|
|
534
|
+
}
|
|
535
|
+
} else if (action === 'remove_task') {
|
|
536
|
+
if (typeof payload['taskId'] !== 'string') throw new Error('taskId is required')
|
|
537
|
+
mutation = { action, taskId: payload['taskId'] }
|
|
538
|
+
} else {
|
|
539
|
+
throw new Error(`unknown plan action "${action}"`)
|
|
540
|
+
}
|
|
541
|
+
const updated = await agentTeamsRuntime.updateStagedPlan(captain, teamId, mutation)
|
|
542
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
543
|
+
res.end(JSON.stringify({ ok: true, phase: updated.phase, members: updated.members.length, tasks: updated.tasks.length }))
|
|
544
|
+
} catch (error: unknown) {
|
|
545
|
+
res.writeHead(409, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
546
|
+
res.end(JSON.stringify({ error: error instanceof Error ? error.message : 'plan operation failed' }))
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
}), 'agent-teams: plan route')
|
|
550
|
+
|
|
551
|
+
// Mascot artwork: serve the role/action images to the activity panel. The
|
|
552
|
+
// bundled whale images ship with the bundle (files: assets/); an optional
|
|
553
|
+
// `artworkDir` replaces them slug by slug, and the vendor namespace
|
|
554
|
+
// (`member-<vendor>-<role>`, `team-lead-<vendor>`) lets one role look
|
|
555
|
+
// different per model vendor. Only slugs this module knows reach the
|
|
556
|
+
// filesystem, so no other name can be read.
|
|
557
|
+
const artDir = fileURLToPath(new URL('../assets/agent-teams/', import.meta.url))
|
|
558
|
+
ctx.effect(() => webServer.register({
|
|
559
|
+
kind: 'prefix',
|
|
560
|
+
path: '/plugins/dsh-agent-teams/assets',
|
|
561
|
+
handler: async (req, res) => {
|
|
562
|
+
let name: string
|
|
563
|
+
try {
|
|
564
|
+
name = decodeURIComponent(new URL(req.url ?? '/', 'http://x').pathname.split('/').pop() ?? '')
|
|
565
|
+
} catch {
|
|
566
|
+
// Malformed percent-encoding: treat as an unknown asset, not a 400.
|
|
567
|
+
res.writeHead(404)
|
|
568
|
+
res.end()
|
|
569
|
+
return
|
|
570
|
+
}
|
|
571
|
+
// Most specific slug first: vendor+role, then role, then vendor, then the
|
|
572
|
+
// packaged whale. A missing combination degrades instead of breaking.
|
|
573
|
+
if (artworkCandidates(name).length === 0) {
|
|
574
|
+
res.writeHead(404)
|
|
575
|
+
res.end()
|
|
576
|
+
return
|
|
577
|
+
}
|
|
578
|
+
try {
|
|
579
|
+
const resolved = await resolveArtwork(name, { artDir, customArtDir })
|
|
580
|
+
if (resolved === undefined) throw new Error(`no artwork shipped for ${name}`)
|
|
581
|
+
res.writeHead(200, { 'content-type': resolved.contentType, 'cache-control': resolved.cacheControl })
|
|
582
|
+
res.end(resolved.data)
|
|
583
|
+
} catch (error: unknown) {
|
|
584
|
+
ctx.logger.warn(`agent-teams: artwork read failed for ${name}: ${String(error)}`)
|
|
585
|
+
res.writeHead(404)
|
|
586
|
+
res.end()
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
}), 'agent-teams: artwork route')
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
registerWebSurface()
|
|
593
|
+
ctx.on('internal/service', (name) => {
|
|
594
|
+
if (WEB_SERVER_KEYS.includes(name as (typeof WEB_SERVER_KEYS)[number])
|
|
595
|
+
|| WORKSPACE_KEYS.includes(name as (typeof WORKSPACE_KEYS)[number])) {
|
|
596
|
+
registerWebSurface()
|
|
597
|
+
}
|
|
598
|
+
})
|
|
599
|
+
}
|