@hydraharness/harness-subagent-in-process-driver 0.1.1-rc.6

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @hydraharness/harness-subagent-in-process-driver
2
+
3
+ This package is the shared run driver for the two in-process providers. Spawn passes no session seed; fork passes the parent's completed-turn prefix. Everything else—depth, child creation, optional child customization, result reading, cancellation, and disposal—has one implementation here.
4
+
5
+ ## Start contract
6
+
7
+ `startInProcessRun(request, options): Promise<SubagentRun>` fulfills only after the child is published in `ctx.agents`. A rejected start has already quiesced the agent factory's unpublished creation transaction, so the caller never receives a half-created handle.
8
+
9
+ The driver follows this sequence:
10
+
11
+ 1. Validate the parent depth and optional absolute `maxDepth`, then derive child depth as parent depth plus one and persist it in the child session header.
12
+ 2. Call `parent.ctx.agents.create` directly, passing the required request signal into the factory's creation transaction.
13
+ 3. During that transaction's unpublished setup window, install the requested persona, tool restriction, and structured-output runtime.
14
+ 4. Publish the child, retain the returned `AgentHandle`, and drive one task with `child.followup(prompt)` followed by `child.whenIdle()`.
15
+ 5. Read the child's own output — its last non-empty assistant message (an empty-content message that records usage is skipped), or its accumulated assistant text when no such message exists — and the final durable turn reason from the complete owned child run, excluding any fork seed.
16
+
17
+ The child gets the parent's working-directory/session lineage and inherits the parent provider, model, and output-token cap unless `request.agentOptions` overrides them. It gets a fresh flat registration scope: parent ownership does not import parent tool restrictions or establish an authority subset.
18
+
19
+ This result boundary is valid because the provider owns an isolated child lifecycle from publication through quiescence. Steering submitted during that lifecycle belongs to the child run; the provider does not pretend the initial follow-up alone owns its output.
20
+
21
+ The driver applies the seam's [delegated policy](../subagent/README.md#delegated-policy) through the shared child-agent helpers: it captures the parent's explicit sandbox override and the `'never'` approval pin before child creation and appends the source-tagged events during unpublished setup, after any fork history and before session publication. See the [delegation-policy decision](../../../.agents/notes/implemented/feature/2026-07-25-subagent-policy-inheritance.md).
22
+
23
+ ## Cancellation and ownership
24
+
25
+ The required request signal covers both startup and the live run. Before publication, `AgentCreationTransaction` observes it, rolls back, and rejects. The factory detaches that creation-only listener before returning; the driver immediately checks the signal once more before installing a minimal live-run listener, closing the handoff race. After publication, abort cancels the child.
26
+
27
+ After fulfillment, the caller owns the run. Provider-plugin unload does not revoke it. `dispose()` removes the live abort listener, records cancellation, and delegates to the returned `AgentHandle.dispose()`, whose memoized quiescence transaction stops the loop, removes the agent and session, and unwinds scoped registrations. Cancellation owns every non-completed in-flight outcome and reports `aborted`; an already-completed turn remains completed.
28
+
29
+ ## Spawn and fork inputs
30
+
31
+ `InProcessRunOptions` is `{ seed?: SessionEvent[] }`. Spawn omits it. Fork supplies a balanced completed-turn prefix and records its length so the result reader never mistakes a seeded parent message for child output.
32
+
33
+ Depth enforcement is internal to `startInProcessRun`: it reads the parent depth via `delegationDepthOf` (the persisted `SessionHeader.delegationDepth` is authoritative; runtime `AgentOptions.subagentDepth` may deepen but never lower it, so a resumed child keeps its budget), treats absence as top-level depth zero, rejects malformed stored values, and reports an attempted child depth above `maxDepth`. An unrepresentable depth above the safe-integer domain is a `RangeError`. The child depth is written to the child header, so it survives persistence and resume.
34
+
35
+ ## Structured output
36
+
37
+ `attachStructuredRuntime(childCtx, schema)` installs the whole contract in the child's scope:
38
+
39
+ - A `structured_output` tool registered with the requested schema validates and stages the model's value.
40
+ - An order-190 system-prompt section tells the child that the tool call is the terminal answer.
41
+ - Both contributions are ordinary child-scoped registrations. An expert `system-prompt/assemble` listener may replace them and therefore owns preserving the structured-output protocol for that child.
42
+ - A `tools/result` observer commits a staged value only after that execution's authoritative final tool result succeeds, including the enclosing `run_code` result for Code Mode sub-dispatch.
43
+ - A monotonic tool guard blocks later calls after capture, and the structured-output execution's `concludeTurn()` marker ends the turn after the result commits.
44
+
45
+ A clean turn that never commits the required structured value reports `error`; the driver does not re-prompt. All registrations ride the child fiber and disappear with it.
46
+
47
+ ## Model Experience
48
+
49
+ ### Child-agent request
50
+
51
+ #### What the model sees
52
+
53
+ The shared driver sends the task verbatim as the child's user message and, when requested, shadows the persona and restricts global tool schemas, lookup, execution, and Code Mode SDK bindings in the unpublished child's fresh scope; parent restrictions are not inherited, and standalone tool-guidance sections remain. Spawn supplies no history; fork supplies its balanced seed.
54
+
55
+ #### Token effect
56
+
57
+ Child input is isolated from the parent and grows through the child's own steps. A persona changes repeated prompt text; filtering changes schema or generated SDK cost but not independently registered guidance.
58
+
59
+ #### KV Cache effect
60
+
61
+ Independent of the parent request cache. The child's later history is append-only, while persona, tool-filter, generated-SDK, provider, or model changes establish a different child prefix.
62
+
63
+ ### Structured-output system prompt, schema, and results
64
+
65
+ #### What the model sees
66
+
67
+ A structured run adds the structured-output instruction below. It also adds a child-scoped `structured_output` definition with exact description `Report your final structured result. Call this exactly once, when your answer is complete; the arguments must match this tool's parameter schema exactly.` and the requested schema. This runtime-only definition is outside the generated shipped [tool package map](../../../docs/tool-catalog.md#tool-package-map). Its canonical acknowledgement is `{ recorded: true }`, rendered as `Structured output recorded.`; a later call becomes ``Error: structured output already recorded: the run is complete, so `<tool>` is not executed``.
68
+
69
+ ##### Structured-output instruction
70
+
71
+ ```markdown
72
+ When you have your final answer, you MUST report it by calling the `structured_output` tool with arguments matching its parameter schema exactly. Do not finish with a plain text answer: only the tool call counts as your result.
73
+ ```
74
+
75
+ #### Token effect
76
+
77
+ Fixed instruction and capability tokens are paid only by that child. Result text enters the child history, while the captured value alone becomes the parent result.
78
+
79
+ #### KV Cache effect
80
+
81
+ Prefix-stable inside the child while the structured-output instruction and schema are unchanged. Changing the schema or capability may invalidate the child's cache from that early segment; results append in child and parent histories.
82
+
83
+ ### Parent start error, indirectly
84
+
85
+ #### What the model sees
86
+
87
+ Through `@hydraharness/harness-tool-subagent`, invalid depth state becomes exactly `Error: agent subagentDepth must be a non-negative safe integer`, `Error: subagent child depth exceeds the safe-integer range`, or `Error: subagent depth <attempted> exceeds maxDepth <max>`. A pre-publication cancellation passes its abort reason through the registry's `Error: <message>` wrapper.
88
+
89
+ #### Token effect
90
+
91
+ Zero tokens on a successful start; only the failed parent tool call retains this text.
92
+
93
+ #### KV Cache effect
94
+
95
+ Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
96
+
97
+ ### Parent result, indirectly
98
+
99
+ #### What the model sees
100
+
101
+ The driver extracts only the child's own last assistant output or captured structured value; seeded parent messages and intermediate child work do not become the result.
102
+
103
+ #### Token effect
104
+
105
+ The parent receives one data-dependent result through the consumer; all other child tokens stay in the child session.
106
+
107
+ #### KV Cache effect
108
+
109
+ Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
110
+
111
+ ## Known Limitations and Deferred Work
112
+
113
+ - **Runs expose no `sendMessage`/`resume`** — the optional runtime capabilities are absent on in-process runs.
114
+ - **Structured capture accepts the `defineTool` schema subset only** — unsupported JSON Schema constructs fail before the child is created; a provider needing a broader schema vocabulary requires a different runtime.
package/lib/index.js ADDED
@@ -0,0 +1,251 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { foldConsumedWork } from "@hydraharness/harness-agent";
3
+ import { SessionId } from "@hydraharness/harness-session";
4
+ import { createUserMessage } from "@hydraharness/harness-llm";
5
+ import { appendDelegatedPolicyOverrides, applyChildComposition, assertSubagentMaxDepth, captureDelegatedPolicyOverrides, childSessionMeta, finalAssistantOutput, resolveChildAgentOptions, resolveChildDepth } from "@hydraharness/harness-subagent";
6
+ import { ToolArgsError, validateJsonSchemaValue } from "@hydraharness/harness-tools";
7
+ //#region lib/types/structured.js
8
+ /**
9
+ * Child-scoped structured-output tool, prompt instruction, terminal guard, and authoritative
10
+ * result capture for in-process subagents. Each child registers its real schema on its own
11
+ * scope, so concurrent runs do not interact and disposal leaves no global residue. The prompt
12
+ * contribution is ordinary reconstructed request state.
13
+ *
14
+ * Capture commits only after the authoritative `tools/result` succeeds; Code Mode capture also
15
+ * waits for the enclosing `run_code` result. The terminal result marker and monotonic tool
16
+ * guard prevent later calls from reopening a completed structured run.
17
+ * @module @hydraharness/harness-subagent-in-process-driver/structured
18
+ */
19
+ /** The model-facing tool name a structured child must call to finish. */
20
+ const STRUCTURED_OUTPUT_TOOL = "structured_output";
21
+ /**
22
+ * The instruction registered as the child's trailing (order-190, the end of
23
+ * the tool-guidance band) scoped prompt section: the demand travels with the
24
+ * tool, as ordinary prompt state of exactly one agent.
25
+ */
26
+ const STRUCTURED_OUTPUT_INSTRUCTION = `When you have your final answer, you MUST report it by calling the \`${STRUCTURED_OUTPUT_TOOL}\` tool with arguments matching its parameter schema exactly. Do not finish with a plain text answer: only the tool call counts as your result.`;
27
+ /**
28
+ * Attach the scoped capture tool, instruction, and enforcement to a child during
29
+ * its creation window. Child disposal removes every registration.
30
+ * @param childCtx - the child agent's scope context (`setup`'s argument).
31
+ * @param schema - the trusted, already-asserted schema subset to enforce (see
32
+ * `assertObjectJsonSchema` in @hydraharness/harness-tools).
33
+ * @returns the attachment handle (read `captured()` after the child settles).
34
+ */
35
+ function attachStructuredRuntime(childCtx, schema) {
36
+ /**
37
+ * Validated values staged by the capture tool body, awaiting THEIR OWN
38
+ * authoritative `tools/result` notification. The execution object's identity
39
+ * uniquely identifies a trip through the pipeline: adapter call ids may
40
+ * repeat across steps, but another execution can never reach this WeakMap
41
+ * entry. This is distinct from the opaque `ToolExecutionToken` used to
42
+ * correlate nested transports. The final notification always deletes its own
43
+ * stage, whether the result succeeded or failed.
44
+ */
45
+ const staged = /* @__PURE__ */ new WeakMap();
46
+ /** Successful nested capture waiting for its enclosing transport to commit. */
47
+ let pending;
48
+ let captured;
49
+ const schemaEntry = {
50
+ name: STRUCTURED_OUTPUT_TOOL,
51
+ description: "Report your final structured result. Call this exactly once, when your answer is complete; the arguments must match this tool's parameter schema exactly.",
52
+ parameters: schema
53
+ };
54
+ childCtx.tools.register({
55
+ ...schemaEntry,
56
+ output: {
57
+ schema: {
58
+ type: "object",
59
+ properties: { recorded: {
60
+ type: "boolean",
61
+ const: true
62
+ } },
63
+ required: ["recorded"],
64
+ additionalProperties: false
65
+ },
66
+ render: () => [{
67
+ type: "text",
68
+ text: "Structured output recorded."
69
+ }]
70
+ },
71
+ execute(args, exec) {
72
+ const violations = validateJsonSchemaValue(schema, args);
73
+ if (violations.length > 0) throw new ToolArgsError(violations);
74
+ staged.set(exec, { value: args });
75
+ exec.concludeTurn();
76
+ return Promise.resolve({ recorded: true });
77
+ }
78
+ });
79
+ childCtx.systemPrompt.section({
80
+ name: `tool:${STRUCTURED_OUTPUT_TOOL}`,
81
+ order: 190,
82
+ text: STRUCTURED_OUTPUT_INSTRUCTION
83
+ });
84
+ childCtx.tools.guard((exec) => captured === void 0 && pending === void 0 ? void 0 : `structured output already recorded: the run is complete, so \`${exec.name}\` is not executed`);
85
+ childCtx.on("tools/result", function(exec, result) {
86
+ if (exec.name === "structured_output") {
87
+ const entry = staged.get(exec);
88
+ if (entry === void 0) return;
89
+ staged.delete(exec);
90
+ if (result.isError) return;
91
+ if (exec.parent === void 0) {
92
+ /* v8 ignore else -- sequential agent-loop dispatch lets the guard block every later supported call */
93
+ if (captured === void 0) captured = { value: entry.value };
94
+ } else if (captured === void 0 && pending === void 0) pending = {
95
+ parent: exec.parent,
96
+ value: entry.value
97
+ };
98
+ return;
99
+ }
100
+ if (pending?.parent !== exec.token) return;
101
+ const entry = pending;
102
+ pending = void 0;
103
+ if (result.isError) return;
104
+ /* v8 ignore else -- Code Mode serializes outer executions, so the guard blocks every later supported call */
105
+ if (captured === void 0) captured = { value: entry.value };
106
+ });
107
+ return { captured: () => captured };
108
+ }
109
+ //#endregion
110
+ //#region lib/types/index.js
111
+ /**
112
+ * Shared driver for in-process ONE-SHOT subagent providers. The agent factory's
113
+ * creation transaction owns unpublished setup and rollback; after publication
114
+ * the returned AgentHandle is the one quiescent lifecycle owner held by the
115
+ * provider's caller.
116
+ *
117
+ * Continuable children never come through here: the continuation manager
118
+ * composes and drives them directly, so this driver owns exactly one turn with
119
+ * one result.
120
+ *
121
+ * @module @hydraharness/harness-subagent-in-process-driver
122
+ */
123
+ /** Map a session turn outcome to the subagent seam's terminal vocabulary. */
124
+ function toStopReason(reason) {
125
+ switch (reason?.kind) {
126
+ case "completed": return "completed";
127
+ case "max-tokens": return "max-tokens";
128
+ case "aborted": return "aborted";
129
+ case "blocked": return "refusal";
130
+ default: return "error";
131
+ }
132
+ }
133
+ /** Error used when cancellation wins before the child publication boundary. */
134
+ function prePublicationAbort() {
135
+ return /* @__PURE__ */ new Error("subagent request was aborted before child publication");
136
+ }
137
+ /** Append one one-shot descriptor inside the child's initial turn before its first request. */
138
+ function attachDescriptorAppend(childCtx, descriptor) {
139
+ let appended = false;
140
+ childCtx.on("agent/pre-step", async ({ agent }, next) => {
141
+ const decision = await next();
142
+ if (!appended && decision.kind === "enter") {
143
+ appended = true;
144
+ agent.session.append("subagent/descriptor", descriptor);
145
+ }
146
+ return decision;
147
+ });
148
+ }
149
+ /**
150
+ * Establish and drive one in-process one-shot child. Fulfillment means the agent
151
+ * is already published in the registry and transfers its turn, cancellation,
152
+ * and disposal work through the returned run. Rejection means the agent
153
+ * factory's unpublished creation transaction reached quiescence without
154
+ * publishing a child. Every start appends its resolved descriptor inside the
155
+ * child's initial turn.
156
+ * @param request - the trusted typed start request, including its required signal.
157
+ * @param options - the optional fork seed.
158
+ * @returns a published holder-owned run.
159
+ */
160
+ async function startInProcessRun(request, options) {
161
+ assertSubagentMaxDepth(request.maxDepth);
162
+ if (request.signal.aborted) throw prePublicationAbort();
163
+ const parent = request.parent;
164
+ const childDepth = resolveChildDepth(parent, request.maxDepth);
165
+ const childId = SessionId(randomUUID());
166
+ const seed = options.seed;
167
+ const activationBoundary = seed?.length ?? 0;
168
+ const inherited = captureDelegatedPolicyOverrides(parent);
169
+ let structured;
170
+ const setup = (childCtx) => {
171
+ appendDelegatedPolicyOverrides(childCtx.agent.session, inherited);
172
+ applyChildComposition(childCtx, parent, {
173
+ persona: request.persona,
174
+ toolFilter: request.toolFilter
175
+ });
176
+ if (request.outputSchema !== void 0) structured = attachStructuredRuntime(childCtx, request.outputSchema);
177
+ attachDescriptorAppend(childCtx, request.descriptor);
178
+ };
179
+ return drivePublishedRun(await parent.ctx.agents.create({
180
+ sessionId: childId,
181
+ meta: childSessionMeta(parent, childDepth, activationBoundary),
182
+ ...seed !== void 0 ? { seed } : {},
183
+ agentOptions: resolveChildAgentOptions(parent, request.agentOptions, childDepth),
184
+ signal: request.signal,
185
+ setup
186
+ }), request.signal, request.prompt, childId, activationBoundary, structured);
187
+ }
188
+ /**
189
+ * Wrap a published child in the single run lifecycle that owns signal handoff,
190
+ * one turn, result settlement, and quiescent disposal.
191
+ */
192
+ function drivePublishedRun(handle, signal, prompt, childId, boundary, structured) {
193
+ const child = handle.agent;
194
+ const flags = { cancelled: false };
195
+ const onAbort = () => {
196
+ flags.cancelled = true;
197
+ child.cancel({ kind: "parent" });
198
+ };
199
+ signal.addEventListener("abort", onAbort, { once: true });
200
+ if (signal.aborted) onAbort();
201
+ const result = (async () => {
202
+ try {
203
+ if (!flags.cancelled) {
204
+ child.followup(createUserMessage({
205
+ content: prompt,
206
+ source: { kind: "user" }
207
+ }));
208
+ await child.whenIdle();
209
+ }
210
+ return readResult(child, boundary, flags.cancelled, structured ? { captured: structured.captured() } : void 0);
211
+ } finally {
212
+ signal.removeEventListener("abort", onAbort);
213
+ }
214
+ })();
215
+ return {
216
+ id: childId,
217
+ localAgent: child,
218
+ result,
219
+ async dispose() {
220
+ signal.removeEventListener("abort", onAbort);
221
+ flags.cancelled = true;
222
+ const disposal = (await Promise.allSettled([handle.dispose(), result]))[0];
223
+ if (disposal.status === "rejected") throw disposal.reason;
224
+ }
225
+ };
226
+ }
227
+ /** Read one settled child's result from events after its activation boundary. */
228
+ function readResult(child, boundary, cancelled, structured) {
229
+ const own = child.session.events.slice(boundary);
230
+ const lastEnd = foldConsumedWork(own).end;
231
+ const output = finalAssistantOutput(own) ?? [];
232
+ const recorded = toStopReason(lastEnd?.data.reason);
233
+ const stopReason = cancelled && recorded !== "completed" ? "aborted" : recorded;
234
+ if (structured !== void 0) {
235
+ if (structured.captured !== void 0) return {
236
+ output,
237
+ structured: structured.captured.value,
238
+ stopReason
239
+ };
240
+ if (stopReason === "completed") return {
241
+ output,
242
+ stopReason: cancelled ? "aborted" : "error"
243
+ };
244
+ }
245
+ return {
246
+ output,
247
+ stopReason
248
+ };
249
+ }
250
+ //#endregion
251
+ export { STRUCTURED_OUTPUT_INSTRUCTION, STRUCTURED_OUTPUT_TOOL, startInProcessRun };
@@ -0,0 +1,23 @@
1
+ //#region lib/types/invariant.js
2
+ /**
3
+ * Package-owned invariant companion for `@hydraharness/harness-subagent-in-process-driver`.
4
+ * @module @hydraharness/harness-subagent-in-process-driver/invariant
5
+ */
6
+ const PACKAGE_NAME = "@hydraharness/harness-subagent-in-process-driver";
7
+ /** Cordis companion plugin name. */
8
+ const name = "subagent-in-process-driver-invariant";
9
+ /** Service required before the companion can reserve package ownership. */
10
+ const inject = ["invariants"];
11
+ /**
12
+ * No runtime invariant: this package exposes no independent event sequence or mutable data relation
13
+ * beyond contracts enforced at its owning seam.
14
+ */
15
+ const install = () => {};
16
+ /**
17
+ * Register this package's invariant companion.
18
+ * @param ctx - Cordis context carrying the invariant service.
19
+ * @returns the installed registration's disposer after setup succeeds.
20
+ */
21
+ const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
22
+ //#endregion
23
+ export { apply, inject, name };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Shared driver for in-process ONE-SHOT subagent providers. The agent factory's
3
+ * creation transaction owns unpublished setup and rollback; after publication
4
+ * the returned AgentHandle is the one quiescent lifecycle owner held by the
5
+ * provider's caller.
6
+ *
7
+ * Continuable children never come through here: the continuation manager
8
+ * composes and drives them directly, so this driver owns exactly one turn with
9
+ * one result.
10
+ *
11
+ * @module @hydraharness/harness-subagent-in-process-driver
12
+ */
13
+ import { type SessionEvent } from '@hydraharness/harness-session';
14
+ import type { ResolvedSubagentStartRequest, SubagentRun } from '@hydraharness/harness-subagent';
15
+ export { STRUCTURED_OUTPUT_TOOL, STRUCTURED_OUTPUT_INSTRUCTION, } from './structured.ts';
16
+ /** Extra inputs the spawn and fork providers supply to the shared driver. */
17
+ export interface InProcessRunOptions {
18
+ /** Completed-turn seed for fork, or undefined for a fresh spawn. */
19
+ readonly seed?: SessionEvent[];
20
+ }
21
+ /**
22
+ * Establish and drive one in-process one-shot child. Fulfillment means the agent
23
+ * is already published in the registry and transfers its turn, cancellation,
24
+ * and disposal work through the returned run. Rejection means the agent
25
+ * factory's unpublished creation transaction reached quiescence without
26
+ * publishing a child. Every start appends its resolved descriptor inside the
27
+ * child's initial turn.
28
+ * @param request - the trusted typed start request, including its required signal.
29
+ * @param options - the optional fork seed.
30
+ * @returns a published holder-owned run.
31
+ */
32
+ export declare function startInProcessRun(request: ResolvedSubagentStartRequest, options: InProcessRunOptions): Promise<SubagentRun>;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Package-owned invariant companion for `@hydraharness/harness-subagent-in-process-driver`.
3
+ * @module @hydraharness/harness-subagent-in-process-driver/invariant
4
+ */
5
+ import type { Context } from '@hydraharness/cordis';
6
+ /** Cordis companion plugin name. */
7
+ export declare const name = "subagent-in-process-driver-invariant";
8
+ /** Service required before the companion can reserve package ownership. */
9
+ export declare const inject: string[];
10
+ /**
11
+ * Register this package's invariant companion.
12
+ * @param ctx - Cordis context carrying the invariant service.
13
+ * @returns the installed registration's disposer after setup succeeds.
14
+ */
15
+ export declare const apply: (ctx: Context) => Promise<() => void>;
16
+ //# sourceMappingURL=invariant.d.ts.map
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Child-scoped structured-output tool, prompt instruction, terminal guard, and authoritative
3
+ * result capture for in-process subagents. Each child registers its real schema on its own
4
+ * scope, so concurrent runs do not interact and disposal leaves no global residue. The prompt
5
+ * contribution is ordinary reconstructed request state.
6
+ *
7
+ * Capture commits only after the authoritative `tools/result` succeeds; Code Mode capture also
8
+ * waits for the enclosing `run_code` result. The terminal result marker and monotonic tool
9
+ * guard prevent later calls from reopening a completed structured run.
10
+ * @module @hydraharness/harness-subagent-in-process-driver/structured
11
+ */
12
+ import type { Context } from '@hydraharness/cordis';
13
+ import { type ObjectJsonSchema } from '@hydraharness/harness-tools';
14
+ /** The model-facing tool name a structured child must call to finish. */
15
+ export declare const STRUCTURED_OUTPUT_TOOL = "structured_output";
16
+ /**
17
+ * The instruction registered as the child's trailing (order-190, the end of
18
+ * the tool-guidance band) scoped prompt section: the demand travels with the
19
+ * tool, as ordinary prompt state of exactly one agent.
20
+ */
21
+ export declare const STRUCTURED_OUTPUT_INSTRUCTION: string;
22
+ /** One structured run's live handle: read the captured value once the child settles. */
23
+ export interface StructuredAttachment {
24
+ /**
25
+ * The captured value, once the child called the tool with valid arguments
26
+ * and the authoritative final tool result accepted that call.
27
+ * @returns the committed value, or undefined while none was accepted.
28
+ */
29
+ captured(): {
30
+ value: unknown;
31
+ } | undefined;
32
+ }
33
+ /**
34
+ * Attach the scoped capture tool, instruction, and enforcement to a child during
35
+ * its creation window. Child disposal removes every registration.
36
+ * @param childCtx - the child agent's scope context (`setup`'s argument).
37
+ * @param schema - the trusted, already-asserted schema subset to enforce (see
38
+ * `assertObjectJsonSchema` in @hydraharness/harness-tools).
39
+ * @returns the attachment handle (read `captured()` after the child settles).
40
+ */
41
+ export declare function attachStructuredRuntime(childCtx: Context, schema: ObjectJsonSchema): StructuredAttachment;
42
+ //# sourceMappingURL=structured.d.ts.map
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@hydraharness/harness-subagent-in-process-driver",
3
+ "description": "Shared in-process subagent run driver: drives a child agent on ctx.agents (used by the spawn and fork backends)",
4
+ "version": "0.1.1-rc.6",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/MaiHongPhong1902/Hydra-Harness.git",
11
+ "directory": "packages/subagent/subagent-in-process-driver"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./src/*": "./src/*",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "lib/index.js",
30
+ "lib/invariant.js",
31
+ "lib/types/**/*.d.ts"
32
+ ],
33
+ "license": "MIT",
34
+ "peerDependencies": {
35
+ "@hydraharness/harness-agent": "^0.1.1-rc.6",
36
+ "@hydraharness/harness-invariants": "^0.1.1-rc.6",
37
+ "@hydraharness/harness-llm": "^0.1.1-rc.6",
38
+ "@hydraharness/harness-session": "^0.1.1-rc.6",
39
+ "@hydraharness/harness-subagent": "^0.1.1-rc.6",
40
+ "@hydraharness/harness-system-prompt": "^0.1.1-rc.6",
41
+ "@hydraharness/harness-tools": "^0.1.1-rc.6",
42
+ "@hydraharness/cordis": "^4.0.2"
43
+ },
44
+ "devDependencies": {
45
+ "@hydraharness/cordis-plugin-include": "^1.0.7",
46
+ "@hydraharness/harness-agent": "^0.1.1-rc.6",
47
+ "@hydraharness/harness-agent-loop": "^0.1.1-rc.6",
48
+ "@hydraharness/cordis-plugin-loader": "^1.0.3",
49
+ "@hydraharness/harness-agent-presets": "^0.1.1-rc.6",
50
+ "@hydraharness/harness-agent-loop-testkit": "^0.1.1-rc.6",
51
+ "@hydraharness/harness-invariants": "^0.1.1-rc.6",
52
+ "@hydraharness/harness-fs-sandbox": "^0.1.1-rc.6",
53
+ "@hydraharness/harness-llm": "^0.1.1-rc.6",
54
+ "@hydraharness/harness-sandbox-policy": "^0.1.1-rc.6",
55
+ "@hydraharness/harness-session": "^0.1.1-rc.6",
56
+ "@hydraharness/harness-subagent": "^0.1.1-rc.6",
57
+ "@hydraharness/harness-tool-fs": "^0.1.1-rc.6",
58
+ "@hydraharness/harness-system-prompt": "^0.1.1-rc.6",
59
+ "@hydraharness/harness-tools": "^0.1.1-rc.6",
60
+ "@hydraharness/harness-user-approval": "^0.1.1-rc.6",
61
+ "@hydraharness/cordis": "^4.0.2"
62
+ }
63
+ }