macro-agent 0.1.7 → 0.1.10

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 (259) hide show
  1. package/CLAUDE.md +179 -38
  2. package/README.md +781 -131
  3. package/dist/acp/claude-code-replay.d.ts +11 -0
  4. package/dist/acp/claude-code-replay.d.ts.map +1 -0
  5. package/dist/acp/claude-code-replay.js +190 -0
  6. package/dist/acp/claude-code-replay.js.map +1 -0
  7. package/dist/acp/macro-agent.d.ts.map +1 -1
  8. package/dist/acp/macro-agent.js +155 -6
  9. package/dist/acp/macro-agent.js.map +1 -1
  10. package/dist/acp/types.d.ts +9 -0
  11. package/dist/acp/types.d.ts.map +1 -1
  12. package/dist/acp/types.js.map +1 -1
  13. package/dist/agent/agent-manager-v2.d.ts +21 -0
  14. package/dist/agent/agent-manager-v2.d.ts.map +1 -1
  15. package/dist/agent/agent-manager-v2.js +234 -71
  16. package/dist/agent/agent-manager-v2.js.map +1 -1
  17. package/dist/agent/agent-manager.d.ts +12 -0
  18. package/dist/agent/agent-manager.d.ts.map +1 -1
  19. package/dist/agent/agent-manager.js.map +1 -1
  20. package/dist/agent/types.d.ts +15 -2
  21. package/dist/agent/types.d.ts.map +1 -1
  22. package/dist/agent/types.js.map +1 -1
  23. package/dist/boot-v2.d.ts +41 -0
  24. package/dist/boot-v2.d.ts.map +1 -1
  25. package/dist/boot-v2.js +34 -37
  26. package/dist/boot-v2.js.map +1 -1
  27. package/dist/cli/index.js +56 -0
  28. package/dist/cli/index.js.map +1 -1
  29. package/dist/cognitive/macro-agent-backend.d.ts.map +1 -1
  30. package/dist/cognitive/macro-agent-backend.js +40 -22
  31. package/dist/cognitive/macro-agent-backend.js.map +1 -1
  32. package/dist/integrations/skilltree.d.ts.map +1 -1
  33. package/dist/integrations/skilltree.js +1 -0
  34. package/dist/integrations/skilltree.js.map +1 -1
  35. package/dist/lifecycle/cleanup.d.ts +33 -2
  36. package/dist/lifecycle/cleanup.d.ts.map +1 -1
  37. package/dist/lifecycle/cleanup.js +28 -6
  38. package/dist/lifecycle/cleanup.js.map +1 -1
  39. package/dist/lifecycle/handlers-v2.d.ts +7 -0
  40. package/dist/lifecycle/handlers-v2.d.ts.map +1 -1
  41. package/dist/lifecycle/handlers-v2.js +28 -2
  42. package/dist/lifecycle/handlers-v2.js.map +1 -1
  43. package/dist/lifecycle/types.d.ts +11 -0
  44. package/dist/lifecycle/types.d.ts.map +1 -1
  45. package/dist/lifecycle/types.js.map +1 -1
  46. package/dist/map/acp-bridge.d.ts +9 -0
  47. package/dist/map/acp-bridge.d.ts.map +1 -1
  48. package/dist/map/acp-bridge.js +15 -2
  49. package/dist/map/acp-bridge.js.map +1 -1
  50. package/dist/map/cascade-bridge.d.ts +44 -0
  51. package/dist/map/cascade-bridge.d.ts.map +1 -0
  52. package/dist/map/cascade-bridge.js +257 -0
  53. package/dist/map/cascade-bridge.js.map +1 -0
  54. package/dist/map/lifecycle-bridge.d.ts +1 -8
  55. package/dist/map/lifecycle-bridge.d.ts.map +1 -1
  56. package/dist/map/lifecycle-bridge.js +76 -22
  57. package/dist/map/lifecycle-bridge.js.map +1 -1
  58. package/dist/map/server.d.ts.map +1 -1
  59. package/dist/map/server.js +47 -6
  60. package/dist/map/server.js.map +1 -1
  61. package/dist/map/sidecar.d.ts.map +1 -1
  62. package/dist/map/sidecar.js +33 -4
  63. package/dist/map/sidecar.js.map +1 -1
  64. package/dist/map/types.d.ts +20 -0
  65. package/dist/map/types.d.ts.map +1 -1
  66. package/dist/mcp/tools/done-v2.d.ts.map +1 -1
  67. package/dist/mcp/tools/done-v2.js +8 -0
  68. package/dist/mcp/tools/done-v2.js.map +1 -1
  69. package/dist/teams/team-manager-v2.d.ts.map +1 -1
  70. package/dist/teams/team-manager-v2.js +26 -0
  71. package/dist/teams/team-manager-v2.js.map +1 -1
  72. package/dist/teams/team-runtime-v2.d.ts.map +1 -1
  73. package/dist/teams/team-runtime-v2.js +16 -3
  74. package/dist/teams/team-runtime-v2.js.map +1 -1
  75. package/dist/workspace/config.d.ts +10 -10
  76. package/dist/workspace/config.d.ts.map +1 -1
  77. package/dist/workspace/config.js +4 -4
  78. package/dist/workspace/config.js.map +1 -1
  79. package/dist/workspace/git-cascade-adapter.d.ts +510 -0
  80. package/dist/workspace/git-cascade-adapter.d.ts.map +1 -0
  81. package/dist/workspace/git-cascade-adapter.js +908 -0
  82. package/dist/workspace/git-cascade-adapter.js.map +1 -0
  83. package/dist/workspace/index.d.ts +3 -3
  84. package/dist/workspace/index.d.ts.map +1 -1
  85. package/dist/workspace/index.js +4 -4
  86. package/dist/workspace/index.js.map +1 -1
  87. package/dist/workspace/landing/direct-push.d.ts +20 -0
  88. package/dist/workspace/landing/direct-push.d.ts.map +1 -0
  89. package/dist/workspace/landing/direct-push.js +74 -0
  90. package/dist/workspace/landing/direct-push.js.map +1 -0
  91. package/dist/workspace/landing/index.d.ts +29 -0
  92. package/dist/workspace/landing/index.d.ts.map +1 -0
  93. package/dist/workspace/landing/index.js +37 -0
  94. package/dist/workspace/landing/index.js.map +1 -0
  95. package/dist/workspace/landing/merge-to-parent.d.ts +41 -0
  96. package/dist/workspace/landing/merge-to-parent.d.ts.map +1 -0
  97. package/dist/workspace/landing/merge-to-parent.js +185 -0
  98. package/dist/workspace/landing/merge-to-parent.js.map +1 -0
  99. package/dist/workspace/landing/optimistic-push.d.ts +16 -0
  100. package/dist/workspace/landing/optimistic-push.d.ts.map +1 -0
  101. package/dist/workspace/landing/optimistic-push.js +27 -0
  102. package/dist/workspace/landing/optimistic-push.js.map +1 -0
  103. package/dist/workspace/landing/queue-to-branch.d.ts +24 -0
  104. package/dist/workspace/landing/queue-to-branch.d.ts.map +1 -0
  105. package/dist/workspace/landing/queue-to-branch.js +79 -0
  106. package/dist/workspace/landing/queue-to-branch.js.map +1 -0
  107. package/dist/workspace/merge-queue/merge-queue.d.ts +10 -0
  108. package/dist/workspace/merge-queue/merge-queue.d.ts.map +1 -1
  109. package/dist/workspace/merge-queue/merge-queue.js +10 -0
  110. package/dist/workspace/merge-queue/merge-queue.js.map +1 -1
  111. package/dist/workspace/merge-queue/types.d.ts +16 -2
  112. package/dist/workspace/merge-queue/types.d.ts.map +1 -1
  113. package/dist/workspace/merge-queue/types.js +9 -0
  114. package/dist/workspace/merge-queue/types.js.map +1 -1
  115. package/dist/workspace/pool/types.d.ts +1 -0
  116. package/dist/workspace/pool/types.d.ts.map +1 -1
  117. package/dist/workspace/pool/worktree-pool.d.ts.map +1 -1
  118. package/dist/workspace/pool/worktree-pool.js +1 -0
  119. package/dist/workspace/pool/worktree-pool.js.map +1 -1
  120. package/dist/workspace/recovery/abandon.d.ts +15 -0
  121. package/dist/workspace/recovery/abandon.d.ts.map +1 -0
  122. package/dist/workspace/recovery/abandon.js +45 -0
  123. package/dist/workspace/recovery/abandon.js.map +1 -0
  124. package/dist/workspace/recovery/auto-resolve.d.ts +27 -0
  125. package/dist/workspace/recovery/auto-resolve.d.ts.map +1 -0
  126. package/dist/workspace/recovery/auto-resolve.js +99 -0
  127. package/dist/workspace/recovery/auto-resolve.js.map +1 -0
  128. package/dist/workspace/recovery/defer.d.ts +15 -0
  129. package/dist/workspace/recovery/defer.d.ts.map +1 -0
  130. package/dist/workspace/recovery/defer.js +16 -0
  131. package/dist/workspace/recovery/defer.js.map +1 -0
  132. package/dist/workspace/recovery/escalate.d.ts +16 -0
  133. package/dist/workspace/recovery/escalate.d.ts.map +1 -0
  134. package/dist/workspace/recovery/escalate.js +24 -0
  135. package/dist/workspace/recovery/escalate.js.map +1 -0
  136. package/dist/workspace/recovery/index.d.ts +32 -0
  137. package/dist/workspace/recovery/index.d.ts.map +1 -0
  138. package/dist/workspace/recovery/index.js +45 -0
  139. package/dist/workspace/recovery/index.js.map +1 -0
  140. package/dist/workspace/recovery/spawn-resolver.d.ts +45 -0
  141. package/dist/workspace/recovery/spawn-resolver.d.ts.map +1 -0
  142. package/dist/workspace/recovery/spawn-resolver.js +111 -0
  143. package/dist/workspace/recovery/spawn-resolver.js.map +1 -0
  144. package/dist/workspace/recovery/types.d.ts +63 -0
  145. package/dist/workspace/recovery/types.d.ts.map +1 -0
  146. package/dist/workspace/recovery/types.js +12 -0
  147. package/dist/workspace/recovery/types.js.map +1 -0
  148. package/dist/workspace/topology/index.d.ts +9 -0
  149. package/dist/workspace/topology/index.d.ts.map +1 -0
  150. package/dist/workspace/topology/index.js +8 -0
  151. package/dist/workspace/topology/index.js.map +1 -0
  152. package/dist/workspace/topology/no-workspace.d.ts +18 -0
  153. package/dist/workspace/topology/no-workspace.d.ts.map +1 -0
  154. package/dist/workspace/topology/no-workspace.js +25 -0
  155. package/dist/workspace/topology/no-workspace.js.map +1 -0
  156. package/dist/workspace/topology/types.d.ts +97 -0
  157. package/dist/workspace/topology/types.d.ts.map +1 -0
  158. package/dist/workspace/topology/types.js +20 -0
  159. package/dist/workspace/topology/types.js.map +1 -0
  160. package/dist/workspace/topology/yaml-driven.d.ts +69 -0
  161. package/dist/workspace/topology/yaml-driven.d.ts.map +1 -0
  162. package/dist/workspace/topology/yaml-driven.js +273 -0
  163. package/dist/workspace/topology/yaml-driven.js.map +1 -0
  164. package/dist/workspace/types-v3.d.ts +110 -0
  165. package/dist/workspace/types-v3.d.ts.map +1 -0
  166. package/dist/workspace/types-v3.js +20 -0
  167. package/dist/workspace/types-v3.js.map +1 -0
  168. package/dist/workspace/types.d.ts +145 -17
  169. package/dist/workspace/types.d.ts.map +1 -1
  170. package/dist/workspace/workspace-manager.d.ts +92 -13
  171. package/dist/workspace/workspace-manager.d.ts.map +1 -1
  172. package/dist/workspace/workspace-manager.js +373 -13
  173. package/dist/workspace/workspace-manager.js.map +1 -1
  174. package/dist/workspace/yaml-schema.d.ts +254 -0
  175. package/dist/workspace/yaml-schema.d.ts.map +1 -0
  176. package/dist/workspace/yaml-schema.js +170 -0
  177. package/dist/workspace/yaml-schema.js.map +1 -0
  178. package/docs/conflict-recovery.md +472 -0
  179. package/docs/git-cascade-integration-gaps.md +678 -0
  180. package/docs/workspace-interfaces.md +731 -0
  181. package/docs/workspace-redesign-plan.md +302 -0
  182. package/package.json +4 -4
  183. package/src/__tests__/e2e/auto-sync.e2e.test.ts +257 -0
  184. package/src/__tests__/e2e/cascade-rebase.e2e.test.ts +254 -0
  185. package/src/__tests__/e2e/cli-run.e2e.test.ts +167 -0
  186. package/src/__tests__/e2e/self-driving-v3.e2e.test.ts +197 -0
  187. package/src/__tests__/e2e/spawn-resolver.e2e.test.ts +200 -0
  188. package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +30 -22
  189. package/src/__tests__/e2e/workspace-v3.e2e.test.ts +413 -0
  190. package/src/acp/__tests__/claude-code-replay.test.ts +225 -0
  191. package/src/acp/__tests__/macro-agent.test.ts +39 -1
  192. package/src/acp/claude-code-replay.ts +208 -0
  193. package/src/acp/macro-agent.ts +167 -9
  194. package/src/acp/types.ts +10 -0
  195. package/src/agent/__tests__/agent-manager-topology.test.ts +73 -0
  196. package/src/agent/__tests__/agent-manager-v2.test.ts +71 -11
  197. package/src/agent/__tests__/task-ref-resolution.test.ts +231 -0
  198. package/src/agent/agent-manager-v2.ts +293 -77
  199. package/src/agent/agent-manager.ts +14 -0
  200. package/src/agent/types.ts +16 -2
  201. package/src/boot-v2.ts +87 -36
  202. package/src/cli/index.ts +61 -0
  203. package/src/cognitive/__tests__/macro-agent-backend.test.ts +47 -5
  204. package/src/cognitive/macro-agent-backend.ts +45 -29
  205. package/src/integrations/skilltree.ts +1 -0
  206. package/src/lifecycle/cleanup.ts +52 -3
  207. package/src/lifecycle/handlers-v2.ts +40 -3
  208. package/src/lifecycle/types.ts +12 -0
  209. package/src/map/__tests__/cascade-bridge.test.ts +229 -0
  210. package/src/map/__tests__/lifecycle-bridge.test.ts +165 -22
  211. package/src/map/acp-bridge.ts +26 -3
  212. package/src/map/cascade-bridge.ts +301 -0
  213. package/src/map/lifecycle-bridge.ts +77 -27
  214. package/src/map/server.ts +47 -6
  215. package/src/map/sidecar.ts +31 -3
  216. package/src/map/types.ts +20 -0
  217. package/src/mcp/tools/done-v2.ts +9 -0
  218. package/src/teams/team-manager-v2.ts +37 -0
  219. package/src/teams/team-runtime-v2.ts +23 -3
  220. package/src/workspace/__tests__/{dataplane-adapter.test.ts → git-cascade-adapter.test.ts} +209 -14
  221. package/src/workspace/__tests__/self-driving-yaml.test.ts +114 -0
  222. package/src/workspace/__tests__/shared-worktree-refcount.test.ts +154 -0
  223. package/src/workspace/__tests__/standalone-mode.test.ts +118 -0
  224. package/src/workspace/__tests__/workspace-manager-v3.test.ts +245 -0
  225. package/src/workspace/__tests__/yaml-schema.test.ts +210 -0
  226. package/src/workspace/config.ts +11 -11
  227. package/src/workspace/git-cascade-adapter.ts +1186 -0
  228. package/src/workspace/index.ts +11 -11
  229. package/src/workspace/landing/__tests__/strategies.test.ts +142 -0
  230. package/src/workspace/landing/direct-push.ts +91 -0
  231. package/src/workspace/landing/index.ts +40 -0
  232. package/src/workspace/landing/merge-to-parent.ts +228 -0
  233. package/src/workspace/landing/optimistic-push.ts +36 -0
  234. package/src/workspace/landing/queue-to-branch.ts +108 -0
  235. package/src/workspace/merge-queue/merge-queue.ts +10 -0
  236. package/src/workspace/merge-queue/types.ts +16 -2
  237. package/src/workspace/pool/__tests__/worktree-pool.integration.test.ts +5 -5
  238. package/src/workspace/pool/types.ts +1 -0
  239. package/src/workspace/pool/worktree-pool.ts +1 -0
  240. package/src/workspace/recovery/__tests__/auto-resolve-integration.test.ts +127 -0
  241. package/src/workspace/recovery/__tests__/spawn-resolver.test.ts +139 -0
  242. package/src/workspace/recovery/__tests__/strategies.test.ts +145 -0
  243. package/src/workspace/recovery/abandon.ts +51 -0
  244. package/src/workspace/recovery/auto-resolve.ts +119 -0
  245. package/src/workspace/recovery/defer.ts +23 -0
  246. package/src/workspace/recovery/escalate.ts +30 -0
  247. package/src/workspace/recovery/index.ts +58 -0
  248. package/src/workspace/recovery/spawn-resolver.ts +145 -0
  249. package/src/workspace/recovery/types.ts +54 -0
  250. package/src/workspace/topology/__tests__/yaml-driven.test.ts +345 -0
  251. package/src/workspace/topology/index.ts +18 -0
  252. package/src/workspace/topology/no-workspace.ts +39 -0
  253. package/src/workspace/topology/types.ts +116 -0
  254. package/src/workspace/topology/yaml-driven.ts +316 -0
  255. package/src/workspace/types-v3.ts +155 -0
  256. package/src/workspace/types.ts +191 -20
  257. package/src/workspace/workspace-manager.ts +474 -19
  258. package/src/workspace/yaml-schema.ts +216 -0
  259. package/src/workspace/dataplane-adapter.ts +0 -546
