owenloop 0.5.2 → 0.5.4

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 (41) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +6 -2
  3. package/dist/packages/work/src/agent/brief.d.ts +6 -0
  4. package/dist/packages/work/src/agent/brief.js +46 -2
  5. package/dist/packages/work/src/agent/loop.js +3 -0
  6. package/dist/packages/work/src/exec/loop.js +153 -9
  7. package/dist/packages/work/src/harness/child-env.js +8 -0
  8. package/dist/packages/work/src/harness/claude.js +82 -9
  9. package/dist/packages/work/src/harness/codex.js +63 -8
  10. package/dist/packages/work/src/harness/contract.d.ts +84 -1
  11. package/dist/packages/work/src/harness/contract.js +75 -0
  12. package/dist/packages/work/src/settings/settings.d.ts +12 -4
  13. package/dist/packages/work/src/settings/settings.js +14 -11
  14. package/dist/src/bundle/runtime.d.ts +1 -1
  15. package/dist/src/bundle/runtime.js +9 -0
  16. package/dist/src/cli.js +226 -8
  17. package/dist/src/config-dir.d.ts +62 -0
  18. package/dist/src/config-dir.js +87 -0
  19. package/dist/src/crypto/trust-roots.d.ts +8 -4
  20. package/dist/src/crypto/trust-roots.js +18 -12
  21. package/dist/src/defs.js +57 -16
  22. package/dist/src/engine.js +25 -3
  23. package/dist/src/hub.d.ts +5 -1
  24. package/dist/src/hub.js +7 -8
  25. package/dist/src/paths.d.ts +47 -4
  26. package/dist/src/paths.js +36 -5
  27. package/dist/src/work-settings.d.ts +8 -5
  28. package/dist/src/work-settings.js +15 -12
  29. package/docs/agent-runner.md +26 -1
  30. package/docs/authoring.md +40 -13
  31. package/docs/bundles.md +9 -0
  32. package/docs/cli.md +121 -24
  33. package/docs/crypto.md +8 -8
  34. package/docs/design.md +20 -2
  35. package/docs/embedding.md +5 -4
  36. package/docs/wire-contracts.md +3 -2
  37. package/package.json +1 -1
  38. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
  39. package/plugins/claude-code/plugin/.mcp.json +1 -1
  40. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
  41. package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
@@ -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
+ }
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Resolution of the local SSHSIG trust root used for workflow publications.
3
3
  *
4
- * The path is derived only from injected environment state. XDG_CONFIG_HOME
5
- * wins over HOME, matching the execution settings path; no ambient home
6
- * directory lookup is allowed here. An absent file is a normal result so the
4
+ * The path is derived only from injected environment state, through the shared
5
+ * `owenloopConfigDir` ladder (`OWENLOOP_CONFIG_DIR` > `XDG_CONFIG_HOME` >
6
+ * `HOME`); no ambient home directory lookup is allowed here. An absent file is
7
+ * a normal result so the
7
8
  * publication verifier can classify it as `unverifiable` instead of confusing
8
9
  * a missing trust root with an unsigned bundle.
9
10
  */
@@ -17,7 +18,10 @@ export interface AllowedSignersAbsent {
17
18
  path: string;
18
19
  }
19
20
  export type AllowedSignersResolution = AllowedSignersPresent | AllowedSignersAbsent;
20
- /** Resolve `<config>/owenloop/allowed_signers` from caller-supplied env. */
21
+ /**
22
+ * Resolve `<owenloop config dir>/allowed_signers` from caller-supplied env,
23
+ * through the one shared ladder in `../config-dir.ts`.
24
+ */
21
25
  export declare function allowedSignersPath(env: Record<string, string | undefined>): string;
22
26
  /**
23
27
  * Read the trust root without collapsing absence and malformed contents. A
@@ -1,23 +1,29 @@
1
1
  /**
2
2
  * Resolution of the local SSHSIG trust root used for workflow publications.
3
3
  *
4
- * The path is derived only from injected environment state. XDG_CONFIG_HOME
5
- * wins over HOME, matching the execution settings path; no ambient home
6
- * directory lookup is allowed here. An absent file is a normal result so the
4
+ * The path is derived only from injected environment state, through the shared
5
+ * `owenloopConfigDir` ladder (`OWENLOOP_CONFIG_DIR` > `XDG_CONFIG_HOME` >
6
+ * `HOME`); no ambient home directory lookup is allowed here. An absent file is
7
+ * a normal result so the
7
8
  * publication verifier can classify it as `unverifiable` instead of confusing
8
9
  * a missing trust root with an unsigned bundle.
9
10
  */
10
11
  import { existsSync, lstatSync, readFileSync } from 'node:fs';
