owenloop 0.5.8 → 0.5.10
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 +69 -0
- package/README.md +81 -39
- package/bin/owenloop.mjs +16 -1
- package/dist/packages/work/src/agent/loop.d.ts +23 -8
- package/dist/packages/work/src/agent/loop.js +55 -6
- package/dist/packages/work/src/bundle/pull.d.ts +21 -0
- package/dist/packages/work/src/bundle/pull.js +118 -0
- package/dist/packages/work/src/consumed-verifier.js +6 -17
- package/dist/packages/work/src/exec/instructions.d.ts +4 -1
- package/dist/packages/work/src/exec/instructions.js +3 -0
- package/dist/packages/work/src/exec/loop.d.ts +2 -2
- package/dist/packages/work/src/exec/loop.js +273 -46
- package/dist/packages/work/src/exec/receipt.d.ts +7 -7
- package/dist/packages/work/src/exec/receipt.js +6 -6
- package/dist/packages/work/src/harness/claude.js +116 -0
- package/dist/packages/work/src/harness/codex.d.ts +8 -0
- package/dist/packages/work/src/harness/codex.js +27 -1
- package/dist/packages/work/src/harness/contract.d.ts +9 -0
- package/dist/packages/work/src/hub/client.d.ts +19 -4
- package/dist/packages/work/src/hub/client.js +7 -3
- package/dist/packages/work/src/hub/types.d.ts +84 -0
- package/dist/packages/work/src/main.js +1 -0
- package/dist/packages/work/src/roles/agent-run.js +57 -32
- package/dist/packages/work/src/roles/exec.js +27 -8
- package/dist/packages/work/src/roles/settings.js +2 -0
- package/dist/packages/work/src/roles/shift.js +14 -2
- package/dist/packages/work/src/roles/util.d.ts +1 -0
- package/dist/packages/work/src/roles/util.js +10 -0
- package/dist/packages/work/src/settings/hub-roster-cache.d.ts +68 -0
- package/dist/packages/work/src/settings/hub-roster-cache.js +370 -0
- package/dist/packages/work/src/settings/roster.d.ts +84 -0
- package/dist/packages/work/src/settings/roster.js +364 -5
- package/dist/packages/work/src/settings/serving.d.ts +17 -0
- package/dist/packages/work/src/settings/serving.js +79 -0
- package/dist/packages/work/src/settings/settings.d.ts +14 -1
- package/dist/packages/work/src/settings/settings.js +14 -0
- package/dist/packages/work/src/shift/loop.d.ts +108 -5
- package/dist/packages/work/src/shift/loop.js +416 -54
- package/dist/packages/work/src/shift/protocol.d.ts +7 -5
- package/dist/packages/work/src/shift/runtime.d.ts +18 -0
- package/dist/packages/work/src/shift/runtime.js +104 -5
- package/dist/packages/work/src/shift/server.js +2 -0
- package/dist/packages/work/src/shift/spawn.d.ts +17 -2
- package/dist/packages/work/src/shift/spawn.js +16 -13
- package/dist/packages/work/src/shift/state.d.ts +29 -2
- package/dist/packages/work/src/shift/state.js +45 -15
- package/dist/packages/work/src/submit-proof.d.ts +11 -8
- package/dist/packages/work/src/submit-proof.js +11 -8
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +7 -1
- package/dist/packages/work/src/util/modifier-init.d.ts +7 -0
- package/dist/packages/work/src/util/modifier-init.js +73 -0
- package/dist/src/bundle/tar.d.ts +9 -4
- package/dist/src/bundle/tar.js +9 -4
- package/dist/src/capabilities.d.ts +76 -6
- package/dist/src/capabilities.js +49 -6
- package/dist/src/capability-mapping-client.d.ts +29 -0
- package/dist/src/capability-mapping-client.js +160 -0
- package/dist/src/cli.d.ts +16 -3
- package/dist/src/cli.js +1925 -281
- package/dist/src/config-dir.d.ts +1 -1
- package/dist/src/config-dir.js +1 -1
- package/dist/src/crypto/index.d.ts +1 -1
- package/dist/src/crypto/index.js +1 -1
- package/dist/src/crypto/org-root.d.ts +30 -12
- package/dist/src/crypto/org-root.js +162 -14
- package/dist/src/crypto/records.d.ts +2 -0
- package/dist/src/crypto/records.js +2 -0
- package/dist/src/defs.d.ts +38 -2
- package/dist/src/defs.js +593 -86
- package/dist/src/engine.d.ts +103 -25
- package/dist/src/engine.js +331 -79
- package/dist/src/hub.d.ts +77 -0
- package/dist/src/hub.js +162 -0
- package/dist/src/implements.d.ts +56 -0
- package/dist/src/implements.js +790 -0
- package/dist/src/index.d.ts +11 -9
- package/dist/src/index.js +6 -5
- package/dist/src/mcp/serve.d.ts +22 -0
- package/dist/src/mcp/serve.js +330 -41
- package/dist/src/mcp/server.d.ts +10 -7
- package/dist/src/mcp/server.js +53 -8
- package/dist/src/model.d.ts +48 -10
- package/dist/src/model.js +252 -99
- package/dist/src/order-resolver.d.ts +1 -0
- package/dist/src/order-resolver.js +8 -1
- package/dist/src/schemas/index.d.ts +11 -0
- package/dist/src/schemas/order.v1.schema.json +7 -1
- package/dist/src/store/def-source.d.ts +19 -0
- package/dist/src/store/def-source.js +87 -17
- package/dist/src/store/gc-recovery.d.ts +46 -0
- package/dist/src/store/gc-recovery.js +258 -0
- package/dist/src/store/gc.d.ts +94 -0
- package/dist/src/store/gc.js +562 -0
- package/dist/src/store/index.d.ts +3 -1
- package/dist/src/store/index.js +2 -0
- package/dist/src/store/install.d.ts +34 -5
- package/dist/src/store/install.js +73 -11
- package/dist/src/store/pre-commit-verifier.js +42 -2
- package/dist/src/store/snapshot-guard.d.ts +18 -0
- package/dist/src/store/snapshot-guard.js +94 -0
- package/dist/src/store.d.ts +69 -4
- package/dist/src/store.js +254 -16
- package/dist/src/types.d.ts +101 -20
- package/dist/src/util.js +4 -1
- package/docs/authoring.md +235 -10
- package/docs/bundles.md +45 -2
- package/docs/cli.md +437 -55
- package/docs/crypto.md +32 -10
- package/docs/design.md +177 -47
- package/docs/evals/mcp-charter-baseline.json +428 -0
- package/docs/mcp-charter-eval.md +124 -0
- package/docs/routing.md +189 -34
- package/docs/shift-logs.md +38 -9
- package/docs/wire-contracts.md +78 -14
- package/examples/workflows/compile-dev-playbook.yaml +1 -1
- package/examples/workflows/delivery.yaml +31 -14
- package/examples/workflows/ship.yaml +38 -4
- package/package.json +2 -1
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/plugin/.mcp.json +1 -1
- package/plugins/claude-code/plugin/skills/author/SKILL.md +22 -0
- package/plugins/claude-code/plugin/skills/ephemeral/SKILL.md +95 -0
- package/plugins/claude-code/plugin/skills/graduate/SKILL.md +156 -0
- package/plugins/claude-code/plugin/skills/plan/SKILL.md +236 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
- package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +22 -0
- package/plugins/codex/plugins/owenloop/skills/ephemeral/SKILL.md +95 -0
- package/plugins/codex/plugins/owenloop/skills/graduate/SKILL.md +156 -0
- package/plugins/codex/plugins/owenloop/skills/plan/SKILL.md +236 -0
|
@@ -713,6 +713,105 @@ const DEFAULT_START_DEPENDENCIES = {
|
|
|
713
713
|
* process that started the session — which is exactly why `stop` is documented
|
|
714
714
|
* as a no-op on a token this process did not start. */
|
|
715
715
|
const SESSIONS = new Map();
|
|
716
|
+
/** Trim a progress line to something a log can hold. Mirrors the codex adapter's
|
|
717
|
+
* convention deliberately — the two adapters' logs are read side by side, so
|
|
718
|
+
* they truncate the same way. Kept local because this adapter must stay in one
|
|
719
|
+
* allowlisted file. */
|
|
720
|
+
const PROGRESS_TEXT_CAP = 2_000;
|
|
721
|
+
function cap(text) {
|
|
722
|
+
return text.length > PROGRESS_TEXT_CAP ? `${text.slice(0, PROGRESS_TEXT_CAP)}…` : text;
|
|
723
|
+
}
|
|
724
|
+
/** Mark messages produced inside a Task-tool subagent. A flat log cannot
|
|
725
|
+
* otherwise tell a subagent's work from the main agent's. */
|
|
726
|
+
function origin(parentToolUseId) {
|
|
727
|
+
return parentToolUseId === null ? '' : `[subagent ${parentToolUseId}] `;
|
|
728
|
+
}
|
|
729
|
+
/** Flatten a tool_result body to loggable text. Non-text parts are named, not
|
|
730
|
+
* rendered — an image block has no useful string form. */
|
|
731
|
+
function toolResultText(content) {
|
|
732
|
+
if (content === undefined)
|
|
733
|
+
return '(no content)';
|
|
734
|
+
if (typeof content === 'string')
|
|
735
|
+
return content;
|
|
736
|
+
return content.map((part) => (part.type === 'text' ? part.text : `(${part.type})`)).join('\n');
|
|
737
|
+
}
|
|
738
|
+
/** One progress line per content block of an assistant message.
|
|
739
|
+
*
|
|
740
|
+
* TOOL INPUTS ARE NEVER LOGGED. A `tool_use` block's `input` can hold a Bash
|
|
741
|
+
* command line carrying a secret. Only `name` and `id` are emitted — the same
|
|
742
|
+
* two fields the codex adapter reveals for `item/started mcpToolCall`. */
|
|
743
|
+
function emitAssistant(message, onEvent) {
|
|
744
|
+
const from = origin(message.parent_tool_use_id);
|
|
745
|
+
if (message.error !== undefined) {
|
|
746
|
+
onEvent({ kind: 'progress', text: `${from}assistant error: ${message.error}` });
|
|
747
|
+
}
|
|
748
|
+
for (const block of message.message.content) {
|
|
749
|
+
switch (block.type) {
|
|
750
|
+
case 'text':
|
|
751
|
+
onEvent({ kind: 'progress', text: cap(`${from}assistant: ${block.text}`) });
|
|
752
|
+
break;
|
|
753
|
+
case 'thinking':
|
|
754
|
+
onEvent({ kind: 'progress', text: cap(`${from}thinking: ${block.thinking}`) });
|
|
755
|
+
break;
|
|
756
|
+
case 'redacted_thinking':
|
|
757
|
+
onEvent({ kind: 'progress', text: `${from}thinking: (redacted)` });
|
|
758
|
+
break;
|
|
759
|
+
case 'tool_use':
|
|
760
|
+
case 'mcp_tool_use':
|
|
761
|
+
onEvent({ kind: 'progress', text: `${from}tool_use ${block.name} ${block.id}` });
|
|
762
|
+
break;
|
|
763
|
+
default:
|
|
764
|
+
// Server-tool results, container uploads, compaction markers and any
|
|
765
|
+
// block the vendor adds later. Naming the type keeps the line useful
|
|
766
|
+
// without guessing at a shape this version does not define.
|
|
767
|
+
onEvent({ kind: 'progress', text: `${from}${block.type} block` });
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
/** The reply a user would see from one top-level assistant message. This is
|
|
772
|
+
* deliberately separate from `emitAssistant`: that function is operational
|
|
773
|
+
* telemetry, while this value is emitted once at turn end as response evidence. */
|
|
774
|
+
function assistantResponse(message) {
|
|
775
|
+
if (message.parent_tool_use_id !== null)
|
|
776
|
+
return undefined;
|
|
777
|
+
const text = message.message.content
|
|
778
|
+
.filter((block) => block.type === 'text')
|
|
779
|
+
.map((block) => block.text)
|
|
780
|
+
.join('\n');
|
|
781
|
+
return text === '' ? undefined : text;
|
|
782
|
+
}
|
|
783
|
+
/** One progress line per content block of a user message — which on this path
|
|
784
|
+
* means tool results coming back, plus any synthetic user text.
|
|
785
|
+
*
|
|
786
|
+
* Tool RESULTS are logged (capped); tool INPUTS are not. A result is what the
|
|
787
|
+
* tool produced, and the codex adapter already logs the equivalent command
|
|
788
|
+
* output. */
|
|
789
|
+
function emitUser(message, onEvent) {
|
|
790
|
+
const from = origin(message.parent_tool_use_id);
|
|
791
|
+
const content = message.message.content;
|
|
792
|
+
if (typeof content === 'string') {
|
|
793
|
+
onEvent({ kind: 'progress', text: cap(`${from}user: ${content}`) });
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
for (const block of content) {
|
|
797
|
+
switch (block.type) {
|
|
798
|
+
case 'text':
|
|
799
|
+
onEvent({ kind: 'progress', text: cap(`${from}user: ${block.text}`) });
|
|
800
|
+
break;
|
|
801
|
+
case 'tool_result': {
|
|
802
|
+
const flag = block.is_error === true ? ' (error)' : '';
|
|
803
|
+
const body = toolResultText(block.content);
|
|
804
|
+
onEvent({
|
|
805
|
+
kind: 'progress',
|
|
806
|
+
text: cap(`${from}tool_result ${block.tool_use_id}${flag}: ${body}`),
|
|
807
|
+
});
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
default:
|
|
811
|
+
onEvent({ kind: 'progress', text: `${from}${block.type} block` });
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
716
815
|
/**
|
|
717
816
|
* Drive the SDK message stream to TURN END and map it onto `AgentEvent`s.
|
|
718
817
|
*
|
|
@@ -734,6 +833,7 @@ const SESSIONS = new Map();
|
|
|
734
833
|
*/
|
|
735
834
|
export async function consumeTurn(q, onEvent, onInit, expectedSessionId) {
|
|
736
835
|
let sessionId;
|
|
836
|
+
let finalResponse;
|
|
737
837
|
for await (const message of q) {
|
|
738
838
|
if (message.type === 'system' && message.subtype === 'init') {
|
|
739
839
|
if (expectedSessionId !== undefined && message.session_id !== expectedSessionId) {
|
|
@@ -753,6 +853,8 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId) {
|
|
|
753
853
|
onInit?.(sessionId);
|
|
754
854
|
}
|
|
755
855
|
else if (message.type === 'result') {
|
|
856
|
+
if (finalResponse !== undefined)
|
|
857
|
+
onEvent({ kind: 'assistant_response', text: finalResponse });
|
|
756
858
|
if (message.subtype !== 'success') {
|
|
757
859
|
// The contract's channel for "something went wrong that is not a resume
|
|
758
860
|
// failure". Emitted BEFORE turn_ended so a caller reading events in
|
|
@@ -766,8 +868,22 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId) {
|
|
|
766
868
|
onEvent({ kind: 'turn_ended' });
|
|
767
869
|
return { sessionId, sawResult: true };
|
|
768
870
|
}
|
|
871
|
+
else if (message.type === 'assistant') {
|
|
872
|
+
emitAssistant(message, onEvent);
|
|
873
|
+
finalResponse = assistantResponse(message) ?? finalResponse;
|
|
874
|
+
}
|
|
875
|
+
else if (message.type === 'user') {
|
|
876
|
+
emitUser(message, onEvent);
|
|
877
|
+
}
|
|
769
878
|
// `needs_input` is NEVER emitted: this SDK path has no blocking-question
|
|
770
879
|
// channel that maps to it, and the contract has no reply channel by design.
|
|
880
|
+
// `stream_event` is deliberately NOT mapped. The SDK only emits it when
|
|
881
|
+
// `Options.includePartialMessages` is set, and `buildClaudeOptions` never
|
|
882
|
+
// sets it — so the branch would be unreachable today, and if it ever
|
|
883
|
+
// became reachable it would duplicate the text the `assistant` message
|
|
884
|
+
// already carries. Unrecognized types stay silent by design: the vendor
|
|
885
|
+
// adds message kinds between releases, and a mapping that threw on one
|
|
886
|
+
// would turn a routine CLI upgrade into a failed order.
|
|
771
887
|
}
|
|
772
888
|
return { sessionId, sawResult: false };
|
|
773
889
|
}
|
|
@@ -87,6 +87,14 @@ export interface TurnOutcome {
|
|
|
87
87
|
* Returns `undefined` for anything that is not a `turn/completed`.
|
|
88
88
|
*/
|
|
89
89
|
export declare function readTurnCompleted(method: string, params: unknown): TurnOutcome | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Read the final user-visible assistant reply from an app-server notification.
|
|
92
|
+
*
|
|
93
|
+
* Deltas are deliberately not used: they are incomplete transport fragments and
|
|
94
|
+
* can coexist with reasoning, tool output, and other intermediate telemetry.
|
|
95
|
+
* The completed `agentMessage` is the app-server's assembled final answer.
|
|
96
|
+
*/
|
|
97
|
+
export declare function readFinalAssistantResponse(method: string, params: unknown): string | undefined;
|
|
90
98
|
/**
|
|
91
99
|
* Map one server→client notification to an `AgentEvent`.
|
|
92
100
|
*
|
|
@@ -496,6 +496,24 @@ export function readTurnCompleted(method, params) {
|
|
|
496
496
|
: `${message} (${details})`,
|
|
497
497
|
};
|
|
498
498
|
}
|
|
499
|
+
/**
|
|
500
|
+
* Read the final user-visible assistant reply from an app-server notification.
|
|
501
|
+
*
|
|
502
|
+
* Deltas are deliberately not used: they are incomplete transport fragments and
|
|
503
|
+
* can coexist with reasoning, tool output, and other intermediate telemetry.
|
|
504
|
+
* The completed `agentMessage` is the app-server's assembled final answer.
|
|
505
|
+
*/
|
|
506
|
+
export function readFinalAssistantResponse(method, params) {
|
|
507
|
+
if (method !== 'item/completed')
|
|
508
|
+
return undefined;
|
|
509
|
+
const item = asMap(asMap(params)['item']);
|
|
510
|
+
if ((str(item['type']) ?? str(item['itemType'])) !== 'agentMessage')
|
|
511
|
+
return undefined;
|
|
512
|
+
if (str(item['phase']) !== 'final_answer')
|
|
513
|
+
return undefined;
|
|
514
|
+
const text = str(item['text']);
|
|
515
|
+
return text === undefined || text === '' ? undefined : text;
|
|
516
|
+
}
|
|
499
517
|
/**
|
|
500
518
|
* Map one server→client notification to an `AgentEvent`.
|
|
501
519
|
*
|
|
@@ -649,6 +667,9 @@ function createTurnGate(onEvent) {
|
|
|
649
667
|
const event = mapNotification(method, params);
|
|
650
668
|
if (event !== undefined)
|
|
651
669
|
onEvent(event);
|
|
670
|
+
const finalResponse = readFinalAssistantResponse(method, params);
|
|
671
|
+
if (finalResponse !== undefined)
|
|
672
|
+
onEvent({ kind: 'assistant_response', text: finalResponse });
|
|
652
673
|
if (mounted !== undefined) {
|
|
653
674
|
// A silent dead order otherwise: with no `submit` tool the agent can
|
|
654
675
|
// never complete the order, so burning the turn's tokens is pointless.
|
|
@@ -1078,12 +1099,17 @@ export const codexAdapter = {
|
|
|
1078
1099
|
// there. Nothing is spawned and unowned by the time this rejects.
|
|
1079
1100
|
const { client, reportExit } = await openClient(args.cwd, onEvent, gate, args.approvals);
|
|
1080
1101
|
let threadId;
|
|
1102
|
+
let reportedModel;
|
|
1081
1103
|
try {
|
|
1082
1104
|
const res = await client.request('thread/start', startParams, SETUP_TIMEOUT_MS);
|
|
1083
1105
|
const id = str(asMap(res['thread'])['id']);
|
|
1084
1106
|
if (id === undefined)
|
|
1085
1107
|
throw new Error('thread/start returned no thread id');
|
|
1086
1108
|
threadId = id;
|
|
1109
|
+
// The app-server resolves an omitted model to the actual session model in
|
|
1110
|
+
// this response. Surface it with the durable session reference so callers
|
|
1111
|
+
// can attribute measurements without scraping persisted Codex state.
|
|
1112
|
+
reportedModel = str(res['model']);
|
|
1087
1113
|
}
|
|
1088
1114
|
catch (err) {
|
|
1089
1115
|
// No token exists yet, so there is nothing to hand back and nothing to
|
|
@@ -1099,7 +1125,7 @@ export const codexAdapter = {
|
|
|
1099
1125
|
SESSIONS.set(threadId, session);
|
|
1100
1126
|
// BEFORE the turn runs and before resolving: the caller persists the token
|
|
1101
1127
|
// on this event, so a mid-turn crash still leaves a resumable record.
|
|
1102
|
-
onEvent({ kind: 'started', ref });
|
|
1128
|
+
onEvent({ kind: 'started', ref, ...(reportedModel === undefined ? {} : { model: reportedModel }) });
|
|
1103
1129
|
try {
|
|
1104
1130
|
await runTurn(client, gate, buildTurnStartParams(threadId, args.brief, args.effort ?? args.permissions.effort));
|
|
1105
1131
|
}
|
|
@@ -56,12 +56,21 @@ export interface HarnessSessionRef {
|
|
|
56
56
|
export type AgentEvent = {
|
|
57
57
|
kind: 'started';
|
|
58
58
|
ref: HarnessSessionRef;
|
|
59
|
+
/** Provider-selected model when the session-start response exposes it. */
|
|
60
|
+
model?: string;
|
|
59
61
|
}
|
|
60
62
|
/** Optional log line. Adapters may emit none; nothing may depend on it. */
|
|
61
63
|
| {
|
|
62
64
|
kind: 'progress';
|
|
63
65
|
text: string;
|
|
64
66
|
}
|
|
67
|
+
/** The completed top-level assistant reply, assembled by the owning adapter.
|
|
68
|
+
* Unlike `progress`, this is suitable for a caller that explicitly needs the
|
|
69
|
+
* final response rather than transport, tool, reasoning, or stderr telemetry. */
|
|
70
|
+
| {
|
|
71
|
+
kind: 'assistant_response';
|
|
72
|
+
text: string;
|
|
73
|
+
}
|
|
65
74
|
/** The harness surfaced a blocking question. Phase 1 defines the EVENT only —
|
|
66
75
|
* this contract has no reply channel, and adding one is Phase 3/4's call. */
|
|
67
76
|
| {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnswerApprovalRequest, AnswerApprovalResponse, AskRequest, AskResponse, ListPendingApprovalsResponse, RequestApprovalRequest, RequestApprovalResponse, GetOrderRequest, GetOrderResponse, HeartbeatRequest, HeartbeatResponse, PresencePingRequest, PresencePingResponse, ReleaseRequest, ReleaseResponse, RejectRequest, RejectResponse, ReportResolutionRequest, ReportResolutionResponse, SubmitRequest, SubmitResponse, WakeResponse, WhatsNextRequest, WhatsNextResponse, WhoamiResponse } from './types.ts';
|
|
1
|
+
import type { AnswerApprovalRequest, AnswerApprovalResponse, AskRequest, AskResponse, GetRostersResponse, ListHarnessModelsResponse, ListPendingApprovalsResponse, RequestApprovalRequest, RequestApprovalResponse, GetOrderRequest, GetOrderResponse, HeartbeatRequest, HeartbeatResponse, PresencePingRequest, PresencePingResponse, ReleaseRequest, ReleaseResponse, RejectRequest, RejectResponse, RetryArtifactRequest, RetryArtifactResponse, ReportResolutionRequest, ReportResolutionResponse, SubmitRequest, SubmitResponse, WakeResponse, WhatsNextRequest, WhatsNextResponse, WhoamiResponse } from './types.ts';
|
|
2
2
|
export interface HubClientOptions {
|
|
3
3
|
/** Hub origin, e.g. `https://hub.owenloop.dev` (no trailing slash needed). */
|
|
4
4
|
origin: string;
|
|
@@ -8,7 +8,7 @@ export interface HubClientOptions {
|
|
|
8
8
|
fetchImpl?: typeof fetch;
|
|
9
9
|
}
|
|
10
10
|
export interface HubClient {
|
|
11
|
-
whatsNext(req
|
|
11
|
+
whatsNext(req: WhatsNextRequest): Promise<WhatsNextResponse>;
|
|
12
12
|
getOrder(req: GetOrderRequest): Promise<GetOrderResponse>;
|
|
13
13
|
heartbeat(req: HeartbeatRequest): Promise<HeartbeatResponse>;
|
|
14
14
|
release(req: ReleaseRequest): Promise<ReleaseResponse>;
|
|
@@ -18,9 +18,20 @@ export interface HubClient {
|
|
|
18
18
|
* ESCALATION: the worker stops and asks a human about an artifact it OWES.
|
|
19
19
|
* Distinct from `reject`, which is a verdict on somebody else's delivered
|
|
20
20
|
* work. Holds the artifact (no counter moves) until a human answers with
|
|
21
|
-
* `owenloop retry <workflow> <path> --text "<answer>"
|
|
21
|
+
* `owenloop retry <workflow> <path> --text "<answer>"`, or with
|
|
22
|
+
* `retryArtifact` on this client.
|
|
22
23
|
*/
|
|
23
24
|
ask(req: AskRequest): Promise<AskResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* The HUMAN half of the escalation channel and the answer to `ask` above:
|
|
27
|
+
* re-arm a stalled or rejected artifact to `owed`, resetting its reject
|
|
28
|
+
* counters. `text` rides to the next producer on the artifact's reason
|
|
29
|
+
* thread. Omit `text` for a bare stall-clear — the engine supplies its own
|
|
30
|
+
* default, so do NOT default it here. Human-only by hub RBAC; an agent
|
|
31
|
+
* token is refused. Optional on this interface for the same reason
|
|
32
|
+
* `getRosters` is: it was added after the existing HubClient fakes.
|
|
33
|
+
*/
|
|
34
|
+
retryArtifact?(req: RetryArtifactRequest): Promise<RetryArtifactResponse>;
|
|
24
35
|
/**
|
|
25
36
|
* TOOL APPROVAL — raise AND poll, one idempotent call. The worker is mid-flight
|
|
26
37
|
* and needs yes/no on ONE tool call; unlike `ask`, the session stays alive, the
|
|
@@ -39,7 +50,11 @@ export interface HubClient {
|
|
|
39
50
|
* re-dispatch no-ops rather than overwriting the first (pre-spend) record.
|
|
40
51
|
*/
|
|
41
52
|
reportResolution(req: ReportResolutionRequest): Promise<ReportResolutionResponse>;
|
|
42
|
-
whoami(): Promise<WhoamiResponse>;
|
|
53
|
+
whoami(signal?: AbortSignal): Promise<WhoamiResponse>;
|
|
54
|
+
/** Read the org's roster cascade using this caller's scoped identity. */
|
|
55
|
+
getRosters?(signal?: AbortSignal): Promise<GetRostersResponse>;
|
|
56
|
+
/** Read the hub's known harness/model registry. */
|
|
57
|
+
listHarnessModels?(): Promise<ListHarnessModelsResponse>;
|
|
43
58
|
/** B5 cheap wake pre-check; `cursor` rides the query string only when set. */
|
|
44
59
|
wake(cursor?: number): Promise<WakeResponse>;
|
|
45
60
|
/** B4 Shift presence register/refresh. */
|
|
@@ -67,27 +67,31 @@ export function createHubClient(opts) {
|
|
|
67
67
|
});
|
|
68
68
|
return parse(res);
|
|
69
69
|
}
|
|
70
|
-
async function get(verb, query) {
|
|
70
|
+
async function get(verb, query, signal) {
|
|
71
71
|
const url = query !== undefined && query !== '' ? `${base}/api/${verb}?${query}` : `${base}/api/${verb}`;
|
|
72
72
|
const res = await fetchImpl(url, {
|
|
73
73
|
method: 'GET',
|
|
74
74
|
headers: await authHeaders(),
|
|
75
|
+
...(signal === undefined ? {} : { signal }),
|
|
75
76
|
});
|
|
76
77
|
return parse(res);
|
|
77
78
|
}
|
|
78
79
|
return {
|
|
79
|
-
whatsNext: (req
|
|
80
|
+
whatsNext: (req) => post('whats_next', req),
|
|
80
81
|
getOrder: (req) => post('get_order', req),
|
|
81
82
|
heartbeat: (req) => post('heartbeat', req),
|
|
82
83
|
release: (req) => post('release', req),
|
|
83
84
|
submit: (req) => post('submit', req),
|
|
84
85
|
reject: (req) => post('reject', req),
|
|
85
86
|
ask: (req) => post('ask', req),
|
|
87
|
+
retryArtifact: (req) => post('retry_artifact', req),
|
|
86
88
|
requestApproval: (req) => post('request_approval', req),
|
|
87
89
|
answerApproval: (req) => post('answer_approval', req),
|
|
88
90
|
listPendingApprovals: () => post('list_pending_approvals', {}),
|
|
89
91
|
reportResolution: (req) => post('report_resolution', req),
|
|
90
|
-
whoami: () => get('whoami'),
|
|
92
|
+
whoami: (signal) => get('whoami', undefined, signal),
|
|
93
|
+
getRosters: (signal) => get('rosters', undefined, signal),
|
|
94
|
+
listHarnessModels: () => get('harness_models'),
|
|
91
95
|
// Cursor is an opaque non-negative integer; omit it entirely to bootstrap
|
|
92
96
|
// (the hub treats missing/invalid as a `changed: true` first sweep).
|
|
93
97
|
wake: (cursor) => get('wake', typeof cursor === 'number' ? `cursor=${encodeURIComponent(String(cursor))}` : undefined),
|
|
@@ -11,6 +11,12 @@ export interface WhatsNextRequest {
|
|
|
11
11
|
workflow?: string;
|
|
12
12
|
/** Server-side filter for which serve crews this caller will accept. */
|
|
13
13
|
serve_crews?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Capability keys in this shift's effective merged rosters. Keys are raw:
|
|
16
|
+
* bare names and exact compounds may be mixed; the hub applies bare-name
|
|
17
|
+
* matching. An empty array legitimately means the shift serves nothing.
|
|
18
|
+
*/
|
|
19
|
+
serve_capabilities: string[];
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* One work order from a per-workflow `whats_next` sweep. `run` is the order
|
|
@@ -26,6 +32,14 @@ export interface WorkOrder {
|
|
|
26
32
|
key?: string;
|
|
27
33
|
index?: number;
|
|
28
34
|
defDigest?: string;
|
|
35
|
+
/** The composed capabilities the hub offered this order under. */
|
|
36
|
+
capabilities?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* THE CREWS THE HUB MATCHED for this order's capabilities, in match order.
|
|
39
|
+
* Hub → worker; this is not `serve_crews`, which travels worker → hub to
|
|
40
|
+
* narrow the orders a shift wants.
|
|
41
|
+
*/
|
|
42
|
+
crews?: string[];
|
|
29
43
|
/** Authoritative worker lane on modern whats_next responses. */
|
|
30
44
|
worker?: string;
|
|
31
45
|
consumedFingerprint?: Record<string, number>;
|
|
@@ -112,6 +126,12 @@ export interface WakeResponse extends HubResponse {
|
|
|
112
126
|
export interface PresencePingRequest {
|
|
113
127
|
name: string;
|
|
114
128
|
serve_crews?: string[];
|
|
129
|
+
/**
|
|
130
|
+
* Capability keys in this shift's effective merged rosters. Keys are raw:
|
|
131
|
+
* bare names and exact compounds may be mixed; the hub applies bare-name
|
|
132
|
+
* matching. An empty array legitimately means the shift serves nothing.
|
|
133
|
+
*/
|
|
134
|
+
serve_capabilities: string[];
|
|
115
135
|
shift_id?: string;
|
|
116
136
|
started_at?: number;
|
|
117
137
|
/** Epoch-millisecond timestamp of the last accepted local shift attendance. */
|
|
@@ -192,6 +212,24 @@ export interface OrderPacket {
|
|
|
192
212
|
* guessing.
|
|
193
213
|
*/
|
|
194
214
|
capabilities?: string[];
|
|
215
|
+
/**
|
|
216
|
+
* THE CREWS THE HUB MATCHED for this order's capabilities, in match order.
|
|
217
|
+
*
|
|
218
|
+
* Hub → worker. This is the hub's answer to "whose roster decides the model
|
|
219
|
+
* for this order", computed at offer time from `capability_routes`. The
|
|
220
|
+
* worker resolves each named crew's merged roster IN THIS ORDER and takes the
|
|
221
|
+
* first crew that carries a row for one of `capabilities`.
|
|
222
|
+
*
|
|
223
|
+
* NOT `serve_crews`. `serve_crews` travels the other way — worker → hub,
|
|
224
|
+
* on `whats_next`/`presence_ping` — and narrows WHICH ORDERS THIS SHIFT
|
|
225
|
+
* WANTS. This field narrows WHICH ROSTER DECIDES an order the shift already
|
|
226
|
+
* has.
|
|
227
|
+
*
|
|
228
|
+
* Optional on the wire because a hub that predates the stamp sends nothing.
|
|
229
|
+
* It is NOT optional in effect: a worker built from this commit REFUSES every
|
|
230
|
+
* capability-bearing order that arrives without it. There is no fallback.
|
|
231
|
+
*/
|
|
232
|
+
crews?: string[];
|
|
195
233
|
/** The run's routing modifier (`deep`), as the caller asked for at start_run. */
|
|
196
234
|
modifier?: string;
|
|
197
235
|
/**
|
|
@@ -261,6 +299,7 @@ export interface ReasonEntry {
|
|
|
261
299
|
by: string;
|
|
262
300
|
text: string;
|
|
263
301
|
fromVersion?: number;
|
|
302
|
+
requested?: string;
|
|
264
303
|
}
|
|
265
304
|
export interface GetOrderResponse extends HubResponse {
|
|
266
305
|
workflow: string;
|
|
@@ -384,6 +423,22 @@ export interface RejectResponse extends HubResponse {
|
|
|
384
423
|
ok: boolean;
|
|
385
424
|
closed?: boolean;
|
|
386
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* The HUMAN stall-clearing lever and answer path for ask. Re-arms a stalled or
|
|
428
|
+
* rejected artifact to owed, resetting its reject counters. text rides to the
|
|
429
|
+
* next producer on the artifact's reason thread; omit it for a bare
|
|
430
|
+
* stall-clear so the engine supplies its own default.
|
|
431
|
+
*/
|
|
432
|
+
export interface RetryArtifactRequest {
|
|
433
|
+
workflow: string;
|
|
434
|
+
path: string;
|
|
435
|
+
text?: string;
|
|
436
|
+
}
|
|
437
|
+
/** The retry-artifact verb's flattened response envelope. */
|
|
438
|
+
export interface RetryArtifactResponse extends HubResponse {
|
|
439
|
+
ok: boolean;
|
|
440
|
+
closed?: boolean;
|
|
441
|
+
}
|
|
387
442
|
/**
|
|
388
443
|
* ESCALATION: the claiming worker cannot honestly build what it owes and stops
|
|
389
444
|
* to ask a person. `path` is one of the order's OWED paths — unlike `reject`,
|
|
@@ -510,6 +565,35 @@ export interface WhoamiResponse extends HubResponse {
|
|
|
510
565
|
authMethod: 'token' | 'oauth' | 'session' | 'debug';
|
|
511
566
|
email?: string;
|
|
512
567
|
}
|
|
568
|
+
/** One model choice in an org-owned roster row. */
|
|
569
|
+
export interface RosterCandidateWire {
|
|
570
|
+
harness: string;
|
|
571
|
+
model: string;
|
|
572
|
+
effort: string;
|
|
573
|
+
}
|
|
574
|
+
/** The agent-readable org roster cascade. */
|
|
575
|
+
export interface GetRostersResponse extends HubResponse {
|
|
576
|
+
global: Record<string, RosterCandidateWire[]>;
|
|
577
|
+
crews: Array<{
|
|
578
|
+
crewId: string;
|
|
579
|
+
crewName: string | null;
|
|
580
|
+
roster: Record<string, RosterCandidateWire[]>;
|
|
581
|
+
}>;
|
|
582
|
+
}
|
|
583
|
+
/** The hub's current harness/model registry, for roster administration. */
|
|
584
|
+
export interface ListHarnessModelsResponse extends HubResponse {
|
|
585
|
+
harnesses: Array<{
|
|
586
|
+
harness: string;
|
|
587
|
+
displayName: string;
|
|
588
|
+
}>;
|
|
589
|
+
models: Array<{
|
|
590
|
+
harness: string;
|
|
591
|
+
model: string;
|
|
592
|
+
efforts: string[];
|
|
593
|
+
updatedAt: number;
|
|
594
|
+
updatedBy: string;
|
|
595
|
+
}>;
|
|
596
|
+
}
|
|
513
597
|
/**
|
|
514
598
|
* Thrown for any non-2xx hub response. `code` is the hub's `error` slug
|
|
515
599
|
* (e.g. `bad_request`) when the body parsed as the hub's `{ error, message }`
|
|
@@ -27,6 +27,7 @@ const ROLES = {
|
|
|
27
27
|
join: () => import("./roles/join.js"),
|
|
28
28
|
sessions: () => import("./roles/sessions.js"),
|
|
29
29
|
approvals: () => import("./roles/approvals.js"),
|
|
30
|
+
util: () => import("./roles/util.js"),
|
|
30
31
|
};
|
|
31
32
|
export async function mainAsync(argv) {
|
|
32
33
|
const [first, ...rest] = argv;
|
|
@@ -85,14 +85,16 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
85
85
|
import "../harnesses.js";
|
|
86
86
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
87
87
|
import { hostname } from 'node:os';
|
|
88
|
+
import { join } from 'node:path';
|
|
88
89
|
import { resolveCacheDir } from "../bundle/cache.js";
|
|
89
|
-
import { createAgentRunLoop } from "../agent/loop.js";
|
|
90
|
+
import { createAgentRunLoop, } from "../agent/loop.js";
|
|
90
91
|
import { createDefaultStoreInstructionResolver } from "../exec/instructions.js";
|
|
92
|
+
import { createHubBundleRecoveryHandler } from "../bundle/pull.js";
|
|
91
93
|
import { createConsumedVerifier } from "../consumed-verifier.js";
|
|
92
94
|
import { createHubClient } from "../hub/client.js";
|
|
93
95
|
import { resolveBearer } from "../credentials/resolve.js";
|
|
94
96
|
import { loadSettings } from "../settings/settings.js";
|
|
95
|
-
import {
|
|
97
|
+
import { effectiveRosterLayers, mergeRosterLayers } from "../settings/roster.js";
|
|
96
98
|
import { adapterFor, defaultHarnessId, registeredHarnessIds } from "../harness/registry.js";
|
|
97
99
|
import { parseHarnessCarrier } from "../bundle/fetch.js";
|
|
98
100
|
import { normalizeStepPermissions, validateHarnessOptions } from "../harness/permissions.js";
|
|
@@ -198,6 +200,8 @@ export function exitCodeFor(outcome) {
|
|
|
198
200
|
case 'no-template':
|
|
199
201
|
case 'no-harness':
|
|
200
202
|
case 'incompatible-harness-policy':
|
|
203
|
+
case 'unstamped-order':
|
|
204
|
+
case 'unresolvable-crew':
|
|
201
205
|
case 'unresolvable-capability':
|
|
202
206
|
case 'unverified-consumed':
|
|
203
207
|
case 'session-store-failed':
|
|
@@ -264,25 +268,6 @@ export async function run(args, deps = {}) {
|
|
|
264
268
|
err(`owenloop work agent-run: ${errMsg(e)}`);
|
|
265
269
|
return 1;
|
|
266
270
|
}
|
|
267
|
-
// Phase 1 interim rule: choose crew rosters in the order the shift was
|
|
268
|
-
// started with. Phase 2 replaces this handoff with crews stamped by the hub
|
|
269
|
-
// on each offer. A hand-run worker and a shift started with --all see only
|
|
270
|
-
// the machine-global settings layer.
|
|
271
|
-
const servedCrews = (env['OWENLOOP_SERVE_CREWS'] ?? '')
|
|
272
|
-
.split(',')
|
|
273
|
-
.map((crew) => crew.trim())
|
|
274
|
-
.filter((crew) => crew !== '');
|
|
275
|
-
let rosters;
|
|
276
|
-
try {
|
|
277
|
-
rosters =
|
|
278
|
-
servedCrews.length > 0
|
|
279
|
-
? servedCrews.map((crew) => mergeRosterLayers(machineRosterLayers(env, crew)))
|
|
280
|
-
: [mergeRosterLayers(machineRosterLayers(env, undefined))];
|
|
281
|
-
}
|
|
282
|
-
catch (e) {
|
|
283
|
-
err(`owenloop work agent-run: ${errMsg(e)}`);
|
|
284
|
-
return 1;
|
|
285
|
-
}
|
|
286
271
|
const origin = parsed.origin ?? settings.hubOrigin;
|
|
287
272
|
if (origin === undefined || origin.trim() === '') {
|
|
288
273
|
err('owenloop work agent-run: no hub origin — pass --origin <url> or set hubOrigin in settings');
|
|
@@ -294,15 +279,6 @@ export async function run(args, deps = {}) {
|
|
|
294
279
|
});
|
|
295
280
|
const instructionCwd = deps.cwd ?? process.cwd();
|
|
296
281
|
let instructions = deps.instructions;
|
|
297
|
-
if (instructions === undefined) {
|
|
298
|
-
try {
|
|
299
|
-
instructions = createDefaultStoreInstructionResolver({ cwd: instructionCwd, env, consumedVerifier });
|
|
300
|
-
}
|
|
301
|
-
catch (e) {
|
|
302
|
-
err(`owenloop work agent-run: instruction store unavailable: ${errMsg(e)}`);
|
|
303
|
-
return 1;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
282
|
let cacheDir;
|
|
307
283
|
try {
|
|
308
284
|
cacheDir = resolveCacheDir(env, settings.cacheDir);
|
|
@@ -337,14 +313,63 @@ export async function run(args, deps = {}) {
|
|
|
337
313
|
'Authenticate the account instead: `owenloop login --hub <origin> --as agent:<account>`.');
|
|
338
314
|
}
|
|
339
315
|
const account = workerEnv['OWENLOOP_ACCOUNT'] ?? 'default';
|
|
316
|
+
// The crews the HUB STAMPED on the order decide which rosters apply, so this
|
|
317
|
+
// runs per order inside the loop — the stamp does not exist at process start.
|
|
318
|
+
const resolveCrewRosters = (crews) => {
|
|
319
|
+
const rosters = [];
|
|
320
|
+
for (const crew of crews) {
|
|
321
|
+
try {
|
|
322
|
+
rosters.push(mergeRosterLayers(effectiveRosterLayers(env, crew, { origin, account })));
|
|
323
|
+
}
|
|
324
|
+
catch (e) {
|
|
325
|
+
return { ok: false, crew, detail: errMsg(e) };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return { ok: true, rosters };
|
|
329
|
+
};
|
|
340
330
|
let hub = deps.hub;
|
|
331
|
+
let token;
|
|
332
|
+
// An injected HubClient is already the embedding boundary's authenticated
|
|
333
|
+
// transport. Keep that seam credential-free even when it asks us to build
|
|
334
|
+
// the ordinary local resolver; authenticated recovery is attached only when
|
|
335
|
+
// this role owns the production hub client and its scoped bearer.
|
|
341
336
|
if (hub === undefined) {
|
|
342
337
|
const bearer = await resolveBearer({ origin, account, env: workerEnv });
|
|
343
338
|
if (!bearer.ok) {
|
|
344
339
|
err(`owenloop work agent-run: ${bearer.message}`);
|
|
345
340
|
return bearer.code;
|
|
346
341
|
}
|
|
347
|
-
|
|
342
|
+
token = bearer.token;
|
|
343
|
+
}
|
|
344
|
+
if (instructions === undefined) {
|
|
345
|
+
try {
|
|
346
|
+
const home = [workerEnv.HOME, workerEnv.USERPROFILE].find((value) => value !== undefined && value.trim() !== '');
|
|
347
|
+
if (home === undefined)
|
|
348
|
+
throw new Error('cannot locate the global workflow store: set HOME or USERPROFILE');
|
|
349
|
+
instructions = createDefaultStoreInstructionResolver({
|
|
350
|
+
cwd: instructionCwd,
|
|
351
|
+
env: workerEnv,
|
|
352
|
+
consumedVerifier,
|
|
353
|
+
...(token === undefined
|
|
354
|
+
? {}
|
|
355
|
+
: {
|
|
356
|
+
onMissing: createHubBundleRecoveryHandler({
|
|
357
|
+
origin,
|
|
358
|
+
token,
|
|
359
|
+
home,
|
|
360
|
+
projectRoot: join(instructionCwd, 'workflows'),
|
|
361
|
+
env: workerEnv,
|
|
362
|
+
warn: (line) => err(`owenloop work agent-run: ${line}`),
|
|
363
|
+
}),
|
|
364
|
+
}),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
err(`owenloop work agent-run: instruction store unavailable: ${errMsg(e)}`);
|
|
369
|
+
return 1;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (hub === undefined) {
|
|
348
373
|
hub = createHubClient({ origin, getToken: async () => token });
|
|
349
374
|
}
|
|
350
375
|
const client = hub;
|
|
@@ -507,7 +532,7 @@ export async function run(args, deps = {}) {
|
|
|
507
532
|
allowedWorkdirRoots: resolveAllowedWorkdirRoots(env, settings.allowedWorkdirRoots, process.cwd()),
|
|
508
533
|
loadStep,
|
|
509
534
|
resolveAdapter,
|
|
510
|
-
|
|
535
|
+
resolveCrewRosters,
|
|
511
536
|
// Phase-1 availability means registry membership. A real binary or
|
|
512
537
|
// credential probe requires new HarnessAdapter contract surface.
|
|
513
538
|
harnessAvailable: (id) => adapterFor(id) !== undefined,
|