8000 feat(circles): circles under Profile and a Share action in the web app by adeelahmad · Pull Request #649 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p
- **Share with the people close to you.** Make circles of trust (your family, close family, friends, colleagues) of
people on the same Lens, and share an activity from your timeline or a resource with a circle and a note: each of
them sees it in their own timeline, and you see it in yours, so nothing is shared behind anyone's back. Share with the
item to also let them open the resource; undo takes it all back, and nothing leaves a vault. Agents do the same over
MCP, and the assistant asks you first. ([Circles of trust](docs/circles.md);
item to also let them open the resource; undo takes it all back, and nothing leaves a vault. In the web app, circles
live under Profile and Share sits on every timeline item and resource. Agents do the same over MCP, and the
assistant asks you first. ([Circles of trust](docs/circles.md);
[checks](docs/requirements.md#share-with-the-people-close-to-you))
- **See what it costs.** An activity ledger of every model call, with reports, charts and budgets that cap spending.
Setup asks for one overall budget after a cloud model, with a soft limit that warns and a hard limit that stops paid
Expand Down Expand Up @@ -333,7 +334,7 @@ Open pull requests, not yet part of Lens, are listed here; none right now.

Next, and not in a pull request yet; each links to where it is tracked:

- **Circles of trust:** circles and a Share action in the web app, rules for what your agent shares without asking,
- **Circles of trust:** rules for what your agent shares without asking,
asking someone's agent (when they're free, what a trip needs) answered from what they let you see, and circles
across Lens servers over ActivityPub ([circles of trust](docs/circles.md)).
- **Notes:** nesting a note under its project or area without a click, pages in the graph, and wiki addresses for
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/circles-web.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- **Circles in the web app.** Your circles are under Profile: a suggested name makes one in one click, people are
added from a list and taken out with ×, and deleting one is undone from its message. **Share** on a timeline item,
or **Share with a circle…** in a resource's menu, picks your only circle, takes a note, and is undone from its
message; shares show under *Shared* in the timeline ([Circles of trust](docs/circles.md)).
9 changes: 8 additions & 1 deletion docs/circles.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Status: in progress. Circles are built in steps; only what is merged is called b
| Part | Status |
| --- | --- |
| Circles of people on the same Lens, sharing an activity or a resource with them and a note, with the item or without, undo; API, MCP and the assistant | built |
| Circles under Profile in the web app, and a Share action on timeline items and resource pages | planned |
| Circles under Profile in the web app, and a Share action on timeline items and resource pages | built |
| Rules per circle: what your agent shares without asking (kinds, entities, a match tree) and what it asks you first about | planned |
| Asking someone's agent (when are they free, what does the trip need), answered only from what they let that circle see, with citations | planned |
| Circles across Lens servers over ActivityPub: a signed inbox, an outbox and WebFinger handles like `sam@lens.example` | planned |
Expand All @@ -24,6 +24,9 @@ Colleagues); none is made for you.
You can add people you share a namespace with, and people who have you in a circle of theirs, so your son can add you
back once you have added him. Admins can add anyone. Adding someone tells them nothing; sharing does.

**In the web app**, your circles are under Profile: a suggested name makes a circle in one click, *Add someone…*
adds a person, the × by a name takes them out, and deleting a circle is undone from its message.

## Sharing

Share one thing at a time with one or more of your circles, or with people in them:
Expand All @@ -37,6 +40,10 @@ what it said when you shared it: the name, the line the timeline gave it, the en
activity and your note. Their automations can follow `share.received` like any other kind ("when Dad shares a school
notice, add it to my calendar"), and their agent reads the note and snapshot as outside text.

In the web app, open an item in the [timeline](timeline.md) and pick **Share**, or pick **Share with a circle…** in
a resource's ⋯ menu. Your only circle is already picked; add a note and share. The message that says it was shared
has **Undo**. Shares show in the timeline under *Shared*.

**With the item.** A share says what the item is, not what is in it. Turn on *with the item* to also give each
person who can't open the resource permission on that one resource, as an owner gives permission on an asset
([Access](access.md#permission-on-an-asset)): they then open it on the visitors' pages. It needs the `publish`
Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ request, to another check that proves the same thing; loosening a requirement or
| Sharing an activity or a resource with a circle and a note shows it in each member's own timeline and the sharer's, with the item or without, undone with its permissions, never from a vault | [test_circles.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_circles.py) `test_sharing_with_a_circle` |
| Automations follow what was shared with the person; removing someone takes their circles and what was shared with them | [test_circles.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_circles.py) `test_automations_follow_shares` |
| Agents make circles and share over MCP; the assistant shares only after the person's yes | [test_circles.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_circles.py) `test_agents_share_too` |
| Circles live under Profile, a suggested circle takes one click and deleting one is undone, not confirmed | [circles-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/circles-ui.test.tsx) `makes a suggested circle in one click`; [circles-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/circles-ui.test.tsx) `deletes a circle with Undo instead of a confirm` |
| Share on a timeline item or a resource picks the only circle, takes a note and is undone from its toast | [circles-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/circles-ui.test.tsx) `picks the only circle, shares with a note, and undoes from the toast` |

## See what it costs

Expand Down
5 changes: 3 additions & 2 deletions docs/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ unless you ask for them by kind.
("Work Gmail received 37 emails"), so a first mailbox sync reads as one line. A click opens it to its items.
- Each line has an icon by kind, the summary (a link to what it is about), who did it, the namespace, the kind and
how long ago. Opened, an item shows its object's fields, the automation run that caused it if one did, **What
this caused** ([below](#what-an-item-caused)), **Open**, **Ask about this** and **Hide**.
this caused** ([below](#what-an-item-caused)), **Open**, **Ask about this**, **Share** (with your
[circles](circles.md)) and **Hide**.
- Filters: words in the summary (Enter applies), **Unreviewed only**, **Important**, kinds by family (Email,
Calendar, Files, Notes, Sensors, Chat, Automations, System; noisy kinds like sensor readings only when picked),
Calendar, Files, Notes, Shared, Sensors, Chat, Automations, System; noisy kinds like sensor readings only when picked),
source or person (from those on the timeline), namespace, entity (as activities tag it), a date range, and an
automation (what it did or caused). Filters live in the address, so a view can be linked, and the last set you used
comes back the next time you open the page in this browser. **Clear** drops them all.
Expand Down
163 changes: 163 additions & 0 deletions nextjs-frontend/__tests__/circles-ui.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import "@testing-library/jest-dom";

import { CirclesPanel } from "@/components/account/circles";
import { addable, firstPick, personLabel, reach, shareable, whom } from "@/components/circles/model";
import { ShareDialog } from "@/components/circles/share-dialog";
import { familyOf } from "@/components/timeline/model";
import { TooltipProvider } from "@/components/ui/tooltip";

const ok = (data: unknown) => Promise.resolve({ data, response: { ok: true, status: 200 } });
const sam = { id: 2, name: "Sam", email: "sam@x.io" };
const sara = { id: 3, name: null, email: "sara@x.io" };
const family = { id: 1, name: "Immediate family", members: [sam] };
const friends = { id: 4, name: "Friends", members: [sam, sara] };

const mockApi = {
listCircles: jest.fn(),
listCirclePeople: jest.fn(() => ok([sam, sara])),
createCircle: jest.fn(() => ok({ id: 9, name: "Friends", members: [] })),
updateCircle: jest.fn(() => ok(family)),
deleteCircle: jest.fn(() => ok({ ok: true })),
shareWithCircles: jest.fn(() =>
ok({ id: 7, at: "", object: {}, circles: [], people: [], with_item: false, granted: 0 }),
),
undoCircleShare: jest.fn(() => ok({ undone: 1, taken_back: 0 })),
};
jest.mock("@/app/openapi-client", () => ({
get Circles() {
return mockApi;
},
}));
jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) }));
const toast = jest.fn();
jest.mock("@/components/ui/toast", () => ({ useToast: () => toast }));

beforeEach(() => {
jest.clearAllMocks();
mockApi.listCircles.mockImplementation(() => ok({ circles: [family], suggested: ["Close family", "Friends"] }));
});

function show(ui: React.ReactNode) {
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<QueryClientProvider client={qc}>
<TooltipProvider>{ui}</TooltipProvider>
</QueryClientProvider>,
);
}

describe("the circles model", () => {
it("names people, and offers only who isn't in the circle yet", () => {
expect(personLabel(sara)).toBe("sara@x.io");
expect(personLabel({ id: 5 })).toBe("Account 5");
expect(addable([sam, sara], family).map((p) => p.id)).toEqual([3]);
});

it("says who a share goes to and counts each person once", () => {
const all = [family, friends];
expect(whom(all, [1])).toBe("Immediate family");
expect(whom(all, [1, 4])).toBe("Immediate family and Friends");
expect(whom([...all, { id: 6, name: "Work" }], [1, 4, 6])).toBe("3 circles");
expect(reach(all, [1, 4])).toBe(2);
expect(firstPick([family])).toEqual([1]);
expect(firstPick(all)).toEqual([]);
});

it("doesn't pass shares on, and files them under Shared", () => {
expect(shareable("share.received")).toBe(false);
expect(shareable("email.received")).toBe(true);
expect(familyOf("share.received")).toBe("Shared");
});
});

describe("circles under Profile", () => {
it("makes a suggested circle in one click", async () => {
show(<CirclesPanel />);
fireEvent.click(await screen.findByRole("button", { name: "Close family" }));
await waitFor(() =>
expect(mockApi.createCircle).toHaveBeenCalledWith(expect.objectContaining({ body: { name: "Close family" } })),
);
});

it("adds and takes out people", async () => {
show(<CirclesPanel />);
const add = await screen.findByRole("combobox", { name: "Add someone to Immediate family" });
await screen.findByRole("option", { name: "sara@x.io" });
fireEvent.change(add, { target: { value: "3" } });
await waitFor(() =>
expect(mockApi.updateCircle).toHaveBeenCalledWith(
expect.objectContaining({ path: { cid: 1 }, body: { add: [3] } }),
),
);
fireEvent.click(screen.getByRole("button", { name: "Take Sam out of Immediate family" }));
await waitFor(() =>
expect(mockApi.updateCircle).toHaveBeenCalledWith(expect.objectContaining({ body: { remove: [2] } })),
);
});

it("deletes a circle with Undo instead of a confirm", async () => {
show(<CirclesPanel />);
fireEvent.click(await screen.findByRole("button", { name: "Delete Immediate family" }));
await waitFor(() => expect(mockApi.deleteCircle).toHaveBeenCalled());
const t = toast.mock.calls.at(-1)[0];
expect(t.title).toBe("Deleted Immediate family");
t.action.onClick();
await waitFor(() =>
expect(mockApi.createCircle).toHaveBeenCalledWith(
expect.objectContaining({ body: { name: "Immediate family", members: [2] } }),
),
);
});
});

describe("sharing", () => {
it("picks the only circle, shares with a note, and undoes from the toast", async () => {
show(<ShareDialog open => {}} activity="email-5" what="“School trip”" />);
const box = await screen.findByRole("checkbox");
await waitFor(() => expect(box).toBeChecked());
fireEvent.change(screen.getByRole("textbox"), { target: { value: "Packed lunch on Friday" } });
fireEvent.click(screen.getByRole("button", { name: "Share with 1" }));
await waitFor(() =>
expect(mockApi.shareWithCircles).toHaveBeenCalledWith(
expect.objectContaining({
body: {
activity: "email-5",
recording: null,
circles: [1],
note: "Packed lunch on Friday",
with_item: false,
},
}),
),
);
const t = toast.mock.calls.at(-1)[0];
expect(t.title).toBe("Shared with Immediate family");
t.action.onClick();
await waitFor(() =>
expect(mockApi.undoCircleShare).toHaveBeenCalledWith(expect.objectContaining({ path: { sid: 7 } })),
);
});

it("offers the item itself only for a resource", async () => {
show(<ShareDialog open => {}} recording={12} what="“Report”" />);
fireEvent.click(await screen.findByRole("switch"));
await waitFor(() => expect(screen.getByRole("checkbox")).toBeChecked());
fireEvent.click(screen.getByRole("button", { name: "Share with 1" }));
await waitFor(() =>
expect(mockApi.shareWithCircles).toHaveBeenCalledWith(
expect.objectContaining({ body: expect.objectContaining({ recording: 12, with_item: true }) }),
),
);
});

it("points to Profile when there are no circles yet", async () => {
mockApi.listCircles.mockImplementation(() => ok({ circles: [], suggested: [] }));
show(<ShareDialog open => {}} activity="email-5" what="“School trip”" />);
expect(await screen.findByRole("link", { name: "Make one under Profile" })).toHaveAttribute(
"href",
"/account#circles",
);
});
});
Loading
Loading
0