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,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local JSON-lines protocol for the foreground shift daemon.
|
|
3
|
+
*
|
|
4
|
+
* The protocol is deliberately small: one request per Unix-socket connection,
|
|
5
|
+
* one response line, then the connection closes. The hub remains the owner of
|
|
6
|
+
* workflow state; this protocol only carries local dispatch observations and
|
|
7
|
+
* attendance commands between the CLI and one daemon process.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SHIFT_SOCKET_NAME = "shift.sock";
|
|
10
|
+
export declare const DEFAULT_NEXT_WAIT_MS = 90000;
|
|
11
|
+
export declare const MAX_REQUEST_LINE_BYTES: number;
|
|
12
|
+
/**
|
|
13
|
+
* The server measures each response's serialized UTF-8 byte length against this
|
|
14
|
+
* ceiling and retains FIFO events that do not fit. A single event whose fields
|
|
15
|
+
* exceed the ceiling is rendered with an explicit truncation marker.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MAX_RESPONSE_LINE_BYTES: number;
|
|
18
|
+
export declare const RESPONSE_TRUNCATION_MARKER = "[truncated]";
|
|
19
|
+
export declare const MAX_EVENT_QUEUE = 1000;
|
|
20
|
+
export declare const OVERLAP_ERROR = "whats_next is already parked \u2014 one park at a time (cancel it or wait for it to return)";
|
|
21
|
+
export declare const NO_DAEMON_SUFFIX = " \u2014 start one with: owenloop shift start <crew\u2026>";
|
|
22
|
+
export type ShiftRequest = {
|
|
23
|
+
op: 'next';
|
|
24
|
+
wait_ms: number;
|
|
25
|
+
} | {
|
|
26
|
+
op: 'status';
|
|
27
|
+
} | {
|
|
28
|
+
op: 'clock_in';
|
|
29
|
+
serve_crews: string[];
|
|
30
|
+
name: string;
|
|
31
|
+
} | {
|
|
32
|
+
op: 'end';
|
|
33
|
+
};
|
|
34
|
+
export interface DispatchedEvent {
|
|
35
|
+
type: 'dispatched';
|
|
36
|
+
workflow: string;
|
|
37
|
+
run: string;
|
|
38
|
+
step: string;
|
|
39
|
+
kind: 'exec' | 'agent-run';
|
|
40
|
+
pid: number;
|
|
41
|
+
}
|
|
42
|
+
export interface ReapedEvent {
|
|
43
|
+
type: 'reaped';
|
|
44
|
+
workflow: string;
|
|
45
|
+
run: string;
|
|
46
|
+
kind: 'exec' | 'agent-run';
|
|
47
|
+
pid: number;
|
|
48
|
+
}
|
|
49
|
+
export interface FailedEvent {
|
|
50
|
+
type: 'failed';
|
|
51
|
+
workflow: string;
|
|
52
|
+
run: string;
|
|
53
|
+
step: string;
|
|
54
|
+
kind: 'exec' | 'agent-run';
|
|
55
|
+
harness?: string;
|
|
56
|
+
executable?: string;
|
|
57
|
+
exitStatus?: number | null;
|
|
58
|
+
signal?: NodeJS.Signals | null;
|
|
59
|
+
message: string;
|
|
60
|
+
}
|
|
61
|
+
/** Reserved for a future local representation of a pending hub gate. */
|
|
62
|
+
export interface GateEvent {
|
|
63
|
+
type: 'gate';
|
|
64
|
+
workflow?: string;
|
|
65
|
+
run?: string;
|
|
66
|
+
name?: string;
|
|
67
|
+
question?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface EndedEvent {
|
|
70
|
+
type: 'ended';
|
|
71
|
+
}
|
|
72
|
+
export type ShiftEvent = DispatchedEvent | ReapedEvent | FailedEvent | GateEvent | EndedEvent;
|
|
73
|
+
export interface ShiftCapacity {
|
|
74
|
+
cap: number;
|
|
75
|
+
free: number;
|
|
76
|
+
running: number;
|
|
77
|
+
events: ShiftEvent[];
|
|
78
|
+
}
|
|
79
|
+
export interface ShiftStatus {
|
|
80
|
+
name: string;
|
|
81
|
+
serve_crews: string[];
|
|
82
|
+
cap: number;
|
|
83
|
+
free: number;
|
|
84
|
+
running: number;
|
|
85
|
+
attended_at: number | null;
|
|
86
|
+
started_at: number;
|
|
87
|
+
}
|
|
88
|
+
export interface ShiftError {
|
|
89
|
+
error: string;
|
|
90
|
+
}
|
|
91
|
+
export type ShiftResponse = ShiftCapacity | ShiftStatus | ShiftError | {
|
|
92
|
+
ok: true;
|
|
93
|
+
ended: true;
|
|
94
|
+
};
|
|
95
|
+
export declare function isShiftError(value: unknown): value is ShiftError;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local JSON-lines protocol for the foreground shift daemon.
|
|
3
|
+
*
|
|
4
|
+
* The protocol is deliberately small: one request per Unix-socket connection,
|
|
5
|
+
* one response line, then the connection closes. The hub remains the owner of
|
|
6
|
+
* workflow state; this protocol only carries local dispatch observations and
|
|
7
|
+
* attendance commands between the CLI and one daemon process.
|
|
8
|
+
*/
|
|
9
|
+
export const SHIFT_SOCKET_NAME = 'shift.sock';
|
|
10
|
+
export const DEFAULT_NEXT_WAIT_MS = 90_000;
|
|
11
|
+
export const MAX_REQUEST_LINE_BYTES = 64 * 1024;
|
|
12
|
+
/**
|
|
13
|
+
* The server measures each response's serialized UTF-8 byte length against this
|
|
14
|
+
* ceiling and retains FIFO events that do not fit. A single event whose fields
|
|
15
|
+
* exceed the ceiling is rendered with an explicit truncation marker.
|
|
16
|
+
*/
|
|
17
|
+
export const MAX_RESPONSE_LINE_BYTES = 512 * 1024;
|
|
18
|
+
export const RESPONSE_TRUNCATION_MARKER = '[truncated]';
|
|
19
|
+
export const MAX_EVENT_QUEUE = 1_000;
|
|
20
|
+
export const OVERLAP_ERROR = 'whats_next is already parked — one park at a time (cancel it or wait for it to return)';
|
|
21
|
+
export const NO_DAEMON_SUFFIX = ' — start one with: owenloop shift start <crew…>';
|
|
22
|
+
export function isShiftError(value) {
|
|
23
|
+
return typeof value === 'object' && value !== null && typeof value.error === 'string';
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command-order routing (plan decision 5). owenloop owns the `x.owenloop` bag
|
|
3
|
+
* on a step — owenloop treats `x` as opaque — and this module defines its one
|
|
4
|
+
* field so far: `routing: 'shift' | 'manual'`.
|
|
5
|
+
*
|
|
6
|
+
* The knob answers ONE question for a `executor: 'command'` step: does THIS shift
|
|
7
|
+
* auto-dispatch it, or leave it for a human/session to pick up? Two inputs feed
|
|
8
|
+
* the decision — the machine-level `commandRouting` setting (default `'shift'`)
|
|
9
|
+
* and the per-step `x.owenloop.routing` override — and MOST RESTRICTIVE WINS:
|
|
10
|
+
* if either says `'manual'`, the shift does not auto-run the command. An
|
|
11
|
+
* invalid/unknown value anywhere fails CLOSED to `'manual'` plus a warning —
|
|
12
|
+
* we never auto-run a command step on a value we could not parse.
|
|
13
|
+
*
|
|
14
|
+
* Agent orders are NOT routed through this knob (decision 5) — only command
|
|
15
|
+
* steps. Pure functions; no I/O, no side effects beyond the returned warnings.
|
|
16
|
+
*/
|
|
17
|
+
import type { FetchedStep } from '../bundle/types.ts';
|
|
18
|
+
export type Routing = 'shift' | 'manual';
|
|
19
|
+
/** True for a `executor: 'command'` step (owenloop RAW_STEP_KEYS `executor`). */
|
|
20
|
+
export declare function isCommandStep(step: FetchedStep): boolean;
|
|
21
|
+
export interface RoutingResolution {
|
|
22
|
+
/** The resolved routing after applying most-restrictive-wins. */
|
|
23
|
+
routing: Routing;
|
|
24
|
+
/** Convenience: whether the shift should auto-dispatch this command order. */
|
|
25
|
+
autoDispatch: boolean;
|
|
26
|
+
/** Human-readable warnings (invalid values that failed closed). */
|
|
27
|
+
warnings: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolve whether the shift auto-dispatches a command step. `machineRaw` is the
|
|
31
|
+
* `commandRouting` setting value (unknown — it came from a JSON file); the step
|
|
32
|
+
* override is read from `x.owenloop.routing`. Most restrictive wins; invalid
|
|
33
|
+
* anywhere ⇒ manual + warning.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveCommandRouting(machineRaw: unknown, step: FetchedStep): RoutingResolution;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** True for a `executor: 'command'` step (owenloop RAW_STEP_KEYS `executor`). */
|
|
2
|
+
export function isCommandStep(step) {
|
|
3
|
+
return step.executor === 'command';
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Coerce an unknown into a `Routing`. `undefined` maps to `absentDefault` with
|
|
7
|
+
* no warning (the field simply wasn't set); any other non-`Routing` value is an
|
|
8
|
+
* error that fails closed to `'manual'` and appends a warning.
|
|
9
|
+
*/
|
|
10
|
+
function coerceRouting(raw, absentDefault, label, warnings) {
|
|
11
|
+
if (raw === undefined)
|
|
12
|
+
return absentDefault;
|
|
13
|
+
if (raw === 'shift' || raw === 'manual')
|
|
14
|
+
return raw;
|
|
15
|
+
warnings.push(`invalid ${label} '${String(raw)}' — failing closed to 'manual' (command not auto-run)`);
|
|
16
|
+
return 'manual';
|
|
17
|
+
}
|
|
18
|
+
/** Read `x.owenloop.routing` off a step, distinguishing a malformed bag. */
|
|
19
|
+
function stepRoutingRaw(step) {
|
|
20
|
+
const x = step.x;
|
|
21
|
+
if (x === undefined || typeof x !== 'object' || x === null)
|
|
22
|
+
return { raw: undefined, malformedBag: false };
|
|
23
|
+
const bag = x['owenloop'];
|
|
24
|
+
if (bag === undefined)
|
|
25
|
+
return { raw: undefined, malformedBag: false };
|
|
26
|
+
if (typeof bag !== 'object' || bag === null || Array.isArray(bag))
|
|
27
|
+
return { raw: undefined, malformedBag: true };
|
|
28
|
+
return { raw: bag['routing'], malformedBag: false };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve whether the shift auto-dispatches a command step. `machineRaw` is the
|
|
32
|
+
* `commandRouting` setting value (unknown — it came from a JSON file); the step
|
|
33
|
+
* override is read from `x.owenloop.routing`. Most restrictive wins; invalid
|
|
34
|
+
* anywhere ⇒ manual + warning.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveCommandRouting(machineRaw, step) {
|
|
37
|
+
const warnings = [];
|
|
38
|
+
const machine = coerceRouting(machineRaw, 'shift', 'commandRouting setting', warnings);
|
|
39
|
+
const { raw: overrideRaw, malformedBag } = stepRoutingRaw(step);
|
|
40
|
+
let override;
|
|
41
|
+
if (malformedBag) {
|
|
42
|
+
warnings.push(`step '${step.name}' has a malformed x.owenloop bag — failing closed to 'manual'`);
|
|
43
|
+
override = 'manual';
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
override = coerceRouting(overrideRaw, 'shift', `x.owenloop.routing on step '${step.name}'`, warnings);
|
|
47
|
+
}
|
|
48
|
+
const routing = machine === 'manual' || override === 'manual' ? 'manual' : 'shift';
|
|
49
|
+
return { routing, autoDispatch: routing === 'shift', warnings };
|
|
50
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { installSignalHandlers, type SignalHost } from '../roles/signals.ts';
|
|
2
|
+
export { installSignalHandlers, type SignalHost };
|
|
3
|
+
export declare function resolveCap(flagCap: number | undefined, settingsCap: number | undefined): number;
|
|
4
|
+
export declare function resolveStateDirOverride(flag: string | undefined, env: Record<string, string | undefined>, settingsStateDir: string | undefined): string | undefined;
|
|
5
|
+
export declare function resolveMaxConcurrentAgents(flagMax: number | undefined, settingsMax: number | undefined): number;
|
|
6
|
+
export declare function resolveShiftName(flagName: string | undefined, opts?: {
|
|
7
|
+
shiftId?: string;
|
|
8
|
+
hostname?: string;
|
|
9
|
+
cwd?: string;
|
|
10
|
+
pid?: number;
|
|
11
|
+
}): string;
|
|
12
|
+
export interface ParsedArgs {
|
|
13
|
+
origin?: string;
|
|
14
|
+
as?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
serveCrews?: string[];
|
|
17
|
+
cap?: number;
|
|
18
|
+
workflow?: string;
|
|
19
|
+
pollIntervalMs?: number;
|
|
20
|
+
once?: boolean;
|
|
21
|
+
maxAgents?: number;
|
|
22
|
+
cacheDir?: string;
|
|
23
|
+
stateDir?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Parse shift's internal `--flag value` and `--flag=value` forms. */
|
|
27
|
+
export declare function parseArgs(args: string[]): ParsedArgs;
|
|
28
|
+
export interface ShiftRuntimeOptions {
|
|
29
|
+
/** Build the Unix-socket shift daemon around the same loop instead of self-driving directly. */
|
|
30
|
+
daemon?: boolean;
|
|
31
|
+
/** Output prefix for errors and lifecycle messages. */
|
|
32
|
+
role?: 'shift';
|
|
33
|
+
/** Socket path selected by the shift command. */
|
|
34
|
+
socketPath?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Public Shift daemon transport is a Unix-domain socket on macOS and Linux. */
|
|
37
|
+
export declare function assertShiftDaemonPlatform(platform?: NodeJS.Platform): void;
|
|
38
|
+
/**
|
|
39
|
+
* Shared runtime setup for the internal shift and public shift daemon.
|
|
40
|
+
* `parsed` is already grammar-validated by the caller; this function owns all
|
|
41
|
+
* credential/settings/cache/spawner resolution so the two entry points cannot
|
|
42
|
+
* drift.
|
|
43
|
+
*/
|
|
44
|
+
export declare function runShiftRuntime(parsed: ParsedArgs, options?: ShiftRuntimeOptions): Promise<number>;
|
|
45
|
+
export declare function run(args: string[]): Promise<number>;
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `owenloop work shift` — the internal standing Shift loop.
|
|
3
|
+
*
|
|
4
|
+
* The human-facing shift daemon uses the same setup and ShiftLoop through
|
|
5
|
+
* `runShiftRuntime(..., { daemon: true })`; this module remains the single place
|
|
6
|
+
* that resolves settings, credentials, caches, child spawners, and signal
|
|
7
|
+
* behavior. The retired shift stdio-MCP mount is intentionally absent.
|
|
8
|
+
*/
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { hostname } from 'node:os';
|
|
11
|
+
import { basename, join } from 'node:path';
|
|
12
|
+
import { performance } from 'node:perf_hooks';
|
|
13
|
+
import { createHubClient } from "../hub/client.js";
|
|
14
|
+
import { resolveBearer } from "../credentials/resolve.js";
|
|
15
|
+
import { loadSettings } from "../settings/settings.js";
|
|
16
|
+
import { resolveCacheDir } from "../bundle/cache.js";
|
|
17
|
+
import { createShiftLoop } from "./loop.js";
|
|
18
|
+
import { createDefaultSpawner } from "./spawn.js";
|
|
19
|
+
import { resolveStateDir, ensureStateDir, reconcileInFlight } from "./state.js";
|
|
20
|
+
import { reconcileActiveSessions, sessionsPath } from "../harness/session-store.js";
|
|
21
|
+
import { resolveWorkRepo, resolveWorkRoot } from "../agent/workdir.js";
|
|
22
|
+
import { installSignalHandlers } from "../roles/signals.js";
|
|
23
|
+
import { createShiftDaemon } from "./server.js";
|
|
24
|
+
import { createBundleIngestor, createStoreInstructionSource, globalStoreRoot, } from "../../../../src/store/index.js";
|
|
25
|
+
// Re-exported so existing importers keep their import site while the
|
|
26
|
+
// implementation lives in the shared signals seam.
|
|
27
|
+
export { installSignalHandlers };
|
|
28
|
+
const DEFAULT_CAP = 3;
|
|
29
|
+
const DEFAULT_POLL_MS = 5_000;
|
|
30
|
+
const DEFAULT_MAX_AGENTS = 4;
|
|
31
|
+
const DEFAULT_PRESENCE_MS = 60_000;
|
|
32
|
+
export function resolveCap(flagCap, settingsCap) {
|
|
33
|
+
return flagCap ?? settingsCap ?? DEFAULT_CAP;
|
|
34
|
+
}
|
|
35
|
+
export function resolveStateDirOverride(flag, env, settingsStateDir) {
|
|
36
|
+
return flag ?? env['OWENLOOP_STATE_DIR'] ?? settingsStateDir;
|
|
37
|
+
}
|
|
38
|
+
export function resolveMaxConcurrentAgents(flagMax, settingsMax) {
|
|
39
|
+
return flagMax ?? settingsMax ?? DEFAULT_MAX_AGENTS;
|
|
40
|
+
}
|
|
41
|
+
export function resolveShiftName(flagName, opts = {}) {
|
|
42
|
+
if (flagName !== undefined && flagName !== '')
|
|
43
|
+
return flagName;
|
|
44
|
+
const suffix = opts.shiftId !== undefined && opts.shiftId !== ''
|
|
45
|
+
? opts.shiftId.replace(/^shf_/, '').replace(/-/g, '').slice(0, 6)
|
|
46
|
+
: `p${opts.pid ?? process.pid}`;
|
|
47
|
+
return `${opts.hostname ?? hostname()}/${basename(opts.cwd ?? process.cwd())}#${suffix}`;
|
|
48
|
+
}
|
|
49
|
+
/** Parse shift's internal `--flag value` and `--flag=value` forms. */
|
|
50
|
+
export function parseArgs(args) {
|
|
51
|
+
const parsed = {};
|
|
52
|
+
const takeValue = (a, i) => {
|
|
53
|
+
const eq = a.indexOf('=');
|
|
54
|
+
if (eq !== -1)
|
|
55
|
+
return { value: a.slice(eq + 1), next: i };
|
|
56
|
+
const v = args[i + 1];
|
|
57
|
+
if (v === undefined)
|
|
58
|
+
return { error: `missing value for ${a}` };
|
|
59
|
+
return { value: v, next: i + 1 };
|
|
60
|
+
};
|
|
61
|
+
const intFlag = (raw, flag) => {
|
|
62
|
+
const n = Number(raw);
|
|
63
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 0) {
|
|
64
|
+
return { error: `${flag} must be a non-negative integer, got '${raw}'` };
|
|
65
|
+
}
|
|
66
|
+
return n;
|
|
67
|
+
};
|
|
68
|
+
for (let i = 0; i < args.length; i++) {
|
|
69
|
+
const a = args[i];
|
|
70
|
+
const name = a.startsWith('--') && a.includes('=') ? a.slice(0, a.indexOf('=')) : a;
|
|
71
|
+
switch (name) {
|
|
72
|
+
case '--once':
|
|
73
|
+
parsed.once = true;
|
|
74
|
+
break;
|
|
75
|
+
case '--origin':
|
|
76
|
+
case '--as':
|
|
77
|
+
case '--name':
|
|
78
|
+
case '--serve-crews':
|
|
79
|
+
case '--cap':
|
|
80
|
+
case '--max-agents':
|
|
81
|
+
case '--workflow':
|
|
82
|
+
case '--poll-interval':
|
|
83
|
+
case '--cache-dir':
|
|
84
|
+
case '--state-dir': {
|
|
85
|
+
const r = takeValue(a, i);
|
|
86
|
+
if ('error' in r)
|
|
87
|
+
return { error: r.error };
|
|
88
|
+
i = r.next;
|
|
89
|
+
if (name === '--origin')
|
|
90
|
+
parsed.origin = r.value;
|
|
91
|
+
else if (name === '--as')
|
|
92
|
+
parsed.as = r.value;
|
|
93
|
+
else if (name === '--name') {
|
|
94
|
+
if (r.value.trim() === '')
|
|
95
|
+
return { error: '--name requires a non-empty value' };
|
|
96
|
+
parsed.name = r.value;
|
|
97
|
+
}
|
|
98
|
+
else if (name === '--serve-crews') {
|
|
99
|
+
parsed.serveCrews = r.value.split(',').map((s) => s.trim()).filter((s) => s !== '');
|
|
100
|
+
}
|
|
101
|
+
else if (name === '--workflow')
|
|
102
|
+
parsed.workflow = r.value;
|
|
103
|
+
else if (name === '--cache-dir')
|
|
104
|
+
parsed.cacheDir = r.value;
|
|
105
|
+
else if (name === '--state-dir')
|
|
106
|
+
parsed.stateDir = r.value;
|
|
107
|
+
else if (name === '--cap') {
|
|
108
|
+
const n = intFlag(r.value, '--cap');
|
|
109
|
+
if (typeof n !== 'number')
|
|
110
|
+
return { error: n.error };
|
|
111
|
+
parsed.cap = n;
|
|
112
|
+
}
|
|
113
|
+
else if (name === '--max-agents') {
|
|
114
|
+
const n = intFlag(r.value, '--max-agents');
|
|
115
|
+
if (typeof n !== 'number')
|
|
116
|
+
return { error: n.error };
|
|
117
|
+
parsed.maxAgents = n;
|
|
118
|
+
}
|
|
119
|
+
else if (name === '--poll-interval') {
|
|
120
|
+
const n = intFlag(r.value, '--poll-interval');
|
|
121
|
+
if (typeof n !== 'number')
|
|
122
|
+
return { error: n.error };
|
|
123
|
+
parsed.pollIntervalMs = n;
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
default:
|
|
128
|
+
return { error: `unknown option '${a}'` };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return parsed;
|
|
132
|
+
}
|
|
133
|
+
function usage() {
|
|
134
|
+
process.stderr.write('usage: owenloop work shift [--origin <url>] [--as <account>] [--name <n>] [--serve-crews a,b] [--cap <n>]\n' +
|
|
135
|
+
' [--workflow <id>] [--poll-interval <ms>] [--once]\n' +
|
|
136
|
+
' [--max-agents <n>] [--cache-dir <p>] [--state-dir <p>]\n');
|
|
137
|
+
}
|
|
138
|
+
function errMsg(err) {
|
|
139
|
+
return err instanceof Error ? err.message : String(err);
|
|
140
|
+
}
|
|
141
|
+
/** Public Shift daemon transport is a Unix-domain socket on macOS and Linux. */
|
|
142
|
+
export function assertShiftDaemonPlatform(platform = process.platform) {
|
|
143
|
+
if (platform === 'win32') {
|
|
144
|
+
throw new Error('the public Shift daemon is not supported on Windows: Windows named-pipe transport is not implemented; ' +
|
|
145
|
+
'use `owenloop work shift` directly');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Shared runtime setup for the internal shift and public shift daemon.
|
|
150
|
+
* `parsed` is already grammar-validated by the caller; this function owns all
|
|
151
|
+
* credential/settings/cache/spawner resolution so the two entry points cannot
|
|
152
|
+
* drift.
|
|
153
|
+
*/
|
|
154
|
+
export async function runShiftRuntime(parsed, options = {}) {
|
|
155
|
+
const daemonMode = options.daemon === true;
|
|
156
|
+
const roleLabel = options.role === 'shift' ? 'owenloop shift' : 'owenloop work shift';
|
|
157
|
+
if (daemonMode) {
|
|
158
|
+
try {
|
|
159
|
+
assertShiftDaemonPlatform();
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
process.stderr.write(`${roleLabel}: ${errMsg(error)}\n`);
|
|
163
|
+
return 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const env = process.env;
|
|
167
|
+
let settings;
|
|
168
|
+
try {
|
|
169
|
+
settings = loadSettings(env);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
process.stderr.write(`${roleLabel}: ${errMsg(err)}\n`);
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
const origin = parsed.origin ?? settings.hubOrigin;
|
|
176
|
+
if (origin === undefined || origin.trim() === '') {
|
|
177
|
+
process.stderr.write(`${roleLabel}: no hub origin — pass --origin <url> or set hubOrigin in settings\n`);
|
|
178
|
+
return 2;
|
|
179
|
+
}
|
|
180
|
+
if (parsed.as !== undefined && parsed.as.trim() === '') {
|
|
181
|
+
process.stderr.write(`${roleLabel}: --as requires a non-empty account name\n`);
|
|
182
|
+
return 2;
|
|
183
|
+
}
|
|
184
|
+
const account = parsed.as ?? 'default';
|
|
185
|
+
const bearer = await resolveBearer({ origin, account, env });
|
|
186
|
+
if (!bearer.ok) {
|
|
187
|
+
process.stderr.write(`${roleLabel}: ${bearer.message}\n`);
|
|
188
|
+
return bearer.code;
|
|
189
|
+
}
|
|
190
|
+
const token = bearer.token;
|
|
191
|
+
let cacheDir;
|
|
192
|
+
let stateDir;
|
|
193
|
+
try {
|
|
194
|
+
cacheDir = parsed.cacheDir ?? resolveCacheDir(env, settings.cacheDir);
|
|
195
|
+
stateDir = resolveStateDir(env, resolveStateDirOverride(parsed.stateDir, env, settings.stateDir));
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
process.stderr.write(`${roleLabel}: ${errMsg(err)}\n`);
|
|
199
|
+
return 1;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
ensureStateDir(stateDir);
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
process.stderr.write(`${roleLabel}: cannot initialize dispatch state at ${stateDir}: ${errMsg(err)}\n`);
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
{
|
|
209
|
+
const liveRunIds = new Set(reconcileInFlight(stateDir).live.filter((r) => r.kind === 'agent-run').map((r) => r.run));
|
|
210
|
+
try {
|
|
211
|
+
const retired = reconcileActiveSessions(sessionsPath(cacheDir), liveRunIds, Date.now());
|
|
212
|
+
for (const rec of retired) {
|
|
213
|
+
process.stderr.write(`${roleLabel}: retired orphaned session ${rec.workflow}/${rec.run} step '${rec.step}' ` +
|
|
214
|
+
`(harness '${rec.harness}', attempt ${String(rec.attempt ?? 1)}) — its worker is gone, ` +
|
|
215
|
+
'so the next attempt replays cold\n');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
process.stderr.write(`${roleLabel}: session reconcile failed (continuing): ${errMsg(err)}\n`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const cap = resolveCap(parsed.cap, settings.dispatchCap);
|
|
223
|
+
const maxConcurrentAgents = resolveMaxConcurrentAgents(parsed.maxAgents, settings.maxConcurrentAgents);
|
|
224
|
+
const workRoot = resolveWorkRoot(env, settings.workRoot, cacheDir);
|
|
225
|
+
const workRepo = resolveWorkRepo(env, settings.workRepo);
|
|
226
|
+
const hub = createHubClient({ origin, getToken: async () => token });
|
|
227
|
+
const now = () => Date.now();
|
|
228
|
+
const monotonicNow = () => performance.now();
|
|
229
|
+
const home = [env.HOME, env.USERPROFILE].find((value) => value !== undefined && value.trim() !== '');
|
|
230
|
+
// Legacy orders and modern agent orders do not need Shift-side instruction
|
|
231
|
+
// lookup. Keep serving those lanes without a home directory; a modern command
|
|
232
|
+
// order still fails closed because its exact digest cannot be resolved.
|
|
233
|
+
const instructionSource = home === undefined
|
|
234
|
+
? undefined
|
|
235
|
+
: createStoreInstructionSource({
|
|
236
|
+
projectRoot: join(process.cwd(), 'workflows'),
|
|
237
|
+
globalRoot: globalStoreRoot(home),
|
|
238
|
+
verifier: createBundleIngestor(),
|
|
239
|
+
});
|
|
240
|
+
const resolveOrderStep = async (order) => {
|
|
241
|
+
if (instructionSource === undefined ||
|
|
242
|
+
order.defDigest === undefined ||
|
|
243
|
+
order.defDigest.trim() === '')
|
|
244
|
+
return undefined;
|
|
245
|
+
if (await instructionSource.prime(order.defDigest) !== 'resolved')
|
|
246
|
+
return undefined;
|
|
247
|
+
return instructionSource.getVerifiedStep(order.defDigest, order.step);
|
|
248
|
+
};
|
|
249
|
+
const shiftId = `shf_${randomUUID()}`;
|
|
250
|
+
const startedAt = now();
|
|
251
|
+
const name = resolveShiftName(parsed.name, { shiftId });
|
|
252
|
+
let daemon;
|
|
253
|
+
const reportWorkerFailure = (failure) => {
|
|
254
|
+
const event = {
|
|
255
|
+
type: 'failed',
|
|
256
|
+
workflow: failure.workflow,
|
|
257
|
+
run: failure.run,
|
|
258
|
+
step: failure.step ?? '(unknown)',
|
|
259
|
+
kind: failure.kind,
|
|
260
|
+
...(failure.harness !== undefined ? { harness: failure.harness } : {}),
|
|
261
|
+
executable: failure.executable,
|
|
262
|
+
exitStatus: failure.exitStatus,
|
|
263
|
+
signal: failure.signal,
|
|
264
|
+
message: failure.message,
|
|
265
|
+
};
|
|
266
|
+
daemon?.onEvent(event);
|
|
267
|
+
process.stderr.write(`${roleLabel}: worker failure ${JSON.stringify(event)}\n`);
|
|
268
|
+
};
|
|
269
|
+
const spawner = createDefaultSpawner(origin, account, undefined, shiftId, reportWorkerFailure);
|
|
270
|
+
const pollIntervalMs = parsed.pollIntervalMs ?? DEFAULT_POLL_MS;
|
|
271
|
+
const loop = createShiftLoop({
|
|
272
|
+
hub,
|
|
273
|
+
spawner,
|
|
274
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
275
|
+
now,
|
|
276
|
+
monotonicNow,
|
|
277
|
+
out: (line) => process.stdout.write(`${line}\n`),
|
|
278
|
+
err: (line) => process.stderr.write(`${line}\n`),
|
|
279
|
+
...(daemonMode ? { onEvent: (event) => daemon?.onEvent(event) } : {}),
|
|
280
|
+
cacheDir,
|
|
281
|
+
stateDir,
|
|
282
|
+
cap,
|
|
283
|
+
serveCrews: parsed.serveCrews ?? [],
|
|
284
|
+
name,
|
|
285
|
+
commandRouting: settings.commandRouting,
|
|
286
|
+
resolveOrderStep,
|
|
287
|
+
pollIntervalMs,
|
|
288
|
+
presenceIntervalMs: DEFAULT_PRESENCE_MS,
|
|
289
|
+
maxConcurrentAgents,
|
|
290
|
+
workRoot,
|
|
291
|
+
...(workRepo !== undefined ? { workRepo } : {}),
|
|
292
|
+
shiftId,
|
|
293
|
+
startedAt,
|
|
294
|
+
...(parsed.workflow !== undefined ? { workflow: parsed.workflow } : {}),
|
|
295
|
+
...(parsed.once === true ? { once: true } : {}),
|
|
296
|
+
});
|
|
297
|
+
if (daemonMode) {
|
|
298
|
+
daemon = createShiftDaemon({
|
|
299
|
+
socketPath: options.socketPath ?? join(stateDir, 'shift.sock'),
|
|
300
|
+
stateDir,
|
|
301
|
+
loop,
|
|
302
|
+
hub,
|
|
303
|
+
now,
|
|
304
|
+
startedAt,
|
|
305
|
+
shiftId,
|
|
306
|
+
err: (line) => process.stderr.write(`${line}\n`),
|
|
307
|
+
});
|
|
308
|
+
installSignalHandlers(daemon, process, (line) => process.stderr.write(`${line}\n`), {
|
|
309
|
+
role: 'shift',
|
|
310
|
+
drainNote: 'draining, in-flight children keep running',
|
|
311
|
+
stopReason: 'signal',
|
|
312
|
+
});
|
|
313
|
+
if (parsed.once !== true) {
|
|
314
|
+
process.stdout.write(`owenloop shift: parked as '${name}' @ ${origin} (cap ${cap})\n`);
|
|
315
|
+
}
|
|
316
|
+
return daemon.run();
|
|
317
|
+
}
|
|
318
|
+
installSignalHandlers(loop, process, (line) => process.stderr.write(`${line}\n`));
|
|
319
|
+
if (parsed.once !== true) {
|
|
320
|
+
process.stdout.write(`owenloop work shift: parked as '${name}' @ ${origin} (cap ${cap})\n`);
|
|
321
|
+
}
|
|
322
|
+
return loop.run();
|
|
323
|
+
}
|
|
324
|
+
export async function run(args) {
|
|
325
|
+
const parsed = parseArgs(args);
|
|
326
|
+
if (parsed.error !== undefined) {
|
|
327
|
+
process.stderr.write(`owenloop work shift: ${parsed.error}\n`);
|
|
328
|
+
usage();
|
|
329
|
+
return 2;
|
|
330
|
+
}
|
|
331
|
+
if (args.some((arg) => arg === '--mcp' || arg.startsWith('--mcp='))) {
|
|
332
|
+
process.stderr.write('owenloop work shift: unknown option \'--mcp\'\n');
|
|
333
|
+
usage();
|
|
334
|
+
return 2;
|
|
335
|
+
}
|
|
336
|
+
return runShiftRuntime(parsed);
|
|
337
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { HubClient } from '../hub/client.ts';
|
|
2
|
+
import type { ShiftLoop } from '../shift/loop.ts';
|
|
3
|
+
import { type ShiftEvent, type ShiftStatus } from './protocol.ts';
|
|
4
|
+
export interface ShiftDaemonOptions {
|
|
5
|
+
socketPath: string;
|
|
6
|
+
stateDir: string;
|
|
7
|
+
loop: ShiftLoop;
|
|
8
|
+
hub: HubClient;
|
|
9
|
+
now: () => number;
|
|
10
|
+
startedAt: number;
|
|
11
|
+
shiftId?: string;
|
|
12
|
+
err: (line: string) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface ShiftDaemon {
|
|
15
|
+
run(): Promise<number>;
|
|
16
|
+
/** Stop the daemon. `end` performs the final attendance-clearing ping. */
|
|
17
|
+
stop(reason?: 'end' | 'signal' | 'loop'): void;
|
|
18
|
+
status(): ShiftStatus;
|
|
19
|
+
/** Callback passed into createShiftLoop for local dispatch observations. */
|
|
20
|
+
onEvent(event: ShiftEvent): void;
|
|
21
|
+
socketPath: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function createShiftDaemon(opts: ShiftDaemonOptions): ShiftDaemon;
|