owenloop 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +7 -8
- package/dist/packages/work/src/agent/capability-model.d.ts +64 -82
- package/dist/packages/work/src/agent/capability-model.js +94 -91
- package/dist/packages/work/src/agent/loop.d.ts +55 -26
- package/dist/packages/work/src/agent/loop.js +144 -50
- package/dist/packages/work/src/bundle/types.d.ts +3 -3
- package/dist/packages/work/src/consumed-verifier.js +6 -17
- package/dist/packages/work/src/exec/loop.d.ts +1 -1
- package/dist/packages/work/src/exec/loop.js +206 -35
- package/dist/packages/work/src/exec/receipt.d.ts +7 -7
- package/dist/packages/work/src/exec/receipt.js +6 -6
- package/dist/packages/work/src/harness/child-env.js +4 -5
- package/dist/packages/work/src/harness/claude.js +100 -0
- package/dist/packages/work/src/harness/codex.js +3 -4
- package/dist/packages/work/src/harness/session-store.d.ts +63 -3
- package/dist/packages/work/src/harness/session-store.js +104 -9
- package/dist/packages/work/src/hub/client.d.ts +19 -4
- package/dist/packages/work/src/hub/client.js +7 -3
- package/dist/packages/work/src/hub/types.d.ts +87 -3
- package/dist/packages/work/src/main.js +1 -0
- package/dist/packages/work/src/roles/agent-run.js +46 -43
- package/dist/packages/work/src/roles/exec.js +2 -0
- package/dist/packages/work/src/roles/sessions.d.ts +3 -2
- package/dist/packages/work/src/roles/sessions.js +9 -2
- package/dist/packages/work/src/roles/settings.js +3 -1
- package/dist/packages/work/src/roles/shift.js +14 -2
- package/dist/packages/work/src/roles/util.d.ts +1 -0
- package/dist/packages/work/src/roles/util.js +10 -0
- package/dist/packages/work/src/settings/hub-roster-cache.d.ts +68 -0
- package/dist/packages/work/src/settings/hub-roster-cache.js +370 -0
- package/dist/packages/work/src/settings/roster.d.ts +105 -0
- package/dist/packages/work/src/settings/roster.js +439 -0
- package/dist/packages/work/src/settings/serving.d.ts +17 -0
- package/dist/packages/work/src/settings/serving.js +79 -0
- package/dist/packages/work/src/settings/settings.d.ts +25 -24
- package/dist/packages/work/src/settings/settings.js +29 -33
- package/dist/packages/work/src/shift/loop.d.ts +108 -5
- package/dist/packages/work/src/shift/loop.js +299 -51
- package/dist/packages/work/src/shift/protocol.d.ts +7 -5
- package/dist/packages/work/src/shift/runtime.d.ts +15 -0
- package/dist/packages/work/src/shift/runtime.js +95 -13
- package/dist/packages/work/src/shift/server.js +2 -0
- package/dist/packages/work/src/shift/spawn.d.ts +18 -50
- package/dist/packages/work/src/shift/spawn.js +30 -65
- package/dist/packages/work/src/shift/state.d.ts +29 -2
- package/dist/packages/work/src/shift/state.js +45 -15
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +10 -5
- package/dist/packages/work/src/util/modifier-init.d.ts +7 -0
- package/dist/packages/work/src/util/modifier-init.js +73 -0
- package/dist/src/bundle/tar.d.ts +9 -4
- package/dist/src/bundle/tar.js +9 -4
- package/dist/src/capabilities.d.ts +50 -0
- package/dist/src/capabilities.js +38 -0
- package/dist/src/cli.d.ts +15 -1
- package/dist/src/cli.js +1099 -32
- package/dist/src/config-dir.d.ts +14 -19
- package/dist/src/config-dir.js +16 -24
- package/dist/src/credentials.d.ts +1 -1
- package/dist/src/credentials.js +1 -1
- package/dist/src/crypto/index.d.ts +1 -1
- package/dist/src/crypto/index.js +1 -1
- package/dist/src/crypto/org-root.d.ts +30 -12
- package/dist/src/crypto/org-root.js +162 -14
- package/dist/src/crypto/records.d.ts +3 -0
- package/dist/src/crypto/records.js +8 -0
- package/dist/src/crypto/trust-roots.d.ts +2 -2
- package/dist/src/crypto/trust-roots.js +2 -2
- package/dist/src/defs.d.ts +6 -1
- package/dist/src/defs.js +203 -8
- package/dist/src/engine.d.ts +55 -6
- package/dist/src/engine.js +172 -22
- package/dist/src/global-config.d.ts +4 -7
- package/dist/src/global-config.js +4 -7
- package/dist/src/hub.d.ts +207 -5
- package/dist/src/hub.js +263 -3
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.js +3 -3
- package/dist/src/mcp/serve.d.ts +22 -0
- package/dist/src/mcp/serve.js +88 -8
- package/dist/src/model.d.ts +2 -0
- package/dist/src/model.js +32 -25
- package/dist/src/order-resolver.d.ts +1 -0
- package/dist/src/order-resolver.js +8 -1
- package/dist/src/schemas/index.d.ts +19 -0
- package/dist/src/schemas/order.v1.schema.json +13 -2
- package/dist/src/store/pre-commit-verifier.js +1 -1
- package/dist/src/store.d.ts +5 -0
- package/dist/src/store.js +43 -8
- package/dist/src/types.d.ts +64 -7
- package/dist/src/work-settings.d.ts +2 -4
- package/dist/src/work-settings.js +2 -4
- package/docs/agent-runner.md +2 -2
- package/docs/authoring.md +90 -2
- package/docs/bundles.md +29 -3
- package/docs/cli.md +456 -120
- package/docs/crypto.md +32 -16
- package/docs/design.md +70 -1
- package/docs/routing.md +762 -0
- package/docs/shift-logs.md +37 -10
- package/docs/wire-contracts.md +50 -7
- package/examples/workflows/delivery.yaml +31 -14
- package/examples/workflows/ship.yaml +10 -2
- package/package.json +1 -1
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/plugin/.mcp.json +1 -1
- package/plugins/claude-code/plugin/skills/author/SKILL.md +1 -2
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
- package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +1 -2
|
@@ -3,10 +3,11 @@ import type { ContactHolder, OrderPacket } from '../hub/types.ts';
|
|
|
3
3
|
import type { ConsumedVerifier } from '../consumed-verifier.ts';
|
|
4
4
|
import type { NormalizedStepSpec } from '../bundle/types.ts';
|
|
5
5
|
import type { HarnessAdapter } from '../harness/contract.ts';
|
|
6
|
-
import { type SessionRecord } from '../harness/session-store.ts';
|
|
7
|
-
import { type
|
|
6
|
+
import { type SessionRecord, type SessionTaskRef } from '../harness/session-store.ts';
|
|
7
|
+
import { type CapabilityMatch } from './capability-model.ts';
|
|
8
|
+
import type { MergedRoster } from '../settings/roster.ts';
|
|
8
9
|
/** Discriminated result of one worker life; the role maps these to exit codes. */
|
|
9
|
-
export type AgentRunOutcome = 'submitted' | 'completed' | 'misroute' | 'workdir-denied' | 'no-template' | 'no-harness' | 'incompatible-harness-policy' | 'unresolvable-capability' | 'unverified-consumed' | 'session-store-failed' | 'no-submit' | 'killed' | 'lease-lost' | 'ownership-error' | 'hub-unreachable' | 'stopped';
|
|
10
|
+
export type AgentRunOutcome = 'submitted' | 'completed' | 'misroute' | 'workdir-denied' | 'no-template' | 'no-harness' | 'incompatible-harness-policy' | 'unstamped-order' | 'unresolvable-crew' | 'unresolvable-capability' | 'unverified-consumed' | 'session-store-failed' | 'no-submit' | 'killed' | 'lease-lost' | 'ownership-error' | 'hub-unreachable' | 'stopped';
|
|
10
11
|
/**
|
|
11
12
|
* Locate the normalized step spec for an order. Injected because the lookup is
|
|
12
13
|
* I/O (the verified workflow store) and because resolving the local definition
|
|
@@ -22,9 +23,10 @@ export type StepLoader = (order: OrderPacket) => Promise<NormalizedStepSpec | nu
|
|
|
22
23
|
* The outcome of resolving which adapter hosts this step agent.
|
|
23
24
|
*
|
|
24
25
|
* The loop never reads a registry and never names a harness: the role
|
|
25
|
-
* (`src/roles/agent-run.ts`, the composition root) owns the precedence
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* (`src/roles/agent-run.ts`, the composition root) owns the precedence:
|
|
27
|
+
* selected roster candidate > `--harness` > step harness > registered
|
|
28
|
+
* default. The selected harness is supplied separately because routing decides
|
|
29
|
+
* it before adapter resolution.
|
|
28
30
|
* `registered` is only ever used to make the failure message actionable.
|
|
29
31
|
*/
|
|
30
32
|
export interface AdapterResolution {
|
|
@@ -32,8 +34,23 @@ export interface AdapterResolution {
|
|
|
32
34
|
adapter?: HarnessAdapter;
|
|
33
35
|
registered: string[];
|
|
34
36
|
}
|
|
35
|
-
/**
|
|
36
|
-
export type AdapterResolver = (stepHarness: string | undefined) => AdapterResolution;
|
|
37
|
+
/** The two harness inputs are rank 1 (roster) and rank 3 (step definition). */
|
|
38
|
+
export type AdapterResolver = (chosenHarness: string | undefined, stepHarness: string | undefined) => AdapterResolution;
|
|
39
|
+
/** Outcome of turning a STAMPED crew name list into merged rosters. */
|
|
40
|
+
export type CrewRosterResolution = {
|
|
41
|
+
ok: true;
|
|
42
|
+
rosters: readonly MergedRoster[];
|
|
43
|
+
} | {
|
|
44
|
+
ok: false;
|
|
45
|
+
crew: string;
|
|
46
|
+
detail: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Turns the crews the HUB STAMPED on an order into merged rosters, in the
|
|
50
|
+
* stamped order. Injected by the role so the loop stays free of filesystem and
|
|
51
|
+
* environment reads.
|
|
52
|
+
*/
|
|
53
|
+
export type CrewRosterResolver = (crews: readonly string[]) => CrewRosterResolution;
|
|
37
54
|
/** Default confirm-phase cadence: one `get_order` per second. */
|
|
38
55
|
export declare const DEFAULT_CONFIRM_INTERVAL_MS = 1000;
|
|
39
56
|
/** Default confirm-phase bound: give the hub 15s to show the submit's outcome. */
|
|
@@ -68,27 +85,30 @@ export interface AgentRunLoopOptions {
|
|
|
68
85
|
loadStep: StepLoader;
|
|
69
86
|
resolveAdapter: AdapterResolver;
|
|
70
87
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* against it before dispatch and REFUSES the order when nothing matches —
|
|
74
|
-
* there is no default model here, by design.
|
|
75
|
-
*
|
|
76
|
-
* Absent (or empty) means the shift declared no map at all, which makes every
|
|
77
|
-
* capability-bearing order unresolvable. That is deliberate: a shift that
|
|
78
|
-
* forgot its map should say so on the first order, not run everything on a
|
|
79
|
-
* hardcoded model.
|
|
88
|
+
* Resolves the crews the hub stamped on the order. REQUIRED — this loop has
|
|
89
|
+
* no crew source other than the order's stamp.
|
|
80
90
|
*/
|
|
81
|
-
|
|
91
|
+
resolveCrewRosters: CrewRosterResolver;
|
|
92
|
+
/**
|
|
93
|
+
* Phase-1 availability is adapter-registry membership at the composition
|
|
94
|
+
* root. A real binary/credential probe needs new adapter-contract surface.
|
|
95
|
+
*/
|
|
96
|
+
harnessAvailable: (harnessId: string) => boolean;
|
|
82
97
|
/** Gate dynamic values and rejection reasons before any prompt rendering. */
|
|
83
98
|
consumedVerifier?: ConsumedVerifier;
|
|
84
99
|
/** Append one session record. Wired to `appendSession` by the role. */
|
|
85
100
|
appendSession: (rec: SessionRecord) => void;
|
|
86
|
-
/** The attempt number for this `(workflow, run, step)`. Wired to `latestFor`. */
|
|
87
|
-
nextAttempt: (workflow: string, run: string, step: string) => number;
|
|
88
101
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* the
|
|
102
|
+
* The attempt number for this engine TASK — `(workflow, step, key)`, not
|
|
103
|
+
* `(workflow, run, step)`. Wired to `latestForTask`. Keyed on the task because
|
|
104
|
+
* the hub re-mints `run` on every firing: keyed on the run this could only ever
|
|
105
|
+
* return 1, and it did, for every firing this machine has ever executed.
|
|
106
|
+
*/
|
|
107
|
+
nextAttempt: (task: SessionTaskRef) => number;
|
|
108
|
+
/**
|
|
109
|
+
* PHASE 4 — the last session record for this engine TASK, or `null` when the
|
|
110
|
+
* task has never run here. Wired to `latestForTask(sessionsFile, ...)` by the
|
|
111
|
+
* role, the same reader `nextAttempt` already uses.
|
|
92
112
|
*
|
|
93
113
|
* It is what makes a resume possible at all: the prior `token` to resume, the
|
|
94
114
|
* `harness` that minted it, the `cwd` it is scoped to, and the
|
|
@@ -96,7 +116,7 @@ export interface AgentRunLoopOptions {
|
|
|
96
116
|
* heard. Absent (or returning `null`) ⇒ every firing is a cold start, which is
|
|
97
117
|
* exactly the pre-Phase-4 behaviour.
|
|
98
118
|
*/
|
|
99
|
-
latestSession?: (
|
|
119
|
+
latestSession?: (task: SessionTaskRef) => SessionRecord | null;
|
|
100
120
|
/**
|
|
101
121
|
* Does this directory still exist? Injected for the same reason every other
|
|
102
122
|
* side effect here is: a unit test drives the "the work dir was reaped, so the
|
|
@@ -159,10 +179,19 @@ export interface ConfirmOptions {
|
|
|
159
179
|
*/
|
|
160
180
|
export type OrderRouting = {
|
|
161
181
|
kind: 'resolved';
|
|
162
|
-
|
|
182
|
+
capability: string;
|
|
183
|
+
match: CapabilityMatch;
|
|
184
|
+
harness: string;
|
|
185
|
+
model: string;
|
|
186
|
+
effort: string;
|
|
163
187
|
} | {
|
|
164
188
|
kind: 'refused';
|
|
165
189
|
capabilities: readonly string[];
|
|
190
|
+
reason: 'harness-policy' | 'unstamped-order' | 'unresolvable-crew' | 'unresolvable-capability';
|
|
191
|
+
offered?: readonly string[];
|
|
192
|
+
stepHarness?: string;
|
|
193
|
+
crew?: string;
|
|
194
|
+
detail?: string;
|
|
166
195
|
} | {
|
|
167
196
|
kind: 'unrouted';
|
|
168
197
|
};
|
|
@@ -174,7 +203,7 @@ export type OrderRouting = {
|
|
|
174
203
|
* abstract rung with no meaning left, and reading it as a model id would put a
|
|
175
204
|
* literal `strong` on the wire to a vendor.
|
|
176
205
|
*/
|
|
177
|
-
export declare function resolveOrderRouting(packet: OrderPacket,
|
|
206
|
+
export declare function resolveOrderRouting(packet: OrderPacket, resolveCrewRosters: CrewRosterResolver, stepHarness: string | undefined, isAvailable: (harnessId: string) => boolean): OrderRouting;
|
|
178
207
|
/**
|
|
179
208
|
* Poll `get_order` at `intervalMs` for at most `graceMs`, answering ONE
|
|
180
209
|
* question: did the hub see the agent's `submit`?
|
|
@@ -62,9 +62,9 @@ import { createApprovalRequester } from "./approvals.js";
|
|
|
62
62
|
import { createLeaseLoop } from "../lease/loop.js";
|
|
63
63
|
import { isResumeUnavailable } from "../harness/contract.js";
|
|
64
64
|
import { preflightStepPermissions } from "../harness/permissions.js";
|
|
65
|
-
import { orderId } from "../harness/session-store.js";
|
|
65
|
+
import { orderId, } from "../harness/session-store.js";
|
|
66
66
|
import { buildOwenloopMcp, renderBrief, renderRejection, renderReplayBrief, } from "./brief.js";
|
|
67
|
-
import {
|
|
67
|
+
import { resolveCapabilityCandidates, selectCandidate, } from "./capability-model.js";
|
|
68
68
|
/** Default confirm-phase cadence: one `get_order` per second. */
|
|
69
69
|
export const DEFAULT_CONFIRM_INTERVAL_MS = 1_000;
|
|
70
70
|
/** Default confirm-phase bound: give the hub 15s to show the submit's outcome. */
|
|
@@ -124,12 +124,83 @@ function briefOwes(packet) {
|
|
|
124
124
|
* abstract rung with no meaning left, and reading it as a model id would put a
|
|
125
125
|
* literal `strong` on the wire to a vendor.
|
|
126
126
|
*/
|
|
127
|
-
export function resolveOrderRouting(packet,
|
|
127
|
+
export function resolveOrderRouting(packet, resolveCrewRosters, stepHarness, isAvailable) {
|
|
128
128
|
const capabilities = packet.capabilities ?? [];
|
|
129
129
|
if (capabilities.length === 0)
|
|
130
130
|
return { kind: 'unrouted' };
|
|
131
|
-
const
|
|
132
|
-
|
|
131
|
+
const stamp = packet.crews;
|
|
132
|
+
if (stamp === undefined) {
|
|
133
|
+
return {
|
|
134
|
+
kind: 'refused',
|
|
135
|
+
capabilities,
|
|
136
|
+
reason: 'unstamped-order',
|
|
137
|
+
detail: 'the order carries no crews field',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (!Array.isArray(stamp) || stamp.length === 0) {
|
|
141
|
+
return {
|
|
142
|
+
kind: 'refused',
|
|
143
|
+
capabilities,
|
|
144
|
+
reason: 'unstamped-order',
|
|
145
|
+
detail: `unusable crews stamp (${JSON.stringify(stamp)})`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (stamp.some((crew) => typeof crew !== 'string' || crew.trim() === '')) {
|
|
149
|
+
return {
|
|
150
|
+
kind: 'refused',
|
|
151
|
+
capabilities,
|
|
152
|
+
reason: 'unstamped-order',
|
|
153
|
+
detail: `unusable crews stamp (${JSON.stringify(stamp)})`,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const resolved = resolveCrewRosters(stamp);
|
|
157
|
+
if (!resolved.ok) {
|
|
158
|
+
return {
|
|
159
|
+
kind: 'refused',
|
|
160
|
+
capabilities,
|
|
161
|
+
reason: 'unresolvable-crew',
|
|
162
|
+
crew: resolved.crew,
|
|
163
|
+
detail: resolved.detail,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
let firstHarnessPolicy;
|
|
167
|
+
for (const roster of resolved.rosters) {
|
|
168
|
+
// Preserve arbitrary capability names through the boundary between the
|
|
169
|
+
// provenance-bearing merged roster and the candidate-only selector.
|
|
170
|
+
const candidateRows = Object.create(null);
|
|
171
|
+
for (const capability of Object.keys(roster)) {
|
|
172
|
+
if (!Object.prototype.hasOwnProperty.call(roster, capability))
|
|
173
|
+
continue;
|
|
174
|
+
candidateRows[capability] = roster[capability].candidates;
|
|
175
|
+
}
|
|
176
|
+
const candidates = resolveCapabilityCandidates(candidateRows, capabilities);
|
|
177
|
+
if (candidates === undefined)
|
|
178
|
+
continue;
|
|
179
|
+
const outcome = selectCandidate(candidates.candidates, stepHarness, isAvailable);
|
|
180
|
+
if (outcome.kind === 'selected') {
|
|
181
|
+
return {
|
|
182
|
+
kind: 'resolved',
|
|
183
|
+
capability: candidates.capability,
|
|
184
|
+
match: candidates.match,
|
|
185
|
+
harness: outcome.candidate.harness,
|
|
186
|
+
model: outcome.candidate.model,
|
|
187
|
+
effort: outcome.candidate.effort,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (outcome.kind === 'harness-policy' && firstHarnessPolicy === undefined) {
|
|
191
|
+
firstHarnessPolicy = { offered: outcome.offered, stepHarness };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (firstHarnessPolicy !== undefined) {
|
|
195
|
+
return {
|
|
196
|
+
kind: 'refused',
|
|
197
|
+
capabilities,
|
|
198
|
+
reason: 'harness-policy',
|
|
199
|
+
offered: firstHarnessPolicy.offered,
|
|
200
|
+
...(firstHarnessPolicy.stepHarness !== undefined ? { stepHarness: firstHarnessPolicy.stepHarness } : {}),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return { kind: 'refused', capabilities, reason: 'unresolvable-capability' };
|
|
133
204
|
}
|
|
134
205
|
/**
|
|
135
206
|
* Poll `get_order` at `intervalMs` for at most `graceMs`, answering ONE
|
|
@@ -184,6 +255,10 @@ export function createAgentRunLoop(opts) {
|
|
|
184
255
|
let sessionRef;
|
|
185
256
|
let adapterId = '';
|
|
186
257
|
let stepName = '';
|
|
258
|
+
/** `OrderPacket.key`, set beside `stepName` when the packet arrives. Typed
|
|
259
|
+
* `undefined`-until-known rather than defaulted to `''`, because `''` is the
|
|
260
|
+
* REAL key of an unfanned step and must not double as "not known yet". */
|
|
261
|
+
let stepKey;
|
|
187
262
|
let attempt = 1;
|
|
188
263
|
let createdAt = 0;
|
|
189
264
|
let recordCwd = opts.cwd;
|
|
@@ -229,6 +304,12 @@ export function createAgentRunLoop(opts) {
|
|
|
229
304
|
workflow,
|
|
230
305
|
run: runId,
|
|
231
306
|
step: stepName,
|
|
307
|
+
// Written whenever the packet is known — which, given the guard above, is
|
|
308
|
+
// always. The conditional spread exists so the field is OMITTED rather
|
|
309
|
+
// than forged if that ever stops being true: an absent `key` means "cannot
|
|
310
|
+
// be attributed to a task" and costs a cold start, while a wrong `key`
|
|
311
|
+
// would hand a worker another task's session.
|
|
312
|
+
...(stepKey !== undefined ? { key: stepKey } : {}),
|
|
232
313
|
order,
|
|
233
314
|
attempt,
|
|
234
315
|
harness: sessionRef?.harness ?? adapterId,
|
|
@@ -337,21 +418,21 @@ export function createAgentRunLoop(opts) {
|
|
|
337
418
|
* An `unrouted` order is not reported at all: the payload's `capability` is
|
|
338
419
|
* required and non-empty on the hub side, and there is no capability to name.
|
|
339
420
|
*/
|
|
340
|
-
async function reportResolution(routing
|
|
421
|
+
async function reportResolution(routing) {
|
|
341
422
|
if (routing.kind === 'unrouted')
|
|
342
423
|
return;
|
|
343
424
|
const payload = routing.kind === 'resolved'
|
|
344
425
|
? {
|
|
345
|
-
capability: routing.
|
|
346
|
-
match: routing.
|
|
347
|
-
model: routing.
|
|
348
|
-
effort: routing.
|
|
349
|
-
harness,
|
|
426
|
+
capability: routing.capability,
|
|
427
|
+
match: routing.match,
|
|
428
|
+
model: routing.model,
|
|
429
|
+
effort: routing.effort,
|
|
430
|
+
harness: routing.harness,
|
|
350
431
|
}
|
|
351
432
|
: // The refusal names the capability the order was OFFERED under — the
|
|
352
433
|
// first one — because that is the row an operator has to add. Model
|
|
353
434
|
// and effort are absent: nothing was selected.
|
|
354
|
-
{ capability: routing.capabilities[0] ?? '', match: 'refused'
|
|
435
|
+
{ capability: routing.capabilities[0] ?? '', match: 'refused' };
|
|
355
436
|
try {
|
|
356
437
|
await opts.hub.reportResolution({ workflow, run: runId, resolution: payload });
|
|
357
438
|
}
|
|
@@ -412,6 +493,7 @@ export function createAgentRunLoop(opts) {
|
|
|
412
493
|
}
|
|
413
494
|
}
|
|
414
495
|
stepName = packet.step;
|
|
496
|
+
stepKey = packet.key;
|
|
415
497
|
recordCwd = packet.workdir ?? opts.cwd;
|
|
416
498
|
// MACHINE POLICY. The operator who started this shift named the directories
|
|
417
499
|
// work may happen in (`owenloop shift start --work-root`, or
|
|
@@ -454,7 +536,33 @@ export function createAgentRunLoop(opts) {
|
|
|
454
536
|
/** `material` is a `let`, so its null-narrowing does not survive into the
|
|
455
537
|
* closures below. This const carries the narrowing across. */
|
|
456
538
|
const step = material;
|
|
457
|
-
|
|
539
|
+
// ---- ROUTING: select a roster candidate before resolving an adapter ----
|
|
540
|
+
const routing = resolveOrderRouting(packet, opts.resolveCrewRosters, step.harness, opts.harnessAvailable);
|
|
541
|
+
await reportResolution(routing);
|
|
542
|
+
if (routing.kind === 'refused') {
|
|
543
|
+
if (routing.reason === 'harness-policy') {
|
|
544
|
+
opts.err(`owenloop work agent-run: step '${packet.step}' declares harness '${routing.stepHarness ?? ''}', ` +
|
|
545
|
+
`but its roster candidates offer [${(routing.offered ?? []).join(', ')}] — releasing`);
|
|
546
|
+
return releaseWith('incompatible-harness-policy', 'incompatible-harness-policy');
|
|
547
|
+
}
|
|
548
|
+
if (routing.reason === 'unstamped-order') {
|
|
549
|
+
opts.err(packet.crews === undefined
|
|
550
|
+
? `owenloop work agent-run: order ${order} was offered under capabilities [${routing.capabilities.join(', ')}] but carries NO crews stamp. This worker resolves crew rosters only from the hub's offer-time stamp; there is no fallback to the crews this shift was started with. The hub at ${opts.origin} must stamp crews on every capability-bearing order. Releasing.`
|
|
551
|
+
: `owenloop work agent-run: order ${order} was offered under capabilities [${routing.capabilities.join(', ')}] but carries an unusable crews stamp (${JSON.stringify(packet.crews)}). Expected a non-empty array of non-empty crew names. This worker resolves crew rosters only from the hub's offer-time stamp; there is no fallback to the crews this shift was started with. The hub at ${opts.origin} must stamp crews on every capability-bearing order. Releasing.`);
|
|
552
|
+
return releaseWith('unstamped-order', 'unstamped-order');
|
|
553
|
+
}
|
|
554
|
+
if (routing.reason === 'unresolvable-crew') {
|
|
555
|
+
opts.err(`owenloop work agent-run: order ${order} is stamped with crews [${packet.crews.join(', ')}], but crew '${routing.crew}' cannot be resolved on this machine: ${routing.detail}. Releasing.`);
|
|
556
|
+
return releaseWith('unresolvable-crew', 'unresolvable-crew');
|
|
557
|
+
}
|
|
558
|
+
opts.err(`owenloop work agent-run: no crew roster row for ${order} — the order's capabilities ` +
|
|
559
|
+
`[${routing.capabilities.join(', ')}] match neither an exact row nor a bare name row in 'roster'. ` +
|
|
560
|
+
`Add a candidate array for one of them and restart the shift. Releasing — this shift will not pick ` +
|
|
561
|
+
`a model it was not told to use.`);
|
|
562
|
+
return releaseWith('unresolvable-capability', 'unresolvable-capability');
|
|
563
|
+
}
|
|
564
|
+
const chosenHarnessId = routing.kind === 'resolved' ? routing.harness : undefined;
|
|
565
|
+
const resolution = opts.resolveAdapter(chosenHarnessId, step.harness);
|
|
458
566
|
adapterId = resolution.id;
|
|
459
567
|
if (resolution.adapter === undefined) {
|
|
460
568
|
const known = resolution.registered.length > 0 ? resolution.registered.join(', ') : '<none>';
|
|
@@ -465,27 +573,24 @@ export function createAgentRunLoop(opts) {
|
|
|
465
573
|
/** The same object as `adapter`, but narrowed — the module-scope `adapter`
|
|
466
574
|
* stays `HarnessAdapter | undefined` for `teardown`/`stop`. */
|
|
467
575
|
const active = resolution.adapter;
|
|
468
|
-
|
|
576
|
+
/** This firing's engine task. Built once, from the packet, and used for both
|
|
577
|
+
* the attempt count and the Phase 4 resume lookup so the two can never
|
|
578
|
+
* disagree about which history they are reading. */
|
|
579
|
+
const task = { workflow, step: packet.step, key: packet.key };
|
|
580
|
+
attempt = opts.nextAttempt(task);
|
|
469
581
|
const spec = {
|
|
470
582
|
workflow,
|
|
471
583
|
run: runId,
|
|
472
584
|
origin: opts.origin,
|
|
473
585
|
account: opts.account,
|
|
474
586
|
...(opts.shiftId !== undefined ? { shiftId: opts.shiftId } : {}),
|
|
475
|
-
// Straight from the packet, not from settings: the modifier is the hub's
|
|
476
|
-
// statement about the RUN, and a shift has no say in it.
|
|
477
587
|
...(packet.modifier !== undefined ? { modifier: packet.modifier } : {}),
|
|
478
588
|
...(packet.escalated === true ? { escalated: true } : {}),
|
|
479
589
|
owes: briefOwes(packet),
|
|
480
590
|
};
|
|
481
|
-
// Permissions arrive PRE-NORMALIZED in the spec. `prepare` ran
|
|
482
|
-
// `normalizeStepPermissions` over the step's `x.harness` options at cache
|
|
483
|
-
// time, so this loop never looks inside an extension bag and never has a bag
|
|
484
|
-
// key — vendor-keyed lookup does not exist in neutral code any more.
|
|
485
591
|
const permissions = step.permissions;
|
|
486
592
|
// Mandatory final-boundary preflight. Common checks run first, followed by
|
|
487
|
-
// the selected adapter's exact capability check.
|
|
488
|
-
// cold session nor a resumed provider process; the held claim is released.
|
|
593
|
+
// the selected adapter's exact capability check.
|
|
489
594
|
const policyIssues = [
|
|
490
595
|
...preflightStepPermissions(permissions),
|
|
491
596
|
...active.preflight(permissions),
|
|
@@ -497,35 +602,13 @@ export function createAgentRunLoop(opts) {
|
|
|
497
602
|
}
|
|
498
603
|
return releaseWith('incompatible-harness-policy', 'incompatible-harness-policy');
|
|
499
604
|
}
|
|
500
|
-
// ---- ROUTING: which model serves this order, and telling the hub --------
|
|
501
|
-
//
|
|
502
|
-
// DELIBERATELY THE LAST GATE BEFORE DISPATCH, and deliberately AFTER every
|
|
503
|
-
// launch gate above (misroute, consumed verification, step spec, adapter,
|
|
504
|
-
// harness policy). Plan §3: the launch gates block on a malformed order
|
|
505
|
-
// before model selection is even attempted, so a refusal never has to be
|
|
506
|
-
// explained in terms of a model the order was never going to reach.
|
|
507
|
-
const routing = resolveOrderRouting(packet, opts.capabilityModels);
|
|
508
|
-
// Plan §6: the record must exist BEFORE tokens are spent, which is why this
|
|
509
|
-
// is a dedicated verb and not a field on the next heartbeat. It is reported
|
|
510
|
-
// on the refusal path too — a refusal is a true observation of what this
|
|
511
|
-
// shift resolved, and the whole point of the report is that the hub can say
|
|
512
|
-
// why an order did or did not run.
|
|
513
|
-
await reportResolution(routing, resolution.id);
|
|
514
|
-
if (routing.kind === 'refused') {
|
|
515
|
-
opts.err(`owenloop work agent-run: no settings row for ${order} — the order's capabilities ` +
|
|
516
|
-
`[${routing.capabilities.join(', ')}] match neither an exact row nor a bare name row in ` +
|
|
517
|
-
`'capabilityModels'. Add a row for one of them (a bare row such as ` +
|
|
518
|
-
`'${routing.capabilities[0]?.split(':')[0] ?? ''}' covers every modifier) and restart the shift. ` +
|
|
519
|
-
`Releasing — this shift will not pick a model it was not told to use.`);
|
|
520
|
-
return releaseWith('unresolvable-capability', 'unresolvable-capability');
|
|
521
|
-
}
|
|
522
605
|
if (routing.kind === 'unrouted') {
|
|
523
|
-
opts.err(`owenloop work agent-run: ${order} carries no capabilities, so no
|
|
524
|
-
`running on '${resolution.id}'
|
|
606
|
+
opts.err(`owenloop work agent-run: ${order} carries no capabilities, so no crew roster row applies — ` +
|
|
607
|
+
`running on '${resolution.id}'s own default model.`);
|
|
525
608
|
}
|
|
526
609
|
else {
|
|
527
|
-
opts.out(`owenloop work agent-run: ${order} resolved '${routing.
|
|
528
|
-
|
|
610
|
+
opts.out(`owenloop work agent-run: ${order} resolved '${routing.capability}' (${routing.match} row) → ` +
|
|
611
|
+
`${routing.harness}/${routing.model} at ${routing.effort}`);
|
|
529
612
|
}
|
|
530
613
|
// ---- PHASE 4: resume or cold replay? -----------------------------------
|
|
531
614
|
//
|
|
@@ -533,7 +616,7 @@ export function createAgentRunLoop(opts) {
|
|
|
533
616
|
// resume preconditions. `renderRejection` reads `packet.owes[].reasons`
|
|
534
617
|
// filtered to `at > prev.deliveredReasonAt` — the packet's `owes` IS the set
|
|
535
618
|
// of paths being re-armed, so no extra path filter is needed here.
|
|
536
|
-
const prev = opts.latestSession?.(
|
|
619
|
+
const prev = opts.latestSession?.(task) ?? null;
|
|
537
620
|
const dirExists = opts.dirExists ?? existsSync;
|
|
538
621
|
const delta = renderRejection({
|
|
539
622
|
packet,
|
|
@@ -553,6 +636,14 @@ export function createAgentRunLoop(opts) {
|
|
|
553
636
|
// dirExists(prev.cwd) a reaped work dir invalidates the session
|
|
554
637
|
// delta.message !== '' nothing new to say — a resume that says
|
|
555
638
|
// nothing spends a turn communicating nothing
|
|
639
|
+
//
|
|
640
|
+
// ON `prev.cwd === recordCwd` NOW THAT `prev` CAN ACTUALLY BE FOUND. An order
|
|
641
|
+
// carrying an explicit `packet.workdir` names the same directory on every
|
|
642
|
+
// firing, so this passes and the resume happens. An order with no `workdir`
|
|
643
|
+
// falls back to `<workRoot>/<workflow>/<run>` (see `agent/workdir.ts`), which
|
|
644
|
+
// moves with the run id — so this declines and the firing starts cold. That
|
|
645
|
+
// is the guard doing its job, not a leftover: the previous session's files
|
|
646
|
+
// genuinely are in a directory this firing is not working in.
|
|
556
647
|
const resumable = prev !== null &&
|
|
557
648
|
prev.token !== '' &&
|
|
558
649
|
prev.harness === resolution.id &&
|
|
@@ -604,8 +695,11 @@ export function createAgentRunLoop(opts) {
|
|
|
604
695
|
run: opts.run,
|
|
605
696
|
onEvent: (e) => opts.out(`owenloop work agent-run: approval ${e.kind} — ${e.text}`),
|
|
606
697
|
});
|
|
698
|
+
// A resolved crew-roster candidate wins over the step's authored harness,
|
|
699
|
+
// model, and effort. The harness was already selected above; these values
|
|
700
|
+
// keep the established rule for the adapter start arguments.
|
|
607
701
|
const resolvedModel = routing.kind === 'resolved'
|
|
608
|
-
? { model: routing.
|
|
702
|
+
? { model: routing.model, effort: routing.effort }
|
|
609
703
|
: undefined;
|
|
610
704
|
const deliverArgs = {
|
|
611
705
|
cwd: recordCwd,
|
|
@@ -62,9 +62,9 @@ export interface FetchedStep {
|
|
|
62
62
|
* LIFTED by `validateFetchedDef` from `x.harness.id`, or from a top-level
|
|
63
63
|
* `harness` key when the def carries one (top-level WINS — forward compat for
|
|
64
64
|
* an owenloop grammar that promotes the field). Declaration only: nothing
|
|
65
|
-
* validates the id here; `src/roles/agent-run.ts`
|
|
66
|
-
*
|
|
67
|
-
* registered adapter.
|
|
65
|
+
* validates the id here; `src/roles/agent-run.ts` uses it after a selected
|
|
66
|
+
* roster candidate and an explicit `--harness`, and fails honestly when the
|
|
67
|
+
* id names no registered adapter.
|
|
68
68
|
*/
|
|
69
69
|
harness?: string;
|
|
70
70
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { mergePolicyFloorWithLocal, } from "../../../src/crypto/policy-floor.js";
|
|
10
10
|
import { resolveArtifactPolicy, } from "../../../src/store/pre-commit-verifier.js";
|
|
11
|
-
import { loadRevocations,
|
|
11
|
+
import { loadRevocations, loadGrants, resolveOrgRoot, } from "../../../src/crypto/org-root.js";
|
|
12
12
|
import { verifyConsumed, } from "../../../src/crypto/verify-consumed.js";
|
|
13
13
|
import { validateProducer } from "../../../src/crypto/chain.js";
|
|
14
14
|
/** Missing-org-root warnings are intentionally latched once per order process-wide. */
|
|
@@ -97,25 +97,14 @@ export function createConsumedVerifier(args) {
|
|
|
97
97
|
let revocations;
|
|
98
98
|
try {
|
|
99
99
|
root = resolveOrgRoot(args.env);
|
|
100
|
-
grants =
|
|
100
|
+
grants = loadGrants(args.env);
|
|
101
101
|
revocations = loadRevocations(args.env);
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (result !== undefined)
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
for (const owed of order.owes) {
|
|
112
|
-
if (owed.reasons.length === 0 && owed.proof === undefined)
|
|
113
|
-
continue;
|
|
114
|
-
const result = policyOutcome(order, opts.hardRule, policy, owed.path, { kind: 'unverifiable', reason }, warnings);
|
|
115
|
-
if (result !== undefined)
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
return { ok: true, order, warnings };
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
reason: `consumed artifact gate refusal for ${order.workflow}/${order.run} step '${order.step}': local producer trust material could not be loaded: ${errorText(error)}`,
|
|
107
|
+
};
|
|
119
108
|
}
|
|
120
109
|
const prerequisite = root.kind === 'absent'
|
|
121
110
|
? 'prerequisite: no org-root anchor is configured'
|
|
@@ -22,7 +22,7 @@ import type { SshProcessAdapter } from '../../../../src/crypto/ssh.ts';
|
|
|
22
22
|
*/
|
|
23
23
|
export declare const CONSUMES_INLINE_MAX_BYTES = 65536;
|
|
24
24
|
/** Discriminated result of an exec run; the role maps these to exit codes. */
|
|
25
|
-
export type ExecOutcome = 'submitted' | 'completed' | 'misroute' | 'workdir-denied' | 'unresolved-instructions' | 'killed' | 'lease-lost' | 'ownership-error' | 'hub-unreachable' | 'submit-rejected' | 'submit-failed' | 'rejected' | 'judge-rejected' | 'judge-no-verdict' | 'reject-failed' | 'stopped';
|
|
25
|
+
export type ExecOutcome = 'submitted' | 'completed' | 'misroute' | 'workdir-denied' | 'unresolved-instructions' | 'killed' | 'lease-lost' | 'ownership-error' | 'hub-unreachable' | 'submit-rejected' | 'submit-failed' | 'command-failed' | 'ask-failed' | 'rejected' | 'judge-rejected' | 'judge-no-verdict' | 'reject-failed' | 'stopped';
|
|
26
26
|
export interface ExecLoopOptions {
|
|
27
27
|
hub: HubClient;
|
|
28
28
|
runner: CommandRunner;
|