aimux-cli 0.1.16 → 0.1.19
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 +184 -67
- package/bin/aimux-dev +10 -0
- package/dist/agent-events.js +0 -1
- package/dist/agent-output-parser.js +0 -1
- package/dist/agent-prompt-delivery.js +0 -1
- package/dist/agent-tracker.js +0 -1
- package/dist/agent-watcher.js +0 -1
- package/dist/alert-display.d.ts +21 -0
- package/dist/alert-display.js +85 -0
- package/dist/atomic-write.js +0 -1
- package/dist/attachment-store.d.ts +0 -7
- package/dist/attachment-store.js +2 -87
- package/dist/builtin-metadata-watchers.js +4 -5
- package/dist/claude-hooks.d.ts +1 -0
- package/dist/claude-hooks.js +25 -1
- package/dist/config.d.ts +19 -13
- package/dist/config.js +28 -15
- package/dist/connection-targets.d.ts +8 -0
- package/dist/connection-targets.js +27 -0
- package/dist/context/compactor.js +0 -1
- package/dist/context/context-bridge.js +0 -1
- package/dist/context/context-file.js +0 -1
- package/dist/context/history.js +0 -1
- package/dist/credentials.d.ts +12 -0
- package/dist/credentials.js +48 -0
- package/dist/daemon.d.ts +23 -0
- package/dist/daemon.js +391 -67
- package/dist/dashboard/command-spec.js +0 -1
- package/dist/dashboard/feedback.js +0 -1
- package/dist/dashboard/index.d.ts +13 -10
- package/dist/dashboard/index.js +3 -27
- package/dist/dashboard/operation-failures.js +0 -1
- package/dist/dashboard/order.d.ts +22 -0
- package/dist/dashboard/order.js +54 -0
- package/dist/dashboard/pending-actions.d.ts +39 -10
- package/dist/dashboard/pending-actions.js +166 -37
- package/dist/dashboard/quick-jump.d.ts +2 -1
- package/dist/dashboard/quick-jump.js +7 -5
- package/dist/dashboard/runtime-evidence.js +0 -1
- package/dist/dashboard/session-actions.d.ts +4 -4
- package/dist/dashboard/session-actions.js +1 -2
- package/dist/dashboard/session-registry.d.ts +4 -3
- package/dist/dashboard/session-registry.js +16 -51
- package/dist/dashboard/sort.js +0 -1
- package/dist/dashboard/state.d.ts +1 -1
- package/dist/dashboard/state.js +0 -1
- package/dist/dashboard/targets.js +0 -1
- package/dist/dashboard/ui-state-store.d.ts +16 -1
- package/dist/dashboard/ui-state-store.js +73 -3
- package/dist/debug-state.d.ts +97 -0
- package/dist/debug-state.js +540 -0
- package/dist/debug.d.ts +38 -0
- package/dist/debug.js +219 -16
- package/dist/default-plugins/gh-pr-context.d.ts +2 -1
- package/dist/default-plugins/gh-pr-context.js +17 -12
- package/dist/default-plugins/transcript-length.js +15 -3
- package/dist/fast-control.js +37 -20
- package/dist/hotkeys.js +0 -1
- package/dist/http-client.js +31 -3
- package/dist/key-parser.js +0 -1
- package/dist/last-used.js +0 -1
- package/dist/local-ui-server.d.ts +22 -0
- package/dist/local-ui-server.js +185 -0
- package/dist/login-flow.d.ts +7 -0
- package/dist/login-flow.js +119 -0
- package/dist/main.js +821 -152
- package/dist/managed-launch-env.js +14 -1
- package/dist/metadata-server.d.ts +36 -36
- package/dist/metadata-server.js +638 -138
- package/dist/metadata-store.d.ts +4 -1
- package/dist/metadata-store.js +30 -3
- package/dist/multiplexer/agent-io-methods.d.ts +2 -10
- package/dist/multiplexer/agent-io-methods.js +12 -44
- package/dist/multiplexer/archives.js +8 -10
- package/dist/multiplexer/dashboard-actions-methods.js +0 -1
- package/dist/multiplexer/dashboard-control.js +45 -14
- package/dist/multiplexer/dashboard-interaction.d.ts +8 -2
- package/dist/multiplexer/dashboard-interaction.js +187 -29
- package/dist/multiplexer/dashboard-model.d.ts +10 -3
- package/dist/multiplexer/dashboard-model.js +417 -36
- package/dist/multiplexer/dashboard-ops.d.ts +9 -7
- package/dist/multiplexer/dashboard-ops.js +178 -69
- package/dist/multiplexer/dashboard-state-methods.d.ts +2 -1
- package/dist/multiplexer/dashboard-state-methods.js +3 -3
- package/dist/multiplexer/dashboard-tail-methods.d.ts +22 -10
- package/dist/multiplexer/dashboard-tail-methods.js +164 -48
- package/dist/multiplexer/dashboard-view-methods.d.ts +1 -1
- package/dist/multiplexer/dashboard-view-methods.js +23 -9
- package/dist/multiplexer/graveyard-view-model.d.ts +9 -1
- package/dist/multiplexer/graveyard-view-model.js +39 -1
- package/dist/multiplexer/index.d.ts +15 -12
- package/dist/multiplexer/index.js +64 -44
- package/dist/multiplexer/navigation.js +0 -1
- package/dist/multiplexer/notifications.js +107 -25
- package/dist/multiplexer/persistence-methods.d.ts +31 -4
- package/dist/multiplexer/persistence-methods.js +304 -309
- package/dist/multiplexer/runtime-lifecycle-methods.d.ts +8 -10
- package/dist/multiplexer/runtime-lifecycle-methods.js +104 -87
- package/dist/multiplexer/runtime-state.d.ts +8 -10
- package/dist/multiplexer/runtime-state.js +82 -146
- package/dist/multiplexer/runtime-sync.d.ts +2 -10
- package/dist/multiplexer/runtime-sync.js +3 -19
- package/dist/multiplexer/service-state-snapshot.d.ts +2 -4
- package/dist/multiplexer/service-state-snapshot.js +4 -52
- package/dist/multiplexer/services.d.ts +1 -0
- package/dist/multiplexer/services.js +55 -6
- package/dist/multiplexer/session-capture.d.ts +1 -0
- package/dist/multiplexer/session-capture.js +23 -0
- package/dist/multiplexer/session-launch.d.ts +4 -1
- package/dist/multiplexer/session-launch.js +152 -64
- package/dist/multiplexer/session-runtime-core.d.ts +8 -20
- package/dist/multiplexer/session-runtime-core.js +40 -136
- package/dist/multiplexer/subscreens.js +10 -4
- package/dist/multiplexer/tool-picker.js +0 -1
- package/dist/multiplexer/worktree-graveyard.d.ts +0 -1
- package/dist/multiplexer/worktree-graveyard.js +15 -17
- package/dist/multiplexer/worktrees.js +96 -41
- package/dist/notification-context.js +8 -5
- package/dist/notifications.js +163 -102
- package/dist/notify.d.ts +4 -0
- package/dist/notify.js +14 -1
- package/dist/orchestration-actions.js +0 -1
- package/dist/orchestration-routing.js +0 -1
- package/dist/orchestration.js +0 -1
- package/dist/osc-notifications.js +0 -1
- package/dist/paths.d.ts +32 -7
- package/dist/paths.js +82 -59
- package/dist/pending-actions.d.ts +5 -0
- package/dist/pending-actions.js +13 -0
- package/dist/plugin-runtime.js +9 -3
- package/dist/project-events.d.ts +1 -10
- package/dist/project-events.js +0 -11
- package/dist/project-scanner.d.ts +2 -3
- package/dist/project-scanner.js +58 -130
- package/dist/project-service-manifest.d.ts +1 -3
- package/dist/project-service-manifest.js +1 -4
- package/dist/recency.js +0 -1
- package/dist/recorder.js +0 -1
- package/dist/relay-client.d.ts +30 -0
- package/dist/relay-client.js +190 -0
- package/dist/remote-access.d.ts +16 -0
- package/dist/remote-access.js +90 -0
- package/dist/runtime-core/exchange-derived.d.ts +2 -0
- package/dist/runtime-core/exchange-derived.js +153 -0
- package/dist/runtime-core/exchange-import.d.ts +24 -0
- package/dist/runtime-core/exchange-import.js +317 -0
- package/dist/runtime-core/exchange-store.d.ts +157 -0
- package/dist/runtime-core/exchange-store.js +452 -0
- package/dist/runtime-core/topology-services.d.ts +38 -0
- package/dist/runtime-core/topology-services.js +170 -0
- package/dist/runtime-core/topology-sessions.d.ts +52 -0
- package/dist/runtime-core/topology-sessions.js +238 -0
- package/dist/runtime-core/topology-store.d.ts +171 -0
- package/dist/runtime-core/topology-store.js +419 -0
- package/dist/runtime-core/topology-worktrees.d.ts +60 -0
- package/dist/runtime-core/topology-worktrees.js +199 -0
- package/dist/runtime-migration.d.ts +69 -0
- package/dist/runtime-migration.js +398 -0
- package/dist/session-bootstrap.d.ts +8 -6
- package/dist/session-bootstrap.js +51 -159
- package/dist/session-runtime.d.ts +2 -0
- package/dist/session-runtime.js +1 -1
- package/dist/session-semantics.d.ts +12 -4
- package/dist/session-semantics.js +14 -1
- package/dist/shell-args.js +0 -1
- package/dist/shell-hooks.js +32 -11
- package/dist/shell-state.d.ts +2 -0
- package/dist/shell-state.js +26 -2
- package/dist/status-detector.js +0 -1
- package/dist/statusline-model.d.ts +10 -2
- package/dist/statusline-model.js +106 -31
- package/dist/task-workflow.d.ts +6 -9
- package/dist/task-workflow.js +37 -85
- package/dist/tasks.d.ts +6 -33
- package/dist/tasks.js +46 -89
- package/dist/team.d.ts +29 -0
- package/dist/team.js +40 -1
- package/dist/terminal-host.js +0 -1
- package/dist/threads.d.ts +6 -35
- package/dist/threads.js +89 -99
- package/dist/tmux/doctor.js +0 -1
- package/dist/tmux/inbox-popup.js +37 -16
- package/dist/tmux/runtime-manager.d.ts +3 -0
- package/dist/tmux/runtime-manager.js +21 -5
- package/dist/tmux/session-transport.js +0 -1
- package/dist/tmux/statusline-cache.js +0 -1
- package/dist/tmux/statusline.js +49 -10
- package/dist/tmux/switcher.js +0 -1
- package/dist/tmux/window-open.js +1 -3
- package/dist/tool-output-watchers.d.ts +0 -18
- package/dist/tool-output-watchers.js +0 -323
- package/dist/tui/render/box.js +0 -1
- package/dist/tui/render/text.js +0 -1
- package/dist/tui/screens/dashboard-renderers.js +37 -26
- package/dist/tui/screens/overlay-renderers.d.ts +2 -0
- package/dist/tui/screens/overlay-renderers.js +37 -2
- package/dist/tui/screens/subscreen-renderers.js +7 -1
- package/dist/workflow.js +0 -1
- package/dist/worktree.js +17 -1
- package/dist-ui/_expo/static/css/web-30453ede1678c16acb08b97e83e8646d.css +1 -0
- package/dist-ui/_expo/static/js/web/entry-477c745b2adc79367a4380ecf07d9ff6.js +14620 -0
- package/dist-ui/assets/assets/images/icon.a5413dcd2e811c9f2317d01a28118d8a.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/back-icon-mask.0a328cd9c1afd0afe8e3b1ec5165b1b4.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/back-icon.35ba0eaec5a4f5ed12ca16fabeae451d.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55@2x.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55@3x.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55@4x.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/close-icon.808e1b1b9b53114ec2838071a7e6daa7.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/close-icon.808e1b1b9b53114ec2838071a7e6daa7@2x.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/close-icon.808e1b1b9b53114ec2838071a7e6daa7@3x.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/close-icon.808e1b1b9b53114ec2838071a7e6daa7@4x.png +0 -0
- package/dist-ui/assets/node_modules/@react-navigation/elements/lib/module/assets/search-icon.286d67d3f74808a60a78d3ebf1a5fb57.png +0 -0
- package/dist-ui/assets/node_modules/expo-router/assets/arrow_down.017bc6ba3fc25503e5eb5e53826d48a8.png +0 -0
- package/dist-ui/assets/node_modules/expo-router/assets/error.d1ea1496f9057eb392d5bbf3732a61b7.png +0 -0
- package/dist-ui/assets/node_modules/expo-router/assets/file.19eeb73b9593a38f8e9f418337fc7d10.png +0 -0
- package/dist-ui/assets/node_modules/expo-router/assets/forward.d8b800c443b8972542883e0b9de2bdc6.png +0 -0
- package/dist-ui/assets/node_modules/expo-router/assets/pkg.ab19f4cbc543357183a20571f68380a3.png +0 -0
- package/dist-ui/assets/node_modules/expo-router/assets/sitemap.412dd9275b6b48ad28f5e3d81bb1f626.png +0 -0
- package/dist-ui/assets/node_modules/expo-router/assets/unmatched.20e71bdf79e3a97bf55fd9e164041578.png +0 -0
- package/dist-ui/favicon.ico +0 -0
- package/dist-ui/index.html +38 -0
- package/dist-ui/metadata.json +1 -0
- package/package.json +29 -12
- package/dist/agent-events.js.map +0 -1
- package/dist/agent-message-parts.d.ts +0 -17
- package/dist/agent-message-parts.js +0 -31
- package/dist/agent-message-parts.js.map +0 -1
- package/dist/agent-output-parser.js.map +0 -1
- package/dist/agent-prompt-delivery.js.map +0 -1
- package/dist/agent-tracker.js.map +0 -1
- package/dist/agent-watcher.js.map +0 -1
- package/dist/atomic-write.js.map +0 -1
- package/dist/attachment-store.js.map +0 -1
- package/dist/builtin-metadata-watchers.js.map +0 -1
- package/dist/claude-hooks.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/context/compactor.js.map +0 -1
- package/dist/context/context-bridge.js.map +0 -1
- package/dist/context/context-file.js.map +0 -1
- package/dist/context/history.js.map +0 -1
- package/dist/daemon.js.map +0 -1
- package/dist/dashboard/command-spec.js.map +0 -1
- package/dist/dashboard/feedback.js.map +0 -1
- package/dist/dashboard/index.js.map +0 -1
- package/dist/dashboard/operation-failures.js.map +0 -1
- package/dist/dashboard/pending-actions.js.map +0 -1
- package/dist/dashboard/quick-jump.js.map +0 -1
- package/dist/dashboard/runtime-evidence.js.map +0 -1
- package/dist/dashboard/session-actions.js.map +0 -1
- package/dist/dashboard/session-registry.js.map +0 -1
- package/dist/dashboard/sort.js.map +0 -1
- package/dist/dashboard/state.js.map +0 -1
- package/dist/dashboard/targets.js.map +0 -1
- package/dist/dashboard/ui-state-store.js.map +0 -1
- package/dist/debug.js.map +0 -1
- package/dist/default-plugins/gh-pr-context.js.map +0 -1
- package/dist/default-plugins/transcript-length.js.map +0 -1
- package/dist/fast-control.js.map +0 -1
- package/dist/hotkeys.js.map +0 -1
- package/dist/http-client.js.map +0 -1
- package/dist/instance-directory.d.ts +0 -32
- package/dist/instance-directory.js +0 -82
- package/dist/instance-directory.js.map +0 -1
- package/dist/instance-registry.d.ts +0 -39
- package/dist/instance-registry.js +0 -208
- package/dist/instance-registry.js.map +0 -1
- package/dist/key-parser.js.map +0 -1
- package/dist/last-used.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/managed-launch-env.js.map +0 -1
- package/dist/metadata-server.js.map +0 -1
- package/dist/metadata-store.js.map +0 -1
- package/dist/multiplexer/agent-io-methods.js.map +0 -1
- package/dist/multiplexer/archives.js.map +0 -1
- package/dist/multiplexer/dashboard-actions-methods.js.map +0 -1
- package/dist/multiplexer/dashboard-control.js.map +0 -1
- package/dist/multiplexer/dashboard-interaction.js.map +0 -1
- package/dist/multiplexer/dashboard-model.js.map +0 -1
- package/dist/multiplexer/dashboard-ops.js.map +0 -1
- package/dist/multiplexer/dashboard-state-methods.js.map +0 -1
- package/dist/multiplexer/dashboard-tail-methods.js.map +0 -1
- package/dist/multiplexer/dashboard-view-methods.js.map +0 -1
- package/dist/multiplexer/graveyard-view-model.js.map +0 -1
- package/dist/multiplexer/index.js.map +0 -1
- package/dist/multiplexer/navigation.js.map +0 -1
- package/dist/multiplexer/notifications.js.map +0 -1
- package/dist/multiplexer/persistence-methods.js.map +0 -1
- package/dist/multiplexer/runtime-lifecycle-methods.js.map +0 -1
- package/dist/multiplexer/runtime-state.js.map +0 -1
- package/dist/multiplexer/runtime-sync.js.map +0 -1
- package/dist/multiplexer/service-state-snapshot.js.map +0 -1
- package/dist/multiplexer/services.js.map +0 -1
- package/dist/multiplexer/session-actions.d.ts +0 -40
- package/dist/multiplexer/session-actions.js +0 -110
- package/dist/multiplexer/session-actions.js.map +0 -1
- package/dist/multiplexer/session-launch.js.map +0 -1
- package/dist/multiplexer/session-runtime-core.js.map +0 -1
- package/dist/multiplexer/subscreens.js.map +0 -1
- package/dist/multiplexer/tool-picker.js.map +0 -1
- package/dist/multiplexer/worktree-graveyard.js.map +0 -1
- package/dist/multiplexer/worktrees.js.map +0 -1
- package/dist/notification-context.js.map +0 -1
- package/dist/notifications.js.map +0 -1
- package/dist/notify.js.map +0 -1
- package/dist/orchestration-actions.js.map +0 -1
- package/dist/orchestration-dispatcher.d.ts +0 -25
- package/dist/orchestration-dispatcher.js +0 -59
- package/dist/orchestration-dispatcher.js.map +0 -1
- package/dist/orchestration-routing.js.map +0 -1
- package/dist/orchestration.js.map +0 -1
- package/dist/osc-notifications.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/plugin-runtime.js.map +0 -1
- package/dist/project-events.js.map +0 -1
- package/dist/project-scanner.js.map +0 -1
- package/dist/project-service-manifest.js.map +0 -1
- package/dist/recency.js.map +0 -1
- package/dist/recorder.js.map +0 -1
- package/dist/session-bootstrap.js.map +0 -1
- package/dist/session-input-operations.d.ts +0 -19
- package/dist/session-input-operations.js +0 -46
- package/dist/session-input-operations.js.map +0 -1
- package/dist/session-message-history.d.ts +0 -27
- package/dist/session-message-history.js +0 -105
- package/dist/session-message-history.js.map +0 -1
- package/dist/session-runtime.js.map +0 -1
- package/dist/session-semantics.js.map +0 -1
- package/dist/shell-args.js.map +0 -1
- package/dist/shell-hooks.js.map +0 -1
- package/dist/shell-state.js.map +0 -1
- package/dist/status-detector.js.map +0 -1
- package/dist/statusline-model.js.map +0 -1
- package/dist/task-dispatcher.d.ts +0 -64
- package/dist/task-dispatcher.js +0 -213
- package/dist/task-dispatcher.js.map +0 -1
- package/dist/task-workflow.js.map +0 -1
- package/dist/tasks.js.map +0 -1
- package/dist/team.js.map +0 -1
- package/dist/terminal-host.js.map +0 -1
- package/dist/threads.js.map +0 -1
- package/dist/tmux/doctor.js.map +0 -1
- package/dist/tmux/inbox-popup.js.map +0 -1
- package/dist/tmux/runtime-manager.js.map +0 -1
- package/dist/tmux/session-transport.js.map +0 -1
- package/dist/tmux/statusline-cache.js.map +0 -1
- package/dist/tmux/statusline.js.map +0 -1
- package/dist/tmux/switcher.js.map +0 -1
- package/dist/tmux/window-open.js.map +0 -1
- package/dist/tool-output-watchers.js.map +0 -1
- package/dist/tui/render/box.js.map +0 -1
- package/dist/tui/render/text.js.map +0 -1
- package/dist/tui/screens/dashboard-renderers.js.map +0 -1
- package/dist/tui/screens/overlay-renderers.js.map +0 -1
- package/dist/tui/screens/subscreen-renderers.js.map +0 -1
- package/dist/workflow.js.map +0 -1
- package/dist/worktree.js.map +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const ACTOR_HEADER = "x-aimux-actor";
|
|
2
|
+
const ROLE_HEADER = "x-aimux-actor-role";
|
|
3
|
+
const USER_ID_HEADER = "x-aimux-actor-user-id";
|
|
4
|
+
const DISPLAY_NAME_HEADER = "x-aimux-actor-display-name";
|
|
5
|
+
const EMAIL_HEADER = "x-aimux-actor-email";
|
|
6
|
+
const SHARE_ID_HEADER = "x-aimux-share-id";
|
|
7
|
+
const SHARE_SESSION_ID_HEADER = "x-aimux-share-session-id";
|
|
8
|
+
const RELAY_HEADER_PREFIX = "x-aimux-";
|
|
9
|
+
function headerValue(headers, name) {
|
|
10
|
+
if (!headers)
|
|
11
|
+
return undefined;
|
|
12
|
+
const direct = headers[name];
|
|
13
|
+
if (typeof direct === "string")
|
|
14
|
+
return direct.trim() || undefined;
|
|
15
|
+
const lowerName = name.toLowerCase();
|
|
16
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
17
|
+
if (key.toLowerCase() === lowerName)
|
|
18
|
+
return value.trim() || undefined;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
function hasRelayActorHeaders(headers) {
|
|
23
|
+
if (!headers)
|
|
24
|
+
return false;
|
|
25
|
+
return Object.keys(headers).some((key) => key.toLowerCase().startsWith(RELAY_HEADER_PREFIX));
|
|
26
|
+
}
|
|
27
|
+
function actorFromJson(value) {
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(value);
|
|
30
|
+
if (!parsed || typeof parsed !== "object")
|
|
31
|
+
return null;
|
|
32
|
+
const record = parsed;
|
|
33
|
+
return {
|
|
34
|
+
role: record.role === "owner" || record.role === "guest" ? record.role : undefined,
|
|
35
|
+
userId: typeof record.userId === "string" ? record.userId : undefined,
|
|
36
|
+
displayName: typeof record.displayName === "string" ? record.displayName : undefined,
|
|
37
|
+
email: typeof record.email === "string" ? record.email : undefined,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function parseRemoteActor(headers) {
|
|
45
|
+
const actorJson = headerValue(headers, ACTOR_HEADER);
|
|
46
|
+
const jsonActor = actorJson ? actorFromJson(actorJson) : null;
|
|
47
|
+
const role = headerValue(headers, ROLE_HEADER) ?? jsonActor?.role;
|
|
48
|
+
if (!role) {
|
|
49
|
+
return hasRelayActorHeaders(headers) ? { role: "guest" } : null;
|
|
50
|
+
}
|
|
51
|
+
if (role !== "owner" && role !== "guest") {
|
|
52
|
+
return { role: "guest" };
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
role,
|
|
56
|
+
userId: headerValue(headers, USER_ID_HEADER) ?? jsonActor?.userId,
|
|
57
|
+
displayName: headerValue(headers, DISPLAY_NAME_HEADER) ?? jsonActor?.displayName,
|
|
58
|
+
email: headerValue(headers, EMAIL_HEADER) ?? jsonActor?.email,
|
|
59
|
+
shareId: headerValue(headers, SHARE_ID_HEADER),
|
|
60
|
+
shareSessionId: headerValue(headers, SHARE_SESSION_ID_HEADER),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function assertRemoteAccessAllowed(actor, method, pathname, searchParams) {
|
|
64
|
+
if (!actor || actor.role === "owner")
|
|
65
|
+
return { ok: true };
|
|
66
|
+
if (actor.role !== "guest")
|
|
67
|
+
return { ok: false, status: 403, error: "remote actor role is not allowed" };
|
|
68
|
+
if (method !== "GET")
|
|
69
|
+
return { ok: false, status: 403, error: "shared guests are read-only" };
|
|
70
|
+
if (pathname === "/health")
|
|
71
|
+
return { ok: true };
|
|
72
|
+
const proxyMatch = pathname.match(/^\/proxy\/[^/]+\/\d+(\/.*)$/);
|
|
73
|
+
if (!proxyMatch)
|
|
74
|
+
return { ok: false, status: 403, error: "shared guests cannot access daemon routes" };
|
|
75
|
+
const subPath = proxyMatch[1] || "/";
|
|
76
|
+
if (subPath === "/agents/output" || subPath === "/agents/history" || subPath === "/events") {
|
|
77
|
+
if (!actor.shareSessionId) {
|
|
78
|
+
return { ok: false, status: 403, error: "shared guest route requires an authorized share session" };
|
|
79
|
+
}
|
|
80
|
+
const requestedSessionId = searchParams.get("sessionId");
|
|
81
|
+
if (!requestedSessionId) {
|
|
82
|
+
return { ok: false, status: 403, error: "shared session route requires a session id" };
|
|
83
|
+
}
|
|
84
|
+
if (requestedSessionId !== actor.shareSessionId) {
|
|
85
|
+
return { ok: false, status: 403, error: "shared guest cannot access another session" };
|
|
86
|
+
}
|
|
87
|
+
return { ok: true };
|
|
88
|
+
}
|
|
89
|
+
return { ok: false, status: 403, error: "shared guests can only read shared session output" };
|
|
90
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
function unique(values) {
|
|
2
|
+
return [...new Set(values.map((value) => value?.trim()).filter(Boolean))];
|
|
3
|
+
}
|
|
4
|
+
function handoffActionFromMessages(messages) {
|
|
5
|
+
const lifecycleMessage = [...messages]
|
|
6
|
+
.reverse()
|
|
7
|
+
.find((message) => message.metadata?.handoffAction === "accepted" || message.metadata?.handoffAction === "completed");
|
|
8
|
+
return {
|
|
9
|
+
action: lifecycleMessage?.metadata?.handoffAction,
|
|
10
|
+
actor: lifecycleMessage?.from,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function handoffFromThread(thread, messages) {
|
|
14
|
+
if (thread.kind !== "handoff")
|
|
15
|
+
return undefined;
|
|
16
|
+
const recipients = unique(thread.waitingOn?.length ? thread.waitingOn : thread.participants.filter((id) => id !== thread.createdBy));
|
|
17
|
+
if (recipients.length === 0)
|
|
18
|
+
return undefined;
|
|
19
|
+
const lifecycle = handoffActionFromMessages(messages);
|
|
20
|
+
const status = lifecycle.action === "completed"
|
|
21
|
+
? "completed"
|
|
22
|
+
: lifecycle.action === "accepted"
|
|
23
|
+
? "accepted"
|
|
24
|
+
: thread.status === "done"
|
|
25
|
+
? "completed"
|
|
26
|
+
: thread.status === "abandoned"
|
|
27
|
+
? "cancelled"
|
|
28
|
+
: "waiting";
|
|
29
|
+
return {
|
|
30
|
+
id: `handoff:${thread.id}`,
|
|
31
|
+
threadId: thread.id,
|
|
32
|
+
status,
|
|
33
|
+
from: thread.createdBy,
|
|
34
|
+
to: recipients,
|
|
35
|
+
acceptedBy: lifecycle.action === "accepted" ? lifecycle.actor : thread.status === "open" ? thread.owner : undefined,
|
|
36
|
+
completedBy: lifecycle.action === "completed" ? lifecycle.actor : thread.status === "done" ? thread.owner : undefined,
|
|
37
|
+
createdAt: thread.createdAt,
|
|
38
|
+
updatedAt: thread.updatedAt,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function reviewFromTask(task) {
|
|
42
|
+
if (task.type !== "review")
|
|
43
|
+
return undefined;
|
|
44
|
+
return {
|
|
45
|
+
id: `review:${task.id}`,
|
|
46
|
+
taskId: task.id,
|
|
47
|
+
reviewOf: task.reviewOf,
|
|
48
|
+
reviewer: task.assignedTo ?? task.assignee,
|
|
49
|
+
status: task.reviewStatus ?? "pending",
|
|
50
|
+
feedback: task.reviewFeedback ?? task.result,
|
|
51
|
+
createdAt: task.createdAt,
|
|
52
|
+
updatedAt: task.updatedAt,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function waitsFromThread(thread) {
|
|
56
|
+
const waitingOn = unique(thread.waitingOn ?? []);
|
|
57
|
+
if (waitingOn.length === 0)
|
|
58
|
+
return [];
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
id: `wait:thread:${thread.id}`,
|
|
62
|
+
status: thread.status === "done" || thread.status === "abandoned" ? "satisfied" : "waiting",
|
|
63
|
+
subjectKind: "thread",
|
|
64
|
+
subjectId: thread.id,
|
|
65
|
+
waitingOn,
|
|
66
|
+
owner: thread.owner,
|
|
67
|
+
createdAt: thread.createdAt,
|
|
68
|
+
updatedAt: thread.updatedAt,
|
|
69
|
+
resolvedAt: thread.status === "done" || thread.status === "abandoned" ? thread.updatedAt : undefined,
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
function waitsFromTask(task) {
|
|
74
|
+
const waitingOn = unique([
|
|
75
|
+
task.status === "blocked" ? task.assignedBy : undefined,
|
|
76
|
+
task.status === "assigned" || task.status === "pending" || task.status === "in_progress"
|
|
77
|
+
? (task.assignedTo ?? task.assignee)
|
|
78
|
+
: undefined,
|
|
79
|
+
]);
|
|
80
|
+
if (waitingOn.length === 0)
|
|
81
|
+
return [];
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
id: `wait:task:${task.id}`,
|
|
85
|
+
status: task.status === "done" || task.status === "failed" ? "satisfied" : "waiting",
|
|
86
|
+
subjectKind: "task",
|
|
87
|
+
subjectId: task.id,
|
|
88
|
+
waitingOn,
|
|
89
|
+
owner: task.assignedBy,
|
|
90
|
+
createdAt: task.createdAt,
|
|
91
|
+
updatedAt: task.updatedAt,
|
|
92
|
+
resolvedAt: task.status === "done" || task.status === "failed" ? task.updatedAt : undefined,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
function inboxFromThread(thread) {
|
|
97
|
+
const participants = unique([...(thread.unreadBy ?? []), ...(thread.waitingOn ?? [])]);
|
|
98
|
+
return participants.map((participantId) => {
|
|
99
|
+
const waiting = (thread.waitingOn ?? []).includes(participantId);
|
|
100
|
+
return {
|
|
101
|
+
id: `inbox:${participantId}:thread:${thread.id}`,
|
|
102
|
+
participantId,
|
|
103
|
+
subjectKind: "thread",
|
|
104
|
+
subjectId: thread.id,
|
|
105
|
+
state: thread.status === "blocked" ? "blocked" : waiting ? "waiting" : "unread",
|
|
106
|
+
urgency: (waiting ? 10 : 0) + ((thread.unreadBy ?? []).includes(participantId) ? 3 : 0),
|
|
107
|
+
updatedAt: thread.updatedAt,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function inboxFromTask(task) {
|
|
112
|
+
const participants = unique([
|
|
113
|
+
task.status === "blocked" ? task.assignedBy : undefined,
|
|
114
|
+
task.status !== "done" && task.status !== "failed" ? (task.assignedTo ?? task.assignee) : undefined,
|
|
115
|
+
]);
|
|
116
|
+
return participants.map((participantId) => ({
|
|
117
|
+
id: `inbox:${participantId}:task:${task.id}`,
|
|
118
|
+
participantId,
|
|
119
|
+
subjectKind: "task",
|
|
120
|
+
subjectId: task.id,
|
|
121
|
+
state: task.status === "blocked" ? "blocked" : task.status === "done" ? "done" : "waiting",
|
|
122
|
+
urgency: task.status === "blocked" ? 12 : task.type === "review" ? 8 : 6,
|
|
123
|
+
updatedAt: task.updatedAt,
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
function preserveAcknowledgedInbox(nextEntries, previousEntries) {
|
|
127
|
+
const previousById = new Map(previousEntries.map((entry) => [entry.id, entry]));
|
|
128
|
+
return nextEntries.map((entry) => {
|
|
129
|
+
const previous = previousById.get(entry.id);
|
|
130
|
+
if (previous?.state === "done" && previous.updatedAt === entry.updatedAt) {
|
|
131
|
+
return { ...entry, state: "done" };
|
|
132
|
+
}
|
|
133
|
+
return entry;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export function deriveRuntimeExchangeIndexes(exchange) {
|
|
137
|
+
const messagesByThread = new Map();
|
|
138
|
+
for (const message of exchange.messages) {
|
|
139
|
+
const existing = messagesByThread.get(message.threadId) ?? [];
|
|
140
|
+
existing.push(message);
|
|
141
|
+
messagesByThread.set(message.threadId, existing);
|
|
142
|
+
}
|
|
143
|
+
const nextInbox = [...exchange.threads.flatMap(inboxFromThread), ...exchange.tasks.flatMap(inboxFromTask)];
|
|
144
|
+
return {
|
|
145
|
+
...exchange,
|
|
146
|
+
handoffs: exchange.threads
|
|
147
|
+
.map((thread) => handoffFromThread(thread, messagesByThread.get(thread.id) ?? []))
|
|
148
|
+
.filter((handoff) => Boolean(handoff)),
|
|
149
|
+
reviews: exchange.tasks.map(reviewFromTask).filter((review) => Boolean(review)),
|
|
150
|
+
waits: [...exchange.threads.flatMap(waitsFromThread), ...exchange.tasks.flatMap(waitsFromTask)],
|
|
151
|
+
inbox: preserveAcknowledgedInbox(nextInbox, exchange.inbox),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AttachmentRecord } from "../attachment-store.js";
|
|
2
|
+
import type { Task } from "../tasks.js";
|
|
3
|
+
import type { OrchestrationMessage, OrchestrationThread } from "../threads.js";
|
|
4
|
+
import { type RuntimeExchange } from "./exchange-store.js";
|
|
5
|
+
export interface RuntimeExchangeLegacySnapshot {
|
|
6
|
+
threads?: OrchestrationThread[];
|
|
7
|
+
messages?: OrchestrationMessage[];
|
|
8
|
+
tasks?: Task[];
|
|
9
|
+
planPaths?: string[];
|
|
10
|
+
historyPaths?: string[];
|
|
11
|
+
contextPaths?: string[];
|
|
12
|
+
recordingPaths?: string[];
|
|
13
|
+
statusPaths?: string[];
|
|
14
|
+
attachments?: AttachmentRecord[];
|
|
15
|
+
now?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildRuntimeExchangeFromLegacySnapshot(input?: RuntimeExchangeLegacySnapshot): RuntimeExchange;
|
|
18
|
+
export declare function importRuntimeExchangeFromLegacyFiles(input?: {
|
|
19
|
+
now?: string;
|
|
20
|
+
additionalHistoryPaths?: string[];
|
|
21
|
+
additionalContextPaths?: string[];
|
|
22
|
+
additionalRecordingPaths?: string[];
|
|
23
|
+
additionalStatusPaths?: string[];
|
|
24
|
+
}): RuntimeExchange;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { getAttachmentsDir, getContextDir, getHistoryDir, getPlansDir, getRecordingsDir, getStatusDir, getTasksDir, getThreadsDir, } from "../paths.js";
|
|
4
|
+
import { emptyRuntimeExchange, } from "./exchange-store.js";
|
|
5
|
+
function unique(values) {
|
|
6
|
+
return [...new Set(values.map((value) => value?.trim()).filter(Boolean))];
|
|
7
|
+
}
|
|
8
|
+
function safeJson(path) {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function listFiles(dir, predicate) {
|
|
17
|
+
if (!existsSync(dir))
|
|
18
|
+
return [];
|
|
19
|
+
try {
|
|
20
|
+
return readdirSync(dir)
|
|
21
|
+
.filter(predicate)
|
|
22
|
+
.map((name) => join(dir, name));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function listNestedFiles(dir, predicate) {
|
|
29
|
+
if (!existsSync(dir))
|
|
30
|
+
return [];
|
|
31
|
+
const paths = [];
|
|
32
|
+
try {
|
|
33
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
34
|
+
const path = join(dir, entry.name);
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
paths.push(...listNestedFiles(path, predicate));
|
|
37
|
+
}
|
|
38
|
+
else if (predicate(entry.name)) {
|
|
39
|
+
paths.push(path);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return paths;
|
|
47
|
+
}
|
|
48
|
+
function readLegacyThreads() {
|
|
49
|
+
return listFiles(getThreadsDir(), (name) => name.endsWith(".json"))
|
|
50
|
+
.map((path) => safeJson(path))
|
|
51
|
+
.filter((thread) => Boolean(thread));
|
|
52
|
+
}
|
|
53
|
+
function readLegacyMessages(threadIds) {
|
|
54
|
+
return threadIds.flatMap((threadId) => {
|
|
55
|
+
const path = join(getThreadsDir(), `${threadId}.jsonl`);
|
|
56
|
+
if (!existsSync(path))
|
|
57
|
+
return [];
|
|
58
|
+
try {
|
|
59
|
+
return readFileSync(path, "utf8")
|
|
60
|
+
.split("\n")
|
|
61
|
+
.map((line) => line.trim())
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.map((line) => {
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(line);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
.filter((message) => Boolean(message));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function readLegacyTasks() {
|
|
79
|
+
return listFiles(getTasksDir(), (name) => name.endsWith(".json"))
|
|
80
|
+
.map((path) => safeJson(path))
|
|
81
|
+
.filter((task) => Boolean(task));
|
|
82
|
+
}
|
|
83
|
+
function readLegacyAttachments() {
|
|
84
|
+
return listFiles(getAttachmentsDir(), (name) => name.endsWith(".json"))
|
|
85
|
+
.map((path) => safeJson(path))
|
|
86
|
+
.filter((attachment) => Boolean(attachment));
|
|
87
|
+
}
|
|
88
|
+
function toExchangeThread(thread) {
|
|
89
|
+
return {
|
|
90
|
+
id: thread.id,
|
|
91
|
+
title: thread.title,
|
|
92
|
+
kind: thread.kind,
|
|
93
|
+
status: thread.status,
|
|
94
|
+
createdAt: thread.createdAt,
|
|
95
|
+
updatedAt: thread.updatedAt,
|
|
96
|
+
createdBy: thread.createdBy,
|
|
97
|
+
participants: thread.participants,
|
|
98
|
+
owner: thread.owner,
|
|
99
|
+
waitingOn: thread.waitingOn,
|
|
100
|
+
worktreePath: thread.worktreePath,
|
|
101
|
+
taskId: thread.taskId,
|
|
102
|
+
relatedPlanIds: thread.relatedPlanIds,
|
|
103
|
+
lastMessageId: thread.lastMessageId,
|
|
104
|
+
unreadBy: thread.unreadBy,
|
|
105
|
+
tags: thread.tags,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function toExchangeMessage(message) {
|
|
109
|
+
return {
|
|
110
|
+
id: message.id,
|
|
111
|
+
threadId: message.threadId,
|
|
112
|
+
ts: message.ts,
|
|
113
|
+
from: message.from,
|
|
114
|
+
to: message.to,
|
|
115
|
+
kind: message.kind,
|
|
116
|
+
body: message.body,
|
|
117
|
+
taskId: message.taskId,
|
|
118
|
+
planId: message.planId,
|
|
119
|
+
metadata: message.metadata,
|
|
120
|
+
deliveredTo: message.deliveredTo,
|
|
121
|
+
deliveredAt: message.deliveredAt,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function normalizeReviewStatus(status) {
|
|
125
|
+
const normalized = String(status ?? "")
|
|
126
|
+
.trim()
|
|
127
|
+
.toLowerCase()
|
|
128
|
+
.replace(/[-\s]+/g, "_");
|
|
129
|
+
if (normalized === "approved" || normalized === "approve")
|
|
130
|
+
return "approved";
|
|
131
|
+
if (normalized === "changes_requested" || normalized === "request_changes")
|
|
132
|
+
return "changes_requested";
|
|
133
|
+
if (normalized === "pending")
|
|
134
|
+
return "pending";
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
function toExchangeTask(task) {
|
|
138
|
+
return {
|
|
139
|
+
id: task.id,
|
|
140
|
+
status: task.status,
|
|
141
|
+
assignedBy: task.assignedBy,
|
|
142
|
+
assignedTo: task.assignedTo,
|
|
143
|
+
assignee: task.assignee,
|
|
144
|
+
assigner: task.assigner,
|
|
145
|
+
threadId: task.threadId,
|
|
146
|
+
tool: task.tool,
|
|
147
|
+
description: task.description,
|
|
148
|
+
prompt: task.prompt,
|
|
149
|
+
result: task.result,
|
|
150
|
+
error: task.error,
|
|
151
|
+
createdAt: task.createdAt,
|
|
152
|
+
updatedAt: task.updatedAt,
|
|
153
|
+
notifiedAt: task.notifiedAt,
|
|
154
|
+
type: task.type,
|
|
155
|
+
reviewStatus: normalizeReviewStatus(task.reviewStatus),
|
|
156
|
+
reviewFeedback: task.reviewFeedback,
|
|
157
|
+
diff: task.diff,
|
|
158
|
+
iteration: task.iteration,
|
|
159
|
+
reviewOf: task.reviewOf,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function buildHandoff(thread) {
|
|
163
|
+
if (thread.kind !== "handoff")
|
|
164
|
+
return undefined;
|
|
165
|
+
const recipients = unique(thread.waitingOn?.length ? thread.waitingOn : thread.participants.filter((id) => id !== thread.createdBy));
|
|
166
|
+
if (recipients.length === 0)
|
|
167
|
+
return undefined;
|
|
168
|
+
return {
|
|
169
|
+
id: `handoff:${thread.id}`,
|
|
170
|
+
threadId: thread.id,
|
|
171
|
+
status: thread.status === "done" ? "completed" : thread.status === "abandoned" ? "cancelled" : "waiting",
|
|
172
|
+
from: thread.createdBy,
|
|
173
|
+
to: recipients,
|
|
174
|
+
acceptedBy: thread.status === "open" ? thread.owner : undefined,
|
|
175
|
+
completedBy: thread.status === "done" ? thread.owner : undefined,
|
|
176
|
+
createdAt: thread.createdAt,
|
|
177
|
+
updatedAt: thread.updatedAt,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function buildReview(task) {
|
|
181
|
+
if (task.type !== "review")
|
|
182
|
+
return undefined;
|
|
183
|
+
return {
|
|
184
|
+
id: `review:${task.id}`,
|
|
185
|
+
taskId: task.id,
|
|
186
|
+
reviewOf: task.reviewOf,
|
|
187
|
+
reviewer: task.assignedTo ?? task.assignee,
|
|
188
|
+
status: normalizeReviewStatus(task.reviewStatus) ?? "pending",
|
|
189
|
+
feedback: task.reviewFeedback ?? task.result,
|
|
190
|
+
createdAt: task.createdAt,
|
|
191
|
+
updatedAt: task.updatedAt,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function buildThreadWait(thread) {
|
|
195
|
+
const waitingOn = unique(thread.waitingOn ?? []);
|
|
196
|
+
if (waitingOn.length === 0)
|
|
197
|
+
return undefined;
|
|
198
|
+
return {
|
|
199
|
+
id: `wait:thread:${thread.id}`,
|
|
200
|
+
status: thread.status === "done" || thread.status === "abandoned" ? "satisfied" : "waiting",
|
|
201
|
+
subjectKind: "thread",
|
|
202
|
+
subjectId: thread.id,
|
|
203
|
+
waitingOn,
|
|
204
|
+
owner: thread.owner,
|
|
205
|
+
createdAt: thread.createdAt,
|
|
206
|
+
updatedAt: thread.updatedAt,
|
|
207
|
+
resolvedAt: thread.status === "done" || thread.status === "abandoned" ? thread.updatedAt : undefined,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function buildInboxEntries(thread) {
|
|
211
|
+
const participants = unique([...(thread.unreadBy ?? []), ...(thread.waitingOn ?? [])]);
|
|
212
|
+
return participants.map((participantId) => {
|
|
213
|
+
const waiting = (thread.waitingOn ?? []).includes(participantId);
|
|
214
|
+
return {
|
|
215
|
+
id: `inbox:${participantId}:thread:${thread.id}`,
|
|
216
|
+
participantId,
|
|
217
|
+
subjectKind: "thread",
|
|
218
|
+
subjectId: thread.id,
|
|
219
|
+
state: thread.status === "blocked" ? "blocked" : waiting ? "waiting" : "unread",
|
|
220
|
+
urgency: (waiting ? 10 : 0) + ((thread.unreadBy ?? []).includes(participantId) ? 3 : 0),
|
|
221
|
+
updatedAt: thread.updatedAt,
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function planRefFromPath(path, now) {
|
|
226
|
+
const sessionId = basename(path).replace(/\.md$/, "");
|
|
227
|
+
return {
|
|
228
|
+
id: `plan:${sessionId}`,
|
|
229
|
+
path,
|
|
230
|
+
ownerSessionId: sessionId,
|
|
231
|
+
title: sessionId,
|
|
232
|
+
createdAt: now,
|
|
233
|
+
updatedAt: now,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function continuityKindForPath(path) {
|
|
237
|
+
const normalized = path.replaceAll("\\", "/");
|
|
238
|
+
if (normalized.includes("/recordings/"))
|
|
239
|
+
return "recording";
|
|
240
|
+
if (normalized.includes("/status/"))
|
|
241
|
+
return "status";
|
|
242
|
+
if (normalized.includes("/history/"))
|
|
243
|
+
return "history";
|
|
244
|
+
return "context";
|
|
245
|
+
}
|
|
246
|
+
function continuityRefFromPath(path, now) {
|
|
247
|
+
const kind = continuityKindForPath(path);
|
|
248
|
+
const file = basename(path);
|
|
249
|
+
const sessionId = file.replace(/\.(jsonl|md|txt)$/, "");
|
|
250
|
+
return {
|
|
251
|
+
id: `${kind}:${sessionId}:${file}`,
|
|
252
|
+
kind,
|
|
253
|
+
path,
|
|
254
|
+
sessionId,
|
|
255
|
+
createdAt: now,
|
|
256
|
+
updatedAt: now,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function attachmentRefFromRecord(record) {
|
|
260
|
+
return {
|
|
261
|
+
id: record.id,
|
|
262
|
+
path: record.contentPath,
|
|
263
|
+
contentUrl: `/attachments/${record.id}/content`,
|
|
264
|
+
mediaType: record.mimeType,
|
|
265
|
+
createdAt: record.createdAt,
|
|
266
|
+
updatedAt: record.createdAt,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
export function buildRuntimeExchangeFromLegacySnapshot(input = {}) {
|
|
270
|
+
const now = input.now ?? new Date().toISOString();
|
|
271
|
+
const exchange = emptyRuntimeExchange(now);
|
|
272
|
+
const threads = input.threads ?? [];
|
|
273
|
+
const tasks = input.tasks ?? [];
|
|
274
|
+
exchange.threads = threads.map(toExchangeThread);
|
|
275
|
+
exchange.messages = (input.messages ?? []).map(toExchangeMessage);
|
|
276
|
+
exchange.tasks = tasks.map(toExchangeTask);
|
|
277
|
+
exchange.handoffs = threads
|
|
278
|
+
.map(buildHandoff)
|
|
279
|
+
.filter((handoff) => Boolean(handoff));
|
|
280
|
+
exchange.reviews = tasks.map(buildReview).filter((review) => Boolean(review));
|
|
281
|
+
exchange.waits = threads.map(buildThreadWait).filter((wait) => Boolean(wait));
|
|
282
|
+
exchange.inbox = threads.flatMap(buildInboxEntries);
|
|
283
|
+
exchange.planRefs = (input.planPaths ?? []).map((path) => planRefFromPath(path, now));
|
|
284
|
+
exchange.continuityRefs = [
|
|
285
|
+
...(input.historyPaths ?? []),
|
|
286
|
+
...(input.contextPaths ?? []),
|
|
287
|
+
...(input.recordingPaths ?? []),
|
|
288
|
+
...(input.statusPaths ?? []),
|
|
289
|
+
].map((path) => continuityRefFromPath(path, now));
|
|
290
|
+
exchange.attachmentRefs = (input.attachments ?? []).map(attachmentRefFromRecord);
|
|
291
|
+
return exchange;
|
|
292
|
+
}
|
|
293
|
+
export function importRuntimeExchangeFromLegacyFiles(input = {}) {
|
|
294
|
+
const now = input.now ?? new Date().toISOString();
|
|
295
|
+
const threads = readLegacyThreads();
|
|
296
|
+
return buildRuntimeExchangeFromLegacySnapshot({
|
|
297
|
+
now,
|
|
298
|
+
threads,
|
|
299
|
+
messages: readLegacyMessages(threads.map((thread) => thread.id)),
|
|
300
|
+
tasks: readLegacyTasks(),
|
|
301
|
+
planPaths: listFiles(getPlansDir(), (name) => name.endsWith(".md")),
|
|
302
|
+
historyPaths: [
|
|
303
|
+
...listFiles(getHistoryDir(), (name) => name.endsWith(".jsonl")),
|
|
304
|
+
...(input.additionalHistoryPaths ?? []),
|
|
305
|
+
],
|
|
306
|
+
contextPaths: [
|
|
307
|
+
...listNestedFiles(getContextDir(), (name) => name.endsWith(".md") || name.endsWith(".jsonl")),
|
|
308
|
+
...(input.additionalContextPaths ?? []),
|
|
309
|
+
],
|
|
310
|
+
recordingPaths: [
|
|
311
|
+
...listFiles(getRecordingsDir(), (name) => name.endsWith(".txt") || name.endsWith(".log")),
|
|
312
|
+
...(input.additionalRecordingPaths ?? []),
|
|
313
|
+
],
|
|
314
|
+
statusPaths: [...listFiles(getStatusDir(), (name) => name.endsWith(".md")), ...(input.additionalStatusPaths ?? [])],
|
|
315
|
+
attachments: readLegacyAttachments(),
|
|
316
|
+
});
|
|
317
|
+
}
|