gentle-pi 4.7.0 → 4.9.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/README.md +115 -44
- package/assets/agents/gentle-ai-explore.md +3 -3
- package/assets/agents/gentle-ai-verify.md +20 -6
- package/assets/agents/gentle-ai-worker.md +14 -13
- package/assets/agents/jd-judge-a.md +1 -3
- package/assets/agents/jd-judge-b.md +1 -3
- package/assets/agents/review-readability.md +1 -5
- package/assets/agents/review-reliability.md +1 -5
- package/assets/agents/review-resilience.md +1 -5
- package/assets/agents/review-risk.md +1 -5
- package/assets/design-canvas/canvas-api.js +45 -0
- package/assets/design-canvas/canvas-boards.js +476 -0
- package/assets/design-canvas/canvas-boot.js +219 -0
- package/assets/design-canvas/canvas-checks.js +491 -0
- package/assets/design-canvas/canvas-comments.js +315 -0
- package/assets/design-canvas/canvas-compare.js +159 -0
- package/assets/design-canvas/canvas-events.js +75 -0
- package/assets/design-canvas/canvas-export.js +393 -0
- package/assets/design-canvas/canvas-focus.js +203 -0
- package/assets/design-canvas/canvas-handoffs.js +150 -0
- package/assets/design-canvas/canvas-i18n-es.js +397 -0
- package/assets/design-canvas/canvas-i18n.js +108 -0
- package/assets/design-canvas/canvas-layout.js +526 -0
- package/assets/design-canvas/canvas-menu.js +219 -0
- package/assets/design-canvas/canvas-messages.js +86 -0
- package/assets/design-canvas/canvas-minimap.js +163 -0
- package/assets/design-canvas/canvas-parts.js +401 -0
- package/assets/design-canvas/canvas-popover.js +234 -0
- package/assets/design-canvas/canvas-rail.js +351 -0
- package/assets/design-canvas/canvas-sizes.js +524 -0
- package/assets/design-canvas/canvas-store.js +167 -0
- package/assets/design-canvas/canvas-theme.js +69 -0
- package/assets/design-canvas/canvas-tokens.js +674 -0
- package/assets/design-canvas/canvas-ui.js +24 -0
- package/assets/design-canvas/canvas-view.js +184 -0
- package/assets/design-canvas/canvas.css +773 -17
- package/assets/design-canvas/canvas.js +2 -1506
- package/assets/design-canvas/index.html +120 -36
- package/assets/design-canvas/inspector.js +574 -21
- package/assets/design-canvas/theme-early.js +10 -0
- package/assets/install-wizard/wizard.js +5 -1
- package/assets/migrations/agent-body-history.json +30 -0
- package/assets/orchestrator-delegation-reference.md +8 -14
- package/assets/orchestrator-delegation.md +5 -9
- package/assets/orchestrator-full-delegation-card.md +11 -16
- package/assets/orchestrator-full-delegation.md +9 -9
- package/assets/orchestrator-memory.md +4 -4
- package/assets/orchestrator-prompts.md +3 -31
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +13 -12
- package/assets/orchestrator-tracking.md +13 -17
- package/assets/orchestrator-verification.md +12 -10
- package/assets/orchestrator-writer.md +13 -13
- package/assets/orchestrator.md +20 -24
- package/bin/gentle-shell.mjs +205 -10
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/orchestration/pi.md +2 -1
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/routing/pi.md +16 -16
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/assets/features/gentle-tower.png +0 -0
- package/docs/auto-permission-answers.md +1 -1
- package/docs/bundled-install.md +14 -6
- package/docs/delegated-verification.md +23 -5
- package/docs/desktop-feed.md +303 -0
- package/docs/desktop-rpc.md +1931 -0
- package/docs/fast-mode.md +2 -2
- package/docs/gentle-agents-activity.md +26 -0
- package/docs/gentle-shell-desktop.md +465 -0
- package/docs/gentle-shell.md +102 -17
- package/docs/images/desktop/chat.png +0 -0
- package/docs/images/desktop/palette.png +0 -0
- package/docs/images/desktop/todo.png +0 -0
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +9 -1
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +113 -32
- package/docs/review-coordinator.md +29 -9
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/work-continuity.md +19 -6
- package/extensions/ask-user-choice.ts +36 -18
- package/extensions/ask-user-question.ts +48 -9
- package/extensions/child-context.ts +21 -7
- package/extensions/gentle-agents.ts +436 -66
- package/extensions/gentle-ai.ts +809 -158
- package/extensions/gentle-design.ts +69 -3
- package/extensions/gentle-desktop-feed.ts +778 -0
- package/extensions/gentle-desktop-rpc.ts +276 -0
- package/extensions/gentle-guide.ts +3 -0
- package/extensions/gentle-herdr-desktop-status.ts +275 -0
- package/extensions/gentle-shell.ts +174 -59
- package/extensions/gentle-stats.ts +30 -1
- package/extensions/gentle-todo.ts +48 -25
- package/extensions/gentle-tower.ts +305 -0
- package/extensions/skill-registry.ts +260 -225
- package/herdr/RECIPE.md +157 -0
- package/herdr/keys.json +14 -0
- package/herdr/layouts/gentle-shell.json +202 -0
- package/herdr/mods/gentle-agents/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-agents/main.js +190 -0
- package/herdr/mods/gentle-agents/mod.json +1 -0
- package/herdr/mods/gentle-agents/snapshot.js +469 -0
- package/herdr/mods/gentle-agents/tokens.js +273 -0
- package/herdr/mods/gentle-chat/MINIMAL.md +69 -0
- package/herdr/mods/gentle-chat/actions.js +180 -0
- package/herdr/mods/gentle-chat/feed.js +321 -0
- package/herdr/mods/gentle-chat/icons/branch.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chat.svg +1 -0
- package/herdr/mods/gentle-chat/icons/check.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chev.svg +1 -0
- package/herdr/mods/gentle-chat/icons/clip.svg +1 -0
- package/herdr/mods/gentle-chat/icons/down.svg +1 -0
- package/herdr/mods/gentle-chat/icons/folder.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-chat/icons/mark.svg +1 -0
- package/herdr/mods/gentle-chat/icons/send.svg +1 -0
- package/herdr/mods/gentle-chat/icons/shield.svg +1 -0
- package/herdr/mods/gentle-chat/icons/stop.svg +1 -0
- package/herdr/mods/gentle-chat/icons/term.svg +1 -0
- package/herdr/mods/gentle-chat/icons/user.svg +1 -0
- package/herdr/mods/gentle-chat/icons/x.svg +1 -0
- package/herdr/mods/gentle-chat/main.js +968 -0
- package/herdr/mods/gentle-chat/mod.json +1 -0
- package/herdr/mods/gentle-chat/session.js +212 -0
- package/herdr/mods/gentle-chat/snapshot.js +469 -0
- package/herdr/mods/gentle-chat/tokens.js +137 -0
- package/herdr/mods/gentle-chat/ui.js +883 -0
- package/herdr/mods/gentle-confirm/main.js +60 -0
- package/herdr/mods/gentle-confirm/mod.json +1 -0
- package/herdr/mods/gentle-inspector/actions.js +180 -0
- package/herdr/mods/gentle-inspector/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/bot.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/check.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/db.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/diff.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/plug.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/review.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stats.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stop.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/todo.svg +1 -0
- package/herdr/mods/gentle-inspector/main.js +500 -0
- package/herdr/mods/gentle-inspector/mod.json +1 -0
- package/herdr/mods/gentle-inspector/snapshot.js +469 -0
- package/herdr/mods/gentle-inspector/tokens.js +273 -0
- package/herdr/mods/gentle-palette/actions.js +180 -0
- package/herdr/mods/gentle-palette/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-palette/icons/bot.svg +1 -0
- package/herdr/mods/gentle-palette/icons/chat.svg +1 -0
- package/herdr/mods/gentle-palette/icons/check.svg +1 -0
- package/herdr/mods/gentle-palette/icons/cmd.svg +1 -0
- package/herdr/mods/gentle-palette/icons/diff.svg +1 -0
- package/herdr/mods/gentle-palette/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-palette/icons/plus.svg +1 -0
- package/herdr/mods/gentle-palette/icons/review.svg +1 -0
- package/herdr/mods/gentle-palette/icons/search.svg +1 -0
- package/herdr/mods/gentle-palette/icons/shield.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stats.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stop.svg +1 -0
- package/herdr/mods/gentle-palette/icons/term.svg +1 -0
- package/herdr/mods/gentle-palette/icons/todo.svg +1 -0
- package/herdr/mods/gentle-palette/main.js +333 -0
- package/herdr/mods/gentle-palette/mod.json +1 -0
- package/herdr/mods/gentle-palette/snapshot.js +469 -0
- package/herdr/mods/gentle-palette/tokens.js +273 -0
- package/herdr/mods/gentle-pane/icons/chat.svg +1 -0
- package/herdr/mods/gentle-pane/icons/close.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-down.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-right.svg +1 -0
- package/herdr/mods/gentle-pane/icons/term.svg +1 -0
- package/herdr/mods/gentle-pane/icons/unzoom.svg +1 -0
- package/herdr/mods/gentle-pane/icons/zoom.svg +1 -0
- package/herdr/mods/gentle-pane/main.js +91 -0
- package/herdr/mods/gentle-pane/mod.json +1 -0
- package/herdr/mods/gentle-pane/snapshot.js +469 -0
- package/herdr/mods/gentle-pane/tokens.js +273 -0
- package/herdr/mods/gentle-sidebar/actions.js +180 -0
- package/herdr/mods/gentle-sidebar/icons/gear.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/mark.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/refresh.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/server-plus.svg +1 -0
- package/herdr/mods/gentle-sidebar/main.js +171 -0
- package/herdr/mods/gentle-sidebar/mod.json +1 -0
- package/herdr/mods/gentle-sidebar/snapshot.js +469 -0
- package/herdr/mods/gentle-sidebar/tokens.js +273 -0
- package/herdr/mods/gentle-spaces/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/monitor.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/plus.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/server.svg +1 -0
- package/herdr/mods/gentle-spaces/machines.js +31 -0
- package/herdr/mods/gentle-spaces/main.js +299 -0
- package/herdr/mods/gentle-spaces/mod.json +1 -0
- package/herdr/mods/gentle-spaces/snapshot.js +469 -0
- package/herdr/mods/gentle-spaces/tokens.js +273 -0
- package/herdr/mods/gentle-status/actions.js +180 -0
- package/herdr/mods/gentle-status/main.js +192 -0
- package/herdr/mods/gentle-status/mod.json +1 -0
- package/herdr/mods/gentle-status/snapshot.js +469 -0
- package/herdr/mods/gentle-status/tokens.js +273 -0
- package/herdr/mods/gentle-tabs/icons/close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/plus.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-max.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-min.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-restore.svg +1 -0
- package/herdr/mods/gentle-tabs/main.js +171 -0
- package/herdr/mods/gentle-tabs/mod.json +1 -0
- package/herdr/mods/gentle-tabs/snapshot.js +469 -0
- package/herdr/mods/gentle-tabs/tokens.js +273 -0
- package/herdr/mods/gentle-tokens/main.js +20 -0
- package/herdr/mods/gentle-tokens/mod.json +1 -0
- package/herdr/mods/gentle-tokens/snapshot.js +469 -0
- package/herdr/mods/gentle-tokens/tokens.js +273 -0
- package/herdr/preview.png +0 -0
- package/herdr/themes/gentle-shell-dark.json +33 -0
- package/herdr/themes/gentle-shell-light.json +34 -0
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +47 -6
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +8 -2
- package/lib/agents-protocol.ts +17 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-rpc-publisher.ts +39 -12
- package/lib/agents-runner.ts +92 -6
- package/lib/agents-session-transport.ts +17 -1
- package/lib/auto-permission-answers.ts +2 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/background-jobs.ts +22 -2
- package/lib/bounded-writer-admission.ts +184 -31
- package/lib/change-diff.ts +104 -0
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/commit-slice-signal.ts +1 -1
- package/lib/delivery-conflict-markers.ts +349 -0
- package/lib/design-canvas-assets.ts +38 -0
- package/lib/design-canvas-server.ts +241 -23
- package/lib/design-comments.ts +94 -4
- package/lib/design-handoffs.ts +2 -1
- package/lib/design-layout.ts +125 -0
- package/lib/design-parts.ts +281 -0
- package/lib/design-system-tokens.ts +111 -0
- package/lib/desktop-agents-service.ts +315 -0
- package/lib/desktop-changes-service.ts +171 -0
- package/lib/desktop-design-service.ts +233 -0
- package/lib/desktop-feed-actions.ts +804 -0
- package/lib/desktop-feed-answers.ts +129 -0
- package/lib/desktop-feed-sources.ts +184 -0
- package/lib/desktop-feed-stats.ts +98 -0
- package/lib/desktop-feed-store.ts +124 -0
- package/lib/desktop-feed.ts +788 -0
- package/lib/desktop-jobs-service.ts +290 -0
- package/lib/desktop-review-service.ts +187 -0
- package/lib/desktop-rpc-agents.ts +403 -0
- package/lib/desktop-rpc-changes.ts +223 -0
- package/lib/desktop-rpc-config-watch.ts +285 -0
- package/lib/desktop-rpc-config.ts +885 -0
- package/lib/desktop-rpc-design.ts +138 -0
- package/lib/desktop-rpc-jobs.ts +290 -0
- package/lib/desktop-rpc-permissions.ts +328 -0
- package/lib/desktop-rpc-profiles.ts +196 -0
- package/lib/desktop-rpc-review.ts +180 -0
- package/lib/desktop-rpc-session.ts +203 -0
- package/lib/desktop-rpc-sessions.ts +250 -0
- package/lib/desktop-rpc-stats.ts +187 -0
- package/lib/desktop-rpc-updates.ts +143 -0
- package/lib/desktop-rpc-usage.ts +229 -0
- package/lib/desktop-rpc.ts +336 -0
- package/lib/desktop-session-service.ts +223 -0
- package/lib/desktop-sessions-service.ts +249 -0
- package/lib/desktop-stats-service.ts +142 -0
- package/lib/desktop-updates-service.ts +268 -0
- package/lib/desktop-usage-service.ts +310 -0
- package/lib/destructive-command-guard.ts +188 -13
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +201 -14
- package/lib/gentle-shell-bundled.ts +100 -9
- package/lib/gentle-shell-desktop.ts +1370 -0
- package/lib/gentle-shell-launcher.ts +45 -3
- package/lib/herdr-desktop-events.ts +40 -0
- package/lib/herdr-desktop-status.ts +229 -0
- package/lib/hidden-tools.ts +35 -0
- package/lib/inprocess-reviewer.ts +96 -12
- package/lib/jobs-sidebar-state.ts +5 -0
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +9 -0
- package/lib/nan-provider.ts +42 -28
- package/lib/native-review-cli.ts +86 -4
- package/lib/openai-fast-tier.ts +1 -0
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/reply-language-anchor.ts +27 -2
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +17 -0
- package/lib/review-coordinator.ts +252 -8
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +56 -3
- package/lib/reviewer-stream.ts +87 -0
- package/lib/session-profile-freeze.ts +13 -5
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/stats-collector.ts +56 -27
- package/lib/tower-actions.ts +100 -0
- package/lib/tower-hub.ts +73 -0
- package/lib/tower-launch.ts +111 -0
- package/lib/tower-open.ts +99 -0
- package/lib/tower-presence.ts +70 -0
- package/lib/tower-server.ts +234 -0
- package/lib/tower-snapshot.ts +298 -0
- package/lib/update-status.ts +238 -0
- package/lib/verifier-settle-reminder.ts +1 -1
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +6 -1
- package/package.json +14 -5
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +39 -0
- package/runtime/gentle-shell-bundled.mjs +100 -9
- package/runtime/gentle-shell-desktop.mjs +1371 -0
- package/runtime/gentle-shell-launcher.mjs +44 -2
- package/runtime/native-review-cli.mjs +86 -4
- package/runtime/review-integration-v2.mjs +56 -3
- package/runtime/tower-actions.mjs +101 -0
- package/runtime/tower-hub.mjs +74 -0
- package/runtime/tower-launch.mjs +112 -0
- package/runtime/tower-open.mjs +100 -0
- package/runtime/tower-presence.mjs +71 -0
- package/runtime/tower-server.mjs +234 -0
- package/runtime/tower-snapshot.mjs +299 -0
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +5 -21
- package/scripts/build-runtime-modules.mjs +10 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/gentle-ai-proxy.mjs +1 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +28 -17
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-server.mjs +38 -9
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +61 -20
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +6 -6
- package/skills/gentle-ai/SKILL.md +5 -5
- package/skills/judgment-day/SKILL.md +2 -2
- package/skills/judgment-day/references/prompts-and-formats.md +1 -1
- package/skills/provider-defect-report/SKILL.md +61 -0
- package/skills/rdd-defect-workflow/SKILL.md +6 -6
- package/skills/skill-improver/SKILL.md +2 -2
- package/skills/skill-registry/SKILL.md +11 -13
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +5 -5
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
- package/tests/agent-tool-overlay.test.ts +89 -0
- package/tests/agents-config.test.ts +10 -1
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner.test.ts +37 -1
- package/tests/agents-session-transport.test.ts +34 -0
- package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
- package/tests/append-system-prompt-route.test.ts +26 -7
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-choice.test.ts +78 -21
- package/tests/ask-user-question.test.ts +61 -6
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/auto-permission-answers.test.ts +12 -1
- package/tests/background-jobs.test.ts +12 -0
- package/tests/bounded-stop-contract.test.ts +148 -27
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bundled-install.test.ts +1 -1
- package/tests/change-diff.test.ts +75 -0
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/commit-slice-signal.test.ts +3 -2
- package/tests/decision-routing-contract.test.ts +390 -0
- package/tests/delegate-for-reason-contract.test.ts +30 -8
- package/tests/delegated-key-learnings-contract.test.ts +21 -28
- package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
- package/tests/delivery-conflict-markers.test.ts +348 -0
- package/tests/design-canvas-all-sizes.test.ts +631 -0
- package/tests/design-canvas-allowlist.test.ts +32 -0
- package/tests/design-canvas-assets.test.ts +11 -878
- package/tests/design-canvas-boards.test.ts +77 -0
- package/tests/design-canvas-checks.test.ts +655 -0
- package/tests/design-canvas-compare.test.ts +79 -0
- package/tests/design-canvas-events.test.ts +59 -0
- package/tests/design-canvas-export.test.ts +1168 -0
- package/tests/design-canvas-focus.test.ts +113 -0
- package/tests/design-canvas-handoffs.test.ts +59 -0
- package/tests/design-canvas-i18n-review.test.ts +513 -0
- package/tests/design-canvas-i18n-views.test.ts +259 -0
- package/tests/design-canvas-i18n.test.ts +528 -0
- package/tests/design-canvas-inspector.test.ts +1004 -0
- package/tests/design-canvas-layout.test.ts +1222 -0
- package/tests/design-canvas-minimap.test.ts +413 -0
- package/tests/design-canvas-modules.test.ts +91 -0
- package/tests/design-canvas-parts.test.ts +721 -0
- package/tests/design-canvas-rail.test.ts +799 -0
- package/tests/design-canvas-server.test.ts +855 -17
- package/tests/design-canvas-sizes.test.ts +548 -0
- package/tests/design-canvas-store.test.ts +189 -0
- package/tests/design-canvas-theme.test.ts +198 -0
- package/tests/design-canvas-tokens.test.ts +965 -0
- package/tests/design-canvas-view.test.ts +299 -0
- package/tests/design-comments.test.ts +201 -1
- package/tests/design-handoffs.test.ts +20 -0
- package/tests/design-layout.test.ts +100 -0
- package/tests/design-parts.test.ts +260 -0
- package/tests/design-system-tokens.test.ts +215 -0
- package/tests/desktop-feed-actions-guards.test.ts +595 -0
- package/tests/desktop-feed-actions.test.ts +761 -0
- package/tests/desktop-feed-live-work.test.ts +209 -0
- package/tests/desktop-feed-performance.test.ts +369 -0
- package/tests/desktop-feed-plan-profiles.test.ts +509 -0
- package/tests/desktop-feed-send-prompt.test.ts +303 -0
- package/tests/desktop-feed-tool-summaries.test.ts +69 -0
- package/tests/desktop-feed.test.ts +615 -0
- package/tests/desktop-rpc-agents.test.ts +1319 -0
- package/tests/desktop-rpc-changes.test.ts +608 -0
- package/tests/desktop-rpc-config-watch.test.ts +1159 -0
- package/tests/desktop-rpc-config.test.ts +1462 -0
- package/tests/desktop-rpc-design.test.ts +672 -0
- package/tests/desktop-rpc-jobs.test.ts +1193 -0
- package/tests/desktop-rpc-permissions.test.ts +321 -0
- package/tests/desktop-rpc-profiles.test.ts +140 -0
- package/tests/desktop-rpc-review.test.ts +678 -0
- package/tests/desktop-rpc-safety.test.ts +119 -0
- package/tests/desktop-rpc-session.test.ts +642 -0
- package/tests/desktop-rpc-sessions.test.ts +647 -0
- package/tests/desktop-rpc-stats.test.ts +431 -0
- package/tests/desktop-rpc-updates.test.ts +525 -0
- package/tests/desktop-rpc-usage.test.ts +707 -0
- package/tests/desktop-rpc.test.ts +293 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +30 -41
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/fixtures/session-profile-v1/replay.ts +4 -1
- package/tests/full-delegation-closure.test.ts +48 -0
- package/tests/gentle-agents.test.ts +848 -8
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +195 -21
- package/tests/gentle-design.test.ts +365 -1
- package/tests/gentle-fast.test.ts +15 -0
- package/tests/gentle-herdr-desktop-status.test.ts +595 -0
- package/tests/gentle-shell-bundled.test.ts +91 -5
- package/tests/gentle-shell-desktop-bin.test.ts +125 -0
- package/tests/gentle-shell-desktop.test.ts +927 -0
- package/tests/gentle-shell-launcher-tower.test.ts +104 -0
- package/tests/gentle-shell-launcher.test.ts +1 -1
- package/tests/gentle-shell.test.ts +121 -87
- package/tests/gentle-todo.test.ts +32 -9
- package/tests/gentle-tower.test.ts +578 -0
- package/tests/herdr-desktop-status.test.ts +285 -0
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/independent-recovery-delivery.test.ts +35 -9
- package/tests/inprocess-reviewer.test.ts +73 -0
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +114 -13
- package/tests/installer-preflight.test.ts +49 -1
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-server.test.ts +203 -4
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/judgment-day-severity-admission.test.ts +46 -0
- package/tests/lazy-module-contradictions-contract.test.ts +181 -0
- package/tests/maintainer/desktop-rpc.maintest.ts +907 -0
- package/tests/maintainer/pi-update-source.maintest.ts +48 -18
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-review-capability-contract.test.ts +19 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-parity.test.ts +24 -5
- package/tests/native-review-refusal-identity.test.ts +25 -0
- package/tests/no-self-pause-contract.test.ts +33 -15
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
- package/tests/odd-routing-contract.test.ts +99 -31
- package/tests/orchestrator-budget.test.ts +32 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +2 -1
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-prompt-budget.test.ts +12 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +249 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -1
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +15 -14
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +200 -30
- package/tests/persona-neutral-voseo.test.ts +4 -4
- package/tests/persona-reply-language.test.ts +1 -1
- package/tests/persona-single-channel.test.ts +13 -5
- package/tests/pi-routing-measured-values.test.ts +24 -0
- package/tests/pi-update-launcher.test.ts +17 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-policy.test.ts +47 -0
- package/tests/primary-context-files.test.ts +233 -0
- package/tests/primary-context-three-files.test.ts +174 -0
- package/tests/primary-session-prompt.test.ts +25 -0
- package/tests/profile-fast-tier.test.ts +66 -1
- package/tests/provider-defect-handoff.test.ts +124 -99
- package/tests/rdd-aware-verification-contract.test.ts +1 -1
- package/tests/rdd-status-line.test.ts +94 -1
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +17 -1
- package/tests/request-context-append-only.test.ts +218 -0
- package/tests/request-context-placement.test.ts +148 -0
- package/tests/review-agent-end-preflight.test.ts +79 -1
- package/tests/review-candidate-view.test.ts +65 -0
- package/tests/review-continuation-registry.test.ts +31 -0
- package/tests/review-contract-prompt.test.ts +2 -1
- package/tests/review-controller.test.ts +2 -1
- package/tests/review-coordinator-correction-gate.test.ts +105 -0
- package/tests/review-coordinator-findings.test.ts +206 -0
- package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
- package/tests/review-coordinator.test.ts +271 -4
- package/tests/review-delivery-preflight.test.ts +462 -0
- package/tests/review-due-compaction.test.ts +31 -0
- package/tests/review-due-public-boundary.test.ts +27 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-json-arguments.test.ts +41 -2
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
- package/tests/review-one-call-findings.test.ts +131 -0
- package/tests/review-one-call-followups.test.ts +308 -0
- package/tests/review-one-call-reviewer-requests.test.ts +207 -0
- package/tests/review-one-call.test.ts +452 -0
- package/tests/review-relay-transport-agent.test.ts +28 -1
- package/tests/review-reviewer-evidence.test.ts +41 -1
- package/tests/review-risk-assessment.test.ts +52 -5
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +32 -2
- package/tests/review-tool-prose-budget.test.ts +1 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/sensitive-path-tools.test.ts +138 -4
- package/tests/session-profile-extension.test.ts +312 -18
- package/tests/session-profile-freeze.test.ts +26 -0
- package/tests/session-profile-v1-compat.test.ts +20 -0
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-usage.test.ts +59 -10
- package/tests/skill-collision-prefixes.test.ts +1 -0
- package/tests/skill-contradictions-contract.test.ts +124 -0
- package/tests/skill-registry-watcher.test.ts +216 -2
- package/tests/skill-registry.test.ts +983 -306
- package/tests/stats-collector.test.ts +109 -2
- package/tests/support/design-canvas-dom.ts +386 -0
- package/tests/support/review-coordinator-runtime.ts +212 -17
- package/tests/task-size-routing-contract.test.ts +49 -14
- package/tests/test-strength-contract.test.ts +2 -1
- package/tests/todo-request-append-only.test.ts +214 -0
- package/tests/tool-batching-contract.test.ts +3 -1
- package/tests/tower-actions.test.ts +247 -0
- package/tests/tower-artifacts.test.ts +114 -0
- package/tests/tower-open.test.ts +97 -0
- package/tests/tower-presence.test.ts +175 -0
- package/tests/tower-server.test.ts +122 -0
- package/tests/tower-snapshot.test.ts +236 -0
- package/tests/tower-web-echo.test.ts +125 -0
- package/tests/tower-web-hover.test.ts +251 -0
- package/tests/update-agent-body-history.test.ts +138 -0
- package/tests/verification-scoped-stop-contract.test.ts +32 -0
- package/tests/verification-tiers-contract.test.ts +229 -0
- package/tests/verifier-preparation.test.ts +229 -0
- package/tests/verifier-settle-reminder.test.ts +2 -2
- package/tests/verify-agent-contract.test.ts +20 -2
- package/tests/verify-first-launch-contract.test.ts +88 -12
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +136 -27
- package/tests/writer-admission-messages.test.ts +232 -0
- package/tests/writer-batch-admission.test.ts +66 -0
- package/tests/writer-edit-surface-scope.test.ts +52 -20
- package/tests/writer-feature-document-admission.test.ts +184 -0
- package/tests/writer-rejection-next-step.test.ts +55 -0
- package/tests/writer-surface-authority-contract.test.ts +158 -0
- package/tests/yolo-mode.test.ts +39 -0
- package/skills/_shared/review-ledger-contract.md +0 -106
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
package/lib/design-comments.ts
CHANGED
|
@@ -11,6 +11,11 @@ import { extname, join, sep } from "node:path";
|
|
|
11
11
|
export const DESIGN_COMMENTS_FILE = "comments.json";
|
|
12
12
|
export const MAX_DESIGN_COMMENTS = 500;
|
|
13
13
|
export const DESIGN_COMMENT_LIMITS = Object.freeze({ comment: 2000, selector: 500, excerpt: 300 });
|
|
14
|
+
/** The size a comment was made at (S7): whole CSS px, inclusive. */
|
|
15
|
+
export const DESIGN_VIEWPORT_LIMITS = Object.freeze({ minWidth: 240, maxWidth: 4096, minHeight: 1, maxHeight: 20000 });
|
|
16
|
+
|
|
17
|
+
/** The longest one-line note: the agent's reply on a resolved comment. */
|
|
18
|
+
export const DESIGN_NOTE_LIMIT = 500;
|
|
14
19
|
|
|
15
20
|
const SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
16
21
|
const ID = /^[A-Za-z0-9_-]{1,32}$/;
|
|
@@ -43,17 +48,61 @@ export type StoredDesignComment = {
|
|
|
43
48
|
resolvedAt: string | null;
|
|
44
49
|
/** `.screenshots/<id>.<ext>`, relative to the design directory; absent when the comment has none. */
|
|
45
50
|
screenshot?: string;
|
|
51
|
+
/** Set only when the comment was made at a size other than the artboard's own. */
|
|
52
|
+
viewport?: DesignViewport;
|
|
53
|
+
/** The agent's one-line note from resolving the comment; absent when it gave none and cleared on reopen. */
|
|
54
|
+
resolution?: string;
|
|
46
55
|
};
|
|
47
56
|
|
|
57
|
+
/** The CSS-px size of the artboard when the comment was made; absent at the artboard's own size. */
|
|
58
|
+
export type DesignViewport = { width: number; height: number };
|
|
59
|
+
|
|
60
|
+
const VIEWPORT_PRESETS: ReadonlyArray<DesignViewport & { name: string }> = [
|
|
61
|
+
{ name: "Phone", width: 390, height: 844 },
|
|
62
|
+
{ name: "Tablet", width: 820, height: 1180 },
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
/** `Phone 390 × 844`, `Tablet 820 × 1180`, or `<w> × <h>`; the same words the canvas card shows. */
|
|
66
|
+
export function describeViewport(viewport: DesignViewport): string {
|
|
67
|
+
const size = `${viewport.width} × ${viewport.height}`;
|
|
68
|
+
const preset = VIEWPORT_PRESETS.find((candidate) => candidate.width === viewport.width && candidate.height === viewport.height);
|
|
69
|
+
return preset ? `${preset.name} ${size}` : size;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Why `value` is not a viewport `{ width, height }` of whole px within the limits, or undefined when it is one. */
|
|
73
|
+
export function viewportProblem(value: unknown): string | undefined {
|
|
74
|
+
const { minWidth, maxWidth, minHeight, maxHeight } = DESIGN_VIEWPORT_LIMITS;
|
|
75
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return "viewport must be an object with width and height";
|
|
76
|
+
const { width, height } = value as Record<string, unknown>;
|
|
77
|
+
if (!Number.isInteger(width) || (width as number) < minWidth || (width as number) > maxWidth) return `viewport width must be a whole number from ${minWidth} to ${maxWidth}`;
|
|
78
|
+
if (!Number.isInteger(height) || (height as number) < minHeight || (height as number) > maxHeight) return `viewport height must be a whole number from ${minHeight} to ${maxHeight}`;
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Why `value` is not a note of at most DESIGN_NOTE_LIMIT characters, or undefined when it is one. */
|
|
83
|
+
export function noteProblem(value: unknown): string | undefined {
|
|
84
|
+
if (typeof value !== "string") return "note must be a string";
|
|
85
|
+
if (value.length > DESIGN_NOTE_LIMIT) return `note must have at most ${DESIGN_NOTE_LIMIT} characters`;
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The one-line resolution note: every line break, with the whitespace around it, becomes one space and the outer
|
|
91
|
+
* whitespace is trimmed (spaces inside a line are kept); undefined when nothing is left.
|
|
92
|
+
*/
|
|
93
|
+
export function normalizeNote(value: string): string | undefined {
|
|
94
|
+
return value.split(/[\r\n\u2028\u2029]/).map((line) => line.trim()).filter(Boolean).join(" ") || undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
48
97
|
export type DesignCommentsDocument = { version: 1; comments: StoredDesignComment[] };
|
|
49
98
|
|
|
50
99
|
export type DesignScreenshotInput = { mimeType: string; data: Buffer };
|
|
51
100
|
|
|
52
|
-
export type DesignCommentInput = { file: string; selector: string; excerpt: string; comment: string; screenshot?: DesignScreenshotInput };
|
|
101
|
+
export type DesignCommentInput = { file: string; selector: string; excerpt: string; comment: string; screenshot?: DesignScreenshotInput; viewport?: DesignViewport };
|
|
53
102
|
|
|
54
103
|
export type DesignScreenshot = { path: string; mimeType: string; data: Buffer };
|
|
55
104
|
|
|
56
|
-
export type DesignCommentsErrorCode = "not-found" | "invalid-file" | "invalid-input" | "limit" | "id-exhausted";
|
|
105
|
+
export type DesignCommentsErrorCode = "not-found" | "invalid-file" | "invalid-input" | "limit" | "id-exhausted" | "locked";
|
|
57
106
|
|
|
58
107
|
export class DesignCommentsError extends Error {
|
|
59
108
|
readonly code: DesignCommentsErrorCode;
|
|
@@ -73,9 +122,12 @@ export interface DesignCommentStore {
|
|
|
73
122
|
/** The design's comments; a missing comments.json is an empty document. */
|
|
74
123
|
read(slug: string): Promise<DesignCommentsDocument>;
|
|
75
124
|
add(slug: string, input: DesignCommentInput): Promise<StoredDesignComment>;
|
|
76
|
-
|
|
125
|
+
/** `note` (resolve only) is stored as the comments' `resolution`; reopening clears it. */
|
|
126
|
+
setStatus(slug: string, ids: readonly string[], status: DesignCommentStatus, options?: { note?: string }): Promise<{ updated: StoredDesignComment[]; unknown: string[] }>;
|
|
77
127
|
/** Stamps sentAt on comments that have none yet. */
|
|
78
128
|
markSent(slug: string, ids: readonly string[]): Promise<StoredDesignComment[]>;
|
|
129
|
+
/** Replaces the text of an open comment, sent or not, and returns the text it had; `locked` when resolved, `not-found` for an unknown id. */
|
|
130
|
+
setText(slug: string, id: string, text: string): Promise<{ comment: StoredDesignComment; previous: string }>;
|
|
79
131
|
listOpen(slug: string, file?: string): Promise<StoredDesignComment[]>;
|
|
80
132
|
/** The screenshot of comment `id`, or undefined when there is no such comment, it has none, or the file is gone. */
|
|
81
133
|
readScreenshot(slug: string, id: string): Promise<DesignScreenshot | undefined>;
|
|
@@ -194,6 +246,7 @@ function inputProblem(input: DesignCommentInput): string | undefined {
|
|
|
194
246
|
if (typeof input.selector !== "string" || input.selector.length < 1 || input.selector.length > DESIGN_COMMENT_LIMITS.selector) return `selector must have 1 to ${DESIGN_COMMENT_LIMITS.selector} characters`;
|
|
195
247
|
if (typeof input.excerpt !== "string" || input.excerpt.length > DESIGN_COMMENT_LIMITS.excerpt) return `excerpt must have at most ${DESIGN_COMMENT_LIMITS.excerpt} characters`;
|
|
196
248
|
if (typeof input.comment !== "string" || input.comment.length < 1 || input.comment.length > DESIGN_COMMENT_LIMITS.comment) return `comment must have 1 to ${DESIGN_COMMENT_LIMITS.comment} characters`;
|
|
249
|
+
if (input.viewport !== undefined) return viewportProblem(input.viewport);
|
|
197
250
|
return undefined;
|
|
198
251
|
}
|
|
199
252
|
|
|
@@ -247,6 +300,10 @@ function parseDocument(raw: string): DesignCommentsDocument {
|
|
|
247
300
|
if (item.screenshot !== undefined && (typeof item.screenshot !== "string" || !SCREENSHOT_PATH.test(item.screenshot))) {
|
|
248
301
|
throw new DesignCommentsError("invalid-file", `${where}.screenshot must be a .screenshots/<id>.<png|jpg|webp|gif> path`);
|
|
249
302
|
}
|
|
303
|
+
if (item.resolution !== undefined) {
|
|
304
|
+
const problem = noteProblem(item.resolution);
|
|
305
|
+
if (problem) throw new DesignCommentsError("invalid-file", `${where}.resolution: ${problem}`);
|
|
306
|
+
}
|
|
250
307
|
const comment: StoredDesignComment = {
|
|
251
308
|
id: item.id,
|
|
252
309
|
file: item.file as string,
|
|
@@ -259,6 +316,8 @@ function parseDocument(raw: string): DesignCommentsDocument {
|
|
|
259
316
|
resolvedAt: item.resolvedAt as string | null,
|
|
260
317
|
};
|
|
261
318
|
if (typeof item.screenshot === "string") comment.screenshot = item.screenshot;
|
|
319
|
+
if (item.viewport !== undefined) comment.viewport = { width: (item.viewport as DesignViewport).width, height: (item.viewport as DesignViewport).height };
|
|
320
|
+
if (typeof item.resolution === "string") comment.resolution = item.resolution;
|
|
262
321
|
return comment;
|
|
263
322
|
});
|
|
264
323
|
return { version: 1, comments };
|
|
@@ -350,6 +409,7 @@ export function createDesignCommentStore(designRoot: string, deps: DesignComment
|
|
|
350
409
|
sentAt: null,
|
|
351
410
|
resolvedAt: null,
|
|
352
411
|
};
|
|
412
|
+
if (input.viewport) comment.viewport = { width: input.viewport.width, height: input.viewport.height };
|
|
353
413
|
let image: string | undefined;
|
|
354
414
|
if (input.screenshot) {
|
|
355
415
|
const name = `${id}.${DESIGN_SCREENSHOT_TYPES[input.screenshot.mimeType]}`;
|
|
@@ -369,9 +429,14 @@ export function createDesignCommentStore(designRoot: string, deps: DesignComment
|
|
|
369
429
|
});
|
|
370
430
|
},
|
|
371
431
|
|
|
372
|
-
async setStatus(slug, ids, status) {
|
|
432
|
+
async setStatus(slug, ids, status, options) {
|
|
373
433
|
if (status !== "open" && status !== "resolved") throw new DesignCommentsError("invalid-input", 'status must be "open" or "resolved"');
|
|
374
434
|
if (!Array.isArray(ids) || ids.some((id) => typeof id !== "string")) throw new DesignCommentsError("invalid-input", "ids must be an array of strings");
|
|
435
|
+
if (options?.note !== undefined) {
|
|
436
|
+
const problem = status === "resolved" ? noteProblem(options.note) : "a note can only accompany resolving a comment";
|
|
437
|
+
if (problem) throw new DesignCommentsError("invalid-input", problem);
|
|
438
|
+
}
|
|
439
|
+
const note = options?.note === undefined ? undefined : normalizeNote(options.note);
|
|
375
440
|
return mutate(slug, (document) => {
|
|
376
441
|
const wanted = new Set(ids);
|
|
377
442
|
const updated: StoredDesignComment[] = [];
|
|
@@ -383,6 +448,14 @@ export function createDesignCommentStore(designRoot: string, deps: DesignComment
|
|
|
383
448
|
comment.resolvedAt = status === "resolved" ? now().toISOString() : null;
|
|
384
449
|
write = true;
|
|
385
450
|
}
|
|
451
|
+
if (status === "open" && comment.resolution !== undefined) {
|
|
452
|
+
delete comment.resolution;
|
|
453
|
+
write = true;
|
|
454
|
+
}
|
|
455
|
+
if (note !== undefined && comment.resolution !== note) {
|
|
456
|
+
comment.resolution = note;
|
|
457
|
+
write = true;
|
|
458
|
+
}
|
|
386
459
|
updated.push(comment);
|
|
387
460
|
}
|
|
388
461
|
const found = new Set(updated.map((comment) => comment.id));
|
|
@@ -403,6 +476,23 @@ export function createDesignCommentStore(designRoot: string, deps: DesignComment
|
|
|
403
476
|
});
|
|
404
477
|
},
|
|
405
478
|
|
|
479
|
+
async setText(slug, id, raw) {
|
|
480
|
+
// Normalized here, like a new comment, so every caller stores the same text.
|
|
481
|
+
const text = typeof raw === "string" ? raw.replace(/\r\n?/g, "\n").trim() : "";
|
|
482
|
+
if (text.length < 1 || text.length > DESIGN_COMMENT_LIMITS.comment) {
|
|
483
|
+
throw new DesignCommentsError("invalid-input", `comment must have 1 to ${DESIGN_COMMENT_LIMITS.comment} characters`);
|
|
484
|
+
}
|
|
485
|
+
return mutate(slug, (document) => {
|
|
486
|
+
const comment = document.comments.find((candidate) => candidate.id === id);
|
|
487
|
+
if (!comment) throw new DesignCommentsError("not-found", `design/${slug} has no comment ${id}`);
|
|
488
|
+
// A resolved comment is done; reopen it to change it.
|
|
489
|
+
if (comment.status !== "open") throw new DesignCommentsError("locked", `comment ${id} is resolved, so its text can no longer change; reopen it first`);
|
|
490
|
+
const previous = comment.comment;
|
|
491
|
+
comment.comment = text;
|
|
492
|
+
return { result: { comment, previous }, write: previous !== text };
|
|
493
|
+
});
|
|
494
|
+
},
|
|
495
|
+
|
|
406
496
|
async readScreenshot(slug, id) {
|
|
407
497
|
const { dir, path } = await locate(slug);
|
|
408
498
|
const stored = (await load(path)).comments.find((comment) => comment.id === id);
|
package/lib/design-handoffs.ts
CHANGED
|
@@ -252,7 +252,8 @@ export function createDesignHandoffStore(designRoot: string, deps: DesignHandoff
|
|
|
252
252
|
const entry = entryOf({
|
|
253
253
|
...base,
|
|
254
254
|
status,
|
|
255
|
-
|
|
255
|
+
// A repeated in_progress report keeps the first start; taking up a sent or implemented handoff starts it again.
|
|
256
|
+
startedAt: status === "in_progress" ? (current?.status === "in_progress" ? current.startedAt ?? stamp : stamp) : base.startedAt,
|
|
256
257
|
implementedAt: status === "implemented" ? stamp : null,
|
|
257
258
|
note: cleanNote,
|
|
258
259
|
previewUrl: preview,
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { isArtboardPath, locateDesignFile, readDesignFile, replaceDesignFile, serializeDesignWrite } from "./design-comments.ts";
|
|
2
|
+
|
|
3
|
+
// The single owner of design/<slug>/layout.json (canvas-layout S3): where each artboard sits on the canvas and the
|
|
4
|
+
// arrangement last chosen. Only the canvas server writes it, after validating the whole document, through the same
|
|
5
|
+
// per-file queue and temp file + rename as comments.json. It is view state, not design content: a file this module
|
|
6
|
+
// cannot read or parse is never an error that stops the canvas, and the next save replaces it. `load` tells such a
|
|
7
|
+
// file apart from a missing one (the server answers it as an error, so the canvas keeps the layout it shows);
|
|
8
|
+
// `read` takes both as no layout.
|
|
9
|
+
|
|
10
|
+
export const DESIGN_LAYOUT_FILE = "layout.json";
|
|
11
|
+
export const DESIGN_LAYOUT_ARRANGEMENTS = ["row", "column", "grid", "free"] as const;
|
|
12
|
+
/** The key of design/system.html, the first board of every design; never an artboard path, which ends in .html. */
|
|
13
|
+
export const DESIGN_LAYOUT_SYSTEM_KEY = "system";
|
|
14
|
+
/** The most positions one layout keeps: every artboard a manifest may list (64) and the system board, with room. */
|
|
15
|
+
export const DESIGN_LAYOUT_MAX_POSITIONS = 100;
|
|
16
|
+
/** The farthest a board may sit from the origin, in canvas px on each axis: a row or column of the largest artboards fits. */
|
|
17
|
+
export const DESIGN_LAYOUT_COORDINATE_MAX = 2_000_000;
|
|
18
|
+
const MAX_FILE_BYTES = 256 * 1024;
|
|
19
|
+
|
|
20
|
+
export type DesignLayoutArrangement = (typeof DESIGN_LAYOUT_ARRANGEMENTS)[number];
|
|
21
|
+
export type DesignLayoutPosition = { x: number; y: number };
|
|
22
|
+
export type DesignLayout = { arrangement: DesignLayoutArrangement; positions: Record<string, DesignLayoutPosition> };
|
|
23
|
+
|
|
24
|
+
export type DesignLayoutErrorCode = "not-found" | "invalid-input" | "invalid-file";
|
|
25
|
+
|
|
26
|
+
export class DesignLayoutError extends Error {
|
|
27
|
+
readonly code: DesignLayoutErrorCode;
|
|
28
|
+
constructor(code: DesignLayoutErrorCode, message: string) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = "DesignLayoutError";
|
|
31
|
+
this.code = code;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DesignLayoutStore {
|
|
36
|
+
/** The design's layout; null when layout.json is missing, unreadable or invalid. */
|
|
37
|
+
read(slug: string): Promise<DesignLayout | null>;
|
|
38
|
+
/**
|
|
39
|
+
* The design's layout; null only when layout.json is missing. A layout.json that is a link, a directory, too large,
|
|
40
|
+
* fails to read or holds no valid layout throws an "invalid-file" error saying why; it is left as it is.
|
|
41
|
+
*/
|
|
42
|
+
load(slug: string): Promise<DesignLayout | null>;
|
|
43
|
+
/** Validates `value` as a whole layout and replaces layout.json with it; a refused value writes nothing. */
|
|
44
|
+
write(slug: string, value: unknown): Promise<DesignLayout>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const isCoordinate = (value: unknown): value is number => Number.isInteger(value) && Math.abs(value as number) <= DESIGN_LAYOUT_COORDINATE_MAX;
|
|
48
|
+
|
|
49
|
+
/** The layout `value` describes, with its keys in a stable order; throws the first problem in words. */
|
|
50
|
+
export function parseDesignLayout(value: unknown): DesignLayout {
|
|
51
|
+
const invalid = (message: string) => new DesignLayoutError("invalid-input", message);
|
|
52
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalid("layout must be a JSON object");
|
|
53
|
+
const record = value as Record<string, unknown>;
|
|
54
|
+
const extra = Object.keys(record).filter((key) => key !== "arrangement" && key !== "positions");
|
|
55
|
+
if (extra.length > 0) throw invalid(`layout has unknown keys: ${extra.join(", ")}`);
|
|
56
|
+
if (!DESIGN_LAYOUT_ARRANGEMENTS.includes(record.arrangement as DesignLayoutArrangement)) throw invalid('arrangement must be "row", "column", "grid" or "free"');
|
|
57
|
+
const raw = record.positions;
|
|
58
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw invalid("positions must be an object");
|
|
59
|
+
const entries = Object.entries(raw as Record<string, unknown>);
|
|
60
|
+
if (entries.length > DESIGN_LAYOUT_MAX_POSITIONS) throw invalid(`positions may hold at most ${DESIGN_LAYOUT_MAX_POSITIONS} boards`);
|
|
61
|
+
const positions: Record<string, DesignLayoutPosition> = {};
|
|
62
|
+
for (const [key, position] of entries) {
|
|
63
|
+
if (key !== DESIGN_LAYOUT_SYSTEM_KEY && !isArtboardPath(key)) throw invalid(`positions keys must be relative .html artboard paths or "${DESIGN_LAYOUT_SYSTEM_KEY}"`);
|
|
64
|
+
if (!position || typeof position !== "object" || Array.isArray(position)) throw invalid(`positions["${key}"] must be an object with x and y`);
|
|
65
|
+
const { x, y, ...rest } = position as Record<string, unknown>;
|
|
66
|
+
if (Object.keys(rest).length > 0) throw invalid(`positions["${key}"] may hold only x and y`);
|
|
67
|
+
if (!isCoordinate(x) || !isCoordinate(y)) throw invalid(`positions["${key}"] x and y must be integers between -${DESIGN_LAYOUT_COORDINATE_MAX} and ${DESIGN_LAYOUT_COORDINATE_MAX}`);
|
|
68
|
+
positions[key] = { x, y };
|
|
69
|
+
}
|
|
70
|
+
return { arrangement: record.arrangement as DesignLayoutArrangement, positions };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function createDesignLayoutStore(designRoot: string): DesignLayoutStore {
|
|
74
|
+
function locate(slug: string): Promise<{ dir: string; path: string }> {
|
|
75
|
+
return locateDesignFile(designRoot, slug, DESIGN_LAYOUT_FILE, (message) => new DesignLayoutError("not-found", message));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function load(slug: string): Promise<DesignLayout | null> {
|
|
79
|
+
const missing = `No design "${slug}" in design/.`;
|
|
80
|
+
const unreadable = (reason: string) => new DesignLayoutError("invalid-file", reason);
|
|
81
|
+
let raw: string | undefined;
|
|
82
|
+
try {
|
|
83
|
+
const { path } = await locate(slug);
|
|
84
|
+
raw = await readDesignFile(path, MAX_FILE_BYTES, () => unreadable(`larger than ${MAX_FILE_BYTES} bytes`));
|
|
85
|
+
} catch (error) {
|
|
86
|
+
// Only a missing design is not found; a layout.json that is a link or a directory is no file to read.
|
|
87
|
+
if (error instanceof DesignLayoutError && (error.message === missing || error.code === "invalid-file")) throw error;
|
|
88
|
+
if (error instanceof DesignLayoutError) throw unreadable("not a regular file");
|
|
89
|
+
const code = error && typeof error === "object" && typeof (error as { code?: unknown }).code === "string" ? (error as { code: string }).code : "";
|
|
90
|
+
throw unreadable(code ? `read error ${code}` : "read error");
|
|
91
|
+
}
|
|
92
|
+
if (raw === undefined) return null;
|
|
93
|
+
let value: unknown;
|
|
94
|
+
try {
|
|
95
|
+
value = JSON.parse(raw);
|
|
96
|
+
} catch {
|
|
97
|
+
throw unreadable("not valid JSON");
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
return parseDesignLayout(value);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw unreadable((error as Error).message);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
load,
|
|
108
|
+
|
|
109
|
+
async read(slug) {
|
|
110
|
+
try {
|
|
111
|
+
return await load(slug);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error instanceof DesignLayoutError && error.code === "invalid-file") return null;
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
async write(slug, value) {
|
|
119
|
+
const layout = parseDesignLayout(value);
|
|
120
|
+
const { dir, path } = await locate(slug);
|
|
121
|
+
await serializeDesignWrite(path, () => replaceDesignFile(dir, path, DESIGN_LAYOUT_FILE, `${JSON.stringify(layout, null, 2)}\n`));
|
|
122
|
+
return layout;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { isArtboardPath, locateDesignFile, readDesignFile, replaceDesignFile, serializeDesignWrite, truncateUtf16 } from "./design-comments.ts";
|
|
3
|
+
import type { DesignHandoffDelivery } from "./design-handoffs.ts";
|
|
4
|
+
|
|
5
|
+
// The single owner of design/<slug>/parts.json (canvas-implement-part): the parts of artboards handed to the session
|
|
6
|
+
// one at a time ("Implement only this"), each with the agent's progress. Unlike handoffs.json it never chooses an
|
|
7
|
+
// artboard, so the other directions stay open. The canvas server and the gentle_design tool write through this module,
|
|
8
|
+
// in the same per-file queue as comments.json and handoffs.json, re-reading the file before every write and replacing
|
|
9
|
+
// it with a temp file + rename. A file this module cannot parse is reported and never overwritten.
|
|
10
|
+
// "Remove" on the canvas (removeSent) clears a part the agent never reported: only a part still `sent` (queued or not),
|
|
11
|
+
// so a part the agent took up or finished keeps its record; every refusal leaves the file byte for byte.
|
|
12
|
+
// The file holds at most 1 MiB: the serialized document is measured before the file is replaced, so a write that would
|
|
13
|
+
// pass it is refused (`too-large`) and the previous file, which Remove can still repair, stays as it was.
|
|
14
|
+
|
|
15
|
+
export const DESIGN_PARTS_FILE = "parts.json";
|
|
16
|
+
/** The most parts one design keeps. */
|
|
17
|
+
export const DESIGN_PARTS_MAX = 100;
|
|
18
|
+
export const DESIGN_PART_SELECTOR_LIMIT = 500;
|
|
19
|
+
export const DESIGN_PART_EXCERPT_LIMIT = 300;
|
|
20
|
+
/** The user's note on the part, like a comment. */
|
|
21
|
+
export const DESIGN_PART_INSTRUCTION_LIMIT = 2000;
|
|
22
|
+
/** The agent's progress note, like a handoff's. */
|
|
23
|
+
export const DESIGN_PART_NOTE_LIMIT = 1000;
|
|
24
|
+
const MAX_FILE_BYTES = 1024 * 1024;
|
|
25
|
+
const PART_ID = /^[a-z0-9]{1,32}$/;
|
|
26
|
+
|
|
27
|
+
export type DesignPartStatus = "sent" | "in_progress" | "implemented";
|
|
28
|
+
|
|
29
|
+
export type DesignPart = {
|
|
30
|
+
id: string;
|
|
31
|
+
file: string;
|
|
32
|
+
selector: string;
|
|
33
|
+
excerpt: string;
|
|
34
|
+
/** The user's note: what of the element to build, or how. Absent when none. */
|
|
35
|
+
instruction?: string;
|
|
36
|
+
status: DesignPartStatus;
|
|
37
|
+
/** The agent was busy when it was sent, so it waits as a follow-up. */
|
|
38
|
+
queued: boolean;
|
|
39
|
+
sentAt: string;
|
|
40
|
+
startedAt: string | null;
|
|
41
|
+
implementedAt: string | null;
|
|
42
|
+
/** The agent's last progress note. */
|
|
43
|
+
note?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type DesignPartsDocument = { version: 1; parts: DesignPart[] };
|
|
47
|
+
|
|
48
|
+
export type DesignPartInput = { file: string; selector: string; excerpt: string; instruction: string };
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* `not-sent`: removeSent was asked for a part the agent already reported (in_progress or implemented).
|
|
52
|
+
* `too-large`: the write would make parts.json larger than 1 MiB; nothing was written.
|
|
53
|
+
*/
|
|
54
|
+
export type DesignPartsErrorCode = "not-found" | "invalid-file" | "invalid-input" | "limit" | "not-sent" | "too-large";
|
|
55
|
+
|
|
56
|
+
export class DesignPartsError extends Error {
|
|
57
|
+
readonly code: DesignPartsErrorCode;
|
|
58
|
+
constructor(code: DesignPartsErrorCode, message: string) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "DesignPartsError";
|
|
61
|
+
this.code = code;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DesignPartStoreDeps {
|
|
66
|
+
now?: () => Date;
|
|
67
|
+
randomId?: () => string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface DesignPartStore {
|
|
71
|
+
/** The design's parts; a missing parts.json is an empty document. */
|
|
72
|
+
read(slug: string): Promise<DesignPartsDocument>;
|
|
73
|
+
/** A new part, status sent and not queued, appended after the others. */
|
|
74
|
+
add(slug: string, input: DesignPartInput): Promise<DesignPart>;
|
|
75
|
+
/** The agent's progress on part `id` of `file`; `note` becomes exactly what this call passes. */
|
|
76
|
+
setStatus(slug: string, file: string, id: string, status: Exclude<DesignPartStatus, "sent">, options: { note?: string }): Promise<DesignPart>;
|
|
77
|
+
/** Marks a still-sent part as queued; true when it was updated. */
|
|
78
|
+
markQueued(slug: string, id: string): Promise<boolean>;
|
|
79
|
+
/** Removes part `id` (a delivery that failed); true when it was there. */
|
|
80
|
+
remove(slug: string, id: string): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* The canvas "Remove": takes part `id` out when it is still `sent` (queued or not) and answers it. An unknown id is
|
|
83
|
+
* `not-found`, a part in progress or implemented is `not-sent`, a malformed id is `invalid-input`; none writes.
|
|
84
|
+
*/
|
|
85
|
+
removeSent(slug: string, id: string): Promise<DesignPart>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const collapse = (value: string) => value.replace(/\s+/g, " ").trim();
|
|
89
|
+
const normalizeText = (value: string) => value.replace(/\r\n?/g, "\n").trim();
|
|
90
|
+
|
|
91
|
+
function isTimestamp(value: unknown): value is string {
|
|
92
|
+
return typeof value === "string" && value.length > 0 && value.length <= 64;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function invalid(message: string): DesignPartsError {
|
|
96
|
+
return new DesignPartsError("invalid-file", message);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The part with its keys in a stable order and no absent optional keys. */
|
|
100
|
+
function partOf(fields: DesignPart): DesignPart {
|
|
101
|
+
return {
|
|
102
|
+
id: fields.id,
|
|
103
|
+
file: fields.file,
|
|
104
|
+
selector: fields.selector,
|
|
105
|
+
excerpt: fields.excerpt,
|
|
106
|
+
...(fields.instruction !== undefined ? { instruction: fields.instruction } : {}),
|
|
107
|
+
status: fields.status,
|
|
108
|
+
queued: fields.queued,
|
|
109
|
+
sentAt: fields.sentAt,
|
|
110
|
+
startedAt: fields.startedAt,
|
|
111
|
+
implementedAt: fields.implementedAt,
|
|
112
|
+
...(fields.note !== undefined ? { note: fields.note } : {}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function parsePart(where: string, value: unknown): DesignPart {
|
|
117
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalid(`${where} must be an object`);
|
|
118
|
+
const item = value as Record<string, unknown>;
|
|
119
|
+
if (typeof item.id !== "string" || !PART_ID.test(item.id)) throw invalid(`${where}.id must be 1 to 32 lowercase letters or digits`);
|
|
120
|
+
if (!isArtboardPath(item.file)) throw invalid(`${where}.file must be a relative .html artboard path`);
|
|
121
|
+
if (typeof item.selector !== "string" || item.selector.length < 1 || item.selector.length > DESIGN_PART_SELECTOR_LIMIT) throw invalid(`${where}.selector must have 1 to ${DESIGN_PART_SELECTOR_LIMIT} characters`);
|
|
122
|
+
if (typeof item.excerpt !== "string" || item.excerpt.length > DESIGN_PART_EXCERPT_LIMIT) throw invalid(`${where}.excerpt must be text of at most ${DESIGN_PART_EXCERPT_LIMIT} characters`);
|
|
123
|
+
if (item.instruction !== undefined && (typeof item.instruction !== "string" || item.instruction.length > DESIGN_PART_INSTRUCTION_LIMIT)) throw invalid(`${where}.instruction must be text of at most ${DESIGN_PART_INSTRUCTION_LIMIT} characters`);
|
|
124
|
+
if (item.status !== "sent" && item.status !== "in_progress" && item.status !== "implemented") throw invalid(`${where}.status must be "sent", "in_progress" or "implemented"`);
|
|
125
|
+
if (typeof item.queued !== "boolean") throw invalid(`${where}.queued must be true or false`);
|
|
126
|
+
if (!isTimestamp(item.sentAt)) throw invalid(`${where}.sentAt must be a timestamp`);
|
|
127
|
+
for (const key of ["startedAt", "implementedAt"] as const) {
|
|
128
|
+
if (item[key] !== null && !isTimestamp(item[key])) throw invalid(`${where}.${key} must be a timestamp or null`);
|
|
129
|
+
}
|
|
130
|
+
if (item.note !== undefined && (typeof item.note !== "string" || item.note.length > DESIGN_PART_NOTE_LIMIT)) throw invalid(`${where}.note must be text of at most ${DESIGN_PART_NOTE_LIMIT} characters`);
|
|
131
|
+
return partOf(item as unknown as DesignPart);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function parseDocument(raw: string): DesignPartsDocument {
|
|
135
|
+
let value: unknown;
|
|
136
|
+
try {
|
|
137
|
+
value = JSON.parse(raw);
|
|
138
|
+
} catch {
|
|
139
|
+
throw invalid("parts.json is not valid JSON");
|
|
140
|
+
}
|
|
141
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalid("parts.json must be a JSON object");
|
|
142
|
+
const record = value as Record<string, unknown>;
|
|
143
|
+
if (record.version !== 1) throw invalid("parts.json version must be 1");
|
|
144
|
+
if (!Array.isArray(record.parts)) throw invalid("parts.json parts must be a list");
|
|
145
|
+
if (record.parts.length > DESIGN_PARTS_MAX) throw invalid(`parts.json may hold at most ${DESIGN_PARTS_MAX} parts`);
|
|
146
|
+
const parts = record.parts.map((part, index) => parsePart(`parts[${index}]`, part));
|
|
147
|
+
if (new Set(parts.map((part) => part.id)).size !== parts.length) throw invalid("parts.json ids must be unique");
|
|
148
|
+
return { version: 1, parts };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function createDesignPartStore(designRoot: string, deps: DesignPartStoreDeps = {}): DesignPartStore {
|
|
152
|
+
const now = deps.now ?? (() => new Date());
|
|
153
|
+
const randomId = deps.randomId ?? (() => randomBytes(6).toString("hex"));
|
|
154
|
+
|
|
155
|
+
function locate(slug: string): Promise<{ dir: string; path: string }> {
|
|
156
|
+
return locateDesignFile(designRoot, slug, DESIGN_PARTS_FILE, (message) => new DesignPartsError("not-found", message));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function load(path: string): Promise<DesignPartsDocument> {
|
|
160
|
+
const raw = await readDesignFile(path, MAX_FILE_BYTES, () => invalid("parts.json is too large"));
|
|
161
|
+
return raw === undefined ? { version: 1, parts: [] } : parseDocument(raw);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Read-modify-write in the file's queue; `change` sets `write: false` when nothing changed. */
|
|
165
|
+
async function mutate<T>(slug: string, change: (document: DesignPartsDocument) => { result: T; write: boolean }): Promise<T> {
|
|
166
|
+
const { dir, path } = await locate(slug);
|
|
167
|
+
return serializeDesignWrite(path, async () => {
|
|
168
|
+
const document = await load(path);
|
|
169
|
+
const { result, write } = change(document);
|
|
170
|
+
if (!write) return result;
|
|
171
|
+
const content = `${JSON.stringify(document, null, 2)}\n`;
|
|
172
|
+
const size = Buffer.byteLength(content);
|
|
173
|
+
if (size > MAX_FILE_BYTES) throw new DesignPartsError("too-large", `design/${slug}/${DESIGN_PARTS_FILE} would grow to ${size} bytes, past the 1 MiB it can hold; nothing was written.`);
|
|
174
|
+
await replaceDesignFile(dir, path, DESIGN_PARTS_FILE, content);
|
|
175
|
+
return result;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
async read(slug) {
|
|
181
|
+
return load((await locate(slug)).path);
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
async add(slug, input) {
|
|
185
|
+
if (!isArtboardPath(input?.file)) throw new DesignPartsError("invalid-input", "file must be a relative .html path inside the design");
|
|
186
|
+
const selector = typeof input.selector === "string" ? collapse(input.selector) : "";
|
|
187
|
+
if (selector.length < 1 || selector.length > DESIGN_PART_SELECTOR_LIMIT) throw new DesignPartsError("invalid-input", `selector must have 1 to ${DESIGN_PART_SELECTOR_LIMIT} characters`);
|
|
188
|
+
if (typeof input.excerpt !== "string") throw new DesignPartsError("invalid-input", "excerpt must be text");
|
|
189
|
+
const excerpt = truncateUtf16(collapse(input.excerpt), DESIGN_PART_EXCERPT_LIMIT).trim();
|
|
190
|
+
if (typeof input.instruction !== "string") throw new DesignPartsError("invalid-input", "instruction must be text");
|
|
191
|
+
const instruction = normalizeText(input.instruction);
|
|
192
|
+
if (instruction.length > DESIGN_PART_INSTRUCTION_LIMIT) throw new DesignPartsError("invalid-input", `instruction must have at most ${DESIGN_PART_INSTRUCTION_LIMIT} characters`);
|
|
193
|
+
return mutate(slug, (document) => {
|
|
194
|
+
if (document.parts.length >= DESIGN_PARTS_MAX) throw new DesignPartsError("limit", `design/${slug} already has ${DESIGN_PARTS_MAX} parts, the most a design can hold.`);
|
|
195
|
+
let id = randomId();
|
|
196
|
+
while (document.parts.some((part) => part.id === id)) id = randomId();
|
|
197
|
+
const part = partOf({ id, file: input.file, selector, excerpt, instruction: instruction || undefined, status: "sent", queued: false, sentAt: now().toISOString(), startedAt: null, implementedAt: null });
|
|
198
|
+
document.parts.push(part);
|
|
199
|
+
return { result: part, write: true };
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
async setStatus(slug, file, id, status, options) {
|
|
204
|
+
if (status !== "in_progress" && status !== "implemented") throw new DesignPartsError("invalid-input", 'status must be "in_progress" or "implemented"');
|
|
205
|
+
const { note } = options ?? {};
|
|
206
|
+
if (note !== undefined && (typeof note !== "string" || note.length > DESIGN_PART_NOTE_LIMIT)) throw new DesignPartsError("invalid-input", `note must have at most ${DESIGN_PART_NOTE_LIMIT} characters`);
|
|
207
|
+
const cleanNote = note === undefined ? undefined : normalizeText(note) || undefined;
|
|
208
|
+
return mutate(slug, (document) => {
|
|
209
|
+
const index = document.parts.findIndex((part) => part.id === id);
|
|
210
|
+
if (index < 0) throw new DesignPartsError("not-found", `No part "${id}" in design/${slug}/parts.json.`);
|
|
211
|
+
const current = document.parts[index];
|
|
212
|
+
if (current.file !== file) throw new DesignPartsError("invalid-input", `Part "${id}" belongs to ${current.file}, not ${file}.`);
|
|
213
|
+
const stamp = now().toISOString();
|
|
214
|
+
const part = partOf({
|
|
215
|
+
...current,
|
|
216
|
+
status,
|
|
217
|
+
// A repeated in_progress report keeps the first start; taking up a sent or implemented part starts it again.
|
|
218
|
+
startedAt: status === "in_progress" ? (current.status === "in_progress" ? current.startedAt ?? stamp : stamp) : current.startedAt,
|
|
219
|
+
implementedAt: status === "implemented" ? stamp : null,
|
|
220
|
+
note: cleanNote,
|
|
221
|
+
});
|
|
222
|
+
document.parts[index] = part;
|
|
223
|
+
return { result: part, write: true };
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
async markQueued(slug, id) {
|
|
228
|
+
return mutate(slug, (document) => {
|
|
229
|
+
const index = document.parts.findIndex((part) => part.id === id);
|
|
230
|
+
if (index < 0 || document.parts[index].status !== "sent" || document.parts[index].queued) return { result: false, write: false };
|
|
231
|
+
document.parts[index] = partOf({ ...document.parts[index], queued: true });
|
|
232
|
+
return { result: true, write: true };
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
async remove(slug, id) {
|
|
237
|
+
return mutate(slug, (document) => {
|
|
238
|
+
const index = document.parts.findIndex((part) => part.id === id);
|
|
239
|
+
if (index < 0) return { result: false, write: false };
|
|
240
|
+
document.parts.splice(index, 1);
|
|
241
|
+
return { result: true, write: true };
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
async removeSent(slug, id) {
|
|
246
|
+
if (typeof id !== "string" || !PART_ID.test(id)) throw new DesignPartsError("invalid-input", "id must be 1 to 32 lowercase letters or digits");
|
|
247
|
+
return mutate(slug, (document) => {
|
|
248
|
+
const index = document.parts.findIndex((part) => part.id === id);
|
|
249
|
+
if (index < 0) throw new DesignPartsError("not-found", `No part "${id}" in design/${slug}/parts.json.`);
|
|
250
|
+
const part = document.parts[index];
|
|
251
|
+
if (part.status !== "sent") throw new DesignPartsError("not-sent", `Part "${id}" is ${part.status}, not sent; only a sent part can be removed.`);
|
|
252
|
+
document.parts.splice(index, 1);
|
|
253
|
+
return { result: part, write: true };
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Records the part BEFORE `deliver` sends it, so the agent can report on a part that is on disk; the delivery says
|
|
261
|
+
* whether it was queued behind a busy agent, and a failed delivery takes the part back.
|
|
262
|
+
*/
|
|
263
|
+
export async function sendDesignPart(
|
|
264
|
+
store: DesignPartStore,
|
|
265
|
+
slug: string,
|
|
266
|
+
input: DesignPartInput,
|
|
267
|
+
deliver: (part: DesignPart) => DesignHandoffDelivery | Promise<DesignHandoffDelivery>,
|
|
268
|
+
): Promise<{ part: DesignPart; queued: boolean }> {
|
|
269
|
+
const part = await store.add(slug, input);
|
|
270
|
+
let delivery: DesignHandoffDelivery;
|
|
271
|
+
try {
|
|
272
|
+
delivery = await deliver(part);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
await store.remove(slug, part.id).catch(() => false);
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
const queued = typeof delivery === "object" && delivery !== null && delivery.queued === true;
|
|
278
|
+
// Already delivered: a failure to note the queue must not report the part as failed.
|
|
279
|
+
if (queued) await store.markQueued(slug, part.id).catch(() => false);
|
|
280
|
+
return { part: queued ? { ...part, queued: true } : part, queued };
|
|
281
|
+
}
|