11
- import { join } from 'node:path';
12
- /** Resolve `<config>/owenloop/allowed_signers` from caller-supplied env. */
12
+ import { owenloopConfigFile } from "../config-dir.js";
13
+ /**
14
+ * Resolve `<owenloop config dir>/allowed_signers` from caller-supplied env,
15
+ * through the one shared ladder in `../config-dir.ts`.
16
+ */
13
17
  export function allowedSignersPath(env) {
14
- const xdg = env.XDG_CONFIG_HOME;
15
- if (xdg !== undefined && xdg.trim() !== '')
16
- return join(xdg, 'owenloop', 'allowed_signers');
17
- const home = env.HOME;
18
- if (home !== undefined && home.trim() !== '')
19
- return join(home, '.config', 'owenloop', 'allowed_signers');
20
- throw new Error('cannot locate an allowed_signers path: set HOME or XDG_CONFIG_HOME');
18
+ try {
19
+ return owenloopConfigFile(env, 'allowed_signers');
20
+ }
21
+ catch (err) {
22
+ // Keep this resolver's own subject in the message. The shared ladder names
23
+ // the VARIABLES; this prefix names WHICH path could not be located, which
24
+ // is what the publication verifier reports to the operator.
25
+ throw new Error(`cannot locate an allowed_signers path: ${err instanceof Error ? err.message : String(err)}`);
26
+ }
21
27
  }
22
28
  /**
23
29
  * Read the trust root without collapsing absence and malformed contents. A
package/dist/src/defs.js CHANGED
@@ -667,8 +667,15 @@ export function buildDef(raw, source, baseDir) {
667
667
  * Prefix all names/stems in a StepDef with `${prefix}.`. Pure — returns a new StepDef.
668
668
  * Rewrites: step name, consume stems, produce stems, generates stems, invalidates, and
669
669
  * effect.onInvalidate step-name strings (but not 'pin'/'escalate').
670
+ *
671
+ * `defInputs` is the INCLUDED definition's declared input names, unprefixed. A
672
+ * `workdirFrom` stem may name one of those instead of one of the step's own
673
+ * consumes, and that stem is prefixed exactly like a consume stem is, because
674
+ * an unmapped child input is hoisted into the parent under `${prefix}.${name}`.
675
+ * Omitting the list would leave such a stem unparseable here and therefore
676
+ * silently unprefixed, pointing at a stem the expanded definition does not have.
670
677
  */
