@opencorelabs/lucidity 0.6.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 (253) hide show
  1. package/README.md +18 -3
  2. package/dist/assets/speech/lucidity-speech +0 -0
  3. package/dist/automations/agent.d.ts.map +1 -1
  4. package/dist/automations/agent.js +2 -0
  5. package/dist/automations/designer.d.ts +1 -1
  6. package/dist/chat/server.d.ts +1 -0
  7. package/dist/chat/server.d.ts.map +1 -1
  8. package/dist/chat/server.js +6 -1
  9. package/dist/coding/conduct.d.ts +1 -22
  10. package/dist/coding/conduct.d.ts.map +1 -1
  11. package/dist/coding/conduct.js +9 -94
  12. package/dist/coding/runCodeTurn.d.ts +3 -16
  13. package/dist/coding/runCodeTurn.d.ts.map +1 -1
  14. package/dist/coding/runCodeTurn.js +157 -165
  15. package/dist/coding/workspaceRegistry.d.ts +24 -0
  16. package/dist/coding/workspaceRegistry.d.ts.map +1 -0
  17. package/dist/coding/workspaceRegistry.js +230 -0
  18. package/dist/coding/worktree.d.ts +11 -14
  19. package/dist/coding/worktree.d.ts.map +1 -1
  20. package/dist/coding/worktree.js +41 -21
  21. package/dist/config.d.ts +2 -0
  22. package/dist/config.d.ts.map +1 -1
  23. package/dist/daemonLease.d.ts +12 -0
  24. package/dist/daemonLease.d.ts.map +1 -0
  25. package/dist/daemonLease.js +32 -0
  26. package/dist/goals/assessment.d.ts +115 -0
  27. package/dist/goals/assessment.d.ts.map +1 -0
  28. package/dist/goals/assessment.js +67 -0
  29. package/dist/goals/notes.d.ts +18 -0
  30. package/dist/goals/notes.d.ts.map +1 -0
  31. package/dist/goals/notes.js +72 -0
  32. package/dist/index.js +63 -15
  33. package/dist/jobs/goals.d.ts +15 -0
  34. package/dist/jobs/goals.d.ts.map +1 -0
  35. package/dist/jobs/goals.js +286 -0
  36. package/dist/jobs/weeklyReview.d.ts.map +1 -1
  37. package/dist/jobs/weeklyReview.js +3 -2
  38. package/dist/queue.d.ts +1 -0
  39. package/dist/queue.d.ts.map +1 -1
  40. package/dist/queue.js +4 -0
  41. package/dist/room/client.d.ts +5 -0
  42. package/dist/room/client.d.ts.map +1 -1
  43. package/dist/room/client.js +124 -107
  44. package/dist/room/computer.d.ts.map +1 -1
  45. package/dist/room/computer.js +2 -0
  46. package/dist/room/durablePublish.d.ts +6 -0
  47. package/dist/room/durablePublish.d.ts.map +1 -0
  48. package/dist/room/durablePublish.js +19 -0
  49. package/dist/room/incidents.d.ts +1 -1
  50. package/dist/room/incidents.d.ts.map +1 -1
  51. package/dist/room/incidents.js +14 -7
  52. package/dist/room/turnQueue.d.ts.map +1 -1
  53. package/dist/room/turnQueue.js +27 -24
  54. package/dist/runtimeStore.d.ts +44 -0
  55. package/dist/runtimeStore.d.ts.map +1 -0
  56. package/dist/runtimeStore.js +188 -0
  57. package/dist/setup/server.js +1 -1
  58. package/dist/turnLog.d.ts +10 -40
  59. package/dist/turnLog.d.ts.map +1 -1
  60. package/dist/turnLog.js +33 -56
  61. package/package.json +4 -4
  62. package/src/automations/agent.ts +2 -0
  63. package/src/chat/server.ts +7 -1
  64. package/src/coding/conduct.ts +10 -147
  65. package/src/coding/runCodeTurn.ts +42 -61
  66. package/src/coding/workspaceRegistry.ts +210 -0
  67. package/src/coding/worktree.ts +44 -20
  68. package/src/config.ts +2 -0
  69. package/src/daemonLease.ts +33 -0
  70. package/src/goals/assessment.ts +106 -0
  71. package/src/goals/notes.ts +88 -0
  72. package/src/index.ts +63 -18
  73. package/src/jobs/goals.ts +384 -0
  74. package/src/jobs/weeklyReview.ts +4 -3
  75. package/src/queue.ts +4 -0
  76. package/src/room/client.ts +85 -80
  77. package/src/room/computer.ts +2 -0
  78. package/src/room/durablePublish.ts +25 -0
  79. package/src/room/incidents.ts +16 -8
  80. package/src/room/turnQueue.ts +26 -27
  81. package/src/runtimeStore.ts +190 -0
  82. package/src/setup/server.ts +1 -1
  83. package/src/turnLog.ts +32 -75
  84. package/vendor/decisions/dist/dayPlan.d.ts +9 -0
  85. package/vendor/decisions/dist/dayPlan.js +82 -0
  86. package/vendor/decisions/dist/index.d.ts +1 -0
  87. package/vendor/decisions/dist/index.js +1 -0
  88. package/vendor/decisions/dist/jev.js +3 -1
  89. package/vendor/decisions/src/dayPlan.ts +80 -0
  90. package/vendor/decisions/src/index.ts +1 -0
  91. package/vendor/decisions/src/jev.ts +3 -1
  92. package/vendor/mcp-server/dist/index.js +2 -0
  93. package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
  94. package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
  95. package/vendor/mcp-server/dist/tools/goals.js +38 -0
  96. package/vendor/mcp-server/package.json +1 -1
  97. package/vendor/mcp-server/src/index.ts +2 -0
  98. package/vendor/mcp-server/src/tools/goals.ts +62 -0
  99. package/vendor/runtime/README.md +2 -2
  100. package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
  101. package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
  102. package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
  103. package/vendor/runtime/dist/executor/claudeAgent.d.ts +1 -1
  104. package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
  105. package/vendor/runtime/dist/executor/claudeAgent.js +25 -10
  106. package/vendor/runtime/dist/executor/codex.d.ts +1 -0
  107. package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
  108. package/vendor/runtime/dist/executor/codex.js +69 -36
  109. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
  110. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
  111. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
  112. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
  113. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
  114. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
  115. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
  116. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
  117. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
  118. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
  119. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
  120. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
  121. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
  122. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
  123. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
  124. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
  125. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
  126. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
  127. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
  128. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
  129. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
  130. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
  131. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
  132. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
  133. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
  134. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
  135. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
  136. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
  137. package/vendor/runtime/dist/executor/codexRpc.d.ts +10 -3
  138. package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
  139. package/vendor/runtime/dist/executor/codexRpc.js +18 -3
  140. package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
  141. package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
  142. package/vendor/runtime/dist/executor/codexSessions.js +88 -0
  143. package/vendor/runtime/dist/executor/health.d.ts +2 -1
  144. package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
  145. package/vendor/runtime/dist/executor/health.js +17 -5
  146. package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
  147. package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
  148. package/vendor/runtime/dist/executor/liveTurns.js +12 -5
  149. package/vendor/runtime/dist/executor/ownership.d.ts +35 -0
  150. package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
  151. package/vendor/runtime/dist/executor/ownership.js +99 -0
  152. package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
  153. package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
  154. package/vendor/runtime/dist/executor/providerRouter.js +5 -0
  155. package/vendor/runtime/dist/executor/types.d.ts +4 -0
  156. package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
  157. package/vendor/runtime/dist/harness/index.d.ts +1 -0
  158. package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
  159. package/vendor/runtime/dist/harness/index.js +12 -1
  160. package/vendor/runtime/dist/harness/types.d.ts +2 -1
  161. package/vendor/runtime/dist/harness/types.d.ts.map +1 -1
  162. package/vendor/runtime/dist/index.d.ts +1 -0
  163. package/vendor/runtime/dist/index.d.ts.map +1 -1
  164. package/vendor/runtime/dist/index.js +1 -0
  165. package/vendor/runtime/dist/prompts/dayPlanning.d.ts +44 -0
  166. package/vendor/runtime/dist/prompts/dayPlanning.d.ts.map +1 -0
  167. package/vendor/runtime/dist/prompts/dayPlanning.js +42 -0
  168. package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
  169. package/vendor/runtime/src/executor/claudeAgent.ts +20 -9
  170. package/vendor/runtime/src/executor/codex.ts +76 -44
  171. package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
  172. package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
  173. package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
  174. package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
  175. package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
  176. package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
  177. package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
  178. package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
  179. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
  180. package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
  181. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
  182. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
  183. package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
  184. package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
  185. package/vendor/runtime/src/executor/codexRpc.ts +22 -4
  186. package/vendor/runtime/src/executor/codexSessions.ts +108 -0
  187. package/vendor/runtime/src/executor/health.ts +16 -6
  188. package/vendor/runtime/src/executor/liveTurns.ts +12 -5
  189. package/vendor/runtime/src/executor/ownership.ts +76 -0
  190. package/vendor/runtime/src/executor/providerRouter.ts +6 -0
  191. package/vendor/runtime/src/executor/types.ts +4 -0
  192. package/vendor/runtime/src/harness/index.ts +12 -1
  193. package/vendor/runtime/src/harness/types.ts +2 -1
  194. package/vendor/runtime/src/index.ts +1 -0
  195. package/vendor/runtime/src/prompts/dayPlanning.ts +46 -0
  196. package/vendor/shared/dist/agentCommands.d.ts +1 -0
  197. package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
  198. package/vendor/shared/dist/cardStudio.d.ts +41 -0
  199. package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
  200. package/vendor/shared/dist/cardStudio.js +13 -3
  201. package/vendor/shared/dist/commandLocal.d.ts.map +1 -1
  202. package/vendor/shared/dist/commandLocal.js +2 -0
  203. package/vendor/shared/dist/commands.d.ts +18 -0
  204. package/vendor/shared/dist/commands.d.ts.map +1 -1
  205. package/vendor/shared/dist/commands.js +2 -0
  206. package/vendor/shared/dist/computer.d.ts +7 -1
  207. package/vendor/shared/dist/computer.d.ts.map +1 -1
  208. package/vendor/shared/dist/computer.js +13 -2
  209. package/vendor/shared/dist/constants.d.ts +3 -3
  210. package/vendor/shared/dist/constants.d.ts.map +1 -1
  211. package/vendor/shared/dist/constants.js +5 -4
  212. package/vendor/shared/dist/dayPlan.d.ts +86 -0
  213. package/vendor/shared/dist/dayPlan.d.ts.map +1 -0
  214. package/vendor/shared/dist/dayPlan.js +46 -0
  215. package/vendor/shared/dist/dayPlanning.d.ts +139 -0
  216. package/vendor/shared/dist/dayPlanning.d.ts.map +1 -0
  217. package/vendor/shared/dist/dayPlanning.js +67 -0
  218. package/vendor/shared/dist/goalNotes.d.ts +4 -0
  219. package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
  220. package/vendor/shared/dist/goalNotes.js +23 -0
  221. package/vendor/shared/dist/goals.d.ts +835 -0
  222. package/vendor/shared/dist/goals.d.ts.map +1 -0
  223. package/vendor/shared/dist/goals.js +198 -0
  224. package/vendor/shared/dist/index.d.ts +5 -0
  225. package/vendor/shared/dist/index.d.ts.map +1 -1
  226. package/vendor/shared/dist/index.js +5 -0
  227. package/vendor/shared/dist/schemas/harness.d.ts +155 -0
  228. package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
  229. package/vendor/shared/dist/schemas/harness.js +8 -0
  230. package/vendor/shared/dist/workspaces.d.ts +138 -0
  231. package/vendor/shared/dist/workspaces.d.ts.map +1 -0
  232. package/vendor/shared/dist/workspaces.js +40 -0
  233. package/vendor/shared/src/agentCommands.ts +1 -0
  234. package/vendor/shared/src/cardStudio.ts +13 -3
  235. package/vendor/shared/src/commandLocal.ts +2 -0
  236. package/vendor/shared/src/commands.ts +2 -0
  237. package/vendor/shared/src/computer.ts +18 -2
  238. package/vendor/shared/src/constants.ts +5 -4
  239. package/vendor/shared/src/dayPlan.ts +81 -0
  240. package/vendor/shared/src/dayPlanning.ts +77 -0
  241. package/vendor/shared/src/goalNotes.ts +23 -0
  242. package/vendor/shared/src/goals.ts +237 -0
  243. package/vendor/shared/src/index.ts +6 -0
  244. package/vendor/shared/src/schemas/harness.ts +8 -0
  245. package/vendor/shared/src/workspaces.ts +48 -0
  246. package/dist/coding/fleetIntegrate.d.ts +0 -37
  247. package/dist/coding/fleetIntegrate.d.ts.map +0 -1
  248. package/dist/coding/fleetIntegrate.js +0 -64
  249. package/dist/coding/openFleetPr.d.ts +0 -41
  250. package/dist/coding/openFleetPr.d.ts.map +0 -1
  251. package/dist/coding/openFleetPr.js +0 -121
  252. package/src/coding/fleetIntegrate.ts +0 -95
  253. package/src/coding/openFleetPr.ts +0 -148
