agentlane 0.0.0 → 0.4.0-rc.2
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/CHANGELOG.md +118 -0
- package/LICENSE +27 -0
- package/README.md +167 -2
- package/dist/agents/claude-plugin.js +79 -0
- package/dist/agents/cli.js +258 -0
- package/dist/agents/detect.js +88 -0
- package/dist/agents/init.js +251 -0
- package/dist/agents/launcher.js +32 -0
- package/dist/agents/package.js +119 -0
- package/dist/agents/skills.js +59 -0
- package/dist/agents/toml.js +325 -0
- package/dist/agents/wiring-check.js +117 -0
- package/dist/agents/wiring.js +374 -0
- package/dist/bench/host.js +104 -0
- package/dist/bench/live.js +511 -0
- package/dist/bench/mcp-client.js +91 -0
- package/dist/bench/model.js +15 -0
- package/dist/bench/report.js +162 -0
- package/dist/bench/run.js +121 -0
- package/dist/bench/schedule.js +140 -0
- package/dist/bench/stats.js +59 -0
- package/dist/bench-cli.js +167 -0
- package/dist/browser/aria.js +184 -0
- package/dist/browser/control.js +203 -0
- package/dist/browser/env.js +118 -0
- package/dist/browser/evidence.js +44 -0
- package/dist/browser/install.js +361 -0
- package/dist/browser/kinds.js +10 -0
- package/dist/browser/lane-browser.js +224 -0
- package/dist/browser/libraries.js +56 -0
- package/dist/browser/paths.js +29 -0
- package/dist/browser/release.js +121 -0
- package/dist/browser/screen.js +19 -0
- package/dist/browser/signin.js +154 -0
- package/dist/browser/stop.js +163 -0
- package/dist/browser/tools.js +25 -0
- package/dist/cache/build.js +154 -0
- package/dist/cache/config.js +186 -0
- package/dist/cache/index.js +4 -0
- package/dist/cache/key.js +196 -0
- package/dist/cache/store.js +303 -0
- package/dist/cli.js +178 -0
- package/dist/clock.js +4 -0
- package/dist/devices/adb.js +160 -0
- package/dist/devices/android.js +214 -0
- package/dist/devices/backend.js +7 -0
- package/dist/devices/bundler.js +46 -0
- package/dist/devices/common.js +51 -0
- package/dist/devices/controls.js +65 -0
- package/dist/devices/dial.js +56 -0
- package/dist/devices/emulator.js +396 -0
- package/dist/devices/hygiene.js +202 -0
- package/dist/devices/index.js +5 -0
- package/dist/devices/launch.js +76 -0
- package/dist/devices/simctl.js +119 -0
- package/dist/devices/tools.js +1 -0
- package/dist/devices/variant.js +99 -0
- package/dist/devices/xcrun.js +265 -0
- package/dist/driver/absence.js +54 -0
- package/dist/driver/caller.js +51 -0
- package/dist/driver/client.js +312 -0
- package/dist/driver/diff.js +180 -0
- package/dist/driver/elements.js +70 -0
- package/dist/driver/engine-main.js +13 -0
- package/dist/driver/engine.js +499 -0
- package/dist/driver/errors.js +11 -0
- package/dist/driver/exec.js +66 -0
- package/dist/driver/failure.js +156 -0
- package/dist/driver/flow.js +94 -0
- package/dist/driver/idle.js +100 -0
- package/dist/driver/images.js +68 -0
- package/dist/driver/install.js +272 -0
- package/dist/driver/lock.js +101 -0
- package/dist/driver/look.js +223 -0
- package/dist/driver/maestro-child.js +194 -0
- package/dist/driver/maestro-runs.js +46 -0
- package/dist/driver/paths.js +105 -0
- package/dist/driver/pixels.js +144 -0
- package/dist/driver/plan.js +108 -0
- package/dist/driver/release.js +7 -0
- package/dist/driver/runner.js +42 -0
- package/dist/driver/selector.js +91 -0
- package/dist/driver/session.js +474 -0
- package/dist/driver/suggest.js +86 -0
- package/dist/driver/supervisor.js +251 -0
- package/dist/driver/tree.js +426 -0
- package/dist/driver-cli.js +865 -0
- package/dist/evidence/device.js +177 -0
- package/dist/evidence/evidence.js +304 -0
- package/dist/evidence/files.js +92 -0
- package/dist/hooks/env.js +81 -0
- package/dist/hooks/run.js +101 -0
- package/dist/mcp/server.js +69 -0
- package/dist/mcp/tools.js +246 -0
- package/dist/name.js +22 -0
- package/dist/plugin/aims.js +465 -0
- package/dist/plugin/conventions.js +73 -0
- package/dist/plugin/guard.js +163 -0
- package/dist/plugin/hook-cli.js +216 -0
- package/dist/plugin/session-name.js +28 -0
- package/dist/plugin/shell.js +254 -0
- package/dist/processes.js +77 -0
- package/dist/project/config.js +316 -0
- package/dist/project/schema.js +335 -0
- package/dist/project/validate.js +224 -0
- package/dist/registry/config.js +142 -0
- package/dist/registry/format.js +22 -0
- package/dist/registry/owner.js +265 -0
- package/dist/registry/paths.js +50 -0
- package/dist/registry/ports.js +26 -0
- package/dist/registry/prune.js +160 -0
- package/dist/registry/refusal.js +53 -0
- package/dist/registry/registry.js +1027 -0
- package/dist/registry/resources.js +117 -0
- package/dist/registry/rows.js +115 -0
- package/dist/registry/status.js +85 -0
- package/dist/registry/store.js +274 -0
- package/dist/registry/types.js +1 -0
- package/dist/registry-cli.js +544 -0
- package/dist/services/services.js +268 -0
- package/dist/services/system.js +189 -0
- package/dist/up/deps.js +1 -0
- package/dist/up/doctor.js +424 -0
- package/dist/up/exec.js +133 -0
- package/dist/up/lane-files.js +75 -0
- package/dist/up/lane-services.js +38 -0
- package/dist/up/maestro-env.js +172 -0
- package/dist/up/preflight.js +232 -0
- package/dist/up/release.js +148 -0
- package/dist/up/resources.js +178 -0
- package/dist/up/restart.js +87 -0
- package/dist/up/setup.js +28 -0
- package/dist/up/up.js +610 -0
- package/dist/up-cli.js +258 -0
- package/dist/usage.js +16 -0
- package/package.json +58 -3
- package/schema/agentlane.schema.json +675 -0
- package/skills/create-verification-skill/LICENSE +21 -0
- package/skills/create-verification-skill/SKILL.md +88 -0
- package/skills/dev-loop/LICENSE +21 -0
- package/skills/dev-loop/SKILL.md +61 -0
- package/skills/device/SKILL.md +8 -0
- package/skills/drive/SKILL.md +64 -0
- package/skills/maintain-verification-skill/LICENSE +21 -0
- package/skills/maintain-verification-skill/SKILL.md +42 -0
- package/skills/setup/SKILL.md +80 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { LANE_TOKEN_ENV, laneVariables, hookEnvironment, resourceVariables } from "../hooks/env.js";
|
|
4
|
+
import { describeExit, HookFailed, runHook, tail } from "../hooks/run.js";
|
|
5
|
+
import { CLI, TOOL } from "../name.js";
|
|
6
|
+
import { EXPORT_NAME_PATTERN, EXPORTS_FILE_ENV } from "../project/schema.js";
|
|
7
|
+
import { laneDir } from "./lane-files.js";
|
|
8
|
+
export class ResourceFailed extends Error {
|
|
9
|
+
resource;
|
|
10
|
+
constructor(resource, problem) {
|
|
11
|
+
super(`resource ${resource}: ${problem}`);
|
|
12
|
+
this.name = 'ResourceFailed';
|
|
13
|
+
this.resource = resource;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function resourceLog(dir, name) {
|
|
17
|
+
return path.join(dir, 'resources', `${name}.log`);
|
|
18
|
+
}
|
|
19
|
+
function exportsFile(dir, name) {
|
|
20
|
+
return path.join(dir, 'resources', `${name}.exports`);
|
|
21
|
+
}
|
|
22
|
+
function message(error) {
|
|
23
|
+
return error instanceof Error ? error.message : String(error);
|
|
24
|
+
}
|
|
25
|
+
function seconds(ms) {
|
|
26
|
+
return `${(ms / 1000).toFixed(1)} s`;
|
|
27
|
+
}
|
|
28
|
+
const LINE = new RegExp(`^(${EXPORT_NAME_PATTERN.slice(1, -1)})=(.*)$`);
|
|
29
|
+
function unquote(value) {
|
|
30
|
+
const first = value[0];
|
|
31
|
+
return value.length >= 2 && (first === '"' || first === "'") && value.endsWith(first) ? value.slice(1, -1) : value;
|
|
32
|
+
}
|
|
33
|
+
/** Reads the NAME=value lines a create wrote, and holds them to the names the resource declares. */
|
|
34
|
+
export function parseExports(text, declared) {
|
|
35
|
+
const found = {};
|
|
36
|
+
text.split('\n').forEach((raw, i) => {
|
|
37
|
+
const line = raw.replace(/\r$/, '');
|
|
38
|
+
if (line.trim() === '' || line.trimStart().startsWith('#'))
|
|
39
|
+
return;
|
|
40
|
+
const [, name, value] = LINE.exec(line) ?? [];
|
|
41
|
+
if (name === undefined || value === undefined) {
|
|
42
|
+
throw new Error(`line ${String(i + 1)} of $${EXPORTS_FILE_ENV} is not NAME=value: ${JSON.stringify(line)}`);
|
|
43
|
+
}
|
|
44
|
+
found[name] = unquote(value);
|
|
45
|
+
});
|
|
46
|
+
const extra = Object.keys(found).filter(n => !declared.includes(n));
|
|
47
|
+
if (extra.length > 0) {
|
|
48
|
+
throw new Error(`create wrote ${extra.join(', ')}, which the resource does not declare in exports (it declares ${declared.join(', ') || 'none'})`);
|
|
49
|
+
}
|
|
50
|
+
const missing = declared.filter(n => !(n in found));
|
|
51
|
+
if (missing.length > 0) {
|
|
52
|
+
throw new Error(`create exited 0 without writing ${missing.join(', ')} to $${EXPORTS_FILE_ENV}; write each as a NAME=value line, e.g. echo "${missing[0] ?? ''}=..." >> "$${EXPORTS_FILE_ENV}"`);
|
|
53
|
+
}
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
function readExports(file, resource) {
|
|
57
|
+
let text = '';
|
|
58
|
+
try {
|
|
59
|
+
text = fs.readFileSync(file, 'utf8');
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error.code !== 'ENOENT')
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
return parseExports(text, resource.exports);
|
|
66
|
+
}
|
|
67
|
+
function recorded(vars) {
|
|
68
|
+
return Object.fromEntries(Object.entries(vars).filter(([key]) => key !== LANE_TOKEN_ENV));
|
|
69
|
+
}
|
|
70
|
+
async function create(r, lane, resource) {
|
|
71
|
+
const { name } = resource;
|
|
72
|
+
const vars = laneVariables(lane, r.config, r.dir);
|
|
73
|
+
const file = exportsFile(r.dir, name);
|
|
74
|
+
const log = resourceLog(r.dir, name);
|
|
75
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
76
|
+
fs.rmSync(file, { force: true });
|
|
77
|
+
r.deps.log(`${TOOL} up: resource ${name}: ${resource.create} (log: ${log})`);
|
|
78
|
+
try {
|
|
79
|
+
await runHook(`resource ${name} create`, resource.create, {
|
|
80
|
+
cwd: resource.cwd,
|
|
81
|
+
env: hookEnvironment(r.deps.env, { ...vars, [EXPORTS_FILE_ENV]: file }, resourceVariables(r.config)),
|
|
82
|
+
log,
|
|
83
|
+
});
|
|
84
|
+
return readExports(file, resource);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const problem = error instanceof HookFailed
|
|
88
|
+
? `create ${describeExit(error.run)}: ${resource.create}\n${tail(log)}\nfull log: ${log}`
|
|
89
|
+
: `${message(error)}\nfull log: ${log}`;
|
|
90
|
+
r.registry.failResource(lane.id, name, problem.split('\n')[0] ?? problem);
|
|
91
|
+
throw new ResourceFailed(name, problem);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
fs.rmSync(file, { force: true });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Runs each resource's create that this lane lacks, in the config's order, each with the values of the ones before it.
|
|
99
|
+
* A resource the lane already has is kept as it is.
|
|
100
|
+
*/
|
|
101
|
+
export async function createResources(r, lane) {
|
|
102
|
+
const result = { lane, created: [], kept: [] };
|
|
103
|
+
for (const resource of r.config.resources) {
|
|
104
|
+
const start = r.registry.startResource(r.ref, {
|
|
105
|
+
name: resource.name,
|
|
106
|
+
cwd: resource.cwd,
|
|
107
|
+
teardown: resource.teardown,
|
|
108
|
+
timeoutMs: resource.teardownTimeoutMs,
|
|
109
|
+
env: recorded(laneVariables(result.lane, r.config, r.dir)),
|
|
110
|
+
cleared: resourceVariables(r.config),
|
|
111
|
+
});
|
|
112
|
+
if (start.kind === 'kept') {
|
|
113
|
+
result.kept.push(resource.name);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (start.retry !== null)
|
|
117
|
+
r.deps.log(`${TOOL} up: resource ${resource.name}: creating it again: ${start.retry}`);
|
|
118
|
+
const exports = await create(r, result.lane, resource);
|
|
119
|
+
r.registry.finishResource(result.lane.id, resource.name, exports);
|
|
120
|
+
result.lane = r.registry.touch(r.ref, `up: resource ${resource.name}`);
|
|
121
|
+
result.created.push(resource.name);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
function isDirectory(dir) {
|
|
126
|
+
try {
|
|
127
|
+
return fs.statSync(dir).isDirectory();
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function tearDown(deps, stateDir, t) {
|
|
134
|
+
const dir = laneDir(stateDir, t.lane);
|
|
135
|
+
const moved = !isDirectory(t.cwd);
|
|
136
|
+
if (moved)
|
|
137
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
138
|
+
const run = await runHook(`resource ${t.name} teardown`, t.teardown, {
|
|
139
|
+
cwd: moved ? dir : t.cwd,
|
|
140
|
+
env: hookEnvironment(deps.env, { ...t.env, ...t.exports }, t.cleared),
|
|
141
|
+
log: resourceLog(dir, t.name),
|
|
142
|
+
timeoutMs: t.timeoutMs,
|
|
143
|
+
});
|
|
144
|
+
return { ms: run.ms, moved };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Tears down the resources of lanes that have ended, by release or by a reap, with what their create recorded. A failed
|
|
148
|
+
* teardown keeps its record, so a later pass tries again; a pass skips one that failed in the last few minutes, unless
|
|
149
|
+
* it names that lane.
|
|
150
|
+
*/
|
|
151
|
+
export async function tearDownEndedResources(deps, registry, stateDir, choice = {}) {
|
|
152
|
+
const byLane = new Map();
|
|
153
|
+
for (const t of registry.takeTeardowns(choice.lane === undefined ? {} : { lane: choice.lane })) {
|
|
154
|
+
const into = byLane.get(t.lane) ?? { lane: t.lane, notes: [], problems: [] };
|
|
155
|
+
byLane.set(t.lane, into);
|
|
156
|
+
const away = `${t.cwd} is gone, so it ran in the lane's log folder`;
|
|
157
|
+
try {
|
|
158
|
+
const done = await tearDown(deps, stateDir, t);
|
|
159
|
+
registry.finishTeardown(t.lane, t.name);
|
|
160
|
+
into.notes.push(`tore down resource ${t.name} (${seconds(done.ms)}${done.moved ? `; ${away}` : ''})`);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const log = resourceLog(laneDir(stateDir, t.lane), t.name);
|
|
164
|
+
const how = error instanceof HookFailed ? `teardown ${describeExit(error.run)}` : `teardown could not run (${message(error)})`;
|
|
165
|
+
const where = isDirectory(t.cwd) ? '' : ` (${away})`;
|
|
166
|
+
const detail = error instanceof HookFailed ? `${t.teardown}\n${tail(log)}\nfull log: ${log}` : `full log: ${log}`;
|
|
167
|
+
if (choice.force) {
|
|
168
|
+
registry.finishTeardown(t.lane, t.name);
|
|
169
|
+
into.problems.push(`forgot resource ${t.name}: ${how}${where}, and --force drops its record, leaving what it made: ${detail}`);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
registry.failTeardown(t.lane, t.name, `${how}: ${t.teardown}`);
|
|
173
|
+
into.problems.push(`resource ${t.name}: ${how}${where} (attempt ${String(t.attempts + 1)}): ${detail}\nits record is kept: the next release or reap tries again, and ${CLI} release ${t.lane} runs it now`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return [...byLane.values()];
|
|
178
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { laneEnvironment } from "../hooks/env.js";
|
|
2
|
+
import { CLI, CONFIG_FILE, TOOL } from "../name.js";
|
|
3
|
+
import { findProjectConfig, loadLaneConfig } from "../project/config.js";
|
|
4
|
+
import { describeOwner, resolveOwner } from "../registry/owner.js";
|
|
5
|
+
import { stateDir } from "../registry/paths.js";
|
|
6
|
+
import { NotClaimed, UsageError } from "../registry/refusal.js";
|
|
7
|
+
import { Registry } from "../registry/registry.js";
|
|
8
|
+
import { resolveFolder } from "../registry-cli.js";
|
|
9
|
+
import { ServiceFailed } from "../services/services.js";
|
|
10
|
+
import { laneDir, readUpRecord } from "./lane-files.js";
|
|
11
|
+
import { claimedPort, recordedProcess, startClaimedService, stopClaimedService } from "./lane-services.js";
|
|
12
|
+
export async function restart(deps, names, worktree) {
|
|
13
|
+
if (names.length === 0) {
|
|
14
|
+
throw new UsageError('restart needs the name of a service', `${CLI} restart <service>, e.g. KEY=value ${CLI} restart api`);
|
|
15
|
+
}
|
|
16
|
+
const folder = resolveFolder(worktree ?? deps.cwd);
|
|
17
|
+
const owner = resolveOwner(deps.env, deps.processes, deps.selfPid);
|
|
18
|
+
const state = stateDir(deps.env);
|
|
19
|
+
const registry = Registry.open({
|
|
20
|
+
dir: state,
|
|
21
|
+
processes: deps.processes,
|
|
22
|
+
ports: deps.ports,
|
|
23
|
+
devices: deps.devices,
|
|
24
|
+
clock: deps.clock,
|
|
25
|
+
...(deps.pollMs !== undefined ? { pollMs: deps.pollMs } : {}),
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
const lane = registry.find(owner, folder.worktree);
|
|
29
|
+
if (!lane) {
|
|
30
|
+
throw new NotClaimed(`${describeOwner(owner)} holds no lane in ${folder.worktree}, so there is no service to restart`, `${CLI} up (it claims a lane, starts every service and launches the app)`);
|
|
31
|
+
}
|
|
32
|
+
const dir = laneDir(state, lane.id);
|
|
33
|
+
const record = readUpRecord(dir);
|
|
34
|
+
const file = record?.config ?? findProjectConfig(folder.worktree);
|
|
35
|
+
if (!file) {
|
|
36
|
+
throw new UsageError(`no ${CONFIG_FILE} in ${folder.worktree} or above it, so its services are unknown`, `write one at the project's root; '${CLI} schema' prints its JSON Schema`);
|
|
37
|
+
}
|
|
38
|
+
const config = loadLaneConfig(file, record?.platform ?? lane.device?.platform);
|
|
39
|
+
const platforms = record?.platforms ?? [config.platform];
|
|
40
|
+
const own = config.allServices.filter(s => s.platforms === null || s.platforms.some(p => platforms.includes(p)));
|
|
41
|
+
const targets = [...new Set(names)].map(name => {
|
|
42
|
+
const service = own.find(s => s.name === name);
|
|
43
|
+
if (!service) {
|
|
44
|
+
const other = config.allServices.find(s => s.name === name);
|
|
45
|
+
throw new UsageError(other
|
|
46
|
+
? `'${name}' runs only for ${other.platforms?.join(', ') ?? ''}, and lane ${lane.id} was brought up for ${platforms.join(', ')}`
|
|
47
|
+
: `'${name}' is not a service in ${config.file}`, `${CLI} restart ${own.map(s => s.name).join(' | ') || '(the config names no services)'}`);
|
|
48
|
+
}
|
|
49
|
+
const port = claimedPort(lane, name);
|
|
50
|
+
if (port === undefined) {
|
|
51
|
+
throw new UsageError(`lane ${lane.id} has no port for ${name}: ${config.file} named it after this lane was made`, `${CLI} release, then ${CLI} up, to claim a port for it`);
|
|
52
|
+
}
|
|
53
|
+
const recorded = recordedProcess(lane, name);
|
|
54
|
+
if (!recorded) {
|
|
55
|
+
throw new ServiceFailed(name, `is not running under lane ${lane.id}: up never started it, or its start failed\nto fix: ${CLI} up (it starts ${name} on ${String(port)} and keeps the healthy services, the device and the app)`, null);
|
|
56
|
+
}
|
|
57
|
+
return { service, port, recorded };
|
|
58
|
+
});
|
|
59
|
+
const ref = { id: lane.id, token: lane.token };
|
|
60
|
+
const services = {
|
|
61
|
+
deps,
|
|
62
|
+
registry,
|
|
63
|
+
ref,
|
|
64
|
+
lane,
|
|
65
|
+
dir,
|
|
66
|
+
env: laneEnvironment(deps.env, lane, config, dir),
|
|
67
|
+
};
|
|
68
|
+
const done = [];
|
|
69
|
+
for (const { service, port, recorded } of targets) {
|
|
70
|
+
const started = deps.clock.now();
|
|
71
|
+
registry.touch(ref, `restart: ${service.name}`);
|
|
72
|
+
const stopped = await stopClaimedService(services, recorded);
|
|
73
|
+
try {
|
|
74
|
+
const detail = await startClaimedService(services, service, port);
|
|
75
|
+
done.push({ service: service.name, port, stopped, started: detail, ms: deps.clock.now() - started });
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
deps.log(`${TOOL} restart: ${service.name} is stopped; lane ${lane.id} keeps port ${String(port)}, the device, the app and every other service. Fix the cause above, then run ${CLI} restart ${service.name} again (or ${CLI} up)`);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return { lane: lane.id, services: done };
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
registry.close();
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/up/setup.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { envName, TOOL } from "../name.js";
|
|
3
|
+
import { hookEnvironment, resourceVariables } from "../hooks/env.js";
|
|
4
|
+
import { resolveFolder } from "../registry-cli.js";
|
|
5
|
+
import { locateConfig } from "./up.js";
|
|
6
|
+
export async function runSetup(deps, worktree) {
|
|
7
|
+
const start = worktree ?? deps.cwd;
|
|
8
|
+
const folder = resolveFolder(start).worktree;
|
|
9
|
+
const config = locateConfig(start);
|
|
10
|
+
const command = config.hooks.setup;
|
|
11
|
+
if (!command) {
|
|
12
|
+
deps.log(`${TOOL} setup: ${config.file} has no setup hook; nothing to run`);
|
|
13
|
+
return { ran: false, code: 0, ms: 0 };
|
|
14
|
+
}
|
|
15
|
+
const env = hookEnvironment(deps.env, { [envName('WORKTREE')]: folder }, resourceVariables(config));
|
|
16
|
+
deps.log(`${TOOL} setup: ${command} (in ${config.dir})`);
|
|
17
|
+
const started = Date.now();
|
|
18
|
+
const code = await new Promise((resolve, reject) => {
|
|
19
|
+
const child = spawn('/bin/sh', ['-c', command], { cwd: config.dir, env, stdio: ['ignore', 2, 2] });
|
|
20
|
+
child.once('error', reject);
|
|
21
|
+
child.once('close', (exit, signal) => {
|
|
22
|
+
resolve(exit ?? (signal ? 128 : 1));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
const ms = Date.now() - started;
|
|
26
|
+
deps.log(`${TOOL} setup: ${code === 0 ? 'done' : `the setup hook exited ${String(code)}`} (${(ms / 1000).toFixed(1)} s)`);
|
|
27
|
+
return { ran: true, code, ms };
|
|
28
|
+
}
|