@dexhq/canvas 0.13.0 → 0.15.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/CHANGELOG.md +53 -0
- package/README.md +21 -18
- package/app/canvas/activity.tsx +8 -15
- package/app/canvas/anchoring.ts +3 -5
- package/app/canvas/canvas-input.ts +151 -14
- package/app/canvas/canvas-keys.ts +9 -0
- package/app/canvas/canvas-model.ts +5 -42
- package/app/canvas/canvas-panels.ts +1 -17
- package/app/canvas/canvas-scene.ts +7 -3
- package/app/canvas/canvas-ui.ts +2 -1
- package/app/canvas/canvas.css +61 -26
- package/app/canvas/change-notice.tsx +10 -1
- package/app/canvas/comment-layer.tsx +2 -1
- package/app/canvas/comments.tsx +204 -82
- package/app/canvas/element-picker.ts +200 -27
- package/app/canvas/engine/canvas-gestures.ts +72 -17
- package/app/canvas/engine/canvas-store.ts +17 -1
- package/app/canvas/engine/engine.css +6 -3
- package/app/canvas/find-bar.tsx +817 -0
- package/app/canvas/find-model.ts +135 -0
- package/app/canvas/flow-canvas.tsx +18 -2
- package/app/canvas/follow-pin.ts +26 -6
- package/app/canvas/frame-node.tsx +43 -26
- package/app/canvas/imported-reviews.tsx +12 -22
- package/app/canvas/layout.ts +27 -0
- package/app/canvas/live-page.ts +142 -19
- package/app/canvas/page-find.ts +220 -0
- package/app/canvas/page-style.ts +23 -0
- package/app/canvas/section-node.tsx +2 -0
- package/app/canvas/spec-threads.ts +24 -23
- package/app/canvas/thread-focus.tsx +14 -12
- package/app/canvas/tool-cursors.ts +16 -16
- package/app/canvas/use-activity.ts +0 -8
- package/app/canvas/use-agent-changes.tsx +34 -40
- package/app/canvas/use-canvas-clipboard.tsx +11 -14
- package/app/canvas/xray.ts +3 -12
- package/app/frame.tsx +5 -0
- package/app/i18n/locales/en/messages.po +114 -12
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +114 -12
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/{sets/lucide.tsx → glyphs.tsx} +7 -5
- package/app/icons/index.tsx +3 -3
- package/app/icons/types.ts +3 -10
- package/app/index.html +3 -3
- package/app/main.tsx +3 -0
- package/app/pages/canvas-settings.tsx +35 -0
- package/app/pages/canvas.tsx +27 -8
- package/app/pages/commands-settings.tsx +16 -2
- package/app/shell/about.tsx +5 -4
- package/app/shell/feedback-details.ts +0 -3
- package/app/shell/feedback-form.tsx +10 -21
- package/app/shell/feedback-link.tsx +2 -1
- package/app/shell/instructions-editor.tsx +1 -1
- package/app/shell/presence-style.ts +59 -0
- package/app/shell/presence.tsx +6 -3
- package/app/shell/scaled-frame.tsx +21 -9
- package/app/shell/settings-sections.ts +12 -0
- package/app/shell/sidebar.tsx +1 -1
- package/app/studio-ui.d.ts +0 -9
- package/app/types.ts +21 -205
- package/app/ui/file-drop.ts +128 -0
- package/app/ui/prompt-editor.tsx +1 -1
- package/app/ui/shadcn/input-group.tsx +2 -2
- package/dist/cli/banner.d.mts +4 -2
- package/dist/cli/banner.mjs +34 -11
- package/dist/cli/commands/app.mjs +19 -11
- package/dist/cli/commands/create.d.mts +26 -14
- package/dist/cli/commands/create.mjs +13 -7
- package/dist/cli/commands/dev.mjs +2 -3
- package/dist/cli/commands/hook.mjs +2 -1
- package/dist/cli/commands/init.d.mts +11 -6
- package/dist/cli/help.d.mts +1 -1
- package/dist/cli/help.mjs +3 -3
- package/dist/cli/main.d.mts +22 -12
- package/dist/config/index.d.mts +6 -5
- package/dist/config/project-files.d.mts +6 -3
- package/dist/config/project-files.mjs +14 -5
- package/dist/config/renamed.d.mts +0 -2
- package/dist/config/renamed.mjs +1 -3
- package/dist/config/schema.d.mts +0 -5
- package/dist/config/schema.mjs +0 -5
- package/dist/content/capture.d.mts +2 -2
- package/dist/content/capture.mjs +2 -2
- package/dist/content/content.d.mts +3 -141
- package/dist/content/content.mjs +7 -65
- package/dist/content/flow-specs.mjs +1 -1
- package/dist/content/prototype-summary.d.mts +3 -39
- package/dist/content/prototype-summary.mjs +2 -3
- package/dist/content/prototypes.mjs +1 -1
- package/dist/content/snapshot-client.mjs +1 -1
- package/dist/content/text-replace.d.mts +30 -0
- package/dist/content/text-replace.mjs +309 -0
- package/dist/content/thread-module.mjs +1 -1
- package/dist/content/threads.mjs +1 -1
- package/dist/paths.d.mts +0 -2
- package/dist/paths.mjs +1 -3
- package/dist/server/agent-env.d.mts +5 -1
- package/dist/server/agent-env.mjs +7 -2
- package/dist/server/agent-session.d.mts +14 -1
- package/dist/server/agent-session.mjs +84 -19
- package/dist/server/brief.mjs +3 -3
- package/dist/server/build-pictures.mjs +1 -1
- package/dist/server/channel.d.mts +19 -24
- package/dist/server/channel.mjs +70 -37
- package/dist/server/claimed-presence.d.mts +18 -0
- package/dist/server/claimed-presence.mjs +58 -0
- package/dist/server/close-check.mjs +2 -2
- package/dist/server/comments/actions.d.mts +153 -0
- package/dist/server/comments/actions.mjs +154 -0
- package/dist/server/comments/routes.d.mts +25 -0
- package/dist/server/comments/routes.mjs +88 -0
- package/dist/server/comments/tools.d.mts +6 -0
- package/dist/server/comments/tools.mjs +154 -0
- package/dist/server/dev-server.mjs +36 -13
- package/dist/server/file-errors.d.mts +7 -2
- package/dist/server/file-errors.mjs +31 -8
- package/dist/server/file-lock.d.mts +2 -2
- package/dist/server/file-lock.mjs +130 -36
- package/dist/server/mcp.d.mts +0 -2
- package/dist/server/mcp.mjs +7 -8
- package/dist/server/me.d.mts +1 -1
- package/dist/server/open-page.d.mts +22 -0
- package/dist/server/open-page.mjs +20 -2
- package/dist/server/outcome.d.mts +22 -0
- package/dist/server/outcome.mjs +8 -0
- package/dist/server/own-copies.mjs +2 -2
- package/dist/server/people.d.mts +1 -1
- package/dist/server/port.d.mts +12 -0
- package/dist/server/port.mjs +66 -14
- package/dist/server/presence.d.mts +4 -1
- package/dist/server/presence.mjs +2 -2
- package/dist/server/requests.d.mts +5 -1
- package/dist/server/requests.mjs +32 -47
- package/dist/server/studio-for.d.mts +5 -0
- package/dist/server/studio-for.mjs +18 -4
- package/dist/server/sync-install.d.mts +8 -12
- package/dist/server/sync-install.mjs +12 -30
- package/dist/server/thread-source.mjs +2 -2
- package/dist/server/tools/describe.d.mts +1 -1
- package/dist/server/tools/describe.mjs +1 -1
- package/dist/server/tools/feedback.d.mts +1 -1
- package/dist/server/tools/reading.mjs +13 -4
- package/dist/server/tools/show.d.mts +1 -1
- package/dist/server/tools/snapshot.d.mts +1 -1
- package/dist/server/tools/thread-list.mjs +1 -1
- package/dist/server/tools/watch.mjs +5 -3
- package/dist/server/vite.mjs +28 -31
- package/dist/server/web-app.mjs +7 -10
- package/dist/server/work-groups.mjs +1 -1
- package/dist/setup/apply.mjs +8 -14
- package/dist/setup/create.d.mts +4 -2
- package/dist/setup/create.mjs +118 -36
- package/dist/setup/design-system-checks.mjs +3 -12
- package/dist/setup/desktop-app-script.mjs +4 -3
- package/dist/setup/desktop-app-start.d.mts +8 -2
- package/dist/setup/desktop-app-start.mjs +64 -29
- package/dist/setup/desktop-app.d.mts +8 -0
- package/dist/setup/desktop-app.mjs +20 -4
- package/dist/setup/detect.d.mts +14 -7
- package/dist/setup/detect.mjs +56 -10
- package/dist/setup/doctor.mjs +2 -4
- package/dist/setup/existing-setup.d.mts +1 -3
- package/dist/setup/existing-setup.mjs +10 -11
- package/dist/setup/migrate/row-titles.mjs +1 -1
- package/dist/setup/own-app.d.mts +1 -2
- package/dist/setup/own-app.mjs +4 -5
- package/dist/setup/plan.d.mts +8 -6
- package/dist/setup/plan.mjs +64 -48
- package/dist/setup/project.d.mts +6 -17
- package/dist/setup/project.mjs +17 -61
- package/dist/setup/prompts.d.mts +5 -5
- package/dist/setup/prompts.mjs +28 -61
- package/dist/setup/questions.d.mts +12 -4
- package/dist/setup/questions.mjs +10 -25
- package/dist/setup/starters.d.mts +2 -0
- package/dist/setup/starters.mjs +26 -9
- package/dist/setup/workspace-setup.d.mts +1 -2
- package/dist/setup/workspace-setup.mjs +4 -6
- package/dist/setup/write.d.mts +15 -5
- package/dist/setup/write.mjs +35 -9
- package/dist/shared/annotations-core.mjs +1 -1
- package/dist/shared/canvas-core.mjs +1 -1
- package/dist/shared/canvas-file.d.mts +201 -0
- package/dist/shared/canvas-file.mjs +1 -0
- package/dist/shared/comments/routes.d.mts +53 -0
- package/dist/shared/comments/routes.mjs +37 -0
- package/dist/shared/feedback.d.mts +8 -0
- package/dist/shared/feedback.mjs +10 -2
- package/dist/shared/page-review.d.mts +2 -11
- package/dist/shared/page-review.mjs +4 -13
- package/dist/shared/presence-core.d.mts +11 -0
- package/dist/shared/presence-core.mjs +11 -2
- package/dist/shared/review-file.d.mts +5 -0
- package/dist/shared/review-file.mjs +23 -13
- package/dist/shared/server-page.mjs +7 -1
- package/dist/shared/signup.d.mts +2 -5
- package/dist/shared/signup.mjs +2 -35
- package/dist/shared/studio-events.d.mts +0 -6
- package/dist/shared/studio-events.mjs +1 -5
- package/dist/shared/studio-files.d.mts +12 -0
- package/dist/shared/studio-files.mjs +6 -1
- package/dist/shared/studio-routes.d.mts +16 -62
- package/dist/shared/studio-routes.mjs +1 -69
- package/dist/shared/threads-core.d.mts +2 -2
- package/dist/shared/threads-core.mjs +1 -1
- package/extension/dist/feedback.js +148 -138
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +146 -136
- package/package.json +3 -20
- package/src/cli/banner.ts +45 -11
- package/src/cli/commands/app.ts +23 -8
- package/src/cli/commands/create.ts +17 -9
- package/src/cli/commands/dev.ts +0 -3
- package/src/cli/commands/hook.ts +4 -1
- package/src/cli/help.ts +3 -3
- package/src/config/index.ts +6 -5
- package/src/config/project-files.ts +21 -11
- package/src/config/renamed.ts +0 -3
- package/src/config/schema.ts +0 -1
- package/src/content/capture.ts +6 -12
- package/src/content/content.ts +7 -244
- package/src/content/flow-specs.ts +2 -1
- package/src/content/prototype-summary.ts +4 -44
- package/src/content/review-pages.ts +2 -1
- package/src/content/snapshot-client.ts +1 -1
- package/src/content/text-replace.ts +449 -0
- package/src/paths.ts +0 -8
- package/src/server/agent-env.ts +12 -2
- package/src/server/agent-session.ts +124 -34
- package/src/server/brief.ts +8 -3
- package/src/server/channel.ts +121 -52
- package/src/server/claimed-presence.ts +93 -0
- package/src/server/comments/actions.ts +352 -0
- package/src/server/comments/routes.ts +176 -0
- package/src/server/comments/tools.ts +317 -0
- package/src/server/dev-server.ts +49 -15
- package/src/server/file-errors.ts +47 -13
- package/src/server/file-lock.ts +205 -54
- package/src/server/mcp.ts +13 -14
- package/src/server/me.ts +2 -5
- package/src/server/open-page.ts +54 -4
- package/src/server/outcome.ts +26 -0
- package/src/server/people.ts +2 -1
- package/src/server/port.ts +94 -20
- package/src/server/presence.ts +11 -3
- package/src/server/requests.ts +60 -70
- package/src/server/studio-for.ts +27 -3
- package/src/server/sync-install.ts +35 -26
- package/src/server/thread-place.ts +2 -4
- package/src/server/tools/reading.ts +16 -3
- package/src/server/tools/watch.ts +7 -7
- package/src/server/vite.ts +37 -40
- package/src/server/web-app.ts +14 -12
- package/src/setup/apply.ts +10 -16
- package/src/setup/create.ts +143 -37
- package/src/setup/design-system-checks.ts +7 -15
- package/src/setup/desktop-app-script.ts +4 -3
- package/src/setup/desktop-app-start.ts +94 -26
- package/src/setup/desktop-app.ts +24 -3
- package/src/setup/detect.ts +56 -14
- package/src/setup/doctor.ts +4 -4
- package/src/setup/existing-setup.ts +10 -12
- package/src/setup/own-app.ts +2 -5
- package/src/setup/plan.ts +93 -84
- package/src/setup/project.ts +25 -118
- package/src/setup/prompts.ts +44 -127
- package/src/setup/questions.ts +27 -29
- package/src/setup/starters.ts +35 -10
- package/src/setup/workspace-setup.ts +8 -18
- package/src/setup/write.ts +52 -9
- package/src/shared/canvas-file.ts +205 -0
- package/src/shared/comments/routes.ts +79 -0
- package/src/shared/feedback.ts +14 -4
- package/src/shared/page-review.ts +11 -16
- package/src/shared/presence-core.ts +16 -2
- package/src/shared/review-file.ts +28 -12
- package/src/shared/server-page.ts +11 -1
- package/src/shared/signup.ts +4 -28
- package/src/shared/studio-events.ts +0 -13
- package/src/shared/studio-files.ts +14 -0
- package/src/shared/studio-routes.ts +21 -64
- package/src/shared/threads-core.ts +2 -2
- package/templates/methods/review.md +2 -2
- package/templates/rules/canvas-frames.md +104 -0
- package/templates/rules/canvas.md +8 -142
- package/templates/rules/prototypes.md +1 -1
- package/templates/rules/snapshots.md +52 -0
- package/templates/starters/standalone/README.md +7 -7
- package/templates/starters/standalone/components.json +1 -1
- package/templates/starters/standalone/package.json +1 -2
- package/templates/starters/turborepo/README.md +6 -6
- package/templates/starters/turborepo/apps/web/components.json +1 -1
- package/templates/starters/turborepo/apps/web/package.json +1 -2
- package/templates/starters/turborepo/apps/web/src/app.tsx +4 -5
- package/templates/starters/turborepo/packages/ui/components.json +1 -1
- package/templates/starters/turborepo/packages/ui/package.json +1 -2
- package/templates/starters/vite/README.md +7 -6
- package/templates/starters/vite/components.json +1 -1
- package/templates/starters/vite/package.json +1 -2
- package/templates/starters/vite/src/app.tsx +3 -4
- package/templates/starters/vite/src/components/ui/accordion.tsx +71 -0
- package/templates/starters/vite/src/components/ui/attachment.tsx +1 -1
- package/templates/starters/vite/src/components/ui/badge.tsx +2 -2
- package/templates/starters/vite/src/components/ui/button.tsx +17 -12
- package/templates/starters/vite/src/components/ui/card.tsx +1 -1
- package/templates/starters/vite/src/components/ui/checkbox.tsx +28 -0
- package/templates/starters/vite/src/components/ui/dialog.tsx +5 -5
- package/templates/starters/vite/src/components/ui/dropdown-menu.tsx +17 -14
- package/templates/starters/vite/src/components/ui/field.tsx +3 -1
- package/templates/starters/vite/src/components/ui/input-group.tsx +5 -3
- package/templates/starters/vite/src/components/ui/input.tsx +1 -1
- package/templates/starters/vite/src/components/ui/label.tsx +2 -0
- package/templates/starters/vite/src/components/ui/native-select.tsx +3 -4
- package/templates/starters/vite/src/components/ui/popover.tsx +1 -1
- package/templates/starters/vite/src/components/ui/separator.tsx +2 -0
- package/templates/starters/vite/src/components/ui/spinner.tsx +3 -7
- package/templates/starters/vite/src/components/ui/switch.tsx +1 -1
- package/templates/starters/vite/src/components/ui/textarea.tsx +1 -1
- package/templates/starters/vite/src/components/ui/toggle.tsx +4 -2
- package/templates/starters/vite/src/index.css +533 -111
- package/app/icons/sets/hugeicons.tsx +0 -259
- package/app/icons/sets/phosphor.tsx +0 -251
- package/dist/server/icon-set.d.mts +0 -15
- package/dist/server/icon-set.mjs +0 -31
- package/dist/server/tools/close-reply.d.mts +0 -6
- package/dist/server/tools/close-reply.mjs +0 -138
- package/dist/server/tools/comment.d.mts +0 -6
- package/dist/server/tools/comment.mjs +0 -49
- package/dist/shared/icon-sets.d.mts +0 -9
- package/dist/shared/icon-sets.mjs +0 -21
- package/src/server/icon-set.ts +0 -56
- package/src/server/tools/close-reply.ts +0 -271
- package/src/server/tools/comment.ts +0 -96
- package/src/shared/icon-sets.ts +0 -23
- /package/app/public/{sudio-192.png → dex-192.png} +0 -0
- /package/app/public/{sudio-512.png → dex-512.png} +0 -0
- /package/app/public/{apple-touch-icon.png → dex-apple-touch-icon.png} +0 -0
- /package/app/public/{favicon-32.png → dex-icon-32.png} +0 -0
- /package/app/public/{favicon.svg → dex-icon.svg} +0 -0
- /package/app/public/{sudio-maskable-512.png → dex-maskable-512.png} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { claimOf } from "../shared/threads-core.mjs";
|
|
1
2
|
import { openPresence } from "./presence.mjs";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
//#region src/server/agent-session.ts
|
|
@@ -34,17 +35,19 @@ const presenceTargetOf = (thread) => {
|
|
|
34
35
|
* acting on `threads`. Presence is best effort: a mark that fails never
|
|
35
36
|
* fails the action.
|
|
36
37
|
*/
|
|
37
|
-
function openAgentSession(root, threads, { agent, id = newSessionId(), presence = openPresence(root) }) {
|
|
38
|
-
/**
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
function openAgentSession(root, threads, { agent, claudeSession, id = newSessionId(), presence = openPresence(root) }) {
|
|
39
|
+
/** Whom its marks are under: itself, and the Claude Code session it serves. */
|
|
40
|
+
const marksUnder = claudeSession && claudeSession !== id ? [id, claudeSession] : [id];
|
|
41
|
+
/**
|
|
42
|
+
* Clear its marks, its sub-agents' too, on one view or doc or everywhere.
|
|
43
|
+
* Presence only shows the work: a clear that fails changes nothing, and
|
|
44
|
+
* marks expire.
|
|
45
|
+
*/
|
|
46
|
+
const clearMarks = async (where) => {
|
|
47
|
+
await Promise.allSettled(marksUnder.map((within) => presence.clear({
|
|
48
|
+
...where,
|
|
49
|
+
within
|
|
50
|
+
})));
|
|
48
51
|
};
|
|
49
52
|
/** Threads this session claimed and has not yet closed or answered. */
|
|
50
53
|
const held = /* @__PURE__ */ new Set();
|
|
@@ -58,6 +61,53 @@ function openAgentSession(root, threads, { agent, id = newSessionId(), presence
|
|
|
58
61
|
};
|
|
59
62
|
/** Given to another server (mcp-handover.ts): this one lets go of nothing. */
|
|
60
63
|
let handedOver = false;
|
|
64
|
+
/** Where each thread it holds is on the canvas, once it has looked. */
|
|
65
|
+
const places = /* @__PURE__ */ new Map();
|
|
66
|
+
const placeOf = async (threadId) => {
|
|
67
|
+
if (!places.has(threadId)) {
|
|
68
|
+
const thread = await threads.find(threadId);
|
|
69
|
+
places.set(threadId, thread && presenceTargetOf(thread));
|
|
70
|
+
}
|
|
71
|
+
return places.get(threadId);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Let go of the threads it holds that a person closed or answered since
|
|
75
|
+
* it claimed them, which are no longer its own. One claimed meanwhile
|
|
76
|
+
* stays held.
|
|
77
|
+
*/
|
|
78
|
+
const letGoOfClosed = async () => {
|
|
79
|
+
const ids = [...held];
|
|
80
|
+
if (ids.length === 0) return;
|
|
81
|
+
const own = new Set((await threads.list({ status: "acknowledged" })).filter((thread) => claimOf(thread)?.session === id).map((thread) => thread.id));
|
|
82
|
+
const closed = ids.filter((each) => !own.has(each));
|
|
83
|
+
if (closed.length > 0) holdingChange(() => {
|
|
84
|
+
for (const each of closed) {
|
|
85
|
+
held.delete(each);
|
|
86
|
+
places.delete(each);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
/** Whether it holds a thread on `where`, as far as it knows. */
|
|
91
|
+
const holdsOn = async (where) => (await Promise.all([...held].map(placeOf))).some((on) => on?.slug === where.slug && on.target === where.target);
|
|
92
|
+
/**
|
|
93
|
+
* Its work on `thread` (or on nothing, waiting) is over: the thread's view
|
|
94
|
+
* shows nobody at work for it, unless it holds another there, and once
|
|
95
|
+
* it holds nothing, nothing it marked does (the file's shared code, other
|
|
96
|
+
* views it changed on the way). What it holds is looked at again first
|
|
97
|
+
* with `recheck`, or when another it holds would keep the view's marks,
|
|
98
|
+
* as a person may have closed it meanwhile. Handed over, its marks are
|
|
99
|
+
* the next server's.
|
|
100
|
+
*/
|
|
101
|
+
const workEnded = async (thread, recheck) => {
|
|
102
|
+
if (handedOver) return;
|
|
103
|
+
const where = thread && presenceTargetOf(thread);
|
|
104
|
+
if (recheck || where && await holdsOn(where)) await letGoOfClosed().catch(() => void 0);
|
|
105
|
+
if (held.size === 0) {
|
|
106
|
+
await clearMarks();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (where && !await holdsOn(where)) await clearMarks(where);
|
|
110
|
+
};
|
|
61
111
|
/**
|
|
62
112
|
* An action on a thread, signed by this session: the thread after it, the
|
|
63
113
|
* problems that stopped it, or undefined when there is no such thread.
|
|
@@ -68,12 +118,17 @@ function openAgentSession(root, threads, { agent, id = newSessionId(), presence
|
|
|
68
118
|
author: agent(),
|
|
69
119
|
session: id
|
|
70
120
|
});
|
|
71
|
-
if (answer?.thread
|
|
72
|
-
|
|
121
|
+
if (action.action === "release" || Boolean(answer?.thread && LETS_GO.has(action.action))) {
|
|
122
|
+
const finished = held.has(threadId);
|
|
123
|
+
holdingChange(() => held.delete(threadId));
|
|
124
|
+
places.delete(threadId);
|
|
125
|
+
await workEnded(answer?.thread, finished).catch(() => void 0);
|
|
126
|
+
}
|
|
73
127
|
return answer;
|
|
74
128
|
};
|
|
75
129
|
return {
|
|
76
130
|
id,
|
|
131
|
+
marksUnder,
|
|
77
132
|
act,
|
|
78
133
|
/**
|
|
79
134
|
* Claim a thread for this session: it is acknowledged (👀), and the
|
|
@@ -82,7 +137,10 @@ function openAgentSession(root, threads, { agent, id = newSessionId(), presence
|
|
|
82
137
|
*/
|
|
83
138
|
claim: async (threadId) => {
|
|
84
139
|
const answer = await act(threadId, { action: "acknowledge" });
|
|
85
|
-
if (answer?.thread)
|
|
140
|
+
if (answer?.thread) {
|
|
141
|
+
places.set(threadId, presenceTargetOf(answer.thread));
|
|
142
|
+
holdingChange(() => held.add(threadId));
|
|
143
|
+
}
|
|
86
144
|
return answer;
|
|
87
145
|
},
|
|
88
146
|
/**
|
|
@@ -96,6 +154,13 @@ function openAgentSession(root, threads, { agent, id = newSessionId(), presence
|
|
|
96
154
|
},
|
|
97
155
|
/** The threads the session holds now, for the server after this one. */
|
|
98
156
|
holding: () => [...held],
|
|
157
|
+
/**
|
|
158
|
+
* The agent waits for work (`watch`): holding none, it is at work
|
|
159
|
+
* nowhere, as when its turn ends, so nothing it marked shows. Holding
|
|
160
|
+
* some, its marks stay with them. A comment a person closed or answered
|
|
161
|
+
* while it held it is no longer its own, and counts for none.
|
|
162
|
+
*/
|
|
163
|
+
waits: () => workEnded(void 0, true).catch(() => void 0),
|
|
99
164
|
/** Hear how many threads the session holds, each time that changes. */
|
|
100
165
|
onHoldingChange: (listener) => {
|
|
101
166
|
holdingListeners.add(listener);
|
|
@@ -108,7 +173,10 @@ function openAgentSession(root, threads, { agent, id = newSessionId(), presence
|
|
|
108
173
|
handOver: (given) => {
|
|
109
174
|
handedOver = true;
|
|
110
175
|
holdingChange(() => {
|
|
111
|
-
for (const threadId of given)
|
|
176
|
+
for (const threadId of given) {
|
|
177
|
+
held.delete(threadId);
|
|
178
|
+
places.delete(threadId);
|
|
179
|
+
}
|
|
112
180
|
});
|
|
113
181
|
},
|
|
114
182
|
/**
|
|
@@ -120,10 +188,7 @@ function openAgentSession(root, threads, { agent, id = newSessionId(), presence
|
|
|
120
188
|
const unfinished = [...held];
|
|
121
189
|
holdingChange(() => held.clear());
|
|
122
190
|
await Promise.allSettled(unfinished.map((threadId) => act(threadId, { action: "release" })));
|
|
123
|
-
if (handedOver)
|
|
124
|
-
try {
|
|
125
|
-
await presence.clear({ session: id });
|
|
126
|
-
} catch {}
|
|
191
|
+
if (!handedOver) await clearMarks();
|
|
127
192
|
}
|
|
128
193
|
};
|
|
129
194
|
}
|
package/dist/server/brief.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { shownFrom } from "../paths.mjs";
|
|
1
|
+
import { TEMPLATES_DIR, shownFrom } from "../paths.mjs";
|
|
2
2
|
import { youOf } from "../shared/studio-routes.mjs";
|
|
3
3
|
import { fileLabel } from "../shared/prototypes-core.mjs";
|
|
4
4
|
import { prototypePaths } from "../content/prototypes.mjs";
|
|
@@ -154,9 +154,9 @@ async function guidesSection(guides, show) {
|
|
|
154
154
|
const always = ALWAYS_ON.includes(guide.path);
|
|
155
155
|
if (always && body.trim().length <= MAX_RULE) return "";
|
|
156
156
|
const when = always ? "Whatever the work: read it first" : frontMatterValue(yaml, WHEN_RE);
|
|
157
|
-
return `\`${show(guide.file)}
|
|
157
|
+
return `${guide.own ? `\`${show(guide.file)}\` (the team's own)` : `\`${guide.path}\``}${when ? `: ${words(when)}` : ""}`;
|
|
158
158
|
}));
|
|
159
|
-
return ["## Dex's rules and methods", `Read one when the work is what it says.\n\n${listed(entries.filter(Boolean), (more) => `and ${more} in those folders`, MAX_GUIDES)}`];
|
|
159
|
+
return ["## Dex's rules and methods", `Read one when the work is what it says. Dex's are in \`${show(TEMPLATES_DIR)}/\`; the team's own are where they say.\n\n${listed(entries.filter(Boolean), (more) => `and ${more} in those folders`, MAX_GUIDES)}`];
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
162
|
* The few lines an agent is told when it first hears from Dex, whether or
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { prototypePage } from "../shared/prototypes-core.mjs";
|
|
2
|
-
import { listPrototypes } from "../content/prototypes.mjs";
|
|
3
2
|
import { canvasFrames, kinded, viewFramePage } from "../shared/canvas-core.mjs";
|
|
3
|
+
import { listPrototypes } from "../content/prototypes.mjs";
|
|
4
4
|
import { contentType } from "./content-type.mjs";
|
|
5
5
|
import { readCanvas } from "../content/content.mjs";
|
|
6
6
|
import { INSTALL_BROWSER, browserInstalled, closeScreenshotBrowser, pictureOfFrame } from "../content/screenshot.mjs";
|
|
@@ -94,22 +94,8 @@ export declare function openReceipt({ graceMs, heard, word: first }?: {
|
|
|
94
94
|
heard?: boolean;
|
|
95
95
|
word?: string;
|
|
96
96
|
}): ChannelReceipt;
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
at: number;
|
|
100
|
-
/** The agent session's id, which signs its claims; missing from older ones. */
|
|
101
|
-
session?: string;
|
|
102
|
-
/** The Dex version the session runs; missing from older ones. */
|
|
103
|
-
version?: string;
|
|
104
|
-
}
|
|
105
|
-
/** What hears of a session whose heartbeat stopped without its saying so. */
|
|
106
|
-
type OnGone = (beat: Heartbeat) => Promise<void>;
|
|
107
|
-
/**
|
|
108
|
-
* Let go of the threads a session that is gone still holds, so they wait
|
|
109
|
-
* for an agent again instead of showing its 👀 for good: a session that
|
|
110
|
-
* crashed or was killed never let go of them itself (agent-session.ts).
|
|
111
|
-
*/
|
|
112
|
-
export declare const releaseGone: (threads: Pick<ThreadModule, "act" | "list">) => OnGone;
|
|
97
|
+
/** What lets go of a gone session's threads: the studio's thread module. */
|
|
98
|
+
type SessionThreads = Pick<ThreadModule, "act" | "list">;
|
|
113
99
|
/**
|
|
114
100
|
* Let go of the threads held by sessions that are no longer connected, so a
|
|
115
101
|
* list shows them waiting and an agent can take them: a session killed
|
|
@@ -120,7 +106,7 @@ export declare const releaseGone: (threads: Pick<ThreadModule, "act" | "list">)
|
|
|
120
106
|
* connected session's heartbeat does not say which it is (an older Dex),
|
|
121
107
|
* or for a claim that names no session.
|
|
122
108
|
*/
|
|
123
|
-
export declare function releaseAbandoned(root: string, threads:
|
|
109
|
+
export declare function releaseAbandoned(root: string, threads: SessionThreads, own: string, { now, listeningMs }?: {
|
|
124
110
|
listeningMs?: number;
|
|
125
111
|
now?: number;
|
|
126
112
|
}): Promise<void>;
|
|
@@ -135,13 +121,20 @@ export declare function setWatching(root: string, on: boolean): Promise<void>;
|
|
|
135
121
|
* The agents connected to the studio over MCP, from their heartbeats: each
|
|
136
122
|
* one's name and whether it is a channel (feedback reaches it by itself).
|
|
137
123
|
* Heartbeats left by sessions that ended without saying so are cleared once
|
|
138
|
-
* they are `listeningMs` old at `now`,
|
|
124
|
+
* they are `listeningMs` old at `now`, each session's work ended first
|
|
125
|
+
* (endGone), its threads let go given `threads`.
|
|
139
126
|
*/
|
|
140
|
-
export declare function connectedAgents(root: string, { now, listeningMs,
|
|
127
|
+
export declare function connectedAgents(root: string, { now, listeningMs, threads }?: {
|
|
141
128
|
listeningMs?: number;
|
|
142
129
|
now?: number;
|
|
143
|
-
|
|
130
|
+
threads?: SessionThreads;
|
|
144
131
|
}): Promise<ConnectedAgent[]>;
|
|
132
|
+
/**
|
|
133
|
+
* The agent sessions running on this machine now, by their heartbeats: not a
|
|
134
|
+
* teammate's, whose claims come from the workspace. Reads only; clearing old
|
|
135
|
+
* heartbeats is connectedAgents's.
|
|
136
|
+
*/
|
|
137
|
+
export declare function localSessions(root: string, now?: number): Promise<Set<string>>;
|
|
145
138
|
/** Why a session was left running: it isn't one Stop is for. */
|
|
146
139
|
export declare class NotAnOldSession extends Error {}
|
|
147
140
|
/**
|
|
@@ -152,18 +145,18 @@ export declare class NotAnOldSession extends Error {}
|
|
|
152
145
|
* outlives its server by up to `LISTENING_MS`, and its process may since be
|
|
153
146
|
* another's, so what the process runs is checked before it is stopped.
|
|
154
147
|
*/
|
|
155
|
-
export declare function stopAgentServer(root: string, pid: number): Promise<void>;
|
|
148
|
+
export declare function stopAgentServer(root: string, pid: number, threads?: SessionThreads): Promise<void>;
|
|
156
149
|
/**
|
|
157
150
|
* The connected agents, for the studio's open pages. While any page listens,
|
|
158
151
|
* one check of the heartbeats runs each tick, and every page hears the list
|
|
159
152
|
* when it changes: an agent connects, or its heartbeat stops and passes the
|
|
160
153
|
* listening window. A page hears the list as it is when it starts listening.
|
|
161
154
|
* Nothing is checked while no page listens. Given `threads`, the threads a
|
|
162
|
-
* gone session held are let go (
|
|
155
|
+
* gone session held are let go (endGone). `now` and `tick` are for tests.
|
|
163
156
|
*/
|
|
164
157
|
export declare function trackAgents(root: string, { now, tick, threads }?: {
|
|
165
158
|
now?: () => number;
|
|
166
|
-
threads?:
|
|
159
|
+
threads?: SessionThreads;
|
|
167
160
|
tick?: Tick;
|
|
168
161
|
}): {
|
|
169
162
|
/**
|
|
@@ -192,8 +185,10 @@ export declare function sessionReport({ agent, channel, holding, now, receipt }:
|
|
|
192
185
|
* it ends, before a signal ends the process. Returns how to stop, and how
|
|
193
186
|
* to beat now, for a change the studio should see before the next beat.
|
|
194
187
|
*/
|
|
195
|
-
export declare function startHeartbeat(root: string, describe: () => ConnectedAgent, { beatMs, onEnd, session, write }?: {
|
|
188
|
+
export declare function startHeartbeat(root: string, describe: () => ConnectedAgent, { beatMs, claudeSession, onEnd, session, write }?: {
|
|
196
189
|
beatMs?: number;
|
|
190
|
+
/** The Claude Code session it serves, when it does. */
|
|
191
|
+
claudeSession?: string;
|
|
197
192
|
onEnd?: () => Promise<void>;
|
|
198
193
|
session?: string;
|
|
199
194
|
/** How a beat is written (for tests): whole, or not at all. */
|
package/dist/server/channel.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { isOlder, readTemplate, runningVersion, shownFrom } from "../paths.mjs";
|
|
2
2
|
import { fileLabel } from "../shared/prototypes-core.mjs";
|
|
3
|
-
import { prepareState, studioState } from "./state.mjs";
|
|
4
3
|
import { claimOf, mentionsAgent, needsAgent } from "../shared/threads-core.mjs";
|
|
4
|
+
import { prepareState, studioState } from "./state.mjs";
|
|
5
|
+
import { openPresence } from "./presence.mjs";
|
|
5
6
|
import { readCloudConfig } from "./cloud.mjs";
|
|
7
|
+
import { describeAt, placeThreads } from "./thread-source.mjs";
|
|
6
8
|
import { groupWork, splitLine } from "./work-groups.mjs";
|
|
7
9
|
import { yoursGroups } from "./own-copies.mjs";
|
|
10
|
+
import { claimComment } from "./comments/actions.mjs";
|
|
8
11
|
import { RESPONSE_BUDGETS, firstOf } from "./response-budget.mjs";
|
|
9
12
|
import { FOR_WORK, SHORT, shaped } from "./thread-forms.mjs";
|
|
10
|
-
import { describeAt, placeThreads } from "./thread-source.mjs";
|
|
11
13
|
import { join } from "node:path";
|
|
12
14
|
import { execFile } from "node:child_process";
|
|
13
15
|
import { randomBytes } from "node:crypto";
|
|
@@ -112,19 +114,27 @@ function openReceipt({ graceMs = WATCH_GRACE_MS, heard = false, word: first = ra
|
|
|
112
114
|
unanswered: () => hears ? [] : [...pushed]
|
|
113
115
|
};
|
|
114
116
|
}
|
|
117
|
+
/** The ids a heartbeat's session works under: its own, and its Claude session's. */
|
|
118
|
+
const idsOf = ({ claudeSession, session }) => [session, claudeSession].filter((each) => each !== void 0);
|
|
115
119
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
120
|
+
* End the work of a session whose heartbeat stopped without its saying so,
|
|
121
|
+
* as a session that crashed or was killed never did (agent-session.ts):
|
|
122
|
+
* clear its marks and its Claude session's, so the canvas shows it at work
|
|
123
|
+
* nowhere, and, given `threads`, let go of the threads it still holds, so
|
|
124
|
+
* they wait for an agent again instead of showing its 👀 for good. Ids
|
|
125
|
+
* still `beating` are left alone: a session moved to another server
|
|
126
|
+
* (mcp-handover.ts) beats there under the same ids.
|
|
119
127
|
*/
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await
|
|
128
|
+
const endGone = async (root, beat, beating, threads) => {
|
|
129
|
+
const { agent, session } = beat;
|
|
130
|
+
if (!session || beating.has(session)) return;
|
|
131
|
+
const releases = threads ? (await threads.list({ status: "acknowledged" })).filter((thread) => claimOf(thread)?.session === session).map((thread) => threads.act(thread.id, {
|
|
124
132
|
action: "release",
|
|
125
133
|
author: agent,
|
|
126
134
|
session
|
|
127
|
-
}))
|
|
135
|
+
})) : [];
|
|
136
|
+
const presence = openPresence(root);
|
|
137
|
+
await Promise.allSettled([...releases, ...idsOf(beat).filter((each) => !beating.has(each)).map((within) => presence.clear({ within }))]);
|
|
128
138
|
};
|
|
129
139
|
/**
|
|
130
140
|
* Let go of the threads held by sessions that are no longer connected, so a
|
|
@@ -182,9 +192,10 @@ async function setWatching(root, on) {
|
|
|
182
192
|
* The agents connected to the studio over MCP, from their heartbeats: each
|
|
183
193
|
* one's name and whether it is a channel (feedback reaches it by itself).
|
|
184
194
|
* Heartbeats left by sessions that ended without saying so are cleared once
|
|
185
|
-
* they are `listeningMs` old at `now`,
|
|
195
|
+
* they are `listeningMs` old at `now`, each session's work ended first
|
|
196
|
+
* (endGone), its threads let go given `threads`.
|
|
186
197
|
*/
|
|
187
|
-
async function connectedAgents(root, { now = Date.now(), listeningMs = LISTENING_MS,
|
|
198
|
+
async function connectedAgents(root, { now = Date.now(), listeningMs = LISTENING_MS, threads } = {}) {
|
|
188
199
|
const dir = studioState(root).agents;
|
|
189
200
|
let names = [];
|
|
190
201
|
try {
|
|
@@ -192,28 +203,50 @@ async function connectedAgents(root, { now = Date.now(), listeningMs = LISTENING
|
|
|
192
203
|
} catch {
|
|
193
204
|
return [];
|
|
194
205
|
}
|
|
195
|
-
const
|
|
206
|
+
const beats = [];
|
|
196
207
|
for (const name of names) {
|
|
197
208
|
const file = join(dir, name);
|
|
198
209
|
try {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
...pidOf(name),
|
|
204
|
-
...beat.unproven && !beat.channel ? { unproven: true } : {},
|
|
205
|
-
...beat.watching ? { watching: true } : {},
|
|
206
|
-
...beat.holding ? { holding: beat.holding } : {},
|
|
207
|
-
...outdatedOf(beat.version)
|
|
210
|
+
beats.push({
|
|
211
|
+
beat: JSON.parse(await readFile(file, "utf8")),
|
|
212
|
+
file,
|
|
213
|
+
name
|
|
208
214
|
});
|
|
209
|
-
else {
|
|
210
|
-
await onGone?.(beat).catch(() => void 0);
|
|
211
|
-
await rm(file, { force: true });
|
|
212
|
-
}
|
|
213
215
|
} catch {}
|
|
214
216
|
}
|
|
217
|
+
const isFresh = (beat) => now - beat.at < listeningMs;
|
|
218
|
+
const beating = new Set(beats.flatMap(({ beat }) => isFresh(beat) ? idsOf(beat) : []));
|
|
219
|
+
const agents = [];
|
|
220
|
+
for (const { beat, file, name } of beats) if (isFresh(beat)) agents.push({
|
|
221
|
+
agent: beat.agent,
|
|
222
|
+
channel: Boolean(beat.channel),
|
|
223
|
+
...pidOf(name),
|
|
224
|
+
...beat.unproven && !beat.channel ? { unproven: true } : {},
|
|
225
|
+
...beat.watching ? { watching: true } : {},
|
|
226
|
+
...beat.holding ? { holding: beat.holding } : {},
|
|
227
|
+
...outdatedOf(beat.version)
|
|
228
|
+
});
|
|
229
|
+
else {
|
|
230
|
+
await endGone(root, beat, beating, threads).catch(() => void 0);
|
|
231
|
+
await rm(file, { force: true });
|
|
232
|
+
}
|
|
215
233
|
return agents;
|
|
216
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* The agent sessions running on this machine now, by their heartbeats: not a
|
|
237
|
+
* teammate's, whose claims come from the workspace. Reads only; clearing old
|
|
238
|
+
* heartbeats is connectedAgents's.
|
|
239
|
+
*/
|
|
240
|
+
async function localSessions(root, now = Date.now()) {
|
|
241
|
+
const dir = studioState(root).agents;
|
|
242
|
+
const sessions = /* @__PURE__ */ new Set();
|
|
243
|
+
const names = await readdir(dir).catch(() => []);
|
|
244
|
+
for (const name of names.filter(isHeartbeat)) try {
|
|
245
|
+
const beat = JSON.parse(await readFile(join(dir, name), "utf8"));
|
|
246
|
+
if (beat.session && now - beat.at < 3e4) sessions.add(beat.session);
|
|
247
|
+
} catch {}
|
|
248
|
+
return sessions;
|
|
249
|
+
}
|
|
217
250
|
/** A heartbeat file's process, as it is named: "62653.json". */
|
|
218
251
|
const pidOf = (name) => {
|
|
219
252
|
const digits = PID_FILE_RE.exec(name)?.[1];
|
|
@@ -256,8 +289,8 @@ const commandOf = (pid) => new Promise((done) => {
|
|
|
256
289
|
* outlives its server by up to `LISTENING_MS`, and its process may since be
|
|
257
290
|
* another's, so what the process runs is checked before it is stopped.
|
|
258
291
|
*/
|
|
259
|
-
async function stopAgentServer(root, pid) {
|
|
260
|
-
const agent = (await connectedAgents(root)).find((each) => each.pid === pid && each.outdated?.restartOnce);
|
|
292
|
+
async function stopAgentServer(root, pid, threads) {
|
|
293
|
+
const agent = (await connectedAgents(root, { threads })).find((each) => each.pid === pid && each.outdated?.restartOnce);
|
|
261
294
|
if (!agent) throw new NotAnOldSession(`Process ${pid} isn't an agent on a Dex from before 0.10, so it is left running.`);
|
|
262
295
|
if (process.platform === "win32") throw new NotAnOldSession(`Dex can't check what process ${pid} runs on Windows, so it is left running. Restart ${agent.agent} instead.`);
|
|
263
296
|
const heartbeat = join(studioState(root).agents, `${pid}.json`);
|
|
@@ -285,10 +318,9 @@ const everyTick = (check) => {
|
|
|
285
318
|
* when it changes: an agent connects, or its heartbeat stops and passes the
|
|
286
319
|
* listening window. A page hears the list as it is when it starts listening.
|
|
287
320
|
* Nothing is checked while no page listens. Given `threads`, the threads a
|
|
288
|
-
* gone session held are let go (
|
|
321
|
+
* gone session held are let go (endGone). `now` and `tick` are for tests.
|
|
289
322
|
*/
|
|
290
323
|
function trackAgents(root, { now = Date.now, tick = everyTick, threads } = {}) {
|
|
291
|
-
const onGone = threads ? releaseGone(threads) : void 0;
|
|
292
324
|
const pages = /* @__PURE__ */ new Set();
|
|
293
325
|
let agents;
|
|
294
326
|
let checking;
|
|
@@ -296,7 +328,7 @@ function trackAgents(root, { now = Date.now, tick = everyTick, threads } = {}) {
|
|
|
296
328
|
const check = () => {
|
|
297
329
|
checking ??= connectedAgents(root, {
|
|
298
330
|
now: now(),
|
|
299
|
-
|
|
331
|
+
threads
|
|
300
332
|
}).then((found) => {
|
|
301
333
|
if (JSON.stringify(found) !== JSON.stringify(agents)) {
|
|
302
334
|
agents = found;
|
|
@@ -350,7 +382,7 @@ function sessionReport({ agent, channel, holding, now = Date.now(), receipt }) {
|
|
|
350
382
|
* it ends, before a signal ends the process. Returns how to stop, and how
|
|
351
383
|
* to beat now, for a change the studio should see before the next beat.
|
|
352
384
|
*/
|
|
353
|
-
function startHeartbeat(root, describe, { beatMs = BEAT_MS, onEnd, session, write = writeWhole } = {}) {
|
|
385
|
+
function startHeartbeat(root, describe, { beatMs = BEAT_MS, claudeSession, onEnd, session, write = writeWhole } = {}) {
|
|
354
386
|
const state = studioState(root);
|
|
355
387
|
const file = state.agent(process.pid);
|
|
356
388
|
let stopped = false;
|
|
@@ -363,6 +395,7 @@ function startHeartbeat(root, describe, { beatMs = BEAT_MS, onEnd, session, writ
|
|
|
363
395
|
...describe(),
|
|
364
396
|
at: Date.now(),
|
|
365
397
|
...session ? { session } : {},
|
|
398
|
+
...claudeSession ? { claudeSession } : {},
|
|
366
399
|
version: runningVersion
|
|
367
400
|
}));
|
|
368
401
|
};
|
|
@@ -598,15 +631,15 @@ async function startChannel(server, root, threads, session, { from = process.cwd
|
|
|
598
631
|
for (const thread of [...held.values()]) {
|
|
599
632
|
let answer;
|
|
600
633
|
try {
|
|
601
|
-
answer = await session
|
|
634
|
+
answer = await claimComment({ session }, thread.id);
|
|
602
635
|
} catch {
|
|
603
636
|
continue;
|
|
604
637
|
}
|
|
605
638
|
held.delete(thread.id);
|
|
606
639
|
sent.add(stamp(thread));
|
|
607
|
-
if (answer
|
|
608
|
-
sent.add(stamp(answer.
|
|
609
|
-
claimed.push(answer.
|
|
640
|
+
if (answer.value) {
|
|
641
|
+
sent.add(stamp(answer.value));
|
|
642
|
+
claimed.push(answer.value);
|
|
610
643
|
}
|
|
611
644
|
}
|
|
612
645
|
if (claimed.length === 0) return;
|
|
@@ -651,4 +684,4 @@ async function startChannel(server, root, threads, session, { from = process.cwd
|
|
|
651
684
|
return stop;
|
|
652
685
|
}
|
|
653
686
|
//#endregion
|
|
654
|
-
export { CHANNEL_ENV, CHANNEL_INSTRUCTIONS, CHANNEL_SERVER, FEEDBACK_WORKFLOW, GATHER_MS, LISTENING_MS, NotAnOldSession, OLD_CHANNEL_SERVERS, WATCH_GRACE_MS, channelEvent, connectedAgents, isWatching, openReceipt, receiptEvent, releaseAbandoned,
|
|
687
|
+
export { CHANNEL_ENV, CHANNEL_INSTRUCTIONS, CHANNEL_SERVER, FEEDBACK_WORKFLOW, GATHER_MS, LISTENING_MS, NotAnOldSession, OLD_CHANNEL_SERVERS, WATCH_GRACE_MS, channelEvent, connectedAgents, isWatching, localSessions, openReceipt, receiptEvent, releaseAbandoned, sessionReport, setWatching, startChannel, startHeartbeat, stopAgentServer, trackAgents };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ThreadModule } from "../content/thread-module.mjs";
|
|
2
|
+
import { PresenceMark, PresenceMatch } from "./presence.mjs";
|
|
3
|
+
//#region src/server/claimed-presence.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mark the agent sessions with a claimed thread on the view or doc `file`
|
|
6
|
+
* belongs to as working on it. `file` is absolute; `content` is the studio's
|
|
7
|
+
* content folder. `sessions` are the agent sessions running on this machine:
|
|
8
|
+
* a teammate's claim, synced from the workspace, is never marked here.
|
|
9
|
+
*/
|
|
10
|
+
export declare function claimedPresence({ clear, content, mark, sessions, threads, now }: {
|
|
11
|
+
clear: (match: PresenceMatch) => Promise<void>;
|
|
12
|
+
content: string;
|
|
13
|
+
mark: (entry: PresenceMark) => Promise<void>;
|
|
14
|
+
sessions: () => Promise<Set<string>>;
|
|
15
|
+
threads: Pick<ThreadModule, "list">;
|
|
16
|
+
now?: () => number;
|
|
17
|
+
}): (file: string) => Promise<void>;
|
|
18
|
+
//#endregion
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { claimOf } from "../shared/threads-core.mjs";
|
|
2
|
+
import { targetForPath } from "../shared/live-presence.mjs";
|
|
3
|
+
import { presenceTargetOf } from "./agent-session.mjs";
|
|
4
|
+
import { relative } from "node:path";
|
|
5
|
+
//#region src/server/claimed-presence.ts
|
|
6
|
+
/** How often one claim's session is marked again while it edits. */
|
|
7
|
+
const REMARK_MS = 1e4;
|
|
8
|
+
/**
|
|
9
|
+
* Mark the agent sessions with a claimed thread on the view or doc `file`
|
|
10
|
+
* belongs to as working on it. `file` is absolute; `content` is the studio's
|
|
11
|
+
* content folder. `sessions` are the agent sessions running on this machine:
|
|
12
|
+
* a teammate's claim, synced from the workspace, is never marked here.
|
|
13
|
+
*/
|
|
14
|
+
function claimedPresence({ clear, content, mark, sessions, threads, now = Date.now }) {
|
|
15
|
+
const marked = /* @__PURE__ */ new Map();
|
|
16
|
+
/** The claimed threads on the view or doc edited. */
|
|
17
|
+
const claimsOn = async (edited) => (await threads.list({
|
|
18
|
+
prototype: edited.slug,
|
|
19
|
+
status: "acknowledged"
|
|
20
|
+
})).filter((thread) => presenceTargetOf(thread)?.target === edited.target);
|
|
21
|
+
return async (file) => {
|
|
22
|
+
const edited = targetForPath(relative(content, file).replaceAll("\\", "/"));
|
|
23
|
+
if (!edited || edited.target === "prototype") return;
|
|
24
|
+
const claimed = await claimsOn(edited);
|
|
25
|
+
const time = now();
|
|
26
|
+
const marks = [];
|
|
27
|
+
let local;
|
|
28
|
+
for (const thread of claimed) {
|
|
29
|
+
const claim = claimOf(thread);
|
|
30
|
+
const session = claim?.session;
|
|
31
|
+
if (!(claim && session)) continue;
|
|
32
|
+
const key = [
|
|
33
|
+
session,
|
|
34
|
+
thread.id,
|
|
35
|
+
edited.slug,
|
|
36
|
+
edited.target
|
|
37
|
+
].join("");
|
|
38
|
+
if (time - (marked.get(key) ?? Number.NEGATIVE_INFINITY) < REMARK_MS) continue;
|
|
39
|
+
local ??= await sessions();
|
|
40
|
+
if (!local.has(session)) continue;
|
|
41
|
+
marked.set(key, time);
|
|
42
|
+
marks.push({
|
|
43
|
+
...edited,
|
|
44
|
+
agent: claim.by,
|
|
45
|
+
session
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (marks.length === 0) return;
|
|
49
|
+
await Promise.all(marks.map(mark));
|
|
50
|
+
const holding = new Set((await claimsOn(edited)).map((thread) => claimOf(thread)?.session));
|
|
51
|
+
await Promise.all(marks.filter(({ session }) => !holding.has(session)).map(({ session }) => clear({
|
|
52
|
+
...edited,
|
|
53
|
+
session
|
|
54
|
+
})));
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { claimedPresence };
|
|
@@ -2,9 +2,9 @@ import { shownFrom } from "../paths.mjs";
|
|
|
2
2
|
import { prototypeFiles } from "../shared/prototypes-core.mjs";
|
|
3
3
|
import { claimOf } from "../shared/threads-core.mjs";
|
|
4
4
|
import { checkPrototypeSource, errorLines, sourceFiles } from "../content/prototype-checks.mjs";
|
|
5
|
-
import { groupWork } from "./work-groups.mjs";
|
|
6
|
-
import { stylesheetOf } from "./thread-source.mjs";
|
|
7
5
|
import { babel } from "../setup/design-system-checks.mjs";
|
|
6
|
+
import { stylesheetOf } from "./thread-source.mjs";
|
|
7
|
+
import { groupWork } from "./work-groups.mjs";
|
|
8
8
|
import { join, relative, sep } from "node:path";
|
|
9
9
|
import { readFile, stat } from "node:fs/promises";
|
|
10
10
|
//#region src/server/close-check.ts
|