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
package/dist/src/hub.js CHANGED
@@ -48,7 +48,7 @@
48
48
  * Secret hygiene is a hard rule here: credentials never land in the repo or a
49
49
  * plaintext `.env`. The 0600 file backend below (dir 0700) lives under the
50
50
  * user's config dir, never the project; all paths derive from the
51
- * caller-supplied `env` (HOME / XDG_CONFIG_HOME), never `process.env` directly,
51
+ * caller-supplied `env` (HOME), never `process.env` directly,
52
52
  * so tests fixture `$HOME` and never touch ambient machine state. Both this
53
53
  * file and `.owenloop/hub.json` are written via `writeFileAtomic` — temp file
54
54
  * in the same dir + rename, refusing a symlinked destination (SEC-3). The
@@ -281,7 +281,7 @@ export function parseCredential(raw) {
281
281
  /**
282
282
  * The user-level config dir (never the project dir). Derives from the caller's
283
283
  * env via the one shared ladder in `config-dir.ts`:
284
- * `OWENLOOP_CONFIG_DIR` > `$XDG_CONFIG_HOME/owenloop` > `$HOME/.config/owenloop`.
284
+ * `OWENLOOP_CONFIG_DIR` > `$HOME/.owenloop`.
285
285
  */
286
286
  export function configDir(env) {
287
287
  return owenloopConfigDir(env);
@@ -629,7 +629,7 @@ export function credentialBackend(env, injected) {
629
629
  * keychain → file. A keychain-backed read NEVER falls through to the file (that
630
630
  * fallback was the REL-6 shadowing bug), and a corrupt entry reads as absent
631
631
  * (`null`) on either store — never as a reason to consult the other. The file
632
- * backend derives its path from the supplied `env` (HOME / XDG_CONFIG_HOME),
632
+ * backend derives its path from the supplied `env` (HOME),
633
633
  * never `process.env` directly, so a caller passing `opts.env` stays hermetic;
634
634
  * only the top-level default falls back to `process.env`.
635
635
  *
@@ -1124,6 +1124,266 @@ export function asCapabilityRoutes(body) {
1124
1124
  const list = body.bindings;
1125
1125
  return list.map((entry, i) => asCapabilityRouteRow(entry, 'capability_routes: malformed response', `bindings[${i}]`));
1126
1126
  }
1127
+ /**
1128
+ * Validate the eight `RoutingAlertWire` fields on one row. `prefix` is the
1129
+ * endpoint-qualified lead-in the caller wants (e.g.
1130
+ * `routing_alerts: malformed response`) and `where` names the offending
1131
+ * position (`alerts[2]`) — a FIELD/INDEX name only, never a value.
1132
+ *
1133
+ * Shared by BOTH endpoints that carry alert rows (`GET /api/routing_alerts` and
1134
+ * `GET /api/run_routing/:wf`), so the two can never drift apart in what they
1135
+ * accept — the same reason `asCapabilityRouteRow` is shared by its three
1136
+ * callers.
1137
+ */
1138
+ function asRoutingAlertRow(entry, prefix, where) {
1139
+ if (typeof entry !== 'object' || entry === null) {
1140
+ throw new Error(`${prefix} — ${where} is not an object`);
1141
+ }
1142
+ const e = entry;
1143
+ for (const field of ['id', 'workflow', 'kind', 'capability']) {
1144
+ if (typeof e[field] !== 'string' || e[field] === '') {
1145
+ throw new Error(`${prefix} — ${where} missing non-empty string ${field}`);
1146
+ }
1147
+ }
1148
+ if (typeof e.at !== 'number') {
1149
+ throw new Error(`${prefix} — ${where} missing number at`);
1150
+ }
1151
+ // Lenient exactly like `asCapabilityRouteRow`'s `crewName`: absent or `null`
1152
+ // both mean "the hub has nothing to report here", which is a normal answer for
1153
+ // all three of these fields.
1154
+ const nullableString = (field) => {
1155
+ const value = e[field];
1156
+ if (value === undefined || value === null)
1157
+ return null;
1158
+ if (typeof value !== 'string' || value === '') {
1159
+ throw new Error(`${prefix} — ${where} ${field} must be a non-empty string or null`);
1160
+ }
1161
+ return value;
1162
+ };
1163
+ return {
1164
+ id: e.id,
1165
+ at: e.at,
1166
+ workflow: e.workflow,
1167
+ kind: e.kind,
1168
+ capability: e.capability,
1169
+ modifier: nullableString('modifier'),
1170
+ step: nullableString('step'),
1171
+ detail: nullableString('detail'),
1172
+ };
1173
+ }
1174
+ /**
1175
+ * Narrow `GET /api/routing_alerts`' 200 body (`{ text, alerts: [...] }`) to a
1176
+ * typed array. An EMPTY array is valid — "this org has recorded no routing
1177
+ * alerts" is a normal, and in fact the desirable, answer.
1178
+ *
1179
+ * **The array is forwarded IN WIRE ORDER and must never be re-sorted.** The
1180
+ * order is meaningful and it is not the same order in both modes: unscoped the
1181
+ * hub returns the org's alerts NEWEST-FIRST (an inbox), while `?workflow=`
1182
+ * scopes to one run AND flips to OLDEST-FIRST (a timeline). A client-side sort
1183
+ * would destroy whichever of the two the operator asked for.
1184
+ */
1185
+ export function asRoutingAlerts(body) {
1186
+ if (typeof body !== 'object' || body === null || !Array.isArray(body.alerts)) {
1187
+ throw new Error('routing_alerts: malformed response — expected an `alerts` array');
1188
+ }
1189
+ const list = body.alerts;
1190
+ return list.map((entry, i) => asRoutingAlertRow(entry, 'routing_alerts: malformed response', `alerts[${i}]`));
1191
+ }
1192
+ /**
1193
+ * Narrow `GET /api/run_routing/:wf`'s 200 body. Throws on anything malformed,
1194
+ * naming the offending FIELD or INDEX only — no body value is ever echoed.
1195
+ *
1196
+ * Uses the `malformed success response` wording rather than `malformed
1197
+ * response`, matching `get_status`, the other single-resource GET: a body that
1198
+ * fails here arrived with a 2xx, and saying so distinguishes it from the hub
1199
+ * having refused the request outright.
1200
+ */
1201
+ export function asRunRouting(body) {
1202
+ const prefix = 'run_routing: malformed success response';
1203
+ if (typeof body !== 'object' || body === null || Array.isArray(body)) {
1204
+ throw new Error(`${prefix} — not an object`);
1205
+ }
1206
+ const b = body;
1207
+ for (const field of ['workflow', 'defName']) {
1208
+ if (typeof b[field] !== 'string' || b[field] === '') {
1209
+ throw new Error(`${prefix} — missing non-empty string ${field}`);
1210
+ }
1211
+ }
1212
+ // ABSENT is legitimate (an unmodified run) and is preserved as absent. `''` is
1213
+ // NOT legitimate — the hub omits the key instead — so it is malformed here
1214
+ // rather than silently normalized to "no modifier".
1215
+ let modifier;
1216
+ if (b.modifier !== undefined) {
1217
+ if (typeof b.modifier !== 'string' || b.modifier === '') {
1218
+ throw new Error(`${prefix} — modifier must be a non-empty string when present`);
1219
+ }
1220
+ modifier = b.modifier;
1221
+ }
1222
+ if (typeof b.waitPolicy !== 'object' || b.waitPolicy === null || Array.isArray(b.waitPolicy)) {
1223
+ throw new Error(`${prefix} — waitPolicy is not an object`);
1224
+ }
1225
+ const waitPolicyWire = b.waitPolicy;
1226
+ if (typeof waitPolicyWire.wait !== 'string' || waitPolicyWire.wait === '') {
1227
+ throw new Error(`${prefix} — waitPolicy missing non-empty string wait`);
1228
+ }
1229
+ const waitPolicy = { wait: waitPolicyWire.wait };
1230
+ if (waitPolicyWire.then !== undefined)
1231
+ waitPolicy.then = waitPolicyWire.then;
1232
+ if (!Array.isArray(b.alerts)) {
1233
+ throw new Error(`${prefix} — missing array alerts`);
1234
+ }
1235
+ const alerts = b.alerts.map((entry, i) => asRoutingAlertRow(entry, prefix, `alerts[${i}]`));
1236
+ // Object-checked and forwarded verbatim — see the interface's doc comment for
1237
+ // why these two are not deep-validated and why their PRESENCE is still required.
1238
+ const joined = (field) => {
1239
+ const value = b[field];
1240
+ if (!Array.isArray(value)) {
1241
+ throw new Error(`${prefix} — missing array ${field}`);
1242
+ }
1243
+ return value.map((entry, i) => {
1244
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
1245
+ throw new Error(`${prefix} — ${field}[${i}] is not an object`);
1246
+ }
1247
+ return entry;
1248
+ });
1249
+ };
1250
+ return {
1251
+ workflow: b.workflow,
1252
+ defName: b.defName,
1253
+ ...(modifier === undefined ? {} : { modifier }),
1254
+ waitPolicy,
1255
+ alerts,
1256
+ resolutionReports: joined('resolutionReports'),
1257
+ escalations: joined('escalations'),
1258
+ };
1259
+ }
1260
+ /**
1261
+ * Validate the four common `CapabilityRerouteWire` fields on one row. `prefix`
1262
+ * is the endpoint-qualified lead-in and `where` names the offending position
1263
+ * (`reroute`, or `reroutes[2]`) — a FIELD/INDEX name only, never a value.
1264
+ *
1265
+ * No field here is nullable: unlike a capability route, a reroute rule names no
1266
+ * crew, so it has no dangling case to represent.
1267
+ */
1268
+ function asCapabilityRerouteRow(entry, prefix, where) {
1269
+ if (typeof entry !== 'object' || entry === null) {
1270
+ throw new Error(`${prefix} — ${where} is not an object`);
1271
+ }
1272
+ const e = entry;
1273
+ for (const field of ['capability', 'target']) {
1274
+ if (typeof e[field] !== 'string' || e[field] === '') {
1275
+ throw new Error(`${prefix} — ${where} missing non-empty string ${field}`);
1276
+ }
1277
+ }
1278
+ for (const field of ['position', 'createdAt']) {
1279
+ if (typeof e[field] !== 'number') {
1280
+ throw new Error(`${prefix} — ${where} missing number ${field}`);
1281
+ }
1282
+ }
1283
+ return {
1284
+ capability: e.capability,
1285
+ target: e.target,
1286
+ position: e.position,
1287
+ createdAt: e.createdAt,
1288
+ };
1289
+ }
1290
+ /**
1291
+ * Narrow `GET /api/capability_reroutes`' 200 body (`{ text, reroutes: [...] }`)
1292
+ * to a typed array. An EMPTY array is valid — "this org has configured no
1293
+ * reroute rules", which is the default and correct state for most orgs.
1294
+ *
1295
+ * THE ARRAY KEY IS `reroutes`. It is neither `bindings` (what the sibling
1296
+ * `capability_routes` endpoint uses) nor `rules` (what the feature is called in
1297
+ * prose). Guessing that key is precisely how `capability list` shipped broken
1298
+ * TWICE — see `asCapabilityRoutes` — so it is copied from
1299
+ * `hub-core/src/verbs/list-capability-reroutes.ts` rather than inferred.
1300
+ *
1301
+ * **Rows arrive in the order the hub TRIES them** (`capability`, then
1302
+ * `position`, then `target`) and are forwarded exactly as received. The order is
1303
+ * SEMANTIC: it is the sequence in which a source's targets are attempted.
1304
+ * Re-sorting it — in this function, in a caller, or in a test fixture — would
1305
+ * silently misreport which substitution happens first.
1306
+ */
1307
+ export function asCapabilityReroutes(body) {
1308
+ if (typeof body !== 'object' || body === null || !Array.isArray(body.reroutes)) {
1309
+ throw new Error('capability_reroutes: malformed response — expected a `reroutes` array');
1310
+ }
1311
+ const list = body.reroutes;
1312
+ return list.map((entry, i) => asCapabilityRerouteRow(entry, 'capability_reroutes: malformed response', `reroutes[${i}]`));
1313
+ }
1314
+ /**
1315
+ * Narrow `POST /api/add_capability_reroute`'s 200 body
1316
+ * (`{ text, reroute, alreadyPresent, ruleCount }`), naming the offending field
1317
+ * only — the same discipline as `asCapabilityRouteAdded`.
1318
+ *
1319
+ * There is no layered non-null check here of the kind `asCapabilityRouteAdded`
1320
+ * applies to `binding.crewName`: a reroute row has no nullable field, because it
1321
+ * resolves no crew.
1322
+ */
1323
+ export function asCapabilityRerouteAdded(body) {
1324
+ const prefix = 'add_capability_reroute: malformed success response';
1325
+ if (typeof body !== 'object' || body === null) {
1326
+ throw new Error(`${prefix} — not an object`);
1327
+ }
1328
+ const b = body;
1329
+ if (b.reroute === undefined) {
1330
+ throw new Error(`${prefix} — missing reroute`);
1331
+ }
1332
+ const reroute = asCapabilityRerouteRow(b.reroute, prefix, 'reroute');
1333
+ if (typeof b.alreadyPresent !== 'boolean') {
1334
+ throw new Error(`${prefix} — missing boolean alreadyPresent`);
1335
+ }
1336
+ if (typeof b.ruleCount !== 'number') {
1337
+ throw new Error(`${prefix} — missing number ruleCount`);
1338
+ }
1339
+ return { reroute, alreadyPresent: b.alreadyPresent, ruleCount: b.ruleCount };
1340
+ }
1341
+ /**
1342
+ * Narrow `POST /api/remove_capability_reroute`'s 200 body
1343
+ * (`{ text, capability, target, removed, remainingTargets }`).
1344
+ *
1345
+ * `removed` must be a BOOLEAN — this guard is how the CLI proves the 2xx really
1346
+ * was the remove verb's answer. BOTH values are deliberate hub responses:
1347
+ * - `true` — the `(capability, target)` rule existed and is now gone;
1348
+ * - `false` — there was no such rule, so there was nothing to do. The hub
1349
+ * answers 200, never a 404 (the same tolerance `remove_capability_route`
1350
+ * has), and that is what makes `routing rule rm` idempotent.
1351
+ *
1352
+ * `remainingTargets` is deliberately STRICT — PRESENT, an array, and every
1353
+ * element a non-empty string. This is the identical asymmetry argued at
1354
+ * `asCapabilityRouteRemoved`: defaulting an absent array to `[]` would assert
1355
+ * "this capability now HOLDS whenever it is unbound" — the alarming reading, and
1356
+ * exactly the signal an operator acts on — off a malformed body. Unlike the
1357
+ * capability-route family there is no nullable field to balance it against, so
1358
+ * every field here is strict.
1359
+ *
1360
+ * The stdout shape built from this is documented in `docs/cli.md` under Routing.
1361
+ */
1362
+ export function asCapabilityRerouteRemoved(body) {
1363
+ const prefix = 'remove_capability_reroute: malformed success response';
1364
+ if (typeof body !== 'object' || body === null) {
1365
+ throw new Error(`${prefix} — not an object`);
1366
+ }
1367
+ const b = body;
1368
+ if (typeof b.removed !== 'boolean') {
1369
+ throw new Error(`${prefix} — missing boolean removed`);
1370
+ }
1371
+ for (const field of ['capability', 'target']) {
1372
+ if (typeof b[field] !== 'string' || b[field] === '') {
1373
+ throw new Error(`${prefix} — missing non-empty string ${field}`);
1374
+ }
1375
+ }
1376
+ if (!Array.isArray(b.remainingTargets)) {
1377
+ throw new Error(`${prefix} — missing array remainingTargets`);
1378
+ }
1379
+ const remainingTargets = b.remainingTargets.map((entry, i) => {
1380
+ if (typeof entry !== 'string' || entry === '') {
1381
+ throw new Error(`${prefix} — remainingTargets[${i}] is not a non-empty string`);
1382
+ }
1383
+ return entry;
1384
+ });
1385
+ return { capability: b.capability, target: b.target, removed: b.removed, remainingTargets };
1386
+ }
1127
1387
  /**
1128
1388
  * The `orphan:` prefix the hub uses to name its reserved orphan crew
1129
1389
  * (`packages/hub-core/src/crews-table.ts` / `verbs/manage-crews.ts`). Mirrored
@@ -13,8 +13,8 @@
13
13
  */
14
14
  export { CallsPinError, Engine, ModifierRefusalError } from './engine.ts';
15
15
  export type { CommitResult, CreateOpts, DefResolver, DeferredFiring, DeferredReason, EmitResult, EngineEvent, EngineListener, EngineWorkflowStatus, Order, ReapDetail, ReapReason, TickResult, } from './engine.ts';
16
- export { capabilityName, claimMatches, composeCapabilities, DEFAULT_MATCH_MODE, MODIFIER_SEPARATOR, } from './capabilities.ts';
17
- export type { MatchMode } from './capabilities.ts';
16
+ export { applyCapabilityRewrites, capabilityName, claimMatches, composeCapabilities, DEFAULT_MATCH_MODE, MODIFIER_SEPARATOR, } from './capabilities.ts';
17
+ export type { CapabilityRewrites, MatchMode } from './capabilities.ts';
18
18
  export { createEngine } from './factory.ts';
19
19
  export type { CreateEngineOpts, CreatedEngine } from './factory.ts';
20
20
  export { createDefInstructionSource, defInstructionDigest, OrderResolver, substituteOrderVars, UnknownDefDigestError, UnknownInstructionError, } from './order-resolver.ts';
package/dist/src/index.js CHANGED
@@ -14,7 +14,7 @@
14
14
  export { CallsPinError, Engine, ModifierRefusalError } from "./engine.js";
15
15
  // Routing capabilities: offer-time composition and the claim-side match. The
16
16
  // hub imports these to reason about the same compounds the engine composes.
17
- export { capabilityName, claimMatches, composeCapabilities, DEFAULT_MATCH_MODE, MODIFIER_SEPARATOR, } from "./capabilities.js";
17
+ export { applyCapabilityRewrites, capabilityName, claimMatches, composeCapabilities, DEFAULT_MATCH_MODE, MODIFIER_SEPARATOR, } from "./capabilities.js";
18
18
  export { createEngine } from "./factory.js";
19
19
  export { createDefInstructionSource, defInstructionDigest, OrderResolver, substituteOrderVars, UnknownDefDigestError, UnknownInstructionError, } from "./order-resolver.js";
20
20
  export { Store, openStore, StoreVersionError } from "./store.js";
@@ -10,7 +10,7 @@
10
10
  * The artifact set for one workflow instance is passed as a `Map<path, data>`.
11
11
  */
12
12
  import { SETTLED_STATES } from './types.ts';
13
- import type { Acceptance, ArtifactData, CheckOptions, CheckReport, CheckStep, ConsumePattern, FiringTrigger, Fingerprint, InvariantPredicate, StepDef, ProducePattern, RejectKind, RunData, WorkflowDef, WorkflowGraph, WorkflowTrace } from './types.ts';
13
+ import type { Acceptance, ArtifactData, CheckOptions, CheckReport, CheckStep, ConsumePattern, FiringTrigger, Fingerprint, InvariantPredicate, JsonSchema, StepDef, ProducePattern, RejectKind, RunData, WorkflowDef, WorkflowGraph, WorkflowTrace } from './types.ts';
14
14
  export type ArtifactMap = ReadonlyMap<string, ArtifactData>;
15
15
  /**
16
16
  * Clock and quiescence facts needed for idle-trigger eligibility.
@@ -186,6 +186,42 @@ export declare function isEscalated(a: ArtifactData | undefined, after: number):
186
186
  * a history row, never change routing.
187
187
  */
188
188
  export declare function rejectionEpisode(a: ArtifactData | undefined): number;
189
+ /**
190
+ * The JSON Schema the engine will enforce on an OWED path, plus what that
191
+ * schema governs — for projection onto the order packet (`Order.owes[]`).
192
+ *
193
+ * This is a read of the definition for the producer's benefit; it decides
194
+ * nothing. Enforcement stays where it already is, and this function's whole
195
+ * job is to return the same schema those sites will apply, so an order never
196
+ * advertises a shape the commit path would not check. Each branch names the
197
+ * site it mirrors:
198
+ *
199
+ * 1. MAP CHILD (`stem[3].suffix`) → the map produce's schema, governing the
200
+ * element value. Mirrors `engine.ts` `produceSchema()`'s map branch, which
201
+ * `green()` calls on the element.
202
+ * 2. COLLECTION SEAL (`stem` + the seal suffix) → the collection produce's
203
+ * schema, governing EACH MEMBER. Mirrors `engine.ts`'s `emit` path, which
204
+ * looks the schema up by `p.kind === 'collection' && p.stem === stem` and
205
+ * validates the member being emitted. The owed path is the seal because
206
+ * `plainOutputs()` pushes `sealPath(stem)` for a collection — the seal is
207
+ * what the step discharges, the members are what the schema describes.
208
+ * Reporting `appliesTo: 'member'` is the whole reason this function returns
209
+ * a discriminator instead of a bare schema.
210
+ * 3. SINGLETON → the singleton produce's schema, governing the submitted
211
+ * value. Mirrors `produceSchema()`'s singleton branch.
212
+ *
213
+ * Map is tested before singleton because a map produce's `stem` and a
214
+ * singleton's can be spelled the same; only the owed path's index token tells
215
+ * them apart, and `parseElement` is the thing that reads it.
216
+ *
217
+ * Returns undefined when the produce declares no schema, which is the common
218
+ * case — the engine then accepts any JSON, and the order should say nothing
219
+ * rather than imply a constraint that does not exist.
220
+ */
221
+ export declare function owedSchema(step: StepDef, path: string): {
222
+ schema: JsonSchema;
223
+ appliesTo: 'value' | 'member';
224
+ } | undefined;
189
225
  /** Bare elements (no further suffix) of a collection stem, in index order. */
190
226
  export declare function members(arts: ArtifactMap, stem: string): ArtifactData[];
191
227
  /**
package/dist/src/model.js CHANGED
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * The artifact set for one workflow instance is passed as a `Map<path, data>`.
11
11
  */
12
- import { bindProduce, elementPath, isMemberOf, parseElement, sealPath, } from "./paths.js";
12
+ import { bindProduce, elementPath, isMemberOf, parseElement, sealPath, sealStem, } from "./paths.js";
13
13
  import { DEBT_STATES, OUTSTANDING_STATES, SETTLED_STATES } from "./types.js";
14
14
  // ---- step shape classification ----------------------------------------------
15
15
  export function mapConsume(step) {
@@ -226,6 +226,52 @@ function produceOwning(step, path) {
226
226
  }
227
227
  return undefined;
228
228
  }
229
+ /**
230
+ * The JSON Schema the engine will enforce on an OWED path, plus what that
231
+ * schema governs — for projection onto the order packet (`Order.owes[]`).
232
+ *
233
+ * This is a read of the definition for the producer's benefit; it decides
234
+ * nothing. Enforcement stays where it already is, and this function's whole
235
+ * job is to return the same schema those sites will apply, so an order never
236
+ * advertises a shape the commit path would not check. Each branch names the
237
+ * site it mirrors:
238
+ *
239
+ * 1. MAP CHILD (`stem[3].suffix`) → the map produce's schema, governing the
240
+ * element value. Mirrors `engine.ts` `produceSchema()`'s map branch, which
241
+ * `green()` calls on the element.
242
+ * 2. COLLECTION SEAL (`stem` + the seal suffix) → the collection produce's
243
+ * schema, governing EACH MEMBER. Mirrors `engine.ts`'s `emit` path, which
244
+ * looks the schema up by `p.kind === 'collection' && p.stem === stem` and
245
+ * validates the member being emitted. The owed path is the seal because
246
+ * `plainOutputs()` pushes `sealPath(stem)` for a collection — the seal is
247
+ * what the step discharges, the members are what the schema describes.
248
+ * Reporting `appliesTo: 'member'` is the whole reason this function returns
249
+ * a discriminator instead of a bare schema.
250
+ * 3. SINGLETON → the singleton produce's schema, governing the submitted
251
+ * value. Mirrors `produceSchema()`'s singleton branch.
252
+ *
253
+ * Map is tested before singleton because a map produce's `stem` and a
254
+ * singleton's can be spelled the same; only the owed path's index token tells
255
+ * them apart, and `parseElement` is the thing that reads it.
256
+ *
257
+ * Returns undefined when the produce declares no schema, which is the common
258
+ * case — the engine then accepts any JSON, and the order should say nothing
259
+ * rather than imply a constraint that does not exist.
260
+ */
261
+ export function owedSchema(step, path) {
262
+ const el = parseElement(path);
263
+ if (el && el.suffix !== '') {
264
+ const mp = step.produces.find((p) => p.kind === 'map' && p.stem === el.stem && p.suffix === el.suffix);
265
+ return mp?.schema === undefined ? undefined : { schema: mp.schema, appliesTo: 'value' };
266
+ }
267
+ const sealed = sealStem(path);
268
+ if (sealed !== null) {
269
+ const cp = step.produces.find((p) => p.kind === 'collection' && p.stem === sealed);
270
+ return cp?.schema === undefined ? undefined : { schema: cp.schema, appliesTo: 'member' };
271
+ }
272
+ const sp = step.produces.find((p) => p.kind === 'singleton' && p.stem === path);
273
+ return sp?.schema === undefined ? undefined : { schema: sp.schema, appliesTo: 'value' };
274
+ }
229
275
  /** An artifact is frozen (no firing re-arms it) when either stall trips or it is held. */
230
276
  function frozen(a, step) {
231
277
  if (!a)
@@ -558,6 +558,17 @@ export declare const WIRE_SCHEMAS: {
558
558
  };
559
559
  };
560
560
  };
561
+ schema: {
562
+ description: string;
563
+ oneOf: {
564
+ type: string;
565
+ }[];
566
+ };
567
+ schemaAppliesTo: {
568
+ description: string;
569
+ type: string;
570
+ enum: string[];
571
+ };
561
572
  proof: {
562
573
  type: string;
563
574
  };
@@ -579,6 +590,14 @@ export declare const WIRE_SCHEMAS: {
579
590
  minLength: number;
580
591
  };
581
592
  };
