@agent-native/dispatch 0.7.0 → 0.8.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.
Files changed (225) hide show
  1. package/README.md +37 -0
  2. package/dist/actions/apply-dream-proposal.d.ts +3 -0
  3. package/dist/actions/apply-dream-proposal.d.ts.map +1 -0
  4. package/dist/actions/apply-dream-proposal.js +11 -0
  5. package/dist/actions/apply-dream-proposal.js.map +1 -0
  6. package/dist/actions/create-dream-report.d.ts +3 -0
  7. package/dist/actions/create-dream-report.d.ts.map +1 -0
  8. package/dist/actions/create-dream-report.js +67 -0
  9. package/dist/actions/create-dream-report.js.map +1 -0
  10. package/dist/actions/create-workspace-resource.js +3 -3
  11. package/dist/actions/create-workspace-resource.js.map +1 -1
  12. package/dist/actions/delete-workspace-resource.js +1 -1
  13. package/dist/actions/delete-workspace-resource.js.map +1 -1
  14. package/dist/actions/ensure-dream-job.d.ts +3 -0
  15. package/dist/actions/ensure-dream-job.d.ts.map +1 -0
  16. package/dist/actions/ensure-dream-job.js +73 -0
  17. package/dist/actions/ensure-dream-job.js.map +1 -0
  18. package/dist/actions/get-dream-settings.d.ts +3 -0
  19. package/dist/actions/get-dream-settings.d.ts.map +1 -0
  20. package/dist/actions/get-dream-settings.js +11 -0
  21. package/dist/actions/get-dream-settings.js.map +1 -0
  22. package/dist/actions/get-dream.d.ts +3 -0
  23. package/dist/actions/get-dream.d.ts.map +1 -0
  24. package/dist/actions/get-dream.js +13 -0
  25. package/dist/actions/get-dream.js.map +1 -0
  26. package/dist/actions/get-workspace-resource-effective-context.d.ts +3 -0
  27. package/dist/actions/get-workspace-resource-effective-context.d.ts.map +1 -0
  28. package/dist/actions/get-workspace-resource-effective-context.js +27 -0
  29. package/dist/actions/get-workspace-resource-effective-context.js.map +1 -0
  30. package/dist/actions/index.d.ts.map +1 -1
  31. package/dist/actions/index.js +30 -4
  32. package/dist/actions/index.js.map +1 -1
  33. package/dist/actions/list-dream-candidates.d.ts +3 -0
  34. package/dist/actions/list-dream-candidates.d.ts.map +1 -0
  35. package/dist/actions/list-dream-candidates.js +68 -0
  36. package/dist/actions/list-dream-candidates.js.map +1 -0
  37. package/dist/actions/list-dreams.d.ts +3 -0
  38. package/dist/actions/list-dreams.d.ts.map +1 -0
  39. package/dist/actions/list-dreams.js +17 -0
  40. package/dist/actions/list-dreams.js.map +1 -0
  41. package/dist/actions/list-workspace-resources-for-app.d.ts +3 -0
  42. package/dist/actions/list-workspace-resources-for-app.d.ts.map +1 -0
  43. package/dist/actions/list-workspace-resources-for-app.js +12 -0
  44. package/dist/actions/list-workspace-resources-for-app.js.map +1 -0
  45. package/dist/actions/list-workspace-resources.js +1 -1
  46. package/dist/actions/list-workspace-resources.js.map +1 -1
  47. package/dist/actions/navigate.d.ts +1 -0
  48. package/dist/actions/navigate.d.ts.map +1 -1
  49. package/dist/actions/navigate.js +2 -1
  50. package/dist/actions/navigate.js.map +1 -1
  51. package/dist/actions/preview-dream-proposal.d.ts +3 -0
  52. package/dist/actions/preview-dream-proposal.d.ts.map +1 -0
  53. package/dist/actions/preview-dream-proposal.js +13 -0
  54. package/dist/actions/preview-dream-proposal.js.map +1 -0
  55. package/dist/actions/preview-workspace-resource-change.d.ts +3 -0
  56. package/dist/actions/preview-workspace-resource-change.d.ts.map +1 -0
  57. package/dist/actions/preview-workspace-resource-change.js +24 -0
  58. package/dist/actions/preview-workspace-resource-change.js.map +1 -0
  59. package/dist/actions/reject-dream-proposal.d.ts +3 -0
  60. package/dist/actions/reject-dream-proposal.d.ts.map +1 -0
  61. package/dist/actions/reject-dream-proposal.js +12 -0
  62. package/dist/actions/reject-dream-proposal.js.map +1 -0
  63. package/dist/actions/restore-starter-workspace-resources.d.ts +3 -0
  64. package/dist/actions/restore-starter-workspace-resources.d.ts.map +1 -0
  65. package/dist/actions/restore-starter-workspace-resources.js +14 -0
  66. package/dist/actions/restore-starter-workspace-resources.js.map +1 -0
  67. package/dist/actions/send-code-agent-remote-command.d.ts +3 -0
  68. package/dist/actions/send-code-agent-remote-command.d.ts.map +1 -0
  69. package/dist/actions/send-code-agent-remote-command.js +53 -0
  70. package/dist/actions/send-code-agent-remote-command.js.map +1 -0
  71. package/dist/actions/set-dream-settings.d.ts +3 -0
  72. package/dist/actions/set-dream-settings.d.ts.map +1 -0
  73. package/dist/actions/set-dream-settings.js +41 -0
  74. package/dist/actions/set-dream-settings.js.map +1 -0
  75. package/dist/actions/update-workspace-resource.js +1 -1
  76. package/dist/actions/update-workspace-resource.js.map +1 -1
  77. package/dist/actions/view-screen.d.ts.map +1 -1
  78. package/dist/actions/view-screen.js +73 -2
  79. package/dist/actions/view-screen.js.map +1 -1
  80. package/dist/components/approval-value-block.d.ts +7 -0
  81. package/dist/components/approval-value-block.d.ts.map +1 -0
  82. package/dist/components/approval-value-block.js +22 -0
  83. package/dist/components/approval-value-block.js.map +1 -0
  84. package/dist/components/create-app-popover.d.ts.map +1 -1
  85. package/dist/components/create-app-popover.js +3 -2
  86. package/dist/components/create-app-popover.js.map +1 -1
  87. package/dist/components/layout/Layout.d.ts.map +1 -1
  88. package/dist/components/layout/Layout.js +8 -1
  89. package/dist/components/layout/Layout.js.map +1 -1
  90. package/dist/components/ui/chart.d.ts +1 -1
  91. package/dist/components/workspace-app-card.d.ts.map +1 -1
  92. package/dist/components/workspace-app-card.js +25 -4
  93. package/dist/components/workspace-app-card.js.map +1 -1
  94. package/dist/components/workspace-resource-effective-stack.d.ts +11 -0
  95. package/dist/components/workspace-resource-effective-stack.d.ts.map +1 -0
  96. package/dist/components/workspace-resource-effective-stack.js +59 -0
  97. package/dist/components/workspace-resource-effective-stack.js.map +1 -0
  98. package/dist/components/workspace-resource-impact-preview.d.ts +9 -0
  99. package/dist/components/workspace-resource-impact-preview.d.ts.map +1 -0
  100. package/dist/components/workspace-resource-impact-preview.js +39 -0
  101. package/dist/components/workspace-resource-impact-preview.js.map +1 -0
  102. package/dist/db/migrations.d.ts.map +1 -1
  103. package/dist/db/migrations.js +59 -0
  104. package/dist/db/migrations.js.map +1 -1
  105. package/dist/db/schema.d.ts +714 -0
  106. package/dist/db/schema.d.ts.map +1 -1
  107. package/dist/db/schema.js +44 -2
  108. package/dist/db/schema.js.map +1 -1
  109. package/dist/hooks/use-navigation-state.d.ts +3 -0
  110. package/dist/hooks/use-navigation-state.d.ts.map +1 -1
  111. package/dist/hooks/use-navigation-state.js +23 -3
  112. package/dist/hooks/use-navigation-state.js.map +1 -1
  113. package/dist/lib/utils.d.ts +2 -1
  114. package/dist/lib/utils.d.ts.map +1 -1
  115. package/dist/lib/utils.js +5 -1
  116. package/dist/lib/utils.js.map +1 -1
  117. package/dist/routes/index.d.ts.map +1 -1
  118. package/dist/routes/index.js +1 -0
  119. package/dist/routes/index.js.map +1 -1
  120. package/dist/routes/pages/approval.d.ts.map +1 -1
  121. package/dist/routes/pages/approval.js +4 -1
  122. package/dist/routes/pages/approval.js.map +1 -1
  123. package/dist/routes/pages/approvals.js +1 -1
  124. package/dist/routes/pages/approvals.js.map +1 -1
  125. package/dist/routes/pages/dream-settings.d.ts +34 -0
  126. package/dist/routes/pages/dream-settings.d.ts.map +1 -0
  127. package/dist/routes/pages/dream-settings.js +68 -0
  128. package/dist/routes/pages/dream-settings.js.map +1 -0
  129. package/dist/routes/pages/dreams.d.ts +5 -0
  130. package/dist/routes/pages/dreams.d.ts.map +1 -0
  131. package/dist/routes/pages/dreams.js +435 -0
  132. package/dist/routes/pages/dreams.js.map +1 -0
  133. package/dist/routes/pages/workspace.d.ts.map +1 -1
  134. package/dist/routes/pages/workspace.js +187 -35
  135. package/dist/routes/pages/workspace.js.map +1 -1
  136. package/dist/server/lib/app-creation-store.d.ts.map +1 -1
  137. package/dist/server/lib/app-creation-store.js +3 -2
  138. package/dist/server/lib/app-creation-store.js.map +1 -1
  139. package/dist/server/lib/dispatch-integrations.d.ts +1 -1
  140. package/dist/server/lib/dispatch-integrations.d.ts.map +1 -1
  141. package/dist/server/lib/dispatch-integrations.js +9 -4
  142. package/dist/server/lib/dispatch-integrations.js.map +1 -1
  143. package/dist/server/lib/dispatch-remote-commands.d.ts +83 -0
  144. package/dist/server/lib/dispatch-remote-commands.d.ts.map +1 -0
  145. package/dist/server/lib/dispatch-remote-commands.js +256 -0
  146. package/dist/server/lib/dispatch-remote-commands.js.map +1 -0
  147. package/dist/server/lib/dispatch-store.d.ts +26 -0
  148. package/dist/server/lib/dispatch-store.d.ts.map +1 -1
  149. package/dist/server/lib/dispatch-store.js +17 -1
  150. package/dist/server/lib/dispatch-store.js.map +1 -1
  151. package/dist/server/lib/dreams-store.d.ts +398 -0
  152. package/dist/server/lib/dreams-store.d.ts.map +1 -0
  153. package/dist/server/lib/dreams-store.js +2330 -0
  154. package/dist/server/lib/dreams-store.js.map +1 -0
  155. package/dist/server/lib/thread-debug-store.d.ts +2 -2
  156. package/dist/server/lib/vault-store.d.ts +1 -1
  157. package/dist/server/lib/workspace-resources-store.d.ts +181 -17
  158. package/dist/server/lib/workspace-resources-store.d.ts.map +1 -1
  159. package/dist/server/lib/workspace-resources-store.js +737 -108
  160. package/dist/server/lib/workspace-resources-store.js.map +1 -1
  161. package/package.json +4 -2
  162. package/src/actions/apply-dream-proposal.ts +12 -0
  163. package/src/actions/create-dream-report.ts +76 -0
  164. package/src/actions/create-workspace-resource.ts +3 -3
  165. package/src/actions/delete-workspace-resource.ts +1 -1
  166. package/src/actions/ensure-dream-job.ts +76 -0
  167. package/src/actions/get-dream-settings.ts +12 -0
  168. package/src/actions/get-dream.ts +14 -0
  169. package/src/actions/get-workspace-resource-effective-context.ts +34 -0
  170. package/src/actions/index.spec.ts +26 -0
  171. package/src/actions/index.ts +31 -4
  172. package/src/actions/list-dream-candidates.ts +77 -0
  173. package/src/actions/list-dreams.ts +17 -0
  174. package/src/actions/list-workspace-resources-for-app.ts +13 -0
  175. package/src/actions/list-workspace-resources.ts +1 -1
  176. package/src/actions/navigate.ts +2 -1
  177. package/src/actions/preview-dream-proposal.ts +14 -0
  178. package/src/actions/preview-workspace-resource-change.ts +25 -0
  179. package/src/actions/reject-dream-proposal.ts +12 -0
  180. package/src/actions/restore-starter-workspace-resources.ts +17 -0
  181. package/src/actions/send-code-agent-remote-command.ts +59 -0
  182. package/src/actions/set-dream-settings.spec.ts +81 -0
  183. package/src/actions/set-dream-settings.ts +44 -0
  184. package/src/actions/update-workspace-resource.ts +1 -1
  185. package/src/actions/view-screen.ts +90 -2
  186. package/src/components/approval-value-block.spec.tsx +59 -0
  187. package/src/components/approval-value-block.tsx +33 -0
  188. package/src/components/create-app-popover.tsx +3 -2
  189. package/src/components/layout/Layout.tsx +8 -0
  190. package/src/components/workspace-app-card.tsx +166 -1
  191. package/src/components/workspace-resource-effective-stack.spec.tsx +125 -0
  192. package/src/components/workspace-resource-effective-stack.tsx +141 -0
  193. package/src/components/workspace-resource-impact-preview.spec.tsx +147 -0
  194. package/src/components/workspace-resource-impact-preview.tsx +116 -0
  195. package/src/db/migrations.ts +59 -0
  196. package/src/db/schema.ts +46 -2
  197. package/src/hooks/use-navigation-state.ts +24 -5
  198. package/src/lib/utils.ts +6 -1
  199. package/src/routes/index.ts +1 -0
  200. package/src/routes/pages/approval.tsx +14 -1
  201. package/src/routes/pages/approvals.tsx +1 -1
  202. package/src/routes/pages/dream-settings.spec.ts +130 -0
  203. package/src/routes/pages/dream-settings.ts +103 -0
  204. package/src/routes/pages/dreams.tsx +1828 -0
  205. package/src/routes/pages/workspace.tsx +577 -97
  206. package/src/server/lib/app-creation-store.ts +3 -2
  207. package/src/server/lib/dispatch-integrations.ts +10 -3
  208. package/src/server/lib/dispatch-remote-commands.spec.ts +167 -0
  209. package/src/server/lib/dispatch-remote-commands.ts +375 -0
  210. package/src/server/lib/dispatch-store.ts +37 -1
  211. package/src/server/lib/dreams-store.spec.ts +1492 -0
  212. package/src/server/lib/dreams-store.ts +3168 -0
  213. package/src/server/lib/workspace-resource-approval-lifecycle.spec.ts +236 -0
  214. package/src/server/lib/workspace-resources-store.spec.ts +1106 -0
  215. package/src/server/lib/workspace-resources-store.ts +1001 -134
  216. package/dist/actions/sync-workspace-resources-to-all.d.ts +0 -3
  217. package/dist/actions/sync-workspace-resources-to-all.d.ts.map +0 -1
  218. package/dist/actions/sync-workspace-resources-to-all.js +0 -9
  219. package/dist/actions/sync-workspace-resources-to-all.js.map +0 -1
  220. package/dist/actions/sync-workspace-resources-to-app.d.ts +0 -3
  221. package/dist/actions/sync-workspace-resources-to-app.d.ts.map +0 -1
  222. package/dist/actions/sync-workspace-resources-to-app.js +0 -11
  223. package/dist/actions/sync-workspace-resources-to-app.js.map +0 -1
  224. package/src/actions/sync-workspace-resources-to-all.ts +0 -10
  225. package/src/actions/sync-workspace-resources-to-app.ts +0 -12
