owenloop 0.5.6 → 0.5.8

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 (82) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +3 -6
  3. package/dist/packages/work/src/agent/approvals.d.ts +53 -0
  4. package/dist/packages/work/src/agent/approvals.js +132 -0
  5. package/dist/packages/work/src/agent/brief.d.ts +12 -0
  6. package/dist/packages/work/src/agent/brief.js +51 -0
  7. package/dist/packages/work/src/agent/capability-model.d.ts +64 -82
  8. package/dist/packages/work/src/agent/capability-model.js +94 -91
  9. package/dist/packages/work/src/agent/loop.d.ts +43 -25
  10. package/dist/packages/work/src/agent/loop.js +135 -50
  11. package/dist/packages/work/src/bundle/types.d.ts +3 -3
  12. package/dist/packages/work/src/exec/loop.js +37 -15
  13. package/dist/packages/work/src/harness/child-env.js +4 -5
  14. package/dist/packages/work/src/harness/claude.d.ts +4 -0
  15. package/dist/packages/work/src/harness/claude.js +72 -3
  16. package/dist/packages/work/src/harness/codex.d.ts +37 -1
  17. package/dist/packages/work/src/harness/codex.js +136 -18
  18. package/dist/packages/work/src/harness/contract.d.ts +54 -1
  19. package/dist/packages/work/src/harness/session-store.d.ts +127 -17
  20. package/dist/packages/work/src/harness/session-store.js +157 -60
  21. package/dist/packages/work/src/hub/client.d.ts +13 -1
  22. package/dist/packages/work/src/hub/client.js +3 -0
  23. package/dist/packages/work/src/hub/types.d.ts +104 -3
  24. package/dist/packages/work/src/main.js +1 -0
  25. package/dist/packages/work/src/roles/agent-run.js +52 -42
  26. package/dist/packages/work/src/roles/approvals.d.ts +76 -0
  27. package/dist/packages/work/src/roles/approvals.js +231 -0
  28. package/dist/packages/work/src/roles/sessions.d.ts +3 -2
  29. package/dist/packages/work/src/roles/sessions.js +9 -2
  30. package/dist/packages/work/src/roles/settings.js +1 -1
  31. package/dist/packages/work/src/settings/roster.d.ts +21 -0
  32. package/dist/packages/work/src/settings/roster.js +80 -0
  33. package/dist/packages/work/src/settings/settings.d.ts +12 -24
  34. package/dist/packages/work/src/settings/settings.js +17 -35
  35. package/dist/packages/work/src/shift/loop.d.ts +2 -0
  36. package/dist/packages/work/src/shift/loop.js +2 -0
  37. package/dist/packages/work/src/shift/runtime.js +17 -9
  38. package/dist/packages/work/src/shift/spawn.d.ts +10 -53
  39. package/dist/packages/work/src/shift/spawn.js +28 -60
  40. package/dist/packages/work/src/usage.d.ts +1 -1
  41. package/dist/packages/work/src/usage.js +8 -4
  42. package/dist/src/capabilities.d.ts +44 -0
  43. package/dist/src/capabilities.js +38 -0
  44. package/dist/src/cli.d.ts +1 -0
  45. package/dist/src/cli.js +460 -5
  46. package/dist/src/config-dir.d.ts +13 -18
  47. package/dist/src/config-dir.js +15 -23
  48. package/dist/src/credentials.d.ts +1 -1
  49. package/dist/src/credentials.js +1 -1
  50. package/dist/src/crypto/records.d.ts +3 -0
  51. package/dist/src/crypto/records.js +19 -0
  52. package/dist/src/crypto/trust-roots.d.ts +2 -2
  53. package/dist/src/crypto/trust-roots.js +2 -2
  54. package/dist/src/engine.d.ts +14 -0
  55. package/dist/src/engine.js +26 -14
  56. package/dist/src/global-config.d.ts +4 -7
  57. package/dist/src/global-config.js +4 -7
  58. package/dist/src/hub.d.ts +207 -5
  59. package/dist/src/hub.js +263 -3
  60. package/dist/src/index.d.ts +2 -2
  61. package/dist/src/index.js +1 -1
  62. package/dist/src/model.d.ts +37 -1
  63. package/dist/src/model.js +47 -1
  64. package/dist/src/schemas/index.d.ts +19 -0
  65. package/dist/src/schemas/order.v1.schema.json +15 -1
  66. package/dist/src/store/pre-commit-verifier.js +1 -1
  67. package/dist/src/types.d.ts +58 -4
  68. package/dist/src/work-settings.d.ts +2 -4
  69. package/dist/src/work-settings.js +2 -4
  70. package/docs/agent-runner.md +2 -2
  71. package/docs/bundles.md +3 -1
  72. package/docs/cli.md +295 -101
  73. package/docs/crypto.md +14 -14
  74. package/docs/routing.md +607 -0
  75. package/docs/shift-logs.md +22 -6
  76. package/package.json +1 -1
  77. package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
  78. package/plugins/claude-code/plugin/.mcp.json +1 -1
  79. package/plugins/claude-code/plugin/skills/author/SKILL.md +1 -2
  80. package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
  81. package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
  82. package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +1 -2
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `owenloop work approvals` — THE OPERATOR SURFACE for the tool-approval gate.
3
+ *
4
+ * WHY THIS EXISTS AT ALL. Without it the channel is write-only: a worker blocks
5
+ * on a person, the hub records the question, and nothing on any human's machine
6
+ * ever displays it. That is the exact failure this whole feature was built to
7
+ * end, so the reader half ships in the same change as the writer half rather
8
+ * than in a follow-up.
9
+ *
10
+ * WHAT AN APPROVAL IS, AND WHAT IT IS NOT. Three human-in-the-loop mechanisms
11
+ * exist and they are not interchangeable:
12
+ *
13
+ * - a pending GATE is an input nobody has provided yet; answered with
14
+ * `owenloop provide`.
15
+ * - an `ask` is a worker saying it cannot honestly build what it OWES. The
16
+ * step ends, the run closes `no_work`, and the answer reaches a FRESH
17
+ * worker later; answered with `owenloop retry --text`.
18
+ * - an APPROVAL — this file — is a worker that is STILL RUNNING and blocked
19
+ * mid-flight on one tool call. Its session is alive and stays alive, the run
20
+ * does not close, and the answer goes back to that very call.
21
+ *
22
+ * The practical consequence for whoever is reading this list: an approval is the
23
+ * only one of the three where somebody is waiting RIGHT NOW. Every one shown
24
+ * here has a worker parked on it.
25
+ *
26
+ * WHY THERE IS A DEADLINE ON THE WORKER SIDE AND NOT HERE. The waiting process
27
+ * gives up after its own window and treats the non-answer as a denial, so an
28
+ * unanswered approval costs the run one honest `ask` rather than a hang. This
29
+ * command therefore cannot promise that an answer will land — it can only
30
+ * deliver one while the worker is still listening. Answering promptly is the
31
+ * whole point of the list.
32
+ *
33
+ * COMMANDS
34
+ * owenloop work approvals [--json] every approval a worker is blocked on
35
+ * owenloop work approvals approve <wf>/<run> <tool-use-id> [--note <text>]
36
+ * owenloop work approvals deny <wf>/<run> <tool-use-id> [--note <text>]
37
+ *
38
+ * The decision is a positional VERB rather than an `--approve` flag, because a
39
+ * flag that grants a dangerous command is one typo away from being omitted, and
40
+ * an omitted flag has to mean something. A verb cannot be omitted.
41
+ *
42
+ * Origin and bearer resolve exactly as in `release`: `--origin` → settings
43
+ * `hubOrigin`, and the `agent:<account>` credential slot for `OWENLOOP_ACCOUNT`
44
+ * (default `default`). The hub refuses `answer_approval` to an agent token by
45
+ * design — this verb is for a person's key.
46
+ *
47
+ * Exit codes: 0 on success (including an empty list) · 1 on a hub/network error
48
+ * · 2 on a usage error.
49
+ */
50
+ import { type HubClient } from '../hub/client.ts';
51
+ type Action = 'list' | 'approve' | 'deny';
52
+ interface ParsedArgs {
53
+ action: Action;
54
+ order?: string;
55
+ toolUseId?: string;
56
+ note?: string;
57
+ origin?: string;
58
+ json?: boolean;
59
+ error?: string;
60
+ }
61
+ /** Parse the subcommand and its flags, in both `--flag value` and `--flag=value` forms. */
62
+ export declare function parseArgs(args: string[]): ParsedArgs;
63
+ /** Split `<workflow>/<run>`. A run id is opaque, so only the FIRST slash splits. */
64
+ export declare function splitOrder(order: string): {
65
+ workflow: string;
66
+ run: string;
67
+ } | undefined;
68
+ export interface RunDeps {
69
+ hub?: HubClient;
70
+ out?: (line: string) => void;
71
+ err?: (line: string) => void;
72
+ env?: Record<string, string | undefined>;
73
+ now?: () => number;
74
+ }
75
+ export declare function run(args: string[], deps?: RunDeps): Promise<number>;
76
+ export {};
@@ -0,0 +1,231 @@
1
+ /**
2
+ * `owenloop work approvals` — THE OPERATOR SURFACE for the tool-approval gate.
3
+ *
4
+ * WHY THIS EXISTS AT ALL. Without it the channel is write-only: a worker blocks
5
+ * on a person, the hub records the question, and nothing on any human's machine
6
+ * ever displays it. That is the exact failure this whole feature was built to
7
+ * end, so the reader half ships in the same change as the writer half rather
8
+ * than in a follow-up.
9
+ *
10
+ * WHAT AN APPROVAL IS, AND WHAT IT IS NOT. Three human-in-the-loop mechanisms
11
+ * exist and they are not interchangeable:
12
+ *
13
+ * - a pending GATE is an input nobody has provided yet; answered with
14
+ * `owenloop provide`.
15
+ * - an `ask` is a worker saying it cannot honestly build what it OWES. The
16
+ * step ends, the run closes `no_work`, and the answer reaches a FRESH
17
+ * worker later; answered with `owenloop retry --text`.
18
+ * - an APPROVAL — this file — is a worker that is STILL RUNNING and blocked
19
+ * mid-flight on one tool call. Its session is alive and stays alive, the run
20
+ * does not close, and the answer goes back to that very call.
21
+ *
22
+ * The practical consequence for whoever is reading this list: an approval is the
23
+ * only one of the three where somebody is waiting RIGHT NOW. Every one shown
24
+ * here has a worker parked on it.
25
+ *
26
+ * WHY THERE IS A DEADLINE ON THE WORKER SIDE AND NOT HERE. The waiting process
27
+ * gives up after its own window and treats the non-answer as a denial, so an
28
+ * unanswered approval costs the run one honest `ask` rather than a hang. This
29
+ * command therefore cannot promise that an answer will land — it can only
30
+ * deliver one while the worker is still listening. Answering promptly is the
31
+ * whole point of the list.
32
+ *
33
+ * COMMANDS
34
+ * owenloop work approvals [--json] every approval a worker is blocked on
35
+ * owenloop work approvals approve <wf>/<run> <tool-use-id> [--note <text>]
36
+ * owenloop work approvals deny <wf>/<run> <tool-use-id> [--note <text>]
37
+ *
38
+ * The decision is a positional VERB rather than an `--approve` flag, because a
39
+ * flag that grants a dangerous command is one typo away from being omitted, and
40
+ * an omitted flag has to mean something. A verb cannot be omitted.
41
+ *
42
+ * Origin and bearer resolve exactly as in `release`: `--origin` → settings
43
+ * `hubOrigin`, and the `agent:<account>` credential slot for `OWENLOOP_ACCOUNT`
44
+ * (default `default`). The hub refuses `answer_approval` to an agent token by
45
+ * design — this verb is for a person's key.
46
+ *
47
+ * Exit codes: 0 on success (including an empty list) · 1 on a hub/network error
48
+ * · 2 on a usage error.
49
+ */
50
+ import { createHubClient } from "../hub/client.js";
51
+ import { resolveBearer } from "../credentials/resolve.js";
52
+ import { loadSettings } from "../settings/settings.js";
53
+ /** Parse the subcommand and its flags, in both `--flag value` and `--flag=value` forms. */
54
+ export function parseArgs(args) {
55
+ const first = args[0];
56
+ const action = first === 'approve' ? 'approve' : first === 'deny' ? 'deny' : 'list';
57
+ // `list` is the default AND an explicit word; anything else that is not a flag
58
+ // is a positional belonging to the decision verbs.
59
+ const rest = first === 'approve' || first === 'deny' || first === 'list' ? args.slice(1) : args;
60
+ const parsed = { action };
61
+ const positionals = [];
62
+ for (let i = 0; i < rest.length; i++) {
63
+ const a = rest[i];
64
+ if (!a.startsWith('--')) {
65
+ positionals.push(a);
66
+ continue;
67
+ }
68
+ const eq = a.indexOf('=');
69
+ const name = eq === -1 ? a : a.slice(0, eq);
70
+ if (name === '--json') {
71
+ parsed.json = true;
72
+ continue;
73
+ }
74
+ if (name !== '--note' && name !== '--origin')
75
+ return { action, error: `unknown option '${a}'` };
76
+ let value;
77
+ if (eq !== -1)
78
+ value = a.slice(eq + 1);
79
+ else {
80
+ const next = rest[i + 1];
81
+ if (next === undefined)
82
+ return { action, error: `missing value for ${a}` };
83
+ value = next;
84
+ i += 1;
85
+ }
86
+ if (name === '--note')
87
+ parsed.note = value;
88
+ else
89
+ parsed.origin = value;
90
+ }
91
+ if (action === 'list') {
92
+ if (positionals.length > 0)
93
+ return { action, error: `unexpected argument '${positionals[0]}'` };
94
+ return parsed;
95
+ }
96
+ const [order, toolUseId, extra] = positionals;
97
+ if (order === undefined)
98
+ return { action, error: 'missing <workflow>/<run>' };
99
+ if (toolUseId === undefined)
100
+ return { action, error: 'missing <tool-use-id>' };
101
+ if (extra !== undefined)
102
+ return { action, error: `unexpected argument '${extra}'` };
103
+ parsed.order = order;
104
+ parsed.toolUseId = toolUseId;
105
+ return parsed;
106
+ }
107
+ /** Split `<workflow>/<run>`. A run id is opaque, so only the FIRST slash splits. */
108
+ export function splitOrder(order) {
109
+ const slash = order.indexOf('/');
110
+ if (slash <= 0 || slash === order.length - 1)
111
+ return undefined;
112
+ return { workflow: order.slice(0, slash), run: order.slice(slash + 1) };
113
+ }
114
+ function usage(err) {
115
+ err('usage: owenloop work approvals [--json]');
116
+ err(' owenloop work approvals approve <workflow>/<run> <tool-use-id> [--note <text>]');
117
+ err(' owenloop work approvals deny <workflow>/<run> <tool-use-id> [--note <text>]');
118
+ }
119
+ function errMsg(err) {
120
+ return err instanceof Error ? err.message : String(err);
121
+ }
122
+ /**
123
+ * Render one waiting approval, ending with the exact command that answers it.
124
+ *
125
+ * Printing the answer command is not decoration. Whoever reads this list is
126
+ * being asked to make a judgement under time pressure, and making them assemble
127
+ * a three-part key by hand is how the wrong call gets approved.
128
+ */
129
+ function renderApproval(a, waitedMs) {
130
+ const order = `${a.workflow}/${a.run}`;
131
+ const waited = waitedMs >= 0 ? `${Math.round(waitedMs / 1_000)}s` : 'unknown';
132
+ const lines = [
133
+ `${order} step=${a.step} ${a.toolName} waiting ${waited}`,
134
+ ` why: ${a.reason}`,
135
+ ];
136
+ if (a.title !== '')
137
+ lines.push(` call: ${a.title}`);
138
+ lines.push(` approve: owenloop work approvals approve ${order} ${a.toolUseId}`);
139
+ lines.push(` deny: owenloop work approvals deny ${order} ${a.toolUseId}`);
140
+ return lines;
141
+ }
142
+ export async function run(args, deps = {}) {
143
+ const out = deps.out ?? ((line) => void process.stdout.write(`${line}\n`));
144
+ const err = deps.err ?? ((line) => void process.stderr.write(`${line}\n`));
145
+ const env = deps.env ?? process.env;
146
+ const now = deps.now ?? Date.now;
147
+ const parsed = parseArgs(args);
148
+ if (parsed.error !== undefined) {
149
+ err(`owenloop work approvals: ${parsed.error}`);
150
+ usage(err);
151
+ return 2;
152
+ }
153
+ let split;
154
+ if (parsed.action !== 'list') {
155
+ split = splitOrder(parsed.order);
156
+ if (split === undefined) {
157
+ err(`owenloop work approvals: '${parsed.order}' is not <workflow>/<run>`);
158
+ usage(err);
159
+ return 2;
160
+ }
161
+ }
162
+ let settings;
163
+ try {
164
+ settings = loadSettings(env);
165
+ }
166
+ catch (e) {
167
+ err(`owenloop work approvals: ${errMsg(e)}`);
168
+ return 1;
169
+ }
170
+ const origin = parsed.origin ?? settings.hubOrigin;
171
+ if (origin === undefined || origin.trim() === '') {
172
+ err('owenloop work approvals: no hub origin — pass --origin <url> or set hubOrigin in settings');
173
+ return 2;
174
+ }
175
+ const account = env['OWENLOOP_ACCOUNT'] ?? 'default';
176
+ const bearer = await resolveBearer({ origin, account, env });
177
+ if (!bearer.ok) {
178
+ err(`owenloop work approvals: ${bearer.message}`);
179
+ return bearer.code;
180
+ }
181
+ const token = bearer.token;
182
+ const hub = deps.hub ?? createHubClient({ origin, getToken: async () => token });
183
+ if (parsed.action === 'list') {
184
+ let approvals;
185
+ try {
186
+ approvals = (await hub.listPendingApprovals()).approvals;
187
+ }
188
+ catch (e) {
189
+ err(`owenloop work approvals: ${errMsg(e)}`);
190
+ return 1;
191
+ }
192
+ if (parsed.json === true) {
193
+ out(JSON.stringify(approvals, null, 2));
194
+ return 0;
195
+ }
196
+ if (approvals.length === 0) {
197
+ out('no workers are blocked on an approval');
198
+ return 0;
199
+ }
200
+ const at = now();
201
+ for (const a of approvals) {
202
+ for (const line of renderApproval(a, at - a.requestedAt))
203
+ out(line);
204
+ out('');
205
+ }
206
+ return 0;
207
+ }
208
+ try {
209
+ const res = await hub.answerApproval({
210
+ workflow: split.workflow,
211
+ run: split.run,
212
+ tool_use_id: parsed.toolUseId,
213
+ decision: parsed.action === 'approve' ? 'approve' : 'deny',
214
+ ...(parsed.note !== undefined ? { note: parsed.note } : {}),
215
+ });
216
+ if (res.ok === false) {
217
+ // The common case by far: the worker gave up waiting and the approval is
218
+ // no longer live. Said plainly, because "failed" would read as a bug.
219
+ err(`owenloop work approvals: not answered — ${res.reason ?? 'the approval is no longer pending'}`);
220
+ return 1;
221
+ }
222
+ if (res.text !== '')
223
+ out(res.text);
224
+ out(`${parsed.action}d ${split.workflow}/${split.run} ${parsed.toolUseId}`);
225
+ return 0;
226
+ }
227
+ catch (e) {
228
+ err(`owenloop work approvals: ${errMsg(e)}`);
229
+ return 1;
230
+ }
231
+ }
@@ -47,8 +47,9 @@ export declare function formatAge(ms: number): string;
47
47
  /**
48
48
  * The resume command for one record, or `undefined` when there is none.
49
49
  *
50
- * Three separate reasons there may be none, all rendered the same way in the
51
- * table because the operator's next move is identical in each: the record names
50
+ * Four separate reasons there may be none, all rendered the same way in the
51
+ * table because the operator's next move is identical in each: the record
52
+ * carries no session token, so there is nothing to resume INTO; the record names
52
53
  * a harness this build does not register (an old row after an adapter was
53
54
  * removed); the adapter registers but implements no interactive resume; or the
54
55
  * adapter threw. The throw is caught rather than propagated because this is a
@@ -98,14 +98,21 @@ function shellQuote(s) {
98
98
  /**
99
99
  * The resume command for one record, or `undefined` when there is none.
100
100
  *
101
- * Three separate reasons there may be none, all rendered the same way in the
102
- * table because the operator's next move is identical in each: the record names
101
+ * Four separate reasons there may be none, all rendered the same way in the
102
+ * table because the operator's next move is identical in each: the record
103
+ * carries no session token, so there is nothing to resume INTO; the record names
103
104
  * a harness this build does not register (an old row after an adapter was
104
105
  * removed); the adapter registers but implements no interactive resume; or the
105
106
  * adapter threw. The throw is caught rather than propagated because this is a
106
107
  * LISTING — one bad row must not take down the other rows with it.
107
108
  */
