@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/lib/members.js
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
* which the captain reads through `agent_teams_status`.
|
|
12
12
|
* @module dsh-agent-teams/members
|
|
13
13
|
*/
|
|
14
|
-
import { installModelSelection } from '@deepseek-ai/dsh-agent';
|
|
15
14
|
// Declaration merge only: makes ctx.subagents visible.
|
|
16
15
|
import { foldSubagentDescriptor } from '@deepseek-ai/dsh-subagent';
|
|
17
16
|
import { createUserMessage, LlmError, ReasoningEffortId } from '@deepseek-ai/dsh-llm';
|
|
17
|
+
import { randomUUID } from 'node:crypto';
|
|
18
18
|
import { join } from 'node:path';
|
|
19
|
-
import { assertMemberModelSelection, guardSubagentCreation, guardSubagentDelivery, installContinuableMemberSetup, memberToolFilter, queueMemberPrompt, restrictableToolNames,
|
|
19
|
+
import { agentTeamsSource, assertMemberModelSelection, observedSessionFormatVersion, outputLimitTurn, guardSubagentCreation, installMemberModelSelection, startMember, usesManagedActivations, guardSubagentDelivery, installContinuableMemberSetup, memberToolFilter, queueMemberPrompt, restrictableToolNames, startMemberWithLenientFilter, steerMemberPrompt, sessionOwnEvents } from "./harness-compat.js";
|
|
20
20
|
import { markMailboxDelivered, appendMailbox, CAPTAIN_KEY, createMessage, readRetiredMemberIds, readTeamSync, readTeam, releaseMailboxDelivery, withTeamLock, writeTeam } from "./state.js";
|
|
21
21
|
import { mailboxPrompt } from "./mailbox.js";
|
|
22
22
|
import { nearestLiveLead } from "./lineage.js";
|
|
@@ -95,34 +95,6 @@ export function composeMemberRoute(request, captain) {
|
|
|
95
95
|
derivedProvider: providerSource === 'captain' && modelSource === 'config',
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
-
/** 拒绝损坏的历史策略,不把非法 allow/deny 当成无限制。 */
|
|
99
|
-
function normalizeToolFilter(value) {
|
|
100
|
-
if (typeof value !== 'object' || value === null || !('deny' in value) || !Array.isArray(value.deny)
|
|
101
|
-
|| value.deny.some((name) => typeof name !== 'string')
|
|
102
|
-
|| ('allow' in value && (!Array.isArray(value.allow) || value.allow.some((name) => typeof name !== 'string')))
|
|
103
|
-
|| Object.keys(value).some(key => key !== 'allow' && key !== 'deny')) {
|
|
104
|
-
throw new Error('agent-teams: invalid member composition toolFilter');
|
|
105
|
-
}
|
|
106
|
-
const filter = value;
|
|
107
|
-
return { deny: [...filter.deny], ...filter.allow === undefined ? {} : { allow: [...filter.allow] } };
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Rebuild the composition a preset-only host must install on cold resume.
|
|
111
|
-
* `team.json` is the durable authority: the member record keeps the exact
|
|
112
|
-
* filter the host accepted, and the persona is deterministic from the same
|
|
113
|
-
* durable team/member fields the spawn used. A record without a filter is
|
|
114
|
-
* refused instead of resumed with an unrestricted tool set.
|
|
115
|
-
* @param team - the durable team owning the member.
|
|
116
|
-
* @param memberName - the member identity decoded from the child label.
|
|
117
|
-
* @param stateDir - configured state directory (part of the persona).
|
|
118
|
-
* @param executionPrompt - plugin-wide execution prompt, a persona input.
|
|
119
|
-
*/
|
|
120
|
-
function durableMemberComposition(team, memberName, stateDir, executionPrompt) {
|
|
121
|
-
const member = team.members.find(item => item.name === memberName && item.status !== 'removed');
|
|
122
|
-
if (member?.toolFilter === undefined)
|
|
123
|
-
return undefined;
|
|
124
|
-
return { persona: memberPersona(team, member, stateDir, executionPrompt), toolFilter: normalizeToolFilter(member.toolFilter) };
|
|
125
|
-
}
|
|
126
98
|
/**
|
|
127
99
|
* Validate a resolved roster against every provider catalog before any child
|
|
128
100
|
* session is created. Catalogs are advisory when empty (some adapters accept
|
|
@@ -147,7 +119,11 @@ export async function validateMemberLlmSelections(ctx, selections, signal) {
|
|
|
147
119
|
}
|
|
148
120
|
}
|
|
149
121
|
const MEMBER_LABEL_PREFIX = 'agent-teams:';
|
|
150
|
-
const FALLBACK_FAILURE_CODES = new Set([
|
|
122
|
+
const FALLBACK_FAILURE_CODES = new Set([
|
|
123
|
+
'QUOTA', 'RATE_LIMIT', 'AUTH', 'MISSING_CREDENTIAL', 'NO_ADAPTER',
|
|
124
|
+
// The account-backed DeepSeek adapter remaps equivalent provider failures.
|
|
125
|
+
'ACCOUNT_QUOTA', 'ACCOUNT_TOKEN_INVALID', 'ACCOUNT_SIGN_IN_REQUIRED',
|
|
126
|
+
]);
|
|
151
127
|
export function isFallbackFailureCode(code) {
|
|
152
128
|
return FALLBACK_FAILURE_CODES.has(code);
|
|
153
129
|
}
|
|
@@ -163,7 +139,7 @@ export function steerCaptainReport(captain, from, content, receipt) {
|
|
|
163
139
|
try {
|
|
164
140
|
captain.steer(createUserMessage({
|
|
165
141
|
content: [{ type: 'text', text: receipt ?? `AgentTeams message from member ${from}:\n\n${content}` }],
|
|
166
|
-
source: { kind: 'agent-teams' },
|
|
142
|
+
source: agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(captain)),
|
|
167
143
|
}));
|
|
168
144
|
return true;
|
|
169
145
|
}
|
|
@@ -196,6 +172,8 @@ export function classifyMemberFailure(observed, current) {
|
|
|
196
172
|
return 'ignored';
|
|
197
173
|
const task = current.task;
|
|
198
174
|
if (task === undefined) {
|
|
175
|
+
if (observed.openAttemptOnly === true)
|
|
176
|
+
return 'ignored';
|
|
199
177
|
// No open attempt is owned by this generation any more, so nothing here may
|
|
200
178
|
// be mutated — but the failure itself must still be recorded. `working` is
|
|
201
179
|
// NOT evidence of newer work: `syncMemberStatus` writes it as soon as the
|
|
@@ -276,6 +254,10 @@ export async function failMemberOpenAttempt(ctx, stateRoot, teamId, memberName,
|
|
|
276
254
|
if (disposition === 'ignored')
|
|
277
255
|
return;
|
|
278
256
|
if (disposition === 'failed_attempt' && task !== undefined) {
|
|
257
|
+
// Historical records may lack a capability id. Bind this failure report
|
|
258
|
+
// to the terminal attempt so a later retry invalidates unread mail.
|
|
259
|
+
if (observed.openAttemptOnly === true)
|
|
260
|
+
task.attemptId ??= randomUUID();
|
|
279
261
|
task.status = 'failed';
|
|
280
262
|
task.output = summary;
|
|
281
263
|
task.updatedAt = Date.now();
|
|
@@ -291,6 +273,9 @@ export async function failMemberOpenAttempt(ctx, stateRoot, teamId, memberName,
|
|
|
291
273
|
: undefined;
|
|
292
274
|
const message = {
|
|
293
275
|
...createMessage(memberName, CAPTAIN_KEY, memberFailureMessage(memberName, summary, disposition, task, settledRecord)),
|
|
276
|
+
...observed.openAttemptOnly === true && task?.attemptId !== undefined
|
|
277
|
+
? { sourceTaskId: task.id, sourceAttemptId: task.attemptId, sourceTaskStatus: 'failed' }
|
|
278
|
+
: {},
|
|
294
279
|
deliveryClaimedAt: Date.now(),
|
|
295
280
|
};
|
|
296
281
|
if (disposition === 'failed_attempt')
|
|
@@ -322,20 +307,34 @@ export async function failMemberOpenAttempt(ctx, stateRoot, teamId, memberName,
|
|
|
322
307
|
: releaseMailboxDelivery(stateRoot, teamId, CAPTAIN_KEY, [prepared.message.id]));
|
|
323
308
|
return true;
|
|
324
309
|
}
|
|
325
|
-
async function
|
|
326
|
-
|
|
310
|
+
async function commitFallbackRoute(stateRoot, teamId, memberName, child, fallback, signal, ctx, activate) {
|
|
311
|
+
return withTeamLock(`team:${stateRoot}:${teamId}`, async () => {
|
|
327
312
|
const team = await readTeam(stateRoot, teamId);
|
|
328
|
-
if (team === undefined)
|
|
329
|
-
return;
|
|
330
|
-
const member = team.members.find(candidate => candidate.name === memberName);
|
|
331
|
-
if (member === undefined)
|
|
332
|
-
return;
|
|
313
|
+
if (signal.aborted || team === undefined || team.captainSessionId !== child.session.header.parentSession || team.halted === true)
|
|
314
|
+
return false;
|
|
315
|
+
const member = team.members.find(candidate => candidate.name === memberName && candidate.id === child.id);
|
|
316
|
+
if (member === undefined || member.status === 'removed' || member.stopping === true)
|
|
317
|
+
return false;
|
|
333
318
|
member.activeProvider = fallback.provider;
|
|
334
319
|
member.activeModel = fallback.model;
|
|
335
320
|
member.fallbackActive = true;
|
|
336
|
-
|
|
321
|
+
let committed = false;
|
|
322
|
+
const onCommit = () => {
|
|
323
|
+
committed = true;
|
|
324
|
+
activate();
|
|
325
|
+
};
|
|
326
|
+
try {
|
|
327
|
+
await writeTeam(stateRoot, team, { signal, onCommit });
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
if (committed)
|
|
331
|
+
throw error;
|
|
332
|
+
ctx.logger.warn(`agent-teams: failed to persist fallback route: ${String(error)}`);
|
|
333
|
+
if (!signal.aborted)
|
|
334
|
+
onCommit();
|
|
335
|
+
}
|
|
336
|
+
return committed;
|
|
337
337
|
});
|
|
338
|
-
void ctx;
|
|
339
338
|
}
|
|
340
339
|
function pendingSelectionKey(parentSessionId, label) {
|
|
341
340
|
return `${parentSessionId}\u0000${label}`;
|
|
@@ -529,14 +528,10 @@ function describeMemberRouteFailure(provider, model, error) {
|
|
|
529
528
|
* cold resume restores the same selection from the owning team's durable
|
|
530
529
|
* record. Legacy members without a complete saved route retain Harness's
|
|
531
530
|
* descriptor provider/model behavior.
|
|
532
|
-
* @param ctx - the plugin context (injects `subagents`).
|
|
533
|
-
* @param stateDir - configured state directory, read for cold-resume snapshots.
|
|
534
|
-
* @param onFailureSettled - settlement hook after a member turn failure.
|
|
535
|
-
* @param executionPrompt - plugin-wide execution prompt (a persona input).
|
|
536
531
|
*/
|
|
537
|
-
export function installMemberSelectionRuntime(ctx, stateDir, onFailureSettled
|
|
532
|
+
export function installMemberSelectionRuntime(ctx, stateDir, onFailureSettled) {
|
|
538
533
|
const pending = new Map();
|
|
539
|
-
const
|
|
534
|
+
const pendingSetup = new Map();
|
|
540
535
|
installContinuableMemberSetup(ctx, (childCtx, child) => {
|
|
541
536
|
const descriptor = foldSubagentDescriptor(sessionOwnEvents(child.session));
|
|
542
537
|
if (descriptor?.mode !== 'continuable' || !descriptor.label.startsWith(MEMBER_LABEL_PREFIX)) {
|
|
@@ -554,51 +549,6 @@ export function installMemberSelectionRuntime(ctx, stateDir, onFailureSettled, e
|
|
|
554
549
|
const workspace = child.session.header.cwd ?? process.cwd();
|
|
555
550
|
const stateRoot = join(workspace, stateDir);
|
|
556
551
|
const key = pendingSelectionKey(parentSessionId, descriptor.label);
|
|
557
|
-
const runtimeCapabilities = ctx.subagents.getProvider?.(descriptor.provider)?.capabilities;
|
|
558
|
-
// A preset-only host advertises only `agentPreset`/`agentOptions`/... and
|
|
559
|
-
// therefore cannot apply the persona or the tool filter from the start
|
|
560
|
-
// request. The plugin owns both: it installs them here, before the first
|
|
561
|
-
// request, for a fresh child and for every cold resume.
|
|
562
|
-
const presetOnly = runtimeCapabilities?.agentPreset === true
|
|
563
|
-
&& runtimeCapabilities.persona === undefined && runtimeCapabilities.toolFilter === undefined;
|
|
564
|
-
const emptyComposition = () => undefined;
|
|
565
|
-
let disposeComposition = emptyComposition;
|
|
566
|
-
if (presetOnly) {
|
|
567
|
-
// The in-memory snapshot exists only while the spawn is materializing;
|
|
568
|
-
// a cold resume rebuilds the same composition from durable team.json.
|
|
569
|
-
const durable = readTeamSync(stateRoot, teamId);
|
|
570
|
-
const composition = compositions.get(key)
|
|
571
|
-
?? (durable?.captainSessionId === parentSessionId
|
|
572
|
-
? durableMemberComposition(durable, memberName, stateDir, executionPrompt)
|
|
573
|
-
: undefined);
|
|
574
|
-
if (composition === undefined) {
|
|
575
|
-
throw new Error(`agent-teams: member "${memberName}" has no durable composition snapshot (tool filter) in team.json, `
|
|
576
|
-
+ 'so this preset-only host cannot resume it with the intended persona and tool isolation; re-add the member');
|
|
577
|
-
}
|
|
578
|
-
const releaseFilter = childCtx.tools.restrict(composition.toolFilter);
|
|
579
|
-
try {
|
|
580
|
-
const releasePersona = childCtx.systemPrompt.section({
|
|
581
|
-
name: 'deployment:persona-prefix',
|
|
582
|
-
order: childCtx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX'),
|
|
583
|
-
text: composition.persona,
|
|
584
|
-
});
|
|
585
|
-
let disposed = false;
|
|
586
|
-
disposeComposition = () => {
|
|
587
|
-
if (disposed)
|
|
588
|
-
return;
|
|
589
|
-
disposed = true;
|
|
590
|
-
releasePersona();
|
|
591
|
-
releaseFilter();
|
|
592
|
-
};
|
|
593
|
-
childCtx.effect(() => disposeComposition, 'agent-teams: member composition');
|
|
594
|
-
}
|
|
595
|
-
catch (error) {
|
|
596
|
-
disposeComposition();
|
|
597
|
-
if (disposeComposition === emptyComposition)
|
|
598
|
-
releaseFilter();
|
|
599
|
-
throw error;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
552
|
// Internal settlement wakeups bypass the public delivery guard. Recheck
|
|
603
553
|
// exact durable membership on every proposed step, including cold resume.
|
|
604
554
|
const disposeAdmission = childCtx.on('agent/pre-step', async (payload, next) => {
|
|
@@ -614,28 +564,57 @@ export function installMemberSelectionRuntime(ctx, stateDir, onFailureSettled, e
|
|
|
614
564
|
return { kind: 'reject' };
|
|
615
565
|
return next();
|
|
616
566
|
});
|
|
567
|
+
// New activations no longer persist persona/toolFilter in host descriptors.
|
|
568
|
+
// Install them before the first request, and restore the exact saved values
|
|
569
|
+
// after a cold resume. Historical descriptors remain owned by Harness.
|
|
570
|
+
const savedTeam = pending.has(key) ? undefined : readTeamSync(stateRoot, teamId);
|
|
571
|
+
const savedMember = savedTeam?.captainSessionId === parentSessionId
|
|
572
|
+
? savedTeam.members.find(member => member.id === child.id && member.name === memberName)
|
|
573
|
+
: undefined;
|
|
574
|
+
const setup = pendingSetup.get(key) ?? savedMember?.runtimeSetup;
|
|
575
|
+
if (usesManagedActivations(ctx.subagents) && savedMember !== undefined
|
|
576
|
+
&& setup === undefined && descriptor.toolFilter === undefined) {
|
|
577
|
+
disposeAdmission();
|
|
578
|
+
throw new Error('agent-teams: saved member runtime setup is missing; refusing an unrestricted resume');
|
|
579
|
+
}
|
|
580
|
+
let disposeSetup = () => undefined;
|
|
581
|
+
if (usesManagedActivations(ctx.subagents) && setup !== undefined) {
|
|
582
|
+
try {
|
|
583
|
+
const stopFilter = childCtx.tools.restrict(setup.toolFilter);
|
|
584
|
+
try {
|
|
585
|
+
const stopPersona = childCtx.systemPrompt.section({
|
|
586
|
+
name: 'deployment:persona-prefix',
|
|
587
|
+
order: childCtx.systemPrompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX'),
|
|
588
|
+
text: setup.persona,
|
|
589
|
+
});
|
|
590
|
+
disposeSetup = () => { stopPersona(); stopFilter(); };
|
|
591
|
+
}
|
|
592
|
+
catch (error) {
|
|
593
|
+
stopFilter();
|
|
594
|
+
throw error;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
catch (error) {
|
|
598
|
+
disposeAdmission();
|
|
599
|
+
throw error;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const cleanupAdmission = () => { disposeSetup(); disposeAdmission(); };
|
|
617
603
|
let selection = pending.get(key);
|
|
618
604
|
if (selection === undefined) {
|
|
619
605
|
const team = readTeamSync(stateRoot, teamId);
|
|
620
606
|
if (team?.captainSessionId !== parentSessionId)
|
|
621
|
-
return
|
|
607
|
+
return cleanupAdmission;
|
|
622
608
|
const durableMember = team.members.find(member => member.name === memberName);
|
|
623
609
|
selection = selectionFromMember(durableMember);
|
|
624
610
|
if (selection !== undefined && (descriptor.agentProvider !== durableMember?.provider || descriptor.agentModel !== durableMember?.model)) {
|
|
625
611
|
throw new Error(`agent-teams: saved model route for member "${memberName}" does not match its subagent descriptor`);
|
|
626
612
|
}
|
|
627
613
|
}
|
|
628
|
-
|
|
629
|
-
// Harness emits agent/error only after request recovery is exhausted. In
|
|
630
|
-
// particular, llm-retry's "always" policy calls downstream request-error
|
|
631
|
-
// listeners before it retries; that waterfall cannot declare a turn dead.
|
|
632
|
-
const disposeFailure = childCtx.on('agent/error', async (payload) => {
|
|
633
|
-
if (payload.agent.id !== child.id || payload.turn === lastFailedTurn)
|
|
634
|
-
return;
|
|
635
|
-
lastFailedTurn = payload.turn;
|
|
614
|
+
const observeFailedAttempt = () => {
|
|
636
615
|
try {
|
|
637
|
-
// Capture the
|
|
638
|
-
// can
|
|
616
|
+
// Capture the capability synchronously, before a handoff or lock wait
|
|
617
|
+
// can move the member to another task attempt.
|
|
639
618
|
const snapshot = readTeamSync(stateRoot, teamId);
|
|
640
619
|
if (snapshot?.captainSessionId !== parentSessionId)
|
|
641
620
|
return;
|
|
@@ -644,16 +623,22 @@ export function installMemberSelectionRuntime(ctx, stateDir, onFailureSettled, e
|
|
|
644
623
|
return;
|
|
645
624
|
const task = snapshot.tasks.find(item => item.assignee === memberName
|
|
646
625
|
&& (item.status === 'claimed' || item.status === 'in_progress'));
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
};
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
626
|
+
return { captainSessionId: parentSessionId, memberId: child.id, task };
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
ctx.logger.warn(`agent-teams: failed to observe member turn failure: ${String(error)}`);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
let lastFailedTurn;
|
|
633
|
+
const recordFailure = async (turn, failure, observed) => {
|
|
634
|
+
if (turn === lastFailedTurn)
|
|
635
|
+
return;
|
|
636
|
+
lastFailedTurn = turn;
|
|
637
|
+
try {
|
|
638
|
+
const recorded = await failMemberOpenAttempt(ctx, stateRoot, teamId, memberName, failure, child.session, observed);
|
|
654
639
|
if (!recorded)
|
|
655
640
|
return;
|
|
656
|
-
// The
|
|
641
|
+
// The failure event precedes driver quiescence. Observe the real
|
|
657
642
|
// lifecycle and kick explicitly even if its idle event was missed.
|
|
658
643
|
// Never force an active Agent's status to idle or retry the failed task.
|
|
659
644
|
await child.whenIdle();
|
|
@@ -672,65 +657,137 @@ export function installMemberSelectionRuntime(ctx, stateDir, onFailureSettled, e
|
|
|
672
657
|
catch (error) {
|
|
673
658
|
ctx.logger.warn(`agent-teams: failed to record member turn failure: ${String(error)}`);
|
|
674
659
|
}
|
|
660
|
+
};
|
|
661
|
+
// Harness emits agent/error only after request recovery is exhausted. In
|
|
662
|
+
// particular, llm-retry's "always" policy calls downstream request-error
|
|
663
|
+
// listeners before it retries; that waterfall cannot declare a turn dead.
|
|
664
|
+
const disposeFailure = childCtx.on('agent/error', (payload) => {
|
|
665
|
+
if (payload.agent.id !== child.id || payload.turn === lastFailedTurn)
|
|
666
|
+
return;
|
|
667
|
+
const observed = observeFailedAttempt();
|
|
668
|
+
if (observed === undefined)
|
|
669
|
+
return;
|
|
670
|
+
const failure = payload.error instanceof LlmError ? payload.error.failure : {
|
|
671
|
+
code: 'UNKNOWN',
|
|
672
|
+
message: payload.error instanceof Error ? payload.error.message : String(payload.error),
|
|
673
|
+
};
|
|
674
|
+
return recordFailure(payload.turn, failure, observed);
|
|
675
|
+
});
|
|
676
|
+
let cappedAttempt;
|
|
677
|
+
const disposeOutputLimit = childCtx.on('session/event', (session, event) => {
|
|
678
|
+
if (session !== child.session)
|
|
679
|
+
return;
|
|
680
|
+
// The host's turn reason stays max-tokens even if fresh steering runs
|
|
681
|
+
// another step. Only the last executed step can leave an attempt stuck.
|
|
682
|
+
if (event.type === 'step/start')
|
|
683
|
+
cappedAttempt = undefined;
|
|
684
|
+
const turn = outputLimitTurn(event);
|
|
685
|
+
if (turn !== undefined) {
|
|
686
|
+
const observed = observeFailedAttempt();
|
|
687
|
+
if (observed?.task !== undefined)
|
|
688
|
+
cappedAttempt = { turn, observed };
|
|
689
|
+
}
|
|
690
|
+
if (event.type !== 'turn/end')
|
|
691
|
+
return;
|
|
692
|
+
const capped = cappedAttempt;
|
|
693
|
+
cappedAttempt = undefined;
|
|
694
|
+
if (capped?.turn !== event.data.turn || event.data.reason?.kind !== 'max-tokens')
|
|
695
|
+
return;
|
|
696
|
+
return recordFailure(capped.turn, {
|
|
697
|
+
code: 'MAX_TOKENS',
|
|
698
|
+
message: 'Model output-token limit reached before the member closed this task',
|
|
699
|
+
}, { ...capped.observed, openAttemptOnly: true });
|
|
675
700
|
});
|
|
701
|
+
const cleanupFailure = () => { disposeOutputLimit(); disposeFailure(); cleanupAdmission(); };
|
|
676
702
|
// Legacy teams still need failure reporting even without a saved route.
|
|
677
703
|
if (selection === undefined)
|
|
678
|
-
return
|
|
704
|
+
return cleanupFailure;
|
|
679
705
|
const selectionRef = { current: modelSelection(selection), assembled: undefined };
|
|
680
|
-
|
|
706
|
+
// Newer Harness owns the next-step selection in the Agent's durable model
|
|
707
|
+
// API. Its installModelSelection hook now only contributes switch notices.
|
|
708
|
+
const model = child.model;
|
|
709
|
+
const nativeModel = typeof model?.select === 'function' ? model : undefined;
|
|
710
|
+
nativeModel?.select(selectionRef.current);
|
|
711
|
+
const disposeSelection = installMemberModelSelection(childCtx, selectionRef);
|
|
681
712
|
const fallback = selection.fallback;
|
|
682
713
|
let switched = false;
|
|
714
|
+
const recoveryLifetime = new AbortController();
|
|
683
715
|
const disposeFallback = childCtx.on('agent/request-error', async (payload, next) => {
|
|
684
|
-
if (payload.agent.id !== child.id
|
|
716
|
+
if (payload.agent.id !== child.id)
|
|
717
|
+
return next();
|
|
718
|
+
const transition = selectFallbackRoute(selectionRef.current, fallback, payload.failure.code, switched);
|
|
719
|
+
if (fallback === undefined || !transition.retry)
|
|
720
|
+
return next();
|
|
721
|
+
// The turn can survive plugin unload. Stop any queued recovery when
|
|
722
|
+
// this child setup is disposed while waiting for the team lock.
|
|
723
|
+
const signal = AbortSignal.any([payload.signal, recoveryLifetime.signal]);
|
|
724
|
+
if (signal.aborted)
|
|
685
725
|
return next();
|
|
686
|
-
const
|
|
687
|
-
// selectFallbackRoute only retries when a fallback route exists; the
|
|
688
|
-
// explicit guard narrows that fact for the compiler.
|
|
689
|
-
if (fallback !== undefined && transition.retry) {
|
|
726
|
+
const committed = await commitFallbackRoute(stateRoot, teamId, memberName, child, fallback, signal, ctx, () => {
|
|
690
727
|
switched = transition.switched;
|
|
691
728
|
selectionRef.current = transition.selection;
|
|
692
|
-
// Request recovery repeats buildRequest inside the current step; it
|
|
693
|
-
// does not re-run prompt assembly. Override that captured route too,
|
|
694
|
-
// otherwise the authorized retry would hit the failed primary again.
|
|
695
|
-
selectionRef.assembled = transition.selection;
|
|
696
|
-
await updateFallbackState(stateRoot, teamId, memberName, fallback, ctx).catch((error) => {
|
|
697
|
-
ctx.logger.warn(`agent-teams: failed to persist fallback route: ${String(error)}`);
|
|
698
|
-
});
|
|
699
729
|
ctx.logger.warn(`agent-teams: member ${child.id} switching to fallback ${fallback.provider}/${fallback.model} after ${payload.failure.code}`);
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
730
|
+
if (nativeModel === undefined) {
|
|
731
|
+
// Legacy recovery rebuilds the request without rerunning assembly.
|
|
732
|
+
selectionRef.assembled = transition.selection;
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
// Modern recovery fixes the route for all retries of a prepared step.
|
|
736
|
+
// Close that step without failing its task, then wake the same member in
|
|
737
|
+
// a new turn. The assignment and any completed calls are already in its
|
|
738
|
+
// session history, so there is no task retry or replay of input.
|
|
739
|
+
nativeModel.select(transition.selection);
|
|
740
|
+
const continuation = createUserMessage({
|
|
741
|
+
content: [{ type: 'text', text: 'AgentTeams switched to the configured fallback model. Continue the current work from the conversation history and recorded task state.' }],
|
|
742
|
+
source: agentTeamsSource({ kind: 'agent-teams' }, observedSessionFormatVersion(child)),
|
|
743
|
+
});
|
|
744
|
+
if (signal.aborted)
|
|
745
|
+
return;
|
|
746
|
+
child.cancel({ kind: 'hook', reason: 'agent-teams/model-fallback' }, { keepInbox: true });
|
|
747
|
+
try {
|
|
748
|
+
child.followup(continuation);
|
|
749
|
+
}
|
|
750
|
+
catch (error) {
|
|
751
|
+
// Cancellation suppresses the host's agent/error event, so a rejected
|
|
752
|
+
// continuation still needs to settle the observed attempt.
|
|
753
|
+
const observed = observeFailedAttempt();
|
|
754
|
+
if (observed !== undefined)
|
|
755
|
+
void recordFailure(payload.turn, payload.failure, observed);
|
|
756
|
+
throw error;
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
if (!committed)
|
|
760
|
+
return next();
|
|
761
|
+
return nativeModel === undefined ? { kind: 'retry' } : undefined;
|
|
703
762
|
});
|
|
704
763
|
return () => {
|
|
764
|
+
recoveryLifetime.abort();
|
|
705
765
|
disposeFallback();
|
|
706
766
|
disposeSelection();
|
|
707
|
-
|
|
708
|
-
disposeAdmission();
|
|
709
|
-
disposeComposition();
|
|
767
|
+
cleanupFailure();
|
|
710
768
|
};
|
|
711
769
|
});
|
|
712
770
|
return {
|
|
713
|
-
scopedComposition: true,
|
|
714
771
|
isPendingMember(agent) {
|
|
715
772
|
const parent = agent.session.header.parentSession;
|
|
716
773
|
const descriptor = foldSubagentDescriptor(sessionOwnEvents(agent.session));
|
|
717
774
|
return parent !== undefined && descriptor?.mode === 'continuable'
|
|
718
775
|
&& pending.has(pendingSelectionKey(parent, descriptor.label));
|
|
719
776
|
},
|
|
720
|
-
async withPending(parentSessionId, label, selection, operation,
|
|
777
|
+
async withPending(parentSessionId, label, selection, operation, setup) {
|
|
721
778
|
const key = pendingSelectionKey(parentSessionId, label);
|
|
722
779
|
if (pending.has(key)) {
|
|
723
780
|
throw new Error(`member model selection is already pending for "${label}"`);
|
|
724
781
|
}
|
|
725
782
|
pending.set(key, selection);
|
|
726
|
-
if (
|
|
727
|
-
|
|
783
|
+
if (setup !== undefined)
|
|
784
|
+
pendingSetup.set(key, setup);
|
|
728
785
|
try {
|
|
729
786
|
return await operation();
|
|
730
787
|
}
|
|
731
788
|
finally {
|
|
732
789
|
pending.delete(key);
|
|
733
|
-
|
|
790
|
+
pendingSetup.delete(key);
|
|
734
791
|
}
|
|
735
792
|
},
|
|
736
793
|
};
|
|
@@ -838,14 +895,11 @@ export async function spawnMember(ctx, config, selections, llmSelection, captain
|
|
|
838
895
|
if (provider.prepareContinuable === undefined) {
|
|
839
896
|
throw new Error(`agent-teams: provider "${config.provider}" does not support continuable members`);
|
|
840
897
|
}
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
&& capabilities.agentPreset === true && selections.scopedComposition === true
|
|
844
|
-
&& typeof ctx.subagents.startActivation === 'function';
|
|
845
|
-
if (!scoped && !capabilities.persona) {
|
|
898
|
+
const legacyCapabilities = provider.capabilities;
|
|
899
|
+
if (!usesManagedActivations(ctx.subagents) && !legacyCapabilities.persona) {
|
|
846
900
|
throw new Error(`agent-teams: provider "${config.provider}" cannot apply a member persona`);
|
|
847
901
|
}
|
|
848
|
-
if (!
|
|
902
|
+
if (!usesManagedActivations(ctx.subagents) && !legacyCapabilities.toolFilter) {
|
|
849
903
|
throw new Error(`agent-teams: provider "${config.provider}" cannot restrict captain-only tools for members`);
|
|
850
904
|
}
|
|
851
905
|
const label = `${MEMBER_LABEL_PREFIX}${team.id}:${member.name}`;
|
|
@@ -853,19 +907,24 @@ export async function spawnMember(ctx, config, selections, llmSelection, captain
|
|
|
853
907
|
// captain-only deny list plus the depth entries this host registers.
|
|
854
908
|
const requestedFilter = resolvedFilter ?? memberToolFilter(config.maxDepth, restrictableToolNames(captain));
|
|
855
909
|
// The lenient retry may drop names this host reports unknown; keep the exact
|
|
856
|
-
// filter the host accepted
|
|
910
|
+
// filter the host accepted for the durable member setup.
|
|
857
911
|
let acceptedFilter = requestedFilter;
|
|
858
|
-
const
|
|
859
|
-
const start = await selections.withPending(captain.id, label, llmSelection, () => (startMemberWithLenientFilter(toolFilter => {
|
|
912
|
+
const start = await startMemberWithLenientFilter(toolFilter => {
|
|
860
913
|
acceptedFilter = toolFilter;
|
|
861
|
-
|
|
862
|
-
return startMember(ctx.subagents, {
|
|
914
|
+
const setup = { persona: memberPersona(team, member, stateDir, config.executionPrompt), toolFilter };
|
|
915
|
+
return selections.withPending(captain.id, label, llmSelection, () => startMember(ctx.subagents, {
|
|
863
916
|
provider: config.provider,
|
|
864
917
|
label,
|
|
865
918
|
request: {
|
|
866
919
|
prompt: [{ type: 'text', text: initialPrompt ?? memberWelcome(team, member.name) }],
|
|
867
920
|
parent: captain,
|
|
868
|
-
|
|
921
|
+
persona: memberPersona(team, member, stateDir, config.executionPrompt),
|
|
922
|
+
// Depth deny entries name host tools; resolve them against the
|
|
923
|
+
// running host's registry so a renamed delegation tool cannot abort
|
|
924
|
+
// the spawn (see memberToolFilter). Depth is still enforced by the
|
|
925
|
+
// parent-chain guard installed at plugin mount. A filter the host
|
|
926
|
+
// still rejects is retried without the names it reported.
|
|
927
|
+
toolFilter,
|
|
869
928
|
agentOptions: {
|
|
870
929
|
provider: llmSelection.provider,
|
|
871
930
|
model: llmSelection.model,
|
|
@@ -878,13 +937,17 @@ export async function spawnMember(ctx, config, selections, llmSelection, captain
|
|
|
878
937
|
// the configured member-relative descendant budget instead.
|
|
879
938
|
},
|
|
880
939
|
signal,
|
|
881
|
-
});
|
|
882
|
-
}, requestedFilter, relaxableDeny)
|
|
940
|
+
}), setup);
|
|
941
|
+
}, requestedFilter, relaxableDeny);
|
|
883
942
|
member.id = start.childId;
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
member
|
|
943
|
+
if (usesManagedActivations(ctx.subagents)) {
|
|
944
|
+
member.runtimeSetup = { persona: memberPersona(team, member, stateDir, config.executionPrompt), toolFilter: acceptedFilter };
|
|
945
|
+
}
|
|
946
|
+
// Only a policy member carries a persisted filter snapshot; a member without
|
|
947
|
+
// a policy keeps its public record shape. Legacy descriptors or runtimeSetup
|
|
948
|
+
// restore the filter on cold resume, depending on the host generation.
|
|
949
|
+
if (member.toolFilter !== undefined)
|
|
950
|
+
member.toolFilter = { ...acceptedFilter };
|
|
888
951
|
}
|
|
889
952
|
/**
|
|
890
953
|
* Deliver one message to a member as its next FIFO turn. Best effort: a
|
|
@@ -952,7 +1015,10 @@ export function installRetiredMemberGuard(ctx, stateDir) {
|
|
|
952
1015
|
}
|
|
953
1016
|
/** Bound all descendant creation, including renamed tools and code-runtime calls. */
|
|
954
1017
|
export function installMemberDelegationGuard(ctx, stateDir, maxDepth) {
|
|
1018
|
+
let active = true;
|
|
955
1019
|
const check = (parent) => {
|
|
1020
|
+
if (!active)
|
|
1021
|
+
return;
|
|
956
1022
|
let ancestor = parent;
|
|
957
1023
|
let depth = 1;
|
|
958
1024
|
while (ancestor !== undefined) {
|
|
@@ -983,6 +1049,7 @@ export function installMemberDelegationGuard(ctx, stateDir, maxDepth) {
|
|
|
983
1049
|
}
|
|
984
1050
|
};
|
|
985
1051
|
guardSubagentCreation(ctx, check);
|
|
1052
|
+
ctx.effect(() => () => { active = false; }, 'agent-teams: delegation guard lifetime');
|
|
986
1053
|
}
|
|
987
1054
|
/**
|
|
988
1055
|
* Snapshot the real driver activity for durable member ids.
|