owenloop 0.5.1 → 0.5.3
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 +30 -0
- package/README.md +9 -2
- package/dist/packages/work/src/agent/brief.d.ts +21 -0
- package/dist/packages/work/src/agent/brief.js +42 -1
- package/dist/packages/work/src/agent/capability-model.d.ts +123 -0
- package/dist/packages/work/src/agent/capability-model.js +148 -0
- package/dist/packages/work/src/agent/loop.d.ts +47 -4
- package/dist/packages/work/src/agent/loop.js +83 -53
- package/dist/packages/work/src/exec/loop.d.ts +17 -0
- package/dist/packages/work/src/exec/loop.js +195 -34
- package/dist/packages/work/src/exec/runner.js +15 -5
- package/dist/packages/work/src/harness/claude.js +69 -9
- package/dist/packages/work/src/harness/codex.js +56 -8
- package/dist/packages/work/src/harness/contract.d.ts +65 -1
- package/dist/packages/work/src/harness/contract.js +56 -0
- package/dist/packages/work/src/harness/session-store.d.ts +3 -1
- package/dist/packages/work/src/harness/session-store.js +46 -22
- package/dist/packages/work/src/hold/mcp.js +9 -2
- package/dist/packages/work/src/hub/client.d.ts +7 -1
- package/dist/packages/work/src/hub/client.js +1 -0
- package/dist/packages/work/src/hub/types.d.ts +71 -3
- package/dist/packages/work/src/roles/agent-run.js +8 -9
- package/dist/packages/work/src/roles/hold.d.ts +2 -0
- package/dist/packages/work/src/roles/hold.js +39 -8
- package/dist/packages/work/src/roles/settings.js +18 -6
- package/dist/packages/work/src/roles/shift.js +13 -1
- package/dist/packages/work/src/settings/settings.d.ts +60 -7
- package/dist/packages/work/src/settings/settings.js +69 -22
- package/dist/packages/work/src/shift/logretention.d.ts +253 -0
- package/dist/packages/work/src/shift/logretention.js +407 -0
- package/dist/packages/work/src/shift/logsink.d.ts +14 -0
- package/dist/packages/work/src/shift/logsink.js +98 -0
- package/dist/packages/work/src/shift/loop.d.ts +18 -1
- package/dist/packages/work/src/shift/loop.js +250 -12
- package/dist/packages/work/src/shift/protocol.d.ts +124 -1
- package/dist/packages/work/src/shift/protocol.js +14 -0
- package/dist/packages/work/src/shift/runtime.d.ts +14 -0
- package/dist/packages/work/src/shift/runtime.js +229 -6
- package/dist/packages/work/src/shift/server.d.ts +13 -0
- package/dist/packages/work/src/shift/server.js +61 -36
- package/dist/packages/work/src/shift/spawn.d.ts +78 -5
- package/dist/packages/work/src/shift/spawn.js +158 -12
- package/dist/packages/work/src/shift/state.d.ts +25 -0
- package/dist/packages/work/src/shift/state.js +29 -5
- package/dist/packages/work/src/shift/truncate.d.ts +35 -0
- package/dist/packages/work/src/shift/truncate.js +73 -0
- package/dist/packages/work/src/submit-proof.d.ts +31 -6
- package/dist/packages/work/src/submit-proof.js +33 -7
- package/dist/packages/work/src/submit-value.d.ts +48 -0
- package/dist/packages/work/src/submit-value.js +118 -0
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +11 -0
- package/dist/src/bundle/runtime.d.ts +1 -1
- package/dist/src/bundle/runtime.js +9 -0
- package/dist/src/capabilities.d.ts +93 -0
- package/dist/src/capabilities.js +101 -0
- package/dist/src/cli.js +37 -11
- package/dist/src/crypto/records.d.ts +3 -0
- package/dist/src/crypto/records.js +11 -0
- package/dist/src/defs.js +192 -4
- package/dist/src/engine.d.ts +112 -3
- package/dist/src/engine.js +224 -28
- package/dist/src/hub.d.ts +27 -11
- package/dist/src/hub.js +24 -18
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.js +4 -1
- package/dist/src/mcp/serve.js +11 -4
- package/dist/src/model.d.ts +36 -0
- package/dist/src/model.js +46 -0
- package/dist/src/schemas/index.d.ts +17 -0
- package/dist/src/schemas/order.v1.schema.json +17 -3
- package/dist/src/store.d.ts +33 -1
- package/dist/src/store.js +57 -4
- package/dist/src/types.d.ts +102 -2
- package/docs/agent-runner.md +26 -1
- package/docs/authoring.md +7 -0
- package/docs/bundles.md +103 -3
- package/docs/cli.md +127 -9
- package/docs/crypto.md +23 -7
- package/docs/shift-logs.md +642 -0
- package/docs/wire-contracts.md +34 -19
- package/package.json +1 -1
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/plugin/.mcp.json +1 -1
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
- package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
- package/dist/packages/work/src/agent/model-policy.d.ts +0 -49
- package/dist/packages/work/src/agent/model-policy.js +0 -138
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
* `{kind:'exited'}` and rejects with the underlying error.
|
|
64
64
|
*/
|
|
65
65
|
import { existsSync } from 'node:fs';
|
|
66
|
-
import { ResumeUnavailableError } from "./contract.js";
|
|
66
|
+
import { ResumeUnavailableError, NEUTRAL_PERMISSION_MODES, isNeutralPermissionMode } from "./contract.js";
|
|
67
67
|
import { register } from "./registry.js";
|
|
68
68
|
import { normalizeStepPermissions, validateHarnessOptions } from "./permissions.js";
|
|
69
69
|
import { ADMITTED_OWENLOOP_KEYS, filterOwenloopEnv } from "./child-env.js";
|
|
@@ -135,6 +135,36 @@ const SANDBOX_MODES = new Set(['read-only', 'workspace-write', 'danger-full-acce
|
|
|
135
135
|
const DEFAULT_SANDBOX = 'workspace-write';
|
|
136
136
|
/** `AskForApproval` values this adapter passes through untouched. */
|
|
137
137
|
const NATIVE_APPROVAL_POLICIES = new Set(['untrusted', 'on-request', 'never']);
|
|
138
|
+
/**
|
|
139
|
+
* This adapter's neutral-vocabulary translation. Every value maps: Codex's
|
|
140
|
+
* `AskForApproval` draws all three distinctions itself, so none is refused here.
|
|
141
|
+
*
|
|
142
|
+
* - `ask` → `untrusted` (`AskForApproval::UnlessTrusted`). It escalates every
|
|
143
|
+
* command to the user except a small trusted read-only allowlist — `ls`,
|
|
144
|
+
* `cat`, `sed`. The allowlist is why this is "consults a human before
|
|
145
|
+
* anything beyond trivially safe reads" rather than a literal every-call
|
|
146
|
+
* prompt, which is exactly how the neutral value is worded.
|
|
147
|
+
* - `auto-safe` → `on-request`. The model decides when to escalate. That is the
|
|
148
|
+
* model-side-judgment position, matching the neutral value's meaning.
|
|
149
|
+
* - `full-access` → `never`. Never asks; a failed command is returned to the
|
|
150
|
+
* model instead of raising a prompt.
|
|
151
|
+
*
|
|
152
|
+
* SEPARATE AXIS, DELIBERATELY. None of these touches `sandbox`. What the step
|
|
153
|
+
* may REACH comes from neutral `filesystem` (and the legacy `sandbox`
|
|
154
|
+
* extension); this field only decides who approves reaching it. `full-access`
|
|
155
|
+
* therefore means "never ask", not "unsandboxed" — a step wanting both states
|
|
156
|
+
* both.
|
|
157
|
+
*/
|
|
158
|
+
const NEUTRAL_TO_APPROVAL_POLICY = Object.freeze({
|
|
159
|
+
'ask': 'untrusted',
|
|
160
|
+
'auto-safe': 'on-request',
|
|
161
|
+
'full-access': 'never',
|
|
162
|
+
});
|
|
163
|
+
/** Values `codexPreflight` accepts: this adapter's own set plus the neutral vocabulary. */
|
|
164
|
+
const ACCEPTED_APPROVAL_POLICIES = new Set([
|
|
165
|
+
...NATIVE_APPROVAL_POLICIES,
|
|
166
|
+
...NEUTRAL_PERMISSION_MODES,
|
|
167
|
+
]);
|
|
138
168
|
const UNRESTRICTED_SANDBOX = 'danger-full-access';
|
|
139
169
|
function unsupportedFilesystemMessage(filesystem) {
|
|
140
170
|
return (`filesystem '${filesystem}' is unsupported by this adapter because Codex app-server ` +
|
|
@@ -173,12 +203,24 @@ function codexPreflight(permissions) {
|
|
|
173
203
|
"use sandbox 'workspace-write' or 'danger-full-access'",
|
|
174
204
|
});
|
|
175
205
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
206
|
+
const authoredMode = permissions.permissionMode;
|
|
207
|
+
if (authoredMode !== undefined) {
|
|
208
|
+
if (!ACCEPTED_APPROVAL_POLICIES.has(authoredMode)) {
|
|
209
|
+
issues.push({
|
|
210
|
+
field: 'permissionMode',
|
|
211
|
+
message: `permissionMode must be one of ${[...ACCEPTED_APPROVAL_POLICIES].join('|')}`,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
else if (isNeutralPermissionMode(authoredMode) &&
|
|
215
|
+
NEUTRAL_TO_APPROVAL_POLICY[authoredMode] === null) {
|
|
216
|
+
// Unreachable today — every neutral value maps here. Kept because the
|
|
217
|
+
// table's `null` arm is a real contract option, and a refusal that only
|
|
218
|
+
// exists once someone uses it is a refusal nobody has tested.
|
|
219
|
+
issues.push({
|
|
220
|
+
field: 'permissionMode',
|
|
221
|
+
message: `permissionMode '${authoredMode}' is unsupported by this adapter`,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
182
224
|
}
|
|
183
225
|
const sandbox = permissions.extensions['sandbox'];
|
|
184
226
|
if (sandbox !== undefined && (typeof sandbox !== 'string' || !SANDBOX_MODES.has(sandbox))) {
|
|
@@ -203,9 +245,15 @@ function codexPreflight(permissions) {
|
|
|
203
245
|
function toApprovalPolicy(mode) {
|
|
204
246
|
if (mode === undefined)
|
|
205
247
|
return 'never';
|
|
248
|
+
if (isNeutralPermissionMode(mode)) {
|
|
249
|
+
const mapped = NEUTRAL_TO_APPROVAL_POLICY[mode];
|
|
250
|
+
if (mapped !== null)
|
|
251
|
+
return mapped;
|
|
252
|
+
throw new Error(`permissionMode '${mode}' is unsupported by this adapter`);
|
|
253
|
+
}
|
|
206
254
|
if (NATIVE_APPROVAL_POLICIES.has(mode))
|
|
207
255
|
return mode;
|
|
208
|
-
throw new Error(`permissionMode must be one of ${[...
|
|
256
|
+
throw new Error(`permissionMode must be one of ${[...ACCEPTED_APPROVAL_POLICIES].join('|')}`);
|
|
209
257
|
}
|
|
210
258
|
function isPlainMap(v) {
|
|
211
259
|
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
@@ -97,7 +97,11 @@ export interface StepPermissions {
|
|
|
97
97
|
filesystem?: FilesystemPermission;
|
|
98
98
|
/** Network authority requested by the workflow definition. */
|
|
99
99
|
network?: NetworkPermission;
|
|
100
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Adapter permission mode. Each adapter validates its own vocabulary, PLUS the
|
|
102
|
+
* neutral values every adapter must either translate or refuse — see
|
|
103
|
+
* `NEUTRAL_PERMISSION_MODES`.
|
|
104
|
+
*/
|
|
101
105
|
permissionMode?: string;
|
|
102
106
|
/** Only ever a positive integer; anything else was dropped in normalization. */
|
|
103
107
|
maxTurns?: number;
|
|
@@ -108,6 +112,66 @@ export interface StepPermissions {
|
|
|
108
112
|
* no adapter needs a null check. */
|
|
109
113
|
extensions: Record<string, unknown>;
|
|
110
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* The HARNESS-NEUTRAL `permissionMode` vocabulary: three distinct positions on
|
|
117
|
+
* ONE axis — how much a step may do before a human is consulted.
|
|
118
|
+
*
|
|
119
|
+
* WHY THIS EXISTS. `permissionMode` sits in `NEUTRAL_KEYS` (see
|
|
120
|
+
* `./permissions.ts`) alongside `filesystem` and `network`, but it did not
|
|
121
|
+
* behave like them. `filesystem: unrestricted` is an INTENT the step states and
|
|
122
|
+
* each adapter translates into its own dialect — one shipped adapter turns it
|
|
123
|
+
* into that vendor's own sandbox setting. `permissionMode` had no translation
|
|
124
|
+
* layer at all: the authored string went to the adapter verbatim, and the
|
|
125
|
+
* shipped adapters accept DISJOINT vocabularies for the same ideas, each
|
|
126
|
+
* refusing the other's at preflight. A step therefore had to name one vendor's
|
|
127
|
+
* word, which pinned it to that vendor as surely as an explicit `id:` would
|
|
128
|
+
* have. That is exactly the pin the neutral-key contract exists to prevent.
|
|
129
|
+
*
|
|
130
|
+
* THE THREE POSITIONS ARE NOT INTERCHANGEABLE. Both shipped harnesses draw the
|
|
131
|
+
* same three distinctions, so collapsing any two would lose a real one:
|
|
132
|
+
*
|
|
133
|
+
* - `ask` — the harness consults a human before anything beyond trivially safe
|
|
134
|
+
* reads. The human is the gate.
|
|
135
|
+
* - `auto-safe` — a model-side classifier judges each action: it proceeds on
|
|
136
|
+
* ordinary work and consults a human only when an action is potentially
|
|
137
|
+
* dangerous. The classifier is the gate; a human is the exception path.
|
|
138
|
+
* - `full-access` — nothing is gated. The harness never consults a human, and
|
|
139
|
+
* a failed action is simply reported back to the model.
|
|
140
|
+
*
|
|
141
|
+
* `auto-safe` is NOT a milder `full-access`: it can still stop and ask. A
|
|
142
|
+
* headless step that must not stall wants `full-access`, and the two exist
|
|
143
|
+
* separately so that choice is stated rather than inferred.
|
|
144
|
+
*
|
|
145
|
+
* `ask` and `auto-safe` are meaningful only where something can answer a
|
|
146
|
+
* prompt. In a Shift-dispatched run nothing can, so a prompt is a stall: the
|
|
147
|
+
* Step Agent stops mid-turn, submits nothing, and the hub re-arms the step into
|
|
148
|
+
* a retry storm whose every worker dies in the same place. That is a reason for
|
|
149
|
+
* a definition author to choose `full-access` for unattended steps, not a
|
|
150
|
+
* reason for an adapter to silently upgrade one value into another.
|
|
151
|
+
*
|
|
152
|
+
* WHAT AN ADAPTER OWES THIS VOCABULARY. For each value an adapter must either
|
|
153
|
+
* map it onto the vendor mode with the same meaning, or refuse it in
|
|
154
|
+
* `preflight` with a `PermissionIssue` naming `permissionMode`. Refusing is a
|
|
155
|
+
* legitimate answer and fails closed: the worker releases its claim and starts
|
|
156
|
+
* no model process. Mapping a value onto a mode that grants MORE than the value
|
|
157
|
+
* describes is never legitimate.
|
|
158
|
+
*
|
|
159
|
+
* VENDOR VALUES ARE UNCHANGED. Each adapter still accepts its own native
|
|
160
|
+
* vocabulary and still refuses every other adapter's. These values are an
|
|
161
|
+
* ADDITION, so no already-published definition changes meaning.
|
|
162
|
+
*/
|
|
163
|
+
export declare const NEUTRAL_PERMISSION_MODES: readonly ["ask", "auto-safe", "full-access"];
|
|
164
|
+
export type NeutralPermissionMode = (typeof NEUTRAL_PERMISSION_MODES)[number];
|
|
165
|
+
/**
|
|
166
|
+
* An adapter's neutral-vocabulary translation table.
|
|
167
|
+
*
|
|
168
|
+
* EXHAUSTIVE BY TYPE, and that is the point: adding a fourth neutral value
|
|
169
|
+
* breaks compilation in every adapter until each one decides what it means
|
|
170
|
+
* there. `null` is the explicit "this adapter has no equivalent" decision and
|
|
171
|
+
* makes `preflight` refuse — distinct from an adapter that simply forgot.
|
|
172
|
+
*/
|
|
173
|
+
export type NeutralPermissionModeMap = Readonly<Record<NeutralPermissionMode, string | null>>;
|
|
174
|
+
export declare function isNeutralPermissionMode(value: string): value is NeutralPermissionMode;
|
|
111
175
|
/** One fail-closed adapter preflight refusal. */
|
|
112
176
|
export interface PermissionIssue {
|
|
113
177
|
/** The normalized permission field or extension key responsible, when one exists. */
|
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HARNESS-NEUTRAL `permissionMode` vocabulary: three distinct positions on
|
|
3
|
+
* ONE axis — how much a step may do before a human is consulted.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS EXISTS. `permissionMode` sits in `NEUTRAL_KEYS` (see
|
|
6
|
+
* `./permissions.ts`) alongside `filesystem` and `network`, but it did not
|
|
7
|
+
* behave like them. `filesystem: unrestricted` is an INTENT the step states and
|
|
8
|
+
* each adapter translates into its own dialect — one shipped adapter turns it
|
|
9
|
+
* into that vendor's own sandbox setting. `permissionMode` had no translation
|
|
10
|
+
* layer at all: the authored string went to the adapter verbatim, and the
|
|
11
|
+
* shipped adapters accept DISJOINT vocabularies for the same ideas, each
|
|
12
|
+
* refusing the other's at preflight. A step therefore had to name one vendor's
|
|
13
|
+
* word, which pinned it to that vendor as surely as an explicit `id:` would
|
|
14
|
+
* have. That is exactly the pin the neutral-key contract exists to prevent.
|
|
15
|
+
*
|
|
16
|
+
* THE THREE POSITIONS ARE NOT INTERCHANGEABLE. Both shipped harnesses draw the
|
|
17
|
+
* same three distinctions, so collapsing any two would lose a real one:
|
|
18
|
+
*
|
|
19
|
+
* - `ask` — the harness consults a human before anything beyond trivially safe
|
|
20
|
+
* reads. The human is the gate.
|
|
21
|
+
* - `auto-safe` — a model-side classifier judges each action: it proceeds on
|
|
22
|
+
* ordinary work and consults a human only when an action is potentially
|
|
23
|
+
* dangerous. The classifier is the gate; a human is the exception path.
|
|
24
|
+
* - `full-access` — nothing is gated. The harness never consults a human, and
|
|
25
|
+
* a failed action is simply reported back to the model.
|
|
26
|
+
*
|
|
27
|
+
* `auto-safe` is NOT a milder `full-access`: it can still stop and ask. A
|
|
28
|
+
* headless step that must not stall wants `full-access`, and the two exist
|
|
29
|
+
* separately so that choice is stated rather than inferred.
|
|
30
|
+
*
|
|
31
|
+
* `ask` and `auto-safe` are meaningful only where something can answer a
|
|
32
|
+
* prompt. In a Shift-dispatched run nothing can, so a prompt is a stall: the
|
|
33
|
+
* Step Agent stops mid-turn, submits nothing, and the hub re-arms the step into
|
|
34
|
+
* a retry storm whose every worker dies in the same place. That is a reason for
|
|
35
|
+
* a definition author to choose `full-access` for unattended steps, not a
|
|
36
|
+
* reason for an adapter to silently upgrade one value into another.
|
|
37
|
+
*
|
|
38
|
+
* WHAT AN ADAPTER OWES THIS VOCABULARY. For each value an adapter must either
|
|
39
|
+
* map it onto the vendor mode with the same meaning, or refuse it in
|
|
40
|
+
* `preflight` with a `PermissionIssue` naming `permissionMode`. Refusing is a
|
|
41
|
+
* legitimate answer and fails closed: the worker releases its claim and starts
|
|
42
|
+
* no model process. Mapping a value onto a mode that grants MORE than the value
|
|
43
|
+
* describes is never legitimate.
|
|
44
|
+
*
|
|
45
|
+
* VENDOR VALUES ARE UNCHANGED. Each adapter still accepts its own native
|
|
46
|
+
* vocabulary and still refuses every other adapter's. These values are an
|
|
47
|
+
* ADDITION, so no already-published definition changes meaning.
|
|
48
|
+
*/
|
|
49
|
+
export const NEUTRAL_PERMISSION_MODES = Object.freeze([
|
|
50
|
+
'ask',
|
|
51
|
+
'auto-safe',
|
|
52
|
+
'full-access',
|
|
53
|
+
]);
|
|
54
|
+
export function isNeutralPermissionMode(value) {
|
|
55
|
+
return NEUTRAL_PERMISSION_MODES.includes(value);
|
|
56
|
+
}
|
|
1
57
|
/** The `code` every `ResumeUnavailableError` carries. Match on THIS, not on the class. */
|
|
2
58
|
export const RESUME_UNAVAILABLE = 'RESUME_UNAVAILABLE';
|
|
3
59
|
/**
|
|
@@ -40,7 +40,9 @@ export interface SessionRecord {
|
|
|
40
40
|
updatedAt: number;
|
|
41
41
|
}
|
|
42
42
|
export interface SessionStoreOptions {
|
|
43
|
-
/** Called once per skipped corrupt
|
|
43
|
+
/** Called once per skipped line — either corrupt bytes that would not parse
|
|
44
|
+
* ("skipping corrupt record") or a parsed object that failed the schema
|
|
45
|
+
* ("skipping invalid record"). Default writes to stderr. */
|
|
44
46
|
warn?: (line: string) => void;
|
|
45
47
|
/** Test barrier invoked under the writer lock after a retirement snapshot. */
|
|
46
48
|
afterWriterSnapshot?: () => void;
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
*
|
|
19
19
|
* FAILURE STANCE, three different answers on purpose:
|
|
20
20
|
* - READ is fail-open: a missing file reads as `[]` (mirrors `readChildRecords`
|
|
21
|
-
* in `src/shift/state.ts`), and
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* in `src/shift/state.ts`), and an unusable line — corrupt bytes that will
|
|
22
|
+
* not parse, or a parsed object that fails the schema — is skipped and
|
|
23
|
+
* reported through the injectable `warn` callback, never thrown. A store that
|
|
24
|
+
* cannot be parsed must degrade a resume into a replay, not break the worker.
|
|
24
25
|
* - APPEND PROPAGATES. Unlike the shift's advisory metering records, a lost
|
|
25
26
|
* session token silently degrades a Phase 4 resume into a cold replay — real
|
|
26
27
|
* work thrown away — so the caller must see the failure.
|
|
@@ -79,28 +80,44 @@ function isNonEmptyString(v) {
|
|
|
79
80
|
return typeof v === 'string' && v !== '';
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
83
|
+
* The non-empty-string fields `isSessionRecord` requires, in the order it checks
|
|
84
|
+
* them. Declared once and kept stable so a record failing several checks always
|
|
85
|
+
* reports the SAME field, which keeps the skip message deterministic.
|
|
86
|
+
* `status` is not here — its check is a membership test, not a string test — and
|
|
87
|
+
* is applied after these, preserving the original check order.
|
|
86
88
|
*/
|
|
87
|
-
|
|
89
|
+
const SESSION_RECORD_STRING_FIELDS = ['workflow', 'run', 'step', 'harness', 'token'];
|
|
90
|
+
/**
|
|
91
|
+
* Name of the first field of `v` that fails the `SessionRecord` schema, or
|
|
92
|
+
* `null` when the record is valid. `'<root>'` means `v` is not a plain object at
|
|
93
|
+
* all, so no field could be read from it.
|
|
94
|
+
*
|
|
95
|
+
* THE SINGLE SOURCE OF TRUTH for record validity: `isSessionRecord` is defined
|
|
96
|
+
* in terms of this function, so the accept/reject decision and the reported
|
|
97
|
+
* field name can never drift apart.
|
|
98
|
+
*
|
|
99
|
+
* Checks exactly the fields whose absence would make the record unusable for a
|
|
100
|
+
* resume: the three key fields plus the harness and token it exists to carry,
|
|
101
|
+
* and a `status` inside the four literals. Everything else is carried verbatim.
|
|
102
|
+
*/
|
|
103
|
+
function firstInvalidSessionRecordField(v) {
|
|
88
104
|
if (typeof v !== 'object' || v === null || Array.isArray(v))
|
|
89
|
-
return
|
|
105
|
+
return '<root>';
|
|
90
106
|
const r = v;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!isNonEmptyString(r['step']))
|
|
96
|
-
return false;
|
|
97
|
-
if (!isNonEmptyString(r['harness']))
|
|
98
|
-
return false;
|
|
99
|
-
if (!isNonEmptyString(r['token']))
|
|
100
|
-
return false;
|
|
107
|
+
for (const field of SESSION_RECORD_STRING_FIELDS) {
|
|
108
|
+
if (!isNonEmptyString(r[field]))
|
|
109
|
+
return field;
|
|
110
|
+
}
|
|
101
111
|
if (typeof r['status'] !== 'string' || !STATUSES.has(r['status']))
|
|
102
|
-
return
|
|
103
|
-
return
|
|
112
|
+
return 'status';
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Validate one parsed line. A type predicate, so a `true` return narrows `v` to
|
|
117
|
+
* `SessionRecord` at the call site.
|
|
118
|
+
*/
|
|
119
|
+
function isSessionRecord(v) {
|
|
120
|
+
return firstInvalidSessionRecordField(v) === null;
|
|
104
121
|
}
|
|
105
122
|
/** Flush a directory entry update where the platform exposes directory fsync. */
|
|
106
123
|
function syncDirectory(dir, sync = fsyncSync) {
|
|
@@ -262,7 +279,14 @@ export function readSessions(file, opts = {}) {
|
|
|
262
279
|
continue;
|
|
263
280
|
}
|
|
264
281
|
if (!isSessionRecord(parsed)) {
|
|
265
|
-
|
|
282
|
+
// DISTINCT WORDING ON PURPOSE — "invalid", not "corrupt". These bytes
|
|
283
|
+
// parsed fine; they just failed the schema. 36 records once whose only
|
|
284
|
+
// fault was an empty `token` were all reported as "corrupt", which sent
|
|
285
|
+
// debugging after a file-integrity problem that did not exist. The second
|
|
286
|
+
// pass runs only on this failure branch, so valid records pay nothing.
|
|
287
|
+
// The field NAME only, never its value — `token` is credential-shaped.
|
|
288
|
+
const badField = firstInvalidSessionRecordField(parsed) ?? '<unknown>';
|
|
289
|
+
warn(`owenloop work sessions: skipping invalid record at ${file}:${i + 1}: field "${badField}" failed schema check`);
|
|
266
290
|
continue;
|
|
267
291
|
}
|
|
268
292
|
out.push(parsed);
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { textResult } from "../mcp/server.js";
|
|
30
30
|
import { buildSubmitProof } from "../submit-proof.js";
|
|
31
|
+
import { normalizeSubmitValue } from "../submit-value.js";
|
|
31
32
|
import { createHoldLoop } from "./loop.js";
|
|
32
33
|
export const HOLD_MCP_TOOL_NAMES = ['get_order', 'submit', 'reject'];
|
|
33
34
|
function errMsg(e) {
|
|
@@ -173,6 +174,12 @@ export function createHoldMcp(deps) {
|
|
|
173
174
|
return textResult({ error: 'submit requires a "value"' }, true);
|
|
174
175
|
}
|
|
175
176
|
const done = args['done'];
|
|
177
|
+
// Normalize a JSON-encoded string value to the object the hub would
|
|
178
|
+
// store BEFORE signing it. Signing the string instead makes the hub drop
|
|
179
|
+
// the proof (it stores normalized bytes the signature does not cover),
|
|
180
|
+
// silently, on both sides — see `../submit-value.ts`. One value is used
|
|
181
|
+
// for both the proof and the wire so the two can never diverge.
|
|
182
|
+
const value = normalizeSubmitValue(args['value']);
|
|
176
183
|
try {
|
|
177
184
|
// Submit is also a dynamic-data boundary. Fetch and gate the bound
|
|
178
185
|
// packet even when no origin was supplied for submit-proof signing;
|
|
@@ -192,7 +199,7 @@ export function createHoldMcp(deps) {
|
|
|
192
199
|
origin: deps.origin,
|
|
193
200
|
order: orderResponse.order,
|
|
194
201
|
path,
|
|
195
|
-
value
|
|
202
|
+
value,
|
|
196
203
|
now: deps.now,
|
|
197
204
|
warn: deps.err,
|
|
198
205
|
...(deps.principalKeys !== undefined ? { principalKeys: deps.principalKeys } : {}),
|
|
@@ -204,7 +211,7 @@ export function createHoldMcp(deps) {
|
|
|
204
211
|
workflow,
|
|
205
212
|
run,
|
|
206
213
|
path,
|
|
207
|
-
value
|
|
214
|
+
value,
|
|
208
215
|
...(typeof done === 'boolean' ? { done } : {}),
|
|
209
216
|
...(proof !== undefined ? { proof } : {}),
|
|
210
217
|
...holderReq,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetOrderRequest, GetOrderResponse, HeartbeatRequest, HeartbeatResponse, PresencePingRequest, PresencePingResponse, ReleaseRequest, ReleaseResponse, RejectRequest, RejectResponse, SubmitRequest, SubmitResponse, WakeResponse, WhatsNextRequest, WhatsNextResponse, WhoamiResponse } from './types.ts';
|
|
1
|
+
import type { GetOrderRequest, GetOrderResponse, HeartbeatRequest, HeartbeatResponse, PresencePingRequest, PresencePingResponse, ReleaseRequest, ReleaseResponse, RejectRequest, RejectResponse, ReportResolutionRequest, ReportResolutionResponse, SubmitRequest, SubmitResponse, WakeResponse, WhatsNextRequest, WhatsNextResponse, WhoamiResponse } from './types.ts';
|
|
2
2
|
export interface HubClientOptions {
|
|
3
3
|
/** Hub origin, e.g. `https://hub.owenloop.dev` (no trailing slash needed). */
|
|
4
4
|
origin: string;
|
|
@@ -14,6 +14,12 @@ export interface HubClient {
|
|
|
14
14
|
release(req: ReleaseRequest): Promise<ReleaseResponse>;
|
|
15
15
|
submit(req: SubmitRequest): Promise<SubmitResponse>;
|
|
16
16
|
reject(req: RejectRequest): Promise<RejectResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Plan §6: record what this shift resolved the order's compound capability to,
|
|
19
|
+
* BEFORE the harness launches. Idempotent on the hub by order id, so a
|
|
20
|
+
* re-dispatch no-ops rather than overwriting the first (pre-spend) record.
|
|
21
|
+
*/
|
|
22
|
+
reportResolution(req: ReportResolutionRequest): Promise<ReportResolutionResponse>;
|
|
17
23
|
whoami(): Promise<WhoamiResponse>;
|
|
18
24
|
/** B5 cheap wake pre-check; `cursor` rides the query string only when set. */
|
|
19
25
|
wake(cursor?: number): Promise<WakeResponse>;
|
|
@@ -82,6 +82,7 @@ export function createHubClient(opts) {
|
|
|
82
82
|
release: (req) => post('release', req),
|
|
83
83
|
submit: (req) => post('submit', req),
|
|
84
84
|
reject: (req) => post('reject', req),
|
|
85
|
+
reportResolution: (req) => post('report_resolution', req),
|
|
85
86
|
whoami: () => get('whoami'),
|
|
86
87
|
// Cursor is an opaque non-negative integer; omit it entirely to bootstrap
|
|
87
88
|
// (the hub treats missing/invalid as a `changed: true` first sweep).
|
|
@@ -31,7 +31,13 @@ export interface WorkOrder {
|
|
|
31
31
|
consumedFingerprint?: Record<string, number>;
|
|
32
32
|
owes?: Array<{
|
|
33
33
|
path: string;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* The TARGET version for this owed output when a version-aware hub
|
|
36
|
+
* projects it: the version the next successful producer commit lands
|
|
37
|
+
* (claim-time committed version + 1), NOT the currently-committed one.
|
|
38
|
+
* It is what a producer signs in its submission proof and what a
|
|
39
|
+
* downstream consumer checks that proof against.
|
|
40
|
+
*/
|
|
35
41
|
version?: number;
|
|
36
42
|
judgmentRejects: number;
|
|
37
43
|
schemaRejects: number;
|
|
@@ -176,6 +182,29 @@ export interface OrderPacket {
|
|
|
176
182
|
outputs: string[];
|
|
177
183
|
/** Opaque location hint — the worker's cwd when set. */
|
|
178
184
|
workdir?: string;
|
|
185
|
+
/**
|
|
186
|
+
* THE COMPOSED CAPABILITIES this order was offered under, in the step's
|
|
187
|
+
* authored order — `['build:deep']` for a `build` step on a `deep` run. This
|
|
188
|
+
* is the key into the shift's `capabilityModels` map (see
|
|
189
|
+
* `src/agent/capability-model.ts`), and therefore what decides which model and
|
|
190
|
+
* effort run. Absent from a pre-modifier hub, which is why the worker treats
|
|
191
|
+
* an empty list as "nothing to resolve against" and refuses rather than
|
|
192
|
+
* guessing.
|
|
193
|
+
*/
|
|
194
|
+
capabilities?: string[];
|
|
195
|
+
/** The run's routing modifier (`deep`), as the caller asked for at start_run. */
|
|
196
|
+
modifier?: string;
|
|
197
|
+
/**
|
|
198
|
+
* `true` when the engine re-offered this step at its escalation target instead
|
|
199
|
+
* of the run's own modifier. The worker does not act on it; it goes in the
|
|
200
|
+
* brief so the agent knows it is on the recovery path.
|
|
201
|
+
*/
|
|
202
|
+
escalated?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* DEPRECATED, and no longer read by the agent loop. The def's authored tier
|
|
205
|
+
* name (`strong`) from the pre-modifier scheme. The hub still projects it for
|
|
206
|
+
* older workers; this one resolves from `capabilities` alone.
|
|
207
|
+
*/
|
|
179
208
|
model?: string;
|
|
180
209
|
/** Worker kind; `'command'` for command orders, absent means agent. */
|
|
181
210
|
worker?: string;
|
|
@@ -186,12 +215,18 @@ export interface OrderPacket {
|
|
|
186
215
|
consumes: Record<string, unknown>;
|
|
187
216
|
/** Claim-time consumed versions when a compatible hub preserves the map. */
|
|
188
217
|
consumedFingerprint?: Record<string, number>;
|
|
189
|
-
/**
|
|
218
|
+
/** Serialized submission proof for the consumed values, projected by a
|
|
219
|
+
* proof-aware hub. Absent from any hub that does not store submit proofs;
|
|
220
|
+
* consume-side verification then reports the artifact as unproven. */
|
|
190
221
|
consumesProof?: string;
|
|
191
222
|
/** The owed outputs and their reason threads. */
|
|
192
223
|
owes: Array<{
|
|
193
224
|
path: string;
|
|
194
|
-
/**
|
|
225
|
+
/** Target version for this output's next successful commit (claim-time
|
|
226
|
+
* committed version + 1), issued by a version-aware hub inside the claim
|
|
227
|
+
* transaction. This is what a producer signs in its submission proof.
|
|
228
|
+
* Absent from a hub that is not version-aware, which leaves the producer
|
|
229
|
+
* submit unsigned. */
|
|
195
230
|
version?: number;
|
|
196
231
|
judgmentRejects: number;
|
|
197
232
|
schemaRejects: number;
|
|
@@ -223,6 +258,39 @@ export interface HeartbeatRequest {
|
|
|
223
258
|
holder?: ContactHolder;
|
|
224
259
|
}
|
|
225
260
|
export type HeartbeatResponse = HubResponse;
|
|
261
|
+
/**
|
|
262
|
+
* Which settings row served the order, mirroring hub-core's `ResolutionMatch`.
|
|
263
|
+
* `refused` is a real, reportable outcome: the shift found no row and will not
|
|
264
|
+
* launch anything, and that is exactly the fact worth recording.
|
|
265
|
+
*/
|
|
266
|
+
export type ResolutionMatch = 'exact' | 'bare' | 'refused';
|
|
267
|
+
export interface ResolutionPayload {
|
|
268
|
+
/** The settings key that matched (`build:deep`, or `build` on a bare match). */
|
|
269
|
+
capability: string;
|
|
270
|
+
match: ResolutionMatch;
|
|
271
|
+
/** Absent on `refused`, and on a command order, which selects no model. */
|
|
272
|
+
model?: string;
|
|
273
|
+
effort?: string;
|
|
274
|
+
harness?: string;
|
|
275
|
+
}
|
|
276
|
+
export interface ReportResolutionRequest {
|
|
277
|
+
workflow: string;
|
|
278
|
+
run: string;
|
|
279
|
+
resolution: ResolutionPayload;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The hub is idempotent by order id: `recorded: false` means a report for this
|
|
283
|
+
* run already stood and was left unchanged. `claimed` is the live lease state,
|
|
284
|
+
* disclosed and never enforced — a `false` here means the order is no longer
|
|
285
|
+
* this worker's to run.
|
|
286
|
+
*/
|
|
287
|
+
export interface ReportResolutionResponse extends HubResponse {
|
|
288
|
+
workflow: string;
|
|
289
|
+
run: string;
|
|
290
|
+
step: string;
|
|
291
|
+
recorded: boolean;
|
|
292
|
+
claimed: boolean;
|
|
293
|
+
}
|
|
226
294
|
export type ReleaseRequest = {
|
|
227
295
|
session: string;
|
|
228
296
|
} | {
|
|
@@ -87,7 +87,6 @@ import "../harnesses.js";
|
|
|
87
87
|
import { hostname } from 'node:os';
|
|
88
88
|
import { resolveCacheDir } from "../bundle/cache.js";
|
|
89
89
|
import { createAgentRunLoop } from "../agent/loop.js";
|
|
90
|
-
import { createModelPolicy } from "../agent/model-policy.js";
|
|
91
90
|
import { createDefaultStoreInstructionResolver } from "../exec/instructions.js";
|
|
92
91
|
import { createConsumedVerifier } from "../consumed-verifier.js";
|
|
93
92
|
import { createHubClient } from "../hub/client.js";
|
|
@@ -199,6 +198,7 @@ export function exitCodeFor(outcome) {
|
|
|
199
198
|
case 'no-template':
|
|
200
199
|
case 'no-harness':
|
|
201
200
|
case 'incompatible-harness-policy':
|
|
201
|
+
case 'unresolvable-capability':
|
|
202
202
|
case 'unverified-consumed':
|
|
203
203
|
case 'session-store-failed':
|
|
204
204
|
case 'no-submit':
|
|
@@ -264,13 +264,12 @@ export async function run(args, deps = {}) {
|
|
|
264
264
|
err(`owenloop work agent-run: ${errMsg(e)}`);
|
|
265
265
|
return 1;
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
});
|
|
267
|
+
// Passed through verbatim. `loadSettings` already validated every row (shape,
|
|
268
|
+
// effort on the ladder, effort accepted by a known model), so there is nothing
|
|
269
|
+
// left to normalize here — and nothing to default: an absent map means the
|
|
270
|
+
// loop refuses capability-bearing orders, which is the intended answer for a
|
|
271
|
+
// shift that never declared what serves what.
|
|
272
|
+
const capabilityModels = settings.capabilityModels;
|
|
274
273
|
const origin = parsed.origin ?? settings.hubOrigin;
|
|
275
274
|
if (origin === undefined || origin.trim() === '') {
|
|
276
275
|
err('owenloop work agent-run: no hub origin — pass --origin <url> or set hubOrigin in settings');
|
|
@@ -498,7 +497,7 @@ export async function run(args, deps = {}) {
|
|
|
498
497
|
cwd: workCwd,
|
|
499
498
|
loadStep,
|
|
500
499
|
resolveAdapter,
|
|
501
|
-
|
|
500
|
+
...(capabilityModels !== undefined ? { capabilityModels } : {}),
|
|
502
501
|
consumedVerifier,
|
|
503
502
|
appendSession: writeSession,
|
|
504
503
|
nextAttempt: (workflow, run, step) => {
|
|
@@ -15,6 +15,8 @@ interface ParsedArgs {
|
|
|
15
15
|
ignoreStdin: boolean;
|
|
16
16
|
mcp: boolean;
|
|
17
17
|
mcpTools?: HoldMcpToolName[];
|
|
18
|
+
/** Never hand the claim back — another process is the holder of record. */
|
|
19
|
+
neverRelease?: boolean;
|
|
18
20
|
error?: string;
|
|
19
21
|
}
|
|
20
22
|
/** Parse `--flag value` and `--flag=value`; unknown flags are an error. */
|