593
+ reroutedFrom: {
594
+ type: string;
595
+ description: string;
596
+ items: {
597
+ type: string;
598
+ minLength: number;
599
+ };
600
+ };
582
601
  modifier: {
583
602
  type: string;
584
603
  minLength: number;
@@ -96,6 +96,15 @@
96
96
  }
97
97
  }
98
98
  },
99
+ "schema": {
100
+ "description": "The JSON Schema the engine will enforce on this owed path at commit time, copied verbatim off the owning produce entry. Absent when that produce declares none, which is the common case and means any JSON is accepted. A JSON Schema is either a keyword object or a bare boolean, so both forms are admitted here.",
101
+ "oneOf": [{ "type": "object" }, { "type": "boolean" }]
102
+ },
103
+ "schemaAppliesTo": {
104
+ "description": "What `schema` governs. Present exactly when `schema` is. `value` — the value submitted to this path (a singleton produce, or one element of a map produce). `member` — each member emitted into this collection, NOT the seal value the path names; a collection's owed path is its seal while its declared schema is checked per member on emit.",
105
+ "type": "string",
106
+ "enum": ["value", "member"]
107
+ },
99
108
  "proof": { "type": "string" }
100
109
  }
101
110
  }
@@ -104,7 +113,12 @@
104
113
  "cause": { "type": "string", "enum": ["inputsGreen", "allGreen", "idle"] },
