owenloop 0.5.3 → 0.5.5
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 +25 -0
- package/README.md +6 -2
- package/dist/packages/work/src/agent/brief.d.ts +6 -0
- package/dist/packages/work/src/agent/brief.js +102 -2
- package/dist/packages/work/src/agent/loop.d.ts +10 -1
- package/dist/packages/work/src/agent/loop.js +28 -0
- package/dist/packages/work/src/agent/workdir.d.ts +22 -0
- package/dist/packages/work/src/agent/workdir.js +80 -0
- package/dist/packages/work/src/exec/loop.d.ts +13 -1
- package/dist/packages/work/src/exec/loop.js +184 -9
- package/dist/packages/work/src/harness/child-env.js +8 -0
- package/dist/packages/work/src/harness/claude.js +25 -6
- package/dist/packages/work/src/harness/codex.js +7 -0
- package/dist/packages/work/src/harness/contract.d.ts +22 -3
- package/dist/packages/work/src/harness/contract.js +22 -3
- package/dist/packages/work/src/hold/mcp.d.ts +11 -2
- package/dist/packages/work/src/hold/mcp.js +69 -2
- package/dist/packages/work/src/hub/client.d.ts +8 -1
- package/dist/packages/work/src/hub/client.js +1 -0
- package/dist/packages/work/src/hub/types.d.ts +29 -0
- package/dist/packages/work/src/roles/agent-run.js +9 -1
- package/dist/packages/work/src/roles/exec.js +9 -0
- package/dist/packages/work/src/roles/shift.js +9 -1
- package/dist/packages/work/src/settings/settings.d.ts +32 -5
- package/dist/packages/work/src/settings/settings.js +37 -12
- package/dist/packages/work/src/shift/runtime.d.ts +7 -0
- package/dist/packages/work/src/shift/runtime.js +29 -4
- package/dist/packages/work/src/shift/spawn.d.ts +12 -2
- package/dist/packages/work/src/shift/spawn.js +16 -3
- package/dist/src/cli.js +257 -7
- package/dist/src/config-dir.d.ts +62 -0
- package/dist/src/config-dir.js +87 -0
- package/dist/src/crypto/trust-roots.d.ts +8 -4
- package/dist/src/crypto/trust-roots.js +18 -12
- package/dist/src/defs.js +57 -16
- package/dist/src/engine.d.ts +46 -1
- package/dist/src/engine.js +97 -3
- package/dist/src/hub.d.ts +5 -1
- package/dist/src/hub.js +7 -8
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/model.d.ts +29 -5
- package/dist/src/model.js +63 -14
- package/dist/src/paths.d.ts +47 -4
- package/dist/src/paths.js +36 -5
- package/dist/src/types.d.ts +8 -2
- package/dist/src/work-settings.d.ts +8 -5
- package/dist/src/work-settings.js +15 -12
- package/docs/authoring.md +40 -13
- package/docs/bundles.md +9 -0
- package/docs/cli.md +155 -24
- package/docs/crypto.md +8 -8
- package/docs/design.md +20 -2
- package/docs/embedding.md +5 -4
- package/docs/wire-contracts.md +3 -2
- package/package.json +1 -1
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/plugin/.mcp.json +1 -1
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
- package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { randomUUID } from 'node:crypto';
|
|
10
10
|
import { hostname } from 'node:os';
|
|
11
|
-
import { basename, join } from 'node:path';
|
|
11
|
+
import { basename, join, resolve } from 'node:path';
|
|
12
12
|
import { performance } from 'node:perf_hooks';
|
|
13
13
|
import { createHubClient } from "../hub/client.js";
|
|
14
14
|
import { resolveBearer } from "../credentials/resolve.js";
|
|
@@ -21,7 +21,7 @@ import { stampShiftEvent } from "./protocol.js";
|
|
|
21
21
|
import { createDefaultSpawner } from "./spawn.js";
|
|
22
22
|
import { resolveStateDir, ensureStateDir, reconcileInFlight } from "./state.js";
|
|
23
23
|
import { reconcileActiveSessions, sessionsPath } from "../harness/session-store.js";
|
|
24
|
-
import { resolveWorkRepo, resolveWorkRoot } from "../agent/workdir.js";
|
|
24
|
+
import { resolveAllowedWorkdirRoots, resolveWorkRepo, resolveWorkRoot, } from "../agent/workdir.js";
|
|
25
25
|
import { installSignalHandlers } from "../roles/signals.js";
|
|
26
26
|
import { createShiftDaemon } from "./server.js";
|
|
27
27
|
import { createBundleIngestor, createStoreInstructionSource, globalStoreRoot, } from "../../../../src/store/index.js";
|
|
@@ -153,6 +153,7 @@ export function parseArgs(args) {
|
|
|
153
153
|
case '--cache-dir':
|
|
154
154
|
case '--log-dir':
|
|
155
155
|
case '--log-max-age':
|
|
156
|
+
case '--work-root':
|
|
156
157
|
case '--state-dir': {
|
|
157
158
|
const r = takeValue(a, i);
|
|
158
159
|
if ('error' in r)
|
|
@@ -202,6 +203,13 @@ export function parseArgs(args) {
|
|
|
202
203
|
return { error: n.error };
|
|
203
204
|
parsed.pollIntervalMs = n;
|
|
204
205
|
}
|
|
206
|
+
else if (name === '--work-root') {
|
|
207
|
+
// ACCUMULATES rather than overwrites — one directory per occurrence
|
|
208
|
+
// is what makes a multi-project boundary expressible at all. A shift
|
|
209
|
+
// that may work in two projects needs two roots, and there is no
|
|
210
|
+
// separator that is safe inside a path on every platform.
|
|
211
|
+
(parsed.workRoots ??= []).push(r.value);
|
|
212
|
+
}
|
|
205
213
|
break;
|
|
206
214
|
}
|
|
207
215
|
default:
|
|
@@ -214,7 +222,7 @@ function usage() {
|
|
|
214
222
|
process.stderr.write('usage: owenloop work shift [--origin <url>] [--as <account>] [--name <n>] [--serve-crews a,b] [--cap <n>]\n' +
|
|
215
223
|
' [--workflow <id>] [--poll-interval <ms>] [--once]\n' +
|
|
216
224
|
' [--max-agents <n>] [--cache-dir <p>] [--state-dir <p>]\n' +
|
|
217
|
-
' [--log-dir <p>] [--log-max-age <ms>]
|
|
225
|
+
' [--log-dir <p>] [--log-max-age <ms>] [--work-root <dir>]...\n');
|
|
218
226
|
}
|
|
219
227
|
function errMsg(err) {
|
|
220
228
|
return err instanceof Error ? err.message : String(err);
|
|
@@ -335,6 +343,23 @@ export async function runShiftRuntime(parsed, options = {}) {
|
|
|
335
343
|
const maxConcurrentAgents = resolveMaxConcurrentAgents(parsed.maxAgents, settings.maxConcurrentAgents);
|
|
336
344
|
const workRoot = resolveWorkRoot(env, settings.workRoot, cacheDir);
|
|
337
345
|
const workRepo = resolveWorkRepo(env, settings.workRepo);
|
|
346
|
+
/**
|
|
347
|
+
* The operator's filesystem boundary, resolved once here so the loop receives
|
|
348
|
+
* an already-absolute list and does no precedence work of its own.
|
|
349
|
+
*
|
|
350
|
+
* Precedence is `--work-root` (repeatable) > `OWENLOOP_ALLOWED_WORKDIR_ROOTS`
|
|
351
|
+
* > `settings.allowedWorkdirRoots` > none. Each rung REPLACES the one below
|
|
352
|
+
* rather than adding to it: a narrowing control that could only ever widen
|
|
353
|
+
* would not be a safety control at all.
|
|
354
|
+
*
|
|
355
|
+
* Relative entries resolve against THIS process's cwd, which is where the
|
|
356
|
+
* operator typed the flag. `settings.allowedWorkdirRoots` cannot be relative
|
|
357
|
+
* — `validateSettings` rejects that at load, because a stored boundary that
|
|
358
|
+
* moves with the launch directory is the exact failure this key removes.
|
|
359
|
+
*/
|
|
360
|
+
const allowedWorkdirRoots = parsed.workRoots !== undefined && parsed.workRoots.length > 0
|
|
361
|
+
? parsed.workRoots.map((entry) => resolve(process.cwd(), entry))
|
|
362
|
+
: resolveAllowedWorkdirRoots(env, settings.allowedWorkdirRoots, process.cwd());
|
|
338
363
|
const hub = createHubClient({ origin, getToken: async () => token });
|
|
339
364
|
const now = () => Date.now();
|
|
340
365
|
const monotonicNow = () => performance.now();
|
|
@@ -445,7 +470,7 @@ export async function runShiftRuntime(parsed, options = {}) {
|
|
|
445
470
|
// output discarded exactly as it did before this change.
|
|
446
471
|
logDirReady
|
|
447
472
|
? { dir: logDir, err: (line) => process.stderr.write(`${line}\n`) }
|
|
448
|
-
: undefined);
|
|
473
|
+
: undefined, allowedWorkdirRoots);
|
|
449
474
|
const pollIntervalMs = parsed.pollIntervalMs ?? DEFAULT_POLL_MS;
|
|
450
475
|
const loop = createShiftLoop({
|
|
451
476
|
hub,
|
|
@@ -164,13 +164,23 @@ export interface SpawnPlan {
|
|
|
164
164
|
* step, registered default). The Shift command has no operator-facing harness
|
|
165
165
|
* flag, so there is no legitimate CLI override for this seam to carry.
|
|
166
166
|
*
|
|
167
|
+
* `allowedWorkdirRoots` (trailing, for the same reason) rides the child's spawn
|
|
168
|
+
* env as `OWENLOOP_ALLOWED_WORKDIR_ROOTS`, a `:`-separated list — the same
|
|
169
|
+
* "spawn env is the contract" shape as `OWENLOOP_ACCOUNT`, and for the same
|
|
170
|
+
* reason: neither `owenloop work exec` nor `owenloop work agent-run` has an
|
|
171
|
+
* operator-facing flag for it. It carries the roots the SHIFT resolved, so an
|
|
172
|
+
* operator's `owenloop shift start --work-root` reaches a detached child that
|
|
173
|
+
* would otherwise only see the settings file. Empty or omitted sets no variable
|
|
174
|
+
* at all, so the child falls through to its own settings-file resolution and
|
|
175
|
+
* the plan stays byte-identical to the pre-policy shape.
|
|
176
|
+
*
|
|
167
177
|
* `logDir` (trailing, after `shiftId`, for the same reason) adds the worker's
|
|
168
178
|
* log DESTINATION to the plan as `<logDir>/<run>.log`. The plan still carries
|
|
169
179
|
* `stdio: ['ignore','ignore','ignore']`: opening the file is I/O, this function
|
|
170
180
|
* is pure, and `createDefaultSpawner` substitutes the descriptors. Omitted ⇒ no
|
|
171
181
|
* `logFile` key at all, and the plan is byte-identical to the pre-logging shape.
|
|
172
182
|
*/
|
|
173
|
-
export declare function buildSpawnPlan(spec: SpawnSpec, origin: string, account: string, binPath: string, execPath?: string, shiftId?: string, logDir?: string): SpawnPlan;
|
|
183
|
+
export declare function buildSpawnPlan(spec: SpawnSpec, origin: string, account: string, binPath: string, execPath?: string, shiftId?: string, logDir?: string, allowedWorkdirRoots?: string[]): SpawnPlan;
|
|
174
184
|
/**
|
|
175
185
|
* The default detached spawner. Captures the resolved hub `origin`, the
|
|
176
186
|
* resolved `account`, the packaged bin path, and the dispatching Shift's
|
|
@@ -179,4 +189,4 @@ export declare function buildSpawnPlan(spec: SpawnSpec, origin: string, account:
|
|
|
179
189
|
* relying on `buildSpawnPlan`'s default) so `shiftId` — trailing after it
|
|
180
190
|
* — can be supplied positionally.
|
|
181
191
|
*/
|
|
182
|
-
export declare function createDefaultSpawner(origin: string, account: string, binPath?: string, shiftId?: string, onFailure?: WorkerFailureReporter, logging?: WorkerLogOptions): Spawner;
|
|
192
|
+
export declare function createDefaultSpawner(origin: string, account: string, binPath?: string, shiftId?: string, onFailure?: WorkerFailureReporter, logging?: WorkerLogOptions, allowedWorkdirRoots?: string[]): Spawner;
|
|
@@ -134,13 +134,23 @@ export function reportedHarnessId(spec, env) {
|
|
|
134
134
|
* step, registered default). The Shift command has no operator-facing harness
|
|
135
135
|
* flag, so there is no legitimate CLI override for this seam to carry.
|
|
136
136
|
*
|
|
137
|
+
* `allowedWorkdirRoots` (trailing, for the same reason) rides the child's spawn
|
|
138
|
+
* env as `OWENLOOP_ALLOWED_WORKDIR_ROOTS`, a `:`-separated list — the same
|
|
139
|
+
* "spawn env is the contract" shape as `OWENLOOP_ACCOUNT`, and for the same
|
|
140
|
+
* reason: neither `owenloop work exec` nor `owenloop work agent-run` has an
|
|
141
|
+
* operator-facing flag for it. It carries the roots the SHIFT resolved, so an
|
|
142
|
+
* operator's `owenloop shift start --work-root` reaches a detached child that
|
|
143
|
+
* would otherwise only see the settings file. Empty or omitted sets no variable
|
|
144
|
+
* at all, so the child falls through to its own settings-file resolution and
|
|
145
|
+
* the plan stays byte-identical to the pre-policy shape.
|
|
146
|
+
*
|
|
137
147
|
* `logDir` (trailing, after `shiftId`, for the same reason) adds the worker's
|
|
138
148
|
* log DESTINATION to the plan as `<logDir>/<run>.log`. The plan still carries
|
|
139
149
|
* `stdio: ['ignore','ignore','ignore']`: opening the file is I/O, this function
|
|
140
150
|
* is pure, and `createDefaultSpawner` substitutes the descriptors. Omitted ⇒ no
|
|
141
151
|
* `logFile` key at all, and the plan is byte-identical to the pre-logging shape.
|
|
142
152
|
*/
|
|
143
|
-
export function buildSpawnPlan(spec, origin, account, binPath, execPath = process.execPath, shiftId, logDir) {
|
|
153
|
+
export function buildSpawnPlan(spec, origin, account, binPath, execPath = process.execPath, shiftId, logDir, allowedWorkdirRoots) {
|
|
144
154
|
const role = spec.kind === 'agent-run' ? 'agent-run' : 'exec';
|
|
145
155
|
return {
|
|
146
156
|
command: execPath,
|
|
@@ -160,6 +170,9 @@ export function buildSpawnPlan(spec, origin, account, binPath, execPath = proces
|
|
|
160
170
|
...process.env,
|
|
161
171
|
OWENLOOP_ACCOUNT: account,
|
|
162
172
|
...(spec.startGate !== undefined ? { OWENLOOP_START_GATE: spec.startGate } : {}),
|
|
173
|
+
...(allowedWorkdirRoots !== undefined && allowedWorkdirRoots.length > 0
|
|
174
|
+
? { OWENLOOP_ALLOWED_WORKDIR_ROOTS: allowedWorkdirRoots.join(':') }
|
|
175
|
+
: {}),
|
|
163
176
|
},
|
|
164
177
|
},
|
|
165
178
|
...(logDir !== undefined && logDir !== '' ? { logFile: runLogFile(logDir, spec.run) } : {}),
|
|
@@ -173,7 +186,7 @@ export function buildSpawnPlan(spec, origin, account, binPath, execPath = proces
|
|
|
173
186
|
* relying on `buildSpawnPlan`'s default) so `shiftId` — trailing after it
|
|
174
187
|
* — can be supplied positionally.
|
|
175
188
|
*/
|
|
176
|
-
export function createDefaultSpawner(origin, account, binPath = resolveOwenloopBin(), shiftId, onFailure, logging) {
|
|
189
|
+
export function createDefaultSpawner(origin, account, binPath = resolveOwenloopBin(), shiftId, onFailure, logging, allowedWorkdirRoots) {
|
|
177
190
|
// ONE report per shift, not one per dispatch. Every condition that stops a
|
|
178
191
|
// worker log from opening — a full disk, a read-only log directory, an
|
|
179
192
|
// operator deleting it underneath a running shift — PERSISTS across the
|
|
@@ -189,7 +202,7 @@ export function createDefaultSpawner(origin, account, binPath = resolveOwenloopB
|
|
|
189
202
|
logging?.err?.(line);
|
|
190
203
|
};
|
|
191
204
|
return (spec) => {
|
|
192
|
-
const plan = buildSpawnPlan(spec, origin, account, binPath, process.execPath, shiftId, logging?.dir);
|
|
205
|
+
const plan = buildSpawnPlan(spec, origin, account, binPath, process.execPath, shiftId, logging?.dir, allowedWorkdirRoots);
|
|
193
206
|
// Open the log ONCE and hand the SAME descriptor to slots 1 and 2. Opening
|
|
194
207
|
// it twice would create two independent file offsets, and the two streams
|
|
195
208
|
// would overwrite each other's bytes — silent corruption no unit test on the
|
package/dist/src/cli.js
CHANGED
|
@@ -1125,6 +1125,14 @@ ${' '.repeat(41)}start a published workflow on the bound hub (human credential)
|
|
|
1125
1125
|
${' '.repeat(41)}--modifier names one value from the def's declared \`modifiers:\` set; every
|
|
1126
1126
|
${' '.repeat(41)}step's capability is then offered as \`<capability>:<modifier>\`. Omit it and
|
|
1127
1127
|
${' '.repeat(41)}the run carries no modifier and its steps are offered on BARE capabilities.
|
|
1128
|
+
cancel <workflow> [--reason <text>] [--hub <url>]
|
|
1129
|
+
${' '.repeat(41)}cancel a running instance on the bound hub (human credential; agents cannot cancel).
|
|
1130
|
+
${' '.repeat(41)}Closes every open lease so the run stops being re-offered, and records the
|
|
1131
|
+
${' '.repeat(41)}terminal status \`cancelled\`. Cancelling an already-terminal instance is a no-op.
|
|
1132
|
+
instance show <workflow> [--hub <url>]
|
|
1133
|
+
${' '.repeat(41)}print one instance's live state on the bound hub: whether it is done, what it
|
|
1134
|
+
${' '.repeat(41)}owes, which steps are eligible or blocked, which runs are in flight, and whether
|
|
1135
|
+
${' '.repeat(41)}the loaded def has drifted from the version the instance is pinned to.
|
|
1128
1136
|
agent new <name> [--crews <a,b>] [--scopes <a,b>] [--shift] [--hub <url>] mint a new Scoped Identity on the hub and store its token in slot agent:<name> (the token is never printed; --shift = --scopes work,run)
|
|
1129
1137
|
capability bind <capability> <crew> [--hub <url>] add a crew to a workflow capability on the hub org — a capability may bind many crews (admin; human credential)
|
|
1130
1138
|
capability unbind <capability> <crew> [--hub <url>] remove one (capability, crew) route
|
|
@@ -1163,7 +1171,9 @@ ${' '.repeat(41)}the run carries no modifier and its steps are offered on BARE c
|
|
|
1163
1171
|
reject <wf> <path> --by <author> --text <msg>
|
|
1164
1172
|
retract <wf> <path> --by <author> --text <msg>
|
|
1165
1173
|
skip <wf> <path> --by <author> --text <msg>
|
|
1166
|
-
retry <wf> <path> [--by <author>] [--text <guidance>] clear a §6 stall
|
|
1174
|
+
retry <wf> <path> [--by <author>] [--text <guidance>] clear a §6 stall, or ANSWER an ask
|
|
1175
|
+
ask <wf> <path> <question> [--by <author>] hold an owed artifact on a question for a human
|
|
1176
|
+
inbox every held question across all instances, with its answer command
|
|
1167
1177
|
heartbeat <wf> <run> [--now <ms>] touch liveness timestamp on an open run
|
|
1168
1178
|
close <wf> <run> [--outcome ok|no_work|failed|skipped] [--summary s]
|
|
1169
1179
|
delete <wf> [--recursive] refuse if children exist unless --recursive (cascades)
|
|
@@ -1214,6 +1224,8 @@ export const COMMAND_OPTIONS = new Map([
|
|
|
1214
1224
|
['trust', cmdOpts('force', 'key', 'principal', 'pools', 'labels', 'namespaces', 'delegate', 'signing-key', 'output', 'reason', 'effective-from')],
|
|
1215
1225
|
['push', cmdOpts('dry-run', 'force', 'hub', 'as', 'bundle')],
|
|
1216
1226
|
['start', cmdOpts('hub', 'crew', 'title', 'provide', 'modifier')],
|
|
1227
|
+
['cancel', cmdOpts('hub', 'reason')],
|
|
1228
|
+
['instance', cmdOpts('hub')],
|
|
1217
1229
|
['agent', cmdOpts('crews', 'hub', 'scopes', 'shift')],
|
|
1218
1230
|
['capability', cmdOpts('hub')],
|
|
1219
1231
|
['crew', cmdOpts('hub', 'kind', 'owner')],
|
|
@@ -1244,6 +1256,8 @@ export const COMMAND_OPTIONS = new Map([
|
|
|
1244
1256
|
['retract', cmdOpts('by', 'text')],
|
|
1245
1257
|
['skip', cmdOpts('by', 'text')],
|
|
1246
1258
|
['retry', cmdOpts('by', 'text')],
|
|
1259
|
+
['ask', cmdOpts('by', 'question')],
|
|
1260
|
+
['inbox', cmdOpts()],
|
|
1247
1261
|
['close', cmdOpts('outcome', 'summary')],
|
|
1248
1262
|
['heartbeat', cmdOpts('now')],
|
|
1249
1263
|
['delete', cmdOpts('recursive')],
|
|
@@ -1864,6 +1878,55 @@ function dispatch(command, io, args) {
|
|
|
1864
1878
|
print(io, { ok: true, action: 'retry', path });
|
|
1865
1879
|
return 0;
|
|
1866
1880
|
}
|
|
1881
|
+
case 'ask': {
|
|
1882
|
+
// The escalation verb: the producing step stops and asks a human about
|
|
1883
|
+
// the artifact IT owes. The answer is a plain `retry --text "<answer>"`
|
|
1884
|
+
// — deliberately no `answer` verb, because `retry` already appends a
|
|
1885
|
+
// structural reason, which is exactly what clears the hold and delivers
|
|
1886
|
+
// the text to the next attempt.
|
|
1887
|
+
const wf = need(args, 1, 'workflow');
|
|
1888
|
+
const path = need(args, 2, 'path');
|
|
1889
|
+
const question = need(args, 3, 'question');
|
|
1890
|
+
engine.ask(wf, path, last(args, 'by') ?? 'human', question);
|
|
1891
|
+
print(io, { ok: true, action: 'ask', path, question });
|
|
1892
|
+
return 0;
|
|
1893
|
+
}
|
|
1894
|
+
case 'inbox': {
|
|
1895
|
+
// THE OPERATOR SURFACE for `ask`. Without it the channel is write-only:
|
|
1896
|
+
// a step can raise a question and nothing ever displays it, which is
|
|
1897
|
+
// the exact failure this whole change exists to end. Reads the LOCAL db
|
|
1898
|
+
// across every instance (no workflow argument) because a person asking
|
|
1899
|
+
// "is anything waiting on me?" does not know which instance to name.
|
|
1900
|
+
//
|
|
1901
|
+
// Each row carries the ready-to-paste release command, because the
|
|
1902
|
+
// answer path (`retry --text`) is not guessable from the question.
|
|
1903
|
+
const rows = [];
|
|
1904
|
+
for (const w of store.listWorkflows()) {
|
|
1905
|
+
let st;
|
|
1906
|
+
try {
|
|
1907
|
+
st = engine.status(w.id);
|
|
1908
|
+
}
|
|
1909
|
+
catch {
|
|
1910
|
+
// An instance whose def no longer resolves cannot be asked about;
|
|
1911
|
+
// skip it rather than aborting the sweep (same stance as `--all`).
|
|
1912
|
+
continue;
|
|
1913
|
+
}
|
|
1914
|
+
for (const d of st.debts) {
|
|
1915
|
+
if (d.question === undefined)
|
|
1916
|
+
continue;
|
|
1917
|
+
rows.push({
|
|
1918
|
+
workflow: w.id,
|
|
1919
|
+
def: w.def,
|
|
1920
|
+
title: w.title ?? null,
|
|
1921
|
+
path: d.path,
|
|
1922
|
+
question: d.question,
|
|
1923
|
+
answer: `owenloop retry ${w.id} ${d.path} --text "<your answer>"`,
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
print(io, rows);
|
|
1928
|
+
return 0;
|
|
1929
|
+
}
|
|
1867
1930
|
case 'close': {
|
|
1868
1931
|
const wf = need(args, 1, 'workflow');
|
|
1869
1932
|
const run = need(args, 2, 'run');
|
|
@@ -3884,11 +3947,11 @@ async function dispatchPush(io, args) {
|
|
|
3884
3947
|
}
|
|
3885
3948
|
}
|
|
3886
3949
|
/**
|
|
3887
|
-
* Resolve the hub for `start` without ever
|
|
3888
|
-
* default or an ambient `OWENLOOP_HUB`. A
|
|
3889
|
-
* durable default. `--hub` is allowed for an
|
|
3890
|
-
* with an existing binding so a copied
|
|
3891
|
-
* the wrong control plane.
|
|
3950
|
+
* Resolve the hub for the per-run commands (`start`, `cancel`) without ever
|
|
3951
|
+
* falling through to the production default or an ambient `OWENLOOP_HUB`. A
|
|
3952
|
+
* connected project supplies the durable default. `--hub` is allowed for an
|
|
3953
|
+
* unbound directory, but must agree with an existing binding so a copied
|
|
3954
|
+
* command cannot silently start — or cancel — a run on the wrong control plane.
|
|
3892
3955
|
*/
|
|
3893
3956
|
function resolveStartHub(io, args) {
|
|
3894
3957
|
const binding = readHubBinding(hubBindingPath(io.cwd));
|
|
@@ -4023,6 +4086,189 @@ async function dispatchStart(io, args) {
|
|
|
4023
4086
|
});
|
|
4024
4087
|
return 0;
|
|
4025
4088
|
}
|
|
4089
|
+
/**
|
|
4090
|
+
* `owenloop cancel` — stop a running instance from the terminal.
|
|
4091
|
+
*
|
|
4092
|
+
* The counterpart to `start`, and the only local way out of a run that can no
|
|
4093
|
+
* longer make progress: a step whose worktree was deleted, or an instance
|
|
4094
|
+
* pinned to a def version its shift can no longer satisfy. Without this, such a
|
|
4095
|
+
* run is re-offered forever and permanently occupies one of a shift's dispatch
|
|
4096
|
+
* slots, because nothing else on this machine can move it to a terminal state.
|
|
4097
|
+
*
|
|
4098
|
+
* Three properties of the hub verb this command deliberately surfaces rather
|
|
4099
|
+
* than hides (`hub-core/src/verbs/cancel-run.ts`):
|
|
4100
|
+
*
|
|
4101
|
+
* - It is HUMAN-ROLE-ONLY. `cancel_run` has no agent-scope entry, so an agent
|
|
4102
|
+
* credential is refused by the hub. This command therefore never consults
|
|
4103
|
+
* `--as` and always reads the `human` slot — offering `--as` would only
|
|
4104
|
+
* produce a 403 further down.
|
|
4105
|
+
* - It is IDEMPOTENT. Cancelling an instance that already reached a terminal
|
|
4106
|
+
* state returns `cancelled: false` plus that state, and writes nothing. That
|
|
4107
|
+
* is a success, not an error, so it exits 0 — a retried cancel must not look
|
|
4108
|
+
* like a failure.
|
|
4109
|
+
* - Its receipt records `outcome: 'failed'`, because the receipt union is only
|
|
4110
|
+
* `done|failed`. The true cancel fact lives in the instance's distinct
|
|
4111
|
+
* `cancelled` status and an `action: 'cancel'` audit row. We print the
|
|
4112
|
+
* status, not the receipt outcome, so the output does not imply the run
|
|
4113
|
+
* failed on its own.
|
|
4114
|
+
*/
|
|
4115
|
+
async function dispatchCancel(io, args) {
|
|
4116
|
+
const workflow = need(args, 1, 'workflow');
|
|
4117
|
+
if (args.missingOptionValues.has('reason')) {
|
|
4118
|
+
throw new CliError('missing value for --reason: expected --reason <text>');
|
|
4119
|
+
}
|
|
4120
|
+
const reason = last(args, 'reason');
|
|
4121
|
+
if (reason !== undefined && reason.trim() === '') {
|
|
4122
|
+
throw new CliError('invalid empty value for --reason: expected --reason <text>');
|
|
4123
|
+
}
|
|
4124
|
+
const origin = resolveStartHub(io, args);
|
|
4125
|
+
const slot = { principal: 'human' };
|
|
4126
|
+
const cred = readCredential(io, origin, slot);
|
|
4127
|
+
if (cred === null) {
|
|
4128
|
+
throw new CliError(`no human credential for ${origin} — run: owenloop login --hub ${origin}`, { exitCode: 3 });
|
|
4129
|
+
}
|
|
4130
|
+
const request = {
|
|
4131
|
+
workflow,
|
|
4132
|
+
...(reason !== undefined ? { reason } : {}),
|
|
4133
|
+
};
|
|
4134
|
+
const { res, cred: used } = await authedPost(io, origin, slot, cred, '/api/cancel_run', request);
|
|
4135
|
+
if (res.status === 401)
|
|
4136
|
+
assertAuthOk(res, used, origin);
|
|
4137
|
+
if (!res.ok) {
|
|
4138
|
+
const message = await hubRequestMessage(res);
|
|
4139
|
+
throw new CliError(message ?? `hub ${origin} rejected the request (HTTP ${res.status})`);
|
|
4140
|
+
}
|
|
4141
|
+
let body;
|
|
4142
|
+
try {
|
|
4143
|
+
body = (await res.json());
|
|
4144
|
+
}
|
|
4145
|
+
catch {
|
|
4146
|
+
throw new CliError('cancel_run: malformed success response — body is not valid JSON');
|
|
4147
|
+
}
|
|
4148
|
+
if (typeof body !== 'object' || body === null || Array.isArray(body)) {
|
|
4149
|
+
throw new CliError('cancel_run: malformed success response — body is not an object');
|
|
4150
|
+
}
|
|
4151
|
+
const wire = body;
|
|
4152
|
+
if (typeof wire.cancelled !== 'boolean') {
|
|
4153
|
+
throw new CliError('cancel_run: malformed success response — missing cancelled flag');
|
|
4154
|
+
}
|
|
4155
|
+
print(io, {
|
|
4156
|
+
ok: true,
|
|
4157
|
+
hub: origin,
|
|
4158
|
+
workflow,
|
|
4159
|
+
cancelled: wire.cancelled,
|
|
4160
|
+
// Present only on the already-terminal path, where the hub reports the state
|
|
4161
|
+
// it found instead of the one it set. On the cancelling path the status is
|
|
4162
|
+
// `cancelled` by construction, so we state it rather than inventing a field
|
|
4163
|
+
// the hub did not send.
|
|
4164
|
+
status: typeof wire.status === 'string' ? wire.status : 'cancelled',
|
|
4165
|
+
// The runs whose leases were closed. Absent on the no-op path.
|
|
4166
|
+
...(Array.isArray(wire.closedRuns) ? { closedRuns: wire.closedRuns } : {}),
|
|
4167
|
+
...(reason !== undefined ? { reason } : {}),
|
|
4168
|
+
});
|
|
4169
|
+
return 0;
|
|
4170
|
+
}
|
|
4171
|
+
/**
|
|
4172
|
+
* `owenloop instance` — read a HUB instance's live state from the terminal.
|
|
4173
|
+
*
|
|
4174
|
+
* The read counterpart to `start` and `cancel`. Two naming constraints forced
|
|
4175
|
+
* this word, and both are collisions with commands that already exist:
|
|
4176
|
+
*
|
|
4177
|
+
* - NOT `status`. `owenloop status` is the LOCAL engine's status and takes
|
|
4178
|
+
* `--db`; it has no hub credential and rejects `--hub`.
|
|
4179
|
+
* - NOT `runs`. `owenloop runs <workflow> [--open]` already lists runs out of
|
|
4180
|
+
* the LOCAL sqlite store. Reusing it would have silently rerouted a local
|
|
4181
|
+
* command to the network.
|
|
4182
|
+
*
|
|
4183
|
+
* `instance` is the hub's own term for a started workflow — `setInstanceStatus`,
|
|
4184
|
+
* `listInstancesWithStatus`, and `cancel_run`'s own "already-terminal instance"
|
|
4185
|
+
* all use it — so a hub instance and a local run stay distinct objects with
|
|
4186
|
+
* distinct commands rather than one command whose meaning flips on a flag.
|
|
4187
|
+
*
|
|
4188
|
+
* Only `show` exists today, and that is a hub limitation rather than a design
|
|
4189
|
+
* choice. `getStatus` is the one instance-read verb with a REST route
|
|
4190
|
+
* (`GET /api/status/:wf`). The verb that lists instances,
|
|
4191
|
+
* `listInstancesWithStatus`, and the two that carry receipt bodies —
|
|
4192
|
+
* `listReceipts` and `getReceiptDetail`, which is where a reviewer's reject
|
|
4193
|
+
* reason actually lives — are exposed only over tRPC for the console. Adding
|
|
4194
|
+
* `instance list`, or any command that can print WHY a step was rejected,
|
|
4195
|
+
* therefore requires new routes on `apps/hub-edge/src/api/routes.ts` and a hub
|
|
4196
|
+
* deploy; it is not something this CLI can reach today. The subcommand form
|
|
4197
|
+
* exists so those arrive as `instance list` without renaming anything.
|
|
4198
|
+
*
|
|
4199
|
+
* Like `cancel`, this reads the `human` slot and never consults `--as`, and it
|
|
4200
|
+
* resolves the hub through `resolveStartHub` so an ambient `OWENLOOP_HUB` can
|
|
4201
|
+
* never silently redirect the read to a different control plane than the one
|
|
4202
|
+
* the project is bound to.
|
|
4203
|
+
*/
|
|
4204
|
+
async function dispatchInstance(io, args) {
|
|
4205
|
+
const USAGE_FORMS = 'usage: owenloop instance show <workflow> [--hub <url>]';
|
|
4206
|
+
const sub = args.positionals[1];
|
|
4207
|
+
if (sub !== 'show') {
|
|
4208
|
+
throw new CliError(`unknown instance subcommand '${sub ?? ''}' — ${USAGE_FORMS}`);
|
|
4209
|
+
}
|
|
4210
|
+
const workflow = args.positionals[2];
|
|
4211
|
+
if (workflow === undefined || workflow === '') {
|
|
4212
|
+
throw new CliError(`missing required argument: workflow (${USAGE_FORMS})`);
|
|
4213
|
+
}
|
|
4214
|
+
const origin = resolveStartHub(io, args);
|
|
4215
|
+
const slot = { principal: 'human' };
|
|
4216
|
+
const cred = readCredential(io, origin, slot);
|
|
4217
|
+
if (cred === null) {
|
|
4218
|
+
throw new CliError(`no human credential for ${origin} — run: owenloop login --hub ${origin}`, { exitCode: 3 });
|
|
4219
|
+
}
|
|
4220
|
+
// The workflow id is a path segment, so it must be encoded — an id carrying a
|
|
4221
|
+
// slash would otherwise silently address a different route.
|
|
4222
|
+
const path = `/api/status/${encodeURIComponent(workflow)}`;
|
|
4223
|
+
const { res, cred: used } = await authedGet(io, origin, slot, cred, path);
|
|
4224
|
+
if (res.status === 401)
|
|
4225
|
+
assertAuthOk(res, used, origin);
|
|
4226
|
+
if (!res.ok) {
|
|
4227
|
+
const message = await hubRequestMessage(res);
|
|
4228
|
+
throw new CliError(message ?? `hub ${origin} rejected the request (HTTP ${res.status})`);
|
|
4229
|
+
}
|
|
4230
|
+
let body;
|
|
4231
|
+
try {
|
|
4232
|
+
body = (await res.json());
|
|
4233
|
+
}
|
|
4234
|
+
catch {
|
|
4235
|
+
throw new CliError('get_status: malformed success response — body is not valid JSON');
|
|
4236
|
+
}
|
|
4237
|
+
if (typeof body !== 'object' || body === null || Array.isArray(body)) {
|
|
4238
|
+
throw new CliError('get_status: malformed success response — body is not an object');
|
|
4239
|
+
}
|
|
4240
|
+
const wire = body;
|
|
4241
|
+
// `done` is the one field every status carries and the one a script branches
|
|
4242
|
+
// on, so its absence means we are not looking at a status at all. Refuse
|
|
4243
|
+
// rather than print a shape that reads as "not done".
|
|
4244
|
+
if (typeof wire.done !== 'boolean') {
|
|
4245
|
+
throw new CliError('get_status: malformed success response — missing done flag');
|
|
4246
|
+
}
|
|
4247
|
+
const arrayOr = (value) => (Array.isArray(value) ? value : []);
|
|
4248
|
+
print(io, {
|
|
4249
|
+
ok: true,
|
|
4250
|
+
hub: origin,
|
|
4251
|
+
workflow,
|
|
4252
|
+
done: wire.done,
|
|
4253
|
+
// Owed inputs the instance is waiting on, each with its acceptance and
|
|
4254
|
+
// whether the engine considers it stalled.
|
|
4255
|
+
debts: arrayOr(wire.debts),
|
|
4256
|
+
// Steps that could be dispatched now, and steps whose preconditions are not
|
|
4257
|
+
// met yet. A run that is neither done nor eligible nor in flight is stuck.
|
|
4258
|
+
eligible: arrayOr(wire.eligible),
|
|
4259
|
+
blocked: arrayOr(wire.blocked),
|
|
4260
|
+
inFlight: arrayOr(wire.inFlight),
|
|
4261
|
+
// True when the def loaded on the hub has moved on from the snapshot this
|
|
4262
|
+
// instance is pinned to. A pinned instance never picks up the new version,
|
|
4263
|
+
// so this is the field that explains "I published a fix and the run still
|
|
4264
|
+
// does the old thing".
|
|
4265
|
+
defDrift: wire.defDrift === true,
|
|
4266
|
+
// Present only when a step's capability has no crew bound to it, which
|
|
4267
|
+
// looks identical to "nothing is picking this up" from the outside.
|
|
4268
|
+
...(Array.isArray(wire.waitingOnCapabilities) ? { waitingOnCapabilities: wire.waitingOnCapabilities } : {}),
|
|
4269
|
+
});
|
|
4270
|
+
return 0;
|
|
4271
|
+
}
|
|
4026
4272
|
/**
|
|
4027
4273
|
* `owenloop mcp` — serve the human control plane to a local MCP host over stdio.
|
|
4028
4274
|
* A thin adapter: read the optional `--hub <url>` flag and hand `io` (which
|
|
@@ -5888,7 +6134,7 @@ async function runDoctor(io, origin) {
|
|
|
5888
6134
|
* the async path, so every existing command and test keeps working exactly as
|
|
5889
6135
|
* before.
|
|
5890
6136
|
*/
|
|
5891
|
-
export const ASYNC_COMMANDS = new Set(['add', 'login', 'logout', 'connect', 'publish', 'trust', 'push', 'start', 'agent', 'capability', 'crew', 'setup', 'doctor', 'enrollments', 'mcp', 'shift']);
|
|
6137
|
+
export const ASYNC_COMMANDS = new Set(['add', 'login', 'logout', 'connect', 'publish', 'trust', 'push', 'start', 'cancel', 'instance', 'agent', 'capability', 'crew', 'setup', 'doctor', 'enrollments', 'mcp', 'shift']);
|
|
5892
6138
|
export async function mainAsync(argv, io = defaultIO()) {
|
|
5893
6139
|
// Delegate execution-side and shift argv tails before root parsing. Their
|
|
5894
6140
|
// roles own their option grammars, including repeated/value forms that the
|
|
@@ -5934,6 +6180,10 @@ export async function mainAsync(argv, io = defaultIO()) {
|
|
|
5934
6180
|
return await dispatchPush(io, args);
|
|
5935
6181
|
case 'start':
|
|
5936
6182
|
return await dispatchStart(io, args);
|
|
6183
|
+
case 'cancel':
|
|
6184
|
+
return await dispatchCancel(io, args);
|
|
6185
|
+
case 'instance':
|
|
6186
|
+
return await dispatchInstance(io, args);
|
|
5937
6187
|
case 'agent':
|
|
5938
6188
|
return await dispatchAgent(io, args);
|
|
5939
6189
|
case 'capability':
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE resolver for owenloop's own user-level config directory — the
|
|
3
|
+
* directory that directly holds `settings.json`, `credentials.json`,
|
|
4
|
+
* `allowed_signers`, `org-root.pub`, `roster/`, and `revocations/`.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS MODULE EXISTS. Until now four call sites each re-derived the same
|
|
7
|
+
* ladder — `$XDG_CONFIG_HOME/owenloop` else `$HOME/.config/owenloop` — and
|
|
8
|
+
* `XDG_CONFIG_HOME` was therefore the ONLY lever an operator had for pointing
|
|
9
|
+
* one owenloop process at a different settings file than another. That lever is
|
|
10
|
+
* not owenloop's to take. `XDG_CONFIG_HOME` is a machine-wide contract that
|
|
11
|
+
* `gh`, `git`, `gcloud`, `npm`, and most of the rest of a developer's toolchain
|
|
12
|
+
* also read, and `owenloop shift start` spreads its whole environment into
|
|
13
|
+
* every worker it dispatches (`shift/spawn.ts`), which in turn passes it to
|
|
14
|
+
* every command step's child process (`exec/` sets exactly three variables of
|
|
15
|
+
* its own on top). So an operator running two shifts with different
|
|
16
|
+
* `capabilityModels` had to set `XDG_CONFIG_HOME` per shift, and that silently
|
|
17
|
+
* relocated the config of every other tool the workflow's scripts shell out to.
|
|
18
|
+
*
|
|
19
|
+
* MEASURED, not theorized. On run `wf_8b2abe6b` the delivery line's `merge-gate`
|
|
20
|
+
* and `merger` steps both failed inside their `gh` probes, because `gh` looked
|
|
21
|
+
* for `hosts.yml` under the shift profile's `XDG_CONFIG_HOME` and found no
|
|
22
|
+
* credential there. `merge-gate` burned its full 40-minute wall clock deferring
|
|
23
|
+
* on a fail-open CI verdict; `merger` then failed four times running with
|
|
24
|
+
* `could not resolve a pull request handle for the branch`. Both probes returned
|
|
25
|
+
* the correct answer the instant they were run with the operator's real
|
|
26
|
+
* `XDG_CONFIG_HOME`. Nothing was wrong with either script.
|
|
27
|
+
*
|
|
28
|
+
* THE FIX IS AN OWENLOOP-SPECIFIC VARIABLE. `OWENLOOP_CONFIG_DIR` names the
|
|
29
|
+
* owenloop config directory ITSELF — no `owenloop` path segment is appended to
|
|
30
|
+
* it — so an operator can scope owenloop's config per process while leaving
|
|
31
|
+
* `XDG_CONFIG_HOME` alone for everything else:
|
|
32
|
+
*
|
|
33
|
+
* OWENLOOP_CONFIG_DIR=~/.config/owenloop-shifts/utility/owenloop \
|
|
34
|
+
* owenloop shift start utility …
|
|
35
|
+
*
|
|
36
|
+
* PRECEDENCE, highest first:
|
|
37
|
+
* 1. `OWENLOOP_CONFIG_DIR` → used verbatim
|
|
38
|
+
* 2. `XDG_CONFIG_HOME` → `<xdg>/owenloop`
|
|
39
|
+
* 3. `HOME` → `<home>/.config/owenloop`
|
|
40
|
+
* Blank or whitespace-only values are treated as unset at every rung, matching
|
|
41
|
+
* the behaviour the four previous copies already had for `XDG_CONFIG_HOME`.
|
|
42
|
+
*
|
|
43
|
+
* ABSOLUTE PATHS ONLY. A relative `OWENLOOP_CONFIG_DIR` would resolve against
|
|
44
|
+
* whatever the current working directory happens to be, and a worker's cwd
|
|
45
|
+
* changes per step (`workdirFrom` points each step at its own worktree). That
|
|
46
|
+
* is the same class of ambient-state bug this module exists to remove, so a
|
|
47
|
+
* relative value is a hard error naming the variable rather than a path that
|
|
48
|
+
* silently means something different in every step.
|
|
49
|
+
*
|
|
50
|
+
* Imports node builtins only. Both closures — the root CLI under `src/` and the
|
|
51
|
+
* execution engine under `packages/work/src/` — import this module directly, so
|
|
52
|
+
* the ladder cannot drift between them again.
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Resolve owenloop's user-level config directory from caller-supplied env.
|
|
56
|
+
*
|
|
57
|
+
* Throws when no rung of the ladder yields a value, rather than guessing a home
|
|
58
|
+
* directory from the ambient process.
|
|
59
|
+
*/
|
|
60
|
+
export declare function owenloopConfigDir(env: Record<string, string | undefined>): string;
|
|
61
|
+
/** A file inside owenloop's config directory. */
|
|
62
|
+
export declare function owenloopConfigFile(env: Record<string, string | undefined>, ...segments: string[]): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE resolver for owenloop's own user-level config directory — the
|
|
3
|
+
* directory that directly holds `settings.json`, `credentials.json`,
|
|
4
|
+
* `allowed_signers`, `org-root.pub`, `roster/`, and `revocations/`.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS MODULE EXISTS. Until now four call sites each re-derived the same
|
|
7
|
+
* ladder — `$XDG_CONFIG_HOME/owenloop` else `$HOME/.config/owenloop` — and
|
|
8
|
+
* `XDG_CONFIG_HOME` was therefore the ONLY lever an operator had for pointing
|
|
9
|
+
* one owenloop process at a different settings file than another. That lever is
|
|
10
|
+
* not owenloop's to take. `XDG_CONFIG_HOME` is a machine-wide contract that
|
|
11
|
+
* `gh`, `git`, `gcloud`, `npm`, and most of the rest of a developer's toolchain
|
|
12
|
+
* also read, and `owenloop shift start` spreads its whole environment into
|
|
13
|
+
* every worker it dispatches (`shift/spawn.ts`), which in turn passes it to
|
|
14
|
+
* every command step's child process (`exec/` sets exactly three variables of
|
|
15
|
+
* its own on top). So an operator running two shifts with different
|
|
16
|
+
* `capabilityModels` had to set `XDG_CONFIG_HOME` per shift, and that silently
|
|
17
|
+
* relocated the config of every other tool the workflow's scripts shell out to.
|
|
18
|
+
*
|
|
19
|
+
* MEASURED, not theorized. On run `wf_8b2abe6b` the delivery line's `merge-gate`
|
|
20
|
+
* and `merger` steps both failed inside their `gh` probes, because `gh` looked
|
|
21
|
+
* for `hosts.yml` under the shift profile's `XDG_CONFIG_HOME` and found no
|
|
22
|
+
* credential there. `merge-gate` burned its full 40-minute wall clock deferring
|
|
23
|
+
* on a fail-open CI verdict; `merger` then failed four times running with
|
|
24
|
+
* `could not resolve a pull request handle for the branch`. Both probes returned
|
|
25
|
+
* the correct answer the instant they were run with the operator's real
|
|
26
|
+
* `XDG_CONFIG_HOME`. Nothing was wrong with either script.
|
|
27
|
+
*
|
|
28
|
+
* THE FIX IS AN OWENLOOP-SPECIFIC VARIABLE. `OWENLOOP_CONFIG_DIR` names the
|
|
29
|
+
* owenloop config directory ITSELF — no `owenloop` path segment is appended to
|
|
30
|
+
* it — so an operator can scope owenloop's config per process while leaving
|
|
31
|
+
* `XDG_CONFIG_HOME` alone for everything else:
|
|
32
|
+
*
|
|
33
|
+
* OWENLOOP_CONFIG_DIR=~/.config/owenloop-shifts/utility/owenloop \
|
|
34
|
+
* owenloop shift start utility …
|
|
35
|
+
*
|
|
36
|
+
* PRECEDENCE, highest first:
|
|
37
|
+
* 1. `OWENLOOP_CONFIG_DIR` → used verbatim
|
|
38
|
+
* 2. `XDG_CONFIG_HOME` → `<xdg>/owenloop`
|
|
39
|
+
* 3. `HOME` → `<home>/.config/owenloop`
|
|
40
|
+
* Blank or whitespace-only values are treated as unset at every rung, matching
|
|
41
|
+
* the behaviour the four previous copies already had for `XDG_CONFIG_HOME`.
|
|
42
|
+
*
|
|
43
|
+
* ABSOLUTE PATHS ONLY. A relative `OWENLOOP_CONFIG_DIR` would resolve against
|
|
44
|
+
* whatever the current working directory happens to be, and a worker's cwd
|
|
45
|
+
* changes per step (`workdirFrom` points each step at its own worktree). That
|
|
46
|
+
* is the same class of ambient-state bug this module exists to remove, so a
|
|
47
|
+
* relative value is a hard error naming the variable rather than a path that
|
|
48
|
+
* silently means something different in every step.
|
|
49
|
+
*
|
|
50
|
+
* Imports node builtins only. Both closures — the root CLI under `src/` and the
|
|
51
|
+
* execution engine under `packages/work/src/` — import this module directly, so
|
|
52
|
+
* the ladder cannot drift between them again.
|
|
53
|
+
*/
|
|
54
|
+
import { isAbsolute, join } from 'node:path';
|
|
55
|
+
/** Read an env var, treating blank and whitespace-only as unset. */
|
|
56
|
+
function present(value) {
|
|
57
|
+
if (value === undefined)
|
|
58
|
+
return undefined;
|
|
59
|
+
return value.trim() === '' ? undefined : value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolve owenloop's user-level config directory from caller-supplied env.
|
|
63
|
+
*
|
|
64
|
+
* Throws when no rung of the ladder yields a value, rather than guessing a home
|
|
65
|
+
* directory from the ambient process.
|
|
66
|
+
*/
|
|
67
|
+
export function owenloopConfigDir(env) {
|
|
68
|
+
const explicit = present(env.OWENLOOP_CONFIG_DIR);
|
|
69
|
+
if (explicit !== undefined) {
|
|
70
|
+
if (!isAbsolute(explicit)) {
|
|
71
|
+
throw new Error(`OWENLOOP_CONFIG_DIR must be an absolute path, received ${JSON.stringify(explicit)} — ` +
|
|
72
|
+
'a relative config dir resolves against each step\'s own working directory');
|
|
73
|
+
}
|
|
74
|
+
return explicit;
|
|
75
|
+
}
|
|
76
|
+
const xdg = present(env.XDG_CONFIG_HOME);
|
|
77
|
+
if (xdg !== undefined)
|
|
78
|
+
return join(xdg, 'owenloop');
|
|
79
|
+
const home = present(env.HOME);
|
|
80
|
+
if (home !== undefined)
|
|
81
|
+
return join(home, '.config', 'owenloop');
|
|
82
|
+
throw new Error('cannot locate a config directory: set OWENLOOP_CONFIG_DIR, XDG_CONFIG_HOME, or HOME');
|
|
83
|
+
}
|
|
84
|
+
/** A file inside owenloop's config directory. */
|
|
85
|
+
export function owenloopConfigFile(env, ...segments) {
|
|
86
|
+
return join(owenloopConfigDir(env), ...segments);
|
|
87
|
+
}
|