108
109
  export function resumeCommandFor(rec) {
110
+ // An empty token is a real, readable record: the worker writes one before the
111
+ // harness emits `started`, so a launch that died still leaves proof it existed.
112
+ // Handing that empty string to `resumeCommand` would print a command that
113
+ // cannot work, which is worse than printing nothing.
114
+ if (rec.token === '')
115
+ return undefined;
109
116
  const adapter = adapterFor(rec.harness);
110
117
  if (adapter?.resumeCommand === undefined)
111
118
  return undefined;
@@ -16,7 +16,7 @@ import { inspectSettings, KNOWN_SETTINGS_KEYS } from "../settings/settings.js";
16
16
  /**
17
17
  * Built-in defaults shown for knobs absent from the file (else `unset`).
18
18
  *
19
- * `capabilityModels` is deliberately absent: it HAS no built-in default. A shift
19
+ * `roster` is deliberately absent: it HAS no built-in default. A shift
20
20
  * with no row for an order's capability refuses that order rather than falling
21
21
  * back to some default model, so printing a default here would describe
22
22
  * behaviour that does not exist.
@@ -0,0 +1,21 @@
1
+ import { type Roster, type RosterCandidate } from '../agent/capability-model.ts';
2
+ export interface RosterLayer {
3
+ /** Provenance printed verbatim by `owenloop roster show`. */
4
+ source: string;
5
+ /** Inspected even if absent, so diagnostics can state where they looked. */
6
+ path?: string;
7
+ /** Absent when the layer does not exist on this machine. */
8
+ roster?: Roster;
9
+ }
10
+ export interface MergedRosterEntry {
11
+ candidates: readonly RosterCandidate[];
12
+ source: string;
13
+ }
14
+ export type MergedRoster = Readonly<Record<string, MergedRosterEntry>>;
15
+ /** Merge key-by-key. `layers` is ordered STRONGEST FIRST. */
16
+ export declare function mergeRosterLayers(layers: readonly RosterLayer[]): MergedRoster;
17
+ /**
18
+ * The machine's layers for one crew, strongest first. When no crew is known,
19
+ * only the machine-global `settings.json` roster participates.
20
+ */
21
+ export declare function machineRosterLayers(env: Record<string, string | undefined>, crew: string | undefined): RosterLayer[];
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Crew-roster disk layout and layered merge.
3
+ *
4
+ * This module owns where machine roster layers come from and their
5
+ * strongest-first cascade. Shape validation and capability lookup remain in
6
+ * `agent/capability-model.ts`.
7
+ */
8
+ import { existsSync, readFileSync } from 'node:fs';
9
+ import { join } from 'node:path';
10
+ import { validateRoster, } from "../agent/capability-model.js";
11
+ import { owenloopConfigDir } from "../../../../src/config-dir.js";
12
+ import { loadSettings } from "./settings.js";
13
+ /** Merge key-by-key. `layers` is ordered STRONGEST FIRST. */
14
+ export function mergeRosterLayers(layers) {
15
+ // Capability names are arbitrary strings, including Object.prototype names.
16
+ // A null prototype keeps every own key routable and makes `__proto__` data,
17
+ // rather than a request to mutate the result's prototype.
18
+ const merged = Object.create(null);
19
+ for (const layer of layers) {
20
+ if (layer.roster === undefined)
21
+ continue;
22
+ for (const [capability, candidates] of Object.entries(layer.roster)) {
23
+ if (!Object.prototype.hasOwnProperty.call(merged, capability)) {
24
+ // Candidate arrays are atomic: a winning layer replaces every weaker
25
+ // candidate, never concatenating or element-merging with it.
26
+ merged[capability] = { candidates, source: layer.source };
27
+ }
28
+ }
29
+ }
30
+ return merged;
31
+ }
32
+ function readCrewRoster(path) {
33
+ let parsed;
34
+ try {
35
+ parsed = JSON.parse(readFileSync(path, 'utf8'));
36
+ }
37
+ catch (error) {
38
+ const message = error instanceof Error ? error.message : String(error);
39
+ throw new Error(`invalid crew roster at ${path}: ${message}`);
40
+ }
41
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
42
+ throw new Error(`invalid crew roster at ${path}: expected an object with a 'roster' key`);
43
+ }
44
+ const roster = parsed['roster'];
45
+ if (typeof roster !== 'object' || roster === null || Array.isArray(roster)) {
46
+ throw new Error(`invalid crew roster at ${path}: 'roster' must be a JSON object`);
47
+ }
48
+ try {
49
+ validateRoster(roster, 'roster');
50
+ }
51
+ catch (error) {
52
+ const message = error instanceof Error ? error.message : String(error);
53
+ throw new Error(`invalid crew roster at ${path}: ${message}`);
54
+ }
55
+ return roster;
56
+ }
57
+ /**
58
+ * The machine's layers for one crew, strongest first. When no crew is known,
59
+ * only the machine-global `settings.json` roster participates.
60
+ */
61
+ export function machineRosterLayers(env, crew) {
62
+ const configDir = owenloopConfigDir(env);
63
+ const layers = [];
64
+ if (crew !== undefined) {
65
+ const path = join(configDir, 'crews', `${crew}.json`);
66
+ layers.push({
67
+ source: `machine crews/${crew}.json`,
68
+ path,
69
+ ...(existsSync(path) ? { roster: readCrewRoster(path) } : {}),
70
+ });
71
+ }
72
+ const path = join(configDir, 'settings.json');
73
+ const settings = loadSettings(env);
74
+ layers.push({
75
+ source: 'machine settings.json',
76
+ path,
77
+ ...(settings.roster !== undefined ? { roster: settings.roster } : {}),
78
+ });
79
+ return layers;
80
+ }
@@ -1,4 +1,4 @@
1
- import { type CapabilityModelRow } from '../agent/capability-model.ts';
1
+ import { type Roster } from '../agent/capability-model.ts';
2
2
  /**
3
3
  * The settings surface — every knob optional, a missing file loading as `{}`.
4
4
  * Each field is the lowest-precedence fallback for a role option (a CLI flag
@@ -119,28 +119,22 @@ export interface Settings {
119
119
  */
