@opencorelabs/lucidity 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 (219) hide show
  1. package/README.md +9 -2
  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 +57 -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 +116 -101
  44. package/dist/room/computer.d.ts.map +1 -1
  45. package/dist/room/computer.js +1 -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 +57 -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 +77 -74
  77. package/src/room/computer.ts +1 -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/mcp-server/dist/index.js +2 -0
  85. package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
  86. package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
  87. package/vendor/mcp-server/dist/tools/goals.js +38 -0
  88. package/vendor/mcp-server/package.json +1 -1
  89. package/vendor/mcp-server/src/index.ts +2 -0
  90. package/vendor/mcp-server/src/tools/goals.ts +62 -0
  91. package/vendor/runtime/README.md +2 -2
  92. package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
  93. package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
  94. package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
  95. package/vendor/runtime/dist/executor/claudeAgent.d.ts +1 -1
  96. package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
  97. package/vendor/runtime/dist/executor/claudeAgent.js +20 -9
  98. package/vendor/runtime/dist/executor/codex.d.ts +1 -0
  99. package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
  100. package/vendor/runtime/dist/executor/codex.js +68 -36
  101. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
  102. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
  103. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
  104. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
  105. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
  106. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
  107. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
  108. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
  109. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
  110. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
  111. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
  112. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
  113. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
  114. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
  115. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
  116. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
  117. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
  118. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
  119. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
  120. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
  121. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
  122. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
  123. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
  124. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
  125. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
  126. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
  127. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
  128. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
  129. package/vendor/runtime/dist/executor/codexRpc.d.ts +10 -3
  130. package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
  131. package/vendor/runtime/dist/executor/codexRpc.js +18 -3
  132. package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
  133. package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
  134. package/vendor/runtime/dist/executor/codexSessions.js +88 -0
  135. package/vendor/runtime/dist/executor/health.d.ts +2 -1
  136. package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
  137. package/vendor/runtime/dist/executor/health.js +17 -5
  138. package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
  139. package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
  140. package/vendor/runtime/dist/executor/liveTurns.js +12 -5
  141. package/vendor/runtime/dist/executor/ownership.d.ts +35 -0
  142. package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
  143. package/vendor/runtime/dist/executor/ownership.js +99 -0
  144. package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
  145. package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
  146. package/vendor/runtime/dist/executor/providerRouter.js +5 -0
  147. package/vendor/runtime/dist/executor/types.d.ts +2 -0
  148. package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
  149. package/vendor/runtime/dist/index.d.ts +1 -0
  150. package/vendor/runtime/dist/index.d.ts.map +1 -1
  151. package/vendor/runtime/dist/index.js +1 -0
  152. package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
  153. package/vendor/runtime/src/executor/claudeAgent.ts +16 -9
  154. package/vendor/runtime/src/executor/codex.ts +75 -44
  155. package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
  156. package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
  157. package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
  158. package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
  159. package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
  160. package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
  161. package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
  162. package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
  163. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
  164. package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
  165. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
  166. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
  167. package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
  168. package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
  169. package/vendor/runtime/src/executor/codexRpc.ts +22 -4
  170. package/vendor/runtime/src/executor/codexSessions.ts +108 -0
  171. package/vendor/runtime/src/executor/health.ts +16 -6
  172. package/vendor/runtime/src/executor/liveTurns.ts +12 -5
  173. package/vendor/runtime/src/executor/ownership.ts +76 -0
  174. package/vendor/runtime/src/executor/providerRouter.ts +6 -0
  175. package/vendor/runtime/src/executor/types.ts +2 -0
  176. package/vendor/runtime/src/index.ts +1 -0
  177. package/vendor/shared/dist/agentCommands.d.ts +1 -0
  178. package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
  179. package/vendor/shared/dist/cardStudio.d.ts +41 -0
  180. package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
  181. package/vendor/shared/dist/cardStudio.js +13 -3
  182. package/vendor/shared/dist/computer.d.ts +7 -1
  183. package/vendor/shared/dist/computer.d.ts.map +1 -1
  184. package/vendor/shared/dist/computer.js +12 -2
  185. package/vendor/shared/dist/constants.d.ts +3 -3
  186. package/vendor/shared/dist/constants.d.ts.map +1 -1
  187. package/vendor/shared/dist/constants.js +5 -4
  188. package/vendor/shared/dist/goalNotes.d.ts +4 -0
  189. package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
  190. package/vendor/shared/dist/goalNotes.js +23 -0
  191. package/vendor/shared/dist/goals.d.ts +835 -0
  192. package/vendor/shared/dist/goals.d.ts.map +1 -0
  193. package/vendor/shared/dist/goals.js +198 -0
  194. package/vendor/shared/dist/index.d.ts +3 -0
  195. package/vendor/shared/dist/index.d.ts.map +1 -1
  196. package/vendor/shared/dist/index.js +3 -0
  197. package/vendor/shared/dist/schemas/harness.d.ts +101 -0
  198. package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
  199. package/vendor/shared/dist/schemas/harness.js +6 -0
  200. package/vendor/shared/dist/workspaces.d.ts +138 -0
  201. package/vendor/shared/dist/workspaces.d.ts.map +1 -0
  202. package/vendor/shared/dist/workspaces.js +40 -0
  203. package/vendor/shared/src/agentCommands.ts +1 -0
  204. package/vendor/shared/src/cardStudio.ts +13 -3
  205. package/vendor/shared/src/computer.ts +16 -2
  206. package/vendor/shared/src/constants.ts +5 -4
  207. package/vendor/shared/src/goalNotes.ts +23 -0
  208. package/vendor/shared/src/goals.ts +237 -0
  209. package/vendor/shared/src/index.ts +4 -0
  210. package/vendor/shared/src/schemas/harness.ts +6 -0
  211. package/vendor/shared/src/workspaces.ts +48 -0
  212. package/dist/coding/fleetIntegrate.d.ts +0 -37
  213. package/dist/coding/fleetIntegrate.d.ts.map +0 -1
  214. package/dist/coding/fleetIntegrate.js +0 -64
  215. package/dist/coding/openFleetPr.d.ts +0 -41
  216. package/dist/coding/openFleetPr.d.ts.map +0 -1
  217. package/dist/coding/openFleetPr.js +0 -121
  218. package/src/coding/fleetIntegrate.ts +0 -95
  219. package/src/coding/openFleetPr.ts +0 -148
