owenloop 0.4.1 → 0.5.1
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 +71 -0
- package/README.md +182 -53
- package/bin/owenloop.mjs +50 -2
- package/dist/packages/work/src/agent/brief.d.ts +176 -0
- package/dist/packages/work/src/agent/brief.js +197 -0
- package/dist/packages/work/src/agent/loop.d.ts +141 -0
- package/dist/packages/work/src/agent/loop.js +669 -0
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -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 +92 -0
- package/dist/packages/work/src/bundle/cache.js +338 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
- package/dist/packages/work/src/bundle/fetch.js +345 -0
- package/dist/packages/work/src/bundle/types.d.ts +164 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -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/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +40 -0
- package/dist/packages/work/src/exec/loop.js +332 -0
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +41 -0
- package/dist/packages/work/src/exec/receipt.js +32 -0
- package/dist/packages/work/src/exec/runner.d.ts +71 -0
- package/dist/packages/work/src/exec/runner.js +256 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +134 -0
- package/dist/packages/work/src/harness/claude.d.ts +140 -0
- package/dist/packages/work/src/harness/claude.js +837 -0
- package/dist/packages/work/src/harness/codex.d.ts +111 -0
- package/dist/packages/work/src/harness/codex.js +1024 -0
- package/dist/packages/work/src/harness/contract.d.ts +308 -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 +91 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
- package/dist/packages/work/src/harness/permissions.d.ts +75 -0
- package/dist/packages/work/src/harness/permissions.js +182 -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 +181 -0
- package/dist/packages/work/src/harness/session-store.js +523 -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 +75 -0
- package/dist/packages/work/src/hold/mcp.js +264 -0
- package/dist/packages/work/src/hub/client.d.ts +23 -0
- package/dist/packages/work/src/hub/client.js +91 -0
- package/dist/packages/work/src/hub/types.d.ts +326 -0
- package/dist/packages/work/src/hub/types.js +26 -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/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
- package/dist/packages/work/src/roles/agent-run.js +529 -0
- package/dist/packages/work/src/roles/exec.d.ts +48 -0
- package/dist/packages/work/src/roles/exec.js +228 -0
- package/dist/packages/work/src/roles/hold.d.ts +72 -0
- package/dist/packages/work/src/roles/hold.js +363 -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 +58 -0
- package/dist/packages/work/src/roles/lint.js +234 -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 +71 -0
- package/dist/packages/work/src/roles/shift.d.ts +13 -0
- package/dist/packages/work/src/roles/shift.js +250 -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 +136 -0
- package/dist/packages/work/src/settings/settings.js +155 -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 +131 -0
- package/dist/packages/work/src/shift/loop.js +751 -0
- package/dist/packages/work/src/shift/protocol.d.ts +95 -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 +45 -0
- package/dist/packages/work/src/shift/runtime.js +337 -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 +109 -0
- package/dist/packages/work/src/shift/spawn.js +158 -0
- package/dist/packages/work/src/shift/state.d.ts +79 -0
- package/dist/packages/work/src/shift/state.js +385 -0
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/src/add.d.ts +189 -0
- package/dist/src/add.js +300 -0
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
- package/dist/src/cli.js +5968 -0
- package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
- package/dist/{credentials.js → src/credentials.js} +35 -31
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
- package/dist/{defs.js → src/defs.js} +181 -61
- package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
- package/dist/{engine.js → src/engine.js} +251 -47
- package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
- package/dist/{factory.js → src/factory.js} +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
- package/dist/{hub.js → src/hub.js} +493 -52
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.js +41 -0
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +38 -0
- package/dist/src/lock.js +325 -0
- package/dist/src/mcp/serve.d.ts +109 -0
- package/dist/{mcp → src/mcp}/serve.js +335 -75
- package/dist/{mcp → src/mcp}/server.d.ts +6 -9
- package/dist/{mcp → src/mcp}/server.js +18 -10
- package/dist/{model.d.ts → src/model.d.ts} +15 -0
- package/dist/{model.js → src/model.js} +112 -2
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
- package/dist/{paths.js → src/paths.js} +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/{types.d.ts → src/types.d.ts} +58 -24
- package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
- package/dist/src/untar.js +38 -0
- package/dist/{util.d.ts → src/util.d.ts} +3 -2
- package/dist/{util.js → src/util.js} +3 -2
- package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
- package/dist/{owenwork.js → src/work-settings.js} +27 -27
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +150 -59
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1758 -163
- package/docs/crypto.md +816 -0
- package/docs/design.md +374 -52
- package/docs/embedding.md +135 -27
- package/docs/wire-contracts.md +380 -0
- 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 +22 -8
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
- package/dist/add.d.ts +0 -384
- package/dist/add.js +0 -834
- package/dist/cli.js +0 -3270
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -23
- package/dist/lock.d.ts +0 -80
- package/dist/lock.js +0 -217
- package/dist/mcp/serve.d.ts +0 -84
- package/dist/untar.js +0 -164
- /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
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* `owenloop work agent-run <order-id>` (Phase 3) — the detached, self-leasing worker
|
|
11
|
+
* that HOSTS one step agent, and the harness-registry COMPOSITION ROOT.
|
|
12
|
+
*
|
|
13
|
+
* The shift spawns one detached
|
|
14
|
+
* `owenloop work agent-run <workflow>/<run> --origin <url>` per AGENT order — the
|
|
15
|
+
* ONLY path an agent order takes, since Phase 5 deleted the legacy stamp path
|
|
16
|
+
* it used to share the lane with. This
|
|
17
|
+
* process owns that order end to end: it takes the lease on first contact,
|
|
18
|
+
* renders the step's brief, starts the step agent inside a harness adapter with
|
|
19
|
+
* a work-holder MCP mount born bound to this order, keeps the lease warm
|
|
20
|
+
* underneath the turn, and learns whether the agent submitted FROM THE HUB.
|
|
21
|
+
* Nothing is ever written to any agent-definition directory.
|
|
22
|
+
*
|
|
23
|
+
* The orchestration CORE lives in `src/agent/loop.ts` (lease + adapter + confirm
|
|
24
|
+
* phase, every side effect injected); this role only parses the arg contract,
|
|
25
|
+
* resolves origin/credential/cache, tags the holder identity, resolves WHICH
|
|
26
|
+
* adapter hosts the agent, loads the brief template, wires the signal seam, and
|
|
27
|
+
* maps `AgentRunOutcome` to an exit code.
|
|
28
|
+
*
|
|
29
|
+
* ── WHERE THE ADAPTERS COME FROM (Phase 6) ──
|
|
30
|
+
*
|
|
31
|
+
* `src/harness/registry.ts` starts empty and forbids a barrel, so SOMEBODY has
|
|
32
|
+
* to import the adapter modules for their `register(...)` side effect to fire.
|
|
33
|
+
* Through Phase 5 that somebody was this file AND `src/roles/lint.ts`, each
|
|
34
|
+
* carrying the same import pair in the same hand-maintained order. Phase 6
|
|
35
|
+
* consolidated both into `src/harnesses.ts`; this file imports THAT, and the
|
|
36
|
+
* single line is directly below the header. Adapter import order — which decides
|
|
37
|
+
* the default harness — now has exactly one owner.
|
|
38
|
+
*
|
|
39
|
+
* ── WHERE THE STEP SPEC COMES FROM ──
|
|
40
|
+
*
|
|
41
|
+
* The order packet carries a `defDigest` reference but no authoritative prompt,
|
|
42
|
+
* harness, or permission text. The worker resolves the digest and step name
|
|
43
|
+
* through the verified local workflow store. The prepare cache remains available
|
|
44
|
+
* for routing and session state, but never supplies execution instructions.
|
|
45
|
+
*
|
|
46
|
+
* ── CREDENTIALS ──
|
|
47
|
+
*
|
|
48
|
+
* Origin/credential resolution mirrors `exec`: origin `--origin` → settings; the
|
|
49
|
+
* bearer comes from owenloop's store via `resolveBearer`, reading the
|
|
50
|
+
* `agent:<account>` slot for the account the shift set in this child's
|
|
51
|
+
* `OWENLOOP_ACCOUNT` spawn env (default `default`). `agent-run` has NO `--as`
|
|
52
|
+
* flag — the spawn-env channel is the contract.
|
|
53
|
+
*
|
|
54
|
+
* D10, CLOSED IN PHASE 6. The MCP mount this worker builds carries no
|
|
55
|
+
* credential — the mounted work-holder resolves its own from the same store —
|
|
56
|
+
* and as of Phase 6 the dev-only `OWENLOOP_TOKEN` override is no longer
|
|
57
|
+
* inherited by the harness child either. Both adapters filter it out through
|
|
58
|
+
* `filterOwenloopEnv` (`src/harness/child-env.ts`), an allowlist scoped to the
|
|
59
|
+
* `OWENLOOP_*` namespace ONLY, so nothing a harness needs in order to start —
|
|
60
|
+
* `PATH`, `HOME`, `NODE_OPTIONS`, a shift setting, a vendor's own credential
|
|
61
|
+
* variable — can be stranded by it.
|
|
62
|
+
*
|
|
63
|
+
* The consequence lands in this file: because the child cannot see the override,
|
|
64
|
+
* THIS ROLE IGNORES IT TOO, so worker and child authenticate as the same
|
|
65
|
+
* principal. See the block around the `resolveBearer` call. `resolveBearer`
|
|
66
|
+
* itself is unchanged and every other role still honours the override.
|
|
67
|
+
*
|
|
68
|
+
* Phase 4's narrower guarantee still holds and is still asserted: the rejection
|
|
69
|
+
* delta and the replay brief carry no credential material
|
|
70
|
+
* (`test/agent-rejection.test.ts`).
|
|
71
|
+
*
|
|
72
|
+
* ── WHERE THE STEP AGENT WORKS (Phase 4) ──
|
|
73
|
+
*
|
|
74
|
+
* `OrderPacket.workdir` (the hub's choice) > `<workRoot>/<workflow>/<run>/` >
|
|
75
|
+
* this process's cwd. The middle rung is new: see `src/agent/workdir.ts` for the
|
|
76
|
+
* per-RUN layout and the reaper that removes it.
|
|
77
|
+
*/
|
|
78
|
+
// ── The composition root, imported for its side effect ──────────────────────
|
|
79
|
+
//
|
|
80
|
+
// PHASE 6: this file used to carry the adapter imports itself, and so did
|
|
81
|
+
// `src/roles/lint.ts` — two roots whose import ORDER had to be kept identical by
|
|
82
|
+
// hand, because the first id registered is the default harness. Both now import
|
|
83
|
+
// the single root, `src/harnesses.ts`, which owns that order. Without this line
|
|
84
|
+
// nothing is registered and every run fails with `'no-harness'`.
|
|
85
|
+
import "../harnesses.js";
|
|
86
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
87
|
+
import { hostname } from 'node:os';
|
|
88
|
+
import { resolveCacheDir } from "../bundle/cache.js";
|
|
89
|
+
import { createAgentRunLoop } from "../agent/loop.js";
|
|
90
|
+
import { createModelPolicy } from "../agent/model-policy.js";
|
|
91
|
+
import { createDefaultStoreInstructionResolver } from "../exec/instructions.js";
|
|
92
|
+
import { createConsumedVerifier } from "../consumed-verifier.js";
|
|
93
|
+
import { createHubClient } from "../hub/client.js";
|
|
94
|
+
import { resolveBearer } from "../credentials/resolve.js";
|
|
95
|
+
import { loadSettings } from "../settings/settings.js";
|
|
96
|
+
import { adapterFor, defaultHarnessId, registeredHarnessIds } from "../harness/registry.js";
|
|
97
|
+
import { parseHarnessCarrier } from "../bundle/fetch.js";
|
|
98
|
+
import { normalizeStepPermissions, validateHarnessOptions } from "../harness/permissions.js";
|
|
99
|
+
import { appendSession, latestFor, sessionsPath } from "../harness/session-store.js";
|
|
100
|
+
import { ensureWorkDir, resolveWorkRepo, resolveWorkRoot } from "../agent/workdir.js";
|
|
101
|
+
import { resolveShiftId, resolveTarget } from "./hold.js";
|
|
102
|
+
import { installSignalHandlers } from "./signals.js";
|
|
103
|
+
const DEFAULT_INTERVAL_MS = 60_000;
|
|
104
|
+
/** Positive-integer flag parse shared by the four ms knobs. */
|
|
105
|
+
function positiveMs(name, raw) {
|
|
106
|
+
const n = Number(raw);
|
|
107
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) {
|
|
108
|
+
return { error: `${name} must be a positive integer, got '${raw}'` };
|
|
109
|
+
}
|
|
110
|
+
return { value: n };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parse the positional `<order-id>` plus `--workflow`/`--origin`/`--shift`/
|
|
114
|
+
* `--harness`/`--heartbeat-interval`/`--jump-tolerance`/`--submit-grace`/
|
|
115
|
+
* `--confirm-interval`. Supports `--flag value` and `--flag=value`; a second
|
|
116
|
+
* positional or an unknown flag is an error. Mirrors `src/roles/exec.ts`.
|
|
117
|
+
*/
|
|
118
|
+
export function parseArgs(args) {
|
|
119
|
+
const parsed = {};
|
|
120
|
+
const takeValue = (a, i) => {
|
|
121
|
+
const eq = a.indexOf('=');
|
|
122
|
+
if (eq !== -1)
|
|
123
|
+
return { value: a.slice(eq + 1), next: i };
|
|
124
|
+
const v = args[i + 1];
|
|
125
|
+
if (v === undefined)
|
|
126
|
+
return { error: `missing value for ${a}` };
|
|
127
|
+
return { value: v, next: i + 1 };
|
|
128
|
+
};
|
|
129
|
+
for (let i = 0; i < args.length; i++) {
|
|
130
|
+
const a = args[i];
|
|
131
|
+
if (!a.startsWith('-')) {
|
|
132
|
+
if (parsed.orderId !== undefined)
|
|
133
|
+
return { error: `unexpected extra argument '${a}'` };
|
|
134
|
+
parsed.orderId = a;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const name = a.startsWith('--') && a.includes('=') ? a.slice(0, a.indexOf('=')) : a;
|
|
138
|
+
switch (name) {
|
|
139
|
+
case '--workflow':
|
|
140
|
+
case '--origin':
|
|
141
|
+
case '--shift':
|
|
142
|
+
case '--harness':
|
|
143
|
+
case '--heartbeat-interval':
|
|
144
|
+
case '--jump-tolerance':
|
|
145
|
+
case '--submit-grace':
|
|
146
|
+
case '--confirm-interval': {
|
|
147
|
+
const r = takeValue(a, i);
|
|
148
|
+
if ('error' in r)
|
|
149
|
+
return { error: r.error };
|
|
150
|
+
i = r.next;
|
|
151
|
+
if (name === '--workflow')
|
|
152
|
+
parsed.workflow = r.value;
|
|
153
|
+
else if (name === '--origin')
|
|
154
|
+
parsed.origin = r.value;
|
|
155
|
+
else if (name === '--shift')
|
|
156
|
+
parsed.shift = r.value;
|
|
157
|
+
else if (name === '--harness') {
|
|
158
|
+
if (r.value.trim() === '')
|
|
159
|
+
return { error: '--harness must be a non-empty harness id' };
|
|
160
|
+
parsed.harness = r.value;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const n = positiveMs(name, r.value);
|
|
164
|
+
if ('error' in n)
|
|
165
|
+
return { error: n.error };
|
|
166
|
+
if (name === '--heartbeat-interval')
|
|
167
|
+
parsed.heartbeatIntervalMs = n.value;
|
|
168
|
+
else if (name === '--jump-tolerance')
|
|
169
|
+
parsed.jumpToleranceMs = n.value;
|
|
170
|
+
else if (name === '--submit-grace')
|
|
171
|
+
parsed.submitGraceMs = n.value;
|
|
172
|
+
else
|
|
173
|
+
parsed.confirmIntervalMs = n.value;
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
default:
|
|
178
|
+
return { error: `unknown option '${a}'` };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return parsed;
|
|
182
|
+
}
|
|
183
|
+
function usage() {
|
|
184
|
+
process.stderr.write('usage: owenloop work agent-run <workflow>/<run> [--origin <url>] [--harness <id>] [--shift <id>]\n' +
|
|
185
|
+
' [--heartbeat-interval <ms>] [--jump-tolerance <ms>]\n' +
|
|
186
|
+
' [--submit-grace <ms>] [--confirm-interval <ms>]\n' +
|
|
187
|
+
' or: owenloop work agent-run <run> --workflow <wf> [...]\n');
|
|
188
|
+
}
|
|
189
|
+
function errMsg(err) {
|
|
190
|
+
return err instanceof Error ? err.message : String(err);
|
|
191
|
+
}
|
|
192
|
+
/** Map the loop's outcome onto the process exit code (see usage.ts). */
|
|
193
|
+
export function exitCodeFor(outcome) {
|
|
194
|
+
switch (outcome) {
|
|
195
|
+
case 'submitted':
|
|
196
|
+
case 'completed':
|
|
197
|
+
return 0;
|
|
198
|
+
case 'misroute':
|
|
199
|
+
case 'no-template':
|
|
200
|
+
case 'no-harness':
|
|
201
|
+
case 'incompatible-harness-policy':
|
|
202
|
+
case 'unverified-consumed':
|
|
203
|
+
case 'session-store-failed':
|
|
204
|
+
case 'no-submit':
|
|
205
|
+
case 'killed':
|
|
206
|
+
case 'lease-lost':
|
|
207
|
+
case 'ownership-error':
|
|
208
|
+
case 'hub-unreachable':
|
|
209
|
+
case 'stopped':
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Import the module named by `OWENLOOP_HARNESS_MODULE`, if any, so its
|
|
215
|
+
* `register(...)` side effect fires before adapter resolution.
|
|
216
|
+
*
|
|
217
|
+
* TEST SEAM. Phase 4 filled the composition root's static import block above
|
|
218
|
+
* with the real adapters, so production no longer needs this to have ANY
|
|
219
|
+
* adapter at all. What it still buys is the ability for a drill to register a
|
|
220
|
+
* FAKE adapter inside a real spawned child without the child reaching for a
|
|
221
|
+
* real CLI. Production leaves the variable unset and this is a no-op. Drills
|
|
222
|
+
* that use it also pin `OWENLOOP_HARNESS=fake`, because the statically
|
|
223
|
+
* imported real adapters now occupy the front of the registry and would
|
|
224
|
+
* otherwise win the `defaultHarnessId()` tie-break. A failed import is
|
|
225
|
+
* reported and then ignored — resolution proceeds and fails honestly with
|
|
226
|
+
* `'no-harness'` if nothing ended up registered.
|
|
227
|
+
*/
|
|
228
|
+
async function loadHarnessModule(spec, err) {
|
|
229
|
+
if (spec === undefined || spec.trim() === '')
|
|
230
|
+
return;
|
|
231
|
+
try {
|
|
232
|
+
await import(__rewriteRelativeImportExtension(spec));
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
err(`owenloop work agent-run: could not load OWENLOOP_HARNESS_MODULE '${spec}': ${errMsg(e)}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
export async function run(args, deps = {}) {
|
|
239
|
+
const out = deps.out ?? ((line) => void process.stdout.write(`${line}\n`));
|
|
240
|
+
const err = deps.err ?? ((line) => void process.stderr.write(`${line}\n`));
|
|
241
|
+
const parsed = parseArgs(args);
|
|
242
|
+
if (parsed.error !== undefined) {
|
|
243
|
+
err(`owenloop work agent-run: ${parsed.error}`);
|
|
244
|
+
usage();
|
|
245
|
+
return 2;
|
|
246
|
+
}
|
|
247
|
+
if (parsed.orderId === undefined || parsed.orderId === '') {
|
|
248
|
+
err('owenloop work agent-run: missing required <order-id>');
|
|
249
|
+
usage();
|
|
250
|
+
return 2;
|
|
251
|
+
}
|
|
252
|
+
const target = resolveTarget(parsed.orderId, parsed.workflow);
|
|
253
|
+
if ('error' in target) {
|
|
254
|
+
err(`owenloop work agent-run: ${target.error}`);
|
|
255
|
+
usage();
|
|
256
|
+
return 2;
|
|
257
|
+
}
|
|
258
|
+
const env = deps.env ?? process.env;
|
|
259
|
+
let settings;
|
|
260
|
+
try {
|
|
261
|
+
settings = loadSettings(env);
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
err(`owenloop work agent-run: ${errMsg(e)}`);
|
|
265
|
+
return 1;
|
|
266
|
+
}
|
|
267
|
+
const modelPolicy = createModelPolicy({
|
|
268
|
+
...(settings.tierMap !== undefined ? { tierMap: settings.tierMap } : {}),
|
|
269
|
+
...(settings.escalateAt !== undefined ? { escalateAt: settings.escalateAt } : {}),
|
|
270
|
+
...(settings.escalationExtensionKey !== undefined
|
|
271
|
+
? { escalationExtensionKey: settings.escalationExtensionKey }
|
|
272
|
+
: {}),
|
|
273
|
+
});
|
|
274
|
+
const origin = parsed.origin ?? settings.hubOrigin;
|
|
275
|
+
if (origin === undefined || origin.trim() === '') {
|
|
276
|
+
err('owenloop work agent-run: no hub origin — pass --origin <url> or set hubOrigin in settings');
|
|
277
|
+
return 2;
|
|
278
|
+
}
|
|
279
|
+
const consumedVerifier = deps.consumedVerifier ?? createConsumedVerifier({
|
|
280
|
+
env,
|
|
281
|
+
now: () => Date.now(),
|
|
282
|
+
});
|
|
283
|
+
const instructionCwd = deps.cwd ?? process.cwd();
|
|
284
|
+
let instructions = deps.instructions;
|
|
285
|
+
if (instructions === undefined) {
|
|
286
|
+
try {
|
|
287
|
+
instructions = createDefaultStoreInstructionResolver({ cwd: instructionCwd, env, consumedVerifier });
|
|
288
|
+
}
|
|
289
|
+
catch (e) {
|
|
290
|
+
err(`owenloop work agent-run: instruction store unavailable: ${errMsg(e)}`);
|
|
291
|
+
return 1;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
let cacheDir;
|
|
295
|
+
try {
|
|
296
|
+
cacheDir = resolveCacheDir(env, settings.cacheDir);
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
err(`owenloop work agent-run: ${errMsg(e)}`);
|
|
300
|
+
return 1;
|
|
301
|
+
}
|
|
302
|
+
// D10, CLOSED in Phase 6 (see the header). The dev-only bearer override is no
|
|
303
|
+
// longer passed to harness children: `filterOwenloopEnv` denies it in both
|
|
304
|
+
// adapters, because a harness child is an ordinary process that inherits this
|
|
305
|
+
// environment and at least one harness persists its start parameters to disk.
|
|
306
|
+
//
|
|
307
|
+
// THIS BLOCK IS THE OTHER HALF OF THAT CHANGE, and the two must stay together.
|
|
308
|
+
// If the worker kept honouring the override while the child could not see it,
|
|
309
|
+
// the two sides would authenticate as different principals: the worker with
|
|
310
|
+
// the override, the child falling back to its `agent:<account>` credential
|
|
311
|
+
// slot. An empty slot would then surface mid-order as an opaque MCP handshake
|
|
312
|
+
// failure, long after startup. So `agent-run` ignores the override too. Both
|
|
313
|
+
// sides now read the same slot, and an empty slot fails at STARTUP through
|
|
314
|
+
// `resolveBearer`'s existing exit-code-2 refusal, whose message names the
|
|
315
|
+
// login command to run.
|
|
316
|
+
//
|
|
317
|
+
// SCOPE: this file only. `resolveBearer` is unchanged and every other role
|
|
318
|
+
// keeps the override — `agent-run` is the one role that spawns a harness.
|
|
319
|
+
const workerEnv = { ...env };
|
|
320
|
+
if ((workerEnv['OWENLOOP_TOKEN'] ?? '') !== '') {
|
|
321
|
+
delete workerEnv['OWENLOOP_TOKEN'];
|
|
322
|
+
err('owenloop work agent-run: OWENLOOP_TOKEN is set and is being IGNORED here. The dev-only ' +
|
|
323
|
+
'bearer override is not passed to harness children, so honouring it would ' +
|
|
324
|
+
'authenticate the worker and the harness child as different principals. ' +
|
|
325
|
+
'Authenticate the account instead: `owenloop login --hub <origin> --as agent:<account>`.');
|
|
326
|
+
}
|
|
327
|
+
const account = workerEnv['OWENLOOP_ACCOUNT'] ?? 'default';
|
|
328
|
+
let hub = deps.hub;
|
|
329
|
+
if (hub === undefined) {
|
|
330
|
+
const bearer = await resolveBearer({ origin, account, env: workerEnv });
|
|
331
|
+
if (!bearer.ok) {
|
|
332
|
+
err(`owenloop work agent-run: ${bearer.message}`);
|
|
333
|
+
return bearer.code;
|
|
334
|
+
}
|
|
335
|
+
const token = bearer.token;
|
|
336
|
+
hub = createHubClient({ origin, getToken: async () => token });
|
|
337
|
+
}
|
|
338
|
+
const client = hub;
|
|
339
|
+
await loadHarnessModule(env['OWENLOOP_HARNESS_MODULE'], err);
|
|
340
|
+
const shiftId = resolveShiftId(parsed.shift, env);
|
|
341
|
+
const holder = {
|
|
342
|
+
kind: 'exec',
|
|
343
|
+
id: deps.holderId ?? `${hostname()}:${process.pid}`,
|
|
344
|
+
...(shiftId !== undefined ? { shiftId } : {}),
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Adapter id precedence: `--harness` > `OWENLOOP_HARNESS` > the step def's
|
|
348
|
+
* `harness` field > the first registered adapter. Every rank is a plain
|
|
349
|
+
* string comparison — nothing here knows what any id MEANS.
|
|
350
|
+
*/
|
|
351
|
+
const envHarness = env['OWENLOOP_HARNESS'];
|
|
352
|
+
const resolveAdapter = (stepHarness) => {
|
|
353
|
+
let id;
|
|
354
|
+
if (parsed.harness !== undefined) {
|
|
355
|
+
id = parsed.harness;
|
|
356
|
+
}
|
|
357
|
+
else if (envHarness !== undefined) {
|
|
358
|
+
// Definition and default selection are lower precedence. An explicit empty
|
|
359
|
+
// environment override is invalid; it must not silently fall through.
|
|
360
|
+
if (envHarness.trim() === '') {
|
|
361
|
+
return {
|
|
362
|
+
id: '<empty OWENLOOP_HARNESS>',
|
|
363
|
+
registered: registeredHarnessIds(),
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
id = envHarness;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
id =
|
|
370
|
+
(stepHarness !== undefined && stepHarness !== '' ? stepHarness : undefined) ??
|
|
371
|
+
defaultHarnessId() ??
|
|
372
|
+
'';
|
|
373
|
+
}
|
|
374
|
+
const adapter = id !== '' ? adapterFor(id) : undefined;
|
|
375
|
+
return {
|
|
376
|
+
id: id !== '' ? id : '<none>',
|
|
377
|
+
...(adapter !== undefined ? { adapter } : {}),
|
|
378
|
+
registered: registeredHarnessIds(),
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
/** Resolve the verified step from the local workflow store, never the prepare cache. */
|
|
382
|
+
const loadStep = async (order) => {
|
|
383
|
+
let resolved;
|
|
384
|
+
try {
|
|
385
|
+
resolved = await instructions.resolveStep(order);
|
|
386
|
+
}
|
|
387
|
+
catch (e) {
|
|
388
|
+
err(`owenloop work agent-run: instruction refusal (integrity): ${errMsg(e)}`);
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
if (!resolved.ok) {
|
|
392
|
+
err(`owenloop work agent-run: ${resolved.reason}`);
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
// Harness adapters build their child environment from process.env. This
|
|
396
|
+
// worker owns one agent order, so the resolver-derived bundle root is
|
|
397
|
+
// per-order state; clear it when provenance is absent to prevent stale
|
|
398
|
+
// values from reaching a later step in the same process.
|
|
399
|
+
if (resolved.bundleDir !== undefined)
|
|
400
|
+
process.env['OWENLOOP_BUNDLE_DIR'] = resolved.bundleDir;
|
|
401
|
+
else
|
|
402
|
+
delete process.env['OWENLOOP_BUNDLE_DIR'];
|
|
403
|
+
// Run identity is engine-derived from this worker's target, never a consumed
|
|
404
|
+
// artifact value. Both registered adapter paths read process.env when they
|
|
405
|
+
// build their child environments, so one setter covers both; overwrite
|
|
406
|
+
// ambient values so a nested agent sees its own identity, not its parent's.
|
|
407
|
+
process.env['OWENLOOP_WORKFLOW'] = target.workflow;
|
|
408
|
+
process.env['OWENLOOP_RUN'] = target.run;
|
|
409
|
+
let carrier;
|
|
410
|
+
const rawStep = resolved.step;
|
|
411
|
+
try {
|
|
412
|
+
carrier = parseHarnessCarrier(rawStep, order.workflow, resolved.step.name);
|
|
413
|
+
}
|
|
414
|
+
catch (e) {
|
|
415
|
+
err(`owenloop work agent-run: instruction refusal (harness-carrier): ${errMsg(e)}`);
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
if (carrier.harnessOptions !== undefined) {
|
|
419
|
+
const errors = validateHarnessOptions(carrier.harnessOptions, resolved.step.name)
|
|
420
|
+
.filter((finding) => finding.severity === 'error');
|
|
421
|
+
if (errors.length > 0) {
|
|
422
|
+
for (const finding of errors) {
|
|
423
|
+
err(`owenloop work agent-run: instruction refusal (harness-policy): step '${finding.step}' ` +
|
|
424
|
+
`x.harness.${finding.field ?? '<bag>'}: ${finding.message}`);
|
|
425
|
+
}
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return {
|
|
430
|
+
step: resolved.step.name,
|
|
431
|
+
brief: resolved.step.body,
|
|
432
|
+
...(carrier.harness !== undefined ? { harness: carrier.harness } : {}),
|
|
433
|
+
permissions: normalizeStepPermissions(carrier.harnessOptions, resolved.step),
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* The session-store sink. A durable `active` row is a provider-work start
|
|
438
|
+
* gate: failure propagates to the loop, which abandons the turn and releases
|
|
439
|
+
* the order before delivery. Later lifecycle rows remain best-effort resume
|
|
440
|
+
* metadata and are reported without replacing the lease as the hub truth.
|
|
441
|
+
*/
|
|
442
|
+
const sessionsFile = sessionsPath(cacheDir);
|
|
443
|
+
const writeSession = (rec) => {
|
|
444
|
+
try {
|
|
445
|
+
appendSession(sessionsFile, rec, { warn: err });
|
|
446
|
+
}
|
|
447
|
+
catch (e) {
|
|
448
|
+
err(`owenloop work agent-run: could not record the session in ${sessionsFile}: ${errMsg(e)}`);
|
|
449
|
+
if (rec.status === 'active')
|
|
450
|
+
throw e;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* PHASE 4 — where the step agent works when the hub supplies no `workdir`.
|
|
455
|
+
*
|
|
456
|
+
* Precedence, highest first:
|
|
457
|
+
* 1. `deps.cwd` — the test seam. An injected cwd is an explicit instruction
|
|
458
|
+
* and must not be second-guessed by a settings key.
|
|
459
|
+
* 2. `<workRoot>/<workflow>/<run>/`, created here.
|
|
460
|
+
* 3. `process.cwd()`, if creating that directory fails.
|
|
461
|
+
*
|
|
462
|
+
* `OrderPacket.workdir` outranks all three, but it lives on the packet, which
|
|
463
|
+
* this role never sees — `src/agent/loop.ts` applies it over whatever is
|
|
464
|
+
* passed here.
|
|
465
|
+
*
|
|
466
|
+
* Created EAGERLY, before the first order arrives, because the loop takes a
|
|
467
|
+
* plain `cwd: string` and turning it into a thunk would push a filesystem
|
|
468
|
+
* concern into the pure orchestration core. The cost of being early is one
|
|
469
|
+
* empty directory for a run whose packets all carry a hub `workdir`; the
|
|
470
|
+
* reaper removes it on the same terms as any other.
|
|
471
|
+
*/
|
|
472
|
+
let workCwd = deps.cwd ?? process.cwd();
|
|
473
|
+
if (deps.cwd === undefined) {
|
|
474
|
+
const workRoot = resolveWorkRoot(env, settings.workRoot, cacheDir);
|
|
475
|
+
const workRepo = resolveWorkRepo(env, settings.workRepo);
|
|
476
|
+
try {
|
|
477
|
+
workCwd = ensureWorkDir({
|
|
478
|
+
workRoot,
|
|
479
|
+
workflow: target.workflow,
|
|
480
|
+
run: target.run,
|
|
481
|
+
...(workRepo !== undefined ? { workRepo } : {}),
|
|
482
|
+
err,
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
catch (e) {
|
|
486
|
+
err(`owenloop work agent-run: could not create a work directory under ${workRoot}: ${errMsg(e)} — ` +
|
|
487
|
+
`falling back to ${workCwd}`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const loop = createAgentRunLoop({
|
|
491
|
+
hub: client,
|
|
492
|
+
workflow: target.workflow,
|
|
493
|
+
run: target.run,
|
|
494
|
+
holder,
|
|
495
|
+
origin,
|
|
496
|
+
account,
|
|
497
|
+
...(shiftId !== undefined ? { shiftId } : {}),
|
|
498
|
+
cwd: workCwd,
|
|
499
|
+
loadStep,
|
|
500
|
+
resolveAdapter,
|
|
501
|
+
modelPolicy,
|
|
502
|
+
consumedVerifier,
|
|
503
|
+
appendSession: writeSession,
|
|
504
|
+
nextAttempt: (workflow, run, step) => {
|
|
505
|
+
const prev = latestFor(sessionsFile, workflow, run, step);
|
|
506
|
+
return prev === null ? 1 : prev.attempt + 1;
|
|
507
|
+
},
|
|
508
|
+
// PHASE 4: the same reader `nextAttempt` uses, handed to the loop whole so
|
|
509
|
+
// it can decide resume vs cold replay. Reads only; the loop is what writes.
|
|
510
|
+
latestSession: (workflow, run, step) => latestFor(sessionsFile, workflow, run, step),
|
|
511
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
512
|
+
now: () => Date.now(),
|
|
513
|
+
out,
|
|
514
|
+
err,
|
|
515
|
+
heartbeatIntervalMs: parsed.heartbeatIntervalMs ?? DEFAULT_INTERVAL_MS,
|
|
516
|
+
// Test affordances only: each exposes an existing knob (defaults unchanged)
|
|
517
|
+
// so a drill can provoke a clock jump or a short confirm without waiting.
|
|
518
|
+
...(parsed.jumpToleranceMs !== undefined ? { jumpToleranceMs: parsed.jumpToleranceMs } : {}),
|
|
519
|
+
...(parsed.submitGraceMs !== undefined ? { submitGraceMs: parsed.submitGraceMs } : {}),
|
|
520
|
+
...(parsed.confirmIntervalMs !== undefined ? { confirmIntervalMs: parsed.confirmIntervalMs } : {}),
|
|
521
|
+
});
|
|
522
|
+
installSignalHandlers(loop, deps.signalHost ?? process, err, {
|
|
523
|
+
role: 'agent-run',
|
|
524
|
+
drainNote: 'stopping the step agent and releasing the order',
|
|
525
|
+
stopReason: 'signal',
|
|
526
|
+
});
|
|
527
|
+
const outcome = await loop.run();
|
|
528
|
+
return exitCodeFor(outcome);
|
|
529
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type HubClient } from '../hub/client.ts';
|
|
2
|
+
import { type ExecOutcome } from '../exec/loop.ts';
|
|
3
|
+
import { type InstructionResolver } from '../exec/instructions.ts';
|
|
4
|
+
import { type CommandRunner } from '../exec/runner.ts';
|
|
5
|
+
import { type ConsumedVerifier } from '../consumed-verifier.ts';
|
|
6
|
+
import { type SignalHost } from './signals.ts';
|
|
7
|
+
interface ParsedArgs {
|
|
8
|
+
orderId?: string;
|
|
9
|
+
workflow?: string;
|
|
10
|
+
origin?: string;
|
|
11
|
+
shift?: string;
|
|
12
|
+
heartbeatIntervalMs?: number;
|
|
13
|
+
jumpToleranceMs?: number;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse the positional `<order-id>` plus `--workflow`/`--origin`/
|
|
18
|
+
* `--heartbeat-interval`/`--jump-tolerance`. Supports `--flag value` and
|
|
19
|
+
* `--flag=value`; a second positional or an unknown flag is an error.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseArgs(args: string[]): ParsedArgs;
|
|
22
|
+
/** Map the loop's outcome onto the process exit code (see usage.ts). */
|
|
23
|
+
export declare function exitCodeFor(outcome: ExecOutcome): number;
|
|
24
|
+
/**
|
|
25
|
+
* Injectable process-boundary deps for `run` — defaulting to the real ones, so
|
|
26
|
+
* the role wiring (holder tag, signal handlers, outcome mapping) is testable
|
|
27
|
+
* without spawning a real child, signaling the test process, or reaching a real
|
|
28
|
+
* hub.
|
|
29
|
+
*/
|
|
30
|
+
export interface RunDeps {
|
|
31
|
+
signalHost?: SignalHost;
|
|
32
|
+
hub?: HubClient;
|
|
33
|
+
runner?: CommandRunner;
|
|
34
|
+
/** Store-backed instruction resolver; injected tests may provide a fake. */
|
|
35
|
+
instructions?: InstructionResolver;
|
|
36
|
+
/** Consume-side verifier; injected tests may provide a fake. */
|
|
37
|
+
consumedVerifier?: ConsumedVerifier;
|
|
38
|
+
out?: (line: string) => void;
|
|
39
|
+
err?: (line: string) => void;
|
|
40
|
+
/** cwd for a command order that carries no `workdir` (default `process.cwd()`). */
|
|
41
|
+
cwd?: string;
|
|
42
|
+
/** Environment used to derive the global workflow-store root. */
|
|
43
|
+
env?: Record<string, string | undefined>;
|
|
44
|
+
/** Holder id override (default `<hostname>:<pid>`) — pinned in tests. */
|
|
45
|
+
holderId?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function run(args: string[], deps?: RunDeps): Promise<number>;
|
|
48
|
+
export {};
|