Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Share new channel apps with their channel by default (#2202)

Regan Bellcfc21dfea0f8
diff --git a/skills-seed/publish/SKILL.md b/skills-seed/publish/SKILL.md
index afdd48c1f..e1edb8b28 100644
--- a/skills-seed/publish/SKILL.md
+++ b/skills-seed/publish/SKILL.md
@@ -111,18 +111,17 @@ publish:
## Sharing — say who can reach it
-Publishing is always private to you: a new app is reachable only by its owner, and
-republishing never changes who can reach it. Grant access as a separate step with the app
-ID or handle:
+New apps made in a channel are shared with that channel for authenticated read/use.
+Apps made in DMs stay private. Republishing never changes access; anonymous access is
+never enabled by default. Grant additional access separately with the app ID or handle:
```
apps({ action: "share", id: "status-board", toScope: "org", permission: "read" })
```
- **read** = can reach the app. **write** = can also manage it (redeploy/rollback).
-- Share to `personal:<id>` (one teammate), or `org:<id>` (the whole org). Team/channel
- scopes can be granted, but team-membership reach at the link is not enforced yet — for
- now use `org:` or `personal:` grants for reach.
+- Share to `personal:<id>` (one teammate), `channel:<id>` (a channel), or `org:<id>`
+ (the whole org). Channel access follows the current channel visibility and membership.
## What you can rely on
diff --git a/src/deploy/deploy-service.ts b/src/deploy/deploy-service.ts
index 4357339b7..cce5b2a60 100644
--- a/src/deploy/deploy-service.ts
+++ b/src/deploy/deploy-service.ts
@@ -306,7 +306,18 @@ export function createDeployService(deps: DeployServiceDeps): DeployService {
const snapshotDir = await snapshotFiles(deps.deployDir, input.files);
const homeDir = input.homeFiles?.length ? await snapshotFiles(deps.deployDir, input.homeFiles) : undefined;
const env = input.stampEnv ? { ...input.env, ...input.stampEnv } : input.env;
+ const id = randomUUID();
+ if (input.createdInScope && parseScopeId(input.createdInScope).kind === "channel") {
+ await deps.acl.grant({
+ ownerScopeId: input.ownerScopeId,
+ ref: deploymentRef(id),
+ granteeScopeId: input.createdInScope,
+ permission: "read",
+ grantedBy: input.createdBy,
+ });
+ }
const d = await deps.deployStore.create({
+ id,
ownerScopeId: input.ownerScopeId,
createdBy: input.createdBy,
entrypoint: input.entrypoint,
diff --git a/src/deploy/deploy-store.ts b/src/deploy/deploy-store.ts
index de734895f..19ba897e0 100644
--- a/src/deploy/deploy-store.ts
+++ b/src/deploy/deploy-store.ts
@@ -90,6 +90,7 @@ interface VersionInput {
export interface DeployStore {
create(
input: {
+ id?: string;
ownerScopeId: ScopeId;
createdBy: string;
name?: string;
@@ -314,7 +315,7 @@ export function createDeployStore(backing?: DurableMap<Deployment> | DeployStore
return {
async create(input) {
- const id = randomUUID();
+ const id = input.id ?? randomUUID();
const v = await makeVersion(id, 1, input);
const d: Deployment = {
id,
diff --git a/src/harness/agent-tools.ts b/src/harness/agent-tools.ts
index 7c407dcf5..9c156a382 100644
--- a/src/harness/agent-tools.ts
+++ b/src/harness/agent-tools.ts
@@ -48,7 +48,9 @@ function describePublishAudience(a: PublishAudienceDescriptor | undefined): stri
const note = a.note ? ` (note: ${a.note})` : "";
if (a.kind === "org") return `Owned by you; reachable by anyone at ${a.orgId ?? "your org"}.${note}`;
if (a.kind === "members") {
- const n = a.memberCount ?? 0;
+ if (a.memberCount === undefined)
+ return `Owned by you; access follows the visibility and membership of its shared scopes.${note}`;
+ const n = a.memberCount;
const who = a.channelRef
? `the ${n} ${n === 1 ? "person" : "people"} currently in #${a.channelRef}`
: `${n} ${n === 1 ? "person" : "people"} you've shared it with`;
@@ -1160,12 +1162,12 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
name: "publish",
label: "publish",
description:
- "Publish a directory from the workspace as a durable, private-by-default web app " +
+ "Publish a directory from the workspace as a durable web app " +
"(it keeps running after the turn ends and gets a stable link). Before publishing, verify the " +
"directory exists and contains files. For a new app or a code/file update, always pass `entrypoint`; " +
"the app must listen on the PORT env var. `dir` is workspace-relative: use `app`, never a path " +
"beginning with `/` or a redundant `workspace/app`. `renameFrom` takes an existing " +
- "deployment name, not its ID. Publishing is always private to the owner and never changes who can reach an app; " +
+ "deployment name, not its ID. New apps are shared for read/use with their creation channel; DMs stay private. Republishing never changes access; " +
"grant access separately with apps action share. Share the full absolute URL " +
"returned by apps action publish so it works in Slack and other surfaces. Use `name` for a friendly, " +
"stable link /d/<name>/; `renameFrom` to rename; `rollbackTo` to flip back to an earlier version. " +
diff --git a/src/tools/primitives.ts b/src/tools/primitives.ts
index f6fe7ea6b..7f203f8fd 100644
--- a/src/tools/primitives.ts
+++ b/src/tools/primitives.ts
@@ -1055,7 +1055,7 @@ export function createToolContext(deps: ToolContextDeps): ToolContext {
async publish(input: PublishInput): Promise<PublishResult> {
if (!writableScopeId) throw new Error("publish needs a writable scope to own the app");
if (input.share !== undefined || input.public !== undefined)
- throw new Error("publish is always private to the owner; use apps action share to grant access");
+ throw new Error("publish does not accept sharing options; use apps action share to change access");
const owner: ScopeId = scopeId("personal", deps.createdBy);
const createdInScope: ScopeId = writableScopeId;
let effectiveEntrypoint = input.entrypoint;
@@ -1439,7 +1439,9 @@ function audienceFromGrantees(
return {
kind: "members",
...(origin.kind === "channel" ? { channelRef: origin.ref } : {}),
- memberCount: granteeScopeIds.length,
+ ...(granteeScopeIds.every((g) => parseScopeId(g).kind === "personal")
+ ? { memberCount: granteeScopeIds.length }
+ : {}),
};
}
diff --git a/test/agent-tools.test.ts b/test/agent-tools.test.ts
index b01d76a2e..4477dea74 100644
--- a/test/agent-tools.test.ts
+++ b/test/agent-tools.test.ts
@@ -1895,6 +1895,17 @@ test("publish reply states owner + resolved audience in human terms (ADR 0003 D7
);
assert.match(members, /reachable by the 3 people currently in #C1/);
+ const channel = textOf(
+ await call(
+ createAgentTools({ current: withAudience({ kind: "members", channelRef: "C1" }) }).find(
+ (tool) => tool.name === "apps",
+ ),
+ { action: "publish", entrypoint: "x", name: "site" },
+ ),
+ );
+ assert.match(channel, /access follows the visibility and membership of its shared scopes/);
+ assert.doesNotMatch(channel, /0 people/);
+
const owner = textOf(
await call(
createAgentTools({ current: withAudience({ kind: "owner" }) }).find((tool) => tool.name === "apps"),
diff --git a/test/deploy-app-shell.test.ts b/test/deploy-app-shell.test.ts
index 91f390f35..3ae0ecb8f 100644
--- a/test/deploy-app-shell.test.ts
+++ b/test/deploy-app-shell.test.ts
@@ -49,7 +49,7 @@ function appServingUpstream(upstreamPort: number) {
identity: createIdentityService(),
orgId: "acme",
} as unknown as Parameters<typeof createApp>[0]);
- return { app, directory };
+ return { app, directory, acl };
}
function httpGet(
@@ -79,7 +79,7 @@ async function widgetFixture(upstreamHandler?: Parameters<typeof createHttpServe
upstream.listen(0);
await new Promise((r) => upstream.once("listening", r));
const upstreamPort = (upstream.address() as AddressInfo).port;
- const { app, directory } = appServingUpstream(upstreamPort);
+ const { app, directory, acl } = appServingUpstream(upstreamPort);
const d = await app.deploy({
ownerScopeId: scopeId("personal", "U1"),
createdBy: "U1",
@@ -103,7 +103,7 @@ async function widgetFixture(upstreamHandler?: Parameters<typeof createHttpServe
await new Promise<void>((resolve) => server.close(() => resolve()));
await new Promise<void>((resolve) => upstream.close(() => resolve()));
};
- return { app, directory, port, close, featureFlags };
+ return { app, directory, acl, d, port, close, featureFlags };
}
const HOST = "mysite.apps.example.com";
@@ -332,6 +332,7 @@ test("app shell: manage grants are checked on every navigation and version reque
test("app shell: a manager from the creation scope can load the app and its assets without a read grant", async () => {
const f = await widgetFixture();
try {
+ await f.acl.revoke(f.d.ownerScopeId, `deployment:${f.d.id}`, scopeId("channel", "CBUILT"), "U1");
await f.directory.replaceChannels(
[{ channelId: "CBUILT", name: "builders", isPrivate: true }],
[{ channelId: "CBUILT", principalId: "U2" }],
diff --git a/test/deploy-publish-gate-parity.test.ts b/test/deploy-publish-gate-parity.test.ts
index 2ac4fe0e2..db68369d5 100644
--- a/test/deploy-publish-gate-parity.test.ts
+++ b/test/deploy-publish-gate-parity.test.ts
@@ -1,7 +1,7 @@
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
-import { test } from "node:test";
+import { test, mock } from "node:test";
import assert from "node:assert/strict";
import { createDeployStore } from "../src/deploy/deploy-store.ts";
import { createDeployService } from "../src/deploy/deploy-service.ts";
@@ -21,8 +21,8 @@ async function setup(opts: { withResolver: boolean } = { withResolver: true }) {
const identity = createIdentityService();
await directory.replaceChannels(
[
- { channelId: CH, name: "built" },
- { channelId: CH_OTHER, name: "shared" },
+ { channelId: CH, name: "built", isPrivate: true },
+ { channelId: CH_OTHER, name: "shared", isPrivate: true },
],
[
{ channelId: CH, principalId: "U1" },
@@ -56,7 +56,7 @@ async function setup(opts: { withResolver: boolean } = { withResolver: true }) {
name: "channel-app",
createdInScope: scopeId("channel", CH),
});
- return { deploy, acl, d };
+ return { deploy, acl, d, directory };
}
test("canManage: a channel-creation member may manage from a DM/other context", async () => {
@@ -117,3 +117,99 @@ test("canManage: the creator may still manage from a DM context", async () => {
});
assert.equal(renamed.name, "renamed-by-creator-dm");
});
+
+test("new channel apps grant read access only to authenticated current channel members", async () => {
+ const { deploy, d, directory } = await setup();
+ assert.equal(d.ownerScopeId, scopeId("personal", "U1"));
+ assert.notEqual(d.public, true);
+ assert.deepEqual(await deploy.deploymentGrantees(d.id), [{ scope: scopeId("channel", CH), permission: "read" }]);
+ assert.equal((await deploy.reachDeployment(d.id, "U2")).status, "ok");
+ assert.equal((await deploy.reachDeployment(d.id, "U3")).status, "denied");
+ assert.equal((await deploy.reachDeployment(d.id, "")).status, "denied");
+ await directory.replaceChannels(
+ [{ channelId: CH, name: "built", isPrivate: true }],
+ [{ channelId: CH, principalId: "U1" }],
+ );
+ assert.equal((await deploy.reachDeployment(d.id, "U2")).status, "denied");
+});
+
+test("direct deployment creation also grants channel read access", async () => {
+ const { deploy } = await setup();
+ const d = await deploy.deploy({
+ ownerScopeId: scopeId("personal", "U1"),
+ createdBy: "U1",
+ entrypoint: "x",
+ files: [],
+ createdInScope: scopeId("channel", CH),
+ });
+ assert.deepEqual(await deploy.deploymentGrantees(d.id), [{ scope: scopeId("channel", CH), permission: "read" }]);
+ assert.equal((await deploy.reachDeployment(d.id, "U2")).status, "ok");
+});
+
+test("DM apps stay private when republished or renamed in a channel", async () => {
+ const { deploy } = await setup();
+ const input = {
+ ownerScopeId: scopeId("personal", "U1"),
+ createdBy: "U1",
+ entrypoint: "x",
+ files: [],
+ name: "dm-app",
+ };
+ const d = await deploy.deployOrUpdate({ ...input, createdInScope: scopeId("personal", "U1") });
+ assert.deepEqual(await deploy.deploymentGrantees(d.id), []);
+ assert.equal((await deploy.reachDeployment(d.id, "U2")).status, "denied");
+ await deploy.deployOrUpdate({ ...input, createdInScope: scopeId("channel", CH) });
+ await deploy.deployOrUpdate({
+ ...input,
+ name: "renamed-dm-app",
+ renameFrom: "dm-app",
+ createdInScope: scopeId("channel", CH_OTHER),
+ });
+ assert.deepEqual(await deploy.deploymentGrantees(d.id), []);
+ assert.equal((await deploy.reachDeployment(d.id, "U2")).status, "denied");
+});
+
+test("republishing channel apps neither widens their audience nor restores revoked grants", async () => {
+ const { deploy, acl, d } = await setup();
+ const input = { ownerScopeId: d.ownerScopeId, createdBy: "U1", name: d.name!, entrypoint: "x", files: [] };
+ await deploy.deployOrUpdate({ ...input, createdInScope: scopeId("channel", CH_OTHER) });
+ assert.deepEqual(await deploy.deploymentGrantees(d.id), [{ scope: scopeId("channel", CH), permission: "read" }]);
+ assert.equal((await deploy.reachDeployment(d.id, "U3")).status, "denied");
+ await acl.revoke(d.ownerScopeId, `deployment:${d.id}`, scopeId("channel", CH), "U1");
+ await deploy.deployOrUpdate({ ...input, createdInScope: scopeId("channel", CH) });
+ assert.deepEqual(await deploy.deploymentGrantees(d.id), []);
+ assert.equal((await deploy.reachDeployment(d.id, "U2")).status, "denied");
+});
+
+test("public-channel defaults follow existing channel visibility without anonymous access", async () => {
+ const { deploy, d, directory } = await setup();
+ await directory.replaceChannels(
+ [{ channelId: CH, name: "built", isPrivate: false }],
+ [{ channelId: CH, principalId: "U1" }],
+ );
+ assert.equal((await deploy.reachDeployment(d.id, "U3")).status, "ok");
+ assert.equal((await deploy.reachDeployment(d.id, "")).status, "denied");
+ assert.notEqual((await deploy.getDeployment(d.id))?.public, true);
+});
+
+test("failed default grant leaves the app name free for a complete retry", async () => {
+ const { deploy, acl } = await setup();
+ const input = {
+ ownerScopeId: scopeId("personal", "U1"),
+ createdBy: "U1",
+ name: "retry-app",
+ entrypoint: "x",
+ files: [],
+ createdInScope: scopeId("channel", CH),
+ };
+ const failure = new Error("grant storage unavailable");
+ const grant = mock.method(acl, "grant", async () => {
+ throw failure;
+ });
+ await assert.rejects(deploy.deployOrUpdate(input), (error) => error === failure);
+ assert.equal(await deploy.getDeployment(input.name), null);
+ grant.mock.restore();
+ const d = await deploy.deployOrUpdate(input);
+ assert.deepEqual(await deploy.deploymentGrantees(d.id), [{ scope: scopeId("channel", CH), permission: "read" }]);
+ assert.equal((await deploy.reachDeployment(d.id, "U2")).status, "ok");
+});
diff --git a/test/publish-default-audience.test.ts b/test/publish-default-audience.test.ts
index f6546f492..627283e5e 100644
--- a/test/publish-default-audience.test.ts
+++ b/test/publish-default-audience.test.ts
@@ -112,7 +112,7 @@ test("D1: a channel publish is owned by personal:<initiator>, channel recorded a
const d = (await deployStore.getByName("site"))!;
assert.equal(d.ownerScopeId, scopeId("personal", "U1"), "owned by the initiator, not the channel");
assert.equal(d.createdInScope, scopeId("channel", "C1"), "channel recorded as origin metadata");
- assert.equal(r.audience?.kind, "owner", "a new app is private to its owner");
+ assert.deepEqual(r.audience, { kind: "members", channelRef: "C1" });
});
test("D1: owner always reaches their own app; canManage recognizes the owner acting from the channel", async () => {
@@ -174,7 +174,7 @@ test("Defect-2: acting in a different channel than the one the app was created i
);
});
-test("first publish is owner-only in every conversation kind", async () => {
+test("first publish grants channel read access but keeps group DMs private", async () => {
const { deploy, acl } = svc();
const config = createMemoryConfigStore(ORG);
const cases = [
@@ -189,8 +189,11 @@ test("first publish is owner-only in every conversation kind", async () => {
];
for (const [i, ctx] of cases.entries()) {
const r = await ctx.publish({ entrypoint: "node server.js", name: `app-${i}` });
- assert.equal(r.audience?.kind, "owner");
- assert.deepEqual(await deploy.deploymentGrantees(`app-${i}`), []);
+ assert.equal(r.audience?.kind, i < 2 ? "members" : "owner");
+ assert.deepEqual(
+ await deploy.deploymentGrantees(`app-${i}`),
+ i < 2 ? [{ scope: scopeId("channel", `C${i + 1}`), permission: "read" }] : [],
+ );
assert.equal((await deploy.getDeployment(`app-${i}`))?.public, undefined);
assert.notEqual((await deploy.reachDeployment(`app-${i}`, "U2")).status, "ok");
}
@@ -228,5 +231,8 @@ test("sharing after publish grants access separately", async () => {
name: "site",
});
assert.equal(again.version, 2);
- assert.deepEqual(await deploy.deploymentGrantees("site"), [{ scope: scopeId("personal", "U2"), permission: "read" }]);
+ assert.deepEqual(await deploy.deploymentGrantees("site"), [
+ { scope: scopeId("channel", "C1"), permission: "read" },
+ { scope: scopeId("personal", "U2"), permission: "read" },
+ ]);
});