8000 feat(timeline): a file changed in its source is file.changed, an update linking the asset it was before by adeelahmad · Pull Request #658 · 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
3 changes: 3 additions & 0 deletions changelog.d/timeline-file-changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A file a watched folder finds changed in its source now shows on the timeline as "Office share updated “Minutes”"
(`file.changed`, an Update that links the asset it was before) rather than as a second "added". Automations on new
assets fire on it as before.
1 change: 1 addition & 0 deletions docs/automations.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ and the paths holding outside text are in `GET /api/v1/activities/kinds` (`event
| `calendar_event.added` | `asset.added` | `recordings` | `startTime`, `endTime`, `location`, `organizer`, `attendees` (addresses), `calendar` | Family calendar added the event “Parents' evening” on 2026-10-20 |
| `feed_post.received` | `asset.added` | `recordings` | `href` (the post's address), `site`, `feed` (its title), `author`, `published`, `categories` | Harbour news received the post “Autumn regatta” from harbour.example.org |
| `file.added` | `asset.added` | `recordings` | `path` (in its source), `mediaType`, `size` (bytes), `duration` (seconds) | Office share added “Minutes” |
| `file.changed` | `asset.added` | `recordings` | as `file.added`, and `previous` (`id`, `url`: the asset it was before); an `Update`, for a file changed in its source and read again | Office share updated “Minutes” |
| `upload.added` | `asset.added` | `recordings` | `path` (the file's name), `mediaType`, `size`, `duration` | Sam uploaded “Call with the school” |
| `web_page.saved` | `asset.added` | `recordings` | `href` (the page's address), `site` | Sam saved “Museum opening hours” from museum.example.org |
| `import.received` | `asset.added` | `recordings` | `via`: hook (an import hook), paste (pasted text) or file (a file read as text) | Phone shortcut imported “Shopping list” |
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ request, to another check that proves the same thing; loosening a requirement or
| A For you order of the timeline, learned from each person's own reactions, comments and marks, each item saying why, with Latest the default; through the API, MCP, the assistant and the page | [test_timeline_for_you.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_for_you.py) `test_for_you_learns_from_reactions_comments_and_marks_and_says_why`, `test_agents_read_for_you_too`; jest [timeline-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-model.test.ts) `keep the For you order as a view, not a filter`, [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `For you: the toggle goes in the address, each placed line says why, and Latest stays the default` |
| Muting a source, a person or a kind on the timeline, for good or until a time, for the person alone, with nothing deleted; through the API, MCP, the assistant (asking first after outside text) and the page | [test_timeline_mutes.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_mutes.py) `test_a_mute_hides_an_actor_or_a_kind_for_the_person_alone`, `test_agents_mute_too_and_the_assistant_asks_first_after_outside_text`; jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `muting a source takes everything from it out, lists it as muted, and Undo or the chip brings it back`, `the menu beside Mute snoozes a source for a day, or mutes the item's kind` |
| An asset moved to another namespace is `asset.moved`, a Move seen where it is now, and a sensor a person pauses, ignores, resumes or sets back to new is `sensor.changed`, an Update with the status it had before, seen in its namespace or by admins; a change that changes nothing logs nothing | [test_timeline_verbs.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_verbs.py) `test_moving_an_asset_is_a_move_seen_where_it_is_now`, `test_switching_a_sensor_is_an_update_with_what_it_was` |
| A file a watched folder finds changed in its source and reads again is `file.changed`, an Update linking the asset it was before, not a second `file.added`; it is still a child of `asset.added`, so triggers on new assets fire on it as before | [test_events_content.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_events_content.py) `test_a_file_changed_in_its_source_is_file_changed_linked_to_the_asset_it_was_before` |
| An opened timeline item shows what it caused, the runs it started of the automations the person manages and the approvals those asked for, with Approve and Decline on waiting ones; `GET /activities/{id}/caused`, `approvals?activity=`, MCP `activity_caused` and the assistant | [test_timeline_caused.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_caused.py) `test_an_item_lists_what_it_caused_and_the_waiting_approval_is_decided_there`, `test_agents_read_what_an_item_caused_too`; jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `an opened item shows what it caused, and a waiting approval is approved there` |
| One timeline item by its id in the address (`/timeline?item=<id>`), opened above the timeline with its actions and a way back, which is where a comment on an item, a reaction and an approval's "because" link | jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `the address can name one item, opened above the timeline, with a way back`; [test_timeline_social.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_social.py) `test_comments_on_a_logged_activity_follow_its_audience` |
| Saved views of the timeline: its filters and order under a name, each person's own, picked from the page's Views menu and through the API and MCP | [test_timeline_views.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_views.py) `test_timeline_views_are_saved_renamed_changed_and_deleted_by_their_maker_alone`, `test_agents_list_save_and_delete_timeline_views`; jest [timeline-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-model.test.ts) `a saved view keeps the filters and order as they are, and offers a name from them`, [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `Views: one click shows a saved view, and the filters shown now are saved under a guessed name`, `Views: the view the filters match is named on the button, and deleting it can be undone` |
Expand Down
7 changes: 4 additions & 3 deletions docs/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Status: in progress. The studio's timeline is built in steps; only what is merge
| Sources, sensors, people and agents as actors in the graph: a Source node with ADDED links, on the canvas, in the explorer and in Cypher | built |
| A For you order learned from what each person reacts to, comments on, marks important and hides, each item saying why | built |
| Muting a source, person or kind, for good or until a time, for yourself alone; `mute_activities` for agents | built |
| Moves and switches as their own verbs: an asset moved to another namespace (`asset.moved`, a Move) and a sensor paused, ignored or resumed (`sensor.changed`, an Update with what it was) | built |
| Moves and switches as their own verbs: an asset moved to another namespace (`asset.moved`, a Move), a sensor paused, ignored or resumed (`sensor.changed`, an Update with what it was), and a file changed in its source and read again (`file.changed`, an Update linking the asset it was before) | built |
| Saved views: the filters and order under a name, one click away in the page's Views menu, each person's own; `timeline_views`, `save_timeline_view` and `delete_timeline_view` for agents | built |

## What shows
Expand Down Expand Up @@ -276,8 +276,9 @@ per source page; they go when the person is removed. Nothing of this costs a mod
- For you counts opens too, once the page reports them, and could cache each person's affinity for a minute rather
than summing it on every read.
- A muted actor's own line in the Filters, and a snooze of your own length from the page.
- A file changed in its source and read again is `asset.added` once more; linking the new activity to the
asset's earlier one as a `file.changed` Update, rather than a second Create, is to come.
- A file changed in its source is read again as a new asset beside the earlier one (`file.changed` links them);
reading the change into the same asset is to come. A file in a namespace's own folders changed in place is read
again into the same asset with no activity yet.
- Marks on activities whose rows are gone (an event log entry past `events.keep_days`, a deleted asset) stay until
the person is removed; a tidy could drop them. Reactions and comments on such activities likewise.
- The agent's reply in a thread is plain text with links; the answer's excerpts could open at their moment, as in
Expand Down
47 changes: 39 additions & 8 deletions fastapi_backend/app/domain/events_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

Each new asset is one activity, `create-recording-<id>`, the same every time it's read, of the most specific kind its
row tells: an email received from a mailbox (`email.received`), a calendar event (`calendar_event.added`), a news
feed's post (`feed_post.received`), a file from storage or Drive (`file.added`), an upload (`upload.added`), a page or video saved from the web
feed's post (`feed_post.received`), a file from storage or Drive (`file.added`; `file.changed`, an Update, when it is a
file read again because it changed there, linked to its earlier asset as `previous`), an upload (`upload.added`), a page or video saved from the web
(`web_page.saved`), something imported (pasted text, a transcript, an import hook's: `import.received`), else
`asset.added`, their parent. The kind is read from the row's content type, where it came from and who brought it,
never from its file.
Expand Down Expand Up @@ -36,7 +37,7 @@
R = store.R
FIELDS = (
"id AS rid, record::id(id) AS id, space, title, source, media, remote, content_type, created_at, path, web, engine, "
"created_by, mail, event, post, email, size, duration_ms, attached_to, converted_from, sensor, form"
"created_by, mail, event, post, email, size, duration_ms, attached_to, converted_from, sensor, form, replaces"
)
TYPES = {"audio": "Audio", "video": "Video", "image": "Image", "document": "Document", "transcript": "Document"}
AUTOMATION_RX = re.compile(r"^automation:(\d+)$")
Expand Down Expand Up @@ -308,7 +309,7 @@ def _feed_post(r):
def _file(r, kind):
"""A file's fields: its name in its source (or the name it was uploaded with), media type, size and length."""
remote = r.get("remote") or {}
path = remote.get("path") if kind == "file.added" else pathlib.PurePosixPath(str(r.get("path") or "")).name
path = remote.get("path") if kind in ("file.added", "file.changed") else pathlib.PurePosixPath(str(r.get("path") or "")).name
media_type = mimetypes.guess_type(str(path or ""))[0]
return store.clean(
{
Expand Down Expand Up @@ -348,7 +349,7 @@ def _kind(r, ctype, source_type, actor):
if (r.get("web") or {}).get("url"):
return "web_page.saved"
if (r.get("remote") or {}).get("source") is not None:
return "file.added"
return "file.changed" if _num(r.get("replaces")) is not None else "file.added"
if UPLOAD_RX.search(str(r.get("path") or "")):
return "upload.added"
if str(r.get("engine") or "").startswith("import:") or str(r.get("path") or "").startswith(("paste:", "hook:")):
Expand All @@ -368,6 +369,8 @@ def _summary(kind, actor, obj):
return f"{who} received the post “{title}”" + (f" from {obj['site']}" if obj.get("site") else "")
if kind == "upload.added":
return f"{who} uploaded “{title}”"
if kind == "file.changed":
return f"{who} updated “{title}”"
if kind == "web_page.saved":
return f"{who} saved “{title}”" + (f" from {obj['site']}" if obj.get("site") else "")
if kind == "import.received":
Expand Down Expand Up @@ -450,8 +453,10 @@ def _activities(db, rows):
obj.update(_event(r))
elif kind == "feed_post.received":
obj.update(_feed_post(r))
elif kind in ("file.added", "upload.added"):
elif kind in ("file.added", "upload.added", "file.changed"):
obj.update(_file(r, kind))
if kind == "file.changed":
obj["previous"] = {"id": f"lens:recording/{int(r['replaces'])}", "url": f"/resources/{int(r['replaces'])}"}
elif kind == "web_page.saved":
obj.update(_web(r))
elif kind == "import.received":
Expand Down Expand Up @@ -558,19 +563,19 @@ def _addrs(title, item="Address"):
return {"type": "array", "title": title, "items": {"type": "string", "title": item}}


def _child(name, label, props, untrusted, sample_actor, sample_obj, summary):
def _child(name, label, props, untrusted, sample_actor, sample_obj, summary, as_type="Create"):
events.kind(
name,
label=label,
source="recordings",
as_type="Create",
as_type=as_type,
object_type="Document",
parent="asset.added",
fields={"object": {"type": "object", "properties": props}},
untrusted=untrusted,
sample={
"id": "create-recording-7",
"type": "Create",
"type": as_type,
"kind": name,
"published": "2026-10-15T16:21:58.000Z",
"ac 8 tor" 10BC8 ;: sample_actor,
Expand Down Expand Up @@ -693,6 +698,32 @@ def _child(name, label, props, untrusted, sample_actor, sample_obj, summary):
},
"Office share added “Minutes”",
)
_child(
"file.changed",
"File changed",
{
**FILE_FIELDS,
"previous": {
"type": "object",
"title": "Earlier version",
"properties": {"id": _s("Its asset"), "url": _s("Its page")},
},
},
("object.name", "object.path"),
{"type": "Service", "id": "lens:source/9", "name": "Office share"},
{
"type": "Document",
"name": "Minutes",
"media": "document",
"content_type": "document",
"path": "board/2026-10 minutes.docx",
"mediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"size": 49120,
"previous": {"id": "lens:recording/6", "url": "/resources/6"},
},
"Office share updated “Minutes”",
as_type="Update",
)
_child(
"upload.added",
"Upload added",
Expand Down
8 changes: 6 additions & 2 deletions fastapi_backend/app/domain/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ def poll_watch(db, cfg, wid, log=print):
)
src = get(db, w["source"])
first, now = not w.get("last_scan_at"), dt.datetime.now(dt.timezone.utc)
known = {r["path"]: r for r in db.rows("SELECT path, size, modified, status FROM remote_file WHERE watch = $w", w=wid)}
known = {r["path"]: r for r in db.rows("SELECT path, size, modified, status, recording FROM remote_file WHERE watch = $w", w=wid)}
gone = {w["space"]: deletion.gone_remote(db, w["space"])} # recordings someone deleted stay deleted
stats = {"seen": 0, "new": 0, "waiting": 0, "skipped": 0, "errors": 0}
routes, shared = w.get("routes") or [], (src.get("routes") or []) if feeds.is_email(src) else []
Expand Down Expand Up @@ -813,7 +813,11 @@ def poll_watch(db, cfg, wid, log=print):
held.add(f["path"])
else:
try:
rid, _job = _ingest(db, cfg, src, f, kind, space, f"watch:{wid}", w.get("steps"), w.get("pipeline"))
rid, job = _ingest(db, cfg, src, f, kind, space, f"watch:{wid}", w.get("steps"), w.get("pipeline"))
before = (k or {}).get("recording")
if job and isinstance(before, int) and before != rid and not feeds.handles(src):
# the file changed there and was read again as a new asset: file.changed, linked to the earlier one
db.q("UPDATE $r SET replaces = $b", r=R("recording", rid), b=before)
db.q("UPSERT $k CONTENT $d", k=key, d={**row, "status": "queued", "recording": rid})
stats["new"] += 1
if space != w["space"]:
Expand Down
28 changes: 28 additions & 0 deletions fastapi_backend/tests/domain/test_events_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,34 @@ def test_a_file_from_storage_is_file_added(db, cfg):
assert a["summary"] == "Office share added “minutes”" and set(a["lens"]["untrusted"]) == {"object.name", "object.path"}


def test_a_file_changed_in_its_source_is_file_changed_linked_to_the_asset_it_was_before(db, cfg, monkeypatch):
calls = store.ns_id(db, "calls")
src = source(db, "Office share", "s3")
wid = db.next_id("watch_path")
db.q(
"CREATE $r CONTENT $d",
r=R("watch_path", wid),
d={"source": src["id"], "path": "/talks", "space": calls, "kinds": "both", "backfill": True, "stable_seconds": 0},
)
listing = [{"path": "/talks/one.mp3", "size": 10, "modified": "2026-01-01T00:00:00Z"}]
monkeypatch.setattr(sources, "list_files", lambda *a, **k: listing)
quiet = lambda *a: None # noqa: E731
assert sources.poll_watch(db, cfg, wid, log=quiet)["new"] == 1
(first,) = db.values("SELECT VALUE record::id(id) FROM recording WHERE remote.path = '/talks/one.mp3'")
assert one(db, cfg, first)["kind"] == "file.added"
assert sources.poll_watch(db, cfg, wid, log=quiet)["new"] == 0 # unchanged: nothing new
listing[0].update(size=11, modified="2026-02-01T00:00:00Z")
assert sources.poll_watch(db, cfg, wid, log=quiet)["new"] == 1
(second,) = [r for r in db.values("SELECT VALUE record::id(id) FROM recording WHERE remote.path = '/talks/one.mp3'") if r != first]
a = one(db, cfg, second)
assert (a["kind"], a["type"]) == ("file.changed", "Update")
assert a["object"]["previous"] == {"id": f"lens:recording/{first}", "url": f"/resources/{first}"}
assert a["object"]["path"] == "/talks/one.mp3" and a["object"]["size"] == 11
assert a["summary"] == "Office share updated “one”" and set(a["lens"]["untrusted"]) == {"object.name", "object.path"}
assert one(db, cfg, first)["kind"] == "file.added" # the earlier one stays what it was
assert "file.changed" in events.descendants("asset.added") # a trigger on any asset still fires on it


def test_an_upload_is_upload_added_by_whoever_uploaded_it(db, cfg, folder):
sam = make_user(db, "sam@example.org", "sam password 1", roles={"pods": "editor"})
db.q("UPDATE $r SET name = 'Sam'", r=R("account", sam))
Expand Down
1 change: 1 addition & 0 deletions nextjs-frontend/components/timeline/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const NOUNS: Record<string, [string, string, string]> = {
"calendar_event.changed": ["changed", "calendar event", "calendar events"],
"feed_post.received": ["received", "post", "posts"],
"file.added": ["added", "file", "files"],
"file.changed": ["updated", "file", "files"],
"upload.added": ["uploaded", "file", "files"],
"web_page.saved": ["saved", "web page", "web pages"],
"import.received": ["imported", "item", "items"],
Expand Down
Loading
0