@@ -0,0 +1,147 @@
1
+ // @vitest-environment happy-dom
2
+ import React, { act } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
+ import {
6
+ ImpactPreview,
7
+ workspaceResourceMutationMessage,
8
+ } from "./workspace-resource-impact-preview";
9
+
10
+ const queryState = vi.hoisted(() => ({
11
+ result: { data: null as any, isLoading: false },
12
+ calls: [] as any[],
13
+ }));
14
+
15
+ vi.mock("@agent-native/core/client", () => ({
16
+ useActionQuery: (...args: any[]) => {
17
+ queryState.calls.push(args);
18
+ return queryState.result;
19
+ },
20
+ }));
21
+
22
+ describe("ImpactPreview", () => {
23
+ let container: HTMLDivElement;
24
+ let root: Root;
25
+
26
+ beforeEach(() => {
27
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
28
+ queryState.calls = [];
29
+ queryState.result = { data: null, isLoading: false };
30
+ container = document.createElement("div");
31
+ document.body.appendChild(container);
32
+ root = createRoot(container);
33
+ });
34
+
35
+ afterEach(() => {
36
+ act(() => root.unmount());
37
+ container.remove();
38
+ vi.unstubAllGlobals();
39
+ });
40
+
41
+ it("renders All-app approval impact and override details", () => {
42
+ queryState.result = {
43
+ isLoading: false,
44
+ data: {
45
+ affectsAllApps: true,
46
+ affectedApps: { count: 4 },
47
+ approval: { willRequestApproval: true },
48
+ overrides: {
49
+ count: 2,
50
+ items: [
51
+ {
52
+ scope: "shared",
53
+ owner: "__shared__",
54
+ label: "Organization/app override",
55
+ updatedAt: 1,
56
+ },
57
+ {
58
+ scope: "personal",
59
+ owner: "person@example.test",
60
+ label: "Personal override (person@example.test)",
61
+ updatedAt: 2,
62
+ },
63
+ ],
64
+ },
65
+ },
66
+ };
67
+
68
+ act(() => {
69
+ root.render(
70
+ <ImpactPreview
71
+ operation="update"
72
+ resourceId="resource_1"
73
+ scope="all"
74
+ />,
75
+ );
76
+ });
77
+
78
+ expect(queryState.calls[0]).toEqual([
79
+ "preview-workspace-resource-change",
80
+ {
81
+ operation: "update",
82
+ resourceId: "resource_1",
83
+ path: undefined,
84
+ scope: "all",
85
+ },
86
+ { enabled: true },
87
+ ]);
88
+ expect(container.textContent).toContain("All apps impact");
89
+ expect(container.textContent).toContain("Approval required");
90
+ expect(container.textContent).toContain("2 overrides");
91
+ expect(container.textContent).toContain(
92
+ "This change applies to every workspace app (4 discovered).",
93
+ );
94
+ expect(container.textContent).toContain(
95
+ "It will be queued for approval before it takes effect.",
96
+ );
97
+ expect(container.textContent).toContain("Organization/app override");
98
+ expect(container.textContent).toContain(
99
+ "Personal override (person@example.test)",
100
+ );
101
+ });
102
+
103
+ it("renders selected-only changes as immediate", () => {
104
+ queryState.result = {
105
+ isLoading: false,
106
+ data: {
107
+ affectsAllApps: false,
108
+ affectedApps: { count: null },
109
+ approval: { willRequestApproval: false },
110
+ overrides: { count: 0, items: [] },
111
+ },
112
+ };
113
+
114
+ act(() => {
115
+ root.render(
116
+ <ImpactPreview
117
+ operation="create"
118
+ path="context/private-launch.md"
119
+ scope="selected"
120
+ />,
121
+ );
122
+ });
123
+
124
+ expect(container.textContent).toContain("Selected only");
125
+ expect(container.textContent).toContain(
126
+ "This change only applies to explicitly granted apps.",
127
+ );
128
+ expect(container.textContent).toContain(
129
+ "It will take effect immediately when saved.",
130
+ );
131
+ });
132
+
133
+ it("uses approval-request mutation copy only for workspace resource approvals", () => {
134
+ expect(
135
+ workspaceResourceMutationMessage(
136
+ { status: "pending", changeType: "workspace-resource.update" },
137
+ "Resource updated",
138
+ ),
139
+ ).toBe("Approval requested");
140
+ expect(
141
+ workspaceResourceMutationMessage(
142
+ { status: "pending", changeType: "dream-proposal.apply" },
143
+ "Resource updated",
144
+ ),
145
+ ).toBe("Resource updated");
146
+ });
147
+ });
@@ -0,0 +1,116 @@
1
+ import { useActionQuery } from "@agent-native/core/client";
2
+ import { Badge } from "@/components/ui/badge";
3
+ import { Skeleton } from "@/components/ui/skeleton";
4
+ import { formatResourceTimestamp } from "./workspace-resource-effective-stack";
5
+
6
+ function isApprovalRequest(result: any): boolean {
7
+ return (
8
+ result?.status === "pending" &&
9
+ typeof result?.changeType === "string" &&
10
+ result.changeType.startsWith("workspace-resource.")
11
+ );
12
+ }
13
+
14
+ export function workspaceResourceMutationMessage(
15
+ result: any,
16
+ fallback: string,
17
+ ): string {
18
+ return isApprovalRequest(result) ? "Approval requested" : fallback;
19
+ }
20
+
21
+ export function ImpactPreview({
22
+ operation,
23
+ resourceId,
24
+ path,
25
+ scope,
26
+ enabled = true,
27
+ }: {
28
+ operation: "create" | "update" | "delete";
29
+ resourceId?: string;
30
+ path?: string;
31
+ scope?: "all" | "selected";
32
+ enabled?: boolean;
33
+ }) {
34
+ const { data: impact, isLoading } = useActionQuery(
35
+ "preview-workspace-resource-change",
36
+ {
37
+ operation,
38
+ resourceId,
39
+ path,
40
+ scope,
41
+ },
42
+ { enabled: enabled && Boolean(resourceId || path) },
43
+ );
44
+
45
+ if (!enabled || (!resourceId && !path)) return null;
46
+
47
+ if (isLoading) {
48
+ return (
49
+ <div className="rounded-lg border bg-muted/30 p-3">
50
+ <Skeleton className="h-4 w-40" />
51
+ <Skeleton className="mt-2 h-3 w-72" />
52
+ </div>
53
+ );
54
+ }
55
+
56
+ const data = impact as any;
57
+ if (!data) return null;
58
+ const affectsAllApps = data.affectsAllApps === true;
59
+ const appCount = data.affectedApps?.count;
60
+ const overrides = data.overrides ?? { count: 0, items: [] };
61
+ const willRequestApproval = data.approval?.willRequestApproval === true;
62
+
63
+ return (
64
+ <div className="rounded-lg border bg-muted/30 p-3 text-xs">
65
+ <div className="flex flex-wrap items-center gap-2">
66
+ <Badge variant={affectsAllApps ? "secondary" : "outline"}>
67
+ {affectsAllApps ? "All apps impact" : "Selected only"}
68
+ </Badge>
69
+ {willRequestApproval ? (
70
+ <Badge
71
+ variant="outline"
72
+ className="border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300"
73
+ >
74
+ Approval required
75
+ </Badge>
76
+ ) : null}
77
+ {overrides.count > 0 ? (
78
+ <Badge variant="outline">
79
+ {overrides.count} override{overrides.count === 1 ? "" : "s"}
80
+ </Badge>
81
+ ) : null}
82
+ </div>
83
+ <p className="mt-2 leading-relaxed text-muted-foreground">
84
+ {affectsAllApps
85
+ ? `This change applies to every workspace app${typeof appCount === "number" ? ` (${appCount} discovered)` : ""}.`
86
+ : "This change only applies to explicitly granted apps."}{" "}
87
+ {willRequestApproval
88
+ ? "It will be queued for approval before it takes effect."
89
+ : "It will take effect immediately when saved."}
90
+ </p>
91
+ {overrides.count > 0 ? (
92
+ <div className="mt-2 space-y-1">
93
+ {overrides.items.slice(0, 4).map((override: any) => (
94
+ <div
95
+ key={`${override.scope}:${override.owner}`}
96
+ className="flex items-center justify-between gap-3 rounded-md border bg-background px-2 py-1.5"
97
+ >
98
+ <span className="min-w-0 truncate text-muted-foreground">
99
+ {override.label}
100
+ </span>
101
+ <span className="shrink-0 font-mono text-[11px] text-muted-foreground">
102
+ {formatResourceTimestamp(override.updatedAt)}
103
+ </span>
104
+ </div>
105
+ ))}
106
+ {overrides.count > 4 ? (
107
+ <div className="text-muted-foreground">
108
+ +{overrides.count - 4} more override
109
+ {overrides.count - 4 === 1 ? "" : "s"}
110
+ </div>
111
+ ) : null}
112
+ </div>
113
+ ) : null}
114
+ </div>
115
+ );
116
+ }
@@ -162,4 +162,63 @@ export const dispatchMigrations: Array<{ version: number; sql: string }> = [
162
162
  );