120
120
  allowedWorkdirRoots?: string[];
121
121
  /**
122
- * How THIS machine serves each capability: a flat map from capability to
123
- * `{model, effort}`, keyed by the composed capability (`wise:deep`) or by the
124
- * bare name (`wise`). See `src/agent/capability-model.ts` for the lookup rule
125
- * and for why this replaced `tierMap`/`tierProfiles` outright.
126
- *
127
- * Carry a bare row per capability the shift's crews serve. The bare row is
128
- * what makes a hub name-match fallback order resolvable — the hub can stamp
129
- * `wise:deep` on an order claimed by a crew bound only to `wise:standard`,
130
- * and that shift has no `wise:deep` row by construction.
122
+ * Machine-global crew roster: each capability maps to an ordered list of
123
+ * `{harness, model, effort}` candidates. A crew-specific roster file can
124
+ * replace individual capability rows above this layer.
131
125
  */
132
- capabilityModels?: Record<string, CapabilityModelRow>;
126
+ roster?: Roster;
133
127
  }
134
128
  /** The known settings keys, in the order `owenloop work settings` prints them. */
135
- export declare const KNOWN_SETTINGS_KEYS: readonly ["hubOrigin", "cacheDir", "stateDir", "dispatchCap", "shiftLogDir", "shiftLogMaxAgeMs", "commandRouting", "defPolicy", "artifactPolicy", "maxConcurrentAgents", "workRoot", "workRepo", "allowedWorkdirRoots", "capabilityModels"];
129
+ export declare const KNOWN_SETTINGS_KEYS: readonly ["hubOrigin", "cacheDir", "stateDir", "dispatchCap", "shiftLogDir", "shiftLogMaxAgeMs", "commandRouting", "defPolicy", "artifactPolicy", "maxConcurrentAgents", "workRoot", "workRepo", "allowedWorkdirRoots", "roster"];
136
130
  /**
137
131
  * Keys owenloop still RECOGNIZES but no longer acts on. Each one produces a
138
132
  * warning naming what replaced it, and is excluded from `unrecognized` so the
139
133
  * same key is not also reported as a likely typo.
140
134
  *
141
- * Distinct from `tierMap`/`tierProfiles`, which are a hard error: ignoring
142
- * those would leave the shift with no capability map and refuse every order,
143
- * whereas ignoring these changes nothing about how a shift runs.
135
+ * Distinct from unrecognized keys, which are surfaced as likely typos. These
136
+ * are recognized legacy settings whose removal leaves current shift behavior
137
+ * unchanged, so they remain a warning rather than a load failure.
144
138
  */