105
114
  "capabilities": {
106
115
  "type": "array",
107
- "description": "The composed routing capabilities this order was offered under: each authored step capability, suffixed ':<modifier>' where a modifier applied. A snapshot of the offer — a claimed order is never recomposed.",
116
+ "description": "The composed routing capabilities this order was offered under: each authored step capability, suffixed ':<modifier>' where a modifier applied. A snapshot of the offer — a claimed order is never recomposed. When 'reroutedFrom' is present this holds the reroute target instead, because this is the capability actually being served.",
117
+ "items": { "type": "string", "minLength": 1 }
118
+ },
119
+ "reroutedFrom": {
120
+ "type": "array",
121
+ "description": "The composed capabilities this order WOULD have been offered under, present only when a reroute rule substituted something else into 'capabilities'. Absent on every ordinary offer, so its presence is itself the signal that the order is not running on the capability its definition asked for.",
108
122
  "items": { "type": "string", "minLength": 1 }
109
123
  },
110
124
  "modifier": {
@@ -30,7 +30,7 @@ function resolvePolicyValue(env, explicit, envKey, settingsKey, label) {
30
30
  }
31
31
  return envValue;
32
32
  }
33
- // A missing HOME/XDG_CONFIG_HOME means there is no settings file to read;
33
+ // A missing HOME means there is no settings file to read;
34
34
  // the built-in default remains usable. Any other settings read/parse error is
