@astrosheep/keiyaku 0.1.87 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -22
- package/build/.tsbuildinfo +1 -1
- package/build/agents/effective-policy.js +32 -0
- package/build/agents/harness/event-channel.js +178 -0
- package/build/agents/harness/execution-handle.js +117 -0
- package/build/agents/harness/index.js +622 -0
- package/build/agents/harness/pump.js +152 -0
- package/build/agents/harness/runtime.js +68 -0
- package/build/agents/index.js +104 -213
- package/build/agents/opencode-sdk.js +12 -18
- package/build/agents/providers/claude-agent-sdk.js +529 -0
- package/build/agents/providers/codex-app-server.js +656 -0
- package/build/agents/providers/codex-sdk.js +193 -0
- package/build/agents/providers/opencode-sdk.js +257 -0
- package/build/agents/providers/pi.js +345 -0
- package/build/agents/selector.js +15 -6
- package/build/agents/session.js +29 -0
- package/build/agents/types.js +5 -11
- package/build/cli/commands/akuma.js +79 -0
- package/build/cli/completion.js +71 -0
- package/build/cli/draft-artifact.js +50 -0
- package/build/cli/flags.js +96 -0
- package/build/cli/help.js +108 -0
- package/build/cli/index.js +204 -912
- package/build/cli/parse.js +280 -0
- package/build/cli/render/arc.js +63 -0
- package/build/{responses/tool-errors.js → cli/render/errors.js} +15 -16
- package/build/cli/render/format.js +199 -0
- package/build/cli/render/misc.js +40 -0
- package/build/cli/render/petition.js +32 -0
- package/build/{responses → cli/render}/response-style.js +4 -4
- package/build/cli/render/shared.js +122 -0
- package/build/cli/render/status.js +69 -0
- package/build/cli/render/summon.js +17 -0
- package/build/cli/render/tell.js +11 -0
- package/build/cli/skills-install.js +237 -0
- package/build/cli/subagent-guard.js +6 -3
- package/build/config/akuma-loader.js +268 -0
- package/build/config/env-keys.js +0 -10
- package/build/config/{schema.js → env.js} +117 -23
- package/build/config/settings.js +137 -260
- package/build/core/amend.js +120 -0
- package/build/core/arc.js +225 -0
- package/build/core/atomic-publish.js +64 -0
- package/build/core/bind.js +281 -0
- package/build/core/claim.js +360 -0
- package/build/core/command-io.js +174 -0
- package/build/core/context.js +108 -0
- package/build/core/contract.js +14 -0
- package/build/core/draft.js +82 -0
- package/build/core/entry.js +203 -0
- package/build/core/forfeit.js +60 -0
- package/build/core/hints.js +108 -0
- package/build/core/ids.js +70 -0
- package/build/core/ledger.js +117 -0
- package/build/core/log.js +24 -0
- package/build/{protocol → core}/markdown/parser.js +68 -0
- package/build/{protocol → core}/markdown/sections.js +2 -28
- package/build/core/markdown/titles.js +9 -0
- package/build/{tools/petition/claim-gates.js → core/petition-claim-gates.js} +43 -29
- package/build/core/petition-claim.js +116 -0
- package/build/core/petition-forfeit.js +39 -0
- package/build/{tools/round/head-guard.js → core/petition-head-guard.js} +2 -2
- package/build/core/petition-run.js +81 -0
- package/build/core/petition.js +96 -0
- package/build/core/places.js +82 -0
- package/build/core/projection-core.js +541 -0
- package/build/core/projection-mint.js +79 -0
- package/build/core/projection-status.js +179 -0
- package/build/core/projection-wake.js +252 -0
- package/build/core/queue.js +73 -0
- package/build/core/ref-log.js +94 -0
- package/build/core/registry.js +96 -0
- package/build/core/render.js +326 -0
- package/build/core/renew.js +195 -0
- package/build/core/scope.js +163 -0
- package/build/core/seal.js +195 -0
- package/build/core/status.js +476 -0
- package/build/{tools/summon/persist.js → core/summon-persist.js} +10 -9
- package/build/core/summon.js +377 -0
- package/build/{protocol/response-history.js → core/transcripts.js} +83 -39
- package/build/core/verdict.js +96 -0
- package/build/core/worktree-path.js +134 -0
- package/build/flow-error.js +80 -4
- package/build/generated/version.js +1 -1
- package/build/git/branches.js +8 -9
- package/build/git/core.js +1 -1
- package/build/git/diff/pathspec.js +2 -3
- package/build/git/diff/preview.js +7 -2
- package/build/git/diff/read.js +4 -3
- package/build/git/staging.js +1 -1
- package/build/index.js +12 -6
- package/build/keiyaku.js +17 -13
- package/build/telemetry/debug-log.js +1 -1
- package/package.json +16 -9
- package/skills/keiyaku/SKILL.md +16 -13
- package/build/agents/claude-agent-sdk-exec.js +0 -352
- package/build/agents/codex-cli-exec.js +0 -237
- package/build/agents/codex-sdk-exec.js +0 -291
- package/build/agents/gemini-cli-core-exec.js +0 -499
- package/build/agents/opencode-exec.js +0 -297
- package/build/agents/process-runner.js +0 -239
- package/build/agents/progress-reporter.js +0 -137
- package/build/agents/round-runner.js +0 -53
- package/build/config/apply-argument-descriptions.js +0 -16
- package/build/config/architect-hints.js +0 -374
- package/build/config/base-rules.js +0 -23
- package/build/config/config.js +0 -50
- package/build/config/dotenv.js +0 -61
- package/build/config/keiyaku-home.js +0 -9
- package/build/config/path-utils.js +0 -11
- package/build/config/render-template.js +0 -8
- package/build/git/diff/filter.js +0 -67
- package/build/git/keiyaku-state.js +0 -58
- package/build/git/snapshot.js +0 -41
- package/build/git/stash.js +0 -62
- package/build/protocol/bind-draft.js +0 -195
- package/build/protocol/draft-artifacts.js +0 -99
- package/build/protocol/file-guards.js +0 -24
- package/build/protocol/keiyaku-draft.js +0 -168
- package/build/protocol/ledger.js +0 -374
- package/build/protocol/markdown/index.js +0 -14
- package/build/protocol/markdown/normalization.js +0 -71
- package/build/protocol/markdown/render.js +0 -68
- package/build/protocol/oath.js +0 -36
- package/build/protocol/render-keiyaku.js +0 -37
- package/build/protocol/review.js +0 -1
- package/build/protocol/status-previews.js +0 -68
- package/build/responses/responses.js +0 -515
- package/build/tools/amend/index.js +0 -18
- package/build/tools/amend/run.js +0 -44
- package/build/tools/bind/index.js +0 -44
- package/build/tools/bind/run.js +0 -237
- package/build/tools/contracts.js +0 -1
- package/build/tools/create-handler.js +0 -31
- package/build/tools/help.js +0 -9
- package/build/tools/petition/claim.js +0 -174
- package/build/tools/petition/forfeit.js +0 -100
- package/build/tools/petition/index.js +0 -83
- package/build/tools/petition/run.js +0 -66
- package/build/tools/round/guidance.js +0 -7
- package/build/tools/round/prompt.js +0 -70
- package/build/tools/round/report.js +0 -153
- package/build/tools/round/worktree.js +0 -55
- package/build/tools/round-close/index.js +0 -19
- package/build/tools/round-close/run.js +0 -98
- package/build/tools/round-open/index.js +0 -20
- package/build/tools/round-open/run.js +0 -77
- package/build/tools/schema.js +0 -69
- package/build/tools/status/index.js +0 -16
- package/build/tools/status/read.js +0 -155
- package/build/tools/summon/index.js +0 -27
- package/build/tools/summon/run.js +0 -80
- /package/build/{config/toml.js → agents/harness/events.js} +0 -0
- /package/build/{git/diff/contracts.js → cli/render/types.js} +0 -0
- /package/build/{protocol/bind-input.js → cli/types.js} +0 -0
- /package/build/{protocol → core}/markdown/lex.js +0 -0
- /package/build/{protocol → core}/markdown/types.js +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FlowError } from "../flow-error.js";
|
|
2
|
+
function deepOverlay(base, extra) {
|
|
3
|
+
const next = {};
|
|
4
|
+
for (const key of Object.keys(base))
|
|
5
|
+
Object.defineProperty(next, key, { value: base[key], enumerable: true, configurable: true, writable: true });
|
|
6
|
+
for (const key of Object.keys(extra)) {
|
|
7
|
+
const value = extra[key];
|
|
8
|
+
const prior = Object.prototype.hasOwnProperty.call(next, key) ? next[key] : undefined;
|
|
9
|
+
const merged = value && typeof value === "object" && !Array.isArray(value)
|
|
10
|
+
? prior && typeof prior === "object" && !Array.isArray(prior)
|
|
11
|
+
? deepOverlay(prior, value)
|
|
12
|
+
: deepOverlay({}, value)
|
|
13
|
+
: value;
|
|
14
|
+
Object.defineProperty(next, key, { value: merged, enumerable: true, configurable: true, writable: true });
|
|
15
|
+
}
|
|
16
|
+
return next;
|
|
17
|
+
}
|
|
18
|
+
export function resolveEffectiveCodexSdkProfile(profile, cwd, overrides = {}) {
|
|
19
|
+
if (profile.webSearchPolicy === "cached" || profile.webSearchPolicy === "live")
|
|
20
|
+
throw new FlowError("UNSUPPORTED_POLICY", `Codex SDK unified webSearchPolicy '${profile.webSearchPolicy}' is unsupported because native web-search capability was not proven with either networkAccessEnabled=false or networkAccessEnabled=true; this restriction can be lifted only by future real native tool-provisioning evidence.`);
|
|
21
|
+
const unified = {
|
|
22
|
+
sandboxMode: profile.accessPolicy === "read" ? "read-only" : "workspace-write",
|
|
23
|
+
networkAccessEnabled: profile.networkPolicy === "enabled",
|
|
24
|
+
webSearchMode: profile.webSearchPolicy ?? "disabled",
|
|
25
|
+
...(profile.model ? { model: profile.model } : {}),
|
|
26
|
+
...(profile.effort ? { modelReasoningEffort: profile.effort === "max" ? "xhigh" : profile.effort } : {}),
|
|
27
|
+
};
|
|
28
|
+
const native = deepOverlay(unified, profile.threadOptions ?? {});
|
|
29
|
+
const threadOptions = { ...native, ...(overrides.model ? { model: overrides.model } : {}), ...(overrides.effort ? { modelReasoningEffort: overrides.effort === "max" ? "xhigh" : overrides.effort } : {}), workingDirectory: cwd, skipGitRepoCheck: true };
|
|
30
|
+
const policy = { ...(threadOptions.sandboxMode === "read-only" ? { accessPolicy: "read" } : threadOptions.sandboxMode === "workspace-write" || threadOptions.sandboxMode === "danger-full-access" ? { accessPolicy: "write" } : {}), ...(typeof threadOptions.networkAccessEnabled === "boolean" ? { networkPolicy: threadOptions.networkAccessEnabled ? "enabled" : "disabled" } : {}), ...(threadOptions.webSearchMode === "disabled" || threadOptions.webSearchMode === "cached" || threadOptions.webSearchMode === "live" ? { webSearchPolicy: threadOptions.webSearchMode } : {}) };
|
|
31
|
+
return Object.freeze({ provider: "codex-sdk", executable: profile.executable, ...(profile.profile ? { profile: profile.profile } : {}), ...(profile.config ? { config: profile.config } : {}), ...(typeof threadOptions.model === "string" ? { model: threadOptions.model } : {}), threadOptions: Object.freeze(threadOptions), effectivePolicy: Object.freeze(policy) });
|
|
32
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/** Closed hard cap for adapter event buffers (§1.5 / faye #315). Not configurable. */
|
|
2
|
+
export const EXEC_EVENT_BUFFER_HARD_CAP = 10_000;
|
|
3
|
+
export function createEventChannelOverflowError(message) {
|
|
4
|
+
const error = new Error(message ??
|
|
5
|
+
`Agent event buffer reached hard cap ${EXEC_EVENT_BUFFER_HARD_CAP}; aborting stream (PROJECTION_STATE_ERROR).`);
|
|
6
|
+
error.name = "EventChannelOverflowError";
|
|
7
|
+
error.code = "PROJECTION_STATE_ERROR";
|
|
8
|
+
return error;
|
|
9
|
+
}
|
|
10
|
+
export function isEventChannelOverflowError(error) {
|
|
11
|
+
return (error instanceof Error &&
|
|
12
|
+
error.code === "PROJECTION_STATE_ERROR" &&
|
|
13
|
+
error.name === "EventChannelOverflowError");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Bounded async event channel for adapter -> runtime.
|
|
17
|
+
* Hard cap is exactly 10_000 (shared across lifecycle + coalesce slots).
|
|
18
|
+
* Channel is blind to provider raw shapes; coalesce keys are explicit opaque strings.
|
|
19
|
+
*/
|
|
20
|
+
export function createEventChannel(options = {}) {
|
|
21
|
+
const queue = [];
|
|
22
|
+
/** Index of the live entry for each coalesce key. */
|
|
23
|
+
const coalesceIndex = new Map();
|
|
24
|
+
const waiters = [];
|
|
25
|
+
let closed = false;
|
|
26
|
+
let failure;
|
|
27
|
+
let drained = false;
|
|
28
|
+
let resolveDrained;
|
|
29
|
+
const drainedPromise = new Promise((resolve) => {
|
|
30
|
+
resolveDrained = resolve;
|
|
31
|
+
});
|
|
32
|
+
const markDrained = () => {
|
|
33
|
+
if (drained)
|
|
34
|
+
return;
|
|
35
|
+
drained = true;
|
|
36
|
+
resolveDrained();
|
|
37
|
+
};
|
|
38
|
+
const reindexCoalesceKeys = () => {
|
|
39
|
+
coalesceIndex.clear();
|
|
40
|
+
for (let i = 0; i < queue.length; i += 1) {
|
|
41
|
+
const key = queue[i].coalesceKey;
|
|
42
|
+
if (key !== undefined) {
|
|
43
|
+
coalesceIndex.set(key, i);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Deliver terminal signal only to currently parked consumers.
|
|
49
|
+
* Does NOT mark drained when there are no waiters: a zero-event close/error must
|
|
50
|
+
* leave whenDrained pending until a consumer actually pulls terminal done/reject.
|
|
51
|
+
*/
|
|
52
|
+
const deliverTerminalToWaiters = () => {
|
|
53
|
+
if (waiters.length === 0)
|
|
54
|
+
return;
|
|
55
|
+
while (waiters.length > 0) {
|
|
56
|
+
const waiter = waiters.shift();
|
|
57
|
+
if (failure !== undefined) {
|
|
58
|
+
// Rejection path marks drained in the waiter reject wrapper below when next() parks;
|
|
59
|
+
// for direct delivery, mark here after reject so whenDrained observes consumer receipt.
|
|
60
|
+
markDrained();
|
|
61
|
+
waiter.reject(failure);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
markDrained();
|
|
65
|
+
waiter.resolve({ value: undefined, done: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const depth = () => queue.length;
|
|
70
|
+
const markOverflow = () => {
|
|
71
|
+
const error = createEventChannelOverflowError();
|
|
72
|
+
failure = error;
|
|
73
|
+
closed = true;
|
|
74
|
+
options.onOverflow?.(error);
|
|
75
|
+
if (queue.length === 0) {
|
|
76
|
+
deliverTerminalToWaiters();
|
|
77
|
+
}
|
|
78
|
+
return "overflow";
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
push(value, meta) {
|
|
82
|
+
if (closed)
|
|
83
|
+
return "closed";
|
|
84
|
+
const coalesceKey = meta?.coalesceKey;
|
|
85
|
+
if (coalesceKey !== undefined) {
|
|
86
|
+
const existing = coalesceIndex.get(coalesceKey);
|
|
87
|
+
if (existing !== undefined) {
|
|
88
|
+
// Same-key replacement: newest snapshot wins; depth unchanged.
|
|
89
|
+
queue[existing] = { value, coalesceKey };
|
|
90
|
+
return "accepted";
|
|
91
|
+
}
|
|
92
|
+
if (depth() >= EXEC_EVENT_BUFFER_HARD_CAP) {
|
|
93
|
+
return markOverflow();
|
|
94
|
+
}
|
|
95
|
+
const waiter = waiters.shift();
|
|
96
|
+
if (waiter) {
|
|
97
|
+
// Direct delivery to a waiting consumer: nothing remains queued for this key.
|
|
98
|
+
waiter.resolve({ value, done: false });
|
|
99
|
+
return "accepted";
|
|
100
|
+
}
|
|
101
|
+
coalesceIndex.set(coalesceKey, queue.length);
|
|
102
|
+
queue.push({ value, coalesceKey });
|
|
103
|
+
return "accepted";
|
|
104
|
+
}
|
|
105
|
+
// Lifecycle: never coalesce or drop.
|
|
106
|
+
if (depth() >= EXEC_EVENT_BUFFER_HARD_CAP) {
|
|
107
|
+
return markOverflow();
|
|
108
|
+
}
|
|
109
|
+
const waiter = waiters.shift();
|
|
110
|
+
if (waiter) {
|
|
111
|
+
waiter.resolve({ value, done: false });
|
|
112
|
+
return "accepted";
|
|
113
|
+
}
|
|
114
|
+
queue.push({ value });
|
|
115
|
+
return "accepted";
|
|
116
|
+
},
|
|
117
|
+
close() {
|
|
118
|
+
if (closed)
|
|
119
|
+
return;
|
|
120
|
+
closed = true;
|
|
121
|
+
// Empty queue + no waiter: leave whenDrained pending until consumer pulls done.
|
|
122
|
+
if (queue.length === 0) {
|
|
123
|
+
deliverTerminalToWaiters();
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
error(error) {
|
|
127
|
+
if (closed && failure !== undefined)
|
|
128
|
+
return;
|
|
129
|
+
closed = true;
|
|
130
|
+
failure = error;
|
|
131
|
+
// Empty queue + no waiter: leave whenDrained pending until consumer pulls rejection.
|
|
132
|
+
if (queue.length === 0) {
|
|
133
|
+
deliverTerminalToWaiters();
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
whenDrained() {
|
|
137
|
+
return drainedPromise;
|
|
138
|
+
},
|
|
139
|
+
depth,
|
|
140
|
+
iterable: {
|
|
141
|
+
[Symbol.asyncIterator]() {
|
|
142
|
+
return {
|
|
143
|
+
next() {
|
|
144
|
+
if (queue.length > 0) {
|
|
145
|
+
const entry = queue.shift();
|
|
146
|
+
reindexCoalesceKeys();
|
|
147
|
+
// After the last item leaves under a closed/failed producer, the next next()
|
|
148
|
+
// (or a parked waiter) must still receive the terminal signal.
|
|
149
|
+
return Promise.resolve({ value: entry.value, done: false });
|
|
150
|
+
}
|
|
151
|
+
if (failure !== undefined) {
|
|
152
|
+
markDrained();
|
|
153
|
+
return Promise.reject(failure);
|
|
154
|
+
}
|
|
155
|
+
if (closed) {
|
|
156
|
+
markDrained();
|
|
157
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
158
|
+
}
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
waiters.push({
|
|
161
|
+
resolve: (result) => {
|
|
162
|
+
if (result.done) {
|
|
163
|
+
markDrained();
|
|
164
|
+
}
|
|
165
|
+
resolve(result);
|
|
166
|
+
},
|
|
167
|
+
reject: (error) => {
|
|
168
|
+
markDrained();
|
|
169
|
+
reject(error);
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { createEventChannel, createEventChannelOverflowError, isEventChannelOverflowError, } from "./event-channel.js";
|
|
3
|
+
import { SubagentFailure } from "../types.js";
|
|
4
|
+
export function createOverflowFailStream(channel) {
|
|
5
|
+
let drained = false;
|
|
6
|
+
let resolveDrained;
|
|
7
|
+
const drainedPromise = new Promise((resolve) => {
|
|
8
|
+
resolveDrained = resolve;
|
|
9
|
+
});
|
|
10
|
+
const markDrained = () => {
|
|
11
|
+
if (drained)
|
|
12
|
+
return;
|
|
13
|
+
drained = true;
|
|
14
|
+
resolveDrained();
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
events: {
|
|
18
|
+
async *[Symbol.asyncIterator]() {
|
|
19
|
+
try {
|
|
20
|
+
for await (const event of channel.iterable) {
|
|
21
|
+
yield event;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (!isEventChannelOverflowError(error)) {
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
yield {
|
|
29
|
+
type: "fail",
|
|
30
|
+
code: "PROJECTION_STATE_ERROR",
|
|
31
|
+
message: error.message,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
markDrained();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
whenDrained: () => drainedPromise,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function createProjectionDriver(input) {
|
|
43
|
+
const id = input.id ?? randomUUID();
|
|
44
|
+
const abortController = new AbortController();
|
|
45
|
+
let finishStarted = false;
|
|
46
|
+
let overflowed = false;
|
|
47
|
+
let resolveCompletion;
|
|
48
|
+
let rejectCompletion;
|
|
49
|
+
const completion = new Promise((resolve, reject) => {
|
|
50
|
+
resolveCompletion = resolve;
|
|
51
|
+
rejectCompletion = reject;
|
|
52
|
+
});
|
|
53
|
+
completion.catch(() => undefined);
|
|
54
|
+
const channel = createEventChannel({
|
|
55
|
+
onOverflow: () => {
|
|
56
|
+
overflowed = true;
|
|
57
|
+
if (!abortController.signal.aborted) {
|
|
58
|
+
abortController.abort();
|
|
59
|
+
}
|
|
60
|
+
void input.abort?.();
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const eventStream = createOverflowFailStream(channel);
|
|
64
|
+
const finish = (action) => {
|
|
65
|
+
if (finishStarted)
|
|
66
|
+
return;
|
|
67
|
+
finishStarted = true;
|
|
68
|
+
channel.close();
|
|
69
|
+
void eventStream.whenDrained().then(action, action);
|
|
70
|
+
};
|
|
71
|
+
const overflowFailure = () => new SubagentFailure("SUBAGENT_EXEC_ERROR", createEventChannelOverflowError().message, {
|
|
72
|
+
diagnostics: "PROJECTION_STATE_ERROR",
|
|
73
|
+
});
|
|
74
|
+
const runPromise = (async () => {
|
|
75
|
+
try {
|
|
76
|
+
const outcome = await input.run({
|
|
77
|
+
emit(event, meta) {
|
|
78
|
+
channel.push(event, meta);
|
|
79
|
+
},
|
|
80
|
+
signal: abortController.signal,
|
|
81
|
+
});
|
|
82
|
+
if (overflowed) {
|
|
83
|
+
finish(() => rejectCompletion(overflowFailure()));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
finish(() => resolveCompletion(outcome));
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (overflowed || isEventChannelOverflowError(error)) {
|
|
90
|
+
finish(() => rejectCompletion(error instanceof SubagentFailure && error.diagnostics === "PROJECTION_STATE_ERROR"
|
|
91
|
+
? error
|
|
92
|
+
: overflowFailure()));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
finish(() => rejectCompletion(error));
|
|
96
|
+
}
|
|
97
|
+
})();
|
|
98
|
+
void runPromise;
|
|
99
|
+
const enqueue = input.enqueue &&
|
|
100
|
+
(async (message) => {
|
|
101
|
+
return input.enqueue(message);
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
id,
|
|
105
|
+
events: eventStream.events,
|
|
106
|
+
completion,
|
|
107
|
+
steerMode: input.steerMode,
|
|
108
|
+
...(enqueue ? { enqueue } : {}),
|
|
109
|
+
...(input.clearQueue ? { clearQueue: input.clearQueue } : {}),
|
|
110
|
+
async abort() {
|
|
111
|
+
if (!abortController.signal.aborted) {
|
|
112
|
+
abortController.abort();
|
|
113
|
+
}
|
|
114
|
+
await input.abort?.();
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|