carrick 0.3.143 → 0.3.145

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 (111) hide show
  1. package/README.md +1 -1
  2. package/bin/carrick.mjs +7 -7
  3. package/dist/auth/read.d.ts +0 -10
  4. package/dist/auth/read.js +3 -11
  5. package/dist/auth/read.js.map +1 -1
  6. package/dist/cli.d.ts +23 -20
  7. package/dist/cli.js +17 -32
  8. package/dist/cli.js.map +1 -1
  9. package/dist/contract.d.ts +54 -0
  10. package/dist/contract.js +14 -0
  11. package/dist/contract.js.map +1 -1
  12. package/dist/hook/checked.d.ts +11 -0
  13. package/dist/hook/checked.js +44 -0
  14. package/dist/hook/checked.js.map +1 -0
  15. package/dist/hook/edited.d.ts +22 -0
  16. package/dist/hook/edited.js +84 -0
  17. package/dist/hook/edited.js.map +1 -0
  18. package/dist/hook/invoker.d.ts +7 -0
  19. package/dist/hook/invoker.js +18 -0
  20. package/dist/hook/invoker.js.map +1 -0
  21. package/dist/hook/late.d.ts +8 -0
  22. package/dist/hook/late.js +60 -0
  23. package/dist/hook/late.js.map +1 -0
  24. package/dist/hook/post-edit.d.ts +0 -22
  25. package/dist/hook/post-edit.js +78 -126
  26. package/dist/hook/post-edit.js.map +1 -1
  27. package/dist/hook/post-read.js +19 -9
  28. package/dist/hook/post-read.js.map +1 -1
  29. package/dist/hook/probe.d.ts +15 -0
  30. package/dist/hook/probe.js +41 -0
  31. package/dist/hook/probe.js.map +1 -0
  32. package/dist/hook/recheck-run.d.ts +2 -0
  33. package/dist/hook/recheck-run.js +28 -0
  34. package/dist/hook/recheck-run.js.map +1 -0
  35. package/dist/hook/rechecks.d.ts +108 -0
  36. package/dist/hook/rechecks.js +537 -0
  37. package/dist/hook/rechecks.js.map +1 -0
  38. package/dist/hook/refresh.d.ts +1 -0
  39. package/dist/hook/refresh.js +1 -1
  40. package/dist/hook/refresh.js.map +1 -1
  41. package/dist/hook/reuse.d.ts +25 -5
  42. package/dist/hook/reuse.js +61 -14
  43. package/dist/hook/reuse.js.map +1 -1
  44. package/dist/hook/session-start.js +14 -0
  45. package/dist/hook/session-start.js.map +1 -1
  46. package/dist/hook/stop-wait.d.ts +17 -0
  47. package/dist/hook/stop-wait.js +120 -0
  48. package/dist/hook/stop-wait.js.map +1 -0
  49. package/dist/hook/stop.js +14 -3
  50. package/dist/hook/stop.js.map +1 -1
  51. package/dist/hook/user-prompt.js +6 -3
  52. package/dist/hook/user-prompt.js.map +1 -1
  53. package/dist/init/agents-section.d.ts +18 -4
  54. package/dist/init/agents-section.js +66 -18
  55. package/dist/init/agents-section.js.map +1 -1
  56. package/dist/init/connect.d.ts +6 -107
  57. package/dist/init/connect.js +7 -318
  58. package/dist/init/connect.js.map +1 -1
  59. package/dist/init/doctor.d.ts +8 -71
  60. package/dist/init/doctor.js +37 -223
  61. package/dist/init/doctor.js.map +1 -1
  62. package/dist/init/hosted.d.ts +7 -7
  63. package/dist/init/hosted.js +8 -10
  64. package/dist/init/hosted.js.map +1 -1
  65. package/dist/init/outdated.d.ts +11 -0
  66. package/dist/init/outdated.js +1 -1
  67. package/dist/init/outdated.js.map +1 -1
  68. package/dist/init/output.d.ts +0 -55
  69. package/dist/init/output.js +0 -142
  70. package/dist/init/output.js.map +1 -1
  71. package/dist/init/projects.d.ts +3 -200
  72. package/dist/init/projects.js +22 -352
  73. package/dist/init/projects.js.map +1 -1
  74. package/dist/init/remove.js +4 -5
  75. package/dist/init/remove.js.map +1 -1
  76. package/dist/init/repos.d.ts +25 -53
  77. package/dist/init/repos.js +28 -65
  78. package/dist/init/repos.js.map +1 -1
  79. package/dist/init/run.d.ts +52 -212
  80. package/dist/init/run.js +252 -988
  81. package/dist/init/run.js.map +1 -1
  82. package/dist/init/self-update.d.ts +18 -0
  83. package/dist/init/self-update.js +147 -0
  84. package/dist/init/self-update.js.map +1 -0
  85. package/dist/init/settings.d.ts +2 -0
  86. package/dist/init/settings.js +13 -2
  87. package/dist/init/settings.js.map +1 -1
  88. package/dist/init/task-skills.d.ts +1 -0
  89. package/dist/init/task-skills.js +1 -1
  90. package/dist/init/task-skills.js.map +1 -1
  91. package/dist/render.d.ts +24 -6
  92. package/dist/render.js +133 -42
  93. package/dist/render.js.map +1 -1
  94. package/dist/templates.d.ts +1 -6
  95. package/dist/templates.js +4 -14
  96. package/dist/templates.js.map +1 -1
  97. package/package.json +6 -6
  98. package/plugin/.claude-plugin/plugin.json +1 -1
  99. package/plugin/hooks/hooks.json +3 -2
  100. package/sidecar/dist/src/capture/api.d.ts +2 -2
  101. package/sidecar/dist/src/capture/deno-project.js +5 -1
  102. package/sidecar/dist/src/index.js +1 -1
  103. package/sidecar/dist/src/library-claims.d.ts +4 -0
  104. package/sidecar/dist/src/library-claims.js +2 -2
  105. package/sidecar/dist/src/project-loader.js +9 -2
  106. package/sidecar/dist/src/type-inferrer.d.ts +17 -2
  107. package/sidecar/dist/src/type-inferrer.js +59 -16
  108. package/sidecar/dist/src/types.d.ts +26 -0
  109. package/sidecar/dist/src/validators.d.ts +6 -0
  110. package/sidecar/dist/src/validators.js +2 -0
  111. package/templates/carrick.json +0 -7
package/dist/init/run.js CHANGED
@@ -1,23 +1,26 @@
1
- // Authenticated setup; Rust owns the workspace and service proposal.
1
+ // Authenticated setup of this machine for a workspace Carrick indexes.
2
2
  //
3
3
  // What this prints is one line per thing that happened (carrick#1026). The
4
4
  // reasoning behind each step — how the hooks deliver, which editor extension
5
- // to install, why the scan is left to CI, what a hand-written carrick.json
6
- // looks like — is in the docs, at the `DOCS*` links in `output.ts`, and this
7
- // command links to them rather than repeating them. The record of the run stays here,
8
- // because nothing else can state it: this login, this project, these repos,
9
- // this many packages, this index.
5
+ // to install — is in the docs, at the `DOCS*` links in `output.ts`, and this
6
+ // command links to them rather than repeating them. The record of the run
7
+ // stays here, because nothing else can state it: this login, this project,
8
+ // these repos, this index.
9
+ //
10
+ // There is one run (carrick#3361). Carrick holds each project's config and
11
+ // builds its index in the cloud, so nothing here proposes services, writes a
12
+ // config, creates or moves a project, or starts a scan: init reads which of
13
+ // these repos the workspace holds, installs the local tools for them, and
14
+ // reads their index in.
10
15
  import fs from "node:fs";
11
- import os from "node:os";
12
16
  import path from "node:path";
13
17
  import { readCredential } from "../auth/credentials.js";
14
- import { openBrowser } from "../auth/oauth.js";
15
18
  import { signIn } from "../auth/run.js";
16
19
  import { resolveRepos } from "../auth/read.js";
17
- import { deriveWorkspace, selectedProposal, selectRepos, siblingRepos, initFolderAbove, writeProposal, realPath, repoRoots, MAX_SIBLINGS, PROPOSAL_FILE, repoIdentity, } from "./repos.js";
18
- import { connectLine, connectRepos, projectAssignments, reposAreInProject, unconnectedRepos, workspaceUrls, } from "./connect.js";
20
+ import { deriveWorkspace, ensureIndexDir, keepRepos, selectRepos, siblingRepos, initFolderAbove, realPath, repoRoots, repoIdentity, } from "./repos.js";
21
+ import { reposUrl } from "./connect.js";
19
22
  import { downloadHostedIndex, hostedReport, nativeRunner, STEP_LABEL } from "./hosted.js";
20
- import { createProject, listProjects, planProject, projectLabel, projectStep, reposPhrase, SLUG, } from "./projects.js";
23
+ import { listProjects, projectLabel, SLUG } from "./projects.js";
21
24
  import { writeRepoCopy } from "./repo-copies.js";
22
25
  import { claudeCodeFound, connectMcpClients, mcpLine, offeredFileClients } from "./mcp.js";
23
26
  import { hookCommand, mergeCarrickHooks, removeCarrickHooks } from "./settings.js";
@@ -29,60 +32,27 @@ import { findCarrick, offerGlobalInstall } from "../global-install.js";
29
32
  import { currentVersion } from "../update.js";
30
33
  import { writeIfChanged } from "./files.js";
31
34
  import { excludedRepos, readWorkspaceFile, removeSelection, writeSelection, WORKSPACE_FILE } from "./workspace-file.js";
32
- import { createOutput, DOCS_EDITOR, DOCS_INDEX, DOCS_INIT_FILES, listBlock, PromptCancelled, tilde, } from "./output.js";
33
- import { renderTemplate, TEMPLATE_PATHS } from "../templates.js";
34
- /**
35
- * The repos this run covers that the scaffold tool still has work in.
36
- *
37
- * The two files that tool writes: the `carrick.json` a scan reads, and the
38
- * workflow that runs the scan. A repo holding both has been scaffolded, and
39
- * the closing instruction is then an instruction to do nothing — which is what
40
- * it was on a folder where every repo was already set up (carrick#1365).
41
- *
42
- * The repo root only, because that is where the scanner looks for a config
43
- * (`Config::load_services`): a `carrick.json` deeper in the tree is a fixture
44
- * or a nested example, not this repo's.
45
- */
46
- export function reposToScaffold(repos, exists = fs.existsSync) {
47
- return repos.filter((repo) => !exists(path.join(repo.path, TEMPLATE_PATHS["carrick.json"])) ||
48
- !exists(path.join(repo.path, TEMPLATE_PATHS.workflow)));
49
- }
50
- /**
51
- * The instruction to paste, naming the repos it is about.
52
- *
53
- * The scaffold tool's branch turns on `repo` and turns soft without it: with
54
- * no `repo` the response keeps its default ending and tells the agent to run
55
- * the scan — on a repo CI already indexes, which is the row the whole
56
- * workspace reads (carrick-cloud `src/tools/scaffold.ts`, cloud#805 item 1).
57
- * So the names are in the sentence, one call per repo.
58
- *
59
- * One repo whose owner/repo is known is the value of `repo`, said once; the
60
- * sentence used to name it and then ask for it again (carrick#1574). A repo
61
- * known here only by its folder still needs the agent to find its owner/repo.
62
- * The several-repo sentence is carrick-cloud#1404's: the tool now takes them
63
- * all in one `repos` call.
64
- */
65
- export function scaffoldSentence(repos) {
66
- const names = repos.map((repo) => repo.name ?? path.basename(repo.path));
67
- if (names.length === 1) {
68
- return repos[0]?.name
69
- ? `Run the carrick scaffold tool with \`repo\` set to ${names[0]}, and follow what it returns.`
70
- : `Run the carrick scaffold tool for ${names[0]}, passing its owner/repo as \`repo\`, and follow what it returns.`;
71
- }
72
- const shown = names.length > 3 ? `${names.slice(0, 3).join(", ")} and ${names.length - 3} more` : names.join(", ");
73
- return `Run the carrick scaffold tool for ${shown}, once each, passing that repo's owner/repo as \`repo\`, and follow what it returns.`;
74
- }
75
- /** The title of the block a run closes on when there is scaffolding left to do. */
76
- export const NEXT_TITLE = "Next: paste this into a new agent session";
35
+ import { createOutput, DOCS_EDITOR, DOCS_INIT_FILES, listBlock, PromptCancelled, tilde, } from "./output.js";
36
+ import { renderTemplate } from "../templates.js";
37
+ /** What a run with nothing left to set up closes on: what this machine can do now. */
38
+ export const READY_SENTENCE = "The index is on this machine: `carrick check <file>` answers for a file, and your agent can ask who calls an operation.";
39
+ /** The title of the block a run closes on (carrick#3286). */
40
+ export const CLOUD_NEXT_TITLE = "Done. Open a new agent session in this folder, then ask it:";
41
+ /** The question the ready email also carries, so both say the same first thing. */
42
+ export const ASK_YOUR_AGENT_PROMPT = "Use Carrick to list every service in our project and the number of endpoints each one exposes";
77
43
  /**
78
- * The line that tells the agent where the proposal is, for a run that set up
79
- * the folder above the one it started in (carrick#1512).
44
+ * What a run closes on, under CLOUD_NEXT_TITLE: the first question to ask,
45
+ * then only the steps still open. What init wrote is already listed while it
46
+ * runs, and a failed step warns where it fails, so neither is repeated here.
47
+ * Nobody scaffolds, so there is no instruction to paste (carrick#3286).
80
48
  */