@@ -0,0 +1,237 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ StudioDateSchema,
4
+ studioLocalDate,
5
+ shiftStudioDate,
6
+ } from './cardStudio.js';
7
+
8
+ export const GoalTimeZoneSchema = z
9
+ .string()
10
+ .max(100)
11
+ .refine((zone) => {
12
+ try {
13
+ new Intl.DateTimeFormat('en', { timeZone: zone });
14
+ return true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ }, 'Choose a valid time zone.');
19
+ export const GoalTimeframeSchema = z
20
+ .object({
21
+ start: StudioDateSchema,
22
+ end: StudioDateSchema,
23
+ precision: z.enum(['month', 'quarter', 'year', 'custom']),
24
+ timeZone: GoalTimeZoneSchema,
25
+ })
26
+ .refine(
27
+ (value) => value.end >= value.start,
28
+ 'The end must be on or after the start.',
29
+ );
30
+ export type GoalTimeframe = z.infer<typeof GoalTimeframeSchema>;
31
+ export const GoalStatusSchema = z.enum([
32
+ 'active',
33
+ 'paused',
34
+ 'completed',
35
+ 'archived',
36
+ ]);
37
+ export const GoalCadenceSchema = z.enum(['weekly', 'monthly', 'yearly']);
38
+ export type GoalCadence = z.infer<typeof GoalCadenceSchema>;
39
+ export const GoalInputSchema = z.object({
40
+ title: z.string().trim().min(1).max(240),
41
+ timeframe: GoalTimeframeSchema,
42
+ status: GoalStatusSchema.default('active'),
43
+ tracking: z.boolean().default(true),
44
+ reviews: z
45
+ .array(GoalCadenceSchema)
46
+ .max(3)
47
+ .default(['weekly', 'monthly'])
48
+ .refine((values) => new Set(values).size === values.length),
49
+ });
50
+ export type GoalInput = z.infer<typeof GoalInputSchema>;
51
+ export const SaveGoalSchema = GoalInputSchema.extend({
52
+ id: z.uuid(),
53
+ revision: z.number().int().nonnegative(),
54
+ });
55
+ export const GoalSchema = GoalInputSchema.extend({
56
+ id: z.uuid(),
57
+ revision: z.number().int().nonnegative(),
58
+ createdAt: z.iso.datetime(),
59
+ updatedAt: z.iso.datetime(),
60
+ });
61
+ export type Goal = z.infer<typeof GoalSchema>;
62
+ export const GoalReferenceSchema = z.object({
63
+ kind: z.enum(['task', 'project', 'habit', 'note']),
64
+ id: z.uuid(),
65
+ });
66
+ export type GoalReference = z.infer<typeof GoalReferenceSchema>;
67
+ export const goalReferenceKey = (ref: GoalReference) => `${ref.kind}:${ref.id}`;
68
+ export const GoalLinkInputSchema = GoalReferenceSchema.extend({
69
+ source: z.enum(['manual', 'ai']).default('manual'),
70
+ reason: z.string().trim().min(1).max(240),
71
+ state: z.enum(['active', 'rejected']).default('active'),
72
+ });
73
+ export const GoalLinkSchema = GoalLinkInputSchema.extend({
74
+ title: z.string().nullable(),
75
+ available: z.boolean(),
76
+ updatedAt: z.iso.datetime(),
77
+ });
78
+ export type GoalLink = z.infer<typeof GoalLinkSchema>;
79
+ export const GoalEvidenceSchema = z.object({
80
+ key: z.string(),
81
+ reference: GoalReferenceSchema,
82
+ at: z.iso.datetime(),
83
+ kind: z.enum([
84
+ 'task_completed',
85
+ 'task_started',
86
+ 'task_reopened',
87
+ 'task_changed',
88
+ 'habit_check_in',
89
+ 'note_changed',
90
+ ]),
91
+ title: z.string().nullable(),
92
+ available: z.boolean(),
93
+ });
94
+ export type GoalEvidence = z.infer<typeof GoalEvidenceSchema>;
95
+ export const GoalCheckSchema = z.object({
96
+ key: z.string(),
97
+ cadence: z.enum(['daily', 'weekly', 'monthly', 'yearly']),
98
+ start: StudioDateSchema,
99
+ end: StudioDateSchema,
100
+ checkedAt: z.iso.datetime(),
101
+ signal: z.enum(['moving', 'quiet', 'unknown']),
102
+ summary: z.string(),
103
+ evidence: z.array(GoalEvidenceSchema),
104
+ references: z.array(GoalReferenceSchema),
105
+ timeframe: GoalTimeframeSchema,
106
+ });
107
+ export type GoalCheck = z.infer<typeof GoalCheckSchema>;
108
+ export const GoalActionSchema = z.object({
109
+ id: z.uuid(),
110
+ goalId: z.uuid(),
111
+ title: z.string(),
112
+ instruction: z.string(),
113
+ references: z.array(GoalReferenceSchema),
114
+ status: z.enum([
115
+ 'proposed',
116
+ 'approved',
117
+ 'running',
118
+ 'completed',
119
+ 'cancelled',
120
+ 'failed',
121
+ ]),
122
+ createdAt: z.iso.datetime(),
123
+ updatedAt: z.iso.datetime(),
124
+ resultNoteId: z.uuid().nullable(),
125
+ resultMarkdown: z.string().nullable(),
126
+ error: z.string().nullable(),
127
+ });
128
+ export type GoalAction = z.infer<typeof GoalActionSchema>;
129
+ export const GoalDetailSchema = z.object({
130
+ goal: GoalSchema,
131
+ links: z.array(GoalLinkSchema),
132
+ checks: z.array(GoalCheckSchema),
133
+ actions: z.array(GoalActionSchema),
134
+ });
135
+ export type GoalDetail = z.infer<typeof GoalDetailSchema>;
136
+ export const GoalsSnapshotSchema = z.object({
137
+ goals: z.array(GoalDetailSchema),
138
+ refreshedAt: z.iso.datetime(),
139
+ });
140
+ export type GoalsSnapshot = z.infer<typeof GoalsSnapshotSchema>;
141
+
142
+ /** Date-only arithmetic deliberately ignores DST and the computer's current zone. */
143
+ export function goalDaysRemaining(
144
+ timeframe: GoalTimeframe,
145
+ now = new Date(),
146
+ ): number {
147
+ return Math.round(
148
+ (Date.parse(timeframe.end) -
149
+ Date.parse(studioLocalDate(now, timeframe.timeZone))) /
150
+ 86_400_000,
151
+ );
152
+ }
153
+ export function goalPeriod(
154
+ cadence: 'daily' | GoalCadence,
155
+ today: string,
156
+ ): { start: string; end: string; key: string } {
157
+ StudioDateSchema.parse(today);
158
+ let start = today,
159
+ end = today;
160
+ if (cadence === 'weekly') {
161
+ const day = new Date(today + 'T12:00:00Z').getUTCDay();
162
+ end = shiftStudioDate(today, -((day + 6) % 7) - 1);
163
+ start = shiftStudioDate(end, -6);
164
+ } else if (cadence === 'monthly') {
165
+ end = shiftStudioDate(today.slice(0, 8) + '01', -1);
166
+ start = end.slice(0, 8) + '01';
167
+ } else if (cadence === 'yearly') {
168
+ const year = Number(today.slice(0, 4)) - 1;
169
+ start = `${year}-01-01`;
170
+ end = `${year}-12-31`;
171
+ }
172
+ return { start, end, key: `${cadence}:${start}` };
173
+ }
174
+ /** Completed periods only, with no backlog flood after a computer wakes. */
175
+ export function dueGoalPeriods(
176
+ goal: Goal,
177
+ existing: readonly Pick<GoalCheck, 'key'>[],
178
+ now = new Date(),
179
+ ) {
180
+ if (!goal.tracking || goal.status !== 'active') return [];
181
+ const today = studioLocalDate(now, goal.timeframe.timeZone);
182
+ if (today < goal.timeframe.start) return [];
183
+ const created = studioLocalDate(
184
+ new Date(goal.createdAt),
185
+ goal.timeframe.timeZone,
186
+ );
187
+ return (['daily', ...goal.reviews] as const)
188
+ .map((cadence) => ({ cadence, ...goalPeriod(cadence, today) }))
189
+ .filter(
190
+ (period) =>
191
+ period.end >= created &&
192
+ period.end >= goal.timeframe.start &&
193
+ !existing.some((check) => check.key === period.key),
194
+ );
195
+ }
196
+
197
+ export const GoalAnalysisSchema = z.object({
198
+ links: z
199
+ .array(GoalReferenceSchema.extend({ reason: z.string().max(240) }))
200
+ .max(12),
201
+ summary: z.string().trim().min(1).max(400),
202
+ help: z
203
+ .object({
204
+ title: z.string().max(100),
205
+ instruction: z.string().max(800),
206
+ references: z.array(GoalReferenceSchema).min(1).max(12),
207
+ })
208
+ .nullable(),
209
+ });
210
+ export type GoalAnalysis = z.infer<typeof GoalAnalysisSchema>;
211
+
212
+ export const GoalCandidateSchema = GoalReferenceSchema.extend({
213
+ title: z.string(),
214
+ description: z.string().nullable(),
215
+ updatedAt: z.iso.datetime().nullable(),
216
+ status: z.string().nullable(),
217
+ projectId: z.uuid().nullable(),
218
+ });
219
+ export type GoalCandidate = z.infer<typeof GoalCandidateSchema>;
220
+ export const GoalTrackingContextSchema = z.object({
221
+ detail: GoalDetailSchema,
222
+ candidates: z.array(GoalCandidateSchema),
223
+ evidence: z.array(GoalEvidenceSchema),
224
+ complete: z.boolean(),
225
+ });
226
+ export type GoalTrackingContext = z.infer<typeof GoalTrackingContextSchema>;
227
+ export const RecordGoalCheckSchema = z.object({
228
+ revision: z.number().int().positive(),
229
+ cadence: z.enum(['daily', 'weekly', 'monthly', 'yearly']),
230
+ summary: z.string().trim().min(1).max(400),
231
+ noteObservations: z
232
+ .array(z.object({ id: z.uuid(), at: z.iso.datetime() }))
233
+ .max(100)
234
+ .default([]),
235
+ notesAvailable: z.boolean().default(false),
236
+ help: GoalAnalysisSchema.shape.help,
237
+ });
@@ -1,3 +1,5 @@
1
+ export * from './dayPlanning.js';
2
+ export * from './workspaces.js';
1
3
  export * from './githubContributions.js';
2
4
  export * from './projectCapture.js';
3
5
  export * from './taskActivity.js';
@@ -441,6 +443,10 @@ export * from './spokenNames.js';
441
443
  export * from './voiceCapture.js';
442
444
  export * from './automations.js';
443
445
  export * from './automationTemplates.js';
446
+ export * from './dayPlan.js';
444
447
 
445
448
  export { parseAgentCommand, findAgentCommand } from './agentCommands.js';
446
449
  export type { AgentCommandOption, AgentCommandContext } from './agentCommands.js';
450
+
451
+ export * from './goals.js';
452
+ export * from './goalNotes.js';
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { WorkspaceCommandSchema, WorkspaceSnapshotSchema } from '../workspaces.js';
2
3
  import {
3
4
  VoiceCaptureAudioSchema,
4
5
  VoiceCaptureReceiptSchema,
@@ -13,6 +14,7 @@ import {
13
14
  AutomationCommandSchema,
14
15
  AutomationSnapshotSchema,
15
16
  } from '../automations.js';
17
+ import { DayPlanningContextSchema } from '../dayPlanning.js';
16
18
  import { ProjectPlanningContextSchema } from '../projectCapture.js';
17
19
  import { validatedCardSegments } from '../cardStatement.js';
18
20
  import {
@@ -81,6 +83,7 @@ export const AskRequestSchema = HarnessRequestBase.extend({
81
83
  prompt: z.string().min(1).max(8000),
82
84
  /** Feature-gated, tool-free project interpretation; never resumes a chat session. */
83
85
  projectPlan: ProjectPlanningContextSchema.optional(),
86
+ dayPlan: DayPlanningContextSchema.optional(),
84
87
  /** Photos attached to the question (vision). Optional; absent on a text-only ask. */
85
88
  images: harnessImagesField,
86
89
  /** Claude Code session id to continue (conversation continuity via --resume). */
@@ -504,6 +507,7 @@ export const AttentionRequestSchema = HarnessRequestBase.extend({
504
507
  });
505
508
 
506
509
  export const HarnessRequestSchema = z.discriminatedUnion('kind', [
510
+ HarnessRequestBase.extend({ kind: z.literal('workspaces'), command: WorkspaceCommandSchema }),
507
511
  HarnessRequestBase.extend({
508
512
  kind: z.literal('voice-capture'),
509
513
  credentialId: z.uuid(),
@@ -787,6 +791,7 @@ export const CommandsResponseSchema = HarnessResponseBase.extend({
787
791
  description: z.string(),
788
792
  argumentHint: z.string(),
789
793
  acceptsArguments: z.boolean().optional(),
794
+ startsConversation: z.boolean().optional(),
790
795
  aliases: z.array(z.string()).optional(),
791
796
  clearsContext: z.boolean().optional(),
792
797
  }),
@@ -794,6 +799,7 @@ export const CommandsResponseSchema = HarnessResponseBase.extend({
794
799
  });
795
800
 
796
801
  export const HarnessResponseSchema = z.discriminatedUnion('kind', [
802
+ HarnessResponseBase.extend({ kind: z.literal('workspaces'), snapshot: WorkspaceSnapshotSchema }),
797
803
  HarnessResponseBase.extend({
798
804
  kind: z.literal('voice-capture'),
799
805
  receipt: VoiceCaptureReceiptSchema.nullable(),
@@ -893,6 +899,7 @@ export const HarnessStreamEventSchema = z.discriminatedUnion('type', [
893
899
  // ran — on `branch` — so the phone shows a quiet "checkout moved" notice on the bubble
894
900
  // instead of the old dead-end rejection that made the user re-send.
895
901
  movedFrom: z.string().optional(),
902
+ checkpointWarning: z.string().optional(),
896
903
  }),
897
904
  z.object({
898
905
  // The result of a `clone` turn (#78): the new repo's id, once cloned into the
@@ -963,6 +970,7 @@ export const HarnessStreamEventSchema = z.discriminatedUnion('type', [
963
970
  type: z.literal('error'),
964
971
  requestId: z.uuidv7(),
965
972
  message: z.string(),
973
+ code: z.string().optional(),
966
974
  }),
967
975
  // A `cancel` request successfully stopped this in-flight turn.
968
976
  z.object({
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+
3
+ export const SavedChatMessageSchema = z.object({
4
+ id: z.string().min(1), role: z.enum(['user', 'lucid', 'notice']), text: z.string(),
5
+ }).passthrough();
6
+
7
+ export const WorkerWorkspaceSchema = z.object({
8
+ workerId: z.uuidv7(), repoId: z.string().min(1), title: z.string().min(1).max(200),
9
+ brief: z.string().max(8000).default(''),
10
+ workspaceId: z.string(), conversationId: z.string(),
11
+ state: z.enum(['creating', 'ready', 'setup_failed', 'archived']),
12
+ branch: z.string().optional(), baseRef: z.string().optional(), baseSha: z.string().optional(),
13
+ resume: z.string().optional(), error: z.string().optional(),
14
+ createdAt: z.string(), updatedAt: z.string(),
15
+ });
16
+ export type WorkerWorkspace = z.infer<typeof WorkerWorkspaceSchema>;
17
+
18
+ export const WorkspaceCommandSchema = z.object({
19
+ action: z.enum(['list', 'create', 'history', 'archive', 'restore', 'import', 'clear-history']),
20
+ repoId: z.string().min(1).optional(), workerId: z.uuidv7().optional(),
21
+ checkout: z.boolean().optional(), revision: z.string().optional(),
22
+ title: z.string().trim().min(1).max(200).optional(),
23
+ brief: z.string().max(8000).optional(), before: z.string().optional(),
24
+ legacy: z.object({
25
+ messages: z.array(SavedChatMessageSchema).max(10_000), resume: z.string().optional(),
26
+ sessionCheckout: z.boolean().optional(),
27
+ }).optional(),
28
+ });
29
+ export type WorkspaceCommand = z.infer<typeof WorkspaceCommandSchema>;
30
+
31
+ export const WorkspaceRunSchema = z.object({
32
+ requestId: z.string(), prompt: z.string(),
33
+ handoff: z.object({ from: z.enum(['claude', 'codex']), to: z.enum(['claude', 'codex']) }).optional(),
34
+ frames: z.array(z.record(z.string(), z.unknown())),
35
+ terminated: z.boolean(),
36
+ });
37
+ export type WorkspaceRun = z.infer<typeof WorkspaceRunSchema>;
38
+ export const WorkspaceSnapshotSchema = z.object({
39
+ workers: z.array(WorkerWorkspaceSchema),
40
+ checkout: z.object({
41
+ repoId: z.string(), conversationId: z.string(), revision: z.string(),
42
+ resume: z.string().optional(),
43
+ }).optional(),
44
+ runs: z.array(WorkspaceRunSchema).optional(),
45
+ legacyMessages: z.array(SavedChatMessageSchema).optional(),
46
+ nextBefore: z.string().optional(),
47
+ });
48
+ export type WorkspaceSnapshot = z.infer<typeof WorkspaceSnapshotSchema>;
@@ -1,37 +0,0 @@
1
- export interface FleetConflict {
2
- workerId: string;
3
- /** The files that couldn't merge cleanly. */
4
- paths: string[];
5
- }
6
- export interface IntegrationResult {
7
- /** The branch the workers were integrated onto — the bare `lucid/<repo>` session, which
8
- * is also where the fleet's single PR opens from. */
9
- branch: string;
10
- /** Worker ids that merged cleanly, in the order they landed. */
11
- merged: string[];
12
- /** Workers whose branch conflicted; their merge was aborted and left for the user to hand
13
- * back to the worker as a fresh turn. */
14
- conflicts: FleetConflict[];
15
- }
16
- /**
17
- * Integrate finished workers onto the fleet branch, one at a time in merge order.
18
- *
19
- * The integration worktree is the bare repo session (`lucid/<repo>`), reset to HEAD, so the
20
- * fan-out's result is a single branch cut fresh from where the user started — clean history to
21
- * open one PR from. Each worker's `fleet/<repo>/<workerId>` branch is merged in; a conflict is
22
- * caught (not thrown), the merge aborted so the next worker can still land, and reported via
23
- * `onConflict` so the conductor surfaces it in the feed rather than silently dropping work.
24
- *
25
- * Sequential and in order because that's where overlap actually bites: the workers ran in
26
- * isolated worktrees and never raced each other on disk — only the merge can conflict, and only
27
- * against what already landed.
28
- */
29
- export declare function integrateWorkers(repoRoot: string, repoId: string, workers: {
30
- workerId: string;
31
- mergeOrder: number;
32
- }[], opts?: {
33
- baseDir?: string;
34
- onMerged?: (workerId: string) => void;
35
- onConflict?: (conflict: FleetConflict) => void;
36
- }): Promise<IntegrationResult>;
37
- //# sourceMappingURL=fleetIntegrate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fleetIntegrate.d.ts","sourceRoot":"","sources":["../../src/coding/fleetIntegrate.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC;0DACsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;8CAC0C;IAC1C,SAAS,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,EACnD,IAAI,GAAE;IACJ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3C,GACL,OAAO,CAAC,iBAAiB,CAAC,CA4C5B"}
@@ -1,64 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
- import { ensureWorkspace, sessionBranch } from './worktree.js';
4
- const exec = promisify(execFile);
5
- async function git(cwd, args) {
6
- const { stdout } = await exec('git', args, { cwd, maxBuffer: 32 * 1024 * 1024 });
7
- return stdout;
8
- }
9
- /**
10
- * Integrate finished workers onto the fleet branch, one at a time in merge order.
11
- *
12
- * The integration worktree is the bare repo session (`lucid/<repo>`), reset to HEAD, so the
13
- * fan-out's result is a single branch cut fresh from where the user started — clean history to
14
- * open one PR from. Each worker's `fleet/<repo>/<workerId>` branch is merged in; a conflict is
15
- * caught (not thrown), the merge aborted so the next worker can still land, and reported via
16
- * `onConflict` so the conductor surfaces it in the feed rather than silently dropping work.
17
- *
18
- * Sequential and in order because that's where overlap actually bites: the workers ran in
19
- * isolated worktrees and never raced each other on disk — only the merge can conflict, and only
20
- * against what already landed.
21
- */
22
- export async function integrateWorkers(repoRoot, repoId, workers, opts = {}) {
23
- const branch = sessionBranch(repoId);
24
- // Fresh bare session = lucid/<repo> reset to HEAD: the integration target.
25
- const ws = await ensureWorkspace(repoRoot, repoId, {
26
- fresh: true,
27
- baseDir: opts.baseDir,
28
- });
29
- const ordered = [...workers].sort((a, b) => a.mergeOrder - b.mergeOrder);
30
- const merged = [];
31
- const conflicts = [];
32
- for (const w of ordered) {
33
- const workerBranch = sessionBranch(repoId, w.workerId);
34
- try {
35
- await git(ws.path, [
36
- 'merge',
37
- '--no-ff',
38
- '-m',
39
- `Merge fleet worker ${w.workerId}`,
40
- workerBranch,
41
- ]);
42
- merged.push(w.workerId);
43
- opts.onMerged?.(w.workerId);
44
- }
45
- catch {
46
- // A conflict (or any merge failure): record the unmerged paths, abort so the branch is
47
- // clean for the next worker, and report. Never fatal — one bad lane can't sink the fleet.
48
- const unmerged = await git(ws.path, [
49
- 'diff',
50
- '--name-only',
51
- '--diff-filter=U',
52
- ]).catch(() => '');
53
- const paths = unmerged
54
- .split('\n')
55
- .map((s) => s.trim())
56
- .filter(Boolean);
57
- await git(ws.path, ['merge', '--abort']).catch(() => { });
58
- const conflict = { workerId: w.workerId, paths };
59
- conflicts.push(conflict);
60
- opts.onConflict?.(conflict);
61
- }
62
- }
63
- return { branch, merged, conflicts };
64
- }
@@ -1,41 +0,0 @@
1
- export interface FleetPrSummary {
2
- title: string;
3
- body: string;
4
- }
5
- /**
6
- * Build the PR's title + body from the fleet goal and the workers that actually landed. Pure so
7
- * it can be unit-tested; the spawn wrapper below is covered by a real run.
8
- */
9
- export declare function fleetPrSummary(goal: string, mergedTitles: string[]): FleetPrSummary;
10
- /**
11
- * Per-feature delivery: build ONE worker's PR title + body.
12
- *
13
- * The title is the worker's own FIRST commit subject, which `codeCommitMessage` already built out
14
- * of Lucid's summary of what it did. The lane title can't do that job and shouldn't have been
15
- * asked to: it's `clampTitle(brief.split('\n')[0])`, so it's the opening line of whatever was
16
- * typed at the board, which names the request rather than the change and is usually cut off
17
- * mid-thought (#308). It stays as the fallback for a branch whose subjects couldn't be read.
18
- *
19
- * The first subject rather than the last, because a steered worker's later commits are
20
- * refinements of the piece of work the branch is about. The rest go in the body under the brief
21
- * that asked for them, which is the one thing the brief is genuinely good for. Pure, unit-tested.
22
- */
23
- export declare function workerPrSummary(title: string, brief: string, subjects?: string[]): FleetPrSummary;
24
- export interface FleetPrResult {
25
- url?: string;
26
- error?: string;
27
- }
28
- /**
29
- * Push the integration branch and open (or reuse) ONE pull request for the whole fan-out.
30
- *
31
- * Runs from the lucid/<repo> worktree, which is on the integration branch and shares the repo's
32
- * GitHub remote. The branch is force-pushed because each fleet resets it fresh to HEAD before
33
- * merging — its history is authored per-run, so the remote must follow. If a PR for the branch is
34
- * already open (a re-integrated fleet), its URL is returned and the force-push updates it in place
35
- * rather than opening a duplicate.
36
- *
37
- * Never throws: a missing/unauthed `gh`, or a repo with no GitHub remote, returns `{ error }` the
38
- * phone can surface — the fleet already merged locally regardless.
39
- */
40
- export declare function openFleetPr(worktreePath: string, branch: string, summary: FleetPrSummary, base?: string): Promise<FleetPrResult>;
41
- //# sourceMappingURL=openFleetPr.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openFleetPr.d.ts","sourceRoot":"","sources":["../../src/coding/openFleetPr.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,cAAc,CAQnF;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAM,EAAO,GACtB,cAAc,CAQhB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAaD;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAC/B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,EACvB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,CAAC,CAuDxB"}
@@ -1,121 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
- const exec = promisify(execFile);
4
- /** The daemon runs under launchd, whose PATH excludes Homebrew — so `gh` (from /opt/homebrew/bin
5
- * or /usr/local/bin) may not resolve. Prepend the usual bins. (mirrors listPrs.ts) */
6
- const GH_PATH = [process.env.PATH, '/opt/homebrew/bin', '/usr/local/bin'].filter(Boolean).join(':');
7
- /**
8
- * Build the PR's title + body from the fleet goal and the workers that actually landed. Pure so
9
- * it can be unit-tested; the spawn wrapper below is covered by a real run.
10
- */
11
- export function fleetPrSummary(goal, mergedTitles) {
12
- const g = goal.trim() || 'Fleet';
13
- const title = `Fleet: ${g}`.slice(0, 120);
14
- const lines = mergedTitles.length
15
- ? mergedTitles.map((t) => `- ${t}`).join('\n')
16
- : '- (no worker changes)';
17
- const body = `${g}\n\nMerged by the fleet:\n${lines}`;
18
- return { title, body };
19
- }
20
- /** Every worker commit subject carries this, so the git log reads as Lucid's work. A PR title
21
- * shouldn't wear it. */
22
- const COMMIT_SUBJECT_PREFIX = /^Lucid:\s*/;
23
- /**
24
- * Per-feature delivery: build ONE worker's PR title + body.
25
- *
26
- * The title is the worker's own FIRST commit subject, which `codeCommitMessage` already built out
27
- * of Lucid's summary of what it did. The lane title can't do that job and shouldn't have been
28
- * asked to: it's `clampTitle(brief.split('\n')[0])`, so it's the opening line of whatever was
29
- * typed at the board, which names the request rather than the change and is usually cut off
30
- * mid-thought (#308). It stays as the fallback for a branch whose subjects couldn't be read.
31
- *
32
- * The first subject rather than the last, because a steered worker's later commits are
33
- * refinements of the piece of work the branch is about. The rest go in the body under the brief
34
- * that asked for them, which is the one thing the brief is genuinely good for. Pure, unit-tested.
35
- */
36
- export function workerPrSummary(title, brief, subjects = []) {
37
- const clean = subjects.map((s) => s.replace(COMMIT_SUBJECT_PREFIX, '').trim()).filter(Boolean);
38
- const t = (clean[0] || title.trim() || 'Fleet worker').slice(0, 120);
39
- const b = brief.trim() || t;
40
- // A single commit says nothing the title hasn't just said, so only list them once there are
41
- // several and the list is actually telling you something.
42
- const rest = clean.length > 1 ? `\n\nCommits:\n${clean.map((c) => `- ${c}`).join('\n')}` : '';
43
- return { title: t, body: b + rest };
44
- }
45
- function ghError(err) {
46
- const stderr = err?.stderr;
47
- const raw = typeof stderr === 'string' && stderr.trim()
48
- ? stderr
49
- : err instanceof Error
50
- ? err.message
51
- : String(err);
52
- return (raw.split('\n')[0] ?? '').slice(0, 200);
53
- }
54
- /**
55
- * Push the integration branch and open (or reuse) ONE pull request for the whole fan-out.
56
- *
57
- * Runs from the lucid/<repo> worktree, which is on the integration branch and shares the repo's
58
- * GitHub remote. The branch is force-pushed because each fleet resets it fresh to HEAD before
59
- * merging — its history is authored per-run, so the remote must follow. If a PR for the branch is
60
- * already open (a re-integrated fleet), its URL is returned and the force-push updates it in place
61
- * rather than opening a duplicate.
62
- *
63
- * Never throws: a missing/unauthed `gh`, or a repo with no GitHub remote, returns `{ error }` the
64
- * phone can surface — the fleet already merged locally regardless.
65
- */
66
- export async function openFleetPr(worktreePath, branch, summary, base) {
67
- const env = { ...process.env, PATH: GH_PATH };
68
- const run = (cmd, args) => exec(cmd, args, { cwd: worktreePath, env, maxBuffer: 8 * 1024 * 1024 });
69
- try {
70
- await run('git', ['push', '--force', '-u', 'origin', branch]);
71
- }
72
- catch (err) {
73
- return { error: ghError(err) };
74
- }
75
- // Reuse an existing open PR for this branch rather than opening a duplicate — the force-push
76
- // above already updated its head.
77
- try {
78
- const { stdout } = await run('gh', [
79
- 'pr',
80
- 'list',
81
- '--head',
82
- branch,
83
- '--state',
84
- 'open',
85
- '--json',
86
- 'url',
87
- '--limit',
88
- '1',
89
- ]);
90
- const existing = JSON.parse(stdout);
91
- if (existing[0]?.url)
92
- return { url: existing[0].url };
93
- }
94
- catch {
95
- // A listing failure shouldn't block a first PR — fall through to create.
96
- }
97
- try {
98
- const { stdout } = await run('gh', [
99
- 'pr',
100
- 'create',
101
- '--head',
102
- branch,
103
- // Target the branch the fleet forked from (repo HEAD), NOT gh's default of the remote's
104
- // default branch — those differ (e.g. a repo checked out on `develop` whose default is
105
- // `main`), and defaulting would open a noisy PR full of unrelated commits.
106
- ...(base ? ['--base', base] : []),
107
- '--title',
108
- summary.title,
109
- '--body',
110
- summary.body,
111
- ]);
112
- const url = stdout
113
- .trim()
114
- .split('\n')
115
- .find((l) => l.startsWith('http'));
116
- return url ? { url } : { error: 'PR created but no URL returned' };
117
- }
118
- catch (err) {
119
- return { error: ghError(err) };
120
- }
121
- }