145
139
  export declare const RETIRED_IGNORED_KEYS: readonly ["escalateAt", "escalationExtensionKey"];
146
140
  /**
@@ -176,15 +170,9 @@ export interface SettingsInspection extends ValidatedSettings {
176
170
  * Resolve the settings file path from the caller's env, through the one shared
177
171
  * ladder in `src/config-dir.ts`: `$OWENLOOP_CONFIG_DIR/settings.json` when
178
172
  * `OWENLOOP_CONFIG_DIR` is set and non-blank (it must be absolute), else
179
- * `$XDG_CONFIG_HOME/owenloop/settings.json`, else
180
- * `$HOME/.config/owenloop/settings.json`. Throws when no rung yields a value
181
- * rather than guessing a home directory.
182
- *
183
- * `OWENLOOP_CONFIG_DIR` is the variable an operator running SEVERAL shifts on
184
- * one machine should reach for. Setting `XDG_CONFIG_HOME` per shift also works,
185
- * but a shift spreads its whole environment into every worker and every command
186
- * step's child, so relocating `XDG_CONFIG_HOME` relocates the config of `gh`,
187
- * `git`, `gcloud`, and everything else those steps shell out to.
173
+ * `$HOME/.owenloop/settings.json`. Throws when no rung yields a value rather
174
+ * than guessing a home directory. `OWENLOOP_CONFIG_DIR` remains for tests and
175
+ * throwaway isolation, not normal operator configuration.
188
176
  */
