@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
package/src/server/file-lock.ts
CHANGED
|
@@ -1,93 +1,239 @@
|
|
|
1
|
-
// A lock every process on this machine shares: a folder
|
|
2
|
-
//
|
|
3
|
-
// each changed under one, so two agents changing the
|
|
4
|
-
// survive, and a claim is only ever won by one of
|
|
5
|
-
// process that stopped halfway is taken over once
|
|
1
|
+
// A lock every process on this machine shares: a folder holding one claim, a
|
|
2
|
+
// file named for its holder and when its lease ends. Presence, thread files
|
|
3
|
+
// and canvas.json are each changed under one, so two agents changing the
|
|
4
|
+
// same file at once both survive, and a claim is only ever won by one of
|
|
5
|
+
// them. A lease left by a process that stopped halfway is taken over once
|
|
6
|
+
// it has ended.
|
|
7
|
+
//
|
|
8
|
+
// Every change to a claim is one rename or unlink of the exact name its
|
|
9
|
+
// changer last saw, so it fails when the claim has changed since: a holder
|
|
10
|
+
// that comes back late never removes the next holder's lock, and two
|
|
11
|
+
// waiters never both take over one left behind. The design is model-checked:
|
|
12
|
+
// .claude/skills/verify-file-lock.
|
|
6
13
|
|
|
7
|
-
import {
|
|
14
|
+
import { randomBytes } from "node:crypto";
|
|
15
|
+
import {
|
|
16
|
+
mkdir,
|
|
17
|
+
readdir,
|
|
18
|
+
rename,
|
|
19
|
+
rm,
|
|
20
|
+
rmdir,
|
|
21
|
+
stat,
|
|
22
|
+
unlink,
|
|
23
|
+
writeFile,
|
|
24
|
+
} from "node:fs/promises";
|
|
25
|
+
import { join } from "node:path";
|
|
8
26
|
import { setTimeout as delay } from "node:timers/promises";
|
|
9
27
|
|
|
10
|
-
// A change takes milliseconds. A
|
|
11
|
-
// that stopped halfway, and is taken over.
|
|
28
|
+
// A change takes milliseconds. A lease longer than this was left by a
|
|
29
|
+
// process that stopped halfway, and is taken over.
|
|
12
30
|
const LOCK_STALE_MS = 5000;
|
|
13
31
|
const LOCK_RETRY_MS = 10;
|
|
14
32
|
|
|
15
33
|
/** How a lock is held. */
|
|
16
34
|
export interface LockOptions {
|
|
17
35
|
/**
|
|
18
|
-
* Keep the
|
|
36
|
+
* Keep the lease fresh while the work runs, so work longer than `staleMs`
|
|
19
37
|
* keeps it: only a lock whose process stopped goes stale.
|
|
20
38
|
*/
|
|
21
39
|
keepAlive?: boolean;
|
|
22
|
-
/** How
|
|
40
|
+
/** How long a lease lasts before it counts as left behind. */
|
|
23
41
|
staleMs?: number;
|
|
24
42
|
}
|
|
25
43
|
|
|
26
|
-
/** A lock kept alive is
|
|
44
|
+
/** A lock kept alive is renewed this often per `staleMs`, so one late renewal still lands in time. */
|
|
27
45
|
const TOUCHES_PER_STALE = 3;
|
|
28
46
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
/**
|
|
48
|
+
* How many times in a row publishing may be refused with no folder there
|
|
49
|
+
* before the refusal is taken as a real error rather than a release racing it.
|
|
50
|
+
*/
|
|
51
|
+
const REFUSALS_WITHOUT_FOLDER = 100;
|
|
52
|
+
|
|
53
|
+
const CLAIM_PREFIX = "holder-";
|
|
54
|
+
|
|
55
|
+
const claimName = (token: string, staleMs: number): string =>
|
|
56
|
+
`${CLAIM_PREFIX}${token}-${Date.now() + staleMs}`;
|
|
34
57
|
|
|
35
|
-
const
|
|
58
|
+
const isClaim = (name: string): boolean => name.startsWith(CLAIM_PREFIX);
|
|
36
59
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
60
|
+
const leaseEnded = (claim: string): boolean =>
|
|
61
|
+
Number(claim.slice(claim.lastIndexOf("-") + 1)) <= Date.now();
|
|
62
|
+
|
|
63
|
+
const code = (error: unknown): string | undefined =>
|
|
64
|
+
(error as NodeJS.ErrnoException).code;
|
|
65
|
+
|
|
66
|
+
/** Whether a call failed for want of what it named: it changed since it was seen. */
|
|
67
|
+
const gone = (error: unknown): boolean => code(error) === "ENOENT";
|
|
40
68
|
|
|
41
69
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* removal happens under a second folder, after looking at the age again.
|
|
45
|
-
* Returns whether this process did the takeover.
|
|
70
|
+
* Whether publishing failed because a folder is there: POSIX refuses a full
|
|
71
|
+
* folder, Windows any folder.
|
|
46
72
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
73
|
+
const refused = (error: unknown): boolean =>
|
|
74
|
+
["EEXIST", "ENOTEMPTY", "EPERM", "EACCES"].includes(code(error) ?? "");
|
|
75
|
+
|
|
76
|
+
/** Run `call`, true when it worked, false when what it named was gone. */
|
|
77
|
+
const unlessGone = (call: Promise<unknown>): Promise<boolean> =>
|
|
78
|
+
call.then(
|
|
79
|
+
() => true,
|
|
80
|
+
(error) => {
|
|
81
|
+
if (gone(error)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
53
84
|
throw error;
|
|
54
85
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Remove what `work` left in the lock's folder. Never a claim: one that is
|
|
90
|
+
* not this caller's is a holder's that took the lock over meanwhile.
|
|
91
|
+
*/
|
|
92
|
+
async function clearBesides(folder: string): Promise<void> {
|
|
93
|
+
for (const entry of await readdir(folder)) {
|
|
94
|
+
if (!isClaim(entry)) {
|
|
95
|
+
await rm(join(folder, entry), { recursive: true, force: true });
|
|
59
96
|
}
|
|
60
|
-
return false;
|
|
61
97
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A folder with no claim is empty for a moment while it is let go, or was
|
|
102
|
+
* left by an older Dex, which held a lock as a bare folder. Once older than
|
|
103
|
+
* `staleMs`, what is in it goes, and then the folder if it is still empty:
|
|
104
|
+
* never a claim, so never a lock that is held.
|
|
105
|
+
*/
|
|
106
|
+
async function clearUnclaimed(
|
|
107
|
+
folder: string,
|
|
108
|
+
entries: string[],
|
|
109
|
+
staleMs: number
|
|
110
|
+
): Promise<void> {
|
|
111
|
+
const old = await stat(folder).then(
|
|
112
|
+
(info) => Date.now() - info.mtimeMs > staleMs,
|
|
113
|
+
() => false
|
|
114
|
+
);
|
|
115
|
+
if (!old) {
|
|
116
|
+
await delay(LOCK_RETRY_MS);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
await rm(join(folder, entry), { recursive: true, force: true });
|
|
69
121
|
}
|
|
122
|
+
await rmdir(folder).catch(() => undefined);
|
|
70
123
|
}
|
|
71
124
|
|
|
72
|
-
/**
|
|
73
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Take the lock `folder`, waiting while another process holds it. Returns
|
|
127
|
+
* the name of this caller's claim.
|
|
128
|
+
*/
|
|
129
|
+
async function lock(
|
|
130
|
+
folder: string,
|
|
131
|
+
token: string,
|
|
132
|
+
staleMs: number
|
|
133
|
+
): Promise<string> {
|
|
134
|
+
const temporary = `${folder}.${token}`;
|
|
135
|
+
let refusals = 0;
|
|
74
136
|
for (;;) {
|
|
137
|
+
// A folder that already holds the claim appears whole, or not at all.
|
|
138
|
+
const mine = claimName(token, staleMs);
|
|
139
|
+
await mkdir(temporary);
|
|
75
140
|
try {
|
|
76
|
-
await
|
|
77
|
-
|
|
141
|
+
await writeFile(join(temporary, mine), "");
|
|
142
|
+
await rename(temporary, folder);
|
|
143
|
+
// Nothing more is awaited before `work` starts. A caller held up so
|
|
144
|
+
// long that its lease ended first is a holder that lapsed.
|
|
145
|
+
return mine;
|
|
78
146
|
} catch (error) {
|
|
79
|
-
|
|
147
|
+
await rm(temporary, { recursive: true, force: true });
|
|
148
|
+
if (!refused(error)) {
|
|
80
149
|
throw error;
|
|
81
150
|
}
|
|
82
151
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
152
|
+
|
|
153
|
+
const entries = await readdir(folder).catch((error: unknown) => {
|
|
154
|
+
if (gone(error)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
});
|
|
159
|
+
if (!entries) {
|
|
160
|
+
refusals += 1;
|
|
161
|
+
if (refusals >= REFUSALS_WITHOUT_FOLDER) {
|
|
162
|
+
throw new Error(`The lock ${folder} could not be made.`);
|
|
163
|
+
}
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
refusals = 0;
|
|
167
|
+
const held = entries.find(isClaim);
|
|
168
|
+
if (!held) {
|
|
169
|
+
await clearUnclaimed(folder, entries, staleMs);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (!leaseEnded(held)) {
|
|
86
173
|
await delay(LOCK_RETRY_MS);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
// Take over the claim seen, if it is still the one there.
|
|
177
|
+
const taken = claimName(token, staleMs);
|
|
178
|
+
if (await unlessGone(rename(join(folder, held), join(folder, taken)))) {
|
|
179
|
+
await clearBesides(folder);
|
|
180
|
+
return taken;
|
|
87
181
|
}
|
|
88
182
|
}
|
|
89
183
|
}
|
|
90
184
|
|
|
185
|
+
/** A held lock's claim, renewed one at a time. */
|
|
186
|
+
function holding(
|
|
187
|
+
folder: string,
|
|
188
|
+
token: string,
|
|
189
|
+
claim: string,
|
|
190
|
+
staleMs: number
|
|
191
|
+
) {
|
|
192
|
+
let current: string | undefined = claim;
|
|
193
|
+
let last: Promise<void> = Promise.resolve();
|
|
194
|
+
/** Renew the lease, unless it was lost: the name now, or undefined. */
|
|
195
|
+
const renew = (): Promise<string | undefined> => {
|
|
196
|
+
last = last.then(async () => {
|
|
197
|
+
if (!current) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const next = claimName(token, staleMs);
|
|
201
|
+
try {
|
|
202
|
+
await rename(join(folder, current), join(folder, next));
|
|
203
|
+
current = next;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
// Gone: taken over. Any other failure keeps the claim as it was.
|
|
206
|
+
if (gone(error)) {
|
|
207
|
+
current = undefined;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
return last.then(() => current);
|
|
212
|
+
};
|
|
213
|
+
return { renew };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Let the lock go, if this caller still holds it: renew it first, so it
|
|
218
|
+
* stays this caller's while the folder is cleared; touch nothing if it was
|
|
219
|
+
* taken over.
|
|
220
|
+
*/
|
|
221
|
+
async function release(
|
|
222
|
+
folder: string,
|
|
223
|
+
claim: ReturnType<typeof holding>
|
|
224
|
+
): Promise<void> {
|
|
225
|
+
const mine = await claim.renew();
|
|
226
|
+
if (!mine) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
await clearBesides(folder);
|
|
230
|
+
if (!(await unlessGone(unlink(join(folder, mine))))) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
// Only an empty folder goes: one published into it meanwhile stays.
|
|
234
|
+
await rmdir(folder).catch(() => undefined);
|
|
235
|
+
}
|
|
236
|
+
|
|
91
237
|
/**
|
|
92
238
|
* Run `work` holding the lock `folder` (its parent must exist), and let it
|
|
93
239
|
* go after, whatever happens. `work` may keep files in the folder while it
|
|
@@ -98,17 +244,22 @@ export async function withLock<T>(
|
|
|
98
244
|
work: () => Promise<T>,
|
|
99
245
|
{ keepAlive = false, staleMs = LOCK_STALE_MS }: LockOptions = {}
|
|
100
246
|
): Promise<T> {
|
|
101
|
-
|
|
247
|
+
const token = randomBytes(8).toString("hex");
|
|
248
|
+
const claim = holding(
|
|
249
|
+
folder,
|
|
250
|
+
token,
|
|
251
|
+
await lock(folder, token, staleMs),
|
|
252
|
+
staleMs
|
|
253
|
+
);
|
|
102
254
|
const fresh = keepAlive
|
|
103
255
|
? setInterval(() => {
|
|
104
|
-
|
|
105
|
-
utimes(folder, now, now).catch(() => undefined);
|
|
256
|
+
claim.renew().catch(() => undefined);
|
|
106
257
|
}, staleMs / TOUCHES_PER_STALE)
|
|
107
258
|
: undefined;
|
|
108
259
|
try {
|
|
109
260
|
return await work();
|
|
110
261
|
} finally {
|
|
111
262
|
clearInterval(fresh);
|
|
112
|
-
await
|
|
263
|
+
await release(folder, claim);
|
|
113
264
|
}
|
|
114
265
|
}
|
package/src/server/mcp.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
//
|
|
16
16
|
// This module creates the server, builds what its tools share
|
|
17
17
|
// (tools/context.ts), registers each group of tools from its module in
|
|
18
|
-
// tools
|
|
18
|
+
// tools/ (the comment tools from comments/tools.ts), and serves.
|
|
19
19
|
|
|
20
20
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
21
21
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -41,10 +41,9 @@ import {
|
|
|
41
41
|
startChannel,
|
|
42
42
|
startHeartbeat,
|
|
43
43
|
} from "./channel.ts";
|
|
44
|
+
import { registerCommentTools } from "./comments/tools.ts";
|
|
44
45
|
import { HANDOVER, type Handover, registerHandover } from "./mcp-handover.ts";
|
|
45
46
|
import { type StudioFor, studioFor } from "./studio-for.ts";
|
|
46
|
-
import { registerCloseAndReplyTools } from "./tools/close-reply.ts";
|
|
47
|
-
import { registerCommentTool } from "./tools/comment.ts";
|
|
48
47
|
import { openToolContext } from "./tools/context.ts";
|
|
49
48
|
import { registerFeedbackTool } from "./tools/feedback.ts";
|
|
50
49
|
import { registerPlaceFrameTool } from "./tools/place-frame.ts";
|
|
@@ -137,12 +136,6 @@ const designSystemOf = (
|
|
|
137
136
|
() => undefined
|
|
138
137
|
);
|
|
139
138
|
|
|
140
|
-
/** The studio's MCP server (see createStudio). */
|
|
141
|
-
export const createStudioServer = (
|
|
142
|
-
root: string,
|
|
143
|
-
options: StudioServerOptions = {}
|
|
144
|
-
): McpServer => createStudio(root, options).server;
|
|
145
|
-
|
|
146
139
|
/**
|
|
147
140
|
* The studio's MCP server and its agent session. `threads`
|
|
148
141
|
* (thread-module.ts) is shared with the channel, so one change feed serves
|
|
@@ -190,6 +183,7 @@ export function createStudio(
|
|
|
190
183
|
};
|
|
191
184
|
const session = openAgentSession(root, threads, {
|
|
192
185
|
agent: agentName,
|
|
186
|
+
claudeSession,
|
|
193
187
|
...(sessionId ? { id: sessionId } : {}),
|
|
194
188
|
});
|
|
195
189
|
const handover = registerHandover(server, session, receipt);
|
|
@@ -216,8 +210,8 @@ export function createStudio(
|
|
|
216
210
|
registerReadingTools(server, context, briefing);
|
|
217
211
|
registerThreadsTool(server, context);
|
|
218
212
|
registerWatchTool(server, context);
|
|
219
|
-
|
|
220
|
-
|
|
213
|
+
// `comment`, `close` and `reply`.
|
|
214
|
+
registerCommentTools(server, context);
|
|
221
215
|
registerPlaceFrameTool(server, context);
|
|
222
216
|
registerShowTool(server, context, findStudio);
|
|
223
217
|
registerSnapshotTool(server, context, findStudio);
|
|
@@ -235,12 +229,13 @@ export async function serveMcp(
|
|
|
235
229
|
const channel = process.env[CHANNEL_ENV] === "1";
|
|
236
230
|
// One thread module, so the channel and `watch` share its change feed.
|
|
237
231
|
const threads = openThreads(root);
|
|
232
|
+
// Claude Code gives its MCP servers the session's id, as it gives hooks.
|
|
233
|
+
const claudeSession = process.env.CLAUDE_CODE_SESSION_ID;
|
|
238
234
|
const { handover, receipt, server, session } = createStudio(root, {
|
|
239
235
|
...options,
|
|
240
236
|
channel,
|
|
241
237
|
threads,
|
|
242
|
-
|
|
243
|
-
claudeSession: process.env.CLAUDE_CODE_SESSION_ID,
|
|
238
|
+
claudeSession,
|
|
244
239
|
});
|
|
245
240
|
const client = () => server.server.getClientVersion()?.name ?? "";
|
|
246
241
|
const pushUntilHandedOver = async () => {
|
|
@@ -265,7 +260,11 @@ export async function serveMcp(
|
|
|
265
260
|
holding: session.holding().length,
|
|
266
261
|
receipt,
|
|
267
262
|
}),
|
|
268
|
-
{
|
|
263
|
+
{
|
|
264
|
+
claudeSession,
|
|
265
|
+
onEnd: session.leave,
|
|
266
|
+
session: session.id,
|
|
267
|
+
}
|
|
269
268
|
);
|
|
270
269
|
// The studio sees a watch start or stop, its grace run out, and the
|
|
271
270
|
// comments the session holds change, as they happen, not a beat later.
|
package/src/server/me.ts
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
// `meTag` in vite.ts) and asks for it again when it may have changed.
|
|
4
4
|
|
|
5
5
|
import { execFile } from "node:child_process";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
identify,
|
|
9
|
-
joinCurrentPerson,
|
|
10
|
-
} from "../content/content.ts";
|
|
6
|
+
import { identify, joinCurrentPerson } from "../content/content.ts";
|
|
7
|
+
import type { Contributor } from "../shared/studio-files.ts";
|
|
11
8
|
import { nameOfMe } from "../shared/studio-routes.ts";
|
|
12
9
|
import { readCloudConfig } from "./cloud.ts";
|
|
13
10
|
|
package/src/server/open-page.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Where the person is in Dex, as an agent asks for it: the file they have
|
|
2
2
|
// open, the page of it, the sections of its canvas in view and the frame
|
|
3
|
-
// selected,
|
|
4
|
-
// tells the server as the person
|
|
5
|
-
// server keeps it with the open
|
|
6
|
-
// first when they are listed.
|
|
3
|
+
// selected, how long ago Dex's interface last said so, and who the canvas
|
|
4
|
+
// shows at work on the file. The interface tells the server as the person
|
|
5
|
+
// moves (shared/open-page-core.ts) and the server keeps it with the open
|
|
6
|
+
// file (state.ts). Threads on that page come first when they are listed.
|
|
7
7
|
|
|
8
8
|
import { readCanvas } from "../content/content.ts";
|
|
9
9
|
import { prototypeTitle } from "../content/prototypes.ts";
|
|
@@ -13,7 +13,13 @@ import {
|
|
|
13
13
|
parseFrameKey,
|
|
14
14
|
viewOf,
|
|
15
15
|
} from "../shared/canvas-core.ts";
|
|
16
|
+
import { fromRoom } from "../shared/live-presence.ts";
|
|
16
17
|
import { onOpenPage } from "../shared/open-page-core.ts";
|
|
18
|
+
import {
|
|
19
|
+
endsAt,
|
|
20
|
+
type PresenceEntry,
|
|
21
|
+
underSession,
|
|
22
|
+
} from "../shared/presence-core.ts";
|
|
17
23
|
import type { ThreadWithPrototype } from "../shared/threads-core.ts";
|
|
18
24
|
import { plural } from "./response-budget.ts";
|
|
19
25
|
import { readFocus, type SavedFocus } from "./state.ts";
|
|
@@ -159,6 +165,50 @@ export async function whereThePersonIs(
|
|
|
159
165
|
};
|
|
160
166
|
}
|
|
161
167
|
|
|
168
|
+
/** An agent the canvas shows at work on a file, as an agent reads it (`where`). */
|
|
169
|
+
export interface AtWork {
|
|
170
|
+
agent: string;
|
|
171
|
+
/**
|
|
172
|
+
* Whose mark it is: the agent reading it (its own session, or the Claude
|
|
173
|
+
* Code session it serves, sub-agents too), another session on this
|
|
174
|
+
* machine, or a teammate in the live workspace.
|
|
175
|
+
*/
|
|
176
|
+
by: "you" | "another session" | "a teammate";
|
|
177
|
+
/** When it ends, unless it is marked again or its work ends first. */
|
|
178
|
+
ends: string;
|
|
179
|
+
/** When it was last marked. */
|
|
180
|
+
marked: string;
|
|
181
|
+
/** "view:<name>", "doc:<name>", or "prototype": shared code, so every view. */
|
|
182
|
+
on: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Who the canvas shows at work on file `slug`, from the fresh `entries`, as
|
|
187
|
+
* the agent whose marks are under the sessions `mine` reads it.
|
|
188
|
+
*/
|
|
189
|
+
export const atWorkOn = (
|
|
190
|
+
entries: readonly PresenceEntry[],
|
|
191
|
+
slug: string,
|
|
192
|
+
mine: readonly string[]
|
|
193
|
+
): AtWork[] =>
|
|
194
|
+
entries
|
|
195
|
+
.filter((entry) => entry.slug === slug)
|
|
196
|
+
.map((entry) => {
|
|
197
|
+
let by: AtWork["by"] = "another session";
|
|
198
|
+
if (fromRoom(entry)) {
|
|
199
|
+
by = "a teammate";
|
|
200
|
+
} else if (mine.some((session) => underSession(entry.session, session))) {
|
|
201
|
+
by = "you";
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
agent: entry.agent,
|
|
205
|
+
on: entry.target,
|
|
206
|
+
by,
|
|
207
|
+
marked: entry.updated,
|
|
208
|
+
ends: new Date(endsAt(entry)).toISOString(),
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
|
|
162
212
|
/** A thread with whether it is on the page the person has open. */
|
|
163
213
|
export interface PlacedThread<T> {
|
|
164
214
|
onOpenPage: boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// What a core action answers: a value, or the problem that stopped it. An
|
|
2
|
+
// action never throws for what it expects to refuse, and never names an
|
|
3
|
+
// HTTP status: each adapter turns a problem into its own answer, a status
|
|
4
|
+
// for the interface's requests and a refusal for an agent's tools.
|
|
5
|
+
|
|
6
|
+
/** What kind of refusal a problem is. */
|
|
7
|
+
export type ProblemKind = "not-found" | "conflict" | "invalid" | "not-allowed";
|
|
8
|
+
|
|
9
|
+
/** Why an action did not happen, in words for people: most say one thing. */
|
|
10
|
+
export interface Problem {
|
|
11
|
+
kind: ProblemKind;
|
|
12
|
+
messages: string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** What an action did, or the problem that stopped it. */
|
|
16
|
+
export type Outcome<T> =
|
|
17
|
+
| { problem?: undefined; value: T }
|
|
18
|
+
| { problem: Problem; value?: undefined };
|
|
19
|
+
|
|
20
|
+
/** An action refused, of `kind`, with what to tell people. */
|
|
21
|
+
export const refused = (
|
|
22
|
+
kind: ProblemKind,
|
|
23
|
+
messages: string[]
|
|
24
|
+
): { problem: Problem; value?: undefined } => ({
|
|
25
|
+
problem: { kind, messages },
|
|
26
|
+
});
|
package/src/server/people.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// contributors.json, with when they last committed and how often, from git's
|
|
3
3
|
// log under any of their git names. Read-only.
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { loadStudio } from "../content/content.ts";
|
|
6
|
+
import type { Contributor } from "../shared/studio-files.ts";
|
|
6
7
|
import type { Person } from "../shared/studio-routes.ts";
|
|
7
8
|
import { runGit } from "./git.ts";
|
|
8
9
|
|