35
35
  // surfaced rather than weakened into the least restrictive policy.
36
36
  let path;
@@ -172,8 +172,25 @@ export interface Order {
172
172
  * value the shift's settings map is keyed by. It is a snapshot of the offer:
173
173
  * an already-claimed order is never recomposed, so re-reading it later
174
174
  * always shows what the claim was actually judged on.
175
+ *
176
+ * When `reroutedFrom` is present this field holds the REROUTE TARGET, not
177
+ * what the def composed. That is deliberate: this is the capability being
178
+ * served, so it is the one a shift must resolve its model against.
175
179
  */
176
180
  capabilities?: string[];
181
+ /**
182
+ * The composed capabilities this order WOULD have been offered under, present
183
+ * only when a caller-supplied reroute rule substituted something else into
184
+ * `capabilities` above.
185
+ *
186
+ * Absent on every ordinary offer, so its presence is itself the signal that
187
+ * the order is not running on the capability its def asked for. Kept separate
188
+ * from `capabilities` rather than replacing it because both facts are true at
189
+ * once and an operator needs each for a different question: `capabilities`
190
+ * answers "what is serving this", `reroutedFrom` answers "what did we ask
191
+ * for". A single field could only ever answer one.
192
+ */
193
+ reroutedFrom?: string[];
177
194
  /**
178
195
  * The modifier this order was composed with. Normally the run's modifier;
179
196
  * on an escalated re-offer, the step's escalation target instead (the run's
@@ -189,10 +206,13 @@ export interface Order {
189
206
  *
190
207
  * The engine decides the transition; this flag is how the decision reaches
191
208
  * the layer that acts on it, instead of that layer re-deriving it by
192
- * diffing `modifier` against the run record. The hub reads it to apply the
193
- * escalation wait policy (wait-then-fallback, even where the deployment
194
- * default is `forever`); a brief reads it to tell the worker it is on the
195
- * recovery path.
209
+ * diffing `modifier` against the run record. A brief reads it to tell the
210
+ * worker it is on the recovery path.
211
+ *
212
+ * An escalated offer gets NO special wait or fallback treatment. It routes by
213
+ * exactly the same rules as any other offer, because "this run is recovering"
214
+ * is not evidence that its operator wants a lower grade of service — see
215
+ * `wait-policy.ts` in the hub.
196
216
  */
197
217
  escalated?: true;
198
218
  /** Opaque config object for a non-agent/non-command worker type (or
@@ -221,6 +241,40 @@ export interface Order {
221
241
  judgmentRejects: number;
222
242
  schemaRejects: number;
223
243
  reasons: ReasonEntry[];
244
+ /**
245
+ * The JSON Schema the engine will enforce on this output at commit time,
246
+ * copied verbatim off the owning produce entry. Absent when that produce
247
+ * declares none — the common case, and the engine then accepts any JSON.
248
+ *
249
+ * WHY IT IS ON THE ORDER. `schemaRejects` and the `'schema'` reason entries
250
+ * already travel here, so a producer is told AFTER the fact that the shape
251
+ * it submitted was wrong, and told the cap it is burning down. It was never
252
+ * told the shape. A re-offered agent reading "your last submission failed
253
+ * its schema" has the same information it had the first time and no more,
254
+ * which is why the same malformed shape gets resubmitted until the counter
255
+ * stalls the step. This closes that: the requirement is stated up front,
256
+ * from the same declaration the refusal will be measured against.
257
+ *
258
+ * It is a COPY, not a reference. The order is immutable once written
259
+ * (`RunData.order`), so this is the schema as it stood at claim time; a def
260
+ * edited mid-run leaves the projected schema and the enforced one able to
261
+ * disagree, exactly as `defDigest` already records for the rest of the
262
+ * order.
263
+ */
264
+ schema?: JsonSchema;
265
+ /**
266
+ * What `schema` governs. Present exactly when `schema` is.
267
+ *
268
+ * - `'value'` — the submitted value itself. Singleton produces, and one
269
+ * element of a map produce.
270
+ * - `'member'` — EACH member emitted into this collection. NOT the seal
271
+ * value at the path this entry names. A collection's owed path is its
272
+ * seal (`model.ts` `plainOutputs` pushes `sealPath(stem)`), while the
273
+ * declared schema is checked per member on `emit`, so projecting it
274
+ * without this discriminator would tell a producer to shape the seal
275
+ * like a member.
276
+ */
277
+ schemaAppliesTo?: 'value' | 'member';
224
278
  /** Opaque proof/signature placeholder for future WP-A4-signed reason
225
279
  * threads. Data-only today: no cryptographic code attaches or verifies
226
280
  * it — the slot exists so signed dynamic data can land without changing
@@ -3,8 +3,7 @@
3
3
  * into the execution-side settings file.
4
4
  *
5
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,
6
+ * (else `$HOME/.owenloop/settings.json`) and, by design,
8
7
  * NEVER writes them — the root CLI's `setup` command is the writer, so a fresh
9
8
  * `owenloop setup` can point `owenloop work` at the hub it just authenticated
10
9
  * against.
@@ -26,8 +25,7 @@
26
25
  /**
27
26
  * The execution settings file path for this environment, through the one shared
28
27
  * 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,
28
+ * wins over `$HOME/.owenloop`. Throws as a `CliError` when no rung yields a value,
31
29
  * so the CLI reports it as an operator error rather than a crash.
32
30
  */
33
31
  export declare function owenloopSettingsPath(env: Record<string, string | undefined>): string;
@@ -3,8 +3,7 @@
3
3
  * into the execution-side settings file.
4
4
  *
5
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,
6
+ * (else `$HOME/.owenloop/settings.json`) and, by design,
8
7
  * NEVER writes them — the root CLI's `setup` command is the writer, so a fresh
9
8
  * `owenloop setup` can point `owenloop work` at the hub it just authenticated
10
9
  * against.
@@ -31,8 +30,7 @@ import { CliError } from "./util.js";
31
30
  /**
32
31
  * The execution settings file path for this environment, through the one shared
33
32
  * 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,
33
+ * wins over `$HOME/.owenloop`. Throws as a `CliError` when no rung yields a value,
36
34
  * so the CLI reports it as an operator error rather than a crash.
37
35
  */
38
36
  export function owenloopSettingsPath(env) {
@@ -2,9 +2,9 @@
2
2
 
3
3
  `owenloop work agent-run` is the only supported dispatcher for workflow Step Agents. The Shift daemon starts `agent-run` children for agent orders. Plugins and skills supervise the Shift daemon; plugins do not package or dispatch a static workflow-worker agent.
4
4
 
5
- The runtime worker resolves the verified workflow definition from the local workflow store, selects the final harness after CLI and environment overrides, and runs permission preflight before either a cold start or a resume. A policy refusal starts no model SDK, CLI, or app-server process. The worker prints every refusal reason, releases the held claim, and exits non-zero.
5
+ The runtime worker resolves the verified workflow definition from the local workflow store, selects the final harness after crew-roster selection and any CLI debug override, and runs permission preflight before either a cold start or a resume. A policy refusal starts no model SDK, CLI, or app-server process. The worker prints every refusal reason, releases the held claim, and exits non-zero.
6
6
 
7
- Runtime preflight is authoritative. `owenloop work lint` runs the same common and adapter checks for author feedback, but lint cannot account for a later `--harness` or `OWENLOOP_HARNESS` override.
7
+ Runtime preflight is authoritative. `owenloop work lint` runs the same common and adapter checks for author feedback, but lint cannot account for a later `--harness` override or a selected crew-roster candidate.
8
8
 
9
9
  Native judge entries do not carry a separately authored `x` map. The definition
10
10
  compiler deep-clones the producer step's complete parsed `x` map onto every
package/docs/bundles.md CHANGED
@@ -292,7 +292,9 @@ shift. See [`docs/shift-logs.md`](shift-logs.md) for the directory layout,
292
292
 
293
293
  The receipt still does not carry the warning, and that is by design rather than
294
294
  a gap: the receipt captures the **command's** streams, and this warning is the
295
- **exec worker's** own. One destination each, no duplication.
295
+ **exec worker's** own. The reverse is not symmetric: the worker also relays the
296
+ command's captured tail into its own output, so a command's last 4 KiB appears
297
+ in both the receipt and `<run>.log`. See [docs/shift-logs.md](shift-logs.md).
296
298
 
297
299
  Two consequences worth stating separately:
298
300