189
177
  export declare function settingsPath(env: Record<string, string | undefined>): string;
190
178
  /**
@@ -15,7 +15,7 @@
15
15
  import { existsSync, readFileSync } from 'node:fs';
16
16
  import { isAbsolute, join } from 'node:path';
17
17
  import { owenloopConfigDir } from "../../../../src/config-dir.js";
18
- import { validateCapabilityModels } from "../agent/capability-model.js";
18
+ import { validateRoster } from "../agent/capability-model.js";
19
19
  /** The known settings keys, in the order `owenloop work settings` prints them. */
20
20
  export const KNOWN_SETTINGS_KEYS = [
21
21
  'hubOrigin',
@@ -31,31 +31,25 @@ export const KNOWN_SETTINGS_KEYS = [
31
31
  'workRoot',
32
32
  'workRepo',
33
33
  'allowedWorkdirRoots',
34
- 'capabilityModels',
34
+ 'roster',
35
35
  ];
36
36
  /**
37
37
  * Keys owenloop still RECOGNIZES but no longer acts on. Each one produces a
38
38
  * warning naming what replaced it, and is excluded from `unrecognized` so the
39
39
  * same key is not also reported as a likely typo.
40
40
  *
41
- * Distinct from `tierMap`/`tierProfiles`, which are a hard error: ignoring
42
- * those would leave the shift with no capability map and refuse every order,
43
- * whereas ignoring these changes nothing about how a shift runs.
41
+ * Distinct from unrecognized keys, which are surfaced as likely typos. These
42
+ * are recognized legacy settings whose removal leaves current shift behavior
43
+ * unchanged, so they remain a warning rather than a load failure.
44
44
  */
45
45
  export const RETIRED_IGNORED_KEYS = ['escalateAt', 'escalationExtensionKey'];
46
46
  /**
47
47
  * Resolve the settings file path from the caller's env, through the one shared
48
48
  * ladder in `src/config-dir.ts`: `$OWENLOOP_CONFIG_DIR/settings.json` when
49
49
  * `OWENLOOP_CONFIG_DIR` is set and non-blank (it must be absolute), else
50
- * `$XDG_CONFIG_HOME/owenloop/settings.json`, else
51
- * `$HOME/.config/owenloop/settings.json`. Throws when no rung yields a value
52
- * rather than guessing a home directory.
53
- *
54
- * `OWENLOOP_CONFIG_DIR` is the variable an operator running SEVERAL shifts on
55
- * one machine should reach for. Setting `XDG_CONFIG_HOME` per shift also works,
56
- * but a shift spreads its whole environment into every worker and every command
57
- * step's child, so relocating `XDG_CONFIG_HOME` relocates the config of `gh`,
58
- * `git`, `gcloud`, and everything else those steps shell out to.
50
+ * `$HOME/.owenloop/settings.json`. Throws when no rung yields a value rather
51
+ * than guessing a home directory. `OWENLOOP_CONFIG_DIR` remains for tests and
52
+ * throwaway isolation, not normal operator configuration.
59
53
  */
60
54
  export function settingsPath(env) {
61
55
  return join(owenloopConfigDir(env), 'settings.json');
@@ -102,19 +96,6 @@ export function validateSettings(raw, path) {
102
96
  throw bad('maxConcurrentAgents', 'a positive integer', v);
103
97
  }
104
98
  }
105
- // RETIRED KEYS ARE A HARD ERROR, NOT AN IGNORED ONE. A file still naming
106
- // `tierMap` or `tierProfiles` describes a routing scheme that no longer
107
- // exists; passing it over as an unrecognized key would start the shift with
108
- // NO capability map at all, and every agent order would then be refused at
109
- // dispatch with a message about capabilities the operator never wrote.
110
- for (const retired of ['tierMap', 'tierProfiles']) {
111
- if (retired in obj) {
112
- throw new Error(`invalid settings file at ${path}: '${retired}' was removed — tiers are replaced by ` +
113
- `'capabilityModels', a flat map from capability to { model, effort } ` +
114
- `(e.g. {"capabilityModels": {"wise:deep": {"model": "<model-id>", "effort": "xhigh"}}}). ` +
115
- `Depth now rides on the capability's modifier suffix, not on a tier rung.`);
116
- }
117
- }
118
99
  if ('allowedWorkdirRoots' in obj) {
119
100
  // ABSOLUTE PATHS ONLY, and that is the one rule worth a hard error rather
120
101
  // than a warning. A relative entry would resolve against whatever directory
@@ -137,22 +118,23 @@ export function validateSettings(raw, path) {
137
118
  }
138
119
  }
139
120
  if ('capabilityModels' in obj) {
140
- const v = obj['capabilityModels'];
121
+ throw new Error(`invalid settings file at ${path}: 'capabilityModels' was replaced by 'roster'. ` +
122
+ `Use {"roster":{"wise":[{"harness":"<harness-id>","model":"<model-id>","effort":"high"}]}}.`);
123
+ }
124
+ if ('roster' in obj) {
125
+ const v = obj['roster'];
141
126
  if (typeof v !== 'object' || v === null || Array.isArray(v)) {
142
- throw bad('capabilityModels', 'an object of { model, effort } per capability', v);
127
+ throw bad('roster', 'a JSON object mapping capabilities to candidate arrays', v);
143
128
  }
144
- // Row shape and effort validity are checked at LOAD, not at resolution: a
145
- // shift whose map is wrong should fail when it starts, not on the first
146
- // order that happens to land on the broken row, hours later.
147
129
  try {
148
- validateCapabilityModels(v);
130
+ validateRoster(v, 'roster');
149
131
  }
150
132
  catch (e) {
151
133
  throw new Error(`invalid settings file at ${path}: ${e instanceof Error ? e.message : String(e)}`);
152
134
  }
153
135
  }
154
- // RETIRED, BUT ONLY A WARNING — a different case from `tierMap` above, and the
155
- // difference is what happens if the key is silently ignored.
136
+ // RETIRED, BUT ONLY A WARNING. The difference is what happens if the key is
137
+ // silently ignored.
156
138
  //
157
139
  // These two configured the WORKER-LOCAL escalation that bumped an order's
158
140
  // model after N judgment rejections. Escalation is now entirely the engine's:
@@ -30,6 +30,8 @@ export interface ShiftLoopOptions {
30
30
  /** Shift name for presence. INITIAL value only — live-mutable via
31
31
  * `ShiftLoop.setShift` (MCP `clock_in`). */
32
32
  name: string;
33
+ /** Stable owner key for session records; unlike `name`, it is not clocked in. */
34
+ shiftOwner?: string;
33
35
  /**
34
36
  * W7: this Shift process incarnation's self-declared id (`shf_<uuid>`)
35
37
  * and process start time — carried on presence pings (attribution/
@@ -326,6 +326,8 @@ export function createShiftLoop(opts) {
326
326
  run: c.order.run,
327
327
  step: c.order.step,
328
328
  ...(childKind === 'agent-run' ? { kind: 'agent-run' } : {}),
329
+ ...(childKind === 'agent-run' ? { shiftName } : {}),
330
+ ...(childKind === 'agent-run' && opts.shiftOwner !== undefined ? { shiftOwner: opts.shiftOwner } : {}),
329
331
  startGate: reserved.gatePath,
330
332
  });
331
333
  cancel = spawned.cancel ?? spawned.terminate;