Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Let team members manage team-owned artifacts (#2591)

Joshua France49cbaa526339
diff --git a/src/api/artifact-share.ts b/src/api/artifact-share.ts
index fc8e322a9..0fc25a5b0 100644
--- a/src/api/artifact-share.ts
+++ b/src/api/artifact-share.ts
@@ -8,8 +8,12 @@ import type { RecipientResolution } from "../directory/directory-store.ts";
export const SHARED_SKILL_TRIGGER_REFUSAL =
"a skill in a shared scope can only be changed by a person, not an automated trigger";
+export function isMultiMemberSkillScope(scope: ScopeId): boolean {
+ return isSharedScope(scope) || parseScopeId(scope).kind === "team";
+}
+
export function triggerBlocksSharedSkill(homeScope: ScopeId, liveActor: boolean): boolean {
- return isSharedScope(homeScope) && !liveActor;
+ return isMultiMemberSkillScope(homeScope) && !liveActor;
}
export function livePersonCapability(c: { liveActor?: boolean; liveAuthor?: boolean } | undefined): boolean {
diff --git a/src/api/control-service.ts b/src/api/control-service.ts
index 6ee2bd8a3..a93bd9823 100644
--- a/src/api/control-service.ts
+++ b/src/api/control-service.ts
@@ -25,8 +25,9 @@ import {
SHARED_SKILL_TRIGGER_REFUSAL,
type ShareArtifactRequest,
type ShareArtifactResult,
+ isMultiMemberSkillScope,
} from "./artifact-share.ts";
-import { actsAsScope, isSharedScope, parseScopeId, type Permission, type ScopeId } from "../types.ts";
+import { actsAsScope, parseScopeId, type Permission, type ScopeId } from "../types.ts";
import { cronRef, encodeRef } from "../acl/resource-ref.ts";
import type { App, VisibleCron } from "./app.ts";
@@ -873,7 +874,7 @@ export function createControlService(app: App, scheduler?: Scheduler, admin?: Ad
if (
req.type === "skill" &&
!livePersonCapability(capability) &&
- (isSharedScope(home.ownerScopeId) || isSharedScope(toScope))
+ (isMultiMemberSkillScope(home.ownerScopeId) || isMultiMemberSkillScope(toScope))
) {
return { ok: false, code: "forbidden", message: SHARED_SKILL_TRIGGER_REFUSAL };
}
diff --git a/src/harness/agent-tools.ts b/src/harness/agent-tools.ts
index 56f2f610b..9ce113331 100644
--- a/src/harness/agent-tools.ts
+++ b/src/harness/agent-tools.ts
@@ -3176,7 +3176,10 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
label: action,
description,
parameters: Type.Object({
- id: Type.String({ description: "Artifact ID; an app may also be named by its handle." }),
+ id: Type.String({
+ description:
+ "Artifact ID (for a skill, the id from skills list or search); an app may also be named by its handle.",
+ }),
toScope:
type === "deploy" && !move
? Type.Optional(
diff --git a/src/resolution/scope-membership.ts b/src/resolution/scope-membership.ts
index 6a7fadc29..66f42b181 100644
--- a/src/resolution/scope-membership.ts
+++ b/src/resolution/scope-membership.ts
@@ -267,6 +267,7 @@ export function createManagesArtifactHome(
if (!principalId || !activePrincipal(deps, principalId)) return false;
if (await canManageScope(principalId, homeScopeId)) return true;
const { kind, ref } = parseScopeId(homeScopeId);
+ if (kind === "team") return teamMember(deps, principalId, ref);
if (!samePerson(createdBy, principalId)) return false;
if (kind === "personal") return true;
if (kind === "channel")
diff --git a/src/tools/primitives.ts b/src/tools/primitives.ts
index dfae5ffb9..a62e0a30a 100644
--- a/src/tools/primitives.ts
+++ b/src/tools/primitives.ts
@@ -1044,6 +1044,7 @@ export function createToolContext(deps: ToolContextDeps): ToolContext {
return {
sourceScopeId,
skills: selected.map(({ skill }) => ({
+ id: skill!.id,
name: skill!.manifest.name,
description: skill!.manifest.description,
source: skill!.scopeId,
diff --git a/src/wiring.ts b/src/wiring.ts
index 902eddd17..cd816ed8b 100644
--- a/src/wiring.ts
+++ b/src/wiring.ts
@@ -1775,7 +1775,10 @@ export function buildApp(
const canReadScope = createCanReadScope({ managedGroups: projects, directory, identity, teams, sessions });
const canWriteScope = createCanWriteScope({ managedGroups: projects, directory, identity, teams });
const canManageScope = createCanManageScope({ managedGroups: projects, directory, identity, sessions });
- const managesArtifactHome = createManagesArtifactHome({ managedGroups: projects, directory }, canManageScope);
+ const managesArtifactHome = createManagesArtifactHome(
+ { managedGroups: projects, directory, identity, teams },
+ canManageScope,
+ );
const currentScopeMembers = createCurrentScopeMembers({ managedGroups: projects, directory, identity });
const isCurrentSharedScopeMember = createIsCurrentSharedScopeMember({ managedGroups: projects, directory, identity });
membership.canReadScope = canReadScope;
diff --git a/test/share-verb.test.ts b/test/share-verb.test.ts
index ea1b63835..ed5947b3c 100644
--- a/test/share-verb.test.ts
+++ b/test/share-verb.test.ts
@@ -11,7 +11,7 @@ import type { RecipientResolution } from "../src/directory/directory-store.ts";
import { shareArtifact as shareRoute } from "../src/api/routes/surface.ts";
import type { ApiCtx } from "../src/api/routes/route.ts";
import { createSkillStore } from "../src/skills/skill-store.ts";
-import { splitToScope } from "../src/api/artifact-share.ts";
+import { splitToScope, triggerBlocksSharedSkill } from "../src/api/artifact-share.ts";
import { createAclStore } from "../src/acl/acl-store.ts";
import { createMemoryFileArtifactStore, type FileArtifactStore } from "../src/files/file-artifact-store.ts";
import { createMemoryDurableByteStore } from "../src/files/durable-byte-store.ts";
@@ -37,6 +37,7 @@ function fakeManages(state: FakeState): ManagesArtifactHome {
const { kind, ref } = parseScopeId(homeScopeId);
const memberManaged = kind === "group" || (kind === "channel" && state.privateChannels.has(ref));
if (memberManaged && (state.scopesByPrincipal[principalId] ?? []).includes(homeScopeId)) return true;
+ if (kind === "team") return (state.scopesByPrincipal[principalId] ?? []).includes(homeScopeId);
if (createdBy !== principalId) return false;
if (kind === "personal") return ref === principalId;
if (kind === "channel") return !state.privateChannels.has(ref);
@@ -556,6 +557,51 @@ test("an automated trigger (no liveActor) cannot MOVE a skill out of its shared
assert.equal(state.moves.length, 1, "a live member's move goes through");
});
+test("a team member who didn't create a team-owned skill can share it onward; a trigger cannot move it out", async () => {
+ const state = await ownerState();
+ state.artifacts["skill:TS"] = {
+ type: "skill",
+ id: "TS",
+ ownerScopeId: scopeId("team", "alpha"),
+ createdBy: "U1",
+ grantRef: "skill:TS",
+ };
+ state.scopesByPrincipal["U2"] = [
+ scopeId("personal", "U2"),
+ scopeId("org", ORG),
+ scopeId("team", "alpha"),
+ scopeId("channel", "C7"),
+ ];
+ state.scopesByPrincipal["U3"] = [scopeId("personal", "U3"), scopeId("org", ORG), scopeId("channel", "C7")];
+ const svc = createControlService(fakeApp(state));
+
+ const shared = await svc.shareArtifact(
+ { type: "skill", id: "TS", scope: scopeId("channel", "C7"), permission: "write" },
+ cap("U2"),
+ );
+ assert.ok(shared.ok, JSON.stringify(shared));
+ assert.ok((await grantsOf(state)).some((g) => g.ref === "skill:TS" && g.granteeScopeId === scopeId("channel", "C7")));
+
+ const outsider = await svc.shareArtifact(
+ { type: "skill", id: "TS", scope: scopeId("channel", "C7"), permission: "write" },
+ cap("U3"),
+ );
+ assert.equal(outsider.ok, false, "a non-member cannot manage the team's skill");
+
+ const trigger = await svc.shareArtifact(
+ { type: "skill", id: "TS", scope: scopeId("personal", "U2"), move: true },
+ cap("U2", scopeId("personal", "U2"), false),
+ );
+ assert.equal(trigger.ok, false, "an automated trigger cannot take a team skill out of the team");
+ assert.equal(state.moves.length, 0);
+});
+
+test("skill mutations from an automated trigger are blocked for team homes, like channel and group homes", () => {
+ assert.equal(triggerBlocksSharedSkill(scopeId("team", "alpha"), false), true);
+ assert.equal(triggerBlocksSharedSkill(scopeId("team", "alpha"), true), false);
+ assert.equal(triggerBlocksSharedSkill(scopeId("personal", "U1"), false), false);
+});
+
test("a trigger (no liveActor) cannot MOVE a personal skill INTO a shared scope either — a move that authors a group-wide skill is guarded like create", async () => {
const state = await ownerState();
state.scopesByPrincipal["U1"] = [scopeId("personal", "U1"), scopeId("org", ORG), scopeId("channel", "C1")];
diff --git a/test/skill-tool.test.ts b/test/skill-tool.test.ts
index e9b99d366..e799c5d4e 100644
--- a/test/skill-tool.test.ts
+++ b/test/skill-tool.test.ts
@@ -97,7 +97,7 @@ function createToolContextWithout(extra: Partial<ToolContextDeps> = {}) {
return { tc };
}
-test("skill discovery pages the current visible catalog without provisioning or exposing metadata", async () => {
+test("skill discovery pages the current visible catalog with ids, without provisioning or exposing other metadata", async () => {
const skills = Array.from({ length: 3 }, (_, i) => ({
skill: {
manifest: {
@@ -127,22 +127,27 @@ test("skill discovery pages the current visible catalog without provisioning or
assert.deepEqual(await tc.listSkills(), { sourceScopeId: null, skills: [] });
assert.deepEqual(await tc.listSkills("", 0, 2, "personal:someone"), {
sourceScopeId: "personal:someone",
- skills: [0, 1].map((i) => ({ name: `skill-${i}`, description: "General task", source: "personal:someone" })),
+ skills: [0, 1].map((i) => ({
+ id: `id-${i}`,
+ name: `skill-${i}`,
+ description: "General task",
+ source: "personal:someone",
+ })),
nextOffset: 2,
});
assert.deepEqual(await tc.listSkills("", 2, 2, "personal:someone"), {
sourceScopeId: "personal:someone",
- skills: [{ name: "skill-2", description: "Telescope planning", source: "personal:someone" }],
+ skills: [{ id: "id-2", name: "skill-2", description: "Telescope planning", source: "personal:someone" }],
});
assert.deepEqual(await tc.listSkills("telescope", 0, 50, "personal:someone"), {
sourceScopeId: "personal:someone",
- skills: [{ name: "skill-2", description: "Telescope planning", source: "personal:someone" }],
+ skills: [{ id: "id-2", name: "skill-2", description: "Telescope planning", source: "personal:someone" }],
});
skills[1]!.skill.scopeId = scopeId("personal", "U1");
const native = await tc.listSkills();
assert.deepEqual(native, {
sourceScopeId: null,
- skills: [{ name: "skill-1", description: "General task", source: "personal:U1" }],
+ skills: [{ id: "id-1", name: "skill-1", description: "General task", source: "personal:U1" }],
});
assert.deepEqual(await tc.listSkills("", 0, 100, "personal:missing"), { sourceScopeId: null, skills: [] });
skills.pop();
diff --git a/test/team-artifact-manage.test.ts b/test/team-artifact-manage.test.ts
new file mode 100644
index 000000000..bf8830350
--- /dev/null
+++ b/test/team-artifact-manage.test.ts
@@ -0,0 +1,33 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { createCanManageScope, createManagesArtifactHome } from "../src/resolution/scope-membership.ts";
+
+const alpha = new Set(["[email protected]", "[email protected]"]);
+const deps = {
+ teams: { isMember: async (principalId: string, teamId: string) => teamId === "alpha" && alpha.has(principalId) },
+ identity: {
+ classify: (principalId: string) => ({
+ type: principalId.startsWith("ext") ? ("external" as const) : ("internal" as const),
+ }),
+ },
+};
+
+test("a team-owned artifact is managed by the team's current members, not only its creator", async () => {
+ const manages = createManagesArtifactHome(deps as never, createCanManageScope(deps as never));
+ assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), true);
+ assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), true);
+});
+
+test("a team-owned artifact is not manageable by non-members, including a creator who is no longer on the team", async () => {
+ const manages = createManagesArtifactHome(deps as never, createCanManageScope(deps as never));
+ assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
+ assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
+ assert.equal(await manages("team:other", "[email protected]", "[email protected]"), false);
+ assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
+});
+
+test("without a team store, team-owned artifacts stay unmanageable (fails closed)", async () => {
+ const noTeams = { identity: deps.identity };
+ const manages = createManagesArtifactHome(noTeams as never, createCanManageScope(noTeams as never));
+ assert.equal(await manages("team:alpha", "[email protected]", "[email protected]"), false);
+});