@moondeck/station 1.0.6 → 1.0.8
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/lib/agents/skill-index-preamble.fixture.ts +2 -0
- package/lib/credential-consumers/engines.ts +4 -0
- package/lib/engine-accounts.ts +25 -2
- package/lib/initial-attachment-command.ts +22 -0
- package/lib/initial-attachments.ts +71 -0
- package/lib/orchestrator.ts +161 -51
- package/lib/skills.ts +122 -114
- package/lib/task-environment/workspace-files.ts +68 -0
- package/package.json +13 -1
- package/src/cloud-credentials.ts +10 -2
- package/src/index.ts +12 -0
- package/src/initial-attachments.ts +74 -0
- package/src/main.ts +7 -0
- package/src/model-limits.ts +103 -0
- package/src/protocol.ts +6 -0
package/lib/orchestrator.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isOwnedInternalConnectionRuntime } from "./internal-connections";
|
|
2
|
+
import { accountAllowsModel } from "../src/model-limits";
|
|
2
3
|
import { prepareNodeData } from "./node-state";
|
|
3
4
|
import { registerConnectionSecret } from "./connection-secret-redaction";
|
|
4
5
|
import { buildCustomConnectionLaunch, tomlString, connectionNativeBlanks, connectionHomePreparation, newConnectionHome, connectionDnsLookupArgv, validateConnectionAddresses, connectionConnectArgv, CustomConnectionLaunchError, launchRefusal, CONNECTION_CONNECT_TIMEOUT_MS } from "./custom-connection-launch";
|
|
@@ -68,7 +69,7 @@ import {
|
|
|
68
69
|
import { ACTIVE_STATUSES, isActive, isOnDashboard } from "./task-status";
|
|
69
70
|
import { isSafeHostTaskId } from "./task-identity";
|
|
70
71
|
import { projectEnvForTask } from "./host-env";
|
|
71
|
-
import { shadowRoute } from "./routing/shadow";
|
|
72
|
+
import { CLASSIFIER_MODEL, shadowRoute } from "./routing/shadow";
|
|
72
73
|
import {
|
|
73
74
|
closeCurrentTaskRunAssignmentForStoppedRuntime,
|
|
74
75
|
getHostTask,
|
|
@@ -132,11 +133,12 @@ import type {
|
|
|
132
133
|
} from "./task-environment/types";
|
|
133
134
|
import { renderSkillLayout } from "./skill-layout";
|
|
134
135
|
import {
|
|
135
|
-
containerSkillFile,
|
|
136
136
|
installedSkillPath,
|
|
137
137
|
installPackageSkills,
|
|
138
138
|
type SkillExec,
|
|
139
139
|
writeAgentSkills,
|
|
140
|
+
renderSkillMd,
|
|
141
|
+
type SkillDelivery,
|
|
140
142
|
} from "./skills";
|
|
141
143
|
import {
|
|
142
144
|
ensureMachineGatewayTunnel,
|
|
@@ -325,6 +327,7 @@ interface Channel {
|
|
|
325
327
|
agentHandle: TaskEnvironmentHandle<unknown> | null;
|
|
326
328
|
/** Per-agent system preamble (channel briefing + assembled persona). */
|
|
327
329
|
preambles: Map<string, string>;
|
|
330
|
+
skillDeliveries: Map<string, SkillDelivery>;
|
|
328
331
|
/** Per-agent first-turn message — only agents whose `initialPrompt` is
|
|
329
332
|
* non-empty have an entry. Delivered once at container-ready. */
|
|
330
333
|
firstTurns: Map<string, string>;
|
|
@@ -1095,10 +1098,10 @@ export class Orchestrator {
|
|
|
1095
1098
|
// array exactly also makes absence authoritative for live removal.
|
|
1096
1099
|
channel.roster = [...spec.agents];
|
|
1097
1100
|
this.cancelStaleConnectionRetries(channel);
|
|
1098
|
-
for (const agent of
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1101
|
+
for (const agent of channel.roster) {
|
|
1102
|
+
if (JSON.stringify(previousById.get(agent.id)?.skills) !== JSON.stringify(agent.skills)) {
|
|
1103
|
+
channel.skillDeliveries.delete(agent.id);
|
|
1104
|
+
}
|
|
1102
1105
|
}
|
|
1103
1106
|
for (const { agent, reason } of changed) {
|
|
1104
1107
|
const recoveryAbortPublished = this.supersedeRecovery(
|
|
@@ -1200,6 +1203,7 @@ export class Orchestrator {
|
|
|
1200
1203
|
spec.mode,
|
|
1201
1204
|
spec.secretaryAgentId,
|
|
1202
1205
|
taskProxiedKeys(channel.taskId),
|
|
1206
|
+
channel.skillDeliveries.get(agent.id),
|
|
1203
1207
|
),
|
|
1204
1208
|
);
|
|
1205
1209
|
}
|
|
@@ -1262,6 +1266,7 @@ export class Orchestrator {
|
|
|
1262
1266
|
}
|
|
1263
1267
|
this.retireRunnerGeneration(channel, agentId);
|
|
1264
1268
|
channel.preambles.delete(agentId);
|
|
1269
|
+
channel.skillDeliveries.delete(agentId);
|
|
1265
1270
|
channel.firstTurns.delete(agentId);
|
|
1266
1271
|
channel.browserStaleSessions.delete(agentId);
|
|
1267
1272
|
channel.rosterSessionChanges.delete(agentId);
|
|
@@ -1465,6 +1470,7 @@ export class Orchestrator {
|
|
|
1465
1470
|
agentEnvironment: null,
|
|
1466
1471
|
agentHandle: null,
|
|
1467
1472
|
preambles,
|
|
1473
|
+
skillDeliveries: new Map(),
|
|
1468
1474
|
firstTurns,
|
|
1469
1475
|
sessionsReady: null,
|
|
1470
1476
|
browserReady: false,
|
|
@@ -1526,13 +1532,6 @@ export class Orchestrator {
|
|
|
1526
1532
|
leasedLaunches: new Map(),
|
|
1527
1533
|
};
|
|
1528
1534
|
this.channels.set(taskId, channel);
|
|
1529
|
-
// ADR-046: materialise each agent's skills to its per-agent SKILL.md in
|
|
1530
|
-
// the workspace (bind-mounted into the container), best-effort, once the
|
|
1531
|
-
// channel can give the task's runtime: where only it can make the
|
|
1532
|
-
// agent's directory (macOS, #cb3j0z), it is asked for then.
|
|
1533
|
-
for (const agent of roster) {
|
|
1534
|
-
writeAgentSkills(taskId, agent, () => this.workspaceRuntime(taskId));
|
|
1535
|
-
}
|
|
1536
1535
|
return channel;
|
|
1537
1536
|
}
|
|
1538
1537
|
|
|
@@ -1816,6 +1815,7 @@ export class Orchestrator {
|
|
|
1816
1815
|
scope: account.scope,
|
|
1817
1816
|
authKind: account.authKind as "env" | "config-dir",
|
|
1818
1817
|
execEnv: {},
|
|
1818
|
+
...(account.allowedModels ? { allowedModels: account.allowedModels } : {}),
|
|
1819
1819
|
}));
|
|
1820
1820
|
}
|
|
1821
1821
|
|
|
@@ -1826,17 +1826,21 @@ export class Orchestrator {
|
|
|
1826
1826
|
kind: string,
|
|
1827
1827
|
exclude?: Set<string>,
|
|
1828
1828
|
preferredId?: string,
|
|
1829
|
+
/** ADR-168: the agent's model; only accounts allowing it are picked. */
|
|
1830
|
+
model?: string | null,
|
|
1829
1831
|
): ResolvedEngineAccount | null {
|
|
1830
1832
|
if (!this.isLeasedChannel(channel)) {
|
|
1831
1833
|
return pickEngineAccount(kind, {
|
|
1832
1834
|
scope: channel.engineAccountScope,
|
|
1833
1835
|
exclude,
|
|
1834
1836
|
preferredId,
|
|
1837
|
+
model,
|
|
1835
1838
|
});
|
|
1836
1839
|
}
|
|
1837
1840
|
return selectAccount(this.engineAccounts(channel, kind), {
|
|
1838
1841
|
exclude,
|
|
1839
1842
|
preferredId,
|
|
1843
|
+
model,
|
|
1840
1844
|
});
|
|
1841
1845
|
}
|
|
1842
1846
|
|
|
@@ -2669,12 +2673,7 @@ export class Orchestrator {
|
|
|
2669
2673
|
// Same per-agent materialisation the initial start does. Browser setup
|
|
2670
2674
|
// is awaited before EVERY missing-session spawn: that reasserts configs
|
|
2671
2675
|
// clobbered by resume/auth injection and covers roster generation.
|
|
2672
|
-
|
|
2673
|
-
if (skillExec) {
|
|
2674
|
-
await installPackageSkills(channel.taskId, missing, skillExec);
|
|
2675
|
-
} else {
|
|
2676
|
-
await installPackageSkills(channel.taskId, missing);
|
|
2677
|
-
}
|
|
2676
|
+
await this.prepareSkills(channel, missing);
|
|
2678
2677
|
if (!this.isActiveChannel(channel)) return;
|
|
2679
2678
|
|
|
2680
2679
|
// One materialization gate owns provisioning and (when enabled)
|
|
@@ -2878,6 +2877,7 @@ export class Orchestrator {
|
|
|
2878
2877
|
const account = pickEngineAccount(agent.kind, {
|
|
2879
2878
|
scope: channel.engineAccountScope,
|
|
2880
2879
|
preferredId: agent.accountId,
|
|
2880
|
+
model: agent.model ?? null,
|
|
2881
2881
|
});
|
|
2882
2882
|
if (!account) {
|
|
2883
2883
|
channel.accountByAgent.delete(agent.id);
|
|
@@ -3120,7 +3120,9 @@ export class Orchestrator {
|
|
|
3120
3120
|
if (!account) {
|
|
3121
3121
|
reason = args.agent.accountBinding === "required"
|
|
3122
3122
|
? args.agent.accountId && open.connectionsUnsupported?.includes(args.agent.accountId) ? "unsupported" : "connection removed"
|
|
3123
|
-
:
|
|
3123
|
+
: leasedModelExcluded(open, kind, args.agent.model)
|
|
3124
|
+
? `no ${kind} account this task can use allows model "${args.agent.model || "(default)"}" — pick an allowed model, or ask an admin to change the accounts' allowed models or roles`
|
|
3125
|
+
: `no ${kind} account this task can use`;
|
|
3124
3126
|
break;
|
|
3125
3127
|
}
|
|
3126
3128
|
if (account.authKind === "env") {
|
|
@@ -3349,12 +3351,16 @@ export class Orchestrator {
|
|
|
3349
3351
|
owner: { agentId: string; slot: LeasedLaunchSlot } | null,
|
|
3350
3352
|
identity: LeasedIdentity,
|
|
3351
3353
|
environment: TaskEnvironmentHandle<unknown>,
|
|
3354
|
+
/** ADR-168: a one-shot's own model (the shadow classifier's): admitted
|
|
3355
|
+
* only while the account still allows it. */
|
|
3356
|
+
oneShotModel?: { kind: string; model: string | null },
|
|
3352
3357
|
): TaskEnvironmentHandle<unknown> {
|
|
3353
3358
|
const agentId = owner?.agentId ?? null;
|
|
3354
3359
|
const held = (): boolean =>
|
|
3355
3360
|
this.isActiveChannel(channel) &&
|
|
3356
3361
|
(owner === null
|
|
3357
|
-
? this.leasedMaterialServed(channel, identity)
|
|
3362
|
+
? this.leasedMaterialServed(channel, identity) &&
|
|
3363
|
+
(oneShotModel === undefined || this.leasedIdentityAllowsModel(channel, identity, oneShotModel.kind, oneShotModel.model))
|
|
3358
3364
|
: channel.leasedLaunches.get(owner.agentId) === owner.slot &&
|
|
3359
3365
|
(owner.slot.session === null
|
|
3360
3366
|
? !owner.slot.created
|
|
@@ -3567,6 +3573,23 @@ export class Orchestrator {
|
|
|
3567
3573
|
});
|
|
3568
3574
|
}
|
|
3569
3575
|
|
|
3576
|
+
/** ADR-168: whether the leased account `identity` names allows `model`
|
|
3577
|
+
* right now (a connection or the task token: always). */
|
|
3578
|
+
private leasedIdentityAllowsModel(channel: Channel, identity: LeasedIdentity, kind: string, model: string | null): boolean {
|
|
3579
|
+
if (identity.subject !== "account" || identity.connection) return true;
|
|
3580
|
+
const lease = leasedEnginesFor(channel.taskId);
|
|
3581
|
+
const account = lease?.open ? lease.accounts.find((candidate) => candidate.credentialId === identity.credentialId) : undefined;
|
|
3582
|
+
return account !== undefined && accountAllowsModel(account.allowedModels, kind, model);
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
/** ADR-168: whether the account an agent is bound to still allows its
|
|
3586
|
+
* model (a connection or the task token: always). */
|
|
3587
|
+
private leasedAccountAllowsAgent(lease: TaskEngineLease, identity: LeasedIdentity, agent: RosterAgent): boolean {
|
|
3588
|
+
if (identity.subject !== "account" || identity.connection) return true;
|
|
3589
|
+
const account = lease.accounts.find((candidate) => candidate.credentialId === identity.credentialId);
|
|
3590
|
+
return !account || accountAllowsModel(account.allowedModels, agent.kind, agent.model ?? null);
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3570
3593
|
/** Whether the task's open gate still serves `identity`'s account at its
|
|
3571
3594
|
* revision and version, for its run, and that version is not being held
|
|
3572
3595
|
* back for a newer one: what a one-shot may start on. An agent's task
|
|
@@ -3599,11 +3622,18 @@ export class Orchestrator {
|
|
|
3599
3622
|
}
|
|
3600
3623
|
|
|
3601
3624
|
/** Whether the agent may start on `identity` right now: still bound to it,
|
|
3602
|
-
*
|
|
3603
|
-
* version, for that run
|
|
3625
|
+
* the task's open gate still serves that account at that revision and
|
|
3626
|
+
* version, for that run, and (ADR-168) the account still allows the
|
|
3627
|
+
* agent's current model. The last can change with no new revision: an
|
|
3628
|
+
* admin narrowing `allowedModels`, or the agent's model changing, while
|
|
3629
|
+
* its session is still being created. Launch admission and the
|
|
3630
|
+
* post-creation checks all read this. */
|
|
3604
3631
|
private leasedIdentityHeld(channel: Channel, agentId: string, identity: LeasedIdentity): boolean {
|
|
3605
3632
|
const bound = channel.leasedIdentityByAgent.get(agentId);
|
|
3606
|
-
|
|
3633
|
+
if (bound === undefined || !sameLeasedIdentity(bound, identity) || !this.leasedMaterialServed(channel, identity)) return false;
|
|
3634
|
+
const agent = channel.roster.find((candidate) => candidate.id === agentId);
|
|
3635
|
+
const lease = leasedEnginesFor(channel.taskId);
|
|
3636
|
+
return !agent || !lease?.open || this.leasedAccountAllowsAgent(lease, identity, agent);
|
|
3607
3637
|
}
|
|
3608
3638
|
|
|
3609
3639
|
/** The leased account an agent runs on: the one it is bound to while that
|
|
@@ -3613,15 +3643,25 @@ export class Orchestrator {
|
|
|
3613
3643
|
agentId: string,
|
|
3614
3644
|
kind: string,
|
|
3615
3645
|
lease: TaskEngineLease,
|
|
3646
|
+
/** ADR-168: the model the launch will run, when it isn't the agent's own
|
|
3647
|
+
* (the shadow classifier's); null = unknown, so only an unlimited
|
|
3648
|
+
* account qualifies. */
|
|
3649
|
+
model?: string | null,
|
|
3616
3650
|
): LeasedEngineAccount | undefined {
|
|
3617
3651
|
const agent = channel.roster.find(candidate => candidate.id === agentId);
|
|
3618
3652
|
if (agent?.accountBinding === "required") {
|
|
3619
3653
|
return lease.accounts.find((account): account is LeasedEngineAccount => account.credentialId === agent.accountId && account.engineKind === kind && account.authKind === "custom-connection" && isLeasedEngineAccount(account));
|
|
3620
3654
|
}
|
|
3621
3655
|
if (lease.accounts.some(account => account.credentialId === agent?.accountId && account.authKind === "custom-connection")) return undefined;
|
|
3656
|
+
// ADR-168: only accounts allowing the agent's current model — so a model
|
|
3657
|
+
// changed mid-task, or an account an admin narrowed, moves the agent off
|
|
3658
|
+
// a binding that no longer allows it.
|
|
3622
3659
|
const accounts = lease.accounts.filter(
|
|
3623
3660
|
(account): account is LeasedEngineAccount =>
|
|
3624
|
-
account.engineKind === kind &&
|
|
3661
|
+
account.engineKind === kind &&
|
|
3662
|
+
account.authKind !== "custom-connection" &&
|
|
3663
|
+
isLeasedEngineAccount(account) &&
|
|
3664
|
+
accountAllowsModel(account.allowedModels, kind, model !== undefined ? model : (agent?.model ?? null)),
|
|
3625
3665
|
);
|
|
3626
3666
|
const bound = channel.accountByAgent.get(agentId);
|
|
3627
3667
|
const preferredId = channel.roster.find(
|
|
@@ -3809,7 +3849,9 @@ export class Orchestrator {
|
|
|
3809
3849
|
let stale = false;
|
|
3810
3850
|
for (const agent of channel.roster) {
|
|
3811
3851
|
const identity = channel.leasedIdentityByAgent.get(agent.id);
|
|
3812
|
-
|
|
3852
|
+
// ADR-168: an account narrowed so it no longer allows the agent's model
|
|
3853
|
+
// is left too: the agent restarts on one that does, or stops saying so.
|
|
3854
|
+
if (!identity || (this.leasedMaterialServed(channel, identity) && this.leasedAccountAllowsAgent(lease, identity, agent))) continue;
|
|
3813
3855
|
if (!channel.sessions.has(agent.id)) continue;
|
|
3814
3856
|
channel.browserStaleSessions.add(agent.id);
|
|
3815
3857
|
stale = true;
|
|
@@ -4393,9 +4435,14 @@ export class Orchestrator {
|
|
|
4393
4435
|
maxOutputBytes: 64 * 1024,
|
|
4394
4436
|
admit,
|
|
4395
4437
|
});
|
|
4438
|
+
// ADR-168 (review #5): the account is chosen and admitted for the model
|
|
4439
|
+
// the classifier actually runs, never the agent's own. Grok's is the
|
|
4440
|
+
// CLI's default, unknown here, so only an account without a limit
|
|
4441
|
+
// qualifies. No compatible account: null, and the pass routes by rules.
|
|
4442
|
+
const classifierModel = CLASSIFIER_MODEL[kind] ?? null;
|
|
4396
4443
|
if (!this.isLeasedChannel(channel)) {
|
|
4397
4444
|
const running = whileOnOwnCredentials(async () => {
|
|
4398
|
-
const env = { ...(pickEngineAccount(kind, { scope: channel.engineAccountScope })?.execEnv ?? {}) };
|
|
4445
|
+
const env = { ...(pickEngineAccount(kind, { scope: channel.engineAccountScope, model: classifierModel })?.execEnv ?? {}) };
|
|
4399
4446
|
const r = await handle.exec(
|
|
4400
4447
|
request(env, () => {
|
|
4401
4448
|
if (!this.isActiveChannel(channel) || !onOwnCredentials()) throw new LeftOwnCredentialsError();
|
|
@@ -4409,7 +4456,7 @@ export class Orchestrator {
|
|
|
4409
4456
|
}
|
|
4410
4457
|
const lease = leasedEnginesFor(channel.taskId);
|
|
4411
4458
|
if (!lease?.open) return null;
|
|
4412
|
-
const account = this.leasedAccountFor(channel, agentId, kind, lease);
|
|
4459
|
+
const account = this.leasedAccountFor(channel, agentId, kind, lease, classifierModel);
|
|
4413
4460
|
if (!account || account.authKind === "custom-connection") return null;
|
|
4414
4461
|
const identity: LeasedIdentity = {
|
|
4415
4462
|
subject: "account",
|
|
@@ -4430,10 +4477,13 @@ export class Orchestrator {
|
|
|
4430
4477
|
this.trackEventOperation(channel, entry.settled);
|
|
4431
4478
|
try {
|
|
4432
4479
|
const env = await this.leasedOneShotEnv(channel, lease, account, handle);
|
|
4433
|
-
|
|
4434
|
-
|
|
4480
|
+
const servedForClassifier = (): boolean =>
|
|
4481
|
+
this.leasedMaterialServed(channel, identity) &&
|
|
4482
|
+
this.leasedIdentityAllowsModel(channel, identity, kind, classifierModel);
|
|
4483
|
+
if (!env || !servedForClassifier()) return null;
|
|
4484
|
+
const r = await this.leasedLaunchEnvironment(channel, null, identity, handle, { kind, model: classifierModel }).exec(
|
|
4435
4485
|
request(env, () => {
|
|
4436
|
-
if (!this.isActiveChannel(channel) || !
|
|
4486
|
+
if (!this.isActiveChannel(channel) || !servedForClassifier()) {
|
|
4437
4487
|
throw new CredentialLeaseUnavailableError("the shadow classifier's account moved");
|
|
4438
4488
|
}
|
|
4439
4489
|
}),
|
|
@@ -4514,12 +4564,10 @@ export class Orchestrator {
|
|
|
4514
4564
|
return tracked;
|
|
4515
4565
|
}
|
|
4516
4566
|
|
|
4517
|
-
/**
|
|
4518
|
-
*
|
|
4519
|
-
* actually been reconstructed, avoiding a new await during cold admission.
|
|
4567
|
+
/** Adapt a settled environment for package installation. Only local container
|
|
4568
|
+
* callers may use the default Docker executor when no handle is available.
|
|
4520
4569
|
*/
|
|
4521
|
-
private providerSkillExec(
|
|
4522
|
-
const environment = channel.agentHandle;
|
|
4570
|
+
private providerSkillExec(environment: TaskEnvironmentHandle<unknown> | null | undefined): SkillExec | undefined {
|
|
4523
4571
|
if (!environment) return undefined;
|
|
4524
4572
|
return async (_container, cmd, cwd) => {
|
|
4525
4573
|
const argv = cmd as [string, ...string[]];
|
|
@@ -4539,6 +4587,45 @@ export class Orchestrator {
|
|
|
4539
4587
|
};
|
|
4540
4588
|
}
|
|
4541
4589
|
|
|
4590
|
+
/** Skills are launch material: await delivery, then rebuild the brief from its result. */
|
|
4591
|
+
private async prepareSkills(channel: Channel, agents: RosterAgent[]): Promise<void> {
|
|
4592
|
+
const remote = isEnvironmentTransportProvider(getHostTask(channel.taskId)?.environmentProvider);
|
|
4593
|
+
let environment: TaskEnvironmentHandle<unknown> | undefined;
|
|
4594
|
+
if (remote) {
|
|
4595
|
+
try {
|
|
4596
|
+
environment = await this.agentEnvironment(channel);
|
|
4597
|
+
} catch (error) {
|
|
4598
|
+
console.warn(`[skills] ${channel.taskId}: task environment unavailable: ${String(error)}`);
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
4601
|
+
if (!this.isActiveChannel(channel)) return;
|
|
4602
|
+
// Use the reconstructed handle directly, not the channel cache: a channel
|
|
4603
|
+
// invalidated during reconstruction never publishes agentHandle.
|
|
4604
|
+
const skillExec = this.providerSkillExec(remote ? environment : channel.agentHandle);
|
|
4605
|
+
// Remote packages must never select installPackageSkills' default Docker executor.
|
|
4606
|
+
const installedPackages = remote && !skillExec ? [] : await installPackageSkills(
|
|
4607
|
+
channel.taskId, agents, skillExec,
|
|
4608
|
+
);
|
|
4609
|
+
for (const agent of agents) {
|
|
4610
|
+
if (!this.isActiveChannel(channel)) return;
|
|
4611
|
+
const path = remote && !environment ? null : await writeAgentSkills(
|
|
4612
|
+
channel.taskId, agent, () => this.workspaceRuntime(channel.taskId), environment,
|
|
4613
|
+
);
|
|
4614
|
+
if (!this.isActiveChannel(channel) || !this.hasDesiredLaunchSettings(channel, agent.id, agent)) continue;
|
|
4615
|
+
const desired = channel.roster.find((entry) => entry.id === agent.id);
|
|
4616
|
+
if (JSON.stringify(desired?.skills) !== JSON.stringify(agent.skills)) continue;
|
|
4617
|
+
const delivery = { path, installedPackages };
|
|
4618
|
+
channel.skillDeliveries.set(agent.id, delivery);
|
|
4619
|
+
const spec = this.channelSpecs.get(channel.taskId);
|
|
4620
|
+
if (!spec) continue;
|
|
4621
|
+
channel.preambles.set(agent.id, buildSystemPreamble(
|
|
4622
|
+
channel.roster, agent, spec.projects, spec.globalContext, spec.workspacePath,
|
|
4623
|
+
spec.branch, channel.humans, channel.browserTesting, channel.sharedFiles,
|
|
4624
|
+
spec.mode, spec.secretaryAgentId, taskProxiedKeys(channel.taskId), delivery,
|
|
4625
|
+
));
|
|
4626
|
+
}
|
|
4627
|
+
}
|
|
4628
|
+
|
|
4542
4629
|
private async startSessions(channel: Channel): Promise<boolean> {
|
|
4543
4630
|
const task = getHostTask(channel.taskId);
|
|
4544
4631
|
if (
|
|
@@ -4612,12 +4699,7 @@ export class Orchestrator {
|
|
|
4612
4699
|
// turn. Idempotent + best-effort (returns fast when there are none); a slow
|
|
4613
4700
|
// clone/install briefly delays start, which is acceptable for skill-bearing
|
|
4614
4701
|
// tasks. Never throws.
|
|
4615
|
-
|
|
4616
|
-
if (skillExec) {
|
|
4617
|
-
await installPackageSkills(channel.taskId, initialRoster, skillExec);
|
|
4618
|
-
} else {
|
|
4619
|
-
await installPackageSkills(channel.taskId, initialRoster);
|
|
4620
|
-
}
|
|
4702
|
+
await this.prepareSkills(channel, initialRoster);
|
|
4621
4703
|
if (!this.isActiveChannel(channel)) return false;
|
|
4622
4704
|
|
|
4623
4705
|
// ADR-053: wire the Playwright MCP browser before agents spawn — configs
|
|
@@ -6144,7 +6226,10 @@ export class Orchestrator {
|
|
|
6144
6226
|
// handled by the path that owns this spawn slot.
|
|
6145
6227
|
if (channel.spawning.has(agentId)) return true;
|
|
6146
6228
|
if (agent.accountBinding === "required") return false;
|
|
6147
|
-
|
|
6229
|
+
// ADR-168: only accounts allowing the agent's model count. With one (or
|
|
6230
|
+
// none) left, the normal error path benches the agent until it resets;
|
|
6231
|
+
// the model rule is never broken to keep it running.
|
|
6232
|
+
if (accountsAllowingModel(this.engineAccounts(channel, agent.kind), agent.model ?? null).length < 2) {
|
|
6148
6233
|
return false;
|
|
6149
6234
|
}
|
|
6150
6235
|
|
|
@@ -6162,6 +6247,7 @@ export class Orchestrator {
|
|
|
6162
6247
|
agent.kind,
|
|
6163
6248
|
current ? new Set([current]) : undefined,
|
|
6164
6249
|
agent.accountId,
|
|
6250
|
+
agent.model ?? null,
|
|
6165
6251
|
);
|
|
6166
6252
|
if (!next) return false;
|
|
6167
6253
|
|
|
@@ -6709,7 +6795,8 @@ export class Orchestrator {
|
|
|
6709
6795
|
return;
|
|
6710
6796
|
}
|
|
6711
6797
|
|
|
6712
|
-
|
|
6798
|
+
// ADR-168: never restart it on an account that doesn't allow its model.
|
|
6799
|
+
const accounts = accountsAllowingModel(this.engineAccounts(channel, agent.kind), agent.model ?? null);
|
|
6713
6800
|
const account =
|
|
6714
6801
|
accounts.find((a) => a.id === channel.accountByAgent.get(agentId)) ??
|
|
6715
6802
|
accounts[0];
|
|
@@ -7445,6 +7532,7 @@ export function buildSystemPreamble(
|
|
|
7445
7532
|
mode?: "open" | "secretary",
|
|
7446
7533
|
secretaryAgentId?: string,
|
|
7447
7534
|
proxiedKeys?: readonly { readonly key: string; readonly domains: readonly string[] }[],
|
|
7535
|
+
skillDelivery?: SkillDelivery,
|
|
7448
7536
|
): string {
|
|
7449
7537
|
const channelList = roster
|
|
7450
7538
|
.map((a) =>
|
|
@@ -7925,16 +8013,18 @@ export function buildSystemPreamble(
|
|
|
7925
8013
|
? [
|
|
7926
8014
|
"## Your skills",
|
|
7927
8015
|
"",
|
|
7928
|
-
...(
|
|
8016
|
+
...(!skillDelivery?.path
|
|
8017
|
+
? ["Skill files are unavailable. The complete guide follows inline:", "", renderSkillMd(agent)]
|
|
8018
|
+
: skillIndex.length > 0
|
|
7929
8019
|
? [
|
|
7930
|
-
`Your skills are indexed at \`${
|
|
8020
|
+
`Your skills are indexed at \`${skillDelivery?.path}\`:`,
|
|
7931
8021
|
`${skillNameList(skillIndex)}. Read the index at the start. Before work a skill`,
|
|
7932
8022
|
"covers, or an action the index names, read that file in full with `cat`; the",
|
|
7933
8023
|
"paths are beside the index. They're yours — other agents have their own.",
|
|
7934
8024
|
]
|
|
7935
8025
|
: [
|
|
7936
8026
|
"Reference material (links + documents) has been prepared for you at",
|
|
7937
|
-
`\`${
|
|
8027
|
+
`\`${skillDelivery?.path}\`. Read it when a task touches what`,
|
|
7938
8028
|
"it covers. It's yours — other agents have their own.",
|
|
7939
8029
|
]),
|
|
7940
8030
|
"",
|
|
@@ -7946,13 +8036,14 @@ export function buildSystemPreamble(
|
|
|
7946
8036
|
...(agent.kind === "claude" &&
|
|
7947
8037
|
(agent.skills ?? []).some((s) => s.type === "package")
|
|
7948
8038
|
? [
|
|
7949
|
-
"##
|
|
8039
|
+
"## Package skills",
|
|
7950
8040
|
"",
|
|
7951
|
-
"
|
|
7952
|
-
"when a task touches what they cover:",
|
|
8041
|
+
"Installation status for this task:",
|
|
7953
8042
|
...(agent.skills ?? [])
|
|
7954
8043
|
.filter((s) => s.type === "package")
|
|
7955
|
-
.map((s) =>
|
|
8044
|
+
.map((s) => skillDelivery?.installedPackages.includes(installedSkillPath(s))
|
|
8045
|
+
? `- **${s.name}** (\`${installedSkillPath(s)}\`) — installed`
|
|
8046
|
+
: `- **${s.name}** — unavailable; installation did not succeed.`),
|
|
7956
8047
|
"",
|
|
7957
8048
|
]
|
|
7958
8049
|
: []),
|
|
@@ -11468,3 +11559,22 @@ function db_setRuntime(
|
|
|
11468
11559
|
): void {
|
|
11469
11560
|
upsertHostTask(taskId, extras);
|
|
11470
11561
|
}
|
|
11562
|
+
|
|
11563
|
+
/** ADR-168: the lease names native accounts of `kind`, but none allows
|
|
11564
|
+
* `model` — the words an agent stops with when an admin narrowed them. */
|
|
11565
|
+
function leasedModelExcluded(lease: TaskEngineLease, kind: string, model: string | undefined): boolean {
|
|
11566
|
+
const native = lease.accounts.filter(
|
|
11567
|
+
(account): account is LeasedEngineAccount =>
|
|
11568
|
+
account.engineKind === kind && account.authKind !== "custom-connection" && isLeasedEngineAccount(account),
|
|
11569
|
+
);
|
|
11570
|
+
return native.length > 0 && !native.some((account) => accountAllowsModel(account.allowedModels, kind, model ?? null));
|
|
11571
|
+
}
|
|
11572
|
+
|
|
11573
|
+
/** ADR-168: the accounts allowing `model` (pure; kept here so a test that
|
|
11574
|
+
* mocks the engine-accounts module wholesale still filters). */
|
|
11575
|
+
function accountsAllowingModel<T extends { kind: string; allowedModels?: readonly string[] }>(
|
|
11576
|
+
accounts: readonly T[],
|
|
11577
|
+
model: string | null,
|
|
11578
|
+
): T[] {
|
|
11579
|
+
return accounts.filter((account) => accountAllowsModel(account.allowedModels, account.kind, model));
|
|
11580
|
+
}
|