163
163
  `,
164
164
  },
165
+ {
166
+ version: 3,
167
+ sql: `
168
+ CREATE TABLE IF NOT EXISTS dispatch_dreams (
169
+ id TEXT PRIMARY KEY,
170
+ owner_email TEXT NOT NULL,
171
+ org_id TEXT,
172
+ source_id TEXT NOT NULL,
173
+ title TEXT NOT NULL,
174
+ status TEXT NOT NULL,
175
+ query TEXT,
176
+ report TEXT,
177
+ summary TEXT,
178
+ candidate_count INTEGER NOT NULL,
179
+ inspected_thread_count INTEGER NOT NULL,
180
+ created_by TEXT NOT NULL,
181
+ error TEXT,
182
+ started_at INTEGER NOT NULL,
183
+ completed_at INTEGER,
184
+ created_at INTEGER NOT NULL,
185
+ updated_at INTEGER NOT NULL
186
+ );
187
+
188
+ CREATE TABLE IF NOT EXISTS dispatch_dream_proposals (
189
+ id TEXT PRIMARY KEY,
190
+ dream_id TEXT NOT NULL,
191
+ owner_email TEXT NOT NULL,
192
+ org_id TEXT,
193
+ target_type TEXT NOT NULL,
194
+ target_path TEXT NOT NULL,
195
+ title TEXT NOT NULL,
196
+ summary TEXT NOT NULL,
197
+ rationale TEXT NOT NULL,
198
+ content TEXT NOT NULL,
199
+ evidence TEXT NOT NULL,
200
+ confidence INTEGER NOT NULL,
201
+ risk TEXT NOT NULL,
202
+ status TEXT NOT NULL,
203
+ applied_by TEXT,
204
+ applied_at INTEGER,
205
+ rejected_by TEXT,
206
+ rejected_at INTEGER,
207
+ created_at INTEGER NOT NULL,
208
+ updated_at INTEGER NOT NULL
209
+ );
210
+
211
+ CREATE INDEX IF NOT EXISTS dispatch_dreams_owner_updated_idx
212
+ ON dispatch_dreams (owner_email, org_id, updated_at);
213
+
214
+ CREATE INDEX IF NOT EXISTS dispatch_dream_proposals_dream_status_idx
215
+ ON dispatch_dream_proposals (dream_id, status);
216
+ `,
217
+ },
218
+ {
219
+ version: 4,
220
+ sql: `
221
+ ALTER TABLE dispatch_dreams ADD COLUMN source_health TEXT;
222
+ `,
223
+ },
165
224
  ];
package/src/db/schema.ts CHANGED
@@ -73,6 +73,50 @@ export const dispatchAuditEvents = table("dispatch_audit_events", {
73
73
  createdAt: integer("created_at").notNull(),
74
74
  });
75
75
 
76
+ export const dispatchDreams = table("dispatch_dreams", {
77
+ id: text("id").primaryKey(),
78
+ ownerEmail: text("owner_email").notNull(),
79
+ orgId: text("org_id"),
80
+ sourceId: text("source_id").notNull(),
81
+ title: text("title").notNull(),
82
+ status: text("status").notNull(),
83
+ query: text("query"),
84
+ report: text("report"),
85
+ summary: text("summary"),
86
+ sourceHealth: text("source_health"),
87
+ candidateCount: integer("candidate_count").notNull(),
88
+ inspectedThreadCount: integer("inspected_thread_count").notNull(),
89
+ createdBy: text("created_by").notNull(),
90
+ error: text("error"),
91
+ startedAt: integer("started_at").notNull(),
92
+ completedAt: integer("completed_at"),
93
+ createdAt: integer("created_at").notNull(),
94
+ updatedAt: integer("updated_at").notNull(),
95
+ });
96
+
97
+ export const dispatchDreamProposals = table("dispatch_dream_proposals", {
98
+ id: text("id").primaryKey(),
99
+ dreamId: text("dream_id").notNull(),
100
+ ownerEmail: text("owner_email").notNull(),
101
+ orgId: text("org_id"),
102
+ targetType: text("target_type").notNull(),
103
+ targetPath: text("target_path").notNull(),
104
+ title: text("title").notNull(),
105
+ summary: text("summary").notNull(),
106
+ rationale: text("rationale").notNull(),
107
+ content: text("content").notNull(),
108
+ evidence: text("evidence").notNull(),
109
+ confidence: integer("confidence").notNull(),
110
+ risk: text("risk").notNull(),
111
+ status: text("status").notNull(),
112
+ appliedBy: text("applied_by"),
113
+ appliedAt: integer("applied_at"),
114
+ rejectedBy: text("rejected_by"),
115
+ rejectedAt: integer("rejected_at"),
116
+ createdAt: integer("created_at").notNull(),
117
+ updatedAt: integer("updated_at").notNull(),
118
+ });
119
+
76
120
  // ─── Vault: workspace-wide secret management ───────────────────────
77
121
 
78
122
  export const vaultSecrets = table("vault_secrets", {
@@ -141,7 +185,7 @@ export const workspaceResources = table("workspace_resources", {
141
185
  description: text("description"),
142
186
  path: text("path").notNull(), // resource path, e.g. "skills/designer.md"
143
187
  content: text("content").notNull(),
144
- scope: text("scope").notNull(), // "all" (push to all apps) | "selected" (grant per-app)
188
+ scope: text("scope").notNull(), // "all" (runtime inherited) | "selected" (grant per-app)
145
189
  createdBy: text("created_by").notNull(),
146
190
  createdAt: integer("created_at").notNull(),
147
191
  updatedAt: integer("updated_at").notNull(),
@@ -154,7 +198,7 @@ export const workspaceResourceGrants = table("workspace_resource_grants", {
154
198
  resourceId: text("resource_id").notNull(),
155
199
  appId: text("app_id").notNull(),
156
200
  status: text("status").notNull(), // "active" | "revoked"
157
- syncedAt: integer("synced_at"),
201
+ syncedAt: integer("synced_at"), // legacy column retained for older rows
158
202
  createdAt: integer("created_at").notNull(),
159
203
  updatedAt: integer("updated_at").notNull(),
160
204
  });
@@ -14,6 +14,9 @@ import type {
14
14
  export interface NavigationState {
15
15
  view: string;
16
16
  path?: string;
17
+ dreamId?: string;
18
+ sourceId?: string;
19
+ query?: string;
17
20
  }
18
21
 
19
22
  export function useNavigationState(extensions?: DispatchExtensionConfig) {
@@ -24,10 +27,19 @@ export function useNavigationState(extensions?: DispatchExtensionConfig) {
24
27
  // Sync current route to application state
25
28
  useEffect(() => {
26
29
  const localPathname = routerPath(location.pathname);
30
+ const params = new URLSearchParams(location.search);
27
31
  const state: NavigationState = {
28
32
  view: resolveView(localPathname, extensions),
29
33
  path: appPath(localPathname),
30
34
  };
35
+ if (state.view === "dreams") {
36
+ const dreamId = params.get("dreamId");
37
+ const sourceId = params.get("sourceId");
38
+ const query = params.get("query");
39
+ if (dreamId) state.dreamId = dreamId;
40
+ if (sourceId) state.sourceId = sourceId;
41
+ if (query) state.query = query;
42
+ }
31
43
 
32
44
  fetch(agentNativePath("/_agent-native/application-state/navigation"), {
33
45
  method: "PUT",
@@ -35,7 +47,7 @@ export function useNavigationState(extensions?: DispatchExtensionConfig) {
35
47
  headers: { "Content-Type": "application/json" },
36
48
  body: JSON.stringify(state),
37
49
  }).catch(() => {});
38
- }, [extensions, location.pathname]);
50
+ }, [extensions, location.pathname, location.search]);
39
51
 
40
52
  // Listen for navigate commands from agent
41
53
  const { data: navCommand } = useQuery({
@@ -66,10 +78,14 @@ export function useNavigationState(extensions?: DispatchExtensionConfig) {
66
78
  const cmd = navCommand as NavigationState;
67
79
 
68
80
  // Navigate to a specific path or resolve view name to path
69
- const path = routerPath(
70
- cmd.path || resolvePath(cmd.view, extensions) || "/overview",
71
- );
72
- navigate(path);
81
+ const resolvedPath =
82
+ cmd.path || resolvePath(cmd.view, extensions) || "/overview";
83
+ const path =
84
+ cmd.view === "dreams" && cmd.dreamId && !resolvedPath.includes("?")
85
+ ? `${resolvedPath}?dreamId=${encodeURIComponent(cmd.dreamId)}`
86
+ : resolvedPath;
87
+ const nextPath = routerPath(path);
88
+ navigate(nextPath);
73
89
  qc.setQueryData(["navigate-command"], null);
74
90
  }, [extensions, navCommand, navigate, qc]);
75
91
  }
@@ -139,6 +155,7 @@ function resolveView(
139
155
  if (pathname.startsWith("/identities")) return "identities";
140
156
  if (pathname.startsWith("/approvals")) return "approvals";
141
157
  if (pathname.startsWith("/audit")) return "audit";
158
+ if (pathname.startsWith("/dreams")) return "dreams";
142
159
  if (pathname.startsWith("/thread-debug")) return "thread-debug";
143
160
  if (pathname.startsWith("/team")) return "team";
144
161
  return "overview";
@@ -180,6 +197,8 @@ function resolvePath(
180
197
  return "/approvals";
181
198
  case "audit":
182
199
  return "/audit";
200
+ case "dreams":
201
+ return "/dreams";
183
202
  case "thread-debug":
184
203
  case "threads":
185
204
  return "/thread-debug";
package/src/lib/utils.ts CHANGED
@@ -1 +1,6 @@
1
- export { cn } from "@agent-native/core";
1
+ import { type ClassValue, clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -46,6 +46,7 @@ export const dispatchRoutes: RouteConfig = [
46
46
  route("approval", "./pages/approval.js"),
47
47
  route("approvals", "./pages/approvals.js"),
48
48
  route("audit", "./pages/audit.js"),
49
+ route("dreams", "./pages/dreams.js"),
49
50
  route("thread-debug", "./pages/thread-debug.js"),
50
51
  route("team", "./pages/team.js"),
51
52
  route("extensions", "./pages/extensions._index.js"),
@@ -7,6 +7,10 @@ import {
7
7
  appPath,
8
8
  } from "@agent-native/core/client";
9
9
  import { toast } from "sonner";
10
+ import {
11
+ ApprovalValueBlock,
12
+ parseApprovalValue,
13
+ } from "@/components/approval-value-block";
10
14
  import { Button } from "@/components/ui/button";
11
15
  import { Badge } from "@/components/ui/badge";
12
16
  import { Skeleton } from "@/components/ui/skeleton";
@@ -168,10 +172,12 @@ export default function ApprovalPreviewRoute() {
168
172
  }
169
173
 
170
174
  const isPending = approval.status === "pending";
175
+ const beforeValue = parseApprovalValue(approval.beforeValue);
176
+ const afterValue = parseApprovalValue(approval.afterValue);
171
177
 
172
178
  return (
173
179
  <div className="flex min-h-screen items-start justify-center bg-background p-6">
174
- <div className="w-full max-w-md space-y-4">
180
+ <div className="w-full max-w-2xl space-y-4">
175
181
  <div className="rounded-2xl border bg-card p-5">
176
182
  <div className="flex items-start gap-3">
177
183
  <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border bg-muted text-foreground">
@@ -224,6 +230,13 @@ export default function ApprovalPreviewRoute() {
224
230
  )}
225
231
  </div>
226
232
 
233
+ {(beforeValue !== null || afterValue !== null) && (
234
+ <div className="mt-4 grid gap-3 md:grid-cols-2">
235
+ <ApprovalValueBlock label="Before" value={beforeValue} />
236
+ <ApprovalValueBlock label="After" value={afterValue} />
237
+ </div>
238
+ )}
239
+
227
240
  {isPending && (
228
241
  <div className="mt-4 flex gap-2">
229
242
  <Button
@@ -58,7 +58,7 @@ export default function ApprovalsRoute() {
58
58
  </div>
59
59
  <div className="mt-1 text-xs text-muted-foreground">
60
60
  {hasOrg
61
- ? "Applies to saved destinations and dispatch settings today."
61
+ ? "Applies to saved destinations, shared dream proposals, All-app workspace resources, and dispatch settings."
62
62
  : "Requires a team workspace. Set one up on the Team page."}
63
63
  </div>
64
64
  </div>
@@ -0,0 +1,130 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ dreamSettingsToDraft,
4
+ dreamSettingsUpdateFromDraft,
5
+ splitSourceIds,
6
+ type DreamSettingsDraft,
7
+ } from "./dream-settings.js";
8
+
9
+ function draft(
10
+ overrides: Partial<DreamSettingsDraft> = {},
11
+ ): DreamSettingsDraft {
12
+ return {
13
+ enabled: true,
14
+ schedule: "0 9 * * 1",
15
+ sourceId: "all",
16
+ sourceIdsText: "",
17
+ allSources: true,
18
+ query: "",
19
+ limit: "8",
20
+ sourceTimeoutMs: "30000",
21
+ sourceConcurrency: "2",
22
+ sourceStartStaggerMs: "250",
23
+ threadConcurrency: "3",
24
+ threadTimeoutMs: "8000",
25
+ minCandidateCount: "1",
26
+ ...overrides,
27
+ };
28
+ }
29
+
30
+ describe("dream settings payload helpers", () => {
31
+ it("normalizes persisted settings into editable draft text", () => {
32
+ expect(
33
+ dreamSettingsToDraft({
34
+ enabled: true,
35
+ schedule: "0 8 * * 2",
36
+ sourceId: "selected",
37
+ sourceIds: ["mail", "calendar"],
38
+ allSources: false,
39
+ query: "memory",
40
+ limit: 12,
41
+ sourceTimeoutMs: 45000,
42
+ sourceConcurrency: 4,
43
+ sourceStartStaggerMs: 500,
44
+ threadConcurrency: 5,
45
+ threadTimeoutMs: 9000,
46
+ minCandidateCount: 2,
47
+ }),
48
+ ).toMatchObject({
49
+ enabled: true,
50
+ schedule: "0 8 * * 2",
51
+ sourceId: "selected",
52
+ sourceIdsText: "mail\ncalendar",
53
+ allSources: false,
54
+ query: "memory",
55
+ limit: "12",
56
+ sourceTimeoutMs: "45000",
57
+ sourceConcurrency: "4",
58
+ sourceStartStaggerMs: "500",
59
+ threadConcurrency: "5",
60
+ threadTimeoutMs: "9000",
61
+ minCandidateCount: "2",
62
+ });
63
+ });
64
+
65
+ it("splits explicit source ids from commas and newlines", () => {
66
+ expect(splitSourceIds(" mail\ncalendar, analytics ,, \nbrain ")).toEqual([
67
+ "mail",
68
+ "calendar",
69
+ "analytics",
70
+ "brain",
71
+ ]);
72
+ });
73
+
74
+ it("builds a save payload that clears source ids and query", () => {
75
+ expect(
76
+ dreamSettingsUpdateFromDraft(
77
+ draft({
78
+ enabled: false,
79
+ schedule: " 0 10 * * 3 ",
80
+ sourceId: " current ",
81
+ sourceIdsText: "",
82
+ allSources: false,
83
+ query: " ",
84
+ minCandidateCount: "0",
85
+ }),
86
+ ),
87
+ ).toMatchObject({
88
+ enabled: false,
89
+ schedule: "0 10 * * 3",
90
+ sourceId: "current",
91
+ sourceIds: [],
92
+ allSources: false,
93
+ query: "",
94
+ limit: 8,
95
+ sourceTimeoutMs: 30000,
96
+ sourceConcurrency: 2,
97
+ sourceStartStaggerMs: 250,
98
+ threadConcurrency: 3,
99
+ threadTimeoutMs: 8000,
100
+ minCandidateCount: 0,
101
+ });
102
+ });
103
+
104
+ it("falls back to all source scope and omits invalid numeric edits", () => {
105
+ expect(
106
+ dreamSettingsUpdateFromDraft(
107
+ draft({
108
+ sourceId: " ",
109
+ sourceIdsText: "mail\ncalendar",
110
+ limit: "not-a-number",
111
+ threadTimeoutMs: "",
112
+ }),
113
+ ),
114
+ ).toMatchObject({
115
+ sourceId: "all",
116
+ sourceIds: ["mail", "calendar"],
117
+ allSources: true,
118
+ });
119
+ expect(
120
+ dreamSettingsUpdateFromDraft(
121
+ draft({ limit: "not-a-number", threadTimeoutMs: "" }),
122
+ ),
123
+ ).not.toHaveProperty("limit");
124
+ expect(
125
+ dreamSettingsUpdateFromDraft(
126
+ draft({ limit: "not-a-number", threadTimeoutMs: "" }),
127
+ ),
128
+ ).not.toHaveProperty("threadTimeoutMs");
129
+ });
130
+ });