@engenty/wizards-runtime 0.9.8 → 0.11.0
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/apps/runtime/dist/app.js +34 -1
- package/apps/runtime/dist/auth/index.js +10 -1
- package/apps/runtime/dist/db/client.js +9 -1
- package/apps/runtime/dist/db/live-triggers.js +144 -0
- package/apps/runtime/dist/db/migrations/tenant/0022_sync.sql +247 -0
- package/apps/runtime/dist/db/migrations/tenant/0023_live_change.sql +167 -0
- package/apps/runtime/dist/db/migrations/tenant/0024_live_presence.sql +28 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0022_snapshot.json +3792 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0023_snapshot.json +3860 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0024_snapshot.json +3967 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +21 -0
- package/apps/runtime/dist/db/schema.js +101 -0
- package/apps/runtime/dist/docs/user-guide/cloud-sync.md +85 -0
- package/apps/runtime/dist/docs/user-guide/data.md +4 -4
- package/apps/runtime/dist/docs/user-guide/meta.json +2 -0
- package/apps/runtime/dist/docs/user-guide/test-and-share.md +4 -14
- package/apps/runtime/dist/docs/user-guide/together.md +60 -0
- package/apps/runtime/dist/files/blobs.js +13 -0
- package/apps/runtime/dist/index.js +11 -1
- package/apps/runtime/dist/live/feed.js +34 -0
- package/apps/runtime/dist/live/hub.js +200 -0
- package/apps/runtime/dist/live/origin.js +53 -0
- package/apps/runtime/dist/live/views.js +146 -0
- package/apps/runtime/dist/mcp/handler.js +7 -1
- package/apps/runtime/dist/mcp/tools.js +51 -2
- package/apps/runtime/dist/plugins/jobs.js +7 -0
- package/apps/runtime/dist/routes/api.js +177 -1
- package/apps/runtime/dist/routes/live.js +85 -0
- package/apps/runtime/dist/routes/studio.js +109 -85
- package/apps/runtime/dist/services/cloud.js +39 -5
- package/apps/runtime/dist/services/presence.js +132 -0
- package/apps/runtime/dist/services/projects.js +11 -0
- package/apps/runtime/dist/services/space-data.js +33 -6
- package/apps/runtime/dist/sync/apply.js +43 -0
- package/apps/runtime/dist/sync/client.js +973 -0
- package/apps/runtime/dist/sync/hub.js +324 -0
- package/apps/runtime/dist/sync/log.js +74 -0
- package/apps/runtime/dist/sync/records.js +943 -0
- package/apps/runtime/dist/sync/state.js +17 -0
- package/apps/runtime/dist/texts.js +2 -0
- package/apps/web/dist/assets/AboutDialog-9VcgySrQ.js +1 -0
- package/apps/web/dist/assets/{ChangelogDialog-BpEIbAZ8.js → ChangelogDialog-BXvT2VMU.js} +1 -1
- package/apps/web/dist/assets/EditorPage-Cvzd0nah.js +4 -0
- package/apps/web/dist/assets/{FlowPreview-APXdRflR.js → FlowPreview-BV1NJ0rF.js} +1 -1
- package/apps/web/dist/assets/{Harness-BsGXMlLg.js → Harness-DYviBlHB.js} +2 -2
- package/apps/web/dist/assets/Marketplace-DTSg7_U7.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-0JrRdUFd.js → NewWizardChannels-DiujJzOR.js} +1 -1
- package/apps/web/dist/assets/NewWizardPage-CngUh9g-.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-DFKJnWtw.js +1 -0
- package/apps/web/dist/assets/PreviewPane-C0E9OLzB.js +9 -0
- package/apps/web/dist/assets/ProjectPage-CYDX-JYc.js +1 -0
- package/apps/web/dist/assets/PublicRunner-CkRO_Pw-.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-BraZbEG_.js → ReadOnly-E-h9y_QO.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-BMgP3aRV.js +2 -0
- package/apps/web/dist/assets/SetupPage-DBO_rzj7.js +1 -0
- package/apps/web/dist/assets/{SharePage-Dk7zC5Zo.js → SharePage-BvvmYB5N.js} +1 -1
- package/apps/web/dist/assets/changelog-zllICQ4q.js +1 -0
- package/apps/web/dist/assets/{coins-391m1e4_.js → coins-DQ91VJAB.js} +1 -1
- package/apps/web/dist/assets/index-Bjn557f1.js +20 -0
- package/apps/web/dist/assets/index-DN0VMwsS.css +1 -0
- package/apps/web/dist/assets/{phone-DvgrtyNO.js → phone-jIuRIwyg.js} +1 -1
- package/apps/web/dist/assets/{runners-4OBelIgF.js → runners-DloOxEbh.js} +1 -1
- package/apps/web/dist/assets/session-BpsCkDv6.js +2 -0
- package/apps/web/dist/assets/{settings-menu-xK9A-gaP.js → settings-menu-CoLUNJGQ.js} +1 -1
- package/apps/web/dist/assets/theme-2XjIQXH3.js +11 -0
- package/apps/web/dist/assets/{ui-BVQk2DtW.js → ui-BIWmkPh6.js} +3 -3
- package/apps/web/dist/assets/{upload-BgXbzG6C.js → upload-BcOvBWHS.js} +1 -1
- package/apps/web/dist/assets/{useMutation-DkwSQWoD.js → useMutation-CD7HmAxR.js} +1 -1
- package/apps/web/dist/assets/{volume-2-DHGoe3Cg.js → volume-2-D2To9w5D.js} +1 -1
- package/apps/web/dist/assets/{wrench-Cf_aE3O0.js → wrench-B98ubRvB.js} +1 -1
- package/apps/web/dist/index.html +8 -8
- package/apps/web/dist/mcp/flow.html +2 -2
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +12 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +12 -0
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +46 -0
- package/node_modules/@engenty/wizards-shared/dist/live.js +9 -0
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +7 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +14 -0
- package/node_modules/@engenty/wizards-shared/dist/sync-merge.d.ts +55 -0
- package/node_modules/@engenty/wizards-shared/dist/sync-merge.js +214 -0
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +166 -0
- package/node_modules/@engenty/wizards-shared/dist/sync.js +40 -0
- package/node_modules/@engenty/wizards-shared/dist/text-merge.d.ts +14 -0
- package/node_modules/@engenty/wizards-shared/dist/text-merge.js +137 -0
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/AboutDialog-B_Ixp_Tb.js +0 -1
- package/apps/web/dist/assets/EditorPage-CKHY4hn4.js +0 -4
- package/apps/web/dist/assets/Marketplace-Dr-Qnb-F.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-9igFL5O8.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-BcK9FUnU.js +0 -1
- package/apps/web/dist/assets/PreviewPane-X4LBqA0D.js +0 -4
- package/apps/web/dist/assets/ProjectPage-CG0i-KhR.js +0 -1
- package/apps/web/dist/assets/PublicRunner-CZR1ziQ4.js +0 -1
- package/apps/web/dist/assets/SettingsPage-Bw4tdoV7.js +0 -2
- package/apps/web/dist/assets/SetupPage-CvkE2aKx.js +0 -1
- package/apps/web/dist/assets/changelog-DDXnAaHm.js +0 -1
- package/apps/web/dist/assets/index-BTUtot4r.js +0 -14
- package/apps/web/dist/assets/index-DcUL6teA.css +0 -1
- package/apps/web/dist/assets/session-DvnGHbDz.js +0 -2
- package/apps/web/dist/assets/theme-D3yDT4QT.js +0 -11
|
@@ -155,6 +155,27 @@
|
|
|
155
155
|
"when": 1792568616734,
|
|
156
156
|
"tag": "0021_model_classes",
|
|
157
157
|
"breakpoints": true
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"idx": 22,
|
|
161
|
+
"version": "6",
|
|
162
|
+
"when": 1792580809821,
|
|
163
|
+
"tag": "0022_sync",
|
|
164
|
+
"breakpoints": true
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"idx": 23,
|
|
168
|
+
"version": "6",
|
|
169
|
+
"when": 1792647499005,
|
|
170
|
+
"tag": "0023_live_change",
|
|
171
|
+
"breakpoints": true
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"idx": 24,
|
|
175
|
+
"version": "6",
|
|
176
|
+
"when": 1792649943526,
|
|
177
|
+
"tag": "0024_live_presence",
|
|
178
|
+
"breakpoints": true
|
|
158
179
|
}
|
|
159
180
|
]
|
|
160
181
|
}
|
|
@@ -625,3 +625,104 @@ export const pluginConnection = sqliteTable("plugin_connection", {
|
|
|
625
625
|
createdAt: createdAt(),
|
|
626
626
|
updatedAt: updatedAt(),
|
|
627
627
|
}, (t) => [index("plugin_connection_space").on(t.plugin, t.projectId)]);
|
|
628
|
+
// --- The two-way sync -----------------------------------------------------------
|
|
629
|
+
// A space that syncs with the organization in the cloud (docs/plans/tenant-sync.md). Triggers
|
|
630
|
+
// on the synced tables note every write in `sync_change` (see the migration); the cloud numbers
|
|
631
|
+
// its changes there, an install finds there what it has not pushed yet.
|
|
632
|
+
/** One change of an item: which space, which kind of item, which one. */
|
|
633
|
+
export const syncChange = sqliteTable("sync_change", {
|
|
634
|
+
seq: integer("seq").primaryKey({ autoIncrement: true }),
|
|
635
|
+
projectId: text("project_id").notNull(),
|
|
636
|
+
kind: text("kind").notNull(),
|
|
637
|
+
item: text("item").notNull(),
|
|
638
|
+
at: integer("at", { mode: "timestamp_ms" }).notNull().default(now),
|
|
639
|
+
}, (t) => [
|
|
640
|
+
index("sync_change_item").on(t.kind, t.item),
|
|
641
|
+
index("sync_change_project").on(t.projectId, t.seq),
|
|
642
|
+
]);
|
|
643
|
+
/**
|
|
644
|
+
* Live changes (docs/plans/live-changes.md): triggers (`db/live-triggers.ts`) number every write
|
|
645
|
+
* to an item a studio shows, pulled ones too, so an open studio hears of it. Kept 15 minutes.
|
|
646
|
+
*/
|
|
647
|
+
export const liveChange = sqliteTable("live_change", {
|
|
648
|
+
seq: integer("seq").primaryKey({ autoIncrement: true }),
|
|
649
|
+
projectId: text("project_id"),
|
|
650
|
+
kind: text("kind").notNull(),
|
|
651
|
+
/** `put` or `del`. */
|
|
652
|
+
op: text("op").notNull(),
|
|
653
|
+
item: text("item").notNull(),
|
|
654
|
+
parent: text("parent"),
|
|
655
|
+
at: integer("at", { mode: "timestamp_ms" }).notNull().default(now),
|
|
656
|
+
}, (t) => [index("live_change_at").on(t.at)]);
|
|
657
|
+
/**
|
|
658
|
+
* Who is in a wizard, page or table right now (docs/plans/live-changes.md, 8): a person in an
|
|
659
|
+
* editor, the studio assistant during its turn, an MCP client or API key for a minute after it
|
|
660
|
+
* read or wrote. A signal, never a lock. A row unseen for 45 seconds is gone.
|
|
661
|
+
*/
|
|
662
|
+
export const livePresence = sqliteTable("live_presence", {
|
|
663
|
+
kind: text("kind").notNull(),
|
|
664
|
+
item: text("item").notNull(),
|
|
665
|
+
/** The person's id, or the client's for an agent. */
|
|
666
|
+
who: text("who").notNull(),
|
|
667
|
+
/** One editor of that person: a tab. */
|
|
668
|
+
tab: text("tab").notNull().default(""),
|
|
669
|
+
/** `person`, `agent` (MCP, API), `assistant`, `run`. */
|
|
670
|
+
whoKind: text("who_kind").notNull(),
|
|
671
|
+
name: text("name").notNull(),
|
|
672
|
+
/** The app an agent acts through; for the assistant, whom it acts for. */
|
|
673
|
+
client: text("client"),
|
|
674
|
+
/** Where in the item: a step, a section, a row; and how to say it. */
|
|
675
|
+
place: text("place"),
|
|
676
|
+
placeLabel: text("place_label"),
|
|
677
|
+
/** `viewing` or `editing`. */
|
|
678
|
+
state: text("state").notNull(),
|
|
679
|
+
seenAt: integer("seen_at", { mode: "timestamp_ms" }).notNull().default(now),
|
|
680
|
+
}, (t) => [
|
|
681
|
+
primaryKey({ columns: [t.kind, t.item, t.who, t.tab] }),
|
|
682
|
+
index("live_presence_seen").on(t.seenAt),
|
|
683
|
+
]);
|
|
684
|
+
/** One row: `applying` is 1 while an install writes what it pulled, so the triggers note none of it. */
|
|
685
|
+
export const syncGuard = sqliteTable("sync_guard", {
|
|
686
|
+
id: integer("id").primaryKey(),
|
|
687
|
+
applying: integer("applying").notNull().default(0),
|
|
688
|
+
});
|
|
689
|
+
/**
|
|
690
|
+
* The version of an item both sides last agreed on, with the cloud's number of it: the common
|
|
691
|
+
* ancestor a three-way merge starts from. Kept by an install.
|
|
692
|
+
*/
|
|
693
|
+
export const syncBase = sqliteTable("sync_base", {
|
|
694
|
+
kind: text("kind").notNull(),
|
|
695
|
+
item: text("item").notNull(),
|
|
696
|
+
projectId: text("project_id").notNull(),
|
|
697
|
+
seq: integer("seq").notNull(),
|
|
698
|
+
record: text("record", { mode: "json" }).$type(),
|
|
699
|
+
}, (t) => [primaryKey({ columns: [t.kind, t.item] }), index("sync_base_project").on(t.projectId)]);
|
|
700
|
+
/** An item both sides changed, where the merge was not clean: it waits for the person. */
|
|
701
|
+
export const syncConflict = sqliteTable("sync_conflict", {
|
|
702
|
+
id: text("id").primaryKey(),
|
|
703
|
+
projectId: text("project_id").notNull(),
|
|
704
|
+
kind: text("kind").notNull(),
|
|
705
|
+
item: text("item").notNull(),
|
|
706
|
+
/** The cloud's number of its version. */
|
|
707
|
+
seq: integer("seq").notNull(),
|
|
708
|
+
base: text("base", { mode: "json" }).$type(),
|
|
709
|
+
local: text("local", { mode: "json" }).$type(),
|
|
710
|
+
remote: text("remote", { mode: "json" }).$type(),
|
|
711
|
+
createdAt: createdAt(),
|
|
712
|
+
}, (t) => [uniqueIndex("sync_conflict_item").on(t.kind, t.item)]);
|
|
713
|
+
/** A merge the sync made by itself: the notice on the item, and what undoes it. */
|
|
714
|
+
export const syncMerge = sqliteTable("sync_merge", {
|
|
715
|
+
id: text("id").primaryKey(),
|
|
716
|
+
projectId: text("project_id").notNull(),
|
|
717
|
+
kind: text("kind").notNull(),
|
|
718
|
+
item: text("item").notNull(),
|
|
719
|
+
/** Labels of the places each side changed. */
|
|
720
|
+
local: text("local", { mode: "json" }).$type().notNull(),
|
|
721
|
+
remote: text("remote", { mode: "json" }).$type().notNull(),
|
|
722
|
+
/** Both sides before the merge. */
|
|
723
|
+
before: text("before", { mode: "json" })
|
|
724
|
+
.$type()
|
|
725
|
+
.notNull(),
|
|
726
|
+
seen: integer("seen", { mode: "boolean" }).notNull().default(false),
|
|
727
|
+
createdAt: createdAt(),
|
|
728
|
+
}, (t) => [index("sync_merge_item").on(t.kind, t.item, t.createdAt)]);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Spaces in the cloud
|
|
3
|
+
description: How engenty wizards on your computer keeps its spaces the same as your organization’s spaces at engenty.ai, both ways, and what happens when both sides change the same thing.
|
|
4
|
+
version: 0.9.8
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
With an account signed in, engenty wizards on your computer keeps its spaces the same as your
|
|
8
|
+
organization’s spaces at engenty.ai. What you change on your computer arrives in the cloud, and
|
|
9
|
+
what someone changes in the cloud’s studio arrives on your computer. You can work offline: your
|
|
10
|
+
changes wait and go up once the cloud can be reached.
|
|
11
|
+
|
|
12
|
+
A computer is signed in to one organization. Everything on it syncs with that organization. To
|
|
13
|
+
work in another one, sign in again and pick it (Settings → Account, or
|
|
14
|
+
`wizards account sign-in` in the terminal).
|
|
15
|
+
|
|
16
|
+
## What syncs
|
|
17
|
+
|
|
18
|
+
| Syncs both ways | Stays where it was made |
|
|
19
|
+
|---|---|
|
|
20
|
+
| The space: name, what it says about itself, brand, facts, themes, its public page | Runs and results |
|
|
21
|
+
| Wizards: the draft, its files, translations and the chat you built it with | Chats with the studio’s assistant |
|
|
22
|
+
| Knowledge: pages, tables and their rows, categories | What wizards keep for people: their lists, files and sign-ins |
|
|
23
|
+
| The space’s files | Connected accounts and keys |
|
|
24
|
+
| Connectors | The model settings, and the headers of connected systems |
|
|
25
|
+
|
|
26
|
+
Publishing on your computer publishes the wizard here, then in the cloud, as its next version
|
|
27
|
+
there. Its address at engenty.ai stays the same. If the cloud can’t be reached, the studio
|
|
28
|
+
publishes there again by itself later.
|
|
29
|
+
|
|
30
|
+
## When it syncs
|
|
31
|
+
|
|
32
|
+
engenty wizards syncs when you save, when you open a wizard, page, table or space, and once a
|
|
33
|
+
minute in between. Nothing changes about how you save.
|
|
34
|
+
|
|
35
|
+
Settings → Spaces in the cloud lists every space with a switch, “Keep the same as in the cloud”.
|
|
36
|
+
It shows each space’s state:
|
|
37
|
+
|
|
38
|
+
| It shows | Means |
|
|
39
|
+
|---|---|
|
|
40
|
+
| Up to date | Both sides are the same. “Last arrived” says when the last change came down |
|
|
41
|
+
| 3 changes wait | They go up at the next sync. “Check now” syncs right away |
|
|
42
|
+
| Only on this computer | The switch is off, and the space stays here |
|
|
43
|
+
| Only in the cloud | The switch is off for a space of the cloud. Switch it on to have it here |
|
|
44
|
+
| The cloud runs a newer version | The sync waits until you update engenty wizards (`wizards update`) |
|
|
45
|
+
| This computer runs a newer version than the cloud | Your changes go up once the cloud is updated |
|
|
46
|
+
| The cloud can’t be reached right now | Your changes wait here |
|
|
47
|
+
|
|
48
|
+
New spaces, made here or in the cloud, sync without you switching them on.
|
|
49
|
+
|
|
50
|
+
## When both sides changed the same thing
|
|
51
|
+
|
|
52
|
+
Usually the two changes fit together. Say you changed a page’s first paragraph and someone in the
|
|
53
|
+
cloud changed its last one. The studio then merges them by itself, and the page shows “Merged with
|
|
54
|
+
changes from the cloud”, with what changed where. “Undo, keep mine” or “Undo, keep the cloud’s”
|
|
55
|
+
takes one side back.
|
|
56
|
+
|
|
57
|
+
When both sides changed the same place, for example a wizard’s title, the studio asks which
|
|
58
|
+
version stays. You see it on the wizard, page or table, in the bar above every page, and under
|
|
59
|
+
Settings → Spaces in the cloud:
|
|
60
|
+
|
|
61
|
+
| Choice | Does |
|
|
62
|
+
|---|---|
|
|
63
|
+
| Keep the cloud’s version | Your change here is replaced |
|
|
64
|
+
| Keep this computer’s version | Your change goes up and replaces the cloud’s |
|
|
65
|
+
| Choose place by place | Shows each place that differs, and you pick a side for each |
|
|
66
|
+
| Ask AI for a proposal | The AI writes a version with both changes. Nothing changes until you take it |
|
|
67
|
+
|
|
68
|
+
Until you decide, each side keeps its own version, and the published version keeps running.
|
|
69
|
+
|
|
70
|
+
## Who can change what
|
|
71
|
+
|
|
72
|
+
Your role in the organization counts on your computer too. Owners and admins change everything.
|
|
73
|
+
Members change wizards, knowledge and files, but they don’t add or delete wizards, and they don’t
|
|
74
|
+
change the space’s settings or its connectors. The cloud refuses what your role doesn’t allow, and
|
|
75
|
+
Settings → Spaces in the cloud says which changes it didn’t take.
|
|
76
|
+
|
|
77
|
+
## Switch it off
|
|
78
|
+
|
|
79
|
+
To keep a space on your computer alone, turn its switch off under Settings → Spaces in the cloud.
|
|
80
|
+
To keep everything here, sign out under Settings → Account. To turn the sync off on this computer
|
|
81
|
+
but keep the account, add this line to `~/.engenty/wizards/.features`:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
twoWaySync=off
|
|
85
|
+
```
|
|
@@ -39,10 +39,10 @@ After an update, engenty wizards brings your data up to date the next time it st
|
|
|
39
39
|
on your computer.
|
|
40
40
|
- **Steps that use the web** send what they search for, open or call.
|
|
41
41
|
- **Connected services** get what a wizard’s actions send them.
|
|
42
|
-
- **
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
- **Your spaces**, with an account signed in: their wizards, drafts included, their knowledge,
|
|
43
|
+
files and connectors sync with your organization at engenty.ai
|
|
44
|
+
([Spaces in the cloud](./cloud-sync.md)). Runs, results, connected accounts and keys stay on
|
|
45
|
+
your computer.
|
|
46
46
|
- **Templates** come from the marketplace at engenty.ai. `MARKETPLACE_URL=off` in the settings file
|
|
47
47
|
turns that off.
|
|
48
48
|
- **The update check** asks GitHub for the newest release.
|
|
@@ -111,20 +111,10 @@ Without an account, the dialog says that the wizard runs only on this computer (
|
|
|
111
111
|
computer” under “Access”). It greys out the ways others reach it and offers “Sign in” and “Create
|
|
112
112
|
account”.
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
| The published version and its files | Drafts and the chat with the assistant |
|
|
119
|
-
| The space’s name, what it says about itself, its colours, facts and logo | Runs and results on your computer |
|
|
120
|
-
| The pages and tables of Knowledge, with their categories | What the wizards keep: their lists and notes |
|
|
121
|
-
| How the link is shared: on or off, runs a day, page or chat | Connected accounts, keys, the space’s documents and its connected systems |
|
|
122
|
-
|
|
123
|
-
At engenty.ai/studio you see the space and its runs there. A small laptop icon marks the space,
|
|
124
|
-
and a note says “You edit this space in engenty wizards on your computer.” The studio there
|
|
125
|
-
doesn’t edit it. An account holds one space from one computer. On a new computer, the share
|
|
126
|
-
dialog offers “Replace that space”, which removes the old computer’s wizards and their links from
|
|
127
|
-
the cloud.
|
|
114
|
+
Your spaces, their wizards with their drafts, and their knowledge and files sync both ways with
|
|
115
|
+
your organization at engenty.ai: what you change here arrives there, and what someone changes in
|
|
116
|
+
the studio there arrives here. Runs and results, connected accounts and keys stay on the side
|
|
117
|
+
where they were made. See [Spaces in the cloud](./cloud-sync.md).
|
|
128
118
|
|
|
129
119
|
When you delete a wizard here, its copy in the cloud is deleted too. When you switch its link
|
|
130
120
|
off here, it is switched off there as well.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Working together
|
|
3
|
+
description: How the studio shows what others change while you work, merges it with what you type, and shows who else is in a wizard, page or table.
|
|
4
|
+
version: 0.10.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The studio shows changes made elsewhere as they happen. You don’t reload anything. That holds
|
|
8
|
+
whoever made the change:
|
|
9
|
+
|
|
10
|
+
- another member of your organization, or you in another window;
|
|
11
|
+
- the AI: the assistant in the editor, or an app like Claude Code over MCP;
|
|
12
|
+
- a run that adds rows to a table;
|
|
13
|
+
- the cloud, when your computer keeps its spaces the same as there
|
|
14
|
+
([Spaces in the cloud](cloud-sync)).
|
|
15
|
+
|
|
16
|
+
A row, a card or a page that changed elsewhere lights up for a moment.
|
|
17
|
+
|
|
18
|
+
## While you type
|
|
19
|
+
|
|
20
|
+
What you type is never replaced. engenty wizards saves a moment after you stop typing:
|
|
21
|
+
|
|
22
|
+
| Your editor | A change from elsewhere |
|
|
23
|
+
|---|---|
|
|
24
|
+
| Nothing typed since the last save | Shows at once. The cursor stays where it was |
|
|
25
|
+
| Something typed, not saved yet | Waits. Nothing moves while you type. The next save merges both, and the editor shows “Merged with changes from …” |
|
|
26
|
+
| You and someone else changed the same place | The editor asks: “Keep mine” or “Take the other version”. Until you choose, your text stays and isn’t saved over theirs |
|
|
27
|
+
|
|
28
|
+
In a table each cell saves on its own. The cell you type in keeps what you type, and the other
|
|
29
|
+
cells of the row change as they come.
|
|
30
|
+
|
|
31
|
+
## Who else is here
|
|
32
|
+
|
|
33
|
+
The header of a wizard, page or table shows who else has it open, with a colour each:
|
|
34
|
+
|
|
35
|
+
- a person’s initials: they look at it, or edit it if their initials have a ring;
|
|
36
|
+
- a robot for the AI: the assistant for someone, or an app over MCP. An app counts as here for a
|
|
37
|
+
minute after it read or changed the wizard.
|
|
38
|
+
|
|
39
|
+
Hold the pointer over a face to see what they do and where: a step of the wizard, a section of a
|
|
40
|
+
page, a row of a table. A row someone else edits has an edge in their colour, and a wizard card
|
|
41
|
+
shows a dot for each person in it. When you type where someone else types, the editor says
|
|
42
|
+
“Anna is editing this too”.
|
|
43
|
+
|
|
44
|
+
This is for your awareness only. Anyone can still edit, and nothing is locked.
|
|
45
|
+
|
|
46
|
+
## The AI knows too
|
|
47
|
+
|
|
48
|
+
An app over MCP learns who else is in a wizard when it reads or changes it. When a person edits
|
|
49
|
+
the same wizard, the app hears that their editor merges its change, and it tells you before
|
|
50
|
+
larger changes.
|
|
51
|
+
|
|
52
|
+
## Switch it off
|
|
53
|
+
|
|
54
|
+
To turn live changes off on your computer, add this line to `~/.engenty/wizards/.features`:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
liveChanges=off
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The studio then shows what changed when you open a page again.
|
|
@@ -20,3 +20,16 @@ export async function getBlob(hash) {
|
|
|
20
20
|
}
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
|
+
/** Whether the store has the bytes of this hash. */
|
|
24
|
+
export async function hasBlob(hash) {
|
|
25
|
+
return /^[a-f0-9]{64}$/.test(hash) && objects.has(blobKey(hash));
|
|
26
|
+
}
|
|
27
|
+
/** Keeps bytes that arrived for a hash, after checking they are what the hash says. */
|
|
28
|
+
export async function putBlobOf(hash, data) {
|
|
29
|
+
if (createHash("sha256").update(data).digest("hex") !== hash) {
|
|
30
|
+
throw new Error("blob does not match its hash");
|
|
31
|
+
}
|
|
32
|
+
if (!(await objects.has(blobKey(hash)))) {
|
|
33
|
+
await objects.put(blobKey(hash), data);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -7,6 +7,7 @@ import { adoptLegacyData } from "./db/adopt.js";
|
|
|
7
7
|
import { knownTenants, migrateAllTenants, migrateControlDb, openTenantDb, withTenant, } from "./db/client.js";
|
|
8
8
|
import { startRunner, stopRunner } from "./engine/runner.js";
|
|
9
9
|
import { basePath, env } from "./env.js";
|
|
10
|
+
import { pruneLive } from "./live/feed.js";
|
|
10
11
|
import { hookConsole } from "./log.js";
|
|
11
12
|
import { managed } from "./manage.js";
|
|
12
13
|
import { checkModelsAtStart, loadCatalog, loadLocalModels } from "./models.js";
|
|
@@ -18,6 +19,7 @@ import { clearRunning, writeRunning } from "./running.js";
|
|
|
18
19
|
import { syncMarketplace } from "./services/marketplace.js";
|
|
19
20
|
import { purgeExpiredRuns } from "./services/shares.js";
|
|
20
21
|
import { purgeUnusedStores } from "./store/index.js";
|
|
22
|
+
import { compactLog } from "./sync/log.js";
|
|
21
23
|
import { forgetRunner, registerRunner } from "./tenants/control.js";
|
|
22
24
|
import { LOCAL_TENANT } from "./tenants/tenant.js";
|
|
23
25
|
import { onRestart, RESTART_EXIT, startUpdateChecks } from "./update.js";
|
|
@@ -93,7 +95,7 @@ if (env.serves.runner) {
|
|
|
93
95
|
async function purge() {
|
|
94
96
|
await purgeSessions();
|
|
95
97
|
for (const id of await knownTenants()) {
|
|
96
|
-
await withTenant(id, () => Promise.all([purgeExpiredRuns(), purgeUnusedStores()])).catch((err) => console.error(`[retention ${id}]`, err));
|
|
98
|
+
await withTenant(id, () => Promise.all([purgeExpiredRuns(), purgeUnusedStores(), compactLog(), pruneLive()])).catch((err) => console.error(`[retention ${id}]`, err));
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
void purge().catch((err) => console.error("[retention]", err));
|
|
@@ -103,6 +105,14 @@ if (!managed) {
|
|
|
103
105
|
const { retryFailedSends } = await import("./services/cloud.js");
|
|
104
106
|
const retry = () => withTenant(LOCAL_TENANT, () => retryFailedSends("local")).catch((err) => console.error("[cloud] retry failed:", err));
|
|
105
107
|
setInterval(() => void retry(), 60_000).unref();
|
|
108
|
+
// The two-way sync of the spaces with the account's organization (sync/client.ts).
|
|
109
|
+
const { syncAll } = await import("./sync/client.js");
|
|
110
|
+
const twoWay = () => withTenant(LOCAL_TENANT, () => syncAll()).catch((err) => console.error("[sync]", err));
|
|
111
|
+
setTimeout(() => void twoWay(), 5_000).unref();
|
|
112
|
+
setInterval(() => void twoWay(), 60_000).unref();
|
|
113
|
+
// And between the rounds: what changes in the cloud, as it happens.
|
|
114
|
+
const { followCloud } = await import("./sync/client.js");
|
|
115
|
+
void withTenant(LOCAL_TENANT, () => followCloud(new AbortController().signal)).catch((err) => console.error("[sync] following the cloud:", err));
|
|
106
116
|
}
|
|
107
117
|
async function shutdown(code = 0) {
|
|
108
118
|
clearRunning(env.dataDir);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { db } from "../db/client.js";
|
|
3
|
+
/**
|
|
4
|
+
* The tenant's live feed (`live_change`, docs/plans/live-changes.md): numbered writes to the
|
|
5
|
+
* items a studio shows. These read it in the current tenant's context.
|
|
6
|
+
*/
|
|
7
|
+
/** How long a change stays readable: a reconnect within it catches up, a later one resets. */
|
|
8
|
+
export const LIVE_KEEP_MS = 15 * 60_000;
|
|
9
|
+
/** The newest number in the feed, 0 when it never had a row. */
|
|
10
|
+
export async function newestSeq() {
|
|
11
|
+
const rows = await db.all(sql `SELECT seq FROM sqlite_sequence WHERE name = 'live_change'`);
|
|
12
|
+
return rows[0]?.seq ?? 0;
|
|
13
|
+
}
|
|
14
|
+
/** The oldest number still kept, or null when the feed is empty. */
|
|
15
|
+
export async function oldestSeq() {
|
|
16
|
+
const rows = await db.all(sql `SELECT MIN(seq) AS seq FROM live_change`);
|
|
17
|
+
return rows[0]?.seq ?? null;
|
|
18
|
+
}
|
|
19
|
+
/** The changes after `since`, oldest first, at most `limit`. */
|
|
20
|
+
export async function changesAfter(since, limit) {
|
|
21
|
+
const rows = await db.all(sql `SELECT seq, project_id, kind, op, item, parent FROM live_change WHERE seq > ${since} ORDER BY seq LIMIT ${limit}`);
|
|
22
|
+
return rows.map((r) => ({
|
|
23
|
+
seq: r.seq,
|
|
24
|
+
projectId: r.project_id,
|
|
25
|
+
kind: r.kind,
|
|
26
|
+
op: r.op,
|
|
27
|
+
item: r.item,
|
|
28
|
+
parent: r.parent,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
/** Deletes changes older than what a reconnect may catch up on. */
|
|
32
|
+
export async function pruneLive(now = Date.now()) {
|
|
33
|
+
await db.run(sql `DELETE FROM live_change WHERE at < ${now - LIVE_KEEP_MS}`);
|
|
34
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { withTenant } from "../db/client.js";
|
|
2
|
+
import { expirePresence } from "../services/presence.js";
|
|
3
|
+
import { changesAfter, newestSeq, oldestSeq, pruneLive } from "./feed.js";
|
|
4
|
+
/** More changes than this in one go and the browser reloads what is open instead. */
|
|
5
|
+
export const BURST = 1000;
|
|
6
|
+
const FAST_MS = 1000;
|
|
7
|
+
const SLOW_MS = 3000;
|
|
8
|
+
/** Ticks stay fast this long after the last change. */
|
|
9
|
+
const BUSY_MS = 60_000;
|
|
10
|
+
const PRUNE_EVERY_MS = 5 * 60_000;
|
|
11
|
+
const EXPIRE_EVERY_MS = 10_000;
|
|
12
|
+
/** Views a batch carries at most, in characters of JSON; the items after it go without. */
|
|
13
|
+
export const BATCH_VIEWS_MAX = 512 * 1024;
|
|
14
|
+
/** Above this a view isn't sent: the browser fetches that item. */
|
|
15
|
+
export const VIEW_MAX = 64 * 1024;
|
|
16
|
+
const feeds = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* Starts sending the tenant's changes after `since` (null: from now on). Answers `hello`, or
|
|
19
|
+
* `reset` when the changes after `since` are no longer kept or `since` is of another database.
|
|
20
|
+
*/
|
|
21
|
+
export async function subscribe(tenantId, since, send, views) {
|
|
22
|
+
const { newest, gap } = await withTenant(tenantId, async () => {
|
|
23
|
+
const newest = await newestSeq();
|
|
24
|
+
if (since === null || since === newest) {
|
|
25
|
+
return { newest, gap: false };
|
|
26
|
+
}
|
|
27
|
+
if (since > newest) {
|
|
28
|
+
return { newest, gap: true };
|
|
29
|
+
}
|
|
30
|
+
const oldest = await oldestSeq();
|
|
31
|
+
return { newest, gap: oldest === null || oldest > since + 1 };
|
|
32
|
+
});
|
|
33
|
+
const sub = { since: since === null || gap ? newest : since, send, views };
|
|
34
|
+
send(gap ? { event: "reset", seq: newest } : { event: "hello", seq: newest });
|
|
35
|
+
let feed = feeds.get(tenantId);
|
|
36
|
+
if (!feed) {
|
|
37
|
+
feed = {
|
|
38
|
+
id: tenantId,
|
|
39
|
+
subs: new Set(),
|
|
40
|
+
timer: null,
|
|
41
|
+
ticking: false,
|
|
42
|
+
again: false,
|
|
43
|
+
changedAt: 0,
|
|
44
|
+
prunedAt: 0,
|
|
45
|
+
expiredAt: 0,
|
|
46
|
+
};
|
|
47
|
+
feeds.set(tenantId, feed);
|
|
48
|
+
}
|
|
49
|
+
feed.subs.add(sub);
|
|
50
|
+
// A catch-up is the next tick's work.
|
|
51
|
+
schedule(feed, sub.since < newest ? 0 : FAST_MS);
|
|
52
|
+
return () => {
|
|
53
|
+
const f = feeds.get(tenantId);
|
|
54
|
+
if (!f) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
f.subs.delete(sub);
|
|
58
|
+
if (!f.subs.size) {
|
|
59
|
+
if (f.timer) {
|
|
60
|
+
clearTimeout(f.timer);
|
|
61
|
+
}
|
|
62
|
+
feeds.delete(tenantId);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** A write in this process: read the tenant's feed now, if anyone listens. */
|
|
67
|
+
export function nudge(tenantId) {
|
|
68
|
+
const feed = tenantId ? feeds.get(tenantId) : undefined;
|
|
69
|
+
if (feed) {
|
|
70
|
+
schedule(feed, 0);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Something only this process knows changed, such as the two-way sync's state. */
|
|
74
|
+
export function signal(tenantId, event) {
|
|
75
|
+
const feed = tenantId ? feeds.get(tenantId) : undefined;
|
|
76
|
+
for (const sub of feed?.subs ?? []) {
|
|
77
|
+
sub.send({ event });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Streams open in this process, for limits and tests. */
|
|
81
|
+
export function openStreams(tenantId) {
|
|
82
|
+
return feeds.get(tenantId)?.subs.size ?? 0;
|
|
83
|
+
}
|
|
84
|
+
function schedule(feed, ms) {
|
|
85
|
+
if (feed.ticking) {
|
|
86
|
+
feed.again = true;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (feed.timer) {
|
|
90
|
+
clearTimeout(feed.timer);
|
|
91
|
+
}
|
|
92
|
+
feed.timer = setTimeout(() => void tick(feed), ms);
|
|
93
|
+
feed.timer.unref?.();
|
|
94
|
+
}
|
|
95
|
+
async function tick(feed) {
|
|
96
|
+
feed.timer = null;
|
|
97
|
+
if (feeds.get(feed.id) !== feed) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
feed.ticking = true;
|
|
101
|
+
feed.again = false;
|
|
102
|
+
try {
|
|
103
|
+
await withTenant(feed.id, () => read(feed));
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
console.error(`[live ${feed.id}]`, err);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
feed.ticking = false;
|
|
110
|
+
}
|
|
111
|
+
if (feeds.get(feed.id) === feed) {
|
|
112
|
+
const quiet = Date.now() - feed.changedAt > BUSY_MS;
|
|
113
|
+
schedule(feed, feed.again ? 0 : quiet ? SLOW_MS : FAST_MS);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function read(feed) {
|
|
117
|
+
const subs = [...feed.subs];
|
|
118
|
+
if (!subs.length) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const from = Math.min(...subs.map((s) => s.since));
|
|
122
|
+
const rows = await changesAfter(from, BURST + 1);
|
|
123
|
+
if (rows.length) {
|
|
124
|
+
feed.changedAt = Date.now();
|
|
125
|
+
}
|
|
126
|
+
if (rows.length > BURST) {
|
|
127
|
+
const seq = await newestSeq();
|
|
128
|
+
for (const sub of subs) {
|
|
129
|
+
sub.since = seq;
|
|
130
|
+
sub.send({ event: "reset", seq });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (rows.length) {
|
|
134
|
+
const read = new Map();
|
|
135
|
+
for (const sub of subs) {
|
|
136
|
+
const mine = rows.filter((r) => r.seq > sub.since);
|
|
137
|
+
if (!mine.length) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const seq = mine[mine.length - 1].seq;
|
|
141
|
+
sub.since = seq;
|
|
142
|
+
sub.send({ event: "changes", seq, items: await withViews(dedupe(mine), sub.views, read) });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (Date.now() - feed.prunedAt > PRUNE_EVERY_MS) {
|
|
146
|
+
feed.prunedAt = Date.now();
|
|
147
|
+
await pruneLive();
|
|
148
|
+
}
|
|
149
|
+
// Who left without saying so: their entries go, and the open studios hear of it.
|
|
150
|
+
if (Date.now() - feed.expiredAt > EXPIRE_EVERY_MS) {
|
|
151
|
+
feed.expiredAt = Date.now();
|
|
152
|
+
await expirePresence();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The views of a batch's `put` items, read once per item and kind of reader. A put whose item
|
|
157
|
+
* is gone by now goes as a `del`; a view too big, or over the batch's budget, is left out.
|
|
158
|
+
*/
|
|
159
|
+
async function withViews(items, views, read) {
|
|
160
|
+
if (!views) {
|
|
161
|
+
return items;
|
|
162
|
+
}
|
|
163
|
+
let budget = BATCH_VIEWS_MAX;
|
|
164
|
+
const out = [];
|
|
165
|
+
for (const x of items) {
|
|
166
|
+
if (x.op === "del") {
|
|
167
|
+
out.push(x);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const key = `${views.key}|${x.kind}|${x.item}`;
|
|
171
|
+
let view = read.get(key);
|
|
172
|
+
if (!view) {
|
|
173
|
+
view = views.read(x).catch(() => undefined);
|
|
174
|
+
read.set(key, view);
|
|
175
|
+
}
|
|
176
|
+
const v = await view;
|
|
177
|
+
if (v === null) {
|
|
178
|
+
out.push({ ...x, op: "del" });
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const size = v === undefined ? 0 : JSON.stringify(v).length;
|
|
182
|
+
if (v === undefined || size > VIEW_MAX || size > budget) {
|
|
183
|
+
out.push(x);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
budget -= size;
|
|
187
|
+
out.push({ ...x, view: v });
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
/** One entry per item, in the order of its last change, with its last op and number. */
|
|
192
|
+
export function dedupe(rows) {
|
|
193
|
+
const last = new Map();
|
|
194
|
+
for (const item of rows) {
|
|
195
|
+
const key = `${item.kind}|${item.item}`;
|
|
196
|
+
last.delete(key);
|
|
197
|
+
last.set(key, item);
|
|
198
|
+
}
|
|
199
|
+
return [...last.values()];
|
|
200
|
+
}
|