owenloop 0.4.0 → 0.5.0
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 +45 -0
- package/README.md +98 -25
- package/bin/owenloop.mjs +2 -2
- package/dist/packages/work/src/agent/brief.d.ts +172 -0
- package/dist/packages/work/src/agent/brief.js +193 -0
- package/dist/packages/work/src/agent/loop.d.ts +135 -0
- package/dist/packages/work/src/agent/loop.js +542 -0
- package/dist/packages/work/src/agent/workdir.d.ts +210 -0
- package/dist/packages/work/src/agent/workdir.js +319 -0
- package/dist/packages/work/src/bundle/cache.d.ts +90 -0
- package/dist/packages/work/src/bundle/cache.js +324 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +85 -0
- package/dist/packages/work/src/bundle/fetch.js +325 -0
- package/dist/packages/work/src/bundle/types.d.ts +160 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
- package/dist/packages/work/src/credentials/owenloop.js +28 -0
- package/dist/packages/work/src/credentials/reader.d.ts +36 -0
- package/dist/packages/work/src/credentials/reader.js +32 -0
- package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
- package/dist/packages/work/src/credentials/resolve.js +56 -0
- package/dist/packages/work/src/exec/loop.d.ts +29 -0
- package/dist/packages/work/src/exec/loop.js +215 -0
- package/dist/packages/work/src/exec/receipt.d.ts +38 -0
- package/dist/packages/work/src/exec/receipt.js +21 -0
- package/dist/packages/work/src/exec/runner.d.ts +65 -0
- package/dist/packages/work/src/exec/runner.js +185 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +127 -0
- package/dist/packages/work/src/harness/claude.d.ts +128 -0
- package/dist/packages/work/src/harness/claude.js +635 -0
- package/dist/packages/work/src/harness/codex.d.ts +110 -0
- package/dist/packages/work/src/harness/codex.js +896 -0
- package/dist/packages/work/src/harness/contract.d.ts +283 -0
- package/dist/packages/work/src/harness/contract.js +32 -0
- package/dist/packages/work/src/harness/fake.d.ts +59 -0
- package/dist/packages/work/src/harness/fake.js +90 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +344 -0
- package/dist/packages/work/src/harness/permissions.d.ts +62 -0
- package/dist/packages/work/src/harness/permissions.js +93 -0
- package/dist/packages/work/src/harness/registry.d.ts +47 -0
- package/dist/packages/work/src/harness/registry.js +45 -0
- package/dist/packages/work/src/harness/session-store.d.ts +163 -0
- package/dist/packages/work/src/harness/session-store.js +319 -0
- package/dist/packages/work/src/harness/types.d.ts +29 -0
- package/dist/packages/work/src/harness/types.js +14 -0
- package/dist/packages/work/src/harnesses.d.ts +38 -0
- package/dist/packages/work/src/harnesses.js +38 -0
- package/dist/packages/work/src/hold/loop.d.ts +36 -0
- package/dist/packages/work/src/hold/loop.js +23 -0
- package/dist/packages/work/src/hold/mcp.d.ts +55 -0
- package/dist/packages/work/src/hold/mcp.js +149 -0
- package/dist/packages/work/src/hub/client.d.ts +22 -0
- package/dist/packages/work/src/hub/client.js +78 -0
- package/dist/packages/work/src/hub/types.d.ts +290 -0
- package/dist/packages/work/src/hub/types.js +28 -0
- package/dist/packages/work/src/lease/loop.d.ts +94 -0
- package/dist/packages/work/src/lease/loop.js +277 -0
- package/dist/packages/work/src/main.d.ts +1 -0
- package/dist/packages/work/src/main.js +48 -0
- package/dist/packages/work/src/mcp/server.d.ts +125 -0
- package/dist/packages/work/src/mcp/server.js +320 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +118 -0
- package/dist/packages/work/src/roles/agent-run.js +447 -0
- package/dist/packages/work/src/roles/exec.d.ts +40 -0
- package/dist/packages/work/src/roles/exec.js +203 -0
- package/dist/packages/work/src/roles/hold.d.ts +68 -0
- package/dist/packages/work/src/roles/hold.js +324 -0
- package/dist/packages/work/src/roles/join.d.ts +18 -0
- package/dist/packages/work/src/roles/join.js +204 -0
- package/dist/packages/work/src/roles/lint.d.ts +59 -0
- package/dist/packages/work/src/roles/lint.js +200 -0
- package/dist/packages/work/src/roles/prepare.d.ts +1 -0
- package/dist/packages/work/src/roles/prepare.js +249 -0
- package/dist/packages/work/src/roles/release.d.ts +48 -0
- package/dist/packages/work/src/roles/release.js +137 -0
- package/dist/packages/work/src/roles/sessions.d.ts +61 -0
- package/dist/packages/work/src/roles/sessions.js +180 -0
- package/dist/packages/work/src/roles/settings.d.ts +6 -0
- package/dist/packages/work/src/roles/settings.js +66 -0
- package/dist/packages/work/src/roles/shift.d.ts +12 -0
- package/dist/packages/work/src/roles/shift.js +228 -0
- package/dist/packages/work/src/roles/signals.d.ts +55 -0
- package/dist/packages/work/src/roles/signals.js +62 -0
- package/dist/packages/work/src/settings/provision.d.ts +21 -0
- package/dist/packages/work/src/settings/provision.js +47 -0
- package/dist/packages/work/src/settings/settings.d.ts +120 -0
- package/dist/packages/work/src/settings/settings.js +116 -0
- package/dist/packages/work/src/shift/client.d.ts +24 -0
- package/dist/packages/work/src/shift/client.js +124 -0
- package/dist/packages/work/src/shift/loop.d.ts +120 -0
- package/dist/packages/work/src/shift/loop.js +468 -0
- package/dist/packages/work/src/shift/protocol.d.ts +91 -0
- package/dist/packages/work/src/shift/protocol.js +24 -0
- package/dist/packages/work/src/shift/routing.d.ts +35 -0
- package/dist/packages/work/src/shift/routing.js +50 -0
- package/dist/packages/work/src/shift/runtime.d.ts +43 -0
- package/dist/packages/work/src/shift/runtime.js +274 -0
- package/dist/packages/work/src/shift/server.d.ts +23 -0
- package/dist/packages/work/src/shift/server.js +716 -0
- package/dist/packages/work/src/shift/spawn.d.ts +86 -0
- package/dist/packages/work/src/shift/spawn.js +100 -0
- package/dist/packages/work/src/shift/state.d.ts +77 -0
- package/dist/packages/work/src/shift/state.js +162 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/{add.d.ts → src/add.d.ts} +12 -40
- package/dist/{add.js → src/add.js} +11 -176
- package/dist/src/cli.d.ts +147 -0
- package/dist/{cli.js → src/cli.js} +1643 -353
- package/dist/src/credentials.d.ts +280 -0
- package/dist/src/credentials.js +697 -0
- package/dist/{defs.js → src/defs.js} +59 -36
- package/dist/{engine.d.ts → src/engine.d.ts} +8 -8
- package/dist/{engine.js → src/engine.js} +29 -20
- package/dist/{hub.d.ts → src/hub.d.ts} +330 -2
- package/dist/{hub.js → src/hub.js} +531 -1
- package/dist/{index.d.ts → src/index.d.ts} +3 -1
- package/dist/{index.js → src/index.js} +2 -1
- package/dist/src/lock.d.ts +80 -0
- package/dist/src/lock.js +217 -0
- package/dist/src/mcp/serve.d.ts +85 -0
- package/dist/src/mcp/serve.js +702 -0
- package/dist/src/mcp/server.d.ts +132 -0
- package/dist/src/mcp/server.js +327 -0
- package/dist/{model.d.ts → src/model.d.ts} +59 -4
- package/dist/{model.js → src/model.js} +149 -22
- package/dist/{types.d.ts → src/types.d.ts} +66 -24
- package/dist/{util.d.ts → src/util.d.ts} +25 -0
- package/dist/{util.js → src/util.js} +26 -0
- package/dist/src/work-settings.d.ts +57 -0
- package/dist/src/work-settings.js +84 -0
- package/docs/authoring.md +102 -53
- package/docs/cli.md +883 -29
- package/docs/design.md +119 -45
- package/docs/embedding.md +39 -14
- package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
- package/examples/workflows/compile-dev-playbook.yaml +338 -0
- package/examples/workflows/judges/gate-sharpness.md +39 -0
- package/examples/workflows/judges/security.md +34 -0
- package/package.json +17 -8
- package/dist/cli.d.ts +0 -83
- /package/dist/{defs.d.ts → src/defs.d.ts} +0 -0
- /package/dist/{factory.d.ts → src/factory.d.ts} +0 -0
- /package/dist/{factory.js → src/factory.js} +0 -0
- /package/dist/{paths.d.ts → src/paths.d.ts} +0 -0
- /package/dist/{paths.js → src/paths.js} +0 -0
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{store.d.ts → src/store.d.ts} +0 -0
- /package/dist/{store.js → src/store.js} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
- /package/dist/{untar.d.ts → src/untar.d.ts} +0 -0
- /package/dist/{untar.js → src/untar.js} +0 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fetchDef` — GET the published workflow def from the hub for `prepare`.
|
|
3
|
+
*
|
|
4
|
+
* Reuses C1's envelope/`HubError` conventions (bearer auth, `{ text, ...data }`
|
|
5
|
+
* parse, non-2xx → `HubError`). It hits `GET /api/workflows/<name>` — the same
|
|
6
|
+
* route `get-workflow.ts` serves — and requires the enriched steps shape C2
|
|
7
|
+
* needs (see D1 / bundle/types.ts). Against TODAY's hub (which omits step
|
|
8
|
+
* bodies) it fails with an actionable error naming the gap rather than caching
|
|
9
|
+
* a bundle it cannot compile.
|
|
10
|
+
*
|
|
11
|
+
* Kept as a sibling of the C1 hub client (not a new method on `HubClient`) so
|
|
12
|
+
* the client's tight verb surface stays untouched; it shares the same auth and
|
|
13
|
+
* error conventions so there is still one error path.
|
|
14
|
+
*
|
|
15
|
+
* HASH-PINNED CLOSURE (E): when the parent version pins its `calls:` children,
|
|
16
|
+
* the SAME `GET /api/workflows/:name` round-trip carries `pins` + a flat
|
|
17
|
+
* hash-keyed `children` map. `fetchDef`/`validateFetchedDef` return a
|
|
18
|
+
* `FetchedBundle` (a `FetchedDef` subtype) whose optional `children` hold the
|
|
19
|
+
* frozen closure. The pin/children cross-checks (DD-5) are HARD fetch errors so
|
|
20
|
+
* a broken closure fails at fetch, never mid-run — see `validateFetchedDef`.
|
|
21
|
+
*/
|
|
22
|
+
import { HubError } from "../hub/types.js";
|
|
23
|
+
/** A step is an agent step (spec candidate) when it is not a command/calls step. */
|
|
24
|
+
function isAgentStep(s) {
|
|
25
|
+
return s.executor !== 'command' && s.calls === undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The ONE fixed, vendor-neutral sub-key of `x` that carries harness selection
|
|
29
|
+
* and harness options: `x.harness = { id?: string, ...options }`.
|
|
30
|
+
*
|
|
31
|
+
* It is a CONSTANT, not a lookup key derived from a harness name. That is the
|
|
32
|
+
* whole point: `src/agent/loop.ts` used to do `def.x[harnessId]`, which keyed a
|
|
33
|
+
* data structure BY the vendor id and leaked the vendor into neutral code. A
|
|
34
|
+
* fixed key does not.
|
|
35
|
+
*/
|
|
36
|
+
export const HARNESS_BAG_KEY = 'harness';
|
|
37
|
+
/**
|
|
38
|
+
* The sub-key of `x` owenloop used BEFORE `HARNESS_BAG_KEY`. Retained for ONE
|
|
39
|
+
* purpose: so `parseHarnessCarrier` can recognize a def still written to the old
|
|
40
|
+
* grammar and REJECT it loudly. Nothing ever reads what is inside it.
|
|
41
|
+
*
|
|
42
|
+
* ISOLATION NOTE: this is the only harness-vendor-shaped string under `src/`
|
|
43
|
+
* outside the two adapter modules (`src/harness/{claude,codex}.ts`) and the two
|
|
44
|
+
* composition roots' import lines. It is deliberate and it is not a dispatch
|
|
45
|
+
* decision — it names a DEAD key so the parser can tell an author exactly what
|
|
46
|
+
* to rename. Phase 6's repo-wide vendor gate LANDED — `test/vendor-gate.test.ts`
|
|
47
|
+
* — and this file is one of its four allowlist entries, which is the intended
|
|
48
|
+
* outcome. Do NOT "fix" a gate failure here by deleting the check: deleting the
|
|
49
|
+
* check restores the silent, fail-open degradation it exists to prevent.
|
|
50
|
+
*/
|
|
51
|
+
export const LEGACY_BAG_KEY = 'claude-code';
|
|
52
|
+
function isPlainMap(v) {
|
|
53
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Lift the harness carrier off one RAW step object (D1).
|
|
57
|
+
*
|
|
58
|
+
* Precedence for the id: a TOP-LEVEL `harness` key wins over `x.harness.id`.
|
|
59
|
+
* owenloop's `RAW_STEP_KEYS` rejects unknown top-level step keys at publish
|
|
60
|
+
* today, so a top-level `harness` cannot actually ship yet — reading it is
|
|
61
|
+
* forward compat for the day the grammar promotes the field, and it means the
|
|
62
|
+
* promotion needs no owenloop change.
|
|
63
|
+
*
|
|
64
|
+
* Validation is loose but HONEST: a non-map `x.harness`, a non-string
|
|
65
|
+
* `x.harness.id`, a non-string top-level `harness`, or a surviving legacy
|
|
66
|
+
* `x.claude-code` bag is a def error naming the step, never a silent drop.
|
|
67
|
+
* Absent keys are simply absent — a step with no harness declaration is
|
|
68
|
+
* completely normal.
|
|
69
|
+
*
|
|
70
|
+
* `label` names the def, `stepName` the step, so an error in a pinned child is
|
|
71
|
+
* attributable. Shared with `owenloop work lint`, which parses raw YAML defs.
|
|
72
|
+
*/
|
|
73
|
+
export function parseHarnessCarrier(s, label, stepName) {
|
|
74
|
+
const where = `hub workflow '${label}': step '${stepName}'`;
|
|
75
|
+
const topLevel = s['harness'];
|
|
76
|
+
if (topLevel !== undefined && typeof topLevel !== 'string') {
|
|
77
|
+
throw new Error(`${where} has a non-string harness`);
|
|
78
|
+
}
|
|
79
|
+
const x = s['x'];
|
|
80
|
+
// A def still carrying the OLD bag key fails HARD here, before anything else
|
|
81
|
+
// looks at `x`. Phase 5 renamed the carrier and shipped NO compatibility shim
|
|
82
|
+
// on purpose; without this check a legacy def parses "cleanly" to
|
|
83
|
+
// `harnessOptions === undefined` — a state indistinguishable from a step that
|
|
84
|
+
// declares no options at all — and the step then runs with its `tools`
|
|
85
|
+
// allow-list and its `disallowedTools` deny-list SILENTLY DROPPED. That is
|
|
86
|
+
// fail-OPEN on permissions, and it is the opposite of the stance this phase
|
|
87
|
+
// takes on the matching cache-format break (`readStepSpec` → `null` → the
|
|
88
|
+
// observable `no-template` outcome). This is DETECTION, not a shim: the legacy
|
|
89
|
+
// bag's contents are never read, only reported, and the message names the
|
|
90
|
+
// exact rename so the failure is self-service.
|
|
91
|
+
if (isPlainMap(x) && LEGACY_BAG_KEY in x) {
|
|
92
|
+
throw new Error(`${where} carries a legacy 'x.${LEGACY_BAG_KEY}' bag — rename that key to ` +
|
|
93
|
+
`'x.${HARNESS_BAG_KEY}' (the fields inside it are unchanged). owenloop no longer ` +
|
|
94
|
+
`reads 'x.${LEGACY_BAG_KEY}', so running the step with it would silently drop the ` +
|
|
95
|
+
`step's tools, disallowedTools, permissionMode, maxTurns and effort.`);
|
|
96
|
+
}
|
|
97
|
+
const raw = isPlainMap(x) ? x[HARNESS_BAG_KEY] : undefined;
|
|
98
|
+
if (raw !== undefined && !isPlainMap(raw)) {
|
|
99
|
+
throw new Error(`${where} has a non-map x.${HARNESS_BAG_KEY}`);
|
|
100
|
+
}
|
|
101
|
+
let bagId;
|
|
102
|
+
const options = {};
|
|
103
|
+
if (raw !== undefined) {
|
|
104
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
105
|
+
if (k === 'id') {
|
|
106
|
+
if (typeof v !== 'string') {
|
|
107
|
+
throw new Error(`${where} has a non-string x.${HARNESS_BAG_KEY}.id`);
|
|
108
|
+
}
|
|
109
|
+
bagId = v;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
options[k] = v;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const carrier = {};
|
|
116
|
+
const id = topLevel ?? bagId;
|
|
117
|
+
if (id !== undefined)
|
|
118
|
+
carrier.harness = id;
|
|
119
|
+
if (Object.keys(options).length > 0)
|
|
120
|
+
carrier.harnessOptions = options;
|
|
121
|
+
return carrier;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Validate one raw def envelope (hash + steps + per-step coercion + the D1 body
|
|
125
|
+
* gap check) into a `FetchedDef`, WITHOUT the pins/children cross-validation. The
|
|
126
|
+
* shared core for both the top-level parent and every child in the flat map.
|
|
127
|
+
* `label` names the def in error messages: the workflow name for a parent, or
|
|
128
|
+
* `<childName>@<childHash>` for a child, so a failure deep in the closure is
|
|
129
|
+
* attributable. Throws a plain `Error` on any structural problem.
|
|
130
|
+
*/
|
|
131
|
+
function validateDefEnvelope(data, label) {
|
|
132
|
+
if (typeof data !== 'object' || data === null) {
|
|
133
|
+
throw new Error(`hub returned a non-object workflow payload for '${label}'`);
|
|
134
|
+
}
|
|
135
|
+
const d = data;
|
|
136
|
+
if (typeof d['hash'] !== 'string' || d['hash'] === '') {
|
|
137
|
+
throw new Error(`hub workflow payload for '${label}' is missing a content hash`);
|
|
138
|
+
}
|
|
139
|
+
if (!Array.isArray(d['steps'])) {
|
|
140
|
+
throw new Error(`hub workflow payload for '${label}' is missing a steps array`);
|
|
141
|
+
}
|
|
142
|
+
const steps = d['steps'].map((raw, i) => {
|
|
143
|
+
if (typeof raw !== 'object' || raw === null) {
|
|
144
|
+
throw new Error(`hub workflow '${label}': step[${i}] is not an object`);
|
|
145
|
+
}
|
|
146
|
+
const s = raw;
|
|
147
|
+
if (typeof s['name'] !== 'string' || s['name'] === '') {
|
|
148
|
+
throw new Error(`hub workflow '${label}': step[${i}] is missing a name`);
|
|
149
|
+
}
|
|
150
|
+
if (s['x'] !== undefined && (typeof s['x'] !== 'object' || s['x'] === null || Array.isArray(s['x']))) {
|
|
151
|
+
throw new Error(`hub workflow '${label}': step '${s['name']}' has a non-map x`);
|
|
152
|
+
}
|
|
153
|
+
// Lift the neutral harness carrier out of `x.harness` (D1). `x` itself is
|
|
154
|
+
// still carried through verbatim — `x.owenloop` is a separate live
|
|
155
|
+
// namespace that `src/shift/routing.ts` reads.
|
|
156
|
+
const carrier = parseHarnessCarrier(s, label, s['name']);
|
|
157
|
+
return {
|
|
158
|
+
name: s['name'],
|
|
159
|
+
consumes: Array.isArray(s['consumes']) ? s['consumes'] : undefined,
|
|
160
|
+
produces: Array.isArray(s['produces']) ? s['produces'] : undefined,
|
|
161
|
+
terminal: typeof s['terminal'] === 'boolean' ? s['terminal'] : undefined,
|
|
162
|
+
body: typeof s['body'] === 'string' ? s['body'] : undefined,
|
|
163
|
+
model: typeof s['model'] === 'string' ? s['model'] : undefined,
|
|
164
|
+
executor: typeof s['executor'] === 'string' ? s['executor'] : undefined,
|
|
165
|
+
...carrier,
|
|
166
|
+
x: s['x'],
|
|
167
|
+
calls: typeof s['calls'] === 'string' ? s['calls'] : undefined,
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
// D1 hub-gap detection: an agent step with no body means the hub predates the
|
|
171
|
+
// C2 bundle-field enrichment. Fail with a message that names the gap (per def,
|
|
172
|
+
// so a bodyless CHILD agent step names that child, not the parent).
|
|
173
|
+
const bodyless = steps.filter((s) => isAgentStep(s) && s.body === undefined);
|
|
174
|
+
if (bodyless.length > 0) {
|
|
175
|
+
const names = bodyless.map((s) => s.name).join(', ');
|
|
176
|
+
throw new Error(`hub does not serve step bodies yet — get_workflow predates C2 bundle fields ` +
|
|
177
|
+
`(agent step(s) with no body: ${names}). The hub's get-workflow.ts steps ` +
|
|
178
|
+
`mapping needs the body/model/executor/x passthrough fields before prepare can compile '${label}'.`);
|
|
179
|
+
}
|
|
180
|
+
const def = {
|
|
181
|
+
name: typeof d['name'] === 'string' ? d['name'] : label,
|
|
182
|
+
steps,
|
|
183
|
+
hash: d['hash'],
|
|
184
|
+
version: typeof d['version'] === 'number' ? d['version'] : undefined,
|
|
185
|
+
};
|
|
186
|
+
const pins = parsePins(d['pins'], label);
|
|
187
|
+
if (pins !== undefined)
|
|
188
|
+
def.pins = pins;
|
|
189
|
+
return def;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Parse an OPTIONAL `pins` array into `FetchedPin[]`, or `undefined` when the key
|
|
193
|
+
* is absent. Throws on a malformed pin. `label` names the pinning def in errors.
|
|
194
|
+
*/
|
|
195
|
+
function parsePins(raw, label) {
|
|
196
|
+
if (raw === undefined)
|
|
197
|
+
return undefined;
|
|
198
|
+
if (!Array.isArray(raw)) {
|
|
199
|
+
throw new Error(`hub workflow '${label}': pins is present but not an array`);
|
|
200
|
+
}
|
|
201
|
+
return raw.map((p, i) => {
|
|
202
|
+
if (typeof p !== 'object' || p === null) {
|
|
203
|
+
throw new Error(`hub workflow '${label}': pins[${i}] is not an object`);
|
|
204
|
+
}
|
|
205
|
+
const pin = p;
|
|
206
|
+
if (typeof pin['call'] !== 'string' || pin['call'] === '') {
|
|
207
|
+
throw new Error(`hub workflow '${label}': pins[${i}] is missing a call step name`);
|
|
208
|
+
}
|
|
209
|
+
if (typeof pin['name'] !== 'string' || pin['name'] === '') {
|
|
210
|
+
throw new Error(`hub workflow '${label}': pin for call '${pin['call']}' is missing a child name`);
|
|
211
|
+
}
|
|
212
|
+
if (typeof pin['hash'] !== 'string' || pin['hash'] === '') {
|
|
213
|
+
throw new Error(`hub workflow '${label}': pin for call '${pin['call']}' is missing a child hash`);
|
|
214
|
+
}
|
|
215
|
+
if (typeof pin['version'] !== 'number' || !Number.isInteger(pin['version'])) {
|
|
216
|
+
throw new Error(`hub workflow '${label}': pin for call '${pin['call']}' has a non-integer version`);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
call: pin['call'],
|
|
220
|
+
name: pin['name'],
|
|
221
|
+
version: pin['version'],
|
|
222
|
+
hash: pin['hash'],
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Validate the raw `data` envelope into a `FetchedBundle`. Validates the parent
|
|
228
|
+
* def envelope (hash/steps/coercion/D1 gap), then the OPTIONAL hash-pinned child
|
|
229
|
+
* closure (E). Throws a plain `Error` on any structural problem.
|
|
230
|
+
*
|
|
231
|
+
* Pin/children cross-validation is a HARD fetch error (DD-5) — failing at fetch
|
|
232
|
+
* beats failing mid-run and mirrors the hub's refuse-partial stance:
|
|
233
|
+
* - exactly one of `pins`/`children` present without the other;
|
|
234
|
+
* - a `children` map key that ≠ the entry's own `hash`;
|
|
235
|
+
* - any pin (parent's or a child's) whose `hash` is absent from the flat map
|
|
236
|
+
* (partial closure);
|
|
237
|
+
* - a pin whose `name` ≠ `children[hash].name`.
|
|
238
|
+
* We do NOT re-walk the hub's name-consistency BFS (hub-enforced; duplicating it
|
|
239
|
+
* buys nothing beyond the checks above). Absent both keys → exactly today's
|
|
240
|
+
* shape (no `pins`/`children` materialized on the return).
|
|
241
|
+
*/
|
|
242
|
+
export function validateFetchedDef(data, name) {
|
|
243
|
+
const parent = validateDefEnvelope(data, name);
|
|
244
|
+
const d = data;
|
|
245
|
+
const rawChildren = d['children'];
|
|
246
|
+
const hasPins = parent.pins !== undefined;
|
|
247
|
+
const hasChildren = rawChildren !== undefined;
|
|
248
|
+
// The hub emits both keys or neither (DD-5).
|
|
249
|
+
if (hasPins !== hasChildren) {
|
|
250
|
+
throw new Error(`hub workflow '${name}': ${hasPins ? 'pins present without a children map' : 'children map present without pins'} ` +
|
|
251
|
+
`(the hub emits both or neither)`);
|
|
252
|
+
}
|
|
253
|
+
const bundle = parent;
|
|
254
|
+
if (!hasChildren)
|
|
255
|
+
return bundle;
|
|
256
|
+
if (typeof rawChildren !== 'object' || rawChildren === null || Array.isArray(rawChildren)) {
|
|
257
|
+
throw new Error(`hub workflow '${name}': children is present but not a hash-keyed map`);
|
|
258
|
+
}
|
|
259
|
+
// Validate every child envelope; the map key MUST equal the entry's own hash.
|
|
260
|
+
const children = {};
|
|
261
|
+
for (const [key, rawChild] of Object.entries(rawChildren)) {
|
|
262
|
+
const child = validateDefEnvelope(rawChild, `${rawChild?.['name'] ?? '?'}@${key}`);
|
|
263
|
+
if (child.hash !== key) {
|
|
264
|
+
throw new Error(`hub workflow '${name}': children map key '${key}' ≠ entry hash '${child.hash}' for child '${child.name}'`);
|
|
265
|
+
}
|
|
266
|
+
children[key] = child;
|
|
267
|
+
}
|
|
268
|
+
// Every pin (the parent's AND every child's, for grandchildren) must resolve
|
|
269
|
+
// into the flat map by hash, and its name must match the entry's name.
|
|
270
|
+
const allPinBearers = [parent, ...Object.values(children)];
|
|
271
|
+
for (const bearer of allPinBearers) {
|
|
272
|
+
for (const pin of bearer.pins ?? []) {
|
|
273
|
+
const target = children[pin.hash];
|
|
274
|
+
if (target === undefined) {
|
|
275
|
+
throw new Error(`hub workflow '${name}': pin '${pin.call}'→${pin.name}@${pin.hash} (in '${bearer.name}') ` +
|
|
276
|
+
`has no entry in the children map (partial closure)`);
|
|
277
|
+
}
|
|
278
|
+
if (target.name !== pin.name) {
|
|
279
|
+
throw new Error(`hub workflow '${name}': pin '${pin.call}' names child '${pin.name}' but children['${pin.hash}'] ` +
|
|
280
|
+
`is '${target.name}'`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
bundle.children = children;
|
|
285
|
+
return bundle;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Fetch and validate a workflow def. Non-2xx becomes a `HubError` (status +
|
|
289
|
+
* message, mirroring the hub client's parse); a 2xx body that is not the
|
|
290
|
+
* enriched shape becomes a plain `Error` from `validateFetchedDef`.
|
|
291
|
+
*/
|
|
292
|
+
export async function fetchDef(opts) {
|
|
293
|
+
const base = opts.origin.replace(/\/+$/, '');
|
|
294
|
+
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
295
|
+
const token = await opts.getToken();
|
|
296
|
+
const res = await fetchImpl(`${base}/api/workflows/${encodeURIComponent(opts.name)}`, {
|
|
297
|
+
method: 'GET',
|
|
298
|
+
headers: { authorization: `Bearer ${token}` },
|
|
299
|
+
});
|
|
300
|
+
const raw = await res.text();
|
|
301
|
+
if (!res.ok) {
|
|
302
|
+
let code;
|
|
303
|
+
let message = raw;
|
|
304
|
+
try {
|
|
305
|
+
const body = JSON.parse(raw);
|
|
306
|
+
if (body && typeof body === 'object') {
|
|
307
|
+
code = body.error;
|
|
308
|
+
message = body.message ?? raw;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
// Not JSON — keep the raw text as the message.
|
|
313
|
+
}
|
|
314
|
+
throw new HubError(res.status, message, code);
|
|
315
|
+
}
|
|
316
|
+
let parsed;
|
|
317
|
+
try {
|
|
318
|
+
parsed = JSON.parse(raw);
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
throw new Error(`hub returned non-JSON for workflow '${opts.name}'`);
|
|
322
|
+
}
|
|
323
|
+
// The envelope is `{ text, ...data }`; the fields we need live at the top level.
|
|
324
|
+
return validateFetchedDef(parsed, opts.name);
|
|
325
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural mirrors of the workflow-def shape `prepare` fetches from the hub.
|
|
3
|
+
*
|
|
4
|
+
* These intentionally mirror owenloop's def grammar (`~/code/owenloop/main`
|
|
5
|
+
* `src/defs.ts` RAW_STEP_KEYS) rather than invent anything: a step carries
|
|
6
|
+
* `name/consumes/produces/terminal` today plus the four fields C2 needs to
|
|
7
|
+
* build a step spec — `body`, `model`, `executor`, and the opaque `x` extension
|
|
8
|
+
* bag. Contents of `x` are otherwise NOT validated here (owenloop treats `x` as
|
|
9
|
+
* a plain map with opaque contents).
|
|
10
|
+
*
|
|
11
|
+
* HARNESS CARRIER (Phase 5 / D1): ONE fixed, vendor-neutral sub-key of `x` —
|
|
12
|
+
* `x.harness` — carries harness selection and harness options for a step:
|
|
13
|
+
* `{ id?: string, ...options }`. `validateFetchedDef` LIFTS it into two
|
|
14
|
+
* first-class neutral fields on the parsed step: `harness` (the id) and
|
|
15
|
+
* `harnessOptions` (every remaining key). Nothing downstream keys a data
|
|
16
|
+
* structure BY a harness name. `x.owenloop` (shift routing) is a separate live
|
|
17
|
+
* namespace under `x` and is untouched by the lift.
|
|
18
|
+
*
|
|
19
|
+
* HUB GAP (see D1 / bundle/fetch.ts): today `GET /api/workflows/:name`
|
|
20
|
+
* (`packages/hub-core/src/verbs/get-workflow.ts`) returns steps with only
|
|
21
|
+
* `name/consumes/produces/terminal` — no `body/model/executor/x`. C2's client
|
|
22
|
+
* contract is the natural enrichment of that same route; extending the hub's
|
|
23
|
+
* steps mapping with those passthrough fields is a small owenloop-service
|
|
24
|
+
* follow-up (out of scope here). Typed LOOSELY on purpose — honest-loose over
|
|
25
|
+
* invented-precise; tighten when the hub's bundle surface firms up.
|
|
26
|
+
*
|
|
27
|
+
* HASH-PINNED MULTI-DEF BUNDLE (E / merged hub squash 60d3e2c1): when a fetched
|
|
28
|
+
* PARENT version pins its `calls:` children by content hash, `GET
|
|
29
|
+
* /api/workflows/:name` ADDITIONALLY carries two keys (present-only — a childless
|
|
30
|
+
* def, or a calls-bearing version published pre-feature, emits NEITHER and the
|
|
31
|
+
* wire is byte-identical to today):
|
|
32
|
+
* - `pins`: array of `{call, name, version, hash}` — one per `calls:` step the
|
|
33
|
+
* parent pins, `hash` being the frozen child content hash.
|
|
34
|
+
* - `children`: ONE FLAT map keyed by child CONTENT HASH; each entry is a full
|
|
35
|
+
* def envelope (`{name, version, hash, inputs, steps}`) plus its own optional
|
|
36
|
+
* `pins` (grandchild pins resolve into the SAME flat map — nesting is
|
|
37
|
+
* reconstructed by following each entry's `pins`, not by nesting the map).
|
|
38
|
+
* These map onto `FetchedDef.pins` (legitimate on parent AND child) and
|
|
39
|
+
* `FetchedBundle.children` below.
|
|
40
|
+
*
|
|
41
|
+
* PERSISTENCE (DD-2): `CachedBundle.def` stays a `FetchedDef` — the parent is
|
|
42
|
+
* persisted WITH its `pins` but WITHOUT the `children` map; each child is cached
|
|
43
|
+
* as its OWN first-class bundle at `bundles/<childName>/<childHash>/` (carrying
|
|
44
|
+
* its own `pins`). So the cache itself becomes the pin index: scanning every
|
|
45
|
+
* cached bundle.json's `pins` covers the transitive closure.
|
|
46
|
+
*/
|
|
47
|
+
import type { StepPermissions } from '../harness/contract.ts';
|
|
48
|
+
/** A single step as served in the fetched workflow def. */
|
|
49
|
+
export interface FetchedStep {
|
|
50
|
+
name: string;
|
|
51
|
+
consumes?: unknown[];
|
|
52
|
+
produces?: unknown[];
|
|
53
|
+
terminal?: boolean;
|
|
54
|
+
/** Prompt body — the Markdown the step agent is briefed with (D6). */
|
|
55
|
+
body?: string;
|
|
56
|
+
/** First-class model field; wins over a harness-option `model` (D6). */
|
|
57
|
+
model?: string;
|
|
58
|
+
/** `'command'` steps are exec/engine concerns, never given a spec (D6). */
|
|
59
|
+
executor?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Which harness the `agent-run` worker should host this step agent in.
|
|
62
|
+
* LIFTED by `validateFetchedDef` from `x.harness.id`, or from a top-level
|
|
63
|
+
* `harness` key when the def carries one (top-level WINS — forward compat for
|
|
64
|
+
* an owenloop grammar that promotes the field). Declaration only: nothing
|
|
65
|
+
* validates the id here; `src/roles/agent-run.ts` resolves it, ranking BELOW
|
|
66
|
+
* `--harness` and `OWENLOOP_HARNESS`, and fails honestly when the id names no
|
|
67
|
+
* registered adapter.
|
|
68
|
+
*/
|
|
69
|
+
harness?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The harness option bag — every key of `x.harness` EXCEPT `id`. Lifted by
|
|
72
|
+
* `validateFetchedDef` so no code outside `src/harness/` has to reach into
|
|
73
|
+
* `x` for it. Fed to `normalizeStepPermissions` at prepare time (D4).
|
|
74
|
+
*/
|
|
75
|
+
harnessOptions?: Record<string, unknown>;
|
|
76
|
+
/**
|
|
77
|
+
* Opaque extension bag. Two sub-keys are meaningful to owenloop: `x.harness`
|
|
78
|
+
* (lifted into `harness`/`harnessOptions` above) and `x.owenloop` (shift
|
|
79
|
+
* command routing, see `src/shift/routing.ts`). Everything else passes
|
|
80
|
+
* through untouched.
|
|
81
|
+
*/
|
|
82
|
+
x?: Record<string, unknown>;
|
|
83
|
+
/** `calls:` child workflow name, when this is a composed-child step (D10). */
|
|
84
|
+
calls?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* One hash-pin the hub emits for a parent's `calls:` child (E). `call` is the
|
|
88
|
+
* calls-step name in the parent; `name`/`version`/`hash` identify the FROZEN
|
|
89
|
+
* child def that step must dispatch. Legitimate on a parent (pins its children)
|
|
90
|
+
* AND on a cached child (a child carries its own pins for its grandchildren).
|
|
91
|
+
*/
|
|
92
|
+
export interface FetchedPin {
|
|
93
|
+
call: string;
|
|
94
|
+
name: string;
|
|
95
|
+
version: number;
|
|
96
|
+
hash: string;
|
|
97
|
+
}
|
|
98
|
+
/** The fetched workflow def envelope (`data` from `GET /api/workflows/:name`). */
|
|
99
|
+
export interface FetchedDef {
|
|
100
|
+
name: string;
|
|
101
|
+
steps: FetchedStep[];
|
|
102
|
+
/** Def content hash — the cache key (D2). */
|
|
103
|
+
hash: string;
|
|
104
|
+
/** Def version when the hub knows it; metadata only (D2). */
|
|
105
|
+
version?: number;
|
|
106
|
+
/**
|
|
107
|
+
* Hash-pins for this def's `calls:` children (E). Present only when the wire
|
|
108
|
+
* carried a `pins` array (a pinned parent, or a cached child that itself pins
|
|
109
|
+
* grandchildren); absent otherwise — a childless/pre-feature def has no key.
|
|
110
|
+
*/
|
|
111
|
+
pins?: FetchedPin[];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A fetched PARENT envelope that additionally carries the frozen child closure
|
|
115
|
+
* (E). `children` is the hub's ONE FLAT map keyed by child CONTENT HASH — each
|
|
116
|
+
* value is a full `FetchedDef` (carrying its own `pins` for grandchildren).
|
|
117
|
+
* `FetchedBundle` is a strict subtype of `FetchedDef`, so every C1/C2 caller
|
|
118
|
+
* that types a fetch result as `FetchedDef` keeps compiling unchanged (DD-1).
|
|
119
|
+
* The `children` map is NEVER persisted inside the parent's bundle.json (DD-2);
|
|
120
|
+
* prepare caches each child as its own bundle.
|
|
121
|
+
*/
|
|
122
|
+
export interface FetchedBundle extends FetchedDef {
|
|
123
|
+
children?: Record<string, FetchedDef>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The normalized per-step spec `prepare` writes to `steps/<step>.json`, one file
|
|
127
|
+
* per dispatchable agent step (D4). It replaces the legacy `templates/<step>.md`
|
|
128
|
+
* compiled frontmatter entirely.
|
|
129
|
+
*
|
|
130
|
+
* What is DELIBERATELY not in here: the four substitution tokens
|
|
131
|
+
* (`ORDER_TOKEN`, `ORIGIN_TOKEN`, `ACCOUNT_TOKEN`, `SHIFT_TOKEN`) and the
|
|
132
|
+
* `mcpServers.owenloop` mount. Those are built at RUN time from the live order
|
|
133
|
+
* by `src/agent/brief.ts` (`renderBrief` + `buildOwenloopMcp`), which is now the
|
|
134
|
+
* only place they exist. A bundle is therefore order-independent.
|
|
135
|
+
*
|
|
136
|
+
* There is no `extensions` key at the top level: the lossless remainder of the
|
|
137
|
+
* harness option bag already lives inside `permissions.extensions`.
|
|
138
|
+
*
|
|
139
|
+
* There is no format version and no migration. A hash dir cached before Phase 5
|
|
140
|
+
* simply has no `steps/*.json`; `readStepSpec` fails honestly and the fix is to
|
|
141
|
+
* re-run `owenloop work prepare`.
|
|
142
|
+
*/
|
|
143
|
+
export interface NormalizedStepSpec {
|
|
144
|
+
/** The step name — the same string that names the file. */
|
|
145
|
+
step: string;
|
|
146
|
+
/** The step body verbatim: no frontmatter, no substitution applied yet. */
|
|
147
|
+
brief: string;
|
|
148
|
+
/** The harness id the def named, when it named one. Data, never a branch. */
|
|
149
|
+
harness?: string;
|
|
150
|
+
/** From `normalizeStepPermissions(step.harnessOptions, step)` at prepare time. */
|
|
151
|
+
permissions: StepPermissions;
|
|
152
|
+
}
|
|
153
|
+
/** What we persist under a hash dir: the validated fetch plus provenance. */
|
|
154
|
+
export interface CachedBundle {
|
|
155
|
+
def: FetchedDef;
|
|
156
|
+
/** Epoch millis the bundle was fetched. */
|
|
157
|
+
fetchedAt: number;
|
|
158
|
+
/** The origin it was fetched from (provenance/debugging). */
|
|
159
|
+
origin: string;
|
|
160
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Credential, Keychain } from '../../../../src/hub.ts';
|
|
2
|
+
import type { CredentialReader } from './reader.ts';
|
|
3
|
+
export declare class OwenloopCredentialReader implements CredentialReader {
|
|
4
|
+
private readonly opts;
|
|
5
|
+
constructor(opts: {
|
|
6
|
+
account: string;
|
|
7
|
+
env?: Record<string, string | undefined>;
|
|
8
|
+
keychain?: Keychain;
|
|
9
|
+
});
|
|
10
|
+
read(origin: string): Promise<Credential | null>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live credential reader backed by owenloop 0.4.0's `readStoredCredential`.
|
|
3
|
+
*
|
|
4
|
+
* This is the ONE enforcement point for "owenloop never reads the human slot":
|
|
5
|
+
* it always addresses `principal: 'agent'` with the configured account. A
|
|
6
|
+
* human-only origin therefore reads as absent (`null`) — owenloop's slots are
|
|
7
|
+
* distinct storage keys, so a Scoped Identity read never falls back to `human`.
|
|
8
|
+
*
|
|
9
|
+
* `read()` lets owenloop's THROWS propagate: a remote-plaintext / invalid
|
|
10
|
+
* origin (SEC-2) or an external-credential-command failure are genuine errors,
|
|
11
|
+
* distinct from the `null` "no Scoped Identity key" case that the resolver turns into a
|
|
12
|
+
* refuse-to-start. Read-only by contract — owenloop never writes credentials.
|
|
13
|
+
*/
|
|
14
|
+
import { readStoredCredential } from "../../../../src/hub.js";
|
|
15
|
+
export class OwenloopCredentialReader {
|
|
16
|
+
opts;
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
this.opts = opts;
|
|
19
|
+
}
|
|
20
|
+
async read(origin) {
|
|
21
|
+
return readStoredCredential(origin, {
|
|
22
|
+
principal: 'agent',
|
|
23
|
+
account: this.opts.account,
|
|
24
|
+
...(this.opts.env !== undefined ? { env: this.opts.env } : {}),
|
|
25
|
+
...(this.opts.keychain !== undefined ? { keychain: this.opts.keychain } : {}),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential read seam. owenloop reads hub credentials through owenloop's
|
|
3
|
+
* store ONLY — it never writes, prints, or stores credentials itself, and it
|
|
4
|
+
* never reads the keychain or `credentials.json` formats directly.
|
|
5
|
+
*
|
|
6
|
+
* The live wiring is against owenloop 0.4.0's `readStoredCredential`
|
|
7
|
+
* (src/credentials/owenloop.ts → `OwenloopCredentialReader`). owenloop reads
|
|
8
|
+
* ONLY the `agent:<account>` slots — never the `human` slot — so a human-only
|
|
9
|
+
* origin reads as absent (`null`), which the roles surface as a clean refuse.
|
|
10
|
+
* `Credential` is re-exported from owenloop below so this seam and the store
|
|
11
|
+
* speak the exact same union.
|
|
12
|
+
*/
|
|
13
|
+
/** The root package's stored-credential union (agent / oauth / oauth-pasted). */
|
|
14
|
+
export type { Credential } from '../../../../src/hub.ts';
|
|
15
|
+
import type { Credential } from '../../../../src/hub.ts';
|
|
16
|
+
/**
|
|
17
|
+
* Reads a stored credential for a hub origin. `read` resolves to `null` when
|
|
18
|
+
* no credential is stored for that origin. Read-only by contract.
|
|
19
|
+
*/
|
|
20
|
+
export interface CredentialReader {
|
|
21
|
+
read(origin: string): Promise<Credential | null>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* In-memory reader seeded from a `Record<origin, Credential>`. Lives in `src`
|
|
25
|
+
* (not `test/`) because C2+ role tests reuse it to stand in for the real store.
|
|
26
|
+
*/
|
|
27
|
+
export declare class FakeCredentialReader implements CredentialReader {
|
|
28
|
+
private readonly store;
|
|
29
|
+
constructor(store?: Record<string, Credential>);
|
|
30
|
+
read(origin: string): Promise<Credential | null>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Bridge from a stored credential to the bearer token the hub client's
|
|
34
|
+
* `getToken` seam expects. Every credential kind carries an `accessToken`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function credentialToToken(c: Credential): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential read seam. owenloop reads hub credentials through owenloop's
|
|
3
|
+
* store ONLY — it never writes, prints, or stores credentials itself, and it
|
|
4
|
+
* never reads the keychain or `credentials.json` formats directly.
|
|
5
|
+
*
|
|
6
|
+
* The live wiring is against owenloop 0.4.0's `readStoredCredential`
|
|
7
|
+
* (src/credentials/owenloop.ts → `OwenloopCredentialReader`). owenloop reads
|
|
8
|
+
* ONLY the `agent:<account>` slots — never the `human` slot — so a human-only
|
|
9
|
+
* origin reads as absent (`null`), which the roles surface as a clean refuse.
|
|
10
|
+
* `Credential` is re-exported from owenloop below so this seam and the store
|
|
11
|
+
* speak the exact same union.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* In-memory reader seeded from a `Record<origin, Credential>`. Lives in `src`
|
|
15
|
+
* (not `test/`) because C2+ role tests reuse it to stand in for the real store.
|
|
16
|
+
*/
|
|
17
|
+
export class FakeCredentialReader {
|
|
18
|
+
store;
|
|
19
|
+
constructor(store = {}) {
|
|
20
|
+
this.store = store;
|
|
21
|
+
}
|
|
22
|
+
async read(origin) {
|
|
23
|
+
return this.store[origin] ?? null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Bridge from a stored credential to the bearer token the hub client's
|
|
28
|
+
* `getToken` seam expects. Every credential kind carries an `accessToken`.
|
|
29
|
+
*/
|
|
30
|
+
export function credentialToToken(c) {
|
|
31
|
+
return c.accessToken;
|
|
32
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type BearerResult = {
|
|
2
|
+
ok: true;
|
|
3
|
+
token: string;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
code: number;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The owenloop `--as <slot>` argument for an account: `agent` for the default
|
|
11
|
+
* account, `agent:<account>` otherwise. Grounded from owenloop's `--as`
|
|
12
|
+
* semantics (`human` | `agent` | `agent:<account>`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function slotArg(account: string): string;
|
|
15
|
+
export declare function resolveBearer(args: {
|
|
16
|
+
origin: string;
|
|
17
|
+
account: string;
|
|
18
|
+
env: Record<string, string | undefined>;
|
|
19
|
+
}): Promise<BearerResult>;
|