671
- function prefixStep(step, prefix) {
678
+ function prefixStep(step, prefix, defInputs = []) {
672
679
  const prefixStem = (stem) => `${prefix}.${stem}`;
673
680
  const newConsumes = step.consumes.map((c) => {
674
681
  const stem = prefixStem(c.stem);
@@ -710,11 +717,12 @@ function prefixStep(step, prefix) {
710
717
  // judges: marker names a local stem (unlike calls:, which names an external
711
718
  // workflow) — it must be prefixed to keep pointing at the (now-prefixed) produce.
712
719
  const newJudges = step.judges !== undefined ? prefixStem(step.judges) : undefined;
713
- // workdirFrom names a local consumed stem followed by a dotted value path.
714
- // Prefix only the stem; the value path is a field path inside the consumed value.
720
+ // workdirFrom names a local consumed stem or a declared input of the included
721
+ // definition, followed by a dotted value path. Prefix only the stem; the value
722
+ // path is a field path inside that artifact's value.
715
723
  let newWorkdirFrom = step.workdirFrom;
716
724
  if (step.workdirFrom !== undefined) {
717
- const parsed = parseWorkdirFrom(step.workdirFrom, step.consumes);
725
+ const parsed = parseWorkdirFrom(step.workdirFrom, step.consumes, defInputs);
718
726
  if (parsed)
719
727
  newWorkdirFrom = `${prefixStem(parsed.stem)}.${parsed.path}`;
720
728
  }
@@ -785,7 +793,8 @@ export function expandIncludes(def, resolve, stack) {
785
793
  }
786
794
  }
787
795
  // (e) prefix child steps
788
- const prefixedSteps = child.steps.map((l) => prefixStep(l, inc.as));
796
+ const childInputList = child.inputs.map((inp) => inp.name);
797
+ const prefixedSteps = child.steps.map((l) => prefixStep(l, inc.as, childInputList));
789
798
  // (f) handle inputs: mapped inputs become internal edges; unmapped are hoisted
790
799
  const inputRewrites = new Map(); // prefixed-stem -> outer artifact
791
800
  for (const childInp of child.inputs) {
@@ -800,6 +809,7 @@ export function expandIncludes(def, resolve, stack) {
800
809
  }
801
810
  }
802
811
  // Apply input rewrites to prefixed steps
812
+ const prefixedChildInputStems = child.inputs.map((inp) => `${inc.as}.${inp.name}`);
803
813
  const rewrittenSteps = prefixedSteps.map((l) => {
804
814
  const rewrittenConsumes = l.consumes.map((c) => {
805
815
  const outer = inputRewrites.get(c.stem);
@@ -809,7 +819,19 @@ export function expandIncludes(def, resolve, stack) {
809
819
  }
810
820
  return c;
811
821
  });
812
- return { ...l, consumes: rewrittenConsumes };
822
+ // A workdirFrom stem naming a MAPPED child input has to follow the same
823
+ // rewrite its consumes just took, or it would keep pointing at the
824
+ // child-local stem that this expansion just replaced. Split against the
825
+ // pre-rewrite consumes plus every prefixed child input, because the stem
826
+ // may be either and both are subject to the mapping.
827
+ let rewrittenWorkdirFrom = l.workdirFrom;
828
+ if (l.workdirFrom !== undefined) {
829
+ const parsed = parseWorkdirFrom(l.workdirFrom, l.consumes, prefixedChildInputStems);
830
+ const outer = parsed ? inputRewrites.get(parsed.stem) : undefined;
831
+ if (parsed && outer !== undefined)
832
+ rewrittenWorkdirFrom = `${outer}.${parsed.path}`;
833
+ }
834
+ return { ...l, consumes: rewrittenConsumes, workdirFrom: rewrittenWorkdirFrom };
813
835
  });
814
836
  resultSteps.push(...rewrittenSteps);
815
837
  // (g) merge child outputs
@@ -1103,25 +1125,44 @@ export function validateDef(def) {
1103
1125
  if (l.workdirFrom === undefined)
1104
1126
  continue;
1105
1127
  const raw = l.workdirFrom.trim();
1106
- const bareConsume = l.consumes.find((c) => c.stem === raw);
1107
- if (bareConsume) {
1108
- errors.push(`step '${l.name}': workdirFrom must use '<consumedStem>.<dotted.path>' with a non-empty value path`);
1128
+ // A stem that is itself dotted (`a.b`) would otherwise split into `a` + `b`
1129
+ // and report a confusing missing-stem error, so name the real mistake first:
1130
+ // the expression is a bare artifact name with no value path after it.
1131
+ const bareStem = l.consumes.some((c) => c.stem === raw) || inputNames.has(raw);
1132
+ if (bareStem) {
1133
+ errors.push(`step '${l.name}': workdirFrom must use '<stem>.<dotted.path>' with a non-empty value path`);
1109
1134
  continue;
1110
1135
  }
1111
1136
  const firstDot = raw.indexOf('.');
1112
1137
  const valuePath = firstDot >= 0 ? raw.slice(firstDot + 1) : '';
1113
1138
  if (firstDot <= 0 || valuePath.length === 0) {
1114
- errors.push(`step '${l.name}': workdirFrom must use '<consumedStem>.<dotted.path>' with a non-empty value path`);
1139
+ errors.push(`step '${l.name}': workdirFrom must use '<stem>.<dotted.path>' with a non-empty value path`);
1115
1140
  continue;
1116
1141
  }
1117
- // Security boundary: a workdirFrom value becomes a filesystem path. The
1118
- // source stem must be a plain consumed artifact so its value has passed the
1119
- // engine's consume-side verification gate before a worker can cd into it.
1120
- const parsed = parseWorkdirFrom(raw, l.consumes);
1142
+ // A workdirFrom value becomes a filesystem path, so the stem must name
1143
+ // something this def actually declares: one of the step's own plain
1144
+ // consumes, or one of the definition's declared inputs.
1145
+ //
1146
+ // The input form exists because a COMMAND step cannot consume a human seed
1147
+ // at all — `exec/instructions.ts` gates command orders with `hardRule:
1148
+ // true`, and `consumed-verifier.ts` refuses any consumed value lacking a
1149
+ // producer signature, which a human-supplied input never has. Naming the
1150
+ // input here routes it through `OrderPacket.workdir` instead, which is a
1151
+ // spawn parameter rather than shell text or a consumed artifact.
1152
+ //
1153
+ // This deliberately relaxes an earlier rule that demanded a CONSUME, on the
1154
+ // stated grounds that the value must pass the consume-side gate "before a
1155
+ // worker can cd into it". That protection was not real: the engine resolves
1156
+ // this expression itself and ships a plain string as `OrderPacket.workdir`,
1157
+ // an explicitly "opaque location hint" that no proof covers and that the
1158
+ // command worker uses unverified. See `paths.ts`'s parseWorkdirFrom header
1159
+ // for the full argument, and note that the runtime bound on a worker's cwd
1160
+ // is the operator's declared work roots, not this check.
1161
+ const parsed = parseWorkdirFrom(raw, l.consumes, [...inputNames]);
1121
1162
  if (!parsed) {
1122
1163
  const stem = raw.slice(0, firstDot);
1123
- errors.push(`step '${l.name}': workdirFrom stem '${stem}' is not in consumes; ` +
1124
- 'a step may only take its workdir from an artifact it consumes');
1164
+ errors.push(`step '${l.name}': workdirFrom stem '${stem}' is neither in consumes nor a declared input; ` +
1165
+ "a step may only take its workdir from an artifact it consumes or from one of the definition's inputs");
1125
1166
  }
1126
1167
  else if (parsed.mode !== 'plain') {
1127
1168
  errors.push(`step '${l.name}': workdirFrom stem '${parsed.stem}' uses a ${parsed.mode} consume; ` +
@@ -1389,14 +1389,36 @@ export class Engine {
1389
1389
  };
1390
1390
  let resolvedWorkdir;
1391
1391
  if (step.workdirFrom !== undefined) {
1392
- const parsed = parseWorkdirFrom(step.workdirFrom, step.consumes);
1392
+ const parsed = parseWorkdirFrom(step.workdirFrom, step.consumes, def.inputs.map((i) => i.name));
1393
1393
  if (!parsed) {
1394
- return unresolved(`workdirFrom '${step.workdirFrom}': expected a consumed stem followed by a non-empty dotted value path`);
1394
+ return unresolved(`workdirFrom '${step.workdirFrom}': expected a consumed or declared-input stem followed by a non-empty dotted value path`);
1395
1395
  }
1396
1396
  if (parsed.mode !== 'plain') {
1397
1397
  return unresolved(`workdirFrom '${step.workdirFrom}': source stem '${parsed.stem}' is not a plain consume`);
1398
1398
  }
1399
- let value = consumes[parsed.stem];
1399
+ // A CONSUMED stem reads out of the firing's resolved consume map, exactly
1400
+ // as before. An INPUT stem the step does not consume is not in that map,
1401
+ // so it reads out of the instance's artifact table instead.
1402
+ //
1403
+ // The green check is what makes this an ordering edge without a consume.
1404
+ // `unresolved` defers the firing rather than failing it, so a step whose
1405
+ // workdir comes from a still-owed input simply is not offered yet and is
1406
+ // reconsidered on the next tick — the same wait a consume would have
1407
+ // produced, without putting the value in `order.consumes` (where the
1408
+ // command launch gate would hard-refuse it for having no producer
1409
+ // signature: a human seed has none). See `paths.ts`'s parseWorkdirFrom
1410
+ // header for why an input-authored cwd is admissible at all.
1411
+ let value;
1412
+ if (parsed.source === 'consume') {
1413
+ value = consumes[parsed.stem];
1414
+ }
1415
+ else {
1416
+ const art = arts.get(parsed.stem);
1417
+ if (art === undefined || art.acceptance !== 'green') {
1418
+ return unresolved(`workdirFrom '${step.workdirFrom}': input '${parsed.stem}' is not green yet`);
1419
+ }
1420
+ value = art.value;
1421
+ }
1400
1422
  const segments = parsed.path.split('.');
1401
1423
  for (let i = 0; i < segments.length; i++) {
1402
1424
  const segment = segments[i];
package/dist/src/hub.d.ts CHANGED
@@ -222,7 +222,11 @@ export declare function keychainServiceFor(normalizedOrigin: string): string;
222
222
  * instead of a clean miss.
223
223
  */
224
224
  export declare function parseCredential(raw: unknown): Credential | null;
225
- /** The user-level config dir (never the project dir). Derives from the caller's env. */
225
+ /**
226
+ * The user-level config dir (never the project dir). Derives from the caller's
227
+ * env via the one shared ladder in `config-dir.ts`:
228
+ * `OWENLOOP_CONFIG_DIR` > `$XDG_CONFIG_HOME/owenloop` > `$HOME/.config/owenloop`.
229
+ */
226
230
  export declare function configDir(env: Record<string, string | undefined>): string;
227
231
  export declare function credentialFilePath(env: Record<string, string | undefined>): string;
228
232
  /**
package/dist/src/hub.js CHANGED
@@ -69,6 +69,7 @@ import { createHash, randomBytes } from 'node:crypto';
69
69
  import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
70
70
  import { basename, dirname, join } from 'node:path';
71
71
  import { parse as parseYaml } from 'yaml';
72
+ import { owenloopConfigDir } from "./config-dir.js";
72
73
  import { hashDef, parseDef } from "./defs.js";
73
74
  import { mkdirRefusingSymlink } from "./util.js";
74
75
  // ---- server-parity def content hash ------------------------------------------
@@ -277,15 +278,13 @@ export function parseCredential(raw) {
277
278
  }
278
279
  return null;
279
280
  }
280
- /** The user-level config dir (never the project dir). Derives from the caller's env. */
281
+ /**
282
+ * The user-level config dir (never the project dir). Derives from the caller's
283
+ * env via the one shared ladder in `config-dir.ts`:
284
+ * `OWENLOOP_CONFIG_DIR` > `$XDG_CONFIG_HOME/owenloop` > `$HOME/.config/owenloop`.
285
+ */
281
286
  export function configDir(env) {
282
- const xdg = env.XDG_CONFIG_HOME;
283
- if (xdg && xdg.trim() !== '')
284
- return join(xdg, 'owenloop');
285
- const home = env.HOME;
286
- if (home && home.trim() !== '')
287
- return join(home, '.config', 'owenloop');
288
- throw new Error('cannot locate a config directory: set HOME or XDG_CONFIG_HOME');
287
+ return owenloopConfigDir(env);
289
288
  }
290
289
  export function credentialFilePath(env) {
291
290
  return join(configDir(env), 'credentials.json');
@@ -37,13 +37,56 @@ export interface WorkdirFromParts {
37
37
  stem: string;
38
38
  path: string;
39
39
  mode: ConsumeMode;
40
+ /**
41
+ * Where the stem was found, which decides where the ENGINE reads the value.
42
+ *
43
+ * - `consume` — the stem names one of the step's own consumes. The value
44
+ * comes out of the resolved consume map for the firing.
45
+ * - `input` — the stem names one of the DEFINITION's declared inputs and
46
+ * the step does not consume it. The value comes out of the instance's
47
+ * artifact table, and the firing defers while that input is still owed.
48
+ *
49
+ * A consume always wins: the loop below tries consumes first at every split
50
+ * boundary, so a step that genuinely consumes an input keeps the old
51
+ * behaviour and nothing about an existing def changes meaning.
52
+ */
53
+ source: 'consume' | 'input';
40
54
  }
41
55
  /**
42
- * Split a workdirFrom expression by the longest prefix that names one of the
43
- * step's own consumes. Artifact stems may contain dots, so the consume list is
44
- * the closed grammar that makes the split deterministic at def-load time.
56
+ * Split a workdirFrom expression by the longest prefix that names either one of
57
+ * the step's own consumes or one of the definition's declared inputs. Artifact
58
+ * stems may contain dots, so those two name lists are the closed grammar that
59
+ * makes the split deterministic at def-load time.
60
+ *
61
+ * ## Why an input stem is admissible, when the value becomes a filesystem path
62
+ *
63
+ * `validateDef` used to require the stem be a plain CONSUME, on the stated
64
+ * grounds that the value must have "passed the engine's consume-side
65
+ * verification gate before a worker can cd into it". That reasoning does not
66
+ * survive contact with what actually crosses the wire:
67
+ *
68
+ * - The engine resolves `workdirFrom` ITSELF, inside the claim transaction
69
+ * (`engine.ts`, `emitOrder`), and ships the resolved STRING as
70
+ * `OrderPacket.workdir` — declared in `packages/work/src/hub/types.ts` as an
71
+ * "Opaque location hint — the worker's cwd when set".
72
+ * - Nothing verifies that field. `consumesProof` covers `order.consumes`
73
+ * entries and only those (`consumed-verifier.ts`, `parseProofMap`), and the
74
+ * command worker takes `order.workdir ?? opts.cwd` with no check at all
75
+ * (`packages/work/src/exec/loop.ts`).
76
+ *
77
+ * So the consume gate never protected the cwd at runtime — by the time the
78
+ * value reaches a worker it is an unverified string in an unverified field
79
+ * either way. The old rule constrained who may AUTHOR the value (a producer
80
+ * step) rather than what a worker will trust, and this widens that authorship
81
+ * to include the human who starts the run. Both are inside the same trust
82
+ * boundary: principals authorized to start or serve runs on this hub.
83
+ *
84
+ * What actually bounds the cwd is machine-side and belongs to the operator, not
85
+ * to the def — a shift refuses an order whose workdir falls outside the roots
86
+ * its operator declared. That check is the runtime protection; this grammar is
87
+ * an authoring question.
45
88
  */
46
- export declare function parseWorkdirFrom(raw: string, consumes: readonly ConsumePattern[]): WorkdirFromParts | null;
89
+ export declare function parseWorkdirFrom(raw: string, consumes: readonly ConsumePattern[], inputs?: readonly string[]): WorkdirFromParts | null;
47
90
  /** Parse a produce declaration. */
48
91
  export declare function parseProduce(raw: string): ProducePattern;
49
92
  /**
package/dist/src/paths.js CHANGED
@@ -65,11 +65,40 @@ export function parseConsume(raw) {
65
65
  return { raw: r, mode: 'plain', stem: r, suffix: '' };
66
66
  }
67
67
  /**
68
- * Split a workdirFrom expression by the longest prefix that names one of the
69
- * step's own consumes. Artifact stems may contain dots, so the consume list is
70
- * the closed grammar that makes the split deterministic at def-load time.
68
+ * Split a workdirFrom expression by the longest prefix that names either one of
69
+ * the step's own consumes or one of the definition's declared inputs. Artifact
70
+ * stems may contain dots, so those two name lists are the closed grammar that
71
+ * makes the split deterministic at def-load time.
72
+ *
73
+ * ## Why an input stem is admissible, when the value becomes a filesystem path
74
+ *
75
+ * `validateDef` used to require the stem be a plain CONSUME, on the stated
76
+ * grounds that the value must have "passed the engine's consume-side
77
+ * verification gate before a worker can cd into it". That reasoning does not
78
+ * survive contact with what actually crosses the wire:
79
+ *
80
+ * - The engine resolves `workdirFrom` ITSELF, inside the claim transaction
81
+ * (`engine.ts`, `emitOrder`), and ships the resolved STRING as
82
+ * `OrderPacket.workdir` — declared in `packages/work/src/hub/types.ts` as an
83
+ * "Opaque location hint — the worker's cwd when set".
84
+ * - Nothing verifies that field. `consumesProof` covers `order.consumes`
85
+ * entries and only those (`consumed-verifier.ts`, `parseProofMap`), and the
86
+ * command worker takes `order.workdir ?? opts.cwd` with no check at all
87
+ * (`packages/work/src/exec/loop.ts`).
88
+ *
89
+ * So the consume gate never protected the cwd at runtime — by the time the
90
+ * value reaches a worker it is an unverified string in an unverified field
91
+ * either way. The old rule constrained who may AUTHOR the value (a producer
92
+ * step) rather than what a worker will trust, and this widens that authorship
93
+ * to include the human who starts the run. Both are inside the same trust
94
+ * boundary: principals authorized to start or serve runs on this hub.
95
+ *
96
+ * What actually bounds the cwd is machine-side and belongs to the operator, not
97
+ * to the def — a shift refuses an order whose workdir falls outside the roots
98
+ * its operator declared. That check is the runtime protection; this grammar is
99
+ * an authoring question.
71
100
  */
72
- export function parseWorkdirFrom(raw, consumes) {
101
+ export function parseWorkdirFrom(raw, consumes, inputs = []) {
73
102
  const r = raw.trim();
74
103
  for (let boundary = r.lastIndexOf('.'); boundary > 0; boundary = r.lastIndexOf('.', boundary - 1)) {
75
104
  const stem = r.slice(0, boundary);
@@ -78,7 +107,9 @@ export function parseWorkdirFrom(raw, consumes) {
78
107
  continue;
79
108
  const consume = consumes.find((c) => c.stem === stem);
80
109
  if (consume)
81
- return { raw: r, stem, path, mode: consume.mode };
110
+ return { raw: r, stem, path, mode: consume.mode, source: 'consume' };
111
+ if (inputs.includes(stem))
112
+ return { raw: r, stem, path, mode: 'plain', source: 'input' };
82
113
  }
83
114
  return null;
84
115
  }
@@ -2,8 +2,9 @@
2
2
  * execution settings file writer — the ONE place the root `owenloop` CLI writes
3
3
  * into the execution-side settings file.
4
4
  *
5
- * `owenloop work` reads its settings from `$XDG_CONFIG_HOME/owenloop/
6
- * settings.json` (else `$HOME/.config/owenloop/settings.json`) and, by design,
5
+ * `owenloop work` reads its settings from `$OWENLOOP_CONFIG_DIR/settings.json`
6
+ * (else `$XDG_CONFIG_HOME/owenloop/settings.json`, else
7
+ * `$HOME/.config/owenloop/settings.json`) and, by design,
7
8
  * NEVER writes them — the root CLI's `setup` command is the writer, so a fresh
8
9
  * `owenloop setup` can point `owenloop work` at the hub it just authenticated
9
10
  * against.
@@ -23,9 +24,11 @@
23
24
  * util.ts — no CLI/engine closure.
24
25
  */
25
26
  /**
26
- * The execution settings file path for this environment. `XDG_CONFIG_HOME` (when
27
- * set and non-blank) wins over `HOME`, matching owenloop's own resolution and
28
- * the owenloop credential store's `configDir`. Throws when neither is set.
27
+ * The execution settings file path for this environment, through the one shared
28
+ * ladder in `config-dir.ts`: `OWENLOOP_CONFIG_DIR` (absolute, used verbatim)
29
+ * wins over `$XDG_CONFIG_HOME/owenloop`, which wins over
30
+ * `$HOME/.config/owenloop`. Throws as a `CliError` when no rung yields a value,
31
+ * so the CLI reports it as an operator error rather than a crash.
29
32
  */
30
33
  export declare function owenloopSettingsPath(env: Record<string, string | undefined>): string;
31
34
  /**
@@ -2,8 +2,9 @@
2
2
  * execution settings file writer — the ONE place the root `owenloop` CLI writes
3
3
  * into the execution-side settings file.
4
4
  *
5
- * `owenloop work` reads its settings from `$XDG_CONFIG_HOME/owenloop/
6
- * settings.json` (else `$HOME/.config/owenloop/settings.json`) and, by design,
5
+ * `owenloop work` reads its settings from `$OWENLOOP_CONFIG_DIR/settings.json`
6
+ * (else `$XDG_CONFIG_HOME/owenloop/settings.json`, else
7
+ * `$HOME/.config/owenloop/settings.json`) and, by design,
7
8
  * NEVER writes them — the root CLI's `setup` command is the writer, so a fresh
8
9
  * `owenloop setup` can point `owenloop work` at the hub it just authenticated
9
10
  * against.
@@ -24,21 +25,23 @@
24
25
  */
25
26
  import { existsSync, mkdirSync, readFileSync } from 'node:fs';
26
27
  import { dirname, join } from 'node:path';
28
+ import { owenloopConfigDir } from "./config-dir.js";
27
29
  import { writeFileAtomic } from "./hub.js";
28
30
  import { CliError } from "./util.js";
29
31
  /**
30
- * The execution settings file path for this environment. `XDG_CONFIG_HOME` (when
31
- * set and non-blank) wins over `HOME`, matching owenloop's own resolution and
32
- * the owenloop credential store's `configDir`. Throws when neither is set.
32
+ * The execution settings file path for this environment, through the one shared
33
+ * ladder in `config-dir.ts`: `OWENLOOP_CONFIG_DIR` (absolute, used verbatim)
34
+ * wins over `$XDG_CONFIG_HOME/owenloop`, which wins over
35
+ * `$HOME/.config/owenloop`. Throws as a `CliError` when no rung yields a value,
36
+ * so the CLI reports it as an operator error rather than a crash.
33
37
  */
34
38
  export function owenloopSettingsPath(env) {
35
- const xdg = env.XDG_CONFIG_HOME;
36
- if (xdg && xdg.trim() !== '')
37
- return join(xdg, 'owenloop', 'settings.json');
38
- const home = env.HOME;
39
- if (home && home.trim() !== '')
40
- return join(home, '.config', 'owenloop', 'settings.json');
41
- throw new CliError('cannot locate a config directory for execution settings: set HOME or XDG_CONFIG_HOME');
39
+ try {
40
+ return join(owenloopConfigDir(env), 'settings.json');
41
+ }
42
+ catch (err) {
43
+ throw new CliError(`cannot locate a config directory for execution settings: ${err instanceof Error ? err.message : String(err)}`);
44
+ }
42
45
  }
43
46
  /**
44
47
  * Read and parse the execution settings file at `path`.
@@ -38,6 +38,7 @@ x:
38
38
  - `tools: []` is an explicit empty allow-list and disables all built-in tools on adapters that support tool lists.
39
39
  - `filesystem` is one of `read-only`, `workspace-write`, or `unrestricted`.
40
40
  - `network` is one of `owenloop-only` or `unrestricted`.
41
+ - `permissionMode` accepts each adapter's own vocabulary, plus three neutral values: `ask`, `auto-safe`, and `full-access`.
41
42
  - `tools` and `disallowedTools` must not overlap.
42
43
  - Invalid types, invalid closed-set values, generated `name`/`description` fields, and the legacy `x.claude-code` carrier are definition errors.
43
44
  - Unknown `x.harness` keys remain opaque extension data. The selected adapter may interpret or warn about those keys.
@@ -58,6 +59,10 @@ A cache created by an older CLI may contain `filesystem` or `network` under `per
58
59
  | `network: owenloop-only` | supported through isolated settings, skills, MCP, and built-in tools | refused |
59
60
  | `network: unrestricted` | supported | supported with `filesystem: unrestricted`, or with an omitted filesystem field and legacy sandbox `workspace-write` / `danger-full-access`; legacy sandbox `read-only` is refused because Codex has no independent read-only network control |
60
61
  | `maxTurns` | enforced by the SDK | refused; Codex app-server has no thread or turn limit parameter |
62
+ | `permissionMode: ask` | translated to `default` | translated to `approvalPolicy: untrusted` |
63
+ | `permissionMode: auto-safe` | translated to `auto`, without the danger companion flag | translated to `approvalPolicy: on-request` |
64
+ | `permissionMode: full-access` | translated to `bypassPermissions` plus the SDK's `allowDangerouslySkipPermissions` companion flag | translated to `approvalPolicy: never` |
65
+ | another adapter's `permissionMode` value | refused; the Claude Code adapter accepts only its own SDK union plus the three neutral values | refused; the Codex adapter accepts only `untrusted`, `on-request`, `never`, plus the three neutral values |
61
66
 
62
67
  Codex refusal of explicit `filesystem: read-only` and `filesystem: workspace-write` is intentional and runs before both cold start and resume. Codex app-server loads configuration from thread, project, global/managed, and persisted session layers. The pinned Codex version has no reliable switch that isolates every layer, and some layers can introduce host processes, providers, endpoints, MCP servers, or additional writable roots outside the thread sandbox. Partial filtering would claim a boundary the adapter cannot prove, so the adapter starts no app-server process and the worker releases the held claim.
63
68
 
@@ -65,7 +70,27 @@ Codex also refuses every defined `maxTurns` value before both cold start and res
65
70
 
66
71
  An omitted `filesystem` field preserves the existing Codex default sandbox behavior. `filesystem: unrestricted` preserves the existing explicit `danger-full-access` behavior. The legacy adapter extension `sandbox` remains available with `read-only`, `workspace-write`, or `danger-full-access` for backward compatibility, but `sandbox` is a vendor-specific pass-through rather than Owenloop's neutral filesystem guarantee. A workflow that requires an enforceable neutral read-only policy must select the Claude Code adapter.
67
72
 
68
- The worker-created `owenloop` MCP mount still wins any `mcp_servers.owenloop` name clash. The default unrestricted mount registers `get_order`, `submit`, and `reject`. Codex approval policy still accepts only `untrusted`, `on-request`, or `never`.
73
+ The worker-created `owenloop` MCP mount still wins any `mcp_servers.owenloop` name clash. The default unrestricted mount registers `get_order`, `submit`, and `reject`. Codex approval policy still accepts only `untrusted`, `on-request`, or `never` as vendor values.
74
+
75
+ ## Neutral approval modes
76
+
77
+ `permissionMode` names how much a step may do before a human is consulted. It is the one neutral field whose values were vendor-specific: Claude Code's never-prompt mode is `bypassPermissions` and Codex's is `never`, and each adapter refuses the other's. A step that must never prompt therefore had to name one vendor's word, which pinned the step to that vendor exactly as an explicit `id:` would.
78
+
79
+ The neutral vocabulary is three positions on one axis, and both shipped harnesses draw all three distinctions themselves:
80
+
81
+ | Neutral value | What is the gate | Claude Code | Codex |
82
+ |---|---|---|---|
83
+ | `ask` | a human, before anything beyond trivially safe reads | `default` | `untrusted` |
84
+ | `auto-safe` | a model-side classifier; it proceeds on ordinary work and consults a human only when an action is potentially dangerous | `auto` | `on-request` |
85
+ | `full-access` | nothing; the harness never consults a human and a failed action is reported back to the model | `bypassPermissions` + `allowDangerouslySkipPermissions` | `never` |
86
+
87
+ `auto-safe` is not a milder `full-access`. It can still stop and ask, which is the whole point of it, so an adapter must never map it onto a never-ask mode. The two exist separately so a definition states the choice rather than having it inferred.
88
+
89
+ `ask` and `auto-safe` are meaningful only where something can answer a prompt. In a Shift-dispatched run nothing can today, so a prompt is a stall: the Step Agent stops mid-turn, submits nothing, and the hub re-arms the step into a retry storm whose every worker dies in the same place. That is a reason for a definition author to choose `full-access` for headless steps, not a reason for an adapter to silently upgrade one value into another.
90
+
91
+ For each neutral value an adapter must either map it onto the vendor mode with the same meaning, or refuse it in preflight. Refusal is a legitimate answer and fails closed: the worker releases its claim and starts no model process. Mapping a value onto a mode that grants more than the value describes is never legitimate.
92
+
93
+ Each adapter still accepts its own vendor vocabulary and still refuses the other's, so no already-published definition changes meaning. A definition that uses a neutral value must declare the `neutral-approval-modes.v1` runtime feature. On a CLI that predates the feature, both shipped adapters refuse the neutral value as out-of-vocabulary and the step fails closed, but the message names a bad permission mode rather than an old runtime; the feature declaration moves that diagnosis to the bundle compatibility check, before any order is offered.
69
94
 
70
95
  The Claude Code adapter refuses a `read-only` allow-list containing anything outside `Read`, `Glob`, `Grep`, `WebFetch`, `WebSearch`, and the born-bound control tools. With `network: owenloop-only`, the allowed read-only built-ins narrow to `Read`, `Glob`, and `Grep`; `WebFetch` and `WebSearch` remain available only with `network: unrestricted`. The Claude Code adapter refuses an `owenloop-only` allow-list containing Bash, web tools, skills, agent delegation, or any unaudited tool. The Claude Code adapter also refuses authored external MCP tool names because the current option surface cannot prove an exact per-tool allow-list for an external server.
71
96