@@ -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
- }
@@ -1,95 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
- import { ensureWorkspace, sessionBranch } from './worktree.js';
4
-
5
- const exec = promisify(execFile);
6
-
7
- async function git(cwd: string, args: string[]): Promise<string> {
8
- const { stdout } = await exec('git', args, { cwd, maxBuffer: 32 * 1024 * 1024 });
9
- return stdout;
10
- }
11
-
12
- export interface FleetConflict {
13
- workerId: string;
14
- /** The files that couldn't merge cleanly. */
15
- paths: string[];
16
- }
17
-
18
- export interface IntegrationResult {
19
- /** The branch the workers were integrated onto — the bare `lucid/<repo>` session, which
20
- * is also where the fleet's single PR opens from. */
21
- branch: string;
22
- /** Worker ids that merged cleanly, in the order they landed. */
23
- merged: string[];
24
- /** Workers whose branch conflicted; their merge was aborted and left for the user to hand
25
- * back to the worker as a fresh turn. */
26
- conflicts: FleetConflict[];
27
- }
28
-
29
- /**
30
- * Integrate finished workers onto the fleet branch, one at a time in merge order.
31
- *
32
- * The integration worktree is the bare repo session (`lucid/<repo>`), reset to HEAD, so the
33
- * fan-out's result is a single branch cut fresh from where the user started — clean history to
34
- * open one PR from. Each worker's `fleet/<repo>/<workerId>` branch is merged in; a conflict is
35
- * caught (not thrown), the merge aborted so the next worker can still land, and reported via
36
- * `onConflict` so the conductor surfaces it in the feed rather than silently dropping work.
37
- *
38
- * Sequential and in order because that's where overlap actually bites: the workers ran in
39
- * isolated worktrees and never raced each other on disk — only the merge can conflict, and only
40
- * against what already landed.
41
- */
42
- export async function integrateWorkers(
43
- repoRoot: string,
44
- repoId: string,
45
- workers: { workerId: string; mergeOrder: number }[],
46
- opts: {
47
- baseDir?: string;
48
- onMerged?: (workerId: string) => void;
49
- onConflict?: (conflict: FleetConflict) => void;
50
- } = {},
51
- ): Promise<IntegrationResult> {
52
- const branch = sessionBranch(repoId);
53
- // Fresh bare session = lucid/<repo> reset to HEAD: the integration target.
54
- const ws = await ensureWorkspace(repoRoot, repoId, {
55
- fresh: true,
56
- baseDir: opts.baseDir,
57
- });
58
-
59
- const ordered = [...workers].sort((a, b) => a.mergeOrder - b.mergeOrder);
60
- const merged: string[] = [];
61
- const conflicts: FleetConflict[] = [];
62
-
63
- for (const w of ordered) {
64
- const workerBranch = sessionBranch(repoId, w.workerId);
65
- try {
66
- await git(ws.path, [
67
- 'merge',
68
- '--no-ff',
69
- '-m',
70
- `Merge fleet worker ${w.workerId}`,
71
- workerBranch,
72
- ]);
73
- merged.push(w.workerId);
74
- opts.onMerged?.(w.workerId);
75
- } catch {
76
- // A conflict (or any merge failure): record the unmerged paths, abort so the branch is
77
- // clean for the next worker, and report. Never fatal — one bad lane can't sink the fleet.
78
- const unmerged = await git(ws.path, [
79
- 'diff',
80
- '--name-only',
81
- '--diff-filter=U',
82
- ]).catch(() => '');
83
- const paths = unmerged
84
- .split('\n')
85
- .map((s) => s.trim())
86
- .filter(Boolean);
87
- await git(ws.path, ['merge', '--abort']).catch(() => {});
88
- const conflict: FleetConflict = { workerId: w.workerId, paths };
89
- conflicts.push(conflict);
90
- opts.onConflict?.(conflict);
91
- }
92
- }
93
-
94
- return { branch, merged, conflicts };
95
- }
@@ -1,148 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
-
4
- const exec = promisify(execFile);
5
-
6
- /** The daemon runs under launchd, whose PATH excludes Homebrew — so `gh` (from /opt/homebrew/bin
7
- * or /usr/local/bin) may not resolve. Prepend the usual bins. (mirrors listPrs.ts) */
8
- const GH_PATH = [process.env.PATH, '/opt/homebrew/bin', '/usr/local/bin'].filter(Boolean).join(':');
9
-
10
- export interface FleetPrSummary {
11
- title: string;
12
- body: string;
13
- }
14
-
15
- /**
16
- * Build the PR's title + body from the fleet goal and the workers that actually landed. Pure so
17
- * it can be unit-tested; the spawn wrapper below is covered by a real run.
18
- */
19
- export function fleetPrSummary(goal: string, mergedTitles: string[]): FleetPrSummary {
20
- const g = goal.trim() || 'Fleet';
21
- const title = `Fleet: ${g}`.slice(0, 120);
22
- const lines = mergedTitles.length
23
- ? mergedTitles.map((t) => `- ${t}`).join('\n')
24
- : '- (no worker changes)';
25
- const body = `${g}\n\nMerged by the fleet:\n${lines}`;
26
- return { title, body };
27
- }
28
-
29
- /** Every worker commit subject carries this, so the git log reads as Lucid's work. A PR title
30
- * shouldn't wear it. */
31
- const COMMIT_SUBJECT_PREFIX = /^Lucid:\s*/;
32
-
33
- /**
34
- * Per-feature delivery: build ONE worker's PR title + body.
35
- *
36
- * The title is the worker's own FIRST commit subject, which `codeCommitMessage` already built out
37
- * of Lucid's summary of what it did. The lane title can't do that job and shouldn't have been
38
- * asked to: it's `clampTitle(brief.split('\n')[0])`, so it's the opening line of whatever was
39
- * typed at the board, which names the request rather than the change and is usually cut off
40
- * mid-thought (#308). It stays as the fallback for a branch whose subjects couldn't be read.
41
- *
42
- * The first subject rather than the last, because a steered worker's later commits are
43
- * refinements of the piece of work the branch is about. The rest go in the body under the brief
44
- * that asked for them, which is the one thing the brief is genuinely good for. Pure, unit-tested.
45
- */
46
- export function workerPrSummary(
47
- title: string,
48
- brief: string,
49
- subjects: string[] = [],
50
- ): FleetPrSummary {
51
- const clean = subjects.map((s) => s.replace(COMMIT_SUBJECT_PREFIX, '').trim()).filter(Boolean);
52
- const t = (clean[0] || title.trim() || 'Fleet worker').slice(0, 120);
53
- const b = brief.trim() || t;
54
- // A single commit says nothing the title hasn't just said, so only list them once there are
55
- // several and the list is actually telling you something.
56
- const rest = clean.length > 1 ? `\n\nCommits:\n${clean.map((c) => `- ${c}`).join('\n')}` : '';
57
- return { title: t, body: b + rest };
58
- }
59
-
60
- export interface FleetPrResult {
61
- url?: string;
62
- error?: string;
63
- }
64
-
65
- function ghError(err: unknown): string {
66
- const stderr = (err as { stderr?: unknown })?.stderr;
67
- const raw =
68
- typeof stderr === 'string' && stderr.trim()
69
- ? stderr
70
- : err instanceof Error
71
- ? err.message
72
- : String(err);
73
- return (raw.split('\n')[0] ?? '').slice(0, 200);
74
- }
75
-
76
- /**
77
- * Push the integration branch and open (or reuse) ONE pull request for the whole fan-out.
78
- *
79
- * Runs from the lucid/<repo> worktree, which is on the integration branch and shares the repo's
80
- * GitHub remote. The branch is force-pushed because each fleet resets it fresh to HEAD before
81
- * merging — its history is authored per-run, so the remote must follow. If a PR for the branch is
82
- * already open (a re-integrated fleet), its URL is returned and the force-push updates it in place
83
- * rather than opening a duplicate.
84
- *
85
- * Never throws: a missing/unauthed `gh`, or a repo with no GitHub remote, returns `{ error }` the
86
- * phone can surface — the fleet already merged locally regardless.
87
- */
88
- export async function openFleetPr(
89
- worktreePath: string,
90
- branch: string,
91
- summary: FleetPrSummary,
92
- base?: string,
93
- ): Promise<FleetPrResult> {
94
- const env = { ...process.env, PATH: GH_PATH };
95
- const run = (cmd: string, args: string[]) =>
96
- exec(cmd, args, { cwd: worktreePath, env, maxBuffer: 8 * 1024 * 1024 });
97
-
98
- try {
99
- await run('git', ['push', '--force', '-u', 'origin', branch]);
100
- } catch (err) {
101
- return { error: ghError(err) };
102
- }
103
-
104
- // Reuse an existing open PR for this branch rather than opening a duplicate — the force-push
105
- // above already updated its head.
106
- try {
107
- const { stdout } = await run('gh', [
108
- 'pr',
109
- 'list',
110
- '--head',
111
- branch,
112
- '--state',
113
- 'open',
114
- '--json',
115
- 'url',
116
- '--limit',
117
- '1',
118
- ]);
119
- const existing = JSON.parse(stdout) as { url: string }[];
120
- if (existing[0]?.url) return { url: existing[0].url };
121
- } catch {
122
- // A listing failure shouldn't block a first PR — fall through to create.
123
- }
124
-
125
- try {
126
- const { stdout } = await run('gh', [
127
- 'pr',
128
- 'create',
129
- '--head',
130
- branch,
131
- // Target the branch the fleet forked from (repo HEAD), NOT gh's default of the remote's
132
- // default branch — those differ (e.g. a repo checked out on `develop` whose default is
133
- // `main`), and defaulting would open a noisy PR full of unrelated commits.
134
- ...(base ? ['--base', base] : []),
135
- '--title',
136
- summary.title,
137
- '--body',
138
- summary.body,
139
- ]);
140
- const url = stdout
141
- .trim()
142
- .split('\n')
143
- .find((l) => l.startsWith('http'));
144
- return url ? { url } : { error: 'PR created but no URL returned' };
145
- } catch (err) {
146
- return { error: ghError(err) };
147
- }
148
- }