@tablation/crew 0.153.2 → 0.154.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +199 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7126,6 +7126,17 @@ function attentionProblems(items, already) {
|
|
|
7126
7126
|
if (already.some((p) => p.kind === "docker_daemon_down")) seen.add(DOCKER_DAEMON_KEY);
|
|
7127
7127
|
return items.filter((i) => !seen.has(i.key)).map((i) => ({ severity: "attention", kind: i.kind, message: i.message }));
|
|
7128
7128
|
}
|
|
7129
|
+
var NO_PROJECTS_REMEDY = "run `crew projects add NAME --prefix PREFIX` (or add a row to the Projects table)";
|
|
7130
|
+
function noProjectsFinding(route2, projectCount) {
|
|
7131
|
+
if (projectCount > 0) return null;
|
|
7132
|
+
return {
|
|
7133
|
+
severity: "attention",
|
|
7134
|
+
kind: "no_projects",
|
|
7135
|
+
route: route2,
|
|
7136
|
+
message: `route ${route2}: the tracker has no Projects row, so no ticket can be worked and a new Repos row has no project to belong to`,
|
|
7137
|
+
remedy: NO_PROJECTS_REMEDY
|
|
7138
|
+
};
|
|
7139
|
+
}
|
|
7129
7140
|
|
|
7130
7141
|
// src/passenger-containers.ts
|
|
7131
7142
|
import { execFileSync as execFileSync10 } from "child_process";
|
|
@@ -9534,6 +9545,19 @@ var Tracker = class {
|
|
|
9534
9545
|
if (!model) return [];
|
|
9535
9546
|
return this.client.records.list(model, { limit: 200 });
|
|
9536
9547
|
}
|
|
9548
|
+
/** Create a `Projects` (area) row (CREW-3359). Throws when the workspace has no Projects table. */
|
|
9549
|
+
async createProjectRow(fields) {
|
|
9550
|
+
const model = this.route.resolved?.areaModelId;
|
|
9551
|
+
if (!model) throw new Error("this workspace has no Projects table");
|
|
9552
|
+
return this.client.records.create(model, fields);
|
|
9553
|
+
}
|
|
9554
|
+
/** Whether the Projects table has the contract's work mode column; true when its columns cannot be read. */
|
|
9555
|
+
async projectHasWorkMode() {
|
|
9556
|
+
const model = this.route.resolved?.areaModelId;
|
|
9557
|
+
if (!model) return false;
|
|
9558
|
+
const cols = await this.columnNames(model);
|
|
9559
|
+
return cols.size === 0 || cols.has(this.contract.columns.workMode);
|
|
9560
|
+
}
|
|
9537
9561
|
/** Every Projects row with its raw `work_mode`, for `crew status`. */
|
|
9538
9562
|
async projectRowsWithModes() {
|
|
9539
9563
|
const rows = await this.projectRows();
|
|
@@ -16269,6 +16293,8 @@ var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
|
16269
16293
|
"source",
|
|
16270
16294
|
"var",
|
|
16271
16295
|
"path",
|
|
16296
|
+
"prefix",
|
|
16297
|
+
"work-mode",
|
|
16272
16298
|
"service",
|
|
16273
16299
|
"topic",
|
|
16274
16300
|
"assignee",
|
|
@@ -17113,7 +17139,20 @@ import { homedir as homedir9 } from "os";
|
|
|
17113
17139
|
import { basename as basename10, join as join42, resolve as resolve4 } from "path";
|
|
17114
17140
|
import { isMap, isSeq, parseDocument, stringify as stringify2 } from "yaml";
|
|
17115
17141
|
var ReposError = class extends Error {
|
|
17142
|
+
/** A stable reason for a `--json` reader, when the failure has one (CREW-3359). */
|
|
17143
|
+
code;
|
|
17144
|
+
constructor(message, code) {
|
|
17145
|
+
super(message);
|
|
17146
|
+
this.code = code;
|
|
17147
|
+
}
|
|
17116
17148
|
};
|
|
17149
|
+
var NO_PROJECTS_CODE = "no_projects";
|
|
17150
|
+
function noProjectsError() {
|
|
17151
|
+
return new ReposError(
|
|
17152
|
+
"the tracker has no Projects row, so the new Repos row has no project to belong to \u2014 create one with `crew projects add NAME --prefix PREFIX`, then re-run (or pass --no-create to skip the Repos row)",
|
|
17153
|
+
NO_PROJECTS_CODE
|
|
17154
|
+
);
|
|
17155
|
+
}
|
|
17117
17156
|
function normalizeRemote2(url) {
|
|
17118
17157
|
if (!url) return void 0;
|
|
17119
17158
|
let s = url.trim();
|
|
@@ -24662,6 +24701,85 @@ function formatProjectsReport(report) {
|
|
|
24662
24701
|
return `${lines2.join("\n")}
|
|
24663
24702
|
`;
|
|
24664
24703
|
}
|
|
24704
|
+
var ProjectsError = class extends Error {
|
|
24705
|
+
code;
|
|
24706
|
+
constructor(message, code = "invalid") {
|
|
24707
|
+
super(message);
|
|
24708
|
+
this.code = code;
|
|
24709
|
+
}
|
|
24710
|
+
};
|
|
24711
|
+
var WORK_MODES = ["automatic", "hybrid", "manual"];
|
|
24712
|
+
var PROJECT_FORBIDDEN_MESSAGE = "this route's key is not allowed to create a Projects row \u2014 a workspace admin has to add the project (the Projects table, or `crew projects add` with an admin's key)";
|
|
24713
|
+
function validateProjectInput(i) {
|
|
24714
|
+
const name = (i.name ?? "").trim();
|
|
24715
|
+
if (!name) throw new ProjectsError("a project needs a name: crew projects add [route] NAME --prefix PREFIX");
|
|
24716
|
+
const prefix = (i.prefix ?? "").trim();
|
|
24717
|
+
if (!prefix) throw new ProjectsError("a project needs an issue prefix: pass --prefix PREFIX (letters and digits, e.g. CREW)");
|
|
24718
|
+
if (!/^[A-Za-z0-9]+$/.test(prefix)) {
|
|
24719
|
+
throw new ProjectsError(`the issue prefix "${prefix}" may only contain letters and digits`);
|
|
24720
|
+
}
|
|
24721
|
+
const mode = i.workMode?.trim().toLowerCase();
|
|
24722
|
+
if (mode !== void 0 && !WORK_MODES.includes(mode)) {
|
|
24723
|
+
throw new ProjectsError(`unknown work mode "${i.workMode}" (use ${WORK_MODES.join(", ")})`);
|
|
24724
|
+
}
|
|
24725
|
+
return { name, prefix: prefix.toUpperCase(), workMode: mode ?? "automatic", explicitMode: mode !== void 0 };
|
|
24726
|
+
}
|
|
24727
|
+
function planProjectAdd(i, ctx) {
|
|
24728
|
+
const v = validateProjectInput(i);
|
|
24729
|
+
for (const row of ctx.existing) {
|
|
24730
|
+
if (row.name?.toLowerCase() === v.name.toLowerCase()) {
|
|
24731
|
+
throw new ProjectsError(`a project named "${row.name}" already exists (${row.id}); nothing was created`, "duplicate");
|
|
24732
|
+
}
|
|
24733
|
+
if (row.issue_prefix && row.issue_prefix.toLowerCase() === v.prefix.toLowerCase()) {
|
|
24734
|
+
throw new ProjectsError(`the prefix ${row.issue_prefix} is already used by project "${row.name ?? row.id}" (${row.id}); nothing was created`, "duplicate");
|
|
24735
|
+
}
|
|
24736
|
+
}
|
|
24737
|
+
const fields = { name: v.name, issue_prefix: v.prefix };
|
|
24738
|
+
if (ctx.hasWorkModeColumn) {
|
|
24739
|
+
fields[ctx.workModeColumn] = v.workMode === "manual" ? ctx.manualWorkMode : v.workMode === "hybrid" ? ctx.hybridWorkMode : "automatic";
|
|
24740
|
+
} else if (v.explicitMode) {
|
|
24741
|
+
throw new ProjectsError(`this workspace's Projects table has no ${ctx.workModeColumn} column, so --work-mode cannot be set; omit it to create the project without one`, "no_work_mode_column");
|
|
24742
|
+
}
|
|
24743
|
+
return { fields, name: v.name, prefix: v.prefix, workMode: ctx.hasWorkModeColumn ? v.workMode : "automatic" };
|
|
24744
|
+
}
|
|
24745
|
+
function isForbidden2(e) {
|
|
24746
|
+
const status2 = e?.status;
|
|
24747
|
+
return status2 === 403 || /\b403\b/.test(e instanceof Error ? e.message : String(e));
|
|
24748
|
+
}
|
|
24749
|
+
async function createProject(tracker, input, opts = {}) {
|
|
24750
|
+
validateProjectInput(input);
|
|
24751
|
+
let plan;
|
|
24752
|
+
try {
|
|
24753
|
+
plan = planProjectAdd(input, {
|
|
24754
|
+
workModeColumn: tracker.contract.columns.workMode,
|
|
24755
|
+
manualWorkMode: tracker.contract.manualWorkMode,
|
|
24756
|
+
hybridWorkMode: tracker.contract.hybridWorkMode,
|
|
24757
|
+
existing: await tracker.projectRows(),
|
|
24758
|
+
hasWorkModeColumn: await tracker.projectHasWorkMode()
|
|
24759
|
+
});
|
|
24760
|
+
} catch (e) {
|
|
24761
|
+
if (e instanceof ProjectsError) throw e;
|
|
24762
|
+
throw new ProjectsError(isForbidden2(e) ? PROJECT_FORBIDDEN_MESSAGE : `could not read the Projects table: ${firstLine2(e)}`, isForbidden2(e) ? "forbidden" : "tracker");
|
|
24763
|
+
}
|
|
24764
|
+
const entry = (id) => ({ id, name: plan.name, issuePrefix: plan.prefix, workMode: plan.workMode, current: false });
|
|
24765
|
+
if (opts.dryRun) return { entry: entry(""), created: false };
|
|
24766
|
+
try {
|
|
24767
|
+
const row = await tracker.createProjectRow(plan.fields);
|
|
24768
|
+
return { entry: entry(row.id), created: true };
|
|
24769
|
+
} catch (e) {
|
|
24770
|
+
throw new ProjectsError(isForbidden2(e) ? PROJECT_FORBIDDEN_MESSAGE : `could not create the project: ${firstLine2(e)}`, isForbidden2(e) ? "forbidden" : "tracker");
|
|
24771
|
+
}
|
|
24772
|
+
}
|
|
24773
|
+
function firstLine2(e) {
|
|
24774
|
+
return (e instanceof Error ? e.message : String(e)).split("\n")[0].slice(0, 200);
|
|
24775
|
+
}
|
|
24776
|
+
async function offerFirstProject(prompter, create2) {
|
|
24777
|
+
prompter.say("The tracker has no Projects row, and the new Repos row has to belong to one.");
|
|
24778
|
+
if (!await prompter.confirm("Create a project now?", true)) return null;
|
|
24779
|
+
const name = await prompter.ask("Project name");
|
|
24780
|
+
const prefix = await prompter.ask("Issue prefix (letters and digits, e.g. CREW)");
|
|
24781
|
+
return (await create2({ name, prefix })).entry;
|
|
24782
|
+
}
|
|
24665
24783
|
|
|
24666
24784
|
// src/forge-cmd.ts
|
|
24667
24785
|
import { parseDocument as parseDocument5 } from "yaml";
|
|
@@ -27482,7 +27600,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
|
|
|
27482
27600
|
import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
|
|
27483
27601
|
import { join as join59 } from "path";
|
|
27484
27602
|
function builtVersion() {
|
|
27485
|
-
return true ? "0.
|
|
27603
|
+
return true ? "0.154.0" : null;
|
|
27486
27604
|
}
|
|
27487
27605
|
var REBUILD_HINT = "rebuild with npm run build";
|
|
27488
27606
|
function newestMtime(path) {
|
|
@@ -29682,6 +29800,7 @@ function usage(problem, requested = false) {
|
|
|
29682
29800
|
crew --version [--json] print the crew version on one line (also: crew version); --json adds home and compiled
|
|
29683
29801
|
crew status [route] [--json] [--verbose] what is running and what needs a person; --verbose adds configuration and full lists; --json for a machine reader
|
|
29684
29802
|
crew projects [--route R] [--json] the Projects rows each route can read (id, name, prefix, work mode)
|
|
29803
|
+
crew projects add [route] NAME --prefix P [--work-mode automatic|hybrid|manual] [--json] [--dry-run] create a Projects row
|
|
29685
29804
|
crew provision --key K --route WS[/PROJECT] [--forge-host H] [--ship-name N] [--json] one non-interactive run: connect, forge tokens,
|
|
29686
29805
|
enable routes, install units with lingering, start the daemon; safe to re-run (CREW_CONNECT_KEY,
|
|
29687
29806
|
CREW_PROVISION_ROUTES, CREW_SHIP_NAME, CREW_FORGE_TOKEN[_<HOST>] also read)
|
|
@@ -32636,7 +32755,7 @@ ${f.tail.trimEnd()}
|
|
|
32636
32755
|
case "repos": {
|
|
32637
32756
|
const sub = positional[1];
|
|
32638
32757
|
const usage2 = () => {
|
|
32639
|
-
process.stderr.write("crew repos add [workspace/project] [name] [path] [--name N] [--project P] [--dry-run] [--no-create]\ncrew repos clone [workspace/project] <name> [--dir PATH] [--dry-run] [--json]\ncrew repos list <workspace/project> [--json]\ncrew repos check [PATH | --route ROUTE [PATH] | ROUTE NAME] [--strict] [--json]\ncrew repos prompt [--json]\ncrew repos hooks [workspace/project] <name> [--suggest] [--agent] [--write route|repo [--replace]] [--clear route] [--recipes ID,ID] [--hook KEY=CMD ...] [--json]\n");
|
|
32758
|
+
process.stderr.write("crew repos add [workspace/project] [name] [path] [--name N] [--project P] [--dry-run] [--no-create] [--json]\ncrew repos clone [workspace/project] <name> [--dir PATH] [--dry-run] [--json]\ncrew repos list <workspace/project> [--json]\ncrew repos check [PATH | --route ROUTE [PATH] | ROUTE NAME] [--strict] [--json]\ncrew repos prompt [--json]\ncrew repos hooks [workspace/project] <name> [--suggest] [--agent] [--write route|repo [--replace]] [--clear route] [--recipes ID,ID] [--hook KEY=CMD ...] [--json]\n");
|
|
32640
32759
|
process.exit(2);
|
|
32641
32760
|
};
|
|
32642
32761
|
if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
|
|
@@ -32937,7 +33056,32 @@ ${f.tail.trimEnd()}
|
|
|
32937
33056
|
if (e instanceof ConfigError) throw new ReposError(`${e.message}; or pass --no-create`);
|
|
32938
33057
|
throw e;
|
|
32939
33058
|
}
|
|
32940
|
-
const
|
|
33059
|
+
const knownProjects = await rowTracker.projectRows();
|
|
33060
|
+
let projectId;
|
|
33061
|
+
if (knownProjects.length === 0 && !value("project") && !planRoute.resolved?.areaId) {
|
|
33062
|
+
if (dryRun) {
|
|
33063
|
+
process.stdout.write(`${plan.block}
|
|
33064
|
+
would need a project first: the tracker has none (\`crew projects add NAME --prefix PREFIX\`)
|
|
33065
|
+
`);
|
|
33066
|
+
break;
|
|
33067
|
+
}
|
|
33068
|
+
if (flag("json") || !(process.stdin.isTTY && process.stdout.isTTY)) throw noProjectsError();
|
|
33069
|
+
const prompter = terminalPrompter();
|
|
33070
|
+
try {
|
|
33071
|
+
const made = await offerFirstProject(prompter, (input) => createProject(rowTracker, input));
|
|
33072
|
+
if (!made) throw noProjectsError();
|
|
33073
|
+
process.stdout.write(`created project ${made.name} (${made.issuePrefix}, ${made.workMode}) ${made.id}
|
|
33074
|
+
`);
|
|
33075
|
+
projectId = made.id;
|
|
33076
|
+
} catch (e) {
|
|
33077
|
+
if (e instanceof ProjectsError) throw new ReposError(e.message, e.code);
|
|
33078
|
+
throw e;
|
|
33079
|
+
} finally {
|
|
33080
|
+
prompter.close();
|
|
33081
|
+
}
|
|
33082
|
+
} else {
|
|
33083
|
+
projectId = resolveRepoProject(knownProjects, value("project"), planRoute.resolved?.areaId);
|
|
33084
|
+
}
|
|
32941
33085
|
let spec;
|
|
32942
33086
|
try {
|
|
32943
33087
|
const rc = loadRepoConfig(top);
|
|
@@ -32972,6 +33116,11 @@ ${f.tail.trimEnd()}
|
|
|
32972
33116
|
`);
|
|
32973
33117
|
} catch (e) {
|
|
32974
33118
|
if (e instanceof ReposError) {
|
|
33119
|
+
if (flag("json") && e.code) {
|
|
33120
|
+
process.stdout.write(`${JSON.stringify({ ok: false, reason: e.code, message: e.message })}
|
|
33121
|
+
`);
|
|
33122
|
+
process.exit(2);
|
|
33123
|
+
}
|
|
32975
33124
|
die("crew repos", e.message, "`crew doctor`", 2);
|
|
32976
33125
|
}
|
|
32977
33126
|
throw e;
|
|
@@ -35141,6 +35290,42 @@ ${where.join("\n")}`);
|
|
|
35141
35290
|
break;
|
|
35142
35291
|
}
|
|
35143
35292
|
case "projects": {
|
|
35293
|
+
if (positional[1] === "add") {
|
|
35294
|
+
const rest = positional.slice(2);
|
|
35295
|
+
const names = cfg.routes.map((r) => r.route);
|
|
35296
|
+
let routeName = value("route");
|
|
35297
|
+
if (!routeName && rest.length > 1 && names.includes(rest[0])) routeName = rest.shift();
|
|
35298
|
+
if (!routeName && names.length === 1) routeName = names[0];
|
|
35299
|
+
const target = cfg.routes.find((r) => r.route === routeName);
|
|
35300
|
+
const failProject = (e) => {
|
|
35301
|
+
if (flag("json")) {
|
|
35302
|
+
process.stdout.write(`${JSON.stringify({ ok: false, reason: e.code, message: e.message })}
|
|
35303
|
+
`);
|
|
35304
|
+
return process.exit(2);
|
|
35305
|
+
}
|
|
35306
|
+
return die("crew projects add", e.message, "`crew projects`", 2);
|
|
35307
|
+
};
|
|
35308
|
+
if (!target) {
|
|
35309
|
+
die("crew projects add", routeName ? `no route "${routeName}" (have: ${names.join(", ")})` : `several routes are configured; name one: ${names.join(", ") || "none"}`, "`crew status`");
|
|
35310
|
+
}
|
|
35311
|
+
try {
|
|
35312
|
+
const { entry, created } = await createProject(
|
|
35313
|
+
new Tracker(target, cfg.ship),
|
|
35314
|
+
{ name: rest.join(" "), prefix: value("prefix"), workMode: value("work-mode") },
|
|
35315
|
+
{ dryRun }
|
|
35316
|
+
);
|
|
35317
|
+
if (flag("json")) process.stdout.write(`${JSON.stringify(created ? entry : { ...entry, id: null }, null, 2)}
|
|
35318
|
+
`);
|
|
35319
|
+
else if (!created) process.stdout.write(`would create project ${entry.name} (${entry.issuePrefix}, ${entry.workMode}) on route ${target.route}
|
|
35320
|
+
`);
|
|
35321
|
+
else process.stdout.write(`created project ${entry.name} (${entry.issuePrefix}, ${entry.workMode}) ${entry.id}
|
|
35322
|
+
`);
|
|
35323
|
+
} catch (e) {
|
|
35324
|
+
if (e instanceof ProjectsError) failProject(e);
|
|
35325
|
+
throw e;
|
|
35326
|
+
}
|
|
35327
|
+
break;
|
|
35328
|
+
}
|
|
35144
35329
|
const only = value("route") ?? positional[1];
|
|
35145
35330
|
const wanted = only ? cfg.routes.filter((r) => r.route === only) : cfg.routes;
|
|
35146
35331
|
if (only && wanted.length === 0) {
|
|
@@ -35502,6 +35687,11 @@ ${where.join("\n")}`);
|
|
|
35502
35687
|
} else if (w.state === "ok") passed++;
|
|
35503
35688
|
}
|
|
35504
35689
|
}
|
|
35690
|
+
if (!flag("offline")) {
|
|
35691
|
+
const np = noProjectsFinding(route2.route, (await new Tracker(route2, cfg.ship).projectRows().catch(() => [null])).length);
|
|
35692
|
+
if (np) problems.push(np);
|
|
35693
|
+
else passed++;
|
|
35694
|
+
}
|
|
35505
35695
|
for (const message of roleCapWarnings(cfg.ship)) problems.push({ severity: "note", kind: "role_cap_above_ship_cap", message });
|
|
35506
35696
|
for (const f of routeAvatarFailures(cfg.ship.stateDir, route2.route)) problems.push({ severity: "note", kind: "persona_avatar_upload_failed", route: route2.route, message: `${f.role} persona avatar failed to upload: ${f.detail}`, remedy: "run `crew agents sync` again" });
|
|
35507
35697
|
if (daemonLiveness) {
|
|
@@ -35845,6 +36035,12 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
35845
36035
|
`);
|
|
35846
36036
|
}
|
|
35847
36037
|
}
|
|
36038
|
+
if (!flag("offline")) {
|
|
36039
|
+
const projectRows = await tracker.projectRows().catch(() => void 0);
|
|
36040
|
+
const np = projectRows ? noProjectsFinding(route2.route, projectRows.length) : null;
|
|
36041
|
+
if (np) R.line(`projects: WARN ${np.message} \u2014 ${np.remedy}
|
|
36042
|
+
`);
|
|
36043
|
+
}
|
|
35848
36044
|
const [ships, crewRows] = await Promise.all([tracker.shipRows(), tracker.crewRows()]);
|
|
35849
36045
|
if (ships.length === 0) {
|
|
35850
36046
|
R.line("ship record: this workspace has no Ships table (fine)\n");
|
package/package.json
CHANGED