@@ -0,0 +1,216 @@
1
+ /**
2
+ * YAML Zod schema for `macro_agent.workspace`.
3
+ *
4
+ * Teams declare workspace topology via `macro_agent.workspace` in their
5
+ * `team.yaml`. This module validates that section and exposes typed config
6
+ * objects that the TopologyPolicy compiler (Phase 3) consumes.
7
+ *
8
+ * @module workspace/yaml-schema
9
+ * @see docs/workspace-interfaces.md §8
10
+ * @see docs/workspace-redesign-plan.md Phase 2
11
+ */
12
+
13
+ import { z } from 'zod';
14
+
15
+ // ─────────────────────────────────────────────────────────────────────────────
16
+ // Enums
17
+ // ─────────────────────────────────────────────────────────────────────────────
18
+
19
+ export const StreamLineageSchema = z.enum([
20
+ 'from_team_root', // attach to the team's root stream (no new stream)
21
+ 'fork_from_team_root', // fork a new stream off the team root
22
+ 'fork_from_parent', // fork a new stream off the spawner's stream
23
+ 'independent', // fork a new stream off a branch (no parent stream)
24
+ 'track_existing_branch', // track an existing branch (no new stream/<id>)
25
+ ]);
26
+
27
+ export const LandingStrategyNameSchema = z.enum([
28
+ 'merge_to_parent_stream',
29
+ 'queue_to_branch',
30
+ 'cherry_pick_stack',
31
+ 'direct_push',
32
+ 'optimistic_push',
33
+ 'none',
34
+ ]);
35
+
36
+ export const ConflictStrategyNameSchema = z.enum([
37
+ 'abort',
38
+ 'ours',
39
+ 'theirs',
40
+ 'defer',
41
+ 'agent',
42
+ ]);
43
+
44
+ /**
45
+ * Recovery strategies for landing conflicts.
46
+ * See docs/conflict-recovery.md §4.
47
+ */
48
+ export const ConflictRecoveryStrategyNameSchema = z.enum([
49
+ 'auto-resolve',
50
+ 'defer',
51
+ 'spawn-resolver',
52
+ 'abandon',
53
+ 'escalate',
54
+ ]);
55
+
56
+ export const WorkspaceKindSchema = z.enum([
57
+ 'new_stream', // agent gets its own stream
58
+ 'attach_to_team_root', // agent works on team root stream
59
+ 'share_with_agent', // agent shares another agent's worktree (ref-counted)
60
+ 'share_parent_cwd', // agent inherits spawner's cwd (no isolation)
61
+ 'none', // no workspace; agent has no streaming concerns
62
+ ]);
63
+
64
+ export const AllocationSchema = z.enum([
65
+ 'new_worktree',
66
+ 'inherit_parent_cwd',
67
+ 'pooled_worktree',
68
+ ]);
69
+
70
+ export const OnParentAdvancedSchema = z.enum([
71
+ 'sync_with_parent',
72
+ 'none',
73
+ ]);
74
+
75
+ export const OnTeamCompleteSchema = z.enum([
76
+ 'keep',
77
+ 'merge_to_main',
78
+ 'abandon',
79
+ ]);
80
+
81
+ // ─────────────────────────────────────────────────────────────────────────────
82
+ // Schemas
83
+ // ─────────────────────────────────────────────────────────────────────────────
84
+
85
+ export const RoleWorkspaceConfigSchema = z.object({
86
+ workspace: WorkspaceKindSchema,
87
+ stream_lineage: StreamLineageSchema.optional(),
88
+ allocation: AllocationSchema.optional(),
89
+
90
+ // Landing
91
+ landing: LandingStrategyNameSchema.optional(),
92
+ landing_config: z.record(z.string(), z.unknown()).optional(),
93
+
94
+ // Conflict handling at landing time
95
+ on_conflict: ConflictStrategyNameSchema.optional(),
96
+ on_conflict_recovery: ConflictRecoveryStrategyNameSchema.optional(),
97
+ conflict_recovery_config: z.record(z.string(), z.unknown()).optional(),
98
+
99
+ // Cascade behavior
100
+ cascade_on_parent_update: z.boolean().optional(),
101
+ on_parent_advanced: OnParentAdvancedSchema.optional(),
102
+
103
+ // Cross-role references
104
+ share_with: z.string().optional(), // role name (for workspace: share_with_agent)
105
+ track_branch: z.string().optional(), // branch name (for stream_lineage: track_existing_branch)
106
+
107
+ // Capabilities granted to this role for MCP tool gating
108
+ capabilities: z.array(z.string()).optional(),
109
+ }).superRefine((val, ctx) => {
110
+ if (val.workspace === 'share_with_agent' && !val.share_with) {
111
+ ctx.addIssue({
112
+ code: 'custom',
113
+ path: ['share_with'],
114
+ message: 'share_with is required when workspace = share_with_agent',
115
+ });
116
+ }
117
+ if (val.stream_lineage === 'track_existing_branch' && !val.track_branch) {
118
+ ctx.addIssue({
119
+ code: 'custom',
120
+ path: ['track_branch'],
121
+ message: 'track_branch is required when stream_lineage = track_existing_branch',
122
+ });
123
+ }
124
+ if (val.workspace === 'new_stream' && !val.stream_lineage) {
125
+ ctx.addIssue({
126
+ code: 'custom',
127
+ path: ['stream_lineage'],
128
+ message: 'stream_lineage is required when workspace = new_stream',
129
+ });
130
+ }
131
+ });
132
+
133
+ export const PoolConfigSchema = z.object({
134
+ enabled: z.boolean().default(true),
135
+ max_size: z.number().int().positive().default(10),
136
+ reuse_across_streams: z.boolean().default(false),
137
+ });
138
+
139
+ export const DefaultStreamConfigSchema = z.object({
140
+ fork_from: z.string().default('main'),
141
+ name_template: z.string().default('{team}'),
142
+ change_id_tracking: z.boolean().default(true),
143
+ });
144
+
145
+ export const ConflictRecoveryTeamConfigSchema = z.object({
146
+ default_strategy: ConflictRecoveryStrategyNameSchema.default('defer'),
147
+ default_config: z.record(z.string(), z.unknown()).optional(),
148
+ escalation_target: z.string().optional(),
149
+ max_recovery_depth: z.number().int().positive().default(3),
150
+ });
151
+
152
+ export const TeamWorkspaceConfigSchema = z.object({
153
+ default_stream: DefaultStreamConfigSchema.optional(),
154
+ on_team_complete: OnTeamCompleteSchema.default('keep'),
155
+ pool: PoolConfigSchema.optional(),
156
+ roles: z.record(z.string(), RoleWorkspaceConfigSchema),
157
+ conflict_recovery: ConflictRecoveryTeamConfigSchema.optional(),
158
+ });
159
+
160
+ // ─────────────────────────────────────────────────────────────────────────────
161
+ // Types (inferred)
162
+ // ─────────────────────────────────────────────────────────────────────────────
163
+
164
+ export type StreamLineage = z.infer<typeof StreamLineageSchema>;
165
+ export type LandingStrategyName = z.infer<typeof LandingStrategyNameSchema>;
166
+ export type ConflictStrategyName = z.infer<typeof ConflictStrategyNameSchema>;
167
+ export type ConflictRecoveryStrategyName = z.infer<typeof ConflictRecoveryStrategyNameSchema>;
168
+ export type WorkspaceKind = z.infer<typeof WorkspaceKindSchema>;
169
+ export type Allocation = z.infer<typeof AllocationSchema>;
170
+ export type OnParentAdvanced = z.infer<typeof OnParentAdvancedSchema>;
171
+ export type OnTeamComplete = z.infer<typeof OnTeamCompleteSchema>;
172
+ export type RoleWorkspaceConfig = z.infer<typeof RoleWorkspaceConfigSchema>;
173
+ export type PoolConfig = z.infer<typeof PoolConfigSchema>;
174
+ export type DefaultStreamConfig = z.infer<typeof DefaultStreamConfigSchema>;
175
+ export type ConflictRecoveryTeamConfig = z.infer<typeof ConflictRecoveryTeamConfigSchema>;
176
+ export type TeamWorkspaceConfig = z.infer<typeof TeamWorkspaceConfigSchema>;
177
+
178
+ // ─────────────────────────────────────────────────────────────────────────────
179
+ // Parsing helpers
180
+ // ─────────────────────────────────────────────────────────────────────────────
181
+
182
+ /**
183
+ * Parse and validate a `macro_agent.workspace` block from a team manifest.
184
+ *
185
+ * Returns `null` when the block is absent (indicating no workspace isolation
186
+ * is configured for the team). Throws on validation failure with a helpful
187
+ * error message.
188
+ */
189
+ export function parseTeamWorkspaceConfig(
190
+ raw: unknown
191
+ ): TeamWorkspaceConfig | null {
192
+ if (raw === undefined || raw === null) return null;
193
+ const result = TeamWorkspaceConfigSchema.safeParse(raw);
194
+ if (!result.success) {
195
+ const issues = result.error.issues
196
+ .map((i) => ` • ${i.path.join('.')}: ${i.message}`)
197
+ .join('\n');
198
+ throw new Error(
199
+ `Invalid macro_agent.workspace configuration:\n${issues}`
200
+ );
201
+ }
202
+ return result.data;
203
+ }
204
+
205
+ /**
206
+ * Extract the workspace block from a loaded openteams `TeamManifest`.
207
+ *
208
+ * openteams treats `macro_agent` as `Record<string, unknown>` — macro-agent
209
+ * owns the schema inside.
210
+ */
211
+ export function extractWorkspaceConfig(
212
+ manifest: { macro_agent?: Record<string, unknown> }
213
+ ): TeamWorkspaceConfig | null {
214
+ const workspaceRaw = manifest.macro_agent?.workspace;
215
+ return parseTeamWorkspaceConfig(workspaceRaw);
216
+ }