81
- export function initFolderSentence(workspace) {
82
- return `The init folder is ${tilde(workspace)}.`;
49
+ export function cloudNextLines(codexTrust, indexPending) {
50
+ return [
51
+ `${ASK_YOUR_AGENT_PROMPT}.`,
52
+ ...(indexPending ? ["", "The index is not on this machine yet: `carrick refresh` reads it in once Carrick has built it."] : []),
53
+ ...(codexTrust ? ["", "Codex: open `codex` here once and trust the project's hooks, or it skips them."] : []),
54
+ ];
83
55
  }
84
- /** What a run with nothing left to set up closes on: what this machine can do now. */
85
- export const READY_SENTENCE = "The index is on this machine: `carrick check <file>` answers for a file, and your agent can ask who calls an operation.";
86
56
  const OWNER_REPO = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
87
57
  export function parseArgs(argv, cwd = process.cwd()) {
88
58
  const options = {
@@ -90,27 +60,20 @@ export function parseArgs(argv, cwd = process.cwd()) {
90
60
  project: null,
91
61
  repos: [],
92
62
  editors: [],
93
- assumeYes: false,
94
- allowMove: false,
95
63
  installGlobal: false,
96
- local: false,
97
64
  };
98
65
  for (let index = 0; index < argv.length; index += 1) {
99
66
  const argument = argv[index];
100
67
  switch (argument) {
68
+ // Accepted and answered by nothing: init asks nothing after sign-in.
69
+ // The release smoke, the release guard's init row and an eval script
70
+ // pass it, so it is not refused (carrick#3361).
101
71
  case "--yes":
102
72
  case "-y":
103
- options.assumeYes = true;
104
73
  break;
105
74
  case "--install-global":
106
75
  options.installGlobal = true;
107
76
  break;
108
- case "--allow-move":
109
- options.allowMove = true;
110
- break;
111
- case "--local":
112
- options.local = true;
113
- break;
114
77
  case "--project": {
115
78
  const value = argv[index + 1];
116
79
  if (!value)
@@ -171,47 +134,36 @@ export function parseArgs(argv, cwd = process.cwd()) {
171
134
  }
172
135
  function help() {
173
136
  return [
174
- "carrick init [DIRECTORY] [--repo OWNER/REPO]... [--project SLUG] [--mcp EDITOR] [--allow-move] [--local]",
137
+ "carrick init [DIRECTORY] [--repo OWNER/REPO]... [--mcp EDITOR] [--install-global]",
175
138
  "",
176
139
  "Sign in (here, or beforehand with carrick login), then set up a repository",
177
- "or a folder of repos: which repos this install covers, the project, the repo",
178
- "connection, the agent hooks, the MCP connection, and the service proposal",
179
- "your agent turns into carrick.json. It writes nothing into the repository but",
180
- "the ignored .carrick directory, the hook settings, the four task skills",
181
- "your agent loads, and a short \"Carrick check\" section in AGENTS.md. No model runs and nothing is uploaded. Where Carrick already",
182
- "holds an index for these repos, it reads that index into .carrick so this",
183
- "machine can answer from it. That read re-reads your source here first, which",
184
- "takes minutes on a large workspace. It skips the re-read when .carrick already",
185
- "holds an index current for this checkout. Nothing is written, here or in",
186
- "Carrick, until you accept what it proposes. Where Carrick builds the index for",
187
- "your workspace, init asks nothing after sign-in: it sets up the repos here that",
188
- "the workspace holds, lists what it adds, and reads their index in.",
140
+ "or a folder of repos for your agent: the agent hooks, the four task skills",
141
+ "your agent loads, a short \"Carrick check\" section in AGENTS.md, and the MCP",
142
+ "connection. It covers the repos here that your Carrick workspace holds, and",
143
+ "reads the index Carrick has built for them into .carrick so this machine can",
144
+ "answer from it. That read re-reads your source here first, which takes",
145
+ "minutes on a large workspace. It skips the re-read when .carrick already holds",
146
+ "an index current for this checkout. Carrick builds the index itself, in the",
147
+ "cloud: init asks nothing after sign-in, runs no scan, and writes nothing into",
148
+ "the repository but the ignored .carrick directory, the hook settings, the",
149
+ "skills and that section.",
189
150
  "",
190
151
  " -w, --workspace DIR The folder holding the repos (default: this one)",
191
- " --repo OWNER/REPO A repo this install covers: repeatable, or one",
192
- " comma-separated list. In a folder of repos without a",
193
- " terminal to choose in, this is required. It also names",
194
- " the GitHub repo whose origin remote names none",
195
- " --project SLUG Put those repos in this Carrick project, creating it",
196
- " if it is not there. A repo that is in another project",
197
- " is MOVED out of it, which changes what every agent",
198
- " querying either project can see, so the move is named",
199
- " and asked about separately",
200
- " --allow-move Accept those moves without being asked. --yes does not",
201
- " --mcp EDITOR Also add Carrick to this editor's own MCP configuration,",
202
- " which is a file outside this workspace: repeatable, or one",
203
- " comma-separated list. Without a terminal no editor file is",
204
- " written unless this names one, and --yes does not name one",
205
- " -y, --yes Take the proposal as printed",
152
+ " --repo OWNER/REPO Cover only this repo: repeatable, or one",
153
+ " comma-separated list. It also names the GitHub repo",
154
+ " whose origin remote names none",
155
+ " --project SLUG Check that the repos are in this Carrick project.",
156
+ " Repos change project on the dashboard, so a project",
157
+ " they are not in stops the run",
158
+ " --mcp EDITOR Add Carrick to this editor's own MCP configuration,",
159
+ " a file outside this workspace: repeatable, or one",
160
+ " comma-separated list. Without it, each editor whose",
161
+ " command is on this machine gets the entry",
206
162
  " --install-global Install carrick on this machine where there is none,",
207
163
  " so the agent hooks can run it by name after this run",
208
- " ends. A terminal is asked instead; --yes is not this",
209
- " --local Set up for an index built on this machine: choose the",
210
- " repos and the project here, and get the scan steps for",
211
- " your agent",
164
+ " ends",
212
165
  "",
213
166
  `What init installs, the hooks included: ${DOCS_INIT_FILES}`,
214
- `CI and a carrick.json written by hand: ${DOCS_INDEX}`,
215
167
  `The editor extension: ${DOCS_EDITOR}`,
216
168
  ].join("\n");
217
169
  }
@@ -231,8 +183,8 @@ function carrickOnPath() {
231
183
  * The repos a project holds that this machine does not, one line per project.
232
184
  *
233
185
  * Carrick answers across every repo in a project, so a machine holding half of
234
- * one gets half the answers, and the connection line above names only what is
235
- * here. `project_repos` is the workspace read's answer to that: the whole
186
+ * one gets half the answers, and the summary line names only what is here.
187
+ * `project_repos` is the workspace read's answer to that: the whole
236
188
  * membership of every project the requested repos are in (carrick#993 row 18).
237
189
  * Capped and counted like the identity lines, because a project can hold two
238
190
  * hundred.
@@ -272,13 +224,8 @@ function listed(items, cap) {
272
224
  }
273
225
  /**
274
226
  * The one line that says what is set up: the project and the repos in it
275
- * from this run (carrick#1489, carrick#1512).
276
- *
277
- * What was written was the list the reader said yes to, and a hook file that
278
- * could not be written has its own line, so what is left to say is where the
279
- * repos are. Only repos with a GitHub remote are named: a repo with none is in
280
- * no project. The line says what it reports: a bare "Shop (shop): api" did
281
- * not (carrick#1574).
227
+ * from this run (carrick#1489, carrick#1512). The line says what it reports:
228
+ * a bare "Shop (shop): api" did not (carrick#1574).
282
229
  */
283
230
  export function summaryLine(project, repos) {
284
231
  const sorted = [...repos].sort();
@@ -287,18 +234,18 @@ export function summaryLine(project, repos) {
287
234
  return repos.length === 0 ? where : `${where}: ${names}`;
288
235
  }
289
236
  /**
290
- * The installs a first scan would be refused over, as commands to run.
237
+ * The installs the local read would have needed for full types, as commands.
291
238
  *
292
- * The scanner states them (`not_installed` on each derived repo, from the same
293
- * preflight rule the scan refuses on), so this only says where each runs, as
294
- * a path from the workspace the agent is in (carrick#1489).
239
+ * The scanner states them (`not_installed` on each derived repo, from its
240
+ * preflight rule), so this only says where each runs, as a path from the
241
+ * workspace (carrick#1489). A repo read in from the hosted index carries the
242
+ * hosted scan's types, captured with dependencies installed, so it is not
243
+ * named (carrick#2839).
295
244
  */
296
245
  export function installCommands(plan, readFromHosted = []) {
297
246
  const commands = [];
298
247
  const hosted = new Set(readFromHosted.map(realPath));
299
248
  for (const repo of plan.repos) {
300
- // Its types are the hosted scan's, captured with dependencies installed
301
- // (carrick#2839).
302
249
  if (hosted.has(realPath(repo.path)))
303
250
  continue;
304
251
  for (const row of repo.not_installed) {
@@ -311,34 +258,26 @@ export function installCommands(plan, readFromHosted = []) {
311
258
  return commands;
312
259
  }
313
260
  /**
314
- * The sentence that installs them, when there is anything to install: an
315
- * instruction to the agent, or a line to the reader when no instruction is
316
- * printed. On a workspace whose index Carrick builds there is no next scan on
317
- * this machine, so that reader's line ends on the read instead ("cloud").
261
+ * The sentence that installs them, when there is anything to install. There is
262
+ * no scan on this machine to install them for, so it ends on the read.
318
263
  */
319
- export function installSentence(commands, to) {
264
+ export function installSentence(commands) {
320
265
  if (commands.length === 0)
321
266
  return null;
322
- if (to === "cloud") {
323
- return `Dependencies are not installed, so the index here was read without their types. Run ${listed(commands, 5)}, then carrick refresh.`;
324
- }
325
- return to === "agent"
326
- ? `First install dependencies: run ${listed(commands, 5)}.`
327
- : `Dependencies are not installed. Run ${listed(commands, 5)} before the next scan.`;
267
+ return `Dependencies are not installed, so the index here was read without their types. Run ${listed(commands, 5)}, then carrick refresh.`;
328
268
  }
329
269
  /**
330
- * The files the write step creates, as one line of the list "Go ahead?" is
331
- * asked about (carrick#1489, carrick#1512).
270
+ * The files the run creates, as one line under "Next:" (carrick#1489,
271
+ * carrick#1512).
332
272
  *
333
273
  * Directories, because each holds several files and the line has to stay one
334
274
  * sentence; every file outside the workspace by its own path, because those
335
275
  * belong to somebody's editor. Claude Code's server list is written by its own
336
276
  * command, so it is named rather than given a path. It says "add", because
337
- * that is what happens: every writer here merges, and a line that listed
338
- * folders read as though it replaced them. And it says where: a folder of
339
- * repos gets the hooks and skills in the folder and again in each repo, with
340
- * that repo's `.git/info/exclude` (carrick#1512, option A), so `folder` is the
341
- * folder as the reader types it, and null for a run in one repo.
277
+ * that is what happens: every writer here merges. And it says where: a folder
278
+ * of repos gets the hooks and skills in the folder and again in each repo,
279
+ * with that repo's `.git/info/exclude` (carrick#1512, option A), so `folder`
280
+ * is the folder as the reader types it, and null for a run in one repo.
342
281
  */
343
282
  export function writesLine(options) {
344
283
  const mcp = [
@@ -353,97 +292,22 @@ export function writesLine(options) {
353
292
  ];
354
293
  return `${parts.slice(0, -1).join(", ")}, and ${parts.at(-1)}`;
355
294
  }
356
- /** The list "Go ahead?" is asked about, under its heading. */
295
+ /** The list of what the run writes, under its heading. */
357
296
  export function nextBlock(lines) {
358
297
  return listBlock("Next:", lines);
359
298
  }
360
299
  /**
361
- * The GitHub App line of that list: which repos still need the App.
362
- *
363
- * With a terminal, init opens the page itself once the reader says yes, so the
364
- * line says that and no address. Without one it cannot, and the line carries
365
- * the address instead: it is the only place a run with no terminal says it.
366
- */
367
- export function connectItem(unconnected, total, interactive, url) {
368
- const which = unconnected.length === total && total === 2
369
- ? "both repos"
370
- : unconnected.length === total && total > 2
371
- ? `all ${total} repos`
372
- : reposPhrase(unconnected);
373
- return interactive
374
- ? `Open GitHub to install Carrick on ${which}`
375
- : `Install the Carrick GitHub App on ${which}: ${url}`;
376
- }
377
- /**
378
- * The moves out of other projects, one line per project they come from, in
379
- * the spelling the move question uses too.
380
- */
381
- export function moveLines(moving, project) {
382
- return [...new Set(moving.map((entry) => entry.from))].map((from) => {
383
- const repos = moving.filter((entry) => entry.from === from).map((entry) => entry.repo);
384
- return `Move ${reposPhrase(repos)} from ${from} into ${project}`;
385
- });
386
- }
387
- /**
388
- * Everything the run will do, one line each, for the one question that covers
389
- * it (carrick#1512).
390
- *
391
- * A project used to be created at its own question, before the reader had seen
392
- * which repos went into it, and the GitHub App line was printed twice around
393
- * the files question. Now the project, the App and the files are three lines
394
- * under "Next:", and "Go ahead?" is asked once, about all of them. A move out
395
- * of another project is a line here too, and still its own question after this
396
- * one, because `--yes` never grants it (carrick#1338).
397
- */
398
- export function nextLines(input) {
399
- const lines = [];
400
- if (input.project !== null && input.create) {
401
- lines.push(`Create project ${input.project} with ${reposPhrase(input.repos)}`);
402
- }
403
- else if (input.project !== null && input.joining.length > 0) {
404
- lines.push(`Add ${reposPhrase(input.joining)} to project ${input.project}`);
405
- }
406
- if (input.project !== null) {
407
- for (const line of moveLines(input.moving, input.project))
408
- lines.push(line);
409
- }
410
- if (input.connect !== null)
411
- lines.push(input.connect);
412
- lines.push(input.writes);
413
- return lines;
414
- }
415
- /**
416
- * The line a run inside one repo prints about the others beside it, where it
417
- * does not ask about them: too many to list, or no terminal to ask in.
300
+ * The line a run inside one repo prints about the others beside it: it sets
301
+ * up this repo, and the folder run is the one that covers them.
418
302
  */
419
303
  export function thisRepoOnly(repo) {
420
304
  return `Setting up ${repo} only. To set up several repos as one system, run carrick init in the folder that holds them.`;
421
305
  }
422
- /**
423
- * Which of the repos beside this one belong to the same system, asked in the
424
- * run itself (carrick#1512).
425
- *
426
- * The run used to name the folder above and tell the reader to start again
427
- * there. This repo starts ticked and the others do not: a sibling folder is
428
- * not a claim that the repos in it call each other. Each row names the GitHub
429
- * repo its remote points at, which is what the reader recognises when two
430
- * folders are called something else.
431
- */
432
- export async function chooseSiblings(current, siblings, directory, out) {
433
- const rows = [current, ...siblings].map((repo) => ({
434
- value: repo.path,
435
- label: repo === current ? `${path.basename(repo.path)} (this repo)` : path.basename(repo.path),
436
- hint: repo.name ?? "no GitHub remote",
437
- }));
438
- return out.choose(`${tilde(directory)} holds other repos. Which belong to the same system as ${path.basename(current.path)}?`, "a repo", rows, { initial: [current.path], required: true });
439
- }
440
306
  /**
441
307
  * An end to the run with its own exit code, decided before anything is written.
442
308
  *
443
- * A refusal ("no terminal and no --yes") and a declined proposal are the same
444
- * shape — stop here, leave everything alone — and they happen at four points
445
- * in the decision. Thrown, they all end in one place, beside the cancel, which
446
- * is the only way to be sure no path between them reaches a write.
309
+ * Thrown, every stop ends in one place, beside the cancel, which is the only
310
+ * way to be sure no path between them reaches a write.
447
311
  */
448
312
  class Stop extends Error {
449
313
  code;
@@ -453,113 +317,20 @@ class Stop extends Error {
453
317
  this.code = code;
454
318
  }
455
319
  }
456
- /** The line a run that was stopped at a question ends on (carrick#1338). */
320
+ /** The line a run that was stopped at the sign-in ends on (carrick#1338). */
457
321
  export const CANCELLED = "Cancelled. Nothing was written, here or in Carrick.";
458
322
  /**
459
- * The line a declined proposal ends on.
460
- *
461
- * A "no" used to be silent, which beside a cancel that says so reads as two
462
- * different things having happened. Both leave the machine and the server as
463
- * they were, and both say it.
464
- */
465
- export const NOTHING_WRITTEN = "Nothing written, here or in Carrick.";
466
- /**
467
- * The repos that start selected, and why each of the others does not.
468
- *
469
- * A default is a claim about somebody's folder, so only the repos something
470
- * already says belong here carry one: connected to this workspace, and in the
471
- * project most of this folder's connected repos are in. Everything else — a
472
- * repo nobody connected, one sitting in a different project, one with no
473
- * GitHub identity to ask about — starts out, with the reason on its row, and
474
- * the reader adds it in one keystroke (carrick#1365).
475
- *
476
- * Two cases preselect nothing at all, and neither is in the ruling because
477
- * neither is a majority: a folder where nothing is connected (a first run), and
478
- * a tie between two projects. A guess there is a guess about which half of
479
- * somebody's folder this install is for.
480
- *
481
- * Unconnected is not the same as unknown: with no read of the workspace — no
482
- * login yet, or a read that did not answer — `identity` is null and nothing is
483
- * preselected, because "not connected" would then be this command's assumption
484
- * rather than the server's answer.
485
- */
486
- export function preselectedRepos(candidates, identity, label = (slug) => slug) {
487
- const reasons = new Map();
488
- const project = new Map();
489
- for (const repo of candidates) {
490
- if (repo.name === null) {
491
- reasons.set(repo.path, "no GitHub identity");
492
- continue;
493
- }
494
- if (identity === null)
495
- continue;
496
- const row = identity.repos.find((entry) => entry.full_name.toLowerCase() === repo.name?.toLowerCase());
497
- if (row === undefined || !row.connected) {
498
- reasons.set(repo.path, "not connected");
499
- continue;
500
- }
501
- project.set(repo.path, row.project_slug);
502
- }
503
- const counts = new Map();
504
- for (const slug of project.values()) {
505
- if (slug !== null)
506
- counts.set(slug, (counts.get(slug) ?? 0) + 1);
507
- }
508
- const ranked = [...counts.entries()].sort((left, right) => right[1] - left[1]);
509
- const majority = ranked.length > 0 && (ranked.length === 1 || ranked[0][1] > ranked[1][1]) ? ranked[0][0] : null;
510
- const keep = [];
511
- for (const [repoPath, slug] of project) {
512
- if (majority !== null && slug === majority)
513
- keep.push(repoPath);
514
- else if (slug === null)
515
- reasons.set(repoPath, "connected, in no project");
516
- else
517
- reasons.set(repoPath, `in ${label(slug)}`);
518
- }
519
- return { keep, reasons };
520
- }
521
- /** A repo as the picker lists it: what it is called, what is in it, and why it is out. */
522
- export function repoChoices(plan, candidates, reasons = new Map()) {
523
- return candidates.map((repo) => {
524
- const found = plan.repos.find((entry) => entry.path === repo.path);
525
- const packages = found?.services.length ?? 0;
526
- const reason = reasons.get(repo.path);
527
- const hint = [
528
- `${packages} package${packages === 1 ? "" : "s"}`,
529
- ...(reason === undefined ? [] : [reason]),
530
- ].join(", ");
531
- return { value: repo.path, label: repo.name ?? path.basename(repo.path), hint };
532
- });
533
- }
534
- /**
535
- * Which repos in this folder this install covers, settled before anything is
536
- * read from Carrick and long before anything is written (carrick#1338).
537
- *
538
- * A folder routinely holds a repo that must not be scanned, and the only
539
- * answer this command used to take was one yes covering every repo in it. The
540
- * terminal picks; without one, `--repo` names them; with neither, there is no
541
- * safe default and the run stops here, having written nothing.
323
+ * The repos `--repo` names, out of the repos this folder holds (carrick#1338,
324
+ * carrick#991).
542
325
  */
543
- export async function chooseRepos(plan, candidates, options, out) {
544
- if (options.repos.length > 0) {
545
- const chosen = selectRepos(candidates, options.repos);
546
- if ("problem" in chosen)
547
- throw new Error(chosen.problem);
548
- if (chosen.taken !== null) {
549
- out.done(`${chosen.taken.name} taken as the GitHub repository for ${chosen.taken.path}`);
550
- }
551
- return chosen.repos;
326
+ function namedRepos(candidates, repos, out) {
327
+ const chosen = selectRepos(candidates, repos);
328
+ if ("problem" in chosen)
329
+ throw new Error(chosen.problem);
330
+ if (chosen.taken !== null) {
331
+ out.done(`${chosen.taken.name} taken as the GitHub repository for ${chosen.taken.path}`);
552
332
  }
553
- // One repo is not a choice, and `--yes` is a reader stating that the list as
554
- // derived is the list they want.
555
- if (candidates.length === 1 || options.assumeYes)
556
- return candidates;
557
- if (!options.interactive) {
558
- throw new Error(`${plan.workspace} holds ${candidates.length} repos and there is no terminal to choose in. Name the ones this install covers with --repo owner/repo (repeatable), or add --yes to cover all ${candidates.length}.`);
559
- }
560
- const { keep, reasons } = preselectedRepos(candidates, options.identity ?? null, options.label);
561
- const kept = new Set(await out.choose("Which repos should Carrick index?", "a repo", repoChoices(plan, candidates, reasons), { initial: keep, required: true }));
562
- return candidates.filter((repo) => kept.has(repo.path));
333
+ return chosen.repos;
563
334
  }
564
335
  /**
565
336
  * The excluded repos a `--repo` flag is asking for, by identity.
@@ -589,54 +360,35 @@ export function namedButExcluded(workspace, excluded, requested, identify = repo
589
360
  });
590
361
  }
591
362
  /**
592
- * Which editors outside the workspace get an MCP entry written for them.
593
- *
594
- * The answer is a set of names, and the default is the empty one: these are
595
- * files in somebody's home directory for editors they may not use, so the
596
- * strongest thing a configuration directory can do is put a row in the
597
- * question (carrick#1365). An editor whose own command answers on PATH starts
598
- * ticked; without a terminal, `--mcp` names them and nothing else is written.
599
- *
600
- * `--yes` does not cover these. It takes the proposal as printed — a list of
601
- * packages and a set of files inside this workspace — and an entry in
602
- * `~/.cursor/mcp.json` is neither.
363
+ * The editors outside the workspace that get an MCP entry: the ones `--mcp`
364
+ * names, or else every one whose own command answers on this machine. A file
365
+ * for an editor this machine does not run is never written unasked
366
+ * (carrick#1365).
603
367
  */
604
- export async function chooseEditors(offered, options, out) {
368
+ export function chooseEditors(offered, named) {
605
369
  if (offered.length === 0)
606
370
  return [];
607
- if (options.editors.length > 0) {
608
- const known = new Map(offered.map((client) => [client.name.toLowerCase(), client.name]));
609
- const chosen = [];
610
- for (const wanted of options.editors) {
611
- const name = known.get(wanted.toLowerCase());
612
- if (name === undefined) {
613
- throw new Error(`--mcp ${wanted} names no editor configured on this machine. The ones here are: ${offered.map((client) => client.name).join(", ")}.`);
614
- }
615
- if (!chosen.includes(name))
616
- chosen.push(name);
371
+ if (named.length === 0)
372
+ return offered.filter((client) => client.installed).map((client) => client.name);
373
+ const known = new Map(offered.map((client) => [client.name.toLowerCase(), client.name]));
374
+ const chosen = [];
375
+ for (const wanted of named) {
376
+ const name = known.get(wanted.toLowerCase());
377
+ if (name === undefined) {
378
+ throw new Error(`--mcp ${wanted} names no editor configured on this machine. The ones here are: ${offered.map((client) => client.name).join(", ")}.`);
617
379
  }
618
- return chosen;
380
+ if (!chosen.includes(name))
381
+ chosen.push(name);
619
382
  }
620
- if (!options.interactive || options.assumeYes)
621
- return [];
622
- return out.choose("Which editors should Carrick be added to? These files are outside this workspace.", "an editor", offered.map((client) => ({
623
- value: client.name,
624
- label: client.name,
625
- hint: client.installed ? client.file : `${client.file}, not detected on this machine`,
626
- })), { initial: offered.filter((client) => client.installed).map((client) => client.name), required: false });
383
+ return chosen;
627
384
  }
628
385
  /** The GitHub repos these folders name, once each. */
629
386
  function repoNames(repos) {
630
387
  return [...new Set(repos.map((repo) => repo.name).filter((name) => name !== null))];
631
388
  }
632
- /** Whether two lists name the same GitHub repos, as GitHub compares them. */
633
- function sameRepos(left, right) {
634
- const names = new Set(left.map((name) => name.toLowerCase()));
635
- return names.size === new Set(right.map((name) => name.toLowerCase())).size && right.every((name) => names.has(name.toLowerCase()));
636
- }
637
389
  /**
638
- * What a run inside one repo says about the folder above, where it does not
639
- * ask about it: the repos beside this one, or a folder that is itself a repo.
390
+ * What a run inside one repo says about the folder above: the repos beside
391
+ * this one, or a folder that is itself a repo.
640
392
  */
641
393
  function aloneLines(current, parent, siblings, out) {
642
394
  if (siblings.length > 0) {
@@ -644,19 +396,17 @@ function aloneLines(current, parent, siblings, out) {
644
396
  }
645
397
  else if (parent.repos.some((repo) => realPath(repo) === realPath(parent.directory))) {
646
398
  // Not a folder of repos but a repository this directory sits inside,
647
- // which is where a scan of it belongs: the one case where "run it in
399
+ // which is where a setup of it belongs: the one case where "run it in
648
400
  // the folder above" is still the answer.
649
401
  out.warn(`The parent folder ${parent.directory} is itself a repo. Run carrick init .. to initialise that workspace.`);
650
402
  }
651
403
  }
652
404
  /**
653
- * The repos that name no GitHub repository, said before anything is requested
654
- * for the others (carrick#991).
405
+ * The repos that name no GitHub repository (carrick#991).
655
406
  *
656
- * A repo with no identity is left out of the project step, the connection
657
- * check and the workspace read, and a run that dropped it in silence read as a
658
- * complete one. A folder of clones can hold dozens, so the list is capped and
659
- * the rest is counted rather than dropped.
407
+ * A repo with no identity cannot be in a Carrick workspace, and a run that
408
+ * dropped it in silence read as a complete one. A folder of clones can hold
409
+ * dozens, so the list is capped and the rest is counted rather than dropped.
660
410
  */
661
411
  function warnMissingIdentities(missing, out) {
662
412
  for (const repo of missing.slice(0, 10)) {
@@ -675,26 +425,22 @@ function warnMissingIdentities(missing, out) {
675
425
  /** What a run with no credential and no terminal to sign in from stops on. */
676
426
  const LOGIN_REQUIRED = "carrick init requires a Carrick login. Run carrick login, or set CARRICK_TOKEN.";
677
427
  /**
678
- * Decide a run on a workspace whose index Carrick builds, asking nothing.
428
+ * Decide the run from the workspace read, asking nothing.
679
429
  *
680
- * The laptop lane asks which repos, which project, which editors and whether
681
- * to go ahead, because each answer starts something: a project, a move, a
682
- * scan somebody pays for. Here the workspace has already answered all of
683
- * them, so the run reads the answers and prints what it adds. It writes
684
- * nothing: a stop here leaves the machine as it was, like every stop before
685
- * the yes on the other lane.
430
+ * The workspace has already answered every question a setup could ask:
431
+ * which repos, which project, which editors. So the run reads the answers and
432
+ * prints what it adds. It writes nothing: a stop here leaves the machine as it
433
+ * was.
686
434
  */
687
- async function cloudLane(input) {
435
+ async function planRun(input) {
688
436
  const { parsed, workspace, derived, candidates, identity, credential, out } = input;
689
- const urls = workspaceUrls(identity.workspace.slug);
690
- const parent = derived.plan.parent_proposal;
437
+ const repos = reposUrl(identity.workspace.slug);
438
+ const parent = derived.parent_proposal;
691
439
  if (parent !== null && candidates.length === 1) {
692
- aloneLines(candidates[0], parent, siblingRepos(derived.plan, excludedRepos(parent.directory)), out);
440
+ aloneLines(candidates[0], parent, siblingRepos(derived, excludedRepos(parent.directory)), out);
693
441
  }
694
442
  // `--repo` still narrows the run, and names nothing the reader did not.
695
- const chosen = parsed.repos.length === 0
696
- ? candidates
697
- : await chooseRepos(derived.plan, candidates, { repos: parsed.repos, assumeYes: true, interactive: false }, out);
443
+ const chosen = parsed.repos.length === 0 ? candidates : namedRepos(candidates, parsed.repos, out);
698
444
  const held = (repo) => {
699
445
  const row = identity.repos.find((entry) => entry.full_name.toLowerCase() === repo.name?.toLowerCase());
700
446
  return row?.connected === true ? row : null;
@@ -702,7 +448,7 @@ async function cloudLane(input) {
702
448
  const selected = chosen.filter((repo) => held(repo) !== null);
703
449
  warnMissingIdentities(chosen.filter((repo) => repo.name === null), out);
704
450
  if (selected.length === 0) {
705
- out.refuse(`None of the repos here is in your Carrick workspace ${identity.workspace.slug}. Add them at ${urls.repos}. If they are in another workspace, run carrick logout, then carrick init, and choose that workspace when you sign in.`);
451
+ out.refuse(`None of the repos here is in your Carrick workspace ${identity.workspace.slug}. Add them at ${repos}. If they are in another workspace, run carrick logout, then carrick init, and choose that workspace when you sign in.`);
706
452
  throw new Stop(1);
707
453
  }
708
454
  const groups = [];
@@ -718,28 +464,23 @@ async function cloudLane(input) {
718
464
  // The project is read here and changed on the dashboard, so a flag that
719
465
  // would move a repo is refused rather than half-honoured.
720
466
  if (parsed.project !== null && parsed.project !== project) {
721
- out.refuse(`On this workspace repos change system on the dashboard: ${urls.repos}. Run carrick init without --project.`);
467
+ out.refuse(`On this workspace repos change system on the dashboard: ${repos}. Run carrick init without --project.`);
722
468
  throw new Stop(1);
723
469
  }
724
470
  const absent = repoNames(chosen.filter((repo) => held(repo) === null));
725
471
  if (absent.length > 0) {
726
472
  const one = absent.length === 1;
727
- out.warn(`${listed(absent, 10)} ${one ? "is" : "are"} not in your Carrick workspace ${identity.workspace.slug}, so this run leaves ${one ? "it" : "them"} out. Add repos at ${urls.repos}, then run carrick init again.`);
473
+ out.warn(`${listed(absent, 10)} ${one ? "is" : "are"} not in your Carrick workspace ${identity.workspace.slug}, so this run leaves ${one ? "it" : "them"} out. Add repos at ${repos}, then run carrick init again.`);
728
474
  }
729
475
  const names = repoNames(selected);
730
476
  const projects = await listProjects(credential.token);
731
- for (const missing of derived.plan.missing)
477
+ for (const missing of derived.missing)
732
478
  out.warn(`${WORKSPACE_FILE} lists ${missing}, which is not a directory on this machine.`);
733
- // The editors the picker would have ticked: the ones whose own command
734
- // answers on this machine. `--mcp` still names them outright.
735
479
  const offered = offeredFileClients();
736
- const editors = parsed.editors.length > 0
737
- ? await chooseEditors(offered, { editors: parsed.editors, assumeYes: true, interactive: false }, out)
738
- : offered.filter((client) => client.installed).map((client) => client.name);
480
+ const editors = chooseEditors(offered, parsed.editors);
739
481
  const kept = new Set(selected.map((repo) => repo.path));
740
482
  const deselected = candidates.filter((repo) => !kept.has(repo.path)).map((repo) => path.basename(repo.path));
741
- // The same list the other lane asks "Go ahead?" about, with no question
742
- // under it: every file is still named before it is written.
483
+ // Every file is named before it is written.
743
484
  out.say(nextBlock([
744
485
  writesLine({
745
486
  workspaceFile: deselected.length > 0,
@@ -751,7 +492,7 @@ async function cloudLane(input) {
751
492
  return {
752
493
  credential,
753
494
  identity,
754
- derived: selectedProposal(derived, selected.map((repo) => repo.path)),
495
+ derived: keepRepos(derived, selected.map((repo) => repo.path)),
755
496
  selected,
756
497
  names,
757
498
  deselected,
@@ -760,6 +501,10 @@ async function cloudLane(input) {
760
501
  groups,
761
502
  editors,
762
503
  waiting: repoNames(selected.filter((repo) => held(repo).services.length === 0)),
504
+ counts: {
505
+ repos: selected.length,
506
+ services: selected.reduce((sum, repo) => sum + held(repo).services.length, 0),
507
+ },
763
508
  };
764
509
  }
765
510
  export async function init(argv) {
@@ -767,7 +512,8 @@ export async function init(argv) {
767
512
  }
768
513
  /**
769
514
  * `init` with the terminal stated rather than sniffed, so a test can be the
770
- * terminal: the cancel path and the picker have no other way in.
515
+ * terminal. The terminal decides only whether init can sign in from here and
516
+ * how a step draws: nothing is asked after sign-in.
771
517
  */
772
518
  export async function initWith(argv, out, interactive) {
773
519
  const parsed = parseArgs(argv);
@@ -775,16 +521,14 @@ export async function initWith(argv, out, interactive) {
775
521
  process.stdout.write(`${parsed}\n`);
776
522
  return parsed.startsWith("carrick init") ? 0 : 2;
777
523
  }
778
- // Where the run was started, and where it sets up: the folder above, once
779
- // the reader has said a repo beside this one belongs with it (carrick#1512).
524
+ // Where the run was started, and where it sets up: the folder above, when
525
+ // an earlier run there covers this repo (carrick#1512).
780
526
  const startedIn = parsed.workspace;
781
527
  let workspace = parsed.workspace;
782
528
  if (!fs.existsSync(workspace)) {
783
529
  process.stderr.write(`carrick init: ${workspace} is not a directory on this machine\n`);
784
530
  return 1;
785
531
  }
786
- // A repo the folder above has already set up is set up from that folder
787
- // again, rather than on its own beside it (carrick#1512).
788
532
  const above = initFolderAbove(workspace);
789
533
  if (above !== null) {
790
534
  out.say(`${path.basename(realPath(workspace))} is set up with the repos in ${tilde(above)}, so this run sets up ${tilde(above)}.`);
@@ -795,72 +539,13 @@ export async function initWith(argv, out, interactive) {
795
539
  const again = (flags = "") => realPath(workspace) === realPath(startedIn)
796
540
  ? `run carrick init${flags} again`
797
541
  : `run carrick init${flags} in ${tilde(workspace)} again`;
798
- // Everything this run would change is decided before any of it happens: the
799
- // repos it covers, the project they belong in, and the moves that would
800
- // take. `--project` used to move repos on the server as its first act and
801
- // print the proposal afterwards, so a reader's only chance to drop a repo
802
- // came after that repo had already been moved (carrick#1338).
803
- //
804
- // The repos the workspace read found an index for: where CI has already built
805
- // one, this run reads it rather than ordering a scan (carrick#993 row 2).
806
- const hostedIndex = [];
807
- // The project the skills are written against, once it is settled. It stays
808
- // null where no repo here names a GitHub repository, and the skills then
809
- // tell the agent to read the scope from the git remote instead.
810
- let projectSlug = null;
811
- let derived;
812
- let credential;
813
- let names;
814
- let initial;
815
- let projects;
816
- let decision;
817
- // The repos this run has permission to take out of another project.
818
- const movable = new Set();
819
- // The ones among them that sit in a project somebody chose, at the read the
820
- // proposal was built from. Their move is said; a repo the App grant has
821
- // just put in the default project is not (carrick#1489).
822
- const announced = new Set();
823
- // The directory names this run leaves out, for the workspace file below.
824
- let deselected = [];
825
- // The editors outside this workspace the answer covers, settled before it.
826
- let editors = [];
827
- // The repos this install covers, for the closing line that names what is
828
- // still to set up in them.
829
- let selectedRepos = [];
830
- let candidates;
831
- let saved;
832
- // The workspace read made before the first question, and the names it was
833
- // made with (carrick#2219). It is what says who builds this workspace's
834
- // index, and the questions below reuse it rather than asking again. Null
835
- // for `--local` and where no repo here names a GitHub repository; its
836
- // `identity` is null where the read did not answer, which leaves the lane
837
- // unknown and the run on the laptop lane.
838
- let early = null;
839
- // Set where that read says Carrick builds the index.
840
- let cloud = null;
841
- // Puts the workspace file back as it was found, for a cloud-lane run that
842
- // stops before it writes anything.
542
+ let plan;
543
+ // Puts the workspace file back as it was found, for a run that stops before
544
+ // it writes anything.
843
545
  let restoreSelection = null;
844
- // Where a decision that does not end in a yes ends, on either lane.
845
- const ended = (error) => {
846
- restoreSelection?.();
847
- // A question the reader ended stops the run where it stands. Nothing above
848
- // this line writes, so there is nothing to undo (carrick#1338).
849
- if (error instanceof PromptCancelled) {
850
- out.refuse(CANCELLED);
851
- return 1;
852
- }
853
- if (error instanceof Stop) {
854
- if (error.message !== "")
855
- process.stderr.write(`carrick init: ${error.message}\n`);
856
- return error.code;
857
- }
858
- process.stderr.write(`carrick init: ${error.message}\n`);
859
- return 1;
860
- };
861
546
  try {
862
547
  // What a previous run wrote down, before anything is derived from it: the
863
- // scanner has already dropped an excluded repo by the time the proposal
548
+ // scanner has already dropped an excluded repo by the time the derivation
864
549
  // arrives, so this is the only place that can tell a reader why the repo
865
550
  // they just named is not here (carrick#1344).
866
551
  const excluded = excludedRepos(workspace);
@@ -868,16 +553,13 @@ export async function initWith(argv, out, interactive) {
868
553
  if (asked.length > 0) {
869
554
  throw new Error(`${WORKSPACE_FILE} leaves ${asked.join(" and ")} out of this workspace, so --repo cannot cover ${asked.length === 1 ? "it" : "them"}. Take ${asked.length === 1 ? "that name" : "those names"} out of the exclude list there and run carrick init again.`);
870
555
  }
871
- // Said once the lane is known, because on a workspace whose index Carrick
872
- // builds the names an earlier run recorded are looked at again below. The
873
- // derivation prints nothing, so on every other run the line is where it
874
- // always was.
875
556
  const leftOut = (names) => {
876
557
  if (names.length === 0)
877
558
  return;
878
559
  out.say(`${WORKSPACE_FILE} leaves ${names.join(", ")} out of this workspace, so nothing below covers ${names.length === 1 ? "it" : "them"}.`);
879
560
  };
880
- // The derivation and the identities are local reads: they name the choice.
561
+ // The derivation and the identities are local reads.
562
+ let derived;
881
563
  try {
882
564
  derived = deriveWorkspace(workspace);
883
565
  }
@@ -885,401 +567,97 @@ export async function initWith(argv, out, interactive) {
885
567
  leftOut(excluded);
886
568
  throw error;
887
569
  }
888
- candidates = derived.plan.repos.map((repo) => repoIdentity(repo.path));
889
- // One read before the first question (carrick#2219): who builds this
890
- // workspace's index decides whether there are questions at all, and only
891
- // Carrick can say. So a machine nobody has signed in on signs in here, and
892
- // a run cancelled at a question after this has minted a key. `--local` is
893
- // the run that does none of it. The read names the repos of this folder,
894
- // or the `--repo` values alone: a repo the reader left out is named in no
895
- // request (carrick#1338).
896
- saved = readCredential();
570
+ let candidates = derived.repos.map((repo) => repoIdentity(repo.path));
571
+ // The read names the repos of this folder, or the `--repo` values alone: a
572
+ // repo the reader left out is named in no request (carrick#1338).
897
573
  const here = parsed.repos.length > 0 ? parsed.repos : repoNames(candidates);
898
- if (!parsed.local && here.length > 0) {
899
- if (saved === null) {
900
- if (!interactive) {
901
- leftOut(excluded);
902
- throw new Error(LOGIN_REQUIRED);
903
- }
904
- saved = await signIn(out.say);
905
- }
906
- early = { names: here, identity: null };
907
- try {
908
- early.identity = await resolveRepos(saved.token, here);
909
- }
910
- catch {
911
- // The read the proposal is built from reports the failure in its own
912
- // words, below.
913
- }
574
+ // Nothing here can be in a Carrick workspace, so there is nothing to sign
575
+ // in for and nothing to set up.
576
+ if (here.length === 0) {
577
+ leftOut(excluded);
578
+ warnMissingIdentities(candidates.filter((repo) => repo.name === null), out);
579
+ throw new Stop(1);
914
580
  }
915
- if (saved !== null && early?.identity?.workspace.index_builder === "cloud") {
916
- let identity = early.identity;
917
- // A repo that has joined the workspace since the last run. The names
918
- // init recorded in the workspace file are a result on this lane, not a
919
- // choice, so they are taken back out and the folder is read whole again.
920
- // A name somebody wrote into `exclude` by hand stays, and is named in no
921
- // request. `--repo` is a choice, and leaves the record alone.
922
- if (parsed.repos.length === 0) {
923
- const before = readWorkspaceFile(workspace);
924
- if (before !== null && removeSelection(workspace) !== null) {
925
- restoreSelection = () => fs.writeFileSync(path.join(workspace, WORKSPACE_FILE), before);
926
- derived = deriveWorkspace(workspace);
927
- candidates = derived.plan.repos.map((repo) => repoIdentity(repo.path));
928
- identity = await resolveRepos(saved.token, repoNames(candidates));
929
- }
581
+ let saved = readCredential();
582
+ if (saved === null) {
583
+ if (!interactive) {
584
+ leftOut(excluded);
585
+ throw new Error(LOGIN_REQUIRED);
930
586
  }
931
- leftOut(excludedRepos(workspace));
932
- cloud = await cloudLane({ parsed, workspace, derived, candidates, identity, credential: saved, out });
587
+ saved = await signIn(out.say);
933
588
  }
934
- else {
935
- leftOut(excluded);
589
+ // One read decides the run: which of these repos the workspace holds, in
590
+ // which project, with which index. A read that fails is said in its own
591
+ // words, and nothing is written.
592
+ let identity = await resolveRepos(saved.token, here);
593
+ // A repo that has joined the workspace since the last run. The names init
594
+ // recorded in the workspace file are a result, not a choice, so they are
595
+ // taken back out and the folder is read whole again. A name somebody wrote
596
+ // into `exclude` by hand stays, and is named in no request. `--repo` is a
597
+ // choice, and leaves the record alone.
598
+ if (parsed.repos.length === 0) {
599
+ const before = readWorkspaceFile(workspace);
600
+ if (before !== null && removeSelection(workspace) !== null) {
601
+ restoreSelection = () => fs.writeFileSync(path.join(workspace, WORKSPACE_FILE), before);
602
+ derived = deriveWorkspace(workspace);
603
+ candidates = derived.repos.map((repo) => repoIdentity(repo.path));
604
+ identity = await resolveRepos(saved.token, repoNames(candidates));
605
+ }
936
606
  }
607
+ leftOut(excludedRepos(workspace));
608
+ plan = await planRun({ parsed, workspace, derived, candidates, identity, credential: saved, out });
937
609
  }
938
610
  catch (error) {
939
- return ended(error);
940
- }
941
- if (cloud !== null) {
942
- // Read, not chosen: nothing is created, assigned or moved on this lane.
943
- derived = cloud.derived;
944
- credential = cloud.credential;
945
- names = cloud.names;
946
- projects = cloud.projects;
947
- decision = { slug: cloud.project, exists: true, create: false };
948
- projectSlug = cloud.project;
949
- deselected = cloud.deselected;
950
- editors = cloud.editors;
951
- selectedRepos = cloud.selected;
952
- }
953
- else
954
- try {
955
- // The repos beside this one, asked about here rather than named with an
956
- // instruction to start again in the folder above (carrick#1512). A yes to
957
- // any of them carries on as if the run had started there: the same
958
- // derivation, the same proposal, and the repos left unticked written to
959
- // the same exclude list a folder run writes.
960
- let ticked = null;
961
- const parent = derived.plan.parent_proposal;
962
- if (parent !== null && candidates.length === 1) {
963
- const current = candidates[0];
964
- const siblings = siblingRepos(derived.plan, excludedRepos(parent.directory));
965
- const asking = siblings.length > 0 &&
966
- siblings.length <= MAX_SIBLINGS &&
967
- interactive &&
968
- !parsed.assumeYes &&
969
- parsed.repos.length === 0;
970
- if (asking) {
971
- const picked = new Set((await chooseSiblings(current, siblings.map((repo) => repoIdentity(repo)), parent.directory, out)).map(realPath));
972
- if (picked.size > 1 || !picked.has(realPath(current.path))) {
973
- workspace = parent.directory;
974
- derived = deriveWorkspace(workspace);
975
- candidates = derived.plan.repos.map((repo) => repoIdentity(repo.path));
976
- const chosen = candidates.filter((repo) => picked.has(realPath(repo.path)));
977
- // This repo first, where the reader kept it: it is the one they
978
- // started in, and every sentence below names it first.
979
- ticked = [
980
- ...chosen.filter((repo) => realPath(repo.path) === realPath(current.path)),
981
- ...chosen.filter((repo) => realPath(repo.path) !== realPath(current.path)),
982
- ];
983
- }
984
- }
985
- else {
986
- aloneLines(current, parent, siblings, out);
987
- }
988
- }
989
- // What Carrick already knows about this folder, before the picker draws
990
- // its defaults. A read, not a write: the credential has to exist already,
991
- // so with `--local` a machine nobody has signed in on still chooses first
992
- // and signs in afterwards, which is what keeps "nothing written, here or
993
- // in Carrick" true of a cancelled run (carrick#1338). A read that does not
994
- // answer preselects nothing rather than guessing, and the authoritative
995
- // read below then reports the failure in its own words.
996
- let known = null;
997
- projects = null;
998
- const knownNames = repoNames(candidates);
999
- // Only where a picker is actually going to draw. Every other path has its
1000
- // answer already — `--repo` names it, `--yes` takes the list as derived, a
1001
- // single repo is not a choice, the question about the repos beside this
1002
- // one was the choice — and asking about a repo whose name the reader never
1003
- // offered is a request that buys nothing (carrick#1338's test pins it: a
1004
- // repo left out is named in no request at all).
1005
- const picking = ticked === null && parsed.repos.length === 0 && !parsed.assumeYes && interactive && candidates.length > 1;
1006
- if (picking && saved !== null && knownNames.length > 0) {
1007
- try {
1008
- // The read made before the first question named these same repos.
1009
- known = early === null ? await resolveRepos(saved.token, knownNames) : early.identity;
1010
- projects = known === null ? null : await listProjects(saved.token);
1011
- }
1012
- catch {
1013
- known = null;
1014
- projects = null;
1015
- }
1016
- }
1017
- const selected = ticked ??
1018
- (await chooseRepos(derived.plan, candidates, {
1019
- repos: parsed.repos,
1020
- assumeYes: parsed.assumeYes,
1021
- interactive,
1022
- identity: known,
1023
- label: (slug) => projectLabel(slug, projects),
1024
- }, out));
1025
- if (selected.length === 0)
1026
- throw new Stop(0);
1027
- selectedRepos = selected;
1028
- derived = selectedProposal(derived, selected.map((repo) => repo.path));
1029
- const kept = new Set(selected.map((repo) => repo.path));
1030
- deselected = candidates
1031
- .filter((repo) => !kept.has(repo.path))
1032
- .map((repo) => path.basename(repo.path));
1033
- const dropped = candidates.length - selected.length;
1034
- // Not after the question about the repos beside this one: its rows were
1035
- // the whole answer, and a folder repo that had no row there (one with no
1036
- // JavaScript or TypeScript in it) is not news.
1037
- if (dropped > 0 && ticked === null) {
1038
- out.done(`${selected.length} of ${candidates.length} repos covered; ${dropped} left out of the proposal, the project and the connection`);
1039
- }
1040
- // A machine that has never signed in signs in here rather than being told
1041
- // to run another command: `carrick login` is the same browser round trip,
1042
- // and refusing to take it was the first thing a new install did
1043
- // (carrick#955). Without a terminal there is no browser to hand it to.
1044
- if (saved)
1045
- credential = saved;
1046
- else {
1047
- if (!interactive) {
1048
- throw new Error(LOGIN_REQUIRED);
1049
- }
1050
- credential = await signIn(out.say);
1051
- }
1052
- names = repoNames(selected);
1053
- if (names.length > 200)
1054
- throw new Error("This workspace has more than 200 GitHub repos. Initialise smaller workspace groups.");
1055
- const missingIdentities = selected.filter((repo) => repo.name === null);
1056
- // Said before anything is requested, and said whether or not --project was
1057
- // given.
1058
- warnMissingIdentities(missingIdentities, out);
1059
- if (parsed.project && missingIdentities.length > 0) {
1060
- throw new Error(`--project ${parsed.project} cannot verify ${missingIdentities.map((repo) => repo.path).join(", ")} because ${missingIdentities.length === 1 ? "it has" : "they have"} no GitHub origin. No project assignment was verified.`);
1061
- }
1062
- if (parsed.project && names.length === 0) {
1063
- throw new Error(`--project ${parsed.project} found no GitHub repos to verify.`);
1064
- }
1065
- if (names.length === 0) {
1066
- // The sentence that stops the rest of this run from reading as a
1067
- // complete one: no project is chosen, no connection is checked, and a
1068
- // later upload has no repo identity to resolve a project from.
1069
- out.warn("No repo here names a GitHub repository, so this run chooses no project and checks no connection.");
1070
- }
1071
- // The read the rest of this run is decided from. The one made before the
1072
- // first question, or the one the picker's defaults came from, is reused
1073
- // only where it named exactly the repos this run covers, because
1074
- // `project_repos` answers for the repos that were ASKED about: a wider
1075
- // read would have the absent-repo lines below naming projects this install
1076
- // does not cover (carrick#993 row 18).
1077
- const read = early ?? { names: knownNames, identity: known };
1078
- initial =
1079
- read.identity !== null && sameRepos(read.names, names) ? read.identity : await resolveRepos(credential.token, names);
1080
- // Read once, for the names: every project this run prints is printed as
1081
- // the dashboard shows it, with the slug beside it (carrick#1338). A
1082
- // workspace whose API has no such action answers null and the lines carry
1083
- // slugs alone, as they did.
1084
- if (projects === null)
1085
- projects = names.length > 0 ? await listProjects(credential.token) : null;
1086
- // The project half of the browser round trip, where this API can do it
1087
- // from here. Nothing is created or moved in it: it settles what this run
1088
- // would do, and the proposal below is where that is accepted. Without
1089
- // --project the step reads the assignment the repos already have and
1090
- // offers the list, rather than doing nothing at all (carrick#987).
1091
- const dashboard = workspaceUrls(initial.workspace.slug).projects;
1092
- // The repos by the folder names the reader has on disk, in the order the
1093
- // questions name them. Only those with a GitHub remote: a repo with none
1094
- // goes into no project, so no project line names it.
1095
- const named = selected.filter((repo) => repo.name !== null).map((repo) => path.basename(repo.path));
1096
- const shortName = (fullName) => {
1097
- const repo = selected.find((entry) => entry.name?.toLowerCase() === fullName.toLowerCase());
1098
- return repo === undefined ? fullName : path.basename(repo.path);
1099
- };
1100
- const prompts = {
1101
- repos: named,
1102
- say: out.say,
1103
- ask: out.ask,
1104
- confirm: out.confirm,
1105
- pick: out.pick,
1106
- dashboard: { url: dashboard, open: (url) => void openBrowser(url).catch(() => false) },
1107
- interactive,
1108
- assumeYes: parsed.assumeYes,
1109
- };
1110
- decision =
1111
- parsed.project === null
1112
- ? await projectStep(projectAssignments(initial, names), projects, prompts)
1113
- : reposAreInProject(initial, names, parsed.project)
1114
- ? { slug: parsed.project, exists: true, create: false }
1115
- : await planProject(parsed.project, projects, prompts);
1116
- const project = decision.slug;
1117
- projectSlug = project;
1118
- const label = (slug) => projectLabel(slug, projects);
1119
- // What the server would be asked to change, before it is asked: the repos
1120
- // that would leave a project somebody put them in, and the ones the grant
1121
- // has yet to connect at all.
1122
- const current = projectAssignments(initial, names);
1123
- const assigned = new Map(names.map((name, index) => [name, current[index] ?? null]));
1124
- const moving = project === null ? [] : names.filter((name) => {
1125
- const current = assigned.get(name);
1126
- return current !== null && current !== undefined && current !== project;
1127
- });
1128
- const joining = project === null ? [] : names.filter((name) => assigned.get(name) == null);
1129
- // The proposal: what this run covers, what it would change, and what the
1130
- // scanner said about it. Everything above is a read; everything below the
1131
- // confirm is a write.
1132
- const plan = derived.plan;
1133
- // The scanner's own warnings about what it proposed. Capped: the proposal
1134
- // file carries every one of them, and it is named on the line above.
1135
- const warnings = plan.repos.flatMap((repo) => repo.warnings);
1136
- for (const warning of warnings.slice(0, 3))
1137
- out.warn(warning);
1138
- if (warnings.length > 3)
1139
- out.warn(`${warnings.length - 3} more notes on the proposal are in ${PROPOSAL_FILE}.`);
1140
- // What the scanner's `missing` holds, in the reader's terms: a path the
1141
- // workspace file lists that is not here (carrick#1574).
1142
- for (const missing of plan.missing)
1143
- out.warn(`${WORKSPACE_FILE} lists ${missing}, which is not a directory on this machine.`);
1144
- // Which editors get an entry, asked before the yes that covers it. The
1145
- // files are outside the workspace and belong to editors this reader may not
1146
- // use, and they used to be written on the strength of a yes to the proposal
1147
- // (carrick#1365). An editor with no configuration directory is not offered,
1148
- // and one this machine has no command for is offered unticked.
1149
- const offered = offeredFileClients();
1150
- editors = await chooseEditors(offered, { editors: parsed.editors, assumeYes: parsed.assumeYes, interactive }, out);
1151
- // What the yes is given to: every thing this run will do, one line each —
1152
- // the project, the GitHub App, the files — and nothing created before it
1153
- // (carrick#1512). The files are named, editor files included, because a
1154
- // question that does not name a file is not consent to write it
1155
- // (carrick#1365, carrick#1489).
1156
- const unconnected = unconnectedRepos(initial, names);
1157
- // The project as the list and the move question both spell it: the name
1158
- // typed for one this run creates, the dashboard's label for one that is
1159
- // there.
1160
- const target = project === null ? null : decision.create ? (decision.name ?? project) : label(project);
1161
- const moves = moving.map((name) => ({ repo: shortName(name), from: label(assigned.get(name) ?? "") }));
1162
- const next = nextLines({
1163
- create: decision.create,
1164
- project: target,
1165
- repos: named,
1166
- joining: joining.map(shortName),
1167
- moving: moves,
1168
- connect: unconnected.length === 0
1169
- ? null
1170
- : connectItem(unconnected.map(shortName), names.length, interactive, workspaceUrls(initial.workspace.slug).connect),
1171
- writes: writesLine({
1172
- workspaceFile: deselected.length > 0,
1173
- editorFiles: offered.filter((client) => editors.includes(client.name)).map((client) => client.file),
1174
- claudeCode: claudeCodeFound(),
1175
- // A folder of repos: the copy in each repo is written as well.
1176
- folder: selected.some((repo) => realPath(repo.path) !== realPath(workspace)) ? tilde(realPath(workspace)) : null,
1177
- }),
1178
- });
1179
- out.say(nextBlock(next));
1180
- if (!parsed.assumeYes) {
1181
- if (!interactive) {
1182
- throw new Stop(1, `use --yes to accept this proposal without a terminal${moving.length > 0 && !parsed.allowMove ? ", and --allow-move to accept the move above" : ""}.`);
1183
- }
1184
- if (!(await out.confirm("Go ahead?"))) {
1185
- out.refuse(NOTHING_WRITTEN);
1186
- throw new Stop(0);
1187
- }
1188
- }
1189
- // A move is its own question. `--yes` accepts a list of packages and a set
1190
- // of local files; taking a repo out of a project changes what every agent
1191
- // querying that project can see, and that is not the same answer
1192
- // (carrick#1338).
1193
- if (moving.length > 0 && target !== null && !parsed.allowMove) {
1194
- const from = [...new Set(moves.map((entry) => entry.from))].join(" and ");
1195
- const repos = reposPhrase(moves.map((entry) => entry.repo));
1196
- if (!interactive) {
1197
- throw new Stop(1, `${repos} ${moving.length === 1 ? "is" : "are"} in project ${from}. Moving ${moving.length === 1 ? "it" : "them"} into ${target} changes what every agent querying either project can see, so it needs --allow-move.`);
1198
- }
1199
- // The same repo and project spelling as the line in the list above it.
1200
- if (!(await out.confirm(`${moveLines(moves, target).join("; ")}?`))) {
1201
- out.refuse(NOTHING_WRITTEN);
1202
- throw new Stop(0);
1203
- }
1204
- }
1205
- for (const name of [...moving, ...joining])
1206
- movable.add(name.toLowerCase());
1207
- for (const name of moving)
1208
- announced.add(name.toLowerCase());
611
+ restoreSelection?.();
612
+ if (error instanceof PromptCancelled) {
613
+ out.refuse(CANCELLED);
614
+ return 1;
1209
615
  }
1210
- catch (error) {
1211
- return ended(error);
616
+ if (error instanceof Stop) {
617
+ if (error.message !== "")
618
+ process.stderr.write(`carrick init: ${error.message}\n`);
619
+ return error.code;
1212
620
  }
1213
- // Accepted. From here the run writes: the project, the assignment, the
1214
- // proposal, the hooks, the skills and the MCP entries.
1215
- const plan = derived.plan;
1216
- const project = decision.slug;
621
+ process.stderr.write(`carrick init: ${error.message}\n`);
622
+ return 1;
623
+ }
624
+ // From here the run writes: the selection, the hooks, the skills and the
625
+ // MCP entries.
626
+ const { derived, credential, names, projects, project, deselected, editors, selected } = plan;
1217
627
  const label = (slug) => projectLabel(slug, projects);
1218
628
  // What the reader still has to do, said once at the end rather than between
1219
629
  // the steps (carrick#1489).
1220
630
  const todo = [];
1221
- let projectExists = decision.exists;
1222
- try {
1223
- if (decision.create && project !== null) {
1224
- const outcome = await createProject(credential.token, project, decision.name ?? project);
1225
- if (outcome.kind === "created") {
1226
- // Known by its name from here on, the same as a listed one. Not said
1227
- // on a line of its own: the list the reader said yes to named it,
1228
- // and the line after the connection names it with its repos
1229
- // (carrick#1512). A create the server refused is still said.
1230
- projects = [...(projects ?? []), outcome.project];
1231
- projectExists = true;
1232
- }
1233
- else if (outcome.kind === "refused") {
1234
- out.warn(`Carrick did not create ${label(project)}: ${outcome.message}`);
1235
- }
1236
- }
1237
- }
1238
- catch (error) {
1239
- process.stderr.write(`carrick init: ${error.message}\n`);
1240
- return 1;
1241
- }
631
+ // Whether the closing block carries the Codex trust step: only when this run
632
+ // wrote the Codex hooks for the first time (carrick#3286).
633
+ let codexTrust = false;
1242
634
  try {
1243
- // The proposal is a seed for an agent, not a config: nothing derived
1244
- // without a model is written into the repository, because the first scan
1245
- // is the paid one and it has to run against a config someone has read
1246
- // (carrick-cloud#799).
1247
- // Both files were named in the question that asked to write them, so
1248
- // neither gets a line of its own (carrick#1489).
1249
- writeProposal(plan.workspace, derived);
1250
- // And the selection itself, in the file every later command reads. Without
1251
- // it the choice lasted one run: `carrick refresh` and `carrick index` walk
1252
- // the folder, the editor hook answers for a file inside a repo nobody
1253
- // covers, and the next `init` asks again (carrick#1344).
1254
- writeSelection(plan.workspace, deselected);
635
+ ensureIndexDir(derived.workspace);
636
+ // The selection, in the file every later command reads. Without it the
637
+ // choice lasted one run: `carrick refresh` walks the folder, the editor
638
+ // hook answers for a file inside a repo nobody covers, and the next `init`
639
+ // reads it again (carrick#1344).
640
+ writeSelection(derived.workspace, deselected);
1255
641
  }
1256
642
  catch (error) {
1257
643
  process.stderr.write(`carrick init: ${error.message}\n`);
1258
644
  return 1;
1259
645
  }
1260
- // The agent hooks, merged by command: this file may already hold a user's
1261
- // own hooks, or the hook pack the hosted index installs. And the MCP
1262
- // connection, for work that crosses repos this machine does not hold,
1263
- // configured for every client this machine has rather than printed for one
1264
- // of them (carrick#955).
1265
646
  // Before the hook commands are decided, because what they say depends on the
1266
647
  // answer: with a global, they are the bare `carrick`, which every shell and
1267
648
  // every agent on this machine resolves; without one, they name this install,
1268
649
  // and an npx cache is cleared (carrick#1372). A machine that already has one
1269
- // was brought level before this command started.
650
+ // was brought level before this command started. Nothing is asked: the line
651
+ // names the command, and `--install-global` runs it.
1270
652
  try {
1271
653
  await offerGlobalInstall({
1272
- // Nothing is asked where Carrick builds the index, so that run gets the
1273
- // line `--yes` gets: the command, and no install.
1274
- assumeYes: parsed.assumeYes || cloud !== null,
654
+ assumeYes: true,
1275
655
  install: parsed.installGlobal,
1276
656
  confirm: (question) => out.confirm(question),
1277
657
  say: (line) => out.warn(line),
1278
658
  });
1279
659
  }
1280
660
  catch (error) {
1281
- // Including a cancelled prompt: somebody answering Ctrl-C to an offer is
1282
- // answering the offer, not ending the setup.
1283
661
  if (!(error instanceof PromptCancelled)) {
1284
662
  out.warn(`The global install was not offered: ${error.message}`);
1285
663
  }
@@ -1308,9 +686,9 @@ export async function initWith(argv, out, interactive) {
1308
686
  // (carrick#1335): which agent opens this workspace is not a thing init can
1309
687
  // know, and a hook file for a host nobody runs costs nothing.
1310
688
  try {
1311
- if (writeCodexHooks(workspace, command.command) === "written") {
1312
- todo.push("Open `codex` in this folder once and choose to trust the project's hooks. Only the terminal app asks; until you do, Codex skips them without saying so.");
1313
- }
689
+ // Said once, last, in the closing block.
690
+ if (writeCodexHooks(workspace, command.command) === "written")
691
+ codexTrust = true;
1314
692
  }
1315
693
  catch (error) {
1316
694
  out.refuse(`Could not configure the Codex hooks: ${error.message}. Fix ${CODEX_HOOKS_FILE} and ${again()}.`);
@@ -1320,10 +698,11 @@ export async function initWith(argv, out, interactive) {
1320
698
  // an agent reads. A file this package did not write, or one somebody has
1321
699
  // since changed, is left alone and named.
1322
700
  try {
1323
- todo.push(...taskSkillWarnings(writeTaskSkills(workspace, { slug: projectSlug })));
701
+ todo.push(...taskSkillWarnings(writeTaskSkills(workspace, { slug: project })));
1324
702
  // Which build wrote them, so a hook running an older `carrick` than this
1325
703
  // one says so instead of answering from files it does not match
1326
- // (carrick#1372).
704
+ // (carrick#1372). It is also the record a run inside one repo of this
705
+ // folder finds (`initFolderAbove`).
1327
706
  recordCliVersion(workspace, currentVersion());
1328
707
  const ignored = ignoredSkillRoots(workspace);
1329
708
  if (ignored.length > 0) {
@@ -1337,7 +716,7 @@ export async function initWith(argv, out, interactive) {
1337
716
  // The check block in AGENTS.md (carrick#2828): only our marked section is
1338
717
  // written, and every other line of the file is left as it is.
1339
718
  try {
1340
- writeAgentsSection(workspace);
719
+ writeAgentsSection(workspace, { slug: project }, plan.counts);
1341
720
  }
1342
721
  catch (error) {
1343
722
  out.refuse(`Could not write the Carrick check section in ${AGENTS_FILE}: ${error.message}`);
@@ -1346,25 +725,21 @@ export async function initWith(argv, out, interactive) {
1346
725
  // started inside one of them reads neither host's files from the folder
1347
726
  // above (carrick#1512, option A as ruled). Kept out of git through each
1348
727
  // repo's own exclude file; a repo that is the workspace already has them.
1349
- for (const repo of selectedRepos) {
728
+ for (const repo of selected) {
1350
729
  if (realPath(repo.path) === realPath(workspace))
1351
730
  continue;
1352
731
  try {
1353
- // Null for a folder that is not a git repository of its own: its lines
1354
- // would land in some other repository's exclude file.
1355
- writeRepoCopy(repo.path, command.command, { slug: projectSlug });
732
+ writeRepoCopy(repo.path, command.command, { slug: project });
1356
733
  }
1357
734
  catch (error) {
1358
735
  out.refuse(`Could not add Carrick's hooks and skills to ${path.basename(repo.path)}: ${error.message}.`);
1359
736
  }
1360
737
  }
1361
- // Nothing here about restarting Claude Code: the instruction this run closes
1362
- // on is pasted into a new agent session, which loads the MCP server it has
1363
- // just been given (carrick#1512).
738
+ // The MCP connection, for work that crosses repos this machine does not
739
+ // hold, configured for every client this machine has (carrick#955). Nothing
740
+ // here about restarting Claude Code: the closing block opens a new agent
741
+ // session, which loads the server it has just been given (carrick#1512).
1364
742
  const mcp = connectMcpClients(editors);
1365
- // Nothing here about `carrick` not being on PATH: the offer above said it, in
1366
- // front of the decision it changes, and with the command for this machine's
1367
- // package manager rather than a guess at npm (carrick#1372).
1368
743
  for (const outcome of mcp.filter((entry) => entry.state === "failed")) {
1369
744
  todo.push(`MCP not configured for ${outcome.client}: ${outcome.detail}`);
1370
745
  }
@@ -1373,6 +748,8 @@ export async function initWith(argv, out, interactive) {
1373
748
  if (!mcp.some((outcome) => outcome.client === "Claude Code")) {
1374
749
  todo.push(`No claude command on this machine, so Claude Code has no Carrick MCP server. Once it is installed: ${mcpLine()}`);
1375
750
  }
751
+ if (plan.identity.allowance_sentence)
752
+ out.say(plan.identity.allowance_sentence);
1376
753
  // The rest of the project, which this machine does not hold. Carrick
1377
754
  // answers across every repo in a project, so a folder holding half of one
1378
755
  // is a partial index and nothing here would otherwise say so
@@ -1380,158 +757,45 @@ export async function initWith(argv, out, interactive) {
1380
757
  // holds this run's repos, set up here or not: a repo in the folder beside
1381
758
  // this one is not missing (carrick#1512). Only read where the run's own
1382
759
  // repos leave something unaccounted for, because each is a git call.
1383
- const absentHere = (identity) => {
1384
- const absent = absentRepos(identity, names, project, label);
1385
- if (absent.length === 0)
1386
- return absent;
1387
- const folder = selectedRepos.some((repo) => realPath(repo.path) === realPath(workspace))
760
+ if (absentRepos(plan.identity, names, project, label).length > 0) {
761
+ const folder = selected.some((repo) => realPath(repo.path) === realPath(workspace))
1388
762
  ? path.dirname(workspace)
1389
763
  : workspace;
1390
764
  const here = repoRoots(folder)
1391
765
  .map((root) => repoIdentity(root).name)
1392
766
  .filter((name) => name !== null);
1393
- return absentRepos(identity, [...names, ...here], project, label);
1394
- };
1395
- // The connection, last of the steps that talk to Carrick, so a read that
1396
- // fails costs nothing already decided: the files above are written
1397
- // (carrick#1489 review).
1398
- //
1399
- // Read again, now. The read the questions were answered from can be minutes
1400
- // old — the App is often installed in another tab while init waits at a
1401
- // prompt — and a first project may have just taken the repos. The
1402
- // connection lines used to come from the old read, and sent a reader to the
1403
- // grant page for repos that were already connected (carrick#1489).
1404
- //
1405
- // Where Carrick builds the index there was no prompt to wait at and nothing
1406
- // here connects, assigns or moves a repo, so the one read made before this
1407
- // run printed anything is the read these lines come from (carrick#2219).
1408
- if (cloud !== null) {
1409
- if (cloud.identity.allowance_sentence)
1410
- out.say(cloud.identity.allowance_sentence);
1411
- todo.push(...absentHere(cloud.identity));
1412
- }
1413
- else
1414
- try {
1415
- const current = await resolveRepos(credential.token, names);
1416
- const role = current.workspace.role;
1417
- const identity = await connectRepos(credential.token, names, current, {
1418
- interactive,
1419
- project: project ?? undefined,
1420
- projectExists,
1421
- movable,
1422
- announce: announced,
1423
- label,
1424
- // A role the read does not state is unknown, not a member's.
1425
- member: role === "member",
1426
- again: again(),
1427
- say: out.say,
1428
- track: (text, work, report) => out.step(text, work, report),
1429
- });
1430
- if (project !== null && !reposAreInProject(identity, names, project)) {
1431
- // An unverified project does not end the run, whether it was named on
1432
- // the command line or picked here. Stopping cost someone their hooks and
1433
- // their proposal for a browser step they could only take afterwards, and
1434
- // the documented command then needed two runs (carrick#993 row 8).
1435
- todo.push(`Finish the browser steps above to put these repos in ${label(project)}, then ${again(` --project ${project}`)} to verify.`);
1436
- }
1437
- // After a wait that was stopped, the grant is still the thing to do, and
1438
- // the line that said so is above the wait.
1439
- const unconnected = unconnectedRepos(identity, names);
1440
- if (interactive && unconnected.length > 0) {
1441
- todo.push(connectLine(unconnected, names.length, workspaceUrls(identity.workspace.slug).connect));
1442
- }
1443
- if (identity.allowance_sentence)
1444
- out.say(identity.allowance_sentence);
1445
- for (const repo of identity.repos) {
1446
- if (repo.connected && repo.services.length > 0)
1447
- hostedIndex.push(repo.full_name);
1448
- }
1449
- todo.push(...absentHere(identity));
1450
- }
1451
- catch (error) {
1452
- // The server's own sentence says what failed; this one says what is left.
1453
- todo.push(`${error.message} The files here are written; ${again()} to verify the connection and the project.`);
1454
- }
1455
- // What is set up, in one line; then the index; then what is left to do;
1456
- // then the instruction for the agent (carrick#1489). Where the workspace
1457
- // has this folder's repos in several projects, one line for each.
1458
- if (cloud !== null) {
1459
- for (const group of cloud.groups)
1460
- out.done(summaryLine(label(group.slug), group.repos));
1461
- }
1462
- else
1463
- out.done(summaryLine(project === null ? null : label(project), selectedRepos.filter((repo) => repo.name !== null).map((repo) => path.basename(repo.path))));
1464
- // No paid scan ran here, and that is the point (carrick-cloud#799): the one
1465
- // scan runs against a config someone has read. Where CI has already built an
1466
- // index, this run reads it onto the machine instead — the hosted index is
1467
- // the whole workspace's row, and `carrick index` from a laptop on a branch
1468
- // replaces it for everyone who queries it (carrick#993 row 2, carrick#1020).
1469
- //
1470
- // Where Carrick builds the index the read always runs, index or not: it is
1471
- // what leaves `.carrick/index.json` here, and the session-start hook reads a
1472
- // later hosted index in only onto a machine that has one (carrick#2219).
1473
- let downloaded = false;
1474
- let readFromHosted = [];
1475
- if (hostedIndex.length > 0 || cloud !== null) {
1476
- // The step reports its own outcome, so the read is one line in a terminal
1477
- // as well as in a pipe: a spinner that stopped with its label spent a
1478
- // second line on the same event (carrick#1032). What it says while it runs
1479
- // is the scanner's own count of where it has got to (carrick#1365).
1480
- //
1481
- // The repo list goes in because the step decides for itself whether to
1482
- // re-read this tree, and a repo the index does not cover is the one way
1483
- // that decision cannot be read off a drift count (carrick#1373).
1484
- const startedAt = Date.now();
1485
- const read = await out.step(STEP_LABEL, (progress) => downloadHostedIndex(plan.workspace, nativeRunner(out.quiet, progress), plan.repos.map((repo) => repo.path), progress), (outcome) => hostedReport(outcome, (Date.now() - startedAt) / 1000, cloud !== null ? "cloud" : "laptop"));
1486
- downloaded = read.kind === "downloaded";
1487
- if (read.kind === "downloaded")
1488
- readFromHosted = read.readFromHosted;
1489
- }
767
+ todo.push(...absentRepos(plan.identity, [...names, ...here], project, label));
768
+ }
769
+ // What is set up, one line per project the workspace has these repos in.
770
+ for (const group of plan.groups)
771
+ out.done(summaryLine(label(group.slug), group.repos));
772
+ // The read always runs, index or not: it is what leaves `.carrick/index.json`
773
+ // here, and the session-start hook reads a later hosted index in only onto a
774
+ // machine that has one (carrick#2219). It reports its own outcome, so it is
775
+ // one line in a terminal as well as in a pipe (carrick#1032), and what it
776
+ // says while it runs is the scanner's own count (carrick#1365). The repo
777
+ // list goes in because the step decides for itself whether to re-read this
778
+ // tree, and a repo the index does not cover is the one way that decision
779
+ // cannot be read off a drift count (carrick#1373).
780
+ const startedAt = Date.now();
781
+ const read = await out.step(STEP_LABEL, (progress) => downloadHostedIndex(derived.workspace, nativeRunner(out.quiet, progress), derived.repos.map((repo) => repo.path), progress), (outcome) => hostedReport(outcome, (Date.now() - startedAt) / 1000));
782
+ const downloaded = read.kind === "downloaded";
783
+ const readFromHosted = read.kind === "downloaded" ? read.readFromHosted : [];
1490
784
  for (const line of todo)
1491
785
  out.warn(line);
1492
- const installs = installCommands(plan);
1493
- // Where Carrick builds the index nobody scaffolds: there is no workflow to
1494
- // write, no config to seed and no scan to run from here, so the run closes
1495
- // on what this machine holds and on what it is still waiting for
1496
- // (carrick#2219).
1497
- if (cloud !== null) {
1498
- if (cloud.waiting.length > 0) {
1499
- const one = cloud.waiting.length === 1;
1500
- out.warn(`Carrick has no index for ${listed(cloud.waiting, 10)} yet. It builds ${one ? "it" : "them"} in the cloud, and ${workspaceUrls(cloud.identity.workspace.slug).repos} shows where ${one ? "it is" : "they are"}. Run carrick refresh here once ${one ? "it is" : "they are"} ready.`);
1501
- }
1502
- const install = installSentence(installCommands(plan, readFromHosted), "cloud");
1503
- if (install !== null)
1504
- out.warn(install);
1505
- if (downloaded)
1506
- out.done(READY_SENTENCE);
1507
- return 0;
1508
- }
1509
- // The scaffold tool writes the files a repo needs; a repo that has them needs
1510
- // nothing pasted anywhere. The line used to close every run, including one
1511
- // where every covered repo already had its config and its workflow, and
1512
- // "this repo" named nothing in a folder of several (carrick#1365).
1513
- //
1514
- // An install the first scan would be refused over goes in front of it: the
1515
- // agent otherwise found out from the refusal (carrick#1489).
1516
- const unscaffolded = reposToScaffold(selectedRepos);
1517
- if (unscaffolded.length > 0) {
1518
- const install = installSentence(installs, "agent");
1519
- // A new session, because that is the one that loads the MCP server this
1520
- // run has just added (carrick#1512).
1521
- out.note(NEXT_TITLE, [
1522
- ...(install === null ? [] : [install]),
1523
- scaffoldSentence(unscaffolded),
1524
- // The scaffold tool reads the proposal from the folder init ran in, and
1525
- // a run that moved to the folder above did not run where it started.
1526
- ...(realPath(workspace) === realPath(startedIn) ? [] : [initFolderSentence(workspace)]),
1527
- ]);
1528
- }
1529
- else {
1530
- const install = installSentence(installs, "reader");
1531
- if (install !== null)
1532
- out.warn(install);
786
+ // There is no workflow to write, no config to seed and no scan to run from
787
+ // here, so the run closes on what this machine holds and on what it is
788
+ // still waiting for (carrick#2219, carrick#3361).
789
+ if (plan.waiting.length > 0) {
790
+ const one = plan.waiting.length === 1;
791
+ out.warn(`Carrick has no index for ${listed(plan.waiting, 10)} yet. It builds ${one ? "it" : "them"} in the cloud, and ${reposUrl(plan.identity.workspace.slug)} shows where ${one ? "it is" : "they are"}. Run carrick refresh here once ${one ? "it is" : "they are"} ready.`);
792
+ }
793
+ const install = installSentence(installCommands(derived, readFromHosted));
794
+ if (install !== null)
795
+ out.warn(install);
796
+ if (downloaded)
1533
797
  out.done(READY_SENTENCE);
1534
- }
798
+ out.note(CLOUD_NEXT_TITLE, cloudNextLines(codexTrust, plan.waiting.length > 0 || !downloaded));
1535
799
  return 0;
1536
800
  }
1537
801
  /** `carrick templates <name>`, so a workflow is one command. */